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
800
Chef has provided with a sequence of integers of length $N$ arranged in an unsorted fashion. The elements of the sequence are ordered as ${A1,A2,A3.....A'N}$ The task of the chef is to identify the highest and lowest value among the given sequence. It is assured that the sequence given contains the highest and the lowe...
["n=int(input())\na=list(map(int,input().split()))\na.sort()\nprint(a[-1],a[0])\n", "n = int(input())\narr = list(map(int,input().split()))\nprint(max(arr),min(arr))", "# cook your dish here\ntry:\n n=int(input())\n num = list(map(int, input().split()[:n]))\n m1=max(num)\n m2=min(num)\n print(m1,m2)\n\ne...
[{"input": ["5", "3 2 7 9 4"], "output": ["9 2"]}]
interview
801
Chefina has two sequences $A_1, A_2, \ldots, A_N$ and $B_1, B_2, \ldots, B_N$. She views two sequences with length $N$ as identical if, after they are sorted in non-decreasing order, the $i$-th element of one sequence is equal to the $i$-th element of the other sequence for each $i$ ($1 \le i \le N$). To impress Chefin...
["from collections import Counter\ntc=int(input())\nfor k in range(tc):\n n=int(input())\n a=list(map(int, input().rstrip().split()))\n b= list(map(int, input().rstrip().split()))\n cc=sorted(a+b)\n #print('cc = ',cc)\n p=[]\n q=[]\n #print('len(cc) = ',len(cc))\n #print('len = ',(2*n))\n #rx=0\n for i in range(0,(2*n)...
[{"input": ["3", "1", "1", "2", "2", "1 2", "2 1", "2", "1 1", "2 2"], "output": ["-1", "0", "1"]}]
interview
802
Chef likes to solve difficult tasks. This time, he tried to solve the Big Famous Unsolvable $A+B=C$. One of his friends played a prank on Chef and randomly shuffled the bits in $A$ and $B$ (independently in each number). However, the funny thing is that the sum of the resulting numbers remained $C$ even after shuffling...
["import math\ndef csb(n): \n count = 0\n while (n): \n n &= (n-1) \n count+= 1\n \n return count\ndef f(ca,cb,i,cf,C,n,dp):\n if ca<0 or cb<0:\n return 0\n if i==n:\n if ca==0 and cb==0 and cf==0:\n return 1\n return 0\n st=str(ca)+\" \"+str(cb)+\" \"+str(cf)+\" \"+str(i)\n if dp.get(st)!=None:\n return dp[st...
[{"input": ["2", "1 2 3", "369 428 797"], "output": ["2", "56"]}]
interview
803
In poker, you have 5 cards. There are 10 kinds of poker hands (from highest to lowest): - royal flush - ace, king, queen, jack and ten, all in the same suit - straight flush - five cards of the same suit in sequence, such as 10,9,8,7,6 of clubs; ace can be counted both as the highest card or as the lowest card - A,...
["cards = ['A','2','3','4','5','6','7','8','9','T','J','Q','K']\n\ndef royal_flush(arr):\n nonlocal ans, confirm\n rf_set = 'TJQKA'\n rf = 1\n for char in arr:\n if char[0] not in rf_set:\n rf = 0\n break\n if rf :\n if len(set(suit)) == 1:\n ans = 'royal flush'\n confirm = 1\ndef straight_flush(arr): # and ...
[{"input": ["3", "AH KH QH TH JH", "KH 5S 3C 5C 7D", "QH QD 2S QC 2C"], "output": ["royal flush", "pair", "full house"]}]
interview
804
Bitland declared war on Chefland and sent an army to fight them, but Chefland defended efficiently and Bitland's army has been reduced to N$N$ soldiers. They have no chance of winning the war and do not want to surrender, so they are planning to commit group suicide. Josh, the leader of Bitland's remaining soldiers, ha...
["import numpy as np\nfor _ in range(int(input())):\n n = int(input())-1;soldiers = [int(j) for j in input().split()]\n force = int(input());attacks = np.zeros(2*n,dtype=int);attacks[:n] = np.array(soldiers);attacks[n:2*n] = attacks[:n];shield = [0 for _ in range(n)];pow_of_2 = 1\n while n // pow_of_2 > 0: p...
[{"input": ["2", "5", "12 34 45 5", "10", "5", "10 15 43 20", "5"], "output": ["possible", "4 100", "impossible"]}]
interview
805
in Chefland, there is a very famous street where $N$ types of street food (numbered $1$ through $N$) are offered. For each valid $i$, there are $S_i$ stores that offer food of the $i$-th type, the price of one piece of food of this type is $V_i$ (the same in each of these stores) and each day, $P_i$ people come to buy ...
["t=int(input())\nwhile(t):\n n=int(input())\n l=[]\n for i in range(n):\n l.append(list(map(int,input().split())));\n m=[]\n for i in l:\n m.append((i[1]//(i[0]+1))*i[2])\n res=max(m)\n print(res)\n t=t-1", "# cook your dish here\nt=int(input())\nwhile(t):\n n=int(input())\n l=[]\n for i in range(n):\n l.append(lis...
[{"input": ["2", "3", "4 6 8", "2 6 6", "1 4 3", "1", "7 7 4"], "output": ["12", "0"]}]
interview
806
John was learning mathematics and was very bored. Jane his best friend gave him a problem to solve. The description of the problem was as follows:- You are given a decimal number $N$(1<=$N$<=$10^9$) and three integers $A$, $B$, $C$. Steps to perform: 1) You have to create a $LIST$. 2) You have to initialize the $LI...
["# Why do we fall ? So we can learn to pick ourselves up.\r\n\r\n\r\n\r\n\r\nt = int(input())\r\nfor _ in range(0,t):\r\n n = int(input())\r\n abc = [int(i) for i in input().split()]\r\n\r\n i = 0\r\n\r\n lst = [n]\r\n\r\n for _ in range(0,100):\r\n k = str(lst[-1]/abc[i%3]).split('.')\r\n ...
[{"input": ["1", "56", "3 5 7", "4", "0", "1", "2", "3"], "output": ["56", "6", "2", "2"]}]
interview
807
You are given an array A of size N. Let us list down all the subarrays of the given array. There will be a total of N * (N + 1) / 2 subarrays of the given array. Let us sort each of the subarrays in descending order of the numbers in it. Now you want to sort these subarrays in descending order. You can compare two su...
["# cook your dish here\nfor _ in range(int(input())):\n n,q=map(int,input().split())\n l=[int(i) for i in input().split()]\n qry=[int(input()) for i in range(q)]\n def cmp(sub1,sub2):\n for i in range(len(sub1)):\n if sub1[i]>sub2[i]:\n return 1 \n if sub1[i]<sub2[i]:\n return 2 \n return 1 \n maxl=[]\n fo...
[{"input": ["1", "4 2", "3 1 2 4", "1", "5"], "output": ["4", "3"]}]
interview
808
One day Chef was playing with numbers. He loves Lowest Common Multiple (LCM) too much and he is a very curious guy. He always try to do new things. Now he want to make a large number with it. But he doesn't want to take too many numbers. He is willing to take only three numbers less than or equal to N (not necessarily...
["from fractions import gcd\nfor testCases in range(eval(input())):\n n = eval(input())\n if n == 1:\n print('1')\n elif n == 2:\n print('2')\n elif n == 3:\n print('6')\n else:\n c = n*(n-1)\n k = n - 2\n while True:\n if gcd(k,n-1) == 1 and gcd(k,n) == 1:\n break\n k -= 1\n d = (n-1)*(n - 2)\n k1 = n -...
[{"input": ["2", "9", "7"], "output": ["504", "210"]}]
interview
809
Zaikia has $N$ sticks of distinct positive lengths $A_1,A_2,\dots,A_N$. For no good reason at all, he wants to know if there is a triplet of sticks which when connected end-to-end will form a non-trivial triangle. Here non-trivial refers to a triangle with positive area. Help Zaikia know if such a triplet exists or not...
["#from itertools import combinations as c\r\nn=int(input());l=list(map(int,input().split()))\r\nl1=[]\r\nif(n<3):\r\n print(\"NO\")\r\nelse:\r\n l.sort()\r\n for i in range(n-2):\r\n if(l[i]+l[i+1]>l[i+2]):\r\n l1.append([l[i+2],l[i+1],l[i]])\r\nif(len(l1)!=0):\r\n print(\"YES\")\r\n p...
[{"input": ["5", "4 2 10 3 5"], "output": ["YES", "5 4 3"]}]
interview
810
Chef is frustrated in this lockown. So to overcome this he plans to travel various mountains. He is very strange so he sets some conditions for $each$ Type 2 query(mentioned below) (i.e. $1$ $i$) : - Let Chef has travelled till $ith$ mountain from left to right. - He does not like to travel the mountain with the heigh...
["# cook your dish here\nfrom bisect import bisect_left \n \ndef BinarySearch(a, x): \n i = bisect_left(a, x) \n if i != len(a) and a[i] == x: \n return i \n else: \n return -1\n\nfor _t in range(int(input())):\n _n, q = list(map(int, input().split()))\n mounts = list(map(int, input().split()))\n for _q in range(q):\...
[{"input": ["1", "10 5", "1 3 5 4 5 6 7 8 4 5", "1 7", "1 3", "1 1", "0 2 7", "1 3"], "output": ["-1", "6", "5", "5"]}]
interview
811
Indian National Olympiad in Informatics 2013 Calvin wakes up early one morning and finds that all his friends in the hostel are asleep. To amuse himself, he decides to play the following game : he draws a sequence of N squares on the ground, numbered 1 to N, and writes an integer in each square. He starts at square k (...
["try:\n n, k=map(int, input().split())\n arr=list(map(int, input().split()))\n forward = [0]*(n+1)\n backward= [0]*(n+1)\n backward[0]=arr[0]\n backward[1]=arr[0]+arr[1]\n for i in range(k, n):\n forward[i]=arr[i] +max(forward[i-1],forward[i-2])\n\n for i in range(2, n):\n backward[i]=a...
[{"input": ["and output corresponding to the example above.", "Sample input", "5 2", "5 3 -2 1 1", "Sample output", "11", "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 ex...
interview
812
DevuLand is a very strange place. There are n villages in it. Some of the villages are occupied by dinosaurs while the remaining ones by villagers. You are given the information of DevuLand by an array D of size n. If D[i] is non-negative, it means that there are D[i] villagers in that village. Otherwise, it mean...
["# cook your dish here\nfor _ in range(int(input())):\n n = int(input())\n a = list(map(int, input().split()))\n curr = 0\n ans = 0\n for x in a:\n curr += x\n ans += abs(curr)\n print(ans)"]
[{"input": ["3", "2", "5 -5", "2", "-5 5", "3", "1 2 -3"], "output": ["5", "5", "4"]}]
interview
813
Harsh, like usual, started studying 6 months before for his end semester examinations. He was going to complete his 8th revision of the whole syllabus, when suddenly Pranav showed up in his room with the last year's question paper for their algorithms course. This paper contains a problem which both of them couldn't so...
["#dt = {} for i in x: dt[i] = dt.get(i,0)+1\r\nimport sys;input = sys.stdin.readline\r\ninp,ip = lambda :int(input()),lambda :[int(w) for w in input().split()]\r\n\r\nn,k = ip()\r\nx = ip()\r\nx.sort()\r\nif k == 1:\r\n a = x[n//2]\r\n b = x[n//2-1]\r\nelse:\r\n s = sum(x)\r\n a = s//n\r\n b = a + 1\r\n...
[{"input": ["3 1", "6 1 7"], "output": ["6"]}]
interview
814
Tzuyu gave Nayeon a strip of $N$ cells (numbered $1$ through $N$) for her birthday. This strip is described by a sequence $A_1, A_2, \ldots, A_N$, where for each valid $i$, the $i$-th cell is blocked if $A_i = 1$ or free if $A_i = 0$. Tzuyu and Nayeon are going to use it to play a game with the following rules: - The p...
["for _ in range(int(input())):\n n=int(input())\n\n\n def maxConsequtiveOnes(lst):\n _max = 0\n _ones = [0]\n for i in lst:\n if i == 0:\n _max += 1\n if i == 1:\n _max = 0\n _ones.append(_max)\n return max(_ones)\n\n\n a = list(map(int, input().split()))\n b = maxConsequtiveOnes(a)\n if (b % 2 == 0):\...
[{"input": ["4", "7", "1 1 0 0 0 1 1", "8", "1 0 1 1 1 0 0 1", "4", "1 1 0 1", "4", "1 1 1 1"], "output": ["Yes", "No", "Yes", "No"]}]
interview
815
Johnny has some difficulty memorizing the small prime numbers. So, his computer science teacher has asked him to play with the following puzzle game frequently. The puzzle is a 3x3 board consisting of numbers from 1 to 9. The objective of the puzzle is to swap the tiles until the following final state is reached: 1 2 3...
["# cook your dish here\r\nfrom collections import deque\r\nprimes = {2,3,5,7,11,13,17}\r\nedges = [(0,3),(0,1),(1,2),(1,4),(2,5),(3,4),(3,6),(4,5),(4,7),(5,8),(6,7),(7,8)]\r\nx = [1,2,3,4,5,6,7,8,9]\r\navail = {tuple(x):0}\r\nq = deque([x])\r\nwhile q:\r\n curr = q.popleft();\r\n for e in edges:\r\n if cu...
[{"input": ["2", "", "7 3 2 ", "4 1 5 ", "6 8 9 ", "", "9 8 5 ", "2 4 1 ", "3 7 6 ", "", ""], "output": ["6", "-1"]}]
interview
816
This is another problem about Indraneel's library. His library has one long shelf. His books are numbered and he identifies the books by their number. Each book has a distinct number. He has lost many books, since many of his friends borrow his books and never bother to return them. He does not want to lose any more bo...
["def bookList():\r\n numBooks=int(input())\r\n bookNum=[int(x) for x in input().split()]\r\n takenBooks=int(input())\r\n for i in range(takenBooks):\r\n takenBookPos=(int(input()))\r\n a=bookNum[takenBookPos-1]\r\n print(a)\r\n bookNum.remove(a)\r\n\r\nbookList()\r\n", "########...
[{"input": ["5", "26 1 42 15 3", "2", "3", "4"], "output": ["42", "3"]}]
interview
817
Amit is going on a date and he wants to gift his date an array of positive numbers. But he is running short on money. He already has an array of numbers in design. Cost of an array of numbers is the sum of elements in it. But he wants to minimize the cost of making it. So he does the following number of operations one...
["for _ in range(int(input())):\r\n n=int(input())\r\n l=list(map(int,input().split()))\r\n su=l[0]\r\n for i in range(1,n):\r\n su^=l[i]\r\n print(su)", "# cook your dish here\nt = int(input())\nfor _ in range(t):\n n = int(input())\n a = list(map(int,input().split()))\n x = 0\n for i...
[{"input": ["3", "5", "8 4 1 5 0", "5", "1 2 4 0 8", "2", "10 10"], "output": ["8", "15", "0"]}]
interview
818
We all know Gru loves Agnes very much. One day Agnes asked Gru to answer some of her queries. She lined up $N$ minions in a straight line from $1$ to $N$. You are given an array $A$ which contains the height of minions. Agnes will ask him several queries. In each query, Gru has to tell whether the bitwise AND of $A[L...
["# cook your dish here\nfor _ in range(int(input())):\n n=int(input())\n a=[int(x) for x in input().split()]\n sum=0\n for i in range(n):\n if a[i]%2==0:\n sum+=1\n a[i]=sum \n q=int(input())\n while q:\n l,r=map(int,input().split())\n if l!=1:\n c=a[r-1]-a[l-2]\n else:\n c=a[r-1] \n if c==0:\n print(\"O...
[{"input": ["1", "5", "1 3 2 4 5", "3", "1 2", "1 5", "3 4"], "output": ["ODD", "EVEN", "EVEN"]}]
interview
819
Motu wants to learn Cricket from a coach, but firstly coach wants to test his IQ level, so he gave Motu $1$ $Red$ $ball$ and $1$ $Black$ $ball$ , and asked him to buy other $x – 1$ red balls and other $y – 1$ black balls from the market. But he put some conditions on buying balls, that if he has $R$ red and $B$ black b...
["T=int(input())\nwhile T:\n x,y=map(int,input().split())\n while(y): \n x, y = y, x % y\n if x==1:\n print(\"YES\")\n else:\n print(\"NO\")\n T-=1", "import math\nT=int(input())\nwhile T:\n\ta,b=map(int,input().split())\n\tif math.gcd(a,b)==1:\n\t\tprint(\"YES\")\n\telse:\n\t\tprint...
[{"input": ["2", "1 2", "2 3"], "output": ["YES", "YES"]}]
interview
820
The Little Elephant from the Zoo of Lviv is going to the Birthday Party of the Big Hippo tomorrow. Now he wants to prepare a gift for the Big Hippo. He has N balloons, numbered from 1 to N. The i-th balloon has the color Ci and it costs Pi dollars. The gift for the Big Hippo will be any subset (chosen randomly, possi...
["# cook your dish here\nfor _ in range(int(input())):\n n,m = list(map(int,input().split()))\n colors = [0]*41; cost = [0]*41\n color = 0\n for i in range(n):\n cc,pp = list(map(int,input().split()))\n colors[cc] += 1\n cost[cc] += pp\n for i in colors:\n if i>0: color += 1\n...
[{"input": ["2", "2 2", "1 4", "2 7", "2 1", "1 4", "2 7"], "output": ["11.000000000", "7.333333333"]}]
interview
821
You are given $n$ intervals on the $X$ axis. Each interval $i$ is specified by its ends $[L_i, R_i]$. You want to color each interval either blue or yellow. After coloring all the intervals, the $X$ axis will will have $4$ colors: - White, the part of $X$ axis contained in no interval - Blue, the part of $X$ axis conta...
["for _ in range(int(input())):\n n = int(input())\n ls = []\n rs = []\n lrs = []\n\n for i in range(n):\n l, r = map(int, input().split())\n ls.append(l)\n rs.append(r)\n lrs.append((l, r, i))\n\n lrs.sort()\n\n c = 0\n maxi = -1\n\n res = [-1] * n\n for l, r, i in lrs:\n if ls[i] > maxi:\n maxi = rs[i]\n res...
[{"input": ["1", "3", "3 7", "2 5", "6 9"], "output": ["100"]}]
interview
822
Doubleville, a small town in Texas, was attacked by the aliens. They have abducted some of the residents and taken them to the a spaceship orbiting around earth. After some (quite unpleasant) human experiments, the aliens cloned the victims, and released multiple copies of them back in Doubleville. So now it might happ...
["def main():\n while True:\n [n, m] = [int(i) for i in input().split()]\n if n == m and n == 0:\n break\n cache = {}\n for i in range(n):\n dna = input().rstrip('\\n')\n if dna in cac...
[{"input": ["9 6", "AAAAAA", "ACACAC", "GTTTTG", "ACACAC", "GTTTTG", "ACACAC", "ACACAC", "TCCCCC", "TCCCCC", "0 0", "", ""], "output": ["1", "2", "0", "1", "0", "0", "0", "0", "0"]}]
interview
823
Chef likes problems which using some math. Now he asks you to solve next one. You have 4 integers, Chef wondering is there non-empty subset which has sum equals 0. -----Input----- The first line of input contains T - number of test cases. Each of the next T lines containing four pairwise distinct integer numbers - a,...
["# cook your dish here\n\n# cook your dish here\n\n \n\nt = int(input())\nwhile t:\n t-=1\n c=0\n ar=[int(i) for i in input().strip().split()]\n for i in range(1,16):\n b=bin(i)[2:].zfill(4)\n s=0\n for i in range(4):\n if b[i]=='1':\n s+=ar[i]\n \n if(s==0):\n c=1\n break\n \n print(\"Yes\" if c==1 else...
[{"input": ["3", "1 2 0 3", "1 2 4 -1", "1 2 3 4"], "output": ["Yes", "Yes", "No"]}]
interview
824
Corruption is on the rise in the country of Freedonia, Gru's home. Gru wants to end this for good and for that he needs the help of his beloved minions. This corruption network can be represented in the form of a tree having N$N$ nodes and N−1$N-1$ edges. The nodes are numbered from 1$1$ to N$N$, and the tree is rooted...
["from sys import stdin,stdout\r\ninput=stdin.readline\r\nn=int(input())\r\na=[[] for i in range(n)]\r\nfor i in range(n-1):\r\n u,v=map(int,input().split())\r\n a[u-1].append(v-1)\r\n a[v-1].append(u-1)\r\nb=[0]*n\r\nvis=[0]*n\r\nst=[(0,0)]\r\nvis[0]=1\r\npa=[0]*n\r\nwhile st:\r\n x,y=st.pop()\r\n b[x]=...
[{"input": ["7", "1 2", "1 3", "2 4", "2 5", "3 6", "3 7"], "output": ["2"]}]
interview
825
Our Chef is doing what he is best at, COOKING A BARBECUE for his guests. He has invited all of us, and taking the help of his apprentice to smoke the barbecues. The chef has got BBQ sticks, each can take N fillings, and he presents N distinctly filled sticks in front his guests forming a N*N matrix But here is the pr...
["testcase = int(input())\nfor case in range(testcase):\n n = int(input())\n print(2**(n-2)+1)\n print('\\n') ", "# Author: Karlheinz Jung\n# Compiler: Python @ ideone.com\n# Computer: Rabbit 286\n# Contest: ALGOTHIKA 2012\n# Problem: Barbeque sticks (ALGBBQ)\n\nN=eval(input())\nfor t in range(N):\n print(2**(eval(inpu...
[{"input": ["1", "4"], "output": ["5"]}]
interview
826
Let's consider a rectangular table R consisting of N rows and M columns. Rows are enumerated from 1 to N from top to bottom. Columns are enumerated from 1 to M from left to right. Each element of R is a non-negative integer. R is called steady if the sum of elements in the ith row is not less then the sum of elements ...
["# This is not my code, it's Snehasish Karmakar's. Refer to http://www.codechef\u00a0\u00a0\u00a0\u00a0.com/viewsolution/7153774\n# for original version.\n# Submitting it to try and work out if it can be sped up.\n\ndef compute_nCr(n,r) :\n C[0][0]=1\n for i in range(1,n+1) :\n# print \"i\",i\n C[i][0]=1\n fo...
[{"input": ["3", "1 1", "2 2", "2 3"], "output": ["2", "25", "273"]}]
interview
827
Limak has a string S, that consists of N lowercase English letters. Limak then created a new string by repeating S exactly K times. For example, for S = "abcb" and K = 2, he would get "abcbabcb". Your task is to count the number of subsequences "ab" (not necessarily consecutive) in the new string. In other words, find ...
["try:\r\n t=int(input())\r\n for i in range(t):\r\n n,k=map(int,input().split())\r\n s=input()\r\n l=[-1]*len(s)\r\n numb=s.count('b')\r\n x=numb\r\n for j in range(len(s)):\r\n if(s[j]=='a'):\r\n l[j]=numb\r\n if(s[j]=='b'):\r\n ...
[{"input": ["3", "4 2", "abcb", "7 1", "aayzbaa", "12 80123123", "abzbabzbazab", "", ""], "output": ["6", "2", "64197148392731290"]}]
interview
828
Chef lives in a big apartment in Chefland. The apartment charges maintenance fees that he is supposed to pay monthly on time. But Chef is a lazy person and sometimes misses the deadlines. The apartment charges 1000 Rs per month as maintenance fees. Also, they also charge a one-time fine of 100 Rs for each of the late p...
["for i in range(int(input())):\n a=int(input())\n b=input().split()\n if '0' in b:\n print(100*(a-b.index('0'))+b.count('0')*1000)\n else:\n print(0)\n", "for i in range(int(input())):\r\n x=int(input())\r\n y=input().split()\r\n if '0' in y:\r\n print(100*(x-y.index('0'))+y.count('0')*...
[{"input": ["4", "2", "1 1", "2", "0 0", "3", "0 1 0", "2", "0 1", "", ""], "output": ["0", "2200", "2300", "1200"]}]
interview
829
Zonal Computing Olympiad 2013, 10 Nov 2012 N teams participate in a league cricket tournament on Mars, where each pair of distinct teams plays each other exactly once. Thus, there are a total of (N × (N-1))/2 matches. An expert has assigned a strength to each team, a positive integer. Strangely, the Martian crowds love...
["# cook your dish here\n# cook your dish here\nfrom itertools import combinations\nn = int(input())\nt = list(combinations(list(map(int, input().split())), 2))\nar = 0\nfor i in t:\n ar += abs(i[0] - i[1])\nprint(ar)", "# cook your dish here\nn=int(input())\nstrength=list(map(int,input().split()))\nrevenue=0\nfor i...
[{"input": ["4", "3 10 3 5", "Sample output", "23", "Test data", "In all subtasks, the strength of each team is an integer between 1 and 1,000 inclusive.", "Subtask 1 (30 marks) : 2 \u2264 N \u2264 1,000.", "Subtask 2 (70 marks) : 2 \u2264 N \u2264 200,000.", "Live evaluation data", "Subtask 1 : Testcases 0,1,2."...
interview
830
Vivek was quite bored with the lockdown, so he came up with an interesting task. He successfully completed this task and now, he would like you to solve it. You are given two strings $A$ and $B$, each with length $N$. Let's index the characters in each string from $0$ ― for each $i$ ($0 \le i < N$), the $i+1$-th charac...
["for _ in range(int(input())):\n n=int(input())\n a=input()\n b=input()\n l=[]\n flag=0\n for i in range(n):\n if b[i]!=a[i]:\n if b[i] in a and b[i]<a[i]:\n l.append(b[i])\n else:\n flag=1\n break\n if flag==1:\n print(-1)\n else:\n if l==[]:\n print(0)\n else:\n l = sorted(list(set(l)), reverse ...
[{"input": ["3", "5", "abcab", "aabab", "3", "aaa", "aab", "2", "de", "cd"], "output": ["2", "3 1 2 4", "3 0 1 3", "-1", "-1"]}]
interview
831
Bear Limak has a sequence of N non-negative integers A1, A2, ..., AN. He defines the score of a segment (consecutive subsequence) as its sum of elements modulo P (not necessarily prime). Find the maximum score of a non-empty segment, and also find the number of segments with this maximum score. -----Input----- First l...
["for _ in range(int(input())):\n n,m=input().split()\n n,m=int(n),int(m)\n x=y=c=0\n l=list(map(int,input().split()))\n for i in range(n):\n for j in range(i,n):\n x=x+l[j]\n if (x%m)>y:\n y=x%m\n c=1\n elif y==(x%m):\n c+=1\n x = 0\n print(y,c)\n\n", "for _ in range(int(input())):\n n,p=map(int,input...
[{"input": ["4", "2 3", "1 2", "3 5", "2 4 3", "3 100", "1 3 5", "4 3", "1 2 3 4"], "output": ["2 1", "4 2", "9 1", "2 2"]}]
interview
832
Chef has a sequence $A_1, A_2, \ldots, A_N$. This sequence has exactly $2^N$ subsequences. Chef considers a subsequence of $A$ interesting if its size is exactly $K$ and the sum of all its elements is minimum possible, i.e. there is no subsequence with size $K$ which has a smaller sum. Help Chef find the number of inte...
["def fact(n):\n if n<2:\n return 1\n return n * fact(n-1)\n \ndef ncr(n, r):\n return fact(n)// (fact(r)*fact(n-r))\n \nt=int(input())\n\nfor _ in range(t):\n n, k = list(map(int, input().split()))\n a = list(map(int, input().split()))\n a.sort()\n count_z = a.count(a[k-1])\n count_z_seq = a[:k].count(a[k-1])\n \n pr...
[{"input": ["1", "4 2", "1 2 3 4"], "output": ["1"]}]
interview
833
Galileo's latest project involves determining the density of stars in certain regions of the sky. For this purpose he started looking for datasets online, and discovered a dataset on Newton's blog. Newton had decomposed the night sky into a Voronoi tessellation with the generators arranged in a grid. He has stored the ...
["import sys\n\ndef main():\n s=sys.stdin.readline\n n, m = list(map(int, s().split()))\n nums={}\n for i in range(1, n+1):\n nums[i]=list(map(int, s().split()))\n cases=int(s())\n for case in range(cases):\n px, py, qx, qy = list(map(int, s().split()))\n ans=[]\n for i in range(px, qx+1):\n for j in range(py-1, ...
[{"input": ["3 3", "10 10 10", "10 10 10", "10 10 10", "4", "1 1 1 1", "1 1 3 3", "2 1 3 3", "3 1 3 3"], "output": ["10", "90", "60", "30"]}]
interview
834
Striver$Striver$ wants to strive hard in order to reach his goals, hence asks his mentor to give him a question for which he has to strive hard. The mentor gives Striver$Striver$ a N$N$ X N$N$ matrix consisting of lowercase characters (′a′$'a'$ to ′z′$'z'$) and Q$Q$ queries. Every query consists of X$X$ and Y$Y$. From...
["a=int(input())\r\nfor _ in range(a):\r\n c,d=list(map(int,input().split()))\r\n crr=[[[0,0] for i in range(c+1)] for j in range(c+1)]\r\n trr=[]\r\n for i in range(c):\r\n kk=list(input().split())\r\n trr.append(kk)\r\n for i in range(1,c+1):\r\n for j in range(1,c+1):\r\n ...
[{"input": ["1", "3 2", "a b a", "a c d", "b a b", "1 3", "3 3"], "output": ["1", "2"]}]
interview
835
Chef is stuck in a two dimensional maze having N rows and M columns. He needs to get out of the maze as soon as possible and arrive at the kitchen in order to serve his hungry customers. But, he can get out of the maze only if he is able to successfully find any magical path in the given maze. A path is defined as mag...
["t = eval(input())\nfor _ in range(t):\n n, m = list(map(int, input().split()))\n if n*m == 2:\n print('Yes')\n elif (n*m)%2 == 0 and m != 1 and n != 1:\n print('Yes')\n else:\n print('No')", "t=int(input())\nfor _ in range(t):\n n,m=input().strip().split()\n if (n=='1' and m=='2') or (n=='2' and m=='1'):\n print(...
[{"input": ["1", "2 2"], "output": ["Yes"]}]
interview
836
Little Egor is a huge movie fan. He likes watching different kinds of movies: from drama movies to comedy movies, from teen movies to horror movies. He is planning to visit cinema this weekend, but he's not sure which movie he should watch. There are n movies to watch during this weekend. Each movie can be characterize...
["def bestMovie():\n tests=int(input())\n for t in range(tests):\n n = int(input())\n L = list(map(int, input().split()))\n R = list(map(int, input().split()))\n maxIndex = -1\n maxValue = 0\n for i in range(n):\n prod = L[i]*R[i]\n if maxValue < prod:\n maxValue = prod\n maxIndex = i\n elif maxValue ...
[{"input": ["2", "2", "1 2", "2 1", "4", "2 1 4 1", "2 4 1 4"], "output": ["1", "2"]}]
interview
837
Find sum of all the numbers that are multiples of 10 and are less than or equal to a given number "N". (quotes for clarity and be careful of integer overflow) -----Input----- Input will start with an integer T the count of test cases, each case will have an integer N. -----Output----- Output each values, on a newline...
["for t in range(eval(input())):\n n=eval(input())\n n-=n%10\n n/=10\n print(n*(n+1)/2*10)", "def tenn():\n t=eval(input())\n for i in range(t):\n a=eval(input())\n r=a/10\n t=(r*(r+1))/2\n print(t*10)\ntenn()\n", "t = int(input())\nl = list()\n\nfor i in range(t):\n n = int(input()) / 10\n l.append(n)\n \nfor n in...
[{"input": ["1", "10"], "output": ["10"]}]
interview
838
Chef and his girlfriend are going to have a promenade. They are walking along the straight road which consists of segments placed one by one. Before walking Chef and his girlfriend stay at the beginning of the first segment, they want to achieve the end of the last segment. There are few problems: - At the beginnin...
["T = int(input())\nfor i in range(T):\n x = int(input())\n l= [int(x) for x in input().split()]\n t=[]\n for i in range(len(l)):\n t.append(l[i]+i) \n print(max(t))", "# cook your dish here\nt=int(input())\nwhile t:\n t=t-1\n n = int(input())\n l = list(map(int,input().split()))\n l.reverse()\n c = 0\n for i in range...
[{"input": ["2", "5", "6 5 4 3 2", "5", "3 4 3 1 1"], "output": ["6", "5"]}]
interview
839
Dhiraj loves Chocolates.He loves chocolates so much that he can eat up to $1000$ chocolates a day. But his mom is fed up by this habit of him and decides to take things in her hand. Its diwali Season and Dhiraj has got a lot of boxes of chocolates and Dhiraj's mom is afraid that dhiraj might eat all boxes of chocolates...
["def isSubsetSum(arr, n, sum): \n subset = [ [False for j in range(sum + 1)] for i in range(3) ] \n for i in range(n + 1): \n for j in range(sum + 1): \n if (j == 0):subset[i % 2][j] = True\n elif (i == 0):subset[i % 2][j] = False\n elif (arr[i - 1] <= j):subset[i % 2][...
[{"input": ["2", "20", "5", "8 7 2 10 5", "11", "4", "6 8 2 10"], "output": ["1", "0"]}]
interview
840
The chef is trying to solve some pattern problems, Chef wants your help to code it. Chef has one number K(odd) to form a new pattern. Help the chef to code this pattern problem. -----Input:----- - First-line will contain $T$, the number of test cases. Then the test cases follow. - Each test case contains a single lin...
["def func(num):\r\n for i in range(num):\r\n if i < num//2 + 1:\r\n print(' '*i, end='')\r\n print('*')\r\n else:\r\n print(' '*(num-i-1), end='')\r\n print('*')\r\n\r\n\r\n\r\nfor _ in range(int(input())):\r\n num = int(input())\r\n func(num)\r\n", "#...
[{"input": ["4", "1", "3", "5", "7"], "output": ["*", "*", "*", "*", "*", "*", "*", "*", "*", "*", "*", "*", "*", "*", "*", "*"]}]
interview
841
The Petrozavodsk camp takes place in about one month. Jafar wants to participate in the camp, but guess what? His coach is Yalalovichik. Yalalovichik is a legendary coach, famous in the history of competitive programming. However, he is only willing to send to the camp students who solve really hard problems on Timus. ...
["M = 10 ** 9 + 7\nfor _ in range(int(input())):\n s,p,m,r = list(map(int, input())),0,1,0\n for d in reversed(s):\n p += d * m\n m = m * 10 % M\n for d in s:\n r = (r * m + p) % M\n p = (p * 10 - (m - 1) * d) % M\n print(r)", "M = 10 ** 9 + 7\n\nt = int(input())\nfor _ in range(...
[{"input": ["1", "123", ""], "output": ["123231312"]}]
interview
842
The chef is trying to solve some pattern problems, Chef wants your help to code it. Chef has one number K to form a new pattern. Help the chef to code this pattern problem. -----Input:----- - First-line will contain $T$, the number of test cases. Then the test cases follow. - Each test case contains a single line of ...
["t=int(input())\r\nfor _ in range(t):\r\n n=int(input())\r\n b=1\r\n if n%2:\r\n c=n-2\r\n for j in range(n//2):\r\n print(\" \"*j+str(b) +\" \"*c+ str(b))\r\n b+=1\r\n c-=2\r\n print(\" \"*(n//2)+str(b)+\" \"*(n//2))\r\n b+=1\r\n c=1\r\n ...
[{"input": ["3", "5", "3", "4"], "output": ["1 1", "2 2", "3", "4 4", "5 5", "1 1", "2", "3 3", "1 1", "22", "33", "4 4"]}]
interview
843
You are given N integer sequences A1, A2, ..., AN. Each of these sequences contains N elements. You should pick N elements, one from each sequence; let's denote the element picked from sequence Ai by Ei. For each i (2 ≤ i ≤ N), Ei should be strictly greater than Ei-1. Compute the maximum possible value of E1 + E2 + ......
["t=int(input())\nfor _ in range(t):\n n=int(input())\n \n grid=[]\n for _ in range(n):\n temp=[]\n temp=list(map(int,input().strip().split()))\n temp.sort()\n grid.append(temp)\n \n \n curr=max(grid[n-1])\n total=curr\n for i in range(n-2,0-1,-1):\n flag=0\n for j in range(n-1,0-1,-1):\n if grid[i][j]<curr:\n...
[{"input": ["1", "3", "1 2 3", "4 5 6", "7 8 9"], "output": ["18"]}]
interview
844
Little kids, Jack and Evan like playing their favorite game Glass-and-Stone. Today they want to play something new and came across Twitter on their father's laptop. They saw it for the first time but were already getting bored to see a bunch of sentences having at most 140 characters each. The only thing they liked to...
["def getInput():\n N_k = input().split()\n N =int(N_k[0])\n k =int(N_k[1])\n list = []\n output = []\n count = 0\n for i in range(0,k):\n val = input()\n if(val!=\"CLOSEALL\"):\n val=val.split()\n val = int (val[1])\n if val not in list:\n count= count +1\n list.append(val)\n else:\n list.remove(val...
[{"input": ["3 6", "CLICK 1", "CLICK 2", "CLICK 3", "CLICK 2", "CLOSEALL", "CLICK 1"], "output": ["1", "2", "3", "2", "0", "1"]}]
interview
845
Give me Biscuit Sunny wants to make slices of biscuit of size c * d into identical pieces. but each piece is a square having maximum possible side length with no left over piece of biscuit. Input Format The first line contains an integer N. N lines follow. Each line contains two space separated integers c and d. ...
["def __gcd(a, b): \n \n # Everything divides 0 \n if (a == 0 or b == 0): \n return 0; \n \n # base case \n if (a == b): \n return a; \n \n # a is greater \n if (a > b): \n return __gcd(a - b, b); \n return __gcd(a, b - a); \n \n# Function to find \n# number of squares \ndef NumberOfSquares(x, y): \n \n # Here i...
[{"input": ["2", "2 2", "6 9"], "output": ["1", "6"]}]
interview
846
-----Problem Statement----- Harry Potter has one biscuit and zero rupee in his pocket. He will perform the following operations exactly $K$ times in total, in the order he likes: - Hit his pocket, which magically increases the number of biscuits by one. - Exchange $A$ biscuits to $1$ rupee. - Exchange $1$ rupee to $B$ ...
["K,A,B = map(int,input().split())\r\n \r\nif A + 2 > B:\r\n print(K + 1)\r\n return\r\n \r\nstart = A - 1\r\nK -= start\r\nans = K//2 * (B-A) + K%2 + start + 1\r\nprint(ans)", "import sys\r\n# sys.stdin = open('input.txt', 'r') \r\n# sys.stdout = open('output.txt', 'w')\r\n \r\nimport math\r\nimport collections\...
[{"input": ["4 2 6"], "output": ["7"]}]
interview
847
Did you know that the people of America eat around 100 acres of pizza per day ? Having read this fact on internet, two chefs from the Elephant city, Arjuna and Bhima are set to make pizza popular in India. They organized a social awareness camp, where N people ( other than these two ) sit around a large pizza. To make ...
["a= [0, 0, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 0, 5, 2, 2, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 2, 7, 4, 0, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 2, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1,...
[{"input": ["4", "2", "4", "5", "6"], "output": ["Arjuna", "Arjuna", "Bhima", "Arjuna"]}]
interview
848
Coach Moony wants the best team to represent their college in ICPC. He has $N$ students standing in a circle with certain rating $X_i$ on a competitive coding platform. It is an established fact that any coder with more rating on the platform is a better coder. Moony wants to send his best $3$ coders based upon ...
["# cook your dish here\r\n#Moony and ICPC team\r\nT = int(input())\r\n\r\nfor i in range(T):\r\n N,data = int(input()),list(map(int,input().split()))\r\n if(N==3):\r\n print(sum(data))\r\n else:\r\n best = data[0]+data[1]+data[2]\r\n overall = best\r\n k=len(data)\r\n for i ...
[{"input": ["1", "7", "10 40 30 30 20 0 0"], "output": ["100"]}]
interview
849
We all know how great ABD aka AB-DE-VILLIERS is. However his team mates were jealous of him and posed a problem for him to solve.The problem description is as follows : Given an array of integers,find the length of the largest subarray(contiguous) of the given array with the maximum possible GCD (Greatest Common Divis...
["n=eval(input())\na=list(map(int,input().split()))\nc=m=0\nmaxi=max(a)\nfor i in range(n):\n if a[i]==maxi:\n c+=1\n m=max(c,m)\n else:\n c=0\nprint(m) ", "from fractions import gcd as G\nn=eval(input())\nflag=1\narr=list(map(int,input().split()))\na=max(arr)\nbest = 0\nI_I = 0\nwhile I_I<n:\n if arr[I_I]==a:\n k=...
[{"input": ["4", "2 4 8 3"], "output": ["1"]}]
interview
850
Chef has a sequence of positive integers $A_1, A_2, \ldots, A_N$. He wants to split this sequence into two non-empty (not necessarily contiguous) subsequences $B$ and $C$ such that $\mathrm{GCD}\,(B) + \mathrm{GCD}\,(C)$ is maximum possible. Help him find this maximum value. Note: The greatest common divisor (GCD) of a...
["from math import gcd\r\n\r\n__author__ = 'Prateek'\r\n\r\n\r\ndef test():\r\n n = int(input())\r\n a = list(map(int, input().split()))\r\n a = list(set(a))\r\n n = len(a)\r\n if len(a) == 1:\r\n print(2 * a[0])\r\n return\r\n g1 = [0 for i in range(n)]\r\n g2 = [0 for i in range(n)]...
[{"input": ["1 ", "4 ", "4 4 7 6 ", ""], "output": ["9"]}]
interview
851
Mr. X has come up with a new string compression algorithm. Consider a string of length N which contains up to K distinct characters. The compression algorithm works as follows: Replace each maximal contiguous substring containing only one distinct character (repeated an arbitrary number of times) and replace it by 2 va...
["for _ in range(int(input())):\n\tn,k=map(int,input().split())\n\tprint(((2*n*(k-1))+2)/k)", "for _ in range(int(input())):\r\n\tn,k=map(int,input().split())\r\n\ta=((2*n*(k-1))+2)/k\r\n\tprint(a)", "# cook your dish here\nfor _ in range(int(input())):\n n,k=map(int,input().split())\n print(2+(n-1)*((2)-(2/k)))"...
[{"input": ["2", "3 1", "3 2", ""], "output": ["2.0", "4.0"]}]
interview
852
The chef is trying to decode some pattern problems, Chef wants your help to code it. Chef has one number K to form a new pattern. Help the chef to code this pattern problem. -----Input:----- - First-line will contain $T$, the number of test cases. Then the test cases follow. - Each test case contains a single line of...
["t=int(input())\nfor t in range(t):\n n=int(input())\n for i in range(0,n):\n for j in range(0,n):\n if i%2==0:\n if j%2==0:\n print(0,end=\"\")\n else:\n print(1,end=\"\")\n else:\n if j%2==0:\n ...
[{"input": ["4", "1", "2", "3", "4"], "output": ["0", "01", "10", "010", "101", "010", "0101", "1010", "0101", "1010"]}]
interview
853
The new Formula 1 season is about to begin and Chef has got the chance to work with the Formula 1 technical team. Recently, the pre-season testing ended and the technical team found out that their timing system for qualifying was a little bit buggy. So, they asked Chef to fix it before the season begins. His task i...
["# cook your dish here\nt=int(input())\nfor i in range(t):\n n=int(input())\n if n<101:\n l1=[]\n l2=[]\n d=dict()\n for i in range(1,2*n+1):\n if i%2==0:\n l1.append(int(input()))\n else:\n l2.append(str(input()))\n r1=[]\n for i in l1:\n r1.append(i)\n l1.sort()\n ind=[]\n for i in l1:\n a=r1....
[{"input": ["2", "3", "Hamilton", "75000", "Vettel", "76000", "Bottas", "75500", "2", "Leclerc", "666666", "Verstappen", "666777"], "output": ["Hamilton", "Bottas", "Vettel", "Leclerc", "Verstappen"]}]
interview
854
A beautiful sequence is defined as a sequence that do not have any repeating elements in it. You will be given any random sequence of integers, and you have to tell whether it is a beautiful sequence or not. -----Input:----- - The first line of the input contains a single integer $T$. $T$ denoting the number of test ...
["# cook your dish here\nfor _ in range(int(input())):\n n = int(input())\n arr = list(map(int,input().split()))\n l = []\n for i in range(0, len(arr)): \n for j in range(i+1, len(arr)): \n if(arr[i] == arr[j]): \n l.append(arr[j])\n if (len(l) ==0):\n print...
[{"input": ["2", "4", "1 2 3 4", "6", "1 2 3 5 1 4"], "output": ["prekrasnyy", "ne krasivo"]}]
interview
855
Accepts a string from the user and print the reverse string as the output without using any built-in function. -----Input:----- Each testcase contains of a single line of input, a string. -----Output:----- For each testcase, output in a single line answer, the reverse string. -----Sample Input:----- 1 Tracy -----Sa...
["oo = int(input())\r\nfor i in range(oo):\r\n\tval = input()\r\n\tprint(val[::-1])", "for _ in range(int(input())):\n s=input()\n print(s[::-1])", "# cook your dish here\nt=int(input())\nfor _ in range(t):\n a=input()\n for i in range(len(a)-1,-1,-1):print(a[i],end=\"\")\n print()\n ", "t=int(input()...
[{"input": ["1", "Tracy"], "output": ["ycarT"]}]
interview
856
You are given a dataset consisting of $N$ items. Each item is a pair of a word and a boolean denoting whether the given word is a spam word or not. We want to use this dataset for training our latest machine learning model. Thus we want to choose some subset of this dataset as training dataset. We want to make sure tha...
["t = int(input())\n\nfor _ in range(t):\n n = int(input())\n \n a = {}\n \n for i in range(n):\n l = input()\n \n if l not in a:\n a[l] = 1\n else:\n a[l] += 1\n \n done = []\n ans = 0\n \n for i in a:\n if a[i] != 0:\n t...
[{"input": ["3", "3", "abc 0", "abc 1", "efg 1", "7", "fck 1", "fck 0", "fck 1", "body 0", "body 0", "body 0", "ram 0", "5", "vv 1", "vv 0", "vv 0", "vv 1", "vv 1", ""], "output": ["2", "6", "3"]}]
interview
857
Problem description. Dominic Toretto has taken his crew to compete in this years' Race Wars, a crew-on-crew tournament in which each member of one crew competes with a member of the other crew in a quarter mile drag race. Each win counts as one point for the winning crew. Draws and loses are awarded zero points. In the...
["testcases = int(input())\n\nfor i in range(testcases):\n n = int(input())\n my = list(map(int,input().split()))\n opp = list(map(int,input().split()))\n \n my.sort(reverse = True)\n opp.sort(reverse = True)\n \n j = 0\n k = 0\n while(k < n):\n if(my[j] > opp[k]):\n j += 1\n k += 1\n\n print(j)"]
[{"input": ["1", "3", "5 4 1", "5 4 1"], "output": ["2"]}]
interview
858
For Diwali, Chef arranges all $K$ laddus in a row in his sweet shop. Whenever a customer comes to buy laddus, chef follows a rule that each customer must buy all laddus on odd position. After the selection of the laddu, a new row is formed, and again out of these only laddus on odd position are selected. This continues...
["# cook your dish here\nt=int(input())\nwhile t>0:\n n=int(input())\n if n==1:\n print(1)\n else:\n c,num=1,2\n while num<n:\n num*=2\n if num==n:\n print(num)\n else:\n print(num//2)\n t-=1", "# cook your dish here\nfrom math import log\n...
[{"input": ["3", "1", "5", "8"], "output": ["1", "4", "8"]}]
interview
859
Voritex a big data scientist collected huge amount of big data having structure of two rows and n columns. Voritex is storing all the valid data for manipulations and pressing invalid command when data not satisfying the constraints. Voritex likes brute force method and he calls it as BT, he decided to run newly create...
["import math\r\nimport os\r\nimport random\r\nimport re\r\nimport sys\r\n\r\n\r\nr = 100000\r\nprev = 1\r\ns = set()\r\nfor i in range(1, r+1):\r\n now = i ^ prev\r\n s.add(now)\r\n prev = now\r\ns = list(s)\r\nt = int(input())\r\nwhile t > 0:\r\n t -= 1\r\n n, k = list(map(int, input().split()))\r\n\r\...
[{"input": ["2", "4 2", "5 5"], "output": ["2", "0"]}]
interview
860
Minion Chef likes to eat bananas a lot. There are N piles of bananas in front of Chef; for each i (1 ≤ i ≤ N), the i-th pile contains Ai bananas. Chef's mother wants her to eat the bananas and be healthy. She has gone to the office right now and will come back in H hours. Chef would like to make sure that she can finis...
["# cook your dish here\nimport math\nT = int(input())\nfor _ in range(T):\n N, H = map(int, input().split())\n A = list(map(int, input().split()))\n low, high = 1, max(A)\n while low != high:\n time = 0\n mid = (low + high) // 2\n for i in range(N):\n time += math.ceil(A[i] / mid)\n \n if time <= H :\n high =...
[{"input": ["3", "3 3", "1 2 3", "3 4", "1 2 3", "4 5", "4 3 2 7"], "output": ["3", "2", "4"]}]
interview
861
Recall the definition of the Fibonacci numbers: f1 := 1 f2 := 2 fn := fn-1 + fn-2 (n>=3) Given two numbers a and b, calculate how many Fibonacci numbers are in the range [a,b]. -----Input----- The input contains several test cases. Each test case consists of two non-negative integer numbers a and b. Input is te...
["#!/usr/bin/env python\n\nF = [1,1]\ndef fibo():\n for i in range(500):\n F.append(F[-2] + F[-1])\n\ndef main():\n fibo()\n #print len(str(F[-1]))\n #print len(str(10**100))\n while True:\n try:\n A, B = list(map(int, input().strip().split()[:2]))\n if A == 0 and B == 0: break\n print(len([x for x in F if x >=...
[{"input": ["10 100", "1234567890 9876543210", "0 0"], "output": ["5", "4"]}]
interview
862
As we all know, Dhoni loves drinking milk. Once he and Sir Jadeja were invited in the inauguration of a Dairy company in Ranchi. The company had arranged n jars of milk from various breeds of cows , jar number i containing a[i] litres of milk. Since Dhoni loves driking milk more than Sir Jadeja, so Kohli sugges...
["cases = int(input())\n\nfor case in range(cases):\n N, M, K = [int(i) for i in input().split()]\n A = [int(i) for i in input().split()]\n jad = 0\n P = M*K\n\n for milk in A:\n if(milk>P):\n jad += milk-P\n else:\n jad += milk%K\n\n print(jad%1000000007)\n", "import sys\n\nMOD = 10**9+7\nfor __ in range(eval(in...
[{"input": ["1", "3 3 3", "15 8 10"], "output": ["9"]}]
interview
863
The government has invited bids from contractors to run canteens at all railway stations. Contractors will be allowed to bid for the catering contract at more than one station. However, to avoid monopolistic price-fixing, the government has declared that no contractor may bid for a pair of neighbouring stations. The ra...
["n=int(input())\r\nl=[]\r\ndp=[]\r\nd={}\r\nfor i in range(n):\r\n\tl.append(int(input()))\r\n\td[i]=[]\r\n\tdp.append([0,0])\r\n\r\nfor i in range(n-1):\r\n\ta,b=list(map(int,input().split()))\r\n\td[a-1].append(b-1)\r\n\td[b-1].append(a-1)\r\n#print(l)\r\n#print(d)\r\n\r\ndef dfs(ch,pa,visited):\r\n\tdp[ch][1]=l[ch]...
[{"input": ["6", "10", "20", "25", "40", "30", "30", "4 5", "1 3", "3 4", "2 3", "6 4"], "output": ["90"]}]
interview
864
These days, chef is very much interested in Mathematics. He has started attending Recitations too! His hunger for problems is increasing day by day! Today, chef was a given a crumpled maths problem, which he is stuck with . He needs your help to do it Here's what his teacher said: "Find sum of all numbers till N, do no...
["testCases = int(input())\nfor c in range(testCases):\n n, k = list(map(int, input().split()))\n sum = 0\n i = 0\n power = 1\n while i <= n:\n if k**power == i:\n power += 1\n else:\n sum += i\n i +=1 \n answer = \"Case #\" + str(c + 1) + \": \" + str(sum)\n print(answer)", "for j in range(int(input())):\n n,k ...
[{"input": ["2", "10 3", "20 2"], "output": ["Case #1: 43", "Case #2: 180"]}]
interview
865
Given N, count how many permutations of [1, 2, 3, ..., N] satisfy the following property. Let P1, P2, ..., PN denote the permutation. The property we want to satisfy is that there exists an i between 2 and n-1 (inclusive) such that - Pj > Pj + 1 ∀ i ≤ j ≤ N - 1. - Pj > Pj - 1 ∀ 2 ≤ j ≤ i. -----Input----- Fir...
["try:\n \n for _ in range(int(input())):\n n = int(input())\n print(0) if(n==1) else print(pow(2,n-1,10**9+7)-2) \nexcept EOFError:\n pass\n\n ", "for _ in range(int(input())):\n n = int(input())\n print(0) if(n==1) else print(pow(2,n-1,10**9+7)-2) ", "for _ in range(int(input())):\n n = int(input())\n if(n==1):\n ...
[{"input": ["2", "2", "3"], "output": ["0", "2"]}]
interview
866
There are n chef's in Chefland. There is a festival in Chefland in which each chef is asked to vote a person as his best friend. Obviously, a person can't vote himself as his best friend. Note that the best friend relationship is not necessarily bi-directional, i.e. it might be possible that x is best friend of y, but...
["t=int(input())\nfor _ in range(t):\n n=int(input())\n l=list(map(int,input().split()))\n if sum(l)!=n or max(l)==n:\n print('-1')\n else:\n d=dict()\n ans=[-1]*n\n for i in range(0,n):\n d[i]=1\n for i in range(n):\n if l[i]!=0:\n count=l[i]\n for k,v in list(d.items()):\n if count>0 and v==1 and i...
[{"input": ["3", "3", "1 1 1", "3", "3 0 0", "3", "2 2 0"], "output": ["2 3 1", "-1", "-1"]}]
interview
867
For her next karate demonstration, Ada will break some bricks. Ada stacked three bricks on top of each other. Initially, their widths (from top to bottom) are W1,W2,W3. Ada's strength is S. Whenever she hits a stack of bricks, consider the largest k≥0 such that the sum of widths of the topmost k bricks does not exceed ...
["T = int(input())\nfor _ in range(T):\n W = list(map(int, input().strip().split()))\n S = W[0]\n W = W[1:]\n W = W[::-1]\n i = 0\n c = 0\n flag = 0\n while (len(W) != 0 or flag != 1) and i<len(W):\n k = i\n su = 0\n while su <= S and k<len(W)-1:\n su += W[k]\n k += 1\n if su-W[k-1]<=S:\n c += 1\n else:\n ...
[{"input": ["3", "3 1 2 2", "2 1 1 1", "3 2 2 1"], "output": ["2", "2", "2"]}]
interview
868
"It does not matter how slowly you go as long as you do not stop." - Confucius You are given an array $A_1, A_2, \ldots, A_N$ and an integer $K$. For each subarray $S = [A_l, A_{l+1}, \ldots, A_r]$ ($1 \le l \le r \le N$): - Let's define an array $B$ as $S$ concatenated with itself $m$ times, where $m$ is the smallest ...
["from bisect import insort\nfrom math import ceil\nfor _ in range(int(input())):\n n,k=list(map(int,input().split( )))\n array=list(map(int,input().split( )))\n ans=0\n index=[]\n for i in range(1,n+1):\n index.append(ceil(k/(ceil(k/i))))\n for i in range(n):\n count=[0]*(2001)\n temp=[]\n for j in range(i,n):\n ...
[{"input": ["1", "3 3", "1 2 3"], "output": ["3"]}]
interview
869
The entire network is under the inspection and direct control of the Decepticons. They have learned our language through the World Wide Web and can easily understand the messages which are being sent. Sam is trying to send the information to Autobots to locate “ALL SPARK” which is the only source of energy that can be ...
["x = input()\ny = input()\nz = x.find(y)\nif z == -1 :\n print('N')\nelse :\n print('Y')", "m=input().strip().lower()\ns=input().strip().lower()\n\nif m.find(s)==-1:\n print('N')\nelse:\n print('Y')", "import sys\n\ndef main():\n s = sys.stdin.readline\n a = s().strip()\n b = s().strip()\n if b in a:\n print(\"Y\")\n...
[{"input": ["techtrishna online event", "onlin"], "output": ["Y"]}]
interview
870
We say that a binary string (a string containing only characters '0' and '1') is pure if it does not contain either of the strings "0101" or "1010" as a subsequence. Recall that string T is a subsequence of string S if we can delete some of the letters of S (possibly none) such that the resulting string will become T. ...
["# cook your dish here\nimport math;\nfrom math import gcd,sqrt,floor,factorial,ceil\nfrom bisect import bisect_left,bisect_right\nimport bisect;\nimport sys;\nfrom sys import stdin,stdout\nimport os\nsys.setrecursionlimit(pow(10,7))\nimport collections\nfrom collections import defaultdict,Counter\nfrom statistics imp...
[{"input": ["4", "010111101", "1011100001011101", "0110", "111111"], "output": ["2", "3", "0", "0"]}]
interview
871
You are given a grid with $R$ rows (numbered $1$ through $R$) and $C$ columns (numbered $1$ through $C$). Initially, each cell of this grid is either empty, contains an ant or an anteater. Each ant is moving in a fixed direction: up, down, left or right. The anteaters do not move. The movement of ants happens in discre...
["import sys\r\n\r\nt = int(input())\r\n# print(t)\r\nfor _ in range(t):\r\n\tn,m = map(int,input().split());\r\n\ts = [];\r\n\tfor i in range(n):\r\n\t\ts.append(input())\r\n\tans = []\r\n\tfor i in range(n):\r\n\t\tans.append([])\r\n\t\tfor j in range(m):\r\n\t\t\tans[i].append([])\r\n\tfor i in range(n):\r\n\t\tfor ...
[{"input": ["10", "3 3", "R--", "---", "--U", "1 4", "R--R", "2 2", "--", "--", "1 4", "R--L", "1 4", "-R-L", "1 4", "-R#L", "3 3", "R-D", "-#-", "R-U", "3 3", "R-D", "---", "R#U", "3 3", "-D-", "R-L", "-U-", "1 7", "RLLLLLL", ""], "output": ["1", "0", "0", "0", "1", "0", "3", "2", "6", "3"]}]
interview
872
Appy and Chef are participating in a contest. There are $N$ problems in this contest; each problem has a unique problem code between $1$ and $N$ inclusive. Appy and Chef decided to split the problems to solve between them ― Appy should solve the problems whose problem codes are divisible by $A$ but not divisible by $B$...
["for t in range(int(input())):\n n, a , b , k = map(int,input().split())\n solvedbychef = 0\n solvedbyappy = 0\n for i in range(n+1):\n if i % a == 0 and i % b == 0 :\n continue\n elif i%a == 0 :\n solvedbyappy+=1\n elif i%b == 0:\n solvedbychef+=1\n totalsolved = solvedbychef + solvedbyappy\n if totalsolved>...
[{"input": ["1", "6 2 3 3"], "output": ["Win"]}]
interview
873
The following graph G is called a Petersen graph and its vertices have been numbered from 0 to 9. Some letters have also been assigned to vertices of G, as can be seen from the following picture: Let's consider a walk W in graph G, which consists of L vertices W1, W2, ..., WL, such that Wi is connected with Wi + 1 f...
["let_to_num = {'A':[0,5], 'B':[1,6], 'C':[2,7], 'D':[3,8], 'E':[4,9]}\n\nnum_to_let = {0:'A', 1:'B', 2:'C', 3:'D', 4:'E',\n 5:'A', 6:'B', 7:'C', 8:'D', 9:'E'}\n\nconnections = {0:(1,4,5), 1:(0,2,6), 2:(1,3,7), 3:(2,4,8), 4:(0,3,9), 5:(0,7,8),\n 6:(1,8,9), 7:(2,5,9), 8:(3,5,6), 9:(4,6,7)}\n\n...
[{"input": ["2", "AAB", "AABE", "", ""], "output": ["501", "-1"]}]
interview
874
ZCO is approaching, and you want to be well prepared! There are $N$ topics to cover and the $i^{th}$ topic takes $H_i$ hours to prepare (where $1 \le i \le N$). You have only $M$ days left to prepare, and you want to utilise this time wisely. You know that you can't spend more than $S$ hours in a day preparing, as yo...
["import math\nT=int(input())\nfor i in range(T):\n N,M,S=input().split()\n N=int(N)\n M=int(M)\n S=int(S)\n ls=list(map(int,input().split()))\n maxx=max(ls)\n if S<17 and maxx<=50:\n ls.sort()\n total_sum = M * S\n count = 0\n sum = 0\n for i in ls:\n if i / S > 2:\n continue\n else:\n sum = sum + math....
[{"input": ["2", "5 4 10", "10 24 30 19 40", "5 4 16", "7 16 35 10 15"], "output": ["2", "4"]}]
interview
875
Vanja and Miksi really like games. After playing one game for a long time, they decided to invent another game! In this game, they have a sequence $A_1, A_2, \dots, A_N$ and two numbers $Z_1$ and $Z_2$. The rules of the game are as follows: - The players take turns alternately, starting with Vanja. - There is an intege...
["import sys\nfrom collections import defaultdict as dd\nfrom collections import deque\nfrom fractions import Fraction as f\nfrom copy import *\nfrom bisect import * \nfrom heapq import *\nfrom math import *\nfrom itertools import permutations \n \ndef eprint(*args):\n print(*args, file=sys.stderr)\nzz=1\n \n#sys.setre...
[{"input": ["3", "2 6 4", "-4 10", "1 1 -1", "2", "2 0 7", "3 4"], "output": ["1", "0", "2"]}]
interview
876
Rachel has some candies and she decided to distribute them among $N$ kids. The ith kid receives $A_i$ candies. The kids are happy iff the difference between the highest and lowest number of candies received is less than $X$. Find out if the children are happy or not. -----Input:----- - First line will contain $T$, num...
["t=int(input())\r\n\r\nfor t1 in range(t):\r\n\tn,x=map(int,input().split())\r\n\ta=list(map(int,input().split()))\r\n\t\r\n\tmx=max(a)\r\n\tmn=min(a)\r\n\t\r\n\tif (mx-mn<x):\r\n\t\tprint(\"YES\")\r\n\telse:\r\n\t\tprint(\"NO\")", "for i in range(int(input())):\r\n n, x = list(map(int, input().split()))\r\n a =...
[{"input": ["2", "5 6", "3 5 6 8 1", "3 10", "5 2 9"], "output": ["NO", "YES"]}]
interview
877
A policeman wants to catch a thief. Both the policeman and the thief can only move on a line on integer coordinates between $0$ and $N$ (inclusive). Initially, the policeman is at a coordinate $x$ and the thief is at a coordinate $y$. During each second, each of them must move to the left or right (not necessarily both...
["t = int(input())\nfor _ in range(t):\n x, y, k, n = [int(x) for x in input().split()]\n k = k*2\n temp = abs(x-y)\n if(temp%k == 0):\n print(\"Yes\")\n else:\n print(\"No\")\n", "t = int(input())\n\nfor _ in range(t):\n x, y, k, n = [int(x) for x in input().split()]\n k = k*2\n temp = abs(x-y)\n if(temp%k == 0):\n ...
[{"input": ["5", "0 1 1 1", "1 4 1 5", "4 2 1 7", "3 7 2 10", "8 2 3 15"], "output": ["No", "No", "Yes", "Yes", "Yes"]}]
interview
878
There is a big staircase with $N$ steps (numbered $1$ through $N$) in ChefLand. Let's denote the height of the top of step $i$ by $h_i$. Chef Ada is currently under the staircase at height $0$ and she wants to reach the top of the staircase (the top of the last step). However, she can only jump from height $h_i$ to the...
["# cook your dish here\n\nimport numpy as np\n \n\ndef minstairs(n,k):\n stairsHeight=[]\n stairs=0\n current = 0\n stairsHeight=list(map(int, input().split()))\n stairsHeight=np.array(stairsHeight)\n curr=0\n for i in range(n):\n if stairsHeight[i]-curr<=k:\n curr=stairsHeight[i]\n else:\n if (stairsHeight[i]-c...
[{"input": ["1", "4 3", "2 4 8 16"], "output": ["3"]}]
interview
879
There are $X$ people participating in a quiz competition and their IDs have been numbered from $1$ to $X$ (both inclusive). Beth needs to form a team among these $X$ participants. She has been given an integer $Y$. She can choose participants whose ID numbers are divisible by $Y$. Now that the team is formed, Beth wan...
["for _ in range(int(input())):\r\n x, y = map(int, input().split())\r\n ans = 0\r\n for i in range(y, x+1, y):\r\n if i%y == 0:\r\n ans += i%10\r\n print(ans)", "lt = [[0, 0, 0, 0, 0, 0, 0, 0, 0 ,0],\n [1, 2, 3, 4, 5, 6, 7, 8, 9, 0],\n [2, 4, 6, 8, 0, 2, 4, 6, 8, 0],\n [3, 6, ...
[{"input": ["2", "10 3", "15 5"], "output": ["18", "10"]}]
interview
880
Tracy loves Donuts. She purchased a lots of Donuts for her birthday party. She learnt to calculate the area of the circle a few days back and she is fascinated to know the area of the donuts as well !! Help her finding the area of the Donuts….. -----Input:----- - First line will contain, number of testcases. Then the ...
["oo = int(input())\r\nfor i in range(oo):\r\n\tval = int(input())\r\n\tprint((val**2)*3.14)", "for _ in range(int(input())):\n n=int(input())\n print((n*n)*3.14)", "# cook your dish here\nimport math\nfor _ in range(int(input())):\n r=int(input())\n if r>=1 and r<=20:\n print(3.14*(r**2))", "# cook ...
[{"input": ["2", "5", "12"], "output": ["78.5", "452.16"]}]
interview
881
Given an array $A_1, A_2, ..., A_N$, count the number of subarrays of array $A$ which are non-decreasing. A subarray $A[i, j]$, where $1 ≤ i ≤ j ≤ N$ is a sequence of integers $A_i, A_i+1, ..., A_j$. A subarray $A[i, j]$ is non-decreasing if $A_i ≤ A_i+1 ≤ A_i+2 ≤ ... ≤ A_j$. You have to count the total number of such...
["# cook your dish here\nt=int(input())\nfor i in range(t):\n n=int(input())\n ar=list(map(int,input().split()))\n tot=0\n st=0\n for j in range(1,n):\n if(ar[j-1]>ar[j]):\n si=j-st\n c=(si*(si+1))//2\n tot+=c\n st=j\n si=n-st\n c=(si*(si+1))//2\n tot+=c\n print(tot)\n", "# cook your dish here\nfor _ in range ...
[{"input": ["2", "4", "1 4 2 3", "1", "5"], "output": ["6", "1"]}]
interview
882
As we all know, Chef is cooking string for long days, his new discovery on string is the longest common pattern length. The longest common pattern length between two strings is the maximum number of characters that both strings have in common. Characters are case sensitive, that is, lower case and upper case characters...
["from collections import Counter\r\ndef solve(A,B):\r\n a = Counter(A)\r\n b = Counter(B)\r\n ans = 0\r\n for i in a:\r\n if i in b:\r\n ans += min(a[i],b[i])\r\n \r\n return ans\r\n \r\n \r\nt = int(input())\r\n\r\nfor _ in range(t):\r\n A = input()\r\n B = input...
[{"input": ["4", "abcd", "xyz", "abcd", "bcda", "aabc", "acaa", "Codechef", "elfedcc", "", ""], "output": ["0", "4", "3", "5"]}]
interview
883
It's year 2018 and it's Christmas time! Before going for vacations, students of Hogwarts School of Witchcraft and Wizardry had their end semester exams. $N$ students attended the semester exam. Once the exam was over, their results were displayed as either "Pass" or "Fail" behind their magic jacket which they wore. A s...
["for _ in range(int(input())):\n n = int(input())\n a = list(map(int, input().split()))\n s = set(a)\n\n if n == 1 or len(s) > 2:\n print(-1)\n continue\n\n if len(s) == 1:\n x = s.pop()\n\n if x == 0:\n print(n)\n elif x == n-1:\n print(0)\n else:\n print(-1)\n\n continue\n\n x, y = sorted(s)\n xc, yc = ...
[{"input": ["1", "4", "3 2 2 2"], "output": ["1"]}]
interview
884
Write a program that reads two numbers $X$ and $K$. The program first finds the factors of $X$ and then gives the sum of $K$th power of every factor. The program also finds the factor of $k$ and outputs the sum of $X$ times of every factor. -----Input:----- - First line will contain $T$, number of testcases. Then the...
["try:\r\n for _ in range(int(input())):\r\n s,s1=0,0\r\n x,k=[int(i) for i in input().split()]\r\n for i in range(2,x+1):\r\n if(x%i==0):\r\n s=s+i**k\r\n for i in range(2,k+1):\r\n if(k%i==0):\r\n s1+=i*x\r\n print(s,s1)\r\nexce...
[{"input": ["1", "8 6"], "output": ["266304 88"]}]
interview
885
Chef solved so many hard questions, now he wants to solve some easy problems for refreshment. Chef asks Cheffina for the new question. Cheffina challenges the chef to print the total number of 0's in the binary representation of N(natural number). -----Input:----- - First-line will contain $T$, the number of test case...
["from sys import stdin, stdout\r\ninput = stdin.readline\r\nfrom collections import defaultdict as dd\r\nimport math\r\ndef geti(): return list(map(int, input().strip().split()))\r\ndef getl(): return list(map(int, input().strip().split()))\r\ndef gets(): return input()\r\ndef geta(): return int(input())\r\ndef print_...
[{"input": ["2", "2", "4"], "output": ["1", "2"]}]
interview
886
Chef is playing a game with his childhood friend. He gave his friend a list of N numbers named $a_1, a_2 .... a_N$ (Note: All numbers are unique). Adjust the numbers in the following order: $(i)$ swap every alternate number with it's succeeding number (If N is odd, do not swap the last number i.e. $a_N$ ). $(ii)$ add ...
["for _ in range(int(input())):\n n=int(input())\n a=list(map(int,input().split()))\n x=int(input())\n for _ in range(1,n,2):\n a[_],a[_-1]=a[_-1],a[_]\n for _ in range(n):\n a[_]+=(a[_]%3)\n # a=a[::-1]\n # a.sort()\n # if x>a[-1]:\n # print(-1)\n # continue\n l,h...
[{"input": ["1", "10", "5 15 1 66 55 32 40 22 34 11", "38"], "output": ["35 41"]}]
interview
887
Arya and Aryan live in a country called Nadaca. Nadaca consists of $N$ cities numbered $1$ through $N$, which are connected by some bidirectional roads. Each road has a positive (not necessarily integer) length. Arya lives in city $1$ and Aryan lives in city $N$. Arya claims that for each city $v$, the shortest path fr...
["# cook your dish here\n# cook your dish here\nfor _ in range(int(input())):\n n=int(input())\n a=list(map(int, input().split()))\n b=list(map(int, input().split()))\n\n if a[0]!=0 or b[-1]!=0 or a[-1]!=b[0]:\n print('No')\n \n else:\n ab=b[0]\n flag=0\n for i in range(1, n-1):\n if a[i]==0 or b[i]==0:\n pri...
[{"input": ["2", "3", "0 1 1", "1 1 0", "3", "0 1 5", "5 1 0"], "output": ["Yes", "No"]}]
interview
888
Cherry has a string S$S$ consisting of lowercase English letters. Using this string, he formed a pyramid of infinite length with certain rules: - N$N$-th row of pyramid contains N$N$ characters. - Each row of pyramid begins with the first character of the string. - The subsequent characters of the row are appended to t...
["def search(arr, lenl, val):\r\n s = 0\r\n l = lenl - 1\r\n\r\n total = 0\r\n\r\n while (s <= l):\r\n m = int((s + l) / 2)\r\n\r\n if (arr[m] <= val):\r\n total = m + 1\r\n s = m + 1\r\n\r\n else:\r\n l = m - 1\r\n\r\n return total\r\n\r\n\r\ndef kmp...
[{"input": ["codechef", "chefcode", "3", "4", "12", "1455"], "output": ["0", "1", "181"]}]
interview
889
Chef is a brilliant university student that does not attend lectures because he believes that they are boring and coding is life! However, his university follows certain rules and regulations, and a student may only take an exam for a course if he has attended at least 75% of lectures for this course. Since you are Che...
["# cook your dish here\ndef ceil(num):\n if num%1==0:\n return int(num//1)\n else:\n return int((num//1)+1)\n \nfor _ in range(int(input())):\n n=int(input())\n s=input()\n p=0\n a=[]\n for i in range(n):\n if s[i]==\"P\":\n p=p+1\n req=ceil(0.75*n)\n requirement=req-p\n for i in range(2,n-2):\n if s[i]==\"A\":\...
[{"input": ["1", "9", "PAAPPAPPP"], "output": ["1"]}]
interview
890
Snakeland is a well organised city. The houses of the city are organised in an orderly rectangular fashion with dimensions 2 * n, i.e. there are total two rows and n columns. The house in the i-th row and j-th column is also said to be the house at coordinates (i, j). Some of the houses are occupied by snakes, while th...
["# cook your dish here\nt=int(input())\nwhile t:\n n=int(input())\n r1=input()\n r2=input()\n r1count=0\n r2count=0\n count=0\n for i in range(n):\n if(r1[i]==\"*\"):\n r1count+=1\n if(r2[i]==\"*\"):\n r2count+=1\n if(r1count>0) and (r2count>0):\n count=1\n r1count=0\n r2count=0\n i=0\n while(i<n):\n if(r...
[{"input": ["3", "2", "**", "**", "3", "***", "*..", "3", "*..", ".*."], "output": ["2", "3", "1"]}]
interview
891
Andrii is good in Math, but not in Programming. He is asking you to solve following problem: Given an integer number N and two sets of integer A and B. Let set A contain all numbers from 1 to N and set B contain all numbers from N + 1 to 2N. Multiset C contains all sums a + b such that a belongs to A and b belongs to B...
["# cook your dish here\nimport math;\nfrom math import gcd,sqrt,floor,factorial,ceil\nfrom bisect import bisect_left,bisect_right\nimport bisect;\nimport sys;\nfrom sys import stdin,stdout\nimport os\nsys.setrecursionlimit(pow(10,7))\nimport collections\nfrom collections import defaultdict,Counter\nfrom statistics imp...
[{"input": ["3 5", "6", "2", "9", "7", "5", ""], "output": ["2", "0", "1", "3", "1"]}]
interview
892
There are $N$ cells numbered 1,2,….., N, and every cell has some positive value. you will be given an array $A_1$,$A_2$,…,$A_N$ where $A_i$ is the value of $ith$ cell and an integer $K$. There is a monkey who wants to reach the $right$ side of the last ($Nth$) cell, initially, the monkey was left side of the first ($1s...
["from sys import setrecursionlimit\r\nsetrecursionlimit(10 * 9)\r\n\r\ndef solve(i):\r\n if i + k >= n:\r\n return 1\r\n\r\n if i in dp:\r\n return dp[i]\r\n\r\n mini = float('inf')\r\n for j in range(i+1, min(n, i+k+1)):\r\n if i == -1 or a[i] == a[j]:\r\n mini = min(mini, ...
[{"input": ["1", "2 2", "3 4"], "output": ["2"]}]
interview
893
Given an array of size N$N$ and two integers K$K$ and S$S$, the special sum of a subarray is defined as follows: (Sum of all elements of the subarray) * (K$K$ - p$p$ * S$S$) Where p$p$ = number of distinct prime factors of “product of all elements of the subarray”. Find the maximum special sum by considering all non...
["# cook your dish here\nfrom math import floor, sqrt\ntry:long\nexcept NameError:long = int \ndef fac(n):\n step,maxq,d = lambda x: 1 + (x<<2) - ((x>>1)<<1),long(floor(sqrt(n))),1\n q = n % 2 == 0 and 2 or 3 \n while q <= maxq and n % q != 0:\n q = step(d)\n d += 1\n return q <= maxq and [q] + fac(...
[{"input": ["4 10 2", "14 2 7 15"], "output": ["138", "Sample"]}]
interview
894
Chef recently developed an affinity for undirected graphs. He likes pairs of graphs that are similar in structure. However, Chef discovered that when the vertices of a graph are reorganized, it's often the case that the resulting graph, although still structurally similar to the original, can look completely different....
["import random\nt=int(input())\nfor testCase in range(t):\n\tn=int(input())\n\tarray1=[]\n\tarray2=[]\n\tarray=[]\n\tfor i in range(n) :\n\t\tarray1.append(list(map(int,input().split())))\n\tfor i in range(n) :\n\t\tarray2.append(list(map(int,input().split())))\n\tfor i in range(n) :\n\t\tarray.append(i)\n#\tprint arr...
[{"input": ["2", "3", "0 1 0", "1 0 0", "0 0 0", "0 0 1", "0 0 1", "1 1 0", "4", "0 0 1 0", "0 0 0 0", "1 0 0 1", "0 0 1 0", "0 0 1 1", "0 0 0 0", "1 0 0 0", "1 0 0 0", ""], "output": ["1 2 3", "1 2 3", "1 4 2 3", "2 4 1 3"]}]
interview
895
Zonal Computing Olympiad 2012, 26 Nov 2011 It's dinner time in Castle Camelot, and the fearsome Knights of the Round Table are clamouring for dessert. You, the chef, are in a soup. There are N knights, including King Arthur, each with a different preference for dessert, but you cannot afford to make desserts for all ...
["n=int(input())\r\nar=list(map(int,input().split()))\r\ndp=[0]*n \r\ndp[0]=ar[0]\r\ndp[1]=ar[1]\r\nfor i in range(2,n):\r\n dp[i]=min(dp[i-2],dp[i-1])+ar[i]\r\n \r\nar.reverse()\r\n#print(ar)\r\ndp1=[0]*n \r\ndp1[0]=ar[0]\r\ndp1[1]=ar[1]\r\nfor i in range(2,n):\r\n dp1[i]=min(dp1[i-2],dp1[i-1])+ar[i]\r\nprint...
[{"input": ["5", "1 2 1 2 2"], "output": ["4"]}]
interview
896
-----Problem Statement----- Chef has a sequence of N segments: [L1, R1], [L2, R2], ..., [LN, RN]. He wants to transform the first segment to the last one (with index N). His plan is to do this big deal with a number of transformations: firstly he will transform the first segment to the second one, then to the third on...
["for tc in range(int(input())):\n N = int(input())\n a, b = list(map(int, input().split()))\n pr = []\n\n # 'L' is lexicographically lower than 'R'.\n # so, we should first try to apply L+ or L-\n # if we can't then only we'll try to apply R+ or R-\n\n for i in range(N - 1):\n l, r = list(map(int, input().split()))\n...
[{"input": ["4", "3", "-1 0", "0 1", "3 5", "1", "0 1", "3", "-2 -1", "-2 -1", "-2 0", "4", "4 6", "3 5", "-1 1", "1 2"], "output": ["9", "R+L+R+L+R+L+R+L+R+", "0", "1", "R+", "13", "L-R-L-L-L-L-R-R-R-R-L+R+L+"]}]
interview
897
Chef had an array A with length N, but some of its elements got lost. Now, each element of this array is either unknown (denoted by -1) or a positive integer not exceeding K. Chef decided to restore the array A by replacing each unknown element by a positive integer not exceeding K. However, Chef has M restrictions tha...
["# cook your dish here\n# cook your dish here\nMOD = 10 ** 9 + 7\n \nfor t in range(int(input())):\n N, M, K = map(int, input().split())\n A = list(map(int, input().split()))\n I, D = [0] * (N + 2), [0] * (N + 2)\n for i in range(M):\n x, L, R = input().split()\n L, R = int(L), int(R)\n ...
[{"input": ["3", "4 2 10", "2 3 5 4", "I 1 2", "D 3 4", "5 2 10", "-1 -1 -1 -1 -1", "I 1 3", "D 3 5", "6 2 2", "-1 -1 -1 -1 -1 -1", "I 1 4", "D 4 6"], "output": ["1", "8", "0"]}]
interview
898
Note : This question carries $150$ $points$ There is an outcry in Middle Earth, as the greatest war between Orgs of Dark Lord Sauron and Frodo Baggins is about to begin. To end the war, Frodo decides to destroy the ring in the volcano of Mordor. There are many ships that lead Frodo to Mordor, and he is confused about w...
["# cook your dish here\nfrom math import pow\nt = int(input())\nfor _ in range(t):\n m,n = map(int,input().rstrip().split())\n cnt = len(str(n))\n x = pow(10,cnt)\n if n == x-1:\n print(m*cnt,m)\n else:\n print(m*(cnt-1),m)", "# cook your dish here\r\ndef sol(z):\r\n r=len(str(z))\r\n ...
[{"input": ["1", "1 9"], "output": ["1 1"]}]
interview
899
Chef wants to teach a lesson of sharing to the students. There are $N$ students (numbered from $1$ to $N$ from left to right) who are asked to stand in a row. Initially Chef gave $A$$i$ candies to the $i$$th$ child. In one operation any child can give any number of candies to the child standing to his immediate left (i...
["from math import ceil\n\nfor _ in range(int(input())):\n n = int(input())\n arr = [int(x) for x in input().split()]\n sarr = sum(arr)\n mavg = sarr/n\n while n>1:\n sarr -= arr.pop()\n n-=1\n mavg = max(mavg, sarr/n)\n print(int(ceil(mavg)))", "import math\nT=int(input())\n\nfor _ in range(T):\n N=int(input())\n A...
[{"input": ["2", "5", "1 2 3 4 5", "5", "5 4 3 2 1"], "output": ["3", "5"]}]
interview