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
2036f85049629d19be6138eaa838b930
UNKNOWN
The chef was busy in solving algebra, he found some interesting results, that there are many numbers which can be formed by sum of some numbers which are prime. Chef wrote those numbers in dairy. Cheffina came and saw what the chef was doing. Cheffina immediately closed chef's dairy and for testing chef's memory, she starts asking numbers and chef needs to answer wheater given number N can be formed by the sum of K prime numbers if it yes then print 1 else print 0. -----Input:----- - First-line will contain $T$, the number of test cases. Then the test cases follow. - Each test case contains a single line of input, two integers $N, K$. -----Output:----- For each test case, output in a single line answer as 1 or 0. -----Constraints----- - $1 \leq T \leq 10^5$ - $2 \leq N \leq 10^5$ - $1 \leq K \leq 10^5$ -----Sample Input:----- 2 12 2 11 2 -----Sample Output:----- 1 0
["from math import sqrt\n\ndef isprime(n):\n if (n % 2 == 0 and n > 2) or n == 1: return 0\n else:\n s = int(sqrt(n)) + 1\n for i in range(3, s, 2):\n if n % i == 0:\n return 0\n return 1\n\ndef find(N, K): \n if (N < 2 * K): \n return 0\n if (K == 1): \n return isprime(N) \n if (K == 2): \n if (N % 2 == 0): \n return 1\n return isprime(N - 2); \n return 1\n\nfor _ in range(int(input())):\n n, k = list(map(int, input().split()))\n print(find(n, k))\n\n\n", "# cook your dish here\ndef isprime(n):\n i=2 \n while i*i<n:\n if n%i==0:\n return 0 \n i+=1 \n return 1 \ndef istrue(n,k):\n if n<2*k:\n return 0 \n if k==1:\n return isprime(n) \n if k==2: \n if n%2==0: \n return 1\n return isprime(n-2) \n return 1\nn=int(input())\nfor i in range(n):\n n,k=list(map(int,input().split()))\n print(istrue(n,k))\n \n", "#https://www.geeksforgeeks.org/check-number-can-written-sum-k-prime-numbers/\r\nfrom sys import stdin, stdout\r\ndef isprime(x): \r\n\ti = 2\r\n\twhile(i * i <= x): \r\n\t\tif (x % i == 0): \r\n\t\t\treturn 0\r\n\t\ti+=1\r\n\treturn 1\r\ndef isSum(N, K): \r\n\tif (N < 2 * K): \r\n\t\treturn 0\r\n\tif (K == 1): \r\n\t\treturn isprime(N) \r\n\tif (K == 2): \r\n\t\tif (N % 2 == 0): \r\n\t\t\treturn 1\r\n\t\treturn isprime(N - 2); \r\n\treturn 1\r\ntest = int(stdin.readline())\r\nfor _ in range(test):\r\n n,k = map(int, stdin.readline().split())\r\n if (isSum(n, k)): \r\n \tstdout.write(\"1\"+'\\n') \r\n else: \r\n \tstdout.write(\"0\"+'\\n') ", "# cook your dish here\nfrom random import randint\ndef prime(n): #Fermat Little's theorem\n if n<4:\n return n==2 or n==3\n for i in range(5):\n a=randint(2,n-2)\n if pow(a,n-1,n)!=1:\n return False\n return True\n\ndef solve(n, k):\n if n<2*k:\n return (0)\n elif k==1:\n if prime(n):\n return (1)\n else:\n return (0) \n elif k==2:\n if n&1:\n if prime(n-2):\n return (1)\n else:\n return (0)\n else:\n return (1)\n else:\n return (1)\nfor t_itr in range(int(input())):\n n,k=list(map(int, input().split()))\n print(solve(n,k))\n", "# cook your dish here\nimport sys\nimport math\nT=int(input())\ndef is_prime(x):\n for j in range(2,int(math.sqrt(x))+1):\n if x%j==0:\n return 0\n return 1\n \nfor t in range(T):\n row=list(int(x) for x in input().split())\n N=row[0]\n K=row[1]\n if K==1:\n print(is_prime(N))\n elif K==2 and N>=4:\n if N%2==0:\n print(1)\n else:\n print(0)\n elif K>=3 and N>=2*K:\n print(1)\n else:\n print(0)"]
{"inputs": [["2", "12 2", "11 2"]], "outputs": [["1", "0"]]}
INTERVIEW
PYTHON3
CODECHEF
2,916
84c5b7b27269be2e8797cdc7263d0895
UNKNOWN
In order to win over and get noticed by his favorite streamer Daenerys, Jon decides to donate a significant amount of money . Every donation made to Daenerys is of $at$ $least$ $1$ $beastcoin$ and is displayed on Daenerys's stream alongside any message written and is visible to every viewer. After spotting that Daenerys had set out a target for the streaming day at minimum $X$ beastcoins, all her viewers would only donate amounts less than $X$ beastcoins. Jon decided to better all of them by straight out donating more than or equal to $X$ beastcoins. Further, he decides to write a message along with his special donation to leave her in awe. His message would be : "Crossing my donation with any other donation will only increase the value of my donation". By Crossing, he means to take the $XOR$ . But even for all his intellectual brilliance, money doesn't grow on trees for Jon. After all he is an underpaid employee in his fancy big name MNC. Unlike Daenerys's daily cash cow who makes videos of how she donated carelessly to other people, Jon has a budget and in this case too, he is looking for the minimum donation he needs to make. Can you tell Jon the minimum amount he needs to donate to Daenerys so that he is able to credibly put out the above comment alongside the donation in order to HOPEFULLY win her over. -----Input Format----- - First line contain an interger $T$, which denotes number of testcases. Next $T$ lines contain single interger $X$. -----Output Format----- - For every testcase print one integer, i.e. minimum donation Jon needs to make. -----Constriants----- - $ 1 \leq T \leq 100000 $ - $ 2 \leq X \leq 10^{18} $ -----Sample Input----- 2 3 7 -----Sample Output----- 4 8
["# cook your dish here\nfor _ in range(int(input(''))):\n n=int(input(''))\n x=bin(n)\n x=len(x)-2\n if n==(2**(x-1)):\n print(n)\n else:\n print(2**x)", "# cook your dish here\n\nt = int(input())\ndon = 2\nfor i in range(t):\n x = int(input())\n n = 1\n while(pow(2, n)<x):\n n+=1\n \n don = pow(2, n)\n print(don)\n \n", "# cook your dish here\nimport math\nread = lambda : list(map(int,input().strip.split()))\nrs =lambda: int(input().strip())\nt = rs()\nans = []\ndef find(x):\n i = 0\n x = x-1;\n while(x):\n x = x>>1;\n i += 1;\n return 1 <<i\n\nfor i in range(t):\n n = rs()\n ans.append(find(n))\nprint(\"\\n\".join([str(x) for x in ans]))", "def nextPowerOf2(n): n -= 1;n |= n >> 1;n |= n >> 2;n |= n >> 4;n |= n >> 8;n |= n >> 16;n += 1;return n \nfor _ in range(int(input())): print(nextPowerOf2(int(input())))", "def nextPowerOf2(n,p):\n\tif (n and not(n & (n - 1))): return n\n\twhile (p < n): p <<= 1\n\treturn p\nfor _ in range(int(input())): print(nextPowerOf2(int(input()),1))", "def nextPowerOf2(n,count):\n\tif (n and not(n & (n - 1))): return n \n\twhile( n != 0): n >>= 1;count += 1\n\treturn 1 << count\nfor _ in range(int(input())): print(nextPowerOf2(int(input()),0))", "# cook your dish here\ndef fun(n):\n b = bin(n-1).replace(\"0b\",\"\")\n if b.count(\"0\") == 0:\n return n\n l = len(b)\n s = \"1\"*l\n return (int(s, 2) + 1)\n\nfor i in range(int(input())):\n n = int(input())\n print(fun(n))\n", "import math \r\nfrom math import log\r\n\r\n\r\ndef isPowerOfTwo (x):\r\n return (x and (not(x & (x - 1))) )\r\n\r\nn = int(input())\r\nfor _ in range(n):\r\n t = int(input())\r\n x = int(log(t) / log(2)) + 1\r\n if t==1:\r\n print(2)\r\n else: \r\n if not isPowerOfTwo(t):\r\n print(2**x)\r\n else:\r\n print(t)\r\n", "# cook your dish here\ntry:\n x=int(input())\n for _ in range(x):\n a=int(input())\n i=0\n while 2**i<a:\n i+=1\n print(2**i)\nexcept:\n pass", "import math\nfor _ in range(int(input())) :\n x = int(input())\n ans = 2 ** math.ceil(math.log2(x))\n print(ans)", "# cook your dish here\nT = int(input())\nfor _ in range(T):\n X = int(input())\n ans = X.bit_length()\n if 2**(ans-1)==X:\n print(2**(ans-1))\n continue\n print(2**(ans))", "t=int(input())\nfor _ in range(t):\n n=int(input())\n st=bin(n)\n st=st[2:]\n # i=st.index(\"1\")\n x=len(st)\n # print(2**n)\n if st.count(\"1\")==1:\n print(n)\n else:\n print(2**x)\n \n \n", "# cook your dish here\nimport math\nt = int(input())\nfor i in range(t):\n x = int(input())\n n = math.floor(math.log2(x)) + 1\n if(x == 2**(n-1)):\n print(x)\n else:\n print(2**n)", "T = int(input())\r\nfor i in range(T):\r\n X = input()\r\n binary = bin(int(X) - 1)[2:]\r\n print(2**len(binary))", "t = int(input())\r\nfor _ in range(t):\r\n x = input()\r\n binary = bin(int(x) - 1)[2:]\r\n print(2**len(binary))", "# cook your dish here\nt=int(input())\nc=[]\nfor i in range(t):\n x=int(input())\n b=bin(x).replace(\"0b\",\"\")\n b=str(b)\n ans=\"1\"\n ans+=\"0\"*len(b)\n el=\"1\"\n el+=\"0\"*(len(b)-1)\n #print(ans)\n i=int(ans,2)\n if(el==b):\n c.append(x)\n else:\n c.append(i)\n \n \n \nfor k in c:\n print(k)\n \n\n \n", "for i in range(int(input())):\r\n\tn = int(input())\r\n\tlens = len(str(bin(n))) - 2\r\n\t# print(lens)\r\n\tif(str(bin(n)).count('1') == 1):\r\n\t\tlens-=1\r\n\tprint(1<<lens)\r\n\t# print()\n", "\r\nimport math\r\n\r\nfor _ in range(int(input())):\r\n n=int(input())\r\n\r\n r=math.log2(n)\r\n\r\n if(r!=int(r)):\r\n r=int(r)\r\n r=pow(2,r+1)\r\n else:\r\n r=int(r)\r\n r=pow(2,r)\r\n \r\n print(r)\r\n", "# cook your dish here\nimport math\nfor _ in range(int(input())):\n n = int(input())\n x = 1 \n #print(x<<1)\n while(x<n): \n x = x<<1 \n print(x)", "# cook your dish here\nimport math\ndef exp(x):\n return x > 0 and (x & (x - 1)) == 0\ndef count(number): \n return int((math.log(number)//math.log(2)) + 1);\nfor x in range(int(input())):\n x=int(input())\n a=exp(x)\n if a==True:\n print(x)\n else:\n b=count(x)\n print(2**b)\n", "def is_xor_greater(a, n):\r\n if a^n > n:\r\n return True\r\n else:\r\n return False\r\n\r\n\r\ndef get_don(n):\r\n i = 1\r\n while (True):\r\n if 2 ** i >= n:\r\n break\r\n else:\r\n i += 1\r\n\r\n\r\n return 2**i\r\n\r\nfor t in range(int(input())):\r\n n = int(input().strip())\r\n print(get_don(n))\r\n\r\n\r\n#for i in range(2, 100):\r\n# print(\"n:\", i, \"value:\", get_don(i))\r\n\r\n", "def is_xor_greater(a, n):\r\n if a^n > n:\r\n return True\r\n else:\r\n return False\r\n\r\n\r\ndef get_don(n):\r\n i = 1\r\n while (True):\r\n if 2 ** i >= n:\r\n break\r\n else:\r\n i += 1\r\n\r\n\r\n return 2**i\r\n\r\nfor t in range(int(input())):\r\n n = int(input().strip())\r\n print(get_don(n))\r\n\r\n\r\n#for i in range(2, 100):\r\n# print(\"n:\", i, \"value:\", get_don(i))\r\n\r\n", "t = int(input())\nfor w in range(0,t):\n x = int(input())\n x = x - 1\n for i in range(1,60):\n if x<(2**i):\n print(2**i)\n break", "pow2 = []\nfor i in range(61):\n pow2.append(1<<i)\nfor _ in range(int(input())):\n x = int(input())\n for i in range(61):\n if x <= pow2[i]:\n print(pow2[i])\n break", "for _ in range(int(input())):\r\n x = int(input())\r\n\r\n\r\n n=0\r\n t=0\r\n while(n<x):\r\n n = 2**t\r\n t+=1\r\n print(2**(t-1))"]
{"inputs": [["2", "3", "7"]], "outputs": [["4", "8"]]}
INTERVIEW
PYTHON3
CODECHEF
5,993
09918fae7afe0c196572a9c245ef7f57
UNKNOWN
Given an array of n$n$ integers : A1,A2,...,An$ A_1, A_2,... , A_n$, find the longest size subsequence which satisfies the following property: The xor of adjacent integers in the subsequence must be non-decreasing. -----Input:----- - First line contains an integer n$n$, denoting the length of the array. - Second line will contain n$n$ space separated integers, denoting the elements of the array. -----Output:----- Output a single integer denoting the longest size of subsequence with the given property. -----Constraints----- - 1≤n≤103$1 \leq n \leq 10^3$ - 0≤Ai≤1018$0 \leq A_i \leq 10^{18}$ -----Sample Input:----- 8 1 200 3 0 400 4 1 7 -----Sample Output:----- 6 -----EXPLANATION:----- The subsequence of maximum length is {1, 3, 0, 4, 1, 7} with Xor of adjacent indexes as {2,3,4,5,6} (non-decreasing)
["# cook your dish here\nn=int(input())\nl=[int(i) for i in input().split()]\nxors=[]\nfor i in range(n):\n for j in range(i+1,n):\n xors.append([l[i]^l[j],(i,j)])\nxors.sort()\n\n#print(xors)\nupto=[0]*n \nfor i in range(len(xors)):\n #a=xors[i][0]\n b,c=xors[i][1][0],xors[i][1][1]\n upto[c]=max(upto[c],upto[b]+1)\n \n#print(upto)\n \nprint(max(upto)+1)", "# cook your dish here\nn=int(input())\nl=[int(i) for i in input().split()]\nxors=[]\nfor i in range(n):\n for j in range(i+1,n):\n xors.append([l[i]^l[j],(i,j)])\nxors.sort()\n\n\nupto=[0]*n \nfor i in range(len(xors)):\n #a=xors[i][0]\n b,c=xors[i][1][0],xors[i][1][1]\n upto[c]=max(upto[c],upto[b]+1)\n \n \n \nprint(max(upto)+1)", "n=int(input())\nl=list(map(int,input().split()))\na=[]\nfor i in range(0,n):\n for j in range(i+1,n):\n a.append((l[i]^l[j],(i,j)))\n\na.sort()\ndp=[0]*n\nfor i in range(0,len(a)):\n x=a[i][0]\n left,right=a[i][1][0],a[i][1][1]\n dp[right]=max(dp[left]+1,dp[right])\n\nprint(max(dp)+1)", "# cook your dish here\nn=int(input())\nl=list(map(int,input().split()))\na=[]\nfor i in range(0,n):\n for j in range(i+1,n):\n a.append((l[i]^l[j],(i,j)))\n\na.sort()\ndp=[0]*n\nfor i in range(0,len(a)):\n x=a[i][0]\n left,right=a[i][1][0],a[i][1][1]\n dp[right]=max(dp[left]+1,dp[right])\n\nprint(max(dp)+1)", "n=int(input())\nl=list(map(int,input().split()))\na=[]\nfor i in range(0,n):\n for j in range(i+1,n):\n a.append((l[i]^l[j],(i,j)))\n\na.sort()\ndp=[0]*n\nfor i in range(0,len(a)):\n x=a[i][0]\n left,right=a[i][1][0],a[i][1][1]\n dp[right]=max(dp[left]+1,dp[right])\n\nprint(max(dp)+1)", "# cook your dish here\nn=int(input())\nl=[int(i) for i in input().split()]\nxors=[]\nfor i in range(n):\n for j in range(i+1,n):\n xors.append([l[i]^l[j],(i,j)])\nxors.sort()\n\n\nupto=[0]*n \nfor i in range(len(xors)):\n #a=xors[i][0]\n b,c=xors[i][1][0],xors[i][1][1]\n upto[c]=max(upto[c],upto[b]+1)\n \n \n \nprint(max(upto)+1)", "# cook your dish here\nn=int(input())\nl=[int(i) for i in input().split()]\nxors=[]\nfor i in range(n):\n for j in range(i+1,n):\n xors.append([l[i]^l[j],(i,j)])\nxors.sort()\n\n\nupto=[0]*n \nfor i in range(len(xors)):\n a=xors[i][0]\n b,c=xors[i][1][0],xors[i][1][1]\n upto[c]=max(upto[c],upto[b]+1)\n \n \n \nprint(max(upto)+1)", "n=int(input())\nl=[int(i) for i in input().split()]\nxors=[]\nfor i in range(n):\n for j in range(i+1,n):\n xors.append([l[i]^l[j],(i,j)])\nxors.sort()\nupto=[0]*n \nfor i in range(len(xors)):\n a=xors[i][0]\n b,c=xors[i][1][0],xors[i][1][1]\n upto[c]=max(upto[c],upto[b]+1)\nprint(max(upto)+1)"]
{"inputs": [["8", "1 200 3 0 400 4 1 7"]], "outputs": [["6"]]}
INTERVIEW
PYTHON3
CODECHEF
2,678
2663e865a1a381194d84264ba940ead8
UNKNOWN
The Siruseri Singing Championship is going to start, and Lavanya wants to figure out the outcome before the tournament even begins! Looking at past tournaments, she realizes that the judges care only about the pitches that the singers can sing in, and so she devises a method through which she can accurately predict the outcome of a match between any two singers. She represents various pitches as integers and has assigned a lower limit and an upper limit for each singer, which corresponds to their vocal range. For any singer, the lower limit will always be less than the upper limit. If a singer has lower limit $L$ and upper limit $U$ ($L < U$), it means that this particular singer can sing in all the pitches between $L$ and $U$, that is they can sing in the pitches {$L, L+1, L+2, \ldots, U$}. The lower bounds and upper bounds of all the singers are distinct. When two singers $S_i$ and $S_j$ with bounds ($L_i$, $U_i)$ and ($L_j$, $U_j$) compete against each other, $S_i$ wins if they can sing in every pitch that $S_j$ can sing in, and some more pitches. Similarly, $S_j$ wins if they can sing in every pitch that $S_i$ can sing in, and some more pitches. If neither of those two conditions are met, the match ends up as a draw. $N$ singers are competing in the tournament. Each singer competes in $N$-1 matches, one match against each of the other singers. The winner of a match scores 2 points, and the loser gets no points. But in case of a draw, both the singers get 1 point each. You are given the lower and upper bounds of all the $N$ singers. You need to output the total scores of each of the $N$ singers at the end of the tournament. -----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 every testcase contains a single integer, $N$, which is the number of singers. - $N$ lines follow, the i-th of which contains two integers: $L_i$ and $U_i$, which correspond to the lower bound and upper bound of the i-th singer. -----Output----- For each testcase output a single line containing $N$ integers, the i-th of which should be score of the i-th singer at the end of the tournament. -----Constraints----- - $1 \le T \le 5$ - $2 \le N \le 10^5$ - $1 \le L_i < U_i \le 10^9$ - All the $2*N$ integers (lower bounds and upper bounds) are distinct. -----Subtasks----- Subtask #1 (15 points): $1 \le N \le 10^3$ Subtask #2 (25 points): - $1 \le N \le 10^5$ - It is guaranteed that no match ends in a draw. Subtask #3 (60 points): Original constraints. -----Sample Input----- 2 3 10 20 13 18 15 19 3 10 22 13 21 15 20 -----Sample Output----- 4 1 1 4 2 0 -----Explanation----- Testcase 1: There are three singers, with the lower bounds and upper bounds as (10, 20), (13, 18) and (15, 19). When the first singer and second singer compete against each other in a match, we see that the second singer can sing in the pitches {13, 14, 15, 16, 17, 18}. Whereas the first singer can sing in the pitches {10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20}. So, we see that the first singer can sing everything that the second singer can, and also some other pitches. Hence the first singer wins this match, and gets 2 points. The second singer gets no points from this match. When the first singer and third singer compete against each other in a match, we see that the third singer can sing in the pitches {15, 16, 17, 18, 19}. So again, we see that the first singer can sing everything that the third singer can. Hence the first singer wins this match, and gets 2 points. The third singer gets no points from this match. When the second singer and third singer compete against each other in a match, we see that the second singer can sing in the pitches {13, 14, 15, 16, 17, 18}, whereas the third singer can sing in the pitches {15, 16, 17, 18, 19}. In particular, the second singer can sing in the pitch 14, which the third singer cannot sing in. And the third singer can sing in the pitch 19, which the second singer cannot sing in. So neither of the two conditions are met, and hence this match ends in a draw. Both the second and third singer get 1 point each. Thus at the end of the tournament, the total score of first player is 2 + 2 = 4. Total score of the second player is 0 + 1 = 1. Total score of the third player is 0 + 1 = 1. Hence the output is 4 1 1 Testcase 2: There are three singers, with the lower bounds and upper bounds as (10, 22), (13, 21) and (15, 20). We see that the first singer wins against both second and third singers. And the second singer wins against the third singer. So the final total scores are (2 + 2), (0 + 2), (0 + 0), which is 4 2 0. Note that this would be a valid testcase in Subtask 2, because no match ends in a draw.
["# cook your dish here\nfrom operator import itemgetter\nt=int(input())\nfor _ in range(t):\n n=int(input())\n start=[]\n end=[]\n for i in range(n):\n first, last = map (int, input().split())\n start.append((first, i))\n end.append((last, i))\n score=[0]*n \n start.sort(key=itemgetter(0))\n end.sort(key=itemgetter(0), reverse=True)\n for i in range(n-1):\n score[start[i][1]]+=n-i-1\n score[end[i][1]]+=n-i-1\n print(' '.join([str(i) for i in score]))", "# cook your dish here\nfrom operator import itemgetter\nt=int(input())\nfor _ in range(t):\n n=int(input())\n start=[]\n end=[]\n for i in range(n):\n first, last = map (int, input().split())\n start.append((first, i))\n end.append((last, i))\n score=[0]*n \n start.sort(key=itemgetter(0))\n end.sort(key=itemgetter(0), reverse=True)\n for i in range(n-1):\n score[start[i][1]]+=n-i-1\n score[end[i][1]]+=n-i-1\n print(' '.join([str(i) for i in score]))", "# cook your dish here\ndef tourneyscore(a):\n scorelist=[0 for i in range(len(a))]\n for i in range(len(a)):\n for k in range(i+1,len(a)):\n if a[i][0]<a[k][0]:\n if a[i][1]>a[k][1]:\n scorelist[i]+=2\n else:\n scorelist[i]+=1\n scorelist[k]+=1\n else:\n if a[i][1]<a[k][1]:\n scorelist[k]+=2\n else:\n scorelist[i]+=1\n scorelist[k]+=1\n print(*scorelist, sep = \" \") \n\nfor T in range(int(input())):\n singerlist=[]\n for N in range(int(input())):\n L,U=input().split()\n L,U=int(L),int(U)\n singerlist.append([L,U])\n tourneyscore(singerlist)\n ", "# cook your dish here\ndef tourneyscore(a):\n scorelist=[]\n for i in range(len(a)):\n scorelist.append(0)\n for i in range(len(a)):\n for k in range(i+1,len(a)):\n if a[i][0]<a[k][0]:\n if a[i][1]>a[k][1]:\n scorelist[i]+=2\n else:\n scorelist[i]+=1\n scorelist[k]+=1\n else:\n if a[i][1]<a[k][1]:\n scorelist[k]+=2\n else:\n scorelist[i]+=1\n scorelist[k]+=1\n print(*scorelist, sep = \" \") \n\nfor T in range(int(input())):\n singerlist=[]\n for N in range(int(input())):\n L,U=input().split()\n L,U=int(L),int(U)\n singerlist.append([L,U])\n tourneyscore(singerlist)\n ", "# cook your dish here\ndef tourneyscore(a):\n scorelist=[]\n for i in range(len(a)):\n scorelist.append(0)\n for i in range(len(a)):\n for k in range(i+1,len(a)):\n x=scorelist[i]\n y=scorelist[k]\n if a[i][0]<a[k][0]:\n if a[i][1]>a[k][1]:\n scorelist[i]=x+2\n else:\n scorelist[i]=x+1\n scorelist[k]=y+1\n else:\n if a[i][1]<a[k][1]:\n scorelist[k]=y+2\n else:\n scorelist[i]=x+1\n scorelist[k]=y+1\n print(*scorelist, sep = \" \") \n\nfor T in range(int(input())):\n singerlist=[]\n for N in range(int(input())):\n L,U=input().split()\n L,U=int(L),int(U)\n singerlist.append([L,U])\n tourneyscore(singerlist)\n ", "# cook your dish here\ndef tourneyscore(a):\n scorelist=[]\n for i in range(len(a)):\n scorelist.append(0)\n for i in range(len(a)):\n for k in range(i+1,len(a)):\n x=scorelist[i]\n y=scorelist[k]\n if a[i][0]<a[k][0]:\n if a[i][1]>a[k][1]:\n scorelist[i]=x+2\n else:\n scorelist[i]=x+1\n scorelist[k]=y+1\n elif a[i][0]>a[k][0]:\n if a[i][1]<a[k][1]:\n scorelist[k]=y+2\n else:\n scorelist[i]=x+1\n scorelist[k]=y+1\n print(*scorelist, sep = \" \") \n\nfor T in range(int(input())):\n singerlist=[]\n for N in range(int(input())):\n L,U=input().split()\n L,U=int(L),int(U)\n singerlist.append([L,U])\n tourneyscore(singerlist)\n ", "# cook your dish here\ndef tourneyscore(a):\n scorelist=[]\n for i in range(len(a)):\n scorelist.append(0)\n for i in range(len(a)):\n for k in range(i+1,len(a)):\n x=scorelist[i]\n y=scorelist[k]\n if a[i][0]<a[k][0]and a[i][1]>a[k][1]:\n scorelist[i]=x+2\n elif a[i][0]>a[k][0]and a[i][1]<a[k][1]:\n scorelist[k]=y+2\n else:\n scorelist[i]=x+1\n scorelist[k]=y+1\n print(*scorelist, sep = \" \") \n\nfor T in range(int(input())):\n singerlist=[]\n for N in range(int(input())):\n L,U=input().split()\n L,U=int(L),int(U)\n singerlist.append([L,U])\n tourneyscore(singerlist)", "# cook your dish here\ndef tourneyscore(a):\n scorelist=[]\n for i in range(len(a)):\n scorelist.append(0)\n for i in range(len(a)):\n for k in range(i+1,len(a)):\n x=scorelist[i]\n y=scorelist[k]\n if a[i][0]<a[k][0]and a[i][1]>a[k][1]:\n scorelist[i]=x+2\n elif a[i][0]>a[k][0]and a[i][1]<a[k][1]:\n scorelist[k]=y+2\n else:\n scorelist[i]=x+1\n scorelist[k]=y+1\n for i in range(len(scorelist)):\n print(scorelist[i],end=' ')\n print()\n\nfor T in range(int(input())):\n singerlist=[]\n for N in range(int(input())):\n L,U=input().split()\n L,U=int(L),int(U)\n singerlist.append([L,U])\n tourneyscore(singerlist)", "# cook your dish here\ntestcase = int(input(''))\n\nfor iterate in range(testcase):\n singers = int(input())\n lower_limit = []\n upper_limit = []\n for i in range(singers):\n lower_limit_value, upper_limit_value = map(int, input().split())\n lower_limit.append([lower_limit_value, i])\n upper_limit.append([upper_limit_value, i])\n\n lower_limit.sort(key = lambda x:x[0], reverse = True)\n upper_limit.sort(key = lambda x:x[0])\n score = [0] * singers\n for i in range(singers):\n score[upper_limit[i][1]] += i\n score[lower_limit[i][1]] += i\n print(*score)", "testcase = int(input(''))\n\nfor iterate in range(testcase):\n singers = int(input())\n lower_limit = []\n upper_limit = []\n for i in range(singers):\n lower_limit_value, upper_limit_value = map(int, input().split())\n lower_limit.append([lower_limit_value, i])\n upper_limit.append([upper_limit_value, i])\n\n lower_limit.sort(key = lambda x:x[0], reverse = True)\n upper_limit.sort(key = lambda x:x[0])\n score = [0] * singers\n for i in range(singers):\n score[upper_limit[i][1]] += i\n score[lower_limit[i][1]] += i\n print(*score)", "for _ in range(int(input())):\r\n N = int(input())\r\n start = []\r\n end = []\r\n for i in range(N):\r\n a,b = list(map(int, input().split()))\r\n start.append([a,i])\r\n end.append([b,i])\r\n start.sort()\r\n end.sort()\r\n scores = [0]*N\r\n for i in range(N):\r\n p = start[i]\r\n q = end[i]\r\n scores[p[1]] += (N - i - 1)\r\n scores[q[1]] += i\r\n print(*scores)\r\n", "# less goooooooo\ntry:\n t = int(input())\nexcept:\n return\nfor q in range(t):\n\tn = int(input())\n\tscore = [0] * n\n\tl = []\n\tu = []\n\tfor q in range(n):\n\t\tx,y = map(int, input().split())\n\t\tl.append([x,q])\n\t\tu.append([y,q])\n\n\tl.sort(key = lambda x:x[0], reverse = True)\n\tu.sort(key = lambda x:x[0])\n\tfor i in range(n):\n\t\tscore[u[i][1]] += i\n\t\tscore[l[i][1]] += i\n\n\tprint(*score)", "# less goooooooo\ntry:\n t = int(input())\nexcept:\n return\nfor q in range(t):\n l = []\n n = int(input())\n score = [0] * n\n for w in range(n):\n li = list(map(int , input().split()))\n l.append(li)\n for x in range(n):\n for y in range(x+1,n):\n if l[x][0] < l[y][0] and l[x][1] > l[y][1]:\n score[x] += 2\n elif l[y][0] < l[x][0] and l[y][1] > l[x][1]:\n score[y] += 2\n else:\n score[x] += 1 \n score[y] += 1 \n score = \"\".join(str(e) + \" \" for e in score)\n print(score)", "from itertools import combinations\nT = int(input())\n\nfor case in range(T):\n n = int(input())\n scores = [0]*n\n pitch = []\n for i in range(n):\n l, u = map(int, input().split())\n pitch.append((l,u))\n \n for (i,j) in combinations(list(range(0,n)), 2):\n if pitch[i][0] < pitch[j][0] and pitch[i][1] > pitch[j][1]:\n scores[i] += 2\n elif pitch[i][0] > pitch[j][0] and pitch[i][1] < pitch[j][1]:\n scores[j] += 2\n else:\n scores[i] += 1\n scores[j] += 1\n \n \n \n '''\n for i in range(n):\n for j in range(i+1,n):\n if pitch[i][0] < pitch[j][0] and pitch[i][1] > pitch[j][1]:\n scores[i] += 2\n elif pitch[i][0] > pitch[j][0] and pitch[i][1] < pitch[j][1]:\n scores[j] += 2\n else:\n scores[i] += 1\n scores[j] += 1\n \n ''' \n print(' '.join(str(a) for a in scores))", "T = int(input())\n\nfor case in range(T):\n n = int(input())\n scores = [0]*n\n pitch = []\n for i in range(n):\n l, u = map(int, input().split())\n pitch.append((l,u))\n \n for i in range(n):\n for j in range(i+1,n):\n if pitch[i][0] < pitch[j][0] and pitch[i][1] > pitch[j][1]:\n scores[i] += 2\n elif pitch[i][0] > pitch[j][0] and pitch[i][1] < pitch[j][1]:\n scores[j] += 2\n else:\n scores[i] += 1\n scores[j] += 1\n print(' '.join(str(a) for a in scores))", "def winner(x,y):\r\n if x[0]<y[0]:\r\n if x[1]>=y[1]:\r\n return 1\r\n else:\r\n return 0\r\n elif x[1]>y[1]:\r\n if x[0]<=y[0]:\r\n return 1\r\n else:\r\n return 0\r\n elif x[1]<y[1]:\r\n if x[0]>=y[0]:\r\n return 2\r\n else:\r\n return 0\r\n elif x[0]>y[0]:\r\n if x[1]<=y[1]:\r\n return 2\r\n else:\r\n return 0\r\n else:\r\n return 0\r\n\r\nfor _ in range(int(input())):\r\n n=int(input())\r\n part=[]\r\n for _ in range(n):\r\n part.append(tuple(map(int, input().split())))\r\n score=[0]*n\r\n for i in range(n):\r\n x=part[i]\r\n if i<n-1:\r\n new=part[i+1:]\r\n for y in range(len(new)):\r\n if winner(x,new[y])==0:\r\n score[i]+=1\r\n score[i+y+1]+=1\r\n elif winner(x,new[y])==1:\r\n score[i]+=2\r\n else:\r\n score[i+y+1]+=2\r\n print(*score)", "def winner(x,y):\r\n if x[0]<y[0]:\r\n if x[1]>=y[1]:\r\n return 1\r\n else:\r\n return 0\r\n elif x[1]>y[1]:\r\n if x[0]<=y[0]:\r\n return 1\r\n else:\r\n return 0\r\n elif x[1]<y[1]:\r\n if x[0]>=y[0]:\r\n return 2\r\n else:\r\n return 0\r\n elif x[0]>y[0]:\r\n if x[1]<=y[1]:\r\n return 2\r\n else:\r\n return 0\r\n else:\r\n return 0\r\n\r\nfor _ in range(int(input())):\r\n n=int(input())\r\n part=[]\r\n for _ in range(n):\r\n part.append(tuple(map(int, input().split())))\r\n score=[0]*n\r\n for i in range(n):\r\n x=part[i]\r\n if i<n:\r\n new=part[i+1:]\r\n for y in range(len(new)):\r\n if winner(x,new[y])==0:\r\n score[i]+=1\r\n score[i+y+1]+=1\r\n elif winner(x,new[y])==1:\r\n score[i]+=2\r\n else:\r\n score[i+y+1]+=2\r\n print(*score)", "# cook your dish here\ntry:\n t = int(input())\nexcept:\n return\nfor q in range(t):\n n = int(input())\n ans = [0] * n\n l = []\n for w in range(n):\n lu = list(map(int , input().split()))\n l.append(lu)\n for i in range(n):\n x = l[i]\n for j in range(i+1,n):\n y = l[j]\n if x[0] < y[0] and x[1] > y[1]:\n ans[i] = ans[i] + 2\n elif y[0] < x[0] and y[1] > x[1]:\n ans[j] = ans[j] + 2\n else:\n ans[i] = ans[i] + 1 \n ans[j] = ans[j] + 1 \n s = ''.join((str(e) + \" \") for e in ans)\n print(s)\n", "# cook your dish here\nT = int(input())\nfor i in range(T):\n N = int(input())\n lower =[]\n upper =[]\n points =[]\n for j in range(N):\n inputs = list(map(int,input().split()))\n lower.append(inputs[0])\n upper.append(inputs[1])\n points.append(0)\n for p in range(N):\n for m in range(p+1,N):\n if (lower[p]<lower[m] and upper[p]>=upper[m]) or (lower[p]<=lower[m] and upper[p]>upper[m]):\n points[p] += 2\n elif (lower[p]>lower[m] and upper[p]<=upper[m]) or (lower[p]>=lower[m] and upper[p]<upper[m]):\n points[m] += 2\n else:\n points[p] +=1\n points[m] +=1\n for n in range(N):\n print(points[n],end=\" \")\n print()", "# cook your dish here\nT = int(input())\nfor i in range(T):\n N = int(input())\n lower ={}\n upper ={}\n points ={}\n for j in range(N):\n lower[j],upper[j] = map(int,input().split()) \n points[j] = 0\n for p in range(N):\n for m in range(p+1,N):\n if (lower[p]<lower[m] and upper[p]>=upper[m]) or (lower[p]<=lower[m] and upper[p]>upper[m]):\n points[p] += 2\n elif (lower[p]>lower[m] and upper[p]<=upper[m]) or (lower[p]>=lower[m] and upper[p]<upper[m]):\n points[m] += 2\n else:\n points[p] +=1\n points[m] +=1\n for n in range(N):\n print(points[n],end=\" \")\n print()", "#dt = {} for i in x: dt[i] = dt.get(i,0)+1\n#dt = {k:v for k,v in sorted(x.items(), key=lambda i: i[1])}\nipnl = lambda n: [int(input()) for _ in range(n)]\ninp = lambda :int(input())\nip = lambda :[int(w) for w in input().split()]\n\nfor _ in range(inp()):\n n = inp()\n sco = [0]*n\n x,y = [],[]\n for i in range(n):\n a,b = ip()\n x.append([a,i])\n y.append([b,i])\n x.sort(reverse = True,key = lambda i: i[0])\n y.sort(key = lambda i: i[0])\n for i in range(n):\n sco[x[i][1]] += i\n sco[y[i][1]] += i\n print(*sco)\n\n\n\n", "#dt = {} for i in x: dt[i] = dt.get(i,0)+1\n#dt = {k:v for k,v in sorted(x.items(), key=lambda i: i[1])}\nipnl = lambda n: [int(input()) for _ in range(n)]\ninp = lambda :int(input())\nip = lambda :[int(w) for w in input().split()]\n\nfor _ in range(inp()):\n n = inp()\n tot = [0]*(n+1)\n sco = [0]*n\n x = [ip()+[i] for i in range(n)]\n x.sort(key = lambda i: i[0])\n for i in range(n-1):\n l,r,i1 = x[i][0],x[i][1],x[i][2]\n for j in reversed(list(range(i+1,n))):\n nl,nr,j1 = x[j][0],x[j][1],x[j][2]\n if nl > l:\n if nr <= r:\n sco[i1] += 2\n else:\n sco[i1] += 1\n sco[j1] += 1\n elif nl == l:\n if nr > r:\n sco[j1] += 2\n elif nr == r:\n sco[i1] += 1\n sco[j1] += 1\n else:\n break\n if j > i+1:\n sco[i1] += 2*(j-i)\n print(*sco)\n\n\n\n", "t = int(input())\r\n\r\nfor _ in range(t):\r\n\tn = int(input())\r\n\tlower = []\r\n\tupper = []\r\n\r\n\tfor __ in range(n):\r\n\t\tx,y = map(int, input().split())\r\n\t\tlower.append([x,__])\r\n\t\tupper.append([y,__])\r\n\r\n\tlower.sort(key = lambda x:x[0], reverse = True)\r\n\tupper.sort(key = lambda x:x[0])\r\n\r\n\t#print(lower, upper)\r\n\r\n\tdell = [0]*n\r\n\r\n\tfor i in range(n):\r\n\t\tdell[upper[i][1]] += i\r\n\t\tdell[lower[i][1]] += i\r\n\r\n\tprint(*dell)", "t = int(input())\r\n\r\nfor _ in range(t):\r\n\tn = int(input())\r\n\tdell = []\r\n\tfor __ in range(n):\r\n\t\tdell.append(list(map(int, input().split())))\r\n\tl = [[0]*n for i in range(n)]\r\n\r\n\tfor i in range(n):\r\n\t\tfor j in range(i+1,n):\r\n\t\t\ts1 = dell[i]\r\n\t\t\ts2 = dell[j]\r\n\r\n\t\t\t# check if s1 ka range ke andar s2\r\n\t\t\tif (s1[0]<=s2[0] and s1[1]>s2[1]) or (s1[0]<s2[0] and s1[1]>=s2[1]):\r\n\t\t\t\t# s1 gains\r\n\t\t\t\tl[i][j] += 2\r\n\r\n\t\t\t# check if s2 ka range is andar s1\r\n\t\t\telif (s2[0]<=s1[0] and s2[1]>s1[1]) or (s2[0]<s1[0] and s2[1]>=s1[1]):\r\n\t\t\t\t#s2 gains\r\n\t\t\t\tl[j][i] += 2\r\n\t\t\t\r\n\t\t\t# tied\r\n\t\t\telse:\r\n\t\t\t\t# both gain\r\n\t\t\t\tl[i][j] += 1\r\n\t\t\t\tl[j][i] += 1\r\n\r\n\tfor ele in l:\r\n\t\tprint(sum(ele),end = \" \")\r\n\tprint()"]
{"inputs": [["2", "3", "10 20", "13 18", "15 19", "3", "10 22", "13 21", "15 20"]], "outputs": [["4 1 1", "4 2 0"]]}
INTERVIEW
PYTHON3
CODECHEF
17,697
36a682c15eae1c92a36a37c31dc22cd3
UNKNOWN
Kira likes to play with strings very much. Moreover he likes the shape of 'W' very much. He takes a string and try to make a 'W' shape out of it such that each angular point is a '#' character and each sides has same characters. He calls them W strings. For example, the W string can be formed from "aaaaa#bb#cc#dddd" such as: a a d a # d a b c d a b c d # # He also call the strings which can generate a 'W' shape (satisfying the above conditions) W strings. More formally, a string S is a W string if and only if it satisfies the following conditions (some terms and notations are explained in Note, please see it if you cannot understand): - The string S contains exactly 3 '#' characters. Let the indexes of all '#' be P1 < P2 < P3 (indexes are 0-origin). - Each substring of S[0, P1−1], S[P1+1, P2−1], S[P2+1, P3−1], S[P3+1, |S|−1] contains exactly one kind of characters, where S[a, b] denotes the non-empty substring from a+1th character to b+1th character, and |S| denotes the length of string S (See Note for details). Now, his friend Ryuk gives him a string S and asks him to find the length of the longest W string which is a subsequence of S, with only one condition that there must not be any '#' symbols between the positions of the first and the second '#' symbol he chooses, nor between the second and the third (here the "positions" we are looking at are in S), i.e. suppose the index of the '#'s he chooses to make the W string are P1, P2, P3 (in increasing order) in the original string S, then there must be no index i such that S[i] = '#' where P1 < i < P2 or P2 < i < P3. Help Kira and he won't write your name in the Death Note. Note: For a given string S, let S[k] denote the k+1th character of string S, and let the index of the character S[k] be k. Let |S| denote the length of the string S. And a substring of a string S is a string S[a, b] = S[a] S[a+1] ... S[b], where 0 ≤ a ≤ b < |S|. And a subsequence of a string S is a string S[i0] S[i1] ... S[in−1], where 0 ≤ i0 < i1 < ... < in−1 < |S|. For example, let S be the string "kira", then S[0] = 'k', S[1] = 'i', S[3] = 'a', and |S| = 4. All of S[0, 2] = "kir", S[1, 1] = "i", and S[0, 3] = "kira" are substrings of S, but "ik", "kr", and "arik" are not. All of "k", "kr", "kira", "kia" are subsequences of S, but "ik", "kk" are not. From the above definition of W string, for example, "a#b#c#d", "aaa#yyy#aaa#yy", and "o#oo#ooo#oooo" are W string, but "a#b#c#d#e", "#a#a#a", and "aa##a#a" are not. -----Input----- First line of input contains an integer T, denoting the number of test cases. Then T lines follow. Each line contains a string S. -----Output----- Output an integer, denoting the length of the longest W string as explained before. If S has no W string as its subsequence, then output 0. -----Constraints----- - 1 ≤ T ≤ 100 - 1 ≤ |S| ≤ 10000 (104) - S contains no characters other than lower English characters ('a' to 'z') and '#' (without quotes) -----Example----- Input: 3 aaaaa#bb#cc#dddd acb#aab#bab#accba abc#dda#bb#bb#aca Output: 16 10 11 -----Explanation----- In the first case: the whole string forms a W String. In the second case: acb#aab#bab#accba, the longest W string is acb#aab#bab#accba In the third case: abc#dda#bb#bb#aca, note that even though abc#dda#bb#bb#aca (boldened characters form the subsequence) is a W string of length 12, it violates Ryuk's condition that there should not be any #'s inbetween the 3 chosen # positions. One correct string of length 11 is abc#dda#bb#bb#aca
["def frequency(s,n):\n f=[[0 for i in range(26)]for j in range(n+1)]\n count=0\n for i in range(n):\n if s[i]!=\"#\":\n f[count][ord(s[i])-97]+=1\n else:\n count+=1\n for j in range(26):\n f[count][j]=f[count-1][j]\n return (f,count)\n \ndef solve(s):\n n=len(s)\n f,count=frequency(s,n)\n if count<3:\n return 0\n ans=0\n index=[]\n for i in range(n-1,-1,-1):\n if s[i]==\"#\":\n index.append(i)\n \n for c in range(1,count-2+1):\n if index[-2]==index[-1]+1 or index[-3]==index[-2]+1:\n index.pop()\n continue\n left=max(f[c-1])\n mid1=0\n mid2=0\n right=0\n for j in range(26):\n mid1=max(mid1,f[c][j]-f[c-1][j])\n mid2=max(mid2,f[c+1][j]-f[c][j])\n right=max(right,f[count][j]-f[c+1][j])\n if left and mid1 and mid2 and right:\n ans=max(ans,left+mid1+mid2+right)\n index.pop()\n return ans\n \nfor _ in range(int(input())):\n s=input()\n ans=solve(s)\n if ans:\n print(ans+3)\n else:\n print(0)\n \n "]
{"inputs": [["3", "aaaaa#bb#cc#dddd", "acb#aab#bab#accba", "abc#dda#bb#bb#aca", "", ""]], "outputs": [["16", "10", "11"]]}
INTERVIEW
PYTHON3
CODECHEF
1,200
b70ff101d149d114488d5fc456fb4dfa
UNKNOWN
Zonal Computing Olympiad 2014, 30 Nov 2013 In IPL 2025, the amount that each player is paid varies from match to match. The match fee depends on the quality of opposition, the venue etc. The match fees for each match in the new season have been announced in advance. Each team has to enforce a mandatory rotation policy so that no player ever plays three matches in a row during the season. Nikhil is the captain and chooses the team for each match. He wants to allocate a playing schedule for himself to maximize his earnings through match fees during the season. -----Input format----- Line 1: A single integer N, the number of games in the IPL season. Line 2: N non-negative integers, where the integer in position i represents the fee for match i. -----Output format----- The output consists of a single non-negative integer, the maximum amount of money that Nikhil can earn during this IPL season. -----Sample Input 1----- 5 10 3 5 7 3 -----Sample Output 1----- 23 (Explanation: 10+3+7+3) -----Sample Input 2----- 8 3 2 3 2 3 5 1 3 -----Sample Output 2----- 17 (Explanation: 3+3+3+5+3) -----Test data----- There is only one subtask worth 100 marks. In all inputs: • 1 ≤ N ≤ 2×105 • The fee for each match is between 0 and 104, inclusive. -----Live evaluation data----- There are 12 test inputs on the server during the exam.
["# cook your dish here\nn=int(input())\nl=list(map(int,input().split()))\ntemp=[]\nfor item in l:\n temp.append(item)\nif(n<=3):\n print(sum(temp))\nelse:\n for i in range(3,n):\n temp[i]=l[i]+min(temp[i-1],temp[i-2],temp[i-3])\n res=sum(l)-min(temp[n-1],temp[n-2],temp[n-3])\n print(res)", "n=int(input())\nl=list(map(int,input().split()))\ntemp=[]\nfor i in range(0,len(l)):\n temp.append(0)\ntemp[0]=l[0]\ntemp[1]=l[1]\ntemp[2]=l[2]\nif(n<=3):\n print(sum(temp))\nelse:\n for i in range(3,n):\n temp[i]=l[i]+min(temp[i-1],temp[i-2],temp[i-3])\n res=sum(l)-min(temp[n-1],temp[n-2],temp[n-3])\n print(res)", "# cook your dish here\nn=int(input())\narr=[int(x) for x in input().split()]\ndef solve(i,k): ####k=2 or k=1 of k=0\n if i<0:\n return 0\n ans=0\n if dp[i][k]!=None:\n return dp[i][k]\n if k==2:\n ans=max(ans,solve(i-1,k))\n ans=max(ans,solve(i-1,k-1)+arr[i])\n elif k==1:\n ans=max(ans,solve(i-1,k-1)+arr[i])\n ans=max(ans,solve(i-1,2))\n else:\n ans=max(ans,solve(i-1,2))\n dp[i][k]=ans\n return ans\n\ndp=[[None,None,None] for x in range(n)]\nfor i in range(n):\n solve(i,2)\nprint(dp[-1][-1])", "# cook your dish here\nn=int(input())\narr=list(map(int,input().split()))\ndp=[0]*(n+1)\ndp[0]=0\ndp[1]=arr[0]\ndp[2]=arr[0]+arr[1]\ndp[3]=max(arr[2]+arr[0],arr[1]+arr[2],dp[-1])\n\nfor i in range(4,n+1):\n dp[i]=max(dp[i-1],arr[i-1]+dp[i-2],arr[i-1]+arr[i-2]+dp[i-3])\n# print(dp)/\nprint(dp[-1])\n# if N > 0:\n# sum[0] = Ps[0]\n# if N > 1:\n# sum[1] = Ps[0] + Ps[1]\n# if N > 2:\n# sum[2] = max(Ps[0] + Ps[2], max(sum[1], Ps[1] + Ps[2]))\n\n\n# for i in range(3, N):\n# sum[i] = max(sum[i-2] + Ps[i], max(sum[i-1], sum[i-3] + Ps[i-1] + Ps[i]))\n", "t=int(input())\narr=input().split()\nsum=[]\ni=0\nwhile(i<len(arr)):\n if(i==0):\n sum.append(int(arr[0]))\n elif(i==1):\n sum.append(int(arr[0])+int(arr[1]))\n elif(i==2):\n sum.append(max(sum[i-2]+int(arr[i]),sum[i-1],int(arr[2])+int(arr[1]))) \n else:\n sum.append(max(max(sum[i-1], sum[i-2]+ int(arr[i])), int(arr[i]) +int(arr[i-1]) + sum[i-3]))\n i=i+1\nprint(sum[t-1])", "# cook your dish here\nN = int(input())\nPs= list(map(int, input().strip().split(\" \")))\n#print(Ps)\n\nsum = [0 for i in range(N)]\nif N > 0:\n sum[0] = Ps[0]\nif N > 1:\n sum[1] = Ps[0] + Ps[1]\nif N > 2:\n sum[2] = max(Ps[0] + Ps[2], max(sum[1], Ps[1] + Ps[2]))\n\n\nfor i in range(3, N):\n sum[i] = max(sum[i-2] + Ps[i], max(sum[i-1], sum[i-3] + Ps[i-1] + Ps[i]))\n \n \nprint(sum.pop())\n\"\"\"\n23\n\"\"\"", "n = int(input())\r\nipl = list(map(int, input().split()))\r\n\r\ndp=list()\r\n\r\nfor i in range(1, n+1):\r\n dp.append(0)\r\n\r\nif n == 1:\r\n print(ipl[0])\r\nelif n == 2:\r\n print(ipl[0] + ipl[1])\r\nelif n == 3:\r\n print(max(ipl[0]+ipl[1], max(ipl[0]+ipl[2], ipl[1]+ipl[2])))\r\nelse:\r\n summ = 0\r\n for i in range(0, n):\r\n summ += ipl[i]\r\n \r\n dp[0] = ipl[0]\r\n dp[1] = ipl[1]\r\n dp[2] = ipl[2]\r\n\r\n for i in range(3, n):\r\n dp[i] = ipl[i] + min(dp[i-1], min(dp[i-2], dp[i-3]))\r\n print(summ - min(dp[n-1], min(dp[n-2], dp[n-3])))\r\n", "# cook your dish here\nN = int(input())\nmatches = list(map(int,input().split()))\ngames = matches[:3]\nfor i in range(3,N):\n games.append(min(games[i-1],games[i-2],games[i-3]) + matches[i])\nprint(sum(matches) - min(games[-1],games[-2],games[-3]))\n\n", "# cook your dish here\n\nN = int(input().strip())\nincomes = []\ntotal_sum = 0\nfor i in input().strip().split(\" \"):\n incomes.append(int(i))\n total_sum += int(i)\n\nstored_values = incomes[:3]\nfor i in range(3, N):\n stored_values.append(incomes[i] + min(stored_values[-1], stored_values[-2], stored_values[-3]))\n\nprint(total_sum - min(stored_values[-1], stored_values[-2], stored_values[-3]))\n", "# cook your dish here\nimport sys\nimport bisect\ninput=sys.stdin.readline\nn=int(input())\nl=input().split()\nli=[int(i) for i in l]\nif(n<=2):\n print(sum(li))\n return\ndp=[0 for i in range(n)]\ndp[0]=li[0]\ndp[1]=li[0]+li[1]\ndp[2]=max(dp[1],li[2]+dp[0],li[1]+li[2])\nfor i in range(3,n):\n dp[i]=max(dp[i-1],li[i]+dp[i-2],li[i-1]+li[i]+dp[i-3])\nprint(dp[n-1])\n", "n=int(input())\nlis=list(map(int, input().split()))\ndp=[0]*n\ndp[0]=lis[0]\ndp[1]=lis[1]\ndp[2]=lis[2]\nif(n<3):\n print(sum(lis))\n return\nfor i in range(3 ,len(lis)):\n dp[i]=min(dp[i-1],dp[i-2],dp[i-3])\n dp[i]+=lis[i]\nprint(sum(lis)-min(dp[n-1], dp[n-2], dp[n-3]))\n", "\n# def recursive(List, taken_previous, idx, r) : \n# if idx >= N : return 0\n# if taken_previous :\n# # I am not sure if you should go 2 steps even futher to check. Probably extra recursion\n# return List[idx] + max( recursive(List, False, idx + 2, r + List[idx]), recursive(List, False, idx + 3, r + List[idx]))\n# else :\n# return List[idx] + max( recursive(List, True, idx + 1, r + List[idx]), recursive(List, False, idx + 2, r + List[idx]) )\n \n# N = int(input())\n# fees = list(map(int, input().split()))\n# dp = [-1] * int(1e6)\n\n# def recursive(nums, n) : \n# if n < 0 : return 0\n# elif n == 0 : return nums[0]\n# elif n == 1 : return nums[0] + nums[1]\n# else : \n# if dp[n] != -1 : return dp[n]\n \n# dp[n] = max( recursive(nums, n - 1), \n# recursive(nums, n - 2) + nums[n],\n# recursive(nums, n - 3) + nums[n] + nums[n-1]\n# )\n \n# return dp[n]\n \n \n# if N <= 2 : print(sum(fees))\n# else :\n# r = recursive(fees, N - 1)\n# print(r)\n \n \ndp = [-1] * int(1e6)\n\n\ndef solve(a, d):\n\tif d < 0:\n\t\treturn 0\n\tif d == 0:\n\t\treturn a[0]\n\tif d == 1:\n\t\treturn a[0] + a[1]\n\n\tif dp[d] != -1:\n\t\treturn dp[d]\n\n\tdp[d] = max(\n\t\tsolve(a, d - 1),\n\t\tsolve(a, d - 2) + a[d],\n\t\tsolve(a, d - 3) + a[d] + a[d - 1]\n\t)\n\treturn dp[d]\n\n\ndef main():\n\tfrom sys import stdin, stdout, setrecursionlimit\n\tsetrecursionlimit(int(1e6))\n\trl = stdin.readline\n\n\tn = int(rl())\n\ta = [int(x) for x in rl().split()]\n\n\tif n < 3:\n\t\tstdout.write(str(sum(a)))\n\t\treturn\n\n\tstdout.write(str(solve(a, n - 1)))\n\n\nmain()\n \n\n \n", "# cook your dish here\nno = int(input())\nalls = list(input().split())\ndp = [0]*(no+1)\nif(no==1):\n\tdp[1]=alls[0]\n\tprint(dp[1])\nelif(no==2):\n\tdp[2] = int(alls[1])+int(alls[0])\n\tprint(dp[2])\nelif(no>=3):\n\tdp[1]= int(alls[0])\n\tdp[2] = int(alls[1])+int(alls[0])\n\ta = int(alls[0])+int(alls[1])\t\t\n\tb = int(alls[1])+int(alls[2])\n\tc = int(alls[0])+int(alls[2])\t\t\n\tdp[3] = max(a,b,c)\n\tfor x in range(4,(no+1)):\n\t\td = int(dp[x-2]) + int(alls[x-1])\n\t\te = int(dp[x-1])\n\t\tf = int(dp[x-3]+int(alls[x-2])+int(alls[x-1]))\n\t\tdp[x] = max(d,e,f)\n\tprint(dp[no])\n", "n = int(input())\r\na = list(map(int,input().split()))\r\ndp = [[0]*3 for i in range(n+1)]\r\n\r\nfor i in range(1,n+1):\r\n dp[i][0] = max(dp[i-1])\r\n for j in range(1,3):\r\n dp[i][j] = max(dp[i][j],dp[i-1][j-1] + a[i-1])\r\n\r\nprint(max(dp[-1])) \r\n", "# cook your dish here\nn=int(input())\narray=list(map(int, input().split()))\nappo2=sum(array)\nfor i in range(3,n):\n array[i]+=min([array[i-1],array[i-2],array[i-3]])\nappo=min([array[-1],array[-2],array[-3]])\nprint(appo2-appo)\n", "from sys import stdin, stdout\nimport math,sys,heapq\nfrom itertools import permutations, combinations\nfrom collections import defaultdict,deque,OrderedDict\nfrom os import path\nimport random\nimport bisect as bi\ndef yes():print('YES')\ndef no():print('NO')\nif (path.exists('input.txt')): \n #------------------Sublime--------------------------------------#\n sys.stdin=open('input.txt','r');sys.stdout=open('output.txt','w');\n def I():return (int(input()))\n def In():return(map(int,input().split()))\nelse:\n #------------------PYPY FAst I/o--------------------------------#\n def I():return (int(stdin.readline()))\n def In():return(map(int,stdin.readline().split()))\n#sys.setrecursionlimit(1500)\ndef dict(a):\n d={} \n for x in a:\n if d.get(x,-1)!=-1:\n d[x]+=1\n else:\n d[x]=1\n return d\ndef find_gt(a, x):\n 'Find leftmost value greater than x'\n i = bi.bisect_left(a, x)\n if i != len(a):\n return i\n else: \n return -1\ndef main():\n try:\n n=I()\n l=list(In())\n dp=[[0,0] for x in range(n)]\n if n==1:\n print(l[0])\n elif n==2:\n print(sum(l))\n else:\n dp[2][0]=l[2]+l[1]\n dp[2][1]=l[2]+l[0]\n ma=max(dp[1][0],dp[1][1])\n dp[1][1]=l[1]\n dp[1][0]=l[1]+l[0]\n for i in range(3,n):\n dp[i][0]=l[i]+dp[i-1][1]\n ma=max(dp[i-2][0],dp[i-2][1],ma)\n dp[i][1]=ma+l[i]\n ma=0\n # for i in range(n):\n # print(dp[i][0],end=\" \")\n # print()\n # for i in range(n):\n # print(dp[i][1],end=\" \")\n # print()\n for i in range(n):\n ma=max(dp[i][0],ma,dp[i][1])\n print(ma)\n \n except:\n pass\n \nM = 998244353\nP = 1000000007\n \ndef __starting_point():\n #for _ in range(I()):main()\n for _ in range(1):main()\n__starting_point()", "# cook your dish here\nn = int(input())\nl = list(map(int, input().split()))\n\nif n <=2 :\n print(sum(l))\nelse:\n ml = [l[0], l[0]+l[1], max(l[0]+l[1], l[1]+l[2], l[0]+l[2])]\n for i in range(3, n):\n new = max(ml[i-1], l[i] + ml[i-2], l[i] + l[i-1] + ml[i-3])\n ml.append(new)\n print(ml[-1])", "from sys import stdin,stdout\r\nfor _ in range(1):#int(stdin.readline())):\r\n n=int(stdin.readline())\r\n a=list(map(int,stdin.readline().split()))\r\n con0=con1=con2=0\r\n con1=a[0]\r\n for i in range(1,n):\r\n con0,con1,con2=max(con0,con1,con2),a[i]+con0,a[i]+con1\r\n print(max(con0,con1,con2))", "from sys import stdin,stdout\r\nfor _ in range(1):#int(stdin.readline())):\r\n n=int(stdin.readline())\r\n a=list(map(int,stdin.readline().split()))\r\n con0=con1=con2=0\r\n con1=a[0]\r\n for i in range(1,n):\r\n con0,con1,con2=max(con0,con1,con2),a[i]+con0,a[i]+con1\r\n print(max(con0,con1,con2))", "from sys import stdin,stdout,setrecursionlimit\r\nsetrecursionlimit(10**6)\r\ndef fn(pos,consecutive):\r\n if pos>=n:return 0\r\n if (pos,consecutive) in dp:return dp[pos,consecutive]\r\n take_cur=0\r\n if consecutive+1<3:take_cur=a[pos]+fn(pos+1,consecutive+1)\r\n dp[pos,consecutive]=max(take_cur,fn(pos+1,0))\r\n return dp[pos,consecutive]\r\nfor _ in range(1):#int(stdin.readline())):\r\n n=int(stdin.readline())\r\n a=list(map(int,stdin.readline().split()))\r\n dp={}\r\n print(fn(0,0))", "# cook your dish here\nimport sys\nread = lambda: sys.stdin.readline().strip()\n\n\nn = int(read())\nnums = list(map(int, read().split()))\ndp = [0] * n\ndp[0] = nums[0]\ndp[1] = nums[1]\ndp[2] = nums[2]\ns = sum(nums)\nfor i in range(3, n):\n dp[i] = min(dp[i-1], dp[i-2], dp[i-3]) + nums[i]\n\nprint(s - min(dp[-1], dp[-2], dp[-3]))", "# cook your dish here\nimport sys\nread = lambda: sys.stdin.readline().strip()\n\n\nn = int(read())\nnums = list(map(int, read().split()))\ndp = [0] * n\ndp[0] = nums[0]\ndp[1] = nums[1]\ndp[2] = nums[2]\ns = sum(nums)\nfor i in range(2, n):\n dp[i] = min(dp[i-1], dp[i-2], dp[i-3]) + nums[i]\n\nprint(s - min(dp[-1], dp[-2], dp[-3]))", "# cook your dish here\nN = int(input())\nlist1 = list(map(int,input().split()))\nnextint=[0 for i in range(N)]\nnotnext=[ 0 for i in range(N)]\nnotnext[-1] = list1[-1]\nnextint[-1] = list1[-1]\nnotnext[-2] = list1[-2]\nnextint[-2] = list1[-2]+list1[-1]\nfor j in range(len(list1)-3,-1,-1):\n nextint[j] = max(list1[j]+notnext[j+1], nextint[j+1])\n notnext[j] = list1[j]+max(nextint[j+2],notnext[j+2]) \n#print(\"nextint: \",nextint,\"notnext: \",notnext)\nprint(max(nextint[0],notnext[0]))", "# cook your dish here\r\nN = int(input())\r\nlist1 = list(map(int,input().split()))\r\nnextint=[0 for i in range(N)]\r\nnotnext=[ 0 for i in range(N)]\r\nnotnext[-1] = list1[-1]\r\nnextint[-1] = list1[-1]\r\nnotnext[-2] = list1[-2]\r\nnextint[-2] = list1[-2]+list1[-1]\r\nfor j in range(len(list1)-3,-1,-1):\r\n nextint[j] = max(list1[j]+notnext[j+1], nextint[j+1])\r\n notnext[j] = list1[j]+max(nextint[j+2],notnext[j+2]) \r\n#print(\"nextint: \",nextint,\"notnext: \",notnext)\r\nprint(max(nextint[0],notnext[0]))"]
{"inputs": [["5", "10 3 5 7 3"]], "outputs": [["23", "("]]}
INTERVIEW
PYTHON3
CODECHEF
12,784
63725c1014c3303e2f73cb847af89427
UNKNOWN
Zombies zombies everywhere!! In a parallel world of zombies, there are N zombies. There are infinite number of unused cars, each of same model only differentiated by the their colors. The cars are of K colors. A zombie parent can give birth to any number of zombie-children (possibly zero), i.e. each zombie will have its parent except the head zombie which was born in the winters by combination of ice and fire. Now, zombies are having great difficulties to commute to their offices without cars, so they decided to use the cars available. Every zombie will need only one car. Head zombie called a meeting regarding this, in which he will allow each zombie to select a car for him. Out of all the cars, the head zombie chose one of cars for him. Now, he called his children to choose the cars for them. After that they called their children and so on till each of the zombie had a car. Head zombie knew that it won't be a good idea to allow children to have cars of same color as that of parent, as they might mistakenly use that. So, he enforced this rule during the selection of cars. Professor James Moriarty is a criminal mastermind and has trapped Watson again in the zombie world. Sherlock somehow manages to go there and met the head zombie. Head zombie told Sherlock that they will let Watson free if and only if Sherlock manages to tell him the maximum number of ways in which the cars can be selected by N Zombies among all possible hierarchies. A hierarchy represents parent-child relationships among the N zombies. Since the answer may be large, output the answer modulo 109 + 7. Sherlock can not compute big numbers, so he confides you to solve this for him. -----Input----- The first line consists of a single integer T, the number of test-cases. Each test case consists of two space-separated integers N and K, denoting number of zombies and the possible number of colors of the cars respectively. -----Output----- For each test-case, output a single line denoting the answer of the problem. -----Constraints----- - 1 ≤ T ≤ 100 - 1 ≤ N ≤ 10^9 - 1 ≤ K ≤ 10^9 -----Subtasks----- Subtask #1 : (10 points) - 1 ≤ T ≤ 20 - 1 ≤ N, K ≤ 10 Subtask 2 : (20 points) - 1 ≤ T ≤ 10 - 1 ≤ N, K ≤ 10000 Subtask 3 : (70 points) - 1 ≤ T ≤ 100 - 1 ≤ N, K ≤ 10^9 -----Example----- Input 2 2 2 3 3 Output: 2 12 -----Explanation In the first sample test case, there are 2 zombies. Let us name them Z1 and Z2. Let one hierarchy be one in which Z1 is parent of Z2. There are 2 colors, suppose red and blue. If Z1 takes red, then Z2 should take a blue. If Z1 takes blue, then Z2 should take red. Note that one other possible hierarchy could be one in which Z2 is a parent of Z1. In that hierarchy also, number of possible ways of assigning cars is 2. So there maximum number of possible ways is 2. In the second example, we have 3 Zombies say Z1, Z2, Z3 and cars of 3 colors, suppose red, blue and green. A hierarchy to maximize the number of possibilities is Z1 is the parent of Z2, Z2 is the parent of Z3. Zombie Z1 can choose one of red, blue or green cars. Z2 can choose one of the remaining two colors (as its car's color can not be same as its parent car.). Z3 can also choose his car in two colors, (one of them could be color same as Z1, and other being the color which is not same as cars of both Z1 and Z2.). This way, there can be 12 different ways of selecting the cars. ----- In the first sample test case, there are 2 zombies. Let us name them Z1 and Z2. Let one hierarchy be one in which Z1 is parent of Z2. There are 2 colors, suppose red and blue. If Z1 takes red, then Z2 should take a blue. If Z1 takes blue, then Z2 should take red. Note that one other possible hierarchy could be one in which Z2 is a parent of Z1. In that hierarchy also, number of possible ways of assigning cars is 2. So there maximum number of possible ways is 2. In the second example, we have 3 Zombies say Z1, Z2, Z3 and cars of 3 colors, suppose red, blue and green. A hierarchy to maximize the number of possibilities is Z1 is the parent of Z2, Z2 is the parent of Z3. Zombie Z1 can choose one of red, blue or green cars. Z2 can choose one of the remaining two colors (as its car's color can not be same as its parent car.). Z3 can also choose his car in two colors, (one of them could be color same as Z1, and other being the color which is not same as cars of both Z1 and Z2.). This way, there can be 12 different ways of selecting the cars.
["ways=x=0\nval=10**9\nremi=((10**9)+7)\nt=int(input())\nfor i in range(t):\n n,k=list(map(int,input().split()))\n if t<=100 and n>=1 and k<=val:\n x=(k-1)**(n-1)\n ways=k*x\n ways=ways%remi\n print(ways)\n x=ways=0\n else:\n break", "test = int(input())\nfor i in range (1,test+1):\n a = input().split(\" \")\n n = int(a[0])\n k = int(a[1])\n ans = pow(k-1,n-1,1000000007)\n ans = (ans*k)%1000000007\n print(ans)", "t = int(input());\nfor i in range(0 ,t):\n n = input().split(\" \");\n n1 = int(n[0])\n k = int(n[1])\n ax = pow(k-1,n1-1,1000000007);\n ax = ((ax%1000000007)*(k%1000000007))%1000000007\n print(ax)", "# your code goes here\nimport sys \nt = eval(input())\nfor i in range(0,t):\n a,b = list(map(int, sys.stdin.readline().split(' ')))\n if(b==1):\n print(0)\n else: \n ans=b*((b-1)**(a-1))%1000000007\n print(ans)", "# your code goes here\nt = eval(input())\nfor i in range(0,t):\n a,b=list(map(int,input().split()))\n if(b==1):\n print(0)\n else: \n ans=b*((b-1)**(a-1))\n ans=ans%1000000007\n print(ans)", "t = eval(input(\"\"))\n \nwhile(t>0):\n n,k = list(map(int,input().split()))\n \n if(k==1):\n if(n==1):\n ans=k;\n print(ans)\n \n else:\n ans=k;\n n=n-1\n k=k-1\n p=1\n while(n>0):\n p=p*k\n p=p%1000000007\n n=n-1\n \n \n ans=(ans*p)%1000000007\n \n print(ans)\n \n \n t=t-1 ", "# cook your code here\nmod=10**9\nmod+=7\nt=input()\nt=int(t)\nwhile(t>0):\n z=input()\n N,K=z.split(' ')\n N=int(N)\n K=int(K)\n t-=1\n if (N==1):\n print(K)\n elif (K==1):\n print(0)\n elif (K==2):\n print(2)\n else:\n res=pow(K-1,N-1,mod)\n res*=K\n res%=mod\n print(res)", "# Recursive power function that evaluates in O(log n)\ndef power(x, y):\n if y == 0:\n return 1\n else:\n temp_val = power(x, y // 2)\n if y % 2 == 0:\n return( (temp_val * temp_val) % 1000000007 )\n else:\n return( (temp_val * temp_val * x) % 1000000007 )\n\ndef __starting_point():\n # Read number of cases\n T = int(input())\n # Run a loop for all test cases\n for i in range(T):\n # Read values\n N, K = list(map(int, input().split()))\n\n val = K * power(K - 1, N - 1)\n print(val % 1000000007)\n\n__starting_point()", "# Recursive power function that evaluates in O(log n)\ndef power(x, y):\n if y == 0:\n return 1\n else:\n temp_val = power(x, y // 2)\n if y % 2 == 0:\n return( (temp_val * temp_val) % 1000000007 )\n else:\n return( (temp_val * temp_val * x) % 1000000007 )\n\ndef __starting_point():\n # Read number of cases\n T = int(input())\n # Run a loop for all test cases\n for i in range(T):\n # Read values\n N, K = list(map(int, input().split()))\n\n val = K * power(K - 1, N - 1)\n print(val % 1000000007)\n\n__starting_point()", "from math import pow\nt=input()\nt=int(t)\nwhile t>0:\n n,k=input().split()\n n=int(n)\n k=int(k)\n p=pow(k-1,n-1)\n tot=(k*p)%(pow(10,9)+7)\n print(int(tot))\n t=t-1", "from math import pow\nt=input()\nt=int(t)\nwhile t>0:\n n,k=input().split()\n n=int(n)\n k=int(k)\n p=pow(k-1,n-1)\n tot=(k*p)%(pow(10,9)+7)\n print(int(tot))\n t=t-1", "def __starting_point():\n # Read number of cases\n T = int(input())\n # Run a loop for all test cases\n for i in range(T):\n # Read values\n N, K = list(map(int, input().split()))\n\n val = K * pow(K - 1, N - 1)\n print(val % 1000000007)\n\n__starting_point()", "t = eval(input())\n\nfor _ in range(t):\n n, k = list(map(int, input().split()))\n ans = k*((k-1)**(n-1))\n print(ans%1000000007)", "import math\nMOD=1000000007\ndef fast_exp(base,exp):\n res=1;\n while(exp>0):\n if(exp%2==1):\n res=(res*base)%MOD\n base=(base*base)%MOD\n exp/=2;\n return res\n \nfor t in range(int(input())):\n \n pro=1\n a,b=list(map(int,input().split()))\n #for i in xrange(a):\n pro*=b\n \n pro*=fast_exp((b-1),(a-1))\n \n print(pro%MOD) \n", "mod = 1000000007\nfor _ in range(int(input())):\n n, k = list(map(int, input().split()))\n x = (k%mod) * pow(k-1,n-1, mod)\n print(x%mod)", "import math\n\nfor t in range(int(input())):\n mod=1000000007\n pro=1\n a,b=list(map(int,input().split()))\n for i in range(a):\n if(i==0):\n pro*=b\n else:\n pro*=((b-1))\n if(pro>mod):\n pro%=mod\n print(pro%mod) \n", "t=int(input())\ndef haha(x,y,p):\n ans = 1 \n x = x % p \n while (y > 0): \n if (y % 2!=0):\n ans = (ans*x) % p; \n y = y/2;\n x = (x**2) % p; \n return ans\nwhile t>0:\n t-=1\n n,k=list(map(int,input().split()))\n m=1000000007\n print(((k%m)*(haha(k-1,n-1,m))%m)%m)", "import sys\nt=int(eval(input(\"\")))\nwhile t:\n m,n=list(map(int,sys.stdin.readline().split()))\n prod=n\n prod*=pow((n-1),(m-1),1000000007)\n print(prod%1000000007)\n t-=1\n", "M=1000000007\ndef expmod_iter(a,b,c):\n x = 1\n while(b>0):\n if(b&1==1): x = (x*a)%c\n a=(a*a)%c\n b >>= 1\n return x%c\n\nt=eval(input())\nwhile t>0:\n t-=1\n n,k=list(map(int,input().split()))\n if n>=2 and k<=1:\n print(0)\n else:\n print((k*expmod_iter(k-1,n-1,M))%M)", "import sys\nt=int(eval(input(\"\")))\nwhile t:\n m,n=list(map(int,sys.stdin.readline().split()))\n prod=n\n prod*=(n-1)**(m-1)\n print(prod%1000000007)\n t-=1\n", "import sys\nt=int(eval(input(\"\")))\nwhile t:\n m,n=list(map(int,sys.stdin.readline().split()))\n prod=n\n for i in range(m-1):\n prod*=n-1\n print(prod%1000000007)\n t-=1\n"]
{"inputs": [["2", "2 2", "3 3"]], "outputs": [["2", "12"]]}
INTERVIEW
PYTHON3
CODECHEF
5,243
25a94d763db068ff920047c0f847b341
UNKNOWN
The Chef has a huge square napkin of size 2n X 2n. He folds the napkin n-3 times. Each time he folds its bottom side over its top side, and then its right side over its left side. After each fold, the side length of the napkin is reduced by half. The Chef continues folding until there remains a 8x8 sheet, lying flat on a table. Oh, did I forget to mention that the Chef was cooking a new brown colored curry while folding the napkin. He drops some brown colored gravy onto some cells in the folded 8x8 napkin. When he drops the gravy, it soaks through all the cells below it. Now the Chef unfolds the napkin to its original size. There are now many curry stained brown colored cells in the napkin. They form several separate regions, each of which is connected. Could you help the Chef count how many regions of brown cells are there in the napkin? Note that two cells are adjacent if they share a common edge (they are not considered adjacent if they only share a corner). Two cells are connected if we can go from one cell to the other via adjacent cells. A region is a maximal set of cells such that every two of its cells are connected. Please see the example test case for more details. -----Input----- The first line contains t, the number of test cases (about 50). Then t test cases follow. Each test case has the following form: - The first line contains N (3 ≤ N ≤ 109) - Then, 8 lines follow. Each line is a string of 8 characters, 0 or 1, where 1 denotes a stained brown cell in the folded napkin. -----Output----- For each test case, print a single number that is the number of disconnected brown regions in the unfolded napkin. Since the result may be a very large number, you only need to print its remainder when dividing by 21945. -----Example----- Input: 3 3 01000010 11000001 00000000 00011000 00011000 00010100 00001000 00000000 4 01000010 11000001 00000000 00011000 00011000 00010100 00001000 00000000 1000000000 11111111 11111111 11111111 11111111 11111111 11111111 11111111 11111111 Output: 6 22 1 -----Output details----- Case 1 and 2: There are 6 brown regions in the 8x8 napkin. If we unfold it once, it has 22 brown regions: 11 regions in the top half and 11 regions in the bottom half (as shown in the figure above). Case 3: All cells of the napkin are stained, so there is always one brown region, no matter how many times the Chef unfolds the napkin.
["import sys\nt = int(sys.stdin.readline())\n\ndef identify(x, y):\n rows[x][y] = '2'\n\n r = 0\n if x == 0:\n r |= 1\n elif rows[x-1][y] == '1':\n r |= identify(x-1, y)\n if x == 7:\n r |= 4\n elif rows[x+1][y] == '1':\n r |= identify(x+1, y)\n if y == 0:\n r |= 2\n elif rows[x][y-1] == '1':\n r |= identify(x, y-1)\n if y == 7:\n r |= 8\n elif rows[x][y+1] == '1':\n r |= identify(x, y+1)\n return r\n\nP = 21945\n\nwhile t:\n t-=1\n n = int(sys.stdin.readline())-3\n\n rows = [list(sys.stdin.readline().strip()) for i in range(8)]\n total = 0\n for i in range(8):\n for j in range(8):\n if rows[i][j] == '1':\n r = identify(i,j)\n # print '\\n'.join([''.join(ro) for ro in rows])\n # print r\n if n == 0:\n total += 1\n # print total\n continue\n if r == 0:\n total += pow(2, 2*n, P)\n elif r == 1 or r == 2 or r == 4 or r == 8:\n total += pow(2, 2*n-1, P)\n if r == 1 or r == 2:\n total += pow(2, n, P)\n elif r == 5 or r == 10:\n total += pow(2, n, P)\n elif r == 3 or r == 6 or r == 12 or r == 9:\n total += pow(2, 2*n-2, P)\n if r == 3:\n total += 3 + 2*pow(2, n-1, P) - 2\n elif r == 6 or r == 9:\n total += pow(2, n-1, P)\n elif r == 15:\n total += 1\n else:\n total += pow(2, n-1, P)\n if r == 11 or r == 7:\n total += 1\n # print total\n print(total % P)\n"]
{"inputs": [["3", "3", "01000010", "11000001", "00000000", "00011000", "00011000", "00010100", "00001000", "00000000", "4", "01000010", "11000001", "00000000", "00011000", "00011000", "00010100", "00001000", "00000000", "1000000000", "11111111", "11111111", "11111111", "11111111", "11111111", "11111111", "11111111", "11111111", "", ""]], "outputs": [["6", "22", "1"]]}
INTERVIEW
PYTHON3
CODECHEF
1,899
4b1c26b83a2b85ef5abf58a25a6477e0
UNKNOWN
Alice and Bob created $N$ and $M$ recipes, respectively ($N, M \ge 1$), and submitted them to Chef for evaluation. Each recipe is represented by a string containing only lowercase English letters. Let's denote Alice's recipes by $A_1, A_2, \ldots, A_N$ and Bob's recipes by $B_1, B_2, \ldots, B_M$. Accidentally, Chef mixed up those recipes ― now, he has $L = N+M$ recipes in a sequence $S_1, S_2, \ldots, S_L$. Thankfully, the recipes created by Alice and Bob are distinguishable from each other. It is well-known that for each recipe $s$ created by Alice, the following property holds, and for each recipe created by Bob, it does not hold: For each $1 \le l < r \le |s|$, the substring $s_l, s_{l+1}, \ldots, s_r$ contains at least as many vowels as consonants. The letters 'a', 'e', 'i', 'o', 'u' are vowels, while the other letters are consonants. The score of a candidate who made $K$ recipes is calculated as the product of $\frac{x_c}{fx_c^K}$ for all letters $c$ that occur in at least one of these recipes; here, $x_c$ is the number of recipes which contain the letter $c$ and $fx_c$ is the total number of occurrences of this letter in all $K$ recipes. Let's denote the scores of Alice and Bob by $sc_A$ and $sc_B$ respectively. Chef wants to know their ratio $sc_A/sc_B$. We know that Chef is a legendary cook, but he is not very good at calculating, so he is asking you to find that number. -----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 $L$. - $L$ lines follow. For each valid $i$, the $i$-th of these lines contains a single string $S_i$. -----Output----- For each test case, if the ratio of scores exceeds $10^7$, print a single line containing the string "Infinity" (without quotes); otherwise, print a single line containing one real number $sc_A/sc_B$. Your answer will be considered correct if its absolute or relative error does not exceed $10^{-6}$. It is guaranteed that $sc_A/sc_B$ does not lie in the range $10^7 \pm 10$. -----Constraints----- - $1 \le T \le 10^5$ - $2 \le L \le 10^5$ - $2 \le |S_i| \le 10^5$ for each valid $i$ - for each valid $i$, $S_i$ contains only lowercase English letters - the sum of $|S_1| + |S_2| + \ldots + |S_L|$ over all test cases does not exceed $10^7$ -----Subtasks----- Subtask #1 (25 points): - $L \le 10$ - $|S_i| \le 10$ for each valid $i$ Subtask #2 (75 points): original constraints -----Example Input----- 2 4 aba abc bab aac 3 aba baab abc -----Example Output----- 1.1250000 0.0277778 -----Explanation----- Example case 1: The recipes "aba" and "aac" are created by Alice, while the recipes "abc" and "bab" are created by Bob. The scores are: - $sc_A = \frac{x_a}{fx_a^N} \cdot \frac{x_b}{fx_b^N} \cdot \frac{x_c}{fx_c^N} = \frac{2}{4^2} \cdot \frac{1}{1^2} \cdot \frac{1}{1^2} = \frac{1}{8}$ - $sc_B = \frac{x_a}{fx_a^M} \cdot \frac{x_b}{fx_b^M} \cdot \frac{x_c}{fx_c^M} = \frac{2}{2^2} \cdot \frac{2}{3^2} \cdot \frac{1}{1^2} = \frac{1}{9}$ - $\frac{sc_A}{sc_B} = \frac{1/8}{1/9} = 1.125$
["# v = [\"a\",\"e\",\"i\",\"o\",\"u\"]\n# for _ in range(int(input())):\n# n = int(input())\n# a,b = [],[]\n# for i in range(n):\n# s = input()\n# isa = True\n# for j in range(1,len(s) - 1):\n# if(s[j] in v):\n# if(s[j - 1] not in v and s[j + 1] not in v):\n# isa = False\n# else:\n# if(s[j - 1] not in v or s[j + 1] not in v):\n# isa = False\n# if(not isa):\n# break\n# if(s[0] not in v and s[1] not in v):\n# isa = False\n# if(s[-1] not in v and s[-2] not in v):\n# isa = False\n# if(isa):\n# a.append(s)\n# else:\n# b.append(s)\n# dicta,dictb = {},{}\n# for i in a:\n# freq = {}\n# for j in i:\n# if(j in freq):\n# freq[j] += 1\n# else:\n# freq[j] = 1\n# for j in freq:\n# if(j not in dicta):\n# dicta[j] = (1,freq[j])\n# else:\n# dicta[j] = (dicta[j][0] + 1,dicta[j][1] + freq[j])\n# for i in b:\n# freq = {}\n# for j in i:\n# if(j in freq):\n# freq[j] += 1\n# else:\n# freq[j] = 1\n# for j in freq:\n# if(j not in dictb):\n# dictb[j] = (1,freq[j])\n# else:\n# dictb[j] = (dictb[j][0] + 1,dictb[j][1] + freq[j])\n# ans = 1\n# for i in dicta:\n# ans *= dicta[i][0]\n# for i in dictb:\n# ans /= dictb[i][0]\n# x,y = 1,1\n# for i in dictb:\n# x *= dictb[i][1]\n# for i in dicta:\n# y *= dicta[i][1]\n# alice,bob = len(a),len(b)\n# for i in range(bob):\n# while(alice > 0 and ans > 10**7):\n# ans /= y\n# alice -= 1\n# ans *= x\n# if(ans > 10**7 and alice == 0):\n# break\n# while(alice > 0):\n# ans /= y\n# if(ans < 1 and alice > 100):\n# ans = 0\n# break\n# alice -= 1\n# if(ans > 10**7):\n# print(\"Infinity\")\n# else:\n# print(ans)\n# #partailly correct [75 pts]\n#sys.stdin.readline() and sys.stdout.write() are faster I/O methods than input() \u00a0\u00a0\u00a0\u00a0and print()\nfrom sys import stdin\nz=['a','i','e','o','u']\nt=int(stdin.readline())\nwhile(t>0):\n t-=1\n n=int(stdin.readline())\n alice=[]\n bob=[]\n for j in range(n):\n s=str(stdin.readline().strip(\"\\n\"))\n # print(s)\n isalice=True\n for i in range(1,len(s)-1):\n if(s[i] in z):\n if(s[i-1] not in z and s[i+1] not in z):\n isalice=False\n else:\n if(s[i-1] not in z or s[i+1] not in z):\n isalice=False\n if(not isalice):\n break\n if(s[0] not in z and s[1] not in z):\n isalice=False\n if(s[-1] not in z and s[-2] not in z):\n isalice=False\n if(isalice):\n alice.append(s)\n else:\n bob.append(s)\n ali={}\n bo={}\n for i in alice:\n d={}\n for j in i:\n if(j in d):\n d[j]+=1\n else:\n d[j]=1\n for j in d:\n if j not in ali:\n ali[j]=(1,d[j])\n else:\n ali[j]=(ali[j][0]+1,ali[j][1]+d[j])\n for i in bob:\n d={}\n for j in i:\n if(j in d):\n d[j]+=1\n else:\n d[j]=1\n for j in d:\n if j not in bo:\n bo[j]=(1,d[j])\n else:\n\n bo[j]=(bo[j][0]+1,bo[j][1]+d[j])\n ans=1\n for i in ali:\n ans*=ali[i][0]\n for i in bo:\n ans=ans/bo[i][0]\n x=1\n y=1\n\n for i in bo:\n x=x*bo[i][1]\n for i in ali:\n y=y*ali[i][1]\n # print(x,y)\n alice=len(alice)\n bob=len(bob)\n for i in range(bob):\n while(alice>0 and ans>10000000):\n ans=ans/y\n alice-=1\n ans*=x\n if(ans>10000000 and alice==0):\n break\n while(alice>0):\n ans=ans/y\n if(ans<1 and alice>100):\n ans=0\n break\n alice-=1\n if(ans>10000000):\n print(\"Infinity\")\n else:\n print(ans)\n#AC\n", "# v = [\"a\",\"e\",\"i\",\"o\",\"u\"]\n# for _ in range(int(input())):\n# n = int(input())\n# a,b = [],[]\n# for i in range(n):\n# s = input()\n# isa = True\n# for j in range(1,len(s) - 1):\n# if(s[j] in v):\n# if(s[j - 1] not in v and s[j + 1] not in v):\n# isa = False\n# else:\n# if(s[j - 1] not in v or s[j + 1] not in v):\n# isa = False\n# if(not isa):\n# break\n# if(s[0] not in v and s[1] not in v):\n# isa = False\n# if(s[-1] not in v and s[-2] not in v):\n# isa = False\n# if(isa):\n# a.append(s)\n# else:\n# b.append(s)\n# dicta,dictb = {},{}\n# for i in a:\n# freq = {}\n# for j in i:\n# if(j in freq):\n# freq[j] += 1\n# else:\n# freq[j] = 1\n# for j in freq:\n# if(j not in dicta):\n# dicta[j] = (1,freq[j])\n# else:\n# dicta[j] = (dicta[j][0] + 1,dicta[j][1] + freq[j])\n# for i in b:\n# freq = {}\n# for j in i:\n# if(j in freq):\n# freq[j] += 1\n# else:\n# freq[j] = 1\n# for j in freq:\n# if(j not in dictb):\n# dictb[j] = (1,freq[j])\n# else:\n# dictb[j] = (dictb[j][0] + 1,dictb[j][1] + freq[j])\n# ans = 1\n# for i in dicta:\n# ans *= dicta[i][0]\n# for i in dictb:\n# ans /= dictb[i][0]\n# x,y = 1,1\n# for i in dictb:\n# x *= dictb[i][1]\n# for i in dicta:\n# y *= dicta[i][1]\n# alice,bob = len(a),len(b)\n# for i in range(bob):\n# while(alice > 0 and ans > 10**7):\n# ans /= y\n# alice -= 1\n# ans *= x\n# if(ans > 10**7 and alice == 0):\n# break\n# while(alice > 0):\n# ans /= y\n# if(ans < 1 and alice > 100):\n# ans = 0\n# break\n# alice -= 1\n# if(ans > 10**7):\n# print(\"Infinity\")\n# else:\n# print(ans)\n# #partailly correct [75 pts]\n#sys.stdin.readline() and sys.stdout.write() are faster I/O methods than input() \u00a0\u00a0\u00a0\u00a0and print()\nfrom sys import stdin\nz=['a','i','e','o','u']\nt=int(stdin.readline())\nwhile(t>0):\n t-=1\n n=int(stdin.readline())\n alice=[]\n bob=[]\n for j in range(n):\n s=str(stdin.readline().strip(\"\\n\"))\n # print(s)\n isalice=True\n for i in range(1,len(s)-1):\n if(s[i] in z):\n if(s[i-1] not in z and s[i+1] not in z):\n isalice=False\n else:\n if(s[i-1] not in z or s[i+1] not in z):\n isalice=False\n if(not isalice):\n break\n if(s[0] not in z and s[1] not in z):\n isalice=False\n if(s[-1] not in z and s[-2] not in z):\n isalice=False\n if(isalice):\n alice.append(s)\n else:\n bob.append(s)\n ali={}\n bo={}\n for i in alice:\n d={}\n for j in i:\n if(j in d):\n d[j]+=1\n else:\n d[j]=1\n for j in d:\n if j not in ali:\n ali[j]=(1,d[j])\n else:\n ali[j]=(ali[j][0]+1,ali[j][1]+d[j])\n for i in bob:\n d={}\n for j in i:\n if(j in d):\n d[j]+=1\n else:\n d[j]=1\n for j in d:\n if j not in bo:\n bo[j]=(1,d[j])\n else:\n\n bo[j]=(bo[j][0]+1,bo[j][1]+d[j])\n ans=1\n for i in ali:\n ans*=ali[i][0]\n for i in bo:\n ans=ans/bo[i][0]\n x=1\n y=1\n\n for i in bo:\n x=x*bo[i][1]\n for i in ali:\n y=y*ali[i][1]\n # print(x,y)\n alice=len(alice)\n bob=len(bob)\n for i in range(bob):\n while(alice>0 and ans>10000000):\n ans=ans/y\n alice-=1\n ans*=x\n if(ans>10000000 and alice==0):\n break\n while(alice>0):\n ans=ans/y\n if(ans<1 and alice>100):\n ans=0\n break\n alice-=1\n if(ans>10000000):\n print(\"Infinity\")\n else:\n print(ans)\n#AC\n", "v = [\"a\",\"e\",\"i\",\"o\",\"u\"]\nfor _ in range(int(input())):\n n = int(input())\n a,b = [],[]\n for i in range(n):\n s = input()\n isa = True\n for j in range(1,len(s) - 1):\n if(s[j] in v):\n if(s[j - 1] not in v and s[j + 1] not in v):\n isa = False\n else:\n if(s[j - 1] not in v or s[j + 1] not in v):\n isa = False\n if(not isa):\n break\n if(s[0] not in v and s[1] not in v):\n isa = False\n if(s[-1] not in v and s[-2] not in v):\n isa = False\n if(isa):\n a.append(s)\n else:\n b.append(s)\n dicta,dictb = {},{}\n for i in a:\n freq = {}\n for j in i:\n if(j in freq):\n freq[j] += 1\n else:\n freq[j] = 1\n for j in freq:\n if(j not in dicta):\n dicta[j] = (1,freq[j])\n else:\n dicta[j] = (dicta[j][0] + 1,dicta[j][1] + freq[j])\n for i in b:\n freq = {}\n for j in i:\n if(j in freq):\n freq[j] += 1\n else:\n freq[j] = 1\n for j in freq:\n if(j not in dictb):\n dictb[j] = (1,freq[j])\n else:\n dictb[j] = (dictb[j][0] + 1,dictb[j][1] + freq[j])\n ans = 1\n for i in dicta:\n ans *= dicta[i][0]\n for i in dictb:\n ans /= dictb[i][0]\n x,y = 1,1\n for i in dictb:\n x *= dictb[i][1]\n for i in dicta:\n y *= dicta[i][1]\n alice,bob = len(a),len(b)\n for i in range(bob):\n while(alice > 0 and ans > 10**7):\n ans /= y\n alice -= 1\n ans *= x\n if(ans > 10**7 and alice == 0):\n break\n while(alice > 0):\n ans /= y\n if(ans < 1 and alice > 100):\n ans = 0\n break\n alice -= 1\n if(ans > 10**7):\n print(\"Infinity\")\n else:\n print(ans)\n#partailly correct [75 pts]\n", "from sys import stdin\nz=['a','i','e','o','u']\nt=int(stdin.readline())\nwhile(t>0):\n t-=1\n n=int(stdin.readline())\n alice=[]\n bob=[]\n for j in range(n):\n s=str(stdin.readline().strip(\"\\n\"))\n # print(s)\n isalice=True\n for i in range(1,len(s)-1):\n if(s[i] in z):\n if(s[i-1] not in z and s[i+1] not in z):\n isalice=False\n else:\n if(s[i-1] not in z or s[i+1] not in z):\n isalice=False\n if(not isalice):\n break\n if(s[0] not in z and s[1] not in z):\n isalice=False\n if(s[-1] not in z and s[-2] not in z):\n isalice=False\n if(isalice):\n alice.append(s)\n else:\n bob.append(s)\n ali={}\n bo={}\n for i in alice:\n d={}\n for j in i:\n if(j in d):\n d[j]+=1\n else:\n d[j]=1\n for j in d:\n if j not in ali:\n ali[j]=(1,d[j])\n else:\n ali[j]=(ali[j][0]+1,ali[j][1]+d[j])\n for i in bob:\n d={}\n for j in i:\n if(j in d):\n d[j]+=1\n else:\n d[j]=1\n for j in d:\n if j not in bo:\n bo[j]=(1,d[j])\n else:\n\n bo[j]=(bo[j][0]+1,bo[j][1]+d[j])\n ans=1\n for i in ali:\n ans*=ali[i][0]\n for i in bo:\n ans=ans/bo[i][0]\n x=1\n y=1\n\n for i in bo:\n x=x*bo[i][1]\n for i in ali:\n y=y*ali[i][1]\n # print(x,y)\n alice=len(alice)\n bob=len(bob)\n for i in range(bob):\n while(alice>0 and ans>10000000):\n ans=ans/y\n alice-=1\n ans*=x\n if(ans>10000000 and alice==0):\n break\n while(alice>0):\n ans=ans/y\n if(ans<1 and alice>100):\n ans=0\n break\n alice-=1\n if(ans>10000000):\n print(\"Infinity\")\n else:\n print(ans)", "def printf(a):\n print(a)\n\ndef enter_int():\n a = int(input())\n return a\n\ndef enter_str():\n a = input()\n return a \n\nv = [\"a\",\"e\",\"i\",\"o\",\"u\"]\nfor _ in range(enter_int()):\n n = enter_int()\n a,b = [],[]\n for i in range(n):\n s = enter_str()\n isa = True\n for j in range(1,len(s) - 1):\n if(s[j] in v):\n if(s[j - 1] not in v and s[j + 1] not in v):\n isa = False\n else:\n if(s[j - 1] not in v or s[j + 1] not in v):\n isa = False\n if(not isa):\n break\n if(s[0] not in v and s[1] not in v):\n isa = False\n if(s[-1] not in v and s[-2] not in v):\n isa = False\n if(isa):\n a.append(s)\n else:\n b.append(s)\n dicta,dictb = {},{}\n for i in a:\n freq = {}\n for j in i:\n if(j in freq):\n freq[j] += 1\n else:\n freq[j] = 1\n for j in freq:\n if(j not in dicta):\n dicta[j] = (1,freq[j])\n else:\n dicta[j] = (dicta[j][0] + 1,dicta[j][1] + freq[j])\n for i in b:\n freq = {}\n for j in i:\n if(j in freq):\n freq[j] += 1\n else:\n freq[j] = 1\n for j in freq:\n if(j not in dictb):\n dictb[j] = (1,freq[j])\n else:\n dictb[j] = (dictb[j][0] + 1,dictb[j][1] + freq[j])\n ans = 1\n for i in dicta:\n ans *= dicta[i][0]\n for i in dictb:\n ans /= dictb[i][0]\n x,y = 1,1\n for i in dictb:\n x *= dictb[i][1]\n for i in dicta:\n y *= dicta[i][1]\n alice,bob = len(a),len(b)\n for i in range(bob):\n while(alice > 0 and ans > 10**7):\n ans /= y\n alice -= 1\n ans *= x\n if(ans > 10**7 and alice == 0):\n break\n while(alice > 0):\n ans /= y\n if(ans < 1 and alice > 100):\n ans = 0\n break\n alice -= 1\n if(ans > 10**7):\n printf(\"Infinity\")\n else:\n printf(ans)", "import math\ndef score(df):\n res,fx,li2,x = {} ,1,{},1\n for val in df:\n for key in val:\n if key not in res:res[key]=1\n else:res[key]+=1\n for val in res.values():fx=fx*val \n for val in res:\n li2[val]=0\n for i in df:\n if val in i:li2[val]+=1 \n for val in li2: x *= li2[val]\n return [x,fx]\ndef prog(li,al,bo):\n for cur in li:\n prev,f = -1,0\n for j in range(len(cur)):\n if cur[j] not in ['a','e','i','o','u']:\n if prev==-1:prev = j\n else:\n if abs(prev-j)==2 or abs(prev-j)==1:\n f = 1\n break\n else:prev = j\n if f==1:bo.append(cur)\n else:al.append(cur) \n sca,scb = score(al),score(bo)\n ans1 = math.log10(sca[0])+len(bo)*math.log10(scb[1])\n ans2 = math.log10(scb[0])+len(al)*(math.log10(sca[1]))\n return (ans1-ans2 ) \nfor i in range(int(input())):\n li,x =[],int(input())\n for i in range(x):li.append(input())\n final =prog(li,[],[])\n print(\"Infinity\") if final >7.0 else print(pow(10,final))", "# cook your dish here\nimport math\nimport decimal\ndecimal.getcontext().prec = 1000\n\nt=int(input())\n\nfor _ in range(t):\n\n l=int(input())\n alice=[]\n bob=[]\n alice_all=\"\"\n bob_all=\"\"\n vowels=['a','e','i','o','u']\n for i in range(l):\n temp=input()\n consonant_index=-1\n for j in range(len(temp)):\n if temp[j] in vowels:\n continue\n else:\n if consonant_index==-1:\n consonant_index=j\n else:\n if j-consonant_index<=2:\n bob.append(temp)\n bob_all=bob_all+temp\n break\n else:\n consonant_index=j\n else:\n alice.append(temp)\n alice_all=alice_all+temp\n\n if l<=10:\n n=len(alice)\n m=len(bob)\n\n score_A,score_B=1,1\n x_a,x_b=1,1\n fx_a,fx_b=1,1\n for i in range(97,123):\n char=chr(i)\n if char in alice_all:\n rec_a=[x for x in alice if char in x]\n x_a*=len(rec_a)\n fx_a=fx_a * alice_all.count(char)\n \n\n if char in bob_all:\n rec_b=[x for x in bob if char in x]\n x_b*=len(rec_b)\n fx_b=fx_b * bob_all.count(char)\n\n fx_a=math.pow(fx_a,n)\n fx_b=math.pow(fx_b,m) \n score_A=x_a/fx_a\n score_B=x_b/fx_b\n ans=score_A/score_B\n if ans>10000000:\n print(\"Infinity\")\n else:\n print(\"{0:.9f}\".format(ans))\n else:\n\n n=decimal.Decimal(len(alice))\n m=decimal.Decimal(len(bob))\n\n score_A=decimal.Decimal(1).quantize(decimal.Decimal('0.0000000001'))\n score_B=decimal.Decimal(1).quantize(decimal.Decimal('0.0000000001'))\n x_a=decimal.Decimal(1).quantize(decimal.Decimal('0.0000000001'))\n x_b=decimal.Decimal(1).quantize(decimal.Decimal('0.0000000001'))\n denom_a=decimal.Decimal(1).quantize(decimal.Decimal('0.0000000001'))\n denom_b=decimal.Decimal(1).quantize(decimal.Decimal('0.0000000001'))\n fx_a=decimal.Decimal(1).quantize(decimal.Decimal('0.0000000001'))\n fx_b=decimal.Decimal(1).quantize(decimal.Decimal('0.0000000001'))\n ans=decimal.Decimal(1).quantize(decimal.Decimal('0.0000000001'))\n charInA=''.join(sorted(set(alice_all)))\n charInB=''.join(sorted(set(bob_all)))\n ctx=decimal.getcontext().copy()\n ctx.Emax=decimal.MAX_EMAX\n ctx.Emin=decimal.MIN_EMIN\n ctx.prec=100\n\n\n for i in charInA:\n rec_a=[x for x in alice if i in x]\n if len(rec_a)>0:\n x_a=ctx.multiply(x_a,len(rec_a))\n fx_a=ctx.multiply(fx_a,alice_all.count(i))\n\n for i in charInB:\n rec_b=[x for x in bob if i in x]\n if len(rec_b)>0:\n x_b=ctx.multiply(x_b,len(rec_b))\n fx_b=ctx.multiply(fx_b,bob_all.count(i))\n \n denom_a=ctx.power(fx_a,n)\n denom_b=ctx.power(fx_b,m)\n score_A=ctx.divide(x_a,denom_a)\n score_B=ctx.divide(x_b,denom_b)\n \n ans=ctx.divide(score_A,score_B)\n\n if ans>10000000:\n print(\"Infinity\")\n else:\n print(\"{0:.9f}\".format(ans))", "#RAJ JAIN\n\nimport decimal\ndecimal.getcontext().prec = 16\ndecimal.getcontext().Emin = -1000000000\ndecimal.getcontext().Emax = 1000000000\n\ndef vowel(x):\n return x in 'aeiou'\n\ndef is_alice(s):\n if not vowel(s[0]) and not vowel(s[1]):\n return False\n\n for i in range(2, len(s)):\n if not vowel(s[i]) and (not vowel(s[i - 1]) or not vowel(s[i - 2])):\n return False\n\n return True\n\ndef fast_exp(x, p):\n x = decimal.Decimal(x)\n ans = decimal.Decimal(1)\n while p > 0:\n if p & 1:\n ans *= x\n x *= x\n p >>= 1\n return ans\n\ndef get_score(strings):\n k = len(strings)\n xc = [0] * 26\n fxc = [0] * 26\n\n for s in strings:\n f = [0] * 26\n for x in s:\n f[ord(x) - 97] += 1\n\n for i in range(26):\n if f[i] > 0:\n xc[i] += 1\n fxc[i] += f[i]\n\n pxc, pfxc = 1, 1\n for i in range(26):\n if xc[i] > 0:\n pxc *= xc[i]\n pfxc *= fxc[i]\n\n return decimal.Decimal(pxc) / fast_exp(pfxc, k)\n \nfor _ in range(int(input())):\n alice, bob = [], []\n for _ in range(int(input())):\n inp = input()\n if is_alice(inp):\n alice.append(inp)\n else:\n bob.append(inp)\n\n alice_score = get_score(alice)\n bob_score = get_score(bob)\n\n ratio = alice_score / bob_score\n if ratio > 10000000.0:\n print('Infinity')\n else:\n print(ratio)\n", "import math\nfrom math import log10\n\ndef score(df):\n# a=\"\"\n n=len(df)\n \n #calulation of fxc\n# for val in df:\n# a=a+val \n \n \n res = {} \n for val in df:\n for key in val:\n if key not in res:\n res[key]=1\n else:\n res[key]+=1\n \n \n# print(res)\n fx=1\n for val in res.values():\n fx=fx*val\n \n li2={}\n #calculation of xc\n for val in res:\n li2[val]=0\n for i in df:\n if val in i:\n li2[val]+=1\n \n x=1\n for val in li2:\n \n x=x*li2[val]\n# print(x,fx,\"x\",\"fc\")\n return [x,fx]\n\n\ndef prog(li):\n al=[]\n bo=[]\n for cur in li:\n prev = -1\n f = 0\n for j in range(len(cur)):\n if cur[j] not in ['a','e','i','o','u']:\n if prev==-1:\n prev = j\n else:\n if abs(prev-j)==2 or abs(prev-j)==1:\n f = 1\n break\n else:\n prev = j\n if f==1:\n bo.append(cur)\n else:\n al.append(cur)\n \n# print(al)\n# print(bo)\n sca=score(al)\n scb=score(bo)\n# print(sca,scb,\"dd\")\n ans1 = log10(sca[0])+len(bo)*log10(scb[1])\n ans2 = log10(scb[0])+len(al)*(log10(sca[1]))\n ans1 = ans1-ans2\n# print(ans1)\n \n return ans1\n \n \n \n \nt = int(input())\nfor i in range(0,t):\n li=[]\n x= int(input())\n for i in range(0,x):\n e=input()\n li.append(e)\n final =prog(li)\n if final >7.0:\n print(\"Infinity\")\n else:\n print(pow(10,final))", "from math import log10\nimport math\nfor _ in range(int(input())):\n n = int(input())\n alice = []\n bob = []\n words = []\n for i in range(n):\n words.append(input())\n for cur in words:\n prev = -1\n f = 0\n for j in range(len(cur)):\n if cur[j] not in ['a','e','i','o','u']:\n if prev==-1:\n prev = j\n else:\n if abs(prev-j)==2 or abs(prev-j)==1:\n f = 1\n break\n else:\n prev = j\n if f==1:\n bob.append(cur)\n else:\n alice.append(cur)\n \n# print(alice)\n# print(bob)\n # Alice \n n1 = len(alice)\n freq_a = {}\n for i in alice:\n for j in i:\n if j not in freq_a:\n freq_a[j] = 1\n else:\n freq_a[j]+=1\n num_a = {}\n for i in freq_a:\n num_a[i] = 0\n for j in alice:\n if i in j:\n num_a[i]+=1\n# print(freq_a)\n# print(num_a)\n num1 = 1\n den1 = 1\n for i in num_a:\n num1 = (num1*num_a[i])\n den1 = den1*freq_a[i]\n \n \n # Bob alphabets\n n2 = len(bob)\n freq_b = {}\n for i in bob:\n for j in i:\n if j not in freq_b:\n freq_b[j] = 1\n else:\n freq_b[j]+=1\n num_b = {}\n for i in freq_b:\n num_b[i] = 0\n for j in bob:\n if i in j:\n num_b[i]+=1\n num2 = 1\n den2 = 1\n for i in num_b:\n num2 = (num2*num_b[i])\n den2 = den2*freq_b[i]\n # # if n<=10:\n # if n2>=n1:\n # ans = pow(den2/den1,n1)*pow(den2,n2-n1)\n # else:\n # ans = pow(den2/den1,n2)*pow(den1,-(n1-n2))\n # t = num1/num2\n # ans = ans*t\n # if ans>10000000.0:\n # print(\"Infinity\")\n # else:\n # print(ans)\n # else:\n ans1 = log10(num1)+n2*log10(den2)\n ans2 = log10(num2)+n1*(log10(den1))\n ans1 = ans1-ans2\n if ans1 > 7.0:\n print(\"Infinity\")\n else:\n print(pow(10,ans1))", "from math import log10\nimport math\nfor _ in range(int(input())):\n n = int(input())\n alice = []\n bob = []\n words = []\n for i in range(n):\n words.append(input())\n for cur in words:\n prev = -1\n f = 0\n for j in range(len(cur)):\n if cur[j] not in ['a','e','i','o','u']:\n if prev==-1:\n prev = j\n else:\n if abs(prev-j)==2 or abs(prev-j)==1:\n f = 1\n break\n else:\n prev = j\n if f==1:\n bob.append(cur)\n else:\n alice.append(cur)\n \n# print(alice)\n# print(bob)\n # Alice \n n1 = len(alice)\n freq_a = {}\n for i in alice:\n for j in i:\n if j not in freq_a:\n freq_a[j] = 1\n else:\n freq_a[j]+=1\n num_a = {}\n for i in freq_a:\n num_a[i] = 0\n for j in alice:\n if i in j:\n num_a[i]+=1\n# print(freq_a)\n# print(num_a)\n num1 = 1\n den1 = 1\n for i in num_a:\n num1 = (num1*num_a[i])\n den1 = den1*freq_a[i]\n \n \n # Bob alphabets\n n2 = len(bob)\n freq_b = {}\n for i in bob:\n for j in i:\n if j not in freq_b:\n freq_b[j] = 1\n else:\n freq_b[j]+=1\n num_b = {}\n for i in freq_b:\n num_b[i] = 0\n for j in bob:\n if i in j:\n num_b[i]+=1\n num2 = 1\n den2 = 1\n for i in num_b:\n num2 = (num2*num_b[i])\n den2 = den2*freq_b[i]\n if n<=10:\n if n2>=n1:\n ans = pow(den2/den1,n1)*pow(den2,n2-n1)\n else:\n ans = pow(den2/den1,n2)*pow(den1,-(n1-n2))\n t = num1/num2\n ans = ans*t\n if ans>10000000.0:\n print(\"Infinity\")\n else:\n print(ans)\n else:\n ans1 = log10(num1)+n2*log10(den2)\n ans2 = log10(num2)+n1*(log10(den1))\n ans1 = ans1-ans2\n if ans1 > 7.0:\n print(\"Infinity\")\n else:\n print(pow(10,ans1))", "from math import log10\nimport math\nfor _ in range(int(input())):\n n = int(input())\n alice = []\n bob = []\n words = []\n for i in range(n):\n words.append(input())\n for cur in words:\n prev = -1\n f = 0\n for j in range(len(cur)):\n if cur[j] not in ['a','e','i','o','u']:\n if prev==-1:\n prev = j\n else:\n if abs(prev-j)==2 or abs(prev-j)==1:\n f = 1\n break\n else:\n prev = j\n if f==1:\n bob.append(cur)\n else:\n alice.append(cur)\n \n# print(alice)\n# print(bob)\n # Alice \n n1 = len(alice)\n freq_a = {}\n for i in alice:\n for j in i:\n if j not in freq_a:\n freq_a[j] = 1\n else:\n freq_a[j]+=1\n num_a = {}\n for i in freq_a:\n num_a[i] = 0\n for j in alice:\n if i in j:\n num_a[i]+=1\n# print(freq_a)\n# print(num_a)\n num1 = 1\n den1 = 1\n for i in num_a:\n num1 = (num1*num_a[i])\n den1 = den1*freq_a[i]\n \n \n # Bob alphabets\n n2 = len(bob)\n freq_b = {}\n for i in bob:\n for j in i:\n if j not in freq_b:\n freq_b[j] = 1\n else:\n freq_b[j]+=1\n num_b = {}\n for i in freq_b:\n num_b[i] = 0\n for j in bob:\n if i in j:\n num_b[i]+=1\n num2 = 1\n den2 = 1\n for i in num_b:\n num2 = (num2*num_b[i])\n den2 = den2*freq_b[i]\n if n<=10:\n# if n2>=n1:\n# ans = pow(den2/den1,n1)*pow(den2,n2-n1)\n# else:\n# ans = pow(den2/den1,n2)*pow(den1,-(n1-n2))\n# t = num1/num2\n# ans = ans*t\n# if ans>10000000.0:\n# print(\"Infinity\")\n# else:\n# print(ans)\n# else:\n ans1 = log10(num1)+n2*log10(den2)\n ans2 = log10(num2)+n1*(log10(den1))\n ans1 = ans1-ans2\n if ans1 > 7.0:\n print(\"Infinity\")\n else:\n print(pow(10,ans1))", "from math import log10\nimport math\nfor _ in range(int(input())):\n n = int(input())\n alice = []\n bob = []\n words = []\n for i in range(n):\n words.append(input())\n for cur in words:\n prev = -1\n f = 0\n for j in range(len(cur)):\n if cur[j] not in ['a','e','i','o','u']:\n if prev==-1:\n prev = j\n else:\n if abs(prev-j)==2 or abs(prev-j)==1:\n f = 1\n break\n else:\n prev = j\n if f==1:\n bob.append(cur)\n else:\n alice.append(cur)\n \n # Alice \n n1 = len(alice)\n freq_a = {}\n for i in alice:\n for j in i:\n if j not in freq_a:\n freq_a[j] = 1\n else:\n freq_a[j]+=1\n num_a = {}\n for i in freq_a:\n num_a[i] = 0\n for j in alice:\n if i in j:\n num_a[i]+=1\n num1 = 1\n den1 = 1\n for i in num_a:\n num1 = (num1*num_a[i])\n den1 = den1*freq_a[i]\n \n \n # Bob alphabets\n n2 = len(bob)\n freq_b = {}\n for i in bob:\n for j in i:\n if j not in freq_b:\n freq_b[j] = 1\n else:\n freq_b[j]+=1\n num_b = {}\n for i in freq_b:\n num_b[i] = 0\n for j in bob:\n if i in j:\n num_b[i]+=1\n num2 = 1\n den2 = 1\n for i in num_b:\n num2 = (num2*num_b[i])\n den2 = den2*freq_b[i]\n if n<=10:\n if n2>=n1:\n ans = pow(den2/den1,n1)*pow(den2,n2-n1)\n else:\n ans = pow(den2/den1,n2)*pow(den1,-(n1-n2))\n t = num1/num2\n ans = ans*t\n if ans>10000000.0:\n print(\"Infinity\")\n else:\n print(ans)\n else:\n ans1 = log10(num1)+n2*log10(den2)\n ans2 = log10(num2)+n1*(log10(den1))\n ans1 = ans1-ans2\n if ans1 > 7.0:\n print(\"Infinity\")\n else:\n print(pow(10,ans1))", "import math\ndef score(a):\n count = {}\n recipes = {}\n for i in range(len(a)):\n x = a[i]\n for j in range(len(x)):\n if x[j] in count:\n count[x[j]] += 1\n else:\n count[x[j]] = 1\n for ch in set(x):\n if ch in recipes:\n recipes[ch] += 1\n else:\n recipes[ch] = 1\n num, den = 0, 0\n for key in recipes:\n # print(key, '{}/{}**{}'.format(recipes[key], count[key], len(a)))\n num += math.log(recipes[key])\n den += len(a) * math.log(count[key])\n # prod *= recipes[key] / (count[key] ** len(a))\n return math.exp(num - den)\nt = int(input())\nfor _ in range(t):\n l = int(input())\n alice = []\n bob = []\n vowels = set('aeiou')\n for i in range(l):\n s = input()\n count = 2\n for j in range(len(s)):\n if s[j] in vowels:\n count += 1\n else:\n if count <= 1:\n bob.append(s)\n break\n count = 0\n else:\n alice.append(s)\n # print(alice, bob)\n s1 = score(alice)\n s2 = score(bob)\n # print(len(alice), len(bob))\n # print(sA, sB)\n if s2 == 0 or math.exp(math.log(s1) - math.log(s2)) > 10**7:\n print('Infinity')\n else:\n print(math.exp(math.log(s1) - math.log(s2)))\n", "import time\nvowels = 'aeiou'\nstart_time = time.time()\ndef main():\n import math as m\n ryt = m.log(10**7, 2)\n lyt = m.log(0.0000009, 2)\n t = int(input())\n v = {\"a\": 1, \"e\": 1, \"i\": 1, \"o\": 1, \"u\": 1}\n for qwer in range(t):\n l = int(input())\n a = []\n b = []\n for wer in range(l):\n s = input()\n n = len(s)\n c1 = 0\n for i in range(n):\n if s[i] not in v:\n if i+1 < n:\n if s[i+1] not in v:\n c1 = 1\n break\n if i+2 < n:\n if s[i+2] not in v:\n c1 = 1\n break\n if c1 == 1:\n b.append(s)\n else:\n a.append(s)\n # for _ in range(l):\n # flag = False\n # s = input()\n # for i in range(len(s)-2):\n # if s[i] not in vowels:\n # if s[i+1] not in vowels or s[i+2] not in vowels:\n # flag = True\n # break\n # else:\n # if s[i+1] not in vowels and s[i+2] not in vowels:\n # flag = True \n # break\n # if flag:\n # b.append(s)\n # else:\n # a.append(s)\n xa = {}\n fxa = {}\n xb = {}\n fxb = {}\n ka = len(a)\n kb = len(b)\n for i in range(ka):\n d = {}\n for j in range(len(a[i])):\n if a[i][j] in d:\n d[a[i][j]] += 1\n else:\n d[a[i][j]] = 1\n for u in d:\n if u in xa:\n xa[u] += 1\n fxa[u] += d[u]\n else:\n xa[u] = 1\n fxa[u] = d[u]\n for i1 in range(kb):\n d = {}\n for j1 in range(len(b[i1])):\n if b[i1][j1] in d:\n d[b[i1][j1]] += 1\n else:\n d[b[i1][j1]] = 1\n for u1 in d:\n if u1 in xb:\n xb[u1] += 1\n fxb[u1] += d[u1]\n else:\n xb[u1] = 1\n fxb[u1] = d[u1]\n ans = 0\n for y in xa:\n ans += m.log(xa[y], 2)-ka*(m.log(fxa[y], 2))\n for r in xb:\n ans += kb*(m.log(fxb[r], 2))-m.log(xb[r], 2)\n if ans > ryt:\n print(\"Infinity\")\n elif ans < lyt:\n print(0)\n else:\n print(2**ans)\n\n\nmain()\n# print(time.time()-start_time)\n", "import time\nimport math\nimport random\nimport string\n\ndef log2(x):\n return math.log(x, 2)\n\nMAX = log2(1e7)\nMIN = log2(1e-7)\n\nstart_time = time.time()\n\nvowels = 'aeiou'\nv = {\"a\": 1, \"e\": 1, \"i\": 1, \"o\": 1, \"u\": 1}\nabets = string.ascii_lowercase\n\ntcs = int(input())\n\nfor test in range(tcs):\n l = int(input())\n a = []\n b = []\n # for _ in range(l):\n # flag = False\n # s = input()\n # for i in range(len(s)-2):\n # if s[i] not in vowels:\n # if s[i+1] not in vowels or s[i+2] not in vowels:\n # flag = True\n # break\n # else:\n # if s[i+1] not in vowels and s[i+2] not in vowels:\n # flag = True \n # break\n # if flag:\n # b.append(s)\n # else:\n # a.append(s)\n for wer in range(l):\n s = input()\n n = len(s)\n c1 = 0\n for i in range(n):\n if s[i] not in v:\n if i+1 < n:\n if s[i+1] not in v:\n c1 = 1\n break\n if i+2 < n:\n if s[i+2] not in v:\n c1 = 1\n break\n if c1 == 1:\n b.append(s)\n else:\n a.append(s)\n alen = len(a)\n blen = len(b)\n # ################ Alice ##############\n achar_dict = {}\n atotal_dict = {}\n for recipe in a:\n d = {}\n for ch in recipe:\n d[ch] = 1\n if atotal_dict.get(ch):\n atotal_dict[ch] += 1\n else:\n atotal_dict[ch] = 1\n for ch in d:\n if achar_dict.get(ch):\n achar_dict[ch] += 1\n else:\n achar_dict[ch] = 1\n ################ Bob ##############\n bchar_dict = {}\n btotal_dict = {}\n for recipe in b:\n d = {}\n for ch in recipe:\n d[ch] = 1\n if btotal_dict.get(ch):\n btotal_dict[ch] += 1\n else:\n btotal_dict[ch] = 1\n for ch in d:\n if bchar_dict.get(ch):\n bchar_dict[ch] += 1\n else:\n bchar_dict[ch] = 1\n ################## Calculation ##################\n result = 0\n for i in achar_dict:\n result += log2(achar_dict[i]) - alen*log2(atotal_dict[i])\n \n for i in bchar_dict:\n result += blen*log2(btotal_dict[i]) - log2(bchar_dict[i])\n\n if result > MAX:\n print('Infinity')\n elif result < MIN:\n print(0)\n else:\n print(2**result)\n # print('%.7f' % 10**result)\n\n# print(time.time() - start_time)\n", "import time\nimport math\nimport random\nimport string\n\ndef log2(x):\n return math.log(x, 2)\n\nMAX = log2(1e7)\nMIN = log2(1e-7)\n\nstart_time = time.time()\n\nvowels = 'aeiou'\nv = {\"a\": 1, \"e\": 1, \"i\": 1, \"o\": 1, \"u\": 1}\nabets = string.ascii_lowercase\n\ntcs = int(input())\n\nfor test in range(tcs):\n l = int(input())\n a = []\n b = []\n for _ in range(l):\n flag = False\n s = input()\n for i in range(len(s)-2):\n if s[i] not in vowels:\n if s[i+1] not in vowels or s[i+2] not in vowels:\n flag = True\n break\n else:\n if s[i+1] not in vowels and s[i+2] not in vowels:\n flag = True \n break\n if flag:\n b.append(s)\n else:\n a.append(s)\n # for wer in range(l):\n # s = input()\n # n = len(s)\n # c1 = 0\n # for i in range(n):\n # if s[i] not in v:\n # if i+1 < n:\n # if s[i+1] not in v:\n # c1 = 1\n # break\n # if i+2 < n:\n # if s[i+2] not in v:\n # c1 = 1\n # break\n # if c1 == 1:\n # b.append(s)\n # else:\n # a.append(s)\n alen = len(a)\n blen = len(b)\n # ################ Alice ##############\n achar_dict = {}\n atotal_dict = {}\n for recipe in a:\n d = {}\n for ch in recipe:\n d[ch] = 1\n if atotal_dict.get(ch):\n atotal_dict[ch] += 1\n else:\n atotal_dict[ch] = 1\n for ch in d:\n if achar_dict.get(ch):\n achar_dict[ch] += 1\n else:\n achar_dict[ch] = 1\n ################ Bob ##############\n bchar_dict = {}\n btotal_dict = {}\n for recipe in b:\n d = {}\n for ch in recipe:\n d[ch] = 1\n if btotal_dict.get(ch):\n btotal_dict[ch] += 1\n else:\n btotal_dict[ch] = 1\n for ch in d:\n if bchar_dict.get(ch):\n bchar_dict[ch] += 1\n else:\n bchar_dict[ch] = 1\n ################## Calculation ##################\n result = 0\n for i in achar_dict:\n result += log2(achar_dict[i]) - alen*log2(atotal_dict[i])\n \n for i in bchar_dict:\n result += blen*log2(btotal_dict[i]) - log2(bchar_dict[i])\n\n if result > MAX:\n print('Infinity')\n elif result < MIN:\n print(0)\n else:\n print(2**result)\n # print('%.7f' % 10**result)\n\n# print(time.time() - start_time)\n"]
{"inputs": [["2", "4", "aba", "abc", "bab", "aac", "3", "aba", "baab", "abc"]], "outputs": [["1.1250000", "0.0277778"]]}
INTERVIEW
PYTHON3
CODECHEF
33,211
61cdabf0052749c72364778c7c1b58b2
UNKNOWN
Today is Chef's birthday. His mom decided to surprise him with a truly fantastic gift: his favourite binary string B. But, unfortunately, all the stocks of binary string B have been sold out, and only a binary string A (A ≠ B) is available in the market. She purchases the string A and tries to convert it to string B by applying any of following three operations zero or more times. AND Operation: She will choose a pair of indices i and j such that i != j and perform following sequence of operations. - result = Ai & Aj - Ai = result & Ai - Aj = result & Aj OR Operation: She will choose a pair of indices i and j such that i != j and perform following sequence of operations. - result = Ai | Aj - Ai = result | Ai - Aj = result | Aj XOR Operation: She will choose a pair of indices i and j such that i != j and perform following sequence of operations. - result = Ai ^ Aj - Ai = result ^ Ai - Aj = result ^ Aj Chef's mom is eagerly waiting to surprise him with his favourite gift and therefore, she wants to convert string A to string B as fast as possible. Can you please help her by telling her the minimum number of operations she will require? If it is impossible to do so, then let Chef's mom know about it. -----Input----- First line of input contains a single integer T denoting the number of test cases. T test cases follow. First line of each test case, will contain binary string A. Second line of each test case, will contain binary string B. -----Output----- For each test case, Print "Lucky Chef" (without quotes) in first line and minimum number of operations required to convert string A to sting B in second line if conversion is possible. Print "Unlucky Chef" (without quotes) in a new line otherwise. -----Constraints----- - 1 ≤ T ≤ 105 - 1 ≤ |A| ≤ 106 - 1 ≤ |B| ≤ 106 - A != B - |A| = |B| - sum of |A| over all test cases does not exceed 106 - sum of |B| over all test cases does not exceed 106 -----Subtasks----- - Subtask #1 (40 points) : Sum of |A| & |B| over all test cases does not exceed 103 - Subtask #2 (60 points) : Sum of |A| & |B| over all test cases does not exceed 106 -----Example----- Input 2 101 010 1111 1010 Output Lucky Chef 2 Unlucky Chef -----Explanation----- Example case 1. - Applying XOR operation with indices i = 1 and j = 2. Resulting string will be 011. - Then, Applying AND operation with indices i = 1 and j = 3. Resulting string will be 010. Example case 2. - It is impossible to convert string A to string B.
["for j in range(int(input())):\n a=input()\n b=input()\n c,d=0,0\n a0=a.count(\"0\")\n a1=a.count(\"1\")\n if(a0==len(a) or a1==len(a)):\n print(\"Unlucky Chef\")\n else:\n print(\"Lucky Chef\")\n for i in range(len(a)):\n if(a[i]!=b[i]):\n if(a[i]==\"0\"):\n c+=1\n else:\n d+=1\n print(max(c,d))", "# cook your dish here\n\nt = int(input())\nwhile t:\n A = input()\n B = input()\n mp1 = 0\n p1 = 0\n mp0 = 0\n p0 = 0\n for i in range(len(B)):\n if A[i]==B[i] and B[i]=='1':\n p1 += 1\n elif A[i]==B[i] and B[i]=='0':\n p0 += 1\n elif A[i]!=B[i] and B[i]=='1':\n mp0 += 1\n else:\n mp1 += 1\n #if A==B:\n # con = True\n # op = 0\n if mp0+p0==len(A) or mp1+p1==len(A):\n con = False\n elif mp1+p0>=mp0+p0:\n con = True\n op = mp1-mp0\n mp1 -= op\n op += mp1\n else:\n con = True\n op = mp0-mp1\n mp0 -= op\n op += mp0\n if con:\n print('Lucky Chef')\n print(op)\n else:\n print('Unlucky Chef')\n t -= 1\n"]
{"inputs": [["2", "101", "010", "1111", "1010"]], "outputs": [["Lucky Chef", "2", "Unlucky Chef"]]}
INTERVIEW
PYTHON3
CODECHEF
956
818e3415943b5cad81c8137a408f47c2
UNKNOWN
You are Dastan, the great Prince of Persia! After searching long for the mysterious 'Sands of Time', you have finally arrived at the gates of the city that hosts the ancient temple of the gods. However, the gate is locked and it can only be opened with a secret code, which you need to obtain by solving the following puzzle: There is a table in front of you, with $N$ coins placed in a row and numbered $1$ through $N$ from left to right. For each coin, you know whether it is initially showing heads or tails. You have to perform exactly $K$ operations. In one operation, you should remove the rightmost coin present on the table, and if this coin was showing heads right before it was removed, then you should also flip all the remaining coins. (If a coin was showing heads, then after it is flipped, it is showing tails, and vice versa.) The code needed to enter the temple is the number of coins which, after these $K$ operations are performed, have not been removed and are showing heads. Can you find this number? The fate of Persia lies in your hands… -----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 characters. For each valid $i$, the $i$-th of these characters is 'H' if the $i$-th coin is initially showing heads or 'T' if it is showing tails. -----Output----- For each test case, print a single line containing one integer ― the number of coins that are showing heads after $K$ operations. -----Constraints----- - $1 \le T \le 200$ - $1 \le K < N \le 100$ -----Subtasks----- Subtask #1 (100 points): original constraints -----Example Input----- 3 5 3 H T T H T 7 4 H H T T T H H 6 1 T H T H T T -----Example Output----- 1 2 2
["t=int(input())\nfor i in range(t):\n n,k=[int(i) for i in input().split()]\n l=input().split()\n for i in range(k):\n if l.pop()=='H':\n for ind,j in enumerate(l):\n if j=='H':\n l[ind]='T'\n else:\n l[ind]='H'\n print(sum([1 for i in l if i=='H']))", "for i in range(int(input())):\n n,k=[int(i) for i in input().split()]\n m=input().split()\n for i in range(k):\n if m.pop()=='H':\n for ind,j in enumerate(m):\n if j=='H':\n m[ind]='T'\n else:\n m[ind]='H'\n print(sum([1 for i in m if i=='H']))", "for _ in range(int(input())):\n n, k = map(int, input().split())\n arr = input().split()\n\n while arr and k:\n if arr.pop() == 'H':\n for i in range(len(arr)):\n if arr[i] == 'H':\n arr[i] = 'T'\n else:\n arr[i] = 'H'\n\n k -= 1\n\n res = sum(i == 'H' for i in arr)\n print(res)", "for _ in range(int(input())):\n n,k = map(int,input().split())\n arr =input().split()\n\n for i in range(k):\n if arr[-1]==\"H\":\n arr.pop()\n n=n-1\n for j in range(n):\n if arr[j]==\"H\":\n arr[j]=\"T\"\n else:\n arr[j]=\"H\"\n else:\n arr.pop()\n n=n-1\n print(arr.count(\"H\"))", "for _ in range(int(input())):\n n,k = list(map(int,input().split()))\n arr =input().split()\n\n for i in range(k):\n if arr[-1]==\"H\":\n arr.pop()\n n=n-1\n for j in range(n):\n if arr[j]==\"H\":\n arr[j]=\"T\"\n else:\n arr[j]=\"H\"\n else:\n arr.pop()\n n=n-1\n print(arr.count(\"H\"))\n \n", "# cook your dish here\nt=int(input())\nwhile t>0:\n n,k=map(int,input().split())\n l=list(input().split())\n l1=l[n-k:]\n c=0\n ch=1\n for i in range(len(l1)-1,-1,-1):\n if l1[i]=='H' and ch==1:\n c+=1\n ch=0\n if l1[i]=='T' and ch==0:\n c+=1\n ch=1\n res=l[0:n-k]\n if c%2==0:\n r=res.count('H')\n else:\n r=res.count('T')\n print(r)\n t-=1", "for _ in range(int(input())):\n n,k = list(map(int,input().split()))\n arr =input().split()\n\n for i in range(k):\n if arr[-1]==\"H\":\n arr.pop()\n n=n-1\n for j in range(n):\n if arr[j]==\"H\":\n arr[j]=\"T\"\n else:\n arr[j]=\"H\"\n else:\n arr.pop()\n n=n-1\n print(arr.count(\"H\"))\n\n\n \n\n\n\n\n", "for _ in range(int(input())):\n n,k = list(map(int,input().split()))\n arr =input().split()\n \n head_count = 0\n\n for i in range(n-1,n-k-1,-1):\n if arr[i]==\"H\":\n if head_count%2==0:\n head_count+=1\n else:\n if head_count%2!=0: #odd\n head_count+=1\n \n if head_count%2==0:\n print(arr[:n-k].count(\"H\"))\n else:\n print(arr[:n-k].count(\"T\"))\n\n\n\n\n", "for _ in range(int(input())):\n n, k = [int(i) for i in input().split()]\n s = input().split()\n for i in range(k):\n if s.pop() == 'H':\n for ind, j in enumerate(s):\n if j == 'H':\n s[ind] = 'T'\n else:\n s[ind] = 'H'\n print(sum([1 for i in s if i =='H']))", "# cook your dish here\nfor i in range(int(input())):\n n,k=map(int,input().split())\n li=input().split()\n li1=li[:n-k]\n li2=li[n-k:]\n dict={'H':'T','T':'H'}\n hd='H'\n for i in li2[::-1]:\n if(i==hd):\n hd=dict[hd]\n print(li1.count(hd)) ", "# cook your dish here\nfor _ in range(int(input())):\n nk=[int(i) for i in input().split()]\n k=nk[1]\n s=input().split()\n for i in range(k):\n a=s.pop()\n if a=='H':\n for indx,j in enumerate(s):\n if j=='H':\n s[indx]='T'\n else:\n s[indx]='H'\n heads=0\n for i in s:\n if i=='H':\n heads+=1\n print(heads)\n", "# cook your dish here\nfor _ in range(int(input())):\n N,k=map(int,input().split())\n arr=list(map(str,input().split()))\n for i in range(1,k+1):\n x=arr[len(arr)-i]\n arr[len(arr)-i]=\"0\"\n if(x==\"H\"):\n for i in range(len(arr)):\n if(arr[i]==\"H\"):\n arr[i]=\"T\"\n elif(arr[i]==\"T\"):\n arr[i]=\"H\"\n print(arr.count(\"H\"))", "# cook your dish here\nfor _ in range(int(input())):\n N,K=map(int,input().split(' '))\n S=input()\n \n S=S.replace('H','1').replace('T','0').replace(' ','')\n # print(S)\n for i in range(1,K+1):\n currBit=S[N-i]\n S=S[:-1]\n if(currBit=='0'):\n continue\n else:\n S_dec=int(S,2)\n xor_mulp=2**(N-i+1)-1\n S=bin(S_dec^xor_mulp)[3:]\n # print(S)\n print(sum(map(int,list(S))))", "# cook your dish here\nt = int(input())\nfor _ in range(t):\n n,k = list(map(int,input().split()))\n l = list(map(str,input().split()))\n i = n-1\n for j in range(k):\n if(l[i]=='T'):\n l.pop(i)\n i=i-1\n else:\n l.pop(i)\n i=i-1\n for k in range(len(l)):\n if(l[k]=='H'):\n l[k]='T'\n else:\n l[k]='H'\n print(l.count('H'))\n \n", "t = int(input())\nfor _ in range(t):\n n, k = map(int,input().split())\n li = list(input().split())\n h = li.count('H')\n t = n - h\n #print(h, t)\n for i in range(k):\n d= li[-1]\n #print(li)\n li = li[:-1]\n #print(li, d)\n if d == 'T':\n t = t - 1\n else:\n h, t = t, h - 1\n li = ['H' if li[j] == 'T' else 'T' for j in range(n - i - 1) ]\n #print(li)\n print(h)", "# cook your dish here\nfor _ in range(int(input())):\n n,k = map(int,input().split())\n l = list(map(str,input().split()))\n while k:\n k -= 1\n if l[-1] == \"H\":\n for i in range(len(l)):\n if l[i] == 'H':\n l[i] = 'T'\n else:\n l[i] = 'H'\n l.pop()\n print(l.count(\"H\"))", "# cook your dish here\nt = int(input())\nfor _ in range(t):\n n,k = map(int, input().split())\n arr = list(map(str, input().split()))\n for i in range(k):\n if arr[-1]=='H':\n for j in range(len(arr)):\n if arr[j]=='H':\n arr[j] = 'T'\n else:\n arr[j] = 'H'\n g = arr.pop()\n print(arr.count('H'))", "for _ in range(int(input())):\n # n = int(input())\n # s = input()\n n,k = list(map(int,input().split()))\n f = input().split()\n leftovers = f[:n-k]\n removed = f[n-k:]\n seekin = 'H'\n flip = {'H':'T' , 'T':'H'}\n for coin in removed[::-1] :\n if coin == seekin :\n seekin = flip[seekin]\n print(leftovers.count(seekin))\n", "# cook your dish here\na = int(input())\nfor i in range(a):\n b = str(input()).split(' ')\n c = str(input()).split(' ')\n li = []\n n = 0\n for i1 in range(int(b[1])):\n li.append(c[int(b[0])-i1-1])\n for i2 in range(int(b[1])-1):\n if li[i2+1]!=li[i2]:\n n+=1\n if c[int(b[0])-1]=='H':\n n+=1\n if n%2==0:\n print(c[:int(b[0])-int(b[1])].count('H'))\n else:\n print(c[:int(b[0])-int(b[1])].count('T'))\n", "for _ in range(int(input())):\n n,k=list(map(int,input().split()))\n a=list(input().split())\n while k>0:\n if a[-1]==\"H\":\n for i in range(len(a)-1):\n if a[i]==\"H\":\n a[i]=\"T\"\n else:\n a[i]=\"H\"\n a.pop()\n else:\n a.pop()\n k=k-1\n print(a.count(\"H\"))", "t = int(input())\n\nfor _ in range(t):\n n, k = [int(x) for x in input().split()]\n \n a = [x for x in input().split()]\n a.reverse()\n \n flag = 0\n for i in range(k):\n if(flag==0 and a[i]=='H'):\n flag = 1\n elif(flag==1 and a[i]=='T'):\n flag = 0\n \n a = a[k:]\n if(flag==0):\n print(a.count('H'))\n else:\n print(a.count('T'))", "for k in range(int(input())):\n n,k=list(map(int,input().split()))\n l=list(map(str,input().split()))\n while k>0:\n if l[-1]==\"H\":\n for i in range(0,len(l)-1):\n if l[i]==\"H\":\n l[i]=\"T\"\n else:\n l[i]=\"H\"\n l.pop()\n \n k=k-1\n print(l.count(\"H\"))\n \n \n", "for k in range(int(input())):\n n,k=list(map(int,input().split()))\n l=list(map(str,input().split()))\n while k>0:\n if l[-1]==\"T\":\n l.pop()\n else:\n for i in range(0,len(l)-1):\n if l[i]==\"H\":\n l[i]=\"T\"\n else:\n l[i]=\"H\"\n l.pop()\n \n k=k-1\n print(l.count(\"H\"))\n \n \n", "# cook your dish here\nfor _ in range(int(input())):\n n, k = list(map(int, input().split()))\n coins = input().split()\n count = 0\n \n for i in range(k):\n coin = coins.pop()\n \n if coin == 'H':\n count += 1\n coins = ['T' if val == 'H' else 'H' for val in coins]\n \n res = coins.count('H')\n \n print(res)", "t=int(input())\nfor i in range(t):\n n,k=list(map(int,input().split()))\n arr = list(map(str,input().strip().split()))[:n] \n l=[]\n counter=0\n for i in range(len(arr)):\n if(arr[i] == \"H\"):\n l.append(1)\n else:\n l.append(0)\n for i in range(n-1,n-k-1,-1):\n if(l[i] == 0):\n counter+=1\n continue\n else:\n for j in range(i):\n if(l[j]==1):\n l[j]-=1\n else:\n l[j]+=1\n counter+=1\n if(counter == k):\n break\n head=0\n for k in range(n-k):\n if l[k]==1:\n head+=1\n print(head)\n"]
{"inputs": [["3", "5 3", "H T T H T", "7 4", "H H T T T H H", "6 1", "T H T H T T"]], "outputs": [["1", "2", "2"]]}
INTERVIEW
PYTHON3
CODECHEF
8,355
c5452166adf3de7724a49864048c8150
UNKNOWN
During Quarantine Time Chef is at home and he was quite confused about what to cook so, he went to his son and asked about what would he prefer to have? He replied, cakes. Now, chef cook $N$ number of cake and number of layers for every cake is different. After cakes are baked, Chef arranged them in a particular order and then generates a number by putting number of layers of cakes as digit in sequence (e.g., if chef arranges cakes with layers in sequence $2$, $3$ and $5$ then generated number is $235$). Chef has to make his son powerful in mathematics, so he called his son and ask him to arrange the cakes in all the possible ways and every time when different sequence is generated he has to note down the number. At the end he has to find sum of all the generated numbers. So, help him to complete this task. -----Input:----- - First line will contain $T$, number of testcases. Then the testcases follow. - The first line of each test case contains a single integer $N$ denoting number of cakes. - The second line contains $N$ space-separated integers $L1$ $L2$ … $LN$ layers of the cake. -----Output:----- For each test case, print a single line containing sum of all the possible numbers which is generated by arranging cake in different sequence. -----Constraints :----- - $1 \leq T \leq 2*10^5$ - $1 \leq N, L1, L2, L3,…, LN \leq 9$ -----Sample Input:----- 1 3 2 3 5 -----Sample Output:----- 2220 -----Explanation:----- Sum of all possibilities : $235 + 532 + 253 + 352 + 523 + 325 = 2220 $
["#cook your recipe\nfrom math import factorial\ntest_cases = int(input())\nfor _ in range(test_cases):\n n = int(input())\n sum1 = 0\n final_sum = 0\n num = list(map(int, input().split()))\n rep_time = factorial(n - 1)\n rep_count = dict()\n for i in num:\n if i in rep_count:\n rep_count[i] +=1\n else:\n rep_count[i] =1\n for j in rep_count:\n if rep_count[j] ==1:\n sum1 += j * factorial(n - rep_count[j])\n else:\n sum1 += j * factorial(n-1)/ factorial(n - rep_count[j])\n \n for k in range(n):\n final_sum += sum1 * (10**k)\n\n print(int(final_sum))", "#cook your recipe\nfrom math import factorial\ntest_cases = int(input())\nfor _ in range(test_cases):\n n = int(input())\n sum1 = 0\n final_sum = 0\n num = list(map(int, input().split()))\n rep_time = factorial(n - 1)\n rep_count = dict()\n for i in num:\n if i in rep_count:\n rep_count[i] +=1\n else:\n rep_count[i] =1\n for j in rep_count:\n if rep_count[j] ==1:\n sum1 += j * factorial(n - rep_count[j])\n else:\n sum1 += j * factorial(n-1)/ factorial(n - rep_count[j])\n \n for k in range(n):\n final_sum += sum1 * (10**k)\n\n print(int(final_sum))", "# def toString(List): \r\n# \treturn ''.join(List) \r\n \r\n# def permute(a, l, r): \r\n# \tif(l==r): \r\n# \t\tlist_ = []\r\n# \t\tlist_.append(toString(a))\r\n# \t\treturn list_'''\r\n# \t\tprint(toString(a))\t\t\r\n# \telse: \r\n# \t\tfor i in range(l,r+1): \r\n# \t\t\ta[l], a[i] = a[i], a[l] \r\n# \t\t\tpermute(a, l+1, r) \r\n# \t\t\ta[l], a[i] = a[i], a[l]\r\n\r\n# for _ in range(int(input())):\r\n# \tn = int(input())\r\n# \tp = list(map(str , input().split())) \r\n# \tpermute(p, 0, n-1)\r\n'''def permutation(start, end):\r\n if(end == start):\r\n #return a\r\n print(*a)\r\n for i in range(start, end+1):\r\n a[i],a[start] = a[start],a[i]\r\n permutation(start+1, end)\r\n a[i],a[start] = a[start],a[i]\r\nfor _ in range(int(input())):\r\n\tn = int(input())\r\n\ta = list(map(int,input().split()))\r\n\tpermutation(0,len(a)-1)'''\r\n\t\r\ndef factorial(n): \r\n\r\n\tf = 1\r\n\tif(n == 0 or n == 1): \r\n\t\treturn 1\r\n\tfor i in range(2, n + 1): \r\n\t\tf = f * i \r\n\treturn f \r\n \r\ndef getSum(arr, n): \r\n \r\n\tfact = factorial(n) \r\n\tdigitsum = 0\r\n\tfor i in range(n): \r\n\t\tdigitsum += arr[i] \r\n\tdigitsum *= (fact // n) \r\n\tres = 0\r\n\ti = 1\r\n\tk = 1\r\n\twhile(i <= n): \r\n\t\tres += (k * digitsum) \r\n\t\tk = k * 10\r\n\t\ti += 1\r\n\r\n\treturn res \r\n \r\nfor _ in range(int(input())):\r\n\tn = int(input())\r\n\tarr = list(map(int , input().split()))\r\n\tprint(getSum(arr, n)) ", "# cook your dish here\ntest_case = int(input())\n\nfor i in range(test_case):\n n = int(input())\n \n val = list(map(int, input().split(' ')))\n \n fac = 1\n for j in range(n):\n fac = fac * (j+1)\n \n noOfDigit = fac//n\n \n initialSum = 0\n \n for j in range(len(val)):\n initialSum += val[j]\n \n initialSum = initialSum*noOfDigit\n \n totalSum = 0\n \n for j in range(n):\n totalSum = totalSum + pow(10, j)*initialSum\n \n print(totalSum)", "import math\r\nT=int(input())\r\nfor i in range(T):\r\n N=int(input())\r\n list=input().split()\r\n s=0\r\n k='0'\r\n for j in range(N):\r\n list[j]=int(list[j])\r\n s+=list[j]\r\n for l in range(N):\r\n k=k+'1'\r\n k=int(k)\r\n c=math.factorial(N-1)\r\n print(s*c*k)\r\n", "import math\nfor _ in range(int(input())):\n n = int(input())\n layers = [int(x) for x in input().split()]\n times = math.factorial(n-1)\n d = sum(layers)*times\n ans = 0\n k = 1\n for i in range(n):\n ans += k*d\n k *= 10\n print(ans)\n", "t=int(input())\r\ndef fac(x):\r\n if x==0:\r\n return 1\r\n else:\r\n return x*fac(x-1)\r\nfor j in range(t):\r\n n=int(input())\r\n a=list(map(int,input().split()))\r\n s=0\r\n for i in range(n):\r\n for j in a:\r\n s+=(j*10**i)*(fac(n-1))\r\n print(s)", "try:\r\n import math\r\n def getSum(arr, n): \r\n \r\n # calculate factorial \r\n fact = math.factorial(n) \r\n \r\n digitsum = 0\r\n for i in range(n): \r\n digitsum += arr[i] \r\n digitsum *= (fact // n) \r\n \r\n # Compute result (sum of \r\n # all the numbers) \r\n res = 0\r\n i = 1\r\n k = 1\r\n while i <= n : \r\n res += (k * digitsum) \r\n k = k * 10\r\n i += 1\r\n \r\n return res \r\n \r\n \r\n b=int(input())\r\n \r\n ls=[]\r\n \r\n while(b>0):\r\n a = int(input())\r\n \r\n arr = input() # takes the whole line of n numbers\r\n l = list(map(int,arr.split(' ')))\r\n \r\n \r\n # n distinct digits \r\n b-=1\r\n n = len(l) \r\n n=a\r\n \r\n \r\n g=int(getSum(l, n))\r\n ls.append(g)\r\n for i in ls:\r\n print(i)\r\nexcept:\r\n pass", "# your code goes here.............\n# Python 3 program to find sun of \n# numbers formed by all permutations \n# of given set of digits \n\n# function to calculate factorial \n# of a number \ndef factorial(n): \n\n\tf = 1\n\tif (n == 0 or n == 1): \n\t\treturn 1\n\tfor i in range(2, n + 1): \n\t\tf = f * i \n\treturn f \n\n# Function to calculate sum \n# of all numbers \ndef getSum(arr, n): \n\n\t# calculate factorial \n\tfact = factorial(n) \n\n\t# sum of all the given digits at \n\t# different positions is same and \n\t# is going to be stored in digitsum. \n\tdigitsum = 0\n\tfor i in range(n): \n\t\tdigitsum += arr[i] \n\tdigitsum *= (fact // n) \n\n\t# Compute result (sum of \n\t# all the numbers) \n\tres = 0\n\ti = 1\n\tk = 1\n\twhile i <= n : \n\t\tres += (k * digitsum) \n\t\tk = k * 10\n\t\ti += 1\n\n\treturn res \n\n# Driver Code \ndef __starting_point(): \n\t\n\t# n distinct digits\n\tt=int(input())\n\tfor _ in range(t):\n\t m=int(input())\n\t arr = list(map(int,input().split())) \n\t n = len(arr) \n\n\t# Print sum of all the numbers formed \n\t print(getSum(arr, n)) \n\n# This code is contributed by ita_c \n\n\n\n\n\n\n__starting_point()", "try:\r\n import math\r\n def getSum(arr, n): \r\n \r\n # calculate factorial \r\n fact = math.factorial(n) \r\n \r\n digitsum = 0\r\n for i in range(n): \r\n digitsum += arr[i] \r\n digitsum *= (fact // n) \r\n \r\n # Compute result (sum of \r\n # all the numbers) \r\n res = 0\r\n i = 1\r\n k = 1\r\n while i <= n : \r\n res += (k * digitsum) \r\n k = k * 10\r\n i += 1\r\n \r\n return res \r\n \r\n \r\n b=int(input())\r\n \r\n ls=[]\r\n \r\n while(b>0):\r\n a = int(input())\r\n \r\n arr = input() # takes the whole line of n numbers\r\n l = list(map(int,arr.split(' ')))\r\n \r\n \r\n # n distinct digits \r\n b-=1\r\n n = len(l) \r\n n=a\r\n \r\n \r\n g=int(getSum(l, n))\r\n ls.append(g)\r\n for i in ls:\r\n print(i)\r\nexcept:\r\n pass", "from collections import defaultdict\r\ndef fac(n):\r\n if n<=1:\r\n return 1\r\n return n*fac(n-1)\r\n\r\nfor i in range (int(input())):\r\n n = int(input())\r\n layers = defaultdict(int)\r\n list_ = list(map(int,input().split()))\r\n for j in range (n):\r\n layers[list_[j]] += 1\r\n sum_ = 0\r\n for j in sorted(layers):\r\n sum_ += j\r\n\r\n sum_ *= fac(len(layers)-1)\r\n ans = sum_\r\n for j in range (len(layers)-1):\r\n ans = ans*10 + sum_\r\n print(ans)\r\n\r\n \r\n", "import math\nt=int(input())\nfor i in range(t):\n n=int(input())\n alpha=list(map(int,input().split()))\n beta=math.factorial(n-1)\n sumfinal=int('1'*n)*sum(alpha)*beta\n print(sumfinal)\n \n \n", "from math import factorial\ntry:\n test_cases = int(input())\n while test_cases:\n test_cases = test_cases -1\n n=int(input())\n cakes=list(map(int,input().split()))\n sum_of_digits=sum(cakes)\n mul=factorial(n)/n #multiplier\n base=sum_of_digits*mul \n totalsum = 0\n for k in range(n):\n totalsum += base*(10**k)\n print(int(totalsum))\n \nexcept:\n pass", "from math import factorial\ntry:\n test_cases = int(input())\n while test_cases:\n test_cases = test_cases -1\n n=int(input())\n cakes=list(map(int,input().split()))\n sum_of_digits=sum(cakes)\n mul=factorial(n)/n #multiplier\n base=sum_of_digits*mul \n totalsum = 0\n for k in range(n):\n totalsum += base*(10**k)\n print(int(totalsum))\n \nexcept:\n pass", "import math\r\nfor _ in range(int(input())):\r\n n = int(input())\r\n grid = [int(i) for i in input().split()]\r\n sum1 = int('1'*n)*sum(grid)*math.factorial(n-1)\r\n print(sum1)\r\n", "from math import factorial\ntry:\n test_cases = int(input())\n while test_cases:\n test_cases = test_cases -1\n n=int(input())\n cakes=list(map(int,input().split()))\n sum_of_digits=sum(cakes)\n mul=factorial(n)/n #multiplier\n base=sum_of_digits*mul \n totalsum = 0\n for k in range(n):\n totalsum += base*(10**k)\n print(int(totalsum))\n \nexcept:\n pass", "from math import factorial\ntry:\n test_cases = int(input())\n while test_cases:\n test_cases = test_cases -1\n n=int(input())\n cakes=list(map(int,input().split()))\n sum_of_digits=sum(cakes)\n mul=factorial(n)/n #multiplier\n base=sum_of_digits*mul \n totalsum = 0\n for k in range(n):\n totalsum += base*(10**k)\n print(int(totalsum))\n \nexcept:\n pass", "from math import factorial as fact\ndef _sum(arr, n): \n f = fact(n)\n ds = 0\n for i in range(n):\n ds += arr[i]\n ds *= (f // n)\n res, i, k = 0, 1, 1\n while i <= n :\n res += (k * ds)\n k = k * 10\n i += 1\n return res\n\nt = int(input())\nfor _ in range(t):\n n = int(input())\n arr = list(map(int, input().split()))\n print(_sum(arr, n))\n", "# cook your dish here\ndef fact(nnn):\n f=1\n for i in range(1,nnn+1):\n f=f*i\n # print(f)\n return f\nt=int(input())\nfor i in range(0,t):\n n=int(input())\n lis=list(map(int,input().strip().split()))[:n]\n s=sum(lis)\n st=\"1\"*n\n last=int(st)\n # fac=\n # print(fact(n-1))\n ans=fact(n-1)*s*last\n print(ans)\n\n", "import math\nfor _ in range(int(input())):\n n=int(input())\n a=list(map(int,input().split()))\n f=math.factorial(n) \n s=0\n for i in range(n): \n s=s+a[i] \n s=s*(f//n) \n r,i,k=0,1,1\n while i<=n : \n r=r+(k*s) \n k=k*10\n i=i+1\n print(r)", "import math\r\nfrom collections import defaultdict\r\nimport itertools\r\n\r\nt = int(input())\r\nfor _ in range(t):\r\n n = int(input())\r\n a = [int(x) for x in input().split()]\r\n total = 0\r\n tmp = 0\r\n fact = math.factorial(n)\r\n for i in range(n):\r\n tmp+=a[i]\r\n tmp *=(fact//n)\r\n i=1\r\n k=1\r\n while i<=n:\r\n total += (k*tmp)\r\n k*=10\r\n i+=1\r\n print(total)", "import math\nt=int(input())\nwhile t>0:\n n=int(input())\n a=[int(i) for i in input().split(\" \")]\n summ=0\n for i in range(0,n):\n summ+=math.pow(10,i)\n summ=sum(a)*summ*math.factorial(n-1)\n print(int(summ))\n t-=1", "def factorial(n):\r\n if n==1:\r\n return 1\r\n if n==0:\r\n return 1\r\n f=1\r\n for i in range(2,n+1):\r\n f=i*f\r\n return f\r\ndef cakes(A):\r\n num=sum(A)\r\n fact=factorial(len(A)-1)\r\n num=num*fact\r\n res=0\r\n n=len(A)\r\n i=1\r\n k=1\r\n while i<=n:\r\n res+=num*k\r\n k=10*k\r\n i+=1\r\n return res\r\nt=int(input())\r\nfor i in range(t):\r\n n=int(input())\r\n A=[int(i) for i in input().split()][:n]\r\n print(cakes(A))", "import math\r\ndef fun():\r\n\tT=int(input())\r\n\tans=[]\r\n\tfor i in range(T):\r\n\t\tT=int(input())\r\n\t\tl=list(input().split())\r\n\t\tl=[int(x) for x in l]\r\n\t\tx=[]\r\n\t\tfor j in range(len(l)):\r\n\t\t\tx+=[math.factorial(len(l)-1)*k*math.pow(10,j) for k in l]\r\n\t\t\t#print(x)\r\n\t\tx1=[int(j) for j in x]\r\n\t\tx=sum(x1)\r\n\t\t#print(x)\r\n\t\tans.append(x)\r\n\t\r\n\tfor j in ans:\r\n\t\tprint(j)\r\n\t\r\nfun()\r\n"]
{"inputs": [["1", "3", "2 3 5"]], "outputs": [["2220"]]}
INTERVIEW
PYTHON3
CODECHEF
12,908
246400b31c5dfd8a2346b0d3ae57b0b7
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:----- 5 1 2 3 4 5 -----Sample Output:----- 1 1 32 1 32 654 1 32 654 10987 1 32 654 10987 1514131211 -----EXPLANATION:----- No need, else pattern can be decode easily.
["t = int(input())\nfor _ in range(t):\n n = int(input())\n for i in range(n):\n for j in range(n):\n if i>=j:\n print(int((i+1)*(i+2)/2)-j,end='')\n print()\n", "# cook your dish here\nt=int(input())\nfor i in range(0,t):\n n = int(input().strip())\n val=1\n for xyz in range(1,n+1):\n list1 = list()\n\n for abc in range(1,xyz+1):\n list1.append(val)\n val +=1\n print(*list1[::-1],sep='')\n print()\n list1.clear()", "# cook your dish here\nt=int(input())\nwhile(t!=0):\n s=''\n k=int(input())\n for i in range(1,k+1):\n for j in range(i*(i+1)//2,i*(i-1)//2,-1):\n s=s+str(j)\n print(s)\n s=''\n t-=1 \n", "# cook your dish here\nfor a0 in range(int(input())):\n n = int(input())\n l = []\n for j in range(1,(((n**2)+n)//2)+1):\n l.append(str(j))\n for i in range(n):\n s = \"\"\n x = l[:i+1]\n x = x[::-1]\n for p in x:\n s+=p\n print(s)\n l = l[i+1:]\n\n", "# cook your dish here\nfor i in range(int(input())):\n p=int(input())\n k=1\n print(1,end=\"\")\n print()\n s=0\n for i in range(1,p):\n k+=i+1\n x=k\n for j in range(i+1):\n print(x,end=\"\")\n x-=1\n print()\n", "for i in range(int(input())):\n p=int(input())\n k=1\n print(1,end=\"\")\n print()\n s=0\n for i in range(1,p):\n k+=i+1\n x=k\n for j in range(i+1):\n print(x,end=\"\")\n x-=1\n print()\n ", "# cook your dish here\nfor u in range(int(input().strip())):\n n = int(input().strip())\n k = 1\n for i in range(1,n+1):\n l = list()\n \n for j in range(1,i+1):\n l.append(k)\n k +=1\n print(*l[::-1],sep='')\n print()\n l.clear()", "# cook your dish here\n\n# cook your dish here\n\nt = int(input())\n\nwhile t:\n n = int(input())\n \n k = 1\n for i in range(n):\n m = k + i\n for j in range(i + 1):\n print(m - j, end='')\n k += 1\n \n print()\n \n t -= 1\n", "for _ in range(int(input())):\n n = int(input())\n if n == 1:\n print(1)\n continue\n ctr = 1\n lis = []\n temp = 1\n for i in range(n):\n for j in range(temp):\n lis.append(ctr)\n ctr += 1\n temp += 1\n lis.reverse()\n lis = list(map(str, lis))\n print(''.join(lis))\n lis = []", "\r\nt=int(input())\r\nwhile t>0:\r\n t-=1\r\n n=int(input())\r\n a=[]\r\n s=n*(n+1)//2\r\n for i in range(1,n+1):\r\n s=i*(i+1)//2\r\n for j in range(i):\r\n \r\n print(s,end=\"\")\r\n s-=1\r\n print()\r\n", "# cook your dish here\nfor i in range(int(input())):\n n = int(input())\n val=0\n for i in range(1,n+1):\n st=\"\"\n temp = val+i\n val = temp\n for j in range(i):\n print(temp,end=\"\")\n temp-=1\n print()", "from sys import*\r\ninput=stdin.readline\r\nt=int(input())\r\nfor _ in range(t):\r\n n=int(input())\r\n num=1\r\n diff=1\r\n for i in range(n):\r\n y=num\r\n for j in range(i+1):\r\n print(y,end=\"\")\r\n y-=1\r\n diff=diff+1\r\n num+=diff\r\n print()\r\n", "# cook your dish here\nfor _ in range(int(input())):\n n=int(input())\n t=0\n for i in range(1,n+1):\n j=0\n k=t+i\n while j<i:\n print(k,end=\"\")\n t+=1\n j+=1\n k-=1\n print(\"\")\n\n", "n=int(input())\nfor i in range(n):\n a=int(input())\n k=0\n for j in range(1,a+1):\n k=k+j\n for l in range(k,k-j,-1):\n print(l,end=\"\")\n print()# cook your dish here\n", "for _ in range(int(input())):\n n = int(input())\n l = 1\n i = 1\n while l <= n:\n s = ''\n for j in range(l):\n s = str(i) + s\n i += 1\n print(s)\n l += 1", "n=int(input())\nfor i in range(n):\n a=int(input())\n k=0\n for j in range(1,a+1):\n k=k+j\n for l in range(k,k-j,-1):\n print(l,end=\"\")\n print()# cook your dish here\n", "t=int(input())\r\nfor i in range(t):\r\n k=int(input())\r\n m=0\r\n for j in range(1,k+1):\r\n m=m+j\r\n n=m\r\n for l in range(1,j+1):\r\n print(n,end=\"\")\r\n n=n-1\r\n print()\r\n \r\n \r\n \r\n ", "for tc in range(int(input())):\r\n K = int(input())\r\n k = 1\r\n for i in range(K):\r\n ar = []\r\n for j in range(i + 1):\r\n ar.append(str(k))\r\n k += 1\r\n print(''.join(ar[::-1]))", "#Pattern J\r\nT = int(input())\r\n\r\nfor t in range(T):\r\n N = int(input())\r\n num = 1\r\n for i in range(N):\r\n sol = \"\"\r\n for j in range(i+1):\r\n sol = str(num) + sol\r\n num+=1\r\n print(sol)", "t=int(input())\nfor i in range(t):\n k=int(input())\n a=1\n for i in range(1,k+1):\n b=a+i\n l=[]\n for x in range(a,b):\n l.append(x)\n for y in l[::-1]:\n print(y,end=\"\")\n print() \n a=b \n \n", "t=int(input())\r\nfor _ in range(t):\r\n n=int(input())\r\n c=0\r\n for i in range(n):\r\n ans=\"\"\r\n c+=i+1\r\n for j in range(i+1):\r\n ans+=str(c)\r\n c-=1\r\n c+=i+1\r\n print(ans)\r\n \r\n \r\n \r\n \r\n \r\n \r\n", "# cook your dish here\nfor _ in range(int(input())):\n n=int(input())\n p=0\n for i in range(n):\n p+=i+1\n for j in range(p,p-i-1,-1):\n print(j,end='')\n print()\n \n \n ", "for _ in range(int(input())):\r\n n = int(input())\r\n\r\n j = 1\r\n\r\n for i in range(n):\r\n s = ''\r\n\r\n l = []\r\n for j in range(j, j+i+1):\r\n l.append(str(j))\r\n\r\n j += 1\r\n\r\n print(''.join(l[::-1]))"]
{"inputs": [["5", "1", "2", "3", "4", "5"]], "outputs": [["1", "1", "32", "1", "32", "654", "1", "32", "654", "10987", "1", "32", "654", "10987", "1514131211"]]}
INTERVIEW
PYTHON3
CODECHEF
6,322
4f01007f5faa4912ee34b18dcfc75e23
UNKNOWN
Bobby has decided to hunt some Parrots. There are n horizontal branch of trees aligned parallel to each other. Branches are numbered 1 to n from top to bottom. On each branch there are some parrots sitting next to each other. Supposed there are a[i]$a[i]$ parrots sitting on the i−th$ i-th$ branch. Sometimes Bobby shots one of the parrot and the parrot dies (suppose that this parrots sat at the i−th$i-th$ branch). Consequently all the parrots on the i−th$i-th$ branch to the left of the dead parrot get scared and jump up on the branch number i − 1$i - 1$, if there exists no upper branch they fly away. Also all the parrots to the right of the dead parrot jump down on branch number i + 1$i + 1$, if there exists no such branch they fly away. Bobby has shot m parrots. You're given the initial number of parrots on each branch, tell him how many parrots are sitting on each branch after the shots. -----Input:----- The first line of the input contains an integer N$N$. The next line contains a list of space-separated integers a1, a2, …, an. The third line contains an integer M$M$. Each of the next M$M$ lines contains two integers x[i]$x[i]$ and y[i]$y[i]$. The integers mean that for the i-th time Bobby shoot the y[i]-th (from left) parrot on the x[i]-th branch. It's guaranteed there will be at least y[i] parrot on the x[i]-th branch at that moment. -----Output:----- On the i−th$i-th$ line of the output print the number of parrots on the i−th$i-th$ branch. -----Constraints----- - 1≤N≤100$1 \leq N \leq 100$ - 0≤a[i]≤100$0 \leq a[i] \leq 100$ - 0≤M≤100$0 \leq M \leq 100$ - 1≤x[i]≤n$1 \leq x[i] \leq n$, 1≤y[i]$1 \leq y[i] $ -----Sample Input:----- 5 10 10 10 10 10 5 2 5 3 13 2 12 1 13 4 6 3 2 4 1 1 2 2 -----Sample Output:----- 0 12 5 0 16 3 0 3
["n = int(input())\nx = [int(i) for i in input().split()]\nm = int(input())\nfor i in range(m):\n a,b = map(int,input().split())\n a -= 1\n t = b-1\n t1 = x[a]-b\n if a-1>=0:\n x[a-1] += t\n if a+1<n:\n x[a+1] += t1\n x[a] = 0\nfor i in x:\n print(i)", "# cook your dish here\nN = int(input())\na = list(map(int,input().split()))\nM = int(input())\nfor _ in range(M):\n x,y = map(int,input().split())\n t = x-1\n if(t-1>=0):\n a[t-1] = a[t-1] + (y -1)\n if(t+1<=N-1):\n a[t+1] = a[t+1] + (a[t] - y)\n a[t] = 0\n \n \nfor j in a:\n print(j)", "Nb=int(input())\ntree=list(map(int,input().split()))\nNs=int(input())\nfor i in range(Ns):\n branch,bird=map(int,input().split())\n branch-=1\n bird-=1\n u=bird\n l=tree[branch]-bird-1\n tree[branch]=0\n if branch-1>=0:\n tree[branch-1]+=u\n try:\n tree[branch+1]+=l\n except:pass\n #print(tree)\nfor nb in tree: \n print(nb)", "n = int(input())\nbranches = list(map(int,input().split()))\n\nfor i in range(int(input())):\n\tbranch, parrot = list(map(int,input().split()))\n\n\t\n\n\tif branch>1:\n\t\tbranches[branch-2] = branches[branch-2]+ parrot-1\n\n\tif branch<n:\n\t\tbranches[branch] = branches[branch] + branches[branch-1] - parrot\n\n\tbranches[branch-1] = 0\n\n\nfor i in branches:\n\tprint(i)\n", "n=int(input())\na1=map(int,input().split())\nm=int(input())\na1=list(a1)\na1.insert(0,0)\na1.insert(n+1,0)\nfor i in range(m):\n x,y=map(int,input().split())\n a1[x-1]+=y-1\n a1[x+1]+=a1[x]-y\n a1[x]=0\nfor i in range(1,n+1):\n print(a1[i])", "n=int(input())\r\narr=list(map(int,input().split()))\r\nm=int(input())\r\nfor i in range(m):\r\n x,y=map(int,input().split())\r\n branch=x-1\r\n left=y-1\r\n right=arr[branch]-y\r\n if branch-1<0:\r\n if branch+1<n:\r\n arr[branch+1]+=right\r\n elif branch+1>=n:\r\n if branch-1>=0:\r\n arr[branch-1]+=left\r\n else:\r\n arr[branch-1]+=left\r\n arr[branch+1]+=right\r\n arr[branch]=0\r\nfor i in range(n):\r\n print(arr[i])", "N = int(input())\r\nbranch = list(map(int,input().split()))\r\nt = int(input())\r\nfor i in range(t):\r\n x, y = list(map(int,input().split()))\r\n if(x==1):\r\n try:\r\n branch[x] += branch[x-1] - y\r\n except:\r\n ...\r\n else:\r\n try:\r\n branch[x-2] += y - 1\r\n except:\r\n ...\r\n try:\r\n branch[x] += branch[x-1] - y\r\n except:\r\n ...\r\n branch[x-1] = 0\r\nfor j in branch:\r\n print(j)\r\n", "n = int(input())\r\na = [0] + list(map(int, input().split())) + [0]\r\n\r\nm = int(input())\r\n\r\nfor _ in range(m):\r\n x, y = list(map(int, input().split()))\r\n a[x-1] += y-1\r\n a[x+1] += a[x] - y\r\n a[x] = 0\r\n\r\nfor i in a[1:-1]:\r\n print(i)\r\n", "n=int(input())\r\na=list(map(int,input().split()))\r\nm=int(input())\r\nmini=0\r\nmaxi=n-1\r\nfor i in range(m):\r\n\r\n x,y=list(map(int,input().split()))\r\n x=x-1\r\n left=y-1\r\n right=a[x]-left-1\r\n ##print(left,right)\r\n if x-1>=0:\r\n a[x-1]+=left\r\n\r\n if x+1<=n-1:\r\n a[x+1]+=right\r\n a[x]=0\r\n\r\n ##print(a)\r\nfor i in range(len(a)):\r\n print(a[i])\r\n", "n=int(input())\r\na=list(map(int,input().split()))\r\nm=int(input())\r\nfor _ in range(m):\r\n x,y=map(int,input().split())\r\n x-=1\r\n if x-1>=0:\r\n a[x-1]+=y-1\r\n \r\n if x+1 <n:\r\n a[x+1]+=a[x]-y\r\n a[x]=0\r\nprint(*a ,sep=\"\\n\")", "n=int(input())\r\na=list(map(int,input().strip().split()))\r\nm=int(input())\r\nfor i in range(m):\r\n x,y=map(int,input().split())\r\n if(x-2>=0):\r\n a[x-2]+=y-1\r\n if(x<n):\r\n a[x]+=a[x-1]-y\r\n a[x-1]=0\r\nfor i in a:\r\n print(i)", "# cook your dish here\nn=int(input())\na=[int(X) for X in input().split()]\na=[0]+a\nfor j in range(int(input())):\n x,y = map(int,input().split())\n\n if x!=1:\n a[x-1]+=y-1\n if x!=n:\n a[x+1]+=(a[x]-y)\n a[x]=0\nprint(*a[1:],sep='\\n')", "n = int(input())\r\narr = list(map(int, input().split(\" \")))\r\nm = int(input())\r\nfor _ in range(m):\r\n branch, ind_from_left = map(int, input().split(\" \"))\r\n if branch > 1 and ind_from_left != 1:\r\n arr[branch - 2] += ind_from_left - 1\r\n if branch < n and ind_from_left != arr[branch - 1]:\r\n arr[branch] += arr[branch - 1] - ind_from_left\r\n arr[branch - 1] = 0\r\nfor b in arr:\r\n print(b)", "# cook your dish here\nwhile True:\n try:\n n=int(input())\n lst=[int(i) for i in input().split()]\n for _ in range(int(input())):\n a,b=[int(i) for i in input().split()]\n a=a-1\n if (a-1)>=0:\n lst[a-1]+=b-1\n if (a+1)<n:\n lst[a+1]+=lst[a]-b\n lst[a]=0\n for i in lst:\n print(i)\n except:\n break\n", "# cook your dish here\nn=int(input())\nl=list(map(int,input().split()))\nq=int(input())\nfor u in range(q):\n x,y=list(map(int,input().split()))\n x-=1\n if(x-1>=0):\n l[x-1]+=(y-1)\n if(x+1<n):\n l[x+1]+=(l[x]-y)\n l[x]=0\nfor i in l:\n print(i)\n", "n=int(input())\na=list(map(int,input().split()))\nq=int(int(input()))\nfor i in range(q):\n x,y=map(int,input().split())\n if (x-2)>=0:\n a[x-2]+=y-1\n if x<n:\n a[x]+=(a[x-1]-y)\n a[x-1]=0\nfor i in range(n):\n print(a[i])", "#dt = {} for i in x: dt[i] = dt.get(i,0)+1\r\nimport sys;input = sys.stdin.readline\r\ninp,ip = lambda :int(input()),lambda :[int(w) for w in input().split()]\r\n\r\nn = inp()\r\nx = ip()\r\nm = inp()\r\nfor i in range(m):\r\n ind,pos = ip()\r\n ind -= 1\r\n t = x[ind]\r\n x[ind] = 0\r\n if ind >= 1:\r\n x[ind-1] += pos-1\r\n if ind <= n-2:\r\n x[ind+1] += t-pos\r\nfor i in range(n):\r\n print(x[i])", "n = int(input())\nA = list(map(int, input().split()))\n\nm = int(input())\nfor _ in range(m):\n x, y = map(int, input().split())\n x -= 1\n y -= 1\n\n left = y\n right = A[x] - left - 1\n \n A[x] = 0\n \n if x - 1 >= 0:\n A[x - 1] += left\n if x + 1 < n:\n A[x + 1] += right\n \nfor a in A:\n print(a)"]
{"inputs": [["5", "10 10 10 10 10", "5", "2 5", "3 13", "2 12", "1 13", "4 6", "3", "2 4 1", "1", "2 2"]], "outputs": [["0", "12", "5", "0", "16", "3", "0", "3"]]}
INTERVIEW
PYTHON3
CODECHEF
6,393
77df9e8b1c1d6015b2f6d0f822ff932b
UNKNOWN
As you know America’s Presidential Elections are about to take place and the most popular leader of the Republican party Donald Trump is famous for throwing allegations against anyone he meets. He goes to a rally and meets n people which he wants to offend. For each person i he can choose an integer between 1 to max[i]. He wants to decide in how many ways he can offend all these persons (N) given the condition that all numbers chosen by him for each person are distinct. So he needs your help to find out the number of ways in which he can do that. If no solution is possible print 0 -----Input----- The first line of the input contains an integer T (1<=T<=100) 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 people Trump wants to offend. The second line contains N space-separated integers maxnumber[0], maxnumber[1], ..., maxnumber[n-1] denoting the maxnumber that trump can choose for each person. -----Output----- For each test case, output a single line containing the number of ways Trump can assign numbers to the people, modulo 1,000,000,007. If it's impossible to assign distinct integers to the people, print 0 -----Constraints----- - 1 ≤ T ≤ 100 - 1 ≤ N ≤ 50 - 1 ≤ Maxnumber[i] ≤ 3000 -----Example----- Input: 3 1 4 2 10 5 4 2 3 1 3 Output: 4 45 0 -----Explanation----- In case 1, He can choose any number from 1 to 4 In case 2,Out of the total 50 combination he can not take (1,1) ,(2,2) , (3,3) ,(4,4) or (5,5).
["for t in range(int(input())):\n n = int(input())\n a = sorted(map(int,input().split()))\n ans = 1\n for i in range(n):\n ans *= (a[i]-i)\n ans %= (10**9+7)\n if (ans == 0):\n break\n print(ans) ", "t = eval(input())\n\nfor i in range(t):\n n=eval(input())\n a = list(map(int, input().split()))\n a.sort()\n \n cnt=1\n for ind,x in enumerate(a):\n cnt*=(x-ind) \n if x-ind<=0:\n cnt=0\n break\n print(cnt%(10**9+7)) \n"]
{"inputs": [["3", "1", "4", "2", "10 5", "4", "2 3 1 3"]], "outputs": [["4", "45", "0"]]}
INTERVIEW
PYTHON3
CODECHEF
432
d379234fb081e9fcba116578845e895c
UNKNOWN
You are given a weighted graph with $N$ nodes and $M$ edges. Some of the nodes are marked as special nodes. Your task is to find the shortest pairwise distance between any two different special nodes. -----Input----- - The first line of the input contains three space-separated integers $N$, $M$ and $K$ denoting the number of nodes, the number of edges, and the number of special nodes. - The next line contains $K$ space-separated distinct integers $A_{1}$, $A_{2}$, $\ldots$, $A_{K}$, denoting the special nodes. - The next $M$ lines each contain three space-separated integers - $X$, $Y$, $Z$, denoting an edge connecting the nodes $X$ and $Y$, with weight $Z$. -----Output----- Output the shortest pairwise distance between any two different special nodes. -----Constraints----- - The given graph is connected. - The given graph doesn't contain self loops and multiple edges. - $1 \leq A_{i} \leq N$ - $1 \leq Z_{j} \leq 10^{4}$ - $1 \leq X_{j}, Y_{j} \leq N$ -----Subtasks----- Subtask #1 (20 points): - $2 \leq N \leq 300$ - $N-1 \leq M \leq \frac{N \cdot (N-1)}{2}$ - $2 \leq K \leq N$ Subtask #2 (25 points): - $2 \leq N \leq 10^5$ - $N-1 \leq M \leq 10^5$ - $2 \leq K \leq 10$ Subtask #3 (55 points): - $2 \leq N \leq 10^5$ - $N-1 \leq M \leq 3 \cdot 10^5$ - $2 \leq K \leq 10^4$ -----Example Input----- 5 5 3 1 3 5 1 2 3 2 3 4 3 4 1 4 5 8 1 5 19 -----Example Output----- 7 -----Explanation----- Nodes $1$, $3$, and $5$ are special nodes. Shortest distance between nodes $1$ and $3$ is $7$, and that between nodes $3$ and $5$ is $9$. Shortest distance between nodes $1$ and $5$ is $16$. Minimum of these distances is $7$. Hence answer is $7$.
["n,m,lk = list(map(int,input().split()))\nsp = [int(i)-1 for i in input().split()]\ndp = []\nfor i in range(n):\n dp += [[0]*n]\nfor i in range(n):\n for j in range(n):\n if(i!=j):\n dp[i][j]=10**18\nfor _ in range(m):\n x,y,z = list(map(int,input().split()))\n dp[x-1][y-1]=z\n dp[y-1][x-1]=z\nfor k in range(n):\n for i in range(n):\n for j in range(n):\n if(dp[i][j]>dp[i][k]+dp[k][j]):\n dp[i][j]=dp[i][k]+dp[k][j]\ndist = 10**18\nfor i in range(lk):\n for j in range(i+1,lk):\n dist = min(dist,dp[sp[i]][sp[j]])\nprint(dist)\n"]
{"inputs": [["5 5 3", "1 3 5", "1 2 3", "2 3 4", "3 4 1", "4 5 8", "1 5 19"]], "outputs": [["7"]]}
INTERVIEW
PYTHON3
CODECHEF
544
d416c73369528c475cda55e79c7288dd
UNKNOWN
Sereja has two integers — A and B — in 7-ary system. He wants to calculate the number C, such that B * C = A. It is guaranteed that B is a divisor of A. Please, help Sereja calculate the number C modulo 7L. -----Input----- First line of input contains an integer T — the number of test cases. T tests follow. For each test case, the first line contains the integer A, and the second line contains the integer B, and the third line contains the integer L. A and B are given in 7-ary system. -----Output----- Output the answer in 7-ary system. -----Constraints----- - 1 ≤ T ≤ 10 - A and B are both positive integers. - Length of A is a positive integer and doesn't exceed 106. - L and length of B are positive integers and do not exceed 10000. -----Subtasks----- - Sub task #1 (20 points): Length of A is a positive integer and doesn't exceed 20. - Sub task #2 (30 points): Length of A is a positive integer and doesn't exceed 2000. - Sub task #3 (50 points): Original constraints. -----Example----- Input:3 21 5 10 202 13 1 202 13 2 Output:3 3 13
["t=int(input())\nwhile t>0 :\n\ta=int(input())\n\tb=int(input())\n\tl=int(input())\n\tx=0\n\ty=0\n\tz=0\n\ta1=0\n\tb1=0\n\tc1=0\n\twhile(a//10!=0 or a%10!=0):\n\t\ta1+=(a%10+((a//10)%10)*7+((a//100)%10)*49+((a//1000)%10)*343+((a//10000)%10)*2401+((a//100000)%10)*16807+((a//1000000)%10)*117649+((a//10000000)%10)*823543+((a//100000000)%10)*5764801+((a//1000000000)%10)*40353607)*(282475249**x)\n\t\tx+=1\n\t\ta//=10000000000\n \n\twhile (b//10!=0 or b%10!=0):\n\t\tb1+=(b%10+((b//10)%10)*7+((b//100)%10)*49+((b//1000)%10)*343+((b//10000)%10)*2401+((b//100000)%10)*16807+((b//1000000)%10)*117649+((b//10000000)%10)*823543+((b//100000000)%10)*5764801+((b//1000000000)%10)*40353607)*(282475249**y)\n\t\ty+=1\n\t\tb//=10000000000\n\tc=(a1//b1)%(7**l)\n\twhile z<l:\n\t\tc1+=(c%7+((c//7)%7)*10+((c//49)%7)*100+((c//343)%7)*1000+((c//2401)%7)*10000+((c//16807)%7)*100000+((c//117649)%7)*1000000+((c//823543)%7)*10000000+((c//5764801)%7)*100000000+((c//40353607)%7)*1000000000)*(10000000000**(z//10))\n\t\tc//=282475249\n\t\tz+=10\n\tprint(c1)\n\tt-=1"]
{"inputs": [["3", "21", "5", "10", "202", "13", "1", "202", "13", "2"]], "outputs": [["3", "3", "13"]]}
INTERVIEW
PYTHON3
CODECHEF
1,047
18ca12f678554ef1cf6988b23cfb65ba
UNKNOWN
There are $N$ villages numbered $1$ to $N$. The villages are connected through bi-directional paths in between them. The whole network is in the form of a tree. Each village has only $1$ fighter but they help each other in times of crisis by sending their fighter to the village in danger through paths along the villages. Defeating a fighter will mean conquering his village. In particular, If village $X$ is under attack, all villages having a path to $X$ will send their fighters for help. Naruto wants to conquer all the villages. But he cannot take on so many fighters at the same time so he plans to use a secret technique with which he can destroy any $1$ village (along with paths connected to it) in the blink of an eye. However, it can be used only once. He realized that if he destroys any village, say $X$, the maximum number of fighters he has to fight at once reduces to $W$. He wants $W$ to be as small as possible. Help him find the optimal $X$. In case of multiple answers, choose the smallest value of $X$. -----Input:----- - First line will contain $T$, number of testcases. Then the testcases follow. - First Line contains $N$. - Next $N - 1$ lines contain $U, V$, denoting a path between village $U$ and $V$. -----Output:----- - For each Test case, print in a new line, optimal $X$ and corresponding value of $W$. -----Constraints----- - $1 \leq T \leq 10$ - $3 \leq N \leq 10^5$ - $1 \leq U, V \leq N$ - $U != V$ -----Sample Input:----- 2 5 1 2 1 3 2 4 3 5 3 1 2 2 3 -----Sample Output:----- 1 2 2 1 -----EXPLANATION:----- Sample 1: By destroying village $1$, The fighters Naruto will be fighting at the same time will be from villages $[2, 4]$ and $[3, 5]$. For this $W$ = $2$. No other choice can give lesser $W$. Hence $1$ is optimal choice.
["# cook your dish here\ndef solve(edges,ans):\n n = len(edges)\n visited = set()\n parents = [-1]*(n+1)\n dp = [0]*(n+1)\n stack = [1]\n w = float('inf')\n x = -1\n while stack:\n node = stack[-1]\n if node not in visited:\n count = 0\n for kid in edges[node]:\n if parents[kid] == -1:\n if kid != 1:\n parents[kid] = node\n else:\n if kid != parents[node]:\n if kid in visited:\n count += 1\n else:\n stack.append(kid)\n\n if node == 1:\n count -= 1\n if count == len(edges[node])-1:\n stack.pop()\n visited.add(node)\n max_val = 0\n for kid in edges[node]:\n dp[node] += dp[kid]\n max_val = max(max_val,dp[kid])\n\n dp[node] += 1\n\n max_val = max(max_val,n-dp[node])\n if max_val < w:\n w = max_val\n x = node\n elif max_val == w:\n x = min(x,node)\n\n ans.append(str(x)+' '+str(w))\n \ndef main():\n t = int(input())\n ans = []\n for i in range(t):\n n = int(input())\n edges = {}\n for j in range(1,n+1):\n edges[j] = []\n\n for j in range(n-1):\n x,y = list(map(int,input().split()))\n edges[x].append(y)\n edges[y].append(x)\n\n solve(edges,ans)\n\n print('\\n'.join(ans))\n\nmain()\n"]
{"inputs": [["2", "5", "1 2", "1 3", "2 4", "3 5", "3", "1 2", "2 3"]], "outputs": [["1 2", "2 1"]]}
INTERVIEW
PYTHON3
CODECHEF
1,206
42d3161157a376b336634c6338fecf30
UNKNOWN
Istiak is learning about arithmetic progressions. Today, he wrote an arithmetic sequence on a piece of paper. Istiak was very happy that he managed to write an arithmetic sequence and went out for lunch. Istiak's friend Rafsan likes to irritate him by playing silly pranks on him. This time, he could have chosen one element of Istiak's sequence and changed it. When Istiak came back, he was devastated to see his sequence ruined — it became a sequence $a_1, a_2, \ldots, a_N$ (possibly identical to the original sequence, if Rafsan did not change anything, in which case Istiak is just overreacting). Help him recover the original sequence. Formally, you have to find an arithmetic sequence $b_1, b_2, \ldots, b_N$ which differs from $a$ in at most one position. $b$ is said to be an arithmetic sequence if there is a real number $d$ such that $b_i - b_{i-1} = d$ for each $i$ ($2 \le i \le N$). If there are multiple valid solutions, you may find any one. -----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$. -----Output----- For each test case, print a single line containing $N$ space-separated integers $b_1, b_2, \ldots, b_N$. It is guaranteed that a valid solution exists. -----Constraints----- - $4 \le N \le 10^5$ - $|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----- 3 4 1 3 10 7 5 -10 -5 0 5 10 4 2 2 2 10 -----Example Output----- 1 3 5 7 -10 -5 0 5 10 2 2 2 2 -----Explanation----- Example case 1: Rafsan changed the third element from $5$ to $10$. Example case 2: No elements were changed. Example case 3: Rafsan changed the fourth element from $2$ to $10$.
["# cook your dish here\ntest_cases = int(input())\nfor i in range(test_cases):\n no_of_elements = int(input())\n sequence = list(map(int, input().split()))\n d1 = sequence[1] - sequence[0]\n d2 = sequence[2] - sequence[1]\n d3 = (sequence[3] - sequence[0])/3\n d4 = (sequence[3] - sequence[1])/2\n d5 = (sequence[2] - sequence[0])/2\n\n if (d2 == d4):\n d = d2\n\n elif(d3 == d5):\n d = d3\n\n elif(d1 == d3):\n d = d1\n\n elif(d1 == d5):\n d = d1\n\n if (d == d1):\n for i in range(no_of_elements):\n sequence[i] = int(sequence[0] + i*d)\n else:\n for i in range(no_of_elements):\n sequence[i] = int(sequence[-1] - ((no_of_elements - i - 1)*d))\n\n for i in sequence:\n print(i, end=\" \")\n\n print('\\n')\n\n\n", "from statistics import mode\nt=int(input())\nfor _ in range(t):\n n=int(input())\n l=list(map(int,input().split()))\n ll=len(l)\n diff=list()\n if(ll==4):\n diff.append(((l[3]-l[0])//3))\n for i in range(ll-1):\n diff.append(l[i+1]-l[i])\n x=mode(diff)\n if(l[0]-l[1]!=x and l[2]-l[1]==x):\n l[0]=l[1]-x\n for i in range(ll-1):\n if(l[i+1]-l[i]!=x):\n l[i+1]=l[i]+x\n \n for i in range(ll):\n print(l[i],end=\" \")\n print()", "from collections import Counter\ndef new_seq(l,d,x):\n new=[x]\n for i in range(len(l)-1):\n t=new[-1]+d\n new.append(t)\n return new\nfor _ in range(int(input())):\n n=int(input())\n l=list(map(int,input().split()))\n aux=[]\n for i in range(n-1):\n aux.append(l[i+1]-l[i])\n aux_1=Counter(aux)\n aux=list(set(aux))\n if len(aux)>1 and len(aux)==3:\n a,b,c=aux[0],aux[1],aux[2]\n if a+b==(2*c):\n t_1=new_seq(l,c,l[0])\n print(*t_1)\n elif a+c==(2*b):\n t_1=new_seq(l,b,l[0])\n print(*t_1)\n else:\n t_1=new_seq(l,a,l[0])\n print(*t_1)\n elif len(aux)==2:\n t_2=aux_1.most_common(1)[0][0]\n if l[0]-l[1]!=t_2:\n print(*new_seq(l,t_2,l[1]-t_2))\n else:\n print(*new_seq(l,t_2,l[0]))\n else:\n print(*l)\n", "t=int(input())\nwhile(t>0):\n n=int(input())\n l=list(map(int,input().split()))\n x=l[1]-l[0]\n if(l[2]-l[1]==l[3]-l[2])and(l[2]-l[1]!=x):\n l[0]=-l[2]+2*l[1]\n elif(l[2]-l[1]!=x)and(l[3]-l[2]!=l[2]-l[1])and(l[3]-l[2]!=x):\n y=l[3]-l[0]\n y//=3\n if(x==y):\n l[2]=l[1]+x\n else:\n l[1]=l[0]+y\n else:\n for i in range(2,n):\n if(l[i]!=l[i-1]+x):\n l[i]=l[i-1]+x\n break\n print(*l)\n t-=1", "# cook your dish here\nfor j in range(int(input())):\n n=int(input())\n x=list(map(int,input().split()))\n w=x.copy()\n t=x.copy()\n d=x[1]-x[0]\n z=[x[0],x[1]]\n for i in range(2,n):\n x[i]=x[i-1]+d\n z.append(x[i])\n e=t[-1]-t[-2]\n y=[t[-1],t[-2]]\n for i in range(n-2):\n t[n-2-i-1]=t[n-2-i]-e\n y.append(t[n-2-i-1])\n y.reverse()\n am,bm=0,0\n for i in range(n):\n if(w[i]!=y[i]):\n am+=1\n if(am>1):\n break\n if(w[i]!=z[i]):\n bm+=1\n if(bm>1):\n break\n if(am==1):\n print(*y)\n else:\n print(*z)\n", "for j in range(int(input())):\n n=int(input())\n x=list(map(int,input().split()))\n w=x.copy()\n t=x.copy()\n d=x[1]-x[0]\n z=[x[0],x[1]]\n for i in range(2,n):\n x[i]=x[i-1]+d\n z.append(x[i])\n e=t[-1]-t[-2]\n y=[t[-1],t[-2]]\n for i in range(n-2):\n t[n-2-i-1]=t[n-2-i]-e\n y.append(t[n-2-i-1])\n y.reverse()\n am,bm=0,0\n for i in range(n):\n if(w[i]!=y[i]):\n am+=1\n if(am>1):\n break\n if(w[i]!=z[i]):\n bm+=1\n if(bm>1):\n break\n if(am==1):\n print(*y)\n else:\n print(*z)\n", "#!/usr/bin/env python3\n# -*- coding: utf-8 -*-\n\"\"\"\nCreated on Sat May 16 22:03:29 2020\n\n@author: shailesh\n\"\"\"\n\n\ndef findD_and_start(A):\n first = A[1] - A[0]\n second = A[2] - A[1]\n third = A[3] - A[2]\n if first == second:\n return second,A[0]\n elif third == second:\n return third,A[3] - 3*third\n else:\n return (A[3] - A[0])//3,A[0]\nT = int(input())\n\nfor t in range(T):\n N = int(input())\n A = [int(i) for i in input().split()]\n d,start = findD_and_start(A)\n \n s = ''\n if d ==0:\n for i in range(N):\n s+=str(start) + ' '\n else:\n for i in range(start,start + N*d,d):\n s+= str(i) + ' '\n print(s.strip())", "for _ in range(int(input())):\n n = int(input())\n a = list(map(int, input().split()))\n f = False\n d = 0\n for i in range(1, n - 3):\n if a[i] - a[i - 1] != a[i + 1] - a[i]:\n d = a[i + 3] - a[i + 2]\n a[i + 1] = a[i + 2] - d\n a[i] = a[i + 1] - d\n a[i - 1] = a[i] - d\n f = True\n break\n\n if (not f):\n if (a[n - 1] - a[n - 4]) / 3 == (a[n - 1] - a[n - 2]):\n d = a[n - 1] - a[n - 2]\n a[n - 3] = a[n - 2] - d\n elif (a[n - 1] - a[n - 4]) / 3 == (a[n - 1] - a[n - 3]) / 2:\n d = a[n - 3] - a[n - 4]\n a[n - 2] = a[n - 3] + d\n elif a[n - 1] - a[n - 2] == a[n - 2] - a[n - 3]:\n d = a[n - 1] - a[n - 2]\n a[n-4] = a[n-3]-d\n else:\n d = a[n - 3] - a[n - 4]\n a[n - 1] = a[n - 2] + d\n\n [print(x, end=\" \") for x in a]\n print()\n", "t = int(input())\nfor T in range(t):\n n = int(input())\n a = [int(x) for x in input().split()]\n diff = []\n cor = 0\n \n for i in range(1, n):\n diff.append(a[i] - a[i - 1])\n d = set(diff)\n d = list(d)\n \n if len(d) == 1:\n print(*a)\n continue\n if len(d) == 2:\n cor = a[2] - a[1]\n if a[1] - a[0] != cor:\n a[0] = a[1] - cor\n else:\n a[-1] = a[-2] + cor\n print(*a)\n continue\n\n \n if (d[0] + d[1]) / 2 == d[2]:\n cor = d[2]\n elif (d[1] + d[2]) / 2 == d[0]:\n cor = d[0]\n else:\n cor = d[1]\n for i in range(1, n):\n if a[i] - a[i - 1] != cor:\n a[i] = a[i - 1] + cor\n print(*a)\n", "t=int(input())\nfor _ in range(t):\n n=int(input())\n a=list(map(int,input().split()))\n if n==4:\n target=-1\n cur=-1\n ind=-1\n s=set()\n flag=False\n for i in range(1,n):\n k=a[i]-a[i-1]\n if k not in s:\n s.add(k)\n else:\n target=k \n cur=a[i]\n ind=i \n flag=True\n break\n if flag:\n back=[cur]\n forth=[cur]\n for i in range(ind+1,n):\n forth.append(forth[-1]+target)\n for i in range(ind-1,-1,-1):\n back.append(back[-1]-target)\n back=back[::-1]\n back.pop()\n print(*back,end=\" \")\n print(*forth)\n else:\n k=(a[-1]-a[0])//(n-1)\n for i in range(n-1,-1,-1):\n print(a[-1]-k*i,end=\" \")\n print() \n else:\n target=-1\n cur=-1\n ind=-1\n s=set()\n for i in range(1,n):\n k=a[i]-a[i-1]\n if k not in s:\n s.add(k)\n else:\n target=k \n cur=a[i]\n ind=i \n break \n back=[cur]\n forth=[cur]\n for i in range(ind+1,n):\n forth.append(forth[-1]+target)\n for i in range(ind-1,-1,-1):\n back.append(back[-1]-target)\n back=back[::-1]\n back.pop()\n print(*back,end=\" \")\n print(*forth)\n ", "t=int(input())\nfor _ in range(t):\n n=int(input())\n a=list(map(int,input().split()))\n if n==4:\n target=-1\n cur=-1\n ind=-1\n s=set()\n flag=False\n for i in range(1,n):\n k=a[i]-a[i-1]\n if k not in s:\n s.add(k)\n else:\n target=k \n cur=a[i]\n ind=i \n flag=True\n break\n if flag:\n back=[cur]\n forth=[cur]\n for i in range(ind+1,n):\n forth.append(forth[-1]+target)\n for i in range(ind-1,-1,-1):\n back.append(back[-1]-target)\n back=back[::-1]\n back.pop()\n print(*back,end=\" \")\n print(*forth)\n else:\n k=(a[-1]-a[0])//(n-1)\n for i in range(n-1,-1,-1):\n print(a[-1]-k*i,end=\" \")\n print() \n else:\n target=-1\n cur=-1\n ind=-1\n s=set()\n for i in range(1,n):\n k=a[i]-a[i-1]\n if k not in s:\n s.add(k)\n else:\n target=k \n cur=a[i]\n ind=i \n break \n back=[cur]\n forth=[cur]\n for i in range(ind+1,n):\n forth.append(forth[-1]+target)\n for i in range(ind-1,-1,-1):\n back.append(back[-1]-target)\n back=back[::-1]\n back.pop()\n print(*back,end=\" \")\n print(*forth)\n ", "for i in range(0,int(input())):\n n=int(input())\n l=list(map(int,input().split()))\n d1=l[1]-l[0]\n d2=l[2]-l[1]\n if(d2==d1):\n ce=l[2]\n for j in range(3,n):\n if l[j]==ce+d1:\n ce+=d1\n else:\n l[j]=ce+d1\n break\n else:\n if l[3]-l[0]==3*d1:\n l[2]=l[1]+d1\n elif l[2]-l[0]==2*(l[3]-l[2]):\n l[1]=l[0]+l[3]-l[2]\n else:\n l[0]=2*l[1]-l[2]\n for j in range(0,n):\n print(l[j],end=\" \")\n print(\"\")\n ", "for _ in range(int(input())):\n N = int(input())\n array = list(map(int, input().split()))\n d1 = array[1] - array[0]\n d2 = array[2] - array[1]\n d3 = array[3] - array[2]\n d = 0\n if d1 == d2:\n d = d1\n elif d1 == d3:\n d = d1\n elif d2 == d3:\n d = d2\n else:\n d = (array[3] - array[0])//3\n\n for i in range(N-1):\n if array[i+1] - array[i] != d:\n if i == 0:\n if array[2] - array[1] == d:\n array[0] = array[1] - d\n else:\n array[1] = array[0] + d\n else:\n array[i+1] = array[i] + d\n break\n print(*array)", "def printAp(a,d,l):\n print(\" \".join([str(int(a+(i*d))) for i in range(l)]))\nt=int(input())\nfor i in range(t):\n n=int(input())\n lst=[int(x) for x in input().split(\" \")]\n a=0;\n diff=0;\n if ((lst[0]+lst[2])/2==lst[1]):\n a=lst[0]\n diff=lst[1]-lst[0]\n elif ((lst[1]+lst[3])/2==lst[2]):\n diff=lst[2]-lst[1]\n a=lst[1]-diff\n else:\n a=lst[0]\n diff=(lst[3]-lst[0])/3\n printAp(a,diff,n);\n", "def printAp(a,d,l):\n print(\" \".join([str(int(a+(i*d))) for i in range(l)]))\nt=int(input())\nfor i in range(t):\n n=int(input())\n lst=[int(x) for x in input().split(\" \")]\n a=0;\n diff=0;\n if ((lst[0]+lst[2])/2==lst[1]):\n a=lst[0]\n diff=lst[1]-lst[0]\n elif ((lst[1]+lst[3])/2==lst[2]):\n diff=lst[2]-lst[1]\n a=lst[1]-diff\n else:\n a=lst[0]\n diff=(lst[3]-lst[0])/3\n printAp(a,diff,n);\n \n"]
{"inputs": [["3", "4", "1 3 10 7", "5", "-10 -5 0 5 10", "4", "2 2 2 10"]], "outputs": [["1 3 5 7", "-10 -5 0 5 10", "2 2 2 2"]]}
INTERVIEW
PYTHON3
CODECHEF
9,405
fbea1792cfce7e7351bb0a1b25a25457
UNKNOWN
Prime numbers are arranged in a ordered list U$U$, in increasing order. Let S$S$ be a sublist of U$U$ with a unique property that for every element A$A$ belonging to list S$S$, if i$i$ denotes the index of A$A$ in list U$U$, than i$i$ also belongs to list U$U$. Given N$N$, find sum of first N$N$ elements of list S$S$, assuming 1-based indexing. As the sum can be very large, print the sum 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. -Only line of each test case has an integer N$N$ . -----Output:----- For each test case, print a single integer denoting the sum of first N$N$ elements of set S$S$ modulo 109+7$10^{9}+7$. -----Constraints----- - 1≤T≤10000$1 \leq T \leq 10000$ - 1≤N≤1000$1 \leq N \leq 1000$ -----Subtasks----- - 20 points : - 1≤T≤10000$1 \leq T \leq 10000$ - 1≤N≤10$1 \leq N \leq 10$ - 20 points : - 1≤T≤100$1 \leq T \leq 100$ - 1≤N≤100$1 \leq N \leq 100$ - 60 points : Original Constraints -----Sample Input:----- 2 1 2 -----Sample Output:----- 3 8 -----EXPLANATION:----- Example case 1: First few elements of set S$S$ are {3,5,11…} , so sum is 3. Example case 2: Sum is 3+5=8.
["import math\r\ndef prime(aa):\r\n\tf=0\r\n\tfor y in ar:\r\n\t\tif aa%y==0:\r\n\t\t\t\treturn 0\r\n\treturn 1\r\nar=[]\r\nar.append(2)\r\npc=3\r\nte=int(input())\r\nfor _ in range(te):\r\n\ta=int(input())\r\n\tf=0\r\n\tc=0\r\n\tadd=0\r\n\tfor x in ar:\r\n\t\ttry:\r\n\t\t\tadd=add+ar[x-1]\r\n\t\texcept:\r\n\t\t\twhile True:\r\n\t\t\t\tif prime(pc)==1:\r\n\t\t\t\t\tar.append(pc)\r\n\t\t\t\t\tif x<=len(ar):\r\n\t\t\t\t\t\tbreak\r\n\t\t\t\tpc+=1\r\n\t\t\tpc+=1\r\n\t\t\tadd=add+ar[x-1]\r\n\t\tc+=1\r\n\t\tif c==a:\r\n\t\t\tbreak\r\n\tprint(add)\r\n", "l=[3, 5, 11, 17, 31, 41, 59, 67, 83, 109, 127, 157, 179, 191, 211, 241, 277, 283, 331, 353, 367, 401, 431, 461, 509, 547, 563, 587, 599, 617, 709, 739, 773, 797, 859, 877, 919, 967, 991, 1031, 1063, 1087, 1153, 1171, 1201, 1217, 1297, 1409, 1433, 1447, 1471, 1499, 1523, 1597, 1621, 1669, 1723, 1741, 1787, 1823, 1847, 1913, 2027, 2063, 2081, 2099, 2221, 2269, 2341, 2351, 2381, 2417, 2477, 2549, 2609, 2647, 2683, 2719, 2749, 2803, 2897, 2909, 3001, 3019, 3067, 3109, 3169, 3229, 3259, 3299, 3319, 3407, 3469, 3517, 3559, 3593, 3637, 3733, 3761, 3911, 3943, 4027, 4091, 4133, 4153, 4217, 4273, 4339, 4397, 4421, 4463, 4517, 4549, 4567, 4663, 4759, 4787, 4801, 4877, 4933, 4943, 5021, 5059, 5107, 5189, 5281, 5381, 5441, 5503, 5557, 5623, 5651, 5701, 5749, 5801, 5851, 5869, 6037, 6113, 6217, 6229, 6311, 6323, 6353, 6361, 6469, 6599, 6653, 6661, 6691, 6823, 6841, 6863, 6899, 7057, 7109, 7193, 7283, 7351, 7417, 7481, 7523, 7607, 7649, 7699, 7753, 7841, 7883, 8011, 8059, 8101, 8117, 8221, 8233, 8287, 8377, 8389, 8513, 8527, 8581, 8719, 8747, 8761, 8807, 8849, 8923, 8999, 9041, 9103, 9293, 9319, 9403, 9461, 9539, 9619, 9661, 9739, 9833, 9859, 9923, 9973, 10009, 10079, 10169, 10267, 10433, 10457, 10487, 10559, 10589, 10631, 10663, 10687, 10723, 10853, 10861, 10909, 11257, 11311, 11369, 11447, 11633, 11743, 11867, 11909, 11927, 11953, 12007, 12097, 12113, 12143, 12203, 12301, 12409, 12421, 12457, 12479, 12503, 12547, 12647, 12763, 12841, 12959, 13003, 13037, 13103, 13171, 13217, 13297, 13331, 13469, 13513, 13591, 13613, 13649, 13693, 13709, 13757, 13859, 14051, 14107, 14159, 14177, 14437, 14479, 14503, 14591, 14713, 14723, 14783, 14867, 14923, 14969, 15061, 15227, 15271, 15299, 15313, 15413, 15511, 15641, 15683, 15823, 15973, 16061, 16073, 16091, 16127, 16141, 16253, 16411, 16451, 16519, 16693, 16703, 16901, 16921, 17117, 17189, 17291, 17333, 17377, 17387, 17417, 17483, 17539, 17627, 17659, 17761, 17911, 17987, 18049, 18149, 18181, 18217, 18229, 18311, 18433, 18443, 18617, 18661, 18719, 18757, 18787, 18917, 19013, 19213, 19433, 19463, 19501, 19577, 19759, 19777, 19819, 19913, 20047, 20063, 20107, 20161, 20231, 20297, 20341, 20441, 20477, 20719, 20759, 20773, 20873, 20899, 20959, 21089, 21149, 21179, 21191, 21269, 21317, 21379, 21493, 21529, 21587, 21727, 21757, 21817, 21937, 22027, 22067, 22093, 22367, 22549, 22651, 22721, 22751, 22811, 22853, 22907, 23087, 23209, 23251, 23431, 23539, 23563, 23669, 23801, 23887, 23899, 23929, 24019, 24071, 24107, 24133, 24151, 24197, 24251, 24379, 24419, 24439, 24509, 24631, 24671, 24781, 24859, 24917, 25057, 25163, 25301, 25307, 25357, 25409, 25423, 25601, 25733, 25763, 25841, 25919, 25969, 26003, 26189, 26263, 26371, 26423, 26489, 26591, 26693, 26783, 26921, 26953, 27017, 27073, 27091, 27437, 27457, 27581, 27689, 27733, 27809, 27847, 27943, 28057, 28109, 28279, 28307, 28393, 28573, 28643, 28657, 28807, 29101, 29137, 29153, 29269, 29333, 29383, 29483, 29569, 29641, 29683, 29803, 30071, 30091, 30113, 30133, 30253, 30557, 30577, 30661, 30707, 30781, 30829, 30869, 30881, 31033, 31069, 31181, 31189, 31267, 31277, 31489, 31513, 31667, 31729, 32003, 32143, 32233, 32261, 32299, 32323, 32341, 32533, 32603, 32719, 32797, 32911, 32933, 32969, 33013, 33029, 33083, 33191, 33203, 33347, 33457, 33469, 33569, 33647, 33749, 33769, 33827, 33911, 33967, 34057, 34259, 34351, 34367, 34421, 34543, 34607, 34651, 34729, 34843, 34919, 35023, 35081, 35311, 35363, 35393, 35507, 35617, 35731, 35801, 35977, 35993, 36083, 36251, 36293, 36307, 36451, 36563, 36599, 36683, 36847, 36887, 36929, 36943, 36997, 37049, 37061, 37217, 37273, 37489, 37657, 37831, 37853, 37889, 37967, 38039, 38053, 38153, 38351, 38377, 38459, 38669, 38711, 38833, 38851, 38917, 39043, 39199, 39217, 39239, 39317, 39451, 39509, 39521, 39733, 39979, 40093, 40151, 40163, 40277, 40289, 40459, 40483, 40577, 40637, 40693, 40801, 40819, 40897, 40961, 41051, 41351, 41467, 41491, 41597, 41647, 41719, 41843, 41983, 42043, 42181, 42293, 42307, 42461, 42499, 42569, 42643, 42697, 42853, 42863, 42979, 43151, 43223, 43283, 43313, 43391, 43633, 43651, 43787, 43889, 44029, 44111, 44171, 44221, 44453, 44621, 44633, 44657, 44729, 44753, 44809, 44879, 44971, 45061, 45191, 45329, 45541, 45557, 45631, 45673, 45863, 45971, 46237, 46279, 46307, 46349, 46441, 46451, 46573, 46619, 46751, 47123, 47237, 47297, 47417, 47563, 47623, 47713, 47837, 47857, 47911, 47963, 48073, 48131, 48259, 48281, 48337, 48481, 48533, 48593, 48647, 48731, 48751, 48821, 48847, 49031, 49139, 49207, 49411, 49451, 49523, 49639, 49667, 49739, 49789, 49843]\r\nt=int(input())\r\nfor i in range(t):\r\n s=0\r\n n=int(input())\r\n for i in range(n):\r\n \ts+=l[i]\r\n print(s%1000000007)\t", "k = []\r\nn = 100000\r\nprime = [True for i in range(n+1)]\r\np = 2\r\nfor i in range(2,int(n ** 0.5)+ 1):\r\n if prime[i]:\r\n j = 2\r\n while i * j <= n:\r\n prime[i * j] = False\r\n j += 1\r\nfor p in range(2, n+1):\r\n if prime[p]: \r\n k.append(p)\r\nfor _ in range(int(input())):\r\n n = int(input())\r\n sum = 0\r\n for i in range(n):\r\n sum += k[k[i]-1]\r\n print(sum)", "import math\r\ndef prime(aa):\r\n\tf=0\r\n\tif aa>=100:\r\n\t\tto=int(math.sqrt(aa))\r\n\telse:\r\n\t\tto=aa\r\n\tfor y in range(2,to):\r\n\t\tif aa%y==0:\r\n\t\t\t\treturn 0\r\n\treturn 1\r\n\r\nte=int(input())\r\nfor _ in range(te):\r\n\ta=int(input())\r\n\tar=[]\r\n\tar.append(2)\r\n\tf=0\r\n\tc=0\r\n\tpc=3\r\n\tadd=0\r\n\tfor x in ar:\r\n\t\ttry:\r\n\t\t\tadd=add+ar[x-1]\r\n\t\texcept:\r\n\t\t\twhile True:\r\n\t\t\t\tif prime(pc)==1:\r\n\t\t\t\t\tar.append(pc)\r\n\t\t\t\t\tif x<=len(ar):\r\n\t\t\t\t\t\tbreak\r\n\t\t\t\tpc+=1\r\n\t\t\tpc+=1\r\n\t\tadd=add+ar[x-1]\r\n\t\tc+=1\r\n\t\tif c==a:\r\n\t\t\tbreak\r\n\tprint(add)\r\n", "l=[2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997, 1009, 1013, 1019, 1021, 1031, 1033, 1039, 1049, 1051, 1061, 1063, 1069, 1087, 1091, 1093, 1097, 1103, 1109, 1117, 1123, 1129, 1151, 1153, 1163, 1171, 1181, 1187, 1193, 1201, 1213, 1217, 1223, 1229, 1231, 1237, 1249, 1259, 1277, 1279, 1283, 1289, 1291, 1297, 1301, 1303, 1307, 1319, 1321, 1327, 1361, 1367, 1373, 1381, 1399, 1409, 1423, 1427, 1429, 1433, 1439, 1447, 1451, 1453, 1459, 1471, 1481, 1483, 1487, 1489, 1493, 1499, 1511, 1523, 1531, 1543, 1549, 1553, 1559, 1567, 1571, 1579, 1583, 1597, 1601, 1607, 1609, 1613, 1619, 1621, 1627, 1637, 1657, 1663, 1667, 1669, 1693, 1697, 1699, 1709, 1721, 1723, 1733, 1741, 1747, 1753, 1759, 1777, 1783, 1787, 1789, 1801, 1811, 1823, 1831, 1847, 1861, 1867, 1871, 1873, 1877, 1879, 1889, 1901, 1907, 1913, 1931, 1933, 1949, 1951, 1973, 1979, 1987, 1993, 1997, 1999, 2003, 2011, 2017, 2027, 2029, 2039, 2053, 2063, 2069, 2081, 2083, 2087, 2089, 2099, 2111, 2113, 2129, 2131, 2137, 2141, 2143, 2153, 2161, 2179, 2203, 2207, 2213, 2221, 2237, 2239, 2243, 2251, 2267, 2269, 2273, 2281, 2287, 2293, 2297, 2309, 2311, 2333, 2339, 2341, 2347, 2351, 2357, 2371, 2377, 2381, 2383, 2389, 2393, 2399, 2411, 2417, 2423, 2437, 2441, 2447, 2459, 2467, 2473, 2477, 2503, 2521, 2531, 2539, 2543, 2549, 2551, 2557, 2579, 2591, 2593, 2609, 2617, 2621, 2633, 2647, 2657, 2659, 2663, 2671, 2677, 2683, 2687, 2689, 2693, 2699, 2707, 2711, 2713, 2719, 2729, 2731, 2741, 2749, 2753, 2767, 2777, 2789, 2791, 2797, 2801, 2803, 2819, 2833, 2837, 2843, 2851, 2857, 2861, 2879, 2887, 2897, 2903, 2909, 2917, 2927, 2939, 2953, 2957, 2963, 2969, 2971, 2999, 3001, 3011, 3019, 3023, 3037, 3041, 3049, 3061, 3067, 3079, 3083, 3089, 3109, 3119, 3121, 3137, 3163, 3167, 3169, 3181, 3187, 3191, 3203, 3209, 3217, 3221, 3229, 3251, 3253, 3257, 3259, 3271, 3299, 3301, 3307, 3313, 3319, 3323, 3329, 3331, 3343, 3347, 3359, 3361, 3371, 3373, 3389, 3391, 3407, 3413, 3433, 3449, 3457, 3461, 3463, 3467, 3469, 3491, 3499, 3511, 3517, 3527, 3529, 3533, 3539, 3541, 3547, 3557, 3559, 3571, 3581, 3583, 3593, 3607, 3613, 3617, 3623, 3631, 3637, 3643, 3659, 3671, 3673, 3677, 3691, 3697, 3701, 3709, 3719, 3727, 3733, 3739, 3761, 3767, 3769, 3779, 3793, 3797, 3803, 3821, 3823, 3833, 3847, 3851, 3853, 3863, 3877, 3881, 3889, 3907, 3911, 3917, 3919, 3923, 3929, 3931, 3943, 3947, 3967, 3989, 4001, 4003, 4007, 4013, 4019, 4021, 4027, 4049, 4051, 4057, 4073, 4079, 4091, 4093, 4099, 4111, 4127, 4129, 4133, 4139, 4153, 4157, 4159, 4177, 4201, 4211, 4217, 4219, 4229, 4231, 4241, 4243, 4253, 4259, 4261, 4271, 4273, 4283, 4289, 4297, 4327, 4337, 4339, 4349, 4357, 4363, 4373, 4391, 4397, 4409, 4421, 4423, 4441, 4447, 4451, 4457, 4463, 4481, 4483, 4493, 4507, 4513, 4517, 4519, 4523, 4547, 4549, 4561, 4567, 4583, 4591, 4597, 4603, 4621, 4637, 4639, 4643, 4649, 4651, 4657, 4663, 4673, 4679, 4691, 4703, 4721, 4723, 4729, 4733, 4751, 4759, 4783, 4787, 4789, 4793, 4799, 4801, 4813, 4817, 4831, 4861, 4871, 4877, 4889, 4903, 4909, 4919, 4931, 4933, 4937, 4943, 4951, 4957, 4967, 4969, 4973, 4987, 4993, 4999, 5003, 5009, 5011, 5021, 5023, 5039, 5051, 5059, 5077, 5081, 5087, 5099, 5101, 5107, 5113, 5119, 5147, 5153, 5167, 5171, 5179, 5189, 5197, 5209, 5227, 5231, 5233, 5237, 5261, 5273, 5279, 5281, 5297, 5303, 5309, 5323, 5333, 5347, 5351, 5381, 5387, 5393, 5399, 5407, 5413, 5417, 5419, 5431, 5437, 5441, 5443, 5449, 5471, 5477, 5479, 5483, 5501, 5503, 5507, 5519, 5521, 5527, 5531, 5557, 5563, 5569, 5573, 5581, 5591, 5623, 5639, 5641, 5647, 5651, 5653, 5657, 5659, 5669, 5683, 5689, 5693, 5701, 5711, 5717, 5737, 5741, 5743, 5749, 5779, 5783, 5791, 5801, 5807, 5813, 5821, 5827, 5839, 5843, 5849, 5851, 5857, 5861, 5867, 5869, 5879, 5881, 5897, 5903, 5923, 5927, 5939, 5953, 5981, 5987, 6007, 6011, 6029, 6037, 6043, 6047, 6053, 6067, 6073, 6079, 6089, 6091, 6101, 6113, 6121, 6131, 6133, 6143, 6151, 6163, 6173, 6197, 6199, 6203, 6211, 6217, 6221, 6229, 6247, 6257, 6263, 6269, 6271, 6277, 6287, 6299, 6301, 6311, 6317, 6323, 6329, 6337, 6343, 6353, 6359, 6361, 6367, 6373, 6379, 6389, 6397, 6421, 6427, 6449, 6451, 6469, 6473, 6481, 6491, 6521, 6529, 6547, 6551, 6553, 6563, 6569, 6571, 6577, 6581, 6599, 6607, 6619, 6637, 6653, 6659, 6661, 6673, 6679, 6689, 6691, 6701, 6703, 6709, 6719, 6733, 6737, 6761, 6763, 6779, 6781, 6791, 6793, 6803, 6823, 6827, 6829, 6833, 6841, 6857, 6863, 6869, 6871, 6883, 6899, 6907, 6911, 6917, 6947, 6949, 6959, 6961, 6967, 6971, 6977, 6983, 6991, 6997, 7001, 7013, 7019, 7027, 7039, 7043, 7057, 7069, 7079, 7103, 7109, 7121, 7127, 7129, 7151, 7159, 7177, 7187, 7193, 7207, 7211, 7213, 7219, 7229, 7237, 7243, 7247, 7253, 7283, 7297, 7307, 7309, 7321, 7331, 7333, 7349, 7351, 7369, 7393, 7411, 7417, 7433, 7451, 7457, 7459, 7477, 7481, 7487, 7489, 7499, 7507, 7517, 7523, 7529, 7537, 7541, 7547, 7549, 7559, 7561, 7573, 7577, 7583, 7589, 7591, 7603, 7607, 7621, 7639, 7643, 7649, 7669, 7673, 7681, 7687, 7691, 7699, 7703, 7717, 7723, 7727, 7741, 7753, 7757, 7759, 7789, 7793, 7817, 7823, 7829, 7841, 7853, 7867, 7873, 7877, 7879, 7883, 7901, 7907]\r\nt=int(input())\r\n\r\nfor i in range(t):\r\n s=0\r\n n=int(input())\r\n c=1\r\n x=0\r\n while(c<=n):\r\n if x+1 in l:\r\n s+=l[x]\r\n c+=1\r\n x+=1\r\n print(s%1000000007)\t", "MOD = 1000000007\r\n\r\nt = int(input())\r\nwhile t:\r\n n = int(input())\r\n P=p=1;l=[]\r\n s=0\r\n while n>0:\r\n l+=P%p*[p]\r\n if len(l)in P%p*l:s = (s%MOD + p%MOD)%MOD;n-=1;\r\n P*=p*p;p+=1\r\n print(s)\r\n t-=1", "import math\r\ndef prime(aa):\r\n\tf=0\r\n\tto=int(math.sqrt(aa))\r\n\tfor y in range(2,aa):\r\n\t\tif aa%y==0:\r\n\t\t\t\treturn 0\r\n\treturn 1\r\n\r\nte=int(input())\r\nfor _ in range(te):\r\n\ta=int(input())\r\n\tar=[]\r\n\tar.append(2)\r\n\tf=0\r\n\tc=0\r\n\tpc=3\r\n\tadd=0\r\n\tfor x in ar:\r\n\t\ttry:\r\n\t\t\tadd=add+ar[x-1]\r\n\t\texcept:\r\n\t\t\twhile True:\r\n\t\t\t\tif prime(pc)==1:\r\n\t\t\t\t\tar.append(pc)\r\n\t\t\t\t\tif x<=len(ar):\r\n\t\t\t\t\t\tbreak\r\n\t\t\t\tpc+=1\r\n\t\t\tpc+=1\r\n\t\tadd=add+ar[x-1]\r\n\t\tc+=1\r\n\t\tif c==a:\r\n\t\t\tbreak\r\n\tprint(add)\r\n", "def SieveOfEratosthenes(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 * 2, n+1, p):\r\n prime[i] = False\r\n p += 1\r\n arr=[] \r\n for p in range(2, n): \r\n if prime[p]: \r\n arr.append(p)\r\n if prime[n]:\r\n arr.append(n)\r\n return arr \r\nt=int(input())\r\nfor _ in range(t):\r\n n =int(input())\r\n k=SieveOfEratosthenes(109)\r\n count=0\r\n s=0\r\n for i in range(2,30):\r\n if count<n:\r\n if i in k:\r\n s+=k[i-1]\r\n count+=1\r\n else:\r\n pass\r\n else:\r\n break\r\n print(s)\r\n \r\n", "import math\r\ndef isPrime(nm):\r\n for i in range(2,int(math.sqrt(nm)+1)):\r\n if nm%i==0:\r\n return False\r\n return True\r\nU=list()\r\nnum=2\r\nfor i in range(10000):\r\n while(not isPrime(num)):\r\n num+=1\r\n U.append(num)\r\n num+=1\r\n#print(U)\r\nS=list()\r\nfor i in range(1,len(U)):\r\n if isPrime(i+1):\r\n S.append(U[i])\r\n#print(len(S))\r\nt=int(input())\r\nfor i in range(t):\r\n sum=0\r\n n=int(input())\r\n for j in range(n):\r\n sum+=S[j]\r\n #sum=sum%1000000007\r\n print(sum)", "primes = []\r\n\r\ndef rwh_primes1(n):\r\n \r\n \"\"\" Returns a list of primes < n \"\"\"\r\n sieve = [True] * (n//2)\r\n for i in range(3,int(n**0.5)+1,2):\r\n if sieve[i//2]:\r\n sieve[i*i//2::i] = [False] * ((n-i*i-1)//(2*i)+1)\r\n return [2] + [2*i+1 for i in range(1,n//2) if sieve[i]]\r\n\r\nprimes = rwh_primes1(1000000)\r\n#print(primes)\r\nplookup = set(primes) \r\nS = []\r\n#print(len(primes))\r\nprime = 10**9+7\r\nfor i in range(2,10000):\r\n if i in plookup:\r\n S.append(primes[i-1])\r\n#print(len(S))\r\ndef __starting_point():\r\n T = int(input())\r\n while T>0:\r\n T-=1\r\n N = int(input())\r\n s = 0\r\n for i in range(N):\r\n s+=S[i]\r\n print(s%prime)\n__starting_point()", "n=100000\r\nprm = [True for i in range(n+1)] \r\np = 2\r\nwhile (p * p <= n):\r\n if (prm[p] == True): \r\n for i in range(p * 2, n+1, p): \r\n prm[i] = False\r\n p += 1\r\nc=[] \r\nfor p in range(2, n): \r\n if prm[p]: \r\n c.append(p)\r\nfor _ in range(int(input())):\r\n k=int(input())\r\n s=0\r\n for i in range(k):\r\n #print(k,i,c[i],c[c[i]-1])\r\n s=(s+c[c[i]-1])%((10**9)+7)\r\n print(s)", "import math\r\ndef isPrime(nm):\r\n for i in range(2,int(math.sqrt(nm)+1)):\r\n if nm%i==0:\r\n return False\r\n return True\r\nU=list()\r\nnum=2\r\nfor i in range(1000+1):\r\n while(not isPrime(num)):\r\n num+=1\r\n U.append(num)\r\n num+=1\r\n#print(U)\r\nS=list()\r\nfor i in range(1,len(U)):\r\n if isPrime(i+1):\r\n S.append(U[i])\r\n#print(S)\r\nt=int(input())\r\nfor i in range(t):\r\n sum=0\r\n n=int(input())\r\n for j in range(n):\r\n sum+=S[j]\r\n print(sum)", "n=10002\r\nprm = [True for i in range(n+1)] \r\np = 2\r\nwhile (p * p <= n):\r\n if (prm[p] == True): \r\n for i in range(p * 2, n+1, p): \r\n prm[i] = False\r\n p += 1\r\nc=[] \r\nfor p in range(2, n): \r\n if prm[p]: \r\n c.append(p)\r\nfor _ in range(int(input())):\r\n k=int(input())\r\n s=0\r\n for i in range(k):\r\n #print(k,i,c[i],c[c[i]-1])\r\n s+=c[c[i]-1]\r\n print(s)", "def s(n):\r\n res = []\r\n prime = [True for i in range(n+1)] \r\n p = 2\r\n for i in range(2,int(n ** 0.5)+ 1):\r\n if prime[i]:\r\n j = 2\r\n while i * j <= n:\r\n prime[i * j] = False\r\n j += 1\r\n for p in range(2, n+1): \r\n if prime[p]: \r\n res.append(p)\r\n return res\r\no = s(100000)\r\nfor _ in range(int(input())):\r\n n = int(input())\r\n sum = 0\r\n for i in range(n):\r\n temp = o[i]\r\n sum += o[temp-1]\r\n print(sum)", "s=[3, 8, 19, 36, 67, 108, 167, 234, 317, 426, 553, 710, 889, 1080, 1291, 1532,\r\n1809, 2092, 2423, 2776, 3143, 3544, 3975, 4436, 4945, 5492, 6055, 6642, 7241, \r\n7858, 8567, 9306, 10079, 10876, 11735, 12612, 13531, 14498, 15489, 16520, 17583,\r\n18670, 19823, 20994, 22195, 23412, 24709, 26118, 27551, 28998, 30469, 31968, \r\n33491, 35088, 36709, 38378, 40101, 41842, 43629, 45452, 47299, 49212, 51239, \r\n53302, 55383, 57482, 59703, 61972, 64313, 66664, 69045, 71462, 73939, 76488, \r\n79097, 81744, 84427, 87146, 89895, 92698, 95595, 98504, 101505, 104524, 107591,\r\n110700, 113869, 117098, 120357, 123656, 126975, 130382, 133851, 137368, 140927,\r\n144520, 148157, 151890, 155651, 159562, 163505, 167532, 171623, 175756, 179909, \r\n184126, 188399, 192738, 197135, 201556, 206019, 210536, 215085, 219652, 224315,\r\n229074, 233861, 238662, 243539, 248472, 253415, 258436, 263495, 268602, 273791,\r\n279072, 284453, 289894, 295397, 300954, 306577, 312228, 317929, 323678, 329479,\r\n335330, 341199, 347236, 353349, 359566, 365795, 372106, 378429, 384782, 391143,\r\n397612, 404211, 410864, 417525, 424216, 431039, 437880, 444743, 451642, 458699,\r\n465808, 473001, 480284, 487635, 495052, 502533, 510056, 517663, 525312, 533011,\r\n540764, 548605, 556488, 564499, 572558, 580659, 588776, 596997, 605230, 613517,\r\n621894, 630283, 638796, 647323, 655904, 664623, 673370, 682131, 690938, 699787,\r\n708710, 717709, 726750, 735853, 745146, 754465, 763868, 773329, 782868, 792487,\r\n802148, 811887, 821720, 831579, 841502, 851475, 861484, 871563, 881732, 891999,\r\n902432, 912889, 923376, 933935, 944524, 955155, 965818, 976505, 987228, 998081,\r\n1008942, 1019851, 1031108, 1042419, 1053788, 1065235, 1076868, 1088611, 1100478,\r\n1112387, 1124314, 1136267, 1148274, 1160371, 1172484, 1184627, 1196830, 1209131,\r\n1221540, 1233961, 1246418, 1258897, 1271400, 1283947, 1296594, 1309357, 1322198,\r\n1335157, 1348160, 1361197, 1374300, 1387471, 1400688, 1413985, 1427316, 1440785,\r\n1454298, 1467889, 1481502, 1495151, 1508844, 1522553, 1536310, 1550169, 1564220,\r\n1578327, 1592486, 1606663, 1621100, 1635579, 1650082, 1664673, 1679386, 1694109,\r\n1708892, 1723759, 1738682, 1753651, 1768712, 1783939, 1799210, 1814509, 1829822,\r\n1845235, 1860746, 1876387, 1892070, 1907893, 1923866, 1939927, 1956000, 1972091,\r\n1988218, 2004359, 2020612, 2037023, 2053474, 2069993, 2086686, 2103389, 2120290,\r\n2137211, 2154328, 2171517, 2188808, 2206141, 2223518, 2240905, 2258322, 2275805,\r\n2293344, 2310971, 2328630, 2346391, 2364302, 2382289, 2400338, 2418487, 2436668,\r\n2454885, 2473114, 2491425, 2509858, 2528301, 2546918, 2565579, 2584298, 2603055,\r\n2621842, 2640759, 2659772, 2678985, 2698418, 2717881, 2737382, 2756959, 2776718,\r\n2796495, 2816314, 2836227, 2856274, 2876337, 2896444, 2916605, 2936836, 2957133,\r\n2977474, 2997915, 3018392, 3039111, 3059870, 3080643, 3101516, 3122415, 3143374,\r\n3164463, 3185612, 3206791, 3227982, 3249251, 3270568, 3291947, 3313440, 3334969,\r\n3356556, 3378283, 3400040, 3421857, 3443794, 3465821, 3487888, 3509981, 3532348,\r\n3554897, 3577548, 3600269, 3623020, 3645831, 3668684, 3691591, 3714678, 3737887,\r\n3761138, 3784569, 3808108, 3831671, 3855340, 3879141, 3903028, 3926927, 3950856,\r\n3974875, 3998946, 4023053, 4047186, 4071337, 4095534, 4119785, 4144164, 4168583,\r\n4193022, 4217531, 4242162, 4266833, 4291614, 4316473, 4341390, 4366447, 4391610,\r\n4416911, 4442218, 4467575, 4492984, 4518407, 4544008, 4569741, 4595504, \r\n4621345, 4647264, 4673233, 4699236, 4725425, 4751688, 4778059, 4804482,\r\n4830971, 4857562, 4884255, 4911038, 4937959, 4964912, 4991929, 5019002,\r\n5046093, 5073530, 5100987, 5128568, 5156257, 5183990, 5211799, 5239646,\r\n5267589, 5295646, 5323755, 5352034, 5380341, 5408734, 5437307, 5465950,\r\n5494607, 5523414, 5552515, 5581652, 5610805, 5640074, 5669407, 5698790,\r\n5728273, 5757842, 5787483, 5817166, 5846969, 5877040, 5907131, 5937244,\r\n5967377, 5997630, 6028187, 6058764, 6089425, 6120132, 6150913, 6181742,\r\n6212611, 6243492, 6274525, 6305594, 6336775, 6367964, 6399231, 6430508,\r\n6461997, 6493510, 6525177, 6556906, 6588909, 6621052, 6653285, 6685546,\r\n6717845, 6750168, 6782509, 6815042, 6847645, 6880364, 6913161, 6946072,\r\n6979005, 7011974, 7044987, 7078016, 7111099, 7144290, 7177493, 7210840,\r\n7244297, 7277766, 7311335, 7344982, 7378731, 7412500, 7446327, 7480238,\r\n7514205, 7548262, 7582521, 7616872, 7651239, 7685660, 7720203, 7754810, \r\n7789461, 7824190, 7859033, 7893952, 7928975, 7964056, 7999367, 8034730,\r\n8070123, 8105630, 8141247, 8176978, 8212779, 8248756, 8284749, 8320832, \r\n8357083, 8393376, 8429683, 8466134, 8502697, 8539296, 8575979, 8612826, \r\n8649713, 8686642, 8723585, 8760582, 8797631, 8834692, 8871909, 8909182, \r\n8946671, 8984328, 9022159, 9060012, 9097901, 9135868, 9173907, 9211960, \r\n9250113, 9288464, 9326841, 9365300, 9403969, 9442680, 9481513, 9520364,\r\n9559281, 9598324, 9637523, 9676740, 9715979, 9755296, 9794747, 9834256,\r\n9873777, 9913510, 9953489, 9993582, 10033733, 10073896, 10114173, 10154462,\r\n10194921, 10235404, 10275981, 10316618, 10357311, 10398112, 10438931, 10479828,\r\n10520789, 10561840, 10603191, 10644658, 10686149, 10727746, 10769393, 10811112, \r\n10852955, 10894938, 10936981, 10979162, 11021455, 11063762, 11106223, 11148722,\r\n11191291, 11233934, 11276631, 11319484, 11362347, 11405326, 11448477, 11491700,\r\n11534983, 11578296, 11621687, 11665320, 11708971, 11752758, 11796647, 11840676,\r\n11884787, 11928958, 11973179, 12017632, 12062253, 12106886, 12151543, 12196272, \r\n12241025, 12285834, 12330713, 12375684, 12420745, 12465936, 12511265, 12556806,\r\n12602363, 12647994, 12693667, 12739530, 12785501, 12831738, 12878017, 12924324,\r\n12970673, 13017114, 13063565, 13110138, 13156757, 13203508, 13250631, 13297868,\r\n13345165, 13392582, 13440145, 13487768, 13535481, 13583318, 13631175, 13679086,\r\n13727049, 13775122, 13823253, 13871512, 13919793, 13968130, 14016611, 14065144,\r\n14113737, 14162384, 14211115, 14259866, 14308687, 14357534, 14406565, 14455704,\r\n14504911, 14554322, 14603773, 14653296, 14702935, 14752602, 14802341, 14852130,\r\n14901973, 14952096, 15002273, 15052614, 15102997, 15153494, 15204085, 15254792,\r\n15305649, 15356708, 15407839, 15458976, 15510169, 15561596, 15613113, 15664694,\r\n15716293, 15768062, 15819891, 15871784, 15923835, 15975998, 16028299, 16080662,\r\n16133373, 16186142, 16239001, 16291904, 16344885, 16397954, 16451047, 16504160,\r\n16557393, 16610692, 16664045, 16717422, 16770859, 16824540, 16878299, 16932076,\r\n16985895, 17039896, 17093909, 17147992, 17202243, 17256520, 17310851, 17365222,\r\n17419823, 17474490, 17529217, 17583996, 17638877, 17693878, 17749229, 17804818,\r\n17860427, 17916088, 17971769, 18027466, 18083199, 18138986, 18194829, 18250826,\r\n18306907, 18363008, 18419205, 18475516, 18531909, 18588478, 18645089, 18701722,\r\n18758423, 18815406, 18872443, 18929550, 18986743, 19044002, 19101331, 19158728,\r\n19216221, 19273870, 19331559, 19389290, 19447041, 19504844, 19562691, 19620608,\r\n19678551, 19736608, 19794675, 19852892, 19911201, 19969712, 20028279, 20086978,\r\n20145885, 20205034, 20264243, 20323660, 20383107, 20442758, 20502481, 20562260,\r\n20622093, 20682044, 20742145, 20802294, 20862517, 20922860, 20983233, 21043742,\r\n21104389, 21165116, 21225937, 21286806, 21347749, 21408800, 21470031, 21531388,\r\n21592997, 21654624, 21716275, 21777998, 21839817, 21901688, 21963667, 22025808,\r\n22088081, 22150408, 22212831, 22275298, 22337805, 22400432, 22463193, 22525984,\r\n22588905, 22651886, 22714945, 22778058, 22841299, 22904612, 22968003, 23031446,\r\n23094913, 23158440, 23222029, 23285658, 23349367, 23413160, 23477241, 23541398,\r\n23605849, 23670332, 23735011, 23799758, 23864611, 23929562, 23994831, 24060202,\r\n24125759, 24191346, 24256955, 24322656, 24388387, 24454164, 24520003, 24585884,\r\n24651973, 24718152, 24784525, 24851094, 24917843, 24984664, 25051515, 25118474,\r\n25185517, 25252658, 25319815, 25387062, 25454333, 25521682, 25589129, 25656706,\r\n25724313, 25792196, 25860097, 25928168, 25996267, 26064486, 26132725, 26201162,\r\n26269801, 26338488, 26407199, 26475942, 26544763, 26613782, 26682891, 26752054,\r\n26821247, 26890584, 26960075, 27029728, 27099425, 27169192, 27239309, 27309432,\r\n27379639, 27449868, 27520165, 27590492, 27660915, 27731396, 27801967, 27872588,\r\n27943251, 28014094, 28084985, 28155942, 28227023, 28298166, 28369453, 28440840,\r\n28512311, 28584072, 28655909, 28727850, 28799843, 28871862, 28944113, 29016450,\r\n29089009, 29161682, 29234409, 29307310, 29380241, 29453190, 29526199, 29599320,\r\n29672579, 29745910, 29819279, 29892732, 29966489, 30040432, 30114503, 30188596,\r\n30262797, 30337108, 30411431, 30485940, 30560467, 30635196, 30710155, 30785366,\r\n30860635, 30936066, 31011695, 31087384, 31163091, 31239028, 31315011, 31391042,\r\n31467121, 31543284, 31619545, 31695948, 31772429, 31848966, 31925597, 32002270,\r\n32079027, 32155804, 32232687, 32309600, 32386647, 32463748, 32540939, 32618188,\r\n32695451, 32772828, 32850259, 32927816, 33005535, 33083282, 33161095, 33239174,\r\n33317313, 33395516, 33473799, 33552116, 33630583, 33709092, 33787741, 33866462,\r\n33945249, 34024168, 34103279, 34182430, 34261589, 34341082, 34420641, 34500458,\r\n34580319, 34660226, 34740297, 34820504, 34900845, 34981274, 35061747, 35142238,\r\n35222795, 35303532, 35384315, 35465232]\r\nfor j in range(int(input())):\r\n n=int(input())\r\n print(s[n-1])\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\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\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\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\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\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\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\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\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\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\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\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\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\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\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\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\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\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\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\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\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\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\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\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\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\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\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\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\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\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\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\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\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", "primes = []\r\nfor possiblePrime in range(2, 10000):\r\n isPrime = True\r\n for num in range(2, int(possiblePrime ** 0.5) + 1):\r\n if possiblePrime % num == 0:\r\n isPrime = False\r\n break\r\n if isPrime:\r\n primes.append(possiblePrime)\r\nplookup = set(primes) \r\nS = []\r\nprime = 10**9+7\r\nfor i in range(2,1000):\r\n if i in plookup:\r\n S.append(primes[i-1])\r\ndef __starting_point():\r\n T = int(input())\r\n while T>0:\r\n T-=1\r\n N = int(input())\r\n s = 0\r\n for i in range(N):\r\n s+=S[i]\r\n print(s%prime)\n__starting_point()", "prime=[False]*100000\r\nnums=[1]\r\nfor i in range(2,100000):\r\n if(not prime[i]):\r\n nums.append(i)\r\n for j in range(i,100000,i):prime[j]=True\r\n#print(nums)\r\nt=int(input())\r\nfor _ in range(t):\r\n n=int(input())\r\n \r\n ans=0\r\n p=10**9+7\r\n for i in range(1,n+1):\r\n ans+=nums[nums[i]]\r\n if(ans>=p):ans%=p\r\n print(ans)\r\n", "prime=[False]*100000\r\nnums=[1]\r\nfor i in range(2,100000):\r\n if(not prime[i]):\r\n nums.append(i)\r\n for j in range(i,8000,i):prime[j]=True\r\n#print(nums)\r\nt=int(input())\r\nfor _ in range(t):\r\n n=int(input())\r\n \r\n ans=0\r\n p=10**9+7\r\n for i in range(1,n+1):\r\n ans+=nums[nums[i]]\r\n if(ans>p):ans%=p\r\n print(ans)\r\n", "prime=[False]*8000\r\nnums=[1]\r\nfor i in range(2,8000):\r\n if(not prime[i]):\r\n nums.append(i)\r\n for j in range(i,8000,i):prime[j]=True\r\n#print(nums)\r\nt=int(input())\r\nfor _ in range(t):\r\n n=int(input())\r\n \r\n ans=0\r\n p=10**9+7\r\n for i in range(1,n+1):\r\n ans+=nums[nums[i]]\r\n if(ans>p):ans%=p\r\n print(ans)\r\n", "def prime(n):\r\n\tnroot = int(n**0.5)+1\r\n\t\r\n\r\n\tctr =0\r\n\tseive= [2,3,5,7,11,13]\r\n\tif n <=seive[-1]:\r\n\t\treturn seive\r\n\telse:\r\n\r\n\t\tn_start = seive[-1]+1\r\n\t\t\r\n\t\tfor i in range(n_start,n):\r\n\t\t\tiroot = int(i**0.5)+1\r\n\t\t\tfor j in seive:\r\n\t\t\t\tif i%j==0:\r\n\t\t\t\t\r\n\t\t\t\t\r\n\t\t\t\t\tctr=0\r\n\t\t\t\t\tbreak\r\n\t\t\t\telse:\r\n\t\t\t\t\tif j>(iroot):\r\n\t\t\t\t\t\t\r\n\t\t\t\t\t\t\r\n\r\n\t\t\t\t\t\tctr=1\r\n\t\t\t\t\t\tbreak\r\n\t\t\tif ctr==1:\r\n\t\t\t\r\n\t\t\t\tseive.append(i)\r\n\t\treturn seive\r\n\r\n\r\n\r\nseive = prime(81100)\r\n\r\nt = int(input())\r\nfor l in range(t):\r\n\tn = int(input())\r\n\ts = []\r\n\r\n\t# print(prime(1000))\r\n\tsump=0\r\n\tfor i in range(n):\r\n\t\tj = seive[i]\r\n\t\t\r\n\t\tsump = (sump + seive[j-1]%1000000007)%100000000\r\n\r\n\t\r\n\t\r\n\t\t\r\n\tprint(sump)", "def isPrime(n):\r\n\tif n == 1 or n == 0:\r\n\t\treturn False\r\n\telif n == 2:\r\n\t\treturn True\r\n\telse:\r\n\t\tfor i in range(2,int(n**(0.5))+1):\r\n\t\t\tif n%i == 0:\r\n\t\t\t\treturn False\r\n\t\treturn True \r\n\r\n\r\ndef getNextPrime(n):\r\n\tn = n+1\r\n\twhile(not isPrime(n)):\r\n\t\tn += 1\r\n\treturn n\r\n\r\nt = int(input())\r\n\r\n\r\nfor _ in range(t):\r\n\tn = int(input())\r\n\tsum_ = 0\r\n\tcurrentPrime = 3\r\n\tN = 2\r\n\tcountN = 1\r\n\ttemp = 0\r\n\tdiff = 0\r\n\twhile countN <= n:\r\n\t\tsum_ += currentPrime\r\n\t\tcountN += 1\r\n\t\ttemp = getNextPrime(N)\r\n\t\tdiff = temp - N\r\n\t\tfor i in range(diff):\r\n\t\t\tcurrentPrime = getNextPrime(currentPrime)\r\n\t\tN = temp\r\n\tprint(sum_%(1000000000+7))\r\n", "def primes_sieve(limit):\r\n limitn = limit+1\r\n not_prime = [False] * limitn\r\n primes = []\r\n\r\n for i in range(2, limitn):\r\n if not_prime[i]:\r\n continue\r\n for f in range(i*2, limitn, i):\r\n not_prime[f] = True\r\n\r\n primes.append(i)\r\n\r\n return primes\r\n\r\n\r\nl = 1000000007\r\np = primes_sieve(81043)\r\ns = []\r\ni = 0\r\nwhile p[i] < len(p)-1 :\r\n s.append(p[p[i]-1])\r\n i += 1\r\n#print(s)\r\nb = [s[0]]\r\nfor i in range(1,len(s)):\r\n b.append(b[len(b)-1]+s[i])\r\n#print(b)\r\n#print(len(b))\r\nfor _ in range(int(input())):\r\n n = int(input())\r\n print(b[n-1])\r\n\r\n", "def prime(n):\r\n\tnroot = int(n**0.5)+1\r\n\t\r\n\r\n\tctr =0\r\n\tseive= [2,3,5,7,11,13]\r\n\tif n <=seive[-1]:\r\n\t\treturn seive\r\n\telse:\r\n\r\n\t\tn_start = seive[-1]+1\r\n\t\t\r\n\t\tfor i in range(n_start,n):\r\n\t\t\tiroot = int(i**0.5)+1\r\n\t\t\tfor j in seive:\r\n\t\t\t\tif i%j==0:\r\n\t\t\t\t\r\n\t\t\t\t\r\n\t\t\t\t\tctr=0\r\n\t\t\t\t\tbreak\r\n\t\t\t\telse:\r\n\t\t\t\t\tif j>(iroot):\r\n\t\t\t\t\t\t\r\n\t\t\t\t\t\t\r\n\r\n\t\t\t\t\t\tctr=1\r\n\t\t\t\t\t\tbreak\r\n\t\t\tif ctr==1:\r\n\t\t\t\r\n\t\t\t\tseive.append(i)\r\n\t\treturn seive\r\n\r\n\r\n\r\nseive = prime(1000000)\r\nt = int(input())\r\nfor l in range(t):\r\n\tn = int(input())\r\n\ts = []\r\n\r\n\t# print(prime(1000))\r\n\r\n\tfor i in range(n):\r\n\t\tj = seive[i]\r\n\t\ts.append(seive[j-1])\r\n\r\n\tsump=0\r\n\tfor i in s:\r\n\t\tsump = (sump + i%1000000007)%100000000\r\n\tprint(sump)", "def isPrime(n):\r\n\tif n == 1 or n == 0:\r\n\t\treturn False\r\n\telif n == 2:\r\n\t\treturn True\r\n\telse:\r\n\t\tfor i in range(2,int(n**(0.5))+1):\r\n\t\t\tif n%i == 0:\r\n\t\t\t\treturn False\r\n\t\treturn True \r\n\r\n\r\ndef getNextPrime(n):\r\n\tn = n+1\r\n\twhile(not isPrime(n)):\r\n\t\tn += 1\r\n\treturn n\r\n\r\nt = int(input())\r\n\r\n\r\nfor _ in range(t):\r\n\tn = int(input())\r\n\tsum_ = 0\r\n\tcurrentPrime = 2\r\n\tN = 1\r\n\tcountN = 1\r\n\twhile countN <= n:\r\n\t\tif isPrime(N):\r\n\t\t\tsum_ += currentPrime\r\n\t\t\tcountN += 1\r\n\t\tcurrentPrime = getNextPrime(currentPrime)\r\n\t\tN += 1\r\n\r\n\tprint(sum_%(1000000000+7))\r\n", "a=[-1,2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,\r\n103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,\r\n199,211,223,227,229,233,239,241,251,257,263,269,271,277,281,283,293,307,311,\r\n313,317,331,337,347,349,353,359,367,373,379,383,389,397,401,409,419,421,431,\r\n433,439,443,449,457,461,463,467,479,487,491,499,503,509,521,523,541,547,557,\r\n563,569,571,577,587,593,599,601,607,613,617,619,631,641,643,647,653,659,661,\r\n673,677,683,691,701,709,719,727,733,739,743,751,757,761,769,773,787,797,809,\r\n811,821,823,827,829,839,853,857,859,863,877,881,883,887,907,911,919,929,937,\r\n941,947,953,967,971,977,983,991,997,1009,1013,1019,1021,1031,1033,1039,1049,\r\n1051,1061,1063,1069,1087,1091,1093,1097,1103,1109,1117,1123,1129,1151,1153,\r\n1163,1171,1181,1187,1193,1201,1213,1217,1223,1229,1231,1237,1249,1259,1277,\r\n1279,1283,1289,1291,1297,1301,1303,1307,1319,1321,1327,1361,1367,1373,1381,\r\n1399,1409,1423,1427,1429,1433,1439,1447,1451,1453,1459,1471,1481,1483,1487,\r\n1489,1493,1499,1511,1523,1531,1543,1549,1553,1559,1567,1571,1579,1583,1597,\r\n1601,1607,1609,1613,1619,1621,1627,1637,1657,1663,1667,1669,1693,1697,1699,\r\n1709,1721,1723,1733,1741,1747,1753,1759,1777,1783,1787,1789,1801,1811,1823,\r\n1831,1847,1861,1867,1871,1873,1877,1879,1889,1901,1907,1913,1931,1933,1949,\r\n1951,1973,1979,1987,1993,1997,1999,2003,2011,2017,2027,2029,2039,2053,2063,\r\n2069,2081,2083,2087,2089,2099,2111,2113,2129,2131,2137,2141,2143,2153,2161,\r\n2179,2203,2207,2213,2221,2237,2239,2243,2251,2267,2269,2273,2281,2287,2293,\r\n2297,2309,2311,2333,2339,2341,2347,2351,2357,2371,2377,2381,2383,2389,2393,\r\n2399,2411,2417,2423,2437,2441,2447,2459,2467,2473,2477,2503,2521,2531,2539,\r\n2543,2549,2551,2557,2579,2591,2593,2609,2617,2621,2633,2647,2657,2659,2663,\r\n2671,2677,2683,2687,2689,2693,2699,2707,2711,2713,2719,2729,2731,2741,2749,\r\n2753,2767,2777,2789,2791,2797,2801,2803,2819,2833,2837,2843,2851,2857,2861,\r\n2879,2887,2897,2903,2909,2917,2927,2939,2953,2957,2963,2969,2971,2999,3001,\r\n3011,3019,3023,3037,3041,3049,3061,3067,3079,3083,3089,3109,3119,3121,3137,\r\n3163,3167,3169,3181,3187,3191,3203,3209,3217,3221,3229,3251,3253,3257,3259,\r\n3271,3299,3301,3307,3313,3319,3323,3329,3331,3343,3347,3359,3361,3371,3373,\r\n3389,3391,3407,3413,3433,3449,3457,3461,3463,3467,3469,3491,3499,3511,3517,\r\n3527,3529,3533,3539,3541,3547,3557,3559,3571,3581,3583,3593,3607,3613,3617,\r\n3623,3631,3637,3643,3659,3671,3673,3677,3691,3697,3701,3709,3719,3727,3733,\r\n3739,3761,3767,3769,3779,3793,3797,3803,3821,3823,3833,3847,3851,3853,3863,\r\n3877,3881,3889,3907,3911,3917,3919,3923,3929,3931,3943,3947,3967,3989,4001,\r\n4003,4007,4013,4019,4021,4027,4049,4051,4057,4073,4079,4091,4093,4099,4111,\r\n4127,4129,4133,4139,4153,4157,4159,4177,4201,4211,4217,4219,4229,4231,4241,\r\n4243,4253,4259,4261,4271,4273,4283,4289,4297,4327,4337,4339,4349,4357,4363,\r\n4373,4391,4397,4409,4421,4423,4441,4447,4451,4457,4463,4481,4483,4493,4507,\r\n4513,4517,4519,4523,4547,4549,4561,4567,4583,4591,4597,4603,4621,4637,4639,\r\n4643,4649,4651,4657,4663,4673,4679,4691,4703,4721,4723,4729,4733,4751,4759,\r\n4783,4787,4789,4793,4799,4801,4813,4817,4831,4861,4871,4877,4889,4903,4909,\r\n4919,4931,4933,4937,4943,4951,4957,4967,4969,4973,4987,4993,4999,5003,5009,\r\n5011,5021,5023,5039,5051,5059,5077,5081,5087,5099,5101,5107,5113,5119,5147,\r\n5153,5167,5171,5179,5189,5197,5209,5227,5231,5233,5237,5261,5273,5279,5281,\r\n5297,5303,5309,5323,5333,5347,5351,5381,5387,5393,5399,5407,5413,5417,5419,\r\n5431,5437,5441,5443,5449,5471,5477,5479,5483,5501,5503,5507,5519,5521,5527,\r\n5531,5557,5563,5569,5573,5581,5591,5623,5639,5641,5647,5651,5653,5657,5659,\r\n5669,5683,5689,5693,5701,5711,5717,5737,5741,5743,5749,5779,5783,5791,5801,\r\n5807,5813,5821,5827,5839,5843,5849,5851,5857,5861,5867,5869,5879,5881,5897,\r\n5903,5923,5927,5939,5953,5981,5987,6007,6011,6029,6037,6043,6047,6053,6067,\r\n6073,6079,6089,6091,6101,6113,6121,6131,6133,6143,6151,6163,6173,6197,6199,\r\n6203,6211,6217,6221,6229,6247,6257,6263,6269,6271,6277,6287,6299,6301,6311,\r\n6317,6323,6329,6337,6343,6353,6359,6361,6367,6373,6379,6389,6397,6421,6427,\r\n6449,6451,6469,6473,6481,6491,6521,6529,6547,6551,6553,6563,6569,6571,6577,\r\n6581,6599,6607,6619,6637,6653,6659,6661,6673,6679,6689,6691,6701,6703,6709,\r\n6719,6733,6737,6761,6763,6779,6781,6791,6793,6803,6823,6827,6829,6833,6841,\r\n6857,6863,6869,6871,6883,6899,6907,6911,6917,6947,6949,6959,6961,6967,6971,\r\n6977,6983,6991,6997,7001,7013,7019,7027,7039,7043,7057,7069,7079,7103,7109,\r\n7121,7127,7129,7151,7159,7177,7187,7193,7207,7211,7213,7219,7229,7237,7243,\r\n7247,7253,7283,7297,7307,7309,7321,7331,7333,7349,7351,7369,7393,7411,7417,\r\n7433,7451,7457,7459,7477,7481,7487,7489,7499,7507,7517,7523,7529,7537,7541,\r\n7547,7549,7559,7561,7573,7577,7583,7589,7591,7603,7607,7621,7639,7643,7649,\r\n7669,7673,7681,7687,7691,7699,7703,7717,7723,7727,7741,7753,7757,7759,7789,\r\n7793,7817,7823,7829,7841,7853,7867,7873,7877,7879,7883,7901,7907,7919,7927,\r\n7933,7937,7949,7951,7963,7993,8009,8011,8017,8039,8053,8059,8069,8081,8087,\r\n8089,8093,8101,8111,8117,8123,8147,8161,8167,8171,8179,8191,8209,8219,8221,\r\n8231,8233,8237,8243,8263,8269,8273,8287,8291,8293,8297,8311,8317,8329,8353,\r\n8363,8369,8377,8387,8389,8419,8423,8429,8431,8443,8447,8461,8467,8501,8513,\r\n8521,8527,8537,8539,8543,8563,8573,8581,8597,8599,8609,8623,8627,8629,8641,\r\n8647,8663,8669,8677,8681,8689,8693,8699,8707,8713,8719,8731,8737,8741,8747,\r\n8753,8761,8779,8783,8803,8807,8819,8821,8831,8837,8839,8849,8861,8863,8867,\r\n8887,8893,8923,8929,8933,8941,8951,8963,8969,8971,8999,9001,9007,9011,9013,\r\n9029,9041,9043,9049,9059,9067,9091,9103,9109,9127,9133,9137,9151,9157,9161,\r\n9173,9181,9187,9199,9203,9209,9221,9227,9239,9241,9257,9277,9281,9283,9293,\r\n9311,9319,9323,9337,9341,9343,9349,9371,9377,9391,9397,9403,9413,9419,9421,\r\n9431,9433,9437,9439,9461,9463,9467,9473,9479,9491,9497,9511,9521,9533,9539,\r\n9547,9551,9587,9601,9613,9619,9623,9629,9631,9643,9649,9661,9677,9679,9689,\r\n9697,9719,9721,9733,9739,9743,9749,9767,9769,9781,9787,9791,9803,9811,9817,\r\n9829,9833,9839,9851,9857,9859,9871,9883,9887,9901,9907,9923,9929,9931,9941,\r\n9949,9967,9973,10007,10009,10037,10039,10061,10067,10069,10079,10091,10093,\r\n10099,10103,10111,10133,10139,10141,10151,10159,10163,10169,10177,10181,\r\n10193,10211,10223,10243,10247,10253,10259,10267,10271,10273,10289,10301,\r\n10303,10313,10321,10331,10333,10337,10343,10357,10369,10391,10399,10427,\r\n10429,10433,10453,10457,10459,10463,10477,10487,10499,10501,10513,10529,\r\n10531,10559,10567,10589,10597,10601,10607,10613,10627,10631,10639,10651,\r\n10657,10663,10667,10687,10691,10709,10711,10723,10729,10733,10739,10753,\r\n10771,10781,10789,10799,10831,10837,10847,10853,10859,10861,10867,10883,\r\n10889,10891,10903,10909,10937,10939,10949,10957,10973,10979,10987,10993,\r\n11003,11027,11047,11057,11059,11069,11071,11083,11087,11093,11113,11117,\r\n11119,11131,11149,11159,11161,11171,11173,11177,11197,11213,11239,11243,\r\n11251,11257,11261,11273,11279,11287,11299,11311,11317,11321,11329,11351,\r\n11353,11369,11383,11393,11399,11411,11423,11437,11443,11447,11467,11471,\r\n11483,11489,11491,11497,11503,11519,11527,11549,11551,11579,11587,11593,\r\n11597,11617,11621,11633,11657,11677,11681,11689,11699,11701,11717,11719,\r\n11731,11743,11777,11779,11783,11789,11801,11807,11813,11821,11827,11831,\r\n11833,11839,11863,11867,11887,11897,11903,11909,11923,11927,11933,11939,\r\n11941,11953,11959,11969,11971,11981,11987,12007,12011,12037,12041,12043,\r\n12049,12071,12073,12097,12101,12107,12109,12113,12119,12143,12149,12157,\r\n12161,12163,12197,12203,12211,12227,12239,12241,12251,12253,12263,12269,\r\n12277,12281,12289,12301,12323,12329,12343,12347,12373,12377,12379,12391,\r\n12401,12409,12413,12421,12433,12437,12451,12457,12473,12479,12487,12491,\r\n12497,12503,12511,12517,12527,12539,12541,12547,12553,12569,12577,12583,\r\n12589,12601,12611,12613,12619,12637,12641,12647,12653,12659,12671,12689,\r\n12697,12703,12713,12721,12739,12743,12757,12763,12781,12791,12799,12809,\r\n12821,12823,12829,12841,12853,12889,12893,12899,12907,12911,12917,12919,\r\n12923,12941,12953,12959,12967,12973,12979,12983,13001,13003,13007,13009,\r\n13033,13037,13043,13049,13063,13093,13099,13103,13109,13121,13127,13147,\r\n13151,13159,13163,13171,13177,13183,13187,13217,13219,13229,13241,13249,\r\n13259,13267,13291,13297,13309,13313,13327,13331,13337,13339,13367,13381,\r\n13397,13399,13411,13417,13421,13441,13451,13457,13463,13469,13477,13487,\r\n13499,13513,13523,13537,13553,13567,13577,13591,13597,13613,13619,13627,\r\n13633,13649,13669,13679,13681,13687,13691,13693,13697,13709,13711,13721,\r\n13723,13729,13751,13757,13759,13763,13781,13789,13799,13807,13829,13831,\r\n13841,13859,13873,13877,13879,13883,13901,13903,13907,13913,13921,13931,\r\n13933,13963,13967,13997,13999,14009,14011,14029,14033,14051,14057,14071,\r\n14081,14083,14087,14107,14143,14149,14153,14159,14173,14177,14197,14207,\r\n14221,14243,14249,14251,14281,14293,14303,14321,14323,14327,14341,14347,\r\n14369,14387,14389,14401,14407,14411,14419,14423,14431,14437,14447,14449,\r\n14461,14479,14489,14503,14519,14533,14537,14543,14549,14551,14557,14561,\r\n14563,14591,14593,14621,14627,14629,14633,14639,14653,14657,14669,14683,\r\n14699,14713,14717,14723,14731,14737,14741,14747,14753,14759,14767,14771,\r\n14779,14783,14797,14813,14821,14827,14831,14843,14851,14867,14869,14879,\r\n14887,14891,14897,14923,14929,14939,14947,14951,14957,14969,14983,15013,\r\n15017,15031,15053,15061,15073,15077,15083,15091,15101,15107,15121,15131,\r\n15137,15139,15149,15161,15173,15187,15193,15199,15217,15227,15233,15241,\r\n15259,15263,15269,15271,15277,15287,15289,15299,15307,15313,15319,15329,\r\n15331,15349,15359,15361,15373,15377,15383,15391,15401,15413,15427,15439,\r\n15443,15451,15461,15467,15473,15493,15497,15511,15527,15541,15551,15559,\r\n15569,15581,15583,15601,15607,15619,15629,15641,15643,15647,15649,15661,\r\n15667,15671,15679,15683,15727,15731,15733,15737,15739,15749,15761,15767,\r\n15773,15787,15791,15797,15803,15809,15817,15823,15859,15877,15881,15887,\r\n15889,15901,15907,15913,15919,15923,15937,15959,15971,15973,15991,16001,\r\n16007,16033,16057,16061,16063,16067,16069,16073,16087,16091,16097,16103,\r\n16111,16127,16139,16141,16183,16187,16189,16193,16217,16223,16229,16231,\r\n16249,16253,16267,16273,16301,16319,16333,16339,16349,16361,16363,16369,\r\n16381,16411,16417,16421,16427,16433,16447,16451,16453,16477,16481,16487,\r\n16493,16519,16529,16547,16553,16561,16567,16573,16603,16607,16619,16631,\r\n16633,16649,16651,16657,16661,16673,16691,16693,16699,16703,16729,16741,\r\n16747,16759,16763,16787,16811,16823,16829,16831,16843,16871,16879,16883,\r\n16889,16901,16903,16921,16927,16931,16937,16943,16963,16979,16981,16987,\r\n16993,17011,17021,17027,17029,17033,17041,17047,17053,17077,17093,17099,\r\n17107,17117,17123,17137,17159,17167,17183,17189,17191,17203,17207,17209,\r\n17231,17239,17257,17291,17293,17299,17317,17321,17327,17333,17341,17351,\r\n17359,17377,17383,17387,17389,17393,17401,17417,17419,17431,17443,17449,\r\n17467,17471,17477,17483,17489,17491,17497,17509,17519,17539,17551,17569,\r\n17573,17579,17581,17597,17599,17609,17623,17627,17657,17659,17669,17681,\r\n17683,17707,17713,17729,17737,17747,17749,17761,17783,17789,17791,17807,\r\n17827,17837,17839,17851,17863,17881,17891,17903,17909,17911,17921,17923,\r\n17929,17939,17957,17959,17971,17977,17981,17987,17989,18013,18041,18043,\r\n18047,18049,18059,18061,18077,18089,18097,18119,18121,18127,18131,18133,\r\n18143,18149,18169,18181,18191,18199,18211,18217,18223,18229,18233,18251,\r\n18253,18257,18269,18287,18289,18301,18307,18311,18313,18329,18341,18353,\r\n18367,18371,18379,18397,18401,18413,18427,18433,18439,18443,18451,18457,\r\n18461,18481,18493,18503,18517,18521,18523,18539,18541,18553,18583,18587,\r\n18593,18617,18637,18661,18671,18679,18691,18701,18713,18719,18731,18743,\r\n18749,18757,18773,18787,18793,18797,18803,18839,18859,18869,18899,18911,\r\n18913,18917,18919,18947,18959,18973,18979,19001,19009,19013,19031,19037,\r\n19051,19069,19073,19079,19081,19087,19121,19139,19141,19157,19163,19181,\r\n19183,19207,19211,19213,19219,19231,19237,19249,19259,19267,19273,19289,\r\n19301,19309,19319,19333,19373,19379,19381,19387,19391,19403,19417,19421,\r\n19423,19427,19429,19433,19441,19447,19457,19463,19469,19471,19477,19483,\r\n19489,19501,19507,19531,19541,19543,19553,19559,19571,19577,19583,19597,\r\n19603,19609,19661,19681,19687,19697,19699,19709,19717,19727,19739,19751,\r\n19753,19759,19763,19777,19793,19801,19813,19819,19841,19843,19853,19861,\r\n19867,19889,19891,19913,19919,19927,19937,19949,19961,19963,19973,19979,\r\n19991,19993,19997,20011,20021,20023,20029,20047,20051,20063,20071,20089,\r\n20101,20107,20113,20117,20123,20129,20143,20147,20149,20161,20173,20177,\r\n20183,20201,20219,20231,20233,20249,20261,20269,20287,20297,20323,20327,\r\n20333,20341,20347,20353,20357,20359,20369,20389,20393,20399,20407,20411,\r\n20431,20441,20443,20477,20479,20483,20507,20509,20521,20533,20543,20549,\r\n20551,20563,20593,20599,20611,20627,20639,20641,20663,20681,20693,20707,\r\n20717,20719,20731,20743,20747,20749,20753,20759,20771,20773,20789,20807,\r\n20809,20849,20857,20873,20879,20887,20897,20899,20903,20921,20929,20939,\r\n20947,20959,20963,20981,20983,21001,21011,21013,21017,21019,21023,21031,\r\n21059,21061,21067,21089,21101,21107,21121,21139,21143,21149,21157,21163,\r\n21169,21179,21187,21191,21193,21211,21221,21227,21247,21269,21277,21283,\r\n21313,21317,21319,21323,21341,21347,21377,21379,21383,21391,21397,21401,\r\n21407,21419,21433,21467,21481,21487,21491,21493,21499,21503,21517,21521,\r\n21523,21529,21557,21559,21563,21569,21577,21587,21589,21599,21601,21611,\r\n21613,21617,21647,21649,21661,21673,21683,21701,21713,21727,21737,21739,\r\n21751,21757,21767,21773,21787,21799,21803,21817,21821,21839,21841,21851,\r\n21859,21863,21871,21881,21893,21911,21929,21937,21943,21961,21977,21991,\r\n21997,22003,22013,22027,22031,22037,22039,22051,22063,22067,22073,22079,\r\n22091,22093,22109,22111,22123,22129,22133,22147,22153,22157,22159,22171,\r\n22189,22193,22229,22247,22259,22271,22273,22277,22279,22283,22291,22303,\r\n22307,22343,22349,22367,22369,22381,22391,22397,22409,22433,22441,22447,\r\n22453,22469,22481,22483,22501,22511,22531,22541,22543,22549,22567,22571,\r\n22573,22613,22619,22621,22637,22639,22643,22651,22669,22679,22691,22697,\r\n22699,22709,22717,22721,22727,22739,22741,22751,22769,22777,22783,22787,\r\n22807,22811,22817,22853,22859,22861,22871,22877,22901,22907,22921,22937,\r\n22943,22961,22963,22973,22993,23003,23011,23017,23021,23027,23029,23039,\r\n23041,23053,23057,23059,23063,23071,23081,23087,23099,23117,23131,23143,\r\n23159,23167,23173,23189,23197,23201,23203,23209,23227,23251,23269,23279,\r\n23291,23293,23297,23311,23321,23327,23333,23339,23357,23369,23371,23399,\r\n23417,23431,23447,23459,23473,23497,23509,23531,23537,23539,23549,23557,\r\n23561,23563,23567,23581,23593,23599,23603,23609,23623,23627,23629,23633,\r\n23663,23669,23671,23677,23687,23689,23719,23741,23743,23747,23753,23761,\r\n23767,23773,23789,23801,23813,23819,23827,23831,23833,23857,23869,23873,\r\n23879,23887,23893,23899,23909,23911,23917,23929,23957,23971,23977,23981,\r\n23993,24001,24007,24019,24023,24029,24043,24049,24061,24071,24077,24083,\r\n24091,24097,24103,24107,24109,24113,24121,24133,24137,24151,24169,24179,\r\n24181,24197,24203,24223,24229,24239,24247,24251,24281,24317,24329,24337,\r\n24359,24371,24373,24379,24391,24407,24413,24419,24421,24439,24443,24469,\r\n24473,24481,24499,24509,24517,24527,24533,24547,24551,24571,24593,24611,\r\n24623,24631,24659,24671,24677,24683,24691,24697,24709,24733,24749,24763,\r\n24767,24781,24793,24799,24809,24821,24841,24847,24851,24859,24877,24889,\r\n24907,24917,24919,24923,24943,24953,24967,24971,24977,24979,24989,25013,\r\n25031,25033,25037,25057,25073,25087,25097,25111,25117,25121,25127,25147,\r\n25153,25163,25169,25171,25183,25189,25219,25229,25237,25243,25247,25253,\r\n25261,25301,25303,25307,25309,25321,25339,25343,25349,25357,25367,25373,\r\n25391,25409,25411,25423,25439,25447,25453,25457,25463,25469,25471,25523,\r\n25537,25541,25561,25577,25579,25583,25589,25601,25603,25609,25621,25633,\r\n25639,25643,25657,25667,25673,25679,25693,25703,25717,25733,25741,25747,\r\n25759,25763,25771,25793,25799,25801,25819,25841,25847,25849,25867,25873,\r\n25889,25903,25913,25919,25931,25933,25939,25943,25951,25969,25981,25997,\r\n25999,26003,26017,26021,26029,26041,26053,26083,26099,26107,26111,26113,\r\n26119,26141,26153,26161,26171,26177,26183,26189,26203,26209,26227,26237,\r\n26249,26251,26261,26263,26267,26293,26297,26309,26317,26321,26339,26347,\r\n26357,26371,26387,26393,26399,26407,26417,26423,26431,26437,26449,26459,\r\n26479,26489,26497,26501,26513,26539,26557,26561,26573,26591,26597,26627,\r\n26633,26641,26647,26669,26681,26683,26687,26693,26699,26701,26711,26713,\r\n26717,26723,26729,26731,26737,26759,26777,26783,26801,26813,26821,26833,\r\n26839,26849,26861,26863,26879,26881,26891,26893,26903,26921,26927,26947,\r\n26951,26953,26959,26981,26987,26993,27011,27017,27031,27043,27059,27061,\r\n27067,27073,27077,27091,27103,27107,27109,27127,27143,27179,27191,27197,\r\n27211,27239,27241,27253,27259,27271,27277,27281,27283,27299,27329,27337,\r\n27361,27367,27397,27407,27409,27427,27431,27437,27449,27457,27479,27481,\r\n27487,27509,27527,27529,27539,27541,27551,27581,27583,27611,27617,27631,\r\n27647,27653,27673,27689,27691,27697,27701,27733,27737,27739,27743,27749,\r\n27751,27763,27767,27773,27779,27791,27793,27799,27803,27809,27817,27823,\r\n27827,27847,27851,27883,27893,27901,27917,27919,27941,27943,27947,27953,\r\n27961,27967,27983,27997,28001,28019,28027,28031,28051,28057,28069,28081,\r\n28087,28097,28099,28109,28111,28123,28151,28163,28181,28183,28201,28211,\r\n28219,28229,28277,28279,28283,28289,28297,28307,28309,28319,28349,28351,\r\n28387,28393,28403,28409,28411,28429,28433,28439,28447,28463,28477,28493,\r\n28499,28513,28517,28537,28541,28547,28549,28559,28571,28573,28579,28591,\r\n28597,28603,28607,28619,28621,28627,28631,28643,28649,28657,28661,28663,\r\n28669,28687,28697,28703,28711,28723,28729,28751,28753,28759,28771,28789,\r\n28793,28807,28813,28817,28837,28843,28859,28867,28871,28879,28901,28909,\r\n28921,28927,28933,28949,28961,28979,29009,29017,29021,29023,29027,29033,\r\n29059,29063,29077,29101,29123,29129,29131,29137,29147,29153,29167,29173,\r\n29179,29191,29201,29207,29209,29221,29231,29243,29251,29269,29287,29297,\r\n29303,29311,29327,29333,29339,29347,29363,29383,29387,29389,29399,29401,\r\n29411,29423,29429,29437,29443,29453,29473,29483,29501,29527,29531,29537,\r\n29567,29569,29573,29581,29587,29599,29611,29629,29633,29641,29663,29669,\r\n29671,29683,29717,29723,29741,29753,29759,29761,29789,29803,29819,29833,\r\n29837,29851,29863,29867,29873,29879,29881,29917,29921,29927,29947,29959,\r\n29983,29989,30011,30013,30029,30047,30059,30071,30089,30091,30097,30103,\r\n30109,30113,30119,30133,30137,30139,30161,30169,30181,30187,30197,30203,\r\n30211,30223,30241,30253,30259,30269,30271,30293,30307,30313,30319,30323,\r\n30341,30347,30367,30389,30391,30403,30427,30431,30449,30467,30469,30491,\r\n30493,30497,30509,30517,30529,30539,30553,30557,30559,30577,30593,30631,\r\n30637,30643,30649,30661,30671,30677,30689,30697,30703,30707,30713,30727,\r\n30757,30763,30773,30781,30803,30809,30817,30829,30839,30841,30851,30853,\r\n30859,30869,30871,30881,30893,30911,30931,30937,30941,30949,30971,30977,\r\n30983,31013,31019,31033,31039,31051,31063,31069,31079,31081,31091,31121,\r\n31123,31139,31147,31151,31153,31159,31177,31181,31183,31189,31193,31219,\r\n31223,31231,31237,31247,31249,31253,31259,31267,31271,31277,31307,31319,\r\n31321,31327,31333,31337,31357,31379,31387,31391,31393,31397,31469,31477,\r\n31481,31489,31511,31513,31517,31531,31541,31543,31547,31567,31573,31583,\r\n31601,31607,31627,31643,31649,31657,31663,31667,31687,31699,31721,31723,\r\n31727,31729,31741,31751,31769,31771,31793,31799,31817,31847,31849,31859,\r\n31873,31883,31891,31907,31957,31963,31973,31981,31991,32003,32009,32027,\r\n32029,32051,32057,32059,32063,32069,32077,32083,32089,32099,32117,32119,\r\n32141,32143,32159,32173,32183,32189,32191,32203,32213,32233,32237,32251,\r\n32257,32261,32297,32299,32303,32309,32321,32323,32327,32341,32353,32359,\r\n32363,32369,32371,32377,32381,32401,32411,32413,32423,32429,32441,32443,\r\n32467,32479,32491,32497,32503,32507,32531,32533,32537,32561,32563,32569,\r\n32573,32579,32587,32603,32609,32611,32621,32633,32647,32653,32687,32693,\r\n32707,32713,32717,32719,32749,32771,32779,32783,32789,32797,32801,32803,\r\n32831,32833,32839,32843,32869,32887,32909,32911,32917,32933,32939,32941,\r\n32957,32969,32971,32983,32987,32993,32999,33013,33023,33029,33037,33049,\r\n33053,33071,33073,33083,33091,33107,33113,33119,33149,33151,33161,33179,\r\n33181,33191,33199,33203,33211,33223,33247,33287,33289,33301,33311,33317,\r\n33329,33331,33343,33347,33349,33353,33359,33377,33391,33403,33409,33413,\r\n33427,33457,33461,33469,33479,33487,33493,33503,33521,33529,33533,33547,\r\n33563,33569,33577,33581,33587,33589,33599,33601,33613,33617,33619,33623,\r\n33629,33637,33641,33647,33679,33703,33713,33721,33739,33749,33751,33757,\r\n33767,33769,33773,33791,33797,33809,33811,33827,33829,33851,33857,33863,\r\n33871,33889,33893,33911,33923,33931,33937,33941,33961,33967,33997,34019,\r\n34031,34033,34039,34057,34061,34123,34127,34129,34141,34147,34157,34159,\r\n34171,34183,34211,34213,34217,34231,34253,34259,34261,34267,34273,34283,\r\n34297,34301,34303,34313,34319,34327,34337,34351,34361,34367,34369,34381,\r\n34403,34421,34429,34439,34457,34469,34471,34483,34487,34499,34501,34511,\r\n34513,34519,34537,34543,34549,34583,34589,34591,34603,34607,34613,34631,\r\n34649,34651,34667,34673,34679,34687,34693,34703,34721,34729,34739,34747,\r\n34757,34759,34763,34781,34807,34819,34841,34843,34847,34849,34871,34877,\r\n34883,34897,34913,34919,34939,34949,34961,34963,34981,35023,35027,35051,\r\n35053,35059,35069,35081,35083,35089,35099,35107,35111,35117,35129,35141,\r\n35149,35153,35159,35171,35201,35221,35227,35251,35257,35267,35279,35281,\r\n35291,35311,35317,35323,35327,35339,35353,35363,35381,35393,35401,35407,\r\n35419,35423,35437,35447,35449,35461,35491,35507,35509,35521,35527,35531,\r\n35533,35537,35543,35569,35573,35591,35593,35597,35603,35617,35671,35677,\r\n35729,35731,35747,35753,35759,35771,35797,35801,35803,35809,35831,35837,\r\n35839,35851,35863,35869,35879,35897,35899,35911,35923,35933,35951,35963,\r\n35969,35977,35983,35993,35999,36007,36011,36013,36017,36037,36061,36067,\r\n36073,36083,36097,36107,36109,36131,36137,36151,36161,36187,36191,36209,\r\n36217,36229,36241,36251,36263,36269,36277,36293,36299,36307,36313,36319,\r\n36341,36343,36353,36373,36383,36389,36433,36451,36457,36467,36469,36473,\r\n36479,36493,36497,36523,36527,36529,36541,36551,36559,36563,36571,36583,\r\n36587,36599,36607,36629,36637,36643,36653,36671,36677,36683,36691,36697,\r\n36709,36713,36721,36739,36749,36761,36767,36779,36781,36787,36791,36793,\r\n36809,36821,36833,36847,36857,36871,36877,36887,36899,36901,36913,36919,\r\n36923,36929,36931,36943,36947,36973,36979,36997,37003,37013,37019,37021,\r\n37039,37049,37057,37061,37087,37097,37117,37123,37139,37159,37171,37181,\r\n37189,37199,37201,37217,37223,37243,37253,37273,37277,37307,37309,37313,\r\n37321,37337,37339,37357,37361,37363,37369,37379,37397,37409,37423,37441,\r\n37447,37463,37483,37489,37493,37501,37507,37511,37517,37529,37537,37547,\r\n37549,37561,37567,37571,37573,37579,37589,37591,37607,37619,37633,37643,\r\n37649,37657,37663,37691,37693,37699,37717,37747,37781,37783,37799,37811,\r\n37813,37831,37847,37853,37861,37871,37879,37889,37897,37907,37951,37957,\r\n37963,37967,37987,37991,37993,37997,38011,38039,38047,38053,38069,38083,\r\n38113,38119,38149,38153,38167,38177,38183,38189,38197,38201,38219,38231,\r\n38237,38239,38261,38273,38281,38287,38299,38303,38317,38321,38327,38329,\r\n38333,38351,38371,38377,38393,38431,38447,38449,38453,38459,38461,38501,\r\n38543,38557,38561,38567,38569,38593,38603,38609,38611,38629,38639,38651,\r\n38653,38669,38671,38677,38693,38699,38707,38711,38713,38723,38729,38737,\r\n38747,38749,38767,38783,38791,38803,38821,38833,38839,38851,38861,38867,\r\n38873,38891,38903,38917,38921,38923,38933,38953,38959,38971,38977,38993,\r\n39019,39023,39041,39043,39047,39079,39089,39097,39103,39107,39113,39119,\r\n39133,39139,39157,39161,39163,39181,39191,39199,39209,39217,39227,39229,\r\n39233,39239,39241,39251,39293,39301,39313,39317,39323,39341,39343,39359,\r\n39367,39371,39373,39383,39397,39409,39419,39439,39443,39451,39461,39499,\r\n39503,39509,39511,39521,39541,39551,39563,39569,39581,39607,39619,39623,\r\n39631,39659,39667,39671,39679,39703,39709,39719,39727,39733,39749,39761,\r\n39769,39779,39791,39799,39821,39827,39829,39839,39841,39847,39857,39863,\r\n39869,39877,39883,39887,39901,39929,39937,39953,39971,39979,39983,39989,\r\n40009,40013,40031,40037,40039,40063,40087,40093,40099,40111,40123,40127,\r\n40129,40151,40153,40163,40169,40177,40189,40193,40213,40231,40237,40241,\r\n40253,40277,40283,40289,40343,40351,40357,40361,40387,40423,40427,40429,\r\n40433,40459,40471,40483,40487,40493,40499,40507,40519,40529,40531,40543,\r\n40559,40577,40583,40591,40597,40609,40627,40637,40639,40693,40697,40699,\r\n40709,40739,40751,40759,40763,40771,40787,40801,40813,40819,40823,40829,\r\n40841,40847,40849,40853,40867,40879,40883,40897,40903,40927,40933,40939,\r\n40949,40961,40973,40993,41011,41017,41023,41039,41047,41051,41057,41077,\r\n41081,41113,41117,41131,41141,41143,41149,41161,41177,41179,41183,41189,\r\n41201,41203,41213,41221,41227,41231,41233,41243,41257,41263,41269,41281,\r\n41299,41333,41341,41351,41357,41381,41387,41389,41399,41411,41413,41443,\r\n41453,41467,41479,41491,41507,41513,41519,41521,41539,41543,41549,41579,\r\n41593,41597,41603,41609,41611,41617,41621,41627,41641,41647,41651,41659,\r\n41669,41681,41687,41719,41729,41737,41759,41761,41771,41777,41801,41809,\r\n41813,41843,41849,41851,41863,41879,41887,41893,41897,41903,41911,41927,\r\n41941,41947,41953,41957,41959,41969,41981,41983,41999,42013,42017,42019,\r\n42023,42043,42061,42071,42073,42083,42089,42101,42131,42139,42157,42169,\r\n42179,42181,42187,42193,42197,42209,42221,42223,42227,42239,42257,42281,\r\n42283,42293,42299,42307,42323,42331,42337,42349,42359,42373,42379,42391,\r\n42397,42403,42407,42409,42433,42437,42443,42451,42457,42461,42463,42467,\r\n42473,42487,42491,42499,42509,42533,42557,42569,42571,42577,42589,42611,\r\n42641,42643,42649,42667,42677,42683,42689,42697,42701,42703,42709,42719,\r\n42727,42737,42743,42751,42767,42773,42787,42793,42797,42821,42829,42839,\r\n42841,42853,42859,42863,42899,42901,42923,42929,42937,42943,42953,42961,\r\n42967,42979,42989,43003,43013,43019,43037,43049,43051,43063,43067,43093,\r\n43103,43117,43133,43151,43159,43177,43189,43201,43207,43223,43237,43261,\r\n43271,43283,43291,43313,43319,43321,43331,43391,43397,43399,43403,43411,\r\n43427,43441,43451,43457,43481,43487,43499,43517,43541,43543,43573,43577,\r\n43579,43591,43597,43607,43609,43613,43627,43633,43649,43651,43661,43669,\r\n43691,43711,43717,43721,43753,43759,43777,43781,43783,43787,43789,43793,\r\n43801,43853,43867,43889,43891,43913,43933,43943,43951,43961,43963,43969,\r\n43973,43987,43991,43997,44017,44021,44027,44029,44041,44053,44059,44071,\r\n44087,44089,44101,44111,44119,44123,44129,44131,44159,44171,44179,44189,\r\n44201,44203,44207,44221,44249,44257,44263,44267,44269,44273,44279,44281,\r\n44293,44351,44357,44371,44381,44383,44389,44417,44449,44453,44483,44491,\r\n44497,44501,44507,44519,44531,44533,44537,44543,44549,44563,44579,44587,\r\n44617,44621,44623,44633,44641,44647,44651,44657,44683,44687,44699,44701,\r\n44711,44729,44741,44753,44771,44773,44777,44789,44797,44809,44819,44839,\r\n44843,44851,44867,44879,44887,44893,44909,44917,44927,44939,44953,44959,\r\n44963,44971,44983,44987,45007,45013,45053,45061,45077,45083,45119,45121,\r\n45127,45131,45137,45139,45161,45179,45181,45191,45197,45233,45247,45259,\r\n45263,45281,45289,45293,45307,45317,45319,45329,45337,45341,45343,45361,\r\n45377,45389,45403,45413,45427,45433,45439,45481,45491,45497,45503,45523,\r\n45533,45541,45553,45557,45569,45587,45589,45599,45613,45631,45641,45659,\r\n45667,45673,45677,45691,45697,45707,45737,45751,45757,45763,45767,45779,\r\n45817,45821,45823,45827,45833,45841,45853,45863,45869,45887,45893,45943,\r\n45949,45953,45959,45971,45979,45989,46021,46027,46049,46051,46061,46073,\r\n46091,46093,46099,46103,46133,46141,46147,46153,46171,46181,46183,46187,\r\n46199,46219,46229,46237,46261,46271,46273,46279,46301,46307,46309,46327,\r\n46337,46349,46351,46381,46399,46411,46439,46441,46447,46451,46457,46471,\r\n46477,46489,46499,46507,46511,46523,46549,46559,46567,46573,46589,46591,\r\n46601,46619,46633,46639,46643,46649,46663,46679,46681,46687,46691,46703,\r\n46723,46727,46747,46751,46757,46769,46771,46807,46811,46817,46819,46829,\r\n46831,46853,46861,46867,46877,46889,46901,46919,46933,46957,46993,46997,\r\n47017,47041,47051,47057,47059,47087,47093,47111,47119,47123,47129,47137,\r\n47143,47147,47149,47161,47189,47207,47221,47237,47251,47269,47279,47287,\r\n47293,47297,47303,47309,47317,47339,47351,47353,47363,47381,47387,47389,\r\n47407,47417,47419,47431,47441,47459,47491,47497,47501,47507,47513,47521,\r\n47527,47533,47543,47563,47569,47581,47591,47599,47609,47623,47629,47639,\r\n47653,47657,47659,47681,47699,47701,47711,47713,47717,47737,47741,47743,\r\n47777,47779,47791,47797,47807,47809,47819,47837,47843,47857,47869,47881,\r\n47903,47911,47917,47933,47939,47947,47951,47963,47969,47977,47981,48017,\r\n48023,48029,48049,48073,48079,48091,48109,48119,48121,48131,48157,48163,\r\n48179,48187,48193,48197,48221,48239,48247,48259,48271,48281,48299,48311,\r\n48313,48337,48341,48353,48371,48383,48397,48407,48409,48413,48437,48449,\r\n48463,48473,48479,48481,48487,48491,48497,48523,48527,48533,48539,48541,\r\n48563,48571,48589,48593,48611,48619,48623,48647,48649,48661,48673,48677,\r\n48679,48731,48733,48751,48757,48761,48767,48779,48781,48787,48799,48809,\r\n48817,48821,48823,48847,48857,48859,48869,48871,48883,48889,48907,48947,\r\n48953,48973,48989,48991,49003,49009,49019,49031,49033,49037,49043,49057,\r\n49069,49081,49103,49109,49117,49121,49123,49139,49157,49169,49171,49177,\r\n49193,49199,49201,49207,49211,49223,49253,49261,49277,49279,49297,49307,\r\n49331,49333,49339,49363,49367,49369,49391,49393,49409,49411,49417,49429,\r\n49433,49451,49459,49463,49477,49481,49499,49523,49529,49531,49537,49547,\r\n49549,49559,49597,49603,49613,49627,49633,49639,49663,49667,49669,49681,\r\n49697,49711,49727,49739,49741,49747,49757,49783,49787,49789,49801,49807,\r\n49811,49823,49831,49843,49853,49871,49877,49891,49919,49921,49927,49937,\r\n49939,49943,49957,49991,49993,49999,50021,50023,50033,50047,50051,50053,\r\n50069,50077,50087,50093,50101,50111,50119,50123,50129,50131,50147,50153,\r\n50159,50177,50207,50221,50227,50231,50261,50263,50273,50287,50291,50311,\r\n50321,50329,50333,50341,50359,50363,50377,50383,50387,50411,50417,50423,\r\n50441,50459,50461,50497,50503,50513,50527,50539,50543,50549,50551,50581,\r\n50587,50591,50593,50599,50627,50647,50651,50671,50683,50707,50723,50741,\r\n50753,50767,50773,50777,50789,50821,50833,50839,50849,50857,50867,50873,\r\n50891,50893,50909,50923,50929,50951,50957,50969,50971,50989,50993,51001,\r\n51031,51043,51047,51059,51061,51071,51109,51131,51133,51137,51151,51157,\r\n51169,51193,51197,51199,51203,51217,51229,51239,51241,51257,51263,51283,\r\n51287,51307,51329,51341,51343,51347,51349,51361,51383,51407,51413,51419,\r\n51421,51427,51431,51437,51439,51449,51461,51473,51479,51481,51487,51503,\r\n51511,51517,51521,51539,51551,51563,51577,51581,51593,51599,51607,51613,\r\n51631,51637,51647,51659,51673,51679,51683,51691,51713,51719,51721,51749,\r\n51767,51769,51787,51797,51803,51817,51827,51829,51839,51853,51859,51869,\r\n51871,51893,51899,51907,51913,51929,51941,51949,51971,51973,51977,51991,\r\n52009,52021,52027,52051,52057,52067,52069,52081,52103,52121,52127,52147,\r\n52153,52163,52177,52181,52183,52189,52201,52223,52237,52249,52253,52259,\r\n52267,52289,52291,52301,52313,52321,52361,52363,52369,52379,52387,52391,\r\n52433,52453,52457,52489,52501,52511,52517,52529,52541,52543,52553,52561,\r\n52567,52571,52579,52583,52609,52627,52631,52639,52667,52673,52691,52697,\r\n52709,52711,52721,52727,52733,52747,52757,52769,52783,52807,52813,52817,\r\n52837,52859,52861,52879,52883,52889,52901,52903,52919,52937,52951,52957,\r\n52963,52967,52973,52981,52999,53003,53017,53047,53051,53069,53077,53087,\r\n53089,53093,53101,53113,53117,53129,53147,53149,53161,53171,53173,53189,\r\n53197,53201,53231,53233,53239,53267,53269,53279,53281,53299,53309,53323,\r\n53327,53353,53359,53377,53381,53401,53407,53411,53419,53437,53441,53453,\r\n53479,53503,53507,53527,53549,53551,53569,53591,53593,53597,53609,53611,\r\n53617,53623,53629,53633,53639,53653,53657,53681,53693,53699,53717,53719,\r\n53731,53759,53773,53777,53783,53791,53813,53819,53831,53849,53857,53861,\r\n53881,53887,53891,53897,53899,53917,53923,53927,53939,53951,53959,53987,\r\n53993,54001,54011,54013,54037,54049,54059,54083,54091,54101,54121,54133,\r\n54139,54151,54163,54167,54181,54193,54217,54251,54269,54277,54287,54293,\r\n54311,54319,54323,54331,54347,54361,54367,54371,54377,54401,54403,54409,\r\n54413,54419,54421,54437,54443,54449,54469,54493,54497,54499,54503,54517,\r\n54521,54539,54541,54547,54559,54563,54577,54581,54583,54601,54617,54623,\r\n54629,54631,54647,54667,54673,54679,54709,54713,54721,54727,54751,54767,\r\n54773,54779,54787,54799,54829,54833,54851,54869,54877,54881,54907,54917,\r\n54919,54941,54949,54959,54973,54979,54983,55001,55009,55021,55049,55051,\r\n55057,55061,55073,55079,55103,55109,55117,55127,55147,55163,55171,55201,\r\n55207,55213,55217,55219,55229,55243,55249,55259,55291,55313,55331,55333,\r\n55337,55339,55343,55351,55373,55381,55399,55411,55439,55441,55457,55469,\r\n55487,55501,55511,55529,55541,55547,55579,55589,55603,55609,55619,55621,\r\n55631,55633,55639,55661,55663,55667,55673,55681,55691,55697,55711,55717,\r\n55721,55733,55763,55787,55793,55799,55807,55813,55817,55819,55823,55829,\r\n55837,55843,55849,55871,55889,55897,55901,55903,55921,55927,55931,55933,\r\n55949,55967,55987,55997,56003,56009,56039,56041,56053,56081,56087,56093,\r\n56099,56101,56113,56123,56131,56149,56167,56171,56179,56197,56207,56209,\r\n56237,56239,56249,56263,56267,56269,56299,56311,56333,56359,56369,56377,\r\n56383,56393,56401,56417,56431,56437,56443,56453,56467,56473,56477,56479,\r\n56489,56501,56503,56509,56519,56527,56531,56533,56543,56569,56591,56597,\r\n56599,56611,56629,56633,56659,56663,56671,56681,56687,56701,56711,56713,\r\n56731,56737,56747,56767,56773,56779,56783,56807,56809,56813,56821,56827,\r\n56843,56857,56873,56891,56893,56897,56909,56911,56921,56923,56929,56941,\r\n56951,56957,56963,56983,56989,56993,56999,57037,57041,57047,57059,57073,\r\n57077,57089,57097,57107,57119,57131,57139,57143,57149,57163,57173,57179,\r\n57191,57193,57203,57221,57223,57241,57251,57259,57269,57271,57283,57287,\r\n57301,57329,57331,57347,57349,57367,57373,57383,57389,57397,57413,57427,\r\n57457,57467,57487,57493,57503,57527,57529,57557,57559,57571,57587,57593,\r\n57601,57637,57641,57649,57653,57667,57679,57689,57697,57709,57713,57719,\r\n57727,57731,57737,57751,57773,57781,57787,57791,57793,57803,57809,57829,\r\n57839,57847,57853,57859,57881,57899,57901,57917,57923,57943,57947,57973,\r\n57977,57991,58013,58027,58031,58043,58049,58057,58061,58067,58073,58099,\r\n58109,58111,58129,58147,58151,58153,58169,58171,58189,58193,58199,58207,\r\n58211,58217,58229,58231,58237,58243,58271,58309,58313,58321,58337,58363,\r\n58367,58369,58379,58391,58393,58403,58411,58417,58427,58439,58441,58451,\r\n58453,58477,58481,58511,58537,58543,58549,58567,58573,58579,58601,58603,\r\n58613,58631,58657,58661,58679,58687,58693,58699,58711,58727,58733,58741,\r\n58757,58763,58771,58787,58789,58831,58889,58897,58901,58907,58909,58913,\r\n58921,58937,58943,58963,58967,58979,58991,58997,59009,59011,59021,59023,\r\n59029,59051,59053,59063,59069,59077,59083,59093,59107,59113,59119,59123,\r\n59141,59149,59159,59167,59183,59197,59207,59209,59219,59221,59233,59239,\r\n59243,59263,59273,59281,59333,59341,59351,59357,59359,59369,59377,59387,\r\n59393,59399,59407,59417,59419,59441,59443,59447,59453,59467,59471,59473,\r\n59497,59509,59513,59539,59557,59561,59567,59581,59611,59617,59621,59627,\r\n59629,59651,59659,59663,59669,59671,59693,59699,59707,59723,59729,59743,\r\n59747,59753,59771,59779,59791,59797,59809,59833,59863,59879,59887,59921,\r\n59929,59951,59957,59971,59981,59999,60013,60017,60029,60037,60041,60077,\r\n60083,60089,60091,60101,60103,60107,60127,60133,60139,60149,60161,60167,\r\n60169,60209,60217,60223,60251,60257,60259,60271,60289,60293,60317,60331,\r\n60337,60343,60353,60373,60383,60397,60413,60427,60443,60449,60457,60493,\r\n60497,60509,60521,60527,60539,60589,60601,60607,60611,60617,60623,60631,\r\n60637,60647,60649,60659,60661,60679,60689,60703,60719,60727,60733,60737,\r\n60757,60761,60763,60773,60779,60793,60811,60821,60859,60869,60887,60889,\r\n60899,60901,60913,60917,60919,60923,60937,60943,60953,60961,61001,61007,\r\n61027,61031,61043,61051,61057,61091,61099,61121,61129,61141,61151,61153,\r\n61169,61211,61223,61231,61253,61261,61283,61291,61297,61331,61333,61339,\r\n61343,61357,61363,61379,61381,61403,61409,61417,61441,61463,61469,61471,\r\n61483,61487,61493,61507,61511,61519,61543,61547,61553,61559,61561,61583,\r\n61603,61609,61613,61627,61631,61637,61643,61651,61657,61667,61673,61681,\r\n61687,61703,61717,61723,61729,61751,61757,61781,61813,61819,61837,61843,\r\n61861,61871,61879,61909,61927,61933,61949,61961,61967,61979,61981,61987,\r\n61991,62003,62011,62017,62039,62047,62053,62057,62071,62081,62099,62119,\r\n62129,62131,62137,62141,62143,62171,62189,62191,62201,62207,62213,62219,\r\n62233,62273,62297,62299,62303,62311,62323,62327,62347,62351,62383,62401,\r\n62417,62423,62459,62467,62473,62477,62483,62497,62501,62507,62533,62539,\r\n62549,62563,62581,62591,62597,62603,62617,62627,62633,62639,62653,62659,\r\n62683,62687,62701,62723,62731,62743,62753,62761,62773,62791,62801,62819,\r\n62827,62851,62861,62869,62873,62897,62903,62921,62927,62929,62939,62969,\r\n62971,62981,62983,62987,62989,63029,63031,63059,63067,63073,63079,63097,\r\n63103,63113,63127,63131,63149,63179,63197,63199,63211,63241,63247,63277,\r\n63281,63299,63311,63313,63317,63331,63337,63347,63353,63361,63367,63377,\r\n63389,63391,63397,63409,63419,63421,63439,63443,63463,63467,63473,63487,\r\n63493,63499,63521,63527,63533,63541,63559,63577,63587,63589,63599,63601,\r\n63607,63611,63617,63629,63647,63649,63659,63667,63671,63689,63691,63697,\r\n63703,63709,63719,63727,63737,63743,63761,63773,63781,63793,63799,63803,\r\n63809,63823,63839,63841,63853,63857,63863,63901,63907,63913,63929,63949,\r\n63977,63997,64007,64013,64019,64033,64037,64063,64067,64081,64091,64109,\r\n64123,64151,64153,64157,64171,64187,64189,64217,64223,64231,64237,64271,\r\n64279,64283,64301,64303,64319,64327,64333,64373,64381,64399,64403,64433,\r\n64439,64451,64453,64483,64489,64499,64513,64553,64567,64577,64579,64591,\r\n64601,64609,64613,64621,64627,64633,64661,64663,64667,64679,64693,64709,\r\n64717,64747,64763,64781,64783,64793,64811,64817,64849,64853,64871,64877,\r\n64879,64891,64901,64919,64921,64927,64937,64951,64969,64997,65003,65011,\r\n65027,65029,65033,65053,65063,65071,65089,65099,65101,65111,65119,65123,\r\n65129,65141,65147,65167,65171,65173,65179,65183,65203,65213,65239,65257,\r\n65267,65269,65287,65293,65309,65323,65327,65353,65357,65371,65381,65393,\r\n65407,65413,65419,65423,65437,65447,65449,65479,65497,65519,65521,65537,\r\n65539,65543,65551,65557,65563,65579,65581,65587,65599,65609,65617,65629,\r\n65633,65647,65651,65657,65677,65687,65699,65701,65707,65713,65717,65719,\r\n65729,65731,65761,65777,65789,65809,65827,65831,65837,65839,65843,65851,\r\n65867,65881,65899,65921,65927,65929,65951,65957,65963,65981,65983,65993,\r\n66029,66037,66041,66047,66067,66071,66083,66089,66103,66107,66109,66137,\r\n66161,66169,66173,66179,66191,66221,66239,66271,66293,66301,66337,66343,\r\n66347,66359,66361,66373,66377,66383,66403,66413,66431,66449,66457,66463,\r\n66467,66491,66499,66509,66523,66529,66533,66541,66553,66569,66571,66587,\r\n66593,66601,66617,66629,66643,66653,66683,66697,66701,66713,66721,66733,\r\n66739,66749,66751,66763,66791,66797,66809,66821,66841,66851,66853,66863,\r\n66877,66883,66889,66919,66923,66931,66943,66947,66949,66959,66973,66977,\r\n67003,67021,67033,67043,67049,67057,67061,67073,67079,67103,67121,67129,\r\n67139,67141,67153,67157,67169,67181,67187,67189,67211,67213,67217,67219,\r\n67231,67247,67261,67271,67273,67289,67307,67339,67343,67349,67369,67391,\r\n67399,67409,67411,67421,67427,67429,67433,67447,67453,67477,67481,67489,\r\n67493,67499,67511,67523,67531,67537,67547,67559,67567,67577,67579,67589,\r\n67601,67607,67619,67631,67651,67679,67699,67709,67723,67733,67741,67751,\r\n67757,67759,67763,67777,67783,67789,67801,67807,67819,67829,67843,67853,\r\n67867,67883,67891,67901,67927,67931,67933,67939,67943,67957,67961,67967,\r\n67979,67987,67993,68023,68041,68053,68059,68071,68087,68099,68111,68113,\r\n68141,68147,68161,68171,68207,68209,68213,68219,68227,68239,68261,68279,\r\n68281,68311,68329,68351,68371,68389,68399,68437,68443,68447,68449,68473,\r\n68477,68483,68489,68491,68501,68507,68521,68531,68539,68543,68567,68581,\r\n68597,68611,68633,68639,68659,68669,68683,68687,68699,68711,68713,68729,\r\n68737,68743,68749,68767,68771,68777,68791,68813,68819,68821,68863,68879,\r\n68881,68891,68897,68899,68903,68909,68917,68927,68947,68963,68993,69001,\r\n69011,69019,69029,69031,69061,69067,69073,69109,69119,69127,69143,69149,\r\n69151,69163,69191,69193,69197,69203,69221,69233,69239,69247,69257,69259,\r\n69263,69313,69317,69337,69341,69371,69379,69383,69389,69401,69403,69427,\r\n69431,69439,69457,69463,69467,69473,69481,69491,69493,69497,69499,69539,\r\n69557,69593,69623,69653,69661,69677,69691,69697,69709,69737,69739,69761,\r\n69763,69767,69779,69809,69821,69827,69829,69833,69847,69857,69859,69877,\r\n69899,69911,69929,69931,69941,69959,69991,69997,70001,70003,70009,70019,\r\n70039,70051,70061,70067,70079,70099,70111,70117,70121,70123,70139,70141,\r\n70157,70163,70177,70181,70183,70199,70201,70207,70223,70229,70237,70241,\r\n70249,70271,70289,70297,70309,70313,70321,70327,70351,70373,70379,70381,\r\n70393,70423,70429,70439,70451,70457,70459,70481,70487,70489,70501,70507,\r\n70529,70537,70549,70571,70573,70583,70589,70607,70619,70621,70627,70639,\r\n70657,70663,70667,70687,70709,70717,70729,70753,70769,70783,70793,70823,\r\n70841,70843,70849,70853,70867,70877,70879,70891,70901,70913,70919,70921,\r\n70937,70949,70951,70957,70969,70979,70981,70991,70997,70999,71011,71023,\r\n71039,71059,71069,71081,71089,71119,71129,71143,71147,71153,71161,71167,\r\n71171,71191,71209,71233,71237,71249,71257,71261,71263,71287,71293,71317,\r\n71327,71329,71333,71339,71341,71347,71353,71359,71363,71387,71389,71399,\r\n71411,71413,71419,71429,71437,71443,71453,71471,71473,71479,71483,71503,\r\n71527,71537,71549,71551,71563,71569,71593,71597,71633,71647,71663,71671,\r\n71693,71699,71707,71711,71713,71719,71741,71761,71777,71789,71807,71809,\r\n71821,71837,71843,71849,71861,71867,71879,71881,71887,71899,71909,71917,\r\n71933,71941,71947,71963,71971,71983,71987,71993,71999,72019,72031,72043,\r\n72047,72053,72073,72077,72089,72091,72101,72103,72109,72139,72161,72167,\r\n72169,72173,72211,72221,72223,72227,72229,72251,72253,72269,72271,72277,\r\n72287,72307,72313,72337,72341,72353,72367,72379,72383,72421,72431,72461,\r\n72467,72469,72481,72493,72497,72503,72533,72547,72551,72559,72577,72613,\r\n72617,72623,72643,72647,72649,72661,72671,72673,72679,72689,72701,72707,\r\n72719,72727,72733,72739,72763,72767,72797,72817,72823,72859,72869,72871,\r\n72883,72889,72893,72901,72907,72911,72923,72931,72937,72949,72953,72959,\r\n72973,72977,72997,73009,73013,73019,73037,73039,73043,73061,73063,73079,\r\n73091,73121,73127,73133,73141,73181,73189,73237,73243,73259,73277,73291,\r\n73303,73309,73327,73331,73351,73361,73363,73369,73379,73387,73417,73421,\r\n73433,73453,73459,73471,73477,73483,73517,73523,73529,73547,73553,73561,\r\n73571,73583,73589,73597,73607,73609,73613,73637,73643,73651,73673,73679,\r\n73681,73693,73699,73709,73721,73727,73751,73757,73771,73783,73819,73823,\r\n73847,73849,73859,73867,73877,73883,73897,73907,73939,73943,73951,73961,\r\n73973,73999,74017,74021,74027,74047,74051,74071,74077,74093,74099,74101,\r\n74131,74143,74149,74159,74161,74167,74177,74189,74197,74201,74203,74209,\r\n74219,74231,74257,74279,74287,74293,74297,74311,74317,74323,74353,74357,\r\n74363,74377,74381,74383,74411,74413,74419,74441,74449,74453,74471,74489,\r\n74507,74509,74521,74527,74531,74551,74561,74567,74573,74587,74597,74609,\r\n74611,74623,74653,74687,74699,74707,74713,74717,74719,74729,74731,74747,\r\n74759,74761,74771,74779,74797,74821,74827,74831,74843,74857,74861,74869,\r\n74873,74887,74891,74897,74903,74923,74929,74933,74941,74959,75011,75013,\r\n75017,75029,75037,75041,75079,75083,75109,75133,75149,75161,75167,75169,\r\n75181,75193,75209,75211,75217,75223,75227,75239,75253,75269,75277,75289,\r\n75307,75323,75329,75337,75347,75353,75367,75377,75389,75391,75401,75403,\r\n75407,75431,75437,75479,75503,75511,75521,75527,75533,75539,75541,75553,\r\n75557,75571,75577,75583,75611,75617,75619,75629,75641,75653,75659,75679,\r\n75683,75689,75703,75707,75709,75721,75731,75743,75767,75773,75781,75787,\r\n75793,75797,75821,75833,75853,75869,75883,75913,75931,75937,75941,75967,\r\n75979,75983,75989,75991,75997,76001,76003,76031,76039,76079,76081,76091,\r\n76099,76103,76123,76129,76147,76157,76159,76163,76207,76213,76231,76243,\r\n76249,76253,76259,76261,76283,76289,76303,76333,76343,76367,76369,76379,\r\n76387,76403,76421,76423,76441,76463,76471,76481,76487,76493,76507,76511,\r\n76519,76537,76541,76543,76561,76579,76597,76603,76607,76631,76649,76651,76667,76673,76679,76697,76717,76733,76753,76757,76771,76777,76781,76801,\r\n76819,76829,76831,76837,76847,76871,76873,76883,76907,76913,76919,76943,\r\n76949,76961,76963,76991,77003,77017,77023,77029,77041,77047,77069,77081,\r\n77093,77101,77137,77141,77153,77167,77171,77191,77201,77213,77237,77239,\r\n77243,77249,77261,77263,77267,77269,77279,77291,77317,77323,77339,77347,\r\n77351,77359,77369,77377,77383,77417,77419,77431,77447,77471,77477,77479,\r\n77489,77491,77509,77513,77521,77527,77543,77549,77551,77557,77563,77569,\r\n77573,77587,77591,77611,77617,77621,77641,77647,77659,77681,77687,77689,\r\n77699,77711,77713,77719,77723,77731,77743,77747,77761,77773,77783,77797,\r\n77801,77813,77839,77849,77863,77867,77893,77899,77929,77933,77951,77969,\r\n77977,77983,77999,78007,78017,78031,78041,78049,78059,78079,78101,78121,\r\n78137,78139,78157,78163,78167,78173,78179,78191,78193,78203,78229,78233,\r\n78241,78259,78277,78283,78301,78307,78311,78317,78341,78347,78367,78401,\r\n78427,78437,78439,78467,78479,78487,78497,78509,78511,78517,78539,78541,\r\n78553,78569,78571,78577,78583,78593,78607,78623,78643,78649,78653,78691,\r\n78697,78707,78713,78721,78737,78779,78781,78787,78791,78797,78803,78809,\r\n78823,78839,78853,78857,78877,78887,78889,78893,78901,78919,78929,78941,\r\n78977,78979,78989,79031,79039,79043,79063,79087,79103,79111,79133,79139,\r\n79147,79151,79153,79159,79181,79187,79193,79201,79229,79231,79241,79259,\r\n79273,79279,79283,79301,79309,79319,79333,79337,79349,79357,79367,79379,\r\n79393,79397,79399,79411,79423,79427,79433,79451,79481,79493,79531,79537,\r\n79549,79559,79561,79579,79589,79601,79609,79613,79621,79627,79631,79633,\r\n79657,79669,79687,79691,79693,79697,79699,79757,79769,79777,79801,79811,\r\n79813,79817,79823,79829,79841,79843,79847,79861,79867,79873,79889,79901,\r\n79903,79907,79939,79943,79967,79973,79979,79987,79997,79999,80021,80039,\r\n80051,80071,80077,80107,80111,80141,80147,80149,80153,80167,80173,80177,\r\n80191,80207,80209,80221,80231,80233,80239,80251,80263,80273,80279,80287,\r\n80309,80317,80329,80341,80347,80363,80369,80387,80407,80429,80447,80449,\r\n80471,80473,80489,80491,80513,80527,80537,80557,80567,80599,80603,80611,\r\n80621,80627,80629,80651,80657,80669,80671,80677,80681,80683,80687,80701,\r\n80713,80737,80747,80749,80761,80777,80779,80783,80789,80803,80809,80819,\r\n80831,80833,80849,80863,80897,80909,80911,80917,80923,80929,80933,80953]\r\nb=[]\r\nfor m in a:\r\n x=a.index(m)\r\n if(x in a):\r\n b.append(m)\r\ns=[]\r\ns.append(b[0])\r\nfor i in range(1,1000):\r\n s.append((b[i]+s[i-1])%1000000007)\r\nfor j in range(int(input())):\r\n n=int(input())\r\n print(s[n-1])"]
{"inputs": [["2", "1", "2"]], "outputs": [["3", "8"]]}
INTERVIEW
PYTHON3
CODECHEF
84,042
9c269de3866fb4b3ddc5fc4cdbd34d83
UNKNOWN
Two integers A and B are the inputs. Write a program to find GCD and LCM of A and B. -----Input----- The first line contains an integer T, total number of testcases. Then follow T lines, each line contains an integer A and B. -----Output----- Display the GCD and LCM of A and B separated by space respectively. The answer for each test case must be displayed in a new line. -----Constraints----- - 1 ≤ T ≤ 1000 - 1 ≤ A,B ≤ 1000000 -----Example----- Input 3 120 140 10213 312 10 30 Output 20 840 1 3186456 10 30
["# 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 lcm = (x*y)//GCD(x,y)\n return lcm\n\nt = int(input())\nwhile t>0:\n x,y = list(map(int,input().split()))\n print(GCD(x,y),LCM(x,y)) \n t -=1\n", "import math\ntc = int(input())\nfor i in range(tc):\n x,y = list(map(int,input().split()))\n gcd = math.gcd(x,y)\n lcm = (x*y)//gcd\n print(gcd,lcm)\n", "# cook your dish here\nimport math\ndef find():\n x,y = map(int,input().split())\n a = math.gcd(x,y)\n lcm = (x*y)//a\n print(a,lcm)\n \n\nfor i in range(int(input())):\n find()", "# cook your dish here\nimport math\ndef find():\n x,y = list(map(int,input().split()))\n a = math.gcd(x,y)\n lcm = (x*y)//a\n print(a,lcm)\n \n\nfor i in range(int(input())):\n find()\n", "# cook your dish here\nimport math\ndef find():\n x,y = map(int,input().split())\n a = math.gcd(x,y)\n lcm = (x*y)//a\n print(a,lcm)\n \n\nfor i in range(int(input())):\n find()", "# cook your dish here\nimport math\nT = int(input())\nwhile(T>0):\n A,B = map(int,input().split())\n hcf = math.gcd(A,B)\n lcm = (A*B)//hcf\n print(hcf,lcm)\n T = T - 1", "# cook your dish here\nimport math\nt = int(input())\nfor i in range(0, t):\n (a, b) = map(int, input() .split())\n gcd = math.gcd(a,b)\n lcm = int((a*b)/gcd)\n print(gcd,lcm)", "import math\nfor t in range(int(input())):\n a,b=map(int, input().split())\n x=math.gcd(a,b)\n y=(a*b)//x\n print(x,y)", "# cook your dish here\nimport math\nn=int(input())\nfor i in range(n):\n a,b=input().split()\n a=int(a)\n b=int(b)\n x=math.gcd(a,b)\n y=(a*b)//x\n print(x,y)\n \n \n \n # if n1>n2:\n # large = n1 \n # small = n2\n # else:\n # large = n2\n # small = n1\n # lt = large\n # st = small\n # while(st!=0):\n # if small%st == 0 and large%st == 0:\n # break\n # else:\n # st = st - 1\n", "import math\nn=int(input())\nfor i in range(n):\n a,b=input().split()\n a=int(a)\n b=int(b)\n x=math.gcd(a,b)\n y=(a*b)//x\n print(x,y)", "def GCD(a,b):\n if(b==0):\n return a\n else:\n return (GCD(b,a%b))\nn=int(input())\nfor i in range(n):\n a,b=input().split()\n a,b=int(a),int(b)\n c=GCD(a,b)\n d=(a*b)//c\n print(c,d)", "t = int(input())\n\ndef gcd(a, b):\n \n while a != b:\n if a > b:\n a = a - b\n else:\n b = b - a\n return a\n\nfor _ in range(t):\n int_1,int_2 = list(map(int,input().split()))\n \n hcf = gcd(int_1,int_2)\n \n lcm = (int_2*int_1)/hcf\n \n print(int(hcf),int(lcm))\n \n", "# cook your dish here\nfrom sys import stdin, stdout\n\n\ndef gcd(A, B):\n if B == 0:\n return A\n \n else:\n return gcd(B, A%B)\n\n\nfor _ in range(int(stdin.readline())):\n A, B = list(map(int, stdin.readline().split()))\n g = gcd(A, B)\n l = A // g * B\n stdout.write(str(g)+\" \")\n stdout.write(str(l)+\"\\n\")\n", "# cook your dish here\nt=int(input())\n\nfor _ in range(t):\n a,b=map(int,input().split())\n dup1=a\n dup2=b\n while(b!=0):\n temp=b \n b=a%b \n a=temp\n gcd=int(a) \n lcm=int ((dup1*dup2)/gcd)\n print(gcd, lcm)", "import math\nN=int(input())\nfor i in range(N):\n a,b=list(map(int,input().split()))\n c=math.gcd(a,b)\n lcm=(a*b)//c\n print(c ,lcm)\n \n", "import math\nt=int(input())\nfor i in range(t):\n a,b=map(int,input().split(\" \"))\n c=math.gcd(a,b)\n l=(a*b)//c\n print(c,\" \",l)"]
{"inputs": [["3", "120 140", "10213 312", "10 30"]], "outputs": [["20 840", "1 3186456", "10 30"]]}
INTERVIEW
PYTHON3
CODECHEF
3,609
637cf36f95f5ce9d81ffcba390a3af2b
UNKNOWN
Soma is a fashionable girl. She absolutely loves shiny stones that she can put on as jewellery accessories. She has been collecting stones since her childhood - now she has become really good with identifying which ones are fake and which ones are not. Her King requested for her help in mining precious stones, so she has told him which all stones are jewels and which are not. Given her description, your task is to count the number of jewel stones. More formally, you're given a string J composed of latin characters where each character is a jewel. You're also given a string S composed of latin characters where each character is a mined stone. You have to find out how many characters of S are in J as well. -----Input----- First line contains an integer T denoting the number of test cases. Then follow T test cases. Each test case consists of two lines, each of which contains a string composed of English lower case and upper characters. First of these is the jewel string J and the second one is stone string S. You can assume that 1 <= T <= 100, 1 <= |J|, |S| <= 100 -----Output----- Output for each test case, a single integer, the number of jewels mined. -----Example----- Input: 4 abc abcdef aA abAZ aaa a what none Output: 3 2 1 0
["n = int(input())\nfor i in range(n):\n count = 0\n k = input()\n x = list(k)\n kk = input()\n y = list(kk)\n for j in y:\n for jj in x:\n if(j==jj):\n count = count+1\n break\n print(count)", "for _t in range(int(input())):\n J = set(list(input().strip()))\n print(sum(1 for x in input() if x in J))", "T=int(input())\nfor i in range(1, T+1):\n J=input()\n S=input()\n count=0\n for letter in S:\n if(letter in J):\n count+=1\n print(count)\n", "# code chef may2012 stones.py\n\n\nt = int(input())\nfor t1 in range(t):\n j = input().strip()\n s = input().strip()\n answer = 0\n for c in s:\n if c in j:\n answer +=1\n print(answer)\n", "ile = eval(input())\nwhile ile:\n suma = 0\n lista = input()\n jeweled = input()\n for znak in jeweled:\n if znak in lista:\n suma+=1\n print(suma)\n ile-=1", "'''\nCreated on 6 mai 2012\n\n@author: Quentin\n'''\nimport sys, re\n\ndef readInput(stream):\n T = int(stream.readline())\n JSs = []\n for Tit in range(T) :\n J = re.sub(\"[\\n\\s]*\",\"\",stream.readline())\n S = re.sub(\"[\\n\\s]*\",\"\",stream.readline())\n JSs.append((J,S))\n return JSs\n\ndef compute(JSs):\n for J, S in JSs :\n count = 0\n for char in S :\n if J.find(char) != -1 :\n count += 1\n print(count)\n\ndef __starting_point():\n JSs = readInput(sys.stdin)\n compute(JSs)\n__starting_point()", "a = (int)(input())\n\nfor i in range(a):\n total = 0\n str1 = input()\n str2 = input()\n str1 = set(str1)\n# str2 = set(str2) \n for a in str1:\n for b in str2:\n if a == b:\n total = total+ 1\n print(total)", "n=int(input())\nfor i in range(0,n):\n s=0\n r1=input().strip()\n r2=input().strip()\n for i in r2:\n if i in r1:\n s+=1\n print(s)", "def process(first, second):\n dist1 = {}\n dist2 = {}\n for s in first:\n dist1[s] = 1\n ret = 0\n for s in second:\n if s in dist1:\n ret = ret + 1\n\n print(ret)\n\ndef __starting_point():\n cases = int(input())\n for i in range(cases):\n first = input()\n second = input()\n\n process(first, second)\n\n__starting_point()", "t=(int)(input())\nwhile t>0:\n t-=1\n c=0\n j=input()\n s=input()\n n=j.__len__()\n m=s.__len__()\n l=int(m)\n p=int(n)\n for i in range(l):\n for k in range(p):\n if s[i]==j[k]:\n c+=1\n break\n print(c)", "n=int(input())\nfor i in range(0,n):\n s=0\n r1=input().strip()\n r2=input().strip()\n for i in r2:\n if i in r1:\n s+=1\n print(s)\n", "for case in range(int(input())):\n jewels = set([])\n for char in input().rstrip(\"\\n\"):\n jewels.add(char)\n \n count = 0\n for char in input().rstrip(\"\\n\"):\n if char in jewels:\n count += 1\n print(count)", "tc = int(input())\nfor itercnt in range(tc):\n str1 = input()\n str2 = input()\n cnt = 0\n for x in str2:\n for y in str1:\n if (x == y): \n cnt+=1\n break\n print(cnt)", "#Jewels And Stones\ndef common(s1,s2):\n n=0\n done=[]\n for i in s1:\n if i in done:\n continue\n for j in s2:\n if i==j:\n n+=1\n done+=[i]\n return n\nt=int(input())\nfor i in range(t):\n s1=str(input())\n s2=str(input())\n print(common(s1,s2))\n", "# Jewels.py\n# Code Chef Problem: Jewels and Stones\n# http://www.codechef.com/MAY12/problems/STONES\n# May Long Challenge 2012\n# Benjamin Johnson\n# May 4 2012 \n# Lessons Learned:\n\nimport sys,time,math\n\n#Use the test file when testing\n#testInputFile = open(\"test.in\",\"r\")\n\n#Get input here\ntestCases = int(sys.stdin.readline())\n#testCases = int(testInputFile.readline())\n\nfor i in range(testCases):\n count = 0\n jewels = {}\n #jewelsLine = testInputFile.readline().strip()\n jewelsLine = sys.stdin.readline().strip()\n for char in jewelsLine:\n if char in jewels:\n jewels[char] += 1\n else:\n jewels[char] = 1\n #stonesLine = testInputFile.readline().strip()\n stonesLine = sys.stdin.readline().strip()\n for stone in stonesLine:\n if stone in jewels:\n if jewels[stone] > 0:\n #jewels[stone] -= 1\n count += 1\n sys.stdout.write(\"%d\\n\"%count)\n\n#testInputFile.close()\n", "def __starting_point():\n t = int(input().strip())\n for test in range(t):\n s1 = input().strip()\n d1 = {}\n for i in s1:\n if i in d1:\n d1[i] += 1\n else:\n d1[i] = 1\n s2 = input().strip()\n ans = 0\n for i in s2:\n if i in d1:\n d1[i] -= 1\n ans += 1\n print(ans)\n \n\n__starting_point()", "from sys import *\nt=eval(input())\nfor i in range(t):\n j=input()\n s=input()\n ans=0\n for k in range(len(s)):\n if s[k] in j:\n ans+=1\n print(ans)\nreturn", "t = int(input())\nwhile t > 0:\n s = set(input())\n ans = 0\n for c in input():\n if c in s:\n ans += 1\n print(ans)\n t -= 1\n", "def main():\n\n t = int(input())\n\n # enter cases\n for i in range(t):\n a = str(input())\n b = str(input())\n checkJewellery(a, b)\n\ndef checkJewellery(a, b):\n count = 0\n for s in b:\n if s in a:\n count = count + 1\n print(count)\n\n#===============================================================================\n\ndef __starting_point():\n main()\n\n__starting_point()", "#!/usr/bin/env python\n#-------------------------------------------------------------------------------\n# Name: module1\n# Purpose:\n#\n# Author: dvdreddy\n#\n# Created: 05/03/2012\n# Copyright: (c) dvdreddy 2012\n# Licence: <your licence>\n#-------------------------------------------------------------------------------\n\n\n\ndef toint(s): return int(s)\ndef tofloat(s): return float(s)\n\ndef get_int():\n s=input()\n return int(s)\n\ndef main():\n t=get_int()\n while t:\n j=input()\n s=input()\n\n a=[0]*256\n for i in j:\n a[ord(i)]=1\n res=0\n for i in s:\n res+=a[ord(i)]\n print(res)\n t-=1\n pass\n\ndef __starting_point():\n main()\n\n__starting_point()"]
{"inputs": [["4", "abc", "abcdef", "aA", "abAZ", "aaa", "a", "what", "none"]], "outputs": [["3", "2", "1", "0"]]}
INTERVIEW
PYTHON3
CODECHEF
5,685
e9c1eec384e8f86df71b9546dee64bbd
UNKNOWN
There are total N friends went to Chef's Pizza shop. There they bought a pizza. Chef divided the pizza into K equal slices. Now you have to check whether these K pizza slices can be distributed equally among the friends. Also given that every person should get at least one slice. If the above conditions are possible then print "YES" otherwise print "NO". -----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 integers N. The second line of each test case contains K. -----Output:----- For each test case, print a single line containing "YES" if the given conditions are true else "NO" if the given conditions are false. -----Constraints----- 1<=T<=10 1<=N<=10^6 1<=K<=10^6 -----Sample Input:----- 2 10 20 12 5 -----Sample Output:----- YES NO -----EXPLANATION:----- Explanation case 1: since there are 10 friends and 20 pizza slice, so each can get 2 slices, so "YES". Explanation case 2: Since there are 12 friends and only 5 pizza slice, so there is no way pizza slices can be distributed equally and each friend gets at least one pizza slice, so "NO".
["for _ in range(int(input())):\n n = int(input())\n k = int(input())\n if k%n==0:\n print(\"YES\")\n else:\n print(\"NO\")\n", "for i in range(int(input())):\n n=int(input())\n k=int(input())\n if k%n==0 and k>=n:\n print(\"YES\")\n else:\n print(\"NO\")", "# cook your dish here\n# cook your dish here\nfor nt in range(int(input())):\n a=int(input())\n b=int(input())\n if b%a==0:\n print(\"YES\")\n else:\n print(\"NO\")", "for _ in range(int(input())):\n N = int(input())\n K = int(input())\n \n if K%N == 0:\n print(\"YES\")\n else:\n print(\"NO\")", "T = int(input())\nwhile T>0:\n N = int(input())\n K = int(input())\n if K %N ==0:\n print(\"YES\")\n else:\n print(\"NO\")\n T = T-1", "T = int(input())\nfor i in range(T):\n N = int(input())\n K = int(input())\n if K%N == 0 and K >= N:\n print('YES')\n else:\n print(\"NO\")", "n=int(input())\nfor i in range(n):\n m=int(input())\n k=int(input())\n if k%m==0:\n print('YES')\n else:\n print('NO')", "for t in range(int(input())):\n a=int(input())\n b=int(input())\n if(b%a==0):\n print(\"YES\")\n else:\n print(\"NO\")\n", "# cook your dish here\nt=int(input())\nwhile(t):\n n=int(input())\n k=int(input())\n if max(n,k)%min(n,k)==0:\n print('YES')\n else:\n print('NO')\n t-=1", "# cook your dish here\nn=int(input())\nfor i in range(n):\n a=int(input())\n b=int(input())\n if b%a==0:\n print('YES')\n else:\n print('NO')", "# cook your dish here\nfor _ in range(int(input())):\n n=int(input())\n m=int(input())\n if m%n==0:\n print(\"YES\")\n else:\n print(\"NO\")", "# cook your dish here\nfor _ in range(int(input())):\n n=int(input())\n m=int(input())\n if m%n==0:\n print(\"YES\")\n else:\n print(\"NO\")", "# cook your dish here\nt=int(input())\nfor _ in range(t):\n a=int(input())\n b=int(input())\n if(b%a==0):\n print(\"YES\")\n else:\n print(\"NO\")\n", "t=int(input())\nfor _ in range(t):\n n=int(input())\n k=int(input())\n if k<n:\n print(\"NO\")\n else:\n if k%n==0:\n print(\"YES\")\n else:\n print(\"NO\")\n", "# cook your dish here\nfor i in range(int(input())):\n n=int(input())\n k=int(input())\n if(k%n==0):\n print(\"YES\")\n else: print(\"NO\")\n", "# cook your dish here\nfor _ in range(int(input())):\n n = int(input())\n k = int(input())\n if k % n == 0:\n print(\"YES\")\n else:\n print(\"NO\")", "# cook your dish here\ndef check(n,k):\n return 1 if k>=n and k%n==0 else 0\n\ndef __starting_point():\n for _ in range(int(input())):\n n=int(input())\n k=int(input())\n if check(n,k):\n print(\"YES\")\n else:\n print(\"NO\")\n__starting_point()", "for i in range(int(input())):\n x = int(input())\n y = int(input())\n if(y%x==0):\n print(\"YES\")\n else:\n print(\"NO\")# cook your dish here\n", "# cook your dish here\nt=int(input())\nfor w in range(t):\n n=int(input())\n k=int(input())\n if k%n==0 and k>=n:\n print('YES')\n else:\n print('NO ')", "# cook your dish here\nfor a0 in range(int(input())):\n n = int(input())\n k = int(input())\n if k%n == 0:\n print('YES')\n else:\n print('NO')", "# cook your dish here\nt=int(input())\nfor i in range(0,t):\n n=int(input())\n k=int(input())\n if k%n==0:\n print(\"YES\")\n else:\n print(\"NO\")\n", "for _ in range(int(input())):\r\n n = int(input())\r\n k = int(input())\r\n print(\"YES\" if k % n == 0 else \"NO\")\r\n"]
{"inputs": [["2", "10", "20", "12", "5"]], "outputs": [["YES", "NO"]]}
INTERVIEW
PYTHON3
CODECHEF
3,877
3e33c78c28918c5903ef20e51163e69f
UNKNOWN
Tennis is a popular game. Consider a simplified view of a tennis game from directly above. The game will appear to be played on a 2 dimensional rectangle, where each player has his own court, a half of the rectangle. Consider the players and the ball to be points moving on this 2D plane. The ball can be assumed to always move with fixed velocity (speed and direction) when it is hit by a player. The ball changes its velocity when hit by the other player. And so on, the game continues. Chef also enjoys playing tennis, but in n+1$n + 1$ dimensions instead of just 3. From the perspective of the previously discussed overhead view, Chef's court is an n$n$-dimensional hyperrectangle which is axis-aligned with one corner at (0,0,0,…,0)$(0, 0, 0, \dots, 0)$ and the opposite corner at (l1,l2,l3,…,ln$(l_1, l_2, l_3, \dots, l_n$). The court of his opponent is the reflection of Chef's court across the n−1$n - 1$ dimensional surface with equation x1=0$x_1 = 0$. At time t=0$t=0$, Chef notices that the ball is at position (0,b2,…,bn)$(0, b_2, \dots, b_n)$ after being hit by his opponent. The velocity components of the ball in each of the n$n$ dimensions are also immediately known to Chef, the component in the ith$i^{th}$ dimension being vi$v_i$. The ball will continue to move with fixed velocity until it leaves Chef's court. The ball is said to leave Chef's court when it reaches a position strictly outside the bounds of Chef's court. Chef is currently at position (c1,c2,…,cn)$(c_1, c_2, \dots, c_n)$. To hit the ball back, Chef must intercept the ball before it leaves his court, which means at a certain time the ball's position and Chef's position must coincide. To achieve this, Chef is free to change his speed and direction at any time starting from time t=0$t=0$. However, Chef is lazy so he does not want to put in more effort than necessary. Chef wants to minimize the maximum speed that he needs to acquire at any point in time until he hits the ball. Find this minimum value of speed smin$s_{min}$. Note: If an object moves with fixed velocity →v$\vec{v}$ and is at position →x$\vec{x}$ at time 0$0$, its position at time t$t$ is given by →x+→v⋅t$\vec{x} + \vec{v} \cdot t$. -----Input----- - The first line contains t$t$, the number of test cases. t$t$ cases follow. - The first line of each test case contains n$n$, the number of dimensions. - The next line contains n$n$ integers l1,l2,…,ln$l_1, l_2, \dots, l_n$, the bounds of Chef's court. - The next line contains n$n$ integers b1,b2,…,bn$b_1, b_2, \dots, b_n$, the position of the ball at t=0$t=0$. - The next line contains n$n$ integers v1,v2,…,vn$v_1, v_2, \dots, v_n$, the velocity components of the ball. - The next line contains n$n$ integers, c1,c2,…,cn$c_1, c_2, \dots, c_n$, Chef's position at t=0$t=0$. -----Output----- - For each test case, output a single line containing the value of smin$s_{min}$. Your answer will be considered correct if the absolute error does not exceed 10−2$10^{-2}$. -----Constraints----- - 1≤t≤1500$1 \leq t \leq 1500$ - 2≤n≤50$2 \leq n \leq 50$ - 1≤li≤50$1 \leq l_i \leq 50$ - 0≤bi≤li$0 \leq b_i \leq l_i$ and b1=0$b_1 = 0$ - −10≤vi≤10$-10 \leq v_i \leq 10$ and v1>0$v_1 > 0$ - 0≤ci≤li$0 \leq c_i \leq l_i$ - It is guaranteed that the ball stays in the court for a non-zero amount of time. -----Sample Input----- 2 2 3 4 0 2 2 -2 2 2 3 10 10 10 0 0 0 1 1 1 5 5 5 -----Sample Output----- 2.0000 0.0000 -----Explanation----- Case 1: The court is 2-dimentional. The ball's trajectory is marked in red. For Chef it is optimal to move along the blue line at a constant speed of 2 until he meets the ball at the boundary. Case 2: The court is 3-dimensional and the ball is coming straight at Chef. So it is best for Chef to not move at all, thus smin=0$s_{min} = 0$.
["eps=1e-8\nt=int(input())\nfor ii in range(t):\n n=int(input())\n l=[int(i) for i in input().split() ]\n b=[int(i) for i in input().split() ]\n v=[int(i) for i in input().split() ]\n c=[int(i) for i in input().split() ]\n greatest_time=l[0]/v[0]\n for i in range(1,n):\n if v[i]>0:\n greatest_time=min(greatest_time,(l[i]-b[i])/v[i])\n elif v[i]<0:\n greatest_time=min(greatest_time,-b[i]/v[i])\n p = sum((b[i] - c[i]) ** 2 for i in range(n))\n q = sum(2 * (b[i] - c[i]) * v[i] for i in range(n))\n r = sum(vi ** 2 for vi in v)\n func = lambda t: p/t/t + q/t + r\n #ternary search\n \n def ternsearch():\n \n if b==c:\n return(0)\n \n lo,hi=0,greatest_time\n while hi-lo>eps:\n d=(hi-lo)/3\n m1=lo+d\n m2=m1+d\n if func(m1)<=func(m2):\n hi=m2\n else:\n lo=m1\n #print(hi,lo)\n #print(func(lo)**(0.5))\n return max(0,func(lo))**(0.5)\n ans=ternsearch()\n print('%.12f' % (ans,))\n \n \n\n \n \n\n", "\r\neps=1e-8\r\nt=int(input())\r\nfor ii in range(t):\r\n n=int(input())\r\n l=[int(i) for i in input().split() ]\r\n b=[int(i) for i in input().split() ]\r\n v=[int(i) for i in input().split() ]\r\n c=[int(i) for i in input().split() ]\r\n greatest_time=l[0]/v[0]\r\n for i in range(1,n):\r\n if v[i]>0:\r\n greatest_time=min(greatest_time,(l[i]-b[i])/v[i])\r\n elif v[i]<0:\r\n greatest_time=min(greatest_time,-b[i]/v[i])\r\n p = sum((b[i] - c[i]) ** 2 for i in range(n))\r\n q = sum(2 * (b[i] - c[i]) * v[i] for i in range(n))\r\n r = sum(vi ** 2 for vi in v)\r\n func = lambda t: p/t/t + q/t + r\r\n #ternary search\r\n \r\n def ternsearch():\r\n \r\n if b==c:\r\n return(0)\r\n \r\n lo,hi=0,greatest_time\r\n while hi-lo>eps:\r\n d=(hi-lo)/3\r\n m1=lo+d\r\n m2=m1+d\r\n if func(m1)<=func(m2):\r\n hi=m2\r\n else:\r\n lo=m1\r\n #print(hi,lo)\r\n #print(func(lo)**(0.5))\r\n return max(0,func(lo))**(0.5)\r\n ans=ternsearch()\r\n print('%.12f' % (ans,))\r\n \r\n \r\n\r\n \r\n \r\n", "# cook your dish here\r\nEPS = 1e-8\r\n\r\n\r\nfor t in range(int(input())):\r\n n = int(input())\r\n l = list(map(int, input().split()))\r\n b = list(map(int, input().split()))\r\n v = list(map(int, input().split()))\r\n c = list(map(int, input().split()))\r\n\r\n t_exit = l[0] / v[0]\r\n for i in range(1, n):\r\n if v[i] > 0:\r\n t_exit = min(t_exit, (l[i] - b[i]) / v[i])\r\n elif v[i] < 0:\r\n t_exit = min(t_exit, -b[i] / v[i])\r\n\r\n p = sum((b[i] - c[i]) ** 2 for i in range(n))\r\n q = sum(2 * (b[i] - c[i]) * v[i] for i in range(n))\r\n r = sum(vi ** 2 for vi in v)\r\n\r\n func = lambda t: p / t / t + q / t + r\r\n def method1():\r\n if b == c:\r\n return 0\r\n lo, hi = 0, t_exit\r\n while hi - lo > EPS:\r\n d = (hi - lo) / 3\r\n m1 = lo + d\r\n m2 = m1 + d\r\n if func(m1) <= func(m2):\r\n hi = m2\r\n else:\r\n lo = m1\r\n return max(0, func(lo)) ** 0.5\r\n ans = method1()\r\n print('%.12f' % (ans,))", "# cook your dish here\r\nEPS = 1e-8\r\nEPS_ANS = 1e-3\r\n\r\nfor t in range(int(input())):\r\n n = int(input())\r\n l = list(map(int, input().split()))\r\n b = list(map(int, input().split()))\r\n v = list(map(int, input().split()))\r\n c = list(map(int, input().split()))\r\n\r\n t_exit = l[0] / v[0]\r\n for i in range(1, n):\r\n if v[i] > 0:\r\n t_exit = min(t_exit, (l[i] - b[i]) / v[i])\r\n elif v[i] < 0:\r\n t_exit = min(t_exit, -b[i] / v[i])\r\n\r\n p = sum((b[i] - c[i]) ** 2 for i in range(n))\r\n q = sum(2 * (b[i] - c[i]) * v[i] for i in range(n))\r\n r = sum(vi ** 2 for vi in v)\r\n\r\n func = lambda t: p / t / t + q / t + r\r\n def method1():\r\n if b == c:\r\n return 0\r\n lo, hi = 0, t_exit\r\n while hi - lo > EPS:\r\n d = (hi - lo) / 3\r\n m1 = lo + d\r\n m2 = m1 + d\r\n if func(m1) <= func(m2):\r\n hi = m2\r\n else:\r\n lo = m1\r\n return max(0, func(lo)) ** 0.5\r\n ans = method1()\r\n print('%.12f' % (ans,))", "# cook your dish here\nEPS = 1e-8\nEPS_ANS = 1e-3\n\nfor t in range(int(input())):\n n = int(input())\n l = list(map(int, input().split()))\n b = list(map(int, input().split()))\n v = list(map(int, input().split()))\n c = list(map(int, input().split()))\n\n t_exit = l[0] / v[0]\n for i in range(1, n):\n if v[i] > 0:\n t_exit = min(t_exit, (l[i] - b[i]) / v[i])\n elif v[i] < 0:\n t_exit = min(t_exit, -b[i] / v[i])\n\n p = sum((b[i] - c[i]) ** 2 for i in range(n))\n q = sum(2 * (b[i] - c[i]) * v[i] for i in range(n))\n r = sum(vi ** 2 for vi in v)\n\n func = lambda t: p / t / t + q / t + r\n def method1():\n if b == c:\n return 0\n lo, hi = 0, t_exit\n while hi - lo > EPS:\n d = (hi - lo) / 3\n m1 = lo + d\n m2 = m1 + d\n if func(m1) <= func(m2):\n hi = m2\n else:\n lo = m1\n return max(0, func(lo)) ** 0.5\n ans = method1()\n print('%.12f' % (ans,))", "# cook your dish here\nEPS = 1e-8\nEPS_ANS = 1e-3\n\nfor t in range(int(input())):\n n = int(input())\n l = list(map(int, input().split()))\n b = list(map(int, input().split()))\n v = list(map(int, input().split()))\n c = list(map(int, input().split()))\n\n t_exit = l[0] / v[0]\n for i in range(1, n):\n if v[i] > 0:\n t_exit = min(t_exit, (l[i] - b[i]) / v[i])\n elif v[i] < 0:\n t_exit = min(t_exit, -b[i] / v[i])\n\n p = sum((b[i] - c[i]) ** 2 for i in range(n))\n q = sum(2 * (b[i] - c[i]) * v[i] for i in range(n))\n r = sum(vi ** 2 for vi in v)\n\n func = lambda t: p / t / t + q / t + r\n def method1():\n if b == c:\n return 0\n lo, hi = 0, t_exit\n while hi - lo > EPS:\n d = (hi - lo) / 3\n m1 = lo + d\n m2 = m1 + d\n if func(m1) <= func(m2):\n hi = m2\n else:\n lo = m1\n return max(0, func(lo)) ** 0.5\n ans = method1()\n print('%.12f' % (ans,))\n", "# cook your dish here\nEPS = 1e-8\nEPS_ANS = 1e-3\n\nfor t in range(int(input())):\n n = int(input())\n l = list(map(int, input().split()))\n b = list(map(int, input().split()))\n v = list(map(int, input().split()))\n c = list(map(int, input().split()))\n\n t_exit = l[0] / v[0]\n for i in range(1, n):\n if v[i] > 0:\n t_exit = min(t_exit, (l[i] - b[i]) / v[i])\n elif v[i] < 0:\n t_exit = min(t_exit, -b[i] / v[i])\n\n p = sum((b[i] - c[i]) ** 2 for i in range(n))\n q = sum(2 * (b[i] - c[i]) * v[i] for i in range(n))\n r = sum(vi ** 2 for vi in v)\n\n func = lambda t: p / t / t + q / t + r\n def method1():\n if b == c:\n return 0\n lo, hi = 0, t_exit\n while hi - lo > EPS:\n d = (hi - lo) / 3\n m1 = lo + d\n m2 = m1 + d\n if func(m1) <= func(m2):\n hi = m2\n else:\n lo = m1\n return max(0, func(lo)) ** 0.5\n ans = method1()\n print('%.12f' % (ans,))\n", "EPS = 1e-8\nEPS_ANS = 1e-3\n\nfor t in range(int(input())):\n n = int(input())\n l = list(map(int, input().split()))\n b = list(map(int, input().split()))\n v = list(map(int, input().split()))\n c = list(map(int, input().split()))\n\n t_exit = l[0] / v[0]\n for i in range(1, n):\n if v[i] > 0:\n t_exit = min(t_exit, (l[i] - b[i]) / v[i])\n elif v[i] < 0:\n t_exit = min(t_exit, -b[i] / v[i])\n\n p = sum((b[i] - c[i]) ** 2 for i in range(n))\n q = sum(2 * (b[i] - c[i]) * v[i] for i in range(n))\n r = sum(vi ** 2 for vi in v)\n\n func = lambda t: p / t / t + q / t + r\n def method1():\n if b == c:\n return 0\n lo, hi = 0, t_exit\n while hi - lo > EPS:\n d = (hi - lo) / 3\n m1 = lo + d\n m2 = m1 + d\n if func(m1) <= func(m2):\n hi = m2\n else:\n lo = m1\n return max(0, func(lo)) ** 0.5\n ans = method1()\n print('%.12f' % (ans,))\n", "EPS = 1e-8\r\nEPS_ANS = 1e-3\r\n\r\nfor t in range(int(input())):\r\n n = int(input())\r\n l = list(map(int, input().split()))\r\n b = list(map(int, input().split()))\r\n v = list(map(int, input().split()))\r\n c = list(map(int, input().split()))\r\n\r\n t_exit = l[0] / v[0]\r\n for i in range(1, n):\r\n if v[i] > 0:\r\n t_exit = min(t_exit, (l[i] - b[i]) / v[i])\r\n elif v[i] < 0:\r\n t_exit = min(t_exit, -b[i] / v[i])\r\n\r\n p = sum((b[i] - c[i]) ** 2 for i in range(n))\r\n q = sum(2 * (b[i] - c[i]) * v[i] for i in range(n))\r\n r = sum(vi ** 2 for vi in v)\r\n\r\n func = lambda t: p / t / t + q / t + r\r\n def method1():\r\n if b == c:\r\n return 0\r\n lo, hi = 0, t_exit\r\n while hi - lo > EPS:\r\n d = (hi - lo) / 3\r\n m1 = lo + d\r\n m2 = m1 + d\r\n if func(m1) <= func(m2):\r\n hi = m2\r\n else:\r\n lo = m1\r\n return max(0, func(lo)) ** 0.5\r\n ans = method1()\r\n print('%.12f' % (ans,))", "# cook your dish here\nimport math\nfor i in range(int(input())):\n n=int(input())\n bound=[int(i) for i in input().split()]\n ball=[int(i) for i in input().split()]\n speed=[int(i) for i in input().split()]\n chef=[int(i) for i in input().split()]\n cspeed=0\n time=float('inf')\n for i in range(n):\n if(speed[i]>0): \n a=(bound[i]-ball[i])/speed[i]\n time=min(a,time)\n elif(speed[i]<0):\n a=abs(ball[i]/speed[i])\n time=min(a,time)\n \n a=b=c=0 \n for i in range(n):\n c+=speed[i]**2 \n a+=(ball[i]-chef[i])**2\n b+=2*speed[i]*(ball[i]-chef[i])\n if(a==0):\n print(0)\n else:\n x=-b/(2*a)\n if(x>=1/time):\n cspeed=c - (b**2)/(4*a)\n print(math.sqrt(cspeed))\n else:\n cspeed=a/(time**2) + b/time + c\n print(math.sqrt(cspeed))\n"]
{"inputs": [["2", "2", "3 4", "0 2", "2 -2", "2 2", "3", "10 10 10", "0 0 0", "1 1 1", "5 5 5"]], "outputs": [["2.0000", "0.0000"]]}
INTERVIEW
PYTHON3
CODECHEF
11,065
10f6d17abe6ab53993662bb6f0ad3c9e
UNKNOWN
Every character in the string “IITMANDI” is given a certain number of points. You are given a scrabble board with only one row. The input contains the positions of score modifiers such as: Double Letter, Triple Letter, Double Word and Triple Word. You need to find the best position to place the string “IITMANDI” such that your score is maximized. Double Letter - Doubles the number of points you get for the letter placed on the double letter. Triple Letter - Triples the number of points you get for the letter placed on the triple letter. Double Word - Doubles the number of points you get for the word. Applied after applying above modifiers. Triple Word - Triples the number of points you get for the word. Applied after applying the above modifiers. The word has to be read from left to right. You can’t place it in the reverse direction. The letters have to be placed continuously on the board. If there is no modifier or a double word or triple word modifier before a tile, it's score is added to the total score. The double word and triple modifiers are applied at the end. -----Input Format----- - First line containes a single integer $T$ - the number of test cases. - First line of each test case contains a single integer $N$ - the size of the board. - Second line of each test case contains a string of size $N$ representing the board according to the following convention: '.' - No modifier 'd' - Double letter 't' - Triple letter 'D' - Double word 'T' - Triple word - Third line of each test case contains 8 integers corresponding to the points associated with each letter of the string "IITMANDI". Note that the 3 'I's in IITMANDI cannot be interchanged freely. The score of the first 'I' will be equal to the first integer, score of the second 'I' will be equal to the second integer and the score of the last 'I' will be equal to the last integer. -----Output Format----- For each test case, output a single integer in a new line, the maximum possible score. -----Constraints----- $ 1 \leq T \leq 1000 $ $ 8 \leq N \leq 100 $ $ 0 \leq $ Points for each character $ \leq 10^5 $ -----Sample Input----- 2 10 ..d.t.D..d 10 11 12 9 8 10 11 15 22 dtDtTD..ddT.TtTdDT..TD 12297 5077 28888 17998 12125 27400 31219 21536 -----Sample Output----- 270 35629632
["# cook your dish here\ntry:\n \n T = int(input())\n\n for i in range(T):\n n = int(input())\n s = input()\n arr = [int(i) for i in input().strip().split(\" \")]\n res = 1\n result = 0\n\n for j in range(n-7):\n res = 1\n res1= 0\n s1 = s[j:j+8]\n for i in range(8):\n if s1[i] == 'D':\n res = res*2\n res1 += arr[i]\n\n elif s1[i] == 'T':\n res = res*3\n res1 = res1 + arr[i]\n elif s1[i] == 'd':\n res1 = res1 + arr[i]*2\n elif s1[i] == 't':\n res1 += arr[i]*3\n else:\n res1 += arr[i]\n res = res*res1\n result = max(res,result)\n print(result)\nexcept EOFError:\n pass\n\n \n \n \n \n \n \n", "# cook your dish here\n# cook your dish here\ntry:\n maxpoint=[]\n def maxpoints(n,string,sc):\n i=0\n points=0\n increaser=1\n while i<8:\n if string[i]=='.':\n points+=sc[i]\n i+=1\n elif string[i]=='d':\n points+=sc[i]*2\n i+=1\n elif string[i]=='t':\n points+=sc[i]*3\n i+=1\n elif string[i]=='D':\n increaser=increaser*2\n points+=sc[i]\n i+=1\n elif string[i]=='T':\n increaser=increaser*3\n points+=sc[i]\n i+=1\n points=points*increaser\n maxpoint.append(points)\n return points\n def values(n,string,sc):\n for i in range(n-7):\n maxpoints(n,string[i:],sc)\n return max(maxpoint)\n t=int(input())\n for i in range(t):\n n=int(input())\n string=str(input())\n if n>=8 and n==len(string):\n sc=list(map(int,input().split()))\n print(values(n,string,sc))\n maxpoint=[]\n else:\n print('String is not equals to the length given')\n break\nexcept EOFError:\n pass", "# cook your dish here\ntry:\n maxpoint=[]\n def maxpoints(n,string,sc):\n i=0\n points=0\n increaser=1\n while i<8:\n if string[i]=='.':\n points+=sc[i]\n i+=1\n elif string[i]=='d':\n points+=sc[i]*2\n i+=1\n elif string[i]=='t':\n points+=sc[i]*3\n i+=1\n elif string[i]=='D':\n increaser=increaser*2\n points+=sc[i]\n i+=1\n elif string[i]=='T':\n increaser=increaser*3\n points+=sc[i]\n i+=1\n points=points*increaser\n maxpoint.append(points)\n return points\n def values(n,string,sc):\n for i in range(n-7):\n maxpoints(n,string[i:],sc)\n return max(maxpoint)\n t=int(input())\n for i in range(t):\n n=int(input())\n string=str(input())\n if n>=8 and n==len(string):\n sc=list(map(int,input().split()))\n print(values(n,string,sc))\n maxpoint=[]\n else:\n print('String is not equals to the length given')\n break\nexcept EOFError:\n pass", "# cook your dish here\ntry:\n maxpoint=[]\n def maxpoints(n,string,sc):\n i=0\n points=0\n increaser=1\n while i<8:\n if string[i]=='.':\n points+=sc[i]\n i+=1\n elif string[i]=='d':\n points+=sc[i]*2\n i+=1\n elif string[i]=='t':\n points+=sc[i]*3\n i+=1\n elif string[i]=='D':\n increaser=increaser*2\n points+=sc[i]\n i+=1\n elif string[i]=='T':\n increaser=increaser*3\n points+=sc[i]\n i+=1\n points=points*increaser\n maxpoint.append(points)\n return points\n def values(n,string,sc):\n for i in range(n-7):\n maxpoints(n,string[i:],sc)\n return max(maxpoint)\n t=int(input())\n for i in range(t):\n n=int(input())\n string=str(input())\n if n>=8 and n==len(string):\n sc=list(map(int,input().split()))\n print(values(n,string,sc))\n maxpoint=[]\n else:\n print('String is not equals to the length given')\n break\nexcept EOFError:\n pass", "# cook your dish here\nfor e in range(int(input())):\n n = int(input())\n s = input()\n l = list(map(int,input().split()))\n s = list(s)\n m = 0\n for i in range(n-7):\n total = 0\n k = 0\n DT = 1\n for j in range(i,i+8):\n if s[j] == '.':\n total += l[k]\n elif s[j] == 'd':\n total += (2*l[k])\n elif s[j] == 't':\n total += (3*l[k])\n elif s[j] == 'D':\n DT = DT * 2\n total += l[k]\n elif s[j] == 'T':\n DT = DT * 3\n total += l[k]\n k += 1\n \n total = total * DT\n m = max(total, m)\n \n \n print(m)", "try:\n maxpoint=[]\n def maxpoints(n,string,sc):\n i=0\n points=0\n increaser=1\n while i<8:\n if string[i]=='.':\n points+=sc[i]\n i+=1\n elif string[i]=='d':\n points+=sc[i]*2\n i+=1\n elif string[i]=='t':\n points+=sc[i]*3\n i+=1\n elif string[i]=='D':\n increaser=increaser*2\n points+=sc[i]\n i+=1\n elif string[i]=='T':\n increaser=increaser*3\n points+=sc[i]\n i+=1\n points=points*increaser\n maxpoint.append(points)\n return points\n def values(n,string,sc):\n for i in range(n-7):\n maxpoints(n,string[i:],sc)\n return max(maxpoint)\n t=int(input())\n for i in range(t):\n n=int(input())\n string=str(input())\n if n>=8 and n==len(string):\n sc=list(map(int,input().split()))\n print(values(n,string,sc))\n maxpoint=[]\n else:\n print('String is not equals to the length given')\n break\nexcept EOFError:\n pass", "try:\n maxpoint=[]\n def maxpoints(n,string,sc):\n i=0\n points=0\n increaser=1\n while i<8:\n if string[i]=='.':\n points+=sc[i]\n i+=1\n elif string[i]=='d':\n points+=sc[i]*2\n i+=1\n elif string[i]=='t':\n points+=sc[i]*3\n i+=1\n elif string[i]=='D':\n increaser=increaser*2\n points+=sc[i]\n i+=1\n elif string[i]=='T':\n increaser=increaser*3\n points+=sc[i]\n i+=1\n points=points*increaser\n maxpoint.append(points)\n return points\n def values(n,string,sc):\n for i in range(n-7):\n maxpoints(n,string[i:],sc)\n return max(maxpoint)\n t=int(input())\n for i in range(t):\n n=int(input())\n string=str(input())\n if n>=8 and n==len(string):\n sc=list(map(int,input().split()))\n print(values(n,string,sc))\n maxpoint=[]\n else:\n print('String is not equals to the length given')\n break\nexcept EOFError:\n pass", "# cook your dish here\nmaxpoints=[]\ndef maxvaluez(num,arr,sc):\n \n i=0\n points=0\n mult=1\n while i<8: \n if arr[i]==\".\":\n points+=sc[i]\n i+=1\n\n elif arr[i]==\"d\":\n points+=2*sc[i]\n i+=1\n\n elif arr[i]==\"t\":\n points+=3*sc[i]\n \n\n i+=1\n\n elif arr[i]==\"D\":\n mult=mult*2\n points+=sc[i]\n i+=1\n\n elif arr[i]==\"T\":\n mult=mult*3\n points+=sc[i]\n i+=1\n\n else:\n i+=1\n \n\n points=points*mult\n maxpoints.append(points)\n return points\n \ndef maxpicker(num,arr,sc):\n for i in range(num-7):\n maxvaluez(num,arr[i:],sc)\n \n return max(maxpoints)\n\ntry:\n t=int(input())\n for i in range(t):\n num = int(input())\n arr = input()\n sc = list(map(int, input().split()))\n print(maxpicker(num,arr,sc))\n maxpoints=[]\nexcept:\n pass", "# cook your dish here\n# cook your code here\nt = int(input())\nfor i in range(t):\n num = int(input())\n arr = input()\n sc = list(map(int, input().split()))\n maxs = 0\n for z in range(num - 7):\n score = 0\n mul =1\n for b in range(8):\n if (arr[z+b]=='d'):\n score += sc[b]*2\n elif (arr[z+b]=='t'):\n score += sc[b]*3 \n elif (arr[z+b]=='D'):\n mul *= 2\n score += sc[b]\n elif (arr[z+b]=='T'):\n mul *= 3\n score += sc[b]\n else:\n score += sc[b]\n score *= mul\n if score > maxs:\n maxs = score\n print(maxs)\n", "# cook your dish here\nT = int(input())\n\nmax_score = []\n\nfor _ in range(T):\n\n N = int(input())\n string = input()\n score = input().split()\n score = list(map(int, score))\n\n \n noi = (N - 8 + 1)\n\n maximum = 0 \n \n for i in range(noi):\n\n dd = 0\n ttt = 0\n scrs = string[i:i+8]\n\n num_scrs = []\n for scr in scrs:\n\n if scr == '.':\n num_scrs.append(1)\n\n elif scr == 'd':\n num_scrs.append(2)\n\n elif scr == 't':\n num_scrs.append(3)\n\n elif scr == 'D':\n num_scrs.append(1)\n dd += 1\n\n elif scr == 'T':\n num_scrs.append(1)\n ttt += 1\n\n s = 0\n \n for i in range(8):\n s += num_scrs[i]*score[i]\n\n s *= 2**dd\n s *= 3**ttt\n\n if s > maximum:\n maximum = s\n \n max_score.append(maximum)\n\n\nfor s in max_score:\n\n print(s)\n", "# cook your dish here\nt=int(input())\nfor i in range(0, t):\n n=int(input())\n s=str(input())\n l=list(map(int, input().split()))\n sum1=sum(l)\n finalSum=0\n for i in range(n-7):\n sum2 = 0\n dw=1\n tw=1\n for k in range(i,i+8):\n if s[k]==\"d\":\n sum2=sum2+2*l[k-i]\n elif s[k]==\"t\":\n sum2 = sum2 + 3*l[k-i]\n elif s[k]==\"D\":\n dw*=2\n sum2 = sum2 + l[k - i]\n elif s[k]==\"T\":\n tw*=3\n sum2 = sum2 + l[k - i]\n else:\n sum2 = sum2 + l[k - i]\n\n # print(sum2)\n finalSum=max(finalSum,sum2*dw*tw)\n\n print(finalSum)", "#cook\npos_values = {\"d\" : 2, \"t\" : 3, \".\" : 1, \"D\" : 1, \"T\" : 1}\nT = int(input())\nfor i in range(T):\n N = int(input())\n positions = input()\n values = input()\n \n list_of_values = []\n temp = 0\n prev = 0\n i = 0\n while i < len(values):\n if values[i] == \" \":\n temp = int(values[prev : i])\n list_of_values.append(temp)\n prev = i+1\n i += 1\n else:\n i += 1\n \n temp = int(values[prev : i])\n list_of_values.append(temp)\n \n set_of_values = []\n \n for j in range(N-7):\n temp = 0\n for k in range(8):\n temp += list_of_values[k]*pos_values.get(positions[j+k])\n \n for k in range(8):\n if positions[j+k] == \"D\":\n temp *= 2\n elif positions[j+k] == \"T\":\n temp *= 3\n \n set_of_values.append(temp)\n \n max_num = 0\n for l in range(len(set_of_values)):\n max_num = max(max_num, set_of_values[l])\n \n print(max_num)", "#cook\npos_values = {\"d\" : 2, \"t\" : 3, \".\" : 1, \"D\" : 1, \"T\" : 1}\nT = int(input())\nfor i in range(T):\n N = int(input())\n positions = input()\n values = input()\n \n list_of_values = []\n temp = 0\n prev = 0\n i = 0\n while i < len(values):\n if values[i] == \" \":\n temp = int(values[prev : i])\n list_of_values.append(temp)\n prev = i+1\n i += 1\n else:\n i += 1\n \n temp = int(values[prev : i])\n list_of_values.append(temp)\n \n set_of_values = []\n \n for j in range(N-7):\n temp = 0\n for k in range(8):\n temp += list_of_values[k]*pos_values.get(positions[j+k])\n \n for k in range(8):\n if positions[j+k] == \"D\":\n temp *= 2\n elif positions[j+k] == \"T\":\n temp *= 3\n \n set_of_values.append(temp)\n \n max_num = 0\n for l in range(len(set_of_values)):\n max_num = max(max_num, set_of_values[l])\n \n print(max_num)", "# cook your dish here\nfor _ in range(int(input())):\n n=int(input())\n s=list(input())\n N=[int(i) for i in input().split()]\n dic={'.':1,'d':2,'t':3,'D':1,'T':1}\n maxx=0\n for i in range(n-8+1):\n st=s[i:i+8]\n total=0\n D=0\n T=0\n for j in range(8):\n if st[j] in ['.','d','t']:\n total=total+dic[st[j]]*N[j]\n elif st[j]=='D':\n total=total+dic[st[j]]*N[j]\n D=D+1\n else:\n total=total+dic[st[j]]*N[j]\n T=T+1\n total=total*(2**D) \n total=total*(3**T)\n if maxx<total:\n maxx=total\n print(maxx)", "T = int(input())\n\nmax_score = []\n\nfor _ in range(T):\n\n N = int(input())\n string = input()\n score = input().split()\n score = list(map(int, score))\n\n \n noi = (N - 8 + 1)\n\n maximum = 0 \n \n for i in range(noi):\n\n dd = 0\n ttt = 0\n scrs = string[i:i+8]\n\n num_scrs = []\n for scr in scrs:\n\n if scr == '.':\n num_scrs.append(1)\n\n elif scr == 'd':\n num_scrs.append(2)\n\n elif scr == 't':\n num_scrs.append(3)\n\n elif scr == 'D':\n num_scrs.append(1)\n dd += 1\n\n elif scr == 'T':\n num_scrs.append(1)\n ttt += 1\n\n s = 0\n \n for i in range(8):\n s += num_scrs[i]*score[i]\n\n s *= 2**dd\n s *= 3**ttt\n\n if s > maximum:\n maximum = s\n \n max_score.append(maximum)\n\n\nfor s in max_score:\n\n print(s)\n\n \n \n \n", "\nt = int(input())\nmaxi =[]\nfor _ in range(t):\n n = int(input())\n board = input()\n arr = input()\n points = list(map(int , arr.split(' ')))\n values = []\n for i in range(n-7):\n dw = 1\n tw = 1\n total = 0 \n for j in range(i,i+8):\n if board[j] == 'd':\n total += 2*points[j-i]\n elif board[j] == 't':\n total += 3*points[j-i]\n elif board[j] == 'D':\n dw *= 2\n total += points[j-i]\n elif board[j] == 'T':\n tw *= 3\n total += points[j-i]\n elif board[j] == \".\" :\n total += points[j-i]\n #print(total)\n \n total *= dw\n \n total *= tw \n values.append(total)\n #print(values)\n maxi.append(max(values))\nfor element in maxi:\n print(element)\n\n", "# cook your dish here\nT=int(input())\nwhile T:\n N=int(input())\n s=str(input())\n l=list(map(int,input().split()))\n \n re=[]\n for i in range(N-7):\n sum=0\n d1=1\n t1=1\n for j in range(len(l)):\n if s[i+j]==\".\":\n sum=sum+l[j]\n elif s[i+j]==\"d\":\n sum=sum+l[j]*2\n elif s[i+j]==\"t\":\n sum=sum+l[j]*3\n elif s[i+j]==\"D\":\n sum=sum+l[j]\n d1=d1*2\n elif s[i+j]==\"T\":\n sum=sum+l[j]\n t1=t1*3\n \n if d1>1 and t1>1:\n sum=sum*d1*t1\n elif d1>1:\n sum=sum*d1\n else:\n sum=sum*t1\n re.append(sum)\n \n print(max(re))\n T=T-1\n", "# cook your dish here\nt = int(input())\nfor z in range (t):\n n = int (input())\n board = input()\n b = list(board)\n #print(b)\n maxscore = 0\n scores = list(map(int , input().split()))\n #print(scores)\n for i in range(0 , n-7):\n #print(i)\n multiplier = 1 \n score = 0 \n for j in range (i,i+8):\n if (board[j]==\".\"):\n score += scores[j-i]\n elif(board[j]==\"d\"):\n score += scores[j-i]*2\n elif(board[j]==\"t\"):\n score += scores[j-i]*3\n elif(board[j]==\"T\"):\n score += scores[j-i]\n multiplier *= 3\n else:\n score += scores[j-i]\n multiplier *= 2\n maxscore= max ( maxscore , multiplier*score)\n print(maxscore)", "for _ in range(int(input())):\n sum = 0; count = 0;max = 0;\n n = int(input())\n st = input()\n li = [int(i) for i in input().split(' ')]\n flag = True\n for i in range(n - 7):\n k = 0;count = 1;sum = 0;\n for j in range(i,i + 8):\n if st[j] == 'd':\n sum += li[k] * 2\n elif st[j] == 't':\n sum += li[k] * 3;\n elif st[j] == 'D':\n sum += li[k]\n count *= 2;\n elif st[j] == 'T':\n sum += li[k]\n count *= 3;\n else:\n sum += li[k]\n k += 1\n if flag == True:\n max = sum * count\n flag = False\n else:\n if sum * count > max:\n max = sum * count\n print(max)", "for _ in range(int(input())):\n sum = 0; count = 0;max = 0;\n n = int(input())\n st = input()\n li = [int(i) for i in input().split(' ')]\n flag = True\n for i in range(n - 7):\n k = 0;count = 1;sum = 0;\n for j in range(i,i + 8):\n if st[j] == 'd':\n sum += li[k] * 2\n elif st[j] == 't':\n sum += li[k] * 3;\n elif st[j] == 'D':\n sum += li[k]\n count *= 2;\n elif st[j] == 'T':\n sum += li[k]\n count *= 3;\n else:\n sum += li[k]\n k += 1\n if flag == True:\n max = sum * count\n flag = False\n else:\n if sum * count > max:\n max = sum * count\n print(max)", "T = int(input())\nfor j in range(T):\n n = int(input())\n ar = input()\n ar_v = list(map(int, input().split()))\n mx=0\n for i in range(n-7):\n sm =0\n m=1\n \n for k in range(8):\n if ar[i+k]=='.':\n sm +=ar_v[k]\n elif ar[i+k]=='d':\n sm =sm+ (2*ar_v[k])\n elif ar[i+k]=='t':\n sm =sm+(3*ar_v[k])\n elif ar[i+k]=='D':\n sm =sm+ar_v[k]\n m *=2\n elif ar[i+k]=='T':\n sm =sm+ar_v[k]\n m *=3\n sm = sm*m\n #print(sm)\n if mx<sm:\n mx=sm\n print(mx)", "# cook your dish here\nT = int(input())\nfor j in range(T):\n n = int(input())\n ar = input()\n ar_v = list(map(int, input().split()))\n mx=0\n for i in range(n-7):\n sm =0\n m=1\n \n for k in range(8):\n if ar[i+k]=='.':\n sm +=ar_v[k]\n elif ar[i+k]=='d':\n sm =sm+ (2*ar_v[k])\n elif ar[i+k]=='t':\n sm =sm+(3*ar_v[k])\n elif ar[i+k]=='D':\n sm =sm+ar_v[k]\n m *=2\n elif ar[i+k]=='T':\n sm =sm+ar_v[k]\n m *=3\n sm = sm*m\n #print(sm)\n if mx<sm:\n mx=sm\n print(mx)", "t=int(input())\nwhile(t>0):\n n=int(input())\n s=str(input())\n A=list(map(int,input().split()))\n maxi=0\n for i in range(0,n-7):\n summ=0\n new=\"\"\n k=0\n for j in range(i,i+8):\n if(s[j]=='D' or s[j]=='T'):\n new=new+s[j]\n if(s[j]=='d'):\n summ+=(2*A[k])\n elif(s[j]=='t'):\n summ+=(3*A[k])\n else:\n summ+=A[k]\n k+=1\n for x in new:\n if(x=='D'):\n summ=(2*summ)\n else:\n summ=(3*summ)\n if(summ>maxi):\n maxi=summ\n print(maxi)\n t=t-1", "#!/bin/python3\n\nimport math\nimport os\nimport random\nimport re\nimport sys\n\ndef findMaxScore(mod, arr):\n\n m = 0\n\n for i in range(0,len(mod)-7):\n m = max(m,getScore(mod[i:i+8],arr))\n\n return m\n\ndef getScore(s,arr):\n \n m = 1\n\n score = 0\n\n for i in range(0,8):\n\n if(s[i] == 'd'):\n score += 2*arr[i]\n elif(s[i] == 't'):\n score += 3*arr[i]\n elif(s[i] == 'D'):\n score += arr[i]\n m *= 2\n elif(s[i] == 'T'):\n score += arr[i]\n m *= 3\n else:\n score += arr[i]\n \n return m*score\n\ndef __starting_point():\n \n try:\n n = int(input())\n \n for _ in range(n):\n \n l = int(input())\n mod = input()\n arr = [int(y) for y in input().split()]\n print(findMaxScore(mod,arr))\n \n except EOFError:\n x = 2\n__starting_point()", "# cook your dish here\n# cook your dish here\ndef calc(W,board):\n #print(board)\n d = t = score = 0\n for i in range(8):\n if board[i]=='d': score+= (2*W[i])\n elif board[i]=='t': score+= (3*W[i])\n elif board[i] == 'D': \n d += 1\n score += W[i]\n elif board[i] == 'T': \n t+=1\n score += W[i]\n else: score += W[i]\n #print(\"i=\",i,\"score=\",score)\n #print(\"d=\",d,\"t=\",t)\n score *= 2**d * 3**t\n #if t>0: score = 3*t*score\n #print(\"\\nvv\",score,\"\\n\")\n #print(len(str(score)))\n #print(\"--------------------------------------------\")\n return score\n \ndef __starting_point():\n output = \"\"\n for test in range(int(input())):\n N = int(input())\n board = input()\n W = [int(x) for x in input().split()]\n m = -1\n for i in range(N-7):\n #print(board[i:i+8])\n m = max(m,calc(W,board[i:i+8]))\n output += str(m)+\"\\n\"\n print(output.rstrip())\n__starting_point()"]
{"inputs": [["2", "10", "..d.t.D..d", "10 11 12 9 8 10 11 15", "22", "dtDtTD..ddT.TtTdDT..TD", "12297 5077 28888 17998 12125 27400 31219 21536"]], "outputs": [["270", "35629632"]]}
INTERVIEW
PYTHON3
CODECHEF
17,980
7057ca7a6c161f8ccc9f557dd4e05bf7
UNKNOWN
Let X be the set of all integers between 0 and n-1. Suppose we have a collection S1, S2, ..., Sm of subsets of X. Say an atom A is a subset of X such that for each Si we have either A is a subset of Si or A and Si do not have any common elements. Your task is to find a collection A1, ..., Ak of atoms such that every item in X is in some Ai and no two Ai, Aj with i ≠ j share a common item. Surely such a collection exists as we could create a single set {x} for each x in X. A more interesting question is to minimize k, the number of atoms. -----Input----- The first line contains a single positive integer t ≤ 30 indicating the number of test cases. Each test case begins with two integers n,m where n is the size of X and m is the number of sets Si. Then m lines follow where the i'th such line begins with an integer vi between 1 and n (inclusive) indicating the size of Si. Following this are vi distinct integers between 0 and n-1 that describe the contents of Si. You are guaranteed that 1 ≤ n ≤ 100 and 1 ≤ m ≤ 30. Furthermore, each number between 0 and n-1 will appear in at least one set Si. -----Output----- For each test case you are to output a single integer indicating the minimum number of atoms that X can be partitioned into to satisfy the constraints. -----Example----- Input: 2 5 2 3 0 1 2 3 2 3 4 4 3 2 0 1 2 1 2 2 2 3 Output: 3 4
["# cook your dish here\n# cook your dish here\nfor _ in range(int(input())):\n n,m=list(map(int,input().split()))\n atomlist = ['']*n\n for k in range(m):\n s=[]\n s.extend(input().split()[1:])\n #print(s)\n for w in range(n):\n if str(w) in s:\n atomlist[w]+=\"1\"\n else:\n atomlist[w]+=\"0\"\n #print(atomlist)\n print(len(set(atomlist)))\n", "# cook your dish here\n# cook your dish here\nfor _ in range(int(input())):\n n,m=list(map(int,input().split()))\n atomlist = ['']*n\n for k in range(m):\n s=[]\n s.extend(input().split()[1:])\n #print(s)\n for w in range(n):\n if str(w) in s:\n atomlist[w]+=\"1\"\n else:\n atomlist[w]+=\"0\"\n #print(atomlist)\n print(len(set(atomlist)))\n", "# cook your dish here\nfor _ in range(int(input())):\n n,m=list(map(int,input().split()))\n atomlist = ['']*n\n for k in range(m):\n s=[]\n s.extend(input().split()[1:])\n #print(s)\n for w in range(n):\n if str(w) in s:\n atomlist[w]+=\"1\"\n else:\n atomlist[w]+=\"0\"\n #print(atomlist)\n print(len(set(atomlist)))\n"]
{"inputs": [["2", "5 2", "3 0 1 2", "3 2 3 4", "4 3", "2 0 1", "2 1 2", "2 2 3"]], "outputs": [["3", "4"]]}
INTERVIEW
PYTHON3
CODECHEF
1,060
8229dcfb342dc10213890020ef8cc5bf
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:----- 5 1 2 3 4 5 -----Sample Output:----- * * ** * ** *** * ** * * **** * ** * * * * ***** -----EXPLANATION:----- No need, else pattern can be decode easily.
["# cook your dish here\ndef solve():\n n=int(input())\n i=0\n while i<n-1:\n if i==0:\n print(\"*\",end=\"\")\n else:\n print(\"*\",end=\"\")\n for k in range(i-1):\n print(\" \",end=\"\")\n print(\"*\",end=\"\")\n print() \n i+=1 \n for i in range(n):\n print(\"*\",end=\"\")\n print() \n\nt=int(input())\ni=0\nwhile(i<t):\n solve()\n \n i+=1", "def solve():\r\n n=int(input())\r\n i=0\r\n while i<n-1:\r\n if i==0:\r\n print(\"*\",end=\"\")\r\n else:\r\n print(\"*\",end=\"\")\r\n for k in range(i-1):\r\n print(\" \",end=\"\")\r\n print(\"*\",end=\"\")\r\n print() \r\n i+=1 \r\n for i in range(n):\r\n print(\"*\",end=\"\")\r\n print() \r\n\r\nt=int(input())\r\ni=0\r\nwhile(i<t):\r\n solve()\r\n \r\n i+=1", "t=int(input())\r\nfor _ in range(t):\r\n n=int(input())\r\n for i in range(n):\r\n if i==n-1:\r\n print('*'*(i+1))\r\n else:\r\n if i==0:\r\n print('*')\r\n else:\r\n print('*'+\" \"*(i+1-2)+'*')\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n", "# cook your dish here\nfor _ in range(int(input())):\n n=int(input())\n for i in range(1,n+1):\n for j in range(1,i+1):\n if j==1 or j==i or i==n:\n print(\"*\",end=\"\")\n else:\n print(\" \",end=\"\")\n print(\"\")\n", "# cook your dish here\nfor _ in range(int(input())):\n n=int(input())\n for i in range(n):\n if i==0 or i==1 or i==n-1:\n for j in range(i+1):\n print(\"*\",end='')\n else:\n for j in range(n):\n if j==0 or j==i:\n print('*',end='')\n else:\n print(\" \",end='')\n print()", "for _ in range(int(input())):\n n=int(input())\n a=0\n if n==1:\n print('*')\n elif n==2:\n print('*')\n print('**')\n else: \n print('*')\n for _ in range(2,n):\n print('*',end=\"\")\n if a>0:\n print(' '*a,end=\"\")\n a+=1 \n print('*')\n print('*'*n) ", "n = int(input())\nwhile(n>0):\n n-=1\n a = int(input())\n print(\"*\")\n for i in range(2,a):\n print(\"*\", end='')\n print(\" \"*(i-2), end='')\n print(\"*\")\n if(a!=1):\n print(\"*\"*a)\n\n", "n = int(input())\nwhile(n>0):\n n-=1\n a = int(input())\n print(\"*\")\n for i in range(2,a):\n print(\"*\", end='')\n print(\" \"*(i-2), end='')\n print(\"*\")\n if(a!=1):\n print(\"*\"*a)\n\n", "t = int(input())\nfor _ in range(t):\n n = int(input())\n for i in range(n):\n for j in range(n):\n if i<(n-1):\n if j==0 or i==j:\n print('*',end='')\n else:\n print(' ',end='')\n else:\n print('*',end='')\n print()\n", "for _ in range(int(input())):\n n = int(input())\n print(\"*\")\n for i in range(2, n):\n print(\"*\" + \" \" * (i - 2) + \"*\")\n if n > 1:\n print(n * \"*\")", "for _ in range(int(input())):\r\n n=int(input())\r\n for i in range(0,n):\r\n for j in range(0,n):\r\n if i==n-1 or j==0 or i==j:\r\n print('*',end='')\r\n else:\r\n print(end=' ')\r\n print()", "try:\r\n t = int(input())\r\n for a in range(t):\r\n k = int(input())\r\n for i in range(k):\r\n # for j in range(k):\r\n if (i==0 or i==k-1):\r\n print(\"*\"*(i+1))\r\n else:\r\n print(\"*\"+(\" \"*(i-1))+\"*\")\r\nexcept EOFError:\r\n pass", "#Pattern I\r\nT = int(input())\r\n\r\nfor t in range(T):\r\n N = int(input())\r\n \r\n for i in range(N):\r\n if(i==0):\r\n print(\"*\")\r\n elif(i==(N-1)):\r\n print(\"*\"*N)\r\n else:\r\n print(\"*\"+\" \"*(i-1)+\"*\")", "t=int(input())\r\nfor i in range(t):\r\n k=int(input())\r\n m=0\r\n for j in range(1,k+1):\r\n for m in range(1,k+1):\r\n if j==k:\r\n print(\"*\",end=\"\")\r\n else:\r\n if m==1 or m==j:\r\n print(\"*\",end=\"\")\r\n else:\r\n print(\" \",end=\"\")\r\n print()", "for tc in range(int(input())):\r\n K = int(input())\r\n for i in range(K):\r\n ar = []\r\n for j in range(i + 1):\r\n if i == K - 1 or j == 0 or j == i:\r\n ar.append('*')\r\n else:\r\n ar.append(' ')\r\n print(''.join(ar))", "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 for i in range(n):\n for j in range(n):\n if j>i: continue\n elif i>j and j!=0 and j!=n-1 and i!=0 and i!=n-1: print(\" \", end=\"\")\n else: print(\"*\", end=\"\")\n print()", "# cook your dish here\nfor a0 in range(int(input())):\n n=int(input())\n if n==1:\n print(\"*\")\n elif n==2:\n print(\"*\")\n print(\"**\")\n elif n==3:\n print(\"*\")\n print(\"**\")\n print(\"***\")\n else:\n print(\"*\")\n print(\"**\")\n for i in range(3,n):\n s=\" \"*(i-2)\n print(\"*\"+s+\"*\")\n print(\"*\"*n)\n", "for _ in range(int(input())):\r\n n = int(input())\r\n\r\n l = [[' '] * i for i in range(1, n+1)]\r\n\r\n for i in range(n-1):\r\n l[i][0] = l[i][-1] = '*'\r\n print(*l[i], sep='')\r\n\r\n print('*' * n)"]
{"inputs": [["5", "1", "2", "3", "4", "5"]], "outputs": [["*", "*", "**", "*", "**", "***", "*", "**", "* *", "****", "*", "**", "* *", "* *", "*****"]]}
INTERVIEW
PYTHON3
CODECHEF
6,961
b5310be8ff0189c7e1d47d0a6709e52d
UNKNOWN
The Quark Codejam's number QC(n, m) represents the number of ways to partition a set of n things into m nonempty subsets. For example, there are seven ways to split a four-element set into two parts: {1, 2, 3} ∪ {4}, {1, 2, 4} ∪ {3}, {1, 3, 4} ∪ {2}, {2, 3, 4} ∪ {1}, {1, 2} ∪ {3, 4}, {1, 3} ∪ {2, 4}, {1, 4} ∪ {2, 3}. We can compute QC(n, m) using the recurrence, QC(n, m) = mQC(n − 1, m) + QC(n − 1, m − 1), for integers 1 < m < n. but your task is a somewhat different: given integers n and m, compute the parity of QC(n, m), i.e. QC(n, m) mod 2. Example : QC(4, 2) mod 2 = 1. Write a program that reads two positive integers n and m, computes QC(n, m) mod 2, and writes the result. -----Input----- The input begins with a single positive integer on a line by itself indicating the number of the cases. This line is followed by the input cases. The input consists two integers n and m separated by a space, with 1 ≤ m ≤ n ≤ 1000000000. -----Output----- For each test case, print the output. The output should be the integer S(n, m) mod 2. Sample Input 1 4 2 Sample Output 1
["for i in range(eval(input())):\n n,k=input().strip().split()\n n=int(n)\n k=int(k)\n print(int( ((n-k)&(int((k-1)/2)))==0))"]
{"inputs": [["1", "4 2"]], "outputs": [["1"]]}
INTERVIEW
PYTHON3
CODECHEF
127
2f1df25d7c2b5441edc1f4436ebbb497
UNKNOWN
Chef loves triangles. But the chef is poor at maths. Given three random lengths Chef wants to find if the three sides form a right-angled triangle or not. Can you help Chef in this endeavour? -----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, three Integers $A,B and C$ -----Output:----- For each test case, output in a single line "YES" if it is possible to form a triangle using the given numbers or "NO" if it is not possible to form a triangle. -----Constraints----- - $1 \leq T \leq 1000000$ - $0 \leq A,B,C \leq 100$ -----Sample Input:----- 2 3 4 5 1 3 4 -----Sample Output:----- YES NO -----EXPLANATION:----- 3,4,5 forms a right-angled triangle. 1, 3 and 4 does not form a right-angled triangle.
["# cook your dish here\ndef check(a,b,c):\n if (a==0) or (b==0) or (c==0):\n return \"NO\"\n else:\n i=3\n while(i>0):\n if (a*a)==(b*b)+(c*c):\n return \"YES\"\n else:\n t=a\n a=b\n b=c\n c=t\n i-=1\n return \"NO\"\ntry:\n for _ in range(int(input())):\n a,b,c=map(int,input().split())\n print(check(a,b,c))\nexcept:\n print(e)\n pass", "try:\n t = int(input())\n for i in range(t):\n a,b,c = map(int,input().split(\" \"))\n if a>0 and b>0 and c>0:\n if (a>=b) and (a>=c):\n if a**2 == b**2 + c**2:\n print(\"YES\")\n else:\n print(\"NO\")\n elif (b>=a) and (b>=c):\n if b**2 == a**2 + c**2:\n print(\"YES\")\n else:\n print(\"NO\")\n else: \n if c**2 == a**2 + b**2:\n print(\"YES\")\n else:\n print(\"NO\")\n else:\n print(\"NO\")\nexcept:\n pass", "for _ in range(int(input())):\r\n abc = sorted([int(x) for x in input().split()])\r\n if 0 in abc:\r\n print(\"NO\")\r\n else:\r\n if abc[-1] * abc[-1] == abc[0] * abc[0] + abc[1] * abc[1]:\r\n print(\"YES\")\r\n else:\r\n print(\"NO\") \r\n", "# cook your dish here\nfor _ in range(int(input())):\n num=list(map(int,input().split()))\n A,B,C=sorted(num)\n if(A>=1 and B>=1 and C>=1):\n if(A**2+B**2)==C**2:\n print(\"YES\")\n else:\n print(\"NO\")\n else:\n print(\"NO\")\n", "# cook your dish here\nT=int(input())\nfor _ in range(T):\n A,B,C=map(int,input().split())\n if A**2+(B**2)==C**2 :\n if A+B>C:\n print(\"YES\")\n else:\n print(\"NO\")\n elif B**2+(C**2)==A**2 :\n if C+B>A:\n print(\"YES\")\n else:\n print(\"NO\")\n elif A**2+(C**2)==B**2 :\n if A+C>B:\n print(\"YES\")\n else:\n print(\"NO\")\n else:\n print(\"NO\")", "n = int(input())\r\n\r\nfor i in range(n):\r\n a,b,c = map(int, input().split())\r\n \r\n a2 = int(pow(a,2))\r\n b2 = int(pow(b,2))\r\n c2 = int(pow(c,2))\r\n \r\n if(a == 0 or b==0 or c==0):\r\n print(\"NO\")\r\n continue\r\n \r\n if(a2+b2 == c2):\r\n print(\"YES\")\r\n elif(c2+b2 == a2):\r\n print(\"YES\")\r\n elif(a2+c2 == b2):\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")", "for t in range(int(input())):\n l=sorted(list(map(int,input().split())))\n if ((l[0]**2) + (l[1]**2) == (l[2]**2)) and (l[0]+l[1]>=l[2]) and (l[0]>0) and (l[1]>0) and (l[2]>0):\n print(\"YES\")\n else:\n print(\"NO\")\n", "T=input()\r\nfor i in range(int(T)):\r\n l = list(map(int,input().split()))\r\n l.sort()\r\n if (l[2]==(l[1]**2+l[0]**2)**0.5) & (l[2]!=0) & (l[0]!=0) & (l[1]!=0): \r\n print(\"YES\")\r\n else:\r\n print(\"NO\") ", "for test_case in range(int(input())):\r\n l = sorted(list(map(int, input().split())))\r\n # print(l)\r\n \r\n x = l[0]**2\r\n y = l[1]**2 \r\n z = l[2]**2\r\n \r\n # print(x, y, z)\r\n if x != 0 and y != 0 and z != 0:\r\n if x + y == z:\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\n \r\n else:\r\n print(\"NO\")", "T= int(input())\r\nwhile(T>0):\r\n\ta,b,c=[int(x) for x in input().split()]\r\n\tif a+b>c and b+c> a and c+a>b:\r\n\t\tif a**2+ b**2 == c**2 or b**2+c**2 ==a**2 or c**2 + a**2 ==b**2:\r\n\t\t\tprint(\"YES\")\r\n\t\telse:\r\n\t\t\tprint(\"NO\")\r\n\telse:\r\n\t\tprint(\"NO\")\r\n\tT-=1", "# cook your dish here\nt=int(input())\nwhile(t):\n t=t-1\n n=list(map(int,input().split()))\n n.sort()\n x=n[0]**2+n[1]**2\n if (x==n[2]**2) and (n[0]+n[1]>n[2]) and (n[0]*n[1]*n[2])!=0:\n print(\"YES\")\n else:\n print(\"NO\")", "# cook your dish here\nt=int(input())\nwhile(t):\n a,b,c=map(int,input().split())\n k=max(a,b,c)\n p=min(a,b,c)\n l=(a+b+c)-k-p\n if k**2==p**2+l**2:\n if k+p>l and k+l>p and l+p>k and k-p<l and k-l<p and l-p<k:\n print(\"YES\")\n else:\n print(\"NO\")\n else:\n print(\"NO\")\n t=t-1", "# cook your dish here\nt=int(input())\nfor i in range(0,t):\n x = list(map(int, input().split()))\n x.sort()\n if((x[2]**2)==(x[0]**2+x[1]**2) and (x[0]!=0)):\n print(\"YES\")\n else:\n print(\"NO\")", "t = int(input())\r\nfor i in range(t):\r\n l = list(map(int, input().split()))\r\n l.sort()\r\n if l[0]==0:\r\n s = 'NO'\r\n else :\r\n for d in range(3):\r\n n = l[d]**2\r\n k = l[d-1]**2\r\n j = l[d-2]**2\r\n if n == k + j:\r\n s = 'YES'\r\n break\r\n else :\r\n s = 'NO'\r\n print(s)", "# cook your dish here\nfor _ in range(int(input())):\n a ,b, c = map(int,input().split())\n if(a == 0 or b== 0 or c==0):\n print(\"NO\")\n continue\n if(a * a + b * b == c*c):\n print(\"YES\")\n elif(a*a + c*c == b*b):\n print(\"YES\")\n elif(b*b + c*c == a*a):\n print(\"YES\")\n else:\n print(\"NO\")", "for __ in range(int(input())):\n a = list(map(int, input().split()))\n \n a.sort()\n if a[0] == 0 or a[1] == 0 or a[2] == 0:\n print(\"NO\")\n elif (a[0]**2 + a[1]**2) == a[2]**2:\n print(\"YES\")\n else:\n print(\"NO\")", "for i in range(int(input())):\r\n a,b,c=[int(x) for x in input().split()]\r\n if a>0 and b>0 and c>0:\r\n if a**2+b**2==c**2:\r\n print(\"YES\")\r\n elif b**2+c**2==a**2:\r\n print(\"YES\")\r\n elif a**2+c**2==b**2:\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\n else:\r\n print(\"NO\")\r\n \r\n", "'''\r\nName : Jaymeet Mehta\r\ncodechef id :mj_13\r\nProblem : Triangle love part 2 \r\n'''\r\nfrom sys import stdin,stdout\r\ndef calc(a,b,c):\r\n if a**2+b**2==c**2:\r\n return True\r\n if b**2+c**2==a**2:\r\n return True\r\n if a**2+c**2==b**2:\r\n return True\r\n return False\r\ntest=int(stdin.readline())\r\nfor _ in range(test):\r\n a,b,c = map(int,stdin.readline().split())\r\n if a==0 or b==0 or c==0:\r\n print(\"NO\")\r\n continue\r\n print(\"YES\") if calc(a,b,c) else print(\"NO\")", "for __ in range(int(input())):\n a = list(map(int, input().split()))\n \n a.sort()\n if a[0] == 0 or a[1] == 0 or a[2] == 0:\n print(\"NO\")\n elif (a[0]**2 + a[1]**2) == a[2]**2:\n print(\"YES\")\n else:\n print(\"NO\")", "# cook your dish here\ntc=int((input()))\nfor _ in range(tc):\n n=list(map(int,input().split()))\n n.sort(reverse=True)\n if (n[0]<=0 or n[1]<=0 or n[2]<=0):\n print(\"NO\")\n elif n[0]*n[0] == ((n[1]*n[1])+(n[2]*n[2])):\n print(\"YES\")\n else:\n print(\"NO\")", "from math import sqrt\r\n\r\nfor _ in range(int(input())):\r\n a, b, c = map(int, input().split())\r\n \r\n if a == 0 or b == 0 or c == 0:\r\n print('NO')\r\n continue\r\n \r\n x = a ** 2 + b ** 2 == c ** 2\r\n y = a ** 2 + c ** 2 == b ** 2\r\n z = b ** 2 + c ** 2 == a ** 2\r\n \r\n print('YES' if x or y or z else 'NO')", "#!/usr/bin/env python3\r\n# coding: utf-8\r\n#Last Modified: 23/Feb/20 12:23:37 PM\r\n\r\n\r\nimport sys\r\n\r\n\r\ndef main():\r\n def checkValidity(a, b, c): \r\n if (a + b <= c) or (a + c <= b) or (b + c <= a) : \r\n return False\r\n else: \r\n return True \r\n def checkrt(a, b, c):\r\n if a**2 + b**2 == c**2 or a**2+c**2==b**2 or b**2+c**2==a**2:\r\n return True\r\n return False\r\n for tc in range(int(input())):\r\n a, b, c=get_ints()\r\n if checkValidity(a, b, c):\r\n if checkrt(a, b, c):\r\n print('YES')\r\n else:\r\n print('NO')\r\n else:\r\n print('NO')\r\n\r\n\r\nget_array = lambda: list(map(int, sys.stdin.readline().split()))\r\n\r\n\r\nget_ints = lambda: list(map(int, sys.stdin.readline().split()))\r\n\r\n\r\ninput = lambda: sys.stdin.readline().strip()\r\n\r\n\r\nmain()\r\n", "# cook your dish here\nt = int(input())\nfor _ in range (t):\n l = [int(x) for x in input().strip().split(\" \")]\n l.sort()\n (a,b,c) = l \n if(a>0 and b>0 and c>0 and a*a + b*b == c*c):\n print(\"YES\")\n else:\n print(\"NO\")", "T = int(input())\r\nfor _ in range(T):\r\n A, B, C = map(int, input().split())\r\n ans = \"NO\"\r\n a_s,bs,cs = A*A,B*B,C*C\r\n if (a_s==bs+cs or bs==a_s+cs or cs==a_s+bs) and A>0 and B>0 and C>0:\r\n ans = \"YES\"\r\n print(ans)", "for _ in range(int(input())):\n int_num = list(map(int,input().split()))\n a, b, c = sorted(int_num)\n if (a + b <= c) or (a + c <= b) or (b + c <= a) or (c <= a or c <= b):\n print('NO')\n else: \n if a**2 + b**2 == c**2:\n print('YES')\n else:\n print('NO')"]
{"inputs": [["2", "3 4 5", "1 3 4"]], "outputs": [["YES", "NO"]]}
INTERVIEW
PYTHON3
CODECHEF
9,479
30d43220824883612b45d9b31a6d5783
UNKNOWN
Increasing COVID cases have created panic amongst the people of Chefland, so the government is starting to push for production of a vaccine. It has to report to the media about the exact date when vaccines will be available. There are two companies which are producing vaccines for COVID. Company A starts producing vaccines on day $D_1$ and it can produce $V_1$ vaccines per day. Company B starts producing vaccines on day $D_2$ and it can produce $V_2$ vaccines per day. Currently, we are on day $1$. We need a total of $P$ vaccines. How many days are required to produce enough vaccines? Formally, find the smallest integer $d$ such that we have enough vaccines at the end of the day $d$. -----Input----- - The first and only line of the input contains five space-separated integers $D_1$, $V_1$, $D_2$, $V_2$ and $P$. -----Output----- Print a single line containing one integer ― the smallest required number of days. -----Constraints----- - $1 \le D_1, V_1, D_2, V_2 \le 100$ - $1 \le P \le 1,000$ -----Subtasks----- Subtask #1 (30 points): $D_1 = D_2$ Subtask #2 (70 points): original constraints -----Example Input 1----- 1 2 1 3 14 -----Example Output 1----- 3 -----Explanation----- Since $D_1 = D_2 = 1$, we can produce $V_1 + V_2 = 5$ vaccines per day. In $3$ days, we produce $15$ vaccines, which satisfies our requirement of $14$ vaccines. -----Example Input 2----- 5 4 2 10 100 -----Example Output 2----- 9 -----Explanation----- There are $0$ vaccines produced on the first day, $10$ vaccines produced on each of days $2$, $3$ and $4$, and $14$ vaccines produced on the fifth and each subsequent day. In $9$ days, it makes a total of $0 + 10 \cdot 3 + 14 \cdot 5 = 100$ vaccines.
["# cook your dish here\ntry:\n d1,v1,d2,v2,p=map(int, input().split())\n total=0\n while p>0:\n total+=1\n if total>=d1:\n p=p-v1\n if total>=d2:\n p=p-v2\n print(total) \nexcept:\n pass", "d1,v1,d2,v2,p=list(map(int,input().split()))\ncheck=0\nif d1==d2:\n check=1\n start=d1-1\n v0=(v1+v2)\n if p%v0==0:\n print((p//v0)+start)\n else:\n print((p//v0)+1+start)\nelif d2<d1:\n con=d2\n pon=d1\n von=v2\nelse:\n con=d1\n pon=d2\n von=v1\nif check!=1:\n starting_day=con-1\n second=pon-con\n third=(second*von)\n if third>p:\n if p%von==0:\n print((p//von)+starting_day)\n else:\n print((p//von)+1+starting_day)\n \n elif third==p:\n print(second+starting_day)\n else:\n v0=(v2+v1)\n if (p-third)%v0==0:\n print(((p-third)//v0)+second+starting_day)\n else:\n print(((p-third)//v0)+second+starting_day+1)\n", "d1,v1,d2,v2,p=list(map(int,input().split()))\ncheck=0\nif d1==d2:\n check=1\n start=d1-1\n v0=(v1+v2)\n if p%v0==0:\n print((p//v0)+start)\n else:\n print((p//v0)+1+start)\nelif d2<d1:\n con=d2\n pon=d1\n von=v2\nelse:\n con=d1\n pon=d2\n von=v1\nif check!=1:\n starting_day=con-1\n second=pon-con\n third=(second*von)\n if third>p:\n if p%von==0:\n print((p//von)+starting_day)\n else:\n print((p//von)+1+starting_day)\n \n elif third==p:\n print(second+starting_day)\n else:\n v0=(v2+v1)\n if (p-third)%v0==0:\n print(((p-third)//v0)+second+starting_day)\n else:\n print(((p-third)//v0)+second+starting_day+1)\n", "d1,v1,d2,v2,p=list(map(int,input().split()))\ncheck=0\nif d1==d2:\n check=1\n start=d1-1\n v0=(v1+v2)\n if p%v0==0:\n print((p//v0)+start)\n else:\n print((p//v0)+1+start)\nelif d2<d1:\n con=d2\n pon=d1\n von=v2\nelse:\n con=d1\n pon=d2\n von=v1\nif check!=1:\n starting_day=con-1\n second=pon-con\n third=(second*von)\n if third>p:\n print((p//von)+1+starting_day)\n elif third==p:\n print(second+starting_day)\n else:\n v0=(v2+v1)\n if (p-third)%v0==0:\n print(((p-third)//v0)+second+starting_day)\n else:\n print(((p-third)//v0)+second+starting_day+1)\n", "d1,v1,d2,v2,p=list(map(int,input().split()))\nif d1==d2:\n check=0\n start=d1-1\n v0=(v1+v2)\n if p%v0==0:\n print((p//v0)+start)\n else:\n print((p//v0)+1+start)\nelif d2<d1:\n con=d2\n pon=d1\n von=v2\nelse:\n con=d1\n pon=d2\n von=v1\nif check!=0:\n starting_day=con-1\n second=pon-con\n third=(second*von)\n if third>p:\n print((p//von)+1+starting_day)\n elif third==p:\n print(second+starting_day)\n else:\n print(((p-third)//(v2+v1))+second+starting_day)\n\n", "\nd1,v1,d2,v2,vaccine = map(int,input().split())\nday = 1\nsum = 0\nwhile sum<vaccine:\n if day==d1:\n sum+=v1\n d1+=1 \n if day==d2:\n sum+=v2\n d2+=1\n if sum>=vaccine:\n break\n day+=1\nprint(day)", "\nd1,v1,d2,v2,vaccine = map(int,input().split())\nday = 1\nsum = 0\nwhile sum<vaccine:\n if day==d1:\n sum+=v1\n d1+=1 \n if day==d2:\n sum+=v2\n d2+=1\n if sum>=vaccine:\n break\n day+=1\nprint(day)", "# cook your dish here\nd1,v1,d2,v2,p = list(map(int,input().split()))\nstore=0\nvac=0\nsmall=0\ni=0\n\nif d1==d2:\n store = p//(v1+v2) \n if store*(v1+v2)<p:\n store+=1\n if d1 >1:\n store+=(d1-1)\n print(store)\nelse:\n diff = abs(d1-d2)\n if d1<d2:\n small = d1\n vac = v1\n else:\n small = d2\n vac =v2\n \n # for i in range(diff):\n # store +=vac\n # if \n # print(store)\n \n while store<p:\n if i >= diff :\n store+= (v1+v2)\n else:\n store+=vac\n i+=1\n \n print(i+small-1)\n \n \n\n \n", "# cook your dish here\nd1,v1,d2,v2,p = list(map(int,input().split()))\n\nif d1==d2:\n store = p//(v1+v2) \n if store*(v1+v2)<p:\n store+=1\n if d1 >1:\n store+=(d1-1)\n print(store)\n# else:\n# diff = abs(d1-d2)\n# if d1<d2:\n# small = d1\n# else:\n# small = d2\n \n# for \n\n \n", "# cook your dish here\nday = 1\nd1,v1,d2,v2,p = map(int,input().split())\nd1 = abs(d1)\nv1 = abs(v1)\nd2 = abs(d2)\nv2 = abs(v2)\np = abs(p)\nvaccines = 0\nwhile(1):\n if(day >= d1):\n vaccines += v1\n if(day >= d2):\n vaccines += v2\n if(vaccines >= p):\n break\n day += 1\nprint(day)", "day = 1\nd1,v1,d2,v2,p = map(int,input().split())\nd1 = abs(d1)\nv1 = abs(v1)\nd2 = abs(d2)\nv2 = abs(v2)\np = abs(p)\nvaccines = 0\nwhile(1):\n if(day >= d1):\n vaccines += v1\n if(day >= d2):\n vaccines += v2\n if(vaccines >= p):\n break\n day += 1\nprint(day)", "vacc=0\nday=0\nd1,v1,d2,v2,p=list(map(int,input().split()))\nfor i in range(1,1000):\n if i>=d1:\n vacc=vacc+v1\n if i>=d2:\n vacc=vacc+v2\n day=day+1\n if vacc>=p:\n break\nprint(day)\n \n", "try:\n a=list(map(int,input().split()))\n d1=a[0]\n v1=a[1]\n d2=a[2]\n v2=a[3]\n p=a[4]\n vacc=0\n day=0\n for i in range(1,1000):\n if i>=d1:\n vacc=vacc+v1\n if i>=d2:\n vacc=vacc+v2\n day=day+1\n if vacc>=p:\n break\n print(day)\nexcept:\n pass", "try:\n a=list(map(int,input().split()))\n d1=a[0]\n v1=a[1]\n d2=a[2]\n v2=a[3]\n p=a[4]\n vacc=0\n day=0\n for i in range(1,1000):\n if i>=d1:\n vacc=vacc+v1\n if i>=d2:\n vacc=vacc+v2\n day=day+1\n if vacc>=p:\n break\n print(day)\nexcept:\n pass", "try:\n a = list(map(int,input().split()))\n d1 = a[0]\n v1 = a[1]\n d2 = a[2]\n v2 = a[3]\n p =a[4]\n vacc = 0\n day = 0\n for i in range(1,1000):\n if i >= d1:\n vacc=vacc+v1\n if i>= d2:\n vacc = vacc+v2\n day = day+1\n if vacc >= p:\n break\n print(day)\nexcept:\n pass", "try:\n a=list(map(int,input().split()))\n d1=a[0]\n v1=a[1]\n d2=a[2]\n v2=a[3]\n p=a[4]\n vacc=0\n day=0\n if d1==d2:\n print(v2)\n else:\n for i in range(1,1000):\n if i>=d1:\n vacc=vacc+v1\n if i>=d2:\n vacc=vacc+v2\n day=day+1\n if vacc>=p:\n break\n print(day)\nexcept:\n pass", "# cook your dish here\nd1,v1,d2,v2,n=map(int,input().split())\nl,i,j,day=0,1,1,0\nwhile(l<n):\n if(i>=d1):\n l+=v1\n if(j>=d2):\n l+=v2\n i+=1\n j+=1\n day+=1\nprint(day)", "d1,v1,d2,v2,p=input().split()\nd1=int(d1)\nv1=int(v1)\nd2=int(d2)\nv2=int(v2)\np=int(p)\nif d1==d2:\n if p%(v1+v2)==0:\n rd=int(p/(v1+v2))+d1-1\n else:\n rd=int(p//(v1+v2))+d1\nelif d1<d2:\n dd=d2-d1\n vp=v1*dd\n if p<=dd:\n if p%v1==0:\n rd=int(p/v1)+d1-1\n else:\n rd=int(p//v1)+d1\n else:\n vl=p-vp\n if vl%(v1+v2)==0:\n rd=int(vl/(v1+v2))+d2-1\n else:\n rd=int(vl//(v1+v2))+d2\nelse:\n dd=d1-d2\n vp=v2*dd\n if p<=vp:\n if p%v2==0:\n rd=int(p/v2)+d2-1\n else:\n rd=int(p//v2)+d2\n else:\n vl=p-vp\n if vl%(v1+v2)==0:\n rd=int(vl/(v1+v2))+d1-1\n else:\n rd=int(vl//(v1+v2))+d1\nprint(rd)", "# cook your dish here\nimport math as m\nNUMBER=input().split()\nD1=int(NUMBER[0])\nV1=int(NUMBER[1])\nD2=int(NUMBER[2])\nV2=int(NUMBER[3])\nP=int(NUMBER[4])\nnumber_vaccine=0\ncount=0\nif D1>D2:\n print(D1-1+m.ceil((P-V2*abs(D1-D2))/(V1+V2)))\nelif D1==D2:\n count=D1-1\n print(D1+m.ceil(P/(V1+V2))-1)\nelse:\n print(D2-1++m.ceil((P-V1*abs(D1-D2))/(V1+V2)))", "# cook your dish here\nNUMBER=input().split()\nD1=int(NUMBER[0])\nV1=int(NUMBER[1])\nD2=int(NUMBER[2])\nV2=int(NUMBER[3])\nP=int(NUMBER[4])\nnumber_vaccine=0\ncount=0\nif D1>D2:\n count=D2-1\n number_vaccine=V2*(D1-D2)\n count+=D1-D2\n while(number_vaccine<P):\n number_vaccine+=V1+V2\n count+=1\n print(count)\nelif D1==D2:\n count=D1-1\n while(number_vaccine<P):\n number_vaccine+=V1+V2\n count+=1 \n print(count)\nelse:\n count=D1-1\n number_vaccine=V1*(D2-D1)\n count+=D2-D1\n while(number_vaccine<P):\n number_vaccine+=V1+V2\n count+=1\n print(count)", "# cook your dish here\nNUMBER=input().split()\nD1=int(NUMBER[0])\nV1=int(NUMBER[1])\nD2=int(NUMBER[2])\nV2=int(NUMBER[3])\nP=int(NUMBER[4])\nnumber_vaccine=0\ncount=0\nif D1>D2:\n count=D2-1\n number_vaccine=V2*(D1-D2)\n count+=D1-D2\n while(number_vaccine<P):\n number_vaccine+=V1+V2\n count+=1\n print(count)\nelif D1==D2:\n count=D1-1\n number_vaccine=V1+V2\n count+=1\n while(number_vaccine<P):\n number_vaccine+=V1+V2\n count+=1 \n print(count)\nelse:\n count=D1-1\n number_vaccine=V1*(D2-D1)\n count+=D2-D1\n while(number_vaccine<P):\n number_vaccine+=V1+V2\n count+=1\n print(count)"]
{"inputs": [["1 2 1 3 14"]], "outputs": [["3"]]}
INTERVIEW
PYTHON3
CODECHEF
7,965
41b06164f004e63b4e1fb31736883351
UNKNOWN
“Jesse, you asked me if I was in the meth business, or the money business… Neither. I’m in the empire business.” Walter’s sold his stack in Gray Matter Technologies, a company which he deserved half a credit, for peanuts. Now this company is worth a billion dollar company. Walter wants to get it's shares to have his Empire Business back and he founds an opportunity. There are $N$ persons having shares $A_1, A_2, A_3, … A_N$ in this company. Walter can buy these shares with their minimum Sold Values. Sold Values of a person's share $ i $ $(1 \leq i \leq N) $ with another person's share $ j $ $ (1 \leq j \leq N) $ is equal to $ A_j+|i-j| $. So, a person's share can have $ N $ possible sold values and Walter has to find minimum sold value among them for each person. Since Walter has to run his meth business also he asks you to find minimum sold value for each person. -----Input:----- - First line will contain $T$, number of test cases. Then the testcases follow. - The First line of each test case contains a integer $N$. - The Second line of each test case contains $N$ space integers namely $A_1,A_2,…A_N$. -----Output:----- For each test case, output in single line $N$ space integers denoting minimum sold value for each person. -----Constraints----- - $1 \leq T \leq 10^5$ - $1 \leq N \leq 2*10^6 $ - $1 \leq A_i \leq 10^9 $ Sum of $N$ over all test cases will not exceed $2*10^6$. -----Sample Input:----- 2 5 6 5 5 5 2 5 1 2 3 4 5 -----Sample Output:----- 6 5 4 3 2 1 2 3 4 5 -----Explanation----- For first case: - Sold value for index $1$: $6,6,7,8,6$ - Sold value for index $2$: $7,5,6,7,5$ - Sold value for index $3$: $8,6,5,6,4$ - Sold value for index $4$: $9,7,6,5,3$ - Sold value for index $5$: $10,8,7,6,2$ Minimum sold value for each index will be $6,5,4,3,2$.
["# cook your dish here\nT=int(input())\nfor _ in range(T):\n n=int(input())\n arr=list(map(int,input().split()))\n left=[-1 for i in range(n)]\n right=[-1 for i in range(n)]\n min1=float(\"inf\")\n for i in range(n):\n min1=min(arr[i],min1+1)\n left[i]=min1\n min1=float(\"inf\")\n for i in range(n-1,-1,-1):\n min1=min(arr[i],min1+1)\n right[i]=min1\n for i in range(n):\n print(min(left[i],right[i]),end=\" \")\n print(\"\",end=\"\\n\")", "# cook your dish here\nt=int(input())\nwhile(t!=0):\n t-=1\n n=int(input())\n fg=list(map(int,input().split()))\n for i in range(1,n):\n fg[i]=min((fg[i-1]+1),fg[i])\n for j in range(n-2,-1,-1):\n fg[j]=min((fg[j+1]+1),fg[j])\n print(*fg)\n", "t=int(input())\nfor _ in range(t):\n n=int(input())\n l=list(map(int,input().split()))[:n]\n for i in range(1,n):\n l[i]=min((l[i-1]+1),l[i])\n for j in range(n-2,-1,-1):\n l[j]=min((l[j+1]+1),l[j])\n print(*l)", "T = int(input())\nfor _ in range(T):\n N = int(input())\n A = list(map(int, input().split()))\n Llist = [A[0]]\n Rlist = [A[N-1]]\n for i in range(1, N):\n Llist.append(min(Llist[-1]+1, A[i]))\n Rlist.append(min(Rlist[-1]+1, A[N-1-i]))\n print(*[min(Llist[i], Rlist[N-1-i]) for i in range(N)])\n", "for _ in range(int(input())):\n n=int(input())\n l=list(map(int,input().split()))\n left=[]\n mini=float('inf')\n for i in range(n):\n c=min(mini+1,l[i])\n left.append(c)\n mini=c\n mini=float('inf')\n for i in range(n-1,-1,-1):\n left[i]=min(mini+1,left[i])\n mini=min(mini+1,l[i])\n print(*left)", "T=int(input())\n\nfor _ in range(T):\n n=int(input())\n A=list(map(int,input().split()))\n for i in range(1,n):\n A[i]=min(A[i],A[i-1]+1)\n\n for i in range(n-2,-1,-1):\n A[i]=min(A[i],A[i+1]+1)\n print(*A)", "t = int(input())\nfor _ in range(t):\n n = int(input())\n arr = list(map(int, input().split()))\n arr_modified = [-1 for _ in range(n)]\n for i in range(n):\n arr_modified[i] = arr[i] + i\n\n # calculate minRights\n minRights = [arr_modified[-1] for _ in range(n)]\n for i in range(n-2, -1, -1):\n minRights[i] = min(arr_modified[i], minRights[i+1])\n # sold values\n minLeft = float('inf')\n soldValues = [-1 for _ in range(n)]\n for i in range(n):\n soldValues[i] = min(minLeft, minRights[i] - i)\n minLeft = min(minLeft + 1, arr[i] + 1)\n print(' '.join(str(x) for x in soldValues))", "for _ in range(int(input())):\n n = int(input())\n *arr, = map(int,input().split())\n ans = [int(1e9)+1]*n\n ans[0] = arr[0]\n for i in range(1,n):\n ans[i] = min(arr[i],ans[i],ans[i-1]+1)\n for i in range(n-1)[::-1]:\n ans[i] = min(arr[i],ans[i],ans[i+1]+1)\n print(*ans)", "t=int(input())\nfor i in range(t):\n n=int(input())\n a=list(map(int,input().split(\" \")))\n s=[]\n p=[]\n p.append(a[0])\n for i in range(1,n):\n p.append(min(p[i-1]+1,a[i]))\n s.append(a[n-1])\n j=n-2\n l=0\n while(j>=0):\n s.append(min(s[l]+1,a[j]))\n j=j-1\n l=l+1\n t=s[::-1]\n for k in range(n):\n print(min(t[k],p[k]),end=\" \")\n print(\"\")\n \n \n \n \n ", "for _ in range(int(input())):\n n = int(input())\n *arr, = map(int,input().split())\n ans = [int(1e9)+1]*n\n ans[0] = arr[0]\n for i in range(1,n):\n ans[i] = min(arr[i],ans[i],ans[i-1]+1)\n for i in range(n-2,-1,-1):\n ans[i] = min(arr[i],ans[i],ans[i+1]+1)\n print(*ans)", "# cook your dish here\nfor _ in range(int(input())):\n n = int(input())\n arr = list(map(int, input().split(' ')))\n for i in range(1,n):\n arr[i] = min(arr[i], arr[i-1] + 1)\n for j in range(n-2, -1, -1):\n arr[j] = min(arr[j], arr[j+1] + 1)\n print(*arr)", "from itertools import accumulate, count\nfrom operator import add, sub\n\nf = lambda x: accumulate(list(map(sub, x, count())), min)\n\nfor s in [*open(0)][2::2]:\n a = *list(map(int, s.split())),\n n = len(a)\n b = f(a)\n c = reversed([*f(reversed(a))])\n print(*(list(map(min, list(map(add, b, count())), list(map(sub, c, count(1 - n)))))))\n", "from itertools import accumulate, count\nfrom operator import add, sub\n\nf = lambda x: accumulate(list(map(sub, x, count())), min)\n\nfor s in [*open(0)][2::2]:\n a = *list(map(int, s.split())),\n n = len(a)\n b = f(a)\n c = reversed([*f(reversed(a))])\n print(*(list(map(min, list(map(add, b, count())), list(map(sub, c, count(1 - n)))))))\n", "from itertools import accumulate, count\nfrom operator import sub\n\nf = lambda x: accumulate(list(map(sub, x, count())), min)\n\nfor s in [*open(0)][2::2]:\n a = *list(map(int, s.split())),\n n = len(a)\n b = f(a)\n c = reversed([*f(reversed(a))])\n print(*(min(x + i, y + n + ~i) for i, x, y in zip(count(), b, c)))\n", "from itertools import accumulate, count\nfrom operator import sub\n\nf = lambda x: accumulate(list(map(sub, x, count())), min)\n\nfor s in [*open(0)][2::2]:\n a = *list(map(int, s.split())),\n n = len(a)\n b = f(a)\n c = reversed([*f(reversed(a))])\n print(*(min(x + i, y + n + ~i) for i, x, y in zip(count(), b, c)))\n", "# cook your dish here\nT=int(input())\n\nfor _ in range(T):\n n=int(input())\n A=list(map(int,input().split()))\n for i in range(1,n):\n A[i]=min(A[i],A[i-1]+1)\n\n for i in range(n-2,-1,-1):\n A[i]=min(A[i],A[i+1]+1)\n print(*A)", "t=int(input())\nfor _ in range(t):\n n=int(input())\n ls=list(map(int,input().split()))\n ldp=ls.copy()\n counter=-1\n for i in ldp:\n counter+=1\n if counter==0:\n continue\n ldp[counter]=min(ldp[counter],ldp[counter-1]+1)\n # print(ldp)\n rdp=ldp.copy()\n for j in range(1,n):\n rdp[n-j-1]=min(rdp[n-j-1],rdp[n-j]+1)\n print(*rdp)\n", "# cook your dish here\nt=int(input())\nfor t1 in range(0,t):\n n=int(input())\n a=list(map(int,input().split()))\n left=[]\n right=[]\n for i in range(0,n):\n if i==0:\n left.append((a[i],i))\n else:\n if a[i]< (left[-1][0]+left[-1][1]+1):\n left.append((a[i],0))\n else:\n left.append((left[-1][0],left[-1][1]+1))\n\n right=[]\n for i in range(n-1,-1,-1):\n if i==n-1:\n right.append((a[i],0))\n else:\n if a[i]< (right[-1][0]+right[-1][1]+1):\n right.append((a[i],0))\n else:\n right.append((right[-1][0],right[-1][1]+1))\n ans=[]\n right=right[::-1]\n #print(left)\n #print(right)\n for i in range(0,n):\n ans.append(min(left[i][0]+left[i][1], right[i][0]+right[i][1]))\n print(*ans)", "# cook your dish here\nt = int(input())\nfor _ in range(t):\n n = int(input())\n l = list(map(int,input().split()))\n right = l\n lmin = l[0]\n left = l\n rmin = l[n-1]\n for i in range(0,n):\n left[i] = min(lmin,l[i])\n lmin = left[i]+1\n i = n-1\n while i >= 0:\n right[i] = min(rmin,l[i])\n rmin = right[i] + 1\n i -= 1\n s = \"\"\n for i in range(n):\n s += str(min(left[i],right[i]))+\" \"\n print(s.strip())\n", "# cook your dish here\nT=int(input())\nfor _ in range(T):\n n=int(input())\n A=list(map(int,input().split()))\n for i in range(1,n):\n A[i]=min(A[i],A[i-1]+1)\n for i in range(n-2,-1,-1):\n A[i]=min(A[i],A[i+1]+1)\n print(*A)", "for _ in range(int(input())):\n n = int(input())\n arr = list(map(int,input().split()))\n for i in range(1,n):arr[i] = min(arr[i],arr[i-1]+1)\n for i in range(n-2,-1,-1):arr[i] = min(arr[i],arr[i+1]+1)\n print(*arr)", "t=int(input())\nfor t1 in range(0,t):\n n=int(input())\n a=list(map(int,input().split()))\n left=[]\n right=[]\n for i in range(0,n):\n if i==0:\n left.append((a[i],i))\n else:\n if a[i]< (left[-1][0]+left[-1][1]+1):\n left.append((a[i],0))\n else:\n left.append((left[-1][0],left[-1][1]+1))\n\n right=[]\n for i in range(n-1,-1,-1):\n if i==n-1:\n right.append((a[i],0))\n else:\n if a[i]< (right[-1][0]+right[-1][1]+1):\n right.append((a[i],0))\n else:\n right.append((right[-1][0],right[-1][1]+1))\n \n right=right[::-1]\n #print(left)\n #print(right)\n final1=[]\n for i in range(0,n):\n final1.append(min(left[i][0]+left[i][1],a[i]))\n final2=[]\n for i in range(0,n):\n final2.append(min(right[i][0]+right[i][1],a[i]))\n\n ans=[]\n for i in range(0,n):\n ans.append(min(final1[i],final2[i]))\n print(*ans)\n\n '''l=a[::]\n for i in range(1,n):\n a[i]=min(a[i],a[i-1]+1)\n\n for i in range(n-2,-1,-1):\n a[i]=min(a[i+1]+1,a[i])\n\n if a!=ans:\n print(l)\n print(a)\n #print(left)\n #print(right)\n print(ans)\n print()\n print(a)\n print()\n for i in range(1,n):\n a[i]=min(a[i],a[i-1]+1)\n\n for i in range(n-2,-1,-1):\n a[i]=min(a[i+1]+1,a[i])\n print(*a)'''"]
{"inputs": [["2", "5", "6 5 5 5 2", "5", "1 2 3 4 5"]], "outputs": [["6 5 4 3 2", "1 2 3 4 5"]]}
INTERVIEW
PYTHON3
CODECHEF
8,299
313a01dcc6fcf4ea9a92213b42749c9c
UNKNOWN
The chef is trying to solve some pattern problems, Chef wants your help to code it. Chef has one number K to form new pattern. Help the chef to code this pattern problem. -----Input:----- - First line will contain $T$, number of testcases. Then the testcases follow. - Each testcase contains of a single line of input, one integer $K$. -----Output:----- For each testcase, output as pattern. -----Constraints----- - $1 \leq T \leq 100$ - $1 \leq K \leq 100$ -----Sample Input:----- 2 2 4 -----Sample Output:----- 2 12 012 12 2 4 34 234 1234 01234 1234 234 34 4 -----EXPLANATION:----- No need, else pattern can be decode easily.
["# cook your dish here\nimport copy\nfor _ in range(int(input())):\n k=int(input())\n c=[]\n d=[]\n start=0\n\n while True:\n c=[]\n for i in range(start):\n c.append(\" \")\n for i in range(start,k+1):\n c.append(str(i))\n start+=1\n d.append(c)\n\n if start>k:\n break\n\n e=copy.copy(d[1:])\n d.reverse()\n d=d+e\n ##print(d)\n for i in range(len(d)):\n print(''.join(d[i]))\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\n\nabc=\"abcdefghijklmnopqrstuvwxyz\"\n\npi=3.141592653589793238\n\n\n\n\nt = int(input())\nfor _ in range(t):\n k = int(input())\n k_buf = k*1\n n_lines = k + 1\n for i in range(n_lines):\n buf = \" \"*k\n for j in range(k,k_buf+1):\n buf=buf+str(j)\n k = k - 1\n print(buf)\n for i in range(1,k_buf+1):\n buf=\" \"*i\n for j in range(i,k_buf+1):\n buf = buf+str(j)\n print(buf)\n \n \n \n", "# cook your dish here\nfor u in range(int(input())):\n n=int(input())\n l=[]\n x=0\n f=[]\n for i in range(n+1):\n f.append(' ')\n for i in range(n+1):\n f=[]\n for i in range(n+1):\n f.append(' ')\n for j in range(x,n+1):\n f[j]=str(j)\n x+=1\n l.append(f)\n d=l[1:][::-1]\n for i in d:\n print(''.join(i))\n for i in l:\n print(''.join(i))\n", "# cook your dish here\nfor _ in range(int(input())):\n\tn = int(input())\n\tflag = False\n\ts = n\n\tfor i in range(2*n+1):\n\t\tif s>=0:\n\t\t\tfor j in range(s):\n\t\t\t\tprint(\" \",end=\"\")\n\t\t\tfor j in range(n+1-s):\n\t\t\t\tprint(j+s,end=\"\")\n\t\telse:\t\t\t\n\t\t\tfor j in range(abs(s)):\n\t\t\t\tprint(\" \",end=\"\")\n\t\t\tfor j in range(n+1-abs(s)):\n\t\t\t\tprint(j+abs(s),end=\"\")\t\t\n\t\tprint()\t\n\t\ts-=1", "for i in range(int(input())):\r\n n = int(input())\r\n\r\n l = [' '] * (n+1)\r\n l[-1] = n\r\n\r\n print(*l, sep='')\r\n\r\n for i in range(n-1, -1, -1):\r\n l[i] = i\r\n print(*l, sep='')\r\n\r\n for i in range(n + 1):\r\n l[i] = ' '\r\n print(*l, sep='')\r\n"]
{"inputs": [["2", "2", "4"]], "outputs": [["2", "12", "012", "12", "2", "4", "34", "234", "1234", "01234", "1234", "234", "34", "4"]]}
INTERVIEW
PYTHON3
CODECHEF
2,324
546ddda11baf23fe3c14eec5ea108741
UNKNOWN
The Fibonacci sequence is defined as F(n) = F(n-1) + F(n-2). You have developed two sequences of numbers. The first sequence that uses the bitwise XOR operation instead of the addition method is called the Xoronacci number. It is described as follows: X(n) = X(n-1) XOR X(n-2) The second sequence that uses the bitwise XNOR operation instead of the addition method is called the XNoronacci number. It is described as follows: E(n) = E(n-1) XNOR E(n-2) The first and second numbers of the sequence are as follows: X(1) = E(1) = a X(2) = E(2) = b Your task is to determine the value of max(X(n),E(n)), where n is the n th term of the Xoronacci and XNoronacci sequence. -----Input:----- The first line consists of a single integer T denoting the number of test cases. The first and the only line of each test case consists of three space separated integers a, b and n. -----Output:----- For each test case print a single integer max(X(n),E(n)). -----Constraints----- - $1 \leq T \leq 1000$ - $2 \leq a,b,n \leq 1000000000000$ -----Sample Input:----- 1 3 4 2 -----Sample Output:----- 4 -----EXPLANATION:----- Xoronacci Sequence : 3 4 7 ……. XNoronacci Sequence : 3 4 0 ……. Here n = 2. Hence max(X(2),E(2)) = 4
["# Python3 program to find XNOR\n# of two numbers\nimport math\n\n\ndef swap(a, b):\n temp = a\n a = b\n b = temp\n\n\n# log(n) solution\ndef xnor(a, b):\n # Make sure a is larger\n if (a < b):\n swap(a, b)\n\n if (a == 0 and b == 0):\n return 1;\n\n # for last bit of a\n a_rem = 0\n\n # for last bit of b\n b_rem = 0\n\n # counter for count bit and\n # set bit in xnor num\n count = 0\n\n # for make new xnor number\n xnornum = 0\n\n # for set bits in new xnor\n # number\n while (a != 0):\n\n # get last bit of a\n a_rem = a & 1\n\n # get last bit of b\n b_rem = b & 1\n\n # Check if current two\n # bits are same\n if (a_rem == b_rem):\n xnornum |= (1 << count)\n\n # counter for count bit\n count = count + 1\n\n a = a >> 1\n b = b >> 1\n\n return xnornum;\n\n\nt= int(input())\nfor o in range(t):\n a,b,n=map(int,input().split())\n c=a^b\n x=bin(c)\n x=x.split(\"b\")\n x=x[1]\n x=len(x)\n d=xnor(a,b)\n p=[a,b,c];r=[a,b,d]\n k=n%3-1\n if p[k]>r[k]:\n print(p[k])\n else :\n print(r[k])", "import math\n\ndef xnor(num1, num2): \n \n if (num1 < num2): \n temp = num1 \n num1 = num2 \n num2 = temp \n num1 = togglebit(num1) \n \n return num1 ^ num2 \n \ndef togglebit( n): \n \n if (n == 0): \n return 1\n \n i = n \n n = n|(n >> 1) \n n |= n >> 2\n n |= n >> 4\n n |= n >> 8\n n |= n >> 16\n \n return i ^ n \n\nfor _ in range(int(input())):\n a, b, n = [int(i) for i in input().split()]\n \n xoro = [a, b, a^b]\n xnoro = [a, b]\n index = 2\n \n while index != 8:\n xnoro.append(xnor(xnoro[index-1], xnoro[index-2]))\n index += 1\n \n if n > 8:\n print(max(xoro[(n%3)-1], xnoro[n%3+5]))\n else:\n print(max(xoro[(n%3)-1], xnoro[n-1]))", "# Python3 program to find XNOR\n# of two numbers\nimport math\n\n\ndef swap(a, b):\n temp = a\n a = b\n b = temp\n\n\n# log(n) solution\ndef xnor(a, b):\n # Make sure a is larger\n if (a < b):\n swap(a, b)\n\n if (a == 0 and b == 0):\n return 1;\n\n # for last bit of a\n a_rem = 0\n\n # for last bit of b\n b_rem = 0\n\n # counter for count bit and\n # set bit in xnor num\n count = 0\n\n # for make new xnor number\n xnornum = 0\n\n # for set bits in new xnor\n # number\n while (a != 0):\n\n # get last bit of a\n a_rem = a & 1\n\n # get last bit of b\n b_rem = b & 1\n\n # Check if current two\n # bits are same\n if (a_rem == b_rem):\n xnornum |= (1 << count)\n\n # counter for count bit\n count = count + 1\n\n a = a >> 1\n b = b >> 1\n\n return xnornum;\n\n\nt= int(input())\nfor o in range(t):\n a,b,n=map(int,input().split())\n c=a^b\n x=bin(c)\n x=x.split(\"b\")\n x=x[1]\n x=len(x)\n d=xnor(a,b)\n p=[a,b,c];r=[a,b,d]\n k=n%3-1\n if p[k]>r[k]:\n print(p[k])\n else :\n print(r[k])", "# Python3 program to find XNOR\n# of two numbers\nimport math\n\n\ndef swap(a, b):\n temp = a\n a = b\n b = temp\n\n\n# log(n) solution\ndef xnor(a, b):\n # Make sure a is larger\n if (a < b):\n swap(a, b)\n\n if (a == 0 and b == 0):\n return 1;\n\n # for last bit of a\n a_rem = 0\n\n # for last bit of b\n b_rem = 0\n\n # counter for count bit and\n # set bit in xnor num\n count = 0\n\n # for make new xnor number\n xnornum = 0\n\n # for set bits in new xnor\n # number\n while (a != 0):\n\n # get last bit of a\n a_rem = a & 1\n\n # get last bit of b\n b_rem = b & 1\n\n # Check if current two\n # bits are same\n if (a_rem == b_rem):\n xnornum |= (1 << count)\n\n # counter for count bit\n count = count + 1\n\n a = a >> 1\n b = b >> 1\n\n return xnornum;\n\n\nt= int(input())\nfor o in range(t):\n a,b,n=map(int,input().split())\n c=a^b\n x=bin(c)\n x=x.split(\"b\")\n x=x[1]\n x=len(x)\n d=xnor(a,b)\n p=[a,b,c];r=[a,b,d]\n k=n%3-1\n if p[k]>r[k]:\n print(p[k])\n else :\n print(r[k])", "# Python3 program to find XNOR\n# of two numbers\nimport math\n\n\ndef swap(a, b):\n temp = a\n a = b\n b = temp\n\n\n# log(n) solution\ndef xnor(a, b):\n # Make sure a is larger\n if (a < b):\n swap(a, b)\n\n if (a == 0 and b == 0):\n return 1;\n\n # for last bit of a\n a_rem = 0\n\n # for last bit of b\n b_rem = 0\n\n # counter for count bit and\n # set bit in xnor num\n count = 0\n\n # for make new xnor number\n xnornum = 0\n\n # for set bits in new xnor\n # number\n while (a != 0):\n\n # get last bit of a\n a_rem = a & 1\n\n # get last bit of b\n b_rem = b & 1\n\n # Check if current two\n # bits are same\n if (a_rem == b_rem):\n xnornum |= (1 << count)\n\n # counter for count bit\n count = count + 1\n\n a = a >> 1\n b = b >> 1\n\n return xnornum;\n\n\nt= int(input())\nfor o in range(t):\n a,b,n=list(map(int,input().split()))\n c=a^b\n x=bin(c)\n x=x.split(\"b\")\n x=x[1]\n x=len(x)\n d=xnor(a,b)\n p=[a,b,c];r=[a,b,d]\n k=n%3-1\n if p[k]>r[k]:\n print(p[k])\n else :\n print(r[k])\n", "# Python3 program to find XNOR\n# of two numbers\nimport math\n\n\ndef swap(a, b):\n temp = a\n a = b\n b = temp\n\n\n# log(n) solution\ndef xnor(a, b):\n # Make sure a is larger\n if (a < b):\n swap(a, b)\n\n if (a == 0 and b == 0):\n return 1;\n\n # for last bit of a\n a_rem = 0\n\n # for last bit of b\n b_rem = 0\n\n # counter for count bit and\n # set bit in xnor num\n count = 0\n\n # for make new xnor number\n xnornum = 0\n\n # for set bits in new xnor\n # number\n while (a != 0):\n\n # get last bit of a\n a_rem = a & 1\n\n # get last bit of b\n b_rem = b & 1\n\n # Check if current two\n # bits are same\n if (a_rem == b_rem):\n xnornum |= (1 << count)\n\n # counter for count bit\n count = count + 1\n\n a = a >> 1\n b = b >> 1\n\n return xnornum;\n\n\nt= int(input())\nfor o in range(t):\n a,b,n=list(map(int,input().split()))\n c=a^b\n x=bin(c)\n x=x.split(\"b\")\n x=x[1]\n x=len(x)\n d=xnor(a,b)\n p=[a,b,c];r=[a,b,d]\n k=n%3-1\n if p[k]>r[k]:\n print(p[k])\n else :\n print(r[k])\n", "def xnor(a, b):\n if a == 0:\n return 1 ^ b \n p = a\n a = a|(a>>1)\n a = a|(a>>2)\n a = a|(a>>4)\n a = a|(a>>8)\n a = a|(a>>16)\n a = a|(a>>32)\n a = a|(a>>64) \n return (a ^ p) ^ b\ndef solve():\n a, b, n = list(map(int, input().split()))\n n -= 1\n index = n % 3\n if index == 0:\n print(a)\n elif index == 1:\n print(b)\n else:\n x = a ^ b\n e = xnor(max(a, b), min(a, b))\n print(max(x, e))\n\nfor _ in range(int(input())):\n solve()\n", "def xnor(a, b):\n if a == 0:\n return 1 ^ b \n p = a\n a = a|(a>>1)\n a = a|(a>>2)\n a = a|(a>>4)\n a = a|(a>>8)\n a = a|(a>>16)\n a = a|(a>>32)\n a = a|(a>>64) \n return (a ^ p) ^ b\ndef solve():\n a, b, n = list(map(int, input().split()))\n n -= 1\n index = n % 3\n if index == 0:\n print(a)\n elif index == 1:\n print(b)\n else:\n x = a ^ b\n e = xnor(max(a, b), min(a, b))\n print(max(x, e))\n \nt = int(input())\nwhile(t > 0):\n solve()\n t = t-1\n", "def xnor(a, b):\n if a == 0:\n return 1 ^ b \n p = a\n a = a|(a>>1)\n a = a|(a>>2)\n a = a|(a>>4)\n a = a|(a>>8)\n a = a|(a>>16)\n a = a|(a>>32)\n a = a|(a>>64) \n return (a ^ p) ^ b\ndef solve():\n a, b, n = list(map(int, input().split()))\n n -= 1\n index = n % 3\n if index == 0:\n print(a)\n elif index == 1:\n print(b)\n else:\n x = a ^ b\n e = xnor(max(a, b), min(a, b))\n print(max(x, e))\n \nt = int(input())\nwhile(t > 0):\n solve()\n t = t-1\n", "# cook your dish here\ndef xnor(a, b):\n if a == 0:\n return 1 ^ b \n p = a\n a = a|(a>>1)\n a = a|(a>>2)\n a = a|(a>>4)\n a = a|(a>>8)\n a = a|(a>>16)\n a = a|(a>>32)\n a = a|(a>>64) \n return (a ^ p) ^ b\ndef solve():\n a, b, n = map(int, input().split())\n n -= 1\n index = n % 3\n if index == 0:\n print(a)\n elif index == 1:\n print(b)\n else:\n x = a ^ b\n e = xnor(max(a, b), min(a, b))\n print(max(x, e))\nt = int(input())\nwhile(t > 0):\n solve()\n t = t-1", "import math \n \ndef togglebit( n): \n \n if (n == 0): \n return 1\n i = n \n n = n|(n >> 1) \n n |= n >> 2\n n |= n >> 4\n n |= n >> 8\n n |= n >> 16\n \n return i ^ n \ndef xnor( num1, num2): \n \n # Make sure num1 is larger \n if (num1 < num2): \n temp = num1 \n num1 = num2 \n num2 = temp \n num1 = togglebit(num1) \n \n return num1 ^ num2 \ndef x(A,B,N):\n if N==1:\n return A\n elif N==2:\n return B\n else:\n t0=A^B\n t1=B^t0\n t2=t0^t1\n if N%3==0:\n return t0\n elif N%3==1:\n return t1\n else:\n return t2\n \ndef xn(A,B,N):\n if N==1:\n return A\n elif N==2:\n return B\n else:\n cache=[xnor(A,B)]\n cache.append(xnor(cache[0],B))\n for i in range(2,7):\n cache.append(xnor(cache[i-1],cache[i-2]))\n t1=xnor(cache[6],cache[5])\n t2=xnor(cache[6],t1)\n t0=xnor(t2,t1)\n if N<=9:\n return cache[N-3]\n else:\n if N%3==0:\n return t0\n elif N%3==1:\n return t1\n else:\n return t2\n \nt=int(input())\nfor _ in range(t):\n p,q,n=map(int,input().split())\n print(max(x(p,q,n),xn(p,q,n)))", "def xnor(a, b):\n if a == 0:\n return 1 ^ b \n p = a\n a = a|(a>>1)\n a = a|(a>>2)\n a = a|(a>>4)\n a = a|(a>>8)\n a = a|(a>>16)\n a = a|(a>>32)\n a = a|(a>>64) \n return (a ^ p) ^ b\ndef solve():\n a, b, n = map(int, input().split())\n n -= 1\n index = n % 3\n if index == 0:\n print(a)\n elif index == 1:\n print(b)\n else:\n x = a ^ b\n e = xnor(max(a, b), min(a, b))\n print(max(x, e))\nt = int(input())\nwhile(t > 0):\n solve()\n t = t-1", "\ndef togglebit( n): \n \n if (n == 0): \n return 1\n\n i = n \n\n n = n|(n >> 1) \n\n n |= n >> 2\n n |= n >> 4\n n |= n >> 8\n n |= n >> 16\n \n return i ^ n \n \ndef xnor( num1, num2): \n \n if (num1 < num2): \n temp = num1 \n num1 = num2 \n num2 = temp \n num1 = togglebit(num1) \n \n return num1 ^ num2 \ndef nthXorFib(n, a, b): \n if n == 0 : \n return a \n if n == 1 : \n return b \n if n == 2 : \n return a ^ b \n \n return nthXorFib(n % 3, a, b) \ndef nthXnorFib(n, a, b): \n if n == 0 : \n return a \n if n == 1 : \n return b \n if n == 2 : \n return xnor(a,b)\n \n return nthXnorFib(n % 3, a, b) \n \nt=int(input())\nwhile(t):\n a,b,n=map(int,input().split())\n print(max(nthXnorFib(n-1,a,b),nthXorFib(n-1,a,b)))\n t-=1", "# cook your dish here\ndef togglebit(n):\n if (n == 0):\n return 1\n \n i = n; \n\n n |= n >> 1; \n \n n |= n >> 2 \n n |= n >> 4 \n n |= n >> 8 \n n |= n >> 16\n return i ^ n\n\n \ndef xnor(num1,num2):\n if (num1 < num2):\n temp = num1\n num1 = num2\n num2 = temp\n num1 = togglebit(num1)\n \n return num1 ^ num2\n \n\n\ndef xn(a,b,n):\n f = [0]*3 \n f[0] = a\n f[1] = b\n \n f[2] = xnor(a,b)\n if(n%3==0):\n return f[2]\n else:\n return f[(n%3)-1]\n\n\n\ndef fib(a, b, n):\n f = [0]*3 \n f[0] = a \n f[1] = b\n f[2] = a^b\n if(n%3==0):\n return f[2]\n else:\n return f[(n%3)-1]\n \n\ndef __starting_point():\n for _ in range(int(input())):\n a,b,n = list(map(int, input().split()))\n print(max(fib(a,b,n), xn(a,b,n)))\n\n\n__starting_point()", "# cook your dish here\ndef xnor(a, b):\n if a == 0:\n return 1 ^ b \n p = a\n a = a|(a>>1)\n a = a|(a>>2)\n a = a|(a>>4)\n a = a|(a>>8)\n a = a|(a>>16)\n a = a|(a>>32)\n a = a|(a>>64) \n return (a ^ p) ^ b\ndef solve():\n a, b, n = map(int, input().split())\n n -= 1\n index = n % 3\n if index == 0:\n print(a)\n elif index == 1:\n print(b)\n else:\n x = a ^ b\n e = xnor(max(a, b), min(a, b))\n print(max(x, e))\nt = int(input())\nwhile(t > 0):\n solve()\n t = t-1", "import sys\nimport math\nfrom collections import defaultdict,Counter\n\ninput=sys.stdin.readline\ndef print(x):\n sys.stdout.write(str(x)+\"\\n\")\n\n# sys.stdout=open(\"CP2/output.txt\",'w')\n# sys.stdin=open(\"CP2/input.txt\",'r')\n\n# m=pow(10,9)+7\nt=int(input())\nfor i in range(t):\n a,b,n=map(int,input().split())\n c=a^b\n c1=bin(c).lstrip('0b')\n c1=list(c1.rjust(max(len(bin(a)),len(bin(b)))-2,'0'))\n # print(c1)\n for j in range(len(c1)):\n if c1[j]=='0':\n c1[j]='1'\n else:\n c1[j]='0'\n c1=int(''.join(c1),2)\n # print(c1,end=' ')\n l=[a,b,max(c,c1)]\n # if a==b:\n # l[2]=1\n # n1=n\n # a1,b1=a,b\n ans=l[(n-1)%3]\n print(ans)\n # while n1-2:\n # n1-=1\n # c=a^b\n # print(c,end=' ')\n # a,b=b,c\n # print()\n # a,b=a1,b1\n # while n-2:\n # n-=1\n # c1=bin(a^b).lstrip('0b')\n # c1=list(c1.rjust(max(len(bin(a)),len(bin(b)))-2,'0'))\n # # print(c1)\n # for j in range(len(c1)):\n # if c1[j]=='0':\n # c1[j]='1'\n # else:\n # c1[j]='0'\n # c1=int(''.join(c1),2)\n # print(c1,end=' ')\n # a,b=b,c1\n # # print(max(c,int(''.join(c1),2)))\n", "from sys import stdin\nimport math\n# Input data\n#stdin = open(\"input\", \"r\")\n\n\ndef togglebit(n):\n\n if (n == 0):\n return 1\n\n i = n\n n = n | (n >> 1)\n n |= n >> 2\n n |= n >> 4\n n |= n >> 8\n n |= n >> 16\n\n return i ^ n\n\n\ndef xnor(num1, num2):\n if (num1 < num2):\n temp = num1\n num1 = num2\n num2 = temp\n num1 = togglebit(num1)\n return num1 ^ num2\n\nfor _ in range(int(stdin.readline())):\n a, b, n = list(map(int, stdin.readline().split()))\n X = [a, b, a ^ b]\n E = [a, b]\n for i in range(2, n):\n E.append(xnor(E[-1], E[-2]))\n if E[-3:] == E[-6:-3]:\n break\n x = (n - 1) % 3\n e = (n - len(E)) % 3\n if e == 0:\n e = -1\n elif e == 1:\n e = -3\n else:\n e = -2\n print(max(X[x], E[e]))\n", "import math \n\ndef xnor(a, b): \n if (a < b): \n a, b = b, a\n \n if (a == 0 and b == 0) : \n return 1; \n # for last bit of a \n a_rem = 0 \n # for last bit of b \n b_rem = 0\n # counter for count bit and \n # set bit in xnor num \n count = 0\n # for make new xnor number \n xnornum = 0 \n # for set bits in new xnor \n # number \n while (a!=0) : \n # get last bit of a \n a_rem = a & 1 \n # get last bit of b \n b_rem = b & 1 \n # Check if current two \n # bits are same \n if (a_rem == b_rem): \n xnornum |= (1 << count) \n # counter for count bit \n count=count+1\n \n a = a >> 1\n b = b >> 1\n \n return xnornum;\n\nfor _ in range(int(input())):\n a, b, n = map(int, input().split())\n X = [a, b, a^b]\n E = [a, b, xnor(a, b)]\n \n i = (n-1)%3\n \n print(max(X[i], E[i]))", "def xnor(a,b): \n if (a < b): \n a,b=b,a \n \n if (a == 0 and b == 0): \n return 1 \n \n a_rem = 0\n b_rem = 0\n \n count = 0 \n \n xnornum = 0 \n \n while (a): \n a_rem = a & 1 \n \n b_rem = b & 1 \n if (a_rem == b_rem): \n xnornum |= (1 << count)\n\n count+=1 \n a = a >> 1\n b = b >> 1 \n return xnornum \n\ndef xor(a,b,n):\n if((n+2)%3==0):\n return a\n elif((n+1)%3==0):\n return b\n else:\n return a^b\n \ndef check(a,b,n):\n if(n==1):\n return a\n elif(n==2):\n return b\n if(n<=6):\n ans=xnor(a,b)\n for i in range(3,n): \n ans,b=xnor(ans,b),ans\n return ans \n elif((n-4)%3==0):\n return a\n elif((n-5)%3==0):\n return b\n elif((n-6)%3==0):\n return xnor(a,b)\n \nfor z in range(int(input())):\n a,b,n=map(int,input().split()) \n print(max(xor(a,b,n),check(a,b,n)))", "import math \n \ndef swap(a,b): \n \n temp=a \n a=b \n b=temp \n \n# log(n) solution \ndef xnor(a, b): \n \n # Make sure a is larger \n if (a < b): \n swap(a, b) \n \n if (a == 0 and b == 0) : \n return 1; \n \n # for last bit of a \n a_rem = 0 \n \n # for last bit of b \n b_rem = 0 \n \n # counter for count bit and \n # set bit in xnor num \n count = 0\n \n # for make new xnor number \n xnornum = 0 \n \n # for set bits in new xnor \n # number \n while (a!=0) : \n \n # get last bit of a \n a_rem = a & 1 \n \n # get last bit of b \n b_rem = b & 1 \n \n # Check if current two \n # bits are same \n if (a_rem == b_rem): \n xnornum |= (1 << count) \n \n # counter for count bit \n count=count+1\n \n a = a >> 1\n b = b >> 1\n \n return xnornum;\n\ndef nthXorFib(n, a, b): \n if n == 0 : \n return a \n if n == 1 : \n return b \n if n == 2 : \n return a ^ b \n \n return nthXorFib(n % 3, a, b)\n\ndef nthXNorFib(n, a, b): \n if n == 0 : \n return a \n if n == 1 : \n return b \n if n == 2 : \n return xnor(a, b)\n \n return nthXNorFib(n % 3, a, b)\n\nfor test in range(int(input())):\n a, b, n = map(int, input().split())\n\n print(max(nthXNorFib(n - 1, a, b), nthXorFib(n - 1, a, b)))", "def xnor(a, b) :\n if a == 0:\n return 1 ^ b \n p = a\n a = a|(a>>1)\n a = a|(a>>2)\n a = a|(a>>4)\n a = a|(a>>8)\n a = a|(a>>16)\n a = a|(a>>32)\n a = a|(a>>64) \n return (a ^ p) ^ b\n\ndef solve() :\n a, b, n = list(map(int, input().split()))\n n -= 1\n index = n % 3\n if index == 0:\n print(a)\n elif index == 1:\n print(b)\n else:\n x = a ^ b\n e = xnor(max(a, b), min(a, b))\n print(max(x, e))\n\nfor _ in range(int(input())) :\n solve()\n", "t = int(input())\nfor x in range(t):\n a,b,n = list(map(int,input().split()))\n import math \n \n# Please refer below post for details of this function \n# https://www.geeksforgeeks.org/toggle-bits-significant-bit/ \n def togglebit( n): \n \n if (n == 0): \n return 1\n \n # Make a copy of n as we are \n # going to change it. \n i = n \n \n # Below steps set bits after \n # MSB (including MSB) \n \n # Suppose n is 273 (binary \n # is 100010001). It does following \n # 100010001 | 010001000 = 110011001 \n n = n|(n >> 1) \n \n # This makes sure 4 bits \n # (From MSB and including MSB) \n # are set. It does following \n # 110011001 | 001100110 = 111111111 \n n |= n >> 2\n n |= n >> 4\n n |= n >> 8\n n |= n >> 16\n \n return i ^ n \n \n # Returns XNOR of num1 and num2 \n def xnor( num1, num2): \n \n # Make sure num1 is larger \n if (num1 < num2): \n temp = num1 \n num1 = num2 \n num2 = temp \n num1 = togglebit(num1) \n \n return num1 ^ num2 \n\n def xor(x,y,p):\n if p%3 == 1:\n return x\n elif p%3 == 2:\n return y\n elif p%3 == 0:\n return (x^y)\n def xnnor(x,y,p):\n if p%3 == 1:\n return x\n elif p%3 == 2:\n return y\n elif p%3 == 0:\n return xnor(x,y) \n #print(xor(a,b,n),xnor(a,b,n))\n print(max(xor(a,b,n),xnnor(a,b,n))) \n", "#Coded By Ujjwal Bharti\ndef binary(x):\n result = []\n while x != 0:\n temp = x%2\n x = x//2\n result.append(temp)\n return result\ndef binCount(x):\n count=0\n while x != 0:\n x = x//2\n count += 1 \n return count\ndef xnor(a,b):\n final = []\n count = max(binCount(a),binCount(b))\n abin = binary(a)\n bbin = binary(b)\n if count != len(abin):\n while len(abin) != count:\n abin.append(0)\n if count != len(bbin):\n while len(bbin) != count:\n bbin.append(0)\n #print(abin,bbin)\n i=0\n while i <count:\n if (bbin[i]==0 and abin[i]==0) or (bbin[i]==1 and abin[i]==1):\n final.append(1)\n else:\n final.append(0)\n i += 1\n #print(abin,bbin,final)\n ans = 0\n i = 0\n #print(final)\n for dig in final:\n ans += (dig*(2**i))\n #print(ans)\n i += 1\n return ans\n \ntulu = int(input())\nfor _ in range(tulu):\n a,b,n = [int(x) for x in input().split()]\n x = a ^ b\n y = xnor(a,b)\n #print(y)\n value1 = x\n value2 = y\n if n %3==1:\n value1=a\n value2=a\n if n%3==2:\n value2=b\n value1=b\n print(max(value1,value2))", "t = int(input())\n\ndef xnor(a, b): \n \n # Make sure a is larger \n if (a < b): \n a, b = b, a\n \n if (a == 0 and b == 0) : \n return 1; \n \n # for last bit of a \n a_rem = 0 \n \n # for last bit of b \n b_rem = 0 \n \n # counter for count bit and \n # set bit in xnor num \n count = 0\n \n # for make new xnor number \n xnornum = 0 \n \n # for set bits in new xnor \n # number \n while (a!=0) : \n \n # get last bit of a \n a_rem = a & 1 \n \n # get last bit of b \n b_rem = b & 1 \n \n # Check if current two \n # bits are same \n if (a_rem == b_rem): \n xnornum |= (1 << count) \n \n # counter for count bit \n count=count+1\n \n a = a >> 1\n b = b >> 1\n \n return xnornum;\n\nwhile t:\n t -= 1\n\n a, b, n = input().split()\n a, b, n = int(a), int(b), int(n)\n\n if n%3 == 1:\n print(a)\n continue\n\n if n%3 == 2:\n print(b)\n continue\n\n xor_ = a ^ b\n xnor_ = xnor(a, b)\n\n print(max(xor_, xnor_))"]
{"inputs": [["1", "3 4 2"]], "outputs": [["4"]]}
INTERVIEW
PYTHON3
CODECHEF
19,547
f890432666ed981c078c7cb07b9ebaa4
UNKNOWN
"I don't have any fancy quotes." - vijju123 Chef was reading some quotes by great people. Now, he is interested in classifying all the fancy quotes he knows. He thinks that all fancy quotes which contain the word "not" are Real Fancy; quotes that do not contain it are regularly fancy. You are given some quotes. For each quote, you need to tell Chef if it is Real Fancy or just regularly fancy. -----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 a single string $S$ denoting a quote. -----Output----- For each test case, print a single line containing the string "Real Fancy" or "regularly fancy" (without quotes). -----Constraints----- - $1 \le T \le 50$ - $1 \le |S| \le 100$ - each character of $S$ is either a lowercase English letter or a space -----Subtasks----- Subtask #1 (100 points): original constraints -----Example Input----- 2 i do not have any fancy quotes when nothing goes right go left -----Example Output----- Real Fancy regularly fancy -----Explanation----- Example case 1: "i do not have any fancy quotes" Example case 2: The word "not" does not appear in the given quote.
["# cook your dish here\nimport re\nt=int(input())\nwhile(t>0):\n s=list(input().split(' '))\n if(\"not\" in s):\n print(\"Real Fancy\")\n else:\n print(\"regularly fancy\")\n t=t-1", "for _ in range(int(input())):\n s = input()\n l = s.split()\n if \"not\" in l:\n print(\"Real Fancy\")\n else:\n print(\"regularly fancy\")", "# cook your dish here\n\nfor _ in range(int(input())):\n s=input()\n t=s.split(\" \")\n if \"not\" in t:\n print(\"Real Fancy\")\n else:\n print(\"regularly fancy\")\n", "t=int(input())\nfor i in range(t):\n n=input()\n a=n.split(' ')\n if 'not' in a:\n print('Real Fancy')\n else:\n print('regularly fancy')\n", "for i in range(int(input())):\n n=input()\n tmp=n.split(' ')\n if 'not' in tmp:\n print('Real Fancy')\n else:\n print('regularly fancy')", "# cook your dish here\nt=int(input())\nfor i in range(t):\n s=input()\n tmp=s.split(\" \")\n if \"not\" in tmp:\n print(\"Real Fancy\")\n else:\n print(\"regularly fancy\")", "t=int(input())\nfor i in range(t):\n s=input().split()\n if('not' in s):\n print(\"Real Fancy\")\n else:\n print(\"regularly fancy\")", "# cook your dish here\nt=int(input())\ndef do():\n s=input()\n if 'not' in s.split():\n print('Real Fancy')\n else:\n print('regularly fancy')\n return\nfor i in range(t):\n do()\n", "# cook your dish here\nfor _ in range(int(input())):\n s = input()\n if 'not' in s.split():\n print('Real Fancy')\n else:\n print('regularly fancy')\n", "# cook your dish here\nfor _ in range(int(input())):\n a=[i for i in input().split()]\n if 'not' in a:\n print(\"Real Fancy\")\n else:\n print(\"regularly fancy\")", "# cook your dish here\nt=int(input())\nfor _ in range(t):\n s=input()[:100]\n s.lower()\n k=s.split()\n if('not' in k):\n print(\"Real Fancy\")\n else:\n print(\"regularly fancy\")\n", "n=int(input())\nwhile n>0:\n s1=list(input().split())\n flag=0\n for i in range(0,len(s1)):\n if str(s1[i])==\"not\":\n #print(s1[i])\n flag=1\n if flag==1:\n print(\"Real Fancy\")\n else:\n print(\"regularly fancy\")\n n=n-1", "# cook your dish here\nfor i in range(int(input())):\n x=input()\n w=\"not\"\n s=x.split()\n if w in s:\n print(\"Real Fancy\")\n else:\n print(\"regularly fancy\")\n print()", "# cook your dish here\nfor i in range(int(input())):\n x=input()\n w=\"not\"\n s=x.split()\n if w in s:\n print(\"Real Fancy\")\n else:\n print(\"regularly fancy\")\n print()", "T=int(input())\nfor i in range(T):\n S=str(input())\n S=S.split()\n for j in S:\n if j==\"not\":\n print(\"Real Fancy\")\n break\n else:\n print(\"regularly fancy\")", "T=int(input())\nfor i in range(T):\n S=str(input())\n S=S.split()\n for j in S:\n if j==\"not\":\n print(\"Real Fancy\")\n break\n else:\n print(\"regularly fancy\")\n", "# cook your dish here\nt=int(input())\nfor i in range(t):\n s=input()\n word=\"not\"\n sp = s.split()\n if word in sp:\n print(\"Real Fancy\")\n else:\n print(\"regularly fancy\")\n print()", "t = int(input())\nwhile t:\n s = input()\n word = \"not\"\n wordlist= s.split()\n \n if word in wordlist :\n print(\"Real Fancy\")\n else :\n print(\"regularly fancy\")\n t = t-1", "t = int(input())\nwhile t:\n s = input()\n word = \"not\"\n wordlist= s.split()\n \n if word in wordlist :\n print(\"Real Fancy\")\n else :\n print(\"regularly fancy\")\n t = t-1", "for t in range(int(input())):\n x=input() \n x=x.split()\n for i in x:\n if i=='not':\n print('Real Fancy')\n break \n else:\n print('regularly fancy') \n", "for i in range(int(input())):\n x=input() \n x=x.split()\n for j in x:\n if j=='not':\n print('Real Fancy')\n break \n else:\n print('regularly fancy') \n", "a=int(input())\nk=a\nwhile(k!=0):\n x=input().split()\n if 'not' in x:\n print('Real Fancy')\n else:\n print('regularly fancy')\n k=k-1", "for i in range(int(input())):\n a = input().split()\n if 'not' in a:\n print('Real Fancy')\n else:\n print('regularly fancy')# cook your dish here\n", "for _ in range(int(input())):\n S = input()\n if \"not\" in S.split():\n print(\"Real Fancy\")\n else:\n print(\"regularly fancy\")", "t = int(input())\nwhile(t):\n s = input()\n l = s.split()\n found = 0\n for x in l:\n if(x == \"not\"):\n found = 1\n if(found):\n print(\"Real Fancy\")\n else :\n print(\"regularly fancy\")\n\n t -= 1"]
{"inputs": [["2", "i do not have any fancy quotes", "when nothing goes right go left"]], "outputs": [["Real Fancy", "regularly fancy"]]}
INTERVIEW
PYTHON3
CODECHEF
4,287
df479829b30185f993b32d3741c6a056
UNKNOWN
Chef has two piles of stones with him, one has n1 stones and the other has n2 stones. Fired up by boredom, he invented a game with the two piles. Before the start of the game Chef chooses an integer m. In the j-th move: - He chooses a number xj such that 1 ≤ xj ≤ m, and removes xj stones from both the piles (this is only possible when both the piles have ≥ xj stones). - The number chosen must be unique over all the moves in the game. That is, for all k < j, xj ≠ xk. The game stops when Chef is unable to make any more moves. Chef wants to make the moves in such a way that the sum of the number of stones remaining in the two piles is minimized. Please help Chef find this. -----Input----- - The first line of input contains an integer T denoting the number of test cases. - Each test case consists of 1 line with three integers — n1, n2 and m — separated by single spaces. -----Output----- For each test case, output a single line containing the minimum sum of the number of stones of two piles. -----Constraints----- Subtask 1 : (5 pts) - 1 ≤ T ≤ 100 - 0 ≤ m ≤ 18 - 0 ≤ n1, n2 ≤ 100 Subtask 2 : (25 pts) - 1 ≤ T ≤ 1000 - 0 ≤ m ≤ 10000 - 0 ≤ n1, n2 ≤ 10000 Subtask 3 : (70 pts) - 1 ≤ T ≤ 105 - 0 ≤ m ≤ 109 - 0 ≤ n1, n2 ≤ 1018 -----Example----- Input:3 1 1 1 1 2 1 4 5 2 Output:0 1 3 -----Explanation----- Example case 1. : Remove 1 stone from each of the piles. Now 0 stones are remaining, so chef cannot remove any more stones from the piles. Hence, answer is 0+0 = 0 Example case 2. : Again, remove 1 stone from both the piles to get (0,1) stones. Now chef cannot remove any more stones from pile 1, so he stops. Hence, answer is 0+1 = 1. Example case 3. : First remove 1 stone from both the piles to get (3,4) stones. Now, remove 2 stones from both the piles so that (1,2) stones are remaining. Now chef cannot remove any more stones owing to the condition that he cannot remove the same number of stones twice. So, the answer is 1+2 = 3.
["import sys\n\nn = int(sys.stdin.readline())\n\nfor _ in range(n):\n p1, p2, m = list(map(int, sys.stdin.readline().split()))\n\n l = min(p1, p2)\n\n #while(m > 0 and l > 0):\n # k = min(l, m)\n # l -= k\n # m -= 1\n\n q = min(p1, p2)\n d = min((m * (m + 1)) / 2, q)\n\n print(p1 - d + p2 - d)", "import sys\n\nn = int(sys.stdin.readline())\n\nfor _ in range(n):\n p1, p2, m = list(map(int, sys.stdin.readline().split()))\n\n l = min(p1, p2)\n\n while(m > 0 and l > 0):\n k = min(l, m)\n l -= k\n m -= 1\n\n q = min(p1, p2)\n print(p1 - q + l + p2 - q + l)\n", "\nn = int(input())\n\nfor _ in range(n):\n p1, p2, m = list(map(int, input().split()))\n\n l = min(p1, p2)\n\n while(m > 0 and l > 0):\n k = min(l, m)\n l -= k\n m -= 1\n\n q = min(p1, p2)\n print(p1 - q + l + p2 - q + l)\n", "import math\namb=math.factorial(10)\nt=eval(input())\nasa=pow(10,10)\nli=[]\nfor i in range(t):\n amb2=math.factorial(10)\n a,b,c=list(map(int,input().split()))\n asa2=pow(10,10)\n d=(c*(c+1))/2\n if d<=a and d<=b:\n li.append(a+b-2*d)\n else:\n amb2=math.factorial(10)\n x=abs(a-b)\n li.append(x)\nfor i in li:\n print(i)", "#t=int(raw_input())\nimport math\nt=eval(input())\nwhile t:\n str=input()\n a,b,r=str.split()\n a=int(a)\n b=int(b)\n r=int(r)\n #print(a,b,r)\n #b=input()\n #r=input()\n t=t-1\n m=min(a,b)\n max_can_remove=(r*(r+1))/2\n ans=0\n if max_can_remove > m:\n ans=abs(a-b)\n else:\n ans=a+b-(2*max_can_remove)\n print(ans)", "for _ in range(eval(input())):\n a,b,m=list(map(int,input().split()))\n gsum=(m+1)*m/2\n if gsum<min(a,b):\n print(a+b-2*gsum)\n else:\n print(abs(a-b))\n", "t = int(input())\nwhile t:\n n1,n2,m = [int(x) for x in input().split()]\n if n2<n1:\n temp = n1\n n1 = n2\n n2 = temp\n sum_m = m*(m+1)/2\n if sum_m >= n1:\n print(n2-n1)\n else:\n print(n1+n2-2*sum_m)\n t-=1", "# CHEFST.py\n\nt = int(input());\nfor _ in range(t):\n n1,n2,m = list(map(int,input().split()))\n x = m*(m+1)\n x/=2;\n y = min(x,min(n1,n2));\n ans = (n1+n2)-(y+y)\n print(ans);", "def moves(n1, n2, m):\n lower = min(n1, n2)\n sum = max(n1, n2) - lower\n coverage = (m * (m + 1)) / 2\n if(coverage < lower):\n sum = sum + (lower - coverage) * 2\n return sum \n\nT=int(input())\nwhile T > 0:\n T = T - 1\n list_num = [int(x) for x in input().split()]\n #print list_num\n print(moves(list_num[0], list_num[1], list_num[2]))", "import sys \nsys.setrecursionlimit(10000)\n\ndef find_min(m,W):\n i=1\n while i <= m :\n if i not in W:\n break\n i+=1\n return i\n \ndef find_max(M,W,m):\n i=min(M,m)\n while i > 0 :\n if i not in W:\n break\n i-=1\n return i\ncache = {}\ndef knap(M,W,m):\n if len(W)==m or M < find_min(m,W) or M==0 :\n return 0\n if (M,tuple(W),m) in cache:\n return cache[(M,tuple(W),m)]\n if m*(m+1)/2<M:\n cache[(M,tuple(W),m)]=m*(m+1)/2\n return cache[(M,tuple(W),m)]\n #if (M,W,m) in cache:\n # return cache[(M,W,m)] \n val = find_max(M,W,m)\n W.add(val)\n #if val == M:\n # return val\n #print val,M\n #cache[(M,W,m)] = \n cache[(M,tuple(W),m)] = val+knap(M-val,W,m)\n return cache[(M,tuple(W),m)]\n\n #return cache[(M,W,m)] \n \ntests = int(input())\nfor i in range(tests):\n n1,n2,m = ([int(x) for x in input().split(\" \")])\n W = set()\n M = min(n1,n2)\n print(max(n1,n2)-M + 2*(M-knap(M,W,m))) ", "def find_min(m,W):\n i=1\n while i <= m :\n if i not in W:\n break\n i+=1\n return i\n \ndef find_max(M,W,m):\n i=min(M,m)\n while i > 0 :\n if i not in W:\n break\n i-=1\n return i\ncache = {}\ndef knap(M,W,m):\n if len(W)==m or M < find_min(m,W) or M==0 :\n return 0\n if (M,tuple(W),m) in cache:\n return cache[(M,tuple(W),m)]\n if m*(m+1)/2<M:\n cache[(M,tuple(W),m)]=m*(m+1)/2\n return cache[(M,tuple(W),m)]\n #if (M,W,m) in cache:\n # return cache[(M,W,m)] \n val = find_max(M,W,m)\n W.add(val)\n #if val == M:\n # return val\n #print val,M\n #cache[(M,W,m)] = \n cache[(M,tuple(W),m)] = val+knap(M-val,W,m)\n return cache[(M,tuple(W),m)]\n\n #return cache[(M,W,m)] \n \ntests = int(input())\nfor i in range(tests):\n n1,n2,m = ([int(x) for x in input().split(\" \")])\n W = set()\n M = min(n1,n2)\n print(max(n1,n2)-M + 2*(M-knap(M,W,m))) ", "def find_min(m,W):\n i=1\n while i <= m :\n if i not in W:\n break\n i+=1\n return i\n \ndef find_max(M,W,m):\n i=min(M,m)\n while i > 0 :\n if i not in W:\n break\n i-=1\n return i\n \ndef knap(M,W,m):\n if len(W)==m or M < find_min(m,W) or M==0 :\n return 0\n if m*(m+1)/2<M:\n return m*(m+1)/2\n #if (M,W,m) in cache:\n # return cache[(M,W,m)] \n val = find_max(M,W,m)\n W.add(val)\n #if val == M:\n # return val\n #print val,M\n #cache[(M,W,m)] = \n return val+knap(M-val,W,m)\n #return cache[(M,W,m)] \n \ntests = int(input())\nfor i in range(tests):\n n1,n2,m = ([int(x) for x in input().split(\" \")])\n W = set()\n M = min(n1,n2)\n print(max(n1,n2)-M + 2*(M-knap(M,W,m))) "]
{"inputs": [["3", "1 1 1", "1 2 1", "4 5 2"]], "outputs": [["0", "1", "3"]]}
INTERVIEW
PYTHON3
CODECHEF
4,841
e120f66b74abff50e1f3113828017066
UNKNOWN
The GoC Timber Mafia is notorious for its deforestation activities in the forests near Siruseri. These activities have increased multifold after the death of the bandit who used to lord over these jungles. Having lost the battle to prevent the Mafia from illegally felling the teak trees in this forest, the government of Siruseri came up with a novel idea. Why not legalise the deforestation activity and at least make some money in the process? So the Government decided to lease out parts of the forest to the Timber Mafia. Most of the teak trees in the forests of Siruseri were planted during the colonial times, after the native trees had been cut. Like everything European, the forest is very regular and orderly. It is rectangular in shape and the trees are arranged in uniformly spaced rows and coloumns. Since the trees differ in height and girth, the timber value differs from tree to tree. The forest department has collected data on each tree and knows the volume of wood (in cubic feet) available in each tree in the forest. The forest department maintains this information in the form of an $M \times N$ array of integers, where the $(i, j)$th entry is the volume, in cubic feet, of the $i^{th}$ tree on the $i^{th}$ row (or, equivalently, the $i^{th}$ tree on the $i^{th}$ column). We assume that our rows are numbered top to bottom and the columns are numbered from left to right. For example, such an array could look like This array tells us that the volume of the tree at position $(3,4)$ is $15$ cubic feet and so on. Any rectangular piece of land with trees at each corner can be leased out. In order to fix the lease price for any rectangular plot of the forest the forest department needs to know the amount of wood available inside the plot. A rectangular plot is described by the positions of the trees in its top left corner and the bottom right corner. For example the positions $(2,2)$ and $(3,4)$ describes the following part rectangular part of the above forest. The total amount of wood available in this rectangular plot is $76$ cubic feet. Similarly $(4,2)$ and $(4,2)$ describes the rectangle with just one tree and its volume is $20$ cubic feet. Your task is to write a program that helps the forest department to compute the total volume of the trees insides any specfied rectangular plot. -----Input:----- - The first line of the input contains two integers $M$ and $N$ indicating the number of rows and columns of trees in the forest. - The following $M$ lines have $N$ integers each. The $j^{th}$ integer on line $i+1$ denotes the volume (in cubic feet) of the $j^{th}$ tree on the $i^{th}$ row. - Line $M+2$ contains a single integer $C$ indicating the number of rectangles for which the total volume is to be computed. - Each of the following $C$ lines (line $M+2+1 ... M+2+C$) contain four integers $x_1, y_1, x_2$ and $y_2$ (with $x_1 \leq x_2$ and $y_1 \leq y_2$) and describes a rectangle. The rectangle has its top left corner at the tree in position $(x_1,y_1)$ and its bottom right corner at the tree at position $(x_2,y_2)$. -----Output:----- Your output must contain $C$ lines with one integer on each line. Line $i$ must contain the total volume of wood in the rectangle described on line $M+2+i$ in the input. -----Constraints----- - In $30 \%$ of inputs, $1 \leq C \leq 100$. - In all inputs, $2 \leq N, M \leq 1000$ and $1 \leq C \leq 1000000$ - $0 \leq$ volume of wood in each tree $\leq 1000$ - $1 \leq x_1 \leq x_2 \leq M$ - $1 \leq y_1 \leq y_2 \leq N$ -----Sample Input----- 4 4 3 4 15 23 14 20 12 9 3 8 12 15 12 20 7 5 2 2 2 3 4 4 2 4 2 -----Sample Output----- 76 20
["# cook your dish here\nfrom sys import stdin\nn, m = map(int,stdin.readline().split())\nforest=[]\nmatrix=[]\nfor _ in range(n):\n forest.append(list(map(int,stdin.readline().split())))\n matrix.append([0]*m)\nmatrix[0][0]=forest[0][0]\nfor j in range(1,m):\n matrix[0][j]=matrix[0][j-1]+forest[0][j]\nfor i in range(1,n):\n matrix[i][0]=matrix[i-1][0]+forest[i][0]\nfor i in range(1,n):\n for j in range(1,m):\n matrix[i][j]=matrix[i-1][j]+matrix[i][j-1]-matrix[i-1][j-1]+forest[i][j]\nc=int(input())\nfor _ in range(c):\n x1, y1, x2, y2 = map(int,stdin.readline().split())\n x1-=1 \n y1-=1 \n x2-=1 \n y2-=1 \n appo=0\n if x1>0:\n appo+=matrix[x1-1][y2]\n if y1>0:\n appo+=matrix[x2][y1-1]\n if x1>0 and y1>0:\n appo-=matrix[x1-1][y1-1]\n print(matrix[x2][y2]-appo)", "# cook your dish here\nfrom sys import stdin\nn, m = map(int,stdin.readline().split())\nforest=[]\nmatrix=[]\nfor _ in range(n):\n forest.append(list(map(int,stdin.readline().split())))\n matrix.append([0]*m)\nmatrix[0][0]=forest[0][0]\nfor j in range(1,m):\n matrix[0][j]=matrix[0][j-1]+forest[0][j]\nfor i in range(1,n):\n matrix[i][0]=matrix[i-1][0]+forest[i][0]\nfor i in range(1,n):\n for j in range(1,m):\n matrix[i][j]=matrix[i-1][j]+matrix[i][j-1]-matrix[i-1][j-1]+forest[i][j]\nc=int(input())\nfor _ in range(c):\n x1, y1, x2, y2 = map(int,stdin.readline().split())\n x1-=1 \n y1-=1 \n x2-=1 \n y2-=1 \n appo=0\n if x1>0:\n appo+=matrix[x1-1][y2]\n if y1>0:\n appo+=matrix[x2][y1-1]\n if x1>0 and y1>0:\n appo-=matrix[x1-1][y1-1]\n print(matrix[x2][y2]-appo)", "# cook your dish here\nn, m = map(int, input().split())\nforest=[]\nmatrix=[]\nfor _ in range(n):\n forest.append(list(map(int, input().split())))\n matrix.append([0]*m)\nmatrix[0][0]=forest[0][0]\nfor j in range(1,m):\n matrix[0][j]=matrix[0][j-1]+forest[0][j]\nfor i in range(1,n):\n matrix[i][0]=matrix[i-1][0]+forest[i][0]\nfor i in range(1,n):\n for j in range(1,m):\n matrix[i][j]=matrix[i-1][j]+matrix[i][j-1]-matrix[i-1][j-1]+forest[i][j]\nc=int(input())\nfor _ in range(c):\n x1, y1, x2, y2 = map(int, input().split())\n x1-=1 \n y1-=1 \n x2-=1 \n y2-=1 \n appo=0\n if x1>0:\n appo+=matrix[x1-1][y2]\n if y1>0:\n appo+=matrix[x2][y1-1]\n if x1>0 and y1>0:\n appo-=matrix[x1-1][y1-1]\n print(matrix[x2][y2]-appo)", "rows,columns=map(int,input().split())\na=[[0 for j in range(columns+1)] for i in range(rows+1)]\nfor i in range(1,rows+1):\n x=[int(i) for i in input().split()]\n s=0\n for j in range(columns):\n s+=x[j]\n a[i][j+1]=s+a[i-1][j+1]\nfor i in range(int(input())):\n x1,y1,x2,y2=map(int,input().split())\n s=a[x2][y2]-a[x2][y1-1]-a[x1-1][y2]+a[x1-1][y1-1]\n print(s)", "rows,columns=list(map(int,input().split()))\na=[[0] for i in range(rows+1)]\na[0]=[0 for i in range(columns+1)]\nfor i in range(1,rows+1):\n x=[int(i) for i in input().split()]\n s=0\n for j in range(columns):\n s+=x[j]\n a[i].append(s+a[i-1][j+1])\nfor i in range(int(input())):\n x1,y1,x2,y2=list(map(int,input().split()))\n s=a[x2][y2]-a[x2][y1-1]-a[x1-1][y2]+a[x1-1][y1-1]\n print(s)\n", "rows,columns=list(map(int,input().split()))\na=[[0] for i in range(rows)]\nfor i in range(rows):\n x=[int(i) for i in input().split()]\n s=0\n for j in x:\n s+=j\n a[i].append(s)\nfor i in range(int(input())):\n x1,y1,x2,y2=list(map(int,input().split()))\n s=0\n for j in range(x1-1,x2):\n s+=a[j][y2]-a[j][y1-1]\n print(s)\n", "from numpy import *\n\nm,n=list(map(int, input().split()))\ntrees=array([[None]*n]*m)\nfor i in range(m):\n trees[i]=list(map(int, input().split()))\n\nc=int(input())\nresult=[]\nfor _ in range(c):\n ans=0\n x1,y1,x2,y2=list(map(int , input().split()))\n for i in range(x1-1,x2):\n temp=[trees[i,j] for j in range(y1-1,y2)]\n ans+=sum(temp)\n result.append(ans)\n\nfor i in result:\n print(i)\n", "from numpy import *\n\nm,n=list(map(int, input().split()))\ntrees=array([[None]*n]*m)\nfor i in range(m):\n trees[i]=list(map(int, input().split()))\n\nc=int(input())\nresult=[]\nfor _ in range(c):\n ans=0\n x1,y1,x2,y2=list(map(int , input().split()))\n for i in range(x1-1,x2):\n for j in range(y1-1,y2):\n ans+=trees[i,j]\n result.append(ans)\n\nfor i in result:\n print(i)\n", "a=input().split()\nn,m=int(a[0]),int(a[1])\narr=[]\nfor i in range(n):\n a=input().split()\n a=[int(j) for j in a]\n arr.append(a)\nfor t in range(int(input())):\n a=input().split()\n x1,y1,x2,y2=int(a[0]),int(a[1]),int(a[2]),int(a[3])\n total=0\n for i in range(x1-1,x2):\n for j in range(y1-1,y2):\n total+=arr[i][j]\n print(total)", "while True:\n try:\n rolcol = input().split()\n row = int(rolcol[0])\n col = int(rolcol[1])\n tree = []\n for i in range(row):\n a = input().split()\n tree.append(a)\n sell = int(input())\n for i in range(sell):\n sum1 = 0\n pos = input().split()\n x1 = int(pos[0])-1\n y1 = int(pos[1])-1\n x2 = int(pos[2])-1\n y2 = int(pos[3])-1\n for j in range(x1,x2+1):\n for k in range(y1,y2+1):\n sum1 = sum1 + int(tree[j][k])\n print(sum1) \n except EOFError:\n break", "# cook your dish here\nfrom sys import stdin, stdout\nrows,columns=map(int,stdin.readline().strip().split())\nmatrix=[]\nfor _ in range(rows):\n row=list(map(int,stdin.readline().strip().split()))\n matrix.append(row)\nC=int(stdin.readline().strip())\nfor _ in range(C):\n tlx,tly,brx,bry=map(int,stdin.readline().strip().split())\n s=0\n for r in range(tlx-1,brx):\n for c in range(tly-1,bry):\n s+=matrix[r][c]\n stdout.write(str(s)+'\\n')", "import numpy as np\nl = input().split()\nn=int(l[0])\nm=int(l[1])\nl=[]\nfor _ in range(n):\n l.append(list(map(int,input().split()))[:])\ntc = int(input())\narr = np.array(l)\nfor _ in range(tc):\n dim = input().split()\n r1 = int(dim[0])\n c1 = int(dim[1])\n r2 = int(dim[2])\n c2 = int(dim[3])\n t = arr[r1-1:r2,c1-1:c2]\n print(np.sum(t))\n \n", "l = input().split()\nn=int(l[0])\nm=int(l[1])\nl=[]\nfor _ in range(n):\n l.append(list(map(int,input().split()))[:])\ntc = int(input())\nfor _ in range(tc):\n dim = input().split()\n r1 = int(dim[0])\n c1 = int(dim[1])\n r2 = int(dim[2])\n c2 = int(dim[3])\n sum=0\n for i in range(r1-1,r2):\n for j in range(c1-1,c2):\n sum+=l[i][j]\n print(sum)\n \n", "# cook your dish here\ntry:\n m, n = list(map(int, input().split()))\n vol = [[0] * (n+1)]\n area = [[]]\n for i in range(m):\n area.append([0] + list(map(int, input().split())))\n vol.append([0] * (n+1))\n \n for i in range(1, m+1):\n for j in range(1, n+1):\n vol[i][j] = vol[i-1][j] + vol[i][j-1] - vol[i-1][j-1] + area[i][j]\n \n t = int(input())\n \n for i in range(t):\n x, y, p, q = list(map(int, input().split()))\n print(vol[p][q] - vol[x-1][q] - vol[p][y-1] + vol[x-1][y-1])\n\nexcept:\n pass", "# cook your dish here\nn,m = list(map(int,input().split()))\nl = []\nfor i in range(n):\n x = list(map(int,input().split()))\n l.append(x)\n\nt = int(input())\nfor _ in range(t):\n x1,y1,x2,y2 = list(map(int,input().split()))\n vol = 0\n for i in range(x1-1,x2):\n for j in range(y1-1,y2):\n vol+=l[i][j]\n print(vol)", "# cook your dish here\nn,m = list(map(int,input().split()))\nl = [[] for _ in range(n)]\nfor i in range(n):\n x = list(map(int,input().split()))\n l[i]+=(x)\n\nt = int(input())\nfor _ in range(t):\n x1,y1,x2,y2 = list(map(int,input().split()))\n vol = 0\n for i in range(x1-1,x2):\n for j in range(y1-1,y2):\n vol+=l[i][j]\n print(vol)", "m,n=map(int, input().split())\nl = []\nfor _ in range(m):\n l.append(list(map(int, input().split())))\nq=[]\nm, n = 0,0\nfor _ in range(int(input())):\n y1,x1,y2,x2 = map(int, input().split())\n q.append([y1,x1,y2,x2])\n n=max(n,x2)\n m=max(m,y2)\n \ndp = [[0 for _ in range(n+1)] for _ in range(m+1)]\ndp[1][1]=l[0][0]\nfor i in range(1,n+1):\n dp[1][i] = dp[1][i-1] + l[0][i-1]\n \nfor j in range(2, m+1):\n t_sum = 0\n for i in range(1, n+1):\n t_sum += l[j-1][i-1]\n dp[j][i] = t_sum + dp[j-1][i]\n\nfor y1,x1,y2,x2 in q:\n ans = dp[y2][x2]-dp[y2][x1-1]-dp[y1-1][x2] + dp[y1-1][x1-1]\n print(ans)"]
{"inputs": [["4 4", "3 4 15 23", "14 20 12 9", "3 8 12 15", "12 20 7 5", "2", "2 2 3 4", "4 2 4 2"]], "outputs": [["76", "20"]]}
INTERVIEW
PYTHON3
CODECHEF
7,938
bcc961e438853a11c635128f87771ab1
UNKNOWN
Meliodas and Ban are fighting over chocolates. Meliodas has $X$ chocolates, while Ban has $Y$. Whoever has lesser number of chocolates eats as many chocolates as he has from the other's collection. This eatfest war continues till either they have the same number of chocolates, or atleast one of them is left with no chocolates. Can you help Elizabeth predict the total no of chocolates they'll be left with at the end of their war? -----Input:----- - First line will contain $T$, number of testcases. Then the testcases follow. - Each testcase contains of a single line of input, which contains two integers $X, Y$, the no of chocolates Meliodas and Ban have, respectively. -----Output:----- For each testcase, output in a single line the no of chocolates that remain after Ban and Meliodas stop fighting. -----Constraints----- - $1 \leq T \leq 100000$ - $0 \leq X,Y \leq 10^9$ -----Sample Input:----- 3 5 3 10 10 4 8 -----Sample Output:----- 2 20 8 -----EXPLANATION:----- Denoting Meliodas as $M$, Ban as $B$. Testcase 1: $M$=5, $B$=3 Ban eates 3 chocolates of Meliodas. $M$=2, $B$=3 Meliodas eats 2 chocolates of Ban. $M$=2, $B$=1 Ban eates 1 chocolate of Meliodas. $M$=1, $B$=1 Since they have the same no of candies, they stop quarreling. Total candies left: 2 Testcase 2: $M$=10, $B$=10 Since both of them had the same candies to begin with, there was no point in fighting. Total candies left: 20 Testcase 3: $M$=4, $B$=8 Meliodas eats 4 chocolates of Ban. $M$=4, $B$=4 Since they have the same no of candies, they stop quarreling. Total candies left: 8
["from math import *\nt=int(input())\nfor i in range(t):\n m,b=input().split()\n m=int(m)\n b=int(b)\n print(2*gcd(m,b))", "from math import*\nn=int(input())\nfor i in range(n):\n b,m=input().split()\n b=int(b)\n m=int(m)\n print(2*gcd(b,m))", "from math import*\nfor i in range(int(input())):\n m,b=input().split()\n m=int(m)\n b=int(b)\n print(2*gcd(m,b))", "from math import *\nt=int(input())\nfor i in range(t):\n m,b=input().split()\n m=int(m)\n b=int(b)\n print(2*gcd(m,b))", "def gcd(a, b):\n if b == 0:\n return a\n return gcd(b, a%b)\n\nfor _ in range(int(input())):\n a, b = map(int, input().split())\n\n print(2 * gcd(a, b))", "from math import *\nt=int(input())\nfor i in range(t):\n a,b=map(int,input().split())\n a=int(a)\n b=int(b)\n print(2*gcd(a,b))", "# cook your dish here\ndef gcd(a, b):\n if b==0:\n return a \n return gcd(b, a%b)\n\nfor _ in range(int(input())):\n M, B = map(int, input().split())\n g = gcd(M, B)\n print(2 * g)", "# cook your dish here\ndef fun(M,B):\n if M==B:\n return M*2\n elif M==0:\n return B*2\n elif B==0:\n return M*2\n else:\n if M>B:\n return fun(M%B,B)\n else:\n return fun(M,B%M)\nt = int(input())\nfor i in range(t):\n M,B=list(map(int,input().split()))\n \n print(fun(M,B))\n", "# cook your dish here\ndef gcd(a, b):\n if b==0:\n return a \n return gcd(b, a%b)\n\nfor _ in range(int(input())):\n M, B = map(int, input().split())\n g = gcd(M, B)\n print(2 * g)", "from math import *\nt=int(input())\nfor i in range(t):\n m,b=input().split()\n m=int(m)\n b=int(b)\n print(2*gcd(m,b))", "# cook your dish here\nfor _ in range(int(input())):\n [m,b]=[int(i) for i in input().split()]\n def E(m,b):\n if m<b:\n return E(b,m)\n if b==0:\n return m\n return E(b,m%b)\n print(2*E(m,b))", "# cook your dish here\ndef chocoValue(a,b):\n if a<b:\n a,b=b,a\n if b==0: \n return a\n return chocoValue(b,a%b)\n\n\nfor x in range(int(input())):\n m,b=map(int,input().split())\n if m or b:\n sumValue= chocoValue(m,b)\n print(2*sumValue)\n else:\n print(0)", "def gcd(a,b):\n if a<b:\n a,b=b,a\n if b==0:\n return a\n return gcd(b,a%b)\n \nfor _ in range(int(input())):\n a,b=map(int,input().split())\n if a or b:\n c=gcd(a,b)\n print(2*c)\n else:\n print(0)", "# cook your dish here\nimport math\nfor _ in range(int(input())):\n m, b = map(int,input().split())\n print(2*math.gcd(m, b))", "# cook your dish here\nimport math\nfor i in range(int(input())):\n n,m=map(int,input().split())\n if n==m or n==0 or m==0:\n print(n+m)\n else:\n a=math.gcd(n,m)\n print(2*a)", "# cook your dish here\nimport math\nfor _ in range(int(input())):\n n,m=map(int,input().split())\n if n==m or n==0 or m==0:\n print(n+m)\n else:\n x=math.gcd(n,m)\n print(2*x)", "t=int(input())\nfor _ in range(t):\n a,b=list(map(int,input().split()))\n while a!=0 and b!=0 and a!=b:\n if(a>b):\n a=a%b\n else:\n b=b%a\n if(a==0 or b==0):\n print((a+b)*2)\n elif(a==b):\n print(a+b)\n", "# cook your dish here\ndef gcd(m,b):\n if m==0:\n return b\n return gcd(b%m,m)\n\ntest = int(input())\n\nwhile test!=0:\n m,b = list(map(int,input().split()))\n result = gcd(m,b)\n print(result*2)\n test-=1\n\n", "def gcd(m,b):\n if m==0:\n return b\n return gcd(b%m,m)\n\ntest = int(input())\n\nwhile test!=0:\n m,b = list(map(int,input().split()))\n result = gcd(m,b)\n print(result*2)\n test-=1\n\n\n", "from math import gcd\nfor i in range(int(input())):\n a,s=list(map(int,input().split()))\n print(gcd(a,s)*2)", "t = int(input())\n\ndef gcd(a, b):\n if(b==0):\n return a\n else:\n return gcd(b, a%b)\n\nfor _ in range(t):\n x, y = [int(a) for a in input().split()]\n \n print(gcd(x, y)*2)", "from math import gcd\nfor _ in range(int(input())) :\n a, b = map(int, input().split())\n print(2 * gcd(a, b))", "# cook your dish here\nfrom math import gcd\nfor _ in range(int(input())):\n x,y= map(int,input().split())\n if x==y:\n print(x+y)\n else:\n print(2*gcd(x,y))", "# cook your dish here\nfor _ in range(int(input())):\n x, y = list(map(int, input().split()))\n \n while(y):\n x, y = y, x % y\n \n print(2*x)"]
{"inputs": [["3", "5 3", "10 10", "4 8"]], "outputs": [["2", "20", "8"]]}
INTERVIEW
PYTHON3
CODECHEF
4,065
da1d436a5884a6b7ef7a1cde55ae9e54
UNKNOWN
Chef is interested to solve series problems. Chef wants to solve a series problem but he can't solve it till now.Can you help Chef to solve the series problem? - In series problem, the series goes as follows 1,9,31,73,141 . . . . . . . . Your task is to find the Nth term of series. For larger value of $N$ answer becomes very large, So your output should be performed $N$th term modulo 1000000007 ($10^9+7$ ). -----Input:----- - First line will contain $T$, number of testcases. Then the testcases follow. - Each testcase contains of a single integer $N$. -----Output:----- For each testcase, output in a single line answer i.e. The $N$th term of series modulo 1000000007. -----Constraints----- - $1 \leq T \leq 10^5$ - $1 \leq N \leq 10^9$ -----Sample Input:----- 2 8 10 -----Sample Output:----- 561 1081
["# cook your dish here\ntry:\n for t in range(int(input())):\n n=int(input())\n ans=n*n*n+((n-1)**2)\n if ans<=10**9+7:\n print(ans)\n else:\n print(ans)%(10**9+7)\nexcept:\n pass", "t=int(input())\nfor i in range(t):\n n=int(input())\n s=(n**3)+((n-1)**2)\n print(s%1000000007)\n", "# cook your dish here\nseries=[]\nseries.append(0)\ni=1\nj=2\nfor i in range(1,10000007):\n series.append(i*i+j*j*j)\n i=i+1\n j=j+1\n \nt=int(input())\nwhile t>0:\n n=int(input())\n print(series[n-1]%1000000007) \n t=t-1\n", "# cook your dish here\nt=int(input())\nfor i in range(t):\n n=int(input())\n if(n==1):\n print(n)\n elif(n<0):\n print(0)\n else:\n print((((n-1)*(n-1))+(n*n*n))%1000000007)", "for _ in range(int(input())):\n n = int(input())\n arr = [1, 9, 31]\n diff = [8, 22]\n if n == 1:\n print(arr[0])\n elif n == 2:\n print(arr[1])\n elif n == 3:\n print(arr[-1])\n else:\n has = 0\n for i in range(2, n-1):\n value = (diff[i - 1] - diff[i - 2])\n value = value + 6\n value = value + diff[-1]\n diff.append(value)\n value = value + arr[-1]\n arr.append(value)\n\n print(arr[-1] % ((10**9) + 7))", "for tc in range(int(input())) :\n n = int(input())\n t = n**3 + (n-1)**2\n print(t%1000000007)", "def power(x, y, p) : \n res = 1\n x = x % p \n \n if (x == 0) : \n return 0\n \n while (y > 0) :\n \n if ((y & 1) == 1) : \n res = (res * x) % p \n \n y = y >> 1 \n x = (x * x) % p \n \n return res \n \nt = int(input())\nmod = 1000000007\nfor _ in range(t):\n n = int(input())\n ans = power(n-1,2,mod) + power(n,3,mod)\n print(ans%mod)", "for _ in range(int(input())):\n n=int(input())\n result= (n**3)+((n-1)**2)\n result = result%(1000000007)\n\n print(result)", "# cook your dish here\nt = int(input())\nwhile t > 0:\n n = int(input())\n ans = (n-1)*(n-1) + n*n*n\n print(ans%1000000007)\n t = t -1;", "for _ in range(int(input())):\n n=int(input())\n result= (n**3)+((n-1)**2)\n result = result%(1000000007)\n\n print(result)", "# cook your dish here\ntry:\n for _ in range(int(input())):\n n=int(input())\n r=n**3+(n-1)**2\n print(r%1000000007)\nexcept:pass \n", "import math\nfor _ in range(int(input())):\n n=int(input())-1\n nth=math.pow(n,2)+math.pow((n+1),3)\n print(int(nth%1000000007))\n", "# cook your dish here\nfor _ in range(int(input())):\n n=int(input())\n print((((n-1)**2)+(n**3))%1000000007)", "for _ in range(int(input())):\n n=int(input())\n m=1000000007\n print((((n-1)**2) + n**3) % m)", "# cook your dish here\nfor u in range(int(input())):\n n=int(input())\n s=(n-1)**2+n**3\n print(s%(10**9+7))\n", "# cook your dish here\nfor u in range(int(input())):\n n=int(input())\n s=(n-1)**2+n**3\n print(s%(10**9+7))\n", "# cook your dish here\ntry:\n t=int(input())\n for _ in range(t):\n n=int(input())\n M = 1000000007\n d=n**3\n f=(n-1)**2\n g=(d+f)%M \n print(g)\nexcept:\n pass", "# cook your dish here\nfor i in range(int(input())):\n x=int(input())\n a=x*x*x+(x-1)*(x-1)\n print(a%1000000007)", "# cook your dish here\nfor i in range(int(input())):\n n=int(input())\n #mod=1000000007\n res=(pow(n-1,2)+pow(n,3))\n print(res%1000000007)", "t = int(input())\nfor i in range(t):\n n = int(input())\n x = [1]\n for i in range(1,n):\n p = (i**2 + (i+1)**3)%1000000007\n x.append(p)\n print(x[n-1])", "# cook your dish here\nT = int(input())\nwhile T > 0:\n N = int(input())\n T = T - 1\n A = (N - 1)**2 + N**3\n print(A%1000000007)", "# cook your dish here\nfor _ in range(int(input())):\n n = int(input())\n print(((n-1)**2 + n**3) % 1000000007)", "# cook your dish here\nfor i in range(int(input())):\n n = int(input())\n x = ((n-1)**2)+((n)**3)\n if x>1000000000:\n x = x%1000000007\n print(x)", "from math import sqrt\nfor _ in range(int(input())):\n N, MOD = int(input()), 1000000007\n print(((N - 1) ** 2) + (N ** 3) % MOD)", "x=pow(10,9)+7 \nfor i in range(int(input())):\n n=int(input())\n ans=pow(n,3)+pow(n-1,2)\n print(ans%x)"]
{"inputs": [["2", "8", "10"]], "outputs": [["561", "1081"]]}
INTERVIEW
PYTHON3
CODECHEF
3,914
458b2f38cace3d0ab2bd547bff582ec7
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 10 10 101 101 101 1010 1010 1010 1010 -----EXPLANATION:----- No need, else pattern can be decode easily.
["for _ in range(int(input())):\n\tn = int(input())\n\tnum = \"\"\n\tval = 1\n\tfor i in range(n):\n\t\tnum += str(val)\n\t\tif val == 1:\n\t\t\tval = 0\n\t\telse:\n\t\t\tval = 1\n\tfor i in range(n):\n\t\tprint(num)\n\t\t\n\t\n", "for _ in range(int(input())):\n\tn = int(input())\n\tnum = \"\"\n\tval = 1\n\tfor i in range(n):\n\t\tnum += str(val)\n\t\tif val == 1:\n\t\t\tval = 0\n\t\telse:\n\t\t\tval = 1\n\tfor i in range(n):\n\t\tprint(num)\n\t\t\n\t\n", "for _ in range(0,int(input())):\r\n a=int(input())\r\n for i in range(0,a):\r\n for j in range(0,a):\r\n if j%2==0:\r\n print(1,end=\"\")\r\n else:\r\n print(0,end=\"\")\r\n print()", "for _ in range(int(input())):\n\tn = int(input())\n\tnum = \"\"\n\tval = 1\n\tfor i in range(n):\n\t\tnum += str(val)\n\t\tif val == 1:\n\t\t\tval = 0\n\t\telse:\n\t\t\tval = 1\n\tfor i in range(n):\n\t\tprint(num)\n\t\t\n\t\n", "t=int(input())\nfor t in range(t):\n n=int(input())\n for i in range(0,n):\n for j in range(0,n):\n if j%2==0:\n print(1,end=\"\")\n else:\n print(0,end=\"\")\n print()", "# cook your dish here\nfor i in range(int(input())):\n k=int(input())\n m1=k\n c=1\n z=0\n count=0\n while(k>1):\n if(z%2==0):\n c=c*10\n else:\n c=c*10+1\n k-=1\n z+=1\n for j in range(m1):\n print(c)", "t=int(input())\nfor t in range(t):\n n=int(input())\n for i in range(0,n):\n for j in range(0,n):\n if j%2==0:\n print(1,end=\"\")\n else:\n print(0,end=\"\")\n print()\n \n", "from sys import*\r\ninput=stdin.readline\r\nt=int(input())\r\nfor _ in range(t):\r\n k=int(input())\r\n l=[1 for _ in range(k)]\r\n for i in range(1,k):\r\n if l[i-1]==0:\r\n l[i]=1\r\n else:\r\n l[i]=0\r\n ans=\"\".join([str(x) for x in l])\r\n for i in range(k):\r\n print(ans)\r\n", "# cook your dish here\nt=int(input())\nfor _ in range(t):\n n=int(input())\n s=\"\"\n for i in range(1,n+1):\n if i%2!=0:\n s+='1'\n else:\n s+='0'\n for i in range(1,n+1):\n print(s)\n", "try:\n for i in range(int(input())):\n n=int(input())\n \n for j in range(1,n+1):\n s=1\n for k in range(1,n+1):\n \n print(s,end=\"\")\n s=1-s\n print(\"\\r\")\nexcept Exception:\n pass\n\n", "# cook your dish here\nfor _ in range(int(input())):\n k = int(input())\n \n for i in range(k):\n x = 1\n for j in range(k):\n print(x,end = '')\n if x == 1:\n x = 0\n else:\n x = 1\n print()", "def solve(n):\r\n for i in range(1,n+1):\r\n j=1\r\n for k in range(1,n+1):\r\n print(j,end='')\r\n if j==1:\r\n j=0\r\n else:\r\n j=1\r\n print()\r\nfor _ in range(int(input())):\r\n n=int(input())\r\n #s=input()\r\n #a,b=map(int,input().split())\r\n #l=list(map(int,input().split()))\r\n solve(n)\r\n", "t = int(input())\n\nfor i in range(t):\n k = int(input()) \n ini = \"\".join([str(i % 2) for i in range(1, k + 1)])\n for j in range(0, k):\n print(ini)\n", "t = int(input())\r\n\r\nfor i in range(t):\r\n k = int(input()) \r\n ini = \"\".join([str(i % 2) for i in range(1, k + 1)])\r\n for j in range(0, k):\r\n print(ini)", "t=int(input())\nfor i in range(0,t):\n n=int(input())\n for j in range(0,n):\n for k in range(0,n):\n if k%2==0:\n print(1,end=\"\")\n else:\n print(0,end=\"\")\n print(\" \")\n ", "try:\r\n tc=int(input())\r\n for _ in range(tc):\r\n n=int(input())\r\n a=0\r\n st=\"\"\r\n for i in range(n):\r\n if a%2==1:\r\n st+='0'\r\n else:\r\n st+='1'\r\n a+=1\r\n for j in range(n):\r\n print(st)\r\nexcept:\r\n pass", "# cook your dish here\n\n# cook your dish here\nt = int(input())\n\nwhile t:\n n = int(input())\n\n\n for i in range(1, n + 1):\n for j in range(1, n + 1):\n if j % 2 == 1:\n print(1, end='')\n else:\n print(0, end='')\n \n print()\n \n t -= 1", "# cook your dish here\n\n# t = [input() for i in range(n)]\n\n\ndef fk(s: str):\n s = int(s)\n # for i in range(2, 1+1+int(s)):\n # for k in range(i, i+s):\n # print(k, end='')\n # print()\n # t = 0\n # for i in range(1, s*s+1):\n # print(i*2, end='')\n # t += 1\n # if t == s:\n # print()\n # t = 0\n res = ''\n ini = 1\n for i in range(s):\n res += str(ini)\n ini = 1-ini\n for i in range(s):\n print(res)\n\n\nn = eval(input())\nn = int(n)\nt = [fk(eval(input())) for i in range(n)]\n\n# fk(3)\n", "try:\r\n def solve(n):\r\n res=\"\"\r\n for i in range(n):\r\n if i%2==0:\r\n res+=\"1\"\r\n else:\r\n res+=\"0\"\r\n return res\r\n t=int(input())\r\n for _ in range(t):\r\n n = int(input())\r\n z=solve(n)\r\n for i in range(n):\r\n print(z)\r\n \r\nexcept EOFError:\r\n pass", "for _ in range(int(input())):\n n=int(input())\n if n==1:\n print(\"1\")\n else:\n s=''\n for i in range(n):\n if i%2==0:\n s+='1'\n else:\n s+='0'\n for i in range(n):\n print(s)", "# cook your dish here\nfor _ in range(int(input())):\n k = int(input())\n s = \"\"\n count = 1\n for i in range(k):\n for j in range(k):\n s += str(count)\n if count == 1:\n count = 0\n else:\n count = 1\n print(s)\n s = \"\"\n count = 1", "# cook your dish here\n\n\nfor _ in range(int(input())):\n n=int(input())\n # c=1\n for i in range(0,n):\n for j in range(0,n):\n if (j)%2==0:\n print('1',end='')\n else:\n print('0',end=\"\")\n # print(i+j,end=\"\")\n # c+=2\n print()"]
{"inputs": [["4", "1", "2", "3", "4"]], "outputs": [["1", "10", "10", "101", "101", "101", "1010", "1010", "1010", "1010"]]}
INTERVIEW
PYTHON3
CODECHEF
6,604
bc569ff7e072a3a568a28c9ad91cc436
UNKNOWN
Chef usually likes to play cricket, but now, he is bored of playing it too much, so he is trying new games with strings. Chef's friend Dustin gave him binary strings $S$ and $R$, each with length $N$, and told him to make them identical. However, unlike Dustin, Chef does not have any superpower and Dustin lets Chef perform only operations of one type: choose any pair of integers $(i, j)$ such that $1 \le i, j \le N$ and swap the $i$-th and $j$-th character of $S$. He may perform any number of operations (including zero). For Chef, this is much harder than cricket and he is asking for your help. Tell him whether it is possible to change the string $S$ to the target string $R$ only using operations of the given type. -----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 a binary string $S$. - The third line contains a binary string $R$. -----Output----- For each test case, print a single line containing the string "YES" if it is possible to change $S$ to $R$ or "NO" if it is impossible (without quotes). -----Constraints----- - $1 \le T \le 400$ - $1 \le N \le 100$ - $|S| = |R| = N$ - $S$ and $R$ will consist of only '1' and '0' -----Example Input----- 2 5 11000 01001 3 110 001 -----Example Output----- YES NO -----Explanation----- Example case 1: Chef can perform one operation with $(i, j) = (1, 5)$. Then, $S$ will be "01001", which is equal to $R$. Example case 2: There is no sequence of operations which would make $S$ equal to $R$.
["for _ in range(int(input())):\n length = int(input())\n S = input()\n R = input()\n if S.count(\"1\") == R.count(\"1\"):\n print(\"YES\")\n else:\n print(\"NO\")", "# cook your dish here\nfor _ in range(int(input())):\n n=int(input())\n s=input()\n r=input()\n c=0\n c1=0\n for j in s:\n if j=='1':\n c+=1\n for k in r:\n if k=='1':\n c1+=1\n if c==c1:\n print(\"YES\")\n else:\n print(\"NO\")", "# cook your dish here\nfor _ in range(int(input())):\n n=int(input())\n s=input()\n r=input()\n c=0\n c1=0\n for j in s:\n if j=='1':\n c+=1\n for k in r:\n if k=='1':\n c1+=1\n if c==c1:\n print(\"YES\")\n else:\n print(\"NO\")", "# cook your dish here\nfor _ in range(int(input())):\n n=int(input())\n s=input()\n r=input()\n if s.count('1')==r.count('1'):\n print('YES')\n else:\n print(\"NO\")\n", "# cook your dish here\nfor i in range(int(input())):\n n=int(input())\n t=list(input())\n j=list(input())\n if t.count('1')==j.count('1'):\n print('YES')\n else:\n print('NO')", "# cook your dish here\nt=int(input());\nfor i in range(t):\n n=int(input());\n s=input();\n r=input();\n c0=0;\n c1=0;\n d0=0;\n d1=0;\n for i in s:\n if i=='1':\n c1=c1+1;\n else:\n c0=c0+1;\n #print(c1,c0);\n for i in r:\n if i=='1':\n d1=d1+1;\n else:\n d0=d0+1;\n #print(d0,d1);\n if ((c0==d0) and (c1==d1)):\n print('YES');\n else:\n print('NO');\n\n \n \n \n", "t=int(input())\nfor i in range(t):\n n=int(input())\n x=list(input())\n y=list(input())\n if x.count('1')==y.count('1'):\n print('YES')\n else:\n print('NO')\n \n", "for i in range(int(input())):\n n=int(input())\n t=list(input())\n j=list(input())\n if t.count('1')==j.count('1'):\n print('YES')\n else:\n print('NO')\n", "for _ in range(int(input())):\n n=int(input())\n a=list(input())\n b=list(input())\n if a.count('1')==b.count('1'):\n print('YES')\n else:\n print('NO')\n", "for _ in range(int(input())):\n n=int(input())\n n1=input()\n n2=input()\n if n1.count('0')==n2.count('0'):\n print(\"YES\")\n else:\n print(\"NO\")\n", "# cook your dish here\nt = int(input())\nfor z in range(t) :\n n = int(input())\n a = input()\n b = input()\n if a.count('0') == b.count('0') :\n print(\"YES\")\n else:\n print(\"NO\")", "# cook your dish here\nfor _ in range(int(input())):\n n=int(input())\n fr=list(input())\n gr=list(input())\n fr.sort()\n gr.sort()\n if(fr==gr):\n print(\"YES\")\n else:\n print(\"NO\")", "for _ in range(int(input())):\n N=int(input())\n S=input()\n R=input()\n if S.count(\"0\")==R.count(\"0\"):\n print(\"YES\")\n else:\n print(\"NO\")", "# cook your dish here\nt=int(input())\nfor i in range(t):\n n=int(input())\n s1 = list(input())\n s2 = list(input())\n s1.sort()\n s2.sort()\n if s1==s2:\n print(\"YES\")\n else:\n print(\"NO\")\n", "# cook your dish here\nfor i in range(int(input())):\n a=int(input())\n b=input()\n c=input()\n if(b.count(\"1\")==c.count(\"1\")):\n print(\"YES\")\n else:\n print(\"NO\")", "# cook your dish here\nfor t in range(int(input())):\n n=int(input())\n a=list(input())\n b=list(input())\n s=[]\n if len(a)==len(b):\n for i in range(0,len(a)):\n for j in range(0,len(b)):\n if a[i]==b[j]:\n b.remove(b[j])\n s.append(a[i])\n break\n else:\n pass\n if len(a)==len(s):\n print(\"YES\")\n else:\n print(\"NO\")\n \n else:\n print(\"YES\")\n", "# cook your dish here\nrii = lambda : map(int, input().strip().split(\" \"))\nril = lambda : list(map(int, input().strip().split(\" \")))\nri = lambda : int(input().strip())\nrs = lambda : input()\nT = ri()\nfor _ in range(T):\n N = ri()\n l1 = rs()\n l2 = rs()\n nb1_1 = len(list(filter(lambda x: x == '1', l1)))\n nb2_1 = len(list(filter(lambda x: x == '1', l2)))\n if nb1_1 == nb2_1:\n print(\"YES\")\n else:\n print(\"NO\")", "# cook your dish here\nrii = lambda : map(int, input().strip().split(\" \"))\nril = lambda : list(map(int, input().strip().split(\" \")))\nri = lambda : int(input().strip())\nrs = lambda : input()\nT = ri()\nfor _ in range(T):\n N = ri()\n l1 = rs()\n l2 = rs()\n nb1_1 = len(list(filter(lambda x: x == '1', l1)))\n nb2_1 = len(list(filter(lambda x: x == '1', l2)))\n if nb1_1 == nb2_1:\n print(\"YES\")\n else:\n print(\"NO\")", "# cook your dish here\ndef cricketbetterthana(s,b):\n if s.count('1')!=b.count('1'):\n return False\n return True\nfor _ in range(int(input())):\n n=int(input())\n s=list(input())\n b=list(input())\n if cricketbetterthana(s,b):\n print(\"YES\")\n else:\n print(\"NO\")\n", "# cook your dish here\nt=int(input())\nfor i in range(t):\n l=int(input())\n s=input()\n r=input()\n c1=0\n c2=0\n c3=0\n c4=0\n for i in range(l):\n if(s[i]=='0'):\n c1+=1 \n else:\n c2+=1 \n for j in range(l):\n if(r[j]=='0'):\n c3+=1 \n else:\n c4+=1\n \n if(c1==c3 and c2==c4):\n print(\"YES\")\n else:\n print(\"NO\")\n", "# cook your dish here\nt=int(input())\nfor i in range(t):\n l=int(input())\n s=input()\n r=input()\n c1=0\n c2=0\n c3=0\n c4=0\n for i in range(l):\n if(s[i]=='0'):\n c1+=1 \n else:\n c2+=1 \n for j in range(l):\n if(r[j]=='0'):\n c3+=1 \n else:\n c4+=1\n \n if(c1==c3 and c2==c4):\n print(\"YES\")\n else:\n print(\"NO\")\n", "# cook your dish here\nfor _ in range(int(input())):\n n = int(input())\n a = input()\n b = input()\n if a.count('1') == b.count('1'):\n print(\"YES\")\n else:\n print(\"NO\")", "t=int(input())\nfor i in range(t):\n n=int(input())\n s=input()\n r=input()\n if(s.count(\"1\")==r.count(\"1\")):\n print(\"YES\")\n else:\n print(\"NO\")", "# cook your dish here\nfor _ in range(int(input())):\n n=int(input())\n s1=input()\n s2=input()\n if s1.count('1')==s2.count('1') and s1.count('0')==s2.count(\"0\"):\n print(\"YES\")\n else:\n print(\"NO\")", "T = int(input())\nfor i in range(T):\n n = int(input())\n S = input()\n R = input()\n l = [x for x in S]\n m = [x for x in R]\n if ((l.count('0') == m.count('0')) or (l.count('1') == m.count('1'))):\n print(\"YES\")\n else:\n print(\"NO\")"]
{"inputs": [["2", "5", "11000", "01001", "3", "110", "001"]], "outputs": [["YES", "NO"]]}
INTERVIEW
PYTHON3
CODECHEF
5,962
56cb9043f489cf291415c6c1a5be571e
UNKNOWN
Anas is playing an amazing game on a grid with $N$ rows and $M$ columns. The rows are numbered $1$ through $N$ from top to bottom and the columns are numbered $1$ through $M$ from left to right. Anas wants to destroy this grid. To do that, he wants to send two heroes from the top left cell to the bottom right cell: - The first hero visits cells in row-major order: $(1,1) \rightarrow (1,2) \rightarrow \ldots \rightarrow (1,M) \rightarrow (2,1) \rightarrow (2,2) \rightarrow \ldots \rightarrow (2,M) \rightarrow \ldots \rightarrow (N,M)$. - The second hero visits cells in column-major order: $(1,1) \rightarrow (2,1) \rightarrow \ldots \rightarrow (N,1) \rightarrow (1,2) \rightarrow (2,2) \rightarrow \ldots \rightarrow (N,2) \rightarrow \ldots \rightarrow (N,M)$. We know that each hero destroys the first cell he visits, rests in the next $K$ cells he visits without destroying them, then destroys the next cell he visits, rests in the next $K$ cells, destroys the next cell, and so on until he reaches (and rests in or destroys) the last cell he visits. Anas does not know the value of $K$. Therefore, for each value of $K$ between $0$ and $N \cdot M - 1$ inclusive, he wants to calculate the number of cells that will be destroyed by at least one hero. Can you help him? -----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 $N \cdot M$ space-separated integers as described above. -----Constraints----- - $1 \le T \le 100$ - $2 \le N, M \le 1,000$ - the sum of $N \cdot M$ over all test cases does not exceed $2 \cdot 10^6$ -----Subtasks----- Subtask #1 (30 points): - $2 \le N, M \le 50$ - the sum of $N \cdot M$ over all test cases does not exceed $5,000$ Subtask #2 (70 points): original constraints -----Example Input----- 1 2 3 -----Example Output----- 6 4 3 3 2 1 -----Explanation----- Example case 1: - $K = 0$: All cells will be destroyed by the heroes. - $K = 1$: The first hero will destroy the cells $[(1,1), (1,3), (2,2)]$, while the second one will destroy the cells $[(1,1), (1,2), (1,3)]$. - $K = 2$: The first hero will destroy the cells $[(1,1), (2,1)]$, while the second one will destroy the cells $[(1,1), (2,2)]$. - $K = 3$: The first hero will destroy the cells $[(1,1), (2,2)]$, while the second one will destroy the cells $[(1,1), (1,3)]$. - $K = 4$: The first hero will destroy the cells $[(1,1), (2,3)]$ and the second one will also destroy the cells $[(1,1), (2,3)]$. - $K = 5$ : The first hero will destroy the cell $(1,1)$ and the second one will also destroy the cell $(1,1)$.
["\"\"\"\nCode chef problem DESTCELL, Destroy Cells\n\"\"\"\n\n\ndef find_destroyed_cells(cell_advance, n, m, k):\n row = 1\n col = 1\n destroyed_cells = {(1, 1)}\n while True:\n row, col = cell_advance(row, col, n, m, k)\n if row <= n and col <= m:\n destroyed_cells.add((row, col))\n else:\n break\n return destroyed_cells\n\n\ndef cell_advance_hero1(row, col, n, m, k):\n return row + (col + k) // m, (col + k) % m + 1\n\n\ndef cell_advance_hero2(row, col, n, m, k):\n return (row + k) % n + 1, col + (row + k)//n\n\n\ndef main():\n t = int(input())\n for _ in range(t):\n n, m = [int(s) for s in input().split(' ')]\n counts = []\n for k in range(n*m):\n cells_h1 = find_destroyed_cells(cell_advance_hero1, n, m, k)\n cells_h2 = find_destroyed_cells(cell_advance_hero2, n, m, k)\n\n destroyed = len(cells_h1) + len(cells_h2) - len(cells_h1 & cells_h2)\n counts.append(destroyed)\n print(' '.join([str(c) for c in counts]))\n\n\nmain()\n", "t = int(input())\nwhile t > 0:\n ans = []\n n, m = list(map(int, input().split()))\n temp = []\n for k in range(0, n*m):\n myset1 = set()\n myset2 = set()\n if k == 0:\n ans.append(n*m)\n elif k == n*m - 1:\n ans.append(1)\n else:\n for j in range(1, m+1):\n i = j\n while i <= n*m:\n temp.append(i)\n i += m\n i = 1\n while i <= n*m:\n myset1.add(i)\n i = i + k + 1\n i = 0\n while i <= n*m-1:\n myset2.add(temp[i])\n i = i + k + 1\n current = list(myset1.union(myset2))\n ans.append(len(current))\n print(*ans)\n t -= 1\n", "t = int(input(''))\nfor v in range(t):\n a = input('').split(' ')\n n = int(a[0])\n m = int(a[1])\n ans = [0]*(n*m)\n for k in range(0,n*m,1):\n su = 2*((n*m-1)//(k+1)+1)\n g = 0\n while(g<n*m):\n j = g%(m)\n i = g//m\n #print((j*n + i),g,k+1)\n if((j*n + i)%(k+1) == 0):\n su = su - 1\n #print(g,su)\n g = g + (k+1)\n print(su, end = ' ')\n print('')\n ", "t = int(input(''))\nfor v in range(t):\n a = input('').split(' ')\n n = int(a[0])\n m = int(a[1])\n ans = [0]*(n*m)\n for k in range(0,n*m,1):\n su = 2*((n*m-1)//(k+1)+1)\n g = 0\n while(g<n*m):\n j = g%(m)\n i = g//m\n #print((j*n + i),g,k+1)\n if((j*n + i)%(k+1) == 0):\n su = su - 1\n #print(g,su)\n g = g + (k+1)\n print(su, end = ' ')\n print('')\n ", "# cook your dish here\nfrom math import ceil\nfor _ in range(int(input())):\n n,m=list(map(int,input().split()))\n l=[str(n*m)]\n #print(ceil(5.3))\n for i in range(1,n*m):\n c=2*ceil((n*m)/(i+1))\n #print(c,\"sas\",(n*m)/(i+1))\n for k in range(0,n*m,i+1):\n r=k%m\n q=k//m\n if((r*n+q)%(i+1)==0):\n c-=1\n l.append(str(c))\n print(\" \".join(l))", "# cook your dish here\ndef destroy_cells(N,M):\n print(N*M,end=' ')\n \n for k in range(1,N*M-1):\n row,col,i,j = 0,0,0,0\n positions = [(0,0)]\n \n while row < N or col < M:\n j = j+k+1\n if j >= M:\n row += j//M\n if row < N:\n j = j%M\n positions.append((row,j))\n \n i = i+k+1\n if i >= N:\n col += i//N\n if col < M:\n i = i%N\n positions.append((i,col))\n \n positions = set(positions)\n print(len(positions),end=' ')\n \n print(1)\n\ntest = int(input())\nfor i in range(test):\n (N,M) = (map(int,input().split()))\n destroy_cells(N,M)", "t=int(input())\nfor tc in range(t):\n n,m=map(int,input().split())\n s=n*m\n x=[]\n y=[]\n z=[]\n a=[]\n print(n*m,end=\" \")\n for i in range(1,n+1):\n for j in range(1,m+1):\n x.append([i,j])\n for j in range(1,m+1):\n for i in range(1,n+1):\n y.append([i,j])\n for k in range(1,m*n):\n a=[]\n z=[]\n for i in range(0,n*m,k+1):\n z.append(x[i])\n for j in range(0,n*m,k+1):\n z.append(y[j]) \n for i in z:\n if i not in a:\n a.append(i) \n print(len(a),end=\" \")\n print()\n", "t=int(input())\nfor tc in range(t):\n n,m=map(int,input().split())\n s=n*m\n x=[]\n y=[]\n z=[]\n a=[]\n print(n*m,end=\" \")\n for i in range(1,n+1):\n for j in range(1,m+1):\n x.append([i,j])\n for j in range(1,m+1):\n for i in range(1,n+1):\n y.append([i,j])\n for k in range(1,m*n):\n a=[]\n z=[]\n for i in range(0,n*m,k+1):\n z.append(x[i])\n for j in range(0,n*m,k+1):\n z.append(y[j]) \n for i in z:\n if i not in a:\n a.append(i) \n print(len(a),end=\" \")\n print()\n", "# cook your dish here\nt=int(input())\nfor i in range(t):\n n,m=map(int,input().split())\n for k in range(n*m):\n s=''\n t=''\n for i in range(n*m):\n s+='0'\n i=0\n while(i<len(s)):\n s=s[:i]+'1'+s[i+1:]\n i+=k+1\n i=0\n for i in range(n):\n while(i<len(s)):\n t+=s[i]\n i+=n \n i=0\n while(i<len(t)):\n t=t[:i]+'1'+t[i+1:]\n i+=k+1\n print(t.count('1'),' ',end='')\n \n \n \n \n \n \n \n \n \n", "for x in range(int(input())):\n n,m=map(int,input().split())\n y=n*m\n print(y,end=\" \")\n for x in range(1,n*m):\n ans = 2*(1+ (n*m-1)//(x+1))\n mu=0\n while(mu<y):\n n1=mu//m\n m1=mu%m\n y2=m1*n+n1\n if(y2%(x+1)==0):\n ans-=1\n mu+=x+1\n print(ans,end=\" \")\n print(\"\")\n", "for x in range(int(input())):\n n,m=map(int,input().split())\n y=n*m\n l=[]\n for x in range(n*m):\n p=x+1\n if(y%p==0):\n ans=2*(y//p)\n else:\n ans=2*((y//p)+1)\n mu=0\n while(mu<y):\n n1=mu//m\n m1=mu%m\n y2=m1*n+n1\n if(y2%(x+1)==0):\n ans-=1\n mu+=x+1\n print(ans,end=\" \")\n print(\"\")\n", "for x in range(int(input())):\n n,m=map(int,input().split())\n y=n*m\n for x in range(n*m):\n a=1\n b=1\n d={(1,1):1}\n count=1\n if x==0:\n print(n*m,end=\" \")\n continue\n while(True):\n b=b+x+1\n if(b>m):\n u=b-m\n if(u%m==0):\n a=a+u//m\n b=m\n else:\n a=a+(u//m)+1\n b=u%m\n if a>n:\n break\n else:\n d[(a,b)]=1\n count+=1\n a=1\n b=1\n while(True):\n a=a+x+1\n if(a>n):\n u=a-n\n if(u%n==0):\n b=b+u//n\n a=n\n else:\n b=b+(u//n)+1\n a=u%n\n if b>m:\n break\n else:\n if (a,b) not in d.keys():\n count+=1\n print(count,end=\" \")\n print(\"\")\n \n \n", "for _ in range(int(input())):\n n,m=map(int,input().split())\n lim=n*m+1\n k=lim-1\n lst=[int(num) for num in range(1,lim)]\n lst2=[]\n for val in range(1,m+1):\n for val2 in range(n):\n lst2.append(val+(m*(val2)))\n for val_k in range(k):\n lst_k=[]\n for index in range(0,lim-1,val_k+1):\n lst_k.append(lst[index])\n lst_k.append(lst2[index])\n print(len(set(lst_k)),end=\" \")\n print()", "for x in range(int(input())):\n n,m=map(int,input().split())\n y=n*m\n l=[(1,1)]\n for x in range(n*m):\n l=[(1,1)]\n a=1\n b=1\n if x==0:\n print(n*m,end=\" \")\n continue\n while(True):\n b=b+x+1\n if(b>m):\n u=b-m\n if(u%m==0):\n a=a+u//m\n b=m\n else:\n a=a+(u//m)+1\n b=u%m\n if a>n:\n break\n else:\n l.append((a,b))\n a=1\n b=1\n while(True):\n a=a+x+1\n if(a>n):\n u=a-n\n if(u%n==0):\n b=b+u//n\n a=n\n else:\n b=b+(u//n)+1\n a=u%n\n if b>m:\n break\n else:\n l.append((a,b))\n print(len(set(l)),end=\" \")\n print(\"\")\n \n \n", "for x in range(int(input())):\n n,m=map(int,input().split())\n y=n*m\n l=[(1,1)]\n for x in range(n*m):\n l=[(1,1)]\n a=1\n b=1\n while(True):\n b=b+x+1\n if(b>m):\n u=b-m\n if(u%m==0):\n a=a+u//m\n b=m\n else:\n a=a+(u//m)+1\n b=u%m\n if a>n:\n break\n else:\n l.append((a,b))\n a=1\n b=1\n while(True):\n a=a+x+1\n if(a>n):\n u=a-n\n if(u%n==0):\n b=b+u//n\n a=n\n else:\n b=b+(u//n)+1\n a=u%n\n if b>m:\n break\n else:\n l.append((a,b))\n print(len(set(l)),end=\" \")\n print(\"\")\n \n \n", "# cook your dish here\nt=int(input())\nl =[]\nfor i in range(0,t):\n ele=list(map(int,input().split()))\n l.append(ele)\nfor i in range(0, t):\n n=l[i][0]\n m=l[i][1]\n f1=[]\n f2=[]\n for j in range(1,n+1):\n for h in range(1, m + 1):\n f1.append((j,h))\n for j in range(1,m+1):\n for h in range(1, n+ 1):\n f2.append((h,j))\n\n for k in range(0,n*m):\n if k==0:\n print(n*m,end=' ')\n else:\n y=[]\n z=[]\n e=0\n while e*(k+1)<n*m:\n\n y.append(f1[e*(k+1)])\n z.append(f2[e*(k+1)])\n e=e+1\n\n for x in z:\n if x not in y:\n y.append(x)\n\n print(len(y),end=' ')", "# cook your dish here\nans = set()\nfor _ in range(int(input())):\n r,c = map(int,input().split())\n count = 0\n for i in range(0,r*c): \n ans.clear()\n for x in range(0,r*c,i+1):\n a = x//r\n b = x%r\n ans.add((a,b))\n a = x%c\n b = x//c\n ans.add((a,b))\n \n print(len(ans), end= \" \")", "ans = [[False for _ in range(1000)] for _ in range(1000)]\nfor _ in range(int(input())):\n r,c = map(int,input().split())\n count = 0\n for i in range(0,r*c):\n val = 0\n for x in range(0,r*c,i+1):\n a = x//r\n b = x%r\n \n # ans.add((a,b))\n if not ans[a][b]:\n ans[a][b] = True\n val+=1\n a = x%c\n b = x//c\n # ans.add((a,b))\n if not ans[a][b]:\n ans[a][b]=True\n val+=1\n \n for x in range(0,r*c,i+1):\n a = x//r\n b = x%r \n ans[a][b]=False\n a = x%c\n b = x//c\n ans[a][b]=False\n \n \n print(val, end= \" \")", "ans = [[False for _ in range(1001)] for _ in range(1001)]\nfor _ in range(int(input())):\n r,c = map(int,input().split())\n count = 0\n for i in range(0,r*c):\n val = 0\n for x in range(0,r*c,i+1):\n a = x//r\n b = x%r\n \n # ans.add((a,b))\n ans[a][b] = True\n a = x%c\n b = x//c\n # ans.add((a,b))\n ans[a][b]=True\n \n for x in range(0,r*c,i+1):\n \n a = x//r\n b = x%r\n \n if ans[a][b] == True:\n ans[a][b]=False\n val+=1\n a = x%c\n b = x//c\n if ans[a][b] == True:\n ans[a][b]=False\n val+=1\n \n \n print(val, end= \" \")", "# cook your dish here\nfor _ in range(int(input())):\n r,c = map(int,input().split())\n count = 0\n for i in range(0,r*c): \n ans = set()\n for x in range(0,r*c,i+1):\n a = x//r\n b = x%r\n ans.add((a,b))\n a = x%c\n b = x//c\n ans.add((a,b))\n \n print(len(ans), end= \" \")", "# cook your dish here\nfor _ in range(int(input())):\n r,c = map(int,input().split())\n count = 0\n for i in range(0,r*c): \n ans = list()\n for x in range(0,r*c,i+1):\n a = x//r\n b = x%r\n ans.append((a,b))\n a = x%c\n b = x//c\n ans.append((a,b))\n \n print(len(set(ans)), end= \" \")"]
{"inputs": [["1", "2 3"]], "outputs": [["6 4 3 3 2 1"]]}
INTERVIEW
PYTHON3
CODECHEF
10,302
d19b4b7a25cc7b9723ec586f9d8e628e
UNKNOWN
Scheme? - Too loudly said. Just a new idea. Now Chef is expanding his business. He wants to make some new restaurants in the big city of Lviv. To make his business competitive he should interest customers. Now he knows how. But don't tell anyone - it is a secret plan. Chef knows four national Ukrainian dishes - salo, borsch, varenyky and galushky. It is too few, of course, but enough for the beginning. Every day in his restaurant will be a dish of the day among these four ones. And dishes of the consecutive days must be different. To make the scheme more refined the dish of the first day and the dish of the last day must be different too. Now he wants his assistant to make schedule for some period. Chef suspects that there is more than one possible schedule. Hence he wants his assistant to prepare all possible plans so that he can choose the best one among them. He asks you for help. At first tell him how many such schedules exist. Since the answer can be large output it modulo 109 + 7, that is, you need to output the remainder of division of the actual answer by 109 + 7. -----Input----- The first line of the input contains an integer T, the number of test cases. Each of the following T lines contains a single integer N denoting the number of days for which the schedule should be made. -----Output----- For each test case output a single integer in a separate line, the answer for the corresponding test case. -----Constraints-----1 ≤ T ≤ 100 2 ≤ N ≤ 109 -----Example----- Input: 3 2 3 5 Output: 12 24 240 -----Explanation----- Case 1. For N = 2 days we have the following 12 schedules: First day Second day salo borsch salo varenyky salo galushky borsch salo borsch varenyky borsch galushky varenyky salo varenyky borsch varenyky galushky galushky salo galushky borsch galushky varenyky Case 2. For N = 3 we have the following 24 schedules: First daySecond dayThird day salo borsch varenyky salo borsch galushky salo varenyky borsch salo varenyky galushky salo galushky borsch salo galushky varenyky borsch salo varenyky borsch salo galushky borsch varenyky salo borsch varenyky galushky borsch galushky salo borsch galushky varenyky varenyky salo borsch varenyky salo galushky varenyky borsch salo varenyky borsch galushky varenyky galushky salo varenyky galushky borsch galushky salo borsch galushky salo varenyky galushky borsch salo galushky borsch varenyky galushky varenyky salo galushky varenyky borsch Case 3. Don't be afraid. This time we will not provide you with a table of 240 schedules. The only thing we want to mention here is that apart from the previous two cases schedules for other values of N can have equal dishes (and even must have for N > 4). For example the schedule (salo, borsch, salo, borsch) is a correct schedule for N = 4 while the schedule (varenyky, salo, galushky, verynky, salo) is a correct schedule for N = 5.
["r = 1000000007\nt = int(input())\nfor i in range(t):\n n = int(input())\n print(pow(3,n,r) + pow(-1,n)*3)\n \n", "import sys\n\nL = 10**9 + 7\n\ndef mat_mult(lst1,lst2,r,c,m):\n res = [[0]*m for i in range(r)]\n for i in range(r):\n for j in range(m):\n res[i][j] = 0\n for k in range(c):\n res[i][j] = (res[i][j] + lst1[i][k]*lst2[k][j])%L\n\n return res\n\n\ndef main():\n mat = [[-1,0,0,0],[1,3,0,0],[0,0,-1,0],[0,0,1,3]]\n result = [[24,108,12,36]]\n t = int(input())\n lst = [None]*t\n for i in range(t):\n lst[i] = int(input())\n for i in range(t):\n if lst[i] == 1:\n print(4)\n continue\n if lst[i] == 2:\n print(12)\n continue\n if lst[i] == 3:\n print(24)\n continue\n mat = [[-1,0,0,0],[1,3,0,0],[0,0,-1,0],[0,0,1,3]]\n result = [[24,108,12,36]]\n N = lst[i] - 3\n while N > 0 :\n if N%2 == 0:\n mat = mat_mult(mat,mat,4,4,4)\n N = N/2\n if N%2 == 1:\n result = mat_mult(result,mat,1,4,4)\n N = N - 1\n print(result[0][0])\n\ndef __starting_point():\n main()\n\n\n\n__starting_point()", "import math\nt=eval(input());\nwhile t:\n a=eval(input());\n if a%2==0:\n s=pow(3,a,1000000007);\n s=s+3;\n print(s);\n else:\n s=pow(3,a,1000000007);\n s=s-3;\n print(s);\n t=t-1;\n", "mod=1000000007\nt=eval(input())\nwhile(t>0):\n flag=0\n n=eval(input())\n if(n>=4):\n if(n%2==0):\n flag=1\n\n ans=1\n base=3\n ans=pow(base,n,mod)\n if(flag==1):\n ans=ans+3\n else:\n ans=ans-3\n print(ans)\n \n else:\n if(n==1):\n print(4) \n \n if(n==2):\n print(12)\n\n if(n==3):\n print(24)\n t=t-1\n", "import math\nt=eval(input());\nwhile t:\n a=eval(input());\n if a%2==0:\n s=pow(3,a,1000000007);\n s=s+3;\n print(s);\n else:\n s=pow(3,a,1000000007);\n s=s-3;\n print(s);\n t=t-1;", "import math\nt=eval(input());\nwhile t:\n a=eval(input());\n if a%2==0:\n s=pow(3,a,1000000007);\n s=s+3;\n print(s);\n else:\n s=pow(3,a,1000000007);\n s=s-3;\n print(s);\n t=t-1;", "import math \nt=eval(input());\nwhile t:\n n=eval(input());\n if n%2==0:\n x=pow(3,n,1000000007);\n x=x+3;\n print(x);\n else:\n x=pow(3,n,1000000007);\n x=x-3;\n print(x);\n t=t-1;", "L=1000000007\ndef pow(a,b):\n if b==0:\n return 1\n elif b==1:\n return a\n else:\n nonlocal L\n x=pow(a,b//2)\n y=pow(a,b%2)\n r=(x*x)%L\n r=(r*y)%L\n return r\nfor i in range(int(input())):\n N=int(input())\n p=pow(3,N)+3 if N%2==0 else pow(3,N)-3\n print(p)\n", "t = int(input())\nfor i in range(t):\n n = int(input())\n if n&1 == 0 :\n print(pow(3, n, 1000000000 + 7) + 3)\n else:\n print(pow(3, n, 1000000000 + 7) - 3)", "\n\nMOD = 1000000007\n\ndef powmod(base,exp):\n if exp == 0:\n return 1\n elif exp & 1:\n return (base * powmod(base,exp-1)) % MOD\n else:\n return powmod((base*base) % MOD,exp//2) % MOD\n\n\n\nt = eval(input())\nfor i in range (0, int(t)):\n n = eval(input())\n k = int(n)//2\n if (int(n) & 1):\n result = 3 * (powmod(9,k)-1)\n else:\n result = powmod(9,k)+3\n print(result % MOD)\n", "MOD = 1000000007\n \nt=eval(input())\nt=int(t)\nwhile(t>0):\n t=t-1\n n=eval(input())\n n=int(n)\n m=n\n result = 1\n x=3\n while(n>0):\n if(n&1):\n result=(result*x)%MOD\n x=(x*x)%MOD\n n=n>>1\n if(m%2==1):\n print(result-3)\n else:\n print((result+3)%MOD)\n", "def go():\n for t in range(int(input())):\n n = int(input())\n v = pow(3,n,1000000007)+(-3 if n&1 else 3)\n print(v%1000000007)\n\ngo()\n", "def main():\n t=int(input())\n i=0\n while i<t:\n i=i+1\n n=int(input())\n ans=pow(3,n-1,1000000007)-pow(-1,n-1,1000000007)\n print((3*ans)%1000000007)\n return 0\n \nmain()\n", "t = eval(input())\nt = int(t)\nc =1000000007\nfor each in range(t):\n n = eval(input())\n n = int(n)\n n2 = n\n result = 1\n base = 3\n while(n>0): \n if(n%2==1): \n result = (result*base)%c\n n = n>>1\n base = (base*base)%c\n if(n2%2==0):\n result = result+3\n else:\n result = result-3\n print(str(result))\n", "#!/usr/bin/python\nimport sys\nm=1000000007\ndef dcexpo(b,p):\n if p==0:\n return 1\n temp=dcexpo(b,p>>1)\n temp=temp**2\n if p&1:\n temp=temp*b\n return temp%m\n \nt = int(input())\nfor test in range(t):\n k=int(input())\n ret=dcexpo(3,k)\n if k&1:\n ret-=3\n else:\n ret+=3\n print(ret)\n"]
{"inputs": [["3", "2", "3", "5"]], "outputs": [["12", "24", "240"]]}
INTERVIEW
PYTHON3
CODECHEF
4,267
ee46f4f9671c017940001aeb6873a277
UNKNOWN
Chef has an array A consisting of N integers. He also has an intger K. Chef wants you to find out number of different arrays he can obtain from array A by applying the following operation exactly K times. - Pick some element in the array and multiply it by -1 As answer could be quite large, print it modulo 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 first line of each test case contains two space separated integers N, K as defined above. - The second line contains N space-separated integers A1, A2, ..., AN denoting the elements of the array. -----Output----- - For each test case, output a single line containing an integer corresponding to the number of different arrays Chef can get modulo 109 + 7. -----Constraints----- - 1 ≤ T ≤ 10 - 1 ≤ N, K ≤ 105 - -106 ≤ Ai ≤ 106 -----Subtasks----- - Subtask #1 (10 points) : N, K ≤ 10 - Subtask #2 (30 points) : N, K ≤ 100 - Subtask #3 (60 points) : N, K ≤ 105 -----Example----- Input: 3 1 3 100 3 1 1 2 1 3 2 1 2 1 Output: 1 3 4 -----Explanation----- Example case 1. Chef has only one element and must apply the operation 3 times to it. After applying the operations, he will end up with -100. That is the only array he will get. Example case 2. Chef can apply operation to one of three elements. So, he can obtain three different arrays. Example case 3. Note that other than applying operation to positions (1, 2), (1, 3), (2, 3), Chef can also apply the operation twice on some element and get the original. In summary, Chef can get following four arrays. [1, 2, 1] [-1, -2, 1] [-1, 2, -1] [1, -2, -1]
["fact = []\nfact.append(1)\nfor i in range(1,100001):\n fact.append((i*fact[i-1])%1000000007)\n \ndef power(a,b,p):\n x=1\n y=a\n while(b>0):\n if(b%2 == 1):\n x=(x*y)\n if(x>p):\n x=x%p\n y=(y*y)\n if(y>p):\n y=y%p\n b=b/2\n \n return x\n \ndef inverse(N,p):\n return power(N,p-2,p)\n \ndef combination(N,R,p):\n return (fact[N]*((inverse(fact[R],p)*inverse(fact[N-R],p))%p))%p\n \nT = int(input())\n \nfor i in range(T):\n N,K = [int(y) for y in input().split()]\n A = [int(arr) for arr in input().split()]\n numZ = 0;\n answer = 0;\n p = 1000000007\n for j in range(len(A)):\n if(A[j] == 0):\n numZ = numZ + 1\n N = N - numZ\n if(numZ > 0):\n if(N > K):\n temp = K;\n while(temp >= 0):\n answer = answer + combination(N,temp,p)\n temp = temp - 1\n else:\n temp = N\n while(temp >= 0):\n answer = answer + combination(N,temp,p)\n temp = temp - 1\n else:\n if(N > K):\n temp = K;\n while(temp >= 0):\n answer = answer + combination(N,temp,p)\n temp = temp - 2\n else:\n temp = N\n while(temp >= 0):\n answer = answer + combination(N,temp,p)\n temp = temp - 2\n print(answer%1000000007)", "import math\n\ndef nCr(n,r):\n f = math.factorial\n return f(n) / f(r) / f(n-r)\n\n\nt = int(input())\n\nfor i in range(0,t):\n a = input().split()\n n = int(a[0])\n k = int(a[1])\n\n arr = input().split()\n\n arr = [int(x) for x in arr]\n\n count = 0\n\n for j in arr:\n if j == 0:\n count = count + 1\n\n ways = 0\n\n\n if(count == 0):\n if(k%2 == 0):\n l=0\n while l<=min(n,k):\n ways = ways + nCr(n,l)\n l = l+2\n\n else:\n l = 1\n while l<=min(n,k):\n ways = ways + nCr(n,l)\n l = l+2\n\n print(ways)\n\n else:\n n = n-count\n l = 0\n\n while l <= min(n,k):\n ways = ways + nCr(n,l)\n l = l+1\n\n print(ways)\n", "mod = 10**9 + 7\nfor t in range(int(input())):\n n, k = list(map(int, input().split()))\n a = list(map(int, input().split()))\n ans = 0\n temp = 1\n limit = min(n,k)+1\n c = a.count(0)\n if (c == 0):\n x = k%2\n for i in range(0, limit):\n if (i%2 == x):\n ans += temp\n ans %= mod\n temp = (temp * (n-i)) / (1+i)\n else:\n n = n-c\n for i in range(0, limit):\n ans += temp\n ans %= mod\n temp = (temp * (n-i)) / (1+i)\n print(ans) ", "mod = 10**9 + 7\nmod2 = 10**100\nfor t in range(int(input())):\n n, k = list(map(int, input().split()))\n a = list(map(int, input().split()))\n ans = 0\n temp = 1\n limit = min(n,k)+1\n c = a.count(0)\n if (c == 0):\n x = k%2\n for i in range(0, limit):\n if (i%2 == x):\n ans += temp\n ans %= mod\n temp = (temp * (n-i)) / (1+i)\n temp %= mod2\n else:\n n = n-c\n for i in range(0, limit):\n ans += temp\n ans %= mod\n temp = (temp * (n-i)) / (1+i)\n temp %= mod2\n print(ans) ", "mod = 10**9 + 7\nmod2 = 10**72\nfor t in range(int(input())):\n n, k = list(map(int, input().split()))\n a = list(map(int, input().split()))\n ans = 0\n temp = 1\n limit = min(n,k)+1\n c = a.count(0)\n if (c == 0):\n x = k%2\n for i in range(0, limit):\n if (i%2 == x):\n ans += temp\n ans %= mod\n temp = (temp * (n-i)) / (1+i)\n temp %= mod2\n else:\n n = n-c\n for i in range(0, limit):\n ans += temp\n ans %= mod\n temp = (temp * (n-i)) / (1+i)\n temp %= mod2\n print(ans) ", "mod = 10**9 + 7\nmod2 = 10**50\nfor t in range(int(input())):\n n, k = list(map(int, input().split()))\n a = list(map(int, input().split()))\n ans = 0\n temp = 1\n limit = min(n,k)+1\n c = a.count(0)\n if (c == 0):\n x = k%2\n for i in range(0, limit):\n if (i%2 == x):\n ans += temp\n ans %= mod\n temp = (temp * (n-i)) / (1+i)\n temp %= mod2\n else:\n n = n-c\n for i in range(0, limit):\n ans += temp\n ans %= mod\n temp = (temp * (n-i)) / (1+i)\n temp %= mod2\n print(ans) ", "mod = 10**9 + 7\nmod2 = 10**36\nfor t in range(int(input())):\n n, k = list(map(int, input().split()))\n a = list(map(int, input().split()))\n ans = 0\n temp = 1\n limit = min(n,k)+1\n c = a.count(0)\n if (c == 0):\n x = k%2\n for i in range(0, limit):\n if (i%2 == x):\n ans += temp\n ans %= mod\n temp = (temp * (n-i)) / (1+i)\n temp %= mod2\n else:\n n = n-c\n for i in range(0, limit):\n ans += temp\n ans %= mod\n temp = (temp * (n-i)) / (1+i)\n temp %= mod2\n print(ans) ", "from math import factorial \nmod = 10**9 + 7\nmod2 = 10**36\nfor t in range(int(input())):\n n, k = list(map(int, input().split()))\n a = list(map(int, input().split()))\n ans = 0\n temp = 1\n limit = min(n,k)+1\n c = a.count(0)\n if (c == 0):\n x = k%2\n for i in range(0, limit):\n if (i%2 == x):\n ans += temp\n ans %= mod\n temp = (temp * (n-i)) / (1+i)\n temp %= mod2\n else:\n n = n-c\n for i in range(0, limit):\n ans += temp\n ans %= mod\n temp = (temp * (n-i)) / (1+i)\n temp %= mod2\n print(ans) ", "from math import factorial \nmod = 10**9 + 7\nmod2 = 10**25\nfor t in range(int(input())):\n n, k = list(map(int, input().split()))\n a = list(map(int, input().split()))\n ans = 0\n temp = 1\n limit = min(n,k)+1\n c = a.count(0)\n if (c == 0):\n x = k%2\n for i in range(0, limit):\n if (i%2 == x):\n ans += temp\n ans %= mod\n temp = (temp * (n-i)) / (1+i)\n temp %= mod2\n else:\n n = n-c\n for i in range(0, limit):\n ans += temp\n ans %= mod\n temp = (temp * (n-i)) / (1+i)\n temp %= mod2\n print(ans) ", "from math import factorial \nmod = 10**9 + 7\nmod2 = 10**18\nfor t in range(int(input())):\n n, k = list(map(int, input().split()))\n a = list(map(int, input().split()))\n ans = 0\n temp = 1\n limit = min(n,k)+1\n c = a.count(0)\n if (c == 0):\n x = k%2\n for i in range(0, limit):\n if (i%2 == x):\n ans += temp\n ans %= mod\n temp = (temp * (n-i)) / (1+i)\n temp %= mod2\n else:\n n = n-c\n for i in range(0, limit):\n ans += temp\n ans %= mod\n temp = (temp * (n-i)) / (1+i)\n temp %= mod2\n print(ans) ", "from math import factorial \nmod = 10**9 + 7\nfor t in range(int(input())):\n n, k = list(map(int, input().split()))\n a = list(map(int, input().split()))\n ans = 0\n temp = 1\n limit = min(n,k)+1\n c = a.count(0)\n if (c == 0):\n x = k%2\n for i in range(0, limit):\n if (i%2 == x):\n ans += temp\n ans %= mod\n temp = (temp * (n-i)) / (1+i)\n temp %= mod\n else:\n n = n-c\n for i in range(0, limit):\n ans += temp\n ans %= mod\n temp = (temp * (n-i)) / (1+i)\n temp %= mod\n print(ans) ", "fact = []\nfor i in range(100001):\n fact.append(1)\n\ndef power(a,b,p):\n x=1\n y=a\n while(b>0):\n if(b%2 == 1):\n x=(x*y)\n if(x>p):\n x=x%p\n y=(y*y)\n if(y>p):\n y=y%p\n b=b/2\n\n return x\n\ndef inverse(N,p):\n return power(N,p-2,p)\n\ndef combination(N,R,p):\n for i in range(1,N+1):\n fact[i] = (fact[i-1]*i)%p\n return (fact[N]*((inverse(fact[R],p)*inverse(fact[N-R],p))%p))%p\n \nT = int(input())\n\nfor i in range(T):\n N,K = [int(y) for y in input().split()]\n A = [int(arr) for arr in input().split()]\n numZ = 0;\n answer = 0;\n p = 1000000007\n for j in range(len(A)):\n if(A[j] == 0):\n numZ = numZ + 1\n N = N - numZ\n if(numZ > 0):\n if(N > K):\n temp = K;\n while(temp >= 0):\n answer = answer + combination(N,temp,p)\n temp = temp - 1\n else:\n temp = N\n while(temp >= 0):\n answer = answer + combination(N,temp,p)\n temp = temp - 1\n else:\n if(N > K):\n temp = K;\n while(temp >= 0):\n answer = answer + combination(N,temp,p)\n temp = temp - 2\n else:\n temp = N\n while(temp >= 0):\n answer = answer + combination(N,temp,p)\n temp = temp - 2\n print(answer%1000000007)", "from math import factorial\nM = 10**9+7\n\nfor t in range(int(input())):\n n, k = list(map(int,input().split()))\n a = list(map(int,input().split()))\n z = a.count(0)\n if z==0:\n s = 0\n x = factorial(n)\n for i in range(k%2,min(n,k)+1,2):\n s += ((x/factorial(i))/factorial(n-i))\n s = s%M\n print(s)\n else:\n n=n-z\n s = 0\n x = factorial(n)\n for i in range(0,min(n,k)+1):\n s += ((x/factorial(i))/factorial(n-i))\n s = s%M\n print(s)\n", "import sys\n\ndef fun(n,x):\n res = 1\n for i in range(n, x,-1):\n res = (res*i) % 1000000007\n return res\n\ndef degree(a,k):\n res = 1\n cur = a\n while(k):\n if (k % 2):\n res = (res * cur) % 1000000007\n k /= 2\n cur = (cur * cur) % 1000000007\n return res\n \ndef inv_fun(k):\n denom = 1\n for x in range(1, k+1, 1):\n ti = x;\n while(ti%1000000007 == 0):\n ti /= 1000000007\n denom = (denom*ti) % 1000000007\n denom = degree(denom, 1000000005) % 1000000007\n return denom\n \ndef nCr(n,r):\n return fun(n,n-r)*inv_fun(r)\n\nT = int(input())\n\nfor x in range(T):\n N, K = [int(y) for y in input().split(\" \")]\n array = [int(t) for t in input().split(\" \")]\n count = 0\n for i in range(len(array)):\n if(array[i] == 0):\n count += 1\n K = min(N,K)\n if count != 0:\n sum = 0\n for j in range(0,min(N-count,K)+1):\n sum += nCr(N-count,j)\n \n elif K%2 == 0:\n sum = 0\n for j in range(0,K+1,2):\n sum += nCr(N,j)\n else:\n sum = 0\n for j in range(1,K+1,2):\n sum += nCr(N,j)%1000000007\n print(sum%1000000007)", "import math\nimport sys\n\ndef fun(n,x):\n res = 1\n for i in range(n, x,-1):\n res = (res*i) %1000000007\n return res\n\ndef degree(a,k):\n res = 1\n cur = a\n while(k):\n if (k % 2):\n res = (res * cur) % 1000000007\n k /= 2\n cur = (cur * cur) % 1000000007\n return res\n \ndef inv_fun(k):\n denom = 1\n for x in range(1, k+1, 1):\n denom = (denom*x) % 1000000007\n denom = degree(denom, 1000000005) % 1000000007\n return denom\n \ndef nCr(n,r):\n return (fun(n,n-r)*inv_fun(r))%1000000007\n \nT = int(input())\nfor x in range(T):\n N, K = [int(y) for y in input().split(\" \")]\n array = [int(t) for t in input().split(\" \")]\n count = 0\n for i in range(len(array)):\n if(array[i] == 0):\n count += 1\n K = min(N,K)\n if count != 0:\n sum = 0\n for j in range(0,min(N-count,K)+1):\n sum += nCr(N-count,j)\n \n elif K%2 == 0:\n sum = 0\n for j in range(0,K+1,2):\n sum += nCr(N,j)\n else:\n sum = 0\n for j in range(1,K+1,2):\n sum += nCr(N,j)\n print(sum%1000000007)", "import math\nimport sys\n\ndef fun(n,x):\n res = 1\n for i in range(n, x,-1):\n res = (res*i)%1000000007\n return res\n\ndef degree(a,k):\n res = 1\n cur = a\n while(k):\n if (k % 2):\n res = (res * cur) % 1000000007\n k /= 2\n cur = (cur * cur) % 1000000007\n return res\n \ndef inv_fun(k):\n denom = 1\n for x in range(1, k+1, 1):\n denom = (denom*x) % 1000000007\n denom = degree(denom, 1000000005) % 1000000007\n return denom\n \ndef nCr(n,r):\n return fun(n,n-r)*inv_fun(r)\n \nT = int(input())\nfor x in range(T):\n N, K = [int(y) for y in input().split(\" \")]\n array = [int(t) for t in input().split(\" \")]\n count = 0\n for i in range(len(array)):\n if(array[i] == 0):\n count += 1\n K = min(N,K)\n if count != 0:\n sum = 0\n for j in range(0,min(N-count,K)+1):\n sum += nCr(N-count,j)\n \n elif K%2 == 0:\n sum = 0\n for j in range(0,K+1,2):\n sum += nCr(N,j)\n else:\n sum = 0\n for j in range(1,K+1,2):\n sum += nCr(N,j)\n print(sum%1000000007)"]
{"inputs": [["3", "1 3", "100", "3 1", "1 2 1", "3 2", "1 2 1"]], "outputs": [["1", "3", "4"]]}
INTERVIEW
PYTHON3
CODECHEF
11,054
b800aad7ec9910a761aaeb491c27bc61
UNKNOWN
Chef Tobby asked Bhuvan to brush up his knowledge of statistics for a test. While studying some distributions, Bhuvan learns the fact that for symmetric distributions, the mean and the median are always the same. Chef Tobby asks Bhuvan out for a game and tells him that it will utilize his new found knowledge. He lays out a total of 109 small tiles in front of Bhuvan. Each tile has a distinct number written on it from 1 to 109. Chef Tobby gives Bhuvan an integer N and asks him to choose N distinct tiles and arrange them in a line such that the mean of median of all subarrays lies between [N-1, N+1], both inclusive. The median of subarray of even length is the mean of the two numbers in the middle after the subarray is sorted Bhuvan realizes that his book didn’t teach him how to solve this and asks for your help. Can you solve the problem for him? In case, no solution exists, print -1. -----Input section----- First line contains, T, denoting the number of test cases. Each of the next T lines, contain a single integer N. -----Output section----- If no solution, exists print -1. If the solution exists, output N space separated integers denoting the elements of the array A such that above conditions are satisfied. In case, multiple answers exist, you can output any one them. -----Input constraints----- 1 ≤ T ≤ 20 1 ≤ N ≤ 100 -----Sample Input----- 3 1 2 3 -----Sample Output----- 1 1 2 1 2 3 -----Explanation----- For test case 3, the subarrays and their median are as follows: - {1}, median = 1 - {2}, median = 2 - {3}, median = 3 - {1, 2}, median = 1.5 - {2, 3}, median = 2.5 - {1, 2, 3}, median = 2 The mean of the medians is 2 which lies in the range [2, 4]
["x=int(input())\nfor a in range(x):\n n=int(input())\n L=[str(n)]\n c=1\n while(len(L)!=n):\n L.append(str(n+c))\n if len(L)==n:\n break\n L.append(str(n-c))\n\n c+=1\n\n a=\" \".join(L)\n\n print(a)\n", "t = int(input())\nfor it in range(t):\n n = int(input())\n if n == 1:\n print(1, end=' ')\n elif n%2 == 0:\n for i in range(n//2, n//2+n):\n print(i, end=' ')\n else:\n for i in range(n//2, n//2+n):\n print(i, end=' ')\n print('')\n", "import sys\n\nt = int(sys.stdin.readline().strip())\n\nwhile t:\n n = int(sys.stdin.readline().strip())\n\n if n == 1:\n st = 1\n elif n == 2:\n st = \"1 2\"\n elif n == 3:\n st = \"1 2 3\"\n else:\n \n \n j = n//2 +1\n add = []\n for i in range(n):\n add.append(str(n-i+j-1))\n\n st = \" \".join(add)\n print(st)\n \n t-=1\n\n\n\n\n", "import sys\nt = int(sys.stdin.readline().strip())\nc=[]\nfor i in range(t):\n c+=[int(sys.stdin.readline().strip())]\n\ndef check(s):\n if s==1:\n return \"1\"\n m = int(((s-1)/2.0)+0.6)\n st=\"\"\n for i in range(m,m+s):\n st=st+\" \"+str(i)\n return st[2:]\n\nfor h in c:\n print(check(h))"]
{"inputs": [["3", "1", "2", "3"]], "outputs": [["1", "1 2", "1 2 3"]]}
INTERVIEW
PYTHON3
CODECHEF
1,099
9c623e6d1bb332cce9147d7514b06bf1
UNKNOWN
"I'm a fan of anything that tries to replace actual human contact." - Sheldon. After years of hard work, Sheldon was finally able to develop a formula which would diminish the real human contact. He found k$k$ integers n1,n2...nk$n_1,n_2...n_k$ . Also he found that if he could minimize the value of m$m$ such that ∑ki=1$\sum_{i=1}^k$n$n$i$i$C$C$m$m$i$i$ is even, where m$m$ = ∑ki=1$\sum_{i=1}^k$mi$m_i$, he would finish the real human contact. Since Sheldon is busy choosing between PS-4 and XBOX-ONE, he want you to help him to calculate the minimum value of m$m$. -----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 k$k$. - Next line contains k space separated integers n1,n2...nk$n_1,n_2...n_k$ . -----Output:----- For each test case output the minimum value of m for which ∑ki=1$\sum_{i=1}^k$n$n$i$i$C$C$m$m$i$i$ is even, where m$m$=m1$m_1$+m2$m_2$+. . . mk$m_k$ and 0$0$ <= mi$m_i$<= ni$n_i$ . If no such answer exists print -1. -----Constraints----- - 1≤T≤1000$1 \leq T \leq 1000$ - 1≤k≤1000$1 \leq k \leq 1000$ - 1≤ni≤10$1 \leq n_i \leq 10$18$18$ -----Sample Input:----- 1 1 5 -----Sample Output:----- 2 -----EXPLANATION:----- 5$5$C$C$2$2$ = 10 which is even and m is minimum.
["t = int(input())\n\ndef conv(n):\n k = bin(n)\n k = k[2:]\n z = len(k)\n c = '1'*z\n if c == k:\n return False\n\ndef find(n):\n\n x = bin(n)[2:]\n str = ''\n for i in x[::-1]:\n if i == '0':\n str+='1'\n break\n else:\n str+='0'\n\n return int(str[::-1],2)\n\nfor i in range(t):\n\n n = int(input())"]
{"inputs": [["1", "1", "5"]], "outputs": [["2"]]}
INTERVIEW
PYTHON3
CODECHEF
361
0a564f2b55389fbcb62c9b32bc8eb482
UNKNOWN
A reversed arabic no is one whose digits have been written in the reversed order. However in this any trailing zeroes are omitted. The task at hand here is a simple one. You need to add two numbers which have been written in reversed arabic and return the output back in reversed arabic form, assuming no zeroes were lost while reversing. -----Input----- The input consists of N cases. The first line of the input contains only a positive integer N. Then follow the cases. Each case consists of exactly one line with two positive integers seperated by space. These are the reversednumbers you are to add. -----Output----- For each case, print exactly one line containing only one integer- the reversed sum of two reversed numbers. Omit any leading zeroes in the output. -----Example----- Input: 1 24 1 Output: 34
["n = int(input())\nfor index in range(0, n):\n a, b = list(map(str, input().split()))\n a = int(a[::-1])\n b = int(b[::-1])\n a = str(a + b)\n a = int(a[::-1])\n print(a)", "for _ in range(int(input())):\n n,m=input().split()\n n=int(n[::-1])\n m=int(m[::-1])\n ans=str(n+m)[::-1]\n print(int(ans))", "T = int(input())\nfor ca in range(0, T):\n x, y = (input()).split(' ')\n z = int(str(int(x[::-1]) + int(y[::-1]))[::-1])\n print(z)\n", "#! /usr/bin/python\n\nt = int(input())\n\nfor i in range(t):\n inp = input().split()\n a = list(inp[0])\n b = list(inp[1])\n\n a.reverse()\n b.reverse()\n \n x = int(''.join(a))\n y = int(''.join(b))\n\n c = list(str(x+y))\n c.reverse()\n \n z = int(''.join(c))\n print(z)\n", "t = int(input(\"\"));\nfor i in range(t):\n s1,s2 = (input(\"\").split());\n s1=str(int(s1))\n s2=str(int(s2))\n s1 = s1[::-1];\n s2 = s2[::-1];\n sum = int(s1) + int(s2) ;\n sum = str(sum)\n sum = sum[::-1];\n print(int(sum))", "for case in range(int(input())):\n a,b = input().split()\n print(str(int(a[::-1]) + int(b[::-1]))[::-1].lstrip(\"0\"))", "case = int(input())\nfor i in range(0, case):\n try:\n l = [elem for elem in input().split()]\n res = int(l[0][::-1]) + int(l[1][::-1])\n print(int(str(res)[::-1]))\n except:\n break", "case = int(input())\nfor i in range(0, case):\n try:\n l = [elem for elem in input().split()]\n res = int(l[0][::-1]) + int(l[1][::-1])\n print(int(str(res)[::-1]))\n except:\n break\n", "N=int(input())\ni=0\nwhile i<N:\n a=input()\n a=list(a)\n a.reverse()\n a=''.join(a)\n a=a.split()\n a=int(a[0])+int(a[1])\n a=list(str(a))\n a.reverse()\n a=''.join(a)\n a=str(int(a))\n i=i+1\n print(a)\n", "for tst in range(int(input())):\n m, n = input().split()\n m = m[::-1]\n n = n[::-1]\n m = int(m)\n n = int(n)\n x = m+n\n x = str(x)\n x = x[::-1]\n x = int(x)\n print(x)\n", "#/usr/bin/python\n\ndef main():\n test = int(input())\n for i in range(test):\n x = input()\n l = x.split()\n a = str(l[0])\n b = str(l[1])\n a = a[::-1]\n b = b[::-1]\n c = int(a) + int(b)\n s = str(c)\n s = s[::-1]\n print(int(s))\n\ndef __starting_point():\n main()\n\n\n__starting_point()", "t=int(input())\nfor i in range(t):\n a=input().split()\n print(int(repr(int(a[0][::-1])+int(a[1][::-1]))[::-1]))\n", "for i in range(int(input())):\n x = input()\n a = x.split()[0]\n b = x.split()[1]\n print(str(int(str(int(a[::-1]) + int(b[::-1]))[::-1])))\n"]
{"inputs": [["1", "24 1"]], "outputs": [["34"]]}
INTERVIEW
PYTHON3
CODECHEF
2,406
73766907e18d2f3a18e073707f326c61
UNKNOWN
Sergey recently learned about country codes - two letter strings, denoting countries. For example, BY stands for Belarus and IN stands for India. Mesmerized by this new discovery, Sergey now looks for country codes everywhere! Sergey has recently found a string S consisting of uppercase Latin letters. He wants to find the number of different country codes that appear in S as contiguous substrings. For the purpose of this problem, consider that every 2-letter uppercase string is a valid country code. -----Input----- The first line of 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 string S, consisting of uppercase Latin letters. -----Output----- For each test case, output a single line containing the number of different country codes appearing in the given string. -----Constraints----- - 1 ≤ T ≤ 100 - Subtask 1 (35 points): 2 ≤ |S| ≤ 3 - Subtask 2 (65 points): 2 ≤ |S| ≤ 104 -----Example----- Input:2 INBY BYBY Output:3 2 -----Explanation----- Example case 1. The codes are IN, NB and BY. Example case 2. The codes are BY and YB.
["#import set\nt = eval(input()) \nwhile(t):\n s = input()\n set1 = set()\n j = 0\n for i in s[:-1]:\n a = s[j:j+2]\n set1.add(a)\n j = j + 1\n print(str(len(set1)) + '\\n')\n t= t-1\n \n", "def bck():\n t=eval(input())\n for i in range(t):\n s=input()\n l=[]\n ch=\"\"\n i=0\n while(i!=len(s)-1):\n ch=s[i]+s[i+1]\n l.append(ch)\n i=i+1\n l=set(l)\n print(len(l))\nbck()\n \n \n", "t=int(eval(input()))\nwhile t:\n a=[]\n t=t-1\n s=input()\n a.append(s[:2])\n for i in range(1,len(s)-1):\n c=s[i:i+2]\n if c not in a:\n a.append(c)\n print(str(len(a)))\n ", "t=eval(input())\n\nwhile t>0:\n a=[[0 for x in range(26)] for x in range(26)]\n ans=0\n t-=1\n s=list(input())\n for i in range(len(s)-1):\n #print s[i]\n if a[ord(s[i])-65][ord(s[i+1])-65]==0:\n #print s[i],\"hello\"\n a[ord(s[i])-65][ord(s[i+1])-65]=1\n ans+=1\n print(ans)\n", "t = eval(input())\nwhile t:\n s = input()\n country = []\n for i in range(len(s)-1):\n temp = s[i] + s[i+1]\n country += [temp]\n country = set(country) \n print(len(country))\n t-=1\n", "import sys\n\ndef work():\n\n\tj=eval(input())\n\tfor k in range(j):\n\t\ts=input()\n\t\ta=''\n\t\tcount=0\n\t\tfor i in range(1,len(s)):\n\t\t\ts1=s[i-1]+s[i]\n\t\t\tif a.find(s1) == -1:\n\t\t\t\ta=a+s1\n\t\t\t\tcount+=1\n#\t\t\t\tprint a.find(s1)\n#\t\t\t\tprint s1\n#\t\t\t\tprint a\n\t\tprint(count)\n\ndef main():\n\twork()\n\n\ndef __starting_point():\n\tmain()\n__starting_point()", "t = int(input())\nwhile(t):\n\ta = []\n\tstring = list(input())\n\tfor i in range(len(string)-1):\n\t\ta.append(str(string[i])+str(string[i+1]))\n\n\ta = set(a)\n\tprint(len(a))\n\tt-=1", "t=int(input())\nwhile t>0 :\n t-=1\n s=input()\n d=dict()\n for i in range(0,len(s)-1) :\n word=s[i:i+2]\n d[word]=d.get(word,0)+1\n print(len(d))\n", "t = eval(input())\nfor _ in range(t):\n\ts = input()\n\td = []\n\tl = len(s)\n\tfor a in range(l-1):\n\t\td.append(s[a:a+2])\n\td = set(d)\n\tprint(len(d))", "t=eval(input())\nfor i in range(1,t+1):\n a=input();l=[]\n for i in range(len(a)-1):\n l+=[a[i]+a[i+1]]\n l=set(l)\n print(len(l))", "t = eval(input())\nfor _ in range(t):\n\ts = input()\n\td = []\n\tl = len(s)\n\tfor a in range(l-1):\n\t\td.append(s[a:a+2])\n\td = set(d)\n\tprint(len(d))", "def extract(s):\n codes = {}\n for i in range(len(s) - 1):\n cc = s[i:i + 2]\n if cc not in codes:\n codes[cc] = True\n return len(codes)\n\nt = int(input())\n\nfor i in range(t):\n print(extract(input()))\n \n\n", "import sys\nt=int(input(\"\"))\nwhile t:\n l2=[]\n count=0\n l=str(input(\"\"))\n for i in range(len(l)-1):\n x=l[i]+l[i+1]\n if x not in l2:\n l2.append(x)\n count+=1\n print(count)\n t-=1\n\n \n \n", "for _ in range(eval(input())):\n arr=[None]*677\n inp=input()\n l=len(inp)\n for i in range(l-1):\n a=inp[i]\n b=inp[i+1]\n num=(ord(a)-65)*26 + (ord(b)-65) + 1 \n #print num\n arr[num]=1\n codes=0 \n for i in arr:\n if i==1:\n codes+=1\n print(codes)", "def bck():\n t=eval(input())\n for i in range(t):\n s=input()\n l=[]\n ch=\"\"\n i=0\n while(i!=len(s)-1):\n ch=s[i]+s[i+1]\n l.append(ch)\n i=i+1\n for j in l:\n if j in l[l.index(j)+1:]:\n l.remove(j)\n print(len(l))\nbck()\n \n \n", "for _ in range(int(input())):\n s=input()\n l=[s[i:i+2] for i in range(len(s)-1)]\n print(len(set(l)))\n", "for _ in range(int(input())):\n a=input()\n s=set([])\n for i in range(len(a)-1):\n s.add(a[i:i+2])\n print(len(s))", "for a in range(int(input())):\n arr = []\n s = input().strip()\n for i in range(len(s) - 1):\n if not(s[i:i + 2] in arr):\n arr.append(s[i:i + 2])\n print(len(arr))", "t = eval(input())\nfor i in range(t):\n\tstring = input()\n\tl = len(string)\n\taset = set()\n\tfor i in range(l-1):\n\t\taset.add(string[i:i+2])\n\tprint(len(aset))", "for i in range(int(input())):\n s=input()\n l=[]\n for j in range(len(s)-1):\n l.append(s[j:j+2])\n print(len(set(l)))", "\n\nimport fractions\nimport sys\n\nf = sys.stdin\n\nif len(sys.argv) > 1:\n f = open(sys.argv[1], \"rt\")\n\n\ndef calc(s):\n codes = set()\n for i in range(1, len(s)):\n ch1 = s[i-1]\n ch2 = s[i]\n codes.add((ch1, ch2))\n return len(codes)\n\nT = int(f.readline().strip())\n\nfor case_id in range(1, T+1):\n s = f.readline().strip()\n\n r = calc(s)\n\n print(r)\n", "import sys\n\nt = eval(input())\nfor _ in range(t):\n\ts = list(map(str, sys.stdin.readline().split()))[0]\n\tn = len(s)\n\td = {}\n\tfor i in range(1,n):\n\t\tk = s[i-1:i+1]\n\t\tif k not in d:\n\t\t\td[k] = 0\n\tprint(len(list(d.keys())))"]
{"inputs": [["2", "INBY", "BYBY"]], "outputs": [["3", "2"]]}
INTERVIEW
PYTHON3
CODECHEF
5,198
76c55dfd30cfce4b6e37850e8b1269c3
UNKNOWN
Suppose there is a X x Y x Z 3D matrix A of numbers having coordinates (i, j, k) where 0 ≤ i < X, 0 ≤ j < Y, 0 ≤ k < Z. Now another X x Y x Z matrix B is defined from A such that the (i, j, k) element of B is the sum of all the the numbers in A in the cuboid defined by the (0, 0, 0) and (i, j, k) elements as the diagonally opposite vertices. In other word (i, j, k) in B is the sum of numbers of A having coordinates (a, b, c) such that 0 ≤ a ≤ i, 0 ≤ b ≤ j, 0 ≤ c ≤ k. The problem is that given B, you have to find out A. -----Input----- The first line of input will contain the number of test cases ( ≤ 10). That many test cases will follow in subsequent lines. The first line of each test case will contain the numbers X Y Z (0 ≤ X, Y, Z ≤ 100). After that there will be X x Y lines each containing Z numbers of B. The first line contains the numbers (0, 0, 0), (0, 0, 1)..., (0, 0, Z-1). The second line has the numbers (0, 1, 0), (0, 1, 1)..., (0, 1, Z-1) and so on. The (Y+1)th line will have the numbers (1, 0, 0), (1, 0, 1)..., (1, 0, Z-1) and so on. -----Output----- For each test case print the numbers of A in exactly the same fashion as the input. -----Example----- Input: 2 3 1 1 1 8 22 1 2 3 0 9 13 18 45 51 Output: 1 7 14 0 9 4 18 18 2
["# Problem: http://www.codechef.com/JULY09/submit/CUBESUM/ \n# Author: Susam Pal\n\ndef computeA():\n X, Y, Z = [int(x) for x in input().split()]\n B = []\n for x in range(X):\n B.append([])\n for y in range(Y):\n B[-1].append([int(t) for t in input().split()])\n for z in range(Z):\n result = B[x][y][z]\n if x:\n result -= B[x - 1][y][z]\n if y:\n result += B[x - 1][y - 1][z]\n if z:\n result -= B[x - 1][y - 1][z - 1]\n \n if y:\n result -= B[x][y - 1][z]\n if z:\n result += B[x][y - 1][z - 1]\n if z:\n result -= B[x][y][z - 1]\n if x:\n result += B[x - 1][y][z - 1]\n print(result, end=' ')\n print()\n\ntest_cases = int(input())\nfor i in range(test_cases):\n computeA()\n", "# Problem: http://www.codechef.com/JULY09/submit/CUBESUM/ \n# Author: Susam Pal\n\ndef computeA():\n X, Y, Z = [int(x) for x in input().split()]\n B = []\n for x in range(X):\n B.append([])\n for y in range(Y):\n B[-1].append([int(t) for t in input().split()])\n for z in range(Z):\n result = B[x][y][z]\n if x:\n result -= B[x - 1][y][z]\n if y:\n result += B[x - 1][y - 1][z]\n if z:\n result -= B[x - 1][y - 1][z - 1]\n \n if y:\n result -= B[x][y - 1][z]\n if z:\n result += B[x][y - 1][z - 1]\n if z:\n result -= B[x][y][z - 1]\n if x:\n result += B[x - 1][y][z - 1]\n print(result, end=' ')\n print()\n\ntest_cases = int(input())\nfor i in range(test_cases):\n computeA()\n"]
{"inputs": [["2", "3 1 1", "1", "8", "22", "1 2 3", "0 9 13", "18 45 51"]], "outputs": [["1", "7", "14", "0 9 4", "18 18 2"]]}
INTERVIEW
PYTHON3
CODECHEF
1,524
870f7efc0b566f882127caf129ae71a4
UNKNOWN
A matrix B (consisting of integers) of dimension N × N is said to be good if there exists an array A (consisting of integers) such that B[i][j] = |A[i] - A[j]|, where |x| denotes absolute value of integer x. You are given a partially filled matrix B of dimension N × N. Q of the entries of this matrix are filled by either 0 or 1. You have to identify whether it is possible to fill the remaining entries of matrix B (the entries can be filled by any integer, not necessarily by 0 or 1) such that the resulting fully filled matrix B is good. -----Input----- The first line of the input contains an integer T denoting the number of test cases. The first line of each test case contains two space separated integers N, Q. Each of the next Q lines contain three space separated integers i, j, val, which means that B[i][j] is filled with value val. -----Output----- For each test case, output "yes" or "no" (without quotes) in a single line corresponding to the answer of the problem. -----Constraints----- - 1 ≤ T ≤ 106 - 2 ≤ N ≤ 105 - 1 ≤ Q ≤ 106 - 1 ≤ i, j ≤ N - 0 ≤ val ≤ 1 - Sum of each of N, Q over all test cases doesn't exceed 106 -----Subtasks----- - Subtask #1 (40 points) 2 ≤ N ≤ 103, 1 ≤ Q ≤ 103, Sum of each of N, Q over all test cases doesn't exceed 104 - Subtask #2 (60 points) Original Constraints -----Example----- Input 4 2 2 1 1 0 1 2 1 2 3 1 1 0 1 2 1 2 1 0 3 2 2 2 0 2 3 1 3 3 1 2 1 2 3 1 1 3 1 Output yes no yes no -----Explanation----- Example 1. You can fill the entries of matrix B as follows. 0 1 1 0 This matrix corresponds to the array A = [1, 2]. Example 2. It is impossible to fill the remaining entries of matrix B such that the resulting matrix is good, as B[1][2] = 1 and B[2][1] = 0, which is impossible.
["import sys\nsys.setrecursionlimit(1000000)\n\nmod = 10**9 + 7\nts = int(input())\nwhile ts > 0:\n n,q = list(map(int,input().split()))\n ncc = n-1\n par = [i for i in range(n)]\n rank = [1]*n\n xor = [0]*n\n flag = 1\n\n def find(a):\n if par[a] == a:\n return a\n else:\n temp = find(par[a])\n xor[a]^=xor[par[a]]\n par[a] = temp\n return temp\n\n def union(a,b): \n a,b = find(a),find(b)\n if a ==b:\n return \n if rank[a] > rank[b]:\n par[b] = a\n\n rank[a]+=rank[b]\n elif rank[a] < rank[b]:\n par[a] = b\n rank[b]+=rank[a]\n else:\n par[b] = a\n rank[a]+=rank[b]\n par[b] =a\n\n for _ in range(q):\n \n a,b,x = list(map(int,input().split()))\n a-=1\n b-=1\n if flag == -1:\n continue\n para = find(a)\n parb = find(b)\n\n if para == parb and xor[a] ^ xor[b] != x:\n flag = -1 \n continue\n # print(\"no\")\n\n if para != parb:\n if rank[para] < rank[parb]:\n xor[para] = xor[a] ^ xor[b] ^ x\n par[para] = parb\n rank[parb]+=rank[para]\n else:\n xor[parb] = xor[a] ^ xor[b] ^ x\n par[parb] = para\n rank[para]+=rank[parb]\n ncc-=1\n \n if flag != -1:\n print(\"yes\")\n else:\n print(\"no\")\n \n ts-=1", "def union(a,b):\n fa=find(a)\n fb=find(b)\n if rank[fa]>rank[fb]:\n dsu[fb]=fa\n elif rank[fb]>rank[fa]:\n dsu[fa]=fb\n else:\n rank[fa]+=1\n dsu[fb]=fa\ndef find(x):\n while x!=dsu[x]:\n dsu[x]=dsu[dsu[x]]\n x=dsu[x]\n return x\nfor _ in range(int(input())):\n n,q=list(map(int,input().split()))\n dsu=[i for i in range(n)]\n rank=[0]*n\n ones=[]\n zeros=[]\n for i in range(q):\n a,b,c=list(map(int,input().split()))\n if c==1:\n ones.append([a-1,b-1])\n else:\n zeros.append([a-1,b-1])\n flag=0\n for i in zeros:\n f1=find(i[0])\n f2=find(i[1])\n union(i[0],i[1])\n color=[0]*n\n for i in ones:\n f1=find(i[0])\n f2=find(i[1])\n if f1==f2:\n flag=1\n else:\n #print(color)\n if color[f1]==0 and color[f2]==0:\n color[f1]=-1\n color[f2]=1\n elif color[f1]!=0 and color[f2]==0:\n color[f2]=-color[f1]\n elif color[f2]!=0 and color[f1]==0:\n color[f1]=-color[f2]\n elif color[f2]==color[f1]:\n flag=1\n \n\n print(\"yes\" if flag==0 else \"no\")\n", "store=dict()\nclass node:\n def __init__(self,data):\n self.data=data\n self.parent=None\n self.rank=0\n self.color=None\ndef makeset(data):\n new_node=node(data)\n new_node.parent=new_node\n store[data]=new_node\ndef union(data1,data2):\n node1=store[data1]\n node2=store[data2]\n\n parent1=findset(node1)\n parent2=findset(node2)\n if parent1.data==parent2.data :\n return\n if parent1.rank >= parent2.rank :\n parent1.rank+=int(parent1.rank==parent2.rank)\n parent2.parent=parent1\n else:\n parent1.parent=parent2\ndef findset(new_node):\n parent=new_node.parent\n if new_node==parent :\n return new_node\n new_node.parent=findset(new_node.parent)\n return new_node.parent\ndef repre(data):\n return findset(store[data])\nfrom sys import stdin,stdout\nfor _ in range(int(stdin.readline())):\n n,q=list(map(int,stdin.readline().split()))\n store=dict();different=[]\n for i in range(1,n+1):\n makeset(i)\n for i in range(q):\n a,b,c=list(map(int,stdin.readline().split()))\n if c==0:\n union(a,b)\n else:\n different.append([a,b])\n ans=True\n for i in range(len(different)):\n ob1=repre(different[i][0])\n ob2=repre(different[i][1])\n if ob1.data==ob2.data:\n ans=0\n break\n elif ob1.color==ob2.color and ob1.color!=None:\n ans=0\n break\n else:\n if ob1.color==None and ob2.color==None :\n ob1.color=True\n ob2.color= not ob1.color\n elif ob1.color==None :\n ob1.color= not ob2.color\n elif ob2.color==None:\n ob2.color= not ob1.color\n \n if ans:\n stdout.write(\"yes\\n\")\n else:\n stdout.write(\"no\\n\")\n\n\n", "import sys\nsys.setrecursionlimit(1000000)\nt = int(input())\n\nfor _ in range(t):\n n, q = map(int, input().split())\n par = [i for i in range(2 * n)]\n def get(u):\n if u != par[u]:\n par[u] = get(par[u])\n return par[u]\n def union(u, v):\n par[get(u)] = get(v)\n \n for i in range(q):\n i, j, val = map(int, input().split())\n i -= 1\n j -= 1\n if val == 0:\n union(i, j)\n union(i + n, j + n)\n else:\n union(i, j + n)\n union(i + n, j)\n if any(get(i) == get(i + n) for i in range(n)):\n print('no')\n else:\n print('yes')"]
{"inputs": [["4", "2 2", "1 1 0", "1 2 1", "2 3", "1 1 0", "1 2 1", "2 1 0", "3 2", "2 2 0", "2 3 1", "3 3", "1 2 1", "2 3 1", "1 3 1"]], "outputs": [["yes", "no", "yes", "no"]]}
INTERVIEW
PYTHON3
CODECHEF
4,314
d64524e0d3eb3e1534c0adfc844efe51
UNKNOWN
Ashley likes playing with strings. She gives Mojo a fun problem to solve. In her imaginary string world, a string of even length is called as "Doublindrome" if both halves of the string are palindromes (both halves have length equal to half of original string). She gives Mojo a string and asks him if he can form a "Doublindrome" by rearranging the characters of the given string or keeping the string as it is. As Mojo is busy playing with cats, solve the problem for him. Print "YES" (without quotes) if given string can be rearranged to form a "Doublindrome" else print "NO" (without quotes). -----Input:----- - First line will contain a single integer $T$, the number of testcases. - Each testcase consists of two lines, first line consists of an integer $N$ (length of the string) and second line consists of the string $S$. -----Output:----- For each testcase, print "YES"(without quotes) or "NO"(without quotes) on a new line. -----Constraints----- - $1 \leq T \leq 10^5$ - $1 \leq N \leq 100$ - $N$ is always even. - String $S$ consists only of lowercase English alphabets. -----Sample Input:----- 1 8 abbacddc -----Sample Output:----- YES -----EXPLANATION:----- The given string is a Doublindrome as its 2 halves "abba" and "cddc" are palindromes.
["for _ in range(int(input())):\n n=int(input())\n s=input()\n d={}\n for j in s:\n if j not in d:\n d[j]=1\n else:\n d[j]+=1\n f=0\n for j in d:\n if(d[j]%2==1):\n f=f+1\n if((n//2)%2==0 and f==0):\n print(\"YES\")\n continue\n if((n//2)%2==1 and f<=2 and f%2==0):\n print(\"YES\")\n continue\n print(\"NO\")", "T = int(input())\n\nfor _ in range(T):\n N = int(input())\n S = input()\n\n if N <= 2:\n print(\"YES\")\n\n else:\n unique_c = {}\n for c in S:\n if c in list(unique_c.keys()):\n unique_c[c] += 1\n else:\n unique_c[c] = 1\n safe = 0\n no_odd = 0\n for c in list(unique_c.keys()):\n if unique_c[c] % 2 != 0:\n no_odd += 1\n \n if N // 2 % 2 == 1:\n if no_odd == 2 or no_odd == 0:\n print(\"YES\")\n else:\n print(\"NO\")\n else:\n if no_odd != 0:\n print(\"NO\")\n else:\n print(\"YES\")\n \n", "# cook your dish here\ntry:\n \n t=int(input())\n for i in range(t):\n n=int(input())\n s=input()\n flag=1\n d=dict()\n for j in range(n):\n d[s[j]]=0\n for j in range(n):\n d[s[j]]=d[s[j]]+1\n flag=1\n if (n//2)%2==0:\n for j in list(d.keys()):\n if d[j]%2!=0:\n flag=0\n break\n if flag==1:\n print(\"YES\")\n else:\n print(\"NO\")\n else:\n count=0\n for j in list(d.keys()):\n if d[j]%2!=0:\n count=count+1\n \n if count==2 or count==0:\n print(\"YES\")\n else:\n print(\"NO\")\n \n \n \nexcept:\n pass\n", "from collections import defaultdict\n\nfor t in range(int(input())):\n n = int(input())\n s = input()\n d = defaultdict(int)\n for i in s:\n d[i] += 1\n count = 0\n for i,j in d.items():\n if j % 2 == 1:\n count += 1\n # print(count)\n if (n//2) % 2 == 0:\n if count == 0:\n print(\"YES\")\n else:\n print(\"NO\")\n else:\n if count == 2 or count == 0:\n print(\"YES\")\n else:\n print(\"NO\")", "# cook your dish here\nfor _ in range(int(input())):\n n=int(input())\n s=list(input())\n d=dict()\n for i in s:\n d[i]=d.get(i,0)+1\n # print(d.values())\n if (n//2)%2==0:\n for i in list(d.values()):\n if i%2==1:\n print(\"NO\")\n break\n else:\n print(\"YES\")\n else:\n c=0\n for i in list(d.values()):\n if i%2==1:\n c+=1\n if c==3:\n print(\"NO\")\n break\n else:\n print(\"YES\")\n \n", "for t in range(int(input())):\n n = int(input()) // 2\n s = input()\n d = {}\n for i in s:\n if (i not in d):\n d[i] = 0\n d[i] += 1\n res = 0\n for i in d:\n if (d[i] % 2):\n res += 1\n if (n % 2):\n if (res == 0 or res == 2):\n print(\"YES\")\n else:\n print(\"NO\")\n else:\n if (res == 0):\n print(\"YES\")\n else:\n print(\"NO\")"]
{"inputs": [["1", "8", "abbacddc"]], "outputs": [["YES"]]}
INTERVIEW
PYTHON3
CODECHEF
2,647
6c449cddafd91391082487836182308a
UNKNOWN
Dhote and Shweta went on a tour by plane for the first time.Dhote was surprised by the conveyor belt at the airport.As Shweta was getting bored Dhote had an idea of playing a game with her.He asked Shweta to count the number of bags whose individual weight is greater than or equal to the half of the total number of bags on the conveyor belt.Shweta got stuck in the puzzle! Help Shweta. -----Input:----- - First line will contain T$T$, number of testcases. Then the testcases follow. - Each testcase contains of a single line of input, one integers N$N$. - next line conatins N$N$ integers that represents weight of bag -----Output:----- For each testcase, print required answer in new line . -----Constraints----- - 1≤T≤1000$1 \leq T \leq 1000$ - 1≤N≤105$1 \leq N \leq 10^5$ - 1≤weightofbag≤105$ 1\leq weight of bag \leq 10^5$ -----Sample Input:----- 1 4 1 2 3 4 -----Sample Output:----- 3
["t=int(input())\r\nfor _ in range(t):\r\n size=int(input())\r\n li=list(map(int,input().split()))\r\n c = 0\r\n for i in li:\r\n if(i >=len(li)/2):\r\n c += 1\r\n print(c)\r\n", "for _ in range(int(input())):\r\n c=0\r\n n = int(input())\r\n w = [int(x) for x in input().split()]\r\n for i in range(n):\r\n if w[i]>=n/2:\r\n c=c+1\r\n print(c)\r\n", "t=int(input())\r\nfor i in range(t):\r\n n=int(input())\r\n l=list(map(int,input().split()))\r\n cnt=0\r\n for j in range(n):\r\n if l[j]>=n/2:\r\n cnt+=1\r\n print(cnt)", "for _ in range(int(input())):\r\n n = int(input())\r\n a = list(map(int, input().split()))\r\n c = 0\r\n for i in a:\r\n if i>=n//2:\r\n c += 1\r\n print(c)\r\n", "for _ in range(int(input())):\r\n c = 0\r\n n = int(input())\r\n a = list(map(int,input().split()))\r\n for i in range(len(a)):\r\n if a[i] >= n//2:\r\n c += 1\r\n print(c)\r\n", "t=int(input())\r\nfor i in range(t):\r\n n=int(input())\r\n l=list(map(int,input().split()))\r\n half=n//2\r\n count=0\r\n for i in l:\r\n if(i>=half):\r\n count+=1\r\n print(count)\r\n", "def test():\r\n N=int(input())\r\n ls=list(map(int,input().split()))\r\n ans=0\r\n n=N/2\r\n for each in ls:\r\n if each>=n:\r\n ans+=1\r\n print(ans)\r\n\r\nT=int(input())\r\nfor i in range(T):\r\n test()\r\n", "for i in range(int(input())):\r\n n=int(input())\r\n l=list(map(int,input().split()))\r\n c=0\r\n for i in l:\r\n if(i>=(n-1)/2):\r\n c+=1\r\n print(c)", "t=int(input())\r\nfor p in range(t):\r\n\tn=int(input())\r\n\tcnt=0\r\n\tarr=list(map(int,input().split()))\r\n\tfor i in range(n):\r\n\t\tif arr[i]>=n//2:\r\n\t\t\tcnt+=1\r\n\tprint(cnt)\r\n", "for _ in range(int(input())):\n n = int(input())\n c = 0\n for i in list(map(int,input().split())):\n if i >= n//2:\n c+=1\n print(c)\n\n", "# cook your dish here\nfor _ in range(int(input())):\n c=0\n n=int(input())\n num=list(map(int,input().split()))\n for i in num:\n if i>=n//2:\n c+=1\n print(c)", "for l in range(int(input())):\n a=int(input())\n s=list(map(int,input().split()))\n m=0\n for i in range(a):\n if s[i]>=(a/2):\n m=m+1\n print(m)", "for i in range(int(input())):\n count = 0\n n = int(input())\n a = list(map(int,input().split()))\n for j in a:\n \tif (2*j>=n):\n count+=1\n print(count)", "# cook your dish here\na=int(input())\nfor i in range(a):\n count=0\n num=int(input())\n w=num/2\n b=[]\n b=input().split()\n for i in range(len(b)):\n b[i]=int(b[i])\n for i in b:\n if(i>=w):\n count+=1\n print(count)\n", "# cook your dish here\nfor i in range(int(input())):\n N=int(input())\n A=[int(x) for x in input().split()]\n P=N/2\n count=0\n for j in range(N):\n if(A[j]>=P):\n count+=1\n print(count)\n", "# cook your dish here\nfor i in range(int(input())):\n total_bags = int(input())\n bags_with_weight = list(map(int,input().split()))\n count = 0\n for x in bags_with_weight:\n if x >= total_bags//2:\n count += 1 \n print(count)\n", "# cook your dish here\nt=int(input())\nfor _ in range(t):\n d=int(input())\n a=[int(i) for i in input().split()]\n c=0\n for i in range(d):\n if a[i]>=d//2:\n c+=1\n print(c)", "for _ in range(int(input())):\r\n n = int(input())\r\n l = [*map(int, input().split())]\r\n print(sum(1 for e in l if e >= n/2))", "T = int(input())\r\nfor t in range(0, T):\r\n N = int(input())\r\n count = 0\r\n A = []\r\n A = list(map(int, input().split()))\r\n X = N//2\r\n for i in range(0, N):\r\n if A[i] >= X:\r\n count += 1\r\n print(count)\r\n", "T = int(input())\nfor i in range(T):\n N = int(input())\n S = input()\n S = S.split()\n cntr = 0\n for j in S:\n if(int(j)>=(N/2)):\n cntr+=1\n print(cntr)\n", "t=int(input())\r\nfor i in range(t):\r\n n=int(input())\r\n ct=0\r\n inputdata=input()\r\n a=inputdata.split()\r\n a=[int(c) for c in a]\r\n \r\n for i in a:\r\n if (i>=n/2):\r\n ct=ct+1\r\n \r\n print(ct)", "for _ in range(int(input().strip())):\r\n\tn = int(input().strip())\r\n\tarr = list(map(int, input().strip().split()))\r\n\tc = 0\r\n\tfor i in arr:\r\n\t\tif i >= n//2:\r\n\t\t\tc += 1\r\n\tprint(c)", "def main():\r\n\tt = int(input())\r\n\tfor i in range(t):\r\n\t\tn = int(input())\r\n\t\tweights = list(map(int, input().split()))\r\n\t\tn /= 2\r\n\t\tcount = 0\r\n\t\tfor j in weights:\r\n\t\t\tif (j >= n):\r\n\t\t\t\tcount += 1\r\n\t\tprint(count)\r\n\r\ndef __starting_point():\r\n\tmain()\n__starting_point()", "try:\n for _ in range(int(input())):\n n = int(input())\n weights = [int(x) for x in input().strip().split()]\n count = 0\n for x in weights:\n if(x >= (n / 2)):\n count += 1\n print(count)\nexcept:\n pass", "def main():\r\n\tt = int(input())\r\n\tfor i in range(t):\r\n\t\tn = int(input())\r\n\t\tweights = list(map(int, input().split()))\r\n\t\tn /= 2\r\n\t\tcount = 0\r\n\t\tfor j in weights:\r\n\t\t\tif (j >= n):\r\n\t\t\t\tcount += 1\r\n\t\tprint(count)\r\n\r\ndef __starting_point():\r\n\tmain()\n__starting_point()"]
{"inputs": [["1", "4", "1 2 3 4"]], "outputs": [["3"]]}
INTERVIEW
PYTHON3
CODECHEF
5,556
8d890e8e4509a5b13c8411fc5f0c9cd5
UNKNOWN
Dio Brando has set a goal for himself of becoming the richest and the most powerful being on earth.To achieve his goals he will do anything using either manipulation,seduction or plain violence. Only one guy stands between his goal of conquering earth ,named Jotaro Kujo aka JoJo .Now Dio has a stand (visual manifestation of life energy i.e, special power ) “Za Warudo” ,which can stop time itself but needs to chant few words to activate the time stopping ability of the stand.There is a code hidden inside the words and if you can decipher the code then Dio loses his power. In order to stop Dio ,Jotaro asks your help to decipher the code since he can’t do so while fighting Dio at the same time. You will be given a string as input and you have to find the shortest substring which contains all the characters of itself and then make a number based on the alphabetical ordering of the characters. For example : “bbbacdaddb” shortest substring will be “bacd” and based on the alphabetical ordering the answer is 2134 -----NOTE:----- A substring is a contiguous subsegment of a string. For example, "acab" is a substring of "abacaba" (it starts in position 3 and ends in position 6), but "aa" or "d" aren't substrings of this string. So the substring of the string s from position l to position r is S[l;r]=SlSl+1…Sr. -----Input :----- The first line contains $T$,number of test cases. The second line contains a string $S$. -----Output:----- For each test cases ,output the number you can get from the shortest string -----Constraints:----- $1 \leq t \leq 100$ $1 \leq |S| \leq 10^6$ -----Test Cases:----- -----Sample Input:----- 6 abcdfgh urdrdrav jojojojoj bbbbaaa cddfsccs tttttttttttt -----Sample Output:----- 1234678 2118418418122 1015 21 46193 20 -----Explanation:----- Test case 1: abcdfgh is the shortest substring containing all char of itself and the number is 1234678
["# cook your dish here\nimport sys\nimport math\nfrom collections import Counter\nfrom collections import OrderedDict \ndef inputt():\n return sys.stdin.readline().strip()\ndef printt(n):\n sys.stdout.write(str(n)+'\\n')\ndef listt():\n return [int(i) for i in inputt().split()]\ndef gcd(a,b): \n return math.gcd(a,b) \n \ndef lcm(a,b): \n return (a*b) / gcd(a,b) \nfrom collections import defaultdict \n\ndef find_sub_string(str): \n str_len = len(str) \n \n # Count all distinct characters. \n dist_count_char = len(set([x for x in str])) \n \n ctr, start_pos, start_pos_index, min_len = 0, 0, -1, 9999999999\n curr_count = defaultdict(lambda: 0) \n for i in range(str_len): \n curr_count[str[i]] += 1\n \n if curr_count[str[i]] == 1: \n ctr += 1\n \n if ctr == dist_count_char: \n while curr_count[str[start_pos]] > 1: \n if curr_count[str[start_pos]] > 1: \n curr_count[str[start_pos]] -= 1\n start_pos += 1\n \n len_window = i - start_pos + 1\n if min_len > len_window: \n min_len = len_window \n start_pos_index = start_pos \n return str[start_pos_index: start_pos_index + min_len]\nt= int(inputt())\nfor _ in range(t):\n j=[]\n str1 =inputt()\n s=find_sub_string(str1) \n for i in s:\n j.append(abs(97-ord(i))+1)\n st = [str(i) for i in j]\n print(''.join(st)) \n\n\n", "# https://www.geeksforgeeks.org/smallest-window-contains-characters-string/\r\nfrom collections import defaultdict\r\n\r\nMAX_CHARS = 256\r\n\r\ndef solve(strr):\r\n n = len(strr)\r\n\r\n dist_count = len(set([x for x in strr]))\r\n\r\n curr_count = defaultdict(lambda: 0)\r\n count = 0\r\n start = 0\r\n min_len = n\r\n\r\n start_index = 0\r\n\r\n for j in range(n):\r\n curr_count[strr[j]] += 1\r\n\r\n if curr_count[strr[j]] == 1:\r\n count += 1\r\n\r\n if count == dist_count:\r\n while curr_count[strr[start]] > 1:\r\n if curr_count[strr[start]] > 1:\r\n curr_count[strr[start]] -= 1\r\n\r\n start += 1\r\n\r\n len_window = j - start + 1\r\n\r\n if min_len > len_window:\r\n min_len = len_window\r\n start_index = start\r\n\r\n return str(strr[start_index: start_index + min_len])\r\n\r\nfor _ in range(int(input())):\r\n x = solve(input().strip())\r\n\r\n print(''.join(str(ord(c) - ord('a') + 1) for c in x))\r\n"]
{"inputs": [["6", "abcdfgh", "urdrdrav", "jojojojoj", "bbbbaaa", "cddfsccs", "tttttttttttt"]], "outputs": [["1234678", "2118418418122", "1015", "21", "46193", "20"]]}
INTERVIEW
PYTHON3
CODECHEF
2,595
9af1708cf9725335dfe958037e9f7708
UNKNOWN
The chef is placing the laddus on the large square plat. The plat has the side of length N. Each laddu takes unit sq.unit area. Cheffina comes and asks the chef one puzzle to the chef as, how many squares can be formed in this pattern with all sides of new square are parallel to the original edges of the plate. -----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 $N$. -----Output:----- For each test case, output in a single line answer as maximum squares on plate satisfying the condition. -----Constraints----- - $1 \leq T \leq 1000$ - $1 \leq N \leq 10^5$ -----Sample Input:----- 2 1 2 -----Sample Output:----- 1 5 -----EXPLANATION:----- For 1) Only 1 Square For 2) 4 squares with area 1 sq.unit 1 square with area 4 sq.unit
["# cook your dish here\n \nt = int(input())\n\nwhile t:\n m = int(input())\n print(int(m * (m + 1) * (2 * m + 1) / 6))\n \n \n t -= 1", "#\n# data = {1:1,0:0}\n#\n# for i in range(2,10**7+1):\n#\n# data[i] = i**2 + data[i-1]\n\n\nfor t in range(int(input())):\n\n N = int(input())\n\n print((N*(N+1)*(2*N + 1))//6)\n\n", "def Solve5():\n n = int(input())\n s = (n*(n+1)*(2*n+1))//6\n print(s)\n\nfor _ in range(int(input())):\n Solve5()", "# cook your dish here\nt=int(input())\n\nwhile t:\n t-=1\n n=int(input())\n \n print((n*(n+1)*((2*n)+1))//6)\n", "# cook your dish here\nn=int(input())\nfor i in range(n):\n x=int(input())\n \n # res=0\n # for j in range(1,x+1):\n # res+=(j*j)\n print((x*(x+1)*(2*x+1))//6)", "# cook your dish here\nt = int(input())\n\nfor _ in range(t):\n \n n = int(input())\n \n # ans = n*((n+1)**3)*0.5 - n*((n+1)**2)*(2*n+1)*(1/3) + (n*(n+1)*0.5)**2\n ans = n*(n+1)*(2*n +1)/6\n \n print(int(ans))", "# cook your dish here\ntry:\n for _ in range(int(input())):\n n=int(input())\n \n \n print((n)*(n+1)*(2*n+1)//6) \nexcept:pass ", "# cook your dish here\ntry:\n for _ in range(int(input())):\n n=int(input())\n \n \n print((n)*(n+1)*(2*n+1)//6) \nexcept:pass ", "for _ in range(int(input())):\n N=int(input())\n print((N*(N+1)*(2*N+1))//6)", "# cook your dish here\nt = int(input())\nfor i in range(t):\n p = int(input())\n a = p*(p+1)*(2*p+1)//6\n print(a)\n", "for _ in range(int(input())):\n n = int(input())\n a = (n*(n+1)*(2*n+1))//6\n print(a)\n\n", "t=int(input())\nwhile(t):\n n=int(input())\n ans=n*(n+1)*(2*n+1)\n ans=ans/6\n print(int(ans))\n t=t-1", "t = int(input())\n\nwhile(t):\n \n t -= 1\n \n n = int(input())\n \n ans = int(n*(n+1)*(2*n + 1)/6)\n \n print(ans)", "# cook your dish here\nfor t in range(int(input())):\n x=0\n n=int(input())\n x=n*(n+1)*(2*n+1)//6\n print(x)\n", "t = int(input());\nfor _ in range(t):\n n = int(input());\n print(n*(n+1)*(2*n+1)//6);", "# your code goes here\nt=int(input())\nwhile t>0:\n n=int(input())\n print((n*(n+1)*(2*n+1))//6)\n t-=1", "for _ in range(int(input())):\n m = int(input())\n print(m * (m + 1) * (2 * m + 1) // 6)", "\n\n\nt = int(input())\nfor _ in range(t):\n n = int(input())\n ans = (n * (n+1) * (2*n +1 ))\n ans /= 6\n ans = int(ans)\n print(ans)\n", "# cook your dish here\nfor t in range(int(input())):\n n=int(input())\n x=(n*(n+1)*(2*n + 1))//6\n print(x)", "# cook your dish here\nt = int(input())\nfor i in range(t):\n n = int(input())\n print(int((n*(n+1)*(2*n+1))/6))", "# cook your dish here\nimport sys\nT=int(input())\nfor t in range(T):\n N=int(input())\n res=N*(N+1)*(2*N+1)/6\n print(int(res))", "# cook your dish here\nimport math\nfor _ in range(int(input())):\n n = int(input())\n print(n*(n+1)*(2*n+1)//6)\n", "T = int(input())\n\nfor i in range(T):\n n = int(input())\n\n ans = n*(n+1)*(2*n+1)/6\n\n print(int(ans))"]
{"inputs": [["2", "1", "2"]], "outputs": [["1", "5"]]}
INTERVIEW
PYTHON3
CODECHEF
2,856
029cd49dea37791f4ff219adf4d6c4f3
UNKNOWN
Chef is making polygon cakes in his kitchen today! Since the judge panel is very strict, Chef's cakes must be beautiful and have sharp and precise $internal$ angles in arithmetic progression. Given the number of sides, $N$, of the cake Chef is baking today and also the measure of its first angle(smallest angle), $A$, find the measure of the $K^{th}$ angle. -----Input:----- - The first line contains a single integer $T$, the number of test cases. - The next $T$ lines contain three space separated integers $N$, $A$ and $K$, the number of sides of polygon, the first angle and the $K^{th}$ angle respectively. -----Output:----- For each test case, print two space separated integers $X$ and $Y$, such that the $K^{th}$ angle can be written in the form of $X/Y$ and $gcd(X, Y) = 1$ -----Constraints----- - $1 \leq T \leq 50$ - $3 \leq N \leq 1000$ - $1 \leq A \leq 1000000000$ - $1 \leq K \leq N$ - It is guaranteed the answer is always valid. -----Sample Input:----- 1 3 30 2 -----Sample Output:----- 60 1
["# cook your dish here\nimport math\nT = int(input())\nfor _ in range(T):\n N, A, K = map(int, input().split(\" \"))\n total = (N-2) * 180\n diffT = total - N*A\n diffN = sum(range(1,N))\n r = (A*diffN+(K-1)*diffT)\n \n d = math.gcd(r, diffN)\n while d > 1:\n r//=d\n diffN//=d\n d = math.gcd(r, diffN)\n print(r, diffN)", "# cook your dish here\nimport math\nT = int(input())\nfor _ in range(T):\n N, A, K = list(map(int, input().split(\" \")))\n total = (N-2) * 180\n \n # 360 = 60 + (1+2+3)*diff + 3*60\n # 360 = 240 + 6*diff\n # 120 = 6*diff\n # 120 / 6 = diff\n \n # K: 60 + (K-1) * diffT / diffN = (60*diffN+(K-1)*diffT) / diffN\n \n diffT = total - N*A\n diffN = sum(range(1,N))\n r = (A*diffN+(K-1)*diffT)\n \n d = math.gcd(r, diffN)\n while d > 1:\n r//=d\n diffN//=d\n d = math.gcd(r, diffN)\n print(r, diffN)\n", "def hcfnaive(a,b): \n if(b==0): \n return a \n else: \n return hcfnaive(b,a%b)\n \nfor i in range(int(input())):\n (N,A,K)=map(int,input().split())\n s=180*(N-2)\n d=hcfnaive(A*N*(N-1)+(s-N*A)*2*(K-1),N*(N-1))\n print((A*N*(N-1)+(s-N*A)*2*(K-1))//d,(N*(N-1))//d)", "# cook your dish here\nimport math\nT = int(input())\nfor _ in range(T):\n N, A, K = list(map(int, input().split(\" \")))\n total = (N-2) * 180\n \n # 360 = 60 + (1+2+3)*diff + 3*60\n # 360 = 240 + 6*diff\n # 120 = 6*diff\n # 120 / 6 = diff\n \n # K: 60 + (K-1) * diffT / diffN = (60*diffN+(K-1)*diffT) / diffN\n \n diffT = total - N*A\n diffN = sum(range(1,N))\n r = (A*diffN+(K-1)*diffT)\n \n d = math.gcd(r, diffN)\n while d > 1:\n r//=d\n diffN//=d\n d = math.gcd(r, diffN)\n print(r, diffN)\n", "# cook your dish here\n\ndef gcd(d,s):\n if s==0:\n return d\n else:\n return gcd(s,d%s)\nfor _ in range(int(input())):\n n,a,k=[int(x) for x in input().split()]\n d = (360*(n-2)-2*a*n)*(k-1)\n \n s = n*(n-1)\n k = gcd(d,s)\n d = d//k\n s=s//k\n print(d+s*a,s)", "# cook your dish here\n\ndef gcd(d,s):\n if s==0:\n return d\n else:\n return gcd(s,d%s)\nfor _ in range(int(input())):\n n,a,k=[int(x) for x in input().split()]\n d = (360*(n-2)-2*a*n)*(k-1)\n \n s = n*(n-1)\n k = gcd(d,s)\n d = d//k\n s=s//k\n print(d+s*a,s)", "def gcd(d,s):\n if s==0:\n return d\n else:\n return gcd(s,d%s)\nfor _ in range(int(input())):\n n,a,k=[int(x) for x in input().split()]\n d = (360*(n-2)-2*a*n)*(k-1)\n \n s = n*(n-1)\n k = gcd(d,s)\n d = d//k\n s=s//k\n print(d+s*a,s)", "def gcd(d,s):\n if s==0:\n return d\n else:\n return gcd(s,d%s)\nfor _ in range(int(input())):\n n,a,k=[int(x) for x in input().split()]\n d = (360*(n-2)-2*a*n)*(k-1)\n s = n*(n-1)\n k = gcd(d,s)\n d = d//k\n s=s//k\n print(d+s*a,s)", "def gcd(d,s):\n if s==0:\n return d\n else:\n return gcd(s,d%s)\nfor _ in range(int(input())):\n n,a,k=[int(x) for x in input().split()]\n d = (360*(n-2)-2*a*n)*(k-1)\n s = n*(n-1)\n k = gcd(d,s)\n d = d//k\n s=s//k\n print(d+s*a,s)", "# cook your dish here\ndef gcd(d,s):\n if s==0:\n return d\n else:\n return gcd(s,d%s)\nfor _ in range(int(input())):\n n,a,k=[int(x) for x in input().split()]\n d = (360*(n-2)-2*a*n)*(k-1)\n s = n*(n-1)\n k = gcd(d,s)\n d = d//k\n s=s//k\n print(d+s*a,s)", "# cook your dish here\ndef gcd(d,s):\n if s==0:\n return d\n else:\n return gcd(s,d%s)\nfor _ in range(int(input())):\n n,a,k=[int(x) for x in input().split()]\n d = (360*(n-2)-2*a*n)*(k-1)\n s = n*(n-1)\n k = gcd(d,s)\n d = d//k\n s=s//k\n print(d+s*a,s)", "# cook your dish here\ndef gcd(d,s):\n if s==0:\n return d\n else:\n return gcd(s,d%s)\nfor _ in range(int(input())):\n n,a,k=[int(x) for x in input().split()]\n d = (360*(n-2)-2*a*n)*(k-1)\n s = n*(n-1)\n k = gcd(d,s)\n d = d//k\n s=s//k\n print(d+s*a,s)", "def gcd(a,b):\n if b==0:\n return a\n return gcd(b,a%b)\nt=int(input())\nfor i in range(t):\n temp=input().split()\n n=int(temp[0])\n a=int(temp[1])\n k=int(temp[2])\n #(n/2)(2a+(n-1)d)=(n-2)180\n tempn=(n-2)*180\n tempn=tempn*2\n tempd=n\n tempn=tempn-2*a*tempd\n tempd=tempd*(n-1)\n tempn=tempn*(k-1)+a*tempd\n g=gcd(tempn,tempd)\n tempn/=g\n tempd/=g\n print(int(tempn),int(tempd)) ", "def gcd(A, B):\n if B==0:\n return A;\n else:\n return gcd(B,A%B);\n\n\nt = int(input())\n\nfor _ in range(t):\n n,a,k = list(map(int, input().split()))\n #d = /(n*(n-1))\n num = a*(n*(n-1)) + (k-1)*(360*(n-2)-2*a*n)\n den = n*(n-1)\n print(f\"{num//gcd(num, den)} {den//gcd(num, den)}\")\n \n", "def gcd(A, B):\n if B==0:\n return A;\n else:\n return gcd(B,A%B);\n\n\nt = int(input())\n\nfor _ in range(t):\n n,a,k = list(map(int, input().split()))\n #d = /(n*(n-1))\n num = a*(n*(n-1)) + (k-1)*(360*(n-2)-2*a*n)\n den = n*(n-1)\n print(f\"{num//gcd(num, den)} {den//gcd(num, den)}\")\n \n", "# cook your dish here\ndef gcd(d,s):\n if s==0:\n return d\n else:\n return gcd(s,d%s)\nfor _ in range(int(input())):\n n,a,k=[int(x) for x in input().split()]\n d = (360*(n-2)-2*a*n)*(k-1)\n s = n*(n-1)\n k = gcd(d,s)\n d = d//k\n s=s//k\n print(d+s*a,s)", "# cook your dish here\n# cook your dish here\n# cook your dish here\ndef gcd(d,s):\n if s==0:\n return d\n else:\n return gcd(s,d%s)\nfor _ in range(int(input())):\n n,a,k=[int(x) for x in input().split()]\n d = (360*(n-2)-2*a*n)*(k-1)\n s = n*(n-1)\n k = gcd(d,s)\n d = d//k\n s=s//k\n print(d+s*a,s)", "# cook your dish here\ndef gcd(d,s):\n if s==0:\n return d\n else:\n return gcd(s,d%s)\nfor _ in range(int(input())):\n n,a,k=[int(x) for x in input().split()]\n d = (360*(n-2)-2*a*n)*(k-1)\n s = n*(n-1)\n k = gcd(d,s)\n d = d//k\n s=s//k\n print(d+s*a,s)", "# cook your dish here\ndef gcd(d,s):\n if s==0:\n return d\n else:\n return gcd(s,d%s)\nfor _ in range(int(input())):\n n,a,k=[int(x) for x in input().split()]\n d = (360*(n-2)-2*a*n)*(k-1)\n s = n*(n-1)\n k = gcd(d,s)\n d = d//k\n s=s//k\n print(d+s*a,s)", "# cook your dish here\n# cook your dish here\ndef gcd(d,s):\n if s==0:\n return d\n else:\n return gcd(s,d%s)\nfor _ in range(int(input())):\n n,a,k=[int(x) for x in input().split()]\n d = (360*(n-2)-2*a*n)*(k-1)\n s = n*(n-1)\n k = gcd(d,s)\n d = d//k\n s=s//k\n print(d+s*a,s)", "# cook your dish here\ndef gcd(d,s):\n if s==0:\n return d\n else:\n return gcd(s,d%s)\nfor _ in range(int(input())):\n n,a,k=[int(x) for x in input().split()]\n d = (360*(n-2)-2*a*n)*(k-1)\n s = n*(n-1)\n k = gcd(d,s)\n d = d//k\n s=s//k\n print(d+s*a,s)", "def gcd(d,s):\n if s==0:\n return d\n else:\n return gcd(s,d%s)\nfor _ in range(int(input())):\n n,a,k=[int(x) for x in input().split()]\n d = (360*(n-2)-2*a*n)*(k-1)\n s = n*(n-1)\n k = gcd(d,s)\n d = d//k \n s=s//k\n print(d+s*a,s)", "from fractions import Fraction\nfor i in range(int(input())):\n a = [int(x) for x in input().split()]\n n=a[0]\n A=a[1]\n k=a[2]\n q=A+((k-1)/(n-1))*(360*(n-2)/n -2*A)\n x=1\n if q-int(q)<1 and q-int(q)>0:\n o=Fraction(q).limit_denominator()\n print(o.numerator,o.denominator)\n else:\n print(int(q),1)", "import math\nt=int(input())\nwhile(t!=0):\n t-=1\n n,a,k=list(map(int,input().split()))\n g=n*(n-1)\n d=(360*(n-2)-2*a*n)\n f=(a*g+(k-1)*d)\n j=math.gcd(f,g)\n b=f//j\n e=g//j\n print(b,e)\n\n"]
{"inputs": [["1", "3 30 2"]], "outputs": [["60 1"]]}
INTERVIEW
PYTHON3
CODECHEF
7,001
91991a866c27947da576979274b2e2a0
UNKNOWN
Indian National Olympiad in Informatics 2016 Boing Inc, has N employees, numbered 1 ... N. Every employee other than Mr. Hojo (the head of the company) has a manager (P[i] denotes the manager of employee i). Thus an employee may manage any number of other employees but he reports only to one manager, so that the organization forms a tree with Mr. Hojo at the root. We say that employee B is a subordinate of employee A if B appears in the subtree rooted at A. Mr. Hojo, has hired Nikhil to analyze data about the employees to suggest how to identify faults in Boing Inc. Nikhil, who is just a clueless consultant, has decided to examine wealth disparity in the company. He has with him the net wealth of every employee (denoted A[i] for employee i). Note that this can be negative if the employee is in debt. He has already decided that he will present evidence that wealth falls rapidly as one goes down the organizational tree. He plans to identify a pair of employees i and j, j a subordinate of i, such A[i] - A[j] is maximum. Your task is to help him do this. Suppose, Boing Inc has 4 employees and the parent (P[i]) and wealth information (A[i]) for each employee are as follows: i 1 2 3 4 A[i] 5 10 6 12 P[i] 2 -1 4 2 P[2] = -1 indicates that employee 2 has no manager, so employee 2 is Mr. Hojo. In this case, the possible choices to consider are (2,1) with a difference in wealth of 5, (2,3) with 4, (2,4) with -2 and (4,3) with 6. So the answer is 6. -----Input format----- There will be one line which contains (2*N + 1) space-separate integers. The first integer is N, giving the number of employees in the company. The next N integers A[1], .., A[N] give the wealth of the N employees. The last N integers are P[1], P[2], .., P[N], where P[i] identifies the manager of employee i. If Mr. Hojo is employee i then, P[i] = -1, indicating that he has no manager. -----Output format----- One integer, which is the needed answer. -----Test data----- -108 ≤ A[i] ≤ 108, for all i. Subtask 1 (30 Marks) 1 ≤ N ≤ 500. Subtask 2 (70 Marks) 1 ≤ N ≤ 105. -----Sample Input----- 4 5 10 6 12 2 -1 4 2 -----Sample Output----- 6
["import sys\r\nfrom collections import defaultdict\r\ninput = sys.stdin.readline\r\nsys.setrecursionlimit(1000000)\r\n\r\narr=[int(x) for x in input().split()]\r\n\r\nif arr[0]==1:\r\n print(0)\r\n return\r\n\r\np=[None]\r\nfor i in range(1,arr[0]+1):\r\n p.append(arr[i])\r\n \r\na=[None]\r\nfor i in range(arr[0]+1,2*arr[0]+1):\r\n a.append(arr[i])\r\n\r\ngraph=defaultdict(list)\r\n\r\nn=len(a)-1\r\nfor i in range(1,n+1):\r\n if a[i]==-1:\r\n source=i\r\n continue\r\n graph[a[i]].append((i,(p[a[i]]-p[i])))\r\n\r\ndef func(node):\r\n nonlocal res\r\n \r\n if len(graph[node])==0:\r\n return -10**9\r\n \r\n curr=-10**9\r\n for child in graph[node]:\r\n x=max(child[1],(func(child[0])+child[1]))\r\n curr=max(curr,x)\r\n res=max(curr,res)\r\n \r\n return curr \r\n\r\nres=-10**9\r\ncurr=func(source)\r\nprint(res) \r\n \r\n \r\n \r\n", "li = list(map(int, input().split()))\n\nn, d = li[0], dict()\nwealths = [None]+li[1:n+1]\nparents = li[n+1:]\n\nfor k in list(range(1, n+1)):\n d[k] = []\n \nmax_diff = -200000000\nroot = None\n\nfor i in range(len(parents)):\n if parents[i] != -1:\n d[parents[i]].append(i+1)\n else:\n root = i+1\n\nq = [root]\nindices = [0 for x in range(n+1)]\n\nwhile len(q) > 0:\n last = q[-1]\n curr = d[last]\n \n if indices[last] < len(curr) and len(curr) >= 1:\n rn = curr[indices[last]]\n indices[last] += 1\n q.append(rn)\n \n for num in q:\n if num != rn:\n if wealths[num]-wealths[rn] > max_diff:\n max_diff = wealths[num]-wealths[rn];\n else:\n q.pop(-1)\n\nprint(max_diff)", "li = list(map(int, input().split()))\nn, d = li[0], dict()\nwealths = [None]+li[1:n+1]\nparents = li[n+1:]\n\nfor k in list(range(1, n+1)):\n d[k] = []\n \nmax_diff = -2 * int(1e8)\nroot = None\n\nfor i in range(len(parents)):\n if parents[i] != -1:\n d[parents[i]].append(i+1)\n else:\n root = i+1\n\nq = [root]\nindices = [0 for x in range(n+1)]\n\nwhile len(q) > 0:\n curr = d[q[-1]]\n \n if indices[q[-1]] < len(curr) and len(curr) >= 1:\n rn = curr[indices[q[-1]]]\n indices[q[-1]] += 1\n q.append(rn)\n \n for num in q:\n if num != rn:\n if wealths[num]-wealths[rn] > max_diff:\n max_diff = wealths[num]-wealths[rn];\n else:\n q.pop(-1)\n\nprint(max_diff)", "# cook your dish here\nfrom collections import defaultdict\nfrom collections import deque\na = list(map(int,input().split()))\nn = a[0]\nv = a[1:n+1]\np = a[n+1:]\nans = -1000000000\nboss = 1\ngraph = defaultdict(set)\nfor i in range(n):\n if p[i] == -1:\n boss = i+1\n continue\n else:\n graph[p[i]].add(i+1)\n \ndef bfs(boss, graph, n):\n nonlocal ans\n que = deque([])\n que.append(boss)\n while que:\n key = que.popleft()\n for item in graph[key]:\n que.append(item)\n z = v[key-1] - v[item-1]\n if(ans<z):\n ans = z \n if v[key-1] > v[item-1]:\n v[item-1] = v[key-1]\nbfs(boss, graph, n)\nprint(ans)\n\n \n \n", "# cook your dish here\ninputs = list(map(int, input().split()))\nn = inputs[0]\nA = inputs[1:n+1]\nP = inputs[n+1:]\narr = [[] for _ in range(n)]\n\nboss = None\nfor j, i in enumerate(P):\n if i == -1:\n boss = j\n else:\n arr[i-1].append(j)\n\ndef BFS(array, start):\n queue = []\n queue.append(boss)\n maxi = -10000000000000000000000\n while queue:\n cur = queue.pop(0)\n val = A[cur]\n for i in arr[cur]:\n queue.append(i)\n cur_val = A[i]\n check = val-cur_val\n \n if check>maxi:\n maxi= check\n if val>cur_val:\n A[i] = val\n return maxi\n\nif n==1:\n print(0)\nelse:\n print(BFS(arr,boss))", "# cook your dish here\nfrom collections import defaultdict\nfrom operator import itemgetter\nfrom collections import deque\n\ndef visit(v):\n height[v][1]=0\n i=0\n coda=deque()\n coda.append(v)\n while len(coda)>0:\n num=len(coda)\n i+=1\n for _ in range(num):\n u=coda.popleft()\n for son in sons[u]:\n height[son][1]=i\n coda.append(son)\n return \n\ninp=list(map(int, input().split()))\nn=inp[0]\nwealth=inp[1:n+1]\nfather=[i-1 if i>0 else i for i in inp[n+1:]]\nsons=defaultdict(lambda:[])\nfor i in range(n):\n if father[i]!=-1:\n sons[father[i]].append(i)\n else:\n boss=i\n\nheight=[[i,0] for i in range(n)]\nvisit(boss)\n\nheight.sort(key=itemgetter(1), reverse=True)\nminimi=[0]*n\ndiff=[0]*n\n\nfor el in height:\n v=el[0]\n if len(sons[v])==0:\n minimi[v]=wealth[v]\n diff[v]=-float('Inf')\n else:\n minimo=min([minimi[u] for u in sons[v]]) \n minimi[v]=min(minimo, wealth[v])\n diff[v]=max(max([diff[u] for u in sons[v]]), wealth[v]-minimo)\n\nprint(diff[boss])\n \n", "# cook your dish here\nfrom multiprocessing import SimpleQueue as queue\nfrom collections import defaultdict\nfrom operator import itemgetter\n\ndef visit(v, i):\n height[v][1]=i\n for u in sons[v]:\n visit(u, i+1)\n return \n\ninp=list(map(int, input().split()))\nn=inp[0]\nwealth=inp[1:n+1]\nfather=[i-1 if i>0 else i for i in inp[n+1:]]\nsons=defaultdict(lambda:[])\nfor i in range(n):\n if father[i]!=-1:\n sons[father[i]].append(i)\n else:\n boss=i\nheight=[[i,0] for i in range(n)]\nvisit(boss, 0)\nheight.sort(key=itemgetter(1), reverse=True)\nminimi=[0]*n\ndiff=[0]*n\nfor el in height:\n v=el[0]\n if len(sons[v])==0:\n minimi[v]=wealth[v]\n diff[v]=-float('Inf')\n else:\n minimo=min([minimi[u] for u in sons[v]]) \n minimi[v]=min(minimo, wealth[v])\n diff[v]=max(max([diff[u] for u in sons[v]]), wealth[v]-minimo)\nprint(diff[boss])\n \n\n'''\ncoda=queue()\nfor i in range(n):\n if len(sons[i])==0:\n coda.put(i)\n visited[i]=1\nwhile len(coda)>0:\n '''", "import sys\nfrom collections import defaultdict\ninput = sys.stdin.readline\nsys.setrecursionlimit(1000000)\n\narr=[int(x) for x in input().split()]\n\nif arr[0]==1:\n print(0)\n return\n\np=[None]\nfor i in range(1,arr[0]+1):\n p.append(arr[i])\n \na=[None]\nfor i in range(arr[0]+1,2*arr[0]+1):\n a.append(arr[i])\n\ngraph=defaultdict(list)\n\nn=len(a)-1\nfor i in range(1,n+1):\n if a[i]==-1:\n source=i\n continue\n graph[a[i]].append((i,(p[a[i]]-p[i])))\n\ndef func(node):\n nonlocal res\n \n if len(graph[node])==0:\n return -10**9\n \n curr=-10**9\n for child in graph[node]:\n x=max(child[1],(func(child[0])+child[1]))\n curr=max(curr,x)\n res=max(curr,res)\n \n return curr \n\nres=-10**9\ncurr=func(source)\nprint(res) \n \n \n \n", "from collections import defaultdict\nfrom sys import stdin\ninput = stdin.readline\n\ngraph=defaultdict(list)\n\narr=[int(x) for x in input().split()]\nif arr[0]==1:\n print(0)\n return\n\np=[None]\nfor i in range(1,arr[0]+1):\n p.append(arr[i])\na=[None]\nfor i in range(arr[0]+1,2*arr[0]+1):\n a.append(arr[i])\n\nn=len(a)-1\n# print(a)\n# print(p)\nfor i in range(1,n+1):\n if a[i]==-1:\n source=i\n continue\n graph[a[i]].append((i,(p[a[i]]-p[i])))\n\n# print(graph)\n\ndef func(node):\n nonlocal res\n \n if len(graph[node])==0:\n return -10**9\n \n curr=-10**9\n for child in graph[node]:\n x=max(child[1],(func(child[0])+child[1]))\n curr=max(curr,x)\n res=max(curr,res)\n \n return curr \n\nres=-10**9\ncurr=func(source)\nprint(res) \n \n \n \n", "from collections import defaultdict\nfrom sys import stdin\ninput = stdin.readline\n\ngraph=defaultdict(list)\n\narr=[int(x) for x in input().split()]\n\np=[None]\nfor i in range(1,arr[0]+1):\n p.append(arr[i])\na=[None]\nfor i in range(arr[0]+1,2*arr[0]+1):\n a.append(arr[i])\n\nn=len(a)-1\n# print(a)\n# print(p)\nfor i in range(1,n+1):\n if a[i]==-1:\n source=i\n continue\n graph[a[i]].append((i,(p[a[i]]-p[i])))\n\n# print(graph)\n\ndef func(node):\n nonlocal res\n \n if len(graph[node])==0:\n return -10**9\n \n curr=-10**9\n for child in graph[node]:\n x=max(child[1],(func(child[0])+child[1]))\n curr=max(curr,x)\n res=max(curr,res)\n \n return curr \n\nres=-10**9\ncurr=func(source)\nprint(res) \n \n \n \n", "x = [int(w) for w in input().split()]\r\nn = x[0]\r\nx = x[1:]\r\na = {(i+1):x[i] for i in range(n)}\r\np = {(i+1):x[n+i] for i in range(n)}\r\nmgr = {i:1 for i in p}\r\nif -1 in mgr:\r\n mgr[-1] = 0\r\n\r\nd = []\r\nfor i in range(1,n+1):\r\n t = [float('-inf')]\r\n par = p[i]\r\n while mgr.get(par,0):\r\n t.append(a[par])\r\n par = p[par]\r\n p[i] = -1\r\n d.append(max(t)-a[i])\r\n a[i] = max(t)\r\nprint(max(d))", "# cook your dish here\n# cook your dish here\nfrom collections import defaultdict\nlist1 = list(map(int,input().split()))\nN = list1[0]\nlist1.pop(0)\nwealth=[]\nparent= {}\nchildren=defaultdict(list)\nfor i in range(N):\n wealth.append(list1[0])\n list1.pop(0)\nroot=0\nfor j in range(N):\n if list1[j] != -1:\n parent[j] = list1[j]-1\n children[list1[j]-1].append(j)\n else:\n root = j\nleaves=[]\ndowegoup={}\ntobevisited=[root]\nwhile len(tobevisited)>0:\n temp = tobevisited.pop()\n if len(children[temp])==0:\n leaves.append(temp)\n else:\n for i in range(len(children[temp])):\n tobevisited.append(children[temp][i])\n if wealth[children[temp][i]]>wealth[temp]:\n dowegoup[children[temp][i]] = False\n else:\n dowegoup[children[temp][i]] = True\n#print(\"wealth: \", wealth, \"parents: \", parent, \"children; \", children, \"leaves: \", leaves, \"dowegoup: \", dowegoup)\nvisited={}\ndisparity={}\nanswer=-10**10\nfor j in range(len(leaves)):\n disparity[leaves[j]]=0\nwhile len(leaves)>0:\n temp = leaves.pop(0)\n if parent[temp] not in disparity:\n disparity[parent[temp]] = wealth[parent[temp]] - wealth[temp]\n if disparity[temp]>0:\n disparity[parent[temp]] += disparity[temp]\n else:\n if disparity[temp]>0:\n gladiator = wealth[parent[temp]]-wealth[temp] +disparity[temp]\n else:\n gladiator = wealth[parent[temp]]-wealth[temp]\n disparity[parent[temp]] = max(gladiator,disparity[parent[temp]])\n if parent[temp]!=root:\n visited[parent[temp]] = True\n leaves.append(parent[temp])\n if disparity[parent[temp]]>answer:\n answer = disparity[parent[temp]]\n#print(\"disparity: \", disparity)\nprint(answer)", "import sys\r\nfrom collections import defaultdict\r\nsys.setrecursionlimit(1000000)\r\ndef dfs(i,maxVal,maxDiff):\r\n visited[i]=True\r\n if not graph[i]:\r\n return maxDiff\r\n else:\r\n stack=[]\r\n for j in graph[i]:\r\n if not visited[j]:\r\n diff=max(maxDiff,maxVal-a[j])\r\n val=max(maxVal,a[j])\r\n stack.append(dfs(j,val,diff))\r\n return max(stack)\r\n\r\ns=list(map(int,input().split()))\r\nn=s[0]\r\na=s[1:n+1]\r\np=s[n+1:]\r\ngraph=defaultdict(list)\r\nfor i in range(n):\r\n graph[p[i]-1].append(i)\r\nboss=graph[-2][0]\r\nvisited=[False]*n\r\nprint(dfs(boss,a[boss],0))", "x = [int(w) for w in input().split()]\r\nn = x[0]\r\nx = x[1:]\r\na = {(i+1):x[i] for i in range(n)}\r\np = {(i+1):x[n+i] for i in range(n)}\r\nmgr = {i:1 for i in p}\r\nif -1 in mgr:\r\n mgr[-1] = 0\r\n\r\nd = []\r\nfor i in range(1,n+1):\r\n t = [float('-inf')]\r\n par = p[i]\r\n while mgr.get(par,0):\r\n t.append(a[par])\r\n par = p[par]\r\n p[i] = -1\r\n d.append(max(t)-a[i])\r\n a[i] = max(t)\r\nprint(max(d))", "x = list(map(int, input().split()))\r\n\r\nn = x[0]\r\nx = x[1:]\r\na = {(i):x[i] for i in range(n)}\r\np = {(i):x[n+i] for i in range(n)}\r\n#vis = [0]*n\r\n#print(a,p)\r\n#vis[p.index(-1)] = 2\r\n\r\nbhutiya = []\r\n\r\nfor i in range(n):\r\n\tif p[i] != -1:\r\n\t\t#vis[i] = 1\r\n\t\t#rem = []\r\n\t\t#rem.append(a[i])\r\n\t\tj = p[i]-1\r\n\t\tmaxi = a[i]\r\n\t\t#print(\"j:\",j)\r\n\t\twhile p[j] != -1:\r\n\t\t\tif a[j] > maxi:\tmaxi = a[j]\r\n\t\t\t#rem.append(a[j])\r\n\t\t\t#vis[j] = 1\r\n\t\t\tj = p[j]-1\r\n\t\t\r\n\t\tif a[j] > maxi:\tmaxi = a[j]\r\n\t\t\r\n\t\tbhutiya.append(maxi-a[i])\r\n\r\nprint(max(bhutiya))\r\n\r\n\r\n", "x = list(map(int, input().split()))\r\n\r\nn = x[0]\r\na = x[1:n+1]\r\np = x[n+1:]\r\n#vis = [0]*n\r\n\r\nparent = a[p.index(-1)]\r\n#vis[p.index(-1)] = 2\r\n\r\nbhutiya = []\r\n\r\nfor i in range(n):\r\n\tif p[i] != -1:\r\n\t\t#vis[i] = 1\r\n\t\t#rem = []\r\n\t\t#rem.append(a[i])\r\n\t\tj = p[i]-1\r\n\t\tmaxi = a[i]\r\n\r\n\t\twhile p[j] != -1:\r\n\t\t\tif a[j] > maxi:\tmaxi = a[j]\r\n\t\t\t#rem.append(a[j])\r\n\t\t\t#vis[j] = 1\r\n\t\t\tj = p[j]-1\r\n\t\t\r\n\t\tif a[j] > maxi:\tmaxi = a[j]\r\n\t\t\r\n\t\tbhutiya.append(maxi-a[i])\r\n\r\nprint(max(bhutiya))\r\n\r\n\r\n", "x = list(map(int, input().split()))\r\n\r\nn = x[0]\r\na = x[1:n+1]\r\np = x[n+1:]\r\nvis = [0]*n\r\n\r\nparent = a[p.index(-1)]\r\nvis[p.index(-1)] = 2\r\n\r\nbhutiya = []\r\n\r\nfor i in range(n):\r\n\tif vis[i] != 2:\r\n\t\t#vis[i] = 1\r\n\t\t#rem = []\r\n\t\t#rem.append(a[i])\r\n\t\tj = p[i]-1\r\n\t\tmaxi = a[i]\r\n\r\n\t\twhile vis[j] != 2:\r\n\t\t\tif a[j] > maxi:\tmaxi = a[j]\r\n\t\t\t#rem.append(a[j])\r\n\t\t\t#vis[j] = 1\r\n\t\t\tj = p[j]-1\r\n\t\t\r\n\t\tif a[j] > maxi:\tmaxi = a[j]\r\n\t\t\r\n\t\tbhutiya.append(maxi-a[i])\r\n\r\nprint(max(bhutiya))\r\n\r\n\r\n", "x = list(map(int, input().split()))\r\n\r\nn = x[0]\r\na = x[1:n+1]\r\np = x[n+1:]\r\nvis = [0]*n\r\n\r\nparent = a[p.index(-1)]\r\nvis[p.index(-1)] = 2\r\n\r\nbhutiya = []\r\n\r\nfor i in range(n):\r\n\tif vis[i] != 2:\r\n\t\tvis[i] = 1\r\n\t\trem = []\r\n\t\trem.append(a[i])\r\n\t\tj = p[i]-1\r\n\r\n\t\twhile vis[j] != 2:\r\n\t\t\trem.append(a[j])\r\n\t\t\tvis[j] = 1\r\n\t\t\tj = p[j]-1\r\n\t\t\r\n\t\trem.append(a[j])\r\n\t\tbhutiya.append(max(rem)-a[i])\r\n\r\nprint(max(bhutiya))\r\n\r\n\r\n", "x = [int(w) for w in input().split()]\r\nn = x[0]\r\nx = x[1:]\r\na = {(i+1):x[i] for i in range(n)}\r\np = {(i+1):x[n+i] for i in range(n)}\r\nmgr = {i:1 for i in p}\r\nif -1 in mgr:\r\n mgr[-1] = 0\r\n\r\nd = []\r\nfor i in range(1,n+1):\r\n t = [float('-inf')]\r\n par = p[i]\r\n while mgr.get(par,0):\r\n t.append(a[par])\r\n par = p[par]\r\n p[i] = -1\r\n d.append(max(t)-a[i])\r\n a[i] = max(t)\r\nprint(max(d))", "x = [int(w) for w in input().split()]\r\nn = x[0]\r\nx = x[1:]\r\na,p = x[:n],x[n:]\r\nx = [[] for i in range(n)]\r\nq = []\r\nfor i in range(n):\r\n if p[i] == -1:\r\n q.append([i,a[i]])\r\n else:\r\n x[p[i]-1].append(i)\r\nans = float('-inf')\r\nwhile q:\r\n i,mx = q[-1]\r\n q.pop()\r\n ans = max(ans,mx-a[i])\r\n mx = max(mx,a[i])\r\n for j in x[i]:\r\n q.append([j,mx])\r\nprint(ans)", "x = [int(w) for w in input().split()]\nn = x[0]\nx = x[1:]\na = {(i+1):x[i] for i in range(n)}\np = {(i+1):x[n+i] for i in range(n)}\nmgr = {i:1 for i in p}\nif -1 in mgr:\n mgr[-1] = 0\n\nd = []\nfor i in range(1,n+1):\n t = [0]\n par = p[i]\n while mgr.get(par,0):\n t.append(a[par])\n par = p[par]\n d.append(max(t)-a[i])\n\nprint(max(d))", "x = [int(w) for w in input().split()]\nn = x[0]\nx = x[1:]\na,p = x[:n],x[n:]\n\nmgr = {i:1 for i in p}\nif -1 in mgr:\n mgr[-1] = 0\n\nd = []\nfor i in range(n):\n t = [0]\n par = p[i]\n while mgr.get(par,0):\n t.append(a[par-1])\n par = p[par-1]\n d.append(max(t)-a[i])\n\nprint(max(d))"]
{"inputs": [["4 5 10 6 12 2 -1 4 2"]], "outputs": [["6"]]}
INTERVIEW
PYTHON3
CODECHEF
16,200
710ae354f6a7b9ea3601ff8b8b3280c6
UNKNOWN
A tennis tournament is about to take place with $N$ players participating in it. Every player plays with every other player exactly once and there are no ties. That is, every match has a winner and a loser. With Naman's birthday approaching, he wants to make sure that each player wins the same number of matches so that nobody gets disheartened. Your task is to determine if such a scenario can take place and if yes find one such scenario. -----Input:----- - First line will contain $T$, number of testcases. Then the testcases follow. - Each testcase contains of a single integer $N$ denoting number of players. -----Output:----- - If it's impossible for everyone to win the same number of matches, print "NO" (without quotes). - Otherwise print "YES" (without quotes) and then print $N$ lines , each line should consist of a string containing only 0s and 1s and should be of size $N$. - If the jth character in the ith line is 1 then it means in the match between $i$ and $j$ , $i$ wins. - You will get a WA if the output does not correspond to a valid tournament, or if the constraints are not satisfied. - You will get also WA verdict if any 2 lines have contradicting results or if a player beats himself. -----Constraints----- - $1 \leq T \leq 100$ - $2 \leq N \leq 100$ -----Subtasks----- - 10 points : $2 \leq N \leq 6$ - 90 points : Original Constraints. -----Sample Input:----- 2 3 2 -----Sample Output:----- YES 010 001 100 NO -----Explanation:----- One such scenario for $N$ = $3$ is when player $1$ beats player $2$, player $2$ to beats player $3$ and player $3$ beats player $1$. Here all players win exactly $1$ match.
["# cook your dish here\na = int(input())\nfor i in range(a):\n n = int(input())\n if n%2==0:\n print('NO')\n else:\n print('YES')\n for i1 in range(n):\n li = [0]*n\n b = str()\n for i2 in range((n-1)//2):\n li[(i1+i2+1)%n]+=1\n for i3 in range(len(li)):\n b+=str(li[i3])\n print(b)", "# cook your dish here\n\ndef calc(n) :\n a = n * (n-1)\n a = int(a/2)\n return a\n\nt = int(input())\ntt = 0\nwhile tt < t :\n tt = tt + 1\n n = int(input())\n num = calc(n)\n if num%n != 0 :\n print(\"NO\")\n else :\n win = int(num/n)\n print(\"YES\")\n i = 0\n while i < n :\n i = i + 1\n j = i\n str = \"\"\n k = 0\n while k < n :\n str = str + \"0\"\n k = k + 1\n k = 0\n while k < win :\n if (j+k)%n==0 :\n str = '1' + str[1:n]\n elif (j+k)%n==(n-1) :\n str = str[:n-1] + \"1\"\n else :\n kkk = (j+k)%n\n str = str[0:kkk] + \"1\" + str[kkk+1:]\n k = k + 1\n print(str) \n \n \n \n \n \n \n \n \n \n \n \n", "T = int(input())\nfor _ in range(T):\n n = int(input())\n if n%2 == 0:\n print(\"NO\")\n else:\n print(\"YES\")\n count = 0\n for _ in range(n):\n count += 1\n d = [0 for _ in range(n)]\n z = int((n - 1)/2)\n for i in range(z):\n if count + i< n-1:\n d[count + i] = 1\n else:\n d[count + i - n] = 1\n for i in d:\n print(i, end=\"\")\n print()", "t=int(input())\nfor i in range(t):\n n=int(input())\n if (n%2==0 or n==1):\n print(\"NO\")\n continue\n else:\n print(\"YES\")\n p=int((n-1)/2)\n for j in range(n):\n c=p+j-n+1\n for k in range(n):\n if ((j+p)>=n and c>=1):\n print(\"1\", end=\"\")\n c=c-1\n elif (k>=(j+1) and k<=(j+p)):\n print(\"1\", end=\"\")\n else:\n print(\"0\", end=\"\")\n print(\"\\n\", end=\"\")\n\n", "try:\n n = int(input())\n for _ in range(n):\n case = int(input())\n if(case%2==0):\n print(\"NO\")\n else:\n print(\"YES\")\n for i in range((case//2)+1):\n arr = [0]*case\n for j in range(i+1, (case//2)+i+1):\n arr[j] = 1\n print(*arr, sep=\"\")\n for i in range(case//2):\n arr = [0]*case\n for j in range(i+1):\n arr[j] = 1\n for k in range(1, (case//2)-i):\n arr[-k] = 1\n print(*arr, sep=\"\")\nexcept EOFError:\n pass\n", "# cook your dish here\nt = int(input())\n\nfor e in range(t):\n n = int(input())\n\n if n % 2 == 0:\n print(\"NO\")\n else:\n print(\"YES\")\n\n total = 0\n for g in range(n):\n total += g\n num = total // n\n \n for i in range(n):\n l = [0] * n\n for j in range(i+1, i+1+num):\n try:\n l[j] = 1\n except IndexError:\n k = j - n\n l[k] = 1\n for b in range(len(l)):\n print(l[b], end = \"\")\n \n print()\n", "try:\n for _ in range(int(input())):\n n=int(input())\n if n%2==0:\n print(\"NO\")\n else:\n z=int(((n-1)/2))\n print(\"YES\")\n for i in range(n):\n cnt=0\n N=[]\n while cnt<z:\n N.append((i+1+cnt)%n)\n cnt+=1\n for j in range(n):\n if j in N:\n print(1,end=\"\")\n else:\n print(0,end=\"\")\n print()\n \nexcept EOFError:\n pass", "for _ in range(int(input())):\n n = int(input())\n if (n-1)%2 != 0:\n print(\"NO\")\n else:\n print(\"YES\")\n b = [0]*n\n for i in range((n-1)//2):\n b[i+1] = 1\n print(*b,sep=\"\")\n for j in range(n-1,0,-1):\n print(*(b[j:]+b[:j]),sep=\"\")", "arr = [[0 for i in range(101)] for i in range(101)]\nfor i in range(1,100):\n k = 0\n for j in range(i+1,101):\n arr[i][j] = k\n k = 1-k\n arr[j][i] = k\n\nt = int(input())\nwhile t:\n n = int(input())\n if n%2==0:\n print(\"NO\")\n else:\n print(\"YES\")\n a = [arr[i][-n:] for i in range(-n,0)]\n for i in range(0,n):\n print(*a[i],sep='')\n t -= 1", "# cook your dish here\n\narr = [[0 for i in range(101)] for i in range(101)]\nfor i in range(1,100):\n k = 0\n for j in range(i+1,101):\n arr[i][j] = k\n k = 1-k\n arr[j][i] = k\n\nt = int(input())\nwhile t:\n n = int(input())\n if n%2==0:\n print(\"NO\")\n else:\n print(\"YES\")\n a = [arr[i][-n:] for i in range(-n,0)]\n for i in range(0,n):\n print(*a[i],sep='')\n t -= 1\n \n", "# cook your dish here\n\narr = [[0 for i in range(101)] for i in range(101)]\nfor i in range(1,100):\n k = 0\n for j in range(i+1,101):\n arr[i][j] = k\n k = 1-k\n arr[j][i] = k\n\nt = int(input())\nwhile t:\n n = int(input())\n if n%2==0:\n print(\"NO\")\n else:\n print(\"YES\")\n a = [arr[i][-n:] for i in range(-n,0)]\n for i in range(0,n):\n print(*a[i],sep='')\n t -= 1\n \n", "# cook your dish here\nt=int(input())\nfor s in range(t):\n n=int(input())\n if(n%2==0):\n print('NO')\n else:\n print('YES')\n a=[[0 for i in range(n)]for i in range(n)]\n i=0\n j=1\n k=1\n while(k<n):\n i=0\n j=k\n while(i<n and j<n):\n a[i][j]=1\n i+=1\n j+=1\n k+=2\n i=1\n j=0\n k=1\n while(k<n):\n i=k\n j=0\n while(i<n and j<n):\n if(a[j][i]==0):\n a[i][j]=1\n i+=1\n j+=1\n k+=1\n for i in range(n):\n for item in a[i]:\n print(item,end=\"\")\n print(\" \")", "for t in range(int(input())):\n n=int(input())\n a=n*(n-1)/2\n if a%n==0:\n print(\"YES\")\n r=int(a/n)\n rem = n-r-1\n l ='0'+'1'*r+'0'*rem\n for u in range(n):\n print(l)\n l = l[-1]+l[:-1]\n else:\n print(\"NO\")\n \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "t=int(input())\nfor i in range(t):\n N=int(input())\n L=[0]*N\n if N%2==1:\n print(\"YES\")\n for i in range(0,N):\n for k in range(1,int((N+1)/2)):\n L[(i+k)%N]=1\n for m in L:\n print(m,sep=\"\",end=\"\")\n print(\"\")\n L=[0]*N\n else:\n print(\"NO\")\n\n\n\n\n", "# cook your dish here\nt=int(input())\nfor i in range(t):\n N=int(input())\n L=[]\n for j in range(N):\n L.append(0)\n if N%2==1:\n print(\"YES\")\n for i in range(0,N):\n for k in range(1,int((N+1)/2)):\n L[(i+k)%N]=1 \n for m in L:\n print(m,sep=\"\",end=\"\")\n print(\"\")\n L=[]\n for j in range(N):\n L.append(0)\n else:\n print(\"NO\")\n \n ", "# cook your dish here\nt=int(input());\nfor i in range(t):\n n=int(input());\n j=n-1;\n if(j%2!=0):\n print(\"NO\");\n else:\n print(\"YES\");\n for i in range(1,n+1):\n k=1;\n for j in range(1,n+1):\n if(i!=j):\n if(i%2!=0):\n if(k%2!=0):\n print(\"1\",end=\"\");\n k+=1;\n else:\n print(\"0\",end=\"\");\n k+=1;\n else:\n if(k%2==0):\n print(\"1\",end=\"\");\n k+=1;\n else:\n print(\"0\",end=\"\");\n k+=1;\n else:\n print(\"0\" , end = \"\")\n print();", "# cook your dish here\nt=int(input())\nfor _ in range(t):\n n=int(input())\n # A=list(map(int,input().split()))\n a=(n-1)//2\n \n if n%2==0:\n print(\"NO\")\n else:\n print(\"YES\")\n for i in range(n-a):\n print(\"0\"*(i+1)+\"1\"*a+\"0\"*(n-i-1-a))\n for i in range(a):\n print(\"1\"*(i+1)+\"0\"*(n-a)+\"1\"*(a-i-1))\n", "for _ in range(int(input())):\n n=int(input())\n if(n%2==0):\n print(\"NO\")\n else:\n print(\"YES\")\n for i in range(n):\n l=[\"0\"]*n\n for j in range(i,i+n//2):\n\n l[((j+1)%n)]=\"1\"\n print(\"\".join(l))", "# cook your dish here\nt=int(input())\nwhile t>0:\n n=int(input())\n if(n%2!=0):\n print(\"YES\")\n k=n//2\n a=[['0' for _ in range(n)] for _ in range(n)]\n for i in range(n):\n d=0\n for j in range(i+1,n):\n a[i][j]=\"1\"\n d+=1\n if(d==k):\n break\n if(d<k):\n for j in range(k-d):\n a[i][j]=\"1\"\n for u in range(n):\n for p in range(n):\n print(a[u][p],end=\"\")\n print()\n else:\n print(\"NO\")\n t-=1", "t=int(input())\nfor i in range(0,t):\n n=int(input())\n if n%2==0:\n print(\"NO\")\n else:\n print(\"YES\")\n s=\"0\"\n for j in range(0,n//2):\n s+=\"1\"\n for j in range(0,n-(n//2 +1)):\n s+=\"0\"\n for j in range(0,n):\n print(s)\n c=s[n-1]\n s=s[0:n-1]\n s=c+s\n", "# cook your dish here\nt = int(input())\nfor _ in range(t):\n n = int(input())\n \n total = round((n * (n -1)) / 2)\n if total % n == 0:\n print(\"YES\")\n win = round(total / n)\n matches = [['0']*n for _ in range(n)]\n \n s_pos = 1\n for r in range(n):\n c_pos = s_pos\n for c in range(win):\n #print(f'Row : {r}, Col : {c_pos}')\n matches[r][c_pos] = '1'\n #print(matches[r][c_pos])\n #print(matches)\n c_pos = (c_pos + 1) % n\n \n s_pos = (s_pos + 1) % n\n \n for itr in matches:\n print(''.join(itr))\n else:\n print(\"NO\")\n \n", "# cook your dish here\nfor t in range(int(input())):\n n=int(input())\n if(n%2==0):\n print(\"NO\")\n else:\n print(\"YES\")\n n1=n//2\n for i in range(n):\n s=['0']*n\n c=0\n for j in range(i+1,n):\n s[j]='1'\n c+=1 \n if(c==n1):\n break\n if(c<n1):\n for j in range(n1-c):\n s[j]='1'\n k=''.join(s)\n print(k)\n \n", "import math\nfrom collections import deque, defaultdict\nfrom sys import stdin, stdout\ninput = stdin.readline\n# print = stdout.write\nlistin = lambda : list(map(int, input().split()))\nmapin = lambda : list(map(int, input().split()))\nfor _ in range(int(input())):\n n = int(input())\n n1 = (n*(n-1))//2\n if n1%n:\n print(\"NO\")\n else:\n print(\"YES\")\n x = [0]\n for i in range(n1//n):\n x.append(1)\n for i in range(n1//n):\n x.append(0)\n for i in range(n):\n print(\"\".join(map(str, x)))\n x = [x[-1]]+x[:-1]", "# cook your dish here\nt=int(input())\nfor i in range(t):\n n=int(input())\n if n%2==0:\n print(\"NO\")\n else:\n print(\"YES\")\n s=''\n s=s+'0'\n for j in range(n//2):\n s+='1'\n for j in range(n//2+1,n):\n s+='0'\n print(s)\n k=n-1\n for j in range(n-1):\n s1=s[0:len(s)-1]\n s2=s[len(s)-1:]\n s=s2+s1\n print(s)\n \n", "for _ in range(int(input())):\n n=int(input())\n if n%2==0:\n print(\"NO\")\n else:\n d={}\n k=(n)*(n-1)//2\n r=k//n\n # print(r)\n l=[[0 for i in range(n)] for j in range(n)]\n # print(l)\n for i in range(1,n):\n #print(d.get(i,0))\n for j in range(i+1,n+1):\n if d.get(i,0)<r:\n l[i-1][j-1]=1\n d[i]=d.get(i,0)+1\n else:\n l[j-1][i-1]=1\n d[j]=d.get(j,0)+1\n print(\"YES\")\n for i in range(n):\n for j in range(n):\n print(l[i][j],end=\"\")\n print()\n \n"]
{"inputs": [["2", "3", "2"]], "outputs": [["YES", "010", "001", "100", "NO"]]}
INTERVIEW
PYTHON3
CODECHEF
10,146
e284659ae7a91aac1fad744d042ab497
UNKNOWN
You like tracking airplane flights a lot. Specifically, you maintain history of an airplane’s flight at several instants and record them in your notebook. Today, you have recorded N such records h1, h2, ..., hN, denoting the heights of some airplane at several instants. These records mean that airplane was first flying on height h1, then started changing its height to h2, then from h2 to h3 and so on. The airplanes are usually on cruise control while descending or ascending, so you can assume that plane will smoothly increase/decrease its height from hi to hi + 1 with a constant speed. You can see that during this period, the airplane will cover all possible heights in the range [min(hi, hi+1), max(hi, hi+1)] (both inclusive). It is easy to see that the plane will be at all possible heights in the range exactly a single instant of time during this ascend/descend. You are interested in finding the maximum integer K such that the plane was at some height exactly K times during the flight. -----Input----- There is a single test case. First line of the input contains an integer N denoting the number of records of heights of the plane. Second line contains N space separated integers denoting h1, h2, ..., hN. -----Output----- Output a single maximum integer K in one line, such that the plane was at some height exactly K times during the flight. -----Constraints----- - hi ≠ hi+1 -----Subtasks----- Subtask #1: (30 points) - 1 ≤ N ≤ 1000 - 1 ≤ hi ≤ 1000 Subtask #2: (70 points) - 1 ≤ N ≤ 105 - 1 ≤ hi ≤ 109 -----Example----- Input: 5 1 2 3 2 3 Output: 3 -----Explanation----- The flight can be draw as: 3 /\/ 2 / 1 There are infinitely many heights at which the plane was 3 times during the flight, for example 2.5, 2.1. Notice that the plane was only 2 times at height 2. Moreover, there are no height at which the plane was more than 3 times, so the answer is 3.
["def f(n):\n\n s = list(map(int, input().split()))\n low = []\n high = []\n\n for i in range(n - 1):\n low.append(min(s[i], s[i+1]))\n high.append(max(s[i], s[i+1]))\n low.sort()\n high.sort()\n curr = mx = 0\n i = j = 0\n n -= 1\n while i < n and j < n:\n if low[i] < high[j]:\n i += 1\n curr += 1\n else:\n j += 1\n curr -= 1\n mx = max(mx, curr)\n\n return mx \n \nn = int(input())\nprint(f(n))"]
{"inputs": [["5", "1 2 3 2 3"]], "outputs": [["3"]]}
INTERVIEW
PYTHON3
CODECHEF
413
72c58e5f0c3cb701d0c50379754bfd23
UNKNOWN
You must have tried to solve the Rubik’s cube. You might even have succeeded at it. Rubik’s cube is a 3x3x3 cube which has 6 different color for each face.The Rubik’s cube is made from 26 smaller pieces which are called cubies. There are 6 cubies at the centre of each face and these comprise of a single color. There are 8 cubies at the 8 corners which comprise of exactly 3 colors. The 12 reamaining cubies comprise of exactly 2 colors. Apple has come up with a variation of the Rubik’s Cube, it’s the Rubik’s cuboid which has different colors on its 6 faces. The Rubik’s Cuboid comes in various sizes represented by M x N x O (M,N,O are natural numbers). Apple is giving away 100 Rubik’s cuboid for free to people who can answer a simple questions. Apple wants to know, in a Rubik’s cuboid with arbitrary dimensions, how many cubies would be there, which comprise of exactly 2 color. -----Input----- The input contains several test cases.The first line of the input contains an integer T denoting the number of test cases. Each test case comprises of 3 natural numbers, M,N & O, which denote the dimensions of the Rubiks Cuboid. -----Output----- For each test case you are required to output the number of cubies which comprise of 2 squares, each of which is of a different color. -----Constraints----- - 1 ≤ T ≤ <1000 - 1 ≤ M ≤ <100000 - 1 ≤ N ≤ <100000 - 1 ≤ O ≤ <100000 -----Example----- Input: 1 3 3 3 Output: 12
["for _ in range(int(input())):\n m=int(input())\n n=int(input())\n o=int(input())\n ans=4*(m+n+o)-24\n if(ans <= 0):\n print('0')\n else:\n print(ans)\n", "import sys\n\nfor __ in range(eval(input())) :\n m , n , o = eval(input()) , eval(input()) , eval(input())\n if m==1 and n==1 and o==1 :\n print(0)\n continue\n print((m-2)*4+(n-2)*4+(o-2)*4)\n", "for tt in range(eval(input())):\n m=eval(input())\n n=eval(input())\n o=eval(input())\n if m==1 and n==1 and o==1:\n print('0')\n continue\n if m!=1 and n!=1 and o!=1:\n ans = abs(4*(m-2)+4*(n-2)+4*(o-2))\n print(ans)\n elif (m==1 and n>1 and o>1):\n ans = (n*o) - ((2*n)+2*(o-2))\n print(ans)\n elif (n==1 and m>1 and o>1):\n ans = (m*o) - ((2*m)+2*(o-2))\n print(ans)\n elif (o==1 and m>1 and n>1):\n ans = (m*n) - ((2*m)+2*(n-2))\n print(ans)\n", "from sys import stdin, stdout\nt = int(stdin.readline())\nwhile t:\n t -= 1\n m = int(stdin.readline())\n n = int(stdin.readline())\n o = int(stdin.readline())\n if m>2 and n>2 and o>2:\n ans = 4*(m+n+o-6)\n elif m==1 or n==1 or o==1 or(m==2 and n==2 and o==2):\n ans=0\n else:\n ans = (m-2) if m > 2 else 0\n ans += (n-2) if m > 2 else 0\n ans += (o-2) if m > 2 else 0\n stdout.write(str(ans)+'\\n')", "for t in range(int(input())):\n m=int(input())\n n=int(input())\n o=int(input())\n if m==1 and (n==1 and o==1):\n print(0)\n else:\n print((m+n+o-6)*4)", "for _ in range(int(input())):\n a=int(input())\n b=int(input())\n c=int(input())\n if a==1 or b==1 or c==1:\n print(0) \n else:\n print(4*(a+b+c-6))"]
{"inputs": [["1", "3", "3", "3"]], "outputs": [["12"]]}
INTERVIEW
PYTHON3
CODECHEF
1,537
adc96bd0e31e41d2654cd9bfabacd124
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:----- 12 21 123 231 312 1234 2341 3412 4123 -----EXPLANATION:----- No need, else pattern can be decode easily.
["# cook your dish here\nfor a0 in range(int(input())):\n n = int(input())\n l = []\n for i in range(1,n+1):\n l.append(i)\n \n for j in range(n):\n s = \"\"\n for k in l:\n s+=str(k)\n print(s)\n x = l[0]\n l.pop(0)\n l.append(x)\n", "for _ in range(int(input())):\r\n n = int(input())\r\n arr = list(range(1,n+1))\r\n for i in range(n):\r\n print(*(arr[i:]+arr[:i]),sep='')", "from sys import*\r\ninput=stdin.readline\r\nt=int(input())\r\nfor _ in range(t):\r\n n=int(input())\r\n y=1\r\n for i in range(n):\r\n y=i+1\r\n for j in range(n):\r\n print(y,end=\"\")\r\n y=(y+1)\r\n if y>n:\r\n y=y%n\r\n if y==0:\r\n y=1\r\n print()\r\n", "for _ in range(int(input())):\n n = int(input())\n if n == 1:\n print(n)\n continue\n s = []\n for i in range(1, n + 1):\n s.append(i)\n s*=2\n # print(s)\n for i in range(0, len(s)//2):\n x = s[i:i+n]\n x = list(map(str, x))\n print(''.join(x))\n # print(s[i:i+n])\n", "\r\nt=int(input())\r\nwhile t>0:\r\n t-=1\r\n n=int(input())\r\n a=[]\r\n for i in range(1,n+1):\r\n a.append(i)\r\n for i in range(n):\r\n \r\n for i in a:\r\n print(i,end=\"\")\r\n x=a[0]\r\n a.append(x)\r\n a.pop(0)\r\n print()\r\n", "\nt=int(input())\nfor i in range(t):\n k=int(input())\n arr=[]\n for i in range(1,k+1):\n arr.append(i)\n \n for i in range(k):\n for j in range(i,k):\n print(arr[j],end=\"\")\n for j in range(0,i):\n print(arr[j],end=\"\")\n print() \n", "for _ in range(int(input())):\n n = int(input())\n l = list(range(1, n + 1))\n for x in range(n):\n print(*l[x:], sep=\"\", end=\"\")\n print(*l[:x], sep=\"\")\n# cook your dish here\n", "for _ in range(int(input())):\n n=int(input())\n a=[]\n for _ in range(1,n+1):\n a.append(str(_))\n a=a+a\n for _ in range(n):\n print(''.join(a[_:_+n]))\n", "t=int(input())\r\nfor i in range(t):\r\n k=int(input())\r\n m=0\r\n for j in range(1,k+1):\r\n for m in range(j,k+1):\r\n print(m,end=\"\")\r\n for n in range(1,j):\r\n print(n,end=\"\")\r\n print()", "try:\r\n t = int(input())\r\n for a in range(t):\r\n k = int(input())\r\n lst = []\r\n for i in range(1,k+1):\r\n lst.append(str(i))\r\n print(\"\".join(lst))\r\n for i in range(k-1):\r\n lst.append(lst[0])\r\n lst.pop(0)\r\n print(\"\".join(lst))\r\nexcept EOFError:\r\n pass", "#Pattern E\r\nT = int(input())\r\n\r\nfor t in range(T):\r\n N = int(input())\r\n \r\n for i in range(N):\r\n sol = \"\"\r\n for j in range(1,N+1):\r\n if((j+i)%N == 0):\r\n sol+=str(N)\r\n else:\r\n sol+=str((j+i)%N)\r\n print(sol)", "t = int(input())\nfor _ in range(t):\n n = int(input())\n for i in range(n):\n for j in range(n):\n if (i+j+1) <= (n):\n print(i+j+1,end='')\n else:\n print(i+j-n+1,end='')\n print()\n", "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 for i in range(1, n+1):\n for j in range(n):\n a = (i+j)%n if (i+j)%n!=0 else n\n print(str(a), end=\"\")\n print()", "for _ in range(int(input())):\r\n n = int(input())\r\n l = list(range(1, n+1))\r\n\r\n for i in range(n):\r\n print(*l, sep='')\r\n l = l[1:] + [l[0]]\r\n", "for tc in range(int(input())):\r\n K = int(input())\r\n S = [str(i) for i in range(1, K + 1)]\r\n for i in range(K):\r\n print(''.join(S))\r\n S = S[1:] + [S[0]]"]
{"inputs": [["3", "2", "3", "4"]], "outputs": [["12", "21", "123", "231", "312", "1234", "2341", "3412", "4123"]]}
INTERVIEW
PYTHON3
CODECHEF
4,981
b0f14fa9a1e40ab26250573c66524fcc
UNKNOWN
You are given $N$ gears numbered $1$ through $N$. For each valid $i$, gear $i$ has $A_i$ teeth. In the beginning, no gear is connected to any other. Your task is to process $M$ queries and simulate the gears' mechanism. There are three types of queries: - Type 1: Change the number of teeth of gear $X$ to $C$. - Type 2: Connect two gears $X$ and $Y$. - Type 3: Find the speed of rotation of gear $Y$ if gear $X$ rotates with speed $V$. It is known that if gear $i$ is directly connected to gear $j$ and gear $i$ rotates with speed $V$, then gear $j$ will rotate with speed $-V A_i / A_j$, where the sign of rotation speed denotes the direction of rotation (so minus here denotes rotation in the opposite direction). You may also notice that gears can be blocked in some cases. This happens when some gear would have to rotate in different directions. If a gear is connected to any blocked gear, it is also blocked. For example, if three gears are connected to each other, this configuration can not rotate at all, and if we connect a fourth gear to these three, it will also be blocked and not rotate. -----Input----- - The first line of the input contains two space-separated integers $N$ and $M$. - The second line contains $N$ space-separated integers $A_1, A_2, \dots, A_N$. - The following $M$ lines describe queries. Each of these lines begins with an integer $T$ denoting the type of the current query. - If $T = 1$, it is followed by a space and two space-separated integers $X$ and $C$. - If $T = 2$, it is followed by a space and two space-separated integers $X$ and $Y$. - If $T = 3$, it is followed by a space and three space-separated integers $X$, $Y$ and $V$. -----Output----- For each query of type 3, print a single line containing two integers separated by a slash '/' — the numerator and denominator of the rotation speed of the given gear expressed as an irreducible fraction (even if this speed is an integer), or $0$ if the gear does not rotate at all. -----Constraints----- - $1 \le N \le 10^5$ - $1 \le M \le 2\cdot 10^5$ - $6 \le A_i \le 10^6$ for each valid $i$ - $1 \le X, Y \le N$ - $1 \le C, V \le 10^6$ -----Subtasks----- Subtask #1 (30 points): - $N \le 2,000$ - $M \le 5,000$ Subtask #2 (70 points): original constraints -----Example Input----- 4 10 6 8 10 13 3 1 2 2 2 1 2 3 1 2 3 2 2 3 1 1 7 3 1 3 10 2 3 1 3 1 3 2 2 1 4 3 1 4 6 -----Example Output----- 0 -9/4 7/1 0 0 -----Explanation----- For the first query of type 3, there are no connections between gears, so the answer is $0$. For the second query of type 3, we can calculate the rotation speed using the formula $-3\cdot\frac{6}{8} = \frac{-9}{4}$. For the third query of type 3, we can use the formula twice, so the speed of the second gear is $-10\cdot\frac{7}{8} = -\frac{35}{4}$, and the speed of the third gear is $-(-\frac{35}{4})\frac{8}{10} = \frac{7}{1}$. For the last query of type 3, all gears are blocked.
["class Dsu:\n def __init__(self, v, s):\n self.par = s\n self.v = v\n self.dr = [1] * v\n self.zero = [False] * v\n self.speed = []\n for i in range(v):\n self.speed.append([])\n self.speed[i].append(i)\n\n def find(self, i):\n # if parent[i] == -1:\n # return i\n # else: return self.find_parent(parent, parent[i])\n if i != self.par[i][0]:\n org = self.par[i][0]\n self.par[i][0] = self.find(self.par[i][0])\n if self.zero[i] or self.zero[self.par[i][0]] or self.zero[org]:\n self.zero[i] = self.zero[self.par[i][0]] = self.zero[org] = True\n if org != self.par[i][0]:\n self.speed[self.par[i][0]].append(i)\n return self.par[i][0]\n\n def union(self, x, y):\n # def union(self, parent, x, y):\n # x_set = self.find_parent(parent, x)\n # y_set = self.find_parent(parent, y)\n # parent[x_set] = y_set\n self.rx = self.find(x)\n self.ry = self.find(y)\n self.sign = -self.dr[x] * self.dr[y]\n if self.rx != self.ry:\n if (self.par[self.rx][1]<self.par[self.ry][1]):\n mx=self.ry\n mn=self.rx\n if (self.par[self.rx][1]>self.par[self.ry][1]):\n mx=self.rx\n mn=self.ry\n if self.par[self.rx][1] != self.par[self.ry][1]:\n self.par[mn][0] = mx\n if self.zero[mn] or self.zero[mx] or self.zero[x] or self.zero[y]:\n self.zero[mn] = self.zero[mx] = self.zero[x] = self.zero[y] = True\n else:\n for i in range(len(self.speed[mn])):\n self.dr[self.speed[mn][i]] *= self.sign\n org = self.par[self.speed[mn][i]][0]\n if org != mx:\n self.par[self.speed[mn][i]][0] = mx\n self.speed[mx].append(self.speed[mn][i])\n self.speed[mx].append(mn)\n\n else:\n self.par[self.ry][0] = self.rx\n self.par[self.rx][1] += 1\n if self.zero[self.rx] or self.zero[self.ry] or self.zero[x] or self.zero[y]:\n self.zero[self.rx] = self.zero[self.ry] = self.zero[x] = self.zero[y] = True\n else:\n for i in range(len(self.speed[self.ry])):\n self.dr[self.speed[self.ry][i]] *= self.sign\n org = self.par[self.speed[self.ry][i]][0]\n if org != self.rx:\n self.par[self.speed[self.ry][i]][0] = self.rx\n self.speed[self.rx].append(self.speed[self.ry][i])\n self.speed[self.rx].append(self.ry)\n else:\n return\n\n\ndef optwo(x, y, D):\n if (D.find(x) == D.find(y) and D.dr[x] == D.dr[y]):\n D.zero[x] = D.zero[y] = True\n D.union(x, y)\n\n\ndef gcd(a, b):\n if a == 0:\n return b\n else:\n return gcd(b % a, a)\n\n\ndef opthree(x, y, v, D):\n if (D.find(x) != D.find(y)) or (D.zero[D.par[y][0]]):\n print(0)\n else:\n g = gcd(v * speed[x], speed[y])\n flag=(D.dr[x] * D.dr[y])//abs(D.dr[x] * D.dr[y])\n print(str(flag * v * speed[x] // g) + \"/\" + str(speed[y] // g))\n\n\nn, M = map(int, input().split())\nspeed = list(map(int, input().split()))\ns = []\nfor i in range(n):\n s.append([i, 0])\nD = Dsu(n, s)\nfor i in range(M):\n T = list(map(int, input().split()))\n if (T[0] == 1):\n speed[T[1] - 1] = T[2]\n elif (T[0] == 2):\n optwo(T[1] - 1, T[2] - 1, D)\n elif (T[0] == 3):\n opthree(T[1] - 1, T[2] - 1, T[3], D)\n"]
{"inputs": [["4 10", "6 8 10 13", "3 1 2 2", "2 1 2", "3 1 2 3", "2 2 3", "1 1 7", "3 1 3 10", "2 3 1", "3 1 3 2", "2 1 4", "3 1 4 6", ""]], "outputs": [["0", "-9/4", "7/1", "0", "0"]]}
INTERVIEW
PYTHON3
CODECHEF
3,837
74b46ef75845dfcce14e03974fe5ccc4
UNKNOWN
Given an alphanumeric string made up of digits and lower case Latin characters only, find the sum of all the digit characters in the string. -----Input----- - The first line of the input contains an integer T denoting the number of test cases. Then T test cases follow. - Each test case is described with a single line containing a string S, the alphanumeric string. -----Output----- - For each test case, output a single line containing the sum of all the digit characters in that string. -----Constraints----- - 1 ≤ T ≤ 1000 - 1 ≤ |S| ≤ 1000, where |S| is the length of the string S. -----Example----- Input: 1 ab1231da Output: 7 -----Explanation----- The digits in this string are 1, 2, 3 and 1. Hence, the sum of all of them is 7.
["for _ in range(eval(input())):\n s = input()\n ans = 0\n for i in s:\n if i.isdigit():\n ans += int(i)\n print(ans) ", "t = int(input())\nwhile t:\n string = list(input())\n ans = 0\n for char in string:\n if ord(char) >= 48 and ord(char) <= 57:\n ans += ord(char) - 48 \n print(ans)\n t -= 1 ", "n = int(input())\nc = 0\nfor i in range(n):\n a = input()\n for i in a:\n if i.isdigit() :\n c += int(i)\n print(c)\n c = 0\n", "# your code goes here\nt = int(input())\nfor _t in range(t):\n st = input()\n ans = 0\n for i in st:\n if i>'0' and i <= '9':\n ans += int(i)\n print(ans)", "# cook your code here\nt=int(input())\nfor i in range(t):\n l=list(input())\n count=0\n for j in l:\n if(j.isdigit()):\n count=count+int(j)\n print(count)", "# nonlocal vairables\nT = eval(input())\ncounter = 1\n\n# methods\ndef ri():\n return list(map(int,input().strip().split()))\n\ndef rs():\n return input().strip().split()\n\ndef solve():\n S = rs()[0]\n ans = 0\n for i in S:\n # print i\n if i.isdigit():\n ans += int(i)\n return ans\n\nwhile T>0:\n T-=1\n print(str(solve()))\n counter+=1\n", "t = int(input())\nwhile t>0:\n t-=1\n sum = 0\n a = input()\n b = list(a)\n for i in b:\n if (i.isdigit()):\n \n sum+=int(i);\n\n print(sum)", "t=eval(input())\nfor x in range(0,t):\n arr=list(input())\n sum=0\n for i in arr:\n if(i.isdigit()):\n sum+=int(i)\n print(sum)", "def getSum(s1):\n sum = 0\n for c in s1:\n if c.isdigit():\n sum += int(c)\n return sum\n\nT = int(input())\nfor i in range(T):\n s = input()\n print(getSum(s))", "import string\nt= int (input().strip())\nfor i in range(t):\n s=input().strip()\n c=0\n for j in s:\n if j.isdigit():\n c+=int(j)\n print(c)\n", "T = eval(input())\n\nwhile (T > 0):\n S = input()\n res = 0\n for i in range(len(S)):\n if (ord(S[i]) <= 57 and ord(S[i]) >=49 ):\n res = res + int(S[i])\n print(res)\n T = T - 1", "t=eval(input())\nfor ii in range(t):\n s=input()\n ans=0\n for i in s:\n if i.isdigit():ans+=int(i)\n print(ans)", "T = int(input())\nfor t in range(T):\n word = input()\n s = 0\n for c in word:\n if c.isdigit():\n s += int(c)\n print(s)\n", "def int_(s):\n try: \n int(s)\n return True\n except ValueError:\n return False\nt=int(input())\nwhile t>0:\n c = str(input())\n s=0\n for i in c:\n if int_(i):\n s=s+int(i)\n print(s) \n t=t-1", "T = int(input())\n\nfor i in range(T):\n s = input()\n count = 0\n for j in range(len(s)):\n if(s[j].isdigit()):\n count += int(s[j])\n print(count)", "T = int(input())\nfor _ in range(T):\n s = input()\n tot = 0\n for x in s:\n if 0<ord(x)-48<10:\n tot += ord(x) - 48\n print(tot)", "c=1\ncases=eval(input())\n\nwhile(c<=cases):\n s=list(input())\n sumc=0\n for i in s:\n g=ord(i)\n if(g>48 and g<=57):\n sumc+=int(i)\n print(sumc)\n c=c+1", "t=int(input().strip())\nfor _ in range(t):\n p = input().strip()\n count=0\n for i in p:\n if not('a'<=i<='z'):\n count+=int(i)\n print(count)\n", "n = int(input())\n\nc=0\nsum=0\nwhile n:\n n-=1\n a = [i for i in input()]\n sum=0\n for i in a:\n try:\n sum+=int(i)\n except:\n continue\n print(sum)\n"]
{"inputs": [["1", "ab1231da"]], "outputs": [["7"]]}
INTERVIEW
PYTHON3
CODECHEF
3,108
6ac09e9b047462f79ad9d6eb15444b42
UNKNOWN
You are given an integer sequence $A_1, A_2, \ldots, A_N$. For any pair of integers $(l, r)$ such that $1 \le l \le r \le N$, let's define $\mathrm{OR}(l, r)$ as $A_l \lor A_{l+1} \lor \ldots \lor A_r$. Here, $\lor$ is the bitwise OR operator. In total, there are $\frac{N(N+1)}{2}$ possible pairs $(l, r)$, i.e. $\frac{N(N+1)}{2}$ possible values of $\mathrm{OR}(l, r)$. Determine if all these values are pairwise distinct. -----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$. -----Output----- For each test case, print a single line containing the string "YES" if all values of $\mathrm{OR}(l, r)$ are pairwise distinct or "NO" otherwise (without quotes). -----Constraints----- - $1 \le T \le 300$ - $1 \le N \le 10^5$ - $0 \le A_i \le 10^{18}$ for each valid $i$ - the sum of $N$ over all test cases does not exceed $3 \cdot 10^5$ -----Example Input----- 4 3 1 2 7 2 1 2 3 6 5 8 5 12 32 45 23 47 -----Example Output----- NO YES YES NO -----Explanation----- Example case 1: The values of $\mathrm{OR}(l, r)$ are $1, 2, 7, 3, 7, 7$ (corresponding to the contiguous subsequences $[1], [2], [7], [1,2], [2,7], [1,2,7]$ respectively). We can see that these values are not pairwise distinct. Example case 2: The values of $\mathrm{OR}(l, r)$ are $1, 2, 3$ (corresponding to the contiguous subsequences $[1], [2], [1, 2]$ respectively) and they are pairwise distinct.
["for _ in range(int(input())):\n n = int(input())\n arr = list(map(int,input().split()))\n\n if n<=62:\n st = set()\n\n for i in range(n):\n curr = 0\n for j in range(i,n):\n curr = curr|arr[j]\n\n st.add(curr)\n \n if len(st)==n*(n+1)//2:\n print(\"YES\")\n else:\n print(\"NO\")\n \n else:\n print(\"NO\")", "# cook your dish here\ndef ortho(n,m):\n res=set()\n tot=(n*(n+1))//2\n pre ={0}\n for x in m:\n pre = {x | y for y in pre} | {x}\n res |= pre\n if(len(res)==tot):\n return \"YES\"\n return \"NO\"\nt=int(input())\nfor i in range(t):\n n=int(input())\n m=list(map(int, input().split()))\n print(ortho(n,m))", "for _ in range(int(input())):\n n=int(input())\n ar=[int(x) for x in input().split()]\n\n if n>62:\n print(\"NO\")\n else:\n v=[]\n f=0\n for i in range(n):\n x=ar[i]\n if ar[i] not in v:\n v.append(ar[i])\n else:\n f=1\n break\n for j in range(i+1,n):\n x|=ar[j]\n if x in v:\n f=1\n break\n else:\n v.append(x)\n if f==1:\n break\n \n if f==1:\n print(\"NO\")\n else:\n print(\"YES\")\n \n \n \n \n \n \n \n \n \n", "T = int(input())\nans = []\n\nfor _ in range(T):\n N = int(input())\n A = [int(i) for i in input().split()]\n\n if(N>62):\n ans.append('NO')\n else:\n D = {}\n flag = True\n for i in range(N):\n x = 0\n for j in range(i,N):\n x |= A[j]\n if(x in D):\n flag = False\n break\n D[x] = True\n if(not flag):\n break\n if(flag):\n ans.append('YES')\n else:\n ans.append('NO')\n\nfor i in ans:\n print(i)\n", "def answer():\n if(n <= 60):\n all_=set()\n for i in range(n):\n value=0\n for j in range(i,n):\n value|=a[j]\n all_.add(value)\n if(len(all_)==n*(n+1)//2):return 'YES'\n return 'NO'\nfor T in range(int(input())):\n n=int(input())\n a=list(map(int,input().split()))\n print(answer())\n\n", "def answer():\n if(n <= 60):\n all_=set()\n for i in range(n):\n value=0\n for j in range(i,n):\n value|=a[j]\n all_.add(value)\n if(len(all_)==n*(n+1)//2):return 'YES'\n return 'NO'\nfor T in range(int(input())):\n n=int(input())\n a=list(map(int,input().split()))\n\n print(answer())\n\n", "def answer():\n value=a[0]\n\n if(n <= 60):\n \n all_=set()\n for i in range(n):\n value=0\n for j in range(i,n):\n value|=a[j]\n all_.add(value)\n \n if(len(all_)==n*(n+1)//2):\n return 'YES'\n\n \n return 'NO'\n\nfor T in range(int(input())):\n n=int(input())\n a=list(map(int,input().split()))\n\n print(answer())\n\n", "import math\nfor t in range(int(input())):\n n=int(input())\n values=list(map(int,input().split()))\n check=set()\n if n>60:\n print(\"NO\")\n else:\n for i in range(n):\n check.add(values[i])\n \n for i in range(n):\n st=0\n for j in range(i,n):\n st=st|values[j]\n check.add(st)\n d=(n*(n+1))//2\n if len(check)==d:\n print(\"YES\")\n else:\n print(\"NO\")\n", "# cook your dish here\nfor t in range(int(input())):\n n=int(input())\n l=list(map(int,input().split()))\n s=set()\n f=1\n for i in range(n):\n a=l[i]\n for j in range(i,n):\n a|=l[j]\n if(a in s):\n print('NO')\n f=0\n break\n s.add(a)\n if(f==0):\n break\n if(f):\n print('YES')", "# cook your dish here\nfor t in range(int(input())):\n n=int(input())\n l=list(map(int,input().split()))\n s=set()\n f=1\n for i in range(n):\n a=l[i]\n for j in range(i,n):\n a|=l[j]\n if(a in s):\n print('NO')\n f=0\n break\n s.add(a)\n if(f==0):\n break\n if(f):\n print('YES')", "for t in range(int(input())):\n n=int(input())\n l=list(map(int,input().split()))\n s=set()\n f=1\n for i in range(n):\n a=l[i]\n for j in range(i,n):\n a|=l[j]\n if(a in s):\n print('NO')\n f=0\n break\n s.add(a)\n if(f==0):\n break\n if(f):\n print('YES')", "# cook your dish here\nT = int(input())\nfor _ in range(T):\n n = int(input())\n arr = list(map(int, input().strip().split()))\n s = set()\n if n > 60:\n print(\"NO\")\n else:\n for i in range(n):\n ordd = 0\n for j in range(i, n):\n ordd = ordd | arr[j]\n s.add(ordd)\n if len(s) == n*(n+1) / 2:\n print(\"YES\")\n else:\n print(\"NO\")\n", "# cook your dish here\nfor _ in range(int(input())):\n n= int(input())\n l=list(map(int,input().split()))\n N=(n)*(n+1)//2\n d=set()\n if n>60:\n print('NO')\n else:\n for i in range(n):\n ans=0\n for j in range(i,n):\n ans=l[j]|ans \n d.add(ans)\n if len(d)==N:\n print('YES')\n else:\n print('NO')", "# cook your dish here\ndef main():\n t = int(input())\n for _ in range(t):\n n = int(input())\n ar = list(map(int, input().split()))\n if n > 62:\n print(\"NO\")\n continue\n lk = set()\n ok = True\n for sz in range(1, n + 1):\n idx = 0\n while idx + sz - 1 < n:\n curr = 0\n for j in range(idx, idx + sz):\n curr = curr | ar[j]\n if curr in lk:\n ok = False\n break\n else:\n lk.add(curr)\n idx += 1\n if ok:\n print(\"YES\")\n else:\n print(\"NO\")\n\ndef __starting_point():\n main()\n__starting_point()", "t = int(input())\nwhile t!= 0:\n n = int(input())\n ls = list(map(int,input().split()))\n p ={0}\n res = set()\n for i in ls:\n p = {i|y for y in p} | {i}\n res |= p\n if len(res) ==(n*(n+1))//2:\n print(\"YES\")\n else:\n print(\"NO\")\n t-=1", "# cook your dish here\ndef subArrayBitWiseOR(A):\n res=set()\n pre={0}\n for x in A:\n pre={x | y for y in pre} | {x}\n res|=pre\n return(len(res))\nt=int(input())\nwhile(t>0):\n t-=1\n n=int(input())\n a=list(map(int,input().split()))\n d=subArrayBitWiseOR(a)\n if(d==(n*(n+1))/2):\n print(\"YES\")\n else:\n print(\"NO\")", "t = int(input())\nwhile t!= 0:\n n = int(input())\n ls = list(map(int,input().split()))\n p ={0}\n res = set()\n for i in ls:\n p = {i|y for y in p} | {i}\n res |= p\n if len(res) ==(n*(n+1))//2:\n print(\"YES\")\n else:\n print(\"NO\")\n t-=1", "\nt=int(input())\nfor k in range(t):\n n=int(input())\n arr=list(map(int,input().split()))\n set1=[]\n for i in range(n):\n if arr[i] in set1:\n f=1\n print(\"NO\")\n break\n else:\n f=0\n set1.append(arr[i])\n for j in range(i+1,n):\n arr[i]=arr[i]|arr[j]\n if arr[i] in set1:\n f=1\n print(\"NO\")\n break\n else:\n set1.append(arr[i])\n f=0\n if f==1:\n break\n if f==0:\n print(\"YES\")\n \n \n \n \n \n", "T = int(input())\nwhile T:\n N = int(input())\n A = list(map(int, input().split()))\n d = set()\n n = (N * (N + 1)) // 2\n if N > 60:\n print(\"NO\")\n else:\n for i in range(N):\n ans = 0\n for j in range(i, N):\n ans = A[j] | ans\n d.add(ans)\n if len(d) == n:\n print(\"YES\")\n else:\n print(\"NO\")\n\n T -= 1", "# cook your dish here\ndef solve(A): \n res, pre=set(),{0}\n for x in A: \n pre={x|y for y in pre}|{x} \n res|=pre \n return len(res) \n \ntest=int(input())\nfor _ in range(test):\n n=int(input())\n arr=list(map(int,input().split()))\n if(solve(arr)!=n*(n+1)//2):\n print('NO')\n else:\n print('YES')\n", "def solve(A): \n res, pre = set(), {0}\n for x in A: \n pre = {x | y for y in pre} | {x} \n res |= pre \n return len(res) \n \n\nfor t in range(int(input())):\n n = int(input())\n arr = list(map(int, input().split()))\n if(solve(arr) != n*(n+1)//2):\n print('NO')\n else:\n print('YES')\n", "try:\n t=int(input())\n if 1<=t<=300:\n for T in range(t):\n n=int(input())\n a=list(map(int,input().split()))\n a.sort(reverse=True)\n to_add=a[0]\n f=0\n for i in range(1,n):\n to_add=to_add|a[i]\n if to_add in a:\n f=1\n break\n a.append(to_add)\n if f==1:\n print(\"NO\")\n else:\n print(\"YES\")\nexcept:\n pass\n\n", "for _ in range(int(input())):\n n=int(input())\n a=list(map(int,input().split()))\n a.sort(reverse=True)\n to_add=a[0]\n f=0\n for i in range(1,n):\n to_add=to_add|a[i]\n if to_add in a:\n f=1\n break\n a.append(to_add)\n if f==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 tot=(n*(n+1))//2\n ans=a.copy()\n to_add=0\n if n>62:\n print(\"NO\")\n continue\n for i in range(n-1):\n to_add=a[i]\n for j in range(i+1,n):\n to_add=to_add|a[j]\n ans.append(to_add)\n if len(set(ans))==tot:\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 tot=(n*(n+1))//2\n ans=a.copy()\n to_add=0\n if n>=62:\n print(\"NO\")\n continue\n for i in range(n-1):\n to_add=a[i]\n for j in range(i+1,n):\n to_add=to_add|a[j]\n ans.append(to_add)\n if len(set(ans))==tot:\n print(\"YES\")\n else:\n print(\"NO\")"]
{"inputs": [["4", "3", "1 2 7", "2", "1 2", "3", "6 5 8", "5", "12 32 45 23 47"]], "outputs": [["NO", "YES", "YES", "NO"]]}
INTERVIEW
PYTHON3
CODECHEF
8,621
ac96f450fa786a8b2d0425d932c848b6
UNKNOWN
In this problem the input will consist of a number of lines of English text consisting of the letters of the English alphabet, the punctuation marks ' (apostrophe), . (full stop), , (comma), ; (semicolon), :(colon) and white space characters (blank, newline). Your task is print the words in the text in lexicographic order (that is, dictionary order). Each word should appear exactly once in your list. You can ignore the case (for instance, "The" and "the" are to be treated as the same word). There should be no uppercase letters in the output. For example, consider the following candidate for the input text: This is a sample piece of text to illustrate this problem. The corresponding output would read as: a illustrate is of piece problem sample text this to -----Input format----- - The first line of input contains a single integer $N$, indicating the number of lines in the input. - This is followed by $N$ lines of input text. -----Output format----- - The first line of output contains a single integer $M$ indicating the number of distinct words in the given text. - The next $M$ lines list out these words in lexicographic order. -----Constraints----- - $1 \leq N \leq 10000$ - There are at most 80 characters in each line. - There are at the most 1000 distinct words in the given text. -----Sample Input----- 2 This is a sample piece of text to illustrate this problem. -----Sample Output----- 10 a illustrate is of piece problem sample text this to
["import sys\nt=int(input())\nx=sys.stdin.readlines()\nl=[]\nfor s in x:\n s=s.replace(\".\",\"\")\n s=s.replace(\"'\",\"\")\n s=s.replace(\",\",\"\")\n s=s.replace(\":\",\"\")\n s=s.replace(\";\",\"\")\n lst=[str(i) for i in s.split()]\n for j in lst:\n l.append(j)\nm=[]\nfor y in l:\n z=y.lower()\n m.append(z)\nn=[]\nfor k in m:\n if(k in n):\n continue\n else:\n n.append(k)\nprint(len(n))\nh=sorted(n)\nfor j in h:\n print(j)", "n= int(input())\ns1=''\nfor _ in range(n):\n s=input()\n s1=s1+s\ns1=s1.lower()\ns1=s1.replace('.','').replace(',','').replace(\"'\",\"\").replace(':','').replace(';','')\na=set(s1.split())\nb=list(a)\nb.sort()\nprint(len(b))\nfor i in b:\n print(i)\n", "import re\r\n\r\nn=int(input())\r\narr=[]; ans=[]\r\n\r\nfor i in range(n):\r\n temp=input().lower().split()\r\n for j in temp:\r\n valids=re.sub(r\"[^a-z]+\", '', j)\r\n arr.append(valids)\r\n\r\n#while('')\r\nwhile('' in arr):\r\n arr.remove('')\r\n \r\n'''for j in range(len(temp)):\r\n if(temp[j]=='.' or temp[j]==';' or temp[j]=='\\'' or temp[j]==':'):\r\n del(temp[j])\r\n if(temp[j]==',' or temp[j]==\"\\n\" or temp[j]==\"\"):\r\n del(temp[j])\r\n \r\n for j in range(len(temp)):\r\n arr.append(temp[j])'''\r\nans=arr\r\n'''for i in arr:\r\n valids = re.sub(r\"[^a-z]+\", '', i)\r\n ans.append(valids)\r\n print(ans)'''\r\n \r\nans=list(set(list(ans)))\r\nans.sort()\r\nprint(len(ans))\r\nprint(*ans, sep='\\n')\r\n ", "lst=[]\r\nans=[]\r\npunctuations = '''!()-[]{};:'\"\\,<>./?@#$%^&*_~'''\r\nt=int(input())\r\nfor i in range(t):\r\n str= input()\r\n s=str.lower()\r\n no_punct = \"\"\r\n for char in s:\r\n if char not in punctuations:\r\n no_punct = no_punct + char\r\n lst.extend(no_punct.split())\r\n \r\n \r\nfor i in lst:\r\n if i not in ans:\r\n ans.append(i)\r\nans.sort()\r\nprint(len(ans))\r\nfor j in ans:\r\n print(j)\r\n\r\n"]
{"inputs": [["2", "This is a sample piece of text to illustrate this", "problem."]], "outputs": [["10", "a", "illustrate", "is", "of", "piece", "problem", "sample", "text", "this", "to"]]}
INTERVIEW
PYTHON3
CODECHEF
2,053
1c17d857cc24ff7bab061aff07852f8d
UNKNOWN
Kajaria has an empty bag and 2 types of tiles - tiles of type $1$ have the number $X$ written and those of type $2$ have the number $Y$ written on them. He has an infinite supply of both type of tiles. In one move, Kajaria adds exactly $1$ tile to the bag. He adds a tile of type $1$ with probability $p$ and a tile of type $2$ with probability $(1 - p)$. If $2$ tiles in the bag have the same number written on them (say $Z$), they are merged into a single tile of twice that number ($2Z$). Find the expected number of moves to reach the first tile with number $S$ written on it. Notes on merging: - Consider that the bag contains tiles $(5, 10, 20, 40)$ and if the new tile added is $5$, then it would merge with the existing $5$ and the bag would now contain $(10, 10, 20, 40)$. The tiles $10$ (already present) and $10$ (newly formed) would then merge in the same move to form $(20, 20, 40)$, and that will form $(40, 40)$, which will form $(80)$. Kajaria guarantees that: - $X$ and $Y$ are not divisible by each other. - A tile with number $S$ can be formed. -----Input----- - First line contains a single integer $T$ - the total no. of testcases - Each testcase is described by $2$ lines: - $X, Y, S$ - $3$ space-separated natural numbers - $u, v$ - $2$ space-separated natural numbers describing the probability $p$ The value of $p$ is provided as a fraction in its lowest form $u/v$ ($u$ and $v$ are co-prime) -----Output----- - For each testcase, if the expected number of moves can be expressed as a fraction $p/q$ in its lowest form, print $(p * q^{-1})$ modulo $10^9 + 7$, where $q^{-1}$ denotes the modular inverse of $q$ wrt $10^9 + 7$. -----Constraints----- - $1 \leq T \leq 10^5$ - $2 \leq X, Y \leq 5 * 10^{17}$ - $1 \leq S \leq 10^{18}$ - $1 \leq u < v \leq 10^{9}$ -----Sample Input----- 1 5 3 96 1 3 -----Sample Output----- 48
["# cook your dish here\nt=int(input())\nMOD=1000000007\ndef mod(n, m=MOD):\n n%=m\n while n<0: n+=m\n return n\n\ndef power(n, p):\n res=1\n while p:\n if p%2: res=mod(res*n)\n p//=2\n n=mod(n*n)\n return res\n\nwhile t:\n ma=input().split()\n x=int(ma[0])\n y=int(ma[1])\n s=int(ma[2])\n ma=input().split()\n u=int(ma[0])\n v=int(ma[1])\n if s%x==0 and ((s // x) & ((s // x) - 1) == 0):\n inv=power(u, MOD-2)\n print(mod(mod(mod(s//x)*v)*inv))\n else:\n inv=power(v-u, MOD-2)\n print(mod(mod(mod(s//y)*v)*inv))\n t-=1\n", "M = 10**9+7\n\nfor _ in range(int(input())):\n x,y,s = [int(s) for s in input().split()]\n u,v = [int(s) for s in input().split()]\n if (s%x==0) and (((s//x)&(s//x -1))==0):\n w = s//x\n else:\n w = s//y\n u = v-u\n ans = ((((w%M) * (v%M))%M)*pow(u,M-2,M))%M\n print(ans)", "M = 10**9+7\n\nfor _ in range(int(input())):\n x,y,s = [int(s) for s in input().split()]\n u,v = [int(s) for s in input().split()]\n if (s%x==0) and (((s//x)&(s//x -1))==0):\n w = s//x\n else:\n w = s//y\n u = v-u\n ans = ((((w%M) * (v%M))%M)*pow(u,M-2,M))%M\n print(ans)", "# cook your dish here\nt=int(input())\nMOD=1000000007\ndef mod(n, m=MOD):\n n%=m\n while n<0: n+=m\n return n\n\ndef power(n, p):\n res=1\n while p:\n if p%2: res=mod(res*n)\n p//=2\n n=mod(n*n)\n return res\n\nwhile t:\n ma=input().split()\n x=int(ma[0])\n y=int(ma[1])\n s=int(ma[2])\n ma=input().split()\n u=int(ma[0])\n v=int(ma[1])\n if s%x==0 and ((s // x) & ((s // x) - 1) == 0):\n inv=power(u, MOD-2)\n print(mod(mod(mod(s//x)*v)*inv))\n else:\n inv=power(v-u, MOD-2)\n print(mod(mod(mod(s//y)*v)*inv))\n t-=1\n"]
{"inputs": [["1", "5 3 96", "1 3"]], "outputs": [["48"]]}
INTERVIEW
PYTHON3
CODECHEF
1,616
7d0ff1a579c4b9856afb205b8ff91a62
UNKNOWN
There are n cards of different colours placed in a line, each of them can be either red, green or blue cards. Count the minimum number of cards to withdraw from the line so that no two adjacent cards have the same colour. -----Input----- - The first line of each input contains an integer n— the total number of cards. - The next line of the input contains a string s, which represents the colours of the cards. We'll consider the cards in a line numbered from 1 to n from left to right. Then the $i^t$$^h$ alphabet equals "G", if the $i^t$$^h$ card is green, "R" if the card is red, and "B", if it's blue. -----Output----- - Print a single integer — the answer to the problem. -----Constraints----- - $1 \leq n \leq 50$ -----Sample Input 1:----- 5 RGGBG -----Sample Input 2:----- 5 RRRRR -----Sample Input 3:----- 2 BB -----Sample Output 1:----- 1 -----Sample Output 2:----- 4 -----Sample Output 3:----- 1
["# cook your dish here\nn = int(input())\ns = [i for i in input()]\ncount = 0\nfor i in range(1,n):\n if s[i] == s[i-1]:\n count += 1\n else:\n continue\nprint(count)\n", "# cook your dish here\n\nn=int(input())\nstring1=input()\ncount=0\nif(n==1):\n print(0)\nelse:\n for i in range(len(string1)-1):\n if(string1[i+1]==string1[i]):\n count+=1\n \n print(count)", "def chef(n,a):\r\n c=0\r\n for i in range(len(a)-1):\r\n if a[i]==a[i+1]:\r\n c+=1\r\n \r\n return c\r\nc=int(input())\r\nb=input()\r\nprint(chef(c,b))\r\n", "\r\n#q2\r\nn=int(input())\r\ndf=str(input())\r\ndf=list(df)\r\nans=0\r\nl=len(df)\r\ni=1\r\nwhile(l>1):\r\n if(i<len(df)-1):\r\n if(df[i-1]==df[i]):\r\n df.pop(i)\r\n l-=1\r\n #print(df)\r\n ans+=1\r\n else:\r\n i+=1\r\n else:\r\n break\r\nl=len(df)\r\nif(l>1):\r\n if(df[l-1]==df[l-2]):\r\n ans+=1\r\nprint(ans)\r\n", "n=int(input())\r\nl=list(input())\r\nj=0\r\ncount=0\r\nwhile(j<len(l)-1):\r\n\tif(l[j]==l[j+1]):\r\n\t\tj-=1\r\n\t\tcount+=1\r\n\t\tl.pop(j+1)\r\n\tj+=1\r\nprint(count)", "# cook your dish here\nn=int(input())\ns=input()\ns=list(s)\nans=0\nfor i in range(1,len(s)):\n if s[i]==s[i-1]:\n ans+=1\n\nprint(ans)\n \n", "# cook your dish here\nn=int(input())\ns=input()\ns=list(s)\n# print(s)\nans=[]\nans.append(s[0])\nfor i in range(1,len(s)):\n if s[i]!=ans[-1]:\n ans.append(s[i])\n# print(ans)\nprint(len(s)-len(ans))\n \n", "# cook your dish here\nn = int(input())\ns = input()\ncount=0\nfor i in range(n):\n\tif(i+1 == n):\n\t\tbreak\n\tif s[i] == s[i+1]:\n\t\tcount+=1\nprint(count)", "n=int(input())\r\ns=input()\r\ncount=0\r\nl=list(s)\r\nfor i in range(0,n-1):\r\n if l[i]==l[i+1]:\r\n count=count+1\r\nprint(count)", "n=int(input())\ns=input()\nl=list(s)\ni=ans=j=0\n\nwhile i<n-1:\n if s[i]==s[i+1]:\n ans+=1\n i+=1\n\nprint(min(ans,n-1))", "n=input()\nx=input()\nc=0 \nfor i in range(1,len(x)):\n if x[i]==x[i-1]:\n c+=1\nprint(c) ", "# cook your dish here\nn = int(input())\nst = input()\ncnt=0\nfor i in range(len(st)-1):\n if st[i] == st[i+1]:\n cnt +=1\nprint(cnt)", "# cook your dish here\nn=int(input())\ns=input()\nans=0\nfor i in range(1,len(s)):\n if s[i]==s[i-1]:\n ans+=1\nprint(ans)", "test=int(input())\n#def solve():\n \n'''hile test:\n solve()\n test-=1 '''\ncount=0\ns=input()\nfor i in range(test-1):\n if s[i+1]==s[i]:\n count+=1 \nprint(count)\n", "# cook your dish here\nn=int(input())\nar=input()\ncount=0\nfor x in range(1,n):\n if ar[x]==ar[x-1]:\n count+=1\nprint(count)", "n = int(input())\r\ns = input()\r\ncount = 0\r\nfor j in range(n-1):\r\n if s[j] == s[j+1]:\r\n count += 1\r\nprint(count)", "# cook your dish here\nn=int(input())\ns=input()\nl=[]\nfor i in s:\n l.append(i)\nans=0\nfor i in range(1,len(s)):\n if l[i-1]==l[i]:\n ans+=1\nprint(ans)", "n=int(input())\ns=input()\nb=0\ni=0\nj=0\nwhile i<n-1:\n j=i+1\n while j<n:\n if s[i]==s[j]:\n #print(\"case 1 j\",j)\n b+=1\n j+=1\n i+=1\n else:\n #print(\"case 2 j :\",j)\n i=j\n break\n \nprint(b)#\n", "n = int(input())\ns = input().upper()\ncount = 0\nfor i in range(n-1):\n if(s[i] == s[i+1]):\n count += 1\nprint(count)", "n = int(input())\r\ns = input()\r\ncount = 0\r\nfor i in range(n-1):\r\n if s[i] == s[i+1]:\r\n count += 1\r\nprint(count)", "# cook your dish here\n\nn=int(input())\nst=str(input())\ncount=0\nwhile(len(st)>0):\n h=0\n if \"RR\" in st:\n i=st.index(\"RR\")\n st=st[:i] +st[i+1:]\n count+=1\n h=1\n if \"GG\" in st:\n i=st.index(\"GG\")\n st=st[:i] +st[i+1:]\n h=1\n count+=1\n if \"BB\" in st:\n i=st.index(\"BB\")\n st=st[:i] +st[i+1:]\n h=1\n count+=1\n if h==0:\n break\nprint(count)", "# cook your dish here\nn=int(input())\ns=list(str(input()))\ni=0\nans=0\nwhile i<len(s)-1:\n if s[i]==s[i+1]:\n del s[i+1]\n ans+=1\n else:\n i+=1\nprint(ans)", "n=int(input())\r\nc=0\r\nl=str(input())\r\nfor i in range(n-1):\r\n if l[i] == l[i+1]:\r\n c+=1\r\nprint(c)\r\n", "n=int(input())\na=input()\ne=a[0]\nf=0\nfor i in range(1,n):\n if a[i]==e:\n f+=1\n else:\n e=a[i]\nprint(f)", "# cook your dish here\n# cook your dish here\nl=int(input())\ns=input()\ni=0\nc=0\ns=list(s)\nwhile i<len(s)-1:\n if s[i]==s[i+1]:\n c+=1\n s.remove(s[i])\n i-=1\n i+=1 \nprint(c)"]
{"inputs": [["5", "RGGBG", "Sample Input 2:", "5", "RRRRR", "Sample Input 3:", "2", "BB"]], "outputs": [["1", "Sample Output 2:", "4", "Sample Output 3:", "1"]]}
INTERVIEW
PYTHON3
CODECHEF
4,764
baf651d2c6ae9dc9dff0929f8c8b642d
UNKNOWN
Devu loves to play with his dear mouse Jerry. One day they play a game on 2 dimensional grid of dimensions n * n (n ≥ 2). Jerry is currently at coordinates (sx, sy) and wants to move to location (ex, ey) where cheese is placed by Devu. Also Devu is very cunning and has placed a bomb at location (bx, by). All these three locations are distinct. In a single move, Jerry can go either up, down, left or right in the grid such that it never goes out of the grid. Also, it has to avoid the bomb. Find out minimum number of moves Jerry needs. It is guaranteed that it is always possible to do so. -----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 seven space separated integers n, sx, sy , ex, ey, bx, by. -----Output----- - For each test case, output a single line containing an integer corresponding to minimum number of moves Jerry needs. -----Constraints----- - 1 ≤ T ≤ 1000 - 2 ≤ n ≤ 20 - 1 ≤ sx, sy , ex, ey, bx, by ≤ n - No two or more poitns in the three points are same. -----Example----- Input: 2 2 1 1 2 2 1 2 3 1 1 1 3 1 2 Output: 2 4 -----Explanation----- Example case 1. ... Jerry will move directly (1, 1) to (2, 1) and then to (2, 2) in total 2 moves. Example case 2. ...
["import sys\n\ndef _r(*conv) :\n r = [conv[i](x) for i, x in enumerate(input().strip().split(' '))]\n return r[0] if len(r) == 1 else r\n\ndef _ra(conv) :\n return list(map(conv, input().strip().split(' ')))\n\ndef _rl() :\n return list(input().strip())\n\ndef _rs() :\n return input().strip()\n\ndef _a(k, *v) :\n return all(x == k for x in v)\n\ndef _i(conv) :\n for line in sys.stdin :\n yield conv(line)\n##################################################################\n\n\nfor _ in range(_r(int)) :\n n, sx, sy, ex, ey, bx, by = _ra(int)\n\n if sx != ex and sy != ey : \n print(abs(sx - ex) + abs(sy - ey))\n else : \n if sx == ex : \n if sx == bx : \n if (by > sy and by < ey) or (by < sy and by > ey) :\n print(abs(sx - ex) + abs(sy - ey) + 2)\n else :\n print(abs(sx - ex) + abs(sy - ey))\n else : \n print(abs(sx - ex) + abs(sy - ey))\n else :\n if sy == by : \n if (bx > sx and bx < ex) or (bx < sx and bx > ex) :\n print(abs(sx - ex) + abs(sy - ey) + 2)\n else : \n print(abs(sx - ex) + abs(sy - ey))\n else : \n print(abs(sx - ex) + abs(sy - ey))\n\n\n", "t=eval(input())\nfor z in range(t):\n tot=0\n n,sx,sy,ex,ey,bx,by=list(map(int,input().strip().split(\" \")))\n if(sx==ex or sy==ey):\n if(sx==ex):\n if(sx==bx and (by>=min(sy,ey) and by<=max(sy,ey))):\n tot+=2\n elif(sy==ey):\n if(sy==by and (bx>=min(sx,ex) and bx<=max(sx,ex))):\n tot+=2\n tot+=abs(sx-ex)+abs(sy-ey)\n print(tot)\n", "for cas in range(eval(input())):\n n, sx, sy, ex, ey, bx, by = list(map(int, input().strip().split()))\n print(abs(sx - ex) + abs(sy - ey) + 2 * ((sx == ex or sy == ey)\n and min(sx, ex) <= bx <= max(sx, ex)\n and min(sy, ey) <= by <= max(sy, ey)\n ))", "for t in range(eval(input())):\n n, sx, sy, ex, ey, bx, by = list(map(int, input().strip().split()))\n bomb = ((sx==ex or sy==ey)\n and min(sx,ex) <= bx <= max(sx, ex)\n and min(sy,ey) <= by <= max(sy, ey))\n print(abs(sx-ex) + abs (sy-ey) + 2 * bomb)", "# cook your code here\nT = int(input())\nfor i in range(T):\n (n,sx,sy,ex,ey,bx,by) = list(map(int,input().split()))\n if sx!=ex and sy!=ey:\n a = abs(sx-ex)+abs(sy-ey)\n print(a)\n else:\n if sx==ex:\n if ex==bx and (by-sy)*(ey-by)>0:\n print(abs(sy-ey)+2)\n else:\n print(abs(sy-ey))\n else:\n if ey==by and (bx-sx)*(ex-bx)>0:\n print(abs(sx-ex)+2)\n else:\n print(abs(sx-ex))\n", "for cas in range(eval(input())):\n n, sx, sy, ex, ey, bx, by = list(map(int, input().strip().split()))\n print(abs(sx - ex) + abs(sy - ey) + 2 * ((sx == ex or sy == ey)\n and min(sx, ex) <= bx <= max(sx, ex)\n and min(sy, ey) <= by <= max(sy, ey)\n ))", "for cas in range(eval(input())):\n n, sx, sy, ex, ey, bx, by = list(map(int, input().strip().split()))\n print(abs(sx - ex) + abs(sy - ey) + 2 * ((sx == ex or sy == ey)\n and min(sx, ex) <= bx <= max(sx, ex)\n and min(sy, ey) <= by <= max(sy, ey)\n ))", "import sys\n\ndef main():\n t=int(sys.stdin.readline())\n for _ in range(t):\n n,sx,sy,dx,dy,bx,by=list(map(int,sys.stdin.readline().strip().split()))\n if (sx==bx==dx) and (min(sy,dy)<by) and (by<max(sy,dy)): \n print(abs(dx-sx)+abs(dy-sy)+2)\n elif (sy==by==dy) and(min(sx,dx)<bx) and (bx<max(sx,dx)):\n print(abs(dx-sx)+abs(dy-sy)+2)\n else:\n print(abs(dx-sx)+abs(dy-sy))\nmain()\n", "for cas in range(eval(input())):\n n, sx, sy, ex, ey, bx, by = list(map(int, input().strip().split()))\n print(abs(sx - ex) + abs(sy - ey) + 2 * ((sx == ex or sy == ey)\n and min(sx, ex) <= bx <= max(sx, ex)\n and min(sy, ey) <= by <= max(sy, ey)\n ))", "for _ in range(eval(input())):\n a=list(map(int,input().split()))\n s=[a[1],a[2]]\n e=[a[3],a[4]]\n b=[a[5],a[6]]\n c=abs(e[1]-s[1])+abs(e[0]-s[0])\n if b[0]==e[0] and b[1]<e[1]:\n c+=2\n print(c)\n else:\n print(c)\n \n"]
{"inputs": [["2", "2 1 1 2 2 1 2", "3 1 1 1 3 1 2"]], "outputs": [["2", "4"]]}
INTERVIEW
PYTHON3
CODECHEF
3,783
5e98a225f72076d9984d819fc9eb9dcb
UNKNOWN
-----Problem Statement----- You all must have played the game candy crush. So here is a bomb which works much the fruit bomb in candy crush. A designer, Anton, designed a very powerful bomb. The bomb, when placed on a location $(x, y)$ in a $R \times C$ grid, wipes out the row $x$ and column $y$ completely. You are given a $R\times C$ grid with $N$ targets. You have only one bomb. Your aim is to maximize the damage and hence destroy most number of targets. Given the location of targets on the grid, find out the number of targets that can destroyed. The grid system uses index starting with $0$. -----Input----- - First line contains three space separated integers, $R$, $C$ and $N$. Then, $N$ lines follow. - Each line contains space separated integers $r$ and $c$ mentioning the location of the target. -----Output----- A single integer giving the number of targets that can be destroyed. -----Constraints----- - $1 \leq R, C \leq 3 \times 10^5$ - $1 \leq N \leq min(R \times C, 3 \times 10^5)$ - $0 \leq r < R$ - $0 \leq c < C$ - Any input pair $(r, c)$ is not repeated. -----Subtasks----- The total marks will be divided into: - 20% : $R, C \leq 10^3$ - 80% : Original Constraints -----Sample Input----- 2 3 3 1 1 0 0 0 2 -----Sample Output----- 3 -----EXPLANATION----- It is possible to destroy all the targets if we place the bomb at $(0, 1)$. Hence, total number of targets destroyed is $3$, which is our answer.
["r,c,n = map(int , input().split());coordinates = [];coordinates_1,coordinates_2 = {},{}\r\nfor _ in range(n):\r\n\tx,y = map(int , input().split())\r\n\tcoordinates.append([x,y])\r\nfor i in coordinates:\r\n if(i[0] in coordinates_1): coordinates_1[i[0]] += 1\r\n else: coordinates_1[i[0]] = 1\r\n if(i[1] in coordinates_2): coordinates_2[i[1]] += 1\r\n else: coordinates_2[i[1]] = 1\r\nprint(max(coordinates_1.values()) + max(coordinates_2.values()))", "try:\n r,c,n=list(map(int,input().split()))\n grid=[[0 for j in range(c)]for i in range(r)]\n for i in range(n):\n a,b=list(map(int,input().split()))\n grid[a][b]=1\n sumcol=[sum(x) for x in zip(*grid)]\n sumrow=[]\n for i in grid:\n sumrow.append(sum(i))\n\n \n \n \n #targets=[]\n #for i in range(r):\n # for j in range(c):\n # targets.append(sumrow[i] + sumcol[j] - 2*grid[i][j])\n print(max(sumrow)+max(sumcol))\nexcept EOFError:\n pass\n", "from collections import defaultdict\nr,c,n = (int(i) for i in input().split())\ndr=defaultdict(int)\ndc = defaultdict(int)\n\nfor i in range(n):\n\tx,y = (int(i) for i in input().split())\n\tdr[x]+=1\n\tdc[y]+=1\n\nmr = max(dr.values())\nmc = max(dc.values())\nif 1 not in [r,c]:\n\tprint(mr+mc)\nelse:\n\tprint(max(mr,mc))", "r,c,n=map(int,input().split())\r\nar=[]\r\nfor i in range(n):\r\n ar.append(list(map(int,input().split())))\r\n\r\nd1={}\r\n\r\n\r\nfor i in ar:\r\n try:\r\n d1[i[0]]+=1\r\n except:\r\n d1[i[0]]=1\r\n\r\nmaxi=-1\r\n\r\nfor i in d1:\r\n if d1[i]>maxi:\r\n maxi=d1[i]\r\n res1=i\r\n\r\nd2={}\r\n\r\nfor i in ar:\r\n if i[0]!=res1:\r\n try:\r\n d2[i[1]]+=1\r\n except:\r\n d2[i[1]]=1\r\n\r\nmaxi=-1\r\n\r\nfor i in d2:\r\n if d2[i]>maxi:\r\n maxi=d2[i]\r\n res2=i\r\n\r\nans1=d1[res1]+d2[res2]\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\nd1={}\r\n\r\nfor i in ar:\r\n try:\r\n d1[i[1]]+=1\r\n except:\r\n d1[i[1]]=1\r\n\r\nmaxi=-1\r\n\r\nfor i in d1:\r\n if d1[i]>maxi:\r\n maxi=d1[i]\r\n res1=i\r\n\r\nd2={}\r\n\r\nfor i in ar:\r\n if i[1]!=res1:\r\n try:\r\n d2[i[0]]+=1\r\n except:\r\n d2[i[0]]=1\r\n\r\nmaxi=-1\r\n\r\nfor i in d2:\r\n if d2[i]>maxi:\r\n maxi=d2[i]\r\n res2=i\r\n\r\nans2=d1[res1]+d2[res2]\r\n\r\nprint(max(ans1,ans2))", "import sys\r\n \r\nsys.setrecursionlimit(500005)\r\nstdin = sys.stdin\r\n \r\nni = lambda: int(ns())\r\nna = lambda: list(map(int, stdin.readline().split()))\r\nns = lambda: stdin.readline().strip()\r\n \r\nh, w, m = na()\r\nrs = [0] * h\r\ncs = [0] * w\r\n \r\nse = set()\r\nfor i in range(m):\r\n r, c = na()\r\n rs[r-1] += 1\r\n cs[c-1] += 1\r\n se.add((r-1)*w+c-1)\r\n \r\nrmax = max(rs)\r\ncmax = max(cs)\r\n \r\nremax = rs.count(rmax)\r\ncemax = cs.count(cmax)\r\nif remax * cemax > m:\r\n print(rmax + cmax)\r\n return\r\n \r\nrmaxs = [i for i, _ in enumerate(rs) if _ == rmax]\r\ncmaxs = [i for i, _ in enumerate(cs) if _ == cmax]\r\nfor r in rmaxs:\r\n for c in cmaxs:\r\n if r*w+c not in se:\r\n print(rmax + cmax)\r\n return\r\nprint(rmax + cmax - 1)\r\n", "r,c,n=list(map(int,input().split()))\na=set()\n\nc2=[0 for i in range(r)]\nd2=[0 for j in range(c)]\n\nfor i in range(n):\n c1,d1=list(map(int,input().split()))\n a.add((c1,d1))\n c2[c1]+=1 \n d2[d1]+=1 \n\n\nmr=max(c2)\nmc=max(d2)\n\np1=[]\np2=[]\n\nfor i in range(r):\n if c2[i]==mr:\n p1.append(i)\n\nfor j in range(c):\n if d2[j]==mc:\n p2.append(j)\n \nans=mr+mc \n\nfor i in p1:\n for j in p2:\n if (i,j) in a:\n continue\n print(ans)\n return\nans -= 1\nprint(ans)\n", "r, c, n = map(int, input().split())\r\nX = [0]*(r+1)\r\nY = [0]*(c+1)\r\nfor i in range(n):\r\n x,y = map(int, input().split())\r\n X[x] += 1\r\n Y[y] += 1\r\nprint(max(X)+max(Y))", "# cook your dish here\nr,c,n = map(int,input().split())\nx={}\ny={}\nxy={}\nfor i in range(n):\n a = [int(i) for i in input().split()]\n if x.get(a[0])==None:\n x[a[0]]=1\n else:\n x[a[0]]+=1\n if y.get(a[1])==None:\n y[a[1]]=1\n else:\n y[a[1]]+=1\n xy[tuple(a)]=1\nxmax = max(x, key=x.get)\nymax = max(y, key=y.get)\nar = []\nar.append(xmax)\nar.append(ymax)\ncount = x[xmax]+y[ymax]\nif xy.get(tuple(ar))!=None:\n count-=1\nprint(count)", "#\n\n#for _ in range(int(input())):\nn,m,x = list(map(int,input().split()))\narr = [[0 for i in range(m)] for j in range(n)]\ndpr = [0]*n \ndpc = [0]*m\nfor i in range(x):\n a,b=list(map(int,input().split()))\n arr[a][b]=1\n dpr[a]+=1 \n dpc[b]+=1\n#print(dpr,dpc)\nmax=-1\nfor i in range(n):\n for j in range(m):\n sum=dpr[i]+dpc[j]\n #print(i,j,sum)\n if arr[i][j]==1:\n sum-=1\n if sum>max:\n max=sum\n if max==x:\n break\nprint(max)\n\n \n", "#\n\n#for _ in range(int(input())):\nn,m,x = list(map(int,input().split()))\narr = [[0 for i in range(m)] for j in range(n)]\ndpr = [0]*n \ndpc = [0]*m\nfor i in range(x):\n a,b=list(map(int,input().split()))\n arr[a][b]=1\n dpr[a]+=1 \n dpc[b]+=1\n#print(dpr,dpc)\nmax=-1\nfor i in range(n):\n for j in range(m):\n sum=dpr[i]+dpc[j]\n #print(i,j,sum)\n if arr[i][j]==1:\n sum-=1\n if sum>max:\n max=sum\nprint(max)\n\n \n", "r,c,n=map(int,input().split())\na=[[0 for i in range(c)] for j in range(r)]\n\nfor i in range(n):\n c1,d1=map(int,input().split())\n a[c1][d1]=1 \n \n\na2=[[0 for i in range(r)] for j in range(c)]\n\n#print(a2)\n\nfor i in range(c):\n for j in range(r):\n a2[i][j]=a[j][i]\n \n \n#print(a,a2)\nc2=[0 for i in range(r)]\nd2=[0 for j in range(c)]\n\nfor i in range(r):\n c2[i]=sum(a[i])\n \nfor i in range(c):\n d2[i]=sum(a2[i])\n#print(c,d)\n \nans=0\n\nfor i in range(r):\n for j in range(c):\n if a[i][j]==1:\n ans=max(ans,c2[i]+d2[j]-1)\n else:\n ans=max(ans,c2[i]+d2[j])\n \nprint(ans)", "# cook your dish here\ndef f(lst1,lst2):\n dict1={}.fromkeys(lst1,0)\n for key in lst1:\n dict1[key]+=1\n s=max(dict1.values())\n for i in dict1:\n if(dict1[i]==s):\n key=i\n break\n lst3=[] \n for i,j in zip(lst1,lst2):\n if(i!=key):\n lst3.append(j)\n dict2={}.fromkeys(lst3,0)\n for key in lst3:\n dict2[key]+=1\n s1=max(dict2.values())\n return s+s1\nr,c,n=list(map(int,input().split()))\nlst1=[]\nlst2=[]\nfor i in range(n):\n r,c=list(map(int,input().split()))\n lst1.append(r)\n lst2.append(c)\nprint(max(f(lst1,lst2),f(lst2,lst1)))\n \n", "\r\nr,c,n=list(map(int,input().split()))\r\nro=[0]*(r+1)\r\nco=[0]*(c+1)\r\nfor i in range(n):\r\n a,b=list(map(int,input().split()))\r\n ro[a]+=1\r\n co[b]+=1\r\nma=0\r\nma+=max(ro)\r\nma+=max(co)\r\nprint(ma)\r\n\r\n\r\n\r\n\r\n\r\n\r\n", "\r\nr,c,n=list(map(int,input().split()))\r\nro=[0]*(r+1)\r\nco=[0]*(c+1)\r\nfor i in range(n):\r\n a,b=list(map(int,input().split()))\r\n ro[a]+=1\r\n co[b]+=1\r\nma=0\r\nma+=max(ro)\r\nma+=max(co)\r\nprint(ma)\r\n\r\n\r\n\r\n\r\n\r\n\r\n", "r, c, n = map(int, input().split())\nX = [0]*(r+1)\nY = [0]*(c+1)\nfor i in range(n):\n x,y = map(int, input().split())\n X[x] += 1\n Y[y] += 1\nprint(max(X)+max(Y))", "r,c,n=map(int,input().split())\nar=[]\nfor i in range(n):\n ar.append(list(map(int,input().split())))\n\nd1={}\n\n\nfor i in ar:\n try:\n d1[i[0]]+=1\n except:\n d1[i[0]]=1\n\nmaxi=-1\n\nfor i in d1:\n if d1[i]>maxi:\n maxi=d1[i]\n res1=i\n\nd2={}\n\nfor i in ar:\n if i[0]!=res1:\n try:\n d2[i[1]]+=1\n except:\n d2[i[1]]=1\n\nmaxi=-1\n\nfor i in d2:\n if d2[i]>maxi:\n maxi=d2[i]\n res2=i\n\nans1=d1[res1]+d2[res2]\n\n\n\n\n\n\n\n\n\nd1={}\n\nfor i in ar:\n try:\n d1[i[1]]+=1\n except:\n d1[i[1]]=1\n\nmaxi=-1\n\nfor i in d1:\n if d1[i]>maxi:\n maxi=d1[i]\n res1=i\n\nd2={}\n\nfor i in ar:\n if i[1]!=res1:\n try:\n d2[i[0]]+=1\n except:\n d2[i[0]]=1\n\nmaxi=-1\n\nfor i in d2:\n if d2[i]>maxi:\n maxi=d2[i]\n res2=i\n\nans2=d1[res1]+d2[res2]\n\nprint(max(ans1,ans2))", "from sys import stdin, stdout\nr, c, n = map(int, stdin.readline().split())\nfx = {}\nfy = {}\ns = set()\nfor _ in range(n):\n x, y = stdin.readline().split()\n fx[x] = fx.get(x, 0)+1\n fy[y] = fy.get(y, 0)+1\n s.add((x,y))\nxl, xn = [], max(fx.values())\nfor x in fx:\n if fx[x] == xn: xl.append(x)\nyl, yn = [], max(fy.values())\nfor y in fy:\n if fy[y] == yn: yl.append(y)\ncount = xn+yn-1\nbroken = False\nfor x in xl:\n for y in yl:\n if (x,y) not in s:\n broken = True\n break\n if broken: break\nstdout.write(str(count+broken))", "import sys\nimport math\nfrom collections import defaultdict,Counter\n\ninput=sys.stdin.readline\ndef print(x):\n sys.stdout.write(str(x)+\"\\n\")\n\n# sys.stdout=open(\"CP1/output.txt\",'w')\n# sys.stdin=open(\"CP1/input.txt\",'r')\n\n# mod=pow(10,9)+7\nr,c,n=map(int,input().split())\nrow=[0]*r\ncol=[0]*c\ns=set()\nfor i in range(n):\n\tx,y=map(int,input().split())\n\trow[x]+=1\n\tcol[y]+=1\n\ts.add((x,y))\nans=0\nfor i in range(r):\n\tfor j in range(c):\n\t\tcur=row[i]+col[j]\n\t\tif (i,j) in s:\n\t\t\tcur-=1\n\t\tans=max(cur,ans)\nprint(ans)\n# mr=max(row)\n# mc=max(col)\n# ans=mr+mc-1\n# r1=\n# for i in range(r):\n# \tif row[i]==mr\n# ind=(0,0)\n# ma=0\n# for i in range(r):\n# \tif row[i]>ma\n# print(ans)\n", "from sys import stdin, stdout\nr, c, n = map(int, stdin.readline().split())\nfx = {}\nfy = {}\ns = set()\nfor _ in range(n):\n x, y = stdin.readline().split()\n fx[x] = fx.get(x, 0)+1\n fy[y] = fy.get(y, 0)+1\n s.add((x,y))\nxl, xn = [], max(fx.values())\nfor x in fx:\n if fx[x] == xn: xl.append(x)\nyl, yn = [], max(fy.values())\nfor y in fy:\n if fy[y] == yn: yl.append(y)\ncount = xn+yn-1\nbroken = False\nfor x in xl:\n for y in yl:\n if (x,y) not in s:\n broken = True\n break\n if broken: break\nstdout.write(str(count+broken))", "r,c,n=list(map(int,input().split()))\nro={}\ncol={}\nfor i in range(n):\n p,q=list(map(int,input().split()))\n try:\n ro[p]+=1\n except KeyError:\n ro[p]=1\n try:\n col[q]+=1\n except KeyError:\n col[q]=1\nmr,mc=-1,-1\nv1,v2=-1,-1\nfor i in list(ro.keys()):\n if(ro[i]>v1):\n v1=ro[i]\n mr=i\nfor i in list(col.keys()):\n if(col[i]>v2):\n v2=col[i]\n mc=i\n#print(col,ro)\nprint(v1+v2)\n", "r,c,n=map(int,input().split())\na=[[0 for i in range(c)] for j in range(r)]\n\nfor i in range(n):\n c1,d1=map(int,input().split())\n a[c1][d1]=1 \n \n\na2=[[0 for i in range(r)] for j in range(c)]\n\n#print(a2)\n\nfor i in range(c):\n for j in range(r):\n a2[i][j]=a[j][i]\n \n \n#print(a,a2)\nc2=[0 for i in range(r)]\nd2=[0 for j in range(c)]\n\nfor i in range(r):\n c2[i]=sum(a[i])\n \nfor i in range(c):\n d2[i]=sum(a2[i])\n#print(c,d)\n \nans=0\n\nfor i in range(r):\n for j in range(c):\n if a[i][j]==1:\n ans=max(ans,c2[i]+d2[j]-1)\n else:\n ans=max(ans,c2[i]+d2[j])\n \nprint(ans)", "r,c,n=map(int,input().split())\na=[[0 for i in range(c)] for j in range(r)]\n\nfor i in range(n):\n c1,d1=map(int,input().split())\n a[c1][d1]=1 \n \n\na2=[[0 for i in range(r)] for j in range(c)]\n\n#print(a2)\n\nfor i in range(c):\n for j in range(r):\n a2[i][j]=a[j][i]\n \n \n#print(a,a2)\nc2=[0 for i in range(r)]\nd2=[0 for j in range(c)]\n\nfor i in range(r):\n c2[i]=sum(a[i])\n \nfor i in range(c):\n d2[i]=sum(a2[i])\n#print(c,d)\n \nans=0\n\nfor i in range(r):\n for j in range(c):\n ans=max(ans,c2[i]+d2[j])\n \nprint(ans)", "\nr,c,n=list(map(int,input().split()))\nro=[0]*n\nco=[0]*n\nfor i in range(n):\n a,b=list(map(int,input().split()))\n ro[a]+=1\n co[b]+=1\nma=0\nma+=max(ro)\nma+=max(co)\nprint(ma)\n\n\n\n\n\n\n"]
{"inputs": [["2 3 3", "1 1", "0 0", "0 2"]], "outputs": [["3"]]}
INTERVIEW
PYTHON3
CODECHEF
12,367
23981a1425f1aa28ea48e0722fb50cb0
UNKNOWN
Chef is now a corporate person. He has to attend office regularly. But chef does not want to go to office, rather he wants to stay home and discover different recipes and cook them. In the office where chef works, has two guards who count how many times a person enters into the office building. Though the duty of a guard is 24 hour in a day, but sometimes they fall asleep during their duty and could not track the entry of a person in the office building. But one better thing is that they never fall asleep at the same time. At least one of them remains awake and counts who enters into the office. Now boss of Chef wants to calculate how many times Chef has entered into the building. He asked to the guard and they give him two integers A and B, count of first guard and second guard respectively. Help the boss to count the minimum and maximum number of times Chef could have entered into the office building. -----Input----- The first line of the input contains an integer T denoting the number of test cases. The description of the T test cases follows. Each test case consists of a line containing two space separated integers A and B. -----Output----- For each test case, output a single line containing two space separated integers, the minimum and maximum number of times Chef could have entered into the office building. -----Constraints----- - 1 ≤ T ≤ 100 - 0 ≤ A, B ≤ 1000000 -----Example----- Input: 1 19 17 Output: 19 36
["# cook your dish here\nfor _ in range(int(input())):\n x, y= map(int, input().split())\n print(max(x,y), x+y)", "n=int(input())\nfor i in range(n):\n g1,g2=map(int,input().split())\n s=0\n if g1<g2:\n s=g2\n else:\n s=g1\n print(s,g1+g2)", "t=int(input())\nfor x in range(t):\n a,b=map(int,input().split())\n if a>b:\n print(a,a+b)\n else:\n print(b,a+b)", "t=int(input())\nfor x in range(t):\n a,b=map(int,input().split())\n if a>b:\n print(a,a+b)\n else:\n print(b,a+b)", "# cook your dish here\nn = int(input())\nwhile n>0:\n a,b = map(int,input().strip().split())\n print(max(a,b),a+b)\n n = n-1", "for _ in range (int(input())):\n a,b = map(int,input().split())\n print(max(a,b),a+b)", "# cook your dish here\nt=int(input())\nfor i in range(t):\n a,b=map(int,input().split())\n if(a>b):\n print(a,a+b)\n else:\n print(b,a+b)", "# cook your dish here\ntry:\n t=int(input())\n for i in range(0,t):\n a,b=map(int,input().split())\n if(a>b):\n print(a,a+b)\n else:\n print(b,a+b)\nexcept:\n pass", "# cook your dish here\nT=int(input())\nfor i in range(T):\n a,b=map(int,input().split())\n #n=int(input())\n print(max(a,b),a+b)", "# cook your dish here\nT=int(input())\nfor i in range(T):\n a,b=map(int,input().split())\n #n=int(input())\n print(max(a,b),max(a,b)+min(a,b))", "for _ in range(int(input())):\r\n z = list(map(int, input().split()))\r\n print(int(max(z)),int(sum(z)))\r\n", "# cook your dish here\nx=int(input())\ns=0\nfor i in range(x):\n (a, b) = map(int, input().split(' '))\n if(a>b):\n s=a\n else:\n s=b\n print(s,a+b) ", "for _ in range(int(input())):\n n = list(map(int, input().split()))\n print(max(n),(n[0]+n[1]))", "for t in range(int(input())):\n x,y=map(int, input().split())\n if y>x:x,y=y,x\n print(x,x+y)", "# cook your dish here\nfor _ in range(int(input())):\n a,b=map(int,input().split(' '))\n if(a>b):\n print(a,end=\" \")\n if(b>a):\n print(b,end=\" \")\n print(a+b)", "# cook your dish here\nn=int(input())\nfor i in range(n):\n x,y=map(int,input().split())\n a=x if x==y else x+y\n print(max(x,y),a)", "# cook your dish here\nv=int(input())\nfor i in range (0,v):\n s=list(map(int,input().split()))\n print(max(s),sum(s))", "# cook your dish here\nt=int(input())\nfor i in range (0,t):\n a=list(map(int,input().split()))\n print(max(a),sum(a))\n", "t=int(input())\nfor i in range(t):\n (a,b)=list(map(int,input().split(\" \")))\n \n if a>b:\n print(a,a+b)\n else:\n print(b,a+b)\n", "t=int(input())\nfor i in range(t):\n x,y=list(map(int,input().split()));\n print(max(x,y),x+y)\n", "t=int(input())\nwhile t!=0:\n a,b=map(int,input().split())\n print(max(a,b),a+b)\n t-=1", "# cook your dish here\nt=int(input())\nwhile t!=0:\n a,b=map(int,input().split())\n print(max(a,b),a+b)\n t-=1", "t=int(input())\r\ni=0\r\nwhile i<t:\r\n\ta,b=input().split()\r\n\ta=int(a)\r\n\tb=int(b)\r\n\tMax=a+b\r\n\tif a>b:\r\n\t\tMin=a\r\n\telse:\r\n\t\tMin=b\r\n\tprint(Min,Max)\r\n\ti+=1", "# cook your dish here\nfor i in range(int(input())):\n a,b=map(int,input().split())\n if(a>b):\n print(a,a+b)\n elif(b>a):\n print(b,a+b)", "N=int(input())\n\nfor i in range(N):\n a,b=list(map(int,input().split()))\n if(a>b):\n print(a,a+b)\n \n elif(a<b):\n print(b,a+b)\n"]
{"inputs": [["1", "19 17"]], "outputs": [["19 36"]]}
INTERVIEW
PYTHON3
CODECHEF
3,577
e724cb1e00a8f25b6f17deae265c17cd
UNKNOWN
Indian National Olympiad in Informatics 2012 You are given a table with 2 rows and N columns. Each cell has an integer in it. The score of such a table is defined as follows: for each column, consider the sum of the two numbers in the column; the maximum of the N numbers so obtained is the score. For example, for the table 7162 1234 the score is max(7 + 1, 1 + 2, 6 + 3, 2 + 4) = 9. The first row of the table is fixed, and given as input. N possible ways to fill the second row are considered: 1,2,...,N 2,3,...,N,1 3,4,...,N,1,2 ··· N, 1, ... , ,N − 1 For instance, for the example above, we would consider each of the following as possibilities for the second row. 1234 2341 3412 4123 Your task is to find the score for each of the above choices of the second row. In the example above, you would evaluate the following four tables, 7162 7162 7162 7162 1234 2341 3412 4123 and compute scores 9, 10, 10 and 11, respectively. -----Input format ----- The first line of the input has a single integer, N. The second line of the input has N integers, representing the first row, from left to right. -----Output format ----- The output should consist of a single line with N integers. For 1 ² k ² N, the kth number in the output should be the score when the second row of the table is taken to be k,k+1,...,N,1,...,k−1. -----Test Data ----- The testdata is grouped into two subtasks with the following constraints on the inputs. • Subtask 1 [30 points] : 1 ≤ N ≤ 3000. • Subtask 2 [70 points] : 1 ≤ N ≤ 200000. In both the subtasks, all the integers in the first row of the table are between 1 and 100000, inclusive. -----Example ----- Here is the sample input and output corresponding to the example above. -----Sample input ----- 4 7 1 6 2 -----Sample output----- 9 10 10 11 Note: Your program should not print anything other than what is specified in the output format. Please remove all diagnostic print statements before making your final submission. A program with extraneous output will be treated as incorrect!
["# cook your dish here\ntry:\n n=int(input())\n \n list_n = list(range(1,n+1))\n list_n_flag=[]\n \n fix_arr = list(map(int,input().split()))\n \n \n k=1\n res_list=[]\n fin_list=[]\n list_n_flag = list_n[k:] + list_n[:k]\n res_list = [list_n[i] + fix_arr[i] for i in range(len(fix_arr))]\n maxx = max(res_list)\n fin_list.append(maxx)\n while list_n!=list_n_flag:\n \n res_list = [list_n_flag[i] + fix_arr[i] for i in range(len(fix_arr))]\n maxx = max(res_list)\n fin_list.append(maxx)\n list_n_flag = list_n_flag[k:] + list_n_flag[:k]\n \n print(*fin_list,sep=\" \")\nexcept:\n pass"]
{"inputs": [["and output corresponding to the example above.", "Sample input", "4", "7 1 6 2", "Sample output", "9 10 10 11", "Note: Your program should not print anything other than what is specified in the output format. Please remove all diagnostic print statements before making your final submission. A program with extraneous output will be treated as incorrect!"]], "outputs": [[]]}
INTERVIEW
PYTHON3
CODECHEF
683
dfe206cb9f991fed69e2815abe482eda
UNKNOWN
Chef likes problems on geometry a lot. Please help him to solve one such problem. Find all possible triangles with integer sides which has the radius of inscribed circle (also known as incircle) equal to R. Two triangles are said to be different if they have at least one different side lengths. Formally, let there be two triangles T1, T2. Let a, b, c denote the sides of triangle T1, such that a ≤ b ≤ c. Similarly, Let d, e, f denote the sides of triangle T2, such that d ≤ e ≤ f. Then T1 will said to be different from T2 if either a ≠ d, or b ≠ e or c ≠ f. -----Input----- There is a single test case per test file. The only line of input contains an integer R. -----Output----- Output in first line single number - number of triangles satisfying statement. Order the sides of triangles in non-decreasing order. Output all triangles in non-decreasing order, i.e. order first by smallest sides, otherwise by second smallest sides, if first and second sides equal, then by third. -----Constraints----- - 1 ≤ R ≤ 100 -----Subtasks----- - Subtask #1: (20 points) 1 ≤ R ≤ 3 - Subtask #2: (30 points) 1 ≤ R ≤ 20 - Subtask #3: (50 points) Original constraints -----Example----- Input:2 Output:5 5 12 13 6 8 10 6 25 29 7 15 20 9 10 17
["r=int(input())\nc=0\nL=[]\nfor i in range(2*r+1,2*r**2+2):\n for j in range(i,r**4+2*r**2+2):\n for k in range(j,r**4+3*r**2+2):\n if 4*(i+j+k)*r**2==(i+j-k)*(i+k-j)*(j+k-i):\n L.append([i,j,k])\n c+=1\nprint(c)\nfor i in range(c):\n for j in range(3):\n print(L[i][j], end=' ')\n print()\n \n", "from math import sqrt\nr = int(input())\ncnt=0\nrt=[]\nfor i in range(1,16*r):\n for j in range(i, 460):\n for k in range(j+1, j+i):\n #print i,j,k\n s = float((i+j+k))/2\n #print s,i,j,k,s*(s-i)*(s-j)*(s-k)\n area = sqrt(abs(s*(s-i)*(s-j)*(s-k)))\n #print(float(2*area))/(i+j+k)\n if (r==(float(2*area))/(i+j+k)):\n cnt+=1\n #print i,j,k,area\n rt.append([i,j,k])\n \nprint(cnt)\n\nfor i in rt:\n for j in i:\n print(j, end=' ')\n print()\n", "from math import sqrt\nr = int(input())\ncnt=0\nrt=[]\nfor i in range(1,10*r):\n for j in range(i, 150):\n for k in range(j+1, j+i):\n #print i,j,k\n s = float((i+j+k))/2\n #print s,i,j,k,s*(s-i)*(s-j)*(s-k)\n area = sqrt(abs(s*(s-i)*(s-j)*(s-k)))\n #print(float(2*area))/(i+j+k)\n if (r==(float(2*area))/(i+j+k)):\n cnt+=1\n #print i,j,k,area\n rt.append([i,j,k])\n \nprint(cnt)\n\nfor i in rt:\n for j in i:\n print(j, end=' ')\n print()\n", "R=int(input())\nt=[]\nfor a in range(2*R,200):\n for b in range(a,300):\n for c in range(b,400 ):\n s=(a+b+c)/2.0\n d=s*(s-a)*(s-b)*(s-c)\n if d>=0 and s!=0 and (a+b)>c:\n if R**2==(d/s**2):\n t.append([a,b,c])\n if len(t)>20:\n break\nprint(len(t))\nfor i in range(len(t)):\n print(t[i][0],t[i][1],t[i][2])", "R=int(input())\nt=[]\nfor a in range(2*R,50):\n for b in range(a,500):\n for c in range(b,500 ):\n s=(a+b+c)/2.0\n d=s*(s-a)*(s-b)*(s-c)\n if d>=0 and s!=0 and (a+b)>c:\n if R**2==(d/s**2):\n t.append([a,b,c])\n if len(t)>20:\n break\nprint(len(t))\nfor i in range(len(t)):\n print(t[i][0],t[i][1],t[i][2])", "R=int(input())\nt=[]\nfor a in range(2*R,120):\n for b in range(a,120):\n for c in range(b,120 ):\n s=(a+b+c)/2.0\n d=s*(s-a)*(s-b)*(s-c)\n if d>=0 and s!=0 and (a+b)>c:\n if R**2==(d/s**2):\n t.append([a,b,c])\n if len(t)>20:\n break\nprint(len(t))\nfor i in range(len(t)):\n print(t[i][0],t[i][1],t[i][2])", "#Pre-Computed using bruteforce\nr=int(input())\nif(r==2):\n print(5)\n print(5,12,13)\n print(6,8,10)\n print(6,25,29)\n print(7,15,20)\n print(9,10,17)\nif(r==1):\n print(1)\n print(3,4,5)\nif(r==3):\n print(13)\n print(7,24,25)\n print(7,65,68)\n print(8,15,17)\n print(8,26,30)\n print(9,12,15)\n print(10,10,12)\n print(11,13,20)\n print(11,100,109)\n print(12,55,65)\n print(13,40,51)\n print(15,28,41)\n print(16,25,39)\n print(19,20,37)", "for t in range(1):\n r = int(input())\n x = []\n for a in range(1, 200):\n for b in range(a, 200):\n for c in range(b, 200):\n if (c >= (a+b)):\n break\n else:\n s = (a + b + c)/2.0\n A = (s*(s-a)*(s-b)*(s-c))**0.5\n if abs(A/s - r) < 0.0000001:\n x.append((a, b, c))\n print(len(x))\n for a, b, c in x:\n print(a, b, c)\n"]
{"inputs": [["2"]], "outputs": [["5", "5 12 13", "6 8 10", "6 25 29", "7 15 20", "9 10 17"]]}
INTERVIEW
PYTHON3
CODECHEF
3,132
0ae6212985743fefa2d7dc7441e0d4e9
UNKNOWN
Lucy had recently learned the game, called Natural Numbers. The rules of the game are really simple. There are N players. At the same time, every player says one natural number. Let's call the number said by the i-th player Ai. The person with the smallest unique number (that is, the smallest number that was not said by anybody else) wins. Sometimes, there is a case when there are no unique numbers at all. Then the game is obviously a draw, so nobody wins it. Sometimes, it's hard to determine the winner, especially, when the number of players is enormous. So in this problem, your assignment will be: given the names of the players and the numbers every of them have said. Please, tell the name of the winner, or determine that nobody wins. -----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 every test case consists of a single integer N - the number of players. Then, N lines will follow. Each of these N lines will consist of the player's name and the number Ai said by her, separated by a single space. -----Output----- For each test case, output a single line containing an answer to the corresponding test case - the name of the winner, or a string "Nobody wins.", if nobody wins the game. -----Example----- Input: 2 5 Kouta 1 Yuka 1 Mayu 3 Lucy 2 Nana 5 2 Lucy 2 Nana 2 Output: Lucy Nobody wins. -----Scoring----- Subtask 1 (17 points): T = 10000, 1 <= N <= 10, 1 <= Ai <= 10 Subtask 2 (19 points): T = 10000, 1 <= N <= 10, 1 <= Ai <= 2*109 Subtask 3 (30 points): T = 100, 1 <= N <= 1000, 1<= Ai <= 2*109 Subtask 4 (34 points): T = 10, 1 <= N <= 10000, 1 <= Ai <= 2*109 You can safely assume that in all the test cases the length of any name will not exceed five letters. All the players' names are unique.
["try:\n t = int(input())\n while t:\n t -= 1\n n = int(input())\n arr = []\n obj = {}\n for i in range(n):\n x,y = input().split()\n y = int(y)\n arr.append([x, y])\n if y in obj: obj[y].append(x)\n else: obj[y] = [x]\n arr.sort(key = lambda i: i[1], reverse = True)\n while len(arr) and len(obj[arr[-1][1]]) > 1:\n arr.pop()\n if len(arr) == 0:\n print('Nobody wins.')\n else:\n print(arr.pop()[0])\nexcept:\n pass", "from collections import defaultdict\r\ndef call_value():\r\n return 0\r\n\r\nt=int(input())\r\nwhile(t>0):\r\n n=int(input())\r\n arr=[]\r\n for _ in range(n):\r\n s,m = input().split()\r\n m=int(m)\r\n arr.append([s,m])\r\n dic = defaultdict(call_value)\r\n for i in arr:\r\n dic[i[1]]+=1\r\n ans=[]\r\n for i in dic:\r\n if(dic[i]==1):\r\n ans.append(i)\r\n if(len(ans)==0):\r\n print(\"Nobody wins.\")\r\n else:\r\n mini=min(ans)\r\n for i in arr:\r\n if(i[1]==mini):\r\n print(i[0])\r\n break\r\n t-=1\r\n\r\n", "def comp(a,b):\r\n if len(a) > len(b):\r\n return b\r\n elif len(b) > len(a):\r\n return a\r\n else:\r\n i = 0\r\n while True:\r\n if a[i] > b[i]:\r\n return b\r\n elif b[i] > a[i]:\r\n return a\r\n i += 1\r\n\r\nfor _ in range(int(input())):\r\n n = int(input())\r\n a = []\r\n b = []\r\n c = []\r\n for i in range(n):\r\n name , score = map(str,input().split())\r\n a.append([name,score])\r\n if score not in c:\r\n if score in b:\r\n b.remove(score)\r\n c.append(score)\r\n else:\r\n b.append(score)\r\n\r\n if len(b) == 0:\r\n print(\"Nobody wins.\")\r\n else:\r\n ans = b[0]\r\n for i in range(1,len(b)):\r\n ans = comp(ans,b[i])\r\n for i in range(len(a)):\r\n if a[i][1] == ans:\r\n print(a[i][0])", "# cook your dish here\ndef comp(a,b):\n if len(a) > len(b):\n return b\n elif len(b) > len(a):\n return a\n else:\n i = 0\n while True:\n if a[i] > b[i]:\n return b\n else:\n return a\n i += 1\n\nfor _ in range(int(input())):\n n = int(input())\n a = []\n b = []\n c = []\n for i in range(n):\n name , score = map(str,input().split())\n a.append([name,score])\n if score not in c:\n if score in b:\n b.remove(score)\n c.append(score)\n else:\n b.append(score)\n\n if len(b) == 0:\n print(\"Nobody wins.\")\n else:\n ans = b[0]\n for i in range(1,len(b)):\n ans = comp(ans,b[i])\n for i in range(len(a)):\n if a[i][1] == ans:\n print(a[i][0])\n", "# cook your dish here\nfor _ in range(int(input())):\n n = int(input())\n a = []\n b = []\n for i in range(n):\n name , score = map(str,input().split())\n a.append([name,score])\n b.append(score)\n a.sort(key = lambda x:x[1])\n b.sort()\n i = 0\n while True:\n p = b.count(b[i])\n if p == 1:\n print(a[i][0])\n break\n else:\n i += p\n if i >= n:\n print(\"Nobody wins.\")\n break\n \n", "# cook your dish here\nfor _ in range(int(input())):\n n = int(input())\n a = []\n b = []\n for i in range(n):\n name , score = map(str,input().split())\n a.append([name,score])\n b.append(score)\n a.sort(key = lambda x:x[1])\n b.sort()\n i = 0\n while True:\n p = b.count(b[i])\n if p == 1:\n print(a[i][0])\n break\n else:\n i += p\n if i == n:\n print(\"Nobody wins.\")\n break\n \n", "from operator import itemgetter\r\nt=int(input())\r\nfor _ in range(t):\r\n n=int(input())\r\n di={}\r\n for i in range(n):\r\n a,b=input().split()\r\n b=int(b)\r\n di.setdefault(b,[])\r\n di[b].append(a)\r\n f=0\r\n for item in sorted(di):\r\n if len(di[item])==1:\r\n print(di[item][0])\r\n f=1\r\n break\r\n if f==0:\r\n print('Nobody wins.')", "# cook your dish here\nfrom collections import OrderedDict \nfor _ in range(int(input())):\n a=[]\n min=10000\n n=int(input())\n s=[0]*n\n l=[0]*n\n flag=0\n for i in range(n):\n s[i],t=input().split()\n t=int(t)\n a.append(t)\n l=a.copy() \n a.sort() \n for x in range(len(a)):\n if a.count(a[x])==1:\n m=x\n flag=1\n break\n if flag==0:\n print(\"Nobody wins.\")\n else: \n h=l.index(a[m])\n print(s[h])", "# input t,n,a[]\n# sort integers\n# if integer repeats continue\n# else break\n\nT=int(input())\nfor t in range(0,T):\n n=int(input())\n s=[0]*n\n np=[0]*n\n for i in range(0,n):\n s[i],np[i]=input().split()\n np[i]=int(np[i])\n no=np[:]\n no.sort()\n ans='-1'\n if no[0]!=no[1]:\n ans=no[0]\n else:\n for i in range(1,n-1):\n if no[i]!=no[i-1] and no[i]!=no[i+1]:\n ans=no[i]\n break\n else:\n continue\n if ans=='-1' and no[n-2]!=no[n-1]:\n ans=no[n-1]\n \n \n for i in range(0,n):\n if ans==np[i]:\n ans=int(i)\n break\n if ans=='-1':\n print('Nobody wins.')\n else:\n print(s[ans])", "# cook your dish here\nt = int(input())\n\nfor _ in range(t):\n n = int(input())\n l = []\n hash = {}\n for i in range(n):\n a,b = map(str,input().split())\n l.append([a,b])\n try:\n hash[b]\n except:\n hash[b]=1\n else:\n hash[b]+=1\n ans = []\n for i in l:\n a,b = i\n if hash[b] == 1:\n ans.append([int(b),a])\n ans.sort()\n if ans!=[]:\n print(ans[0][1])\n else:\n print('Nobody wins.')\n\n\n\n\n\n\n", "t=int(input())\r\nwhile(t):\r\n re=[]\r\n st={}\r\n m={}\r\n for _ in range(int(input())):\r\n a,b=input().split()\r\n b=int(b)\r\n if b in list(st.keys()):\r\n st[b]+=1\r\n else:\r\n st[b]=1\r\n m[b]=a\r\n re.append(int(b))\r\n count=0\r\n re=list(set(re))\r\n re.sort()\r\n ind=0\r\n for i in re:\r\n if st[i]==1:\r\n count+=1\r\n ind=i\r\n break\r\n if count==1:\r\n print(m[ind])\r\n else:\r\n print(\"Nobody wins.\")\r\n t-=1", "from collections import Counter\r\nT=int(input())\r\nfor i in range(T):\r\n NM=[]\r\n A=[]\r\n z=0\r\n N=int(input())\r\n for j in range(N):\r\n nm,a=input().split()\r\n NM.append(nm)\r\n A.append(int(a))\r\n D=Counter(A)\r\n K=sorted(D.keys())\r\n for k in K:\r\n if D[k]==1:\r\n z=k\r\n break\r\n else:\r\n pass\r\n if z==0:\r\n print(\"Nobody wins.\")\r\n else:\r\n print(NM[A.index(z)])", "\r\nfor _ in range(int(input())):\r\n\tq = []\r\n\r\n\tfor __ in range(int(input())):\r\n\t\ta, b = list(input().split())\r\n\t\tb = int(b)\r\n\t\tq.append((a,b))\r\n\r\n\tq = sorted(q, key= lambda x:x[1])\r\n\t#print(q)\r\n\ti = 0\r\n\twin = \"\"\r\n\tif len(q) == 1:\r\n\t\t#print(q[0][0])\r\n\t\tcontinue\r\n\twhile i < len(q):\r\n\t\t#print(i)\r\n\t\tt = q[i][1]\r\n\r\n\t\tif i == len(q)-1 or q[i][1] != q[i+1][1]:\r\n\t\t\twin = q[i][0]\r\n\t\t\tbreak\r\n\r\n\t\twhile i < len(q) and q[i][1] == t:\r\n\t\t\t#print(q[i][1])\r\n\t\t\ti += 1\r\n\t\t#print(i)\r\n\t\tif i == len(q):\r\n\t\t\tbreak\r\n\r\n\r\n\tif win == \"\":\r\n\t\tprint(\"Nobody wins.\")\r\n\telse:\r\n\t\tprint(win)\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\n2\r\n5\r\nKouta 1\r\nYuka 1\r\nMayu 3\r\nLucy 2\r\nNana 5\r\n2\r\nLucy 2\r\nNana 2\r\n\r\n\"\"\"", "for _ in range(int(input())):\r\n n=int(input())\r\n goes=[]\r\n for u in range(n):\r\n z=input().split()\r\n goes.append((int(z[1]),z[0]))\r\n\r\n goes.sort()\r\n res = 'Nobody wins.'\r\n last = goes[0][0] - 1\r\n win = False\r\n for val, nm in goes:\r\n if val == last:\r\n win = False\r\n else:\r\n if win:\r\n res = lastnm\r\n break\r\n win = True\r\n lastnm = nm\r\n last = val\r\n\r\n if win:\r\n res = lastnm\r\n print(res)\r\n", "# https://www.codechef.com/problems/NUMBERS\n\nfor _ in range(int(input())):\n n = int(input())\n goes = []\n for _ in range(n):\n z = input().split()\n goes.append( (int(z[1]),z[0]) )\n\n goes.sort()\n res = 'Nobody wins.'\n last = goes[0][0] - 1\n win = False\n for val, nm in goes:\n if val == last:\n win = False\n else:\n if win:\n res = lastnm\n break\n win = True\n lastnm = nm\n last = val\n \n if win:\n res = lastnm\n print(res)\n", "# https://www.codechef.com/problems/NUMBERS\n\nfor _ in range(int(input())):\n n = int(input())\n goes = []\n for _ in range(n):\n z = input().split()\n goes.append( (int(z[1]),z[0]) )\n\n goes.sort()\n res = 'Nobody wins.'\n last = goes[0][0] - 1\n win = False\n for val, nm in goes:\n if val == last:\n win = False\n else:\n if win:\n res = lastnm\n break\n win = True\n lastnm = nm\n last = val\n \n print(res)\n"]
{"inputs": [["2", "5", "Kouta 1", "Yuka 1", "Mayu 3", "Lucy 2", "Nana 5", "2", "Lucy 2", "Nana 2", "", ""]], "outputs": [["Lucy", "Nobody wins."]]}
INTERVIEW
PYTHON3
CODECHEF
10,230
6e16f9b38139a5c3e140d24d0bb5ab4d
UNKNOWN
Write a program that reads numbers until -1 is not given. The program finds how many of the given numbers are more than 30, $N$. It also finds the average weighted sum of even numbers, $A$. The weight of the $i$th number is defined as the position of the number (1 based indexing) times the number. To find the average weighted sum, you need to add all these weights for the even numbers, then divide the sum by the sum of the positions of the numbers. -----Input:----- - First line will contain $T$, number of testcases. Then the testcases follow. - Each testcase contains some numbers, terminated by -1 -----Output:----- For each testcase, output in a single line the count of numbers that are greater than 30, $N$, and the average weighted sum of the even numbers, $A$, separated by a space. Make sure to set the precision of the average weighted sum to 2 places after the decimal point. -----Constraints----- - $1 \leq T \leq 1000$ - $2 \leq N \leq 1000$ -----Sample Input:----- 1 33 100 77 42 12 -1 -----Sample Output:----- 4 38.91 -----EXPLANATION:----- In the series of numbers 33 100 77 42 12 -1, the count of numbers greater than 30 is 4 The average weighted sum of the even numbers is given by: ((2 * 100) + (4 * 42) + (5 * 12)) / (2 + 4 + 5)
["for _ in range(int(input())):\r\n a=list(map(int,input().split()))\r\n num=0\r\n den=0\r\n k=1\r\n great=0\r\n for i in a:\r\n if i==-1:break\r\n else:\r\n if i>30:great+=1\r\n if i%2==0:\r\n num+=k*i\r\n den+=k\r\n k+=1\r\n print(great,'%.2f'%(num/den))", "for i in range(int(input())):\n c = 0\n arr = list(map(int,input().split()))\n for k in arr:\n if k==-1:\n break\n arr.append(a)\n if k >30:\n c=c+1\n num = 0\n den = 0\n for i in range(0,len(arr)):\n if arr[i]%2==0:\n num = num + arr[i]*(i+1)\n den = den + i + 1\n print(c, \"{:.2f}\".format(num/den))\n \n \n \n", "T = int(input())\nwhile T:\n numbers = input().split()\n N = 0\n A = 0\n pos = 0\n for i in range(len(numbers)):\n if int(numbers[i]) > 30:\n N += 1\n if int(numbers[i]) % 2 == 0:\n A += (int(numbers[i]) * (i + 1))\n pos += (i + 1)\n print(N, '%.2f'%(A/pos))\n T -= 1", "T = int(input())\n\nfor testcase in range(T):\n i = 1\n above_30 = 0\n wsum_numerator = 0\n wsum_denominator = 0\n \n vals = [int(f) for f in input().split(\" \")]\n \n val = vals[i-1]\n \n while not val == -1:\n if val > 30:\n above_30 += 1\n \n if val % 2 == 0:\n wsum_numerator += i * val\n wsum_denominator += i\n \n i += 1\n val = vals[i-1]\n \n wsum = wsum_numerator / wsum_denominator\n print(above_30, \"{:.2f}\".format(wsum))\n", "# cook your dish here\nfor t in range(int(input())):\n N=list(map(int,input().split()))\n c=0\n p=0\n l=[]\n l1=[]\n for i in N:\n p+=1\n if i>30:\n c+=1\n if i>0:\n if i%2==0:\n l.append(i*p)\n l1.append(p)\n out=sum(l)/sum(l1)\n print('{} {:.2f}'.format(c,out))\n", "# cook your dish here\nfor u in range(int(input())):\n l=list(map(int,input().split()))\n n=len(l)\n s=0\n for i in range(n):\n if(l[i]>30):\n s=s+1\n c=0\n x=0\n for i in range(n):\n if(l[i]%2==0):\n c=c+(l[i]*(i+1))\n x=x+(i+1)\n print(s,end=\" \")\n ss=c/x\n print('%.2f'%ss)\n", "t = int(input())\nwhile(t):\n t-=1\n arr = [int(x) for x in input().split()]\n count = 0\n avg = []\n divv = []\n for i in range(len(arr)):\n if(arr[i]==-1):\n break\n else:\n if(arr[i]>=30):\n count+=1\n if(arr[i]& 1==0):\n avg.append((i+1)*arr[i])\n divv.append(i+1)\n average = sum(avg)/sum(divv)\n print(count,'%.2f'%average)\n \n \n", "# cook your dish here\nt=int(input())\nwhile(t): \n l=list(map(int,input().split()))\n count=0\n div=0\n evenSum=0\n for i in range(0,len(l)-1):\n if(l[i]>30):\n count+=1 \n if(l[i]%2==0):\n evenSum+=l[i]*(i+1)\n div+=i+1\n average=evenSum/div \n print('%d %.2f'%(count,average))\n t-=1", "for _ in range(int(input())):\n count=0\n l=list(map(int,input().split(\" \")))\n s=0\n d=0\n i=1\n for x in l:\n if x>30:\n count+=1\n if x%2==0:\n s+=(i*x)\n d+=i\n i+=1\n print(count,end=\" \")\n print(\"%.2f\"%(s/d))", "for _ in range(int(input())):\n count=0\n l=list(map(int,input().split(\" \")))\n s=0\n d=0\n i=1\n for x in l:\n if x>30:\n count+=1\n if x%2==0:\n s+=(i*x)\n d+=i\n i+=1\n print(count,end=\" \")\n print(\"%.2f\"%(s/d))", "t=int(input())\nfor _ in range(t):\n l=list(map(int,input().strip().split()))\n l.insert(0,0)\n c,n,a=0,0,0\n for i in range(1,len(l)):\n if l[i]>=30:\n c+=1\n if l[i]%2==0:\n a+=l[i]*i\n n+=i\n x=a/n \n print(c,\"{:.2f}\".format(x)) \n\n", "t=int(input())\r\ni=1 \r\nwhile(i<=t):\r\n lst=list(map(int,input().strip().split()))\r\n a=lst.index(-1)\r\n lst1=lst[0:(a)]\r\n a1=len([j for j in lst1 if j>30])\r\n lst2=[k for k in lst1 if (k%2==0)]\r\n lst3=[0]*len(lst2)\r\n s=0 \r\n for l in range(0,len(lst2)):\r\n lst3[l]=(lst1.index(lst2[l])+1)\r\n s=s+(lst2[l]*lst3[l])\r\n ans=s/sum(lst3)\r\n print(a1,\"{0:.2f}\".format(ans))\r\n i+=1 \r\n \r\n", "for _ in range(int(input())):\n x = [int(w) for w in input().split()]\n ind = x.index(-1)\n x = x[:ind]\n ctr = 0\n a,b = 0,0\n for i in range(len(x)):\n if x[i] > 30:\n ctr += 1\n if x[i]%2==0:\n a += (i+1)*x[i]\n b += (i+1)\n ans = a/b\n print(ctr,'%.2f'%ans)", "for _ in range(int(input())):\r\n\ta=list(map(int,input().split()))\r\n\ta.remove(-1)\r\n\tb=[]\r\n\td=[]\r\n\tc=0\r\n\ts=0\r\n\tfor i in range(len(a)):\r\n\t\tif a[i]>30:\r\n\t\t\tc+=1\r\n\t\tif a[i]%2==0:\r\n\t\t\tb.append(a[i])\r\n\t\t\td.append(i+1)\r\n\tfor j in range(len(b)):\r\n\t\ts+=b[j]*d[j]\r\n\tr=s/sum(d)\r\n\tprint('{} {:.2f}'.format(c,r))"]
{"inputs": [["1", "33 100 77 42 12 -1"]], "outputs": [["4 38.91"]]}
INTERVIEW
PYTHON3
CODECHEF
5,315
e8a9f6260592b622073491a3f003e829
UNKNOWN
Mance Rayder, the King-Beyond-the-Wall, has always wanted to lead the largest army the North has ever seen against the NIght’s Watch. For this humungous feat he has banded the waring tribes, the Giants, Thenns and Wildings, together by going to great extents. But the King is facing with an issue he always saw it coming. The huge army is divided into smaller divisions and each division can be of the type $G, T$ or $W$ standing for Giants, Thenns and Wildings respectively. Mance doesn’t want two divisions of the same type standing together as he fears it might lead to a mutiny or an unorganised charge or retreat. For a given numbers of $G, T$ and $W$, find whether an army can be organised in accordance to the rules set by Mance. Not to forget that Mance has to include all the divisions in his battle formation in order to stand a chance against the Wall’s defences. -----Input:----- - First line will contain $N$, the number of test cases. - Each of the next $N$ lines will contain three integers $G$, $T$ and $W$ - the number of Giant, Thenn and Wildling divisions respectively. -----Output:----- For each testcase, output in a single line $Yes$ if a battle formation is possible or $No$ otherwise. -----Constraints----- - $1 \leq N \leq 100$ - $1 \leq G,T,W \leq 10^9$ -----Sample Input:----- 1 1 2 1 -----Sample Output:----- Yes -----Explanation:----- The first case can be formed as : $ TGWT $. Hence the answer is $ Yes $.
["n=int(input())\nfor i in range(n):\n a=list(map(int,input().split()))\n a.sort()\n if a[0]+a[1]>=a[2]-1:\n print(\"Yes\")\n else:\n print(\"No\")\n \n", "for _ in range(int(input())):\n a=list(map(int,input().split()))\n a.sort()\n if(a[0]+a[1]>=a[2]):\n print(\"Yes\")\n else:\n print(\"No\")", "test=int(input())\nwhile(test!=0):\n a=list(map(int,input().split()))\n a.sort()\n if (a[0]+a[1]+1)>=max(a):\n print(\"Yes\")\n else:\n print(\"No\")\n test-=1\n", "# cook your dish here\nfor _ in range(int(input())):\n li=[int(i) for i in input().split()]\n li.sort()\n if (li[0]+li[1]+1)>=li[2]:\n print(\"Yes\")\n else:\n print('No')", "# cook your dish here\nT = int(input())\nfor i in range(T):\n G,T,W = map(int,input().split())\n if G+T<W or G+W<T or W+T<G:\n print(\"No\")\n else:\n print(\"Yes\")", "# cook your dish here\nfor a0 in range(int(input())):\n x=list(map(int, input().split()))\n x.sort()\n if x[0]+x[1]>=x[2]-1:\n print(\"Yes\")\n else:\n print(\"No\")", "for _ in range(int(input())):\n a = (int(i) for i in input().split())\n a = sorted(a)\n if (a[2] <= (a[0] + a[1] + 1)):\n print('Yes')\n else:\n print('No')\n\n", "for t in range(int(input())):\n g=list(map(int,input().split()))\n m=max(g)\n g.remove(m)\n m1=max(g)\n m2=min(g)\n if(m1+m2>=m-1):\n print(\"Yes\")\n elif(m1==m2 and m2==m):\n print(\"Yes\")\n else:print(\"No\")", "try:\n for _ in range(int(input())):\n g,t,w=map(int,input().rstrip().split())\n m=max(g,t,w)\n total=g+t+w-m\n if m-total<2:\n print('Yes')\n else:\n print('No')\nexcept:\n pass", "for t in range(int(input())):\n g,t,w=list(map(int,input().split()))\n m=max(g,t,w)\n if((g+t+w-m+1)>=m):\n print('Yes')\n else:\n print('No')\n", "for i in range(int(input())):\n li=list(map(int,input().split()))\n '''if a>0 and b>0 and c>0:\n if a+b>c or b+c>a or a+c>b :\n print(\"Yes\")\n else:\n print(\"No\")\n else:\n print(\"No\")'''\n a=max(li)\n b=min(li)\n c=0\n for j in li:\n if j!=a and j!=b:\n c=j\n break\n if c==0:\n if li.count(min(li))>li.count(max(li)):\n c=min(li)\n else:\n c=max(li)\n if b+c>=a-1:\n print(\"Yes\")\n elif a==b and a==c:\n print(\"Yes\")\n else:\n print(\"No\")\n", "for t in range(int(input())):\n a,b,c=list(map(int,input().split()))\n l=[]\n l.append(a)\n l.append(b)\n l.append(c)\n l.sort()\n if(l[2]<=((l[0]+l[1])+1)):\n print(\"Yes\")\n else:\n print(\"No\")\n", "for i in range(int(input())):\n li=list(map(int,input().split()))\n t=abs(sum(li)-max(li))\n if(t>=max(li)-1):\n print(\"Yes\")\n else:\n print(\"No\")\n", "t=int(input())\nfor i in range(t):\n s=list(map(int,input().split()))\n s.sort()\n if s[2]>s[0]+s[1]+1:\n print(\"No\")\n else:\n print(\"Yes\")\n", "for i in range(int(input())):\n \n l=[int(x) for x in input().split()]\n \n l.sort(reverse=True)\n if(l[1]+l[2]>=l[0]):\n print(\"Yes\") \n else:\n print(\"No\") ", "for i in range (int(input())):\n r,b,k=map(int,input().split())\n if (r-1>b+k or b-1>r+k or k-1>r+b):\n print(\"No\")\n else:\n print(\"Yes\")", "'''\n _____ _ _\n/ ___/ | | ____ ____ ____ | | \n| / _ _ | |__ / _ \\ / __| _ __ / _ \\ ____ | | __ ___ ___ ___\n| | | | | || _ \\ | |_) || |_ | '__|| |_) | / _ || |/ / / / /\n| \\___ | \\_/ || |_) || ____/| _| | / | ____/ | (_| || / / / /\n\\_____\\\\_____/|__,_/ \\_____||_| |_| \\_____| \\__,_||_|\\_\\ / / / \u00a0\u00a0\u00a0\u00a0 \n'''\nimport math\nfor i in range(int(input())):\n a= list(map(int,input().split()))\n a.sort()\n a[1]=a[1]-a[0]\n a[2]=a[2]-2*a[0]\n if(a[2]-a[1]<=1):\n print('Yes')\n else:\n print('No')\n", "for _ in range(int(input())):\n l = sorted(list(map(int,input().split())))\n if l[0]+l[1]+1 >= l[2]:\n print(\"Yes\")\n else:\n print(\"No\")", "# cook your dish here\nfrom sys import stdin, stdout\nimport math\nfrom itertools import permutations, combinations\nfrom collections import defaultdict\nimport bisect\nimport heapq as hq\n\n\ndef L():\n return list(map(int, stdin.readline().split()))\n\n\ndef In():\n return list(map(int, stdin.readline().split()))\n\n\ndef I():\n return int(stdin.readline())\n\n\nP = 1000000007\n\n\ndef main():\n try:\n for _ in range(I()):\n # code here ALL THE BEST\n l=L()\n l.sort()\n if (l[0]+l[1]>=l[2]):\n print('Yes')\n else:\n print('No')\n\n\n except:\n pass\n\n\ndef __starting_point():\n main()\n\n__starting_point()", "# cook your dish here\nfor _ in range(int(input())):\n a,b,c = list(map(int,input().split()))\n ma = max(a,b,c)\n mb = min(a,b,c)\n mc = a+b+c-ma-mb\n if ma <= mb+mc+1:\n print(\"Yes\")\n else :\n print(\"No\")", "n = int(input())\nfor _ in range(n):\n a = list(map(int, input().split()))\n a.sort()\n if a[2] <= (a[1]+a[0]+1):\n print('Yes')\n else:\n print('No')", "# cook your dish here\nn = int(input())\nfor i in range(n):\n li = [int(i) for i in input().split()]\n print('Yes' if sum(li) - max(li) >= max(li) else 'No')", "# cook your dish here\ntry:\n t=int(input())\n for i in range(t):\n l=list(map(int,input().split()))\n r=l.index(max(l))\n s=0\n for j in l:\n if(j!=l[r]):\n s+=j \n if(s+1>=l[r]):\n print(\"Yes\")\n else:\n print(\"No\")\nexcept:\n pass\n", "# cook your dish here\ntry:\n t=int(input())\n for i in range(t):\n l=list(map(int,input().split()))\n r=l.index(max(l))\n s=0\n for j in l:\n if(j!=l[r]):\n s+=j \n if(s+1>=l[r]):\n print(\"Yes\")\n else:\n print(\"No\")\nexcept:\n pass\n", "t = int(input())\nfor i in range(t):\n a = [int(i) for i in input().split()]\n a = sorted(a)\n if a[2] > a[0] + a[1]:\n print(\"No\")\n else:\n print(\"Yes\")\n \n"]
{"inputs": [["1", "1 2 1"]], "outputs": [["Yes"]]}
INTERVIEW
PYTHON3
CODECHEF
5,767
6f85ebb321352c7565c9a0c331988b27
UNKNOWN
Master Oogway has forseen that a panda named Po will be the dragon warrior, and the master of Chi. But he did not tell anyone about the spell that would make him the master of Chi, and has left Po confused. Now Po has to defeat Kai, who is the super villian, the strongest of them all. Po needs to master Chi, and he finds a spell which unlocks his powerful Chi. But the spell is rather strange. It asks Po to calculate the factorial of a number! Po is very good at mathematics, and thinks that this is very easy. So he leaves the spell, thinking it's a hoax. But little does he know that this can give him the ultimate power of Chi. Help Po by solving the spell and proving that it's not a hoax. -----Input----- First line of input contains an integer T denoting the number of test cases. The next T lines contain an integer N. -----Output----- For each test case, print a single line containing the solution to the spell which is equal to factorial of N, i.e. N!. Since the output could be large, output it modulo 1589540031(Grand Master Oogway's current age). -----Constraints----- - 1 ≤ T ≤ 100000 - 1 ≤ N ≤ 100000 -----Example----- Input: 4 1 2 3 4 Output: 1 2 6 24
["arr = []\narr.append(1)\n_ = 1\nwhile _<=100002:\n arr.append(_*arr[_-1]%1589540031)\n _+=1\nfor _ in range(int(input())):\n print(arr[int(input())])", "T=int(input())\na=[]\na.append(1)\nfor j in range(10**5+1):\n a.append(a[j]*(j+1)%1589540031)\nfor i in range(T):\n N=int(input())\n print(a[N])", "a = []\na.append(1)\nfor i in range(1,100001):\n a.append( (a[-1]*i) % 1589540031 )\nt = int(input() )\nfor i in range(t):\n n = int(input() )\n print(a[n])", "t = eval(input())\nli =[0] * 100001\nli[1] = 1\nfor j in range(2,100001):\n li[j] = (li[j-1]*j)%1589540031\nfor x in range(t):\n n = eval(input())\n print(li[n])\n", "facts = []\nlast = 1\nfor i in range(1, 100001):\n last = last * i % 1589540031\n facts.append(last)\nfor x in range(eval(input())):\n print(facts[eval(input())-1])"]
{"inputs": [["4", "1", "2", "3", "4"]], "outputs": [["1", "2", "6", "24"]]}
INTERVIEW
PYTHON3
CODECHEF
796
658568e65f55738f0d2f8f6096c09153
UNKNOWN
Chef is in need of money, so he decided to play a game with Ramsay. In this game, there are $N$ rows of coins (numbered $1$ through $N$). For each valid $i$, the $i$-th row contains $C_i$ coins with values $A_{i, 1}, A_{i, 2}, \ldots, A_{i, C_i}$. Chef and Ramsay alternate turns; Chef plays first. In each turns, the current player can choose one row that still contains coins and take one of the coins remaining in this row. Chef may only take the the first (leftmost) remaining coin in the chosen row, while Ramsay may only take the last (rightmost) remaining coin in the chosen row. The game ends when there are no coins left. Each player wants to maximise the sum of values of the coins he took. Assuming that both Chef and Ramsay play optimally, what is the maximum amount of money (sum of values of coins) Chef can earn through this game? -----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 an integer $C_i$, followed by a space and $C_i$ space-separated integers $A_{i, 1}, A_{i, 2}, \ldots, A_{i, C_i}$. -----Output----- For each test case, print a single line containing one integer ― the maximum amount of money Chef can earn. -----Constraints----- - $1 \le T \le 10$ - $1 \le N \le 10^4$ - $1 \le C_i \le 10$ for each valid $i$ - $1 \le A_{i, j} \le 10^5$ for each valid $i$ and $j$ -----Subtasks----- Subtask #1 (20 points): $N = 1$ Subtask #2 (80 points): original constraints -----Example Input----- 1 2 4 5 2 3 4 2 1 6 -----Example Output----- 8 -----Explanation----- Example case 1: One optimal sequence of moves is: Chef takes the coin with value $5$, Ramsay takes $4$, Chef takes $2$, Ramsay takes $3$, Chef takes $1$ and Ramsay takes $6$. At the end, Chef has $5+2+1 = 8$ units of money.
["for i in range(int(input())):\n n=int(input())\n chef=0\n ans=[]\n for i in range(0,n):\n l=list(map(int,input().split()))\n c=l[0]\n if c%2==0:\n for i in range(1,len(l)//2+1):\n chef=chef+l[i]\n continue;\n for i in range(1,len(l)//2):\n chef=chef+l[i]\n ans.append(l[len(l)//2])\n ans.sort(reverse=True)\n for i in range(len(ans)):\n if i%2==0:\n chef=chef+ans[i]\n print(chef)\n \n \n", "for i in range(int(input())):\n n=int(input())\n chef=0\n ans=[]\n for i in range(0,n):\n l=list(map(int,input().split()))\n c=l[0]\n if c%2==0:\n for i in range(1,len(l)//2+1):\n chef=chef+l[i]\n continue;\n for i in range(1,len(l)//2):\n chef=chef+l[i]\n ans.append(l[len(l)//2])\n ans.sort(reverse=True)\n for i in range(len(ans)):\n if i%2==0:\n chef=chef+ans[i]\n print(chef)\n \n \n", "for i in range(int(input())):\n n=int(input())\n chef=0\n ans=[]\n for i in range(0,n):\n l=list(map(int,input().split()))\n c=l[0]\n if c%2==0:\n for i in range(1,len(l)//2+1):\n chef=chef+l[i]\n continue;\n for i in range(1,(len(l)//2)+1):\n chef=chef+l[i]\n ans.append(l[len(l)//2])\n print(chef)\n \n \n", "for i in range(int(input())):\n n=int(input())\n chef=0\n ans=[]\n for i in range(0,n):\n l=list(map(int,input().split()))\n c=l[0]\n if c%2==0:\n for i in range(1,len(l)//2+1):\n chef=chef+l[i]\n continue;\n for i in range(1,len(l)//2):\n chef=chef+l[i]\n ans.append(l[len(l)//2])\n ans.sort(reverse=True)\n for i in range(len(ans)):\n if i%2==0:\n chef=chef+ans[i]\n print(chef)\n \n \n", "# cook your dish here\n\nT = int(input())\n\nfor _ in range(T):\n n = int(input())\n s = 0\n temp = []\n for _ in range(n):\n l = list(map(int, input().split()))\n if l[0]%2 == 0:\n s += sum(l[1:len(l)//2+1])\n else:\n s += sum(l[1:len(l)//2])\n temp.append(l[len(l)//2])\n temp.sort(reverse= True)\n s += sum(temp[::2])\n \n print(s)\n", "t=int(input())\nfor i in range(t):\n n=int(input())\n chef=0\n t=[]\n for i in range(n):\n l=list(map(int,input().split()))\n c=l[0]\n if c%2==0:\n for i in range(1,len(l)//2+1):\n chef=chef+l[i]\n continue;\n for i in range(1,len(l)//2):\n chef=chef+l[i]\n t.append(l[len(l)//2])\n t.sort(reverse=True)\n for i in range(len(t)):\n if i%2==0:\n chef=chef+t[i]\n print(chef)\n \n", "# cook your dish here\nimport math\nfor _ in range(int(input())):\n n=int(input())\n x=0\n mi=[]\n for i in range(n):\n l=list(map(int,input().split()))\n c=l[0]\n l1=l[1:]\n d=math.floor(c/2)\n s=sum(l1[:d])\n x=x+s\n if c%2!=0:\n mi.append(l1[d])\n mi.sort(reverse=True)\n for i in range(len(mi)):\n if(i+1)%2!=0:\n x=x+mi[i]\n \n print(x)\n", "# cook your dish here\nimport math\nfor _ in range(int(input())):\n n=int(input())\n x=0\n for i in range(n):\n l=list(map(int,input().split()))\n c=l[0]\n l1=l[1:]\n d=math.ceil(c/2)\n s=sum(l1[:d])\n x=x+s\n l1=[]\n c=0\n d=0\n print(x)\n", "# cook your dish here\nimport math\nfor _ in range(int(input())):\n n=int(input())\n x=0\n for i in range(n):\n l=list(map(int,input().split()))\n c=l[0]\n l1=l[1:]\n d=math.ceil(c/2)\n for i in range(d):\n x=x+l1[i]\n l1=[]\n c=0\n d=0\n print(x)\n", "# cook your dish here\nimport math\nfor _ in range(int(input())):\n n=int(input())\n x=0\n for i in range(n):\n l=list(map(int,input().split()))\n c=l[0]\n l1=l[1:]\n s=len(l1)\n d=math.ceil(s/2)\n for i in range(d):\n x=x+l1[i]\n print(x)\n", "# cook your dish here\nimport math\nfor _ in range(int(input())):\n n=int(input())\n x=0\n for i in range(n):\n l=list(map(int,input().split()))\n c=l[0]\n l=l[1:]\n s=len(l)\n d=math.ceil(s/2)\n for i in range(d):\n x=x+l[i]\n print(x)\n", "for _ in range(int(input())):\n chef,f = 0,[]\n for j in range(int(input())):\n k=list(map(int,input().split()))\n for r in range(1,k[0]//2 +1 ):chef+=k[r]\n if(k[0]%2==1):f.append(k[k[0]//2 +1])\n f.sort(reverse=True)\n for p in range(0,len(f),2):chef+=f[p]\n print(chef)", "# cook your dish here\ntest=int(input())\ndic={}\nfor _ in range(test):\n dic={}\n n=int(input())\n for i in range(n):\n a=input().split()\n l=[int(a[i]) for i in range(1,int(a[0])+1)]\n dic[i]=l\n c=0\n lg=[]\n for i in dic:\n c+=len(dic[i])\n chef={i:dic[i][0] for i in range(n)}\n ram={i:dic[i][len(dic[i])-1] for i in range(n)}\n #chef={k: v for k, v in sorted(chef.items(), key=lambda item: item[1])}\n #ram={k: v for k, v in sorted(ram.items(), key=lambda item: item[1])}\n i=0\n ans=0\n while(i<c):\n if(i%2==0):\n var=min(chef,key=chef.get)\n #print(chef[var])\n ans+=chef[var]\n if(len(dic[var])==1):\n chef.pop(var)\n ram.pop(var)\n dic[var].pop(0)\n else:\n dic[var].pop(0)\n chef[var]=dic[var][0]\n #print(\"dic=\",dic)\n else:\n var=min(ram,key=ram.get)\n lg=len(dic[var])-1\n if(lg==0):\n chef.pop(var)\n ram.pop(var)\n else:\n dic[var].pop(lg)\n ram[var]=dic[var][lg-1]\n #print(\"dic=\",dic)\n\n i+=1\n print(ans)\n \n \n \n", "for _ in range(int(input())):\n chef=0\n f=[]\n for j in range(int(input())):\n k=list(map(int,input().split()))\n for r in range(1,k[0]//2 +1 ):\n chef+=k[r]\n if(k[0]%2==1):\n f.append(k[k[0]//2 +1])\n f.sort(reverse=True)\n for p in range(0,len(f),2):\n chef+=f[p]\n print(chef)\n \n", "for _ in range(int(input())):\n chef=0\n for j in range(int(input())):\n k=list(map(int,input().split()))\n if(k[0]%2==0):\n for r in range(1,k[0]//2 +1 ):\n chef+=k[r]\n else:\n for r in range(1,k[0]//2 +2 ):\n chef+=k[r]\n print(chef)\n \n", "for _ in range(int(input())):\n n=int(input())\n l,l1=[],[]\n l3=[]\n s=0\n for i in range(n):\n l2=list(map(int,input().split()))\n n=l2[0]\n l2=l2[1:]\n if n%2==0:\n s+=sum(l2[:len(l2)//2])\n else:\n l.append(sum(l2[:len(l2)//2]))\n l.append(sum(l2[:len(l2)//2+1]))\n l1.append(l)\n l=[]\n l3.append(l1[len(l1)-1][1]-l1[len(l1)-1][0])\n l4=l3.copy()\n for i in range(len(l3)):\n \n if i<len(l3)//2:\n t=l3.index(min(l3))\n s+=min(l1[t])\n l3[t]=99999\n else:\n t=l4.index(max(l4))\n s+=max(l1[t])\n l4[t]=0\n print(s)\n \n \n \n", "for _ in range(int(input())):\n n=int(input())\n l,l1=[],[]\n l3=[]\n s=0\n for i in range(n):\n l2=list(map(int,input().split()))\n n=l2[0]\n l2=l2[1:]\n if n%2==0:\n s+=sum(l2[:len(l2)//2])\n else:\n l.append(sum(l2[:len(l2)//2]))\n l.append(sum(l2[:len(l2)//2+1]))\n l1.append(l)\n l=[]\n l3.append(l1[len(l1)-1][1]-l1[len(l1)-1][0])\n for i in range(len(l3)):\n if i<len(l3)//2:\n t=l3.index(min(l3))\n s+=min(l1[t])\n l1.remove(l1[t])\n else:\n t=l3.index(min(l3))\n s+=max(l1[t])\n l1.remove(l1[t])\n print(s)\n \n \n \n", "for _ in range(int(input())):\n n=int(input())\n l,l1=[],[]\n l3=[]\n s=0\n for i in range(n):\n l2=list(map(int,input().split()))\n n=l2[0]\n l2=l2[1:]\n if n%2==0:\n s+=sum(l2[:len(l2)//2])\n else:\n l.append(sum(l2[:len(l2)//2]))\n l.append(sum(l2[:len(l2)//2+1]))\n l1.append(l)\n l=[]\n l3.append(l1[len(l1)-1][1]-l1[len(l1)-1][0])\n for i in range(len(l3)):\n if i<len(l3)//2:\n t=l3.index(min(l3))\n s+=min(l1[t])\n l1.remove(l1[t])\n else:\n t=l3.index(min(l3))\n s+=max(l1[t])\n l1.remove(l1[t])\n print(s)\n \n \n \n", "for _ in range(int(input())):\n s=0\n l1=[]\n for i in range(int(input())):\n l=list(map(int,input().split()))\n n=l[0]\n l=l[1:]\n if n%2==0:\n s+=sum(l[:n//2])\n else:\n l1.append(l)\n l2,l3=[],[]\n for i in range(len(l1)):\n l2.append(sum(l1[i][:len(l1[i])//2]))\n l2.append(sum(l1[i][:len(l1[i])//2+1]))\n l3.append(l2)\n l2=[]\n l3.sort()\n for i in range(len(l3)):\n if i<len(l3)//2:\n s+=min(l3[i])\n else:\n s+=max(l3[i])\n print(s)\n", "for _ in range (int(input())):\n n1=int(input())\n sum1=0\n for i in range(n1):\n li=[int(i) for i in input().split()]\n li.pop(0)\n if len(li)%2==0:\n n=(len(li))//2\n else:\n n=(len(li)//2)+1\n sum1+=sum(li[:n])\n print(sum1)\n \n \n", "# cook your dish here\nfor _ in range(int(input())):\n n=int(input()) \n chef,f=0,[]\n for i in range(n):\n l=list(map(int,input().split()))\n b=l[0]\n if b&1:\n f.append(l[(b//2)+1]) \n for i in range(1,(b//2)+1):\n chef+=l[i]\n print(chef+sum((sorted(f))[::2]))", "# cook your dish here\nfor _ in range(int(input())):\n n=int(input()) \n chef,f=0,[]\n for i in range(n):\n l=list(map(int,input().split()))\n b=l[0]\n if b&1:\n f.append(l[(b//2)+1]) \n for i in range(1,(b//2)+1):\n chef+=l[i]\n print(chef+sum((sorted(f,reverse=True))[::2]))", "# cook your dish here\nfor _ in range(int(input())):\n n=int(input()) \n chef,f=0,[]\n for i in range(n):\n l=list(map(int,input().split()))\n b=l[0]\n if b&1:\n f.append(l[(b//2)+1]) \n for i in range(1,(b//2)+1):\n chef+=l[i]\n print(chef+sum(sorted(f)[::2]))"]
{"inputs": [["1", "2", "4 5 2 3 4", "2 1 6"]], "outputs": [["8"]]}
INTERVIEW
PYTHON3
CODECHEF
8,776
7fcefaef98c24823945f40c388573871
UNKNOWN
Consider a currency system in which there are notes of six denominations, namely, Rs. 1, Rs. 2, Rs. 5, Rs. 10, Rs. 50, Rs. 100. If the sum of Rs. N is input, write a program to computer smallest number of notes that will combine to give Rs. N. -----Input----- The first line contains an integer T, total number of testcases. Then follow T lines, each line contains an integer N. -----Output----- For each test case, display the smallest number of notes that will combine to give N, in a new line. -----Constraints----- - 1 ≤ T ≤ 1000 - 1 ≤ N ≤ 1000000 -----Example----- Input 3 1200 500 242 Output 12 5 7
["# cook your dish here\nt= int(input())\nfor i in range(t):\n cnt=0\n n=int(input())\n while(n>=100):\n n-=100\n cnt+=1\n while(n>=50):\n n-=50\n cnt+=1\n while(n>=10):\n n-=10\n cnt+=1\n while(n>=5):\n n-=5\n cnt+=1\n while(n>=2):\n n-=2\n cnt+=1\n while(n>=1):\n n-=1\n cnt+=1\n print(cnt)", "n = int(input())\ndef count (x) :\n m = 0 \n if (x - 100 >= 0) :\n m = int(x/100)\n x = x%100 \n if (x - 50 >= 0):\n m = int(x/50) + m\n x = x%50\n if (x - 10 >= 0):\n m = int(x/10) + m \n x = x%10\n if (x - 5 >= 0) :\n m = int(x/5) + m \n x = x%5\n if (x - 2 >= 0) :\n m = int(x/2) + m \n x= x%2\n if (x - 1 >= 0) :\n m = 1 + m \n return (m) \n \nfor i in range (n) :\n x = int(input())\n p = count(x)\n print(p)\n \n", "n=int(input())\nfor i in range(n):\n a=int(input())\n note=0\n while a!=0:\n if a>=100:\n a-=100\n elif a>=50:\n a-=50\n elif a>=10:\n a-=10 \n elif a>=5:\n a-=5 \n elif a>=2:\n a-=2\n else:\n a-=1 \n note+=1 \n print(note)\n \n", "for _ in range(int(input())):\n l=[100,50,10,5,2,1]\n n=int(input())\n c=0\n for i in l:\n if(n>=i):\n r=n/i\n if(type(r)==int):\n print(r)\n break\n else:\n r=int(r)\n c+=r\n n=n-(i*r)\n if(n==0):\n break\n print(c)\n \n \n \n \n \n", "x=int(input())\nlst=[1 , 2 , 5 , 10 , 50 , 100 ]\nfor i in range(x):\n y=int(input())\n c=5\n a=0\n while(y>0):\n if(y >= lst[c] ):\n y=y-lst[c]\n a=a+1\n else:\n c=c-1\n print(a) \n", "# cook your dish here\nx=int(input())\nlst=[1 , 2 , 5 , 10 , 50 , 100 ]\nfor i in range(x):\n y=int(input())\n c=5\n a=0\n while(y>0):\n if(y >= lst[c] ):\n y=y-lst[c]\n a=a+1\n else:\n c=c-1\n print(a) ", "# cook your dish here\nx=int(input())\nlst=[1 , 2 , 5 , 10 , 50 , 100 ]\nfor i in range(x):\n y=int(input())\n c=5\n a=0\n while(y>0):\n if(y >= lst[c] ):\n y=y-lst[c]\n a=a+1\n else:\n c=c-1\n print(a) ", "# cook your dish here\ndef notes(a):\n Q = [ 100, 50, 10,5,2,1]\n x ,b= 0,0\n for i in Q:\n b=a//i\n x += b\n a = a-i*b\n return x\nn=int(input())\nfor i in range(n):\n m=int(input())\n print(notes(m))", "# cook your dish here\nt=int(input())\nwhile t!=0:\n n=int(input())\n ct=0\n notes=[100,50,10,5,2,1]\n i=0\n while n:\n ct+=n//notes[i]\n n=n%notes[i]\n i+=1\n print(ct)\n t=t-1", "t=int(input())\nl=[100,50,10,5,2,1]\nfor _ in range(t):\n c=0\n n=int(input())\n i=0\n while n:\n c+=n//l[i]\n n=n%l[i]\n i=i+1\n \n print(c)", "t=int(input())\nl=[100,50,10,5,2,1]\nfor _ in range(t):\n c=0\n n=int(input())\n i=0\n while n:\n c+=n//l[i]\n n=n%l[i]\n i=i+1\n \n print(c)\n \n", "#Read the number of test cases.\r\nT = int(input())\r\n\r\nfor tc in range(T):\r\n# Read integers a and b.\r\n n = int(input())\r\n count = 0\r\n while n:\r\n count += n//100\r\n n=n%100\r\n count += n//50\r\n n=n%50\r\n count += n//10\r\n n=n%10\r\n count += n//5\r\n n=n%5\r\n count += n//2\r\n n=n%2\r\n count += n//1\r\n n=n%1\r\n print(count) \r\n", "# cook your dish here\na=[100,50,10,5,2,1]\nfor i in range(int(input())):\n n=int(input())\n c=0\n for i in a:\n if n!=0:\n if n//i!=0:\n c+=n//i\n n-=((n//i)*i)\n else:\n break \n print(c)", "# cook your dish here\nT = int(input())\n\navail = [100,50,10,5,2,1]\n\nfor i in range(T):\n N = int(input())\n notes = []\n for note in avail:\n if note > N:\n continue\n else:\n c = N//note\n notes.append(c)\n N = N % note\n print(sum(notes))", "t=int(input())\r\ni=0\r\nwhile i<t:\r\n\tn=int(input())\r\n\tc=0\r\n\tz=0\r\n\tif n>=100:\r\n\t\ta=n//100\r\n\t\tn=n-(100*a)\r\n\t\tz=a\r\n\tif n>=50:\r\n\t\tb=n//50\r\n\t\tn=n-(50*b)\r\n\t\tz=z+b\r\n\tif n>=10:\r\n\t\tc=n//10\r\n\t\tn=n-(10*c)\r\n\t\tz=z+c\r\n\tif n>=5:\r\n\t\td=n//5\r\n\t\tn=n-(5*d)\r\n\t\tz=z+d\r\n\tif n>=2:\r\n\t\te=n//2\r\n\t\tn=n-(2*e)\r\n\t\tz=z+e\r\n\tif n==1:\r\n\t\tprint(z+1)\r\n\telse:\r\n\t\tprint(z)\r\n\ti+=1", "n=int(input())\nfor i in range(n):\n t=int(input())\n sum=0\n while(t):\n t1=t//100\n sum+=t1\n t=t%100\n if t>0:\n t1=t//50\n sum+=t1\n t=t%50\n if t>0:\n t1=t//10\n sum+=t1\n t=t%10\n if t>0:\n t1=t//5\n sum+=t1\n t=t%5\n if t>0:\n t1=t//2\n sum+=t1\n t=t%2\n if t>0:\n t1=t//1\n sum+=t1\n t=t%1\n print(sum)", "# cook your dish here\nt=int(input())\nfor i in range(t):\n s=0\n n=int(input())\n l=[100,50,10,5,2,1]\n k=n\n while(k!=0):\n for j in range(len(l)):\n s=s+(k//l[j])\n k=k%l[j]\n print(s)\n \n \n", "# cook your dish here\r\nt=int(input())\r\nfor i in range(t):\r\n s=0\r\n n=int(input())\r\n l=[100,50,10,5,2,1]\r\n k=n\r\n it=0\r\n total=0\r\n l1=[]\r\n while(sum(l1)!=n):\r\n r=k//l[it]\r\n total=total+r\r\n if(r!=0):\r\n l1.append(r*l[it])\r\n k=k%l[it]\r\n it+=1\r\n print(total)\r\n \r\n", "t= int(input())\n\nfor i in range(t):\n a=int(input())\n notes=[100,50,10,5,2,1]\n c=0\n while a>=1:\n for i in notes:\n c=c+a//i\n a=a%i\n \n print(c)", "# cook your dish here\nt=int(input())\ncl=[1,2,5,10,50,100]\nl=len(cl)\nfor i in range(t):\n a=int(input())\n n=0\n w=1\n while(a%cl[-w]!=0):\n n=n+a//cl[-w]\n a=a%cl[-w]\n w=w+1\n n=n+a//cl[-w]\n print(n)\n \n", "t=int(input())\nl=[100,50,10,5,2,1]\nfor k in range(t):\n c=0\n s=0\n n=int(input())\n for j in range(6):\n s=int(n/l[j])\n c=c+s\n n=n-(s*l[j])\n print(c)", "# cook your dish here\nt=int(input())\nfor i in range(t):\n P=[100,50,10,5,2,1]\n n=int(input())\n count=0\n for i in P:\n if(n>=i):\n count=count+n//i\n n=n%i\n print(count) ", "# cook your dish here\nfor i in range(int(input())):\n num=int(input())\n cnt=0\n lst=[100,50,10,5,2,1]\n for i in range(len(lst)):\n cnt+=num//lst[i]\n num=num%lst[i]\n print(cnt)", "# cook your dish here\nt = int(input())\nfor i in range(t):\n n = int(input())\n c=0\n sum=0\n if(n>=100):\n c = c + n//100\n n = n%100\n if(n>=50):\n c = c + n//50\n n=n%50\n if(n>=10):\n c = c+ n//10\n n = n%10\n if(n>=5):\n c = c + n//5\n n = n%5\n if(n>=2):\n c = c + n//2\n n = n%2\n if(n>=1):\n c = c+ n//1\n \n print(c)\n \n", "# cook your dish here\nn=int(input())\nl1=[]\nfor i in range(0,n):\n l1.append(int(input()))\nfor item in l1:\n num1=0\n a=item%100\n if(a==0):\n num1+=(item/100)\n else:\n num1+=((item-a)/100)\n b=a%50\n if(b==0):\n num1+=(a/50)\n else:\n num1+=((a-b)/50)\n c=b%10\n if(c==0):\n num1+=(b/10)\n else:\n num1+=((b-c)/10)\n d=c%5\n if(d==0):\n num1+=(c/5)\n else:\n num1+=((c-d)/5)\n e=d%2\n if(e==0):\n num1+=(d/2)\n else:\n num1+=((d-e)/2)\n f=e%1\n if(f==0):\n num1+=(e)\n print(int(num1))"]
{"inputs": [["3", "1200", "500", "242"]], "outputs": [["12", "5", "7"]]}
INTERVIEW
PYTHON3
CODECHEF
8,532
81993a3d359c696674c2ac24cc0c2702
UNKNOWN
After fixing the mercury leak, Kim has arrived in the planning room, where he finds a square map of a field, with $N$ rows and $N$ columns. Each cell in the field is either empty, or has a lookout tower on it. Using his notes, he immediately realises that this field is where the JSA will build their new base! Kim knows that Soum is a fan of symmetric base design, and will only approve of a base to be built if it is square. Furthermore, Soum also requires that all the rows in the base, and all the columns in the base have exactly one tower square in them. This means that a base plan is valid if and only if: - It is square in shape - Every row in the base has exactly one lookout tower in it. - Every column in the base has exactly one lookout tower in it. Kim notices that all the rows and all the columns in the field have exactly one tower square in them, but he knows that some of them could have been built to throw him off! Can you help Kim find how many valid base plans are possible in this field? Two base plans are considered different if one contains a cell in the grid that the other does not. Please refer to the samples for more details. -----Input:----- - The first line of input contains $T$, the number of testcases. - The first line of each testcase contains a single integer, $N$, representing the side length of the field. - The next $N$ lines of each testcase contain a string of length $N$, consisting of only 0 and 1. If position $j$ in string $i$ is 0, it means that this the field has no tower at $[i][j]$, and if it is 1, then this cell does have a tower at $[i][j]$. It is guaranteed that every row in the input will have exactly one tower, and every column in the input will also have exactly one tower. -----Output:----- For each testcase, output a single integer $K$, representing the number of different base plans possible. -----Subtasks----- - For all subtasks, $N \leq 2500$ and $T \leq 10$. - In addition, the sum of $N$ in any testfile is at most $2500$. Subtask 1 [28 points] : All the towers will be on the diagonal from the top-left to the bottom-right positions. Formally, all positions where $i = j$ have a tower. And no other position has a tower Subtask 2 [39 points] : $N \leq 600$ Subtask 3 [33 points] : $N \leq 2500$ -----Sample Input:----- 2 2 10 01 4 1000 0010 0100 0001 -----Sample Output:----- 3 8 -----Explanation:----- In the first testcase, there are three valid base plans: The entire 2x2 square, the 1x1 square which contains only the cell (1, 1) and the 1x1 square which contains only the cell (2, 2). In the second testcase, There are eight valid base plans: - The 4x4 square with top left corner at (1, 1) - The 3x3 square with top left corner at (1, 1) - The 3x3 square with top left corner at (2, 2) - The 3x3 square with top left corner at (1, 1) - The 2x2 square with top left corner at (2, 2) - The 1x1 square which contains only the cell (1, 1) - The 1x1 square which contains only the cell (2, 3) - The 1x1 square which contains only the cell (3, 2) - The 1x1 square which contains only the cell (4, 4)
["T = int(input())\r\n\r\nans = []\r\nfor _ in range(T):\r\n\tz = int(input())\r\n\r\n\tfor k in range(z):\r\n\t\ts = input()\r\n\r\n\tans.append((z*(z+1))//2)\r\n\r\nfor ele in ans:\r\n\tprint(ele)", "t = int(input())\nfor i in range(t):\n n = int(input())\n l =[]\n for j in range(n):\n l.append(list(input()))\n if(n==1):\n print(1)\n continue\n elif(n==2):\n print(3)\n continue\n else:\n val = int((n*(n+1))/2)\n count = (n-3)+1\n flagl = 1\n flagr = 1\n for j in range(n):\n if(flagl==0 and flagr==0):\n break\n if(l[j][j]=='0'):\n flagl=0\n if(l[n-j-1][n-j-1]=='0'):\n flagr=0\n if(flagl==0 and flagr==0):\n print(val-count)\n else:\n print(val)\n", "t=int(input())\r\nfor i in range(0,t):\r\n l=[]\r\n N=int(input())\r\n for j in range(0,N):\r\n x=input()\r\n l.append(x)\r\n print(int(N*(N+1)/2))", "# cook your dish here\nimport math\nt=int(input())\nfor _ in range(t):\n n=int(input())\n ind=[]\n \n for i in range(0,n):\n l1=input()\n x=list(l1)\n y=x.index('1')\n ind.append(y)\n \n count=n+1\n\n flag=0 \n for i in range(1,n):\n if ind[i]==ind[i-1]+1:\n flag=1\n else:\n flag=0\n break\n if flag==1:\n print(int((n*(n+1))/2))\n continue \n \n for i in range(2,n):\n for j in range(0,n):\n if (j+i)>n:\n break\n s=sum(ind[j:j+i])\n f=min(ind[j:j+i])\n if (s-i*f)==(int(((i-1)*(i))/2)):\n count+=1\n print(count) \n \n \n \n", "# cook your dish here\nfor _ in range(int(input())) :\n N = int(input())\n field = []\n for i in range(N) :\n field.append(list(map(int, input())))\n print(N*(N+1)//2)", "# cook your dish here\n# cook your dish here\nfor _ in range(int(input())):\n size=int(input())\n power=[]\n for i in range(size):\n power.append(input())\n diag=True\n for i in range(size):\n if power[i][i]=='0':\n diag=False\n break\n if diag:\n print((size*(size+1))//2)\n else:\n print(size)", "import sys\r\nfrom collections import defaultdict\r\nfrom itertools import permutations, combinations\r\nimport string\r\nfrom heapq import heapify, heappush, heappop\r\n\r\n\r\ndef solve():\r\n sys.setrecursionlimit(int(1e5))\r\n MOD = int(1e9) + 7\r\n alphabets = string.ascii_lowercase; digits = string.digits\r\n glo = globals; loc = locals;\r\n get_arr = lambda type_=int: list(map(type_, sys.stdin.readline().rstrip('\\n').split()))\r\n inp = lambda type_=int: type_(sys.stdin.readline().rstrip('\\n'))\r\n pair = lambda type_=int: list(map(type_, sys.stdin.readline().rstrip('\\n').split(' ')))\r\n debug = lambda *args: [(args[i], eval(args[i], args[-1])) for i in range(len(args)-1)]\r\n filter_ = lambda fn, arr: list(filter(fn, arr))\r\n map_ = lambda fn, arr: list(map(fn, arr))\r\n t = inp()\r\n for _ in range(t):\r\n n = inp()\r\n grid = []\r\n for i in range(n):\r\n grid.append(inp(str))\r\n d = defaultdict(int)\r\n res = n\r\n l = []\r\n for i in range(n):\r\n s = grid[i]\r\n for j in range(n):\r\n if s[j] == '1':\r\n d[i] = j\r\n l.append(j)\r\n break\r\n #print(d)\r\n # print(l)\r\n for i in range(len(grid)):\r\n my_set = set()\r\n my_set2 = set()\r\n for j in range(i, len(grid)):\r\n my_set.add(l[j])\r\n my_set2.add(d[l[j]])\r\n if my_set == my_set2 and len(my_set) > 1:\r\n res += 1\r\n print(res)\r\n\r\n\r\nsolve()\r\n", "t=int(input())\r\nwhile t!=0:\r\n sum1=0\r\n n=int(input())\r\n for i in range(1,n+1):\r\n\r\n m=input()\r\n sum1+=i\r\n print(sum1)\r\n\r\n t-=1", "try:\r\n for i in range(int(input())):\r\n n=int(input())\r\n c=0\r\n for k in range(n):\r\n s=str(input())\r\n a=s.find(\"1\")\r\n if(a!=k):\r\n c=c+1\r\n a=((n*(n+1))//2)\r\n print(a-c)\r\nexcept:\r\n pass\r\n", "def fact(n):\r\n\tfactorial = 1\r\n\tif int(n) >= 1:\r\n\t\tfor i in range (1,int(n)+1):\r\n\t\t\tfactorial = factorial * i\r\n\treturn factorial\r\n\r\nt = int(input())\r\nfor i in range(t):\r\n\tn = int(input())\r\n\ts = []\r\n\tfor j in range(n):\r\n\t\ts.append(input())\t\r\n\tprint(int((fact(n)/(fact(n-2)))/2) + n)", "t=int(input())\r\nfor _ in range (t):\r\n n=int(input())\r\n l=[]\r\n for i in range(n):\r\n l.append(input())\r\n x=int(n*(n+1)/2)\r\n print(x)\r\n", "t = int(input())\r\n\r\nwhile t > 0:\r\n n = int(input())\r\n a = []\r\n for i in range(n):\r\n temp = input()\r\n a.append(temp)\r\n\r\n print((n*n+n)//2)\r\n t-=1", "# cook your dish here\n\ndef foo(temp,p):\n flag=True\n for d in range(p):\n yet = temp[d]\n if 1 not in yet:\n flag=False\n break\n return flag\n \nT = int(input())\nfor t in range(T):\n N = int(input())\n lst = []\n count=0\n temp = []\n for n in range(N):\n num = list(map(int,str(input())))\n x = num.index(1)\n y = (n,x)\n temp.append(y)\n lst.append(num)\n \n print(int(N*(N+1)/2))", "t=int(input())\r\nfor _ in range(t):\r\n m=[]\r\n n=int(input())\r\n for i in range(n):\r\n s=input()\r\n l=list(s)\r\n m.append(l)\r\n\r\n q,ans=[],[]\r\n for i in range(len(m)):\r\n for j in range(len(m)):\r\n if m[i][j]==\"1\":\r\n ans.append((i+1,j+1))\r\n q.append([i+1,j+1])\r\n\r\n\r\n for i in range(len(q)):\r\n for j in range(i+1,len(q)):\r\n x,y=[0,0],[0,0]\r\n r=abs(q[i][0]-q[j][0])\r\n c=abs(q[i][1]-q[j][1])\r\n shift=abs(r-c)\r\n\r\n if shift==0:\r\n x=min(q[i][0],q[i][1])\r\n y=max(q[j][0],q[j][1])\r\n p=((x,x),(y,y))\r\n else:\r\n if r>c:\r\n a1,a2=min(q[i][1],q[j][1]),max(q[i][1],q[j][1])\r\n if a2+shift<=n:\r\n x[1]=a1\r\n y[1]=a2+shift\r\n x[0]=min(q[i][0],q[j][0])\r\n y[0]=max(q[i][0],q[j][0])\r\n elif a1-shift>=1:\r\n x[1]=a1-shift\r\n y[1]=a2\r\n x[0]=min(q[i][0],q[j][0])\r\n y[0]=max(q[i][0],q[j][0])\r\n else:\r\n if q[i][0]-shift>=1:\r\n x[0]=q[i][0]-shift\r\n x[1]=min(q[i][1],q[j][1])\r\n y[0]=q[j][0]\r\n y[1]=max(q[i][1],q[j][1])\r\n elif q[j][0]+shift<=n:\r\n x[0]=q[i][0]\r\n x[1]=min(q[i][1],q[j][1])\r\n y[1]=max(q[i][1],q[j][1])\r\n y[0]=q[j][0]+shift\r\n\r\n p=((x[0],x[1]),(y[0],y[1]))\r\n ans.append(p)\r\n\r\n d={}\r\n for i in ans:\r\n d[i]=1\r\n print(len(d))", "from collections import Counter\r\n\r\nfor t in range(int(input())):\r\n n = int(input())\r\n pos = [(i, input().strip().find('1')) for i in range(n)]\r\n c = n\r\n for i in range(2, n + 1):\r\n multiset = Counter()\r\n for k in range(i):\r\n multiset[pos[k][0]] += 1\r\n multiset[pos[k][1]] += 1\r\n if len(multiset) == i:\r\n c += 1\r\n for j in range(1, n - i + 1):\r\n multiset[pos[j - 1][0]] -= 1\r\n if multiset[pos[j - 1][0]] == 0:\r\n del multiset[pos[j - 1][0]]\r\n multiset[pos[j - 1][1]] -= 1\r\n if multiset[pos[j - 1][1]] == 0:\r\n del multiset[pos[j - 1][1]]\r\n multiset[pos[j + i - 1][0]] += 1\r\n multiset[pos[j + i - 1][1]] += 1\r\n if len(multiset) == i:\r\n c += 1\r\n print(c)\r\n", "# cook your dish here\nfor _ in range(int(input())):\n a=[]\n n=int(input())\n for i in range(n):\n s=input()\n a.append(s)\n print((n*(n+1))//2)", "for __ in range(int(input())):\r\n n=int(input())\r\n for i in range(n):\r\n s=input()\r\n c=int(n*(n+1)/2)\r\n print(c) \r\n\r\n\r\n", "from sys import stdin as s\nt =int(s.readline())\nwhile t:\n\tt-=1\n\tn=int(s.readline())\n\tfor _ in range(n):\n\t\ta = s.readline()\n\tprint(n*(n+1)//2)", "t=int(input())\nfor i in range(t):\n n=int(input())\n swa=0\n suma=0\n for j in range(0,n):\n s=input()\n for k in range(0,n):\n if s[k]=='1':\n swa=swa+(abs(k-j))\n while n>=1:\n suma+=n \n n=n-1\n if swa==0:\n print(suma)\n else:\n print(suma-swa+1)", "T=int(input())\nfor i in range(0,T):\n lst2=[]\n N=int(input())\n for j in range(0,N):\n lst=input()\n lst2.append(lst)\n print(int(N*(N+1)/2))\n", "# cook your dish here\nT=int(input())\nfor i in range(0,T):\n lst2=[]\n N=int(input())\n for j in range(0,N):\n lst=input()\n lst2.append(lst)\n print(int(N*(N+1)/2))", "for _ in range(int(input())):\n n=int(input())\n for q in range(n):\n data=input()\n count=0\n ans=(n*(n+1))//2\n print(ans)\n # cook your dish here\n", "_ = int(input())\r\n\r\nwhile _ > 0:\r\n n = int(input())\r\n a = []\r\n for i in range(n):\r\n temp = input()\r\n a.append(temp)\r\n print((n*n+n)//2)\r\n \r\n _-=1", "for _ in range(int(input())):\r\n n=int(input())\r\n power=[]\r\n for i in range(n):\r\n power.append(input())\r\n d = True\r\n for i in range(n):\r\n if(power[i][i]!='1'):\r\n d = False\r\n break\r\n if(d):\r\n ans = (n*(n+1))//2\r\n print(ans)\r\n else:\r\n print(0)", "# cook your dish here\nimport math\nt=int(input())\nfor _ in range(t):\n n=int(input())\n l=[]\n for i in range(0,n):\n l1=input()\n l.append(l1)\n ind=[]\n count=n+1\n for i in range(0,n):\n x=list(l[i])\n y=x.index('1')\n ind.append(y)\n flag=0 \n for i in range(1,n):\n if ind[i]==ind[i-1]+1:\n flag=1\n else:\n flag=0\n break\n if flag==1:\n print(int((n*(n+1))/2))\n continue \n \n for i in range(2,n):\n for j in range(0,n):\n nl=[]\n if (j+i)>n:\n break\n s=sum(ind[j:j+i])\n f=min(ind[j:j+i])\n if (s-i*f)==(int(((i-1)*(i))/2)):\n count+=1\n print(count) \n \n \n \n"]
{"inputs": [["2", "2", "10", "01", "4", "1000", "0010", "0100", "0001"]], "outputs": [["3", "8"]]}
INTERVIEW
PYTHON3
CODECHEF
11,371
fc21fdf378f915ed8e5a52b8fdeee372
UNKNOWN
Nobody outside the cooking community knows that Chef is a big fan of Chefgram™ — a social network where chefs and cooks upload their secret kitchen photos. Recently Chef clicked a beautiful photo, which is represented using 10 pixels in a single row. Respecting Chefgram™'s boolean roots, every pixel is either white or black. Chefgram™ has N filters. Every filter is a string containing 10 symbols. Every symbol is either '+' or '-'. - A '+' at the ith position in a filter means that if Chef applies this filter to his photo, the ith pixel will be inverted: it becomes black if it was originally white, and vice versa. - A '-' at the ith position in a filter string means that if Chef applies this filter to his photo, the ith pixel will remain unchanged. Chef can apply as many filters as he wants from a list. He can pick any subset of filters and consequently apply them to a photo. For example: - Imagine that Chef has a photo "bbwwbbwwbb" (where 'b' stands for black and 'w' stands for white). - He applies filters "++--++--++", "-+-+-+-+-+". - Applying the first filter will transform his picture to "wwwwwwwwww". - Applying the second filter on the transformed picture will give Chef the picture "wbwbwbwbwb". Even if Chefgram™ has two or more identical filters, they are still considered different! Chef is extremely interested in knowing how many different subsets of all the Chefgram™ filters can he apply to transform his photo into 10 black pixels? -----Input----- - The first line of input contains a single integer T — the number of test cases. - First line of each test case contains a string S. Each symbol is either 'b' or 'w'. This is Chef's photo. - Second line of each test case contains a single integer N — the number of Chefgram™ filters. - Each of the next N lines contains a single string Fi, each symbol of which is either '+' or '-'. This string is the ith Chefgram™ filter. -----Output----- - For each test case, output a single line containing a single integer — answer to Chef's question modulo 109+7. -----Constraints----- - 1 ≤ T ≤ 5 - |S| = 10 - 1 ≤ N ≤ 10^5 - |Fi| = 10 -----Subtasks----- - Subtask 1: T ≤ 5; N ≤ 20; Points: 20 - Subtask 2: T ≤ 5; N ≤ 10^3; Points: 30 - Subtask 3: T ≤ 5; N ≤ 10^5; Points: 50 -----Example----- Input: 3 wwwwwwwwww 3 +-+-+-+-+- ---------- +--------- wbwbwbwbwb 3 +-+-+-+-+- +-+------- ----+-+-+- bbbbbbbbbb 2 ---------- ---------- Output: 0 2 4 -----Explanation----- Example case 1. There is no filter or combination of filters transforming the picture to whole black. Example case 2. Chef can either apply the first filter (and invert all whites) or apply the second and third filters in any order. Example case 3. Picture is already fully black, and we have two different identity filters. Chef can either apply the empty subset of filters, the first filter only, the second filter only, or both.
["import itertools\nimport numpy as np\nb = np.zeros((100001), dtype=np.int)\ndef power2(a):\n\tb[0] = 1\n\tif b[a] > 0:\n\t\treturn b[a]\n\telse:\n\t\tfor i in range(1,a+1):\n\n\t\t\tb[i] = b[i-1]*2\n\t\t\tif b[i] > (10**9+7):\n\t\t\t\tb[i] = b[i]%(10**9+7)\n\t\treturn b[a]\n\n\ndef __starting_point():\n\tt = eval(input())\n\tfor i in range(t):\n\t\ts = input()\n\t\tn = eval(input())\n\t\tf_list = []\n\t\tcount = 0\n\t\tfor j in range(n):\n\t\t\tf_list.append(input())\n\t\tinp = \"\"\n\t\tbin_list = []\n\t\tfor j in range(len(s)):\n\t\t\tif s[j] == 'w':\n\t\t\t\tinp = inp + '0'\n\t\t\telse:\n\t\t\t\tinp = inp + '1'\n\t\t#print inp\n\n\t\ta = np.zeros((1024), dtype=np.int)\n\t\tfor j in range(n):\n\t\t\ts1 = \"\"\n\t\t\tfor k in range(len(f_list[j])):\n\t\t\t\tif f_list[j][k]=='+':\n\t\t\t\t\ts1 = s1 + '1'\n\t\t\t\telse:\n\t\t\t\t\ts1 = s1 + '0'\n\t\t\tif n < 1024:\n\t\t\t\tbin_list.append(s1)\n\t\t\tp = int(s1,2)\n\t\t\tif a[p] == 0:\n\t\t\t\tcount = count+1\n\t\t\ta[p] = a[p]+1\n\t\tcount_2 = 0\n\n\n\t\t#print a\n\t\t\t\n\t\tif n < 1024:\n\t\t\tdp = np.zeros((n+1,1024) ,dtype=np.int64)\n\t\t\tdp[0,0] = 1\n\t\t\tfor j in range(1,n+1):\n\t\t\t\tfor k in range(1024):\n\t\t\t\t#print j-1\n\t\t\t\t#print k^int(bin_list[j-1],2)\n\n\t\t\t\t\tdp[j,k] = (dp[j-1][k] + dp[j-1][k^int(bin_list[j-1],2)])%(10**9+7)\n\n\t\t\t\t#print dp\n\t\t\tp = 1023 ^ int(inp,2)\n\n\t\t\tprint(dp[n,p]%(10**9+7))\n\n\t\telse:\n\n\t\t\tdp = np.zeros((1025,1024) ,dtype=np.int64)\n\t\t\tdp[0,0] = 1\n\t\t\tfor j in range(1,1025):\n\t\t\t\tcount_2 = count_2 + 1\n\t\t\t\tif a[j-1] > 0:\n\t\t\t\t\tl = power2(a[j-1]-1)\n\t\t\t\tfor k in range(1024):\n\t\t\t\t#print j-1\n\t\t\t\t#print k^int(bin_list[j-1],2)\n\t\t\t\t\tif a[j-1] > 0:\n\t\t\t\t\t\tdp[j,k] = (((dp[j-1][k] + dp[j-1][k^(j-1)])%(10**9+7)) * l )%(10**9+7)\n\t\t\t\t\telif dp[j-1][k] > 0:\n\t\t\t\t\t\tdp[j,k] = dp[j-1][k]\n\n\t\t\t\tif count_2 == count:\n\t\t\t\t\tbreak\n\t\t\t\t#print dp\n\t\t\tp = 1023 ^ int(inp,2)\n\n\t\t\tprint(dp[j,p]%(10**9+7))\n\n\n\n\n\n\n\n\n\n__starting_point()", "t = eval(input())\nMOD = 1000000007\ntemp = [0]*1025\nfor xx in range(0,t):\n inp = input()\n n = eval(input())\n ct = [0]*1025\n ans = [0]*1025\n while(n):\n s = input()\n m = 0\n j = 9\n c = 1\n while(j >= 0):\n if(s[j]=='+'):\n m |= c\n c <<= 1\n j -= 1\n ct[m] += 1\n n -= 1\n\n for i in range(0,1024):\n m = i\n c = ct[i]\n while(c):\n for j in range(0,1024):\n temp[j] = ans[m^j]\n temp[m] += 1\n for j in range(0,1024):\n ans[j] += temp[j]\n if(ans[j] > 100000000000000000):\n ans[j] %= MOD\n c -= 1\n \n ans[0] += 1\n s = []\n for i in range(0,10):\n if(inp[i] == 'b'):\n s.append('-')\n else:\n s.append('+')\n m = 0\n j = 9\n c = 1\n while(j >= 0):\n if(s[j]=='+'):\n m |= c\n c <<= 1\n j -= 1\n print(ans[m]%MOD)\n", "t = eval(input())\nMOD = 1000000007\ntemp = [0]*1025\nfor xx in range(0,t):\n inp = input()\n n = eval(input())\n ct = [0]*1025\n ans = [0]*1025\n while(n):\n s = input()\n m = 0\n j = 9\n c = 1\n while(j >= 0):\n if(s[j]=='+'):\n m |= c\n c <<= 1\n j -= 1\n ct[m] += 1\n n -= 1\n\n for i in range(0,1024):\n m = i\n c = ct[i]\n while(c):\n for j in range(0,1024):\n temp[j] = ans[m^j]\n temp[m] += 1\n for j in range(0,1024):\n ans[j] += temp[j]\n if(ans[j] > 100000000000000000):\n ans[j] %= MOD\n c -= 1\n \n ans[0] += 1\n s = []\n for i in range(0,10):\n if(inp[i] == 'b'):\n s.append('-')\n else:\n s.append('+')\n m = 0\n j = 9\n c = 1\n while(j >= 0):\n if(s[j]=='+'):\n m |= c\n c <<= 1\n j -= 1\n print(ans[m])\n", "from collections import defaultdict\nimport operator\n\nfor i in range(int(input())):\n s=input()\n s=s.replace('b','1')\n s=s.replace('w','0')\n compare=int(s,2)\n\n n=int(input())\n List=[]\n for i in range(n):\n bin=input()\n bin=bin.replace('+','1')\n bin=bin.replace('-','0')\n num=int(bin,2)\n List.append(num)\n \n length=int(2**n)\n count=int(0)\n i=j=int(0)\n for i in range(length):\n x=0;\n for j in range(0,n):\n if i&(1<<j)>0:\n x=operator.xor(x,List[j])\n \n if(operator.xor(x,compare)==1023):\n count+=1\n \n print(count)\n \n \n \n \n \n \n \n \n \n ", "from collections import defaultdict\nimport operator\n\nfor i in range(int(input())):\n s=input()\n s=s.replace('b','1')\n s=s.replace('w','0')\n compare=int(s,2)\n\n n=int(input())\n List=[]\n for i in range(n):\n bin=input()\n bin=bin.replace('+','1')\n bin=bin.replace('-','0')\n num=int(bin,2)\n List.append(num)\n \n length=2**n\n count=0\n for i in range(length):\n x=0;\n for j in range(0,n):\n if i&(1<<j)>0:\n x=operator.xor(x,List[j])\n \n if(operator.xor(x,compare)==1023):\n count+=1\n \n print(count)\n \n \n \n \n \n \n \n \n \n ", "import itertools\nimport numpy as np\nb = np.zeros((1024), dtype=np.int)\ndef power2(a):\n\tb[0] = 1\n\tif b[a] > 0:\n\t\treturn b[a]\n\telse:\n\t\tfor i in range(1,a+1):\n\n\t\t\tb[i] = b[i-1]*2\n\t\t\tif b[i] > (10**9+7):\n\t\t\t\tb[i] = b[i]%(10**9+7)\n\t\treturn b[a]\n\n# def countBits(p1):\n# \tcount = 0\n# \tp2 = p1\n# \twhile p2:\n# \t\tp2 = p2 & (p2-1)\n# \t\tcount = count + 1\n# \tp = '{0:b}'.format(p1)\n# \tif count == len(p):\n# \t\treturn True\n# \telse:\n# \t\treturn False\n\n\ndef __starting_point():\n\tt = eval(input())\n\tfor i in range(t):\n\t\ts = input()\n\t\tn = eval(input())\n\t\tf_list = []\n\t\tcount = 0\n\t\tfor j in range(n):\n\t\t\tf_list.append(input())\n\t\tinp = \"\"\n\t\tbin_list = []\n\t\tfor j in range(len(s)):\n\t\t\tif s[j] == 'w':\n\t\t\t\tinp = inp + '0'\n\t\t\telse:\n\t\t\t\tinp = inp + '1'\n\t\t#print inp\n\n\t\ta = np.zeros((1024), dtype=np.int)\n\t\tfor j in range(n):\n\t\t\ts1 = \"\"\n\t\t\tfor k in range(len(f_list[j])):\n\t\t\t\tif f_list[j][k]=='+':\n\t\t\t\t\ts1 = s1 + '1'\n\t\t\t\telse:\n\t\t\t\t\ts1 = s1 + '0'\n\t\t\tif n < 1024:\n\t\t\t\tbin_list.append(s1)\n\t\t\tp = int(s1,2)\n\t\t\tif a[p] == 0:\n\t\t\t\tcount = count+1\n\t\t\ta[p] = a[p]+1\n\t\tcount_2 = 0\n\n\n\t\t#print a\n\t\t\t\n\t\t#print bin_list\n\t\t# lst = [list(k) for k in itertools.product([0,1], repeat=n)]\n\t\t# #print lst\n\t\t# count = 0\n\t\t# for j in xrange(len(lst)):\n\t\t# \tp = \"0\"*n\n\t\t# \tfor k in xrange(len(lst[j])):\n\t\t# \t\tif lst[j][k]==1:\n\t\t# \t\t\tp1 = int(p,2) ^ int(bin_list[k],2)\n\t\t# \t\t\tp = '{0:b}'.format(p1)\n\t\t# \t\t\t#print p\n\t\t# \tp2 = int(p,2) ^ int(inp,2)\n\t\t# \t#print '{0:b}'.format(p2)+\"#\"\n\t\t# \tif p2 == (2**len(s)) - 1:\n\t\t# \t\tcount = (count+1)%(10**9+7)\n\t\t# print count%(10**9 + 7)\n\t\tif n < 1024:\n\t\t\tdp = np.zeros((n+1,1024) ,dtype=np.int64)\n\t\t\tdp[0,0] = 1\n\t\t\tfor j in range(1,n+1):\n\t\t\t\tfor k in range(1024):\n\t\t\t\t#print j-1\n\t\t\t\t#print k^int(bin_list[j-1],2)\n\n\t\t\t\t\tdp[j,k] = (dp[j-1][k] + dp[j-1][k^int(bin_list[j-1],2)])%(10**9+7)\n\n\t\t\t\t#print dp\n\t\t\tp = 1023 ^ int(inp,2)\n\n\t\t\tprint(dp[n,p]%(10**9+7))\n\n\t\telse:\n\n\t\t\tdp = np.zeros((1025,1024) ,dtype=np.int64)\n\t\t\tdp[0,0] = 1\n\t\t\tfor j in range(1,1025):\n\t\t\t\tcount_2 = count_2 + 1\n\t\t\t\tl = power2(a[j-1]-1)\n\t\t\t\tfor k in range(1024):\n\t\t\t\t#print j-1\n\t\t\t\t#print k^int(bin_list[j-1],2)\n\t\t\t\t\tif a[j-1] > 0:\n\t\t\t\t\t\tdp[j,k] = (((dp[j-1][k] + dp[j-1][k^(j-1)])%(10**9+7)) * l )%(10**9+7)\n\t\t\t\t\telif dp[j-1][k] > 0:\n\t\t\t\t\t\tdp[j,k] = dp[j-1][k]\n\n\t\t\t\tif count_2 == count:\n\t\t\t\t\tbreak\n\t\t\t\t#print dp\n\t\t\tp = 1023 ^ int(inp,2)\n\n\t\t\tprint(dp[j,p]%(10**9+7))\n\n\n\n\n\n\n\n\n\n__starting_point()", "import itertools\nimport numpy as np\nb = np.zeros((1024), dtype=np.int)\ndef power2(a):\n\tb[0] = 1\n\tif b[a] > 0:\n\t\treturn b[a]\n\telse:\n\t\tfor i in range(1,a+1):\n\n\t\t\tb[i] = b[i-1]*2\n\t\t\tif b[i] > (10**9+7):\n\t\t\t\tb[i] = b[i]%(10**9+7)\n\t\treturn b[a]\n\n# def countBits(p1):\n# \tcount = 0\n# \tp2 = p1\n# \twhile p2:\n# \t\tp2 = p2 & (p2-1)\n# \t\tcount = count + 1\n# \tp = '{0:b}'.format(p1)\n# \tif count == len(p):\n# \t\treturn True\n# \telse:\n# \t\treturn False\n\n\ndef __starting_point():\n\tt = eval(input())\n\tfor i in range(t):\n\t\ts = input()\n\t\tn = eval(input())\n\t\tf_list = []\n\t\tcount = 0\n\t\tfor j in range(n):\n\t\t\tf_list.append(input())\n\t\tinp = \"\"\n\t\tbin_list = []\n\t\tfor j in range(len(s)):\n\t\t\tif s[j] == 'w':\n\t\t\t\tinp = inp + '0'\n\t\t\telse:\n\t\t\t\tinp = inp + '1'\n\t\t#print inp\n\n\t\ta = np.zeros((1024), dtype=np.int)\n\t\tfor j in range(n):\n\t\t\ts1 = \"\"\n\t\t\tfor k in range(len(f_list[j])):\n\t\t\t\tif f_list[j][k]=='+':\n\t\t\t\t\ts1 = s1 + '1'\n\t\t\t\telse:\n\t\t\t\t\ts1 = s1 + '0'\n\t\t\tif n < 1024:\n\t\t\t\tbin_list.append(s1)\n\t\t\tp = int(s1,2)\n\t\t\tif a[p] == 0:\n\t\t\t\tcount = count+1\n\t\t\ta[p] = a[p]+1\n\t\tcount_2 = 0\n\n\n\t\t#print a\n\t\t\t\n\t\t#print bin_list\n\t\t# lst = [list(k) for k in itertools.product([0,1], repeat=n)]\n\t\t# #print lst\n\t\t# count = 0\n\t\t# for j in xrange(len(lst)):\n\t\t# \tp = \"0\"*n\n\t\t# \tfor k in xrange(len(lst[j])):\n\t\t# \t\tif lst[j][k]==1:\n\t\t# \t\t\tp1 = int(p,2) ^ int(bin_list[k],2)\n\t\t# \t\t\tp = '{0:b}'.format(p1)\n\t\t# \t\t\t#print p\n\t\t# \tp2 = int(p,2) ^ int(inp,2)\n\t\t# \t#print '{0:b}'.format(p2)+\"#\"\n\t\t# \tif p2 == (2**len(s)) - 1:\n\t\t# \t\tcount = (count+1)%(10**9+7)\n\t\t# print count%(10**9 + 7)\n\t\tif n < 1024:\n\t\t\tdp = np.zeros((n+1,1024) ,dtype=np.int64)\n\t\t\tdp[0,0] = 1\n\t\t\tfor j in range(1,n+1):\n\t\t\t\tfor k in range(1024):\n\t\t\t\t#print j-1\n\t\t\t\t#print k^int(bin_list[j-1],2)\n\n\t\t\t\t\tdp[j,k] = (dp[j-1][k] + dp[j-1][k^int(bin_list[j-1],2)])%(10**9+7)\n\n\t\t\t\t#print dp\n\t\t\tp = 1023 ^ int(inp,2)\n\n\t\t\tprint(dp[n,p]%(10**9+7))\n\n\t\telse:\n\n\t\t\tdp = np.zeros((1025,1024) ,dtype=np.int64)\n\t\t\tdp[0,0] = 1\n\t\t\tfor j in range(1,1025):\n\t\t\t\tcount_2 = count_2 + 1\n\t\t\t\tfor k in range(1024):\n\t\t\t\t#print j-1\n\t\t\t\t#print k^int(bin_list[j-1],2)\n\t\t\t\t\tif a[j-1] > 0:\n\t\t\t\t\t\tdp[j,k] = (((dp[j-1][k] + dp[j-1][k^(j-1)])%(10**9+7)) * power2(a[j-1]-1))%(10**9+7)\n\t\t\t\t\telif dp[j-1][k] > 0:\n\t\t\t\t\t\tdp[j,k] = dp[j-1][k]\n\n\t\t\t\tif count_2 == count:\n\t\t\t\t\tbreak\n\t\t\t\t#print dp\n\t\t\tp = 1023 ^ int(inp,2)\n\n\t\t\tprint(dp[j,p]%(10**9+7))\n\n\n\n\n\n\n\n\n\n__starting_point()", "import itertools\nimport numpy as np\n\ndef power2(a):\n\tsum_1 = 1\n\tfor i in range(1,a+1):\n\t\tsum_1 = sum_1 * 2\n\t\tif sum_1 > 10**9+7:\n\t\t\tsum_1 = sum_1 % (10**9+7)\n\treturn sum_1\n\n# def countBits(p1):\n# \tcount = 0\n# \tp2 = p1\n# \twhile p2:\n# \t\tp2 = p2 & (p2-1)\n# \t\tcount = count + 1\n# \tp = '{0:b}'.format(p1)\n# \tif count == len(p):\n# \t\treturn True\n# \telse:\n# \t\treturn False\n\n\ndef __starting_point():\n\tt = eval(input())\n\tfor i in range(t):\n\t\ts = input()\n\t\tn = eval(input())\n\t\tf_list = []\n\t\tcount = 0\n\t\tfor j in range(n):\n\t\t\tf_list.append(input())\n\t\tinp = \"\"\n\t\tbin_list = []\n\t\tfor j in range(len(s)):\n\t\t\tif s[j] == 'w':\n\t\t\t\tinp = inp + '0'\n\t\t\telse:\n\t\t\t\tinp = inp + '1'\n\t\t#print inp\n\n\t\ta = np.zeros((1024), dtype=np.int)\n\t\tfor j in range(n):\n\t\t\ts1 = \"\"\n\t\t\tfor k in range(len(f_list[j])):\n\t\t\t\tif f_list[j][k]=='+':\n\t\t\t\t\ts1 = s1 + '1'\n\t\t\t\telse:\n\t\t\t\t\ts1 = s1 + '0'\n\t\t\tif n < 1024:\n\t\t\t\tbin_list.append(s1)\n\t\t\tp = int(s1,2)\n\t\t\tif a[p] == 0:\n\t\t\t\tcount = count+1\n\t\t\ta[p] = a[p]+1\n\t\tcount_2 = 0\n\n\n\t\t#print a\n\t\t\t\n\t\t#print bin_list\n\t\t# lst = [list(k) for k in itertools.product([0,1], repeat=n)]\n\t\t# #print lst\n\t\t# count = 0\n\t\t# for j in xrange(len(lst)):\n\t\t# \tp = \"0\"*n\n\t\t# \tfor k in xrange(len(lst[j])):\n\t\t# \t\tif lst[j][k]==1:\n\t\t# \t\t\tp1 = int(p,2) ^ int(bin_list[k],2)\n\t\t# \t\t\tp = '{0:b}'.format(p1)\n\t\t# \t\t\t#print p\n\t\t# \tp2 = int(p,2) ^ int(inp,2)\n\t\t# \t#print '{0:b}'.format(p2)+\"#\"\n\t\t# \tif p2 == (2**len(s)) - 1:\n\t\t# \t\tcount = (count+1)%(10**9+7)\n\t\t# print count%(10**9 + 7)\n\t\tif n < 1024:\n\t\t\tdp = np.zeros((n+1,1024) ,dtype=np.int64)\n\t\t\tdp[0,0] = 1\n\t\t\tfor j in range(1,n+1):\n\t\t\t\tfor k in range(1024):\n\t\t\t\t#print j-1\n\t\t\t\t#print k^int(bin_list[j-1],2)\n\n\t\t\t\t\tdp[j,k] = (dp[j-1][k] + dp[j-1][k^int(bin_list[j-1],2)])%(10**9+7)\n\n\t\t\t\t#print dp\n\t\t\tp = 1023 ^ int(inp,2)\n\n\t\t\tprint(dp[n,p]%(10**9+7))\n\n\t\telse:\n\n\t\t\tdp = np.zeros((1025,1024) ,dtype=np.int64)\n\t\t\tdp[0,0] = 1\n\t\t\tfor j in range(1,1025):\n\t\t\t\tcount_2 = count_2 + 1\n\t\t\t\tfor k in range(1024):\n\t\t\t\t#print j-1\n\t\t\t\t#print k^int(bin_list[j-1],2)\n\t\t\t\t\tif a[j-1] > 0:\n\t\t\t\t\t\tdp[j,k] = (((dp[j-1][k] + dp[j-1][k^(j-1)])%(10**9+7)) * power2(a[j-1]-1))%(10**9+7)\n\t\t\t\t\telif dp[j-1][k] > 0:\n\t\t\t\t\t\tdp[j,k] = dp[j-1][k]\n\n\t\t\t\tif count_2 == count:\n\t\t\t\t\tbreak\n\t\t\t\t#print dp\n\t\t\tp = 1023 ^ int(inp,2)\n\n\t\t\tprint(dp[j,p]%(10**9+7))\n\n\n\n\n\n\n\n\n\n__starting_point()", "import itertools\nimport numpy as np\n\ndef power2(a):\n\tsum_1 = 1\n\tfor i in range(1,a+1):\n\t\tsum_1 = sum_1 * 2\n\t\tif sum_1 > 10**9+7:\n\t\t\tsum_1 = sum_1 % (10**9+7)\n\treturn sum_1\n\n# def countBits(p1):\n# \tcount = 0\n# \tp2 = p1\n# \twhile p2:\n# \t\tp2 = p2 & (p2-1)\n# \t\tcount = count + 1\n# \tp = '{0:b}'.format(p1)\n# \tif count == len(p):\n# \t\treturn True\n# \telse:\n# \t\treturn False\n\n\ndef __starting_point():\n\tt = eval(input())\n\tfor i in range(t):\n\t\ts = input()\n\t\tn = eval(input())\n\t\tf_list = []\n\t\tfor j in range(n):\n\t\t\tf_list.append(input())\n\t\tinp = \"\"\n\t\tbin_list = []\n\t\tfor j in range(len(s)):\n\t\t\tif s[j] == 'w':\n\t\t\t\tinp = inp + '0'\n\t\t\telse:\n\t\t\t\tinp = inp + '1'\n\t\t#print inp\n\n\t\ta = np.zeros((1024), dtype=np.int)\n\t\tfor j in range(n):\n\t\t\ts1 = \"\"\n\t\t\tfor k in range(len(f_list[j])):\n\t\t\t\tif f_list[j][k]=='+':\n\t\t\t\t\ts1 = s1 + '1'\n\t\t\t\telse:\n\t\t\t\t\ts1 = s1 + '0'\n\t\t\tif n < 1024:\n\t\t\t\tbin_list.append(s1)\n\t\t\tp = int(s1,2)\n\t\t\ta[p] = a[p]+1\n\n\n\t\t#print a\n\t\t\t\n\t\t#print bin_list\n\t\t# lst = [list(k) for k in itertools.product([0,1], repeat=n)]\n\t\t# #print lst\n\t\t# count = 0\n\t\t# for j in xrange(len(lst)):\n\t\t# \tp = \"0\"*n\n\t\t# \tfor k in xrange(len(lst[j])):\n\t\t# \t\tif lst[j][k]==1:\n\t\t# \t\t\tp1 = int(p,2) ^ int(bin_list[k],2)\n\t\t# \t\t\tp = '{0:b}'.format(p1)\n\t\t# \t\t\t#print p\n\t\t# \tp2 = int(p,2) ^ int(inp,2)\n\t\t# \t#print '{0:b}'.format(p2)+\"#\"\n\t\t# \tif p2 == (2**len(s)) - 1:\n\t\t# \t\tcount = (count+1)%(10**9+7)\n\t\t# print count%(10**9 + 7)\n\t\tif n < 1024:\n\t\t\tdp = np.zeros((n+1,1024) ,dtype=np.int64)\n\t\t\tdp[0,0] = 1\n\t\t\tfor j in range(1,n+1):\n\t\t\t\tfor k in range(1024):\n\t\t\t\t#print j-1\n\t\t\t\t#print k^int(bin_list[j-1],2)\n\n\t\t\t\t\tdp[j,k] = (dp[j-1][k] + dp[j-1][k^int(bin_list[j-1],2)])%(10**9+7)\n\n\t\t\t\t#print dp\n\t\t\tp = 1023 ^ int(inp,2)\n\n\t\t\tprint(dp[n,p]%(10**9+7))\n\n\t\telse:\n\n\t\t\tdp = np.zeros((1025,1024) ,dtype=np.int64)\n\t\t\tdp[0,0] = 1\n\t\t\tfor j in range(1,1025):\n\t\t\t\tfor k in range(1024):\n\t\t\t\t#print j-1\n\t\t\t\t#print k^int(bin_list[j-1],2)\n\t\t\t\t\tif a[j-1] > 0:\n\t\t\t\t\t\tdp[j,k] = (((dp[j-1][k] + dp[j-1][k^(j-1)])%(10**9+7)) * power2(a[j-1]-1))%(10**9+7)\n\t\t\t\t\telif dp[j-1][k] > 0:\n\t\t\t\t\t\tdp[j,k] = dp[j-1][k]\n\n\t\t\t\t#print dp\n\t\t\tp = 1023 ^ int(inp,2)\n\n\t\t\tprint(dp[1024,p]%(10**9+7))\n\n\n\n\n\n\n\n\n\n__starting_point()", "import itertools\nimport numpy as np\n\ndef power2(a):\n\tsum_1 = 1\n\tfor i in range(1,a+1):\n\t\tsum_1 = sum_1 * 2\n\t\tif sum_1 > 10**9+7:\n\t\t\tsum_1 = sum_1 % (10**9+7)\n\treturn sum_1\n\n# def countBits(p1):\n# \tcount = 0\n# \tp2 = p1\n# \twhile p2:\n# \t\tp2 = p2 & (p2-1)\n# \t\tcount = count + 1\n# \tp = '{0:b}'.format(p1)\n# \tif count == len(p):\n# \t\treturn True\n# \telse:\n# \t\treturn False\n\n\ndef __starting_point():\n\tt = eval(input())\n\tfor i in range(t):\n\t\ts = input()\n\t\tn = eval(input())\n\t\tf_list = []\n\t\tfor j in range(n):\n\t\t\tf_list.append(input())\n\t\tinp = \"\"\n\t\tbin_list = []\n\t\tfor j in range(len(s)):\n\t\t\tif s[j] == 'w':\n\t\t\t\tinp = inp + '0'\n\t\t\telse:\n\t\t\t\tinp = inp + '1'\n\t\t#print inp\n\n\t\ta = np.zeros((1024), dtype=np.int)\n\t\tfor j in range(n):\n\t\t\ts1 = \"\"\n\t\t\tfor k in range(len(f_list[j])):\n\t\t\t\tif f_list[j][k]=='+':\n\t\t\t\t\ts1 = s1 + '1'\n\t\t\t\telse:\n\t\t\t\t\ts1 = s1 + '0'\n\t\t\tif n < 1024:\n\t\t\t\tbin_list.append(s1)\n\t\t\tp = int(s1,2)\n\t\t\ta[p] = a[p]+1\n\n\n\t\t#print a\n\t\t\t\n\t\t#print bin_list\n\t\t# lst = [list(k) for k in itertools.product([0,1], repeat=n)]\n\t\t# #print lst\n\t\t# count = 0\n\t\t# for j in xrange(len(lst)):\n\t\t# \tp = \"0\"*n\n\t\t# \tfor k in xrange(len(lst[j])):\n\t\t# \t\tif lst[j][k]==1:\n\t\t# \t\t\tp1 = int(p,2) ^ int(bin_list[k],2)\n\t\t# \t\t\tp = '{0:b}'.format(p1)\n\t\t# \t\t\t#print p\n\t\t# \tp2 = int(p,2) ^ int(inp,2)\n\t\t# \t#print '{0:b}'.format(p2)+\"#\"\n\t\t# \tif p2 == (2**len(s)) - 1:\n\t\t# \t\tcount = (count+1)%(10**9+7)\n\t\t# print count%(10**9 + 7)\n\t\tif n < 1024:\n\t\t\tdp = np.zeros((n+1,1024) ,dtype=np.int)\n\t\t\tdp[0,0] = 1\n\t\t\tfor j in range(1,n+1):\n\t\t\t\tfor k in range(1024):\n\t\t\t\t#print j-1\n\t\t\t\t#print k^int(bin_list[j-1],2)\n\n\t\t\t\t\tdp[j,k] = (dp[j-1][k] + dp[j-1][k^int(bin_list[j-1],2)])%(10**9+7)\n\n\t\t\t\t#print dp\n\t\t\tp = 1023 ^ int(inp,2)\n\n\t\t\tprint(dp[n,p]%(10**9+7))\n\n\t\telse:\n\n\t\t\tdp = np.zeros((1025,1024) ,dtype=np.int)\n\t\t\tdp[0,0] = 1\n\t\t\tfor j in range(1,1025):\n\t\t\t\tfor k in range(1024):\n\t\t\t\t#print j-1\n\t\t\t\t#print k^int(bin_list[j-1],2)\n\t\t\t\t\tif a[j-1] > 0:\n\t\t\t\t\t\tdp[j,k] = (((dp[j-1][k] + dp[j-1][k^(j-1)])%(10**9+7)) * power2(a[j-1]-1))%(10**9+7)\n\t\t\t\t\telif dp[j-1][k] > 0:\n\t\t\t\t\t\tdp[j,k] = dp[j-1][k]\n\n\t\t\t\t#print dp\n\t\t\tp = 1023 ^ int(inp,2)\n\n\t\t\tprint(dp[1024,p]%(10**9+7))\n\n\n\n\n\n\n\n\n\n\n__starting_point()", "import itertools\nimport numpy as np\n\n# def countBits(p1):\n# \tcount = 0\n# \tp2 = p1\n# \twhile p2:\n# \t\tp2 = p2 & (p2-1)\n# \t\tcount = count + 1\n# \tp = '{0:b}'.format(p1)\n# \tif count == len(p):\n# \t\treturn True\n# \telse:\n# \t\treturn False\n\n\ndef __starting_point():\n\tt = eval(input())\n\tfor i in range(t):\n\t\ts = input()\n\t\tn = eval(input())\n\t\tf_list = []\n\t\tfor j in range(n):\n\t\t\tf_list.append(input())\n\t\tinp = \"\"\n\t\tbin_list = []\n\t\tfor j in range(len(s)):\n\t\t\tif s[j] == 'w':\n\t\t\t\tinp = inp + '0'\n\t\t\telse:\n\t\t\t\tinp = inp + '1'\n\t\t#print inp\n\n\t\ta = np.zeros((1024), dtype=np.int)\n\t\tfor j in range(n):\n\t\t\ts1 = \"\"\n\t\t\tfor k in range(len(f_list[j])):\n\t\t\t\tif f_list[j][k]=='+':\n\t\t\t\t\ts1 = s1 + '1'\n\t\t\t\telse:\n\t\t\t\t\ts1 = s1 + '0'\n\n\t\t\tbin_list.append(s1)\n\t\t\tp = int(s1,2)\n\t\t\ta[p] = a[p]+1\n\t\t#print a\n\t\t\t\n\t\t#print bin_list\n\t\t# lst = [list(k) for k in itertools.product([0,1], repeat=n)]\n\t\t# #print lst\n\t\t# count = 0\n\t\t# for j in xrange(len(lst)):\n\t\t# \tp = \"0\"*n\n\t\t# \tfor k in xrange(len(lst[j])):\n\t\t# \t\tif lst[j][k]==1:\n\t\t# \t\t\tp1 = int(p,2) ^ int(bin_list[k],2)\n\t\t# \t\t\tp = '{0:b}'.format(p1)\n\t\t# \t\t\t#print p\n\t\t# \tp2 = int(p,2) ^ int(inp,2)\n\t\t# \t#print '{0:b}'.format(p2)+\"#\"\n\t\t# \tif p2 == (2**len(s)) - 1:\n\t\t# \t\tcount = (count+1)%(10**9+7)\n\t\t# print count%(10**9 + 7)\n\t\tif n < 1024:\n\t\t\tdp = np.zeros((n+1,1024) ,dtype=np.int)\n\t\t\tdp[0,0] = 1\n\t\t\tfor j in range(1,n+1):\n\t\t\t\tfor k in range(1024):\n\t\t\t\t#print j-1\n\t\t\t\t#print k^int(bin_list[j-1],2)\n\n\t\t\t\t\tdp[j,k] = (dp[j-1][k] + dp[j-1][k^int(bin_list[j-1],2)])%(10**9+7)\n\n\t\t\t\t#print dp\n\t\t\tp = 1023 ^ int(inp,2)\n\n\t\t\tprint(dp[n,p]%(10**9+7))\n\n\t\telse:\n\n\t\t\tdp = np.zeros((1025,1024) ,dtype=np.int)\n\t\t\tdp[0,0] = 1\n\t\t\tfor j in range(1,1025):\n\t\t\t\tfor k in range(1024):\n\t\t\t\t#print j-1\n\t\t\t\t#print k^int(bin_list[j-1],2)\n\t\t\t\t\tif a[j-1] > 0:\n\t\t\t\t\t\tdp[j,k] = ((dp[j-1][k] + dp[j-1][k^(j-1)]) * (2**(a[j-1] - 1)))%(10**9+7)\n\t\t\t\t\telse:\n\t\t\t\t\t\tdp[j,k] = dp[j-1][k]\n\n\t\t\t\t#print dp\n\t\t\tp = 1023 ^ int(inp,2)\n\n\t\t\tprint(dp[1024,p]%(10**9+7))\n\n\n\n\n\n\n\n\n\n\n__starting_point()", "import itertools\nimport numpy as np\n\n# def countBits(p1):\n# \tcount = 0\n# \tp2 = p1\n# \twhile p2:\n# \t\tp2 = p2 & (p2-1)\n# \t\tcount = count + 1\n# \tp = '{0:b}'.format(p1)\n# \tif count == len(p):\n# \t\treturn True\n# \telse:\n# \t\treturn False\n\n\ndef __starting_point():\n\tt = eval(input())\n\tfor i in range(t):\n\t\ts = input()\n\t\tn = eval(input())\n\t\tf_list = []\n\t\tfor j in range(n):\n\t\t\tf_list.append(input())\n\t\tinp = \"\"\n\t\tbin_list = []\n\t\tfor j in range(len(s)):\n\t\t\tif s[j] == 'w':\n\t\t\t\tinp = inp + '0'\n\t\t\telse:\n\t\t\t\tinp = inp + '1'\n\t\t#print inp\n\n\t\ta = np.zeros((1024), dtype=np.int)\n\t\tfor j in range(n):\n\t\t\ts1 = \"\"\n\t\t\tfor k in range(len(f_list[j])):\n\t\t\t\tif f_list[j][k]=='+':\n\t\t\t\t\ts1 = s1 + '1'\n\t\t\t\telse:\n\t\t\t\t\ts1 = s1 + '0'\n\n\t\t\tbin_list.append(s1)\n\t\t\tp = int(s1,2)\n\t\t\ta[p] = a[p]+1\n\t\t#print a\n\t\t\t\n\t\t#print bin_list\n\t\t# lst = [list(k) for k in itertools.product([0,1], repeat=n)]\n\t\t# #print lst\n\t\t# count = 0\n\t\t# for j in xrange(len(lst)):\n\t\t# \tp = \"0\"*n\n\t\t# \tfor k in xrange(len(lst[j])):\n\t\t# \t\tif lst[j][k]==1:\n\t\t# \t\t\tp1 = int(p,2) ^ int(bin_list[k],2)\n\t\t# \t\t\tp = '{0:b}'.format(p1)\n\t\t# \t\t\t#print p\n\t\t# \tp2 = int(p,2) ^ int(inp,2)\n\t\t# \t#print '{0:b}'.format(p2)+\"#\"\n\t\t# \tif p2 == (2**len(s)) - 1:\n\t\t# \t\tcount = (count+1)%(10**9+7)\n\t\t# print count%(10**9 + 7)\n\t\tif n < 1024:\n\t\t\tdp = np.zeros((n+1,1024) ,dtype=np.int)\n\t\t\tdp[0,0] = 1\n\t\t\tfor j in range(1,n+1):\n\t\t\t\tfor k in range(1024):\n\t\t\t\t#print j-1\n\t\t\t\t#print k^int(bin_list[j-1],2)\n\n\t\t\t\t\tdp[j,k] = (dp[j-1][k] + dp[j-1][k^int(bin_list[j-1],2)])%(10**9+7)\n\n\t\t\t\t#print dp\n\t\t\tp = 1023 ^ int(inp,2)\n\n\t\t\tprint(dp[n,p]%(10**9+7))\n\n\t\telse:\n\n\t\t\tdp = np.zeros((1025,1024) ,dtype=np.int)\n\t\t\tdp[0,0] = 1\n\t\t\tfor j in range(1,1025):\n\t\t\t\tfor k in range(1024):\n\t\t\t\t#print j-1\n\t\t\t\t#print k^int(bin_list[j-1],2)\n\t\t\t\t\tif a[j-1] > 0:\n\t\t\t\t\t\tdp[j,k] = (((dp[j-1][k] + dp[j-1][k^(j-1)])%(10**9+7)) * (2**(a[j-1] - 1)))%(10**9+7)\n\t\t\t\t\telse:\n\t\t\t\t\t\tdp[j,k] = dp[j-1][k]\n\n\t\t\t\t#print dp\n\t\t\tp = 1023 ^ int(inp,2)\n\n\t\t\tprint(dp[1024,p]%(10**9+7))\n\n\n\n\n\n\n\n\n\n\n__starting_point()", "import itertools\nimport numpy as np\n\n# def countBits(p1):\n# \tcount = 0\n# \tp2 = p1\n# \twhile p2:\n# \t\tp2 = p2 & (p2-1)\n# \t\tcount = count + 1\n# \tp = '{0:b}'.format(p1)\n# \tif count == len(p):\n# \t\treturn True\n# \telse:\n# \t\treturn False\n\n\ndef __starting_point():\n\tt = eval(input())\n\tfor i in range(t):\n\t\ts = input()\n\t\tn = eval(input())\n\t\tf_list = []\n\t\tfor j in range(n):\n\t\t\tf_list.append(input())\n\t\tinp = \"\"\n\t\tbin_list = []\n\t\tfor j in range(len(s)):\n\t\t\tif s[j] == 'w':\n\t\t\t\tinp = inp + '0'\n\t\t\telse:\n\t\t\t\tinp = inp + '1'\n\t\t#print inp\n\t\tfor j in range(n):\n\t\t\ts1 = \"\"\n\t\t\tfor k in range(len(f_list[j])):\n\t\t\t\tif f_list[j][k]=='+':\n\t\t\t\t\ts1 = s1 + '1'\n\t\t\t\telse:\n\t\t\t\t\ts1 = s1 + '0'\n\t\t\tbin_list.append(s1)\n\t\t#print bin_list\n\t\t# lst = [list(k) for k in itertools.product([0,1], repeat=n)]\n\t\t# #print lst\n\t\t# count = 0\n\t\t# for j in xrange(len(lst)):\n\t\t# \tp = \"0\"*n\n\t\t# \tfor k in xrange(len(lst[j])):\n\t\t# \t\tif lst[j][k]==1:\n\t\t# \t\t\tp1 = int(p,2) ^ int(bin_list[k],2)\n\t\t# \t\t\tp = '{0:b}'.format(p1)\n\t\t# \t\t\t#print p\n\t\t# \tp2 = int(p,2) ^ int(inp,2)\n\t\t# \t#print '{0:b}'.format(p2)+\"#\"\n\t\t# \tif p2 == (2**len(s)) - 1:\n\t\t# \t\tcount = (count+1)%(10**9+7)\n\t\t# print count%(10**9 + 7)\n\n\t\tdp = np.zeros((n+1,1024) ,dtype=np.int)\n\t\tdp[0,0] = 1\n\t\tfor j in range(1,n+1):\n\t\t\tfor k in range(1024):\n\t\t\t\t#print j-1\n\t\t\t\t#print k^int(bin_list[j-1],2)\n\t\t\t\tdp[j,k] = (dp[j-1][k] + dp[j-1][k^int(bin_list[j-1],2)])%(10**9+7)\n\n\t\tp = 1023 ^ int(inp,2)\n\n\t\tprint(dp[n][p]%(10**9+7))\n\n\n\n\n\n\n\n\n\n\n__starting_point()", "def ct(string):\n\ti = 0\n\tnum = 0\n\twhile( i < 10):\n\t\tnum *= 2\n\t\tif(string[i] == 'w'):\n\t\t\tnum += 1\n\t\ti += 1\n\treturn num\n\t\ndef convert(string):\n\ti = 0\n\tnum = 0\n\twhile( i < 10):\n\t\tnum *= 2\n\t\tif(string[i] == '+'):\n\t\t\tnum += 1\n\t\ti += 1\n\treturn num\n\nt = int(input())\nwhile(t > 0):\n\tpic = input()\n\tm = ct(pic)\n\ttab = {m : 1}\n\tn = int(input())\n\t\n\twhile(n > 0):\n\t\tfiltr = input()\n\t\tnum = convert(filtr)\n\t\tk = list(tab.keys())\n\t\tnewtab = tab.copy()\n\t\t\n\t\tfor i in k:\n\t\t\tvalue = tab[i]\n\t\t\tnew = num ^ i\n\t\t\tz = tab.get(new,0)\n\t\t\tif(z > 10000000 or value > 10000000):\n\t\t\t\tnewtab[new] = (z + value) % 1000000007\n\t\t\telse:\n\t\t\t\tnewtab[new] = (z + value)\n\t\tn -= 1\n\t\ttab = newtab.copy()\n\tprint(str(tab.get(0,0)))\t\t\n\tt -= 1\n\t", "def ct(string):\n\ti = 0\n\tl = len(string)\n\tnum = 0\n\twhile( i < l):\n\t\tnum *= 2\n\t\tif(string[i] == 'w'):\n\t\t\tnum += 1\n\t\ti += 1\n\treturn num\n\t\ndef convert(string):\n\ti = 0\n\tl = len(string)\n\tnum = 0\n\twhile( i < l):\n\t\tnum *= 2\n\t\tif(string[i] == '+'):\n\t\t\tnum += 1\n\t\ti += 1\n\treturn num\n\nt = int(input())\nwhile(t > 0):\n\tpic = input()\n\tm = ct(pic)\n\ttab = {m : 1}\n\tn = int(input())\n\t\n\twhile(n > 0):\n\t\tfiltr = input()\n\t\tnum = convert(filtr)\n\t\tk = list(tab.keys())\n\t\tnewtab = tab.copy()\n\t\t\n\t\tfor i in k:\n\t\t\tvalue = tab[i]\n\t\t\tnew = num ^ i\n\t\t\tnewtab[new] = (tab.get(new,0) + value) % 1000000007\n\t\tn -= 1\n\t\ttab = newtab.copy()\n\tprint(str(tab.get(0,0)))\t\t\n\tt -= 1\n\t", "import itertools\n\ndef powerset(f,n):\n\tlst = []\n\tfor i in range(1,n+1):\n\t\tlst.append(list(itertools.combinations(f,i)))\n\treturn lst\n\ndef read():\n\treturn input()\n\ndef add(s,f):\n\tresult = ''\n\t# print 'adding '+s+' and '+f+' results in ',\n\tfor i in range(len(s)):\n\t\tif s[i]=='+' and f[i]=='+':\n\t\t\tresult+='-'\n\t\telif s[i]=='+' or f[i]=='+':\n\t\t\tresult+='+'\n\t\telse:\n\t\t\tresult+='-'\n\t# print result\n\treturn result\n\ndef resultfilter(f):\n\tresult = f[0]\n\tif len(f)==1:\n\t\treturn result\n\tfor item in f[1:]:\n\t\tresult = add(result,item)\n\treturn result\n\ndef getRequired(s):\n\tf = ''\n\tfor i in range(len(s)):\n\t\tif s[i]=='b':\n\t\t\tf+='-'\n\t\telse:\n\t\t\tf+='+'\n\treturn f\n\nfor t in range(int(read())):\n\ts = read()\n\tif 'w' in s:\n\t\tcount = 0\n\telse:\n\t\tcount = 1\n\trequiredF = getRequired(s)\n\t# print 'required '+requiredF\n\tn = int(read())\n\tf = []\n\tfor i in range(n):\n\t\tf.append(read())\n\ty = powerset(f,n)\n\tfor item in y:\n\t\tfor temp in item:\n\t\t\t# print temp\n\t\t\toutput = resultfilter(temp)\n\t\t\t# print output\n\t\t\t# print output==requiredF\n\t\t\tif output == requiredF:\n\t\t\t\t# print 'Increasing count'\n\t\t\t\tcount+=1\n\tprint(count%1000000007)", "import itertools\nimport numpy as np\n\ndef countBits(p1):\n\tcount = 0\n\tp2 = p1\n\twhile p2:\n\t\tp2 = p2 & (p2-1)\n\t\tcount = count + 1\n\tp = '{0:b}'.format(p1)\n\tif count == len(p):\n\t\treturn True\n\telse:\n\t\treturn False\n\n\ndef __starting_point():\n\tt = eval(input())\n\tfor i in range(t):\n\t\ts = input()\n\t\tn = eval(input())\n\t\tf_list = []\n\t\tfor j in range(n):\n\t\t\tf_list.append(input())\n\t\tinp = \"\"\n\t\tbin_list = []\n\t\tfor j in range(len(s)):\n\t\t\tif s[j] == 'w':\n\t\t\t\tinp = inp + '0'\n\t\t\telse:\n\t\t\t\tinp = inp + '1'\n\t\t#print inp\n\t\tfor j in range(n):\n\t\t\ts1 = \"\"\n\t\t\tfor k in range(len(f_list[j])):\n\t\t\t\tif f_list[j][k]=='+':\n\t\t\t\t\ts1 = s1 + '1'\n\t\t\t\telse:\n\t\t\t\t\ts1 = s1 + '0'\n\t\t\tbin_list.append(s1)\n\t\t#print bin_list\n\t\tlst = [list(k) for k in itertools.product([0,1], repeat=n)]\n\t\t#print lst\n\t\tcount = 0\n\t\tfor j in range(len(lst)):\n\t\t\tp = \"0\"*n\n\t\t\tfor k in range(len(lst[j])):\n\t\t\t\tif lst[j][k]==1:\n\t\t\t\t\tp1 = int(p,2) ^ int(bin_list[k],2)\n\t\t\t\t\tp = '{0:b}'.format(p1)\n\t\t\t\t\t#print p\n\t\t\tp2 = int(p,2) ^ int(inp,2)\n\t\t\t#print '{0:b}'.format(p2)+\"#\"\n\t\t\tif p2 == (2**len(s)) - 1:\n\t\t\t\tcount = (count+1)%(10**9+7)\n\t\tprint(count%(10**9 + 7))\n\n\t\t# dp = np.zeros((n,1024))\n\t\t# dp[0,0] = 1\n\t\t# for j in range(1,n):\n\t\t# \tfor k in xrange(1024):\n\t\t# \t\tdp[j,k] = max(dp[j-1][k], dp[j-1][j^int(inp,2)])\n\n\n\n\n\n\n\n\n\n\n__starting_point()", "def bw(s):\n t=[]\n for i in s:\n if i=='b':\n t.append('0')\n else:\n t.append('1')\n return int(''.join(str(i) for i in t),2)\ndef pm(s):\n t=[]\n for i in s:\n if i=='-':\n t.append('0')\n else:\n t.append('1')\n return int(''.join(str(i) for i in t),2)\ndef inp(n):\n t=[]\n for i in range(n):\n s=input()\n t.append(pm(s))\n return t\ndef f(n,k,s):\n dp=[[0 for i in range(1024)] for i in range(n+1)]\n dp[0][0]=1\n for i in range(1,n+1):\n for j in range(1024):\n dp[i][j]=dp[i-1][j]+dp[i-1][j^s[i-1]]\n return dp[n][k]%((10**9)+7)\nt=int(input())\nfor i in range(t):\n k=bw(input())\n n=int(input())\n print(f(n,k,inp(n)))", "def bw(s):\n t=[]\n for i in s:\n if i=='b':\n t.append('0')\n else:\n t.append('1')\n return int(''.join(str(i) for i in t),2)\ndef pm(s):\n t=[]\n for i in s:\n if i=='-':\n t.append('0')\n else:\n t.append('1')\n return int(''.join(str(i) for i in t),2)\ndef inp(n):\n t=[]\n for i in range(n):\n s=input()\n t.append(pm(s))\n return t\ndef f(n,k,s):\n dp=[[0 for i in range(1024)] for i in range(n+1)]\n dp[0][0]=1\n for i in range(1,n+1):\n for j in range(1024):\n dp[i][j]=dp[i-1][j]+dp[i-1][j^s[i-1]]\n if dp[i][j]>1023:\n dp[i][j]-=1023\n return dp[n][k]\nt=int(input())\nfor i in range(t):\n k=bw(input())\n n=int(input())\n print(f(n,k,inp(n)))", "def bw(s):\n t=[]\n for i in s:\n if i=='b':\n t.append('0')\n else:\n t.append('1')\n return int(''.join(str(i) for i in t),2)\ndef pm(s):\n t=[]\n for i in s:\n if i=='-':\n t.append('0')\n else:\n t.append('1')\n return int(''.join(str(i) for i in t),2)\ndef inp(n):\n t=[]\n for i in range(n):\n s=input()\n t.append(pm(s))\n return t\ndef f(n,k,s):\n dp=[[0 for i in range(1024)] for i in range(n+1)]\n dp[0][0]=1\n for i in range(1,n+1):\n for j in range(1024):\n dp[i][j]=dp[i-1][j]+dp[i-1][j^s[i-1]]\n return dp[n][k]\nt=int(input())\nfor i in range(t):\n k=bw(input())\n n=int(input())\n print(f(n,k,inp(n)))", "\n\nimport fractions\nimport sys\n\nimport pprint\n\nf = sys.stdin\n\nif len(sys.argv) > 1:\n f = open(sys.argv[1], \"rt\")\n\nMOD = 10**9 + 7\nIMG_SPACE = 2**10\n\ndef str2num(s, one_char):\n n = 0\n for ch in s:\n n = n << 1\n if ch == one_char:\n n = n | 1\n return n\n\ndef img2num(img_str):\n return str2num(img_str, 'w')\n\ndef flt2num(flt_str):\n return str2num(flt_str, '+')\n\ndef calc(S, filters_str):\n N = len(filters_str)\n img_num = img2num(S)\n filters_num = [flt2num(flt) for flt in filters_str]\n\n counts = [[0] * IMG_SPACE for i in range(N)]\n\n # init\n row = counts[N - 1]\n for i in range(IMG_SPACE):\n n = 0\n if i == 0:\n n += 1\n if i ^ filters_num[N-1] == 0:\n n += 1\n row[i] = n\n\n # pass\n for j in range(N-2, -1, -1):\n row = counts[j]\n next_row = counts[j + 1]\n for i in range(IMG_SPACE):\n row[i] = (next_row[i] + next_row[i ^ filters_num[j]]) % MOD\n\n #~ pprint.pprint(counts)\n\n return counts[0][img_num]\n\nT = int(f.readline().strip())\n\nfor case_id in range(1, T+1):\n S = f.readline().strip()\n N = int(f.readline().strip())\n filters = []\n for i in range(N):\n filters.append(f.readline().strip())\n\n r = calc(S, filters)\n\n print(r)\n", "def evaluate(a, b):\n\tans = ''\n\tfor i in range(0, len(a)):\n\t\tif a[i] == b[i]:\n\t\t\tans += '-'\n\t\telse:\n\t\t\tans += '+'\n\treturn ans\n\ndef dp(p_bar, n, s):\n\tmod = 10**7 + 9\n\tif n == 0:\n\t\treturn 0\n\telif n == 1:\n\t\tk = 0\n\t\tif p_bar == s[0]:\n\t\t\tk += 1\n\t\tif p_bar == \"----------\":\n\t\t\tk += 1\n\t\treturn k\n\telse:\n\t\treturn (dp(p_bar, n-1, s)%mod + dp(evaluate(p_bar, s[n-1]), n-1, s))%mod\n\n\nt = int(input())\n\nfor i in range(0, t):\n\tp = input()\n\tn = int(input())\n\ts = []\n\tfor j in range(0, n):\n\t\ttemp = input()\n\t\ts.append(temp)\n\tp_bar = ''\n\tfor j in p:\n\t\tif j == 'w':\n\t\t\tp_bar += '+'\n\t\telse:\n\t\t\tp_bar += '-'\n\tprint(dp(p_bar, n, s))", "Author = \"Rahul_Arora\"\nDate = \"8/12/15\"\n\nimport sys\nfrom math import factorial as f\nt=eval(input())\nAuthor = \"Rahul_Arora\"\nDate = \"8/12/15\"\n\nMODULUS=10**9 + 7\nvariable=f(10)\nfor temp in range(t):\n Author = \"Rahul_Arora\"\n Date = \"8/12/15\"\n s=input()\n st=''\n for i in s:\n if i=='w':\n st+='0'\n else:\n st+='1'\n var=int(st,2)\n check = 10000\n variable=f(8)\n n=list(map(int,sys.stdin.readline().split()))\n n=n[0]\n asp=n\n li=[]\n for k in range(n):\n check += k\n ss=list(map(str,sys.stdin.readline().split()))\n ss=ss[0]\n st=''\n for i in ss:\n if i=='+':\n st+='1'\n else:\n st+='0'\n variable=f(7)\n li.append(int(st,2))\n lii=set(li)\n lii=list(lii)\n my_list=lii[:]\n asp=len(lii)\n dp=[0]*1024\n ANSWER=0\n my_list=lii[:]\n for i in range(asp):\n vp=[0]*1024\n check = check-i\n j=0\n while j<1024:\n vp[j^lii[i]]+=dp[j]\n j+=1\n vp[lii[i]]+=1\n j=0\n my_list=lii[:]\n while j<1024:\n dp[j]+=vp[j]\n j+=1\n my_list=lii[:]\n if var==1023:\n ANSWER+=1\n my_list=lii[:]\n my_list=lii[:]\n for i in range(1024):\n if i^var==1023:\n ANSWER+=dp[i]\n i+=1\n variable=f(10)\n le=len(li)-len(set(li))\n variable=f(10)\n ANSWER=((ANSWER%MODULUS)*(pow(2,le,MODULUS)))\n variable=f(10)\n check = check*10/check\n variable=f(10)\n print(ANSWER%MODULUS)\nauthor='rahulxxarora'", "def filtera(p):\n p = p.replace('w','1')\n p = p.replace('b','0')\n return p\ndef filtern(q):\n q = q.replace('+','1')\n q = q.replace('-','0')\n return q\nmod = 10**9 + 7 \nfrom sys import stdin \ninp = stdin.read().split() \nx = 0 \nfor _ in range(int(inp[x])):\n x += 1\n m = int(filtera(inp[x]),2)\n x += 1\n n = int(inp[x])\n arr = []\n for _ in range(n):\n x += 1\n k = int(filtern(inp[x]),2)\n arr.append(k)\n d = [[0]*(1025) for _ in range(2)]\n d[0][0] = 1\n for i in range(1,n + 1):\n for j in range(1024):\n d[i%2][j] = (d[(i - 1)%2][j] + d[(i - 1)%2][j ^ arr[i-1]]) % mod \n if n%2: \n print(d[1][m] % mod)\n else:\n print(d[0][m] % mod)\n \n"]
{"inputs": [["3", "wwwwwwwwww", "3", "+-+-+-+-+-", "----------", "+---------", "wbwbwbwbwb", "3", "+-+-+-+-+-", "+-+-------", "----+-+-+-", "bbbbbbbbbb", "2", "----------", "----------", "", ""]], "outputs": [["0", "2", "4"]]}
INTERVIEW
PYTHON3
CODECHEF
36,598
dbbc513e620f417b721350b9d73e4189
UNKNOWN
During quarantine chef’s friend invented a game. In this game there are two players, player 1 and Player 2. In center of garden there is one finish circle and both players are at different distances respectively $X$ and $Y$ from finish circle. Between finish circle and Player 1 there are $X$ number of circles and between finish circle and Player 2 there are $Y$ number of circles. Both player wants to reach finish circle with minimum number of jumps. Player can jump one circle to another circle. Both players can skip $2^0-1$ or $2^1- 1$ or …. or $2^N-1$ circles per jump. A player cannot skip same number of circles in a match more than once. If both players uses optimal way to reach finish circle what will be the difference of minimum jumps needed to reach finish circle by both players. If both players reach finish circle with same number of jumps answer will be $0$ $0$. -----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 2 space separated integers $X$ and $Y$. -----Output:----- For each test case, print a single line containing 2 space-separated integers which player win and what is the difference between number of minimum jump required by both players to reach finish circle. -----Constraints----- - $1 \leq T \leq 10^5$ - $1 \leq X,Y \leq 2*10^7$ -----Sample Input:----- 2 4 5 3 5 -----Sample Output:----- 0 0 1 1 -----Explanation:----- Test Case 1: Test Case 2:
["import math\n\nfor i in range(int(input())):\n p,q=list(map(int,input().split()))\n c=0\n h=0\n \n while(q>=0):\n if(q==0):\n h+=1\n break\n \n d=int(math.log2(q+1))\n if(d==0):\n h+=1\n break\n y=(2**d)-1\n q-=y+1\n if(q==-1):\n h+=1\n break\n h+=1\n \n while(p>=0):\n if(p==0):\n c+=1\n break\n else:\n rem=int(math.log2(p+1))\n \n if(rem==0):\n c+=1\n break\n \n y=(2**rem)-1\n p-=y+1\n if(p==-1):\n c+=1\n break\n c+=1\n\n if(c==h):\n print(0,0)\n if(c<h):\n print(1,h-c)\n if(c>h):\n print(2,c-h)\n", "import math\nt=int(input())\nfor i in range(t):\n p,q=list(map(int,input().split()))\n c=0\n h=0\n while(p>=0):\n if(p==0):\n c+=1\n break\n \n else:\n d=int(math.log(p+1,2))\n \n if(d==0):\n c+=1\n break\n \n y=(2**d)-1\n p-=y+1\n if(p==-1):\n c+=1\n break\n c+=1\n while(q>=0):\n if(q==0):\n h+=1\n break\n \n d=int(math.log(q+1,2))\n if(d==0):\n h+=1\n break\n y=(2**d)-1\n q-=y+1\n if(q==-1):\n h+=1\n break\n h+=1\n if(c==h):\n print(0,0)\n else:\n if(c<h):\n print(1,h-c)\n else:\n print(2,c-h)\n \n \n \n \n \n \n \n \n", "l = [(2**i -1) for i in range(0,25)]\nfor _ in range(int(input())):\n x, y = list(map(int,input().split()))\n x_l = [i for i in l if i <= x]\n y_l = [i for i in l if i <= y]\n count_x, count_y, final_x, final_y = 0, 0, x+1, y+1\n while True:\n temp = 0\n for i in range(len(x_l)-1,-1,-1):\n if temp+(x_l[i]+1) <= final_x:\n temp += (x_l[i]+1)\n count_x += 1\n if temp == final_x:\n break\n break\n while True:\n temp = 0\n for i in range(len(y_l)-1,-1,-1):\n if temp+(y_l[i]+1) <= final_y:\n temp += (y_l[i]+1)\n count_y += 1\n if temp == final_y:\n break\n break\n if count_x == count_y:\n print(0,0)\n elif count_x < count_y:\n print(1, count_y-count_x)\n else:\n print(2, count_x-count_y)\n \n \n", "#=============templates==============#\ntakeArr = lambda: list(map(int,input().split()))\ntakeList = lambda: list(map(int,input().split()))\nimport sys\nsys.setrecursionlimit(10**6)\n# import itertools\n# import collections\n#==================MAIN==================# \nfrom math import floor,ceil,log2 \ndef powOfPositive(n) : \n pos = floor(log2(n)); \n return 2**pos; \ndef powOfNegative(n) : \n pos = ceil(log2(n)); \n return (-1 * pow(2, pos)); \ndef highestPowerOf2(n) : \n if (n > 0) : \n return powOfPositive(n); \n else : \n n = -n; \n return powOfNegative(n); \ndef main(t):\n x,y = takeArr()\n a,b = x+1,y+1\n sa = sb = 0\n while a:\n a -= highestPowerOf2(a)\n sa += 1\n while b:\n b -= highestPowerOf2(b)\n sb += 1\n \n winner = 2 if sa>sb else 1 if sb>sa else 0\n score = abs(sa-sb) if winner else 0\n print(winner,score)\n if t>1:\n main(t-1)\nmain(int(input()))\n \n#==================END==================#\n", "import sys\ninput = sys.stdin.readline\n\nT = int(input().strip())\n\nfor _ in range(T):\n X,Y = list(map(int,input().split()))\n x = X+1\n y = Y +1\n def bit(x):\n a = []\n while x>0:\n a.append(x&1)\n x = x//2\n\n return sum(a)\n \n count_x = bit(x)\n count_y = bit(y)\n\n\n # while(x>0):\n # n = bit(x)\n # # print('n_x ' , n)\n # if x == 2**(n+1)-1:\n # count_x += 1\n # break\n # elif 2**n -1 < x:\n # x = (x-(2**n-1))\n # count_x +=1\n # if x != 1:\n # x = x-1\n # else:\n # count_x += 1\n # break\n \n \n # while y>0:\n # n = bit(y)\n # # print('n ' , n)\n # if y == 2**(n+1)-1:\n # count_y += 1\n # break\n # elif 2**n -1 < y:\n # y = (y-(2**n-1))\n # count_y += 1\n # if y != 1:\n # y = y-1\n # else:\n # count_y += 1\n # break\n # print('x',count_x, count_y)\n\n if count_x < count_y:\n print('1',count_y-count_x)\n elif count_y < count_x:\n print('2',count_x-count_y)\n else:\n print('0','0')\n\n", "t = int(input())\nfor _ in range(t):\n x,y = list(map(int,input().split()))\n p = 0\n mx = max(x,y)\n while 2**p<=mx:\n p+=1\n px = p\n py = p\n x_m = 0\n y_m = 0\n x+=1\n y+=1\n while x:\n while 2**px>x:\n px-=1\n x -= 2**px\n x_m += 1\n while y:\n while 2**py>y:\n py-=1\n y -= 2**py\n y_m += 1\n if x_m==y_m: print(0,0)\n else:\n if x_m>y_m:\n print(2, abs(x_m - y_m))\n else:\n print(1, abs(x_m - y_m))\n", "t = int(input())\nfor _ in range(t):\n x,y = list(map(int,input().split()))\n x += 1\n y += 1\n ans1,ans2 = bin(x)[2:].count('1'),bin(y)[2:].count('1')\n if ans1 == ans2:\n print(0,0)\n elif ans1 > ans2:\n print(2,abs(ans1-ans2))\n else:\n print(1,abs(ans1-ans2))\n", "\nt=int(input())\nfor _ in range(t):\n\n x,y=list(map(int,input().split()))\n if x==y:\n print(0,0)\n else:\n x_count=bin(x+1).count('1')\n y_count=bin(y+1).count('1')\n if x_count==y_count:\n print(0,0)\n elif x_count<y_count:\n print(1,y_count-x_count)\n else:\n print(2,x_count-y_count)\n \n", "for _ in range(int(input())):\n x, y = map(int, input().split())\n x = (bin(x+1)[2:]).count('1')\n y = (bin(y+1)[2:]).count('1')\n \n if x == y:\n print(0, 0)\n elif x < y:\n print(1, abs(x-y))\n else:\n print(2, abs(x-y))", "def jumpsto(n):\n if n == 0:\n return 0\n elif n & n-1 == 0:\n return 1 \n jump = 0 \n powe = 0\n n1 = n \n while n1 != 0:\n n1 = n1//2\n powe += 1 \n powe -= 1 \n jump += 1 \n return jump + jumpsto(n- 2**powe)\n\n\nfor _ in range(int(input())):\n # = int(input())\n x, y = list(map(int, input().strip().split()))\n x += 1 \n y += 1 \n # = list(map(int, input().strip().split()))\n jumpx = jumpsto(x)\n jumpy = jumpsto(y)\n if jumpx == jumpy :\n print(0,0)\n elif jumpx < jumpy:\n print(1, jumpy - jumpx)\n else:\n print(2, jumpx - jumpy)\n \n \n \n \n \n \n", "# cook your dish here\nimport math\n\ndef jump(x, t=1):\n if x <= 0:\n return t + x\n n = int(math.log(x+1, 2))\n n = x - 2**n\n return jump(n, t+1)\n\nt = int(input())\nfor _ in range(t):\n x, y = list(map(int, input().split()))\n x = jump(x)\n y = jump(y)\n if x == y:\n print(\"0 0\")\n elif x > y:\n print(2, x-y)\n else:\n print(1, y-x)\n", "from sys import stdin\nimport math\n# Input data\n#stdin = open(\"input\", \"r\")\n\n\ndef func(x):\n count = 0\n while(x > 0):\n n = int(math.log2(x + 1))\n k = 2**n\n count += 1\n if k > x:\n k //= 2\n x -= k\n return count\n\nfor _ in range(int(stdin.readline())):\n x, y = list(map(int, stdin.readline().split()))\n a, b = func(x + 1), func(y + 1)\n if a == b:\n print(0, 0)\n else:\n if a > b:\n print(2, a - b)\n else:\n print(1, b - a)\n", "import math\nd=10**8\ne=[0]\np=1\nwhile p<d:\n p*=2\n e.append(p-1)\ne=e[::-1]\nfor _ in range(int(input())):\n li=list(map(int,input().split()))\n ans1=0\n n1=li[0]+1\n ans2=0\n n2=li[1]+1\n for i in e:\n if (n1-i-1)>=0:\n n1-=i\n n1-=1\n ans1+=1\n ans1+=n1\n for i in e:\n if (n2-i-1)>=0:\n n2-=i\n n2-=1\n ans2+=1\n ans2+=n1\n if(ans1==ans2):\n print(0,0)\n elif ans1>ans2:\n print(2,ans1-ans2)\n else:\n print(1,ans2-ans1)\n \n\n \n", "# cook your dish here\nfor _ in range(int(input())):\n a,b=list(map(int,input().split()))\n c=list(bin(a+1)[2:])\n d=list(bin(b+1)[2:])\n e=c.count('1')\n f=d.count('1')\n if e==f:\n print(0,0)\n elif e<f:\n print(1,f-e)\n else:\n print(2,e-f)", "# cook your dish here\ndef fuck_off(x,y):\n X=bin(x+1)[2:]\n Y=bin(y+1)[2:]\n count1,count2=0,0\n for i in X:\n if i=='1':\n count1+=1\n for i in Y:\n if i=='1':\n count2+=1\n if count1==count2:\n print(0,\" \",0)\n if count1>count2:\n print(2,\" \",abs(count1-count2))\n if count1<count2:\n print(1,\" \",abs(count2-count1))\nt=int(input())\nfor i in range(t):\n x,y=input().split()\n fuck_off(int(x),int(y))", "'''\nName : Vasu Gamdha\ncodechef id :vasu_vg\nProblem : CRCLJUMP\n\n##############################\n### LOGIC STAYS BETWEEN US ###\n##############################\n'''\n\nfrom sys import stdin as sin, stdout as sout\nMOD=1000000007\nfor _ in range(int(sin.readline())):\n x,y=map(int,sin.readline().split())\n x,y=x+1,y+1\n xx,yy=bin(x).count(\"1\"),bin(y).count(\"1\")\n ans= str(xx) + \" \" + str(yy)\n if xx==yy: sout.write(str(\"0 0\")+\"\\n\")\n elif xx>yy: sout.write(str(\"2 \")+ str(xx-yy) +\"\\n\")\n else: sout.write(str(\"1 \")+ str(yy-xx) +\"\\n\")", "# cook your dish here\nfor _ in range (int(input())) :\n a,b = list(map(int,input().split()))\n c = list(bin(a+1)[2:])\n d = list(bin(b+1)[2:])\n e = c.count('1')\n f = d.count('1')\n if e == f :\n print(0,0)\n elif e<f :\n print(1,f-e)\n else :\n print(2,e-f)\n", "# cook your dish here\nimport math \n \n\ndef Log2(x): \n return (math.log10(x) / \n math.log10(2))\ndef isPowerOfTwo(n): \n return (math.ceil(Log2(n)) == math.floor(Log2(n)))\nt=int(input())\nfor i in range(t):\n x,y=list(map(int,input().split()))\n step_x=0\n step_y=0\n if(isPowerOfTwo(x+1)):\n step_x=1\n else:\n while(x>=0):\n nx=Log2(x+1)\n s=int(nx)\n x-=(2**s)\n step_x+=1\n if(isPowerOfTwo(y+1)):\n step_y=1\n else:\n while(y>=0):\n ny=Log2(y+1)\n s_y=int(ny)\n y-=(2**s_y)\n step_y+=1\n if(step_x==step_y):\n print(0,0)\n elif(step_x>step_y):\n print(2,abs(step_x-step_y))\n \n else:\n print(1,abs(step_x-step_y))\n \n", "# cook your dish here\nfrom math import log2,floor\nfor _ in range(int(input())):\n x,y=list(map(int,input().split()))\n count1,count2=0,0\n while True:\n z=floor(log2(x+1))\n #print(z)\n x=x-((2**z)-1)\n x-=1\n count1 += 1\n\n if x<0:\n break\n ##print(x)\n ##count1+=1\n\n while True:\n ##print(y)\n z = floor(log2(y + 1))\n\n y = y - ((2 ** z) - 1)\n y-=1\n count2 += 1\n\n if y<0:\n break\n\n ##print(count1,count2)\n if count1==count2:\n print(0,0)\n if count1>count2:\n print(2,abs(count1-count2))\n if count2>count1:\n print(1,count2-count1)\n\n", "# cook your dish here\ntest_cases=int(input())\nfor i in range(test_cases):\n X,Y=map(int,input().split())\n X+=1\n Y+=1\n x=str(bin(X))\n y=str(bin(Y))\n count1=0\n count2=0\n for i in x:\n if(i=='1'):\n count1+=1\n for i in y:\n if(i=='1'):\n count2+=1\n if(count1>count2):\n print(2,abs(count1-count2))\n elif(count2>count1):\n print(1,abs(count1-count2))\n else:\n print(0,0)", "def main():\n T = int(input())\n while T:\n a,b = list(map(int, input().split()))\n c1 = bin(a+1).count('1')\n c2 = bin(b+1).count('1')\n if c1 > c2:\n print(2,c1-c2)\n elif c1 < c2:\n print(1, c2-c1)\n else:\n print(\"0 0\")\n T-=1\ndef __starting_point():\n main()\n__starting_point()", "# cook your dish here\nfrom math import log\nfor _ in range(int(input())):\n x,y = map(int,input().split())\n x += 1\n y += 1\n c1,c2 = 0,0\n while x>0:\n x = x - 2**int(log(x,2))\n c1 += 1\n while y>0:\n y = y - 2**int(log(y,2))\n c2 += 1\n if c1==c2:\n print(0,0)\n elif c1>c2:\n print(2,c1-c2)\n else:\n print(1,c2-c1)"]
{"inputs": [["2", "4 5", "3 5"]], "outputs": [["0 0", "1 1"]]}
INTERVIEW
PYTHON3
CODECHEF
10,816
6e9583296251b512e2e4a80f35a6b32b
UNKNOWN
Chef is playing a game with his brother Chefu. He asked Chefu to choose a positive integer $N$, multiply it by a given integer $A$, then choose a divisor of $N$ (possibly $N$ itself) and add it to the product. Let's denote the resulting integer by $M$; more formally, $M = A \cdot N + d$, where $d$ is some divisor of $N$. Chefu told Chef the value of $M$ and now, Chef should guess $N$. Help him find all values of $N$ which Chefu could have chosen. -----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 $A$ and $M$. -----Output----- For each test case, print two lines. The first line should contain a single integer $C$ denoting the number of possible values of $N$. The second line should contain $C$ space-separated integers denoting all possible values of $N$ in increasing order. It is guaranteed that the sum of $C$ over all test cases does not exceed $10^7$. -----Constraints----- - $1 \le T \le 100$ - $2 \le M \le 10^{10}$ - $1 \le A < M$ -----Subtasks----- Subtask #1 (50 points): - $M \le 10^6$ Subtask #2 (50 points): original constraints -----Example Input----- 3 3 35 5 50 4 65 -----Example Output----- 1 10 0 3 13 15 16
["import math\ndef divisors(n):\n arr = []\n for i in range(1,1+int(math.ceil(math.sqrt(n)))):\n if n%i == 0:\n arr.append(i)\n arr.append(n//i)\n arr = list(sorted(set(arr)))\n return arr\ntry:\n t = int(input())\n while t:\n t -= 1\n a,m = map(int, input().split())\n divs = divisors(m)\n ans = []\n for d in divs:\n q = (m//d-1)/a\n if q%1 == 0 and q>0:\n ans.append((int(d*q)))\n ans.sort()\n print(len(ans))\n for i in ans:\n print(i, end = ' ')\n print()\nexcept:\n pass", "import math\ndef divisors(n):\n arr = []\n for i in range(1,1+int(math.ceil(math.sqrt(n)))):\n if n%i == 0:\n arr.append(i)\n arr.append(n//i)\n arr = list(sorted(set(arr)))\n return arr\ntry:\n t = int(input())\n while t:\n t -= 1\n a,m = map(int, input().split())\n divs = divisors(m)\n ans = []\n for d in divs:\n q = (m//d-1)/a\n if q%1 == 0 and q>0:\n ans.append((int(d*q)))\n ans.sort()\n print(len(ans))\n for i in ans:\n print(i, end = ' ')\n print()\nexcept:\n pass", "T = int(input())\nimport math\nfor i in range(T):\n list = []\n A,M = input().split()\n A = int(A)\n M = int(M)\n L1 = M//A\n L2 = math.ceil(M/(A+1))\n while L2 <= L1 :\n N = L2\n if M - N*A !=0 and N%(M - N*A) == 0 :\n list.append(L2)\n L2 += 1\n\n print(len(list))\n if len(list) > 0:\n for j in range(len(list)-1):\n print(list[j],end=\" \")\n print(list[len(list)-1])\n else:\n print(\" \")\n", "from math import sqrt\ndef solve():\n a,m=list(map(int,input().split()))\n\n all_vals=[]\n\n for i in range(1,int(sqrt(m))+1):\n if(m%i==0):\n if((m-i)%a==0 and ((m-i)//a)%i==0):\n all_vals.append((m-i)//a)\n i=m//i\n if(i!=m and (m-i)%a==0 and ((m-i)//a)%i==0):\n all_vals.append((m-i)//a)\n\n\n print(len(all_vals))\n if(len(all_vals)!=0):\n all_vals.sort()\n print(*all_vals)\n\n \n\nfor T in range(int(input())):\n solve()\n \n", "from math import sqrt\ndef solve():\n a,m=list(map(int,input().split()))\n\n all_vals=[]\n\n for i in range(1,int(sqrt(m))+1):\n if(m%i==0):\n if((m-i)%a==0 and ((m-i)//a)%i==0):\n all_vals.append((m-i)//a)\n i=m//i\n if(i!=m and (m-i)%a==0 and ((m-i)//a)%i==0):\n all_vals.append((m-i)//a)\n\n\n print(len(all_vals))\n if(len(all_vals)!=0):\n all_vals.sort()\n print(*all_vals)\n\n \n\nfor T in range(int(input())):\n solve()\n \n", "# cook your dish here\nfrom math import sqrt\ndef solve():\n a,m=list(map(int,input().split()))\n n=m//(a+1)\n\n all_vals=[]\n \n while(a*n<m or (a>=int(sqrt(m)) and n<=sqrt(m))):\n if(a*n+((m-a*n)*(n%(m-a*n)==0))==m):\n all_vals.append(n)\n n+=1\n\n print(len(all_vals))\n if(len(all_vals)!=0):\n print(*all_vals)\n\n \n\nfor T in range(int(input())):\n solve()\n \n", "# cook your dish here\ndef solve():\n a,m=list(map(int,input().split()))\n n=m//(a+1)\n\n all_vals=[]\n \n while(a*n<m):\n if(a*n+((m-a*n)*(n%(m-a*n)==0))==m):\n all_vals.append(n)\n n+=1\n\n print(len(all_vals))\n if(len(all_vals)!=0):\n print(*all_vals)\n\n \n\nfor T in range(int(input())):\n solve()\n \n", "from math import ceil\ndef solve():\n a,m=list(map(int,input().split()))\n n=ceil(m/a)\n\n all_vals=[]\n \n while((a*n+n)>=m):\n if((m-a*n)>0 and a*n+((m-a*n)*(n%(m-a*n)==0))==m):\n all_vals.append(n)\n n-=1\n\n print(len(all_vals))\n if(len(all_vals)!=0):\n print(*all_vals[::-1])\n\n \n\nfor T in range(int(input())):\n solve()\n \n", "# cook your dish here\ndef solve():\n a,m=list(map(int,input().split()))\n n=m//(a+1)\n\n all_vals=[]\n \n while(a*n<m):\n if(a*n+((m-a*n)*(n%(m-a*n)==0))==m):\n all_vals.append(n)\n n+=1\n\n print(len(all_vals))\n if(len(all_vals)!=0):\n print(*all_vals)\n\n \n\nfor T in range(int(input())):\n solve()\n \n", "import math\n\nfor _ in range(int(input())):\n a,m=list(map(int, input().split()))\n f={1}\n for i in range(2, int(math.sqrt(m))+1):\n if m%i==0:\n f.add(i)\n f.add(m//i)\n \n total=0\n l=[]\n for i in f:\n p=m-i\n if p%a==0:\n q=p//a \n if q%i==0:\n l.append(q)\n total+=1 \n \n print(total)\n if total>0:\n l.sort()\n print(*l, end=' ')\n print('')\n \n else:\n print(' ')", "# -*- coding: utf-8 -*-\n\"\"\"\nCreated on Wed Oct 7 10:50:29 2020\n\n@author: Vineet\n\"\"\"\n\n\nfrom math import sqrt\n\nt=int(input())\n\nwhile(t>0):\n a,m = [int(x) for x in input().split()]\n div=[]\n n=[]\n for i in range(1,int(sqrt(m))+1):\n if m%i==0:\n if m//i==i:\n div.append(i)\n else:\n div.append(i)\n div.append(m//i)\n div.sort()\n div=div[:-1]\n \n for i in div:\n if ((m//i)-1)%a==0:\n n.append(i*(((m//i)-1)//a))\n s=set(n)\n n=list(s)\n n.sort()\n print(len(n))\n for i in n:\n print(i,end=' ')\n print()\n\n t-=1", "# -*- coding: utf-8 -*-\n\"\"\"\nCreated on Wed Oct 7 10:50:29 2020\n\n@author: Vineet\n\"\"\"\n\n\nfrom math import sqrt\n\nt=int(input())\n\nwhile(t>0):\n a,m = [int(x) for x in input().split()]\n div=[]\n n=[]\n for i in range(1,int(sqrt(m))+1):\n if m%i==0:\n if m//i==i:\n div.append(i)\n else:\n div.append(i)\n div.append(m//i)\n div.sort()\n div=div[:-1]\n \n for i in div:\n if ((m//i)-1)%a==0:\n n.append(i*(((m//i)-1)//a))\n s=set(n)\n n=list(s)\n n.sort()\n print(len(n))\n for i in n:\n print(i,end=' ')\n print()\n\n t-=1", "# cook your dish here\ndef getdiv(m):\n i=1\n res=[]\n while(i*i<=m):\n if(m%i==0):\n res.append(i)\n if(m//i!=i):\n res.append(m//i)\n i+=1\n return res\n\ntest=int(input())\nfor _ in range(test):\n a,m=map(int,input().split())\n div=getdiv(m)\n res=[]\n for i in div:\n n=(m-i)/a\n if(n>=i and n%1==0 and n%i==0):\n res.append(int(n))\n res.sort()\n print(len(res))\n for i in res:\n print(i,end=' ')\n print('')", "# cook your dish here\n# code by RAJ BHAVSAR\n\ndef getdiv(m):\n i = 1\n res = []\n while(i*i <= m):\n if(m%i == 0):\n res.append(i)\n if(m//i != i):\n res.append(m//i)\n i += 1\n return res\n\nfor _ in range(int(input())):\n a,m = map(int,input().split())\n div = getdiv(m)\n res = []\n for i in div:\n n = (m-i)/a\n if(n>=i and n%1 == 0 and n%i == 0):\n res.append(int(n))\n res.sort()\n print(len(res))\n for i in res:\n print(i,end=' ')\n print('')", "t=int(input())\nfor i in range(t):\n am=input().split()\n a=int(am[0])\n m=int(am[1])\n l=list()\n c=0\n indx=m//a\n for i in range(indx,0,-1):\n diff=m-i*a\n if(diff>i):\n break\n if(diff!=0):\n if(i%diff==0):\n c+=1\n l.append(i)\n l.sort()\n res=str()\n for i in range(len(l)):\n res=res+str(l[i])+\" \"\n res.rstrip()\n print(c)\n print(res)\n", "import math\n\ndef search(l):\n a=l[0]\n n=l[1]\n g=[]\n r=[]\n e=[]\n t=[]\n z=[]\n i = 1\n while i <= math.sqrt(n): \n \n if (n % i == 0) : \n \n \n if (n / i == i) : \n g.append(i) \n else : \n \n g.append(i)\n g.append(int(n/i))\n i = i + 1\n g.sort()\n \n for i in g:\n k=(int(n/i)-1)\n e.append(k)\n \n for j in e:\n if(j%a==0):\n p=int(j/a)\n ind=e.index(j)\n f=g[ind]*p\n z.append(f)\n t.append(p)\n \n z.sort()\n \n if(len(z)==1 and z[0]==0):\n print(\"0\")\n else:\n z.remove(0)\n print(len(z))\n print(*z,sep=\" \")\n \n\n \n\n\n\n\n\nt=int(input())\n\nfor i in range(t):\n l=list(map(int,input().split()))\n search(l)\n ", "import math\nt = int(input())\nwhile t>0:\n t -= 1\n # n = int(input())\n a, m = list(map(int, input().split()))\n d = 1\n ans = set()\n limit = int(math.sqrt(m)+1)\n while d<limit+1:\n if m%d == 0:\n num = m//d-1\n if num%a == 0:\n ans.add((num//a)*d)\n d2 = m//d\n num = m//d2-1\n if num > 0 and num%a == 0:\n ans.add((num//a)*d2)\n d += 1\n print(len(ans))\n print(*sorted(ans))\n\n\n\n\n", "# cook your dish here\nt=int(input())\nfor _ in range(t):\n d=[]\n jj=0\n a,m=list(map(int,input().split()))\n p=m//(a+1)\n q=m//a\n for i in range(p,q+1):\n if i!=m/a:\n \n if i%(m-a*i)==0:\n d.append(i)\n #jj=jj+1 \n print(len(d))\n #print(d)\n d.sort()\n # print(jj)\n for u in d:\n print(u,end=\" \")\n print(\"\\n\",end=\"\") \n \n", "import sys\nimport math\nfrom collections import defaultdict,Counter\n\n# input=sys.stdin.readline\n# def print(x):\n# sys.stdout.write(str(x)+\"\\n\")\n\n# sys.stdout=open(\"CP3/output.txt\",'w')\n# sys.stdin=open(\"CP3/input.txt\",'r')\n\n# m=pow(10,9)+7\nt=int(input())\nfor i in range(t):\n a,m=map(int,input().split())\n r=(m-1)//a\n # print(r)\n l=[]\n for j in range(1,r+1):\n if m%(a*j+1)==0:\n d=m//(a*j+1)\n l.append(d*j)\n print(len(l))\n print(*l)", "# cook your dish here\nimport math\ndef Divisors(n):\n l=[]\n for i in range(1,int(math.sqrt(n))+1):\n if n%i==0:\n if n/i==i:\n l.append(i)\n else:\n l.append(n//i)\n l.append(i)\n return l\n \nfrom sys import stdin,stdout\nfor _ in range(int(input())):\n a,m=list(map(int,input().split()))\n div=Divisors(m)\n #print(div)\n ans=set()\n for i in div:\n if ((m//i)-1)%a==0:\n ans.add((((m//i)-1)//a)*i)\n ans=list(ans)[1:]\n ans.sort()\n print(len(ans))\n print(*ans)\n \n", "import sys\ndef input(): return sys.stdin.readline().strip()\n\nt = int(input())\nwhile t:\n t -= 1\n a, m = map(int, input().split())\n possible = []\n for i in range(2, int(m**0.5)+1):\n if not m%i:\n d = m//i\n if not (m-d)%(a*d):\n possible.append((m-d)//a)\n d = m//d\n if not (m-d)%(a*d):\n possible.append((m-d)//a)\n if not(m-1)%a:\n possible.append((m-1)//a)\n \n possible.sort()\n print(len(possible))\n for i in possible:\n print(i, end = \" \")\n print()\n", "# cook your dish here\nt = int(input())\nwhile t>0:\n a,m = list(map(int,input().split()))\n l = m//a\n arr = []\n for i in range(l,0,-1):\n if m-i*a>i:\n break\n if m-a*i==0:\n continue\n elif i%(m-a*i)==0:\n arr.append(i)\n print(len(arr))\n arr = arr[::-1]\n print(\" \".join(map(str,arr)))\n t=t-1\n"]
{"inputs": [["3", "3 35", "5 50", "4 65"]], "outputs": [["1", "10", "0", "3", "13 15 16"]]}
INTERVIEW
PYTHON3
CODECHEF
9,676
f7a7ce8bb3ee9f06e5c407eafa67f9e8
UNKNOWN
Mr. Das is a teacher teaching for several years in a school. He is not computer savvy. Due to lockdown, now he has to take classes online. Recently he took an online exam for students of different classes. Now, he will call parents of all the students who scored lower than average marks for the class. He has requested you to give the name $X$, parent's phone number $P$, and marks obtained $M$ to him. -----Input:----- - First line contains $T$ no. of test cases - for every test case, first line contains an integer $N$, no. of students of his class - Next $N$ lines contain $X$, $P$ , and $M$ separated by space -----Output:----- For every test case, find details of the students who scored below average, then print $X, P, M$ separated by space on a new line as per the increasing order of their marks. In case there are multiple students with the same marks, print them as per the order of their occurrence in the input -----Constraints----- - $1 \leq T \leq 20$ - X contains characters between a-z and A-Z with a maximum length of 20 - $1 \leq N \leq 100$ - P is 10 digits - $0 \leq M \leq 100$ -----Sample Input:----- 2 3 Rahul 1345964789 47 Rupendra 1457856987 58 Priya 1478569820 45 2 Tanuja 4310779415 97 Akash 3689781245 43 -----Sample Output:----- Priya 1478569820 45 Rahul 1345964789 47 Akash 3689781245 43 -----EXPLANATION:----- In #1, Priya and Rahul's number was lower than average. In #2, Akash's number was lower than average
["try:\n # cook your dish here\n t=int(input())\n for j in range(t):\n n=int(input())\n x=[]\n p=[]\n m=[]\n for i in range(n):\n X,P,M=list(map(str,input().split()))\n x.append(X)\n p.append(int(P))\n m.append(int(M))\n avg=sum(m)/n\n for i in m:\n if i<avg:\n z=sorted([k for k in m if k<avg])\n for i in range(len(z)):\n print(x[m.index(z[i])],p[m.index(z[i])],m[m.index(z[i])])\n \nexcept:\n pass", "# cook your dish here\nt=int(input())\nfor _ in range(t):\n n=int(input())\n d={}\n for j in range(n):\n x,p,m=map(str,input().split())\n if((x,p) not in d):\n d[(x,p)]=int(m)\n lst=d.values()\n s=sum(lst)\n avg=s/n\n count=0\n \n d=sorted(d.items())\n for i in range(n):\n if(d[i][1]<avg):\n count=1\n print(d[i][0][0],d[i][0][1],d[i][1])\n if(count==0):\n print('\\n')", "# cook your dish here\nt=int(input())\nfor _ in range(t):\n n=int(input())\n d={}\n for j in range(n):\n x,p,m=map(str,input().split())\n if((x,p) not in d):\n d[(x,p)]=int(m)\n lst=d.values()\n s=sum(lst)\n avg=s/n\n count=0\n \n d=sorted(d.items())\n for i in range(n):\n if(d[i][1]<avg):\n count=1\n print(d[i][0][0],d[i][0][1],d[i][1])\n if(count==0):\n print(-1)", "# cook your dish here\nfor _ in range(int(input())):\n l=[]\n lll=[]\n s=0\n n=int(input())\n for _ in range(n):\n ll=list(map(str,input().split()))\n s+=float(ll[2])\n lll.append(ll)\n avg=s/n\n #print(avg)\n for i in lll:\n if float(i[2])<avg:\n l.append(i)\n #print(l,lll)\n l.sort(key = lambda x: x[2])\n for i in l:\n print(*i)", "#Help the teacher\nfor _ in range(int(input())):\n n = int(input())\n list1 = []\n for i in range(n):\n list1.append(list(map(str,input().split())))\n sums = 0\n for i in list1:\n sums += int(i[2])\n avg = sums/n\n ans = []\n for i in list1:\n if(avg>int(i[2])):\n ans.append(i)\n ans.sort(key = lambda ans: int(ans[2]))\n for i in ans:\n print(*i)", "# cook your dish here\nimport math\nt=int(input())\nfor i in range(t):\n n=int(input())\n x={}\n p={}\n m=[]\n for j in range(n):\n x1,p1,m1=input().split()\n m.append(int(m1))\n x[int(m1)]=x1\n p[int(m1)]=p1\n su=sum(m)\n avg=su/n\n m.sort()\n for j in range(n):\n if(m[j]<50):\n print(x[m[j]],end=\" \")\n print(p[m[j]],end=\" \")\n print(m[j])\n \n ", "from operator import itemgetter\nt=int(input())\nfor _ in range(t):\n n=int(input())\n #d=defaultdict(list)\n l=[]\n d={}\n sum1=0\n for i in range(n):\n name,p_mobile,marks=map(str,input().split())\n d['name']=name\n d['p_mobile']=p_mobile\n d['marks']=int(marks)\n l.append(d)\n sum1+=int(marks)\n d={}\n avg=sum1/n\n l=sorted(l,key=itemgetter('marks'))\n for i in l:\n if i['marks']<avg:\n print(i['name'],i['p_mobile'],i['marks'])", "# cook your dish here\nfrom operator import itemgetter\nfor _ in range(int(input())):\n n=int(input())\n info=[]\n val=0\n for i in range(n):\n lst=list(input().strip().split())\n val+=int(lst[2])\n info.append(lst)\n info.sort(key=lambda info:info[2])\n #print(ans)\n final=[]\n val=val/n\n for i in range(n):\n if int(info[i][2])<val:\n final.append(info[i])\n \n for i in final:\n print(i[0],i[1],i[2])", "from statistics import mean\nfrom collections import Counter\nfor _ in range(int(input())):\n n=int(input());d={}\n for i in range(n):\n x,y,z=input().split()\n d[int(z)]=[x,y]\n avg=mean(d);a=[]\n for i in d:\n if(i<avg):a.append(i)\n a.sort()\n for i in a:print(*d[i],i)\n", "# cook your dish here\nt=int(input())\nfor i in range(t):\n n=int(input())\n x={}\n p={}\n m=[]\n for j in range(n):\n x1,p1,m1=input().split()\n m.append(int(m1))\n x[int(m1)]=x1\n p[int(m1)]=p1\n su=sum(m)\n avg=su/n\n m.sort()\n for j in range(n):\n if(m[j]<avg):\n print(x[m[j]],end=\" \")\n print(p[m[j]],end=\" \")\n print(m[j])\n \n ", "# cook your dish here\nt=int(input())\nfor _ in range(t):\n n=int(input())\n l=[]\n avg=0\n for i in range(n):\n x,p,m=input().split(\" \")\n p=int(p)\n m=int(m)\n avg+=m\n l.append([x,p,m])\n avg=avg//n\n ret=[]\n for i in range(n):\n if l[i][2]<=avg:\n ret.append([l[i][0],l[i][1],l[i][2]])\n ret.sort()\n for i in range(len(ret)):\n print(ret[i][0],ret[i][1],ret[i][2])", "from statistics import mean\nfrom collections import Counter\nfor _ in range(int(input())):\n n=int(input());d={}\n for i in range(n):\n x,y,z=input().split()\n d[int(z)]=[x,y]\n avg=mean(d);a=[]\n for i in d:\n if(i<avg):a.append(i)\n a.sort();c=0\n for i in range(len(a)-1):\n if(a[i]==a[i+1]):c=1;break\n if(c==1):\n result=sorted(a,key=a.count,reverse=True)\n for i in result:print(*d[i],i)\n else:\n for i in a:print(*d[i],i)", "# cook your dish here\nt=int(input())\nfor _ in range(t):\n n=int(input())\n l=[]\n avg=0\n for i in range(n):\n x,p,m=input().split(\" \")\n p=int(p)\n m=int(m)\n avg+=m\n l.append([x,p,m])\n avg=avg//n\n ret=[]\n for i in range(n):\n if l[i][2]<avg:\n ret.append([l[i][0],l[i][1],l[i][2]])\n ret.sort()\n for i in range(len(ret)):\n print(ret[i][0],ret[i][1],ret[i][2])", "# cook your dish here\n\nt=int(input())\nfor i in range(t):\n n=int(input())\n l=[]\n for j in range(n):\n l.append(input().split())\n #print(l)\n sum=0\n avg=0\n for j in range(n):\n sum+=int(l[j][2])\n avg=sum/n\n x=[]\n #print(avg)\n for k in l:\n if int(k[2])<avg:\n x.append(k[2])\n x.sort()\n y=0\n le=len(x)\n while(le!=0):\n for k in l:\n #print(le)\n if y<len(x):\n if x[y]==k[2]:\n print(k[0],k[1],k[2])\n y+=1\n le-=1\n k[2]=-1\n break\n \n \n", "# cook your dish here\ntry:\n t=int(input())\n for i in range(t):\n n=int(input())\n a=[]\n avg=0\n for j in range(n):\n t=list(input().split())\n avg=avg+int(t[2])\n a.append(t)\n avg//=n\n a.sort(key=lambda a:a[2])\n for x in a:\n if int(x[2])<=(avg):\n print(' '.join(map(str,x)))\nexcept EOFError:\n pass", "# cook your dish here\ntry:\n t=int(input())\n for i in range(t):\n n=int(input())\n a=[]\n avg=0\n for j in range(n):\n t=list(input().split())\n avg=avg+float(t[2])\n a.append(t)\n avg/=n\n a.sort(key=lambda a:a[2])\n for x in a:\n if round(float(x[2]))<=round(avg):\n print(' '.join(map(str,x)))\nexcept EOFError:\n pass", "# cook your dish here\ntry:\n t=int(input())\n for i in range(t):\n n=int(input())\n a=[]\n avg=0\n for j in range(n):\n t=list(input().split())\n avg=avg+float(t[2])\n a.append(t)\n avg/=n\n a.sort(key=lambda a:a[2])\n for x in a:\n if int(x[2])<=round(avg):\n print(' '.join(map(str,x)))\nexcept EOFError:\n pass", "# cook your dish here\ntry:\n t=int(input())\n for i in range(t):\n n=int(input())\n a=[]\n avg=0\n for j in range(n):\n t=list(input().split())\n avg=avg+float(t[2])\n a.append(t)\n avg/=n\n a.sort(key=lambda a:a[2])\n for x in a:\n if float(x[2])<round(avg):\n print(' '.join(map(str,x)))\nexcept EOFError:\n pass", "# cook your dish here\ntry:\n t=int(input())\n for i in range(t):\n n=int(input())\n a=[]\n avg=0\n for j in range(n):\n t=list(input().split())\n avg=avg+float(t[2])\n a.append(t)\n avg/=n\n \n a.sort(key=lambda a:a[2])\n for x in a:\n if int(x[2])<round(avg):\n print(' '.join(map(str,x)))\nexcept EOFError:\n pass", "# cook your dish here\nfor _ in range(int(input())):\n l=[]\n lll=[]\n s=0\n n=int(input())\n for _ in range(n):\n ll=list(map(str,input().split()))\n s+=float(ll[2])\n lll.append(ll)\n avg=s/n\n #print(avg)\n for i in lll:\n if float(i[2])<avg:\n l.append(i)\n l.sort(key = lambda x: x[2])\n for i in l:\n print(*i)", "# cook your dish here\ntry:\n t=int(input())\n for i in range(t):\n n=int(input())\n a=[]\n avg=0\n for j in range(n):\n t=list(input().split())\n avg=avg+float(t[2])\n a.append(t)\n avg/=n\n a.sort(key=lambda a:a[2])\n for x in a:\n if float(x[2])<avg:\n print(' '.join(map(str,x)))\nexcept EOFError:\n pass", "# cook your dish here\ntry:\n t=int(input())\n for i in range(t):\n n=int(input())\n a=[]\n avg=0\n for j in range(n):\n t=list(input().split())\n avg=avg+int(t[2])\n a.append(t)\n avg//=n\n a.sort(key=lambda a:a[2])\n for x in a:\n if int(x[2])<avg:\n print(' '.join(map(str,x)))\nexcept EOFError:\n pass", "# cook your dish here\ndef swapPositions(list, pos1, pos2): \n list[pos1], list[pos2] = list[pos2], list[pos1] \n return list\n\nt = int(input())\nwhile(t):\n t-=1 \n avg = 0\n x=[]\n y=[]\n z=[]\n \n n = int(input())\n for i in range(0,n):\n a,b,c = input().split(' ')\n c = int(c)\n x.append(a)\n y.append(b)\n z.append(c)\n avg = avg + c\n avg = avg/n\n '''for i in range(0,n):\n for j in range(0,n):\n if z[i]>z[j]:\n swapPositions(z,i,j)\n swapPositions(x,i,j)\n swapPositions(y,i,j)'''\n for i in range(0,n):\n if z[i]<avg:\n print(x[i] + \" \"+ y[i] + \" \"+ str(z[i]))", "# cook your dish here\nfor _ in range(int(input())):\n l=[]\n lll=[]\n s=0\n n=int(input())\n for _ in range(n):\n ll=list(map(str,input().split()))\n s+=int(ll[2])\n lll.append(ll)\n avg=s//n\n #print(avg)\n for i in lll:\n if int(i[2])<avg:\n l.append(i)\n l.sort(key = lambda x: x[2])\n for i in l:\n print(*i)", "# -*- coding: utf-8 -*-\n\"\"\"\nCreated on Thu Jul 30 11:31:06 2020\n\n@author: MONIMOY\n\"\"\"\n\nt = int(input())\n\ndef sortkey(ele):\n return int(ele[2])\n\ndef avg(s):\n total = 0\n for i in range(len(s)):\n total += int(s[i][2])\n return total/len(s)\n\nout=[]\nfor i in range(t):\n n = int(input())\n s = []\n \n for j in range(n):\n a = input().split()\n s.append(a)\n s.sort(key=sortkey)\n av = avg(s)\n for k in s:\n if int(k[2]) < av:\n out.append(k)\n \nfor i in range(len(out)):\n print(*out[i], sep=\" \")"]
{"inputs": [["2", "3", "Rahul 1345964789 47", "Rupendra 1457856987 58", "Priya 1478569820 45", "2", "Tanuja 4310779415 97", "Akash 3689781245 43"]], "outputs": [["Priya 1478569820 45", "Rahul 1345964789 47", "Akash 3689781245 43"]]}
INTERVIEW
PYTHON3
CODECHEF
9,618
ca69fb07e2616838c786559a3439f449
UNKNOWN
Chef and his mother are going travelling. Chef's world consists of $N$ cities (numbered $1$ through $N$) connected by $N-1$ bidirectional roads such that each city can be reached from any other city using roads. For each city, we know its age — the number of years elapsed since the foundation of the city; let's denote the age of city $i$ by $a_i$. First of all, Chef and his mother have to decide what city they should visit first. Suppose that Chef chooses a city $c_c$ and his mother chooses a (not necessarily different) city $c_m$. The difference of their choices is the number of different bits in the binary representations of $a_{c_c}$ and $a_{c_m}$. Chef will not argue with his mother if the parity of this difference is not equal to the parity of the length of the shortest path between cities $c_c$ and $c_m$ (the number of roads on the shortest path between them). Find the number of ways to choose the cities $c_c$ and $c_m$ such that Chef avoids quarreling with his mother. -----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$. - Each of the following $N-1$ lines contains two space-separated integers $A$ and $B$ denoting a road between cities $A$ and $B$. - The last 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 — the number of valid pairs $c_c, c_m$. -----Constraints----- - $1 \le T \le 10$ - $1 \le N \le 10^5$ - $1 \le A, B \le N$ - $0 \le a_i \le 10^9$ for each valid $i$ -----Sample Input----- 1 3 1 2 1 3 1 2 3 -----Sample Output----- 2 -----Explanation----- Example case 1: The two possible choices are $c_c=2, c_m=3$ (their binary representations differ by one bit, the shortest path has length $2$) and $c_c=1, c_m=2$ (there are two different bits in their binary representations and the shortest path has length $1$).
["'''input\n1\n3\n1 2\n1 3\n1 2 3\n'''\nimport sys\nsys.setrecursionlimit(1000000)\nfor _ in range(eval(input())):\n C=[]\n n=eval(input())\n for i in range(n):\n C.append([])\n for i in range(n-1):\n a,b=[int(x)-1 for x in input().split()]\n C[a].append(b)\n C[b].append(a)\n cnt=0\n Co=[bin(int(x)).count(\"1\") for x in input().split()]\n Q=[0]*(n+100)\n cur=0\n done=[0]*n\n done[0]=1\n H=[0]*n\n for i in range(n):\n r=Q[i]\n if H[r]&1 == Co[r]&1:\n cnt+=1\n for i in C[r]:\n if done[i]==0:\n done[i]=1\n Q[cur+1]=i\n cur+=1\n H[i]=H[r]+1\n #dfs(0,-1)\n print(cnt*(n-cnt))\n\n"]
{"inputs": [["1", "3", "1 2", "1 3", "1 2 3"]], "outputs": [["2"]]}
INTERVIEW
PYTHON3
CODECHEF
606
042b4066c956b1c6137b79be6c91c70e
UNKNOWN
Shivam owns a gambling house, which has a special wheel called The Wheel of Fortune. This wheel is meant for giving free coins to people coming in the house. The wheel of fortune is a game of chance. It uses a spinning wheel with exactly N numbered pockets and a coin is placed in between every consecutive pocket. The wheel is spun in either of the two ways. Before the wheel is turned, all the coins are restored and players bet on a number K. Then a needle is made to point to any one of the pocket which has number K written on it. Wheel is then spun till the needle encounters number K again and the player gets all the coins the needle has encountered. Shivam being the owner of the gambling house, has the authority to place the needle on any of the K numbered pockets and also he could rotate the wheel in either of the two ways. Shivam has to figure out a way to minimize number of coins that he has to spend on every given bet. You are given a wheel having N elements and Q players. Each player bets on a number K from the wheel. For each player you have to print minimum number of coins Shivam has to spend. -----Input----- - The first line of the input contains an integer T denoting the number of test cases . The description of T testcases follow. - The first line of each test case contains single integer N . - The second line of each test case contains N space seperated integers denoting the numbers on the wheel. - The third line of each test case contains a single integer Q denoting the number of players. - Then, Q lines follow a single integer K from the N numbers of the wheel -----Output----- For each player, output the minimum number of coins Shivam has to spend. -----Constraints----- - 1 ≤ T ≤ 10 - 1 ≤ N ≤ 100000 - 1 ≤ Number written on the Wheel ≤ 1000 - 1 ≤ Q ≤ 10000 - 1 ≤ K ≤ 1000 - It is guaranteed that K belongs to the N numbers written on the wheel. -----Example----- Input: 2 3 1 2 3 3 1 2 3 6 2 1 5 3 2 1 4 1 2 3 5 Output: 3 3 3 2 2 6 6
["t=int(input())\r\nfor _ in range(t):\r\n n=int(input())\r\n arr=list(map(int,input().split()))\r\n d={}\r\n for i in range(n):\r\n if arr[i] in d:\r\n d[arr[i]].append(i)\r\n else:\r\n d[arr[i]]=[i]\r\n q=int(input())\r\n for i in range(q):\r\n m=int(input())\r\n if len(d[m])==1:\r\n print(n)\r\n elif len(d[m])==2:\r\n print(min((d[m][1]-d[m][0]),((n-d[m][1])+d[m][0])))\r\n else:\r\n k=100000\r\n for j in range(len(d[m])-1):\r\n if (d[m][j+1]-d[m][j])<k:\r\n k=d[m][j+1]-d[m][j]\r\n else:\r\n pass\r\n print(min(k,((n-d[m][len(d[m])-1])+d[m][0])))\r\n \r\n \r\n"]
{"inputs": [["2", "3", "1 2 3", "3", "1", "2", "3", "6", "2 1 5 3 2 1", "4", "1", "2", "3", "5"]], "outputs": [["3", "3", "3", "2", "2", "6", "6"]]}
INTERVIEW
PYTHON3
CODECHEF
800
9f10edbfd2de7b0432dc54fc7ad1f5f4
UNKNOWN
Chef is playing a game with two of his friends. In this game, each player chooses an integer between $1$ and $P$ inclusive. Let's denote the integers chosen by Chef, friend 1 and friend 2 by $i$, $j$ and $k$ respectively; then, Chef's score is (((Nmodi)modj)modk)modN.(((Nmodi)modj)modk)modN.(((N\,\mathrm{mod}\,i)\,\mathrm{mod}\,j)\,\mathrm{mod}\,k)\,\mathrm{mod}\,N\,. Chef wants to obtain the maximum possible score. Let's denote this maximum score by $M$. Find the number of ways to choose the triple $(i,j,k)$ so that Chef's score is equal to $M$. -----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 $P$. -----Output----- For each test case, print a single line containing one integer — the number of ways to obtain the maximum score. -----Constraints----- - $1 \le T \le 10^6$ - $1 \le N \le P \le 10^6$ -----Subtasks----- Subtask #1 (10 points): - $1 \le T \le 100$ - $1 \le N \le P \le 100$ Subtask #2 (90 points): original constraints -----Example Input----- 2 4 4 3 4 -----Example Output----- 9 13 -----Explanation----- Example case 1: Chef's maximum possible score is $M = 1$. All possible values of $(i, j, k)$ such that the score is $1$ are $(3, 2, 2)$, $(3, 2, 3)$, $(3, 2, 4)$, $(3, 3, 2)$, $(3, 3, 3)$, $(3, 3, 4)$, $(3, 4, 2)$, $(3, 4, 3)$, $(3, 4, 4)$.
["for __ in range(int(input())):\n n,p=list(map(int,input().split()))\n d=n%(n//2+1)\n if(d==0):\n t=p*p*p\n else:\n t=(p-d)*(p-d)+(p-d)*(p-n)+(p-n)*(p-n)\n print(t)\n", "t = int(input())\n\nfor _ in range(t):\n n, p = map(int, input().strip().split())\n\n if n <= 2:\n print(p * p * p)\n\n else:\n m = (n - 1) // 2\n res = (p-m)**2 + (p-n)**2 + ((p-m) * (p-n))\n print(res)", "# cook your dish here\ndef check(n,p,divisor):\n product=1\n \n if p>n:\n i=p-n\n j=p-n\n k=1\n product=i*j\n i=1\n j=p-(n%divisor)\n k=j\n product+=(i*j*k)\n i=p-n\n j=1\n k=p-(n%divisor)\n product+=(i*j*k)\n print(product)\n elif p<=n and p>=divisor:\n i=1\n j=p-(n%divisor)\n k=j\n product=i*j*k\n print(product)\n else:\n if p<divisor:\n greatest=0\n \n for m in range (1,p):\n if n%m>greatest:\n greatest=n%m\n \n i=1\n j=p-greatest\n k=p-greatest\n product=(i*j*k)\n print(product)\n\n \nt=int(input())\nwhile t>0:\n n,p=tuple(map(int,input().split()))\n if n<=2:\n print(p*p*p)\n elif n%2==0:\n check(n,p,n//2+1)\n else:\n check(n,p,(n+1)//2)\n\n \n t-=1\n \n \n \n \n", "# cook your dish here\nt= int(input())\nwhile t:\n n, p = map(int, input().split()) \n if n<=2:\n print(p*p*p)\n else:\n max=int((n-1)/2)\n c=(p-max)*(p-max)\n c=c+(p-n)*(p-max)\n c=c+(p-n)*(p-n)\n print(c)\n t=t-1", " # cook your dish here\ntry:\n t=int(input())\n for i in range(t):\n l=list(map(int,input().split()))\n n=l[0]\n p=l[1]\n if(n==1 or n==2):\n print((p)**3)\n else:\n if(n%2==0):\n print((p-int(n/2)+1)**2+(p-n)*(p-int(n/2)+1)+(p-n)**2)\n else:\n print((p-int(n/2))**2+(p-n)*(p-int(n/2))+(p-n)**2)\nexcept Exception:\n pass\n \n", " # cook your dish here\ntry:\n t=int(input())\n for i in range(t):\n l=list(map(int,input().split()))\n n=l[0]\n p=l[1]\n if(n==1 or n==2):\n print(p**3)\n else:\n if(n%2==0):\n print((p-(n//2-1))**2+(p-n)*(p-(n//2-1))+(p-n)**2)\n else:\n print((p-(n//2))**2+(p-n)*(p-(n//2))+(p-n)**2)\nexcept Exception:\n pass\n \n", "t=int(input())\nfor i in range(t):\n inp = list(map(int,input().split()))\n n=inp[0]\n p=inp[1]\n if(n==1 or n==2):\n print(p*p*p)\n else:\n if(n%2==0):\n print((p-(n//2-1))**2+(p-n)*(p-(n//2-1))+(p-n)**2)\n else:\n print((p-(n-1)//2)**2+(p-n)*(p-(n-1)//2)+(p-n)**2)", "t = int(input())\nfor test in range(t):\n n,p = map(int, input().split())\n m = round(n/2 - 0.7) #max possible score when i,j,k are the next integer \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0greater than n/2\n if m==0:\n choices = p**3\n else:\n choices = (p-m)**2 + (p-n)**2 + (p-m)*(p-n)\n print(choices)", "from sys import stdin\n\nt = int(stdin.readline())\n\nwhile t:\n n, p = [int(x) for x in stdin.readline().split()]\n\n l_rem = n % ((n//2) + 1)\n \n if l_rem == 0:\n print(p*p*p)\n else:\n ans = (p-l_rem)*(p-l_rem)\n ans += (p-n)*(p-l_rem)\n ans += (p-n)*(p-n)\n print(ans)\n\n t -= 1", "T=int(input())\nwhile T>0:\n n,p=input().split()\n n=int(n)\n p=int(p)\n if n>2:\n Rem=n%((n//2)+1)\n total=(p-Rem)*(p-Rem)+(p-n)*(p-Rem)+(p-n)*(p-n)\n else:\n total=p*p*p\n print(total)\n T=T-1\n \n", "# -*- coding: utf-8 -*-\n\"\"\"\n@author: anishukla\n\"\"\"\nT = int(input())\nfor i in range(T):\n N, P = map(int,input().split())\n req = (N//2)+1\n \n if(N==1 or N==2):\n print(P**3)\n \n else:\n req=N%req\n b=(P-req)**2\n c=(P-N)*(P-req)\n a=(P-N)*(P-N)\n print(a+b+c)", "# cook your dish here\nR = lambda : list(map(int,input().split()))\nt = int(input())\nfor _ in range(t):\n n,p = R()\n max_no =n-(int(n/2)+1)\n # print(max_no)\n if max_no==0:\n print(p*p*p)\n else:\n ans = (p-max_no)**2+(p-n)*(p-max_no)+(p-n)**2\n print(ans)\n", "R = lambda : list(map(int,input().split()))\nt = int(input())\nfor _ in range(t):\n n,p = R()\n max_no =n-(int(n/2)+1)\n # print(max_no)\n if max_no==0:\n print(p*p*p)\n else:\n ans = (p-max_no)**2+(p-n)*(p-max_no)+(p-n)**2\n print(ans)\n", "R = lambda : list(map(int,input().split()))\nt = int(input())\nfor _ in range(t):\n n,p = R()\n max_no =n-(int(n/2)+1)\n # print(max_no)\n if max_no==0:\n print(p*p*p)\n else:\n ans = 1*(p-max_no)*(p-max_no)+(p-n)*(p-max_no)+(p-n)*(p-n)\n print(ans)\n", "for _ in range(int(input())):\n n,p=map(int,input().split())\n d=n%(n//2+1)\n #print(\"d = \",d)\n if (n==2 or n==1):\n t=p*p*p\n else:\n t=(p-d)*(p-d)+(p-d)*(p-n)+(p-n)*(p-n)\n print(t)", "t = int(input())\nfor i in range(t) :\n n,p = map(int , input().split(\" \"))\n if n==1 or n==2 :\n print(p*p*p)\n else :\n if n%2 == 0 :\n m = n//2 - 1\n z = (p-m)*(p-m) + (p-n)*(p-m) + (p-n)*(p-n)\n else :\n m = n//2\n z = (p - m) * (p - m) + (p - n) * (p - m) + (p - n) * (p - n)\n print(z)", "def main():\n for i in range(int(input())):\n n, p = list(map(int,input().split()))\n m = n%(n//2 + 1)\n if m==0:\n print(p*p*p)\n else:\n c1 = p-n\n t1 = c1*c1\n t2 = c1*(p-m)\n t3 = (p-m)*(p-m)\n cases = t1+t2+t3\n print(cases)\n\nmain()\n\n\n", "for T in range(int(input())):\n N, P = map(int, input().split())\n M = count = 0\n for i in range(1,P+1):\n for j in range(1,P+1):\n for k in range(1,P+1):\n m = N%i%j%k%N\n if M < m:\n count = 1\n M = m\n elif M == m:\n count += 1\n print(count)", "# cook your dish here\nfrom sys import stdin,stdout\n\nl_in = stdin.readline\nl_out = stdout.write\n\n \nt = int(l_in())\n\nfor i in range(t):\n MaxM = 0\n count = 0\n N,P = list(map(int,(l_in().strip().split())))\n ar = list(range(1,P+1))\n #print(ar)\n for i in ar:#range(P):\n for j in ar:#range(P):\n for k in ar:#range(P):\n M = (((N%i)%j)%k)%N\n if M > MaxM:\n count = 1\n MaxM = M\n #print(\"{} {} {} {}\".format(i,j,k,MaxM))\n elif M == MaxM:\n count = count + 1\n #print(\"{} {} {} {}\".format(i,j,k,MaxM))\n print(count)\n \n", "for __ in range(int(input())):\n n,p=list(map(int,input().split()))\n d=n%(n//2+1)\n if(d==0):\n t=p*p*p\n else:\n t=(p-d)*(p-d)+(p-d)*(p-n)+(p-n)*(p-n)\n print(t)\n", "# cook your dish here\nts=int(input())\nwhile ts>0:\n num,p=list(map(int,input().split()))\n aa=(num//2)+1\n if(num==1 or num==2):\n print(p*p*p)\n else:\n aa=num%aa\n b=(p-aa)**2\n c=(p-num)*(p-aa)\n a=(p-num)*(p-num)\n print(b+c+a)\n ts=ts-1\n\n"]
{"inputs": [["2", "4 4", "3 4"]], "outputs": [["9", "13"]]}
INTERVIEW
PYTHON3
CODECHEF
6,224
688ea792235ea82fe52a47fd59166cd9
UNKNOWN
There is a girl named ''Akansha''. She is very fond of eating chocolates but she has a weak immune system due to which she gets cold after eating chocolate during morning, evening and night and can only eat at most $x$ number of chocolate each afternoon. A friend of hers gifted her some $n$ number of chocolates that she doesn't want to share with anyone. Those chocolate have to be finished before they expire. (no. of days in which they are going to expire from the day she has been gifted the chocolate is given for each chocolate) $Note:$ Chocolate cannot be consumed on the day it expires. Help Akansha to know if it is possible for her to finish all the chocolates before they expire or not. -----Input:----- - First line will contain $T$, number of test cases. Then the test cases follow. - First line contains $n$,the number of chocolates gifted to her - Second line contains $x$,the number of chocolates she can eat each afternoon - Third line contains $n$ space separated integers $A1,A2...An$,denoting the expiry of each of the $n$ chocolates -----Output:----- For each testcase, print $Possible$, if she can complete all the chocolates gifted to her. Otherwise, print $Impossible$, if she can not finish all the chocolates. -----Constraints----- - $1 \leq T \leq 100$ - $1 \leq n \leq 1500$ - $1 \leq x \leq 1500$ - $1 \leq Ai \leq 1500$ -----Subtasks----- - 100 points : $Original Constraints$ -----Sample Input:----- 3 3 5 4 1 2 5 2 4 4 3 2 2 5 1 4 2 3 1 1 -----Sample Output:----- Impossible Possible Impossible -----EXPLANATION:----- - Example case 1 1st and 3rd chocolate on the 1st afternoon as she can consume at most 5. one chocolate will be wasted. $Note:$ she cannot eat the 2nd chocolate because chocolates cannot be consumed on the day of expiry. - Example case 2 4th and 5th chocolate on 1st afternoon, 3rd and 1st chocolate on 2nd afternoon. And 2nd chocolate on the 3rd afternoon. It will take a total of 3 days to finish the chocolate. - Example case 3 She cannot eat 4th and 5th chocolate as they will expire on the very 1st day, she can eat 2nd chocolate on 1st afternoon, then 3rd chocolate on 2nd afternoon, then 1st chocolate on 3rd afternoon, and 2 chocolates 4th and 5th will expire.
["for t in range(int(input().strip())):\n n = int(input().strip())\n x = int(input().strip())\n arr = list(map(int, input().strip().split()))\n arr.sort()\n day = 1\n acc = 0\n isPossible = True\n for a in arr:\n acc += 1\n if acc > x:\n day += 1\n acc = 1\n if day >= a:\n isPossible = False\n break\n\n print(\"Possible\" if isPossible else \"Impossible\")\n", "for _ in range(int(input())):\n n = int(input())\n x = int(input())\n l = list(map(int, input().split()))\n l.sort()\n \n if n%x == 0:\n td = n//x\n else:\n td = n//x+1\n \n for d in range(1, td+1):\n if l[(d-1)*x] == d:\n print(\"Impossible\")\n break\n if l[(d-1)*x] != d:\n print(\"Possible\")", "def woow(l,oned):\n if 1 in l:\n return False\n else:\n for i in range(2,len(l)-1):\n if (l.count(i)>oned):\n lm=l.count(i)//i\n for tp in range(1,lm):\n if i+tp in l:\n return False\n return True\ntc=int(input())\nfor tcc in range(1,tc+1):\n chocs=int(input())\n oned=int(input())\n l=list(map(int,input().split()))\n if woow(l,oned)==True:\n print(\"Possible\")\n else:\n print(\"Impossible\")", "try:\n t = int(input())\n while(t > 0):\n t -= 1\n n = int(input())\n x = int(input())\n a = list(map(int, input().split()))\n if 1 in a:\n print('Impossible')\n else:\n a.sort(reverse = True)\n i,count,ct=len(a)-1,0,0\n v = 0\n while(i>=0):\n if a[i] - v == 1:\n print(\"Impossible\")\n break\n ct += 1\n if ct == x:\n ct = 0\n count += 1\n v += 1\n i-=1\n print('Possible')\nexcept:\n pass", "try:\n t=int(input())\n for i in range(t):\n n=int(input())\n x=int(input())\n l=list(map(int,input().split()))\n if 1 in l:\n print(\"Impossible\")\n else:\n l.sort()\n flag=False\n i=0\n j=0\n while i<max(l)-1:\n ll=l[j:j+x]\n j=j+x\n if i+1 in ll:\n flag=True\n break\n i=i+1\n if flag:\n print('Impossible')\n else:\n print('Possible')\nexcept:\n pass", "T = int(input())\n\ndef choc(x, A):\n sorted_A = list(A)\n sorted_A.sort()\n \n dec_by_one = lambda a : a - 1\n \n while not sorted_A == [] and sorted_A[0] > 1:\n del sorted_A[:x]\n sorted_A = list(map(dec_by_one, sorted_A))\n \n if sorted_A == []:\n print(\"Possible\")\n else:\n print(\"Impossible\")\n\nfor testcase in range(T):\n n = input()\n x = int(input())\n A = [int(a) for a in input().split()]\n \n choc(x, A)\n", "try:\n n=int(input())\n for i in range(n):\n a=int(input())\n b=int(input())\n c=list(map(int,input().split()))\n if 1 in c:\n print(\"Impossible\")\n else:\n c.sort()\n flag=False\n i=0\n j=0\n while i<max(c)-1:\n c1=c[j:j+b]\n j=j+b\n if i+1 in c1:\n flag=True\n break\n i=i+1\n if flag:\n print(\"Impossible\")\n else:\n print(\"Possible\")\nexcept:\n pass", "try:\n t=int(input())\n for i in range(t):\n n=int(input())\n x=int(input())\n l=list(map(int,input().split()))\n if 1 in l:\n print(\"Impossible\")\n else:\n l.sort()\n flag=False\n i=0\n j=0\n while i<max(l)-1:\n ll=l[j:j+x]\n j=j+x\n if i+1 in ll:\n flag=True\n break\n i=i+1\n if flag:\n print('Impossible')\n else:\n print('Possible')\nexcept:\n pass", "# cook your dish here\n# cook your dish here# cook your dish here\nt=int(input())\n\nfor _ in range (t):\n d=int(input())\n s=int(input())\n e=list(map(int,input().split()))\n\n for i in e:\n if(i==1):\n flag= 1\n break\n else:\n flag=0\n if(flag==1):\n print(\"Impossible\")\n else:\n print(\"Possible\")\n \n", "# cook your dish here\nt= int(input())\nfor i in range(t):\n n = int(input())\n x = int(input())\n exp = list(map(int, input().split()))\n exp.sort()\n while(len(exp) >= x):\n if (1 in exp):\n break\n else:\n exp = exp[x:]\n exp = [e - 1 for e in exp]\n if (1 not in exp):\n print(\"Possible\")\n else:\n print(\"Impossible\")", "def abc(l):\n for i in l:\n if i==1:\n return 'Impossible'\n return 'Possible'\n\nt=int(input())\nwhile(t!=0):\n n=int(input())\n a=int(input())\n l=list(map(int,input().split()))\n print(abc(l))\n t-=1\n\n", "# cook your dish here# cook your dish here\nt=int(input())\n\nfor _ in range (t):\n d=int(input())\n s=int(input())\n f=list(map(int,input().split()))\n count=0\n flag=0\n for i in f:\n if(i==1):\n flag= 1\n break\n else:\n flag=0\n if(flag==1):\n print(\"Impossible\")\n else:\n print(\"Possible\")\n \n", "for _ in range(int(input())):\n n=int(input())\n x=int(input())\n l=sorted(list(map(int,input().split())))\n if l[0]==1:\n print(\"Impossible\")\n else:\n j=i=t=q=0\n while i<n:\n if t<x:\n if (l[i]-j)==1:\n print(\"Impossible\")\n q+=1\n break\n else:\n i+=1\n t+=1\n else:\n j+=1\n t=0\n if q==1:\n break\n if not q:\n print(\"Possible\")", "for _ in range(int(input())):\n n=int(input())\n x=int(input())\n l=sorted(list(map(int,input().split())))\n if l[0]==1:\n print(\"Impossible\")\n else:\n j=i=t=q=0\n while i<n:\n if t<x:\n if (l[i]-j)==1:\n print(\"Impossible\")\n q+=1\n break\n else:\n i+=1\n else:\n j+=1\n if q==1:\n break\n if not q:\n print(\"Possible\")", "# cook your dish here\nT=int(input())\nfor i in range(T):\n n=int(input())\n x=int(input())\n arr=[int(i) for i in input().split()]\n arr.sort()\n while(True):\n if arr[0]==1:\n print(\"Impossible\")\n break\n else:\n del arr[0:x]\n arr=[arr[i]-1 for i in range(len(arr))]\n if arr==[]:\n print(\"Possible\")\n break", "T=int(input())\nwhile T:\n n=int(input())\n x=int(input())\n A=list(map(int,input().split()))\n A.sort()\n flag=True\n i=0\n temp=1\n while i<n:\n for j in range(i,min(i+x,n)):\n if(A[j]<=temp):\n flag=False\n break\n temp+=1 \n i+=x\n if(flag):print(\"Possible\")\n else:print(\"Impossible\")\n T-=1", "T=int(input())\nwhile T:\n n=int(input())\n x=int(input())\n A=list(map(int,input().split()))\n A.sort()\n flag=True\n i=0\n temp=1\n while i<n:\n for j in range(i,min(i+x,n)):\n if(A[j]<=temp):\n flag=False\n break\n i+=x\n if(flag):print(\"Possible\")\n else:print(\"Impossible\")\n T-=1", "# cook your dish here\nt=int(input())\nfor y in range(t):\n flag=True\n n=int(input())\n x=int(input())\n arr=list(map(int,input().split()))\n arr.sort(reverse=True)\n while(len(arr)!=0):\n for k in range(len(arr)):\n arr[k]=arr[k]-1\n if(arr[k]==0):\n flag=False\n break\n for j in range(x):\n try:\n arr.pop()\n except :\n pass\n if(flag==True):\n print('Possible')\n else:\n print('Impossible')\n", "t = int(input())\nfor k in range(0,t):\n n = int(input())\n if n==1:\n x = int(input())\n g = int(input())\n if g == 1:\n print(\"Impossible\")\n else:\n print(\"Possible\")\n else:\n x = int(input())\n seq = input().split(\" \")\n game = []\n\n for j in range(0,n):\n game.append(int(seq[j]))\n game.sort()\n \n if(game[0]==1):\n print(\"Impossible\")\n else:\n print(\"Possible\")", "# cook your dish here\nfor _ in range(int(input())):\n n=int(input())\n x=int(input())\n a=list(map(int,input().split()))\n day=1\n ans=\"Possible\"\n a.sort()\n for i in range(0,len(a),x):\n if a[i]<=day:\n ans=\"Impossible\"\n break\n else:\n day+=1\n print(ans)", "t = int(input())\nlis = []\nfor i in range(t):\n\n n = int(input())\n x = int(input())\n expiry = [int(i) for i in input().split()]\n day = 1\n val = x\n\n expiry.sort()\n\n while(n > 0):\n\n if expiry[0] > day:\n expiry.pop(0)\n n = n-1\n val = val-1\n else:\n lis.append(\"Impossible\")\n break\n if(val == 0):\n day += 1\n val = x\n if(n == 0):\n lis.append(\"Possible\")\n'''\n for i in range(x):\n if expiry[i]>day:\n expiry.pop(0)\n n = n-1\n if n==0:\n lis.append(\"Possible\")\n break\n #val = False\n else:\n lis.append(\"Impossible\")\n break\n #val = False\n day+=1\n'''\nfor i in lis:\n print(i)\n", "for t in range(int(input())):\n n=int(input())\n x=int(input())\n a=list(map(int,input().strip().split()))\n a.sort()\n if a[0]==1:\n print(\"Impossible\")\n else:\n c=0\n p=0\n if a[n-1]<=x:\n print(\"Possible\")\n else:\n for i in range(n):\n if a[i]-x>0:\n c=c+1\n continue\n if c in a:\n p=1\n print(\"Impossible\")\n break\n if p==0:\n print(\"Possible\")\n \n \n\n \n", "for _ in range(int(input())):\n n = int(input())\n x = int(input())\n a = list(map(int, input().split()))\n s = sorted(a)\n flag = False\n if x>n:\n for i in range(n):\n if s[i]==1:\n break\n else:\n flag = True\n else:\n sub = 0\n b = n%x\n for i in range(n):\n if len(s)>b:\n for j in range(x):\n a = s[0] - sub\n #print(a)\n if a == 1:\n flag = False\n break\n else:\n del s[0]\n flag = True\n sub += 1\n if flag:\n pass\n else:\n break\n #print(s)\n if flag:\n print(\"Possible\")\n else:\n print(\"Impossible\")\n\n\n\n\n\n\n\n"]
{"inputs": [["3", "3", "5", "4 1 2", "5", "2", "4 4 3 2 2", "5", "1", "4 2 3 1 1"]], "outputs": [["Impossible", "Possible", "Impossible"]]}
INTERVIEW
PYTHON3
CODECHEF
8,960
dfef83c3297a4f1f6a0f6333f589ebab
UNKNOWN
You are at the top left cell $(1, 1)$ of an $n \times m$ labyrinth. Your goal is to get to the bottom right cell $(n, m)$. You can only move right or down, one cell per step. Moving right from a cell $(x, y)$ takes you to the cell $(x, y + 1)$, while moving down takes you to the cell $(x + 1, y)$. Some cells of the labyrinth contain rocks. When you move to a cell with rock, the rock is pushed to the next cell in the direction you're moving. If the next cell contains a rock, it gets pushed further, and so on. The labyrinth is surrounded by impenetrable walls, thus any move that would put you or any rock outside of the labyrinth is illegal. Count the number of different legal paths you can take from the start to the goal modulo $10^9 + 7$. Two paths are considered different if there is at least one cell that is visited in one path, but not visited in the other. -----Input----- The first line contains two integers $n, m$ — dimensions of the labyrinth ($1 \leq n, m \leq 2000$). Next $n$ lines describe the labyrinth. Each of these lines contains $m$ characters. The $j$-th character of the $i$-th of these lines is equal to "R" if the cell $(i, j)$ contains a rock, or "." if the cell $(i, j)$ is empty. It is guaranteed that the starting cell $(1, 1)$ is empty. -----Output----- Print a single integer — the number of different legal paths from $(1, 1)$ to $(n, m)$ modulo $10^9 + 7$. -----Examples----- Input 1 1 . Output 1 Input 2 3 ... ..R Output 0 Input 4 4 ...R .RR. .RR. R... Output 4 -----Note----- In the first sample case we can't (and don't have to) move, hence the only path consists of a single cell $(1, 1)$. In the second sample case the goal is blocked and is unreachable. Illustrations for the third sample case can be found here: https://assets.codeforces.com/rounds/1225/index.html
["def getSum(dp, pos, s, e, type_):\n if e < s:\n return 0\n \n if type_=='D':\n if e==m-1:\n return dp[pos][s]\n return dp[pos][s]-dp[pos][e+1]\n else:\n if e==n-1:\n return dp[s][pos]\n return dp[s][pos]-dp[e+1][pos]\n\nmod = 10**9+7\nn, m = map(int, input().split())\na = [list(list(map(lambda x: 1 if x=='R' else 0, input()))) for _ in range(n)] \n\nSD = [[0]*m for _ in range(n)]\nSN = [[0]*m for _ in range(n)]\ndpD = [[0]*m for _ in range(n)]\ndpN = [[0]*m for _ in range(n)]\n\nfor i in range(n-1, -1, -1):\n for j in range(m-1, -1, -1):\n if i == n-1:\n SD[i][j]=a[i][j] \n else:\n SD[i][j]=SD[i+1][j]+a[i][j]\n\n if j == m-1:\n SN[i][j]=a[i][j]\n else: \n SN[i][j]=SN[i][j+1]+a[i][j]\n \nfor j in range(m-1,-1,-1):\n if a[n-1][j]==1:\n break\n dpD[n-1][j]=1\n dpN[n-1][j]=1\n \nfor i in range(n-1,-1,-1):\n if a[i][m-1]==1:\n break\n dpD[i][m-1]=1\n dpN[i][m-1]=1\n \nfor j in range(m-2, -1, -1):\n if i==n-1:\n break\n dpD[n-1][j]+=dpD[n-1][j+1]\n \nfor i in range(n-2,-1,-1): \n if j==m-1:\n break\n dpN[i][m-1]+=dpN[i+1][m-1] \n \nfor i in range(n-2,-1,-1):\n for j in range(m-2,-1,-1):\n s, e = j, m-SN[i][j]-1\n #print(i, j, s, e, 'N')\n dpN[i][j] = getSum(dpD, i+1, s, e, 'D')\n dpN[i][j] = (dpN[i][j] + dpN[i+1][j]) % mod \n \n s, e = i, n-SD[i][j]-1\n #print(i, j, s, e, 'D')\n dpD[i][j] = getSum(dpN, j+1, s, e, 'N')\n\n if i != 0:\n for j in range(m-2,-1,-1): \n dpD[i][j] = (dpD[i][j] + dpD[i][j+1]) % mod \n \nprint(dpD[0][0] % mod) "]
{ "inputs": [ "1 1\n.\n", "2 3\n...\n..R\n", "4 4\n...R\n.RR.\n.RR.\nR...\n", "1 3\n.R.\n", "2 2\n.R\nR.\n", "10 10\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n" ], "outputs": [ "1\n", "0\n", "4\n", "0\n", "0\n", "48620\n" ] }
INTERVIEW
PYTHON3
CODEFORCES
1,833
f2f73d47387025589bfa5d5ccd1971bf
UNKNOWN
Tavak and Seyyed are good friends. Seyyed is very funny and he told Tavak to solve the following problem instead of longest-path. You are given l and r. For all integers from l to r, inclusive, we wrote down all of their integer divisors except 1. Find the integer that we wrote down the maximum number of times. Solve the problem to show that it's not a NP problem. -----Input----- The first line contains two integers l and r (2 ≤ l ≤ r ≤ 10^9). -----Output----- Print single integer, the integer that appears maximum number of times in the divisors. If there are multiple answers, print any of them. -----Examples----- Input 19 29 Output 2 Input 3 6 Output 3 -----Note----- Definition of a divisor: https://www.mathsisfun.com/definitions/divisor-of-an-integer-.html The first example: from 19 to 29 these numbers are divisible by 2: {20, 22, 24, 26, 28}. The second example: from 3 to 6 these numbers are divisible by 3: {3, 6}.
["l,r = map(int, input().split(\" \"))\nif l == r:\n print (l)\nelse:\n print (2)", "a, b = list(map(int, input().split()))\nif a != b:\n print(2)\nelse:\n print(a)\n", "l,r=map(int,input().split())\nif abs(l-r)>0:\n print(2)\nelse:\n print(l)", "L, R = [int(i) for i in input().split()]\n\nif L == R:\n print(L)\nelse:\n print(2)\n", "def __starting_point():\n l, r = list(map(int, input().split()))\n if l == r:\n print(l)\n else:\n print(2)\n\n__starting_point()", "l, r = map(int, input().split()) \nif l == r:\n print(l)\nelse:\n print(2)", "l, r = list(map(int, input().split()))\nif l == r:\n print(l)\nelse:\n print(2)\n", "l, r = map(int, input().split())\nprint(2 if r - l + 1 >= 2 else l)", "l,r = list(map(int,input().split()))\nif l==r:\n\tprint(l)\nelse:\n\tprint(2)\n", "l, r = [int(i) for i in input().split()]\nif l != r:\n print(2)\nelse:\n print(r)\n", "l,r = map(int, input().split())\nif l == r:\n print(l)\nelse:\n print(2)", "l, r = list(map(int, input().split()))\n\nif l == r:\n print(l)\nelse:\n print(2)\n", "x, y = list(map(int, input().split()))\n\nif x == y:\n print(x)\nelse:\n print(2)\n", "I = lambda: input().split()\nl, r = map(int, I())\nif l == r:\n print(l)\nelse:\n print(2)", "import sys\n\ndef solve():\n l, r = map(int, input().split())\n\n if l == r:\n ans = l\n else:\n ans = 2\n\n print(ans)\n\ndef __starting_point():\n solve()\n__starting_point()", "l, r = list(map(int, input().split()))\n\nif l == r:\n print(l)\nelse:\n print(2)\n", "l,r = map(int,input().split())\nif(l==r):\n\tprint(l)\nelse:\n\tprint(2)", "L, R = map(int, input().split())\nif (R != L):\n print(2)\nelse:\n print(L)", "tmp=input()\ntmp=tmp.split(' ')\nl=int(tmp[0])\nr=int(tmp[1])\nif (l==r):\n print(l)\nelse:\n print(2)\n", "l, r = map(int, input().split())\n\nif l == r:\n print(l)\nelse:\n print(2)", "import math,string,itertools,collections,re,fractions,array,copy\nimport bisect\nimport heapq\nfrom itertools import chain, dropwhile, permutations, combinations\nfrom collections import deque, defaultdict, OrderedDict, namedtuple, Counter, ChainMap\n\n\n# Guide:\n# 1. construct complex data types while reading (e.g. graph adj list)\n# 2. avoid any non-necessary time/memory usage\n# 3. avoid templates and write more from scratch\n# 4. switch to \"flat\" implementations\n\ndef VI(): return list(map(int,input().split()))\ndef I(): return int(input())\ndef LIST(n,m=None): return [0]*n if m is None else [[0]*m for i in range(n)]\ndef ELIST(n): return [[] for i in range(n)]\ndef MI(n=None,m=None): # input matrix of integers\n if n is None: n,m = VI()\n arr = LIST(n)\n for i in range(n): arr[i] = VI()\n return arr\ndef MS(n=None,m=None): # input matrix of strings\n if n is None: n,m = VI()\n arr = LIST(n)\n for i in range(n): arr[i] = input()\n return arr\ndef MIT(n=None,m=None): # input transposed matrix/array of integers\n if n is None: n,m = VI()\n a = MI(n,m)\n arr = LIST(m,n)\n for i,l in enumerate(a):\n for j,x in enumerate(l):\n arr[j][i] = x\n return arr\n\ndef main(info=0):\n # n = I()\n # a = VI()\n # aa = MI()\n # s = input()\n # ss = MS()\n # n,m = VI()\n # u,v,w = MIT(n,m)\n # img = MS(n,m)\n l,r = VI()\n #math.gcd(l,r)\n if l==r:\n print(l)\n return\n print(2)\n\n\n\n\ndef __starting_point():\n main()\n\n__starting_point()", "l, r = list(map(int, input().split()))\nif l != r:\n\tprint(\"2\")\nelse:\n\tprint(l)\n", "l, r = list(map(int, input().split()))\nl1, r1 = l, r\nif l == r:\n print(l)\nelse:\n print(2)\n", "def Main():\n\ta, b = map(int ,input().split())\n\tif a == b:\n\t\tprint(a)\n\telse:\n\t\tprint(2)\n\t\ndef __starting_point():\n Main()\n__starting_point()"]
{ "inputs": [ "19 29\n", "3 6\n", "39 91\n", "76 134\n", "93 95\n", "17 35\n", "94 95\n", "51 52\n", "47 52\n", "38 98\n", "30 37\n", "56 92\n", "900000000 1000000000\n", "37622224 162971117\n", "760632746 850720703\n", "908580370 968054552\n", "951594860 953554446\n", "347877978 913527175\n", "620769961 988145114\n", "820844234 892579936\n", "741254764 741254768\n", "80270976 80270977\n", "392602363 392602367\n", "519002744 519002744\n", "331900277 331900277\n", "419873015 419873018\n", "349533413 349533413\n", "28829775 28829776\n", "568814539 568814539\n", "720270740 720270743\n", "871232720 871232722\n", "305693653 305693653\n", "634097178 634097179\n", "450868287 450868290\n", "252662256 252662260\n", "575062045 575062049\n", "273072892 273072894\n", "770439256 770439256\n", "2 1000000000\n", "6 8\n", "2 879190747\n", "5 5\n", "999999937 999999937\n", "3 3\n", "5 100\n", "2 2\n", "3 18\n", "7 7\n", "39916801 39916801\n", "3 8\n", "13 13\n", "4 8\n", "3 12\n", "6 12\n", "999999103 999999103\n", "100000007 100000007\n", "3 99\n", "999999733 999999733\n", "5 10\n", "982451653 982451653\n", "999900001 1000000000\n", "999727999 999727999\n", "2 999999999\n", "242 244\n", "3 10\n", "15 27\n", "998244353 998244353\n", "5 15\n", "999999797 999999797\n", "2 3\n", "999999929 999999929\n", "3 111111\n", "12 18\n", "479001599 479001599\n", "10000019 10000019\n", "715827883 715827883\n", "999992977 999992977\n", "11 11\n", "29 29\n", "1000003 1000003\n", "6 15\n", "1200007 1200007\n", "3 1000000000\n", "990000023 990000023\n", "1717 1717\n", "141650963 141650963\n", "1002523 1002523\n", "900000011 900000011\n", "104729 104729\n", "4 12\n", "100003 100003\n", "17 17\n", "10 100\n" ], "outputs": [ "2\n", "2\n", "2\n", "2\n", "2\n", "2\n", "2\n", "2\n", "2\n", "2\n", "2\n", "2\n", "2\n", "2\n", "2\n", "2\n", "2\n", "2\n", "2\n", "2\n", "2\n", "2\n", "2\n", "519002744\n", "331900277\n", "2\n", "349533413\n", "2\n", "568814539\n", "2\n", "2\n", "305693653\n", "2\n", "2\n", "2\n", "2\n", "2\n", "770439256\n", "2\n", "2\n", "2\n", "5\n", "999999937\n", "3\n", "2\n", "2\n", "2\n", "7\n", "39916801\n", "2\n", "13\n", "2\n", "2\n", "2\n", "999999103\n", "100000007\n", "2\n", "999999733\n", "2\n", "982451653\n", "2\n", "999727999\n", "2\n", "2\n", "2\n", "2\n", "998244353\n", "2\n", "999999797\n", "2\n", "999999929\n", "2\n", "2\n", "479001599\n", "10000019\n", "715827883\n", "999992977\n", "11\n", "29\n", "1000003\n", "2\n", "1200007\n", "2\n", "990000023\n", "1717\n", "141650963\n", "1002523\n", "900000011\n", "104729\n", "2\n", "100003\n", "17\n", "2\n" ] }
INTERVIEW
PYTHON3
CODEFORCES
3,903
36668bb32d23a116835d68fc906ca9ac
UNKNOWN
"QAQ" is a word to denote an expression of crying. Imagine "Q" as eyes with tears and "A" as a mouth. Now Diamond has given Bort a string consisting of only uppercase English letters of length n. There is a great number of "QAQ" in the string (Diamond is so cute!). $8$ illustration by 猫屋 https://twitter.com/nekoyaliu Bort wants to know how many subsequences "QAQ" are in the string Diamond has given. Note that the letters "QAQ" don't have to be consecutive, but the order of letters should be exact. -----Input----- The only line contains a string of length n (1 ≤ n ≤ 100). It's guaranteed that the string only contains uppercase English letters. -----Output----- Print a single integer — the number of subsequences "QAQ" in the string. -----Examples----- Input QAQAQYSYIOIWIN Output 4 Input QAQQQZZYNOIWIN Output 3 -----Note----- In the first example there are 4 subsequences "QAQ": "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN".
["s=input()\nans = 0\nfor i in range(len(s)):\n if s[i] == 'A':\n ans += s[:i].count('Q') * s[i:].count('Q')\nprint(ans)", "from sys import stdin, stdout\nfrom random import randrange\n\ns = stdin.readline().strip()\nn = len(s)\nans = 0\n\nfor i in range(n):\n for j in range(i + 1, n):\n for z in range(j + 1, n):\n if s[i] == 'Q' and s[j] == 'A' and s[z] == 'Q':\n ans += 1\n\nstdout.write(str(ans))", "\na = input()\nans = 0\nn=len(a)\nfor j in range(n-2):\n for i in range(j+1,n-1):\n for t in range(i+1,n):\n if a[j] == 'Q' and a[i] =='A' and a[t] == 'Q':\n ans+=1\nprint(ans)\n", "s = input()\nan = 0\nfor i in range(len(s)):\n for j in range(i + 1, len(s)):\n for k in range(j + 1, len(s)):\n if s[i] + s[j] + s[k] == 'QAQ':\n an += 1\nprint(an)\n", "s = str(input())\nn = len(s)\ncnt = 0\nfor i in range(0, n):\n for j in range(i + 1, n):\n for k in range(j + 1, n):\n if s[i] == 'Q' and s[j] == 'A' and s[k] == 'Q':\n cnt = cnt + 1\nprint(cnt)", "s = input()\nans = 0\nfor i in range(len(s)):\n for j in range(i + 1, len(s)):\n if s[i] == 'Q' and s[j] == 'A':\n ans += s[j + 1:].count('Q')\nprint(ans)\n", "n=input()\ni=0\nfor x in range(len(n)):\n if n[x]=='Q':\n for y in range(x,len(n)):\n if n[y]=='A':\n for z in range(y,len(n)):\n if n[z]=='Q':\n i+=1\nprint(i)\n", "a = input()\ns=0\nfor i in range(len(a)-2):\n for j in range(i+1,len(a)-1):\n for k in range(j+1, len(a)):\n if a[i]+a[j]+a[k]=='QAQ': s+=1\nprint(s)\n", "x = input()\nn = len( x )\n\nans = 0\n\nfor i in range( n ):\n for j in range( i+1, n ):\n for k in range( j+1, n ):\n if x[i] == 'Q' and x[j] == 'A' and x[k] == 'Q':\n ans += 1\n\nprint( ans )\n", "x = input()\nn = 0\nfor i in range(len(x)):\n if x[i] == 'Q':\n for j in range(i, len(x)):\n if x[j] == 'A':\n for k in range(j, len(x)):\n if x[k] == 'Q':\n n += 1\nprint(n)", "s = input()\nn = len(s)\nans = 0\nfor i in range(n):\n for j in range(i + 1, n):\n for k in range(j + 1, n):\n if s[i] == s[k] == 'Q' and s[j] == 'A':\n ans += 1\nprint(ans)", "# Main maut ko takiya, aur kafan ko chaadar banakar audhta hoon!\n\ns=input()\n\nans=0\n\nfor i in range(len(s)):\n\t\n\tif(s[i]=='A'):\n\t\tql=s[:i].count(\"Q\")\n\t\tqr=s[i+1:].count(\"Q\")\n\t\t\n\t\tans+=ql*qr\n\t\t\nprint(ans)\n\n\n", "s = input()\nr = ''\nfor i in s:\n\tif i in 'QA':\n\t\tr += i\nwhile len(r) and r[0] != 'Q':\n\tr = r[1:]\nwhile len(r) and r[-1] != 'Q':\n\tr = r[:-1]\nres = 0\nfor i in range(len(r)):\n\tif r[i] == 'A':\n\t\tres += r[:i].count('Q') * r[i + 1:].count('Q')\nprint(res)", "s = input()\nres = 0\nfor i in range(len(s)):\n for j in range(i + 1, len(s)):\n for k in range(j + 1, len(s)):\n if s[i] + s[j] + s[k] == \"QAQ\":\n res += 1\nprint(res)", "s = list(input())\nn = len(s)\n\nans = 0\nfor i in range(n - 2):\n if s[i] != 'Q':\n continue\n for j in range(i + 1, n - 1):\n if s[j] != 'A':\n continue\n for k in range(j + 1, n):\n if s[k] != 'Q':\n continue\n ans += 1\nprint(ans)\n", "# -*- coding: utf-8 -*-\n\nimport math\nimport collections\nimport bisect\nimport heapq\nimport time\nimport random\nimport itertools\nimport sys\n\n\"\"\"\ncreated by shhuan at 2017/11/19 21:52\n\n\"\"\"\n\nS = input()\n\nN = len(S)\nans = 0\nfor i in range(N):\n if S[i] != 'Q':\n continue\n for j in range(i+1, N):\n if S[j] != 'A':\n continue\n for k in range(j+1, N):\n if S[k] == 'Q':\n ans += 1\n\nprint(ans)", "s=input()\nn=len(s)\nans=0\nfor i in range(n-2):\n for j in range(i+1,n-1):\n for k in range(j+1,n):\n if s[i]=='Q' and s[j]=='A' and s[k]=='Q':\n ans+=1\nprint(ans)", "s = input()\n\nk = 0\nfor x in range(0, len(s) - 2):\n for y in range(x + 1, len(s) - 1):\n for z in range(y + 1, len(s)):\n if s[x] == 'Q' and s[y] == 'A' and s[z] == 'Q':\n k += 1\n\nprint(k)\n", "k = input('')\nanswer = 0\nfor i in range(len(k)):\n if k[i] == 'Q':\n for j in range(i + 1, len(k)):\n if k[j] == 'A':\n for z in range(j + 1, len(k)):\n if k[z] == 'Q':\n answer += 1\nprint(answer)", "# IAWT\ns = input()\nans = 0\nfor i in range(len(s)):\n for j in range(i+1, len(s)):\n for k in range(j+1, len(s)):\n if s[i] == 'Q' and s[j] == 'A' and s[k] == 'Q':\n ans += 1\n\nprint(ans)\n", "s = input()\n\na = 0\nq = 0\nans = 0\n\nfor c in s:\n if c == 'Q':\n ans += a\n q += 1\n if c == 'A':\n a += q\n\nprint(ans)\n", "s = input()\ncount = 0\nfor i in range(len(s)):\n\tif s[i] == 'Q':\n\t\tfor j in range(i + 1, len(s)):\n\t\t\tif s[j] == 'A':\n\t\t\t\tfor k in range(j + 1, len(s)):\n\t\t\t\t\tif s[k] == 'Q':\n\t\t\t\t\t\tcount += 1\nprint(count)\n", "#http://codeforces.com/contest/894/problem/0\n#solved\n\narray = input()\na = len(array)\no = 0\n\nfor i in range(a):\n if array[i] == \"Q\":\n for j in range(i + 1, a):\n if array[j] == \"A\":\n for k in range(j + 1, a):\n if array[k] == \"Q\":\n o += 1\n\nprint(o)", "str1 = input()\nans = 0\nfor i,char1 in enumerate(str1):\n\tif char1 == 'A':\n\t\tcount1 = 0\n\t\tcount2 = 0\n\t\tfor j in range(i):\n\t\t\tif (str1[j] == 'Q'):\n\t\t\t\tcount1+= 1\n\t\tfor j in range(i+1, len(str1)):\n\t\t\tif (str1[j] == 'Q'):\n\t\t\t\tcount2+= 1\n\t\tans += count1*count2\nprint(ans)", "q=input()\na,s=[],[]\nfor i in range(0,len(q)):\n if q[i]=='Q':\n a.append(i)\n elif q[i]=='A':\n s.append(i)\nans=0\nfor i in a:\n h=list([x for x in s if x>i])\n for j in h:\n ans+=len(list([y for y in a if y>j]))\nprint(ans)\n"]
{ "inputs": [ "QAQAQYSYIOIWIN\n", "QAQQQZZYNOIWIN\n", "QA\n", "IAQVAQZLQBQVQFTQQQADAQJA\n", "QQAAQASGAYAAAAKAKAQIQEAQAIAAIAQQQQQ\n", "AMVFNFJIAVNQJWIVONQOAOOQSNQSONOASONAONQINAONAOIQONANOIQOANOQINAONOQINAONOXJCOIAQOAOQAQAQAQAQWWWAQQAQ\n", "AAQQAXBQQBQQXBNQRJAQKQNAQNQVDQASAGGANQQQQTJFFQQQTQQA\n", "KAZXAVLPJQBQVQQQQQAPAQQGQTQVZQAAAOYA\n", "W\n", "DBA\n", "RQAWNACASAAKAGAAAAQ\n", "QJAWZAAOAAGIAAAAAOQATASQAEAAAAQFQQHPA\n", "QQKWQAQAAAAAAAAGAAVAQUEQQUMQMAQQQNQLAMAAAUAEAAEMAAA\n", "QQUMQAYAUAAGWAAAQSDAVAAQAAAASKQJJQQQQMAWAYYAAAAAAEAJAXWQQ\n", "QORZOYAQ\n", "QCQAQAGAWAQQQAQAVQAQQQQAQAQQQAQAAATQAAVAAAQQQQAAAUUQAQQNQQWQQWAQAAQQKQYAQAAQQQAAQRAQQQWBQQQQAPBAQGQA\n", "QQAQQAKQFAQLQAAWAMQAZQAJQAAQQOACQQAAAYANAQAQQAQAAQQAOBQQJQAQAQAQQQAAAAABQQQAVNZAQQQQAMQQAFAAEAQAQHQT\n", "AQEGQHQQKQAQQPQKAQQQAAAAQQQAQEQAAQAAQAQFSLAAQQAQOQQAVQAAAPQQAWAQAQAFQAXAQQQQTRLOQAQQJQNQXQQQQSQVDQQQ\n", "QNQKQQQLASQBAVQQQQAAQQOQRJQQAQQQEQZUOANAADAAQQJAQAQARAAAQQQEQBHTQAAQAAAAQQMKQQQIAOJJQQAQAAADADQUQQQA\n", "QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ\n", "AMQQAAQAAQAAAAAAQQQBOAAANAAKQJCYQAE\n", "AYQBAEQGAQEOAKGIXLQJAIAKQAAAQPUAJAKAATFWQQAOQQQUFQYAQQMQHOKAAJXGFCARAQSATHAUQQAATQJJQDQRAANQQAE\n", "AAQXAAQAYQAAAAGAQHVQYAGIVACADFAAQAAAAQZAAQMAKZAADQAQDAAQDAAAMQQOXYAQQQAKQBAAQQKAXQBJZDDLAAHQQ\n", "AYQQYAVAMNIAUAAKBBQVACWKTQSAQZAAQAAASZJAWBCAALAARHACQAKQQAQAARPAQAAQAQAAZQUSHQAMFVFZQQQQSAQQXAA\n", "LQMAQQARQAQBJQQQAGAAZQQXALQQAARQAQQQQAAQQAQQQAQQCAQQAQQAYQQQRAAZATQALYQQAAHHAAQHAAAAAAAAQQMAAQNAKQ\n", "MAQQWAQOYQMAAAQAQPQZAOAAQAUAQNAAQAAAITQSAQAKAQKAQQWSQAAQQAGUCDQMQWKQUXKWQQAAQQAAQQZQDQQQAABXQUUXQOA\n", "QTAAQDAQXAQQJQQQGAAAQQQQSBQZKAQQAQQQQEAQNUQBZCQLYQZQEQQAAQHQVAORKQVAQYQNASZQAARZAAGAAAAOQDCQ\n", "QQWAQQGQQUZQQQLZAAQYQXQVAQFQUAQZUQZZQUKBHSHTQYLQAOQXAQQGAQQTQOAQARQADAJRAAQPQAQQUQAUAMAUVQAAAQQAWQ\n", "QQAAQQAQVAQZQQQQAOEAQZPQIBQZACQQAFQQLAAQDATZQANHKYQQAQTAAFQRQAIQAJPWQAQTEIRXAEQQAYWAAAUKQQAQAQQQSQQH\n", "AQQQQAQAAQQAQAQAAAAAAAAAQAQAAAAAQAQAQQQAQQQAAAQQQAAAAAAAQAAAAQQQQQQQAQQQQAQAAAQAAAAAQAQAAAAAQAQAAAA\n", "AQQQQAQAAQQAQAQAAAAAAAAAQAQAAAAAQAQAQQQAQQQAAAQQQAAAAAAAQAAAAQQQQQQQAQQQQAQAAAQAAAAAQAQAAAAAQ\n", "AQQQQAQAAQQAQAQAAAAAAAAAQAQAAAAAQAQAQQQAQQQAAAQQQAAAAAAAQAAAAQQQQQQQAQQQQAQAAAQAAAAAQAQAAAAAQAQAA\n", "AQQQQAQAAQQAQAQAAAAAAAAAQAQAAAAAQAQAQQQAQQQAAAQQQAAAAAAAQAAAAQQQQQQQAQQQQAQAAAQAAAAAQAQAAAAAQQAA\n", "QQQQQAQAAQQAQAQAAAAAAAAAQAQAAAAAQAQAQQQAQQQAAAQQQAAAAAAAQAAAAQQQQQQQAQQQQAQAAAQAAAAAQAQAAAAAQAQAA\n", "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ\n", "QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\n", "QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ\n", "QAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQA\n", "AQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQ\n", "Q\n", "A\n", "FFF\n", "AAAAAA\n" ], "outputs": [ "4\n", "3\n", "0\n", "24\n", "378\n", "1077\n", "568\n", "70\n", "0\n", "0\n", "10\n", "111\n", "411\n", "625\n", "1\n", "13174\n", "10420\n", "12488\n", "9114\n", "35937\n", "254\n", "2174\n", "2962\n", "2482\n", "7768\n", "5422\n", "3024\n", "4527\n", "6416\n", "14270\n", "13136\n", "14270\n", "14231\n", "15296\n", "0\n", "0\n", "0\n", "20825\n", "20825\n", "0\n", "0\n", "0\n", "0\n" ] }
INTERVIEW
PYTHON3
CODEFORCES
6,195
da12fd2bd3273a557cd0636217fa1ba9
UNKNOWN
Write a function that accepts a square matrix (`N x N` 2D array) and returns the determinant of the matrix. How to take the determinant of a matrix -- it is simplest to start with the smallest cases: A 1x1 matrix `|a|` has determinant `a`. A 2x2 matrix `[ [a, b], [c, d] ]` or ``` |a b| |c d| ``` has determinant: `a*d - b*c`. The determinant of an `n x n` sized matrix is calculated by reducing the problem to the calculation of the determinants of `n` matrices of`n-1 x n-1` size. For the 3x3 case, `[ [a, b, c], [d, e, f], [g, h, i] ]` or ``` |a b c| |d e f| |g h i| ``` the determinant is: `a * det(a_minor) - b * det(b_minor) + c * det(c_minor)` where `det(a_minor)` refers to taking the determinant of the 2x2 matrix created by crossing out the row and column in which the element a occurs: ``` |- - -| |- e f| |- h i| ``` Note the alternation of signs. The determinant of larger matrices are calculated analogously, e.g. if M is a 4x4 matrix with first row `[a, b, c, d]`, then: `det(M) = a * det(a_minor) - b * det(b_minor) + c * det(c_minor) - d * det(d_minor)`
["def determinant(m):\n a = 0\n if len(m) == 1:\n a = m[0][0]\n else:\n for n in xrange(len(m)):\n if (n + 1) % 2 == 0:\n a -= m[0][n] * determinant([o[:n] + o[n+1:] for o in m[1:]])\n else:\n a += m[0][n] * determinant([o[:n] + o[n+1:] for o in m[1:]])\n \n return a", "import numpy as np\n\ndef determinant(a):\n return round(np.linalg.det(np.matrix(a)))", "import numpy as np\ndef determinant(matrix):\n return round(np.linalg.det(matrix))", "def determinant(matrix):\n #your code here\n result = 0\n l = len(matrix)\n\n #base case when length of matrix is 1\n if l == 1:\n return matrix[0][0]\n\n #base case when length of matrix is 2\n if l == 2:\n return matrix[0][0] * matrix[1][1] - matrix[0][1] * matrix[1][0]\n\n #for length of matrix > 2\n for j in range(0, l):\n # create a sub matrix to find the determinant\n if l!=2:\n sub_matrix = [] \n sub_matrix = [(row[0:j]+row[j+1:]) for row in matrix[1:]]\n result = result + (-1)**j * matrix[0][j] * determinant(sub_matrix)\n return result", "def determinant(matrix):\n return reduce(lambda r, i:r+(-1)**i*matrix[0][i]*determinant([m[:i]+m[i+1:] for m in matrix[1:]]),range(len(matrix[0])),0) if len(matrix) != 1 else matrix[0][0]", "def sub_determinant(matrix, i):\n sub_matrix = []\n for j in range(1,len(matrix)):\n sub_matrix.append(matrix[j][:i] + matrix[j][i+1:])\n return sub_matrix\n \ndef determinant(matrix):\n if len(matrix) == 0:\n return 0\n elif len(matrix) == 1:\n return matrix[0][0]\n elif len(matrix) == 2:\n return matrix[0][0] * matrix[1][1] - matrix[0][1]*matrix[1][0]\n else:\n sum = 0\n for i in range(0,len(matrix)):\n if 1 == i & 1:\n sum = sum - matrix[0][i] * determinant(sub_determinant(matrix,i))\n else:\n sum = sum + matrix[0][i] * determinant(sub_determinant(matrix,i))\n return sum\n", "def determinant(m):\n ans,sizeM = 0, len(m)\n if sizeM == 1: return m[0][0]\n for n in range(sizeM):\n ans+= (-1)**n * m[0][n] * determinant([ m[i][:n]+m[i][n+1:] for i in range(1,sizeM) ])\n return ans", "from numpy.linalg import det\ndeterminant=lambda m: int(round(det(m))) ", "def determinant(m):\n if len(m) == 1 : return m[0][0]\n if len(m) == 2 : return (m[0][0]*m[1][1]) - (m[0][1]*m[1][0])\n li = [[m[j][:i] + m[j][i+1:] for j in range(1,len(m))] for i in range(len(m))]\n return sum(-m[0][i]*(determinant(j)) if i&1 else m[0][i]*(determinant(j)) for i,j in enumerate(li))", "import numpy as np\n\n\ndef determinant(matrix):\n return np.linalg.det(matrix).round()\n"]
{"fn_name": "determinant", "inputs": [[[[5]]]], "outputs": [[5]]}
INTERVIEW
PYTHON3
CODEWARS
2,814
def determinant(matrix):
df17d16a333eab1b9abfcd790e35eee3
UNKNOWN
Write a function called `sumIntervals`/`sum_intervals()` that accepts an array of intervals, and returns the sum of all the interval lengths. Overlapping intervals should only be counted once. ### Intervals Intervals are represented by a pair of integers in the form of an array. The first value of the interval will always be less than the second value. Interval example: `[1, 5]` is an interval from 1 to 5. The length of this interval is 4. ### Overlapping Intervals List containing overlapping intervals: ``` [ [1,4], [7, 10], [3, 5] ] ``` The sum of the lengths of these intervals is 7. Since [1, 4] and [3, 5] overlap, we can treat the interval as [1, 5], which has a length of 4. ### Examples: ```C# // empty intervals Intervals.SumIntervals(new (int, int)[]{ }); // => 0 Intervals.SumIntervals(new (int, int)[]{ (2, 2), (5, 5)}); // => 0 // disjoined intervals Intervals.SumIntervals(new (int, int)[]{ (1, 2), (3, 5) }); // => (2-1) + (5-3) = 3 // overlapping intervals Intervals.SumIntervals(new (int, int)[]{ (1, 4), (3, 6), (2, 8) }); // (1,8) => 7 ```
["def sum_of_intervals(intervals):\n s, top = 0, float(\"-inf\")\n for a,b in sorted(intervals):\n if top < a: top = a\n if top < b: s, top = s+b-top, b\n return s", "def sum_of_intervals(intervals):\n result = set()\n for start, stop in intervals:\n for x in range(start, stop):\n result.add(x)\n \n return len(result)", "def sum_of_intervals(intervals):\n return len(set([n for (a, b) in intervals for n in [i for i in range(a, b)]]))", "def sum_of_intervals(intervals): \n s = []\n for i in intervals:\n s += list(range(i[0],i[1]))\n return len(set(s))", "from itertools import chain\n\ndef sum_of_intervals(intervals):\n return len(set(chain.from_iterable(range(*i) for i in intervals)))", "def sum_of_intervals(intervals):\n total = set()\n for x,y in intervals:\n for i in range(x,y):\n total.add(i) \n return(len(total))", "def sum_of_intervals(intervals):\n return len(set().union(*[list(range(*item))for item in intervals]))", "sum_of_intervals=lambda a:len(set.union(*(set(range(*i))for i in a)))", "def sum_of_intervals(intervals):\n return len(set([i for a,b in intervals for i in range(a,b)]))", "def sum_of_intervals(intervals):\n result = set()\n for start, end in intervals:\n result |= set(range(start, end))\n return len(result)", "def sum_of_intervals(intervals):\n sets = set()\n for a, b in intervals:\n sets.update(list(range(a, b)))\n return len(sets)\n", "def sum_of_intervals(intervals):\n return len(set([n for a,b in intervals for n in list(range(a,b))]))", "from bisect import bisect\ndef sum_of_intervals(intervals):\n I = []\n for a, b in intervals:\n i = bisect(I, a)\n j = bisect(I, b)\n I = I[:i] + [a]*(1-i%2) + [b]*(1-j%2) + I[j:]\n return sum(I[1::2]) - sum(I[::2])", "def sum_of_intervals(intervals):\n #1) get range of each tuplem -> list\n #2) turn \"list\" obj into \"set\" obj to remove repeats\n #3) return the length of the final \"set\" obj\n return len(set([i for t in intervals for i in range(t[0],t[-1])]))", "def sum_of_intervals(intervals):\n answer = []\n for tup in intervals:\n for j in range(tup[0],tup[1]):\n answer.append(j)\n return len(list(set(answer)))", "def sum_of_intervals(intervals):\n intervals.sort()\n x = 0\n while x < len(intervals) -1:\n if intervals[x][0] <= intervals[x+1][0] and intervals[x][1] >= intervals[x+1][1]:\n intervals.pop( x+1)\n elif intervals[x][0] <= intervals[x+1][0] and intervals[x][1] >= intervals[x+1][0] and intervals[x][1] < intervals[x+1][1]:\n intervals[x] = (intervals[x][0], intervals[x+1][1])\n intervals.pop(x+1)\n else:\n x+=1\n\n return sum(intervals[x][1] - intervals[x][0] for x in range(len(intervals)))", "def sum_of_intervals(intervals):\n list1=[]\n for i in intervals:\n for j in range(i[0],i[1]):\n list1.append(j)\n set1=set(list1)\n return len(set1)", "import functools\ndef sum_of_intervals(intervals):\n return len(functools.reduce(lambda x,y:x|y,[set(range(x,y)) for x,y in intervals]))", "def sum_of_intervals(intervals):\n return len({a for interval in intervals for a in range(*interval)})", "def sum_of_intervals(intervals):\n\n # Merge the intervals so that all intervals are disjoint\n merged = sorted([list(t) for t in intervals])\n i = 0\n while i < len(merged) - 1:\n if merged[i + 1][1] <= merged[i][1]:\n # Next interval is a subset of current interval\n del merged[i + 1]\n continue\n if merged[i + 1][0] <= merged[i][1]:\n # Next interval has some overlap with currenrt interval\n merged[i][1] = merged[i + 1][1]\n del merged[i + 1]\n continue\n i += 1\n \n # Calculate the sum of the disjoint intervals\n return sum(b - a for a, b in merged)\n"]
{"fn_name": "sum_of_intervals", "inputs": [[[[1, 5]]]], "outputs": [[4]]}
INTERVIEW
PYTHON3
CODEWARS
4,036
def sum_of_intervals(intervals):
81ac9bf45f0e92d99caecf1e3447a1b8
UNKNOWN
# Task You are given integer `n` determining set S = {1, 2, ..., n}. Determine if the number of k-element subsets of S is `ODD` or `EVEN` for given integer k. # Example For `n = 3, k = 2`, the result should be `"ODD"` In this case, we have 3 2-element subsets of {1, 2, 3}: `{1, 2}, {1, 3}, {2, 3}` For `n = 2, k = 1`, the result should be `"EVEN"`. In this case, we have 2 1-element subsets of {1, 2}: `{1}, {2}` `Don't bother with naive solution - numbers here are really big.` # Input/Output - `[input]` integer `n` `1 <= n <= 10^9` - `[input]` integer `k` `1 <= k <= n` - `[output]` a string `"EVEN"` or `"ODD"` depending if the number of k-element subsets of S = {1, 2, ..., n} is ODD or EVEN.
["def subsets_parity(n, k):\n return 'EVEN' if ~n & k else 'ODD'", "subsets_parity=lambda n,k:~n&k and\"EVEN\"or\"ODD\"", "subsets_parity=s=lambda n,k:n<k and\"EVEN\"or n<2and\"ODD\"or(lambda b:s(n&~b,k&~b))(1<<n.bit_length()-1)", "#Courtesy of giants :D\ndef subsets_parity(n,k):\n N,K = bin(n)[2:][::-1], bin(k)[2:][::-1]\n for i in range(len(K)):\n if K[i] > N[i]:\n return 'EVEN'\n return 'ODD'", "#using lucas's theorem https://en.wikipedia.org/wiki/Lucas%27s_theorem\n\ndef to_bin(n):\n k = 0\n while n >= 2**k: k += 1\n s = \"\"\n for i in range(k - 1, -1, -1):\n if n - 2**i >= 0: \n s += \"1\"\n n -= 2**i\n else: s += \"0\"\n return s\n\ndef subsets_parity(n, k):\n s1 = to_bin(n)\n s2 = to_bin(k)\n for i in range(-1, -len(s2) - 1, -1):\n if s1[i] == \"0\" and s2[i] == \"1\": return \"EVEN\"\n return \"ODD\"", "def subsets_parity(n,k):\n string_set = \"{:02b}\".format(n)\n length = len(string_set)\n string_subset = \"{:02b}\".format(k).zfill(length)\n for i in range(0, length):\n if not int(string_set[i]) and int(string_subset[i]):\n return \"EVEN\"\n break\n else:\n return \"ODD\"", "import math\n\ndef f1(n):\n x,s=1,0\n while 2**x<=n:\n s=s+ math.floor(n/2**x)\n x=x+1\n return (s)\n\ndef subsets_parity(n,k):\n if n==k:\n return \"ODD\"\n if n>0 and k>0 and n-k>0:\n if f1(n) == f1(k) + f1(n-k):\n return \"ODD\"\n else:\n return \"EVEN\"\n \n \n", "def subsets_parity(n,k):\n while k:\n if not n & 1 and k & 1: return 'EVEN'\n n, k = n // 2, k // 2\n return 'ODD'", "def c(n):\n m = 0\n while n > 0:\n n = n // 2\n m += n\n return m\n\ndef subsets_parity(n,k):\n return \"EVEN\" if (c(n)-c(k)-c(n-k))>0 else \"ODD\"", "def subsets_parity(n,k):\n return 'ODD' if n==k|(n-k) else 'EVEN'"]
{"fn_name": "subsets_parity", "inputs": [[3, 2], [2, 1], [1, 1], [20, 10], [48, 12]], "outputs": [["ODD"], ["EVEN"], ["ODD"], ["EVEN"], ["EVEN"]]}
INTERVIEW
PYTHON3
CODEWARS
1,979
def subsets_parity(n,k):
8a21042bf3144d32d8bd7c3caf36feaf
UNKNOWN
# 'Magic' recursion call depth number This Kata was designed as a Fork to the one from donaldsebleung Roboscript series with a reference to: https://www.codewars.com/collections/roboscript It is not more than an extension of Roboscript infinite "single-" mutual recursion handling to a "multiple-" case. One can suppose that you have a machine that works through a specific language. It uses the script, which consists of 3 major commands: - `F` - Move forward by 1 step in the direction that it is currently pointing. - `L` - Turn "left" (i.e. rotate 90 degrees anticlockwise). - `R` - Turn "right" (i.e. rotate 90 degrees clockwise). The number n afterwards enforces the command to execute n times. To improve its efficiency machine language is enriched by patterns that are containers to pack and unpack the script. The basic syntax for defining a pattern is as follows: `pnq` Where: - `p` is a "keyword" that declares the beginning of a pattern definition - `n` is a non-negative integer, which acts as a unique identifier for the pattern (pay attention, it may contain several digits). - `` is a valid RoboScript code (without the angled brackets) - `q` is a "keyword" that marks the end of a pattern definition For example, if you want to define `F2LF2` as a pattern and reuse it later: ``` p333F2LF2q ``` To invoke a pattern, a capital `P` followed by the pattern identifier `(n)` is used: ``` P333 ``` It doesn't matter whether the invocation of the pattern or the pattern definition comes first. Pattern definitions should always be parsed first. ``` P333p333P11F2LF2qP333p11FR5Lq ``` # ___Infinite recursion___ As we don't want a robot to be damaged or damaging someone else by becoming uncontrolable when stuck in an infinite loop, it's good to considere this possibility in the programs and to build a compiler that can detect such potential troubles before they actually happen. * ### Single pattern recursion infinite loop This is the simplest case, that occurs when the pattern is invoked inside its definition: p333P333qP333 => depth = 1: P333 -> (P333) * ### Single mutual recursion infinite loop Occurs when a pattern calls to unpack the mutual one, which contains a callback to the first: p1P2qp2P1qP2 => depth = 2: P2 -> P1 -> (P2) * ### Multiple mutual recursion infinite loop Occurs within the combo set of mutual callbacks without termination: p1P2qp2P3qp3P1qP3 => depth = 3: P3 -> P1 -> P2 -> (P3) * ### No infinite recursion: terminating branch This happens when the program can finish without encountering an infinite loop. Meaning the depth will be considered 0. Some examples below: P4p4FLRq => depth = 0 p1P2qp2R5qP1 => depth = 0 p1P2qp2P1q => depth = 0 (no call) # Task Your interpreter should be able to analyse infinite recursion profiles in the input program, including multi-mutual cases. Though, rather than to analyse only the first encountered infinite loop and get stuck in it like the robot would be, your code will have continue deeper in the calls to find the depth of any infinite recursion or terminating call. Then it should return the minimal and the maximal depths encountered, as an array `[min, max]`. ### About the exploration of the different possible branches of the program: * Consider only patterns that are to be executed: ``` p1P1q => should return [0, 0], there is no execution p1P2P3qp2P1qp3P1q => similarly [0, 0] p1P1qP1 => returns [1, 1] ``` * All patterns need to be executed, strictly left to right. Meaning that you may encounter several branches: ``` p1P2P3qp2P1qp3P1qP3 => should return [2, 3] P3 -> P1 -> P2 -> (P1) depth = 3 (max) \-> (P3) depth = 2 (min) ``` # Input * A valid RoboScript program, as string. * Nested definitions of patterns, such as `p1...p2***q...q` will not be tested, even if that could be of interest as a Roboscript improvement. * All patterns will have a unique identifier. * Since the program is valid, you won't encounter calls to undefined pattern either. # Output * An array `[min, max]`, giving what are the minimal and the maximal recursion depths encountered. ### Examples ``` p1F2RF2LqP1 => should return [0, 0], no infinite recursion detected p1F2RP1F2LqP1 => should return [1, 1], infinite recursion detection case P2p1P2qp2P1q => should return [2, 2], single mutual infinite recursion case p1P2qP3p2P3qp3P1q => should return [3, 3], twice mutual infinite recursion case p1P2P1qp2P3qp3P1qP1 => should return [1, 3], mixed infinite recursion case ```
["from collections import defaultdict\nfrom itertools import chain\nimport re\n\nPARSE = re.compile(r'[pP]\\d+|q')\n\ndef magic_call_depth_number(prog):\n \n def parse(it, p=''):\n for m in it:\n if m[0].startswith('p'): parse(it, m[0])\n elif m[0]=='q': return\n else: pCmds[p].append(m[0].lower())\n \n def travel(p, seen, d=1):\n if not pCmds[p]:\n yield 0\n else:\n for n in pCmds[p]:\n if n in seen: yield d\n else: yield from travel(n, seen|{n}, d+1)\n \n pCmds = defaultdict(list)\n parse(PARSE.finditer(prog))\n inf = list(chain.from_iterable(travel(p, {p}) for p in pCmds['']))\n \n return [min(inf, default=0), max(inf, default=0)]\n", "import re\nfrom collections import defaultdict, deque\ndef magic_call_depth_number(s):\n adjacent = defaultdict(list)\n for i, j, k in re.findall(r'(p\\d+)(.+?)(q)', s):\n for n in re.findall(r'P\\d+', j):\n adjacent[i.upper()].append(n)\n \n s, depths = re.sub(r'p.+?q', '', s), []\n \n def BFS(start):\n Q = deque([[start, 1, []]])\n while Q:\n node, depth, path = Q.popleft()\n path.append(node)\n if not adjacent[node] : depths.append(0)\n for i in adjacent[node]:\n if i not in path : Q.append([i, depth + 1, path[:]])\n else : depths.append(depth)\n \n [BFS(i) for i in re.findall(r'P\\d+', s)]\n return [min(depths), max(depths)] if depths else [0,0]", "import re\ndef functrion_L(Q):\n findall_elements = {F : re.findall('P(\\d+)',V) for F,V in re.findall('p(\\d+)([^q]+)',Q)}\n return findall_elements\n\ndef H(Q) :\n M = functrion_L(Q)\n R = [9E9,0]\n def H(V,S = set(),C = 0) :\n if V in S :\n R[:] = min(R[0],C),max(R[1],C)\n return 9\n S.add(V)\n T = 0\n for B in M[V] : T = H(B,S,-~C) or T\n R[0] = R[0] if T else 0\n S.remove(V)\n return R[0]\n for V in re.findall('P(\\d+)',re.sub('p(\\d+)([^q]+)','',Q)) : H(V)\n return [R[0] if R[0] < 9E9 else 0,R[1]]\nmagiCallDepthNumber = magic_call_depth_number = H", "import re\ndef H(Q) :\n M,R = {F : re.findall('P(\\d+)',V) for F,V in re.findall('p(\\d+)([^q]+)',Q)},[9E9,0]\n def H(V,S = set(),C = 0) :\n if V in S :\n R[:] = min(R[0],C),max(R[1],C)\n return 9\n S.add(V)\n T = 0\n for B in M[V] : T = H(B,S,-~C) or T\n R[0] = R[0] if T else 0\n S.remove(V)\n return R[0]\n for V in re.findall('P(\\d+)',re.sub('p(\\d+)([^q]+)','',Q)) : H(V)\n return [R[0] if R[0] < 9E9 else 0,R[1]]\nmagiCallDepthNumber = magic_call_depth_number = H", "from re import compile\nbuild = compile(r\"P(\\d+)\").findall\nread = compile(r\"p(\\d+)(.*?)q\").sub\n\ndef magic_call_depth_number(pattern):\n P = {}\n def filling(w):\n k, v = w.groups()\n P[k] = set(build(v))\n return \"\"\n \n def minimum(id1, S):\n if id1 in S: return (False, -1)\n if not P[id1]: return (True, 0)\n mini = float('inf')\n for id2 in P[id1]:\n b, x = minimum(id2, S|{id1})\n if b: return (True, 0)\n mini = min(mini, x+1)\n return (False, mini)\n \n def maximum(id1, S):\n if id1 in S: return (True, -1)\n if not P[id1]: return (False, 0)\n res, maxi = (False, 0)\n for id2 in P[id1]:\n b, x = maximum(id2, S|{id1})\n if b: res, maxi = res or b, max(maxi, x+1)\n return (res, maxi)\n \n P[None] = set(build(read(filling, pattern)))\n return [minimum(None, set())[1], maximum(None, set())[1]]", "def magic_call_depth_number(program):\n templates = dict()\n code = str()\n \n i = 0\n while i < len(program):\n \n if program[i] != 'p':\n code += program[i]\n else:\n i += 1\n n = str()\n while program[i].isdigit():\n n += program[i]\n i += 1\n \n template = str()\n while program[i] != 'q':\n template += program[i]\n i += 1\n \n templates[n] = template\n \n i += 1\n \n mymin = 999\n mymax = 0\n \n i = 0\n while i < len(code):\n while code[i] == 'F' or code[i] == 'L' or code[i] == 'R':\n i += 1\n while code[i].isdigit():\n i += 1\n \n i += 1\n n = str()\n while i < len(code) and code[i].isdigit():\n n += code[i]\n i += 1\n \n # \u043e\u0431\u0440\u0430\u0440\u0431\u043e\u0442\u0430\u0442\u044c \u0432\u044b\u0437\u043e\u0432 Pn\n min_max = calc_min_max([n], n, templates, 0)\n mymin = min(mymin, min_max[0])\n mymax = max(mymax, min_max[1])\n \n if mymax == 0:\n mymin = 0\n \n return [mymin, mymax]\n\ndef calc_min_max(used, c, templates, depth):\n mymin = 999\n mymax = 0\n \n flag = 0\n i = 0\n while i < len(templates[c]):\n while i < len(templates[c]) and (templates[c][i] == 'F' or templates[c][i] == 'L' or templates[c][i] == 'R'):\n i += 1\n while i < len(templates[c]) and (templates[c][i].isdigit()):\n i += 1\n \n if not (i < len(templates[c])):\n break\n \n i += 1\n n = str()\n while i < len(templates[c]) and templates[c][i].isdigit():\n n += templates[c][i]\n i += 1\n \n # \u0432 \u0432\u044b\u0437\u043e\u0432\u0435 Pc \u043f\u0440\u043e\u0438\u0437\u043e\u0448\u0451\u043b \u0432\u044b\u0437\u043e\u0432 Pn\n flag = 1\n if used.count(n):\n loop_with_depth = depth + 1\n mymin = min(mymin, loop_with_depth)\n mymax = max(mymax, loop_with_depth)\n else:\n used_copy = used.copy()\n used_copy.append(n)\n min_max = calc_min_max(used_copy, n, templates, depth + 1)\n mymin = min(mymin, min_max[0])\n mymax = max(mymax, min_max[1])\n \n return [mymin if flag else 0, mymax]\n", "import re\n\nclass Pattern:\n def __init__(self, definition, patterns):\n self._name = re.findall(\"p([0-9]+)\", definition)[0]\n self._calls = re.findall(\"P([0-9]+)\", definition)\n patterns[self._name] = self\n \n def simulate(self, patterns, visited, depths, depth=0):\n if self._name in visited:\n depths.append(depth)\n return\n \n if len(self._calls) == 0:\n depths.append(0)\n return\n \n visited.add(self._name)\n for call in self._calls:\n patterns[call].simulate(patterns, visited, depths, depth+1)\n visited.remove(self._name)\n\ndef magic_call_depth_number(pattern):\n patterns = {}\n while True:\n match = re.search(\"p[0-9]+[^q]*q\", pattern)\n if match == None:\n break\n (start, end) = match.span()\n pattern = pattern[0:start] + pattern[end:]\n Pattern(match.group(0), patterns)\n \n depths = []\n for e in re.findall(\"P([0-9]+)\", pattern):\n visited = set()\n patterns[e].simulate(patterns, visited, depths)\n \n if len(depths) == 0:\n return [0, 0]\n else:\n return [min(depths), max(depths)]", "import re\n\ndef magic_call_depth_number(pattern):\n subroutines = {} # list them by number\n s = re.compile(r'p(\\d+)((P\\d+|[FLR]*\\d*)+)q')\n subrout = s.search(pattern)\n while subrout:\n # put the subroutine in the dictionary\n subroutines[\"P\" + subrout.group(1)] = tokens(subrout.group(2))\n # extract this subroutine from the pattern and see if there are more\n pattern = pattern.replace(subrout.group(0), \"\")\n subrout = s.search(pattern)\n # Make a tree\n depths = walk_tree(tokens(pattern), [], subroutines)\n return [min(depths), max(depths)]\n \ndef tokens(pattern):\n return re.findall(r'([PFLR]\\d*)', pattern)\n \ndef walk_tree(token_list, stack, subroutine_dict):\n depths = []\n stops_here = True\n for t in token_list:\n if t.startswith(\"P\"):\n stops_here = False\n if t in stack:\n depths.append(len(stack))\n else:\n depths.extend(walk_tree(subroutine_dict[t], stack + [t], subroutine_dict))\n if stops_here:\n depths.append(0)\n return depths", "UPPER_BOUND = 1000000000\n\ndef test_call (current_function: str, functions: dict, stack: set):\n min_n = UPPER_BOUND\n max_n = 0\n\n stack.add(current_function)\n #print(\" \" * len(stack), current_function, ' ', functions,\n # current_function in stack, sep='')\n for next_funcion in functions[current_function]:\n if next_funcion in stack:\n min_n = min(min_n, 1)\n max_n = max(max_n, 1)\n\n else:\n current_min, current_max = \\\n test_call(next_funcion, functions, stack)\n current_min += 1\n current_max += 1\n if current_min < min_n:\n min_n = current_min\n if current_min == 1:\n min_n = 0\n if current_max != 1 and current_max > max_n:\n max_n = current_max\n stack.remove(current_function)\n if min_n == UPPER_BOUND:\n min_n = 0\n if max_n < min_n:\n max_n = min_n\n return (min_n, max_n)\n\ndef read_function(s: str):\n \"\"\"\n return:\n (function_#, [functions called])\n \"\"\"\n i = 0;\n while (s[i] in \"0123456789\"):\n i += 1\n\n function_no = int(s[0:i])\n function_calls = []\n\n #print(\"Reading\", function_no)\n\n while 1:\n i = s.find('P', i)\n if i < 0:\n break;\n nums = i + 1\n i += 1\n while i < len(s) and s[i] in \"0123456789\":\n i += 1\n nume = i\n #print(\" call from\", nums, \"to\", nume)\n function_call = int(s[nums:nume])\n function_calls.append(function_call)\n\n return (function_no, function_calls)\n\ndef parse_program (program_s: str):\n i = 0;\n functions = {}\n\n while 1:\n i = program_s.find('p', i)\n if i < 0:\n break\n funs = i + 1\n i = program_s.find('q', i)\n fune = i\n func_no, fun_calls = read_function(program_s[funs:fune])\n functions[func_no] = fun_calls\n\n\n #print(\"Finish parsing\")\n i = 0;\n min_n, max_n = UPPER_BOUND, 0\n\n while 1:\n next_sof = program_s.find('p', i)\n next_eof = program_s.find('q', i)\n if (next_sof < 0):\n next_sof = len(program_s)\n\n #print(\"WTF\", next_sof, next_eof)\n\n while 1:\n i = program_s.find('P', i)\n if i < 0 or i >= next_sof:\n break;\n nums = i + 1\n i += 1\n while i < len(program_s) and program_s[i] in \"0123456789\":\n i += 1\n nume = i\n #print(\"Calling\", nums, nume)\n function_call = int(program_s[nums:nume])\n c_min_n, c_max_n = test_call(function_call, functions, set())\n if c_min_n < min_n:\n min_n = c_min_n\n if c_max_n > max_n:\n max_n = c_max_n\n\n if i < 0 or next_eof < 0:\n break\n i = next_eof + 1\n\n\n if min_n == UPPER_BOUND:\n min_n = 0\n max_n = 0\n\n return [min_n, max_n]\n\n\ndef magic_call_depth_number(pattern):\n return parse_program(pattern)\n\n\n"]
{"fn_name": "magic_call_depth_number", "inputs": [["p0F2LF2RqP0"], ["p1P2P3qp2P1qp3P1qP3"], ["p1P2qp2P3qP4p3P4qp4P1q"], ["p1P2P4qp2P3qp3P4qP1p4P1q"], ["p1P2P3qP2P1p2P3qp3P4qp4P1q"], ["p1P2qp2P3qp3P4qP6p4P1qp5P7qp6P5qp7P6qP1"], ["P1P2P7p1P2qp2P3qp3P4qp4P1qp5P7qp6P5qp7P5q"], ["P2P7P6p1P2qp2P3qp3P4qp4P1qp5P8qp6P5qp7P5qp8P7q"], ["P9P1P7P5P4p1P2qp2P3qp3P4qp4P1qp5P8qp7P5qp8P7qp9F2q"], ["p6023R6F95L64R98P3321L15qP8886P8063P2161p3321P6023P6023F86L64qp8886F12F3L33P3321P3321R57qp8063P3321L35P3321P8886P6023F51qp2161P8063P8063F32R6F46q"], ["p5048L50R23P2998R9qp2125P3445R41R48qp1776R41P392qP2904p2998R4P2125P1776qp3445F57P1776F37R70qp392P2998R28P3445F55qp2904P3445L14L42R29P392q"]], "outputs": [[[0, 0]], [[2, 3]], [[4, 4]], [[2, 4]], [[3, 4]], [[3, 4]], [[2, 4]], [[3, 4]], [[0, 4]], [[3, 5]], [[4, 6]]]}
INTERVIEW
PYTHON3
CODEWARS
11,913
def magic_call_depth_number(pattern):
693729f097a8ae2f64c1d5f3cc1d9eb8
UNKNOWN
We are given a certain number ```n``` and we do the product partitions of it. ```[59, 3, 2, 2, 2]``` is a product partition of ```1416``` because: ``` 59 * 3 * 2 * 2 * 2 = 1416 ``` We form a score, ```sc``` for each partition in the following way: - if ```d1, d2, ...., dk``` are the prime factors of ```n```, and ```f1, f2, ...., fk```, the corresponding frequencies for each factor, we calculate: Suposse that we have that ```n = 1416``` The product partitions of this number with a corresponding special score are as follows: ``` Product Partition Score(sc) [59, 3, 2, 2, 2] 350 # equals to: (59^1 + 3^1 + 2^3) * 5 [177, 2, 2, 2] 740 # equals to: (177^1 + 2^3) * 4 [118, 3, 2, 2] 500 [59, 6, 2, 2] 276 [354, 2, 2] 1074 [59, 4, 3, 2] 272 [236, 3, 2] 723 [177, 4, 2] 549 [118, 6, 2] 378 [59, 12, 2] 219 [708, 2] 1420 <---- maximum value [118, 4, 3] 375 [59, 8, 3] 210 [472, 3] 950 [59, 6, 4] 207 [354, 4] 716 [236, 6] 484 [177, 8] 370 [118, 12] 260 [59, 24] 166 <---- minimum value ``` So we need a function that may give us the product partition with maximum or minimum score. The function ```find_spec_prod_part()``` will receive two arguments: - an integer ```n, n > 0``` - a command as a string, one of the following ones: ```'max' or 'min'``` The function should output a list with two elements: the found product partition (as a list sorted in descendin order) with its corresponding score. ``` find_spec_prod_part(n, com) ---> [prod_partition, score] ``` Let'see some cases: ```python find_spec_prod_part(1416, 'max') == [[708, 2], 1420] find_spec_prod_part(1416, 'min') == [[59, 24], 166] ``` The function should reject prime numbers: ```python find_spec_prod_part(10007 , 'max') == "It is a prime number" ``` Enjoy it! Hint: In this kata, optimization is one of the purposes or tags. The algorithm to produce the product partition is a key factor in terms of speed. Your code will be tested for an ```n``` value up to ```500000```.
["def primeFactors(n):\n \n factors = []\n \n while n % 2 == 0: \n n /= 2\n factors.append(2)\n \n for i in range(3, int(n**.5) + 1,2): \n while n % i == 0: \n n /= i\n factors.insert(0, i)\n \n if n > 2: factors.insert(0, int(n))\n \n return factors\n \ndef score(p):\n \n last, xp, s = p[0], p[0], 0\n \n for j in p[1:]:\n if j == last:\n xp *= j\n else:\n s += xp\n xp, last = j, j\n return (s + xp) * len(p)\n \n\ndef prod(lst):\n \n res = 1\n \n for v in lst: res *= v\n return res\n\ndef multiply_partitions(partition): return [prod(sub) for sub in partition]\n\ndef partition(collection):\n \n if len(collection) == 1:\n yield [collection]\n return\n\n first = collection[0]\n \n for smaller in partition(collection[1:]): \n for n, subset in enumerate(smaller):\n yield smaller[:n] + [[ first ] + subset] + smaller[n+1:]\n yield [ [ first ] ] + smaller\n\n\ndef find_spec_prod_part(n, com): \n \n factors = primeFactors(n)\n \n if len(factors) == 1: return 'It is a prime number'\n \n fn = min if com == 'min' else max\n mplist = []\n best = [factors, score(factors)]\n \n for p in partition(factors):\n mp = multiply_partitions(p)\n \n if mp in mplist or mp[0]==n:\n continue \n mplist.append(mp)\n best = fn(best, [mp, score(mp)], key=lambda x: x[1])\n \n return [sorted(best[0], reverse=True), best[1]]", "def primeFactors(n):\n factors = []\n while n % 2 == 0: \n n /= 2\n factors.append(2)\n for i in range(3,int(n**.5)+1,2): \n while n % i == 0: \n n /=i\n factors.insert(0, i)\n if n > 2: \n factors.insert(0, int(n))\n return factors\n \ndef score(p):\n last, xp, s = p[0], p[0], 0\n for e in p[1:]:\n if e == last:\n xp *= e\n else:\n s += xp\n xp, last = e, e\n return (s + xp) * len(p)\n \n\ndef prod(lst):\n res = 1\n for v in lst: res *= v\n return res\n\ndef multiply_partitions(partition):\n return [prod(sub) for sub in partition]\n\ndef partition(collection):\n if len(collection) == 1:\n yield [ collection ]\n return\n\n first = collection[0]\n for smaller in partition(collection[1:]):\n # insert `first` in each of the subpartition's subsets\n for n, subset in enumerate(smaller):\n yield smaller[:n] + [[ first ] + subset] + smaller[n+1:]\n # put `first` in its own subset \n yield [ [ first ] ] + smaller\n\n\ndef find_spec_prod_part(n, com): \n factors = primeFactors(n)\n if len(factors) == 1: return 'It is a prime number'\n fn = min if com == 'min' else max\n mplist = []\n best = [factors, score(factors)]\n for p in partition(factors):\n mp = multiply_partitions(p)\n if mp in mplist or mp[0]==n:\n continue\n mplist.append(mp)\n best = fn(best, [mp, score(mp)], key=lambda x: x[1])\n \n return [sorted(best[0], reverse=True), best[1]]", "from collections import Counter\nfrom itertools import permutations\nfrom itertools import chain\nimport numpy as np\n\n\ndef prime_factors(n):\n factors = []\n while n % 2 == 0:\n n = n // 2\n factors.append(2)\n \n for k in range(3, n+1, 2):\n while n % k == 0:\n n = n // k\n factors.append(k)\n if n == 1:\n break\n return factors\n\n \ndef get_score(factors):\n factor_counts = Counter(factors)\n return sum(f**factor_counts[f] for f in factor_counts)*sum(c for c in factor_counts.values())\n\n\ndef int_partitions(m, memo = {}):\n if m in memo:\n return memo[m]\n all_partitions = [[m]]\n \n for i in range(1, m):\n for p in int_partitions(m-i, memo):\n all_partitions.append([i] + p)\n \n memo[m] = all_partitions\n return all_partitions\n\n\ndef make_partitions(factors):\n partitions = int_partitions(len(factors))\n part_perm = []\n \n for p in partitions:\n part_perm.append(set(list(permutations(p, len(p)))))\n\n part_perm = set(list(chain.from_iterable(part_perm)))\n all_new_factors = []\n\n for inds in part_perm: \n new_factors = []\n j_start = 0\n\n for i in inds:\n j_end = j_start + i\n new_factors.append(np.product(factors[j_start:j_end]))\n j_start = j_end\n \n if len(new_factors) > 1:\n all_new_factors.append(new_factors) \n \n return all_new_factors\n\n\ndef find_spec_prod_part(n, com):\n factors = prime_factors(n) \n \n if len(factors) == 1:\n return \"It is a prime number\"\n \n all_factors = make_partitions(factors)\n scores = [get_score(x) for x in all_factors]\n \n if com == \"max\":\n opt_id = np.argmax(scores)\n else:\n opt_id = np.argmin(scores)\n \n return [sorted(all_factors[opt_id], reverse=True), scores[opt_id]] ", "from itertools import cycle, groupby, islice\nfrom operator import lt, gt\n\ndef find_spec_prod_part(n, com):\n prime_factors = list(factor(n))\n if len(prime_factors) < 2:\n return 'It is a prime number'\n cmp = lt if com == 'min' else gt\n best_part = None\n best_score = None\n for part in set(islice(partitions(prime_factors), 1, None)):\n sc = score(part)\n if not best_score or cmp(sc, best_score):\n best_part = part\n best_score = sc\n return [list(best_part), best_score]\n\ndef factor(n):\n if n < 1: raise ValueError('factor: n must be > 0')\n for d in [2, 3, 5]:\n while n % d == 0:\n yield d\n n = n // d\n d = 7\n wheel = cycle([4, 2, 4, 2, 4, 6, 2, 6])\n while n > 1 and d * d <= n:\n if n % d == 0:\n yield d\n n = n // d\n else:\n d += next(wheel)\n if n > 1:\n yield n\n\ndef partitions(factors):\n if len(factors) == 1:\n yield factors[0],\n return\n first = factors[0]\n for subpart in partitions(factors[1:]):\n for n, fact in enumerate(subpart):\n yield tuple(sorted(subpart[:n] + (first * fact,) + subpart[n+1:], reverse=True))\n yield tuple(sorted((first,) + subpart, reverse=True))\n\ndef score(part):\n factors = [(f, len(list(g))) for f, g in groupby(part)]\n return sum(f**e for f, e in factors) * sum(e for _, e in factors)\n", "import math\nfrom collections import Counter\nfrom itertools import permutations\n\ndef find_spec_prod_part(n, com):\n # your code here\n temp_partition = [] \n factors = primeFactors(n)\n counter = Counter(factors)\n max_score = calculateScore(counter)\n min_score = max_score\n partition_min = factors\n partition_max = factors\n \n x = len(factors)\n \n if len(factors) == 1:\n return \"It is a prime number\"\n \n perms = list(set(list(permutations(factors))))\n \n \n divs = list(accel_asc(len(factors))) \n \n\n for div in divs:\n if len(div) == 1 or len(div) == len(factors):\n continue\n for perm in perms:\n temp_partition = []\n start = 0\n product = 1\n seq = []\n\n for i in div:\n seq = perm[start:(start+i)]\n for j in seq:\n product *= j\n temp_partition.append(product)\n start = start+i\n product = 1\n\n counter = Counter(temp_partition)\n score = calculateScore(counter)\n \n if score > max_score:\n max_score = score\n partition_max = temp_partition\n \n if score < min_score:\n min_score = score\n partition_min = temp_partition\n \n \n if com == 'max':\n partition_max.sort(reverse = True)\n return [partition_max, max_score]\n if com == 'min':\n partition_min.sort(reverse = True)\n return [partition_min, min_score]\n\n\ndef calculateScore(count):\n score = 0\n coef = 0\n for key in count:\n score += key**count[key]\n coef += count[key]\n score = score * coef\n return score\n\n# A function to print all prime factors of \n# a given number n \ndef primeFactors(n): \n prime_factors = [] \n # Print the number of two's that divide n \n while n % 2 == 0: \n prime_factors.append(2), \n n = n / 2\n \n # n must be odd at this point \n # so a skip of 2 ( i = i + 2) can be used \n for i in range(3, int(math.sqrt(n))+1, 2): \n \n # while i divides n, print i ad divide n \n while n % i == 0: \n prime_factors.append(i), \n n = n / i \n if n != 1:\n prime_factors.append(int(n))\n\n return prime_factors\n\ndef accel_asc(n):\n a = [0 for i in range(n + 1)]\n k = 1\n y = n - 1\n while k != 0:\n x = a[k - 1] + 1\n k -= 1\n while 2 * x <= y:\n a[k] = x\n y -= x\n k += 1\n l = k + 1\n while x <= y:\n a[k] = x\n a[l] = y\n yield a[:k + 2]\n x += 1\n y -= 1\n a[k] = x + y\n y = x + y - 1\n yield a[:k + 1]", "from functools import reduce\nfrom operator import mul,gt,lt\nfrom itertools import combinations\nfrom collections import Counter\ndef is_prime(n):\n if n<2:\n return False\n elif n==2:\n return True\n elif n%2==0:\n return False\n for i in range(3,int(n**0.5)+1,2):\n if n%i==0:\n return False\n return True\n\nmemo={}\n \ndef _prot_part(arr):\n if len(arr)<2:\n return set({(arr[0],)})\n elif len(arr)==2:\n return set([tuple(sorted(arr)),(arr[0]*arr[1],)])\n elif tuple(arr) in memo:\n return memo[tuple(arr)]\n r=set()\n for j in range(1,len(arr)//2+1):\n for t in combinations(arr,j):\n arr2=arr[:]\n for e in t:\n arr2.remove(e)\n s2=_prot_part(arr2)\n for e1 in _prot_part(list(t)):\n for e2 in s2:\n r.add(tuple(sorted(list(e1+e2))))\n r.add((reduce(mul,arr),))\n memo[tuple(arr)]=r\n return r\n\ndef find_spec_prod_part(n, com):\n if is_prime(n):\n return 'It is a prime number'\n r=[]\n while(n%2==0):\n r.append(2)\n n//=2\n x=3\n while(n>1 and not is_prime(n)):\n while(n%x==0):\n r.append(x)\n n//=x\n x+=2\n if n>1:\n r.append(n)\n p=_prot_part(r)\n if com=='max':\n m=[None,-1]\n f=gt\n else:\n m=[None,10e10]\n f=lt\n for t in p:\n if len(t)==1:\n continue\n a,b=0,0\n for k,v in Counter(t).items():\n a+=k**v\n b+=v\n score=a*b\n if f(score,m[1]):\n m=[sorted(t,reverse=True),score]\n return m ", "from numpy import prod\ndef find_spec_prod_part(n, com):\n partitions = []\n current_partition = 2\n while n > 1:\n if n % current_partition == 0:\n partitions.append(current_partition)\n n /= current_partition\n current_partition = 2\n else:\n current_partition += 1\n\n if len(partitions) == 1:\n return \"It is a prime number\"\n \n result = [([0], -1)] if com == \"max\" else [([0], float('Inf'),)]\n sc_opt(partitions, result, com)\n \n result[0][0].sort(reverse=True)\n return [result[0][0], result[0][1]]\n\ndef sc_opt(partitions, result, com):\n if (com == \"min\" and result[0][1] > sc(partitions)) or (com == \"max\" and result[0][1] < sc(partitions)):\n result[0] = (partitions, sc(partitions))\n if len(partitions) == 2 or (com == \"min\" and max(partitions) > result[0][1]) or (com == \"min\" and max(partitions) > result[0][1]) :\n return\n for p in set(partitions):\n current = partitions.copy()\n current.remove(p)\n for i in filter(lambda x: x >= p, set(current)):\n curr = current.copy()\n curr[curr.index(i)] *= p\n sc_opt(curr, result, com)\n\ndef sc(partitions):\n return sum([p ** partitions.count(p) for p in set(partitions)]) * len(partitions)", "def partition(n):\n return [[int(n/x)] for x in range(1, 1+int(n/2)) if n % x == 0]\n \ndef prod(a):\n prod = 1\n for n in a:\n prod *= n\n return prod\n\ndef score(a):\n return sum(n ** a.count(n) for n in reversed(sorted(set(a)))) * len(a)\n \ndef find_spec_prod_part(n, com):\n #non-recursive way to find partitions\n there_are_new = True\n \n partitions = partition(n)\n \n while there_are_new:\n there_are_new = False\n new_partitions = []\n for p in partitions:\n product = prod(p)\n if product < n:\n for new in partition(n/product):\n if new[0] <= p[-1] and prod(p+new) <= n:\n there_are_new = True\n new_partitions.append(p + new)\n else: \n new_partitions.append(p)\n \n partitions = new_partitions\n \n if len(partitions) <= 1:\n return (\"It is a prime number\")\n \n func = max if com == \"max\" else min\n return func( ([p, s] for (p, s) in ((p, score(p)) for p in partitions if len(p) > 1)), key=lambda x: x[1])", "def partition(n):\n return [[int(n/x)] for x in range(1, 1+int(n/2)) if n % x == 0]\n \ndef prod(a):\n prod = 1\n for n in a:\n prod *= n\n return prod\n\ndef score(a):\n return sum(n**a.count(n) for n in reversed(sorted(set(a))))*len(a) \n \ndef find_spec_prod_part(n, com):\n there_are_new = True\n \n partitions = partition(n)\n \n while there_are_new:\n there_are_new = False\n new_partitions = []\n for p in partitions:\n product = prod(p)\n if product < n:\n for new in partition(n/product):\n if new[0] <= p[-1] and prod(p+new) <= n:\n there_are_new = True\n new_partitions.append(p + new)\n else: \n new_partitions.append(p)\n \n partitions = new_partitions\n \n if len(partitions) <= 1:\n return (\"It is a prime number\")\n \n result = None\n result_score = None\n \n for p in partitions:\n if len(p) > 1:\n s = score(p)\n if (com == \"max\" and (not result_score or result_score < s)) or (com == \"min\" and (not result_score or result_score > s)):\n result = p\n result_score = s\n \n return [result, result_score]"]
{"fn_name": "find_spec_prod_part", "inputs": [[1416, "max"], [1416, "min"], [10007, "max"]], "outputs": [[[[708, 2], 1420]], [[[59, 24], 166]], ["It is a prime number"]]}
INTERVIEW
PYTHON3
CODEWARS
15,259
def find_spec_prod_part(n, com):
e4113bf16283f1969cb511d4050c56b9
UNKNOWN
Complete the solution so that it strips all text that follows any of a set of comment markers passed in. Any whitespace at the end of the line should also be stripped out. **Example:** Given an input string of: ``` apples, pears # and bananas grapes bananas !apples ``` The output expected would be: ``` apples, pears grapes bananas ``` The code would be called like so: ```python result = solution("apples, pears # and bananas\ngrapes\nbananas !apples", ["#", "!"]) # result should == "apples, pears\ngrapes\nbananas" ```
["def solution(string,markers):\n parts = string.split('\\n')\n for s in markers:\n parts = [v.split(s)[0].rstrip() for v in parts]\n return '\\n'.join(parts)", "def strip_line(line, markers):\n for m in markers:\n if m in line:\n line = line[:line.index(m)]\n return line.rstrip()\n\ndef solution(string,markers):\n stripped = [strip_line(l, markers) for l in string.splitlines()]\n return '\\n'.join(stripped)", "def solution(string,markers):\n lst = string.split('\\n')\n ans = []\n for line in lst:\n for m in markers:\n if m in line:\n line = line[: line.find(m)].strip()\n ans.append(line) \n return '\\n'.join(ans)", "import re\n\ndef solution(string,markers):\n for marker in markers:\n string = re.sub(r' *?\\{}.*$'.format(marker),'', string, flags = re.M)\n return string", "from re import sub\ndef solution(string,markers):\n return sub(\"(.*?) ?([\\%s].*)\" % \"\\\\\".join(markers),\"\\g<1>\",string) if markers else string", "def solution(string,markers):\n lst = string.split('\\n')\n for i, s in enumerate(lst):\n for m in markers:\n f = s.find(m)\n s = s[0:f] if f >= 0 else s[:]\n lst[i] = s.strip()\n\n return '\\n'.join(lst)\n", "def solution(string, markers):\n lines = string.splitlines()\n for mark in markers:\n lines = [line.split(mark)[0].strip() for line in lines]\n return '\\n'.join(lines)", "from re import escape, sub\n\n\ndef solution(s, markers):\n return s if not markers else \\\n sub(r'( *[{}].*)'.format(escape(''.join(markers))), '', s)\n", "def solution(string,markers):\n # split string into lines to process them one after another\n content = string.split(\"\\n\")\n \n #process every line by its own and append the clean line to clean_content\n clean_content = []\n for full_line in content:\n \n #appending each char until marker\n clean_line = \"\"\n for char in full_line:\n \n #check for marker, if no marker add char to clean_line \n #if char in marker break loop\n \n if not char in markers:\n clean_line += char\n else:\n break\n \n #strip whitespaces\n clean_line = clean_line.strip()\n\n #add clean line to content\n clean_content.append(clean_line)\n \n return \"\\n\".join(clean_content)"]
{"fn_name": "solution", "inputs": [["apples, pears # and bananas\ngrapes\nbananas !apples", ["#", "!"]], ["a #b\nc\nd $e f g", ["#", "$"]], ["apples, pears # and bananas\ngrapes\nbananas !#apples", ["#", "!"]], ["apples, pears # and bananas\ngrapes\nbananas #!apples", ["#", "!"]], ["apples, pears # and bananas\ngrapes\navocado @apples", ["@", "!"]], ["apples, pears \u00a7 and bananas\ngrapes\navocado *apples", ["*", "\u00a7"]], ["", ["#", "!"]], ["#", ["#", "!"]], ["\n\u00a7", ["#", "\u00a7"]], ["apples, pears # and bananas\ngrapes\nbananas !apples", []]], "outputs": [["apples, pears\ngrapes\nbananas"], ["a\nc\nd"], ["apples, pears\ngrapes\nbananas"], ["apples, pears\ngrapes\nbananas"], ["apples, pears # and bananas\ngrapes\navocado"], ["apples, pears\ngrapes\navocado"], [""], [""], ["\n"], ["apples, pears # and bananas\ngrapes\nbananas !apples"]]}
INTERVIEW
PYTHON3
CODEWARS
2,514
def solution(string,markers):
0d7a3382c3f7954653bbbd45d8f05ce5
UNKNOWN
# Connect Four Take a look at wiki description of Connect Four game: [Wiki Connect Four](https://en.wikipedia.org/wiki/Connect_Four) The grid is 6 row by 7 columns, those being named from A to G. You will receive a list of strings showing the order of the pieces which dropped in columns: ```python pieces_position_list = ["A_Red", "B_Yellow", "A_Red", "B_Yellow", "A_Red", "B_Yellow", "G_Red", "B_Yellow"] ``` The list may contain up to 42 moves and shows the order the players are playing. The first player who connects four items of the same color is the winner. You should return "Yellow", "Red" or "Draw" accordingly.
["COLUMNS, ROWS = 'ABCDEFG', range(6)\nLINES = [{(COLUMNS[i+k], ROWS[j]) for k in range(4)}\n for i in range(len(COLUMNS) - 3) for j in range(len(ROWS))] \\\n + [{(COLUMNS[i], ROWS[j+k]) for k in range(4)}\n for i in range(len(COLUMNS)) for j in range(len(ROWS) - 3)] \\\n + [{(COLUMNS[i+k], ROWS[j+k]) for k in range(4)}\n for i in range(len(COLUMNS) - 3) for j in range(len(ROWS) - 3)] \\\n + [{(COLUMNS[i+k], ROWS[j-k]) for k in range(4)}\n for i in range(len(COLUMNS) - 3) for j in range(3, len(ROWS))]\n\ndef who_is_winner(pieces_positions):\n players = {}\n board = dict.fromkeys(COLUMNS, 0)\n for position in pieces_positions:\n column, player = position.split('_')\n pos = (column, board[column])\n board[column] += 1\n players.setdefault(player, set()).add(pos)\n if any(line <= players[player] for line in LINES):\n return player\n return \"Draw\"", "from itertools import count, takewhile\n\nX, Y, HALF_DIRS = 6, 7, ((0,1),(1,0),(1,1),(1,-1))\n\n\ndef who_is_winner(lstMoves):\n \n def isWinner(): return any(countAligned(*dirs)>=4 for dirs in HALF_DIRS)\n \n def isInsideAndSameGuy(a,b): return 0<=a<X and 0<=b<Y and board[a][b]==who\n \n def countAligned(dx,dy):\n return 1 + sum( sum( takewhile(bool, (isInsideAndSameGuy(x+dx*swap*n, y+dy*swap*n) for n in count(1)) ))\n for swap in (1,-1) )\n \n \n board = [[' ']*Y for _ in range(X)]\n xIdx = [0]*Y\n \n for move in lstMoves:\n y, who = ord(move[0])-65, move[2]\n x = xIdx[y]\n board[x][y] = who\n xIdx[y] += 1\n if isWinner(): return move[2:]\n else:\n return \"Draw\"", "def who_is_winner(pieces_position_list):\n\n grid = [[0,0,0,0,0,0,0],\n [0,0,0,0,0,0,0],\n [0,0,0,0,0,0,0],\n [0,0,0,0,0,0,0],\n [0,0,0,0,0,0,0],\n [0,0,0,0,0,0,0]] \n \n columns = 7\n rows = 6\n rowPosition = 0\n winner = None\n drawCount = 0\n \n for piece in pieces_position_list:\n if piece[2] == \"Y\":\n code = 2\n else:\n code = 1\n \n if piece[0] == \"A\":\n columnPosition = 0\n elif piece[0] == \"B\":\n columnPosition = 1\n elif piece[0] == \"C\":\n columnPosition = 2\n elif piece[0] == \"D\":\n columnPosition = 3\n elif piece[0] == \"E\":\n columnPosition = 4\n elif piece[0] == \"F\":\n columnPosition = 5\n elif piece[0] == \"G\":\n columnPosition = 6\n \n while grid[rowPosition][columnPosition] != 0:\n if grid[5][columnPosition] == 1 or grid[5][columnPosition] == 2:\n break\n rowPosition += 1 \n grid[rowPosition][columnPosition] = code\n rowPosition = 0\n \n #check horizontal positions for winner\n for row in range(rows):\n for column in range(columns-3):\n if grid[row][column] == 1 and grid[row][column+1] == 1 and grid[row][column+2] == 1 and grid[row][column+3] == 1:\n winner = \"Red\"\n elif grid[row][column] == 2 and grid[row][column+1] == 2 and grid[row][column+2] == 2 and grid[row][column+3] == 2:\n winner = \"Yellow\"\n \n #check vertical positions\n for row in range(rows-3):\n for column in range(columns):\n if grid[row][column] == 1 and grid[row+1][column] == 1 and grid[row+2][column] == 1 and grid[row+3][column] == 1:\n winner = \"Red\"\n elif grid[row][column] == 2 and grid[row+1][column] == 2 and grid[row+2][column] == 2 and grid[row+3][column] == 2:\n winner = \"Yellow\"\n \n #check left vertical positions\n for row in range(3,rows):\n for column in range(columns-3):\n if grid[row][column] == 1 and grid[row-1][column+1] == 1 and grid[row-2][column+2] == 1 and grid[row-3][column+3] == 1:\n winner = \"Red\"\n elif grid[row][column] == 2 and grid[row-1][column+1] == 2 and grid[row-2][column+2] == 2 and grid[row-3][column+3] == 2:\n winner = \"Yellow\"\n \n #check right vertical positions\n for row in range(rows-3):\n for column in range(columns-3):\n if grid[row][column] == 1 and grid[row+1][column+1] == 1 and grid[row+2][column+2] == 1 and grid[row+3][column+3] == 1:\n winner = \"Red\"\n elif grid[row][column] == 2 and grid[row+1][column+1] == 2 and grid[row+2][column+2] == 2 and grid[row+3][column+3] == 2:\n winner = \"Yellow\"\n\n #check winning condition\n if winner == \"Red\":\n return \"Red\"\n break\n elif winner == \"Yellow\":\n return \"Yellow\"\n break\n \n if winner == None:\n return \"Draw\"\n \n \n \n", "import numpy as np\nfrom scipy.signal import convolve2d\ndef who_is_winner(pieces_position_list):\n arr = np.zeros((7,6), int)\n for a in pieces_position_list:\n pos, color = a.split('_')\n pos = ord(pos) - ord('A')\n val = (-1,1)[color == 'Red']\n arr[pos, np.argmin(arr[pos] != 0)] = val\n t_arr = val * arr\n if any(np.max(cv) == 4 for cv in (convolve2d(t_arr, [[1,1,1,1]], 'same'),\n convolve2d(t_arr, [[1],[1],[1],[1]], 'same'),\n convolve2d(t_arr, [[1,0,0,0], [0,1,0,0], [0,0,1,0], [0,0,0,1]], 'same'),\n convolve2d(t_arr, [[0,0,0,1], [0,0,1,0], [0,1,0,0], [1,0,0,0]], 'same'))):\n return color\n return 'Draw'", "from numpy import diagonal, rot90\n\ndef who_is_winner(pieces_position_list):\n board = [[' ']*6 for _ in range(7)]\n \n def check(i, j, p):\n if p in ''.join(board[i]): return True\n if p in ''.join(list(zip(*board))[j]): return True\n if p in ''.join(diagonal(board, j-i)): return True\n if p in ''.join(diagonal(rot90(board), +i+j-5)): return True\n return False\n \n id = [0]*7\n for move in pieces_position_list:\n i, p = ord(move[0]) - 65, move[2]\n j = id[i]\n board[i][j], id[i] = p, j+1\n if check(i, j, p*4):\n return \"Yellow\" if p == 'Y' else \"Red\"\n return \"Draw\"", "import re\ndef who_is_winner(pieces_position_list):\n # Your code here!\n tempList=[\"\".join([\"*\" for j in range(7)])+\"\\t\" for i in range(6)]\n for i in pieces_position_list:\n temp=i.split(\"_\") \n columns=ord(temp[0])-ord(\"A\")\n sign=\"1\" if temp[1]==\"Red\" else \"2\"\n for j in range(len(tempList)):\n if tempList[j][columns]==\"*\":\n tempList[j]=tempList[j][:columns]+sign+tempList[j][columns+1:]\n break\n else:\n return \"Draw\"\n win=GetWin(\"\".join(tempList))\n if win!=\"Draw\":\n print(win)\n return win\n else:\n return \"Draw\"\n pass\n \ndef GetWin(string):\n if re.search(r\"1{4,}|1(?:.{7}1){3,}|1(?:.{8}1){3,}|1(?:.{6}1){3,}\",string):\n return \"Red\"\n if re.search(r\"2{4,}|2(?:.{7}2){3,}|2(?:.{8}2){3,}|2(?:.{6}2){3,}\",string):\n return \"Yellow\"\n return \"Draw\"", "def who_is_winner(moves):\n G = {(c, r):' ' for r in range(6) for c in range(7)}\n\n for col, colour in [(ord(m[0]) - ord('A'), m[2]) for m in moves]:\n for row in range(6):\n if G[(col, row)] == ' ':\n G[(col,row)] = colour\n break\n if colour*4 in ' '.join([''.join(G[(col, k)] for k in range(6)),\n ''.join(G[(k, row)] for k in range(7)),\n ''.join(G.get((k, row - col + k), ' ') for k in range(7)),\n ''.join(G.get((k, row + col - k), ' ') for k in range(7))]): return {'Y':'Yellow', 'R':'Red'}[colour]\n return 'Draw' ", "import string\n\n\ndef vertical_win(game_board_matrix):\n win = 0\n for x_value in range(0, 7):\n coloumn = [game_board_matrix[i][x_value] for i in range(0, 6)]\n i=0\n while i < 3:\n row4 = coloumn [i:i+4]\n i+=1\n if row4.count('R') == 4:\n win = 1\n if row4.count('Y') == 4:\n win = 1\n if win == 1:\n return True\n elif win == 0:\n return False\n\ndef diagonal_left_win(matrix):\n win = 0\n for height_level in range(2,-1,-1):\n for x in range(6,2, -1):\n diagonal = [matrix[height_level+offset][x-offset] for offset in range(0,4)]\n if diagonal.count('R') == 4:\n win = 1\n if diagonal.count('Y') == 4:\n win = 1\n return win\n\ndef diagonal_right_win(matrix):\n win = 0\n for height_level in range(2,-1,-1):\n for x in range(0,4, 1):\n diagonal = [matrix[height_level+offset][x+offset] for offset in range(0,4)]\n if diagonal.count('R') == 4:\n win = 1\n if diagonal.count('Y') == 4:\n win = 1\n return win\n\ndef horizontal_win(matrix):\n win = 0\n for row in matrix:\n i=0\n while i < 4:\n row4 = row [i:i+4]\n i+=1\n if row4.count('R') == 4:\n win = 1\n if row4.count('Y') == 4:\n win = 1\n if win == 1:\n return True\n elif win == 0:\n return False\n \n \ndef who_is_winner(pieces_position_list):\n heigth_list = [ 5, 5,5,5,5,5,5 ]\n w, h = 7, 6;\n game_board = [[0 for x in range(w)] for y in range(h)]\n move_dict = {}\n letters = list(string.ascii_uppercase)[0:7]\n for letter, i in enumerate(letters):\n move_dict[i] = letter\n \n parsed_moves = [ parsed_move.split(\"_\") for parsed_move in pieces_position_list]\n converted_moves = [[move_dict[move[0]], move[1]] for move in parsed_moves]\n for move in converted_moves:\n x_coordinate, colour = move\n game_board[heigth_list[x_coordinate]][x_coordinate] = colour[0]\n if heigth_list[x_coordinate] > 0:\n heigth_list[x_coordinate] = heigth_list[x_coordinate] - 1\n if horizontal_win(game_board) or vertical_win(game_board) or diagonal_left_win(game_board) or diagonal_right_win(game_board):\n return colour\n diagonal_left_win(game_board)\n return \"Draw\"", "def who_is_winner(pieces_position_list):\n C, counts, rows = {'R':'Red', 'Y':'Yellow'}, [0,0,0,0,0,0,0], 6\n grid, slots, I = list(), 7, {'A':0, 'B':1, 'C':2, 'D':3, 'E':4, 'F':5, 'G':6}\n # grid index is 0-6 for A-G. Contains list up to 6 \"R\"=-1 or \"Y\"=1 (or None = 0)\n for i in range(7): grid.append([0,0,0,0,0,0])\n for piece in pieces_position_list:\n slot, color = I[piece[0]], C[piece[2]]\n grid[slot][counts[slot]] = color\n # Test win condition\n # VERTICAL\n n = 0\n for y in range(counts[slot], rows):\n if grid[slot][y] == color: n += 1\n else: break\n for y in range(counts[slot]-1, -1, -1):\n if grid[slot][y] == color: n += 1\n else: break\n if n >= 4: return color\n # HORIZONTAL\n n = 0\n for x in range(slot, slots):\n if grid[x][counts[slot]] == color: n += 1\n else: break\n for x in range(slot-1, -1, -1):\n if grid[x][counts[slot]] == color: n += 1\n else: break\n if n >= 4: return color\n # NORTHEAST\n x, y, n = slot, counts[slot], 0 \n while x < slots and y < rows:\n if grid[x][y] == color: x, y, n = x+1, y+1, n+1\n else: break\n x, y = slot-1, counts[slot]-1\n while x >= 0 and y >= 0:\n if grid[x][y] == color: x, y, n = x-1, y-1, n+1\n else: break\n if n >= 4: return color\n # NORTHWEST\n x, y, n = slot, counts[slot], 0 \n while x >= 0 and y < rows:\n if grid[x][y] == color: x, y, n = x-1, y+1, n+1\n else: break\n x, y = slot+1, counts[slot]-1\n while x < slots and y >= 0:\n if grid[x][y] == color: x, y, n = x+1, y-1, n+1\n else: break\n if n >= 4: return color\n counts[slot] += 1\n return \"Draw\"\n", "def who_is_winner(moves):\n field = [[' ' for i in range(7)] for j in range(6)]\n \n for move in moves:\n column, color = move.split('_')\n \n field = place_color(field, column, color)\n result = check_win(field)\n \n if result:\n return result\n return 'Draw'\n\ndef check_win(field):\n field = list(reversed(field))\n \n for i in field: # Horizontal win check\n for j in range(4):\n h = set(i[j:4+j])\n \n if h == {'R'}: return 'Red'\n elif h == {'Y'}: return 'Yellow'\n \n for i in range(3): # Vertical win check\n for j in range(7):\n v = set([field[i+k][j] for k in range(4)])\n \n if v == {'R'}: return 'Red'\n elif v == {'Y'}: return 'Yellow'\n \n for i in range(3): # Diagonal win check\n for j in range(4):\n r = [field[i][j], field[i+1][j+1], field[i+2][j+2], field[i+3][j+3]]\n l = [field[i][-j-1], field[i+1][-j-2], field[i+2][-j-3], field[i+3][-j-4]]\n \n if set(r) == {'R'} or set(l) == {'R'}: return 'Red'\n elif set(r) == {'Y'} or set(l) == {'Y'}: return 'Yellow'\n \n return 0 \n\ndef place_color(field, column, color):\n index = {'A':0,'B':1,'C':2,'D':3,'E':4,'F':5,'G':6}[column]\n \n for i in range(1, 7+1):\n if field[-i][index] == ' ': \n field[-i][index] = color[0]\n break\n \n return field\n \n"]
{"fn_name": "who_is_winner", "inputs": [[["C_Yellow", "E_Red", "G_Yellow", "B_Red", "D_Yellow", "B_Red", "B_Yellow", "G_Red", "C_Yellow", "C_Red", "D_Yellow", "F_Red", "E_Yellow", "A_Red", "A_Yellow", "G_Red", "A_Yellow", "F_Red", "F_Yellow", "D_Red", "B_Yellow", "E_Red", "D_Yellow", "A_Red", "G_Yellow", "D_Red", "D_Yellow", "C_Red"]], [["C_Yellow", "B_Red", "B_Yellow", "E_Red", "D_Yellow", "G_Red", "B_Yellow", "G_Red", "E_Yellow", "A_Red", "G_Yellow", "C_Red", "A_Yellow", "A_Red", "D_Yellow", "B_Red", "G_Yellow", "A_Red", "F_Yellow", "B_Red", "D_Yellow", "A_Red", "F_Yellow", "F_Red", "B_Yellow", "F_Red", "F_Yellow", "G_Red", "A_Yellow", "F_Red", "C_Yellow", "C_Red", "G_Yellow", "C_Red", "D_Yellow", "D_Red", "E_Yellow", "D_Red", "E_Yellow", "C_Red", "E_Yellow", "E_Red"]], [["F_Yellow", "G_Red", "D_Yellow", "C_Red", "A_Yellow", "A_Red", "E_Yellow", "D_Red", "D_Yellow", "F_Red", "B_Yellow", "E_Red", "C_Yellow", "D_Red", "F_Yellow", "D_Red", "D_Yellow", "F_Red", "G_Yellow", "C_Red", "F_Yellow", "E_Red", "A_Yellow", "A_Red", "C_Yellow", "B_Red", "E_Yellow", "C_Red", "E_Yellow", "G_Red", "A_Yellow", "A_Red", "G_Yellow", "C_Red", "B_Yellow", "E_Red", "F_Yellow", "G_Red", "G_Yellow", "B_Red", "B_Yellow", "B_Red"]], [["A_Yellow", "B_Red", "B_Yellow", "C_Red", "G_Yellow", "C_Red", "C_Yellow", "D_Red", "G_Yellow", "D_Red", "G_Yellow", "D_Red", "F_Yellow", "E_Red", "D_Yellow"]], [["A_Red", "B_Yellow", "A_Red", "B_Yellow", "A_Red", "B_Yellow", "G_Red", "B_Yellow"]]], "outputs": [["Yellow"], ["Yellow"], ["Red"], ["Red"], ["Yellow"]]}
INTERVIEW
PYTHON3
CODEWARS
14,160
def who_is_winner(pieces_position_list):
243df11b998ef602aad7268d3043619e
UNKNOWN
### Lyrics... Pyramids are amazing! Both in architectural and mathematical sense. If you have a computer, you can mess with pyramids even if you are not in Egypt at the time. For example, let's consider the following problem. Imagine that you have a pyramid built of numbers, like this one here: ``` /3/ \7\ 4 2 \4\ 6 8 5 \9\ 3 ``` ### Here comes the task... Let's say that the *'slide down'* is the maximum sum of consecutive numbers from the top to the bottom of the pyramid. As you can see, the longest *'slide down'* is `3 + 7 + 4 + 9 = 23` Your task is to write a function `longestSlideDown` (in ruby: `longest_slide_down`) that takes a pyramid representation as argument and returns its' __largest__ *'slide down'*. For example, ```python longestSlideDown([[3], [7, 4], [2, 4, 6], [8, 5, 9, 3]]) => 23 ``` ### By the way... My tests include some extraordinarily high pyramids so as you can guess, brute-force method is a bad idea unless you have a few centuries to waste. You must come up with something more clever than that. (c) This task is a lyrical version of the __Problem 18__ and/or __Problem 67__ on [ProjectEuler](https://projecteuler.net).
["def longest_slide_down(p):\n res = p.pop()\n while p:\n tmp = p.pop()\n res = [tmp[i] + max(res[i],res[i+1]) for i in range(len(tmp))] \n return res.pop()", "def longest_slide_down(pyr):\n for row in range(len(pyr)-1, 0, -1):\n for col in range(0, row):\n pyr[row-1][col] += max(pyr[row][col], pyr[row][col+1])\n return pyr[0][0]", "def longest_slide_down(pyramid):\n l = len(pyramid)\n for i in range(l-2,-1,-1):\n for j in range(i+1):\n pyramid[i][j] = max([pyramid[i+1][j],pyramid[i+1][j+1]])+pyramid[i][j]\n return pyramid[0][0]\n", "def longest_slide_down(pyramid):\n i = len(pyramid) - 2\n while i > - 1:\n for j in range(len(pyramid[i])):\n pyramid[i][j] += max(pyramid[i+1][j], pyramid[i+1][j+1])\n i -= 1\n return pyramid[0][0]", "class Tree(object):\n value = summ = None\n left = right = None\n \n def __init__(self, value):\n self.value = value\n\n\ndef iter_pairs(level):\n it = iter(level)\n a, b = Tree(next(it)), Tree(next(it))\n while b.value is not None:\n yield a, b\n a, b = b, Tree(next(it, None))\n\n\ndef build_tree(pyramid):\n it = iter(pyramid)\n root = Tree(next(iter(next(it))))\n prev_level = iter([root])\n for level in it:\n tree_level = []\n parent = next(prev_level)\n \n for left_tree, right_tree in iter_pairs(level):\n tree_level.append(left_tree)\n\n parent.left = left_tree\n parent.right = right_tree\n parent = next(prev_level, None)\n \n tree_level.append(right_tree)\n prev_level = iter(tree_level)\n\n return root\n\n\ndef calc_max_sums(root):\n if root is None:\n return 0\n\n if root.summ is not None:\n return root.summ\n\n root.summ = root.value + max(calc_max_sums(root.left), calc_max_sums(root.right))\n return root.summ\n\n\ndef find_max_slide(root):\n if root is None:\n return 0\n\n if not (root.left and root.right):\n return root.value\n\n if root.left.summ >= root.right.summ:\n return root.value + find_max_slide(root.left)\n \n if root.left.summ < root.right.summ:\n return root.value + find_max_slide(root.right)\n\n\ndef longest_slide_down(pyramid):\n tree = build_tree(pyramid)\n calc_max_sums(tree)\n return find_max_slide(tree)", "def longest_slide_down(a):\n a = a[::-1]\n for j in range(1,len(a)):\n a[j] = [a[j][i]+max(a[j-1][i],a[j-1][i+1]) for i in range(len(a[j]))]\n return a[-1][0]\n", "def longest_slide_down(pyramid):\n if len(pyramid) == 1:\n return pyramid[0][0]\n left, current = pyramid[:-1], pyramid[-1]\n pair_sum_g = map(max, zip(current[:-1], current[1:]))\n for i, x in enumerate(pair_sum_g):\n left[-1][i] += x\n return longest_slide_down(left)"]
{"fn_name": "longest_slide_down", "inputs": [[[[3], [7, 4], [2, 4, 6], [8, 5, 9, 3]]], [[[75], [95, 64], [17, 47, 82], [18, 35, 87, 10], [20, 4, 82, 47, 65], [19, 1, 23, 75, 3, 34], [88, 2, 77, 73, 7, 63, 67], [99, 65, 4, 28, 6, 16, 70, 92], [41, 41, 26, 56, 83, 40, 80, 70, 33], [41, 48, 72, 33, 47, 32, 37, 16, 94, 29], [53, 71, 44, 65, 25, 43, 91, 52, 97, 51, 14], [70, 11, 33, 28, 77, 73, 17, 78, 39, 68, 17, 57], [91, 71, 52, 38, 17, 14, 91, 43, 58, 50, 27, 29, 48], [63, 66, 4, 68, 89, 53, 67, 30, 73, 16, 69, 87, 40, 31], [4, 62, 98, 27, 23, 9, 70, 98, 73, 93, 38, 53, 60, 4, 23]]], [[[59], [73, 41], [52, 40, 9], [26, 53, 6, 34], [10, 51, 87, 86, 81], [61, 95, 66, 57, 25, 68], [90, 81, 80, 38, 92, 67, 73], [30, 28, 51, 76, 81, 18, 75, 44], [84, 14, 95, 87, 62, 81, 17, 78, 58], [21, 46, 71, 58, 2, 79, 62, 39, 31, 9], [56, 34, 35, 53, 78, 31, 81, 18, 90, 93, 15], [78, 53, 4, 21, 84, 93, 32, 13, 97, 11, 37, 51], [45, 3, 81, 79, 5, 18, 78, 86, 13, 30, 63, 99, 95], [39, 87, 96, 28, 3, 38, 42, 17, 82, 87, 58, 7, 22, 57], [6, 17, 51, 17, 7, 93, 9, 7, 75, 97, 95, 78, 87, 8, 53], [67, 66, 59, 60, 88, 99, 94, 65, 55, 77, 55, 34, 27, 53, 78, 28], [76, 40, 41, 4, 87, 16, 9, 42, 75, 69, 23, 97, 30, 60, 10, 79, 87], [12, 10, 44, 26, 21, 36, 32, 84, 98, 60, 13, 12, 36, 16, 63, 31, 91, 35], [70, 39, 6, 5, 55, 27, 38, 48, 28, 22, 34, 35, 62, 62, 15, 14, 94, 89, 86], [66, 56, 68, 84, 96, 21, 34, 34, 34, 81, 62, 40, 65, 54, 62, 5, 98, 3, 2, 60], [38, 89, 46, 37, 99, 54, 34, 53, 36, 14, 70, 26, 2, 90, 45, 13, 31, 61, 83, 73, 47], [36, 10, 63, 96, 60, 49, 41, 5, 37, 42, 14, 58, 84, 93, 96, 17, 9, 43, 5, 43, 6, 59], [66, 57, 87, 57, 61, 28, 37, 51, 84, 73, 79, 15, 39, 95, 88, 87, 43, 39, 11, 86, 77, 74, 18], [54, 42, 5, 79, 30, 49, 99, 73, 46, 37, 50, 2, 45, 9, 54, 52, 27, 95, 27, 65, 19, 45, 26, 45], [71, 39, 17, 78, 76, 29, 52, 90, 18, 99, 78, 19, 35, 62, 71, 19, 23, 65, 93, 85, 49, 33, 75, 9, 2], [33, 24, 47, 61, 60, 55, 32, 88, 57, 55, 91, 54, 46, 57, 7, 77, 98, 52, 80, 99, 24, 25, 46, 78, 79, 5], [92, 9, 13, 55, 10, 67, 26, 78, 76, 82, 63, 49, 51, 31, 24, 68, 5, 57, 7, 54, 69, 21, 67, 43, 17, 63, 12], [24, 59, 6, 8, 98, 74, 66, 26, 61, 60, 13, 3, 9, 9, 24, 30, 71, 8, 88, 70, 72, 70, 29, 90, 11, 82, 41, 34], [66, 82, 67, 4, 36, 60, 92, 77, 91, 85, 62, 49, 59, 61, 30, 90, 29, 94, 26, 41, 89, 4, 53, 22, 83, 41, 9, 74, 90], [48, 28, 26, 37, 28, 52, 77, 26, 51, 32, 18, 98, 79, 36, 62, 13, 17, 8, 19, 54, 89, 29, 73, 68, 42, 14, 8, 16, 70, 37], [37, 60, 69, 70, 72, 71, 9, 59, 13, 60, 38, 13, 57, 36, 9, 30, 43, 89, 30, 39, 15, 2, 44, 73, 5, 73, 26, 63, 56, 86, 12], [55, 55, 85, 50, 62, 99, 84, 77, 28, 85, 3, 21, 27, 22, 19, 26, 82, 69, 54, 4, 13, 7, 85, 14, 1, 15, 70, 59, 89, 95, 10, 19], [4, 9, 31, 92, 91, 38, 92, 86, 98, 75, 21, 5, 64, 42, 62, 84, 36, 20, 73, 42, 21, 23, 22, 51, 51, 79, 25, 45, 85, 53, 3, 43, 22], [75, 63, 2, 49, 14, 12, 89, 14, 60, 78, 92, 16, 44, 82, 38, 30, 72, 11, 46, 52, 90, 27, 8, 65, 78, 3, 85, 41, 57, 79, 39, 52, 33, 48], [78, 27, 56, 56, 39, 13, 19, 43, 86, 72, 58, 95, 39, 7, 4, 34, 21, 98, 39, 15, 39, 84, 89, 69, 84, 46, 37, 57, 59, 35, 59, 50, 26, 15, 93], [42, 89, 36, 27, 78, 91, 24, 11, 17, 41, 5, 94, 7, 69, 51, 96, 3, 96, 47, 90, 90, 45, 91, 20, 50, 56, 10, 32, 36, 49, 4, 53, 85, 92, 25, 65], [52, 9, 61, 30, 61, 97, 66, 21, 96, 92, 98, 90, 6, 34, 96, 60, 32, 69, 68, 33, 75, 84, 18, 31, 71, 50, 84, 63, 3, 3, 19, 11, 28, 42, 75, 45, 45], [61, 31, 61, 68, 96, 34, 49, 39, 5, 71, 76, 59, 62, 67, 6, 47, 96, 99, 34, 21, 32, 47, 52, 7, 71, 60, 42, 72, 94, 56, 82, 83, 84, 40, 94, 87, 82, 46], [1, 20, 60, 14, 17, 38, 26, 78, 66, 81, 45, 95, 18, 51, 98, 81, 48, 16, 53, 88, 37, 52, 69, 95, 72, 93, 22, 34, 98, 20, 54, 27, 73, 61, 56, 63, 60, 34, 63], [93, 42, 94, 83, 47, 61, 27, 51, 79, 79, 45, 1, 44, 73, 31, 70, 83, 42, 88, 25, 53, 51, 30, 15, 65, 94, 80, 44, 61, 84, 12, 77, 2, 62, 2, 65, 94, 42, 14, 94], [32, 73, 9, 67, 68, 29, 74, 98, 10, 19, 85, 48, 38, 31, 85, 67, 53, 93, 93, 77, 47, 67, 39, 72, 94, 53, 18, 43, 77, 40, 78, 32, 29, 59, 24, 6, 2, 83, 50, 60, 66], [32, 1, 44, 30, 16, 51, 15, 81, 98, 15, 10, 62, 86, 79, 50, 62, 45, 60, 70, 38, 31, 85, 65, 61, 64, 6, 69, 84, 14, 22, 56, 43, 9, 48, 66, 69, 83, 91, 60, 40, 36, 61], [92, 48, 22, 99, 15, 95, 64, 43, 1, 16, 94, 2, 99, 19, 17, 69, 11, 58, 97, 56, 89, 31, 77, 45, 67, 96, 12, 73, 8, 20, 36, 47, 81, 44, 50, 64, 68, 85, 40, 81, 85, 52, 9], [91, 35, 92, 45, 32, 84, 62, 15, 19, 64, 21, 66, 6, 1, 52, 80, 62, 59, 12, 25, 88, 28, 91, 50, 40, 16, 22, 99, 92, 79, 87, 51, 21, 77, 74, 77, 7, 42, 38, 42, 74, 83, 2, 5], [46, 19, 77, 66, 24, 18, 5, 32, 2, 84, 31, 99, 92, 58, 96, 72, 91, 36, 62, 99, 55, 29, 53, 42, 12, 37, 26, 58, 89, 50, 66, 19, 82, 75, 12, 48, 24, 87, 91, 85, 2, 7, 3, 76, 86], [99, 98, 84, 93, 7, 17, 33, 61, 92, 20, 66, 60, 24, 66, 40, 30, 67, 5, 37, 29, 24, 96, 3, 27, 70, 62, 13, 4, 45, 47, 59, 88, 43, 20, 66, 15, 46, 92, 30, 4, 71, 66, 78, 70, 53, 99], [67, 60, 38, 6, 88, 4, 17, 72, 10, 99, 71, 7, 42, 25, 54, 5, 26, 64, 91, 50, 45, 71, 6, 30, 67, 48, 69, 82, 8, 56, 80, 67, 18, 46, 66, 63, 1, 20, 8, 80, 47, 7, 91, 16, 3, 79, 87], [18, 54, 78, 49, 80, 48, 77, 40, 68, 23, 60, 88, 58, 80, 33, 57, 11, 69, 55, 53, 64, 2, 94, 49, 60, 92, 16, 35, 81, 21, 82, 96, 25, 24, 96, 18, 2, 5, 49, 3, 50, 77, 6, 32, 84, 27, 18, 38], [68, 1, 50, 4, 3, 21, 42, 94, 53, 24, 89, 5, 92, 26, 52, 36, 68, 11, 85, 1, 4, 42, 2, 45, 15, 6, 50, 4, 53, 73, 25, 74, 81, 88, 98, 21, 67, 84, 79, 97, 99, 20, 95, 4, 40, 46, 2, 58, 87], [94, 10, 2, 78, 88, 52, 21, 3, 88, 60, 6, 53, 49, 71, 20, 91, 12, 65, 7, 49, 21, 22, 11, 41, 58, 99, 36, 16, 9, 48, 17, 24, 52, 36, 23, 15, 72, 16, 84, 56, 2, 99, 43, 76, 81, 71, 29, 39, 49, 17], [64, 39, 59, 84, 86, 16, 17, 66, 3, 9, 43, 6, 64, 18, 63, 29, 68, 6, 23, 7, 87, 14, 26, 35, 17, 12, 98, 41, 53, 64, 78, 18, 98, 27, 28, 84, 80, 67, 75, 62, 10, 11, 76, 90, 54, 10, 5, 54, 41, 39, 66], [43, 83, 18, 37, 32, 31, 52, 29, 95, 47, 8, 76, 35, 11, 4, 53, 35, 43, 34, 10, 52, 57, 12, 36, 20, 39, 40, 55, 78, 44, 7, 31, 38, 26, 8, 15, 56, 88, 86, 1, 52, 62, 10, 24, 32, 5, 60, 65, 53, 28, 57, 99], [3, 50, 3, 52, 7, 73, 49, 92, 66, 80, 1, 46, 8, 67, 25, 36, 73, 93, 7, 42, 25, 53, 13, 96, 76, 83, 87, 90, 54, 89, 78, 22, 78, 91, 73, 51, 69, 9, 79, 94, 83, 53, 9, 40, 69, 62, 10, 79, 49, 47, 3, 81, 30], [71, 54, 73, 33, 51, 76, 59, 54, 79, 37, 56, 45, 84, 17, 62, 21, 98, 69, 41, 95, 65, 24, 39, 37, 62, 3, 24, 48, 54, 64, 46, 82, 71, 78, 33, 67, 9, 16, 96, 68, 52, 74, 79, 68, 32, 21, 13, 78, 96, 60, 9, 69, 20, 36], [73, 26, 21, 44, 46, 38, 17, 83, 65, 98, 7, 23, 52, 46, 61, 97, 33, 13, 60, 31, 70, 15, 36, 77, 31, 58, 56, 93, 75, 68, 21, 36, 69, 53, 90, 75, 25, 82, 39, 50, 65, 94, 29, 30, 11, 33, 11, 13, 96, 2, 56, 47, 7, 49, 2], [76, 46, 73, 30, 10, 20, 60, 70, 14, 56, 34, 26, 37, 39, 48, 24, 55, 76, 84, 91, 39, 86, 95, 61, 50, 14, 53, 93, 64, 67, 37, 31, 10, 84, 42, 70, 48, 20, 10, 72, 60, 61, 84, 79, 69, 65, 99, 73, 89, 25, 85, 48, 92, 56, 97, 16], [3, 14, 80, 27, 22, 30, 44, 27, 67, 75, 79, 32, 51, 54, 81, 29, 65, 14, 19, 4, 13, 82, 4, 91, 43, 40, 12, 52, 29, 99, 7, 76, 60, 25, 1, 7, 61, 71, 37, 92, 40, 47, 99, 66, 57, 1, 43, 44, 22, 40, 53, 53, 9, 69, 26, 81, 7], [49, 80, 56, 90, 93, 87, 47, 13, 75, 28, 87, 23, 72, 79, 32, 18, 27, 20, 28, 10, 37, 59, 21, 18, 70, 4, 79, 96, 3, 31, 45, 71, 81, 6, 14, 18, 17, 5, 31, 50, 92, 79, 23, 47, 9, 39, 47, 91, 43, 54, 69, 47, 42, 95, 62, 46, 32, 85], [37, 18, 62, 85, 87, 28, 64, 5, 77, 51, 47, 26, 30, 65, 5, 70, 65, 75, 59, 80, 42, 52, 25, 20, 44, 10, 92, 17, 71, 95, 52, 14, 77, 13, 24, 55, 11, 65, 26, 91, 1, 30, 63, 15, 49, 48, 41, 17, 67, 47, 3, 68, 20, 90, 98, 32, 4, 40, 68], [90, 51, 58, 60, 6, 55, 23, 68, 5, 19, 76, 94, 82, 36, 96, 43, 38, 90, 87, 28, 33, 83, 5, 17, 70, 83, 96, 93, 6, 4, 78, 47, 80, 6, 23, 84, 75, 23, 87, 72, 99, 14, 50, 98, 92, 38, 90, 64, 61, 58, 76, 94, 36, 66, 87, 80, 51, 35, 61, 38], [57, 95, 64, 6, 53, 36, 82, 51, 40, 33, 47, 14, 7, 98, 78, 65, 39, 58, 53, 6, 50, 53, 4, 69, 40, 68, 36, 69, 75, 78, 75, 60, 3, 32, 39, 24, 74, 47, 26, 90, 13, 40, 44, 71, 90, 76, 51, 24, 36, 50, 25, 45, 70, 80, 61, 80, 61, 43, 90, 64, 11], [18, 29, 86, 56, 68, 42, 79, 10, 42, 44, 30, 12, 96, 18, 23, 18, 52, 59, 2, 99, 67, 46, 60, 86, 43, 38, 55, 17, 44, 93, 42, 21, 55, 14, 47, 34, 55, 16, 49, 24, 23, 29, 96, 51, 55, 10, 46, 53, 27, 92, 27, 46, 63, 57, 30, 65, 43, 27, 21, 20, 24, 83], [81, 72, 93, 19, 69, 52, 48, 1, 13, 83, 92, 69, 20, 48, 69, 59, 20, 62, 5, 42, 28, 89, 90, 99, 32, 72, 84, 17, 8, 87, 36, 3, 60, 31, 36, 36, 81, 26, 97, 36, 48, 54, 56, 56, 27, 16, 91, 8, 23, 11, 87, 99, 33, 47, 2, 14, 44, 73, 70, 99, 43, 35, 33], [90, 56, 61, 86, 56, 12, 70, 59, 63, 32, 1, 15, 81, 47, 71, 76, 95, 32, 65, 80, 54, 70, 34, 51, 40, 45, 33, 4, 64, 55, 78, 68, 88, 47, 31, 47, 68, 87, 3, 84, 23, 44, 89, 72, 35, 8, 31, 76, 63, 26, 90, 85, 96, 67, 65, 91, 19, 14, 17, 86, 4, 71, 32, 95], [37, 13, 4, 22, 64, 37, 37, 28, 56, 62, 86, 33, 7, 37, 10, 44, 52, 82, 52, 6, 19, 52, 57, 75, 90, 26, 91, 24, 6, 21, 14, 67, 76, 30, 46, 14, 35, 89, 89, 41, 3, 64, 56, 97, 87, 63, 22, 34, 3, 79, 17, 45, 11, 53, 25, 56, 96, 61, 23, 18, 63, 31, 37, 37, 47], [77, 23, 26, 70, 72, 76, 77, 4, 28, 64, 71, 69, 14, 85, 96, 54, 95, 48, 6, 62, 99, 83, 86, 77, 97, 75, 71, 66, 30, 19, 57, 90, 33, 1, 60, 61, 14, 12, 90, 99, 32, 77, 56, 41, 18, 14, 87, 49, 10, 14, 90, 64, 18, 50, 21, 74, 14, 16, 88, 5, 45, 73, 82, 47, 74, 44], [22, 97, 41, 13, 34, 31, 54, 61, 56, 94, 3, 24, 59, 27, 98, 77, 4, 9, 37, 40, 12, 26, 87, 9, 71, 70, 7, 18, 64, 57, 80, 21, 12, 71, 83, 94, 60, 39, 73, 79, 73, 19, 97, 32, 64, 29, 41, 7, 48, 84, 85, 67, 12, 74, 95, 20, 24, 52, 41, 67, 56, 61, 29, 93, 35, 72, 69], [72, 23, 63, 66, 1, 11, 7, 30, 52, 56, 95, 16, 65, 26, 83, 90, 50, 74, 60, 18, 16, 48, 43, 77, 37, 11, 99, 98, 30, 94, 91, 26, 62, 73, 45, 12, 87, 73, 47, 27, 1, 88, 66, 99, 21, 41, 95, 80, 2, 53, 23, 32, 61, 48, 32, 43, 43, 83, 14, 66, 95, 91, 19, 81, 80, 67, 25, 88], [8, 62, 32, 18, 92, 14, 83, 71, 37, 96, 11, 83, 39, 99, 5, 16, 23, 27, 10, 67, 2, 25, 44, 11, 55, 31, 46, 64, 41, 56, 44, 74, 26, 81, 51, 31, 45, 85, 87, 9, 81, 95, 22, 28, 76, 69, 46, 48, 64, 87, 67, 76, 27, 89, 31, 11, 74, 16, 62, 3, 60, 94, 42, 47, 9, 34, 94, 93, 72], [56, 18, 90, 18, 42, 17, 42, 32, 14, 86, 6, 53, 33, 95, 99, 35, 29, 15, 44, 20, 49, 59, 25, 54, 34, 59, 84, 21, 23, 54, 35, 90, 78, 16, 93, 13, 37, 88, 54, 19, 86, 67, 68, 55, 66, 84, 65, 42, 98, 37, 87, 56, 33, 28, 58, 38, 28, 38, 66, 27, 52, 21, 81, 15, 8, 22, 97, 32, 85, 27], [91, 53, 40, 28, 13, 34, 91, 25, 1, 63, 50, 37, 22, 49, 71, 58, 32, 28, 30, 18, 68, 94, 23, 83, 63, 62, 94, 76, 80, 41, 90, 22, 82, 52, 29, 12, 18, 56, 10, 8, 35, 14, 37, 57, 23, 65, 67, 40, 72, 39, 93, 39, 70, 89, 40, 34, 7, 46, 94, 22, 20, 5, 53, 64, 56, 30, 5, 56, 61, 88, 27], [23, 95, 11, 12, 37, 69, 68, 24, 66, 10, 87, 70, 43, 50, 75, 7, 62, 41, 83, 58, 95, 93, 89, 79, 45, 39, 2, 22, 5, 22, 95, 43, 62, 11, 68, 29, 17, 40, 26, 44, 25, 71, 87, 16, 70, 85, 19, 25, 59, 94, 90, 41, 41, 80, 61, 70, 55, 60, 84, 33, 95, 76, 42, 63, 15, 9, 3, 40, 38, 12, 3, 32], [9, 84, 56, 80, 61, 55, 85, 97, 16, 94, 82, 94, 98, 57, 84, 30, 84, 48, 93, 90, 71, 5, 95, 90, 73, 17, 30, 98, 40, 64, 65, 89, 7, 79, 9, 19, 56, 36, 42, 30, 23, 69, 73, 72, 7, 5, 27, 61, 24, 31, 43, 48, 71, 84, 21, 28, 26, 65, 65, 59, 65, 74, 77, 20, 10, 81, 61, 84, 95, 8, 52, 23, 70], [47, 81, 28, 9, 98, 51, 67, 64, 35, 51, 59, 36, 92, 82, 77, 65, 80, 24, 72, 53, 22, 7, 27, 10, 21, 28, 30, 22, 48, 82, 80, 48, 56, 20, 14, 43, 18, 25, 50, 95, 90, 31, 77, 8, 9, 48, 44, 80, 90, 22, 93, 45, 82, 17, 13, 96, 25, 26, 8, 73, 34, 99, 6, 49, 24, 6, 83, 51, 40, 14, 15, 10, 25, 1], [54, 25, 10, 81, 30, 64, 24, 74, 75, 80, 36, 75, 82, 60, 22, 69, 72, 91, 45, 67, 3, 62, 79, 54, 89, 74, 44, 83, 64, 96, 66, 73, 44, 30, 74, 50, 37, 5, 9, 97, 70, 1, 60, 46, 37, 91, 39, 75, 75, 18, 58, 52, 72, 78, 51, 81, 86, 52, 8, 97, 1, 46, 43, 66, 98, 62, 81, 18, 70, 93, 73, 8, 32, 46, 34], [96, 80, 82, 7, 59, 71, 92, 53, 19, 20, 88, 66, 3, 26, 26, 10, 24, 27, 50, 82, 94, 73, 63, 8, 51, 33, 22, 45, 19, 13, 58, 33, 90, 15, 22, 50, 36, 13, 55, 6, 35, 47, 82, 52, 33, 61, 36, 27, 28, 46, 98, 14, 73, 20, 73, 32, 16, 26, 80, 53, 47, 66, 76, 38, 94, 45, 2, 1, 22, 52, 47, 96, 64, 58, 52, 39], [88, 46, 23, 39, 74, 63, 81, 64, 20, 90, 33, 33, 76, 55, 58, 26, 10, 46, 42, 26, 74, 74, 12, 83, 32, 43, 9, 2, 73, 55, 86, 54, 85, 34, 28, 23, 29, 79, 91, 62, 47, 41, 82, 87, 99, 22, 48, 90, 20, 5, 96, 75, 95, 4, 43, 28, 81, 39, 81, 1, 28, 42, 78, 25, 39, 77, 90, 57, 58, 98, 17, 36, 73, 22, 63, 74, 51], [29, 39, 74, 94, 95, 78, 64, 24, 38, 86, 63, 87, 93, 6, 70, 92, 22, 16, 80, 64, 29, 52, 20, 27, 23, 50, 14, 13, 87, 15, 72, 96, 81, 22, 8, 49, 72, 30, 70, 24, 79, 31, 16, 64, 59, 21, 89, 34, 96, 91, 48, 76, 43, 53, 88, 1, 57, 80, 23, 81, 90, 79, 58, 1, 80, 87, 17, 99, 86, 90, 72, 63, 32, 69, 14, 28, 88, 69], [37, 17, 71, 95, 56, 93, 71, 35, 43, 45, 4, 98, 92, 94, 84, 96, 11, 30, 31, 27, 31, 60, 92, 3, 48, 5, 98, 91, 86, 94, 35, 90, 90, 8, 48, 19, 33, 28, 68, 37, 59, 26, 65, 96, 50, 68, 22, 7, 9, 49, 34, 31, 77, 49, 43, 6, 75, 17, 81, 87, 61, 79, 52, 26, 27, 72, 29, 50, 7, 98, 86, 1, 17, 10, 46, 64, 24, 18, 56], [51, 30, 25, 94, 88, 85, 79, 91, 40, 33, 63, 84, 49, 67, 98, 92, 15, 26, 75, 19, 82, 5, 18, 78, 65, 93, 61, 48, 91, 43, 59, 41, 70, 51, 22, 15, 92, 81, 67, 91, 46, 98, 11, 11, 65, 31, 66, 10, 98, 65, 83, 21, 5, 56, 5, 98, 73, 67, 46, 74, 69, 34, 8, 30, 5, 52, 7, 98, 32, 95, 30, 94, 65, 50, 24, 63, 28, 81, 99, 57], [19, 23, 61, 36, 9, 89, 71, 98, 65, 17, 30, 29, 89, 26, 79, 74, 94, 11, 44, 48, 97, 54, 81, 55, 39, 66, 69, 45, 28, 47, 13, 86, 15, 76, 74, 70, 84, 32, 36, 33, 79, 20, 78, 14, 41, 47, 89, 28, 81, 5, 99, 66, 81, 86, 38, 26, 6, 25, 13, 60, 54, 55, 23, 53, 27, 5, 89, 25, 23, 11, 13, 54, 59, 54, 56, 34, 16, 24, 53, 44, 6], [13, 40, 57, 72, 21, 15, 60, 8, 4, 19, 11, 98, 34, 45, 9, 97, 86, 71, 3, 15, 56, 19, 15, 44, 97, 31, 90, 4, 87, 87, 76, 8, 12, 30, 24, 62, 84, 28, 12, 85, 82, 53, 99, 52, 13, 94, 6, 65, 97, 86, 9, 50, 94, 68, 69, 74, 30, 67, 87, 94, 63, 7, 78, 27, 80, 36, 69, 41, 6, 92, 32, 78, 37, 82, 30, 5, 18, 87, 99, 72, 19, 99], [44, 20, 55, 77, 69, 91, 27, 31, 28, 81, 80, 27, 2, 7, 97, 23, 95, 98, 12, 25, 75, 29, 47, 71, 7, 47, 78, 39, 41, 59, 27, 76, 13, 15, 66, 61, 68, 35, 69, 86, 16, 53, 67, 63, 99, 85, 41, 56, 8, 28, 33, 40, 94, 76, 90, 85, 31, 70, 24, 65, 84, 65, 99, 82, 19, 25, 54, 37, 21, 46, 33, 2, 52, 99, 51, 33, 26, 4, 87, 2, 8, 18, 96], [54, 42, 61, 45, 91, 6, 64, 79, 80, 82, 32, 16, 83, 63, 42, 49, 19, 78, 65, 97, 40, 42, 14, 61, 49, 34, 4, 18, 25, 98, 59, 30, 82, 72, 26, 88, 54, 36, 21, 75, 3, 88, 99, 53, 46, 51, 55, 78, 22, 94, 34, 40, 68, 87, 84, 25, 30, 76, 25, 8, 92, 84, 42, 61, 40, 38, 9, 99, 40, 23, 29, 39, 46, 55, 10, 90, 35, 84, 56, 70, 63, 23, 91, 39], [52, 92, 3, 71, 89, 7, 9, 37, 68, 66, 58, 20, 44, 92, 51, 56, 13, 71, 79, 99, 26, 37, 2, 6, 16, 67, 36, 52, 58, 16, 79, 73, 56, 60, 59, 27, 44, 77, 94, 82, 20, 50, 98, 33, 9, 87, 94, 37, 40, 83, 64, 83, 58, 85, 17, 76, 53, 2, 83, 52, 22, 27, 39, 20, 48, 92, 45, 21, 9, 42, 24, 23, 12, 37, 52, 28, 50, 78, 79, 20, 86, 62, 73, 20, 59], [54, 96, 80, 15, 91, 90, 99, 70, 10, 9, 58, 90, 93, 50, 81, 99, 54, 38, 36, 10, 30, 11, 35, 84, 16, 45, 82, 18, 11, 97, 36, 43, 96, 79, 97, 65, 40, 48, 23, 19, 17, 31, 64, 52, 65, 65, 37, 32, 65, 76, 99, 79, 34, 65, 79, 27, 55, 33, 3, 1, 33, 27, 61, 28, 66, 8, 4, 70, 49, 46, 48, 83, 1, 45, 19, 96, 13, 81, 14, 21, 31, 79, 93, 85, 50, 5], [92, 92, 48, 84, 59, 98, 31, 53, 23, 27, 15, 22, 79, 95, 24, 76, 5, 79, 16, 93, 97, 89, 38, 89, 42, 83, 2, 88, 94, 95, 82, 21, 1, 97, 48, 39, 31, 78, 9, 65, 50, 56, 97, 61, 1, 7, 65, 27, 21, 23, 14, 15, 80, 97, 44, 78, 49, 35, 33, 45, 81, 74, 34, 5, 31, 57, 9, 38, 94, 7, 69, 54, 69, 32, 65, 68, 46, 68, 78, 90, 24, 28, 49, 51, 45, 86, 35], [41, 63, 89, 76, 87, 31, 86, 9, 46, 14, 87, 82, 22, 29, 47, 16, 13, 10, 70, 72, 82, 95, 48, 64, 58, 43, 13, 75, 42, 69, 21, 12, 67, 13, 64, 85, 58, 23, 98, 9, 37, 76, 5, 22, 31, 12, 66, 50, 29, 99, 86, 72, 45, 25, 10, 28, 19, 6, 90, 43, 29, 31, 67, 79, 46, 25, 74, 14, 97, 35, 76, 37, 65, 46, 23, 82, 6, 22, 30, 76, 93, 66, 94, 17, 96, 13, 20, 72], [63, 40, 78, 8, 52, 9, 90, 41, 70, 28, 36, 14, 46, 44, 85, 96, 24, 52, 58, 15, 87, 37, 5, 98, 99, 39, 13, 61, 76, 38, 44, 99, 83, 74, 90, 22, 53, 80, 56, 98, 30, 51, 63, 39, 44, 30, 91, 91, 4, 22, 27, 73, 17, 35, 53, 18, 35, 45, 54, 56, 27, 78, 48, 13, 69, 36, 44, 38, 71, 25, 30, 56, 15, 22, 73, 43, 32, 69, 59, 25, 93, 83, 45, 11, 34, 94, 44, 39, 92], [12, 36, 56, 88, 13, 96, 16, 12, 55, 54, 11, 47, 19, 78, 17, 17, 68, 81, 77, 51, 42, 55, 99, 85, 66, 27, 81, 79, 93, 42, 65, 61, 69, 74, 14, 1, 18, 56, 12, 1, 58, 37, 91, 22, 42, 66, 83, 25, 19, 4, 96, 41, 25, 45, 18, 69, 96, 88, 36, 93, 10, 12, 98, 32, 44, 83, 83, 4, 72, 91, 4, 27, 73, 7, 34, 37, 71, 60, 59, 31, 1, 54, 54, 44, 96, 93, 83, 36, 4, 45], [30, 18, 22, 20, 42, 96, 65, 79, 17, 41, 55, 69, 94, 81, 29, 80, 91, 31, 85, 25, 47, 26, 43, 49, 2, 99, 34, 67, 99, 76, 16, 14, 15, 93, 8, 32, 99, 44, 61, 77, 67, 50, 43, 55, 87, 55, 53, 72, 17, 46, 62, 25, 50, 99, 73, 5, 93, 48, 17, 31, 70, 80, 59, 9, 44, 59, 45, 13, 74, 66, 58, 94, 87, 73, 16, 14, 85, 38, 74, 99, 64, 23, 79, 28, 71, 42, 20, 37, 82, 31, 23], [51, 96, 39, 65, 46, 71, 56, 13, 29, 68, 53, 86, 45, 33, 51, 49, 12, 91, 21, 21, 76, 85, 2, 17, 98, 15, 46, 12, 60, 21, 88, 30, 92, 83, 44, 59, 42, 50, 27, 88, 46, 86, 94, 73, 45, 54, 23, 24, 14, 10, 94, 21, 20, 34, 23, 51, 4, 83, 99, 75, 90, 63, 60, 16, 22, 33, 83, 70, 11, 32, 10, 50, 29, 30, 83, 46, 11, 5, 31, 17, 86, 42, 49, 1, 44, 63, 28, 60, 7, 78, 95, 40], [44, 61, 89, 59, 4, 49, 51, 27, 69, 71, 46, 76, 44, 4, 9, 34, 56, 39, 15, 6, 94, 91, 75, 90, 65, 27, 56, 23, 74, 6, 23, 33, 36, 69, 14, 39, 5, 34, 35, 57, 33, 22, 76, 46, 56, 10, 61, 65, 98, 9, 16, 69, 4, 62, 65, 18, 99, 76, 49, 18, 72, 66, 73, 83, 82, 40, 76, 31, 89, 91, 27, 88, 17, 35, 41, 35, 32, 51, 32, 67, 52, 68, 74, 85, 80, 57, 7, 11, 62, 66, 47, 22, 67], [65, 37, 19, 97, 26, 17, 16, 24, 24, 17, 50, 37, 64, 82, 24, 36, 32, 11, 68, 34, 69, 31, 32, 89, 79, 93, 96, 68, 49, 90, 14, 23, 4, 4, 67, 99, 81, 74, 70, 74, 36, 96, 68, 9, 64, 39, 88, 35, 54, 89, 96, 58, 66, 27, 88, 97, 32, 14, 6, 35, 78, 20, 71, 6, 85, 66, 57, 2, 58, 91, 72, 5, 29, 56, 73, 48, 86, 52, 9, 93, 22, 57, 79, 42, 12, 1, 31, 68, 17, 59, 63, 76, 7, 77], [73, 81, 14, 13, 17, 20, 11, 9, 1, 83, 8, 85, 91, 70, 84, 63, 62, 77, 37, 7, 47, 1, 59, 95, 39, 69, 39, 21, 99, 9, 87, 2, 97, 16, 92, 36, 74, 71, 90, 66, 33, 73, 73, 75, 52, 91, 11, 12, 26, 53, 5, 26, 26, 48, 61, 50, 90, 65, 1, 87, 42, 47, 74, 35, 22, 73, 24, 26, 56, 70, 52, 5, 48, 41, 31, 18, 83, 27, 21, 39, 80, 85, 26, 8, 44, 2, 71, 7, 63, 22, 5, 52, 19, 8, 20], [17, 25, 21, 11, 72, 93, 33, 49, 64, 23, 53, 82, 3, 13, 91, 65, 85, 2, 40, 5, 42, 31, 77, 42, 5, 36, 6, 54, 4, 58, 7, 76, 87, 83, 25, 57, 66, 12, 74, 33, 85, 37, 74, 32, 20, 69, 3, 97, 91, 68, 82, 44, 19, 14, 89, 28, 85, 85, 80, 53, 34, 87, 58, 98, 88, 78, 48, 65, 98, 40, 11, 57, 10, 67, 70, 81, 60, 79, 74, 72, 97, 59, 79, 47, 30, 20, 54, 80, 89, 91, 14, 5, 33, 36, 79, 39], [60, 85, 59, 39, 60, 7, 57, 76, 77, 92, 6, 35, 15, 72, 23, 41, 45, 52, 95, 18, 64, 79, 86, 53, 56, 31, 69, 11, 91, 31, 84, 50, 44, 82, 22, 81, 41, 40, 30, 42, 30, 91, 48, 94, 74, 76, 64, 58, 74, 25, 96, 57, 14, 19, 3, 99, 28, 83, 15, 75, 99, 1, 89, 85, 79, 50, 3, 95, 32, 67, 44, 8, 7, 41, 62, 64, 29, 20, 14, 76, 26, 55, 48, 71, 69, 66, 19, 72, 44, 25, 14, 1, 48, 74, 12, 98, 7], [64, 66, 84, 24, 18, 16, 27, 48, 20, 14, 47, 69, 30, 86, 48, 40, 23, 16, 61, 21, 51, 50, 26, 47, 35, 33, 91, 28, 78, 64, 43, 68, 4, 79, 51, 8, 19, 60, 52, 95, 6, 68, 46, 86, 35, 97, 27, 58, 4, 65, 30, 58, 99, 12, 12, 75, 91, 39, 50, 31, 42, 64, 70, 4, 46, 7, 98, 73, 98, 93, 37, 89, 77, 91, 64, 71, 64, 65, 66, 21, 78, 62, 81, 74, 42, 20, 83, 70, 73, 95, 78, 45, 92, 27, 34, 53, 71, 15], [30, 11, 85, 31, 34, 71, 13, 48, 5, 14, 44, 3, 19, 67, 23, 73, 19, 57, 6, 90, 94, 72, 57, 69, 81, 62, 59, 68, 88, 57, 55, 69, 49, 13, 7, 87, 97, 80, 89, 5, 71, 5, 5, 26, 38, 40, 16, 62, 45, 99, 18, 38, 98, 24, 21, 26, 62, 74, 69, 4, 85, 57, 77, 35, 58, 67, 91, 79, 79, 57, 86, 28, 66, 34, 72, 51, 76, 78, 36, 95, 63, 90, 8, 78, 47, 63, 45, 31, 22, 70, 52, 48, 79, 94, 15, 77, 61, 67, 68], [23, 33, 44, 81, 80, 92, 93, 75, 94, 88, 23, 61, 39, 76, 22, 3, 28, 94, 32, 6, 49, 65, 41, 34, 18, 23, 8, 47, 62, 60, 3, 63, 33, 13, 80, 52, 31, 54, 73, 43, 70, 26, 16, 69, 57, 87, 83, 31, 3, 93, 70, 81, 47, 95, 77, 44, 29, 68, 39, 51, 56, 59, 63, 7, 25, 70, 7, 77, 43, 53, 64, 3, 94, 42, 95, 39, 18, 1, 66, 21, 16, 97, 20, 50, 90, 16, 70, 10, 95, 69, 29, 6, 25, 61, 41, 26, 15, 59, 63, 35]]]], "outputs": [[23], [1074], [7273]]}
INTERVIEW
PYTHON3
CODEWARS
2,916
def longest_slide_down(pyramid):
a1cc0f6ce802cd8bdb2a9da1c7bc139f
UNKNOWN
In this kata we want to convert a string into an integer. The strings simply represent the numbers in words. Examples: * "one" => 1 * "twenty" => 20 * "two hundred forty-six" => 246 * "seven hundred eighty-three thousand nine hundred and nineteen" => 783919 Additional Notes: * The minimum number is "zero" (inclusively) * The maximum number, which must be supported is 1 million (inclusively) * The "and" in e.g. "one hundred and twenty-four" is optional, in some cases it's present and in others it's not * All tested numbers are valid, you don't need to validate them
["words = {w: n for n, w in enumerate('zero one two three four five six seven eight nine ten eleven twelve thirteen fourteen fifteen sixteen seventeen eighteen nineteen'.split())}\nwords.update({w: 10 * n for n, w in enumerate('twenty thirty forty fifty sixty seventy eighty ninety hundred'.split(), 2)})\nthousands = {w: 1000 ** n for n, w in enumerate('thousand million billion trillion quadrillion quintillion sextillion septillion octillion nonillion decillion'.split(), 1)}\ndef parse_int(strng):\n num = group = 0\n for w in strng.replace(' and ', ' ').replace('-', ' ').split():\n if w == 'hundred': group *= words[w]\n elif w in words: group += words[w]\n else:\n num += group * thousands[w]\n group = 0\n return num + group", "ONES = ['zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine',\n 'ten', 'eleven', 'twelve', 'thirteen', 'fourteen', 'fifteen', 'sixteen', 'seventeen', \n 'eighteen', 'nineteen']\nTENS = ['twenty', 'thirty', 'forty', 'fifty', 'sixty', 'seventy', 'eighty', 'ninety']\n\ndef parse_int(string):\n print(string)\n numbers = []\n for token in string.replace('-', ' ').split(' '):\n if token in ONES:\n numbers.append(ONES.index(token))\n elif token in TENS:\n numbers.append((TENS.index(token) + 2) * 10)\n elif token == 'hundred':\n numbers[-1] *= 100\n elif token == 'thousand':\n numbers = [x * 1000 for x in numbers]\n elif token == 'million':\n numbers = [x * 1000000 for x in numbers]\n return sum(numbers)", "dic = {'zero' : 0, \n 'one' : 1, \n 'two' : 2, \n 'three' : 3, \n 'four' : 4, \n 'five' : 5, \n 'six' : 6, \n 'seven' : 7, \n 'eight' : 8, \n 'nine' : 9, \n 'ten' : 10, \n 'eleven' : 11, \n 'twelve' : 12, \n 'thirteen' : 13, \n 'fourteen' : 14, \n 'fifteen' : 15, \n 'sixteen' : 16, \n 'seventeen' : 17, \n 'eighteen' : 18, \n 'nineteen' : 19, \n 'twenty' : 20, \n 'twenty-one' : 21, \n 'twenty-two' : 22, \n 'twenty-three' : 23, \n 'twenty-four' : 24, \n 'twenty-five' : 25, \n 'twenty-six' : 26, \n 'twenty-seven' : 27, \n 'twenty-eight' : 28, \n 'twenty-nine' : 29, \n 'thirty' : 30, \n 'thirty-one' : 31, \n 'thirty-two' : 32, \n 'thirty-three' : 33, \n 'thirty-four' : 34, \n 'thirty-five' : 35, \n 'thirty-six' : 36, \n 'thirty-seven' : 37, \n 'thirty-eight' : 38, \n 'thirty-nine' : 39, \n 'forty' : 40, \n 'forty-one' : 41, \n 'forty-two' : 42, \n 'forty-three' : 43, \n 'forty-four' : 44, \n 'forty-five' : 45, \n 'forty-six' : 46, \n 'forty-seven' : 47, \n 'forty-eight' : 48, \n 'forty-nine' : 49, \n 'fifty' : 50, \n 'fifty-one' : 51, \n 'fifty-two' : 52, \n 'fifty-three' : 53, \n 'fifty-four' : 54, \n 'fifty-five' : 55, \n 'fifty-six' : 56, \n 'fifty-seven' : 57, \n 'fifty-eight' : 58, \n 'fifty-nine' : 59, \n 'sixty' : 60, \n 'sixty-one' : 61, \n 'sixty-two' : 62, \n 'sixty-three' : 63, \n 'sixty-four' : 64, \n 'sixty-five' : 65, \n 'sixty-six' : 66, \n 'sixty-seven' : 67, \n 'sixty-eight' : 68, \n 'sixty-nine' : 69, \n 'seventy' : 70, \n 'seventy-one' : 71, \n 'seventy-two' : 72, \n 'seventy-three': 73, \n 'seventy-four' : 74, \n 'seventy-five' : 75, \n 'seventy-six' : 76, \n 'seventy-seven': 77, \n 'seventy-eight': 78, \n 'seventy-nine' : 79, \n 'eighty' : 80, \n 'eighty-one' : 81, \n 'eighty-two' : 82, \n 'eighty-three' : 83, \n 'eighty-four' : 84, \n 'eighty-five' : 85, \n 'eighty-six' : 86, \n 'eighty-seven' : 87, \n 'eighty-eight' : 88, \n 'eighty-nine' : 89, \n 'ninety' : 90, \n 'ninety-one' : 91, \n 'ninety-two' : 92, \n 'ninety-three' : 93, \n 'ninety-four' : 94, \n 'ninety-five' : 95, \n 'ninety-six' : 96, \n 'ninety-seven' : 97, \n 'ninety-eight' : 98, \n 'ninety-nine' : 99,\n 'hundred' : 100,\n 'thousand' : 1000,\n 'million' : 1000_000,}\n\ndef parse_int(s):\n cn, res = 0, 0\n for number in (dic[w] for w in s.replace(' and','').split() if w in dic):\n if number < 100: cn += number\n elif number == 100: cn *= number\n else : res += cn * number; cn = 0\n return res + cn", "def parse_int(string):\n \n print(string)\n \n setDigit = {\"zero\" :0,\n \"one\" :1,\n \"two\" :2,\n \"three\" :3,\n \"four\" :4,\n \"five\" :5,\n \"six\" :6,\n \"seven\" :7,\n \"eight\" :8,\n \"nine\" :9,\n \"ten\" :10,\n \"eleven\" :11,\n \"twelve\" :12,\n \"thirteen\" :13,\n \"fourteen\" :14,\n \"fifteen\" :15,\n \"sixteen\" :16,\n \"seventeen\" :17,\n \"eighteen\" :18,\n \"nineteen\" :19,\n \"twenty\" :20,\n \"thirty\" :30,\n \"forty\" :40,\n \"fifty\" :50,\n \"sixty\" :60,\n \"seventy\" :70,\n \"eighty\" :80,\n \"ninety\" :90,\n }\n \n \n millionNumber, thousandNumber, hundredNumber, number = (0,) * 4\n \n for word in string.split():\n for newWord in word.split('-'): \n \n try:\n digit = setDigit[newWord]\n number += digit\n except:\n \n if newWord == \"hundred\":\n hundredNumber = number\n number = 0\n \n if newWord == \"thousand\":\n thousandNumber = 100 * hundredNumber + number\n hundredNumber = 0\n number = 0\n \n if newWord == \"million\":\n millionNumber = number\n number = 0\n \n return(millionNumber * 1000000 + thousandNumber * 1000 + hundredNumber * 100 + number)\n \n", "import re\n\nSIMPLIFIER = re.compile(r'(\\s|-|\\band)+')\nSPLITTER = [re.compile(rf'\\s*{what}\\s*') for what in ('million', 'thousand', 'hundred', r'ty\\b')]\nCOEFS = [10**x for x in (6,3,2,1)]\n\nvals = \"zero one two three four five six seven eight nine ten eleven twelve thirteen fourteen fifteen sixteen seventeen eighteen nineteen\".split()\nVALUES = {name:v for name,v in zip(vals, range(len(vals)))}\nVALUES.update({'twen': 2, 'thir': 3, 'for': 4, 'fif': 5, 'eigh':8})\n\n\ndef parse_int(s): \n return parse(0, SIMPLIFIER.sub(' ',s.lower()))\n\ndef parse(i, s):\n if i == len(SPLITTER): return VALUES.get(s,0)\n \n lst, coef, i = SPLITTER[i].split(s), COEFS[i], i+1\n \n return parse(i,lst[0]) if len(lst)==1 else coef * parse(i,lst[0]) + parse(i,lst[1])", "VALUES = {\n 'zero': 0,\n 'one': 1,\n 'two': 2,\n 'three': 3,\n 'four': 4,\n 'five': 5,\n 'six': 6,\n 'seven': 7,\n 'eight': 8,\n 'nine': 9,\n 'ten': 10,\n 'eleven': 11,\n 'twelve': 12,\n 'thirteen': 13,\n 'fourteen': 14,\n 'fifteen': 15,\n 'sixteen': 16,\n 'seventeen': 17,\n 'eighteen': 18,\n 'nineteen': 19,\n 'twenty': 20,\n 'thirty': 30,\n 'forty': 40,\n 'fifty': 50,\n 'sixty': 60,\n 'seventy': 70,\n 'eighty': 80,\n 'ninety': 90,\n}\n\n\ndef parse_int(string): \n if not string:\n return 0\n\n if string == 'one million':\n return 1000000\n\n if string in VALUES:\n return VALUES[string]\n\n if 'thousand' in string:\n before, after = split(string, 'thousand and') if 'thousand and' in string else split(string, 'thousand')\n factor = 1000\n elif 'hundred' in string:\n before, after = split(string, 'hundred and') if 'hundred and' in string else split(string, 'hundred')\n factor = 100\n elif '-' in string:\n before, after = split(string, ' ') if ' ' in string else split(string, '-')\n factor = 1\n\n return parse_int(before) * factor + parse_int(after)\n \n\ndef split(string, separator):\n before, after = string.rsplit(separator, 1)\n return before.strip(), after.strip()", "number_words = {'': 0, 'zero': 0, 'one': 1, 'two': 2, 'three': 3, 'four': 4, 'five': 5, 'six': 6,\n 'seven': 7, 'eight': 8, 'nine': 9, 'ten': 10, 'eleven': 11, 'twelve': 12, 'thirteen': 13,\n 'fourteen': 14, 'fifteen': 15, 'sixteen': 16, 'seventeen': 17, 'eighteen': 18,\n 'nineteen': 19, 'twenty': 20, 'thirty': 30, 'forty': 40, 'fifty': 50, 'sixty': 60,\n 'seventy': 70, 'eighty': 80, 'ninety': 90, 'one million': 1000000}\n\ndef parse_int(string):\n string_words = string.split()\n if 'thousand' in string_words:\n parts = string.partition('thousand')\n return parse_int(parts[0].strip()) * 1000 + parse_int(parts[2].strip())\n elif 'hundred' in string_words:\n parts = string.partition('hundred')\n return parse_int(parts[0].strip()) * 100 + parse_int(parts[2].strip())\n elif '-' in string:\n parts = string.replace('and ', '').split('-')\n return number_words[parts[0]] + number_words[parts[1]]\n else:\n return number_words[string.replace('and ', '')]", "from functools import reduce\ndef parse_int(string):\n unit_ts={'zero':0,'one':1,'two':2,'three':3,'four':4,'five':5,'six':6,'seven':7,'eight':8,'nine':9,'ten':10,'eleven':11,'twelve':12,'thirteen':13,'fourteen':14,'fifteen':15,'sixteen':16,'seventeen':17,'eighteen':18,'nineteen':19,'twenty':20,'thirty':30,'forty':40,'fifty':50,'sixty':60,'seventy':70,'eighty':80,'ninety':90,'hundred':100,'thousand':1000,'million':1000000,'billion':1000000000}\n text=string.split(' ')\n lst=[]\n for element in text:\n if '-' in element:lst.append(unit_ts[element.split('-')[0]]+unit_ts[element.split('-')[1]])\n elif element in unit_ts:lst.append(unit_ts[element])\n myid=lst.index(max(lst))\n result=0\n result+=reduce(lambda x,y:x*y if y%100==0 else x+y,lst[:myid+1])if lst[:myid+1]!=[] else 0\n result+=reduce(lambda x,y:x*y if y%100==0 else x+y,lst[myid+1:])if lst[myid+1:]!=[] else 0\n return result", "def parse_int(string):\n units = [\n \"zero\", \"one\", \"two\", \"three\", \"four\", \"five\", \"six\", \"seven\", \"eight\",\"nine\", \"ten\", \n \"eleven\", \"twelve\", \"thirteen\", \"fourteen\", \"fifteen\", \"sixteen\", \"seventeen\", \"eighteen\",\n \"nineteen\"\n ]\n tens = [\"\", \"\", \"twenty\", \"thirty\", \"forty\", \"fifty\", \"sixty\", \"seventy\", \"eighty\", \"ninety\"]\n \n string = string.replace('-', ' ')\n string = string.replace(' and ',' ')\n words = string.split()\n ans = 0\n final_ans = 0\n \n for word in words:\n if word in units: ans += units.index(word)\n elif word in tens: ans += tens.index(word)*10\n elif word == 'hundred': ans *= 100\n elif word == 'thousand': final_ans,ans = ans*1000, 0\n elif word == 'million': return 1000000\n final_ans += ans \n return final_ans\n", "conv={\n \"zero\": 0,\n \"one\": 1,\n \"two\": 2,\n \"three\": 3,\n \"four\": 4,\n \"five\": 5,\n \"six\": 6,\n \"seven\": 7,\n \"eight\": 8,\n \"nine\": 9,\n \"ten\": 10,\n \"eleven\": 11,\n \"twelve\": 12,\n \"thirteen\": 13,\n \"fourteen\": 14,\n \"fifteen\": 15,\n \"sixteen\": 16,\n \"seventeen\": 17,\n \"eighteen\": 18,\n \"nineteen\": 19,\n \"twenty\": 20,\n \"thirty\": 30,\n \"forty\": 40,\n \"fifty\": 50,\n \"sixty\": 60,\n \"seventy\": 70,\n \"eighty\": 80,\n \"ninety\": 90,\n \"hundred\": 100,\n \"thousand\": 1000,\n \"million\": 1000000\n }\n\n\ndef parse99(s: str):\n num = 0\n for wd in s.split(\"-\"): num += conv.get(wd.strip(), 0)\n return num\n \n\ndef parseHundreds(s: str):\n s = s.split(\"hundred\")\n if len(s) == 1:\n return parse99(s[0])\n else:\n return parse99(s[0])*100 + parse99(s[1])\n \n\ndef parseThousands(s: str):\n s = s.split(\"thousand\")\n if len(s) == 1:\n return parseHundreds(s[0])\n else:\n return parseHundreds(s[0])*1000 + parseHundreds(s[1]) \n \ndef parseMillions(s: str):\n s = s.split(\"million\")\n if len(s) == 1:\n return parseThousands(s[0])\n else:\n return parseThousands(s[0])*1000000 + parseThousands(s[1]) \n\ndef parse_int(s: str):\n #\n return parseMillions(s.replace(\" and \",\" \"))"]
{"fn_name": "parse_int", "inputs": [["zero"], ["one"], ["two"], ["three"], ["four"], ["five"], ["six"], ["seven"], ["eight"], ["nine"], ["ten"], ["twenty"], ["twenty-one"], ["thirty-seven"], ["forty-six"], ["fifty-nine"], ["sixty-eight"], ["seventy-two"], ["eighty-three"], ["ninety-four"], ["one hundred"], ["one hundred one"], ["one hundred and one"], ["one hundred sixty-nine"], ["two hundred and ninety-nine"], ["seven hundred thirty-six"], ["two thousand"], ["one thousand three hundred and thirty-seven"], ["ten thousand"], ["twenty-six thousand three hundred and fifty-nine"], ["thirty-five thousand"], ["ninety-nine thousand nine hundred and ninety-nine"], ["six hundred sixty-six thousand six hundred sixty-six"], ["seven hundred thousand"], ["two hundred thousand three"], ["two hundred thousand and three"], ["two hundred three thousand"], ["five hundred thousand three hundred"], ["eight hundred eighty-eight thousand eight hundred and eighty-eight"], ["one million"]], "outputs": [[0], [1], [2], [3], [4], [5], [6], [7], [8], [9], [10], [20], [21], [37], [46], [59], [68], [72], [83], [94], [100], [101], [101], [169], [299], [736], [2000], [1337], [10000], [26359], [35000], [99999], [666666], [700000], [200003], [200003], [203000], [500300], [888888], [1000000]]}
INTERVIEW
PYTHON3
CODEWARS
14,637
def parse_int(string):
e587a3790b1935e2a1cc199558729732
UNKNOWN
Create a function that differentiates a polynomial for a given value of `x`. Your function will receive 2 arguments: a polynomial as a string, and a point to evaluate the equation as an integer. ## Assumptions: * There will be a coefficient near each `x`, unless the coefficient equals `1` or `-1`. * There will be an exponent near each `x`, unless the exponent equals `0` or `1`. * All exponents will be greater or equal to zero ## Examples: ```python differenatiate("12x+2", 3) ==> returns 12 differenatiate("x^2+3x+2", 3) ==> returns 9 ```
["from collections import defaultdict\nimport re\n\nP = re.compile(r'\\+?(-?\\d*)(x\\^?)?(\\d*)')\n\ndef differentiate(eq, x):\n \n derivate = defaultdict(int)\n for coef,var,exp in P.findall(eq):\n exp = int(exp or var and '1' or '0')\n coef = int(coef!='-' and coef or coef and '-1' or '1')\n \n if exp: derivate[exp-1] += exp * coef\n \n return sum(coef * x**exp for exp,coef in derivate.items())", "def parse_monom(monom):\n if 'x' not in monom: monom = monom + 'x^0'\n if monom.startswith('x'): monom = '1' + monom\n if monom.startswith('-x'): monom = '-1' + monom[1:]\n if monom.endswith('x'): monom = monom + '^1'\n coefficient, degree = map(int, monom.replace('x', '').split('^'))\n return degree, coefficient\n\ndef differentiate(equation, point):\n monoms = equation.replace('-', '+-').lstrip('+').split('+')\n polynom = dict(map(parse_monom, monoms))\n return sum(coefficient * degree * point ** (degree - 1)\n for degree, coefficient in polynom.items() if degree)", "from re import finditer\n\ndef differentiate(equation, point):\n res = 0\n \n for exp in finditer(r'([\\+\\-])?(\\d*)?x\\^?(\\d+)?', equation):\n sign = -1 if exp.group(1) == '-' else 1\n scalar = int(exp.group(2)) if exp.group(2) else 1\n power = int(exp.group(3)) if exp.group(3) else 1\n\n res += sign * (power * scalar) * point ** (power - 1)\n \n return res\n\n", "def differentiate(equation, point):\n #This can almost certainly be done waaaaay better with regex ...\n \n #Where are all the signs between terms?\n signs = [i for i in range(len(equation)) if equation[i] in \"+-\"]\n if not 0 in signs: signs = [0] + signs\n \n #Parse the coefficients and powers (all assumed integers)\n coeffs = []\n powers = []\n for i in range(len(signs)):\n if i+1 == len(signs):\n term = equation[signs[i]:]\n else:\n term = equation[signs[i]:signs[i+1]]\n if \"^\" in term:\n i = term.index(\"^\")\n powers += [int(term.split(\"^\")[1])]\n elif \"x\" in term:\n powers += [1]\n if \"x\" in term:\n c = term.split(\"x\")[0]\n if c in [\"\",\"+\",\"-\"]:\n coeffs += [-1 if c == \"-\" else 1]\n else:\n coeffs += [int(c)]\n return sum([c*p*point**(p-1) for c,p in zip(coeffs,powers)])\n", "import re\n\ndef differentiate(equation, point):\n d = {int(p or 1): int({'' : 1, '-' : -1}.get(n, n)) for n, x, p in re.findall('([-]?\\d*)(?:(x)(?:\\^(\\d+))?)?', equation) if x or p}\n return sum(t * p * point ** (p - 1) for p, t in d.items())", "def differentiate(equation, point):\n a = filter(lambda x:'x' in x,equation.replace('-','+-').split(\"+\"))\n sum = 0\n for i in list(a):\n split_i = i.split('x')\n split_i[0] = split_i[0] + '1' if split_i[0] == '' or split_i[0]=='-' else split_i[0]\n split_i[1] = '^1' if split_i[1] == '' else split_i[1]\n sum += int(split_i[0])*int(split_i[1][1:])*(point**(int(split_i[1][1:])-1))\n return sum", "def differentiate(eq, point):\n eq = eq.replace('-', ' -').strip()\n eq = eq.replace('+', ' +').strip()\n eq = eq.replace('-x', '-1x')\n eq = eq.replace('+x', '+1x')\n eq = eq.split(' ')\n\n eq = [i if i[0].isalpha() == False else \"1\"+i for i in eq]\n \n if \"x\" not in eq[-1]: eq.pop(-1)\n for i in range(len(eq)):\n if eq[i][-1] == \"x\":\n eq[i] = eq[i][:-1] + \"x^1\"\n j = int(eq[i][-1])\n eq[i] = int(eq[i][:-3]) * j * (point ** (j-1))\n\n return sum(eq)", "import re\n\ndef differentiate(equation, point):\n terms = re.findall(r'[-]*[0-9x^]+', equation)\n result = 0\n for term in terms:\n amount = re.search(r'^-*[0-9]+|^-*x', term)\n if amount is not None:\n amount = amount.group(0)\n if amount == 'x':\n amount = 1\n elif amount == \"-x\":\n amount = -1\n else:\n int(amount)\n power = re.search(r'(?<=\\^)\\d+$|x+$', term)\n if power is not None:\n power = power.group(0)\n if power.isnumeric():\n result = result + (int(power) * int(amount) * point**(int(power)-1))\n elif power == 'x':\n power = 1\n result = result + (int(amount) * power)\n return result", "from re import findall\n\ndef val(s):\n if not s: return 1\n if s[0] == '+': return int(s[1:] or '1')\n if s[0] == '-': return -int(s[1:] or '1')\n return int(s)\n\ndef differentiate(equation, point):\n res = 0\n for x in findall(\"[+-]?\\d*x(?:\\^\\d+)?\", equation):\n i = x.find('x')\n v, p = val(x[:i]), int(x[i+2:] or '1')\n res += v * p * point**(p-1)\n return res", "def differentiate(equation, point):\n\n if equation[0] != '-': equation = '+' + equation\n \n equation = equation.replace('+x', '+1x').replace('-x', '-1x').replace('+', ' ').replace('-', ' -')\n \n terms = [[int(e) for e in (w + '^1' if '^' not in w else w).split('x^')] for w in equation.split() if 'x' in w]\n \n return sum(c * p * point ** (p - 1) for c, p in terms)"]
{"fn_name": "differentiate", "inputs": [["12x+2", 3], ["x-66", 3], ["x^2-x", 3], ["-5x^2+10x+4", 3], ["x^2+3x+3", 3], ["1000x^2+300x+200", 531], ["21x^2+35x+3", 2071], ["66x^3+3x^2+3", 441], ["21x^4+3x^3", 414], ["-21x^5+3x^3", 12398], ["-x^2+3x-3", 1234567908], ["-7x^5+22x^4-55x^3-94x^2+87x-56", -3], ["-123x^5+3x", 8559], ["x^2", 59884848483559]], "outputs": [[12], [1], [5], [-20], [9], [1062300], [87017], [38509884], [5962009860], [-2480823269890144044], [-2469135813], [-6045], [-3300404885229567012], [119769696967118]]}
INTERVIEW
PYTHON3
CODEWARS
5,329
def differentiate(equation, point):
4ac245b90ad51d6f6327e17bb0f59a42
UNKNOWN
My little sister came back home from school with the following task: given a squared sheet of paper she has to cut it in pieces which, when assembled, give squares the sides of which form an increasing sequence of numbers. At the beginning it was lot of fun but little by little we were tired of seeing the pile of torn paper. So we decided to write a program that could help us and protects trees. ## Task Given a positive integral number n, return a **strictly increasing** sequence (list/array/string depending on the language) of numbers, so that the sum of the squares is equal to n². If there are multiple solutions (and there will be), return as far as possible the result with the largest possible values: ## Examples `decompose(11)` must return `[1,2,4,10]`. Note that there are actually two ways to decompose 11², 11² = 121 = 1 + 4 + 16 + 100 = 1² + 2² + 4² + 10² but don't return `[2,6,9]`, since 9 is smaller than 10. For `decompose(50)` don't return `[1, 1, 4, 9, 49]` but `[1, 3, 5, 8, 49]` since `[1, 1, 4, 9, 49]` doesn't form a strictly increasing sequence. ## Note Neither `[n]` nor `[1,1,1,…,1]` are valid solutions. If no valid solution exists, return `nil`, `null`, `Nothing`, `None` (depending on the language) or `"[]"` (C) ,`{}` (C++), `[]` (Swift, Go). The function "decompose" will take a positive integer n and return the decomposition of N = n² as: - [x1 ... xk] or - "x1 ... xk" or - Just [x1 ... xk] or - Some [x1 ... xk] or - {x1 ... xk} or - "[x1,x2, ... ,xk]" depending on the language (see "Sample tests") # Note for Bash ``` decompose 50 returns "1,3,5,8,49" decompose 4 returns "Nothing" ``` # Hint Very often `xk` will be `n-1`.
["def decompose(n):\n total = 0\n answer = [n]\n while len(answer):\n temp = answer.pop()\n total += temp ** 2\n for i in range(temp - 1, 0, -1):\n if total - (i ** 2) >= 0:\n total -= i ** 2\n answer.append(i)\n if total == 0:\n return sorted(answer)\n return None", "def decompose(n, a=None):\n if a == None: a = n*n\n if a == 0: return []\n for m in range(min(n-1, int(a ** .5)), 0, -1):\n sub = decompose(m, a - m*m)\n if sub != None: return sub + [m]", "import math\ndef decompose(n):\n if n <= 4: return None\n result = [n - 1]\n remain = n ** 2 - (n - 1) ** 2\n while True:\n if not remain: return list(reversed(result))\n if result[0] == 1: return None\n if result[-1] == 1:\n remain += result.pop() ** 2\n result[-1] -= 1\n remain += (result[-1] + 1) ** 2 - result[-1] ** 2\n else:\n i = min(result[-1] - 1, int(math.floor(math.sqrt(remain))))\n result.append(i)\n remain -= i ** 2", "import math\ndef decompose(n):\n value = n-1\n remains = n**2\n cache = {value : remains}\n remains -= value**2\n \n while remains:\n value = int(math.sqrt(remains))\n if value < min(cache.keys()):\n cache[value] = remains\n remains -= value**2\n else:\n del cache[min(cache.keys())]\n if not cache: return None\n value = min(cache.keys())\n remains = cache.pop(value)\n cache[value-1] = remains\n remains -= (value-1)**2\n return sorted(cache.keys())", "import math\n\ndef decompose_aux(nb, rac):\n if (nb == 0):\n return [] \n i = rac\n l = None\n while (i >= int(math.sqrt(nb / 2.0)) + 1):\n diff = nb - i * i\n rac = int(math.sqrt(diff))\n l = decompose_aux(diff, rac);\n if l != None: \n l.append(i)\n return l\n i -= 1\n return l\n \ndef decompose(n):\n l = decompose_aux(n * n, int(math.sqrt(n * n - 1)))\n if l != None:\n return l \n else:\n return None", "def decompose(n):\n # your code\n def fun(s,i):\n if s<0:return None\n if s==0:return []\n for j in range(i-1,0,-1):\n some = fun(s-j**2,j)\n if some!=None:\n return some+[j]\n\n return fun(n**2,n)", "def dec(r, d):\n for i in range(d-1, 0, -1):\n if r < i * i:\n continue\n if r == i * i:\n return [i]\n a = dec(r - i * i, i)\n if a:\n return a + [i]\n return None\ndef decompose(n):\n return dec(n * n, n)", "def decompose(n):\n return decompose_helper(n ** 2, n - 1)\n\n\ndef decompose_helper(n, end):\n for i in range(end, 0, -1):\n if i ** 2 == n:\n return [i]\n\n new = n - i ** 2\n d = decompose_helper(new, min(i - 1, int(new ** 0.5)))\n if d:\n return d + [i]\n"]
{"fn_name": "decompose", "inputs": [[12], [6], [50], [44], [625], [5], [7100], [123456], [1234567], [7654321], [4], [7654322]], "outputs": [[[1, 2, 3, 7, 9]], [null], [[1, 3, 5, 8, 49]], [[2, 3, 5, 7, 43]], [[2, 5, 8, 34, 624]], [[3, 4]], [[2, 3, 5, 119, 7099]], [[1, 2, 7, 29, 496, 123455]], [[2, 8, 32, 1571, 1234566]], [[6, 10, 69, 3912, 7654320]], [null], [[1, 4, 11, 69, 3912, 7654321]]]}
INTERVIEW
PYTHON3
CODEWARS
3,077
def decompose(n):
84296b28b079466eab2ba5c8b026b510
UNKNOWN
This kata generalizes [Twice Linear](https://www.codewars.com/kata/5672682212c8ecf83e000050). You may want to attempt that kata first. ## Sequence Consider an integer sequence `U(m)` defined as: 1. `m` is a given non-empty set of positive integers. 2. `U(m)[0] = 1`, the first number is always 1. 3. For each `x` in `U(m)`, and each `y` in `m`, `x * y + 1` must also be in `U(m)`. 4. No other numbers are in `U(m)`. 5. `U(m)` is sorted, with no duplicates. ### Sequence Examples #### `U(2, 3) = [1, 3, 4, 7, 9, 10, 13, 15, 19, 21, 22, 27, ...]` 1 produces 3 and 4, since `1 * 2 + 1 = 3`, and `1 * 3 + 1 = 4`. 3 produces 7 and 10, since `3 * 2 + 1 = 7`, and `3 * 3 + 1 = 10`. #### `U(5, 7, 8) = [1, 6, 8, 9, 31, 41, 43, 46, 49, 57, 64, 65, 73, 156, 206, ...]` 1 produces 6, 8, and 9. 6 produces 31, 43, and 49. ## Task: Implement `n_linear` or `nLinear`: given a set of postive integers `m`, and an index `n`, find `U(m)[n]`, the `n`th value in the `U(m)` sequence. ### Tips * Tests use large n values. Slow algorithms may time-out. * Tests use large values in the m set. Algorithms which multiply further than neccessary may overflow. * Linear run time and memory usage is possible. * How can you build the sequence iteratively, without growing extra data structures?
["from heapq import *\n\ndef n_linear(ms, n):\n lst = [1] * (n+1)\n q = [(1+v,v,1) for v in ms]\n heapify(q)\n for i in range(1,n+1):\n v,x,j = heappop(q)\n lst[i] = v\n heappush(q, (lst[j]*x+1, x, j+1) )\n while q[0][0]==lst[i]:\n v,x,j = heappop(q)\n heappush(q, (lst[j]*x+1, x, j+1) )\n return lst[n]", "from heapq import heappush, heappop\n\ndef n_linear(m, n):\n h = [1]\n x = 0\n for _ in range(n+1):\n x = heappop(h)\n while h and h[0] == x:\n heappop(h)\n for y in m:\n a = y * x + 1\n heappush(h, a)\n return x", "from collections import deque\nfrom heapq import heappush, heappop\n\n\ndef n_linear(m, n):\n y, h, q = 1, [], {}\n for x in m:\n h.append((y, x))\n q[x] = deque([x * y + 1])\n while n:\n z, w = heappop(h)\n if y != z:\n y = z\n for x in m: q[x].append(x * y + 1)\n n -= 1\n heappush(h, (q[w].popleft(), w))\n return y\n", "from heapq import *\n\ndef n_linear(m,n):\n k = [1]\n queue = []\n while len(k) <= n:\n for x in m:\n heappush(queue, x*k[-1]+1)\n k.append(heappop(queue))\n\n while queue[0] == k[-1]:\n heappop(queue)\n \n return k[-1]", "from heapq import *\n\ndef n_linear(ms, n):\n lst = [1] * (n+1)\n q = [(1+v,v,1) for v in ms]\n heapify(q)\n for i in range(1,n+1):\n v,x,j = heappop(q)\n lst[i] = v\n heappush(q, (lst[j]*x+1, x, j+1) )\n while q[0][0]==lst[i]:\n v,x,j = heappop(q)\n heappush(q, (lst[j]*x+1, x, j+1) )\n print(ms,n)\n return lst[n]", "def n_linear(m, n): \n indxs = {i:0 for i in m}\n u = [1]\n \n while len(u) <= n:\n tmp = [ [k*u[v] + 1, k] for k, v in indxs.items()]\n nxt = min(tmp, key = lambda x: x[0])\n u.append(nxt[0]) \n for i in tmp:\n if i[0] == nxt[0]:\n indxs[i[1]] += 1\n return u[n]", "def n_linear(m,n):\n arr = [1]\n ms = list(m)\n idxs = [0] * len(ms)\n r = range(len(ms))\n \n for i in range(n):\n vals = [arr[idxs[j]]*ms[j]+1 for j in r]\n val = min(vals)\n arr.append(val)\n \n for j in r:\n idxs[j] += 1*(val==vals[j])\n \n return arr[n]", "def n_linear(m,n):\n arr = [1]\n indices = [0] * len(m)\n r = range(len(m))\n count = 0\n while count < n:\n x = min([arr[indices[i]] * m[i] for i in r])\n for i in r:\n if x == arr[indices[i]] * m[i]:\n indices[i] += 1\n arr.append(x + 1)\n count += 1\n \n return arr[-1]", "import heapq\n\ndef n_linear_generator(m):\n u = [1]\n s = set(u)\n\n while True:\n x = heapq.heappop(u)\n yield x\n s.remove(x)\n\n for y in m:\n z = x * y + 1\n if z not in s:\n heapq.heappush(u, z)\n s.add(z)\n\nmemos = {}\n\ndef n_linear(m, n):\n m = tuple(m)\n if m not in memos:\n memos[m] = ([], n_linear_generator(m))\n \n past, gen = memos[m]\n past.extend(next(gen) for _ in range(len(past), n + 1))\n return past[n]", "def n_linear(m,n):\n if n==0: return 1\n init,dicto=[1],{}.fromkeys(m,0)\n for i in range(n):\n dd = min(k*init[dicto[k]]+1 for k in dicto)\n init.append(dd)\n for k in dicto:\n dicto[k] += init[dicto[k]]*k+1==dd\n return dd"]
{"fn_name": "n_linear", "inputs": [[[2, 3], 0], [[3, 2, 5], 0], [[2, 3], 1], [[2, 3], 2], [[2, 3], 3], [[2, 3], 4], [[2, 3], 5], [[2, 3], 6], [[2, 3], 7], [[2, 3], 8], [[2, 3], 9], [[2, 3], 10], [[2, 3], 11], [[2, 3], 12], [[2, 3], 13], [[2, 3], 14], [[2, 3], 15], [[2, 3], 16], [[2, 3], 17], [[2, 3], 18], [[2, 3], 19], [[2, 3], 20], [[2, 3], 30], [[2, 3], 50], [[2, 3], 97], [[2, 3], 100], [[2, 3], 144], [[2, 3], 200], [[2, 3], 951], [[2, 3], 1000], [[5, 7, 8], 10], [[5, 7, 8], 11], [[2, 3, 4, 5], 33], [[2, 3, 4, 5], 100], [[3, 5, 7, 9, 11], 50], [[3, 5, 7, 9, 11], 70], [[3, 5, 7, 9, 11], 90], [[3, 2], 10], [[3, 2], 234], [[3, 2], 923], [[3, 2], 445], [[1, 3], 999], [[1, 5], 1000], [[5, 12], 519], [[14, 10], 56], [[2, 6], 416], [[10, 13], 741], [[3, 5], 351], [[5, 9], 246], [[8, 13], 864], [[6, 5], 779], [[8, 7], 738], [[12, 2], 752], [[8, 4, 2], 386], [[5, 11, 7], 475], [[3, 8, 5], 190], [[2, 5, 6], 415], [[4, 2, 5], 315], [[4, 8, 7], 354], [[13, 9, 2], 377], [[14, 12, 8], 297], [[12, 14, 2], 181], [[12, 4, 7], 370], [[4, 9, 6, 7, 19, 17, 10, 13], 835], [[10, 5, 9, 17, 6, 12], 71], [[14, 4, 9, 16, 3], 239], [[8, 11, 14, 7, 5, 9, 3, 17], 809], [[11, 15, 19, 5, 14, 12], 210], [[10, 4, 14, 11, 3], 639], [[7, 12, 19, 2, 15, 9, 4], 634], [[9, 19, 7, 12, 16, 18], 273], [[16, 5, 18, 13, 11, 8, 14, 4], 891], [[9, 2, 3, 10, 11, 4, 6, 18], 503], [[2, 3, 6, 17, 13, 5], 570], [[12, 13, 5, 4], 136], [[8, 4, 7, 2, 18, 17], 46], [[13, 12, 19, 3], 784], [[17, 14, 9, 16, 11, 8, 13, 19, 7], 185], [[18, 12, 16, 15, 10, 17, 6, 8, 7], 534], [[3, 18, 10, 9, 19, 6, 7, 17, 4], 195], [[18, 12, 5, 11], 136], [[12, 9, 4, 18, 13, 19], 566], [[12, 2, 6, 5, 4], 243], [[2, 3], 200000], [[2, 3, 5], 300000], [[2, 3, 10000002], 200000], [[2, 3, 5, 10000000], 200000]], "outputs": [[1], [1], [3], [4], [7], [9], [10], [13], [15], [19], [21], [22], [27], [28], [31], [39], [40], [43], [45], [46], [55], [57], [91], [175], [406], [447], [706], [1051], [8013], [8488], [64], [65], [46], [139], [154], [226], [316], [22], [1339], [7537], [2983], [1000], [1001], [32961973], [304795], [37339], [3172655773], [58596], [1553901], [1727528929], [5833116], [80282057], [349957], [1359], [79399], [2346], [2733], [987], [16724], [7127], [246387], [4789], [35965], [3071], [427], [1387], [1941], [3095], [3364], [1156], [6175], [3401], [724], [1006], [1631], [79], [62321], [1090], [2601], [361], [6049], [8949], [527], [7202134], [1092439], [7202134], [719671]]}
INTERVIEW
PYTHON3
CODEWARS
3,585
def n_linear(m,n):