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
600
The Fibonacci sequence $F_0, F_1, \ldots$ is a special infinite sequence of non-negative integers, where $F_0 = 0$, $F_1 = 1$ and for each integer $n \ge 2$, $F_n = F_{n-1} + F_{n-2}$. Consider the sequence $D$ of the last decimal digits of the first $N$ Fibonacci numbers, i.e. $D = (F_0 \% 10, F_1 \% 10, \ldots, F_{N-...
["import math\n\nt = int(input())\n\na = [-1, 0, 1]\n\nfor i in range(58):\n temp = a[-1] + a[-2]\n temp = temp%10\n a.append(temp)\n \nfor _ in range(t):\n n = int(input())\n \n temp = len(bin(n)) - 3\n temp = 2**temp\n temp = temp%60\n \n print(a[temp])", "import math\n\ndef logBase2(n):\n res = 0\n fact = 1\n while(...
[{"input": ["1", "9"], "output": ["3"]}]
interview
601
The bustling town of Siruseri has just one sports stadium. There are a number of schools, colleges, sports associations, etc. that use this stadium as the venue for their sports events. Anyone interested in using the stadium has to apply to the Manager of the stadium indicating both the starting date (a positive intege...
["# cook your dish here\nn=(int(input()))\nx=[]\nfor _ in range(n):\n a,b=map(int,input().split())\n a=[a,a+b]\n x.append(a)\nx = sorted(x, key= lambda i:i[1])\ny=-1\nc=0\nfor i in range(len(x)):\n if x[i][0]>y:\n c+=1\n y=x[i][1]\nprint(c)", "# cook your dish here\nn=(int(input()))\nx=[]\nfor...
[{"input": ["4", "2 5", "9 7", "15 6", "9 3", "Sample output:", "3"], "output": []}]
interview
602
Chef Loves to listen to remix songs, but currently he had already finished the entire playlist of remix songs. As Chef is smart, so he thought let's make my own remix songs of the original songs. Chef is not having much knowledge of making remix songs, so he came up with the simple technique in which he will pick the w...
["m= 9999999\r\nword=''\r\np= ''\r\ntry:\r\n s=input().split()\r\n for i in s:\r\n if(len(i) <= m):\r\n m = len(i)\r\n word = i\r\n p = word\r\n for i in s:\r\n p+= (' '+i+' '+ word)\r\n \r\n print(p)\r\n\r\n \r\nexcept E...
[{"input": ["Mai Hu Jiyaan"], "output": ["Hu Mai Hu Hu Hu Jiyaan Hu"]}]
interview
603
----- Statement ----- You need to find a string which has exactly K positions in it such that the character at that position comes alphabetically later than the character immediately after it. If there are many such strings, print the one which has the shortest length. If there is still a tie, print the string which c...
["for i in range(int(input())):\n N = int(input())\n s = 'zyxwvutsrqponmlkjihgfedcba'\n r = ''\n while True:\n r = s[-N-1:] + r \n if N < 26:\n break\n N -= 25\n print(r)", "s='abcdefghijklmnopqrstuvwxyz'\nfor u in range(int(input())):\n n=int(input())\n r=''\n while(1):\n r=s[n::-1]+r\n if(n<26):\n break\n n...
[{"input": ["2", "1", "2"], "output": ["ba", "cba"]}]
interview
604
You are given a grid with $R$ rows (numbered $1$ through $R$) and $C$ columns (numbered $1$ through $C$). A cell in row $r$ and column $c$ is denoted by $(r, c)$. Two cells in the grid are adjacent if they have a common side. For each valid $i$ and $j$, there is a value $a_{i, j}$ written in cell $a_{i, j}$. A cell in ...
["for _ in range(int(input())):\n r,c = map(int,input().split())\n l = []\n for k in range(r):\n a = list(map(int,input().split()))\n l.append(a)\n ans = \"Stable\" \n for i in range(r):\n for j in range(c):\n p = l[i][j]\n count=0\n if i-1>=0 and j>=0:\n count+=1 \n if i>=0 and j-1>=0:\n count+=1 \n ...
[{"input": ["2", "3 3", "1 2 1", "2 3 2", "1 2 1", "3 4", "0 0 0 0", "0 0 0 0", "0 0 4 0"], "output": ["Stable", "Unstable"]}]
interview
605
There is a rectangular grid of cells consisting of n rows and m columns. You will place a robot on one of the grid cells and provide it with a command string s, consisting of characters ‘L’, ‘R’, ‘U’, ‘D’. After being placed, the robot will follow the instructions of the command string, where 'L' corresponds moving to ...
["# cook your dish here\ntest=int(input())\nfor _ in range(test):\n b=list(map(int,str(input()).split(' ')))\n c=str(input())\n li1=[0]\n li2=[0]\n for i1 in range(len(c)):\n if c[i1]=='R':\n li1.append(li1[len(li1)-1]+1)\n elif c[i1]=='L':\n li1.append(li1[len(li1)-1]-1)\n elif c[i1]=='U':\n li2.append(li2[le...
[{"input": ["5", "1 1", "R", "2 3", "LLRU", "3 2", "LLRU", "4 3", "ULURUDRDLD", "3 6", "RURUR"], "output": ["unsafe", "safe", "unsafe", "safe", "safe"]}]
interview
606
Consider the infinite x$x$ axis. There are N$N$ impacts on this X-axis at integral points (X1$X_1$,X2$X_2$,....XN$X_N$) (all distinct) . An impact at a point X$X$i propagates such that at a point X$X$0, the effect of the impact is K|Xi−X0|$K^{|X_i - X_0|}$. Given the point X0$X_0$, N$N$ and K$K$. Assume the total impa...
["# cook your dish here\nT = int(input())\nfor i in range(T):\n l = list(map(int, input().split()))\n n, k, m, x = l[0], l[1], l[2], l[3]\n if k == 1:\n if n == m:\n print(\"yes\")\n else:\n print(\"no\")\n elif m % k > 1:\n print(\"no\")\n elif k == 2:\n ...
[{"input": ["2", "4 3 10 10", "2 3 10 10"], "output": ["no", "yes"]}]
interview
607
You are given a sequence $A_1, A_2, \ldots, A_N$. You have to split the array into maximum number of non-empty subarrays such that the gcd of elements of each subarray is equal to 1. -----Input:----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ t...
["'''input\n2\n3\n2 2 3\n4\n2 3 3 2\n'''\nimport math\n\nfor _ in range(int(input())):\n n = int(input())\n a = list(map(int, input().split()))\n count = 0\n i = 0\n while i < len(a):\n if a[i] == 1:\n count += 1\n i += 1\n continue\n curr_gcd = a[i]\n while i < len(a) and curr_gcd != 1:\n curr_gcd = math.gc...
[{"input": ["2", "3", "2 2 3", "4", "2 3 3 2"], "output": ["1", "2"]}]
interview
608
Abhi Ram analyses london stock exchange and invests in a software company C-.gate . He wants to sell his shares after 5 weeks. Given the investment m, increase or decrease of share prices of 5 weeks(+/- pi) , help him to calculate his net profit or loss percentage(n%) of his investment to establish his own company KM...
["for i in range(int(input())):\n\t n = int(input())\n\t P = list(map(float, input().split()))\n\t pr = 1\n\t for p in P:\n\t\t a = 100+p\n\t\t pr = (pr*a)/100\n\t pr = (pr-1)*100\n\t x = 6-len(str(int(abs(pr))))\n \t if (x==1):\n \t \t if (pr==0):\n \t \t \tprint(0)\n\t\t elif (pr>0):\n\t\t \tprint(\"+\"+str(\...
[{"input": ["2", "10000", "+5 -3 -2 +10 +15", "6256250", "-24 +22 +4 -16 +20"], "output": ["+26.2634", "-2.79977"]}]
interview
609
Chef published a blog post, and is now receiving many queries about it. On day $i$, he receives $Q_i$ queries. But Chef can answer at most $k$ queries in a single day. Chef always answers the maximum number of questions that he can on any given day (note however that this cannot be more than $k$). The remaining questi...
["# cook your dish here\n\nt=int(input())\nwhile(t):\n t=t-1\n n,k=list(map(int,input().split()))\n q=list(map(int,input().split()))\n days,rem=0,0\n for i in range(n):\n rem+=q[i]\n if(rem>=k):\n rem-=k\n else:\n days=i+1\n break\n days+=1\n if(rem>=k):\n days+=(rem//k)+1\n print(days)\n", "# cook your dish...
[{"input": ["2", "6 5", "10 5 5 3 2 1", "1 1", "100"], "output": ["6", "101"]}]
interview
610
Due to the COVID pandemic, people have been advised to stay at least $6$ feet away from any other person. Now, people are lining up in a queue at the local shop and it is your duty to check whether they are all following this advice. There are a total of $N$ spots (numbered $1$ through $N$) where people can stand in fr...
["# cook your dish here\nt=int(input())\nwhile t>0:\n n=int(input())\n l=list(map(int,input().split()))\n l1=[]\n c=1\n for i in range(len(l)):\n if l[i]==1:\n l1.append(i)\n for j in range(len(l1)-1):\n if l1[j+1]-l1[j]<6:\n c=0\n break\n if c:\n ...
[{"input": ["3", "3", "1 0 1", "7", "1 0 0 0 0 0 1", "11", "0 1 0 0 0 0 0 1 0 0 1", ""], "output": ["NO", "YES", "NO"]}]
interview
611
"What do you know about happiness?" — Yoda Chef is happy only if three conditions hold: - Chef finished cooking a delicious meal - Chef got AC for a programming problem with an almost correct code - Chef got a new problem with a sequence of integers Today, all three conditions are satisfied. Chef would like you to fee...
["# cook your dish here\n\nt=int(input())\n\nfor i in range(t):\n n=int(input())\n a=list(map(int,input().split()))\n d={}\n for i in range(n):\n if a[i]-1 not in d:\n d[a[i]-1]=[i]\n else:\n d[a[i]-1].append(i)\n ans=False\n d1={}\n \n for i in d:\n if ans==True:\n break\n for j in d:\n if i!=j:\n if a[...
[{"input": ["4", "4", "1 1 2 3", "4", "2 1 3 3", "5", "5 4 4 3 1", "5", "3 2 1 1 4"], "output": ["Truly Happy", "Poor Chef", "Poor Chef", "Truly Happy"]}]
interview
612
Lots of geeky customers visit our chef's restaurant everyday. So, when asked to fill the feedback form, these customers represent the feedback using a binary string (i.e a string that contains only characters '0' and '1'. Now since chef is not that great in deciphering binary strings, he has decided the following cri...
["# cook your dish here\nt=int(input())\nfor i in range(t):\n s=input()\n fl=-1\n n=len(s)\n for i in range(n-2):\n if(s[i:i+3]==\"010\" or s[i:i+3]==\"101\"):\n fl=0\n print(\"Good\")\n break\n\n if(fl==-1):\n print(\"Bad\")\n", "# cook your dish here\nt=int(input())\nfor i in range(t):\n s=input()\n fl=-1\n n...
[{"input": ["2", "11111110", "10101010101010"], "output": ["Bad", "Good"]}]
interview
613
-----Problem----- Nikki's latest work is writing a story of letters. However, she finds writing story so boring that, after working for three hours, she realized that all she has written are M long words consisting entirely of letters A and B. Having accepted that she will never finish the story in time, Nikki has ...
["def check(s):\n arr=[s[0]]\n l=len(s)\n f1=0\n for i in range(1,l):\n if arr==[]: arr.append(s[i])\n elif arr[-1]!=s[i]:arr.append(s[i])\n else: del arr[-1]\n if arr==[]: return True\n else: return False\n \ncount = 0\nfor t in range(eval(input())):\n s=input().strip()\n if check(s): count+=1\nprint(count)", "coun...
[{"input": ["3", "ABAB", "AABB", "ABBA"], "output": ["2"]}]
interview
614
Chef would like go shopping to buy ingredients for his special dish. The local grocery store has some special discount offers. If you want to buy some set of ingredients you will pay for all ingredients except the cheapest one. Chef would like to spend as little money as possible. You have to help him. :) The store is...
["from itertools import permutations as p\ndef disc(a,b):\n for ai in a:\n for bi in b:\n if ai==bi:\n return False\n return True\n\nfor i in range(eval(input())):\n n = eval(input())\n arr = list(map(int,input().split()))\n perms = list(p(arr))\n m = eval(input())\n offer = {}\n for i in range(m):\n dup = list(...
[{"input": ["1", "4", "1 2 3 4", "3", "2 1 2", "2 3 4", "3 1 2 3"], "output": ["6"]}]
interview
615
Nexus 4.O is going to be organized by ASME, GLA University. Shubhanshu, Head of Finance Team is working for it. He has $N$ number of bills of different values as $a$$1$,$ a$$2$, $a$$3$…$a$$n$. He is interested in a game in which one has to do the addition of the bills. But due to privacy concerns, he cannot share the d...
["\nt=int(input())\nfor i in range(t):\n l=list(map(int,input().split(' ')))\n a=l[0]\n b=l[1]\n \n l1=list(map(int,input().split(' ')))\n for i in range(b):\n l2=list(map(int,input().split(' ')))\n a1=l2[0]\n b1=l2[1]\n su=0\n for j in range(a1-1,b1):\n su=(su+l1[j])%1000000000\n print(su) ", "\nt=int(input())...
[{"input": ["1", "8 3", "1 2 3 4 5 6 7 8", "2 3", "1 6", "5 8"], "output": ["5", "21", "26"]}]
interview
616
There are $M$ levels for a building numbered from $1$ to $M$ from top to bottom, each level having $N$ parking spots numbered from $1$ to $N$ from left to right. Some spots might have a car while other may be empty, the information of which is given in form of two dimensional character array $C$ ($C_{i, j}$ denote park...
["from sys import stdin\n\nfor _ in range(int(stdin.readline())):\n m, n = list(map(int, stdin.readline().split()))\n final = []\n arr = []\n val = 0\n extra = 0\n for j in range(m):\n ans = list(map(str, stdin.readline().split()))\n if ans.count('N') == n:\n val += 1\n else:\n if val%2 == 0:\n arr.append(ans...
[{"input": ["2", "4 5", "N P N N P", "N N P N N", "N P N N N", "P N N N N", "3 3", "N P P", "P P P", "P P N"], "output": ["10", "6"]}]
interview
617
We all know that Share market is place where drastic change occurs within moments. So we have one Stockholder, Isabella, who wants to maximize her profit by selling her shares. She has $N$ shares of a Doofenshmirtz Corporation which is represented by $N$ different lines where each line contains two space separated inte...
["def CeilIndex(A, l, r, key): \n \n while (r - l > 1): \n \n m = l + (r - l)//2\n if (A[m] >= key): \n r = m \n else: \n l = m \n return r \n \ndef LongestIncreasingSubsequenceLength(A, size): \n \n # Add boundary case, \n # when array size is one \n \n...
[{"input": ["1", "4", "1 2", "4 3", "3 5", "2 4"], "output": ["3"]}]
interview
618
Dexter, being irritated by DD, gave her a lucrative game to play to keep her busy. There are $N$ bags numbered $1$ to $N$. The $i_{th}$ bag contains $A_i$ coins. The bags are placed in a circular order such that the $N_{th}$ bag is adjacent to the $1^{st}$ bag. DD can select $K$ consecutive adjacent bags and take all ...
["t=int(input())\nfor i in range(t):\n n,k=list(map(int,input().split(\" \")))\n arr=list(map(int,input().strip().split(\" \")))[:n]\n def maxCircularSum(arr, n, k):\n if (n < k):\n print(\"Invalid\");\n return;\n\n sum = 0;\n start = 0;\n end = k - 1;\n\n ...
[{"input": ["1", "5 3", "8 6 9 4 10"], "output": ["24"]}]
interview
619
In a regular table tennis match, the player who serves changes every time after 2 points are scored, regardless of which players scored them. Chef and Cook are playing a different match — they decided that the player who serves would change every time after $K$ points are scored instead (again regardless of which playe...
["n=int(input())\nfor i in range(n):\n l=list(map(int,input().split()))\n k=l[0]+l[1]\n k=k%(2*l[2])\n \n if k>=0 and k<l[2]:\n print(\"CHEF\")\n else:\n print(\"COOK\")\n", "t=int(input())\nwhile t>0:\n p1,p2,k=map(int,input().split())\n s=(p1+p2)//k\n if s%2==0:\n print(\"CHEF\")\n else:\n print(\"COOK\...
[{"input": ["3", "1 3 2", "0 3 2", "34 55 2"], "output": ["CHEF", "COOK", "CHEF"]}]
interview
620
Find the length of the longest contiguous segment in an array, in which if a given element $K$ is inserted, $K$ becomes the second largest element of that subarray. -----Input:----- - The first line will contain $T$, number of test cases. Then the test cases follow. - The first line of each test case contains two int...
["for _ in range(int(input())):\n n,k=list(map(int,input().split()))\n a=list(map(int,input().split()))\n def check(mid):\n d,left={},0\n for i in range(mid):\n if a[i]>k:\n if a[i] not in d: \n d[a[i]]=1\n else: \n d[a[i]]+=1\n if len(d)==1:\n return True\n for i in range(mid,n):\n if a[left]>k...
[{"input": ["2", "5 3", "2 4 2 4 2", "8 5", "9 3 5 7 8 11 17 2"], "output": ["5", "3"]}]
interview
621
Given n words w[1..n], which originate from the same stem (e.g. grace, graceful, disgraceful, gracefully), we are interested in the original stem. To simplify the problem, we define the stem as the longest consecutive substring that occurs in all the n words. If there are ties, we will choose the smallest one in the al...
["t = eval(input())\nfor _ in range(t):\n n = eval(input())\n a = input().strip().split()\n cb, cs = 0, \"\"\n for i in range(len(a[0])):\n for j in range(i+1,len(a[0])+1):\n al = True\n s = a[0][i:j]\n for k in a[1:]:\n if s not in k:\n al = False\n break\n if al:\n if j-i>=cb:\n cb = max(cb...
[{"input": ["1", "4", "grace graceful disgraceful gracefully"], "output": ["grace"]}]
interview
622
Chef has a rectangular piece of paper. He puts it on a big board in such a way that two sides of the paper are horizontal and two are vertical, and then he performs a sequence of $N$ operations. You are given a string $S$ with length $N$; for each valid $i$, the $i$-th character of $S$ determines the type of the $i$-th...
["# cook your dish here folding paper\nfrom collections import Counter\ndef li():return [int(i) for i in input().rstrip('\\n').split()]\ndef st():return input().rstrip('\\n')\ndef val():return int(input().rstrip('\\n'))\ndef dist(a,b):return ((a[0]-b[0])**2+(a[1]-b[1])**2)**0.5\nfor _ in range(val()):\n n,m,w,h=li()\n ...
[{"input": ["2", "6 2 10 10", "ULRDDL", "4 4", "5 5", "4 2 10 10", "RUDL", "1 1", "9 9"], "output": ["1.41421356237", "2.00000000000"]}]
interview
623
Given the list of numbers, you are to sort them in non decreasing order. -----Input----- t – the number of numbers in list, then t lines follow [t <= 10^6]. Each line contains one integer: N [0 <= N <= 10^6] -----Output----- Output given numbers in non decreasing order. -----Example----- Input: 5 5 3 6 7 1 Output...
["t = int(input())\nlist_to_tri = []\nfor i in range(t):\n list_to_tri.append(int(input()))\nlist_to_tri.sort()\nfor i in list_to_tri:\n print(i)\n", "# cook your dish here\nn=int(input())\nlst = []\nfor i in range(n):\n i=int(input())\n lst.append(i)\n\nlst.sort()\nfor i in range(n):\n print(lst[i])\n",...
[{"input": ["5", "5", "3", "6", "7", "1"], "output": ["1", "3", "5", "6", "7"]}]
interview
624
Once, a genius guy Cristo visited NASA where he met many scientists. A young intern Mark at NASA asked Cristo to observe the strange behaviour of two independent particles (say Alpha and Beta) moving in the free space.Cristo was astonished to see the movement of Alpha and Beta. However, he formulated a procedure to e...
["for _ in range(eval(input())):\n n=eval(input())\n mod=1000000007\n f1,f2=[0]*101000,[0]*101000\n f1[1]=0\n f1[2]=2\n f1[3]=3\n f2[1]=1\n f2[2]=1\n f2[3]=2;\n for i in range(4,100001):\n f1[i]=f1[i-1]%mod+f1[i-2]%mod+f1[i-3]%mod\n f2[i]=f2[i-1]%mod+f2[i-2]%mod+f2[i-3]%mod\n print(f1[n]%mod,f2[n]%mod) ", "MOD = 10**...
[{"input": ["2", "1", "2"], "output": ["0 1", "2 1"]}]
interview
625
Shaun is very much interested in Subarrays. Shaun wants to count the number of subarrays in his chosen array with sum being a multiple of $10^9$. Since, Shaun is interested in huge numbers.He chose his array such that it contains only $10^8$ and $9*10^8$ as its elements. Help shaun to count the number of required subar...
["def subCount(arr, n, k):\r\n\r\n mod = []\r\n for i in range(k + 1):\r\n mod.append(0)\r\n\r\n\r\n cumSum = 0\r\n for i in range(n):\r\n cumSum = cumSum + arr[i]\r\n\r\n # as the sum can be negative,\r\n # taking modulo twice\r\n mod[((cumSum % k) + k) % k] = mod[((cumSu...
[{"input": ["2", "3", "100000000 900000000 100000000", "1", "900000000"], "output": ["2", "0"]}]
interview
626
The Chef has prepared the appetizers in the shapes of letters to spell a special message for the guests. There are n appetizers numbered from 0 to n-1 such that if the appetizers are arrayed in this order, they will display the message. The Chef plans to display them in this order on a table that can be viewed by all g...
["t=int(input())\ndef reversebinary(bits,n):\n bStr=''\n for i in range(bits):\n if n>0:\n bStr=bStr+str(n%2)\n else:\n bStr=bStr+'0'\n n=n>>1\n return int(bStr,2)\n \nfor i in range(t):\n k,msg=input().split()\n k=int(k)\n newmsg=[]\n for j in msg:...
[{"input": ["2", "2 chef", "4 enjoyourapplepie", "", ""], "output": ["cehf", "eayejpuinpopolre"]}]
interview
627
Bharat was given a problem to solve, by his brother, Lord Ram. The problem was like, given integers, $N$ and $K$, Bharat has to find the number (possibilities) of non-increasing arrays of length $K$, where each element of the array is between $1$ and $N$ (both inclusive). He was confused, regarding this problem. So, he...
["import math\np=7+10**9\nn,k=list(map(int,input().split()))\nc=math.factorial(n+k-1)//((math.factorial(k))*(math.factorial(n-1)))\nprint(c%p)\n", "from math import *\n \n# Function to find the nCr \ndef printNcR(n, r): \n \n # p holds the value of n*(n-1)*(n-2)..., \n # k holds the value of r*(r-1)... \n p = 1\n k = 1...
[{"input": ["2 5"], "output": ["6"]}]
interview
628
Chef and his best friend Aleksa are into mathematical games these days. Today, they have some ( ≥ 0 ) black cells represented as B, and a white cell represented as W, lying randomly in a straight line. They have decided to play with these cells. In a move, a player chooses some ( > 0 ) black cells lying on any one side...
["t =int(input()) #no. of test cases\nwhile t>0:\n t=t-1\n str=input()\n size=len(str)\n pos=str.find('W')\n left=pos\n right=size-pos-1\n arr = [[0 for i in range(right+1)] for j in range(left+1)]\n #arr[i,j] = 1 if with i black cells on left and j on right 1st player can \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00...
[{"input": ["3", "W", "BW", "BWBB"], "output": ["Chef", "Aleksa", "Aleksa"]}]
interview
629
Naturally, the magical girl is very good at performing magic. She recently met her master wizard Devu, who gifted her R potions of red liquid, B potions of blue liquid, and G potions of green liquid. - The red liquid potions have liquid amounts given by r[1], ..., r[R] liters. - The green liquid potions have liqu...
["import sys\nimport math\nimport heapq\ndef half(n):\n return n//2\ndef main(arr,m):\n a,b,c=arr\n \n while m!=0:\n \n \n \n s=max(a,b,c)\n \n if s==a:\n a=half(a)\n elif s==b:\n b=half(b)\n else:\n c=half(c)\n m-=1\n return max(a,b,c)\n \n \n \n \n \n\nfor i in range(int(input())):\n r,g,b,m=list(map...
[{"input": ["3", "1 1 1 1", "1", "2", "3", "1 1 1 1", "2", "4", "6", "3 2 2 2", "1 2 3", "2 4", "6 8"], "output": ["2", "4", "4"]}]
interview
630
Cersei wants to be the queen of seven kingdoms. For this to happen, she needs to address the soldiers in her army. There are n$n$ soldiers in her army (numbered 1$1$ through n$n$). Cersei passes on the message to the first soldier (soldier 1). This message needs to reach every soldier in the army. For this, the sol...
["dt, a = None, None\ndef dfs(z):\n r = [{}, {}];ln = len(dt[z])\n if ln == 0:r[0][0] = 0;r[1][1 << a[z]] = 1\n elif ln == 1:\n l = dfs(dt[z][0]);r[0] = l[1]\n for m in l[0]: r[1][(1 << a[z]) | m] = min(r[1][(1 << a[z]) | m], l[0][m] + 1) if (1 << a[z]) | m in r[1] else l[0][m] + 1\n ...
[{"input": ["1", "5 4 3", "1 1 2 2 3", "1 2", "1 3", "2 4", "2 5"], "output": ["3"]}]
interview
631
In Ciel's restaurant, a waiter is training. Since the waiter isn't good at arithmetic, sometimes he gives guests wrong change. Ciel gives him a simple problem. What is A-B (A minus B) ? Surprisingly, his answer is wrong. To be more precise, his answer has exactly one wrong digit. Can you imagine this? Can you make the...
["a, b = [int(x) for x in input().split()]\nr = list(str(a-b))\nif r[0] == \"1\":\n r[0] = \"2\"\nelse:\n r[0]=\"1\"\nprint(\"\".join(r))\n"]
[{"input": ["5858 1234"], "output": ["1624", "Output details", "The correct answer of 5858-1234 is 4624.", "So, for instance, 2624, 4324, 4623, 4604 and 4629 will be accepted, but 0624, 624, 5858, 4624 and 04624 will be rejected.", "Notes", "The problem setter is also not good at arithmetic."]}]
interview
632
Sheldon is a little geek living in Texas. While his friends like to play outside, little Sheldon likes to play around with ICs and lasers in his house. He decides to build N clap activated toggle machines each with one power inlet and one outlet. Each machine works when its power source inlet is receiving power. When t...
["n=int(input())\nwhile n>0:\n i=1\n a,b=(int(i) for i in input().split())\n if (b+1)%(i<<a)==0:\n print(\"ON\")\n else:\n print(\"OFF\")\n n=n-1\n", "for _ in range(int(input())):\n n,k=input().split()\n n=int(n)\n k=int(k)\n \n p=2**n-1\n \n if p==k:\n print('ON')\n elif p<k:\n if (k-p)%(2**n)==0:\n print('ON')...
[{"input": ["4", "4 0", "4 47", "1 0", "1 1"], "output": ["OFF", "ON", "OFF", "ON"]}]
interview
633
Well known investigative reporter Kim "Sherlock'' Bumjun needs your help! Today, his mission is to sabotage the operations of the evil JSA. If the JSA is allowed to succeed, they will use the combined power of the WQS binary search and the UFDS to take over the world! But Kim doesn't know where the base is located. He ...
["n=int(input())\ndef do():\n t=int(input())\n x=[]\n for i in range(t):\n x.append(int(input()))\n print(max(x))\n return\nfor i in range(n):\n do()", "t=int(input())\ndef do():\n n=int(input())\n a=[]\n for i in range(n):\n a.append(int(input()))\n print(max(a))\n return\nfor i in range(t):\n do()", "# cook your di...
[{"input": ["1", "5", "4", "7", "6", "3", "1"], "output": ["7"]}]
interview
634
Lyra Belacqua is a very gifted girl. She is one of a very small set of people capable of reading an alethiometer, more commonly known as The Golden Compass. It has one specific use: to tell the truth. The name in fact, is derived from "Aletheia" meaning truth, and "-ometer", meaning "measuring device". The alethiomete...
["string=input()\nmax_no=0\nfor i in range(len(string)):\n var_occur=0\n check_no=str()\n j=i\n while(j<len(string) and var_occur<2 ):\n if(string[j].isalpha()):\n if(var_occur==0):\n check_no+='9'\n var_occur+=1\n else:\n var_occur+=1\n else:\n check_no+=string[j]\n j+=1\n #print(check_no)\n max_no=m...
[{"input": ["06454", "Input2:", "C0D3C43F"], "output": ["6454", "Output2:", "3943"]}]
interview
635
Chef is given a sequence of prime numbers $A_1, A_2, \ldots, A_N$. This sequence has exactly $2^N$ subsequences. A subsequence of $A$ is good if it does not contain any two identical numbers; in particular, the empty sequence is good. Chef has to find the number of good subsequences which contain at most $K$ numbers. S...
["# cook your dish here\nfrom collections import Counter\ndef solve(arr, n, k):\n ans = 0\n dict1 = {}\n mod = 1000000007\n \n for i in range(n):\n if arr[i] in dict1:\n dict1[arr[i]] += 1 \n else:\n dict1[arr[i]] = 1\n l1 = [0]+list(dict1.keys())\n v = min(k, len(l1))\n dp = [[0 for _ in range(v+1)]for _ in rang...
[{"input": ["5 3", "2 2 3 3 5"], "output": ["18"]}]
interview
636
In this problem you are given a sequence of $N$ positive integers $S[1],S[2],\dots,S[N]$. In addition you are given an integer $T$, and your aim is to find the number of quadruples $(i,j,k,l)$, such that $1 \le i < j < k < l \le N$, and $S[i] + S[j] + S[k] + S[l] = T$. That is, the number of ways of picking four numb...
["# cook your dish here\nfrom itertools import combinations\na = list(map(int, input().split()))\nn = a[0]\nt = a[1]\nq = list(combinations(a[2:], 4))\ntotal = 0\nfor i in q:\n if sum(i) == t:\n total += 1\nprint(total)\n", "from itertools import combinations\ndef rSubset(arr, r): \n return list(combinati...
[{"input": ["6 20 3 1 1 2 5 10"], "output": ["1"]}]
interview
637
A balanced parenthesis string is defined as follows: - The empty string is balanced - If P is balanced, (P) is also - If P and Q are balanced, PQ is also balanced You are given two even integers n$n$ and k$k$. Find any balanced paranthesis string of length n$n$ that doesn't contain a balanced substring of length k$k$,...
["import sys\n\n\ndef input():\n return sys.stdin.readline().strip()\n\n\nfor i in range(int(input())):\n n, k = map(int, input().split())\n arr = []\n if k == 2 or k == 4 or n % 2 != 0 or n == k:\n arr.append('-1')\n elif k % 2 != 0:\n for i in range(int(n / 2)):\n arr.append('(...
[{"input": ["2", "4 2", "8 6"], "output": ["-1", "(())(())"]}]
interview
638
You will be given m strings. For each of those strings, you need to count the total number of appearances of that string as substrings in all possible strings of length n containing only lower case English letters. A string may appear in a string multiple times. Also, these appearances may overlap. All these must be ...
["for _ in range(int(input())):\r\n n,m=map(int,input().split())\r\n print(\"Case \"+str(_+1)+\":\")\r\n for i in range(m):\r\n s=input()\r\n ls=len(s)\r\n if ls>n:\r\n print(\"0\")\r\n else:\r\n k=(n-ls+1)\r\n print((k*pow(26,n-ls,1000000007))%10000...
[{"input": ["3", "2 1", "aa", "2 1", "d", "12 3", "cdmn", "qweewef", "qs", "", ""], "output": ["Case 1:", "1", "Case 2:", "52", "Case 3:", "443568031", "71288256", "41317270"]}]
interview
639
For a string $S$ let the unique set of characters that occur in it one or more times be $C$. Consider a permutation of the elements of $C$ as $(c_1, c_2, c_3 ... )$. Let $f(c)$ be the number of times $c$ occurs in $S$. If any such permutation of the elements of $C$ satisfies $f(c_i) = f(c_{i-1}) + f(c_{i-2})$ for all $...
["# cook your dish here\nt=int(input())\nfor _ in range(t):\n st=input()\n s=set(st)\n a=[]\n f1=f2=0\n for i in s:\n a.append(st.count(i))\n a.sort()\n if len(a)>=3:\n for i in range(2,len(a)):\n if a[i]!=a[i-1]+a[i-2]:\n f1=1\n break\n x=a[0]\n a[0]=a[1]\n a[1]=x\n for i in range(2,len(a)):\n if a[i]!...
[{"input": ["3", "aaaabccc", "aabbcc", "ppppmmnnoooopp"], "output": ["Dynamic", "Not", "Dynamic"]}]
interview
640
Chef made two laddus with sweetness X and Y respectively. Cheffina comes and sees the chef created two laddus with different sweetness (might be same). Cheffina has the magical power to make the sweetness of laddus equal. Cheffina requires 1 unit of power to increase the sweetness of laddu by its original value i.e. 1 ...
["def gcd(a,b):\r\n\tif b==0:return a\r\n\telse:return gcd(b,a%b)\r\ndef lcm(a,b):\r\n\tm=a*b\r\n\tg=gcd(a,b)\r\n\treturn int(m/g)\r\nfor _ in range(int(input())):\r\n\tx,y=[int(x) for x in input().split()]\r\n\tl=lcm(x,y)\r\n\ts=int(l/x)\r\n\tt=int(l/y)\r\n\tprint(s+t-2)", "for i in range(int(input())):\r\n def gcd...
[{"input": ["2", "2 2", "4 6"], "output": ["0", "3"]}]
interview
641
A key feature of the Siruseri railway network is that it has exactly one route between any pair of stations. The government has chosen three contractors to run the canteens at the stations on the railway network. To ensure that there are no disputes between the contractors it has been decided that if two stations, say ...
["n=int(input())\r\ncost=[]\r\nd={}\r\nval_desc=[0]*n\r\nvisited=set()\r\nvisited.add(0)\r\ndfstack=[]\r\ndesc = [[False for i in range(n)] for i in range(n)]\r\nfor i in range(n):\r\n\tcost.append(int(input()))\r\n\td[i]=[]\r\n\r\nfor i in range(n-1):\r\n\tj,k=list(map(int,input().split()))\r\n\td[j-1].append(k-1)\r\n...
[{"input": ["6", "10", "20", "25", "40", "30", "30", "4 5", "1 3", "3 4", "2 3", "6 4"], "output": ["70"]}]
interview
642
Chef is the leader of Chef's Earth Defense Organization, and his mission is to counter aliens which are threatening the earth. According to information gathered by the organization, there are $N$ alien spaceships (numbered $1$ through $N$) planning to invade the earth. The $i$-th spaceship will appear on the radar at t...
["# cook your dish here\ndef isValid(mid):\n time = 0.0\n for i in range(n):\n if time < c[i]:\n time = c[i]\n time += mid # cannon cooling\n elif time >= c[i] and time <= c[i] + d:\n time += mid # cannon cooling\n else:\n return False\n return True\n\nt = int(input())\nwhile t != 0:\n n, d = list(map(int, i...
[{"input": ["2", "3 2", "3 2 3", "2 1", "5 6"], "output": ["1.5000000000", "2.0000000000"]}]
interview
643
Ted$Ted$ loves prime numbers. One day he is playing a game called legendary$legendary$ with his girlfriend Robin$Robin$. Ted$Ted$ writes a number N$N$ on a table and the number is in the form of : N = P1A1 * P2A2 * ……….. * PnAn Ted$Ted$ asks Robin$Robin$ to find the sum of all the numbers which are less than or equal ...
["\r\n\r\nd = 10**9 + 7\r\n\r\nt = int(input())\r\nwhile t:\r\n t-=1\r\n n =int(input())\r\n p =list(map(int, input().strip().split()))\r\n a =list(map(int, input().strip().split()))\r\n b =list(map(int, input().strip().split()))\r\n ans = 1\r\n for i in range(n):\r\n c = a[i] - b[i] + 1\r\n...
[{"input": ["1", "3", "2 3 5", "2 1 2", "1 1 1"], "output": ["540"]}]
interview
644
There are $N$ friends in a group. Each of them have $A_{i}$ candies. Can they share all of these candies among themselves such that each one of them have equal no. of candies. -----Input:----- - First line will contain $T$, number of testcases. Then the testcases follow. - First line of each testcase contains of a si...
["# cook your dish here\n\nfor _ in range(int(input())):\n friends = int(input())\n candies = list(map(int,input().split()))\n if (sum(candies) % friends == 0):\n print(\"Yes\")\n else:\n print(\"No\")", "t=input()\nfor i in range(int(t)):\n n=int(input())\n l=list(map(int,input().split()))\n if(sum(l)%n==0): print(\...
[{"input": ["1", "3", "1 2 3"], "output": ["Yes"]}]
interview
645
Chef has $K$ chocolates and he wants to distribute them to $N$ people (numbered $1$ through $N$). These people are standing in a line in such a way that for each $i$ ($1 \le i \le N-1$), person $i$ and person $i+1$ are adjacent. First, consider some way to distribute chocolates such that for each valid $i$, the number ...
["t = int(input())\nfor _ in range(t):\n n = int(input())\n k = int(input())\n num = int(k/n)\n x = max(n*(1+num) - k, 0)\n diff = abs(x - (n-x))\n if diff == 0:\n number = 2*x - 1\n else:\n number = min(x, n-x)*2\n print(number)", "# cook your dish here\nt = int(input())\nfor _ in range(t):\n n = int(input())\n k = ...
[{"input": ["1", "3", "2"], "output": ["2"]}]
interview
646
Given a string $s$. You can perform the following operation on given string any number of time. Delete two successive elements of the string if they are same. After performing the above operation you have to return the least possible length of the string. -----Input:----- - First line will contain $T$, number of testc...
["from sys import stdin,stdout\nimport math,bisect\nfrom datetime import date\nfrom collections import Counter,deque,defaultdict\nL=lambda:list(map(int, stdin.readline().strip().split()))\nM=lambda:list(map(int, stdin.readline().strip().split()))\nI=lambda:int(stdin.readline().strip())\nS=lambda:stdin.readline().strip(...
[{"input": ["3", "abccd", "abbac", "aaaa"], "output": ["3", "1", "0"]}]
interview
647
Ashley wrote a random number generator code. Due to some reasons, the code only generates random positive integers which are not evenly divisible by 10. She gives $N$ and $S$ as input to the random number generator. The code generates a random number with number of digits equal to $N$ and sum of digits equal to $S$. Th...
["\"\"\"\n Author : thekushalghosh\n Team : CodeDiggers\n\"\"\"\nimport sys,math\ninput = sys.stdin.readline\n############ ---- USER DEFINED INPUT FUNCTIONS ---- ############\ndef inp():\n return(int(input()))\ndef inlt():\n return(list(map(int,input().split())))\ndef insr():\n s = input()\n return(...
[{"input": ["2", "1 5", "2 2"], "output": ["5", "1"]}]
interview
648
Chef is going to organize a hill jumping competition and he is going to be one of the judges in it. In this competition there are N hills in a row, and the initial height of i-th hill is Ai. Participants are required to demonstrate their jumping skills by doing what the judges tell them. Judges will give each participa...
["n,q=list(map(int,input().split()))\nfinal=[]\nheight=list(map(int,input().split()))\nfor k in range(0,q):\n b=input().split()\n if int(b[0])==1:\n step=int(b[1])-1\n for k in range(0,int(b[2])):\n temp = 0\n j=1\n while j in range(1,101) and temp==0 and step+j<n:\n if height[step+j]>height[step]:\n ste...
[{"input": ["5 3", "1 2 3 4 5", "1 1 2", "2 3 4 -1", "1 1 2"], "output": ["3", "4"]}]
interview
649
Mandarin chinese , Russian and Vietnamese as well. You are given a grid with $n$ rows and $m$ columns. Each cell of this grid can either be empty or it contains one particle. It can never contain more than one particle. Let's denote the cell in the $i$-th row and $j$-th column by $(i, j)$, with the top left corner bein...
["def main():\n for _ in range(int(input())):\n rows,column = map(int,input().split())\n arr = []\n for i in range(rows):\n arr.append(list(input()))\n string = input()\n last = string[-1]\n operation = Find(string,last)\n for i in string[0]+operation:\n if i == \"L\":\n arr = Left(arr)\n if i == \"R\":...
[{"input": ["3", "4 4", "1010", "0010", "1001", "0100", "LRDU", "4 3", "000", "010", "001", "101", "LRL", "3 2", "01", "10", "00", "D"], "output": ["0011", "0011", "0001", "0001", "000", "100", "100", "110", "00", "00", "11"]}]
interview
650
Chef is the event manager of his college. He has been assigned the task to manage the upcoming tech fest. There are $K$ rooms where the event can take place, and at a particular time only one event can be organized in a room for a particular time interval. Each event coordinator has their strictly preferred room $P_i$,...
["import sys\r\n# import math\r\nfrom math import gcd\r\n# import re\r\n# from heapq import *\r\n# from collections import defaultdict as dd\r\n# from collections import OrderedDict as odict\r\n# from collections import Counter as cc\r\n# from collections import deque\r\n# sys.setrecursionlimit(10**5)#thsis is must\r\n...
[{"input": ["1", "4 2", "1 10 1", "10 20 2", "15 50 2", "20 30 2"], "output": ["3"]}]
interview
651
In these quarantine days, Chef and Chefina are getting bored. So, Chef came up with a game for her. He gets a pack of cards with numbers written on them. Chef then asks her to remove cards from the pack in the following manner: Chefina can choose any 3 cards at a time, having unique values, and remove the smallest and ...
["# cook your dish here\ntry:\n for i in range(int(input())):\n n=int(input())\n l=[int(j) for j in input().split()][:n]\n d={}\n for j in l:\n d[j]=d.get(j,0)+1\n a=len(d)\n c=0\n for j in list(d.keys()):\n while(d[j]>=3):\n d[j]=(d[j]//3)+(d[j]%3)\n if(d[j]==2):\n c=c+1\n if(c&1):\n s=0\n for ...
[{"input": ["2", "5", "1 2 2 3 5", "9", "1 2 2 3 3 5 8 8 9"], "output": ["3", "5"]}]
interview
652
Shubham recently learned the lexicographical order in strings. Now, he has two strings s1 and s2 of the equal size and Shubham wants to compare those two strings lexicographically. Help Shubham with the strings comparison. Note: Letters are case insensitive. -----Input----- First line contains a integer T de...
["t=eval(input())\nwhile t:\n t=t-1\n s1=input().lower()\n s2=input().lower()\n res=\"equal\"\n for i in range(len(s1)):\n if(s1[i]!=s2[i]):\n \n res=\"first\" if s1[i]<s2[i] else \"second\"\n break\n print(res)\n", "import sys\n\nfor __ in range(eval(input())) :\n a , b = input().lower() , input().lower()\n if ...
[{"input": ["2", "abc", "acb", "AB", "ba"], "output": ["first", "first"]}]
interview
653
You have a laser with P amount of energy in it. You are playing a game where you have to use the laser to destroy some crystals, each with some health of their own. Initially, you have 0 points. Each crystal has an associated health. The health of the ith crystal is given by health[i]. You can perform one of the two ac...
["def game(n,l,p):\n if(len(l)==0):\n return 0\n l.sort()\n if(len(l)>=1 and p<l[0]):\n return 0\n l.sort()\n c=0\n \n \n ma=set()\n ma.add(0)\n while(len(l)):\n if(p>=l[0]):\n p-=l[0]\n \n c+=1\n ma.add(c)\n l=l[1...
[{"input": ["1", "200", "100"], "output": ["0"]}]
interview
654
Three numbers A, B and C are the inputs. Write a program to find second largest among them. -----Input----- The first line contains an integer T, the total number of testcases. Then T lines follow, each line contains three integers A, B and C. -----Output----- For each test case, display the second largest among A...
["# cook your dish here\nx=int(input())\nfor i in range(x):\n s=list(map(int,input().split()))\n s.sort()\n print(s[1])\n \n \n", "for i in range(int(input())):\r\n a=list(map(int, input().split()))\r\n a.sort()\r\n print(a[1])", "n= int(input())\nfor i in range(n):\n a,b,c= list(map(int,inpu...
[{"input": ["3", "120 11 400", "10213 312 10", "10 3 450"], "output": ["120", "312", "10"]}]
interview
655
Chef had a sequence of positive integers with length $N + K$. He managed to calculate the arithmetic average of all elements of this sequence (let's denote it by $V$), but then, his little brother deleted $K$ elements from it. All deleted elements had the same value. Chef still knows the remaining $N$ elements — a sequ...
["def __starting_point():\n t=int(input())\n for _ in range(t):\n n,k,v=map(int,input().split())\n li=list(map(int,input().split()))\n sumn=0\n for i in range(n):\n sumn=sumn+li[i]\n sumk=v*(n+k)-sumn\n e=int(sumk/k)\n r=sumk%k\n if e<=0:\n print(-1)\n elif r!=0:\n print(-1)\n else:\n print(e)\n__star...
[{"input": ["3", "3 3 4", "2 7 3", "3 1 4", "7 6 5", "3 3 4", "2 8 3"], "output": ["4", "-1", "-1"]}]
interview
656
Write a program to obtain a number $N$ and increment its value by 1 if the number is divisible by 4 $otherwise$ decrement its value by 1. -----Input:----- - First line will contain a number $N$. -----Output:----- Output a single line, the new value of the number. -----Constraints----- - $0 \leq N \leq 1000$ -----Sa...
["# cook your dish here\nn = int(input())\nif(n%4==0):\n print(n+1)\nelse:\n print(n-1)", "n=int(input())\nif n%4==0:\n n+=1\nelse:\n n-=1\nprint(n)", "# cook your dish h\nn = int(input())\nif n%4==0:\n print(n+1)\nelse:\n print(n-1)", "# cook your dish h\nn = int(input())\nif n%4==0:\n print(n+1)\...
[{"input": ["5"], "output": ["4"]}]
interview
657
You will be given a two-dimensional array with row consisting values 0 or 1. A move consists of choosing any column or row, and toggling all the 0’s as 1’s and 1’s as 0’s. After making the required moves, every row represents a binary number and the score of the matrix will be sum of all the numbers represented as ...
["def matrixScore(A):\r\n \"\"\"\r\n :type A: List[List[int]]\r\n :rtype: int\r\n \"\"\"\r\n m,n = len(A),len(A[0])\r\n # \u884c\u53d8\u6362\r\n for i in range(m):\r\n if A[i][0] == 1: continue\r\n for j in range(n):\r\n A[i][j] = 1 -...
[{"input": ["3 4", "0 0 1 1", "1 0 1 0", "1 1 0 0"], "output": ["39"]}]
interview
658
A sequence of integers ($a_1, a_2, \ldots, a_k$) is said to be UpDown, if these inequalities hold true: - $a_1 \le a_2$ - $a_2 \ge a_3$ - $a_3 \le a_4$ and so on. That is, every even-indexed element should be at least as large as its adjacent elements. And every odd-indexed element should be at most as large as its adj...
["# cook your dish here\nt=int(input())\nfor _ in range(t):\n n=int(input())\n array=list(map(int, input().split()))\n list_sub=[]\n idx=0\n counter=0\n for i in range(n-1):\n if counter%2==0 and array[i]<=array[i+1]:\n counter+=1 \n elif counter%2==1 and array[i]>=array[i+1]:...
[{"input": ["2", "7", "100 1 10 3 20 25 24", "5", "3 3 2 4 1"], "output": ["7", "6"]}]
interview
659
Binod is a youtuber and he is busy in the fame of social media so he asked you to help him solve a problem. You have been given an array of $positive$ $integers$ $a_{1},a_{2},a_{3},...,a_{i},...,a_{n}$ of size n.You have to find the smallest length of the subarray such that the length of the subarray must be $strictly$...
["#binarr\r\ndef binarr(a, k, s):\r\n a.sort(reverse=True)\r\n arr = [0]*k\r\n for i in range(k):\r\n arr[i] = a[i]\r\n if sum(arr) <= s:\r\n return binarr(a, k+1, s)\r\n return len(arr)\r\n\r\ntry:\r\n n, k, s = list(map(int, input().split()))\r\n a = list(map(int, input().split()))\...
[{"input": ["1:", "5 1 5", "1 2 3 4 5"], "output": ["2"]}]
interview
660
The chef was busy in solving algebra, he found some interesting results, that there are many numbers which can be formed by the sum of the factorial of the digits, he wrote all those interesting numbers in the diary(in increasing order) and went to sleep. Cheffina came and stole his diary, in morning chef found that hi...
["t = int(input())\nfor i in range(t):\n n = int(input())\n if n == 1 or n == 2 or n == 145 or n == 40585:\n print(1)\n else:\n print(0)\n", "from collections import Counter\r\nimport string\r\nimport math\r\nimport sys\r\n# sys.setrecursionlimit(10**6) \r\ndef isprime(x): \r\n \r\n # che...
[{"input": ["2", "2", "10"], "output": ["1", "0"]}]
interview
661
Raju has created a program to find the square root of a number. But his program can store only integers. Being a newbie, he didn't know about rounding the numbers. Hence his program returns the absolute value of the result if possible. For example, sqrt(3) = 1.73205080757……. His program will return 1 Given a number $N$...
["try:\n from math import sqrt\n t,x=list(map(int,input().split()))\n for _ in range(t):\n n=int(input())\n if(n<0):\n print(\"no\")\n else:\n diff=(x/100)*n\n ans=int(sqrt(n))\n ans1=ans**2\n if(n-ans1<=diff):\n print(\"yes\")\n else:\n print(\"no\")\nexcept:\n pass\n", "import math \nt,x=map(int,...
[{"input": ["2 20", "5", "3"], "output": ["yes", "no"]}]
interview
662
Kabir wants to impress Tara by showing her his problem solving skills. He has decided to give the correct answer to the next question which will be asked by his Algorithms teacher. The question asked is: Find the sum of alternate consecutive d$d$ odd numbers from the range L$L$ to R$R$ inclusive. if d$d$ is 3 and L$L$ ...
["# cook your dish here\nfor t in range(int(input().strip())):\n d = int(input().strip())\n L, R = map(int, input().strip().split(\" \"))\n if L % 2 == 0:\n L += 1\n sum = (((((R - L + 2)//2)//d)+1)//2) - 1\n sum = (sum * 2 * d * (sum + 1) * d) + (sum+1) *d * (L + d -1)\n print(sum%1000000007)"...
[{"input": ["1", "3", "10 33"], "output": ["114"]}]
interview
663
You are given a string $S$ and an integer $L$. A operation is described as :- "You are allowed to pick any substring from first $L$ charcaters of $S$, and place it at the end of the string $S$. A string $A$ is a substring of an string $B$ if $A$ can be obtained from $B$ by deletion of several (possibly, zero or all) c...
["def least_rotation(S: str) -> int:\r\n \"\"\"Booth's algorithm.\"\"\"\r\n f = [-1] * len(S) # Failure function\r\n k = 0 # Least rotation of string found so far\r\n for j in range(1, len(S)):\r\n sj = S[j]\r\n i = f[j - k - 1]\r\n while i != -1 and sj != S[k + i + 1]:\r\n ...
[{"input": ["2", "1 rga", "2 cab"], "output": ["arg", "abc"]}]
interview
664
This year $p$ footballers and $q$ cricketers have been invited to participate in IPL (Indian Programming League) as guests. You have to accommodate them in $r$ rooms such that- - No room may remain empty. - A room may contain either only footballers or only cricketers, not both. - No cricketers are allowed to stay alon...
["# cook your dish here\nMOD = 998244353\n\nfball = [ [0]*101 for _ in range(101) ]\n\ncric = [ [0]*101 for _ in range(101) ] \n\n\n\ndef calSNum(n, r):\n if n == r or r == 1:\n fball[r][n] = 1\n return\n if n > 0 and r > 0 and n > r:\n fball[r][n] = (fball[r-1][n-1]%MOD + (r*fball[r][n-1])%MOD )%MOD\n return\n fba...
[{"input": ["4", "2 1 4", "2 4 4", "2 5 4", "2 8 4"], "output": ["0", "3", "10", "609"]}]
interview
665
Chef organised a chess tournament, which spanned over $M$ months. There were $N$ players, and player $i$ was rated $R_i$ before the start of the tournament. To see the progress of the players, he noted their rating changes at the end of each month. After the tournament, FIDE asked Chef to find the number of players who...
["# cook your dish here\nt=int(input())\nfor _ in range(t):\n n,m=list(map(int,input().split()))\n r=list(map(int,input().split()))\n rating=[[r[i]]*(m) for i in range(n)]\n ranking=[[0]*m for i in range(n)]\n for i in range(n):\n diff=list(map(int,input().split()))\n for j in range(m):\n rating[i][j]+=diff[j]\n ...
[{"input": ["2", "3 3", "2500 2500 2520", "10 -5 -20", "10 15 20", "-15 17 13", "2 3", "2125 2098", "-20 10 -10", "10 10 -20"], "output": ["2", "2"]}]
interview
666
The chef is trying to solve some pattern problems, Chef wants your help to code it. Chef has one number K to form a new pattern. Help the chef to code this pattern problem. -----Input:----- - First-line will contain $T$, the number of test cases. Then the test cases follow. - Each test case contains a single line of ...
["# cook your dish here\n\nt = int(input())\n\nfor _ in range(t):\n s = ''\n n = int(input())\n if n==1:\n print(1)\n continue\n for i in range(1, n+1):\n s = s + str(i)\n print(s)\n \n p = 1\n for i in range(n-1):\n s = ''\n for j in range(n):\n s =...
[{"input": ["4", "1", "2", "3", "4"], "output": ["1", "12", "34", "123", "456", "789", "1234", "5678", "9101112", "13141516"]}]
interview
667
Diana is planning to make a very long journey. Her journey consists of $N$ bus routes, numbered from $1 to N$ in the order she must take them. The buses themselves are very fast but do not run often. The $i-th$ bus route only runs every $Xi$ days. More specifically, she can only take the $i-th$ bus on day $Xi, 2Xi, 3X...
["t = int(input())\r\nfor _ in range(t):\r\n nd = list(map(int, input().split()))\r\n n = nd[0]\r\n d = nd[1]\r\n cutOff = []\r\n x = d\r\n buses = list(map(int, input().split()))\r\n for i in range(len(buses)-1,-1,-1):\r\n x = x - x%buses[i]\r\n print(x)\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r...
[{"input": ["3", "3 10", "3 7 2", "4 100", "11 10 5 50", "1 1", "1"], "output": ["6", "99", "1"]}]
interview
668
You are given an array A with size N (indexed from 0) and an integer K. Let's define another array B with size N · K as the array that's formed by concatenating K copies of array A. For example, if A = {1, 2} and K = 3, then B = {1, 2, 1, 2, 1, 2}. You have to find the maximum subarray sum of the array B. Fomally, you ...
["def max_sum(arr):\n # Finds the maximum sum of sub-arrays of arr\n max_till_now = -1000000 #minimum possible number \n current_sum = 0\n for i in range(len(arr)):\n if current_sum < 0:\n # If sum of previous elements is negative, then ignore them. Start fresh\n # with `current...
[{"input": ["2", "2 3", "1 2", "3 2", "1 -2 1", "", ""], "output": ["9", "2"]}]
interview
669
Nadaca is a country with N$N$ cities. These cities are numbered 1$1$ through N$N$ and connected by M$M$ bidirectional roads. Each city can be reached from every other city using these roads. Initially, Ryan is in city 1$1$. At each of the following K$K$ seconds, he may move from his current city to an adjacent city (a ...
["T = int(input())\nfor _ in range(T):\n N, M, K = [int(x) for x in input().split()]\n UV = [[int(x) for x in input().split()] for _ in range(M)]\n Q = int(input())\n AB = [[int(x) for x in input().split()] for _ in range(Q)]\n \n X = [[i] for i in range(N)]\n for u, v in UV:\n X[u - 1] += [v - 1]...
[{"input": ["3", "4 3 3", "1 2", "1 3", "1 4", "0", "4 3 3", "1 2", "1 3", "1 4", "1", "2 2", "4 3 3", "1 2", "1 3", "1 4", "1", "2 1"], "output": ["28", "4", "6"]}]
interview
670
Sereja has an array A of N positive integers : A[1], A[2], A[3], ... , A[N]. In a single operation on the array, he performs the following two steps : - Pick two indices i, j s.t. A[i] > A[j] - A[i] -= A[j] Sereja can apply these operations any number of times (possibly zero), such that the sum of resulting eleme...
["def gcd(a,b):\n if b==0:\n return a\n else:\n return gcd(b,a%b)\n \ndef main():\n t=int(input())\n while t!=0:\n t=t-1\n n=int(input())\n if n==1:\n print(input())\n else:\n a=list(map(int,input().split(\" \")))\n p=a[0]\n for i in range(1,n):\n p=gcd(p,a[i])\n if p==1:\n break\n print(n*p)\...
[{"input": ["2", "1", "1", "3", "2 4 6"], "output": ["1", "6"]}]
interview
671
Chef is going to start playing Fantasy Football League (FFL) this season. In FFL, each team consists of exactly $15$ players: $2$ goalkeepers, $5$ defenders, $5$ midfielders and $3$ forwards. Chef has already bought $13$ players; he is only missing one defender and one forward. There are $N$ available players (numbered...
["for i in range(int(input())):\n n,s =map(int,input().split())\n l1=list(map(int,input().split()))\n l2=list(map(int,input().split()))\n m=[]\n n=[]\n for i in range(len(l1)):\n if l2[i]==0:\n m.append(l1[i])\n else:\n n.append(l1[i])\n if len(m)>0 and len(n)>0:\n if 100-s>=(min(m)+min(n)):\n print(\"yes\")\n...
[{"input": ["2", "4 90", "3 8 6 5", "0 1 1 0", "4 90", "5 7 6 5", "0 1 1 0"], "output": ["yes", "no"]}]
interview
672
In my town ,there live a coder named Chef . He is a cool programmer . One day , he participate in a programming contest ,the contest give him only one problem . If he can’t solve the problem ,the problem setter will kill him . But the round allow you to help Chef. Can you save the life of Chef from problem setter ? :p ...
["# cook your dish here\nfrom math import sqrt\nfor i in range(int(input())):\n x1,y1,x2,y2=list(map(float,input().split()))\n m=(y2-y1)/(x2-x1)\n c=y2-m*x2\n print('Test case : ',i+1)\n q=int(input())\n for i in range(q):\n x3,y3=list(map(float,input().split()))\n if(y3-m*x3-c==0):\n print(\"YES\")\n else:\n d=...
[{"input": ["2", "3 5 6 5", "2", "4 5", "6 8", "3 4 7 10", "1", "7 4"], "output": ["Test case : 1", "YES", "NO", "3.000000", "Test case : 2", "NO", "3.328201"]}]
interview
673
Its Christmas time and Santa has started his ride to deliver gifts to children waiting for him in a 1-dimentional city. All houses in this city are on a number line numbered as 1, 2, 3… and so on. Santa wants to deliver to houses from n to m, but he found that all the kids living at positions that are divisible by a, a...
["from math import gcd\r\nfrom math import ceil\r\nfrom itertools import combinations as c\r\nt=int(input())\r\nfor _ in range(t):\r\n n,m,a,d=list(map(int,input().split()))\r\n \r\n l=[]\r\n for i in range(5):\r\n l.append(a+i*d)\r\n ans=m-n+1\r\n for i in range(1,6):\r\n x=list(c(l,i))...
[{"input": ["1", "2 20 2 1"], "output": ["5"]}]
interview
674
Chef bought an electronic board and pen. He wants to use them to record his clients' signatures. The board is a grid with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$) of pixels. Initially, all pixels are white. A client uses the electronic pen to sign on the board; whenever the pen tou...
["import numpy as np\nfor _ in range(int(input())):\n ans = np.float('inf')\n n, m = (int(x) for x in input().split())\n sig = np.zeros((n,m))\n img = np.zeros((3*n,3*m))\n for row in range(n):\n sig[row,:] = np.array([int(x) for x in input()])\n for row in range(n):\n img[row+n,m:2*m] = np.array([int(x) for x in inp...
[{"input": ["5", "3 3", "100", "010", "000", "000", "010", "001", "4 4", "0000", "0110", "0000", "0011", "1100", "0000", "1100", "0000", "3 3", "100", "000", "001", "000", "010", "000", "3 3", "000", "010", "000", "100", "000", "001", "3 3", "111", "000", "000", "001", "001", "001"], "output": ["0", "2", "1", "0", "2"]...
interview
675
A permutation $p_1,p_2...p_N$ of $\{1, 2, ..., N\}$ is beautiful if $p_i \& p_{i+1}$ is greater than 0 for every $1 \leq i < N$ . You are given an integer $N$, and your task is toconstruct a beautiful permutation of length $N$ or determine that it's impossible. Note that $a \& b$ denotes the bitwise AND of $a$ and $b$....
["import math\ndef ispoweroftwo(y):\n return math.ceil(math.log(y,2))==math.floor(math.log(y,2))\nt=int(input())\nfor i in range(t):\n n=int(input())\n \n a=[]\n if(ispoweroftwo(n) and n!=1):\n print(-1,end=\" \")\n if(n==1):\n print(1)\n \n if(n>=3 and not(ispoweroftwo(n))):\n a.append(2)\n a.append(3)\n a.append...
[{"input": ["3", "4", "3", "5"], "output": ["-1", "1 3 2", "2 3 1 5 4"]}]
interview
676
There is an event in DUCS where boys get a chance to show off their skills to impress girls. The boy who impresses the maximum number of girls will be honoured with the title “Charming Boy of the year”. There are $N$ girls in the department. Each girl gives the name of a boy who impressed her the most. You need to find...
["from collections import Counter\r\n\r\nfor _ in range(int(input())):\r\n n=int(input())\r\n l=[i for i in input().split()]\r\n ll=[]\r\n c=Counter(l)\r\n cc=[]\r\n m=0\r\n for l,count in c.most_common(len(l)-1):\r\n if m==0:\r\n ll.append(l)\r\n cc.append(count)\r\n ...
[{"input": ["2", "10", "john berry berry thomas thomas john john berry thomas john", "4", "ramesh suresh suresh ramesh"], "output": ["john", "ramesh"]}]
interview
677
Computation of the date either previous or forthcoming dates is quiet easy. But it is quiet difficult to calculate the day from a particular given date. You are required to find a day from a particular date given to you. -----Input----- It consists of a single line entry consisting of date in format dd mm yyyy. i.e. ...
["import sys\nimport datetime\na,b,c = list(map(int,sys.stdin.readline().split()))\nd = datetime.date(c,b,a)\nprint(d.strftime(\"%A\"))", "import sys\nfrom datetime import date\na,b,c = list(map(int,sys.stdin.readline().split()))\nd = date(c,b,a)\nprint(d.strftime(\"%A\"))", "import sys\nfrom datetime import date\na,b,...
[{"input": ["14 3 2012"], "output": ["Wednesday"]}]
interview
678
Snackdown 2019 is coming! People have started to spread the word and tell other people about the contest. There are $N$ people numbered $1$ through $N$. Initially, only person $1$ knows about Snackdown. On each day, everyone who already knows about Snackdown tells other people about it. For each valid $i$, person $i$ c...
["# cook your dish here\ntest_case = int(input())\nwhile test_case :\n n_people = int(input())\n array = list(map(int, input().strip().split()))\n sums =[0 for i in range(n_people)]\n \n sums[0] = array[0]\n \n for i in range(1, n_people) :\n sums[i] = sums[i-1] + array[i]\n \n # print(sums)\n\n k = 1 \n count = 0\n ...
[{"input": ["2", "7", "2 1 1 5 5 5 5", "5", "5 1 3 2 1"], "output": ["2", "1"]}]
interview
679
Harry is a bright student. To prepare thoroughly for exams, he completes all the exercises in his book! Now that the exams are approaching fast, he is doing book exercises day and night. He writes down and keeps updating the remaining number of exercises on the back cover of each book. Harry has a lot of books messed o...
["t=eval(input())\n \na=[]\nb=[]\n \ntop=-1\n \nfor __ in range(0,t):\n \n x=input().split()\n \n if(x[0]!=\"-1\" and x[0]!=\"0\"):\n \n add=int(x[0])\n \n if top!=-1 and add>a[top][0] :\n \n b[top]+=1\n \n else:\n a.append((add,x[1]))\n \n b.append(0)\n top+=1\n \n \n elif (x[0]==\"-1\"):\n...
[{"input": ["6", "9 english", "6 mathematics", "8 geography", "-1", "3 graphics", "-1"], "output": ["1 mathematics", "0 graphics"]}]
interview
680
You are given two integer sequences $A_1, A_2, \ldots, A_N$ and $B_1, B_2, \ldots, B_M$. For any two sequences $U_1, U_2, \ldots, U_p$ and $V_1, V_2, \ldots, V_q$, we define Score(U,V)=∑i=1p∑j=1qUi⋅Vj.Score(U,V)=∑i=1p∑j=1qUi⋅Vj.Score(U, V) = \sum_{i=1}^p \sum_{j=1}^q U_i \cdot V_j \,. You should process $Q$ queries of...
["t = int(input())\nl,r,x = 0,0,0\nans = []\nfor i in range(t):\n (n,m) = tuple(map(int,input().split()))\n a = list(map(int,input().split()))\n b = list(map(int,input().split()))\n suma = sum(a)\n sumb = sum(b)\n q = int(input())\n for j in range(q):\n l1 = list(map(int,input().split()))\n if l1[0] == 1:\n l = l1[...
[{"input": ["1", "3 4", "2 -1 5", "3 3 2 4", "6", "3", "1 2 3 -2", "3", "1 1 3 1", "2 2 4 2", "3"], "output": ["72", "24", "90"]}]
interview
681
You are playing following game: given an array A of N natural numbers. All numbers in the array A are at most M. On every turn you may pick any two different elements Ai and Aj (i≠j), such that Ai, Aj ≤ M, and add K to both. The game ends when you are not able to continue. That is, when there is no pair (i,j) left such...
["\nfrom math import ceil\nfrom bisect import bisect_right as b_r\nfrom bisect import bisect_left as b_l\nar = list(map(int , input().split()))\na = [int(ceil((ar[1]-int(x)+1)/ar[2])) for x in input().split()]\ns = sum(a)\nar[1] = max(a)\nm = ar[1] - (s-ar[1])%2\nmi = s%2 \nprint(int( (m-mi)//2 +1)%(10**9+7))\n\n"]
[{"input": ["3 3 2", "1 2 3"], "output": ["2"]}]
interview
682
Rohit collects coins: he has exactly one coin for every year from 1 to n. Naturally, Rohit keeps all the coins in his collection in the order in which they were released. Once Rohit's younger brother made a change — he took all the coins whose release year dated from l to r inclusively and put them in the reverse order...
["n=int(input())\na=list(map(int,input().split()))\n\nl,r=-1,-1\nfor i in range(n):\n if a[i]!=i+1:\n l=i\n break\n\nfor i in range(n-1,-1,-1):\n if a[i]!=i+1:\n r=i\n break\n\nj=r+1\n\nfor i in range(l,r+1):\n if a[i]==j:\n j-=1\n continue\n else:\n print(0,...
[{"input": ["8", "1 6 5 4 3 2 7 8"], "output": ["2 6"]}]
interview
683
-----Problem Statement----- Write a program that accepts a number, n, and outputs the same. -----Input----- The only line contains a single integer. -----Output----- Output the answer in a single line. -----Constraints----- - 0 ≤ n ≤ 105 -----Sample Input----- 123 -----Sample Output----- 123
["# cook your dish here\na = int(input())\nprint(a)", "# cook your dish here\nnum = int(input())\nprint(num)", "# cook your dish here\nnum = int(input())\nprint(num)", "a=int(input(\"\"))\nprint(a)", "a=int(input())\nprint(a)", "from sys import *\n\n\ndef main():\n nombre = stdin.readline().strip()\n stdout.write...
[{"input": ["123"], "output": ["123"]}]
interview
684
Congratulations !!! You have successfully completed the heist by looting all the gifts in Santa's locker. Now it's time to decide who gets to take all the gifts, you or the Grinch, there will be no splitting. So you and Grinch decide to play a game. To start the game, an Integer N will be given. The game is played in t...
["# cook your dish here\nimport math \n \n# Function to find the Largest \n# Odd Divisor Game to check \n# which player wins \ndef findWinner(n, k): \n \n cnt = 0; \n \n # Check if n == 1 then \n # player 2 will win \n if (n == 1): \n print(\"Grinch\"); \n \n # Check if n == 2 or ...
[{"input": ["7", "1", "2", "3", "4", "5", "6", "12"], "output": ["Grinch", "Me", "Me", "Grinch", "Me", "Grinch", "Me"]}]
interview
685
You are given an axis-aligned rectangle in a 2D Cartesian plane. The bottom left corner of this rectangle has coordinates (0,0)$(0, 0)$ and the top right corner has coordinates (N−1,N−1)$(N-1, N-1)$. You are also given K$K$ light sources; each light source is a point inside or on the perimeter of the rectangle. For eac...
["# https://www.codechef.com/problems/RECTLIT\r\n\r\ndef assess(sq,points):\r\n EWct = 0\r\n NSct = 0\r\n for a,b in points:\r\n EW = (a == 0 or a == sq)\r\n NS = (b == 0 or b == sq)\r\n if EW and NS:\r\n return 'yes'\r\n EWct += EW\r\n NSct += NS\r\n if NSct + ...
[{"input": ["2", "2 10", "0 0", "1 0", "2 10", "1 2", "1 1"], "output": ["yes", "no"]}]
interview
686
Chef has been working in a restaurant which has N floors. He wants to minimize the time it takes him to go from the N-th floor to ground floor. He can either take the elevator or the stairs. The stairs are at an angle of 45 degrees and Chef's velocity is V1 m/s when taking the stairs down. The elevator on the other ...
["n=int(input())\nl=[]\nfor i in range(0,n):\n a,b,c=map(int,input().split())\n n1=(2**0.5)*(a/b)\n n2=2*(a/c)\n if n1>n2:\n l.append(\"Elevator\")\n else:\n l.append(\"Stairs\")\nfor i in l:\n print(i)", "n=int(input())\nl=[]\nfor i in range(0,n):\n a,b,c=list(map(int,input().split()))\n n1=(2**0.5)*(a/b)\n n2=2*(a/...
[{"input": ["3", "5 10 15", "2 10 14", "7 14 10"], "output": ["Elevator", "Stairs", "Stairs"]}]
interview
687
The Little Elephant likes permutations. This time he has a permutation A[1], A[2], ..., A[N] of numbers 1, 2, ..., N. He calls a permutation A good, if the number of its inversions is equal to the number of its local inversions. The number of inversions is equal to the number of pairs of integers (i; j) such that 1 ≤ ...
["from sys import stdin\nt = int(stdin.readline())\n\ndef count(n, arr):\n loc = 0\n glob = 0\n for i in range(n-1):\n if arr[i] > arr[i+1]:\n loc += 1\n for i in range(n-1):\n for j in range(i+1, n):\n if glob > loc:\n return 0\n if arr[i] > arr[j]:\n glob += 1;\n if glob == loc:\n return 1\n return 0\n...
[{"input": ["4", "1", "1", "2", "2 1", "3", "3 2 1", "4", "1 3 2 4"], "output": ["YES", "YES", "NO", "YES"]}]
interview
688
You are given a string s of length 8 consisting solely of '0's and '1's. Assume that the characters of the string are written in a circular fashion. You need to find the number of 0-1 or 1-0 transitions that one has to make while making a single traversal over the string. ie. start from any character and go circularly ...
["n = int(input())\n# this code only for 8 bits string and it isn't possible to more than 8 bits of \u00a0\u00a0\u00a0\u00a0string \n\n# for i in range(n):\n# s = input()\n# subString1, subString2 = s[:4], s[4:]\n# rev = subString2[::-1]\n# print( 'uniform' if(subString1 == rev) else 'non-uniform'...
[{"input": ["4", "00000000", "10101010", "10000001", "10010011"], "output": ["uniform", "non-uniform", "uniform", "non-uniform"]}]
interview
689
In africa jungle , there were zebra's who liked to spit. There owner watched them for whole day and noted in his sheet where each zebra spitted. Now he's in a confusion and wants to know if in the jungle there are two zebra's which spitted at each other. Help him solve this task. If the zebra is present in position a s...
["# cook your dish here\nt=int(input())\ni=0\na=0\nd=dict()\nwhile i<t:\n l=input().split()\n d[int(l[0])]=int(l[0])+int(l[1])\n i+=1\nfor k in d:\n if d[k] in d:\n if d[d[k]]==k:\n a=1\n break\nif a==1:\n print(\"YES\")\nelse:\n print(\"NO\")", "# cook your dish here\nt=i...
[{"input": ["2", "0 1", "1 -1"], "output": ["YES"]}]
interview
690
You are a king and you are at war. If the enemy breaks through your frontline you lose. Enemy can break the line only if the sum of morale of any $K$ continuous soldiers is strictly less than $M$. So, you being a motivational orator decides to boost their morale by giving a speech. On hearing it morale of a soldier mul...
["n,k,m = map(int,input().split())\nar = list(map(int,input().split()))\nfsum = [ar[0]]\nfor i in range(1,n):\n fsum.append(fsum[i-1]+ar[i])\ni = k\n#print(fsum)\nc = 0\nwhile i <= n:\n if i == k:\n s = fsum[i-1]\n else:\n s = fsum[i-1]-fsum[i-k-1]\n if s == 0:\n c = -1\n break\n...
[{"input": ["6 2 5", "1 1 1 1 1 1"], "output": ["2"]}]
interview
691
You are given a sequence $A_1, A_2, \ldots, A_N$. For each valid $i$, the star value of the element $A_i$ is the number of valid indices $j < i$ such that $A_j$ is divisible by $A_i$. Chef is a curious person, so he wants to know the maximum star value in the given sequence. Help him find it. -----Input----- - The fir...
["T = int(input())\nfor _ in range(T):\n n = int(input())\n arr = list(map(int, input().split()))\n a = [0 for _ in range(max(arr)+1)]\n star_val = []\n for i in range(len(arr)):\n j = 1\n val = 0\n while j*arr[i] <= len(a):\n val += a[j*arr[i]-1]\n j += 1\n star_val.append(val)\n a[arr[i]-1] += 1\n print(max(...
[{"input": ["1", "7", "8 1 28 4 2 6 7"], "output": ["3"]}]
interview
692
There is crazy man named P29892P. He always tries to do crazy things as he thinks. One day he invented a machine and named it as ANGEN. The ANGEN is used to perform range operations. The range operation means performing operations on range values from {L..R}. At any time it performs operations on values in between L to...
["VQ = \"UAMmSs\"\nn = int(input())\na = list(map(int, input().split()))\nfor _ in range(int(input())):\n q, x, y = input().split()\n if q not in VQ:\n print(\"!!!\")\n continue\n if q == \"U\":\n a[int(x) - 1] = int(y)\n continue\n l = int(x) - 1\n r = int(y)\n if q == \"A\":\n print(sum(a[l:r]))\n continue\n if...
[{"input": ["6", "1 2 5 3 10 6", "6", "A 1 5", "M 1 3", "m 5 6", "s 3 6", "U 1 7", "S 1 2"], "output": ["21", "5", "6", "5", "2"]}]
interview
693
Write a program to find the factorial value of any number entered by the user. -----Input----- The first line contains an integer T, the total number of testcases. Then T lines follow, each line contains an integer N. -----Output----- For each test case, display the factorial of the given number N in a new line. -...
["# cook your dish here\nx=int(input())\nfor i in range(x):\n s=int(input())\n fact=1\n for i in range(1,s+1):\n fact=fact*i\n print(fact)\n", "# cook your dish here\nfor _ in range(int(input())):\n n= int(input())\n fact=1\n if n==0:\n pass\n else:\n for i in range(1, n+1):...
[{"input": ["3", "3", "4", "5"], "output": ["6", "24", "120"]}]
interview
694
The MarkiT online virtual market startup wants to organize its grand opening in NIT Patna. but they want maximum crowd for their inauguration. So the manager told this to Praveen a student in NITP who suggested them: The first-year students come to campus every x hour, Second-year students come to campus every y hou...
["import math\ndef fun(num1,num2):\n if num1>num2:\n a=num1\n b=num2\n else:\n a=num2\n b=num1\n rem=a%b\n while(rem!=0):\n a=b\n b=rem\n rem=a%b\n gcd=b\n return (int((num1*num2)/gcd))\n \nfor _ in range (int(input())):\n hours=int(input())*24\n x,y,z=list(map(int,input().split()))\n lcm=x\n lcm=fun(x,y)\n lcm...
[{"input": ["1", "10", "8 10 6"], "output": ["2"]}]
interview
695
You are given three non-negative integers $X$, $Y$ and $N$. Find the number of integers $Z$ such that $0 \le Z \le N$ and $(X \oplus Z) < (Y \oplus Z)$, where $\oplus$ denotes the bitwise XOR operation. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The d...
["# cook your dish here\ntc=int(input())\nfor j in range(tc):\n ip=list(map(int,input().rstrip().split()))\n x=ip[0]\n y=ip[1]\n n=ip[2]\n cnt=0\n if(x==y):\n print('0')\n continue\n ln=bin(x).replace(\"0b\", \"\") \n rn=bin(y).replace(\"0b\", \"\") \n ll=len(ln)\n rl=len(rn)\n #print(ln)\n #print(rn)\n if(ll==len(rn...
[{"input": ["3", "1 2 10", "2 1 10", "0 0 7"], "output": ["6", "5", "0"]}]
interview
696
You are given a permutation of natural integers from 1 to N, inclusive. Initially, the permutation is 1, 2, 3, ..., N. You are also given M pairs of integers, where the i-th is (Li Ri). In a single turn you can choose any of these pairs (let's say with the index j) and arbitrarily shuffle the elements of our permutatio...
["t=int(input())\nfor _ in range(t):\n n,m=list(map(int,input().split()))\n l=list(map(int,input().split()))\n k=[]\n for i in range(m):\n a,b=list(map(int,input().split()))\n k.append([a,b])\n k.sort()\n c=[]\n flag=1\n x=k[0][0]\n y=k[0][1]\n \n for i in k[1:]:\n if i[0]<=y:\n y=max(y,i[1])\n else:\n c.append...
[{"input": ["2", "7 4", "3 1 2 4 5 7 6", "1 2", "4 4", "6 7", "2 3", "4 2", "2 1 3 4", "2 4", "2 3"], "output": ["Possible", "Impossible"]}]
interview
697
In Programmers Army Land, people have started preparation as sports day is scheduled next week. You are given a task to form 1 team of $k$ consecutive players, from a list of sports player whose powers are given to you. You want your team to win this championship, so you have to chose your $k$ team players optimally i....
["# cook your dish here\ndef func(arr, k):\n sumi = 0\n for j in range(k):\n sumi += arr[j]\n maxi = sumi\n for i in range(k,len(arr)):\n sumi -= arr[i - k]\n sumi += arr[i]\n maxi = max(maxi,sumi)\n return maxi\nfor _ in range(int(input())):\n n, k = map(int,input().split(...
[{"input": ["1", "5 3", "1 2 3 4 5"], "output": ["12"]}]
interview
698
For years you have been working hard in Santa's factory to manufacture gifts for kids in substandard work environments with no pay. You have finally managed to escape the factory and now you seek revenge. You are planning a heist with the Grinch to steal all the gifts which are locked in a safe. Since you have worked i...
["import math\nt = int(input())\n \ndef phi(n):\n\tres = n\n\ti = 2\n\twhile i*i<=n:\n\t\tif n%i==0:\n\t\t\tres/=i\n\t\t\tres*=(i-1)\n \n\t\t\twhile n%i==0:\n\t\t\t\tn/=i\n\t\ti+=1\n\t\n\tif n>1:\n\t\tres/=n\n\t\tres*=(n-1)\n \n\treturn int(res)\n \nwhile t:\n\ta,m = list(map(int,input().split()))\n\tg = math.gcd(a,m)\...
[{"input": ["3", "4 9", "5 10", "42 9999999967"], "output": ["6", "1", "9999999966"]}]
interview
699
Chef wants to host some Division-3 contests. Chef has $N$ setters who are busy creating new problems for him. The $i^{th}$ setter has made $A_i$ problems where $1 \leq i \leq N$. A Division-3 contest should have exactly $K$ problems. Chef wants to plan for the next $D$ days using the problems that they have current...
["for T in range(int (eval(input()))):\n N,K,D=list(map(int,input().split()))\n A=list(map(int,input().split()))\n P=sum(A)//K \n print(min(P,D))\n", "# cook your dish here\n#Hello\nr=int(input())\nwhile r>0:\n n,k,d=map(int,input().split())\n l=list(map(int,input().split()))[0:n]\n sum=0\n for x in range(n):\n sum=su...
[{"input": ["5", "1 5 31", "4", "1 10 3", "23", "2 5 7", "20 36", "2 5 10", "19 2", "3 3 300", "1 1 1"], "output": ["0", "2", "7", "4", "1"]}]
interview