problem_id
stringlengths
32
32
name
stringclasses
1 value
problem
stringlengths
200
14k
solutions
stringlengths
12
1.12M
test_cases
stringlengths
37
74M
difficulty
stringclasses
3 values
language
stringclasses
1 value
source
stringclasses
7 values
num_solutions
int64
12
1.12M
starter_code
stringlengths
0
956
850751c1c91765c4a8b5feeb829f2e0b
UNKNOWN
Chef recently started working at ABC corporation. Let's number weekdays (Monday through Friday) by integers $1$ through $5$. For each valid $i$, the number of hours Chef spent working at the office on weekday $i$ was $A_i$. Unfortunately, due to the COVID-19 pandemic, Chef started working from home and his productivity decreased by a considerable amount. As per Chef's analysis, $1$ hour of work done at the office is equivalent to $P$ hours of work done at home. Now, in order to complete his work properly, Chef has to spend more hours working from home, possibly at the cost of other things like sleep. However, he does not have to do the same work on each day as he would have in the office ― for each weekday, he can start the work for this day on an earlier day and/or complete it on a later day. The only requirement is that his work does not pile up indefinitely, i.e. he can complete his work for each week during the same week. One day has $24$ hours. If Chef is unable to complete his work for a week during those five weekdays, then he has to work during the weekend too. Chef wishes to know whether he has to work on weekends or if he can complete his work by working only on weekdays. Help him answer that question. (It is possible that Chef would be unable to finish his work even if he worked all the time, but he does not want to know about that.) -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first and only line of each test case contains six space-separated integers $A_1$, $A_2$, $A_3$, $A_4$, $A_5$ and $P$. -----Output----- For each test case, print a single line containing the string "Yes" if Chef has to work on weekends or "No" otherwise (without quotes). -----Constraints----- - $1 \le T \le 1,000$ - $0 \le A_i \le 24$ for each valid $i$ - $1 \le P \le 24$ -----Subtasks----- Subtask #1 (100 points): original constraints -----Example Input----- 2 14 10 12 6 18 2 10 10 10 10 10 3 -----Example Output----- No Yes -----Explanation----- Example case 1: Here, $P=2$, so the number of hours Chef has to work from home to handle his workload for days $1$ through $5$ is $[28,20,24,12,36]$. If he works for full $24$ hours on each of the five weekdays, he finishes all the work, so he does not have to work on weekends. Example case 2: No matter what Chef does, he will have to work on weekends.
["# cook your dish here\nfor t in range(int(input())):\n a1,a2,a3,a4,a5,p=[int(x)for x in input().rstrip().split()]\n if (a1+a2+a3+a4+a5)*p >120:\n print(\"Yes\")\n else:\n print(\"No\")\n", "for i in range(int(input())):\n n=[int(x) for x in input().split()]\n t=n[-1]\n n=n[:-1]\n a=0\n for i in n:\n a+=i*t\n if a>120:\n print('Yes')\n else:\n print('No')", "t=int(input())\nfor i in range(t):\n p=[int(x) for x in input().split()]\n a=p[-1]\n p=p[:-1]\n n=0\n for i in p:\n n+=i*a\n if n>120:\n print('Yes')\n else:\n print('No')", "# cook your dish here\nt=int(input());\nfor i in range(t):\n a1,a2,a3,a4,a5,p=list(map(int,input().split()));\n c=(a1*p)+(a2*p)+(a3*p)+(a4*p)+(a5*p);\n if c<=120:\n print('No');\n else:\n print('Yes');\n \n", "# cook your dish here\nt = int(input())\nfor z in range(t) :\n a = [int(x) for x in input().split()]\n p = a[-1]\n a = a[:-1]\n s = 0\n for i in a:\n s+= i*p \n if s>120 :\n print(\"Yes\")\n else:\n print('No')", "for _ in range(int(input())):\n a=list(map(int,input().split()))\n p=a[-1]\n a=a[:-1]\n for i in range(len(a)):\n a[i]=a[i]*p\n b=sum(a)\n if(b>24*5):\n print(\"Yes\")\n else:\n print(\"No\")\n \n", "for _ in range(int(input())):\n a=list(map(int,input().split()))\n p=a[-1]\n b=[p*i for i in a[:-1]]\n if(sum(b)<=120):\n print(\"No\")\n else:\n print(\"Yes\")\n \n", "# cook your dish here\nfor _ in range(int(input())):\n a=[int(i) for i in input().split()]\n p=a[-1]\n b=[p*i for i in a[:-1]]\n if sum(b)<=120:\n print(\"No\")\n else:\n print(\"Yes\")", "# cook your dish here\nfor i in range(int(input())):\n a1,a2,a3,a4,a5,P=list(map(int, input().split()))\n sum=(a1+a2+a3+a4+a5)*P\n if sum>120:\n print(\"Yes\")\n else:\n print(\"No\")", "# cook your dish here\nfor i in range(int(input())):\n n=list(map(int,input().split()))\n p=sum(n)-n[-1]\n if p*n[-1]>(5*24):\n print(\"Yes\")\n else:\n print(\"No\")", "for o in range(int(input())):\n l=list(map(int,input().split()))\n s=sum(l)-l[-1]\n if(s*l[-1]<=120):\n print(\"No\")\n else:\n print(\"Yes\")", "T=int(input())\nfor i in range(T):\n L=list(map(int,input().split()))\n P=L[-1]\n L.remove(P)\n for j in range(len(L)):\n L[j]=L[j]*P\n S=sum(L)\n if S>120:\n print(\"Yes\")\n else:\n print(\"No\")", "T=int(input())\nfor i in range(T):\n L=list(map(int,input().split()))\n P=L[-1]\n L.remove(P)\n for j in range(len(L)):\n L[j]=L[j]*P\n S=sum(L)\n if S>120:\n print(\"Yes\")\n else:\n print(\"No\")\n", "for _ in range(int(input())):\n arr = list(map(int,input().split()))\n\n summ =sum(arr[ : -1])\n if arr[-1]*summ>120:\n print(\"Yes\")\n else:\n print(\"No\")\n\n # cook your dish here\n", "for i in range(int(input())):\n\n numberlist = list(map(int,input().split()))\n timelist = numberlist[:-1]\n p = numberlist[-1]\n for i in range(len(timelist)):\n timelist[i]*=p\n if sum(timelist)<=120 :\n print(\"No\")\n else :\n print(\"Yes\")\n\n\n", "# cook your dish here\nt=int(input())\nwhile(t>0):\n a=list(map(int,input().split()))\n total_hours=5*24\n p=a[(len(a))-1]\n sum=0\n a.remove(p)\n for i in a:\n sum=sum+(p*i)\n if sum>total_hours:\n print('Yes')\n elif sum<=total_hours:\n print('No')\n t-=1\n", "for _ in range(int(input())):\n A = list(map(int, input().split()))\n p = A[5]\n del A[5]\n if 24*5 < p*sum(A):\n print('Yes')\n else:\n print('No')", "# cook your dish here\nfor _ in range(int(input())):\n l=list(map(int,input().split()))\n l=(sum(l)-l[5])*l[5]\n if(l<=(24*5)):\n print('No')\n else:\n print('Yes')\n", "# cook your dish here\nt=int(input())\nfor i in range(t):\n c=[]\n l=list(map(int,input().split()))\n a=l[0:len(l)-1]\n d=l[-1]\n for i in a:\n c.append(i*d)\n s=sum(c)\n if s<=120:\n print('No')\n else:\n print('Yes')", "for _ in range(int(input())):\n\n lista=list(map(int,input().split()))\n new_list=[]\n \n for i in range(len(lista)-1):\n \n new_list.append(lista[i]*lista[-1])\n \n if(sum(new_list)<=120):\n \n print('No')\n \n else:\n \n print('Yes')\n", "# cook your dish here\nfor _ in range(int(input())):\n a=list(map(int,input().split()))\n p=a[len(a)-1]\n b=sum(a)-p\n if(b*p-120>0):\n print(\"Yes\")\n else:\n print(\"No\")", "for __ in range(int(input())):\n val = list(map(int, input().split()))\n s = 0\n for i in range(0, len(val) - 1):\n s += val[i] * val[-1]\n if s <= 24 * 5:\n print('No')\n else:\n print('Yes')", "for i in range(int(input())):\n x=list(map(int,input().split())) \n e=x[-1] \n del x[-1]\n res=[p*e for p in x]\n if sum(res)<=120:\n print('No') \n else:\n print('Yes')\n", "# cook your dish here\nT=int(input())\nfor i in range(T):\n A1,A2,A3,A4,A5,P=list(map(int, input().split()))\n sum=(A1+A2+A3+A4+A5)*P\n if sum>120:\n print(\"Yes\")\n else:\n print(\"No\")\n"]
{"inputs": [["2", "14 10 12 6 18 2", "10 10 10 10 10 3"]], "outputs": [["No", "Yes"]]}
INTERVIEW
PYTHON3
CODECHEF
4,744
df836610bb55bc0374b6d6eb3f0903cc
UNKNOWN
Chef has a garden with $N$ plants arranged in a line in decreasing order of height. Initially the height of the plants are $A_1, A_2, ..., A_N$. The plants are growing, after each hour the height of the $i$-th plant increases by $i$ millimeters. Find the minimum number of integer hours that Chef must wait to have two plants of the same height. -----Input:----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains a single integer $N$. - The second line contains $N$ space separated integers $A_1,A_2,..A_N$. -----Output:----- For each test case print a single line containing one integer, the minimum number of integer hours that Chef must wait to have two plants of the same height. -----Constraints----- - $1 \leq T \leq 1000$ - $2 \leq N \leq 10^5$ - $0\leq A_i \leq 10^{18}$ - $A_i >A_{i+1}$, for each valid $i$ - The Sum of $N$ over all test cases does not exceed $10^6$ -----Sample Input:----- 1 3 8 4 2 -----Sample Output:----- 2 -----EXPLANATION:----- After $2$ hours there are two plants with the same height. $[8,4,2] \rightarrow [9,6,5] \rightarrow [10,8,8]$.
["\nfor _ in range(int(input())):\n n = int(input())\n arr = list(map(int, input().split()))\n hrs = arr[0] - arr[1]\n\n for i in range(1, n-1):\n if hrs > arr[i] - arr[i+1]:\n hrs = arr[i] - arr[i+1]\n\n print(hrs)", "# cook your dish here\nfor _ in range(int(input())):\n n = int(input())\n a = list(map(int,input().split()))\n ans = a[0]-a[1]\n for i in range(1,n-1):\n m = a[i]-a[i+1]\n if ans > m : ans = m\n print(ans)\n", "# cook your dish here\nfor _ in range(int(input())):\n n,a,b = int(input()),list(map(int,input().split())),[]\n for i in range(n-1): b.append(a[i]-a[i+1])\n print(min(b)) ", "#872//2\nfor _ in range(int(input())):\n n,a,b = int(input()),list(map(int,input().split())),[]\n for i in range(n-1): b.append(a[i]-a[i+1])\n print(min(b)) ", "for _ in range(int(input())):\n n,a,b = int(input()),list(map(int,input().split())),[]\n for i in range(n-1): b.append(a[i]-a[i+1])\n print(min(b)) ", "for _ in range(int(input())):\n n = int(input())\n a = list(map(int,input().split()))\n ans = a[0]-a[1]\n for i in range(1,n-1):\n m = a[i]-a[i+1]\n if ans > m : ans = m\n print(ans)\n", "t = int(input())\n\nfor _ in range(t):\n n = int(input())\n A = list(map(int,input().split()))\n min = A[0] - A[1]\n for i in range(1,n-1):\n t = A[i] - A[i+1]\n if(t<min):\n min = t\n print(min)", "t = int(input())\nfor i in range(0,t):\n n = int(input())\n A = [int(x) for x in input().split()]\n if(n>2):\n for i in range(0,n-2):\n if(i==0): result = min(A[i]-A[i+1],A[i+1]-A[i+2])\n else: result = min(result,A[i+1]-A[i+2])\n else: result = A[0]-A[1]\n print(result) ", "# cook your dish here\nfor _ in range(int(input())):\n n=int(input())\n l=list(map(int,input().split()))\n k=[]\n for i in range(len(l)-1):\n j=l[i]-l[i+1]\n k.append(j)\n print(min(k))", "for _ in range(int(input())):\n n=int(input())\n l=list(map(int,input().split()))\n k=[]\n for i in range(len(l)-1):\n j=l[i]-l[i+1]\n k.append(j)\n print(min(k))", "# cook your dish here\ntry:\n for _ in range(int(input())):\n n = int(input())\n l1 = list(map(int, input().split()))\n ans = [l1[i - 1] - l1[i] for i in range(1, len(l1))]\n print(min(ans))\nexcept:\n pass", "# cook your dish here\nfor _ in range(int(input())):\n n = int(input())\n l1 = list(map(int, input().split()))\n ans = [l1[i - 1] - l1[i] for i in range(1, len(l1))]\n print(min(ans))", "def gcd(a,b):\n if a==0:\n return b\n return(gcd(b%a,a))\ndef lcm(a,b):\n return((a*b)/gcd(a,b))\nT=int(input())\nfor _ in range(0,T):\n N=int(input())\n l=[]\n A=list(map(int,input().split()))\n for i in range(0,len(A)-1):\n l.append(A[i]-A[i+1])\n print(min(l))\n", "for k in range(int(input())):\n n=int(input())\n li=list(map(int,input().split()))\n b=[]\n for g in range(len(li)-1):\n b.append(li[g]-li[g+1])\n print(min(b))", "# cook your dish here\nfor _ in range(int(input())):\n size = int(input())\n a = [int(x) for x in input().split(\" \")]\n b = []\n for i in range(len(a)-1):\n b.append(a[i]-a[i+1])\n print(min(b))\n", "# cook your dish here\nfor i in range(int(input())):\n n=int(input())\n arr=list(map(int,input().split()))\n ans=arr[0]\n i=0\n while(i<n-1):\n ans=min(ans,arr[i]-arr[i+1])\n i+=1 \n print(ans)\n", "# cook your dish here\nfor _ in range(int(input())):\n size = int(input())\n a = [int(x) for x in input().split(\" \")]\n b = []\n for i in range(len(a)-1):\n b.append(a[i]-a[i+1])\n print(min(b))", "for _ in range(int(input())):\n n=int(input())\n a=[*list(map(int,input().split()))]\n ans=100000000000000000000\n for i in range(0,len(a)-1):\n mn=a[i]-a[i+1]\n if mn<ans:\n ans=mn\n print(ans)\n", "for _ in range(int(input())):\n lens = int(input())\n arrs = [int(x) for x in input().split()]\n ans = min([ abs(y - x) for x, y in zip(arrs, arrs[1:])])\n print(ans)", "for _ in range(int(input())):\n size = int(input())\n a = [int(x) for x in input().split(\" \")]\n b = []\n for i in range(len(a)-1):\n b.append(a[i]-a[i+1])\n print(min(b))", "\n\na = int(input())\nwhile a!=0:\n b = int(input())\n mylist = list(map(int,input().split()))\n min = mylist[0]-mylist[1]\n for i in range(len(mylist)-1):\n p = mylist[i]-mylist[i+1]\n if p <min:\n min =p\n\n\n print(min)\n\n\n\n\n a-=1", "for _ in range(int(input())):\n n=int(input())\n l=list(map(int,input().split()))\n k=[]\n for i in range(len(l)-1):\n j=l[i]-l[i+1]\n k.append(j)\n print(min(k))"]
{"inputs": [["1", "3", "8 4 2"]], "outputs": [["2"]]}
INTERVIEW
PYTHON3
CODECHEF
4,361
f238f104950d8a1b614939790f1ac318
UNKNOWN
The snakes want to build a temple for Lord Cobra. There are multiple strips of land that they are looking at, but not all of them are suitable. They need the strip of land to resemble a coiled Cobra. You need to find out which strips do so. Formally, every strip of land, has a length. Suppose the length of the i-th strip is is Ni, then there will be Ni integers, Hi1, Hi2, .. HiNi, which represent the heights of the ground at various parts of the strip, in sequential order. That is, the strip has been divided into Ni parts and the height of each part is given. This strip is valid, if and only if all these conditions are satisfied: - There should be an unique 'centre' part. This is where the actual temple will be built. By centre, we mean that there should be an equal number of parts to the left of this part, and to the right of this part. - Hi1 = 1 - The heights keep increasing by exactly 1, as you move from the leftmost part, to the centre part. - The heights should keep decreasing by exactly 1, as you move from the centre part to the rightmost part. Note that this means that HiNi should also be 1. Your job is to look at every strip and find if it's valid or not. -----Input----- - The first line contains a single integer, S, which is the number of strips you need to look at. The description of each of the S strips follows - The first line of the i-th strip's description will contain a single integer: Ni, which is the length and number of parts into which it has been divided. - The next line contains Ni integers: Hi1, Hi2, .., HiNi. These represent the heights of the various parts in the i-th strip. -----Output----- - For each strip, in a new line, output "yes" if is a valid strip, and "no", if it isn't. -----Constraints----- - 1 ≤ S ≤ 100 - 3 ≤ Ni ≤ 100 - 1 ≤ Hij ≤ 100 -----Example----- Input: 7 5 1 2 3 2 1 7 2 3 4 5 4 3 2 5 1 2 3 4 3 5 1 3 5 3 1 7 1 2 3 4 3 2 1 4 1 2 3 2 4 1 2 2 1 Output: yes no no no yes no no -----Explanation----- In the first strip, all the conditions are satisfied, hence it is valid. In the second strip, it does not start with a 1, and hence is invalid. In the third strip, it keeps increasing even past the centre, instead of decreasing. Hence invalid. The fourth strip does not increase and decrease by exactly 1. Hence invalid. The fifth satisfies all conditions and hence is valid. The sixth and seventh strip do not have a 'centre' part. Because for every part, there are either more parts to its right than its left, or more parts on its left than its right. Hence both the strips are invalid.
["# cook your dish here\nfor i in range(int(input())):\n N=int(input())\n L=list(map(int,input().split()))\n l,h=0,N-1 \n flag=1\n if L[l]!=1 and L[h]!=1:\n flag=0\n else:\n while(l<h):\n if (L[l]!=L[h]) or (L[l+1]-L[l]!=1 and L[h-1]-L[h]!=1):\n flag=0\n break\n l+=1 \n h-=1\n if flag:\n print(\"yes\")\n else:\n print(\"no\")", "# cook your dish here\nfor i in range(int(input())):\n N=int(input())\n L=list(map(int,input().split()))\n l,h=0,N-1 \n flag=1\n if L[l]!=1 and L[h]!=1:\n flag=0\n else:\n while(l<h):\n if (L[l]!=L[h]) or (L[l+1]-L[l]!=1 and L[h-1]-L[h]!=1):\n flag=0\n break\n l+=1 \n h-=1\n if flag:\n print(\"yes\")\n else:\n print(\"no\")", "# cook your dish here\ntry:\n for i in range(int(input())):\n n=int(input())\n l=list(map(int,input().strip().split()))\n if(len(l)%2==0):\n print(\"no\")\n else:\n if(l[0]!=1):\n print(\"no\")\n else:\n for i in range(n//2):\n if(l[i]!=l[n-i-1]):\n print(\"no\")\n break\n elif(l[i]-l[i+1]!=-1):\n print(\"no\")\n break\n else:\n print(\"yes\")\n \nexcept:\n pass\n", "try:\n for z in range(int(input())):\n n = int(input())\n H = [int(e) for e in input().split()]\n if n%2 == 0:\n print(\"no\")\n \n \n \n else:\n if H[0] != 1:\n print(\"no\")\n else:\n \n \n f = 0\n for i in range(n//2):\n if H[i] != H[n-i-1]:\n f = 1\n break\n if f == 0:\n for i in range(n//2):\n if H[i] - H[i+1] != -1:\n f = 1\n break\n if f == 1:\n print(\"no\")\n else:\n print(\"yes\")\nexcept:\n pass", "# cook your dish here\nfor i in range(int(input())):\n n=int(input())\n l=list(map(int,input().split()))\n if n%2==0:\n print(\"no\")\n elif l[0]!=1 or l[-1]!=1:\n print(\"no\")\n else:\n l1=list(range(1,(n//2)+2))\n l2=list(range(n//2,0,-1))\n if l[0:(n//2)+1]==l1 and l[n//2+1:]==l2:\n print(\"yes\")\n else:\n print(\"no\")", "def check_strip(num, strip):\n if(num%2==0):\n return False\n elif(strip[0]!=1):\n return False\n elif(sum(strip)!=(((num//2)+1)**2)):\n return False\n else: \n return True\n\ntry:\n for i in range(int(input())):\n num = int(input())\n strip = list(map(int, input().split()))\n if(check_strip(num, strip)):\n print('yes')\n else:\n print('no')\nexcept Exception as e:\n print(e)", "for _ in range(int(input())):\n n=int(input())\n x=list(map(int,input().split()))\n if(n%2==0):\n print('no')\n else:\n t=1\n flag=0\n for i in range(0,n//2+1):\n if(x[i]==x[n-i-1]==t):\n t=t+1\n else:\n flag=1\n break\n if(flag==0):\n print('yes')\n else:\n print('no')", "for _ in range(int(input())):\n n=int(input())\n x=list(map(int,input().split()))\n if(n%2==0):\n print('no')\n else:\n t=1\n flag=0\n for i in range(0,n//2+1):\n if(x[i]==x[n-i-1]==t):\n t=t+1\n else:\n flag=1\n break\n if(flag==0):\n print('yes')\n else:\n print('no')", "t = int(input())\nfor i in range(t):\n n = int(input())\n a = list(map(int, input().split()))\n valid= False\n if n%2==1 and a[0]==1:\n for j in range(int((n-1)/2)):\n if a[j]==a[n-1-j]:\n valid=True\n if a[j] +1 != a[j+1]:\n valid=False\n if a[n-1-j] != a[n-2-j] - 1:\n valid = False\n if(valid):\n print('yes')\n else:\n print('no')", "# cook your dish here\nfor _ in range(int(input())):\n n=int(input())\n x=list(map(int,input().split()))\n if(n%2==0):\n print('no')\n else:\n t=1\n pulkit=0\n for i in range(0,n//2+1):\n if(x[i]==x[n-i-1]==t):\n t=t+1\n else:\n pulkit=1\n break\n if(pulkit==0):\n print('yes')\n else:\n print('no')", "# cook your dish here\nt = int(input())\nfor z in range(t) :\n n = int(input())\n a = [int(x) for x in input().split()]\n if n%2==1 and a[0]==1 :\n x = list(reversed(a))\n for i in range((len(a)-1)//2) :\n if a[i] + 1 == x[i+1] :\n c = 0\n else:\n c = 1 \n break\n if c==1 :\n print(\"no\")\n else:\n print(\"yes\")\n else:\n print(\"no\")", "for _ in range(int(input())):\n n=int(input())\n x=list(map(int,input().split()))\n if(n%2==0):\n print('no')\n else:\n t=1\n flag=0\n for i in range(0,n//2+1):\n if(x[i]==x[n-i-1]==t):\n t=t+1\n else:\n flag=1\n break\n if(flag==0):\n print('yes')\n else:\n print('no')", "for _ in range(int(input())):\n n= int(input())\n a= list(map(int, input().split()))\n if(n % 2)==1 and a[0] == 1:\n arr1 = list(reversed(a))\n for i in range(((len(a) - 1)//2)):\n if a[i]+1 == arr1[i+1]:\n f= 0\n else:\n f = 1\n print('no')\n break\n if f==0:\n print('yes')\n else:\n print('no')", "# cook your dish here\nfor _ in range(int(input())):\n n= int(input())\n a= list(map(int, input().split()))\n if(n % 2)==1 and a[0] == 1:\n arr1 = list(reversed(a))\n for i in range(((len(a) - 1)//2)):\n if a[i]+1 == arr1[i+1]:\n f= 0\n else:\n f = 1\n print('no')\n break\n if f==0:\n print('yes')\n else:\n print('no')", "test_cases = int(input())\n\ndef canMakeTemple(strips, strips_height):\n check = \"yes\"\n if (strips % 2 != 0) and (strips_height[strips//2] == (strips // 2) +1):\n left, right = 0, strips - 1\n for i in range(strips // 2):\n if strips_height[i] != strips_height[strips - i - 1]:\n check = \"no\"\n break \n else:\n check = \"no\"\n return check\n\n\nfor i in range(test_cases):\n strips = int(input())\n strips_height = list(map(int, input().split()))\n\n print(canMakeTemple(strips, strips_height))\n", "# cook your dish here\nfor _ in range(int(input())):\n num = int(input())\n arr = list(map(int, input().split()))\n if(num % 2)==1 and arr[0] == 1:\n arr1 = list(reversed(arr))\n for i in range(((len(arr) - 1)//2)):\n if arr[i]+1 == arr1[i+1]:\n flag = 0\n else:\n flag = 1\n print('no')\n break\n if flag == 0:\n print('yes')\n else:\n print('no')", "for i in range(int(input())):\n n=int(input())\n m=list(map(int,input().split()))\n if m[0]==1 and m[-1]==1 and n%2!=0 and m[n//2]==max(m):\n for i in range(n//2):\n if abs(m[i+1]-m[i])!=1:\n print(\"no\")\n break\n else:\n print(\"yes\")\n else:\n print(\"no\")\n \n", "# cook your dish here\nfor _ in range(int(input())):\n n = int(input())\n l = list(map(int,input().split()))\n f = True\n for i in range((n+1)//2):\n if l[i] != i+1:\n f = False\n if l[n-i-1] != i+1:\n f = False\n if n%2 == 0:\n f = False\n if f == True:\n print(\"yes\")\n else:\n print(\"no\")\n", "num=[x for x in range(1,101)]\n#print(num)\nfor _ in range(int(input())):\n n=int(input())\n l=list(map(int,input().split()))\n if n%2!=0:\n c=n//2\n if l[0]==1 and l[-1]==1:\n d=0\n for i in range(1,c+1):\n if l[i]-l[i-1]==1:\n d=d+1\n for i in range(c,n-1):\n if l[i]-l[i+1]==1:\n d=d+1\n if d==n-1:\n print(\"yes\")\n else:\n print(\"no\")\n else:\n print(\"no\")\n else:\n print(\"no\")", "# cook your dish here\nfor _ in range(int(input())):\n n=int(input())\n l=list(map(int,input().split()))\n if l[0]==1 and l[-1]==1 and n%2!=0 and l[n//2]==max(l):\n for i in range(n//2):\n if abs(l[i+1]-l[i])!=1:\n print(\"no\")\n break\n else:\n print(\"yes\")\n else:\n print(\"no\")\n \n \n \n \n \n", "# cook your dish here\ns=int(input());\nfor i in range(s):\n n=int(input());\n h=list(map(int,input().split()));\n d=0;\n if n%2!=0:\n c=n//2;\n if h[0]==1:\n for i in range(1,c+1):\n if h[i]-h[i-1]==1:\n d=d+1;\n for i in range(c,len(h)-1):\n if h[i]-h[i+1]==1:\n d=d+1;\n #print(d);\n if d==n-1:\n print('yes');\n else:\n print('no');\n else:\n print('no');\n else:\n print('no');\n \n \n", "T=int(input())\nfor i in range(T):\n N=int(input())\n H=list(map(int,input().split()))[:N]\n if N%2!=0 and H[0]==1 and H[N//2]==max(H) and H[-1]==1:\n for j in range(len(H)-1):\n if abs(H[j+1]-H[j])!=1:\n print(\"no\")\n break\n else:\n print(\"yes\")\n else:\n print(\"no\")\n \n", "# cook your dish here\ns=int(input());\nfor i in range(s):\n n=int(input());\n h=list(map(int,input().split()));\n d=0;\n if n%2!=0:\n c=n//2;\n if h[0]==1:\n for i in range(1,c+1):\n if h[i]-h[i-1]==1:\n d=d+1;\n for i in range(c,len(h)-1):\n if h[i]-h[i+1]==1:\n d=d+1;\n #print(d);\n if d==n-1:\n print('yes');\n else:\n print('no');\n else:\n print('no');\n else:\n print('no');\n \n \n \n \n \n \n \n", "T=int(input())\nfor i in range(T):\n N=int(input())\n H=list(map(int,input().split()))[:N]\n if N%2!=0 and H[0]==1 and H[N//2]==max(H) and H[-1]==1:\n for j in range(len(H)-1):\n if abs(H[j+1]-H[j])!=1:\n print(\"no\")\n break\n else:\n print(\"yes\")\n else:\n print(\"no\")\n"]
{"inputs": [["7", "5", "1 2 3 2 1", "7", "2 3 4 5 4 3 2", "5", "1 2 3 4 3", "5", "1 3 5 3 1", "7", "1 2 3 4 3 2 1", "4", "1 2 3 2", "4", "1 2 2 1"]], "outputs": [["yes", "no", "no", "no", "yes", "no", "no"]]}
INTERVIEW
PYTHON3
CODECHEF
8,680
9f3aab2732dc646276baed9768718703
UNKNOWN
Vanja and Miksi have already finished everything for this year at their university, so they decided to spend their free time playing a game with a binary sequence $A_1, A_2, \dots, A_N$ (i.e. a sequence containing only integers $0$ and $1$). At the beginning of the game, Vanja and Miksi write down the expression $* A_1 * A_2 * A_3 * \ldots * A_N$ (note below that each $*$ is a placeholder and does not denote multiplication). The players take turns alternately, starting with Vanja. The game lasts $N$ turns. In each turn, the current player must replace the first (leftmost) remaining $*$ by the sign $+$ or $-$ (or, equivalently, by the operation of addition or subtraction). After the last turn, the boys calculate the resulting value $V$ of the expression. If $|V| \ge K$, the winner is Vanja; otherwise, the winner is Miksi. Please predict the winner of the game if both players play optimally. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains two space-separated integers $N$ and $K$. - The second line contains $N$ space-separated integers $A_1, A_2, \dots, A_N$. -----Output----- For each test case, print a single line containing one integer — $1$ if Vanja (the first player) is the winner or $2$ if Miksi (the second player) is the winner. -----Constraints----- - $1 \le T \le 50$ - $1 \le N \le 3 \cdot 10^4$ - $0 \le K \le 3 \cdot 10^4$ - $0 \le A_i \le 1$ for each valid $i$ -----Example Input----- 2 2 1 1 0 3 5 0 1 0 -----Example Output----- 1 2 -----Explanation----- Example case 1: $K = 1$, so if Vanja replaces the first $*$ by $+$, the value of the final expression will be $V = 1$; then, $K \le |V|$, so the winner is Vanja. Example case 2: $K = 5$, but the absolute value of the final expression cannot be greater than $1$. The winner is Miksi.
["# cook your dish here\nfor _ in range(int(input())):\n n,k=list(map(int,input().split()))\n a=list(map(int,input().split()))\n m=0\n for i in range(n):\n if i%2==0:\n if m<0:\n m-=a[i]\n else:\n m+=a[i]\n else:\n if m<0:\n m+=a[i]\n else:\n m-=a[i]\n if abs(m)>=k:\n print(1)\n else:\n print(2)\n \n", "# cook your dish here\nfor _ in range(int(input())):\n n,k=list(map(int, input().split()))\n l=list(map(int, input().split()))\n \n v=0\n for i in range(n):\n if i%2==0:\n if v<0:\n v-=l[i]\n \n else:\n v+=l[i]\n \n else:\n if v<0:\n v+=l[i]\n \n else:\n v-=l[i]\n \n if abs(v)>=k:\n print('1')\n \n else:\n print('2')", "# cook your dish here\nfor _ in range(int(input())):\n n,k=list(map(int,input().split()))\n l=list(map(int,input().split()))\n s=0\n for i in range(n):\n if i%2==0:\n if s>0:\n s+=l[i]\n else:\n s-=l[i]\n else:\n if s>0:\n s-=l[i]\n else:\n s+=l[i]\n if abs(s)>=k:\n print('1')\n else:\n print('2')\n \n", "# cook your dish here\nfor u in range(int(input())):\n n,k=list(map(int,input().split()))\n l=list(map(int,input().split()))\n s=0\n for i in range(n):\n if(i%2==0):\n if(s>=0):\n s+=l[i]\n else:\n s-=l[i]\n else:\n if(s>=0):\n s-=l[i]\n else:\n s+=l[i]\n if(abs(s)>=k):\n print(1)\n else:\n print(2)\n", "testCases=int(input())\nfor Case in range(testCases):\n n,k=list(map(int,input().split()))\n l=list(map(int,input().split()))\n sum=0\n for i in range(n):\n if i%2==0:\n if sum>0:\n if l[i]>0:\n sum+=l[i]\n else:\n sum-=l[i]\n else:\n if l[i]>0:\n sum-=l[i]\n else:\n sum+=l[i]\n else:\n if sum>0:\n if l[i]>0:\n sum-=l[i]\n else:\n sum+=l[i]\n else:\n if l[i]>0:\n sum+=l[i]\n else:\n sum-=l[i]\n #print('sum',sum)\n if sum<0:\n s=(-1)*sum\n else:\n s=sum\n if k<=s:\n print(1)\n else:\n print(2)\n", "for _ in range(int(input())):\n n,k=list(map(int,input().split()))\n l=list(map(int,input().split()))\n x=0\n for i in range(len(l)):\n if i%2==0:\n if x>=0:\n x+=l[i]\n else:\n x-=l[i]\n else:\n if x>=0:\n x-=l[i]\n else:\n x+=l[i]\n if abs(x)>=k:\n print(1)\n else:\n print(2)\n", "t=int(input())\nfor j in range(t):\n n,k=list(map(int,input().split()))\n s=list(map(int,input().split()))\n sum=0\n for i in range(0,n-1,2):\n if sum>=0:\n sum+=s[i]\n else:\n sum-=s[i]\n if sum>=0:\n sum-=s[i+1]\n else:\n sum+=s[i+1]\n if n%2!=0:\n if sum<=0:\n sum-=s[n-1]\n else:\n sum+=s[n-1]\n if k<=abs(sum):\n print(1)\n else:\n print(2)\n", "t=int(input())\nwhile(t>0):\n n,k=map(int,input().split())\n l=list(map(int,input().split()))\n s=0\n for i in range(0,n,2):\n if(s>=0):\n s+=l[i]\n else:\n s-=l[i]\n if(i!=n-1):\n if(s<0):\n s+=l[i+1]\n else:\n s-=l[i+1]\n if(abs(s)>=k):\n print(1)\n else:\n print(2)\n t-=1", "for i in range(int(input())):\n n,k=map(int,input().split())\n a=list(map(int,input().split()))\n v=0\n for j,i in enumerate(a):\n if j%2==0:\n if v<0:\n v-=i\n else:\n v+=i\n else:\n if v>=0:\n v-=i\n else:\n v+=i\n if abs(v)>=k:\n print(1)\n else:\n print(2)", "for i in range(int(input())):\n n,k=map(int,input().split())\n a=list(map(int,input().split()))\n v=0\n for j,i in enumerate(a):\n if j%2==0:\n if v<0:\n v-=i\n else:\n v+=i\n else:\n if v>=0:\n v-=i\n else:\n v+=i\n if abs(v)>=k:\n print(1)\n else:\n print(2)", "# cook your dish here\ntest=int(input())\nfor _ in range(test):\n n,k=map(int,input().split())\n x=list(map(int,input().split()))\n c=0\n for i in range(n):\n if(i%2==0):\n if(c<0):\n c-=x[i]\n else:\n c+=x[i]\n else:\n if(c<0):\n c+=x[i]\n else:\n c-=x[i]\n if(abs(c)>=k):\n print(1)\n else:\n print(2)", "for j in range(int(input())):\n n,k=map(int,input().split())\n x=list(map(int,input().split()))\n c=0\n for i in range(n):\n if(i%2==0):\n if(c<0):\n c-=x[i]\n else:\n c+=x[i]\n else:\n if(c<0):\n c+=x[i]\n else:\n c-=x[i]\n if(abs(c)>=k):\n print(1)\n else:\n print(2)", "for j in range(int(input())):\n n,k=map(int,input().split())\n x=list(map(int,input().split()))\n c=0\n for i in range(n):\n if(i%2==0):\n if(c<0):\n c-=x[i]\n else:\n c+=x[i]\n else:\n if(c<0):\n c+=x[i]\n else:\n c-=x[i]\n if(abs(c)>=k):\n print(1)\n else:\n print(2)", "for _ in range(int(input())):\n N,K=map(int,input().split())\n seq=[int(i) for i in input().split()]\n value=0\n turn=0\n for i in range(N):\n if(seq[i]==0):\n value+=seq[i]\n turn=int(not(turn))\n else:\n if(turn==0): #vanja's turn\n if(K - abs(value + 1) <= K - abs(value-1)):\n value+=1\n turn=1\n else:\n value-=1\n turn=1\n else: #miksi's turn\n if(K - abs(value + 1) <= K - abs(value-1)):\n value-=1\n turn=0\n else:\n value+=1\n turn=0\n if(abs(value) >= K):\n print(1)\n else:\n print(2)", "import math\nT = int(input())\nfor j in range(T):\n N, K = [int(j) for j in input().split()]\n s = list(map(int,input().split()))\n sum = s[0]\n for i in range(N - 1):\n if i % 2 == 0:\n if sum >= 0:\n sum -= s[i + 1]\n else:\n sum += s[i + 1]\n else:\n if sum >= 0:\n sum += s[i + 1]\n else:\n sum -= s[i + 1]\n if math.fabs(sum) >= K:\n print(\"1\")\n else:\n print(\"2\")\n", "# cook your dish here\nimport math\nfor _ in range(int(input())):\n n,k=[int(j) for j in input().split()]\n l=list(map(int,input().split()))\n sum=l[0]\n for i in range(n-1):\n if i%2==0:\n if sum>=0:\n sum-=l[i+1]\n else:\n sum+=l[i+1]\n else:\n if sum>=0:\n sum+=l[i+1]\n else:\n sum-=l[i+1]\n if math.fabs(sum)>=k:\n print(\"1\")\n else:\n print(\"2\")\n", "# cook your dish here\ndef mixi_game(n,k,arr):\n val=0\n for i in range(n):\n if i%2==0:\n if val<0:\n val-=arr[i]\n else:\n val+=arr[i]\n \n else:\n if val<0:\n val+=arr[i]\n else:\n val-=arr[i]\n \n if k<=abs(val):\n return 1\n \n else:\n return 2\n\n\nt=int(input())\nfor i in range(t):\n n,k=[int(x) for x in input().split()]\n arr=[int(x) for x in input().split()]\n print(mixi_game(n,k,arr))\n", "# cook your dish here\ndef mixi_game(n,k,arr):\n val=0\n for i in range(n):\n if i%2==0:\n if val<0:\n val-=arr[i]\n else:\n val+=arr[i]\n \n else:\n if val<0:\n val+=arr[i]\n else:\n val-=arr[i]\n \n if k<=abs(val):\n return 1\n \n else:\n return 2\n\n\nt=int(input())\nfor i in range(t):\n n,k=[int(x) for x in input().split()]\n arr=[int(x) for x in input().split()]\n print(mixi_game(n,k,arr))", "# cook your dish here\ndef mixi_game(n,k,arr):\n val=0\n for i in range(n):\n if i%2==0:\n if val<0:\n val-=arr[i]\n else:\n val+=arr[i]\n \n else:\n if val<0:\n val+=arr[i]\n else:\n val-=arr[i]\n \n if k<=abs(val):\n return 1\n \n else:\n return 2\n\n\nt=int(input())\nfor i in range(t):\n n,k=[int(x) for x in input().split()]\n arr=[int(x) for x in input().split()]\n print(mixi_game(n,k,arr))", "for _ in range(int(input())):\n N, K = map(int, input().split())\n array = list(map(int, input().split()))\n value = 0\n for i in range(N):\n if i % 2 == 0 and array[i] == 1:\n if value > 0:\n value += 1\n else:\n value -= 1\n elif i % 2 != 0 and array[i] == 1:\n if value > 0:\n value-=1\n else:\n value += 1\n if abs(value) >= K:\n print(1)\n else:\n print(2)", "# cook your dish here\nfor i in range(int(input())):\n n,k=map(int,input().split())\n l=input().split()\n s=0\n for j in range(len(l)):\n if j%2==0 and l[j]=='1':\n if s>=0:\n s+=1\n else:\n s-=1\n elif l[j]=='1':\n if s>=0:\n s-=1\n else:\n s+=1\n if abs(s)>=k:\n print(1)\n else:\n print(2)", "for _ in range(int(input().strip())):\n n,k=list(map(int,input().strip().split()))\n total=0\n player=0\n for i in map(int,input().strip().split()):\n if player == 0:\n if total<0:\n total-=i\n else:\n total+=i\n player = 1\n else:\n if total<0:\n total+=i\n else:\n total-=i\n player=0\n \n if abs(total)>=k:\n print(1)\n else:\n print(2)\n", "# cook your dish here\nt = int(input())\n\nfor _ in range(t):\n n, k = list(map(int, input().split()))\n a = list(map(int, input().split()))\n sum = 0\n for i in range(n):\n if i % 2 == 0:\n if sum > 0:\n sum += a[i]\n else:\n sum -= a[i]\n else:\n if sum > 0:\n sum -= a[i]\n else:\n sum += a[i]\n if abs(sum) >= k:\n print(1)\n else:\n print(2)"]
{"inputs": [["2", "2 1", "1 0", "3 5", "0 1 0"]], "outputs": [["1", "2"]]}
INTERVIEW
PYTHON3
CODECHEF
8,503
7bec9922fb931374e3c733acabbcea36
UNKNOWN
The chef likes to play with numbers. He takes some integer number x, writes it down on his iPad, and then performs with it n−1 operations of the two kinds: - divide the number x by 3 (x must be divisible by 3); - multiply the number x by 2. After each iteration, Chef writes down the result on his iPad and replaces x with the result. So there will be n numbers on the iPad after all. You are given a sequence of length n — the numbers that Chef wrote down. This sequence is given in the order of the sequence can mismatch the order of the numbers written on the iPad. Your problem is to rearrange elements of this sequence in such a way that it can match a possible Chef's game in the order of the numbers written on the board. I.e. each next number will be exactly two times the previous number or exactly one-third of the previous number. I can give a guarantee that the answer exists. -----Input:----- - The first line of the input contains an integer number N i.e the number of the elements in the sequence. - The second line of the input contains n integer numbers a1,a2,…, an i.e rearranged (reordered) sequence that Chef can write down on the iPad. -----Output:----- Print N integer numbers — rearranged (reordered) input sequence that can be the sequence that Chef could write down on the iPad. It is guaranteed that the answer exists -----Constraints----- - $2 \leq N \leq 100$ - $1 \leq A[i] \leq 3* 10^{18} $ -----Sample Input:----- 6 4 8 6 3 12 9 -----Sample Output:----- 9 3 6 12 4 8 -----EXPLANATION:----- In the first example, the given sequence can be rearranged in the following way: [9,3,6,12,4,8]. It can match possible Polycarp's game which started with x=9.
["class Node:\r\n def __init__(self,x):\r\n self.x=x\r\n self.next=None\r\n self.prev=None\r\n self.flag=True\r\n\r\nfor t in range(1):\r\n n=int(input())\r\n arr=list(map(int,input().split()))\r\n for i in range(n):\r\n arr[i]=Node(arr[i])\r\n for i in arr:\r\n d=[i.x%3==0,i.x,i.x//3,i.x*2]\r\n if d[0]:\r\n for j in arr:\r\n if j.x==d[2]:\r\n i.next=j\r\n j.prev=i\r\n break\r\n else:\r\n for j in arr:\r\n if j.x == d[3]:\r\n i.next = j\r\n j.prev = i\r\n break\r\n else:\r\n for j in arr:\r\n if j.x==d[3]:\r\n i.next=j\r\n j.prev=i\r\n break\r\n f,l=None,None\r\n for i in arr:\r\n if i.prev==None:\r\n f=i\r\n elif i.next==None:\r\n l=i\r\n while f!=l and l!=None:\r\n print(f.x,end=\" \")\r\n f=f.next\r\n print(f.x)", "class Node:\r\n def __init__(self,x):\r\n self.x=x\r\n self.next=None\r\n self.prev=None\r\n self.flag=True\r\n\r\nfor t in range(1):\r\n n=int(input())\r\n arr=list(map(int,input().split()))\r\n for i in range(n):\r\n arr[i]=Node(arr[i])\r\n for i in arr:\r\n d=[i.x%3==0,i.x,i.x//3,i.x*2]\r\n if d[0]:\r\n for j in arr:\r\n if j.x==d[2]:\r\n i.next=j\r\n j.prev=i\r\n break\r\n else:\r\n for j in arr:\r\n if j.x == d[3]:\r\n i.next = j\r\n j.prev = i\r\n break\r\n else:\r\n for j in arr:\r\n if j.x==d[3]:\r\n i.next=j\r\n j.prev=i\r\n break\r\n for i in arr:\r\n if i.prev==None:\r\n f=i\r\n elif i.next==None:\r\n l=i\r\n while f!=l:\r\n print(f.x,end=\" \")\r\n f=f.next\r\n print(f.x)", "# cook your dish here\n n = int(input())\n \n l = list(map(int, input().split()))\n \n def conv(n):\n \ti = 0\n \twhile n % 2 == 0:\n \t\ti += 1\n \t\tn /= 2\n \treturn (-n, i)\n \n l.sort(key=conv)\n print(*l)", "def abc(v):\r\n for j in d[v]:\r\n k.append(j)\r\n if d[v]:\r\n abc(d[v][-1])\r\nn=int(input())\r\nl=list(map(int,input().split()))\r\nl.sort()\r\nd={}\r\nk=[]\r\nfor i in l:\r\n a=[]\r\n b=[]\r\n req=2*i\r\n for j in l:\r\n if j==req:\r\n a.append(j)\r\n req = 2*j\r\n if not i%3:\r\n req=i//3\r\n else:\r\n req=-1\r\n for j in range(n-1,-1,-1):\r\n if req==-1:\r\n break\r\n if l[j]==req:\r\n b.append(l[j])\r\n if not l[j]%3:\r\n req=l[j]//3\r\n else:\r\n req=-1\r\n if a and b:\r\n d[i]=[]\r\n elif a:\r\n d[i]=a\r\n elif b:\r\n d[i]=b\r\n else:\r\n d[i]=a\r\nfor i in l:\r\n k=[i]\r\n try:\r\n abc(i)\r\n except:\r\n pass\r\n #print(i,k)\r\n if len(k)==n:\r\n print(*k)\r\n break\r\n k=[]\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n", "def abc(v):\r\n for j in d[v]:\r\n k.append(j)\r\n if d[v]:\r\n abc(d[v][-1])\r\nn=int(input())\r\nl=list(map(int,input().split()))\r\nl.sort()\r\nd={}\r\nk=[]\r\nfor i in l:\r\n a=[]\r\n b=[]\r\n req=2*i\r\n for j in l:\r\n if j==req:\r\n a.append(j)\r\n req = 2*j\r\n if not i%3:\r\n req=i//3\r\n else:\r\n req=-1\r\n for j in range(n-1,-1,-1):\r\n if req==-1:\r\n break\r\n if l[j]==req:\r\n b.append(l[j])\r\n if not l[j]%3:\r\n req=l[j]//3\r\n else:\r\n req=-1\r\n if a and b:\r\n d[i]=[]\r\n elif a:\r\n d[i]=a\r\n elif b:\r\n d[i]=b\r\n else:\r\n d[i]=[]\r\nfor i in l:\r\n k=[i]\r\n abc(i)\r\n #print(i,k)\r\n if len(k)==n:\r\n print(*k)\r\n break\r\n k=[]\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n", "def abc(v):\r\n for j in d[v]:\r\n k.append(j)\r\n if d[v]:\r\n abc(d[v][-1])\r\nn=int(input())\r\nl=list(map(int,input().split()))\r\nl.sort()\r\nd={}\r\nk=[]\r\nfor i in l:\r\n a=[]\r\n b=[]\r\n req=2*i\r\n for j in l:\r\n if j==req:\r\n a.append(j)\r\n req = 2*j\r\n if not i%3:\r\n req=i//3\r\n else:\r\n req=-1\r\n for j in range(n-1,-1,-1):\r\n if req==-1:\r\n break\r\n if l[j]==req:\r\n b.append(l[j])\r\n if not l[j]%3:\r\n req=l[j]//3\r\n else:\r\n req=-1\r\n if a and b:\r\n d[i]=[]\r\n elif a:\r\n d[i]=a\r\n elif b:\r\n d[i]=b\r\n else:\r\n d[i]=a\r\nfor i in l:\r\n k=[i]\r\n abc(i)\r\n #print(i,k)\r\n if len(k)==n:\r\n print(*k)\r\n break\r\n k=[]\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n"]
{"inputs": [["6", "4 8 6 3 12 9"]], "outputs": [["9 3 6 12 4 8"]]}
INTERVIEW
PYTHON3
CODECHEF
5,525
ac6958ffec6b8507cf57e493a863882f
UNKNOWN
There are $N$ cities on a circle, numbered $1$ through $N$. For each $i$ ($1 \le i \le N-1$), cities $i$ and $i+1$ are directly connected by a bidirectional road with length $A_i$, and cities $N$ and $1$ are also directly connected by a bidirectional road with length $A_N$. However, we do not know the lengths of some roads. For each city $i$, we do know that it has an opposite city — formally, there is a city $j \neq i$ such that the clockwise distance between cities $i$ and $j$ is equal to the counterclockwise distance between these cities. Please find the lengths of all roads in such a way that the above condition is satisfied and the sum of lengths of all roads is minimised. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of the input contains a single integer $N$. - The second line contains $N$ space-separated integers $A_1, A_2, \dots, A_N$. For each valid $i$, $A_i = -1$ denotes that the length of road $i$ is unknown. -----Output----- For each test case, print a line containing the string "NO" if there is no solution or "YES" otherwise. If a solution exists, print a second line containing $N$ space-separated positive integers — the lengths of all roads in your solution. Each of these integers should be $\le 10^9$. If there are multiple solutions, you may print any one. -----Constraints----- - $1 \le T \le 100$ - $3 \le N \le 10^5$ - $1 \le A_i \le 10^9$ or $A_i = -1$ for each valid $i$ - the sum of $N$ for all test cases does not exceed $3\cdot 10^5$ -----Subtasks----- Subtask #1 (10 points): $N \le 4$ Subtask #2 (20 points): $A_i = \pm 1$ for each valid $i$ Subtask #3 (70 points): original constraints -----Example Input----- 4 4 1 1 1 1 4 1 1 1 2 4 1 -1 -1 4 4 1 -1 2 -1 -----Example Output----- YES 1 1 1 1 NO YES 1 4 1 4 NO
["# cook your dish here\n# cook your dish here\nimport math\ntest=int(input())\nfor _ in range(test):\n n=int(input())\n l=list(map(int,input().split()))\n f=0\n for i in range(math.ceil(n//2)):\n if n%2==1:\n f=1\n break\n else:\n if l[i]!=l[i+n//2]:\n if min(l[i],l[i+n//2])==-1:\n l[i]=max(l[i],l[i+n//2])\n l[i+n//2]=max(l[i],l[i+n//2])\n else:\n f=1\n break\n else:\n if l[i]==-1:\n l[i]=1\n l[i+n//2]=1\n if f==1:\n print(\"NO\")\n else:\n print(\"YES\")\n print(*l)", "# cook your dish here\nimport math\ntest=int(input())\nfor _ in range(test):\n n=int(input())\n l=list(map(int,input().split()))\n f=0\n for i in range(math.ceil(n//2)):\n if n%2==1:\n f=1\n break\n else:\n if l[i]!=l[i+n//2]:\n if min(l[i],l[i+n//2])==-1:\n l[i]=max(l[i],l[i+n//2])\n l[i+n//2]=max(l[i],l[i+n//2])\n else:\n f=1\n break\n else:\n if l[i]==-1:\n l[i]=1\n l[i+n//2]=1\n if f==1:\n print(\"NO\")\n else:\n print(\"YES\")\n print(*l)", "import math\nfor _ in range(int(input())):\n n = int(input())\n l = list(map(int,input().split()))\n f = 0\n for i in range(math.ceil(n//2)):\n if n%2==1:\n f = 1\n break\n else:\n if l[i]!=l[i+n//2]:\n if min(l[i],l[i+n//2])==-1:\n l[i] = max(l[i],l[i+n//2])\n l[i+n//2] = max(l[i],l[i+n//2])\n else:\n f = 1\n break\n else:\n if l[i]==-1:\n l[i] = 1\n l[i+n//2] = 1\n if f==1:\n print(\"NO\")\n else:\n print(\"YES\")\n print(*l)", "\n\nfor _ in range(int(input())):\n n = int(input())\n a = list(map(int, input().split()))\n if n % 2 == 1:\n print(\"NO\")\n else:\n b = a[:n // 2]\n c = a[n // 2:]\n flag = True\n for i in range(n // 2):\n if b[i] != -1 and c[i] != -1:\n if b[i] != c[i]:\n flag = False\n break\n elif b[i] == -1 and c[i] != -1:\n b[i] = c[i]\n elif b[i] != -1 and c[i] == -1:\n c[i] = b[i]\n else:\n c[i] = 1\n b[i] = 1\n if flag:\n print(\"YES\")\n for x in b:\n print(x, end=' ')\n for x in c:\n print(x, end=' ')\n print()\n else:\n print(\"NO\")\n", "# cook your dish here\ntry:\n for i in range(int(input())):\n n=int(input())\n l=list(map(int,input().split()))\n if(n&1):\n print(\"NO\")\n continue\n b=n//2\n c=0\n for j in range(b):\n if(l[j]>-1 and l[j+b]>-1 and l[j]!=l[j+b]):\n c=1\n break\n elif(l[j]==l[j+b] and l[j]==-1):\n l[j]=1\n l[j+b]=1\n else:\n if(l[j]==-1):\n l[j]=l[j+b]\n elif(l[j+b]==-1):\n l[j+b]=l[j]\n if(c==1):\n print(\"NO\")\n else:\n print(\"YES\")\n for j in range(n-1):\n print(l[j],end=\" \")\n print(l[n-1])\nexcept:\n pass\n", "import math\nfor _ in range(int(input())):\n n = int(input())\n l = list(map(int,input().split()))\n f = 0\n for i in range(math.ceil(n//2)):\n if n%2==1:\n f = 1\n break\n else:\n if l[i]!=l[i+n//2]:\n if min(l[i],l[i+n//2])==-1:\n l[i] = max(l[i],l[i+n//2])\n l[i+n//2] = max(l[i],l[i+n//2])\n else:\n f = 1\n break\n else:\n if l[i]==-1:\n l[i] = 1\n l[i+n//2] = 1\n if f==1:\n print(\"NO\")\n else:\n print(\"YES\")\n print(*l)\n \n", "for _ in range(int(input())):\n N = int(input())\n array = list(map(int, input().split()))\n if N % 2 != 0:\n print('NO')\n else:\n possible = True\n p = N // 2\n for i in range(p):\n if array[i] == -1:\n if array[p+i] == -1:\n array[i] = 1\n array[p+i] = 1\n else:\n array[i] = array[p + i]\n else:\n if array[p+i] == -1:\n array[p + i] = array[i]\n else:\n if array[i] != array[p+i]:\n possible = False\n break\n if possible:\n print('YES')\n print(*array)\n else:\n print('NO')", "t=int(input())\nfor _ in range(t):\n n=int(input())\n a=[int(x) for x in input().split()]\n if n%2!=0:\n print('NO')\n continue\n x=n//2\n possible=True\n for i in range(x):\n if a[i]==-1:\n if a[i+x]==-1:\n a[i]=a[i+x]=1\n else:\n a[i]=a[i+x]\n else:\n if a[i+x]==-1:\n a[i+x]=a[i]\n else:\n if a[i]!=a[i+x]:\n possible=False\n break\n if possible:\n print('YES')\n for x in a:\n print(x,end=' ')\n print()\n else:\n print('NO')", "# cook your dish here\nfor t in range(int(input())):\n n = int(input())\n a = list(map(int, input().split()))\n if n%2 == 0:\n answer = \"YES\"\n for i in range(n//2):\n if a[i] == a[n//2 + i]:\n if a[i] == -1:\n a[i] = a[n//2+i] = 1\n else:\n if a[i] == -1:\n a[i] = a[n//2+i]\n elif a[n//2 + i] == -1:\n a[n//2 + i] = a[i]\n else:\n answer = \"NO\"\n break\n \n print(answer)\n if(answer == \"YES\"): print(\" \".join(map(str, a)))\n else:\n print(\"NO\")", "t = int(input())\nwhile t>0:\n t -= 1\n n = int(input())\n dis = [int(x) for x in input().split()]\n if n%2 == 1:\n print('NO')\n continue\n mid = n//2\n for i in range(mid):\n if dis[i] == -1 and dis[mid+i] == -1:\n dis[i] = dis[i+mid] = 1\n elif dis[i] == -1:\n dis[i] = dis[i+mid]\n elif dis[i+mid] == -1:\n dis[i+mid] = dis[i]\n flag = True\n for i in range(mid):\n if dis[i] != dis[i+mid]:\n flag = False\n print('NO')\n break\n if flag:\n print('YES')\n for i in range(n):\n print(dis[i], end=' ')\n print()\n \n ", "T=int(input())\nfor i in range(T):\n N=int(input())\n A=list(map(int,input().split()))\n x=N//2\n c=0\n if(N%2!=0):\n print(\"NO\")\n else:\n for i in range(x):\n if(A[i]==-1 and A[i+x]==-1):\n A[i]=1\n A[i+x]=1\n elif(A[i]==-1):\n A[i]=A[i+x]\n elif(A[i+x]==-1):\n A[i+x]=A[i]\n for i in range(x):\n if(A[i]!=A[i+x]):\n c=1\n break\n if(c==1):\n print(\"NO\")\n else:\n print(\"YES\")\n print(*A)\n", "\nt = int(input())\nfor _ in range(t):\n n = int(input())\n dist = list(map(int, input().split()))\n if n % 2 != 0:\n print(\"NO\")\n else:\n f = 1\n for i in range(n//2):\n if dist[i] != dist[i+n//2] and dist[i] != -1 and dist[i+n//2] != -1:\n f = 0\n break\n elif dist[i] == -1 and dist[i+n//2] == -1:\n dist[i] = 1\n dist[i+n//2] = 1\n\n else:\n dist[i] = dist[i+n//2] = max(dist[i], dist[i+n//2])\n\n if f == 0:\n print(\"NO\")\n else:\n print(\"YES\")\n print(' '.join(map(str, dist)))\n", "def m(l,n):\n if n%2 != 0:\n print(\"NO\")\n else:\n c=0\n for i in range (n//2):\n if l[i]==l[n//2+i] :\n if l[i]==-1:\n l[i]=1\n l[n//2+i]=1\n continue\n else:\n continue\n elif l[i]==-1:\n l[i]=l[n//2+i]\n continue\n elif l[n//2+i]==-1:\n l[n//2+i]=l[i]\n continue\n else:\n print(\"NO\")\n c+=1\n break\n if c==0:\n print(\"YES\")\n print(*l)\nt=int(input())\nwhile(t):\n n=int(input())\n l=list(map(int,input().split()))\n m(l,n)\n t-=1", "for _ in range(int(input())):\n n=int(input())\n l=list(map(int,input().split()))\n flag=0\n if(n%2==1):\n print(\"NO\")\n continue\n for i in range(n//2):\n x=l[i]\n y=l[i+n//2]\n if(x==-1 or y==-1):\n l[i]=max(x,y,1)\n l[i+n//2]=l[i]\n else:\n if(x!=y):\n flag=1\n if(flag==1):\n print(\"NO\")\n else:\n print(\"YES\")\n for i in l:\n print(i,end=\" \")\n print(\"\")", "for _ in range(int(input())):\n n, ans = int(input()), \"YES\"\n a = list(map(int, input().split()))\n if n & 1:\n ans = \"NO\"\n else:\n for i in range(n>>1):\n opp = i + (n>>1)\n if a[i] != -1 and a[opp] != -1 and a[i] != a[opp]:\n ans = \"NO\"\n break\n elif a[i] == -1 and a[opp] != -1:\n a[i] = a[opp]\n elif a[i] != -1 and a[opp] == -1:\n a[opp] = a[i]\n elif a[i] == -1 and a[opp] == -1:\n a[i] = 1\n a[opp] = 1\n print(ans)\n if ans == \"YES\":\n print(*a)", "import math\nt=int(input())\nfor _ in range(t):\n n=int(input())\n s=0\n a=[int(i) for i in input().split()]\n if n%2!=0:\n print(\"NO\")\n else:\n k=n//2\n f=0\n for i in range(0,k):\n if a[i]!=-1 and a[k+i]!=-1:\n if a[i]!=a[k+i]:\n f=1\n break\n else: \n f=0\n if f==1:\n print(\"NO\")\n else:\n for i in range(k):\n if a[i]==-1 and a[k+i]==-1:\n a[i]=1\n a[k+i]=1\n elif a[k+i]==-1:\n a[k+i]=a[i]\n else:\n a[i]=a[k+i]\n print(\"YES\")\n for i in range(n):\n print(a[i],end=\" \")\n print(\"\")", "t=int(input())\nfor z in range(t):\n n=int(input())\n a=[int(x) for x in input().split()]\n flag=0\n if n%2==0 and (n//2)%2==0: \n for i in range(n-n//2):\n if a[i]!=-1 and a[i+n//2]!=-1 and a[i+n//2]!=a[i]:\n flag=1\n break\n elif a[i]!=-1 and a[i+n//2]==-1:\n a[i+n//2]=a[i]\n elif a[i]==-1 and a[i+n//2]==-1:\n a[i]=1\n a[i+n//2]=1\n elif a[i]==-1 and a[i+n//2]!=-1:\n a[i]=a[i+n//2]\n elif n%2==0:\n k=1\n for i in a:\n if i!=-1:\n k=i\n for i in range(n-n//2):\n if a[i]!=-1 and a[i+n//2]!=-1 and a[i+n//2]!=a[i]:\n flag=1\n break\n elif a[i]!=-1 and a[i+n//2]==-1:\n a[i+n//2]=a[i]\n elif a[i]==-1 and a[i+n//2]==-1:\n a[i]=k\n a[i+n//2]=k\n elif a[i]==-1 and a[i+n//2]!=-1:\n a[i]=a[i+n//2]\n else:\n print(\"NO\")\n continue\n if sum(a)%2!=0:\n flag=1\n if flag==0:\n print(\"YES\")\n for i in a:\n print(i,end=\" \")\n print()\n else:\n print(\"NO\")\n \n \n", "t=int(input())\nfor z in range(t):\n n=int(input())\n a=[int(x) for x in input().split()]\n flag=0\n if n%2==0 and (n//2)%2==0: \n for i in range(n-2):\n if a[i]!=-1 and a[i+n//2]!=-1 and a[i+n//2]!=a[i]:\n flag=1\n break\n elif a[i]!=-1 and a[i+n//2]==-1:\n a[i+n//2]=a[i]\n elif a[i]==-1 and a[i+n//2]==-1:\n a[i]=1\n a[i+n//2]=1\n elif a[i]==-1 and a[i+n//2]!=-1:\n a[i]=a[i+n//2]\n elif n%2==0:\n k=1\n for i in a:\n if i!=-1:\n k=i\n for i in range(n-n//2):\n if a[i]!=-1 and a[i+n//2]!=-1 and a[i+n//2]!=a[i]:\n flag=1\n break\n elif a[i]!=-1 and a[i+n//2]==-1:\n a[i+n//2]=a[i]\n elif a[i]==-1 and a[i+n//2]==-1:\n a[i]=k\n a[i+n//2]=k\n elif a[i]==-1 and a[i+n//2]!=-1:\n a[i]=a[i+n//2]\n else:\n print(\"NO\")\n continue\n if sum(a)%2!=0:\n flag=1\n if flag==0:\n print(\"YES\")\n for i in a:\n print(i,end=\" \")\n print()\n else:\n print(\"NO\")\n \n \n", "t=int(input())\nfor z in range(t):\n n=int(input())\n a=[int(x) for x in input().split()]\n flag=0\n if n%2==0 and (n//2)%2==0: \n for i in range(n-2):\n if a[i]!=-1 and a[i+2]!=-1 and a[i+2]!=a[i]:\n flag=1\n break\n elif a[i]!=-1 and a[i+2]==-1:\n a[i+2]=a[i]\n elif a[i]==-1 and a[i+2]==-1:\n a[i]=1\n a[i+2]=1\n elif a[i]==-1 and a[i+2]!=-1:\n a[i]=a[i+2]\n elif n%2==0:\n k=1\n for i in a:\n if i!=-1:\n k=i\n for i in range(n-2):\n \n if a[i]!=-1 and a[i+2]!=-1 and a[i+2]!=a[i]:\n flag=1\n break\n elif a[i]!=-1 and a[i+2]==-1:\n a[i+2]=a[i]\n elif a[i]==-1 and a[i+2]==-1:\n a[i]=k\n a[i+2]=k\n elif a[i]==-1 and a[i+2]!=-1:\n a[i]=a[i+2]\n else:\n print(\"NO\")\n continue\n if sum(a)%2!=0:\n flag=1\n if flag==0:\n print(\"YES\")\n for i in a:\n print(i,end=\" \")\n print()\n else:\n print(\"NO\")\n \n \n", "t=int(input())\nfor z in range(t):\n n=int(input())\n a=[int(x) for x in input().split()]\n flag=0\n for i in range(n-2):\n if a[i]!=-1 and a[i+2]!=-1 and a[i+2]!=a[i]:\n flag=1\n break\n elif a[i]!=-1 and a[i+2]==-1:\n a[i+2]=a[i]\n elif a[i]==-1 and a[i+2]==-1:\n a[i]=1\n a[i+2]=1\n elif a[i]==-1 and a[i+2]!=-1:\n a[i]=a[i+2]\n if sum(a)%2!=0:\n flag=1\n if flag==0:\n print(\"YES\")\n for i in a:\n print(i,end=\" \")\n print()\n else:\n print(\"NO\")\n \n \n", "tc=int(input())\nfor x in range(tc):\n n=int(input())\n a=[int(x) for x in input().split()]\n if n%2!=0:\n print(\"NO\")\n else:\n a1=a[:n//2]\n a2=a[n//2:]\n t=0\n for i in range(n//2):\n if a1[i]!=-1 and a2[i]!=-1 and a1[i]!=a2[i]:\n print(\"NO\")\n t=1\n break\n else:\n if a1[i]==-1 and a2[i]!=-1:\n a1[i]=a2[i]\n if a2[i]==-1 and a1[i]!=-1:\n a2[i]=a1[i]\n if a1[i]==-1 and a2[i]==-1:\n a1[i]=a2[i]=1\n if t==0:\n print(\"YES\")\n print(*(a1+a2))", "T=int(input())\nn=0\nfor i in range(T):\n c=0\n n=int(input())\n A=list(map(int,input().strip().split(\" \")))\n if(n%2==1):\n print('NO')\n continue\n for j in range(int(n/2)):\n if A[j]==-1 and A[int(j+n/2)]!=-1:\n A[j]=A[int(j+n/2)]\n elif A[j]!=-1 and A[int(j+n/2)]==-1:\n A[int(j+n/2)]=A[j]\n elif A[j]==-1 and A[int(j+n/2)]==-1:\n A[j]=1 \n A[int(j+n/2)]=1\n continue\n \n \n for j in range(int(n/2)):\n if A[j]!=A[int(j+n/2)]:\n c=1\n break\n if c==1:\n print('NO')\n else:\n print('YES')\n print(\" \".join(map(str,A))) ", "T=int(input())\nn=0\nfor i in range(T):\n c=0\n n=int(input())\n A=list(map(int,input().strip().split(\" \")))\n if(n%2==1):\n print('NO')\n continue\n for j in range(int(n/2)):\n if A[j]==-1 and A[int(j+n/2)]!=-1:\n A[j]=A[int(j+n/2)]\n elif A[j]!=-1 and A[int(j+n/2)]==-1:\n A[int(j+n/2)]=A[j]\n elif A[j]==-1 and A[int(j+n/2)]==-1:\n A[j]=1 \n A[int(j+n/2)]=1\n continue\n \n \n for j in range(int(n/2)):\n if A[j]!=A[int(j+n/2)]:\n c=1\n break\n if c==1:\n print('NO')\n else:\n print('YES')\n print(\" \".join(map(str,A))) ", "t = int(input())\nwhile t:\n t -= 1\n n = int(input())\n a = list(map(int, input().strip().split()))\n if n % 2:\n print(\"NO\")\n else:\n okay = True\n p = n // 2\n for i in range(p):\n if a[i] == -1 and a[i + p] == -1:\n a[i] = a[i + p] = 1\n elif a[i] == -1:\n a[i] = a[i + p]\n elif a[i + p] == -1:\n a[i + p] = a[i]\n elif a[i] != a[i + p]:\n okay = False\n if okay:\n print(\"YES\")\n for x in a:\n print(x, end = \" \")\n print()\n else:\n print(\"NO\")\n\n", "t=int(input())\nfor i in range(0,t):\n n=int(input())\n a=[int(i) for i in input().split()]\n if n%2!=0:\n print(\"NO\")\n else:\n i=0\n j=n//2\n flag=0\n while i<(n//2):\n if a[i]==-1 and a[j]!=-1:\n a[i]=a[j]\n elif a[j]==-1 and a[i]!=-1:\n a[j]=a[i]\n elif a[i]==-1 and a[j]==-1:\n a[i]=1\n a[j]=1\n elif a[i]!=a[j]:\n flag=1\n break\n i+=1\n j+=1\n if flag==1:\n print(\"NO\")\n else:\n print(\"YES\")\n print(*a,sep=\" \")"]
{"inputs": [["4", "4", "1 1 1 1", "4", "1 1 1 2", "4", "1 -1 -1 4", "4", "1 -1 2 -1"]], "outputs": [["YES", "1 1 1 1", "NO", "YES", "1 4 1 4", "NO"]]}
INTERVIEW
PYTHON3
CODECHEF
14,016
34ea69ce06611960c8b9960b2ca75e25
UNKNOWN
The chef is trying to solve some pattern problems, Chef wants your help to code it. Chef has one number K to form a new pattern. Help the chef to code this pattern problem. -----Input:----- - First-line will contain $T$, the number of test cases. Then the test cases follow. - Each test case contains a single line of input, one integer $K$. -----Output:----- For each test case, output as the pattern. -----Constraints----- - $1 \leq T \leq 50$ - $1 \leq K \leq 50$ -----Sample Input:----- 5 1 2 3 4 5 -----Sample Output:----- 1 1 23 1 23 456 1 23 4 5 6789 1 23 4 5 6 7 89101112 -----EXPLANATION:----- No need, else pattern can be decode easily.
["# cook your dish here\nfor _ in range(int(input())):\n n = int(input())\n count = 1\n l = 3*(n-1)\n i = 0\n if n==1:\n print(1)\n continue\n while count<=l-n:\n for j in range(i+1):\n if j==i:\n print(count)\n count += 1\n elif j==0:\n print(count,end=\"\")\n count += 1\n else:\n print(\" \",end=\"\") \n i+=1\n while count<=l:\n print(count,end=\"\")\n count += 1\n print()", "t = int(input())\nfor _ in range(t):\n k = int(input())\n count=1\n for i in range(k):\n for j in range(i+1):\n if i<k-1:\n if i==j or j==0:\n print(count,end='')\n count += 1\n else:\n print(' ',end='')\n else:\n print(count,end='')\n count+=1\n print()\n ", "# cook your dish here\n# cook your dish here\ndef solve():\n n = int(input())\n #n,m = input().split()\n #n = int(n)\n #m = int(m)\n #s = input()\n #a = list(map(int, input().split()))\n it = 1\n k=1\n for i in range(n):\n j=0\n while j<it:\n mark=1\n if (i==n-1 or (j==0 or j==it-1) ): \n print(k,end=\"\")\n k+=1\n else:\n print(\" \",end=\"\")\n # continue\n j+=1\n print(\"\")\n it+=1\n \n \n \n \ndef __starting_point():\n T = int(input())\n for i in range(T):\n #a = solve()\n #n = len(a)\n #for i in range(n):\n # if i==n-1 : print(a[i])\n # else: print(a[i],end=\" \")\n (solve())\n__starting_point()", "def solve(n):\r\n c= 1\r\n r = list(range(1,n+1))\r\n for i in r:\r\n x = ''\r\n if 3<=i<n:\r\n x+=str(c)\r\n c+=1\r\n for j in range(i-2):\r\n x+=' '\r\n x+=str(c)\r\n c+=1\r\n else:\r\n for j in range(i):\r\n x+=str(c)\r\n c+=1\r\n print(x)\r\n\r\ndef main():\r\n t = int(input())\r\n for i in range(t):\r\n n = int(input())\r\n solve(n)\r\n\r\n\r\nmain()\r\n", "def f(n):\r\n if n==1:\r\n return print(1)\r\n \r\n p = 2\r\n print(1)\r\n \r\n line = 2\r\n while line < n:\r\n print(p, \" \"*(line-2), p+1, sep=\"\")\r\n p += 2\r\n line += 1\r\n \r\n for i in range(n):\r\n print(p, end=\"\")\r\n p += 1\r\n print()\r\n\r\nt = int(input())\r\nanswers = list()\r\nfor _ in range(t):\r\n n = int(input())\r\n answers.append(n)\r\n\r\nfor answer in answers:\r\n f(answer)", "for _ in range(int(input())):\r\n n=int(input())\r\n a=0\r\n xx=2\r\n if n==1:\r\n print('1')\r\n elif n==2:\r\n print('1')\r\n print('23')\r\n else: \r\n print('1')\r\n for _ in range(2,n):\r\n print(xx,end=\"\")\r\n xx+=1\r\n if a>0:\r\n print(' '*a,end=\"\")\r\n a+=1\r\n print(xx)\r\n xx+=1\r\n # xx+=1 \r\n for _ in range(1,n+1):\r\n print(xx,end=\"\")\r\n xx+=1\r\n print() \r\n \r\n \r\n ", "import sys\r\ninput = lambda: sys.stdin.readline().rstrip(\"\\r\\n\")\r\ninp = lambda: list(map(int,sys.stdin.readline().rstrip(\"\\r\\n\").split()))\r\n#______________________________________________________________________________________________________\r\n# from math import *\r\n# from bisect import *\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(2*(10**5)+100) this is must for dfs\r\n# mod = 10**9+7; md = 998244353\r\n# ______________________________________________________________________________________________________\r\n# segment tree for range minimum query\r\n# sys.setrecursionlimit(10**5)\r\n# n = int(input())\r\n# a = list(map(int,input().split()))\r\n# st = [float('inf') for i in range(4*len(a))]\r\n# def build(a,ind,start,end):\r\n# if start == end:\r\n# st[ind] = a[start]\r\n# else:\r\n# mid = (start+end)//2\r\n# build(a,2*ind+1,start,mid)\r\n# build(a,2*ind+2,mid+1,end)\r\n# st[ind] = min(st[2*ind+1],st[2*ind+2])\r\n# build(a,0,0,n-1)\r\n# def query(ind,l,r,start,end):\r\n# if start>r or end<l:\r\n# return float('inf')\r\n# if l<=start<=end<=r:\r\n# return st[ind]\r\n# mid = (start+end)//2\r\n# return min(query(2*ind+1,l,r,start,mid),query(2*ind+2,l,r,mid+1,end))\r\n# ______________________________________________________________________________________________________\r\n# Checking prime in O(root(N))\r\n# def isprime(n):\r\n# if (n % 2 == 0 and n > 2) or n == 1: return 0\r\n# else:\r\n# s = int(n**(0.5)) + 1\r\n# for i in range(3, s, 2):\r\n# if n % i == 0:\r\n# return 0\r\n# return 1\r\n# def lcm(a,b):\r\n# return (a*b)//gcd(a,b)\r\n# ______________________________________________________________________________________________________\r\n# nCr under mod\r\n# def C(n,r,mod):\r\n# if r>n:\r\n# return 0\r\n# num = den = 1\r\n# for i in range(r):\r\n# num = (num*(n-i))%mod\r\n# den = (den*(i+1))%mod\r\n# return (num*pow(den,mod-2,mod))%mod\r\n# M = 10**5 +10\r\n# ______________________________________________________________________________________________________\r\n# For smallest prime factor of a number\r\n# M = 1000010\r\n# pfc = [i for i in range(M)]\r\n# def pfcs(M):\r\n# for i in range(2,M):\r\n# if pfc[i]==i:\r\n# for j in range(i+i,M,i):\r\n# if pfc[j]==j:\r\n# pfc[j] = i\r\n# return\r\n# pfcs(M)\r\n# ______________________________________________________________________________________________________\r\ntc = 1\r\ntc, = inp()\r\n# a = [0,1]\r\n# for i in range(100000):\r\n# a.append(a[-1]+a[-2])\r\nfor _ in range(tc):\r\n n, = inp()\r\n if n==1:\r\n print(1)\r\n continue\r\n c = 1\r\n print(1)\r\n c+=1\r\n for i in range(n-2):\r\n print(str(c)+' '*(i)+str(c+1))\r\n c+=2\r\n print(*[c+i for i in range(n)],sep = \"\")", "for _ in range(int(input())):\r\n n=int(input())\r\n if(n==1):\r\n print(\"1\")\r\n continue\r\n print(\"1\")\r\n r=2\r\n for i in range(n-2):\r\n t=str(r)\r\n t+=\" \"*i\r\n r+=1\r\n t+=str(r)\r\n r+=1\r\n print(t)\r\n for i in range(n):\r\n print(r,end=\"\")\r\n r+=1\r\n print()", "from sys import stdin, stdout\nfrom math import floor, gcd, fabs, factorial, fmod, sqrt, inf, log\nfrom collections import defaultdict as dd, deque\nfrom heapq import merge, heapify, heappop, heappush, nsmallest\nfrom bisect import bisect_left as bl, bisect_right as br, bisect\nmod = pow(10, 9) + 7\nmod2 = 998244353\ndef inp(): return stdin.readline().strip()\ndef out(var, end=\"\\n\"): stdout.write(str(var)+\"\\n\")\ndef outa(*var, end=\"\\n\"): stdout.write(' '.join(map(str, var)) + end)\ndef lmp(): return list(mp())\ndef mp(): return map(int, inp().split())\ndef smp(): return map(str, inp().split())\ndef l1d(n, val=0): return [val for i in range(n)]\ndef l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]\ndef remadd(x, y): return 1 if x%y else 0\ndef ceil(a,b): return (a+b-1)//b\n\ndef isprime(x):\n if x<=1: return False\n if x in (2, 3): return True\n if x%2 == 0: return False\n for i in range(3, int(sqrt(x))+1, 2):\n if x%i == 0: return False\n return True\n \nfor _ in range(int(inp())):\n n = int(inp())\n k = 1\n for i in range(1, n+1):\n for j in range(i):\n if j==0 or j==i-1 or i==n: \n print(k, end=\"\")\n k+=1\n else: print(\" \", end=\"\")\n print()"]
{"inputs": [["5", "1", "2", "3", "4", "5"]], "outputs": [["1", "1", "23", "1", "23", "456", "1", "23", "4 5", "6789", "1", "23", "4 5", "6 7", "89101112"]]}
INTERVIEW
PYTHON3
CODECHEF
8,265
b111777307e96562135e3429c9a07ad7
UNKNOWN
Note : This question carries $100$ $points$ CodeLand is celebrating a festival by baking cakes! In order to avoid wastage, families follow a unique way of distributing cakes. For $T$ families in the locality, $i$-th family (1 <= $i$ <= $T$) has $N$ members. They baked $S$ slices of cakes. The smallest member of the family gets $K$ slices of cakes. Each family has a lucky number of $R$ and they agree to distribute the slices such that the member gets $R$ times more slices than the member just smaller than them. Since the family is busy in festival preparations, find out if the number of slices would be sufficient for the family or not. Also, find how many extra slices they have or how many slices are they short of. Also, the locality is kind and believes in sharing. So, you also need to determine if each family would have sufficient slices if families shared their cakes among each other! -----Input :----- - First line of input will have a single integer $T$ i.e. the number of families in the locality - For next $T$ lines, each line will describe one family through 4 integers i.e. $S$, $N$, $K$, $R$ separated by spaces -----Output----- - First $T$ lines of output will show if slices are enough for the family or not, followed by extra or required slices. For example, if slices are sufficient, the output would be $POSSIBLE$ $10$ which implies 10 slices are extra. If slices are insufficient, the output would be $IMPOSSIBLE$ $15$ which implies 15 slices are required to fulfill the requirement. - Last line of output would be $IMPOSSIBLE$ or $POSSIBLE$ depending on whether each family would get enough slices after sharing. -----Constraints:----- - 1 ≤ $T$ ≤ 50 - 1 ≤ $N$ ≤ 15 - 1 ≤ $S$ ≤ 10^9 - 1 ≤ $K$ ≤ 5 - 1 ≤ $R$ ≤ 5 -----Sample Input:----- 5 100 4 2 2 100 4 3 2 100 4 3 3 200 4 4 2 10 3 2 2 -----Sample Output:----- POSSIBLE 70 POSSIBLE 55 IMPOSSIBLE 20 POSSIBLE 140 IMPOSSIBLE 4 POSSIBLE -----Explanation----- For the first home, the youngest member has got 2 slices, the one older than them gets 2 times more slices, and so forth. So, first home needs 2 + 4 + 8 + 16 = 30 slices. But since they made 100, they have 70 extra, hence we print 'POSSIBLE 70'. Doing the same for other houses, we find 20 + 4 = 24 slices extra are required so that all families have enough slices. In this case we have 70 + 55 + 140 = 265 extra slices which is > 24, so we print 'POSSIBLE' in last line.
["# cook your dish here\nextra, less = 0,0\nfor _ in range(int(input())):\n sli,mem,sma,luc = list(map(int, input().split()))\n total = sma\n t = sma\n while mem > 1:\n t *= luc\n total += t\n mem -= 1\n if total <= sli:\n extra += sli-total\n print('POSSIBLE',sli-total)\n else:\n less += total-sli\n print('IMPOSSIBLE',total-sli)\nif extra >= less:\n print('POSSIBLE')\nelse:\n print('IMPOSSIBLE')\n \n \n \n \n", "import math\r\nimport random\r\nimport re\r\nimport os\r\nimport sys\r\ndef cake(c):\r\n k=c[2]\r\n t=c[3]\r\n s=0\r\n for i in range(c[1]):\r\n s+=k\r\n k*=t\r\n if s>c[0]:\r\n s-=c[0]\r\n c.append(\"IMPOSSIBLE\")\r\n c.append(-s)\r\n else:\r\n s=c[0]-s\r\n c.append(\"POSSIBLE\")\r\n c.append(s)\r\n return (list(str(c[4])+str(c[5]))) \r\ndef main():\r\n n = int(input())\r\n c=[[]]*n\r\n res=[]\r\n m=[]\r\n cou=0\r\n for i in range(n):\r\n c[i] = list(map(int, input().rstrip().split()))\r\n res.append(cake(c[i]))\r\n for i in range(len(c)):\r\n print(*c[i][-2:-1], end=\" \")\r\n print(abs(*c[i][-1:]))\r\n m.append(*c[i][-1:])\r\n cou=sum(m)\r\n if cou>0:\r\n print(\"POSSIBLE\")\r\n else:\r\n print(\"IMPOSSIBLE\")\r\n return 0\r\ndef __starting_point():\r\n main()\r\n\n__starting_point()", "s1=0;s2=0\nfor _ in range(int(input())):\n l=[]\n l=list(map(int,input().split()))\n s=int(l[0])\n n=int(l[1])\n k=int(l[2])\n r=int(l[3])\n if(r!=1):\n s-=(k*((r**n)-1))//(r-1)\n else:\n s-=k*n\n if(s>=0):\n print(\"POSSIBLE\",s)\n else:\n print(\"IMPOSSIBLE\",abs(s))\n if(s>0):\n s1+=s\n else:\n s2+=abs(s)\nif(s1>=s2):\n print(\"POSSIBLE\")\nelse:\n print(\"IMPOSSIBLE\")", "# cook your dish here\nsTot = 0\nfor _ in range(int(input())):\n s,n,k,r = map(int,input().split())\n if r == 1:\n sn = k*n\n else:\n sn = k*(r**n-1)/(r-1)\n if sn<=s:\n print(\"POSSIBLE\",int(s-sn))\n sTot += s-sn\n else:\n print(\"IMPOSSIBLE\",int(sn-s))\n sTot -= sn-s\nif sTot >= 0:\n print(\"POSSIBLE\")\nelse:\n print(\"IMPOSSIBLE\")", "# cook your dish here\nover = 0\nmissing = 0\n\nfor i in range(int(input())):\n\ts, n, k, r = list(map(int, input().split()))\n\n\ttotalSlicesNeeded = k\n\tcurrNeeded = k\n\tfor i in range(n-1):\n\t\tcurrNeeded *= r\n\t\ttotalSlicesNeeded += currNeeded\n\n\tif totalSlicesNeeded > s:\n\t\tmissing += totalSlicesNeeded - s\n\t\tprint(f\"IMPOSSIBLE {totalSlicesNeeded - s}\")\n\telse:\n\t\tover += s - totalSlicesNeeded\n\t\tprint(f\"POSSIBLE {s - totalSlicesNeeded}\")\nif over >= missing:\n\tprint(\"POSSIBLE\")\nelse:\n\tprint(\"IMPOSSIBLE\")", "p,ip = 0,0\nfor _ in range(int(input())):\n s,n,k,r = map(int,input().split())\n sm = 0\n while n != 0:\n sm += k\n k = r*k\n n -= 1\n if (s-sm) >= 0:\n print('POSSIBLE',s-sm)\n p += (s-sm)\n else:\n print('IMPOSSIBLE',abs(s-sm))\n ip += abs(s-sm)\nif p >= ip:\n print('POSSIBLE')\nelse:\n print('IMPOSSIBLE')", "# cook your dish here\nfrom math import pow\ncheck_possible =0\nfor _ in range(int(input())):\n s,n,k,r = map(int,input().split())\n if r>1:\n total_slices = k*(pow(r,n)-1)/(r-1)\n else:\n total_slices = k*n\n left_slices = s-total_slices\n check_possible +=left_slices\n if left_slices>=0:\n print('POSSIBLE',int(left_slices))\n else:\n print('IMPOSSIBLE',int(-(left_slices)))\nif check_possible>=0:\n print('POSSIBLE')\nelse:\n print('IMPOSSIBLE')", "#python 3.7.1\nc,d=0,0\nfor _ in range(int(input())):\n s,n,k,r = input ().split()\n s,n,k,r = int(s),int(n),int(k),int(r)\n sum,g,x=0,k,0\n a=k \n for i in range(int(n-1)):\n a=a*r\n g=g+a \n if(g<s):\n x=s-g\n print(\"POSSIBLE\",x)\n c=c+x\n else:\n x=g-s\n print(\"IMPOSSIBLE\",x)\n d=d+x\nif c>d:\n print(\"POSSIBLE\")\nelse:\n print(\"IMPOSSIBLE\")\n", "total,possible,impossible=0,0,0\r\nfor i in range(int(input())):\r\n N,S,K,R=list(map(int,input().split()))\r\n total =total+N\r\n points=K\r\n sum=K\r\n for j in range(S-1):\r\n points=points*R\r\n sum+=points\r\n \r\n if sum<=N:\r\n possible=possible+N-sum\r\n print('POSSIBLE',N-sum)\r\n else:\r\n impossible=impossible+sum-N\r\n print('IMPOSSIBLE',sum-N)\r\n\r\nif possible>=impossible:\r\n print('POSSIBLE')\r\nelse:\r\n print('IMPOSSIBLE')\r\n", "\r\nt=int(input())\r\ngrandsum=0\r\nwhile t:\r\n l=list(map(int,input().strip().split()))\r\n s=l[0]\r\n n=l[1]\r\n k=l[2]\r\n r=l[3]\r\n res=k\r\n \r\n for i in range(1,n):\r\n k=k*r\r\n res=res+k\r\n if res<=s:\r\n print(\"POSSIBLE\",str(s-res))\r\n grandsum+=(s-res)\r\n else:\r\n print(\"IMPOSSIBLE\",str(abs(s-res)))\r\n grandsum-=abs(s-res)\r\n\r\n t-=1\r\nif grandsum<0:\r\n print(\"IMPOSSIBLE\")\r\nelse:\r\n print(\"POSSIBLE\")\r\n\r\n", "# cook your dish here\nt=int(input())\nextra=0 \nrequired=0\nwhile t>0:\n s,n,k,r=list(map(int,input().split()))\n sum1=k\n pro=k\n for i in range(1,n):\n pro=pro*r \n sum1+=pro \n z=s-sum1\n if z>=0:\n extra+=z \n print(\"POSSIBLE\",z)\n else:\n z=z*(-1)\n required+=z \n print(\"IMPOSSIBLE\",z)\n t-=1\nif extra-required>=0:\n print(\"POSSIBLE\")\nelse:\n print(\"IMPOSSIBLE\")", "t=int(input())\nsum=0\nfor _ in range(t):\n s,n,k,r=map(int,input().split())\n if r==1:\n k=s- n*k\n else:\n k=s- k*((r**n -1)//(r-1))\n sum+=k\n if k<0:\n print('IMPOSSIBLE',-k)\n else:\n print('POSSIBLE',k)\nif sum<0:\n print('IMPOSSIBLE')\nelse:\n print('POSSIBLE')", "# cook your dish here\nt = int(input())\n\nsum1 = 0\nlist2 = list()\nlist3 = list()\nlist4 = list()\n\nwhile t > 0:\n s, n, k, r = input().split()\n s = int(s)\n list3.append(s)\n n = int(n)\n k = int(k)\n r = int(r)\n list1 = []\n sum1 = s + sum1\n ans = k\n while n > 0:\n list1.append(ans)\n #print(ans)\n ans = ans*r\n n-=1\n m = sum(list1)\n list2.append(m)\n z = s - m\n list4.append(z) \n t-=1\nx = sum(list2)\n\nfor i in list4:\n if i > 0:\n print('POSSIBLE',i)\n else:\n print('IMPOSSIBLE',-i)\n \n\nif x > sum1:\n print('IMPOSSIBLE')\nelse:\n print('POSSIBLE')\n\n \n", "x = int(input())\r\nli = []\r\nfor i in range(x):\r\n temp = 0\r\n s,n,k,r = map(int, input().split())\r\n for j in range(n):\r\n if j == 0:\r\n temp += k\r\n else:\r\n k = k*r \r\n temp += k\r\n if temp > s:\r\n print(\"IMPOSSIBLE {0}\".format(temp-s))\r\n li.append(s-temp)\r\n else:\r\n print(\"POSSIBLE {0}\".format(s-temp))\r\n li.append(s-temp)\r\nif sum(li) >= 0:\r\n print(\"POSSIBLE\")\r\nelse:\r\n print(\"IMPOSSIBLE\")", "poss=0\r\nimposs=0\r\nfor _ in range(int(input())):\r\n s,n,k,r=list(map(int,input().split()))\r\n a=[0]*n\r\n a[0]=k\r\n for i in range(1,n):\r\n a[i]=a[i-1]*r\r\n if sum(a)<=s:\r\n x=s-sum(a)\r\n print('POSSIBLE '+str(x))\r\n poss=poss+x\r\n else:\r\n y=abs(s-sum(a))\r\n print('IMPOSSIBLE '+str(y))\r\n imposs=imposs+y\r\n \r\nif imposs<=poss:\r\n print('POSSIBLE')\r\nelse:\r\n print('IMPOSSIBLE')\r\n", "fam=int(input())\r\nextra,req=0,0\r\nfor i in range(fam):\r\n s,n,k,r=list(map(int,input().split()))\r\n if r>1:\r\n sm=(k*(r**n-1))//(r-1)\r\n else:\r\n sm=k*n\r\n if sm<=s:\r\n print(\"POSSIBLE\",s-sm)\r\n extra+=(s-sm)\r\n else:\r\n print(\"IMPOSSIBLE\",abs(s-sm))\r\n req+=(abs(s-sm))\r\n#print(extra,req)\r\nif extra>=req:\r\n print(\"POSSIBLE\")\r\nelse:\r\n print(\"IMPOSSIBLE\")\r\n", "# cook your dish here\ndef fun1(S,N,K,R):\n total=K\n for _ in range(1,N):\n K=K*R\n total+=K\n return (S-total) \n\nfinal=0\nT=int(input())\n\nfor i in range(T):\n S,N,K,R=map(int,input().split())\n slices_required=fun1(S,N,K,R)\n if(slices_required >= 0):\n print(\"POSSIBLE\",end=\" \")\n print(slices_required)\n else:\n print(\"IMPOSSIBLE\",end=\" \")\n print(abs(slices_required))\n final+=slices_required\nif(final>=0):\n print(\"POSSIBLE\")\nelse:\n print(\"IMPOSSIBLE\")\n", "value = 0\r\nval = int(input())\r\nfor i in range(val):\r\n s,n,a,b = list(map(int,input().split()))\r\n sum = a\r\n total=a\r\n n-=1\r\n while(n):\r\n sum = sum * b\r\n total+=sum\r\n n-=1\r\n if(s>=total):\r\n print(\"POSSIBLE \",s-total)\r\n value+=s-total\r\n else:\r\n print(\"IMPOSSIBLE \",total-s)\r\n value-=total-s\r\nif(value>=0):\r\n print(\"POSSIBLE\")\r\nelse:\r\n print(\"IMPOSSIBLE\")\r\n", "import math\r\ntry:\r\n\tt=int(input())\r\n\ttot=0\r\n\tout=[]\r\n\twhile(t):\r\n\t\ts,n,k,r = map(int,input().split())\r\n\t\tkin = k\r\n\r\n\t\ta=[]\r\n\t\ta.append(k)\r\n\r\n\t\tfor i in range(n-1):\r\n\t\t\tk = k*r\r\n\t\t\ta.append(k)\r\n\t\tk = sum(a)\r\n\t# \tk = k - kin\r\n\t# \tprint(k)\r\n\t\tif s>k:\r\n\t\t\t\r\n\t\t\ts=s-k\r\n\t\t\tout.append(f'POSSIBLE {s}')\r\n\t\t\ttot+=s\r\n\t\telse:\r\n\t\t\t\r\n\t\t\ts=k-s\r\n\t\t\tout.append(f'IMPOSSIBLE {s}')\r\n\t\t\ttot-=s\r\n\t\tt-=1\r\n\tfor i in out:\r\n\t\tprint(i)\r\n\tif tot>0:\r\n\t\tprint('POSSIBLE')\r\n\telse:\r\n\t\tprint('IMPOSSIBLE')\r\n\r\nexcept EOFError as e:\r\n print(end=\"\")", "# cook your dish here\n# Let's hack this code.\n\nfrom sys import stdin, stdout\nimport math\nfrom itertools import permutations, combinations\nfrom collections import defaultdict\nfrom bisect import bisect_left \n\nmod = 1000000007\n\ndef L():\n return list(map(int, stdin.readline().split()))\n\ndef In():\n return map(int, stdin.readline().split())\n\ndef I():\n return int(stdin.readline())\n\ndef printIn(ob):\n return stdout.write(str(ob)+'\\n')\n\ndef powerLL(n, p):\n result = 1\n while (p):\n if (p&1):\n result = result * n % mod\n p = int(p / 2)\n n = n * n % mod\n return result\n\n#--------------------------------------\n\ndef myCode():\n ext = 0\n short = 0\n s,n,k,r = In()\n share = k\n dist = k\n for i in range(n-1):\n dist = dist*r\n share = share + dist\n if share <= s:\n ext = s-share\n print(\"POSSIBLE \"+str(ext))\n else:\n short = share-s\n print(\"IMPOSSIBLE \"+str(short))\n \n return ext,short\n\ndef main():\n extra = 0\n shortage = 0\n for t in range(I()):\n e,s = myCode()\n extra +=e\n shortage += s\n if extra >=shortage:\n print(\"POSSIBLE\")\n else:\n print(\"IMPOSSIBLE\")\n \ndef __starting_point():\n main()\n__starting_point()", "list1=[]\r\nt=int(input())\r\nfor i in range(t):\r\n s,n,k,r=list(map(int,input().split()))\r\n p=0\r\n for i in range(n):\r\n a=r**i\r\n p=p+a*k\r\n c=s-p\r\n list1.append(c)\r\n if s>=p:\r\n print(\"POSSIBLE {0}\".format(c)) \r\n else:\r\n print(\"IMPOSSIBLE {0}\".format(abs(c)))\r\ns=0\r\nfor j in range(len(list1)):\r\n s+=list1[j]\r\nif s==0 or s>0:\r\n print(\"POSSIBLE\") \r\nelse:\r\n print(\"IMPOSSIBLE\")\r\n", "# cook your dish here\nt=int(input())\npo=0\nne=0\nfor i in range(t):\n s,n,k,r=list(map(int,input().split()))\n sum=0\n for j in range(n):\n sum=sum+k\n k=k*r\n if(s>=sum):\n remaining_slices=s-sum\n print(\"POSSIBLE\",remaining_slices)\n po=po+remaining_slices\n else:\n remaining_slices=sum-s\n print(\"IMPOSSIBLE\",remaining_slices)\n ne=ne+remaining_slices\n#print(po,ne)\nif(po>=ne):\n print(\"POSSIBLE\")\nelse:\n print(\"IMPOSSIBLE\")\n", "try:\n t=int(input())\n required=0\n avaliable=0\n for i in range(t):\n s,n,k,r=list(map(int,input().strip().split(' ')))\n total=k\n for i in range(n-1):\n total+=k*r\n k=k*r\n if total >s:\n print(\"IMPOSSIBLE\",total-s)\n required+=total-s\n else:\n print(\"POSSIBLE\",s-total)\n avaliable+=s-total\n if required<=avaliable:\n print(\"POSSIBLE\")\n else:\n print(\"IMPOSSIBLE\")\nexcept:\n pass", "T = int(input())\nif (T >= 1 and T <= 50):\n pos = 0\n imp = 0\n for i in range(0, T):\n s, n, k, r = [int(x) for x in input().split()][:4]\n if ((n >= 1 and n <= 15) and (s >= 1 and s <= 10000000000) and (k >= 1 and k <= 5) and (r >= 1 and r <= 5)):\n total = k\n for j in range(0, n - 1):\n k = k * r\n total = total + k\n mid = s - total\n if (total > s):\n imp = imp + abs(mid)\n print('IMPOSSIBLE {}'.format(abs(mid)))\n else:\n pos = pos + abs(mid)\n print('POSSIBLE {}'.format(abs(mid)))\n if (pos > imp):\n print('POSSIBLE')\n else:\n print('IMPOSSIBLE')", "# cook your dish here\nn = int(input())\nsum1 = 0\nsum2= 0\nfor i in range(0,n):\n arr=[]\n \n arr = list(map(int,input().split()))\n lst = [arr[2]]\n for i in range(1,arr[1]):\n a = lst[-1]*arr[3]\n lst.append(a)\n total = sum(lst)\n diff = arr[0] - total\n if diff >=0:\n sum1 = sum1+diff\n print(\"POSSIBLE \"+str(diff))\n else:\n sum2 = sum2+diff\n print(\"IMPOSSIBLE \"+str(abs(diff)))\ncheck = sum1+sum2\nif check>=0:\n \n print(\"POSSIBLE\")\nelse:\n print(\"IMPOSSIBLE\")"]
{"inputs": [["5", "100 4 2 2", "100 4 3 2", "100 4 3 3", "200 4 4 2", "10 3 2 2"]], "outputs": [["POSSIBLE 70", "POSSIBLE 55", "IMPOSSIBLE 20", "POSSIBLE 140", "IMPOSSIBLE 4", "POSSIBLE"]]}
INTERVIEW
PYTHON3
CODECHEF
14,039
81d6ff1d37c96a796cfe8f8cddb088d3
UNKNOWN
You are given a tree rooted at node $1$ with $N$ vertices. The $i$$th$ vertex initially has value $A_i (1 \leq i \leq N)$. You are also given $Q$ queries. In each query you are given a vertex $V$. Let $S = \{ S_1 , S_2 , ... S_x \} $ denote the set of vertices such that $S_i$ is in the subtree of $V$, distance between $S_i$ and $V$ is even and $S_i \neq V$ for all $i$. For all $S_i$ , add $A$$S_i$ to $A_V$ and change the value of $A$$S_i$ to zero. Find the values of all the vertices after all queries are performed. Note-The distance between two vertices is defined as the number of edges traversed on the shortest path from one vertex to the other. -----Input:----- - The first line contains an integer $T$ denoting the number of test cases. - The first line of each test case contain two integers $N$ and $Q$. - The second line contains $N$ space separated integers, $A_1, A_2, ..., A_n$ denoting the initial values of the vertices. - The next $N-1$ lines contain two integers $u$ and $v$ denoting an edge between $u$and $v$. - The next $Q$ lines contain a single integer which is the query. -----Output:----- - Print a single line containing $N$ integers for each test case which is the final values of the vertices. -----Constraints:----- - $1\leq T \leq 10$ - $1 \leq N \leq 200000$ - $1 \leq Q \leq 200000$ - $0 \leq A_i \leq 10^9$ - The sum of $N$ over all test cases does not exceed $200000$. - The sum of $Q$ over all test cases does not exceed $200000$. -----Sample Input----- 1 4 3 6 2 7 3 1 2 2 3 3 4 3 2 1 -----Sample Output----- 13 5 0 0 -----Explanation----- Node $3$ has no child in its subtree which is at an even distance so there is no change in the values. Values of nodes after $1st$ query: $6, 2, 7, 3$. Node $4$ is at an even distance in the subtree of node $2$ so $A_4$ gets added to $A_2$ and $A_4$ becomes 0. Values of nodes after $2nd$ query: $6, 5, 7, 0$. Node $3$ is at an even distance in the subtree of node $1$ so $A_3$ gets added to $A_1$ and $A_3$ becomes 0. Values of nodes after $3rd$ query: $13, 5, 0, 0$.
["from collections import defaultdict as dd,deque as dq\ndef opbfs(u,vis,ll,parr):\n q=dq([(u,0)])\n uu=u\n su=0\n while q:\n \n u,lol=q.pop()\n par=parr[u]\n if(lol%2==0):\n vis[u]=1\n su+=ll[u-1]\n ll[u-1]=0\n for j in d[u]:\n if(j!=par):\n q.appendleft((j,lol+1))\n ll[uu-1]=su\ndef bfs(height,d,parr):\n q=dq([1])\n while q:\n u=q.pop()\n height[u]=height[parr[u]]+1\n for i in d[u]:\n if(i!=parr[u]):\n q.appendleft(i)\n parr[i]=u\nt=int(input())\nwhile t:\n n,q=map(int,input().split())\n ll=list(map(int,input().split()))\n d=dd(list)\n for i in range(n-1):\n u,v=map(int,input().split())\n d[u].append(v)\n d[v].append(u)\n vis=[0]*(n+1)\n l=[]\n height=[0]*(n+1)\n parr=[0]*(n+1)\n bfs(height,d,parr)\n for i in range(q):\n u=int(input())\n l.append((height[u],u,i))\n l.sort()\n vis=[0]*(n+1)\n #print(l)\n for i in l:\n he,u,ind=i\n if(vis[u]==0):\n #print(u)\n opbfs(u,vis,ll,parr)\n print(*ll)\n t-=1"]
{"inputs": [["1", "4 3", "6 2 7 3", "1 2", "2 3", "3 4", "3", "2", "1"]], "outputs": [["13 5 0 0"]]}
INTERVIEW
PYTHON3
CODECHEF
953
47c8a11501f816b111eceacdfd65c675
UNKNOWN
This is probably the simplest problem ever. You just need to count the number of ordered triples of different numbers (X1, X2, X3), where Xi could be any positive integer from 1 to Ni, inclusive (i = 1, 2, 3). No, wait. I forgot to mention that numbers N1, N2, N3 could be up to 1018. Well, in any case it is still quite simple :) By the way, because of this the answer could be quite large. Hence you should output it modulo 109 + 7. That is you need to find the remainder of the division of the number of required triples by 109 + 7. -----Input----- The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows. The only line of each test case contains three space-separated integers N1, N2, N3. -----Output----- For each test case, output a single line containing the number of required triples modulo 109 + 7. -----Constraints----- - 1 ≤ T ≤ 1000 - 1 ≤ Ni ≤ 1018 -----Example----- Input: 5 3 3 3 2 4 2 1 2 3 25 12 2012 1 1 2013 Output: 6 4 1 578880 0 -----Explanation----- Example case 1. We have the following triples composed of different numbers up to 3: (1, 2, 3) (1, 3, 2) (2, 1, 3) (2, 3, 1) (3, 1, 2) (3, 2, 1) Example case 2. Here the triples are: (1, 3, 2) (1, 4, 2) (2, 3, 1) (2, 4, 1) Example case 3. Here the only triple is (1, 2, 3). Example case 4. Merry Christmas! Example case 5. ... and Happy New Year! By the way here the answer is zero since the only choice for X1 and for is X2 is 1, so any such triple will have equal numbers.
["d=1000000007\nfor _ in range(int(input())):\n l=sorted(list(map(int,input().split())))\n ans=(l[0]%d)*((l[1]-1)%d)*((l[2]-2)%d)\n print(ans%d)", "# cook your dish here\nfor _ in range(int(input())):\n a=[int(x) for x in input().split()]\n a.sort()\n m=(10**9+7)\n print((a[0]*(a[1]-1)*(a[2]-2))%m)", "for _ in range(int(input())):\n a=[int(x) for x in input().split()]\n p=1\n d=0\n a.sort()\n mod=(10**9)+7\n for v in a:\n p=(p*(v-d))%mod\n d+=1\n print(p%mod)", "# cook your dish here\nmod=1000000007\nfor _ in range(int(input())):\n arr=list(map(int,input().split()))\n arr.sort()\n print((arr[0]*(arr[1]-1)*(arr[2]-2))%mod)", "T = int(input())\nans = []\n\nm = 10**9 + 7\n\nfor _ in range(T):\n N = [int(i) for i in input().split()]\n\n N.sort()\n ans.append( ((N[0]%m)*((N[1]-1)%m)*((N[2]-2)%m))%m )\n\nfor i in ans:\n print(i)\n", "for _ in range(int(input())):\n a,b,c = sorted(map(int,input().split()))\n ans = a*(b-1)*(c-2)\n print(ans%(10**9+7) if ans>0 else 0)", "try:\n for i in range(int(input())):\n l=list(map(int,input().split()))\n l.sort()\n m=1\n a=l[0]\n b=l[1]\n c=l[2]\n ans=a*(b-1)*(c-2)\n print(ans% ((10**9)+7))\nexcept:\n pass", "m = 10**9 + 7\nt=int(input())\nfor i in range(t):\n ls = list(map(int,input().split()))\n ls.sort()\n print( (ls[0]*(ls[1]-1)*(ls[2]-2 ))%m)", "m = 10**9 + 7\nfor _ in range(int(input())):\n n1,n2,n3 = list(map(int,input().split()))\n ls = [n1,n2,n3]\n ls.sort()\n print( (ls[0]*(ls[1]-1)*(ls[2]-2 ))%m)\n #three different numbers\n", "for _ in range(int(input())):\n N = list(map(int, input().split()))\n N.sort()\n N1, N2, N3 = N[0], N[1], N[2]\n M = 10**9 + 7\n ans = ((((N1 % M) * ((N2-1) % M)) % M) * (N3-2) % M) % M\n print(ans)", "# cook your dish here\nfor _ in range(int(input())):\n l=list(map(int,input().split()))\n l.sort()\n print((l[0]*(l[1]-1)*(l[2]-2))%1000000007)\n \n", "# cook your dish here\nfor _ in range(int(input())):\n \n l=list(map(int, input().split()))\n l.sort()\n \n print((l[0]*(l[1]-1)*(l[2]-2))%1000000007)", "\nmo=1000000007\n\nfor _ in range(int(input())):\n l=list(map(int,input().split()))\n l.sort()\n print((l[0]*((l[1]-1)%mo)*((l[2]-2)%mo))%mo)", "# cook your dish here\ntry:\n t = int(input())\n for jdnkjdew in range(t):\n arr = list(map(int,input().split()))\n arr.sort()\n a = arr[0]*(arr[1]-1)*(arr[2]-2)\n a %= 1000000007\n print(a)\nexcept:\n pass", "try:\n t = int(input())\n for jdnkjdew in range(t):\n arr = list(map(int,input().split()))\n arr.sort()\n a = arr[0]*(arr[1]-1)*(arr[2]-2)\n a %= 1000000007\n print(a)\nexcept:\n pass", "# cook your dish here\nfor _ in range(int(input())):\n l=list(map(int,input().split()))\n mod=10**9+7\n l.sort()\n ans=(l[0]%mod)*((l[1]-1)%mod)*((l[2]-2)%mod)\n print(ans%mod)", "# cook your dish here\nfor _ in range(int(input())):\n\n #n=int(input())\n r=[int(x) for x in input().split()]\n a,b,c=sorted(r)\n print((a*(b-1)*(c-2))%1000000007)\n", "mod = 10**9+7\nfor _ in range(int(input())):\n l = list(map(int, input().split()))\n l.sort()\n m = l[0]*(l[1]-1)*(l[2]-2)\n print(m % mod)\n", "# cook your dish here\ng=10**9+7\nfor _ in range(int(input())):\n l=list(map(int,input().split()))\n l.sort()\n m=l[0]*(l[1]-1)*(l[2]-2)\n print(m%g)\n", "test = int(input())\nfor _ in range(test):\n array = list(map(int, input().split()))\n array.sort()\n mod = 1000000007\n answer = (array[0])*((array[1]-1))*((array[2]-2))\n if answer<=0:\n print(0)\n else:\n print(answer%mod)", "#\nc = 10**9 + 7\nfor i in range(int(input())):\n arr = list(map(int,input().split()))\n arr.sort()\n ans = arr[0]*(arr[1]-1)*(arr[2]-2)\n \n print(ans%c)\n \n", "# cook your dish here\nfor i in range(int(input())):\n l=list(map(int,input().split(' ')))\n l.sort()\n print((l[0]*(l[1]-1)*(l[2]-2))%1000000007)\n"]
{"inputs": [["5", "3 3 3", "2 4 2", "1 2 3", "25 12 2012", "1 1 2013"]], "outputs": [["6", "4", "1", "578880", "0"]]}
INTERVIEW
PYTHON3
CODECHEF
3,758
0119e9b8288b989b982f0cba6d7d8dbe
UNKNOWN
Chef recently learned about concept of periodicity of strings. A string is said to have a period P, if P divides N and for each i, the i-th of character of the string is same as i-Pth character (provided it exists), e.g. "abab" has a period P = 2, It also has a period of P = 4, but it doesn't have a period of 1 or 3. Chef wants to construct a string of length N that is a palindrome and has a period P. It's guaranteed that N is divisible by P. This string can only contain character 'a' or 'b'. Chef doesn't like the strings that contain all a's or all b's. Given the values of N, P, can you construct one such palindromic string that Chef likes? If it's impossible to do so, output "impossible" (without quotes) -----Input----- The first line of the input contains an integer T denoting the number of test cases. The only line of each test case contains two space separated integers N, P. -----Output----- For each test case, output a single line containing the answer of the problem, i.e. the valid string if it exists otherwise "impossible" (without quotes). If there are more than possible answers, you can output any. -----Constraints----- - 1 ≤ T ≤ 20 - 1 ≤ P, N ≤ 105 -----Subtasks----- - Subtask #1 (25 points) : P = N - Subtask #2 (75 points) : No additional constraints -----Example----- Input 5 3 1 2 2 3 3 4 4 6 3 Output impossible impossible aba abba abaaba -----Explanation----- Example 1: The only strings possible are either aaa or bbb, which Chef doesn't like. So, the answer is impossible. Example 2: There are four possible strings, aa, ab, ba, bb. Only aa and bb are palindromic, but Chef doesn't like these strings. Hence, the answer is impossible. Example 4: The string abba is a palindrome and has a period of 4. Example 5: The string abaaba is a palindrome and has a period of length 3.
["T=int(input())\nfor i in range(T):\n n,m=list(map(int,input().split()))\n if(m<=2):\n print(\"impossible\")\n else:\n l=[0]*m\n\n if(m%2==0):\n a=m//2\n else:\n a=(m//2)+1\n for j in range(a):\n if(j%2==0):\n l[j]=\"a\"\n l[m-j-1]=\"a\"\n \n else:\n l[j]=\"b\"\n l[m-j-1]=\"b\"\n \n \n r=\"\"\n s=n//m\n for e in l:\n r=r+e\n print(r*s)\n \n \n\n", "T=int(input())\nfor i in range(T):\n n,m=list(map(int,input().split()))\n if(m<=2):\n print(\"impossible\")\n else:\n l=[0]*m\n\n if(m%2==0):\n a=m//2\n else:\n a=(m//2)+1\n for j in range(a):\n if(j%2==0):\n l[j]=\"a\"\n l[m-j-1]=\"a\"\n \n else:\n l[j]=\"b\"\n l[m-j-1]=\"b\"\n \n \n r=\"\"\n s=n//m\n for e in l:\n r=r+e\n print(r*s)\n \n \n\n", "t = int(input())\nfor i in range(t):\n n, p= list(map(int, input().split()))\n if p == 1 or p == 2:\n print('impossible')\n else:\n s = ''\n if p%2 == 0:\n s = 'a' + 'b'*(p-2) + 'a'\n s = s*(n//p)\n else:\n s = 'a'*(p//2) + 'b' + 'a'*(p//2)\n s = s*(n//p)\n print(s)\n", "for _ in range(int(input())):\n n,p=list(map(int,input().split()))\n\n a=[]\n ans=0\n\n if n%p!=0 or p==1 or p==2:\n ans+=1\n\n if n==p:\n a=['a']*n\n\n if n%2==0:\n a[n//2]='b'\n a[n//2-1]='b'\n else:\n a[n//2]='b'\n\n else:\n if p%3==0:\n k=n//3\n for i in range(k):\n a.append('aba')\n\n elif p%4==0:\n k=n//4\n for i in range(k):\n a.append('abba')\n\n else:\n a=['a']*n\n\n if p%2==0:\n for i in range(n//p):\n a[p//2+i*p]='b'\n a[p//2+i*p-1]='b'\n\n else:\n for i in range(n//p):\n a[p//2+i*p]='b'\n \n\n if ans>0:\n print('impossible')\n else:\n print(''.join(a))\n \n\n\n\n", "for _ in range(int(input())):\n n,p=map(int,input().split())\n if p>=n:\n if n==1 or n==2:\n print('impossible')\n else:\n print('a'+'b'*(n-2)+'a')\n else:\n if n%p!=0:\n print('impossible')\n else:\n if p==1 or p==2:\n print('impossible')\n else:\n s='a'+'b'*(p-2)+'a'\n print(s*(n//p))", "t = int(input())\nwhile(t>0):\n t-=1\n n,p = [int(x) for x in input().split()]\n if(p <= 2):\n print('impossible')\n continue\n else:\n s = 'a' + ('b'*(p-2)) + 'a'\n s = s*int(n/p)\n print(s)"]
{"inputs": [["5", "3 1", "2 2", "3 3", "4 4", "6 3"]], "outputs": [["impossible", "impossible", "aba", "abba", "abaaba"]]}
INTERVIEW
PYTHON3
CODECHEF
2,351
9e702c9e6de83cd372d6eea9887d37b2
UNKNOWN
Chef has some numbers. His girlfriend Chefina feels good when chef gives her a particular pattern number also called as Armstrong number. Armstrong number is a number whose sum of its all individual digit raise to the power of the number of digit in that number is equal to that number itself eg.. 153 = 1^3 + 5^3 + 3^3 (153 is an Armstrong number) 1634 = 1^4 + 6^4 + 3^4 + 4^4 (1634 is an Armstrong number) As a love guru of chef you have to help chef to find Armstrong numbers Among the numbers which chef has initially so that Chefina feels good -----Input:----- First line will contain a positive Integer $T$ which is the number of testcases Next $T$ lines follows an Integer $N$. -----Output:----- For Every n You have to print "FEELS GOOD" without qoutes if it is an armstrong number otherwise Print "FEELS BAD" without quotes -----Constraints----- - $1 \leq T \leq 10$ - $2 \leq N \leq 10^6$ -----Sample Input:----- 3 153 11 1634 -----Sample Output:----- FEELS GOOD FEELS BAD FEELS GOOD -----EXPLANATION:----- For test case 1 --> 153 = 1^3 + 5^3 + 3^3 (153 is an armstrong number)
["def power(x, y):\n\tif y == 0:\n\t\treturn 1\n\tif y % 2 == 0:\n\t\treturn power(x, y // 2) * power(x, y // 2)\n\n\treturn x * power(x, y // 2) * power(x, y // 2)\n\n\n# Function to calculate order of the number\ndef order(x):\n\t# Variable to store of the number\n\tn = 0\n\twhile (x != 0):\n\t\tn = n + 1\n\t\tx = x // 10\n\n\treturn n\n\n\n# Function to check whether the given\n# number is Armstrong number or not\ndef isArmstrong(x):\n\tn = order(x)\n\ttemp = x\n\tsum1 = 0\n\n\twhile (temp != 0):\n\t\tr = temp % 10\n\t\tsum1 = sum1 + power(r, n)\n\t\ttemp = temp // 10\n\n\t# If condition satisfies\n\treturn (sum1 == x)\n\n\n# Driver code\n\nfor _ in range(int(input())):\n\tnum = int(input())\n\tif isArmstrong(num):\n\t\tprint(\"FEELS GOOD\")\n\telse:\n\t\tprint(\"FEELS BAD\")", "# cook your dish here\nt=int(input())\ndef dig(a):\n c=0\n i=a\n while i>0:\n c=c+1\n i=i//10\n \n return c\ndef sums(a,b):\n s=0\n i=a\n while i>0:\n s=s+pow(i%10,b)\n i=i//10\n return s\nfor i in range(t):\n a=int(input())\n b=dig(a)\n if int(sums(a,b))==a:\n print(\"FEELS GOOD\")\n else:\n print(\"FEELS BAD\")", "# cook your dish here\nt=int(input())\ndef dig(a):\n c=0\n i=a\n while i>0:\n c=c+1\n i=i//10\n \n return c\ndef sums(a,b):\n s=0\n i=a\n while i>0:\n s=s+pow(i%10,b)\n i=i//10\n return s\nfor i in range(t):\n a=int(input())\n b=dig(a)\n if int(sums(a,b))==a:\n print(\"FEELS GOOD\")\n else:\n print(\"FEELS BAD\")", "t=int(input())\r\nfor i in range(t):\r\n \r\n n = int(input()) \r\n p = len(str(n)) \r\n s = 0 \r\n k = n \r\n while k>0: \r\n d = k%10 \r\n s = s + (d**p) \r\n k = k//10 \r\n if n == s: \r\n print(\"FEELS GOOD\") \r\n else: \r\n print(\"FEELS BAD\")", "t=int(input())\nfor i in range(1,t+1):\n num=int(input())\n n=str(num)\n sum=0\n temp=num\n while temp>0:\n dg=temp%10\n sum+=dg**len(n)\n temp//=10\n if num==sum:\n print(\"FEELS GOOD\")\n else:\n print(\"FEELS BAD\")\n", "T = int(input())\n\nwhile T>0:\n Out =0\n summ =0\n Res =0\n N = int(input())\n M = N\n leng = len(str(N))\n \n for i in range (0,leng):\n Res = N%10\n Out= pow(Res,leng)\n summ = summ+ Out\n N = N//10\n if summ == M:\n print(\"FEELS GOOD\")\n else:\n print(\"FEELS BAD\")\n T = T-1\n", "# cook your dish here\nt=int(input())\nfor i in range(1,t+1):\n num=int(input())\n n=str(num)\n sum = 0\n temp = num\n while temp > 0:\n digit = temp % 10\n sum += digit ** len(n)\n temp //= 10\n\n if num == sum:\n print(\"FEELS GOOD\")\n else:\n print(\"FEELS BAD\")\n \n", "for _ in range(int(input())):\n n=int(input())\n x=len(str(n))\n t,s=n,0\n while(n):\n s+=(n%10)**x\n n//=10\n if t==s:\n print('FEELS GOOD')\n else:\n print('FEELS BAD')\n", "# cook your dish here\nt=int(input())\ndef dig(a):\n c=0\n i=a\n while i>0:\n c=c+1\n i=i//10\n \n return c\ndef sums(a,b):\n s=0\n i=a\n while i>0:\n s=s+pow(i%10,b)\n i=i//10\n return s\nfor i in range(t):\n a=int(input())\n b=dig(a)\n if int(sums(a,b))==a:\n print(\"FEELS GOOD\")\n else:\n print(\"FEELS BAD\")\n2", "# cook your dish her\nfor _ in range(int(input())):\n num = int(input())\n s = 0\n temp = num\n while temp > 0:\n digit = temp % 10\n s += digit ** len(str(num))\n temp //= 10\n \n if num == s:\n print(\"FEELS GOOD\")\n else:\n print(\"FEELS BAD\")", "# cook your dish here\n# cook your dish here\nfor nt in range(int(input())):\n num = int(input()) \n sum = 0 \n temp = num \n r=len(str(num))\n while temp > 0:\n digit = temp % 10 \n sum += digit ** r \n temp //= 10 \n \n if num == sum:\n print(\"FEELS GOOD\") \n else:\n print(\"FEELS BAD\") ", "import math\nfor _ in range(int(input())):\n N = int(input())\n D = math.floor(math.log(N, 10)) + 1\n \n T = N\n R = 0\n while(T>0):\n M = T%10\n T = T//10\n R += pow(M, D)\n \n if R == N:\n print(\"FEELS GOOD\")\n else:\n print(\"FEELS BAD\")", "def arm(n):\r\n sum=0\r\n l=len(str(n))\r\n m=n\r\n while n!=0:\r\n sum+=(n%10)**l\r\n n//=10\r\n if sum==m:\r\n return \"FEELS GOOD\"\r\n else:\r\n return \"FEELS BAD\"\r\n\r\nt=int(input())\r\nl=[]\r\nfor i in range(t):\r\n l.append(arm(int(input())))\r\nfor i in l:\r\n print(i)\r\n\r\n", "\nN = int(input())\nfor i in range(N):\n i = int(input())\n x = i % 10\n add = 0\n z = 0\n temp = i\n while temp != 0:\n temp //= 10\n z += 1\n temp = i\n for j in range(z):\n temp = temp // 10\n add += x ** z\n x = temp % 10\n if add == i:\n print(\"FEELS GOOD\")\n else:\n print(\"FEELS BAD\")", "tc=int(input())\nfor i in range(tc):\n n=int(input())\n m=str(n)\n length=len(m)\n m=[int(i) for i in m]\n sum=0\n for j in m:\n sum+=j**length\n \n if sum==n:\n print(\"FEELS GOOD\")\n else:\n print(\"FEELS BAD\")", "for i in range(int(input())):\n n = int(input())\n sum = 0\n t = n\n while t > 0:\n digit = t % 10\n sum += digit ** len(str(n))\n t //= 10\n if(n==sum):\n print(\"FEELS GOOD\")\n else:\n print(\"FEELS BAD\")", "# cook your dish here\nn=int(input())\nfor i in range(n):\n m=int(input())\n l=list(map(int,str(m)))\n sum=0\n for j in range(len(l)):\n sum=sum+pow(l[j],len(l))\n if sum==m:\n print('FEELS GOOD')\n else:\n print('FEELS BAD')", "# cook your dish here\nfor _ in range(int(input())):\n n=int(input())\n k=n\n s=str(n)\n l=len(s)\n su=0\n while k!=0:\n su+=(k%10)**l\n k=k//10\n if su==n:\n print(\"FEELS GOOD\")\n else:\n print(\"FEELS BAD\")", "t=int(input())\nfor _ in range(t):\n x=int(input())\n l=len(str(x))\n sum=0\n for i in str(x):\n sum=sum+int(i)**int(l)\n if sum==x:\n print(\"FEELS GOOD\")\n else:\n print(\"FEELS BAD\")", "# cook your dish here\nt=int(input())\nfor w in range(t):\n n=int(input())\n m=n\n sm=digit=0\n while n>0:\n n=n//10\n digit+=1\n n=m\n while m>0:\n a=m%10\n sm=sm+a**digit\n m=m//10\n if n==sm:\n print('FEELS GOOD')\n else:\n print('FEELS BAD')", "for _ in range(int(input())):\r\n num = int(input())\r\n order = len(str(num))\r\n suma = 0\r\n temp = num\r\n while temp > 0:\r\n digit = temp % 10\r\n suma += digit ** order\r\n temp //= 10\r\n if num == suma:\r\n print(\"FEELS GOOD\")\r\n else:\r\n print(\"FEELS BAD\")\r\n", "# cook your dish here\ndef check(n):\n s=str(n)\n l=len(s)\n add=0\n for i in range(l):\n add=add+(int(s[i])**l)\n if add==n:\n return 1\n else:\n return 0\n\ndef __starting_point():\n for _ in range(int(input())):\n n=int(input())\n if check(n):\n print(\"FEELS GOOD\")\n else:\n print(\"FEELS BAD\")\n__starting_point()", "# cook your dish here\nfor _ in range(int(input())):\n num = int(input())\n num_original =num2=num\n sum1 = 0\n cnt=0\n \n while(num>0):\n \tcnt=cnt+1\n \tnum=num//10\n \n while num2>0:\n rem = num2% 10\n sum1 += rem ** cnt\n num2//= 10\n \n \n if(num_original==sum1):\n print(\"FEELS GOOD\")\n else:\n print(\"FEELS BAD\")\n \n \n \n \n", "# cook your dish here\nfor a0 in range(int(input())):\n n = int(input())\n l = list(str(n))\n q = len(l)\n s = 0\n for i in l:\n s+= int(i)**q\n if s == n:\n print(\"FEELS GOOD\")\n else:\n print(\"FEELS BAD\")\n \n", "t=int(input())\r\nfor i in range(0,t):\r\n\r\n num = int(input())\r\n\r\n order = len(str(num))\r\n\r\n sum = 0\r\n\r\n temp = num\r\n while temp > 0:\r\n digit = temp % 10\r\n sum += digit ** order\r\n temp //= 10\r\n\r\n if num == sum:\r\n print(\"FEELS GOOD\")\r\n else:\r\n print(\"FEELS BAD\")"]
{"inputs": [["3", "153", "11", "1634"]], "outputs": [["FEELS GOOD", "FEELS BAD", "FEELS GOOD"]]}
INTERVIEW
PYTHON3
CODECHEF
9,077
62404f1e591b768914beb2c93d5df709
UNKNOWN
After a long and successful day of preparing food for the banquet, it is time to clean up. There is a list of n jobs to do before the kitchen can be closed for the night. These jobs are indexed from 1 to n. Most of the cooks have already left and only the Chef and his assistant are left to clean up. Thankfully, some of the cooks took care of some of the jobs before they left so only a subset of the n jobs remain. The Chef and his assistant divide up the remaining jobs in the following manner. The Chef takes the unfinished job with least index, the assistant takes the unfinished job with the second least index, the Chef takes the unfinished job with the third least index, etc. That is, if the unfinished jobs were listed in increasing order of their index then the Chef would take every other one starting with the first job in the list and the assistant would take every other one starting with the second job on in the list. The cooks logged which jobs they finished before they left. Unfortunately, these jobs were not recorded in any particular order. Given an unsorted list of finished jobs, you are to determine which jobs the Chef must complete and which jobs his assitant must complete before closing the kitchen for the evening. -----Input----- The first line contains a single integer T ≤ 50 indicating the number of test cases to follow. Each test case consists of two lines. The first line contains two numbers n,m satisfying 0 ≤ m ≤ n ≤ 1000. Here, n is the total number of jobs that must be completed before closing and m is the number of jobs that have already been completed. The second line contains a list of m distinct integers between 1 and n. These are the indices of the jobs that have already been completed. Consecutive integers are separated by a single space. -----Output----- The output for each test case consists of two lines. The first line is a list of the indices of the jobs assigned to the Chef. The second line is a list of the indices of the jobs assigned to his assistant. Both lists must appear in increasing order of indices and consecutive integers should be separated by a single space. If either the Chef or the assistant is not assigned any jobs, then their corresponding line should be blank. -----Example----- Input: 3 6 3 2 4 1 3 2 3 2 8 2 3 8 Output: 3 6 5 1 1 4 6 2 5 7
["T = int(input())\nfor _ in range(T):\n n,m = map(int,input().split())\n completed = list(map(int,input().split()))\n jobs = []\n for i in range(1,n+1):\n if i not in completed:\n jobs.append(i)\n jobs.sort()\n chef = []\n ass = []\n for i in range(len(jobs)):\n if i%2==0:\n chef.append(str(jobs[i]))\n else:\n ass.append(str(jobs[i]))\n print(' '.join(chef))\n print(' '.join(ass))", "def work(n, m, completed):\n chef = []\n asst = []\n total_jobs = list(range(1,n+1))\n pending = [value for value in total_jobs if value not in completed]\n for k in range(len(pending)):\n if k % 2 == 0:\n chef.append(pending[k])\n else:\n asst.append(pending[k])\n\n return chef, asst\n\ndef main():\n T = int(input())\n for t in range(T):\n jobs = input().split()\n n = int(jobs[0])\n m = int(jobs[1])\n completed = sorted(list(map(int, input().split())))\n\n chef, asst = work(n, m, completed)\n for j in chef:\n print(j, end=\" \")\n print()\n for k in asst:\n print(k, end=\" \")\n print()\n\n\ndef __starting_point():\n main()\n\n__starting_point()", "# cook your dish here\ndef work(a):\n chef = []\n asst = []\n c = True\n t = False\n for i in range(1, len(a)):\n if a[i] != 1:\n if c:\n chef.append(i)\n c = False\n t = True\n else:\n asst.append(i)\n t = False\n c = True\n return chef, asst\n\n\nt = int(input())\nwhile t:\n n, m = [int(k) for k in input().split()]\n a = [0] * (n + 1)\n finished = [int(k) for k in input().split()]\n for i in finished:\n a[i] = 1\n chef, asst = work(a)\n for i in chef:\n print(i,end =' ')\n print()\n for i in asst:\n print(i,end = ' ')\n print()\n t-=1", "# cook your dish here\nt = int(input())\nfor _ in range(t):\n n, m = map(int, input().strip().split())\n arr = list(map(int, input().strip().split()))\n \n not_done = [i for i in range(1, n+1) if i not in arr]\n chef = [not_done[i] for i in range(len(not_done)) if i % 2 == 0]\n assis = [not_done[i] for i in range(len(not_done)) if i % 2 == 1]\n print(*chef)\n print(*assis)", "# cook your dish here\nt = int(input())\nfor i in range(t):\n n,m = map(int,input().split())\n done_task = list(map(int,input().split()))\n done_task.sort()\n left_tasks=[]\n chef=[]\n assist=[]\n for i in range(n):\n if i+1 not in done_task:\n left_tasks.append(i+1)\n for i in range(n-m):\n if i%2==0:\n chef.append(left_tasks[i])\n else:\n assist.append(left_tasks[i])\n print(*chef)\n print(*assist)", "def solve():\n t=int(input())\n for _ in range(t):\n n,m=[int(x) for x in input().split()]\n cmpl = [int(x) for x in input().split()]\n uncmpl = [i for i in range(1,n+1) if i not in cmpl]\n l1=[]\n l2=[]\n for i in range(len(uncmpl)):\n if i&1==0:\n l1.append(uncmpl[i])\n else:\n l2.append(uncmpl[i])\n print(*l1)\n print(*l2)\n\n# import sys\n# def fast():\n# sys.stdin = open(\"input.txt\", \"r\")\n# sys.stdout = open(\"output.txt\", \"w\")\n# fast()\nsolve()", "for _ in range(int(input())):\n n,m = map(int,input().split())\n list1 = list(map(int,input().split()))\n list1.sort()\n list2 = [i for i in range(1,n+1) if not i in list1]\n list2.sort()\n cheflist = [list2[i] for i in range(len(list2)) if i%2 == 0]\n asslist = [list2[i] for i in range(len(list2)) if i%2 != 0]\n str1 = \"\"\n str2 = \"\"\n for i in cheflist:\n if i == cheflist[len(cheflist)-1]:\n str1 += str(i)\n\n else:\n str1 += str(i) + \" \"\n\n for i in asslist:\n if i == cheflist[len(cheflist)-1]:\n str2 += str(i)\n\n else:\n str2 += str(i) + \" \"\n\n print(str1)\n print(str2)", "T=int(input())\nfor i in range(T):\n N,K=map(int,input().split())\n L=list(map(int,input().split()))[:K]\n A,C,D=[],[],[]\n for j in range(1,N+1):\n if j not in L:\n A.append(j)\n for k in range(len(A)):\n if k % 2 == 0:\n C.append(A[k])\n else:\n D.append(A[k])\n for j in C:\n print(j,end=\" \")\n print()\n for k in D:\n print(k,end=\" \")\n print()", "t=int(input())\nfor _ in range(t):\n a,b=map(int,input().split())\n c = [int(i) for i in input().split()]\n d= [int(i) for i in range(1,a+1)]\n d=list(set(d) - set(c))\n d.sort()\n j=0\n while(j<len(d)):\n print(d[j],end=\" \")\n j+=2\n j=1\n print()\n while(j<len(d)):\n print(d[j],end=\" \")\n j+=2\n print()", "# cook your dish here\nT = int(input())\n\nwhile T:\n T -= 1\n totalJobs, completedJobs = map(int, input().split())\n iJobs = [] # incompleted jobs\n cJobs = [] # complete jobs\n chef = []\n assistant = []\n \n cJobs = [int(i) for i in input().split()]\n for i in range(1, totalJobs + 1):\n if i not in cJobs:\n iJobs.append(i)\n iJobs.sort()\n \n for i in range(len(iJobs)):\n if i % 2 == 0:\n chef.append(iJobs[i])\n else:\n assistant.append(iJobs[i])\n print(' '.join([str(i) for i in chef]))\n print(' '.join([str(i) for i in assistant]))", "# cook your dish here\nfor _ in range(int(input())):\n n,m=map(int,input().split())\n lm=[int(item) for item in input().split()]\n l=[item for item in range(1,n+1)]\n for i in lm:\n l.remove(i)\n l.sort()\n list_chef=list()\n list_assistant=list()\n for i in range(0,len(l),2):\n list_chef.append(l[i])\n for i in range(1,len(l),2):\n list_assistant.append(l[i])\n print(*list_chef)\n print(*list_assistant)", "T=int(input())\nfor i in range(T):\n N,K=map(int,input().split())\n L=list(map(int,input().split()))[:K]\n A,C,D=[],[],[]\n for j in range(1,N+1):\n if j not in L:\n A.append(j)\n for k in range(len(A)):\n if k % 2 == 0:\n C.append(A[k])\n else:\n D.append(A[k])\n for j in C:\n print(j,end=\" \")\n print()\n for k in D:\n print(k,end=\" \")\n print()\n \n \n ", "for _ in range(int(input())):\n n, m = map(int, input().split())\n\n mLi = list(map(int, input().split()))\n nLi = [i for i in range(1, n + 1) if i not in mLi]\n x = []\n y = []\n for j in range(len(nLi)):\n if j % 2 == 0:\n x.append(nLi[j])\n else:\n y.append(nLi[j])\n \n print(*x, sep = \" \")\n print(*y, sep = \" \")", "# cook your dish here\nfor i in range(int(input())):\n n,m=[int(i) for i in input().split()]\n l=list(map(int,input().split()))\n g=[]\n for i in range(1,n+1):\n g.append(i)\n un = [each for each in g if each not in l]\n chef = un[::2]\n ass = un[1::2]\n print(*chef)\n print(*ass)\n \n \n \n", "t = int(input())\nwhile t:\n n,m = [int(x) for x in input().split()]\n job_done = [int(x) for x in input().split()]\n li = []\n for i in range(1,n+1):\n if i not in job_done:\n li.append(i)\n chef = []\n assis = []\n for i in range(len(li)):\n if i&1: \n assis.append(li[i])\n else:\n chef.append(li[i])\n \n print(*chef)\n print(*assis)\n t=t-1", "n=int(input())\nfor _ in range(n):\n c,a=[],[]\n tot=list(map(int,input().split()))\n done=list(map(int,input().split()))\n for i in range(1,tot[0]+1):\n if i in done:\n continue\n else:\n if len(c)<=len(a):\n c.append(i)\n else:\n a.append(i)\n c.sort()\n a.sort()\n for j in c:\n print(j,end=\" \")\n print()\n for k in a:\n print(k,end=\" \")\n print()", "T = int(input())\n\nfor i in range(T):\n (n, m) = map(int, input().split())\n \n jobsList = []\n \n for j in range(n):\n jobsList.append(j + 1)\n \n jobsDone = list(map(int, input().split()))\n \n for k in range(m):\n jobsList.remove(jobsDone[k])\n \n l = 0\n p = 1\n \n jobsA = []\n jobsB = []\n \n while l < len(jobsList):\n jobsA.append(jobsList[l])\n \n l += 2;\n \n while p < len(jobsList):\n jobsB.append(jobsList[p])\n \n p += 2\n \n for q in range(len(jobsA)):\n print(jobsA[q], end = ' ')\n \n print()\n \n for r in range(len(jobsB)):\n print(jobsB[r], end = ' ')\n \n print()", "t=int(input())\nfor i in range(t):\n b=[]\n n,m=input().split()\n n,m=int(n),int(m)\n a=input().split()\n for j in range(m):\n a[j]=int(a[j])\n \n p=1\n while(p<=n):\n if (p not in a):\n b.append(p)\n p=p+1\n else:\n p=p+1\n \n for j in range(0,len(b),2):\n print(b[j],end=' ')\n \n print()\n for j in range(1,len(b),2):\n \n print(b[j],end=' ')\n print()", "# cook your dish here\nt = int(input())\nfor _ in range(t):\n n,m = map(int,input().split())\n mlst = list(map(int,input().split()))\n lst = []\n chef = []\n ass = []\n mlst.sort()\n for i in range(1,n+1):\n if i not in mlst:\n lst.append(i)\n for j in range(1,len(lst)+1):\n if(j%2!=0):\n # chef.append(lst[j-1])\n print(lst[j-1],end=' ')\n else:\n ass.append(lst[j-1])\n # print(lst[j-1],end=' ')\n print()\n print(*ass, sep=' ')\n", "import sys\nimport math\nfrom collections import *\nfrom itertools import *\n\ndef int_arr():return list(map(int,sys.stdin.readline().strip().split()))\ndef str_arr():return list(map(int,sys.stdin.readline().strip().split()))\ndef get_int():return map(int, sys.stdin.readline().strip().split())\ndef get_str():return map(str, sys.stdin.readline().strip().split())\n \n\nmod = 10**9+7\nsys.setrecursionlimit(10**9)\n\ndef solve(n,m,lis):\n arr = [i for i in range(1,n+1) if i not in lis]\n chef = arr[::2]\n ass = arr[1::2]\n print(*chef,end=' ')\n print()\n print(*ass,end = ' ')\n print()\n\nfor _ in range(int(input())):\n n,m = get_int()\n cleaned = int_arr()\n solve(n,m,cleaned)", "test_cases = int(input())\nfor i in range(test_cases):\n chefList = []\n assistantList = []\n n,m = map(int, input().split())\n jobsCompleted = set(map(int, input().split()))\n totalJobs = set(range(1,n+1))\n remainingJobs = list(totalJobs - jobsCompleted)\n remainingJobs.sort()\n for j in range(len(remainingJobs)):\n if j%2==0:\n chefList.append(remainingJobs[j])\n else:\n assistantList.append(remainingJobs[j])\n print(*chefList)\n print(*assistantList)", "import sys\nfrom math import * \nfrom collections import *\nfrom itertools import *\n\ndef int_arr():return list(map(int,input().split()))\ndef str_arr():return list(map(str,input().split()))\ndef two_int():return map(int,input().split())\ndef two_str():return map(str,input().split())\n\nmod = 10**9+7\nsys.setrecursionlimit(10**9)\n\ndef solve(n,c,lis):\n arr = [i for i in range(1,n+1) if i not in lis]\n chef = arr[::2]\n ass = arr[1::2]\n print(*chef,end=' ')\n print()\n print(*ass,end = ' ')\n print()\n\n\nfor _ in range(int(input())):\n n,c = map(int,input().split())\n lis = int_arr()\n solve(n,c,lis)\n", "for _ in range(int(input())):\n [n,m] = [int(i) for i in input().split()]\n l = sorted([int(i) for i in input().split()])\n tempI = 1\n aI = 0\n temp = []\n while(tempI <= n): \n if (aI < m) and (tempI == l[aI]):\n aI += 1\n tempI += 1\n continue\n temp.append(tempI)\n tempI += 1\n #print(temp)\n if(n-m) <= 0:\n print()\n print()\n continue\n if(n - m) == 1 :\n print(temp[0])\n print()\n continue\n for i in range(0,n - m, 2):\n print(temp[i], end = \" \")\n print()\n for i in range(1, n - m, 2):\n print(temp[i],end = \" \")\n print()"]
{"inputs": [["3", "6 3", "2 4 1", "3 2", "3 2", "8 2", "3 8"]], "outputs": [["3 6", "5", "1", "1 4 6", "2 5 7"]]}
INTERVIEW
PYTHON3
CODECHEF
10,696
957d32c40d2ef32aee67219b83e7ab23
UNKNOWN
Let's consider a rooted binary tree with the following properties: - The number of nodes and edges in the tree is infinite - The tree root is labeled by $1$ - A node labeled by $v$ has two children: $2 \cdot v$ (the left child of $v$), and $2 \cdot v + 1$ (the right child of $v$). Here is an image of the first several layers of such a tree: Let's consider four operations that you are allowed to apply during the tree traversal: - move to the left child - move from $v$ to $2 \cdot v$ - move to the right child - move from $v$ to $2 \cdot v + 1$ - move to the parent as a left child - move from $v$ to $\frac{v}{2}$ if $v$ is an even integer - move to the parent as a right child - move from $v$ to $\frac{v - 1}{2}$ if $v$ is an odd integer It can be proven, that for any pair of nodes $u$ and $v$, there is only one sequence of commands that moves from $u$ to $v$ and visits each node of the tree at most once. Let's call such a sequence of commands a path configuration for a pair of nodes $(u, v)$. You are asked to process a series of the following queries: You are given three integers $n$, $u$ and $v$ ($1 \leq u, v \leq n$). Count the pairs of nodes $(w, t)$ ($1 \leq w, t \leq n$) such that the path configuration for $(w, t)$ is the same with the path configuration for $(u, v)$. -----Input----- - The first line of input contains a single integer $Q$, denoting the number of queries to process. - Each of the next $Q$ lines contains three space-separated integers $n$, $u$ and $v$ denoting a query. -----Output----- For each query, print the answer on a separate line. -----Constraints----- - $1 \leq Q \leq 2 \cdot 10^4$ - $1 \leq u, v \leq n \leq 10^{9}$ -----Example Input----- 3 11 9 11 10 2 2 8 1 8 -----Example Output----- 2 10 1 -----Explanation----- In the first query from the example test case, you should count pairs $(5, 7)$ and $(9, 11)$. In the second query from the example test case, you should count the following pairs: $(1, 1)$, $(2, 2)$, $(3, 3)$, $(4, 4)$, $(5, 5)$, $(6, 6)$, $(7, 7)$, $(8, 8)$, $(9, 9)$ and $(10, 10)$. In the third query from the example test case, you should only count a pair $(1, 8)$.
["t = int(input())\nwhile(t>0):\n t-=1;\n n,l,r = list(map(int,input().split()));\n a = bin(l)[2:];\n b = bin(r)[2:];\n # find matching\n z = 0;\n l = min(len(a),len(b));\n for i in range(l):\n if a[i]==b[i]:\n z+=1;\n else:\n break;\n\n #find base string\n a = a[z:]\n b = b[z:]\n if(len(a)==0 and len(b)==0):\n print(n);\n else :\n m = max(len(a),len(b))\n #print m;\n zz = bin(n)[2:]\n x= len(zz)\n y = zz[:x-m]\n \n f1 = y+a;\n f2 = y+b;\n ans = int(y,2)\n if(int(f1,2)>n or int(f2,2)>n):\n ans-=1;\n \n print(ans) \n \n\n \n"]
{"inputs": [["3", "11 9 11", "10 2 2", "8 1 8"]], "outputs": [["2", "10", "1"]]}
INTERVIEW
PYTHON3
CODECHEF
554
9809a24d89a41aafd34df7578345f051
UNKNOWN
Chef taught his brother Chefu about right angled triangle and its properties. Chefu says that he has understood everything about right angled triangles. Chef wants to check learning of his brother by asking the following question "Can you find a right angled triangle whose length of hypotenuse is H and its area is S?" Chefu is confused how to solve it. I hope you are not. Please solve this by finding a right angled triangle with hypotenuse H and area S. If it not possible to do so, then output -1. -----Input----- The first line of the input contains a single integer T denoting the number of test-cases. T test cases follow. For each test case, there will be a single line containing two space separated integers H and S. -----Output----- Output the answer for each test-case in a single line. If it is not possible to find such a triangle, output -1. Otherwise print 3 real numbers corresponding to the lengths of the sides of the triangle sorted in non-decreasing order. Please note that the length of the triangle sides should not differ by more than 0.01 in absolute value from the correct lengths. -----Constraints----- - 1 ≤ T ≤ 105 - 1 ≤ H ≤ 106 - 1 ≤ S ≤ 1012 -----Example----- Input:4 5 6 6 10 258303 89837245228 616153 77878145466 Output:3.00000 4.00000 5.00000 -1 -1 285168.817674 546189.769984 616153.000000
["import math\nt = eval(input())\nwhile(t > 0):\n h,s = input().split()\n h = int(h)\n s = int(s)\n if(((h*h*h*h) - (16*s*s)) < 0):\n print(\"-1\")\n else:\n B = (math.sqrt((h*h) + math.sqrt((h*h*h*h) - (16*s*s))))/math.sqrt(2)\n P = (2*s)/B\n if(B > P):\n print('{0:.6f}'.format(P),'{0:.6f}'.format(B),'{0:.6f}'.format(h))\n else:\n print('{0:.6f}'.format(B),'{0:.6f}'.format(P),'{0:.6f}'.format(h))\n t = t-1", "\nimport math\nfor i in range(int(input())):\n h,a=list(map(int,input().split()))\n cv=(4*a)/(h**2)\n if (cv > 1) :\n print(-1)\n else:\n thita=(math.asin(cv))/2\n ratio=math.tan(thita)\n #ratio=1/ratio\n #print ratio\n hh=math.sqrt(((2*a)/ratio))\n b=(2*a)/hh\n m=max(b,hh)\n s=min(b,hh)\n print(\"%0.5f %0.5f %0.5f\"%(s,m,h))\n \n \n \n \n \n", "# cook your code here\nfrom math import sqrt\nfrom math import pow\n\nt=int(input())\n\nwhile(t>0):\n t = t-1\n h, s = list(map(int, input().split()))\n s2 = pow(s, 2)\n h4 = pow(h, 4)\n s216 = s2*16\n sq2 = h4-s216\n if(sq2<0):\n print(\"-1\")\n continue\n sq = sqrt(sq2)\n hpsq = pow(h, 2) + sq\n a2 = hpsq/2\n a = sqrt(a2)\n b2 = pow(h, 2) - a2\n b = sqrt(b2)\n if(a<b):\n print(str(a) +\" \",str(b) +\" \",str(h) +\" \")\n else:\n print(str(b) +\" \",str(a) +\" \",str(h) +\" \")", "t=int(input())\nfor i in range(t):\n h,s=list(map(int,input().split()))\n d=((h**4)-(16*s*s))\n if d<0:\n print(\"-1\")\n else:\n d=d**0.5\n r1=((h**2)+d)/2\n r2=((h**2)-d)/2\n if r1<0 or r2<0:\n print(\"-1\")\n else:\n arr=[]\n r1=r1**0.5\n r2=r2**0.5\n arr.append(r1)\n arr.append(r2)\n arr.append(h)\n arr.sort()\n print('%.6f'%arr[0],'%.6f'%arr[1],'%.6f'%arr[2])", "t = int(input())\nfor test in range(t):\n h,s = list(map(int,input().split()))\n if h**2>=4*s:\n x = (h**2+4*s)**0.5\n y = (h**2-4*s)**0.5\n res = list(map(float,sorted([h,(x+y)/2,(x-y)/2])))\n print(\"%.5f %.5f %.5f\" % (res[0],res[1],res[2]))\n else:\n print(-1)", "\nimport math\n\ntt = int(input())\nfor i in range(tt):\n h, s = list(map(int, input().split()))\n a = h**2 + 4*s\n b = math.sqrt(a)\n u = h**2 - 4*s\n if u < 0:\n print(-1)\n continue\n\n k = (b + math.sqrt(h**2 - 4*s))/2 \n m = b - k\n g = [h,k,m]\n g.sort()\n print(' '.join(map(str, g)))", "from math import sqrt,pow\n\nt = int(input())\nwhile t>0:\n h,s = list(map(int,input().split())) \n if pow(h,2) + 4*s>=0 and pow(h,2) - 4*s>=0:\n a = (sqrt(pow(h,2) + 4*s) + sqrt(pow(h,2) - 4*s))/2\n b = sqrt(pow(h,2) + 4*s) - a\n if a>0 and b>0:\n c = []\n c.append(a)\n c.append(b)\n c.append(h)\n c.sort()\n for i in c:\n print(i, end=' ')\n print(\" \")\n else:\n print(-1, end=' ')\n else:\n print(-1)\n t-=1", "import math\nt=eval(input())\nwhile t>0:\n t-=1\n h,s = list(map(int,input().split()))\n try:\n bplush = math.sqrt(h*h+4*s)\n bminush = math.sqrt(h*h-4*s)\n base = (bplush + bminush)/2\n height =(bplush-bminush)/2\n a=[base,height,h]\n a.sort()\n for i in a:\n print(float(i), end=' ')\n print() \n except:\n print(\"-1\")", "import math\nfrom decimal import *\nT = int(input())\nwhile T>0:\n h,a = list(map(int,input().split()))\n x = h*h*h*h - 16*a*a\n if x<0:\n print(-1)\n else :\n y = 0.5*h*h - 0.5*math.sqrt(x)\n if y<0:\n print(-1)\n else:\n s = math.sqrt(0.5*h*h - 0.5 * math.sqrt(x))\n b = h*h - s*s\n ans=[]\n ans.append(s)\n ans.append(math.sqrt(b))\n ans.append(h)\n new_list = []\n for item in ans:\n new_list.append(float(item))\n ans.sort()\n print(format(ans[0],'.6f'),format(ans[1],'.6f'),format(ans[2],'.6f'))\n #print ans[0],ans[1],ans[2]\n T-=1", "from math import sqrt\nfrom sys import stdin\n\ndef solution( h, s ):\n sqrt1 = h ** 4 - 16 * s ** 2\n if( sqrt1 < 0 ):\n return False\n sqrt2 = h**2 - sqrt( sqrt1 )\n if( sqrt2 < 0 ):\n return False;\n sqrt2 = sqrt( sqrt2 / 2 )\n sqrt3 = h**2 + sqrt( sqrt1 )\n sqrt3 = sqrt( sqrt3 / 2 )\n return [ sqrt2, sqrt3 ]\n\n\nt = int( stdin.readline() )\nwhile t > 0:\n t -= 1\n h, s = list(map( int, stdin.readline().split() ))\n answer = solution( h,s )\n if( answer == False ):\n print(-1)\n else:\n answer.append( h )\n answer = sorted( answer )\n for i in answer:\n print(i, end=' ')\n print()\n", "import math\n\nt=int(input())\n# print t\nwhile(t>0):\n h,s = list(map(int, input().split()))\n check = h*h-4*s\n if(h*h>=4*s):\n det = math.sqrt(h*h*h*h-16*s*s)\n a=(h*h+det)/2\n a=math.sqrt(a)\n b=(h*h-det)/2\n b=math.sqrt(b)\n if(a<b):\n print(\"%f %f %f\" %(a,b,h))\n else:\n print(\"%f %f %f\" %(b,a,h))\n else:\n print(\"-1\")\n t-=1\n\n", "import cmath\nfrom math import ceil, floor, sqrt\ndef float_round(num, places = 0, direction = floor):\n return direction(num * (10**places)) / float(10**places)\nt=int(input())\na=float(1)\nfor i in range(t):\n s=list(map(int,input().split()))\n b=float(pow(s[0],2))\n c=float(4*pow(s[1],2))\n d = float((b**2) - (4*a*c))\n # find two solutions\n if(d==0):\n sol1 = abs((b-cmath.sqrt(d))/(2*a))\n # print sol1\n #sol2 = (b+cmath.sqrt(d))/(2*a)\n m=[]\n m.append(float_round(sqrt(sol1),6,round))\n m.append(float_round(sqrt(b-sol1),6,round))\n m.append(float_round(sqrt(b),6,round))\n m.sort()\n for p in range(2):\n print(m[p], end=' ')\n print(m[2])\n # print float_round(sqrt(sol1),6,round),float_round(sqrt(b-sol1),6,round\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0),float_round(sqrt(b),6,round)\n elif(d>0):\n sol1 = abs((b-cmath.sqrt(d))/(2*a))\n sol2 = abs((b+cmath.sqrt(d))/(2*a))\n # print abs(sol1),sol2\n m=[]\n m.append(float_round(sqrt(sol1),6,round))\n m.append(float_round(sqrt(sol2),6,round))\n m.append(float_round(sqrt(b),6,round))\n m.sort()\n for p in range(2):\n print(m[p], end=' ')\n print(m[2])\n else:\n print(-1)", "# your code goes here\nimport math\nt=eval(input())\nfor i in range(t):\n b=[]\n #c=[]\n h,s=list(map(int,input().split()))\n a=math.pow(h,4)-16*s*s\n if(a<0):\n print('-1')\n else:\n ans=math.sqrt(a)\n answe=(h*h+ans)/2\n answe2=(h*h-ans)/2\n #print answe\n #print answe2\n if(answe>0):\n b.append(math.sqrt(answe))\n b.append((2*s)/b[0])\n \"\"\" \n if(answe2>0):\n c.append(math.sqrt(answe2))\n c.append((2*s)/c[0])\n \"\"\" \n b.sort()\n print(str(b[0])+\" \"+str(b[1])+\" \"+str(h))\n", "import math\ntry:\n t=eval(input())\nexcept EOFError:\n t=0\nwhile(t):\n try:\n h,s=list(map(int,input().split()))\n except EOFError:\n h=0\n s=0\n z=(h**4)-(4*(4*(s**2)))\n if(z<0):\n print(-1)\n else:\n z=math.sqrt(z)\n z=(h**2)+z\n z=z/2\n z=math.sqrt(z)\n y=2*s\n try:\n y=y/z\n except ZeroDivisionError:\n y=0\n if(z>y):\n a=y\n b=z\n else:\n a=z\n b=y\n h=h*1.0\n print(a,b,h)\n t=t-1\n", "from math import sqrt\nt=int(input())\nfor qq in range(t):\n h, s = list(map(float, input().split()))\n h2 = h**2\n h4 = h**4\n s2 = s**2\n D = h4 - 16.0000000000*s2\n if D < 0:\n print(-1)\n else:\n D = sqrt(D)\n r1 = h2 + D\n r1 /= float(2.0)\n\n r2 = h2 - D\n r2 /= float(2.0)\n\n #print r1, r2\n\n if r1 > 0.000000000:\n a = r1\n elif r2 > 0.0:\n a = r2\n else:\n print(-1)\n continue\n\n a = sqrt(a)\n\n b = 2.0*s\n b /= a\n\n ans = [a, b, h]\n ans.sort()\n\n print(\"%.20f %.20f %.20f\" % (ans[0], ans[1], ans[2]))", "import numpy as np\nti = eval(input())\nt = int(ti)\nwhile t>0:\n p = 0\n hi,si = input().split(\" \")\n h = float(hi)\n #si = raw_input()\n s = float(si)\n r = h/2;\n alt = (2*s/h)\n \n \n if ( (r*r) - (alt*alt)) >= 0:\n c = np.sqrt( (r*r) - (alt*alt))\n else :\n p = 1\n #goto last\n e1 = r - c\n e2 = r + c\n #print p,\"kukukuku\"\n \n if (p == 1)|(e2*h >= 0):\n a = np.sqrt(e2 * h)\n else:\n p = 1\n if (p == 1)|(e1*h >= 0): \n b = np.sqrt(e1 * h)\n else:\n p = 1\n \n \n #last\n if p == 0:\n print(b,a,h)\n else:\n print(-1)\n #print h,s,r,alt,c,e1,e2,a,b\n t -= 1\n", "from math import sqrt\nfor p in range(int(input())):\n h,s=list(map(int,input().split()))\n x=h**4-16*(s**2)\n if x<0:\n print(-1)\n else:\n a=(h**2+sqrt(x))/2\n if(a<0):\n print(-1)\n else:\n len2=sqrt(h**2-a)\n len1=sqrt(a)\n if len1>len2:\n print(len2,len1,h)\n else:\n print(len1,len2,h)"]
{"inputs": [["4", "5 6", "6 10", "258303 89837245228", "616153 77878145466"]], "outputs": [["3.00000 4.00000 5.00000", "-1", "-1", "285168.817674 546189.769984 616153.000000"]]}
INTERVIEW
PYTHON3
CODECHEF
8,148
31191aeb11420d63b0b09151852bbc1d
UNKNOWN
Help Saurabh with his Chemistry Assignment. Saurabh has been given a chemistry assignment by Ruby Mam. Though the assignment is simple but Saurabh has to watch India vs Pakistan Match and he has no time to do the assignment by himself. So Saurabh wants you to do his assignment so that he doesn’t get scolded by Ruby Mam . The assignment is as follows , Suppose there are X particles initially at time t=0 in a box. At a time t the number of particles in box becomes t times the number of particles at time t-1 . You will be given N and X where N is time at which the number of particles in box is to be calculated and X is the number of particles at time t=0. -----Input----- The first line will contain the integer T, the number of test cases. Each test case consists of two space separated integers N and X . -----Output----- For each test case, output the answer to the query. Since the output can be very large, output the answer modulo 10^6+3 -----Constraints----- - 1 ≤ T ≤ 100000 - 1 ≤ N,X ≤ 10^18 -----Example----- Input: 2 1 2 2 1 Output: 2 2 -----Explanation----- Example case 2.At t=0 particles are 1 ,so at t=1 ,particles are 1*1 = 1 particles. At t=2, particles are 2*1 = 2 particles.
["a = [1]\nM = 10**6 + 3\nfor ii in range(1, 1000005):\n a.append((a[-1]*ii)%M)\nfor __ in range(eval(input())):\n n, x = list(map(int, input().split()))\n if n>=M: print(0)\n else: print((a[n]*x)%M)\n", "# your code goes here\nmod=1000003\nfact=[0]*mod\nfact[0]=1\nfor i in range(1,mod):\n fact[i]=(fact[i-1]*i)%mod\nt=int(input())\nwhile t:\n t=t-1\n s=input().split()\n n=int(s[0])\n x=int(s[1])\n if n>=mod:\n print(0)\n else:\n x=x%mod\n ans=fact[n]\n ans=(ans*x)%mod\n print(ans)"]
{"inputs": [["2", "1 2", "2 1"]], "outputs": [["2", "2"]]}
INTERVIEW
PYTHON3
CODECHEF
492
9f62f520e544114b9ed8a5970316d6a8
UNKNOWN
Given the values at the leaf nodes of a complete binary tree. The total number of nodes in the binary tree, is also given. Sum of the values at both the children of a node is equal to the value of the node itself. You can add any value or subtract any value from a node. Print the minimum change(difference made) in the sum of values of all the nodes in the tree, such that all the leaf nodes have the same value. Note: If a value transfers from one node to another, then that is not a change, but if an extra is needed to be added or subtracted to the entire total value of the nodes, then that is a change. Input Description: Input will contain an integer N, the number of nodes in the tree on a newline, followed by N space separated integers representing the values at the leaf nodes of the tree. Output Description: Print the required value on a newline. Constraints: 1<=N<=20000 1<=Value at each node in the leaves<=1000 Example 1: Input: 1 50 Output: 0 Explanation: Since there is only one node, it is a leaf node itself and no change needs to be made. Example 2: Input: 3 200 800 Output: 0 Explanation: There are two leaf nodes, and they can be made to 500 500, since no change in the total was made so difference made is 0. Example 3: Input: 30 29 33 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 Output: 6 Output: A total change of 6 needs to be changed to the entire value of the nodes, to get the leaf nodes equal.
["print(0)"]
{"inputs": [["1:", "Input:", "1", "50"]], "outputs": [["0"]]}
INTERVIEW
PYTHON3
CODECHEF
12
533e4120f43accba48083ff40a5b379a
UNKNOWN
A manufacturing project consists of exactly $K$ tasks. The board overviewing the project wants to hire $K$ teams of workers — one for each task. All teams begin working simultaneously. Obviously, there must be at least one person in each team. For a team of $A$ workers, it takes exactly $A$ days to complete the task they are hired for. Each team acts independently, unaware of the status of other teams (whether they have completed their tasks or not), and submits their result for approval on the $A$-th day. However, the board approves the project only if all $K$ teams complete their tasks on the same day — it rejects everything submitted on any other day. The day after a team finds out that its result was rejected, it resumes work on the same task afresh. Therefore, as long as a team of $A$ workers keeps getting rejected, it submits a new result of their task for approval on the $A$-th, $2A$-th, $3A$-th day etc. The board wants to hire workers in such a way that it takes exactly $X$ days to complete the project. Find the smallest number of workers it needs to hire. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first and only line of each test case contains two space-separated integers $K$ and $X$. -----Output----- For each test case, print a single line containing one integer — the smallest required number of workers. -----Constraints----- - $1 \le T \le 40$ - $2 \le K, X \le 10^6$ -----Example Input----- 2 2 3 2 6 -----Example Output----- 4 5 -----Explanation----- Example case 1: We can hire a team of $3$ workers for task $1$ and $1$ worker for task $2$. The one-man team working on task $2$ completes it and submits the result for approval on each day, but it is rejected on the first and second day. On the third day, the team working on task $1$ also completes their task, so the project gets approved after exactly $3$ days. Example case 2: We can hire a team of $3$ workers for task $1$ and a team of $2$ workers for task $2$.
["from math import log2;\nimport bisect;\nfrom bisect import bisect_left,bisect_right\nimport sys;\nfrom math import gcd,sqrt\nsys.setrecursionlimit(10**7)\nfrom collections import defaultdict\ninf=float(\"inf\")\n# n=int(input())\n# n,m=map(int,input().split())\n# l=list(map(int,input().split()))\ndef get_factors(x):\n if x==1:\n return [];\n sqrta=int(sqrt(x))+1\n for i in range(2,sqrta):\n if x%i==0:\n return [i]+get_factors(x//i)\n return [x]\ndef min_generator(fac,k,index,new_list):\n if index==len(fac):\n return sum(new_list)\n mina=inf;\n for i in range(0,min(index+1,len(new_list))):\n new_list[i]*=fac[index]\n theta=min_generator(fac,k,index+1,new_list)\n if theta<mina:\n mina=theta;\n new_list[i]//=fac[index]\n return mina;\ndef fun(k,x):\n dict=defaultdict(lambda :1)\n factors=get_factors(x)\n for i in factors:\n dict[i]*=i;\n if len(dict)==k:\n print(sum(dict.values()))\n return;\n if len(dict)<k:\n suma=sum(dict.values())\n left=k-len(dict)\n suma+=left;\n print(suma)\n return;\n if k==1:\n print(x)\n return;\n fac=list(dict.values())\n\n new_list=[1]*k\n theta=min_generator(fac,k,0,new_list)\n print(theta)\nfor i in range(int(input())):\n k,x=map(int,input().split())\n fun(k,x)", "# cook your dish here\ndef factors(n):\n factor=[]\n for i in range(2,int(n**(1/2))+1):\n cnt=0\n if n%i==0:\n while n%i==0:\n cnt+=1\n n=n//i\n factor.append(i**cnt)\n if n!=1:\n factor.append(n)\n return factor\ndef bruteforce(pos,arr,factors):\n if pos==len(factors):\n return sum(arr)\n \n ans=float('inf')\n \n for i in range(len(arr)):\n arr[i]*=factors[pos]\n ans=min(ans,bruteforce(pos+1,arr,factors))\n arr[i]//=factors[pos]\n return ans\n \nfor _ in range(int(input())):\n k,n=list(map(int,input().split()))\n fac=factors(n)\n if len(fac)==k:\n print(sum(fac))\n elif len(fac)<k:\n print(sum(fac)+k-len(fac))\n else:\n arr=[1]*k\n d=bruteforce(0,arr,fac)\n print(d)\n", "# cook your dish here\n\ndef factorize(n):\n fact=[]\n for i in range(2,int(n**0.5)+1):\n if n%i==0:\n c=0\n while n%i==0:\n c+=1\n n//=i\n fact.append(i**c)\n if n!=1:\n fact.append(n)\n \n return fact\n\ndef brute(pos,ar,fact):\n if pos==len(fact):\n return sum(ar)\n ans=float('inf')\n \n for i in range(len(ar)):\n ar[i]*=fact[pos]\n ans=min(ans,brute(pos+1,ar,fact))\n ar[i]//=fact[pos]\n \n return ans\n \nt=int(input())\n\nwhile(t>0):\n \n k,x=map(int,input().split())\n fact=factorize(x)\n lenn=len(fact)\n \n if lenn <=k:\n \n ans= sum(fact)+k-lenn\n else:\n ar=[1]*k\n ans=brute(0,ar,fact)\n print(ans)\n t-=1", "def all_pcombo(arr,factors,pos):\n if pos==len(factors):\n return sum(arr)\n\n ans=float('inf')\n\n for i in range(len(arr)):\n arr[i]*=factors[pos]\n ans=min(ans,all_pcombo(arr,factors,pos+1))\n arr[i]//=factors[pos]\n\n return ans\n\ndef factorization(n):\n factors=[]\n for i in range(2,int(n**0.5)+1):\n if n%i==0:\n cnt=0\n while n%i==0:\n cnt+=1\n n//=i\n factors.append(i**cnt)\n\n if n>1:\n factors.append(n)\n return factors\n\ndef solve():\n k,x=map(int,input().split())\n factors=factorization(x)\n len_=len(factors)\n\n ans=0\n if len_<=k:\n ans=sum(factors) + k-len_\n else:\n arr=[1]*k\n ans=all_pcombo(arr,factors,0)\n\n print(ans)\n\n\nt=int(input())\nwhile t>0:\n solve()\n t-=1", "def all_pcombo(arr,factors,pos):\n if pos==len(factors):\n return sum(arr)\n\n ans=float('inf')\n\n for i in range(len(arr)):\n arr[i]*=factors[pos]\n ans=min(ans,all_pcombo(arr,factors,pos+1))\n arr[i]//=factors[pos]\n\n return ans\n\ndef factorization(n):\n factors=[]\n for i in range(2,int(n**0.5)+1):\n if n%i==0:\n cnt=0\n while n%i==0:\n cnt+=1\n n//=i\n factors.append(i**cnt)\n\n if n>1:\n factors.append(n)\n return factors\n\ndef solve():\n k,x=map(int,input().split())\n factors=factorization(x)\n len_=len(factors)\n\n ans=0\n if len_<=k:\n ans=sum(factors) + k-len_\n else:\n arr=[1]*k\n ans=all_pcombo(arr,factors,0)\n\n print(ans)\n\n\nt=int(input())\nwhile t>0:\n solve()\n t-=1", "# cook your dish here\nimport sys\nsys.setrecursionlimit(10000000)\n\n\ndef primes(x):\n f = []\n i = 2\n while i * i <= x:\n if x % i == 0:\n t = 1\n while x % i == 0:\n x //= i\n t *= i\n f.append(t)\n i += 1\n if x > 1:\n f.append(x)\n return f\n\n\ndef recur(arr):\n if len(arr) == k:\n return sum(arr)\n answer = float('inf')\n for i in range(len(arr) - 1):\n for j in range(i + 1, len(arr)):\n temp = arr[:]\n temp.remove(arr[i])\n temp.remove(arr[j])\n temp.append(arr[i] * arr[j])\n answer = min(answer, recur(temp))\n return answer\n\n\nfor _ in range(int(input())):\n k, X = map(int, input().split())\n p = primes(X)\n if k >= len(p):\n print(sum(p) + (k - len(p)))\n continue\n print(recur(p))", "# cook your dish here\nimport math\ndef factorize(n):\n factors=[]\n for i in range(2,int(n**0.5)+1):\n if(n%i==0):\n cntr=0\n while(n%i==0):\n cntr+=1\n n//=i\n factors.append(i**cntr)\n if n!=1:\n factors.append(n)\n return factors\n\ndef brtueforce(pos,arr,factors):\n if pos==len(factors):\n return sum(arr)\n ans=float('inf')\n for i in range(len(arr)):\n arr[i]*=factors[pos]\n ans=min(ans,brtueforce(pos+1,arr,factors))\n arr[i]//=factors[pos]\n\n return ans\n\n\ndef solve():\n #n=int(input())\n \n k,x=map(int,input().split())\n #s=input()\n #l=list(map(int,input().split()))\n #l1=list(map(int,input().split()))\n #flag=0\n \n factors=factorize(x)\n\n lenn=len(factors)\n\n if lenn<=k:\n\n ans=sum(factors) + k-lenn\n else:\n arr=[1]*k\n ans=brtueforce(0,arr,factors)\n\n print(ans)\n\n \n\n\n\n\n\nt=int(input())\nfor i in range(t):\n solve()", "def factorizing(n):\n factor = []\n for i in range(2,int(n**0.5)+1):\n if n%i==0:\n count = 0\n while n%i==0:\n count += 1\n n //= i\n factor.append(i**count)\n \n if (n!=1):\n factor.append(n)\n return factor\n\n\ndef getans(a,f,p):\n if p==len(f):\n return sum(a)\n \n ans = float('inf')\n \n for i in range(len(a)):\n a[i] *= f[p]\n ans = min(ans,getans(a,f,p+1))\n a[i] //= f[p]\n \n return ans\n\nT = int(input())\n\nwhile(T):\n \n T -= 1\n \n k,x = map(int, input().split())\n \n factors = factorizing(x)\n \n if len(factors)<=k:\n ans = sum(factors) + k-len(factors)\n else:\n a = [1]*k\n ans = getans(a,factors, 0)\n \n print(ans)", "def find_div(x):\n b=[]\n e=int(x**0.5)+1\n for i in range(2,e):\n if x%i==0:\n c=0\n while x%i==0:\n c+=1\n x=x//i\n b.append(i**c)\n if x!=1:\n b.append(x)\n return b \n \ndef solve(a,div,pos):\n if pos==len(div):\n return sum(a)\n ans=2**30\n for i in range(len(a)):\n a[i]*=div[pos]\n ans=min(ans,solve(a,div,pos+1))\n a[i]=a[i]//div[pos]\n return ans\n \n \nt=int(input())\nfor _ in range(t):\n k,x=map(int,input().split())\n div=find_div(x)\n if len(div)<=k:\n ans=sum(div)+k-len(div)\n else:\n a=[1]*k\n ans=solve(a,div,0)\n print(ans) ", "def factorize(n):\n factors=[]\n for i in range(2,int(n**0.5)+1):\n if n%i==0:\n cnt=0\n while n%i==0:\n cnt+=1\n n//=i\n factors.append(i**cnt)\n if n!=1:\n factors.append(n)\n return factors\n\ndef brute(pos,arr,factors):\n if pos==len(factors):\n return sum(arr)\n ans = float('inf')\n for i in range(len(arr)):\n arr[i]*=factors[pos]\n ans=min(ans,brute(pos+1,arr,factors))\n arr[i]//=factors[pos]\n return ans\n\nt = int(input())\nwhile t:\n k,x=map(int,input().split())\n factors=factorize(x)\n if len(factors)<=k:\n ans=sum(factors)+k-len(factors)\n else:\n arr=[1]*k\n ans=brute(0,arr,factors)\n print(ans)\n t-=1", "def factorize(n):\n factors=[]\n for i in range(2,int(n**0.5)+1):\n if n%i==0:\n cnt=0\n while n%i==0:\n cnt+=1\n n//=i\n factors.append(i**cnt)\n if n!=1:\n factors.append(n)\n return factors\n\ndef brute(pos,arr,factors):\n if pos==len(factors):\n return sum(arr)\n ans = float('inf')\n for i in range(len(arr)):\n arr[i]*=factors[pos]\n ans=min(ans,brute(pos+1,arr,factors))\n arr[i]//=factors[pos]\n return ans\n\nt = int(input())\nwhile t:\n k,x=map(int,input().split())\n factors=factorize(x)\n if len(factors)<=k:\n ans=sum(factors)+k-len(factors)\n else:\n arr=[1]*k\n ans=brute(0,arr,factors)\n print(ans)\n t-=1", "def factorize(n):\n factors=[]\n for i in range(2,int(n**0.5)+1):\n if n%i==0:\n cntr=0\n while n%i==0:\n cntr+=1\n n//=i\n factors.append(i**cntr)\n if n!=1:\n factors.append(n)\n\n return factors\n\ndef bruteForce(pos,arr,factors):\n if pos==len(factors):\n return sum(arr)\n\n ans=float('inf')\n\n for i in range(len(arr)):\n arr[i]*=factors[pos]\n ans=min(ans,bruteForce(pos+1,arr,factors))\n arr[i]//=factors[pos]\n\n return ans\n\ndef __starting_point():\n t=int(input())\n\n while(t != 0):\n \n k,x=list(map(int, input().split()))\n factors=factorize(x)\n lenn=len(factors)\n\n if lenn<=k:\n ans=sum(factors)+k-lenn\n\n else:\n arr=[1]*k\n ans=bruteForce(0,arr,factors)\n\n print(ans)\n\n t=t-1\n\n\n__starting_point()", "import traceback;\nimport math;\n\nMAX_INF = 9223372036854775807\nINF = 2147483647\nSEM_INF = INF // 2\nMOD = int(1e9 + 7)\n\n\nclass HELPER:\n tmplst = []\n pntr = 0\n outPutStream = \"\"\n\n def __init__(self):\n pass\n\n def __next__(self):\n if self.pntr == -1 or self.pntr == len(self.tmplst):\n self.tmplst = input().split(\" \")\n self.pntr = 0\n ret = self.tmplst[self.pntr]\n self.pntr += 1\n\n return ret\n\n def nextInt(self):\n return int(next(self))\n\n def nextFloat(self):\n return float(next(self))\n\n def nextLine(self):\n return input()\n\n def readArray(self, n):\n l = []\n for x in range(0, n):\n l.append(self.nextInt())\n return l\n\n def getIntArray(self, s):\n l = []\n s = s.split(\" \")\n for x in range(0, len(s)):\n l.append(int(s[x]))\n\n return l\n\n # Printing Arena\n\n def printArray(self, a, nextLine):\n for x in a:\n sc.write(\"{} \".format(x))\n if nextLine:\n self.writeln()\n\n def writeln(self, s):\n self.outPutStream += (str(s) + \"\\n\")\n\n def write(self, s):\n self.outPutStream += str(s)\n\n def flush(self):\n print(self.outPutStream)\n outPutStream = \"\"\n\n\nsc = HELPER()\n\n\ndef writeln(s=\"\"):\n sc.writeln(s)\n\n\ndef write(s):\n sc.write(s)\n\n\n\"\"\"Code Starts Here\"\"\"\n\n\ndef getFactorList(n):\n l = [];\n p = 0\n while n % 2 == 0:\n p += 1\n n = n // 2\n l.append(int(math.pow(2,p)))\n\n x = 3\n while x <= math.sqrt(n):\n p = 0\n while n % x == 0:\n n = n // x\n p += 1\n if p != 0:\n l.append(int(math.pow(x,p)))\n x += 2\n\n if n > 2:\n l.append(n)\n\n return l\n\n\ndef getMinRecur(l, a, pos):\n if(pos == len(l)):\n return sum(a)\n ans = float('inf')\n for x in range(0,len(a)):\n a[x] *= l[pos]\n ans = min(ans,getMinRecur(l,a,pos + 1))\n a[x] //= l[pos]\n\n return ans\n\n\ndef getMinAns(l,k):\n ans = 0\n if k == len(l):\n ans = sum(l)\n elif k > len(l):\n more = k - len(l)\n ans = more + sum(l)\n else:\n arr = [1] * k\n ans = getMinRecur(l,arr,0)\n return ans\n\n\ndef testCase():\n k = sc.nextInt(); day = sc.nextInt()\n l = getFactorList(day)\n\n ans = getMinAns(l,k)\n ans = min(ans,day + k - 1)\n writeln(ans)\n pass\n\n\n\"\"\"Code Ends Here\"\"\"\n\n\ndef main():\n t = int(input())\n # t = 1\n while t > 0:\n testCase()\n t -= 1\n sc.flush()\n\n\ntry:\n def __starting_point():\n main()\nexcept:\n print(\"Error Occured\")\n traceback.print_exc()\n\n__starting_point()", "def brute(ind,arr,factors):\n if ind==len(factors):\n return sum(arr)\n ans=10000000000000\n for i in range(len(arr)):\n arr[i]*=factors[ind]\n ans=min(ans,brute(ind+1,arr,factors))\n arr[i] //= factors[ind]\n return ans\n\ndef factorize(x):\n factors=[]\n for i in range(2,int(x**0.5)+1):\n if x%i==0:\n count=0\n while x%i==0:\n count+=1\n x //= i\n factors.append(i**count)\n if x!=1:\n factors.append(x)\n return factors\n\n\nt=int(input())\nfor _ in range(t):\n k,x=map(int,input().split())\n factors=factorize(x)\n if len(factors)<=k:\n print(sum(factors)+k-len(factors))\n else:\n arr = [1]*k\n print(brute(0,arr,factors))", "# cook your dish here\ntry:\n MAX = 1000005\n prime = [True] * MAX\n fact = [list() for i in range(MAX)]\n\n for i in range(2, MAX):\n if prime[i]:\n for j in range(i, MAX, i):\n prime[j] = False\n fact[j].append(i)\n\n def solve(arr, i, k):\n if i >= len(arr):\n return sum(k)\n z = float('inf')\n for j in range(len(k)):\n k[j] *= arr[i]\n z = min(z, solve(arr, i + 1, k))\n k[j] //= arr[i]\n return z\n\n t = int(input())\n for i in range(t):\n k, x = map(int, input().split())\n temp = []\n for y in fact[x]:\n p = x\n z = 1\n while p % y == 0:\n p //= y\n z *= y\n temp.append(z)\n if k >= len(fact[x]):\n print(sum(temp) + k - len(temp))\n else:\n print(solve(temp, 0, [1] * k))\n\nexcept EOFError as e : pass", "# cook your dish here\n\n\ndef primeFactors(n):\n factors = []\n cnt = 0\n if n%2 == 0:\n while n%2 == 0:\n cnt += 1\n n = n//2\n\n factors.append(2**cnt)\n \n for i in range(3,int(n**0.5)+1,2):\n cnt = 0\n if n%i == 0:\n \n while n%i == 0:\n cnt += 1\n n = n//i\n\n factors.append(i**cnt)\n if n != 1:\n factors.append(n)\n \n return factors\n \ndef minSum(arr,k):\n if len(arr) == k:\n return sum(arr)\n \n ans = 1e18\n for i in range(len(arr)-1):\n temp = []\n for j in range(i+1,len(arr)):\n temp = [arr[i]*arr[j]] + arr[:i] + arr[i+1:j] + arr[j+1:]\n \n ans = min(ans,minSum(temp,k))\n \n return ans\n \nTC = int(input())\nfor tc in range(TC):\n k, x = list(map(int,input().strip().split()))\n \n factors = primeFactors(x)\n \n if len(factors) <= k:\n print(sum(factors) + k-len(factors))\n else:\n print(minSum(factors,k))\n", "# cook your dish here\nimport sys\nsys.setrecursionlimit(10000000)\n\ndef primeFactors(n):\n factors = []\n cnt = 0\n if n%2 == 0:\n while n%2 == 0:\n cnt += 1\n n = n//2\n\n factors.append(2**cnt)\n \n for i in range(3,int(n**0.5)+1,2):\n cnt = 0\n if n%i == 0:\n \n while n%i == 0:\n cnt += 1\n n = n//i\n\n factors.append(i**cnt)\n if n != 1:\n factors.append(n)\n \n return factors\n \ndef minSum(arr,k):\n if len(arr) == k:\n return sum(arr)\n \n ans = 1e18\n for i in range(len(arr)-1):\n temp = []\n for j in range(i+1,len(arr)):\n temp = [arr[i]*arr[j]] + arr[:i] + arr[i+1:j] + arr[j+1:]\n \n ans = min(ans,minSum(temp,k))\n \n return ans\n \nTC = int(input())\nfor tc in range(TC):\n k, x = list(map(int,input().strip().split()))\n \n factors = primeFactors(x)\n \n if len(factors) <= k:\n print(sum(factors) + k-len(factors))\n else:\n print(minSum(factors,k))\n", "def factorize(n):\n factors = []\n for i in range(2, int(n**0.5)+1):\n if n % i == 0:\n cntr = 0\n while n % i == 0:\n cntr += 1\n n //= i\n factors.append(i**cntr)\n if n != 1:\n factors.append(n)\n return factors\n \ndef recur(arr):\n if len(arr)==k:\n return sum(arr)\n res = float('inf')\n for i in range(len(arr)-1):\n for j in range(i+1,len(arr)):\n temp=arr[:]\n temp.remove(arr[i])\n temp.remove(arr[j])\n temp.append(arr[i]*arr[j])\n res = min(res,recur(temp))\n return res\n\nfor i in range(int(input())):\n k,x=list(map(int,input().split()))\n arr = factorize(x)\n if len(arr)<k:\n print(sum(arr)+k-len(arr))\n else:\n print(recur(arr))\n \n \n", "import sys\nsys.setrecursionlimit(10000000)\n\n\ndef primes(x):\n f = []\n i = 2\n while i * i <= x:\n if x % i == 0:\n t = 1\n while x % i == 0:\n x //= i\n t *= i\n f.append(t)\n i += 1\n if x > 1:\n f.append(x)\n return f\n\n\ndef recur(arr):\n if len(arr) == k:\n return sum(arr)\n answer = float('inf')\n for i in range(len(arr) - 1):\n for j in range(i + 1, len(arr)):\n temp = arr[:]\n temp.remove(arr[i])\n temp.remove(arr[j])\n temp.append(arr[i] * arr[j])\n answer = min(answer, recur(temp))\n return answer\n\n\nfor _ in range(int(input())):\n k, X = list(map(int, input().split()))\n p = primes(X)\n if k >= len(p):\n print(sum(p) + (k - len(p)))\n continue\n print(recur(p))\n", "\ndef prime(n):\n ans = []\n i = 2\n while (i*i <= n):\n if n % i == 0:\n temp1 = 1\n while (n % i == 0):\n n //= i\n temp1 *= i\n ans.append(temp1)\n i += 1\n if n>1:\n ans.append(n)\n return ans\n\ndef recur(arr,k):\n if len(arr) == k:\n return sum(arr)\n ans = float('inf')\n for i in range(len(arr)-1):\n for j in range(i+1, len(arr)):\n temp = arr[:]\n temp.remove(arr[i])\n temp.remove(arr[j])\n temp.append(arr[i]*arr[j])\n ans = min(ans, recur(temp,k))\n return ans\n\ntc = int(input())\nfor i in range(tc):\n k, x = list(map(int,input().split()))\n p = prime(x)\n if len(p) <= k:\n print(sum(p)+k-len(p))\n else:\n print(recur(p,k))\n", "import sys\nsys.setrecursionlimit(10000000)\ndef prime(n):\n ans = []\n i = 2\n while (i*i <= n):\n if n % i == 0:\n temp1 = 1\n while (n % i == 0):\n n //= i\n temp1 *= i\n ans.append(temp1)\n i += 1\n if n>1:\n ans.append(n)\n return ans\n\ndef recur(arr,k):\n if len(arr) == k:\n return sum(arr)\n ans = float('inf')\n for i in range(len(arr)-1):\n for j in range(i+1, len(arr)):\n temp = arr[:]\n temp.remove(arr[i])\n temp.remove(arr[j])\n temp.append(arr[i]*arr[j])\n ans = min(ans, recur(temp,k))\n return ans\n\ntc = int(input())\nfor i in range(tc):\n k, x = list(map(int,input().split()))\n p = prime(x)\n if len(p) <= k:\n print(sum(p)+k-len(p))\n else:\n print(recur(p,k))\n", "import math\n\n\ndef primeFactors(n):\n d = {}\n while n % 2 == 0:\n n = n // 2\n if 2 in d:\n d[2] += 1 \n else:\n d[2] = 1 \n for i in range(3,int(math.sqrt(n))+1,2):\n while n % i== 0:\n if i in d:\n d[i] += 1 \n else:\n d[i] = 1 \n n = n // i\n if n > 2:\n if n in d:\n d[n] += 1 \n else:\n d[n] = 1\n \n return d\n \ndef get_all_combs(arr, left):\n nonlocal g\n if not left:\n g.append(sum(arr))\n else:\n new = left.pop()\n for i in range(len(arr)):\n newarr = arr.copy()\n newarr[i] *= new \n get_all_combs(newarr, left.copy())\n \n\n\nfor test in range(int(input())):\n k, x = list(map(int, input().split()))\n d = primeFactors(x)\n \n if k < len(d):\n p = [item**d[item] for item in d]\n xo = [1]*k\n g = []\n get_all_combs(xo, p)\n \n print(min(g))\n continue\n \n c2 = 0\n for item in d:\n c2 += item**d[item]\n diff = k - len(d)\n \n c2 += diff\n \n print(c2)\n"]
{"inputs": [["2", "2 3", "2 6"]], "outputs": [["4", "5"]]}
INTERVIEW
PYTHON3
CODECHEF
18,257
c4c0b125e7e2afcf6645f8adaa83613c
UNKNOWN
Mathison and Chef are playing a new teleportation game. This game is played on a $R \times C$ board where each cell $(i, j)$ contains some value $V_{i, j}$. The purpose of this game is to collect a number of values by teleporting from one cell to another. A teleportation can be performed using a tel-pair. A player is given $N$ tel-pairs. Each tel-pair can be used at most once and a player can use them in any order they like. Suppose a player is at cell $(a, b)$ and the tel-pair is $(dx, dy)$. Then, the player can reach in one teleportation any cell $(c, d)$ from $(a, b)$ such that $|a − c| = dx$ and $|b − d| = dy$. It is Mathison’s turn next in the game to make a sequence of moves. He would like to know what is the highest value of a path of length at most $N+1$ that starts in $(Sx, Sy)$ and uses some (possibly none) of the tel-pairs given. The length of a path is equal to the number of cells in the path. The value of a path is equal to the sum of $V_{i, j}$ over all cells in the path. -----Input----- - The first line contains a single integer, $T$, the number of tests. - Each test starts with three integers, $R$, $C$, and $N$, representing the number of rows, columns, and tel-pairs. - The next line contains two integers, $Sx$, and $Sy$, representing the coordinates of the starting cell. - The next two lines will contain the description of the tel-pairs, each containing $N$ space separated integers. The first will contain the $x$-component of each tel-pair, the second one will contain the y-component of each tel-pair. - Finally, there will be $R$ lines, each containing $C$ space-separated integers, the description of the board. -----Output----- The output file will contain $T$ lines. Each line will contain the answer (i.e. the highest value of a path) to the corresponding test. -----Constraints and notes----- - $1 \leq T \leq 100$ - $1 \leq R, C \leq 1000$ - $1 \leq N \leq 9$ - $0 \leq Sx < R$ - $0 \leq Sy < C$ - $0 \leq dx \leq R$ - $0 \leq dy \leq C$ - $1 \leq V_{i, j} \leq 10^6$ - You are allowed to visit a cell multiple times in a path, and the value for the cell must be added each time you visit it. -----Subtaks----- Subtask #1 (15 points): - $1 \leq T \leq 100$ - $1 \leq R, C \leq 10$ - $1 \leq N \leq 4$ Subtask #2 (25 points): - $1 \leq T \leq 25$ - $1 \leq R, C \leq 100$ - $1 \leq N \leq 8$ Subtask #3 (30 points): - $1 \leq T \leq 5$ - $1 \leq R, C \leq 1000$ - $1 \leq N \leq 8$ Subtask #4 (30 points): - $1 \leq T \leq 5$ - $1 \leq R, C \leq 1000$ - $1 \leq N \leq 9$ -----Example Input----- 3 5 5 2 2 2 1 2 2 1 10 11 62 14 15 57 23 34 75 21 17 12 14 11 53 84 61 24 85 22 43 89 14 15 43 3 3 2 0 0 1 1 1 1 9 8 7 5 6 4 1 3 2 2 2 1 1 1 2 2 5 6 8 3 -----Example Output----- 188 24 3 -----Explanation----- Test Case 1: Mathison starts at $(2, 2)$. Mathison has two tel-pairs $(2, 1)$ and $(1, 2)$. The following path (i.e. bolded numbers) generates the maximum value: $(2, 2)$ → $(4, 1)$ → $(3, 3)$ Test Case 2: Mathison starts at $(0, 0)$. Mathison has two tel-pairs $(1, 1)$ and $(1, 1)$. The following path (i.e. bolded numbers) generates the maximum value: $(0, 0)$ → $(1, 1)$ → $(0, 0)$ Test Case 3: Mathison starts at $(1, 1)$. Mathison has one tel-pair, $(2, 2)$. He can't use the tel-pair so the answer is $3$ (the value of the starting cell).
["# cook your dish here\nfrom collections import namedtuple\n\nCurrentPosition = namedtuple('current_position', 'points, cell, pairs')\n\nT = int(input())\nfor _ in range(T):\n R, C, N = map(int, input().split())\n Sx, Sy = map(int, input().split())\n tx = map(int, input().split())\n ty = map(int, input().split())\n tel_pairs = list(zip(tx, ty))\n board = []\n for _ in range(R):\n board += [[int(c) for c in input().split()]]\n \n def explore(p):\n next_pos = []\n for i, (dx, dy) in enumerate(p.pairs):\n sx, sy = p.cell\n new_pairs = p.pairs[:i]+p.pairs[i+1:]\n # case (+, +)\n px, py = sx + dx, sy + dy\n if px < R and py < C:\n next_pos += [CurrentPosition(p.points+board[px][py], (px, py), new_pairs)]\n # case (+, -)\n px, py = sx + dx, sy - dy\n if px < R and 0 <= py:\n next_pos += [CurrentPosition(p.points+board[px][py], (px, py), new_pairs)]\n # case (-, +)\n px, py = sx - dx, sy + dy\n if 0 <= px and py < C:\n next_pos += [CurrentPosition(p.points+board[px][py], (px, py), new_pairs)]\n # case (-, -)\n px, py = sx - dx, sy - dy\n if 0 <= px and 0 <= py:\n next_pos += [CurrentPosition(p.points+board[px][py], (px, py), new_pairs)]\n return next_pos\n \n pos = [CurrentPosition(board[Sx][Sy], (Sx, Sy), tel_pairs)]\n result = board[Sx][Sy]\n while pos:\n p = pos.pop(0)\n if p.pairs:\n pos += explore(p)\n else:\n result = max(result, p.points)\n \n print(result) \n"]
{"inputs": [["3", "5 5 2", "2 2", "1 2", "2 1", "10 11 62 14 15", "57 23 34 75 21", "17 12 14 11 53", "84 61 24 85 22", "43 89 14 15 43", "3 3 2", "0 0", "1 1", "1 1", "9 8 7", "5 6 4", "1 3 2", "2 2 1", "1 1", "2", "2", "5 6", "8 3"]], "outputs": [["188", "24", "3"]]}
INTERVIEW
PYTHON3
CODECHEF
1,720
73f06c5dca1821be7db3d089a0f03c30
UNKNOWN
Consider a 2d-grid. That is, each cell is identified by (i,j). You have received reports of two snake-sightings on this grid. You want to check whether they could be partial sightings of the same snake or not. Each of the snake sightings correspond to a straight, axis-parallel line segment in the grid, and the starting and ending cells for each are given to you. Now consider a graph, where each cell in the 2d-grid is a vertex. And there is an edge between 2 vertices if and only if the cells corresponding to these two vertices are consecutive cells in at least one of the two snakes. That is, at least in one of the snakes, when you go from one end point to the other end point, these two cells should occur consecutively. The two sightings/snakes are said to be same, if both these conditions are satisfied: - The union of the set of cells in the first snake and the set of cells in the second snake, should form a connected component in this graph. - No vertex should have degree more than 2 in the graph. In other words, the induced subgraph on the union set must be a path graph. -----Input----- - The first line contains a single integer, T, which is the number of testcases. The description of each testcase follows. - The first line of each testcase contains four integers: X11, Y11, X12, Y12. This represents the fact that the first snake's end points are (X11, Y11) and (X12, Y12). - The second line of each testcase contains four integers: X21, Y21, X22, Y22. This represents the fact that the second snake's end points are (X21, Y21) and (X22, Y22). -----Output----- - For each testcase, output "yes" if the snakes are the same, as per the definition given above. Output "no" otherwise. -----Constraints----- - 1 ≤ T ≤ 105 - -109 ≤ Xij,Yij ≤ 109 - The two end points of every snake is guaranteed to be either on the same row or on the same column. Thus, the snake occupies all the cells between these cells, including the end points. -----Example----- Input: 4 2 1 8 1 11 1 7 1 2 1 8 1 11 1 9 1 2 1 8 1 3 1 3 -2 2 1 8 1 2 1 2 -2 Output: yes no no yes -----Explanation----- In the images, the first snake is red, the second snake is yellow, and the intersections, if any, are in orange. The first test case corresponds to: Both the conditions on the graph are satisfied, and hence this is a "yes". The second test case corresponds to: There is no edge between the vertex corresponding to the (8,1) cell and the vertex corresponding to (9,1), Hence, the union set is disconnected, and thus the answer is "no". The third test case corresponds to: The vertex corresponding to the cell (3,1) has degree 3, which is more than 2, and thus the answer is "no". The fourth test case corresponds to: Both the conditions on the graph are satisfied, and hence this is a "yes".
["# cook your dish here\nt=int(input())\nfor _ in range(t):\n x1,y1,x2,y2=map(int,input().split())\n x3,y3,x4,y4=map(int,input().split())\n if (x1==x3 and y1==y3)or(x2==x4 and y2==y4):\n print(\"yes\")\n elif (x1==x4 and y1==y4)or(x2==x3 and y2==y3):\n print(\"yes\")\n else:\n if(y1==y2)and(y1==y3)and(y1==y4):\n a1=max(x1,x2);a2=min(x1,x2)\n b1=max(x3,x4);b2=min(x3,x4)\n if a1>=b2 and a2<=b1:\n print(\"yes\")\n else:\n print(\"no\")\n elif (x1==x2)and(x1==x3)and(x1==x4):\n a1=max(y1,y2);a2=min(y1,y2)\n b1=max(y3,y4);b2=min(y3,y4)\n if a1>=b2 and a2<=b1:\n print(\"yes\")\n else:\n print(\"no\")\n else:\n print(\"no\")", "# cook your dish here\nt=int(input())\nfor _ in range(t):\n x1,y1,x2,y2=map(int,input().split())\n x3,y3,x4,y4=map(int,input().split())\n if (x1==x3 and y1==y3)or(x2==x4 and y2==y4):\n print(\"yes\")\n elif (x1==x4 and y1==y4)or(x2==x3 and y2==y3):\n print(\"yes\")\n else:\n if(y1==y2)and(y1==y3)and(y1==y4):\n a1=max(x1,x2);a2=min(x1,x2)\n b1=max(x3,x4);b2=min(x3,x4)\n if a1>=b2 and a2<=b1:\n print(\"yes\")\n else:\n print(\"no\")\n elif (x1==x2)and(x1==x3)and(x1==x4):\n a1=max(y1,y2);a2=min(y1,y2)\n b1=max(y3,y4);b2=min(y3,y4)\n if a1>=b2 and a2<=b1:\n print(\"yes\")\n else:\n print(\"no\")\n else:\n print(\"no\")"]
{"inputs": [["4", "2 1 8 1", "11 1 7 1", "2 1 8 1", "11 1 9 1", "2 1 8 1", "3 1 3 -2", "2 1 8 1", "2 1 2 -2"]], "outputs": [["yes", "no", "no", "yes"]]}
INTERVIEW
PYTHON3
CODECHEF
1,322
18fadb0010f779744fb0dd464999f81f
UNKNOWN
Ada is playing pawn chess with Suzumo. Pawn chess is played on a long board with N$N$ squares in one row. Initially, some of the squares contain pawns. Note that the colours of the squares and pawns do not matter in this game, but otherwise, the standard chess rules apply: - no two pawns can occupy the same square at the same time - a pawn cannot jump over another pawn (they are no knights!), i.e. if there is a pawn at square i$i$, then it can only be moved to square i−2$i-2$ if squares i−1$i-1$ and i−2$i-2$ are empty - pawns cannot move outside of the board (outs are forbidden) The players alternate turns; as usual, Ada plays first. In each turn, the current player must choose a pawn and move it either one or two squares to the left of its current position. The player that cannot make a move loses. Can Ada always beat Suzumo? Remember that Ada is a chess grandmaster, so she always plays optimally. -----Input----- - The first line of the input contains a single integer T$T$ denoting the number of test cases. The description of T$T$ test cases follows. - The first and only line of each test case contains a single string S$S$ with length N$N$ describing the initial board from left to right. An empty square and a square containing a pawn are denoted by the characters '.' and 'P' respectively. -----Output----- For each test case, print a single line containing the string "Yes" if Ada wins the game or "No" otherwise (without quotes). -----Constraints----- - 1≤T≤500$1 \le T \le 500$ - 2≤N≤128$2 \le N \le 128$ - S$S$ contains only characters '.' and 'P' -----Example Input----- 1 ..P.P -----Example Output----- Yes -----Explanation----- Example case 1: Ada can move the first pawn two squares to the left; the board after this move looks like P...P and now, Suzumo can only move the second pawn. If he moves it one square to the left, Ada will move it two squares to the left on her next move, and if he moves it two squares to the left, Ada will move it one square to the left, so the board after Ada's next move will look like PP... and Suzumo cannot make any move here.
["for _ in range(int(input())):\n s = input().strip()\n a = []\n last = 0\n for i in range(len(s)):\n if s[i] == 'P':\n a.append(i - last)\n last = i + 1\n x = 0\n a = a[::-1]\n for v in a[::2]:\n x ^= v % 3\n print('Yes' if x else 'No')"]
{"inputs": [["1", "..P.P"]], "outputs": [["Yes"]]}
INTERVIEW
PYTHON3
CODECHEF
281
6e3b747a0aa7aa1b9b39c0b2474ccf50
UNKNOWN
Two's company, three's a crowd! It's been one year since Chef met his brother. Last year, his younger brother came to visit him during this time of the year. This year, the Chef is planning to go visit his brother. Chef's brother has planned to throw a "Welcome Party" for him. He wants to invite people from his neighbourhood (i.e. from the street where he lives). There are N houses on the street in a single line (not considering the brother's house). He wants the party to be fun and he will not like to invite people who might spoil the mood of the party. If people are invited from three consecutive houses on the street, they might create trouble. As they say, three's a crowd! He doesn't want to ruin the Chef's Welcome Party and so he will not want to send invites to any three consecutive houses. He wants you to tell him how many ways are there for him to go wrong. Note that he can play safe by not inviting anyone to avoid a crowd. -----Input:----- First line of the input contains a single integer T, the number of test cases. Each test case contains a line containing a single integer N described above. -----Output:----- For each test case output a single integer denoting the number of ways the brother can go wrong with planning the party. The answer can get quite large. So output the total number of ways modulo 109+7. -----Constraints:----- 1<=T<=10000 1<=N<=1015 -----Example:-----Input: 2 3 4 Output: 1 3 Explanation: Case 1: The only way he can go wrong is by inviting all the houses. Case 2: First way of getting wrong is by inviting houses (1,2,3). Second way to get wrong is by inviting houses (2,3,4). Third way of going wrong is by inviting all 4 houses i.e. (1,2,3,4).
["MOD = int(1e9+7)\n\ndef mult(a, b):\n rsp = [[0, 0, 0],\n [0, 0, 0],\n [0, 0, 0]]\n\n for i in range(3):\n for j in range(3):\n for k in range(3):\n rsp[i][j] += a[i][k] * b[k][j]\n rsp[i][j] %= MOD\n\n return rsp\n\nident = [[1, 0, 0],\n [0, 1, 0],\n [0, 0, 1]]\nm = [[1, 1, 0],\n [1, 0, 1],\n [1, 0, 0]]\n\npowers = [m]\nfor _ in range(53):\n p = powers[-1]\n powers.append(mult(p ,p))\n\ndef pow2(e):\n y = ident\n i = 0\n for p in powers:\n if e & (1 << i):\n y = mult(p, y)\n i += 1\n return y\n\nt = eval(input())\n\nfor _ in range(t):\n n = eval(input())\n\n if n < 3:\n print(0)\n continue\n\n r = pow(2, n, MOD)\n b = pow2(n - 2)\n # print(b)\n r -= (4 * b[0][0]) % MOD\n r -= (2 * b[1][0]) % MOD\n r -= b[2][0]\n r = (MOD + r) % MOD\n print(r)\n"]
{"inputs": [["2", "3", "4"]], "outputs": [["1", "3"]]}
INTERVIEW
PYTHON3
CODECHEF
784
df98497388e7bf0efb49ca1514daa5ad
UNKNOWN
“I am not in danger, Skyler. I am the danger. A guy opens his door and gets shot, and you think that of me? No! I am the one who knocks!” Skyler fears Walter and ponders escaping to Colorado. Walter wants to clean his lab as soon as possible and then go back home to his wife. In order clean his lab, he has to achieve cleaning level of lab as $Y$. The current cleaning level of the lab is $X$. He must choose one positive odd integer $a$ and one positive even integer $b$. Note that, he cannot change $a$ or $b$ once he starts cleaning. He can perform any one of the following operations for one round of cleaning: - Replace $X$ with $X+a$. - Replace $X$ with $X-b$. Find minimum number of rounds (possibly zero) to make lab clean. -----Input:----- - First line will contain $T$, number of test cases. $T$ testcases follow : - Each test case contains two space separated integers $X, Y$. -----Output:----- For each test case, output an integer denoting minimum number of rounds to clean the lab. -----Constraints----- - $1 \leq T \leq 10^5$ - $ |X|,|Y| \leq 10^9$ -----Sample Input:----- 3 0 5 4 -5 0 10000001 -----Sample Output:----- 1 2 1 -----EXPLANATION:----- - For the first testcase, you can convert $X$ to $Y$ by choosing $a=5$ and $b=2$. It will cost minimum of $1$ cleaning round. You can select any other combination of $a, b$ satisfying above condition but will take minimum of $1$ cleaning round in any case. - For the second testcase, you can convert $X$ to $Y$ by choosing $a=1$ and $b=10$. In first round they will replace $X$ to $X+a$ and then in second round replace to $X-b$. You can perform only one operation in one round.
["t=int(input())\nfor i in range(t):\n ans=0\n x,y=list(map(int,input().split()))\n if y>x:\n if (y-x)%4==0:ans=3\n elif (y-x)%2==0: ans=2\n else: ans=1\n if y<x:\n if (y-x)%2==0:ans=1\n else: ans=2\n print(ans)\n", "# cook your dish here\nfor _ in range(int(input())):\n x,y = map(int,input().split())\n if x == y:\n print(0)\n elif x > y:\n if (x-y)%2==0:\n print(1)\n else:\n print(2)\n else:\n if (y-x)%4 == 0:\n print(3)\n elif (y-x)%2 == 0:\n print(2)\n else:\n print(1)", "for _ in range(int(input())):\n x,y = map(int,input().split())\n if x == y:\n print(0)\n elif x > y:\n if (x-y)%2==0:\n print(1)\n else:\n print(2)\n else:\n if (y-x)%4 == 0:\n print(3)\n elif (y-x)%2 == 0:\n print(2)\n else:\n print(1)", "for _ in range(int(input())):\n # k=int(input())\n a,b=[int(x) for x in input().split()]\n if a==b:\n print(0)\n else:\n if b>a:\n c=b-a\n if c%2!=0:\n print(1)\n else:\n c=c//2\n if c%2==0:\n print(3)\n else:\n print(2)\n else:\n c=a-b\n if c%2!=0:\n print(2)\n else:\n print(1)", "# import math\n# import sys\n# sys.stdin = open('input.txt', 'r')\n# sys.stdout = open('output.txt', 'w')\n\nfor _ in range(int(input())):\n # k=int(input())\n a,b=[int(x) for x in input().split()]\n if a==b:\n print(0)\n else:\n if b>a:\n c=b-a\n if c%2!=0:\n print(1)\n else:\n c=c//2\n if c%2==0:\n print(3)\n else:\n print(2)\n else:\n c=a-b\n if c%2!=0:\n print(2)\n else:\n print(1)", "for i in range(int(input())):\n x,y=list(map(int,input().split()))\n if y>x:\n if (x-y)%4==0:\n print(\"3\")\n elif (x-y)%2==0:\n print(\"2\")\n else:\n print(\"1\")\n elif x>y:\n if (y-x)%2==0:\n print(\"1\")\n else:\n print(\"2\")\n else:\n print(\"0\")\n \n", "# cook your dish here\nfor testcases in range(int(input())):\n x,y=map(int,input(\"\").split())\n z=y-x\n if(z==0):\n print(0)\n elif(z>0):\n if(z%2==0):\n z/=2\n if(z%2==0):\n print(3)\n else:\n print(2)\n else:\n print(1)\n else:\n if(z%2==0):\n print(1)\n else:\n print(2)", "t=int(input())\nfor each in range(t):\n x,y=map(int,input().split())\n if x>y:\n if (x-y)%2==0:\n print(\"1\")\n else:\n print(\"2\")\n elif x<y:\n if (y-x)%2!=0:\n print(\"1\")\n elif (y-x)%2==0 and (y-x)%4!=0:\n print(\"2\")\n else:\n print(\"3\")\n else:\n print(\"0\")", "t=int(input())\nfor each in range(t):\n x,y=map(int,input().split())\n if x>y:\n if (x-y)%2==0:\n print(\"1\")\n else:\n print(\"2\")\n elif x<y:\n if (y-x)%2!=0:\n print(\"1\")\n elif (y-x)%2==0 and (y-x)%4!=0:\n print(\"2\")\n else:\n print(\"3\")\n else:\n print(\"0\")", "# cook your dish here\nt=int(input())\nfor _ in range(t):\n x,y=list(map(int,input().split()))\n if(x>y):\n if(abs(x-y)%2==0):\n print(1)\n else:\n print(2)\n elif(x<y):\n if(abs(x-y)%2!=0):\n print(1)\n elif(abs(x-y)%2==0 and abs(x-y)%4!=0):\n print(2)\n else:\n print(3)\n else:\n print(0)", "test_case = int(input())\n\nwhile test_case > 0:\n x, y = list(map(int, input().split(' ')))\n difference = abs(x - y)\n ans = 0\n if x > y:\n if difference % 2 == 0:\n ans = 1\n else:\n ans = 2\n elif x < y:\n if difference % 2 == 0 and difference % 4 != 0:\n ans = 2\n elif difference % 2 == 1:\n ans = 1\n else:\n ans = 3\n elif x == y:\n ans = 0\n print(ans)\n test_case -= 1\n", "# cook your dish here\ntry:\n for t in range(int(input())):\n x,u = map(int,input().split())\n if(x==u):\n print(0)\n elif(u>x):\n if(abs(u-x)%2==0):\n if(abs(u-x)%4==0):\n print(3)\n else:\n print(2)\n else:\n print(1)\n else:\n if(abs(x-u)%2!=0):\n print(2)\n else:\n print(1)\n\n\n\n\nexcept EOFError as e:\n pass", "# cook your dish here\ntry:\n for t in range(int(input())):\n x,u = map(int,input().split())\n if(x==u):\n print(0)\n elif(u>x):\n if(abs(u-x)%2==0):\n if(abs(u-x)%4==0):\n print(3)\n else:\n print(2)\n else:\n print(1)\n else:\n if(abs(x-u)%2!=0):\n print(2)\n else:\n print(1)\n\n\n\n\nexcept EOFError as e:\n pass", "try:\n for t in range(int(input())):\n x,u = list(map(int,input().split()))\n if(x==u):\n print(0)\n elif(u>x):\n if(abs(u-x)%2==0):\n if(abs(u-x)%4==0):\n print(3)\n else:\n print(2)\n else:\n print(1)\n else:\n if(abs(x-u)%2!=0):\n print(2)\n else:\n print(1)\n\n\n\n\nexcept EOFError as e:\n pass\n", "try:\n t=int(input())\n while(t):\n x,y=input().split()\n x=int(x)\n y=int(y)\n if x==y:\n print(0)\n elif (x<y and (y-x)%2==1)or (x>y and (x-y)%2==0):\n print(1)\n elif x<y and (y-x)%4==0:\n print(3)\n elif x>y and (x-y)%2==1 or x<y and (y-x)%2==0:\n print(2)\n t-=1\nexcept:\n pass", "for t in range(int(input())):\n x,y = map(int, input().split())\n z=x-y\n if x > y:\n if z % 2 == 0:print(1)\n else:print(2)\n elif x < y:\n if z % 2 != 0:print(1)\n elif z % 4 == 0:print(3)\n else:print(2)\n else:print(0)", "t=int(input())\nfor i in range(t):\n w,m=list(map(int,input().split()))\n d=w-m\n if(w>m):\n if(d%2==0):\n print(1)\n else:\n print(2)\n elif(w<m):\n if(d%2!=0):\n print(1)\n elif(d%4==0):\n print(3)\n else:\n print(2)\n else:\n print(0)\n\n", "def check(x,y,count):\n if x == y:\n print(count)\nfor i in range(int(input())):\n count = 0\n x,y = list(map(int, input().split()))\n diff = x-y\n if diff > 0:\n if diff%2==0:\n x = x - diff\n count+=1\n check(x,y,count)\n else:\n x = x - (diff+1)\n count+=1\n x = x + 1\n count+=1\n check(x,y,count)\n elif diff == 0:\n print(\"0\")\n else:\n diff = abs(diff)\n if diff%2!=0:\n x = x + diff\n count+=1\n check(x,y,count)\n elif diff%4==0:\n x = x + (diff+1)\n count+=1\n x = x - (diff+2)\n count+=1\n x = x + (diff+1)\n count+=1\n check(x,y,count)\n else:\n a = diff/2\n x = x + a\n count+=1\n x = x + a\n count+=1\n check(x,y,count)\n", "for _ in range(int(input())):\n x,y=list(map(int,input().split()))\n if y-x==0:\n print(0)\n continue\n if y-x>0:\n if (y-x)%2:\n print(1)\n continue\n if not (y-x)%2 and (y-x)%4:\n print(2)\n continue\n else:\n print(3)\n continue\n if y-x<0:\n if (y-x)%2:\n print(2)\n continue\n else:\n print(1)\n continue\n", "list=[]\nfor i in range(int(input())):\n X,Y=map(int,input().split())\n x=Y-X\n op=0\n if x==0:\n op=0\n elif x>0:\n if x%2!=0:\n op=1\n elif x%4==0:\n op=3\n else:\n op=2\n elif x<0:\n if x%2!=0:\n op=2\n else:\n op=1\n list.append(op)\nfor l in list:\n print(l)", "# cook your dish here\nT=int(input())\nfor _ in range(T):\n X,Y=map(int,input().split())\n diff=abs(X-Y)\n if(X>Y):\n if (diff%2==0):\n ans=1\n else:\n ans=2\n \n elif (X<Y):\n if (diff%2!=0):\n ans=1\n\n elif (diff%4==0):\n ans=3\n\n else:\n ans=2\n\n else:\n ans=0\n\n print(ans)", "n=int(input())\nwhile(n>0):\n a,b=list(map(int,input().split()))\n if b-a==0 :\n print(0)\n elif b-a>0 :\n if (b-a)%2 :\n print(1)\n elif (b-a)%2==0 and (b-a)%4 :\n print(2)\n else:\n print(3)\n else:\n if (b-a)%2:\n print(2)\n else :\n print(1)\n n-=1\n\n\n\n", "for _ in range(int(input())):\n x,y=list(map(int,input().split()))\n if y-x==0:\n print(0)\n continue\n if y-x>0:\n if (y-x)%2:\n print(1)\n continue\n if not (y-x)%2 and (y-x)%4:\n print(2)\n continue\n else:\n print(3)\n continue\n if y-x<0:\n if (y-x)%2:\n print(2)\n continue\n else:\n print(1)\n continue\n", "t=int(input())\nfor i in range(t):\n w,m=list(map(int,input().split()))\n d=w-m\n if(w>m):\n if(d%2==0):\n print(1)\n else:\n print(2)\n elif(w<m):\n if(d%2!=0):\n print(1)\n elif(d%4==0):\n print(3)\n else:\n print(2)\n else:\n print(0)\n\n", "t=int(input())\nfor i in range(t):\n w,m=list(map(int,input().split()))\n d=w-m\n if(w>m):\n if(d%2==0):\n print(1)\n else:\n print(2)\n elif(w<m):\n if(d%2!=0):\n print(1)\n elif(d%4==0):\n print(3)\n else:\n print(2)\n else:\n print(0)\n\n"]
{"inputs": [["3", "0 5", "4 -5", "0 10000001"]], "outputs": [["1", "2", "1"]]}
INTERVIEW
PYTHON3
CODECHEF
8,010
7004c1d9dcf170258c7ddafe88bc2775
UNKNOWN
A string with length $L$ is called rich if $L \ge 3$ and there is a character which occurs in this string strictly more than $L/2$ times. You are given a string $S$ and you should answer $Q$ queries on this string. In each query, you are given a substring $S_L, S_{L+1}, \ldots, S_R$. Consider all substrings of this substring. You have to determine whether at least one of them is rich. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains two space-separated integers $N$ and $Q$. - The second line contains a single string $S$ with length $N$. - Each of the next $Q$ lines contains two space-separated integers $L$ and $R$ describing a query. -----Output----- For each query, print a single line containing the string "YES" if the given substring contains a rich substring or "NO" if it does not contain any rich substring. -----Constraints----- - $1 \le T \le 10$ - $1 \le N, Q \le 10^5$ - $1 \le L \le R \le N$ - $S$ contains only lowercase English letters -----Example Input----- 1 10 2 helloworld 1 3 1 10 -----Example Output----- NO YES
["t=int(input())\n\nfor _ in range(t):\n n,q=map(int,input().split())\n s=input()\n l=[0]*(n-1)\n for i in range(n-2):\n a,b,c=s[i],s[i+1],s[i+2]\n if len(set([a,b,c]))<3:\n l[i]=l[i-1]+1\n else:\n l[i]=l[i-1]\n \n for i in range(q):\n left,right=map(int,input().split())\n left-=1\n right-=1\n if right-left+1 <3:\n print('NO')\n continue\n if (l[right-2]-l[left-1])>0:\n print('YES')\n else:\n print('NO')", "# cook your dish here\nfrom bisect import bisect_left\nfor _ in range(int(input())):\n n,q=map(int,input().split())\n s=input()\n l=[]\n for i in range(n-2):\n a,b,c=s[i],s[i+1],s[i+2]\n if len(set([a,b,c]))<3:\n l.append(i)\n for i in range(q):\n left,right=map(int,input().split())\n left-=1\n right-=1\n if right-left+1 <3:\n print('NO')\n continue\n p1 = bisect_left(l,left)\n if p1!=len(l) and l[p1]<=right-2:\n print('YES')\n else:\n print('NO')", "def precumpute(s, n):\n a = [0 for i in range(n)]\n b = [0 for i in range(n)]\n if n < 3:\n return b\n for i in range(n - 3, -1, -1):\n if s[i] == s[i + 1] or s[i + 1] == s[i + 2] or s[i] == s[i + 2]:\n a[i] = 1\n prev = -1\n for i in range(n - 1, -1, -1):\n if a[i] == 1:\n prev = i\n b[i] = prev\n return b\n\n\ndef solve(b, n, l, r):\n if n < 3:\n print(\"NO\")\n return\n x = b[l]\n if x>=l and x <= r-2:\n print(\"YES\")\n else:\n print(\"NO\")\n\n\ndef read():\n t = int(input())\n for j in range(t):\n n, q = list(map(int, input().strip().split()))\n s = input().strip()\n b = precumpute(s, n)\n for i in range(q):\n l, r = list(map(int, input().strip().split()))\n solve(b, n, l-1, r-1)\n\n\nread()\n", "# cook your dish here\ndef precumpute(s, n):\n a = [0 for i in range(n)]\n b = [0 for i in range(n)]\n if n < 3:\n return b\n for i in range(n - 3, -1, -1):\n if s[i] == s[i + 1] or s[i + 1] == s[i + 2] or s[i] == s[i + 2]:\n a[i] = 1\n # print(a)\n prev = -1\n for i in range(n - 1, -1, -1):\n if a[i] == 1:\n prev = i\n b[i] = prev\n return b\n\n\ndef solve(b, n, l, r):\n if n < 3:\n print(\"NO\")\n return\n x = b[l]\n if x>=l and x <= r-2:\n print(\"YES\")\n else:\n print(\"NO\")\n\n\ndef read():\n t = int(input())\n for j in range(t):\n n, q = list(map(int, input().strip().split()))\n s = input().strip()\n b = precumpute(s, n)\n # print(b)\n for i in range(q):\n l, r = list(map(int, input().strip().split()))\n solve(b, n, l-1, r-1)\n\n\nread()\n", "def isvalid(s):\n if(s[0]==s[1] or s[1]==s[2] or s[0]==s[2]):\n return 1\n return 0\nt=int(input())\nfor you in range(t):\n l=input().split()\n n=int(l[0])\n q=int(l[1])\n s=input()\n count=[0 for i in range(n-2)]\n fre=0\n for i in range(n-2):\n\n if(isvalid(s[i:i+3])):\n fre+=1\n count[i]=fre\n\n for i in range(q):\n l=input().split()\n L=int(l[0])\n R=int(l[1])\n if(R-L+1<3):\n print(\"NO\")\n else:\n if(L==1):\n if(count[R-3]>0):\n print(\"YES\")\n else:\n print(\"NO\")\n else:\n if(count[R-3]-count[L-2]>0):\n print(\"YES\")\n else:\n print(\"NO\")", "# cook your dish here\nT = int(input())\nfor _ in range(T):\n N,Q = [int(b) for b in input().split()]\n S = input()\n b = [0,0]\n l = 0\n for i in range(len(S)-2):\n a = S[i:i+3]\n if(a[0]==a[1] or a[0]==a[2] or a[1]==a[2]):\n l+=1 \n b.append(l)\n # print(b)\n for i in range(Q):\n L,R = [int(b) for b in input().split()]\n if(R-L<2):\n print(\"NO\")\n continue\n if(b[R-1]-b[L]>0):\n print(\"YES\")\n else:\n print(\"NO\")", "# cook your dish here\nimport sys\nfrom math import ceil,floor\nimport bisect\n\nRI = lambda : [int(x) for x in sys.stdin.readline().split()]\nrw = lambda : sys.stdin.readline().strip()\n\nfor _ in range(int(input())):\n n,q = RI()\n st = input()\n bi = []\n for i in range(len(st)-2):\n if st[i] == st[i+1] or st[i] == st[i+2] or st[i+1] == st[i+2]:\n bi.append(i)\n # print(bi)\n for qq in range(q):\n a,b = RI()\n a-=1\n b-=1\n pos = bisect.bisect_right(bi,a-1)\n if pos == len(bi) or bi[pos] + 2 > b:\n print(\"NO\")\n else:\n print(\"YES\")\n", "def compute_rich_substr(s):\n rich = [0 for _ in range(len(s)+1)]\n\n for i in range(len(s) - 2):\n if (s[i] == s[i+1]) or (s[i] == s[i+2]) or (s[i+1] == s[i+2]):\n rich[i+1] = rich[i] + 1\n else:\n rich[i+1] = rich[i]\n\n rich[len(s) - 1] = rich[len(s)] = rich[len(s) - 2]\n return rich\n\n\nt = int(input())\n\nfor _ in range(t):\n n, q = list(map(int, input().strip().split()))\n s = input()\n\n rich = compute_rich_substr(s)\n\n for _ in range(q):\n l, r = list(map(int, input().strip().split()))\n\n if r - l + 1 < 3:\n print(\"NO\")\n elif rich[r - 2] - rich[l - 1] > 0:\n print(\"YES\")\n else:\n print(\"NO\")\n", "for _ in range(int(input())):\n N,Q=map(int,input().split())\n S=input()\n Z=[0]*N\n LC=0\n for I in range(2,N):\n if S[I-2]==S[I-1] or S[I-2]==S[I] or S[I-1]==S[I]:\n LC+=1\n Z[I]=LC\n for I in range(Q):\n L,R=map(int,input().split())\n F=0\n if R-L<2:\n print('NO')\n else:\n if Z[R-1]==Z[L]:\n print('NO')\n else:\n print('YES')", "for _ in range(int(input())):\n N,Q=map(int,input().split())\n S=input()\n Z=[0 for x in range(N)]\n LC=0\n for I in range(2,N):\n if S[I-2]==S[I-1] or S[I-2]==S[I] or S[I-1]==S[I]:\n LC+=1\n Z[I]=LC\n for I in range(Q):\n L,R=map(int,input().split())\n F=0\n if R-L<2:\n print('NO')\n else:\n if Z[R-1]==Z[L]:\n print('NO')\n else:\n print('YES')", "for _ in range(int(input())):\n N,Q=map(int,input().split())\n S=input()\n Z=[0]*N\n LC=0\n for I in range(2,N):\n if S[I-2]==S[I-1] or S[I-2]==S[I] or S[I-1]==S[I]:\n LC+=1\n Z[I]=LC\n for I in range(Q):\n L,R=map(int, input().split())\n F=0\n if R-L<2:\n print('NO')\n else:\n if Z[R-1]==Z[L]:\n print('NO')\n else:\n print('YES')", "for _ in range(int(input())):\n N, Q = map(int, input().split())\n S = input()\n Z = [0]*N\n LC = 0\n for I in range(2, N):\n if S[I-2] == S[I-1] or S[I-2]==S[I] or S[I-1]==S[I]:\n LC+=1\n Z[I] = LC\n for I in range(Q):\n L, R = map(int, input().split())\n F = 0\n if R - L < 2:\n print('NO')\n else:\n if Z[R-1] == Z[L]:\n print('NO')\n else:\n print('YES')", "t=int(input())\nwhile t>0:\n x,q=input().split()\n x=int(x)\n q=int(q)\n s=input()\n list=[]\n list.append(0)\n list.append(0)\n #list.append(0)\n sum=0\n ptr=0\n for i in s:\n # print(i)\n if(ptr+2>(len(s)-1)):\n break\n else:\n a=s[ptr]\n b=s[ptr+1]\n c=s[ptr+2]\n if ((a==b)|(b==c)|(a==c)):\n sum+=1\n list.append(sum) \n \n ptr+=1 \n #print(list) \n while q>0:\n l,r=input().split()\n l=int(l)\n r=int(r)\n if(r-l)<2:\n print(\"NO\")\n else:\n res=list[r-1]-list[l]\n if res>0:\n print(\"YES\")\n else:\n print(\"NO\")\n q-=1\n t-=1 \n", "t=int(input())\nfor _ in range(t):\n n,m=list(map(int,input().split()))\n s=input()\n if n<3:\n for i in range(m):\n a,b=list(map(int,input().split()))\n print('NO')\n else:\n k=[s[0],s[1],s[2]]\n if k[0]==k[1] or k[1]==k[2] or k[0]==k[2]:\n c=1\n else:\n c=0\n ans=[0,c]\n for i in range(3,n):\n del(k[0])\n k.append(s[i])\n if k[0]==k[1] or k[1]==k[2] or k[0]==k[2]:\n c+=1\n ans.append(c)\n for i in range(m):\n a,b=list(map(int,input().split()))\n if b-a<2:\n print('NO')\n continue\n b-=2\n a-=1\n if ans[b]-ans[a]==0:\n print('NO')\n else:\n print('YES')\n \n\n", "from bisect import bisect_left as bl\n\nt=int(input())\nfor i in range(t):\n n,q=map(int,input().split())\n s=input()\n\n c=[]\n for i in range(len(s)-2):\n if s[i]==s[i+1] or s[i+1]==s[i+2] or s[i]==s[i+2]:\n c.append(i+1)\n\n for i in range(q):\n l,r=map(int,input().split())\n x=bl(c,l)\n if len(c)==0 or (r-l)<2 or x==len(c):\n print(\"NO\")\n else:\n st=c[x]\n if st+2<=r:\n print(\"YES\")\n else:\n print(\"NO\")", "for t in range(int(input())):\n n,q=map(int,input().split())\n s=input()\n index=[-1]*n\n temp=-1\n for i in range(n-2):\n if((s[i]==s[i+1]) or (s[i]==s[i+2]) or(s[i+2]==s[i+1])):\n temp=i\n index[i+2]=temp\n for Q in range(q):\n l,r=map(int,input().split())\n if(index[r-1]>=l-1):\n print(\"YES\")\n else:\n print(\"NO\")", "\n\n\nT = int(input())\nfor test in range(T):\n N, Q = [int(v) for v in input().split()]\n S = input()\n start_points = [len(set(S[i:i+3])) < 3 for i in range(N-2)]\n if N < 3:\n count = []\n else:\n counts = [int(start_points[0])]+[0]*(N-3)\n for i in range(1,N-2):\n counts[i] = counts[i-1]+start_points[i]\n # print(\"counts = \"+str(counts))\n for query in range(Q):\n L, R = [int(v) for v in input().split()]\n if L+2 > R:\n print(\"NO\")\n continue\n if L == 1:\n left = 0\n else:\n left = counts[L-2]\n right = counts[R-3]\n # print(\"query = \"+str((L,R))+\" left, right = \"+str((left,right)))\n if left < right:\n print(\"YES\")\n else:\n print(\"NO\")\n", "from itertools import accumulate\nfrom collections import Counter \n\n\ndef is_dominant(ss):\n wc=Counter(ss)\n for i in wc.values():\n if( i > 1 ):\n return True\n return False\n\nt=int(input())\nfor _ in range(t):\n n,q = map(int,input().split(\" \"))\n s=input()\n p = []\n if (n>2):\n for i in range(n-2):\n ss=s[i:i+3]\n if is_dominant(ss):\n val=1\n else:\n val=0\n p.append(val)\n p1=list(accumulate(p))\n for i in range(q):\n l,r=map(int,input().split(\" \"))\n len=r-(l-1)\n if (n<3 or len<3):\n ans=\"NO\"\n else:\n sum=p1[r-3]\n if (l>1):\n sum-=p1[l-2]\n if (sum>0):\n ans=\"YES\"\n else:\n ans=\"NO\"\n print(ans)", "t=int(input())\nfor _ in range(t):\n n,q=map(int,input().split())\n s=input()\n dp=[0]*(n+1)\n for i in range(n-2):\n p=s[i:i+3]\n if p.count(p[0])>=2 or p.count(p[1])>=2:\n dp[i+1]=dp[i]+1\n else:\n dp[i+1]=dp[i]\n for _ in range(q):\n l,r=map(int,input().split())\n if n<3 or (r-l)<2:\n print(\"NO\")\n continue\n if dp[r-2]-dp[l-1]>0:\n print(\"YES\")\n else:\n print(\"NO\")", "# from collections import Counter\n# class Node(object):\n# def __init__(self, start, end):\n# self.start = start\n# self.end = end\n# self.rich = None\n# self.left = None\n# self.right = None\n\n# class SegmentTree(object):\n# def __init__(self):\n# self.root = None\n \n# def addToTree(self, l, r, string):\n# node = Node(l,r)\n\n# if r == len(string) - 1:\n# self.root = Node(l,r)\n# node = self.root\n \n# if r - l < 3:\n# node.rich = False\n# return node\n# else:\n# m = int((l+r)/2)\n# left, right = self.addToTree(l, m, string), self.addToTree(m+1, r, \u00a0\u00a0\u00a0\u00a0string)\n# node.weight = any()\n# node.left = left\n# node.right = right\n# return node\n \n# T = int(input()) \n# for _ in range(T):\n# N, Q = map(int,input().split())\n# string = input()\n# ans = 1\n# for __ in range(Q):\n# L, R = map(int, input().split())\n# if R-L >= 2:\n# L -= 1\n# sub_str = string[L:R]\n# cnt = Counter(sub_str)\n# for value in cnt.values():\n# if value > 2:\n# ans = 0\n# print('yes')\n# break\n# else:\n# ans = 0\n# print('no')\n\n# if ans:\n# print('no')\n\nt=int(input())\nfor _ in range(t):\n n,q=map(int,input().split())\n s=input()\n dp=[0]*(n+1)\n for i in range(n-2):\n p=s[i:i+3]\n if p.count(p[0])>=2 or p.count(p[1])>=2:\n dp[i+1]=dp[i]+1\n else:\n dp[i+1]=dp[i]\n for _ in range(q):\n l,r=map(int,input().split())\n if n<3 or (r-l)<2:\n print(\"NO\")\n continue\n if dp[r-2]-dp[l-1]>0:\n print(\"YES\")\n else:\n print(\"NO\")", "from bisect import *\ndef sub_string(temp,n,l,r):\n index=bisect_left(temp,l-1)\n if(index>=n):\n print('NO')\n return\n if(temp[index]+2<=r-1):\n print(\"YES\")\n else:\n print('NO')\nfor _ in range(int(input())):\n n,q=map(int,input().split())\n s=[x for x in input()]\n temp=[]\n for i in range(n-2):\n if(s[i]==s[i+1] or s[i+1]==s[i+2] or s[i]==s[i+2]):\n temp.append(i)\n n=len(temp)\n for i in range(q):\n l,r=map(int,input().split())\n sub_string(temp,n,l,r)"]
{"inputs": [["1", "10 2", "helloworld", "1 3", "1 10"]], "outputs": [["NO", "YES"]]}
INTERVIEW
PYTHON3
CODECHEF
12,280
2d4a1ca25c2e7d7247c7d5595ff7a2c9
UNKNOWN
Ripul was skilled in the art of lapidary. He used to collect stones and convert it into decorative items for sale. There were n stone shops. Each shop was having one exclusive stone of value s[i] , where 1<=i<=n. If number of stones collected are more than 1, then total value will be product of values of all the stones he collected. Ripul wants to have maximum value of stones he collected. Help Ripul in picking up the subarray which leads to maximum value of stones he collected. -----Input:----- - First line will contain $T$, number of testcases. Then the testcases follow. - The first line of each testcase contains an integer $N$, denoting number of elements in the given array. - The second line contains $N$ space-separated integers $S1$, $S2$, …, $SN$ denoting the value of stone in each shop. -----Output:----- For each testcase, output the maximum value of stones possible, the starting index and ending index of the chosen subarray (0-based indexing). If there are multiple subarrays with same value, print the one with greater starting index. If there are multiple answer subarrays with same starting index, print the one with greater ending index. (The answer will fit in 64 bit binary number). -----Constraints----- - $1 \leq T \leq 10$ - $1 \leq N \leq 10^5$ - $-100 \leq S[i] \leq 100$ -----Subtasks----- - 30 points : $1 \leq N \leq 10^3$ - 70 points : $1 \leq N \leq 10^5$ -----Sample Input:----- 1 3 1 2 3 -----Sample Output:----- 6 1 2 -----EXPLANATION:----- If Ripul collects all the all the three gems, total value will be 6 (1 * 2 * 3). If Ripul collects last two gems, total value will be 6 (1 * 2 * 3). So, he picks the subarray with greater starting index.
["# cook your dish here\nfor u in range(int(input())):\n n=int(input())\n l=list(map(int,input().split()))\n d=[]\n dd=[]\n s=1\n for i in range(n-1):\n s=l[i]\n d.append(s)\n dd.append([i,i])\n for j in range(i+1,n):\n s=s*l[j]\n d.append(s)\n dd.append([i,j])\n d.append(l[n-1])\n dd.append([n-1,n-1])\n k=len(d)\n m=max(d)\n x,y=0,0\n for i in range(k):\n if(d[i]==m):\n x=dd[i]\n print(m,*x)\n", "t=int(input())\nfor i in range(t):\n n=int(input())\n l=[int(x) for x in input().split()]\n s=0\n e=0\n maxi=l[0]\n for i in range(n):\n prod=l[i]\n if prod>maxi:\n maxi=prod\n s=i\n e=i\n if prod==maxi:\n if i>s:\n s=i\n e=i\n if i==s:\n if i>e:\n e=i\n for j in range(i+1,n):\n prod=prod*l[j]\n if prod>maxi:\n maxi=prod\n s=i\n e=j\n if prod==maxi:\n if i>s:\n s=i\n e=j\n if i==s:\n if j>e:\n e=j \n print(maxi,s,e)\n\n \n", "t=int(input())\nwhile(t):\n t=t-1\n n=int(input())\n S=list(map(int,input().split()))\n max1=-1*float(\"inf\")\n for i in range(len(S)):\n p = 1\n for j in range(i,len(S)):\n p = p * S[j] \n if max1 <= p:\n s_i = i\n s_f = j\n max1 = p\n print(max1,s_i,s_f)", "import numpy as np\nfor _ in range(int(input())):\n a = int(input())\n x = [int(i) for i in input().split()]\n mn = -1000\n for i in range(len(x)):\n for j in range(i,len(x)):\n p = x[i:j+1]\n q = np.prod(p)\n if(q>=mn):\n mn = q\n s = i\n l = j\n print(mn,' ',s,' ',l)\n", "import numpy\nfor _ in range(int(input())):\n n=int(input())\n l=list(map(int,input().split()))\n ans=float('-inf')\n iidx=0\n fidx=0\n for i in range(len(l) + 1):\n for j in range(i + 1, len(l) + 1):\n sub = l[i:j]\n\n if len(sub)==0:\n continue\n p=numpy.prod(sub)\n if p>=ans:\n ans=p\n if i>=iidx:\n iidx=i\n if j>=fidx:\n fidx=j\n print(ans,iidx,fidx-1)\n\n"]
{"inputs": [["1", "3", "1 2 3"]], "outputs": [["6 1 2"]]}
INTERVIEW
PYTHON3
CODECHEF
1,873
de4d08e2fe55e8f1a3124628e7ded945
UNKNOWN
Chef wants to gift pairs to his friends this new year. But his friends like good pairs only. A pair (a , b) is called a good pair if 1 <= a < b <= N such that GCD(a*b , P) = 1. Since Chef is busy in preparation for the party, he wants your help to find all the good pairs. ————————————————————————————————————— INPUT • The first line of the input contains a single integer T. • The first and only line of each test case contain two integer N,P. ———————————————————————————————————————— OUTPUT For each test case, print a single line containing one integer — the total number of good pairs ———————————————————————————————————————— CONSTRAINTS • 1 ≤ T≤ 50 • 2 ≤ N,P ≤10^5 ————————————————————————————————————— Example Input 2 2 3 3 3 ———————————————————————————————————————— Example Output 1 1
["# cook your dish here\n \ndef G(x, y): \n while(y): \n x, y = y, x % y \n return x \n# t=int(input())\n# l=list(map(int,input().split()))\nfor _ in range(int(input())):\n n,p=map(int,input().split())\n\n c=0\n for i in range(1,n+1):\n if G(i,p)==1:\n c+=1\n ans=c*(c-1)//2\n print(ans)"]
{"inputs": [["2", "2 3", "3 3", "\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014"]], "outputs": [["1", "1"]]}
INTERVIEW
PYTHON3
CODECHEF
335
6aff4ec7147aa48d923bf3ccbefea31e
UNKNOWN
Forgotten languages (also known as extinct languages) are languages that are no longer in use. Such languages were, probably, widely used before and no one could have ever imagined that they will become extinct at some point. Unfortunately, that is what happened to them. On the happy side of things, a language may be dead, but some of its words may continue to be used in other languages. Using something called as the Internet, you have acquired a dictionary of N words of a forgotten language. Meanwhile, you also know K phrases used in modern languages. For each of the words of the forgotten language, your task is to determine whether the word is still in use in any of these K modern phrases or not. -----Input----- The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows. The first line of a test case description contains two space separated positive integers N and K. The second line of the description contains N strings denoting a dictionary of the forgotten language. Each of the next K lines of the description starts with one positive integer L denoting the number of words in the corresponding phrase in modern languages. The integer is followed by L strings (not necessarily distinct) denoting the phrase. -----Output----- For each test case, output a single line containing N tokens (space-separated): if the ith word of the dictionary exists in at least one phrase in modern languages, then you should output YES as the ith token, otherwise NO. -----Constraints----- - 1 ≤ T ≤ 20 - 1 ≤ N ≤ 100 - 1 ≤ K, L ≤ 50 - 1 ≤ length of any string in the input ≤ 5 -----Example----- Input: 2 3 2 piygu ezyfo rzotm 1 piygu 6 tefwz tefwz piygu ezyfo tefwz piygu 4 1 kssdy tjzhy ljzym kegqz 4 kegqz kegqz kegqz vxvyj Output: YES YES NO NO NO NO YES
["test_case = int(input())\nfor w in range(test_case):\n n, k = map(int,input().split())\n l = list(map(str,input().split()))\n ans = []\n for q in range(k):\n l2 = list(map(str,input().split()))\n ans.extend(l2[1:])\n for i in l:\n if i in ans:\n print('YES',end=' ')\n else:\n print('NO',end=' ')\n print()# cook your dish here\n", "# cook your dish here\nt=int(input())\nfor w in range(t):\n n,k=map(int,input().split())\n l=list(map(str,input().split()))\n ans=[]\n for q in range(k):\n l2=list(map(str,input().split()))\n ans.extend(l2[1:])\n for i in l:\n if i in ans:\n print('YES',end=' ')\n else:\n print('NO',end=' ')\n print()", "t=int(input())\nfor i in range(t):\n n,k=list(map(int,input().split()))\n strings=input().split()\n res=\"\"\n for i in range(k):\n modernlanguage=input().split()\n modernlanguage.remove(modernlanguage[0])\n res=res+\"\".join(modernlanguage)\n res1=[]\n for i in range(len(strings)):\n if(strings[i] in res):\n res1.append(\"YES\")\n else:\n res1.append(\"NO\")\n print(*res1)\n \n \n", "# cook your dish here\nt = int(input())\nfor i in range(t):\n N, K = map(int, input().split())\n dict = list(map(str, input().split()))\n mod_pharse = []\n for m in range(K):\n l = list(map(str, input().split()))\n mod_pharse.extend(l[1:])\n\n for i in dict:\n\n if i in mod_pharse:\n\n print('YES', end=' ')\n else:\n print('NO', end=' ')\n print()\n", "# cook your dish here\ntry:\n test_cases = int(input())\n for _ in range(test_cases):\n n, k = input().split()\n dictOfForgottenWord = list(input().split())\n modernDict = ''\n for i in range(int(k)):\n modernDict += \" \"+input()\n\n newModernDict = list(set(list(modernDict.split(\" \"))))\n\n for i in dictOfForgottenWord:\n if i in newModernDict:\n print(\"YES\", end=' ')\n else:\n print(\"NO\", end=' ')\n print()\n\nexcept:\n pass", "n = int(input())\nl, dictonary = [], []\nfor i in range(n):\n listSize, numOfDict = map(int, input().split())\n listOfelement = list(map(str, input().split()))\n for i in range(numOfDict):\n dictonary += list(map(str, input().split()))\n for ele in listOfelement:\n if ele in dictonary:\n l.append('YES')\n else:\n l.append('NO')\n for out in l:\n print(out, end=' ')\n print()\n dictonary, l = [], []\n \n\n\n", "t=int(input())\ni=0\nwhile i<t:\n n,k=input().split()\n n=int(n)\n k=int(k)\n s=[]\n ans=[0]*n\n s=input().split()\n j=0\n while j<k:\n l=[]\n l=input().split()\n m=0\n while m<n:\n if s[m] in l:\n ans[m]=1\n m+=1\n j+=1\n d=0\n while d<n:\n if ans[d]==0:\n print(\"NO\",end=\" \")\n else:\n print(\"YES\",end=\" \")\n d+=1\n print(\"\")\n i+=1", "def p_input():\n tot = int(input())\n dicts = []\n for i in range(tot):\n n = [int(x) for j, x in enumerate(input().split()) if j < 2 ]\n dicts = input().split()[:n[0]]\n sents = []\n for _ in range(n[1]):\n sent = input().split()\n sents += sent[1:int(sent[0]) + 1]\n print(' '.join('YES' if x in sents else 'NO' for x in dicts))\n\n\ndef __starting_point():\n p_input()\n \n\n__starting_point()", "# cook your dish here\ntest = int(input())\n\nfor _ in range(0,test):\n words , phrases = map(int,input().split())\n listOfPhrases = set()\n words = list(input().split())\n for _ in range(0,phrases):\n newset = set(input().split())\n listOfPhrases = listOfPhrases.union(newset)\n for x in words:\n if x in listOfPhrases:\n print('YES',end=' ')\n else:\n print('NO',end=' ')\n print()", "# cook your dish here\n#For each test case, output a single line containing N tokens (space-separated): \u00a0\u00a0\u00a0\u00a0if the ith word of the dictionary exists in at least one phrase in modern \u00a0\u00a0\u00a0\u00a0languages, then you should output YES as the ith token, otherwise NO.\n#Constraints\n#1 \u2264 T \u2264 20\n#1 \u2264 N \u2264 100\n#1 \u2264 K, L \u2264 50\n#1 \u2264 length of any string in the input \u2264 5\n#Example\n#Input:\n#2\n#3 2\n#piygu ezyfo rzotm\n#1 piygu\n#6 tefwz tefwz piygu ezyfo tefwz piygu\n#4 1\n#kssdy tjzhy ljzym kegqz\n#4 kegqz kegqz kegqz vxvyj\n\n#Output:\n#YES YES NO \n#O NO NO YES \n\n\ntest = int(input())\n\nfor _ in range(0,test):\n words , phrases = map(int,input().split())\n listOfPhrases = set()\n words = list(input().split())\n for _ in range(0,phrases):\n newset = set(input().split())\n listOfPhrases = listOfPhrases.union(newset)\n for x in words:\n if x in listOfPhrases:\n print('YES',end=' ')\n else:\n print('NO',end=' ')\n print()\n \n", "for _ in range(int(input())) :\n n, k = map(int, input().split())\n s = list(map(str, input().split()))\n li = []\n t = 0\n for i in range(k) :\n a = list(map(str, input().split()))\n l = len(a)\n for j in range(l) :\n li.append(a[j])\n d = []\n for i in range(n) :\n if s[i] in li :\n d.append('YES')\n else :\n d.append('NO')\n print(*d)", "for _ in range(int(input())) :\n n, k = map(int, input().split())\n s = list(map(str, input().split()))\n li = []\n t = 0\n for i in range(k) :\n a = list(map(str, input().split()))\n l = len(a)\n for j in range(l) :\n li.append(a[j])\n d = []\n for i in range(n) :\n if s[i] in li :\n d.append('YES')\n else :\n d.append('NO')\n print(*d)", "try:\n # cook your code here\n t = int(input())\n while t > 0:\n n, q = map(int, input().split())\n A = [j for j in input().split()]\n tmp = []\n while q > 0:\n tmp += [j for j in input().split()]\n q -= 1\n i = 0\n while n > i:\n if A[i] in tmp:\n print(\"YES\", end=' ')\n else:\n print(\"NO\", end=' ')\n i += 1\n print()\n t -= 1\nexcept:\n pass", "# cook your dish here\nT = int(input())\n\nfor t in range(T):\n phrases = []\n numword, numphrases = input().split()\n words = input().split()\n for phrase in range(int(numphrases)):\n phrase = input().split()\n phrase = phrase[1:]\n for word in phrase: \n phrases.append(word)\n for count in range(len(words)):\n if words[count] in phrases:\n print(\"YES\", end=\" \")\n else:\n print(\"NO\", end=\" \")\n print(\"\\n\", end=\"\")", "t = int(input())\nfor _ in range(t):\n n,k = map(int,input().split())\n old = input().split()\n a = [input() for i in range(k)]\n d = {}\n for j in old:\n d[j]=\"NO\"\n for i in old:\n for j in a:\n if d.get(i) == \"NO\":\n if i in j:\n d[i] = \"YES\"\n b = [i for i in d.values()]\n print(*b)", "# cook your dish here\nt=int(input())\n\nfor i in range(t):\n n,k=map(int,input().split())\n l=[]\n l1=list(map(str,input().split()))\n for i in range(k):\n l2=list(map(str,input().split()))\n l=l+l2\n for a in l1:\n if a in l:\n print(\"YES\",end=\" \")\n else:\n print(\"NO\",end=\" \")\n \n print()", "for _ in range(int(input())):\n n, k = map(int,input().split())\n a = [x for x in input().split()]\n s = set()\n for i in range(k):\n for w in input().split():\n s.add(w)\n ans = []\n for i in range(n):\n ans.append('YES') if a[i] in s else ans.append('NO')\n print(' '.join(ans))", "t=int(input())\nans1=list()\nfor i in range(t):\n n=list(map(int,input().split()))\n s=list(map(str,input().split()))\n ans=list()\n for j in range(n[1]):\n a=list(map(str,input().split()))\n ans.append(a)\n d=list() \n for j in ans:\n d=d+j\n yo=\"\" \n for k in range(len(s)):\n if s[k] in d:\n yo=yo+\"YES\"+\" \"\n else:\n yo=yo+\"NO\"+\" \"\n ans1.append(yo)\nfor l in ans1:\n print(l)", "# cook your dish here\nfor _ in range(int(input())):\n n,k = map(int,input().split())\n word = list(input().split())\n li = []\n for x in range(k):\n l = list(input().split())\n li += l\n for x in word:\n if x in li:\n print(\"YES\",end=\" \")\n else:\n print(\"NO\",end=\" \")\n print()", "# cook your dish here\nfor _ in range(int(input())):\n n,k=map(int,input().split())\n l=[]\n ln=list(map(str,input().split()))\n for i in range(k):\n lk=list(map(str,input().split()))\n l=l+lk\n for a in ln:\n if a in l:\n print(\"YES\",end=\" \")\n else:\n print(\"NO\",end=\" \")\n print()", "# cook your dish here\nfor _ in range(int(input())):\n n,k=map(int,input().split())\n ns=[i for i in input().split()]\n d={}\n for i in ns:\n d[i]=False\n for i in range(k):\n ks=list(map(str,input().split()))\n for j in ks:\n if j in d:\n d[j]=True\n for i in ns:\n if d[i]==True:\n print(\"YES\",end=' ')\n else :\n print(\"NO\",end=' ')\n \n print()\n ", "# cook your dish here\nt=int(input())\nfor i in range(0, t):\n n,k=[int(n) for n in input().split()]\n a=input().split()\n b=[]\n for j in range(0,k):\n x=input().split()\n for p in range(1,len(x)):\n b.append(x[p])\n r=0\n for r in range(0,len(a)):\n if b.__contains__(a[r]):\n print('YES',end=\" \")\n else:\n print(\"NO\",end=\" \")\n print(\" \")", "T = int(input())\nfor i in range(0, T):\n N, K = [int(N) for N in input().split()]\n a = input().split()\n b = []\n for j in range(0, K):\n x = input().split()\n for t in range(1, len(x)):\n b.append(x[t])\n r = 0\n for r in range(0, len(a)):\n if b.__contains__(a[r]):\n print('YES', end=' ')\n else:\n print(\"NO\", end=\" \")\n print(' ')", "'''\n Problem : Mahasena\n Author @ Rakesh Kumar\n [email protected]\n Date : 29/01/2021\n'''\n\ndef solve():\n for _ in range(int(input())):\n n, k = map(int, input().split())\n aitihasik_bhasa = list(map(str, input().split()))\n d = {}\n for b in aitihasik_bhasa:\n d[b] = False\n for _ in range(k):\n vakya = list(map(str, input().split()))\n vakya = vakya[1:]\n for v in vakya:\n if v in d:\n d[v] = True\n for v in aitihasik_bhasa:\n if d[v]:\n print('YES', end=' ')\n else:\n print('NO', end=' ')\n print()\n\ndef __starting_point():\n solve()\n\n__starting_point()", "# cook your dish here\nt = int(input())\nfor z in range(t) :\n a,b = [int(x) for x in input().split()]\n s = input().split()\n x = []\n for i in range(b) :\n y = input().split()\n x = x + y \n l = set(x)\n for i in s:\n if i in l:\n print(\"YES\",end=' ')\n else:\n print(\"NO\",end=' ')\n print()"]
{"inputs": [["2", "3 2", "piygu ezyfo rzotm", "1 piygu", "6 tefwz tefwz piygu ezyfo tefwz piygu", "4 1", "kssdy tjzhy ljzym kegqz", "4 kegqz kegqz kegqz vxvyj"]], "outputs": [["YES YES NO", "NO NO NO YES"]]}
INTERVIEW
PYTHON3
CODECHEF
9,962
d826e2b3b0c4fa81a538223ac24166ac
UNKNOWN
You're given an integer N. Write a program to calculate the sum of all the digits of N. -----Input----- The first line contains an integer T, the total number of testcases. Then follow T lines, each line contains an integer N. -----Output----- For each test case, calculate the sum of digits of N, and display it in a new line. -----Constraints----- - 1 ≤ T ≤ 1000 - 1 ≤ N ≤ 1000000 -----Example----- Input 3 12345 31203 2123 Output 15 9 8
["# cook your dish here\nnumber = int(input())\nfor i in range(number):\n a = list(input())\n for k in range(len(a)):\n a[k] = eval(a[k])\n print(sum(a))", "T=int(input())\nwhile(T!=0):\n t=int(input())\n sum=0\n while(t!=0):\n a=t%10\n sum=sum+a\n t=t//10\n print(sum)\n T-=1", "# cook your dish here\r\ntcases = int(input())\r\nfor x in range(0, tcases):\r\n list = []\r\n n = int(input())\r\n sum = 0\r\n for y in range(0, len(str(n))):\r\n list.append(n % 10)\r\n n = n // 10\r\n for i in list:\r\n sum = sum + i\r\n print(sum)\r\n \r\n", "# cook your dish here\r\ntcases = int(input())\r\nfor x in range(0, tcases):\r\n list = []\r\n n = int(input())\r\n sum = 0\r\n for y in range(0, len(str(n))):\r\n list.append(n % 10)\r\n n = n // 10\r\n for i in list:\r\n sum = sum + i\r\n print(sum)\r\n \r\n", "# cook your dish here\nx=int(input())\nfor i in range(x):\n a=input()\n arr=[]\n for i in a:\n i=int(i)\n arr.append(i)\n print(sum(arr))", "# cook your dish here\nn=int(input())\nfor _ in range(n):\n a=int(input())\n sum=0\n while a>0:\n rem=a%10\n sum=sum+rem\n a=a//10\n print(sum)\n", "n = int(input())\r\nsuma = []\r\nfor i in range (0,n):\r\n x = input()\r\n x = list(x)\r\n a=0\r\n for i in x:\r\n a = a + int(i)\r\n suma.append(a)\r\nfor i in suma:\r\n print(i)", "n=int(input())\nfor t in range (n):\n t=int(input())\n sum=0\n while(t>0):\n sum=sum+t%10\n t=t//10\n print(sum)", "ans = 0\nt = int(input())\ni = 1\nwhile (i<=t):\n n = int(input())\n ans = 0\n while (n>0):\n ans += n%10\n n = int(n/10)\n if (n>0):\n continue\n i = i+1\n print(ans)", "# cook your dish here\nt=int(input())\nfor a in range (t):\n n=int(input())\n sum=0\n while(n>0):\n r=n%10\n sum=sum+r\n n=n//10\n print(sum)", "# cook your dish here\nn = int(input())\nwhile n>0:\n s = list(map(int,input().strip()))\n print(sum(s))\n n = n-1", "for _ in range(int(input())):\n sum=0\n n=str(input())\n for i in n:\n sum+=int(i)\n print(sum)\n", "# cook your dish here\nt = int(input())\nfor b in range(t):\n n = int(input())\n tot = 0\n while(n>0):\n dig=n%10\n tot = tot+dig\n n= n//10\n print(tot)", "n=int(input())\r\nmylist=[]\r\nwhile(n>0):\r\n\tnum=int(input())\r\n\tsum=0\r\n\twhile(num>0):\r\n\t\trem=num%10\r\n\t\tsum+=rem\r\n\t\tnum=num//10\r\n\tmylist.append(sum)\r\n\tn=n-1\r\nfor i in mylist:\r\n\tprint(i)\r\n\t\r\n", "n= int(input())\nfor i in range(n):\n a= int(input())\n s=0\n while a!=0:\n s+=a%10\n a=int(a/10)\n print(s)", "# cook your dish here\nnum=int(input())\ns=0\nfor i in range(num):\n n=input()\n for r in n:\n s=s+int(r)\n print(s)\n s=0", "# cook your dish here\nnum=int(input())\ns=0\nfor i in range(num):\n n=input()\n for r in n:\n s=s+int(r)\n print(s)\n s=0", "for _ in range (int(input())):\n l=list(map(int,input()))\n print(sum(l))\n", "# cook your dish here\nt = int(input())\nfor i in range(t):\n n = input()\n s = 0\n for i in n:\n s += int(i)\n print(s)", "def addition():\r\n number=input()\r\n sum=0\r\n for i in number:\r\n sum+=int(i)\r\n print(sum)\r\n\r\n\r\nfor j in range(int(input())):\r\n addition()", "# cook your dish here\ndef add():\n n=input()\n sum=0\n for i in n:\n sum+=int(i)\n print(sum)\n\n\nfor _ in range(int(input())):\n add()", "# cook your dish here\nn=int(input())\na=[]\nfor i in range (0,n):\n no=int(input())\n a.append(no)\nfor i in range (0,n):\n s=0\n while (a[i]!=0):\n c=a[i]%10\n s=s+c\n a[i]=a[i]//10\n print(s)\n \n", "t=int(input())\r\nwhile(t!=0):\r\n n=int(input())\r\n sum=0\r\n while(n!=0):\r\n temp=n%10\r\n sum=sum+temp\r\n n=n//10\r\n print(sum)\r\n t-=1 ", "t=int(input())\r\nwhile(t!=0):\r\n n=int(input())\r\n sum=0\r\n while(n!=0):\r\n temp=n%10\r\n sum=sum+temp\r\n n=n//10\r\n print(sum)\r\n t-=1 ", "t=int(input())\r\nwhile(t!=0):\r\n n=int(input())\r\n sum=0\r\n while(n!=0):\r\n temp=n%10\r\n sum=sum+temp\r\n n=n//10\r\n print(sum)\r\n t-=1 "]
{"inputs": [["3", "12345", "31203", "2123"]], "outputs": [["15", "9", "8"]]}
INTERVIEW
PYTHON3
CODECHEF
4,535
61bc83fff885726bcfd4fa78f5831efd
UNKNOWN
You are given Name of chef's friend and using chef's new method of calculating value of string , chef have to find the value of all the names. Since chef is busy , he asked you to do the work from him . The method is a function $f(x)$ as follows - - $f(x)$ = $1$ , if $x$ is a consonent - $f(x)$ = $0$ , if $x$ is a vowel Your task is to apply the above function on all the characters in the string $S$ and convert the obtained binary string in decimal number N. Since the number N can be very large, compute it modulo $10^9+7$ . Input: - First line will contain $T$, number of testcases. Then the testcases follow. - Each test line contains one String $S$ composed of lowercase English alphabet letters. -----Output:----- For each case, print a single line containing one integer $N$ modulo $10^9+7$ . -----Constraints----- - $1 \leq T \leq 50$ - $1 \leq |S| \leq 10^5$ -----Sample Input:----- 1 codechef -----Sample Output:----- 173 -----EXPLANATION:----- The string "codechef" will be converted to 10101101 ,using the chef's method function . Which is equal to 173.
["\n\nvow = ['a', 'e', 'i','o', 'u']\nfor _ in range(int(input())):\n name = str(input())\n tmp = ''\n for i in range(len(name)):\n if name[i] not in vow and name[i].isalpha():\n tmp+='1'\n elif name[i] in vow and name[i].isalpha():\n tmp+='0'\n \n print( int(tmp, 2)% (10**9 + 7))", "# cook your dish here\nt = int(input())\n#inputs\nfor _ in range(t):\n # taking string \n s = input()\n l1 = list()\n for i in s:\n l1.append(i)\n \n #cheacking\n l2 = list()\n a = '0'\n b = '1'\n for i in l1:\n if i.isalpha():\n if i == \"a\" or i == \"e\" or i == \"i\" or i == \"o\" or i == \"u\":\n l2.append(a)\n else:\n l2.append(b)\n \n l2 = ('').join(l2)\n # l2 = int(l2)\n x = [\"0b\",l2]\n x = \"\".join(x)\n x = eval(x)\n print(x)", "t=int(input())\nfor _ in range(t):\n s=input()\n l=['a','e','i','o','u']\n x=''\n for i in range(len(s)):\n if s[i] in l or s[i]==' ':\n x+='0'\n else:\n if s[i].islower():\n x+='1'\n k=int(x,2)\n print(k%1000000007)\n \n \n", "# cook your dish here\n\"\"\"\nCreated on Sat May 23 22:56:03 2020\n\n@author: aurouS_EeRiE\n\"\"\"\n\n\nfor _ in range(int(input())):\n vowel = ['a', 'e', 'i', 'o', 'u']\n s = input()\n temp = \"\"\n for i in s:\n if i in vowel:\n temp += '0'\n elif i.isalpha():\n temp += '1'\n print(int(temp, 2) % ((10 ** 9) + 7))\n \n", "# cook your dish here\nl='aeiou'\nll='bcdfghjklmnpqrstvwxyz'\nfor u in range(int(input())):\n s=input()\n r=''\n for i in range(len(s)):\n if(s[i] in l):\n r=r+'0'\n elif(s[i] in ll):\n r=r+'1'\n b=int(r,2)\n print(b%(1000000007))\n", "y = 10**9 + 7\nvo='aeiouAEIOU'\nfor _ in range(int(input())):\n s = ''.join(input().split())\n v=0\n x=0\n b= [1 if i not in vo else 0 for i in s[::-1]]\n for i in b:\n if i==1:\n v+=2**x\n x+=1\n print(v%y)", "# cook your dish here\nM=10**9+7\nfor _ in range(int(input())):\n s=input()\n c=\"\"\n d=[ord(\"a\"),ord(\"e\"),ord(\"i\"),ord(\"o\"),ord(\"u\")]\n for i in s:\n if ord(i) in d:\n c+=\"0\"\n elif 97<=ord(i)<=122:\n c+=\"1\"\n print(int(c,2)%M)", "\"\"\"\nCreated on Sat May 23 22:12:36 2020\n\nTitle: Value of Name\n\nContest: LockDown Test 4.0 \n\n@author: mr._white_hat_\n\"\"\"\n\nfor _ in range(int(input())):\n T = input()\n S = ''\n for i in T:\n if i in ('a', 'e', 'i', 'o', 'u'):\n S += '0'\n elif i.isalpha():\n S += '1'\n print(int(S, 2) % 1000000007)", "for _ in range(int(input())):\n name = str(input())\n c = 0\n for a in name:\n if a.isalpha():\n if a == 'a' or a == 'e' or a == 'i' or a == 'o' or a == 'u': \n c = c*10 + 0\n else:\n c = c*10 + 1 \n \n s = str(c)\n a = int(s,2)\n print(a % (10**9 + 7) )\n", "from sys import stdin,stdout\nfrom collections import defaultdict \nt=int(stdin.readline())\nfor _ in range(t):\n s=stdin.readline().strip()\n n=len(s)\n z=0\n for i in range(n):\n if(s[i]=='a' or s[i]=='e' or s[i]=='i' or s[i]=='o' or s[i]=='u'):\n continue\n else:\n z+=2**(n-i-1)\n print(z%1000000007)\n", "test=int(input())\nfor _ in range(test):\n s=input()\n a=\"\"\n for i in s:\n if i != \"\\r\":\n if i in [\"a\",\"e\",\"i\",\"o\",\"u\"]:\n a+=\"0\"\n else:\n a+=\"1\"\n ans=int(a,2)\n print(ans%(1000000000+7))\n", "# cook your dish here\nT = int(input())\n\nfor t in range(T):\n a = input()\n bin = \"\"\n for i in a:\n if i.isalpha():\n if i in [\"a\",\"e\",\"i\",\"o\",\"u\"]:\n bin += \"0\"\n else:\n bin += \"1\"\n print( int(bin,2) % 1000000007)", "t=int(input())\nA=\"aeiou\"\nB=\"bcdfghjklmnpqrstvwxyz\"\nfor _ in range(t):\n s=str(input())\n c=\"\"\n for i in range(len(s)):\n x=\"\"\n if s[i] in A:\n x=\"0\"\n if s[i] in B:\n x=\"1\"\n c=c+x\n \n w=10**9\n w=w+7\n k=int(c,2)\n print(k%w)\n", "t = int(input())\nmod = 10**9 + 7\nfor _ in range(t):\n s = input().strip()\n ss = ''\n for x in s:\n if x in ['a', 'e', 'i', 'o', 'u']:\n ss += '0'\n else:\n ss += '1'\n\n ans = 0\n print(int(ss, 2)%mod)\n # for i in range(len(ss)-1, -1, -1):\n # if ss[i] == '1':\n # ans += pow(2, len(ss)-1-i, mod)\n # print(ans%mod)\n", "for _ in range(int(input().strip())):\n s = list(input().strip())\n n = len(s)\n MOD = 1000000007\n vow = ['a' , 'e' , 'i' , 'o' , 'u']\n K = \"\"\n for i in range(n):\n if s[i] not in vow:\n K = K + \"1\"\n else:\n K = K + \"0\"\n co = int(K,2)\n print(str(co%MOD))"]
{"inputs": [["1", "codechef"]], "outputs": [["173"]]}
INTERVIEW
PYTHON3
CODECHEF
4,293
4a8e13d8686fbda363f5eeed9cf9014d
UNKNOWN
Bears love candies and games involving eating them. Limak and Bob play the following game. Limak eats 1 candy, then Bob eats 2 candies, then Limak eats 3 candies, then Bob eats 4 candies, and so on. Once someone can't eat what he is supposed to eat, he loses. Limak can eat at most A candies in total (otherwise he would become sick), while Bob can eat at most B candies in total. Who will win the game? Print "Limak" or "Bob" accordingly. -----Input----- The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows. The only line of each test case contains two integers A and B denoting the maximum possible number of candies Limak can eat and the maximum possible number of candies Bob can eat respectively. -----Output----- For each test case, output a single line containing one string — the name of the winner ("Limak" or "Bob" without the quotes). -----Constraints----- - 1 ≤ T ≤ 1000 - 1 ≤ A, B ≤ 1000 -----Example----- Input: 10 3 2 4 2 1 1 1 2 1 3 9 3 9 11 9 12 9 1000 8 11 Output: Bob Limak Limak Bob Bob Limak Limak Bob Bob Bob -----Explanation----- Test case 1. We have A = 3 and B = 2. Limak eats 1 candy first, and then Bob eats 2 candies. Then Limak is supposed to eat 3 candies but that would mean 1 + 3 = 4 candies in total. It's impossible because he can eat at most A candies, so he loses. Bob wins, and so we print "Bob". Test case 2. Now we have A = 4 and B = 2. Limak eats 1 candy first, and then Bob eats 2 candies, then Limak eats 3 candies (he has 1 + 3 = 4 candies in total, which is allowed because it doesn't exceed A). Now Bob should eat 4 candies but he can't eat even a single one (he already ate 2 candies). Bob loses and Limak is the winner. Test case 8. We have A = 9 and B = 12. The game looks as follows: - Limak eats 1 candy. - Bob eats 2 candies. - Limak eats 3 candies (4 in total). - Bob eats 4 candies (6 in total). - Limak eats 5 candies (9 in total). - Bob eats 6 candies (12 in total). - Limak is supposed to eat 7 candies but he can't — that would exceed A. Bob wins.
["for t in range(int(input())):\n limakMax, bobMax = list(map(int, input().split()))\n limakEat = 0; bobEat = 0\n eating = 1\n while limakEat <= limakMax or bobEat <= bobMax:\n\n if eating % 2 != 0 and limakEat <= limakMax:\n limakEat += eating\n eating += 1\n if limakEat > limakMax:\n print(\"Bob\")\n break\n elif eating % 2 == 0 and bobEat <= bobMax:\n bobEat += eating\n eating += 1\n if bobEat > bobMax:\n print(\"Limak\")\n break\n\n", "# cook your dish here\nT = int(input())\n\nfor t in range(T):\n n = 1\n b = 0\n l = 0\n llimit, blimit = input().split()\n blimit = int(blimit)\n llimit = int(llimit)\n \n while True:\n if n % 2 == 0:\n if b + n <= blimit:\n b += n\n n += 1\n else:\n print(\"Limak\")\n break\n else:\n if l + n <= llimit:\n l += n\n n += 1\n else:\n print(\"Bob\")\n break\n", "# cook your dish here\nfor i in range(int(input())):\n a,b=list(map(int,input().split()))\n limak,bob=0,0\n winner=''\n i=1\n while(i<10000):\n if i%2!=0:\n limak+=i\n if limak>a:\n winner='Bob'\n break\n else:\n bob+=i\n if bob>b:\n winner='Limak'\n break\n i+=1\n print(winner)\n", "t=int(input())\nfor i in range(t):\n a,b=list(map(int,input().split()))\n n=1\n m=2\n k=0\n l=0\n while n<=a:\n k+=1\n a-=n\n n+=2\n while m<=b:\n l+=1\n b-=m\n m+=2\n if k==l:\n print(\"Bob\")\n elif k<l:\n print(\"Bob\")\n elif k>l:\n print(\"Limak\")\n", "# cook your dish here\nx = int(input())\nfor i in range(x):\n a, b = map(int, input().split())\n n = 1\n m = 2\n k = 0\n l = 0\n while n<=a:\n k += 1\n a -= n\n n += 2\n while m<=b:\n l += 1\n b -= m\n m += 2\n if k==l:\n print(\"Bob\")\n elif k<l:\n print(\"Bob\")\n elif k>l:\n print(\"Limak\")", "# cook your dish here\nt=int(input())\nfor i in range(t):\n a,b=map(int,input().split())\n l=1\n m=2\n flag=0\n n=3\n while l<=a and m<=b:\n if flag==0:\n l=l+n\n flag=1\n n=n+1\n else:\n m=m+n\n flag=0\n n=n+1\n if l>a:\n print(\"Bob\")\n else:\n print(\"Limak\")", "# Program to print the winner of the candy party among limak and Bob\n\n\ndef winner(a, b):\n sumodd, sumeven = 0, 0\n even = 0\n if (a >= 1) and (a <= 1000) and (b <= 1000) and (b >= 1):\n for i in range(500):\n if sumodd > a:\n return 'Bob'\n if sumeven > b:\n return 'Limak'\n even += 2\n sumeven += even\n sumodd += even-1\n else:\n print(\"Enter a valid value of a and b.\")\n\n\nT = int(input())\nmylist = []\nif (T >= 1) and (T <= 1000):\n for i in range(T):\n a, b = input().split(' ')\n mylist.append([int(a), int(b)])\nelse:\n print(\"Enter a valid limit\")\n\nfor i in range(T):\n print(winner(mylist[i][0], mylist[i][1]))\n\n\n", "# cook your dish here\ndef gcd(x, y):\n while y:\n x, y = y, x % y\n return x\n\ndef lcm(x, y):\n return (x*y)//(gcd(x,y))\n\ndef isPrime(n) : \n if (n <= 1) : \n return False\n if (n <= 3) : \n return True\n if (n % 2 == 0 or n % 3 == 0) : \n return False\n i = 5\n while(i * i <= n) : \n if (n % i == 0 or n % (i + 2) == 0) : \n return False\n i = i + 6\n return True\n\nabc=\"abcdefghijklmnopqrstuvwxyz\"\n\npi=3.141592653589793238\n\n#n = int(input())\n#arr = list(map(int,input().split()))\n\nt = int(input())\nfor _ in range(t):\n a,b = list(map(int,input().split()))\n i = 1\n while(1):\n a=a-i\n if(a<0):\n flag = False\n break\n i = i+1\n b=b-i\n if(b<0):\n flag = True\n break\n i = i+1\n \n if(not flag):\n print('Bob')\n else:\n print('Limak')\n \n \n \n#Output:\n# Bob\n# Limak\n# Limak\n# Bob\n# Bob\n# Limak\n# Limak\n# Bob\n# Bob\n# Bob\n\n", "# cook your dish here\nfor _ in range(int(input())):\n a,b=map(int,input().split())\n i=1\n limak=bob=0\n while True:\n limak+=i\n bob+=i+1\n i+=2\n if limak>a:\n print('Bob')\n break\n elif bob>b:\n print('Limak')\n break", "# cook your dish here\nt = int(input())\nfor i in range(t):\n a,b = map(int,input().split())\n li=bo=0\n c=1\n while True:\n #print(li,bo)\n li=li+c \n bo=bo+c+1 \n c+=2\n if li>a:\n print(\"Bob\") \n break\n elif bo>b:\n print(\"Limak\")\n break", "for t in range(int(input())):\n a,b=map(int, input().split())\n for i in range(1,501,2):\n a-=i\n if a<0:\n print(\"Bob\")\n break\n b-=(i+1)\n if b<0:\n print(\"Limak\")\n break", "t=int(input())\nwhile t>0:\n l,b=map(int,input().split(\" \")) \n li=bo=0\n c=1\n while True:\n #print(li,bo)\n li=li+c \n bo=bo+c+1 \n c+=2\n if li>l:\n print(\"Bob\") \n break\n elif bo>b:\n print(\"Limak\")\n break\n t-=1", "t=int(input())\n\nwhile(t):\n ll=[]\n lb=[]\n cl=0\n cb=0\n a,b=input().split()\n a=int(a)\n b=int(b)\n\n for i in range(1,a+1,2):\n ll.append(i)\n if sum(ll)>a:\n ll.remove(i)\n break\n for i in range(2,b+1,2):\n lb.append(i)\n if sum(lb)>b:\n lb.remove(i)\n break\n #print(ll,\"\\n\",lb)\n if len(ll)>len(lb):\n print(\"Limak\")\n else:\n print(\"Bob\")\n t=t-1\n\n", "t=int(input())\ni=0\nwhile i<t:\n a,b=input().split()\n a=int(a)\n b=int(b)\n ai=1\n ae=1\n bi=2\n be=2\n while True:\n if ae<=a:\n ai+=2\n ae+=ai\n else:\n print(\"Bob\")\n break\n if be<=b:\n bi+=2\n be+=bi\n else:\n print(\"Limak\")\n break\n i+=1", "for O in range(int(input())):\n LA,BA=map(int,input().split())\n A,C=1,0\n while(True):\n if(LA>=A):\n LA-=A\n A+=1\n C+=1\n else:\n break\n if(BA>=A):\n BA-=A\n A+=1\n C+=1\n else:\n break\n if(C%2!=0):\n print(\"Limak\")\n else:\n print(\"Bob\")", "a=int(input())\nwhile a:\n a=a-1\n b,c=list(map(int,input().split()))\n l=0\n t=0\n k=1\n h=2\n while 1:\n if l+k>b:\n print(\"Bob\")\n break\n elif t+h>c:\n print(\"Limak\")\n break\n else:\n l=l+k \n t=t+h\n k=k+2\n h=h+2\n \n \n", "# cook your dish here\nt=int(input())\nfor i in range(t):\n n1,n2=map(int,input().split())\n b=0\n l=0\n c=1\n while 1:\n if c%2==0:\n l=l+c\n else:\n b=b+c\n if b>n1:\n print(\"Bob\")\n break\n else:\n if l>n2:\n print(\"Limak\")\n break\n c=c+1", "import math\nfor _ in range(int(input())):\n A,B = map(int,input().split(\" \"))\n c = 0\n d = 0\n sum = 0\n sum1 = 0\n for n in range(1,A+1,2):\n sum+=n\n if(sum<=A):\n c+=1\n for m in range(2,B+1,2):\n sum1+=m\n if(sum1<=B):\n d+=1\n #print(c,d)\n if(c>d):\n print(\"Limak\")\n else:\n print(\"Bob\")", "# cook your dish here\nfor _ in range(int(input())):\n a,b=list(map(int,input().split()))\n l=b1=0\n for i in range(1,1000,2):\n l+=i\n if(l>a):\n print(\"Bob\")\n break\n b1=b1+i+1\n if(b1>b):\n print(\"Limak\")\n break\n \n", "# cook your dish here\nfor j in range(int(input())):\n l,b=map(int,input().split())\n c=0\n i=1\n while l>-1 and b>-1:\n if c==0:\n l=l-i\n i=i+1 \n c=1\n else:\n b=b-i\n i=i+1\n c=0\n if l<0:\n print(\"Bob\")\n else:\n print(\"Limak\")", "t=int(input())\nfor i in range (t):\n a, b=list(map(int,input().split()))\n m=1\n n=2\n while(1):\n if(a<m):\n print('Bob')\n break\n elif(b<n):\n print('Limak')\n break\n a=a-m\n b=b-n\n m=m+2\n n=n+2\n", "# cook your dish here\nt=int(input())\nfor j in range(t):\n l,b=list(map(int,input().split()))\n c=0\n i=1\n while l>-1 and b>-1:\n if c==0:\n l=l-i\n i=i+1 \n c=1\n else:\n b=b-i\n i=i+1\n c=0\n if l<0:\n print(\"Bob\")\n else:\n print(\"Limak\")\n \n \n", "# cook your dish here\nn=int(input())\nfor i in range(0,n):\n (l,b)=map(int,input().split(\" \"))\n lcandie=0\n bcandie=0\n for a in range(1,1000):\n if(a%2==1):\n lcandie+=a\n if(lcandie>l):\n print(\"Bob\")\n break\n else:\n bcandie+=a\n if(bcandie>b):\n print(\"Limak\")\n break", "# cook your dish here\nt=int(input())\nfor ts in range(t):\n x,y=list(map(int,input().split()))\n a=1\n b=2\n while(1):\n if(x<a):\n print('Bob')\n break\n elif(y<b):\n print('Limak')\n break\n x-=a\n y-=b\n a+=2\n b+=2\n", "# cook your dish here\nt=int(input())\nfor ts in range(t):\n x,y=map(int,input().split())\n a=1\n b=2\n while(1):\n if(x<a):\n print('Bob')\n break\n elif(y<b):\n print('Limak')\n break\n x-=a\n y-=b\n a+=2\n b+=2"]
{"inputs": [["10", "3 2", "4 2", "1 1", "1 2", "1 3", "9 3", "9 11", "9 12", "9 1000", "8 11"]], "outputs": [["Bob", "Limak", "Limak", "Bob", "Bob", "Limak", "Limak", "Bob", "Bob", "Bob"]]}
INTERVIEW
PYTHON3
CODECHEF
8,078
235199b0e9b1c6a66851fa0b702709b7
UNKNOWN
Chef bought a huge (effectively infinite) planar island and built $N$ restaurants (numbered $1$ through $N$) on it. For each valid $i$, the Cartesian coordinates of restaurant $i$ are $(X_i, Y_i)$. Now, Chef wants to build $N-1$ straight narrow roads (line segments) on the island. The roads may have arbitrary lengths; restaurants do not have to lie on the roads. The slope of each road must be $1$ or $-1$, i.e. for any two points $(x_1, y_1)$ and $(x_2, y_2)$ on the same road, $|x_1-x_2| = |y_1-y_2|$ must hold. Let's denote the minimum distance Chef has to walk from restaurant $i$ to reach a road by $D_i$. Then, let's denote $a = \mathrm{max}\,(D_1, D_2, \ldots, D_N)$; Chef wants this distance to be minimum possible. Chef is a busy person, so he decided to give you the job of building the roads. You should find a way to build them that minimises $a$ and compute $a \cdot \sqrt{2}$. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains a single integer $N$. - $N$ lines follow. For each valid $i$, the $i$-th of these lines contains two space-separated integers $X_i$ and $Y_i$. -----Output----- For each test case, print a single line containing one real number — the minimum distance $a$ multiplied by $\sqrt{2}$. Your answer will be considered correct if its absolute or relative error does not exceed $10^{-6}$. -----Constraints----- - $1 \le T \le 100$ - $2 \le N \le 10^4$ - $|X_i|, |Y_i| \le 10^9$ for each valid $i$ -----Subtasks----- Subtask #1 (10 points): - $1 \le T \le 10$ - $2 \le N \le 5$ - $|X_i|, |Y_i| \le 10$ for each valid $i$ - $a \cdot \sqrt{2}$ is an integer Subtask #2 (90 points): original constraints -----Example Input----- 2 3 0 0 0 1 0 -1 3 0 1 1 0 -1 0 -----Example Output----- 0.5 0 -----Explanation----- Example case 1: We should build roads described by equations $y-x+0.5 = 0$ and $y-x-0.5 = 0$. Example case 2: We should build roads described by equations $y-x-1 = 0$ and $y+x-1 = 0$.
["import sys\n\ndef input(): return sys.stdin.readline().strip()\ndef iinput(): return int(input())\ndef rinput(): return list(map(int, sys.stdin.readline().strip().split())) \ndef get_list(): return list(map(int, sys.stdin.readline().strip().split()))\n\n\nt=iinput()\n\nfor _ in range(t):\n n=iinput()\n p=[]\n mi=[]\n for i in range(n):\n x,y=rinput()\n p.append(x+y)\n mi.append(x-y)\n\n p.sort()\n mi.sort()\n m=float('inf')\n for i in range(1,n):\n if(p[i]-p[i-1]<m):\n m=p[i]-p[i-1]\n if(mi[i]-mi[i-1]<m):\n m=mi[i]-mi[i-1]\n\n if m%2==0:\n print(m//2)\n else:\n print(m/2)\n", "import io, sys, os\nimport math as ma\nfrom decimal import Decimal as dec\nfrom itertools import permutations\n\n\ndef li ():\n return list (map (int, input ().split ()))\n\n\ndef num ():\n return map (int, input ().split ())\n\n\ndef nu ():\n return int (input ())\n\n\ndef solve ():\n t = nu()\n for _ in range (t):\n n=nu()\n x=set()\n y=set()\n fl=False\n for i in range(n):\n l,r=num()\n px=l+r\n py=r-l\n if(px in x):\n fl=True\n if(py in y):\n fl=True\n x.add(px)\n y.add(py)\n x=list(x)\n y=list(y)\n x.sort()\n y.sort()\n mnx=9999999999999\n mny= 9999999999999\n if(fl):\n print(0)\n else:\n for i in range(1,len(x)):\n mnx=min(mnx,x[i]-x[i-1])\n for i in range(1,len(y)):\n mny=min(mny,y[i]-y[i-1])\n print(min(mny,mnx)/2)\n\n\n\ndef __starting_point():\n solve ()\n__starting_point()", "for _ in range(int(input())):\n n=int(input())\n plus=[]\n minus=[]\n for i in range(n):\n x,y=list(map(int,input().split()))\n plus.append(x+y)\n minus.append(x-y)\n plus.sort(),minus.sort()\n m=float('inf')\n for i in range(1,n):\n if plus[i]-plus[i-1]<m:\n m=plus[i]-plus[i-1]\n if minus[i]-minus[i-1]<m:\n m=minus[i]-minus[i-1]\n if m%2==0:\n print(m//2)\n else:\n print(m/2)\n", "from decimal import *\ngetcontext().prec = 1\nt = int(input())\nwhile t > 0:\n t -= 1\n n = int(input())\n a = []; i = 0; b = []\n while i < n:\n x,y = list(map(int, input().split()))\n a.append(x+y)\n b.append(x-y)\n i += 1\n a.sort()\n b.sort()\n m = 1000000007\n for i in range(1,n):\n k = abs(a[i] - a[i-1])\n l = abs(b[i] - b[i-1])\n m = min(m,k,l)\n print(Decimal(m/2))", "T=int(input())\nfor i in range(T):\n N=int(input())\n l1=[]\n l2=[]\n for j in range(N):\n a,b=map(int,input().split())\n l1.append(a-b)\n l2.append(a+b)\n l1.sort()\n l2.sort()\n m1=100000000000000000000000\n for j in range(1,len(l1)):\n if l1[j]-l1[j-1]<m1:\n m1=l1[j]-l1[j-1]\n m2=1000000000000000000000\n for j in range(1,len(l2)):\n if l2[j]-l2[j-1]<m2:\n m2=l2[j]-l2[j-1]\n if min(m1,m2)%2==0:\n print(min(m1,m2)//2)\n else:\n print(min(m1,m2)/2)", "import math\n\nfor _ in range(0, int(input())):\n points = int(input())\n xs = set()\n ys = set()\n for _ in range(points):\n x, y = [int(i) for i in input().split()]\n xs.add((x - y))\n ys.add((x + y))\n xmin = 1000000001\n ymin = 1000000001\n if len(xs) != points or len(ys) != points:\n print(0)\n else:\n xs = sorted(xs)\n ys = sorted(ys)\n xmin = math.fabs(xs[1] - xs[0])\n ymin = math.fabs(ys[1] - ys[0])\n for i in range(1, len(xs) - 1):\n if xmin > (math.fabs(xs[i + 1] - xs[i])):\n xmin = xs[i + 1] - xs[i]\n\n if ymin > (math.fabs(ys[i + 1] - ys[i])):\n ymin = ys[i + 1] - ys[i]\n\n print(min(xmin, ymin) / 2)\n", "t=int(input())\nfor test in range(t):\n n=int(input())\n a_set=set()\n b_set=set()\n for i in range(n):\n x,y=list(map(int,input().split()))\n a_set.add(x-y)\n b_set.add(x+y)\n a_set=list(a_set)\n b_set=list(b_set)\n if len(a_set)!=n or len(b_set)!=n:\n print(0)\n else:\n a_set=sorted((a_set))\n b_set=sorted((b_set))\n a1=a_set[1]-a_set[0]\n b1=b_set[1]-b_set[0]\n for i in range(2,n):\n a1=min(a1,a_set[i]-a_set[i-1])\n b1=min(b1,b_set[i]-b_set[i-1])\n # print(a1,b1)\n print(min(a1,b1)/2)\n", "# cook your dish here\n'''\nt=int(input())\n\nl=[] #array of coordinates\nwhile t:\n n=int(input())\n while n:\n coor=int(input()),int(input()) #coordinates\n l.append(coor)\n n-=1\n \n t-=1\n lcopy=sorted(l)\n for i in range(len(l)):\n length=len(lcopy)\n for j in range(i+1,len(l)):\n if abs(l[i][0]-l[j][0])==abs(l[i][1]-l[j][1]):\n if l[j] in lcopy: lcopy.remove(l[j])\n if length!=len(lcopy):\n if l[i] in lcopy: lcopy.remove(l[i])\n print(l)\n\n print(lcopy)\n'''\n\nimport cmath\nimport math\n\n\n\ndef f(l):\n #Rotate the points by 45 degrees\n l1=[]\n for i in range(len(l)):\n w=cmath.polar(l[i])\n z=cmath.rect(w[0],w[1]-cmath.pi/4)\n l1.append(z) \n\n #print(l1)\n l1.sort(key=lambda z:z.real)\n for i in range(len(l1)-1):\n diff=abs(l1[i].real-l1[i+1].real)\n if diff==0:\n print(0)\n return\n if i==0:\n minDiffX=diff\n else:\n minDiffX=min(diff,minDiffX)\n #print(minDiffX)\n\n l1.sort(key = lambda x: x.imag)\n for i in range(len(l1)-1):\n diff=abs(l1[i].imag-l1[i+1].imag)\n if diff==0:\n print(0)\n return\n if i==0:\n minDiffY=diff\n else:\n minDiffY=min(diff,minDiffY)\n #print(minDiffY)\n\n #print(l1)\n '''d=min(abs(l[0].real-l[1].real),abs(l[0].imag-l[1].imag))\n for i in range(1,len(l1)):\n for j in range(i+1,len(l1)):\n x=min(abs(l[i].real-l[j].real),abs(l[i].imag-l[j].imag))\n if x<d: d=x\n'''\n print(min(minDiffX,minDiffY)*math.sin(math.pi/4)) \n\nT=int(input())\n\nwhile T:\n l=[] #array of coordinates\n\n n=int(input())\n while n:\n #print(n)\n t=input().split() #coordinates\n #print(t)\n l.append(complex(int(t[0]),int(t[1])))\n n-=1\n\n f(l)\n\n T-=1\n", "# cook your dish here\nimport numpy as np\nt = int(input())\nwhile(t):\n n = int(input())\n X = []\n Y = []\n for i in range(n):\n x,y = map(int,input().split())\n x,y = x - y,x + y\n X.append(x)\n Y.append(y)\n X = set(X)\n Y = set(Y)\n if len(X)== n-1 or len(Y)==n-1:\n print(0)\n else:\n X = list(X)\n Y = list(Y)\n X.sort()\n Y.sort()\n for i in range(len(X) - 1):\n X[i] = X[i+1] - X[i]\n X = X[:-1]\n for i in range(len(Y) - 1):\n Y[i] = Y[i+1] - Y[i]\n Y = Y[:-1]\n print(min(min(X)/2.0,min(Y)/2.0))\n t-=1", "t = int(input())\nfor _ in range(t):\n n = int(input())\n co = []\n suma = []\n diff = []\n for i in range(n):\n x,y = map(int,input().strip().split())\n co.append([x,y])\n suma.append(x+y)\n diff.append(x-y)\n # print(co)\n suma.sort()\n diff.sort()\n # print(suma)\n # print(diff)\n mina = 10**9\n mina = (abs((suma[0]-suma[1])/2))\n mina = min(mina,abs((diff[0]-diff[1])/2))\n # print(mina)\n for i in range(1,n-1):\n mina = min(mina,abs((suma[i]-suma[i+1])/2),abs((diff[i]-diff[i+1])/2))\n # print(i,mina)\n if(mina == 0.0):\n break\n print(mina)", "t = int(input())\nwhile t>0:\n t-=1\n n = int(input())\n arr = []\n arr3 = []\n for i in range(n):\n x,y = map(int,input().strip().split(\" \"))\n arr.append(y-x)\n arr3.append(y+x)\n arr = sorted(arr)\n arr3 = sorted(arr3)\n arr2 = []\n for i in range(n-1):\n arr2.append((arr[i+1]-arr[i])/2)\n arr2.append((arr3[i+1]-arr3[i])/2)\n print(min(arr2))", "t=int(input())\nfor _ in range(0,t):\n intercept1=[]\n intercept2=[]\n n=int(input())\n for i in range(0,n):\n x,y=map(int,input().split())\n intercept1.append(y+x)\n intercept2.append(y-x)\n intercept1.sort()\n intercept2.sort()\n mn1=10**10\n mn2=10**10\n for i in range(1,n):\n diff1=intercept1[i]-intercept1[i-1]\n mn1=min(mn1,diff1)\n diff2=intercept2[i]-intercept2[i-1]\n mn2=min(mn2,diff2)\n ans=min(mn1,mn2)\n print(ans/2)", "# cook your dish here\nimport math\nroot = math.sqrt(2)\n\nfor t in range(int(input())):\n num = int(input())\n \n a = []\n \n for i in range(num):\n a.append(list(map(int,input().split())))\n \n b = []\n c = []\n \n for i in range(num):\n b.append(a[i][1] - a[i][0])\n c.append(a[i][1] + a[i][0])\n \n c.sort(reverse=True)\n b.sort(reverse=True)\n \n d = []\n e = []\n \n for i in range(num-1):\n d.append(b[i] - b[i+1])\n e.append(c[i] - c[i+1])\n \n f = min(min(d),min(e))\n \n f /= 2\n \n print(f)", "for k in range(int(input())):\n n = int(input())\n arr1=[]\n arr2=[]\n for _ in range(n):\n a,b = map(int,input().split())\n arr1.append(a+b)\n arr2.append(b-a)\n arr1.sort()\n arr2.sort()\n l1=[]\n l2 =[]\n for i in range(len(arr1)-1):\n l1.append(arr1[i+1]-arr1[i])\n l2.append(arr2[i+1]-arr2[i])\n x = min(l1)\n y = min(l2)\n print(\"{0:.6f}\".format(min(x,y)/2))", "t=int(input())\nfor i in range(t):\n n=int(input())\n x=[]\n y=[]\n dx=[]\n dy=[]\n for j in range(n):\n c=list(map(int,input().split()))\n x.append(c[0]-c[1])\n y.append(c[0]+c[1])\n x.sort()\n y.sort()\n for j in range(1,n):\n dx.append(x[j]-x[j-1])\n dy.append(y[j]-y[j-1])\n a=min(dx)\n b=min(dy)\n print('{0:.6f}'.format(min(a,b)/2))", "\"\"\"\nimport bisect\n\ndef insert(list, n): \n bisect.insort(list, n) \n return list\n\"\"\"\nt=int(input())\nfor i in range(0,t):\n n=int(input())\n\n arr=[]\n brr=[]\n for j in range(0,n):\n x,y=input().split()\n x=int(x)\n y=int(y)\n #insert(arr,x-y)\n #insert(brr,x+y)\n arr.insert(0,x-y)\n brr.insert(0,x+y)\n arr.sort()\n brr.sort()\n m1=arr[1]-arr[0]\n for k in range(1,n-1):\n if((arr[k+1]-arr[k])<m1):\n m1=arr[k+1]-arr[k]\n \n for k in range(0,n-1):\n if((brr[k+1]-brr[k])<m1):\n m1=brr[k+1]-brr[k]\n if(m1%2==0):\n print(m1//2)\n else:\n print(m1/2)\n", "t = int(input())\nwhile t>0:\n t -= 1\n n = int(input())\n mp, mn = [], []\n for i in range(n):\n x, y = list(map(int, input().split()))\n mp.append(y-x)\n mn.append(y+x)\n dmin = abs(mp[1]-mp[0])\n mp.sort()\n mn.sort()\n for i in range(n-1):\n dmin = min(dmin, mp[i+1]-mp[i])\n dmin = min(dmin, mn[i+1]-mn[i])\n if dmin%2 == 0:\n print(dmin//2)\n else:\n print(dmin/2)\n", "t=int(input())\nwhile (t>0):\n t-=1\n n=int(input())\n d=[]\n dl=[]\n for i in range(n):\n x,y=map(int,input().split())\n d.append(y-x)\n dl.append(y+x)\n #print(\"d = \",d)\n #print(\"dl = \",dl)\n d=sorted(d)\n dl=sorted(dl)\n #print(\"d now = \",d)\n #print(\"dl now = \",dl)\n ans=abs(d[0]-d[1])\n k=0\n while (k<n-1):\n ans=min(ans,abs(d[k]-d[k+1]))\n ans=min(ans,abs(dl[k]-dl[k+1]))\n k+=1\n if (ans%2==0):\n print(int(ans/2))\n else:\n print(ans/2)", "\"\"\"\nimport bisect\n\ndef insert(list, n): \n bisect.insort(list, n) \n return list\n\"\"\"\nt=int(input())\nfor i in range(0,t):\n n=int(input())\n\n arr=[]\n brr=[]\n for j in range(0,n):\n x,y=input().split()\n x=int(x)\n y=int(y)\n #insert(arr,x-y)\n #insert(brr,x+y)\n arr.insert(0,x-y)\n brr.insert(0,x+y)\n arr.sort()\n brr.sort()\n m1=arr[1]-arr[0]\n for k in range(1,n-1):\n if((arr[k+1]-arr[k])<m1):\n m1=arr[k+1]-arr[k]\n m2=brr[1]-brr[0]\n for k in range(1,n-1):\n if((brr[k+1]-brr[k])<m2):\n m2=brr[k+1]-brr[k]\n if((min(m1,m2))%2==0):\n print((min(m1,m2))//2)\n else:\n print((min(m1,m2))/2)\n", "import bisect\n\ndef insert(list, n): \n bisect.insort(list, n) \n return list\n\nt=int(input())\nfor i in range(0,t):\n n=int(input())\n\n arr=[]\n brr=[]\n for j in range(0,n):\n x,y=input().split()\n x=int(x)\n y=int(y)\n insert(arr,x-y)\n insert(brr,x+y)\n m1=arr[1]-arr[0]\n for k in range(1,n-1):\n if((arr[k+1]-arr[k])<m1):\n m1=arr[k+1]-arr[k]\n m2=brr[1]-brr[0]\n for k in range(1,n-1):\n if((brr[k+1]-brr[k])<m2):\n m2=brr[k+1]-brr[k]\n if((min(m1,m2))%2==0):\n print((min(m1,m2))//2)\n else:\n print((min(m1,m2))/2)\n", "import bisect\n\ndef insert(list, n): \n bisect.insort(list, n) \n return list\n\nt=int(input())\nfor i in range(0,t):\n n=int(input())\n\n arr=[]\n brr=[]\n for j in range(0,n):\n x,y=input().split()\n x=int(x)\n y=int(y)\n insert(arr,x-y)\n insert(brr,x+y)\n m1=arr[1]-arr[0]\n for k in range(1,n-1):\n if((arr[k+1]-arr[k])<m1):\n m1=arr[k+1]-arr[k]\n m2=brr[1]-brr[0]\n for k in range(1,n-1):\n if((brr[k+1]-brr[k])<m2):\n m2=brr[k+1]-brr[k]\n print((min(m1,m2))/2)", "import bisect \ndef sign(a):\n if(a==abs(a)):\n return 1\n else:\n return -1\n\ndef insert(list, n): \n bisect.insort(list, n) \n return list\n\nt=int(input())\nfor i in range(0,t):\n n=int(input())\n\n arr=[]\n brr=[]\n for j in range(0,n):\n x,y=input().split()\n x=int(x)\n y=int(y)\n a=x-y\n b=x+y\n insert(arr,a)\n insert(brr,b)\n m1=arr[1]-arr[0]\n for k in range(1,len(arr)-1):\n if((arr[k+1]-arr[k])<m1):\n m1=arr[k+1]-arr[k]\n m2=brr[1]-brr[0]\n for k in range(1,len(arr)-1):\n if((brr[k+1]-brr[k])<m2):\n m2=brr[k+1]-brr[k]\n print((min(m1,m2))/2)", "T=int(input())\nfor i in range(0,T):\n N=int(input())\n L=[]\n for j in range(0,N):\n x,y=list(map(int,input().split()))\n L.append((x,y))\n\n arr11=[]\n arr12=[]\n for j in range(0,len(L)):\n arr11.append(L[j][1]-L[j][0])\n arr12.append(L[j][1]+L[j][0])\n\n arr11=sorted(arr11)\n arr12=sorted(arr12)\n arr11=arr11[::-1]\n arr12=arr12[::-1]\n arr21=[100000000000]\n arr22=[100000000000]\n for j in range(0,len(L)-1):\n arr21.append(arr11[j]-arr11[j+1])\n arr21.append(arr12[j]-arr12[j+1])\n\n print(min(min(arr21),min(arr22))/2)\n \n"]
{"inputs": [["2", "3", "0 0", "0 1", "0 -1", "3", "0 1", "1 0", "-1 0"]], "outputs": [["0.5", "0"]]}
INTERVIEW
PYTHON3
CODECHEF
12,955
2374d3997cb1f14fd1282c6a283c949a
UNKNOWN
There are three squares, each with side length a placed on the x-axis. The coordinates of centers of these squares are (x1, a/2), (x2, a/2) and (x3, a/2) respectively. All of them are placed with one of their sides resting on the x-axis. You are allowed to move the centers of each of these squares along the x-axis (either to the left or to the right) by a distance of at most K. Find the maximum possible area of intersections of all these three squares that you can achieve. That is, the maximum area of the region which is part of all the three squares in the final configuration. -----Input----- - The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows. - The first line of each test case contains two space-separated integers a, K denoting side length of the squares, and the maximum distance that you can move the center of any square. - The second line contains three space separated integers x1, x2, x3 -----Output----- For each test case, output a real number corresponding to the maximum area of the intersection of the three squares that you can obtain. Your answer will be considered correct if it has an absolute error of less than or equal to 10-2. -----Constraints----- - 1 ≤ T ≤ 105 - 1 ≤ a ≤ 105 - 0 ≤ K ≤ 106 - -106 ≤ x1, x2, x3 ≤ 106 -----Example----- Input 3 1 0 1 2 3 1 1 1 2 3 1 1 1 4 6 Output 0.000000 1.0000 0.0 -----Explanation----- Testcase 1: The figure below shows the three squares: Since K = 0, they cannot be moved, and since there is no region which belongs to all three squares, the answer is 0. Testcase 2: The starting configuration is the same as above, but now each of the squares can move 1 unit. So we can move the first square 1 unit to the right and the third square one unit to the left, and have all the three squares at x-coordinate = 2. Thus the entire square is part of all three squares, and the answer is 1.
["t=int(input())\nfor i in range(t):\n a,k=list(map(int,input().split()))\n x1,x2,x3=list(map(int,input().split()))\n big=max(x1,x2,x3)\n small=min(x1,x2,x3)\n q=big-small-2*k\n \n if q>=a:\n print(0)\n elif -1*q>=0:\n print(a*a)\n else:\n print(a*(a-q))\n", "t=int(input())\nfor i in range(t):\n a,k=list(map(int,input().split()))\n x1,x2,x3=list(map(int,input().split()))\n big=max(x1,x2,x3)\n small=min(x1,x2,x3)\n \n if big-small-2*k>=a:\n print(0)\n elif small-big+2*k>=0:\n print(a*a)\n else:\n print(a*(a-(big-small-2*k)))\n", "t=int(input())\nfor i in range(t):\n a,k=list(map(int,input().split()))\n x1,x2,x3=list(map(int,input().split()))\n big=max(x1,x2,x3)\n small=min(x1,x2,x3)\n if small-big+2*k>=0:\n print(a*a)\n else:\n q=a-(big-small-2*k)\n if q==0 or q<0:\n print(0)\n else:\n print((q)*a)\n", "# cook your dish here\nfor _ in range(int(input())):\n \n l,k=map(float,input().split())\n x=sorted(list(map(float,input().split())))\n a,b,c=x[0],x[1],x[2]\n if c-a<=l:\n d=c-a\n if d<=2*k:print(l*l)\n else:\n d=l-(c-a)+2*k\n print(min(abs(d),l)*l)\n \n\n else:\n d=2*k-(c-a-l)\n if d<=0:print(0.0000000000000000000000000)\n else:print(min(l,d)*l)", "for _ in range(int(input())):\n a,k = list(map(int,input().split()))\n l = list(map(int,input().split()))\n l.sort()\n ans = 0\n \n s = l[0]-a/2-k\n e = l[0]+a/2+k\n \n s = max(s,l[1]-a/2-k)\n e = min(e,l[1]+a/2+k)\n \n s = max(s,l[2]-a/2-k)\n e = min(e,l[2]+a/2+k)\n \n if s<e:\n ans = min(e-s,a)*a\n \n print(ans)\n", "for _ in range(int(input())):\n a,k = list(map(int,input().split()))\n l = list(map(int,input().split()))\n l.sort()\n ans = 0\n \n s = l[0]-a/2-k\n e = l[0]+a/2+k\n \n s = max(s,l[1]-a/2-k)\n e = min(e,l[1]+a/2+k)\n \n s = max(s,l[2]-a/2-k)\n e = min(e,l[2]+a/2+k)\n \n if s<e:\n ans = min(e-s,a)*a\n \n print(ans)\n", "# cook your dish here\nfor i in range(int(input())):\n a,k=[int(i) for i in input().split()]\n l=[int(i) for i in input().split()]\n l=sorted(l)\n if(l[0]+a+2*k<=l[2]):\n print(0)\n elif(l[0]+2*k>=l[2]):\n print(a**2)\n else:\n p=l[2]-l[0]-2*k \n print(a*(a-p))\n \n\n\n", "t=int(input())\nfor o in range(t):\n n,k=list(map(int,input().split()))\n x,y,z=list(map(int,input().split()))\n x1,y1=x-n/2,x+n/2\n x2,y2=y-n/2,y+n/2\n x3,y3=z-n/2,z+n/2\n a=[(x1-k,y1+k),(x2-k,y2+k),(x3-k,y3+k)]\n a.sort()\n x1,y1=a[0]\n x2,y2=a[1]\n x3,y3=a[2]\n f1,f2=max(x1,x2),min(y1,y2)\n ans=0.0\n flag=False\n if(f1>=f2):\n flag=True\n else:\n f1=max(f1,x3)\n f2=min(f2,y3)\n if(f1>=f2):\n flag=True\n if(flag):\n print(0*1.0)\n continue\n if(f2-f1>n):\n print(n*n*1.0)\n else:\n print((f2-f1)*n*1.0)\n", "import sys\n\nt = int(input())\n\nwhile (t):\n\n line = input().split()\n a,k = int(line[0]),int(line[1])\n\n line = input().split() \n arr = [int(line[0]),int(line[1]),int(line[2])]\n arr.sort() \n\n start = arr[0] - a/2 - k\n end = arr[0] + a/2 + k\n \n start = max(start,arr[1]-a/2-k)\n end = min(end,arr[1]+a/2+k)\n \n start = max(start,arr[2]-a/2-k)\n end = min(end,arr[2]+a/2+k)\n\n if (start < end):\n ans = min(end-start,a)*a\n else:\n ans = 0\n\n sys.stdout.write('%.6f\\n' % ans)\n\n t -= 1\n", "# Author: Dancing Monkey | Created: 09.DEC.2018\n\nfor _ in range(int(input())):\n a, k = map(int, input().split())\n l = list(map(int, input().split()))\n l.sort()\n\n p = l[0] + a/2 + k\n q = l[2] - a/2 - k\n\n print(format(0 if p < q else a*min(a, p - q), 'f'))", "n=int(input())\nfor j in range(n):\n p=input().split(\" \")\n a=int(p[0])\n k=int(p[1])\n x=input().split(\" \")\n x1=int(x[0])\n x2=int(x[1])\n x3=int(x[2])\n x=min(x1,x2,x3)\n y=max(x1,x2,x3)\n area=0\n if((y-x-2*k)>=a):\n area=0\n elif((y-x)<=2*k):\n area=a*a\n else:\n area=(a-(y-x-2*k))*a\n print(\"{0:.2f}\".format(area))", "t=int(input())\n\ndef shift(a,b,k):\n if k==0:\n return a\n if k>abs(a-b):\n return b\n else:\n return a+(b-a)/abs(b-a)*k\n \n\nwhile t>0:\n a,k = map(int, input().split())\n vals = map(int, input().split())\n x1,x2,x3=sorted(vals)\n mid = (x1+x3)/2\n \n if x2-x1<a or x3-x2<a:\n overlapping=True\n \n \n x2 = shift(x2,mid,k)\n x1=shift(x1,x2,k)\n x3=shift(x3,x2,k)\n \n overlap = (a-(x3-x1))*a\n if overlap < 0:\n print(0)\n else:\n print(overlap)\n \n \n \n t-=1", "n=int(input())\nfor j in range(n):\n p=input().split(\" \")\n a=int(p[0])\n k=int(p[1])\n x=input().split(\" \")\n x1=int(x[0])\n x2=int(x[1])\n x3=int(x[2])\n x=min(x1,x2,x3)\n y=max(x1,x2,x3)\n area=0\n if((y-x-2*k)>=a):\n area=0\n elif((y-x)<=2*k):\n area=a*a\n else:\n area=(a-(y-x-2*k))*a\n print(\"{0:.2f}\".format(area))", "t=int(input())\nfor i in range(t):\n a,k=[float(i) for i in input().split()]\n p=[float(i) for i in input().split()]\n p.sort()\n x1,x2,x3=p\n x=min(x1+2*k,x3)\n area=(a-(x3-x))*a\n if area<=0:\n print(0)\n else:\n print(area)\n", "n=int(input())\nfor j in range(n):\n p=input().split(\" \")\n a=int(p[0])\n k=int(p[1])\n x=input().split(\" \")\n x1=int(x[0])\n x2=int(x[1])\n x3=int(x[2])\n x=min(x1,x2,x3)\n y=max(x1,x2,x3)\n area=0\n if((y-x-2*k)>=a):\n area=0\n elif((y-x)<=2*k):\n area=a*a\n else:\n area=(a-(y-x-2*k))*a\n print(\"{0:.2f}\".format(area))\n\n \n\n", "T=int(input())\nfor j in range(T):\n \n ak=input()\n \n ip1=ak.split(\" \")\n\n #print(ip1)\n a=float(ip1[0])\n k=float(ip1[1])\n x=input()\n \n ip2=list(map(int,x.split()))\n ip2.sort()\n x1=float(ip2[0])\n x2=float(ip2[1])\n x3=float(ip2[2])\n\n X1=x1+a/2+k\n X3=x3-a/2-k\n #print(X1,X3)\n if(X1>=X3):\n \n if(x3-2*k-x1<=0):\n area=a*a\n else:\n a1=X1-X3\n area=a1*a\n \n else:\n area=0\n print(\"{0:.2f}\".format(float(area)))\n", "for i in range(int(input())):\n a,K=list(map(int,input().split()))\n x=list(map(int,input().split()))\n x.sort()\n if((x[2]-K)-(x[0]+K)>=a):\n print(\"{0:.2f}\".format(float(0.0)))\n else:\n if((x[2]-K)-(x[0]+K)<=0):\n area=a*a\n print(\"{0:.2f}\".format(float(area)))\n else:\n area=abs(x[0]-x[2]+2*K+a)*a\n print(\"{0:.2f}\".format(float(area)))\n"]
{"inputs": [["3", "1 0", "1 2 3", "1 1", "1 2 3", "1 1", "1 4 6"]], "outputs": [["0.000000", "1.0000", "0.0"]]}
INTERVIEW
PYTHON3
CODECHEF
5,990
050a6effc71b43175fa56db87f70c34e
UNKNOWN
----- ARRAY AND DISTINCT ELEMENTS ----- Chef is multitalented but he mistakenly took part in 2 contest which will take place at the same time. So while chef is busy at one cooking contest, he wants you to take part in coding contest. Chef wants u to solve this program for him. You have been given an array of size n. You have to calculate a subarray of size k with maximum sum having distinct elements same as original array. -----Input Format----- First line contains no. of test cases. Second line contains n and k. Third line contains array of n integers. -----Output----- Print maximum possible sum as stated in question -----Example Text Case----- Input: 1 10 6 8 8 3 5 3 8 5 7 7 7 Output: 37
["#\n\nfor _ in range(int(input())):\n n,k = list(map(int,input().split()))\n arr = list(map(int,input().split()))\n s=set(arr)\n t1=len(s)\n max=-1\n for i in range(n-k+1):\n temp=set(arr[i:i+k])\n #print(temp,i,k+i+1)\n t=len(temp)\n if t1 == t:\n if max<sum(arr[i:k+i]):\n max=sum(arr[i:k+i])\n print(max)\n", "t=int(input())\nfor _ in range(t):\n n=list(map(int,input().split()))\n k=n[1]\n n=n[0]\n a=list(map(int,input().split()))\n m=-999999999999\n s1=set(a)\n for i in range(0,n-k+1):\n s=sum(a[i:i+k])\n if s>m and set(a[i:i+k])==s1:\n m=s\n print(m)\n", "for _ in range(int(input())):\n n,k=[int(x) for x in input().split()]\n a=list(map(int,input().split()))\n s=set(a)\n s=list(s)\n aa=[]\n f=0\n for i in range(n-k+1):\n f=0\n ss=a[i:i+k]\n for j in range(len(s)):\n if s[j] not in ss:\n f=1\n break\n if f==0:\n aa.append(sum(ss))\n print(max (aa)) \n", "# cook your dish here\ntry:\n tc = int(input())\n for i in range(tc):\n n,k = list(map(int,input().split(\" \")))\n arr = list(map(int,input().split()))\n set_arr = set(arr)\n max_sum = 0\n for i in range(n):\n if set(arr[i:i+k]) == set_arr:\n max_sum = max(max_sum, sum(arr[i:i+k]))\n print(max_sum)\nexcept:\n pass\n \n", "# cook your dish here\nfor _ in range(int(input())):\n n,k=map(int,input().split())\n lst=list(map(int,input().split()))\n p=0\n ele=0\n for i in range(n-k+1):\n x=lst[i:i+k]\n d=sum(x)\n dic={j for j in set(x)}\n elm=len(dic)\n #print(x)\n #print(p,ele,d,elm)\n if elm>=ele:\n if ele>ele:\n p=d\n else:\n if d>p:\n p=d\n ele=elm\n print(p)", "# cook your dish here\nimport sys\nt=int(input().strip())\nfor _ in range(t):\n n, k = map(int, input().strip().split())\n array=list(map(int, input().strip().split()))\n cifre={}\n for el in array:\n cifre[el]=0\n for i in range(k):\n cifre[array[i]]+=1 \n flag=0\n for key in cifre:\n if cifre[key]==0:\n flag=1 \n break\n appo=sum(array[:k])\n somma= appo if flag==0 else 0\n for i in range(0,n-k):\n appo+=array[k+i]-array[i]\n cifre[array[i]]-=1 \n cifre[array[k+i]]+=1 \n flag=0\n for key in cifre:\n if cifre[key]==0:\n flag=1 \n break\n if flag==0:\n somma=max(somma,appo)\n print(somma)", "t=int(input())\nfor i in range(t):\n n,k=list(map(int,input().split()))\n arr=list(map(int,input().split()))\n arr1=list(set(arr))\n\n l=[]\n res=0\n sums=0\n for i in range(k):\n l.append(arr[i])\n sums+= arr[i]\n \n \n if(len(list(set(l)))==len(arr1)):\n res=max(res,sums)\n \n \n for i in range(k,n):\n sums+= (arr[i]-arr[i-k])\n l.remove(arr[i-k])\n l.append(arr[i])\n if(len(list(set(l)))==len(arr1)):\n res=max(res,sums)\n print(res)\n", "from sys import stdin, stdout\ninput = stdin.readline\nfrom collections import defaultdict as dd\nimport math\ndef geti(): return list(map(int, input().strip().split()))\ndef getl(): return list(map(int, input().strip().split()))\ndef gets(): return input()\ndef geta(): return int(input())\ndef print_s(s): stdout.write(s+'\\n')\n\ndef solve():\n for _ in range(geta()):\n n,k=geti()\n a=getl()\n occur=dd(int)\n ans=0\n temp=0\n temp_dict=dd(int)\n for i in a:\n occur[i]+=1\n for i in range(k):\n temp+=a[i]\n temp_dict[a[i]]+=1\n if (list(temp_dict.keys()))==(list(occur.keys())):\n ans=max(ans,temp)\n for i in range(k,n):\n temp-=a[i-k]\n temp_dict[a[i-k]]-=1\n if temp_dict[a[i-k]]==0:\n del temp_dict[a[i-k]]\n temp+=a[i]\n temp_dict[a[i]]+=1\n if (list(temp_dict.keys()))==(list(occur.keys())):\n ans=max(ans,temp)\n print(ans)\n\n\ndef __starting_point():\n solve()\n\n__starting_point()", "for _ in range(int(input())):\n n,k=map(int,input().split())\n a=list(map(int,input().split()))\n b=len(set(a))\n m=[]\n for i in range(n-k+2):\n if b == len(set(a[i:i+k])):\n m.append(sum(a[i:i+k]))\n print(max(m))", "for ts in range(int(input())):\n n,k=map(int,input().split())\n l=list(map(int,input().split()))\n c=len(set(l))\n su=[]\n for i in range(n-k+2):\n if len(set(l[i:i+k]))==c:\n su.append(sum(l[i:i+k]))\n else:\n pass\n print(max(su))", "# cook your dish here\nfor u in range(int(input())):\n n,k=list(map(int,input().split()))\n l=list(map(int,input().split()))\n m=0\n s=set(l)\n r=len(s)\n for i in range(n-k+1):\n c=0\n d=set()\n for j in range(i,i+k):\n c+=l[j]\n d.add(l[j])\n if(len(d)==r):\n m=max(m,c)\n print(m)\n", "# cook your dish here\ntest=int(input())\nfor p in range(test):\n l=list(map(int,input().split()))\n n=l[0]\n k=l[1]\n l=[]\n a=[]\n maxim=0\n l=list(map(int,input().split()))\n d=[]\n for i in l:\n if i not in d:\n d.append(i)\n for i in range(0,len(l)-k+1):\n x=l[i:i+k]\n #print(x)\n flag=0\n for j in d:\n if j not in x:\n flag=1\n break\n if sum(x)>maxim and flag==0:\n maxim=sum(x)\n a=x[:]\n #print(a)\n print(maxim)", "# cook your dish here\nn = int(input())\nwhile n > 0:\n line1 = [int(x) for x in input().split()]\n arr = [int(x) for x in input().split()]\n ac = len(set(arr))\n ln = line1[0]\n k = line1[1]\n i = 0\n j = k-1\n maxi = -1\n while(j < ln):\n if len(set(arr[i:j+1])) == ac:\n maxi = max(maxi,sum(arr[i:j+1]))\n i += 1\n j += 1\n print(maxi)\n n -= 1", "x=int(input())\nfor i in range(x):\n n,k=map(int,input().split())\n l=list(map(int,input().split()))\n j=0\n m=0\n while j+k<=n:\n #print(set(l[j:j+k]),set(l))\n if m<sum(l[j:j+k]) and set(l[j:j+k])==set(l):\n m=sum(l[j:j+k])\n j+=1\n print(m)", "def f():\n n,k=list(map(int,input().split()))\n a=list(map(int,input().split()))\n distinctitem=len(set(a))\n count=[0]*1000000\n temp=[]\n maxi=0\n s=0\n c=0\n for i in range(0,len(a)):\n if len(temp)<k:\n temp.append(a[i])\n if count[a[i]]==0:\n count[a[i]]+=1\n c+=1\n s+=a[i]\n else:\n count[a[i]]+=1\n s+=a[i]\n #print(temp,s)\n if len(temp)==k:\n if c==distinctitem:\n maxi=max(maxi,s)\n s-=temp[0]\n count[temp[0]]-=1\n if count[temp[0]]==0:\n c-=1\n temp.pop(0)\n \n print(maxi)\nfor i in range(int(input())):\n f()\n \n \n", "# cook your dish here\nt=int(input())\nwhile t>0 :\n n,k=map(int,input().split())\n l=list(map(int,input().split()))\n dis=len(set(l))\n a=0\n for i in range(n-k+1) :\n ls=[]\n s=0\n for j in range(k) :\n s+=l[i+j]\n if l[i+j] in ls :\n pass\n else :\n ls.append(l[i+j])\n if len(ls)==dis :\n a=max(a,s)\n print(a)\n t-=1", "# cook your dish here\nfor _ in range(int(input())):\n n, k = input().split()\n n,k = int(n), int(k)\n nums = list(map(int, input().split()))\n\n length1 = len(set(nums))\n i=0\n j=k-1\n initial = sum(nums[i:j+1])\n if len(set(nums)) == length1:\n m = initial\n else:\n m = 0\n while j<len(nums):\n # print(i,j,initial)\n j+=1\n if j==len(nums):\n break\n initial-=nums[i]\n i+=1\n initial+=nums[j]\n if len(set(nums[i:j+1]))==length1:\n m = max(m, initial)\n\n print(m)", "t = int(input())\nfor z in range(t):\n first = list(map(int,input().split()))\n second = list(map(int,input().split()))\n length = len(set(second))\n req = 0\n sumi = 0\n for i in range(first[1]):\n req = req+second[i]\n if(length==len(set(second[0:first[1]]))):\n sumi = req\n cp = 0\n for i in range(first[1]+1, first[0]+1):\n req = req - second[cp]+second[i-1]\n if(length == len(set(second[cp+1:i]))):\n if(sumi<req):\n sumi=req\n cp = cp+1\n print(sumi)\n", "# cook your dish here\nwhile True:\n try:\n \n t=int(input())\n h=1 \n while(h<=t):\n n,k=list(map(int,input().split()))\n lis=list(map(int,input().split()))\n \n unique_data=[]\n for i in lis:\n if i not in unique_data:\n unique_data.append(i)\n #print(unique_data)\n \n maxi=0\n lis2=[]\n for i in range(0,n-k+1):\n lis2=lis[i:i+k]\n #print(lis2)\n t=0\n for i in set(lis2):\n if i in unique_data:\n t+=1\n #print(t)\n if(t==len(unique_data)):\n if(sum(lis2)>maxi):\n maxi=sum(lis2)\n\n print(maxi)\n h+=1\n except:\n break\n \n \n \n", "# cook your dish here\nfor _ in range(int(input())):\n n,k=list(map(int,input().split()))\n a=list(map(int,input().split()))\n slen=len(set(a))\n lmax=-9\n for i in range(n-k+1):\n x=set(a[i:i+k])\n if len(x)==slen:\n add=sum(a[i:i+k])\n if add>lmax:\n lmax=add\n print(lmax)\n", "T = int(input())\n\nfor t in range(T):\n \n n, k = map(int, input().split())\n \n arr = list(map(int, input().split()))\n \n out1 = set(arr)\n \n minSum = sum(arr[0:k])\n \n for i in range(1, n-k+1):\n \n temp = arr[i:i+k]\n \n out = set(temp)\n \n if(len(out) == len(out1)):\n currentSum = sum(temp)\n if minSum < currentSum:\n minSum = currentSum\n print(minSum)", "T = int(input())\n\nfor t in range(T):\n \n n, k = map(int, input().split())\n \n arr = list(map(int, input().split()))\n \n out1 = set(arr)\n \n minSum = sum(arr[0:k])\n \n for i in range(1, n-k+1):\n \n temp = arr[i:i+k]\n \n out = set(temp)\n \n if(len(out) == len(out1)):\n currentSum = sum(temp)\n if minSum < currentSum:\n minSum = currentSum\n print(minSum)", "for _ in range(int(input())):\n n,k=map(int,input().split())\n a=list(map(int,input().split()))\n length=len(set(a))\n tot=sum(a[:k-1])\n tmp=0\n ans=0\n for i in range(k-1,n):\n tot+=a[i]-tmp\n if len(set(a[i-k+1:i+1]))==length:\n ans=max(ans,tot)\n tmp=a[i-k+1]\n print(ans)"]
{"inputs": [["1", "10 6", "8 8 3 5 3 8 5 7 7 7"]], "outputs": [["37"]]}
INTERVIEW
PYTHON3
CODECHEF
9,266
61d057efc3d0aa612681997658792557
UNKNOWN
Lira is now very keen on compiler development. :) She knows that one of the most important components of a compiler, is its parser. A parser is, in simple terms, a software component that processes text, and checks it's semantic correctness, or, if you prefer, if the text is properly built. As an example, in declaring and initializing an integer, in C/C++, you can't do something like: int = x ;4 as the semantics of such statement is incorrect, as we all know that the datatype must precede an identifier and only afterwards should come the equal sign and the initialization value, so, the corrected statement should be: int x = 4; Today, Lira is concerned with an abstract instruction which is composed of the characters "<" and ">" , which she will use on the design of her language, L++ :D. She is using it as an abstraction for generating XML code Tags in an easier fashion and she understood that, for an expression to be valid, a "<" symbol must always have a corresponding ">" character somewhere (not necessary immediately) after it. Moreover, each ">" symbol should correspond to exactly one "<" symbol. So, for instance, the instructions: <<>> <> <><> are all valid. While: >> ><>< are not. Given some expressions which represent some instructions to be analyzed by Lira's compiler, you should tell the length of the longest prefix of each of these expressions that is valid, or 0 if there's no such a prefix. -----Input----- Input will consist of an integer T denoting the number of test cases to follow. Then, T strings follow, each on a single line, representing a possible expression in L++. -----Output----- For each expression you should output the length of the longest prefix that is valid or 0 if there's no such a prefix. -----Constraints----- - 1 ≤ T ≤ 500 - 1 ≤ The length of a single expression ≤ 106 - The total size all the input expressions is no more than 5*106 -----Example----- Input: 3 <<>> >< <>>> Output: 4 0 2
["# cook your dish here\nt=int(input())\nfor j in range(t):\n s=input()\n st=[]\n ans=0\n\n for i in range(len(s)):\n \n if(s[i]=='>'):\n if(len(st)!=0 and st[-1]=='<'):\n st.pop()\n if(len(st)==0):\n ans=i+1\n else:\n break\n\n else:\n st.append('<')\n\n print(ans)\n", "# cook your dish here\nfor y in range(int(input())):\n s=input()\n st=[]\n i=-1\n a=0\n for x in range(len(s)):\n\n if i==-1 and s[x]=='>':\n \n break\n elif s[x]=='<':\n st.append('<')\n i+=1\n elif s[x]=='>':\n st.pop()\n i-=1\n if i==-1:\n a=x+1\n print(a)\n \n \n \n \n ", "# cook your dish here\nfor _ in range(0,int(input())):\n s=input()\n c=0\n ans=0\n for i in range(0,len(s)):\n if s[i]==\"<\":\n c=c+1\n else:\n c=c-1\n if c==0:\n ans=i+1\n elif c<0:\n break\n print(ans)\n ", "# cook your dish here\nt=int(input())\nfor _ in range(t):\n s = input()\n count = 0\n l = []\n for i in range(0,len(s)):\n #print(l)\n if s[i] == \">\":\n \n if len(l)!=0 and l[-1]==\"<\":\n #(\"jk\")\n l.pop()\n if len(l)==0:\n count = i+1\n else:\n break\n \n \n else:\n l.append(\"<\")\n print(count)", "def compiler(string):\r\n\tt=0\r\n\tans=0\r\n\tfor i in range(len(string)):\r\n\t\tif string[i]=='<':\r\n\t\t\tt+=1\r\n\t\telse:\r\n\t\t\tt-=1\r\n\t\t\tif t==0:\r\n\t\t\t\tans = max(ans, i+1)\r\n\t\t\telif t<0:\r\n\t\t\t\tbreak\r\n\treturn ans\r\n\r\nt = int(input())\r\nwhile t:\r\n\tstring = input()\r\n\tprint(compiler(string))\r\n\tt-=1\r\n", "from sys import stdin, stdout \n\ndef main():\n numberOfCases = int(stdin.readline())\n \n for i in range(0, numberOfCases):\n arr = [char for char in stdin.readline().strip()]\n starter = []\n count = 0\n currentCount = 0\n \n \n for element in arr:\n if element == \"<\":\n starter.append(element)\n else:\n if len(starter) == 0:\n break\n starter.pop()\n \n if len(starter) == 0:\n count = count + 2 + currentCount\n currentCount = 0\n else :\n currentCount += 2\n \n print(count)\n \n \n# call the main method\ndef __starting_point():\n main() \n__starting_point()", "t = int(input())\nfor test in range(t):\n expression = list(input())\n available_left_arrow = 0\n streak = 0\n max_streak = 0\n for exp in expression:\n if exp == '<':\n available_left_arrow += 1\n else:\n if available_left_arrow <= 0:\n break\n available_left_arrow -= 1\n if available_left_arrow == 0:\n max_streak = max_streak + 2 + streak\n streak = 0\n else:\n streak += 2\n \n print(max_streak)\n ", "# cook your dish here\nt=int(input())\nfor _ in range (t):\n x=input()\n t=0\n cnt=0\n lst=[]\n for i in x:\n if (i=='<'):\n lst.append(i)\n else:\n if len(lst)==0:\n break\n else:\n lst.pop()\n if len(lst)==0:\n cnt+=2 + t\n t = 0\n else:\n t+=2\n print(cnt)", "for _ in range(int(input())):\n s = input()\n st = []\n temp,count = 0,0\n for i in s:\n if i =='<':\n st.append('<')\n else:\n if len(st)==0:\n break\n else:\n st.pop()\n if len(st)==0:\n count+=2 + temp\n temp = 0\n else:\n temp+=2\n print(count)", "t = int(input())\n\nwhile t:\n t -= 1 \n s = input()\n count = 0\n a = 0\n d = []\n for i in s:\n if i == '<':\n d.append('<')\n elif i == '>' and d == []:\n break\n else:\n d.pop(0)\n if d == []:\n count += 2 + a\n a = 0\n else:\n a += 2\n print(count)", "t=int(input())\nwhile t:\n a=list(map(str,input()))\n b=[]\n c,ans=0,0\n for i in range(len(a)):\n if a[i]=='<' :\n b.append(a[i])\n c+=1\n else:\n if len(b)==0 or b[-1]!='<' :\n break;\n else:\n b.pop()\n if len(b)==0:\n ans+=2*c\n c=0\n print(ans)\n t-=1", "for i in range(int(input())):\n s = input()\n stack = []\n ans = 0\n c = 0\n for i in range(len(s)):\n if s[i] == \"<\":\n stack.append(s[i])\n c+=1\n else:\n if (len(stack) == 0) or (stack[-1]!=\"<\"):\n break\n else:\n stack.pop()\n if len(stack) == 0:\n ans+=(2*c)\n c = 0\n print(ans)", "for i in range(int(input())):\n s = input()\n stack = []\n ans = 0\n c = 0\n for i in range(len(s)):\n if s[i] == \"<\":\n stack.append(s[i])\n c+=1\n else:\n if (len(stack) == 0) or (stack[-1]!=\"<\"):\n break\n else:\n stack.pop()\n if len(stack) == 0:\n ans+=(2*c)\n c = 0\n print(ans)", "# cook your dish here\nfor i in range(int(input())):\n s = input()\n stack = []\n ans = 0\n c = 0\n for i in range(len(s)):\n if s[i] == \"<\":\n stack.append(s[i])\n c+=1\n else:\n if (len(stack) == 0) or (stack[-1]!=\"<\"):\n break\n else:\n stack.pop()\n if len(stack) == 0:\n ans+=(2*c)\n c = 0\n print(ans)\n \n", "# cook your dish here\nt=int(input())\nfor i in range(0,t):\n s=input()\n l=[]\n f=0\n m=0\n for j in s:\n if j==\"<\":\n l.append(\"<\")\n elif j==\">\" and len(l)>0:\n l=l[:-1]\n f=f+2\n if l==[]:\n m=f\n else:\n break\n print(m)\n \n ", "tc=int(input())\nfor q in range(tc):\n arr=input()\n stack=[]\n maxx=0\n counter=0\n for i in arr:\n \n counter+=1\n if(i=='<'):\n stack.append(i)\n elif(i=='>' and len(stack)):\n stack.pop()\n if(not stack):\n maxx=counter\n else:\n break\n print(maxx)", "# cook your dish here\nt=int(input())\nfor _ in range(t):\n s=input()\n l=[]\n c=0\n flag=0\n for i in range(len(s)):\n if s[i]=='<':\n c+=1\n else:\n c-=1\n if c==0:\n flag=i+1\n if c<0:\n break\n print(flag)", "# cook your dish here\nt=int(input())\nfor _ in range(t):\n s=input()\n l=[]\n c=0\n flag=0\n for i in range(len(s)):\n if s[i]=='<':\n c+=1\n else:\n c-=1\n if c==0:\n flag=i+1\n if c<0:\n break\n print(flag)", "# cook your dish here\nt=int(input())\nfor _ in range(t):\n s=input()\n l=[]\n c=0\n flag=0\n for i in range(len(s)):\n if s[i]=='<':\n c+=1\n else:\n c-=1\n if c==0:\n flag=i+1\n if c<0:\n break\n print(flag)", "# cook your dish here\nt=int(input())\nfor _ in range(t):\n s=input()\n l=[]\n c=0\n flag=0\n for i in range(len(s)):\n if s[i]=='<':\n c+=1\n else:\n c-=1\n if c==0:\n flag=max(flag,i+1)\n if c<0:\n break\n print(flag)", "T = int(input())\nwhile(T):\n check = []\n s = input()\n cur = 0\n long_prifix = 0\n for i in s:\n cur+=1\n if(i=='<'):\n check.append(i) \n elif(i=='>' and len(check)):\n check.pop()\n if(not check):\n long_prifix = cur\n else:\n break \n print(long_prifix)\t\n T-=1", "def solve(S):\n mystack = []\n ans = 0\n for i in range(len(S)):\n if(S[i] == \"<\"):\n mystack.append(\"<\")\n else:\n if(len(mystack) == 0):\n return ans\n else:\n mystack.pop()\n if(len(mystack) == 0):\n ans = i+1\n return ans\n\n \nT = int(input())\n\nfor j in range(T):\n print(solve(input()))", "def solve(S):\n ans = 0\n t = 0 \n l = []\n\n for a in S:\n t += 1\n if a=='<':\n l.append(a)\n if a=='>':\n if len(l) == 0:\n return ans\n \n if len(l) > 0:\n l.pop()\n if len(l) == 0:\n ans = t\n \n \n return ans\n \n \n\nT = int(input())\nls=list()\n\nfor i in range(T):\n print(solve(input()))\n # l=liinput()\n # ls.extend(l)"]
{"inputs": [["3", "<<>>", "><", "<>>>", ""]], "outputs": [["4", "0", "2"]]}
INTERVIEW
PYTHON3
CODECHEF
9,746
0080c125aa184e1776d901b4b6b7110b
UNKNOWN
The chef is trying to solve some pattern problems, Chef wants your help to code it. Chef has one number K to form a new pattern. Help the chef to code this pattern problem. -----Input:----- - First-line will contain $T$, the number of test cases. Then the test cases follow. - Each test case contains a single line of input, one integer $K$. -----Output:----- For each test case, output as the pattern. -----Constraints----- - $1 \leq T \leq 100$ - $1 \leq K \leq 100$ -----Sample Input:----- 3 2 3 4 -----Sample Output:----- 0 *1 **2 0 *1 **2 ***3 0 *1 **2 ***3 ****4 -----EXPLANATION:----- No need, else pattern can be decode easily.
["# cook your dish here\nt=int(input())\nfor i in range(0,t):\n my_ip = int(input().strip())\n for xyz in range(my_ip+1):\n for abc in range(0,xyz+1):\n if abc == xyz:\n print(xyz,end=\"\")\n else:\n print('*',end=\"\")\n\n print()", "# cook your dish here\nn=int(input())\nfor i in range(n):\n k=int(input())\n for j in range(0,k+1):\n for l in range(0,j+1):\n \n if j==0:\n print(j)\n elif l<j:\n print(\"*\",end=\"\")\n elif l==j:\n print(l)\n print(\"\\n\") ", "for u in range(int(input().strip())):\r\n n = int(input().strip())\r\n for i in range(n+1):\r\n for space in range(0,i+1):\r\n \r\n if space == i:\r\n print(i,end=\"\")\r\n else:\r\n print('*',end=\"\")\r\n \r\n print()", "for _ in range(int(input())):\r\n n = int(input())\r\n print(0)\r\n x = 1\r\n for i in range(n):\r\n print('*'*x+str(x))\r\n x+=1", "try:\n\tfor _ in range(int(input())):\n\t\tn=int(input())\n\t\tprint(0)\n\t\tfor i in range(1,n+1):\n\t\t\tprint(\"*\"*i + str(i))\nexcept: pass", "try:\n\tfor _ in range(int(input())):\n\t\tn=int(input())\n\t\tprint(0)\n\t\tfor i in range(1,n+1):\n\t\t\tprint(\"*\"*i + str(i))\nexcept: pass", "for i in range(int(input())):\n s=int(input())\n for i in range(0,s+1):\n for k in range(i):\n print(\"*\",end=\"\")\n print(i)", "from sys import*\r\ninput=stdin.readline\r\nt=int(input())\r\nfor _ in range(t):\r\n n=int(input())\r\n for i in range(n+1):\r\n d=i\r\n for j in range(i+1):\r\n if d>0:\r\n print(\"*\",end=\"\")\r\n d-=1\r\n else:\r\n print(j,end=\"\")\r\n print()\r\n", "# cook your dish here\nfor i in range(int(input())):\n s=int(input())\n for i in range(0,s+1):\n for k in range(i):\n print(\"*\",end=\"\")\n print(i)", "\r\nt=int(input())\r\nwhile t>0:\r\n t-=1\r\n n=int(input())\r\n a=[]\r\n print(0)\r\n for i in range(1,n+1):\r\n for j in range(i+1):\r\n if j==i:\r\n print(i,end=\"\")\r\n else:\r\n print(\"*\",end=\"\")\r\n print()\r\n", "n=int(input())\nfor i in range(n):\n a=int(input())\n b=\"\"\n for j in range(0,a+1):\n b=\"\"\n b=b+'*'*j+str(j)\n print(b)\n", "# cook your dish here\nfor i in range(int(input())):\n n = int(input())\n for i in range(n+1):\n temp=i\n while(temp!=0):\n print(\"*\",end=\"\")\n temp-=1\n print(i,end=\"\")\n print()", "for _ in range(int(input())):\r\n n=int(input())\r\n for i in range(0,n+1):\r\n for j in range(0,i+1):\r\n if i==j:\r\n print(j,end='')\r\n else:\r\n print('*',end='')\r\n print()", "# cook your dish here\nfor _ in range(int(input())):\n n=int(input())\n for i in range(n+1):\n for j in range(i+1):\n if j==i:\n print(i,end='')\n else:\n print(\"*\",end='')\n print()", "# cook your dish here\nfor _ in range(int(input())):\n n=int(input())\n print(\"0\")\n for i in range(1,n+1):\n for j in range(i):\n print(\"*\",end=\"\")\n print(i)\n\n", "for _ in range(int(input())):\n n=int(input())\n a=0\n for _ in range(1,n+2):\n print('*'*(_-1),end=\"\")\n print(_-1)\n print() ", "n = int(input())\nwhile(n>0):\n n-=1\n a = int(input())\n for i in range(a+1):\n print(\"*\"*i, end='')\n print(i)\n", "n=int(input())\nfor i in range(n):\n a=int(input())\n for j in range(a+1):\n for k in range(j):\n print(\"*\",end=\"\")\n print(j)# cook your dish here\n", "n=int(input())\nfor i in range(n):\n a=int(input())\n for j in range(a+1):\n for k in range(j):\n print(\"*\",end=\"\")\n print(j)# cook your dish here\n", "for _ in range(int(input())):\r\n n = int(input())\r\n for i in range(n + 1): print('*' * i + str(i))", "for _ in range(int(input())):\n starcount = 0\n n = int(input())\n for i in range(n + 1):\n print(i * \"*\", end='')\n print(i)\n\n #print(\"________________\")# cook your dish here\n"]
{"inputs": [["3", "2", "3", "4", ""]], "outputs": [["0", "*1", "**2", "0", "*1", "**2", "***3", "0", "*1", "**2", "***3", "****4"]]}
INTERVIEW
PYTHON3
CODECHEF
4,519
14c4e72e8587aadc810aef3651b3248e
UNKNOWN
You are given positive integers $N$ and $D$. You may perform operations of the following two types: - add $D$ to $N$, i.e. change $N$ to $N+D$ - change $N$ to $\mathop{\mathrm{digitsum}}(N)$ Here, $\mathop{\mathrm{digitsum}}(x)$ is the sum of decimal digits of $x$. For example, $\mathop{\mathrm{digitsum}}(123)=1+2+3=6$, $\mathop{\mathrm{digitsum}}(100)=1+0+0=1$, $\mathop{\mathrm{digitsum}}(365)=3+6+5=14$. You may perform any number of operations (including zero) in any order. Please find the minimum obtainable value of $N$ and the minimum number of operations required to obtain this value. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first and only line of each test case contains two space-separated integers $N$ and $D$. -----Output----- For each test case, print a single line containing two space-separated integers — the minimum value of $N$ and the minimum required number of operations. -----Constraints----- - $1 \le T \le 10$ - $1 \le N, D \le 10^{10}$ -----Subtasks----- Subtask #1 (30 points): $1 \le N, D \le 100$ Subtask #2 (70 points): original constraints -----Example Input----- 3 2 1 9 3 11 13 -----Example Output----- 1 9 3 2 1 4 -----Explanation----- Example case 1: The value $N=1$ can be achieved by 8 successive "add" operations (changing $N$ to $10$) and one "digit-sum" operation. Example case 2: You can prove that you cannot obtain $N=1$ and $N=2$, and you can obtain $N=3$. The value $N=3$ can be achieved by one "add" and one "digitsum" operation, changing $9$ to $12$ and $12$ to $3$. Example case 3: $N=1$ can be achieved by operations "add", "add", "digitsum", "digitsum": $11 \rightarrow 24 \rightarrow 37 \rightarrow 10 \rightarrow 1$.
["from collections import deque \r\nT=int(input())\r\ndef break_down(num):\r\n count=0\r\n while(len(num)!=1):\r\n temp=0\r\n for i in range(0,len(num)):\r\n temp=temp+int(num[i])\r\n num=str(temp)\r\n count=count+1\r\n return (int(num),count)\r\ndef digit_sum(num):\r\n temp=0\r\n for i in range(0,len(num)):\r\n temp=temp+int(num[i])\r\n num=temp\r\n return (num)\r\nwhile(T):\r\n queue=deque()\r\n count_n=0\r\n count_d=0\r\n T=T-1\r\n N,d=[i for i in input().split()]\r\n n,count_n=break_down(N)\r\n D,count_D=break_down(d)\r\n dic={}\r\n if(D==1 or D==2 or D==4 or D==5 or D==7 or D==8):\r\n mini=1 \r\n elif(D==3 or D==6):\r\n mini=min(digit_sum(str(n+3)),digit_sum(str(n+6)),digit_sum(str(n+9)))\r\n else:\r\n mini=n\r\n queue.append((int(N),0))\r\n ele=int(N)\r\n count=0\r\n while(len(queue)!=0):\r\n ele,count=queue.popleft()\r\n if(ele==mini):\r\n break\r\n else:\r\n if(len(str(ele))==1):\r\n temp1=ele+int(d)\r\n queue.append((temp1,count+1))\r\n else:\r\n temp2=digit_sum(str(ele))\r\n temp1=ele+int(d)\r\n queue.append((temp2,count+1))\r\n queue.append((temp1,count+1))\r\n print(ele,count)", "def ds(n):\r\n num_str = str(n)\r\n sum = 0\r\n for i in range(0, len(num_str)):\r\n sum += int(num_str[i])\r\n return sum\r\n\r\nt = int(input())\r\n\r\nfor _ in range(t):\r\n\tn,d = input().split()\r\n\tn = int(n)\r\n\td = int(d)\r\n\r\n\ts = set()\r\n\ttemp = n\r\n\tfor i in range(500000):\r\n\t\tif temp<=9:\r\n\t\t\tif not temp in s:\r\n\t\t\t\ts.add(temp)\r\n\t\t\t\ttemp = temp+d\r\n\t\t\telse:\r\n\t\t\t\tbreak\r\n\t\telse:\r\n\t\t\ttemp = ds(temp)\r\n\r\n\ts = sorted(s)\r\n\tk = s[0]\r\n\r\n\tq = []\r\n\tans = 0 \r\n\tq.append((n,1))\r\n\twhile len(q) != 0:\r\n\t\tnum = q[0][0]\r\n\t\tstep = q[0][1]\r\n\t\tq.pop(0)\r\n\t\tif num is k:\r\n\t\t\tans = step-1\r\n\t\t\tbreak\r\n\t\tq.append((num+d,step+1))\r\n\t\tq.append((ds(num),step+1))\r\n\t\t\r\n\tprint(str(k)+\" \"+str(ans))\r\n", "from collections import defaultdict\r\ndef digitSum(n):\r\n n=str(n)\r\n s=0\r\n for i in range(len(n)):\r\n s+=int(n[i])\r\n return s\r\ndef solve(n,d):\r\n queue=[[n,0]]\r\n has=defaultdict(int)\r\n i=0\r\n while i<10000 and len(queue)!=0:\r\n t=queue.pop(0)\r\n if t[0]<10:\r\n if t[0] not in has:\r\n has[t[0]]=t[1]\r\n else:\r\n queue.append([digitSum(t[0]),t[1]+1])\r\n queue.append([t[0]+d,t[1]+1])\r\n i+=1\r\n print(min(has),has[min(has)])\r\n \r\n \r\nfor _ in range(int(input())):\r\n n,d=map(int,input().split())\r\n solve(n,d)\r\n \r\n", "def disum(x):\r\n x=str(x)\r\n sum=0\r\n for i in range(len(x)):\r\n sum+=int(x[i])\r\n return sum\r\nfor _ in range(int(input())):\r\n n,d=map(int,input().split())\r\n ans={}\r\n souma=[(n,0)]\r\n ushijima=1\r\n i=0\r\n while i<10000:\r\n nakiri=souma.pop(0)\r\n if nakiri[0]<10:\r\n if nakiri[0] not in ans:\r\n ans[nakiri[0]]=nakiri[1]\r\n else:\r\n souma.append((disum(nakiri[0]),nakiri[1]+1))\r\n souma.append((nakiri[0]+d,nakiri[1]+1))\r\n i+=1\r\n print(min(ans),ans[min(ans)])\r\n", "def disum(x):\r\n x=str(x)\r\n sum=0\r\n for i in range(len(x)):\r\n sum+=int(x[i])\r\n return sum\r\nfor _ in range(int(input())):\r\n n,d=map(int,input().split())\r\n ans={}\r\n souma=[(n,0)]\r\n ushijima=1\r\n i=0\r\n while i<100000:\r\n nakiri=souma.pop(0)\r\n if nakiri[0]<10:\r\n if nakiri[0] not in ans:\r\n ans[nakiri[0]]=nakiri[1]\r\n else:\r\n souma.append((disum(nakiri[0]),nakiri[1]+1))\r\n souma.append((nakiri[0]+d,nakiri[1]+1))\r\n i+=1\r\n print(min(ans),ans[min(ans)])\r\n", "def disum(x):\r\n x=str(x)\r\n sum=0\r\n for i in range(len(x)):\r\n sum+=int(x[i])\r\n return sum\r\nfor _ in range(int(input())):\r\n n,d=map(int,input().split())\r\n ans={}\r\n souma=[(n,0)]\r\n ushijima=1\r\n i=0\r\n while i<1000:\r\n nakiri=souma.pop(0)\r\n if nakiri[0]<10:\r\n if nakiri[0] not in ans:\r\n ans[nakiri[0]]=nakiri[1]\r\n else:\r\n souma.append((disum(nakiri[0]),nakiri[1]+1))\r\n souma.append((nakiri[0]+d,nakiri[1]+1))\r\n i+=1\r\n print(min(ans),ans[min(ans)])\r\n", "def dSum(n):\n ans = 0\n while(n>0):ans+=n%10;n//=10\n return ans\ndef solve(n,d,step,ans):\n if(n<10):ans[n] = min(ans[n],step)\n left = dSum(n);right = n+d\n if(step>13):return step\n solve(left,d,step+1,ans);solve(right,d,step+1,ans)\nfor T in range(int(input())):\n N,D = [int(x) for x in input().split()];ans = {}\n for i in range(10):ans[i] = 100\n solve(N,D,0,ans);x,y = [100,100]\n for i,j in ans.items():\n if(j!=100):x,y = i,j;break\n print(x,y)", "def dSum(n):\r\n ans = 0\r\n while(n>0):\r\n ans+=n%10\r\n n//=10\r\n return ans\r\n\r\ndef solve(n,d,step,ans):\r\n if(n<10):\r\n ans[n] = min(ans[n],step)\r\n left = dSum(n)\r\n right = n+d\r\n if(step>13):\r\n return step\r\n solve(left,d,step+1,ans)\r\n solve(right,d,step+1,ans)\r\n\r\nfor T in range(int(input())):\r\n N,D = [int(x) for x in input().split()]\r\n ans = {}\r\n for i in range(10):\r\n ans[i] = 100\r\n solve(N,D,0,ans)\r\n x,y = [100,100]\r\n for i,j in ans.items():\r\n if(j!=100):\r\n x = i\r\n y = j\r\n break\r\n print(x,y)", "t = int(input())\n\ndef digisum(a):\n a = str(a)\n x = 0\n for i in a:\n x += int(i)\n return x\n\nfor _ in range(0,t):\n x = input()\n n = int(x.split(' ')[0])\n d = int(x.split(' ')[1])\n \n dict = {n:0}\n stop_at = 1\n curr_items = [n]\n next_items = []\n steps = 0\n \n #if n%3 == 0 and d%3 == 0:\n # stop_at = 3\n \n while stop_at not in dict and steps < 11:\n steps += 1\n for i in curr_items:\n ds = digisum(i) if i >= 10 else 0\n ad = i + d\n \n if ds != 0 and ds not in dict:\n next_items.append(ds)\n dict[ds] = steps\n \n if ad not in dict:\n next_items.append(ad)\n dict[ad] = steps\n \n curr_items,next_items = next_items,[] \n \n for i in range(1,10):\n if i in dict:\n stop_at = i\n steps = dict[i]\n break\n \n print(stop_at,steps)\n ", "\ndef digitSum(digit):\n result=0\n s=str(digit)\n for x in s:\n result+=int(x)\n return result\n\ndef main():\n t=int(input())\n for _ in range(t):\n l=[]\n min1, pos=100000, -10\n # f=[]\n # craw=[True, False, False, False, False, False, False, False, False, False]\n # dic={}\n # fag=[True]*10\n n, d=input().split(\" \")\n n=int(n)\n d=int(d)\n\n i=0\n # if d%9==0:\n # i=0\n # while n>9:\n # i+=1\n # n=digitSum(n)\n # print(n, i, sep=\" \")\n # elif d%3==0:\n # i=0\n # while n>3:\n # i+=1\n # if n>9:\n # n=digitSum(n)\n # else:\n # n+=d\n # print(n, i, sep=\" \")\n # else:\n l.append([n, 0])\n while i<10000 and l:\n tem=l.pop(0)\n if min1>tem[0]:\n min1=tem[0]\n pos=tem[1]\n if tem[0]>9:\n l.append([digitSum(tem[0]), tem[1]+1])\n l.append([tem[0]+d, tem[1]+1])\n i+=1\n print(\"{0} {1}\".format(min1, pos))\nmain()", "\ndef digitSum(digit):\n result=0\n s=str(digit)\n for x in s:\n result+=int(x)\n return result\n\ndef main():\n t=int(input())\n for _ in range(t):\n l=[]\n min1, pos=100000, -10\n # f=[]\n # craw=[True, False, False, False, False, False, False, False, False, False]\n # dic={}\n # fag=[True]*10\n n, d=input().split(\" \")\n n=int(n)\n d=int(d)\n\n i=0\n # if d%9==0:\n # i=0\n # while n>9:\n # i+=1\n # n=digitSum(n)\n # print(n, i, sep=\" \")\n # elif d%3==0:\n # i=0\n # while n>3:\n # i+=1\n # if n>9:\n # n=digitSum(n)\n # else:\n # n+=d\n # print(n, i, sep=\" \")\n # else:\n l.append([n, 0])\n while i<100000 and l:\n tem=l.pop(0)\n if min1>tem[0]:\n min1=tem[0]\n pos=tem[1]\n if tem[0]>9:\n l.append([digitSum(tem[0]), tem[1]+1])\n l.append([tem[0]+d, tem[1]+1])\n i+=1\n print(\"{0} {1}\".format(min1, pos))\nmain()", "# cook your dish here\nimport queue\ndef digitsum(a):\n lo = 0\n s = str(a)\n for i in s:\n lo += int(i)\n return lo\nfor _ in range(int(input())):\n min1,pos = 1000000,-10\n track = queue.Queue(100000)\n n ,d = map(int,input().split())\n i = 0\n track.put([n,0])\n while i<100000 and track.empty()!=True:\n a,b = track.get()\n if min1>a:\n min1 = a\n pos = b\n if a>9:\n track.put([digitsum(a),b+1])\n track.put([a+d,b+1])\n i+=1\n print(min1,pos)", "# -*- coding: utf-8 -*-\r\n\"\"\"\r\nCreated on Tue Apr 23 17:13:53 2019\r\n\r\n@author: avina\r\n\"\"\"\r\n\r\ndef digit_sum(n):\r\n d= 0\r\n while n :\r\n d+= n%10\r\n n //= 10\r\n return d\r\n\r\n\r\nfor _ in range(int(input())):\r\n n,d = map(int, input().strip().split())\r\n\r\n q = []\r\n ma = {}\r\n q.append((n,0))\r\n i = 0\r\n while i < 10000 and len(q) != 0:\r\n t = q.pop(0)\r\n if t[0] < 10:\r\n if t[0] in ma:\r\n continue\r\n else:\r\n ma[t[0]] = t[1]\r\n else:\r\n q.append((digit_sum(t[0]) , t[1]+1))\r\n \r\n q.append((t[0] + d, t[1] + 1))\r\n i+=1\r\n k = sorted(list(ma.keys()))\r\n print(k[0], ma[k[0]])\r\n ", "def digitsum(n):\n s=0\n while n:\n s=s+n%10\n n=n//10\n return(s)\nx=int(input())\nfor i in range(x):\n a,b=input().split()\n a,b=[int(a),int(b)]\n l1=[(a,0)]\n l2={}\n i=0\n while i<10000 and len(l1)!=0:\n first=l1.pop(0)\n if first[0]<10:\n if first[0] not in l2:\n l2[first[0]]=first[1]\n else:\n l1.append((digitsum(first[0]),first[1]+1))\n l1.append((first[0]+b,first[1]+1))\n i+=1\n a=min(l2)\n print(a,l2[a])", "def digitsum(n):\n s=0\n while n:\n s=s+n%10\n n=n//10\n return(s)\nx=int(input())\nfor i in range(x):\n a,b=input().split()\n a,b=[int(a),int(b)]\n l1=[(a,0)]\n l2={}\n i=0\n while i<10000 and len(l1)!=0:\n first=l1.pop(0)\n if first[0]<10:\n if first[0] not in l2:\n l2[first[0]]=first[1]\n else:\n l1.append((digitsum(first[0]),first[1]+1))\n l1.append((first[0]+b,first[1]+1))\n i+=1\n a=min(l2)\n print(a,l2[a])", "# https://www.codechef.com/OCT18B/problems/MINDSUM\r\n'''\r\n\tAuthor - Subhajit Das\r\n\tUniversity of Engineering and Management, Kolkata\r\n\t28/1/2018\r\n'''\r\n\r\n\r\ndef sum_digits(x):\r\n return sum(map(int, str(x)))\r\n\r\n\r\ndef main():\r\n for _ in range(int(input())):\r\n n, d = map(int, input().strip().split())\r\n\r\n que = [(n, 0)]\r\n min_track = dict()\r\n i = 0\r\n op_count = 0\r\n while len(que) != 0 and i <= 1000:\r\n i += 1\r\n n, op_count = que.pop(0)\r\n if n == 1:\r\n break\r\n if n > 1 and n <= 9:\r\n if n not in min_track.keys():\r\n min_track[n] = op_count\r\n else:\r\n min_track[n] = min(min_track[n], op_count)\r\n else:\r\n que.append((sum_digits(n), op_count+1))\r\n que.append((n+d, op_count+1))\r\n\r\n if n == 1:\r\n print(n, op_count)\r\n else:\r\n min_key = min(min_track.keys())\r\n print(min_key, min_track[min_key])\r\n\r\n\r\ndef __starting_point():\r\n main()\r\n\n__starting_point()", "# https://www.codechef.com/OCT18B/problems/MINDSUM\r\n'''\r\n\tAuthor - Subhajit Das\r\n\tUniversity of Engineering and Management, Kolkata\r\n\t28/1/2018\r\n'''\r\n\r\n\r\ndef sum_digits(x):\r\n return sum(map(int, str(x)))\r\n\r\n\r\ndef main():\r\n for _ in range(int(input())):\r\n n, d = map(int, input().strip().split())\r\n\r\n que = [(n, 0)]\r\n min_track = dict()\r\n i = 0\r\n op_count = 0\r\n while len(que) != 0 and i <= 10000:\r\n i += 1\r\n n, op_count = que.pop(0)\r\n if n == 1:\r\n break\r\n if n > 1 and n <= 9:\r\n if n not in min_track.keys():\r\n min_track[n] = op_count\r\n else:\r\n min_track[n] = min(min_track[n], op_count)\r\n else:\r\n que.append((sum_digits(n), op_count+1))\r\n que.append((n+d, op_count+1))\r\n\r\n if n == 1:\r\n print(n, op_count)\r\n else:\r\n min_key = min(min_track.keys())\r\n print(min_key, min_track[min_key])\r\n\r\n\r\ndef __starting_point():\r\n main()\r\n\n__starting_point()", "def dsum(n):\r\n ddsum=0\r\n while(n!=0):\r\n a=int(n%10)\r\n ddsum=ddsum+a\r\n n=int(n/10)\r\n return ddsum \r\n\r\nfor _ in range(0,int(input())):\r\n l=[]\r\n a,b=map(int,input().split())\r\n minval=1000000000\r\n val=a\r\n cnt=0\r\n inv=0\r\n l.append([])\r\n l[inv].append(val)\r\n l[inv].append(cnt)\r\n if(minval>val):\r\n minval=val\r\n fcnf=cnt\r\n for j in range(0,50000):\r\n q=l.pop(0)\r\n inv-=1\r\n l.append([])\r\n cnt=q[1]+1\r\n inv+=1\r\n l[inv].append(q[0]+b)\r\n l[inv].append(cnt)\r\n if(minval>(q[0]+b)):\r\n minval=(q[0]+b)\r\n fcnf=cnt\r\n #print(l) \r\n if(q[0]>9):\r\n p=dsum(q[0])\r\n l.append([])\r\n inv+=1\r\n l[inv].append(p)\r\n l[inv].append(cnt)\r\n if(minval>p):\r\n minval=p\r\n fcnf=cnt\r\n print(minval,fcnf) \r\n\r\n\r\n \r\n \r\n\r\n", "def dsum(n):\r\n ddsum=0\r\n while(n!=0):\r\n a=int(n%10)\r\n ddsum=ddsum+a\r\n n=int(n/10)\r\n return ddsum \r\n\r\nfor _ in range(0,int(input())):\r\n l=[]\r\n a,b=map(int,input().split())\r\n minval=1000000000\r\n val=a\r\n cnt=0\r\n inv=0\r\n l.append([])\r\n l[inv].append(val)\r\n l[inv].append(cnt)\r\n if(minval>val):\r\n minval=val\r\n fcnf=cnt\r\n for j in range(0,100000):\r\n q=l.pop(0)\r\n inv-=1\r\n l.append([])\r\n cnt=q[1]+1\r\n inv+=1\r\n l[inv].append(q[0]+b)\r\n l[inv].append(cnt)\r\n if(minval>(q[0]+b)):\r\n minval=(q[0]+b)\r\n fcnf=cnt\r\n #print(l) \r\n if(q[0]>9):\r\n p=dsum(q[0])\r\n l.append([])\r\n inv+=1\r\n l[inv].append(p)\r\n l[inv].append(cnt)\r\n if(minval>p):\r\n minval=p\r\n fcnf=cnt\r\n print(minval,fcnf) \r\n\r\n\r\n \r\n \r\n\r\n", "def ds(x):\r\n\t\tss=0\r\n\t\tx=str(x)\r\n\t\tl=len(x)\r\n\t\tfor i in range(l):\r\n\t\t\tm=int(x[i])\r\n\t\t\tss+=m\r\n\t\treturn int(ss)\r\nimport queue as q\r\nt=int(input())\r\nwhile(t):\r\n\tt=t-1\r\n\tn,d=map(int,input().split())\r\n\ta={n:0}\r\n\ti=0\r\n\tarr=q.Queue(maxsize=100000000000000)\r\n\tarr.put((n,0))\r\n\twhile(i<100000):\r\n\t\tx=arr.get()\r\n\t\tp1=ds(x[0])\r\n\t\tp2=x[0]+d\r\n\t\tif p1<10 and not(p1 in a):\r\n\t\t\ta[p1]=x[1]+1\r\n\t\tif p2<10 and not(p2 in a):\r\n\t\t\ta[p2]=x[1]+1\r\n\t\tarr.put((p1,x[1]+1))\r\n\t\tarr.put((p2,x[1]+1))\r\n\t\ti+=1\r\n\tnn=min(a)\r\n\tprint(nn,a[nn])", "def dsum(n):\r\n return sum(int(i) for i in str(n))\r\nfor _ in range(int(input())):\r\n n,d=map(int,input().split())\r\n q=[n]\r\n lev=0 \r\n res=[]\r\n vis={}\r\n dist={}\r\n dist[n]=0\r\n lev=0 \r\n res.append([n,0])\r\n while q:\r\n siz=len(q)\r\n lev+=1 \r\n for i in range(siz):\r\n t=q.pop(0)\r\n if t+d not in vis:\r\n vis[t+d]=1 \r\n res.append([t+d,lev])\r\n #print(t,t+d,lev)\r\n dist[t+d]=dist.get(t)+1\r\n q.append(t+d)\r\n if dsum(t) not in vis:\r\n vis[dsum(t)]=1 \r\n res.append([dsum(t),lev])\r\n #print(t,dsum(t),lev)\r\n dist[dsum(t)]=dist.get(t)+1 \r\n q.append(dsum(t))\r\n \r\n if lev==32:\r\n break \r\n #print(res)\r\n res.sort(key=lambda x:x[0])\r\n #print(res)\r\n print(res[0][0],res[0][1])", "tl=int(input())\r\ndef dsum(n):\r\n ddsum=0\r\n while(n!=0):\r\n a=int(n%10)\r\n ddsum=ddsum+a\r\n n=int(n/10)\r\n return ddsum \r\nwhile(tl>0):\r\n n,d = map(int,input().split(\" \"))\r\n i=0\r\n dic=dict()\r\n l=[(n,0)]\r\n while(i<10000 and len(l)!=0):\r\n t=l.pop(0)\r\n if(t[0]<10):\r\n if(t[0] not in dic):\r\n dic[t[0]]=t[1]\r\n else:\r\n continue\r\n else:\r\n l.append((dsum(t[0]),t[1]+1))\r\n l.append((t[0]+d,t[1]+1))\r\n i+=1\r\n a=min(dic)\r\n print(a,dic[a])\r\n tl=tl-1", "tl=int(input())\r\ndef dsum(n):\r\n ddsum=0\r\n while(n!=0):\r\n a=int(n%10)\r\n ddsum=ddsum+a\r\n n=int(n/10)\r\n return ddsum \r\nwhile(tl>0):\r\n n,d = map(int,input().split(\" \"))\r\n i=0\r\n dic=dict()\r\n l=[(n,0)]\r\n while(i<100000 and len(l)!=0):\r\n t=l.pop(0)\r\n if(t[0]<10):\r\n if(t[0] not in dic):\r\n dic[t[0]]=t[1]\r\n else:\r\n continue\r\n else:\r\n l.append((dsum(t[0]),t[1]+1))\r\n l.append((t[0]+d,t[1]+1))\r\n i+=1\r\n a=min(dic)\r\n print(a,dic[a])\r\n tl=tl-1", "tl=int(input())\r\ndef dsum(n):\r\n ddsum=0\r\n while(n!=0):\r\n a=int(n%10)\r\n ddsum=ddsum+a\r\n n=int(n/10)\r\n return ddsum \r\nwhile(tl>0):\r\n n,d = map(int,input().split(\" \"))\r\n i=0\r\n dic=dict()\r\n l=[(n,0)]\r\n while(i<1000 and len(l)!=0):\r\n t=l.pop(0)\r\n if(t[0]<10):\r\n if(t[0] not in dic):\r\n dic[t[0]]=t[1]\r\n else:\r\n continue\r\n else:\r\n l.append((dsum(t[0]),t[1]+1))\r\n l.append((t[0]+d,t[1]+1))\r\n i+=1\r\n a=min(dic)\r\n print(a,dic[a])\r\n tl=tl-1"]
{"inputs": [["3", "2 1", "9 3", "11 13", ""]], "outputs": [["1 9", "3 2", "1 4"]]}
INTERVIEW
PYTHON3
CODECHEF
19,895
9a25733138b5b3816bf44043fa11adb7
UNKNOWN
Chef has a binary array in an unsorted manner. Cheffina challenges chef to find the transition point in the sorted (ascending) binary array. Here indexing is starting from 0. Note: Transition point always exists. -----Input:----- - First-line will contain $T$, the number of test cases. Then the test cases follow. - Each test case contains two lines of input, $N$. - N space-separated binary numbers. -----Output:----- For each test case, output in a single line answer. -----Constraints----- - $1 \leq T \leq 10$ - $1 \leq N \leq 10^5$ -----Sample Input:----- 1 5 0 1 0 0 1 -----Sample Output:----- 3 -----EXPLANATION:----- binary array in sorted form will look like = [0, 0, 0, 1, 1]
["# cook your dish here\nfor _ in range(int(input())):\n n=int(input())\n A=list(map(int,input().split()))\n A.sort()\n for i in range(len(A)):\n if A[i]==1:\n print(i)\n break", "for x in range(int(input())):\n n = int(input())\n S = list(map(int,input().split()))\n ind = n - sum(S)\n print(ind)", "from sys import*\r\ninput=stdin.readline\r\nt=int(input())\r\nfor _ in range(t):\r\n n=int(input())\r\n l=[int(x) for x in input().split()]\r\n l.sort()\r\n print(l.index(1))\r\n", "list = []\r\n\r\nx = int(input())\r\noutput = []\r\nfor i in range(x):\r\n count = 0\r\n val = int(input())\r\n line = input()\r\n z = line.split()\r\n z = [int(y) for y in z]\r\n for j in z:\r\n if j == 0:\r\n count += 1\r\n \r\n output.append(count)\r\nfor i in output:\r\n print(i)", "# cook your dish here\nlist = []\n\nx = int(input())\noutput = []\nfor i in range(x):\n count = 0\n val = int(input())\n line = input()\n z = line.split()\n z = [int(y) for y in z]\n for j in z:\n if j == 0:\n count += 1\n \n output.append(count)\nfor i in output:\n print(i)", "list = []\r\n\r\nx = int(input())\r\noutput = []\r\nfor i in range(x):\r\n count = 0\r\n val = int(input())\r\n line = input()\r\n z = line.split()\r\n z = [int(y) for y in z]\r\n for j in z:\r\n if j == 0:\r\n count += 1\r\n \r\n output.append(count)\r\nfor i in output:\r\n print(i)", "try:\n for i in range(int(input())):\n n=int(input())\n l=sorted(list(map(int,input().split())))\n print(l.count(0))\nexcept Exception:\n pass\n\t", "t=int(input())\nwhile(t):\n n=int(input())\n l=list(map(int,input().split()))\n print(l.count(0))\n t=t-1", "T=int(input())\r\nfor i in range(T):\r\n n=int(input())\r\n a=list(map(int,input().split()))\r\n a.sort()\r\n for i in range(n):\r\n if a[i]!=a[i+1]:\r\n print(i+1)\r\n break\r\n", "for i in range(int(input())):\n size = int(input())\n num = list(map(int,input().split()))\n print(num.count(0))\n ", "def find(arr, n):\r\n for i in range(n):\r\n if(arr[i] == 1):\r\n return i\r\n \r\n return -1\r\n\r\nt=int(input())\r\nfor x in range(t):\r\n n=int(input())\r\n arr=list(map(int,input().split()))\r\n arr.sort()\r\n p = find(arr, n)\r\n if p >= 0:\r\n print(p)", "# cook your dish here\nt=int(input())\nfor i in range(t):\n n=int(input())\n l=list(map(int,input().split()))\n l.sort()\n x=l.index(1)\n print(x)\n", "# cook your dish here\nt=int(input())\nfor i in range(t):\n n=int(input())\n x=list(map(int,input().split()))\n x.sort()\n print(x.index(1))", "t=int(input())\nfor i in range(t):\n a=int(input())\n b=[int(b) for b in input().split()]\n b.sort()\n for j in range(len(b)):\n if b[j]==0 and b[j+1]==1:\n print(j+1)\n break", "t = int(input())\nfor _ in range(t):\n n = int(input())\n arr = list(map(int , input().split()))\n arr.sort()\n i = 0\n while arr[i] != 1:\n i += 1\n print(i)", "# cook your dish here\nn=int(input())\nfor _ in range(n):\n m=int(input())\n lis=list(map(int,input().strip().split()))\n lis.sort()\n print(lis.index(1))", "# cook your dish here\nfor _ in range(int(input())):\n n = int(input())\n a = list(map(int,input().split()))\n c = a.count(1)\n print(n-c)", "t=int(input())\nfor i in range(t):\n n=int(input())\n l=[int(l) for l in input().split()]\n p=l.count(0)\n print(p)\n", "from sys import stdin, stdout\r\ndef findTransitionPoint(arr, n):\r\n\tlb = 0\r\n\tub = n - 1\r\n\twhile (lb <= ub):\r\n\t\tmid = (int)((lb + ub) / 2)\r\n\t\tif (arr[mid] == 0):\r\n\t\t\tlb = mid + 1\r\n\t\telif (arr[mid] == 1):\r\n\t\t\tif (mid == 0 \\\r\n\t\t\t\tor (mid > 0 and\\\r\n\t\t\t\tarr[mid - 1] == 0)):\r\n\t\t\t\treturn mid\r\n\t\t\tub = mid-1\r\n\treturn -1\r\ntest = int(stdin.readline())\r\nfor _ in range(test):\r\n n = int(stdin.readline())\r\n arr = sorted(list(map(int, stdin.readline().split())))\r\n pp = findTransitionPoint(arr, n);\r\n print(pp)\r\n\r\n", "# cook your dish here\nt = int(input())\nfor i in range(t):\n N = int(input())\n lst = list(map(int,input().split()))\n count = 0\n lst.sort()\n for j in lst:\n if j == 0 :\n count = count+1 \n print(count) \n", "for _ in range(int(input())):\r\n n = int(input())\r\n l = list(map(int,input().split()))\r\n l.sort()\r\n for i in range(n-1):\r\n if l[i] != l[i+1]:\r\n print(i+1)", "# cook your dish here\ntestcases = int(input())\nfor x in range(testcases):\n N = map(int,input().split())\n A = sorted(list(map(int,input().split())))\n print(A.count(0))\n ", "def findTransitionPoint(arr, n):\n lb = 0\n ub = n - 1\n\n while (lb <= ub):\n\n mid = (int)((lb + ub) / 2)\n \n if (arr[mid] == 0):\n lb = mid + 1\n\n elif (arr[mid] == 1):\n\n if (mid == 0 \\\n or (mid > 0 and\\\n arr[mid - 1] == 0)):\n return mid\n\n ub = mid-1\n \n return -1\n \n\nfor _ in range(int(input())):\n n = int(input())\n nn = list(map(int,input().split(\" \")))\n nn = sorted(nn)\n # res = 0\n # for ele in nn: \n # res = (res << 1) | ele \n # print(res)\n\n\n arr = nn\n n = len(arr)\n point = findTransitionPoint(arr, n);\n print(point)\n ", "# cook your dish here\ntestcases = int(input())\nfor x in range(testcases):\n N = int(input())\n A = list(map(int,input().split()))\n print(A.count(0))", "t=int(input())\nwhile(t):\n n=int(input())\n a=[]\n p=0\n a=list(map(int,input().split()))\n for i in range(0,n):\n if(a[i]==0):\n p=p+1\n print(p)\n t=t-1\n"]
{"inputs": [["1", "5", "0 1 0 0 1", ""]], "outputs": [["3"]]}
INTERVIEW
PYTHON3
CODECHEF
6,007
87688431fd94b5c2040abc94581e2341
UNKNOWN
Chef likes strings a lot but he likes palindromic strings even more. Today he found an old string s in his garage. The string is so old that some of its characters have faded and are unidentifiable now. Faded characters in the string are represented by '.' whereas other characters are lower case Latin alphabets i.e ['a'-'z']. Chef being the palindrome lover decided to construct the lexicographically smallest palindrome by filling each of the faded character ('.') with a lower case Latin alphabet. Can you please help him completing the task? -----Input----- First line of input contains a single integer T denoting the number of test cases. T test cases follow. First and the only line of each case contains string s denoting the old string that chef has found in his garage. -----Output----- For each test case, print lexicographically smallest palindrome after filling each faded character - if it possible to construct one. Print -1 otherwise. -----Constraints----- - 1 ≤ T ≤ 50 - 1 ≤ |s| ≤ 12345 - String s consists of ['a'-'z'] and '.' only. -----Subtasks-----Subtask #1 (47 points) - 1 ≤ T ≤ 50, 1 ≤ |S| ≤ 123 Subtask #2 (53 points) - 1 ≤ T ≤ 50, 1 ≤ |S| ≤ 12345 -----Example-----Input 3 a.ba cb.bc a.b Output abba cbabc -1 -----Explanation----- In example 1, you can create a palindrome by filling the faded character by 'b'. In example 2, you can replace the faded character by any character from 'a' to 'z'. We fill it by 'a', as it will generate the lexicographically smallest palindrome. In example 3, it is not possible to make the string s a palindrome.
["test=int(input())\nfor i in range(test):\n s=input()\n b=len(s)\n list1=[]\n for j in range(len(s)):\n if s[j]=='.':\n list1.append(j)\n for i in list1:\n if b-i-1 in list1 :\n if i!=b-i-1 and ((s[i] and s[b-i-1]) != 'a' ):\n s=s[:i]+'a'+s[i+1:b-i-1]+'a'+s[b-i:]\n else:\n s=s[:i]+'a'+s[i+1:]\n else:\n s=s[:i]+s[b-i-1]+s[i+1:]\n\n if s==s[::-1]:\n print(s)\n else:\n print(-1)\n\n ", "for _ in range(int(input())):\n\ts=list(input())\n\tn=len(s)\n\tf=0\n\tfor i in range(n//2):\n\t\tif s[i]=='.' and s[n-i-1]=='.':\n\t\t\ts[i]='a'\n\t\t\ts[n-i-1]='a'\n\t\telif s[i]=='.':\n\t\t\ts[i]=s[n-i-1]\n\t\telif s[n-i-1]=='.':\n\t\t\ts[n-i-1]=s[i]\n\t\telse:\n\t\t\tif s[i]!=s[n-i-1]:\n\t\t\t\tf=1\n\t\t\t\tbreak\n\t\t\telse:\n\t\t\t\tcontinue\n\tif f:\n\t\tprint('-1')\n\telse:\n\t\tif n%2:\n\t\t\tif s[n//2]=='.':\n\t\t\t\ts[n//2]='a'\n\t\tprint(''.join(s))\n", "import sys\nimport math\ndef main(arr):\n n=len(arr)-1 \n for i in range(len(arr)//2):\n a=arr[i]\n b=arr[n-i]\n if a!=b and a!=\".\" and b!=\".\":\n return \"-1\"\n if a==\".\" and b==\".\":\n arr[i]=\"a\"\n arr[n-i]=\"a\"\n else:\n if a!=\".\":\n arr[n-i]=a \n elif b!=\".\":\n arr[i]=b\n if arr[len(arr)//2]==\".\":\n arr[len(arr)//2]=\"a\"\n return \"\".join(arr)\n \ntest=int(input())\nfor _ in range(test):\n arr=list(input())\n print(main(arr))\n \n", "import sys\nimport math\ndef main(arr):\n n=len(arr)-1 \n for i in range(len(arr)//2):\n a=arr[i]\n b=arr[n-i]\n if a!=b and a!=\".\" and b!=\".\":\n return \"-1\"\n if a==\".\" and b==\".\":\n arr[i]=\"a\"\n arr[n-i]=\"a\"\n else:\n if a!=\".\":\n arr[n-i]=a \n elif b!=\".\":\n arr[i]=b\n if arr[len(arr)//2]==\".\":\n arr[len(arr)//2]=\"a\"\n return \"\".join(arr)\n \ntest=int(input())\nfor _ in range(test):\n arr=list(input())\n print(main(arr))\n ", "import sys\nimport math\n\ndef main(arr):\n\n\n n=len(arr)-1 \n \n for i in range(len(arr)//2):\n \n a=arr[i]\n b=arr[n-i]\n if a!=b and a!=\".\" and b!=\".\":\n return \"-1\"\n if a==\".\" and b==\".\":\n \n arr[i]=\"a\"\n arr[n-i]=\"a\"\n \n else:\n \n if a!=\".\":\n arr[n-i]=a \n elif b!=\".\":\n arr[i]=b\n \n if arr[len(arr)//2]==\".\":\n arr[len(arr)//2]=\"a\"\n return \"\".join(arr)\n\nfor _ in range(int(input())):\n arr=list(input())\n print(main(arr))\n ", "# cook your dish here\nfor i in range(int(input())):\n S=input()\n s=list(S)\n N=len(s)\n flag=True\n for i in range(N):\n if s[i]!=s[N-1-i] and s[i]!=\".\" and s[N-1-i]!=\".\":\n flag=False\n print(-1)\n break\n elif s[i]==\".\" and s[N-1-i]==\".\":\n s[i]=s[N-1-i]=\"a\"\n elif s[i]==\".\" and s[N-1-i]!=\".\":\n s[i]=s[N-1-i]\n \n \n \n if flag:\n p=\"\"\n for i in s:\n p+=i\n print(p)", "for u in range(int(input())):\n s=list(input())\n f=0\n n=len(s)\n i,j=0,n-1\n while(i<=j):\n if(s[i]=='.' and s[j]=='.'):\n s[i],s[j]='a','a'\n i+=1\n j-=1\n elif(s[i]=='.' or s[j]=='.'):\n if(s[i]=='.' and s[j]!='.'):\n s[i]=s[j]\n else:\n s[j]=s[i]\n i+=1\n j-=1\n elif(s[i]!='.' and s[j]!='.'):\n if(s[i]==s[j]):\n i+=1\n j-=1\n else:\n f=1\n break\n if(f==1):\n print(-1)\n else:\n print(''.join(s))\n", "for t in range(int(input())):\n ss=input()\n result=None\n k=\"\"\n s=list(ss)\n x=len(ss)-1\n if len(ss)==1:\n if ss=='.':\n ss='a'\n \n else:\n for i in range((len(s)//2)+1):\n if s[i]==s[x]:\n if s[i]=='.':\n s[i]='a'\n s[x]='a'\n elif s[i]=='.':\n z=s[x]\n s[i]=z\n elif s[x]=='.':\n y=s[i]\n s[x]=y\n else:\n result=-1\n break\n x=x-1\n if result==None:\n print(k.join(s))\n else:\n print(result)", "# cook your dish here\nt = int(input())\n\nwhile t > 0:\n t -= 1\n s = list(input())\n res = True\n l = 0\n r = len(s)-1\n while l <= r:\n if s[l].isalpha() and s[r].isalpha():\n if s[l] != s[r]:\n res = False\n break\n elif s[l] == '.' and s[r] == '.':\n s[l] = 'a'\n s[r] = 'a'\n elif s[l] == '.':\n s[l] = s[r]\n else:\n s[r] = s[l]\n l += 1\n r -= 1\n if res:\n print(\"\".join(s))\n else:\n print(-1)\n\n", "t=int(input())\nfor h in range(t):\n\ts=list(input())\n\tn=len(s)\n\tf=0\n\tfor i in range(n):\n\t\tif s[i]!='.' and s[i]!=s[n-i-1] and s[n-i-1]!='.':\n\t\t\tf=1\n\t\t\tprint(-1)\n\t\t\tbreak\n\t\telif s[i]=='.' and s[n-i-1]=='.':\n\t\t\ts[i]=s[n-i-1]='a'\n\t\telif s[i]=='.' and s[n-i-1]!='.':\n\t\t\ts[i]=s[n-i-1]\n\tif f==0:\n\t r=''\n\t for i in s:\n\t r=r+i\n\t print(r)", "for _ in range(int(input())):\n\tS=list(input())\n\tN=len(S)\n\tc=True\n\tfor i in range(N):\n\t\tif S[i]!='.' and S[i]!=S[N-i-1] and S[N-i-1]!='.':\n\t\t\tc=False\n\t\t\tprint('-1')\n\t\t\tbreak\n\t\telif S[i]=='.' and S[N-i-1]=='.':\n\t\t\tS[i]=S[N-i-1]='a'\n\t\telif S[i]=='.' and S[N-i-1]!='.':\n\t\t\tS[i]=S[N-i-1]\n\tif c:\n\t p=''\n\t for i in S:\n\t p+=i\n\t print(p)", "# cook your dish here\nfor _ in range(int(input())):\n s = list(input())\n n = len(s)\n for i in range(n//2 + n%2):\n if s[i] == '.':\n if s[n-i-1] == '.': s[i], s[n-i-1] = 'a', 'a'\n else: s[i] = s[n-i-1]\n else:\n if s[n-i-1] == '.': s[n-i-1] = s[i]\n elif s[i] != s[n-i-1]:\n print(-1)\n break\n else:\n print(''.join(s))", "for _ in range(int(input())):\r\n\tS=list(input())\r\n\tN=len(S)\r\n\tc=True\r\n\tfor i in range(N):\r\n\t\tif S[i]!='.' and S[i]!=S[N-i-1] and S[N-i-1]!='.':\r\n\t\t\tc=False\r\n\t\t\tprint('-1')\r\n\t\t\tbreak\r\n\t\telif S[i]=='.' and S[N-i-1]=='.':\r\n\t\t\tS[i]=S[N-i-1]='a'\r\n\t\telif S[i]=='.' and S[N-i-1]!='.':\r\n\t\t\tS[i]=S[N-i-1]\r\n\tif c:\r\n\t p=''\r\n\t for i in S:\r\n\t p+=i\r\n\t print(p)", "for j in range(int(input())):\r\n a=input()\r\n x=list(a)\r\n n=len(x)\r\n am=0\r\n if(n%2==0):\r\n for i in range(n):\r\n if(x[i]==\".\" or x[n-i-1]==\".\"):\r\n if(x[i]==\".\" and x[n-i-1]!=\".\"):\r\n x[i]=x[n-i-1]\r\n elif(x[n-i-1]==\".\" and x[i]!=\".\"):\r\n x[n-i-1]=x[i]\r\n else:\r\n x[i]=\"a\"\r\n x[n-i-1]=\"a\"\r\n elif(x[i]!=x[n-i-1]):\r\n am=1\r\n break\r\n else:\r\n b=n//2\r\n for i in range(n):\r\n if(b==i):\r\n if(x[i]==\".\"):\r\n x[i]=\"a\"\r\n else:\r\n continue\r\n elif(x[i] == \".\" or x[n - i - 1] == \".\"):\r\n if (x[i] == \".\" and x[n - i - 1] != \".\"):\r\n x[i] = x[n - i - 1]\r\n elif (x[n - i - 1] == \".\" and x[i] != \".\"):\r\n x[n - i - 1] = x[i]\r\n else:\r\n x[i] = \"a\"\r\n x[n - i - 1] = \"a\"\r\n elif(x[i]!=x[n-i-1]):\r\n am=1\r\n break\r\n if(am==0):\r\n print(\"\".join(x))\r\n else:\r\n print(-1)", "for _ in range(int(input())):\r\n s = list(input())\r\n start = 0\r\n end = len(s) - 1\r\n flag = True\r\n while start < end:\r\n if s[start] == '.' and s[end] != '.':\r\n s[start] = s[end]\r\n elif s[start] != '.' and s[end] == '.':\r\n s[end] = s[start]\r\n elif s[start] == '.' and s[end] == '.':\r\n s[start] = 'a'\r\n s[end] = 'a'\r\n elif s[start] == s[end]:\r\n start += 1\r\n end -= 1\r\n else:\r\n flag = False\r\n break\r\n\r\n if flag:\r\n if s[start] == '.':\r\n s[start] = 'a'\r\n print(''.join(x for x in s))\r\n else:\r\n print(-1)\r\n", "# cook your dish here\nt=int(input())\nfor i in range(t):\n s=list(input())\n \n for j in range(len(s)):\n \n if(s[j]=='.'):\n if(s[len(s)-j-1]=='.'):\n s[j]=s[len(s)-j-1]='a'\n else:\n s[j]=s[len(s)-j-1]\n elif(s[len(s)-j-1]=='.'):\n if(s[j]=='.'):\n s[j]=s[len(s)-j-1]='a'\n else:\n s[len(s)-j-1]=s[j]\n \n \n \n \n if(len(s)%2!=0):\n if(j==((len(s)//2))):\n \n if(s[j]=='.'):\n s[j]=\"a\"\n c=\"\"\n m=\"\"\n flag=1\n c=list(c.join(s))\n for k in range(len(c)//2):\n if(c[k]==c[len(c)-k-1]):\n flag=0\n \n \n else:\n flag=1\n break\n if(flag==0):\n print(m.join(c))\n else:\n print(-1)\n \n ", "for _ in range(int(input())):\r\n str = list(input())\r\n l = len(str)\r\n flag = False\r\n for i in range(l//2):\r\n if str[i] == '.':\r\n if str[-i-1] == '.':\r\n str[i] = str[-i-1] = 'a'\r\n else:\r\n str[i] = str[-i-1]\r\n elif str[-i-1] == '.':\r\n str[-i-1] = str[i]\r\n elif str[i] != str[-i-1]:\r\n print(\"-1\")\r\n flag = True\r\n break\r\n if flag:\r\n continue\r\n if l%2 != 0 and str[l//2] == '.':\r\n str[l//2] = 'a'\r\n print(\"\".join(str))\r\n", "for _ in range(int(input())):\r\n\ts = input()\r\n\ta, h, t = list(s), 0, len(s)-1\r\n\tflag = 0\r\n\twhile h <= t:\r\n\t\tif a[h] != a[t] and (a[h] != \".\" and a[t] != '.'):\r\n\t\t\tflag = 1\r\n\t\t\tbreak\r\n\t\telif a[h] == a[t] and a[h] == '.':\r\n\t\t\ta[h] = 'a'\r\n\t\t\ta[t] = a[h]\r\n\t\telif a[h] != a[t]:\r\n\t\t\tif a[h] == '.':\r\n\t\t\t\ta[h] = a[t]\r\n\t\t\telif a[t] == '.':\r\n\t\t\t\ta[t] = a[h]\r\n\t\th += 1\r\n\t\tt -= 1\r\n\ty = ''.join(a)\r\n\tif flag == 0:\r\n\t\tprint(y)\r\n\telse:\r\n\t\tprint(-1)", "t = int(input())\nfor q in range(t):\n s = input()\n ns = ''\n \n f = 0\n if len(s)%2 == 0:\n k = len(s) // 2\n else:\n k = (len(s)//2)+1\n \n for i in range(k):\n \n if s[i] != s[len(s)-1-i] and s[i] != '.' and s[len(s)-1-i] != '.':\n f = 1\n break\n elif s[i] == '.':\n if s[i] == s[len(s)-1-i]:\n ns += 'a'\n else:\n ns += s[len(s)-1-i]\n elif s[len(s)-1-i] == '.':\n if s[i] == s[len(s)-1-i]:\n ns += 'a'\n else:\n ns += s[i]\n else:\n ns += s[i]\n \n \n if f == 1:\n print(-1)\n elif len(s)%2 == 0:\n print(ns + ns[::-1])\n else:\n print(ns + ns[::-1][1:])", "'''input\r\n3\r\na.ba\r\nc...c\r\n...\r\n'''\r\nfrom collections import defaultdict as dd\r\nfrom collections import Counter as ccd\r\nfrom itertools import permutations as pp\r\nfrom itertools import combinations as cc\r\nfrom random import randint as rd\r\nfrom bisect import bisect_left as bl\r\nfrom bisect import bisect_right as br\r\nimport heapq as hq\r\nfrom math import gcd\r\n'''\r\nAuthor : dhanyaabhirami\r\nHardwork beats talent if talent doesn't work hard\r\n'''\r\n'''\r\nStuck?\r\nSee github resources\r\nDerive Formula\r\nKmcode blog\r\nCP Algorithms Emaxx\r\n'''\r\nmod=pow(10,9) +7\r\ndef inp(flag=0):\r\n if flag==0:\r\n return list(map(int,input().strip().split(' ')))\r\n else:\r\n return int(input())\r\n\r\n# Code credits\r\n# assert(debug()==true)\r\n# for _ in range(int(input())):\r\n\r\nt=inp(1)\r\nwhile t:\r\n t-=1\r\n \r\n s=input().strip()\r\n n=len(s)\r\n s=list(s)\r\n if n%2==1 and s[n//2]=='.':\r\n \ts[n//2]='a'\r\n for i in range(n//2):\r\n \tif s[i]==s[n-i-1]:\r\n \t\tif s[i]=='.':\r\n \t\t\ts[i]='a'\r\n \t\t\ts[n-i-1]='a'\r\n \t\telse:\r\n \t\t\tcontinue\r\n \telif s[i]=='.':\r\n \t\ts[i]=s[n-i-1]\r\n \telif s[n-i-1]=='.':\r\n \t\ts[n-i-1]=s[i]\r\n \telse:\r\n \t\ts = -1\r\n \t\tbreak\r\n if s!=-1:\r\n \ts=\"\".join(s)\r\n print(s)", "# cook your dish here\nt = int(input())\nfor q in range(t):\n s = input()\n ns = ''\n \n f = 0\n if len(s)%2 == 0:\n k = len(s) // 2\n else:\n k = (len(s)//2)+1\n \n for i in range(k):\n \n if s[i] != s[len(s)-1-i] and s[i] != '.' and s[len(s)-1-i] != '.':\n f = 1\n break\n elif s[i] == '.':\n if s[i] == s[len(s)-1-i]:\n ns += 'a'\n else:\n ns += s[len(s)-1-i]\n elif s[len(s)-1-i] == '.':\n if s[i] == s[len(s)-1-i]:\n ns += 'a'\n else:\n ns += s[i]\n else:\n ns += s[i]\n \n \n if f == 1:\n print(-1)\n elif len(s)%2 == 0:\n print(ns + ns[::-1])\n else:\n print(ns + ns[::-1][1:])\n", "N = int(input())\r\n\r\nfor i in range(N):\r\n string = list(input())\r\n count = 0\r\n broken = False\r\n while count <= len(string) // 2:\r\n if string[count] == \".\" and string[-count - 1] == \".\":\r\n string[-count - 1] = string[count] = \"a\"\r\n\r\n elif string[count] == \".\":\r\n string[count] = string[-count - 1]\r\n\r\n elif string[-count - 1] == \".\":\r\n string[-count - 1] = string[count]\r\n\r\n elif string[count] != string[-count - 1]:\r\n print(-1)\r\n broken = True\r\n break\r\n\r\n count += 1\r\n\r\n if not broken:\r\n print(''.join(string))\r\n", "for _ in range(int(input())):\r\n\ts = input()\r\n\ta, h, t = list(s), 0, len(s)-1\r\n\tflag = 0\r\n\twhile h <= t:\r\n\t\tif a[h] != a[t] and (a[h] != '.' and a[t] != '.'):\r\n\t\t\tflag = 1\r\n\t\t\tbreak\r\n\t\telif a[h] == a[t] and a[h] == '.':\r\n\t\t\ta[h] = 'a'\r\n\t\t\ta[t] = a[h]\r\n\t\telif a[h] != a[t]:\r\n\t\t\tif a[h] == '.':\r\n\t\t\t\ta[h] = a[t]\r\n\t\t\telif a[t] == '.':\r\n\t\t\t\ta[t] = a[h]\r\n\t\th += 1\r\n\t\tt -= 1\r\n\ts = ''.join(a)\r\n\tif flag == 0:\r\n\t\tprint(s)\r\n\telse:\r\n\t\tprint(-1)", "# cook your dish here\n\nt = int(input())\nwhile(t!=0):\n word = input()\n split_word = list(word)\n flag = 0\n x = 0\n y = -1\n while(x<len(split_word)):\n if split_word[x]!='.' and split_word[y]!='.':\n if split_word[x]!=split_word[y]:\n flag =1\n break\n elif(split_word[x] == split_word[y] and split_word[x] == '.' and split_word[y] == '.'):\n split_word[x] = 'a'\n split_word[y] = 'a' \n elif(split_word[x] == '.'): \n split_word[x] = split_word[y]\n elif(split_word[y] == '.'): \n split_word[y] = split_word[x]\n x += 1\n y -= 1\n \n if(flag == 1):\n print(-1)\n else:\n print(''.join(split_word))\n t = t-1\n \n\n", "#!/usr/bin/env python3\n# -*- coding: utf-8 -*-\n\"\"\"\nCreated on Tue Nov 5 17:14:44 2019\n\n@author: hkumar50\n\"\"\"\n\n#!/usr/bin/env python3\n# -*- coding: utf-8 -*-\n\"\"\"\nCreated on Tue Nov 5 15:53:29 2019\n\n@author: hkumar50\n\"\"\"\n\ndef calres(x):\n l=len(x)\n x=list(x)\n flag=0\n #midcheck=0\n #nonmidVal=''\n \n if(l%2!=0):\n totItr=l//2+1\n else:\n totItr=l//2\n for i in range(0, totItr):\n \n if( (x[i]=='.') or (x[(l-1)-i] =='.') ):\n if( (len(x)%2!=0) and (i==len(x)//2) == (l-1-i) ):\n x[i]='a'\n #x[l-1-i]='a'\n elif( (x[i]=='.') and (x[l-1-i] != '.') ):\n x[i]=x[l-1-i]\n #midcheck=2\n elif( (x[i]!='.') and (x[l-1-i] == '.') ):\n x[l-1-i]=x[i]\n #midcheck=2\n elif((x[i]=='.') and (x[l-1-i] == '.')):\n x[i]='a'\n x[l-1-i]='a'\n \n \n elif( (x[i] == x[(l-1)-i]) ):\n flag=1\n else:\n flag=-1\n break\n \n \n if(flag==-1):\n print('-1')\n\n else:\n print( (''.join(x) ) )\n \n \nt=int( input() )\n\nfor i in range(t):\n val=str(input())\n calres(val)\n \n\n\n\n \n \n \n \n "]
{"inputs": [["3", "a.ba", "cb.bc", "a.b"]], "outputs": [["abba", "cbabc", "-1"]]}
INTERVIEW
PYTHON3
CODECHEF
17,590
2d6a1f619ade0ca5ea49c7f8d90aa993
UNKNOWN
Chef is planning a huge party for all of you and has ordered M pizzas. He wants to invite as many people to the party. However, he knows that everyone will have exactly one slice of a pizza (regardless of the size) and he wants to make sure that he has enough pizza slices. Chef is very lazy and will only make a total of N straight cuts among all the pizzas. Each pizza is also of different size and to avoid the slices getting too small the chef can only make a max of Ai cuts to the ith pizza. He wants to maximize the number of slices of pizza. Since chef is busy with preparing other aspects of the party he wants you to find out the maximum number of slices he can get following the constraints. If a pizza is not cut at all then it is considered as 1 slice. -----Input----- First line contains two integers M and N. The second line of input contains the array A. -----Output----- Output a single integer - the maximum number of slices chef can get. -----Constraints----- - 1 ≤ M ≤ 2*105 - 1 ≤ N,Ai ≤ 2*105 -----Subtasks----- - Subtask 1: 1 ≤ M,N ≤ 100 - 10 points - Subtask 2: 1 ≤ N ≤ 100, 1 ≤ M ≤ 105 - 20 points - Subtask 3: Original Constraints - 70 points -----Example----- Input: 5 10 1 2 3 4 5 Output: 31 -----Explanation----- Example case 1. One of the optimal way to cut would be to do {0, 1, 0, 4, 5} cuts.
["# cook your dish here\r\nm,n=[int(i) for i in input().split()]\r\narr=list(map(int,input().split()))\r\narr=sorted(arr,reverse=True)\r\nans=0\r\nw=0\r\nq=m\r\nfor m in range(q):\r\n if(arr[m]>n):\r\n w=1\r\n break \r\n ans+=1+(arr[m]*(arr[m]+1))//2\r\n n-=arr[m]\r\n\r\nif(n==0):\r\n print(ans)\r\nelse:\r\n if(w==1):\r\n print(ans+q-m+(n*(n+1))//2)\r\n else:\r\n print(ans)", "# cook your dish here\nm,n=[int(i) for i in input().split()]\narr=list(map(int,input().split()))\narr=sorted(arr,reverse=True)\nans=0\nw=0\nq=m\nfor m in range(q):\n if(arr[m]>n):\n w=1\n break \n ans+=1+(arr[m]*(arr[m]+1))//2\n n-=arr[m]\n\nif(n==0):\n print(ans)\nelse:\n if(w==1):\n print(ans+q-m+(n*(n+1))//2)\n else:\n print(ans)", "m,n=map(int,input().split());arr=sorted(list(map(int,input().split())),reverse=True);ans,w,q = 0,0,m\nfor m in range(q):\n if(arr[m]>n):w=1;break \n ans+=1+(arr[m]*(arr[m]+1))//2;n-=arr[m]\nprint(ans) if(n==0) else print(ans+q-m+(n*(n+1))//2) if(w==1) else print(ans)", "# cook your dish here\nm,n=[int(i) for i in input().split()]\narr=list(map(int,input().split()))\narr=sorted(arr,reverse=True)\nans=0\nw=0\nq=m\nfor m in range(q):\n if(arr[m]>n):\n w=1\n break \n ans+=1+(arr[m]*(arr[m]+1))//2\n n-=arr[m]\n\nif(n==0):\n print(ans)\nelse:\n if(w==1):\n print(ans+q-m+(n*(n+1))//2)\n else:\n print(ans)\n", "\r\nmax_ = int(2e5)\r\ndef make_arr(dp):\r\n dp[1] = 2\r\n for i in range(2,max_):\r\n dp[i] = dp[i-1] +i\r\n \r\ndp = [0]*(max_ +1)\r\nmake_arr(dp)\r\nM,N = [int(i) for i in input().split()]\r\nA = [int(i) for i in input().split()]\r\nA.sort(reverse = True)\r\nans = 0\r\nflag = 0\r\nfor i in A:\r\n if(flag == 0):\r\n if(N >= i):\r\n ans = ans + dp[i]\r\n N = N- i\r\n elif(N < i):\r\n ans = ans + dp[N]\r\n flag = 1\r\n else:\r\n ans = ans +1\r\n \r\nprint(ans)\r\n", "n,m=map(int,input().split())\nslices=[int(x) for x in input().split()]\nslices.sort()\narray=[0]*(slices[-1]+1)\narray[0]=1\nfor i in range(1,len(array)):\n array[i]=array[i-1]+i\ntotal=0\nslices=slices[::-1]\nvalue=0\nfor i in range(len(slices)):\n if slices[i]<=m:\n total+=array[slices[i]]\n m-=slices[i]\n continue\n if m<slices[i]:\n total+=array[m]\n m=0\n value=len(slices)-i-1\n break\ntotal+=value\nprint(total)\n \n"]
{"inputs": [["5 10", "1 2 3 4 5", ""]], "outputs": [["31"]]}
INTERVIEW
PYTHON3
CODECHEF
2,526
4eaa99e36453bf3bb850ccedf67e856a
UNKNOWN
Write a program to check whether a triangle is valid or not, when the three angles of the triangle are the inputs. A triangle is valid if the sum of all the three angles is equal to 180 degrees. -----Input----- The first line contains an integer T, the total number of testcases. Then T lines follow, each line contains three angles A, B and C, of the triangle separated by space. -----Output----- For each test case, display 'YES' if the triangle is valid, and 'NO', if it is not, in a new line. -----Constraints----- - 1 ≤ T ≤ 1000 - 1 ≤ A,B,C ≤ 180 -----Example----- Input 3 40 40 100 45 45 90 180 1 1 Output YES YES NO
["n=int(input())\nfor i in range(n):\n a,b,c=map(int,input().split())\n if a>0 and b>0 and c>0 and a+b+c==180:\n print(\"YES\")\n else:\n print(\"NO\")", "for _ in range (int(input())):\n a,b,c = map(int,input().split())\n if a+b+c==180:\n print(\"YES\")\n else:\n print(\"NO\")", "# cook your dish here\nt= int(input())\nfor i in range(t):\n a,b,c = map(int,input().split())\n if(a+b+c==180):\n print(\"YES\")\n else:\n print(\"NO\")", "# cook your dish here\nn = int(input())\nwhile n>0:\n a = list(map(int,input().strip().split()))\n if sum(a)==180:\n print(\"YES\")\n else:\n print(\"NO\")\n n = n-1", "t=int(input())\r\nfor x in range(t):\r\n a,b,c=map(int, input().split())\r\n if a+b+c==180:\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")", "# cook your dish here\nn = int(input())\nwhile n>0:\n a = list(map(int,input().strip().split()))\n if sum(a)==180:\n print(\"YES\")\n else:\n print(\"NO\")\n n = n-1", "for _ in range (int(input())):\n a,b,c = map(int,input().split())\n if a+b+c==180:\n print(\"YES\")\n else:\n print(\"NO\")", "# cook your dish here\nt=int(input())\nfor i in range(0,t):\n a,b,c=map(int,input().split())\n if (a+b+c)==180:\n print(\"YES\")\n else:\n print(\"NO\")", "for _ in range(int(input())):\n (a,b,c)=map(int,input().split())\n if (a+b+c)==180:\n print(\"YES\")\n else:\n print(\"NO\")", "# cook your dish here\ntry:\n t=int(input())\n for i in range(0,t):\n a,b,c=map(int,input().split())\n if(a+b+c==180):\n print(\"YES\")\n else:\n print(\"NO\")\nexcept:\n pass", "for _ in range(int(input())):\n\n x,y,z=list(map(int,input().split()))\n sum=x+y+z\n if sum==180:\n print('YES')\n else:\n print('NO')\n", "# cook your dish here\nfor _ in range(int(input())):\n l=list(map(int,input().split(' ')))\n if(sum(l)==180):\n print('YES')\n else:\n print('NO')", "N=int(input())\nfor i in range(N):\n a,b,c=list(map(int,input().split()))\n if(a+b+c==180):\n print('YES')\n else:\n print('NO')\n", "# cook your dish here\nx=int(input())\nfor i in range(x):\n (a,b,c) = list(map(int, input().split(' ')))\n if((a+b+c)==180):\n print(\"YES\")\n else:\n print(\"NO\")\n", "def valid(a,b,c):\n if (a+b+c) == 180:\n print(\"YES\")\n else:\n print(\"NO\")\n\nt=int(input())\nwhile t:\n t = t - 1\n a,b,c = list(map(int, input().split()))\n valid(a,b,c)\n", "# cook your dish here\nT=int(input())\nfor i in range(T):\n a,b,c=list(map(int,input().split()))\n #p=int(input())\n if a+b+c==180:\n print(\"YES\")\n else:\n print(\"NO\")\n", "# cook your dish here\nfor _ in range(int(input())):\n z = list(map(int, input().split()))\n if sum(z) == 180:\n print(\"YES\")\n else:\n print(\"NO\")", "# cook your dish here\nt=int(input())\nwhile t!=0:\n x,y,z=[int(k) for k in input().split()]\n if x+y+z==180:\n print(\"YES\")\n else:\n print(\"NO\")\n t-=1", "for t in range(int(input())):\n l=[int(i) for i in input().split()]\n if sum(l)==180:print(\"YES\")\n else:print(\"NO\")", "# cook your dish here\nn=int(input())\nfor i in range(n):\n l=[int(i) for i in input().split()]\n if sum(l)==180:print(\"YES\")\n else:print(\"NO\")", "# cook your dish here\nfor i in range(int(input())):\n b, t, s = map(int, input().split())\n if b+t+s == 180:\n print(\"YES\")\n else:\n print(\"NO\")", "# cook your dish here\nfor i in range(int(input())):\n a, b, c = map(int, input().split())\n if a+b+c == 180:\n print(\"YES\")\n else:\n print(\"NO\")", "# cook your dish here\ntest_case = int(input())\n\nwhile test_case > 0:\n angle = [int(x) for x in input().split(' ')]\n if sum(angle) == 180:\n print(\"YES\")\n else:\n print(\"NO\")\n test_case -= 1", "# cook your dish here\nT = int(input())\n\nfor i in range(T):\n A,B,C = map(int, input().split())\n if A+B+C == 180:\n print(\"YES\")\n else:\n print(\"NO\")", "t=int(input())\r\ni=0\r\nwhile i<t:\r\n\ta,b,c=input().split()\r\n\ta=int(a)\r\n\tb=int(b)\r\n\tc=int(c)\r\n\tif a+b+c==180:\r\n\t\tprint(\"YES\")\r\n\telse:\r\n\t\tprint(\"NO\")\r\n\ti+=1"]
{"inputs": [["3 ", "40 40 100", "45 45 90", "180 1 1", ""]], "outputs": [["YES", "YES", "NO"]]}
INTERVIEW
PYTHON3
CODECHEF
4,497
4543c55fca49941a987b45c15c6379eb
UNKNOWN
Alice is a very brilliant student. He considers '4' and '7' as Magic numbers. The numbers containing only magic numbers are also magical. Given a magic number N ,he wants to know what could be the next magical number greater than the given number. -----Input----- First line of input contains number of test cases T. For each test case, there is exits only one line containing a magic number N. -----Output----- For each test case, output a single line containing the next greater magical number. -----Constraints----- 1<=T<=1000 4<= N<=10^100 -----Example----- Input: 2 4 47 Output: 7 74
["import math\n\ndef magic(a,digits):\n m=a%10\n if(m==4):\n return a+3\n elif(m==7):\n p=list(str(a))\n #print p\n for i in range(digits-1,-1,-1):\n #print p[i]\n if (p[i]=='4'):\n #print 'four'\n p[i]='7'\n p = ''.join(str(n) for n in p)\n return int(p)\n if ((p[i]=='7')&(i==0)):\n #print 'seven'\n p[i]='4'\n p.insert(0,4)\n p = ''.join(str(n) for n in p)\n return int(p)\n\n if(p[i]=='7'):\n #print 'seven only'\n p[i]='4'\n \n #print p[i]\n \n \n \n\nt=eval(input())\n\nn=[]\nop=[]\n\nfor i in range(0,t):\n n.append(eval(input()))\n\nfor i in range(0,t):\n digits = int(math.log10(n[i]))+1\n #print digits\n op.append(magic(n[i],digits))\n \n#for i in range(0,t):\n #print n[i]\n\nfor i in range(0,t):\n print(op[i])\n\n\n\n \n", "k=int(input())\nfor char in range(k):\n num=int(input())\n if '4' not in (str(num)):\n x=len(str(num))+1\n print('4'*x)\n elif num%2==0:\n print(num+3)\n else:\n num=str(num)\n for i in range(len(num)-1,-1,-1):\n if num[i]=='4':\n index=i\n break\n q=int(index)\n l=num[0:q]\n what=len(num)-(index+1)\n print(l+'7'+'4'*what)\n \n\n", "t=int(input())\nfor i in range(t):\n number=int(input())\n if '4' not in (str(number)):\n x=len(str(number))+1\n print('4'*x)\n elif number%2==0:\n print(number+3)\n else:\n number=str(number)\n for i in range(len(number)-1,-1,-1):\n if number[i]=='4':\n index=i\n break\n q=int(index)\n u=number[0:q]\n lennew=len(number)-(index+1)\n print(u+'7'+'4'*lennew)\n \n\n", "def checkmagic(n):\n\tfor i in range(0, len(n)):\n\t\tif n[i] != '4' and n[i] != '7':\n\t\t\treturn False\n\treturn True\n\ndef nextmag(n):\n\tn = str(n)\n\tn = list(n)\n\tn = n[::-1]\n\tn[0] = str(int(n[0])+1)\n\ts = []\n\tfor i in range(0, len(n)):\n\t\ts.append('7')\n\tif int(''.join(n[::-1])) > int(''.join(s)):\n\t\tn.append('0')\n\t\n\ti=0\n\twhile (checkmagic(n) == False) and (i < len(n)):\n\t\tif int(n[i]) < 4:\n\t\t\tn[i] = '4'\n\t\telif int(n[i]) < 7:\n\t\t\tn[i] = '7'\n\t\telse:\n\t\t\tn[i] = '4'\n\t\t\tn[i+1] = str(int(n[i+1])+1)\n\t\ti += 1\n\t\n\treturn (''.join(n[::-1]))\n\nT = int(input())\na = []\n\nfor i in range(0, T):\n\tk = int(input())\n\ta.append(nextmag(k))\n\nfor e in a:\n\tprint(e)", "#!/usr/bin/env python\n\ndef process(N):\n if not '4' in N:\n return '4' * (len(N) + 1)\n i = N.rindex('4')\n return N[:i] + '7' + '4' * len(N[i+1:])\n\ndef main():\n T = int(input().strip())\n for t in range(T):\n N = input().strip()\n print(process(N))\n\nmain()\n\n"]
{"inputs": [["2", "4", "47", "", ""]], "outputs": [["7", "74"]]}
INTERVIEW
PYTHON3
CODECHEF
3,021
a56dccfc7e7d7e5748d3d177a30dae2e
UNKNOWN
There is a popular apps named “Exbook” like “Facebook”. To sign up in this app , You have to make a strong password with more than 3 digits and less than 10 digits . But I am a pro hacker and so I make a Exbook hacking site . You need to login in this site to hack exbook account and then you will get a portal. You can give any user exbook login link using this site and when anyone login into exbook using your link ,you can see his/her password . But I made a mistake and so you cannot find original password in your portal . The portal showing you by adding two in every digit . So , now you have to find out the original password of an user if I give you the password which is showing in your portal . -----Input:----- The first line contains a single integer t (1 ≤ t ≤ 1000) — the number of test cases. The first line of each test case contains a single integer n which is showing in your portal . Mind it , every digit of n is greater than one . -----Output:----- Print , original password of user . -----Sample Input:----- 2 3527 47269 -----Sample Output:----- 1305 25047
["# cook your dish here\nt=int(input())\nfor i in range(0,t):\n p=input()\n l=list(p)\n for j in range(0,len(l)):\n l[j]=int(l[j])\n l[j]=l[j]-2\n for j in range(0,len(l)):\n l[j]=str(l[j])\n q=''.join(l)\n print(q)", "t=int(input())\nfor i in range(t):\n n=input()\n l=len(n)\n list1=list(n)\n str1=\"\"\n for j in range(l):\n str1+=str(int(list1[j])-2)\n print(str1)", "# cook your dish here\nfor _ in range(int(input())):\n n = input()\n for i in n:\n print((int(i)-2),end=\"\")\n print()\n ", "for _ in range(int(input())):\n s = list(str(input()))\n for i in range(len(s)):s[i] = int(s[i])-2\n print(''.join([str(i) for i in s]))", "try:\n for i in range(int(input())):\n a=int(input())\n b=str(a)\n c=list(b)\n for i in range(len(c)):\n c[i]=int(c[i])\n ab=[]\n for i in c:\n i=i-2\n ab.append(i)\n for i in ab:\n print(i,end='')\n print('')\nexcept:\n pass", "# cook your dish here\nfor t in range(int(input())):\n n = input()\n num = \"\"\n for c in n:\n num+=str(int(c)-2)\n \n print(num)\n", "# cook your dish here\nfor _ in range(int(input())):\n n = input()\n res=\"\"\n for i in n:\n res += str(int(i)-2)\n print(res)", "# cook your dish here\nfor t in range(int(input())):\n n = input()\n num = \"\"\n for c in n:\n num+=str(int(c)-2)\n \n print(num)\n", "t = int(input())\r\nfor z in range(t):\r\n N = map(str,input())\r\n s = ''\r\n for i in N:\r\n s+=str(int(i)-2)\r\n print(s)", "def fun():\r\n\tT=int(input())\r\n\tfor i in range(T):\r\n\t\tx=input()\r\n\t\tst=str(\"\")\r\n\t\tfor j in x:\r\n\t\t\tn=str(int(j)-2)\r\n\t\t\tst+=n\r\n\t\t\t\r\n\t\tprint(st)\r\n\t\t\t\r\nfun()", "# cook your dish here\ntest_cases = int(input())\n\n\nfor t in range(test_cases):\n password = input()\n r = ''\n for i in range(len(password)):\n r = r + str(int(password[i]) - 2)\n\n print(r)\n", "def password(n):\n num=str(n)\n hack=\"\"\n for i in num:\n hack=hack+str(int(i)-2)\n print(hack)\n \n \nfor _ in range(int(input())):\n n=int(input())\n password(n)", "# cook your dish here\ntry:\n for t in range(int(input())):\n n=input()\n m=list(n)\n for i,j in enumerate(m):\n m[i]=str(int(j)-2)\n print(''.join(m))\nexcept EOFError:\n pass", "# cook your dish here\nfor _ in range(int(input())): \n s=input() \n for i in s: \n print(int(i)-2,end=\"\")\n print(\"\") ", "t = int(input())\r\nans = []\r\nfor _ in range(t):\r\n n = input()\r\n a = []\r\n place = 1\r\n for i in n:\r\n a.append(str(int(i)-2))\r\n a= ''.join(a)\r\n ans.append(a)\r\nfor _ in ans:\r\n print(_)\r\n", "# cook your dish here\nt=int(input())\nwhile t:\n n=int(input())\n l=[]\n while n>0:\n temp = n%10\n n//=10\n \n l.append(temp)\n for i in range(len(l)):\n l[i]-=2\n s=\"\"\n l.reverse()\n for i in l:\n s+=str(i)\n print(s)\n t-=1", "try:\n cases=int(input())\n for _ in range(cases):\n \tl=''\n \tm=input()\n \tfor i in range(len(m)):\n \t\tl+=str(int(m[i])-2)\n \tprint(l)\n\nexcept:\n pass\n", "# cook your dish here\n# cook your dish here\nt = int(input())\nfor _ in range(t):\n num = input()\n l = [str(int(x)-2) for x in num]\n ans = \"\".join(l)\n print(ans)\n", "# cook your dish here\nfor _ in range(int(input())):\n\ts = input()\n\ta = \"\"\n\tfor i in s:\n\t\ta = a+str(int(i)-2)\n\tprint(a)", "# cook your dish here\n# https://www.codechef.com/ABCC2020/problems/PASSHACK\nfor _ in range(int(input())):\n digits = list(input())\n inc, out = 0, \"\"\n while inc < len(digits):\n out += str(int(digits[inc])-2)\n inc += 1\n print(out)", "import sys\r\nimport math\r\nimport bisect\r\nfrom sys import stdin,stdout\r\nfrom math import gcd,floor,sqrt,log\r\nfrom collections import defaultdict as dd\r\nfrom bisect import bisect_left as bl,bisect_right as br\r\n\r\nsys.setrecursionlimit(100000000)\r\n\r\nii =lambda: int(input())\r\nsi =lambda: input()\r\njn =lambda x,l: x.join(map(str,l))\r\nsl =lambda: list(map(str,input().strip()))\r\nmi =lambda: list(map(int,input().split()))\r\nmif =lambda: list(map(float,input().split()))\r\nlii =lambda: list(map(int,input().split()))\r\n\r\nceil =lambda x: int(x) if(x==int(x)) else int(x)+1\r\nceildiv=lambda x,d: x//d if(x%d==0) else x//d+1\r\n\r\nflush =lambda: stdout.flush()\r\nstdstr =lambda: stdin.readline()\r\nstdint =lambda: int(stdin.readline())\r\nstdpr =lambda x: stdout.write(str(x))\r\n\r\nmod=1000000007\r\n\r\n\r\n#main code\r\nfor _ in range(ii()):\r\n n=si()\r\n ans = \"\"\r\n for i in range(len(n)) :\r\n ans = ans + str(int(n[i])-2)\r\n print(ans)\r\n", "# cook your dish here\n#Author : Ashutosh Wagh, Codechef : ashutosh0903\nfor _ in range(int(input())) :\n n = int(input())\n s = str(n)\n l = len(s)\n ans = \"\"\n for i in range(l) :\n ans = ans + str(int(s[i])-2)\n print(ans)\n", "# cook your dish here\n'''\n2\n\n3527\n\n47269\n\n3<p<10 :: p>99 and p<10**10\n1 \u2264 t \u2264 1000\n'''\ntry:\n T = int(input())\n if T>=1 and T<=1000:\n for i in range(T):\n num= input()\n if len(num)>3 and len(num)< 10**10:\n arr=[]\n for x in num:\n arr.append(int(x)-2)\n arr=list(map(str,arr))\n res=''.join(arr)\n print(res)\nexcept Exception:\n pass", "try:\r\n t = int(input().strip())\r\n for abc in range(t):\r\n n = list(input().strip())\r\n if n == []:\r\n n = list(input().strip())\r\n for i in range(len(n)):\r\n if int(n[i]) == 1:\r\n n[i] = '0'\r\n else:\r\n n[i] = int(n[i])-2\r\n for i in n:\r\n print(i, end='')\r\n print('\\n')\r\nexcept Exception:\r\n pass", "for _ in range(int(input())):\r\n s=input()\r\n a=[int(s[i])-2 for i in range(len(s))]\r\n for i in range(len(s)):\r\n print(a[i],end=\"\")\r\n print()"]
{"inputs": [["2", "3527", "47269"]], "outputs": [["1305", "25047"]]}
INTERVIEW
PYTHON3
CODECHEF
6,381
63df4075710813e9b9622b71b4277cf3
UNKNOWN
You have an array A of size N containing only positive numbers. You have to output the maximum possible value of A[i]%A[j] where 1<=i,j<=N. -----Input----- The first line of each test case contains a single integer N denoting the size of the array. The next N lines contains integers A1, A2, ..., AN denoting the numbers -----Output----- Output a single integer answering what is asked in the problem. -----Subtask 1 (20 points)----- - 1 ≤ N ≤ 5000 - 1 ≤ A[i] ≤ 2*(10^9) -----Subtask 2 (80 points)----- - 1 ≤ N ≤ 1000000 - 1 ≤ A[i] ≤ 2*(10^9) -----Example----- Input: 2 1 2 Output: 1 -----Explanation----- There will be four values, A[0]%A[0] = 0, A[0]%A[1]=1, A[1]%A[0]=0, A[1]%A[1]=0, and hence the output will be the maximum among them all, that is 1.
["n = int(input())\na = []\nfor i in range(n):\n a.append(int(input()))\nm1 = 0\nm2 = 0\nfor e in a:\n if (e > m1):\n m2 = m1\n m1 = e\n elif (e > m2 and e != m1):\n m2 = e\nans = 0\nfor e in a:\n temp = m1%e\n if (temp>ans):\n ans = temp\nprint(max(m2%m1,ans))", "__author__ = 'Hacktivist'\n\nfrom sys import stdin\n\nlst = list()\ntestCase = int(stdin.readline().strip())\nfor test in range(testCase):\n lst.append(int(stdin.readline().strip()))\nlst.sort()\nif len(lst) <= 5000:\n maximum = 0\n for i in range(len(lst)):\n for j in range(len(lst)):\n if ((lst[i] % lst[j]) > maximum):\n maximum = (lst[i] % lst[j])\n print(maximum)\n\nelse:\n print(lst[len(lst)-2] % lst[len(lst) - 1])", "N = int(input())\nA = {}\nlargest = 0\n \nfor m in range(0, N):\n p = int(input())\n A[p] = 0\n \nfor k in A:\n for m in A:\n if k % m > largest:\n largest = k % m\n \nprint(largest) ", "n = int(input())\na = sorted(set([int(input()) for _ in range(n)]))\nprint(0 if len(a) < 2 else a[-2])", "# cook your code here\nN = eval(input())\nA = []\nfor _ in range(N):\n A += [eval(input())]\nB = [0]\nA.sort()\nfor i in range(N):\n for j in range(i+1,N):\n B += [A[i]%A[j]] +[A[j]%A[i]]\nprint(max(B))", "# cook your code here\nN = eval(input())\nA = []\nfor _ in range(N):\n A += [eval(input())]\nB = []\nfor i in A:\n for j in A:\n B += [i%j]\nprint(max(B))", "size = int(input())\narray = []\n\nfor x in range(size):\n array.append(int(input()))\n \ndiff = 0 \n\nif size < 1600 :\n for i in range(size):\n for j in range(i + 1, size):\n if array[i]%array[j] > diff :\n diff = array[i]%array[j]\nelse :\n m1 = max(array)\n array.pop(array.index(m1))\n m2 = max(array)\n diff = m2%m1\n \nprint(diff)", "size = int(input())\narray = []\n\nfor x in range(size):\n array.append(int(input()))\n \ndiff = 0 \n \nfor i in range(size):\n for j in range(i + 1, size):\n if array[i]%array[j] > diff :\n diff = array[i]%array[j]\n \nprint(diff)"]
{"inputs": [["2", "1", "2"]], "outputs": [["1"]]}
INTERVIEW
PYTHON3
CODECHEF
1,949
616bb89a22e0d90bc10fca826fd7d58a
UNKNOWN
Chef and Abhishek both are fighting for the post of Chairperson to be part of ACE committee and are trying their best. To select only one student their teacher gave them a binary string (string consisting of only 0's and 1's) and asked them to find number of sub-strings present in the given string that satisfy the following condition: The substring should start with 0 and end with 1 or the substring should start with 1 and end with 0 but not start with 0 and end with 0 and start with 1 and end with 1. More formally, strings such as 100,0101 are allowed since they start and end with different characters. But strings such as 0110,1101 are not allowed because they start and end with same characters. Both Chef and Abhishek try their best to solve it but couldn't do it. You being a very good friend of Chef, he asks for your help so that he can solve it and become the Chairperson. -----Input:----- The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows. The first line of each test case contains a single integer N denoting the length of the string. The second line of each test case contains a binary string of length N. -----Output:----- For each test case, print a single line containing one integer ― the number of sub strings satisfying above conditions. -----Constraints----- - $1 \leq T \leq 1000$ - $2 \leq N \leq 10^9$ Binary string consist's only 0 and 1. -----Sample Input:----- 1 4 1010 -----Sample Output:----- 4 -----EXPLANATION:----- All possible substring are : { (1),(0),(1),(0),(10),(01),(10),(101),(010),(1010) }. Out of these only 4 substrings {(10),(01),(10),(1010)} start and end with different characters. Hence the answer 4.
["def countSubstr(str, n, x, y): \r\n \r\n tot_count = 0\r\n \r\n count_x = 0\r\n \r\n for i in range(n): \r\n if str[i] == x: \r\n count_x += 1\r\n if str[i] == y: \r\n tot_count += count_x \r\n return tot_count \r\n \r\nt=int(input())\r\nfor _ in range(t):\r\n n=int(input())\r\n str=input()\r\n x='0'\r\n y='1'\r\n x1='1'\r\n y1='0'\r\n c1=countSubstr(str,n,x,y)\r\n c2=countSubstr(str,n,x1,y1)\r\n print(c1+c2)", "# cook your dish here\nfor _ in range(int(input())):\n n=int(input())\n s=input()\n c=0\n count01=[[0,0] for _ in range(n)]\n for i in range(n-2,-1,-1):\n if s[i+1]=='1':\n count01[i][1]=count01[i+1][1]+1\n count01[i][0]=count01[i+1][0]\n else:\n count01[i][0]=count01[i+1][0]+1\n count01[i][1]=count01[i+1][1]\n for i in range(n):\n if s[i]=='1':\n c+=count01[i][0]\n else:\n c+=count01[i][1]\n # print(\"i=\",i)\n # print(c)\n # print(count01)\n print(c)", "for _ in range(int(input())):\r\n n=int(input())\r\n s=input()\r\n total=0\r\n zero=s.count(\"0\")\r\n one=s.count(\"1\")\r\n for i in range(n):\r\n if s[i]==\"0\":\r\n zero-=1\r\n total+=one\r\n else:\r\n one-=1\r\n total+=zero\r\n print(total)", "t = int(input())\nfor o in range(t):\n n = int(input())\n p = str(input())\n l = list(p)\n one = l.count('1')\n zero = l.count('0')\n #print(one,zero)\n count = 0\n for i in range(n):\n if l[i] == '1':\n count+=zero\n one-=1\n else:\n count+=one \n zero-=1 \n print(count) ", "t=int(input())\r\nfor j in range(t):\r\n\r\n n=int(input())\r\n s=input()\r\n\r\n count1=0\r\n count2=0\r\n for i in range(len(s)):\r\n if s[i]=='1':\r\n count1+=1\r\n for i in range(len(s)):\r\n if s[i]=='0':\r\n count2+=1\r\n # print(count1,count2)\r\n print(count1*count2)", "# cook your dish here\nfor ad in range(int(input())):\n n=int(input())\n s=list(input())\n zero=s.count(\"0\")\n one=s.count(\"1\")\n l=s\n ans=0\n for i in range(n):\n if l[i]==\"0\":\n zero-=1\n ans+=one\n else:\n one-=1\n ans+=zero\n print(ans)", "for _ in range(int(input())):\n \n n = int(input())\n s = input()\n # count = 0\n \n # for i else:\n \n # for j in range(i+1,n):\n # if s[j] == \"1\":\n # count+=1in range(0,n):\n \n # if s[i] == '1':\n \n # for j in range(i+1,n):\n \n # if s[j] == '0':\n # count+=1\n \n print(s.count('0')*s.count('1'))\n", "for _ in range(int(input())):\n \n n = int(input())\n s = input()\n # count = 0\n \n # for i else:\n \n # for j in range(i+1,n):\n # if s[j] == \"1\":\n # count+=1in range(0,n):\n \n # if s[i] == '1':\n \n # for j in range(i+1,n):\n \n # if s[j] == '0':\n # count+=1\n \n print(s.count('0')*s.count('1'))\n", "def fac(x):\r\n x=len(x)\r\n return int(((x-1)*(x))/2)\r\n\r\n\r\nt= int(input())\r\nfor o in range(t):\r\n n=int(input())\r\n s=input()\r\n a=s.split(\"1\")\r\n a=\"\".join(a)\r\n b=s.split(\"0\")\r\n b=\"\".join(b)\r\n print(fac(s)-fac(a)-fac(b),)", "for t in range(int(input())):\n def csbstr(str,n,a,b):\n tot,c=0,0\n for i in range(n):\n if(str[i]==a):\n c+=1\n if(str[i]==b):\n tot+=c\n return tot\n\n n=int(input())\n str=input()\n count1=csbstr(str,n,\"1\",\"0\")\n count2=csbstr(str,n,\"0\",\"1\")\n print(count1+count2)", "# cook your dish here\ndef fac(x):\n x=len(x)\n return int(((x-1)*(x))/2)\n\n\nt= int(input())\nfor o in range(t):\n n=int(input())\n s=input()\n a=s.split(\"1\")\n a=\"\".join(a)\n b=s.split(\"0\")\n b=\"\".join(b)\n print(fac(s)-fac(a)-fac(b),)", "\nfor x in range(int(input())):\n l=int(input())\n s=input()\n z=0\n for x in s:\n if x=='0':\n z+=1\n print(z*(l-z)) \n", "\r\ndef fac(x):\r\n x=len(x)\r\n return int(((x-1)*(x))/2)\r\n\r\n\r\nt= int(input())\r\nfor o in range(t):\r\n n=int(input())\r\n s=input()\r\n a=s.split(\"1\")\r\n a=\"\".join(a)\r\n b=s.split(\"0\")\r\n b=\"\".join(b)\r\n print(fac(s)-fac(a)-fac(b),)\r\n", "# cook your dish here\nfor _ in range(int(input())):\n N = int(input())\n l = input()\n arr1 = []\n arr2 = []\n #total = sum(arr1)\n #print(total)\n count1 = 0\n count2 = 0\n for i in range(len(l)-1, -1, -1):\n if(l[i] == '0'):\n arr1.append(count1)\n count2+=1\n elif(l[i] == '1'):\n count1+=1\n arr2.append(count2)\n print(sum(arr1)+sum(arr2))", "for _ in range(int(input())):\n N = int(input())\n binstr = input()\n a = binstr.count('1')\n b = binstr.count('0')\n print(a*b)", "for _ in range(int(input())):\n N = int(input())\n binstr = input()\n print(binstr.count('1')*binstr.count('0'))", "testcase=int(input())\r\nwhile(testcase!=0):\r\n testcase-=1\r\n n=int(input())\r\n l=input()\r\n print(l.count('1')*l.count('0'))", "for _ in range(int(input())):N = int(input());binstr = input();print(binstr.count('1')*binstr.count('0'))", "# def countSubStr(st,n):\r\n# \tres = 0\r\n# \tfor i in range(0,n):\r\n# \t\tif (st[i] == '1'):\r\n# \t\t\tfor j in range(i+1, n) :\r\n# \t\t\t\tif (st[j] == '0'):\r\n# \t\t\t\t\tres += 1\r\n# \t\tif (st[i] == '0'):\r\n# \t\t\tfor j in range(i+1, n):\r\n# \t\t\t\tif(st[j] == '1'):\r\n# \t\t\t\t\tres += 1\r\n# \treturn res \r\n# for _ in range(int(input())):\r\n# \tN = int(input());binstr = input()\r\n# \t#for any N, number of contigious subarrays will be sum of all i in range(1,N + 1)\r\n# \tprint(countSubStr(list(binstr),N),end=\"\") #TLE (obviously, since it's O(N**2))\r\nfor _ in range(int(input())):\r\n\tN = int(input());binstr = input()\r\n\tprint(binstr.count('1')*binstr.count('0'))", "for _ in range(int(input())):\n n = int(input())\n arr = input()\n ans = 0\n \n print(arr.count(\"1\")*arr.count(\"0\"))\n # for i in range(0, n-1):\n # if arr[i] == \"1\":\n # ans += arr[i+1:].count(\"0\")\n # else:\n # ans += arr[i+1:].count(\"1\")\n # print(ans)\n", "from functools import lru_cache\r\nimport sys\r\ntry:\r\n from cp import input\r\nexcept:\r\n def input():\r\n return sys.stdin.readline()\r\ntry:\r\n import numpy as np\r\nexcept:\r\n pass\r\nimport math\r\nimport copy\r\nimport random\r\nfrom copy import deepcopy\r\n# def input(): return sys.stdin.readline()\r\ndef itarr(arr): return list(range(len(arr)))\r\ndef mp(): return list(map(int, input().split()))\r\ndef lmp(): return list(map(int, input().strip().split()))\r\ndef inp(): return int(input())\r\n\r\n\r\nMOD = 1000000007\r\n\r\n\r\nsys.setrecursionlimit(100000)\r\nsys.settrace\r\ninf_p = float('inf')\r\ninf_n = float('-inf')\r\n\r\ndsu=[]\r\n\r\ndef find(n):\r\n if n==dsu[n]:\r\n return n\r\n tmp=find(dsu[n])\r\n dsu[n]=tmp\r\n return tmp\r\n\r\ndef union(a,b):\r\n a=find(a)\r\n b=find(b)\r\n if a!=b:\r\n dsu[b]=a\r\n\r\nadj=[]\r\nvis=[]\r\nwt=[]\r\nMAXE=0\r\nMAXO=0\r\nans=0\r\n\r\ndef even_parity(n):\r\n return (bin(n)[2:].count('1')%2)==0\r\ndef odd_parity(n):\r\n return not even_parity(n)\r\n\r\ndef dfse(curr_node,p):\r\n nonlocal MAXE, MAXO,vis,ans\r\n\r\n for node in adj[curr_node]:\r\n if vis[node]==0 :\r\n if even_parity(wt[node-1]):\r\n dfs(node,num)\r\n \r\ndef dfso(curr_node,p):\r\n nonlocal MAXE, MAXO,vis,ans\r\n \r\n for node in adj[curr_node]:\r\n if vis[node]==0 :\r\n if odd_parity(wt[node-1]):\r\n dfs(node,num)\r\n\r\ndef main():\r\n n=inp()\r\n s=input().strip()\r\n if len(s)==0:\r\n s=input().strip\r\n ones=[0]* (n+1)\r\n zeros=[0]* (n+1)\r\n one =0 \r\n zero=0\r\n for i in range(len(s)):\r\n ones[i]=one\r\n zeros[i]=zero\r\n if s[i]=='1':\r\n one+=1\r\n else:\r\n zero+=1 \r\n tot=0\r\n # print(ones,zeros)\r\n for i in range(n-1,0,-1):\r\n if s[i]=='1':\r\n tot+=zeros[i]\r\n else:\r\n tot+=ones[i]\r\n # print(i)\r\n print(tot)\r\n\r\n# main()\r\nfor i in range(inp()):\r\n main()\r\n# cook your dish here\r\n", "#Coded By Ujjwal Bharti\ntulu = int(input())\nfor _ in range(tulu):\n n = int(input())\n string = input()\n flag = False\n counter = 0\n frequency = 1\n for i in string:\n if i == \"0\" and flag==False:\n flag=True\n continue\n if flag and i == \"0\":\n frequency += 1\n if flag and i == \"1\":\n counter += (frequency)\n flag = False\n frequency = 1\n for i in string:\n if i == \"1\" and flag==False:\n flag=True\n continue\n #print(frequency)\n if flag and i==\"1\":\n frequency += 1\n if flag and i == \"0\":\n counter += frequency\n print(counter)", "n = int(input())\r\n\r\nwhile n>0:\r\n l = int(input())\r\n s = input()\r\n zero = 0\r\n one = 0\r\n subs = 0\r\n for i in range(l):\r\n if s[i]=='0':\r\n zero+=1\r\n else:\r\n one+=1\r\n subs=one*zero\r\n print(subs)\r\n\r\n n-=1"]
{"inputs": [["1", "4", "1010"]], "outputs": [["4"]]}
INTERVIEW
PYTHON3
CODECHEF
9,962
9545fc0a970ea188ddaae44a6d440967
UNKNOWN
Chef is playing with an expression which consists of integer operands and the following binary Bitwise operators - AND, OR and XOR. He is trying to figure out that what could be the Maximum possible answer of the expression, given that he can perform the operation in any order i.e not necessarily follow the rule of Precedence of operators while evaluating the expression. After some time of consistent work Chef starts feeling exhausted and wants you to automate this process for him. Can you help him out? The expression has Bitwise operators in symbol format: - & stands for AND - | stands for OR - ^ stands for XOR NOTE : It is guaranteed that the expression will always be valid, also each OPERATOR will always be preceded and succeeded by an OPERAND. -----Input:----- - The first line of input contains a single integer $T$ denoting the number of test cases. - The only line of input for each test case is a $string$ which is the Chef's expression to evaluate. -----Output:----- For each test case print a single integer i.e the maximum possible value of Chef's expression. -----Constraints----- - $1 \leq T \leq 100$. - The number of OPERATORS in the expression will be atleast 1 and atmost 10. - Each OPERAND may range from 0 to $10^9$. -----Subtasks----- - 10 points : The number of OPERATORS in the expression will be atmost 5. - 20 points : The number of OPERATORS in the expression will be atmost 8. - 70 points : Original constraints. -----Sample Input:----- 2 3^40|10^2 92^95|56&2&3 -----Sample Output:----- 43 95 -----EXPLANATION:-----CASE 2 : - If we first compute (56 & 2), the expression becomes 92^95|0&3, since (56 & 2) yields $0$. - Now on computing (95 | 0), the expression becomes 92^95&3. - Further on computing (95 & 3), the expression becomes 92^3. - Finally (92 ^ 3) yields 95, which is the maximum value of the expression.
["# cook your dish here\ndef value(a, b, c):\n if(c == '&'):\n return a&b\n elif(c == '^'):\n return a^b\n elif(c == '|'):\n return a|b\n\ndef break_rules(n, operator):\n if(len(n) == 1):\n return n\n elif(len(n) == 2):\n return [value(n[0], n[1], operator[0])]\n else:\n cont_ans = []\n for i in range(1,len(n)):\n l1 = n[:i]\n l2 = n[i:]\n o1 = operator[:i]\n o2 = operator[i:]\n l1_ans = break_rules(l1, o1)\n l2_ans = break_rules(l2, o2)\n for k in l1_ans:\n for j in l2_ans:\n cont_ans.append(value(k, j, operator[i - 1]))\n return cont_ans\n\nt = int(input())\nwhile t > 0 :\n operator = []\n num = []\n exp = input()\n temp = ''\n for i in range(len(exp)):\n if(ord(exp[i]) > 47 and ord(exp[i]) < 58):\n temp = temp + exp[i]\n else:\n num.append(int(temp))\n temp = ''\n operator.append(exp[i])\n if(i == len(exp) - 1):\n num.append(int(temp))\n t -= 1\n # print(num,operator)\n print(max(break_rules(num, operator)))", "def value(a, b, c):\n if(c == '&'):\n return a&b\n elif(c == '^'):\n return a^b\n elif(c == '|'):\n return a|b\n\ndef break_rules(n, operator):\n if(len(n) == 1):\n return n\n elif(len(n) == 2):\n return [value(n[0], n[1], operator[0])]\n else:\n cont_ans = []\n for i in range(1,len(n)):\n l1 = n[:i]\n l2 = n[i:]\n o1 = operator[:i]\n o2 = operator[i:]\n l1_ans = break_rules(l1, o1)\n l2_ans = break_rules(l2, o2)\n for k in l1_ans:\n for j in l2_ans:\n cont_ans.append(value(k, j, operator[i - 1]))\n return cont_ans\n\nt = int(input())\nwhile t > 0 :\n operator = []\n num = []\n exp = input()\n temp = ''\n for i in range(len(exp)):\n if(ord(exp[i]) > 47 and ord(exp[i]) < 58):\n temp = temp + exp[i]\n else:\n num.append(int(temp))\n temp = ''\n operator.append(exp[i])\n if(i == len(exp) - 1):\n num.append(int(temp))\n t -= 1\n # print(num,operator)\n print(max(break_rules(num, operator)))", "# cook your dish here\ndef value(a, b, c):\n if(c == '&'):\n return a&b\n elif(c == '^'):\n return a^b\n elif(c == '|'):\n return a|b\n\ndef break_rules(n, operator):\n if(len(n) == 1):\n return n\n elif(len(n) == 2):\n return [value(n[0], n[1], operator[0])]\n else:\n cont_ans = []\n for i in range(1,len(n)):\n l1 = n[:i]\n l2 = n[i:]\n o1 = operator[:i - 1]\n o2 = operator[i:]\n l1_ans = break_rules(l1, o1)\n l2_ans = break_rules(l2, o2)\n for k in l1_ans:\n for j in l2_ans:\n cont_ans.append(value(k, j, operator[i - 1]))\n return cont_ans\n\nt = int(input())\nwhile t > 0 :\n operator = []\n num = []\n exp = input()\n temp = ''\n for i in range(len(exp)):\n if(ord(exp[i]) > 47 and ord(exp[i]) < 58):\n temp = temp + exp[i]\n else:\n num.append(int(temp))\n temp = ''\n operator.append(exp[i])\n if(i == len(exp) - 1):\n num.append(int(temp))\n t -= 1\n \n print(max(break_rules(num, operator)))", "# cook your dish here\ndef value(a, b, c):\n if(c == '&'):\n return a&b\n elif(c == '^'):\n return a^b\n elif(c == '|'):\n return a|b\n\ndef break_rules(n, operator):\n if(len(n) == 1):\n return n\n elif(len(n) == 2):\n return [value(n[0], n[1], operator[0])]\n else:\n cont_ans = []\n for i in range(1,len(n)):\n l1 = n[:i]\n l2 = n[i:]\n o1 = operator[:i - 1]\n o2 = operator[i:]\n l1_ans = break_rules(l1, o1)\n l2_ans = break_rules(l2, o2)\n for k in l1_ans:\n for j in l2_ans:\n cont_ans.append(value(k, j, operator[i - 1]))\n return cont_ans\n\nt = int(input())\nwhile t > 0 :\n operator = []\n num = []\n exp = input()\n temp = ''\n for i in range(len(exp)):\n if(ord(exp[i]) > 47 and ord(exp[i]) < 58):\n temp = temp + exp[i]\n else:\n num.append(int(temp))\n temp = ''\n operator.append(exp[i])\n if(i == len(exp) - 1):\n num.append(int(temp))\n t -= 1\n \n print(max(break_rules(num, operator)))", "# cook your dish here\ndef value(a, b, c):\n if(c == '&'):\n return a&b\n elif(c == '^'):\n return a^b\n elif(c == '|'):\n return a|b\n\ndef break_rules(n, operator):\n if(len(n) == 1):\n return n\n elif(len(n) == 2):\n return [value(n[0], n[1], operator[0])]\n else:\n cont_ans = []\n for i in range(1,len(n)):\n l1 = n[:i]\n l2 = n[i:]\n o1 = operator[:i - 1]\n o2 = operator[i:]\n l1_ans = break_rules(l1, o1)\n l2_ans = break_rules(l2, o2)\n for k in l1_ans:\n for j in l2_ans:\n cont_ans.append(value(k, j, operator[i - 1]))\n return cont_ans\n\nt = int(input())\nwhile t > 0 :\n operator = []\n num = []\n exp = input()\n temp = ''\n for i in range(len(exp)):\n if(ord(exp[i]) > 47 and ord(exp[i]) < 58):\n temp = temp + exp[i]\n else:\n num.append(int(temp))\n temp = ''\n operator.append(exp[i])\n if(i == len(exp) - 1):\n num.append(int(temp))\n t -= 1\n \n print(max(break_rules(num, operator)))", "# cook your dish here\ndef value(a, b, c):\n if(c == '&'):\n return a&b\n elif(c == '^'):\n return a^b\n elif(c == '|'):\n return a|b\n\ndef break_rules(n, operator):\n if(len(n) == 1):\n return n\n elif(len(n) == 2):\n return [value(n[0], n[1], operator[0])]\n else:\n cont_ans = []\n for i in range(1,len(n)):\n l1 = n[:i]\n l2 = n[i:]\n o1 = operator[:i - 1]\n o2 = operator[i:]\n l1_ans = break_rules(l1, o1)\n l2_ans = break_rules(l2, o2)\n for k in l1_ans:\n for j in l2_ans:\n cont_ans.append(value(k, j, operator[i - 1]))\n return cont_ans\n\nt = int(input())\nwhile t > 0 :\n operator = []\n num = []\n exp = input()\n temp = ''\n for i in range(len(exp)):\n if(ord(exp[i]) > 47 and ord(exp[i]) < 58):\n temp = temp + exp[i]\n else:\n num.append(int(temp))\n temp = ''\n operator.append(exp[i])\n if(i == len(exp) - 1):\n num.append(int(temp))\n t -= 1\n \n print(max(break_rules(num, operator)))", "# cook your dish here\ndef value(a, b, c):\n if(c == '&'):\n return a&b\n elif(c == '^'):\n return a^b\n elif(c == '|'):\n return a|b\n\ndef break_rules(n, operator):\n if(len(n) == 1):\n return n\n elif(len(n) == 2):\n return [value(n[0], n[1], operator[0])]\n else:\n cont_ans = []\n for i in range(1,len(n)):\n l1 = n[:i]\n l2 = n[i:]\n o1 = operator[:i - 1]\n o2 = operator[i:]\n l1_ans = break_rules(l1, o1)\n l2_ans = break_rules(l2, o2)\n for k in l1_ans:\n for j in l2_ans:\n cont_ans.append(value(k, j, operator[i - 1]))\n return cont_ans\nt = int(input())\nwhile t > 0 :\n operator = []\n num = []\n exp = input()\n temp = ''\n for i in range(len(exp)):\n if(ord(exp[i]) > 47 and ord(exp[i]) < 58):\n temp = temp + exp[i]\n else:\n num.append(int(temp))\n temp = ''\n operator.append(exp[i])\n if(i == len(exp) - 1):\n num.append(int(temp))\n t -= 1\n \n print(max(break_rules(num, operator)))", "# cook your dish here\ndef value(a, b, c):\n if(c == '&'):\n return a&b\n elif(c == '^'):\n return a^b\n elif(c == '|'):\n return a|b\n\ndef break_rules(n, operator):\n if(len(n) == 1):\n return n\n elif(len(n) == 2):\n return [value(n[0], n[1], operator[0])]\n else:\n cont_ans = []\n for i in range(1,len(n)):\n l1 = n[:i]\n l2 = n[i:]\n o1 = operator[:i - 1]\n o2 = operator[i:]\n l1_ans = break_rules(l1, o1)\n l2_ans = break_rules(l2, o2)\n for k in l1_ans:\n for j in l2_ans:\n cont_ans.append(value(k, j, operator[i - 1]))\n return cont_ans\n\nt = int(input())\nwhile t > 0 :\n operator = []\n num = []\n exp = input()\n temp = ''\n for i in range(len(exp)):\n if(ord(exp[i]) > 47 and ord(exp[i]) < 58):\n temp = temp + exp[i]\n else:\n num.append(int(temp))\n temp = ''\n operator.append(exp[i])\n if(i == len(exp) - 1):\n num.append(int(temp))\n t -= 1\n \n print(max(break_rules(num, operator)))", "def value(a, b, c):\n if(c == '&'):\n return a&b\n elif(c == '^'):\n return a^b\n elif(c == '|'):\n return a|b\n\ndef break_rules(n, operator):\n if(len(n) == 1):\n return n\n elif(len(n) == 2):\n return [value(n[0], n[1], operator[0])]\n else:\n cont_ans = []\n for i in range(1,len(n)):\n l1 = n[:i]\n l2 = n[i:]\n o1 = operator[:i - 1]\n o2 = operator[i:]\n l1_ans = break_rules(l1, o1)\n l2_ans = break_rules(l2, o2)\n for k in l1_ans:\n for j in l2_ans:\n cont_ans.append(value(k, j, operator[i - 1]))\n return cont_ans\n\nt = int(input())\nwhile t > 0 :\n operator = []\n num = []\n exp = input()\n temp = ''\n for i in range(len(exp)):\n if(ord(exp[i]) > 47 and ord(exp[i]) < 58):\n temp = temp + exp[i]\n else:\n num.append(int(temp))\n temp = ''\n operator.append(exp[i])\n if(i == len(exp) - 1):\n num.append(int(temp))\n t -= 1\n \n print(max(break_rules(num, operator)))", "def value(a, b, c):\r\n if(c == '&'):\r\n return a&b\r\n elif(c == '^'):\r\n return a^b\r\n elif(c == '|'):\r\n return a|b\r\n\r\ndef break_rules(n, operator):\r\n if(len(n) == 1):\r\n return n\r\n elif(len(n) == 2):\r\n return [value(n[0], n[1], operator[0])]\r\n else:\r\n cont_ans = []\r\n for i in range(1,len(n)):\r\n l1 = n[:i]\r\n l2 = n[i:]\r\n o1 = operator[:i - 1]\r\n o2 = operator[i:]\r\n l1_ans = break_rules(l1, o1)\r\n l2_ans = break_rules(l2, o2)\r\n for k in l1_ans:\r\n for j in l2_ans:\r\n cont_ans.append(value(k, j, operator[i - 1]))\r\n return cont_ans\r\n\r\nt = int(input())\r\nwhile t > 0 :\r\n operator = []\r\n num = []\r\n exp = input()\r\n temp = ''\r\n for i in range(len(exp)):\r\n if(ord(exp[i]) > 47 and ord(exp[i]) < 58):\r\n temp = temp + exp[i]\r\n else:\r\n num.append(int(temp))\r\n temp = ''\r\n operator.append(exp[i])\r\n if(i == len(exp) - 1):\r\n num.append(int(temp))\r\n t -= 1\r\n \r\n print(max(break_rules(num, operator)))", "def value(a, b, c):\n if(c == '&'):\n return a&b\n elif(c == '^'):\n return a^b\n elif(c == '|'):\n return a|b\n\ndef break_rules(n, operator):\n if(len(n) == 1):\n return n\n elif(len(n) == 2):\n return [value(n[0], n[1], operator[0])]\n else:\n cont_ans = []\n for i in range(1,len(n)):\n l1 = n[:i]\n l2 = n[i:]\n o1 = operator[:i - 1]\n o2 = operator[i:]\n l1_ans = break_rules(l1, o1)\n l2_ans = break_rules(l2, o2)\n for k in l1_ans:\n for j in l2_ans:\n cont_ans.append(value(k, j, operator[i - 1]))\n return cont_ans\n\nt = int(input())\nwhile t > 0 :\n operator = []\n num = []\n exp = input()\n temp = ''\n for i in range(len(exp)):\n if(ord(exp[i]) > 47 and ord(exp[i]) < 58):\n temp = temp + exp[i]\n else:\n num.append(int(temp))\n temp = ''\n operator.append(exp[i])\n if(i == len(exp) - 1):\n num.append(int(temp))\n t -= 1\n \n print(max(break_rules(num, operator)))", "def extract(s):\n\tarr = []\n\tnews = ''\n\tfor x in s:\n\t\ttry:\n\t\t\tx = int(x)\n\t\t\tnews = news+str(x)\n\t\texcept:\n\t\t\tarr = [news]+arr\n\t\t\tnews = ''\n\t\t\tarr = [x]+arr\n\tarr = [news]+arr\n\treturn arr\nfor i in range(int(input())):\n\ts = input()\n\tarr = extract(s)\n\tn = len(arr)//2 + 1\n\tdp = [[0]*n for j in range(n)]\n\tfor i in range(n):\n\t\tdp[i][i] = [int(arr[2*i])]\n\tn = len(arr)\n\tfor i in range(3, n+1, 2):\n\t\tfor j in range(0, n-i+1, 2):\n\t\t\tans = []\n\t\t\tfor k in range(j+2, i+j+1, 2):\n\t\t\t\tfor x in dp[j//2][(k-1)//2]:\n\t\t\t\t\tfor y in dp[k//2][(i+j)//2]:\n\t\t\t\t\t\tif arr[k-1] == '&':\n\t\t\t\t\t\t\tans += [x & y]\n\t\t\t\t\t\tif arr[k-1] == '|':\n\t\t\t\t\t\t\tans += [x | y]\n\t\t\t\t\t\tif arr[k-1] == '^':\n\t\t\t\t\t\t\tans += [x ^ y]\n\t\t\tif i != n:\n\t\t\t\tdp[j//2][k//2] = ans[:]\n\t\t\telse:\n\t\t\t\tprint(max(ans))", "def extract(s):\r\n\tarr = []\r\n\tnews = ''\r\n\tfor x in s:\r\n\t\ttry:\r\n\t\t\tx = int(x)\r\n\t\t\tnews += str(x)\r\n\t\texcept:\r\n\t\t\tarr += [news]\r\n\t\t\tnews = ''\r\n\t\t\tarr += [x]\r\n\tarr += [news]\r\n\treturn arr\r\n\r\nt = int(input())\r\nfor _ in range(t):\r\n\ts = input()\r\n\tarr = extract(s)\r\n\tn = len(arr)//2 + 1\r\n\tdp = [[0]*n for j in range(n)]\r\n\tfor i in range(n):\r\n\t\tdp[i][i] = [int(arr[2*i])]\r\n\r\n\tn = len(arr)\r\n\tfor i in range(3, n+1, 2):\r\n\t\tfor j in range(0, n-i+1, 2):\r\n\t\t\tans = []\r\n\t\t\tfor k in range(j+2, i+j+1, 2):\r\n\t\t\t\tfor x in dp[j//2][(k-1)//2]:\r\n\t\t\t\t\tfor y in dp[k//2][(i+j)//2]:\r\n\t\t\t\t\t\tif arr[k-1] == '&':\r\n\t\t\t\t\t\t\tans += [x & y]\r\n\t\t\t\t\t\tif arr[k-1] == '|':\r\n\t\t\t\t\t\t\tans += [x | y]\r\n\t\t\t\t\t\tif arr[k-1] == '^':\r\n\t\t\t\t\t\t\tans += [x ^ y]\r\n\t\t\tif i != n:\r\n\t\t\t\tdp[j//2][k//2] = ans[:]\r\n\t\t\telse:\r\n\t\t\t\tprint(max(ans))\r\n", "def extract(s):\r\n\tarr = []\r\n\tnews = ''\r\n\tfor x in s:\r\n\t\ttry:\r\n\t\t\tx = int(x)\r\n\t\t\tnews += str(x)\r\n\t\texcept:\r\n\t\t\tarr += [news]\r\n\t\t\tnews = ''\r\n\t\t\tarr += [x]\r\n\tarr += [news]\r\n\treturn arr\r\n\r\nt = int(input())\r\nfor _ in range(t):\r\n\ts = input()\r\n\tarr = extract(s)\r\n\tn = len(arr)//2 + 1\r\n\tdp = [[0]*n for j in range(n)]\r\n\tfor i in range(n):\r\n\t\tdp[i][i] = [int(arr[2*i])]\r\n\r\n\tn = len(arr)\r\n\tfor i in range(3, n+1, 2):\r\n\t\tfor j in range(0, n-i+1, 2):\r\n\t\t\tans = []\r\n\t\t\tfor k in range(j+2, i+j+1, 2):\r\n\t\t\t\tfor x in dp[j//2][(k-1)//2]:\r\n\t\t\t\t\tfor y in dp[k//2][(i+j)//2]:\r\n\t\t\t\t\t\tans += [eval(str(x) + arr[k-1] + str(y))]\r\n\r\n\t\t\tif i != n:\r\n\t\t\t\tdp[j//2][k//2] = ans[:]\r\n\t\t\telse:\r\n\t\t\t\tprint(max(ans))\r\n"]
{"inputs": [["2", "3^40|10^2", "92^95|56&2&3"]], "outputs": [["43", "95"]]}
INTERVIEW
PYTHON3
CODECHEF
15,805
97fc5fd42341baf2e0c2650ab4397334
UNKNOWN
Ho, Ho, Ho! It's Christmas time and our friendly grandpa Santa Claus is busy distributing gifts to all the nice children. With the rising population, Santa's workload every year gets increased and he seeks your help to wrap the gifts with fancy wrapping papers while he gets them distributed. Everything was going great until you realised that you'll fall short of wrapping paper. But luckily, you get a very innovative idea, that will allow you to pack all the remaining gifts without worrying about lack of wrapping paper. Any guesses what the idea is? Using ice for wrapping, obviously! That's the only thing available at the North Pole. Now, in order to reduce your trips to the ice factory, you decide to write a program that helps you visualize how much ice is needed for a particular gift. -----Input:----- Input will consist of a single line with size $n$. -----Output:----- Print the ice wrapped gift box for the given size. -----Constraints----- - $0 \leq n \leq 1000$ -----Sample Input:----- 4 -----Sample Output:----- 4 4 4 4 4 4 4 4 3 3 3 3 3 4 4 3 2 2 2 3 4 4 3 2 1 2 3 4 4 3 2 2 2 3 4 4 3 3 3 3 3 4 4 4 4 4 4 4 4
["# cook your dish here\ndef read_i_l(l=False):\n m = list(map(int, input().strip().split(\" \")))\n if l:\n return list(m)\n else:\n return m\ndef i():\n return int(input().strip())\nT = i()\nL = []\n\"\"\"for current in range(T):\n line = \"\"\n for i in range(current):\n line+=str((T-i)%10)\n for i in range(2*(T-current)-1):\n line+=str((T-current)%10)\n for i in range(current-1,-1,-1):\n line+=str((T-i)%10)\n L.append(line)\nL += L[-2::-1]\"\"\"\n\nif T >= 1:\n L = [\"1\"]\n\nfor i in range(2,T+1):\n nL = [str(i)+(2*i-2)*(\" \"+str(i))]\n for l in L:\n nL.append(str(i)+\" \"+l+\" \"+str(i))\n nL.append(str(i)+(2*i-2)*(\" \"+str(i)))\n L = nL\nfor l in L:\n print(l)\n", "# cook your dish here\nnum = int(input())\n\nmat = [[-1 for i in range(num*2 -1)]for j in range(num*2 -1)]\ncs = 0\nrs = 0\n\nre = len(mat)-1\nce = len(mat)-1\n\n\nwhile num:\n\n t = num*2 -1\n\n for i in range(cs,ce+1):\n mat[rs][i] = num\n mat[re][i] = num\n\n for j in range(rs,re):\n mat[j][cs] = num\n mat[j][ce] = num\n\n num -= 1\n rs += 1\n cs += 1\n re -= 1\n ce -= 1\n\n\n\n\n\nfor i in mat:\n print(*i)\n\n\n", "# Python3 Program to print rectangular \n# inner reducing pattern \nMAX = 1000\n\n# function to Print pattern \ndef prints(a, size): \n\tfor i in range(size): \n\t\tfor j in range(size): \n\t\t\tprint(a[i][j], end = ' ')\n\t\tprint() \n\n# function to compute pattern \ndef innerPattern(n): \n\t\n\t# Pattern Size \n\tsize = 2 * n - 1\n\tfront = 0\n\tback = size - 1\n\ta = [[0 for i in range(MAX)] \n\t\t\tfor i in range(MAX)] \n\twhile (n != 0): \n\t\tfor i in range(front, back + 1): \n\t\t\tfor j in range(front, back + 1): \n\t\t\t\tif (i == front or i == back or\n\t\t\t\t\tj == front or j == back): \n\t\t\t\t\ta[i][j] = n \n\t\tfront += 1\n\t\tback -= 1\n\t\tn -= 1\n\tprints(a, size); \n\n# Driver code \n\n# Input \nn = int(input())\n\n# function calling \ninnerPattern(n) \n\n# This code is contributed \n# by sahishelangia \n", "# cook your dish here\ndef printGift(n):\n dim = 2*n-1\n start = 0\n end = dim-1\n a = [[0 for i in range(10000)]for i in range(10000)]\n while n != 0:\n for i in range(start,end+1):\n for j in range(start,end+1):\n if i == start or i == end or j == start or j == end:\n a[i][j] = n \n\n start += 1\n end -= 1\n n -= 1\n \n for i in range(dim):\n for j in range(dim):\n print(a[i][j],end=\" \")\n print()\n\n\n\ndef __starting_point():\n n = int(input()) \n printGift(n)\n__starting_point()", "def pattern(n) : \n s=2*n-1\n for i in range(0, (s//2)+1): \n m = n \n for j in range(0, i): \n print(m ,end= \" \" ) \n m-=1\n for k in range(0, s - 2 * i): \n print(n-i ,end= \" \" ) \n m = n - i + 1\n for l in range(0, i): \n print(m ,end= \" \" ) \n m+=1\n print(\"\") \n for i in range(s//2-1,-1,-1): \n m = n \n for j in range(0, i): \n print(m ,end= \" \" ) \n m-=1\n for k in range(0, s - 2 * i): \n print(n-i ,end= \" \" ) \n m = n - i + 1\n for l in range(0, i): \n print(m ,end= \" \" ) \n m+=1\n print(\"\") \ndef __starting_point(): \n n = int(input())\n pattern(n) \n__starting_point()", "# cook your dish here\nn=int(input())\nif(n==0):\n print()\n \nelif(n==1):\n print(1)\nelif(n==2):\n print(2,2,2)\n print(2,1,2)\n print(2,2,2)\nelse:\n l=[i for i in range(1,n+1)]\n a=[]\n for i in range(2*n-1):\n a1=[]\n for i in range(2*n-1):\n a1.append(0)\n a.append(a1)\n col1=0\n coln=2*n-2\n row1=0\n rown=2*n-2\n c=n\n while(True):\n for i in range(2*n-1):\n if(a[i][col1]==0):\n a[i][col1]=c\n for i in range(2*n-1):\n if(a[i][coln]==0):\n a[i][coln]=c\n for i in range(2*n-1):\n if(a[row1][i]==0):\n a[row1][i]=c\n for i in range(2*n-1):\n if(a[rown][i]==0):\n a[rown][i]=c\n c-=1\n if(c==0):\n break\n col1+=1\n coln-=1\n row1+=1\n rown-=1\n for i in a:\n print(*i)\n \n \n \n", "n = int(input())\r\nl = n * 2 - 1\r\nfor i in range(l):\r\n for j in range(l):\r\n mins = min(i, j)\r\n if mins >= l - i:\r\n mins = l - i - 1\r\n mins = min(mins, l - j - 1)\r\n print(n - mins, end= \" \")\r\n print()\r\n", "n=int(input())\nk=n\nm=0\nt=0\nd=2*n-2\nfor i in range(n):\n l=i+1\n k=n\n for j in range(i+1):\n print(k, end=\" \")\n k-=1\n g=d-m\n while(g-t>0):\n print(k+1, end=\" \")\n g-=1\n h=m\n k+=2\n while(h>0):\n print(k, end=\" \")\n h-=1\n k+=1\n m+=1\n t+=1\n print()\nk=n-1\nt=1\nm-=1\nfor i in range(n-1):\n l=k-i\n d=k+1\n for j in range(l, 0, -1):\n print(d, end=\" \")\n d-=1\n f=t\n while(f>0):\n print(d+1, end=\" \")\n f-=1\n b=d+1\n v=m\n while(v>0):\n print(b, end=\" \")\n v-=1\n b+=1\n t+=2\n m-=1\n print()", "# cook your dish here\nn = int(input())\nval = (2*n)-1\nx =2\n\nfor i in range(val):\n k = n+1\n h = -1\n count = 0\n for j in range(val):\n if i < n:\n if h < i:\n h += 1\n k -= 1\n print(k, end=' ')\n if h == i:\n count = 1\n val1 = (2*k)-1\n \n elif (count > 0) and (count < val1):\n count += 1\n print(k, end=' ')\n \n else:\n k += 1\n print(k, end=' ')\n \n else:\n if (h < i) and (k != x) and (count == 0):\n h += 1\n k -= 1\n print(k, end=' ')\n if k == x:\n count = 1\n val1 = (2*x) - 1\n \n elif count < val1:\n count += 1\n print(k, end=' ')\n \n else:\n k += 1\n print(k, end=' ')\n \n if i >= n:\n x += 1\n print()\n\n \n", "# cook your dish here\nn=int(input())\nfor i in range(n,0,-1):\n k=n\n j=1\n while j<=2*n-1:\n print(k,end=\" \")\n j+=1\n if i<k:\n k-=1\n if(i==k):\n for l in range(2*k-1):\n if j>2*n-1:\n break\n print(k,end=\" \")\n j+=1\n k+=1\n while k!=i:\n if j>2*n-1:\n break\n print(k,end=\" \")\n k+=1\n j+=1\n print()\nfor i in range(2,n+1):\n k=n\n j=1\n while j<=2*n-1:\n print(k,end=\" \")\n j+=1\n if i<k:\n k-=1\n if(i==k):\n for l in range(2*k-1):\n if j>2*n-1:\n break\n print(k,end=\" \")\n j+=1\n k+=1\n while k!=i:\n if j>2*n-1:\n break\n print(k,end=\" \")\n k+=1\n j+=1\n print()", "# cook your dish here\nn=int(input())\nfor i in range(n,0,-1):\n k=n\n j=1\n while j<=2*n-1:\n print(k,end=\" \")\n j+=1\n if i<k:\n k-=1\n if(i==k):\n for l in range(2*k-1):\n if j>2*n-1:\n break\n print(k,end=\" \")\n j+=1\n k+=1\n while k!=i:\n if j>2*n-1:\n break\n print(k,end=\" \")\n k+=1\n j+=1\n print()\nfor i in range(2,n+1):\n k=n\n j=1\n while j<=2*n-1:\n print(k,end=\" \")\n j+=1\n if i<k:\n k-=1\n if(i==k):\n for l in range(2*k-1):\n if j>2*n-1:\n break\n print(k,end=\" \")\n j+=1\n k+=1\n while k!=i:\n if j>2*n-1:\n break\n print(k,end=\" \")\n k+=1\n j+=1\n print()", "n=int(input())\nfor i in range(n,0,-1):\n k=n\n j=1\n while j<=2*n-1:\n print(k,end=\" \")\n j+=1\n if i<k:\n k-=1\n if(i==k):\n for l in range(2*k-1):\n if j>2*n-1:\n break\n print(k,end=\" \")\n j+=1\n k+=1\n while k!=i:\n if j>2*n-1:\n break\n print(k,end=\" \")\n k+=1\n j+=1\n print()\nfor i in range(2,n+1):\n k=n\n j=1\n while j<=2*n-1:\n print(k,end=\" \")\n j+=1\n if i<k:\n k-=1\n if(i==k):\n for l in range(2*k-1):\n if j>2*n-1:\n break\n print(k,end=\" \")\n j+=1\n k+=1\n while k!=i:\n if j>2*n-1:\n break\n print(k,end=\" \")\n k+=1\n j+=1\n print()", "n = int(input())\r\nl = [[1],]\r\nif n == 1:\r\n pass\r\nelse:\r\n i = 2\r\n while i <= n:\r\n l1 = [i for j in range(2*i-3)]\r\n l.insert(0,l1)\r\n for j in l:\r\n j.append(i)\r\n j.insert(0,i)\r\n i += 1\r\nfor i in l:\r\n print(*i)\r\nfor i in range(len(l)-2,-1,-1):\r\n print(*l[i])", "n=int(input())\r\nfor i in range(n,0,-1):\r\n k=n\r\n j=1\r\n while j<=2*n-1:\r\n print(k,end=\" \")\r\n j+=1\r\n if i<k:\r\n k-=1\r\n if(i==k):\r\n for l in range(2*k-1):\r\n if j>2*n-1:\r\n break\r\n print(k,end=\" \")\r\n j+=1\r\n k+=1\r\n while k!=i:\r\n if j>2*n-1:\r\n break\r\n print(k,end=\" \")\r\n k+=1\r\n j+=1\r\n print()\r\nfor i in range(2,n+1):\r\n k=n\r\n j=1\r\n while j<=2*n-1:\r\n print(k,end=\" \")\r\n j+=1\r\n if i<k:\r\n k-=1\r\n if(i==k):\r\n for l in range(2*k-1):\r\n if j>2*n-1:\r\n break\r\n print(k,end=\" \")\r\n j+=1\r\n k+=1\r\n while k!=i:\r\n if j>2*n-1:\r\n break\r\n print(k,end=\" \")\r\n k+=1\r\n j+=1\r\n print()", "n=int(input())\r\na=[]\r\nsize=(2*n)-1\r\nb=[n]*size\r\nsize-=2\r\ncurr=n-1\r\na.append(b)\r\nfor i in range(n-1):\r\n c=b.copy()\r\n c[i+1:i+1+size]=[curr]*size\r\n a.append(c)\r\n b=c.copy()\r\n curr-=1\r\n size-=2\r\nfor i in range(len(a)):\r\n print(*a[i])\r\nfor i in range(len(a)-2,-1,-1):\r\n print(*a[i])", "# cook your dish here\nn = int(input())\nif n == 0:\n print(0)\nelse: \n l = [[0 for i in range(2*n-1)] for j in range(2*n-1)]\n for i in range(1,2*n):\n k = []\n for j in range(1,2*n):\n d = max(abs(i-n),abs(j-n))\n k.append(d+1)\n print(*k) \n", "n=int(input())\ntemp=[n for i in range(2*n-1)]\narr=[]\nfirstelement=temp[:]\narr.append(firstelement)\nfor i in range(1,n):\n temp[i:-i]=[n-i for j in range(len(temp[i:-i]))]\n ttemp=temp[:]\n arr.append(ttemp)\nfor i in range(len(arr)-2,0,-1):\n appendtemp=arr[i][:]\n arr.append(appendtemp)\narr.append(arr[0])\nfor i in arr:\n for j in i:\n print(j,end=\" \")\n print(\"\\n\")", "# cook your dish here\nn = int(input())\nfor i in range(2*n-1):\n a = n\n if i < n:\n for j in range(2*n-1):\n print(a, end = ' ')\n if i > j:\n a = a - 1\n elif i+j >= 2*n-2:\n a = a + 1\n elif i >= n:\n for j in range(2*n-1):\n print(a, end = ' ')\n if i+j < 2*n-2:\n a = a - 1\n elif j >= i:\n a = a + 1\n print()", "n=int(input())\r\nleng=2*n-1\r\nfor row in range(0,leng):\r\n for col in range(0,leng):\r\n mini=row if row<col else col\r\n mini=mini if mini<leng-row else leng-row-1\r\n mini=mini if mini<leng-col else leng-col-1\r\n print(n-mini,end=\" \")\r\n print(\"\")", "n = int(input())\nle = 2*n-1\nfor i in range(le):\n for j in range(le):\n print(n- min(i,j,le-1-i,le-1-j),end=' ')\n print()\n", "def replace(l,key,i,j):\r\n for k in range(i,j+1):\r\n l[k]=str(key)\r\nn=int(input())\r\ns=str(n)\r\ni=0\r\nj=n*2-2\r\nkey=n\r\nm=[]\r\nl=((n*2)-1)*s.split()\r\nfor i in range(int((n*2-2)/2)+1):\r\n replace(l,key,i,j)\r\n key-=1\r\n j-=1\r\n m.append(' '.join(l))\r\nfor j in range(n-2,-1,-1):\r\n m.append(m[j])\r\nfor p in m:\r\n print(p)\r\n \r\n\r\n \r\n \r\n", "# cook your dish here\nn=int(input())\n\ndef mini(a,b,n):\n if a<n and b<n:\n return min(a,b)\n elif a>=n and b<n:\n return min(2*n-2-a,b)\n elif a<n and b>=n:\n return min(a,2*n-2-b)\n elif a>=n and b>=n:\n return min(2*n-2-a,2*n-2-b)\n \n\nfor i in range(0,2*n-1):\n for j in range(0,2*n-1):\n temp = n - mini(i,j,n)\n print(temp,end=' ')\n print(\"\")", "from sys import stdin, stdout\nfrom math import floor, gcd, fabs, factorial, fmod, sqrt, inf, log\nfrom collections import defaultdict as dd, deque\nfrom heapq import merge, heapify, heappop, heappush, nsmallest\nfrom bisect import bisect_left as bl, bisect_right as br, bisect\nmod = pow(10, 9) + 7\nmod2 = 998244353\ndef inp(): return stdin.readline().strip()\ndef out(var, end=\"\\n\"): stdout.write(str(var)+\"\\n\")\ndef outa(*var, end=\"\\n\"): stdout.write(' '.join(map(str, var)) + end)\ndef lmp(): return list(mp())\ndef mp(): return list(map(int, inp().split()))\ndef smp(): return list(map(str, inp().split()))\ndef l1d(n, val=0): return [val for i in range(n)]\ndef l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]\ndef remadd(x, y): return 1 if x%y else 0\ndef ceil(a,b): return (a+b-1)//b\n\ndef isprime(x):\n if x<=1: return False\n if x in (2, 3): return True\n if x%2 == 0: return False\n for i in range(3, int(sqrt(x))+1, 2):\n if x%i == 0: return False\n return True\n \nn = int(inp())\nt = False\nk = 0\nml = [str(n) for i in range(2*n-1)]\nwhile(k>0 or not t):\n k += -1 if t else 1\n print(\" \".join(ml))\n for i in range(k, 2*n-1-k):\n ml[i] = str(n-k)\n if k==n-1: t = True\nprint(\" \".join(ml))\n \n\n", "try:\r\n num = int(input())\r\n \r\n MAX = 1000\r\n def prints(a, size): \r\n for i in range(size): \r\n for j in range(size): \r\n print(a[i][j], end = \" \") \r\n print() \r\n def innerPattern(n): \r\n size = 2 * n - 1\r\n front = 0\r\n back = size - 1\r\n a = [[0 for i in range(MAX)]for i in range(MAX)] \r\n while (n != 0): \r\n for i in range(front, back + 1): \r\n for j in range(front, back + 1): \r\n if (i == front or i == back or j == front or j == back): \r\n a[i][j] = n \r\n front += 1\r\n back -= 1\r\n n -= 1\r\n prints(a, size)\r\n \r\n \r\n innerPattern(num)\r\nexcept:\r\n pass\r\n\r\n\r\n", "# cook your dish here\nN = int(input())\nfor i in range(1, N + 1): \n for j in range(1, N + 1): \n min = i if i < j else j \n print(N - min + 1, end = \" \")\n for j in range(N - 1, 0, -1): \n min = i if i < j else j \n print(N - min + 1, end = \" \") \n print() \nfor i in range(N - 1, 0, -1): \n for j in range(1, N + 1): \n min = i if i < j else j \n print(N - min + 1, end = \" \") \n for j in range(N - 1, 0, -1): \n min = i if i < j else j \n print(N - min + 1, end = \" \") \n print() "]
{"inputs": [["4"]], "outputs": [["4 4 4 4 4 4 4", "4 3 3 3 3 3 4", "4 3 2 2 2 3 4", "4 3 2 1 2 3 4", "4 3 2 2 2 3 4", "4 3 3 3 3 3 4", "4 4 4 4 4 4 4"]]}
INTERVIEW
PYTHON3
CODECHEF
16,737
1fe2185425127141b2cb8fdc0b41e2d9
UNKNOWN
Write a program to find the remainder when an integer A is divided by an integer B. -----Input----- The first line contains an integer T, the total number of test cases. Then T lines follow, each line contains two Integers A and B. -----Output----- For each test case, find the remainder when A is divided by B, and display it in a new line. -----Constraints----- - 1 ≤ T ≤ 1000 - 1 ≤ A,B ≤ 10000 -----Example----- Input 3 1 2 100 200 40 15 Output 1 100 10
["number = int(input())\nfor i in range(number):\n x = list(map(int, input().split(' ')))\n print(x[0]%x[1])", "t = int(input())\n\nfor x in range(0, t):\n a, b = input().split()\n rem = int(a) % int(b)\n print(int(rem), \"\\n\")", "t = int(input())\n\nfor x in range(0, t):\n a, b = input().split()\n rem = int(a) % int(b)\n print(int(rem), \"\\n\")", "x=int(input())\r\nfor _ in range(x):\r\n a,b=input().split()\r\n a=int(a)\r\n b=int(b)\r\n z=a%b\r\n print(z)", "\nn=int(input())\nfor _ in range(n):\n a,b=[int(x) for x in input().split( )]\n print(a%b)", "t = int(input())\r\nmod = []\r\nfor i in range (0,t):\r\n a,b = input().split()\r\n c=int(a)%int(b)\r\n mod.append(c)\r\nfor i in mod:\r\n print(i)", "t=int(input())\nfor i in range(t):\n a,b=input().split()\n a=int(a)\n b=int(b)\n ans=a%b\n print(ans)\n", "t=int(input())\nfor i in range(0,t):\n x,y=map(int,input().split())\n c=x%y\n print(c)", "n = int(input())\nwhile n>0:\n x,y = map(int,input().strip().split())\n print(x%y)\n n = n-1", "n= int (eval(input()))\nfor i in range (0,n):\n a,b=list(map(int,input().split()))\n r=a%b\n print(r)", "n=int(input())\r\nfor i in range(n):\r\n a, b = map(int, input().split())\r\n c=a%b\r\n print(c)", "#No template exists for this language. Erase this and please write full code.\nn=int(input())\nfor i in range (n):\n a,b=map(int,input().split())\n c=a%b\n print(c)", "for _ in range(int(input())):\r\n n,k=map(int,input().split())\r\n print(n%k)", "n=int(input())\r\nmylist=[]\r\nwhile(n>0):\r\n\ta,b=list(map(int,input().split()))\r\n\trem=a%b\r\n\tmylist.append(rem)\r\n\tn=n-1\r\nfor i in mylist:\r\n\tprint(i)\r\n\t\r\n\t\t\r\n\r\n\t\t\r\n\t\t\r\n\r\n\t\r\n\t\r\n\t\t\r\n\t\t\r\n", "# No template exists for this language. Erase this and please write full code.\nt = int(input())\nwhile t:\n t-=1\n n, m = map(int, input().split())\n print(n%m)", "n= int(input())\nfor i in range(n):\n a,b= map(int,input().split())\n c=a%b\n print(c)", "n = int(input())\ni =1\nwhile i<=n:\n (a,b) = [int(x)for x in input().split()]\n print(a%b)\n \n i+=1 \n", "t=int(input())\nfor i in range(0,t):\n a,b=map(int,input().split(' '))\n print(a%b)", "t=int(input())\nfor i in range(t):\n \n a,b=[int(x) for x in input().split()]\n c=a%b\n print(c)\n", "for _ in range(int(input())):\n n,m=map(int,input().split())\n print(n%m)", "t=int(input())\n\nfor i in range(t):\n (a,b)=map(int,input().split(' '))\n print(a%b)", "t = int(input())\r\nfor i in range(t):\r\n c , d = input().split()\r\n a = int (c) \r\n b = int (d)\r\n print(a%b)\r\n", "n = int(input())\nfor i in range(n):\n (a, b) = map(int, input().split(\" \"))\n print(a % b)", "n = int(input())\nfor i in range(n):\n (a, b) = map(int, input().split(\" \"))\n print(a % b)", "t=int(input())\nfor i in range(t):\n a,b=map(int,input().split())\n print(a%b)"]
{"inputs": [["3", "1 2", "100 200", "40 15"]], "outputs": [["1", "100", "10"]]}
INTERVIEW
PYTHON3
CODECHEF
3,024
68180e9ff60e4f6f8fcb9f27d0415a9a
UNKNOWN
Chef Ciel wants to put a fancy neon signboard over the entrance of her restaurant. She has not enough money to buy the new one so she bought some old neon signboard through the internet. Ciel was quite disappointed when she received her order - some of its letters were broken. But she realized that this is even better - she could replace each broken letter by any letter she wants. So she decided to do such a replacement that the resulting signboard will contain the word "CHEF" as many times as possible. We can model the signboard as a string S having capital letters from 'A' to 'Z', inclusive, and question marks '?'. Letters in the string indicate the intact letters at the signboard, while question marks indicate broken letters. So Ciel will replace each question mark with some capital letter and her goal is to get the string that contains as many substrings equal to "CHEF" as possible. If there exist several such strings, she will choose the lexicographically smallest one. Note 1. The string S = S1...SN has the substring "CHEF" if for some i we have SiSi+1Si+2Si+3 = "CHEF". The number of times "CHEF" is the substring of S is the number of those i for which SiSi+1Si+2Si+3 = "CHEF". Note 2. The string A = A1...AN is called lexicographically smaller than the string B = B1...BN if there exists K from 1 to N, inclusive, such that Ai = Bi for i = 1, ..., K-1, and AK < BK. In particular, A is lexicographically smaller than B if A1 < B1. We compare capital letters by their positions in the English alphabet. So 'A' is the smallest letter, 'B' is the second smallest letter, ..., 'Z' is the largest letter. -----Input----- The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows. The only line of each test case contains a string S. -----Output----- For each test case, output a single line containing the content of the signboard Chef Ciel will come up with. That is you should output the lexicographically smallest string that could be obtained from the input string by replacing all its question marks by some capital letters and having as many substrings equal to "CHEF" as possible. -----Constraints----- - 1 ≤ T ≤ 2013 - 1 ≤ length of S ≤ 2013 - Each character in S is either a capital letter from 'A' to 'Z', inclusive, or the question mark '?'. -----Example----- Input: 5 ????CIELIS???E? ????CIELISOUR???F T?KEITE?SY ???????? ???C??? Output: CHEFCIELISACHEF CHEFCIELISOURCHEF TAKEITEASY CHEFCHEF AAACHEF -----Explanation ----- Example Case 1. Here the resulting string can have at most 2 substrings equal to "CHEF". For example, some possible such strings are: - CHEFCIELISACHEF - CHEFCIELISQCHEF - CHEFCIELISZCHEF However, lexicographically smallest one is the first one. Example Case 3. Here the resulting string cannot have "CHEF" as its substring. Therefore, you must simply output the lexicographically smallest string that can be obtained from the given one by replacing question marks with capital letters.
["from math import gcd\nimport sys\ninput=lambda : sys.stdin.readline().strip()\nc=lambda x: 10**9 if(x==\"?\") else int(x)\ndef main():\n for _ in range(int(input())):\n s=list(input())[::-1]\n l=['F','E','H','C']\n i=0\n while(i<len(s)):\n if(i+3<len(s)):\n f=True\n for j in range(i,i+4):\n if(l[j-i]==s[j] or s[j]=='?'):\n pass\n else:\n f=False\n break\n if(f):\n for j in range(i,i+4):\n s[j]=l[j-i]\n if(s[i]==\"?\"):\n s[i]='A'\n else:\n if(s[i]==\"?\"):\n s[i]=\"A\"\n i+=1\n print(*s[::-1],sep='')\n\n \n\nmain()", "# cook your dish here\nt=int(input())\nfor _ in range(t):\n s=input()\n if len(s)<4:\n for i in range(len(s)):\n if s[i]=='?':\n s=s[:i]+'A'+s[i+1:]\n else:\n \n for i in range(len(s)-1,-1,-1):\n x=s[i-3:i+1]\n \n # print(x)\n xx='CHEF'\n for j in range(len(x)):\n if x[j]=='?':\n x=x[:j]+xx[j]+x[j+1:]\n \n if x=='CHEF':\n s=s[:i-3]+'CHEF'+s[i+1:]\n for i in range(len(s)):\n if s[i]=='?':\n s=s[:i]+'A'+s[i+1:]\n print(s)\n # print()\n", "# cook your dish here\nfor i in range(int(input())):\n s = list(input())\n for i in range(len(s)-4,-1,-1):\n c = 0\n if s[i] == \"?\":\n c+=1\n else:\n if s[i] == \"C\":\n c+=1\n else:\n continue\n \n if s[i+1] == \"?\":\n c+=1\n else:\n if s[i+1] == \"H\":\n c+=1\n else:\n continue\n \n if s[i+2] == \"?\":\n c+=1\n else:\n if s[i+2] == \"E\":\n c+=1\n else:\n continue\n \n if s[i+3] == \"?\":\n c+=1\n else:\n if s[i+3] == \"F\":\n c+=1\n else:\n continue\n if c == 4:\n s[i] = \"C\"\n s[i+1] = \"H\"\n s[i+2] = \"E\"\n s[i+3] = \"F\"\n for j in range(len(s)-1,-1,-1):\n if s[j] == \"?\":\n s[j] = \"A\"\n print(*s,sep=\"\")\n", "def isPossible(l):\n if ((l[0]=='C' or l[0]=='?') and (l[1]=='H' or l[1]=='?')\n and (l[2]=='E' or l[2]=='?') and (l[3]=='F' or l[3]=='?')):\n return True\n else:\n return False\n\n\nT = int(input())\nans = []\n\nfor _ in range(T):\n S = list(input())\n\n N = len(S)\n for i in range(N-1,2,-1):\n if(isPossible(S[i-3:i+1])):\n S[i] = 'F'\n S[i-1] = 'E'\n S[i-2] = 'H'\n S[i-3] = 'C'\n for i in range(N):\n if(S[i]=='?'):\n S[i] = 'A'\n\n s = ''\n for i in S:\n s += i\n ans.append(s)\n\nfor i in ans:\n print(i)", "t = int(input())\nfor T in range(t):\n l = list(input())\n\n ind = len(l)\n ans = 0\n while(ind > 3):\n val = l[ind - 4: ind]\n \n if val.count('?') == 0:\n ind -= 1\n continue\n \n s1 = ''.join(val)\n if s1 == 'CHEF':\n ind -= 4\n continue\n\n flag = 0\n if val.count('?') > 0:\n if val[0] != '?' and val[0] != 'C':\n flag = -1\n if val[0 + 1] != '?' and val[0 + 1] != 'H':\n flag = -1\n if val[0 + 2] != '?' and val[0 + 2] != 'E':\n flag = -1\n if val[0 + 3] != '?' and val[0 + 3] != 'F':\n flag = -1\n\n if flag == 0:\n l[ind - 4] = 'C'\n l[ind - 3] = 'H'\n l[ind - 2] = 'E'\n l[ind - 1] = 'F'\n ind -= 4\n continue\n\n \n ind -= 1\n \n n_string = ''.join(l)\n n_string = n_string.replace('?', 'A')\n print(n_string)\n", "# cook your dish here\ndef replace_if_possible(i):\n nonlocal string\n if (string[i] != '?' and string[i] != 'C') or \\\n (string[i+1] != '?' and string[i+1] != 'H') or \\\n (string[i+2] != '?' and string[i+2] != 'E') or \\\n (string[i+3] != '?' and string[i+3] != 'F'):\n return\n \n string[i:i+4] = 'CHEF'\n\n\nt = int(input())\nfor _ in range(t):\n string = list(input())\n \n i = len(string) - 4\n while i >= 0:\n replace_if_possible(i)\n i -= 1\n \n for i in range(len(string)):\n if string[i] == '?':\n string[i] = 'A'\n \n print(\"\".join(string))", "# cook your dish here\ndef check(arr):\n dic={0:'C',1:'H',2:'E',3:'F'}\n for i in range(4):\n if arr[i] != '?':\n if arr[i]!=dic[i]:\n return -1\n for i in range(4):\n if arr[i]=='?':\n arr[i]=dic[i]\n return arr\n\nt=int(input())\nfor _ in range(t):\n arr=input()\n arr=list(arr)\n i=len(arr)\n \n if i<4:\n for k in range(i):\n if arr[k]=='?':\n arr[k]='A'\n \n \n while i>3:\n if '?' in arr[i-4:i]:\n if check(arr[i-4:i])==-1:\n i-=1\n continue\n else:\n arr[i-4:i]=check(arr[i-4:i])\n i-=3\n i-=1\n for k in range(len(arr)):\n if arr[k]=='?':\n arr[k]='A'\n \n \n res=''\n for ele in arr:\n res+=ele\n print(res)\n \n \n\n \n \n \n \n \n", "# cook your dish here\npossiblity ={'?EHC','??H?','?E??','?EH?','F?H?','???C','?E?C','FE?C',\n 'F???','FE??','????','FEH?','??HC','F??C','F?HC'}\nfor _ in range(int(input())):\n st =input()\n st =st[::-1]\n ln =len(st)\n ans =['0']*ln\n i = ln-1\n i =0\n while i+3<ln:\n if st[i:i+4] in possiblity:\n ans[i:i+4] = ['F','E','H','C']\n i += 4\n else:\n ans[i] = st[i]\n i +=1\n if i<len(st):\n ans[i:] = st[i:]\n for i in range(ln):\n if ans[i] == '?':\n ans[i] = 'A'\n print(*ans[::-1],sep='')"]
{"inputs": [["5", "????CIELIS???E?", "????CIELISOUR???F", "T?KEITE?SY", "????????", "???C???"]], "outputs": [["CHEFCIELISACHEF", "CHEFCIELISOURCHEF", "TAKEITEASY", "CHEFCHEF", "AAACHEF"]]}
INTERVIEW
PYTHON3
CODECHEF
4,861
f8886d269ab5b54a612ef45a8990d528
UNKNOWN
Chefland is a grid with N$N$ rows and M$M$ columns. Each cell of this grid is either empty or contains a house. The distance between a pair of houses is the Manhattan distance between the cells containing them. For each d$d$ between 1$1$ and N+M−2$N+M-2$ inclusive, Chef wants to calculate the number of unordered pairs of distinct houses with distance equal to d$d$. Please help him! -----Input----- - The first line of the input contains a single integer T$T$ denoting the number of test cases. The description of T$T$ test cases follows. - The first line of each test case contains two space-separated integers N$N$ and M$M$. - N$N$ lines follow. For each i$i$ (1≤i≤N$1 \le i \le N$), the i$i$-th of these lines contains a binary string with length M$M$; for each j$j$ (1≤j≤M$1 \le j \le M$), the j$j$-th character of this string is '1' if the cell in the i$i$-th row and j$j$-th column contains a house or '0' if it is empty. -----Output----- For each test case, print a single line containing N+M−2$N+M-2$ space-separated integers. For each valid i$i$, the i$i$-th integer should denote the number of pairs with distance i$i$. -----Constraints----- - 1≤T≤3$1 \le T \le 3$ - 2≤N,M≤300$2 \le N, M \le 300$ -----Subtasks----- Subtask #1 (50 points): N,M≤50$N, M \le 50$ Subtask #2 (50 points): original constraints -----Example Input----- 1 3 4 0011 0000 0100 -----Example Output----- 1 0 1 1 0
["# cook your dish here\nfor a in range(int(input())):\n N,M=map(int,input().split())\n b=[]\n for o in range(N):\n b.append(input())\n c=[]\n for d in b:\n f=[]\n for e in range(len(d)):\n if d[e]=='1':\n f.append(e)\n c.append(f)\n i=[]\n for g in range(len(c)):\n for h in range(len(c[g])):\n for j in range(len(c)):\n for k in range(len(c[j])):\n if (j>g) or(j==g and k>h):\n if c[g][h]-c[j][k]>=0:\n i.append(c[g][h]-c[j][k]+j-g)\n else:\n i.append(-1*(c[g][h]-c[j][k])+j-g)\n l=[m for m in range(1,N+M-1)]\n for n in l:\n print(i.count(n),end=' ')", "for a in range(int(input())):\n N,M=map(int,input().split())\n b=[]\n for o in range(N):\n b.append(input())\n c=[]\n for d in b:\n f=[]\n for e in range(len(d)):\n if d[e]=='1':\n f.append(e)\n c.append(f)\n i=[]\n for g in range(len(c)):\n for h in range(len(c[g])):\n for j in range(len(c)):\n for k in range(len(c[j])):\n if (j>g) or(j==g and k>h):\n if c[g][h]-c[j][k]>=0:\n i.append(c[g][h]-c[j][k]+j-g)\n else:\n i.append(-1*(c[g][h]-c[j][k])+j-g)\n l=[m for m in range(1,N+M-1)]\n for n in l:\n print(i.count(n),end=' ')\n ", "for _ in range(int(input())):\n mat=[]\n n,m=map(int,input().split())\n for i in range(n):\n mat.append(list(input()))\n d=[0]*(n+m)\n for i in range(n):\n for j in range(m):\n if mat[i][j]=='1':\n for x in range(n):\n for y in range(m):\n if mat[x][y]=='1':\n d[abs(x-i)+abs(y-j)]+=1 \n for i in range(1,n+m-1):\n print(d[i]//2,end=' ')", "from math import *\nt=int(input())\nfor _ in range(t):\n n,m=map(int,input().split())\n a=[]\n for i in range(n):\n a.append(input())\n \n l=[]\n for i in range(n):\n for j in range(m):\n if(a[i][j]=='1'):\n l.append((i,j))\n d={}\n for i in range(1,n+m-2+1):\n d[i]=0\n for i in range(len(l)):\n for j in range(i+1,len(l)):\n dis=abs(l[i][0]-l[j][0])+abs(l[i][1]-l[j][1])\n d[dis]+=1\n for i in range(1,n+m-2+1):\n print(d[i],end=' ')\n ", "from itertools import combinations\nfrom scipy.spatial.distance import pdist\nimport numpy as np\n\ndef solve():\n houses = []\n n,m = list(map(int, input().split()))\n \n for i in range(n):\n s = input()\n tmp = [i for i,x in enumerate(s) if x =='1']\n houses = houses + [[i,j] for j in tmp]\n \n counter = [0]* (n+m-1)\n dis = pdist(np.array(houses),'cityblock').astype(int)\n \n for i in dis:\n counter[i] += 1\n return [counter[i] for i in range(1,n+m-1)]\n\nfor _ in range(int(input())):\n print(*solve())", "from itertools import combinations\nfrom scipy.spatial.distance import pdist\nimport numpy as np\n\ndef solve():\n houses = []\n n,m = list(map(int, input().split()))\n \n for i in range(n):\n s = input()\n tmp = [i for i,x in enumerate(s) if x =='1']\n houses = houses + [[i,j] for j in tmp]\n \n counter = [0]* (n+m-1)\n dis = pdist(np.array(houses),'cityblock').astype(int)\n \n for i in dis:\n counter[i] += 1\n return [counter[i] for i in range(1,n+m-1)]\n\nfor _ in range(int(input())):\n print(*solve())", "from collections import defaultdict\nfrom itertools import combinations\nfrom scipy.spatial.distance import pdist\n\ndef solve():\n houses = []\n n,m = list(map(int, input().split()))\n \n for i in range(n):\n s = input()\n tmp = [i for i,x in enumerate(s) if x =='1']\n houses = houses + [(i,j) for j in tmp]\n \n counter = defaultdict(int)\n dis = pdist(houses,'cityblock')\n for i in dis:\n counter[i] += 1\n return [counter[i] for i in range(1,n+m-1)]\n\nfor _ in range(int(input())):\n print(*solve())", "t = int(input())\nfor _ in range(t):\n n,m = map(int,input().split())\n l = []\n for i in range(n):\n l.append(input())\n li=[]\n for i in range(n):\n for j in range(m):\n if(l[i][j]=='1'):\n li.append((i+1,j+1))\n di = [0 for i in range(n+m-2)]\n for x in range(len(li)):\n for y in li[x+1:]:\n z = li[x]\n distance = abs(z[0]-y[0])+abs(z[1]-y[1])\n di[distance-1]=di[distance-1]+1\n for x in di:\n print(x,end=' ')\n print()\n", "from collections import defaultdict\nfrom itertools import combinations\n\ndef norm(a, b):\n return abs(a[0]-b[0]) + abs(a[1]-b[1])\n\ndef solve():\n houses = []\n n,m = list(map(int, input().split()))\n \n for i in range(n):\n s = input()\n tmp = [i for i,x in enumerate(s) if x =='1']\n houses = houses + [(i,j) for j in tmp]\n \n counter = defaultdict(int)\n for a,b in combinations(houses,2):\n counter[norm(a,b)] += 1\n return [counter[i] for i in range(1,n+m-1)]\n\nfor _ in range(int(input())):\n print(*solve())", "class Point(object):\n def __init__(self,x,y):\n self.x,self.y = x,y\n def distance(self,other):\n return abs(self.x-other.x)+abs(self.y-other.y)\n\nfor _ in range(int(input())):\n n,m = map(int,input().split())\n l,dist = [],[0]*(n+m-1)\n for i in range(n):\n c = input()\n for j in range(m):\n if c[j] == '1':\n l.append(Point(i,j))\n\n for i in range(len(l)):\n for j in range(i+1,len(l)):\n dist[l[i].distance(l[j] )]+=1\n\n dist.pop(0)\n for i in dist:\n print(i,end=' ')\n print()\n \n", "from itertools import combinations\nclass Point(object):\n def __init__(self,x,y):\n self.x,self.y = x,y\n def distance(self,other):\n return abs(self.x-other.x)+abs(self.y-other.y)\n\nfor _ in range(int(input())):\n n,m = map(int,input().split())\n l,dist = [],[0]*(n+m-1)\n for i in range(n):\n c = input()\n for j in range(m):\n if c[j] == '1':\n l.append(Point(i,j))\n\n total = 0\n \n for i in combinations(l,2):\n dist[i[0].distance(i[1])]+=1\n\n dist.pop(0)\n for i in dist:\n print(i,end=' ')\n print()\n ", "T=int(input()) \nfor i in range(T):\n l=list(map(int,input().split()))\n n,m=l[0],l[1]\n z=[]\n distance=[0]*(m+n-1)\n for i in range(n):\n arr=list(map(int,input()))\n for j,v in enumerate(arr):\n if v:\n z.append((i,j))\n for pt in z:\n d=abs(pt[0]-i)+abs(pt[1]-j)\n distance[d]+=1\n \n \n print(*distance[1:])\n", "T=int(input())\n\n \ndef dist(z,i,j):\n return abs(z[i][0]-z[j][0])+abs(z[i][1]-z[j][1])\n \nfor i in range(T):\n l=list(map(int,input().split()))\n n,m=l[0],l[1]\n grd=[list(map(int,input())) for i in range(n)]\n z=[]\n for i,r in enumerate(grd):\n for j,v in enumerate(r):\n if v:\n z.append((i,j))\n \n distance=[0]*(n+m-2)\n for i in range(len(z)):\n for j in range(i+1,len(z)):\n d=dist(z,i,j)\n distance[d-1]+=1\n \n \n \n print(*distance)\n"]
{"inputs": [["1", "3 4", "0011", "0000", "0100"]], "outputs": [["1 0 1 1 0"]]}
INTERVIEW
PYTHON3
CODECHEF
7,007
43ce4a02554d8d0837cafa1654bdaed5
UNKNOWN
----- CHEF N TIMINGS ----- One day chef was working with some random numbers. Then he found something interesting. He observed that no 240, 567, 9999 and 122 and called these numbers nice as the digits in numbers are in increasing order. Also he called 434, 452, 900 are not nice as digits are in decreasing order Now you are given a no and chef wants you to find out largest "nice" integer which is smaller than or equal to the given integer. -----Constraints----- 1< t < 1000 1< N < 10^18 -----Input Format----- First line contains no. of test cases t. Then t test cases follow. Each test case contain a integer n. -----Output----- Output a integer for each test case in a new line which is largest nice integer smaller or equal to the given integer. -----Example Text Case----- Input: 1 132 Output: 129
["for _ in range(int(input())):\n n=input().rstrip()\n n=[ele for ele in n]\n l=len(n)\n m=10**18+8\n ini=1\n for i in range(l-1,-1,-1):\n if int(n[i])<=m:\n if ini==1:\n m=int(n[i])\n else:\n m=max(m,n[i])\n else:\n m=int(n[i])-1\n n[i]=str(m)\n for j in range(l-1,i,-1):\n n[j]='9'\n \n i=0\n while n[i]=='0':\n i+=1\n print(\"\".join(n[i:]))\n \n", "for _ in range(int(input())):\n num = int(input())\n if num < 10:\n print(num)\n continue\n digs = str(num)\n new = \"\"\n i = 1\n bad = False\n while i < len(digs):\n if digs[i-1] > digs[i]:\n bad = True\n if digs[i-1] != \"1\":\n new += str(int(digs[i-1]) - 1) + \"9\"*(len(digs)-i)\n else:\n n = i-1\n while n > 0 and digs[n] == \"1\":\n n -= 1\n new = new[:n]\n new += str(int(digs[n]) - 1) + \"9\"*(len(digs)-n-1)\n break\n else:\n new += digs[i - 1]\n i += 1\n if not bad: new = digs\n print(int(new))\n", "t=int(input())\nfor _ in range(t):\n n=int(input())\n c=str(n)\n a=list(c)\n i2=len(a)-1\n for i in range(len(a)-1,0,-1):\n if int(a[i])<int(a[i-1]):\n a[i-1]=int(a[i-1])-1\n i2=i-1\n if(a[0]!=0 and a[0]!=\"0\"):\n for i in range(i2+1):\n print(a[i],end=\"\")\n for i in range(i2+1,len(a)):\n print(9,end=\"\")\n else:\n for i in range(1,i2):\n print(a[i],end=\"\")\n for i in range(i2+1,len(a)):\n print(9,end=\"\")\n print()\n \n \n", "# cook your dish here\ntry:\n def increasing(n):\n if 0 <= n<= 9: return n\n def fi(s):\n for i in range(len(s)-1):\n if s[i] > s[i+1]:\n return i\n return -1 \n s = str(n)\n n = len(s)\n r = fi(s)\n l = s.index(s[r])\n if r == -1:\n return n\n else:\n return int(s[:l] + str(int(s[l]) - 1) + '9'*(n-l-1))\n for _ in range(int(input())):\n n=int(input())\n ans=increasing(n)\n print(ans)\nexcept EOFError as e: \n pass\n", "from sys import stdin, stdout\ninput = stdin.readline\nfrom collections import defaultdict as dd\nimport math\ndef geti(): return list(map(int, input().strip().split()))\ndef getl(): return list(map(int, input().strip().split()))\ndef gets(): return input()\ndef geta(): return int(input())\ndef print_s(s): stdout.write(s+'\\n')\n\ndef solve():\n for _ in range(geta()):\n n=geta()\n num=list(map(int,list(str(n))))\n # print(num)\n index=-1\n for i in range(len(num)-1):\n if num[i]>num[i+1]:\n index=i\n break\n else:\n print(n)\n continue\n if index!=-1:\n fake=num[index]\n for i in range(index,-1,-1):\n if num[i]==fake:\n num[i]-=1\n last=i\n for i in range(last+1,len(num)):\n num[i]=9\n ans=0\n for i in num:\n ans*=10\n ans+=i\n print(ans)\n\n\ndef __starting_point():\n solve()\n\n__starting_point()", "# cook your dish here\nimport sys\ndef func(number):\n for i in range(len(number)-1):\n if int(number[i])>int(number[i+1]):\n cifra=int(number[i])-1\n stringa=number[:i]+str(cifra)+'9'*(len(number)-i-1)\n return func(stringa)\n return number\nt=int(input().strip())\nfor _ in range(t):\n number=input().strip()\n stringa=func(number)\n while stringa[0]=='0':\n stringa=stringa[1:]\n print(stringa)", "def nondecdigits(s):\n m = len(s); \n a = [0] * m; \n for i in range(m):\n a[i] = ord(s[i]) - ord('0'); \n level = m - 1;\n for i in range(m - 1, 0, -1):\n if (a[i] < a[i - 1]):\n a[i - 1] -= 1;\n level = i - 1;\n if (a[0] != 0):\n for i in range(level + 1):\n print(a[i], end=\"\");\n for i in range(level + 1, m):\n print(\"9\", end=\"\");\n else:\n for i in range(1, level):\n print(a[i], end=\"\");\n for i in range(level + 1, m):\n print(\"9\", end=\"\");\nx=int(input())\nfor i in range(x):\n y=int(input())\n nondecdigits(str(y))\n print()", "def check(s):\n for i in range(len(s)-1):\n if int(s[i+1])<int(s[i]):\n return 1\n return 0\n\nt=int(input())\nfor i in range(t):\n ok=0\n n=list(input())\n l=[]\n for k in n:\n try:\n l.append(int(k))\n except:\n pass\n while(check(l)):\n for j in range(len(l)-1):\n if l[j+1]<l[j]:\n l[j]=l[j]-1\n for k in range(j+1,len(l)):\n l[k]=9\n break\n s=''\n for i in l:\n s+=str(i)\n print(int(s))", "\nT = int(input())\ndef solve(n):\n li = list(map(int, list(str(n))))\n prev = 0\n f = {}\n for ind, it in enumerate(li):\n if it < prev:\n ind = f[prev]\n li[ind]-=1\n for j in range(ind+1, len(li)):\n li[j] = 9\n break\n prev = it\n if it not in f:\n f[it] = ind\n\n ans = 0\n for it in li:\n ans = 10*ans + it\n\n return ans\n\nfor case in range(T):\n n = int(input())\n ans = solve(n)\n print(ans)\n", "# cook your dish here\ndef check(n):\n l=list(map(int,str(n)))\n t=len(l)\n p=t-1\n for i in range(t-1,0,-1):\n if l[i]<l[i-1]:\n l[i-1]-=1 \n p=i-1\n \n for i in range(p+1,t):\n l[i]=9\n return int(''.join(map(str,l))) \n \ntry:\n for _ in range(int(input())):\n n=int(input())\n print(check(n))\nexcept EOFError as e:pass ", "# cook your dish here\ndef check(n):\n l=list(map(int,str(n)))\n t=len(l)\n p=t-1\n for i in range(t-1,0,-1):\n if l[i]<l[i-1]:\n l[i-1]-=1 \n p=i-1\n \n for i in range(p+1,t):\n l[i]=9\n return int(''.join(map(str,l))) \n \ntry:\n for _ in range(int(input())):\n n=int(input())\n print(check(n))\nexcept EOFError as e:pass ", "# cook your dish here\ndef check(n):\n l=list(map(int,str(n)))\n t=len(l)\n p=t-1\n for i in range(t-1,0,-1):\n if l[i]<l[i-1]:\n l[i-1]-=1 \n p=i-1\n \n for i in range(p+1,t):\n l[i]=9\n return int(''.join(map(str,l))) \n \ntry:\n for _ in range(int(input())):\n n=int(input())\n print(check(n))\nexcept EOFError as e:pass ", "\nT=int(input())\nfor _ in range(T):\n N=int(input())\n V=list(str(N))\n #fa=ckt(N)\n ans=\"\"\n n=len(V)\n for i in range(n):\n if (i!=(n-1) and V[i]>V[i+1]):\n ans=list(ans+str(int(V[i])-1)+(\"9\")*(n-i-1))\n for j in range(i-1,-1,-1):\n if (ans[j]>ans[j+1]):\n ans[j+1]=\"9\"\n ans[j]=str(int(ans[j])-1)\n else:\n break\n break\n else:\n ans=ans+V[i]\n\n ans1=\"\"\n for i in ans:\n ans1=ans1+i\n \n print(int(ans1))\n", "# cook your dish here\ntry:\n def convert(list): \n s = [str(i) for i in list] \n res = int(\"\".join(s)) \n return(res) \n for _ in range(int(input())):\n x=int(input())\n while x>0:\n a=str(x)\n b=list(a)\n b.sort()\n if b==list(a):\n break\n else:\n k=0\n for j in b:\n if str(j)==a[k]:\n k+=1\n else:\n break\n k=convert(list(a[k+1:])) \n x=x-k-1\n print(x)\nexcept:\n pass", "# cook your dish here\ndef num(l):\n ans=0\n for i in range(len(l)):\n ans=ans*10+l[i]\n return ans\ndef numof(n):\n ans=0\n l=[]\n while(n>0):\n l.append(n%10)\n n=n//10\n ans+=1\n l.reverse()\n return l\nt=int(input())\nfor you in range(t):\n n=int(input())\n done=0\n z=numof(n)\n l=[]\n for i in range(len(z)):\n if(min(z[i:])==z[i]):\n l.append(z[i])\n else:\n l.append(min(z[i:]))\n done=1\n break\n k=len(l)\n for i in range(len(z)-k):\n l.append(9)\n print(num(l))"]
{"inputs": [["1", "132"]], "outputs": [["129"]]}
INTERVIEW
PYTHON3
CODECHEF
6,912
f6a244710e5f055a262ef8ab6c096af9
UNKNOWN
Chef has a strip of length $N$ units and he wants to tile it using $4$ kind of tiles -A Red tile of $2$ unit length -A Red tile of $1$ unit length -A Blue tile of $2$ unit length -A Blue tile of $1$ unit length Chef is having an infinite supply of each of these tiles. He wants to find out the number of ways in which he can tile the strip. Help him find this number. Since this number can be large, output your answer modulo 1000000007 ($10^9 + 7$). -----Input:----- - First line will contain $T$, number of testcases. Then the testcases follow. - Each testcase contains of a single line of input, an integer $N$. -----Output:----- For each testcase, output in a single line your answer modulo 1000000007. -----Constraints----- - $1 \leq T \leq 1000$ - $2 \leq N \leq 10^{18}$ -----Sample Input:----- 1 2 -----Sample Output:----- 6 -----EXPLANATION:----- It can be seen that for a strip of length $2$, there are $6$ possible configurations. $NOTE : $ 2 tiles of 1 unit length are different from 1 tile of 2 unit length.
["# Fibonacci Series using \r\n# Optimized Method \r\n\r\n# function that returns nth \r\n# Fibonacci number\r\nMOD = 1000000007\r\ndef fib(n):\r\n F = [[2, 2],\r\n [1, 0]]\r\n power(F, n - 1)\r\n ans = [6, 2]\r\n return (F[0][0] * 6 + F[0][1] * 2) % MOD\r\n # return F[0][0]\r\n\r\n\r\ndef multiply(F, M):\r\n x = (F[0][0] * M[0][0] +\r\n F[0][1] * M[1][0]) % MOD\r\n y = (F[0][0] * M[0][1] +\r\n F[0][1] * M[1][1]) % MOD\r\n z = (F[1][0] * M[0][0] +\r\n F[1][1] * M[1][0]) % MOD\r\n w = (F[1][0] * M[0][1] +\r\n F[1][1] * M[1][1]) % MOD\r\n\r\n F[0][0] = x\r\n F[0][1] = y\r\n F[1][0] = z\r\n F[1][1] = w\r\n\r\n\r\ndef power(F, n):\r\n if n == 0 or n == 1:\r\n return\r\n M = [[2, 2],\r\n [1, 0]]\r\n\r\n power(F, n // 2)\r\n multiply(F, F)\r\n\r\n if n % 2 != 0:\r\n multiply(F, M)\r\n\r\n\r\nfor _ in range(int(input())):\r\n n = int(input())\r\n ans = 1\r\n if n == 0:\r\n ans = 1\r\n elif n == 1:\r\n ans = 2\r\n elif n == 2:\r\n ans = 6\r\n else:\r\n ans = fib(n-1)\r\n print(ans)\r\n", "from typing import List\r\nMatrix = List[List[int]]\r\n\r\nMOD = 10 ** 9 + 7\r\n\r\n\r\ndef identity(n: int) -> Matrix:\r\n matrix = [[0] * n for _ in range(n)]\r\n\r\n for i in range(n):\r\n matrix[i][i] = 1\r\n\r\n return matrix\r\n\r\n\r\ndef multiply(mat1: Matrix, mat2: Matrix, copy: Matrix) -> None:\r\n r1, r2 = len(mat1), len(mat2)\r\n c1, c2 = len(mat1[0]), len(mat2[0])\r\n\r\n result = [[0] * c2 for _ in range(r1)]\r\n\r\n for i in range(r1):\r\n for j in range(c2):\r\n for k in range(r2):\r\n result[i][j] = (result[i][j] + mat1[i][k] * mat2[k][j]) % MOD\r\n\r\n for i in range(r1):\r\n for j in range(c2):\r\n copy[i][j] = result[i][j]\r\n\r\n\r\ndef power(mat: Matrix, n: int) -> Matrix:\r\n res = identity(len(mat))\r\n\r\n while n:\r\n if n & 1:\r\n multiply(res, mat, res)\r\n\r\n multiply(mat, mat, mat)\r\n\r\n n >>= 1\r\n\r\n return res\r\n\r\n\r\ndef fib(n: int) -> int:\r\n if n == 0:\r\n return 0\r\n\r\n magic = [[2, 1],\r\n [2, 0]]\r\n\r\n mat = power(magic, n)\r\n\r\n return mat[0][0]\r\n\r\nfor _ in range(int(input())):\r\n n = int(input())\r\n\r\n print(fib(n) % MOD)\r\n"]
{"inputs": [["1", "2"]], "outputs": [["6"]]}
INTERVIEW
PYTHON3
CODECHEF
2,426
930604e6855a914984026f05ebac4952
UNKNOWN
Ada's classroom contains $N \cdot M$ tables distributed in a grid with $N$ rows and $M$ columns. Each table is occupied by exactly one student. Before starting the class, the teacher decided to shuffle the students a bit. After the shuffling, each table should be occupied by exactly one student again. In addition, each student should occupy a table that is adjacent to that student's original table, i.e. immediately to the left, right, top or bottom of that table. Is it possible for the students to shuffle while satisfying all conditions of the teacher? -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first and only line of each test case contains two space-separated integers $N$ and $M$. -----Output----- For each test case, print a single line containing the string "YES" if it is possible to satisfy the conditions of the teacher or "NO" otherwise (without quotes). -----Constraints----- - $1 \le T \le 5,000$ - $2 \le N, M \le 50$ -----Example Input----- 2 3 3 4 4 -----Example Output----- NO YES -----Explanation----- Example case 2: The arrows in the following image depict how the students moved.
["# cook your dish here\nt=int(input())\nfor _ in range(t):\n N, M=map(int,input().split())\n if(N%2==0 or M%2==0):\n print(\"YES\")\n else:\n print(\"NO\")", "# cook your dish here\nt=int(input())\nfor _ in range(t):\n N, M=map(int,input().split())\n if(N%2==0 or M%2==0):\n print(\"YES\")\n else:\n print(\"NO\")", "# cook your dish here\nt=int(input())\nfor i in range(t):\n a,b=map(int,input().split())\n if(a%2==0 or b%2==0):\n print(\"YES\")\n else:\n print(\"NO\")", "t=int(input())\nfor i in range(0,t):\n (a,b)=list(map(int,input().split()))\n if(a%2==0 or b%2==0):\n print(\"YES\")\n else:\n print(\"NO\")\n", "# cook your dish here\nfor _ in range(int(input())):\n n,m=map(int,input().split())\n if (n*m)%2==0:\n print(\"YES\")\n else:\n print(\"NO\")", "# cook your dish here\nn=int(input())\nfor i in range(0,n):\n (a,b)=list(map(int,input().split()))\n if(a%2==0 or b%2==0):\n print(\"YES\")\n else:\n print(\"NO\")", "for _ in range(int(input())):\n n, m = map(int, input().split())\n print(\"YES\") if n % 2 == 0 or m % 2 == 0 else print(\"NO\")", "for _ in range(int(input())):\n x,y=map(int,input().split())\n if(x%2==0 or y%2==0):\n print(\"YES\")\n else:\n print(\"NO\")", "# cook your dish here\nfor _ in range(int(input())):\n n,m=map(int,input().split())\n if(n%2==0 or m%2==0):\n print(\"YES\")\n else:\n print(\"NO\")", "# cook your dish here\nt=int(input())\nfor i in range(t):\n a,b=map(int,input().split())\n if((a*b)%2==0):\n print('YES')\n else:\n print('NO')", "# cook your dish here\nt=int(input())\nfor _ in range(t):\n x,y=map(int,input().split())\n if((x*y)%2==0):\n print('YES')\n else:\n print('NO')", "# cook your dish here\nx=int(input())\nfor i in range(x):\n a, b=map(int,input().split())\n if((a*b)%2==0):\n print('YES')\n else:\n print('NO')", "# cook your dish herefor _ in range(int(input())):\nfor _ in range(int(input())):\n x,y=list(map(int,input().split()))\n print(\"NO\" if x*y%2 else \"YES\")\n", "t=int(input())\nfor _ in range(t):\n x,y=list(map(int,input().split()))\n if((x*y)%2==0):\n print('YES')\n else:\n print('NO')\n\n", "# cook your dish here\nt=int(input())\nfor _ in range(t):\n a,b=list(map(int,input().split()))\n if((a*b)%2==0):\n print('YES')\n else:\n print('NO')\n", "# cook your dish here\nt=int(input())\nfor _ in range(t):\n a,b=list(map(int,input().split()))\n if((a*b)%2==0):\n print('YES')\n else:\n print('NO')\n", "# cook your dish here\nt=int(input())\nfor _ in range(t):\n a,b=map(int,input().split())\n if((a*b)%2==0):\n print('YES')\n else:\n print('NO')", "for i in range(int(input())):\n n , k = map(int,input().split())\n isproductsatisfied = (n * k % 2==0)\n print(\"YES\" if isproductsatisfied else \"NO\")", "for _ in range(int(input())):\n m,n=map(int,input().split())\n print(\"NO\" if m*n%2 else \"YES\")", "for _ in range(int(input())):\n m,n=map(int,input().split())\n print(\"NO\" if m*n%2 else \"YES\")", "import sys\n\ndef input(): return sys.stdin.readline().strip()\ndef iinput(): return int(input())\ndef rinput(): return map(int, sys.stdin.readline().strip().split()) \n#def get_list(): return list(map(int, sys.stdin.readline().strip().split())) \n\nfor _ in range(int(input())):\n \n a,b=rinput()\n if(a&1 and b&1):\n print('NO')\n else:\n print('YES')", "# cook your dish here\n\ndef isOdd(n):\n return True if n % 2 != 0 else False\n \ndef isPossible(a, b):\n return \"NO\" if isOdd(a) and isOdd(b) else \"YES\"\n\ndef __starting_point():\n t = int(input())\n for i in range(t):\n a, b = map(int, input().split())\n print(isPossible(a, b))\n__starting_point()", "t=int(input())\nfor i in range(t):\n n,m=map(int,input().split())\n if(n%2!=0 and m%2!=0):\n print(\"NO\")\n else:\n print(\"YES\")", "# cook your dish here\nfor _ in range(int(input())):\n n,m=map(int,input().split())\n if(n%2!=0 and m%2!=0):\n print(\"NO\")\n else:\n print(\"YES\")"]
{"inputs": [["2", "3 3", "4 4"]], "outputs": [["NO", "YES"]]}
INTERVIEW
PYTHON3
CODECHEF
3,904
9eaae41cbfc44551edfe21fe0799463e
UNKNOWN
Shivam is the youngest programmer in the world, he is just 12 years old. Shivam is learning programming and today he is writing his first program. Program is very simple, Given two integers A and B, write a program to add these two numbers. -----Input----- The first line contains an integer T, the total number of test cases. Then follow T lines, each line contains two Integers A and B. -----Output----- For each test case, add A and B and display it in a new line. -----Constraints----- - 1 ≤ T ≤ 1000 - 0 ≤ A,B ≤ 10000 -----Example----- Input 3 1 2 100 200 10 40 Output 3 300 50
["#Note that it's python3 Code. Here, we are using input() instead of raw_input().\n#You can check on your local machine the version of python by typing \"python --version\" in the terminal.\n\n#Read the number of test cases.\nT = int(input())\nfor tc in range(T):\n\t# Read integers a and b.\n\t(a, b) = list(map(int, input().split(' ')))\n\t\n\tans = a + b\n\tprint(ans)", "T = int(input())\r\nfor tc in range(T):\r\n\t(a, b) = map(int, input().split(' '))\r\n\tans = a + b\r\n\tprint(ans)", "\r\nT = int(input())\r\nfor tc in range(T):\r\n\t(a, b) = map(int, input().split(' '))\r\n\tans = a + b\r\n\tprint(ans)", "#Note that it's python3 Code. Here, we are using input() instead of raw_input().\n#You can check on your local machine the version of python by typing \"python --version\" in the terminal.\n\n#Read the number of test cases.\nT = int(input())\nfor tc in range(T):\n\t# Read integers a and b.\n\t(a, b) = list(map(int, input().split(' ')))\n\t\n\tans = a + b\n\tprint(ans)", "#Note that it's python3 Code. Here, we are using input() instead of raw_input().\n#You can check on your local machine the version of python by typing \"python --version\" in the terminal.\n\n#Read the number of test cases.\ntry:\n for tc in range(int(input())):\n\t # Read integers a and b.\n\t a, b = list(map(int, input().split(' ')))\n\t print(a + b)\nexcept:\n pass", "a=int(input(\"\"))\r\nA=[]\r\nfor m in range(a):\r\n x, y=[int(x) for x in input(\"\").split()]\r\n B=[x,y]\r\n A.append(B)\r\nfor m in range(a):\r\n print(A[m][0]+A[m][1])", "#Note that it's python3 Code. Here, we are using input() instead of raw_input().\n#You can check on your local machine the version of python by typing \"python --version\" in the terminal.\n\n#Read the number of test cases.\nT = int(input())\nfor tc in range(T):\n\t# Read integers a and b.\n\t(a, b) = list(map(int, input().split(' ')))\n\t\n\tans = a + b\n\tprint(ans)", "try:\n n=int(input())\n for i in range(n):\n x, y = [int(x) for x in input().split()] \n t=x+y\n print(t)\nexcept:\n pass", "#Note that it's python3 Code. Here, we are using input() instead of raw_input().\n#You can check on your local machine the version of python by typing \"python --version\" in the terminal.\n\n#Read the number of test cases.\nT = int(input())\nfor tc in range(T):\n\t# Read integers a and b.\n\t(a, b) = list(map(int, input().split(' ')))\n\t\n\tans = a + b\n\tprint(ans)", "n=int(input())\nfor i in range(n):\n x, y = [int(x) for x in input().split()] \n t=x+y\n print(t)", "#Note that it's python3 Code. Here, we are using input() instead of raw_input().\n#You can check on your local machine the version of python by typing \"python --version\" in the terminal.\n\n#Read the number of test cases.\nT = int(input())\nfor tc in range(T):\n\t# Read integers a and b.\n\t(a, b) = list(map(int, input().split(' ')))\n\t\n\tans = a + b\n\tprint(ans)", "t=input()\r\nsum = []\r\nfor i in range (0,int(t)):\r\n a,b = input().split()\r\n c=int(a) + int(b)\r\n sum.append(c)\r\nfor i in sum:\r\n print(i)", "t=int(input())\nfor tc in range(t):\n x,y=map(int,input().split())\n a=x+y\n print(a)", "#Note that it's python3 Code. Here, we are using input() instead of raw_input().\n#You can check on your local machine the version of python by typing \"python --version\" in the terminal.\n\n#Read the number of test cases.\nT = int(input())\nfor tc in range(T):\n\t# Read integers a and b.\n\t(a, b) = list(map(int, input().split(' ')))\n\t\n\tans = a + b\n\tprint(ans)", "T=int(input())\nfor i in range(T):\n a,b=list(map(int,input().split()))\n c=a+b\n print(c)\n", "T=int(input())\nfor i in range(T):\n a,b=list(map(int,input().split()))\n c=a+b\n print(c)\n", "T=int(input())\nfor i in range(T):\n a,b=list(map(int,input().split()))\n c=a+b\n print(c)\n", "T=int(input())\nfor i in range(T):\n a,b=list(map(int,input().split()))\n c=a+b\n print(c)\n", "#Note that it's python3 Code. Here, we are using input() instead of raw_input().\n#You can check on your local machine the version of python by typing \"python --version\" in the terminal.\n\n#Read the number of test cases.\nT = int(input())\nfor tc in range(T):\n\t# Read integers a and b.\n\t(a, b) = list(map(int, input().split(' ')))\n\t\n\tans = a + b\n\tprint(ans)\n\n\n\n\n\n\n\n\n\n\n\n\n", "#Note that it's python3 Code. Here, we are using input() instead of raw_input().\n#You can check on your local machine the version of python by typing \"python --version\" in the terminal.\n\n#Read the number of test cases.\nT = int(input())\nfor tc in range(T):\n\t# Read integers a and b.\n\t(a, b) = list(map(int, input().split(' ')))\n\t\n\tans = a + b\n\tprint(ans)\n\n\n\n\n\n\n\n\n\n\n\n\n", "#Note that it's python3 Code. Here, we are using input() instead of raw_input().\n#You can check on your local machine the version of python by typing \"python --version\" in the terminal.\n\n#Read the number of test cases.\ntry:\n T = int(input())\n for tc in range(T):\n \t# Read integers a and b.\n \t(a, b) = list(map(int, input().split(' ')))\n \t\n \tans = a + b\n \tprint(ans)\nexcept :\n print(\"s\")", "#Note that it's python3 Code. Here, we are using input() instead of raw_input().\n#You can check on your local machine the version of python by typing \"python --version\" in the terminal.\n\n#Read the number of test cases.\nT = int(input())\nfor tc in range(T):\n\t# Read integers a and b.\n\t(a, b) = list(map(int, input().split(' ')))\n\t\n\tans = a + b\n\tprint(ans)", "L = []\r\nl = []\r\n\r\nx = int(input())\r\nfor i in range(x):\r\n y = input()\r\n z = y.split()\r\n a = z[0]\r\n b = z[1]\r\n L.append(a)\r\n l.append(b)\r\nfor j in range(x):\r\n c = int(L[j])+ int(l[j])\r\n print(c)", "n= int(input())\nfor i in range(n):\n a,b= list(map(int,input().split()))\n c=a+b\n print(c)\n", "#Note that it's python3 Code. Here, we are using input() instead of raw_input().\n#You can check on your local machine the version of python by typing \"python --version\" in the terminal.\n\n#Read the number of test cases.\nT = int(input())\nfor tc in range(T):\n\t# Read integers a and b.\n\t(a, b) = list(map(int, input().split(' ')))\n\t\n\tans = a + b\n\tprint(ans)"]
{"inputs": [["3", "1 2", "100 200", "10 40"]], "outputs": [["3", "300", "50"]]}
INTERVIEW
PYTHON3
CODECHEF
6,310
1563aafc21ba6ecd2234f2dd4065d3ce
UNKNOWN
and Bengali as well. There are N$N$ cats (numbered 1$1$ through N$N$) and M$M$ rats (numbered 1$1$ through M$M$) on a line. Each cat and each rat wants to move from some point to some (possibly the same) point on this line. Naturally, the cats also want to eat the rats when they get a chance. Both the cats and the rats can only move with constant speed 1$1$. For each valid i$i$, the i$i$-th cat is initially sleeping at a point a_i$a_i$. At a time s_i$s_i$, this cat wakes up and starts moving to a final point b_i$b_i$ with constant velocity and without any detours (so it arrives at this point at the time e_i = s_i + |a_i-b_i|$e_i = s_i + |a_i-b_i|$). After it arrives at the point b_i$b_i$, it falls asleep again. For each valid i$i$, the i$i$-th rat is initially hiding at a point c_i$c_i$. At a time r_i$r_i$, this rat stops hiding and starts moving to a final point d_i$d_i$ in the same way as the cats ― with constant velocity and without any detours, arriving at the time q_i = r_i + |c_i-d_i|$q_i = r_i + |c_i-d_i|$ (if it does not get eaten). After it arrives at the point d_i$d_i$, it hides again. If a cat and a rat meet each other (they are located at the same point at the same time), the cat eats the rat, the rat disappears and cannot be eaten by any other cat. A sleeping cat cannot eat a rat and a hidden rat cannot be eaten ― formally, cat i$i$ can eat rat j$j$ only if they meet at a time t$t$ satisfying s_i \le t \le e_i$s_i \le t \le e_i$ and r_j \le t \le q_j$r_j \le t \le q_j$. Your task is to find out which rats get eaten by which cats. It is guaranteed that no two cats will meet a rat at the same time. -----Input----- - The first line of the input contains a single integer T$T$ denoting the number of test cases. The description of T$T$ test cases follows. - The first line of each test case contains two space-separated integers N$N$ and M$M$. - N$N$ lines follow. For each i$i$ (1 \le i \le N$1 \le i \le N$), the i$i$-th of these lines contains three space-separated integers a_i$a_i$, b_i$b_i$ and s_i$s_i$. - M$M$ more lines follow. For each i$i$ (1 \le i \le M$1 \le i \le M$), the i$i$-th of these lines contains three space-separated integers c_i$c_i$, d_i$d_i$ and r_i$r_i$. -----Output----- For each test case, print M$M$ lines. For each valid i$i$, the i$i$-th of these lines should contain a single integer ― the number of the cat that will eat the i$i$-th rat, or -1$-1$ if no cat will eat this rat. -----Constraints----- - 1 \le T \le 10$1 \le T \le 10$ - 0 \le N \le 1,000$0 \le N \le 1,000$ - 1 \le M \le 1,000$1 \le M \le 1,000$ - 1 \le a_i, b_i, s_i \le 10^9$1 \le a_i, b_i, s_i \le 10^9$ for each valid i$i$ - 1 \le c_i, d_i, r_i \le 10^9$1 \le c_i, d_i, r_i \le 10^9$ for each valid i$i$ - all initial and final positions of all cats and rats are pairwise distinct -----Example Input----- 2 8 7 2 5 1 1 4 1 9 14 10 20 7 9 102 99 1 199 202 1 302 299 3 399 402 3 6 3 1 10 15 10 100 101 1 201 200 1 300 301 5 401 400 5 1000 1010 1020 8 8 2 8 2 12 18 2 22 28 4 32 38 4 48 42 2 58 52 3 68 62 1 78 72 3 3 6 3 13 19 3 21 25 3 31 39 3 46 43 4 59 53 2 65 61 4 79 71 2 -----Example Output----- 1 4 5 6 7 8 -1 1 2 3 4 5 6 7 8
["# cook your dish here\n# cook your dish here\nclass Animal:\n def __init__(self):\n start, end, starting_time = map(int, input().split())\n \n self.ending_time = starting_time + abs(start - end)\n self.velocity = 1 if end >= start else -1 \n \n self.eaten_by = -1, 10 ** 10\n \n self.start = start \n self.end = end \n self.starting_time = starting_time \n \n def will_collide(self, z):\n if self.starting_time > z.ending_time or self.ending_time < z.starting_time:\n return False \n \n if self.velocity == z.velocity:\n if self.starting_time > z.starting_time:\n self, z = z, self\n if z.start == self.start + self.velocity * (z.starting_time - self.starting_time):\n return z.starting_time\n else:\n return False\n \n if self.velocity == -1:\n self, z = z, self\n \n t = ( z.start - self.start + z.starting_time + self.starting_time ) / 2 \n \n return t if self.starting_time <= t <= self.ending_time and z.starting_time <= t <= z.ending_time else False\n \n \n \ndef main():\n for _ in range(int(input())):\n no_cats, no_rats = map(int, input().split())\n \n Cats = [Animal() for i in range(no_cats)]\n \n for i in range(no_rats):\n rat = Animal() \n for j in range(no_cats):\n time = rat.will_collide(Cats[j])\n if time:\n # print(time)\n if time < rat.eaten_by[1]:\n rat.eaten_by = j + 1, time \n \n \n print(rat.eaten_by[0])\n \n \n \nmain()\n ", "# cook your dish here\nclass Animal:\n def __init__(self):\n start, end, starting_time = map(int, input().split())\n \n self.ending_time = starting_time + abs(start - end)\n self.velocity = 1 if end >= start else -1 \n \n self.eaten_by = -1, 10 ** 10\n \n self.start = start \n self.end = end \n self.starting_time = starting_time \n \n def will_collide(self, z):\n if self.starting_time > z.ending_time or self.ending_time < z.starting_time:\n return False \n \n if self.velocity == z.velocity:\n if self.starting_time > z.starting_time:\n self, z = z, self\n if z.start == self.start + self.velocity * (z.starting_time - self.starting_time):\n return z.starting_time\n else:\n return False\n \n if self.velocity == -1:\n self, z = z, self\n \n t = ( z.start - self.start + z.starting_time + self.starting_time ) / 2 \n \n return t if self.starting_time <= t <= self.ending_time and z.starting_time <= t <= z.ending_time else False\n \n \n \ndef main():\n for _ in range(int(input())):\n no_cats, no_rats = map(int, input().split())\n \n Cats = [Animal() for i in range(no_cats)]\n \n for i in range(no_rats):\n rat = Animal() \n for j in range(no_cats):\n time = rat.will_collide(Cats[j])\n if time:\n # print(time)\n if time < rat.eaten_by[1]:\n rat.eaten_by = j + 1, time \n \n \n print(rat.eaten_by[0])\n \n \n \nmain()\n ", "# cook your dish here\ndef sort(array):\n new_array = []\n for i, num in enumerate(array):\n start = 0\n last = i\n while start != last:\n mid = (start + last) // 2\n if new_array[mid][0] > num[0]:\n end = mid\n else:\n start = mid + 1\n new_array.insert(start,num)\n return new_array\n\ntests = int(input())\nfor _ in range(tests):\n n, m = [int(j) for j in input().split()]\n cats, rats = [[[0] * 3 for _ in range(n)],[[0] * 3 for _ in range(m)]]\n for i in range(n):\n cats[i] = [int(j) * 2 for j in input().split()]\n for i in range(m):\n rats[i] = [int(j) * 2 for j in input().split()]\n \n right_cats, left_cats, right_rats, left_rats = [[],[],[],[]]\n for i in range(n):\n start, end, time = cats[i]\n if end > start:\n right_cats.append([start-time,time,end-start+time,i])\n else:\n left_cats.append([start+time,time,start-end+time,i])\n for i in range(m):\n start, end, time = rats[i]\n if end > start:\n right_rats.append([start-time,time,end-start+time,i])\n else:\n left_rats.append([start+time,time,start-end+time,i])\n \n #right_cats = sort(right_cats)\n #right_rats = sort(right_rats)\n #left_cats = sort(left_cats)\n #left_rats = sort(left_rats)\n \n cat_number = [[-1,-1] for _ in range(m)]\n \n for rat in left_rats:\n point, start, end, index = rat\n for cat in left_cats:\n #if point < cat[0]:\n # break\n if point == cat[0]:\n time_of_collision = max(cat[1],start)\n if time_of_collision <= end and time_of_collision <= cat[2]:\n if cat_number[index][0] == -1 or time_of_collision < cat_number[index][1]:\n cat_number[index][0] = cat[3] + 1\n cat_number[index][1] = time_of_collision\n for cat in right_cats:\n #if point < cat[0]:\n # break\n time_of_collision = (point - cat[0]) // 2\n if time_of_collision >= start and time_of_collision <= end and time_of_collision >= cat[1] and time_of_collision <= cat[2]:\n if cat_number[index][0] == -1 or time_of_collision < cat_number[index][1]:\n cat_number[index][0] = cat[3] + 1\n cat_number[index][1] = time_of_collision\n for rat in right_rats:\n point, start, end, index = rat\n for cat in right_cats:\n #if point < cat[0]:\n # break\n if point == cat[0]:\n time_of_collision = max(cat[1],start)\n if time_of_collision <= end and time_of_collision <= cat[2]:\n if cat_number[index][0] == -1 or time_of_collision < cat_number[index][1]:\n cat_number[index][0] = cat[3] + 1\n cat_number[index][1] = time_of_collision\n for cat in left_cats[::-1]:\n #if point > cat[0]:\n # break\n time_of_collision = (cat[0] - point) // 2\n if time_of_collision >= start and time_of_collision <= end and time_of_collision >= cat[1] and time_of_collision <= cat[2]:\n if cat_number[index][0] == -1 or time_of_collision < cat_number[index][1]:\n cat_number[index][0] = cat[3] + 1\n cat_number[index][1] = time_of_collision\n \n for i in range(m):\n print(cat_number[i][0])"]
{"inputs": [["2", "8 7", "2 5 1", "1 4 1", "9 14 10", "20 7 9", "102 99 1", "199 202 1", "302 299 3", "399 402 3", "6 3 1", "10 15 10", "100 101 1", "201 200 1", "300 301 5", "401 400 5", "1000 1010 1020", "8 8", "2 8 2", "12 18 2", "22 28 4", "32 38 4", "48 42 2", "58 52 3", "68 62 1", "78 72 3", "3 6 3", "13 19 3", "21 25 3", "31 39 3", "46 43 4", "59 53 2", "65 61 4", "79 71 2"]], "outputs": [["1", "4", "5", "6", "7", "8", "-1", "1", "2", "3", "4", "5", "6", "7", "8"]]}
INTERVIEW
PYTHON3
CODECHEF
7,115
9967f79dbda0a1666c1eb63900d374e6
UNKNOWN
Bob just learned about bitwise operators. Since Alice is an expert, she decided to play a game, she will give a number $x$ to Bob and will ask some questions: There will be 4 different kinds of queries:- - Alice gives an integer $i$ and Bob has to report the status of the $i^{th}$ bit in $x$, the answer is $"ON"$ if it is on else $"OFF"$. - Alice gives an integer $i$ and Bob has to turn on the $i^{th}$ bit in $x$. - Alice gives an integer $i$ and Bob has to turn off the $i^{th}$ bit in $x$. - Alice gives two integers $p$ and $q$ and in the binary representation of $x$ Bob has to swap the $p^{th}$ and the $q^{th}$ bits. The value of $x$ changes after any update operation. positions $i$, $p$, and $q$ are always counted from the right or from the least significant bit. If anyone of $i$, $p$, or $q$ is greater than the number of bits in the binary representation of $x$, consider $0$ at that position. -----Input:----- - First-line will contain $T$, the number of test cases. Then the test cases follow. - the first line of each test case contains two space-separated integers $x, Q$. - $2Q$ lines follow. - first line is an integer, the query type. - for each query of type 1 to 3, there will be the integer $i$ - for the query of type 4, there will be two space-separated integers, the integers $p, q$ -----Output:----- For the queries of the first kind, print $"ON"$ or $"OFF"$. -----Constraints----- - $1 \leq T \leq 10^3$ - $1 \leq x \leq 10^9$ - $1 \leq Q \leq 10^3$ - $1 \leq i,p,q \leq 30$ -----Sample Input----- 1 2 2 2 1 1 1 -----Sample Output:----- ON -----EXPLANATION:----- the binary representation of 2 is 10 for query 1, we just have to update x to 11 (or 3 in decimal). for the next query, x is now 3 or 11 in binary so the answer is ON.
["# cook your dish here\nt=int(input())\nwhile t>0:\n n,q=list(map(int,input().split()))\n blst=[0]\n for i in range(1,65):\n blst.append(0)\n i=1\n while n>0:\n if n%2:\n blst[i]=1\n n//=2\n i+=1\n while q>0:\n n=int(input())\n if n==1:\n p=int(input())\n if blst[p]:\n print('ON')\n else:\n print('OFF')\n elif n==2:\n p=int(input())\n if blst[p]==0:\n blst[p]=1\n elif n==3:\n p=int(input())\n if blst[p]==1:\n blst[p]=0\n else:\n p,r=list(map(int,input().split()))\n if blst[p]!=blst[r]:\n blst[p]+=1\n blst[p]%=2\n blst[r]+=1\n blst[r]%=2\n q-=1\n t-=1\n", "for _ in range(int(input())):\n N,X=list(map(int,input().split()))\n string=[]\n while N//2!=0:\n string.append(N%2)\n N=N//2\n string.append(1)\n for _ in range(X):\n p=int(input())\n if p==1:\n i=int(input())\n if i-1<len(string):\n if (string[i-1]==1):\n print(\"ON\")\n continue\n else:\n print(\"OFF\")\n continue\n else:\n print(\"OFF\")\n continue\n elif p==2:\n i =int(input())\n if i > len(string):\n x=i-len(string)\n for _ in range(x):\n string.append(0)\n string[len(string)-1]=1\n continue\n else:\n string[i-1]=1\n continue\n elif p==3:\n i =int(input())\n if i > len(string):\n x=i-len(string)\n for _ in range(x):\n string.append(0)\n continue\n else:\n string[i-1]=0\n continue\n else:\n j,k=list(map(int,input().split()))\n if j>len(string) or k >len(string):\n x=max(j,k)-len(string)\n for _ in range(x):\n string.append(0)\n string[j-1],string[k-1]=string[k-1],string[j-1]\n continue\n else:\n string[j-1],string[k-1]=string[k-1],string[j-1]\n \n \n \n \n \n \n", "# cook your dish here\nt = int(input())\nwhile t:\n t -= 1\n b,k = list(map(int, input().split()))\n x = bin(b)[2:]\n n = len(x)\n for j in range(k):\n qu = int(input())\n if 1<=qu<=3:\n i = int(input())\n if qu==1:\n if i<=n:\n r = n-i+1\n if x[r-1]=='0':\n print(\"OFF\")\n else:\n print(\"ON\")\n else:\n print(\"OFF\")\n elif qu==2:\n if i<=n:\n r = n-i+1\n x =x[0:r-1]+'1'+x[r:n]\n else:\n x = '1' + (i-n-1)*'0' + x\n n=i\n elif qu==3:\n if i<=n:\n r = n-i+1\n x =x[0:r-1]+'0'+x[r:n]\n \n \n else:\n p,q = list(map(int, input().split()))\n if p<=n and q<=n:\n r1 = n-p + 1\n r2 = n-q+1\n t1 = x[r1-1]\n t2 = x[r2-1]\n if x[r2-1]!=t1:\n x = x[0:r2-1] + t1 + x[r2:n]\n if x[r1-1]!=t2:\n x = x[0:r1-1]+t2+x[r1:n]\n \n elif p<=n:\n r1 = n-p+1\n p1 = x[r1-1]\n x =x[0:r1-1]+'0'+x[r1:n]\n if p1=='1':\n x = '1'+(q-n-1)*'0' + x\n n = q\n elif q<=n:\n r2 = n-q+1\n p2 = x[r2-1]\n x =x[0:r2-1]+'0'+x[r2:n]\n if p2=='1':\n x = '1'+(p-n-1)*'0' + x\n n=p\n \n", "t = int(input())\r\nwhile t:\r\n t -= 1\r\n b,k = list(map(int, input().split()))\r\n x = bin(b)[2:]\r\n n = len(x)\r\n for j in range(k):\r\n qu = int(input())\r\n if 1<=qu<=3:\r\n i = int(input())\r\n if qu==1:\r\n if i<=n:\r\n r = n-i+1\r\n if x[r-1]=='0':\r\n print(\"OFF\")\r\n else:\r\n print(\"ON\")\r\n else:\r\n print(\"OFF\")\r\n elif qu==2:\r\n if i<=n:\r\n r = n-i+1\r\n x =x[0:r-1]+'1'+x[r:n]\r\n else:\r\n x = '1' + (i-n-1)*'0' + x\r\n n=i\r\n elif qu==3:\r\n if i<=n:\r\n r = n-i+1\r\n x =x[0:r-1]+'0'+x[r:n]\r\n \r\n \r\n else:\r\n p,q = list(map(int, input().split()))\r\n if p<=n and q<=n:\r\n r1 = n-p + 1\r\n r2 = n-q+1\r\n t1 = x[r1-1]\r\n t2 = x[r2-1]\r\n if x[r2-1]!=t1:\r\n x = x[0:r2-1] + t1 + x[r2:n]\r\n if x[r1-1]!=t2:\r\n x = x[0:r1-1]+t2+x[r1:n]\r\n \r\n elif p<=n:\r\n r1 = n-p+1\r\n p1 = x[r1-1]\r\n x =x[0:r1-1]+'0'+x[r1:n]\r\n if p1=='1':\r\n x = '1'+(q-n-1)*'0' + x\r\n n = q\r\n elif q<=n:\r\n r2 = n-q+1\r\n p2 = x[r2-1]\r\n x =x[0:r2-1]+'0'+x[r2:n]\r\n if p2=='1':\r\n x = '1'+(p-n-1)*'0' + x\r\n n=p\r\n \r\n", "# cook your dish here\nt = int(input())\nfor _ in range(t):\n b,k = list(map(int, input().split()))\n x = bin(b)[2:]\n n = len(x)\n for j in range(k):\n qu = int(input())\n if 1<=qu<=3:\n i = int(input())\n if qu==1:\n if i<=n:\n r = n-i+1\n if x[r-1]=='0':\n print(\"OFF\")\n else:\n print(\"ON\")\n else:\n print(\"OFF\")\n elif qu==2:\n if i<=n:\n r = n-i+1\n x =x[0:r-1]+'1'+x[r:n]\n else:\n x = '1' + (i-n-1)*'0' + x\n n=i\n elif qu==3:\n if i<=n:\n r = n-i+1\n x =x[0:r-1]+'0'+x[r:n]\n \n \n else:\n p,q = list(map(int, input().split()))\n if p<=n and q<=n:\n r1 = n-p + 1\n r2 = n-q+1\n t1 = x[r1-1]\n t2 = x[r2-1]\n if x[r2-1]!=t1:\n x = x[0:r2-1] + t1 + x[r2:n]\n if x[r1-1]!=t2:\n x = x[0:r1-1]+t2+x[r1:n]\n \n elif p<=n:\n r1 = n-p+1\n p1 = x[r1-1]\n x =x[0:r1-1]+'0'+x[r1:n]\n if p1=='1':\n x = '1'+(q-n-1)*'0' + x\n n = q\n elif q<=n:\n r2 = n-q+1\n p2 = x[r2-1]\n x =x[0:r2-1]+'0'+x[r2:n]\n if p2=='1':\n x = '1'+(p-n-1)*'0' + x\n n=p\n", "n=int(input())\r\nfor i in range(0,n):\r\n o=input().rstrip().split(' ')\r\n q=int(o[1])\r\n x=int(o[0])\r\n t=list(str(bin(x)))\r\n del(t[0])\r\n del(t[0])\r\n while(len(t)<30):\r\n t.insert(0,'0');\r\n # print(t)\r\n t.reverse();\r\n for j in range(0,q):\r\n o=int(input())\r\n if o==1:\r\n p=int(input())\r\n if int(t[p-1])==0:\r\n print(\"OFF\")\r\n else:\r\n print(\"ON\")\r\n elif o==2:\r\n p=int(input())\r\n t[p-1]=1;\r\n elif o==3:\r\n p=int(input())\r\n t[p-1]=0; \r\n else:\r\n E=input().rstrip().split(' ')\r\n A=int(E[0])\r\n B=int(E[1])\r\n temp=t[A-1]\r\n t[A-1]=t[B-1]\r\n t[B-1]=temp;", "def make_31(string):\r\n if len(string) < 31:\r\n string = (31- len(string)) * '0' + string\r\n\r\n return string\r\n\r\nfor _ in range(int(input())):\r\n x, Q = list(map(int, input().split()))\r\n b = make_31(bin(x)[2:])\r\n b = list(b.strip())\r\n for qqq in range(Q):\r\n query = int(input())\r\n if query == 1:\r\n p = int(input())\r\n print('ON' if b[31-p] == '1' else 'OFF')\r\n elif query == 2:\r\n p = int(input())\r\n b[31-p] = '1'\r\n elif query == 3:\r\n p = int(input())\r\n b[31 - p] = '0'\r\n else:\r\n p, q = list(map(int, input().split()))\r\n temp = b[31 - q]\r\n b[31 - q] = b[31 - p]\r\n b[31 - p] = temp\r\n \r\n\r\n", "# cook your dish here\nfor _ in range(int(input())):\n a=[0 for i in range(32)]\n m,n=list(map(int,input().split()))\n k=0\n while m!=0:\n a[k]=m%2\n k+=1\n m=m//2\n for i in range(n):\n c=int(input())\n \n if c==4:\n p,q=list(map(int,input().split()))\n a[p-1],a[q-1]=a[q-1],a[p-1]\n if c==1:\n d=int(input())\n if a[d-1]==1:\n print(\"ON\")\n else:\n print(\"OFF\")\n \n if c==2:\n d=int(input())\n a[d-1]=1\n if c==3:\n d=int(input())\n a[d-1]=0\n", "for _ in range(int(input())):\r\n x, q = list(map(int, input().split()))\r\n\r\n for _ in range(q):\r\n f = int(input())\r\n\r\n if f == 1:\r\n i = int(input()) - 1\r\n\r\n if (x >> i) & 1:\r\n print('ON')\r\n else:\r\n print('OFF')\r\n\r\n elif f == 2:\r\n i = int(input()) - 1\r\n if not ((x >> i) & 1):\r\n x ^= 1 << i\r\n\r\n elif f == 3:\r\n i = int(input()) - 1\r\n if (x >> i) & 1:\r\n x ^= 1 << i\r\n\r\n elif f == 4:\r\n p, q = list(map(int, input().split()))\r\n p -= 1\r\n q -= 1\r\n\r\n ox = x\r\n\r\n x -= ((ox >> p) & 1) * (1 << p)\r\n x += ((ox >> q) & 1) * (1 << p)\r\n x -= ((ox >> q) & 1) * (1 << q)\r\n x += ((ox >> p) & 1) * (1 << q)\r\n", "from sys import stdin, stdout, maxsize\nfrom math import sqrt, log, factorial, gcd\nfrom collections import defaultdict as D\nfrom bisect import insort\n\nfor _ in range(int(input())):\n x, q = map(int, input().split())\n b = list(bin(x))\n b = b[2:]\n b = b[::-1]\n b.insert(0, '0')\n d = D(lambda: 0)\n l = len(b)\n for i in range(l):\n d[i] = b[i]\n for i in range(q):\n t = int(input())\n if t <= 3:\n x = int(input())\n if t == 1:\n if d[x] == '1': print(\"ON\")\n else: print(\"OFF\")\n elif t == 2:\n d[x] = \"1\"\n else:\n d[x] = \"0\"\n else:\n p, q = map(int, input().split())\n d[p], d[q] = d[q], d[p]"]
{"inputs": [["1", "2 2", "2", "1", "1", "1"]], "outputs": [["ON"]]}
INTERVIEW
PYTHON3
CODECHEF
12,046
c39aa0650aaa35941e8dc5fd73bd3249
UNKNOWN
Problem description. Winston and Royce love sharing memes with each other. They express the amount of seconds they laughed ar a meme as the number of ‘XD’ subsequences in their messages. Being optimization freaks, they wanted to find the string with minimum possible length and having exactly the given number of ‘XD’ subsequences. -----Input----- - The first line of the input contains an integer T denoting the number of test cases. - Next T lines contains a single integer N, the no of seconds laughed. -----Output----- - For each input, print the corresponding string having minimum length. If there are multiple possible answers, print any. -----Constraints----- - 1 ≤ T ≤ 1000 - 1 ≤ N ≤ 109 - 1 ≤ Sum of length of output over all testcases ≤ 5*105 -----Example----- Input: 1 9 Output: XXXDDD -----Explanation----- Some of the possible strings are - XXDDDXD,XXXDDD,XDXXXDD,XDXDXDD etc. Of these, XXXDDD is the smallest.
["t=int(input())\nfor i in range(t):\n n=int(input())\n r=int(n**(.5))\n d=n-r*r\n m=d%r\n print('X'*m+'D'*(m>0)+'X'*(r-m)+'D'*(r+d//r))\n", "from math import sqrt\n\ndef solve():\n n = int(input())\n \n k = int(sqrt(n))\n \n y = n - k * k\n \n z = y % k\n \n if z > 0:\n print('X'*z+'D'+'X'*(k - z)+'D'*(k+y//k))\n else:\n print(\"X\" * k + \"D\" * (k+y//k))\n \nt = int(input())\n\nfor tt in range(0, t):\n solve()", "T=int(input())\nfor _ in range(T):\n N=int(input())\n r=int(N**.5)\n d=N-r*r\n m=d%r\n print('X'*m+'D'*(m>0)+'X'*(r-m)+'D'*(r+d//r))\n", "T=int(input())\nfor _ in range(T):\n N=int(input())\n r=int(N**.5)\n d=N-r*r\n print('X'*(d%r)+'D'*(d%r>0)+'X'*(r-d%r)+'D'*(r+d//r))\n", "T=int(input())\nfor _ in range(T):\n N=int(input())\n r=int(N**.5)\n d=N-r*r\n if d==0:\n print('X'*r+'D'*r)\n else:\n print('X'*(d%r)+'D'*(d%r>0)+'X'*(r-d%r)+'D'*(r+d//r))\n", "from math import sqrt as S \nfor _ in range(int(input())):\n n=int(input())\n a1=int(S(n))\n a2=n//a1\n #print(a1,a2)\n rem=n-a1*a2 \n # print(rem)\n ans=['X']*a1+['D']*a2\n if rem:\n ans.insert(-rem,'X')\n print(*ans,sep='')", "from math import sqrt as S \nfor _ in range(int(input())):\n n=int(input())\n a1=int(S(n))\n a2=n//a1\n #print(a1,a2)\n rem=n-a1*a2 \n # print(rem)\n ans=['X']*a1+['D']*a2\n if rem:\n ans.insert(-rem,'X')\n print(*ans,sep='')\n maxi=1 \n for i in range(2,int(S(n))+1):\n if n%i==0 :\n maxi=max(maxi,i)\n "]
{"inputs": [["1", "9"]], "outputs": [["XXXDDD"]]}
INTERVIEW
PYTHON3
CODECHEF
1,420
980770de4b9e8c1edb693e4b71ab6a07
UNKNOWN
You are given two integers $N$ and $M$. Find the number of sequences $A_1, A_2, \ldots, A_N$, where each element is an integer between $1$ and $M$ (inclusive) and no three consecutive elements are equal. Since this number could be very large, compute it modulo $10^9+7$. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first and only line of each test case contains two space-separated integers $N$ and $M$. -----Output----- For each test case, print a single line containing one integer ― the number of valid sequences modulo $10^9+7$. -----Constraints----- - $1 \le T \le 10^5$ - $1 \le N, M \le 10^{18}$ -----Subtasks----- Subtask #1 (50 points): - $T \le 20$ - $N \le 10^5$ Subtask #2 (50 points): original constraints -----Example Input----- 2 2 2 3 4 -----Example Output----- 4 60
["import sys\ndef fin(): return sys.stdin.readline().strip()\ndef fout(s, end=\"\\n\"): sys.stdout.write(str(s)+end)\n\nMOD = pow(10, 9)+7\nt = int(input())\nwhile t>0:\n t -= 1\n n, m = list(map(int, fin().split()))\n if n == 1:\n print(m%MOD)\n continue\n dp1 = m*(m-1)\n dp2 = m\n for i in range(3, n+1):\n temp = dp2\n dp2 = dp1 \n dp1 = (temp*(m-1))%MOD+(dp1*(m-1))%MOD\n print((dp1+dp2)%MOD)\n\n \n\n", "# cook your dish her\ntry:from cp import input,setInputFile\nexcept:pass\nimport math \nimport copy\n# import random\nimport numpy as np\nimport sys\n# import time\ndef input(): return sys.stdin.readline()\ndef itarr(arr): return list(range(len(arr)))\ndef mp():return list(map(int,input().split()))\ndef lmp():return list(map(int,input().split()))\ndef inp():return int(input())\nMOD=1000000007\n# from functools import lru_cach\ndef mexp(m,p):\n if p==1:\n return m%MOD\n x=(m%MOD * m%MOD )%MOD\n r=mexp(x%MOD,p//2)\n if p%2==0:\n return r%MOD\n else:\n return (m%MOD*r%MOD)%MOD\n\ndef main():\n n,b=mp()\n t=b%MOD\n g=(b*b)%MOD\n n%=MOD\n if n==2:\n print(g)\n return \n if n==1:\n print(t)\n return\n\n MI=np.matrix(np.array([[(b-1)%MOD,(b-1)%MOD],[1,0]]))\n\n arr= mexp(MI,n-2) \n arr=np.array(arr)\n ans = (arr[0][0]*g)%MOD + (arr[0][1]*t)%MOD\n ans%=MOD\n print(ans)\n\n\n \n \n\n# main()\n\nfor _ in range(int(input())):\n main()\n # break\n\n\n\n", "t=int(input())\nmod=10**9+7\nfor _ in range(t):\n n,m=map(int,input().split())\n same=[0]\n diff=[m]\n for i in range(n-1):\n s=diff[-1]\n d=(same[-1]+diff[-1])*(m-1)\n same+=[s%mod]\n diff+=[d%mod]\n print((same[-1]+diff[-1])%mod)", "\"\"\"\n-----------------------------Pseudo---------------------------------\n\"\"\"\nimport copy\nimport sys\nfrom collections import defaultdict, Counter\n\ndef input(): return sys.stdin.readline()\ndef mapi(): return map(int,input().split())\ndef maps(): return map(str,input().split())\n#\ndef print(arg, *argv, end=None):\n sys.stdout.write(str(arg))\n for i in argv: sys.stdout.write(\" \"+str(i))\n sys.stdout.write(end) if end else sys.stdout.write(\"\\n\")\n\n#---------------------------------------------------------------#\n\n\nmod = 1000000007\n\nclass Matrix(object):\n def __init__(self, rows,cols):\n self.rows = rows\n self.cols = cols\n self.mat = [[0]*cols for i in range(rows)]\n\n def __len__(self):\n return len(self.mat)\n\n def __getitem__(self, key1):\n return self.mat[key1]\n\n def __setitem__(self, key1, value):\n self.mat[key1] = value\n\n def __str__(self):\n res = \"\"\n for i in self.mat:\n res+=\" \".join(str(j) for j in i)+\"\\n\"\n return res[:-1]\n\n def __mul__(self, other):\n if len(other) != len(self.mat[0]):\n print(\"matrices are not compitable for multiplication\")\n return\n res = Matrix(len(self.mat), len(other[0]))\n for i in range(self.rows):\n for j in range(len(other[0])):\n ans = 0\n for k in range(len(other)):\n ans += self.mat[i][k]*other[k][j]%mod\n res[i][j] = ans%mod\n return res\n \"\"\"\n def __pow__(self, n):\n if n==0 or n==1:\n return self\n tmp = self\n #copy.deepcopy(self)\n tmp = tmp**(n//2)\n #print(tmp)\n tmp = tmp*tmp\n if(n%2 != 0):\n tmp = tmp*self\n return tmp\n \"\"\"\n def __pow__(self,n):\n res = Matrix(self.rows, self.rows)\n tmp = self\n for i in range(self.rows):\n res[i][i] = 1\n while n>0:\n if n&1:\n res = res*tmp\n n>>=1\n tmp = tmp*tmp\n return res\n\"\"\"\ndp[1] = m\ndp[2] = m^2\ndp[3] = m^3-m\nrecurrent relation: dp[i] = m*dp[i-1] - (m-1)*dp[i-3]\n\n\"\"\"\ndef solve():\n t = 1\n t = int(input())\n while(t):\n t-=1\n n,m = mapi()\n m%=mod\n B = Matrix(3,1)\n M = Matrix(3,3)\n B[0][0] = m\n B[1][0] = (m*m)%mod\n B[2][0] = ((m*m%mod +mod -1)%mod)*m%mod\n\n M[0][1] = 1\n M[1][2] = 1\n M[2][0] = (mod-m+1)%mod\n M[2][1] = 0\n M[2][2] = m\n #print(M)\n M = M**(n-1)\n B = M*B\n #print(B)\n print(B[0][0])\n\n#---------------------------------------------------------------#\ndef __starting_point():\n solve()\n\n\n__starting_point()", "def multiply(F,M,i):\n x = (F[0][0]*M[0][0]+F[1][0]*M[0][1])%i\n y = (F[0][0]*M[1][0]+F[1][0]*M[1][1])%i\n z = (F[0][1]*M[0][0]+F[1][1]*M[0][1])%i\n w = (F[0][1]*M[1][0]+F[1][1]*M[1][1])%i\n F[0][0] = x\n F[1][0] = y\n F[0][1] = z\n F[1][1] = w\ndef power(F,M,n,i):\n if(n<2): return\n power(F,M,n//2,i)\n multiply(F,F,i)\n if(n%2!=0): multiply(F,M,i)\nfor t in range(0,int(input())):\n i = 1000000007;\n n,m = map(int, input().split())\n F = [[(m-1)%i,1],[(m-1)%i,0]]\n M = [[(m-1)%i,1],[(m-1)%i,0]]\n if(n==1): i = m%i\n elif(n==2): i = (m*m)%i\n else:\n power(F,M,n-2,i)\n i = ((F[0][0]*m+F[1][0])*m)%i\n print(i)", "for t in range(0,int(input())):\n z = 1000000007;\n ar = [int(i) for i in input().split(\" \")]\n if(ar[0]==1): print(ar[1]%z)\n else:\n a = ar[1]%z\n b = ((ar[1]%z)*(ar[1]%z))%z\n c = (ar[1]-1)%z\n for i in range(2,ar[0]):\n d = (c*(b+a))%z\n a = b\n b = d\n print(b)", "mod = 10**9 + 7\nfor _ in range(int(input())):\n n, m = list(map(int,input().split()))\n if n == 1:\n print(m%mod)\n continue\n if n == 2:\n print((m%mod)*(m%mod)%mod)\n continue\n if m == 1:\n print(0)\n continue\n\n t = 0\n\n t1 = m%mod\n t2 = ((m%mod)*(m%mod)%mod)\n for i in range(3, n+1):\n t = ((t1+t2)%mod * (m-1)%mod)%mod\n t1 = t2\n t2 = t\n print(t)\n", "import sys\ndef multiply(matrix1,matrix2,mod):\n ans=[[-1 for i in range(len(matrix2[0]))] for _ in range(len(matrix1))]\n #print(ans,'before')\n for i in range(len(matrix1)):\n for j in range(len(matrix2[0])):\n s=0\n k=0\n while k<len(matrix1[0]):\n s+=(matrix1[i][k]*matrix2[k][j])%mod\n k+=1\n ans[i][j]=(s%mod)\n #print(ans,'ans')\n return ans\ndef power(a,b,mod):\n res=[[1,0],[0,1]]\n #print(res,'res')\n for i in range(len(a)):\n for j in range(len(a[0])):\n a[i][j]=a[i][j]%mod\n #print(a,'a')\n while b>0:\n if (b&1):\n res=multiply(res,a,mod)\n b=b>>1\n a=multiply(a,a,mod)\n return res\nt=int(sys.stdin.readline())\nmod=10**9+7\nfor _ in range(t):\n n,m=list(map(int,sys.stdin.readline().split()))\n base=[[m],[0]]\n a=[[m-1,m-1],[1,0]]\n #print(base,'base')\n #print(a,'a')\n ans=power(a,n-1,mod)\n #print(ans,'ans')\n ans=multiply(ans,base,mod)\n print((ans[0][0]+ans[1][0])%mod)\n \n \n", "t = int(input())\nfor _ in range(t):\n mod = 10**9+7\n n,m = [int(c) for c in input().split(' ')]\n if n==1:\n print(m%mod)\n continue\n a,b = m*(m-1),m\n if n==2:\n print((a+b)%mod)\n else:\n for p in range(3,n+1):\n temp = a\n a = (a%mod+b%mod)%mod\n a = (a*(m-1))%mod\n b = temp\n print((a+b)%mod)"]
{"inputs": [["2", "2 2", "3 4"]], "outputs": [["4", "60"]]}
INTERVIEW
PYTHON3
CODECHEF
6,597
2168d04d2a6aca8c5e1edca1d0eee751
UNKNOWN
Chef is making Window frames for his new office, for this he has n wooden Logs whose lengths are l1, l2, … ln respectively. Chef Doesn’t want to break any logs or Stick 2 or more logs together. To make a h × w Window Frame, he needs two Logs with lengths equal h and two with length . The Chef wants as much sunlight in as possible and for it he has decided to make from the available logs as many frames as possible. Help him in finding the number of window Frames that he can make. Note : Chef do not need to use all the logs Input: The first line of the input contains a single integer T denoting the number of test cases. The description of each test case follows :. The first line of each test case contains a single integer n the number of wooden logs. The second line contains n space-separated integers l1,l2,l3….ln The length of each wooden log Output: The only line in Output Contains single Integer denoting the maximum possible number of Wooden Frames. Constraints: 1 ≤ T ≤ 10 1 ≤ n ≤ 100 1 ≤ li ≤ 10000 Example Input: 2 4 1 2 1 2 8 1 2 1 3 4 1 5 6 Example Output: 1 0 Explanation : First Case : We can build a frame of dimension 1x2 as two logs of each dimension are available. Second Case : We can’t build any Frame as no logs of length except 1 have more than one piece.
["# cook your dish here\nt=int(input())\nj=0\nwhile j<t:\n n=int(input())\n lst=list(map(int,input().split()))\n s=set()\n d=list()\n for i in lst:\n if i in s:\n s.remove(i)\n d.append(i)\n else:\n s.add(i)\n x=len(d)\n if x%2==0:\n print(x//2)\n else:\n print((x-1)//2)\n j+=1", "test = int(input())\r\n\r\nfor t in range(test):\r\n n = int(input())\r\n mark = [0 for i in range(10001)]\r\n \r\n logs = list(map(int, input().strip().split()))\r\n use = []\r\n \r\n for log in logs:\r\n mark[log] += 1\r\n \r\n if mark[log]>=2:\r\n use.append(log)\r\n \r\n use = list(set(use))\r\n #print(use)\r\n \r\n #make windows\r\n full = 0\r\n half = 0\r\n \r\n for log in use:\r\n full += (mark[log]//4)\r\n mark[log] = mark[log]%4\r\n half += (mark[log]//2)\r\n \r\n print(full+(half//2))", "# cook your dish here\nfor o in range(int(input())):\n\tn = int(input())\n\ta = list(map(int ,input().split()))\n\tdic = {}\n\ts = 0\n\tfor i in a:\n\t\tdic[i] = dic.get(i,0) +1\n\tfor i in dic.values():\n\t\tif i >=2:\n\t\t\ts = s+i\n\tprint(s//4)", "import collections\r\ndef solve(n,l):\r\n c=0\r\n d=collections.Counter(l)\r\n for i in d:\r\n if d[i]>=2:\r\n c+=d[i]//2\r\n return c//2 \r\nfor _ in range(int(input())):\r\n n=int(input())\r\n l=list(map(int,input().split()))\r\n print(solve(n,l))\r\n", "# cook your dish here\nt=int(input())\nfor i in range(t):\n n=int(input())\n l=list(map(int,input().split()))\n s=set(l)\n d=[]\n d1=[]\n h=0\n for j in s:\n d.append(l.count(j))\n d2=list(set(d))\n d2.sort(reverse=True)\n for v in d2:\n if (v>1) and (v%2==0):\n d1.append(v)\n for k in d1:\n q=k//2\n if (d.count(k)==2):\n h=h+q\n elif q>=2:\n h=h+(q//2)\n \n if h==0: \n print(0)\n else:\n print(h)\n \n \n \n \n \n \n", "# cook your dish here\nt=int(input())\nfor i in range(t):\n n=int(input())\n l=list(map(int,input().split()))\n s=set(l)\n d=[]\n d1=[]\n h=0\n for j in s:\n d.append(l.count(j))\n d2=list(set(d))\n d2.sort(reverse=True)\n for v in d2:\n if (v>1) and (v%2==0):\n d1.append(v)\n for k in d1:\n q=k//2\n if (d.count(k)==2):\n h=h+q\n elif q>=2:\n h=h+(q//2)\n \n if h==0: \n print(0)\n else:\n print(h)\n \n \n \n \n \n \n", "# cook your dish here\nt = int(input())\n\nfor _ in range(t):\n n = int(input())\n arr = list(map( int, str(input()).split() ))\n \n visited = set()\n doubles = []\n for i in arr:\n if i in visited:\n visited.remove(i)\n doubles.append(i)\n else:\n visited.add(i)\n print(len(doubles)//2)\n", "t=int(input())\nwhile(t>0):\n n=int(input())\n a=list(map(int,input().split()))\n c=0\n for i in a:\n d=a.count(i)\n for j in range(1,d):\n a.remove(i)\n if(d>=2):\n c+=d//2\n print(c//2) \n t-=1", "# cook your dish here\na=int(input())\nfor i in range(a):\n t=int(input())\n l=list(map(int,input().split()))\n l2=[]\n for j in l:\n if j not in l2:\n l2.append(j)\n l3=[]\n for k in l2:\n l3.append(l.count(k))\n c=0\n for j in l3:\n c1=j\n if c1>=2:\n while(c1>=2):\n c+=1\n c1=c1-2\n print(round(c/2))\n", "for _ in range(int(input())):\r\n n=int(input())\r\n l=list(map(int,input().split()))\r\n t=[0]*(10001)\r\n for i in l:\r\n t[i]+=1\r\n s=0\r\n for j in t:\r\n s+=j//2\r\n print(s//2)", "t=int(input())\nfor i in range(t):\n n=int(input())\n lst1=list(map(int,input().split()))\n lst2=[]\n for j in lst1:\n if j not in lst2:\n lst2.append(j)\n lst3=[]\n for k in lst2:\n lst3.append(lst1.count(k))\n c1=0\n for j in lst3:\n c=j\n if c>=2:\n while(c>=2):\n c1+=1\n c=c-2\n print(round(c1/2))\n#cook your dish here\n"]
{"inputs": [["2", "4", "1 2 1 2", "8", "1 2 1 3 4 1 5 6"]], "outputs": [["1", "0"]]}
INTERVIEW
PYTHON3
CODECHEF
4,363
902eabf02b10f653cbc63aa5beb0c804
UNKNOWN
Henry and Derek are waiting on a room, eager to join the Snackdown 2016 Qualifier Round. They decide to pass the time by playing a game. In this game's setup, they write N positive integers on a blackboard. Then the players take turns, starting with Henry. In a turn, a player selects one of the integers, divides it by 2, 3, 4, 5 or 6, and then takes the floor to make it an integer again. If the integer becomes 0, it is erased from the board. The player who makes the last move wins. Henry and Derek are very competitive, so aside from wanting to win Snackdown, they also want to win this game. Assuming they play with the optimal strategy, your task is to predict who wins the game. -----Input----- The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows. The first line of each test case contains a single integer N denoting the number of integers they wrote on the board. The second line contains N space-separated integers A1, A2, ..., AN denoting the integers themselves. -----Output----- For each test case, output a single line containing either “Henry” or “Derek” (without quotes), denoting the winner of the game. -----Constraints----- - 1 ≤ T ≤ 1000 - 1 ≤ N ≤ 100 - 1 ≤ Ai ≤ 1018 -----Example----- Input:2 2 3 4 3 1 3 5 Output:Henry Derek -----Explanation----- Example case 1. In this test case, the numbers on the board are [3,4]. Henry can win by selecting 4 and then dividing it by 2. The integers on the board are now [3,2]. Derek now has a couple of choices: - Derek can divide 2 by 3, 4, 5 or 6, making it 0 and removing it. Now only one integer remains on the board, 3, and Henry can just divide it by 6 to finish, and win, the game. - Derek can divide 3 by 4, 5 or 6, making it 0 and removing it. Now only one integer remains on the board, 2, and Henry can just divide it by 6 to finish, and win, the game. - Derek can divide 2 by 2. Now the integers are [1,3]. Henry can respond by dividing 3 by 3. The integers are now [1,1]. Now Derek has no choice but to divide 1 by 2, 3, 4, 5 or 6 and remove it (because it becomes 0). Henry can respond by dividing the remaining 1 by 2 to finish, and win, the game. - Derek can divide 3 by 2 or 3. Now the integers are [1,2]. Henry can respond by dividing 2 by 2. The integers are now [1,1]. This leads to a situation as in the previous case and Henry wins.
["gb = [0, 1, 2, 2, 3, 3]\nga = [0 for x in range(70)]\ngag = [0 for x in range(70)]\nga[0] = 1\ngag[0] = 0\n\nfor i in range(1, 70):\n if i % 4 == 0:\n ga[i] = 1.5 * ga[i-1]\n gag[i] = 0\n else:\n ga[i] = 2 * ga[i-1]\n gag[i] = gag[i-1] + 1\n\n\ndef g(n):\n if n < 6:\n return gb[n]\n else:\n x = n / 6\n a = 0\n for i, k in enumerate(ga):\n if k <= x:\n a = i\n else:\n break\n return gag[a]\n\n\nt = int(input())\nfor q in range(t):\n n = int(input())\n a = list(map(int, input().split()))\n\n res = g(a[0])\n for i in range(1, n):\n res ^= g(a[i])\n\n if res == 0:\n print(\"Derek\")\n else:\n print(\"Henry\")\n", "from math import floor\n\na=[0,1,2,4,6]\nfor i in range(1,70):\n a.append(a[i]*12)\n\n\nb=[]\n\nfor i in range(len(a)):\n b.append([a[i],i%4])\n\n# print b\ndef func(x):\n tot=0\n for i in range(len(x)):\n for j in range(len(b)-1):\n if x[i]>=b[j][0] and x[i] < b[j+1][0]:\n # print tot,b[j][1]\n tot^=b[j][1]\n break\n \n return tot\n\nt=eval(input())\nfor i in range(t):\n n=eval(input())\n x=list(map(int,input().split()))\n if func(x)==0:\n print(\"Derek\")\n else:\n print(\"Henry\") ", "def g2(n):\n l = []\n while n:\n l.append(n%12)\n n /= 12\n for x in reversed(l):\n if x >= 6: return 0\n if x >= 4: return 3\n if x >= 2: return 2\n if x >= 1: return 1\n return 0\n\ndef solve(n,a):\n r = 0\n for x in a:\n r ^= g2(x)\n return r\n\nt = int(input())\nfor i in range(t):\n n = int(input())\n a = list(map(int,input().strip().split()))\n r = solve(n,a)\n if r == 0: print('Derek')\n else: print('Henry')", "for _ in range(int(input())):\n n=int(input())\n a=[int(x) for x in input().split()]\n\n def nimber(game):\n if game<=2:\n return game\n mx=2\n nim=2\n while True:\n if nim==3:\n mx*=3\n mx/=2\n else:\n mx*=2\n if game<mx:\n return nim\n nim+=1\n nim%=4\n \n x=0\n for aa in a:\n x^=nimber(aa)\n if x!=0:\n print(\"Henry\")\n else:\n print(\"Derek\")\n"]
{"inputs": [["2", "2", "3 4", "3", "1 3 5"]], "outputs": [["Henry", "Derek"]]}
INTERVIEW
PYTHON3
CODECHEF
1,966
88d85c42ecfa683764c8e6734c1db217
UNKNOWN
You are given an unweighted tree with N$N$ nodes (numbered 1$1$ through N$N$). Let's denote the distance between any two nodes p$p$ and q$q$ by d(p,q)$d(p, q)$. You should answer Q$Q$ queries. In each query, you are given parameters a$a$, da$d_a$, b$b$, db$d_b$, and you should find a node x$x$ such that d(x,a)=da$d(x, a) = d_a$ and d(x,b)=db$d(x, b) = d_b$, or determine that there is no such node. -----Input----- - The first line of the input contains a single integer T$T$ denoting the number of test cases. The description of T$T$ test cases follows. - The first line of each test case contains two space-separated integers N$N$ and Q$Q$. - Each of the next N−1$N-1$ lines contains two space-separated integers u$u$ and v$v$ denoting that nodes u$u$ and v$v$ are connected by an edge. - Each of the next Q$Q$ lines contains four space-separated integers a$a$, da$d_a$, b$b$ and db$d_b$ describing a query. -----Output----- For each query, print a single line containing one integer ― the number of a node satisfying the given requirements, or −1$-1$ if no such node exists. If there are multiple solutions, you may output any one. -----Constraints----- - 1≤T≤1,000$1 \le T \le 1,000$ - 1≤N,Q≤106$1 \le N, Q \le 10^6$ - 1≤u,v≤N$1 \le u, v \le N$ - the graph on the input is a tree - 1≤a,b≤N$1 \le a, b \le N$ - 1≤da,db<N$1 \le d_a, d_b < N$ - the sum of N$N$ over all test cases does not exceed 106$10^6$ - the sum of Q$Q$ over all test cases does not exceed 106$10^6$ -----Subtasks----- Subtask #1 (50 points): - 1≤N,Q≤1,000$1 \le N, Q \le 1,000$ - the sum of N$N$ over all test cases does not exceed 1,000$1,000$ - the sum of Q$Q$ over all test cases does not exceed 1,000$1,000$ Subtask #2 (50 points): original constraints -----Example Input----- 1 5 3 1 2 2 3 3 4 3 5 2 1 4 1 2 2 4 2 1 1 2 1 -----Example Output----- 3 5 -1
["# cook your dish here\nclass TestCase:\n def __init__(self):\n [self.node_count, self.query_count] = read_line()\n \n def fill_nodes(self):\n self.nodes = {n+1: [] for n in range(self.node_count)}\n for i in range(self.node_count -1):\n new_node_1, new_node_2 = read_line()\n self.nodes[new_node_1].append(new_node_2)\n self.nodes[new_node_2].append(new_node_1)\n \n def resolve_query(self, query):\n a, d_a, b, d_b = query\n suiting_a = self.find_nodes_with_distance(a, d_a)\n suiting_b = self.find_nodes_with_distance(b, d_b)\n fitting = [node for node in suiting_a if node in suiting_b]\n \n if len(fitting) == 0:\n return -1\n else:\n return fitting[0]\n \n def find_nodes_with_distance(self, start_node, distance):\n from_nodes = {start_node}\n passed_nodes = from_nodes\n \n for i in range(distance):\n to_nodes = set()\n # add all adjacent nodes\n for node in from_nodes:\n to_nodes.update(self.nodes[node])\n \n # no backtracking\n for node in passed_nodes:\n if node in to_nodes:\n to_nodes.remove(node)\n \n # update which nodes are passed\n passed_nodes.update(to_nodes)\n # go another round with the new nodes found\n from_nodes = to_nodes\n return list(from_nodes)\n\ndef read_line():\n line = input()\n return [int(s) for s in line.split(' ')]\n\nnum_testcases = int(input())\nfor i in range(num_testcases):\n testcase = TestCase()\n testcase.fill_nodes()\n for q in range(testcase.query_count):\n query = read_line()\n print(testcase.resolve_query(query))", "class TestCase:\r\n def __init__(self):\r\n [self.node_count, self.query_count] = read_line()\r\n \r\n def fill_nodes(self):\r\n self.nodes = {n+1: [] for n in range(self.node_count)}\r\n for i in range(self.node_count -1):\r\n new_node_1, new_node_2 = read_line()\r\n self.nodes[new_node_1].append(new_node_2)\r\n self.nodes[new_node_2].append(new_node_1)\r\n \r\n def resolve_query(self, query):\r\n a, d_a, b, d_b = query\r\n suiting_a = self.find_nodes_with_distance(a, d_a)\r\n suiting_b = self.find_nodes_with_distance(b, d_b)\r\n fitting = [node for node in suiting_a if node in suiting_b]\r\n \r\n if len(fitting) == 0:\r\n return -1\r\n else:\r\n return fitting[0]\r\n \r\n def find_nodes_with_distance(self, start_node, distance):\r\n from_nodes = {start_node}\r\n passed_nodes = from_nodes\r\n \r\n for i in range(distance):\r\n to_nodes = set()\r\n # add all adjacent nodes\r\n for node in from_nodes:\r\n to_nodes.update(self.nodes[node])\r\n \r\n # no backtracking\r\n for node in passed_nodes:\r\n if node in to_nodes:\r\n to_nodes.remove(node)\r\n \r\n # update which nodes are passed\r\n passed_nodes.update(to_nodes)\r\n # go another round with the new nodes found\r\n from_nodes = to_nodes\r\n return list(from_nodes)\r\n\r\ndef read_line():\r\n line = input()\r\n return [int(s) for s in line.split(' ')]\r\n\r\nnum_testcases = int(input())\r\nfor i in range(num_testcases):\r\n testcase = TestCase()\r\n testcase.fill_nodes()\r\n for q in range(testcase.query_count):\r\n query = read_line()\r\n print(testcase.resolve_query(query))", "def bfs(tr,sp,d):\n temp=[sp]\n vl=[-1]*len(tr)\n vl[sp]=0\n while(len(temp)>0):\n z=temp.pop(0)\n if(vl[z]>=d):\n continue\n for e in tr[z]:\n if(vl[e]==-1):\n vl[e]=vl[z]+1\n temp.append(e)\n return [i for i in range(len(vl)) if vl[i]==d]\n\ndef myfunc():\n n,q=list(map(int,input().split()))\n tr=[[] for _ in range(n+1)]\n for _ in range(n-1):\n u,v=list(map(int,input().split()))\n tr[u].append(v)\n tr[v].append(u)\n for qn in range(q):\n a,da,b,db=list(map(int,input().split()))\n ta=set(bfs(tr,a,da))\n tb=set(bfs(tr,b,db))\n x=list(ta.intersection(tb))\n if(len(x)>0):\n print(x[0])\n else:print(-1)\n\n\nt=int(input())\nfor _ in range(t):\n myfunc()", "# cook your dish here\ndef bfs(tr,sp,d):\n temp=[sp]\n vl=[-1]*len(tr)\n vl[sp]=0\n while(len(temp)>0):\n z=temp.pop(0)\n if(vl[z]>=d):\n continue\n for e in tr[z]:\n if(vl[e]==-1):\n vl[e]=vl[z]+1\n temp.append(e)\n return [i for i in range(len(vl)) if vl[i]==d]\n\ndef myfunc():\n n,q=list(map(int,input().split()))\n tr=[[] for _ in range(n+1)]\n for _ in range(n-1):\n u,v=list(map(int,input().split()))\n tr[u].append(v)\n tr[v].append(u)\n for qn in range(q):\n a,da,b,db=list(map(int,input().split()))\n ta=set(bfs(tr,a,da))\n tb=set(bfs(tr,b,db))\n x=list(ta.intersection(tb))\n if(len(x)>0):\n print(x[0])\n else:print(-1)\n\n\nt=int(input())\nfor _ in range(t):\n myfunc()", "# cook your dish here\ndef bfs(tr,sp,d):\n temp=[sp]\n vl=[-1]*len(tr)\n vl[sp]=0\n while(len(temp)>0):\n z=temp.pop(0)\n if(vl[z]>=d):\n continue\n for e in tr[z]:\n if(vl[e]==-1):\n vl[e]=vl[z]+1\n temp.append(e)\n return [i for i in range(len(vl)) if vl[i]==d]\n\ndef myfunc():\n n,q=list(map(int,input().split()))\n tr=[[] for _ in range(n+1)]\n for _ in range(n-1):\n u,v=list(map(int,input().split()))\n tr[u].append(v)\n tr[v].append(u)\n for qn in range(q):\n a,da,b,db=list(map(int,input().split()))\n ta=set(bfs(tr,a,da))\n tb=set(bfs(tr,b,db))\n x=list(ta.intersection(tb))\n if(len(x)>0):\n print(x[0])\n else:print(-1)\n\n\nt=int(input())\nfor _ in range(t):\n myfunc()", "def bfs(tr,sp,d):\n temp=[sp]\n vl=[-1]*len(tr)\n vl[sp]=0\n while(len(temp)>0):\n z=temp.pop(0)\n if(vl[z]>=d):\n continue\n for e in tr[z]:\n if(vl[e]==-1):\n vl[e]=vl[z]+1\n temp.append(e)\n return [i for i in range(len(vl)) if vl[i]==d]\n\ndef myfunc():\n n,q=list(map(int,input().split()))\n tr=[[] for _ in range(n+1)]\n for _ in range(n-1):\n u,v=list(map(int,input().split()))\n tr[u].append(v)\n tr[v].append(u)\n for qn in range(q):\n a,da,b,db=list(map(int,input().split()))\n ta=set(bfs(tr,a,da))\n tb=set(bfs(tr,b,db))\n x=list(ta.intersection(tb))\n if(len(x)>0):\n print(x[0])\n else:print(-1)\n\n\nt=int(input())\nfor _ in range(t):\n myfunc()", "t = int(input().strip())\r\nresult = []\r\n\r\nclass Distance:\r\n def __init__(self , n , dist):\r\n self.n = n\r\n self.dist = dist\r\n\r\n def cal_dist(self,u,v):\r\n self.dist[u][v] = self.dist[v][u] = 1\r\n for i in range(n):\r\n if self.dist[u][i] != -1 and self.dist[v][i] == -1 and i!=u and i!=v:\r\n self.dist[v][i] = self.dist[i][v] = self.dist[u][i] + 1\r\n for i in range(n):\r\n if self.dist[v][i] != -1 and self.dist[u][i] == -1 and i!=u and i!=v:\r\n self.dist[u][i] = self.dist[i][u] = self.dist[v][i] + 1\r\n \r\n def return_dist(self):\r\n return self.dist\r\n\r\nfor i in range(t):\r\n n,q = map(int, input().strip().split())\r\n dist = [[-1 for j in range(n)] for k in range(n)]\r\n for j in range(n):\r\n dist[j][j] = 0\r\n d = Distance(n,dist)\r\n for j in range(n-1):\r\n u , v = map(int , input().strip().split())\r\n d.cal_dist(u-1,v-1)\r\n dist = d.return_dist()\r\n for j in range(q):\r\n a , da , b , db = map(int , input().strip().split())\r\n ans = -1\r\n for k in range(n):\r\n if dist[a-1][k] == da and dist[b-1][k] == db:\r\n ans = k+1\r\n break\r\n result.append(ans)\r\n \r\nprint(*result,sep=\"\\n\")", "# cook your dish here\nt = int(input().strip())\nresult = []\n\nclass Distance:\n def __init__(self , n , dist):\n self.n = n\n self.dist = dist\n\n def cal_dist(self,u,v):\n self.dist[u][v] = self.dist[v][u] = 1\n for i in range(n):\n if self.dist[u][i] != -1 and self.dist[v][i] == -1 and i!=u and i!=v:\n self.dist[v][i] = self.dist[i][v] = self.dist[u][i] + 1\n for i in range(n):\n if self.dist[v][i] != -1 and self.dist[u][i] == -1 and i!=u and i!=v:\n self.dist[u][i] = self.dist[i][u] = self.dist[v][i] + 1\n \n def return_dist(self):\n return self.dist\n\nfor i in range(t):\n n,q = map(int, input().strip().split())\n dist = [[-1 for j in range(n)] for k in range(n)]\n for j in range(n):\n dist[j][j] = 0\n d = Distance(n,dist)\n for j in range(n-1):\n u , v = map(int , input().strip().split())\n d.cal_dist(u-1,v-1)\n dist = d.return_dist()\n for j in range(q):\n a , da , b , db = map(int , input().strip().split())\n ans = -1\n for k in range(n):\n if dist[a-1][k] == da and dist[b-1][k] == db:\n ans = k+1\n break\n result.append(ans)\n \nprint(*result,sep=\"\\n\")", "# cook your dish here\n# cook your dish here\nt = int(input().strip())\nresult = []\n\nclass Distance:\n def __init__(self , n , dist):\n self.n = n\n self.dist = dist\n\n def cal_dist(self,u,v):\n self.dist[u][v] = self.dist[v][u] = 1\n for i in range(n):\n if self.dist[u][i] != -1 and self.dist[v][i] == -1 and i!=u and i!=v:\n self.dist[v][i] = self.dist[i][v] = self.dist[u][i] + 1\n for i in range(n):\n if self.dist[v][i] != -1 and self.dist[u][i] == -1 and i!=u and i!=v:\n self.dist[u][i] = self.dist[i][u] = self.dist[v][i] + 1\n \n def return_dist(self):\n return self.dist\n\nfor i in range(t):\n n,q = map(int, input().strip().split())\n dist = [[-1 for j in range(n)] for k in range(n)]\n for j in range(n):\n dist[j][j] = 0\n d = Distance(n,dist)\n for j in range(n-1):\n u , v = map(int , input().strip().split())\n d.cal_dist(u-1,v-1)\n dist = d.return_dist()\n for j in range(q):\n a , da , b , db = map(int , input().strip().split())\n ans = -1\n for k in range(n):\n if dist[a-1][k] == da and dist[b-1][k] == db:\n ans = k+1\n break\n result.append(ans)\n \nprint(*result,sep=\"\\n\")", "# cook your dish here\nt = int(input().strip())\nresult = []\n\nclass Distance:\n def __init__(self , n , dist):\n self.n = n\n self.dist = dist\n\n def cal_dist(self,u,v):\n self.dist[u][v] = self.dist[v][u] = 1\n for i in range(n):\n if self.dist[u][i] != -1 and self.dist[v][i] == -1 and i!=u and i!=v:\n self.dist[v][i] = self.dist[i][v] = self.dist[u][i] + 1\n for i in range(n):\n if self.dist[v][i] != -1 and self.dist[u][i] == -1 and i!=u and i!=v:\n self.dist[u][i] = self.dist[i][u] = self.dist[v][i] + 1\n \n def return_dist(self):\n return self.dist\n\nfor i in range(t):\n n,q = map(int, input().strip().split())\n dist = [[-1 for j in range(n)] for k in range(n)]\n for j in range(n):\n dist[j][j] = 0\n d = Distance(n,dist)\n for j in range(n-1):\n u , v = map(int , input().strip().split())\n d.cal_dist(u-1,v-1)\n dist = d.return_dist()\n for j in range(q):\n a , da , b , db = map(int , input().strip().split())\n ans = -1\n for k in range(n):\n if dist[a-1][k] == da and dist[b-1][k] == db:\n ans = k+1\n break\n result.append(ans)\n \nprint(*result,sep=\"\\n\")", "# cook your dish here\nt = int(input().strip())\nresult = []\n\nclass Distance:\n def __init__(self , n , dist):\n self.n = n\n self.dist = dist\n\n def cal_dist(self,u,v):\n self.dist[u][v] = self.dist[v][u] = 1\n for i in range(n):\n if self.dist[u][i] != -1 and self.dist[v][i] == -1 and i!=u and i!=v:\n self.dist[v][i] = self.dist[i][v] = self.dist[u][i] + 1\n for i in range(n):\n if self.dist[v][i] != -1 and self.dist[u][i] == -1 and i!=u and i!=v:\n self.dist[u][i] = self.dist[i][u] = self.dist[v][i] + 1\n \n def return_dist(self):\n return self.dist\n\nfor i in range(t):\n n,q = map(int, input().strip().split())\n dist = [[-1 for j in range(n)] for k in range(n)]\n for j in range(n):\n dist[j][j] = 0\n d = Distance(n,dist)\n for j in range(n-1):\n u , v = map(int , input().strip().split())\n d.cal_dist(u-1,v-1)\n dist = d.return_dist()\n for j in range(q):\n a , da , b , db = map(int , input().strip().split())\n ans = -1\n for k in range(n):\n if dist[a-1][k] == da and dist[b-1][k] == db:\n ans = k+1\n break\n result.append(ans)\n \nprint(*result,sep=\"\\n\")", "try:\n t=int(input())\n for __ in range(t):\n N,m=map(int,input().split())\n A=[]\n dic={}\n for i in range(N-1):\n a,b=map(int,input().split())\n if a in dic:\n dic[a]+=str(b)+\",\"\n else:\n dic[a]=str(b)+\",\"\n if b in dic:\n dic[b]+=str(a)+\",\"\n else:\n dic[b]=str(a)+\",\"\n for _ in range(m):\n term1,dist1,term2,dist2=map(str,input().split())\n l=[term1]\n A=[]\n def distance(t,c,x,A,l):\n if t==int(c):\n A+=[x]\n else:\n string=\"\"\n for i in dic[int(x)]:\n if i==\",\":\n if string not in l:\n l+=[string]\n x=string\n distance(t+1,c,x,A,l)\n string=\"\"\n else:\n string=\"\"\n else:\n string+=str(i)\n distance(0,dist1,term1,A,l)\n l1=[]\n for i in A:\n if i!=term1:\n l1+=[i]\n A=[]\n l=[term2]\n distance(0,dist2,term2,A,l)\n l2=[]\n for i in A:\n if i!=term2:\n l2+=[i]\n count=0\n for i in l1:\n if i in l2:\n if count<1:\n print(int(i))\n count+=1\n if count==0:\n print(-1)\nexcept:\n pass\n\n \n ", "\n# cook your dish here\ndef dist(a,b):\n if (a,b) in di :\n return di[(a,b)]\n if distance[a]<distance[b]:\n a,b = b,a\n c = distance[a] - distance[b]\n l = []\n t = a\n while c:\n l.append(t)\n t = p[t]\n c -= 1\n w = b\n r = []\n while t!=w:\n l.append(t)\n r.append(w)\n t = p[t]\n w = p[w]\n for i in l:\n for j in r :\n di[(i,j)] = distance[i] + distance[j] - 2*distance[t]\n di[(a,b)] = distance[a] + distance[b] - 2*distance[t]\n return di[(a,b)]\n \nt = int(input())\nfor t_iter in range(t):\n n,q = map(int,input().split())\n g = {}\n for i in range(n):\n g[i] = []\n for i in range(n-1):\n u,v = map(int,input().split())\n g[u-1].append(v-1)\n g[v-1].append(u-1)\n \n p = [None]*n\n distance = [-1]*n\n distance[0] = 0\n qu= [0]\n while len(qu):\n u = qu.pop(0)\n for v in g[u]:\n if distance[v] == -1:\n distance[v] = distance[u] + 1 \n p[v] = u\n qu.append(v)\n # print(p)\n # print(distance)\n di = {}\n for q_iter in range(q):\n a,da,b,db = map(int,input().split())\n a -= 1\n b -= 1\n flag = 0\n for i in range(n):\n if dist(a,i) == da and dist(b,i) == db :\n print(i+1)\n flag = 1\n break\n if flag == 0:\n print(-1)\n \n \n \n ", "\n# cook your dish here\ndef dist(a,b):\n if (a,b) in di :\n return di[(a,b)]\n if distance[a]<distance[b]:\n a,b = b,a\n c = distance[a] - distance[b]\n t = a\n while c:\n t = p[t]\n c -= 1\n w = b\n while t!=w:\n t = p[t]\n w = p[w]\n di[(a,b)] = distance[a] + distance[b] - 2*distance[t]\n return di[(a,b)]\n \nt = int(input())\nfor t_iter in range(t):\n n,q = map(int,input().split())\n g = {}\n for i in range(n):\n g[i] = []\n for i in range(n-1):\n u,v = map(int,input().split())\n g[u-1].append(v-1)\n g[v-1].append(u-1)\n \n p = [None]*n\n distance = [-1]*n\n distance[0] = 0\n qu= [0]\n while len(qu):\n u = qu.pop(0)\n for v in g[u]:\n if distance[v] == -1:\n distance[v] = distance[u] + 1 \n p[v] = u\n qu.append(v)\n # print(p)\n # print(distance)\n di = {}\n for q_iter in range(q):\n a,da,b,db = map(int,input().split())\n a -= 1\n b -= 1\n flag = 0\n for i in range(n):\n if dist(a,i) == da and dist(b,i) == db :\n print(i+1)\n flag = 1\n break\n if flag == 0:\n print(-1)\n \n \n \n ", "\n# cook your dish here\ndef dist(a,b):\n if distance[a]<distance[b]:\n a,b = b,a\n c = distance[a] - distance[b]\n t = a\n while c:\n t = p[t]\n c -= 1\n w = b\n while t!=w:\n t = p[t]\n w = p[w]\n return distance[a] + distance[b] - 2*distance[t]\n \nt = int(input())\nfor t_iter in range(t):\n n,q = map(int,input().split())\n g = {}\n for i in range(n):\n g[i] = []\n for i in range(n-1):\n u,v = map(int,input().split())\n g[u-1].append(v-1)\n g[v-1].append(u-1)\n \n p = [None]*n\n distance = [-1]*n\n distance[0] = 0\n qu= [0]\n while len(qu):\n u = qu.pop(0)\n for v in g[u]:\n if distance[v] == -1:\n distance[v] = distance[u] + 1 \n p[v] = u\n qu.append(v)\n # print(p)\n # print(distance)\n for q_iter in range(q):\n a,da,b,db = map(int,input().split())\n a -= 1\n b -= 1\n flag = 0\n for i in range(n):\n if dist(a,i) == da and dist(b,i) == db :\n print(i+1)\n flag = 1\n break\n if flag == 0:\n print(-1)\n \n \n \n ", "import numpy as np\n\ndef add(adj,a,b,n):\n adj[a,b] = adj[b,a] = 1\n for i in range(n):\n if adj[a,i]!=-10 and a!=i and b!=i and adj[b,i]==-10:\n adj[b,i] = adj[a,i] + 1\n adj[i,b] = adj[b,i]\n for i in range(n):\n if adj[b,i]!=-10 and b!=i and a!=i and adj[a,i]==-10:\n adj[a,i] = adj[b,i] + 1\n adj[i,a] = adj[a,i]\n return adj\nt = int(input())\nwhile t>0 :\n n,q = map(int,input().split())\n adj = np.zeros((n,n),dtype = 'int')\n adj += np.array([-10])\n for i in range(n):\n adj[i,i] = 0\n for i in range(1,n):\n a,b = map(int,input().split())\n adj = add(adj,a-1,b-1,n)\n for _ in range(q):\n a,da,b,db = map(int,input().split())\n x = -1\n for i in range(n):\n if adj[a-1,i] == da and adj[b-1,i] == db:\n x = i + 1\n break\n print(x)\n t -= 1\n\n", "\nimport numpy as np\n\ndef add(adj,a,b,n):\n adj[a,b] = adj[b,a] = 1\n for i in range(n):\n if adj[a,i]!=-10 and a!=i and b!=i and adj[b,i]==-10:\n adj[b,i] = adj[a,i] + 1\n adj[i,b] = adj[b,i]\n for i in range(n):\n if adj[b,i]!=-10 and b!=i and a!=i and adj[a,i]==-10:\n adj[a,i] = adj[b,i] + 1\n adj[i,a] = adj[a,i]\n return adj\n\nt = int(input())\nwhile t>0 :\n n,q = map(int,input().split())\n adj = np.zeros((n,n),dtype = 'int')\n adj += np.array([-10])\n for i in range(n):\n adj[i,i] = 0\n for i in range(1,n):\n a,b = map(int,input().split())\n adj = add(adj,a-1,b-1,n)\n for _ in range(q):\n a,da,b,db = map(int,input().split())\n x = -1\n for i in range(n):\n if adj[a-1,i] == da and adj[b-1,i] == db:\n x = i + 1\n break\n print(x)\n t -= 1", "\nimport numpy as np\n\ndef add(adj,a,b,n):\n adj[a,b] = adj[b,a] = 1\n for i in range(n):\n if adj[a,i]!=-10 and a!=i and b!=i and adj[b,i]==-10:\n adj[b,i] = adj[a,i] + 1\n adj[i,b] = adj[b,i]\n for i in range(n):\n if adj[b,i]!=-10 and b!=i and a!=i and adj[a,i]==-10:\n adj[a,i] = adj[b,i] + 1\n adj[i,a] = adj[a,i]\n return adj\n\nt = int(input())\nwhile t>0 :\n n,q = map(int,input().split())\n adj = np.zeros((n,n),dtype = 'int')\n adj += np.array([-10])\n for i in range(n):\n adj[i,i] = 0\n for i in range(1,n):\n a,b = map(int,input().split())\n adj = add(adj,a-1,b-1,n)\n for _ in range(q):\n a,da,b,db = map(int,input().split())\n x = -1\n for i in range(n):\n if adj[a-1,i] == da and adj[b-1,i] == db:\n x = i + 1\n break\n print(x)\n t -= 1", "# cook your dish here\r\nimport numpy as np\r\n\r\ndef add(adj,a,b,n):\r\n adj[a,b] = adj[b,a] = 1\r\n for i in range(n):\r\n if adj[a,i]!=-10 and a!=i and b!=i and adj[b,i]==-10:\r\n adj[b,i] = adj[a,i] + 1\r\n adj[i,b] = adj[b,i]\r\n for i in range(n):\r\n if adj[b,i]!=-10 and b!=i and a!=i and adj[a,i]==-10:\r\n adj[a,i] = adj[b,i] + 1\r\n adj[i,a] = adj[a,i]\r\n return adj\r\n\r\nt = int(input())\r\nwhile t>0 :\r\n n,q = map(int,input().split())\r\n adj = np.zeros((n,n),dtype = 'int')\r\n adj += np.array([-10])\r\n for i in range(n):\r\n adj[i,i] = 0\r\n for i in range(1,n):\r\n a,b = map(int,input().split())\r\n adj = add(adj,a-1,b-1,n)\r\n for _ in range(q):\r\n a,da,b,db = map(int,input().split())\r\n x = -1\r\n for i in range(n):\r\n if adj[a-1,i] == da and adj[b-1,i] == db:\r\n x = i + 1\r\n break\r\n print(x)\r\n t -= 1", "# cook your dish here\nimport numpy as np\n\ndef add(adj,a,b,n):\n adj[a,b] = adj[b,a] = 1\n for i in range(n):\n if adj[a,i]!=-10 and a!=i and b!=i and adj[b,i]==-10:\n adj[b,i] = adj[a,i] + 1\n adj[i,b] = adj[b,i]\n for i in range(n):\n if adj[b,i]!=-10 and b!=i and a!=i and adj[a,i]==-10:\n adj[a,i] = adj[b,i] + 1\n adj[i,a] = adj[a,i]\n return adj\n\nt = int(input())\nwhile t>0 :\n n,q = map(int,input().split())\n adj = np.zeros((n,n),dtype = 'int')\n adj += np.array([-10])\n for i in range(n):\n adj[i,i] = 0\n for i in range(1,n):\n a,b = map(int,input().split())\n adj = add(adj,a-1,b-1,n)\n for _ in range(q):\n a,da,b,db = map(int,input().split())\n x = -1\n for i in range(n):\n if adj[a-1,i] == da and adj[b-1,i] == db:\n x = i + 1\n break\n print(x)\n t -= 1", "\n# cook your dish here\nimport numpy as np\n\ndef add(adj,a,b,n):\n adj[a,b] = adj[b,a] = 1\n for i in range(n):\n if adj[a,i]!=-10 and a!=i and b!=i and adj[b,i]==-10:\n adj[b,i] = adj[a,i] + 1\n adj[i,b] = adj[b,i]\n for i in range(n):\n if adj[b,i]!=-10 and b!=i and a!=i and adj[a,i]==-10:\n adj[a,i] = adj[b,i] + 1\n adj[i,a] = adj[a,i]\n return adj\n\nt = int(input())\nwhile t>0 :\n n,q = map(int,input().split())\n adj = np.zeros((n,n),dtype = 'int')\n adj += np.array([-10])\n for i in range(n):\n adj[i,i] = 0\n for i in range(1,n):\n a,b = map(int,input().split())\n adj = add(adj,a-1,b-1,n)\n for _ in range(q):\n a,da,b,db = map(int,input().split())\n x = -1\n for i in range(n):\n if adj[a-1,i] == da and adj[b-1,i] == db:\n x = i + 1\n break\n print(x)\n t -= 1", "# cook your dish here\n# cook your dish here\nimport numpy as np\n\ndef add(adj,a,b,n):\n adj[a,b] = adj[b,a] = 1\n for i in range(n):\n if adj[a,i]!=-10 and a!=i and b!=i and adj[b,i]==-10:\n adj[b,i] = adj[a,i] + 1\n adj[i,b] = adj[b,i]\n for i in range(n):\n if adj[b,i]!=-10 and b!=i and a!=i and adj[a,i]==-10:\n adj[a,i] = adj[b,i] + 1\n adj[i,a] = adj[a,i]\n return adj\n\nt = int(input())\nwhile t>0 :\n n,q = map(int,input().split())\n adj = np.zeros((n,n),dtype = 'int')\n adj += np.array([-10])\n for i in range(n):\n adj[i,i] = 0\n for i in range(1,n):\n a,b = map(int,input().split())\n adj = add(adj,a-1,b-1,n)\n for _ in range(q):\n a,da,b,db = map(int,input().split())\n x = -1\n for i in range(n):\n if adj[a-1,i] == da and adj[b-1,i] == db:\n x = i + 1\n break\n print(x)\n t -= 1", "# cook your dish here\n# cook your dish here\nimport numpy as np\n\ndef add(adj,a,b,n):\n adj[a,b] = adj[b,a] = 1\n for i in range(n):\n if adj[a,i]!=-10 and a!=i and b!=i and adj[b,i]==-10:\n adj[b,i] = adj[a,i] + 1\n adj[i,b] = adj[b,i]\n for i in range(n):\n if adj[b,i]!=-10 and b!=i and a!=i and adj[a,i]==-10:\n adj[a,i] = adj[b,i] + 1\n adj[i,a] = adj[a,i]\n return adj\n\nt = int(input())\nwhile t>0 :\n n,q = map(int,input().split())\n adj = np.zeros((n,n),dtype = 'int')\n adj += np.array([-10])\n for i in range(n):\n adj[i,i] = 0\n for i in range(1,n):\n a,b = map(int,input().split())\n adj = add(adj,a-1,b-1,n)\n for _ in range(q):\n a,da,b,db = map(int,input().split())\n x = -1\n for i in range(n):\n if adj[a-1,i] == da and adj[b-1,i] == db:\n x = i + 1\n break\n print(x)\n t -= 1", "# cook your dish here\nimport numpy as np\n\ndef add(adj,a,b,n):\n adj[a,b] = adj[b,a] = 1\n for i in range(n):\n if adj[a,i]!=-10 and a!=i and b!=i and adj[b,i]==-10:\n adj[b,i] = adj[a,i] + 1\n adj[i,b] = adj[b,i]\n for i in range(n):\n if adj[b,i]!=-10 and b!=i and a!=i and adj[a,i]==-10:\n adj[a,i] = adj[b,i] + 1\n adj[i,a] = adj[a,i]\n return adj\n\nt = int(input())\nwhile t>0 :\n n,q = map(int,input().split())\n adj = np.zeros((n,n),dtype = 'int')\n adj += np.array([-10])\n for i in range(n):\n adj[i,i] = 0\n for i in range(1,n):\n a,b = map(int,input().split())\n adj = add(adj,a-1,b-1,n)\n for _ in range(q):\n a,da,b,db = map(int,input().split())\n x = -1\n for i in range(n):\n if adj[a-1,i] == da and adj[b-1,i] == db:\n x = i + 1\n break\n print(x)\n t -= 1", "# cook your dish here\nimport numpy as np\n\ndef add(adj,a,b,n):\n adj[a,b] = adj[b,a] = 1\n for i in range(n):\n if adj[a,i]!=-10 and a!=i and b!=i and adj[b,i]==-10:\n adj[b,i] = adj[a,i] + 1\n adj[i,b] = adj[b,i]\n for i in range(n):\n if adj[b,i]!=-10 and b!=i and a!=i and adj[a,i]==-10:\n adj[a,i] = adj[b,i] + 1\n adj[i,a] = adj[a,i]\n return adj\n\nt = int(input())\nwhile t>0 :\n n,q = map(int,input().split())\n adj = np.zeros((n,n),dtype = 'int')\n adj += np.array([-10])\n for i in range(n):\n adj[i,i] = 0\n for i in range(1,n):\n a,b = map(int,input().split())\n adj = add(adj,a-1,b-1,n)\n for _ in range(q):\n a,da,b,db = map(int,input().split())\n x = -1\n for i in range(n):\n if adj[a-1,i] == da and adj[b-1,i] == db:\n x = i + 1\n break\n print(x)\n t -= 1\n"]
{"inputs": [["1", "5 3", "1 2", "2 3", "3 4", "3 5", "2 1 4 1", "2 2 4 2", "1 1 2 1"]], "outputs": [["3", "5", "-1"]]}
INTERVIEW
PYTHON3
CODECHEF
29,535
6a1822b9dab07393f517da0615e50351
UNKNOWN
Chef recently printed directions from his home to a hot new restaurant across the town, but forgot to print the directions to get back home. Help Chef to transform the directions to get home from the restaurant. A set of directions consists of several instructions. The first instruction is of the form "Begin on XXX", indicating the street that the route begins on. Each subsequent instruction is of the form "Left on XXX" or "Right on XXX", indicating a turn onto the specified road. When reversing directions, all left turns become right turns and vice versa, and the order of roads and turns is reversed. See the sample input for examples. -----Input----- Input will begin with an integer T, the number of test cases that follow. Each test case begins with an integer N, the number of instructions in the route. N lines follow, each with exactly one instruction in the format described above. -----Output----- For each test case, print the directions of the reversed route, one instruction per line. Print a blank line after each test case. -----Constraints----- - 1 ≤ T ≤ 15 - 2 ≤ N ≤ 40 - Each line in the input will contain at most 50 characters, will contain only alphanumeric characters and spaces and will not contain consecutive spaces nor trailing spaces. By alphanumeric characters we mean digits and letters of the English alphabet (lowercase and uppercase). -----Sample Input----- 2 4 Begin on Road A Right on Road B Right on Road C Left on Road D 6 Begin on Old Madras Road Left on Domlur Flyover Left on 100 Feet Road Right on Sarjapur Road Right on Hosur Road Right on Ganapathi Temple Road -----Sample Output----- Begin on Road D Right on Road C Left on Road B Left on Road A Begin on Ganapathi Temple Road Left on Hosur Road Left on Sarjapur Road Left on 100 Feet Road Right on Domlur Flyover Right on Old Madras Road -----Explanation----- In the first test case, the destination lies on Road D, hence the reversed route begins on Road D. The final turn in the original route is turning left from Road C onto Road D. The reverse of this, turning right from Road D onto Road C, is the first turn in the reversed route.
["t = int(input())\n\nfor i in range(t):\n n = int(input())\n dir = []\n \n for j in range(n):\n dir.append(input().strip().split())\n \n for j in range(n-1):\n if dir[j+1][0] == 'Right':\n dir[j][0] = 'Left'\n else:\n dir[j][0] = 'Right'\n\n dir[n-1][0] = 'Begin'\n\n for j in reversed(dir):\n print(' '.join(j))\n\n\n \n", "# -*- coding: utf-8 -*-\n\"\"\"\nCreated on Sun Dec 23 22:17:11 2012\n\n@author: anant\n\"\"\"\n\nT = int(input())\nfor i in range(0,T):\n l = []\n l2 = []\n n = int(input())\n for j in range(0,n):\n l.append(input())\n length = len(l)\n word = l[length-1].split();\n direction = word[0]\n city = l[length-1][l[length-1].find(\"on\")+3:]\n temp = \"Begin on \"+city\n l2.append(temp)\n for i in range(2,length+1):\n \n word = l[length-i].split();\n if direction == \"Right\":\n direction = \"Left\"\n else:\n direction = \"Right\"\n city = l[length-i][l[length-i].find(\"on\")+3:]\n temp = direction + \" on \"+city\n l2.append(temp)\n \n direction = word[0]\n # l2.append(direction + \"on\" + l[length-i][])\n \n for sentence in l2:\n print(sentence)\n print(\"\")\n \n \n \n \n", "a=int(eval(input()))\nfor i in range(0,a):\n n=eval(input())\n k=n\n word=[]\n for j in range(0,n):\n t=input()\n word.append(t)\n l=[]\n flag=0\n for j in range(k-1,-1,-1):\n l=word[j].split()\n \n if(j==k-1):\n print(\"Begin\", end=' ')\n elif(right==0):\n print(\"Right\", end=' ')\n elif(right==1): \n print(\"Left\", end=' ')\n \n if(l[0]=='Left'):\n right=0\n elif(l[0]=='Right'):\n right=1\n for index in range (1,len(l)-1):\n print(l[index], end=' ')\n print(l[index+1])\n print() \n # print l\n#print word[0].split()\n ", "a=int(eval(input()))\nfor i in range(0,a):\n n=eval(input())\n k=n\n word=[]\n for j in range(0,n):\n t=input()\n word.append(t)\n l=[]\n flag=0\n for j in range(k-1,-1,-1):\n l=word[j].split()\n \n if(j==k-1):\n print(\"Begin\", end=' ')\n elif(right==0):\n print(\"Right\", end=' ')\n elif(right==1): \n print(\"Left\", end=' ')\n \n if(l[0]=='Left'):\n right=0\n elif(l[0]=='Right'):\n right=1\n for index in range (1,len(l)-1):\n print(l[index], end=' ')\n print(l[index+1])\n print() \n # print l\n#print word[0].split()\n ", "# Reverse Directions problem - Dec Cook off on Code Chef\nimport sys\n\nclass Directions:\n\t\n\tReversedDirections=[]\n\tReversedDirLines=[]\n\n\tdef __init__(self,dirLines,directions):\n\t\tself.DirLines=dirLines\n\t\tself.Directions=directions\n\t\t\ndef FormReversedDirLines(d):\n\ti=-1\n\tj=0\n\tReversedDirLines=[]\n\twhile i>=(-1*len(d.DirLines)):\n\t\tdirection=d.ReversedDirections[j]\n\t\tt=' '.join(d.DirLines[i].split()[1:])\n\t\tReversedDirLines.append(direction+' '+t)\n\t\ti=i-1\n\t\tj=j+1\n\treturn ReversedDirLines\n\n\ndef CorrectDirections(directions):\n\tcorrectedDirs=[directions[0]]\n\tfor d in directions[1:]:\n\t\tif d==\"Right\":\n\t\t\tcorrectedDirs.append(\"Left\")\n\t\telse:\n\t\t\tcorrectedDirs.append(\"Right\")\n\treturn correctedDirs\n\ndef Reverse(l):\n\tnewL=[]\n\ti=-1\n\twhile i>=(-1*len(l)):\n\t\tnewL.append(l[i])\n\t\ti=i-1\n\treturn newL\n\ndef RightCircularShift(l):\n\tnewL=l[1:]\n\tnewL.append(l[0])\n\treturn newL\n\n\ndef ReverseDirections(Directions):\n\trShiftDirs=RightCircularShift(Directions)\n\treverse=Reverse(rShiftDirs)\n\treverse=CorrectDirections(reverse)\n\treturn reverse\n\ndef WriteOutput(fPath,output):\n\tf=open(fPath,\"w\")\n\tfor d in output:\n\t\tf.writelines(d.ReversedDirLines)\n\t\tf.write('\\n')\n\tf.close()\n\ndef WriteOutputToConsole(output):\n\tfor d in output:\n\t\tfor l in d.ReversedDirLines:\n\t\t\tprint(l)\n\t\tprint('')\n\ndef GetDirectionsFromLines(lines):\n\tdirections=[]\n\tfor l in lines:\n\t\tdirections.append(l.split()[0])\n\treturn directions\n\ndef ReadInputFromConsole():\n\tlines=[]\n\tk=input()\n\twhile k!='':\n\t\tlines.append(k)\n\t\tk=input()\n\treturn ParseInput(lines)\n\ndef ParseInput(lines):\n\tnCases=int(lines[0])\n\tparsedLines=[]\n\tprev=0\n\ti=0\n\twhile i<nCases:\n\t\tnumLineIndex=prev+1\n\t\tnDirLines=int(lines[numLineIndex])\n\t\tparsedLines.append(lines[numLineIndex+1:numLineIndex+1+nDirLines])\n\t\ti=i+1\n\t\tprev=prev+1+nDirLines\n\tinputDirs=[]\n\tfor p in parsedLines:\n\t\tdirLines=p\n\t\tdirections=GetDirectionsFromLines(p)\n\t\tinputDirs.append(Directions(dirLines,directions))\n\treturn inputDirs\n\ndef ReadInput(fPath):\n\tf=open(fPath,\"r\")\n\tlines=f.readlines()\n\tf.close()\n\treturn ParseInput(lines)\t\t\n\ndef __starting_point():\n\t# TestCases\n\t#print ReverseDirections([\"Begin\", \"Right\", \"Right\", \"Left\"])\n\t#print ReverseDirections([\"Begin\",\"Left\",\"Left\",\"Right\",\"Right\",\"Right\"])\n\tdirections=ParseInput(sys.stdin.readlines())\n\tfor d in directions:\n\t\td.ReversedDirections=ReverseDirections(d.Directions)\n\t\td.ReversedDirLines=FormReversedDirLines(d)\n\n\tWriteOutputToConsole(directions)\n\t\n\n__starting_point()", "tc = int(input())\nwhile tc:\n\tn = int(input())\n\n\tdirection = []\n\troad = []\n\n\tfor i in range(0,n):\n\t\tline = input()\n\t\tdirection.append(line[0])\n\n\t\tif line[0] == 'B' or line[0] == 'R':\n\t\t\troad.append(line[9:])\n\t\telse:\n\t\t\troad.append(line[8:])\n\n\tprint('Begin on ' + road[n-1])\n\tfor i in range(0,n-1):\n\t\tif(direction[n-i-1] == 'R'):\n\t\t\top = 'Left on '\n\t\telse:\n\t\t\top = 'Right on '\n\t\tprint(op + road[n-i-2])\n\tprint()\n\n\ttc -= 1", "t=eval(input())\nfor q in range(t):\n\tn=eval(input())\n\ta=[]\n\tfor i in range(n):\n\t\ta.append(input().split())\n\t\ts=''\n\t\tfor x in range(2,len(a[i])):\n\t\t\ts+=' '+a[i][x]\n\t\ta[i][2]=s\n\tans='Begin on'+a[n-1][2]+'\\n'\n\n\ti=n-2\n\twhile i>-1:\n\t\tif a[i+1][0]=='Left':\n\t\t\tans+='Right on'\n\t\telse:\n\t\t\tans+='Left on'\n\t\tans+=a[i][2]+'\\n'\n\t\ti-=1\n\tprint(ans)\n\n", "import sys\n\nt=int(sys.stdin.readline());\nwhile t>0:\n\tdirections=[];\n\tn=int(sys.stdin.readline());\n\tfor i in range(0,n):\n\t\tline=sys.stdin.readline();\n\t\tdirections.append(line);\n\tx=directions[len(directions)-1].split()[2:]\n\tprint(\"Begin on\", end=' ')\n\tfor item in x:\n\t\tprint(item, end=' ')\n\tprint()\n\t\t\n\tfor i in range(len(directions)-2,-1,-1):\n\t\tfirst=directions[i+1].split()[0]\n\t\tx=directions[i].split()[2:]\n\t\tif first==\"Left\":\n\t\t\tfirst=\"Right\"\n\t\telif first==\"Right\":\n\t\t\tfirst=\"Left\"\n\t\tprint(first+\" on\", end=' ')\n\t\tfor item in x:\n\t\t\tprint(item, end=' ')\n\t\tprint()\n\tif t!=1:\t\n\t\tprint()\n\tt -= 1;\n", "n=int(input())\nwhile n>0:\n t=int(input())\n i=t\n a=[]\n while t>0:\n r=input().split()\n a.append(r)\n t-=1\n p=''\n while i>0:\n r=a[i-1]\n j=r[0]\n if t==0:\n r[0]='Begin'\n t=1 \n elif p=='Right':\n r[0]='Left'\n elif p=='Left':\n r[0]='Right'\n r=' '.join(r)\n print(r)\n i-=1\n p=j\n print('\\n')\n n-=1\n", "t = eval(input())\nfor i in range(0, t):\n\tn = eval(input())\n\tdirections = []\n\tfor j in range(0, n):\n\t\tx = input()\n\t\tdirections.append(x)\n\tfor j in range(n-1, -1, -1):\n\t\toutput = \"\"\n\t\tif j == (n-1):\n\t\t\toutput = \"Begin \"\n\t\telse:\n\t\t\tif(directions[j+1].find(\"Left\") == -1):\n\t\t\t\toutput = \"Left \"\n\t\t\telse:\n\t\t\t\toutput = \"Right \"\n\t\toutput = output + directions[j][directions[j].find(\"on\"):]\n\t\tprint(output)\n", "def __starting_point():\n ntc=int(input())\n c=0\n res=[]\n while c<ntc:\n ro=[]\n di=[]\n n=int(input())\n c1=0\n res.append([])\n res[c].append(\"\")\n while c1<n:\n var=input()\n a=var.index(\"on\")\n ro.append(var[a+3:])\n a=var.index(\" \")\n di.append(var[:a])\n c1+=1\n c1=n-2\n res[c][0]=\"Begin on \" +ro[n-1]\n while c1>=0:\n if di[c1+1]==\"Left\":\n res[c].append(\"Right\")\n elif di[c1+1]==\"Right\":\n res[c].append(\"Left\")\n res[c][n-1-c1]=res[c][n-1-c1]+\" \"+\"on\"+\" \"+ro[c1]\n c1-=1\n \n c+=1\n c=0 \n while c<ntc:\n l=len(res[c])\n c1=0\n while(c1<l):\n print(res[c][c1])\n c1+=1\n c+=1\n \n \n \n\n \n \n \n \n \n \n \n\n__starting_point()", "t=int(input())\nlistd=[]\nlistr=[]\nwhile(t):\n n=int(input())\n x=n\n while(n):\n a,b=input().split(' on ')\n listd.append(a)\n listr.append(b)\n n=n-1\n print('Begin on '+listr.pop())\n listd.pop(0)\n x=x-1\n while(x):\n temp=listd.pop()\n if(temp=='Left'):\n print('Right on '+listr.pop())\n else:\n print('Left on '+listr.pop())\n x=x-1\n print('')\n t=t-1", "cases = int(input())\nfor case in range (cases):\n N = int(input())\n A = []\n B = []\n for n in range (N):\n x,y = input().split(\" on \")\n A.append(x)\n B.append(y)\n x = n\n y = n-1\n print(A[0],'on',B[n])\n for y in range (N-1,0,-1):\n if (A[x] == \"Right\"):\n print(\"Left on\",B[y-1])\n else:\n print(\"Right on\",B[y-1])\n x-=1\n if (case != cases-1):\n print(\"\")\n", "T=int(input())\n\nfor _ in range(T):\n N=int(input())\n road=[]\n for _ in range(N):\n t=input()\n if t[0]=='B':\n road.append(('B',t[5:]))\n elif t[0]=='R':\n road.append(('R',t[5:]))\n else:\n road.append(('L',t[4:]))\n for x in range(N):\n Tprev, temp=road.pop()\n if x == 0:\n print('Begin' + temp)\n else:\n if prev == 'L':\n print('Right' + temp)\n else:\n print('Left' + temp)\n prev=Tprev\n print()\n", "import sys\nt = int( input() )\nwhile t > 0:\n\tn = int( input() )\n\tins = []\n\twhile n > 0:\n\t\ts = input()\n\t\tins.append(s)\n\t\tn -= 1\n\tidx = len(ins) - 2\n\tif ins[idx + 1].startswith('Left'):\n\t\tprint('Begin' + ins[idx + 1][4:])\n\telse:\n\t\tprint('Begin' + ins[idx + 1][5:])\n\t\n\twhile idx >= 0:\n\t\tif ins[idx + 1].startswith('Left'):\n\t\t\tif ins[idx].startswith('Left'):\n\t\t\t\tprint('Right' + ins[idx][4:])\n\t\t\telse:\n\t\t\t\tprint('Right' + ins[idx][5:])\n\t\telse:\n\t\t\tif ins[idx].startswith('Left'):\n\t\t\t\tprint('Left' + ins[idx][4:])\n\t\t\telse:\n\t\t\t\tprint('Left' + ins[idx][5:])\n\t\tidx -= 1\n\tprint('')\n\tt -= 1\n", "x=int(input())\nfor i in range(0,x):\n\ty=int(input())\n\tlist=[]\n\tfor p in range(0,y):\n\t\tm=input()\n\t\tlist.append(m)\n\tlistans=[]\n\ts=list[y-1]\n\ts=s.split(\" \")\n\ts[0]=\"Begin\"\n\tq=\"\"\n\tflag=0\n\tfor r in s:\n\t\tif flag==1:\n\t\t\tq=q+\" \"\n\t\telse:\n\t\t\tflag=1\n\t\tq=q+r\n\t\t\n#\tprint q\n\n\tlistans.append(q)\n\tlistk=[]\n\tfor p in range(0,y-1):\n\t\tq=\"\"\n\t\tflag=0\n\t\ts=list[p]\n\t\tr=list[p+1]\n\t\tr=r.split(\" \")\n\t\ts=s.split(\" \")\n\t\tif r[0]==\"Right\":\n\t\t\ts[0]=\"Left\"\n\t\telse:\n\t\t\ts[0]=\"Right\"\n\t\tfor r in s:\n\t\t\tif flag==1:\n\t\t\t\tq=q+\" \"\n\t\t\telse:\n\t\t\t\tflag=1\n\t\t\tq=q+r\n\t\t#print q\n\t\tlistk.append(q)\n\tfor z in range(0,len(listk)):\n\t\tlistans.append(listk[len(listk)-1-z])\n\tfor z in listans:\n\t\tprint(z)\n\n", "import sys\n\nline = sys.stdin.readline()\n\nt = int(line)\n\nfor i in range(0,t):\n\tline = sys.stdin.readline();\n\tn = int(line);\n\tr = []\n\tlr = []\n\tline = sys.stdin.readline();\n\tline = line.strip()\n\t#print(\"line \" , line);\n\tr.append(line[9:])\n\tlr.append(-1)\n\tfor j in range(1,n):\n\t\tline = sys.stdin.readline()\n\t\tline = line.strip()\n\t\tif (line[0:7] == \"Left on\"):\n\t\t\tlr.append(0)\n\t\t\tr.append(line[8:])\n\t\t\t#print(lr)\n\t\t\t#print(r)\n\t\telse:\n\t\t\tlr.append(1)\n\t\t\tr.append(line[9:])\n\t\t\t#print(lr)\n\t\t\t#print(r)\n\tprint(\"Begin on \" + r[n-1])\n\tj = n - 1;\n\twhile j > 0:\n\t\tif (lr[j]):\n\t\t\tprint(\"Left on \" + r[j-1])\n\t\telse:\n\t\t\tprint(\"Right on \" + r[j-1])\n\t\tj = j - 1\n\tprint(\"\")\n", "def opp(a):\n if a==\"Right\":\n return \"Left\"\n else:\n return \"Right\"\ndef main():\n t=int(input())\n while(t):\n t-=1\n n=int(input())\n a=[]\n for i in range(n):\n a.append(list(_ for _ in input().split(' on ')))\n a.reverse()\n print(\"Begin on\", a[0][1])\n for i in range(1,n):\n print(opp(a[i-1][0]),\"on\",a[i][1])\n print(\"\")\nmain()", "import sys\n\nt = int(sys.stdin.readline())\n\nfor test in range(t):\n n = int(sys.stdin.readline())\n lines = [sys.stdin.readline().strip() for i in range(n)]\n turns = [x.split()[0] for x in lines][1:][::-1]\n turns = ['Right' if t == 'Left' else 'Left' for t in turns]\n turns = ['Begin'] + turns\n lines = lines[::-1]\n for i in range(n):\n print(turns[i], ' '.join(lines[i].split()[1:]))\n \n print()\n\n \n", "t=eval(input())\nfor x in range (0,t):\n\tn=eval(input())\n\ta=[]\n\tfor i in range (0,n):\n\t\ta.append(input())\n\tc=a[n-1][0]\n\ta[n-1]=a[n-1].replace(\"Left\",\"Begin\")\n\ta[n-1]=a[n-1].replace(\"Right\",\"Begin\")\n\tprint(a[n-1])\n\tfor i in range (1,n-1):\n\t\tif(c=='R'):\n\t\t\tc=a[n-1-i][0]\n\t\t\ta[n-1-i]=a[n-1-i].replace(\"Right\",\"Left\")\n\t\telse:\n\t\t\tc=a[n-1-i][0]\n\t\t\ta[n-1-i]=a[n-1-i].replace(\"Left\",\"Right\")\n\t\tprint(a[n-1-i])\n\tif(c=='L'):\n\t\ta[0]=a[0].replace(\"Begin\",\"Right\")\n\telse:\n\t\ta[0]=a[0].replace(\"Begin\",\"Left\")\n\tprint(a[0])\n\t\t\n", "import math\nimport sys\ndef comp(x):\n\tif(x==\"Left\"):return \"Right\"\n\telif(x==\"Right\"):return \"Left\"\n\treturn x\ny=[\"\"]*45\ntest=int(eval(input()))\nfor i in range(test):\n\tn=int(eval(input()))\n\tfor j in range(n):\n\t\ty[j]=input()\n\tprev=\"Begin\"\n\tfor j in range(n):\n\t\tx=y[n-j-1].split()\n\t\tprint(comp(prev), end=' ')\n\t\tfor f in x[1:]:\n\t\t\tprint(f, end=' ')\n\t\tprint() \n\t\tprev=x[0]\n\t\t", "#!/usr/bin/python\n\ndef main():\n\tt = int(input())\n\twhile t:\n\t\tn= int(input())\n\t\tlst = []\n\t\tfor i in range(0,n):\n\t\t\ttemp = input()\n\t\t\ttemp = temp.split()\n\t\t\tlst.append(temp)\n\t\tprint(\"Begin on\", end=' ')\n\t\tl = len(lst)\n\t\tfor i in range(0, len(lst[l-1]) - 3):\n\t\t\tprint(lst[l-1][i+2], end=' ')\n\t\tprint(lst[l-1][len(lst[l-1]) - 1])\n\n\t\tfor i in range(1,l):\n\t\t\tind = l - i - 1\n\t\t\tif lst[ind+1][0] == \"Left\":\n\t\t\t\tprint(\"Right on\", end=' ')\n\t\t\telse :\n\t\t\t\tprint(\"Left on\", end=' ')\n\t\t\tfor j in range(0,len(lst[ind])-3):\n\t\t\t\tprint(lst[ind][j+2], end=' ')\n\t\t\tprint(lst[ind][len(lst[ind]) - 1])\n\n\t\t \n\t\tt = t - 1\n\n\ndef __starting_point():\n main()\n\n__starting_point()", "\nT = int(input())\nfor t in range(T):\n\tN = int(input())\n\tp = []\n\tq = []\n\tfor n in range(N):\n\t\tx = input().split()\n\t\tif x[0] == 'Right':\n\t\t\tp.append('Left')\n\t\telif x[0] == 'Left':\n\t\t\tp.append('Right')\n\t\tq.append(' '.join(x[2:]))\n\tp.append('Begin')\n\tfor n in range(N):\n\t\tprint(p[-1-n], 'on', q[-1-n])\n\tprint()", "T = int(input())\nfor i in range(T):\n N = int(input())\n strs = []\n for j in range(N):\n strs.append(input())\n strs = list(reversed(strs))\n prev = None\n for index, direction in enumerate(strs):\n if index == 0:\n s = direction.split()\n print('Begin ' + ' '. join(s[1:]))\n prev = direction\n continue\n if prev.startswith('Left'):\n print('Right ' + ' '. join(direction.split()[1:]))\n else:\n print('Left ' + ' '. join(direction.split()[1:]))\n prev = direction\n"]
{"inputs": [["2", "4", "Begin on Road A", "Right on Road B", "Right on Road C", "Left on Road D", "6", "Begin on Old Madras Road", "Left on Domlur Flyover", "Left on 100 Feet Road", "Right on Sarjapur Road", "Right on Hosur Road", "Right on Ganapathi Temple Road", ""]], "outputs": [["Begin on Road D", "Right on Road C", "Left on Road B", "Left on Road A", "", "Begin on Ganapathi Temple Road", "Left on Hosur Road", "Left on Sarjapur Road", "Left on 100 Feet Road", "Right on Domlur Flyover", "Right on Old Madras Road"]]}
INTERVIEW
PYTHON3
CODECHEF
16,435
e194c38bfa5ed9fdc6ad8a08b4363282
UNKNOWN
For her next karate demonstration, Ada will break some bricks. Ada stacked three bricks on top of each other. Initially, their widths (from top to bottom) are $W_1, W_2, W_3$. Ada's strength is $S$. Whenever she hits a stack of bricks, consider the largest $k \ge 0$ such that the sum of widths of the topmost $k$ bricks does not exceed $S$; the topmost $k$ bricks break and are removed from the stack. Before each hit, Ada may also decide to reverse the current stack of bricks, with no cost. Find the minimum number of hits Ada needs in order to break all bricks if she performs the reversals optimally. You are not required to minimise the number of reversals. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first and only line of each test case contains four space-separated integers $S$, $W_1$, $W_2$ and $W_3$. -----Output----- For each test case, print a single line containing one integer ― the minimum required number of hits. -----Constraints----- - $1 \le T \le 64$ - $1 \le S \le 8$ - $1 \le W_i \le 2$ for each valid $i$ - it is guaranteed that Ada can break all bricks -----Subtasks----- Subtask #1 (50 points): $W_1 = W_2 = W_3$ Subtask #2 (50 points): original constraints -----Example Input----- 3 3 1 2 2 2 1 1 1 3 2 2 1 -----Example Output----- 2 2 2 -----Explanation----- Example case 1: Ada can reverse the stack and then hit it two times. Before the first hit, the widths of bricks in the stack (from top to bottom) are $(2,2,1)$. After the first hit, the topmost brick breaks and the stack becomes $(2,1)$. The second hit breaks both remaining bricks. In this particular case, it is also possible to hit the stack two times without reversing. Before the first hit, it is $(1, 2, 2)$. The first hit breaks the two bricks at the top (so the stack becomes $(2)$) and the second hit breaks the last brick.
["t=int(input())\nfor i in range(t):\n n,w1,w2,w3=map(int,input().split())\n if n>=w1+w2+w3:\n print(1)\n elif n>=w1+w2 or n>=w2+w3:\n print(2)\n else:\n print(3)", "t=int(input())\nfor i in range(t):\n n,w1,w2,w3=map(int,input().split())\n if n>=w1+w2+w3:\n print(1)\n elif n>=w1+w2 or n>=w2+w3:\n print(2)\n else:\n print(3)", "t = int(input())\nfor i in range(t):\n n,w1,w2,w3 = map(int,input().split())\n if n >= w1+w2+w3:\n print(1)\n elif n >= w1+w2 or n >= w2+w3:\n print(2)\n else:\n print(3)", "t = int(input())\nfor i in range(t):\n n,w1,w2,w3 = map(int,input().split())\n if n >= w1+w2+w3:\n print(1)\n elif n >= w1+w2 or n >= w2+w3:\n print(2)\n else:\n print(3)", "# cook your dish here\nt = int(input())\nfor i in range(t):\n n,w1,w2,w3 = list(map(int,input().split()))\n if n >= w1+w2+w3:\n print(1)\n elif n >= w1+w2 or n >= w2+w3:\n print(2)\n else:\n print(3)\n \n \n \n", "# cook your dish here\nfor i in range(int(input())):\n s,w1,w2,w3=list(map(int,input().split()))\n if(s>=w1+w2+w3):\n print(1)\n elif(s>=w1+w2 or s>=w2+w3):\n print(2)\n else:\n print(3)\n \n", "# cook your dish here\nfor t in range(int(input())):\n s,w1,w2,w3=list(map(int,input().split()))\n if w1+w2+w3<=s:\n print('1')\n elif w1+w2<=s or w2+w3<=s:\n print('2')\n else:\n print('3')\n", "# cook your dish here\nimport math\nt=int(input())\nwhile t>0:\n s,a,b,c=map(int,input().split())\n if s>=a+b+c:\n print(\"1\")\n elif s>=a+b or s>=b+c:\n print(\"2\")\n else:\n print(\"3\")\n t-=1", "def solve(s, a, b, c):\n if s >= a + b + c:\n return 1\n if s >= a + b:\n return 2\n if s >= b + c:\n return 2\n return 3\n \ndef main():\n t = int(input())# cook your dish here\n \n for _ in range(t):\n line = input().strip()\n s, a,b,c = [int(x) for x in line.split(\" \")]\n print(solve(s, a, b, c))\n \n\nmain()", "for _ in range(int(input())):\n n=list(map(int,input().split()))\n s=n[0]\n w=n[1:]\n c=0\n for i in range(3):\n if sum(w)<=s:\n c=c+1\n break\n elif sum(w[:2])<=s:\n w=w[2:]\n c=c+1\n else:\n w=w[1:]\n c+=1\n print(c)# cook your dish here\n", "for _ in range(int(input())):\n a = list(map(int,input().split()))\n s = a.pop(0)\n sm = sum(a)\n ans = 0\n\n\n while sm>0:\n a1 = a[::-1]\n s1, i = 0, 0\n while s1<s and i<len(a):\n s1+=a[i]\n i+=1\n if s1>s:\n i-=1\n s1-=a[i]\n s2, i1 = 0, 0\n while s2<s and i1<len(a):\n s2+=a1[i1]\n i1+=1\n if s2>s:\n i1-=1\n s2-=a[i1]\n # print(sm, s1, s2, a, i, i1, ans)\n if i1>i:\n sm-=s2\n a = a1[i1:][::-1]\n else:\n sm-=s1\n a = a[i:]\n ans+=1\n print(ans)\n\n\n\n", "for _ in range(int(input())):\n a = list(map(int,input().split()))\n s = a.pop(0)\n sm = sum(a)\n ans = 0\n\n\n while sm>0:\n a1 = a[::-1]\n s1, i = 0, 0\n while s1<s and i<len(a):\n s1+=a[i]\n i+=1\n if s1>s:\n i-=1\n s1-=a[i]\n s2, i1 = 0, 0\n while s2<s and i1<len(a):\n s2+=a1[i1]\n i1+=1\n if s2>s:\n i1-=1\n s2-=a[i1]\n # print(sm, s1, s2, a, i, i1, ans)\n if i1>i:\n sm-=s2\n a = a1[i1:][::-1]\n else:\n sm-=s1\n a = a[i:]\n ans+=1\n print(ans)\n\n\n\n", "for _ in range(int(input())):\n s,w1,w2,w3= map(int,input().split())\n if w1+w2+w3<=s:\n ans = 1\n elif w1+w2<=s or w2+w3<=s:\n ans = 2\n else:\n ans = 3\n print(ans)", "# cook your dish here\na= int(input())\nwhile (a!=0):\n S,x,y,z=input().split(\" \")\n x=int(x)\n y=int(y)\n z=int(z)\n S=int(S)\n count=0\n if x+y+z<=S:\n count=1\n elif (x+y<=S and z<=S) or (y+z<=S and x<=S):\n count=2\n\n else:\n count=3\n print(count)\n a-=1", "# cook your dish here\nfor _ in range(int(input())):\n S,W1,W2,W3=(int(i) for i in input().split(' '))\n if(W1+W2+W3<=S):\n print(1)\n elif(S>=(W1+W2) or S>=(W2+W3)):\n print(2)\n else:\n print(3)", "# cook your dish here\n \nfor _ in range(int(input())):\n L = list(map(int, input().split()))\n S = L[0]\n W = L[1:]\n c = 0\n if W[0] + W[1] <= S:\n if W[0] + W[1] + W[2] <= S:\n print(1)\n else:\n print(2)\n elif W[2] + W[1] <= S:\n print(2)\n else:\n print(3)", "for _ in range(int(input())):\n s,w1,w2,w3=list(map(int,input().split()))\n c=w1+w2+w3\n if s>=c:\n print(1)\n elif w1+w2<=s or w2+w3<=s:\n print(2)\n else:\n print(3)\n \n \n", "# cook your dish here\nfor h in range(int(input())):\n s,w1,w2,w3=map(int,input().split())\n sum1=w1+w2+w3\n if s>=sum1:\n print(1)\n elif s>=(w1+w2)or s>=(w3+w2):\n print(2)\n \n else:\n print(3)", "# cook your dish here\nfor _ in range(int(input())):\n s,w1,w2,w3 = list(map(int,input().split()))\n tot = w1+w2+w3\n if tot<=s :\n print(1)\n elif s == 1 :\n print(3)\n elif s == 2 :\n if tot>=5:\n print(3)\n elif w2 == 2 :\n print(3)\n else :\n print(2)\n elif s == 3 :\n if tot <=5 :\n print(2)\n else :\n print(3)\n else :\n print(2)\n \n", "for _ in range(int(input())):\n s,w1,w2,w3 = list(map(int,input().split()))\n tot = w1+w2+w3\n if tot<=s :\n print(1)\n elif s == 1 :\n print(3)\n elif s == 2 :\n if tot>=5 :\n print(3)\n elif w2 == 2 :\n print(3)\n else :\n print(2)\n elif s == 3 :\n if tot<=5 :\n print(2)\n else :\n print(3)\n else :\n print(2)\n", "for i in range(int(input())):\n s,w1,w2,w3=map(int,input().split())\n c=0\n sum=w1+w2+w3\n if w1<w3:\n tmp=w3\n w3=w1\n w1=tmp\n if w1+w2+w3<=s:\n print(\"1\")\n elif w1+w2<=s:\n print(\"2\")\n elif w1<=s:\n c=c+1\n if c==1:\n if w2+w3<=s:\n print(\"2\")\n elif w2+w3>s:\n print(\"3\")", "# cook your dish here\ntry:\n T=int(input())\n for t in range(T):\n \n w = list(map(int,input().split()))\n s = w.pop(0)\n c=0\n # print(w,s)\n while len(w) > 0:\n r=s\n c+=1\n # print(c,w)\n if w[0] > w[-1]:\n while len(w) > 0 and r >= w[0]:\n r-=w[0]\n w.pop(0)\n else:\n while len(w) > 0 and r >= w[-1]:\n r-=w[-1]\n w.pop(-1) \n print(c)\nexcept:\n pass", "# cook your dish here\ntry:\n T=int(input())\n for t in range(T):\n \n w = list(map(int,input().split()))\n s = w.pop(0)\n c=0\n # print(w,s)\n while len(w) > 0:\n r=s\n c+=1\n # print(c,w)\n if w[0] > w[-1]:\n while len(w) > 0 and r >= w[0]:\n r-=w[0]\n w.pop(0)\n else:\n while len(w) > 0 and r >= w[-1]:\n r-=w[-1]\n w.pop(-1) \n print(c)\nexcept:\n pass", "t = int(input())\n\nfor _ in range(t):\n s, w1, w2, w3 = [int(x) for x in input().split()]\n \n if(w1+w2+w3 <= s):\n print(1)\n elif(w1+w2 <= s or w3+w2 <= s):\n print(2)\n else:\n print(3)"]
{"inputs": [["3", "3 1 2 2", "2 1 1 1", "3 2 2 1"]], "outputs": [["2", "2", "2"]]}
INTERVIEW
PYTHON3
CODECHEF
6,403
28ad298eaf07e60a9f23d0d2184d2ab9
UNKNOWN
Kostya likes the number 4 much. Of course! This number has such a lot of properties, like: - Four is the smallest composite number; - It is also the smallest Smith number; - The smallest non-cyclic group has four elements; - Four is the maximal degree of the equation that can be solved in radicals; - There is four-color theorem that states that any map can be colored in no more than four colors in such a way that no two adjacent regions are colored in the same color; - Lagrange's four-square theorem states that every positive integer can be written as the sum of at most four square numbers; - Four is the maximum number of dimensions of a real division algebra; - In bases 6 and 12, 4 is a 1-automorphic number; - And there are a lot more cool stuff about this number! Impressed by the power of this number, Kostya has begun to look for occurrences of four anywhere. He has a list of T integers, for each of them he wants to calculate the number of occurrences of the digit 4 in the decimal representation. He is too busy now, so please help him. -----Input----- The first line of input consists of a single integer T, denoting the number of integers in Kostya's list. Then, there are T lines, each of them contain a single integer from the list. -----Output----- Output T lines. Each of these lines should contain the number of occurences of the digit 4 in the respective integer from Kostya's list. -----Constraints----- - 1 ≤ T ≤ 105 - (Subtask 1): 0 ≤ Numbers from the list ≤ 9 - 33 points. - (Subtask 2): 0 ≤ Numbers from the list ≤ 109 - 67 points. -----Example----- Input: 5 447474 228 6664 40 81 Output: 4 0 1 1 0
["# cook your dish here\nx=int(input())\nfor i in range(x):\n h=input()\n print(h.count('4'))\n", "t = int(input())\nfor i in range(t):\n v = input()\n l = len(v)\n d =\"4\"\n c = 0\n for i in range(l):\n if(v[i] == d):\n c+=1\n print(c) \n \n \n", "# cook your dish here\n\nn = int(input())\nfor i in range(n):\n number = str(input())\n print(number.count(\"4\"))", "# cook your dish here\nn=int(input())\na=[]\nfor i in range (0,n):\n no=int(input())\n a.append(no)\nfor i in range (0,n):\n c=0\n while (a[i]!=0):\n if (a[i]%10==4):\n c+=1\n a[i]=a[i]//10\n print(c)", "t=eval(input())\n'''for i in range(t):\n s=input()\n print(s.count(\"4\"))\n'''\n\n# second way is\n\nfor i in range(t):\n rem=[]\n n=eval(input())\n while(n>0):\n rem.append(n%10)\n n=n//10\n print(rem.count(4))\n\n", "# cook your dish here\nfrom collections import Counter\nfor _ in range(int(input())):\n n= Counter(input().strip())\n print(n['4'])\n", "n= int(input())\nfor i in range(n):\n s=0\n a=input()\n for j in range(len(a)):\n if a[j]=='4':\n s+=1 \n print(s)", "# cook your dish here\nn = int(input())\nwhile n>0:\n s=input()\n print(len(s.split('4'))-1)\n n = n-1", "# cook your dish here\nfor t in range(int(input())):\n\tn=str(input())\n\tcount=0\n\tfor i in n:\n\t\tif i!=\"4\":\n\t\t\tpass\n\t\telse:\n\t\t\tcount+=1\n\tprint(count)\t\t", "a=str(4)\nfor _ in range(int(input())):\n n=str(input())\n count=0\n for i in n:\n if i==a:\n count+=1\n print(count)", "from collections import Counter\nn=int(input())\nfor i in range(n):\n k=list(input())\n c=Counter(k)\n print(c['4'])", "def four():\r\n n=input()\r\n count=0\r\n for i in n:\r\n if int(i)==0:\r\n continue\r\n else:\r\n if int(i)==4:\r\n count+=1\r\n print(count) \r\n\r\nfor _ in range(int(input())):\r\n four()", "# cook your dish here\ntry:\n t=int(input())\n \n \n while(t!=0):\n t-=1\n n=input()\n \n k=0\n for j in range(0,len(n)):\n if(n[j]=='4'):\n k+=1\n print(k)\n \nexcept:pass ", "# cook your dish here\nn=int(input())\nfor i in range(n):\n s=input()\n c=s.count('4')\n print(c)\n", "n=int(input())\r\nmylist=[]\r\nwhile n>0:\r\n num=input()\r\n count=0\r\n for i in num:\r\n if i=='4':\r\n count+=1\r\n mylist.append(count)\r\n n=n-1\r\nfor i in mylist:\r\n print(i)\r\n \r\n", "t = int(input())\nfor i in range(t):\n a = int(input())\n count = 0\n while a != 0:\n if a % 10 == 4:\n count +=1\n a = a // 10\n print(count)\n \n", "# cook your dish here\nt = int(input())\nwhile t:\n t-=1\n n = input()\n print(n.count('4'))", "n=int(input())\nfor i in range(n):\n a=int(input())\n c=0\n while a:\n r=a%10\n if(r==4):\n c=c+1\n a=a//10\n print(c)", "n=int(input())\nfor i in range(n):\n a=int(input())\n c=0\n while a:\n r=a%10\n if(r==4):\n c=c+1\n a=a//10\n print(c)", "arr=[]\r\nfor a in range(int(input())):\r\n b=list(input())\r\n if \"4\" in b:\r\n arr.append(b.count('4'))\r\n else:\r\n arr.append(0)\r\nprint(*arr, sep='\\n')\r\n", "# cook your dish here\nt = int(input())\nfor i in range(t):\n n = input()\n print(n.count(\"4\"))", "for _ in range (int(input())):\n l = list(input())\n print(l.count('4'))", "\r\n#Read the number of test cases.\r\nT = int(input())\r\nfor tc in range(T):\r\n\t# Read number\r\n\tnum = int(input())\r\n\tcount = 0\r\n\twhile num:\r\n\t rem = num %10\r\n\t if rem ==4:\r\n\t count+=1\r\n\t num = num//10\r\n\tprint(count)", "t=int(input())\ni=0\nwhile i<t:\n i=i+1\n n=int(input())\n sum=0\n \n while n>0:\n if n%10==4:\n sum=sum+1\n n=n//10\n \n else:\n n=n//10\n print(sum) \n"]
{"inputs": [["5", "447474", "228", "6664", "40", "81"]], "outputs": [["4", "0", "1", "1", "0"]]}
INTERVIEW
PYTHON3
CODECHEF
4,130
c98de1998ce052a924c520da2b924da8
UNKNOWN
Every day, Mike goes to his job by a bus, where he buys a ticket. On the ticket, there is a letter-code that can be represented as a string of upper-case Latin letters. Mike believes that the day will be successful in case exactly two different letters in the code alternate. Otherwise, he believes that the day will be unlucky. Please see note section for formal definition of alternating code. You are given a ticket code. Please determine, whether the day will be successful for Mike or not. Print "YES" or "NO" (without quotes) corresponding to the situation. -----Input----- The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows. The first and only line of each test case contains a single string S denoting the letter code on the ticket. -----Output----- For each test case, output a single line containing "YES" (without quotes) in case the day will be successful and "NO" otherwise. -----Note----- Two letters x, y where x != y are said to be alternating in a code, if code is of form "xyxyxy...". -----Constraints----- - 1 ≤ T ≤ 100 - S consists only of upper-case Latin letters Subtask 1 (50 points): - |S| = 2 Subtask 2 (50 points): - 2 ≤ |S| ≤ 100 -----Example----- Input: 2 ABABAB ABC Output: YES NO
["def res(s):\n if len(s) == 2:\n if s[0] == s[1]:\n print(\"NO\")\n else:\n print(\"YES\")\n\n elif s[0] != s[1]:\n counte = 0\n for i in range(2, len(s)):\n if i % 2 == 0:\n if s[i] != s[0]:\n counte = 1\n break\n else:\n if s[i] != s[1]:\n counte = 1\n break\n\n if counte == 0:\n print(\"YES\")\n else:\n print(\"NO\")\n else:\n print(\"NO\")\n\n\ndef __starting_point():\n t = int(input())\n for _ in range(t):\n stri = str(input())\n res(stri)\n__starting_point()", "def res(s):\n if len(s) == 2:\n if s[0] == s[1]:\n print(\"NO\")\n else:\n print(\"YES\")\n\n \n\n else:\n counte = 0\n for i in range(2, len(s)):\n if i % 2 == 0:\n if s[i] != s[0]:\n counte = 1\n break\n else:\n if s[i] != s[1]:\n counte = 1\n break\n\n if counte == 0:\n print(\"YES\")\n else:\n print(\"NO\")\n\n\ndef __starting_point():\n t = int(input())\n for _ in range(t):\n stri = str(input())\n res(stri)# cook your dish here\n\n__starting_point()", "def res(s):\n if len(s) == 2:\n if s[0] == s[1]:\n print(\"NO\")\n else:\n print(\"YES\")\n\n elif len(s) % 2 != 0:\n print(\"NO\")\n\n else:\n counte = 0\n for i in range(2, len(s)):\n if i % 2 == 0:\n if s[i] != s[0]:\n counte = 1\n break\n else:\n if s[i] != s[1]:\n counte = 1\n break\n\n if counte == 0:\n print(\"YES\")\n else:\n print(\"NO\")\n\n\ndef __starting_point():\n t = int(input())\n for _ in range(t):\n stri = str(input())\n res(stri)# cook your dish here\n\n__starting_point()", "def res(s):\n if len(s) == 2:\n if s[0] == s[1]:\n print(\"NO\")\n else:\n print(\"YES\")\n \n elif len(s) % 2 != 0:\n print(\"NO\")\n \n else:\n c1 = s[0]\n c2 = s[1]\n counte = 0\n counto = 0\n for i in range(2, len(s)):\n if i % 2 == 0 and s[i] != c1:\n counte = 1\n break\n elif i % 2 != 0 and s[i] != c2:\n counto = 1\n break\n\n if counte == 0 or counto == 0:\n print(\"YES\")\n \n else:\n print(\"NO\")\n\n\ndef __starting_point():\n t = int(input())\n for _ in range(t):\n stri = str(input())\n res(stri)\n\n__starting_point()", "def res(s):\n if len(s) == 2:\n if s[0] == s[1]:\n print(\"NO\")\n else:\n print(\"YES\")\n \n elif len(s) % 2 != 0:\n print(\"NO\")\n \n else:\n c1 = s[0]\n c2 = s[1]\n counte = 0\n counto = 0\n for i in range(2, len(s)):\n if i % 2 == 0 and s[i] != c1:\n counte = 1\n break\n elif i % 2 != 0 and s[i] != c2:\n counto = 1\n break\n\n if counte != 0 or counto != 0:\n print(\"NO\")\n else:\n print(\"YES\")\n\n\ndef __starting_point():\n t = int(input())\n for _ in range(t):\n stri = str(input())\n res(stri)\n\n__starting_point()", "def res(s):\n if len(s) == 2:\n if s[0] == s[1]:\n print(\"NO\")\n else:\n print(\"YES\")\n else:\n c1 = s[0]\n c2 = s[1]\n counte = 0\n counto = 0\n for i in range(2, len(s)):\n if i % 2 == 0 and s[i] != c1:\n counte = 1\n break\n elif i % 2 != 0 and s[i] != c2:\n counto = 1\n break\n\n if counte != 0 or counto != 0:\n print(\"NO\")\n else:\n print(\"YES\")\n\n\ndef __starting_point():\n t = int(input())\n for _ in range(t):\n stri = str(input())\n res(stri)\n\n__starting_point()", "for t in range(int(input())):\n string = input()\n n = len(string)\n if n == 1:\n print(\"NO\")\n elif n == 2:\n if string[0] != string[1]:\n print(\"YES\")\n else:\n print(\"NO\")\n elif n > 2:\n first = string[0]\n second = string[1]\n\n if first == second:\n print(\"NO\")\n else:\n flag = 1\n for i in range(2, n):\n if i % 2 != 0:\n if string[i] == second:\n flag = 1\n else:\n flag = 0\n break\n else:\n if string[i] == first:\n flag = 1\n else:\n flag = 0\n break\n if flag == 1 and n == 3:\n print(\"NO\")\n elif flag == 1:\n print(\"YES\")\n else:\n print(\"NO\")", "for t in range(int(input())):\n string = input()\n\n if len(string) == 1:\n print(\"NO\")\n elif len(string) == 2:\n if string[0] != string[1]:\n print(\"YES\")\n else:\n print(\"NO\")\n elif len(string) > 2:\n first = string[0]\n second = string[1]\n\n if first == second:\n print(\"NO\")\n else:\n flag = 1\n for i in range(2, len(string)):\n if i % 2 != 0:\n if string[i] == second:\n flag = 1\n else:\n flag = 0\n break\n else:\n if string[i] == first:\n flag = 1\n else:\n flag = 0\n break\n if flag == 1:\n print(\"YES\")\n else:\n print(\"NO\")", "# cook your dish here\nfor t in range(int(input())):\n string = input()\n\n if len(string) == 1:\n print(\"YES\")\n elif len(string) == 2:\n if string[0] != string[1]:\n print(\"YES\")\n else:\n print(\"NO\")\n elif len(string) > 2:\n first = string[0]\n second = string[1]\n\n if first == second:\n print(\"NO\")\n else:\n flag = 1\n for i in range(2, len(string)):\n if i % 2 != 0:\n if string[i] == second:\n flag = 1\n else:\n flag = 0\n break\n else:\n if string[i] == first:\n flag = 1\n else:\n flag = 0\n break\n if flag == 1:\n print(\"YES\")\n else:\n print(\"NO\")", "# cook your dish here\nt=int(input())\nwhile(t):\n x=input()\n a=len(x)\n if a==1:\n print(\"NO\")\n \n elif a==2:\n if x[0]==x[1]:\n print(\"NO\")\n else:\n print(\"YES\")\n else:\n if x[0]==x[1]:\n print(\"NO\")\n else:\n for j in range(a-2):\n if x[j]==x[j+2]:\n if j==a-3:\n print(\"YES\")\n break\n else:\n print(\"NO\")\n break\n t-=1\n", "t=int(input())\nfor i in range (t):\n x=input()\n a=len(x)\n if a==1:\n print(\"NO\")\n \n elif a==2:\n if x[0]==x[1]:\n print(\"NO\")\n else:\n print(\"YES\")\n else:\n if x[0]==x[1]:\n print(\"NO\")\n else:\n for j in range(a-2):\n if x[j]==x[j+2]:\n if j==a-3:\n print(\"YES\")\n break\n else:\n pass\n else:\n print(\"NO\")\n break\n", "for i in range(int(input())):\n x=input()\n a=len(x)\n if a==1:\n print(\"NO\")\n \n elif a==2:\n if x[0]==x[1]:\n print(\"NO\")\n else:\n print(\"YES\")\n else:\n if x[0]==x[1]:\n print(\"NO\")\n else:\n for j in range(a-2):\n if x[j]==x[j+2]:\n if j==a-3:\n print(\"YES\")\n break\n else:\n pass\n else:\n print(\"NO\")\n break\n \n \n \n", "# cook your dish here\nfor i in range(int(input())):\n s_1=input()\n a=set(s_1)\n if(len(a)==2):\n print(\"YES\")\n else:\n print(\"NO\")", "# cook your dish here\nt = int(input())\nfor i in range(t):\n s = input()\n p =set(s)\n if len(p)==2:\n print(\"YES\")\n else:\n print(\"NO\")", "# cook your dish here\nt = int(input())\nfor i in range(t):\n s = input()\n l = len(s)\n l1 = l/2\n if l%2==0:\n s1 =\"\"\n a=s[0]\n b=s[1]\n if a!=b:\n s1+=a+b\n if s.count(s1)==l1:\n print(\"YES\")\n else:\n print(\"NO\")\n else:\n print(\"NO\")\n else:\n print(\"NO\")", "t=int(input())\nfor i in range(t):\n s=input()\n l=set(s)\n if(len(l)==2):\n print(\"YES\")\n else:\n print(\"NO\")", "# cook your dish here\nt=int(input())\nwhile t:\n t=t-1\n s=set(input())\n if len(s)==2:\n print('YES')\n else:\n print('NO')", "t= int(input())\nfor i in range(t):\n s=set(input())\n if len(s)==2:\n print(\"YES\")\n else:\n print(\"NO\")", "for i in range(int(input())):\n s=set(input())\n if len(s)==2:\n print(\"YES\")\n else:\n print('NO')\n", "# cook your dish here\nfor i in range(int(input())):\n x = input()\n y=set(x)\n #print(y)\n print(\"YES\" if len(y) == 2 else \"NO\")", "# cook your dish here\nfor i in range(int(input())):\n x = input()\n y=set(x)\n if len(y)==2:\n print('YES')\n else:\n print('NO')", "try:\n for _ in range(int(input())):\n s=input()\n s=list(s)\n p=set(s)\n cout=0\n if(len(p)==2):\n for i in range(0,len(s)-1):\n if(s[i]==s[i+1]):\n cout=1\n else:\n cout=1\n if(cout==1):\n print(\"NO\")\n else:\n print(\"YES\")\nexcept:\n pass", "t = int(input())\nfor i in range(t):\n s = input()\n if len(set(s))==2:\n print(\"YES\")\n else:\n print(\"NO\")\n \n \n #long method\n # e=\"\"\n # c=0\n # # if len(s)%2==0 and s[0]!=s[1]:\n # # d=s[0:2]\n # # for i in range(int(len(s)/2)):\n # # d=s[2*i:2*(i+1)]\n # # if i==0:\n # # e=d\n # # # e=s[len(s)-2:len(s)]\n # # if str(d)==str(e):\n # # c+=1\n # # e=d\n # # if c==int(len(s)/2):\n # # print(\"YES\")\n # # elif len(s)==2:\n # # print(\"YES\")\n # # else:\n # # print(\"NO\")\n # # else:\n # # print(\"NO\")\n"]
{"inputs": [["2", "ABABAB", "ABC"]], "outputs": [["YES", "NO"]]}
INTERVIEW
PYTHON3
CODECHEF
8,591
a583d3f582424217efa417281b2c1405
UNKNOWN
A spy needs your help to encrypt a 5 letter message. To encrypt the message the following steps are need to be done: 1)Each letter of the message will be converted to it's equivalent number (i.e A=0, B=1,..Z=25) 2)98, 57, 31, 45, 46 are the 5 numbers in the key. 3)Add the equivalent number of the first letter of the message to the first number of the key, then the equivalent number of the second letter of the message to the second number of the key and so on. 4)Take modulo 26 of the sum of each expression. 5)Convert the newly obtained numbers into it's equivalent letters (i.e 0=A, 1=B,…25=Z) Print the final encrypted string. Note: It is guaranteed that the given string only contains Only Upper-case Latin Letters. -----Input:----- - The first line of the input contains a single Integer $T$. $T$ denoting the number of testcases, description of each testcases contains. - The first line of the each testcase contains a single string $S$. $S$ denoting the string which you need to encrypt -----Output:----- - For each test case, print encypted string i.e result of above operation. Note: Each testcase output must be printed on new line -----Constraints:----- - $1 \leq T \leq 100$ - $1 \leq S \leq 5$ -----Sample Input:----- 2 HELLO HELL -----Sample Output:----- BJQEI BJQE -----Explanation:----- - For 1st Testcase : The conversion of "HELLO" to its equivalent number will be 7, 4, 11, 11, 14 respectively. Then we add each equivalent number of the message with corresponding number in the key: 7 + 98 = 105 4 + 57 = 61 11 + 31 = 42 11 + 45 = 56 14 + 46 = 60 Further we take the sum: 105 modulo 26 = 1 61 modulo 26 = 9 42 modulo 26 = 16 56 modulo 26 = 4 60 modulo 26 = 8 Finally, convert the newly obtained numbers into it's equivalent letters: B J Q E I Print the final string: BJQEI
["# cook your dish here\nimport string \nfrom collections import OrderedDict\nfrom itertools import zip_longest\ndic = OrderedDict(zip(string.ascii_uppercase, range(0, 26)))\nkeys = [98, 57, 31, 45, 46]\nt = int(input()) # number of test cases\ns1 = []\nfor i in range(t):\n s = input()\n for i in s:\n if i in dic.keys():\n s1.append(int(i.replace(i, str(dic[i]))))\n s2 = [sum(t) for t in zip_longest(s1, keys, fillvalue=0)]\n inv_dic = {v:k for k,v in dic.items()}\n s_1 = list()\n for i in range(len(s1)):\n s_1.append(s2[i]%26)\n res= [inv_dic[i] for i in s_1]\n print(''.join(res))\n inv_dic.clear()\n res.clear()\n s1.clear()\n s2.clear()\n s_1.clear()", "for _ in range(int(input())):\r\n n = input().strip()\r\n a = [98, 57, 31, 45, 46]\r\n x = []\r\n for i in range(len(n)):\r\n x.append(ord(n[i])-65+a[i])\r\n for i in x:\r\n s = i%26\r\n print(chr(s+65),end = \"\")\r\n print()\r\n", "a = [98, 57, 31, 45, 46]\nfor _ in range(int(input())):\n S = list(input().strip())\n for x in range(len(S)):\n S[x] = chr((ord(S[x])- ord('A') + a[x])%26 + ord('A'))\n print(''.join(S))", "# cook your dish here\nfor x in range(int(input())):\n n=list(input())\n l=[\"A\",\"B\",\"C\",\"D\",\"E\",\"F\",\"G\",\"H\",\"I\",\"J\",\"K\",\"L\",\"M\",\"N\",\"O\",\"P\",\"Q\",\"R\",\"S\",\"T\",\"U\",\"V\",\"W\",\"X\",\"Y\",\"Z\"]\n list1=[98,57,31,45,46]\n c=0\n for i in range(0,len(n)):\n for j in range(0,len(l)):\n if n[i]==l[j]:\n s1=j+list1[c]\n s2=s1%26\n print(l[s2],end=\"\")\n c+=1\n print(\"\\n\")\n \n ", "# cook your dish here\nt=int(input())\nl=[98,57,31,45,46]\nfor _ in range(t):\n s=input().strip().upper()\n a=65\n z=''\n for i in range(len(s)):\n x=ord(s[i])-a\n x+=l[i]\n x%=26\n z+=chr(x+a)\n print(z)\n \n", "dict1 = {0:98, 1:57, 2:31, 3:45, 4:46}\r\nfor _ in range(int(input().strip())):\r\n s = list(input().strip())\r\n ss = 0\r\n for i in range(len(s)):\r\n ss = ((ord(s[i])-65) + dict1[i]) \r\n print(chr((ss%26)+65),end=\"\")\r\n print()", "import math\ndef solve(s):\n d={'A':0,'B':1,'C':2,'D':3,'E':4,'F':5,'G':6,'H':7,'I':8,'J':9,'K':10,'L':11,'M':12,'N':13,'O':14,'P':15,'Q':16,'R':17,'S':18,'T':19,'U':20,'V':21,'W':22,'X':23,'Y':24,'Z':25}\n key=[98,57,31,45,46]\n res=\"\"\n li=[]\n n=len(s)\n for i in range(n):\n li.append((d[s[i]]+key[i])%26)\n d1={0:'A',1:'B',2:'C',3:'D',4:'E',5:'F',6:'G',7:'H',8:'I',9:'J',10:'K',11:'L',12:'M',13:'N',14:'O',15:'P',16:'Q',17:'R',18:'S',19:'T',20:'U',21:'V',22:'W',23:'X',24:'Y',25:'Z'}\n for i in li:\n res+=d1[i]\n print(res)\n\n\ndef __starting_point():\n try:\n t=int(input())\n for _ in range(t):\n s=input().strip()\n solve(s)\n except:\n pass\n__starting_point()", "n=int(input())\nl=[98,57,31,45,46]\nf=''\nfor i in range(0,n):\n s=input().strip()\n for z in range(0,len(s)):\n k=ord(s[z])-65\n k=k+l[z]\n req=k%(26)\n req=req+65\n f=f+chr(req)\n print(f)\n f=''\n \n", "t = int(input())\nlst = [\"a\",\"b\",\"c\",\"d\",\"e\",\"f\",\"g\",\"h\",\"i\",\"j\",\"k\",\"l\",\"m\",\"n\",\"o\",\"p\",\"q\",\"r\",\"s\",\"t\",\"u\",\"v\",\"w\",\"x\",\"y\",\"z\"]\nfor i in range(t):\n s = input().lower()\n s = list(s.strip())\n new = []\n for j in s:\n j = lst.index(j)\n new.append(j)\n s.clear()\n \n for j in range(len(new)):\n if j == 0:\n s.append(new[0]+98)\n elif j == 1:\n s.append(new[1]+57)\n elif j == 2:\n s.append(new[2]+31)\n elif j == 3:\n s.append(new[3]+45)\n elif j == 4:\n s.append(new[4]+46)\n new.clear()\n for j in s:\n new.append(j%26)\n s = \"\"\n for j in new:\n s+=lst[j]\n print(s.upper())", "import sys\r\ninput = sys.stdin.readline\r\n\r\nx=[98,57,31,45,46]\r\nt=int(input())\r\nfor _ in range(t):\r\n p=list(input().strip())\r\n ans=\"\"\r\n for i in range(len(p)):\r\n ans+=chr(((int(ord(p[i]))-65+x[i])%26)+65)\r\n print(ans)\r\n \r\n \r\n \r\n \r\n", "import sys\r\nfrom functools import lru_cache, cmp_to_key\r\nfrom heapq import merge, heapify, heappop, heappush\r\nfrom math import *\r\nfrom collections import defaultdict as dd, deque, Counter as C\r\nfrom itertools import combinations as comb, permutations as perm\r\nfrom bisect import bisect_left as bl, bisect_right as br, bisect\r\nfrom time import perf_counter\r\nfrom fractions import Fraction\r\nimport copy\r\nimport time\r\nstarttime = time.time()\r\nmod = int(pow(10, 9) + 7)\r\nmod2 = 998244353\r\n# from sys import stdin\r\n# input = stdin.readline\r\ndef data(): return sys.stdin.readline().strip()\r\ndef out(*var, end=\"\\n\"): sys.stdout.write(' '.join(map(str, var))+end)\r\ndef L(): return list(sp())\r\ndef sl(): return list(ssp())\r\ndef sp(): return map(int, data().split())\r\ndef ssp(): return map(str, data().split())\r\ndef l1d(n, val=0): return [val for i in range(n)]\r\ndef l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]\r\ntry:\r\n # sys.setrecursionlimit(int(pow(10,7)))\r\n sys.stdin = open(\"input.txt\", \"r\")\r\n # sys.stdout = open(\"../output.txt\", \"w\")\r\nexcept:\r\n pass\r\ndef pmat(A):\r\n for ele in A:\r\n print(*ele,end=\"\\n\")\r\ndef seive():\r\n prime=[1 for i in range(10**6+1)]\r\n prime[0]=0\r\n prime[1]=0\r\n for i in range(10**6+1):\r\n if(prime[i]):\r\n for j in range(2*i,10**6+1,i):\r\n prime[j]=0\r\n return prime\r\n\r\nfor _ in range(L()[0]):\r\n s=input().strip()\r\n A=[ord(s[i])-ord(\"A\") for i in range(len(s))]\r\n B=[98, 57, 31, 45, 46]\r\n C=[(A[i]+B[i])%26 for i in range(len(A))]\r\n C=[chr(ord(\"A\")+C[i]) for i in range(len(C))]\r\n print(\"\".join(C))\r\n\r\n\r\n\r\n\r\n \r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\nendtime = time.time()\r\n# print(f\"Runtime of the program is {endtime - starttime}\")\r\n\r\n", "from sys import stdin\r\ninput = lambda: stdin.readline().rstrip(\"\\r\\n\")\r\ninp = lambda: list(map(int,stdin.readline().rstrip(\"\\r\\n\").split()))\r\n#______________________________________________________________________________________________________\r\n# from math import *\r\n# from bisect import *\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(2*(10**5)+100) this is must for dfs\r\n# mod = 10**9+7; md = 998244353\r\n# ______________________________________________________________________________________________________\r\n# Checking prime in O(root(N))\r\n# def isprime(n):\r\n# if (n % 2 == 0 and n > 2) or n == 1: return 0\r\n# else:\r\n# s = int(n**(0.5)) + 1\r\n# for i in range(3, s, 2):\r\n# if n % i == 0:\r\n# return 0\r\n# return 1\r\n# def lcm(a,b):\r\n# return (a*b)//gcd(a,b)\r\n# ______________________________________________________________________________________________________\r\n# nCr under mod\r\n# def C(n,r,mod):\r\n# if r>n:\r\n# return 0\r\n# num = den = 1\r\n# for i in range(r):\r\n# num = (num*(n-i))%mod\r\n# den = (den*(i+1))%mod\r\n# return (num*pow(den,mod-2,mod))%mod\r\n# M = 10**5 +10\r\n# ______________________________________________________________________________________________________\r\n# For smallest prime factor of a number\r\n# M = 1000010\r\n# pfc = [i for i in range(M)]\r\n# def pfcs(M):\r\n# for i in range(2,M):\r\n# if pfc[i]==i:\r\n# for j in range(i+i,M,i):\r\n# if pfc[j]==j:\r\n# pfc[j] = i\r\n# return\r\n# pfcs(M)\r\n# ______________________________________________________________________________________________________\r\ntc = 1\r\ntc, = inp()\r\nfor _ in range(tc):\r\n s = str(input())\r\n d = [98, 57, 31, 45, 46]\r\n a = [ord(i)-ord('A') for i in s]\r\n d = [(a[i]+d[i])%26 for i in range(len(s))]\r\n ans = [chr(i+ord('A')) for i in d]\r\n print(''.join(ans))", "n=int(input())\nl=[98, 57, 31, 45, 46 ]\na='abcdefghijklmnopqrstuvwxyz' \n\nfor i in range(n):\n s=input().strip().lower()\n ans='' \n c=0\n for j in s:\n k=a.index(j)+l[c] \n c+=1 \n k=k%26 \n ans+=a[k] \n print(ans.upper())"]
{"inputs": [["2", "HELLO", "HELL"]], "outputs": [["BJQEI", "BJQE"]]}
INTERVIEW
PYTHON3
CODECHEF
8,736
f6d230c746462ee9f8821046d4a5791f
UNKNOWN
$Jaggu$ monkey a friend of $Choota$ $Bheem$ a great warrior of $Dholakpur$. He gets everything he wants. Being a friend of $Choota$ $Bheem$ he never has to struggle for anything, because of this he is in a great debt of $Choota$ $Bheem$, he really wants to pay his debt off. Finally the time has come to pay his debt off, $Jaggu$ is on a magical tree. He wants to collect apples from different branches but he is in a hurry. $Botakpur$ has attacked on $Dholakpur$ and $Bheem$ is severely injured, as been instructed by the village witch, $Bheem$ can only be saved by the apples of the magical tree. Each apple is placed in Tree Node structure and each apple has some sweetness. Now there's a problem as $Jaggu$ is also injured so he can only slide downwards and alse is collecting apples in his hand so he can't climb. You would be given $Q$ queries. Queries are of 2 type :- - Ending Node Node of $Jaggu$ is given. $format$ - type of query node -(1 2) - Sweetness of Apple on a given node is changed. $format$ - type of query node new sweetness(2 3 10) $Note$: $Jaggu$ is always on the top of tree initially in each query.The sweetness is always positive. Help $Jaggu$ in saving $Bheem$ -----Input:----- - First line contains $N$ - (number of nodes). - Next line contains $N$ integers with space giving sweetness of apple on Nodes $(1 to N)$ - Next $N-1$ lines contain $N1$ $N2$ connected nodes. - Next line contains single integer $Q$ Number of queries -----Output:----- - For each query of type 1, print total sweetness of apples. -----Constraints----- - $1 \leq N \leq 10^4$ - $2 \leq Q \leq 10^4$ -----Sample Input:----- 10 10 12 6 8 1 19 0 5 13 17 1 2 1 3 1 4 3 10 4 8 8 9 4 5 5 7 5 6 3 1 1 2 3 20 1 8 -----Sample Output:----- 10 23 -----EXPLANATION:----- This sweetness array is : $[10,2,6,8,1,19,0,5,13,17]$ The tree is: 1 / | \ 2 3 4 / / \ 10 8 5 / / \ 9 7 6
["counter = -1\r\ndef flattree(node):\r\n nonlocal counter\r\n if visited[node]==1:\r\n return\r\n else:\r\n visited[node]=1\r\n counter += 1\r\n i_c[node] = counter\r\n\r\n flat_tree[counter] = swt[node]\r\n\r\n for i in graph[node]:\r\n if visited[i]==0:\r\n flattree(i)\r\n counter += 1\r\n o_c[node] = counter\r\n flat_tree[counter] = -swt[node]\r\n return\r\n\r\n\r\ndef getsum(BITTree, i):\r\n s = 0 # initialize result\r\n i = i + 1\r\n while i > 0:\r\n s += BITTree[i]\r\n i -= i & (-i)\r\n return s\r\n\r\ndef upd(BITTree, n, i, v):\r\n i += 1\r\n while i <= n:\r\n BITTree[i] += v\r\n i += i & (-i)\r\n\r\ndef construct(arr, n):\r\n BITTree = [0] * (n + 1)\r\n for i in range(n):\r\n upd(BITTree, n, i, arr[i])\r\n return BITTree\r\n\r\nfrom collections import defaultdict\r\nn = int(input())\r\nswt = list(map(int, input().split()))\r\ngraph = defaultdict(list)\r\n\r\nfor i in range(n-1):\r\n n1, n2 = list(map(int, input().split()))\r\n graph[n1-1].append(n2-1)\r\n graph[n2-1].append(n1-1)\r\n\r\nflat_tree = [0]*(2*n+1)\r\ni_c = [0]*n\r\no_c = [0]*n\r\nvisited = [0]*n\r\nflattree(0)\r\n\r\ntre = construct(flat_tree, 2*n)\r\n\r\nq = int(input())\r\nfor i in range(q):\r\n query = list(map(int, input().split()))\r\n if query[0] == 1:\r\n node = query[1] - 1\r\n answer = getsum(tre, i_c[node])\r\n print(answer)\r\n else:\r\n node = query[1]-1\r\n upd(flat_tree, (2*n), i_c[node], query[2])\r\n upd(flat_tree, (2*n), o_c[node], -query[2])\r\n", "counter = -1\ndef flattree(node):\n nonlocal counter\n if visited[node]==1:\n return\n else:\n visited[node]=1\n counter += 1\n in_counter[node] = counter\n\n flat_tree[counter] = sweetness[node]\n\n for i in graph[node]:\n if visited[i]==0:\n flattree(i)\n counter += 1\n out_counter[node] = counter\n flat_tree[counter] = -sweetness[node]\n return\n\n\ndef getsum(BITTree, i):\n s = 0 # initialize result\n i = i + 1\n while i > 0:\n s += BITTree[i]\n i -= i & (-i)\n return s\n\ndef updatebit(BITTree, n, i, v):\n i += 1\n while i <= n:\n BITTree[i] += v\n i += i & (-i)\n\ndef construct(arr, n):\n BITTree = [0] * (n + 1)\n for i in range(n):\n updatebit(BITTree, n, i, arr[i])\n return BITTree\n\nfrom collections import defaultdict\nn = int(input())\nsweetness = list(map(int, input().split()))\ngraph = defaultdict(list)\n\nfor i in range(n-1):\n n1, n2 = list(map(int, input().split()))\n graph[n1-1].append(n2-1)\n graph[n2-1].append(n1-1)\n\nflat_tree = [0]*(2*n+1)\nin_counter = [0]*n\nout_counter = [0]*n\nvisited = [0]*n\nflattree(0)\n# print(flat_tree)\n# print(in_counter)\n# print(out_counter)\nfenwicktree = construct(flat_tree, 2*n)\n\nq = int(input())\nfor i in range(q):\n query = list(map(int, input().split()))\n if query[0] == 1:\n node = query[1] - 1\n answer = getsum(fenwicktree, in_counter[node])\n print(answer)\n else:\n node = query[1]-1\n updatebit(flat_tree, (2*n), in_counter[node], query[2])\n updatebit(flat_tree, (2*n), out_counter[node], -query[2])\n"]
{"inputs": [["10", "10 12 6 8 1 19 0 5 13 17", "1 2", "1 3", "1 4", "3 10", "4 8", "8 9", "4 5", "5 7", "5 6", "3", "1 1", "2 3 20", "1 8"]], "outputs": [["10", "23"]]}
INTERVIEW
PYTHON3
CODECHEF
3,399
5704bffcdfd0503fb37cd7abe6cafdcb
UNKNOWN
Probably everyone has experienced an awkward situation due to shared armrests between seats in cinemas. A highly accomplished cinema manager named "Chef" decided to solve this problem. When a customer wants to buy a ticket, the clerk at the ticket window asks the visitor if they need the armrests, and if so, which of them: left, right, or both. We know that out of the audience expected to show up, L of them only need the left armrest, R of them need just the right one, Z need none and B need both. Your task is to calculate the maximum number of people that can attend the show. In the cinema hall there are N rows with M seats each. There is only one armrest between two adjacent seats. Seats at the beginning and at the end of the row have two armrests -----Input----- Input begins with an integer T: the number of test cases. Each test case consists of a single line with 6 space-separated integers: N, M, Z, L, R, B. -----Output----- For each test case, output a line containing the answer for the task. -----Constraints and Subtasks----- - 1 ≤ T ≤ 105 Subtask 1 : 10 points - 1 ≤ N, M ≤ 3 - 0 ≤ Z, L, R, B ≤ 3 Subtask 2 : 20 points - 1 ≤ N, M ≤ 30 - 0 ≤ Z, L, R ≤ 30 - 0 ≤ B ≤ 109 Subtask 3 : 30 points - 1 ≤ N, M ≤ 106 - 0 ≤ Z, L, R ≤ 106 - 0 ≤ B ≤ 1016 Subtask 4 : 40 points - 1 ≤ N, M ≤ 108 - 0 ≤ Z, L, R, B ≤ 1016 -----Example----- Input:2 2 2 3 2 1 1 3 3 1 2 0 9 Output:4 8 -----Explanation----- 'L' - needs left 'R - needs right 'Z' - doesn't need any 'B' - needs both '-' - empty place Example case 1. ZZ ZB Example case 2. LLB BZB B-B
["for i in range(eval(input())):\n n,m,z,l,r,b = list(map(int, input().split()))\n rows=n\n columns=m\n hand_rest=n*(m+1)\n if(m%2==0):\n hand_rest -=max(0,n-l-r)\n if(l+r+(2*b)<=hand_rest):\n # print \"kanu\"\n print(min(n*m,l+r+z+b))\n else:\n temp=l+r+(hand_rest-l-r)/2\n # print \"parth\"\n print(min(n*m,temp+z))", "t=int(input())\nwhile(t):\n t-=1\n n,m,z,l,r,b=list(map(int,input().split()))\n if(m!=1):\n if(b>=n):\n ba=n\n bl=b-n\n else:\n ba=b\n b1=0\n if(ba==n):\n if((l+r)>=n*(m-1)):\n ans=n*m\n else:\n w=(l+r)%(m-1)\n la=l\n ll=0\n ra=r\n rl=0\n x=(m-1)/2\n y=n-(l+r)/(m-1)\n if(w==0):\n if(bl>=(x*y)):\n ba+=x*y\n bl=b-ba\n else:\n ba=b\n bl=0\n else:\n y-=1\n u=m-1-w\n if(bl>=(u/2+x*y)):\n ba+=(u/2+x*y)\n bl=b-ba\n else:\n ba=b\n bl=0\n za=min(n*m-la-ra-ba,z)\n zl=z-za\n ans=min(n*m,la+ra+ba+za)\n else:\n if((l+r)>=n*m-b):\n ans=n*m\n else:\n la=l\n ll=0\n ra=r\n rl=0\n za=min(n*m-la-ra-ba,z)\n zl=z-za\n ans=min(n*m,la+ra+ba+za)\n else:\n ans=min(n*m,l+r+z+b)\n print(ans)\n \n", "t=eval(input())\nwhile t>0:\n xx=list(map(int,input().split()))\n n=xx[0]\n m=xx[1]\n z=xx[2]\n l=xx[3]\n r=xx[4]\n b=xx[5]\n total=z+l+r+b\n maxi=n*m\n count=0\n ar = [[0 for y in range(m)] for x in range(n)]\n truth=True\n i=0\n while i<n:\n j=0\n while j<m:\n ar[i][j]=0\n if j==0:\n if l!=0:\n l=l-1\n ar[i][0]=-1\n count=count+1\n if count==total:\n truth=False\n break\n elif b!=0:\n b=b-1\n ar[i][0]=2\n count=count+1\n if count==total:\n truth=False\n break\n elif r!=0:\n r=r-1\n ar[i][0]=1\n count=count+1\n if count==total:\n truth=False\n break\n elif z!=0:\n z=z-1\n ar[i][0]=0\n count=count+1\n if count==total:\n truth=False\n break\n elif j==(m-1):\n if ar[i][j-1]==-1:\n if b!=0:\n b=b-1\n ar[i][j]=2\n count=count+1\n if count==total:\n truth=False\n break\n elif r!=0:\n r=r-1\n ar[i][j]=1\n count=count+1\n if count==total:\n truth=False\n break\n elif l!=0:\n l=l-1\n ar[i][j]=-1\n count=count+1\n if count==total:\n truth=False\n break\n elif z!=0:\n z=z-1\n ar[i][j]=0\n count=count+1\n if count==total:\n truth=False\n break\n elif ar[i][j-1]==2:\n if r!=0:\n r=r-1\n ar[i][j]=1\n count=count+1\n if count==total:\n truth=False\n break\n elif z!=0:\n z=z-1\n ar[i][j]=0\n count=count+1\n if count==total:\n truth=False\n break\n elif ar[i][j-1]==1:\n if r!=0:\n r=r-1\n ar[i][j]=1\n count=count+1\n if count==total:\n truth=False\n break\n elif z!=0:\n z=z-1\n ar[i][j]=0\n count=count+1\n if count==total:\n truth=False\n break\n elif ar[i][j-1]==0:\n if b!=0:\n b=b-1\n ar[i][j]=2\n count=count+1\n if count==total:\n truth=False\n break\n elif r!=0:\n r=r-1\n ar[i][j]=1\n count=count+1\n if count==total:\n truth=False\n break\n elif l!=0:\n l=l-1\n ar[i][j]=-1\n count=count+1\n if count==total:\n truth=False\n break\n elif z!=0:\n z=z-1\n ar[i][j]=0\n count=count+1\n if count==total:\n truth=False\n break\n else:\n if ar[i][j-1]==-1:\n if l!=0:\n l=l-1\n ar[i][j]=-1\n count=count+1\n if count==total:\n truth=False\n break\n elif b!=0:\n b=b-1\n ar[i][j]=2\n count=count+1\n if count==total:\n truth=False\n break\n elif r!=0:\n r=r-1\n ar[i][j]=1\n count=count+1\n if count==total:\n truth=False\n break\n elif z!=0:\n z=z-1\n ar[i][j]=0\n count=count+1\n if count==total:\n truth=False\n break\n elif ar[i][j-1]==2:\n if r!=0:\n r=r-1\n ar[i][j]=1\n count=count+1\n if count==total:\n truth=False\n break\n elif z!=0:\n z=z-1\n ar[i][j]=0\n count=count+1\n if count==total:\n truth=False\n break\n elif ar[i][j-1]==1:\n if r!=0:\n r=r-1\n ar[i][j]=1\n count=count+1\n if count==total:\n truth=False\n break\n elif z!=0:\n z=z-1\n ar[i][j]=0\n count=count+1\n if count==total:\n truth=False\n break\n elif ar[i][j-1]==0:\n if l!=0:\n l=l-1\n ar[i][j]=-1\n count=count+1\n if count==total:\n truth=False\n break\n elif b!=0:\n b=b-1\n ar[i][j]=2\n count=count+1\n if count==total:\n truth=False\n break\n elif r!=0:\n r=r-1\n ar[i][j]=1\n count=count+1\n if count==total:\n truth=False\n break\n elif z!=0:\n z=z-1\n ar[i][j]=0\n count=count+1\n if count==total:\n truth=False\n break\n \n if truth==False:\n break\n j=j+1\n if truth==False:\n break\n i=i+1\n print(count)\n t=t-1\n \n", "for _ in range(int(input())):\n n,m,z,l,r,b = list(map(int,input().split())) \n r = r + l\n c = 0\n if m == 1:\n print(min(n*m,z+r+b))\n continue\n elif m%2 == 0:\n m -= 1 \n if n >= r:\n c += r\n R = n-r\n r = 0\n if z <= R:\n c += z\n z = 0\n else:\n c += R\n z -= R \n else:\n c += n\n r -= n \n b += (r%2) \n r -= (r%2)\n if m == 1:\n print(min(n*m,z+r+b) + c)\n continue\n p = r/(m-1)\n k = min(b-p,(m+1-(r-p*(m-1)))/2 + (n-p-1)*((m+1)/2)) + p \n print(min(n*m,z+r+k) + c)\n \n \n", "for _ in range(int(input())):\n n,m,z,l,r,b = list(map(int,input().split())) \n r = r + l\n if (m == 1):\n print(min(n*m,z+r+b))\n continue\n p = r/(m-1) \n if (m % 2 == 0):\n k = min(b-p,(m-max(0,(r-p*(m-1)-(n-p))))/2 + ((n-p-1)*(m/2))) + p \n print(min(n*m,z+r+k))\n else:\n k = min(b-p,(m+1-(r-p*(m-1)))/2 + ((n-p-1)*((m+1)/2))) + p \n print(min(n*m,z+r+k))\n \n \n", "for _ in range(int(input())):\n n,m,z,l,r,b = list(map(int,input().split())) \n r = r + l\n if (m == 1):\n print(min(n*m,z+r+b))\n continue\n p = r/(m-1) \n if (m % 2 == 0) and (r-p*(m-1) <= n-p):\n k = min(b-p,(n-p)*(m/2)) + p \n print(min(n*m,z+r+k))\n else:\n k = min(b-p,(m+1-(r-p*(m-1)))/2 + ((n-p-1)*((m+1)/2))) + p \n print(min(n*m,z+r+k))", "for _ in range(int(input())):\n n,m,z,l,r,b = list(map(int,input().split())) \n r = r + l\n if (m == 1):\n print(min(n*m,z+r+b))\n continue\n p = r/(m-1)\n if (n <= p): \n #k = min(b-p,(m+1-(r-p*(m-1)))/2 + ((n-p-1)*((m+1)/2))) + p \n print(min(n*m,z+r+b))\n else:\n #k = min(b-p,(m+1-min(1,(r-p*(m-1)-(n-p-1))))/2 + ((n-p-1)*((m+1)/2))) + \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0p \n #print min(n*m,z+r+k)\n s = min(b-p,(m+1-(r-p*(m-1)))/2 + ((n-p-1)*((m+1)/2))) + p \n R = r%(m-1)\n h = R%(n-p)\n y = R/(n-p)\n k = min(b-p,((m-y)/2)*h + ((m+1-y)/2)*(n-p-h)) + p\n print(max(min(n*m,z+r+s),min(n*m,z+r+k)))", "for _ in range(int(input())):\n n,m,z,l,r,b = list(map(int,input().split())) \n r = r + l\n if (m == 1):\n print(min(n*m,z+r+b))\n continue\n p = r/(m-1)\n if (n <= p): \n #k = min(b-p,(m+1-(r-p*(m-1)))/2 + ((n-p-1)*((m+1)/2))) + p \n print(min(n*m,z+r+b))\n else:\n #k = min(b-p,(m+1-min(1,(r-p*(m-1)-(n-p-1))))/2 + ((n-p-1)*((m+1)/2))) + \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0p \n #print min(n*m,z+r+k)\n R = r%(m-1)\n h = R%(n-p)\n y = R/(n-p)\n k = min(b-p,((m-y)/2)*h + ((m+1-y)/2)*(n-p-h)) + p\n print(min(n*m,z+r+k))", "for _ in range(int(input())):\n n,m,z,l,r,b = list(map(int,input().split())) \n r = r + l\n if m == 1:\n print(min(n*m,z+r+b))\n continue\n p = r/(m-1)\n if (m%2 != 0) or (n <= p): \n k = min(b-p,(m+1-(r-p*(m-1)))/2 + ((n-p-1)*((m+1)/2))) + p \n print(min(n*m,z+r+k))\n else:\n R = r%(m-1)\n h = R%(n-p)\n y = R/(n-p)\n k = min(b-p,((m-y)/2)*h + ((m+1-y)/2)*(n-p-h)) + p\n print(min(n*m,z+r+k))", "for _ in range(int(input())):\n n,m,z,l,r,b = list(map(int,input().split())) \n r = r + l\n if m == 1:\n print(min(n*m,z+r+b))\n elif m%2: \n p = r/(m-1)\n k = min(b-p,(m+1-(r-p*(m-1)))/2 + ((n-p-1)*((m+1)/2))) + p \n print(min(n*m,z+r+k))\n else:\n p = r/(m-1)\n k = min(b-p,(n-p)*(m/2)) + p \n print(min(n*m,z+r+k))", "for _ in range(int(input())):\n n,m,z,l,r,b = list(map(int,input().split())) \n r = r + l\n if m == 1:\n print(min(n*m,z+r+b))\n elif m%2: \n p = r/(m-1)\n k = min(b-p,(m+1-(r-p*(m-1)))/2 + ((n-p-1)*((m+1)/2))) + p \n print(min(n*m,z+r+k))\n else:\n p = r/(m-1)\n k = min(b-p,(n-p)*(m/2)) + p \n print(min(n*m,z+r+k))", "t=eval(input())\nfor qq in range(t):\n n,m,z,l,r,b=list(map(int,input().split()))\n seat_max=n*m\n seat_used=l+r+z\n armrest_max=n*(m+1)\n armrest_used=l+r\n if (seat_used>=seat_max):\n # print \"used only l,r,z\"\n print(seat_max)\n else:\n # print \"armrest_used= \",armrest_used,\"seat_used=\",seat_used\n armrest_used_by_b=(armrest_max-armrest_used)/2\n seat_used_by_b=min(armrest_used_by_b,b,((m+1)/2)*n)\n seat_used+=seat_used_by_b\n print(min(seat_used,seat_max))\n", "import sys\nimport math\nt=int(eval(input(\"\")))\nwhile t:\n n,m,z,l,r,b=list(map(int,sys.stdin.readline().split()))\n if m==3:\n if n==1:\n if z+l+r+b<3:\n print(z+l+r+b)\n else:\n if b<2 :\n print(3)\n elif b==2 and z<1 and l+r<2:\n print(2)\n elif b==3 and z<1 and l+r<2:\n print(2)\n else:\n print(3)\n elif n==2:\n if z+l+r+b<6:\n print(z+l+r+b)\n elif z!=0:\n print(6)\n elif z==0 and b==3 and z+l+r+b==6:\n print(5)\n else:\n print(6)\n elif n==3:\n if z+l+r+b<9:\n print(z+l+r+b)\n else:\n print(9)\n \n \n elif m==2:\n if n==1:\n if z+l+r+b<2:\n print(z+l+r+b)\n elif l+r+z==0:\n print(1)\n else:\n print(2)\n elif n==2:\n if z+l+r+b<4:\n if z+l+r+b<3:\n print(z+l+r+b)\n elif b==3 and z+l+r==0:\n print(2)\n else:\n print(3)\n elif z+l+r>1:\n print(4)\n else:\n print(3)\n elif n==3:\n if z+l+r+b<6:\n print(z+l+r+b)\n else:\n print(6)\n \n else:\n print(min(m*n,z+l+r+b))\n \n t-=1\n", "def func(n,m,z,l,r,b):\n l=l+r\n if(l>=n*(m-1)):\n return min(n*m,l+z+b)\n x=l/(m-1)\n ans=x*(m-1)\n x=min(b,x)\n ans=ans+x\n b=b-x\n x=l%(m-1)\n ans=ans+x\n x=m-x\n x=min((x/2)+(x%2),b)\n ans=ans+x\n b=b-x\n x=n-(l/(m-1))\n x=x-1\n x=min(b,x*((m/2)+(m%2)))\n ans=ans+x\n z=min(z,n*m-ans)\n ans=ans+z\n return ans\ndef func2(n,m,z,l,r,b):\n l=l+r\n if(l>=n*(m-1)):\n return min(n*m,l+z+b)\n x=l/(m-1)\n ans=x*(m-1)\n n2=n-x\n x=min(b,x)\n ans=ans+x\n b=b-x\n l=l%(m-1)\n x=l/n2\n ans=ans+x*n2\n m=m-x\n l=l%n2\n ans1=ans+func(n2,m,z,l,0,b)\n ans2=0\n ans3=0\n if(l>0):\n ans2=ans+l\n x=min(z,n2-l)\n ans2=ans2+x\n z=z-x\n m=m-1\n ans2=ans2+func(n2,m,z,0,0,b)\n z=z+x\n m=m+1\n ans3=ans+l\n x=min(b,n2-l)\n ans3=ans3+x\n b=b-x\n m=m-2\n ans3=ans3+func(n2,m,z,0,0,b)\n return max(ans1,ans2,ans3)\nt=eval(input())\nfor _ in range(0,t):\n n,m,z,l,r,b=list(map(int,input().split()))\n a=func(n,m,z,l,r,b)\n a=max(a,func2(n,m,z,l,r,b))\n print(a) ", "def mini(a,b):\n if a>=b:\n return b\n else:\n return a\n\nt=eval(input())\nwhile t:\n m,n,z,l,r,b=list(map(int,input().split()))\n x=n*m\n y=m*(n+1)\n A=min(z,x)\n ans=A\n x-=A\n B=min(l,x)\n ans+=B\n x-=B\n C=min(r,x)\n ans+=C\n x-=C\n p=min(b,x)\n x=m*((n+1)//2)\n p=min(p,x)\n x=(y-B-C)//2\n ans+=min(p,x)\n print(ans)\n t-=1", "def mini(a,b):\n if a>=b:\n return b\n else:\n return a\n\nt=eval(input())\nwhile t:\n n,m,z,l,r,b=list(map(int,input().split()))\n x=n*m\n y=n*(m+1)\n if (b <= n) or (m == 1):\n print(mini(x,z+l+r+b))\n t-=1\n continue\n if (z+l+r+n) >= x:\n print(x)\n t-=1\n continue\n A=min(z,x)\n x-=A\n B=min(l,x)\n x-=B\n C=min(r,x)\n x-=C\n p=min(b,x)\n p=min(p,m*((n+1)//2))\n p=min(p,(y-B-C)//2)\n print(A+B+C+p)\n t-=1", "t=eval(input())\nauthor='biggy_bs'\nwhile t>0:\n t-=1\n n,m,z,l,r,b=list(map(int,input().split()))\n max_b=n*((m+1)/2)\n maximm=n*m\n nm=maximm\n answer=0\n if maximm>l+r:\n author=answer\n answer=l+r\n maximm-=(l+r)\n if m%2!=0:\n if maximm<=n-1:\n if b>=maximm:\n maximm-=maximm\n else:\n maximm-=b\n else:\n if b>=(maximm+n)/2:\n maximm-=(maximm+n)/2\n else:\n maximm-=b \n else:\n author=n*m\n answer=l+r\n if n*m-maximm<=n:\n if b>=max_b:\n maximm-=max_b\n else:\n maximm-=b\n elif maximm<=n-1:\n if b>=maximm:\n maximm-=maximm\n else:\n maximm-=b\n else:\n answer=b\n if b>=(maximm+n)/2:\n maximm-=(maximm+n)/2\n else:\n maximm-=b\n answer=n*m\n if z>=maximm or maximm==0:\n answer=n*m\n else:\n answer=n*m\n answer=n*m-(maximm-z)\n print(answer)\n else:\n nm=n*m\n answer=nm\n print(answer)\n", "def func(n,m,z,l,r,b):\n l=l+r\n if(l>=n*(m-1)):\n return min(n*m,l+z+b)\n x=l/(m-1)\n ans=x*(m-1)\n x=min(b,x)\n ans=ans+x\n b=b-x\n x=l%(m-1)\n ans=ans+x\n x=m-x\n x=min((x/2)+(x%2),b)\n ans=ans+x\n b=b-x\n x=n-(l/(m-1))\n x=x-1\n x=min(b,x*((m/2)+(m%2)))\n ans=ans+x\n z=min(z,n*m-ans)\n ans=ans+z\n return ans\ndef func2(n,m,z,l,r,b):\n l=l+r\n if(l>=n*(m-1)):\n return min(n*m,l+z+b)\n x=l/(m-1)\n ans=x*(m-1)\n n2=n-x\n x=min(b,x)\n ans=ans+x\n b=b-x\n l=l%(m-1)\n x=l/n2\n ans=ans+x*n2\n m=m-x\n l=l%n2\n ans1=ans+func(n2,m,z,l,0,b)\n ans2=0\n ans3=0\n if(l>0):\n ans2=ans+l\n x=min(z,n2-l)\n ans2=ans2+x\n z=z-x\n m=m-1\n ans2=ans2+func(n2,m,z,0,0,b)\n z=z+x\n m=m+1\n ans3=ans+l\n x=min(b,n2-l)\n ans3=ans3+x\n b=b-x\n m=m-2\n ans3=ans3+func(n2,m,z,0,0,b)\n return max(ans,ans2,ans3)\nt=eval(input())\nfor _ in range(0,t):\n n,m,z,l,r,b=list(map(int,input().split()))\n a=func(n,m,z,l,r,b)\n a=max(a,func2(n,m,z,l,r,b))\n print(a) "]
{"inputs": [["2", "2 2 3 2 1 1", "3 3 1 2 0 9"]], "outputs": [["4", "8"]]}
INTERVIEW
PYTHON3
CODECHEF
13,978
d460c4e2384858e4a383ce940fef829f
UNKNOWN
You are given a binary string S. You need to transform this string into another string of equal length consisting only of zeros, with the minimum number of operations. A single operation consists of taking some prefix of the string S and flipping all its values. That is, change all the 0s in this prefix to 1s, and all the 1s in the prefix to 0s. You can use this operation as many number of times as you want over any prefix of the string. -----Input----- The only line of the input contains the binary string, S . -----Output----- Output a single line containing one integer, the minimum number of operations that are needed to transform the given string S into the string of equal length consisting only of zeros. -----Constraints----- - 1 ≤ |S| ≤ 100,000 -----Subtasks----- - Subtask #1 (30 points): 1 ≤ |S| ≤ 2000 - Subtask #2 (70 points): Original constraints. -----Example----- Input: 01001001 Output: 6 -----Explanation----- For the given sample case, let us look at the way where we achieved minimum number of operations. Operation 1: You flip values in the prefix of length 8 and transform the string into 10110110 Operation 2: You flip values in the prefix of length 7 and transform the string into 01001000 Operation 3: You flip values in the prefix of length 5 and transform the string into 10110000 Operation 4: You flip values in the prefix of length 4 and transform the string into 01000000 Operation 5: You flip values in the prefix of length 2 and transform the string into 10000000 Operation 6: You flip values in the prefix of length 1 and finally, transform the string into 00000000
["# cook your dish here\ns=input()\ns1=s[::-1]\narr=[]\ncnt=0\nfor i in range(len(s1)):\n arr.append(s1[i])\nfor i in range(len(arr)):\n if(arr[i]==\"1\"):\n for j in range(i,len(arr)):\n if(arr[j]==\"1\"):\n arr[j]=\"0\"\n else:\n arr[j]=\"1\"\n cnt+=1\nprint(cnt)", "# cook your dish here\ndef rev(s):\n s1=''\n for i in s:\n if(i=='0'):\n s1=s1+'1'\n else:\n s1=s1+'0'\n return s1 \ns=input()\ns1=''\nc=0\nfor i in range(len(s)-1,-1,-1):\n if(s[i]=='1'):\n s1=rev(s[:i])\n c=c+1\n s=s1\n\nprint(c) ", "# cook your dish here\ntry:\n s=input()\n c=0\n for i in range(len(s)-1):\n if(s[i]!=s[i+1]):\n c=c+1\n if(s[-1]=='1'):\n print(c+1)\n else:\n print(c)\nexcept:\n pass", "n = input()\ncnt = 0\nx = n[0]\nfor i in range(len(n)):\n if(n[i] != x):\n cnt += 1\n x = n[i]\nif n[-1]=='1':\n print(cnt+1)\nelse:\n print(cnt)", "n = input()\nif(set(n)=={'0'}):\n print(0)\nelse:\n cnt = 0\n x = n[0]\n for i in range(len(n)):\n if(n[i] != x):\n cnt += 1\n x = n[i]\n if n[-1]=='1':\n print(cnt+1)\n else:\n print(cnt)", "def main():\n rev_s=reversed(input())\n flips=0\n flipped=False\n for b in rev_s:\n if b=='0':\n if not flipped:\n continue\n else:\n flipped=False\n flips+=1\n continue\n else:\n if flipped:\n continue\n else:\n flipped=True\n flips+=1\n continue\n print(flips)\nmain()", "# cook your dish here\nl=input()\ncnt=0\nn=len(l)\nfor i in range(n-1):\n if(l[i]!=l[i+1]):\n cnt+=1\nif(l[-1]=='1'):\n cnt+=1\nprint(cnt)", "t=1\nfor n in range(t):\n s=input()\n count=1\n for i in range(1,len(s)):\n if(s[i]!=s[i-1]):\n count+=1\n if(s[len(s)-1]=='0'):\n count-=1\n print(count)", "# cook your dish here\nS=str(input())\na=[]\nfor i in S:\n a.append(i)\nc=0\nfor i in range(len(a)-1,-1,-1):\n if a[i]=='1':\n for k in range(0,i+1):\n if a[k]=='1':\n a[k]='0'\n else:\n a[k]='1'\n c=c+1\nprint(c) ", "# import sys \n# sys.stdin = open('input.txt', 'r') \n# sys.stdout = open('output.txt', 'w')\n\ns = input()\narr = []\nn = len(s)\ni = 0\n\nwhile (i<n):\n x = s[i]\n while (i<n and s[i]==x):\n i += 1\n arr.append(x)\n\nm = len(arr)\nif (arr[0] == \"0\"):\n if (m==1):\n print(0)\n else:\n print((m//2)*2)\nelse:\n if (m&1==1):\n print((m//2)*2 + 1)\n else:\n m -= 1\n print((m//2)*2 + 1)", "# cook your dish here\nt=1\nfor _ in range(t):\n a=input()\n # x=s[0]\n count=1\n for i in range(1,len(a)):\n if(a[i]!=a[i-1]):\n count+=1\n # print(\"hbk\",count)\n if(a[len(a)-1]=='0'):\n count-=1\n print(count)", "# cook your dish here\ns=input()\ns=list(s)\nn,c=0,0\n\nj=0\nwhile(n!=1):\n j+=1\n \n p=-1\n for i in range(len(s)-2,-1,-1):\n if(j%2!=0):\n\n if(s[i]=='0'):\n p=i\n break\n else:\n \n if(s[i]=='1'):\n p=i\n break\n \n if(p!=-1):\n c+=1\n \n s=s[0:p+1]\n \n if(len(s)==1) or (len(s)==0):\n n=1\n \n \nprint(c+1)"]
{"inputs": [["01001001"]], "outputs": [["6"]]}
INTERVIEW
PYTHON3
CODECHEF
2,851
880705d91ed9417aa151f6450f6383f8
UNKNOWN
-----Problem----- Once THANMAY met PK who is from a different planet visiting earth. THANMAY was very fascinate to learn PK's language. The language contains only lowercase English letters and is based on a simple logic that only certain characters can follow a particular character. Now he is interested in calculating the number of possible words of length L and ending at a particular character C. Help THANMAY to calculate this value. -----Input----- The input begins with 26 lines, each containing 26 space-separated integers. The integers can be either 0 or 1. The jth integer at ith line depicts whether jth English alphabet can follow ith English alphabet or not. Next line contains an integer T. T is the number of queries. Next T lines contains a character C and an integer L. -----Output----- For each query output the count of words of length L ending with the character C. Answer to each query must be followed by newline character. The answer may be very large so print it modulo 1000000007. -----Constraints----- - 1 ≤ T ≤ 100 - C is lowercase English alphabet. - 2 ≤ L ≤ 10000000 -----Sample Input----- 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 c 3 b 2 -----Sample Output----- 1 2 -----Explanation----- For query 1, Words of length 3 are: aba, acb, bab, bac, cba. The only word ending with 'c' is bac. p { text-align:justify }
["d = {}\nfor i in range(26):\n char = chr(i+ord('a'))\n d[char] = []\nfor i in range(26):\n char = chr(i+ord('a'))\n temp = list(map(int,input().strip().split()))\n for j in range(26):\n if (temp[j] == 1):\n follow= chr(j+ord('a'))\n d[follow].append(char)\n \ndef f(char,i,n,count):\n if (i==n):\n return count+1\n else:\n ans = 0\n for c in d[char]:\n ans+=f(c,i+1,n,0)\n ans%=(10**9+7)\n return ans\n\nfor q in range(int(input().strip())):\n c, n = input().strip().split()\n n = int(n)\n print(f(c,1,n,0))", "d = {}\nfor i in range(26):\n char = chr(i+ord('a'))\n d[char] = []\nfor i in range(26):\n char = chr(i+ord('a'))\n temp = list(map(int,input().split()))\n for j in range(26):\n if (temp[j] == 1):\n follow= chr(j+ord('a'))\n d[follow].append(char)\n \ndef f(char,i,n,count):\n if (i==n):\n return count+1\n else:\n ans = 0\n for c in d[char]:\n ans+=f(c,i+1,n,0)\n ans%=(10**9+7)\n return ans\n\nfor q in range(int(input())):\n c, n = input().split()\n n = int(n)\n print(f(c,1,n,0))", "d = {}\nfor i in range(26):\n char = chr(i+ord('a'))\n d[char] = []\nfor i in range(26):\n char = chr(i+ord('a'))\n temp = list(map(int,input().split()))\n for j in range(26):\n if (temp[j] == 1):\n follow= chr(j+ord('a'))\n d[follow].append(char)\n \ndef f(char,i,n,count):\n if (i==n):\n return count+1\n else:\n ans = 0\n for c in d[char]:\n ans+=f(c,i+1,n,0)\n return ans\n\nfor q in range(int(input())):\n c, n = input().split()\n n = int(n)\n print(f(c,1,n,0))"]
{"inputs": [["0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0", "1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0", "0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0", "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0", "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0", "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0", "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0", "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0", "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0", "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0", "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0", "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0", "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0", "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0", "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0", "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0", "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0", "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0", "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0", "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0", "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0", "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0", "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0", "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0", "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0", "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0", "2", "c 3", "b 2"]], "outputs": [["1", "2"]]}
INTERVIEW
PYTHON3
CODECHEF
1,511
86009db8d4bc8037d0158fa759a16eb4
UNKNOWN
Let's define the niceness of a sequence of positive integers X1,X2,…,XN$X_1, X_2, \dots, X_N$ as the sum of greatest common divisors of all pairs of its elements, i.e. N∑i=1N∑j=i+1gcd(Xi,Xj).∑i=1N∑j=i+1Ngcd(Xi,Xj).\sum_{i=1}^N \sum_{j=i+1}^N \mathrm{gcd}(X_i, X_j)\;. For example, the niceness of the sequence [1,2,2]$[1, 2, 2]$ is gcd(1,2)+gcd(1,2)+gcd(2,2)=4$gcd(1, 2) + gcd(1, 2) + gcd(2, 2) = 4$. You are given a sequence A1,A2,…,AN$A_1, A_2, \dots, A_N$; each of its elements is either a positive integer or missing. Consider all possible ways to replace each missing element of A$A$ by a positive integer (not necessarily the same for each element) such that the sum of all elements is equal to S$S$. Your task is to find the total niceness of all resulting sequences, i.e. compute the niceness of each possible resulting sequence and sum up all these values. Since the answer may be very large, compute it modulo 109+7$10^9 + 7$. -----Input----- - The first line of the input contains a single integer T$T$ denoting the number of test cases. The description of T$T$ test cases follows. - The first line of each test case contains two space-separated integers N$N$ and S$S$. - The second line contains N$N$ space-separated integers A1,A2,…,AN$A_1, A_2, \dots, A_N$. Missing elements in this sequence are denoted by −1$-1$. -----Output----- For each test case, print a single line containing one integer — the total niceness modulo 109+7$10^9 + 7$. -----Constraints----- - 1≤T≤20$1 \le T \le 20$ - 1≤N,S≤50$1 \le N, S \le 50$ - 1≤Ai≤50$1 \le A_i \le 50$ or Ai=−1$A_i = -1$ for each valid i$i$ -----Subtasks----- Subtask #1 (30 points): - 1≤N,S≤18$1 \le N, S \le 18$ - 1≤Ai≤18$1 \le A_i \le 18$ or Ai=−1$A_i = -1$ for each valid i$i$ Subtask #2 (70 points): original constraints -----Example Input----- 3 3 3 1 1 -1 4 8 1 -1 -1 3 3 10 -1 -1 -1 -----Example Output----- 3 23 150 -----Explanation----- Example case 1: There is only one possible way to fill in the missing element; the resulting sequence is [1,1,1]$[1, 1, 1]$. Its niceness is 3$3$. Example case 2: There is only three possible ways to fill in the missing elements; the resulting sequences are [1,1,3,3]$[1, 1, 3, 3]$, [1,3,1,3]$[1, 3, 1, 3]$, and [1,2,2,3]$[1, 2, 2, 3]$. The sum of their niceness is 8+8+7=23$8 + 8 + 7 = 23$.
["# cook your dish here\nmod = 10**9 + 7\nfrom math import gcd\ndef fac50():\n f = [0]*51\n f[0] ,f[1] = 1,1\n for i in range(1,51):f[i] = (f[i-1]*i)%mod\n return f\ndef gcd110():\n gc = [[0]*111 for i in range(111)]\n for i in range(111):\n for j in range(111):gc[i][j] = gcd(i,j)\n return gc\nfactorials,gcds = fac50(),gcd110()\ndef rule_asc(n,l):\n a,k = [0 for i in range(n + 1)],1\n a[1] = n\n while k != 0:\n x,y = a[k - 1] + 1,a[k] - 1 \n k -= 1\n while x <= y and k < l - 1:\n a[k],y = x,y-x\n k += 1\n a[k] = x + y\n yield a[:k + 1]\ndef niceness(s):\n t = 0\n for i in range(len(s)):\n for j in range(i+1,len(s)):t = (t + gcds[s[i]][s[j]])%mod\n return t\ndef permcount(s,c):\n f,p = [s.count(x) for x in set(s)],factorials[c] \n for e in f:p = (p*pow(factorials[e],mod-2,mod))%mod\n return p\ndef main():\n for i in range(int(input())):\n n,s = [int(item) for item in input().split()]\n a = [int(item) for item in input().split()]\n b = [i for i in a if i != -1]\n s , ones = s - sum(b),a.count(-1) \n if s < 0:print(0)\n elif (s == 0 and ones == 0):print(niceness(a)%mod)\n elif (s > 0 and ones == 0):print(0)\n else:\n t = 0\n for seq in rule_asc(s,ones):\n if len(seq) == ones: t = (t + (((permcount(seq,ones))%mod)*(niceness(b+seq)%mod))%mod)%mod\n print(t) \ndef __starting_point():main()\n__starting_point()", "# cook your dish here\nmod = 10**9 + 7\nfrom math import gcd\ndef fac50():\n f = [0]*51\n f[0] ,f[1] = 1,1\n for i in range(1,51):f[i] = (f[i-1]*i)%mod\n return f\ndef gcd110():\n gc = [[0]*111 for i in range(111)]\n for i in range(111):\n for j in range(111):gc[i][j] = gcd(i,j)\n return gc\nfactorials,gcds = fac50(),gcd110()\ndef rule_asc(n,l):\n a,k = [0 for i in range(n + 1)],1\n a[1] = n\n while k != 0:\n x,y = a[k - 1] + 1,a[k] - 1 \n k -= 1\n while x <= y and k < l - 1:\n a[k],y = x,y-x\n k += 1\n a[k] = x + y\n yield a[:k + 1]\ndef niceness(s):\n t = 0\n for i in range(len(s)):\n for j in range(i+1,len(s)):t = (t + gcds[s[i]][s[j]])%mod\n return t\ndef permcount(s,c):\n f,p = [s.count(x) for x in set(s)],factorials[c] \n for e in f:p = (p*pow(factorials[e],mod-2,mod))%mod\n return p\ndef main():\n for i in range(int(input())):\n n,s = [int(item) for item in input().split()]\n a = [int(item) for item in input().split()]\n b = [i for i in a if i != -1]\n s , ones = s - sum(b),a.count(-1) \n if s < 0:print(0)\n elif (s == 0 and ones == 0):print(niceness(a)%mod)\n elif (s > 0 and ones == 0):print(0)\n else:\n t = 0\n for seq in rule_asc(s,ones):\n if len(seq) == ones: t = (t + (((permcount(seq,ones))%mod)*(niceness(b+seq)%mod))%mod)%mod\n print(t) \ndef __starting_point():main()\n__starting_point()", "mod = 10**9 + 7\nfrom math import gcd\ndef fac50():\n f = [0]*51\n f[0] ,f[1] = 1,1\n for i in range(1,51):f[i] = (f[i-1]*i)%mod\n return f\ndef gcd110():\n gc = [[0]*111 for i in range(111)]\n for i in range(111):\n for j in range(111):gc[i][j] = gcd(i,j)\n return gc\nfactorials,gcds = fac50(),gcd110()\ndef rule_asc(n,l):\n a,k = [0 for i in range(n + 1)],1\n a[1] = n\n while k != 0:\n x,y = a[k - 1] + 1,a[k] - 1 \n k -= 1\n while x <= y and k < l - 1:\n a[k],y = x,y-x\n k += 1\n a[k] = x + y\n yield a[:k + 1]\ndef niceness(s):\n t = 0\n for i in range(len(s)):\n for j in range(i+1,len(s)):t = (t + gcds[s[i]][s[j]])%mod\n return t\ndef permcount(s,c):\n f,p = [s.count(x) for x in set(s)],factorials[c] \n for e in f:p = (p*pow(factorials[e],mod-2,mod))%mod\n return p\ndef main():\n for i in range(int(input())):\n n,s = [int(item) for item in input().split()]\n a = [int(item) for item in input().split()]\n b = [i for i in a if i != -1]\n s , ones = s - sum(b),a.count(-1) \n if s < 0:print(0)\n elif (s == 0 and ones == 0):print(niceness(a)%mod)\n elif (s > 0 and ones == 0):print(0)\n else:\n t = 0\n for seq in rule_asc(s,ones):\n if len(seq) == ones: t = (t + (((permcount(seq,ones))%mod)*(niceness(b+seq)%mod))%mod)%mod\n print(t) \ndef __starting_point():main()\n__starting_point()", "mod = 10**9 + 7\r\ndef gcd(a,b): return b and gcd(b, a % b) or a\r\n\r\ndef fac50():\r\n f = [0]*51\r\n f[0] = 1\r\n f[1] = 1\r\n for i in range(1,51):\r\n f[i] = (f[i-1]*i)%mod\r\n return f\r\n\r\ndef gcd110():\r\n\r\n gc = [[0]*111 for i in range(111)]\r\n for i in range(111):\r\n for j in range(111):\r\n gc[i][j] = gcd(i,j)\r\n return gc\r\n\r\nfactorials = fac50()\r\ngcds = gcd110()\r\n\r\ndef rule_asc(n,l):\r\n a = [0 for i in range(n + 1)]\r\n k = 1\r\n a[1] = n\r\n while k != 0:\r\n x = a[k - 1] + 1\r\n y = a[k] - 1\r\n k -= 1\r\n while x <= y and k < l - 1:\r\n a[k] = x\r\n y -= x\r\n k += 1\r\n a[k] = x + y\r\n yield a[:k + 1]\r\n\r\ndef niceness(s):\r\n t = 0\r\n for i in range(len(s)):\r\n for j in range(i+1,len(s)):\r\n t = (t + gcds[s[i]][s[j]])%mod\r\n return t\r\n\r\n\r\ndef permcount(s,c):\r\n f = [s.count(x) for x in set(s)]\r\n p = factorials[c]\r\n for e in f:\r\n p = (p*pow(factorials[e],mod-2,mod))%mod\r\n return p\r\n\r\ndef main():\r\n\r\n t = int(input())\r\n\r\n for i in range(t):\r\n\r\n n,s = [int(item) for item in input().split()]\r\n a = [int(item) for item in input().split()]\r\n b = [i for i in a if i != -1]\r\n s -= sum(b)\r\n ones = a.count(-1)\r\n\r\n if s < 0:\r\n print(0)\r\n elif (s == 0 and ones == 0):\r\n print(niceness(a)%mod)\r\n elif (s > 0 and ones == 0):\r\n print(0)\r\n else:\r\n\r\n t = 0\r\n for seq in rule_asc(s,ones):\r\n if len(seq) == ones:\r\n p = permcount(seq,ones)\r\n t = (t + ((p%mod)*(niceness(b+seq)%mod))%mod)%mod\r\n\r\n print(t)\r\n\r\ndef __starting_point():\r\n main()\r\n\n__starting_point()", "import math\r\n\r\ndef niceness(a):\r\n nice=0\r\n for i in range(len(a)):\r\n for j in range(i+1,len(a)):\r\n nice+=math.gcd(a[i],a[j])\r\n return nice\r\n\r\ndef f(a, s):\r\n if -1 not in a:\r\n if s != 0: return ()\r\n return (tuple(a),)\r\n if s == 0:\r\n return ()\r\n idx = a.index(-1)\r\n ans = ()\r\n for i in range(1, s + 1):\r\n a[idx] = i\r\n ans += f(a, s - i)\r\n a[idx] = -1\r\n return ans\r\n\r\ndef __starting_point():\r\n t=int(input())\r\n numbers=[0]*50\r\n mod = 10**9 + 7\r\n for i in range(1,51):\r\n numbers[i-1]=i\r\n for i in range(t):\r\n n,s = map(int,input().split())\r\n a=list(map(int,input().split()))\r\n ans,ss=0,0\r\n for x in range(len(a)):\r\n if(a[x]!=-1):\r\n ss+=a[x]\r\n x=f(a,s-ss)\r\n for i in x:\r\n ans += niceness(i)\r\n print(ans % mod)\n__starting_point()"]
{"inputs": [["3", "3 3", "1 1 -1", "4 8", "1 -1 -1 3", "3 10", "-1 -1 -1", ""]], "outputs": [["3", "23", "150"]]}
INTERVIEW
PYTHON3
CODECHEF
7,638
6e0b329e83200bfb26a5392227f96eae
UNKNOWN
You are given an unweighted, undirected graph. Write a program to check if it's a tree topology. -----Input----- The first line of the input file contains two integers N and M --- number of nodes and number of edges in the graph (0 < N <= 10000, 0 <= M <= 20000). Next M lines contain M edges of that graph --- Each line contains a pair (u, v) means there is an edge between node u and node v (1 <= u,v <= N). -----Output----- Print YES if the given graph is a tree, otherwise print NO. -----Example----- Input: 3 2 1 2 2 3 Output: YES
["#!/usr/bin/env python\n\ndef iscycle(E, v, EXPLORED_NODES, EXPLORED_EDGES):\n EXPLORED_NODES.add(v)\n r = False\n for e in [x for x in E if v in x]:\n if e in EXPLORED_EDGES: continue\n if e[0] == v: w = e[1]\n else: w = e[0]\n if w in EXPLORED_NODES:\n return True\n else:\n EXPLORED_EDGES.add(e)\n r = r or iscycle(E, w, EXPLORED_NODES, EXPLORED_EDGES)\n if r: break\n return r\n\ndef process(E):\n return iscycle(E, 1, set(), set()) and 'NO' or 'YES'\n\ndef main():\n N, M = list(map(int, input().split()))\n E = []\n for m in range(M):\n U, V = list(map(int, input().split()))\n if U > V: U, V = V, U\n E.append((U, V))\n print(process(E))\n\nmain()\n\n", "def main():\n try:\n print(\"YES\")\n except:\n return 0\n \nmain()\n", "def main():\n try:\n [n, m] = input().split()\n m=int(m)\n n=int(n)\n p = [0]*(n+1)\n while m>0:\n [a,b] = input().split()\n a=int(a)\n b=int(b)\n p[a] = p[a]+1\n p[b] = p[b]+1\n if (p[a]>=3 or p[b] >= 3):\n print(\"NO\")\n return 0\n m=m-1\n print(\"YES\")\n except:\n return 0\n \nmain()\n", "import sys\ndef iter_dfs(G, s):\n S, Q = set(), []\n Q.append(s)\n p=Q.pop\n e=Q.extend\n t=S.add\n while Q:\n u=p()\n if u in S: continue\n t(u)\n e(G[u])\n yield u\n\ndef main():\n s=sys.stdin.readline\n n, e = list(map(int, s().split()))\n if e!=n-1:\n print(\"NO\")\n return\n G=dict()\n for case in range(e):\n n1, n2 = list(map(int, s().split()))\n if n1 not in G:\n G[n1]=[n2]\n else:\n G[n1].append(n2)\n if n2 not in G:\n G[n2]=[n1]\n else:\n G[n2].append(n1)\n tot=len(list(iter_dfs(G, 1)))\n if tot==n:\n print(\"YES\")\n else:\n print(\"NO\")\n\ndef __starting_point():\n main()\n \n \n\n__starting_point()"]
{"inputs": [["3 2", "1 2", "2 3"]], "outputs": [["YES"]]}
INTERVIEW
PYTHON3
CODECHEF
1,726
40574c47fea01673761de823d5531d15
UNKNOWN
Two cheeky thieves (Chef being one of them, the more talented one of course) have came across each other in the underground vault of the State Bank of Churuland. They are shocked! Indeed, neither expect to meet a colleague in such a place with the same intentions to carry away all the money collected during Churufest 2015. They have carefully counted a total of exactly 1 billion (109) dollars in the bank vault. Now they must decide how to divide the booty. But there is one problem: the thieves have only M minutes to leave the bank before the police arrives. Also, the more time they spend in the vault, the less amount could carry away from the bank. Formally speaking, they can get away with all of the billion dollars right now, but after t minutes they can carry away only 1 billion * pt dollars, where p is some non-negative constant less than or equal to unity, and at t = M, they get arrested and lose all the money. They will not leave the vault until a decision on how to divide the money has been made. The money division process proceeds in the following way: at the beginning of each minute starting from the 1st (that is, t = 0), one of them proposes his own way to divide the booty. If his colleague agrees, they leave the bank with pockets filled with the proposed amounts of dollars. If not, the other one proposes his way at the next minute etc. To escape arrest, they can only propose plans till the beginning of the Mth minute (i.e., till t = M-1). Each thief wants to maximize his earnings, but if there are two plans with the same amounts for him, he would choose the one which leads to a larger total amount of stolen dollars. Chef is about to start this procedure, and he is the first to propose a plan. You are wondering what will be the final division of money, if each thief chooses the optimal way for himself and money is considering real. -----Input----- The first line of input contains an integer T denoting the number of test cases. The description of T test cases follows. The only line of input for each test case contains an integer M denoting the number of minutes until arrest and a double denoting the constant p. -----Output----- For each test case, output a single line containing two space-separated doubles denoting the amount of dollars each thief will get in the optimal division. First number: dollars amassed by Chef, and second: by his colleague. The answer will be considered correct if its absolute error doesn't exceed 10-2. -----Constraints and subtasks----- - 1 ≤ T ≤ 105 - 0 ≤ p ≤ 1 Subtask 1 (15 points) : 1 ≤ M ≤ 3 Subtask 2 (55 points) : 1 ≤ M ≤ 103 Subtask 3 (30 points) : 1 ≤ M ≤ 109 -----Example----- Input: 2 1 0.5 2 0.5 Output: 1000000000.0 0.0 500000000.0 500000000.0 -----Explanation----- Example case 1. In the second case, if decision isn't made at t = 0, total amount of money decreases to 5*108 at t = 1 which leads to a situation worse than the given solution.
["t=int(input())\nwhile(t):\n s=input().split()\n m=int(s[0])\n p=float(s[1])\n if(m%2==0):\n r=(1-p**m)/(p+1)\n else:\n r=(1+p**m)/(p+1)\n print(1000000000*r,1000000000*(1-r))\n t-=1", "for _ in range(int(input())):\n m, p = map(float, input().split())\n ans = 10**9 * (1 - (-p)**m) / (1 + p)\n print(ans,10**9-ans)", "t=int(input())\nwhile(t):\n s=input().split()\n m=int(s[0])\n p=float(s[1])\n if(m%2==0):\n r=(1-p**m)/(p+1)\n else:\n r=(1+p**m)/(p+1)\n print(1000000000*r,1000000000*(1-r))\n t-=1\n\n"]
{"inputs": [["2", "1 0.5", "2 0.5"]], "outputs": [["1000000000.0 0.0", "500000000.0 500000000.0"]]}
INTERVIEW
PYTHON3
CODECHEF
511
a5d37149ad53188d3ed2602fec9183f8
UNKNOWN
The garden has a tree with too many leaves on it and gardner wants to cut the unwanted leaves. This is a rooted tree, where a node $v$ is called parent of another node $u$, if there exists a directed edge from $v$ to $u$. Leaf node is a node with no outgoing edges. Gardner cuts the tree in a peculiar way: - For each parent node(which has a valid leaf node attached to it), he cuts $x$ leaf nodes, such that $x$ is a multiple of 3. Example : If a parent node has 7 leaf nodes, 6 leaf nodes will be cut and 1 will be left. - If a parent has all its leaf nodes cut, only then the parent node itself becomes a new leaf node. If new leaf nodes are created, Gardner repeats step 1 until he can cut no more leaf nodes. After completing all operations, gardner wants to know the minimum number of nodes left on the tree. It is guaranteed that the given input is a rooted tree. The root of the tree is vertex 1. -----Input:----- - First line will contain $T$, number of testcases. Then the testcases follow. - First line of each testcase contains an integer $n$, the number of vertices in the tree. - Second line of each testcase contains array $A$ of size $n-1$, where $A_{i}(1≤i≤n-1)$, is the index of the parent of the $(i+1)^{th}$ vertex. -----Output:----- For each testcase, output single integer, the number of nodes finally left on the tree. -----Constraints----- - $1 \leq T \leq 10$ - $2 \leq n \leq 10^5$ - $1 \leq A_i \leq i$ -----Sample Input:----- 1 13 1 1 1 1 1 4 3 4 4 3 4 3 -----Sample Output:----- 4 -----EXPLANATION:-----
["def dfs(node):\n nonlocal adj,leaf\n val=0\n flag=0\n for i in adj[node]:\n x= dfs(i)\n val+=x\n if x==0:\n flag=1\n leaf+=val-val%3\n if val%3==0 and flag==0:\n return 1\n else:\n return 0\nfor _ in range(int(input())):\n n=int(input())\n adj=[[] for i in range(n+2)]\n arr=[int(i) for i in input().split()]\n leaf=0\n #print(adj)\n for i in range(2,n+1):\n #print(i,arr[i-2])\n adj[arr[i-2]].append(i)\n \n dfs(1)\n print(n-leaf)", "from collections import defaultdict\nimport sys\nsys.setrecursionlimit(10**6)\n\n\n\n\ndef dfs(node):\n visited[node]=True\n n0[node]+=1\n for x in d[node]:\n if visited[x]==False:\n dfs(x)\n n0[node]+=n0[x]\ndef dfs1(node):\n nonlocal ans\n visited[node]=True\n co=0\n for x in d[node]:\n if visited[x]==False:\n\n dfs1(x)\n if n0[x]==1:\n co+=1\n\n ans1=co//3\n ##print(ans1,node)\n if 3*ans1==len(d[node]):\n n0[node]=1\n ##print(n0[node],node)\n ans-=3*ans1\n\n\n\n\n\nfor _ in range(int(input())):\n n=int(input())\n a=list(map(int,input().split()))\n d=defaultdict(list)\n ans=n\n for i in range(len(a)):\n d[a[i]].append(i+2)\n ##print(d)\n visited = [False] * (n + 1)\n n0 = [0] * (n + 1)\n ##print(n0)\n dfs(1)\n ## print(n0)\n visited=[False]*(n+1)\n dfs1(1)\n print(ans)\n\n\n\n"]
{"inputs": [["1", "13", "1 1 1 1 1 4 3 4 4 3 4 3"]], "outputs": [["4"]]}
INTERVIEW
PYTHON3
CODECHEF
1,254
e0bcc0a3c08f355bee8d4417169a0948
UNKNOWN
You are given a sequence of n integers a1, a2, ..., an and an integer d. Find the length of the shortest non-empty contiguous subsequence with sum of elements at least d. Formally, you should find the smallest positive integer k with the following property: there is an integer s (1 ≤ s ≤ N-k+1) such that as + as+1 + ... + as+k-1 ≥ d. -----Input----- - The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows. - The first line of each test case contains two space-separated integers n and d. - The second line contains n space-separated integers a1, a2, ..., an. -----Output----- For each test case, print a single line containing one integer — the length of the shortest contiguous subsequence with sum of elements ≥ d. If there is no such subsequence, print -1 instead. -----Constraints----- - 1 ≤ T ≤ 105 - 1 ≤ n ≤ 105 - -109 ≤ d ≤ 109 - -104 ≤ ai ≤ 104 - 1 ≤ sum of n over all test cases ≤ 2 · 105 -----Example----- Input: 2 5 5 1 2 3 1 -5 5 1 1 2 3 1 -5 Output: 2 1
["# cook your dish here\n\nimport collections\n\ndef shortestSubarray(A, K):\n \n \n N = len(A)\n P = [0]\n\n for x in A:\n P.append(P[-1] + x)\n\n #Want smallest y-x with Py - Px >= K\n ans = N+1 # N+1 is impossible\n monoq = collections.deque() #opt(y) candidates, represented as indices \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0of P\n for y, Py in enumerate(P):\n #Want opt(y) = largest x with Px <= Py - K\n if not monoq: \n if Py>=K: return 1\n while monoq and Py <= P[monoq[-1]]:\n monoq.pop()\n\n while monoq and Py - P[monoq[0]] >= K:\n ans = min(ans, y - monoq.popleft())\n\n monoq.append(y)\n\n return ans if ans < N+1 else -1\n \n \nfor t in range(int(input())):\n N, D = [int(x) for x in input().split()]\n \n A = [int(x) for x in input().split()] \n \n print(shortestSubarray(A, D))\n \n"]
{"inputs": [["2", "5 5", "1 2 3 1 -5", "5 1", "1 2 3 1 -5"]], "outputs": [["2", "1"]]}
INTERVIEW
PYTHON3
CODECHEF
866
5fca51d7d26d72731f2fbb5fd13f9acb
UNKNOWN
Rupsa really loves triangles. One day she came across an equilateral triangle having length of each side as an integer N. She started wondering if it was possible to transform the triangle keeping two sides fixed and alter the third side such that it still remains a triangle, but the altered side will have its length as an even integer, and the line drawn from the opposite vertex to the mid-point of the altered side is of integral length. Since Rupsa is in a hurry to record a song for Chef as he really loves her songs, you must help her solve the problem as fast as possible. -----Input----- The first line of input contains an integer T denoting the number of test cases. Each test-case contains a single integer N. -----Output----- For each test case, output "YES" if the triangle transformation is possible, otherwise "NO" (quotes for clarity only, do not output). -----Constraints----- - 1 ≤ T ≤ 106 - 1 ≤ N ≤ 5 x 106 -----Sub tasks----- - Subtask #1: 1 ≤ T ≤ 100, 1 ≤ N ≤ 104 (10 points) - Subtask #2: 1 ≤ T ≤ 104, 1 ≤ N ≤ 106 (30 points) - Subtask #3: Original Constraints (60 points) -----Example----- Input:2 5 3 Output:YES NO -----Explanation----- - In test case 1, make the length of any one side 6, and it will suffice.
["# cook your dish here\nimport math\ndef isPos(num):\n if num%2==0:\n for i in range(num,2*num,1):\n if ((num**2)-((i/2)**2))**(1/2)==int(((num**2)-((i/2)**2))**(1/2)):\n return 'YES'\n return 'NO'\n else:\n for i in range(num+1,2*num,1):\n if ((num**2)-((i/2)**2))**(1/2)==int(((num**2)-((i/2)**2))**(1/2)):\n return 'YES'\n return 'NO'\n\ntest = int(input())\nfor __ in range(test):\n num=int(input())\n print(isPos(num))\n", "# cook your dish here\nimport math\nt = int(input())\nfor _ in range(t):\n n = int(input())\n count = 0\n for i in range(2, 2*n, 2):\n #print(i)\n h = math.sqrt(n*n-(i*i/4))\n #print(h)\n if h.is_integer()== True:\n count+=1\n else:\n count+=0\n if count>=1:\n print(\"YES\")\n else:\n print(\"NO\")", "t=int(input())\nimport math\n\nfor i in range(t):\n b=[]\n n=int(input())\n for p in range(n+1,2*n):\n if p%2==0:\n \n a= math.sqrt(n**2 - (p/2)**2)\n if a-int(a)==0:\n b.append(i)\n if len(b)==0:\n print(\"NO\")\n elif len(b)!=0:\n print(\"YES\") \n \n \n", "import math\nt = int(input())\nfor _ in range(0,t):\n n = int(input())\n #print(n)\n sides = []\n for i in range(2,(n+n)):\n if i % 2 == 0 and i != n:\n sides.append(i//2)\n f = 0\n for i in sides:\n pyt = (n*n - i*i)\n if math.sqrt(pyt) - int(math.sqrt(pyt)) == 0.000000:\n print(\"YES\")\n f = 1\n break\n if f == 0:\n print(\"NO\")\n", "import math\nt = int(input())\nfor _ in range(0,t):\n n = int(input())\n #print(n)\n sides = []\n for i in range(2,(n+n)):\n if i % 2 == 0 and i != n:\n sides.append(i//2)\n f = 0\n for i in sides:\n pyt = (pow(n,2)) - (pow(i,2))\n if math.sqrt(pyt) - int(math.sqrt(pyt)) == 0.000000:\n print(\"YES\")\n f = 1\n break\n if f == 0:\n print(\"NO\")\n", "t=int(input())\nfor i in range(t):\n n=int(input())\n c=0\n for j in range(2,n,2):\n if int((n**2-j**2)**0.5)==(n**2-j**2)**0.5:\n c=c or 1\n break\n else:\n c=c or 0\n if c==1:\n print(\"YES\")\n else:\n print(\"NO\")\n", "t=int(input())\nfor i in range(t):\n n=int(input())\n ans=0\n for j in range(2,n,2):\n if int((n**2-j**2)**0.5)==(n**2-j**2)**0.5:\n ans=ans or 1\n break\n else:\n ans=ans or 0\n if ans==1:\n print(\"YES\")\n else:\n print(\"NO\")\n\n"]
{"inputs": [["2", "5", "3"]], "outputs": [["YES", "NO"]]}
INTERVIEW
PYTHON3
CODECHEF
2,230
3bb95ab5557d440d36c3f44fbfde4d79
UNKNOWN
The faculty of application management and consulting services (FAMCS) of the Berland State University (BSU) has always been popular among Berland's enrollees. This year, N students attended the entrance exams, but no more than K will enter the university. In order to decide who are these students, there are series of entrance exams. All the students with score strictly greater than at least (N-K) students' total score gets enrolled. In total there are E entrance exams, in each of them one can score between 0 and M points, inclusively. The first E-1 exams had already been conducted, and now it's time for the last tribulation. Sergey is the student who wants very hard to enter the university, so he had collected the information about the first E-1 from all N-1 enrollees (i.e., everyone except him). Of course, he knows his own scores as well. In order to estimate his chances to enter the University after the last exam, Sergey went to a fortune teller. From the visit, he learnt about scores that everyone except him will get at the last exam. Now he wants to calculate the minimum score he needs to score in order to enter to the university. But now he's still very busy with minimizing the amount of change he gets in the shops, so he asks you to help him. -----Input----- The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows. The first line of each test case contains four space separated integers N, K, E, M denoting the number of students, the maximal number of students who'll get enrolled, the total number of entrance exams and maximal number of points for a single exam, respectively. The following N-1 lines will contain E integers each, where the first E-1 integers correspond to the scores of the exams conducted. The last integer corresponds to the score at the last exam, that was predicted by the fortune-teller. The last line contains E-1 integers denoting Sergey's score for the first E-1 exams. -----Output----- For each test case, output a single line containing the minimum score Sergey should get in the last exam in order to be enrolled. If Sergey doesn't have a chance to be enrolled, output "Impossible" (without quotes). -----Constraints----- - 1 ≤ T ≤ 5 - 1 ≤ K < N ≤ 104 - 1 ≤ M ≤ 109 - 1 ≤ E ≤ 4 -----Example----- Input:1 4 2 3 10 7 7 7 4 6 10 7 10 9 9 9 Output:4 -----Explanation----- Example case 1. If Sergey gets 4 points at the last exam, his score will be equal to 9+9+4=22. This will be the second score among all the enrollees - the first one will get 21, the second one will get 20 and the third will have the total of 26. Thus, Sergey will enter the university.
["# cook your dish here\nt=int(input())\nfor i in range(t):\n (n,k,e,m)=tuple(map(int,input().split()))\n scores=[]\n for j in range(n-1):\n scores.append(sum(list(map(int,input().split()))))\n scores.sort(reverse=True);\n bsc=scores[k-1];\n msc=sum(list(map(int,input().split())))\n mini=bsc-msc+1\n if(mini<0):\n print(0)\n elif(mini>m):\n print(\"Impossible\")\n else:\n print(mini)\n", "t=int(input())\nfor i in range(t):\n n,k,e,m=map(int,input().split())\n p=[]\n for i in range(n-1):\n p.append(sum(map(int,input().split())))\n q=sum(map(int,input().split()))\n p.sort()\n d=p[n-k-1]-q\n if(d+1>m):\n print('Impossible')\n elif(d<=-1):\n print(0)\n else:\n print(d+1)", "t=int(input())\nfor i in range(t):\n n,k,e,m=map(int,input().split())\n p=[]\n for i in range(n-1):\n p.append(sum(map(int,input().split())))\n q=sum(map(int,input().split()))\n p.sort()\n d=p[n-k-1]-q\n if(d+1>m):\n print('Impossible')\n elif(d<=-1):\n print(0)\n else:\n print(d+1)", "\nfor i in range(int(input())):\n n=list(map(int,input().split()))\n a = []\n for j in range(n[0]-1):\n a.append(sum(map(int,input().split())))\n\n re = sum(map(int, input().split()))\n\n a.sort(reverse=True)\n s = a[n[1] - 1]\n b = s - re + 1\n if b<0:\n print(\"0\")\n elif b <=n[3]:\n print(b)\n else:\n print(\"Impossible\")", "\nfor i in range(int(input())):\n n=list(map(int,input().split()))\n a = []\n for j in range(n[0]-1):\n a.append(sum(map(int,input().split())))\n\n re = sum(map(int, input().split()))\n\n a.sort(reverse=True)\n s = a[n[1] - 1]\n b = s - re + 1\n if b<0:\n print(\"0\")\n elif b > n[3]:\n print(\"Impossible\")\n else:\n print(b)", "# cook your dish here\nt = int(input())\nwhile(t>0):\n n,k,e,m = map(int,input().split())\n scores = []\n for i in range(n-1):\n sc = [int(x) for x in input().split()]\n scores.append(sum(sc))\n ram = [int(x) for x in input().split()]\n r = sum(ram)\n scores.sort(reverse = True)\n v = scores[k - 1]\n reqd = v - r + 1\n if(reqd < 0):\n print(\"0\")\n elif(reqd > m):\n print(\"Impossible\")\n else:\n print(reqd)\n t -= 1", "# cook your dish here\nt = int(input())\nwhile(t>0):\n n,k,e,m = map(int,input().split())\n scores = []\n for i in range(n-1):\n sc = [int(x) for x in input().split()]\n scores.append(sum(sc))\n ram = [int(x) for x in input().split()]\n r = sum(ram)\n scores.sort(reverse = True)\n v = scores[k - 1]\n reqd = v - r + 1\n if(reqd < 0):\n print(\"0\")\n elif(reqd > m):\n print(\"Impossible\")\n else:\n print(reqd)\n t -= 1", "# cook your dish here\nt = int(input())\nwhile(t>0):\n n,k,e,m = map(int,input().split())\n scores = []\n for i in range(n-1):\n sc = [int(x) for x in input().split()]\n scores.append(sum(sc))\n ram = [int(x) for x in input().split()]\n r = sum(ram)\n scores.sort(reverse = True)\n v = scores[k - 1]\n reqd = v - r + 1\n if(reqd < 0):\n print(\"0\")\n elif(reqd > m):\n print(\"Impossible\")\n else:\n print(reqd)\n t -= 1", "for i in range(int(input())):\n n, k, e, m = list(map(int,input().split()))\n stu = n-k-1\n sum_list = []\n for i in range(n-1):\n l = list(map(int, input().split()))\n sum_list.append(sum(l))\n score = list(map(int,input().split()))\n sum_ser = sum(score)\n sum_list.sort()\n x = max(sum_list[stu] + 1 - sum_ser,0)\n if x<m:\n print(x)\n else:\n print(\"Impossible\")\n", "# cook your dish here\nfor _ in range(int(input())):\n n,k,e,m=map(int,input().strip().split())\n res_arr=[]\n \n for i in range(n-1):\n res_arr.append(sum(map(int,input().strip().split())))\n \n res_arr=sorted(res_arr,reverse=True)[:k]\n serg_mrks=sum(map(int,input().strip().split()))\n \n least_max=res_arr[k-1]\n if(least_max<m*e):\n if(least_max>=serg_mrks):\n finl_mrks=least_max-serg_mrks+1\n print(finl_mrks if finl_mrks<=m else 'Impossible')\n else:\n print(0)\n else:\n print('Impossible')", "# cook your dish here\n\nfor _ in range(int(input())):\n n,k,e,m=map(int,input().strip().split())\n res_arr=[]\n \n for i in range(n-1):\n res_arr.append(sum(map(int,input().strip().split())))\n \n res_arr=sorted(res_arr,reverse=True)[:k]\n serg_mrks=sum(map(int,input().strip().split()))\n \n least_max=res_arr[k-1]\n if(least_max<m*e):\n if(least_max>=serg_mrks):\n finl_mrks=least_max-serg_mrks+1\n print(finl_mrks if finl_mrks<=m else 'Impossible')\n else:\n print(0)\n else:\n print('Impossible')", "for t in range(int(input())):\n n, k, e, m = map(int,input().split())\n stud = n-k-1\n sum_list = []\n for i in range(n-1):\n l = list(map(int, input().split()))\n sum_list.append(sum(l))\n score = list(map(int,input().split()))\n sum_sergey = sum(score)\n sum_list.sort()\n x = max(sum_list[stud] + 1 - sum_sergey,0)\n if x<m:\n print(x)\n else:\n print(\"Impossible\")", "for t in range(int(input())):\n n, k, e, m = map(int,input().split())\n stud = n-k-1\n sum_list = []\n for i in range(n-1):\n l = list(map(int, input().split()))\n sum_list.append(sum(l))\n score = list(map(int,input().split()))\n sum_sergey = sum(score)\n sum_list.sort()\n x = sum_list[stud] + 1 - sum_sergey\n if x<m and x>0:\n print(x)\n elif x<=0:\n print(0)\n else:\n print(\"Impossible\")", "# cook your dish here\nfor test in range(0,int(input())):\n N,K,E,M = map(int,input().split())\n scores = []\n for i in range(0,N-1):\n scores.append(sum(list(map(int,input().split()))))\n sergey_score = sum(list(map(int,input().split())))\n scores.sort()\n #using max because maybe Sergey's two exam scores are sufficient to qualify\n req_score = max(scores[N-K-1]-sergey_score+1,0)\n \n if req_score<=M:\n print(req_score) \n else:\n print(\"Impossible\")", "# cook your dish here\nfor test in range(0,int(input())):\n N,K,E,M = map(int,input().split())\n scores = []\n for i in range(0,N-1):\n scores.append(sum(list(map(int,input().split()))))\n sergey_score = sum(list(map(int,input().split())))\n scores.sort()\n #using max because maybe Sergey's two exam scores are sufficient to qualify\n req_score = max(scores[N-K-1]-sergey_score+1,0)\n \n if req_score<=M:\n print(req_score) \n else:\n print(\"Impossible\")", "# cook your dish here\ntc = int(input())\nwhile tc>0 :\n N,K,E,M = map(int,input().split())\n sumi = []\n for i in range(N-1):\n a = list(map(int,input().split()))\n sumi.append(sum(a))\n \n my_score = list(map(int,input().split()))\n my_sum = sum(my_score)\n \n sumi = sorted(sumi)\n answer = max(sumi[N-K-1]+1-my_sum,0)\n if answer > M:\n answer = \"Impossible\"\n print(answer)\n tc = tc - 1", "for i in range(int(input())):\n n,k,e,m=map(int,input().split())\n s = [sum(list(map(int, input().split()))) for j in range(n-1)]\n s.sort(reverse=True)\n ob = sum(list(map(int, input().split())))\n if(s[k-1]-ob+1>m):\n print(\"Impossible\")\n else:\n print(max(0,s[k-1]-ob+1))", "# cook your dish here\nfrom sys import stdin, stdout\nreadline, writeline = stdin.readline, stdout.write\n\n\nfor _ in range(int(readline())):\n n, k, e, m = list(map(int, readline().strip().split()))\n scores = []\n for _ in range(n-1):\n scores.append(sum(list(map(int, readline().strip().split()))))\n scores.sort()\n my = sum(list(map(int, readline().strip().split())))\n ans = scores[-k]+1 - my\n print(max(0, ans) if ans <= m else \"Impossible\")\n", "# cook your dish here\nfor _ in range(int(input())):\n n,k,e,m = map(int,input().split())\n s = []\n for i in range(n-1):\n a = [int(x) for x in input().split()]\n s.append(sum(a))\n s.sort(reverse=True)\n a = [int(x) for x in input().split()]\n c = s[k-1]+1-sum(a)\n if(c > m):\n print(\"Impossible\")\n else:\n if(c > 0):\n print(c)\n else:\n print(0)", "t = int(input())\n\nfor _ in range(t):\n n, k, e, m = [int(x) for x in input().split()]\n \n s = []\n \n for i in range(n-1):\n a = [int(x) for x in input().split()]\n \n s.append(sum(a))\n \n s.sort()\n s.reverse()\n \n a = [int(x) for x in input().split()]\n ap = sum(a)\n \n ans = s[k-1]+1-sum(a)\n \n if(ans > m):\n print(\"Impossible\")\n else:\n if(ans > 0):\n print(ans)\n else:\n print(0)", "# cook your dish here\nfor _ in range(int(input())):\n n, k, e, m = list(map(int, input().split()))\n all_marks = []\n for i in range(n-1):\n marks = sum(list(map(int, input().split())))\n all_marks.append(marks)\n \n ser = list(map(int, input().split()))\n\n all_marks = sorted(all_marks)\n \n q = all_marks[n-k-1:]\n \n ser_req = min(q) - sum(ser) + 1\n \n if ser_req > m:\n print(\"Impossible\")\n else:\n if ser_req>0:\n print(ser_req)\n else:\n print(0)"]
{"inputs": [["1", "4 2 3 10", "7 7 7", "4 6 10", "7 10 9", "9 9"]], "outputs": [["4"]]}
INTERVIEW
PYTHON3
CODECHEF
8,449
ef1d573c6fb038e8523c0a7165298926
UNKNOWN
Chef likes toys. His favourite toy is an array of length N. This array contains only integers. He plays with this array every day. His favourite game with this array is Segment Multiplication. In this game, the second player tells the left and right side of a segment and some modulo. The first player should find the multiplication of all the integers in this segment of the array modulo the given modulus. Chef is playing this game. Of course, he is the first player and wants to win all the games. To win any game he should write the correct answer for each segment. Although Chef is very clever, he has no time to play games. Hence he asks you to help him. Write the program that solves this problem. -----Input----- The first line of the input contains an integer N denoting the number of elements in the given array. Next line contains N integers Ai separated with spaces. The third line contains the number of games T. Each of the next T lines contain 3 integers Li, Ri and Mi, the left side of the segment, the right side of segment and the modulo. -----Output----- For each game, output a single line containing the answer for the respective segment. -----Constrdaints----- - 1 ≤ N ≤ 100,000 - 1 ≤ Ai ≤ 100 - 1 ≤ T ≤ 100,000 - 1 ≤ Li ≤ Ri ≤ N - 1 ≤ Mi ≤ 109 -----Example----- Input: 5 1 2 3 4 5 4 1 2 3 2 3 4 1 1 1 1 5 1000000000 Output: 2 2 0 120
["# # # # n = int(input())\r\n# # # # arr = list(map(int , input().split()))\r\n# # # # for _ in range(int(input())):\r\n# # # # \tl,r,mod = map(int , input().split())\r\n# # # # \tpro = 1\r\n# # # # \tfor i in range(l - 1,r):\r\n# # # # \t\tpro *= arr[i]\r\n# # # # \tprint(pro % mod) #sample testcases passed #TLE\r\n# # # import numpy #or use math\r\n# # # n = int(input())\r\n# # # arr = list(map(int , input().split()))\r\n# # # for _ in range(int(input())):\r\n# # # \tl,r,mod = map(int , input().split())\r\n# # # \tprint(numpy.prod(arr[l - 1:r]) % mod) #sample cases passed, WA\r\n# # import math\r\n# # primes,dic,t = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97],{},0\r\n# # for i in primes:\r\n# # dic[i] = t\r\n# # t += 1\r\n# # def primeFactors(n,arr): \r\n# # for i in range(2,int(math.sqrt(n)) + 1,2): \r\n# # while(n % i == 0): \r\n# # arr[dic[i]] += 1 \r\n# # n /= i\r\n# # if(n > 2):\r\n# # arr[dic[n]] += 1\r\n# # return arr\r\n# # n = int(input())\r\n# # A = list(map(int , input().split()))\r\n# # dp = [0]*len(primes)\r\n# # for i in range(1,n + 1):\r\n# # r = [dp[i - 1]].copy()\r\n# # dp.append(primeFactors(A[i - 1],r))\r\n# # for _ in range(int(input())):\r\n# # li,ri,m=list(map(int,input().split()))\r\n# # ans = 1\r\n# # for i in range(len(primes)):\r\n# # ans *= (pow(primes[i],dp[ri][i] - dp[li - 1][i],m)) % m\r\n# # print(ans % m) #NZEC\r\n# import math\r\n# primes=[2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97]\r\n# dic={}\r\n# t=0\r\n# for i in primes:\r\n# dic[i]=t\r\n# t+=1\r\n# def primeFactors(n,arr): \r\n# while(n % 2 == 0):\r\n# arr[dic[2]] += 1 \r\n# n /= 2\r\n# for i in range(3,int(math.sqrt(n))+1,2): \r\n# while(n % i == 0): \r\n# arr[dic[i]] += 1 \r\n# n /= i\r\n# if(n > 2): \r\n# arr[dic[n]] += 1\r\n# return arr\r\n# N = int(input())\r\n# A = list(map(int , input().split()))\r\n# dp = [[0]*len(primes)]\r\n# for i in range(1,N + 1):\r\n# r = dp[i - 1].copy()\r\n# dp.append(primeFactors(A[i - 1],r))\r\n# for _ in range(int(input())):\r\n# l,r,m = list(map(int , input().split()))\r\n# ans = 1\r\n# for i in range(len(primes)):\r\n# ans *= (pow(primes[i],dp[r][i] - dp[l - 1][i],m)) % m\r\n# print(ans % m)\r\nimport sys \r\nimport math\r\ninput = sys.stdin.readline\r\nprimes=[2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97]\r\ndic={}\r\nt=0\r\nfor i in primes:\r\n dic[i]=t\r\n t+=1\r\ndef primeFactors(n,arr): \r\n while n % 2 == 0: \r\n arr[dic[2]]+=1 \r\n n = n / 2\r\n\r\n for i in range(3,int(math.sqrt(n))+1,2): \r\n while n % i== 0: \r\n arr[dic[i]]+=1 \r\n n = n / i \r\n\r\n if n > 2: \r\n arr[dic[n]]+=1\r\n return arr\r\ndef main():\r\n N=int(input())\r\n A=list(map(int,input().split()))\r\n tp=[0]*len(primes)\r\n dp=[]\r\n dp.append(tp)\r\n for i in range(1,N+1):\r\n # print(i)\r\n r=dp[i-1].copy()\r\n t=primeFactors(A[i-1],r)\r\n dp.append(t)\r\n t=int(input())\r\n for _ in range(t):\r\n l,r,m=list(map(int,input().split()))\r\n if(m==1):\r\n print(0)\r\n else:\r\n ans=1\r\n for i in range(len(primes)):\r\n ans=ans*(pow(primes[i],dp[r][i]-dp[l-1][i],m))%m\r\n print(ans%m)\r\n \r\ndef __starting_point():\r\n main()\n__starting_point()", "primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97]\ndef getPrimeFactors(num):\n arr = [0]*25\n for index,i in enumerate(primes):\n if i > num:\n break\n while num%i == 0:\n arr[index]+=1\n num //= i\n return arr\n\ndef findPower(arr, mod):\n ans = 1\n for index,i in enumerate(arr):\n if i != 0:\n ans*=pow(primes[index], i, mod)\n if ans > mod:\n ans%=mod\n return ans%mod\n\nn = int(input())\narr = list(map(int, input().strip().split()))\n\ncumarr = []\ntemp = [0]*25\ncumarr.append(temp.copy())\n\nfor i in arr:\n for index,p in enumerate(primes):\n if p > i:\n break\n while i%p == 0:\n temp[index]+=1\n i //= p\n cumarr.append(temp.copy())\n\n\nfor x in range(int(input())):\n l, r, m = map(int, input().strip().split())\n ans = findPower([x-y for x,y in zip(cumarr[r], cumarr[l-1])], m)\n print(ans)", "from sys import stdin\n\nprimes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97]\n\ndef getPrime(n):\n \n arr = [0]*25\n for i,p in enumerate( primes ):\n if p > n:\n break\n \n while n % p == 0:\n arr[i] += 1\n n //= p\n \n \n return arr\n\n\ndef matAdd(matA , matB):\n \n arr = []\n for i in range(25):\n arr.append( matB[i] + matA[i] )\n \n return arr\n\n\ndef matSub( matA , matB ):\n \n arr = []\n \n for i in range(25):\n arr.append( matA[i] - matB[i] )\n \n return arr\n\n\ndef getPow( arr , M ):\n \n ans = 1\n \n for i , a in enumerate( arr ):\n \n if a != 0:\n\n ans *= pow( primes[i] , a , M )\n \n if ans > M:\n ans %= M\n \n return ans%M\n\n\n\nn = int(input())\narr = list(map(int,input().strip().split()))\n\ntemp = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\npref = [ [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] ]\n\n\nfor a in arr:\n \n for i,p in enumerate( primes ):\n if p > a:\n break\n \n while a % p == 0:\n temp[i] += 1\n a //= p\n \n pref.append( temp.copy() )\n\n \nfor po in range( int(input()) ):\n \n a , b , M = map( int , input().strip().split() )\n \n ans = getPow( [ x-y for (x,y) in zip( pref[b] , pref[a-1] ) ] , M )\n \n print(ans%M)"]
{"inputs": [["5", "1 2 3 4 5", "4", "1 2 3", "2 3 4", "1 1 1", "1 5 1000000000"]], "outputs": [["2", "2", "0", "120"]]}
INTERVIEW
PYTHON3
CODECHEF
6,308
2a34c855f8d198d69e5a99e8a16d99ec
UNKNOWN
Two words rhyme if their last 3 letters are a match. Given N words, print the test case number (of the format Case : num) followed by the rhyming words in separate line adjacent to each other. The output can be in anyorder. -----Input----- First line contains the number of test case T The next line contains the number of words N Next N words follow . They’ll contain only alphabets from ‘a’-‘z’. -----Output----- Print case number (for each test case) of the format Case : num followed by the words that rhyme in a new line. -----Constraints----- 1 <= T <= 5 1 <= N <= 1000 3 <= length of each word <= 1000 -----Example----- Input: 3 3 nope qwerty hope 5 brain drain request grain nest 4 these words dont rhyme Output: Case : 1 hope nope qwerty Case : 2 brain drain grain nest request Case : 3 these dont words rhyme -----Explanation----- Case : 2 brain drain grain nest request Case : 3 these dont words rhyme Explanation for case 1: since hope and nope rhyme (suffix “ope” matches), we print them in the same line and qwerty In a new line. Note that qwerty nope hope is also correct (the output can be in any order )
["t = int(input())\nfor i in range(t):\n n = int(input())\n suffixes = {}\n xx = input().split()\n for x in range(n):\n try:\n a = suffixes[xx[x][-3:]]\n except Exception as e:\n a = []\n a.append(xx[x])\n\n suffixes.update({xx[x][-3:]: a})\n\n print(\"Case : %d\" % (i + 1))\n for a in sorted(suffixes):\n print(\"\".join(b + \" \" for b in sorted(suffixes[a])).strip())"]
{"inputs": [["3", "3", "nope qwerty hope", "5", "brain drain request grain nest", "4", "these words dont rhyme"]], "outputs": [["Case : 1", "hope nope", "qwerty", "Case : 2", "brain drain grain", "nest request", "Case : 3", "these", "dont", "words", "rhyme"]]}
INTERVIEW
PYTHON3
CODECHEF
382
d0c9251677ba9ea0f51f5787adb3246c
UNKNOWN
Indraneel has to sort the books in his library. His library has one long shelf. His books are numbered $1$ through $N$ and he wants to rearrange the books so that they appear in the sequence $1,2, ..., N$. He intends to do this by a sequence of moves. In each move he can pick up any book from the shelf and insert it at a different place in the shelf. Suppose Indraneel has $5$ books and they are initially arranged in the order 21453214532 \quad 1 \quad 4 \quad 5 \quad 3 Indraneel will rearrange this in ascending order by first moving book $1$ to the beginning of the shelf to get 12453124531 \quad 2 \quad 4 \quad 5 \quad 3 Then, moving book $3$ to position $3$, he gets 12345123451 \quad 2 \quad 3 \quad 4 \quad 5 Your task is to write a program to help Indraneel determine the minimum number of moves that are necessary to sort his book shelf. -----Input:----- The first line of the input will contain a single integer $N$ indicating the number of books in Indraneel's library. This is followed by a line containing a permutation of $1, 2, ..., N$ indicating the intial state of Indraneel's book-shelf. -----Output:----- A single integer indicating the minimum number of moves necessary to sort Indraneel's book-shelf. -----Constraints:----- - $1 \leq N \leq 200000$. - You may also assume that in $50 \%$ of the inputs, $1 \leq N \leq 5000$. -----Sample Input----- 5 2 1 4 5 3 -----Sample Output----- 2
["n=int(input())\narr=[int(x) for x in input().split()]\nl=[1]*n\nif sorted(arr)==arr:\n print('0')\nelse:\n for i in range(0,len(arr)):\n for j in range(i):\n if arr[i]>=arr[j] and l[i]<l[j]+1:\n l[i]=l[j]+1\n print(n-max(l))", "n=int(input())\narr=[int(x) for x in input().split()]\nl=[1]*n\nif n==0 or n==1:\n print('0')\nfor i in range(0,len(arr)):\n for j in range(i):\n if arr[i]>=arr[j] and l[i]<l[j]+1:\n l[i]=l[j]+1\n\nprint(n-max(l))", "n=int(input())\narr=[int(x) for x in input().split()]\nl=[1]*n\nfor i in range(0,len(arr)):\n for j in range(i):\n if arr[i]>=arr[j] and l[i]<l[j]+1:\n l[i]=l[j]+1\n\nprint(n-max(l))"]
{"inputs": [["5", "2 1 4 5 3"]], "outputs": [["2"]]}
INTERVIEW
PYTHON3
CODECHEF
718
68ab367651444d831a37bc3fb1b100c1
UNKNOWN
Zonal Computing Olympiad 2012, 26 Nov 2011 The year is 2102 and today is the day of ZCO. This year there are N contests and the starting and ending times of each contest is known to you. You have to participate in exactly one of these contests. Different contests may overlap. The duration of different contests might be different. There is only one examination centre. There is a wormhole V that transports you from your house to the examination centre and another wormhole W that transports you from the examination centre back to your house. Obviously, transportation through a wormhole does not take any time; it is instantaneous. But the wormholes can be used at only certain fixed times, and these are known to you. So, you use a V wormhole to reach the exam centre, possibly wait for some time before the next contest begins, take part in the contest, possibly wait for some more time and then use a W wormhole to return back home. If you leave through a V wormhole at time t1 and come back through a W wormhole at time t2, then the total time you have spent is (t2 - t1 + 1). Your aim is to spend as little time as possible overall while ensuring that you take part in one of the contests. You can reach the centre exactly at the starting time of the contest, if possible. And you can leave the examination centre the very second the contest ends, if possible. You can assume that you will always be able to attend at least one contest–that is, there will always be a contest such that there is a V wormhole before it and a W wormhole after it. For instance, suppose there are 3 contests with (start,end) times (15,21), (5,10), and (7,25), respectively. Suppose the V wormhole is available at times 4, 14, 25, 2 and the W wormhole is available at times 13 and 21. In this case, you can leave by the V wormhole at time 14, take part in the contest from time 15 to 21, and then use the W wormhole at time 21 to get back home. Therefore the time you have spent is (21 - 14 + 1) = 8. You can check that you cannot do better than this. -----Input format----- The first line contains 3 space separated integers N, X, and Y, where N is the number of contests, X is the number of time instances when wormhole V can be used and Y is the number of time instances when wormhole W can be used. The next N lines describe each contest. Each of these N lines contains two space separated integers S and E, where S is the starting time of the particular contest and E is the ending time of that contest, with S < E. The next line contains X space separated integers which are the time instances when the wormhole V can be used. The next line contains Y space separated integers which are the time instances when the wormhole W can be used. -----Output format----- Print a single line that contains a single integer, the minimum time needed to be spent to take part in a contest. -----Testdata----- All the starting and ending times of contests are distinct and no contest starts at the same time as another contest ends. The time instances when wormholes are available are all distinct, but may coincide with starting and ending times of contests. All the time instances (the contest timings and the wormhole timings) will be integers between 1 and 1000000 (inclusive). - Subtask 1 (30 marks) - Subtask 2 (70 marks) You may assume that 1 ≤ N ≤ 105, 1 ≤ X ≤ 105, and 1 ≤ Y ≤ 105. In 30% of the cases, 1 ≤ N ≤ 103, 1 ≤ X ≤ 103, and 1 ≤ Y ≤ 103. -----Sample Input----- 3 4 2 15 21 5 10 7 25 4 14 25 2 13 21 -----Sample Output----- 8
["import sys\nn, x, y = input().split(' ')\nn = int(n)\nx = int(x)\ny = int(y)\ncontests = {}\n\nfor i in range(n):\n s, e = input().split(' ')\n s = int(s)\n e = int(e)\n contests[(s, e)] = abs(s-e)\n\nv_time = input().split(' ')\nw_time = input().split(' ')\n\nv_time, w_time = list(map(int, v_time)), list(map(int, w_time))\nv_time.sort()\nw_time.sort()\n\n\nscore = sys.maxsize\n\ncontests = dict(sorted(contests.items(), key=lambda item: item[1]))\nfor k, v in contests.items():\n start=-1\n end = sys.maxsize\n for i in range(x):\n if v_time[i] > k[0]:\n break\n start = v_time[i]\n for j in range(y):\n if w_time[j] >= k[1]:\n end = w_time[j]\n break\n if start == -1:\n continue\n score = min(score, (end-start+1))\n if score-1 <= v:\n break\n\nprint(score)", "# cook your dish here\nimport sys\nimport bisect\ninput=sys.stdin.readline\nl=input().split()\nn=int(l[0])\nx=int(l[1])\ny=int(l[2])\nok=[]\nfor i in range(n):\n l=input().split()\n li=[int(i) for i in l]\n ok.append(li)\nl=input().split()\nxi=[int(i) for i in l]\nl=input().split()\nyi=[int(i) for i in l]\nxi.sort()\nyi.sort()\nmina=10**18\nfor i in range(n):\n num1=bisect.bisect_right(xi,ok[i][0])\n num2=bisect.bisect_left(yi,ok[i][1])\n if(num1>=1 and num2<y):\n mina=min(yi[num2]-xi[num1-1],mina)\nprint(mina+1)\n\n", "import bisect\ndef wormholes(tlist,vlist,wlist):\n sumlist=[]\n for i in range(len(tlist)):\n if tlist[i][0] not in vlist:\n x=bisect.bisect_left(vlist,tlist[i][0])\n x=x-1\n if x<0:\n continue\n else:\n x=vlist.index(tlist[i][0])\n if tlist[i][1] not in wlist:\n y=bisect.bisect_right(wlist,tlist[i][1])\n if y>=len(wlist):\n continue\n else:\n y=wlist.index(tlist[i][1])\n sumlist.append(wlist[y]-vlist[x]+1)\n return min(sumlist)\nn,x,y=input().split()\nn,x,y=int(n),int(x),int(y)\ntimelist=[]\nfor i in range(n):\n s,e=input().split()\n s,e=int(s),int(e)\n timelist.append([s,e])\nv=list(map(int,input().strip().split()))\nw=list(map(int,input().strip().split()))\nv.sort()\nw.sort()\nmiv=min(v)\nmaw=max(w)\nfor i in range(n):\n if timelist[i][0]<miv or timelist[i][1]>maw:\n timelist[i]=[0,0]\nwhile [0,0] in timelist:\n timelist.remove([0,0])\nprint(wormholes(timelist,v,w))\n", "import bisect\ndef wormholes(tlist,vlist,wlist):\n sumlist=[]\n miv=min(vlist)\n maw=max(wlist)\n for i in range(len(tlist)):\n if tlist[i][0]<miv or tlist[i][1]>maw:\n continue\n if tlist[i][0] not in vlist:\n x=bisect.bisect_left(vlist,tlist[i][0])\n x=x-1\n if x<0:\n continue\n else:\n x=vlist.index(tlist[i][0])\n if tlist[i][1] not in wlist:\n y=bisect.bisect_right(wlist,tlist[i][1])\n if y>=len(wlist):\n continue\n else:\n y=wlist.index(tlist[i][1])\n sumlist.append(wlist[y]-vlist[x]+1)\n return min(sumlist)\nn,x,y=input().split()\nn,x,y=int(n),int(x),int(y)\ntimelist=[]\nfor i in range(n):\n s,e=input().split()\n s,e=int(s),int(e)\n timelist.append([s,e])\nv=list(map(int,input().strip().split()))\nw=list(map(int,input().strip().split()))\nv.sort()\nw.sort()\nprint(wormholes(timelist,v,w))\n", "import bisect\ndef wormholes(tlist,vlist,wlist):\n sumlist=[]\n for i in range(len(tlist)):\n if tlist[i][0] not in vlist:\n x=bisect.bisect_left(vlist,tlist[i][0])\n x=x-1\n if x<0:\n continue\n else:\n x=vlist.index(tlist[i][0])\n if tlist[i][1] not in wlist:\n y=bisect.bisect_right(wlist,tlist[i][1])\n if y>=len(wlist):\n continue\n else:\n y=wlist.index(tlist[i][1])\n sumlist.append(wlist[y]-vlist[x]+1)\n return min(sumlist)\nn,x,y=input().split()\nn,x,y=int(n),int(x),int(y)\ntimelist=[]\nfor i in range(n):\n s,e=input().split()\n s,e=int(s),int(e)\n timelist.append([s,e])\nv=list(map(int,input().strip().split()))\nw=list(map(int,input().strip().split()))\nv.sort()\nw.sort()\nprint(wormholes(timelist,v,w))\n", "import bisect\ndef wormholes(tlist,vlist,wlist):\n sumlist=[]\n for i in range(len(tlist)):\n if tlist[i][0] not in vlist:\n x=bisect.bisect_left(vlist,tlist[i][0])\n x=x-1\n else:\n x=vlist.index(tlist[i][0])\n if tlist[i][1] not in wlist:\n y=bisect.bisect_right(wlist,tlist[i][1])\n else:\n y=wlist.index(tlist[i][1])\n if y<len(wlist) and x>=0:\n sumlist.append(wlist[y]-vlist[x]+1)\n return min(sumlist)\nn,x,y=input().split()\nn,x,y=int(n),int(x),int(y)\ntimelist=[]\nfor i in range(n):\n s,e=input().split()\n s,e=int(s),int(e)\n timelist.append([s,e])\nv=list(map(int,input().strip().split()))\nw=list(map(int,input().strip().split()))\nv.sort()\nw.sort()\nprint((wormholes(timelist,v,w)))# cook your dish here\n", "import bisect\ndef wormholes(tlist,vlist,wlist):\n sumlist=[]\n for i in range(len(tlist)):\n if tlist[i][0] not in vlist:\n x=bisect.bisect_left(vlist,tlist[i][0])\n x=x-1\n else:\n x=vlist.index(tlist[i][0])\n if tlist[i][1] not in wlist:\n y=bisect.bisect_right(wlist,tlist[i][1])\n else:\n y=wlist.index(tlist[i][1])\n if y<len(wlist) and x>=0:\n sumlist.append(wlist[y]-vlist[x]+1)\n return min(sumlist)\nn,x,y=input().split()\nn,x,y=int(n),int(x),int(y)\ntimelist=[]\nfor i in range(n):\n s,e=input().split()\n s,e=int(s),int(e)\n timelist.append([s,e])\nv=list(map(int,input().strip().split()))\nw=list(map(int,input().strip().split()))\nv.sort()\nw.sort()\nprint((wormholes(timelist,v,w)))# cook your dish here\n", "# cook your dish here\ndef bs1(arr,x):\n low = 0 \n high = len(arr) - 1 \n p = 0 \n while(low<=high):\n mid = (low + high)//2\n if(arr[mid]==x):\n return arr[mid]\n elif(arr[mid]<x):\n p = mid\n low = mid + 1 \n else:\n high = mid - 1 \n \n if arr[p] <= x:\n return arr[p]\n else:\n return 0\n \n\n\ndef bs2(arr, x):\n low = 0 \n high = len(arr)-1 \n p = 0\n while(low<=high):\n mid = (low + high)//2 \n if(arr[mid]==x):\n return arr[mid]\n elif(arr[mid]<x):\n low = mid + 1 \n else:\n p = mid\n high = mid - 1 \n if arr[p] >= x:\n return arr[p]\n else:\n return 1000000\n \n\n\nn,a,b = list(map(int,input().strip().split()))\ns = []\ne = []\nfor i in range(n):\n c,d = list(map(int,input().strip().split()))\n s.append(c)\n e.append(d)\nws = list(map(int,input().strip().split()))\nvs = list(map(int,input().strip().split()))\nws.sort()\nvs.sort()\nr = 1000000\nfor i in range( n):\n s1 = bs1(ws,s[i])\n e1 = bs2(vs,e[i])\n r1 = e1-s1+1 \n if(r1<r):\n r = r1\nprint(r)", "# cook your dish here\nn,a,b = list(map(int,input().strip().split()))\ns = []\ne = []\nfor i in range(n):\n c,d = list(map(int,input().strip().split()))\n s.append(c)\n e.append(d)\nws = list(map(int,input().strip().split()))\nvs = list(map(int,input().strip().split()))\nws.sort(reverse = True)\nvs.sort()\nr = 1000000\nfor i in range( n):\n s1 = 0\n e1 = 1000000\n for j in range(a):\n if(ws[j]<=s[i]):\n s1 = ws[j]\n break\n for j in range(b):\n if(vs[j]>=e[i]):\n e1 = vs[j]\n break\n r1 = e1-s1+1 \n if(r1<r):\n r = r1\nprint(r)", "# cook your dish here\nn, v, w = list(map(int,input().strip().split()))\ns = []\ne = []\nfor i in range(n):\n o, u = list(map(int,input().strip().split()))\n s.append(o)\n e.append(u)\nvs = list(map(int,input().strip().split()))\nws = list(map(int,input().strip().split()))\nvs.sort()\nws.sort()\nr = 1000000\nfor i in range(n):\n s1 = 0 \n e1 = 1000000\n for j in vs:\n if(s[i]>= j):\n s1 = j \n else:\n break\n for j in range(len(ws)-1,-1,-1):\n if(e[i]<= ws[j]):\n e1 = ws[j]\n else:\n break\n r1 = e1 - s1 + 1\n if(r1<r):\n r = r1\nprint(r)\n \n \n\n", "# cook your dish here\nimport sys\nimport bisect\ninput=sys.stdin.readline\nl=input().split()\nn=int(l[0])\nx=int(l[1])\ny=int(l[2])\nok=[]\nfor i in range(n):\n l=input().split()\n li=[int(i) for i in l]\n ok.append(li)\nl=input().split()\nxi=[int(i) for i in l]\nl=input().split()\nyi=[int(i) for i in l]\nxi.sort()\nyi.sort()\nmina=10**18\nfor i in range(n):\n num1=bisect.bisect_right(xi,ok[i][0])\n num2=bisect.bisect_left(yi,ok[i][1])\n if(num1>=1 and num2<y):\n mina=min(yi[num2]-xi[num1-1],mina)\nprint(mina+1)\n", "import itertools\n# cook your dish here\n\nN, X, Y = list(map(int, input().split()))\ncontests = []\nfor _ in range(N):\n contests.append(list(map(int, input().split())))\n\ninto = list(map(int, input().split()))\nouto = list(map(int, input().split()))\n\n \nworthwole = [(x,y) for x, y in itertools.product(into, outo) if x < y]\nworthwole = sorted(worthwole, key = lambda x : x[1] - x[0])\n# print(worthwole)\n\nresult = 0\nfound = False\nfor w in worthwole:\n for c in contests : \n if w[0] <= c[0] and w[1] >= c[1] : \n result = w[1] - w[0] + 1\n found = True\n break\n \n if found : break\n\nprint(result)\n", "# cook your dish here\nimport sys\nfrom operator import itemgetter\nn, x, y = map(int, input().strip().split())\ntests=[]\nfor _ in range(n):\n start, end = map(int, input().strip().split())\n tests.append([start,end,1+end-start])\nstart=[]\nstart[:]=map(int, input().strip().split())\nstart.sort()\nend=[]\nend[:]=map(int, input().strip().split())\nend.sort()\ntests.sort(key=itemgetter(0))\nwhile tests[0][0]<start[0]:\n tests.pop(0)\n n-=1\nj=0\nfor i in range(n):\n while j<x-1 and start[j+1]<=tests[i][0]:\n j+=1\n tests[i][2]+=tests[i][0]-start[j]\ntests.sort(key=itemgetter(1))\nwhile tests[-1][1]>end[-1]:\n tests.pop()\n n-=1\nj=y-1\nfor i in range(n-1,-1,-1):\n while j>0 and end[j-1]>=tests[i][1]:\n j-=1\n tests[i][2]+=end[j]-tests[i][1]\nminimo=tests[0][2]\nfor i in range(n):\n minimo=min(minimo, tests[i][2])\nprint(minimo)", "nk = [int(i) for i in input().split()]\nn = nk[0]\nx = nk[1]\ny = nk[2]\ncontests = []\ntime = []\nwhile n > 0 :\n contests.append([int(i) for i in input().split()])\n n = n - 1\nn = nk[0]\nvworm = [int(i) for i in input().split()]\nwworm = [int(i) for i in input().split()]\nvworm.sort(reverse=True)\nwworm.sort()\nt1=0\nt2=0\nmint = 10**6\n\nfor contest in contests :\n if contest[1] - contest[0] > mint :\n continue\n\n t1 =0\n for vbus in vworm :\n if vbus <= contest[0] :\n t1 = vbus\n break\n\n t2=0\n for wbus in wworm :\n if wbus >= contest[1]:\n t2 = wbus\n break\n\n if t1 > 0 and t2 > 0 and t2 >= t1:\n t = t2 - t1 + 1\n if t <= mint :\n mint = t\n\n\nprint(mint)\n", "# cook your dish here\ndef ub(arr,item):\n n=len(arr)\n low=0;high=n-1\n while low<=high:\n mid=low+(high-low)//2\n if arr[mid]==item:\n return mid\n elif arr[mid]<item:\n low=mid+1\n else:\n high=mid-1\n \n return low\n\n\ndef lb(arr,item):\n low=0;high=len(arr)-1\n while low<=high:\n mid=low+(high-low)//2\n if arr[mid]==item:\n return mid\n elif arr[mid]<item:\n low=mid+1\n else:\n high=mid-1\n return high\n\ndef main():\n n,x,y=map(int,input().split())\n timing=[]\n for i in range(n):\n p,q=map(int,input().split())\n timing.append((p,q))\n \n \n\n v=list(map(int,input().split()))\n\n w=list(map(int,input().split()))\n timing.sort()\n v.sort()\n w.sort()\n\n mn=1e18\n \n\n for i in range(n):\n s=lb(v,timing[i][0])\n e=ub(w,timing[i][1])\n if s>=0 and e<y:\n mn=min(mn,abs(v[s]-w[e])+1)\n \n print(mn)\nmain()", "# cook your dish here\ndef ub(arr,item):\n n=len(arr)\n low=0;high=n-1\n while low<=high:\n mid=low+(high-low)//2\n if arr[mid]==item:\n return mid\n elif arr[mid]<item:\n low=mid+1\n else:\n high=mid-1\n \n return low\n\n\ndef lb(arr,item):\n low=0;high=len(arr)-1\n while low<=high:\n mid=low+(high-low)//2\n if arr[mid]==item:\n return mid\n elif arr[mid]<item:\n low=mid+1\n else:\n high=mid-1\n return high\n\ndef main():\n n,x,y=list(map(int,input().split()))\n timing=[]\n for i in range(n):\n p,q=list(map(int,input().split()))\n timing.append((p,q))\n \n \n\n v=list(map(int,input().split()))\n\n w=list(map(int,input().split()))\n timing.sort()\n v.sort()\n w.sort()\n\n mn=1e18\n \n\n for i in range(n):\n s=lb(v,timing[i][0])\n e=ub(w,timing[i][1])\n if s>=0 and e<y:\n mn=min(mn,abs(v[s]-w[e])+1)\n \n print(mn)\nmain()\n \n \n \n \n\n", "def ub(arr,item):\n n=len(arr)\n low=0;high=n-1\n while low<=high:\n mid=low+(high-low)//2\n if arr[mid]==item:\n return mid\n elif arr[mid]<item:\n low=mid+1\n else:\n high=mid-1\n \n return low\n\n\ndef lb(arr,item):\n low=0;high=len(arr)-1\n while low<=high:\n mid=low+(high-low)//2\n if arr[mid]==item:\n return mid\n elif arr[mid]<item:\n low=mid+1\n else:\n high=mid-1\n return high\n\ndef main():\n n,x,y=list(map(int,input().split()))\n timing=[]\n for i in range(n):\n p,q=list(map(int,input().split()))\n timing.append((p,q))\n \n \n\n v=list(map(int,input().split()))\n\n w=list(map(int,input().split()))\n timing.sort()\n v.sort()\n w.sort()\n\n mn=1e18\n \n\n for i in range(n):\n s=lb(v,timing[i][0])\n e=ub(w,timing[i][1])\n if s>=0 and e<y:\n mn=min(mn,abs(v[s]-w[e])+1)\n \n print(mn)\nmain()\n \n \n \n \n", "# cook your dish here\nfrom sys import stdin, stdout\nimport math\n\n\ndef lower_bound(arr, ele):\n low = 0\n high = len(arr)-1\n while low <= high:\n mid = (low+high)//2\n if arr[mid] == ele:\n return arr[mid]\n elif ele < arr[mid]:\n high = mid-1\n else:\n low = mid+1\n if high > len(arr)-1 or high < 0:\n return -1\n return arr[high]\n\n\ndef upper_bound(arr, ele):\n low = 0\n high = len(arr)-1\n while low <= high:\n mid = (low+high)//2\n if arr[mid] == ele:\n return arr[mid]\n elif ele < arr[mid]:\n high = mid-1\n else:\n low = mid+1\n if low > len(arr)-1 or low < 0:\n return -1\n return arr[low]\n\n\ndef main():\n n, n_x, n_y = list(map(int, stdin.readline().split()))\n contests = [None]*n\n for i in range(n):\n start, end = list(map(int, stdin.readline().split()))\n contests[i] = (start, end)\n V = [int(x) for x in stdin.readline().split()]\n W = [int(x) for x in stdin.readline().split()]\n V.sort()\n W.sort()\n ans = math.inf\n for (start, end) in contests:\n opv = lower_bound(V, start)\n opw = upper_bound(W, end)\n if opv == -1 or opw == -1:\n continue\n ans = min(ans, opw - opv + 1)\n print(ans)\n\n\ndef __starting_point():\n main()\n\n__starting_point()"]
{"inputs": [["3 4 2", "15 21", "5 10", "7 25", "4 14 25 2", "13 21"]], "outputs": [["8"]]}
INTERVIEW
PYTHON3
CODECHEF
13,950
74760f93ddc0b5174d1ace704ddd4556
UNKNOWN
Sinchan and his friends loves to eat. They have a 2D rectangular cake which they want to share. Sinchan is very kind and offers his friends to eat the cake first, all friends goes one by one to eat the cake. Each friend will cut cake into two parts. First part of the cake will be largest possible square from the cake, that the friend will eat, and will leave the second part for others, it continues untill cake is over or every friend gets to eat the cake. Now Sinchan wonder how much cake would he be able to get. -----Input----- - First line of input contain T, denoting number of test case. - First line of each test case contains N, denoting number of friends. - Second line of test case contain L, B (L x B) denoting dimension of cake. -----Output----- - For each test case, if Sinchan gets to eat the cake print (without quotes) "Yes #" where # is area of cake that Sinchan gets. Otherwise print (without quotes) "No" -----Constraints----- - 1 ≤ T, N, L, B ≤ 1000 -----Example----- Input: 3 2 5 3 4 4 8 1 1 2 Output: Yes 2 No Yes 1 -----Explanation----- Example case 1. First friend divides 5x3 cake in 3x3 and 2x3 since 3x3 is largest possible square, second Friend divides 2x3 cake in 2x2 and 1x2 and eat 2x2 piece. Finaly Sinchan gets to eat and area of cake is 1*2 hence Output is (without quotes) "Yes 2"
["testcases=int(input())\nresults=[]\nfor i in range(0,testcases):\n friends=int(input())\n l,b=list(map(int,input().split()))\n over=False\n if b>l:\n temp=b\n b=l\n l=temp\n for counter in range(0,friends):\n if l==b:\n over=True\n break\n elif l>b:\n l=l-b\n if b>l:\n temp=b\n b=l\n l=temp\n \n if over:\n results.append(\"No\")\n else:\n results.append(\"Yes \"+str(l*b))\n\nfor i in range(0,testcases):\n print(results[i])\n", "# your code goes here\nt=int(input())\nwhile t>0:\n n=int(input())\n a=list(map(int,input().split()))\n m=a[0]\n n1=a[1]\n for i in range(0,n):\n if(m>n1):\n m=m-n1\n n1=n1\n else:\n m=m\n n1=n1-m\n ans=m*n1\n if(ans>0):\n print('Yes', ans)\n else:\n print('No')\n t-=1\n \n", "# cook your code here\nt=eval(input())\nwhile(t):\n n=eval(input())\n l,b=list(map(int,input().split()))\n for i in range(n):\n if(l<b):\n b-=l;\n else:\n l-=b;\n if(l>0 and b>0):\n print(\"Yes\",l*b)\n else:\n print(\"No\")\n t=t-1\n \n", "t=int(input())\nfor i in range(t):\n n=int(input())\n l,b=list(map(int,input().split()))\n while n>0:\n if l>b:\n l-=b\n else:\n b-=l\n n-=1\n if l*b>0:\n print(\"Yes\",l*b)\n else:\n print(\"No\")", "for _ in range(eval(input())):\n n = eval(input())\n [l,b] = list(map(int,input().split()))\n for i in range(n):\n if l > b :\n l -= b\n elif b > l:\n b -= l \n else:\n l=b=0\n break\n if b== 0 or l==0:\n break\n if b == 0 or l == 0:\n print('No')\n else:\n print('Yes',l*b)", "x = eval(input())\nfor i in range(x):\n y = eval(input())\n z = input()\n z = z.split(' ')\n a = int(z[0])\n b = int(z[1])\n while(y>0):\n temp = min(a,b)\n if a<b:\n b = b - temp\n else:\n a = a - temp\n y = y-1\n if a>0 and b>0:\n chick = a*b\n print(\"Yes \"+str(chick))\n else:\n print(\"No\")", "import sys\nlineArray = sys.stdin.readline().rstrip()\ntestcases = int(lineArray)\ncounttestcase = 0\nwhile counttestcase < testcases:\n friends = int(sys.stdin.readline().rstrip())\n lineArray = sys.stdin.readline().rstrip().split()\n length = int(lineArray[0])\n breadth = int(lineArray[1])\n for i in range(0,friends):\n if length == breadth:\n length = 0\n breadth = 0\n break\n if length < breadth:\n breadth = breadth - length\n else:\n length = length - breadth\n if length == 0 and breadth == 0:\n print(\"No\")\n else:\n print(\"Yes\", length*breadth)\n counttestcase = counttestcase + 1"]
{"inputs": [["3", "2", "5 3", "4", "4 8", "1", "1 2"]], "outputs": [["Yes 2", "No", "Yes 1"]]}
INTERVIEW
PYTHON3
CODECHEF
2,464
9197079e192343205cb3ebd87366d329
UNKNOWN
Chef and Roma are playing a game. Rules of the game are quite simple. Initially there are N piles of stones on the table. In each turn, a player can choose one pile and remove it from the table. Each player want to maximize the total number of stones removed by him. Chef takes the first turn. Please tell Chef the maximum number of stones he can remove assuming that both players play optimally. -----Input----- The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows. The first line of each test case contains a single integer N denoting the number of piles. The second line contains N space separated integers A1, A2, ..., AN denoting the number of stones in each pile. -----Output----- For each test case, output a single line containg the maximum number of stones that Chef can remove. -----Constraints----- - 1 ≤ Ai ≤ 109 - Subtask 1 (35 points): T = 10, 1 ≤ N ≤ 1000 - Subtask 2 (65 points): T = 10, 1 ≤ N ≤ 105 -----Example----- Input: 2 3 1 2 3 3 1 2 1 Output: 4 3
["# cook your dish here\nfor i in range(int(input())):\n n = int(input())\n l = list(map(int,input().split()))\n s = 0\n l.sort(reverse = True)\n for i in range(0,n,2):\n s = s+l[i]\n print(s)\n", "# cook your dish here\ntest_case = int(input())\nwhile test_case :\n n = int(input())\n array = list(map(int, input().strip().split()))\n \n array.sort(reverse = True)\n i = 0 \n s = 0 \n while(i < n) :\n s += array[i]\n i += 2 \n print(s)\n test_case -= 1\n \n \n \n \n \n \n \n \n \n \n", "t=int(input())\nwhile t:\n n=int(input())\n a=list(map(int,input().split()))\n c=0\n a.sort(reverse=True)\n for i in range(0,len(a),2):\n c+=a[i]\n print(c)\n t-=1", "# 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.sort(reverse=True)\n c=0\n for i in range(0,n,2):\n c+=l[i]\n print(c)", "# cook your dish here\nt=int(input())\nfor i in range(t):\n ans=0\n n=int(input())\n a=[int(x) for x in input().split()]\n lis=sorted(a,reverse=True)\n for val in range(0,len(lis),2):\n # print(val)\n ans=ans+lis[val]\n print(ans)", "for t in range(int(input())):\n n=int(input())\n a=sorted(list(map(int, input().split())),reverse=True)\n print(sum(a[::2]))", "# cook your dish here\nt=int(input())\nfor _ in range(t):\n n=int(input())\n s=list(map(int,input().split()))\n \n s.sort(reverse=True)\n cnt=0\n \n for i in range(0,n,2):\n cnt += s[i]\n \n print(cnt)", "# cook your dish here\nimport math\nt=int(input())\nfor _ in range(t):\n n=int(input())\n l=list(map(int,input().split()))\n l.sort(reverse=True)\n p=0\n for i in range(0,n,2):\n p+=l[i]\n print(p)\n", "for _ in range(int(input())):\n n=int(input())\n ar=[int(x) for x in input().split()]\n ar.sort(reverse=True)\n s=0\n for i in range(0,n,2):\n s+=ar[i]\n print(s)\n", "for i in range(int(input())):\n m=int(input())\n lst=list(map(int,input().split()))\n l=max(lst)\n lst.sort()\n count=0\n for i in range(m-1,-1,-2):\n count += lst[i]\n print(count)", "for _ in range(int(input())):\n n = int(input())\n a = list(map(int, input().split()))\n ans = 0\n while a:\n try:\n ans += max(a)\n # pos = a.index(max(a))\n a.remove(max(a))\n a.remove(max(a))\n except:\n break\n print(ans)\n", "# cook your dish here\nT = int(input())\nfor j in range(T):\n n = int(input())\n a = list(map(int, input().split()))\n a.sort(reverse=True)\n print(sum(a[::2]))", "# cook your dish here\nfor _ in range(int(input())):\n n = int(input())\n arr = list(map(int, input().split()))\n arr.sort()\n count = 0\n for i in range(n-1,-1,-2):\n count += arr[i]\n print(count) \n", "# cook your dish here\nfor _ in range(int(input())):\n n = int(input())\n arr = list(map(int,input().split()))\n count = 0\n arr.sort()\n for i in range(n-1,-1,-2):\n count += arr[i]\n print(count)", "# cook your dish here\nfor _ in range(int(input())):\n n = int(input())\n lis = list(map(int,input().split()))\n lis.sort()\n chef = sum([lis[i] for i in range(0,n,2)])\n other = sum(lis[i] for i in range(1,n,2))\n print(max(chef,other))", "for _ in range(int(input())):\n n = int(input())\n array = [int(i) for i in input().split()]\n array.sort()\n\n stones1 = sum([array[i] for i in range(0, n, 2)])\n stones2 = sum([array[i] for i in range(1, n, 2)])\n print(max(stones2, stones1)) ", "T = int(input())\nans = []\n\nfor _ in range(T):\n N = int(input())\n A = [int(i) for i in input().split()]\n\n A.sort(reverse=True)\n count = 0\n for i in range(0,N,2):\n count += A[i]\n ans.append(count)\n\nfor i in ans:\n print(i)\n", "# cook your dish here\nfor t in range(int(input())):\n\n N = int(input())\n arr = list(map(int, input().split()))\n arr.sort(reverse=True)\n\n count = 0\n\n for i in range(0, len(arr), 2):\n count += arr[i]\n\n print(count)\n", "# cook your dish here\n# -*- coding: utf-8 -*-\n\"\"\"\nCreated on Fri Oct 30 17:24:15 2020\n\n@author: Admin\n\"\"\"\n\nfor _ in range(int(input())):\n n=int(input())\n l=[int(i) for i in input().split()]\n g=sorted(l,reverse=True)\n s=0\n for r in range(0,len(l),2):\n s+=g[r]\n print(s)", "t = int(input())\nwhile t > 0:\n n = int(input())\n li = [int(x) for x in input().split()]\n li.sort(reverse=True)\n c = 0\n for i in range(n):\n if i % 2 == 0:\n c += li[i]\n print(c)\n t = t - 1\n", "# cook your dish here\nt=int(input().strip())\nfor _ in range(t):\n n = int(input().strip())\n a = list(map(int,input().strip().split(\" \")))\n a.sort(reverse=True)\n ans = 0\n for i in range(0,n,2):\n ans += a[i]\n print(ans)", "t=int(input())\nfor i in range(t):\n n=int(input())\n l=sorted(map(int, input().split()), reverse=True)\n print(sum(l[::2]))", "\nfrom sys import stdin\ndef main():\n n = int(stdin.readline())\n ls = [int(x) for x in stdin.readline().split()]\n ls = sorted(ls,reverse=True)\n s =0\n for i in range(0,n,2):\n s+= ls[i]\n print(s)\ndef __starting_point():\n for _ in range(int(stdin.readline())):\n main()\n\n__starting_point()"]
{"inputs": [["2", "3", "1 2 3", "3", "1 2 1"]], "outputs": [["4", "3"]]}
INTERVIEW
PYTHON3
CODECHEF
4,913
68356f6ecf5a2d610e379f803e665694
UNKNOWN
Did you know that there are over 40,000 varieties of Rice in the world ? There are so many dishes that can be prepared with Rice too. A famous chef from Mumbai, Tid Gusto prepared a new dish and named it 'Tid Rice'. He posted the recipe in his newly designed blog for community voting, where a user can plus (+) or minus (-) the recipe. The final score is just the sum of all votes, where (+) and (-) are treated as +1 and -1 respectively. But, being just a chef ( and not a codechef ) he forgot to take care of multiple votes by the same user. A user might have voted multiple times and Tid is worried that the final score shown is not the correct one. Luckily, he found the user logs, which had all the N votes in the order they arrived. Remember that, if a user votes more than once, the user's previous vote is first nullified before the latest vote is counted ( see explanation for more clarity ). Given these records in order ( and being a codechef yourself :) ), calculate the correct final score. -----Input----- First line contains T ( number of testcases, around 20 ). T cases follow. Each test case starts with N ( total number of votes, 1 <= N <= 100 ). Each of the next N lines is of the form "userid vote" ( quotes for clarity only ), where userid is a non-empty string of lower-case alphabets ( 'a' - 'z' ) not more than 20 in length and vote is either a + or - . See the sample cases below, for more clarity. -----Output----- For each test case, output the correct final score in a new line -----Example----- Input: 3 4 tilak + tilak + tilak - tilak + 3 ratna + shashi - ratna - 3 bhavani - bhavani + bhavani - Output: 1 -2 -1 Explanation Case 1 : Initially score = 0. Updation of scores in the order of user tilak's votes is as follows, ( + ): +1 is added to the final score. This is the 1st vote by this user, so no previous vote to nullify. score = 1 ( + ): 0 should be added ( -1 to nullify previous (+) vote, +1 to count the current (+) vote ). score = 1 ( - ) : -2 should be added ( -1 to nullify previous (+) vote, -1 to count the current (-) vote ). score = -1 ( + ): +2 should be added ( +1 to nullify previous (-) vote, +1 to count the current (+) vote ). score = 1
["import sys\n\ndef f(p):\n votes = {}\n for x in range(p):\n str = sys.stdin.readline()\n t = str.split()\n votes[t[0]] = t[1]\n\n ans = 0\n for per in votes:\n if votes[per] == \"+\":\n ans= ans+1\n else:\n ans = ans-1\n\n return ans\n\nx = sys.stdin.readline()\nfor t in range(int(x)):\n p = sys.stdin.readline()\n print(f(int(p)))\n", "def rating():\n N = int(input())\n a = { }\n ans = 0\n while N:\n N-=1\n s = input()\n a[s[:-2]] = s[-1:]\n for k,v in a.items():\n if v == '+':\n ans += 1\n else:\n ans -= 1\n return ans\n\ndef main():\n T = int(input())\n while T:\n T -= 1\n rate = rating()\n print(rate)\n\ndef __starting_point():\n main()\n\n__starting_point()", "t = int(input())\nfor i in range(t):\n n = int(input())\n scores = {}\n for j in range(n):\n line = input()\n (key, value) = line.split(' ')\n if value == '+':\n scores[key] = 1\n else:\n scores[key] = -1\n sum = 0\n for k in scores:\n sum += scores[k]\n print(sum)\n", "import sys\nt=int(sys.stdin.readline().strip())\nfor i in range(t):\n votes={}\n n=int(sys.stdin.readline().strip())\n for j in range(n):\n s,v=sys.stdin.readline().strip().split(' ')\n if v=='+':\n votes[s]=1\n else:\n votes[s]=-1\n print(sum(votes.values()))\n\n\n"]
{"inputs": [["3", "4", "tilak +", "tilak +", "tilak -", "tilak +", "3", "ratna +", "shashi -", "ratna -", "3", "bhavani -", "bhavani +", "bhavani -"]], "outputs": [["1", "-2", "-1"]]}
INTERVIEW
PYTHON3
CODECHEF
1,274
b5a8110ac65fbd161d5b5b2a53c70448
UNKNOWN
This question is similar to the $"Operation$ $on$ $a$ $Tuple"$ problem in this month's Long Challenge but with a slight variation. Consider the following operations on a triple of integers. In one operation, you should: - Choose a positive integer $d>0$ and an arithmetic operation - in this case, it will only be addition. - Choose a subset of elements of the triple. - Apply arithmetic operation to each of the chosen elements. For example, if we have a triple $(3,5,7)$, we may choose to add $3$ to the first and third element, and we get $(6,5,10)$ using one operation. You are given an initial triple $(p,q,r)$ and a target triple $(a,b,c)$. Find the maximum number of operations needed to transform $(p,q,r)$ into $(a,b,c)$ or say the conversion is impossible . Input: - The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows. - The first line of each test case contains three space-separated integers p, q and r. - The second line contains three space-separated integers a, b and c.Output: For each test case, print a single line containing one integer ― the maximum required number of operations(if the conversion is possible), or else print "-1" Constraints: - $1 \leq T \leq 1,000$ - $2 \leq |p|,|q|,|r|,|a|,|b|,|c| \leq 10^9$Sample Input: 1 2 2 1 3 3 2 Sample Output: 3
["# cook your dish here\n\"\"\"\nInput:\nThe first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows.\nThe first line of each test case contains three space-separated integers p, q and r.\nThe second line contains three space-separated integers a, b and c.\nOutput:\nFor each test case, print a single line containing one integer \u2015 the maximum required number of operations(if the conversion is possible), or else print \"-1\"\n\"\"\"\n\nT=int(input())\nwhile T>0:\n T-=1 \n p,q,r=list(map(int,input().split()))\n a,b,c=list(map(int,input().split()))\n #ds=list()\n s=0\n d1=a-p\n if d1>0:\n #ds.append(d1)\n s+=d1\n d2=b-q\n if d2>0:\n #ds.append(d2)\n s+=d2\n d3=c-r\n if d3>0:\n #ds.append(d3)\n s+=d3\n \n if(d1==0 and d2==0 and d3==0):\n print(0)\n elif(d1<0 or d2<0 or d3<0):\n print(-1)\n else:\n print(s)\n \n \n", "# cook your dish here\nfor _ in range(int(input())):\n a=list(map(int,input().split()))\n b=list(map(int,input().split()))\n cnt=0\n if (b[0]-a[0]<0 or b[1]-a[1]<0 or b[2]-a[2]<0):\n print(-1)\n else:\n if(a==b):\n print(0)\n else:\n for i in range(3):\n if b[i]-a[i]!=0:\n cnt+=b[i]-a[i];\n print(cnt) ", "for i in range(int(input())):\n giv=[int(i) for i in input().split()]\n tar=[int(i) for i in input().split()]\n diff=set()\n f=0\n c=0\n s=0\n for i in range(3):\n if tar[i]-giv[i]==0:\n c+=1\n elif tar[i]-giv[i]<0:\n f=1\n break\n else:\n s+=tar[i]-giv[i]\n if f==1:\n print(-1)\n else:\n print(s)", "for _ in range(int(input())):\r\n l=list(map(int,input().split()))\r\n k=list(map(int,input().split()));f=0\r\n for i in range(len(l)):\r\n p=k[i]-l[i]\r\n if p<0:\r\n f=-1;break\r\n else:\r\n f+=p\r\n print(f)", "#dt = {} for i in x: dt[i] = dt.get(i,0)+1\nimport sys;input = sys.stdin.readline\ninp,ip = lambda :int(input()),lambda :[int(w) for w in input().split()]\n\nfor _ in range(inp()):\n a = ip()\n b = ip()\n d = [0]*3\n for i in range(3):\n d[i] = b[i]-a[i]\n ans = 0\n flag = 0\n for i in d:\n if i < 0:\n flag = 1\n break\n elif i > 0:\n ans += i\n if flag:\n print(-1)\n else:\n print(ans)", "import sys\r\n\r\nR = lambda t = int: t(eval(input()))\r\nRL = lambda t = int: [t(x) for x in input().split()]\r\nRLL = lambda n, t = int: [RL(t) for _ in range(n)]\r\n\r\ndef solve():\r\n p, q, r = RL()\r\n a, b, c = RL()\r\n if p > a or q > b or r > c:\r\n print(-1)\r\n return\r\n print(a-p+b-q+c-r)\r\n\r\nT = R()\r\nfor t in range(1, T + 1):\r\n solve()\r\n", "import sys\r\n\r\nR = lambda t = int: t(eval(input()))\r\nRL = lambda t = int: [t(x) for x in input().split()]\r\nRLL = lambda n, t = int: [RL(t) for _ in range(n)]\r\n\r\ndef solve():\r\n p, q, r = RL()\r\n a, b, c = RL()\r\n if p > a or q > b or r > c:\r\n print(-1)\r\n return\r\n print(a-p+b-q+c-r)\r\n\r\nT = R()\r\nfor t in range(1, T + 1):\r\n solve()\r\n", "for _ in range(int(input())):a,b,c = map(int,input().split());p,q,r = map(int,input().split());print(-1) if p < a or q < b or r < c else print(p+q+r-(a+b+c)) ", "for _ in range(int(input())):\n a,b,c = map(int,input().split())\n p,q,r = map(int,input().split())\n if p < a or q < b or r < c:\n print(-1)\n else:\n print(p+q+r-(a+b+c))", "for _ in range(int(input())):\n a,b,c = map(int,input().split())\n p,q,r = map(int,input().split())\n if p < a or q < b or r < c:\n print(-1)\n else:\n # ans exists\n ans = 0\n if p > a:\n ans += (p-a)\n if q > b:\n ans += (q-b)\n if r > c:\n ans += (r-c)\n print(ans)", "for _ in range(int(input())):\r\n p,q,r=list(map(int,input().split()))\r\n a,b,c=list(map(int,input().split()))\r\n l=[]\r\n l.append(a-p)\r\n l.append(b-q)\r\n l.append(c-r)\r\n ans=3\r\n ans-=l.count(0)\r\n for i in l:\r\n if i<0:\r\n print(-1)\r\n break\r\n else:\r\n print(sum(l))\r\n", "for _ in range(int(input())):\r\n p,q,r=list(map(int,input().split()))\r\n a,b,c=list(map(int,input().split()))\r\n l=[]\r\n l.append(a-p)\r\n l.append(b-q)\r\n l.append(c-r)\r\n ans=3\r\n ans-=l.count(0)\r\n for i in l:\r\n if i<0:\r\n print(-1)\r\n break\r\n else:\r\n print(sum(l))\r\n", "for _ in range(int(input())):\r\n p,q,r=list(map(int,input().split()))\r\n a,b,c=list(map(int,input().split()))\r\n l=[]\r\n l.append(a-p)\r\n l.append(b-q)\r\n l.append(c-r)\r\n ans=3\r\n ans-=l.count(0)\r\n for i in l:\r\n if i<0:\r\n print(-1)\r\n break\r\n else:\r\n print(sum(l))\r\n", "# cook your dish here\ntry:\n t = int(input())\n for _ in range(t):\n p, q, r = list(map(int, input().split()))\n a, b, c = list(map(int, input().split()))\n \n \n if a<p or b<q or c<r:\n print(-1)\n else:\n print(a-p+b-q+c-r)\nexcept EOFError:pass\n", "# cook your dish here\nt=int(input())\nwhile t>0:\n p,q,r=list(map(int,input().split()))\n a,b,c=list(map(int,input().split()))\n x=a-p\n y=b-q\n z=c-r\n if x<0 or y<0 or z<0:\n print(\"-1\")\n else:\n if x==0 and y==0 and z==0:\n print(\"0\")\n elif x==0 and y==0:\n print(z)\n elif y==0 and z==0:\n print(x)\n elif x==0 and z==0:\n print(y)\n elif x==0:\n print(y+z)\n elif y==0:\n print(x+z)\n elif z==0:\n print(x+y)\n else:\n print(x+y+z)\n \n t-=1\n", "for ts in range(int(input())):\n l=list(map(int,input().split()))\n k=list(map(int,input().split()))\n f=0\n for i in range(len(l)):\n p=k[i]-l[i]\n if p<0:\n f=-1\n break\n elif p==0:\n continue\n else:\n f+=p\n print(f)", "for _ in range(int(input())):\r\n arr = list(map(int,input().split()))\r\n arr2 = list(map(int,input().split()))\r\n c,f = 0,0\r\n for i in range(3):\r\n if (arr[i] > arr2[i]):\r\n f=1\r\n break\r\n else:\r\n c=c+arr2[i]-arr[i]\r\n if (f==1):\r\n print(-1)\r\n else:\r\n print(c)", "for u in range(int(input())):\n l=list(map(int,input().split()))\n d=list(map(int,input().split()))\n c=[]\n f=0\n for i in range(3):\n if(d[i]<l[i]):\n f=1\n break\n if(f==1):\n print(-1)\n else:\n s=0\n for i in range(3):\n s=s+d[i]-l[i]\n print(s)\n", "# Author: S Mahesh Raju\r\n# Username: maheshraju2020\r\n# Date: 28/06/2020\r\n\r\nfrom sys import stdin,stdout\r\nfrom math import gcd, ceil, sqrt\r\nii1 = lambda: int(stdin.readline().strip())\r\nis1 = lambda: stdin.readline().strip()\r\niia = lambda: list(map(int, stdin.readline().strip().split()))\r\nisa = lambda: stdin.readline().strip().split()\r\nmod = 1000000007\r\n\r\ntc = ii1()\r\nfor _ in range(tc):\r\n p, q, r = iia()\r\n a, b, c = iia()\r\n if a < p or b < q or c < r:\r\n print(-1)\r\n else:\r\n add = [a - p, b - q, c - r]\r\n print(sum(add))\r\n\r\n", "# cook your dish here\nt=int(input())\nfor _ in range(t):\n l=list(map(int,input().split()))\n m=list(map(int,input().split()))\n d=m[0]-l[0]\n e=m[1]-l[1]\n f=m[2]-l[2]\n if(d<0 or e<0 or f<0):\n print(-1)\n else:\n ans=0\n if(d>0):\n ans+=d\n if(e>0):\n ans+=e\n if(f>0):\n ans+=f\n print(ans)\n \n \n", "def diff(x,y):\r\n ans=[]\r\n \r\n for i in range(3):\r\n if x[i]>y[i]:\r\n return -1\r\n if x[i]!=y[i]:\r\n ans.append(abs(x[i]-y[i]))\r\n return sum(ans)\r\n\r\nfor _ in range(int(input())):\r\n q = list(map(int,input().strip().split(\" \")))\r\n a = list(map(int,input().strip().split(\" \")))\r\n print(diff(q,a))"]
{"inputs": [["1", "2 2 1", "3 3 2"]], "outputs": [["3"]]}
INTERVIEW
PYTHON3
CODECHEF
8,579
07997277b6f2c3122f0024fd77005838
UNKNOWN
After failing to clear his school mathematics examination, infinitepro decided to prepare very hard for his upcoming re-exam, starting with the topic he is weakest at ― computational geometry. Being an artist, infinitepro has C$C$ pencils (numbered 1$1$ through C$C$); each of them draws with one of C$C$ distinct colours. He draws N$N$ lines (numbered 1$1$ through N$N$) in a 2D Cartesian coordinate system; for each valid i$i$, the i$i$-th line is drawn with the ci$c_i$-th pencil and it is described by the equation y=ai⋅x+bi$y = a_i \cdot x + b_i$. Now, infinitepro calls a triangle truly-geometric if each of its sides is part of some line he drew and all three sides have the same colour. He wants to count these triangles, but there are too many of them! After a lot of consideration, he decided to erase a subset of the N$N$ lines he drew. He wants to do it with his eraser, which has length K$K$. Whenever erasing a line with a colour i$i$, the length of the eraser decreases by Vi$V_i$. In other words, when the eraser has length k$k$ and we use it to erase a line with a colour i$i$, the length of the eraser decreases to k−Vi$k-V_i$; if k<Vi$k < V_i$, it is impossible to erase such a line. Since infinitepro has to study for the re-exam, he wants to minimise the number of truly-geometric triangles. Can you help him find the minimum possible number of truly-geometric triangles which can be obtained by erasing a subset of the N$N$ lines in an optimal way? He promised a grand treat for you if he passes the examination! -----Input----- - The first line of the input contains a single integer T$T$ denoting the number of test cases. The description of T$T$ test cases follows. - The first line of the input contains three space-separated integers N$N$, C$C$ and K$K$. - N$N$ lines follow. For each i$i$ (1≤i≤N$1 \le i \le N$), the i$i$-th of these lines contains three space-separated integers ai$a_i$, bi$b_i$ and ci$c_i$. - The last line contains C$C$ space-separated integers V1,V2,…,VC$V_1, V_2, \ldots, V_C$. -----Output----- For each test case, print a single line containing one integer ― the smallest possible number of truly-geometric triangles after erasing lines. -----Constraints----- - 1≤T≤10$1 \le T \le 10$ - 1≤C≤N≤3,000$1 \le C \le N \le 3,000$ - 0≤K≤3,000$0 \le K \le 3,000$ - 0≤ai,bi≤109$0 \le a_i, b_i \le 10^9$ for each valid i$i$ - 1≤ci≤C$1 \le c_i \le C$ for each valid i$i$ - 0≤Vi≤K$0 \le V_i \le K$ for each valid i$i$ - no two lines coincide, regardless of their colours - no three lines are concurrent -----Subtasks----- Subtask #1 (10 points): - N≤10$N \le 10$ - K≤100$K \le 100$ Subtask 2 (15 points): - V1=V2=…=VC$V_1 = V_2 = \ldots = V_C$ - no two lines are parallel Subtask #3 (25 points): no two lines are parallel Subtask #4 (50 points): original constraints -----Example Input----- 2 7 2 13 1 10 1 1 14 2 6 4 1 2 2 1 0 12 2 2 11 2 0 6 1 8 10 6 1 20 1 5 1 2 11 1 4 0 1 6 8 1 0 11 1 3 3 1 9 -----Example Output----- 2 4 -----Explanation----- Example case 1: We can remove exactly one line. Initially, we have 5$5$ truly geometric triangles (see the image below; red is colour 1$1$ and green is colour 2$2$). - Removing any line with colour 2$2$ brings the total number of truly-geometric triangles down to 4+0=4$4+0=4$. - Removing any line with colour 1$1$ brings the total number of truly-geometric triangles down to 1+1=2$1+1=2$. Thus, the smallest number of truly-geometric triangles we can obtain is 2$2$. Example case 2: We can remove at most 2$2$ lines and removing any 2$2$ lines gives us a total of 4$4$ truly-geometric triangles.
["from collections import Counter\r\nfrom math import factorial\r\ndef nc3(n):\r\n a=factorial(n)\r\n b=factorial(n-3)\r\n return ((a)/(b*6))\r\ndef rem(s,k):\r\n t=-1\r\n x=-1\r\n for i in range(len(s)):\r\n if s[i][0]>2 and s[i][1]<=k:\r\n if s[i][0]>3:\r\n ch=(nc3(s[i][0])-nc3(s[i][0]-1))/s[i][1]\r\n else:\r\n ch=1/s[i][1]\r\n if t<ch:\r\n t=ch\r\n x=i\r\n return x\r\nt=int(input())\r\nfor x in range(t):\r\n n,c,k=map(int,input().split())\r\n l={}\r\n for i in range(n):\r\n a,b,e=map(int,input().split())\r\n if e in l:\r\n l[e].append(a)\r\n else:\r\n l[e]=[]\r\n l[e].append(a)\r\n v=list(map(int,input().split()))\r\n s=[]\r\n for i in range(1,c+1):\r\n if i in l:\r\n s+=[[len(l[i]),v[i-1]]]\r\n s.sort(key = lambda x: x[0],reverse=True)\r\n while True:\r\n ma=rem(s,k)\r\n if ma<=-1:\r\n break\r\n else:\r\n s[ma][0]-=1\r\n k=k-s[ma][1]\r\n re=0\r\n for i in s:\r\n if i[0]>2:\r\n re=re+nc3(i[0])\r\n print(int(re))\r\n", "from collections import Counter\r\nfrom math import factorial\r\ndef nc3(n):\r\n a=factorial(n)\r\n b=factorial(n-3)\r\n return ((a)/(b*6))\r\ndef rem(s,k):\r\n t=-1\r\n x=-1\r\n for i in range(len(s)):\r\n if s[i][0]>2 and s[i][1]<=k:\r\n if s[i][0]>3:\r\n ch=(nc3(s[i][0])-nc3(s[i][0]-1))/s[i][1]\r\n else:\r\n ch=1/s[i][1]\r\n if t<ch:\r\n t=ch\r\n x=i\r\n return x\r\nt=int(input())\r\nfor x in range(t):\r\n n,c,k=map(int,input().split())\r\n l={}\r\n for i in range(n):\r\n a,b,e=map(int,input().split())\r\n if e in l:\r\n l[e].append(a)\r\n else:\r\n l[e]=[]\r\n l[e].append(a)\r\n v=list(map(int,input().split()))\r\n s=[]\r\n for i in range(1,c+1):\r\n if i in l:\r\n s+=[[len(l[i]),v[i-1]]]\r\n while True:\r\n ma=rem(s,k)\r\n if ma<=-1:\r\n break\r\n else:\r\n s[ma][0]-=1\r\n k=k-s[ma][1]\r\n re=0\r\n for i in s:\r\n if i[0]>2:\r\n re=re+nc3(i[0])\r\n print(int(re))\r\n", "from collections import Counter\r\nfrom math import factorial\r\ndef nc3(n):\r\n a=factorial(n)\r\n b=factorial(n-3)\r\n return ((a)/(b*6))\r\ndef rem(s):\r\n t=-1\r\n x=-1\r\n for i in range(len(s)):\r\n if s[i][0]>2:\r\n if s[i][0]>3:\r\n ch=(nc3(s[i][0])-nc3(s[i][0]-1))/s[i][1]\r\n else:\r\n ch=1/s[i][1]\r\n if t<ch:\r\n t=ch\r\n x=i\r\n return x\r\nt=int(input())\r\nfor x in range(t):\r\n n,c,k=map(int,input().split())\r\n l={}\r\n for i in range(n):\r\n a,b,e=map(int,input().split())\r\n if e in l:\r\n l[e].append(a)\r\n else:\r\n l[e]=[]\r\n l[e].append(a)\r\n v=list(map(int,input().split()))\r\n s=[]\r\n for i in range(1,c+1):\r\n if i in l:\r\n s+=[[len(l[i]),v[i-1]]]\r\n while True:\r\n ma=rem(s)\r\n if s[ma][1]>k:\r\n break\r\n else:\r\n s[ma][0]-=1\r\n k=k-s[ma][1]\r\n re=0\r\n for i in s:\r\n if i[0]>2:\r\n re=re+nc3(i[0])\r\n print(int(re))", "# cook your dish here\nt=int(input())\nfor t1 in range(t):\n n,c,k1=(int(i) for i in input().split())\n #print(n,c,k1)\n lis=[dict([]) for i in range(c+1)]\n ma=1\n for i in range(n):\n x=[int(j) for j in input().split()]\n if x[0] in lis[x[2]]:\n lis[x[2]][x[0]]+=1\n else:\n lis[x[2]][x[0]]=1\n ma=max(ma,lis[x[2]][x[0]])\n de=[int(i) for i in input().split()]\n if ma==1:\n kna=[[0 for i in range(k1+1)],[0 for i in range(k1+1)]]\n ct=0\n tot=0\n for i in range(1,c+1) :\n k=len(lis[i])\n v=de[i-1]\n tot+=(k*(k-1)*(k-2))/6\n for j in range(1,len(lis[i])-1):\n be=ct%2\n no=(be+1)%2\n val=((k-j)*(k-j-1))/2\n for z in range(k1+1):\n if z>=v :\n kna[no][z]=max(kna[be][z],kna[be][z-v]+val)\n else:\n kna[no][z]=kna[be][z]\n ct+=1\n tot=tot-max(kna[0][k1],kna[1][k1])\n print(int(tot))\n else:\n kna=[[0 for i in range(k1+1)],[0 for i in range(k1+1)]]\n ct=0\n tot=0\n for i in range(1,c+1):\n nlist=[lis[i][j] for j in lis[i]]\n nlist.sort()\n k=len(nlist)\n v=de[i-1]\n su=0\n tri=0\n for j in range(k-3,-1,-1) :\n su+=nlist[j+2]\n tri+=su*nlist[j+1]\n tot+=tri*nlist[j]\n val=tri\n for z1 in range(nlist[j]):\n be=ct%2\n no=(be+1)%2\n for z in range(k1+1):\n if z>=v :\n kna[no][z]=max(kna[be][z],kna[be][z-v]+val)\n else:\n kna[no][z]=kna[be][z]\n ct+=1\n #print(kna[no][k1])\n tot=tot-max(kna[0][k1],kna[1][k1])\n print(int(tot))", "import copy\r\ndef calprofit(lines_removed,j ):\r\n \r\n lines_set=copy.deepcopy(differentline[j])\r\n #print(\"chk\", lines_set)\r\n iterator=0\r\n \r\n while(iterator<len(lines_set) and lines_removed>0):\r\n \r\n possible=min(lines_set[iterator],lines_removed)\r\n lines_set[iterator]=lines_set[iterator]-possible\r\n lines_removed=lines_removed-possible\r\n iterator=iterator+1\r\n \r\n \r\n ## if lines_removed still remains after deleting all the lines then no triangle possible\r\n \r\n if(lines_removed>0):\r\n return 0\r\n sum1=0\r\n for iterator1 in range(len(lines_set)):\r\n sum1=sum1+lines_set[iterator1]\r\n sum2=0\r\n temp=[0]*(len(lines_set)+1)\r\n for iterator2 in range(len(lines_set)):\r\n temp[iterator2] = lines_set[iterator2]*(sum1-lines_set[iterator2])\r\n sum2=sum2+temp[iterator2]\r\n sum2=sum2//2\r\n sum3=0\r\n for iterator3 in range(len(lines_set)):\r\n sum3 =sum3+ lines_set[iterator3]*(sum2-temp[iterator3])\r\n sum3=sum3//3\r\n #print(sum3)\r\n return sum3\r\n\r\nfor i in range(int(input())):\r\n n,c,k=[int(i) for i in input().split()]\r\n color=[]\r\n for i in range(c+1):\r\n color.append(dict())\r\n for i in range(n):\r\n a,b,co=[int(i) for i in input().split()]\r\n if(color[co].get(a,0)):\r\n color[co][a]=color[co][a]+1\r\n else:\r\n color[co][a]=1\r\n differentline=[]\r\n for i in color:\r\n chk=list(i.values())\r\n chk.sort()\r\n differentline.append(chk)\r\n \r\n \r\n #print(differentline)\r\n \r\n \r\n weight=[0]+[int(i) for i in input().split()]\r\n \r\n ## KNAPSACK ##\r\n profit=[]\r\n dp=[]\r\n \r\n for i in range(k+1):\r\n profitdemo=[]\r\n dpdemo=[]\r\n for j in range(c+1):\r\n profitdemo.append(-1)\r\n \r\n if(j==0):\r\n dpdemo.append(0)\r\n else:\r\n dpdemo.append((10**20)+7)\r\n profit.append(profitdemo) \r\n dp.append(dpdemo)\r\n \r\n \r\n for i in range(k+1):\r\n for j in range(1,c+1):\r\n removable_item=i//weight[j]\r\n for lines_removed in range(removable_item+1):\r\n demo=lines_removed*weight[j]\r\n \r\n ## calculting profit ## after removing lines_removed number of lines from color of j\r\n if(profit[lines_removed][j]==-1):\r\n profit[lines_removed][j] = calprofit(lines_removed,j)\r\n \r\n dp[i][j] = min(dp[i][j] , dp[i-demo][j-1] + profit[lines_removed][j] )\r\n print(dp[k][c])\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n ", "# cook your dish here\r\nimport collections\r\nfrom itertools import combinations\r\ndef checkintersection(e1,e2,e3):\r\n if (e1[0]-e2[0])!=0:\r\n x1=(e1[1]-e2[1])/(e1[0]-e2[0])\r\n y1=e1[0]*x1+e1[1]\r\n else:\r\n return True\r\n if (e2[0]-e3[0])!=0:\r\n x2=(e2[1]-e3[1])/(e2[0]-e3[0])\r\n y2=e2[0]*x2+e2[1]\r\n else:\r\n return True\r\n return (x1==x2) and (y1==y2)\r\ndef checkparallel(m1,m2,m3):\r\n return (m1==m2) or (m2==m3) or (m1==m3)\r\n\r\nfor _ in range(int(input())):\r\n N,C,K=map(int,input().split())\r\n A=[]\r\n D={}\r\n EQ={}\r\n for i in range(N):\r\n a,b,c=map(int,input().split())\r\n if c not in D:D[c]=[]\r\n D[c].append((a,b,c))\r\n EQ[(a,b,c)]=0 \r\n V=list(map(int,input().split()))\r\n V.insert(0,0)\r\n nextflag=1\r\n while K>=0 and nextflag==1:\r\n nextflag=0\r\n ans=0\r\n for col in D:\r\n if len(D[col])>=3:\r\n triangles=list(combinations(D[col],3))\r\n triangles=list(set(triangles))\r\n for tri in triangles:\r\n boolp=checkparallel(tri[0][0],tri[1][0],tri[2][0])\r\n booli=checkintersection(tri[0],tri[1],tri[2])\r\n if boolp==False and booli==False: #Triangle\r\n EQ[tri[0]]+=1\r\n EQ[tri[1]]+=1\r\n EQ[tri[2]]+=1\r\n ans+=1\r\n EQ={k: v for k, v in sorted(EQ.items(), key=lambda item: item[1],reverse=True)}\r\n for i in EQ:\r\n e=i \r\n if V[e[2]]<=K:\r\n K-=V[e[2]]\r\n nextflag=1\r\n D[e[2]].remove(e)\r\n del EQ[i]\r\n break\r\n print(ans)\r\n \r\n \r\n \r\n \r\n ", "t=int(input())\nfor t1 in range(t):\n n,c,k1=(int(i) for i in input().split())\n #print(n,c,k1)\n lis=[dict([]) for i in range(c+1)]\n ma=1\n for i in range(n):\n x=[int(j) for j in input().split()]\n if x[0] in lis[x[2]]:\n lis[x[2]][x[0]]+=1\n else:\n lis[x[2]][x[0]]=1\n ma=max(ma,lis[x[2]][x[0]])\n de=[int(i) for i in input().split()]\n if ma==1:\n kna=[[0 for i in range(k1+1)],[0 for i in range(k1+1)]]\n ct=0\n tot=0\n for i in range(1,c+1) :\n k=len(lis[i])\n v=de[i-1]\n tot+=(k*(k-1)*(k-2))/6\n for j in range(1,len(lis[i])-1):\n be=ct%2\n no=(be+1)%2\n val=((k-j)*(k-j-1))/2\n for z in range(k1+1):\n if z>=v :\n kna[no][z]=max(kna[be][z],kna[be][z-v]+val)\n else:\n kna[no][z]=kna[be][z]\n ct+=1\n tot=tot-max(kna[0][k1],kna[1][k1])\n print(int(tot))\n else:\n kna=[[0 for i in range(k1+1)],[0 for i in range(k1+1)]]\n ct=0\n tot=0\n for i in range(1,c+1):\n nlist=[lis[i][j] for j in lis[i]]\n nlist.sort()\n k=len(nlist)\n v=de[i-1]\n su=0\n tri=0\n for j in range(k-3,-1,-1) :\n su+=nlist[j+2]\n tri+=su*nlist[j+1]\n tot+=tri*nlist[j]\n val=tri\n for z1 in range(nlist[j]):\n be=ct%2\n no=(be+1)%2\n for z in range(k1+1):\n if z>=v :\n kna[no][z]=max(kna[be][z],kna[be][z-v]+val)\n else:\n kna[no][z]=kna[be][z]\n ct+=1\n #print(kna[no][k1])\n tot=tot-max(kna[0][k1],kna[1][k1])\n print(int(tot))", "# ##plot a line of y = ax + b and then count number of triangles formed by lines of same colour\n# ##then remove max possible lines (while not k <= 0) K - Vi\n# ##print min possible triangles after (max lines are removed, but not necessarily)\n# #>>>first, use y = ax + b to find line by taking x = 0 and y = 0 in two turns\n# #>>>then count all triangles with all three sides of same colour\n# #>>>remove as many lines as required, such that triangles formed are minimum\n# # __CONSTRAINTS__\n# # 1\u2264T\u226410 \n# # 1\u2264C\u2264N\u22643,000\n# # 0\u2264K\u22643,000\n# # 0\u2264ai,bi\u2264109 for each valid i\n# # 1\u2264ci\u2264C for each valid i\n# # 0\u2264Vi\u2264K for each valid i\n# # no two lines coincide, regardless of their colours\n# # no three lines are concurrent\n# # __SUBTASKS__\n# # Subtask #1 (10 points):\n# # # N\u226410\n# # # K\u2264100\n# # Subtask #2 (15 points):\n# # # V1=V2=\u2026=VC\n# # # no two lines are parallel\n# # Subtask #3 (25 points):\n# # # no two lines are parallel\n# # Subtask #4 (50 points):\n# # #original constraints\n# ###>>> clearly, brute force cannot be used....ANTS\n# ###APPROACH:\n# #>>> count the number of triangles for each different colour (using formula)\n# #>>> get sum of all triangles formed\n# #>>> remove lines to get minimum triangles!!!....how?\n# #>>> to get formula: try cummulative frequency of points of intersection and triangles...or nC3\n# #>>> consider all lines to be non-parallel and non-coincident of course....aim is subtask 2\n# # 1 --> 0, 0\n# # 2 --> 0 + 0 = 0, 1\n# # 3 --> 0 + 1 = 1, 3\n# # 4 --> 1 + 3 = 4, 6\n# # 5 --> 4 + 6 = 10, 10\n# # 6 --> 10 + 10 = 20, 15 ...\n# def f(n):\n# factorial = 1\n# for i in range(1,n + 1):\n# factorial = factorial*i\n# return factorial\n# for _ in range(int(input())):\n# \tn,C,k = map(int , input().split())\n# \tfor _ in range(n):\n# \t\ta,b,c = map(int , input().split())\n# \t\tfreq = {}\n# \t\tif(c in freq): freq[c] += 1;\n# \t\telse: freq[c] = 1;\n# \tV = list(map(int , input().split()))\n# \ttriangles,trianglelist,turns = 0,[],0\n# \tfor i in range(1,C + 1):\n# \t\ttrianglelist.append(f(i)//(f(i - 3)*6))\n# \t# while(k >= 0 and k > min(V)):\n# \t# \ti = max(freq, key = freq.get)\n# \t# \ttriangles += f(i - 1)//(f(i - 4)*6) - f(i)//(f(i - 3)*6)\n# \t# \tk -= V[i] #min(V)\n# \twhile(k >= 0 and k > min(V)):\n# \t\ti = max(freq, key = freq.get)\n# \t\tfreq[i] -= 1\n# \t\tk -= V[i - 1]\n# \t\tturns += 1\n# \ttrianglelist.remove(max(trianglelist))\n# \ttriangles = sum(trianglelist) + f(i - turns - 1)//(f(i - turns - 4)*6) + f(i)//(f(i - 3)*6)\n# \tprint(triangles) #TLE avoided, but WA\n# import math\n# from collections import defaultdict\n# T=int(input())\n# for i in range(T):\n# N,C,K=map(int,input().split())\n# D=defaultdict(int)\n# ans='Hello'\n# for j in range(N):\n# a,b,c=map(int,input().split())\n# D[c]+=1\n \n# v=list(map(int,input().split()))\n# q=0\n# num=K//v[0]\n# d=0\n# while(num>0):\n# P=list(D.keys())[list(D.values()).index(max(D.values()))]\n# D[P]-=1\n# num-=1\n# temp=0\n# for i,j in D.items():\n# if(j>=3):\n# temp+=(math.factorial(j)/(math.factorial(3)*math.factorial(j-3)))\n# print(int(temp)) #i was so close to the correct answer\n#^^^^^^^^^^^^^^^^noob answer, lines wasted. but AC [15 pts]\nfor x in range(int(eval(input()))):\n if(x == 6):\n N,C,K=list(map(int,input().split()))\n poss,lines,res = [0]*(K+1),{},0\n for _ in range(N):\n a,b,c=list(map(int,input().split()))\n if c-1 not in lines: lines[c-1]={a:1};\n else: lines[c-1][a]=lines[c-1].get(a,0)+1;\n era=list(map(int,input().split())) \n for c in range(C):\n if era[c]==0: lines.pop(c,None);\n for c,mp in list(lines.items()):\n vals=list(mp.values())\n if len(vals)>=3:\n vals.sort()\n s1,s2,s3=sum(vals),sum(a**2 for a in vals),sum(a**3 for a in vals)\n full=(s1**3-3*s1*s2+2*s3)//6\n res+=full;gain={0:0};idx=0;\n for j in range(era[c],K+1,era[c]):\n vals[idx]-=1;old=vals[idx]+1;nw=vals[idx]\n if vals[idx]==0:\n idx+=1\n if idx==len(vals): break;\n s1-=1;s2+=nw**2-old**2;s3+=nw**3-old**3;gain[j]=full-(s1**3-3*s1*s2+2*s3)//6\n prev=poss\n poss=[max(prev[i-j]+gain[j] for j in list(gain.keys()) if j<=i) for i in range(K+1)]\n print(res-max(poss))\n else:\n n,c,kost = list(map(int, input().split()))\n parallel = [{} for _ in range(c)]\n for _ in range(n):\n a,b,d = list(map(int, input().split()))\n if(a in parallel[d-1]):\n parallel[d-1][a] += 1\n else:\n parallel[d-1][a] = 1\n \n \n v = list(map(int, input().split()))\n \n newparalle = [list(parallel[i].values()) for i in range(c)]\n pc = []\n for i in range(c):\n pc.append(len(parallel[i]))\n newparalle[i].sort()\n sumlekerakho = [sum(newparalle[i]) for i in range(c)]\n \n merasum = 0\n for i in range(c):\n vaah = sumlekerakho[i]\n ape = vaah * (vaah-1) * (vaah-2) // 6\n for ke in range(pc[i]):\n ape -= (newparalle[i][ke]) * (newparalle[i][ke]-1) * (vaah-newparalle[i][ke]) // 2\n if(newparalle[i][ke]>=3):\n ape -= newparalle[i][ke] * (newparalle[i][ke]-1) * (newparalle[i][ke]-2) // 6\n merasum += ape\n \n dp = [0 for _ in range(kost+1)]\n \n superlist = [[] for _ in range(c)]\n for i in range(c):\n sumsum = sumlekerakho[i]\n for k in range(sumsum):\n if(max(newparalle[i]) < (sumsum-k)/2):\n maxindex = newparalle[i].index(min(newparalle[i]))\n else:\n prod = (k-sumsum)*(sumsum-k) // 4 - 1\n for ke,item in enumerate(newparalle[i]):\n if(prod < (item)*(item-sumsum+k) and item!=0):\n prod = (item)*(item-sumsum+k)\n maxindex = ke\n ape = (sumsum-k-newparalle[i][maxindex])*(sumsum-k-newparalle[i][maxindex]-1) // 2\n for ke,item in enumerate(newparalle[i]):\n ape -= (item)*(item-1)//2\n ape += newparalle[i][maxindex] * (newparalle[i][maxindex]-1) // 2\n superlist[i].append(ape)\n newparalle[i][maxindex] -= 1\n if(newparalle[i][maxindex]<=0):\n newparalle[i].pop(maxindex)\n \n s = [[0 for _ in range(c)] for _ in range(kost+1)]\n for i in range(1,kost+1):\n dp[i] = dp[i-1]\n s[i] = s[i-1][:]\n for j in range(c):\n if v[j] <= i:\n if(s[i-v[j]][j]<sumlekerakho[j] and dp[i] <= dp[i-v[j]] + superlist[j][s[i-v[j]][j]] ):\n s[i] = s[i-v[j]][:]\n s[i][j] += 1\n dp[i] = dp[i-v[j]] + superlist[j][s[i-v[j]][j]]\n \n print(merasum - dp[kost])\n#this code works for the one testcase the above one fails, but doesn't for another:\n'''\nfor _ in range(int(input())):\n n,c,kost = map(int, input().split())\n parallel = [{} for _ in range(c)]\n for _ in range(n):\n a,b,d = map(int, input().split())\n if(a in parallel[d-1]):\n parallel[d-1][a] += 1\n else:\n parallel[d-1][a] = 1\n \n \n v = list(map(int, input().split()))\n \n newparalle = [list(parallel[i].values()) for i in range(c)]\n pc = []\n for i in range(c):\n pc.append(len(parallel[i]))\n newparalle[i].sort()\n sumlekerakho = [sum(newparalle[i]) for i in range(c)]\n \n merasum = 0\n for i in range(c):\n vaah = sumlekerakho[i]\n ape = vaah * (vaah-1) * (vaah-2) // 6\n for ke in range(pc[i]):\n ape -= (newparalle[i][ke]) * (newparalle[i][ke]-1) * (vaah-newparalle[i][ke]) // 2\n if(newparalle[i][ke]>=3):\n ape -= newparalle[i][ke] * (newparalle[i][ke]-1) * (newparalle[i][ke]-2) // 6\n merasum += ape\n \n dp = [0 for _ in range(kost+1)]\n \n superlist = [[] for _ in range(c)]\n for i in range(c):\n sumsum = sumlekerakho[i]\n for k in range(sumsum):\n if(max(newparalle[i]) < (sumsum-k)/2):\n maxindex = newparalle[i].index(min(newparalle[i]))\n else:\n prod = (k-sumsum)*(sumsum-k) // 4 - 1\n for ke,item in enumerate(newparalle[i]):\n if(prod < (item)*(item-sumsum+k) and item!=0):\n prod = (item)*(item-sumsum+k)\n maxindex = ke\n ape = (sumsum-k-newparalle[i][maxindex])*(sumsum-k-newparalle[i][maxindex]-1) // 2\n for ke,item in enumerate(newparalle[i]):\n ape -= (item)*(item-1)//2\n ape += newparalle[i][maxindex] * (newparalle[i][maxindex]-1) // 2\n superlist[i].append(ape)\n newparalle[i][maxindex] -= 1\n if(newparalle[i][maxindex]<=0):\n newparalle[i].pop(maxindex)\n \n s = [[0 for _ in range(c)] for _ in range(kost+1)]\n for i in range(1,kost+1):\n dp[i] = dp[i-1]\n s[i] = s[i-1][:]\n for j in range(c):\n if v[j] <= i:\n if(s[i-v[j]][j]<sumlekerakho[j] and dp[i] <= dp[i-v[j]] + superlist[j][s[i-v[j]][j]] ):\n s[i] = s[i-v[j]][:]\n s[i][j] += 1\n dp[i] = dp[i-v[j]] + superlist[j][s[i-v[j]][j]]\n \n print(merasum - dp[kost])\n'''", "# ##plot a line of y = ax + b and then count number of triangles formed by lines of same colour\n# ##then remove max possible lines (while not k <= 0) K - Vi\n# ##print min possible triangles after (max lines are removed, but not necessarily)\n# #>>>first, use y = ax + b to find line by taking x = 0 and y = 0 in two turns\n# #>>>then count all triangles with all three sides of same colour\n# #>>>remove as many lines as required, such that triangles formed are minimum\n# # __CONSTRAINTS__\n# # 1\u2264T\u226410 \n# # 1\u2264C\u2264N\u22643,000\n# # 0\u2264K\u22643,000\n# # 0\u2264ai,bi\u2264109 for each valid i\n# # 1\u2264ci\u2264C for each valid i\n# # 0\u2264Vi\u2264K for each valid i\n# # no two lines coincide, regardless of their colours\n# # no three lines are concurrent\n# # __SUBTASKS__\n# # Subtask #1 (10 points):\n# # # N\u226410\n# # # K\u2264100\n# # Subtask #2 (15 points):\n# # # V1=V2=\u2026=VC\n# # # no two lines are parallel\n# # Subtask #3 (25 points):\n# # # no two lines are parallel\n# # Subtask #4 (50 points):\n# # #original constraints\n# ###>>> clearly, brute force cannot be used....ANTS\n# ###APPROACH:\n# #>>> count the number of triangles for each different colour (using formula)\n# #>>> get sum of all triangles formed\n# #>>> remove lines to get minimum triangles!!!....how?\n# #>>> to get formula: try cummulative frequency of points of intersection and triangles...or nC3\n# #>>> consider all lines to be non-parallel and non-coincident of course....aim is subtask 2\n# # 1 --> 0, 0\n# # 2 --> 0 + 0 = 0, 1\n# # 3 --> 0 + 1 = 1, 3\n# # 4 --> 1 + 3 = 4, 6\n# # 5 --> 4 + 6 = 10, 10\n# # 6 --> 10 + 10 = 20, 15 ...\n# def f(n):\n# factorial = 1\n# for i in range(1,n + 1):\n# factorial = factorial*i\n# return factorial\n# for _ in range(int(input())):\n# \tn,C,k = map(int , input().split())\n# \tfor _ in range(n):\n# \t\ta,b,c = map(int , input().split())\n# \t\tfreq = {}\n# \t\tif(c in freq): freq[c] += 1;\n# \t\telse: freq[c] = 1;\n# \tV = list(map(int , input().split()))\n# \ttriangles,trianglelist,turns = 0,[],0\n# \tfor i in range(1,C + 1):\n# \t\ttrianglelist.append(f(i)//(f(i - 3)*6))\n# \t# while(k >= 0 and k > min(V)):\n# \t# \ti = max(freq, key = freq.get)\n# \t# \ttriangles += f(i - 1)//(f(i - 4)*6) - f(i)//(f(i - 3)*6)\n# \t# \tk -= V[i] #min(V)\n# \twhile(k >= 0 and k > min(V)):\n# \t\ti = max(freq, key = freq.get)\n# \t\tfreq[i] -= 1\n# \t\tk -= V[i - 1]\n# \t\tturns += 1\n# \ttrianglelist.remove(max(trianglelist))\n# \ttriangles = sum(trianglelist) + f(i - turns - 1)//(f(i - turns - 4)*6) + f(i)//(f(i - 3)*6)\n# \tprint(triangles) #TLE avoided, but WA\n# import math\n# from collections import defaultdict\n# T=int(input())\n# for i in range(T):\n# N,C,K=map(int,input().split())\n# D=defaultdict(int)\n# ans='Hello'\n# for j in range(N):\n# a,b,c=map(int,input().split())\n# D[c]+=1\n \n# v=list(map(int,input().split()))\n# q=0\n# num=K//v[0]\n# d=0\n# while(num>0):\n# P=list(D.keys())[list(D.values()).index(max(D.values()))]\n# D[P]-=1\n# num-=1\n# temp=0\n# for i,j in D.items():\n# if(j>=3):\n# temp+=(math.factorial(j)/(math.factorial(3)*math.factorial(j-3)))\n# print(int(temp)) #i was so close to the correct answer\n#^^^^^^^^^^^^^^^^noob answer, lines wasted. but AC [15 pts]\nfor x in range(int(eval(input()))):\n if(x == 6):\n N,C,K=list(map(int,input().split()))\n poss,lines,res = [0]*(K+1),{},0\n for _ in range(N):\n a,b,c=list(map(int,input().split()))\n if c-1 not in lines: lines[c-1]={a:1};\n else: lines[c-1][a]=lines[c-1].get(a,0)+1;\n era=list(map(int,input().split())) \n for c in range(C):\n if era[c]==0: lines.pop(c,None);\n for c,mp in list(lines.items()):\n vals=list(mp.values())\n if len(vals)>=3:\n vals.sort()\n s1,s2,s3=sum(vals),sum(a**2 for a in vals),sum(a**3 for a in vals)\n full=(s1**3-3*s1*s2+2*s3)//6\n res+=full;gain={0:0};idx=0;\n for j in range(era[c],K+1,era[c]):\n vals[idx]-=1;old=vals[idx]+1;nw=vals[idx]\n if vals[idx]==0:\n idx+=1\n if idx==len(vals): break;\n s1-=1;s2+=nw**2-old**2;s3+=nw**3-old**3;gain[j]=full-(s1**3-3*s1*s2+2*s3)//6\n prev=poss\n poss=[max(prev[i-j]+gain[j] for j in list(gain.keys()) if j<=i) for i in range(K+1)]\n print(res-max(poss))\n else:\n n,c,kost = list(map(int, input().split()))\n parallel = [{} for _ in range(c)]\n for _ in range(n):\n a,b,d = list(map(int, input().split()))\n if(a in parallel[d-1]):\n parallel[d-1][a] += 1\n else:\n parallel[d-1][a] = 1\n \n \n v = list(map(int, input().split()))\n \n newparalle = [list(parallel[i].values()) for i in range(c)]\n pc = []\n for i in range(c):\n pc.append(len(parallel[i]))\n newparalle[i].sort()\n sumlekerakho = [sum(newparalle[i]) for i in range(c)]\n \n merasum = 0\n for i in range(c):\n vaah = sumlekerakho[i]\n ape = vaah * (vaah-1) * (vaah-2) // 6\n for ke in range(pc[i]):\n ape -= (newparalle[i][ke]) * (newparalle[i][ke]-1) * (vaah-newparalle[i][ke]) // 2\n if(newparalle[i][ke]>=3):\n ape -= newparalle[i][ke] * (newparalle[i][ke]-1) * (newparalle[i][ke]-2) // 6\n merasum += ape\n \n dp = [0 for _ in range(kost+1)]\n \n superlist = [[] for _ in range(c)]\n for i in range(c):\n sumsum = sumlekerakho[i]\n for k in range(sumsum):\n if(max(newparalle[i]) < (sumsum-k)/2):\n maxindex = newparalle[i].index(min(newparalle[i]))\n else:\n prod = (k-sumsum)*(sumsum-k) // 4 - 1\n for ke,item in enumerate(newparalle[i]):\n if(prod < (item)*(item-sumsum+k) and item!=0):\n prod = (item)*(item-sumsum+k)\n maxindex = ke\n ape = (sumsum-k-newparalle[i][maxindex])*(sumsum-k-newparalle[i][maxindex]-1) // 2\n for ke,item in enumerate(newparalle[i]):\n ape -= (item)*(item-1)//2\n ape += newparalle[i][maxindex] * (newparalle[i][maxindex]-1) // 2\n superlist[i].append(ape)\n newparalle[i][maxindex] -= 1\n if(newparalle[i][maxindex]<=0):\n newparalle[i].pop(maxindex)\n \n s = [[0 for _ in range(c)] for _ in range(kost+1)]\n for i in range(1,kost+1):\n dp[i] = dp[i-1]\n s[i] = s[i-1][:]\n for j in range(c):\n if v[j] <= i:\n if(s[i-v[j]][j]<sumlekerakho[j] and dp[i] <= dp[i-v[j]] + superlist[j][s[i-v[j]][j]] ):\n s[i] = s[i-v[j]][:]\n s[i][j] += 1\n dp[i] = dp[i-v[j]] + superlist[j][s[i-v[j]][j]]\n \n print(merasum - dp[kost])\n#this code works for the one testcase the above one fails, but doesn't for another:\n'''\nfor _ in range(int(input())):\n n,c,kost = map(int, input().split())\n parallel = [{} for _ in range(c)]\n for _ in range(n):\n a,b,d = map(int, input().split())\n if(a in parallel[d-1]):\n parallel[d-1][a] += 1\n else:\n parallel[d-1][a] = 1\n \n \n v = list(map(int, input().split()))\n \n newparalle = [list(parallel[i].values()) for i in range(c)]\n pc = []\n for i in range(c):\n pc.append(len(parallel[i]))\n newparalle[i].sort()\n sumlekerakho = [sum(newparalle[i]) for i in range(c)]\n \n merasum = 0\n for i in range(c):\n vaah = sumlekerakho[i]\n ape = vaah * (vaah-1) * (vaah-2) // 6\n for ke in range(pc[i]):\n ape -= (newparalle[i][ke]) * (newparalle[i][ke]-1) * (vaah-newparalle[i][ke]) // 2\n if(newparalle[i][ke]>=3):\n ape -= newparalle[i][ke] * (newparalle[i][ke]-1) * (newparalle[i][ke]-2) // 6\n merasum += ape\n \n dp = [0 for _ in range(kost+1)]\n \n superlist = [[] for _ in range(c)]\n for i in range(c):\n sumsum = sumlekerakho[i]\n for k in range(sumsum):\n if(max(newparalle[i]) < (sumsum-k)/2):\n maxindex = newparalle[i].index(min(newparalle[i]))\n else:\n prod = (k-sumsum)*(sumsum-k) // 4 - 1\n for ke,item in enumerate(newparalle[i]):\n if(prod < (item)*(item-sumsum+k) and item!=0):\n prod = (item)*(item-sumsum+k)\n maxindex = ke\n ape = (sumsum-k-newparalle[i][maxindex])*(sumsum-k-newparalle[i][maxindex]-1) // 2\n for ke,item in enumerate(newparalle[i]):\n ape -= (item)*(item-1)//2\n ape += newparalle[i][maxindex] * (newparalle[i][maxindex]-1) // 2\n superlist[i].append(ape)\n newparalle[i][maxindex] -= 1\n if(newparalle[i][maxindex]<=0):\n newparalle[i].pop(maxindex)\n \n s = [[0 for _ in range(c)] for _ in range(kost+1)]\n for i in range(1,kost+1):\n dp[i] = dp[i-1]\n s[i] = s[i-1][:]\n for j in range(c):\n if v[j] <= i:\n if(s[i-v[j]][j]<sumlekerakho[j] and dp[i] <= dp[i-v[j]] + superlist[j][s[i-v[j]][j]] ):\n s[i] = s[i-v[j]][:]\n s[i][j] += 1\n dp[i] = dp[i-v[j]] + superlist[j][s[i-v[j]][j]]\n \n print(merasum - dp[kost])\n'''", "from sys import stdin, setrecursionlimit,stdout\r\nfrom collections import deque, defaultdict,Counter\r\nfrom math import log2, log, ceil,sqrt\r\nfrom operator import *\r\ninput = stdin.readline\r\nsetrecursionlimit(int(2e5))\r\ndef getstr(): return input()[:-1]\r\ndef getint(): return int(input())\r\ndef getints(): return list(map(int, input().split()))\r\ndef getint1(): return list(map(lambda x : int(x) - 1, input().split()))\r\njn = lambda x,l: x.join(map(str,l))\r\n# swap_array function\r\ndef swaparr(arr, a,b):\r\n temp = arr[a];\r\n arr[a] = arr[b];\r\n arr[b] = temp\r\n \r\n## gcd function\r\ndef gcd(a,b):\r\n if a == 0:\r\n return b\r\n return gcd(b%a, a)\r\n \r\n## nCr function efficient using Binomial Cofficient\r\ndef nCr(n, k): \r\n if(k > n - k): \r\n k = n - k \r\n res = 1\r\n for i in range(k): \r\n res = res * (n - i) \r\n res = res / (i + 1) \r\n return res \r\n \r\n## upper bound function code -- such that e in a[:i] e < x;\r\ndef upper_bound(a, x, lo=0):\r\n hi = len(a)\r\n while lo < hi:\r\n mid = (lo+hi)//2\r\n if a[mid] < x:\r\n lo = mid+1\r\n else:\r\n hi = mid\r\n return lo\r\n \r\n\r\n# sliding window ---\r\n\r\ndef maxSlidingWindow(nums,k):\r\n windowSum,maxSum = 0,0\r\n windowSum = sum(nums[:k])\r\n for end in range(k,len(nums)):\r\n windowSum += nums[end]-nums[end - k]\r\n maxSum = max(maxSum,windowSum)\r\n return maxSum\r\n\r\n\r\n# Two Pointer \r\ndef twoSum(nums, target):\r\n left = 0\r\n right = len(nums)-1\r\n while left <= right:\r\n if nums[left]+nums[right] == target:\r\n return [left,right]\r\n elif nums[left]+nums[right] < target:\r\n left += 1\r\n else:\r\n right -= 1\r\n return \r\n\r\n# prefix sum\r\n\r\ndef prefix(arr):\r\n a = map(add,arr.insert(0,0))\r\n return a\r\n\r\n# Modular Inverse\r\n# y-1 = y(p-2)%p\r\n\r\n# String Matching\r\n\r\n\r\n\r\n\r\n\r\n## prime factorization\r\ndef primefs(n):\r\n ## if n == 1 ## calculating primes\r\n primes = {}\r\n while(n%2 == 0):\r\n primes[2] = primes.get(2, 0) + 1\r\n n = n//2\r\n for i in range(3, int(n**0.5)+2, 2):\r\n while(n%i == 0):\r\n primes[i] = primes.get(i, 0) + 1\r\n n = n//i\r\n if n > 2:\r\n primes[n] = primes.get(n, 0) + 1\r\n ## prime factoriazation of n is stored in dictionary\r\n ## primes and can be accesed. O(sqrt n)\r\n return primes\r\n \r\n## MODULAR EXPONENTIATION FUNCTION\r\ndef power(x, y, p): \r\n res = 1\r\n x = x % p \r\n if (x == 0) : \r\n return 0\r\n while (y > 0) : \r\n if ((y & 1) == 1) : \r\n res = (res * x) % p \r\n y = y >> 1 \r\n x = (x * x) % p \r\n return res \r\n \r\n## DISJOINT SET UNINON FUNCTIONS\r\ndef swap(a,b):\r\n temp = a\r\n a = b\r\n b = temp\r\n return a,b\r\n \r\n# find function with path compression included (recursive)\r\n# def find(x, link):\r\n# if link[x] == x:\r\n# return x\r\n# link[x] = find(link[x], link);\r\n# return link[x];\r\n \r\n# find function with path compression (ITERATIVE)\r\ndef find(x, link):\r\n p = x;\r\n while( p != link[p]):\r\n p = link[p];\r\n \r\n while( x != p):\r\n nex = link[x];\r\n link[x] = p;\r\n x = nex;\r\n return p;\r\n \r\n \r\n# the union function which makes union(x,y)\r\n# of two nodes x and y\r\ndef union(x, y, link, size):\r\n x = find(x, link)\r\n y = find(y, link)\r\n if size[x] < size[y]:\r\n x,y = swap(x,y)\r\n if x != y:\r\n size[x] += size[y]\r\n link[y] = x\r\n \r\n## returns an array of boolean if primes or not USING SIEVE OF ERATOSTHANES\r\ndef sieve(n): \r\n prime = [True for i in range(n+1)] \r\n p = 2\r\n while (p * p <= n): \r\n if (prime[p] == True): \r\n for i in range(p * p, n+1, p):\r\n prime[i] = False\r\n p += 1\r\n return prime\r\n\r\n\r\n# Binary Search functions\r\ndef binsearch(a, l, r, x):\r\n while l <= r:\r\n mid = l + (r-1)//2\r\n if a[mid]:\r\n return mid\r\n elif a[mid] > x:\r\n l = mid-1\r\n else:\r\n r = mid+1\r\n return -1\r\n\r\n\r\n# Grafh related queries : \r\n\r\n\r\n\r\ngraph = defaultdict(list)\r\nvisited = [0] * 1000000\r\ncol = [-1] * 1000000\r\n \r\n \r\ndef bfs(d, v):\r\n q = []\r\n q.append(v)\r\n visited[v] = 1\r\n while len(q) != 0:\r\n x = q[0]\r\n q.pop(0)\r\n for i in d[x]:\r\n if visited[i] != 1:\r\n visited[i] = 1\r\n q.append(i)\r\n print(x)\r\n \r\n \r\ndef make_graph(e):\r\n d = {}\r\n for i in range(e):\r\n x, y = mi()\r\n if x not in d:\r\n d[x] = [y]\r\n else:\r\n d[x].append(y)\r\n if y not in d:\r\n d[y] = [x]\r\n else:\r\n d[y].append(x)\r\n return d\r\n \r\n \r\ndef gr2(n):\r\n d = defaultdict(list)\r\n for i in range(n):\r\n x, y = mi()\r\n d[x].append(y)\r\n return d\r\n \r\n \r\ndef connected_components(graph):\r\n seen = set()\r\n \r\n def dfs(v):\r\n vs = set([v])\r\n component = []\r\n while vs:\r\n v = vs.pop()\r\n seen.add(v)\r\n vs |= set(graph[v]) - seen\r\n component.append(v)\r\n return component\r\n \r\n ans = []\r\n for v in graph:\r\n if v not in seen:\r\n d = dfs(v)\r\n ans.append(d)\r\n return ans\r\n\r\n# End graph related queries\r\n \r\n#### PRIME FACTORIZATION IN O(log n) using Sieve ####\r\nMAXN = int(1e6 + 5)\r\ndef spf_sieve():\r\n spf[1] = 1;\r\n for i in range(2, MAXN):\r\n spf[i] = i;\r\n for i in range(4, MAXN, 2):\r\n spf[i] = 2;\r\n for i in range(3, ceil(MAXN ** 0.5), 2):\r\n if spf[i] == i:\r\n for j in range(i*i, MAXN, i):\r\n if spf[j] == j:\r\n spf[j] = i;\r\n ## function for storing smallest prime factors (spf) in the array\r\n \r\n################## un-comment below 2 lines when using factorization #################\r\n# spf = [0 for i in range(MAXN)] \r\n# spf_sieve() \r\ndef factoriazation(x):\r\n ret = {};\r\n while x != 1:\r\n ret[spf[x]] = ret.get(spf[x], 0) + 1;\r\n x = x//spf[x]\r\n return ret\r\n ## this function is useful for multiple queries only, o/w use\r\n ## primefs function above. complexity O(log n)\r\n \r\n## taking integer array input\r\n\r\n\r\n# LCM of two numbers :\r\ndef lcm(a, b): return abs(a * b) // math.gcd(a, b)\r\n \r\n#defining a couple constants\r\nMOD = int(1e9)+7;\r\nCMOD = 998244353;\r\nINF = float('inf'); NINF = -float('inf');\r\ny, n = \"YES\", \"NO\"\r\nabd = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12,\r\n 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24,\r\n 'z': 25}\r\n\r\n\r\n# used for testing your code \r\n\r\n# inputs=open('input.txt','r') \r\n\r\ndef solve():\r\n # n = no. of lines,c = no. of distinct color ,k = len. of erasor \r\n n,c,k = map(int,input().split())\r\n d = {}\r\n for i in range(n):\r\n a,b,c = map(int,input().split())\r\n if c not in d.keys():\r\n d[c] = 1\r\n else:\r\n d[c] += 1\r\n v = list(map(int,input().split())) # equal \r\n l_r = k//v[0] # how much line can i remove\r\n l = list(d.values())\r\n i = 0\r\n while l_r != 0:\r\n l[l.index(max(l))] -= 1\r\n l_r -= 1 \r\n count = 0\r\n for i in l:\r\n count+=((i)*(i-1)*(i-2))//6\r\n print(count)\r\ndef __starting_point():\r\n # solve()\r\n # for t in range(getint()):\r\n # print(\"Case #{}: \".format(t + 1), end=\"\")\r\n # solve()\r\n for _ in range(int(input())):#getint()):\r\n solve()\r\n\r\n # https://codeforces.com/contest/507/status/B/page/296?order=BY_PROGRAM_LENGTH_ASC\n__starting_point()", "for x in range(int(input())):\r\n if(x == 6):\r\n n,c,kost = map(int, input().split())\r\n parallel = [{} for _ in range(c)]\r\n for _ in range(n):\r\n a,b,d = map(int, input().split())\r\n if(a in parallel[d-1]):\r\n parallel[d-1][a] += 1\r\n else:\r\n parallel[d-1][a] = 1\r\n \r\n \r\n v = list(map(int, input().split()))\r\n \r\n newparalle = [list(parallel[i].values()) for i in range(c)]\r\n pc = []\r\n for i in range(c):\r\n pc.append(len(parallel[i]))\r\n newparalle[i].sort()\r\n sumlekerakho = [sum(newparalle[i]) for i in range(c)]\r\n \r\n merasum = 0\r\n for i in range(c):\r\n vaah = sumlekerakho[i]\r\n ape = vaah * (vaah-1) * (vaah-2) // 6\r\n for ke in range(pc[i]):\r\n ape -= (newparalle[i][ke]) * (newparalle[i][ke]-1) * (vaah-newparalle[i][ke]) // 2\r\n if(newparalle[i][ke]>=3):\r\n ape -= newparalle[i][ke] * (newparalle[i][ke]-1) * (newparalle[i][ke]-2) // 6\r\n merasum += ape\r\n \r\n dp = [0 for _ in range(kost+1)]\r\n \r\n superlist = [[] for _ in range(c)]\r\n for i in range(c):\r\n sumsum = sumlekerakho[i]\r\n for k in range(sumsum):\r\n if(max(newparalle[i]) < (sumsum-k)/2):\r\n maxindex = newparalle[i].index(min(newparalle[i]))\r\n else:\r\n prod = (k-sumsum)*(sumsum-k) // 4 - 1\r\n for ke,item in enumerate(newparalle[i]):\r\n if(prod < (item)*(item-sumsum+k) and item!=0):\r\n prod = (item)*(item-sumsum+k)\r\n maxindex = ke\r\n ape = (sumsum-k-newparalle[i][maxindex])*(sumsum-k-newparalle[i][maxindex]-1) // 2\r\n for ke,item in enumerate(newparalle[i]):\r\n ape -= (item)*(item-1)//2\r\n ape += newparalle[i][maxindex] * (newparalle[i][maxindex]-1) // 2\r\n superlist[i].append(ape)\r\n newparalle[i][maxindex] -= 1\r\n if(newparalle[i][maxindex]<=0):\r\n newparalle[i].pop(maxindex)\r\n \r\n s = [[0 for _ in range(c)] for _ in range(kost+1)]\r\n for i in range(1,kost+1):\r\n dp[i] = dp[i-1]\r\n s[i] = s[i-1][:]\r\n for j in range(c):\r\n if v[j] <= i:\r\n if(s[i-v[j]][j]<sumlekerakho[j] and dp[i] <= dp[i-v[j]] + superlist[j][s[i-v[j]][j]] ):\r\n s[i] = s[i-v[j]][:]\r\n s[i][j] += 1\r\n dp[i] = dp[i-v[j]] + superlist[j][s[i-v[j]][j]]\r\n \r\n print(merasum - dp[kost])\r\n else:\r\n N,C,K=map(int,input().split())\r\n poss,lines,res = [0]*(K+1),{},0\r\n for _ in range(N):\r\n a,b,c=map(int,input().split())\r\n if c-1 not in lines: lines[c-1]={a:1};\r\n else: lines[c-1][a]=lines[c-1].get(a,0)+1;\r\n era=list(map(int,input().split())) \r\n for c in range(C):\r\n if era[c]==0: lines.pop(c,None);\r\n for c,mp in lines.items():\r\n vals=list(mp.values())\r\n if len(vals)>=3:\r\n vals.sort()\r\n s1,s2,s3=sum(vals),sum(a**2 for a in vals),sum(a**3 for a in vals)\r\n full=(s1**3-3*s1*s2+2*s3)//6\r\n res+=full;gain={0:0};idx=0;\r\n for j in range(era[c],K+1,era[c]):\r\n vals[idx]-=1;old=vals[idx]+1;nw=vals[idx]\r\n if vals[idx]==0:\r\n idx+=1\r\n if idx==len(vals): break;\r\n s1-=1;s2+=nw**2-old**2;s3+=nw**3-old**3;gain[j]=full-(s1**3-3*s1*s2+2*s3)//6\r\n prev=poss\r\n poss=[max(prev[i-j]+gain[j] for j in gain.keys() if j<=i) for i in range(K+1)]\r\n print(res-max(poss))", "# ##plot a line of y = ax + b and then count number of triangles formed by lines of same colour\n# ##then remove max possible lines (while not k <= 0) K - Vi\n# ##print min possible triangles after (max lines are removed, but not necessarily)\n# #>>>first, use y = ax + b to find line by taking x = 0 and y = 0 in two turns\n# #>>>then count all triangles with all three sides of same colour\n# #>>>remove as many lines as required, such that triangles formed are minimum\n# # __CONSTRAINTS__\n# # 1\u2264T\u226410 \n# # 1\u2264C\u2264N\u22643,000\n# # 0\u2264K\u22643,000\n# # 0\u2264ai,bi\u2264109 for each valid i\n# # 1\u2264ci\u2264C for each valid i\n# # 0\u2264Vi\u2264K for each valid i\n# # no two lines coincide, regardless of their colours\n# # no three lines are concurrent\n# # __SUBTASKS__\n# # Subtask #1 (10 points):\n# # # N\u226410\n# # # K\u2264100\n# # Subtask #2 (15 points):\n# # # V1=V2=\u2026=VC\n# # # no two lines are parallel\n# # Subtask #3 (25 points):\n# # # no two lines are parallel\n# # Subtask #4 (50 points):\n# # #original constraints\n# ###>>> clearly, brute force cannot be used....ANTS\n# ###APPROACH:\n# #>>> count the number of triangles for each different colour (using formula)\n# #>>> get sum of all triangles formed\n# #>>> remove lines to get minimum triangles!!!....how?\n# #>>> to get formula: try cummulative frequency of points of intersection and triangles...or nC3\n# #>>> consider all lines to be non-parallel and non-coincident of course....aim is subtask 2\n# # 1 --> 0, 0\n# # 2 --> 0 + 0 = 0, 1\n# # 3 --> 0 + 1 = 1, 3\n# # 4 --> 1 + 3 = 4, 6\n# # 5 --> 4 + 6 = 10, 10\n# # 6 --> 10 + 10 = 20, 15 ...\n# def f(n):\n# factorial = 1\n# for i in range(1,n + 1):\n# factorial = factorial*i\n# return factorial\n# for _ in range(int(input())):\n# \tn,C,k = map(int , input().split())\n# \tfor _ in range(n):\n# \t\ta,b,c = map(int , input().split())\n# \t\tfreq = {}\n# \t\tif(c in freq): freq[c] += 1;\n# \t\telse: freq[c] = 1;\n# \tV = list(map(int , input().split()))\n# \ttriangles,trianglelist,turns = 0,[],0\n# \tfor i in range(1,C + 1):\n# \t\ttrianglelist.append(f(i)//(f(i - 3)*6))\n# \t# while(k >= 0 and k > min(V)):\n# \t# \ti = max(freq, key = freq.get)\n# \t# \ttriangles += f(i - 1)//(f(i - 4)*6) - f(i)//(f(i - 3)*6)\n# \t# \tk -= V[i] #min(V)\n# \twhile(k >= 0 and k > min(V)):\n# \t\ti = max(freq, key = freq.get)\n# \t\tfreq[i] -= 1\n# \t\tk -= V[i - 1]\n# \t\tturns += 1\n# \ttrianglelist.remove(max(trianglelist))\n# \ttriangles = sum(trianglelist) + f(i - turns - 1)//(f(i - turns - 4)*6) + f(i)//(f(i - 3)*6)\n# \tprint(triangles) #TLE avoided, but WA\n# import math\n# from collections import defaultdict\n# T=int(input())\n# for i in range(T):\n# N,C,K=map(int,input().split())\n# D=defaultdict(int)\n# ans='Hello'\n# for j in range(N):\n# a,b,c=map(int,input().split())\n# D[c]+=1\n \n# v=list(map(int,input().split()))\n# q=0\n# num=K//v[0]\n# d=0\n# while(num>0):\n# P=list(D.keys())[list(D.values()).index(max(D.values()))]\n# D[P]-=1\n# num-=1\n# temp=0\n# for i,j in D.items():\n# if(j>=3):\n# temp+=(math.factorial(j)/(math.factorial(3)*math.factorial(j-3)))\n# print(int(temp)) #i was so close to the correct answer\n#^^^^^^^^^^^^^^^^noob answer, lines wasted. but AC [15 pts]\nfor _ in range(int(eval(input()))):\n N,C,K=list(map(int,input().split()))\n poss,lines,res = [0]*(K+1),{},0\n for _ in range(N):\n a,b,c=list(map(int,input().split()))\n if c-1 not in lines: lines[c-1]={a:1};\n else: lines[c-1][a]=lines[c-1].get(a,0)+1;\n era=list(map(int,input().split())) \n for c in range(C):\n if era[c]==0: lines.pop(c,None);\n for c,mp in list(lines.items()):\n vals=list(mp.values())\n if len(vals)>=3:\n vals.sort()\n s1,s2,s3=sum(vals),sum(a**2 for a in vals),sum(a**3 for a in vals)\n full=(s1**3-3*s1*s2+2*s3)//6\n res+=full;gain={0:0};idx=0;\n for j in range(era[c],K+1,era[c]):\n vals[idx]-=1;old=vals[idx]+1;nw=vals[idx]\n if vals[idx]==0:\n idx+=1\n if idx==len(vals): break;\n s1-=1;s2+=nw**2-old**2;s3+=nw**3-old**3;gain[j]=full-(s1**3-3*s1*s2+2*s3)//6\n prev=poss\n poss=[max(prev[i-j]+gain[j] for j in list(gain.keys()) if j<=i) for i in range(K+1)]\n print(res-max(poss))"]
{"inputs": [["2", "7 2 13", "1 10 1", "1 14 2", "6 4 1", "2 2 1", "0 12 2", "2 11 2", "0 6 1", "8 10", "6 1 20", "1 5 1", "2 11 1", "4 0 1", "6 8 1", "0 11 1", "3 3 1", "9"]], "outputs": [["2", "4"]]}
INTERVIEW
PYTHON3
CODECHEF
48,724
5ea889cae3bfb491085fc39105a8df3d
UNKNOWN
On Miu's smart phone, there is a search feature which lets her search for a contact name by typing digits on the keypad where each digit may correspond to any of the characters given below it. For example, to search for TOM, she can type 866 and for MAX she can type 629. +------+-----+------+ | 1 | 2 | 3 | | | ABC | DEF | +------+-----+------+ | 4 | 5 | 6 | | GHI | JKL | MNO | +------+-----+------+ | 7 | 8 | 9 | | PQRS | TUV | WXYZ | +------+-----+------+ | | 0 | | +------+-----+------+ Miu typed a random string of digits $S$ on the keypad while playing around, where each digit is between 2 and 9 inclusive. Now she wants to know the number of possible strings which would map to $S$. Since this number can be very large, output it modulo 10^9 + 7 (1000000007) -----Input:----- - The first line of the input consists of a single integer $T$ denoting the number of test cases. - Each test case consists of a string $S$. -----Output:----- - For each test case, print a single line containing one integer - the count of all possible strings mod 1,000,000,007 -----Constraints----- - 1 <= $T$ <= 10 - 1 <= $|S|$ <= 105 -----Subtasks----- Subtask #1 (10 points): - 1 <= $|S|$ <= 10 Subtask #2 (90 points): - Original Constraints -----Sample Input:----- 2 5 72 -----Sample Output:----- 3 12 -----EXPLANATION:----- - Example Case 1: On the key 5, we have the character set JKL. Hence the possible strings are J,K,L. Hence the answer is 3 % (1000000007) = 3. - Example Case 2: On key 7, we have the character set PQRS. On key 2, we have the character set ABC. Hence the possible strings are PA,PB,PC,QA,QB,QC,RA,RB,RC,SA,SB,SC. Hence the answer is 12 % (1000000007) = 12.
["for _ in range(int(input())):\n n=int(input())\n n1=0\n ans=1\n while(n>0):\n d=int(n % 10)\n if(d!=0):\n if(d!=9 and d!=7 and d!=1):\n n1=3\n elif(d==1):\n n1=1\n else:\n n1=4\n ans=(int(ans)*int(n1))% (1000000007)\n n/=10\n else:\n n/=10\n if(ans==1):\n print(\"0\")\n else:\n print(ans %(1000000007))\n", "t = int(input())\nfor i in range(t):\n l = [0,0,3,3,3,3,3,4,3,4]\n n = int(input())\n s=1\n while(n>0):\n if(l[int(n%10)]!=0):\n s*=l[int(n%10)]\n n/=10\n print(s)\n", "# cook your dish here\n\nn=int(input())\nfor i in range(n):\n num=int(input())\n\n mul=1\n while num:\n a=(num%10)\n num//=10\n if a==7 or a==9:\n mul*=4\n else:\n mul*=3\n \n print(mul%1000000007)\n", "# cook your dish here\n\nn=int(input())\nfor i in range(n):\n num=int(input())\n a=[]\n while num:\n a.append(num%10)\n num//=10\n mul=1\n for j in a:\n if j==7 or j==9:\n mul*=4\n elif j!=0 and j!=1:\n mul*=3\n print(mul%1000000007)\n", "for _ in range(int(input())):\n n=int(input())\n n1=0\n ans=1\n while(n>0):\n d=int(n % 10)\n if(d!=0):\n if(d!=9 and d!=7 and d!=1):\n n1=3\n elif(d==1):\n n1=1\n else:\n n1=4\n ans=(int(ans)*int(n1))% (1000000007)\n n/=10\n else:\n n/=10\n if(ans==1):\n print(\"0\")\n else:\n print(ans %(1000000007))\n", "t = int(input())\nfor i in range(t):\n l = [1,0,3,3,3,3,3,4,3,4]\n n = int(input())\n s=1\n while(n>0):\n s*=l[int(n%10)]\n n/=10\n print(s)\n", "# cook your dish here\n\n\narr=[\"ABC\",\"DEF\",\"GHI\",\"JKL\",\"MNO\",\"PQRS\",\"TUV\",\"WXYZ\"]\nt=int(input())\nfor i in range(0,t):\n n=str(input())\n \n n=int(n)\n \n p=n\n hi=1\n while p>1:\n j=p%10\n j=int(j)\n if j>1:\n \n hi=(hi*len(arr[j-2]))%1000000007\n \n p=p/10\n \n \n print(hi)\n \n", "# cook your dish here\n\n\narr=[\"ABC\",\"DEF\",\"GHI\",\"JKL\",\"MNO\",\"PQRS\",\"TUV\",\"WXYZ\"]\nt=int(input())\nfor i in range(0,t):\n n=str(input())\n l=len(n)\n n=int(n)\n \n p=n\n hi=1\n while p>1:\n j=p%10\n j=int(j)\n if j>1:\n \n hi=hi*len(arr[j-2])\n \n p=p/10\n \n \n print(hi)\n \n", "# cook your dish here\n\ndef count(res):\n sum=0\n for items in result:\n sum=sum+1\n return sum \n \nimport itertools\narr=[\"ABC\",\"DEF\",\"GHI\",\"JKL\",\"MNO\",\"PQRS\",\"TUV\",\"WXYZ\"]\nt=int(input())\nfor i in range(0,t):\n n=str(input())\n l=len(n)\n n=int(n)\n s=\"\"\n p=n\n hi=1\n while p>0:\n j=p%10\n j=int(j)\n if j>1:\n #s=s+arr[j-2]\n #result=itertools.combinations(arr[j-2],1)\n hi=hi*len(arr[j-2])\n \n p=p/10\n #result=itertools.combinations(s,l)\n \n print(hi)\n \n", "# cook your dish here\nlst = {2:3,3:3,4:3,5:3,6:3,7:4,8:3,9:4}\n\nfor _ in range(int(input())):\n val = list(map(int,input().strip()))\n count = 1\n for i in val:\n count*=lst[int(i)]\n if count != 1:\n print(count%1000000007)\n else:\n print(0)\n", "M = 1000000007\ndef letterCombinations(s):\n n = len(s)\n digits = list(s)\n if n==0:\n return []\n table = [0,0,3,3,3,3,3,4,3,4]\n \n ans = 1\n for i in range(n):\n ans = (ans* table[int(digits[i])])%M\n print(ans%M)\n\nt = int(input())\nwhile t>0:\n s = input().strip()\n letterCombinations(s)\n \n t-=1", "# cook your dish here\nd={'2':3,'3':3,'4':3,'5':3,'6':3,'7':4,'8':3,'9':4}\nmod=10**9+7\ntry:\n t=int(input())\n while(t):\n mul=1\n s=int(input())\n s=str(s)\n s=sorted(s)\n for i in s:\n mul=mul*(d[i])\n print(mul%mod)\n t=t-1\nexcept EOFError:\n pass\n", "# cook your dish here\nd={'2':3,'3':3,'4':3,'5':3,'6':3,'7':4,'8':3,'9':4}\nmod=10**9+7\ntry:\n t=int(input())\n while(t):\n mul=1\n s=int(input())\n s=str(s)\n s=sorted(s)\n for i in s:\n mul=mul*(d[i])\n print(mul%mod)\n t=t-1\nexcept EOFError:\n pass\n", "t = int(input())\n\nfor _ in range(t):\n n = input().strip()\n answer = 1\n for x in n:\n if int(x) <= 6 or int(x) == 8:\n answer *= 3\n elif int(x) == 7 or int(x) == 9:\n answer *= 4\n print(answer % 1000000007)\n", "d={2:3,3:3,4:3,5:3,6:3,7:4,8:3,9:4}\n\nt=int(input())\n\nres=[]\n\nfor x in range(t):\n st=input()\n mul=1\n for i in st:\n if i.isdigit()==False:\n continue\n digit=int(i)\n if digit>=2 and digit<=9:\n mul=mul*d[int(i)]\n mul=mul%(1000000007)\n else:\n continue\n \n res.append(mul)\n\nfor x in res:\n print(x)", "d={1:1,2:3,3:3,4:3,5:3,6:3,7:4,8:3,9:4,0:1}\nn=int(input())\nfor i in range(n):\n p=int(input())\n sum=1\n if(p<9):\n print(d[p])\n else:\n r=str(p)\n for j in range(len(r)):\n sum=sum*d[int(r[j])]\n print(sum%1000000007)", "# cook your dish here\nconstant = (10**9)+7\ntry:\n testCases = int(input().strip())\n for _ in range(testCases):\n total = 1\n ip = list(input().strip())\n for i in ip:\n if i in ['7','9']:\n total *= 4\n else:\n total *= 3\n print(total % constant)\nexcept EOFError:\n pass", "# cook your dish here\nconstant = (10**9)+7\ntry:\n testCases = int(input().strip())\n for _ in range(testCases):\n total = 1\n ip = list(input().strip())\n for i in ip:\n if i in ['7','9']:\n total *= 4\n else:\n total *= 3\n print(total % constant)\nexcept EOFError:\n pass", "from sys import stdin\n\nmod = 1000000007\nfor _ in range(int(stdin.readline())):\n s = stdin.readline().strip()\n ans = 1\n for ele in s:\n if ele == '7' or ele == '9':\n ans = (ans*4)%mod\n else:\n ans = (ans*3)%mod\n print(ans%mod)\n", "# cook your dish here\nt=int(input())\nwhile(t>0):\n n=int(input())\n c=1\n while(n>0):\n m=n%10\n if(m==7 or m==9):\n c*=4\n else:\n c*=3\n n=n//10\n print(c%1000000007)\n t-=1", "# cook your dish here\n\nt = int(input())\n#d = {\"1\":1, \"2\":3, \"3\":3, \"4\":3, \"5\":3, \"6\":3, \"7\":4, \"8\":3, \"9\":4, \"0\":1}\nfor rep in range(t):\n p = 1\n s = input()\n l = list(s)\n for i in l:\n if i == \"7\" or i == \"9\":\n p = (p * 4) % 1000000007\n elif i in [\"2\",\"3\",\"4\",\"5\",\"6\",\"8\"]:\n p = (p * 3) % 1000000007\n print(p)"]
{"inputs": [["2", "5", "72"]], "outputs": [["3", "12"]]}
INTERVIEW
PYTHON3
CODECHEF
5,844
ab93883a29da74cac0a2d67c511e87bf
UNKNOWN
Leha is a bright mathematician. Today he is investigating whether an integer is divisible by some square number or not. He has a positive integer X represented as a product of N integers a1, a2, .... aN. He has somehow figured out that there exists some integer P such that the number X is divisible by P2, but he is not able to find such P himself. Can you find it for him? If there are more than one possible values of P possible, you can print any one of them. -----Input----- The first line of the input contains an integer T denoting the number of test cases. T test cases follow. The first line of each test case contains one integer N denoting the number of intgers in presentation of X. The second line contains N space-separated integers a1, a2, .... aN. -----Output----- For each test case, output a single integer P deoting the answer for this test case. Note that P must be in range from 2 to 1018 inclusive. It's guaranteed that at least one answer exists. If there are more than one possible answers, print any. -----Constraints----- - 1 ≤ T ≤ 5 - 1 ≤ N ≤ 100 - 1 ≤ ai ≤ 1018 -----Subtasks----- - Subtask 1[19 points]: 1 ≤ a1*a2*...*aN ≤ 106 - Subtask 2[22 points]: 1 ≤ a1*a2*...*aN ≤ 1012 - Subtask 3[23 points]: 1 ≤ ai ≤ 1012 - Subtask 4[36 points]: no additional constraints -----Example----- Input: 1 3 21 11 6 Output: 3 -----Explanation----- Example case 1. X = 21 * 11 * 6 = 1386. It's divisible by 9 which is a square number, as 9 = 32. So P = 3.
["import sys\nimport math\nr=int(input())\nfor v in range (0,r):\n n = int(input())\n x=1\n arr=list(map(int,input().strip().split(\" \")))\n for i in range (0,n):\n x=x*arr[i]\n \n for i in range (2,100000000):\n if(x%(pow(i,2))==0):\n ans1=i\n break\n \n \n print(ans1) \n", "import math\ndef forloop(list,list1):\n r = 1\n for x in list:\n r *= x\n for i in list1:\n if(r%i==0):\n break;\n return i\nt=int(input())\nwhile(t>0):\n l1=[]\n n=int(input())\n l=list(map(int,input().split()))\n for i in range(2,1000000):\n l1.append(i*i)\n l1=tuple(l1)\n n1=forloop(l,l1)\n ans=math.sqrt(n1)\n print(int(ans))\n t-=1", "import sys\nimport math\nr=int(input())\nfor v in range (0,r):\n n = int(input())\n x=1\n arr=list(map(int,input().strip().split(\" \")))\n for i in range (0,n):\n arr[i]=arr[i]%1000000000000000007\n for i in range (0,n):\n x=x*arr[i]\n \n for i in range (2,1000000):\n if(x%(pow(i,2))==0):\n ans1=i\n break\n \n \n print(ans1) \n", "import sys\nimport math\nr=int(input())\nfor v in range (0,r):\n n = int(input())\n x=1\n arr=list(map(int,input().strip().split(\" \")))\n for i in range (0,n):\n arr[i]=arr[i]%1000000007\n for i in range (0,n):\n x=x*arr[i]\n \n for i in range (2,1000000):\n if(x%(pow(i,2))==0):\n ans1=i\n break\n \n \n print(ans1) \n", "import math\ndef forloop(list,list1):\n r = 1\n for x in list:\n r *= x\n for i in l1:\n if(r%i==0):\n break;\n return i\nt=int(input())\nwhile(t>0):\n l1=[]\n n=int(input())\n l=list(map(int,input().split()))\n for i in range(2,1000000):\n l1.append(i*i)\n l1=tuple(l1)\n n1=forloop(l,l1)\n ans=math.sqrt(n1)\n print(int(ans))\n t-=1", "import math\nfor i in range(int(input())):\n y=int(input())\n x=list(map(int,input().split()))\n p=1\n for j in x:\n p=p*j\n \n m=max(x)\n \n r=1\n \n for k in range(2,m):\n \n if p%k**2==0:\n r=k\n break\n print(r)", "import fractions \n\ndef repeat_factor(n):\n fs = []\n for i in range(2, int(n**0.5) + 1):\n if n % i == 0:\n q = n / i;\n if q % i == 0:\n return i\n return 1\n\n\nnprobs = int(input())\nfor i in range(nprobs):\n x = input()\n prob = list(map(int, input().split()))\n found = False\n # for i in range(len(prob)):\n # for j in range(len(prob)):\n # if (i != j):\n # hcf = fractions.gcd(prob[i], prob[j])\n # if hcf > 1:\n # print hcf\n # found = True\n # break\n # if found:\n # break\n # if found:\n # break\n prod = 1\n for i in prob:\n prod *= i\n # for i in prob:\n # x = repeat_factor(i)\n # if x > 1:\n # print x\n # break\n x = repeat_factor(prod)\n print(x)\n\n", "import sys\nimport math\nr=int(input())\nfor v in range (0,r):\n n = int(input())\n x=1\n arr=list(map(int,input().strip().split(\" \")))\n for i in range (0,n):\n arr[i]=arr[i]%1000000007\n for i in range (0,n):\n x=x*arr[i]\n x%=1000000007\n \n for i in range (2,1000000):\n if(x%(pow(i,2))==0):\n ans1=i\n break\n \n \n print(ans1) \n", "import sys\nimport math\nr=int(input())\nfor v in range (0,r):\n n = int(input())\n x=1\n arr=list(map(int,input().strip().split(\" \")))\n for i in range (0,n):\n arr[i]=arr[i]%1000000000000000007\n for i in range (0,n):\n x=x*arr[i]\n x%=1000000007\n \n for i in range (2,1000000):\n if(x%(pow(i,2))==0):\n ans1=i\n break\n \n \n print(ans1) \n", "from collections import *\ndef prime(n):\n d=2\n while d*d<=n:\n while n%d==0:\n primef.append(d)\n n=n//d\n d+=1\n if n>1: primef.append(n)\nfor _ in range(eval(input())):\n primef=[]\n x,prod=eval(input()),1\n m=list(map(int,input().split()))\n for i in m:\n prime(i)\n for i in primef:\n if primef.count(i)>=2: break\n print(i)\n", "import math\n\ndef gen_primes(num):\n nonlocal primes\n flag = False\n j = 0\n for i in range(primes[-1]+1, num+1):\n while primes[j] < math.sqrt(i):\n if i%primes[j] == 0:\n flag = True\n break\n j += 1\n if flag:\n flag = False\n pass\n else:\n primes.append(i)\n\n\ndef divisible(num):\n nonlocal primes, d, divisors\n srt = int(round(math.sqrt(num)))\n if srt <= primes[-1]:\n for i in primes:\n if num % (i*i) == 0:\n d = i\n return True\n elif num % i == 0:\n if divisors.get(i, 0):\n d = i\n return True\n else:\n divisors[i] = 1\n \n else:\n gen_primes(srt)\n for i in primes:\n if num % (i*i) == 0:\n d = i\n return True\n elif num % i == 0:\n if divisors.get(i, 0):\n d = i\n return True\n else:\n divisors[i] = 1\n\n\nprimes = [2,3,5,7,11]\nfor i in range(eval(input())):\n n = eval(input())\n l = input().strip().split()\n divisors = {}\n d = 0\n for j in range(n):\n l[j] = int(l[j])\n check = divisible(l[j])\n if check:\n print(d)\n break\n", "import math\ndef forloop(list):\n r = 1\n for x in list:\n r *= x\n return r\nt=int(input())\nwhile(t>0):\n l1=[]\n n=int(input())\n l=list(map(int,input().split()))\n for i in range(2,1000000):\n l1.append(i*i)\n l1=tuple(l1)\n n1=forloop(l)\n for i in l1:\n if(n1%i==0):\n break;\n ans=math.sqrt(i)\n print(int(ans))\n t-=1", "import sys\nimport math\nr=int(input())\nfor v in range (0,r):\n n = int(input())\n x=1\n arr=list(map(int,input().strip().split(\" \")))\n for i in range (0,n):\n x=x*arr[i]\n x%=1000000007\n \n for i in range (2,9000000):\n if(x%(pow(i,2))==0):\n ans1=i\n break\n \n \n print(ans1) \n", "import math\n\ndef divisorGenerator(n):\n large_divisors = []\n for i in range(2, int(math.sqrt(n) + 1)):\n if n % i == 0:\n yield i\n if i*i != n:\n large_divisors.append(n / i)\n for divisor in reversed(large_divisors):\n yield divisor\nt = int(input())\nwhile t>0 :\n n = int(input())\n a = list(map(int,input().split()))\n p = 1\n for i in a:\n p = p * i\n s = list(divisorGenerator(p))\n\n for j in s:\n if p % (j**2) ==0 :\n print(j)\n break\n t = t - 1 \n", "import sys\nimport math\nr=int(input())\nfor v in range (0,r):\n n = int(input())\n x=1\n arr=list(map(int,input().strip().split(\" \")))\n for i in range (0,n):\n x=x*arr[i]\n \n \n for i in range (2,1000000):\n if(x%(pow(i,2))==0):\n ans1=i\n break\n \n \n print(ans1) \n", "import math\n\nfor i in range(int(input())):\n y=int(input())\n x=list(map(int,input().split()))\n pr=1\n for j in x:\n pr=pr*j\n #s=min(x)\n m=max(x)\n #m=int(math.sqrt(m))\n #s=int(math.sqrt(s))\n rm=1\n #print s,m\n for k in range(2,m):\n #print k\n if pr%k**2==0:\n rm=k\n break\n print(rm) \n \n", "import sys\nimport math\nr=int(input())\nfor v in range (0,r):\n n = int(input())\n x=1\n arr=list(map(int,input().strip().split(\" \")))\n for i in range (0,n):\n x=x*arr[i]\n \n \n for i in range (2,10000000):\n if(x%(pow(i,2))==0):\n ans1=i\n break\n \n \n print(ans1) \n", "import math\n\ndef gen_primes(num):\n nonlocal primes\n flag = False\n j = 0\n for i in range(primes[-1]+1, num+1):\n while primes[j] <= math.sqrt(i):\n if i%primes[j] == 0:\n flag = True\n break\n j += 1\n if flag:\n flag = False\n pass\n else:\n primes.append(i)\n\n\ndef divisible(num):\n nonlocal primes, d, divisors\n srt = int(round(math.sqrt(num)))\n if srt <= primes[-1]:\n for i in primes:\n if num % (i*i) == 0:\n d = i\n return True\n elif num % i == 0:\n if divisors.get(i, 0):\n d = i\n return True\n else:\n divisors[i] = 1\n \n else:\n gen_primes(srt)\n for i in primes:\n if num % (i*i) == 0:\n d = i\n return True\n elif num % i == 0:\n if divisors.get(i, 0):\n d = i\n return True\n else:\n divisors[i] = 1\n\n\nprimes = [2,3,5,7,11]\nfor i in range(eval(input())):\n n = eval(input())\n l = input().strip().split()\n divisors = {}\n d = 0\n for j in range(n):\n l[j] = int(l[j])\n check = divisible(l[j])\n if check:\n print(d)\n break\n", "import sys\nimport math\nr=int(input())\nfor v in range (0,r):\n n = int(input())\n x=1\n arr=list(map(int,input().strip().split(\" \")))\n for i in range (0,n):\n x=x*arr[i]\n \n \n for i in range (2,20000000):\n if(x%(pow(i,2))==0):\n ans1=i\n break\n \n \n print(ans1) \n", "import sys\nimport math\nr=int(input())\nfor v in range (0,r):\n n = int(input())\n x=1\n arr=list(map(int,input().strip().split(\" \")))\n for i in range (0,n):\n x=x*arr[i]\n \n \n for i in range (2,20000000):\n if(x%(math.pow(i,2))==0):\n ans1=i\n break\n \n \n print(ans1) \n", "import sys\nimport math\nr=int(input())\nfor v in range (0,r):\n n = int(input())\n x=1\n arr=list(map(int,input().strip().split(\" \")))\n for i in range (0,n):\n x=x*arr[i]\n \n \n for i in range (2,80000000):\n if(x%(math.pow(i,2))==0):\n ans1=i\n break\n \n \n print(ans1) \n", "import sys\nimport math\nr=int(input())\nfor v in range (0,r):\n n = int(input())\n x=1\n arr=list(map(int,input().strip().split(\" \")))\n for i in range (0,n):\n x=x*arr[i]\n \n \n for i in range (2,20000000):\n if(x%(math.pow(i,2))==0):\n ans1=i\n break\n \n \n print(ans1) \n", "import sys\nimport math\nr=int(input())\nfor v in range (0,r):\n n = int(input())\n x=1\n arr=list(map(int,input().strip().split(\" \")))\n for i in range (0,n):\n x=x*arr[i]\n \n \n for i in range (2,15000000):\n if(x%(math.pow(i,2))==0):\n ans1=i\n break\n \n \n print(ans1) \n"]
{"inputs": [["1", "3", "21 11 6"]], "outputs": [["3"]]}
INTERVIEW
PYTHON3
CODECHEF
9,278
c2b58859efe6dd5a35c77df831d8fa0a
UNKNOWN
Kabir Singh is playing a game on the non-negative side of x-axis. It takes him $1 second$ to reach from Pth position to (P−1)th position or (P+1)th position. Kabir never goes to the negative side and also doesn't stop at any moment of time. The movement can be defined as : - At the beginning he is at $x=0$ , at time $0$ - During the first round, he moves towards $x=1$ and comes back to the $x=0$ position. - In the second round, he moves towards the $x=2$ and comes back again to $x=0$. - So , at $Kth$ round , he moves to $x=K$ and comes back to $x=0$ So in this way game goes ahead. For Example, the path of Kabir for $3rd$ round is given below. $0−1−2−3−2−1−0$ The overall path followed by Kabir would look somewhat like this: $0−1−0−1−2−1−0−1−2−3−2−1−0−1−2−3−4−3−…$ Now the task is , You are given Two Non-Negative integers $N$ , $K$ . You have to tell the time at which Kabir arrives at $x=N$ for the $Kth$ time. Note - Kabir visits all the points , he can not skip or jump over one point. -----Input:----- - First line will contain $T$, number of testcases. Then the testcases follow. - Each testcase contains of a single line of input, two integers $N, K$. -----Output:----- For each testcase, output in a single line answer i.e Time Taken by Kabir Singh modulo 1000000007. -----Constraints----- - $1 \leq T \leq 10^5$ - $0 \leq N \leq 10^9$ - $1 \leq K \leq 10^9$ -----Sample Input:----- 4 0 1 1 1 1 3 4 6 -----Sample Output:----- 0 1 5 46 -----EXPLANATION:----- Test Case 1: Kabir starts the journey from the $N=0$ at time $t=0$ and it's the first time$ (K=1)$, he is here. So, the answer is $0$. Test Case 3: The path followed by Kabir to reach 1 for the third time is given below. $0−1−0−1−2−1$ He reaches $1$ for the third time at $ t=5$.
["# cook your dish here\nT=int(input())\nMOD=int(1e9+7)\nfor t in range(T):\n N,K=[int(a) for a in input().split()]\n M=K//2\n # ans= ((K%2)?( (N+M)*(N+M) + M ):( (N+M)*(N+M) - M) )\n ans=(N+M)*(N+M) -M\n if(K%2):\n ans+=2*M\n if(N==0):\n ans=K*(K-1)\n print(ans%MOD) ", "# cook your dish here\nt=int(input())\nfor _ in range(t):\n n,k=list(map(int,input().split()))\n M = 1000000007\n if(n==0):\n m=k-1\n total=(m*(m+1))\n print(total % M)\n else:\n if(k % 2==0):\n m=(k-2)//2 + n\n total=(m*(m+1)) + n\n print(total % M)\n else:\n m=(k)//2 + n\n total=(m*(m+1)) - n\n print(total % M)\n", "mod = 10**9 + 7\r\nfor t in range(int(input())):\r\n n, k = map(int, input().split())\r\n if n == 0:\r\n if k == 1:\r\n print(0)\r\n else:\r\n print(int((k * (1 + k)) / 2) % mod)\r\n continue\r\n futile_moves = (n - 1)\r\n if k == 1:\r\n f_time = futile_moves * (1 + futile_moves)\r\n print((f_time + n) % mod)\r\n continue\r\n k -= 1\r\n futile_moves += 1\r\n if k % 2 == 0:\r\n futile_moves += (int(k / 2) - 1)\r\n else:\r\n futile_moves += int(k / 2)\r\n f_time = futile_moves * (1 + futile_moves)\r\n if k % 2 == 0:\r\n f_time += (futile_moves + 1) * 2 - n\r\n else:\r\n f_time += n\r\n f_time %= mod\r\n print(f_time)", "# cook your dish here\n\"\"\"\nCreated on Sat May 23 23:48:49 2020\n\n@author: aurouS_EeRiE\n\"\"\"\n\n\ndef solve(n, k):\n ans = 0\n if n == 0:\n if k == 1:\n return 0\n else:\n return ((k - 1) * (k)) % ((10 ** 9) + 7)\n if k == 1:\n return (n * n) % ((10 ** 9) + 7)\n if k % 2 == 0:\n ans = n * n + n * k + int(int((k - 1) / 2) * int((k - 1) / 2 + 1))\n if k % 2 != 0:\n ans = n * n + (2 * n) * (max(0, int((k - 1) / 2))) + int(int((k - 1) / 2) * int((k - 1) / 2 + 1))\n return ans % ((10 ** 9) + 7)\n\nt = int(input())\nfor i in range(t):\n n, k=map(int, input().split())\n print(solve(n, k))", "# cook your dish here\nmod = 10**9 + 7\n\nfor k in range(int(input())):\n\tnum, times = map(int, input().split())\n\n\tif num == 0:\n\t\tx = times - 1\n\t\tans = (((x%mod)*(x%mod))%mod + x%mod)%mod\n\telse:\n\t\tif times%2 == 0:\n\t\t\tx = num + (times-1)//2\n\t\t\tans = ((((x%mod)*(x+1)%mod) + x%mod) + num%mod - x%mod)%mod\n\t\telse:\n\t\t\tx = num + (times-1)//2\n\t\t\tans = ((((x%mod)*(x+1)%mod) + x%mod) - num%mod - x%mod)%mod\n\n\tprint(ans)", "import math\r\nmod=1000000007\r\nT=int(input())\r\nfor _ in range(T):\r\n n,m=list(map(int,input().split()))\r\n if (n==0):\r\n print((m*(m-1))%mod)\r\n \r\n elif (m==1):\r\n print(((n*(n-1))+n)%mod)\r\n\r\n else:\r\n val=n-1+(math.ceil((m-1)/2))\r\n fv=(val*(val+1))%mod\r\n if ((m-1)%2==0):\r\n fv=(fv+(2*(val+1))-n)%mod\r\n else:\r\n fv=(fv+n)%mod\r\n\r\n print(fv%mod)\r\n", "# cook your dish here\nmod=10**9+7\nfor _ in range(int(input())):\n n,k=map(int,input().split())\n if n==0:\n print(k*(k-1))\n else:\n ans=0\n tmp=k//2\n if k&1:\n ans+=k-1\n ans+=(n+tmp)*(n+tmp)-tmp\n print(ans%mod)", "# cook your dish here\n\"\"\"\nCreated on Sat May 23 23:28:42 2020\n\nTitle: Walking Man\n\nContest: LockDown Test 4.0\n\n@author: mr._white_hat_\n\"\"\"\n\nfor _ in range(int(input())):\n n, k = map(int, input().split())\n if n==0:\n print((k*(k-1))% 1000000007)\n continue\n x = int((k - k % 2) / 2)\n ans = (n + x - 1)*(n + x) + n + 2*(k % 2)*(x) \n print(ans % 1000000007)", "# cook your dish here\nT=int(input())\nMOD=int(1e9+7)\nfor t in range(T):\n N,K=[int(a) for a in input().split()]\n M=K//2\n ans=(N+M)*(N+M) -M\n if(K%2):\n ans+=2*M\n if(N==0):\n ans=K*(K-1)\n print(ans%MOD) ", "# cook your dish here\nt=int(input())\nfor _ in range(t):\n\n [n,k]=[int(x) for x in input().split()]\n if n==0:\n print(((k-1)*k)%1000000007)\n continue\n \n if k%2==0:\n x=int(k/2)-1\n print( ((n+x)*(n+x+1)+ n ) % 1000000007 )\n else:\n x=int((k-3)/2)\n print( ((n+x) * (n+x+1) + n+2*x+2 ) % 1000000007 )", "import math\r\nMOD = 1000000007\r\n\r\nT = int(input())\r\n\r\n# d = {0: [0, 2, 6, 12, 20, 30, 42, 56, 72], 1: [1, 3, 5, 7, 11, 13, 19, 21, 29, 31, 41, 43, 55, 57, 71, 73, 89], 2: [4, 8, 10, 14, 18, 22, 28, 32, 40, 44, 54, 58, 70, 74, 88], 3: [9, 15, 17, 23, 27, 33, 39, 45, 53, 59, 69, 75, 87], 4: [16, 24, 26, 34, 38, 46, 52, 60, 68, 76, 86], 5: [25, 35, 37, 47, 51, 61, 67, 77, 85], 6: [36, 48, 50, 62, 66, 78, 84], 7: [49, 63, 65, 79, 83], 8: [64, 80, 82], 9: [81]}\r\nfor t in range(T):\r\n i,N = list(map(int, input().split()))\r\n if i == 0:\r\n N = N*2\r\n tmp = math.floor(N/2)\r\n tmp2 = math.floor((N-1)/2)\r\n ans = (i*i)%MOD + (tmp*2*i)%MOD + ( tmp2*(tmp2+1) )%MOD\r\n print(ans%MOD)\r\n", "# cook your dish here\nt=int(input())\n\nfor _ in range(0,t):\n n,k= map(int, input().split())\n if n!=0:\n fn=n+(k//2)\n if k%2==0:\n print((fn**2-fn+n)%1000000007)\n else:\n print((fn**2+fn-n)%1000000007)\n else:\n print((k*(k-1))%1000000007)", "# import sys\n# sys.stdin = open('input.txt','r')\n# sys.stdout = open('output1.txt','w')\nimport math\nfrom sys import stdin,stdout\nfrom math import gcd,sqrt,ceil,floor,inf\nfrom copy import deepcopy\nii1=lambda:int(stdin.readline().strip())\nis1=lambda:stdin.readline().strip()\niia=lambda:list(map(int,stdin.readline().strip().split()))\nisa=lambda:stdin.readline().strip().split()\nmod=1000000007\n# fib=[1,1]\n# a=1\n# b=1\n# for i in range(100001):\n# a,b=b,a+b\n# fib.append(b%mod)\n# print(fib[0:10])\nfor _ in range(ii1()):\n n,k=iia()\n new=k-1\n if n==0:\n if k==1:\n ans=0\n else:\n ans=(k-1)*(k)\n elif k==1:\n ans=n*(n+1)-n\n elif k%2==0:\n ans=(n+(new//2))*(n+(new//2)+1)+n\n else:\n ans=(n+(new//2))*(n+(new//2)+1)-n\n print(ans%mod)\n\n\n\n\n\n\n", "t = int(input())\r\nfor i in range(t):\r\n n, k = [int(x) for x in input().split()]\r\n if n == 0:\r\n ans = (k - 1) * k\r\n print(ans % 1000000007)\r\n continue\r\n k -= 1\r\n if k == 0:\r\n ans = n * (n - 1) + n\r\n print(ans % 1000000007)\r\n elif k % 2 != 0:\r\n p = n + (k // 2)\r\n ans = p * (p + 1) + n\r\n print(ans % 1000000007)\r\n else:\r\n k -= 2\r\n p = n + (k // 2)\r\n ans = p * (p + 1) + (p + 1) + (p + 1 - n)\r\n print(ans % 1000000007)\r\n", "t = int(input())\r\nmod = 10**9 + 7\r\nfor _ in range(t):\r\n n, k = list(map(int, input().split()))\r\n if n==0:\r\n k-=1\r\n print(k**2+k)\r\n continue\r\n if k==1:\r\n l = n-1\r\n nz = l**2 + l\r\n print(nz+n)\r\n continue\r\n rem = k%2\r\n up = k//2\r\n l = up + n - 1\r\n nz = l**2 + l\r\n #print(nz)\r\n if rem==0:\r\n ans = nz + n\r\n print(ans%mod)\r\n else:\r\n ans = nz + 2*l + 2 - n\r\n print(ans%mod)\r\n", "test=int(input())\r\nfor _ in range(test):\r\n n,k=map(int,input().split())\r\n ans=pow(n,2,1000000007)\r\n k=k-1\r\n i=0\r\n while(k!=0):\r\n ans+=(2*n)%1000000007\r\n if n!=0:\r\n k-=1\r\n if k==0:\r\n break\r\n ans+=(i+2)%1000000007\r\n k-=1\r\n \r\n i=i+2\r\n print(ans%1000000007)", "#dt = {} for i in x: dt[i] = dt.get(i,0)+1\nipnl = lambda n: [int(input()) for _ in range(n)]\ninp = lambda :int(input())\nip = lambda :[int(w) for w in input().split()]\n\nM = 10**9+7\nfor _ in range(inp()):\n n,k = ip()\n if n == 0:\n t = k*(k-1)\n print(t%M)\n continue\n if k == 1:\n print(n*n)\n continue\n kk = k//2\n t = (n+kk)*(n+kk)\n if k%2:\n t += kk\n else:\n t -= kk\n print(t%M)", "import sys\nfrom random import choice,randint\ninp=sys.stdin.readline\nout=sys.stdout.write\nflsh=sys.stdout.flush\n \nsys.setrecursionlimit(10**9)\ninf = 10**20\neps = 1.0 / 10**10\nmod = 10**9+7\ndd = [(-1,0),(0,1),(1,0),(0,-1)]\nddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]\n \ndef MI(): return map(int, inp().strip().split())\ndef LI(): return list(map(int, inp().strip().split()))\ndef LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines().strip()]\ndef LI_(): return [int(x)-1 for x in inp().strip().split()]\ndef LF(): return [float(x) for x in inp().strip().split()]\ndef LS(): return inp().strip().split()\ndef I(): return int(inp().strip())\ndef F(): return float(inp().strip())\ndef S(): return inp().strip()\ndef pf(s): return out(s+'\\n')\ndef JA(a, sep): return sep.join(map(str, a))\ndef JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)\n\ndef main():\n from math import ceil\n t = I()\n l = []\n for _ in range(t):\n n,k=MI()\n if n==0:\n k-=1\n ans = ((k)*((k+1)))%mod\n l.append(ans)\n else:\n # if k==1:\n # ans = ((((n)*((n-1)))%mod)+ n%mod)%mod\n # l.append(ans)\n # else:\n # k-=1\n # lr = (n%mod+((ceil(k/2)%mod))%mod\n # ans = ((lr*((lr-1))%mod\n # if k%2!=0:\n # ans= (ans%mod + n%mod)%mod\n # else:\n # ans = ((ans%mod)+((lr+n)%mod))%mod\n # l.append(ans)\n if k%2!=0:\n lr = k//2\n l.append(((n*n)%mod+(lr*((2*n)%mod))%mod+(lr*(lr+1))%mod)%mod)\n else:\n lr = k//2\n l.append(((n*n)%mod + (lr*(2*n)%mod)%mod + (lr*(lr-1))%mod)%mod)\n\n for i in range(t):\n pf(str(l[i]))\n\ndef __starting_point():\n main()\n__starting_point()", "MOD = 10**9+7\r\nfor lo in range(int(input())):\r\n n, k = list(map(int,input().split()))\r\n if n==0:\r\n print(k*(k-1) % MOD)\r\n continue\r\n \r\n c = k//2\r\n x = 1\r\n if k%2==0:\r\n x = 0\r\n \r\n y = c+x+n\r\n \r\n if x==0:\r\n ans = (y*(y-1))+n\r\n else:\r\n ans = (y*(y-1))-n\r\n \r\n print(ans % MOD)\r\n", "import math\r\nt = int(input())\r\nwhile t > 0:\r\n\tk = input()\r\n\tif len(k) == 0: continue;\r\n\r\n\tn, k = k.split()\r\n\tn = int(n)\r\n\tk = int(k)\r\n\r\n\t\r\n\tif n == 0 and k == 1 : \r\n\t\tprint(\"0\")\r\n\t\tt-=1\r\n\t\tcontinue\r\n\telif n == 0:\r\n\t\tprint((k*(k-1))%1000000007)\r\n\t\tt-=1\r\n\t\tcontinue\r\n\t\r\n\tlevel = n + math.ceil((k + 1)/2)\r\n\ttime = (level - 1)*(level - 2)\r\n\r\n\tif k%2 == 0 : time = time + n;\r\n\telse : time = time + 2*(level-1) - n;\r\n\tprint(time%1000000007)\r\n\tt-=1", "'''\r\n leave a comment if you don't understand something :)\r\n thanks for choosing my code!! ~Srikar\r\n\r\n'''\r\n\r\nT=int(input())\r\nmod=1000000007\r\nfor _ in range(T):\r\n n,k=list(map(int,input().split()))\r\n if n==0:\r\n k-=1\r\n print((k*(k+1))% mod )\r\n else:\r\n if k==1:\r\n print((n**2) % mod)\r\n \r\n \r\n else:\r\n if k%2==0:\r\n a=k//2 #even numbers\r\n b=a-1 #odd numbers\r\n \r\n ans=((n**2) % mod)+((a*((2*n)%mod))%mod)+((b*(b+1))%mod)\r\n else:\r\n k-=1\r\n a=k//2 #even numbers\r\n b=a #odd numbers\r\n \r\n ans=((n**2) % mod)+((a*((2*n)%mod))%mod)+((b*(b+1))%mod)\r\n \r\n print(ans%mod)\r\n \r\n \r\n \r\n \r\n", "mod = 1000000007\r\nfor _ in range(int(input())):\r\n n,k = list(map(int, input().split()))\r\n if n == 0:\r\n k -= 1\r\n print(k*(k+1) % mod)\r\n else:\r\n if k==1:\r\n print((n**2) % mod)\r\n else:\r\n if k%2==0:\r\n a=k // 2\r\n b=a - 1\r\n \r\n ans=((n**2) % mod)+((a*((2*n)%mod))%mod)+((b*(b+1))%mod)\r\n else:\r\n k -= 1\r\n a = k // 2\r\n b = a\r\n \r\n ans = ((n**2) % mod)+((a*((2*n)%mod))%mod)+((b*(b+1))%mod)\r\n \r\n print(ans%mod)\r\n \r\n"]
{"inputs": [["4", "0 1", "1 1", "1 3", "4 6"]], "outputs": [["0", "1", "5", "46"]]}
INTERVIEW
PYTHON3
CODECHEF
12,888
83965d177227288bcf879f0a41219335
UNKNOWN
Chef Ada is preparing $N$ dishes (numbered $1$ through $N$). For each valid $i$, it takes $C_i$ minutes to prepare the $i$-th dish. The dishes can be prepared in any order. Ada has a kitchen with two identical burners. For each valid $i$, to prepare the $i$-th dish, she puts it on one of the burners and after $C_i$ minutes, removes it from this burner; the dish may not be removed from the burner before those $C_i$ minutes pass, because otherwise it cools down and gets spoiled. Any two dishes may be prepared simultaneously, however, no two dishes may be on the same burner at the same time. Ada may remove a dish from a burner and put another dish on the same burner at the same time. What is the minimum time needed to prepare all dishes, i.e. reach the state where all dishes are prepared? -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains a single integer $N$. - The second line contains $N$ space-separated integers $C_1, C_2, \ldots, C_N$. -----Output----- For each test case, print a single line containing one integer ― the minimum number of minutes needed to prepare all dishes. -----Constraints----- - $1 \le T \le 1,000$ - $1 \le N \le 4$ - $1 \le C_i \le 5$ for each valid $i$ -----Subtasks----- Subtask #1 (1 points): $C_1 = C_2 = \ldots = C_N$ Subtask #2 (99 points): original constraints -----Example Input----- 3 3 2 2 2 3 1 2 3 4 2 3 4 5 -----Example Output----- 4 3 7 -----Explanation----- Example case 1: Place the first two dishes on the burners, wait for two minutes, remove both dishes and prepare the last one on one burner. Example case 2: Place the first and third dish on the burners. When the first dish is prepared, remove it and put the second dish on the same burner. Example case 3: Place the third and fourth dish on the burners. When the third dish is prepared, remove it and put the second dish on the same burner. Similarly, replace the fourth dish (when it is prepared) by the first dish on the other burner.
["for i in range(int(input())):\n n=int(input())\n c=[int(z) for z in input().split()]\n c.sort()\n c.reverse()\n b1,b2=0,0\n for i in range(n):\n if b1<b2:\n b1+=c[i]\n elif b2<b1:\n b2+=c[i]\n else:\n b1+=c[i]\n print(max(b1,b2))\n \n", "n=int(input())\nfor i in range(n):\n N=int(input())\n lst=list(map(int,input().split()))\n lst.sort()\n if N==1:\n print(lst[0])\n elif N==2:\n print(lst[1])\n elif N==3:\n print(lst[1]+max(lst[0],(lst[2]-lst[1])))\n else:\n if lst[3]-lst[2]>=lst[1]:\n print(lst[2]+lst[1]+max(lst[0],lst[3]-(lst[1]+lst[2])))\n else:\n print(lst[3]+max(lst[0],lst[1]+lst[2]-lst[3]))\n\n \n \n", "# cook your dish here\nn=int(input())\nfor i in range(n):\n N=int(input())\n lst=list(map(int,input().split()))\n if N==1:\n print(lst[0])\n elif N==2:\n print(lst[1])\n elif N==3:\n print(lst[1]+max(lst[0],(lst[2]-lst[1])))\n else:\n if lst[3]-lst[2]>=lst[1]:\n print(lst[2]+lst[1]+max(lst[0],lst[3]-(lst[1]+lst[2])))\n else:\n print(lst[3]+max(lst[0],lst[1]+lst[2]-lst[3]))", "\nfor _ in range(int(input())):\n a=int(input())\n b=list(map(int,input().split()))[:a]\n b.sort(reverse=True)\n n1,n2=0,0\n for i in range(a):\n if n1<n2:\n n1+=b[i]\n else:\n n2+=b[i]\n print(max(n1,n2))\n", "# cook your dish here\nt=int(input())\nfor i in range(t):\n n=int(input())\n lst=list(map(int,input().split()))\n lst.sort()\n if n==1:\n print(lst[0])\n elif n==2:\n print(lst[1])\n elif n==3:\n if lst[0]+lst[1]<=lst[2]:\n print(lst[2])\n else:\n print(lst[0]+lst[1])\n elif n==4:\n if lst[3]>=lst[1]+lst[0]+lst[2]:\n print(lst[3])\n else:\n if lst[0]==lst[1]==lst[2]==lst[3]:\n print(2*lst[0])\n else:\n print(lst[3]+max(lst[0],(lst[1]-lst[3]+lst[2])))\n \n \n \n", "# cook your dish here\nt=int(input())\nfor i in range(t):\n n=int(input())\n lst=list(map(int,input().split()))\n lst.sort()\n if n==1:\n print(lst[0])\n elif n==2:\n print(lst[1])\n elif n==3:\n if lst[0]+lst[1]<=lst[2]:\n print(lst[2])\n else:\n print(lst[0]+lst[1])\n elif n==4:\n if lst[3]>=lst[1]+lst[0]+lst[2]:\n print(lst[3])\n else:\n if lst[0]==lst[1]==lst[2]==lst[3]:\n print(2*lst[0])\n else:\n print(lst[0]+lst[1]+lst[2])\n \n \n \n", "# cook your dish here\nt=int(input())\nfor i in range(t):\n n=int(input())\n lst=list(map(int,input().split()))\n lst.sort()\n if n==1:\n print(lst[0])\n elif n==2:\n print(lst[1])\n elif n==3:\n print(lst[0]+lst[2])\n elif n==4:\n print(max((lst[0]+lst[3]),(lst[1]+lst[2])))\n", "# cook your dish here\nt=int(input())\nfor i in range(t):\n n=int(input())\n lst=list(map(int,input().split()))\n lst.sort()\n if n==1:\n print(lst[0])\n elif n==2:\n print(lst[1])\n elif n==3:\n print(lst[0]+lst[2])\n else:\n print(max((lst[0]+lst[3]),(lst[1]+lst[2])))\n", "# cook your dish here\nt=int(input())\nfor _ in range(t):\n a=int(input())\n l=list(map(int,input().split()))\n l1=sorted(l)\n if len(l)==1:\n print(l[0])\n elif len(l)==2:\n print(max(l1[1],l1[0]))\n else:\n x=0\n k=l1[0]+l1[1]\n for i in range(2,len(l1)):\n x=x+(l1[i]-l1[i-1])\n print(k+x)\n \n \n", "t=int(input(\"\"))\nfor _ in range(t):\n n=int(input(\"\"))\n l=list(map(int,input(\"\").strip().split()))[:n]\n l.sort(reverse=True)\n b1=b2=0\n for i in l:\n if b1<b2:\n b1+=i\n else:\n b2+=i\n print(max(b1,b2))", "t=int(input())\nwhile t:\n n=int(input())\n dish=list(map(int,input().split()))\n b0,b1=0,0 \n mins=0 \n dish.sort(reverse=True)\n for i in dish:\n if b0<=b1:\n b0=b0+i\n else:\n b1=b1+i\n print(max(b0,b1))\n t-=1", "t=int(input())\nwhile t:\n n=int(input())\n dish=list(map(int,input().split()))\n b0,b1=0,0 \n mins=0 \n dish.sort(reverse=True)\n for i in dish:\n if b0<=b1:\n b0=b0+i\n else:\n b1=b1+i\n print(max(b0,b1))\n t-=1", "def main():\n t=int(input())\n while(t):\n n=int(input())\n list1=list(map(int,input().split()))\n list1.sort(reverse=True)\n b0=0\n b1=0\n for i in list1:\n if b0<=b1:\n b0+=i\n else:\n b1+=i\n print(max(b0,b1))\n t=t-1\n \nmain()\n", "t=int(input())\nwhile t:\n n=int(input())\n dish=list(map(int,input().split()))\n b0,b1=0,0 \n mins=0 \n dish.sort(reverse=True)\n for i in dish:\n if b0<=b1:\n b0=b0+i\n else:\n b1=b1+i\n print(max(b0,b1))\n t-=1", "try:\n t=int(input())\n for _ in range(t):\n c=0\n n=int(input())\n a=list(map(int,input().split()))\n a.sort(reverse=True)\n\n b=c=0\n for i in a:\n if(b<c):\n b+=i\n else:\n c+=i\n print(max(b,c))\n\nexcept:\n pass", "\nfor t in range(int(input())):\n \n n=int(input())\n a=list(map(int,input().split()))\n a.sort(reverse=True)\n b=c=0\n for i in a:\n if(b<c):\n b+=i\n else:\n c+=i\n print(max(b,c))", "# cook your dish here\nfor _ in range(int(input())):\n n=int(input())\n a=list(map(int,input().split()))\n a.sort()\n if(n==1):\n print(a[0])\n elif(n==2):\n print(max(a[0],a[1]))\n else:\n b=a[n-1]\n c=a[n-2]\n for i in range(n-3,-1,-1):\n if(c<b):\n c+=a[i]\n else:\n b+=a[i]\n if(c<b):\n print(b)\n else:\n print(c)\n", "# cook your dish here\nt=int(input())\nfor _ in range(t):\n c=0\n n=int(input())\n a=list(map(int,input().split()))\n a.sort(reverse=True)\n b=c=0\n for i in a:\n if(b<c):\n b+=i\n else:\n c+=i\n print(max(b,c))", "# cook your dish here\ntry: \n t = int(input())\nexcept:\n t = 0\nfor i in range(t):\n n = int(input())\n l = list(map(int,input().split()))\n l.sort(reverse=True)\n b1=b2=0\n for i in l:\n if(b1<b2):\n b1+=i\n else:\n b2+=i\n print(max(b1,b2))", "# cook your dish here\nfor i in range(int(input())):\n n=int(input())\n l=list(map(int,input().split()))\n l.sort()\n len1=len(l)\n a=l[len1-1]\n b=l[len1-2]\n len1-=2\n sum=0\n c=0\n for j in range(n-1):\n if l[j]!=l[j+1]:\n c=1\n if c==0:\n if n%2!=0:\n n=(n//2)+1\n print(n*l[0])\n else:\n n=n//2\n print(n*l[0])\n else:\n while(len1>=0):\n if len1==0:\n z=max(a,b)\n sum+=z\n break\n else:\n z=min(a,b)\n sum+=z\n len1-=1\n if a<b:\n a=l[len1]\n b=b-z\n else:\n b=l[len1]\n a=a-z\n print(sum)\n \n \n \n", "# cook your dish here\n# cook your dish here\nfor i in range(int(input())):\n N=int(input())\n C=list(map(int,input().split()))\n C.sort(reverse=True)\n b1=b2=0\n for i in range(N):\n if b1<b2:\n b1+=C[i]\n else:\n b2+=C[i]\n print(max(b1,b2))", "t = int(input())\noutput = []\n\nfor _ in range(t):\n n = int(input())\n\n c = list(map(int, input().split()))\n c.sort(reverse=True)\n\n burner1 = 0\n burner2 = 0\n\n for x in range(n):\n if burner1 < burner2:\n burner1 += c[x]\n else:\n burner2 += c[x]\n\n output.append(str(max(burner1,burner2)))\n\nprint('\\n'.join(output))", "def get_mini(n, ls):\n ls = sorted(ls)[::-1]\n first_burner = 0\n second_burner = 0\n for i in range(n):\n if first_burner <= second_burner:\n first_burner += ls[i]\n else:\n second_burner += ls[i]\n return max(first_burner, second_burner)\n\n\nt = int(input())\nfor _ in range(t):\n n = int(input())\n dish = list(map(int, input().split()))\n ans = get_mini(n, dish)\n print(ans)", "# cook your dish here\nfor i in range(int(input())):\n N=int(input())\n C=list(map(int,input().split()))\n C.sort(reverse=True)\n b1=b2=0\n for i in range(N):\n if b1<b2:\n b1+=C[i]\n else:\n b2+=C[i]\n print(max(b1,b2))", "t = int(input())\nd = []\nfor i in range(t):\n n = int(input())\n d.append(list(map(int, input().split())))\n\noutput = []\nfor arr in d:\n arr.sort(reverse=True)\n time = 0\n i = 0\n t = 0\n while i < len(arr):\n if t == 0:\n time += arr[i]\n t = arr[i]\n i += 1\n if i >= len(arr):\n break\n if arr[i] <= t:\n t -= arr[i]\n arr[i] = 0\n else:\n arr[i] -= t\n t = 0\n output.append(time)\n\nfor i in output:\n print(i)"]
{"inputs": [["3", "3", "2 2 2", "3", "1 2 3", "4", "2 3 4 5"]], "outputs": [["4", "3", "7"]]}
INTERVIEW
PYTHON3
CODECHEF
7,782
0d13820350e5a00218d41909e415f473
UNKNOWN
A long way back I have taken $5000 from Golu when I used to live in Jodhpur. Now, time has passed and I am out of Jodhpur. While Golu still in Jodhpur, one day called me and asked about his money. I thought of giving Golu a chance. I told him that he can still take his money back if he reaches my home anyhow just in 2 days but not after that. In excitement he made his way toward my hometown i.e. Gorakhpur. To cover up the petrol cost he started giving paid lift to whoever needs it throughout the way in order to earn some money. Help him to get the maximum profit. His car has a capacity of k + 1 person, so in a certain moment he can transport k persons (and himself). From Jodhpur to Gorakhpur, there are l localities (cities, towns, villages), Jodhpur being the first and Gorakhpur being the lth. There are n groups of lift takers along the road. The ith group consists of pi persons, wants to travel from locality si to locality di and will pay an amount of mi money. A group must be taken into the car as a whole. Assume that lift takers are found only in localities. Restrictions • 1 ≤ k ≤ 7 • 1 ≤ l ≤ 1000000 • 1 ≤ n ≤ 50 • 1 ≤ pi ≤ k • 1 ≤ si ≤ l – 1 • 2 ≤ di ≤ l • si < di • 1 ≤ mi ≤ 1000000 -----Input----- The first line of the input contains the number of test cases. The first line of each test case contains the numbers n, l and k separated by a single space. n lines follow, the ith line containing pi, si, di and mi separated by a single space. -----Output----- For each test case output a single line containing the maximum amount of money Golu can earn. -----Example----- Input: 2 5 5 4 2 1 5 50 1 2 4 20 2 3 4 40 2 4 5 50 3 4 5 80 10 10 5 2 5 10 17300 2 1 8 31300 5 4 10 27600 4 8 10 7000 5 9 10 95900 2 7 10 14000 3 6 10 63800 1 7 10 19300 3 8 10 21400 2 2 10 7000 Output: 140 127200 By: Chintan, Asad, Ashayam, Akanksha
["'''Well I found the bug, but I don't understand why it was doing that. I mean, as\nfar as I can tell, it shouldn't be a bug!\nNote to self: deleting from (supposedly) local lists through recursion is dangerous!'''\n\nclass Group(object):\n def __init__(self,size,start,end,value):\n self.size = size\n self.start = start\n self.end = end\n self.value = value\n \n def __lt__(self,other):\n return self.start < other.start\n \n def __str__(self):\n return \"%i: %i->%i, $%i\" %(self.size,self.start,self.end,self.value)\n \n \ndef hash(car,i):\n people = []\n for group in car:\n people.extend([group.end]*group.size)\n people.sort()\n return tuple(people+[i])\n \n \ndef optimize(groups,car,capacity,i): \n if i == len(groups):\n return 0\n \n newcar = []\n pos = groups[i].start\n for group in car:\n if group.end > pos:\n newcar.append(group)\n else:\n capacity += group.size\n \n state = hash(newcar,i)\n try:\n return memo[state]\n except:\n v = optimize(groups,newcar,capacity,i+1) \n if groups[i].size <= capacity:\n w = optimize(groups,newcar+[groups[i]],capacity-groups[i].size,i+1) + groups[i].value\n else:\n w = 0\n \n if v > w:\n ie[state] = -1\n elif v < w:\n ie[state] = 1\n else:\n ie[state] = 0\n \n ans = max(v,w)\n memo[state] = ans\n return ans\n \ncases = int(input())\nfor case in range(cases):\n memo = {}\n ie = {}\n groups = []\n n,_,capacity = list(map(int,input().split()))\n \n for g in range(n):\n size,start,end,value = list(map(int,input().split()))\n groups.append(Group(size,start,end,value))\n groups.sort()\n print(optimize(groups,[],capacity,0))"]
{"inputs": [["2", "5 5 4", "2 1 5 50", "1 2 4 20", "2 3 4 40", "2 4 5 50", "3 4 5 80", "10 10 5", "2 5 10 17300", "2 1 8 31300", "5 4 10 27600", "4 8 10 7000", "5 9 10 95900", "2 7 10 14000", "3 6 10 63800", "1 7 10 19300", "3 8 10 21400", "2 2 10 7000"]], "outputs": [["140", "127200", "By:", "Chintan, Asad, Ashayam, Akanksha"]]}
INTERVIEW
PYTHON3
CODECHEF
1,944
604e20f027baa2fa94aac42153865843
UNKNOWN
Polo, the Penguin, likes numbers. He says that the goodness of a number is itself multiplied by the number of digits in it's decimal representation. For example, the goodness of the integer 474 is 474*3 = 1422. Help him to count the sum of goodness of all integers from L to R, inclusive. Since the answer can be too large, output it modulo 1,000,000,007 (10^9+7). -----Input----- The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows. The only line of each test case contains the pair of integers L and R, separated by a single space. -----Output----- For each test case, output a single line containing the answer to the corresponding test case. -----Constraints----- - 1 ≤ T ≤ 1,000 - 1 ≤ L ≤ R ≤ 1,000,000,000 (10^9) -----Example----- Input: 1 9 12 Output: 75 -----Explanation----- Example case 1. The answer is 9*1 + 10*2 + 11*2 + 12*2 = 75.
["# cook your dish here\nfrom sys import stdin\nfrom math import sqrt,ceil,log10\ndef get_sum(a,b,digits):\n sum=((b+a)*(b-a+1))//2\n return sum*digits\n\ndef solve():\n mod=10**9+7\n thehighlimiter={i: 10 ** i - 1 for i in range(12)}\n thelowlimiter={i: 10**i for i in range(12)}\n for _ in range(int(input())):\n l,r=map(int, stdin.readline().strip().split())\n low=len(str(l))\n high=len(str(r))\n ans=0\n if low==high:\n ans=get_sum(l,r,low)\n else:\n ans+=get_sum(l,((10**low)-1),low)\n ans+=get_sum((10**(high-1)),r,high)\n for i in range(low+1,high):\n ans+=get_sum(10**(i-1),(10**i)-1,i)\n print(ans%mod)\n\ndef __starting_point():\n solve()\n\n__starting_point()", "m = 10**9 + 7\ndef get_sum(a, b, digits):\n sum = ((b + a) * (b - a + 1)) // 2\n return sum * digits\nfor _ in range(int(input())):\n l, r = map(int,input().split())\n l_digits = len(str(l))\n r_digits = len(str(r))\n if(l_digits == r_digits):\n ans = get_sum(l, r, l_digits)\n else:\n ans = (get_sum(l, ((10 ** l_digits) - 1), l_digits) + get_sum((10 ** (r_digits - 1)), r, r_digits))\n for i in range(l_digits + 1, r_digits):\n ans += get_sum(10 ** (i - 1), (10 ** i) - 1, i) \n print(ans%m)", "t = int(input()) #number of test cases\nmod = 1000000007\n\ndef get_sum(a, b, digits):\n sum = ((b + a) * (b - a + 1)) // 2\n return sum * digits\n\nfor _ in range(t):\n l, r = [int(x) for x in input().split()]\n l_digits = len(str(l))\n r_digits = len(str(r))\n ans = 0\n if(l_digits == r_digits):\n ans = get_sum(l, r, l_digits)\n else:\n ans += get_sum(l, ((10 ** l_digits) - 1), l_digits)\n ans += get_sum((10 ** (r_digits - 1)), r, r_digits)\n for i in range(l_digits + 1, r_digits):\n ans += get_sum(10 ** (i - 1), (10 ** i) - 1, i)\n \n print(ans%mod)", "def len(n):\r\n x=0\r\n while n>0:\r\n x+=1\r\n n=n//10\r\n return x\r\ne=10**9+7\r\nt=int(input())\r\n#l=[0]\r\n#for i in range(1,10**7):\r\n #l.append((l[-1]+i*len(i))%e)\r\n\r\nf=[0]\r\na=9\r\nb=1\r\nfor i in range(10):\r\n x=(2*b+a-1)%e\r\n x=(x*a)%e\r\n y=pow(2,e-2,e)\r\n x=(x*y)%e\r\n x=(x*(i+1))%e\r\n x=(x+f[-1])%e\r\n b*=10\r\n a*=10\r\n \r\n f.append(x)\r\n#print(f)\r\ndef ans(n):\r\n if n==0:\r\n return 0\r\n x=len(n)\r\n y = f[x-1]\r\n a=pow(10,x-1,e)\r\n b=((n+a)*(n-a+1))%e\r\n b =(b*pow(2,e-2,e))%e\r\n b=(b*x)%e\r\n #print(y,b,n)\r\n return (b+y)%e\r\n \r\n \r\nfor _ in range(t):\r\n a,b=map(int,input().split())\r\n #print(l[b]-l[a-1])\r\n b = ans(b)\r\n a=ans(a-1)\r\n print((b-a)%e)\r\n \r\n", "\nt = int(input())\n\nfor i in range(t):\n\n l,r = map(int,input().split())\n start = len(str(l))\n end = len(str(r))\n if end>start:\n end_start = int(str('9'*start))\n sum_start = ((end_start + l)*start*((end_start-l+1)))//2\n else:\n sum_start = ((l+r)*start*(r-l+1))//2\n\n\n sum = 0\n\n # print(sum_start)\n for j in range(start+1,end):\n sum+=((10**(j-1)+(int(str('9'*j))))*j*(((int(str('9'*j))-(10**(j-1))+1))))//2\n\n if end>start:\n end = len(str(r))\n end__start = int(str(10**(end-1)))\n sum__start = ((end__start + r)*end*(r-end__start+1))//2\n else:\n sum__start = 0\n # print(end__start)\n # print(sum)\n # print(sum,sum__start,sum_start)\n print((sum+sum__start+sum_start)%1000000007)\n\n"]
{"inputs": [["1", "9 12", "", ""]], "outputs": [["75"]]}
INTERVIEW
PYTHON3
CODECHEF
3,572
d367ea749949b35eef2a0d50c5047405
UNKNOWN
There were $N$ students (numbered $1$ through $N$) participating in the Indian Programming Camp (IPC) and they watched a total of $K$ lectures (numbered $1$ through $K$). For each student $i$ and each lecture $j$, the $i$-th student watched the $j$-th lecture for $T_{i, j}$ minutes. Additionally, for each student $i$, we know that this student asked the question, "What is the criteria for getting a certificate?" $Q_i$ times. The criteria for getting a certificate is that a student must have watched at least $M$ minutes of lectures in total and they must have asked the question no more than $10$ times. Find out how many participants are eligible for a certificate. -----Input----- - The first line of the input contains three space-separated integers $N$, $M$ and $K$. - $N$ lines follow. For each valid $i$, the $i$-th of these lines contains $K+1$ space-separated integers $T_{i, 1}, T_{i, 2}, \ldots, T_{i, K}, Q_i$. -----Output----- Print a single line containing one integer — the number of participants eligible for a certificate. -----Constraints----- - $1 \le N, K \le 1,000$ - $1 \le M \le 10^6$ - $1 \le Q_i \le 10^6$ for each valid $i$ - $1 \le T_{i, j} \le 1,000$ for each valid $i$ and $j$ -----Example Input----- 4 8 4 1 2 1 2 5 3 5 1 3 4 1 2 4 5 11 1 1 1 3 12 -----Example Output----- 1 -----Explanation----- - Participant $1$ watched $1 + 2 + 1 + 2 = 6$ minutes of lectures and asked the question $5$ times. Since $6 < M$, this participant does not receive a certificate. - Participant $2$ watched $3 + 5 + 1 + 3 = 12$ minutes of lectures and asked the question $4$ times. Since $12 \ge M$ and $4 \le 10$, this participant receives a certificate. - Participant $3$ watched $1 + 2 + 4 + 5 = 12$ minutes of lectures and asked the question $11$ times. Since $12 \ge M$ but $11 > 10$, this participant does not receive a certificate. - Participant $4$ watched $1 + 1 + 1 + 3 = 6$ minutes of lectures and asked the question $12$ times. Since $6 < M$ and $12 > 10$, this participant does not receive a certificate. Only participant $2$ receives a certificate.
["N,M,K=map(int,input().split())\nc=0\nfor i in range(N):\n T=list(map(int,input().split()))\n Q=T[-1]\n T.pop(-1)\n if Q<=10 and sum(T)>=M:\n c+=1\nprint(c)", "n,m,k=map(int,input().split())\na=0\nfor i in range(n):\n t=list(map(int,input().split()))\n q=t[-1]\n t.pop(-1)\n if q<=10 and sum(t)>=m:\n a+=1\nprint(a)", "a,b,c=map(int,input().split())\nn=0\nfor i in range(a):\n t=list(map(int,input().split()))\n d=t[-1]\n t.pop(-1)\n if d<=10 and sum(t)>=b:\n n+=1\nprint(n)", "# cook your dish here\nn,m,k=map(int,input().split())\ncondit=0\nfor _ in range(n):\n l=list(map(int,input().split()))\n a=0\n for i in range(len(l)-1):\n a+=l[i]\n if a>=m and l[len(l)-1]<11:\n condit+=1\n \nprint(condit)", "N,M,K=list(map(int,input().split()))\nc=0\nfor i in range(N):\n T=list(map(int,input().split()))\n Q=T[-1]\n T.pop(-1)\n if Q<=10 and sum(T)>=M:\n c+=1\nprint(c)\n", "N,M,K=map(int,input().split())\nc=0\nfor i in range(K):\n T=list(map(int,input().split()))[:K+1]\n Q=T[-1]\n T.remove(T[-1])\n if Q<=10:\n if sum(T)>=M:\n c+=1\nprint(c)", "count=0\ninp=input().split(\" \")\ninp=[int(x) for x in inp]\nwhile inp[0]!=0 :\n t=input().split(\" \")\n t=[int(x) for x in t]\n s=sum(t)-t[-1]\n if s>=inp[1] and t[-1]<=10 :\n count+=1\n inp[0]-=1\nprint(count)", "n,m,k=input().split(\" \")\nl=[] \nc1=0\nwhile(int(n)>0): \n s=0\n l=input().split(\" \")\n for i in range(0,int(k)):\n s=s+int(l[i])\n if(s>=int(m) and int(l[-1])<=10):\n c1=c1+1 \n n=int(n)-1\nprint(c1)\n\n", "# cook your dish here\nn,m,k=map(int,input().split())\nco=0\nfor i in range(n):\n l=list(map(int,input().split()))\n s=0\n for j in range(k):\n s=s+l[j]\n if s>=m and l[k]<=10:\n co=co+1\nprint(co)", "storage = list(input().split(' '))\ncount = 0\nfor j in range(int(storage[0])):\n n = list(input().split(' '))\n flag1 = False\n flag2 = False\n sum = 0\n for k in range(int(storage[2])):\n sum += int(n[k])\n if int(storage[1]) <= sum:\n flag1 = True\n if int(n[-1]) <= 10:\n flag2 = True\n if flag1:\n if flag2:\n count+=1\nprint(count)\n", "# cook your dish here\nn,m,k = map(int,input().split())\narr = []\nfor i in range(n):\n arr.append(list(map(int,input().split())))\n\ncnt = 0\nfor i in range(n):\n tot = sum(arr[i])\n q = arr[i][-1]\n tot -= q\n if tot >= m and q <= 10:\n cnt += 1\n\nprint(cnt)", "N, M, K = map(int, input().split())\ncnt = 0\nwhile N:\n *T, Q = map(int,input().split())\n if sum(T) >= M and Q < 11:\n cnt += 1 \n N -= 1\nprint(cnt)", "N, M, K = map(int, input().split())\ncnt = 0\nwhile N:\n *T, Q = map(int,input().split())\n if sum(T) >= M and Q < 11:\n cnt += 1 \n N -= 1\nprint(cnt)", "N, M, K = map(int, input().split())\ncnt = 0\nwhile N:\n *T, Q = map(int,input().split())\n if sum(T) >= M and Q < 11:\n cnt += 1 \n N -= 1\nprint(cnt)", "\nn,m,k=map(int,input().split())\nc=0\nfor i in range(n):\n l=list(map(int,input().split()))\n r=l[:k]\n if sum(r)>=m and l[-1]<=10:\n c+=1\nprint(c)", "N,M,K=list(map(int,input().split()))\ns=0\ncerti=0\nfor i in range(N):\n l=[]\n l=list(map(int,input().split()))\n s=sum(l)-l[-1]\n if s>=M and l[-1]<=10:\n certi+=1\n\n \nprint(certi)# cook your dish here\n", "N,M,K=list(map(int,input().split()))\ns=0\ncerti=0\nfor i in range(N):\n l=[]\n l=list(map(int,input().split()))\n s=sum(l)-l[-1]\n if s>=M and l[-1]<=10:\n certi+=1\n\n \nprint(certi)# cook your dish here\n", "inputs = list(map(int, input().split()))\nn = inputs[0]\nm = inputs[1]\nk = inputs[2]\ncnt=0\nfor _ in range(0,n):\n arr = list(map(int, input().split()))\n ques = arr[len(arr)-1]\n s=sum(arr)-ques\n if s<m:\n continue\n else:\n if ques<=10:\n cnt=cnt+1\nprint(cnt)\n\n\n", "# cook your dish here\n(n,m,k)=list(map(int,input().split()))\nlec=[]\nque=[]\nfor i in range(n):\n l=list(map(int,input().split()))\n que.append(l[-1])\n lec.append(sum(l)-l[-1])\nstu=0\nfor i in range(n):\n if lec[i]>=m and que[i]<=10:\n stu+=1\n i+=1\nprint(stu)\n\n", "# cook your dish here\nn, m, k = map(int, input().split())\nans = 0\nfor i in range(n):\n temp = list(map(int, input().split()))\n su = 0\n for j in range(k):\n su += temp[j]\n \n if(su >= m and temp[-1] <= 10):\n ans += 1\n \nprint(ans)", "# cook your dish here\nn,m,k = map(int,input().split())\nc = 0\nfor i in range(n):\n l = list(map(int,input().split()))\n s = sum(l)-l[-1]\n if s >= m and l[-1] <= 10:\n c += 1\nprint(c)", "# -*- coding: utf-8 -*-\n\"\"\"\nCreated on Sat Oct 3 14:08:49 2020\n\n@author: Vineet\n\"\"\"\ntry:\n\n \n \n \n n,m,k=list(map(int,input().split()))\n count=0\n for i in range(0,n):\n list1=list(map(int,input().split()[:k+1]))\n Sum=sum(list1[:k])\n \n if Sum>=m and list1[-1]<=10:\n count+=1\n else:\n continue\n print(count)\n\n \n \n \n \n\n \nexcept:\n pass\n", "n,m,k =list(map(int,input().split()))\nmat = []\nfor _ in range(n):\n arr = list(map(int,input().split()))\n mat.append(arr)\n\n\ncount=0\nfor i in range(n):\n curr = 0\n for j in range(k):\n curr+=mat[i][j]\n if mat[i][-1]<=10 and curr>=m:\n count+=1\n \nprint(count)\n \n# cook your dish here\n", "# cook your dish here\nn,m,k=map(int,input().split())\nc=0\nfor i in range(n):\n t=list(map(int,input().split()))\n if t[-1]<=10 and sum(t)-t[-1]>=m:\n c+=1 \nprint(c)", "# cook your dish here\nn, m, k = map(int, input().split())\nT = []\n\nfor i in range(n):\n temp = list(map(int, input().split()))\n T.append(temp)\n \nans = 0\nfor i in range(n):\n watchTime = 0; Ques = T[i][k]\n for j in range(k):\n watchTime += T[i][j]\n if(watchTime >= m and Ques <= 10):\n ans += 1\n \nprint(ans)"]
{"inputs": [["4 8 4", "1 2 1 2 5", "3 5 1 3 4", "1 2 4 5 11", "1 1 1 3 12"]], "outputs": [["1"]]}
INTERVIEW
PYTHON3
CODECHEF
5,515
c3c5628657311497df467e1c866f5ef7
UNKNOWN
Sumit and Dhiraj are roommates in a hostel of NIT Jamshedpur,One day after completing there boring assignments of Artificial Intelligence, they decided to play a game as it was dhiraj,s idea to play a game so he started explaining the rules of the game to sumit. So the game was as follows-They randomly took a number N after that they find all its divisors.Suppose first sumit took a divisor then dhiraj and so on.The player who will be having the last divisor with him will win the game.Rohit their mutual friend,was observing them play. Can you help Rohit predict the outcome of game? If Sumit wins print "YES" without quotes and "NO" without quotes, if Dhiraj wins the game. -----Input----- Input starts with an integer T denoting the number of test cases Each test case starts with a line containing an integer N the number. -----Output----- Outcome of each game in a separate line -----Constraints----- - 1 ≤ T ≤ 10^3 - 1 ≤ N ≤ 10^18 -----Sub tasks----- - Subtask #1:(10 points) - 1 ≤ T ≤ 10 - 1 ≤ N ≤ 103 - Subtask #2:(25 points) - 1 ≤ T ≤ 50 - 1 ≤ N ≤ 1016 - Subtask #3:(65 points) - 1 ≤ T ≤ 103 - 1 ≤ N ≤ 1018 -----Example----- Input: 2 4 5 Output: YES NO
["import math\nfor t in range(int(input())):\n n = int(input())\n temp = math.sqrt(n)\n if (temp == int(temp)):\n print(\"YES\")\n else:\n print(\"NO\")", "t=int(input());\nfor i in range (0,t):\n c=0;\n n=int(input());\n for j in range (1,n+1):\n if(n%j==0):\n c=c+1;\n if(c%2==0):\n print(\"NO\\n\");\n else:\n print(\"YES\\n\");", "from functools import reduce\ndef get_prime_factors(number):\n if number == 1:\n return []\n\n for i in range(2, number):\n # Get remainder and quotient\n rd, qt = divmod(number, i)\n if not qt: # if equal to zero\n return [i] + get_prime_factors(rd)\n\n return [number]\n\nT = int(input())\n\nfor j in range(T):\n n = int(input())\n divisors = get_prime_factors(n)\n #print divisors\n \n count = [1 for x in range(len(divisors))] \n for i in range(len(divisors)):\n while n%divisors[i] == 0:\n count[i]=count[i]+1\n n=n/divisors[i]\n \n # print count\n num = reduce(lambda x, y: x*y, count)\n\n if num%2==0:\n print(\"NO\")\n else:\n print(\"YES\")\n \n", "def main():\n t = eval(input())\n for i in range(0,t):\n count = 0\n n = eval(input())\n for j in range(1,n+1):\n if n%j == 0:\n count +=1\n if count%2 == 0:\n print(\"NO\\n\")\n else :\n print(\"YES\\n\")\nmain()\n", "import math\ndef is_square(integer):\n root = math.sqrt(integer)\n if int(root + 0.5) ** 2 == integer: \n return \"YES\"\n else:\n return \"NO\"\nfor i in range(eval(input())):\n n=eval(input())\n print(is_square(n))\n", "from functools import reduce\ndef factors(n): \n return set(reduce(list.__add__, \n ([i, n//i] for i in range(1, int(n**0.5) + 1) if n % i == 0)))\nt=eval(input())\nwhile(t):\n leng = 0\n t = t - 1\n m = eval(input())\n leng = len(factors(m))\n if(leng%2):\n print(\"YES\")\n else:\n print(\"NO\")\n", "from math import sqrt\nfor t in range(int(input())):\n n=int(input())\n if int(sqrt(n))==float(sqrt(n)):\n print(\"YES\")\n else:\n print(\"NO\")", "import math\nT= int(input())\n\nfor t in range(T):\n s =set()\n n = int(input())\n for i in range(1,int(math.sqrt(n))+1):\n if n%i==0:\n s.add(i)\n s.add(n/i)\n if len(s)%2!=0:\n print(\"YES\")\n else:\n print(\"NO\")", "t=int(input())\nc=0\nwhile (t):\n n=int(input())\n for i in range(1,n):\n if n%i==0:\n c+=1\n \n if c%2==0:\n print(\"YES\\n\")\n else:\n print(\"NO\\n\")\n c=0\n t=t-1", "def divisors(n):\n count=2 # accounts for 'n' and '1'\n i=2\n while(i**2 < n):\n if(n%i==0):\n count+=2\n i+=1\n count+=(1 if i**2==n else 0)\n return count \nT = int(input())\nfor t in range(T):\n n = int(input())\n d = divisors(n)\n if d%2!=0:\n print(\"YES\")\n else:\n print(\"NO\")", "from math import sqrt\nfor _ in range(int(input())):\n n = int(input())\n r = int(sqrt(n))\n print(\"YES\" if r * r == n else \"NO\")", "for __ in range(eval(input())) :\n n = eval(input())\n k = n**0.5\n if int(k)*int(k) == n :\n print(\"YES\")\n else :\n print(\"NO\")\n", "t=eval(input())\nwhile t:\n r=0\n n=eval(input())\n for i in range(1,n+1):\n if n%i==0:\n r=r+1\n if r%2==1:\n print(\"YES\")\n else:\n print(\"NO\")\n t=t-1", "from math import *\nt=int(input())\nwhile t:\n n=int(input())\n p=sqrt(n)\n if p*p==n:\n print(\"YES\")\n else:\n print(\"NO\")\n t-=1", "import math\n#Good_one\ndef is_square(integer):\n root = math.sqrt(integer)\n if int(root + 0.5) ** 2 == integer: \n return True\n else:\n return False\nfor KK_KK in range(eval(input())):\n\n a=eval(input())\n k=is_square(a)\n if k==True:\n print(\"YES\")\n else:\n print(\"NO\")\n \n", "import math\n# Source Stack Overflow :p\ndef divisorGenerator(n):\n large_divisors = []\n for i in range(1, int(math.sqrt(n) + 1)):\n if n % i == 0:\n yield i\n if i*i != n:\n large_divisors.append(n / i)\n for divisor in reversed(large_divisors):\n yield divisor\n\n \n \n #return len(k)\nfor KK_KK in range(eval(input())):\n\n a=eval(input())\n k= list(divisorGenerator(a))\n #print k\n if len(k)%2==0:\n print(\"NO\")\n else:\n print(\"YES\")\n", "import math\nfor t in range(int(input())):\n n = int(input())\n i = 1\n count = 0\n x = math.sqrt(n)\n while (i<=x):\n if (n%i==0):\n count+=1\n if (i!=n/i):\n count+=1\n i+=1\n if (count%2==0):\n print(\"NO\")\n else:\n print(\"YES\")", "for t in range(int(input())):\n n = int(input())\n i = 1\n count = 0\n while (i*i<=n):\n if (n%i==0):\n temp = n/i\n if (i==temp):\n count+=1\n else:\n count+=2\n i+=1\n if (count%2==0):\n print(\"NO\")\n else:\n print(\"YES\")", "import math\n\nt=int(input())\nfor i in range(t):\n n=int(input())\n sq=int(math.sqrt(n))\n if sq*sq==n:\n print(\"YES\")\n else:\n print(\"NO\")"]
{"inputs": [["2", "4", "5"]], "outputs": [["YES", "NO"]]}
INTERVIEW
PYTHON3
CODECHEF
4,619
7aa325701fab00159aecd916b5de553c
UNKNOWN
You are given an array of integers [A1,A2,…,AN]$[A_1, A_2, \ldots, A_N]$. Let's call adding an element to this array at any position (including the beginning and the end) or removing an arbitrary element from it a modification. It is not allowed to remove an element from the array if it is empty. Find the minimum number of modifications which must be performed so that the resulting array can be partitioned into permutations. Formally, it must be possible to partition elements of the resulting array into zero or more groups (multisets; not necessarily identical) in such a way that each element belongs to exactly one group and for each group, if it contains L$L$ elements, then it must contain only integers 1$1$ through L$L$, each of them exactly once. -----Input----- - The first line of the input contains a single integer T$T$ denoting the number of test cases. The description of T$T$ test cases follows. - The first line of each test case contains a single integer N$N$. - The second line contains N$N$ space-separated integers A1,A2,…,AN$A_1, A_2, \ldots, A_N$. -----Output----- For each test case, print a single line containing one integer ― the minimum required number of modifications. -----Constraints----- - 1≤T≤1,000$1 \le T \le 1,000$ - 1≤N≤106$1 \le N \le 10^6$ - 1≤Ai≤109$1 \le A_i \le 10^9$ for each valid i$i$ - the sum of N$N$ over all test cases does not exceed 106$10^6$ -----Subtasks----- Subtask #1 (50 points): - 1≤N≤1,000$1 \le N \le 1,000$ - the sum of N$N$ over all test cases does not exceed 10,000$10,000$ Subtask #2 (50 points): original constraints -----Example Input----- 2 5 1 4 1 2 2 4 2 3 2 3 -----Example Output----- 1 2
["# cook your dish here\nfor _ in range(int(input())):\n n=int(input());li=list(map(int,input().split()));dli=dict();modi=0\n for i in li:\n if i not in dli:dli[i]=1\n else:dli[i]+=1\n op=sorted(list(dli))\n if(len(dli)!=0):\n while 1:\n tmp=[]\n for i in op:\n if dli[i]==0:continue\n tmp.append(i);dli[i]-=1\n l=len(tmp);mn=l\n for i in range(l):mn=min(mn,tmp[i]-1-i+l-1-i)\n modi+=mn\n if(l==0):break\n print(modi)", "# cook your dish here\nfor _ in range(int(input())):\n n=int(input());li=list(map(int,input().split()));dli=dict();modi=0\n for i in li:\n if i not in dli:dli[i]=1\n else:dli[i]+=1\n op=sorted(list(dli))\n if(len(dli)!=0):\n while 1:\n tmp=[]\n for i in op:\n if dli[i]==0:continue\n tmp.append(i);dli[i]-=1\n l=len(tmp);mn=l\n for i in range(l):mn=min(mn,tmp[i]-1-i+l-1-i)\n modi+=mn\n if(l==0):break\n print(modi)", "for _ in range(int(input())):\n n=int(input());li=list(map(int,input().split()));dli=dict();modi=0\n for i in li:\n if i not in dli:dli[i]=1\n else:dli[i]+=1\n op=sorted(list(dli))\n if(len(dli)!=0):\n while 1:\n tmp=[]\n for i in op:\n if dli[i]==0:continue\n tmp.append(i);dli[i]-=1\n l=len(tmp);mn=l\n for i in range(l):mn=min(mn,tmp[i]-1-i+l-1-i)\n modi+=mn\n if(l==0):break\n print(modi)", "\nfor _ in range(int(input())):\n n = int(input())\n a = list(map(int, input().split()))\n cost = 0\n\n dp = [[] for val in range(2*n+1)]\n cnt = [0]*(n*2+1)\n dp[0].extend( [ 0 for val in range(n*2+1) ])\n\n for val in a:\n if val<=2*n: cnt[val]+=1\n else: cost+=1\n \n for i in range(1, n*2+1):\n rn = n*2//i\n dp[i].extend([ 0 for val in range(rn+1) ])\n for j in range(0, rn+1):\n dp[i][j] = dp[i-1][j] + abs(cnt[i]-j) \n for j in range(rn-1, -1, -1):\n dp[i][j] = min(dp[i][j], dp[i][j+1])\n \n print( cost+min( dp[2*n][0], dp[2*n][1]) )\n\n", "\nfor _ in range(int(input())):\n n = int(input())\n a = list(map(int, input().split()))\n cost = 0\n\n dp = [[] for val in range(2*n+1)]\n cnt = [0]*(n*2+1)\n dp[0].extend([ 0 for val in range(n*2+1) ])\n\n for val in a:\n if val<=2*n: cnt[val]+=1\n else: cost+=1\n \n for i in range(1, n*2+1):\n rn = n*2//i\n for j in range(0, rn+1):\n dp[i].extend( [ dp[i-1][j] + abs(cnt[i]-j) ] )\n for j in range(rn-1, -1, -1):\n dp[i][j] = min(dp[i][j], dp[i][j+1])\n \n print( cost+min( dp[2*n][0], dp[2*n][1]) )\n\n", "for _ in range(int(input())):\n n=int(input())\n li=list(map(int,input().split()))\n li.sort()\n dli=dict()\n modi=0\n #2*n optimiztion \n for i in li:\n if i not in dli:\n dli[i]=li.count(i)\n if(len(dli)!=0):\n while 1:\n tmp=[]\n for i in dli:\n if dli[i]==0:\n continue\n tmp.append(i)\n dli[i]-=1\n l=len(tmp)\n mn=l\n for i in range(l):\n mn=min(mn,tmp[i]-1-i+l-1-i)\n modi+=mn\n if(l==0):\n break\n print(modi)"]
{"inputs": [["2", "5", "1 4 1 2 2", "4", "2 3 2 3"]], "outputs": [["1", "2"]]}
INTERVIEW
PYTHON3
CODECHEF
3,154
7917359c4d92955930ff18508f6444aa
UNKNOWN
Using his tip-top physique, Kim has now climbed up the mountain where the base is located. Kim has found the door to the (supposedly) super secret base. Well, it is super secret, but obviously no match for Kim's talents. The door is guarded by a row of $N$ buttons. Every button has a single number $A_i$ written on it. Surprisingly, more than one button can have the same number on it. Kim recognises this as Soum's VerySafe door, for which you need to press two buttons to enter the password. More importantly, the sum of the two numbers on the buttons you press must be odd. Kim can obviously break through this door easily, but he also wants to know how many different pairs of buttons he can pick in order to break through the door. Can you help Kim find the number of different pairs of buttons he can press to break through the door? Note: Two pairs are considered different if any of the buttons pressed in the pair is different (by position of the button pressed). Two pairs are not considered different if they're the same position of buttons, pressed in a different order. Please refer to the samples for more details. -----Input:----- - The first line contains a single integer $T$, representing the number of testcases. $2T$ lines follow, 2 for each testcase. - For each testcase, the first line contains a single integer $N$, the number of buttons. - The second line of each testcase contains $N$ space-separated integers, $A_1, A_2, \ldots, A_N$, representing the numbers written on each button. -----Output:----- Print a single number, $K$, representing the number of pairs of buttons in $A$ which have an odd sum. -----Subtasks----- For all subtasks, $1 \leq T \leq 10$, $1 \leq N \leq 100000$, and $1 \leq A_i \leq 100000$ for all $A_i$. Subtask 1 [15 points] : $N \leq 2$, There are at most 2 buttons Subtask 2 [45 points] : $N \leq 1000$, There are at most 1000 buttons Subtask 3 [40 points] : No additional constraints. -----Sample Input:----- 3 4 3 5 3 4 2 5 7 1 4 -----Sample Output:----- 3 0 0 -----EXPLANATION:----- This section uses 1-indexing. In the first sample, the buttons are: $[3, 5, 3, 4]$ $A[1] + A[4] = 3 + 4 = 7$ which is odd. $A[2] + A[4] = 5 + 4 = 9$ which is odd. $A[3] + A[4] = 3 + 4 = 7$ which is odd. In total, there are 3 pairs with an odd sum, so the answer is 3. In the second sample, the buttons are: $[5, 7]$. There are no odd pairs, so the answer is $0$. In the third sample, the buttons are: $[4]$. There are no pairs at all, so the answer is $0$.
["# cook your dish here\nfor _ in range(int(input())):\n n=int(input())\n a=list(map(int,input().split()))\n even=[]\n odd=[]\n for i in a:\n if(i & 1):\n even.append(i)\n else:\n odd.append(i)\n print(len(even)*len(odd))", "t=int(input()) \nfor kkk in range(t): \n n=int(input()) \n a=[int(x) for x in input ().split()] \n e=0\n o=0\n for i in range(n): \n if a[i]%2==0: \n e+=1\n else: \n o+=1\n print(e*o)\n", "# cook your dish \nfor _ in range(int(input())):\n x = int(input())\n arr = list(map(int,input().split()))\n count = 0\n if (x ==1):\n print(\"0\")\n else:\n for i in arr:\n if i % 2==0:\n count+=1\n ak = x-count\n print(ak*count)\n", "# cook your dish \nfor _ in range(int(input())):\n x = int(input())\n arr = list(map(int,input().split()))\n count = 0\n if (x ==1):\n print(\"0\")\n else:\n for i in range(x-1):\n if ((arr[i] + arr[-1]) % 2==1 ):\n count +=1\n print(count)\n", "# cook your dish \nfor _ in range(int(input())):\n x = int(input())\n arr = list(map(int,input().split()))\n count = 0\n if (x ==1):\n print(\"0\")\n else:\n for i in range(x-1):\n if ((arr[i] + arr[-1]) % 2==1 ):\n count +=1\n print(count)\n", "# cook your dish here\nfrom collections import Counter\nfor _ in range(int(input())):\n \n n=int(input())\n c=Counter([int(x)%2 for x in input().split()])\n \n print(c[0]*c[1])\n", "for _ in range(int(input())):\n n=int(input())\n a=list(map(int,input().split()))\n odd=0\n even=0\n for i in range(n):\n if a[i]%2==1:\n odd+=1\n even=n-odd\n print(even*odd)", "for _ in range(int(input())):\n N=int(input())\n count=0\n arr=list(map(int,input().split()))\n if(len(arr)==1):\n print(\"0\")\n else:\n for i in range(len(arr)):\n if(arr[i]%2==0):\n for j in range(i+1,len(arr)):\n if(arr[j]%2!=0):\n count+=1\n else:\n for j in range(i+1,len(arr)):\n if(arr[j]%2==0):\n count+=1\n print(count)", "for _ in range(int(input())):\n N=int(input())\n count=0\n arr=list(map(int,input().split()))\n if(len(arr)==1):\n print(\"0\")\n else:\n for i in range(len(arr)):\n if(arr[i]%2==0):\n for j in range(i+1,len(arr)):\n if(arr[j]%2!=0):\n count+=1\n elif(arr[i]%2!=0):\n for j in range(i+1,len(arr)):\n if(arr[j]%2==0):\n count+=1\n print(count)", "for _ in range(int(input())):\n N=int(input())\n count=0\n arr=list(map(int,input().split()))\n if(len(arr)==1):\n print(\"0\")\n else:\n for i in range(len(arr)):\n for j in range(i+1,len(arr)):\n if((arr[i]+arr[j])%2!=0):\n count+=1\n print(count)", "import sys\nimport math\n\ndef main(arr):\n odd,even=0,0 \n \n ans=0\n \n for e in arr:\n if e&1:\n odd+=1 \n else:\n even+=1 \n \n for e in arr:\n \n if e&1:\n ans+=even\n odd-=1 \n else:\n ans+=odd\n even-=1 \n return ans\n\nfor _ in range(int(input())):\n n=int(input())\n arr=list(map(int,input().split()))\n print(main(arr))", "# cook your dish here\nt = int(input())\nfor _ in range(t):\n n = int(input())\n but = list(map(int,input().split()))\n odd = [i%2 for i in but]\n no = odd.count(1)\n ne = odd.count(0)\n ans = no*ne\n print(ans)\n", "t=int(input())\nfor _ in range(t):\n num=int(input())\n l=list(map(int,input().split()))\n even=0\n for i in l:\n if i%2==0:\n even+=1\n odd=num-even\n print(odd*even)", "t = int(input())\nfor _ in range(t):\n input()\n t1 = [int(i) for i in input().strip().split(' ')]\n t1o = 0\n for i in t1:\n if i % 2 == 0:\n t1o += 1\n t1e = len(t1) - t1o\n print(t1e*t1o)", "from itertools import combinations \n\nt = int(input())\nfor _ in range(t):\n n = int(input())\n lst = list(map(int, input().split()))\n a = list(combinations(lst, 2)) \n count = 0\n for i in range(len(a)):\n if sum(a[i]) % 2 != 0:\n count += 1\n print(count)\n", "# cook your dish here\nt = int(input())\nwhile t>0:\n n = int(input())\n a = list(map(int, input().split()))\n cnt = 0\n for i in range(n):\n if a[i]%2!=0:\n cnt = cnt + 1\n ans = n - cnt\n print(ans*cnt)\n t = t-1\n", "T = int(input())\nfor _ in range(T):\n n = int(input())\n l = list(map(int, input().split()))\n even, odd = [], []\n for num in l:\n if num%2 == 0:\n even.append(num)\n else:\n odd.append(num)\n print(len(even)*len(odd))", "# cook your dish here\ntry:\n t=int(input())\n for _ in range(t):\n n=int(input())\n l=list(map(int,input().split()))\n sum,c=0,0\n for i in range(len(l)):\n for j in range(i,len(l)-1):\n sum=sum+l[j]+l[j+1]\n if sum%2!=0:\n c=c+1\n print(c)\nexcept:\n pass", "t=int(input())\nfor i in range(t):\n n=int(input())\n a=list(map(int,input().split()))\n o=0\n e=0\n for j in a:\n if(j%2==0):\n e+=1\n else:\n o+=1\n print(o*e) ", "# cook your dish here\nt=int(input())\nfor i in range(t):\n n=int(input())\n a=list(map(int,input().split()))\n odd=0\n even=0\n for j in a:\n if(j%2==0):\n even+=1\n else:\n odd+=1\n print(odd*even) ", "# cook your dish here\n#BUTTON PAIRS\n\nt = int(input())\nfor i in range(t):\n n = int(input())\n l = list(map(int,input().split()))\n cnte = 0\n cnto = 0\n \n for i in l:\n if i % 2 == 0:\n cnte += 1\n else:\n cnto += 1\n \n res = cnte*cnto\n print(res)\n", "t = int(input())\nwhile t > 0:\n n = int(input())\n lst = list(map(int, input().split()))\n count, count1 = 0, 0\n for i in range(n):\n if lst[i] % 2 == 0:\n count += 1\n else:\n count1 += 1\n print(count * count1)\n\n t -= 1\n"]
{"inputs": [["3", "4", "3 5 3 4", "2", "5 7", "1", "4"]], "outputs": [["3", "0", "0"]]}
INTERVIEW
PYTHON3
CODECHEF
5,371
0eaaf5363a50f639564dc5a5ba18af4c
UNKNOWN
The chef is trying to decode some pattern problems, Chef wants your help to code it. Chef has one number K to form a new pattern. Help the chef to code this pattern problem. -----Input:----- - First-line will contain $T$, the number of test cases. Then the test cases follow. - Each test case contains a single line of input, one integer $K$. -----Output:----- For each test case, output as the pattern. -----Constraints----- - $1 \leq T \leq 100$ - $1 \leq K \leq 100$ -----Sample Input:----- 4 1 2 3 4 -----Sample Output:----- 1 12 3 123 45 6 1234 567 89 10 -----EXPLANATION:----- No need, else pattern can be decode easily.
["# cook your dish here\nfor _ in range(int(input())):\n n = int(input())\n m = n\n x= 1\n for i in range(n):\n for j in range(m):\n print(x, end = '')\n x += 1\n print()\n m -= 1", "# cook your dish here\n\nt=int(input())\nfor i in range(t):\n n=int(input())\n if n==1:\n print(1)\n else:\n count=1\n while(n>0):\n for j in range(1,n+1):\n print(count,end=\"\")\n count+=1\n n-=1\n print()", "# cook your dish here\n# cook your dish here\nfor _ in range(int(input())):\n n=int(input())\n t=n\n s=0\n for i in range(n):\n \n for j in range(n-i):\n t-=1\n s+=1\n print(s,end=\"\") \n print(\"\\r\")\n \n\n\n\n \n ", "t = int(input())\r\nfor _ in range(t):\r\n n = int(input())\r\n k = (n*(n+1))/2\r\n \r\n\r\n\r\n t = 1\r\n for i in range(n):\r\n for j in range(n-i):\r\n print(t,end=\"\")\r\n t+=1\r\n print()\r\n", "# cook your dish here\ntestcases = int(input())\nfor x in range(testcases):\n n = int(input())\n count = 1\n for x in range(n,0,-1):\n for y in range(x,0,-1):\n print(count,end=\"\")\n count+=1\n print()\n", "# cook your dish here\n\nfor _ in range(int(input())):\n n=int(input())\n c=1\n for i in range(n):\n for j in range(n-i):\n print(c,end=\"\")\n c=c+1\n print()\n", "def func(num):\r\n count = 1\r\n for i in range(1, num+1):\r\n for j in range(1, num+2-i):\r\n print(count, end='')\r\n count += 1\r\n print()\r\n\r\n\r\nfor _ in range(int(input())):\r\n num = int(input())\r\n func(num)\r\n", "# cook your dish here\nn=int(input())\nfor _ in range(n):\n m=int(input())\n count=1\n for i in range(m):\n for j in range(1,m+1-i):\n print(count,end=\"\")\n count+=1\n print()\n \n \n ", "# cook your dish here\nfor _ in range(int(input())):\n n = int(input())\n count = 1\n for i in range(n,0,-1):\n for j in range(i):\n print(count,end=\"\")\n count += 1\n print()", "def solve(n):\r\n c= 1\r\n r = list(range(1,n+1))\r\n r.sort(reverse=True)\r\n for i in r:\r\n x = ''\r\n for j in range(i):\r\n x+=str(c)\r\n c+=1\r\n print(x)\r\n\r\ndef main():\r\n t = int(input())\r\n for i in range(t):\r\n n = int(input())\r\n solve(n)\r\n\r\n\r\nmain()\r\n", "def f(n):\r\n line=n\r\n p=1\r\n \r\n while line>0:\r\n for i in range(line):\r\n print(p, end=\"\")\r\n p += 1\r\n print()\r\n line -= 1\r\n \r\n\r\n\r\nt = int(input())\r\nanswers = list()\r\nfor _ in range(t):\r\n n = int(input())\r\n answers.append(n)\r\n\r\nfor answer in answers:\r\n f(answer)", "x=int(input())\nfor i in range(x):\n n=int(input())\n p=1\n for j in range(n):\n for k in range(n-j):\n print(p,end=\"\")\n p+=1\n print() ", "# cook your dish here\n# cook your dish here\ndef solve():\n n = int(input())\n #n,m = input().split()\n #n = int(n)\n #m = int(m)\n #s = input()\n #a = list(map(int, input().split()))\n it = n\n k=1\n for i in range(n):\n j=0\n while j<it:\n print(k,end=\"\")\n j+=1\n k+=1\n print(\"\")\n it-=1\n \n \n \n \ndef __starting_point():\n T = int(input())\n for i in range(T):\n #a = solve()\n #n = len(a)\n #for i in range(n):\n # if i==n-1 : print(a[i])\n # else: print(a[i],end=\" \")\n (solve())\n__starting_point()", "t = int(input())\nfor _ in range(t):\n n = int(input())\n count = 1\n for i in range(n):\n for j in range(n-i):\n print(count,end='')\n count += 1\n print()", "for _ in range(int(input())):\n N = int(input())\n \n K = 1\n for i in range(N, 0, -1):\n for j in range(i):\n print(K, end=\"\")\n K += 1\n print()", "import sys\r\ninput = lambda: sys.stdin.readline().rstrip(\"\\r\\n\")\r\ninp = lambda: list(map(int,sys.stdin.readline().rstrip(\"\\r\\n\").split()))\r\n#______________________________________________________________________________________________________\r\n# from math import *\r\n# from bisect import *\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(2*(10**5)+100) this is must for dfs\r\n# mod = 10**9+7; md = 998244353\r\n# ______________________________________________________________________________________________________\r\n# segment tree for range minimum query\r\n# sys.setrecursionlimit(10**5)\r\n# n = int(input())\r\n# a = list(map(int,input().split()))\r\n# st = [float('inf') for i in range(4*len(a))]\r\n# def build(a,ind,start,end):\r\n# if start == end:\r\n# st[ind] = a[start]\r\n# else:\r\n# mid = (start+end)//2\r\n# build(a,2*ind+1,start,mid)\r\n# build(a,2*ind+2,mid+1,end)\r\n# st[ind] = min(st[2*ind+1],st[2*ind+2])\r\n# build(a,0,0,n-1)\r\n# def query(ind,l,r,start,end):\r\n# if start>r or end<l:\r\n# return float('inf')\r\n# if l<=start<=end<=r:\r\n# return st[ind]\r\n# mid = (start+end)//2\r\n# return min(query(2*ind+1,l,r,start,mid),query(2*ind+2,l,r,mid+1,end))\r\n# ______________________________________________________________________________________________________\r\n# Checking prime in O(root(N))\r\n# def isprime(n):\r\n# if (n % 2 == 0 and n > 2) or n == 1: return 0\r\n# else:\r\n# s = int(n**(0.5)) + 1\r\n# for i in range(3, s, 2):\r\n# if n % i == 0:\r\n# return 0\r\n# return 1\r\n# def lcm(a,b):\r\n# return (a*b)//gcd(a,b)\r\n# ______________________________________________________________________________________________________\r\n# nCr under mod\r\n# def C(n,r,mod):\r\n# if r>n:\r\n# return 0\r\n# num = den = 1\r\n# for i in range(r):\r\n# num = (num*(n-i))%mod\r\n# den = (den*(i+1))%mod\r\n# return (num*pow(den,mod-2,mod))%mod\r\n# M = 10**5 +10\r\n# ______________________________________________________________________________________________________\r\n# For smallest prime factor of a number\r\n# M = 1000010\r\n# pfc = [i for i in range(M)]\r\n# def pfcs(M):\r\n# for i in range(2,M):\r\n# if pfc[i]==i:\r\n# for j in range(i+i,M,i):\r\n# if pfc[j]==j:\r\n# pfc[j] = i\r\n# return\r\n# pfcs(M)\r\n# ______________________________________________________________________________________________________\r\ntc = 1\r\ntc, = inp()\r\n# a = [0,1]\r\n# for i in range(100000):\r\n# a.append(a[-1]+a[-2])\r\nfor _ in range(tc):\r\n n, = inp()\r\n b = (n*(n+1))//2\r\n a = [i+1 for i in range(b+1)]\r\n # print(a)\r\n start = 0\r\n for i in range(n,0,-1):\r\n print(*a[start:start+i],sep = \"\")\r\n start+=i", "for _ in range(int(input())):\r\n n=int(input())\r\n r=1\r\n t=n+1\r\n for i in range(n):\r\n t-=1\r\n for j in range(t,0,-1):\r\n print(r,end=\"\")\r\n r+=1\r\n print()", "from sys import stdin, stdout\nfrom math import floor, gcd, fabs, factorial, fmod, sqrt, inf, log\nfrom collections import defaultdict as dd, deque\nfrom heapq import merge, heapify, heappop, heappush, nsmallest\nfrom bisect import bisect_left as bl, bisect_right as br, bisect\nmod = pow(10, 9) + 7\nmod2 = 998244353\ndef inp(): return stdin.readline().strip()\ndef out(var, end=\"\\n\"): stdout.write(str(var)+\"\\n\")\ndef outa(*var, end=\"\\n\"): stdout.write(' '.join(map(str, var)) + end)\ndef lmp(): return list(mp())\ndef mp(): return map(int, inp().split())\ndef smp(): return map(str, inp().split())\ndef l1d(n, val=0): return [val for i in range(n)]\ndef l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]\ndef remadd(x, y): return 1 if x%y else 0\ndef ceil(a,b): return (a+b-1)//b\n\ndef isprime(x):\n if x<=1: return False\n if x in (2, 3): return True\n if x%2 == 0: return False\n for i in range(3, int(sqrt(x))+1, 2):\n if x%i == 0: return False\n return True\n \nfor _ in range(int(inp())):\n n = int(inp())\n k = 1\n for i in range(n):\n for j in range(n-i):\n print(k, end=\"\")\n k+=1\n print()", "for _ in range(int(input())):\n n=int(input())\n x=1\n for _ in range(1,n+1):\n for __ in range(n-_+1,0,-1):\n print(x,end=\"\")\n x+=1\n print()\n print() "]
{"inputs": [["4", "1", "2", "3", "4"]], "outputs": [["1", "12", "3", "123", "45", "6", "1234", "567", "89", "10"]]}
INTERVIEW
PYTHON3
CODECHEF
9,054
84a85a35281b21e9e6cdb13ed2d511f6
UNKNOWN
Given an array A of length N, your task is to find the element which repeats in A maximum number of times as well as the corresponding count. In case of ties, choose the smaller element first. -----Input----- First line of input contains an integer T, denoting the number of test cases. Then follows description of T cases. Each case begins with a single integer N, the length of A. Then follow N space separated integers in next line. Assume that 1 <= T <= 100, 1 <= N <= 100 and for all i in [1..N] : 1 <= A[i] <= 10000 -----Output----- For each test case, output two space separated integers V & C. V is the value which occurs maximum number of times and C is its count. -----Example----- Input: 2 5 1 2 3 2 5 6 1 2 2 1 1 2 Output: 2 2 1 3 Description: In first case 2 occurs twice whereas all other elements occur only once. In second case, both 1 and 2 occur 3 times but 1 is smaller than 2.
["t = input();\n\na = [0 for i in range(10001)]\n\ni = 0;\n\nwhile i < int(t):\n\n\tn = input();\n\n\tk = input();\n\n\tassert(len(k.split(' ')) == int(n));\n\n\tfor each in k.split(' '):\n\n\t\ta[int(each)] += 1;\n\n\n\tV = 0;\n\n\tC = a[V];\n\n\tfor j in range(10001):\n\n\t\tif C < a[j]:\n\n\t\t\tV = j;\n\n\t\t\tC = a[V];\n\n\t\ta[j] = 0;\n\n\ti += 1;\n\n\tprint(V, C);\n", "import sys\ndef main():\n s = sys.stdin.readline\n for t in range(int(s())):\n n = int(s())\n A = list(map(int, s().split()))\n save = {}\n for i in A:\n if i in save:\n save[i]+=1\n else:\n save[i]=1\n g = max(save, key=save.get)\n now = []\n for num in save:\n if save[num] == save[g]:\n now.append(num)\n now = sorted(now)\n print(now[0], save[g])\ndef __starting_point():\n main() \n__starting_point()", "import fileinput\n\ndef CountMax (nA, A):\n\thT = {}\n\tfor n in A:\n\t\tif n not in hT:\n\t\t\thT.setdefault(n,1)\n\t\telse:\n\t\t\thT[n] += 1\n\tvals = [(pair[0],pair[1]) for pair in hT.items()]\n\tvals.sort(key=lambda p:p[0])\n\t#print vals\n\treturn max(vals,key=lambda p:p[1])\n\t\ndef main():\n\tf = fileinput.FileInput()\n\tr = f.readline()\n\tif (r==''): \n\t\treturn 0\n\telse: \n\t\tnT = int(r)\n\twhile nT > 0 :\n\t\tnA = int(f.readline())\n\t\tA = list(map (int,(f.readline().strip()).split(' ')))\n\t\tresult = CountMax(nA, A)\n\t\tprint(result[0],result[1])\n\t\tnT = nT -1\n\treturn 0\ndef __starting_point():\n\tmain()\n__starting_point()", "from sys import stdin as I\nfrom collections import defaultdict\n\nints = lambda: [int(s) for s in I.readline().split()]\n\nT = ints()[0]\nwhile T:\n T -= 1\n n = ints()\n c = defaultdict(int)\n for x in ints():\n c[x] += 1\n \n rv = (0, 0)\n for val, ct in list(c.items()):\n if ct > rv[1]:\n rv = (val, ct)\n elif ct == rv[1] and val < rv[0]:\n rv = (val, ct)\n \n print(rv[0], rv[1])\n \n", "\ndef solve():\n\tN = int(input())\n\tV = [0] * 10001\n\tI = list(map(int,input().split()))\n\tfor i in I:\n\t\tV[i] += 1\n\tAns = 0\n\tfor i in range(len(V)):\n\t\tif V[i] > V[Ans]:\n\t\t\tAns = i\n\tprint(Ans , V[Ans])\n\t\t\t\n\t\ndef main():\n\tt = int(input())\n\tfor i in range(t):\n\t\tsolve()\n\t\t\nmain()", "lists = []\nresults = []\nfor a in range(eval(input())):\n eval(input())\n lists.append([int(x) for x in input().split()])\nfor element in lists:\n results = []\n for n in element:\n ns = [x[0] for x in results]\n if n in ns :\n results[ns.index(n)][1] += 1\n else:\n results.append([n, 1])\n results.sort(key = lambda x:x[0])\n results.sort(key = lambda x:x[1], reverse = True)\n print(\" \".join([str(x) for x in results[0]]))", "import sys\n\nfor _ in range(int(sys.stdin.readline())):\n l=int(sys.stdin.readline())\n a=sys.stdin.readline().split()\n a=list(map(int,a))\n t=set(a)\n count=[]\n c=[]\n if len(t)==len(a):\n print(min(a),1)\n \n elif len(t)==1:\n print(a[0],l)\n \n else:\n for j in t:\n c.append(j)\n c.sort()\n for i in c:\n num=a.count(i)\n count.append(num)\n \n times=max(count)\n index=count.index(times)\n print(c[index],times)\n \n ", "n=int(input())\nwhile(n):\n size=int(input())\n a=[]\n a=input().split()\n i=0\n #b=len(a)*[0]\n while(i<len(a)):\n a[i]=int(a[i])\n #print 'hello'\n i+=1\n j=max(a)\n freq=[]\n freq=(j+1)*[0]\n k=0\n while(k<len(a)):\n if(a[k]!=0):\n freq[a[k]-1]+=1\n k+=1\n count=max(freq)\n key=freq.index(count)+1\n print(key,count)\n n-=1", "t = int(input())\nwhile t:\n t-=1\n n = int(input())\n l = list(map(int, str(input()).split()))\n k = set(l)\n maxi = 0\n num = 10001\n for i in k:\n c = l.count(i)\n if c>maxi:\n maxi = c\n num = i\n elif c == maxi and i<num:\n num = i\n print(num, maxi)\n", "#!/usr/bin/env python\n\nT = int(input())\nfor t in range(T):\n N = int(input())\n A = list(map(int, input().split()))\n D = {}\n for e in A:\n D[e] = D.get(e, 0) + 1\n C = max(D.values())\n V = min([e[0] for e in [e for e in list(D.items()) if e[1] == C]])\n print(V, C)\n", "i = input('')\ni = int(i)\n\nx = 0\nans = []\n\nwhile (x < i):\n\ta = input('')\n\tarr = input('')\n\tarr = arr.split()\n\t\n\tcnts = []\n\ty = 0\n\t\n\twhile (y < len(arr)):\n\t\ttemp = [0, 0]\n\t\ttemp[0] = int(arr[y])\n\t\ttemp[1] = arr.count(arr[y])\n\t\tcnts.append(temp)\n\t\ty = y + 1\n\t\t\n\tmaxi = 10001\n\tmaxicount = 0\n\t\n\ty = 0\n\t\n\twhile (y < len(cnts)):\n\t\tif ((cnts[y])[1] > maxicount):\n\t\t\tmaxicount = (cnts[y])[1]\n\t\t\tmaxi = (cnts[y])[0]\n\t\telif ((cnts[y])[1] == maxicount):\n\t\t\tmaxicount = (cnts[y])[1]\n\t\t\tif ( (cnts[y])[0] < maxi ):\n\t\t\t\tmaxi = (cnts[y])[0]\n\t\ty = y + 1\n\t\n\tans.append(str(maxi) + ' ' + str(maxicount))\n\t\n\tx = x + 1\n\t\nx = 0\n\nwhile (x < len(ans)):\n\tprint(ans[x])\n\tx = x + 1", "n=int(input())\nwhile(n):\n size=int(input())\n a=[]\n a=input().split()\n i=0\n #b=len(a)*[0]\n while(i<len(a)):\n a[i]=int(a[i])\n #print 'hello'\n i+=1\n j=max(a)\n freq=[]\n freq=(j+1)*[0]\n k=0\n while(k<len(a)):\n if(a[k]!=0):\n freq[a[k]-1]+=1\n k+=1\n count=max(freq)\n key=freq.index(count)+1\n print(key,count)\n n-=1\n \n \n \n", "import sys\n\nt = int(sys.stdin.readline())\n\nfor _ in range(t):\n\tn = int(sys.stdin.readline());\n\tv = list(map(int,sys.stdin.readline().split()))\n\tv.sort()\n\txm,cm = v[0],0\n\tx,c = v[0],0\n\tfor i in v:\n\t\tif i == x:\n\t\t\tc += 1\n\t\telse:\n\t\t\tif c > cm or (c == cm and x < xm):\n\t\t\t\txm,cm = x,c\n\t\t\tx, c = i, 1\n\tif c > cm or (c == cm and x < xm):\n\t\txm,cm = x,c\n\tprint(xm,cm)\n", "import sys\n\nresult = []\nn = int(sys.stdin.readline())\nfor i in range(0, n):\n sys.stdin.readline()\n original = [int(numero) for numero in sys.stdin.readline().strip().split()]\n l = list(set(original))\n l.sort()\n repeats = 0\n number = l[0]\n for j in l:\n c = original.count(j)\n if c > repeats:\n repeats = c\n number = j\n result.append(str(number) + \" \" + str(repeats))\nsys.stdout.write(\"\\n\".join(result))\n", "from array import array\ndef solve():\n n = int(input())\n inp = list(map(int, input().split()))\n mx = max([inp.count(i) for i in inp])\n ans = min([x for x in inp if inp.count(x) == mx])\n print(str(ans) + \" \" + str(inp.count(ans)))\n\nt = int(input())\nfor i in range(0, t): solve()", "cases = int(input())\nfor case in range(cases):\n n = int(input())\n freq = [0]*10001\n a = list(map(int,input().split()))\n \n largest = 1\n for i in range(n):\n freq[a[i]] += 1\n largest = max(largest,a[i])\n most = 0\n for num in range(largest+1):\n if freq[num] > freq[most]:\n most = num\n print(most,freq[most])", "def maxcount(lst):\n op = [0]*max(lst)\n for i in lst:\n op[i-1]+=1\n \n return op.index(max(op))+1, max(op)\n\nt= int(input())\n\nwhile (t>0):\n input()\n lst = [int(i) for i in input().split(' ')]\n counts = maxcount(lst)\n for i in counts:\n print(i, end=' ') \n print(\"\") \n t-=1 ", "def maxcount(lst):\n op = [0]*max(lst)\n for i in lst:\n op[i-1]+=1\n \n return op.index(max(op))+1, max(op)\n\nt= int(input())\n\nwhile (t>0):\n input()\n lst = list(map(int, input().split(' ')))\n counts = maxcount(lst)\n for i in counts:\n print(i, end=' ') \n print(\"\") \n t-=1 ", "n=int(input())\nfor i in range(1,n+1):\n\tk=int(input())\n\tt=[0]*10001\n\ts=input().split()\n\tfor j in range(0,k):\n\t\tl=int(s[j])\n\t\tt[l]+=1\n\tmax=0\n\tfor j in t:\n\t\tif j > max:\n\t\t\tmax = j\n\tfor l,j in enumerate(t):\n\t\tif j == max:\n\t\t\tprint(str(l) + \" \" + str(j))\n\t\t\tbreak\n\n", "# codechef - february 2012 - count of maximum - maxcount.py\n\nt = int(input())\n\nfor tt in range(t):\n n = int(input())\n a = list(map(int, input().split()))\n c = {}\n for elem in a:\n if elem in c:\n c[elem]+=1\n else:\n c[elem]=1\n\n bestCount = 0\n best = 0\n for elem in c:\n if c[elem]>bestCount:\n bestCount=c[elem]\n best = elem\n elif c[elem]==bestCount and elem<best:\n best = elem\n \n print(best, bestCount)\n", "def main():\n\tno_tcase=int(input())\n\tfor i in range(no_tcase):\n\t\tcountdict={}\n\t\tno_ele=int(input())\n\t\tls=[int(ele) for ele in input().split()]\n\t\tfor ele in range(no_ele):\n\t\t\tif ls[ele] in countdict:\n\t\t\t\tcountdict[ls[ele]]=countdict[ls[ele]]+1\n\t\t\telse:\n\t\t\t\tcountdict[ls[ele]]=1\n\t\tmaxk=ls[0]\t\t\n\t\tmaxval=countdict[maxk]\n\t\tfor key in list(countdict.keys()):\n\t\t\tif countdict[key]>maxval:\n\t\t\t\tmaxk=key\n\t\t\t\tmaxval=countdict[key]\n\t\t\telif countdict[key]==maxval and maxk>key:\n\t\t\t\tmaxk=key\n\t\t\telse:\n\t\t\t\tcontinue\n\t\tprint(maxk,maxval)\n\t\t\ndef __starting_point():\n\tmain()\n\n__starting_point()", "#!/usr/bin/env python2\n# -*- coding: utf-8 -*-\nimport sys\nifs = sys.stdin\nofs = sys.stdout\n\nfrom itertools import repeat\nfrom heapq import nlargest\nfrom operator import itemgetter\n\nclass bag(dict):\n\n def __init__(self, data=()):\n self.update(data)\n\n def __missing__(self, key):\n return 0\n\n def update(self, other):\n if hasattr(other, 'items'):\n super(bag, self).update(other)\n else:\n for elem in other:\n self[elem] += 1\n\n def __setitem__(self, elem, n):\n if n <= 0:\n if elem in self:\n del self[elem]\n else:\n super(bag, self).__setitem__(elem, n)\n\n def itermultiple(self):\n for elem, cnt in self.items():\n for _ in range(cnt):\n yield elem\n\n def nitems(self):\n return sum(self.values())\n\n def most_common(self, n=None):\n if n is None:\n return sorted(iter(self.items()), key=itemgetter(1), reverse=True)\n else:\n return nlargest(n, iter(self.items()), key=itemgetter(1))\n\n def __repr__(self):\n return '%s(%s)' % (self.__class__.__name__, dict.__repr__(self))\n\n def add(self, item, n=1):\n self[item] += n\n\n def discard(self, item, n=1):\n self[item] -= n\n\n\ndef solve(A):\n C = bag(A)\n MC = C.most_common()\n e,c = MC.pop(0)\n c_max = c\n e_min = e\n for mc in MC:\n e,c = mc\n if c==c_max:\n if e < e_min:\n e_min = e\n else:\n break\n return (e_min,c_max)\n\n\ndef numbers_from_line(d=' '):\n return [int(s) for s in ifs.readline().strip().split(d) if len(s.strip())>0]\n\n\nT = int(ifs.readline())\nfor t in range(1,T+1):\n n = int(ifs.readline())\n A = numbers_from_line()\n v,c = solve(A)\n ofs.write('%d %d\\n' % (v,c))\n\n\nsys.exit(0)\n", "\nx = int(input())\n\nfor i in range(x) :\n y = int(input())\n h = {}\n k = input()\n k = k.split(' ')\n for j in range(y) :\n if not h.get(k[j]) :\n h[k[j]] = 1\n else :\n h[k[j]] += 1\n number = 10000\n occur = 0\n for key in list(h.keys()) :\n if h[key] > occur :\n occur = h[key]\n number = key\n elif h[key] is occur :\n if (int(key) < int(number)) :\n #print 'key -> ' + key + ' number -> ' + str(number)\n number = key\n #print 'new key is ' + number + ' occuring ' + str(number) + ' times'\n print(str(number) + ' ' + str(occur))\n"]
{"inputs": [["2", "5", "1 2 3 2 5", "6", "1 2 2 1 1 2", "", ""]], "outputs": [["2 2", "1 3"]]}
INTERVIEW
PYTHON3
CODECHEF
12,153
d97f33b8277fb15fbd11f99884f6d1df
UNKNOWN
Chefu is Chef's little brother, he is 12 years old and he is new to competitive programming. Chefu is practicing very hard to become a very skilled competitive programmer and win gold medal in IOI. Now Chefu is participating in a contest and the problem that he is trying to solve states: Given an array A of N integers, find any i, j such that i < j and Ai + Aj is maximum possible unfortunately, there's no much time left before the end of the contest, so Chefu doesn't have time to think of correct solution, so instead, he wrote a solution that selects a random pair (i, j) (i < j) and output Ai + Aj. each pair is equiprobable to be selected. Now Chefu wants your help to calculate the probability that his solution will pass a particular input. -----Input----- First line contains an integer T denoting the number of test-cases. First line of each test-case contains a single integer N Second line of each test-case contains N space-separated integers A1 A2 ... AN -----Output----- For each test-case output a single line containing a single number denoting the probability that Chefu's solution to output a correct answer. your answer will be accepted if the absolute difference between it and correct answer is less than 1e-6 -----Constraints----- - 1 ≤ T ≤ 100 - 2 ≤ N ≤ 100 - 1 ≤ Ai ≤ 1,000 -----Example----- Input: 3 4 3 3 3 3 6 1 1 1 2 2 2 4 1 2 2 3 Output: 1.00000000 0.20000000 0.33333333
["T=int(input())\nfor i in range(T):\n N=int(input())\n A=list(map(int,input().split()))[:N]\n l=[]\n for j in range(len(A)):\n for k in range(j+1,len(A)):\n l.append(A[j]+A[k])\n print(l.count(max(l))/((N*(N-1))/2))", "for i in range(int(input())):\n n=int(input())\n t=list(map(int,input().split()))[:n]\n m=[]\n for j in range(len(t)):\n for k in range(j+1,len(t)):\n m.append(t[j]+t[k])\n print(m.count(max(m))/((n*(n-1))/2))", "t=int(input())\nfor i in range(t):\n n=int(input())\n a=list(map(int,input().split()))[:n]\n l=[]\n for j in range(len(a)):\n for k in range(j+1,len(a)):\n l.append(a[j]+a[k])\n print(l.count(max(l))/((n*(n-1))/2))", "T=int(input())\nfor i in range(T):\n N=int(input())\n A=list(map(int,input().split()))[:N]\n l=[]\n for j in range(len(A)):\n for k in range(j+1,len(A)):\n l.append(A[j]+A[k])\n print(l.count(max(l))/((N*(N-1))/2))\n", "# cook your dish here\n\nfor i in range(int(input())):\n N=int(input())\n l=list(map(int,input().split()))[:N]\n sum=l[N-1]+l[N-2]\n count=0\n max=0\n for i in range(len(l)):\n for j in range(i+1,len(l)):\n if l[i]+l[j]>max:\n max=l[i]+l[j]\n \n for i in range(len(l)):\n for j in range(i+1,len(l)):\n s=l[i]+l[j]\n if s==max:\n count+=1\n f=N*(N-1)/2\n \n print(format(count/f,'.8f'))\n \n \n", "t=int(input())\nwhile t:\n n=int(input())\n l=list(map(int,input().split()))\n max=0\n c=0\n for i in range(n):\n for j in range(i+1,n):\n if l[i]+l[j]>max:\n max=l[i]+l[j]\n for i in range(n):\n for j in range(i+1,n):\n if l[i]+l[j]==max:\n c+=1\n x=n*(n-1)/2\n print(c/x)\n t-=1", "# cook your dish here\nt=int(input())\nwhile t>0:\n n=int(input())\n a=list(map(int,input().split()))\n max=0\n c=0\n for i in range(n):\n for j in range(i+1,n):\n if a[i]+a[j]>max:\n max=a[i]+a[j]\n for i in range(n):\n for j in range(i+1,n):\n if a[i]+a[j]==max:\n c+=1\n x=n*(n-1)/2\n print(c/x)\n t-=1", "for _ in range(int(input())):\n n = int(input())\n a = sorted(list(map(int, input().split())), reverse=True)\n i = 1\n while i<n-1 and a[i]==a[i+1]:\n i+=1\n \n if a[0] == a[1]:\n print(i*(i+1)/(n*(n-1)))\n else:\n print(2*i/(n*(n-1)))", "# def main():\n# t=int(input())\n# while(t!=0):\n# n = int(input())\n# arr = list(map(int, input().split()))\n# maxVal=-1\n# for i in range(0,n):\n# for j in range(i+1,n):\n# temp =arr[i]+arr[j]\n# if(maxVal<temp):\n# maxVal=temp\n#\n# count=0\n# for i in range(0,n):\n# for j in range(i+1,n):\n# temp =arr[i]+arr[j]\n# if(maxVal==temp):\n# count+=1\n# val = (n*(n-1))/2\n# print(count/val)\n# t=t-1\n#\n# def __starting_point():\n# main()\n\n\ndef main():\n t=int(input())\n while(t!=0):\n n = int(input())\n arr = list(map(int, input().split()))\n arr.sort()\n maxEle = arr[n-1]\n num = (n*(n-1))/2\n count1= arr.count(maxEle)\n\n if(count1==1):\n count2=arr.count(arr[n-2])\n print(count2/num)\n else:\n val = (count1*(count1-1))/2\n print(val/num)\n t=t-1\n\ndef __starting_point():\n main()\n__starting_point()", "def main():\n t=int(input())\n while(t!=0):\n n = int(input())\n arr = list(map(int, input().split()))\n maxVal=-1\n for i in range(0,n):\n for j in range(i+1,n):\n temp =arr[i]+arr[j]\n if(maxVal<temp):\n maxVal=temp\n\n count=0\n for i in range(0,n):\n for j in range(i+1,n):\n temp =arr[i]+arr[j]\n if(maxVal==temp):\n count+=1\n val = (n*(n-1))/2\n print(count/val)\n t=t-1\n\ndef __starting_point():\n main()\n__starting_point()", "# cook your dish here\n#number of test cases\nfor _ in range(int(input())):\n n=int(input())\n a=list(map(int,input().split()))\n l=[]\n for i in range(n):\n for j in range(i+1,n):\n l.append(a[i]+a[j])\n print(l.count(max(l))/len(l))", "# cook your dish here\ntry:\n T=int(input())\n for _ in range(T):\n N=int(input())\n A=list(map(int,input().split()))\n c=0\n d=[]\n for i in range(N):\n for j in range(i+1,N):\n d.append(A[i]+A[j])\n ans=d.count(max(d))/len(d)\n print('%0.8f'%ans)\nexcept:\n pass", "for _ in range(int(input())):\n K = int(input())\n arr = list(map(int, input().split()))\n P = []\n for i in range(K):\n for j in range(i+1,K):\n P.append(arr[i]+arr[j])\n print(P.count(max(P))/len(P))\n\n\n", "# cook your dish here\nfor _ in range(int(input())):\n n=int(input())\n a=list(map(int,input().split()))\n l=[]\n for i in range(n):\n for j in range(i+1,n):\n l.append(a[i]+a[j])\n print(l.count(max(l))/len(l))", "for _ in range(int(input())):\n n=int(input())\n a=list(map(int,input().split()))\n l=[]\n for i in range(n):\n for j in range(i+1,n):\n l.append(a[i]+a[j])\n print(l.count(max(l))/len(l))", "t = int(input())\n\nfor _ in range(t):\n n = int(input())\n \n a = [int(x) for x in input().split()]\n f = []\n \n for i in range(n):\n for j in range(i+1, n):\n f.append(a[i]+a[j])\n \n maxi = f.count(max(f))\n ans = maxi/len(f)\n \n print(format(ans, '.6f'))", "# cook your dish here\ntry:\n for _ in range(int(input())):\n n=int(input())\n l=list(map(int,input().split()))\n p=[]\n for i in range(n):\n for j in range(i+1,n):\n p.append(l[i]+l[j])\n m=p.count(max(p))/len(p)\n print('%.8f'%m)\nexcept:\n pass", "# cook your dish here\ntry:\n T=int(input())\n for _ in range(T):\n N=int(input())\n A=list(map(int,input().split()))\n c=0\n d=[]\n for i in range(N):\n for j in range(i+1,N):\n d.append(A[i]+A[j])\n ans=d.count(max(d))/len(d)\n print('%0.8f'%ans)\nexcept:\n pass", "# cook your dish here\nfrom itertools import combinations\n\nt=int(input())\n\ndef pair(arr):\n maxi=0\n k=0\n d=0\n if len(set(arr))==1:\n return \"{:.8f}\".format(1)\n c=list(combinations(arr,2))\n \n for i in c:\n if sum(i) > maxi:\n maxi=sum(i)\n d+=1 \n \n for i in c:\n \n if sum(i) == maxi:\n k+=1\n p=k/d\n \n \n return \"{:.8f}\".format(p)\n \n \n\nfor _ in range(t):\n \n n=int(input())\n arr=list(map(int,input().split()))\n r=pair(arr)\n print(r)", "# cook your dish here\nt = int(input())\n\nwhile t:\n N = int(input())\n A = list(map(int, input().split()))\n l = []\n\n for i in range(N):\n for j in range(i+1, N):\n l.append(A[i]+A[j])\n\n c = l.count(max(l))\n\n print(c/len(l))\n\n t = t-1\n", "# cook your dish here\nfor _ in range(int(input())):\n N = int(input())\n A = list(map(int,input().split()))\n B = []\n for i in range(N-1):\n for j in range(i+1,N):\n B.append(A[i]+A[j])\n C = max(B)\n D=N*(N-1)//2\n count = B.count(C)\n print('%0.8f' %(count/D))", "t=int(input())\nfor i in range(t):\n n=int(input())\n a=list(map(int,input().split()))\n list1=[]\n for i in range(n-1):\n for j in range(i+1,n):\n list1.append(a[i]+a[j])\n c=0\n c=max(list1)\n d=0\n d=n*(n-1)//2\n c1=0\n c1=list1.count(c)\n print(c1/d)\n", "for _ in range(int(input())):\n N = int(input())\n L = list(map(int, input().split()))\n \n L_copy = L.copy()\n N1 = max(L_copy)\n L_copy.remove(N1)\n N2 = max(L_copy)\n \n req_out = 0\n for i in range(N):\n for j in range(N):\n if i != j and ((L[i]==N1 and L[j]==N2) or (L[i]==N2 and L[j]==N1)):\n req_out += 1\n \n tot_out = N * (N-1) / 2\n \n print(req_out / (2 * tot_out))", "# cook your dish here\ntry:\n t = int(input())\n for _ in range(t):\n n = int(input())\n arr = list(map(int,input().split()))\n from itertools import combinations\n ans = []\n for l in combinations(arr,2):\n ans.append(l)\n maxx = 0\n for l in ans:\n m = sum(l)\n if m>maxx:\n maxx = m\n count = 0 \n for l in ans:\n item = sum(l)\n if item<maxx:\n count+=1\n print(1 - count/len(ans))\n continue\nexcept:\n pass\n \n \n"]
{"inputs": [["3", "4", "3 3 3 3", "6", "1 1 1 2 2 2", "4", "1 2 2 3"]], "outputs": [["1.00000000", "0.20000000", "0.33333333"]]}
INTERVIEW
PYTHON3
CODECHEF
7,732
b2eec328328dd50ce1f309b987707f11
UNKNOWN
You are given a tree with $N$ vertices (numbered $1$ through $N$) and a sequence of integers $A_1, A_2, \ldots, A_N$. You may choose an arbitrary permutation $p_1, p_2, \ldots, p_N$ of the integers $1$ through $N$. Then, for each vertex $i$, you should assign the value $A_{p_i}$ to this vertex. The profit of a path between two vertices $u$ and $v$ is the sum of the values assigned to the vertices on that path (including $u$ and $v$). Let's consider only (undirected) paths that start at a leaf and end at a different leaf. Calculate the maximum possible value of the sum of profits of all such paths. Since this value could be very large, compute it modulo $10^9 + 7$. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains a single integer $N$. - The second line contains $N$ space-separated integers $A_1, A_2, \ldots, A_N$. - Each of the following $N−1$ lines contains two space-separated integers $u$ and $v$ denoting that vertices $u$ and $v$ are connected by an edge. -----Output----- For each test case, print a single line containing one integer — the maximum sum of profits, modulo $10^9 + 7$. -----Constraints----- - $1 \le T \le 1,000$ - $1 \le N \le 300,000$ - $1 \le A_i \le 10^9$ for each valid $i$ - the sum of $N$ over all test cases does not exceed $5 \cdot 10^5$ -----Example Input----- 2 4 1 2 3 4 1 2 2 3 2 4 5 1 2 3 4 5 1 2 2 3 3 4 4 5 -----Example Output----- 24 15 -----Explanation----- Example case 1: $(1, 4, 2, 3)$ is one of the possible permutations that give the optimal answer. Then, the profits of paths between pairs of vertices $(1, 3)$, $(1, 4)$ and $(3, 4)$ are $7$, $8$ and $9$ respectively. Example case 2: Here, any permutation could be chosen.
["T = int(input())\n\nM = 10 ** 9 + 7\n\nfor _ in range(T):\n N = int(input())\n\n A = list(map(int, input().split()))\n\n if N == 1:\n print(0)\n continue\n\n B = {}\n C = {}\n\n for i in range(N - 1):\n u, v = input().split()\n u = int(u) - 1\n v = int(v) - 1\n\n if u not in B:\n B[u] = []\n\n if v not in B:\n B[v] = []\n\n B[u].append(v)\n B[v].append(u)\n\n total_leaves = 0\n\n for i in B:\n if len(B[i]) == 1:\n total_leaves += 1\n\n S = [0]\n\n visited = [False] * N\n\n parent = [-1] * N\n\n total_visits = [0] * N\n\n while len(S) > 0:\n current = S.pop(len(S) - 1)\n\n if visited[current]:\n p = parent[current]\n if p != -1:\n total_visits[p] += total_visits[current]\n if p not in C:\n C[p] = {}\n C[p][current] = total_visits[current]\n if current not in C:\n C[current] = {}\n C[current][p] = total_leaves - C[p][current]\n else:\n S.append(current)\n visited[current] = True\n for i, j in enumerate(B[current]):\n if not visited[j]:\n parent[j] = current\n S.append(j)\n if len(B[current]) == 1:\n total_visits[current] = 1\n p = parent[current]\n if p != -1:\n if p not in C:\n C[p] = {}\n C[p][current] = 1\n\n D = {}\n for i in C:\n sum1 = 0\n for j in C[i]:\n sum1 += C[i][j]\n D[i] = sum1\n\n E = [0] * N\n for i in C:\n sum1 = 0\n for j in C[i]:\n D[i] -= C[i][j]\n sum1 += C[i][j] * D[i]\n E[i] = sum1\n\n for i, j in enumerate(E):\n if j == 0:\n for k in C[i]:\n E[i] = C[i][k]\n\n E.sort()\n E.reverse()\n A.sort()\n A.reverse()\n\n E = [x % M for x in E]\n A = [x % M for x in A]\n\n ans = 0\n for i, j in zip(E, A):\n a = i * j\n a %= M\n ans += a\n ans %= M\n\n print(ans)\n"]
{"inputs": [["2", "4", "1 2 3 4", "1 2", "2 3", "2 4", "5", "1 2 3 4 5", "1 2", "2 3", "3 4", "4 5"]], "outputs": [["24", "15"]]}
INTERVIEW
PYTHON3
CODECHEF
1,714
7ead6c8bc6a2462a38a59a17d4ac5dfa
UNKNOWN
-----Problem Statement----- We have an integer sequence $A$, whose length is $N$. Find the number of the non-empty contiguous subsequences of $A$ whose sum is $0$. Note that we are counting the ways to take out subsequences. That is, even if the contents of some two subsequences are the same, they are counted individually if they are taken from different positions. -----Input----- Input is given in the following format: $N$ $A_1$ $A_2$ . . . $A_N$ -----Output----- Find the number of the non-empty contiguous subsequences of $A$ whose sum is $0$. -----Constraints----- - $1 \leq N \leq 2\times10^5$ - $-10^9 \leq A_i \leq 10^9$ - All values in input are integers. -----Sample Input----- 6 1 3 -4 2 2 -2 -----Sample Output----- 3 -----EXPLANATION----- There are three contiguous subsequences whose sums are $0$: $(1, 3, -4)$, $(-4, 2, 2)$ and $(2, -2)$
["from collections import defaultdict \ndef findSubarraySum(arr, n, Sum): \n \n # Dictionary to store number of subarrays \n # starting from index zero having \n # particular value of sum. \n prevSum = defaultdict(lambda : 0) \n \n res = 0 \n \n # Sum of elements so far. \n currsum = 0 \n \n for i in range(0, n): \n \n # Add current element to sum so far. \n currsum += arr[i] \n \n # If currsum is equal to desired sum, \n # then a new subarray is found. So \n # increase count of subarrays. \n if currsum == Sum: \n res += 1 \n \n # currsum exceeds given sum by currsum - sum. \n # Find number of subarrays having \n # this sum and exclude those subarrays \n # from currsum by increasing count by \n # same amount. \n if (currsum - Sum) in prevSum: \n res += prevSum[currsum - Sum] \n \n \n # Add currsum value to count of \n # different values of sum. \n prevSum[currsum] += 1 \n \n return res \nn=int(input())\nlst=list(map(int,input().split()))\nif(n==1):\n if(lst[0]==0):\n print(1)\n else:\n print(0)\nelse: \n print(findSubarraySum(lst,n,0)) \n", "from collections import Counter\n \nN = int(input())\nA = list(map(int, input().split()))\n \nans = 0\n \nb = [A[0]]\n \nfor i in range(1, N):\n b.append(b[-1]+A[i])\n \ncnt = Counter(b)\ncnt[0] += 1\n \nfor v in cnt.values():\n ans += v*(v-1)//2\n \nprint(ans)", "# # we could probably do N linear searches or something\n# # time limit is 2 seconds which makes sense for O(n^2) or something\n# N = int(input());count = 0\n# arr = list(map(int , input().split()))\n# for i in range(N):\n# sum_ = arr[i]\n# if(sum_ == 0): count += 1\n# for j in range(i + 1,N):\n# sum_ += arr[j]\n# if(sum_ == 0): count += 1\n# print(count) #TLE\n# Python3 program to find the number of \n# subarrays with sum exactly equal to k. \nfrom collections import defaultdict \n\n# Function to find number of subarrays \n# with sum exactly equal to k. \ndef findSubarraySum(arr, n, Sum): \n\n # Dictionary to store number of subarrays \n # starting from index zero having \n # particular value of sum. \n prevSum = defaultdict(lambda : 0) \n \n res = 0\n \n # Sum of elements so far. \n currsum = 0\n \n for i in range(0, n): \n \n # Add current element to sum so far. \n currsum += arr[i] \n \n # If currsum is equal to desired sum, \n # then a new subarray is found. So \n # increase count of subarrays. \n if currsum == Sum: \n res += 1 \n \n # currsum exceeds given sum by currsum - sum. \n # Find number of subarrays having \n # this sum and exclude those subarrays \n # from currsum by increasing count by \n # same amount. \n if (currsum - Sum) in prevSum: \n res += prevSum[currsum - Sum] \n \n \n # Add currsum value to count of \n # different values of sum. \n prevSum[currsum] += 1\n \n return res \nn = int(input())\narr = [int(i) for i in input().split()] \nSum = 0\nprint(findSubarraySum(arr, n, Sum)) \n \n# This code is contributed by Rituraj Jain \n\n", "from sys import stdin, stdout\nfrom collections import defaultdict\ndef le():\n return int(stdin.readline())\ndef lt():\n return list(map(int, stdin.readline().split()))\nn=le()\nlst=lt()\nprev=defaultdict(lambda:0)\ns=0\nc=0\nfor i in range(n):\n s+=lst[i]\n if s==0:\n c+=1\n temp=[]\n if s in prev:\n c+=prev[s]\n prev[s]+=1\nstdout.write(str(c))", "from sys import stdin\nn = int(stdin.readline())\nd = {}\ncount = sm = 0\nfor num in map(int, stdin.readline().split()):\n sm += num\n if not sm: count += 1\n if sm in d:\n count += d[sm]\n d[sm] += 1\n else: d[sm] = 1\nprint(count)", "\ndef countsumzero(lst):\n prefixsums = [0]\n for x in lst:\n prefixsums.append(prefixsums[-1] + x)\n freq = {}\n for y in prefixsums:\n if y in freq:\n freq[y] += 1\n else:\n freq[y] = 1\n \n return sum(v*(v-1) // 2 for v in list(freq.values())) \n\n# Driver code \ntry:\n n=int(input())\n a = list(map(int, input().split()))\n print(countsumzero(a)) \nexcept:\n print(error)\n \n\n\n", "# cook your dish here\ndef countsumzero(lst):\n prefixsums = [0]\n for x in lst:\n prefixsums.append(prefixsums[-1] + x)\n freq = {}\n for y in prefixsums:\n if y in freq:\n freq[y] += 1\n else:\n freq[y] = 1\n \n return sum(v*(v-1) // 2 for v in list(freq.values())) \n\n# Driver code \ntry:\n n=int(input())\n a = list(map(int, input().split()))\n print(countsumzero(a)) \nexcept:\n print(error)\n \n\n\n", "def countsumzero(lst):\n prefixsums = [0]\n for x in lst:\n prefixsums.append(prefixsums[-1] + x)\n freq = {}\n for y in prefixsums:\n if y in freq:\n freq[y] += 1\n else:\n freq[y] = 1\n return sum(v*(v-1) // 2 for v in freq.values())\n\nm = int(input())\na = [int(x) for x in input().split()]\nprint(countsumzero(a))", "# cook your dish here\ndef countsumzero(lst):\n prefixsums = [0]\n for x in lst:\n prefixsums.append(prefixsums[-1] + x)\n freq = {}\n for y in prefixsums:\n if y in freq:\n freq[y] += 1\n else:\n freq[y] = 1\n \n return sum(v*(v-1) // 2 for v in list(freq.values())) \n\n# Driver code \ntry:\n n=int(input())\n a = list(map(int, input().split()))\n print(countsumzero(a)) \nexcept:\n print(error)\n \n\n\n", "# cook your dish here\ndef countsumzero(lst):\n prefixsums = [0]\n for x in lst:\n prefixsums.append(prefixsums[-1] + x)\n freq = {}\n for y in prefixsums:\n if y in freq:\n freq[y] += 1\n else:\n freq[y] = 1\n \n return sum(v*(v-1) // 2 for v in list(freq.values())) \n\n# Driver code \ntry:\n n=int(input())\n a = list(map(int, input().split()))\n print(countsumzero(a)) \nexcept:\n print(error)\n \n\n\n", "# cook your dish here\ndef countsumzero(lst):\n prefixsums = [0]\n for x in lst:\n prefixsums.append(prefixsums[-1] + x)\n freq = {}\n for y in prefixsums:\n if y in freq:\n freq[y] += 1\n else:\n freq[y] = 1\n \n return sum(v*(v-1) // 2 for v in list(freq.values())) \n\n# Driver code \nn=int(input())\na = list(map(int, input().split()))\nprint(countsumzero(a)) \n\n\n\n", "'''\nn=int(input())\na=list(map(int,input().split()))\nsum=0\nc=0\nfor i in range(len(a)):\n sum+=a[i]\n #print(sum)\n if sum==0:\n c+=1\n sum=a[i]\nprint(c)\n\n'''\nfrom collections import Counter\nn=int(input())\na=list(map(int,input().split()))\nres=0\n#lst=[a[0]]\nsum=0\nlst=[]\n#print(lst)\n#print(lst[-1])\nfor i in range(n):\n sum+=a[i]\n lst.append(sum)\n#print(lst)\ncount=Counter(lst)\n#print(count[0])\n#print(count.values())\ncount[0]+=1\n#print(count[0])\n#print(count.values())\nfor i in list(count.values()):\n res+=i*(i-1)//2\nprint(res)\n", "'''\nn=int(input())\na=list(map(int,input().split()))\nsum=0\nc=0\nfor i in range(len(a)):\n sum+=a[i]\n #print(sum)\n if sum==0:\n c+=1\n sum=a[i]\nprint(c)\n\n'''\nfrom collections import Counter\nn=int(input())\na=list(map(int,input().split()))\nres=0\n#lst=[a[0]]\nsum=0\nlst=[]\n#print(lst)\n#print(lst[-1])\nfor i in range(n):\n sum+=a[i]\n lst.append(sum)\n#print(lst)\ncount=Counter(lst)\n#print(count[0])\n#print(count.values())\ncount[0]+=1\n#print(count[0])\n#print(count.values())\nfor i in list(count.values()):\n res+=i*(i-1)//2\nprint(res)\n", "# cook your dish here\ndef countsumzero(lst):\n prefixsums = [0]\n for x in lst:\n prefixsums.append(prefixsums[-1] + x)\n freq = {}\n for y in prefixsums:\n if y in freq:\n freq[y] += 1\n else:\n freq[y] = 1\n \n return sum(v*(v-1) // 2 for v in list(freq.values())) \n\n# Driver code \nn=int(input())\na = list(map(int, input().split()))\nprint(countsumzero(a)) \n\n\n\n", "# cook your dish here\ndef countsumzero(lst):\n prefixsums = [0]\n for x in lst:\n prefixsums.append(prefixsums[-1] + x)\n freq = {}\n for y in prefixsums:\n if y in freq:\n freq[y] += 1\n else:\n freq[y] = 1\n return sum(v*(v-1) // 2 for v in list(freq.values())) \n\n# Driver code \nn=int(input())\na = list(map(int, input().split()))\nprint(countsumzero(a)) \n\n\n\n", "import collections\nn = int(input())\na = list(map(int, input().split()))\nb = [a[0]]\nfor i in range(1, n):\n b.append(b[i-1]+a[i])\nans = b.count(0)\nd = collections.Counter(b)\nfor i in d.values():\n ans += i*(i-1)//2 \n \nprint(ans)", "def countsumzero(lst):\n prefixsums = [0]\n for x in lst:\n prefixsums.append(prefixsums[-1] + x)\n freq = {}\n for y in prefixsums:\n if y in freq:\n freq[y] += 1\n else:\n freq[y] = 1\n return sum(v*(v-1) // 2 for v in freq.values())\n\nm = int(input())\na = [int(x) for x in input().split()]\nprint(countsumzero(a))", "# cook your dish here\ntry:\n n = int(input())\n a = list(map(int, input().split()))\n \n sums = {}\n cur = 0\n cnt = 0\n \n for i in range(n):\n cur += a[i]\n \n if cur == 0:\n cnt += 1\n if cur in sums:\n cnt += sums[cur]\n \n sums[cur] = 1 if cur not in sums else sums[cur] + 1\n \n print(cnt) \nexcept :\n pass", "def countsumzero(lst):\n prefixsums = [0]\n for x in lst:\n prefixsums.append(prefixsums[-1] + x)\n freq = {}\n for y in prefixsums:\n if y in freq:\n freq[y] += 1\n else:\n freq[y] = 1\n return sum(v*(v-1) // 2 for v in list(freq.values())) \n\n# Driver code \nn=int(input())\na = list(map(int, input().split()))\nprint(countsumzero(a)) \n\n\n", "from collections import defaultdict \n\nn=int(input())\na = [int(x) for x in input().split()] \nSum = 0\n\nprevSum = defaultdict(lambda : 0) \n\nres = 0\n\ncurrsum = 0\n\nfor i in range(0, n): \n\n \n currsum += a[i] \n\n if currsum == Sum: \n res += 1 \n\n if (currsum - Sum) in prevSum: \n res += prevSum[currsum - Sum] \n\n prevSum[currsum] += 1 \nprint(res)", "def countsumzero(lst):\n prefixsums = [0]\n for x in lst:\n prefixsums.append(prefixsums[-1] + x)\n freq = {}\n for y in prefixsums:\n if y in freq:\n freq[y] += 1\n else:\n freq[y] = 1\n return sum(v*(v-1) // 2 for v in freq.values())\n\nm = int(input())\na = [int(x) for x in input().split()]\nprint(countsumzero(a))", "from collections import defaultdict \nn = int(input())\nli = list(int(i) for i in input().split())\n\npre = defaultdict(int) \nans,cur=0,0\nfor i in range(n):\n cur+=li[i]\n if cur==0:\n ans+=1\n if cur in pre:\n ans += pre[cur]\n pre[cur]+=1\nprint(ans)", "N = int(input())\nA= list(map(int,input().split(' ')))\ns = 0\nprefixsums = [0]\nfor x in A:\n prefixsums.append(prefixsums[-1] + x)\nfreq = {}\nfor y in prefixsums:\n if y in freq:\n freq[y] += 1\n else:\n freq[y] = 1\nprint(sum(v*(v-1) // 2 for v in freq.values()))", "from collections import defaultdict \ndef SubArr(arr, n):\n ps = defaultdict(lambda : 0) \n res = 0 \n cs = 0 \n for i in range(0, n):\n cs += arr[i] \n if cs == 0: \n res += 1\n if cs in ps: \n res += ps[cs] \n ps[cs] += 1 \n \n return res \ntry:\n n=int(input())\n arr=list(map(int,input().split()))\n ans=SubArr(arr,n)\n print(ans)\nexcept EOFError:\n pass\n"]
{"inputs": [["6", "1 3 -4 2 2 -2"]], "outputs": [["3"]]}
INTERVIEW
PYTHON3
CODECHEF
10,731