[{"source":"apps","task_type":"verifiable_code","in_source_id":"1","prompt":"Solve the following coding problem using the programming language python:\n\nMikhail walks on a Cartesian plane. He starts at the point $(0, 0)$, and in one move he can go to any of eight adjacent points. For example, if Mikhail is currently at the point $(0, 0)$, he can go to any of the following points in one move: $(1, 0)$; $(1, 1)$; $(0, 1)$; $(-1, 1)$; $(-1, 0)$; $(-1, -1)$; $(0, -1)$; $(1, -1)$. \n\nIf Mikhail goes from the point $(x1, y1)$ to the point $(x2, y2)$ in one move, and $x1 \\ne x2$ and $y1 \\ne y2$, then such a move is called a diagonal move.\n\nMikhail has $q$ queries. For the $i$-th query Mikhail's target is to go to the point $(n_i, m_i)$ from the point $(0, 0)$ in exactly $k_i$ moves. Among all possible movements he want to choose one with the maximum number of diagonal moves. Your task is to find the maximum number of diagonal moves or find that it is impossible to go from the point $(0, 0)$ to the point $(n_i, m_i)$ in $k_i$ moves.\n\nNote that Mikhail can visit any point any number of times (even the destination point!).\n\n\n-----Input-----\n\nThe first line of the input contains one integer $q$ ($1 \\le q \\le 10^4$) \u2014 the number of queries.\n\nThen $q$ lines follow. The $i$-th of these $q$ lines contains three integers $n_i$, $m_i$ and $k_i$ ($1 \\le n_i, m_i, k_i \\le 10^{18}$) \u2014 $x$-coordinate of the destination point of the query, $y$-coordinate of the destination point of the query and the number of moves in the query, correspondingly.\n\n\n-----Output-----\n\nPrint $q$ integers. The $i$-th integer should be equal to -1 if Mikhail cannot go from the point $(0, 0)$ to the point $(n_i, m_i)$ in exactly $k_i$ moves described above. Otherwise the $i$-th integer should be equal to the the maximum number of diagonal moves among all possible movements.\n\n\n-----Example-----\nInput\n3\n2 2 3\n4 3 7\n10 1 9\n\nOutput\n1\n6\n-1\n\n\n\n-----Note-----\n\nOne of the possible answers to the first test case: $(0, 0) \\to (1, 0) \\to (1, 1) \\to (2, 2)$.\n\nOne of the possible answers to the second test case: $(0, 0) \\to (0, 1) \\to (1, 2) \\to (0, 3) \\to (1, 4) \\to (2, 3) \\to (3, 2) \\to (4, 3)$.\n\nIn the third test case Mikhail cannot reach the point $(10, 1)$ in 9 moves.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nq=int(input())\n\nfor e in range(q):\n x,y,k=list(map(int,input().split()))\n x,y=abs(x),abs(y)\n x,y=max(x,y),min(x,y)\n \n if(x%2!=k%2):\n k-=1\n y-=1\n \n \n if(x>k):\n print(-1)\n continue\n if((x-y)%2):\n k-=1\n x-=1\n print(k)\n \n \n \n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\n2 2 3\\n4 3 7\\n10 1 9\\n', 'output': '1\\n6\\n-1\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/1036/B'}","problem_id":"vfc_4","program":"```python\nq=int(input())\n\nfor e in range(q):\n x,y,k=list(map(int,input().split()))\n x,y=abs(x),abs(y)\n x,y=max(x,y),min(x,y)\n \n if(x%2!=k%2):\n k-=1\n y-=1\n \n \n if(x>k):\n print(-1)\n continue\n if((x-y)%2):\n k-=1\n x-=1\n print(k)\n \n \n \n\n```","inputs":"3\n2 2 3\n4 3 7\n10 1 9\n","output":"1\n6\n-1\n","actual_output":"1\n6\n-1\n","execution_success":true,"sample_index":2},{"source":"apps","task_type":"verifiable_code","in_source_id":"2","prompt":"Solve the following coding problem using the programming language python:\n\nYou are given three sequences: $a_1, a_2, \\ldots, a_n$; $b_1, b_2, \\ldots, b_n$; $c_1, c_2, \\ldots, c_n$.\n\nFor each $i$, $a_i \\neq b_i$, $a_i \\neq c_i$, $b_i \\neq c_i$.\n\nFind a sequence $p_1, p_2, \\ldots, p_n$, that satisfy the following conditions:\n\n\n\n $p_i \\in \\{a_i, b_i, c_i\\}$\n\n $p_i \\neq p_{(i \\mod n) + 1}$.\n\nIn other words, for each element, you need to choose one of the three possible values, such that no two adjacent elements (where we consider elements $i,i+1$ adjacent for $imaxx):\n maxx = new_ar[j][1]\n if(new_ar[j][1]maxx):\n maxx = new_ar[j][1]\n if(new_ar[j][1] 1:\n j = i // 2\n if self.l[ j ] > self.l[ i ]:\n self.l[ j ], self.l[ i ] = self.l[ i ], self.l[ j ]\n i = j\n else:\n break\n def pop( self ):\n r = self.l[ 1 ]\n l = self.l.pop()\n n = len( self.l ) - 1\n if n:\n self.l[ 1 ] = l\n i = 1\n while True:\n j = i * 2\n k = j + 1\n if k < len( self.l ) and self.l[ i ] > max( self.l[ j ], self.l[ k ] ):\n if self.l[ j ] == min( self.l[ j ], self.l[ k ] ):\n self.l[ i ], self.l[ j ] = self.l[ j ], self.l[ i ]\n i = j\n else:\n self.l[ i ], self.l[ k ] = self.l[ k ], self.l[ i ]\n i = k\n elif k < len( self.l ) and self.l[ i ] > self.l[ k ]:\n self.l[ i ], self.l[ k ] = self.l[ k ], self.l[ i ]\n i = k\n elif j < len( self.l ) and self.l[ i ] > self.l[ j ]:\n self.l[ i ], self.l[ j ] = self.l[ j ], self.l[ i ]\n i = j\n else:\n break\n return r\n\nt = int( I() )\nfor _ in range( t ):\n n = int( I() )\n voter = [ list( map( int, I().split() ) ) for _ in range( n ) ]\n h = Heap()\n d = {}\n for m, p in voter:\n if m not in d:\n d[ m ] = []\n d[ m ].append( p )\n need = {}\n c = 0\n sk = sorted( d.keys() )\n for m in sk:\n need[ m ] = max( 0, m - c )\n c += len( d[ m ] )\n c = 0\n ans = 0\n for m in sk[::-1]:\n for p in d[ m ]:\n h.ins( p )\n while c < need[ m ]:\n c += 1\n ans += h.pop()\n print( ans )\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\n3\\n1 5\\n2 10\\n2 8\\n7\\n0 1\\n3 1\\n1 1\\n6 1\\n1 1\\n4 1\\n4 1\\n6\\n2 6\\n2 3\\n2 8\\n2 7\\n4 4\\n5 5\\n', 'output': '8\\n0\\n7\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/1251/E2'}","problem_id":"vfc_28","program":"```python\nimport sys\ndef I():\n return sys.stdin.readline().rstrip()\n\nclass Heap:\n def __init__( self ):\n self.l = [ -1 ]\n self.n = 0\n def n( self ):\n return self.n\n def top( self ):\n return self.l[ 1 ]\n def ins( self, x ):\n self.l.append( x )\n n = len( self.l ) - 1\n i = n\n while i > 1:\n j = i // 2\n if self.l[ j ] > self.l[ i ]:\n self.l[ j ], self.l[ i ] = self.l[ i ], self.l[ j ]\n i = j\n else:\n break\n def pop( self ):\n r = self.l[ 1 ]\n l = self.l.pop()\n n = len( self.l ) - 1\n if n:\n self.l[ 1 ] = l\n i = 1\n while True:\n j = i * 2\n k = j + 1\n if k < len( self.l ) and self.l[ i ] > max( self.l[ j ], self.l[ k ] ):\n if self.l[ j ] == min( self.l[ j ], self.l[ k ] ):\n self.l[ i ], self.l[ j ] = self.l[ j ], self.l[ i ]\n i = j\n else:\n self.l[ i ], self.l[ k ] = self.l[ k ], self.l[ i ]\n i = k\n elif k < len( self.l ) and self.l[ i ] > self.l[ k ]:\n self.l[ i ], self.l[ k ] = self.l[ k ], self.l[ i ]\n i = k\n elif j < len( self.l ) and self.l[ i ] > self.l[ j ]:\n self.l[ i ], self.l[ j ] = self.l[ j ], self.l[ i ]\n i = j\n else:\n break\n return r\n\nt = int( I() )\nfor _ in range( t ):\n n = int( I() )\n voter = [ list( map( int, I().split() ) ) for _ in range( n ) ]\n h = Heap()\n d = {}\n for m, p in voter:\n if m not in d:\n d[ m ] = []\n d[ m ].append( p )\n need = {}\n c = 0\n sk = sorted( d.keys() )\n for m in sk:\n need[ m ] = max( 0, m - c )\n c += len( d[ m ] )\n c = 0\n ans = 0\n for m in sk[::-1]:\n for p in d[ m ]:\n h.ins( p )\n while c < need[ m ]:\n c += 1\n ans += h.pop()\n print( ans )\n\n```","inputs":"3\n3\n1 5\n2 10\n2 8\n7\n0 1\n3 1\n1 1\n6 1\n1 1\n4 1\n4 1\n6\n2 6\n2 3\n2 8\n2 7\n4 4\n5 5\n","output":"8\n0\n7\n","actual_output":"8\n0\n7\n","execution_success":true,"sample_index":8},{"source":"apps","task_type":"verifiable_code","in_source_id":"8","prompt":"Solve the following coding problem using the programming language python:\n\nYou like playing chess tournaments online.\n\nIn your last tournament you played $n$ games. For the sake of this problem, each chess game is either won or lost (no draws). When you lose a game you get $0$ points. When you win you get $1$ or $2$ points: if you have won also the previous game you get $2$ points, otherwise you get $1$ point. If you win the very first game of the tournament you get $1$ point (since there is not a \"previous game\").\n\nThe outcomes of the $n$ games are represented by a string $s$ of length $n$: the $i$-th character of $s$ is W if you have won the $i$-th game, while it is L if you have lost the $i$-th game.\n\nAfter the tournament, you notice a bug on the website that allows you to change the outcome of at most $k$ of your games (meaning that at most $k$ times you can change some symbol L to W, or W to L). Since your only goal is to improve your chess rating, you decide to cheat and use the bug.\n\nCompute the maximum score you can get by cheating in the optimal way.\n\n\n-----Input-----\n\nEach test contains multiple test cases. The first line contains an integer $t$ ($1\\le t \\le 20,000$) \u2014 the number of test cases. The description of the test cases follows.\n\nThe first line of each testcase contains two integers $n, k$ ($1\\le n\\le 100,000$, $0\\le k\\le n$) \u2013 the number of games played and the number of outcomes that you can change.\n\nThe second line contains a string $s$ of length $n$ containing only the characters W and L. If you have won the $i$-th game then $s_i=\\,$W, if you have lost the $i$-th game then $s_i=\\,$L.\n\nIt is guaranteed that the sum of $n$ over all testcases does not exceed $200,000$.\n\n\n-----Output-----\n\nFor each testcase, print a single integer \u2013 the maximum score you can get by cheating in the optimal way.\n\n\n-----Example-----\nInput\n8\n5 2\nWLWLL\n6 5\nLLLWWL\n7 1\nLWLWLWL\n15 5\nWWWLLLWWWLLLWWW\n40 7\nLLWLWLWWWLWLLWLWWWLWLLWLLWLLLLWLLWWWLWWL\n1 0\nL\n1 1\nL\n6 1\nWLLWLW\n\nOutput\n7\n11\n6\n26\n46\n0\n1\n6\n\n\n\n-----Note-----\n\nExplanation of the first testcase. Before changing any outcome, the score is $2$. Indeed, you won the first game, so you got $1$ point, and you won also the third, so you got another $1$ point (and not $2$ because you lost the second game).\n\nAn optimal way to cheat is to change the outcomes of the second and fourth game. Doing so, you end up winning the first four games (the string of the outcomes becomes WWWWL). Hence, the new score is $7=1+2+2+2$: $1$ point for the first game and $2$ points for the second, third and fourth game.\n\nExplanation of the second testcase. Before changing any outcome, the score is $3$. Indeed, you won the fourth game, so you got $1$ point, and you won also the fifth game, so you got $2$ more points (since you won also the previous game).\n\nAn optimal way to cheat is to change the outcomes of the first, second, third and sixth game. Doing so, you end up winning all games (the string of the outcomes becomes WWWWWW). Hence, the new score is $11 = 1+2+2+2+2+2$: $1$ point for the first game and $2$ points for all the other games.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nimport sys\ninput = sys.stdin.readline\n\ndef main():\n n, k = map(int, input().split())\n string = input().strip()\n if \"W\" not in string:\n ans = min(n, k) * 2 - 1\n print(max(ans, 0))\n return\n \n L_s = []\n cnt = 0\n bef = string[0]\n ans = 0\n for s in string:\n if s == bef:\n cnt += 1\n else:\n if bef == \"L\":\n L_s.append(cnt)\n else:\n ans += cnt * 2 - 1\n cnt = 1\n bef = s\n if bef == \"W\":\n ans += cnt * 2 - 1\n cnt = 0\n \n if string[0] == \"L\" and L_s:\n cnt += L_s[0]\n L_s = L_s[1:]\n L_s.sort()\n for l in L_s:\n if k >= l:\n ans += l * 2 + 1\n k -= l\n else:\n ans += k * 2\n k = 0\n \n ans += 2 * min(k, cnt)\n print(ans)\n \n \n \nfor _ in range(int(input())):\n main()\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '8\\n5 2\\nWLWLL\\n6 5\\nLLLWWL\\n7 1\\nLWLWLWL\\n15 5\\nWWWLLLWWWLLLWWW\\n40 7\\nLLWLWLWWWLWLLWLWWWLWLLWLLWLLLLWLLWWWLWWL\\n1 0\\nL\\n1 1\\nL\\n6 1\\nWLLWLW\\n', 'output': '7\\n11\\n6\\n26\\n46\\n0\\n1\\n6\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/1427/B'}","problem_id":"vfc_32","program":"```python\nimport sys\ninput = sys.stdin.readline\n\ndef main():\n n, k = map(int, input().split())\n string = input().strip()\n if \"W\" not in string:\n ans = min(n, k) * 2 - 1\n print(max(ans, 0))\n return\n \n L_s = []\n cnt = 0\n bef = string[0]\n ans = 0\n for s in string:\n if s == bef:\n cnt += 1\n else:\n if bef == \"L\":\n L_s.append(cnt)\n else:\n ans += cnt * 2 - 1\n cnt = 1\n bef = s\n if bef == \"W\":\n ans += cnt * 2 - 1\n cnt = 0\n \n if string[0] == \"L\" and L_s:\n cnt += L_s[0]\n L_s = L_s[1:]\n L_s.sort()\n for l in L_s:\n if k >= l:\n ans += l * 2 + 1\n k -= l\n else:\n ans += k * 2\n k = 0\n \n ans += 2 * min(k, cnt)\n print(ans)\n \n \n \nfor _ in range(int(input())):\n main()\n```","inputs":"8\n5 2\nWLWLL\n6 5\nLLLWWL\n7 1\nLWLWLWL\n15 5\nWWWLLLWWWLLLWWW\n40 7\nLLWLWLWWWLWLLWLWWWLWLLWLLWLLLLWLLWWWLWWL\n1 0\nL\n1 1\nL\n6 1\nWLLWLW\n","output":"7\n11\n6\n26\n46\n0\n1\n6\n","actual_output":"7\n11\n6\n26\n46\n0\n1\n6\n","execution_success":true,"sample_index":9},{"source":"apps","task_type":"verifiable_code","in_source_id":"9","prompt":"Solve the following coding problem using the programming language python:\n\nAlice and Bob play a game. They have a binary string $s$ (a string such that each character in it is either $0$ or $1$). Alice moves first, then Bob, then Alice again, and so on.\n\nDuring their move, the player can choose any number (not less than one) of consecutive equal characters in $s$ and delete them.\n\nFor example, if the string is $10110$, there are $6$ possible moves (deleted characters are bold): $\\textbf{1}0110 \\to 0110$; $1\\textbf{0}110 \\to 1110$; $10\\textbf{1}10 \\to 1010$; $101\\textbf{1}0 \\to 1010$; $10\\textbf{11}0 \\to 100$; $1011\\textbf{0} \\to 1011$. \n\nAfter the characters are removed, the characters to the left and to the right of the removed block become adjacent. I. e. the following sequence of moves is valid: $10\\textbf{11}0 \\to 1\\textbf{00} \\to 1$.\n\nThe game ends when the string becomes empty, and the score of each player is the number of $1$-characters deleted by them.\n\nEach player wants to maximize their score. Calculate the resulting score of Alice.\n\n\n-----Input-----\n\nThe first line contains one integer $T$ ($1 \\le T \\le 500$) \u2014 the number of test cases.\n\nEach test case contains exactly one line containing a binary string $s$ ($1 \\le |s| \\le 100$).\n\n\n-----Output-----\n\nFor each test case, print one integer \u2014 the resulting score of Alice (the number of $1$-characters deleted by her).\n\n\n-----Example-----\nInput\n5\n01111001\n0000\n111111\n101010101\n011011110111\n\nOutput\n4\n0\n6\n3\n6\n\n\n\n-----Note-----\n\nQuestions about the optimal strategy will be ignored.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfor _ in range(int(input())):\n s = input()\n p = [i for i in s.split(\"0\") if i!=\"\"]\n p.sort(reverse=True)\n ans = 0\n for i in range(0,len(p),2):\n ans+=len(p[i])\n print(ans)\n\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '5\\n01111001\\n0000\\n111111\\n101010101\\n011011110111\\n', 'output': '4\\n0\\n6\\n3\\n6\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/1398/B'}","problem_id":"vfc_36","program":"```python\nfor _ in range(int(input())):\n s = input()\n p = [i for i in s.split(\"0\") if i!=\"\"]\n p.sort(reverse=True)\n ans = 0\n for i in range(0,len(p),2):\n ans+=len(p[i])\n print(ans)\n\n\n```","inputs":"5\n01111001\n0000\n111111\n101010101\n011011110111\n","output":"4\n0\n6\n3\n6\n","actual_output":"4\n0\n6\n3\n6\n","execution_success":true,"sample_index":10},{"source":"apps","task_type":"verifiable_code","in_source_id":"11","prompt":"Solve the following coding problem using the programming language python:\n\nYou have a string $s$ \u2014 a sequence of commands for your toy robot. The robot is placed in some cell of a rectangular grid. He can perform four commands: 'W' \u2014 move one cell up; 'S' \u2014 move one cell down; 'A' \u2014 move one cell left; 'D' \u2014 move one cell right. \n\nLet $Grid(s)$ be the grid of minimum possible area such that there is a position in the grid where you can place the robot in such a way that it will not fall from the grid while running the sequence of commands $s$. For example, if $s = \\text{DSAWWAW}$ then $Grid(s)$ is the $4 \\times 3$ grid: you can place the robot in the cell $(3, 2)$; the robot performs the command 'D' and moves to $(3, 3)$; the robot performs the command 'S' and moves to $(4, 3)$; the robot performs the command 'A' and moves to $(4, 2)$; the robot performs the command 'W' and moves to $(3, 2)$; the robot performs the command 'W' and moves to $(2, 2)$; the robot performs the command 'A' and moves to $(2, 1)$; the robot performs the command 'W' and moves to $(1, 1)$. [Image] \n\nYou have $4$ extra letters: one 'W', one 'A', one 'S', one 'D'. You'd like to insert at most one of these letters in any position of sequence $s$ to minimize the area of $Grid(s)$.\n\nWhat is the minimum area of $Grid(s)$ you can achieve?\n\n\n-----Input-----\n\nThe first line contains one integer $T$ ($1 \\le T \\le 1000$) \u2014 the number of queries.\n\nNext $T$ lines contain queries: one per line. This line contains single string $s$ ($1 \\le |s| \\le 2 \\cdot 10^5$, $s_i \\in \\{\\text{W}, \\text{A}, \\text{S}, \\text{D}\\}$) \u2014 the sequence of commands.\n\nIt's guaranteed that the total length of $s$ over all queries doesn't exceed $2 \\cdot 10^5$.\n\n\n-----Output-----\n\nPrint $T$ integers: one per query. For each query print the minimum area of $Grid(s)$ you can achieve.\n\n\n-----Example-----\nInput\n3\nDSAWWAW\nD\nWA\n\nOutput\n8\n2\n4\n\n\n\n-----Note-----\n\nIn the first query you have to get string $\\text{DSAWW}\\underline{D}\\text{AW}$.\n\nIn second and third queries you can not decrease the area of $Grid(s)$.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nn = int(input())\n\ndef area(width, height) :\n return (width+1) * (height+1)\n\ndef calcul(s1, c, s2) :\n maxx, maxy, minx, miny = 0, 0, 0, 0\n x, y = 0, 0\n for k in range(len(s1)) :\n if s1[k] == \"W\" :\n y += 1\n if s1[k] == \"S\" :\n y -= 1\n if s1[k] == \"A\" :\n x -= 1\n if s1[k] == \"D\" :\n x += 1\n maxx = max(maxx, x)\n minx = min(minx, x)\n\n maxy = max(maxy, y)\n miny = min(miny, y)\n\n\n\n\n if c == \"W\" :\n y += 1\n elif c == \"S\" :\n y -= 1\n elif c == \"A\" :\n x -= 1\n elif c == \"D\" :\n x += 1\n else :\n print(c, \"ok\")\n\n maxx = max(maxx, x)\n minx = min(minx, x)\n\n maxy = max(maxy, y)\n miny = min(miny, y)\n\n for k in range(len(s2)) :\n if s2[k] == \"W\" :\n y += 1\n if s2[k] == \"S\" :\n y -= 1\n if s2[k] == \"A\" :\n x -= 1\n if s2[k] == \"D\" :\n x += 1\n maxx = max(maxx, x)\n minx = min(minx, x)\n\n maxy = max(maxy, y)\n miny = min(miny, y)\n\n\n\n diffx = maxx - minx\n diffy = maxy - miny\n tmp = area(diffx, diffy)\n\n\n return tmp\n\ndef pre_calcul(s, moment, pre_avant, date_debut) :\n x, y, maxx, minx, maxy, miny = pre_avant\n for k in range(date_debut, moment) :\n if s[k] == \"W\" :\n y += 1\n if s[k] == \"S\" :\n y -= 1\n if s[k] == \"A\" :\n x -= 1\n if s[k] == \"D\" :\n x += 1\n maxx = max(maxx, x)\n minx = min(minx, x)\n\n maxy = max(maxy, y)\n miny = min(miny, y)\n\n return (x, y, maxx, minx, maxy, miny)\n\ndef calcul2(s, c, moment, precalcul) :\n x, y, maxx, minx, maxy, miny = precalcul\n\n\n\n if c == \"W\" :\n y += 1\n elif c == \"S\" :\n y -= 1\n elif c == \"A\" :\n x -= 1\n elif c == \"D\" :\n x += 1\n else :\n print(c, \"ok\")\n\n maxx = max(maxx, x)\n minx = min(minx, x)\n\n maxy = max(maxy, y)\n miny = min(miny, y)\n\n for k in range(moment, len(s)) :\n if s[k] == \"W\" :\n y += 1\n if s[k] == \"S\" :\n y -= 1\n if s[k] == \"A\" :\n x -= 1\n if s[k] == \"D\" :\n x += 1\n maxx = max(maxx, x)\n minx = min(minx, x)\n\n maxy = max(maxy, y)\n miny = min(miny, y)\n\n\n\n diffx = maxx - minx\n diffy = maxy - miny\n tmp = area(diffx, diffy)\n\n\n return tmp\n\nfor _ in range(n) :\n s = input()\n maxx, maxy, minx, miny = 0, 0, 0, 0\n x, y = 0, 0\n momentminx, momentmaxx, momentminy, momentmaxy = -1, -1, -1, -1\n for k in range(len(s)) :\n if s[k] == \"W\" :\n y += 1\n if s[k] == \"S\" :\n y -= 1\n if s[k] == \"A\" :\n x -= 1\n if s[k] == \"D\" :\n x += 1\n\n if x > maxx :\n momentmaxx = k\n if y > maxy :\n momentmaxy = k\n if x < minx :\n momentminx = k\n if y < miny :\n momentminy = k\n maxx = max(maxx, x)\n minx = min(minx, x)\n\n maxy = max(maxy, y)\n miny = min(miny, y)\n diffx = maxx - minx\n diffy = maxy - miny\n\n\n tmp = 999999999999999999999999999999999999\n l = [momentmaxx, momentmaxy, momentminx, momentminy]\n l = list(set(l))\n l = [i for i in l if i != -1]\n l.sort()\n if l != [] :\n precalcul = pre_calcul(s, l[0], (0, 0, 0, 0, 0, 0), 0)\n avant = l[0]\n for moment in l :\n precalcul = pre_calcul(s, moment, precalcul, avant)\n avant = moment\n tmp = min(tmp, calcul2(s, 'W', moment, precalcul))\n tmp = min(tmp, calcul2(s, 'S', moment, precalcul))\n tmp = min(tmp, calcul2(s, 'A', moment, precalcul))\n tmp = min(tmp, calcul2(s, 'D', moment, precalcul))\n print(tmp)\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\nDSAWWAW\\nD\\nWA\\n', 'output': '8\\n2\\n4\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/1202/C'}","problem_id":"vfc_44","program":"```python\nn = int(input())\n\ndef area(width, height) :\n return (width+1) * (height+1)\n\ndef calcul(s1, c, s2) :\n maxx, maxy, minx, miny = 0, 0, 0, 0\n x, y = 0, 0\n for k in range(len(s1)) :\n if s1[k] == \"W\" :\n y += 1\n if s1[k] == \"S\" :\n y -= 1\n if s1[k] == \"A\" :\n x -= 1\n if s1[k] == \"D\" :\n x += 1\n maxx = max(maxx, x)\n minx = min(minx, x)\n\n maxy = max(maxy, y)\n miny = min(miny, y)\n\n\n\n\n if c == \"W\" :\n y += 1\n elif c == \"S\" :\n y -= 1\n elif c == \"A\" :\n x -= 1\n elif c == \"D\" :\n x += 1\n else :\n print(c, \"ok\")\n\n maxx = max(maxx, x)\n minx = min(minx, x)\n\n maxy = max(maxy, y)\n miny = min(miny, y)\n\n for k in range(len(s2)) :\n if s2[k] == \"W\" :\n y += 1\n if s2[k] == \"S\" :\n y -= 1\n if s2[k] == \"A\" :\n x -= 1\n if s2[k] == \"D\" :\n x += 1\n maxx = max(maxx, x)\n minx = min(minx, x)\n\n maxy = max(maxy, y)\n miny = min(miny, y)\n\n\n\n diffx = maxx - minx\n diffy = maxy - miny\n tmp = area(diffx, diffy)\n\n\n return tmp\n\ndef pre_calcul(s, moment, pre_avant, date_debut) :\n x, y, maxx, minx, maxy, miny = pre_avant\n for k in range(date_debut, moment) :\n if s[k] == \"W\" :\n y += 1\n if s[k] == \"S\" :\n y -= 1\n if s[k] == \"A\" :\n x -= 1\n if s[k] == \"D\" :\n x += 1\n maxx = max(maxx, x)\n minx = min(minx, x)\n\n maxy = max(maxy, y)\n miny = min(miny, y)\n\n return (x, y, maxx, minx, maxy, miny)\n\ndef calcul2(s, c, moment, precalcul) :\n x, y, maxx, minx, maxy, miny = precalcul\n\n\n\n if c == \"W\" :\n y += 1\n elif c == \"S\" :\n y -= 1\n elif c == \"A\" :\n x -= 1\n elif c == \"D\" :\n x += 1\n else :\n print(c, \"ok\")\n\n maxx = max(maxx, x)\n minx = min(minx, x)\n\n maxy = max(maxy, y)\n miny = min(miny, y)\n\n for k in range(moment, len(s)) :\n if s[k] == \"W\" :\n y += 1\n if s[k] == \"S\" :\n y -= 1\n if s[k] == \"A\" :\n x -= 1\n if s[k] == \"D\" :\n x += 1\n maxx = max(maxx, x)\n minx = min(minx, x)\n\n maxy = max(maxy, y)\n miny = min(miny, y)\n\n\n\n diffx = maxx - minx\n diffy = maxy - miny\n tmp = area(diffx, diffy)\n\n\n return tmp\n\nfor _ in range(n) :\n s = input()\n maxx, maxy, minx, miny = 0, 0, 0, 0\n x, y = 0, 0\n momentminx, momentmaxx, momentminy, momentmaxy = -1, -1, -1, -1\n for k in range(len(s)) :\n if s[k] == \"W\" :\n y += 1\n if s[k] == \"S\" :\n y -= 1\n if s[k] == \"A\" :\n x -= 1\n if s[k] == \"D\" :\n x += 1\n\n if x > maxx :\n momentmaxx = k\n if y > maxy :\n momentmaxy = k\n if x < minx :\n momentminx = k\n if y < miny :\n momentminy = k\n maxx = max(maxx, x)\n minx = min(minx, x)\n\n maxy = max(maxy, y)\n miny = min(miny, y)\n diffx = maxx - minx\n diffy = maxy - miny\n\n\n tmp = 999999999999999999999999999999999999\n l = [momentmaxx, momentmaxy, momentminx, momentminy]\n l = list(set(l))\n l = [i for i in l if i != -1]\n l.sort()\n if l != [] :\n precalcul = pre_calcul(s, l[0], (0, 0, 0, 0, 0, 0), 0)\n avant = l[0]\n for moment in l :\n precalcul = pre_calcul(s, moment, precalcul, avant)\n avant = moment\n tmp = min(tmp, calcul2(s, 'W', moment, precalcul))\n tmp = min(tmp, calcul2(s, 'S', moment, precalcul))\n tmp = min(tmp, calcul2(s, 'A', moment, precalcul))\n tmp = min(tmp, calcul2(s, 'D', moment, precalcul))\n print(tmp)\n\n```","inputs":"3\nDSAWWAW\nD\nWA\n","output":"8\n2\n4\n","actual_output":"8\n2\n4\n","execution_success":true,"sample_index":12},{"source":"apps","task_type":"verifiable_code","in_source_id":"12","prompt":"Solve the following coding problem using the programming language python:\n\nOnce again, Boris needs the help of Anton in creating a task. This time Anton needs to solve the following problem:\n\nThere are two arrays of integers $a$ and $b$ of length $n$. It turned out that array $a$ contains only elements from the set $\\{-1, 0, 1\\}$.\n\nAnton can perform the following sequence of operations any number of times: Choose any pair of indexes $(i, j)$ such that $1 \\le i < j \\le n$. It is possible to choose the same pair $(i, j)$ more than once. Add $a_i$ to $a_j$. In other words, $j$-th element of the array becomes equal to $a_i + a_j$. \n\nFor example, if you are given array $[1, -1, 0]$, you can transform it only to $[1, -1, -1]$, $[1, 0, 0]$ and $[1, -1, 1]$ by one operation.\n\nAnton wants to predict if it is possible to apply some number (zero or more) of these operations to the array $a$ so that it becomes equal to array $b$. Can you help him?\n\n\n-----Input-----\n\nEach test contains multiple test cases. \n\nThe first line contains the number of test cases $t$ ($1 \\le t \\le 10000$). The description of the test cases follows.\n\nThe first line of each test case contains a single integer $n$ ($1 \\le n \\le 10^5$) \u00a0\u2014 the length of arrays.\n\nThe second line of each test case contains $n$ integers $a_1, a_2, \\dots, a_n$ ($-1 \\le a_i \\le 1$) \u00a0\u2014 elements of array $a$. There can be duplicates among elements.\n\nThe third line of each test case contains $n$ integers $b_1, b_2, \\dots, b_n$ ($-10^9 \\le b_i \\le 10^9$) \u00a0\u2014 elements of array $b$. There can be duplicates among elements.\n\nIt is guaranteed that the sum of $n$ over all test cases doesn't exceed $10^5$.\n\n\n-----Output-----\n\nFor each test case, output one line containing \"YES\" if it's possible to make arrays $a$ and $b$ equal by performing the described operations, or \"NO\" if it's impossible.\n\nYou can print each letter in any case (upper or lower).\n\n\n-----Example-----\nInput\n5\n3\n1 -1 0\n1 1 -2\n3\n0 1 1\n0 2 2\n2\n1 0\n1 41\n2\n-1 0\n-1 -41\n5\n0 1 -1 1 -1\n1 1 -1 1 -1\n\nOutput\nYES\nNO\nYES\nYES\nNO\n\n\n\n-----Note-----\n\nIn the first test-case we can choose $(i, j)=(2, 3)$ twice and after that choose $(i, j)=(1, 2)$ twice too. These operations will transform $[1, -1, 0] \\to [1, -1, -2] \\to [1, 1, -2]$\n\nIn the second test case we can't make equal numbers on the second position.\n\nIn the third test case we can choose $(i, j)=(1, 2)$ $41$ times. The same about the fourth test case.\n\nIn the last lest case, it is impossible to make array $a$ equal to the array $b$.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfrom math import *\n\nmod = 1000000007\n\nfor zz in range(int(input())):\n n = int(input())\n a = [ int(i) for i in input().split()]\n b = [int(i) for i in input().split()]\n ha = True\n hp = False\n hm = False\n for i in range(n):\n if b[i] != a[i]:\n if b[i] > a[i]:\n if (hp):\n pass\n else:\n ha = False\n break\n else:\n if (hm):\n pass\n else:\n ha = False\n break\n if a[i] > 0:\n hp = True\n elif a[i] < 0:\n hm = True\n\n if ha:\n print('YES')\n else:\n print('NO')\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '5\\n3\\n1 -1 0\\n1 1 -2\\n3\\n0 1 1\\n0 2 2\\n2\\n1 0\\n1 41\\n2\\n-1 0\\n-1 -41\\n5\\n0 1 -1 1 -1\\n1 1 -1 1 -1\\n', 'output': 'YES\\nNO\\nYES\\nYES\\nNO\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/1333/B'}","problem_id":"vfc_48","program":"```python\nfrom math import *\n\nmod = 1000000007\n\nfor zz in range(int(input())):\n n = int(input())\n a = [ int(i) for i in input().split()]\n b = [int(i) for i in input().split()]\n ha = True\n hp = False\n hm = False\n for i in range(n):\n if b[i] != a[i]:\n if b[i] > a[i]:\n if (hp):\n pass\n else:\n ha = False\n break\n else:\n if (hm):\n pass\n else:\n ha = False\n break\n if a[i] > 0:\n hp = True\n elif a[i] < 0:\n hm = True\n\n if ha:\n print('YES')\n else:\n print('NO')\n\n```","inputs":"5\n3\n1 -1 0\n1 1 -2\n3\n0 1 1\n0 2 2\n2\n1 0\n1 41\n2\n-1 0\n-1 -41\n5\n0 1 -1 1 -1\n1 1 -1 1 -1\n","output":"YES\nNO\nYES\nYES\nNO\n","actual_output":"YES\nNO\nYES\nYES\nNO\n","execution_success":true,"sample_index":13},{"source":"apps","task_type":"verifiable_code","in_source_id":"13","prompt":"Solve the following coding problem using the programming language python:\n\nYour company was appointed to lay new asphalt on the highway of length $n$. You know that every day you can either repair one unit of the highway (lay new asphalt over one unit of the highway) or skip repairing.\n\nSkipping the repair is necessary because of the climate. The climate in your region is periodical: there are $g$ days when the weather is good and if you lay new asphalt these days it becomes high-quality pavement; after that, the weather during the next $b$ days is bad, and if you lay new asphalt these days it becomes low-quality pavement; again $g$ good days, $b$ bad days and so on.\n\nYou can be sure that you start repairing at the start of a good season, in other words, days $1, 2, \\dots, g$ are good.\n\nYou don't really care about the quality of the highway, you just want to make sure that at least half of the highway will have high-quality pavement. For example, if the $n = 5$ then at least $3$ units of the highway should have high quality; if $n = 4$ then at least $2$ units should have high quality.\n\nWhat is the minimum number of days is needed to finish the repair of the whole highway?\n\n\n-----Input-----\n\nThe first line contains a single integer $T$ ($1 \\le T \\le 10^4$) \u2014 the number of test cases.\n\nNext $T$ lines contain test cases \u2014 one per line. Each line contains three integers $n$, $g$ and $b$ ($1 \\le n, g, b \\le 10^9$) \u2014 the length of the highway and the number of good and bad days respectively.\n\n\n-----Output-----\n\nPrint $T$ integers \u2014 one per test case. For each test case, print the minimum number of days required to repair the whole highway if at least half of it should have high quality.\n\n\n-----Example-----\nInput\n3\n5 1 1\n8 10 10\n1000000 1 1000000\n\nOutput\n5\n8\n499999500000\n\n\n\n-----Note-----\n\nIn the first test case, you can just lay new asphalt each day, since days $1, 3, 5$ are good.\n\nIn the second test case, you can also lay new asphalt each day, since days $1$-$8$ are good.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfor i in range(int(input())):\n n,g,b=map(int,input().split())\n nn=(n+1)//2\n print(max(nn+(nn-1)//g*b,n))\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\n5 1 1\\n8 10 10\\n1000000 1 1000000\\n', 'output': '5\\n8\\n499999500000\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/1303/B'}","problem_id":"vfc_52","program":"```python\nfor i in range(int(input())):\n n,g,b=map(int,input().split())\n nn=(n+1)//2\n print(max(nn+(nn-1)//g*b,n))\n```","inputs":"3\n5 1 1\n8 10 10\n1000000 1 1000000\n","output":"5\n8\n499999500000\n","actual_output":"5\n8\n499999500000\n","execution_success":true,"sample_index":14},{"source":"apps","task_type":"verifiable_code","in_source_id":"14","prompt":"Solve the following coding problem using the programming language python:\n\nVasya claims that he had a paper square. He cut it into two rectangular parts using one vertical or horizontal cut. Then Vasya informed you the dimensions of these two rectangular parts. You need to check whether Vasya originally had a square. In other words, check if it is possible to make a square using two given rectangles.\n\n\n-----Input-----\n\nThe first line contains an integer $t$ ($1 \\le t \\le 10^4$) \u2014 the number of test cases in the input. Then $t$ test cases follow.\n\nEach test case is given in two lines.\n\nThe first line contains two integers $a_1$ and $b_1$ ($1 \\le a_1, b_1 \\le 100$) \u2014 the dimensions of the first one obtained after cutting rectangle. The sizes are given in random order (that is, it is not known which of the numbers is the width, and which of the numbers is the length).\n\nThe second line contains two integers $a_2$ and $b_2$ ($1 \\le a_2, b_2 \\le 100$) \u2014 the dimensions of the second obtained after cutting rectangle. The sizes are given in random order (that is, it is not known which of the numbers is the width, and which of the numbers is the length).\n\n\n-----Output-----\n\nPrint $t$ answers, each of which is a string \"YES\" (in the case of a positive answer) or \"NO\" (in the case of a negative answer). The letters in words can be printed in any case (upper or lower).\n\n\n-----Example-----\nInput\n3\n2 3\n3 1\n3 2\n1 3\n3 3\n1 3\n\nOutput\nYes\nYes\nNo\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfor _ in range(int(input())):\n a1, b1 = list(map(int, input().split()))\n a2, b2 = list(map(int, input().split()))\n if a1 > b1:\n a1, b1 = b1, a1\n if a2 > b2:\n a2, b2 = b2, a2\n flag = False\n if a1 == a2 and a1 == b1 + b2:\n flag = True\n if b1 == b2 and b1 == a1 + a2:\n flag = True\n print('Yes' if flag else 'No')\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\n2 3\\n3 1\\n3 2\\n1 3\\n3 3\\n1 3\\n', 'output': 'Yes\\nYes\\nNo\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/1351/B'}","problem_id":"vfc_56","program":"```python\nfor _ in range(int(input())):\n a1, b1 = list(map(int, input().split()))\n a2, b2 = list(map(int, input().split()))\n if a1 > b1:\n a1, b1 = b1, a1\n if a2 > b2:\n a2, b2 = b2, a2\n flag = False\n if a1 == a2 and a1 == b1 + b2:\n flag = True\n if b1 == b2 and b1 == a1 + a2:\n flag = True\n print('Yes' if flag else 'No')\n\n```","inputs":"3\n2 3\n3 1\n3 2\n1 3\n3 3\n1 3\n","output":"Yes\nYes\nNo\n","actual_output":"Yes\nYes\nNo\n","execution_success":true,"sample_index":15},{"source":"apps","task_type":"verifiable_code","in_source_id":"15","prompt":"Solve the following coding problem using the programming language python:\n\nScreen resolution of Polycarp's monitor is $a \\times b$ pixels. Unfortunately, there is one dead pixel at his screen. It has coordinates $(x, y)$ ($0 \\le x < a, 0 \\le y < b$). You can consider columns of pixels to be numbered from $0$ to $a-1$, and rows\u00a0\u2014 from $0$ to $b-1$.\n\nPolycarp wants to open a rectangular window of maximal size, which doesn't contain the dead pixel. The boundaries of the window should be parallel to the sides of the screen.\n\nPrint the maximal area (in pixels) of a window that doesn't contain the dead pixel inside itself.\n\n\n-----Input-----\n\nIn the first line you are given an integer $t$ ($1 \\le t \\le 10^4$)\u00a0\u2014 the number of test cases in the test. In the next lines you are given descriptions of $t$ test cases.\n\nEach test case contains a single line which consists of $4$ integers $a, b, x$ and $y$ ($1 \\le a, b \\le 10^4$; $0 \\le x < a$; $0 \\le y < b$)\u00a0\u2014 the resolution of the screen and the coordinates of a dead pixel. It is guaranteed that $a+b>2$ (e.g. $a=b=1$ is impossible).\n\n\n-----Output-----\n\nPrint $t$ integers\u00a0\u2014 the answers for each test case. Each answer should contain an integer equal to the maximal possible area (in pixels) of a rectangular window, that doesn't contain the dead pixel.\n\n\n-----Example-----\nInput\n6\n8 8 0 0\n1 10 0 3\n17 31 10 4\n2 1 0 0\n5 10 3 9\n10 10 4 8\n\nOutput\n56\n6\n442\n1\n45\n80\n\n\n\n-----Note-----\n\nIn the first test case, the screen resolution is $8 \\times 8$, and the upper left pixel is a dead pixel. Here you can see one of two possible layouts of the maximal window. [Image]\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfrom math import *\n\nzzz = int(input())\nfor zz in range(zzz):\n a, b, x, y = list(map(int, input().split()))\n print(max(x*b, (a-x-1)*b, y*a, (b - y - 1)*a))\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '6\\n8 8 0 0\\n1 10 0 3\\n17 31 10 4\\n2 1 0 0\\n5 10 3 9\\n10 10 4 8\\n', 'output': '56\\n6\\n442\\n1\\n45\\n80\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/1315/A'}","problem_id":"vfc_60","program":"```python\nfrom math import *\n\nzzz = int(input())\nfor zz in range(zzz):\n a, b, x, y = list(map(int, input().split()))\n print(max(x*b, (a-x-1)*b, y*a, (b - y - 1)*a))\n\n```","inputs":"6\n8 8 0 0\n1 10 0 3\n17 31 10 4\n2 1 0 0\n5 10 3 9\n10 10 4 8\n","output":"56\n6\n442\n1\n45\n80\n","actual_output":"56\n6\n442\n1\n45\n80\n","execution_success":true,"sample_index":16},{"source":"apps","task_type":"verifiable_code","in_source_id":"16","prompt":"Solve the following coding problem using the programming language python:\n\nPolycarp, Arkady's friend, prepares to the programming competition and decides to write a contest. The contest consists of $n$ problems and lasts for $T$ minutes. Each of the problems is defined by two positive integers $a_i$ and $p_i$\u00a0\u2014 its difficulty and the score awarded by its solution.\n\nPolycarp's experience suggests that his skill level is defined with positive real value $s$, and initially $s=1.0$. To solve the $i$-th problem Polycarp needs $a_i/s$ minutes.\n\nPolycarp loves to watch series, and before solving each of the problems he will definitely watch one episode. After Polycarp watches an episode, his skill decreases by $10\\%$, that is skill level $s$ decreases to $0.9s$. Each episode takes exactly $10$ minutes to watch. When Polycarp decides to solve some problem, he firstly has to watch one episode, and only then he starts solving the problem without breaks for $a_i/s$ minutes, where $s$ is his current skill level. In calculation of $a_i/s$ no rounding is performed, only division of integer value $a_i$ by real value $s$ happens.\n\nAlso, Polycarp can train for some time. If he trains for $t$ minutes, he increases his skill by $C \\cdot t$, where $C$ is some given positive real constant. Polycarp can train only before solving any problem (and before watching series). Duration of the training can be arbitrary real value.\n\nPolycarp is interested: what is the largest score he can get in the contest? It is allowed to solve problems in any order, while training is only allowed before solving the first problem.\n\n\n-----Input-----\n\nThe first line contains one integer $tc$ ($1 \\le tc \\le 20$)\u00a0\u2014 the number of test cases. Then $tc$ test cases follow.\n\nThe first line of each test contains one integer $n$ ($1 \\le n \\le 100$)\u00a0\u2014 the number of problems in the contest.\n\nThe second line of the test contains two real values $C, T$ ($0 < C < 10$, $0 \\le T \\le 2 \\cdot 10^5$), where $C$ defines the efficiency of the training and $T$ is the duration of the contest in minutes. Value $C, T$ are given exactly with three digits after the decimal point.\n\nEach of the next $n$ lines of the test contain characteristics of the corresponding problem: two integers $a_i, p_i$ ($1 \\le a_i \\le 10^4$, $1 \\le p_i \\le 10$)\u00a0\u2014 the difficulty and the score of the problem.\n\nIt is guaranteed that the value of $T$ is such that changing it by the $0.001$ in any direction will not change the test answer.\n\nPlease note that in hacks you can only use $tc = 1$.\n\n\n-----Output-----\n\nPrint $tc$ integers\u00a0\u2014 the maximum possible score in each test case.\n\n\n-----Examples-----\nInput\n2\n4\n1.000 31.000\n12 3\n20 6\n30 1\n5 1\n3\n1.000 30.000\n1 10\n10 10\n20 8\n\nOutput\n7\n20\n\n\n\n-----Note-----\n\nIn the first example, Polycarp can get score of $7$ as follows: Firstly he trains for $4$ minutes, increasing $s$ to the value of $5$; Then he decides to solve $4$-th problem: he watches one episode in $10$ minutes, his skill level decreases to $s=5*0.9=4.5$ and then he solves the problem in $5/s=5/4.5$, which is roughly $1.111$ minutes; Finally, he decides to solve $2$-nd problem: he watches one episode in $10$ minutes, his skill level decreases to $s=4.5*0.9=4.05$ and then he solves the problem in $20/s=20/4.05$, which is roughly $4.938$ minutes. \n\nThis way, Polycarp uses roughly $4+10+1.111+10+4.938=30.049$ minutes, to get score of $7$ points. It is not possible to achieve larger score in $31$ minutes.\n\nIn the second example, Polycarp can get $20$ points as follows: Firstly he trains for $4$ minutes, increasing $s$ to the value of $5$; Then he decides to solve $1$-st problem: he watches one episode in $10$ minutes, his skill decreases to $s=5*0.9=4.5$ and then he solves problem in $1/s=1/4.5$, which is roughly $0.222$ minutes. Finally, he decides to solve $2$-nd problem: he watches one episode in $10$ minutes, his skill decreases to $s=4.5*0.9=4.05$ and then he solves the problem in $10/s=10/4.05$, which is roughly $2.469$ minutes. \n\nThis way, Polycarp gets score of $20$ in $4+10+0.222+10+2.469=26.691$ minutes. It is not possible to achieve larger score in $30$ minutes.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfrom math import sqrt\nclass pro(object):\n def __init__(self,dif,sc):\n self.dif=dif\n self.sc=sc\n\n def __lt__(self,other):\n return self.dif>other.dif\n\nT=int(input())\nmul=[1]\nfor i in range(100):\n mul.append(mul[i]*10/9)\ninf=1000000007\nfor t in range(T):\n n=int(input())\n effi,tim=list(map(float,input().split()))\n prob=[]\n for i in range(n):\n x,y=list(map(int,input().split()))\n prob.append(pro(x,y))\n prob.sort()\n f=[[inf for i in range(n+1)] for j in range(1001)]\n f[0][0]=0\n totsc=0\n for i in range(n):\n totsc+=prob[i].sc\n for j in range(totsc,prob[i].sc-1,-1):\n for k in range(1,i+2):\n f[j][k]=min(f[j][k],f[j-prob[i].sc][k-1]+prob[i].dif*mul[k])\n for i in range(totsc,-1,-1):\n flag=False\n for j in range(n+1):\n if sqrt(effi*f[i][j])>=1:\n res=2*sqrt(f[i][j]/effi)-1/effi+10*j\n else:\n res=f[i][j]+10*j\n if res<=tim:\n print(i)\n flag=True\n break\n if flag==True:\n break\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n4\\n1.000 31.000\\n12 3\\n20 6\\n30 1\\n5 1\\n3\\n1.000 30.000\\n1 10\\n10 10\\n20 8\\n', 'output': '7\\n20\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/1056/F'}","problem_id":"vfc_64","program":"```python\nfrom math import sqrt\nclass pro(object):\n def __init__(self,dif,sc):\n self.dif=dif\n self.sc=sc\n\n def __lt__(self,other):\n return self.dif>other.dif\n\nT=int(input())\nmul=[1]\nfor i in range(100):\n mul.append(mul[i]*10/9)\ninf=1000000007\nfor t in range(T):\n n=int(input())\n effi,tim=list(map(float,input().split()))\n prob=[]\n for i in range(n):\n x,y=list(map(int,input().split()))\n prob.append(pro(x,y))\n prob.sort()\n f=[[inf for i in range(n+1)] for j in range(1001)]\n f[0][0]=0\n totsc=0\n for i in range(n):\n totsc+=prob[i].sc\n for j in range(totsc,prob[i].sc-1,-1):\n for k in range(1,i+2):\n f[j][k]=min(f[j][k],f[j-prob[i].sc][k-1]+prob[i].dif*mul[k])\n for i in range(totsc,-1,-1):\n flag=False\n for j in range(n+1):\n if sqrt(effi*f[i][j])>=1:\n res=2*sqrt(f[i][j]/effi)-1/effi+10*j\n else:\n res=f[i][j]+10*j\n if res<=tim:\n print(i)\n flag=True\n break\n if flag==True:\n break\n\n```","inputs":"2\n4\n1.000 31.000\n12 3\n20 6\n30 1\n5 1\n3\n1.000 30.000\n1 10\n10 10\n20 8\n","output":"7\n20\n","actual_output":"7\n20\n","execution_success":true,"sample_index":17},{"source":"apps","task_type":"verifiable_code","in_source_id":"17","prompt":"Solve the following coding problem using the programming language python:\n\nYou are given an array $a_1, a_2 \\dots a_n$. Calculate the number of tuples $(i, j, k, l)$ such that: $1 \\le i < j < k < l \\le n$; $a_i = a_k$ and $a_j = a_l$; \n\n\n-----Input-----\n\nThe first line contains a single integer $t$ ($1 \\le t \\le 100$)\u00a0\u2014 the number of test cases.\n\nThe first line of each test case contains a single integer $n$ ($4 \\le n \\le 3000$)\u00a0\u2014 the size of the array $a$.\n\nThe second line of each test case contains $n$ integers $a_1, a_2, \\dots, a_n$ ($1 \\le a_i \\le n$)\u00a0\u2014 the array $a$.\n\nIt's guaranteed that the sum of $n$ in one test doesn't exceed $3000$.\n\n\n-----Output-----\n\nFor each test case, print the number of described tuples.\n\n\n-----Example-----\nInput\n2\n5\n2 2 2 2 2\n6\n1 3 3 1 2 3\n\nOutput\n5\n2\n\n\n\n-----Note-----\n\nIn the first test case, for any four indices $i < j < k < l$ are valid, so the answer is the number of tuples.\n\nIn the second test case, there are $2$ valid tuples: $(1, 2, 4, 6)$: $a_1 = a_4$ and $a_2 = a_6$; $(1, 3, 4, 6)$: $a_1 = a_4$ and $a_3 = a_6$.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nclass BIT():\n def __init__(self,n):\n self.BIT=[0]*(n+1)\n self.num=n\n\n def query(self,idx):\n res_sum = 0\n while idx > 0:\n res_sum += self.BIT[idx]\n idx -= idx&(-idx)\n return res_sum\n\n #Ai += x O(logN)\n def update(self,idx,x):\n while idx <= self.num:\n self.BIT[idx] += x\n idx += idx&(-idx)\n return\n\nimport sys,random\n\ninput=sys.stdin.readline\n\nfor _ in range(int(input())):\n n=int(input())\n a=list(map(int,input().split()))\n pair=[[] for i in range(n+1)]\n for i in range(n):\n for j in range(i+1,n):\n if a[i]==a[j]:\n pair[i+1].append(j+1)\n\n bit=BIT(n)\n ans=0\n for i in range(1,n+1):\n minus=bit.query(i)\n for r in pair[i]:\n ans+=bit.query(r-1)-minus\n for r in pair[i]:\n bit.update(r,1)\n\n print(ans)\n \n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n5\\n2 2 2 2 2\\n6\\n1 3 3 1 2 3\\n', 'output': '5\\n2\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/1400/D'}","problem_id":"vfc_68","program":"```python\nclass BIT():\n def __init__(self,n):\n self.BIT=[0]*(n+1)\n self.num=n\n\n def query(self,idx):\n res_sum = 0\n while idx > 0:\n res_sum += self.BIT[idx]\n idx -= idx&(-idx)\n return res_sum\n\n #Ai += x O(logN)\n def update(self,idx,x):\n while idx <= self.num:\n self.BIT[idx] += x\n idx += idx&(-idx)\n return\n\nimport sys,random\n\ninput=sys.stdin.readline\n\nfor _ in range(int(input())):\n n=int(input())\n a=list(map(int,input().split()))\n pair=[[] for i in range(n+1)]\n for i in range(n):\n for j in range(i+1,n):\n if a[i]==a[j]:\n pair[i+1].append(j+1)\n\n bit=BIT(n)\n ans=0\n for i in range(1,n+1):\n minus=bit.query(i)\n for r in pair[i]:\n ans+=bit.query(r-1)-minus\n for r in pair[i]:\n bit.update(r,1)\n\n print(ans)\n \n\n```","inputs":"2\n5\n2 2 2 2 2\n6\n1 3 3 1 2 3\n","output":"5\n2\n","actual_output":"5\n2\n","execution_success":true,"sample_index":18},{"source":"apps","task_type":"verifiable_code","in_source_id":"19","prompt":"Solve the following coding problem using the programming language python:\n\nThe only difference between easy and hard versions is constraints.\n\nThe BerTV channel every day broadcasts one episode of one of the $k$ TV shows. You know the schedule for the next $n$ days: a sequence of integers $a_1, a_2, \\dots, a_n$ ($1 \\le a_i \\le k$), where $a_i$ is the show, the episode of which will be shown in $i$-th day.\n\nThe subscription to the show is bought for the entire show (i.e. for all its episodes), for each show the subscription is bought separately.\n\nHow many minimum subscriptions do you need to buy in order to have the opportunity to watch episodes of purchased shows $d$ ($1 \\le d \\le n$) days in a row? In other words, you want to buy the minimum number of TV shows so that there is some segment of $d$ consecutive days in which all episodes belong to the purchased shows.\n\n\n-----Input-----\n\nThe first line contains an integer $t$ ($1 \\le t \\le 10000$) \u2014 the number of test cases in the input. Then $t$ test case descriptions follow.\n\nThe first line of each test case contains three integers $n, k$ and $d$ ($1 \\le n \\le 2\\cdot10^5$, $1 \\le k \\le 10^6$, $1 \\le d \\le n$). The second line contains $n$ integers $a_1, a_2, \\dots, a_n$ ($1 \\le a_i \\le k$), where $a_i$ is the show that is broadcasted on the $i$-th day.\n\nIt is guaranteed that the sum of the values \u200b\u200bof $n$ for all test cases in the input does not exceed $2\\cdot10^5$.\n\n\n-----Output-----\n\nPrint $t$ integers \u2014 the answers to the test cases in the input in the order they follow. The answer to a test case is the minimum number of TV shows for which you need to purchase a subscription so that you can watch episodes of the purchased TV shows on BerTV for $d$ consecutive days. Please note that it is permissible that you will be able to watch more than $d$ days in a row.\n\n\n-----Example-----\nInput\n4\n5 2 2\n1 2 1 2 1\n9 3 3\n3 3 3 2 2 2 1 1 1\n4 10 4\n10 8 6 4\n16 9 8\n3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3\n\nOutput\n2\n1\n4\n5\n\n\n\n-----Note-----\n\nIn the first test case to have an opportunity to watch shows for two consecutive days, you need to buy a subscription on show $1$ and on show $2$. So the answer is two.\n\nIn the second test case, you can buy a subscription to any show because for each show you can find a segment of three consecutive days, consisting only of episodes of this show.\n\nIn the third test case in the unique segment of four days, you have four different shows, so you need to buy a subscription to all these four shows.\n\nIn the fourth test case, you can buy subscriptions to shows $3,5,7,8,9$, and you will be able to watch shows for the last eight days.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfor _ in range(int(input())):\n n, k, d = list(map(int, input().split()))\n a = list(map(int, input().split()))\n s = {}\n for q in range(d):\n s[a[q]] = s.get(a[q], 0)+1\n ans = len(s)\n for q in range(d, n):\n if s[a[q-d]] == 1:\n del s[a[q-d]]\n else:\n s[a[q-d]] -= 1\n s[a[q]] = s.get(a[q], 0)+1\n ans = min(ans, len(s))\n print(ans)\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '4\\n5 2 2\\n1 2 1 2 1\\n9 3 3\\n3 3 3 2 2 2 1 1 1\\n4 10 4\\n10 8 6 4\\n16 9 8\\n3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3\\n', 'output': '2\\n1\\n4\\n5\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/1225/B2'}","problem_id":"vfc_76","program":"```python\nfor _ in range(int(input())):\n n, k, d = list(map(int, input().split()))\n a = list(map(int, input().split()))\n s = {}\n for q in range(d):\n s[a[q]] = s.get(a[q], 0)+1\n ans = len(s)\n for q in range(d, n):\n if s[a[q-d]] == 1:\n del s[a[q-d]]\n else:\n s[a[q-d]] -= 1\n s[a[q]] = s.get(a[q], 0)+1\n ans = min(ans, len(s))\n print(ans)\n\n```","inputs":"4\n5 2 2\n1 2 1 2 1\n9 3 3\n3 3 3 2 2 2 1 1 1\n4 10 4\n10 8 6 4\n16 9 8\n3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3\n","output":"2\n1\n4\n5\n","actual_output":"2\n1\n4\n5\n","execution_success":true,"sample_index":20},{"source":"apps","task_type":"verifiable_code","in_source_id":"20","prompt":"Solve the following coding problem using the programming language python:\n\nGildong owns a bulgogi restaurant. The restaurant has a lot of customers, so many of them like to make a reservation before visiting it.\n\nGildong tries so hard to satisfy the customers that he even memorized all customers' preferred temperature ranges! Looking through the reservation list, he wants to satisfy all customers by controlling the temperature of the restaurant.\n\nThe restaurant has an air conditioner that has 3 states: off, heating, and cooling. When it's off, the restaurant's temperature remains the same. When it's heating, the temperature increases by 1 in one minute. Lastly, when it's cooling, the temperature decreases by 1 in one minute. Gildong can change the state as many times as he wants, at any integer minutes. The air conditioner is off initially.\n\nEach customer is characterized by three values: $t_i$ \u2014 the time (in minutes) when the $i$-th customer visits the restaurant, $l_i$ \u2014 the lower bound of their preferred temperature range, and $h_i$ \u2014 the upper bound of their preferred temperature range.\n\nA customer is satisfied if the temperature is within the preferred range at the instant they visit the restaurant. Formally, the $i$-th customer is satisfied if and only if the temperature is between $l_i$ and $h_i$ (inclusive) in the $t_i$-th minute.\n\nGiven the initial temperature, the list of reserved customers' visit times and their preferred temperature ranges, you're going to help him find if it's possible to satisfy all customers.\n\n\n-----Input-----\n\nEach test contains one or more test cases. The first line contains the number of test cases $q$ ($1 \\le q \\le 500$). Description of the test cases follows.\n\nThe first line of each test case contains two integers $n$ and $m$ ($1 \\le n \\le 100$, $-10^9 \\le m \\le 10^9$), where $n$ is the number of reserved customers and $m$ is the initial temperature of the restaurant.\n\nNext, $n$ lines follow. The $i$-th line of them contains three integers $t_i$, $l_i$, and $h_i$ ($1 \\le t_i \\le 10^9$, $-10^9 \\le l_i \\le h_i \\le 10^9$), where $t_i$ is the time when the $i$-th customer visits, $l_i$ is the lower bound of their preferred temperature range, and $h_i$ is the upper bound of their preferred temperature range. The preferred temperature ranges are inclusive.\n\nThe customers are given in non-decreasing order of their visit time, and the current time is $0$.\n\n\n-----Output-----\n\nFor each test case, print \"YES\" if it is possible to satisfy all customers. Otherwise, print \"NO\".\n\nYou can print each letter in any case (upper or lower).\n\n\n-----Example-----\nInput\n4\n3 0\n5 1 2\n7 3 5\n10 -1 0\n2 12\n5 7 10\n10 16 20\n3 -100\n100 0 0\n100 -50 50\n200 100 100\n1 100\n99 -100 0\n\nOutput\nYES\nNO\nYES\nNO\n\n\n\n-----Note-----\n\nIn the first case, Gildong can control the air conditioner to satisfy all customers in the following way: At $0$-th minute, change the state to heating (the temperature is 0). At $2$-nd minute, change the state to off (the temperature is 2). At $5$-th minute, change the state to heating (the temperature is 2, the $1$-st customer is satisfied). At $6$-th minute, change the state to off (the temperature is 3). At $7$-th minute, change the state to cooling (the temperature is 3, the $2$-nd customer is satisfied). At $10$-th minute, the temperature will be 0, which satisfies the last customer. \n\nIn the third case, Gildong can change the state to heating at $0$-th minute and leave it be. Then all customers will be satisfied. Note that the $1$-st customer's visit time equals the $2$-nd customer's visit time.\n\nIn the second and the fourth case, Gildong has to make at least one customer unsatisfied.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nq = int(input())\nfor _ in range(q):\n n, m = list(map(int, input().split()))\n info = [list(map(int, input().split())) for i in range(n)]\n info = sorted(info)\n now =(m, m)\n time = 0\n flag = True\n for i in range(n):\n t, l, h = info[i]\n l_now = now[0] - (t - time)\n h_now = now[1] + (t - time)\n time = t\n if h < l_now or h_now < l:\n flag = False\n else:\n l_now = max(l_now, l)\n h_now = min(h_now, h)\n now = (l_now, h_now)\n if flag:\n print(\"YES\")\n else:\n print(\"NO\")\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '4\\n3 0\\n5 1 2\\n7 3 5\\n10 -1 0\\n2 12\\n5 7 10\\n10 16 20\\n3 -100\\n100 0 0\\n100 -50 50\\n200 100 100\\n1 100\\n99 -100 0\\n', 'output': 'YES\\nNO\\nYES\\nNO\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/1304/C'}","problem_id":"vfc_80","program":"```python\nq = int(input())\nfor _ in range(q):\n n, m = list(map(int, input().split()))\n info = [list(map(int, input().split())) for i in range(n)]\n info = sorted(info)\n now =(m, m)\n time = 0\n flag = True\n for i in range(n):\n t, l, h = info[i]\n l_now = now[0] - (t - time)\n h_now = now[1] + (t - time)\n time = t\n if h < l_now or h_now < l:\n flag = False\n else:\n l_now = max(l_now, l)\n h_now = min(h_now, h)\n now = (l_now, h_now)\n if flag:\n print(\"YES\")\n else:\n print(\"NO\")\n```","inputs":"4\n3 0\n5 1 2\n7 3 5\n10 -1 0\n2 12\n5 7 10\n10 16 20\n3 -100\n100 0 0\n100 -50 50\n200 100 100\n1 100\n99 -100 0\n","output":"YES\nNO\nYES\nNO\n","actual_output":"YES\nNO\nYES\nNO\n","execution_success":true,"sample_index":21},{"source":"apps","task_type":"verifiable_code","in_source_id":"21","prompt":"Solve the following coding problem using the programming language python:\n\nAmong Johnny's numerous hobbies, there are two seemingly harmless ones: applying bitwise operations and sneaking into his dad's office. As it is usually the case with small children, Johnny is unaware that combining these two activities can get him in a lot of trouble.\n\nThere is a set $S$ containing very important numbers on his dad's desk. The minute Johnny heard about it, he decided that it's a good idea to choose a positive integer $k$ and replace each element $s$ of the set $S$ with $s \\oplus k$ ($\\oplus$ denotes the exclusive or operation). \n\nHelp him choose such $k$ that Johnny's dad will not see any difference after his son is done playing (i.e. Johnny will get the same set as before playing). It is possible that no such number exists. It is also possible that there are many of them. In such a case, output the smallest one. Note that the order of elements in a set doesn't matter, i.e. set $\\{1, 2, 3\\}$ equals to set $\\{2, 1, 3\\}$.\n\nFormally, find the smallest positive integer $k$ such that $\\{s \\oplus k | s \\in S\\} = S$ or report that there is no such number.\n\nFor example, if $S = \\{1, 3, 4\\}$ and $k = 2$, new set will be equal to $\\{3, 1, 6\\}$. If $S = \\{0, 1, 2, 3\\}$ and $k = 1$, after playing set will stay the same.\n\n\n-----Input-----\n\nIn the first line of input, there is a single integer $t$ ($1 \\leq t \\leq 1024$), the number of test cases. In the next lines, $t$ test cases follow. Each of them consists of two lines. \n\nIn the first line there is a single integer $n$ ($1 \\leq n \\leq 1024$) denoting the number of elements in set $S$. Second line consists of $n$ distinct integers $s_i$ ($0 \\leq s_i < 1024$), elements of $S$.\n\nIt is guaranteed that the sum of $n$ over all test cases will not exceed $1024$.\n\n\n-----Output-----\n\nPrint $t$ lines; $i$-th line should contain the answer to the $i$-th test case, the minimal positive integer $k$ satisfying the conditions or $-1$ if no such $k$ exists.\n\n\n-----Example-----\nInput\n6\n4\n1 0 2 3\n6\n10 7 14 8 3 12\n2\n0 2\n3\n1 2 3\n6\n1 4 6 10 11 12\n2\n0 1023\n\nOutput\n1\n4\n2\n-1\n-1\n1023\n\n\n\n-----Note-----\n\nIn the first test case, the answer is $1$ because it is a minimum positive integer and it satisfies all the conditions.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nt = int(input())\n\nfor _ in range(t):\n n = list(input().strip())\n s = list(map(int, input().strip().split()))\n\n check = set(s)\n found = False\n for i in range(1, 1025):\n newset = set([e^i for e in s])\n if check == newset:\n print(i)\n found = True\n break\n if not found:\n print(-1)\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '6\\n4\\n1 0 2 3\\n6\\n10 7 14 8 3 12\\n2\\n0 2\\n3\\n1 2 3\\n6\\n1 4 6 10 11 12\\n2\\n0 1023\\n', 'output': '1\\n4\\n2\\n-1\\n-1\\n1023\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/1362/B'}","problem_id":"vfc_84","program":"```python\nt = int(input())\n\nfor _ in range(t):\n n = list(input().strip())\n s = list(map(int, input().strip().split()))\n\n check = set(s)\n found = False\n for i in range(1, 1025):\n newset = set([e^i for e in s])\n if check == newset:\n print(i)\n found = True\n break\n if not found:\n print(-1)\n\n```","inputs":"6\n4\n1 0 2 3\n6\n10 7 14 8 3 12\n2\n0 2\n3\n1 2 3\n6\n1 4 6 10 11 12\n2\n0 1023\n","output":"1\n4\n2\n-1\n-1\n1023\n","actual_output":"1\n4\n2\n-1\n-1\n1023\n","execution_success":true,"sample_index":22},{"source":"apps","task_type":"verifiable_code","in_source_id":"22","prompt":"Solve the following coding problem using the programming language python:\n\nLet's define the following recurrence: $$a_{n+1} = a_{n} + minDigit(a_{n}) \\cdot maxDigit(a_{n}).$$\n\nHere $minDigit(x)$ and $maxDigit(x)$ are the minimal and maximal digits in the decimal representation of $x$ without leading zeroes. For examples refer to notes.\n\nYour task is calculate $a_{K}$ for given $a_{1}$ and $K$.\n\n\n-----Input-----\n\nThe first line contains one integer $t$ ($1 \\le t \\le 1000$)\u00a0\u2014 the number of independent test cases.\n\nEach test case consists of a single line containing two integers $a_{1}$ and $K$ ($1 \\le a_{1} \\le 10^{18}$, $1 \\le K \\le 10^{16}$) separated by a space.\n\n\n-----Output-----\n\nFor each test case print one integer $a_{K}$ on a separate line.\n\n\n-----Example-----\nInput\n8\n1 4\n487 1\n487 2\n487 3\n487 4\n487 5\n487 6\n487 7\n\nOutput\n42\n487\n519\n528\n544\n564\n588\n628\n\n\n\n-----Note-----\n\n$a_{1} = 487$ \n\n $a_{2} = a_{1} + minDigit(a_{1}) \\cdot maxDigit(a_{1}) = 487 + \\min (4, 8, 7) \\cdot \\max (4, 8, 7) = 487 + 4 \\cdot 8 = 519$ \n\n $a_{3} = a_{2} + minDigit(a_{2}) \\cdot maxDigit(a_{2}) = 519 + \\min (5, 1, 9) \\cdot \\max (5, 1, 9) = 519 + 1 \\cdot 9 = 528$ \n\n $a_{4} = a_{3} + minDigit(a_{3}) \\cdot maxDigit(a_{3}) = 528 + \\min (5, 2, 8) \\cdot \\max (5, 2, 8) = 528 + 2 \\cdot 8 = 544$ \n\n $a_{5} = a_{4} + minDigit(a_{4}) \\cdot maxDigit(a_{4}) = 544 + \\min (5, 4, 4) \\cdot \\max (5, 4, 4) = 544 + 4 \\cdot 5 = 564$ \n\n $a_{6} = a_{5} + minDigit(a_{5}) \\cdot maxDigit(a_{5}) = 564 + \\min (5, 6, 4) \\cdot \\max (5, 6, 4) = 564 + 4 \\cdot 6 = 588$ \n\n $a_{7} = a_{6} + minDigit(a_{6}) \\cdot maxDigit(a_{6}) = 588 + \\min (5, 8, 8) \\cdot \\max (5, 8, 8) = 588 + 5 \\cdot 8 = 628$\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nimport sys\n\ninput = sys.stdin.readline\n\nfor _ in range(int(input())):\n\ta, k = list(map(int, input().split()))\n\tfor _ in range(k - 1):\n\t\tif '0' in str(a):\n\t\t\tbreak\n\t\ta += int(min(list(str(a)))) * int(max(list(str(a))))\n\tprint(a)\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '8\\n1 4\\n487 1\\n487 2\\n487 3\\n487 4\\n487 5\\n487 6\\n487 7\\n', 'output': '42\\n487\\n519\\n528\\n544\\n564\\n588\\n628\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/1355/A'}","problem_id":"vfc_88","program":"```python\nimport sys\n\ninput = sys.stdin.readline\n\nfor _ in range(int(input())):\n\ta, k = list(map(int, input().split()))\n\tfor _ in range(k - 1):\n\t\tif '0' in str(a):\n\t\t\tbreak\n\t\ta += int(min(list(str(a)))) * int(max(list(str(a))))\n\tprint(a)\n\n```","inputs":"8\n1 4\n487 1\n487 2\n487 3\n487 4\n487 5\n487 6\n487 7\n","output":"42\n487\n519\n528\n544\n564\n588\n628\n","actual_output":"42\n487\n519\n528\n544\n564\n588\n628\n","execution_success":true,"sample_index":23},{"source":"apps","task_type":"verifiable_code","in_source_id":"23","prompt":"Solve the following coding problem using the programming language python:\n\nThe only difference between easy and hard versions is constraints.\n\nNow elections are held in Berland and you want to win them. More precisely, you want everyone to vote for you.\n\nThere are $n$ voters, and two ways to convince each of them to vote for you. The first way to convince the $i$-th voter is to pay him $p_i$ coins. The second way is to make $m_i$ other voters vote for you, and the $i$-th voter will vote for free.\n\nMoreover, the process of such voting takes place in several steps. For example, if there are five voters with $m_1 = 1$, $m_2 = 2$, $m_3 = 2$, $m_4 = 4$, $m_5 = 5$, then you can buy the vote of the fifth voter, and eventually everyone will vote for you. Set of people voting for you will change as follows: ${5} \\rightarrow {1, 5} \\rightarrow {1, 2, 3, 5} \\rightarrow {1, 2, 3, 4, 5}$.\n\nCalculate the minimum number of coins you have to spend so that everyone votes for you.\n\n\n-----Input-----\n\nThe first line contains one integer $t$ ($1 \\le t \\le 5000$) \u2014 the number of test cases.\n\nThe first line of each test case contains one integer $n$ ($1 \\le n \\le 5000$) \u2014 the number of voters.\n\nThe next $n$ lines contains the description of voters. $i$-th line contains two integers $m_i$ and $p_i$ ($1 \\le p_i \\le 10^9, 0 \\le m_i < n$).\n\nIt is guaranteed that the sum of all $n$ over all test cases does not exceed $5000$.\n\n\n-----Output-----\n\nFor each test case print one integer \u2014 the minimum number of coins you have to spend so that everyone votes for you.\n\n\n-----Example-----\nInput\n3\n3\n1 5\n2 10\n2 8\n7\n0 1\n3 1\n1 1\n6 1\n1 1\n4 1\n4 1\n6\n2 6\n2 3\n2 8\n2 7\n4 4\n5 5\n\nOutput\n8\n0\n7\n\n\n\n-----Note-----\n\nIn the first test case you have to buy vote of the third voter. Then the set of people voting for you will change as follows: ${3} \\rightarrow {1, 3} \\rightarrow {1, 2, 3}$.\n\nIn the second example you don't need to buy votes. The set of people voting for you will change as follows: ${1} \\rightarrow {1, 3, 5} \\rightarrow {1, 2, 3, 5} \\rightarrow {1, 2, 3, 5, 6, 7} \\rightarrow {1, 2, 3, 4, 5, 6, 7}$.\n\nIn the third test case you have to buy votes of the second and the fifth voters. Then the set of people voting for you will change as follows: ${2, 5} \\rightarrow {1, 2, 3, 4, 5} \\rightarrow {1, 2, 3, 4, 5, 6}$.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nimport heapq\n\nfor _ in range(int(input())):\n n = int(input())\n voters = []\n for i in range(n):\n m,p = list(map(int, input().split()))\n voters.append((m, -p))\n voters.sort()\n for i in range(n):\n voters[i] = (voters[i][0], -voters[i][1])\n\n ans = 0\n costs = []\n heapq.heapify(costs)\n bought = 0\n for i in range(n-1, -1, -1):\n buysNeeded = voters[i][0] - i - bought\n heapq.heappush(costs, voters[i][1])\n while buysNeeded > 0 and len(costs) > 0:\n ans += heapq.heappop(costs)\n bought += 1\n buysNeeded -= 1\n\n print(ans)\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\n3\\n1 5\\n2 10\\n2 8\\n7\\n0 1\\n3 1\\n1 1\\n6 1\\n1 1\\n4 1\\n4 1\\n6\\n2 6\\n2 3\\n2 8\\n2 7\\n4 4\\n5 5\\n', 'output': '8\\n0\\n7\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/1251/E1'}","problem_id":"vfc_92","program":"```python\nimport heapq\n\nfor _ in range(int(input())):\n n = int(input())\n voters = []\n for i in range(n):\n m,p = list(map(int, input().split()))\n voters.append((m, -p))\n voters.sort()\n for i in range(n):\n voters[i] = (voters[i][0], -voters[i][1])\n\n ans = 0\n costs = []\n heapq.heapify(costs)\n bought = 0\n for i in range(n-1, -1, -1):\n buysNeeded = voters[i][0] - i - bought\n heapq.heappush(costs, voters[i][1])\n while buysNeeded > 0 and len(costs) > 0:\n ans += heapq.heappop(costs)\n bought += 1\n buysNeeded -= 1\n\n print(ans)\n\n```","inputs":"3\n3\n1 5\n2 10\n2 8\n7\n0 1\n3 1\n1 1\n6 1\n1 1\n4 1\n4 1\n6\n2 6\n2 3\n2 8\n2 7\n4 4\n5 5\n","output":"8\n0\n7\n","actual_output":"8\n0\n7\n","execution_success":true,"sample_index":24},{"source":"apps","task_type":"verifiable_code","in_source_id":"24","prompt":"Solve the following coding problem using the programming language python:\n\nTry guessing the statement from this picture: $3$ \n\nYou are given a non-negative integer $d$. You have to find two non-negative real numbers $a$ and $b$ such that $a + b = d$ and $a \\cdot b = d$.\n\n\n-----Input-----\n\nThe first line contains $t$ ($1 \\le t \\le 10^3$) \u2014 the number of test cases.\n\nEach test case contains one integer $d$ $(0 \\le d \\le 10^3)$.\n\n\n-----Output-----\n\nFor each test print one line.\n\nIf there is an answer for the $i$-th test, print \"Y\", and then the numbers $a$ and $b$.\n\nIf there is no answer for the $i$-th test, print \"N\".\n\nYour answer will be considered correct if $|(a + b) - a \\cdot b| \\le 10^{-6}$ and $|(a + b) - d| \\le 10^{-6}$.\n\n\n-----Example-----\nInput\n7\n69\n0\n1\n4\n5\n999\n1000\n\nOutput\nY 67.985071301 1.014928699\nY 0.000000000 0.000000000\nN\nY 2.000000000 2.000000000\nY 3.618033989 1.381966011\nY 997.998996990 1.001003010\nY 998.998997995 1.001002005\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfor _ in range(int(input())):\n d=int(input())\n anws=False\n if d**2>=4*d:\n root=(d**2-4*d)**0.5\n a=(d+root)/2\n b=(d-root)/2\n anws=True\n if anws:\n print(\"Y {:.9f} {:.9f}\".format(a,b))\n else:\n print(\"N\")\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '7\\n69\\n0\\n1\\n4\\n5\\n999\\n1000\\n', 'output': 'Y 67.985071301 1.014928699\\nY 0.000000000 0.000000000\\nN\\nY 2.000000000 2.000000000\\nY 3.618033989 1.381966011\\nY 997.998996990 1.001003010\\nY 998.998997995 1.001002005\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/1076/C'}","problem_id":"vfc_96","program":"```python\nfor _ in range(int(input())):\n d=int(input())\n anws=False\n if d**2>=4*d:\n root=(d**2-4*d)**0.5\n a=(d+root)/2\n b=(d-root)/2\n anws=True\n if anws:\n print(\"Y {:.9f} {:.9f}\".format(a,b))\n else:\n print(\"N\")\n```","inputs":"7\n69\n0\n1\n4\n5\n999\n1000\n","output":"Y 67.985071301 1.014928699\nY 0.000000000 0.000000000\nN\nY 2.000000000 2.000000000\nY 3.618033989 1.381966011\nY 997.998996990 1.001003010\nY 998.998997995 1.001002005\n","actual_output":"Y 67.985071301 1.014928699\nY 0.000000000 0.000000000\nN\nY 2.000000000 2.000000000\nY 3.618033989 1.381966011\nY 997.998996990 1.001003010\nY 998.998997995 1.001002005\n","execution_success":true,"sample_index":25},{"source":"apps","task_type":"verifiable_code","in_source_id":"26","prompt":"Solve the following coding problem using the programming language python:\n\nYou are given a special jigsaw puzzle consisting of $n\\cdot m$ identical pieces. Every piece has three tabs and one blank, as pictured below. $\\{3$ \n\nThe jigsaw puzzle is considered solved if the following conditions hold: The pieces are arranged into a grid with $n$ rows and $m$ columns. For any two pieces that share an edge in the grid, a tab of one piece fits perfectly into a blank of the other piece. \n\nThrough rotation and translation of the pieces, determine if it is possible to solve the jigsaw puzzle.\n\n\n-----Input-----\n\nThe test consists of multiple test cases. The first line contains a single integer $t$ ($1\\le t\\le 1000$)\u00a0\u2014 the number of test cases. Next $t$ lines contain descriptions of test cases.\n\nEach test case contains two integers $n$ and $m$ ($1 \\le n,m \\le 10^5$).\n\n\n-----Output-----\n\nFor each test case output a single line containing \"YES\" if it is possible to solve the jigsaw puzzle, or \"NO\" otherwise. You can print each letter in any case (upper or lower).\n\n\n-----Example-----\nInput\n3\n1 3\n100000 100000\n2 2\n\nOutput\nYES\nNO\nYES\n\n\n\n-----Note-----\n\nFor the first test case, this is an example solution: [Image] \n\nFor the second test case, we can show that no solution exists.\n\nFor the third test case, this is an example solution: $\\left\\{\\begin{array}{l}{3} \\\\{3} \\end{array} \\right\\}$\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfor _ in range(int(input())):\n n, m = list(map(int, input().split()))\n if n < m:\n n, m = m, n # n > m\n\n if m == 1:\n print(\"YES\")\n continue\n\n if m == 2 and n == 2:\n print(\"YES\")\n continue\n\n print(\"NO\")\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\n1 3\\n100000 100000\\n2 2\\n', 'output': 'YES\\nNO\\nYES\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/1345/A'}","problem_id":"vfc_104","program":"```python\nfor _ in range(int(input())):\n n, m = list(map(int, input().split()))\n if n < m:\n n, m = m, n # n > m\n\n if m == 1:\n print(\"YES\")\n continue\n\n if m == 2 and n == 2:\n print(\"YES\")\n continue\n\n print(\"NO\")\n\n```","inputs":"3\n1 3\n100000 100000\n2 2\n","output":"YES\nNO\nYES\n","actual_output":"YES\nNO\nYES\n","execution_success":true,"sample_index":27},{"source":"apps","task_type":"verifiable_code","in_source_id":"27","prompt":"Solve the following coding problem using the programming language python:\n\nThere are $n$ positive integers $a_1, a_2, \\dots, a_n$. For the one move you can choose any even value $c$ and divide by two all elements that equal $c$.\n\nFor example, if $a=[6,8,12,6,3,12]$ and you choose $c=6$, and $a$ is transformed into $a=[3,8,12,3,3,12]$ after the move.\n\nYou need to find the minimal number of moves for transforming $a$ to an array of only odd integers (each element shouldn't be divisible by $2$).\n\n\n-----Input-----\n\nThe first line of the input contains one integer $t$ ($1 \\le t \\le 10^4$) \u2014 the number of test cases in the input. Then $t$ test cases follow.\n\nThe first line of a test case contains $n$ ($1 \\le n \\le 2\\cdot10^5$) \u2014 the number of integers in the sequence $a$. The second line contains positive integers $a_1, a_2, \\dots, a_n$ ($1 \\le a_i \\le 10^9$).\n\nThe sum of $n$ for all test cases in the input doesn't exceed $2\\cdot10^5$.\n\n\n-----Output-----\n\nFor $t$ test cases print the answers in the order of test cases in the input. The answer for the test case is the minimal number of moves needed to make all numbers in the test case odd (i.e. not divisible by $2$).\n\n\n-----Example-----\nInput\n4\n6\n40 6 40 3 20 1\n1\n1024\n4\n2 4 8 16\n3\n3 1 7\n\nOutput\n4\n10\n4\n0\n\n\n\n-----Note-----\n\nIn the first test case of the example, the optimal sequence of moves can be as follows:\n\n before making moves $a=[40, 6, 40, 3, 20, 1]$; choose $c=6$; now $a=[40, 3, 40, 3, 20, 1]$; choose $c=40$; now $a=[20, 3, 20, 3, 20, 1]$; choose $c=20$; now $a=[10, 3, 10, 3, 10, 1]$; choose $c=10$; now $a=[5, 3, 5, 3, 5, 1]$ \u2014 all numbers are odd. \n\nThus, all numbers became odd after $4$ moves. In $3$ or fewer moves, you cannot make them all odd.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\ntests = int(input())\nfor test in range(tests):\n n = int(input())\n a = [int(i) for i in input().split()]\n d = {}\n for i in range(n):\n s = 0\n while a[i] % 2 == 0:\n a[i] //= 2\n s += 1\n if a[i] in list(d.keys()):\n d[a[i]] = max(s, d[a[i]])\n else:\n d[a[i]] = s\n s = 0\n for i in list(d.keys()):\n s += d[i]\n print(s)\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '4\\n6\\n40 6 40 3 20 1\\n1\\n1024\\n4\\n2 4 8 16\\n3\\n3 1 7\\n', 'output': '4\\n10\\n4\\n0\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/1259/B'}","problem_id":"vfc_108","program":"```python\ntests = int(input())\nfor test in range(tests):\n n = int(input())\n a = [int(i) for i in input().split()]\n d = {}\n for i in range(n):\n s = 0\n while a[i] % 2 == 0:\n a[i] //= 2\n s += 1\n if a[i] in list(d.keys()):\n d[a[i]] = max(s, d[a[i]])\n else:\n d[a[i]] = s\n s = 0\n for i in list(d.keys()):\n s += d[i]\n print(s)\n\n```","inputs":"4\n6\n40 6 40 3 20 1\n1\n1024\n4\n2 4 8 16\n3\n3 1 7\n","output":"4\n10\n4\n0\n","actual_output":"4\n10\n4\n0\n","execution_success":true,"sample_index":28},{"source":"apps","task_type":"verifiable_code","in_source_id":"28","prompt":"Solve the following coding problem using the programming language python:\n\nAcacius is studying strings theory. Today he came with the following problem.\n\nYou are given a string $s$ of length $n$ consisting of lowercase English letters and question marks. It is possible to replace question marks with lowercase English letters in such a way that a string \"abacaba\" occurs as a substring in a resulting string exactly once?\n\nEach question mark should be replaced with exactly one lowercase English letter. For example, string \"a?b?c\" can be transformed into strings \"aabbc\" and \"azbzc\", but can't be transformed into strings \"aabc\", \"a?bbc\" and \"babbc\".\n\nOccurrence of a string $t$ of length $m$ in the string $s$ of length $n$ as a substring is a index $i$ ($1 \\leq i \\leq n - m + 1$) such that string $s[i..i+m-1]$ consisting of $m$ consecutive symbols of $s$ starting from $i$-th equals to string $t$. For example string \"ababa\" has two occurrences of a string \"aba\" as a substring with $i = 1$ and $i = 3$, but there are no occurrences of a string \"aba\" in the string \"acba\" as a substring.\n\nPlease help Acacius to check if it is possible to replace all question marks with lowercase English letters in such a way that a string \"abacaba\" occurs as a substring in a resulting string exactly once.\n\n\n-----Input-----\n\nFirst line of input contains an integer $T$ ($1 \\leq T \\leq 5000$), number of test cases. $T$ pairs of lines with test case descriptions follow.\n\nThe first line of a test case description contains a single integer $n$ ($7 \\leq n \\leq 50$), length of a string $s$.\n\nThe second line of a test case description contains string $s$ of length $n$ consisting of lowercase English letters and question marks.\n\n\n-----Output-----\n\nFor each test case output an answer for it.\n\nIn case if there is no way to replace question marks in string $s$ with a lowercase English letters in such a way that there is exactly one occurrence of a string \"abacaba\" in the resulting string as a substring output \"No\".\n\nOtherwise output \"Yes\" and in the next line output a resulting string consisting of $n$ lowercase English letters. If there are multiple possible strings, output any.\n\nYou may print every letter in \"Yes\" and \"No\" in any case you want (so, for example, the strings yEs, yes, Yes, and YES will all be recognized as positive answer).\n\n\n-----Example-----\nInput\n6\n7\nabacaba\n7\n???????\n11\naba?abacaba\n11\nabacaba?aba\n15\nasdf???f???qwer\n11\nabacabacaba\n\nOutput\nYes\nabacaba\nYes\nabacaba\nYes\nabadabacaba\nYes\nabacabadaba\nNo\nNo\n\n\n\n-----Note-----\n\nIn first example there is exactly one occurrence of a string \"abacaba\" in the string \"abacaba\" as a substring.\n\nIn second example seven question marks can be replaced with any seven lowercase English letters and with \"abacaba\" in particular.\n\nIn sixth example there are two occurrences of a string \"abacaba\" as a substring.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nimport sys\nINF = 10**20\nMOD = 10**9 + 7\nI = lambda:list(map(int,input().split()))\nfrom math import gcd\nfrom math import ceil\nfrom collections import defaultdict as dd, Counter\nfrom bisect import bisect_left as bl, bisect_right as br\n\n\n\"\"\"\nFacts and Data representation\nConstructive? Top bottom up down\n\"\"\"\ndef check(s):\n t = 'abacaba'\n ans = 0\n for i in range(len(s)):\n if s[i: i + 7] == t:\n ans += 1\n return ans\n\ndef solve():\n n, = I()\n s = input()\n t = 'abacaba'\n cnt = check(s)\n if cnt > 1:\n print('No')\n return\n elif cnt == 1:\n s = list(s)\n for i in range(n):\n if s[i] == '?':\n s[i] = 'z'\n print('Yes')\n print(''.join(s))\n else:\n s = list(s)\n ok = s[::]\n for i in range(n - 6):\n ok = s[::]\n for j in range(7):\n if s[i + j] == t[j]:\n continue\n elif s[i + j] == '?':\n ok[i + j] = t[j]\n else:\n break\n else:\n for i in range(n):\n if ok[i] == '?':\n ok[i] = 'z'\n ok = ''.join(ok)\n if check(ok) != 1:\n continue\n print('Yes')\n print(ok)\n return\n print('No')\n\nt, = I()\nwhile t:\n t -= 1\n solve()\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '6\\n7\\nabacaba\\n7\\n???????\\n11\\naba?abacaba\\n11\\nabacaba?aba\\n15\\nasdf???f???qwer\\n11\\nabacabacaba\\n', 'output': 'Yes\\nabacaba\\nYes\\nabacaba\\nYes\\nabazabacaba\\nYes\\nabacabazaba\\nNo\\nNo\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/1379/A'}","problem_id":"vfc_112","program":"```python\nimport sys\nINF = 10**20\nMOD = 10**9 + 7\nI = lambda:list(map(int,input().split()))\nfrom math import gcd\nfrom math import ceil\nfrom collections import defaultdict as dd, Counter\nfrom bisect import bisect_left as bl, bisect_right as br\n\n\n\"\"\"\nFacts and Data representation\nConstructive? Top bottom up down\n\"\"\"\ndef check(s):\n t = 'abacaba'\n ans = 0\n for i in range(len(s)):\n if s[i: i + 7] == t:\n ans += 1\n return ans\n\ndef solve():\n n, = I()\n s = input()\n t = 'abacaba'\n cnt = check(s)\n if cnt > 1:\n print('No')\n return\n elif cnt == 1:\n s = list(s)\n for i in range(n):\n if s[i] == '?':\n s[i] = 'z'\n print('Yes')\n print(''.join(s))\n else:\n s = list(s)\n ok = s[::]\n for i in range(n - 6):\n ok = s[::]\n for j in range(7):\n if s[i + j] == t[j]:\n continue\n elif s[i + j] == '?':\n ok[i + j] = t[j]\n else:\n break\n else:\n for i in range(n):\n if ok[i] == '?':\n ok[i] = 'z'\n ok = ''.join(ok)\n if check(ok) != 1:\n continue\n print('Yes')\n print(ok)\n return\n print('No')\n\nt, = I()\nwhile t:\n t -= 1\n solve()\n```","inputs":"6\n7\nabacaba\n7\n???????\n11\naba?abacaba\n11\nabacaba?aba\n15\nasdf???f???qwer\n11\nabacabacaba\n","output":"Yes\nabacaba\nYes\nabacaba\nYes\nabazabacaba\nYes\nabacabazaba\nNo\nNo\n","actual_output":"Yes\nabacaba\nYes\nabacaba\nYes\nabazabacaba\nYes\nabacabazaba\nNo\nNo\n","execution_success":true,"sample_index":29},{"source":"apps","task_type":"verifiable_code","in_source_id":"30","prompt":"Solve the following coding problem using the programming language python:\n\nYou are given a string $s$ of even length $n$. String $s$ is binary, in other words, consists only of 0's and 1's.\n\nString $s$ has exactly $\\frac{n}{2}$ zeroes and $\\frac{n}{2}$ ones ($n$ is even).\n\nIn one operation you can reverse any substring of $s$. A substring of a string is a contiguous subsequence of that string.\n\nWhat is the minimum number of operations you need to make string $s$ alternating? A string is alternating if $s_i \\neq s_{i + 1}$ for all $i$. There are two types of alternating strings in general: 01010101... or 10101010...\n\n\n-----Input-----\n\nThe first line contains a single integer $t$ ($1 \\le t \\le 1000$)\u00a0\u2014 the number of test cases.\n\nThe first line of each test case contains a single integer $n$ ($2 \\le n \\le 10^5$; $n$ is even)\u00a0\u2014 the length of string $s$.\n\nThe second line of each test case contains a binary string $s$ of length $n$ ($s_i \\in$ {0, 1}). String $s$ has exactly $\\frac{n}{2}$ zeroes and $\\frac{n}{2}$ ones.\n\nIt's guaranteed that the total sum of $n$ over test cases doesn't exceed $10^5$.\n\n\n-----Output-----\n\nFor each test case, print the minimum number of operations to make $s$ alternating.\n\n\n-----Example-----\nInput\n3\n2\n10\n4\n0110\n8\n11101000\n\nOutput\n0\n1\n2\n\n\n\n-----Note-----\n\nIn the first test case, string 10 is already alternating.\n\nIn the second test case, we can, for example, reverse the last two elements of $s$ and get: 0110 $\\rightarrow$ 0101.\n\nIn the third test case, we can, for example, make the following two operations: 11101000 $\\rightarrow$ 10101100; 10101100 $\\rightarrow$ 10101010.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nt = int(input())\nfor i in range(t):\n n = int(input())\n s = input()\n ans = 0\n for y in range(1, n):\n if s[y] == s[y-1]:\n ans += 1\n print((ans + ans % 2) // 2)\n \n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\n2\\n10\\n4\\n0110\\n8\\n11101000\\n', 'output': '0\\n1\\n2\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/1437/B'}","problem_id":"vfc_120","program":"```python\nt = int(input())\nfor i in range(t):\n n = int(input())\n s = input()\n ans = 0\n for y in range(1, n):\n if s[y] == s[y-1]:\n ans += 1\n print((ans + ans % 2) // 2)\n \n\n```","inputs":"3\n2\n10\n4\n0110\n8\n11101000\n","output":"0\n1\n2\n","actual_output":"0\n1\n2\n","execution_success":true,"sample_index":31},{"source":"apps","task_type":"verifiable_code","in_source_id":"31","prompt":"Solve the following coding problem using the programming language python:\n\nSkier rides on a snowy field. Its movements can be described by a string of characters 'S', 'N', 'W', 'E' (which correspond to $1$ meter movement in the south, north, west or east direction respectively).\n\nIt is known that if he moves along a previously unvisited segment of a path (i.e. this segment of the path is visited the first time), then the time of such movement is $5$ seconds. If he rolls along previously visited segment of a path (i.e., this segment of the path has been covered by his path before), then it takes $1$ second.\n\nFind the skier's time to roll all the path.\n\n\n-----Input-----\n\nThe first line contains an integer $t$ ($1 \\le t \\le 10^4$) \u2014 the number of test cases in the input. Then $t$ test cases follow.\n\nEach set is given by one nonempty string of the characters 'S', 'N', 'W', 'E'. The length of the string does not exceed $10^5$ characters.\n\nThe sum of the lengths of $t$ given lines over all test cases in the input does not exceed $10^5$.\n\n\n-----Output-----\n\nFor each test case, print the desired path time in seconds.\n\n\n-----Example-----\nInput\n5\nNNN\nNS\nWWEN\nWWEE\nNWNWS\n\nOutput\n15\n6\n16\n12\n25\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nDIR = {\"N\": (0, 1), \"S\": (0, -1), \"W\": (-1, 0), \"E\": (1, 0)}\n\nfor t in range(int(input())):\n path = input()\n tracks = set()\n x, y = 0, 0\n time = 0\n for char in path:\n x1 = x + DIR[char][0]\n y1 = y + DIR[char][1]\n if (x, y, x1, y1) in tracks or (x1, y1, x, y) in tracks:\n time += 1\n else:\n time += 5\n tracks.add((x, y, x1, y1))\n x, y = x1, y1\n print(time)\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '5\\nNNN\\nNS\\nWWEN\\nWWEE\\nNWNWS\\n', 'output': '15\\n6\\n16\\n12\\n25\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/1351/C'}","problem_id":"vfc_124","program":"```python\nDIR = {\"N\": (0, 1), \"S\": (0, -1), \"W\": (-1, 0), \"E\": (1, 0)}\n\nfor t in range(int(input())):\n path = input()\n tracks = set()\n x, y = 0, 0\n time = 0\n for char in path:\n x1 = x + DIR[char][0]\n y1 = y + DIR[char][1]\n if (x, y, x1, y1) in tracks or (x1, y1, x, y) in tracks:\n time += 1\n else:\n time += 5\n tracks.add((x, y, x1, y1))\n x, y = x1, y1\n print(time)\n\n```","inputs":"5\nNNN\nNS\nWWEN\nWWEE\nNWNWS\n","output":"15\n6\n16\n12\n25\n","actual_output":"15\n6\n16\n12\n25\n","execution_success":true,"sample_index":32},{"source":"apps","task_type":"verifiable_code","in_source_id":"32","prompt":"Solve the following coding problem using the programming language python:\n\nLately, Mr. Chanek frequently plays the game Arena of Greed. As the name implies, the game's goal is to find the greediest of them all, who will then be crowned king of Compfestnesia.\n\nThe game is played by two people taking turns, where Mr. Chanek takes the first turn. Initially, there is a treasure chest containing $N$ gold coins. The game ends if there are no more gold coins in the chest. In each turn, the players can make one of the following moves: Take one gold coin from the chest. Take half of the gold coins on the chest. This move is only available if the number of coins in the chest is even. \n\nBoth players will try to maximize the number of coins they have. Mr. Chanek asks your help to find the maximum number of coins he can get at the end of the game if both he and the opponent plays optimally.\n\n\n-----Input-----\n\nThe first line contains a single integer $T$ $(1 \\le T \\le 10^5)$ denotes the number of test cases.\n\nThe next $T$ lines each contain a single integer $N$ $(1 \\le N \\le 10^{18})$.\n\n\n-----Output-----\n\n$T$ lines, each line is the answer requested by Mr. Chanek.\n\n\n-----Example-----\nInput\n2\n5\n6\n\nOutput\n2\n4\n\n\n\n-----Note-----\n\nFor the first case, the game is as follows: Mr. Chanek takes one coin. The opponent takes two coins. Mr. Chanek takes one coin. The opponent takes one coin. \n\nFor the second case, the game is as follows: Mr. Chanek takes three coins. The opponent takes one coin. Mr. Chanek takes one coin. The opponent takes one coin.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfrom sys import stdin, stdout\nfrom collections import defaultdict\ninput = stdin.readline\nfor _ in range(int(input())):\n\tn = int(input())\n\tchanek = 0\n\tflag = 1\n\twhile n>0:\n\t\tif n%4==0 and n!=4:\n\t\t\tif flag:\n\t\t\t\tchanek += 1\n\t\t\t\tn-=1\n\t\t\t\tflag = 0\n\t\t\telse:\n\t\t\t\tn-=1\n\t\t\t\tflag = 1\n\t\telif n%2:\n\t\t\tif flag:\n\t\t\t\tchanek += 1\n\t\t\t\tn-=1\n\t\t\t\tflag = 0\n\t\t\telse:\n\t\t\t\tn-=1\n\t\t\t\tflag = 1\n\t\telse:\n\t\t\tif flag:\n\t\t\t\tchanek += n//2\n\t\t\t\tn//=2\n\t\t\t\tflag = 0\n\t\t\telse:\n\t\t\t\tn//=2\n\t\t\t\tflag = 1\n\tprint(chanek)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n5\\n6\\n', 'output': '2\\n4\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/1425/A'}","problem_id":"vfc_128","program":"```python\nfrom sys import stdin, stdout\nfrom collections import defaultdict\ninput = stdin.readline\nfor _ in range(int(input())):\n\tn = int(input())\n\tchanek = 0\n\tflag = 1\n\twhile n>0:\n\t\tif n%4==0 and n!=4:\n\t\t\tif flag:\n\t\t\t\tchanek += 1\n\t\t\t\tn-=1\n\t\t\t\tflag = 0\n\t\t\telse:\n\t\t\t\tn-=1\n\t\t\t\tflag = 1\n\t\telif n%2:\n\t\t\tif flag:\n\t\t\t\tchanek += 1\n\t\t\t\tn-=1\n\t\t\t\tflag = 0\n\t\t\telse:\n\t\t\t\tn-=1\n\t\t\t\tflag = 1\n\t\telse:\n\t\t\tif flag:\n\t\t\t\tchanek += n//2\n\t\t\t\tn//=2\n\t\t\t\tflag = 0\n\t\t\telse:\n\t\t\t\tn//=2\n\t\t\t\tflag = 1\n\tprint(chanek)\n```","inputs":"2\n5\n6\n","output":"2\n4\n","actual_output":"2\n4\n","execution_success":true,"sample_index":33},{"source":"apps","task_type":"verifiable_code","in_source_id":"34","prompt":"Solve the following coding problem using the programming language python:\n\nYou have a large electronic screen which can display up to $998244353$ decimal digits. The digits are displayed in the same way as on different electronic alarm clocks: each place for a digit consists of $7$ segments which can be turned on and off to compose different digits. The following picture describes how you can display all $10$ decimal digits:\n\n[Image]\n\nAs you can see, different digits may require different number of segments to be turned on. For example, if you want to display $1$, you have to turn on $2$ segments of the screen, and if you want to display $8$, all $7$ segments of some place to display a digit should be turned on.\n\nYou want to display a really large integer on the screen. Unfortunately, the screen is bugged: no more than $n$ segments can be turned on simultaneously. So now you wonder what is the greatest integer that can be displayed by turning on no more than $n$ segments.\n\nYour program should be able to process $t$ different test cases.\n\n\n-----Input-----\n\nThe first line contains one integer $t$ ($1 \\le t \\le 100$) \u2014 the number of test cases in the input.\n\nThen the test cases follow, each of them is represented by a separate line containing one integer $n$ ($2 \\le n \\le 10^5$) \u2014 the maximum number of segments that can be turned on in the corresponding testcase.\n\nIt is guaranteed that the sum of $n$ over all test cases in the input does not exceed $10^5$.\n\n\n-----Output-----\n\nFor each test case, print the greatest integer that can be displayed by turning on no more than $n$ segments of the screen. Note that the answer may not fit in the standard $32$-bit or $64$-bit integral data type.\n\n\n-----Example-----\nInput\n2\n3\n4\n\nOutput\n7\n11\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfor _ in range(int(input())):\n\tn = int(input())\n\tif(n%2):\n\t\tprint(\"7\"+\"1\"*((n-3)//2))\n\telse:\n\t\tprint(\"1\"*(n//2))\t\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n3\\n4\\n', 'output': '7\\n11\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/1295/A'}","problem_id":"vfc_136","program":"```python\nfor _ in range(int(input())):\n\tn = int(input())\n\tif(n%2):\n\t\tprint(\"7\"+\"1\"*((n-3)//2))\n\telse:\n\t\tprint(\"1\"*(n//2))\t\n```","inputs":"2\n3\n4\n","output":"7\n11\n","actual_output":"7\n11\n","execution_success":true,"sample_index":35},{"source":"apps","task_type":"verifiable_code","in_source_id":"35","prompt":"Solve the following coding problem using the programming language python:\n\nYoung wilderness explorers set off to their first expedition led by senior explorer Russell. Explorers went into a forest, set up a camp and decided to split into groups to explore as much interesting locations as possible. Russell was trying to form groups, but ran into some difficulties...\n\nMost of the young explorers are inexperienced, and sending them alone would be a mistake. Even Russell himself became senior explorer not long ago. Each of young explorers has a positive integer parameter $e_i$\u00a0\u2014 his inexperience. Russell decided that an explorer with inexperience $e$ can only join the group of $e$ or more people.\n\nNow Russell needs to figure out how many groups he can organize. It's not necessary to include every explorer in one of the groups: some can stay in the camp. Russell is worried about this expedition, so he asked you to help him.\n\n\n-----Input-----\n\nThe first line contains the number of independent test cases $T$($1 \\leq T \\leq 2 \\cdot 10^5$). Next $2T$ lines contain description of test cases.\n\nThe first line of description of each test case contains the number of young explorers $N$ ($1 \\leq N \\leq 2 \\cdot 10^5$).\n\nThe second line contains $N$ integers $e_1, e_2, \\ldots, e_N$ ($1 \\leq e_i \\leq N$), where $e_i$ is the inexperience of the $i$-th explorer.\n\nIt's guaranteed that sum of all $N$ doesn't exceed $3 \\cdot 10^5$.\n\n\n-----Output-----\n\nPrint $T$ numbers, each number on a separate line.\n\nIn $i$-th line print the maximum number of groups Russell can form in $i$-th test case.\n\n\n-----Example-----\nInput\n2\n3\n1 1 1\n5\n2 3 1 2 2\n\nOutput\n3\n2\n\n\n\n-----Note-----\n\nIn the first example we can organize three groups. There will be only one explorer in each group. It's correct because inexperience of each explorer equals to $1$, so it's not less than the size of his group.\n\nIn the second example we can organize two groups. Explorers with inexperience $1$, $2$ and $3$ will form the first group, and the other two explorers with inexperience equal to $2$ will form the second group.\n\nThis solution is not unique. For example, we can form the first group using the three explorers with inexperience equal to $2$, and the second group using only one explorer with inexperience equal to $1$. In this case the young explorer with inexperience equal to $3$ will not be included in any group.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nimport sys\n\ninput=sys.stdin.readline\n\nfor _ in range(int(input())):\n N=int(input())\n e=list(map(int,input().split()))\n e.sort()\n ans=0\n val=0\n g=0\n for i in range(0,N):\n g+=1\n val=e[i]\n if g>=val:\n ans+=1\n g=0\n val=0\n print(ans)\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n3\\n1 1 1\\n5\\n2 3 1 2 2\\n', 'output': '3\\n2\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/1355/B'}","problem_id":"vfc_140","program":"```python\nimport sys\n\ninput=sys.stdin.readline\n\nfor _ in range(int(input())):\n N=int(input())\n e=list(map(int,input().split()))\n e.sort()\n ans=0\n val=0\n g=0\n for i in range(0,N):\n g+=1\n val=e[i]\n if g>=val:\n ans+=1\n g=0\n val=0\n print(ans)\n\n```","inputs":"2\n3\n1 1 1\n5\n2 3 1 2 2\n","output":"3\n2\n","actual_output":"3\n2\n","execution_success":true,"sample_index":36},{"source":"apps","task_type":"verifiable_code","in_source_id":"36","prompt":"Solve the following coding problem using the programming language python:\n\nIt is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.\n\nMarmot brought Mole n ordered piles of worms such that i-th pile contains a_{i} worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a_1, worms in second pile are labeled with numbers a_1 + 1 to a_1 + a_2 and so on. See the example for a better understanding.\n\nMole can't eat all the worms (Marmot brought a lot) and, as we all know, Mole is blind, so Marmot tells him the labels of the best juicy worms. Marmot will only give Mole a worm if Mole says correctly in which pile this worm is contained.\n\nPoor Mole asks for your help. For all juicy worms said by Marmot, tell Mole the correct answers.\n\n\n-----Input-----\n\nThe first line contains a single integer n (1 \u2264 n \u2264 10^5), the number of piles.\n\nThe second line contains n integers a_1, a_2, ..., a_{n} (1 \u2264 a_{i} \u2264 10^3, a_1 + a_2 + ... + a_{n} \u2264 10^6), where a_{i} is the number of worms in the i-th pile.\n\nThe third line contains single integer m (1 \u2264 m \u2264 10^5), the number of juicy worms said by Marmot.\n\nThe fourth line contains m integers q_1, q_2, ..., q_{m} (1 \u2264 q_{i} \u2264 a_1 + a_2 + ... + a_{n}), the labels of the juicy worms.\n\n\n-----Output-----\n\nPrint m lines to the standard output. The i-th line should contain an integer, representing the number of the pile where the worm labeled with the number q_{i} is.\n\n\n-----Examples-----\nInput\n5\n2 7 3 4 9\n3\n1 25 11\n\nOutput\n1\n5\n3\n\n\n\n-----Note-----\n\nFor the sample input:\n\n The worms with labels from [1, 2] are in the first pile. The worms with labels from [3, 9] are in the second pile. The worms with labels from [10, 12] are in the third pile. The worms with labels from [13, 16] are in the fourth pile. The worms with labels from [17, 25] are in the fifth pile.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nn=int(input())\na=list(map(int,input().split()))\nk=[]\nfor i in range(n):\n for j in range(a[i]):\n k.append(i+1)\nm=int(input())\nb=list(map(int,input().split()))\nfor i in b:\n print(k[i-1])\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '5\\n2 7 3 4 9\\n3\\n1 25 11\\n', 'output': '1\\n5\\n3\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/474/B'}","problem_id":"vfc_144","program":"```python\nn=int(input())\na=list(map(int,input().split()))\nk=[]\nfor i in range(n):\n for j in range(a[i]):\n k.append(i+1)\nm=int(input())\nb=list(map(int,input().split()))\nfor i in b:\n print(k[i-1])\n```","inputs":"5\n2 7 3 4 9\n3\n1 25 11\n","output":"1\n5\n3\n","actual_output":"1\n5\n3\n","execution_success":true,"sample_index":37},{"source":"apps","task_type":"verifiable_code","in_source_id":"38","prompt":"Solve the following coding problem using the programming language python:\n\nTwo players decided to play one interesting card game.\n\nThere is a deck of $n$ cards, with values from $1$ to $n$. The values of cards are pairwise different (this means that no two different cards have equal values). At the beginning of the game, the deck is completely distributed between players such that each player has at least one card. \n\nThe game goes as follows: on each turn, each player chooses one of their cards (whichever they want) and puts on the table, so that the other player doesn't see which card they chose. After that, both cards are revealed, and the player, value of whose card was larger, takes both cards in his hand. Note that as all cards have different values, one of the cards will be strictly larger than the other one. Every card may be played any amount of times. The player loses if he doesn't have any cards.\n\nFor example, suppose that $n = 5$, the first player has cards with values $2$ and $3$, and the second player has cards with values $1$, $4$, $5$. Then one possible flow of the game is:\n\nThe first player chooses the card $3$. The second player chooses the card $1$. As $3>1$, the first player gets both cards. Now the first player has cards $1$, $2$, $3$, the second player has cards $4$, $5$.\n\nThe first player chooses the card $3$. The second player chooses the card $4$. As $3<4$, the second player gets both cards. Now the first player has cards $1$, $2$. The second player has cards $3$, $4$, $5$.\n\nThe first player chooses the card $1$. The second player chooses the card $3$. As $1<3$, the second player gets both cards. Now the first player has only the card $2$. The second player has cards $1$, $3$, $4$, $5$.\n\nThe first player chooses the card $2$. The second player chooses the card $4$. As $2<4$, the second player gets both cards. Now the first player is out of cards and loses. Therefore, the second player wins.\n\nWho will win if both players are playing optimally? It can be shown that one of the players has a winning strategy.\n\n\n-----Input-----\n\nEach test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \\le t \\le 100$). The description of the test cases follows.\n\nThe first line of each test case contains three integers $n$, $k_1$, $k_2$ ($2 \\le n \\le 100, 1 \\le k_1 \\le n - 1, 1 \\le k_2 \\le n - 1, k_1 + k_2 = n$)\u00a0\u2014 the number of cards, number of cards owned by the first player and second player correspondingly.\n\nThe second line of each test case contains $k_1$ integers $a_1, \\dots, a_{k_1}$ ($1 \\le a_i \\le n$)\u00a0\u2014 the values of cards of the first player.\n\nThe third line of each test case contains $k_2$ integers $b_1, \\dots, b_{k_2}$ ($1 \\le b_i \\le n$)\u00a0\u2014 the values of cards of the second player.\n\nIt is guaranteed that the values of all cards are different.\n\n\n-----Output-----\n\nFor each test case, output \"YES\" in a separate line, if the first player wins. Otherwise, output \"NO\" in a separate line. You can print each letter in any case (upper or lower).\n\n\n-----Example-----\nInput\n2\n2 1 1\n2\n1\n5 2 3\n2 3\n1 4 5\n\nOutput\nYES\nNO\n\n\n\n-----Note-----\n\nIn the first test case of the example, there is only one possible move for every player: the first player will put $2$, the second player will put $1$. $2>1$, so the first player will get both cards and will win.\n\nIn the second test case of the example, it can be shown that it is the second player who has a winning strategy. One possible flow of the game is illustrated in the statement.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nq = int(input())\nfor z in range(q):\n n, k1, k2 = map(int, input().split())\n arr1 = list(map(int, input().split()))\n arr2 = list(map(int, input().split()))\n if max(arr1) > max(arr2):\n print('YES')\n else:\n print('NO')\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n2 1 1\\n2\\n1\\n5 2 3\\n2 3\\n1 4 5\\n', 'output': 'YES\\nNO\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/1270/A'}","problem_id":"vfc_152","program":"```python\nq = int(input())\nfor z in range(q):\n n, k1, k2 = map(int, input().split())\n arr1 = list(map(int, input().split()))\n arr2 = list(map(int, input().split()))\n if max(arr1) > max(arr2):\n print('YES')\n else:\n print('NO')\n```","inputs":"2\n2 1 1\n2\n1\n5 2 3\n2 3\n1 4 5\n","output":"YES\nNO\n","actual_output":"YES\nNO\n","execution_success":true,"sample_index":39},{"source":"apps","task_type":"verifiable_code","in_source_id":"39","prompt":"Solve the following coding problem using the programming language python:\n\nAfter a long party Petya decided to return home, but he turned out to be at the opposite end of the town from his home. There are $n$ crossroads in the line in the town, and there is either the bus or the tram station at each crossroad.\n\nThe crossroads are represented as a string $s$ of length $n$, where $s_i = \\texttt{A}$, if there is a bus station at $i$-th crossroad, and $s_i = \\texttt{B}$, if there is a tram station at $i$-th crossroad. Currently Petya is at the first crossroad (which corresponds to $s_1$) and his goal is to get to the last crossroad (which corresponds to $s_n$).\n\nIf for two crossroads $i$ and $j$ for all crossroads $i, i+1, \\ldots, j-1$ there is a bus station, one can pay $a$ roubles for the bus ticket, and go from $i$-th crossroad to the $j$-th crossroad by the bus (it is not necessary to have a bus station at the $j$-th crossroad). Formally, paying $a$ roubles Petya can go from $i$ to $j$ if $s_t = \\texttt{A}$ for all $i \\le t < j$. \n\nIf for two crossroads $i$ and $j$ for all crossroads $i, i+1, \\ldots, j-1$ there is a tram station, one can pay $b$ roubles for the tram ticket, and go from $i$-th crossroad to the $j$-th crossroad by the tram (it is not necessary to have a tram station at the $j$-th crossroad). Formally, paying $b$ roubles Petya can go from $i$ to $j$ if $s_t = \\texttt{B}$ for all $i \\le t < j$.\n\nFor example, if $s$=\"AABBBAB\", $a=4$ and $b=3$ then Petya needs:[Image] buy one bus ticket to get from $1$ to $3$, buy one tram ticket to get from $3$ to $6$, buy one bus ticket to get from $6$ to $7$. \n\nThus, in total he needs to spend $4+3+4=11$ roubles. Please note that the type of the stop at the last crossroad (i.e. the character $s_n$) does not affect the final expense.\n\nNow Petya is at the first crossroad, and he wants to get to the $n$-th crossroad. After the party he has left with $p$ roubles. He's decided to go to some station on foot, and then go to home using only public transport.\n\nHelp him to choose the closest crossroad $i$ to go on foot the first, so he has enough money to get from the $i$-th crossroad to the $n$-th, using only tram and bus tickets.\n\n\n-----Input-----\n\nEach test contains one or more test cases. The first line contains the number of test cases $t$ ($1 \\le t \\le 10^4$).\n\nThe first line of each test case consists of three integers $a, b, p$ ($1 \\le a, b, p \\le 10^5$)\u00a0\u2014 the cost of bus ticket, the cost of tram ticket and the amount of money Petya has.\n\nThe second line of each test case consists of one string $s$, where $s_i = \\texttt{A}$, if there is a bus station at $i$-th crossroad, and $s_i = \\texttt{B}$, if there is a tram station at $i$-th crossroad ($2 \\le |s| \\le 10^5$).\n\nIt is guaranteed, that the sum of the length of strings $s$ by all test cases in one test doesn't exceed $10^5$.\n\n\n-----Output-----\n\nFor each test case print one number\u00a0\u2014 the minimal index $i$ of a crossroad Petya should go on foot. The rest of the path (i.e. from $i$ to $n$ he should use public transport).\n\n\n-----Example-----\nInput\n5\n2 2 1\nBB\n1 1 1\nAB\n3 2 8\nAABBBBAABB\n5 3 4\nBBBBB\n2 1 1\nABABAB\n\nOutput\n2\n1\n3\n1\n6\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nt=int(input())\n\nfor tt in range(t):\n a,b,p=map(int,input().split())\n s=input()\n n=len(s)\n cost = [0]*n\n cost[-1] = 0\n typ = ''\n i=n-2\n while i>=0:\n if s[i]==typ:\n cost[i] = cost[i+1]\n else:\n typ = s[i]\n cost[i] = cost[i+1] + (a if typ=='A' else b)\n i-=1\n i=0\n while cost[i] > p:\n i+=1\n print(i+1)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '5\\n2 2 1\\nBB\\n1 1 1\\nAB\\n3 2 8\\nAABBBBAABB\\n5 3 4\\nBBBBB\\n2 1 1\\nABABAB\\n', 'output': '2\\n1\\n3\\n1\\n6\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/1315/B'}","problem_id":"vfc_156","program":"```python\nt=int(input())\n\nfor tt in range(t):\n a,b,p=map(int,input().split())\n s=input()\n n=len(s)\n cost = [0]*n\n cost[-1] = 0\n typ = ''\n i=n-2\n while i>=0:\n if s[i]==typ:\n cost[i] = cost[i+1]\n else:\n typ = s[i]\n cost[i] = cost[i+1] + (a if typ=='A' else b)\n i-=1\n i=0\n while cost[i] > p:\n i+=1\n print(i+1)\n```","inputs":"5\n2 2 1\nBB\n1 1 1\nAB\n3 2 8\nAABBBBAABB\n5 3 4\nBBBBB\n2 1 1\nABABAB\n","output":"2\n1\n3\n1\n6\n","actual_output":"2\n1\n3\n1\n6\n","execution_success":true,"sample_index":40},{"source":"apps","task_type":"verifiable_code","in_source_id":"40","prompt":"Solve the following coding problem using the programming language python:\n\nYou are given a sequence $a_1, a_2, \\dots, a_n$, consisting of integers.\n\nYou can apply the following operation to this sequence: choose some integer $x$ and move all elements equal to $x$ either to the beginning, or to the end of $a$. Note that you have to move all these elements in one direction in one operation.\n\nFor example, if $a = [2, 1, 3, 1, 1, 3, 2]$, you can get the following sequences in one operation (for convenience, denote elements equal to $x$ as $x$-elements): $[1, 1, 1, 2, 3, 3, 2]$ if you move all $1$-elements to the beginning; $[2, 3, 3, 2, 1, 1, 1]$ if you move all $1$-elements to the end; $[2, 2, 1, 3, 1, 1, 3]$ if you move all $2$-elements to the beginning; $[1, 3, 1, 1, 3, 2, 2]$ if you move all $2$-elements to the end; $[3, 3, 2, 1, 1, 1, 2]$ if you move all $3$-elements to the beginning; $[2, 1, 1, 1, 2, 3, 3]$ if you move all $3$-elements to the end; \n\nYou have to determine the minimum number of such operations so that the sequence $a$ becomes sorted in non-descending order. Non-descending order means that for all $i$ from $2$ to $n$, the condition $a_{i-1} \\le a_i$ is satisfied.\n\nNote that you have to answer $q$ independent queries.\n\n\n-----Input-----\n\nThe first line contains one integer $q$ ($1 \\le q \\le 3 \\cdot 10^5$)\u00a0\u2014 the number of the queries. Each query is represented by two consecutive lines.\n\nThe first line of each query contains one integer $n$ ($1 \\le n \\le 3 \\cdot 10^5$)\u00a0\u2014 the number of elements.\n\nThe second line of each query contains $n$ integers $a_1, a_2, \\dots , a_n$ ($1 \\le a_i \\le n$)\u00a0\u2014 the elements.\n\nIt is guaranteed that the sum of all $n$ does not exceed $3 \\cdot 10^5$.\n\n\n-----Output-----\n\nFor each query print one integer\u00a0\u2014 the minimum number of operation for sorting sequence $a$ in non-descending order.\n\n\n-----Example-----\nInput\n3\n7\n3 1 6 6 3 1 1\n8\n1 1 4 4 4 7 8 8\n7\n4 2 5 2 6 2 7\n\nOutput\n2\n0\n1\n\n\n\n-----Note-----\n\nIn the first query, you can move all $1$-elements to the beginning (after that sequence turn into $[1, 1, 1, 3, 6, 6, 3]$) and then move all $6$-elements to the end.\n\nIn the second query, the sequence is sorted initially, so the answer is zero.\n\nIn the third query, you have to move all $2$-elements to the beginning.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\ndef main():\n from sys import stdin, stdout\n for _ in range(int(stdin.readline())):\n n = int(stdin.readline())\n inp1 = [-1] * (n + 1)\n inp2 = [-1] * (n + 1)\n for i, ai in enumerate(map(int, stdin.readline().split())):\n if inp1[ai] < 0:\n inp1[ai] = i\n inp2[ai] = i\n inp1 = tuple((inp1i for inp1i in inp1 if inp1i >= 0))\n inp2 = tuple((inp2i for inp2i in inp2 if inp2i >= 0))\n n = len(inp1)\n ans = 0\n cur = 0\n for i in range(n):\n if i and inp1[i] < inp2[i - 1]:\n cur = 1\n else:\n cur += 1\n ans = max(ans, cur)\n stdout.write(f'{n - ans}\\n')\n\n\nmain()\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\n7\\n3 1 6 6 3 1 1\\n8\\n1 1 4 4 4 7 8 8\\n7\\n4 2 5 2 6 2 7\\n', 'output': '2\\n0\\n1\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/1223/D'}","problem_id":"vfc_160","program":"```python\ndef main():\n from sys import stdin, stdout\n for _ in range(int(stdin.readline())):\n n = int(stdin.readline())\n inp1 = [-1] * (n + 1)\n inp2 = [-1] * (n + 1)\n for i, ai in enumerate(map(int, stdin.readline().split())):\n if inp1[ai] < 0:\n inp1[ai] = i\n inp2[ai] = i\n inp1 = tuple((inp1i for inp1i in inp1 if inp1i >= 0))\n inp2 = tuple((inp2i for inp2i in inp2 if inp2i >= 0))\n n = len(inp1)\n ans = 0\n cur = 0\n for i in range(n):\n if i and inp1[i] < inp2[i - 1]:\n cur = 1\n else:\n cur += 1\n ans = max(ans, cur)\n stdout.write(f'{n - ans}\\n')\n\n\nmain()\n\n```","inputs":"3\n7\n3 1 6 6 3 1 1\n8\n1 1 4 4 4 7 8 8\n7\n4 2 5 2 6 2 7\n","output":"2\n0\n1\n","actual_output":"2\n0\n1\n","execution_success":true,"sample_index":41},{"source":"apps","task_type":"verifiable_code","in_source_id":"41","prompt":"Solve the following coding problem using the programming language python:\n\nYou are fed up with your messy room, so you decided to clean it up.\n\nYour room is a bracket sequence $s=s_{1}s_{2}\\dots s_{n}$ of length $n$. Each character of this string is either an opening bracket '(' or a closing bracket ')'.\n\nIn one operation you can choose any consecutive substring of $s$ and reverse it. In other words, you can choose any substring $s[l \\dots r]=s_l, s_{l+1}, \\dots, s_r$ and change the order of elements in it into $s_r, s_{r-1}, \\dots, s_{l}$.\n\nFor example, if you will decide to reverse substring $s[2 \\dots 4]$ of string $s=$\"((()))\" it will be equal to $s=$\"()(())\".\n\nA regular (aka balanced) bracket sequence is a bracket sequence that can be transformed into a correct arithmetic expression by inserting characters '1' and '+' between the original characters of the sequence. For example, bracket sequences \"()()\", \"(())\" are regular (the resulting expressions are: \"(1)+(1)\", \"((1+1)+1)\"), and \")(\" and \"(\" are not.\n\nA prefix of a string $s$ is a substring that starts at position $1$. For example, for $s=$\"(())()\" there are $6$ prefixes: \"(\", \"((\", \"(()\", \"(())\", \"(())(\" and \"(())()\".\n\nIn your opinion, a neat and clean room $s$ is a bracket sequence that:\n\n the whole string $s$ is a regular bracket sequence; and there are exactly $k$ prefixes of this sequence which are regular (including whole $s$ itself). \n\nFor example, if $k = 2$, then \"(())()\" is a neat and clean room.\n\nYou want to use at most $n$ operations to make your room neat and clean. Operations are applied one after another sequentially.\n\nIt is guaranteed that the answer exists. Note that you do not need to minimize the number of operations: find any way to achieve the desired configuration in $n$ or less operations.\n\n\n-----Input-----\n\nThe first line contains integer number $t$ ($1 \\le t \\le 100$)\u00a0\u2014 the number of test cases in the input. Then $t$ test cases follow.\n\nThe first line of a test case contains two integers $n$ and $k$ ($1 \\le k \\le \\frac{n}{2}, 2 \\le n \\le 2000$, $n$ is even)\u00a0\u2014 length of $s$ and required number of regular prefixes.\n\nThe second line of a test case contains $s$ of length $n$\u00a0\u2014 the given bracket sequence. It contains only '(' and ')'.\n\nIt is guaranteed that there are exactly $\\frac{n}{2}$ characters '(' and exactly $\\frac{n}{2}$ characters ')' in the given string.\n\nThe sum of all values $n$ over all the test cases in the input doesn't exceed $2000$.\n\n\n-----Output-----\n\nFor each test case print an answer.\n\nIn the first line print integer $m$ ($0 \\le m \\le n$)\u00a0\u2014 the number of operations. You do not need to minimize $m$, any value is suitable.\n\nIn the following $m$ lines print description of the operations, each line should contain two integers $l,r$ ($1 \\le l \\le r \\le n$), representing single reverse operation of $s[l \\dots r]=s_{l}s_{l+1}\\dots s_{r}$. Operations are applied one after another sequentially.\n\nThe final $s$ after all operations should be a regular, also it should be exactly $k$ prefixes (including $s$) which are regular.\n\nIt is guaranteed that the answer exists. If there are several possible answers you can print any.\n\n\n-----Example-----\nInput\n4\n8 2\n()(())()\n10 3\n))()()()((\n2 1\n()\n2 1\n)(\n\nOutput\n4\n3 4\n1 1\n5 8\n2 2\n3\n4 10\n1 4\n6 7\n0\n1\n1 2\n\n\n\n-----Note-----\n\nIn the first example, the final sequence is \"()(()())\", where two prefixes are regular, \"()\" and \"()(()())\". Note, that all the operations except \"5 8\" in the example output are useless (they do not change $s$).\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nt = int(input())\nfor tt in range(t):\n n,k=list(map(int,input().split()))\n s = input()\n ans = []\n if s[0] == ')':\n for i in range(n):\n if s[i] == '(':\n ans.append([1,i+1])\n s = s[i::-1] + s[i+1:]\n break\n for i in range(1,(k-1)*2):\n if i%2==0:\n if s[i]!='(':\n for j in range(i+1,n):\n if s[j] == '(':\n ans.append([i+1,j+1])\n s = s[:i] + s[j:i-1:-1] + s[j+1:]\n break\n else:\n if s[i]!=')':\n for j in range(i+1,n):\n if s[j] == ')':\n ans.append([i+1,j+1])\n s = s[:i] + s[j:i-1:-1] + s[j+1:]\n break\n for i in range((k-1)*2,(n+(2*(k-1)))//2+1):\n if s[i]!='(':\n for j in range(i+1,n):\n if s[j] == '(':\n ans.append([i+1,j+1])\n s = s[:i] + s[j:i-1:-1] + s[j+1:]\n break\n print(len(ans))\n for i in ans:\n print(*i)\n \n\n\n\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '4\\n8 2\\n()(())()\\n10 3\\n))()()()((\\n2 1\\n()\\n2 1\\n)(\\n', 'output': '1\\n5 7\\n5\\n1 3\\n3 5\\n5 7\\n6 9\\n7 10\\n0\\n1\\n1 2\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/1227/C'}","problem_id":"vfc_164","program":"```python\nt = int(input())\nfor tt in range(t):\n n,k=list(map(int,input().split()))\n s = input()\n ans = []\n if s[0] == ')':\n for i in range(n):\n if s[i] == '(':\n ans.append([1,i+1])\n s = s[i::-1] + s[i+1:]\n break\n for i in range(1,(k-1)*2):\n if i%2==0:\n if s[i]!='(':\n for j in range(i+1,n):\n if s[j] == '(':\n ans.append([i+1,j+1])\n s = s[:i] + s[j:i-1:-1] + s[j+1:]\n break\n else:\n if s[i]!=')':\n for j in range(i+1,n):\n if s[j] == ')':\n ans.append([i+1,j+1])\n s = s[:i] + s[j:i-1:-1] + s[j+1:]\n break\n for i in range((k-1)*2,(n+(2*(k-1)))//2+1):\n if s[i]!='(':\n for j in range(i+1,n):\n if s[j] == '(':\n ans.append([i+1,j+1])\n s = s[:i] + s[j:i-1:-1] + s[j+1:]\n break\n print(len(ans))\n for i in ans:\n print(*i)\n \n\n\n\n\n```","inputs":"4\n8 2\n()(())()\n10 3\n))()()()((\n2 1\n()\n2 1\n)(\n","output":"1\n5 7\n5\n1 3\n3 5\n5 7\n6 9\n7 10\n0\n1\n1 2\n","actual_output":"1\n5 7\n5\n1 3\n3 5\n5 7\n6 9\n7 10\n0\n1\n1 2\n","execution_success":true,"sample_index":42},{"source":"apps","task_type":"verifiable_code","in_source_id":"42","prompt":"Solve the following coding problem using the programming language python:\n\nYou are given a binary string $s$ (recall that a string is binary if each character is either $0$ or $1$).\n\nLet $f(t)$ be the decimal representation of integer $t$ written in binary form (possibly with leading zeroes). For example $f(011) = 3, f(00101) = 5, f(00001) = 1, f(10) = 2, f(000) = 0$ and $f(000100) = 4$.\n\nThe substring $s_{l}, s_{l+1}, \\dots , s_{r}$ is good if $r - l + 1 = f(s_l \\dots s_r)$.\n\nFor example string $s = 1011$ has $5$ good substrings: $s_1 \\dots s_1 = 1$, $s_3 \\dots s_3 = 1$, $s_4 \\dots s_4 = 1$, $s_1 \\dots s_2 = 10$ and $s_2 \\dots s_4 = 011$. \n\nYour task is to calculate the number of good substrings of string $s$.\n\nYou have to answer $t$ independent queries.\n\n\n-----Input-----\n\nThe first line contains one integer $t$ ($1 \\le t \\le 1000$) \u2014 the number of queries.\n\nThe only line of each query contains string $s$ ($1 \\le |s| \\le 2 \\cdot 10^5$), consisting of only digits $0$ and $1$.\n\nIt is guaranteed that $\\sum\\limits_{i=1}^{t} |s_i| \\le 2 \\cdot 10^5$.\n\n\n-----Output-----\n\nFor each query print one integer \u2014 the number of good substrings of string $s$.\n\n\n-----Example-----\nInput\n4\n0110\n0101\n00001000\n0001000\n\nOutput\n4\n3\n4\n3\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nLOG = 20\n\ndef solve(s):\n\tn = len(s)\n\tres = 0\n\tz = 0\n\tfor t in range(0, n):\n\t\tif s[t] == '0':\n\t\t\tz += 1\n\t\t\tcontinue\n\t\tfor l in range(1, min(LOG, n - t + 1)):\n\t\t\tx = int(s[t:t+l], 2)\n\t\t\t# print(l, t, x, l + z)\n\t\t\tif l + z >= x:\n\t\t\t\tres += 1\n\n#\t\t\tprint(t, l, x, res, z)\n\t\tz = 0\n\treturn res\n\n\nt = int(input())\nwhile t > 0:\n\tt -= 1\n\ts = input()\n\tprint(solve(s))\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '4\\n0110\\n0101\\n00001000\\n0001000\\n', 'output': '4\\n3\\n4\\n3\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/1217/C'}","problem_id":"vfc_168","program":"```python\nLOG = 20\n\ndef solve(s):\n\tn = len(s)\n\tres = 0\n\tz = 0\n\tfor t in range(0, n):\n\t\tif s[t] == '0':\n\t\t\tz += 1\n\t\t\tcontinue\n\t\tfor l in range(1, min(LOG, n - t + 1)):\n\t\t\tx = int(s[t:t+l], 2)\n\t\t\t# print(l, t, x, l + z)\n\t\t\tif l + z >= x:\n\t\t\t\tres += 1\n\n#\t\t\tprint(t, l, x, res, z)\n\t\tz = 0\n\treturn res\n\n\nt = int(input())\nwhile t > 0:\n\tt -= 1\n\ts = input()\n\tprint(solve(s))\n```","inputs":"4\n0110\n0101\n00001000\n0001000\n","output":"4\n3\n4\n3\n","actual_output":"4\n3\n4\n3\n","execution_success":true,"sample_index":43},{"source":"apps","task_type":"verifiable_code","in_source_id":"43","prompt":"Solve the following coding problem using the programming language python:\n\nPetya is preparing for his birthday. He decided that there would be $n$ different dishes on the dinner table, numbered from $1$ to $n$. Since Petya doesn't like to cook, he wants to order these dishes in restaurants.\n\nUnfortunately, all dishes are prepared in different restaurants and therefore Petya needs to pick up his orders from $n$ different places. To speed up this process, he wants to order courier delivery at some restaurants. Thus, for each dish, there are two options for Petya how he can get it: the dish will be delivered by a courier from the restaurant $i$, in this case the courier will arrive in $a_i$ minutes, Petya goes to the restaurant $i$ on his own and picks up the dish, he will spend $b_i$ minutes on this. \n\nEach restaurant has its own couriers and they start delivering the order at the moment Petya leaves the house. In other words, all couriers work in parallel. Petya must visit all restaurants in which he has not chosen delivery, he does this consistently.\n\nFor example, if Petya wants to order $n = 4$ dishes and $a = [3, 7, 4, 5]$, and $b = [2, 1, 2, 4]$, then he can order delivery from the first and the fourth restaurant, and go to the second and third on your own. Then the courier of the first restaurant will bring the order in $3$ minutes, the courier of the fourth restaurant will bring the order in $5$ minutes, and Petya will pick up the remaining dishes in $1 + 2 = 3$ minutes. Thus, in $5$ minutes all the dishes will be at Petya's house.\n\nFind the minimum time after which all the dishes can be at Petya's home.\n\n\n-----Input-----\n\nThe first line contains one positive integer $t$ ($1 \\le t \\le 2 \\cdot 10^5$)\u00a0\u2014 the number of test cases. Then $t$ test cases follow.\n\nEach test case begins with a line containing one integer $n$ ($1 \\le n \\le 2 \\cdot 10^5$)\u00a0\u2014 the number of dishes that Petya wants to order.\n\nThe second line of each test case contains $n$ integers $a_1 \\ldots a_n$ ($1 \\le a_i \\le 10^9$)\u00a0\u2014 the time of courier delivery of the dish with the number $i$.\n\nThe third line of each test case contains $n$ integers $b_1 \\ldots b_n$ ($1 \\le b_i \\le 10^9$)\u00a0\u2014 the time during which Petya will pick up the dish with the number $i$.\n\nThe sum of $n$ over all test cases does not exceed $2 \\cdot 10^5$.\n\n\n-----Output-----\n\nFor each test case output one integer\u00a0\u2014 the minimum time after which all dishes can be at Petya's home.\n\n\n-----Example-----\nInput\n4\n4\n3 7 4 5\n2 1 2 4\n4\n1 2 3 4\n3 3 3 3\n2\n1 2\n10 10\n2\n10 10\n1 2\n\nOutput\n5\n3\n2\n3\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\ndef check(M):\n sm = 0\n for i in range(n):\n if a[i] > M:\n sm += b[i]\n return sm <= M\n\n\ngans = []\nfor _ in range(int(input())):\n n = int(input())\n a = list(map(int, input().split()))\n b = list(map(int, input().split()))\n L = 0\n R = max(a)\n while R - L > 1:\n M = (L + R) // 2\n if check(M):\n R = M\n else:\n L = M\n gans.append(R)\nprint(*gans, sep='\\n')\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '4\\n4\\n3 7 4 5\\n2 1 2 4\\n4\\n1 2 3 4\\n3 3 3 3\\n2\\n1 2\\n10 10\\n2\\n10 10\\n1 2\\n', 'output': '5\\n3\\n2\\n3\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/1443/C'}","problem_id":"vfc_172","program":"```python\ndef check(M):\n sm = 0\n for i in range(n):\n if a[i] > M:\n sm += b[i]\n return sm <= M\n\n\ngans = []\nfor _ in range(int(input())):\n n = int(input())\n a = list(map(int, input().split()))\n b = list(map(int, input().split()))\n L = 0\n R = max(a)\n while R - L > 1:\n M = (L + R) // 2\n if check(M):\n R = M\n else:\n L = M\n gans.append(R)\nprint(*gans, sep='\\n')\n\n```","inputs":"4\n4\n3 7 4 5\n2 1 2 4\n4\n1 2 3 4\n3 3 3 3\n2\n1 2\n10 10\n2\n10 10\n1 2\n","output":"5\n3\n2\n3\n","actual_output":"5\n3\n2\n3\n","execution_success":true,"sample_index":44},{"source":"apps","task_type":"verifiable_code","in_source_id":"44","prompt":"Solve the following coding problem using the programming language python:\n\nToday the kindergarten has a new group of $n$ kids who need to be seated at the dinner table. The chairs at the table are numbered from $1$ to $4n$. Two kids can't sit on the same chair. It is known that two kids who sit on chairs with numbers $a$ and $b$ ($a \\neq b$) will indulge if: $gcd(a, b) = 1$ or, $a$ divides $b$ or $b$ divides $a$. \n\n$gcd(a, b)$\u00a0\u2014 the maximum number $x$ such that $a$ is divisible by $x$ and $b$ is divisible by $x$.\n\nFor example, if $n=3$ and the kids sit on chairs with numbers $2$, $3$, $4$, then they will indulge since $4$ is divided by $2$ and $gcd(2, 3) = 1$. If kids sit on chairs with numbers $4$, $6$, $10$, then they will not indulge.\n\nThe teacher really doesn't want the mess at the table, so she wants to seat the kids so there are no $2$ of the kid that can indulge. More formally, she wants no pair of chairs $a$ and $b$ that the kids occupy to fulfill the condition above.\n\nSince the teacher is very busy with the entertainment of the kids, she asked you to solve this problem.\n\n\n-----Input-----\n\nThe first line contains one integer $t$ ($1 \\leq t \\leq 100$)\u00a0\u2014 the number of test cases. Then $t$ test cases follow.\n\nEach test case consists of one line containing an integer $n$ ($1 \\leq n \\leq 100$)\u00a0\u2014 the number of kids.\n\n\n-----Output-----\n\nOutput $t$ lines, which contain $n$ distinct integers from $1$ to $4n$\u00a0\u2014 the numbers of chairs that the kids should occupy in the corresponding test case. If there are multiple answers, print any of them. You can print $n$ numbers in any order.\n\n\n-----Example-----\nInput\n3\n2\n3\n4\n\nOutput\n6 4\n4 6 10\n14 10 12 8\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nt=int(input())\nfor you in range(t):\n n=int(input())\n for i in range(n):\n print(4*n-2*i,end=\" \")\n print()\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\n2\\n3\\n4\\n', 'output': '8 6 \\n12 10 8 \\n16 14 12 10 \\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/1443/A'}","problem_id":"vfc_176","program":"```python\nt=int(input())\nfor you in range(t):\n n=int(input())\n for i in range(n):\n print(4*n-2*i,end=\" \")\n print()\n\n```","inputs":"3\n2\n3\n4\n","output":"8 6 \n12 10 8 \n16 14 12 10 \n","actual_output":"8 6 \n12 10 8 \n16 14 12 10 \n","execution_success":true,"sample_index":45},{"source":"apps","task_type":"verifiable_code","in_source_id":"45","prompt":"Solve the following coding problem using the programming language python:\n\nJett is tired after destroying the town and she wants to have a rest. She likes high places, that's why for having a rest she wants to get high and she decided to craft staircases.\n\nA staircase is a squared figure that consists of square cells. Each staircase consists of an arbitrary number of stairs. If a staircase has $n$ stairs, then it is made of $n$ columns, the first column is $1$ cell high, the second column is $2$ cells high, $\\ldots$, the $n$-th column if $n$ cells high. The lowest cells of all stairs must be in the same row.\n\nA staircase with $n$ stairs is called nice, if it may be covered by $n$ disjoint squares made of cells. All squares should fully consist of cells of a staircase. This is how a nice covered staircase with $7$ stairs looks like: [Image] \n\nFind out the maximal number of different nice staircases, that can be built, using no more than $x$ cells, in total. No cell can be used more than once.\n\n\n-----Input-----\n\nThe first line contains a single integer $t$ $(1 \\le t \\le 1000)$ \u00a0\u2014 the number of test cases.\n\nThe description of each test case contains a single integer $x$ $(1 \\le x \\le 10^{18})$ \u00a0\u2014 the number of cells for building staircases.\n\n\n-----Output-----\n\nFor each test case output a single integer \u00a0\u2014 the number of different nice staircases, that can be built, using not more than $x$ cells, in total.\n\n\n-----Example-----\nInput\n4\n1\n8\n6\n1000000000000000000\n\nOutput\n1\n2\n1\n30\n\n\n\n-----Note-----\n\nIn the first test case, it is possible to build only one staircase, that consists of $1$ stair. It's nice. That's why the answer is $1$.\n\nIn the second test case, it is possible to build two different nice staircases: one consists of $1$ stair, and another consists of $3$ stairs. This will cost $7$ cells. In this case, there is one cell left, but it is not possible to use it for building any nice staircases, that have not been built yet. That's why the answer is $2$.\n\nIn the third test case, it is possible to build only one of two nice staircases: with $1$ stair or with $3$ stairs. In the first case, there will be $5$ cells left, that may be used only to build a staircase with $2$ stairs. This staircase is not nice, and Jett only builds nice staircases. That's why in this case the answer is $1$. If Jett builds a staircase with $3$ stairs, then there are no more cells left, so the answer is $1$ again.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nimport sys\nimport random\nfrom fractions import Fraction\nfrom math import *\n \ndef input():\n return sys.stdin.readline().strip()\n \ndef iinput():\n return int(input())\n\ndef finput():\n return float(input())\n\ndef tinput():\n return input().split()\n\ndef linput():\n return list(input())\n \ndef rinput():\n return list(map(int, tinput()))\n\ndef fiinput():\n return list(map(float, tinput()))\n \ndef rlinput():\n return list(map(int, input().split()))\ndef trinput():\n return tuple(rinput())\n\ndef srlinput():\n return sorted(list(map(int, input().split())))\n\ndef NOYES(fl):\n if fl:\n print(\"NO\")\n else:\n print(\"YES\")\ndef YESNO(fl):\n if fl:\n print(\"YES\")\n else:\n print(\"NO\")\n \ndef main():\n n = iinput()\n #k = iinput() \n #m = iinput() \n #n = int(sys.stdin.readline().strip()) \n #n, k = rinput()\n #n, m = rinput()\n #m, k = rinput()\n #n, k, m = rinput()\n #n, m, k = rinput()\n #k, n, m = rinput()\n #k, m, n = rinput() \n #m, k, n = rinput()\n #m, n, k = rinput()\n #q = srlinput()\n #q = linput()\n s, t, res = 1, 1, 0\n while s <= n:\n res += 1\n n -= s\n t = 2 * t + 1\n s = (t * (t + 1)) // 2\n print(res)\n \n \n \n \n \n \n \n \n \n \n\nfor i in range(iinput()):\n main()\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '4\\n1\\n8\\n6\\n1000000000000000000\\n', 'output': '1\\n2\\n1\\n30\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/1419/B'}","problem_id":"vfc_180","program":"```python\nimport sys\nimport random\nfrom fractions import Fraction\nfrom math import *\n \ndef input():\n return sys.stdin.readline().strip()\n \ndef iinput():\n return int(input())\n\ndef finput():\n return float(input())\n\ndef tinput():\n return input().split()\n\ndef linput():\n return list(input())\n \ndef rinput():\n return list(map(int, tinput()))\n\ndef fiinput():\n return list(map(float, tinput()))\n \ndef rlinput():\n return list(map(int, input().split()))\ndef trinput():\n return tuple(rinput())\n\ndef srlinput():\n return sorted(list(map(int, input().split())))\n\ndef NOYES(fl):\n if fl:\n print(\"NO\")\n else:\n print(\"YES\")\ndef YESNO(fl):\n if fl:\n print(\"YES\")\n else:\n print(\"NO\")\n \ndef main():\n n = iinput()\n #k = iinput() \n #m = iinput() \n #n = int(sys.stdin.readline().strip()) \n #n, k = rinput()\n #n, m = rinput()\n #m, k = rinput()\n #n, k, m = rinput()\n #n, m, k = rinput()\n #k, n, m = rinput()\n #k, m, n = rinput() \n #m, k, n = rinput()\n #m, n, k = rinput()\n #q = srlinput()\n #q = linput()\n s, t, res = 1, 1, 0\n while s <= n:\n res += 1\n n -= s\n t = 2 * t + 1\n s = (t * (t + 1)) // 2\n print(res)\n \n \n \n \n \n \n \n \n \n \n\nfor i in range(iinput()):\n main()\n\n```","inputs":"4\n1\n8\n6\n1000000000000000000\n","output":"1\n2\n1\n30\n","actual_output":"1\n2\n1\n30\n","execution_success":true,"sample_index":46},{"source":"apps","task_type":"verifiable_code","in_source_id":"46","prompt":"Solve the following coding problem using the programming language python:\n\nRecently, you found a bot to play \"Rock paper scissors\" with. Unfortunately, the bot uses quite a simple algorithm to play: he has a string $s = s_1 s_2 \\dots s_{n}$ of length $n$ where each letter is either R, S or P.\n\nWhile initializing, the bot is choosing a starting index $pos$ ($1 \\le pos \\le n$), and then it can play any number of rounds. In the first round, he chooses \"Rock\", \"Scissors\" or \"Paper\" based on the value of $s_{pos}$: if $s_{pos}$ is equal to R the bot chooses \"Rock\"; if $s_{pos}$ is equal to S the bot chooses \"Scissors\"; if $s_{pos}$ is equal to P the bot chooses \"Paper\"; \n\nIn the second round, the bot's choice is based on the value of $s_{pos + 1}$. In the third round\u00a0\u2014 on $s_{pos + 2}$ and so on. After $s_n$ the bot returns to $s_1$ and continues his game.\n\nYou plan to play $n$ rounds and you've already figured out the string $s$ but still don't know what is the starting index $pos$. But since the bot's tactic is so boring, you've decided to find $n$ choices to each round to maximize the average number of wins.\n\nIn other words, let's suggest your choices are $c_1 c_2 \\dots c_n$ and if the bot starts from index $pos$ then you'll win in $win(pos)$ rounds. Find $c_1 c_2 \\dots c_n$ such that $\\frac{win(1) + win(2) + \\dots + win(n)}{n}$ is maximum possible.\n\n\n-----Input-----\n\nThe first line contains a single integer $t$ ($1 \\le t \\le 1000$)\u00a0\u2014 the number of test cases.\n\nNext $t$ lines contain test cases\u00a0\u2014 one per line. The first and only line of each test case contains string $s = s_1 s_2 \\dots s_{n}$ ($1 \\le n \\le 2 \\cdot 10^5$; $s_i \\in \\{\\text{R}, \\text{S}, \\text{P}\\}$)\u00a0\u2014 the string of the bot.\n\nIt's guaranteed that the total length of all strings in one test doesn't exceed $2 \\cdot 10^5$.\n\n\n-----Output-----\n\nFor each test case, print $n$ choices $c_1 c_2 \\dots c_n$ to maximize the average number of wins. Print them in the same manner as the string $s$.\n\nIf there are multiple optimal answers, print any of them.\n\n\n-----Example-----\nInput\n3\nRRRR\nRSP\nS\n\nOutput\nPPPP\nRSP\nR\n\n\n-----Note-----\n\nIn the first test case, the bot (wherever it starts) will always choose \"Rock\", so we can always choose \"Paper\". So, in any case, we will win all $n = 4$ rounds, so the average is also equal to $4$.\n\nIn the second test case: if bot will start from $pos = 1$, then $(s_1, c_1)$ is draw, $(s_2, c_2)$ is draw and $(s_3, c_3)$ is draw, so $win(1) = 0$; if bot will start from $pos = 2$, then $(s_2, c_1)$ is win, $(s_3, c_2)$ is win and $(s_1, c_3)$ is win, so $win(2) = 3$; if bot will start from $pos = 3$, then $(s_3, c_1)$ is lose, $(s_1, c_2)$ is lose and $(s_2, c_3)$ is lose, so $win(3) = 0$; The average is equal to $\\frac{0 + 3 + 0}{3} = 1$ and it can be proven that it's the maximum possible average.\n\nA picture from Wikipedia explaining \"Rock paper scissors\" game: $\\beta$\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n#\n# ------------------------------------------------\n# ____ _ Generatered using\n# / ___| | |\n# | | __ _ __| | ___ _ __ ______ _\n# | | / _` |/ _` |/ _ \\ '_ \\|_ / _` |\n# | |__| (_| | (_| | __/ | | |/ / (_| |\n# \\____\\____|\\____|\\___|_| |_/___\\____|\n#\n# GNU Affero General Public License v3.0\n# ------------------------------------------------\n# Author : prophet\n# Created : 2020-07-12 11:19:01.523119\n# UUID : aXsU7xuXyjk3Ky2f\n# ------------------------------------------------\n#\nproduction = True\n\nimport sys, math, collections\n\ndef input(input_format = 0, multi = 0):\n\n if multi > 0: return [input(input_format) for i in range(multi)]\n else:\n next_line = sys.stdin.readline()[:-1]\n\n if input_format >= 10:\n use_list = False\n input_format = int(str(input_format)[-1])\n else: use_list = True\n\n if input_format == 0: formatted_input = [next_line]\n elif input_format == 1: formatted_input = list(map(int, next_line.split()))\n elif input_format == 2: formatted_input = list(map(float, next_line.split()))\n elif input_format == 3: formatted_input = list(next_line)\n elif input_format == 4: formatted_input = list(map(int, list(next_line)))\n elif input_format == 5: formatted_input = next_line.split()\n else: formatted_input = [next_line]\n\n return formatted_input if use_list else formatted_input[0]\n\ndef out(output_line, output_format = 0, newline = True):\n\n formatted_output = \"\"\n\n if output_format == 0: formatted_output = str(output_line)\n elif output_format == 1: formatted_output = \" \".join(map(str, output_line))\n elif output_format == 2: formatted_output = \"\\n\".join(map(str, output_line))\n\n print(formatted_output, end = \"\\n\" if newline else \"\")\n\ndef log(*args):\n if not production:\n print(\"$$$\", end = \"\")\n print(*args)\n\nenu = enumerate\n\nter = lambda a, b, c: b if a else c\n\nceil = lambda a, b: -(-a // b)\n\ndef mapl(iterable, format = 0):\n \n if format == 0: return list(map(int, iterable))\n elif format == 1: return list(map(str, iterable))\n elif format == 2: return list(map(list, iterable))\n#\n# >>>>>>>>>>>>>>> START OF SOLUTION <<<<<<<<<<<<<<\n#\n\n\ndef solve():\n\n s = input(3)\n\n u = [0] * 3\n\n for i in s:\n if i == \"R\":\n u[0] += 1\n elif i == \"P\":\n u[1] += 1\n elif i == \"S\":\n u[2] += 1\n\n log(u)\n y = 0\n p = 0\n\n for i, j in enu(u):\n if j > y:\n y = j\n p = i\n\n if p == 0:\n a = \"P\"\n elif p == 1:\n a = \"S\"\n elif p == 2:\n a = \"R\"\n\n out(a * len(s))\n\n return\n\n\nfor i in range(input(11)): solve()\n# solve()\n\n#\n# >>>>>>>>>>>>>>>> END OF SOLUTION <<<<<<<<<<<<<<<\n#\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\nRRRR\\nRSP\\nS\\n', 'output': 'PPPP\\nPPP\\nR\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/1380/B'}","problem_id":"vfc_184","program":"```python\n#\n# ------------------------------------------------\n# ____ _ Generatered using\n# / ___| | |\n# | | __ _ __| | ___ _ __ ______ _\n# | | / _` |/ _` |/ _ \\ '_ \\|_ / _` |\n# | |__| (_| | (_| | __/ | | |/ / (_| |\n# \\____\\____|\\____|\\___|_| |_/___\\____|\n#\n# GNU Affero General Public License v3.0\n# ------------------------------------------------\n# Author : prophet\n# Created : 2020-07-12 11:19:01.523119\n# UUID : aXsU7xuXyjk3Ky2f\n# ------------------------------------------------\n#\nproduction = True\n\nimport sys, math, collections\n\ndef input(input_format = 0, multi = 0):\n\n if multi > 0: return [input(input_format) for i in range(multi)]\n else:\n next_line = sys.stdin.readline()[:-1]\n\n if input_format >= 10:\n use_list = False\n input_format = int(str(input_format)[-1])\n else: use_list = True\n\n if input_format == 0: formatted_input = [next_line]\n elif input_format == 1: formatted_input = list(map(int, next_line.split()))\n elif input_format == 2: formatted_input = list(map(float, next_line.split()))\n elif input_format == 3: formatted_input = list(next_line)\n elif input_format == 4: formatted_input = list(map(int, list(next_line)))\n elif input_format == 5: formatted_input = next_line.split()\n else: formatted_input = [next_line]\n\n return formatted_input if use_list else formatted_input[0]\n\ndef out(output_line, output_format = 0, newline = True):\n\n formatted_output = \"\"\n\n if output_format == 0: formatted_output = str(output_line)\n elif output_format == 1: formatted_output = \" \".join(map(str, output_line))\n elif output_format == 2: formatted_output = \"\\n\".join(map(str, output_line))\n\n print(formatted_output, end = \"\\n\" if newline else \"\")\n\ndef log(*args):\n if not production:\n print(\"$$$\", end = \"\")\n print(*args)\n\nenu = enumerate\n\nter = lambda a, b, c: b if a else c\n\nceil = lambda a, b: -(-a // b)\n\ndef mapl(iterable, format = 0):\n \n if format == 0: return list(map(int, iterable))\n elif format == 1: return list(map(str, iterable))\n elif format == 2: return list(map(list, iterable))\n#\n# >>>>>>>>>>>>>>> START OF SOLUTION <<<<<<<<<<<<<<\n#\n\n\ndef solve():\n\n s = input(3)\n\n u = [0] * 3\n\n for i in s:\n if i == \"R\":\n u[0] += 1\n elif i == \"P\":\n u[1] += 1\n elif i == \"S\":\n u[2] += 1\n\n log(u)\n y = 0\n p = 0\n\n for i, j in enu(u):\n if j > y:\n y = j\n p = i\n\n if p == 0:\n a = \"P\"\n elif p == 1:\n a = \"S\"\n elif p == 2:\n a = \"R\"\n\n out(a * len(s))\n\n return\n\n\nfor i in range(input(11)): solve()\n# solve()\n\n#\n# >>>>>>>>>>>>>>>> END OF SOLUTION <<<<<<<<<<<<<<<\n#\n\n```","inputs":"3\nRRRR\nRSP\nS\n","output":"PPPP\nPPP\nR\n","actual_output":"PPPP\nPPP\nR\n","execution_success":true,"sample_index":47},{"source":"apps","task_type":"verifiable_code","in_source_id":"47","prompt":"Solve the following coding problem using the programming language python:\n\nThis is the easy version of the problem. The difference between the versions is that the easy version has no swap operations. You can make hacks only if all versions of the problem are solved.\n\nPikachu is a cute and friendly pok\u00e9mon living in the wild pikachu herd.\n\nBut it has become known recently that infamous team R wanted to steal all these pok\u00e9mon! Pok\u00e9mon trainer Andrew decided to help Pikachu to build a pok\u00e9mon army to resist.\n\nFirst, Andrew counted all the pok\u00e9mon\u00a0\u2014 there were exactly $n$ pikachu. The strength of the $i$-th pok\u00e9mon is equal to $a_i$, and all these numbers are distinct.\n\nAs an army, Andrew can choose any non-empty subsequence of pokemons. In other words, Andrew chooses some array $b$ from $k$ indices such that $1 \\le b_1 < b_2 < \\dots < b_k \\le n$, and his army will consist of pok\u00e9mons with forces $a_{b_1}, a_{b_2}, \\dots, a_{b_k}$.\n\nThe strength of the army is equal to the alternating sum of elements of the subsequence; that is, $a_{b_1} - a_{b_2} + a_{b_3} - a_{b_4} + \\dots$.\n\nAndrew is experimenting with pok\u00e9mon order. He performs $q$ operations. In $i$-th operation Andrew swaps $l_i$-th and $r_i$-th pok\u00e9mon.\n\nNote: $q=0$ in this version of the task.\n\nAndrew wants to know the maximal stregth of the army he can achieve with the initial pok\u00e9mon placement. He also needs to know the maximal strength after each operation.\n\nHelp Andrew and the pok\u00e9mon, or team R will realize their tricky plan!\n\n\n-----Input-----\n\nEach test contains multiple test cases.\n\nThe first line contains one positive integer $t$ ($1 \\le t \\le 10^3$) denoting the number of test cases. Description of the test cases follows.\n\nThe first line of each test case contains two integers $n$ and $q$ ($1 \\le n \\le 3 \\cdot 10^5, q = 0$) denoting the number of pok\u00e9mon and number of operations respectively.\n\nThe second line contains $n$ distinct positive integers $a_1, a_2, \\dots, a_n$ ($1 \\le a_i \\le n$) denoting the strengths of the pok\u00e9mon.\n\n$i$-th of the last $q$ lines contains two positive integers $l_i$ and $r_i$ ($1 \\le l_i \\le r_i \\le n$) denoting the indices of pok\u00e9mon that were swapped in the $i$-th operation.\n\nIt is guaranteed that the sum of $n$ over all test cases does not exceed $3 \\cdot 10^5$, and the sum of $q$ over all test cases does not exceed $3 \\cdot 10^5$. \n\n\n-----Output-----\n\nFor each test case, print $q+1$ integers: the maximal strength of army before the swaps and after each swap.\n\n\n-----Example-----\nInput\n3\n3 0\n1 3 2\n2 0\n1 2\n7 0\n1 2 5 4 3 6 7\n\nOutput\n3\n2\n9\n\n\n\n-----Note-----\n\nIn third test case we can build an army in such way: [1 2 5 4 3 6 7], its strength will be $5\u22123+7=9$.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nimport sys\ninput = sys.stdin.readline\nfrom bisect import bisect_right\n\nbin_s = [1]\nwhile bin_s[-1] <= 10 ** 9:\n bin_s.append(bin_s[-1] * 2)\n\n\ndef main():\n n, q = map(int, input().split())\n alst = list(map(int, input().split()))\n dp = [[-1, -1] for _ in range(n)]\n dp[0] = [alst[0], 0]\n for i, a in enumerate(alst[1:], start = 1):\n dp[i][0] = max(dp[i - 1][0], dp[i - 1][1] + a)\n dp[i][1] = max(dp[i - 1][1], dp[i - 1][0] - a)\n print(max(dp[-1]))\n \n\nfor _ in range(int(input())):\n main()\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\n3 0\\n1 3 2\\n2 0\\n1 2\\n7 0\\n1 2 5 4 3 6 7\\n', 'output': '3\\n2\\n9\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/1420/C1'}","problem_id":"vfc_188","program":"```python\nimport sys\ninput = sys.stdin.readline\nfrom bisect import bisect_right\n\nbin_s = [1]\nwhile bin_s[-1] <= 10 ** 9:\n bin_s.append(bin_s[-1] * 2)\n\n\ndef main():\n n, q = map(int, input().split())\n alst = list(map(int, input().split()))\n dp = [[-1, -1] for _ in range(n)]\n dp[0] = [alst[0], 0]\n for i, a in enumerate(alst[1:], start = 1):\n dp[i][0] = max(dp[i - 1][0], dp[i - 1][1] + a)\n dp[i][1] = max(dp[i - 1][1], dp[i - 1][0] - a)\n print(max(dp[-1]))\n \n\nfor _ in range(int(input())):\n main()\n```","inputs":"3\n3 0\n1 3 2\n2 0\n1 2\n7 0\n1 2 5 4 3 6 7\n","output":"3\n2\n9\n","actual_output":"3\n2\n9\n","execution_success":true,"sample_index":48},{"source":"apps","task_type":"verifiable_code","in_source_id":"48","prompt":"Solve the following coding problem using the programming language python:\n\nYou are playing a very popular game called Cubecraft. Initially, you have one stick and want to craft $k$ torches. One torch can be crafted using one stick and one coal.\n\nHopefully, you've met a very handsome wandering trader who has two trade offers: exchange $1$ stick for $x$ sticks (you lose $1$ stick and gain $x$ sticks). exchange $y$ sticks for $1$ coal (you lose $y$ sticks and gain $1$ coal). \n\nDuring one trade, you can use only one of these two trade offers. You can use each trade offer any number of times you want to, in any order.\n\nYour task is to find the minimum number of trades you need to craft at least $k$ torches. The answer always exists under the given constraints.\n\nYou have to answer $t$ independent test cases.\n\n\n-----Input-----\n\nThe first line of the input contains one integer $t$ ($1 \\le t \\le 2 \\cdot 10^4$) \u2014 the number of test cases. Then $t$ test cases follow.\n\nThe only line of the test case contains three integers $x$, $y$ and $k$ ($2 \\le x \\le 10^9$; $1 \\le y, k \\le 10^9$) \u2014 the number of sticks you can buy with one stick, the number of sticks required to buy one coal and the number of torches you need, respectively.\n\n\n-----Output-----\n\nFor each test case, print the answer: the minimum number of trades you need to craft at least $k$ torches. The answer always exists under the given constraints.\n\n\n-----Example-----\nInput\n5\n2 1 5\n42 13 24\n12 11 12\n1000000000 1000000000 1000000000\n2 1000000000 1000000000\n\nOutput\n14\n33\n25\n2000000003\n1000000001999999999\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfor haaghfj in range(int(input())):\n x,y,k = list(map(int,input().split()))\n print(k + (y * k + k - 1 +x-2) // (x - 1))\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '5\\n2 1 5\\n42 13 24\\n12 11 12\\n1000000000 1000000000 1000000000\\n2 1000000000 1000000000\\n', 'output': '14\\n33\\n25\\n2000000003\\n1000000001999999999\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/1418/A'}","problem_id":"vfc_192","program":"```python\nfor haaghfj in range(int(input())):\n x,y,k = list(map(int,input().split()))\n print(k + (y * k + k - 1 +x-2) // (x - 1))\n\n```","inputs":"5\n2 1 5\n42 13 24\n12 11 12\n1000000000 1000000000 1000000000\n2 1000000000 1000000000\n","output":"14\n33\n25\n2000000003\n1000000001999999999\n","actual_output":"14\n33\n25\n2000000003\n1000000001999999999\n","execution_success":true,"sample_index":49},{"source":"apps","task_type":"verifiable_code","in_source_id":"49","prompt":"Solve the following coding problem using the programming language python:\n\nLet's call some positive integer classy if its decimal representation contains no more than $3$ non-zero digits. For example, numbers $4$, $200000$, $10203$ are classy and numbers $4231$, $102306$, $7277420000$ are not.\n\nYou are given a segment $[L; R]$. Count the number of classy integers $x$ such that $L \\le x \\le R$.\n\nEach testcase contains several segments, for each of them you are required to solve the problem separately.\n\n\n-----Input-----\n\nThe first line contains a single integer $T$ ($1 \\le T \\le 10^4$) \u2014 the number of segments in a testcase.\n\nEach of the next $T$ lines contains two integers $L_i$ and $R_i$ ($1 \\le L_i \\le R_i \\le 10^{18}$).\n\n\n-----Output-----\n\nPrint $T$ lines \u2014 the $i$-th line should contain the number of classy integers on a segment $[L_i; R_i]$.\n\n\n-----Example-----\nInput\n4\n1 1000\n1024 1024\n65536 65536\n999999 1000001\n\nOutput\n1000\n1\n0\n2\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n\nimport sys\n#sys.stdin=open(\"data.txt\")\ninput=sys.stdin.readline\n\n# this math tutorial is boring\n\nclassy=set()\n\nfor i in range(19):\n for j in range(i):\n for k in range(j):\n for a in range(10): # a=0 for good measure\n for b in range(10):\n for c in range(10):\n what=a*10**i+b*10**j+c*10**k\n classy.add(what)\n\nli=sorted(classy)\n\ndef counting(i):\n # return len([x for x in li if x <= i])+C\n lo=0\n hi=len(li)-1\n while lo=(w//3)>=0 and (n//3)>=(w//3 + i * d1)>=0 and (n//3)>=(w//3 + j * d2)>=0:\n print('yes')\n f = 1\n if f == 0:\n print('no')\nmain()\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '5\\n3 0 0 0\\n3 3 0 0\\n6 4 1 0\\n6 3 3 0\\n3 3 3 2\\n', 'output': 'yes\\nyes\\nyes\\nno\\nno\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/451/C'}","problem_id":"vfc_204","program":"```python\ndef main():\n t = int(input())\n for z in range(t):\n n, k, d1, d2 = map(int, input().split())\n if n % 3 != 0:\n print('no')\n continue\n f = 0\n for i in [-1, +1]:\n for j in [-1, +1]:\n w = (k - i * d1 - j * d2)\n if f == 0 and (w % 3 == 0) and (n//3)>=(w//3)>=0 and (n//3)>=(w//3 + i * d1)>=0 and (n//3)>=(w//3 + j * d2)>=0:\n print('yes')\n f = 1\n if f == 0:\n print('no')\nmain()\n```","inputs":"5\n3 0 0 0\n3 3 0 0\n6 4 1 0\n6 3 3 0\n3 3 3 2\n","output":"yes\nyes\nyes\nno\nno\n","actual_output":"yes\nyes\nyes\nno\nno\n","execution_success":true,"sample_index":52},{"source":"apps","task_type":"verifiable_code","in_source_id":"52","prompt":"Solve the following coding problem using the programming language python:\n\nHarry Water, Ronaldo, Her-my-oh-knee and their friends have started a new school year at their MDCS School of Speechcraft and Misery. At the time, they are very happy to have seen each other after a long time. The sun is shining, birds are singing, flowers are blooming, and their Potions class teacher, professor Snipe is sulky as usual. Due to his angst fueled by disappointment in his own life, he has given them a lot of homework in Potions class. \n\nEach of the n students has been assigned a single task. Some students do certain tasks faster than others. Thus, they want to redistribute the tasks so that each student still does exactly one task, and that all tasks are finished. Each student has their own laziness level, and each task has its own difficulty level. Professor Snipe is trying hard to improve their work ethics, so each student\u2019s laziness level is equal to their task\u2019s difficulty level. Both sets of values are given by the sequence a, where a_{i} represents both the laziness level of the i-th student and the difficulty of his task. \n\nThe time a student needs to finish a task is equal to the product of their laziness level and the task\u2019s difficulty. They are wondering, what is the minimum possible total time they must spend to finish all tasks if they distribute them in the optimal way. Each person should receive one task and each task should be given to one person. Print the answer modulo 10 007.\n\n\n-----Input-----\n\nThe first line of input contains integer n (1 \u2264 n \u2264 100 000)\u00a0\u2014 the number of tasks. The next n lines contain exactly one integer number a_{i} (1 \u2264 a_{i} \u2264 100 000)\u00a0\u2014 both the difficulty of the initial task and the laziness of the i-th students.\n\n\n-----Output-----\n\nPrint the minimum total time to finish all tasks modulo 10 007.\n\n\n-----Example-----\nInput\n2\n1\n3\n\nOutput\n6\n\n\n\n-----Note-----\n\nIn the first sample, if the students switch their tasks, they will be able to finish them in 3 + 3 = 6 time units.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nn=int(input())\na=sorted(int(input()) for _ in range(n))\nprint(sum(a[i]*a[-i-1] for i in range(n))%10007)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n1\\n3\\n', 'output': '6\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/717/C'}","problem_id":"vfc_208","program":"```python\nn=int(input())\na=sorted(int(input()) for _ in range(n))\nprint(sum(a[i]*a[-i-1] for i in range(n))%10007)\n```","inputs":"2\n1\n3\n","output":"6\n","actual_output":"6\n","execution_success":true,"sample_index":53},{"source":"apps","task_type":"verifiable_code","in_source_id":"54","prompt":"Solve the following coding problem using the programming language python:\n\nYou are playing a variation of game 2048. Initially you have a multiset $s$ of $n$ integers. Every integer in this multiset is a power of two. \n\nYou may perform any number (possibly, zero) operations with this multiset.\n\nDuring each operation you choose two equal integers from $s$, remove them from $s$ and insert the number equal to their sum into $s$.\n\nFor example, if $s = \\{1, 2, 1, 1, 4, 2, 2\\}$ and you choose integers $2$ and $2$, then the multiset becomes $\\{1, 1, 1, 4, 4, 2\\}$.\n\nYou win if the number $2048$ belongs to your multiset. For example, if $s = \\{1024, 512, 512, 4\\}$ you can win as follows: choose $512$ and $512$, your multiset turns into $\\{1024, 1024, 4\\}$. Then choose $1024$ and $1024$, your multiset turns into $\\{2048, 4\\}$ and you win.\n\nYou have to determine if you can win this game.\n\nYou have to answer $q$ independent queries.\n\n\n-----Input-----\n\nThe first line contains one integer $q$ ($1 \\le q \\le 100$) \u2013 the number of queries.\n\nThe first line of each query contains one integer $n$ ($1 \\le n \\le 100$) \u2014 the number of elements in multiset.\n\nThe second line of each query contains $n$ integers $s_1, s_2, \\dots, s_n$ ($1 \\le s_i \\le 2^{29}$) \u2014 the description of the multiset. It is guaranteed that all elements of the multiset are powers of two. \n\n\n-----Output-----\n\nFor each query print YES if it is possible to obtain the number $2048$ in your multiset, and NO otherwise.\n\nYou may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES will all be recognized as positive answer).\n\n\n-----Example-----\nInput\n6\n4\n1024 512 64 512\n1\n2048\n3\n64 512 2\n2\n4096 4\n7\n2048 2 2048 2048 2048 2048 2048\n2\n2048 4096\n\nOutput\nYES\nYES\nNO\nNO\nYES\nYES\n\n\n\n-----Note-----\n\nIn the first query you can win as follows: choose $512$ and $512$, and $s$ turns into $\\{1024, 64, 1024\\}$. Then choose $1024$ and $1024$, and $s$ turns into $\\{2048, 64\\}$ and you win.\n\nIn the second query $s$ contains $2048$ initially.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfor i in range(int(input())):\n n=int(input())\n s=list(map(int,input().split()))\n a=0\n for i in s:\n if i<2049:a+=i\n if a<2048:print(\"NO\")\n else:print(\"YES\")\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '6\\n4\\n1024 512 64 512\\n1\\n2048\\n3\\n64 512 2\\n2\\n4096 4\\n7\\n2048 2 2048 2048 2048 2048 2048\\n2\\n2048 4096\\n', 'output': 'YES\\nYES\\nNO\\nNO\\nYES\\nYES\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/1221/A'}","problem_id":"vfc_216","program":"```python\nfor i in range(int(input())):\n n=int(input())\n s=list(map(int,input().split()))\n a=0\n for i in s:\n if i<2049:a+=i\n if a<2048:print(\"NO\")\n else:print(\"YES\")\n```","inputs":"6\n4\n1024 512 64 512\n1\n2048\n3\n64 512 2\n2\n4096 4\n7\n2048 2 2048 2048 2048 2048 2048\n2\n2048 4096\n","output":"YES\nYES\nNO\nNO\nYES\nYES\n","actual_output":"YES\nYES\nNO\nNO\nYES\nYES\n","execution_success":true,"sample_index":55},{"source":"apps","task_type":"verifiable_code","in_source_id":"55","prompt":"Solve the following coding problem using the programming language python:\n\nA penguin Rocher has $n$ sticks. He has exactly one stick with length $i$ for all $1 \\le i \\le n$.\n\nHe can connect some sticks. If he connects two sticks that have lengths $a$ and $b$, he gets one stick with length $a + b$. Two sticks, that were used in the operation disappear from his set and the new connected stick appears in his set and can be used for the next connections.\n\nHe wants to create the maximum number of sticks that have the same length. It is not necessary to make all sticks have the same length, some sticks can have the other length. How many sticks with the equal length he can create?\n\n\n-----Input-----\n\nThe input consists of multiple test cases. The first line contains a single integer $t$ ($1 \\le t \\le 1000$)\u00a0\u2014 the number of test cases. Next $t$ lines contain descriptions of test cases.\n\nFor each test case, the only line contains a single integer $n$ ($1 \\le n \\le 10^{9}$).\n\n\n-----Output-----\n\nFor each test case, print a single integer \u00a0\u2014 the answer to the problem.\n\n\n-----Example-----\nInput\n4\n1\n2\n3\n4\n\nOutput\n1\n1\n2\n2\n\n\n\n-----Note-----\n\nIn the third case, he can connect two sticks with lengths $1$ and $2$ and he will get one stick with length $3$. So, he will have two sticks with lengths $3$.\n\nIn the fourth case, he can connect two sticks with lengths $1$ and $3$ and he will get one stick with length $4$. After that, he will have three sticks with lengths $\\{2, 4, 4\\}$, so two sticks have the same length, and one stick has the other length.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfor __ in range(int(input())):\n n = int(input())\n print((n + 1) // 2)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '4\\n1\\n2\\n3\\n4\\n', 'output': '1\\n1\\n2\\n2\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/1371/A'}","problem_id":"vfc_220","program":"```python\nfor __ in range(int(input())):\n n = int(input())\n print((n + 1) // 2)\n```","inputs":"4\n1\n2\n3\n4\n","output":"1\n1\n2\n2\n","actual_output":"1\n1\n2\n2\n","execution_success":true,"sample_index":56},{"source":"apps","task_type":"verifiable_code","in_source_id":"57","prompt":"Solve the following coding problem using the programming language python:\n\nYou are given an array $a$ of length $n$, which initially is a permutation of numbers from $1$ to $n$. In one operation, you can choose an index $i$ ($1 \\leq i < n$) such that $a_i < a_{i + 1}$, and remove either $a_i$ or $a_{i + 1}$ from the array (after the removal, the remaining parts are concatenated). \n\nFor example, if you have the array $[1, 3, 2]$, you can choose $i = 1$ (since $a_1 = 1 < a_2 = 3$), then either remove $a_1$ which gives the new array $[3, 2]$, or remove $a_2$ which gives the new array $[1, 2]$.\n\nIs it possible to make the length of this array equal to $1$ with these operations?\n\n\n-----Input-----\n\nThe first line contains a single integer $t$ ($1 \\leq t \\leq 2 \\cdot 10^4$) \u00a0\u2014 the number of test cases. The description of the test cases follows.\n\nThe first line of each test case contains a single integer $n$ ($2 \\leq n \\leq 3 \\cdot 10^5$) \u00a0\u2014 the length of the array.\n\nThe second line of each test case contains $n$ integers $a_1$, $a_2$, ..., $a_n$ ($1 \\leq a_i \\leq n$, $a_i$ are pairwise distinct)\u00a0\u2014 elements of the array.\n\nIt is guaranteed that the sum of $n$ over all test cases doesn't exceed $3 \\cdot 10^5$.\n\n\n-----Output-----\n\nFor each test case, output on a single line the word \"YES\" if it is possible to reduce the array to a single element using the aforementioned operation, or \"NO\" if it is impossible to do so.\n\n\n-----Example-----\nInput\n4\n3\n1 2 3\n4\n3 1 2 4\n3\n2 3 1\n6\n2 4 6 1 3 5\n\nOutput\nYES\nYES\nNO\nYES\n\n\n\n-----Note-----\n\nFor the first two test cases and the fourth test case, we can operate as follow (the bolded elements are the pair chosen for that operation):\n\n$[\\text{1}, \\textbf{2}, \\textbf{3}] \\rightarrow [\\textbf{1}, \\textbf{2}] \\rightarrow [\\text{1}]$\n\n$[\\text{3}, \\textbf{1}, \\textbf{2}, \\text{4}] \\rightarrow [\\text{3}, \\textbf{1}, \\textbf{4}] \\rightarrow [\\textbf{3}, \\textbf{4}] \\rightarrow [\\text{4}]$\n\n$[\\textbf{2}, \\textbf{4}, \\text{6}, \\text{1}, \\text{3}, \\text{5}] \\rightarrow [\\textbf{4}, \\textbf{6}, \\text{1}, \\text{3}, \\text{5}] \\rightarrow [\\text{4}, \\text{1}, \\textbf{3}, \\textbf{5}] \\rightarrow [\\text{4}, \\textbf{1}, \\textbf{5}] \\rightarrow [\\textbf{4}, \\textbf{5}] \\rightarrow [\\text{4}]$\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nt = int(input())\nfor case in range(t):\n n = int(input())\n arr = list(map(int, input().split()))\n if arr[-1] > arr[0]:\n print(\"YES\")\n else:\n print(\"NO\")\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '4\\n3\\n1 2 3\\n4\\n3 1 2 4\\n3\\n2 3 1\\n6\\n2 4 6 1 3 5\\n', 'output': 'YES\\nYES\\nNO\\nYES\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/1375/C'}","problem_id":"vfc_228","program":"```python\nt = int(input())\nfor case in range(t):\n n = int(input())\n arr = list(map(int, input().split()))\n if arr[-1] > arr[0]:\n print(\"YES\")\n else:\n print(\"NO\")\n```","inputs":"4\n3\n1 2 3\n4\n3 1 2 4\n3\n2 3 1\n6\n2 4 6 1 3 5\n","output":"YES\nYES\nNO\nYES\n","actual_output":"YES\nYES\nNO\nYES\n","execution_success":true,"sample_index":58},{"source":"apps","task_type":"verifiable_code","in_source_id":"58","prompt":"Solve the following coding problem using the programming language python:\n\nYou have a rectangular chocolate bar consisting of n \u00d7 m single squares. You want to eat exactly k squares, so you may need to break the chocolate bar. \n\nIn one move you can break any single rectangular piece of chocolate in two rectangular pieces. You can break only by lines between squares: horizontally or vertically. The cost of breaking is equal to square of the break length.\n\nFor example, if you have a chocolate bar consisting of 2 \u00d7 3 unit squares then you can break it horizontally and get two 1 \u00d7 3 pieces (the cost of such breaking is 3^2 = 9), or you can break it vertically in two ways and get two pieces: 2 \u00d7 1 and 2 \u00d7 2 (the cost of such breaking is 2^2 = 4).\n\nFor several given values n, m and k find the minimum total cost of breaking. You can eat exactly k squares of chocolate if after all operations of breaking there is a set of rectangular pieces of chocolate with the total size equal to k squares. The remaining n\u00b7m - k squares are not necessarily form a single rectangular piece.\n\n\n-----Input-----\n\nThe first line of the input contains a single integer t (1 \u2264 t \u2264 40910)\u00a0\u2014 the number of values n, m and k to process.\n\nEach of the next t lines contains three integers n, m and k (1 \u2264 n, m \u2264 30, 1 \u2264 k \u2264 min(n\u00b7m, 50))\u00a0\u2014 the dimensions of the chocolate bar and the number of squares you want to eat respectively.\n\n\n-----Output-----\n\nFor each n, m and k print the minimum total cost needed to break the chocolate bar, in order to make it possible to eat exactly k squares.\n\n\n-----Examples-----\nInput\n4\n2 2 1\n2 2 3\n2 2 2\n2 2 4\n\nOutput\n5\n5\n4\n0\n\n\n\n-----Note-----\n\nIn the first query of the sample one needs to perform two breaks: to split 2 \u00d7 2 bar into two pieces of 2 \u00d7 1 (cost is 2^2 = 4), to split the resulting 2 \u00d7 1 into two 1 \u00d7 1 pieces (cost is 1^2 = 1). \n\nIn the second query of the sample one wants to eat 3 unit squares. One can use exactly the same strategy as in the first query of the sample.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nmem = [[[0 for i in range(51)] for j in range(31)] for k in range(31)]\n\n\ndef f(n, m, k):\n if mem[n][m][k]:\n return mem[n][m][k]\n if (n*m == k) or (k == 0):\n return 0\n cost = 10**9\n for x in range(1, n//2 + 1):\n for z in range(k+1):\n cost = min(cost, m*m + f(n-x, m, k-z) + f(x, m, z))\n for y in range(1, m//2 + 1):\n for z in range(k+1):\n cost = min(cost, n*n + f(n, m-y, k-z) + f(n, y, z))\n mem[n][m][k] = cost\n return cost\n\n\nt = int(input())\nfor i in range(t):\n n, m, k = list(map(int, input().split()))\n print(f(n, m, k))\n\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '4\\n2 2 1\\n2 2 3\\n2 2 2\\n2 2 4\\n', 'output': '5\\n5\\n4\\n0\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/598/E'}","problem_id":"vfc_232","program":"```python\nmem = [[[0 for i in range(51)] for j in range(31)] for k in range(31)]\n\n\ndef f(n, m, k):\n if mem[n][m][k]:\n return mem[n][m][k]\n if (n*m == k) or (k == 0):\n return 0\n cost = 10**9\n for x in range(1, n//2 + 1):\n for z in range(k+1):\n cost = min(cost, m*m + f(n-x, m, k-z) + f(x, m, z))\n for y in range(1, m//2 + 1):\n for z in range(k+1):\n cost = min(cost, n*n + f(n, m-y, k-z) + f(n, y, z))\n mem[n][m][k] = cost\n return cost\n\n\nt = int(input())\nfor i in range(t):\n n, m, k = list(map(int, input().split()))\n print(f(n, m, k))\n\n\n```","inputs":"4\n2 2 1\n2 2 3\n2 2 2\n2 2 4\n","output":"5\n5\n4\n0\n","actual_output":"5\n5\n4\n0\n","execution_success":true,"sample_index":59},{"source":"apps","task_type":"verifiable_code","in_source_id":"59","prompt":"Solve the following coding problem using the programming language python:\n\nDark is going to attend Motarack's birthday. Dark decided that the gift he is going to give to Motarack is an array $a$ of $n$ non-negative integers.\n\nDark created that array $1000$ years ago, so some elements in that array disappeared. Dark knows that Motarack hates to see an array that has two adjacent elements with a high absolute difference between them. He doesn't have much time so he wants to choose an integer $k$ ($0 \\leq k \\leq 10^{9}$) and replaces all missing elements in the array $a$ with $k$.\n\nLet $m$ be the maximum absolute difference between all adjacent elements (i.e. the maximum value of $|a_i - a_{i+1}|$ for all $1 \\leq i \\leq n - 1$) in the array $a$ after Dark replaces all missing elements with $k$.\n\nDark should choose an integer $k$ so that $m$ is minimized. Can you help him?\n\n\n-----Input-----\n\nThe input consists of multiple test cases. The first line contains a single integer $t$ ($1 \\leq t \\leq 10^4$) \u00a0\u2014 the number of test cases. The description of the test cases follows.\n\nThe first line of each test case contains one integer $n$ ($2 \\leq n \\leq 10^{5}$)\u00a0\u2014 the size of the array $a$.\n\nThe second line of each test case contains $n$ integers $a_1, a_2, \\ldots, a_n$ ($-1 \\leq a_i \\leq 10 ^ {9}$). If $a_i = -1$, then the $i$-th integer is missing. It is guaranteed that at least one integer is missing in every test case.\n\nIt is guaranteed, that the sum of $n$ for all test cases does not exceed $4 \\cdot 10 ^ {5}$.\n\n\n-----Output-----\n\nPrint the answers for each test case in the following format:\n\nYou should print two integers, the minimum possible value of $m$ and an integer $k$ ($0 \\leq k \\leq 10^{9}$) that makes the maximum absolute difference between adjacent elements in the array $a$ equal to $m$.\n\nMake sure that after replacing all the missing elements with $k$, the maximum absolute difference between adjacent elements becomes $m$.\n\nIf there is more than one possible $k$, you can print any of them.\n\n\n-----Example-----\nInput\n7\n5\n-1 10 -1 12 -1\n5\n-1 40 35 -1 35\n6\n-1 -1 9 -1 3 -1\n2\n-1 -1\n2\n0 -1\n4\n1 -1 3 -1\n7\n1 -1 7 5 2 -1 5\n\nOutput\n1 11\n5 35\n3 6\n0 42\n0 0\n1 2\n3 4\n\n\n\n-----Note-----\n\nIn the first test case after replacing all missing elements with $11$ the array becomes $[11, 10, 11, 12, 11]$. The absolute difference between any adjacent elements is $1$. It is impossible to choose a value of $k$, such that the absolute difference between any adjacent element will be $\\leq 0$. So, the answer is $1$.\n\nIn the third test case after replacing all missing elements with $6$ the array becomes $[6, 6, 9, 6, 3, 6]$. $|a_1 - a_2| = |6 - 6| = 0$; $|a_2 - a_3| = |6 - 9| = 3$; $|a_3 - a_4| = |9 - 6| = 3$; $|a_4 - a_5| = |6 - 3| = 3$; $|a_5 - a_6| = |3 - 6| = 3$. \n\nSo, the maximum difference between any adjacent elements is $3$.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfor _ in range(int(input())):\n n=int(input())\n a=list(map(int,input().split()))\n ans,small,big=0,2*10**9,-1\n for i in range(len(a)-1):\n if a[i]==-1 and a[i+1]!=-1:\n small=min(small, a[i+1])\n big=max(big, a[i+1])\n if a[i]!=-1 and a[i+1]==-1:\n small = min(small, a[i])\n big = max(big, a[i])\n if a[i]!=-1 and a[i+1]!=-1:\n ans=max(ans, abs(a[i]-a[i+1]))\n if big==-1:print(ans, 0)\n else:\n x=(small+big)//2\n ans=max(ans, abs(big-x))\n ans=max(ans, abs(x-small))\n print(ans, x)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '7\\n5\\n-1 10 -1 12 -1\\n5\\n-1 40 35 -1 35\\n6\\n-1 -1 9 -1 3 -1\\n2\\n-1 -1\\n2\\n0 -1\\n4\\n1 -1 3 -1\\n7\\n1 -1 7 5 2 -1 5\\n', 'output': '1 11\\n5 37\\n3 6\\n0 0\\n0 0\\n1 2\\n3 4\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/1301/B'}","problem_id":"vfc_236","program":"```python\nfor _ in range(int(input())):\n n=int(input())\n a=list(map(int,input().split()))\n ans,small,big=0,2*10**9,-1\n for i in range(len(a)-1):\n if a[i]==-1 and a[i+1]!=-1:\n small=min(small, a[i+1])\n big=max(big, a[i+1])\n if a[i]!=-1 and a[i+1]==-1:\n small = min(small, a[i])\n big = max(big, a[i])\n if a[i]!=-1 and a[i+1]!=-1:\n ans=max(ans, abs(a[i]-a[i+1]))\n if big==-1:print(ans, 0)\n else:\n x=(small+big)//2\n ans=max(ans, abs(big-x))\n ans=max(ans, abs(x-small))\n print(ans, x)\n```","inputs":"7\n5\n-1 10 -1 12 -1\n5\n-1 40 35 -1 35\n6\n-1 -1 9 -1 3 -1\n2\n-1 -1\n2\n0 -1\n4\n1 -1 3 -1\n7\n1 -1 7 5 2 -1 5\n","output":"1 11\n5 37\n3 6\n0 0\n0 0\n1 2\n3 4\n","actual_output":"1 11\n5 37\n3 6\n0 0\n0 0\n1 2\n3 4\n","execution_success":true,"sample_index":60},{"source":"apps","task_type":"verifiable_code","in_source_id":"60","prompt":"Solve the following coding problem using the programming language python:\n\nIn order to celebrate Twice's 5th anniversary, Tzuyu and Sana decided to play a game.\n\nTzuyu gave Sana two integers $a$ and $b$ and a really important quest.\n\nIn order to complete the quest, Sana has to output the smallest possible value of ($a \\oplus x$) + ($b \\oplus x$) for any given $x$, where $\\oplus$ denotes the bitwise XOR operation. \n\n\n-----Input-----\n\nEach test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \\le t \\le 10^{4}$). Description of the test cases follows.\n\nThe only line of each test case contains two integers $a$ and $b$ ($1 \\le a, b \\le 10^{9}$).\n\n\n-----Output-----\n\nFor each testcase, output the smallest possible value of the given expression.\n\n\n-----Example-----\nInput\n6\n6 12\n4 9\n59 832\n28 14\n4925 2912\n1 1\n\nOutput\n10\n13\n891\n18\n6237\n0\n\n\n\n-----Note-----\n\nFor the first test case Sana can choose $x=4$ and the value will be ($6 \\oplus 4$) + ($12 \\oplus 4$) = $2 + 8$ = $10$. It can be shown that this is the smallest possible value.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nn = int(input())\nfor _ in range(n):\n a, b = list(map(int, input().split()))\n print(a ^ b)\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '6\\n6 12\\n4 9\\n59 832\\n28 14\\n4925 2912\\n1 1\\n', 'output': '10\\n13\\n891\\n18\\n6237\\n0\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/1421/A'}","problem_id":"vfc_240","program":"```python\nn = int(input())\nfor _ in range(n):\n a, b = list(map(int, input().split()))\n print(a ^ b)\n\n```","inputs":"6\n6 12\n4 9\n59 832\n28 14\n4925 2912\n1 1\n","output":"10\n13\n891\n18\n6237\n0\n","actual_output":"10\n13\n891\n18\n6237\n0\n","execution_success":true,"sample_index":61},{"source":"apps","task_type":"verifiable_code","in_source_id":"61","prompt":"Solve the following coding problem using the programming language python:\n\nYou are given a permutation $p_1, p_2, \\dots, p_n$. Recall that sequence of $n$ integers is called a permutation if it contains all integers from $1$ to $n$ exactly once.\n\nFind three indices $i$, $j$ and $k$ such that: $1 \\le i < j < k \\le n$; $p_i < p_j$ and $p_j > p_k$. Or say that there are no such indices.\n\n\n-----Input-----\n\nThe first line contains a single integer $T$ ($1 \\le T \\le 200$)\u00a0\u2014 the number of test cases.\n\nNext $2T$ lines contain test cases\u00a0\u2014 two lines per test case. The first line of each test case contains the single integer $n$ ($3 \\le n \\le 1000$)\u00a0\u2014 the length of the permutation $p$.\n\nThe second line contains $n$ integers $p_1, p_2, \\dots, p_n$ ($1 \\le p_i \\le n$; $p_i \\neq p_j$ if $i \\neq j$)\u00a0\u2014 the permutation $p$.\n\n\n-----Output-----\n\nFor each test case: if there are such indices $i$, $j$ and $k$, print YES (case insensitive) and the indices themselves; if there are no such indices, print NO (case insensitive). \n\nIf there are multiple valid triples of indices, print any of them.\n\n\n-----Example-----\nInput\n3\n4\n2 1 4 3\n6\n4 6 1 2 5 3\n5\n5 3 1 2 4\n\nOutput\nYES\n2 3 4\nYES\n3 5 6\nNO\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nimport sys\nimport math\n#from queue import *\nimport random\n#sys.setrecursionlimit(int(1e6))\ninput = sys.stdin.readline\n \n############ ---- USER DEFINED INPUT FUNCTIONS ---- ############\ndef inp():\n return(int(input()))\ndef inara():\n return(list(map(int,input().split())))\ndef insr():\n s = input()\n return(list(s[:len(s) - 1]))\ndef invr():\n return(list(map(int,input().split())))\n################################################################\n############ ---- THE ACTUAL CODE STARTS BELOW ---- ############\n\nt=inp()\n\nfor _ in range(t):\n\tn=inp()\n\tara=inara()\n\t\n\tans=[]\n\t\n\tfor i in range(1,n-1):\n\t\tif ara[i]>ara[i-1] and ara[i]>ara[i+1]:\n\t\t\tans.append(i)\n\t\t\tans.append(i+1)\n\t\t\tans.append(i+2)\n\t\t\tbreak\n\t\n\tif len(ans)==0:\n\t\tprint(\"NO\")\n\telse:\n\t\tprint(\"YES\")\n\t\tprint(*ans)\n\t\n\t\n\t\t\t\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\n4\\n2 1 4 3\\n6\\n4 6 1 2 5 3\\n5\\n5 3 1 2 4\\n', 'output': 'YES\\n2 3 4\\nYES\\n1 2 3\\nNO\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/1380/A'}","problem_id":"vfc_244","program":"```python\nimport sys\nimport math\n#from queue import *\nimport random\n#sys.setrecursionlimit(int(1e6))\ninput = sys.stdin.readline\n \n############ ---- USER DEFINED INPUT FUNCTIONS ---- ############\ndef inp():\n return(int(input()))\ndef inara():\n return(list(map(int,input().split())))\ndef insr():\n s = input()\n return(list(s[:len(s) - 1]))\ndef invr():\n return(list(map(int,input().split())))\n################################################################\n############ ---- THE ACTUAL CODE STARTS BELOW ---- ############\n\nt=inp()\n\nfor _ in range(t):\n\tn=inp()\n\tara=inara()\n\t\n\tans=[]\n\t\n\tfor i in range(1,n-1):\n\t\tif ara[i]>ara[i-1] and ara[i]>ara[i+1]:\n\t\t\tans.append(i)\n\t\t\tans.append(i+1)\n\t\t\tans.append(i+2)\n\t\t\tbreak\n\t\n\tif len(ans)==0:\n\t\tprint(\"NO\")\n\telse:\n\t\tprint(\"YES\")\n\t\tprint(*ans)\n\t\n\t\n\t\t\t\n\n```","inputs":"3\n4\n2 1 4 3\n6\n4 6 1 2 5 3\n5\n5 3 1 2 4\n","output":"YES\n2 3 4\nYES\n1 2 3\nNO\n","actual_output":"YES\n2 3 4\nYES\n1 2 3\nNO\n","execution_success":true,"sample_index":62},{"source":"apps","task_type":"verifiable_code","in_source_id":"62","prompt":"Solve the following coding problem using the programming language python:\n\nPolycarp wants to assemble his own keyboard. Layouts with multiple rows are too complicated for him \u2014 his keyboard will consist of only one row, where all $26$ lowercase Latin letters will be arranged in some order.\n\nPolycarp uses the same password $s$ on all websites where he is registered (it is bad, but he doesn't care). He wants to assemble a keyboard that will allow to type this password very easily. He doesn't like to move his fingers while typing the password, so, for each pair of adjacent characters in $s$, they should be adjacent on the keyboard. For example, if the password is abacaba, then the layout cabdefghi... is perfect, since characters a and c are adjacent on the keyboard, and a and b are adjacent on the keyboard. It is guaranteed that there are no two adjacent equal characters in $s$, so, for example, the password cannot be password (two characters s are adjacent).\n\nCan you help Polycarp with choosing the perfect layout of the keyboard, if it is possible?\n\n\n-----Input-----\n\nThe first line contains one integer $T$ ($1 \\le T \\le 1000$) \u2014 the number of test cases.\n\nThen $T$ lines follow, each containing one string $s$ ($1 \\le |s| \\le 200$) representing the test case. $s$ consists of lowercase Latin letters only. There are no two adjacent equal characters in $s$.\n\n\n-----Output-----\n\nFor each test case, do the following:\n\n if it is impossible to assemble a perfect keyboard, print NO (in upper case, it matters in this problem); otherwise, print YES (in upper case), and then a string consisting of $26$ lowercase Latin letters \u2014 the perfect layout. Each Latin letter should appear in this string exactly once. If there are multiple answers, print any of them. \n\n\n-----Example-----\nInput\n5\nababa\ncodedoca\nabcda\nzxzytyz\nabcdefghijklmnopqrstuvwxyza\n\nOutput\nYES\nbacdefghijklmnopqrstuvwxyz\nYES\nedocabfghijklmnpqrstuvwxyz\nNO\nYES\nxzytabcdefghijklmnopqrsuvw\nNO\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nT = int(input())\n\n\n\ndef solve(S):\n res = [S[0]]\n pos = 0 # think...\n for s in S[1:]:\n # can we change?\n if 0 <= pos-1 < len(res) and res[pos-1] == s:\n pos = pos-1\n elif 0 <= pos+1 < len(res) and res[pos+1] == s:\n pos = pos+1\n elif pos == 0 and s not in res:\n res.insert(0, s) # pos is still 0\n elif pos == len(res)-1 and s not in res:\n res.append(s)\n pos += 1\n else: return None\n #print(''.join(res))\n for x in range(ord('a'), ord('z')+1):\n x = chr(x)\n if x not in res:\n res.append(x)\n return ''.join(res)\n\nfor _ in range(T):\n res = solve(input())\n if res is None:\n print('NO')\n else:\n print('YES')\n print(res)\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '5\\nababa\\ncodedoca\\nabcda\\nzxzytyz\\nabcdefghijklmnopqrstuvwxyza\\n', 'output': 'YES\\nbacdefghijklmnopqrstuvwxyz\\nYES\\nedocabfghijklmnpqrstuvwxyz\\nNO\\nYES\\nxzytabcdefghijklmnopqrsuvw\\nNO\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/1303/C'}","problem_id":"vfc_248","program":"```python\nT = int(input())\n\n\n\ndef solve(S):\n res = [S[0]]\n pos = 0 # think...\n for s in S[1:]:\n # can we change?\n if 0 <= pos-1 < len(res) and res[pos-1] == s:\n pos = pos-1\n elif 0 <= pos+1 < len(res) and res[pos+1] == s:\n pos = pos+1\n elif pos == 0 and s not in res:\n res.insert(0, s) # pos is still 0\n elif pos == len(res)-1 and s not in res:\n res.append(s)\n pos += 1\n else: return None\n #print(''.join(res))\n for x in range(ord('a'), ord('z')+1):\n x = chr(x)\n if x not in res:\n res.append(x)\n return ''.join(res)\n\nfor _ in range(T):\n res = solve(input())\n if res is None:\n print('NO')\n else:\n print('YES')\n print(res)\n\n```","inputs":"5\nababa\ncodedoca\nabcda\nzxzytyz\nabcdefghijklmnopqrstuvwxyza\n","output":"YES\nbacdefghijklmnopqrstuvwxyz\nYES\nedocabfghijklmnpqrstuvwxyz\nNO\nYES\nxzytabcdefghijklmnopqrsuvw\nNO\n","actual_output":"YES\nbacdefghijklmnopqrstuvwxyz\nYES\nedocabfghijklmnpqrstuvwxyz\nNO\nYES\nxzytabcdefghijklmnopqrsuvw\nNO\n","execution_success":true,"sample_index":63},{"source":"apps","task_type":"verifiable_code","in_source_id":"63","prompt":"Solve the following coding problem using the programming language python:\n\nLee just became Master in Codeforces, and so, he went out to buy some gifts for his friends. He bought $n$ integers, now it's time to distribute them between his friends rationally...\n\nLee has $n$ integers $a_1, a_2, \\ldots, a_n$ in his backpack and he has $k$ friends. Lee would like to distribute all integers in his backpack between his friends, such that the $i$-th friend will get exactly $w_i$ integers and each integer will be handed over to exactly one friend.\n\nLet's define the happiness of a friend as the sum of the maximum and the minimum integer he'll get.\n\nLee would like to make his friends as happy as possible, in other words, he'd like to maximize the sum of friends' happiness. Now he asks you to calculate the maximum sum of friends' happiness.\n\n\n-----Input-----\n\nThe first line contains one integer $t$ ($1 \\le t \\le 10^4$)\u00a0\u2014 the number of test cases.\n\nNext $3t$ lines contain test cases\u00a0\u2014 one per three lines.\n\nThe first line of each test case contains two integers $n$ and $k$ ($1 \\le n \\le 2 \\cdot 10^5$; $1 \\le k \\le n$)\u00a0\u2014 the number of integers Lee has and the number of Lee's friends.\n\nThe second line of each test case contains $n$ integers $a_1, a_2, \\ldots, a_n$ ($-10^9 \\le a_i \\le 10^9$)\u00a0\u2014 the integers Lee has.\n\nThe third line contains $k$ integers $w_1, w_2, \\ldots, w_k$ ($1 \\le w_i \\le n$; $w_1 + w_2 + \\ldots + w_k = n$)\u00a0\u2014 the number of integers Lee wants to give to each friend. \n\nIt's guaranteed that the sum of $n$ over test cases is less than or equal to $2 \\cdot 10^5$.\n\n\n-----Output-----\n\nFor each test case, print a single integer\u00a0\u2014 the maximum sum of happiness Lee can achieve.\n\n\n-----Example-----\nInput\n3\n4 2\n1 13 7 17\n1 3\n6 2\n10 10 10 10 11 11\n3 3\n4 4\n1000000000 1000000000 1000000000 1000000000\n1 1 1 1\n\nOutput\n48\n42\n8000000000\n\n\n\n-----Note-----\n\nIn the first test case, Lee should give the greatest integer to the first friend (his happiness will be $17 + 17$) and remaining integers to the second friend (his happiness will be $13 + 1$).\n\nIn the second test case, Lee should give $\\{10, 10, 11\\}$ to the first friend and to the second friend, so the total happiness will be equal to $(11 + 10) + (11 + 10)$\n\nIn the third test case, Lee has four friends and four integers, it doesn't matter how he distributes the integers between his friends.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\ndef solve():\n n, k = map(int,input().split())\n lst1 = list(map(int,input().split()))\n lst1.sort(reverse=True)\n ind = 0\n ans = 0\n lst2 = list(map(int,input().split()))\n lst2.sort()\n for i in range(k):\n lst2[i] -= 1\n if lst2[i] == 0: ans += lst1[ind]\n ans += lst1[ind]\n ind += 1\n lst2.sort()\n for i in lst2:\n if i != 0:\n ind += i - 1\n ans += lst1[ind]\n ind += 1\n print(ans)\nfor i in range(int(input())):\n solve()\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\n4 2\\n1 13 7 17\\n1 3\\n6 2\\n10 10 10 10 11 11\\n3 3\\n4 4\\n1000000000 1000000000 1000000000 1000000000\\n1 1 1 1\\n', 'output': '48\\n42\\n8000000000\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/1369/C'}","problem_id":"vfc_252","program":"```python\ndef solve():\n n, k = map(int,input().split())\n lst1 = list(map(int,input().split()))\n lst1.sort(reverse=True)\n ind = 0\n ans = 0\n lst2 = list(map(int,input().split()))\n lst2.sort()\n for i in range(k):\n lst2[i] -= 1\n if lst2[i] == 0: ans += lst1[ind]\n ans += lst1[ind]\n ind += 1\n lst2.sort()\n for i in lst2:\n if i != 0:\n ind += i - 1\n ans += lst1[ind]\n ind += 1\n print(ans)\nfor i in range(int(input())):\n solve()\n```","inputs":"3\n4 2\n1 13 7 17\n1 3\n6 2\n10 10 10 10 11 11\n3 3\n4 4\n1000000000 1000000000 1000000000 1000000000\n1 1 1 1\n","output":"48\n42\n8000000000\n","actual_output":"48\n42\n8000000000\n","execution_success":true,"sample_index":64},{"source":"apps","task_type":"verifiable_code","in_source_id":"65","prompt":"Solve the following coding problem using the programming language python:\n\nYou and your friend are playing the game Mortal Kombat XI. You are trying to pass a challenge tower. There are $n$ bosses in this tower, numbered from $1$ to $n$. The type of the $i$-th boss is $a_i$. If the $i$-th boss is easy then its type is $a_i = 0$, otherwise this boss is hard and its type is $a_i = 1$.\n\nDuring one session, either you or your friend can kill one or two bosses (neither you nor your friend can skip the session, so the minimum number of bosses killed during one session is at least one). After your friend session, your session begins, then again your friend session begins, your session begins, and so on. The first session is your friend's session.\n\nYour friend needs to get good because he can't actually kill hard bosses. To kill them, he uses skip points. One skip point can be used to kill one hard boss.\n\nYour task is to find the minimum number of skip points your friend needs to use so you and your friend kill all $n$ bosses in the given order.\n\nFor example: suppose $n = 8$, $a = [1, 0, 1, 1, 0, 1, 1, 1]$. Then the best course of action is the following:\n\n your friend kills two first bosses, using one skip point for the first boss; you kill the third and the fourth bosses; your friend kills the fifth boss; you kill the sixth and the seventh bosses; your friend kills the last boss, using one skip point, so the tower is completed using two skip points. \n\nYou have to answer $t$ independent test cases.\n\n\n-----Input-----\n\nThe first line of the input contains one integer $t$ ($1 \\le t \\le 2 \\cdot 10^4$) \u2014 the number of test cases. Then $t$ test cases follow.\n\nThe first line of the test case contains one integer $n$ ($1 \\le n \\le 2 \\cdot 10^5$) \u2014 the number of bosses. The second line of the test case contains $n$ integers $a_1, a_2, \\dots, a_n$ ($0 \\le a_i \\le 1$), where $a_i$ is the type of the $i$-th boss.\n\nIt is guaranteed that the sum of $n$ does not exceed $2 \\cdot 10^5$ ($\\sum n \\le 2 \\cdot 10^5$).\n\n\n-----Output-----\n\nFor each test case, print the answer: the minimum number of skip points your friend needs to use so you and your friend kill all $n$ bosses in the given order.\n\n\n-----Example-----\nInput\n6\n8\n1 0 1 1 0 1 1 1\n5\n1 1 1 1 0\n7\n1 1 1 1 0 0 1\n6\n1 1 1 1 1 1\n1\n1\n1\n0\n\nOutput\n2\n2\n2\n2\n1\n0\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nimport math\nfrom collections import deque\nfrom sys import stdin, stdout\nfrom string import ascii_letters\nimport sys\nletters = ascii_letters\ninput = stdin.readline\n#print = stdout.write\n\nfor _ in range(int(input())):\n n = int(input())\n arr = list(map(int, input().split()))\n ans = [999999999] * n\n ans[0] = 1 if arr[0] == 1 else 0\n if n > 1:\n ans[1] = ans[0]\n if n > 2:\n ans[2] = ans[0]\n for i in range(n):\n if i + 1 >= n:\n continue\n if arr[i + 1] == 1:\n ans[i + 1] = min(ans[i + 1], ans[i] + 1)\n if i + 2 < n:\n ans[i + 2] = min(ans[i + 2], ans[i] + 1)\n if i + 3 < n: \n ans[i + 3] = min(ans[i + 3], ans[i] + 1)\n else:\n ans[i + 1] = min(ans[i + 1], ans[i])\n if i + 2 < n:\n ans[i + 2] = min(ans[i + 2], ans[i])\n if i + 3 < n:\n ans[i + 3] = min(ans[i + 3], ans[i])\n print(ans[-1])\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '6\\n8\\n1 0 1 1 0 1 1 1\\n5\\n1 1 1 1 0\\n7\\n1 1 1 1 0 0 1\\n6\\n1 1 1 1 1 1\\n1\\n1\\n1\\n0\\n', 'output': '2\\n2\\n2\\n2\\n1\\n0\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/1418/C'}","problem_id":"vfc_260","program":"```python\nimport math\nfrom collections import deque\nfrom sys import stdin, stdout\nfrom string import ascii_letters\nimport sys\nletters = ascii_letters\ninput = stdin.readline\n#print = stdout.write\n\nfor _ in range(int(input())):\n n = int(input())\n arr = list(map(int, input().split()))\n ans = [999999999] * n\n ans[0] = 1 if arr[0] == 1 else 0\n if n > 1:\n ans[1] = ans[0]\n if n > 2:\n ans[2] = ans[0]\n for i in range(n):\n if i + 1 >= n:\n continue\n if arr[i + 1] == 1:\n ans[i + 1] = min(ans[i + 1], ans[i] + 1)\n if i + 2 < n:\n ans[i + 2] = min(ans[i + 2], ans[i] + 1)\n if i + 3 < n: \n ans[i + 3] = min(ans[i + 3], ans[i] + 1)\n else:\n ans[i + 1] = min(ans[i + 1], ans[i])\n if i + 2 < n:\n ans[i + 2] = min(ans[i + 2], ans[i])\n if i + 3 < n:\n ans[i + 3] = min(ans[i + 3], ans[i])\n print(ans[-1])\n\n```","inputs":"6\n8\n1 0 1 1 0 1 1 1\n5\n1 1 1 1 0\n7\n1 1 1 1 0 0 1\n6\n1 1 1 1 1 1\n1\n1\n1\n0\n","output":"2\n2\n2\n2\n1\n0\n","actual_output":"2\n2\n2\n2\n1\n0\n","execution_success":true,"sample_index":66},{"source":"apps","task_type":"verifiable_code","in_source_id":"67","prompt":"Solve the following coding problem using the programming language python:\n\nThis problem is different from the easy version. In this version Ujan makes at most $2n$ swaps. In addition, $k \\le 1000, n \\le 50$ and it is necessary to print swaps themselves. You can hack this problem if you solve it. But you can hack the previous problem only if you solve both problems.\n\nAfter struggling and failing many times, Ujan decided to try to clean up his house again. He decided to get his strings in order first.\n\nUjan has two distinct strings $s$ and $t$ of length $n$ consisting of only of lowercase English characters. He wants to make them equal. Since Ujan is lazy, he will perform the following operation at most $2n$ times: he takes two positions $i$ and $j$ ($1 \\le i,j \\le n$, the values $i$ and $j$ can be equal or different), and swaps the characters $s_i$ and $t_j$.\n\nUjan's goal is to make the strings $s$ and $t$ equal. He does not need to minimize the number of performed operations: any sequence of operations of length $2n$ or shorter is suitable.\n\n\n-----Input-----\n\nThe first line contains a single integer $k$ ($1 \\leq k \\leq 1000$), the number of test cases.\n\nFor each of the test cases, the first line contains a single integer $n$ ($2 \\leq n \\leq 50$), the length of the strings $s$ and $t$. \n\nEach of the next two lines contains the strings $s$ and $t$, each having length exactly $n$. The strings consist only of lowercase English letters. It is guaranteed that strings are different.\n\n\n-----Output-----\n\nFor each test case, output \"Yes\" if Ujan can make the two strings equal with at most $2n$ operations and \"No\" otherwise. You can print each letter in any case (upper or lower).\n\nIn the case of \"Yes\" print $m$ ($1 \\le m \\le 2n$) on the next line, where $m$ is the number of swap operations to make the strings equal. Then print $m$ lines, each line should contain two integers $i, j$ ($1 \\le i, j \\le n$) meaning that Ujan swaps $s_i$ and $t_j$ during the corresponding operation. You do not need to minimize the number of operations. Any sequence of length not more than $2n$ is suitable.\n\n\n-----Example-----\nInput\n4\n5\nsouse\nhouhe\n3\ncat\ndog\n2\naa\naz\n3\nabc\nbca\n\nOutput\nYes\n1\n1 4\nNo\nNo\nYes\n3\n1 2\n3 1\n2 3\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfor _ in range(int(input())):\n n = int(input())\n s = input()\n t = input()\n\n d = {}\n for i in range(ord('a'), ord('z') + 1):\n d[chr(i)] = 0\n\n for cs in s:\n d[cs] += 1\n for ct in t:\n d[ct] += 1\n\n ok = True\n for e in d:\n if d[e] % 2 == 1:\n ok = False\n\n if not ok:\n print(\"No\")\n else:\n print(\"Yes\")\n\n changes = []\n\n s, t = list(s), list(t)\n for i in range(n-1):\n if s[i] != t[i]:\n r = (0, -1)\n for j in range(i+1, n):\n if s[j] == t[i]:\n r = (j, 0)\n\n for j in range(i+1, n):\n if t[j] == t[i]:\n r = (j, 1)\n\n if r[1] == 0:\n changes += [(r[0], i+1), (i, i+1)]\n s[r[0]], t[i+1] = t[i+1], s[r[0]]\n s[i], t[i+1] = t[i+1], s[i]\n elif r[1] == 1:\n changes += [(i, r[0])]\n s[i], t[r[0]] = t[r[0]], s[i]\n\n print(len(changes))\n for change in changes:\n x, y = change\n print(x+1, y+1)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '4\\n5\\nsouse\\nhouhe\\n3\\ncat\\ndog\\n2\\naa\\naz\\n3\\nabc\\nbca\\n', 'output': 'Yes\\n1\\n1 4\\nNo\\nNo\\nYes\\n3\\n2 2\\n1 2\\n2 3\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/1243/B2'}","problem_id":"vfc_268","program":"```python\nfor _ in range(int(input())):\n n = int(input())\n s = input()\n t = input()\n\n d = {}\n for i in range(ord('a'), ord('z') + 1):\n d[chr(i)] = 0\n\n for cs in s:\n d[cs] += 1\n for ct in t:\n d[ct] += 1\n\n ok = True\n for e in d:\n if d[e] % 2 == 1:\n ok = False\n\n if not ok:\n print(\"No\")\n else:\n print(\"Yes\")\n\n changes = []\n\n s, t = list(s), list(t)\n for i in range(n-1):\n if s[i] != t[i]:\n r = (0, -1)\n for j in range(i+1, n):\n if s[j] == t[i]:\n r = (j, 0)\n\n for j in range(i+1, n):\n if t[j] == t[i]:\n r = (j, 1)\n\n if r[1] == 0:\n changes += [(r[0], i+1), (i, i+1)]\n s[r[0]], t[i+1] = t[i+1], s[r[0]]\n s[i], t[i+1] = t[i+1], s[i]\n elif r[1] == 1:\n changes += [(i, r[0])]\n s[i], t[r[0]] = t[r[0]], s[i]\n\n print(len(changes))\n for change in changes:\n x, y = change\n print(x+1, y+1)\n```","inputs":"4\n5\nsouse\nhouhe\n3\ncat\ndog\n2\naa\naz\n3\nabc\nbca\n","output":"Yes\n1\n1 4\nNo\nNo\nYes\n3\n2 2\n1 2\n2 3\n","actual_output":"Yes\n1\n1 4\nNo\nNo\nYes\n3\n2 2\n1 2\n2 3\n","execution_success":true,"sample_index":68},{"source":"apps","task_type":"verifiable_code","in_source_id":"68","prompt":"Solve the following coding problem using the programming language python:\n\nYou have a string $s$ consisting of $n$ characters. Each character is either 0 or 1.\n\nYou can perform operations on the string. Each operation consists of two steps: select an integer $i$ from $1$ to the length of the string $s$, then delete the character $s_i$ (the string length gets reduced by $1$, the indices of characters to the right of the deleted one also get reduced by $1$); if the string $s$ is not empty, delete the maximum length prefix consisting of the same characters (the indices of the remaining characters and the string length get reduced by the length of the deleted prefix). \n\nNote that both steps are mandatory in each operation, and their order cannot be changed.\n\nFor example, if you have a string $s =$ 111010, the first operation can be one of the following: select $i = 1$: we'll get 111010 $\\rightarrow$ 11010 $\\rightarrow$ 010; select $i = 2$: we'll get 111010 $\\rightarrow$ 11010 $\\rightarrow$ 010; select $i = 3$: we'll get 111010 $\\rightarrow$ 11010 $\\rightarrow$ 010; select $i = 4$: we'll get 111010 $\\rightarrow$ 11110 $\\rightarrow$ 0; select $i = 5$: we'll get 111010 $\\rightarrow$ 11100 $\\rightarrow$ 00; select $i = 6$: we'll get 111010 $\\rightarrow$ 11101 $\\rightarrow$ 01. \n\nYou finish performing operations when the string $s$ becomes empty. What is the maximum number of operations you can perform?\n\n\n-----Input-----\n\nThe first line contains a single integer $t$ ($1 \\le t \\le 1000$)\u00a0\u2014 the number of test cases.\n\nThe first line of each test case contains a single integer $n$ ($1 \\le n \\le 2 \\cdot 10^5$)\u00a0\u2014 the length of the string $s$.\n\nThe second line contains string $s$ of $n$ characters. Each character is either 0 or 1.\n\nIt's guaranteed that the total sum of $n$ over test cases doesn't exceed $2 \\cdot 10^5$.\n\n\n-----Output-----\n\nFor each test case, print a single integer\u00a0\u2014 the maximum number of operations you can perform.\n\n\n-----Example-----\nInput\n5\n6\n111010\n1\n0\n1\n1\n2\n11\n6\n101010\n\nOutput\n3\n1\n1\n1\n3\n\n\n\n-----Note-----\n\nIn the first test case, you can, for example, select $i = 2$ and get string 010 after the first operation. After that, you can select $i = 3$ and get string 1. Finally, you can only select $i = 1$ and get empty string.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfrom itertools import groupby\ndef main():\n N = int(input())\n S = input()\n \n C = [len(list(x[1])) for x in groupby(S)]\n M = len(C)\n dup_idx = []\n for i, c in enumerate(C):\n if c > 1:\n dup_idx.append(i)\n \n dup_idx.reverse()\n\n curr = 0\n while dup_idx:\n i = dup_idx[-1]\n\n if i < curr:\n dup_idx.pop()\n continue\n\n C[i] -= 1\n if C[i] == 1:\n dup_idx.pop()\n\n curr += 1\n\n ans = curr + (M-curr+1)//2\n \n print(ans)\n\ndef __starting_point():\n for __ in [0]*int(input()):\n main()\n\n__starting_point()\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '5\\n6\\n111010\\n1\\n0\\n1\\n1\\n2\\n11\\n6\\n101010\\n', 'output': '3\\n1\\n1\\n1\\n3\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/1430/D'}","problem_id":"vfc_272","program":"```python\nfrom itertools import groupby\ndef main():\n N = int(input())\n S = input()\n \n C = [len(list(x[1])) for x in groupby(S)]\n M = len(C)\n dup_idx = []\n for i, c in enumerate(C):\n if c > 1:\n dup_idx.append(i)\n \n dup_idx.reverse()\n\n curr = 0\n while dup_idx:\n i = dup_idx[-1]\n\n if i < curr:\n dup_idx.pop()\n continue\n\n C[i] -= 1\n if C[i] == 1:\n dup_idx.pop()\n\n curr += 1\n\n ans = curr + (M-curr+1)//2\n \n print(ans)\n\ndef __starting_point():\n for __ in [0]*int(input()):\n main()\n\n__starting_point()\n```","inputs":"5\n6\n111010\n1\n0\n1\n1\n2\n11\n6\n101010\n","output":"3\n1\n1\n1\n3\n","actual_output":"3\n1\n1\n1\n3\n","execution_success":true,"sample_index":69},{"source":"apps","task_type":"verifiable_code","in_source_id":"69","prompt":"Solve the following coding problem using the programming language python:\n\nBertown is a city with $n$ buildings in a straight line.\n\nThe city's security service discovered that some buildings were mined. A map was compiled, which is a string of length $n$, where the $i$-th character is \"1\" if there is a mine under the building number $i$ and \"0\" otherwise.\n\nBertown's best sapper knows how to activate mines so that the buildings above them are not damaged. When a mine under the building numbered $x$ is activated, it explodes and activates two adjacent mines under the buildings numbered $x-1$ and $x+1$ (if there were no mines under the building, then nothing happens). Thus, it is enough to activate any one mine on a continuous segment of mines to activate all the mines of this segment. For manual activation of one mine, the sapper takes $a$ coins. He can repeat this operation as many times as you want.\n\nAlso, a sapper can place a mine under a building if it wasn't there. For such an operation, he takes $b$ coins. He can also repeat this operation as many times as you want.\n\nThe sapper can carry out operations in any order.\n\nYou want to blow up all the mines in the city to make it safe. Find the minimum number of coins that the sapper will have to pay so that after his actions there are no mines left in the city.\n\n\n-----Input-----\n\nThe first line contains one positive integer $t$ ($1 \\le t \\le 10^5$)\u00a0\u2014 the number of test cases. Then $t$ test cases follow.\n\nEach test case begins with a line containing two integers $a$ and $b$ ($1 \\le a, b \\le 1000$)\u00a0\u2014 the cost of activating and placing one mine, respectively.\n\nThe next line contains a map of mines in the city\u00a0\u2014 a string consisting of zeros and ones.\n\nThe sum of the string lengths for all test cases does not exceed $10^5$.\n\n\n-----Output-----\n\nFor each test case, output one integer\u00a0\u2014 the minimum number of coins that the sapper will have to pay.\n\n\n-----Example-----\nInput\n2\n1 1\n01000010\n5 1\n01101110\n\nOutput\n2\n6\n\n\n\n-----Note-----\n\nIn the second test case, if we place a mine under the fourth building and then activate it, then all mines on the field are activated. The cost of such operations is six, $b=1$ coin for placing a mine and $a=5$ coins for activating.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nt = int(input())\n\nfor case in range(t):\n a, b = list(map(int, input().split()))\n s = input()\n\n z = 10000\n total = 0\n act = False\n\n for i in range(len(s)):\n cur = s[i]\n if cur == '0':\n z += 1\n act = False\n else:\n if not act:\n act = True\n total += min(a, b * z)\n z = 0\n\n print(total)\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n1 1\\n01000010\\n5 1\\n01101110\\n', 'output': '2\\n6\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/1443/B'}","problem_id":"vfc_276","program":"```python\nt = int(input())\n\nfor case in range(t):\n a, b = list(map(int, input().split()))\n s = input()\n\n z = 10000\n total = 0\n act = False\n\n for i in range(len(s)):\n cur = s[i]\n if cur == '0':\n z += 1\n act = False\n else:\n if not act:\n act = True\n total += min(a, b * z)\n z = 0\n\n print(total)\n\n```","inputs":"2\n1 1\n01000010\n5 1\n01101110\n","output":"2\n6\n","actual_output":"2\n6\n","execution_success":true,"sample_index":70},{"source":"apps","task_type":"verifiable_code","in_source_id":"70","prompt":"Solve the following coding problem using the programming language python:\n\nWord $s$ of length $n$ is called $k$-complete if $s$ is a palindrome, i.e. $s_i=s_{n+1-i}$ for all $1 \\le i \\le n$; $s$ has a period of $k$, i.e. $s_i=s_{k+i}$ for all $1 \\le i \\le n-k$. \n\nFor example, \"abaaba\" is a $3$-complete word, while \"abccba\" is not.\n\nBob is given a word $s$ of length $n$ consisting of only lowercase Latin letters and an integer $k$, such that $n$ is divisible by $k$. He wants to convert $s$ to any $k$-complete word.\n\nTo do this Bob can choose some $i$ ($1 \\le i \\le n$) and replace the letter at position $i$ with some other lowercase Latin letter.\n\nSo now Bob wants to know the minimum number of letters he has to replace to convert $s$ to any $k$-complete word.\n\nNote that Bob can do zero changes if the word $s$ is already $k$-complete.\n\nYou are required to answer $t$ test cases independently.\n\n\n-----Input-----\n\nThe first line contains a single integer $t$ ($1 \\le t\\le 10^5$) \u2014 the number of test cases.\n\nThe first line of each test case contains two integers $n$ and $k$ ($1 \\le k < n \\le 2 \\cdot 10^5$, $n$ is divisible by $k$).\n\nThe second line of each test case contains a word $s$ of length $n$.\n\nIt is guaranteed that word $s$ only contains lowercase Latin letters. And it is guaranteed that the sum of $n$ over all test cases will not exceed $2 \\cdot 10^5$.\n\n\n-----Output-----\n\nFor each test case, output one integer, representing the minimum number of characters he has to replace to convert $s$ to any $k$-complete word.\n\n\n-----Example-----\nInput\n4\n6 2\nabaaba\n6 3\nabaaba\n36 9\nhippopotomonstrosesquippedaliophobia\n21 7\nwudixiaoxingxingheclp\n\nOutput\n2\n0\n23\n16\n\n\n\n-----Note-----\n\nIn the first test case, one optimal solution is aaaaaa.\n\nIn the second test case, the given word itself is $k$-complete.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nimport sys\ninput = sys.stdin.readline\nfrom collections import defaultdict\n\nclass Unionfind:\n def __init__(self, n):\n self.par = [-1]*n\n self.rank = [1]*n\n \n def root(self, x):\n r = x\n \n while not self.par[r]<0:\n r = self.par[r]\n \n t = x\n \n while t!=r:\n tmp = t\n t = self.par[t]\n self.par[tmp] = r\n \n return r\n \n def unite(self, x, y):\n rx = self.root(x)\n ry = self.root(y)\n \n if rx==ry:\n return\n \n if self.rank[rx]<=self.rank[ry]:\n self.par[ry] += self.par[rx]\n self.par[rx] = ry\n \n if self.rank[rx]==self.rank[ry]:\n self.rank[ry] += 1\n else:\n self.par[rx] += self.par[ry]\n self.par[ry] = rx\n \n def is_same(self, x, y):\n return self.root(x)==self.root(y)\n \n def count(self, x):\n return -self.par[self.root(x)]\n\nt = int(input())\n\nfor _ in range(t):\n n, k = map(int, input().split())\n s = input()[:-1]\n uf = Unionfind(n)\n \n for i in range(n//2):\n uf.unite(i, n-1-i)\n \n for i in range(n-k):\n uf.unite(i, i+k)\n \n d = defaultdict(dict)\n \n for i in range(n):\n if s[i] not in d[uf.root(i)]:\n d[uf.root(i)][s[i]] = 1\n else:\n d[uf.root(i)][s[i]] += 1\n \n rs = set(uf.root(i) for i in range(n))\n ans = 0\n \n for r in rs:\n ans += uf.count(r)-max(list(d[r].values()))\n \n print(ans)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '4\\n6 2\\nabaaba\\n6 3\\nabaaba\\n36 9\\nhippopotomonstrosesquippedaliophobia\\n21 7\\nwudixiaoxingxingheclp\\n', 'output': '2\\n0\\n23\\n16\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/1332/C'}","problem_id":"vfc_280","program":"```python\nimport sys\ninput = sys.stdin.readline\nfrom collections import defaultdict\n\nclass Unionfind:\n def __init__(self, n):\n self.par = [-1]*n\n self.rank = [1]*n\n \n def root(self, x):\n r = x\n \n while not self.par[r]<0:\n r = self.par[r]\n \n t = x\n \n while t!=r:\n tmp = t\n t = self.par[t]\n self.par[tmp] = r\n \n return r\n \n def unite(self, x, y):\n rx = self.root(x)\n ry = self.root(y)\n \n if rx==ry:\n return\n \n if self.rank[rx]<=self.rank[ry]:\n self.par[ry] += self.par[rx]\n self.par[rx] = ry\n \n if self.rank[rx]==self.rank[ry]:\n self.rank[ry] += 1\n else:\n self.par[rx] += self.par[ry]\n self.par[ry] = rx\n \n def is_same(self, x, y):\n return self.root(x)==self.root(y)\n \n def count(self, x):\n return -self.par[self.root(x)]\n\nt = int(input())\n\nfor _ in range(t):\n n, k = map(int, input().split())\n s = input()[:-1]\n uf = Unionfind(n)\n \n for i in range(n//2):\n uf.unite(i, n-1-i)\n \n for i in range(n-k):\n uf.unite(i, i+k)\n \n d = defaultdict(dict)\n \n for i in range(n):\n if s[i] not in d[uf.root(i)]:\n d[uf.root(i)][s[i]] = 1\n else:\n d[uf.root(i)][s[i]] += 1\n \n rs = set(uf.root(i) for i in range(n))\n ans = 0\n \n for r in rs:\n ans += uf.count(r)-max(list(d[r].values()))\n \n print(ans)\n```","inputs":"4\n6 2\nabaaba\n6 3\nabaaba\n36 9\nhippopotomonstrosesquippedaliophobia\n21 7\nwudixiaoxingxingheclp\n","output":"2\n0\n23\n16\n","actual_output":"2\n0\n23\n16\n","execution_success":true,"sample_index":71},{"source":"apps","task_type":"verifiable_code","in_source_id":"71","prompt":"Solve the following coding problem using the programming language python:\n\nYou're given an array $a$ of $n$ integers, such that $a_1 + a_2 + \\cdots + a_n = 0$.\n\nIn one operation, you can choose two different indices $i$ and $j$ ($1 \\le i, j \\le n$), decrement $a_i$ by one and increment $a_j$ by one. If $i < j$ this operation is free, otherwise it costs one coin.\n\nHow many coins do you have to spend in order to make all elements equal to $0$?\n\n\n-----Input-----\n\nEach test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \\le t \\le 5000$). Description of the test cases follows.\n\nThe first line of each test case contains an integer $n$ ($1 \\le n \\le 10^5$) \u00a0\u2014 the number of elements.\n\nThe next line contains $n$ integers $a_1, \\ldots, a_n$ ($-10^9 \\le a_i \\le 10^9$). It is given that $\\sum_{i=1}^n a_i = 0$.\n\nIt is guaranteed that the sum of $n$ over all test cases does not exceed $10^5$.\n\n\n-----Output-----\n\nFor each test case, print the minimum number of coins we have to spend in order to make all elements equal to $0$.\n\n\n-----Example-----\nInput\n7\n4\n-3 5 -3 1\n2\n1 -1\n4\n-3 2 -3 4\n4\n-1 1 1 -1\n7\n-5 7 -6 -4 17 -13 4\n6\n-1000000000 -1000000000 -1000000000 1000000000 1000000000 1000000000\n1\n0\n\nOutput\n3\n0\n4\n1\n8\n3000000000\n0\n\n\n\n-----Note-----\n\nPossible strategy for the first test case: Do $(i=2, j=3)$ three times (free), $a = [-3, 2, 0, 1]$. Do $(i=2, j=1)$ two times (pay two coins), $a = [-1, 0, 0, 1]$. Do $(i=4, j=1)$ one time (pay one coin), $a = [0, 0, 0, 0]$.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nt=int(input())\nwhile t>0 :\n n=int(input())\n a=list(map(int,input().split()))\n an=0\n s=0\n for i in a :\n if s+i>=0 :\n s+=i \n else :\n s+=i\n an-=s \n s=0\n print(an)\n t-=1 \n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '7\\n4\\n-3 5 -3 1\\n2\\n1 -1\\n4\\n-3 2 -3 4\\n4\\n-1 1 1 -1\\n7\\n-5 7 -6 -4 17 -13 4\\n6\\n-1000000000 -1000000000 -1000000000 1000000000 1000000000 1000000000\\n1\\n0\\n', 'output': '3\\n0\\n4\\n1\\n8\\n3000000000\\n0\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/1405/B'}","problem_id":"vfc_284","program":"```python\nt=int(input())\nwhile t>0 :\n n=int(input())\n a=list(map(int,input().split()))\n an=0\n s=0\n for i in a :\n if s+i>=0 :\n s+=i \n else :\n s+=i\n an-=s \n s=0\n print(an)\n t-=1 \n```","inputs":"7\n4\n-3 5 -3 1\n2\n1 -1\n4\n-3 2 -3 4\n4\n-1 1 1 -1\n7\n-5 7 -6 -4 17 -13 4\n6\n-1000000000 -1000000000 -1000000000 1000000000 1000000000 1000000000\n1\n0\n","output":"3\n0\n4\n1\n8\n3000000000\n0\n","actual_output":"3\n0\n4\n1\n8\n3000000000\n0\n","execution_success":true,"sample_index":72},{"source":"apps","task_type":"verifiable_code","in_source_id":"72","prompt":"Solve the following coding problem using the programming language python:\n\nPhoenix loves beautiful arrays. An array is beautiful if all its subarrays of length\u00a0$k$ have the same sum. A subarray of an array is any sequence of consecutive elements.\n\nPhoenix currently has an array $a$ of length $n$. He wants to insert some number of integers, possibly zero, into his array such that it becomes beautiful. The inserted integers must be between $1$ and $n$ inclusive. Integers may be inserted anywhere (even before the first or after the last element), and he is not trying to minimize the number of inserted integers.\n\n\n-----Input-----\n\nThe input consists of multiple test cases. The first line contains an integer $t$ ($1 \\le t \\le 50$)\u00a0\u2014 the number of test cases.\n\nThe first line of each test case contains two integers $n$ and $k$ ($1 \\le k \\le n \\le 100$).\n\nThe second line of each test case contains $n$ space-separated integers ($1 \\le a_i \\le n$)\u00a0\u2014 the array that Phoenix currently has. This array may or may not be already beautiful.\n\n\n-----Output-----\n\nFor each test case, if it is impossible to create a beautiful array, print -1. Otherwise, print two lines.\n\nThe first line should contain the length of the beautiful array $m$ ($n \\le m \\le 10^4$). You don't need to minimize $m$.\n\nThe second line should contain $m$ space-separated integers ($1 \\le b_i \\le n$)\u00a0\u2014 a beautiful array that Phoenix can obtain after inserting some, possibly zero, integers into his array $a$. You may print integers that weren't originally in array $a$.\n\nIf there are multiple solutions, print any. It's guaranteed that if we can make array $a$ beautiful, we can always make it with resulting length no more than $10^4$.\n\n\n-----Example-----\nInput\n4\n4 2\n1 2 2 1\n4 3\n1 2 2 1\n3 2\n1 2 3\n4 4\n4 3 4 2\n\nOutput\n5\n1 2 1 2 1\n4\n1 2 2 1\n-1\n7\n4 3 2 1 4 3 2\n\n\n-----Note-----\n\nIn the first test case, we can make array $a$ beautiful by inserting the integer $1$ at index $3$ (in between the two existing $2$s). Now, all subarrays of length $k=2$ have the same sum $3$. There exists many other possible solutions, for example: $2, 1, 2, 1, 2, 1$ $1, 2, 1, 2, 1, 2$ \n\nIn the second test case, the array is already beautiful: all subarrays of length $k=3$ have the same sum $5$.\n\nIn the third test case, it can be shown that we cannot insert numbers to make array $a$ beautiful.\n\nIn the fourth test case, the array $b$ shown is beautiful and all subarrays of length $k=4$ have the same sum $10$. There exist other solutions also.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nt = int(input())\n\nfor _ in range(t):\n n, k = [int(x) for x in input().split()]\n a = [int(x) for x in input().split()]\n if len(set(a)) > k:\n print(-1)\n continue\n l = list(set(a))\n l.extend([1]*(k - len(l)))\n\n print(n*k)\n for _ in range(n):\n print(*l, end=\" \")\n print()\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '4\\n4 2\\n1 2 2 1\\n4 3\\n1 2 2 1\\n3 2\\n1 2 3\\n4 4\\n4 3 4 2\\n', 'output': '8\\n1 2 1 2 1 2 1 2 \\n12\\n1 2 1 1 2 1 1 2 1 1 2 1 \\n-1\\n16\\n2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 \\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/1348/B'}","problem_id":"vfc_288","program":"```python\nt = int(input())\n\nfor _ in range(t):\n n, k = [int(x) for x in input().split()]\n a = [int(x) for x in input().split()]\n if len(set(a)) > k:\n print(-1)\n continue\n l = list(set(a))\n l.extend([1]*(k - len(l)))\n\n print(n*k)\n for _ in range(n):\n print(*l, end=\" \")\n print()\n\n```","inputs":"4\n4 2\n1 2 2 1\n4 3\n1 2 2 1\n3 2\n1 2 3\n4 4\n4 3 4 2\n","output":"8\n1 2 1 2 1 2 1 2 \n12\n1 2 1 1 2 1 1 2 1 1 2 1 \n-1\n16\n2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 \n","actual_output":"8\n1 2 1 2 1 2 1 2 \n12\n1 2 1 1 2 1 1 2 1 1 2 1 \n-1\n16\n2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 \n","execution_success":true,"sample_index":73},{"source":"apps","task_type":"verifiable_code","in_source_id":"76","prompt":"Solve the following coding problem using the programming language python:\n\nLee is going to fashionably decorate his house for a party, using some regular convex polygons...\n\nLee thinks a regular $n$-sided (convex) polygon is beautiful if and only if he can rotate it in such a way that at least one of its edges is parallel to the $OX$-axis and at least one of its edges is parallel to the $OY$-axis at the same time.\n\nRecall that a regular $n$-sided polygon is a convex polygon with $n$ vertices such that all the edges and angles are equal.\n\nNow he is shopping: the market has $t$ regular polygons. For each of them print YES if it is beautiful and NO otherwise.\n\n\n-----Input-----\n\nThe first line contains a single integer $t$ ($1 \\le t \\le 10^4$)\u00a0\u2014 the number of polygons in the market. \n\nEach of the next $t$ lines contains a single integer $n_i$ ($3 \\le n_i \\le 10^9$): it means that the $i$-th polygon is a regular $n_i$-sided polygon. \n\n\n-----Output-----\n\nFor each polygon, print YES if it's beautiful or NO otherwise (case insensitive).\n\n\n-----Example-----\nInput\n4\n3\n4\n12\n1000000000\n\nOutput\nNO\nYES\nYES\nYES\n\n\n\n-----Note-----\n\nIn the example, there are $4$ polygons in the market. It's easy to see that an equilateral triangle (a regular $3$-sided polygon) is not beautiful, a square (a regular $4$-sided polygon) is beautiful and a regular $12$-sided polygon (is shown below) is beautiful as well. [Image]\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nt = int(input())\n\nfor _ in range(t):\n n = int(input())\n if n%4 == 0:\n print(\"YES\")\n else:\n print(\"NO\")\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '4\\n3\\n4\\n12\\n1000000000\\n', 'output': 'NO\\nYES\\nYES\\nYES\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/1369/A'}","problem_id":"vfc_304","program":"```python\nt = int(input())\n\nfor _ in range(t):\n n = int(input())\n if n%4 == 0:\n print(\"YES\")\n else:\n print(\"NO\")\n```","inputs":"4\n3\n4\n12\n1000000000\n","output":"NO\nYES\nYES\nYES\n","actual_output":"NO\nYES\nYES\nYES\n","execution_success":true,"sample_index":77},{"source":"apps","task_type":"verifiable_code","in_source_id":"77","prompt":"Solve the following coding problem using the programming language python:\n\nYou have a fence consisting of $n$ vertical boards. The width of each board is $1$. The height of the $i$-th board is $a_i$. You think that the fence is great if there is no pair of adjacent boards having the same height. More formally, the fence is great if and only if for all indices from $2$ to $n$, the condition $a_{i-1} \\neq a_i$ holds.\n\nUnfortunately, it is possible that now your fence is not great. But you can change it! You can increase the length of the $i$-th board by $1$, but you have to pay $b_i$ rubles for it. The length of each board can be increased any number of times (possibly, zero).\n\nCalculate the minimum number of rubles you have to spend to make the fence great again!\n\nYou have to answer $q$ independent queries.\n\n\n-----Input-----\n\nThe first line contains one integer $q$ ($1 \\le q \\le 3 \\cdot 10^5$) \u2014 the number of queries.\n\nThe first line of each query contains one integers $n$ ($1 \\le n \\le 3 \\cdot 10^5$) \u2014 the number of boards in the fence.\n\nThe following $n$ lines of each query contain the descriptions of the boards. The $i$-th line contains two integers $a_i$ and $b_i$ ($1 \\le a_i, b_i \\le 10^9$) \u2014 the length of the $i$-th board and the price for increasing it by $1$, respectively.\n\nIt is guaranteed that sum of all $n$ over all queries not exceed $3 \\cdot 10^5$.\n\nIt is guaranteed that answer to each query will not exceed $10^{18}$.\n\n\n-----Output-----\n\nFor each query print one integer \u2014 the minimum number of rubles you have to spend to make the fence great.\n\n\n-----Example-----\nInput\n3\n3\n2 4\n2 1\n3 5\n3\n2 3\n2 10\n2 6\n4\n1 7\n3 3\n2 6\n1000000000 2\n\nOutput\n2\n9\n0\n\n\n\n-----Note-----\n\nIn the first query you have to increase the length of second board by $2$. So your total costs if $2 \\cdot b_2 = 2$.\n\nIn the second query you have to increase the length of first board by $1$ and the length of third board by $1$. So your total costs if $1 \\cdot b_1 + 1 \\cdot b_3 = 9$.\n\nIn the third query the fence is great initially, so you don't need to spend rubles.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n3\n\nimport math\nimport os\nimport sys\n\n\nDEBUG = 'DEBUG' in os.environ\n\n\ndef inp():\n return sys.stdin.readline().rstrip()\n\n\ndef dprint(*value, sep=' ', end='\\n'):\n if DEBUG:\n print(*value, sep=sep, end=end)\n\n\nINF = 10 ** 20\n\n\ndef solve(N, A, B):\n dp = {A[0]: 0, A[0] + 1: B[0], A[0] + 2: B[0] * 2}\n for i in range(1, N):\n ndp = {}\n\n h = A[i]\n for ph, c in dp.items():\n for inc in range(3):\n nh = h + inc\n if ph == nh:\n continue\n if nh not in ndp:\n ndp[nh] = INF\n ndp[nh] = min(ndp[nh], c + B[i] * inc)\n\n dp = ndp\n\n return min(dp.values())\n\n\ndef main():\n Q = int(inp())\n for _ in range(Q):\n N = int(inp())\n A = []\n B = []\n for _ in range(N):\n a, b = [int(e) for e in inp().split()]\n A.append(a)\n B.append(b)\n print(solve(N, A, B))\n\n\ndef __starting_point():\n main()\n\n__starting_point()\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\n3\\n2 4\\n2 1\\n3 5\\n3\\n2 3\\n2 10\\n2 6\\n4\\n1 7\\n3 3\\n2 6\\n1000000000 2\\n', 'output': '2\\n9\\n0\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/1221/D'}","problem_id":"vfc_308","program":"```python\n3\n\nimport math\nimport os\nimport sys\n\n\nDEBUG = 'DEBUG' in os.environ\n\n\ndef inp():\n return sys.stdin.readline().rstrip()\n\n\ndef dprint(*value, sep=' ', end='\\n'):\n if DEBUG:\n print(*value, sep=sep, end=end)\n\n\nINF = 10 ** 20\n\n\ndef solve(N, A, B):\n dp = {A[0]: 0, A[0] + 1: B[0], A[0] + 2: B[0] * 2}\n for i in range(1, N):\n ndp = {}\n\n h = A[i]\n for ph, c in dp.items():\n for inc in range(3):\n nh = h + inc\n if ph == nh:\n continue\n if nh not in ndp:\n ndp[nh] = INF\n ndp[nh] = min(ndp[nh], c + B[i] * inc)\n\n dp = ndp\n\n return min(dp.values())\n\n\ndef main():\n Q = int(inp())\n for _ in range(Q):\n N = int(inp())\n A = []\n B = []\n for _ in range(N):\n a, b = [int(e) for e in inp().split()]\n A.append(a)\n B.append(b)\n print(solve(N, A, B))\n\n\ndef __starting_point():\n main()\n\n__starting_point()\n```","inputs":"3\n3\n2 4\n2 1\n3 5\n3\n2 3\n2 10\n2 6\n4\n1 7\n3 3\n2 6\n1000000000 2\n","output":"2\n9\n0\n","actual_output":"2\n9\n0\n","execution_success":true,"sample_index":78},{"source":"apps","task_type":"verifiable_code","in_source_id":"78","prompt":"Solve the following coding problem using the programming language python:\n\nYou are given a picture consisting of $n$ rows and $m$ columns. Rows are numbered from $1$ to $n$ from the top to the bottom, columns are numbered from $1$ to $m$ from the left to the right. Each cell is painted either black or white. \n\nYou think that this picture is not interesting enough. You consider a picture to be interesting if there is at least one cross in it. A cross is represented by a pair of numbers $x$ and $y$, where $1 \\le x \\le n$ and $1 \\le y \\le m$, such that all cells in row $x$ and all cells in column $y$ are painted black.\n\nFor examples, each of these pictures contain crosses:\n\n [Image] \n\nThe fourth picture contains 4 crosses: at $(1, 3)$, $(1, 5)$, $(3, 3)$ and $(3, 5)$.\n\nFollowing images don't contain crosses:\n\n [Image] \n\nYou have a brush and a can of black paint, so you can make this picture interesting. Each minute you may choose a white cell and paint it black.\n\nWhat is the minimum number of minutes you have to spend so the resulting picture contains at least one cross?\n\nYou are also asked to answer multiple independent queries.\n\n\n-----Input-----\n\nThe first line contains an integer $q$ ($1 \\le q \\le 5 \\cdot 10^4$) \u2014 the number of queries.\n\nThe first line of each query contains two integers $n$ and $m$ ($1 \\le n, m \\le 5 \\cdot 10^4$, $n \\cdot m \\le 4 \\cdot 10^5$) \u2014 the number of rows and the number of columns in the picture.\n\nEach of the next $n$ lines contains $m$ characters \u2014 '.' if the cell is painted white and '*' if the cell is painted black.\n\nIt is guaranteed that $\\sum n \\le 5 \\cdot 10^4$ and $\\sum n \\cdot m \\le 4 \\cdot 10^5$.\n\n\n-----Output-----\n\nPrint $q$ lines, the $i$-th line should contain a single integer \u2014 the answer to the $i$-th query, which is the minimum number of minutes you have to spend so the resulting picture contains at least one cross.\n\n\n-----Example-----\nInput\n9\n5 5\n..*..\n..*..\n*****\n..*..\n..*..\n3 4\n****\n.*..\n.*..\n4 3\n***\n*..\n*..\n*..\n5 5\n*****\n*.*.*\n*****\n..*.*\n..***\n1 4\n****\n5 5\n.....\n..*..\n.***.\n..*..\n.....\n5 3\n...\n.*.\n.*.\n***\n.*.\n3 3\n.*.\n*.*\n.*.\n4 4\n*.**\n....\n*.**\n*.**\n\nOutput\n0\n0\n0\n0\n0\n4\n1\n1\n2\n\n\n\n-----Note-----\n\nThe example contains all the pictures from above in the same order.\n\nThe first 5 pictures already contain a cross, thus you don't have to paint anything.\n\nYou can paint $(1, 3)$, $(3, 1)$, $(5, 3)$ and $(3, 5)$ on the $6$-th picture to get a cross in $(3, 3)$. That'll take you $4$ minutes.\n\nYou can paint $(1, 2)$ on the $7$-th picture to get a cross in $(4, 2)$.\n\nYou can paint $(2, 2)$ on the $8$-th picture to get a cross in $(2, 2)$. You can, for example, paint $(1, 3)$, $(3, 1)$ and $(3, 3)$ to get a cross in $(3, 3)$ but that will take you $3$ minutes instead of $1$.\n\nThere are 9 possible crosses you can get in minimum time on the $9$-th picture. One of them is in $(1, 1)$: paint $(1, 2)$ and $(2, 1)$.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nimport sys\n\nq = int(sys.stdin.readline().strip())\nfor t in range(0, q):\n n, m = list(map(int, sys.stdin.readline().strip().split()))\n L = []\n R = [0] * n\n C = [0] * m\n for i in range (0, n):\n L.append(sys.stdin.readline().strip())\n for j in range (0, m):\n if L[i][j] != \"*\":\n R[i] = R[i] + 1\n C[j] = C[j] + 1\n ans = n + m - 1\n for i in range (0, n):\n for j in range (0, m):\n x = 0\n if L[i][j] != \"*\":\n x = -1\n ans = min([ans, R[i]+C[j]+x])\n print(ans)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '9\\n5 5\\n..*..\\n..*..\\n*****\\n..*..\\n..*..\\n3 4\\n****\\n.*..\\n.*..\\n4 3\\n***\\n*..\\n*..\\n*..\\n5 5\\n*****\\n*.*.*\\n*****\\n..*.*\\n..***\\n1 4\\n****\\n5 5\\n.....\\n..*..\\n.***.\\n..*..\\n.....\\n5 3\\n...\\n.*.\\n.*.\\n***\\n.*.\\n3 3\\n.*.\\n*.*\\n.*.\\n4 4\\n*.**\\n....\\n*.**\\n*.**\\n', 'output': '0\\n0\\n0\\n0\\n0\\n4\\n1\\n1\\n2\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/1194/B'}","problem_id":"vfc_312","program":"```python\nimport sys\n\nq = int(sys.stdin.readline().strip())\nfor t in range(0, q):\n n, m = list(map(int, sys.stdin.readline().strip().split()))\n L = []\n R = [0] * n\n C = [0] * m\n for i in range (0, n):\n L.append(sys.stdin.readline().strip())\n for j in range (0, m):\n if L[i][j] != \"*\":\n R[i] = R[i] + 1\n C[j] = C[j] + 1\n ans = n + m - 1\n for i in range (0, n):\n for j in range (0, m):\n x = 0\n if L[i][j] != \"*\":\n x = -1\n ans = min([ans, R[i]+C[j]+x])\n print(ans)\n```","inputs":"9\n5 5\n..*..\n..*..\n*****\n..*..\n..*..\n3 4\n****\n.*..\n.*..\n4 3\n***\n*..\n*..\n*..\n5 5\n*****\n*.*.*\n*****\n..*.*\n..***\n1 4\n****\n5 5\n.....\n..*..\n.***.\n..*..\n.....\n5 3\n...\n.*.\n.*.\n***\n.*.\n3 3\n.*.\n*.*\n.*.\n4 4\n*.**\n....\n*.**\n*.**\n","output":"0\n0\n0\n0\n0\n4\n1\n1\n2\n","actual_output":"0\n0\n0\n0\n0\n4\n1\n1\n2\n","execution_success":true,"sample_index":79},{"source":"apps","task_type":"verifiable_code","in_source_id":"80","prompt":"Solve the following coding problem using the programming language python:\n\nWhile doing some spring cleaning, Daniel found an old calculator that he loves so much. However, it seems like it is broken. When he tries to compute $1 + 3$ using the calculator, he gets $2$ instead of $4$. But when he tries computing $1 + 4$, he gets the correct answer, $5$. Puzzled by this mystery, he opened up his calculator and found the answer to the riddle: the full adders became half adders! \n\nSo, when he tries to compute the sum $a + b$ using the calculator, he instead gets the xorsum $a \\oplus b$ (read the definition by the link: https://en.wikipedia.org/wiki/Exclusive_or).\n\nAs he saw earlier, the calculator sometimes gives the correct answer. And so, he wonders, given integers $l$ and $r$, how many pairs of integers $(a, b)$ satisfy the following conditions: $$a + b = a \\oplus b$$ $$l \\leq a \\leq r$$ $$l \\leq b \\leq r$$\n\nHowever, Daniel the Barman is going to the bar and will return in two hours. He tells you to solve the problem before he returns, or else you will have to enjoy being blocked.\n\n\n-----Input-----\n\nThe first line contains a single integer $t$ ($1 \\le t \\le 100$) \u2014 the number of testcases.\n\nThen, $t$ lines follow, each containing two space-separated integers $l$ and $r$ ($0 \\le l \\le r \\le 10^9$).\n\n\n-----Output-----\n\nPrint $t$ integers, the $i$-th integer should be the answer to the $i$-th testcase.\n\n\n-----Example-----\nInput\n3\n1 4\n323 323\n1 1000000\n\nOutput\n8\n0\n3439863766\n\n\n\n-----Note-----\n\n$a \\oplus b$ denotes the bitwise XOR of $a$ and $b$.\n\nFor the first testcase, the pairs are: $(1, 2)$, $(1, 4)$, $(2, 1)$, $(2, 4)$, $(3, 4)$, $(4, 1)$, $(4, 2)$, and $(4, 3)$.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\ndef solve(L, R):\n res = 0\n for i in range(32):\n for j in range(32):\n l = (L >> i) << i\n r = (R >> j) << j\n #print(l, r)\n if l>>i&1==0 or r>>j&1==0:\n continue\n l -= 1<> i) << i\n r = (R >> j) << j\n #print(l, r)\n if l>>i&1==0 or r>>j&1==0:\n continue\n l -= 1< x$ and $w_{i-x} = $ 1, then $s_i = $ 1); if the character $w_{i+x}$ exists and is equal to 1, then $s_i$ is 1 (formally, if $i + x \\le n$ and $w_{i+x} = $ 1, then $s_i = $ 1); if both of the aforementioned conditions are false, then $s_i$ is 0. \n\nYou are given the integer $x$ and the resulting string $s$. Reconstruct the original string $w$.\n\n\n-----Input-----\n\nThe first line contains one integer $t$ ($1 \\le t \\le 1000$) \u2014 the number of test cases.\n\nEach test case consists of two lines. The first line contains the resulting string $s$ ($2 \\le |s| \\le 10^5$, each character of $s$ is either 0 or 1). The second line contains one integer $x$ ($1 \\le x \\le |s| - 1$).\n\nThe total length of all strings $s$ in the input does not exceed $10^5$.\n\n\n-----Output-----\n\nFor each test case, print the answer on a separate line as follows:\n\n if no string $w$ can produce the string $s$ at the end of the process, print $-1$; otherwise, print the binary string $w$ consisting of $|s|$ characters. If there are multiple answers, print any of them. \n\n\n-----Example-----\nInput\n3\n101110\n2\n01\n1\n110\n1\n\nOutput\n111011\n10\n-1\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nimport sys\n\ninput=sys.stdin.readline\n\nfor _ in range(int(input())):\n s=input().rstrip()\n x=int(input())\n n=len(s)\n ans=[\"1\" for i in range(n)]\n for i in range(n):\n if s[i]==\"0\":\n if i-x>=0:\n ans[i-x]=\"0\"\n if i+x=0:\n check|=(ans[i-x]==\"1\")\n if i+x=0:\n ans[i-x]=\"0\"\n if i+x=0:\n check|=(ans[i-x]==\"1\")\n if i+x a[i]:\n if tmp == len(lis[-1]):\n lis.append(now)\n now = [a[i]]\n tmp = 1\n else:\n tmp += 1\n now.append(a[i])\n else:\n now.append(a[i])\n\n if len(now) > 0:\n lis.append(now)\n\n #print (lis)\n print (len(lis)-1)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\n4\\n1 4 3 2\\n2\\n1 2\\n3\\n1 2 3\\n', 'output': '3\\n1\\n1\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/1437/D'}","problem_id":"vfc_356","program":"```python\nfrom sys import stdin\n\ntt = int(stdin.readline())\n\nfor loop in range(tt):\n\n n = int(stdin.readline())\n a = list(map(int,stdin.readline().split()))\n\n lis = [ [1] ]\n\n now = []\n tmp = 0\n\n for i in range(1,n):\n if len(now) == 0:\n now.append(a[i])\n tmp = 1\n elif now[-1] > a[i]:\n if tmp == len(lis[-1]):\n lis.append(now)\n now = [a[i]]\n tmp = 1\n else:\n tmp += 1\n now.append(a[i])\n else:\n now.append(a[i])\n\n if len(now) > 0:\n lis.append(now)\n\n #print (lis)\n print (len(lis)-1)\n```","inputs":"3\n4\n1 4 3 2\n2\n1 2\n3\n1 2 3\n","output":"3\n1\n1\n","actual_output":"3\n1\n1\n","execution_success":true,"sample_index":90},{"source":"apps","task_type":"verifiable_code","in_source_id":"92","prompt":"Solve the following coding problem using the programming language python:\n\nYou are given two strings of equal length $s$ and $t$ consisting of lowercase Latin letters. You may perform any number (possibly, zero) operations on these strings.\n\nDuring each operation you choose two adjacent characters in any string and assign the value of the first character to the value of the second or vice versa.\n\nFor example, if $s$ is \"acbc\" you can get the following strings in one operation: \"aabc\" (if you perform $s_2 = s_1$); \"ccbc\" (if you perform $s_1 = s_2$); \"accc\" (if you perform $s_3 = s_2$ or $s_3 = s_4$); \"abbc\" (if you perform $s_2 = s_3$); \"acbb\" (if you perform $s_4 = s_3$); \n\nNote that you can also apply this operation to the string $t$.\n\nPlease determine whether it is possible to transform $s$ into $t$, applying the operation above any number of times.\n\nNote that you have to answer $q$ independent queries.\n\n\n-----Input-----\n\nThe first line contains one integer $q$ ($1 \\le q \\le 100$)\u00a0\u2014 the number of queries. Each query is represented by two consecutive lines.\n\nThe first line of each query contains the string $s$ ($1 \\le |s| \\le 100$) consisting of lowercase Latin letters.\n\nThe second line of each query contains the string $t$ ($1 \\le |t| \\leq 100$, $|t| = |s|$) consisting of lowercase Latin letters.\n\n\n-----Output-----\n\nFor each query, print \"YES\" if it is possible to make $s$ equal to $t$, and \"NO\" otherwise.\n\nYou may print every letter in any case you want (so, for example, the strings \"yEs\", \"yes\", \"Yes\", and \"YES\" will all be recognized as positive answer).\n\n\n-----Example-----\nInput\n3\nxabb\naabx\ntechnocup\ntechnocup\na\nz\n\nOutput\nYES\nYES\nNO\n\n\n\n-----Note-----\n\nIn the first query, you can perform two operations $s_1 = s_2$ (after it $s$ turns into \"aabb\") and $t_4 = t_3$ (after it $t$ turns into \"aabb\"). \n\nIn the second query, the strings are equal initially, so the answer is \"YES\".\n\nIn the third query, you can not make strings $s$ and $t$ equal. Therefore, the answer is \"NO\".\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfor _ in range(int(input())):\n print(\"YES\" if set(input()).intersection(input()) else \"NO\")\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\nxabb\\naabx\\ntechnocup\\ntechnocup\\na\\nz\\n', 'output': 'YES\\nYES\\nNO\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/1223/B'}","problem_id":"vfc_368","program":"```python\nfor _ in range(int(input())):\n print(\"YES\" if set(input()).intersection(input()) else \"NO\")\n\n```","inputs":"3\nxabb\naabx\ntechnocup\ntechnocup\na\nz\n","output":"YES\nYES\nNO\n","actual_output":"YES\nYES\nNO\n","execution_success":true,"sample_index":93},{"source":"apps","task_type":"verifiable_code","in_source_id":"93","prompt":"Solve the following coding problem using the programming language python:\n\nSanta has to send presents to the kids. He has a large stack of $n$ presents, numbered from $1$ to $n$; the topmost present has number $a_1$, the next present is $a_2$, and so on; the bottom present has number $a_n$. All numbers are distinct.\n\nSanta has a list of $m$ distinct presents he has to send: $b_1$, $b_2$, ..., $b_m$. He will send them in the order they appear in the list.\n\nTo send a present, Santa has to find it in the stack by removing all presents above it, taking this present and returning all removed presents on top of the stack. So, if there are $k$ presents above the present Santa wants to send, it takes him $2k + 1$ seconds to do it. Fortunately, Santa can speed the whole process up \u2014 when he returns the presents to the stack, he may reorder them as he wishes (only those which were above the present he wanted to take; the presents below cannot be affected in any way).\n\nWhat is the minimum time required to send all of the presents, provided that Santa knows the whole list of presents he has to send and reorders the presents optimally? Santa cannot change the order of presents or interact with the stack of presents in any other way.\n\nYour program has to answer $t$ different test cases.\n\n\n-----Input-----\n\nThe first line contains one integer $t$ ($1 \\le t \\le 100$) \u2014 the number of test cases.\n\nThen the test cases follow, each represented by three lines.\n\nThe first line contains two integers $n$ and $m$ ($1 \\le m \\le n \\le 10^5$) \u2014 the number of presents in the stack and the number of presents Santa wants to send, respectively.\n\nThe second line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ ($1 \\le a_i \\le n$, all $a_i$ are unique) \u2014 the order of presents in the stack.\n\nThe third line contains $m$ integers $b_1$, $b_2$, ..., $b_m$ ($1 \\le b_i \\le n$, all $b_i$ are unique) \u2014 the ordered list of presents Santa has to send.\n\nThe sum of $n$ over all test cases does not exceed $10^5$.\n\n\n-----Output-----\n\nFor each test case print one integer \u2014 the minimum number of seconds which Santa has to spend sending presents, if he reorders the presents optimally each time he returns them into the stack.\n\n\n-----Example-----\nInput\n2\n3 3\n3 1 2\n3 2 1\n7 2\n2 1 7 3 4 5 6\n3 1\n\nOutput\n5\n8\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfor tc in range(int(input())):\n n,m = list(map(int, input().split()))\n al = list(map(int, input().split()))\n bl = list(map(int, input().split()))\n aidx = {}\n for i,e in enumerate(al):\n aidx[e]=i\n midx = -1\n res = 0\n for i,e in enumerate(bl):\n idx = aidx[e]\n if idx <= midx:\n res += 1\n else:\n res += 2*(idx-i)+1\n midx = max(midx, idx)\n print(res)\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n3 3\\n3 1 2\\n3 2 1\\n7 2\\n2 1 7 3 4 5 6\\n3 1\\n', 'output': '5\\n8\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/1279/C'}","problem_id":"vfc_372","program":"```python\nfor tc in range(int(input())):\n n,m = list(map(int, input().split()))\n al = list(map(int, input().split()))\n bl = list(map(int, input().split()))\n aidx = {}\n for i,e in enumerate(al):\n aidx[e]=i\n midx = -1\n res = 0\n for i,e in enumerate(bl):\n idx = aidx[e]\n if idx <= midx:\n res += 1\n else:\n res += 2*(idx-i)+1\n midx = max(midx, idx)\n print(res)\n\n```","inputs":"2\n3 3\n3 1 2\n3 2 1\n7 2\n2 1 7 3 4 5 6\n3 1\n","output":"5\n8\n","actual_output":"5\n8\n","execution_success":true,"sample_index":94},{"source":"apps","task_type":"verifiable_code","in_source_id":"95","prompt":"Solve the following coding problem using the programming language python:\n\nYou are given a integer $n$ ($n > 0$). Find any integer $s$ which satisfies these conditions, or report that there are no such numbers:\n\nIn the decimal representation of $s$: $s > 0$, $s$ consists of $n$ digits, no digit in $s$ equals $0$, $s$ is not divisible by any of it's digits. \n\n\n-----Input-----\n\nThe input consists of multiple test cases. The first line of the input contains a single integer $t$ ($1 \\leq t \\leq 400$), the number of test cases. The next $t$ lines each describe a test case.\n\nEach test case contains one positive integer $n$ ($1 \\leq n \\leq 10^5$).\n\nIt is guaranteed that the sum of $n$ for all test cases does not exceed $10^5$.\n\n\n-----Output-----\n\nFor each test case, print an integer $s$ which satisfies the conditions described above, or \"-1\" (without quotes), if no such number exists. If there are multiple possible solutions for $s$, print any solution.\n\n\n-----Example-----\nInput\n4\n1\n2\n3\n4\n\nOutput\n-1\n57\n239\n6789\n\n\n\n-----Note-----\n\nIn the first test case, there are no possible solutions for $s$ consisting of one digit, because any such solution is divisible by itself.\n\nFor the second test case, the possible solutions are: $23$, $27$, $29$, $34$, $37$, $38$, $43$, $46$, $47$, $49$, $53$, $54$, $56$, $57$, $58$, $59$, $67$, $68$, $69$, $73$, $74$, $76$, $78$, $79$, $83$, $86$, $87$, $89$, $94$, $97$, and $98$.\n\nFor the third test case, one possible solution is $239$ because $239$ is not divisible by $2$, $3$ or $9$ and has three digits (none of which equals zero).\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n#JMD\n#Nagendra Jha-4096\n\n \nimport sys\nimport math\n\n#import fractions\n#import numpy\n \n###File Operations###\nfileoperation=0\nif(fileoperation):\n orig_stdout = sys.stdout\n orig_stdin = sys.stdin\n inputfile = open('W:/Competitive Programming/input.txt', 'r')\n outputfile = open('W:/Competitive Programming/output.txt', 'w')\n sys.stdin = inputfile\n sys.stdout = outputfile\n\n###Defines...###\nmod=1000000007\n \n###FUF's...###\ndef nospace(l):\n ans=''.join(str(i) for i in l)\n return ans\n \n \n \n##### Main ####\nt=int(input())\nfor tt in range(t):\n n=int(input())\n\n if n==1:\n print(-1)\n else:\n s=\"2\"\n for i in range(n-1):\n s+='3'\n print(s)\n #n,k,s= map(int, sys.stdin.readline().split(' '))\n #a=list(map(int,sys.stdin.readline().split(' ')))\n \n \n#####File Operations#####\nif(fileoperation):\n sys.stdout = orig_stdout\n sys.stdin = orig_stdin\n inputfile.close()\n outputfile.close()\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '4\\n1\\n2\\n3\\n4\\n', 'output': '-1\\n23\\n233\\n2333\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/1326/A'}","problem_id":"vfc_380","program":"```python\n#JMD\n#Nagendra Jha-4096\n\n \nimport sys\nimport math\n\n#import fractions\n#import numpy\n \n###File Operations###\nfileoperation=0\nif(fileoperation):\n orig_stdout = sys.stdout\n orig_stdin = sys.stdin\n inputfile = open('W:/Competitive Programming/input.txt', 'r')\n outputfile = open('W:/Competitive Programming/output.txt', 'w')\n sys.stdin = inputfile\n sys.stdout = outputfile\n\n###Defines...###\nmod=1000000007\n \n###FUF's...###\ndef nospace(l):\n ans=''.join(str(i) for i in l)\n return ans\n \n \n \n##### Main ####\nt=int(input())\nfor tt in range(t):\n n=int(input())\n\n if n==1:\n print(-1)\n else:\n s=\"2\"\n for i in range(n-1):\n s+='3'\n print(s)\n #n,k,s= map(int, sys.stdin.readline().split(' '))\n #a=list(map(int,sys.stdin.readline().split(' ')))\n \n \n#####File Operations#####\nif(fileoperation):\n sys.stdout = orig_stdout\n sys.stdin = orig_stdin\n inputfile.close()\n outputfile.close()\n```","inputs":"4\n1\n2\n3\n4\n","output":"-1\n23\n233\n2333\n","actual_output":"-1\n23\n233\n2333\n","execution_success":true,"sample_index":96},{"source":"apps","task_type":"verifiable_code","in_source_id":"96","prompt":"Solve the following coding problem using the programming language python:\n\nPetya has come to the math exam and wants to solve as many problems as possible. He prepared and carefully studied the rules by which the exam passes.\n\nThe exam consists of $n$ problems that can be solved in $T$ minutes. Thus, the exam begins at time $0$ and ends at time $T$. Petya can leave the exam at any integer time from $0$ to $T$, inclusive.\n\nAll problems are divided into two types: easy problems \u2014 Petya takes exactly $a$ minutes to solve any easy problem; hard problems \u2014 Petya takes exactly $b$ minutes ($b > a$) to solve any hard problem. \n\nThus, if Petya starts solving an easy problem at time $x$, then it will be solved at time $x+a$. Similarly, if at a time $x$ Petya starts to solve a hard problem, then it will be solved at time $x+b$.\n\nFor every problem, Petya knows if it is easy or hard. Also, for each problem is determined time $t_i$ ($0 \\le t_i \\le T$) at which it will become mandatory (required). If Petya leaves the exam at time $s$ and there is such a problem $i$ that $t_i \\le s$ and he didn't solve it, then he will receive $0$ points for the whole exam. Otherwise (i.e if he has solved all such problems for which $t_i \\le s$) he will receive a number of points equal to the number of solved problems. Note that leaving at time $s$ Petya can have both \"mandatory\" and \"non-mandatory\" problems solved.\n\nFor example, if $n=2$, $T=5$, $a=2$, $b=3$, the first problem is hard and $t_1=3$ and the second problem is easy and $t_2=2$. Then: if he leaves at time $s=0$, then he will receive $0$ points since he will not have time to solve any problems; if he leaves at time $s=1$, he will receive $0$ points since he will not have time to solve any problems; if he leaves at time $s=2$, then he can get a $1$ point by solving the problem with the number $2$ (it must be solved in the range from $0$ to $2$); if he leaves at time $s=3$, then he will receive $0$ points since at this moment both problems will be mandatory, but he will not be able to solve both of them; if he leaves at time $s=4$, then he will receive $0$ points since at this moment both problems will be mandatory, but he will not be able to solve both of them; if he leaves at time $s=5$, then he can get $2$ points by solving all problems. \n\nThus, the answer to this test is $2$.\n\nHelp Petya to determine the maximal number of points that he can receive, before leaving the exam.\n\n\n-----Input-----\n\nThe first line contains the integer $m$ ($1 \\le m \\le 10^4$)\u00a0\u2014 the number of test cases in the test.\n\nThe next lines contain a description of $m$ test cases. \n\nThe first line of each test case contains four integers $n, T, a, b$ ($2 \\le n \\le 2\\cdot10^5$, $1 \\le T \\le 10^9$, $1 \\le a < b \\le 10^9$)\u00a0\u2014 the number of problems, minutes given for the exam and the time to solve an easy and hard problem, respectively.\n\nThe second line of each test case contains $n$ numbers $0$ or $1$, separated by single space: the $i$-th number means the type of the $i$-th problem. A value of $0$ means that the problem is easy, and a value of $1$ that the problem is hard.\n\nThe third line of each test case contains $n$ integers $t_i$ ($0 \\le t_i \\le T$), where the $i$-th number means the time at which the $i$-th problem will become mandatory.\n\nIt is guaranteed that the sum of $n$ for all test cases does not exceed $2\\cdot10^5$.\n\n\n-----Output-----\n\nPrint the answers to $m$ test cases. For each set, print a single integer\u00a0\u2014 maximal number of points that he can receive, before leaving the exam.\n\n\n-----Example-----\nInput\n10\n3 5 1 3\n0 0 1\n2 1 4\n2 5 2 3\n1 0\n3 2\n1 20 2 4\n0\n16\n6 20 2 5\n1 1 0 1 0 0\n0 8 2 9 11 6\n4 16 3 6\n1 0 1 1\n8 3 5 6\n6 20 3 6\n0 1 0 0 1 0\n20 11 3 20 16 17\n7 17 1 6\n1 1 0 1 0 0 0\n1 7 0 11 10 15 10\n6 17 2 6\n0 0 1 0 0 1\n7 6 3 7 10 12\n5 17 2 5\n1 1 1 1 0\n17 11 10 6 4\n1 1 1 2\n0\n1\n\nOutput\n3\n2\n1\n0\n1\n4\n0\n1\n2\n1\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nimport sys\nfrom operator import itemgetter\n\ndef count(a, b, num_a, num_b, cur_time):\n\tcurrent_result = 0\n\t#print('count time = ', cur_time, \"num_a =\", num_a, 'num_b = ', num_b)\n\tif num_a * a + num_b * b <= cur_time and cur_time >= 0:\n\t\tcur_time -= num_a * a + num_b * b\n\t\tcurrent_result = num_a + num_b\n\t\tif num_a < total_a:\n\t\t\tif (total_a - num_a) * a <= cur_time:\n\t\t\t\tcurrent_result += total_a - num_a\n\t\t\t\tcur_time -= (total_a - num_a) * a\n\t\t\t\t#print(1)\n\t\t\telse:\n\t\t\t\tcurrent_result += cur_time // a\n\t\t\t\tcur_time -= a *(cur_time // a)\n\t\t\t\t#print(2)\n\t\tif num_b < total_b:\n\t\t\tif (total_b - num_b) * b <= cur_time:\n\t\t\t\tcurrent_result += total_b - num_b\n\t\t\t\t#print(3)\n\t\t\telse:\n\t\t\t\t#print(4)\n\t\t\t\tcurrent_result += cur_time // b\n\t#print('current_result = ', current_result)\n\treturn current_result\n\n\ndef solve(n, T, a, b, tasks, total_a, total_b):\t\n\ttasks = sorted(tasks)\n\t#print(tasks)\n\tresult = 0\n\tnum_a = 0\n\tnum_b = 0\n\n\tfor i in range(len(tasks)):\n\t\ttime, t = tasks[i] \n\t\t#print(tasks[i])\n\t\tcur_time = time - 1\n\t\t#print('cur time = ', cur_time)\n\t\tcurrent_result = count(a, b, num_a, num_b, cur_time)\n\t\tresult = max(current_result, result)\n\n\t\tif t == 0:\n\t\t\tnum_a += 1\n\t\telse:\n\t\t\tnum_b += 1\n\n\t\tif i == len(tasks) - 1 or tasks[i + 1][1] != tasks[i][1]:\n\t\t\tresult = max(result, count(a, b, num_a, num_b, cur_time))\n\n\t\t#print(\"i =\", i, \"result = \", result)\n\n\tresult = max(result, count(a, b, total_a, total_b, T))\n\treturn result\n\n\nq = int(input())\n\nfor i in range(q):\n\tn, T, a, b = list(map(int, input().split()))\n\ttypes = list(map(int, input().split()))\n\ttotal_a, total_b = 0, 0\n\tfor t in types:\n\t\tif t == 0:\n\t\t\ttotal_a += 1\n\t\telse:\n\t\t\ttotal_b += 1\n\tt = list(map(int, input().split()))\n\t#print(t)\n\t#print(types)\n\ttasks = list(zip(t, types))\n\tprint(solve(n, T, a, b, tasks, total_a, total_b))\t\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '10\\n3 5 1 3\\n0 0 1\\n2 1 4\\n2 5 2 3\\n1 0\\n3 2\\n1 20 2 4\\n0\\n16\\n6 20 2 5\\n1 1 0 1 0 0\\n0 8 2 9 11 6\\n4 16 3 6\\n1 0 1 1\\n8 3 5 6\\n6 20 3 6\\n0 1 0 0 1 0\\n20 11 3 20 16 17\\n7 17 1 6\\n1 1 0 1 0 0 0\\n1 7 0 11 10 15 10\\n6 17 2 6\\n0 0 1 0 0 1\\n7 6 3 7 10 12\\n5 17 2 5\\n1 1 1 1 0\\n17 11 10 6 4\\n1 1 1 2\\n0\\n1\\n', 'output': '3\\n2\\n1\\n0\\n1\\n4\\n0\\n1\\n2\\n1\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/1282/C'}","problem_id":"vfc_384","program":"```python\nimport sys\nfrom operator import itemgetter\n\ndef count(a, b, num_a, num_b, cur_time):\n\tcurrent_result = 0\n\t#print('count time = ', cur_time, \"num_a =\", num_a, 'num_b = ', num_b)\n\tif num_a * a + num_b * b <= cur_time and cur_time >= 0:\n\t\tcur_time -= num_a * a + num_b * b\n\t\tcurrent_result = num_a + num_b\n\t\tif num_a < total_a:\n\t\t\tif (total_a - num_a) * a <= cur_time:\n\t\t\t\tcurrent_result += total_a - num_a\n\t\t\t\tcur_time -= (total_a - num_a) * a\n\t\t\t\t#print(1)\n\t\t\telse:\n\t\t\t\tcurrent_result += cur_time // a\n\t\t\t\tcur_time -= a *(cur_time // a)\n\t\t\t\t#print(2)\n\t\tif num_b < total_b:\n\t\t\tif (total_b - num_b) * b <= cur_time:\n\t\t\t\tcurrent_result += total_b - num_b\n\t\t\t\t#print(3)\n\t\t\telse:\n\t\t\t\t#print(4)\n\t\t\t\tcurrent_result += cur_time // b\n\t#print('current_result = ', current_result)\n\treturn current_result\n\n\ndef solve(n, T, a, b, tasks, total_a, total_b):\t\n\ttasks = sorted(tasks)\n\t#print(tasks)\n\tresult = 0\n\tnum_a = 0\n\tnum_b = 0\n\n\tfor i in range(len(tasks)):\n\t\ttime, t = tasks[i] \n\t\t#print(tasks[i])\n\t\tcur_time = time - 1\n\t\t#print('cur time = ', cur_time)\n\t\tcurrent_result = count(a, b, num_a, num_b, cur_time)\n\t\tresult = max(current_result, result)\n\n\t\tif t == 0:\n\t\t\tnum_a += 1\n\t\telse:\n\t\t\tnum_b += 1\n\n\t\tif i == len(tasks) - 1 or tasks[i + 1][1] != tasks[i][1]:\n\t\t\tresult = max(result, count(a, b, num_a, num_b, cur_time))\n\n\t\t#print(\"i =\", i, \"result = \", result)\n\n\tresult = max(result, count(a, b, total_a, total_b, T))\n\treturn result\n\n\nq = int(input())\n\nfor i in range(q):\n\tn, T, a, b = list(map(int, input().split()))\n\ttypes = list(map(int, input().split()))\n\ttotal_a, total_b = 0, 0\n\tfor t in types:\n\t\tif t == 0:\n\t\t\ttotal_a += 1\n\t\telse:\n\t\t\ttotal_b += 1\n\tt = list(map(int, input().split()))\n\t#print(t)\n\t#print(types)\n\ttasks = list(zip(t, types))\n\tprint(solve(n, T, a, b, tasks, total_a, total_b))\t\n\n```","inputs":"10\n3 5 1 3\n0 0 1\n2 1 4\n2 5 2 3\n1 0\n3 2\n1 20 2 4\n0\n16\n6 20 2 5\n1 1 0 1 0 0\n0 8 2 9 11 6\n4 16 3 6\n1 0 1 1\n8 3 5 6\n6 20 3 6\n0 1 0 0 1 0\n20 11 3 20 16 17\n7 17 1 6\n1 1 0 1 0 0 0\n1 7 0 11 10 15 10\n6 17 2 6\n0 0 1 0 0 1\n7 6 3 7 10 12\n5 17 2 5\n1 1 1 1 0\n17 11 10 6 4\n1 1 1 2\n0\n1\n","output":"3\n2\n1\n0\n1\n4\n0\n1\n2\n1\n","actual_output":"3\n2\n1\n0\n1\n4\n0\n1\n2\n1\n","execution_success":true,"sample_index":97},{"source":"apps","task_type":"verifiable_code","in_source_id":"97","prompt":"Solve the following coding problem using the programming language python:\n\nYour friend Jeff Zebos has been trying to run his new online company, but it's not going very well. He's not getting a lot of sales on his website which he decided to call Azamon. His big problem, you think, is that he's not ranking high enough on the search engines. If only he could rename his products to have better names than his competitors, then he'll be at the top of the search results and will be a millionaire.\n\nAfter doing some research, you find out that search engines only sort their results lexicographically. If your friend could rename his products to lexicographically smaller strings than his competitor's, then he'll be at the top of the rankings!\n\nTo make your strategy less obvious to his competitors, you decide to swap no more than two letters of the product names.\n\nPlease help Jeff to find improved names for his products that are lexicographically smaller than his competitor's!\n\nGiven the string $s$ representing Jeff's product name and the string $c$ representing his competitor's product name, find a way to swap at most one pair of characters in $s$ (that is, find two distinct indices $i$ and $j$ and swap $s_i$ and $s_j$) such that the resulting new name becomes strictly lexicographically smaller than $c$, or determine that it is impossible.\n\nNote: String $a$ is strictly lexicographically smaller than string $b$ if and only if one of the following holds: $a$ is a proper prefix of $b$, that is, $a$ is a prefix of $b$ such that $a \\neq b$; There exists an integer $1 \\le i \\le \\min{(|a|, |b|)}$ such that $a_i < b_i$ and $a_j = b_j$ for $1 \\le j < i$. \n\n\n-----Input-----\n\nThe first line of input contains a single integer $t$ ($1 \\le t \\le 1500$) denoting the number of test cases. The next lines contain descriptions of the test cases.\n\nEach test case consists of a single line containing two space-separated strings $s$ and $c$ ($2 \\le |s| \\le 5000, 1 \\le |c| \\le 5000$). The strings $s$ and $c$ consists of uppercase English letters.\n\nIt is guaranteed that the sum of $|s|$ in the input is at most $5000$ and the sum of the $|c|$ in the input is at most $5000$.\n\n\n-----Output-----\n\nFor each test case, output a single line containing a single string, which is either the new name which is obtained after swapping no more than one pair of characters that is strictly lexicographically smaller than $c$. In case there are many possible such strings, you can output any of them; three dashes (the string \"---\" without quotes) if it is impossible. \n\n\n-----Example-----\nInput\n3\nAZAMON APPLE\nAZAMON AAAAAAAAAAALIBABA\nAPPLE BANANA\n\nOutput\nAMAZON\n---\nAPPLE\n\n\n\n-----Note-----\n\nIn the first test case, it is possible to swap the second and the fourth letters of the string and the resulting string \"AMAZON\" is lexicographically smaller than \"APPLE\".\n\nIt is impossible to improve the product's name in the second test case and satisfy all conditions.\n\nIn the third test case, it is possible not to swap a pair of characters. The name \"APPLE\" is lexicographically smaller than \"BANANA\". Note that there are other valid answers, e.g., \"APPEL\".\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nimport sys\nreader = (s.rstrip() for s in sys.stdin)\ninput = reader.__next__\n\ndef solve():\n s,c = input().split()\n # i,j\u3067j\u304c\u8907\u6570\u3042\u308b\u3068\u304d\n n = len(s)\n for i in range(n-1):\n prev = s[i]\n pos = i\n for j in range(i+1, n):\n if s[j]= a and left <= right:\n print(b - a - (right - left))\n else:\n print(b - a)\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '9\\n1 10 7 1\\n3 3 3 0\\n8 2 10 4\\n8 2 10 100\\n-10 20 -17 2\\n-3 2 2 0\\n-3 1 2 0\\n2 3 2 3\\n-1 3 -2 2\\n', 'output': '7\\n0\\n4\\n0\\n30\\n5\\n4\\n0\\n3\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/1282/A'}","problem_id":"vfc_404","program":"```python\nimport os\nfrom io import BytesIO\n\n# input = BytesIO(os.read(0, os.fstat(0).st_size)).readline\nfor i in range(int(input())):\n a, b, c, r = list(map(int, input().split()))\n a, b = min(a, b), max(a, b)\n left = max(c - r, a)\n right = min(c + r, b)\n if right >= a and left <= right:\n print(b - a - (right - left))\n else:\n print(b - a)\n\n```","inputs":"9\n1 10 7 1\n3 3 3 0\n8 2 10 4\n8 2 10 100\n-10 20 -17 2\n-3 2 2 0\n-3 1 2 0\n2 3 2 3\n-1 3 -2 2\n","output":"7\n0\n4\n0\n30\n5\n4\n0\n3\n","actual_output":"7\n0\n4\n0\n30\n5\n4\n0\n3\n","execution_success":true,"sample_index":102},{"source":"apps","task_type":"verifiable_code","in_source_id":"102","prompt":"Solve the following coding problem using the programming language python:\n\nHooray! Polycarp turned $n$ years old! The Technocup Team sincerely congratulates Polycarp!\n\nPolycarp celebrated all of his $n$ birthdays: from the $1$-th to the $n$-th. At the moment, he is wondering: how many times he turned beautiful number of years?\n\nAccording to Polycarp, a positive integer is beautiful if it consists of only one digit repeated one or more times. For example, the following numbers are beautiful: $1$, $77$, $777$, $44$ and $999999$. The following numbers are not beautiful: $12$, $11110$, $6969$ and $987654321$.\n\nOf course, Polycarpus uses the decimal numeral system (i.e. radix is 10).\n\nHelp Polycarpus to find the number of numbers from $1$ to $n$ (inclusive) that are beautiful.\n\n\n-----Input-----\n\nThe first line contains an integer $t$ ($1 \\le t \\le 10^4$) \u2014 the number of test cases in the input. Then $t$ test cases follow.\n\nEach test case consists of one line, which contains a positive integer $n$ ($1 \\le n \\le 10^9$) \u2014 how many years Polycarp has turned.\n\n\n-----Output-----\n\nPrint $t$ integers \u2014 the answers to the given test cases in the order they are written in the test. Each answer is an integer: the number of beautiful years between $1$ and $n$, inclusive.\n\n\n-----Example-----\nInput\n6\n18\n1\n9\n100500\n33\n1000000000\n\nOutput\n10\n1\n9\n45\n12\n81\n\n\n\n-----Note-----\n\nIn the first test case of the example beautiful years are $1$, $2$, $3$, $4$, $5$, $6$, $7$, $8$, $9$ and $11$.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\ns = []\nfor i in range(1, 10):\n k = 0\n for l in range(1, 10):\n k *= 10\n k += i\n s.append(k)\ns.sort()\nq = int(input())\nwhile q:\n n = int(input())\n l = 0\n r = len(s)\n while l + 1 < r:\n m = (l + r) // 2\n if s[m] <= n:\n l = m\n else:\n r = m\n print(r)\n q -= 1\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '6\\n18\\n1\\n9\\n100500\\n33\\n1000000000\\n', 'output': '10\\n1\\n9\\n45\\n12\\n81\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/1259/A'}","problem_id":"vfc_408","program":"```python\ns = []\nfor i in range(1, 10):\n k = 0\n for l in range(1, 10):\n k *= 10\n k += i\n s.append(k)\ns.sort()\nq = int(input())\nwhile q:\n n = int(input())\n l = 0\n r = len(s)\n while l + 1 < r:\n m = (l + r) // 2\n if s[m] <= n:\n l = m\n else:\n r = m\n print(r)\n q -= 1\n```","inputs":"6\n18\n1\n9\n100500\n33\n1000000000\n","output":"10\n1\n9\n45\n12\n81\n","actual_output":"10\n1\n9\n45\n12\n81\n","execution_success":true,"sample_index":103},{"source":"apps","task_type":"verifiable_code","in_source_id":"103","prompt":"Solve the following coding problem using the programming language python:\n\nAshish and Vivek play a game on a matrix consisting of $n$ rows and $m$ columns, where they take turns claiming cells. Unclaimed cells are represented by $0$, while claimed cells are represented by $1$. The initial state of the matrix is given. There can be some claimed cells in the initial state.\n\nIn each turn, a player must claim a cell. A cell may be claimed if it is unclaimed and does not share a row or column with any other already claimed cells. When a player is unable to make a move, he loses and the game ends.\n\nIf Ashish and Vivek take turns to move and Ashish goes first, determine the winner of the game if both of them are playing optimally.\n\nOptimal play between two players means that both players choose the best possible strategy to achieve the best possible outcome for themselves.\n\n\n-----Input-----\n\nThe first line consists of a single integer $t$ $(1 \\le t \\le 50)$\u00a0\u2014 the number of test cases. The description of the test cases follows.\n\nThe first line of each test case consists of two space-separated integers $n$, $m$ $(1 \\le n, m \\le 50)$\u00a0\u2014 the number of rows and columns in the matrix.\n\nThe following $n$ lines consist of $m$ integers each, the $j$-th integer on the $i$-th line denoting $a_{i,j}$ $(a_{i,j} \\in \\{0, 1\\})$.\n\n\n-----Output-----\n\nFor each test case if Ashish wins the game print \"Ashish\" otherwise print \"Vivek\" (without quotes).\n\n\n-----Example-----\nInput\n4\n2 2\n0 0\n0 0\n2 2\n0 0\n0 1\n2 3\n1 0 1\n1 1 0\n3 3\n1 0 0\n0 0 0\n1 0 0\n\nOutput\nVivek\nAshish\nVivek\nAshish\n\n\n\n-----Note-----\n\nFor the first case: One possible scenario could be: Ashish claims cell $(1, 1)$, Vivek then claims cell $(2, 2)$. Ashish can neither claim cell $(1, 2)$, nor cell $(2, 1)$ as cells $(1, 1)$ and $(2, 2)$ are already claimed. Thus Ashish loses. It can be shown that no matter what Ashish plays in this case, Vivek will win. \n\nFor the second case: Ashish claims cell $(1, 1)$, the only cell that can be claimed in the first move. After that Vivek has no moves left.\n\nFor the third case: Ashish cannot make a move, so Vivek wins.\n\nFor the fourth case: If Ashish claims cell $(2, 3)$, Vivek will have no moves left.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nt = int(input())\n\nfor _ in range(t):\n n, m = [int(x) for x in input().split()]\n grid = [[int(x) for x in input().split()] for _ in range(n)]\n\n rows = sum(1 for x in grid if all(y == 0 for y in x))\n cols = sum(1 for j in range(m) if all(grid[i][j] == 0 for i in range(n)))\n\n res = min(rows, cols)\n\n print(\"Ashish\" if res % 2 else \"Vivek\")\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '4\\n2 2\\n0 0\\n0 0\\n2 2\\n0 0\\n0 1\\n2 3\\n1 0 1\\n1 1 0\\n3 3\\n1 0 0\\n0 0 0\\n1 0 0\\n', 'output': 'Vivek\\nAshish\\nVivek\\nAshish\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/1365/A'}","problem_id":"vfc_412","program":"```python\nt = int(input())\n\nfor _ in range(t):\n n, m = [int(x) for x in input().split()]\n grid = [[int(x) for x in input().split()] for _ in range(n)]\n\n rows = sum(1 for x in grid if all(y == 0 for y in x))\n cols = sum(1 for j in range(m) if all(grid[i][j] == 0 for i in range(n)))\n\n res = min(rows, cols)\n\n print(\"Ashish\" if res % 2 else \"Vivek\")\n\n```","inputs":"4\n2 2\n0 0\n0 0\n2 2\n0 0\n0 1\n2 3\n1 0 1\n1 1 0\n3 3\n1 0 0\n0 0 0\n1 0 0\n","output":"Vivek\nAshish\nVivek\nAshish\n","actual_output":"Vivek\nAshish\nVivek\nAshish\n","execution_success":true,"sample_index":104},{"source":"apps","task_type":"verifiable_code","in_source_id":"104","prompt":"Solve the following coding problem using the programming language python:\n\nYou are given a colored permutation $p_1, p_2, \\dots, p_n$. The $i$-th element of the permutation has color $c_i$.\n\nLet's define an infinite path as infinite sequence $i, p[i], p[p[i]], p[p[p[i]]] \\dots$ where all elements have same color ($c[i] = c[p[i]] = c[p[p[i]]] = \\dots$).\n\nWe can also define a multiplication of permutations $a$ and $b$ as permutation $c = a \\times b$ where $c[i] = b[a[i]]$. Moreover, we can define a power $k$ of permutation $p$ as $p^k=\\underbrace{p \\times p \\times \\dots \\times p}_{k \\text{ times}}$.\n\nFind the minimum $k > 0$ such that $p^k$ has at least one infinite path (i.e. there is a position $i$ in $p^k$ such that the sequence starting from $i$ is an infinite path).\n\nIt can be proved that the answer always exists.\n\n\n-----Input-----\n\nThe first line contains single integer $T$ ($1 \\le T \\le 10^4$) \u2014 the number of test cases.\n\nNext $3T$ lines contain test cases \u2014 one per three lines. The first line contains single integer $n$ ($1 \\le n \\le 2 \\cdot 10^5$) \u2014 the size of the permutation.\n\nThe second line contains $n$ integers $p_1, p_2, \\dots, p_n$ ($1 \\le p_i \\le n$, $p_i \\neq p_j$ for $i \\neq j$) \u2014 the permutation $p$.\n\nThe third line contains $n$ integers $c_1, c_2, \\dots, c_n$ ($1 \\le c_i \\le n$) \u2014 the colors of elements of the permutation.\n\nIt is guaranteed that the total sum of $n$ doesn't exceed $2 \\cdot 10^5$.\n\n\n-----Output-----\n\nPrint $T$ integers \u2014 one per test case. For each test case print minimum $k > 0$ such that $p^k$ has at least one infinite path.\n\n\n-----Example-----\nInput\n3\n4\n1 3 4 2\n1 2 2 3\n5\n2 3 4 5 1\n1 2 3 4 5\n8\n7 4 5 6 1 8 3 2\n5 3 6 4 7 5 8 4\n\nOutput\n1\n5\n2\n\n\n\n-----Note-----\n\nIn the first test case, $p^1 = p = [1, 3, 4, 2]$ and the sequence starting from $1$: $1, p[1] = 1, \\dots$ is an infinite path.\n\nIn the second test case, $p^5 = [1, 2, 3, 4, 5]$ and it obviously contains several infinite paths.\n\nIn the third test case, $p^2 = [3, 6, 1, 8, 7, 2, 5, 4]$ and the sequence starting from $4$: $4, p^2[4]=8, p^2[8]=4, \\dots$ is an infinite path since $c_4 = c_8 = 4$.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfrom sys import stdin\ninput = stdin.readline\nq = int(input())\nfor rwerew in range(q):\n\tn = int(input())\n\tp = list(map(int,input().split()))\n\tc = list(map(int,input().split()))\n\tfor i in range(n):\n\t\tp[i] -= 1\n\tprzyn = [0] * n\n\tgrupa = []\n\ti = 0\n\twhile i < n:\n\t\tif przyn[i] == 1:\n\t\t\ti += 1\n\t\telse:\n\t\t\tnowa_grupa = [i]\n\t\t\tj = p[i]\n\t\t\tprzyn[i] = 1\n\t\t\twhile j != i:\n\t\t\t\tprzyn[j] = 1\n\t\t\t\tnowa_grupa.append(j)\n\t\t\t\tj = p[j]\n\t\t\tgrupa.append(nowa_grupa)\n\tgrupacol = []\n\tfor i in grupa:\n\t\tcyk = []\n\t\tfor j in i:\n\t\t\tcyk.append(c[j])\n\t\tgrupacol.append(cyk)\n\t#print(grupacol)\n\tmini = 234283742834\n\tfor cykl in grupacol:\n\t\tdziel = []\n\t\td = 1\n\t\twhile d**2 <= len(cykl):\n\t\t\tif len(cykl)%d == 0:\n\t\t\t\tdziel.append(d)\n\t\t\td += 1\n\t\tdodat = []\n\t\tfor d in dziel:\n\t\t\tdodat.append(len(cykl)/d)\n\t\tdziel_ost = list(map(int,dziel + dodat))\n\t\t#print(dziel_ost, len(cykl))\n\t\tfor dzielnik in dziel_ost:\n\t\t\tfor i in range(dzielnik):\n\t\t\t\tindeks = i\n\t\t\t\tsecik = set()\n\t\t\t\tchuj = True\n\t\t\t\twhile indeks < len(cykl):\n\t\t\t\t\tsecik.add(cykl[indeks])\n\t\t\t\t\tindeks += dzielnik\n\t\t\t\t\tif len(secik) > 1:\n\t\t\t\t\t\tchuj = False\n\t\t\t\t\t\tbreak\n\t\t\t\tif chuj:\n\t\t\t\t\tmini = min(mini, dzielnik)\n\tprint(mini)\n\t\t\t\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\n4\\n1 3 4 2\\n1 2 2 3\\n5\\n2 3 4 5 1\\n1 2 3 4 5\\n8\\n7 4 5 6 1 8 3 2\\n5 3 6 4 7 5 8 4\\n', 'output': '1\\n5\\n2\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/1327/D'}","problem_id":"vfc_416","program":"```python\nfrom sys import stdin\ninput = stdin.readline\nq = int(input())\nfor rwerew in range(q):\n\tn = int(input())\n\tp = list(map(int,input().split()))\n\tc = list(map(int,input().split()))\n\tfor i in range(n):\n\t\tp[i] -= 1\n\tprzyn = [0] * n\n\tgrupa = []\n\ti = 0\n\twhile i < n:\n\t\tif przyn[i] == 1:\n\t\t\ti += 1\n\t\telse:\n\t\t\tnowa_grupa = [i]\n\t\t\tj = p[i]\n\t\t\tprzyn[i] = 1\n\t\t\twhile j != i:\n\t\t\t\tprzyn[j] = 1\n\t\t\t\tnowa_grupa.append(j)\n\t\t\t\tj = p[j]\n\t\t\tgrupa.append(nowa_grupa)\n\tgrupacol = []\n\tfor i in grupa:\n\t\tcyk = []\n\t\tfor j in i:\n\t\t\tcyk.append(c[j])\n\t\tgrupacol.append(cyk)\n\t#print(grupacol)\n\tmini = 234283742834\n\tfor cykl in grupacol:\n\t\tdziel = []\n\t\td = 1\n\t\twhile d**2 <= len(cykl):\n\t\t\tif len(cykl)%d == 0:\n\t\t\t\tdziel.append(d)\n\t\t\td += 1\n\t\tdodat = []\n\t\tfor d in dziel:\n\t\t\tdodat.append(len(cykl)/d)\n\t\tdziel_ost = list(map(int,dziel + dodat))\n\t\t#print(dziel_ost, len(cykl))\n\t\tfor dzielnik in dziel_ost:\n\t\t\tfor i in range(dzielnik):\n\t\t\t\tindeks = i\n\t\t\t\tsecik = set()\n\t\t\t\tchuj = True\n\t\t\t\twhile indeks < len(cykl):\n\t\t\t\t\tsecik.add(cykl[indeks])\n\t\t\t\t\tindeks += dzielnik\n\t\t\t\t\tif len(secik) > 1:\n\t\t\t\t\t\tchuj = False\n\t\t\t\t\t\tbreak\n\t\t\t\tif chuj:\n\t\t\t\t\tmini = min(mini, dzielnik)\n\tprint(mini)\n\t\t\t\n\n```","inputs":"3\n4\n1 3 4 2\n1 2 2 3\n5\n2 3 4 5 1\n1 2 3 4 5\n8\n7 4 5 6 1 8 3 2\n5 3 6 4 7 5 8 4\n","output":"1\n5\n2\n","actual_output":"1\n5\n2\n","execution_success":true,"sample_index":105},{"source":"apps","task_type":"verifiable_code","in_source_id":"105","prompt":"Solve the following coding problem using the programming language python:\n\n\u2014 Hey folks, how do you like this problem?\n\n\u2014 That'll do it. \n\nBThero is a powerful magician. He has got $n$ piles of candies, the $i$-th pile initially contains $a_i$ candies. BThero can cast a copy-paste spell as follows: He chooses two piles $(i, j)$ such that $1 \\le i, j \\le n$ and $i \\ne j$. All candies from pile $i$ are copied into pile $j$. Formally, the operation $a_j := a_j + a_i$ is performed. \n\nBThero can cast this spell any number of times he wants to \u2014 but unfortunately, if some pile contains strictly more than $k$ candies, he loses his magic power. What is the maximum number of times BThero can cast the spell without losing his power?\n\n\n-----Input-----\n\nThe first line contains one integer $T$ ($1 \\le T \\le 500$) \u2014 the number of test cases.\n\nEach test case consists of two lines: the first line contains two integers $n$ and $k$ ($2 \\le n \\le 1000$, $2 \\le k \\le 10^4$); the second line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ ($1 \\le a_i \\le k$). \n\nIt is guaranteed that the sum of $n$ over all test cases does not exceed $1000$, and the sum of $k$ over all test cases does not exceed $10^4$.\n\n\n-----Output-----\n\nFor each test case, print one integer \u2014 the maximum number of times BThero can cast the spell without losing his magic power.\n\n\n-----Example-----\nInput\n3\n2 2\n1 1\n3 5\n1 2 3\n3 7\n3 2 2\n\nOutput\n1\n5\n4\n\n\n\n-----Note-----\n\nIn the first test case we get either $a = [1, 2]$ or $a = [2, 1]$ after casting the spell for the first time, and it is impossible to cast it again.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nimport math\nt = int(input())\nfor test in range(t):\n n,k = map(int,input().split())\n A = list(map(int,input().split()))\n A.sort()\n ans = 0\n for i in range(1,n):\n if(A[i]>k):\n ans = 0\n break\n rem = k-A[i]\n ans+=rem//A[0]\n print(ans)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\n2 2\\n1 1\\n3 5\\n1 2 3\\n3 7\\n3 2 2\\n', 'output': '1\\n5\\n4\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/1417/A'}","problem_id":"vfc_420","program":"```python\nimport math\nt = int(input())\nfor test in range(t):\n n,k = map(int,input().split())\n A = list(map(int,input().split()))\n A.sort()\n ans = 0\n for i in range(1,n):\n if(A[i]>k):\n ans = 0\n break\n rem = k-A[i]\n ans+=rem//A[0]\n print(ans)\n```","inputs":"3\n2 2\n1 1\n3 5\n1 2 3\n3 7\n3 2 2\n","output":"1\n5\n4\n","actual_output":"1\n5\n4\n","execution_success":true,"sample_index":106},{"source":"apps","task_type":"verifiable_code","in_source_id":"107","prompt":"Solve the following coding problem using the programming language python:\n\nChaneka has a hobby of playing with animal toys. Every toy has a different fun value, a real number. Chaneka has four boxes to store the toys with specification: The first box stores toys with fun values in range of $(-\\infty,-1]$. The second box stores toys with fun values in range of $(-1, 0)$. The third box stores toys with fun values in range of $(0, 1)$. The fourth box stores toys with fun value in range of $[1, \\infty)$. \n\nChaneka has $A$, $B$, $C$, $D$ toys in the first, second, third, and fourth box, respectively. One day she decides that she only wants one toy, a super toy. So she begins to create this super toy by sewing all the toys she has.\n\nWhile the number of toys Chaneka has is more than 1, she takes two different toys randomly and then sews them together, creating a new toy. The fun value of this new toy is equal to the multiplication of fun values of the sewn toys. She then puts this new toy in the appropriate box. She repeats this process until she only has one toy. This last toy is the super toy, and the box that stores this toy is the special box.\n\nAs an observer, you only know the number of toys in each box initially but do not know their fun values. You also don't see the sequence of Chaneka's sewing. Determine which boxes can be the special box after Chaneka found her super toy.\n\n\n-----Input-----\n\nThe first line has an integer $T$ $(1 \\le T \\le 5 \\cdot 10^4)$, the number of test cases.\n\nEvery case contains a line with four space-separated integers $A$ $B$ $C$ $D$ $(0 \\le A, B, C, D \\le 10^6, A + B + C + D > 0)$, which denotes the number of toys in the first, second, third, and fourth box, respectively.\n\n\n-----Output-----\n\nFor each case, print four space-separated strings. Each string represents the possibility that the first, second, third, and fourth box can be the special box from left to right.\n\nFor each box, print \"Ya\" (Without quotes, Indonesian for yes) if that box can be the special box. Print \"Tidak\" (Without quotes, Indonesian for No) otherwise.\n\n\n-----Example-----\nInput\n2\n1 2 0 1\n0 1 0 0\n\nOutput\nYa Ya Tidak Tidak\nTidak Ya Tidak Tidak\n\n\n\n-----Note-----\n\nFor the first case, here is a scenario where the first box is the special box: The first box had toys with fun values $\\{-3\\}$. The second box had toys with fun values $\\{ -0.5, -0.5 \\}$ The fourth box had toys with fun values $\\{ 3 \\}$ \n\nThe sewing sequence: Chaneka sews the toy with fun $-0.5$ and $-0.5$ to a toy with fun $0.25$ and then put it in the third box. Chaneka sews the toy with fun $-3$ and $0.25$ to a toy with fun $-0.75$ and then put it in the second box. Chaneka sews the toy with fun $-0.75$ and $3$ to a toy with fun $-1.25$ and then put it in the first box, which then became the special box. \n\nHere is a scenario where the second box ends up being the special box: The first box had toys with fun values $\\{-3\\}$ The second box had toys with fun values $\\{ -0.33, -0.25 \\}$. The fourth box had toys with fun values $\\{ 3 \\}$. \n\nThe sewing sequence: Chaneka sews the toy with fun $-3$ and $-0.33$ to a toy with fun $0.99$ and then put it in the third box. Chaneka sews the toy with fun $0.99$ and $3$ to a toy with fun $2.97$ and then put in it the fourth box. Chaneka sews the toy with fun $2.97$ and $-0.25$ to a toy with fun $-0.7425$ and then put it in the second box, which then became the special box. There is only one toy for the second case, so Chaneka does not have to sew anything because that toy, by definition, is the super toy.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nt = int(input())\nfor _ in range(t):\n a, b, c, d = [int(i) for i in input().split(\" \")]\n sgn = (a+b)%2\n small = False\n large = False\n if a == 0 and d == 0:\n small = True\n if b == 0 and c == 0:\n large = True\n okay = [True] * 4\n if sgn == 0:\n okay[0] = False\n okay[1] = False\n else:\n okay[2] = False\n okay[3] = False\n if small:\n okay[0] = False\n okay[3] = False\n if large:\n okay[1] = False\n okay[2] = False\n print(\" \".join([\"Ya\" if okay[i] else \"Tidak\" for i in range(4)]))\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n1 2 0 1\\n0 1 0 0\\n', 'output': 'Ya Ya Tidak Tidak\\nTidak Ya Tidak Tidak\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/1425/H'}","problem_id":"vfc_428","program":"```python\nt = int(input())\nfor _ in range(t):\n a, b, c, d = [int(i) for i in input().split(\" \")]\n sgn = (a+b)%2\n small = False\n large = False\n if a == 0 and d == 0:\n small = True\n if b == 0 and c == 0:\n large = True\n okay = [True] * 4\n if sgn == 0:\n okay[0] = False\n okay[1] = False\n else:\n okay[2] = False\n okay[3] = False\n if small:\n okay[0] = False\n okay[3] = False\n if large:\n okay[1] = False\n okay[2] = False\n print(\" \".join([\"Ya\" if okay[i] else \"Tidak\" for i in range(4)]))\n```","inputs":"2\n1 2 0 1\n0 1 0 0\n","output":"Ya Ya Tidak Tidak\nTidak Ya Tidak Tidak\n","actual_output":"Ya Ya Tidak Tidak\nTidak Ya Tidak Tidak\n","execution_success":true,"sample_index":108},{"source":"apps","task_type":"verifiable_code","in_source_id":"108","prompt":"Solve the following coding problem using the programming language python:\n\nYou're given an array $a_1, \\ldots, a_n$ of $n$ non-negative integers.\n\nLet's call it sharpened if and only if there exists an integer $1 \\le k \\le n$ such that $a_1 < a_2 < \\ldots < a_k$ and $a_k > a_{k+1} > \\ldots > a_n$. In particular, any strictly increasing or strictly decreasing array is sharpened. For example: The arrays $[4]$, $[0, 1]$, $[12, 10, 8]$ and $[3, 11, 15, 9, 7, 4]$ are sharpened; The arrays $[2, 8, 2, 8, 6, 5]$, $[0, 1, 1, 0]$ and $[2, 5, 6, 9, 8, 8]$ are not sharpened. \n\nYou can do the following operation as many times as you want: choose any strictly positive element of the array, and decrease it by one. Formally, you can choose any $i$ ($1 \\le i \\le n$) such that $a_i>0$ and assign $a_i := a_i - 1$.\n\nTell if it's possible to make the given array sharpened using some number (possibly zero) of these operations.\n\n\n-----Input-----\n\nThe input consists of multiple test cases. The first line contains a single integer $t$ ($1 \\le t \\le 15\\ 000$) \u00a0\u2014 the number of test cases. The description of the test cases follows.\n\nThe first line of each test case contains a single integer $n$ ($1 \\le n \\le 3 \\cdot 10^5$).\n\nThe second line of each test case contains a sequence of $n$ non-negative integers $a_1, \\ldots, a_n$ ($0 \\le a_i \\le 10^9$).\n\nIt is guaranteed that the sum of $n$ over all test cases does not exceed $3 \\cdot 10^5$.\n\n\n-----Output-----\n\nFor each test case, output a single line containing \"Yes\" (without quotes) if it's possible to make the given array sharpened using the described operations, or \"No\" (without quotes) otherwise.\n\n\n-----Example-----\nInput\n10\n1\n248618\n3\n12 10 8\n6\n100 11 15 9 7 8\n4\n0 1 1 0\n2\n0 0\n2\n0 1\n2\n1 0\n2\n1 1\n3\n0 1 0\n3\n1 0 1\n\nOutput\nYes\nYes\nYes\nNo\nNo\nYes\nYes\nYes\nYes\nNo\n\n\n\n-----Note-----\n\nIn the first and the second test case of the first test, the given array is already sharpened.\n\nIn the third test case of the first test, we can transform the array into $[3, 11, 15, 9, 7, 4]$ (decrease the first element $97$ times and decrease the last element $4$ times). It is sharpened because $3 < 11 < 15$ and $15 > 9 > 7 > 4$.\n\nIn the fourth test case of the first test, it's impossible to make the given array sharpened.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfor _ in range(int(input())):\n n=int(input())\n li=list(map(int,input().split()))\n ans=0\n for i in range(n):\n if li[i]>=i:\n ans+=1\n else:\n break\n for i in range(n):\n if li[n-1-i]>=i:\n ans+=1\n else:\n break\n if ans>n:\n print(\"Yes\")\n else:\n print(\"No\")\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '10\\n1\\n248618\\n3\\n12 10 8\\n6\\n100 11 15 9 7 8\\n4\\n0 1 1 0\\n2\\n0 0\\n2\\n0 1\\n2\\n1 0\\n2\\n1 1\\n3\\n0 1 0\\n3\\n1 0 1\\n', 'output': 'Yes\\nYes\\nYes\\nNo\\nNo\\nYes\\nYes\\nYes\\nYes\\nNo\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/1291/B'}","problem_id":"vfc_432","program":"```python\nfor _ in range(int(input())):\n n=int(input())\n li=list(map(int,input().split()))\n ans=0\n for i in range(n):\n if li[i]>=i:\n ans+=1\n else:\n break\n for i in range(n):\n if li[n-1-i]>=i:\n ans+=1\n else:\n break\n if ans>n:\n print(\"Yes\")\n else:\n print(\"No\")\n```","inputs":"10\n1\n248618\n3\n12 10 8\n6\n100 11 15 9 7 8\n4\n0 1 1 0\n2\n0 0\n2\n0 1\n2\n1 0\n2\n1 1\n3\n0 1 0\n3\n1 0 1\n","output":"Yes\nYes\nYes\nNo\nNo\nYes\nYes\nYes\nYes\nNo\n","actual_output":"Yes\nYes\nYes\nNo\nNo\nYes\nYes\nYes\nYes\nNo\n","execution_success":true,"sample_index":109},{"source":"apps","task_type":"verifiable_code","in_source_id":"109","prompt":"Solve the following coding problem using the programming language python:\n\nYou have a bag of size $n$. Also you have $m$ boxes. The size of $i$-th box is $a_i$, where each $a_i$ is an integer non-negative power of two.\n\nYou can divide boxes into two parts of equal size. Your goal is to fill the bag completely.\n\nFor example, if $n = 10$ and $a = [1, 1, 32]$ then you have to divide the box of size $32$ into two parts of size $16$, and then divide the box of size $16$. So you can fill the bag with boxes of size $1$, $1$ and $8$.\n\nCalculate the minimum number of divisions required to fill the bag of size $n$.\n\n\n-----Input-----\n\nThe first line contains one integer $t$ ($1 \\le t \\le 1000$) \u2014 the number of test cases.\n\nThe first line of each test case contains two integers $n$ and $m$ ($1 \\le n \\le 10^{18}, 1 \\le m \\le 10^5$) \u2014 the size of bag and the number of boxes, respectively.\n\nThe second line of each test case contains $m$ integers $a_1, a_2, \\dots , a_m$ ($1 \\le a_i \\le 10^9$) \u2014 the sizes of boxes. It is guaranteed that each $a_i$ is a power of two.\n\nIt is also guaranteed that sum of all $m$ over all test cases does not exceed $10^5$.\n\n\n-----Output-----\n\nFor each test case print one integer \u2014 the minimum number of divisions required to fill the bag of size $n$ (or $-1$, if it is impossible).\n\n\n-----Example-----\nInput\n3\n10 3\n1 32 1\n23 4\n16 1 4 1\n20 5\n2 1 16 1 8\n\nOutput\n2\n-1\n0\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nimport sys\nimport math\nfrom collections import defaultdict\nfrom collections import deque\nfrom itertools import combinations\nfrom itertools import permutations\ninput = lambda : sys.stdin.readline().rstrip()\nread = lambda : list(map(int, input().split()))\ngo = lambda : 1/0\ndef write(*args, sep=\"\\n\"):\n for i in args:\n sys.stdout.write(\"{}{}\".format(i, sep))\nINF = float('inf')\nMOD = int(1e9 + 7)\nYES = \"YES\"\nNO = -1\n\nfor _ in range(int(input())):\n try:\n n, m = read()\n arr = read()\n x = [0] * 65\n \n if sum(arr) < n:\n print(NO)\n go()\n \n for i in arr:\n x[int(math.log2(i))] += 1\n \n ans = 0\n for i in range(65):\n if (1 << i) & n:\n if x[i] != 0:\n x[i] -= 1\n continue \n\n total = 0\n for j in range(i):\n total += (1 << j) * x[j]\n \n if total >= (1 << i):\n temp = 1 << i \n for j in reversed(range(i)):\n while temp - (1 << j) >= 0 and x[j] > 0:\n temp -= 1 << j \n x[j] -= 1\n continue \n \n j = i\n while j < 65 and x[j] == 0:\n j += 1\n if j == 65:\n print(NO)\n go() \n else:\n x[j] -= 1\n for k in range(i, j):\n x[k] += 1\n ans += (j - i)\n \n print(ans)\n\n\n except ZeroDivisionError:\n continue\n\n except Exception as e:\n print(e)\n continue\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\n10 3\\n1 32 1\\n23 4\\n16 1 4 1\\n20 5\\n2 1 16 1 8\\n', 'output': '2\\n-1\\n0\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/1303/D'}","problem_id":"vfc_436","program":"```python\nimport sys\nimport math\nfrom collections import defaultdict\nfrom collections import deque\nfrom itertools import combinations\nfrom itertools import permutations\ninput = lambda : sys.stdin.readline().rstrip()\nread = lambda : list(map(int, input().split()))\ngo = lambda : 1/0\ndef write(*args, sep=\"\\n\"):\n for i in args:\n sys.stdout.write(\"{}{}\".format(i, sep))\nINF = float('inf')\nMOD = int(1e9 + 7)\nYES = \"YES\"\nNO = -1\n\nfor _ in range(int(input())):\n try:\n n, m = read()\n arr = read()\n x = [0] * 65\n \n if sum(arr) < n:\n print(NO)\n go()\n \n for i in arr:\n x[int(math.log2(i))] += 1\n \n ans = 0\n for i in range(65):\n if (1 << i) & n:\n if x[i] != 0:\n x[i] -= 1\n continue \n\n total = 0\n for j in range(i):\n total += (1 << j) * x[j]\n \n if total >= (1 << i):\n temp = 1 << i \n for j in reversed(range(i)):\n while temp - (1 << j) >= 0 and x[j] > 0:\n temp -= 1 << j \n x[j] -= 1\n continue \n \n j = i\n while j < 65 and x[j] == 0:\n j += 1\n if j == 65:\n print(NO)\n go() \n else:\n x[j] -= 1\n for k in range(i, j):\n x[k] += 1\n ans += (j - i)\n \n print(ans)\n\n\n except ZeroDivisionError:\n continue\n\n except Exception as e:\n print(e)\n continue\n```","inputs":"3\n10 3\n1 32 1\n23 4\n16 1 4 1\n20 5\n2 1 16 1 8\n","output":"2\n-1\n0\n","actual_output":"2\n-1\n0\n","execution_success":true,"sample_index":110},{"source":"apps","task_type":"verifiable_code","in_source_id":"110","prompt":"Solve the following coding problem using the programming language python:\n\nOn February 14 Denis decided to give Valentine to Nastya and did not come up with anything better than to draw a huge red heart on the door of the length $k$ ($k \\ge 3$). Nastya was very confused by this present, so she decided to break the door, throwing it on the mountains.\n\nMountains are described by a sequence of heights $a_1, a_2, \\dots, a_n$ in order from left to right ($k \\le n$). It is guaranteed that neighboring heights are not equal to each other (that is, $a_i \\ne a_{i+1}$ for all $i$ from $1$ to $n-1$).\n\nPeaks of mountains on the segment $[l,r]$ (from $l$ to $r$) are called indexes $i$ such that $l < i < r$, $a_{i - 1} < a_i$ and $a_i > a_{i + 1}$. It is worth noting that the boundary indexes $l$ and $r$ for the segment are not peaks. For example, if $n=8$ and $a=[3,1,4,1,5,9,2,6]$, then the segment $[1,8]$ has only two peaks (with indexes $3$ and $6$), and there are no peaks on the segment $[3, 6]$.\n\nTo break the door, Nastya throws it to a segment $[l,l+k-1]$ of consecutive mountains of length $k$ ($1 \\le l \\le n-k+1$). When the door touches the peaks of the mountains, it breaks into two parts, after that these parts will continue to fall in different halves and also break into pieces when touching the peaks of the mountains, and so on. Formally, the number of parts that the door will break into will be equal to $p+1$, where $p$ is the number of peaks on the segment $[l,l+k-1]$.\n\nNastya wants to break it into as many pieces as possible. Help her choose such a segment of mountains $[l, l+k-1]$ that the number of peaks on it is maximum. If there are several optimal segments, Nastya wants to find one for which the value $l$ is minimal.\n\nFormally, you need to choose a segment of mountains $[l, l+k-1]$ that has the maximum number of peaks. Among all such segments, you need to find the segment that has the minimum possible value $l$.\n\n\n-----Input-----\n\nThe first line contains an integer $t$ ($1 \\leq t \\leq 10^4$) \u00a0\u2014 the number of test cases. Then the descriptions of the test cases follow.\n\nThe first line of each test case contains two integers $n$ and $k$ ($3 \\leq k \\leq n \\leq 2 \\cdot 10^5$) \u00a0\u2014 the number of mountains and the length of the door.\n\nThe second line of the input data set contains $n$ integers $a_1, a_2, \\dots, a_n$ ($0 \\leq a_i \\leq 10 ^ 9$, $a_i \\neq a_{i + 1}$) \u00a0\u2014 the heights of mountains.\n\nIt is guaranteed that the sum of $n$ over all the test cases will not exceed $2 \\cdot 10^5$.\n\n\n-----Output-----\n\nFor each test case, output two integers $t$ and $l$ \u00a0\u2014 the maximum number of parts that the door can split into, and the left border of the segment of length $k$ that the door should be reset to.\n\n\n-----Example-----\nInput\n5\n8 6\n1 2 4 1 2 4 1 2\n5 3\n3 2 3 2 1\n10 4\n4 3 4 3 2 3 2 1 0 1\n15 7\n3 7 4 8 2 3 4 5 21 2 3 4 2 1 3\n7 5\n1 2 3 4 5 6 1\n\nOutput\n3 2\n2 2\n2 1\n3 1\n2 3\n\n\n\n-----Note-----\n\nIn the first example, you need to select a segment of mountains from $2$ to $7$. In this segment, the indexes $3$ and $6$ are peaks, so the answer is $3$ (only $2$ peaks, so the door will break into $3$ parts). It is not difficult to notice that the mountain segments $[1, 6]$ and $[3, 8]$ are not suitable since they only have a $1$ peak (for the first segment, the $6$ index is not a peak, and for the second segment, the $3$ index is not a peak).\n\nIn the second example, you need to select a segment of mountains from $2$ to $4$. In this segment, the index $3$ is a peak, so the answer is $2$ (only $1$ peak, so the door will break into $2$ parts).\n\nIn the third example, you need to select a segment of mountains from $1$ to $4$. In this segment, the index $3$ is a peak, so the answer is $2$ (only $1$ peak, so the door will break into $2$ parts). You can see that on the segments $[2, 5]$, $[4, 7]$ and $[5, 8]$ the number of peaks is also $1$, but these segments have a left border greater than the segment $[1, 4]$, so they are not the correct answer.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfor _ in range(int(input())):\n n, k = tuple(map(int, input().split()))\n arr = list(map(int, input().split()))\n\n peaks = [0 for i in range(n)]\n for i in range(1, n - 1):\n if arr[i] > arr[i - 1] and arr[i] > arr[i + 1]:\n peaks[i] = 1\n\n cnt = 0\n max_peaks = 0\n answer = 0\n\n for i in range(k - 1):\n cnt += peaks[i]\n max_peaks += peaks[i]\n\n for i in range(k - 1, n - 1):\n cnt -= peaks[i - k + 2]\n cnt += peaks[i]\n if cnt > max_peaks:\n max_peaks = cnt\n answer = i - k + 2\n\n print(max_peaks + 1, answer + 1)\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '5\\n8 6\\n1 2 4 1 2 4 1 2\\n5 3\\n3 2 3 2 1\\n10 4\\n4 3 4 3 2 3 2 1 0 1\\n15 7\\n3 7 4 8 2 3 4 5 21 2 3 4 2 1 3\\n7 5\\n1 2 3 4 5 6 1\\n', 'output': '3 2\\n2 2\\n2 1\\n3 1\\n2 3\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/1341/B'}","problem_id":"vfc_440","program":"```python\nfor _ in range(int(input())):\n n, k = tuple(map(int, input().split()))\n arr = list(map(int, input().split()))\n\n peaks = [0 for i in range(n)]\n for i in range(1, n - 1):\n if arr[i] > arr[i - 1] and arr[i] > arr[i + 1]:\n peaks[i] = 1\n\n cnt = 0\n max_peaks = 0\n answer = 0\n\n for i in range(k - 1):\n cnt += peaks[i]\n max_peaks += peaks[i]\n\n for i in range(k - 1, n - 1):\n cnt -= peaks[i - k + 2]\n cnt += peaks[i]\n if cnt > max_peaks:\n max_peaks = cnt\n answer = i - k + 2\n\n print(max_peaks + 1, answer + 1)\n\n```","inputs":"5\n8 6\n1 2 4 1 2 4 1 2\n5 3\n3 2 3 2 1\n10 4\n4 3 4 3 2 3 2 1 0 1\n15 7\n3 7 4 8 2 3 4 5 21 2 3 4 2 1 3\n7 5\n1 2 3 4 5 6 1\n","output":"3 2\n2 2\n2 1\n3 1\n2 3\n","actual_output":"3 2\n2 2\n2 1\n3 1\n2 3\n","execution_success":true,"sample_index":111},{"source":"apps","task_type":"verifiable_code","in_source_id":"111","prompt":"Solve the following coding problem using the programming language python:\n\nYou are given an image, that can be represented with a 2-d n by m grid of pixels. Each pixel of the image is either on or off, denoted by the characters \"0\" or \"1\", respectively. You would like to compress this image. You want to choose an integer k > 1 and split the image into k by k blocks. If n and m are not divisible by k, the image is padded with only zeros on the right and bottom so that they are divisible by k. Each pixel in each individual block must have the same value. The given image may not be compressible in its current state. Find the minimum number of pixels you need to toggle (after padding) in order for the image to be compressible for some k. More specifically, the steps are to first choose k, then the image is padded with zeros, then, we can toggle the pixels so it is compressible for this k. The image must be compressible in that state.\n\n\n-----Input-----\n\nThe first line of input will contain two integers n, m (2 \u2264 n, m \u2264 2 500), the dimensions of the image.\n\nThe next n lines of input will contain a binary string with exactly m characters, representing the image.\n\n\n-----Output-----\n\nPrint a single integer, the minimum number of pixels needed to toggle to make the image compressible.\n\n\n-----Example-----\nInput\n3 5\n00100\n10110\n11001\n\nOutput\n5\n\n\n\n-----Note-----\n\nWe first choose k = 2.\n\nThe image is padded as follows: \n\n001000\n\n101100\n\n110010\n\n000000\n\n\n\nWe can toggle the image to look as follows: \n\n001100\n\n001100\n\n000000\n\n000000\n\n\n\nWe can see that this image is compressible for k = 2.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n#!/usr/bin/env python\n# coding:utf-8\n# Copyright (C) dirlt\n\nfrom sys import stdin\n\n\ndef run(n, m, pixels):\n ans = 1 << 30\n\n acc = [[0] * (m + 1) for _ in range(n + 1)]\n for i in range(n):\n for j in range(m):\n acc[i + 1][j + 1] = acc[i + 1][j] + int(pixels[i][j])\n for j in range(m):\n acc[i + 1][j + 1] += acc[i][j + 1]\n # print(acc)\n\n for k in range(2, max(n, m) + 1):\n r, c = (n + k - 1) // k, (m + k - 1) // k\n res = 0\n for i in range(r):\n for j in range(c):\n x, y = i * k, j * k\n x2, y2 = min(x + k - 1, n - 1), min(y + k - 1, m - 1)\n zero = acc[x2 + 1][y2 + 1] - acc[x][y2 + 1] - acc[x2 + 1][y] + acc[x][y]\n # print(x, y, k, zero, k * k - zero)\n res += min(zero, k * k - zero)\n # print(k, res)\n ans = min(ans, res)\n print(ans)\n\n\ndef main():\n n, m = [int(x) for x in stdin.readline().split()]\n pixels = []\n for i in range(n):\n pixels.append(stdin.readline().strip())\n run(n, m, pixels)\n\n\ndef __starting_point():\n import os\n\n if os.path.exists('tmp.in'):\n stdin = open('tmp.in')\n main()\n\n__starting_point()\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3 5\\n00100\\n10110\\n11001\\n', 'output': '5\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/838/A'}","problem_id":"vfc_444","program":"```python\n#!/usr/bin/env python\n# coding:utf-8\n# Copyright (C) dirlt\n\nfrom sys import stdin\n\n\ndef run(n, m, pixels):\n ans = 1 << 30\n\n acc = [[0] * (m + 1) for _ in range(n + 1)]\n for i in range(n):\n for j in range(m):\n acc[i + 1][j + 1] = acc[i + 1][j] + int(pixels[i][j])\n for j in range(m):\n acc[i + 1][j + 1] += acc[i][j + 1]\n # print(acc)\n\n for k in range(2, max(n, m) + 1):\n r, c = (n + k - 1) // k, (m + k - 1) // k\n res = 0\n for i in range(r):\n for j in range(c):\n x, y = i * k, j * k\n x2, y2 = min(x + k - 1, n - 1), min(y + k - 1, m - 1)\n zero = acc[x2 + 1][y2 + 1] - acc[x][y2 + 1] - acc[x2 + 1][y] + acc[x][y]\n # print(x, y, k, zero, k * k - zero)\n res += min(zero, k * k - zero)\n # print(k, res)\n ans = min(ans, res)\n print(ans)\n\n\ndef main():\n n, m = [int(x) for x in stdin.readline().split()]\n pixels = []\n for i in range(n):\n pixels.append(stdin.readline().strip())\n run(n, m, pixels)\n\n\ndef __starting_point():\n import os\n\n if os.path.exists('tmp.in'):\n stdin = open('tmp.in')\n main()\n\n__starting_point()\n```","inputs":"3 5\n00100\n10110\n11001\n","output":"5\n","actual_output":"5\n","execution_success":true,"sample_index":112},{"source":"apps","task_type":"verifiable_code","in_source_id":"112","prompt":"Solve the following coding problem using the programming language python:\n\nNow that Heidi has made sure her Zombie Contamination level checker works, it's time to strike! This time, the zombie lair is a strictly convex polygon on the lattice. Each vertex of the polygon occupies a point on the lattice. For each cell of the lattice, Heidi knows the level of Zombie Contamination \u2013 the number of corners of the cell that are inside or on the border of the lair.\n\nGiven this information, Heidi wants to know the exact shape of the lair to rain destruction on the zombies. Help her!\n\n[Image]\n\n\n-----Input-----\n\nThe input contains multiple test cases.\n\nThe first line of each test case contains one integer N, the size of the lattice grid (5 \u2264 N \u2264 500). The next N lines each contain N characters, describing the level of Zombie Contamination of each cell in the lattice. Every character of every line is a digit between 0 and 4. \n\nCells are given in the same order as they are shown in the picture above: rows go in the decreasing value of y coordinate, and in one row cells go in the order of increasing x coordinate. This means that the first row corresponds to cells with coordinates (1, N), ..., (N, N) and the last row corresponds to cells with coordinates (1, 1), ..., (N, 1).\n\nThe last line of the file contains a zero. This line should not be treated as a test case. The sum of the N values for all tests in one file will not exceed 5000.\n\n\n-----Output-----\n\nFor each test case, give the following output:\n\nThe first line of the output should contain one integer V, the number of vertices of the polygon that is the secret lair. The next V lines each should contain two integers, denoting the vertices of the polygon in the clockwise order, starting from the lexicographically smallest vertex.\n\n\n-----Examples-----\nInput\n8\n00000000\n00000110\n00012210\n01234200\n02444200\n01223200\n00001100\n00000000\n5\n00000\n01210\n02420\n01210\n00000\n7\n0000000\n0122100\n0134200\n0013200\n0002200\n0001100\n0000000\n0\n\nOutput\n4\n2 3\n2 4\n6 6\n5 2\n4\n2 2\n2 3\n3 3\n3 2\n3\n2 5\n4 5\n4 2\n\n\n\n-----Note-----\n\nIt is guaranteed that the solution always exists and is unique. It is guaranteed that in the correct solution the coordinates of the polygon vertices are between 2 and N - 2. A vertex (x_1, y_1) is lexicographically smaller than vertex (x_2, y_2) if x_1 < x_2 or $x_{1} = x_{2} \\wedge y_{1} < y_{2}$.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nimport math\n\ndef lexComp(a, b):\n if a[0] != b[0]:\n return -1 if a[0] < b[0] else 1\n if a[1] != b[1]:\n return -1 if a[1] < b[1] else 1\n return 0\n\ndef turn(a, b, c):\n return (b[0] - a[0]) * (c[1] - b[1]) - (b[1] - a[1]) * (c[0] - b[0])\n \ndef dist2(a, b):\n return (a[0] - b[0]) ** 2 + (a[1] - b[1]) ** 2\n\ndef solve(n):\n a = [list(map(int, input())) for _ in range(n)]\n points = []\n for i in range(n):\n for j in range(n):\n if a[i][j] == 1:\n curPoints = []\n for dx in range(0, 2):\n for dy in range(0, 2):\n ok = True\n for ddx in range(0, 2):\n for ddy in range(0, 2):\n x, y = i - 1 + dx + ddx, j - 1 + dy + ddy\n if 0 <= x < n and 0 <= y < n and a[x][y] == 0:\n ok = False\n if ok:\n curPoints.append((i + dx, j + dy))\n points.append(curPoints[0])\n points = list(set(points))\n for i in range(1, len(points)):\n if lexComp(points[0], points[i]) > 0:\n points[0], points[i] = points[i], points[0]\n points[1:] = sorted(points[1:], key=lambda p: (math.atan2(p[1] - points[0][1], p[0] - points[0][0]), dist2(p, points[0])))\n hull = []\n for p in points:\n while len(hull) >= 2 and turn(hull[-2], hull[-1], p) <= 0:\n hull.pop()\n hull.append(p)\n hull = [(p[1], n - p[0]) for p in hull]\n hull = hull[::-1]\n start = 0\n for i in range(1, len(hull)):\n if lexComp(hull[i], hull[start]) < 0:\n start = i\n newHull = hull[start:]\n newHull.extend(hull[:start])\n hull = newHull\n print(len(hull))\n for p in hull:\n print(p[0], p[1])\n \nwhile True:\n n = int(input())\n if n == 0:\n break\n solve(n)\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '8\\n00000000\\n00000110\\n00012210\\n01234200\\n02444200\\n01223200\\n00001100\\n00000000\\n5\\n00000\\n01210\\n02420\\n01210\\n00000\\n7\\n0000000\\n0122100\\n0134200\\n0013200\\n0002200\\n0001100\\n0000000\\n0\\n', 'output': '4\\n2 3\\n2 4\\n6 6\\n5 2\\n4\\n2 2\\n2 3\\n3 3\\n3 2\\n3\\n2 5\\n4 5\\n4 2\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/690/B2'}","problem_id":"vfc_448","program":"```python\nimport math\n\ndef lexComp(a, b):\n if a[0] != b[0]:\n return -1 if a[0] < b[0] else 1\n if a[1] != b[1]:\n return -1 if a[1] < b[1] else 1\n return 0\n\ndef turn(a, b, c):\n return (b[0] - a[0]) * (c[1] - b[1]) - (b[1] - a[1]) * (c[0] - b[0])\n \ndef dist2(a, b):\n return (a[0] - b[0]) ** 2 + (a[1] - b[1]) ** 2\n\ndef solve(n):\n a = [list(map(int, input())) for _ in range(n)]\n points = []\n for i in range(n):\n for j in range(n):\n if a[i][j] == 1:\n curPoints = []\n for dx in range(0, 2):\n for dy in range(0, 2):\n ok = True\n for ddx in range(0, 2):\n for ddy in range(0, 2):\n x, y = i - 1 + dx + ddx, j - 1 + dy + ddy\n if 0 <= x < n and 0 <= y < n and a[x][y] == 0:\n ok = False\n if ok:\n curPoints.append((i + dx, j + dy))\n points.append(curPoints[0])\n points = list(set(points))\n for i in range(1, len(points)):\n if lexComp(points[0], points[i]) > 0:\n points[0], points[i] = points[i], points[0]\n points[1:] = sorted(points[1:], key=lambda p: (math.atan2(p[1] - points[0][1], p[0] - points[0][0]), dist2(p, points[0])))\n hull = []\n for p in points:\n while len(hull) >= 2 and turn(hull[-2], hull[-1], p) <= 0:\n hull.pop()\n hull.append(p)\n hull = [(p[1], n - p[0]) for p in hull]\n hull = hull[::-1]\n start = 0\n for i in range(1, len(hull)):\n if lexComp(hull[i], hull[start]) < 0:\n start = i\n newHull = hull[start:]\n newHull.extend(hull[:start])\n hull = newHull\n print(len(hull))\n for p in hull:\n print(p[0], p[1])\n \nwhile True:\n n = int(input())\n if n == 0:\n break\n solve(n)\n\n```","inputs":"8\n00000000\n00000110\n00012210\n01234200\n02444200\n01223200\n00001100\n00000000\n5\n00000\n01210\n02420\n01210\n00000\n7\n0000000\n0122100\n0134200\n0013200\n0002200\n0001100\n0000000\n0\n","output":"4\n2 3\n2 4\n6 6\n5 2\n4\n2 2\n2 3\n3 3\n3 2\n3\n2 5\n4 5\n4 2\n","actual_output":"4\n2 3\n2 4\n6 6\n5 2\n4\n2 2\n2 3\n3 3\n3 2\n3\n2 5\n4 5\n4 2\n","execution_success":true,"sample_index":113},{"source":"apps","task_type":"verifiable_code","in_source_id":"113","prompt":"Solve the following coding problem using the programming language python:\n\nBob watches TV every day. He always sets the volume of his TV to $b$. However, today he is angry to find out someone has changed the volume to $a$. Of course, Bob has a remote control that can change the volume.\n\nThere are six buttons ($-5, -2, -1, +1, +2, +5$) on the control, which in one press can either increase or decrease the current volume by $1$, $2$, or $5$. The volume can be arbitrarily large, but can never be negative. In other words, Bob cannot press the button if it causes the volume to be lower than $0$.\n\nAs Bob is so angry, he wants to change the volume to $b$ using as few button presses as possible. However, he forgets how to do such simple calculations, so he asks you for help. Write a program that given $a$ and $b$, finds the minimum number of presses to change the TV volume from $a$ to $b$.\n\n\n-----Input-----\n\nEach test contains multiple test cases. The first line contains the number of test cases $T$ ($1 \\le T \\le 1\\,000$). Then the descriptions of the test cases follow.\n\nEach test case consists of one line containing two integers $a$ and $b$ ($0 \\le a, b \\le 10^{9}$)\u00a0\u2014 the current volume and Bob's desired volume, respectively.\n\n\n-----Output-----\n\nFor each test case, output a single integer\u00a0\u2014 the minimum number of presses to change the TV volume from $a$ to $b$. If Bob does not need to change the volume (i.e. $a=b$), then print $0$.\n\n\n-----Example-----\nInput\n3\n4 0\n5 14\n3 9\n\nOutput\n2\n3\n2\n\n\n\n-----Note-----\n\nIn the first example, Bob can press the $-2$ button twice to reach $0$. Note that Bob can not press $-5$ when the volume is $4$ since it will make the volume negative. \n\nIn the second example, one of the optimal ways for Bob is to press the $+5$ twice, then press $-1$ once.\n\nIn the last example, Bob can press the $+5$ once, then press $+1$.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nimport math\nfrom decimal import Decimal\nimport heapq\nfrom collections import deque\ndef na():\n\tn = int(input())\n\tb = [int(x) for x in input().split()]\n\treturn n,b\n \n \ndef nab():\n\tn = int(input())\n\tb = [int(x) for x in input().split()]\n\tc = [int(x) for x in input().split()]\n\treturn n,b,c\n \n \ndef dv():\n\tn, m = list(map(int, input().split()))\n\treturn n,m\n \n \ndef dva():\n\tn, m = list(map(int, input().split()))\n\ta = [int(x) for x in input().split()]\n\tb = [int(x) for x in input().split()]\n\treturn n,m,b\n \n \ndef eratosthenes(n): \n\tsieve = list(range(n + 1))\n\tfor i in sieve:\n\t\tif i > 1:\n\t\t\tfor j in range(i + i, len(sieve), i):\n\t\t\t\tsieve[j] = 0\n\treturn sorted(set(sieve))\n \n \ndef lol(lst,k):\n\tk=k%len(lst)\n\tret=[0]*len(lst)\n\tfor i in range(len(lst)):\n\t\tif i+k=0:\n\t\t\tret[i]=lst[i+k]\n\t\tif i+k>=len(lst):\n\t\t\tret[i]=lst[i+k-len(lst)]\n\t\tif i+k<0:\n\t\t\tret[i]=lst[i+k+len(lst)]\n\treturn(ret)\ndef nm():\n\tn = int(input())\n\tb = [int(x) for x in input().split()]\n\tm = int(input())\n\tc = [int(x) for x in input().split()]\n\treturn n,b,m,c\n \n \ndef dvs():\n\tn = int(input())\n\tm = int(input())\n\treturn n, m \n \ndef fact(a, b):\n\tc = []\n\tans = 0\n\tf = int(math.sqrt(a))\n\tfor i in range(1, f + 1):\n\t\tif a % i == 0:\n\t\t\tc.append(i)\n\tl = len(c)\n\tfor i in range(l):\n\t\tc.append(a // c[i])\n\tfor i in range(len(c)):\n\t\tif c[i] <= b:\n\t\t\tans += 1\n\tif a / f == f and b >= f:\n\t\treturn ans - 1\n\treturn ans\n \n\nt = int(input())\nfor i in range(t):\n\ta ,b = list(map(int, input().split()))\n\tif a == b:\n\t\tprint(0)\n\telse:\n\t\td = abs(a - b)\n\t\tk1 = d//5\n\t\td -= k1 *5 \n\t\tk2 = d // 2\n\t\td -= k2 * 2\n\t\tprint(d + k1 + k2)\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\n4 0\\n5 14\\n3 9\\n', 'output': '2\\n3\\n2\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/1255/A'}","problem_id":"vfc_452","program":"```python\nimport math\nfrom decimal import Decimal\nimport heapq\nfrom collections import deque\ndef na():\n\tn = int(input())\n\tb = [int(x) for x in input().split()]\n\treturn n,b\n \n \ndef nab():\n\tn = int(input())\n\tb = [int(x) for x in input().split()]\n\tc = [int(x) for x in input().split()]\n\treturn n,b,c\n \n \ndef dv():\n\tn, m = list(map(int, input().split()))\n\treturn n,m\n \n \ndef dva():\n\tn, m = list(map(int, input().split()))\n\ta = [int(x) for x in input().split()]\n\tb = [int(x) for x in input().split()]\n\treturn n,m,b\n \n \ndef eratosthenes(n): \n\tsieve = list(range(n + 1))\n\tfor i in sieve:\n\t\tif i > 1:\n\t\t\tfor j in range(i + i, len(sieve), i):\n\t\t\t\tsieve[j] = 0\n\treturn sorted(set(sieve))\n \n \ndef lol(lst,k):\n\tk=k%len(lst)\n\tret=[0]*len(lst)\n\tfor i in range(len(lst)):\n\t\tif i+k=0:\n\t\t\tret[i]=lst[i+k]\n\t\tif i+k>=len(lst):\n\t\t\tret[i]=lst[i+k-len(lst)]\n\t\tif i+k<0:\n\t\t\tret[i]=lst[i+k+len(lst)]\n\treturn(ret)\ndef nm():\n\tn = int(input())\n\tb = [int(x) for x in input().split()]\n\tm = int(input())\n\tc = [int(x) for x in input().split()]\n\treturn n,b,m,c\n \n \ndef dvs():\n\tn = int(input())\n\tm = int(input())\n\treturn n, m \n \ndef fact(a, b):\n\tc = []\n\tans = 0\n\tf = int(math.sqrt(a))\n\tfor i in range(1, f + 1):\n\t\tif a % i == 0:\n\t\t\tc.append(i)\n\tl = len(c)\n\tfor i in range(l):\n\t\tc.append(a // c[i])\n\tfor i in range(len(c)):\n\t\tif c[i] <= b:\n\t\t\tans += 1\n\tif a / f == f and b >= f:\n\t\treturn ans - 1\n\treturn ans\n \n\nt = int(input())\nfor i in range(t):\n\ta ,b = list(map(int, input().split()))\n\tif a == b:\n\t\tprint(0)\n\telse:\n\t\td = abs(a - b)\n\t\tk1 = d//5\n\t\td -= k1 *5 \n\t\tk2 = d // 2\n\t\td -= k2 * 2\n\t\tprint(d + k1 + k2)\n\n```","inputs":"3\n4 0\n5 14\n3 9\n","output":"2\n3\n2\n","actual_output":"2\n3\n2\n","execution_success":true,"sample_index":114},{"source":"apps","task_type":"verifiable_code","in_source_id":"114","prompt":"Solve the following coding problem using the programming language python:\n\nYou play a computer game. In this game, you lead a party of $m$ heroes, and you have to clear a dungeon with $n$ monsters. Each monster is characterized by its power $a_i$. Each hero is characterized by his power $p_i$ and endurance $s_i$.\n\nThe heroes clear the dungeon day by day. In the beginning of each day, you choose a hero (exactly one) who is going to enter the dungeon this day.\n\nWhen the hero enters the dungeon, he is challenged by the first monster which was not defeated during the previous days (so, if the heroes have already defeated $k$ monsters, the hero fights with the monster $k + 1$). When the hero fights the monster, there are two possible outcomes:\n\n if the monster's power is strictly greater than the hero's power, the hero retreats from the dungeon. The current day ends; otherwise, the monster is defeated. \n\nAfter defeating a monster, the hero either continues fighting with the next monster or leaves the dungeon. He leaves the dungeon either if he has already defeated the number of monsters equal to his endurance during this day (so, the $i$-th hero cannot defeat more than $s_i$ monsters during each day), or if all monsters are defeated \u2014 otherwise, he fights with the next monster. When the hero leaves the dungeon, the current day ends.\n\nYour goal is to defeat the last monster. What is the minimum number of days that you need to achieve your goal? Each day you have to use exactly one hero; it is possible that some heroes don't fight the monsters at all. Each hero can be used arbitrary number of times.\n\n\n-----Input-----\n\nThe first line contains one integer $t$ ($1 \\le t \\le 10^5$) \u2014 the number of test cases. Then the test cases follow.\n\nThe first line of each test case contains one integer $n$ ($1 \\le n \\le 2 \\cdot 10^5$) \u2014 the number of monsters in the dungeon.\n\nThe second line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ ($1 \\le a_i \\le 10^9$), where $a_i$ is the power of the $i$-th monster.\n\nThe third line contains one integer $m$ ($1 \\le m \\le 2 \\cdot 10^5$) \u2014 the number of heroes in your party.\n\nThen $m$ lines follow, each describing a hero. Each line contains two integers $p_i$ and $s_i$ ($1 \\le p_i \\le 10^9$, $1 \\le s_i \\le n$) \u2014 the power and the endurance of the $i$-th hero.\n\nIt is guaranteed that the sum of $n + m$ over all test cases does not exceed $2 \\cdot 10^5$.\n\n\n-----Output-----\n\nFor each test case print one integer \u2014 the minimum number of days you have to spend to defeat all of the monsters (or $-1$ if it is impossible).\n\n\n-----Example-----\nInput\n2\n6\n2 3 11 14 1 8\n2\n3 2\n100 1\n5\n3 5 100 2 3\n2\n30 5\n90 1\n\nOutput\n5\n-1\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nimport sys\ninput = sys.stdin.readline\nimport bisect\n\nt=int(input())\n\nfor testcases in range(t):\n n=int(input())\n A=list(map(int,input().split()))\n m=int(input())\n PS=[tuple(map(int,input().split())) for i in range(m)]\n\n PS.sort()\n K=[PS[-1]]\n\n for a,b in PS[::-1][1:]:\n if b<=K[-1][1]:\n continue\n else:\n K.append((a,b))\n\n K.reverse()\n\n ANS=1\n count=0\n countmax=n+1\n LEN=len(K)\n for a in A:\n x=bisect.bisect_left(K,(a,0))\n if x==LEN:\n print(-1)\n break\n elif K[x][1]>=count+1 and countmax>=count+1:\n count+=1\n countmax=min(countmax,K[x][1])\n else:\n ANS+=1\n count=1\n countmax=K[x][1]\n\n #print(a,count,countmax,ANS)\n else:\n print(ANS)\n \n \n \n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n6\\n2 3 11 14 1 8\\n2\\n3 2\\n100 1\\n5\\n3 5 100 2 3\\n2\\n30 5\\n90 1\\n', 'output': '5\\n-1\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/1257/D'}","problem_id":"vfc_456","program":"```python\nimport sys\ninput = sys.stdin.readline\nimport bisect\n\nt=int(input())\n\nfor testcases in range(t):\n n=int(input())\n A=list(map(int,input().split()))\n m=int(input())\n PS=[tuple(map(int,input().split())) for i in range(m)]\n\n PS.sort()\n K=[PS[-1]]\n\n for a,b in PS[::-1][1:]:\n if b<=K[-1][1]:\n continue\n else:\n K.append((a,b))\n\n K.reverse()\n\n ANS=1\n count=0\n countmax=n+1\n LEN=len(K)\n for a in A:\n x=bisect.bisect_left(K,(a,0))\n if x==LEN:\n print(-1)\n break\n elif K[x][1]>=count+1 and countmax>=count+1:\n count+=1\n countmax=min(countmax,K[x][1])\n else:\n ANS+=1\n count=1\n countmax=K[x][1]\n\n #print(a,count,countmax,ANS)\n else:\n print(ANS)\n \n \n \n\n```","inputs":"2\n6\n2 3 11 14 1 8\n2\n3 2\n100 1\n5\n3 5 100 2 3\n2\n30 5\n90 1\n","output":"5\n-1\n","actual_output":"5\n-1\n","execution_success":true,"sample_index":115},{"source":"apps","task_type":"verifiable_code","in_source_id":"115","prompt":"Solve the following coding problem using the programming language python:\n\nPolycarp plays a computer game (yet again). In this game, he fights monsters using magic spells.\n\nThere are two types of spells: fire spell of power $x$ deals $x$ damage to the monster, and lightning spell of power $y$ deals $y$ damage to the monster and doubles the damage of the next spell Polycarp casts. Each spell can be cast only once per battle, but Polycarp can cast them in any order.\n\nFor example, suppose that Polycarp knows three spells: a fire spell of power $5$, a lightning spell of power $1$, and a lightning spell of power $8$. There are $6$ ways to choose the order in which he casts the spells:\n\n first, second, third. This order deals $5 + 1 + 2 \\cdot 8 = 22$ damage; first, third, second. This order deals $5 + 8 + 2 \\cdot 1 = 15$ damage; second, first, third. This order deals $1 + 2 \\cdot 5 + 8 = 19$ damage; second, third, first. This order deals $1 + 2 \\cdot 8 + 2 \\cdot 5 = 27$ damage; third, first, second. This order deals $8 + 2 \\cdot 5 + 1 = 19$ damage; third, second, first. This order deals $8 + 2 \\cdot 1 + 2 \\cdot 5 = 20$ damage. \n\nInitially, Polycarp knows $0$ spells. His spell set changes $n$ times, each time he either learns a new spell or forgets an already known one. After each change, calculate the maximum possible damage Polycarp may deal using the spells he knows.\n\n\n-----Input-----\n\nThe first line contains one integer $n$ ($1 \\le n \\le 2 \\cdot 10^5$)\u00a0\u2014 the number of changes to the spell set.\n\nEach of the next $n$ lines contains two integers $tp$ and $d$ ($0 \\le tp_i \\le 1$; $-10^9 \\le d \\le 10^9$; $d_i \\neq 0$) \u2014 the description of the change. If $tp_i$ if equal to $0$, then Polycarp learns (or forgets) a fire spell, otherwise he learns (or forgets) a lightning spell.\n\nIf $d_i > 0$, then Polycarp learns a spell of power $d_i$. Otherwise, Polycarp forgets a spell with power $-d_i$, and it is guaranteed that he knew that spell before the change.\n\nIt is guaranteed that the powers of all spells Polycarp knows after each change are different (Polycarp never knows two spells with the same power).\n\n\n-----Output-----\n\nAfter each change, print the maximum damage Polycarp can deal with his current set of spells.\n\n\n-----Example-----\nInput\n6\n1 5\n0 10\n1 -5\n0 5\n1 11\n0 -10\n\nOutput\n5\n25\n10\n15\n36\n21\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nclass BIT():\n def __init__(self,n):\n self.BIT=[0]*(n+1)\n self.num=n\n\n def query(self,idx):\n res_sum = 0\n while idx > 0:\n res_sum += self.BIT[idx]\n idx -= idx&(-idx)\n return res_sum\n\n #Ai += x O(logN)\n def update(self,idx,x):\n while idx <= self.num:\n self.BIT[idx] += x\n idx += idx&(-idx)\n return\n\nimport sys,heapq,random\n\ninput=sys.stdin.readline\n\nn=int(input())\nspell=[tuple(map(int,input().split())) for i in range(n)]\n\n\nS=set([])\nfor i in range(n):\n S.add(abs(spell[i][1]))\nS=list(S)\nS.sort(reverse=True)\ncomp={i:e+1 for e,i in enumerate(S)}\nN=len(S)\n\nx_exist=BIT(N)\ny_exist=BIT(N)\npower=BIT(N)\n\nX,Y,S=0,0,0\nXmax=[]\nYmin=[]\nx_data=[0]*(N+1)\ny_data=[0]*(N+1)\n\nfor i in range(n):\n t,d=spell[i]\n S+=d\n if d<0:\n id=comp[-d]\n if t==0:\n X-=1\n x_exist.update(id,-1)\n power.update(id,d)\n x_data[id]-=1\n else:\n Y-=1\n y_exist.update(id,-1)\n power.update(id,d)\n y_data[id]-=1\n else:\n id=comp[d]\n if t==0:\n X+=1\n x_exist.update(id,1)\n power.update(id,d)\n heapq.heappush(Xmax,-d)\n x_data[id]+=1\n else:\n Y+=1\n y_exist.update(id,1)\n power.update(id,d)\n heapq.heappush(Ymin,d)\n y_data[id]+=1\n if X==0:\n if Y==0:\n print(0)\n else:\n while not y_data[comp[Ymin[0]]]:\n heapq.heappop(Ymin)\n print(2*S-Ymin[0])\n else:\n if Y==0:\n print(S)\n else:\n start=0\n end=N\n while end-start>1:\n test=(end+start)//2\n if x_exist.query(test)+y_exist.query(test)<=Y:\n start=test\n else:\n end=test\n if y_exist.query(start)!=Y:\n print(S+power.query(start))\n else:\n while not y_data[comp[Ymin[0]]]:\n heapq.heappop(Ymin)\n while not x_data[comp[-Xmax[0]]]:\n heapq.heappop(Xmax)\n print(S+power.query(start)-Ymin[0]-Xmax[0])\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '6\\n1 5\\n0 10\\n1 -5\\n0 5\\n1 11\\n0 -10\\n', 'output': '5\\n25\\n10\\n15\\n36\\n21\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/1398/E'}","problem_id":"vfc_460","program":"```python\nclass BIT():\n def __init__(self,n):\n self.BIT=[0]*(n+1)\n self.num=n\n\n def query(self,idx):\n res_sum = 0\n while idx > 0:\n res_sum += self.BIT[idx]\n idx -= idx&(-idx)\n return res_sum\n\n #Ai += x O(logN)\n def update(self,idx,x):\n while idx <= self.num:\n self.BIT[idx] += x\n idx += idx&(-idx)\n return\n\nimport sys,heapq,random\n\ninput=sys.stdin.readline\n\nn=int(input())\nspell=[tuple(map(int,input().split())) for i in range(n)]\n\n\nS=set([])\nfor i in range(n):\n S.add(abs(spell[i][1]))\nS=list(S)\nS.sort(reverse=True)\ncomp={i:e+1 for e,i in enumerate(S)}\nN=len(S)\n\nx_exist=BIT(N)\ny_exist=BIT(N)\npower=BIT(N)\n\nX,Y,S=0,0,0\nXmax=[]\nYmin=[]\nx_data=[0]*(N+1)\ny_data=[0]*(N+1)\n\nfor i in range(n):\n t,d=spell[i]\n S+=d\n if d<0:\n id=comp[-d]\n if t==0:\n X-=1\n x_exist.update(id,-1)\n power.update(id,d)\n x_data[id]-=1\n else:\n Y-=1\n y_exist.update(id,-1)\n power.update(id,d)\n y_data[id]-=1\n else:\n id=comp[d]\n if t==0:\n X+=1\n x_exist.update(id,1)\n power.update(id,d)\n heapq.heappush(Xmax,-d)\n x_data[id]+=1\n else:\n Y+=1\n y_exist.update(id,1)\n power.update(id,d)\n heapq.heappush(Ymin,d)\n y_data[id]+=1\n if X==0:\n if Y==0:\n print(0)\n else:\n while not y_data[comp[Ymin[0]]]:\n heapq.heappop(Ymin)\n print(2*S-Ymin[0])\n else:\n if Y==0:\n print(S)\n else:\n start=0\n end=N\n while end-start>1:\n test=(end+start)//2\n if x_exist.query(test)+y_exist.query(test)<=Y:\n start=test\n else:\n end=test\n if y_exist.query(start)!=Y:\n print(S+power.query(start))\n else:\n while not y_data[comp[Ymin[0]]]:\n heapq.heappop(Ymin)\n while not x_data[comp[-Xmax[0]]]:\n heapq.heappop(Xmax)\n print(S+power.query(start)-Ymin[0]-Xmax[0])\n\n```","inputs":"6\n1 5\n0 10\n1 -5\n0 5\n1 11\n0 -10\n","output":"5\n25\n10\n15\n36\n21\n","actual_output":"5\n25\n10\n15\n36\n21\n","execution_success":true,"sample_index":116},{"source":"apps","task_type":"verifiable_code","in_source_id":"118","prompt":"Solve the following coding problem using the programming language python:\n\nThere are $n$ programmers that you want to split into several non-empty teams. The skill of the $i$-th programmer is $a_i$. You want to assemble the maximum number of teams from them. There is a restriction for each team: the number of programmers in the team multiplied by the minimum skill among all programmers in the team must be at least $x$.\n\nEach programmer should belong to at most one team. Some programmers may be left without a team.\n\nCalculate the maximum number of teams that you can assemble.\n\n\n-----Input-----\n\nThe first line contains the integer $t$ ($1 \\le t \\le 1000$)\u00a0\u2014 the number of test cases.\n\nThe first line of each test case contains two integers $n$ and $x$ ($1 \\le n \\le 10^5; 1 \\le x \\le 10^9$)\u00a0\u2014 the number of programmers and the restriction of team skill respectively.\n\nThe second line of each test case contains $n$ integers $a_1, a_2, \\dots , a_n$ ($1 \\le a_i \\le 10^9$), where $a_i$ is the skill of the $i$-th programmer.\n\nThe sum of $n$ over all inputs does not exceed $10^5$.\n\n\n-----Output-----\n\nFor each test case print one integer \u2014 the maximum number of teams that you can assemble. \n\n\n-----Example-----\nInput\n3\n5 10\n7 11 2 9 5\n4 8\n2 4 2 3\n4 11\n1 3 3 7\n\nOutput\n2\n1\n0\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n__MULTITEST = True\n\n## solve\ndef solve():\n n, x = map(int, input().split())\n a = list(map(int, input().split()))\n a.sort()\n\n group = 0\n ptr = n-1\n members = 0\n\n currentMin = int(1e10)\n while ptr > -1:\n currentMin = min(currentMin, a[ptr])\n members += 1\n\n if currentMin * members >= x:\n group += 1\n members = 0\n currentMin = int(1e10)\n \n ptr -= 1\n \n print(group)\n\n## main\ndef __starting_point():\n t = (int(input()) if __MULTITEST else 1)\n for tt in range(t):\n solve();\n__starting_point()\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\n5 10\\n7 11 2 9 5\\n4 8\\n2 4 2 3\\n4 11\\n1 3 3 7\\n', 'output': '2\\n1\\n0\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/1380/C'}","problem_id":"vfc_472","program":"```python\n__MULTITEST = True\n\n## solve\ndef solve():\n n, x = map(int, input().split())\n a = list(map(int, input().split()))\n a.sort()\n\n group = 0\n ptr = n-1\n members = 0\n\n currentMin = int(1e10)\n while ptr > -1:\n currentMin = min(currentMin, a[ptr])\n members += 1\n\n if currentMin * members >= x:\n group += 1\n members = 0\n currentMin = int(1e10)\n \n ptr -= 1\n \n print(group)\n\n## main\ndef __starting_point():\n t = (int(input()) if __MULTITEST else 1)\n for tt in range(t):\n solve();\n__starting_point()\n```","inputs":"3\n5 10\n7 11 2 9 5\n4 8\n2 4 2 3\n4 11\n1 3 3 7\n","output":"2\n1\n0\n","actual_output":"2\n1\n0\n","execution_success":true,"sample_index":119},{"source":"apps","task_type":"verifiable_code","in_source_id":"119","prompt":"Solve the following coding problem using the programming language python:\n\nAssume that you have $k$ one-dimensional segments $s_1, s_2, \\dots s_k$ (each segment is denoted by two integers \u2014 its endpoints). Then you can build the following graph on these segments. The graph consists of $k$ vertexes, and there is an edge between the $i$-th and the $j$-th vertexes ($i \\neq j$) if and only if the segments $s_i$ and $s_j$ intersect (there exists at least one point that belongs to both of them).\n\nFor example, if $s_1 = [1, 6], s_2 = [8, 20], s_3 = [4, 10], s_4 = [2, 13], s_5 = [17, 18]$, then the resulting graph is the following: [Image] \n\nA tree of size $m$ is good if it is possible to choose $m$ one-dimensional segments so that the graph built on these segments coincides with this tree.\n\nYou are given a tree, you have to find its good subtree with maximum possible size. Recall that a subtree is a connected subgraph of a tree.\n\nNote that you have to answer $q$ independent queries.\n\n\n-----Input-----\n\nThe first line contains one integer $q$ ($1 \\le q \\le 15 \\cdot 10^4$) \u2014 the number of the queries. \n\nThe first line of each query contains one integer $n$ ($2 \\le n \\le 3 \\cdot 10^5$) \u2014 the number of vertices in the tree.\n\nEach of the next $n - 1$ lines contains two integers $x$ and $y$ ($1 \\le x, y \\le n$) denoting an edge between vertices $x$ and $y$. It is guaranteed that the given graph is a tree.\n\nIt is guaranteed that the sum of all $n$ does not exceed $3 \\cdot 10^5$.\n\n\n-----Output-----\n\nFor each query print one integer \u2014 the maximum size of a good subtree of the given tree.\n\n\n-----Example-----\nInput\n1\n10\n1 2\n1 3\n1 4\n2 5\n2 6\n3 7\n3 8\n4 9\n4 10\n\nOutput\n8\n\n\n\n-----Note-----\n\nIn the first query there is a good subtree of size $8$. The vertices belonging to this subtree are ${9, 4, 10, 2, 5, 1, 6, 3}$.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nimport sys\ninput = sys.stdin.readline\nt = int(input())\nfor _ in range(t):\n n = int(input())\n ab = [list(map(int,input().split())) for i in range(n-1)]\n graph = [[] for i in range(n+1)]\n deg = [0]*(n+1)\n for a,b in ab:\n graph[a].append(b)\n graph[b].append(a)\n deg[a] += 1\n deg[b] += 1\n pnt = [max(deg[i]-1,1) for i in range(n+1)]\n root = 1\n stack = [root]\n dist = [0]*(n+1)\n dist[root] = pnt[root]\n while stack:\n x = stack.pop()\n for y in graph[x]:\n if dist[y] == 0:\n dist[y] = dist[x]+pnt[y]\n stack.append(y)\n far = dist.index(max(dist))\n root = far\n stack = [root]\n dist = [0]*(n+1)\n dist[root] = pnt[root]\n while stack:\n x = stack.pop()\n for y in graph[x]:\n if dist[y] == 0:\n dist[y] = dist[x]+pnt[y]\n stack.append(y)\n print(max(dist))\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n10\\n1 2\\n1 3\\n1 4\\n2 5\\n2 6\\n3 7\\n3 8\\n4 9\\n4 10\\n', 'output': '8\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/1238/F'}","problem_id":"vfc_476","program":"```python\nimport sys\ninput = sys.stdin.readline\nt = int(input())\nfor _ in range(t):\n n = int(input())\n ab = [list(map(int,input().split())) for i in range(n-1)]\n graph = [[] for i in range(n+1)]\n deg = [0]*(n+1)\n for a,b in ab:\n graph[a].append(b)\n graph[b].append(a)\n deg[a] += 1\n deg[b] += 1\n pnt = [max(deg[i]-1,1) for i in range(n+1)]\n root = 1\n stack = [root]\n dist = [0]*(n+1)\n dist[root] = pnt[root]\n while stack:\n x = stack.pop()\n for y in graph[x]:\n if dist[y] == 0:\n dist[y] = dist[x]+pnt[y]\n stack.append(y)\n far = dist.index(max(dist))\n root = far\n stack = [root]\n dist = [0]*(n+1)\n dist[root] = pnt[root]\n while stack:\n x = stack.pop()\n for y in graph[x]:\n if dist[y] == 0:\n dist[y] = dist[x]+pnt[y]\n stack.append(y)\n print(max(dist))\n```","inputs":"1\n10\n1 2\n1 3\n1 4\n2 5\n2 6\n3 7\n3 8\n4 9\n4 10\n","output":"8\n","actual_output":"8\n","execution_success":true,"sample_index":120},{"source":"apps","task_type":"verifiable_code","in_source_id":"120","prompt":"Solve the following coding problem using the programming language python:\n\nAyoub thinks that he is a very smart person, so he created a function $f(s)$, where $s$ is a binary string (a string which contains only symbols \"0\" and \"1\"). The function $f(s)$ is equal to the number of substrings in the string $s$ that contains at least one symbol, that is equal to \"1\".\n\nMore formally, $f(s)$ is equal to the number of pairs of integers $(l, r)$, such that $1 \\leq l \\leq r \\leq |s|$ (where $|s|$ is equal to the length of string $s$), such that at least one of the symbols $s_l, s_{l+1}, \\ldots, s_r$ is equal to \"1\". \n\nFor example, if $s = $\"01010\" then $f(s) = 12$, because there are $12$ such pairs $(l, r)$: $(1, 2), (1, 3), (1, 4), (1, 5), (2, 2), (2, 3), (2, 4), (2, 5), (3, 4), (3, 5), (4, 4), (4, 5)$.\n\nAyoub also thinks that he is smarter than Mahmoud so he gave him two integers $n$ and $m$ and asked him this problem. For all binary strings $s$ of length $n$ which contains exactly $m$ symbols equal to \"1\", find the maximum value of $f(s)$.\n\nMahmoud couldn't solve the problem so he asked you for help. Can you help him? \n\n\n-----Input-----\n\nThe input consists of multiple test cases. The first line contains a single integer $t$ ($1 \\leq t \\leq 10^5$) \u00a0\u2014 the number of test cases. The description of the test cases follows.\n\nThe only line for each test case contains two integers $n$, $m$ ($1 \\leq n \\leq 10^{9}$, $0 \\leq m \\leq n$)\u00a0\u2014 the length of the string and the number of symbols equal to \"1\" in it.\n\n\n-----Output-----\n\nFor every test case print one integer number\u00a0\u2014 the maximum value of $f(s)$ over all strings $s$ of length $n$, which has exactly $m$ symbols, equal to \"1\".\n\n\n-----Example-----\nInput\n5\n3 1\n3 2\n3 3\n4 0\n5 2\n\nOutput\n4\n5\n6\n0\n12\n\n\n\n-----Note-----\n\nIn the first test case, there exists only $3$ strings of length $3$, which has exactly $1$ symbol, equal to \"1\". These strings are: $s_1 = $\"100\", $s_2 = $\"010\", $s_3 = $\"001\". The values of $f$ for them are: $f(s_1) = 3, f(s_2) = 4, f(s_3) = 3$, so the maximum value is $4$ and the answer is $4$.\n\nIn the second test case, the string $s$ with the maximum value is \"101\".\n\nIn the third test case, the string $s$ with the maximum value is \"111\".\n\nIn the fourth test case, the only string $s$ of length $4$, which has exactly $0$ symbols, equal to \"1\" is \"0000\" and the value of $f$ for that string is $0$, so the answer is $0$.\n\nIn the fifth test case, the string $s$ with the maximum value is \"01010\" and it is described as an example in the problem statement.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nimport sys\ninput = sys.stdin.readline\n\nt=int(input())\n\ndef calc(x):\n return x*(x+1)//2\n\nfor test in range(t):\n n,m=list(map(int,input().split()))\n\n ANS=calc(n)\n\n k=n-m\n q,mod=divmod(k,m+1)\n\n ANS-=calc(q+1)*mod+calc(q)*(m+1-mod)\n\n print(ANS)\n \n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '5\\n3 1\\n3 2\\n3 3\\n4 0\\n5 2\\n', 'output': '4\\n5\\n6\\n0\\n12\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/1301/C'}","problem_id":"vfc_480","program":"```python\nimport sys\ninput = sys.stdin.readline\n\nt=int(input())\n\ndef calc(x):\n return x*(x+1)//2\n\nfor test in range(t):\n n,m=list(map(int,input().split()))\n\n ANS=calc(n)\n\n k=n-m\n q,mod=divmod(k,m+1)\n\n ANS-=calc(q+1)*mod+calc(q)*(m+1-mod)\n\n print(ANS)\n \n\n```","inputs":"5\n3 1\n3 2\n3 3\n4 0\n5 2\n","output":"4\n5\n6\n0\n12\n","actual_output":"4\n5\n6\n0\n12\n","execution_success":true,"sample_index":121},{"source":"apps","task_type":"verifiable_code","in_source_id":"121","prompt":"Solve the following coding problem using the programming language python:\n\nReminder: the median of the array $[a_1, a_2, \\dots, a_{2k+1}]$ of odd number of elements is defined as follows: let $[b_1, b_2, \\dots, b_{2k+1}]$ be the elements of the array in the sorted order. Then median of this array is equal to $b_{k+1}$.\n\nThere are $2n$ students, the $i$-th student has skill level $a_i$. It's not guaranteed that all skill levels are distinct.\n\nLet's define skill level of a class as the median of skill levels of students of the class.\n\nAs a principal of the school, you would like to assign each student to one of the $2$ classes such that each class has odd number of students (not divisible by $2$). The number of students in the classes may be equal or different, by your choice. Every student has to be assigned to exactly one class. Among such partitions, you want to choose one in which the absolute difference between skill levels of the classes is minimized.\n\nWhat is the minimum possible absolute difference you can achieve?\n\n\n-----Input-----\n\nEach test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \\le t \\le 10^4$). The description of the test cases follows.\n\nThe first line of each test case contains a single integer $n$ ($1 \\le n \\le 10^5$)\u00a0\u2014 the number of students halved.\n\nThe second line of each test case contains $2n$ integers $a_1, a_2, \\dots, a_{2 n}$ ($1 \\le a_i \\le 10^9$)\u00a0\u2014 skill levels of students.\n\nIt is guaranteed that the sum of $n$ over all test cases does not exceed $10^5$.\n\n\n-----Output-----\n\nFor each test case, output a single integer, the minimum possible absolute difference between skill levels of two classes of odd sizes.\n\n\n-----Example-----\nInput\n3\n1\n1 1\n3\n6 5 4 1 2 3\n5\n13 4 20 13 2 5 8 3 17 16\n\nOutput\n0\n1\n5\n\n\n\n-----Note-----\n\nIn the first test, there is only one way to partition students\u00a0\u2014 one in each class. The absolute difference of the skill levels will be $|1 - 1| = 0$.\n\nIn the second test, one of the possible partitions is to make the first class of students with skill levels $[6, 4, 2]$, so that the skill level of the first class will be $4$, and second with $[5, 1, 3]$, so that the skill level of the second class will be $3$. Absolute difference will be $|4 - 3| = 1$.\n\nNote that you can't assign like $[2, 3]$, $[6, 5, 4, 1]$ or $[]$, $[6, 5, 4, 1, 2, 3]$ because classes have even number of students.\n\n$[2]$, $[1, 3, 4]$ is also not possible because students with skills $5$ and $6$ aren't assigned to a class.\n\nIn the third test you can assign the students in the following way: $[3, 4, 13, 13, 20], [2, 5, 8, 16, 17]$ or $[3, 8, 17], [2, 4, 5, 13, 13, 16, 20]$. Both divisions give minimal possible absolute difference.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfor _ in range(int(input())):\n n = int(input())\n ar = list(map(int, input().split()))\n ar.sort()\n print(abs(ar[n] - ar[n - 1]))\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\n1\\n1 1\\n3\\n6 5 4 1 2 3\\n5\\n13 4 20 13 2 5 8 3 17 16\\n', 'output': '0\\n1\\n5\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/1300/B'}","problem_id":"vfc_484","program":"```python\nfor _ in range(int(input())):\n n = int(input())\n ar = list(map(int, input().split()))\n ar.sort()\n print(abs(ar[n] - ar[n - 1]))\n```","inputs":"3\n1\n1 1\n3\n6 5 4 1 2 3\n5\n13 4 20 13 2 5 8 3 17 16\n","output":"0\n1\n5\n","actual_output":"0\n1\n5\n","execution_success":true,"sample_index":122},{"source":"apps","task_type":"verifiable_code","in_source_id":"508","prompt":"Solve the following coding problem using the programming language python:\n\nThere is an infinitely long street that runs west to east, which we consider as a number line.\nThere are N roadworks scheduled on this street.\nThe i-th roadwork blocks the point at coordinate X_i from time S_i - 0.5 to time T_i - 0.5.\nQ people are standing at coordinate 0. The i-th person will start the coordinate 0 at time D_i, continue to walk with speed 1 in the positive direction and stop walking when reaching a blocked point.\nFind the distance each of the Q people will walk.\n\n-----Constraints-----\n - All values in input are integers.\n - 1 \\leq N, Q \\leq 2 \\times 10^5\n - 0 \\leq S_i < T_i \\leq 10^9\n - 1 \\leq X_i \\leq 10^9\n - 0 \\leq D_1 < D_2 < ... < D_Q \\leq 10^9\n - If i \\neq j and X_i = X_j, the intervals [S_i, T_i) and [S_j, T_j) do not overlap.\n\n-----Input-----\nInput is given from Standard Input in the following format:\nN Q\nS_1 T_1 X_1\n:\nS_N T_N X_N\nD_1\n:\nD_Q\n\n-----Output-----\nPrint Q lines. The i-th line should contain the distance the i-th person will walk or -1 if that person walks forever.\n\n-----Sample Input-----\n4 6\n1 3 2\n7 13 10\n18 20 13\n3 4 2\n0\n1\n2\n3\n5\n8\n\n-----Sample Output-----\n2\n2\n10\n-1\n13\n-1\n\nThe first person starts coordinate 0 at time 0 and stops walking at coordinate 2 when reaching a point blocked by the first roadwork at time 2.\nThe second person starts coordinate 0 at time 1 and reaches coordinate 2 at time 3. The first roadwork has ended, but the fourth roadwork has begun, so this person also stops walking at coordinate 2.\nThe fourth and sixth persons encounter no roadworks while walking, so they walk forever. The output for these cases is -1.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfrom heapq import heapify, heappush, heappop\nimport sys\ninput = sys.stdin.readline\n\ndef solve():\n N, Q = list(map(int, input().split()))\n events = []\n for i in range(N):\n S, T, X = list(map(int, input().split()))\n events.append((S-X-0.5, 1, X))\n events.append((T-X-0.5, 0, X))\n for i in range(Q):\n D = int(input())\n events.append((D, 2, i))\n\n events.sort()\n\n anss = [-1] * Q\n PQ = []\n isClosed = dict()\n for tm, tp, x in events:\n if tp == 0:\n isClosed[x] = 0\n elif tp == 1:\n isClosed[x] = 1\n heappush(PQ, x)\n else:\n while PQ:\n if isClosed[PQ[0]] == 1:\n anss[x] = PQ[0]\n break\n heappop(PQ)\n\n print(('\\n'.join(map(str, anss))))\n\n\nsolve()\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '4 6\\n1 3 2\\n7 13 10\\n18 20 13\\n3 4 2\\n0\\n1\\n2\\n3\\n5\\n8\\n', 'output': '2\\n2\\n10\\n-1\\n13\\n-1\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://atcoder.jp/contests/abc128/tasks/abc128_e'}","problem_id":"vfc_874","program":"```python\nfrom heapq import heapify, heappush, heappop\nimport sys\ninput = sys.stdin.readline\n\ndef solve():\n N, Q = list(map(int, input().split()))\n events = []\n for i in range(N):\n S, T, X = list(map(int, input().split()))\n events.append((S-X-0.5, 1, X))\n events.append((T-X-0.5, 0, X))\n for i in range(Q):\n D = int(input())\n events.append((D, 2, i))\n\n events.sort()\n\n anss = [-1] * Q\n PQ = []\n isClosed = dict()\n for tm, tp, x in events:\n if tp == 0:\n isClosed[x] = 0\n elif tp == 1:\n isClosed[x] = 1\n heappush(PQ, x)\n else:\n while PQ:\n if isClosed[PQ[0]] == 1:\n anss[x] = PQ[0]\n break\n heappop(PQ)\n\n print(('\\n'.join(map(str, anss))))\n\n\nsolve()\n\n```","inputs":"4 6\n1 3 2\n7 13 10\n18 20 13\n3 4 2\n0\n1\n2\n3\n5\n8\n","output":"2\n2\n10\n-1\n13\n-1\n","actual_output":"2\n2\n10\n-1\n13\n-1\n","execution_success":true,"sample_index":123},{"source":"apps","task_type":"verifiable_code","in_source_id":"510","prompt":"Solve the following coding problem using the programming language python:\n\nYou are given a string S of length N consisting of lowercase English letters.\nProcess Q queries of the following two types:\n - Type 1: change the i_q-th character of S to c_q. (Do nothing if the i_q-th character is already c_q.)\n - Type 2: answer the number of different characters occurring in the substring of S between the l_q-th and r_q-th characters (inclusive).\n\n-----Constraints-----\n - N, Q, i_q, l_q, and r_q are integers.\n - S is a string consisting of lowercase English letters.\n - c_q is a lowercase English letter.\n - 1 \\leq N \\leq 500000\n - 1 \\leq Q \\leq 20000\n - |S| = N\n - 1 \\leq i_q \\leq N\n - 1 \\leq l_q \\leq r_q \\leq N\n - There is at least one query of type 2 in each testcase.\n\n-----Input-----\nInput is given from Standard Input in the following format:\nN\nS\nQ\nQuery_1\n\\vdots\nQuery_Q\n\nHere, Query_i in the 4-th through (Q+3)-th lines is one of the following:\n1 i_q c_q\n\n2 l_q r_q\n\n-----Output-----\nFor each query of type 2, print a line containing the answer.\n\n-----Sample Input-----\n7\nabcdbbd\n6\n2 3 6\n1 5 z\n2 1 1\n1 4 a\n1 7 d\n2 1 7\n\n-----Sample Output-----\n3\n1\n5\n\nIn the first query, cdbb contains three kinds of letters: b , c , and d, so we print 3.\nIn the second query, S is modified to abcdzbd.\nIn the third query, a contains one kind of letter: a, so we print 1.\nIn the fourth query, S is modified to abcazbd.\nIn the fifth query, S does not change and is still abcazbd.\nIn the sixth query, abcazbd contains five kinds of letters: a, b, c, d, and z, so we print 5.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nn = int(input())\ns = list(input())\ns = [ord(i)-97 for i in s]\n\ndic = {}\nfor i in range(26):\n dic[i] = []\n\nfor i in range(n):\n dic[s[i]].append(i)\n\nfor i in range(26):\n dic[i].append(float('inf'))\n\nfrom bisect import bisect_left\nq = int(input())\nfor i in range(q):\n x, y, z = input().split()\n if x == '1':\n y, z = int(y) - 1, ord(z) - 97\n p = bisect_left(dic[s[y]], y)\n dic[s[y]].pop(p)\n dic[z].insert(bisect_left(dic[z], y), y)\n s[y] = z\n else:\n res = 0\n y, z = int(y) - 1, int(z) - 1\n for i in range(26):\n p = dic[i][bisect_left(dic[i], y)]\n if p <= z:\n res += 1\n print(res)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '7\\nabcdbbd\\n6\\n2 3 6\\n1 5 z\\n2 1 1\\n1 4 a\\n1 7 d\\n2 1 7\\n', 'output': '3\\n1\\n5\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://atcoder.jp/contests/abc157/tasks/abc157_e'}","problem_id":"vfc_882","program":"```python\nn = int(input())\ns = list(input())\ns = [ord(i)-97 for i in s]\n\ndic = {}\nfor i in range(26):\n dic[i] = []\n\nfor i in range(n):\n dic[s[i]].append(i)\n\nfor i in range(26):\n dic[i].append(float('inf'))\n\nfrom bisect import bisect_left\nq = int(input())\nfor i in range(q):\n x, y, z = input().split()\n if x == '1':\n y, z = int(y) - 1, ord(z) - 97\n p = bisect_left(dic[s[y]], y)\n dic[s[y]].pop(p)\n dic[z].insert(bisect_left(dic[z], y), y)\n s[y] = z\n else:\n res = 0\n y, z = int(y) - 1, int(z) - 1\n for i in range(26):\n p = dic[i][bisect_left(dic[i], y)]\n if p <= z:\n res += 1\n print(res)\n```","inputs":"7\nabcdbbd\n6\n2 3 6\n1 5 z\n2 1 1\n1 4 a\n1 7 d\n2 1 7\n","output":"3\n1\n5\n","actual_output":"3\n1\n5\n","execution_success":true,"sample_index":124},{"source":"apps","task_type":"verifiable_code","in_source_id":"511","prompt":"Solve the following coding problem using the programming language python:\n\nThere are N Snuke Cats numbered 1, 2, \\ldots, N, where N is even.\nEach Snuke Cat wears a red scarf, on which his favorite non-negative integer is written.\nRecently, they learned the operation called xor (exclusive OR).What is xor?\n\nFor n non-negative integers x_1, x_2, \\ldots, x_n, their xor, x_1~\\textrm{xor}~x_2~\\textrm{xor}~\\ldots~\\textrm{xor}~x_n is defined as follows:\n\n - When x_1~\\textrm{xor}~x_2~\\textrm{xor}~\\ldots~\\textrm{xor}~x_n is written in base two, the digit in the 2^k's place (k \\geq 0) is 1 if the number of integers among x_1, x_2, \\ldots, x_n whose binary representations have 1 in the 2^k's place is odd, and 0 if that count is even. \nFor example, 3~\\textrm{xor}~5 = 6.\n\n\nThey wanted to use this operation quickly, so each of them calculated the xor of the integers written on their scarfs except his scarf.\nWe know that the xor calculated by Snuke Cat i, that is, the xor of the integers written on the scarfs except the scarf of Snuke Cat i is a_i.\nUsing this information, restore the integer written on the scarf of each Snuke Cat.\n\n-----Constraints-----\n - All values in input are integers.\n - 2 \\leq N \\leq 200000\n - N is even.\n - 0 \\leq a_i \\leq 10^9\n - There exists a combination of integers on the scarfs that is consistent with the given information.\n\n-----Input-----\nInput is given from Standard Input in the following format:\nN\na_1 a_2 \\ldots a_N\n\n-----Output-----\nPrint a line containing N integers separated with space.\nThe i-th of the integers from the left should represent the integer written on the scarf of Snuke Cat i.\nIf there are multiple possible solutions, you may print any of them.\n\n-----Sample Input-----\n4\n20 11 9 24\n\n-----Sample Output-----\n26 5 7 22\n\n - 5~\\textrm{xor}~7~\\textrm{xor}~22 = 20\n - 26~\\textrm{xor}~7~\\textrm{xor}~22 = 11\n - 26~\\textrm{xor}~5~\\textrm{xor}~22 = 9\n - 26~\\textrm{xor}~5~\\textrm{xor}~7 = 24\nThus, this output is consistent with the given information.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nn=int(input())\na=list(map(int,input().split()))\n\nX=[]\nb=a[0]\nfor i in range(1,n) :\n b^=a[i]\n\nfor i in range(n) :\n x=b^a[i]\n X.append(x)\n\nfor i in X :\n print(i,end=\" \")\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '4\\n20 11 9 24\\n', 'output': '26 5 7 22\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://atcoder.jp/contests/abc171/tasks/abc171_e'}","problem_id":"vfc_886","program":"```python\nn=int(input())\na=list(map(int,input().split()))\n\nX=[]\nb=a[0]\nfor i in range(1,n) :\n b^=a[i]\n\nfor i in range(n) :\n x=b^a[i]\n X.append(x)\n\nfor i in X :\n print(i,end=\" \")\n\n```","inputs":"4\n20 11 9 24\n","output":"26 5 7 22\n","actual_output":"26 5 7 22 ","execution_success":true,"sample_index":125},{"source":"apps","task_type":"verifiable_code","in_source_id":"512","prompt":"Solve the following coding problem using the programming language python:\n\nThere is a tree with N vertices numbered 1 to N.\nThe i-th edge in this tree connects Vertex a_i and Vertex b_i, and the color and length of that edge are c_i and d_i, respectively.\nHere the color of each edge is represented by an integer between 1 and N-1 (inclusive). The same integer corresponds to the same color, and different integers correspond to different colors.\nAnswer the following Q queries:\n - Query j (1 \\leq j \\leq Q): assuming that the length of every edge whose color is x_j is changed to y_j, find the distance between Vertex u_j and Vertex v_j. (The changes of the lengths of edges do not affect the subsequent queries.)\n\n-----Constraints-----\n - 2 \\leq N \\leq 10^5\n - 1 \\leq Q \\leq 10^5\n - 1 \\leq a_i, b_i \\leq N\n - 1 \\leq c_i \\leq N-1\n - 1 \\leq d_i \\leq 10^4\n - 1 \\leq x_j \\leq N-1\n - 1 \\leq y_j \\leq 10^4\n - 1 \\leq u_j < v_j \\leq N\n - The given graph is a tree.\n - All values in input are integers.\n\n-----Input-----\nInput is given from Standard Input in the following format:\nN Q\na_1 b_1 c_1 d_1\n:\na_{N-1} b_{N-1} c_{N-1} d_{N-1}\nx_1 y_1 u_1 v_1\n:\nx_Q y_Q u_Q v_Q\n\n-----Output-----\nPrint Q lines. The j-th line (1 \\leq j \\leq Q) should contain the answer to Query j.\n\n-----Sample Input-----\n5 3\n1 2 1 10\n1 3 2 20\n2 4 4 30\n5 2 1 40\n1 100 1 4\n1 100 1 5\n3 1000 3 4\n\n-----Sample Output-----\n130\n200\n60\n\nThe graph in this input is as follows:\n\nHere the edges of Color 1 are shown as solid red lines, the edge of Color 2 is shown as a bold green line, and the edge of Color 4 is shown as a blue dashed line.\n - Query 1: Assuming that the length of every edge whose color is 1 is changed to 100, the distance between Vertex 1 and Vertex 4 is 100 + 30 = 130.\n - Query 2: Assuming that the length of every edge whose color is 1 is changed to 100, the distance between Vertex 1 and Vertex 5 is 100 + 100 = 200.\n - Query 3: Assuming that the length of every edge whose color is 3 is changed to 1000 (there is no such edge), the distance between Vertex 3 and Vertex 4 is 20 + 10 + 30 = 60. Note that the edges of Color 1 now have their original lengths.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nimport sys\ninput = sys.stdin.readline\nsys.setrecursionlimit(10**5)\n\nN, Q = map(int, input().split())\n\npath = [[] for _ in range(N)]\n\nfor _ in range(N-1) :\n a, b, c, d = (int(i) for i in input().split())\n path[a-1].append((b-1, c-1, d))\n path[b-1].append((a-1, c-1, d))\n\n# doubling\u306b\u5fc5\u8981\u306aK\u3092\u6c42\u3081\u308b\nfor K in range(18) :\n if 2 ** K >= N :\n break\n\n# dfs\nparent = [[-1] * N for _ in range(K)]\nrank = [-1 for _ in range(N)]\n\nrank[0] = 0\nqueue = [0]\n\nwhile queue :\n cur = queue.pop()\n for nex, _, _ in path[cur] :\n if rank[nex] < 0 :\n queue.append(nex)\n parent[0][nex] = cur\n rank[nex] = rank[cur] + 1\n\n# doubling \nfor i in range(1, K) :\n for j in range(N) :\n if parent[i-1][j] > 0 :\n parent[i][j] = parent[i-1][parent[i-1][j]]\n\n# lca\ndef lca(a, b) :\n if rank[a] > rank[b] :\n a, b = b, a\n\n diff = rank[b] - rank[a]\n i = 0\n while diff > 0 :\n if diff & 1 :\n b = parent[i][b]\n diff >>= 1\n i += 1\n \n if a == b :\n return a\n\n for i in range(K-1, -1, -1) :\n if parent[i][a] != parent[i][b] :\n a = parent[i][a]\n b = parent[i][b]\n\n return parent[0][a]\n\n# Query\u306e\u5148\u8aad\u307f\nschedule = [[] for _ in range(N)]\nfor i in range(Q) : \n x, y, u, v = map(int, input().split())\n x, u, v = x-1, u-1, v-1\n l = lca(u, v)\n schedule[u].append((i, 1, x, y))\n schedule[v].append((i, 1, x, y))\n schedule[l].append((i, -2, x, y))\n\nret = [0] * Q\nC = [0] * (N-1)\nD = [0] * (N-1)\n\ndef dfs(cur, pre, tot) :\n for i, t, c, d in schedule[cur] :\n ret[i] += t * (tot - D[c] + C[c] * d)\n \n for nex, c, d in path[cur] :\n if nex == pre :\n continue\n C[c] += 1\n D[c] += d\n dfs(nex, cur, tot + d)\n C[c] -= 1\n D[c] -= d\n\ndfs(0, -1, 0)\n \nfor i in range(Q) :\n print(ret[i])\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '5 3\\n1 2 1 10\\n1 3 2 20\\n2 4 4 30\\n5 2 1 40\\n1 100 1 4\\n1 100 1 5\\n3 1000 3 4\\n', 'output': '130\\n200\\n60\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://atcoder.jp/contests/abc133/tasks/abc133_f'}","problem_id":"vfc_890","program":"```python\nimport sys\ninput = sys.stdin.readline\nsys.setrecursionlimit(10**5)\n\nN, Q = map(int, input().split())\n\npath = [[] for _ in range(N)]\n\nfor _ in range(N-1) :\n a, b, c, d = (int(i) for i in input().split())\n path[a-1].append((b-1, c-1, d))\n path[b-1].append((a-1, c-1, d))\n\n# doubling\u306b\u5fc5\u8981\u306aK\u3092\u6c42\u3081\u308b\nfor K in range(18) :\n if 2 ** K >= N :\n break\n\n# dfs\nparent = [[-1] * N for _ in range(K)]\nrank = [-1 for _ in range(N)]\n\nrank[0] = 0\nqueue = [0]\n\nwhile queue :\n cur = queue.pop()\n for nex, _, _ in path[cur] :\n if rank[nex] < 0 :\n queue.append(nex)\n parent[0][nex] = cur\n rank[nex] = rank[cur] + 1\n\n# doubling \nfor i in range(1, K) :\n for j in range(N) :\n if parent[i-1][j] > 0 :\n parent[i][j] = parent[i-1][parent[i-1][j]]\n\n# lca\ndef lca(a, b) :\n if rank[a] > rank[b] :\n a, b = b, a\n\n diff = rank[b] - rank[a]\n i = 0\n while diff > 0 :\n if diff & 1 :\n b = parent[i][b]\n diff >>= 1\n i += 1\n \n if a == b :\n return a\n\n for i in range(K-1, -1, -1) :\n if parent[i][a] != parent[i][b] :\n a = parent[i][a]\n b = parent[i][b]\n\n return parent[0][a]\n\n# Query\u306e\u5148\u8aad\u307f\nschedule = [[] for _ in range(N)]\nfor i in range(Q) : \n x, y, u, v = map(int, input().split())\n x, u, v = x-1, u-1, v-1\n l = lca(u, v)\n schedule[u].append((i, 1, x, y))\n schedule[v].append((i, 1, x, y))\n schedule[l].append((i, -2, x, y))\n\nret = [0] * Q\nC = [0] * (N-1)\nD = [0] * (N-1)\n\ndef dfs(cur, pre, tot) :\n for i, t, c, d in schedule[cur] :\n ret[i] += t * (tot - D[c] + C[c] * d)\n \n for nex, c, d in path[cur] :\n if nex == pre :\n continue\n C[c] += 1\n D[c] += d\n dfs(nex, cur, tot + d)\n C[c] -= 1\n D[c] -= d\n\ndfs(0, -1, 0)\n \nfor i in range(Q) :\n print(ret[i])\n```","inputs":"5 3\n1 2 1 10\n1 3 2 20\n2 4 4 30\n5 2 1 40\n1 100 1 4\n1 100 1 5\n3 1000 3 4\n","output":"130\n200\n60\n","actual_output":"130\n200\n60\n","execution_success":true,"sample_index":126},{"source":"apps","task_type":"verifiable_code","in_source_id":"513","prompt":"Solve the following coding problem using the programming language python:\n\nWe have a tree with N vertices, whose i-th edge connects Vertex u_i and Vertex v_i.\nVertex i has an integer a_i written on it.\nFor every integer k from 1 through N, solve the following problem:\n - We will make a sequence by lining up the integers written on the vertices along the shortest path from Vertex 1 to Vertex k, in the order they appear. Find the length of the longest increasing subsequence of this sequence.\nHere, the longest increasing subsequence of a sequence A of length L is the subsequence A_{i_1} , A_{i_2} , ... , A_{i_M} with the greatest possible value of M such that 1 \\leq i_1 < i_2 < ... < i_M \\leq L and A_{i_1} < A_{i_2} < ... < A_{i_M}.\n\n-----Constraints-----\n - 2 \\leq N \\leq 2 \\times 10^5\n - 1 \\leq a_i \\leq 10^9\n - 1 \\leq u_i , v_i \\leq N\n - u_i \\neq v_i\n - The given graph is a tree.\n - All values in input are integers.\n\n-----Input-----\nInput is given from Standard Input in the following format:\nN\na_1 a_2 ... a_N\nu_1 v_1\nu_2 v_2\n:\nu_{N-1} v_{N-1}\n\n-----Output-----\nPrint N lines. The k-th line, print the length of the longest increasing subsequence of the sequence obtained from the shortest path from Vertex 1 to Vertex k.\n\n-----Sample Input-----\n10\n1 2 5 3 4 6 7 3 2 4\n1 2\n2 3\n3 4\n4 5\n3 6\n6 7\n1 8\n8 9\n9 10\n\n-----Sample Output-----\n1\n2\n3\n3\n4\n4\n5\n2\n2\n3\n\nFor example, the sequence A obtained from the shortest path from Vertex 1 to Vertex 5 is 1,2,5,3,4. Its longest increasing subsequence is A_1, A_2, A_4, A_5, with the length of 4.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nimport bisect\nimport sys\nsys.setrecursionlimit(10**7)\n\ndef dfs(v):\n pos=bisect.bisect_left(dp,arr[v])\n changes.append((pos,dp[pos]))\n dp[pos]=arr[v]\n ans[v]=bisect.bisect_left(dp,10**18)\n for u in g[v]:\n if checked[u]==0:\n checked[u]=1\n dfs(u)\n pos,val=changes.pop()\n dp[pos]=val\n\n\nn=int(input())\narr=[0]+list(map(int,input().split()))\ng=[[] for _ in range(n+1)]\nfor _ in range(n-1):\n a,b=map(int,input().split())\n g[a].append(b)\n g[b].append(a)\nans=[0]*(n+1)\nchecked=[0]*(n+1)\nchecked[1]=1\ndp=[10**18 for _ in range(n+1)]\nchanges=[]\ndfs(1)\nfor i in range(1,n+1):\n print(ans[i])\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '10\\n1 2 5 3 4 6 7 3 2 4\\n1 2\\n2 3\\n3 4\\n4 5\\n3 6\\n6 7\\n1 8\\n8 9\\n9 10\\n', 'output': '1\\n2\\n3\\n3\\n4\\n4\\n5\\n2\\n2\\n3\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://atcoder.jp/contests/abc165/tasks/abc165_f'}","problem_id":"vfc_894","program":"```python\nimport bisect\nimport sys\nsys.setrecursionlimit(10**7)\n\ndef dfs(v):\n pos=bisect.bisect_left(dp,arr[v])\n changes.append((pos,dp[pos]))\n dp[pos]=arr[v]\n ans[v]=bisect.bisect_left(dp,10**18)\n for u in g[v]:\n if checked[u]==0:\n checked[u]=1\n dfs(u)\n pos,val=changes.pop()\n dp[pos]=val\n\n\nn=int(input())\narr=[0]+list(map(int,input().split()))\ng=[[] for _ in range(n+1)]\nfor _ in range(n-1):\n a,b=map(int,input().split())\n g[a].append(b)\n g[b].append(a)\nans=[0]*(n+1)\nchecked=[0]*(n+1)\nchecked[1]=1\ndp=[10**18 for _ in range(n+1)]\nchanges=[]\ndfs(1)\nfor i in range(1,n+1):\n print(ans[i])\n```","inputs":"10\n1 2 5 3 4 6 7 3 2 4\n1 2\n2 3\n3 4\n4 5\n3 6\n6 7\n1 8\n8 9\n9 10\n","output":"1\n2\n3\n3\n4\n4\n5\n2\n2\n3\n","actual_output":"1\n2\n3\n3\n4\n4\n5\n2\n2\n3\n","execution_success":true,"sample_index":127},{"source":"apps","task_type":"verifiable_code","in_source_id":"514","prompt":"Solve the following coding problem using the programming language python:\n\nWrite a program to take two numbers as input and print their difference if the first number is greater than the second number otherwise$otherwise$ print their sum.\n\n-----Input:-----\n- First line will contain the first number (N1$N1$)\n- Second line will contain the second number (N2$N2$)\n\n-----Output:-----\nOutput a single line containing the difference of 2 numbers (N1\u2212N2)$(N1 - N2)$ if the first number is greater than the second number otherwise output their sum (N1+N2)$(N1 + N2)$.\n\n-----Constraints-----\n- \u22121000\u2264N1\u22641000$-1000 \\leq N1 \\leq 1000$\n- \u22121000\u2264N2\u22641000$-1000 \\leq N2 \\leq 1000$\n\n-----Sample Input:-----\n82\n28\n\n-----Sample Output:-----\n54\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nm = int(input())\nn = int(input())\nprint(m-n) if m>n else print(m+n)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '82\\n28\\n', 'output': '54\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/DIFFSUM'}","problem_id":"vfc_898","program":"```python\nm = int(input())\nn = int(input())\nprint(m-n) if m>n else print(m+n)\n```","inputs":"82\n28\n","output":"54\n","actual_output":"54\n","execution_success":true,"sample_index":128},{"source":"apps","task_type":"verifiable_code","in_source_id":"515","prompt":"Solve the following coding problem using the programming language python:\n\nWitua is a little student from the University of Lviv. He enjoys studying math. Witua knows a lot of famous mathematicians like Eratosthenes, Pythagoras, Fermat, Diophantus, Furko, Gauss and so on. However, his favorite one is Euler. The only thing Witua likes more than Euler is Euler\u2019s totient function \u03c6. He is exploring the nature of this function. One of the steps of his work is finding \u03c6(i)/i for all 2\u2264i\u2264N. He doesn\u2019t need to know every such value, but Witua wonders for what value i, is \u03c6(i)/i the maximum he can get? Help little student to find such i that \u03c6(i)/i is maximum among all the 2\u2264i\u2264N.\n\n-----Input-----\nThe first line contains single integer T - the number of test cases. Each of the next T lines contains a single integer N. \n\n-----Output-----\nFor every test case output i such that \u03c6(i)/i is maximum among all i (2\u2264i\u2264N) in a separate line.\n\n-----Constrains-----\nT (1\u2264T\u2264500 )\n\nN(2\u2264N\u226410^18)\n\n\n-----Example-----\nInput:\n3\n2\n3\n4\n\nOutput:\n2\n3\n3\n\nExplanation\u03c6(2)/2=1/2\n\u03c6(3)/3=2/3\n\u03c6(4)/4=2/4\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\ndef modular_pow(base, exponent, modulus):\n result = 1\n while exponent > 0:\n if(exponent %2 == 1):\n result = (result * base) % modulus\n exponent = exponent//2\n base = (base * base)%modulus\n return result\ndef passesMillerRabinTest(n, a):\n s = 0\n d = n-1\n while(d%2 == 0):\n s += 1\n d >>= 1\n x = modular_pow(a, d, n)\n if(x == 1 or x == n-1):\n return True\n for ss in range(s - 1):\n x = (x*x)%n\n if(x == 1):\n return False\n if(x == n-1):\n return True\n return False\nprimeList = (2, 3,5,7,11,13,17,19, 23,29, 31,37)\ndef isPrime(n):\n for p in primeList:\n if n%p == 0:\n return n == p\n for p in primeList:\n if passesMillerRabinTest(n, p) == False:\n return False\n return True\n \nt = int(input())\nfor tt in range(t):\n n = int(input())\n if(n == 2):\n print(2)\n continue\n if n%2 == 0:\n n -= 1\n while True:\n if(isPrime(n)):\n print(n)\n break\n n -= 2\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\n2\\n3\\n4\\n', 'output': '2\\n3\\n3\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/WITMATH'}","problem_id":"vfc_902","program":"```python\n# cook your dish here\ndef modular_pow(base, exponent, modulus):\n result = 1\n while exponent > 0:\n if(exponent %2 == 1):\n result = (result * base) % modulus\n exponent = exponent//2\n base = (base * base)%modulus\n return result\ndef passesMillerRabinTest(n, a):\n s = 0\n d = n-1\n while(d%2 == 0):\n s += 1\n d >>= 1\n x = modular_pow(a, d, n)\n if(x == 1 or x == n-1):\n return True\n for ss in range(s - 1):\n x = (x*x)%n\n if(x == 1):\n return False\n if(x == n-1):\n return True\n return False\nprimeList = (2, 3,5,7,11,13,17,19, 23,29, 31,37)\ndef isPrime(n):\n for p in primeList:\n if n%p == 0:\n return n == p\n for p in primeList:\n if passesMillerRabinTest(n, p) == False:\n return False\n return True\n \nt = int(input())\nfor tt in range(t):\n n = int(input())\n if(n == 2):\n print(2)\n continue\n if n%2 == 0:\n n -= 1\n while True:\n if(isPrime(n)):\n print(n)\n break\n n -= 2\n\n```","inputs":"3\n2\n3\n4\n","output":"2\n3\n3\n","actual_output":"2\n3\n3\n","execution_success":true,"sample_index":129},{"source":"apps","task_type":"verifiable_code","in_source_id":"516","prompt":"Solve the following coding problem using the programming language python:\n\nAlmir had a small sequence $A_1, A_2, \\ldots, A_N$. He decided to make $K$ copies of this sequence and concatenate them, forming a sequence $X_1, X_2, \\ldots, X_{NK}$; for each valid $i$ and $j$ ($0 \\le j < K$), $X_{j \\cdot N + i} = A_i$.\nFor example, if $A = (1, 2, 3)$ and $K = 4$, the final sequence is $X = (1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3)$.\nA pair $(i, j)$, where $1 \\le i < j \\le N$, is an inversion if $X_i > X_j$. Find the number of inversions in the final sequence $X$.\n\n-----Input-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The first line of each test case contains two space-separated integers $N$ and $K$.\n- The second line contains $N$ space-separated integers $A_1, A_2, \\ldots, A_N$.\n\n-----Output-----\nFor each test case, print a single line containing one integer \u2015 the number of inversions in the sequence $X$.\n\n-----Constraints-----\n- $1 \\le T \\le 1,000$\n- $1 \\le N \\le 100$\n- $1 \\le K \\le 10^6$\n- $1 \\le A_i \\le 10^9$ for each valid $i$\n\n-----Subtasks-----\nSubtask #1 (100 points): original constraints\n\n-----Example Input-----\n2\n3 3\n2 1 3\n4 100\n99 2 1000 24\n\n-----Example Output-----\n12\n30000\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\ndef count(k,n,m):\n sum1=(m*(m+1))//2\n sum2=(m*(m-1))//2\n ct=0\n for i in range(n):\n for j in range(n):\n if ik[j]:\n ct+=sum1\n elif jk[j]:\n ct+=sum2\n return ct\n\ntest=int(input())\nfor _ in range(test):\n n,m=map(int,input().split())\n k=list(map(int,input().split()))\n print(count(k,n,m))\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n3 3\\n2 1 3\\n4 100\\n99 2 1000 24\\n\\n', 'output': '12\\n30000\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/INVYCNT'}","problem_id":"vfc_906","program":"```python\n# cook your dish here\ndef count(k,n,m):\n sum1=(m*(m+1))//2\n sum2=(m*(m-1))//2\n ct=0\n for i in range(n):\n for j in range(n):\n if ik[j]:\n ct+=sum1\n elif jk[j]:\n ct+=sum2\n return ct\n\ntest=int(input())\nfor _ in range(test):\n n,m=map(int,input().split())\n k=list(map(int,input().split()))\n print(count(k,n,m))\n\n```","inputs":"2\n3 3\n2 1 3\n4 100\n99 2 1000 24\n\n","output":"12\n30000\n","actual_output":"12\n30000\n","execution_success":true,"sample_index":130},{"source":"apps","task_type":"verifiable_code","in_source_id":"517","prompt":"Solve the following coding problem using the programming language python:\n\nIndian National Olympiad in Informatics 2015\nA string is any nonempty sequence of 0s and 1s. Examples of strings are 00, 101, 111000, 1, 0, 01. The length of a string is the number of symbols in it. For example, the length of 111000 is 6. If u and v are strings, then uv is the string obtained by concatenating u and v. For example if u = 110 and v = 0010 then uv = 1100010.\nA string w is periodic if there exists a string v such that w = vn = vv \u00b7 \u00b7 \u00b7 v (n times), for some n \u2265 2. Note that in this case the length of v is strictly less than that of w. For example, 110110 is periodic, because it is vv for v = 110.\nGiven a positive integer N , find the number of strings of length N which are not periodic. Report the answer modulo M . The non-periodic strings of length 2 are 10 and 01. The non- periodic strings of length 3 are 001, 010, 011, 100, 101, and 110.\n\n-----Input format-----\nA single line, with two space-separated integers, N and M .\n\n-----Output format-----\nA single integer, the number of non-periodic strings of length N , modulo M .\n\n-----Test Data-----\nIn all subtasks, 2 \u2264 M \u2264 108. The testdata is grouped into 4 subtasks.\nSubtask 1 (10 marks) 1 \u2264 N \u2264 4000. N is the product of two distinct prime numbers.\nSubtask 2 (20 marks) 1 \u2264 N \u2264 4000. N is a power of a prime number.\nSubtask 3 (35 marks) 1 \u2264 N \u2264 4000.\nSubtask 4 (35 marks) 1 \u2264 N \u2264 150000.\n\n-----Example-----\nHere is the sample input and output corresponding to the example above:\n\n-----Sample input-----\n3 176\n\n-----Sample output-----\n6\n\nNote: 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!\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\r\ndef offset(l, flag):\r\n x = 0\r\n # print(l)\r\n for i in range(1, len(l)):\r\n temp = []\r\n for j in range(i):\r\n v = getbig(l[i], l[j], fs)\r\n if v > 1:\r\n temp.append(v)\r\n if flag:\r\n x += 2**v - 2\r\n else:\r\n x -= 2**v - 2\r\n x += offset(temp, not flag)\r\n return x\r\n \r\ndef getbig(v1, v2, factors):\r\n x = 1\r\n for f in factors:\r\n while v1%f == 0 and v2%f == 0:\r\n v1//=f\r\n v2//=f\r\n x*=f\r\n return x\r\n \r\ndef prime_factors(n):\r\n i = 2\r\n factors = set()\r\n while i * i <= n:\r\n if n % i:\r\n i += 1\r\n else:\r\n n //= i\r\n factors.add(i)\r\n if n > 1:\r\n factors.add(n)\r\n return factors\r\n \r\nn,m = map(int, input().split())\r\nif n == 1:\r\n print(1)\r\nelse:\r\n fs = prime_factors(n)\r\n fs.discard(n)\r\n ans = 2**n-2\r\n temp = []\r\n for v in fs:\r\n v = n//v\r\n temp.append(v)\r\n ans -= 2**v - 2\r\n # print(ans)\r\n ans += offset(temp, True)\r\n # print(fs)\r\n print(ans%m)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3 176\\n', 'output': '6\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/INOIPRAC/problems/INOI1502'}","problem_id":"vfc_910","program":"```python\n# cook your dish here\r\ndef offset(l, flag):\r\n x = 0\r\n # print(l)\r\n for i in range(1, len(l)):\r\n temp = []\r\n for j in range(i):\r\n v = getbig(l[i], l[j], fs)\r\n if v > 1:\r\n temp.append(v)\r\n if flag:\r\n x += 2**v - 2\r\n else:\r\n x -= 2**v - 2\r\n x += offset(temp, not flag)\r\n return x\r\n \r\ndef getbig(v1, v2, factors):\r\n x = 1\r\n for f in factors:\r\n while v1%f == 0 and v2%f == 0:\r\n v1//=f\r\n v2//=f\r\n x*=f\r\n return x\r\n \r\ndef prime_factors(n):\r\n i = 2\r\n factors = set()\r\n while i * i <= n:\r\n if n % i:\r\n i += 1\r\n else:\r\n n //= i\r\n factors.add(i)\r\n if n > 1:\r\n factors.add(n)\r\n return factors\r\n \r\nn,m = map(int, input().split())\r\nif n == 1:\r\n print(1)\r\nelse:\r\n fs = prime_factors(n)\r\n fs.discard(n)\r\n ans = 2**n-2\r\n temp = []\r\n for v in fs:\r\n v = n//v\r\n temp.append(v)\r\n ans -= 2**v - 2\r\n # print(ans)\r\n ans += offset(temp, True)\r\n # print(fs)\r\n print(ans%m)\n```","inputs":"3 176\n","output":"6\n","actual_output":"6\n","execution_success":true,"sample_index":131},{"source":"apps","task_type":"verifiable_code","in_source_id":"518","prompt":"Solve the following coding problem using the programming language python:\n\nFinally, the pandemic is over in ChefLand, and the chef is visiting the school again. Chef likes to climb the stairs of his school's floor by skipping one step, sometimes chef climbs the stairs one by one. Simply, the chef can take one or 2 steps in one upward movement. There are N stairs between ground and next floor. The chef is on the ground floor and he wants to go to the next floor with Cheffina but, Cheffina asks chef in how many ways, the chef can reach the next floor normally or any combination of skipping one step, where order doesn't matter. \n\n-----Input:-----\n- First-line will contain $T$, the number of test cases. Then the test cases follow. \n- Each test case contains a single line of input, two integers $N$. \n\n-----Output:-----\nFor each test case, output in a single line answer as the number of ways.\n\n-----Constraints-----\n- $1 \\leq T \\leq 1000$\n- $1 \\leq N \\leq 10^5$\n\n-----Sample Input:-----\n1\n3\n\n-----Sample Output:-----\n2\n\n-----EXPLANATION:-----\nways: [1,1,1], here chef climb to the next floor, one by one stair.\n[1,2], here chef climb to the next floor, one step first and after that 2 stairs at once.\nNote, [2,1] consider the same as that of [1,2] hence ignored.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfor _ in range(int(input())):\n N=int(input())\n if N%2==0:\n print(N//2+1)\n else:\n print((N-1)//2+1)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n3\\n', 'output': '2\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/PBK12020/problems/ITGUY20'}","problem_id":"vfc_914","program":"```python\nfor _ in range(int(input())):\n N=int(input())\n if N%2==0:\n print(N//2+1)\n else:\n print((N-1)//2+1)\n```","inputs":"1\n3\n","output":"2\n","actual_output":"2\n","execution_success":true,"sample_index":132},{"source":"apps","task_type":"verifiable_code","in_source_id":"519","prompt":"Solve the following coding problem using the programming language python:\n\nIndian National Olympiad in Informatics 2016\n\tThere are k types of brackets each with its own opening bracket and closing bracket. We assume that the first pair is denoted by the numbers 1 and k+1, the second by 2 and k+2 and so on. Thus the opening brackets are denoted by 1,2,.., k, and the corresponding closing brackets are denoted by k+1,k+2,..., 2*k respectively.\n\n\tSome sequences with elements from 1,2, ... 2*k form well-bracketed sequences while others don't. A sequence is well-bracketed, if we can match or pair up opening brackets and closing brackets of the same type in such a way that the following holds:\n\n\t 1) every bracket is paired up\n\n\t 2) in each matched pair, the opening bracket occurs before the closing bracket\n\n\t 3) for a matched pair, any other matched pair lies either completely between them or outside them.\n\n\tFor the examples discussed below, let us assume that k = 2. The sequence 1,1,3 is not well-bracketed as one of the two 1's cannot be paired. The sequence 3,1,3,1 is not well-bracketed as there is no way to match the second 1 to a closing bracket occurring after it. The sequence 1,2,3,4 is not well-bracketed as the matched pair 2,4 is neither completely between the matched pair 1,3 nor completely outside it. That is, the matched pairs cannot overlap. The sequence 1,2,4,3,1,3 is well-bracketed. We match the first 1 with the first 3, the 2 with the 4 and the second 1 with the second 3, satisfying all the 3 conditions. If you rewrite these sequences using [,{,],} instead of 1,2,3,4 respectively, this will be quite clear.\n\n\tIn this problem you are given a sequence of brackets, of length N: B[1], .., B[N], where each B[i] is one of the brackets. You are also given an array of Values: V[1],.., V[N].\n\n\tAmong all the subsequences in the Values array, such that the corresponding bracket subsequence in the B Array is a well-bracketed sequence, you need to find the maximum sum. Suppose N = 6, k = 3 and the values of V and B are as follows:\n\ni\t1\t2\t3\t4\t5\t6\nV[i]\t4\t5\t-2\t1\t1\t6\nB[i]\t1\t3\t4\t2\t5\t6\n\n\tThen, the brackets in positions 1,3 form a well-bracketed sequence (1,4) and the sum of the values in these positions is 2 (4 + -2 = 2). The brackets in positions 1,3,4,5 form a well-bracketed sequence (1,4,2,5) and the sum of the values in these positions is 4. Finally, the brackets in positions 2,4,5,6 forms a well-bracketed sequence (3,2,5,6) and the sum of the values in these positions is 13. The sum of the values in positions 1,2,5,6 is 16 but the brackets in these positions (1,3,5,6) do not form a well-bracketed sequence. You can check the best sum from positions whose brackets form a well-bracketed sequence is 13.\n\n\n-----Input format-----\n\tOne line, which contains (2*N + 2) space separate integers. The first integer denotes N. The next integer is k. The next N integers are V[1],..., V[N]. The last N integers are B[1],.., B[N].\n\n\n-----Output format-----\n\tOne integer, which is the maximum sum possible satisfying the requirement mentioned above. \n\n\n-----Test data-----\n\n\t\t1 \u2264 k \u2264 7\n\n\t\t-106 \u2264 V[i] \u2264 106, for all i\n\n\t\t1 \u2264 B[i] \u2264 2*k, for all i.\n\t\nSubtask 1 (40 Marks) 1 \u2264 n \u2264 10.\nSubtask 2 (60 Marks) 1 \u2264 n \u2264 700.\n\n\n-----Sample Input-----\n6 3 4 5 -2 1 1 6 1 3 4 2 5 6\n\n-----Sample Output-----\n13\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\r\nimport bisect\r\nn, k1, *l = map(int, input().split())\r\nv_l, b_l = l[:n], l[n:]\r\n\r\nb_inv = {key:[] for key in range(2*k1)}\r\nfor i in range(n):\r\n b_l[i] -= 1\r\n b_inv[b_l[i]].append(i)\r\n\r\ndp = [[0 for _ in range(n)] for _ in range(n)]\r\nfor k in range(1, n):\r\n for j in range(n-2, -1, -1):\r\n if j+k >= n:\r\n continue\r\n \r\n dp[j][j+k] = max(dp[j][j+k], dp[j][j+k-1])\r\n if b_l[j+k] >= k1:\r\n left = bisect.bisect_right(b_inv[b_l[j+k]-k1], j)\r\n \r\n if b_l[j+k] >= k1:\r\n for i in b_inv[b_l[j+k]-k1][left:]:\r\n if i > j+k:\r\n break\r\n if i > j:\r\n dp[j][j+k] = max(dp[j][j+k], dp[j][i-1]+dp[i][j+k])\r\n \r\n if b_l[j+k]-k1 == b_l[j]:\r\n if j+k-1 < n:\r\n dp[j][j+k] = max(dp[j][j+k], v_l[j+k]+v_l[j]+dp[j+1][j+k-1])\r\n else:\r\n dp[j][j+k] = max(dp[j][j+k], v_l[j+k]+v_l[j])\r\n \r\n\r\nprint(dp[0][-1])\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '6 3 4 5 -2 1 1 6 1 3 4 2 5 6\\n', 'output': '13\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/INOIPRAC/problems/INOI1602'}","problem_id":"vfc_918","program":"```python\n# cook your dish here\r\nimport bisect\r\nn, k1, *l = map(int, input().split())\r\nv_l, b_l = l[:n], l[n:]\r\n\r\nb_inv = {key:[] for key in range(2*k1)}\r\nfor i in range(n):\r\n b_l[i] -= 1\r\n b_inv[b_l[i]].append(i)\r\n\r\ndp = [[0 for _ in range(n)] for _ in range(n)]\r\nfor k in range(1, n):\r\n for j in range(n-2, -1, -1):\r\n if j+k >= n:\r\n continue\r\n \r\n dp[j][j+k] = max(dp[j][j+k], dp[j][j+k-1])\r\n if b_l[j+k] >= k1:\r\n left = bisect.bisect_right(b_inv[b_l[j+k]-k1], j)\r\n \r\n if b_l[j+k] >= k1:\r\n for i in b_inv[b_l[j+k]-k1][left:]:\r\n if i > j+k:\r\n break\r\n if i > j:\r\n dp[j][j+k] = max(dp[j][j+k], dp[j][i-1]+dp[i][j+k])\r\n \r\n if b_l[j+k]-k1 == b_l[j]:\r\n if j+k-1 < n:\r\n dp[j][j+k] = max(dp[j][j+k], v_l[j+k]+v_l[j]+dp[j+1][j+k-1])\r\n else:\r\n dp[j][j+k] = max(dp[j][j+k], v_l[j+k]+v_l[j])\r\n \r\n\r\nprint(dp[0][-1])\n```","inputs":"6 3 4 5 -2 1 1 6 1 3 4 2 5 6\n","output":"13\n","actual_output":"13\n","execution_success":true,"sample_index":133},{"source":"apps","task_type":"verifiable_code","in_source_id":"520","prompt":"Solve the following coding problem using the programming language python:\n\nWrite a program that takes in a letterclass ID of a ship and display the equivalent string class description of the given ID. Use the table below.\n\nClass ID Ship ClassB or bBattleShipC or cCruiserD or dDestroyerF or fFrigate\n\n-----Input-----\n\nThe first line contains an integer T, the total number of testcases. Then T lines follow, each line contains a character. \n\n-----Output-----\nFor each test case, display the Ship Class depending on ID, in a new line.\n\n-----Constraints-----\n- 1 \u2264 T \u2264 1000\n\n-----Example-----\nInput\n\n3 \nB\nc\nD\n\nOutput\nBattleShip\nCruiser\nDestroyer\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\nt=int(input())\nfor i in range(t):\n n=input()\n if(n=='b' or n=='B'):\n print('BattleShip')\n elif(n=='c' or n=='C'):\n print('Cruiser')\n elif(n=='d' or n=='D'):\n print('Destroyer')\n else:\n print('Frigate')\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\nB\\nc\\nD\\n', 'output': 'BattleShip\\nCruiser\\nDestroyer\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/FLOW010'}","problem_id":"vfc_922","program":"```python\n# cook your dish here\nt=int(input())\nfor i in range(t):\n n=input()\n if(n=='b' or n=='B'):\n print('BattleShip')\n elif(n=='c' or n=='C'):\n print('Cruiser')\n elif(n=='d' or n=='D'):\n print('Destroyer')\n else:\n print('Frigate')\n```","inputs":"3\nB\nc\nD\n","output":"BattleShip\nCruiser\nDestroyer\n","actual_output":"BattleShip\nCruiser\nDestroyer\n","execution_success":true,"sample_index":134},{"source":"apps","task_type":"verifiable_code","in_source_id":"522","prompt":"Solve the following coding problem using the programming language python:\n\nThree Best Friends $AMAN$ , $AKBAR$ , $ANTHONY$ are planning to go to \u201cGOA\u201d , but just like every other goa trip plan there is a problem to their plan too.\nTheir parents will only give permission if they can solve this problem for them\nThey are a given a number N and they have to calculate the total number of triplets (x ,y ,z)\nSatisfying the given condition y * x +z=n.\nFor ex if N=3\nThen there exist 3 triplets( x ,y ,z): (1,1,2) , (1,2,1) , (2,1,1) which satisfy the condition\nHelp the group to get permission for the trip\n\n-----Input:-----\n- First line will contain the number $N$.\n\n-----Output:-----\nthe possible number of triplets satisfying the given condition\n\n-----Constraints-----\n- $2 \\leq N \\leq 10^6$\n\n-----Sample Input:-----\n3\n\n-----Sample Output:-----\n3\n\n-----EXPLANATION:-----\nthere exist 3 triplets ( x ,y ,z): (1,1,2) , (1,2,1) , (2,1,1) which satisfy the condition\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nimport sys\r\ndef get_array(): return list(map(int , sys.stdin.readline().strip().split()))\r\ndef get_ints(): return list(map(int, sys.stdin.readline().strip().split()))\r\ndef input(): return sys.stdin.readline().strip()\r\nimport sys\r\nsys.setrecursionlimit(10**9)\r\nfrom math import sqrt,ceil,floor\r\nn=int(input())\r\nco=0\r\nans=0\r\nfor i in range(1,n):\r\n ans+=n//i\r\n if n%i==0:\r\n ans-=1\r\nprint(ans)\r\n\r\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\n', 'output': '3\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/SPRT2020/problems/GOATRIP'}","problem_id":"vfc_930","program":"```python\nimport sys\r\ndef get_array(): return list(map(int , sys.stdin.readline().strip().split()))\r\ndef get_ints(): return list(map(int, sys.stdin.readline().strip().split()))\r\ndef input(): return sys.stdin.readline().strip()\r\nimport sys\r\nsys.setrecursionlimit(10**9)\r\nfrom math import sqrt,ceil,floor\r\nn=int(input())\r\nco=0\r\nans=0\r\nfor i in range(1,n):\r\n ans+=n//i\r\n if n%i==0:\r\n ans-=1\r\nprint(ans)\r\n\r\n\n```","inputs":"3\n","output":"3\n","actual_output":"3\n","execution_success":true,"sample_index":136},{"source":"apps","task_type":"verifiable_code","in_source_id":"524","prompt":"Solve the following coding problem using the programming language python:\n\nThere are total $N$ cars in a sequence with $ith$ car being assigned with an alphabet equivalent to the $ith$ alphabet of string $S$ . Chef has been assigned a task to calculate the total number of cars with alphabet having a unique even value in the given range X to Y (both inclusive)\n. The value of an alphabet is simply its position in alphabetical order e.g.: a=1, b=2, c=3\u2026\nThe chef will be given $Q$\nsuch tasks having varying values of $X$ and $Y$\nNote: string $S$ contains only lowercase alphabets\n\n-----Input-----\nFirst line of input contains a string $S$ of length $N$.\nSecond line contains an integer denoting no. of queries $Q$.\nNext q lines contain two integers denoting values of $X$ and $Y$.\n\n-----Output-----\nFor each query print a single integer denoting total number of cars with alphabet having a unique even value in the given range $X$ to $Y$.\n\n-----Constraints-----\n- $1 \\leq n \\leq 10^5$\n- $1 \\leq q \\leq 10^5$\n\n-----Example Input-----\nbbccdd\n5\n1 2\n3 4\n5 6\n1 6\n2 5\n\n-----Example Output-----\n1\n0\n1\n2\n2\n\n-----Explanation:-----\nExample case 1: \nQuery 1: range 1 to 2 contains the substring $\"bb\"$ where each character has a value of 2. Since we will only be considering unique even values, the output will be 1\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\narr = list(input())\r\nn = len(arr)\r\nans = list()\r\n#for i in arr:\r\n #ans.append(ord(i)-96)\r\nli = ['b','d','f','h','j','l','n','p','r','t','v','x','z']\r\ns = set(arr)\r\ntemp = s.intersection(li)\r\nfor _ in range(int(input())):\r\n x,y = list(map(int,input().split()))\r\n li = list(temp)\r\n #s = set()\r\n c=0\r\n for i in range(x-1,y):\r\n if arr[i] in li:\r\n c+=1 \r\n li.remove(arr[i])\r\n if len(li)==0:\r\n break\r\n print(c)\r\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': 'bbccdd\\n5\\n1 2\\n3 4\\n5 6\\n1 6\\n2 5\\n', 'output': '1\\n0\\n1\\n2\\n2\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/STRG2020/problems/TOTCARS'}","problem_id":"vfc_938","program":"```python\narr = list(input())\r\nn = len(arr)\r\nans = list()\r\n#for i in arr:\r\n #ans.append(ord(i)-96)\r\nli = ['b','d','f','h','j','l','n','p','r','t','v','x','z']\r\ns = set(arr)\r\ntemp = s.intersection(li)\r\nfor _ in range(int(input())):\r\n x,y = list(map(int,input().split()))\r\n li = list(temp)\r\n #s = set()\r\n c=0\r\n for i in range(x-1,y):\r\n if arr[i] in li:\r\n c+=1 \r\n li.remove(arr[i])\r\n if len(li)==0:\r\n break\r\n print(c)\r\n\n```","inputs":"bbccdd\n5\n1 2\n3 4\n5 6\n1 6\n2 5\n","output":"1\n0\n1\n2\n2\n","actual_output":"1\n0\n1\n2\n2\n","execution_success":true,"sample_index":137},{"source":"apps","task_type":"verifiable_code","in_source_id":"525","prompt":"Solve the following coding problem using the programming language python:\n\nYou are given three numbers $a$, $b$, $c$ . Write a program to determine the largest number that is less than or equal to $c$ and leaves a remainder $b$ when divided by $a$.\n\n-----Input:-----\n- First line will contain $T$, number of testcases. Then the testcases follow.\n- Each testcase contains a single line of input, having three integers $a$, $b$, $c$.\n\n-----Output:-----\n- For each testcase, output in a single line the largest number less than or equal to $c$.\n\n-----Constraints:-----\n- $1 \\leq T \\leq 100000$\n- $0 \\leq b < a < c \\leq$ $10$^18\n\n-----Sample Input:-----\n1\n7 2 10\n\n-----Sample Output:-----\n9\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\nfor t in range(int(input())):\n a,b,c=map(int,input().split())\n p=(c//a)*a+b\n if p<=c:\n print(p)\n else:\n print(((c//a)-1)*a+b)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n7 2 10\\n', 'output': '9\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/CCOD2020/problems/MOTU001'}","problem_id":"vfc_942","program":"```python\n# cook your dish here\nfor t in range(int(input())):\n a,b,c=map(int,input().split())\n p=(c//a)*a+b\n if p<=c:\n print(p)\n else:\n print(((c//a)-1)*a+b)\n```","inputs":"1\n7 2 10\n","output":"9\n","actual_output":"9\n","execution_success":true,"sample_index":138},{"source":"apps","task_type":"verifiable_code","in_source_id":"526","prompt":"Solve the following coding problem using the programming language python:\n\nAureole the Techno-cultural fest of JEC thought of conducting a workshop on big data, as the topic is hot everyone wants to take part but due to limited seats in the Jashan Auditorium there is a selection criteria, a problem is given.\nthe problem states a string is to be compressed when two or more consecutive characters are same they are to be compressed into one character and the original number count is to be written after it ex. aaabb -> a3b2\nwhere every character is of 8bits and every integer is of 32bits\nyou are asked to find the difference in size between original string and compressed string\n\n-----Input:-----\n- First line will contain $T$, number of testcases. Then the testcases follow. \n- Each testcase contains of a single line of input $S$ the string to be compressed. \n\n-----Output:-----\nFor each testcase, output in a single line The difference in size.\n\n-----Constraints-----\n- $1 \\leq T \\leq 100$\n- $1 \\leq |S| \\leq 10^5$\n\n-----Subtasks-----\n- 40 points : S will contain only a-z\n- 60 points : S will contain 0-9 characters also\n\n-----Sample Input:-----\n1\naaabb\n\n-----Sample Output:-----\n-40\n\n-----EXPLANATION:-----\nthe resulting string will be a3b2 its size will be 80, original string size will be 40 so ans= 40-80\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n#include\nfor _ in range(int(input())):\n s=input()\n n=len(s)\n if n==1:\n if s[0].isalpha(): print(\"-32\")\n else: print(0)\n else:\n num,ch=0,0\n p,q=0,0\n c=1\n x=s[0]\n ans=\"\"\n for i in range(1,n):\n if s[i-1]==s[i]:\n c+=1\n if i==n-1:\n ans+=s[i-1]\n ch+=1\n if c>1:\n ans+=str(c)\n num+=1\n c=1\n else:\n ans+=s[i-1]\n ch+=1\n if c>1:\n ans+=str(c)\n num+=1\n c=1\n if i==n-1:\n ans+=s[i]\n ch+=1\n #print(ans,num,ch)\n sol=(n*8)-((num*32)+(ch*8))\n print(sol)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\naaabb\\n', 'output': '-40\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/COPT2020/problems/AUREOLE'}","problem_id":"vfc_946","program":"```python\n#include\nfor _ in range(int(input())):\n s=input()\n n=len(s)\n if n==1:\n if s[0].isalpha(): print(\"-32\")\n else: print(0)\n else:\n num,ch=0,0\n p,q=0,0\n c=1\n x=s[0]\n ans=\"\"\n for i in range(1,n):\n if s[i-1]==s[i]:\n c+=1\n if i==n-1:\n ans+=s[i-1]\n ch+=1\n if c>1:\n ans+=str(c)\n num+=1\n c=1\n else:\n ans+=s[i-1]\n ch+=1\n if c>1:\n ans+=str(c)\n num+=1\n c=1\n if i==n-1:\n ans+=s[i]\n ch+=1\n #print(ans,num,ch)\n sol=(n*8)-((num*32)+(ch*8))\n print(sol)\n```","inputs":"1\naaabb\n","output":"-40\n","actual_output":"-40\n","execution_success":true,"sample_index":139},{"source":"apps","task_type":"verifiable_code","in_source_id":"527","prompt":"Solve the following coding problem using the programming language python:\n\nGiven an Array of length $N$ containing elements $Ai$ ( i = 1 to n ) . You have to handle $Q$ queries on this array . Each Query is of two types k=(1 or 2). \nType 1:- $k$ $l$ $r$ in which you have to tell whether the product of numbers in range l to r results in a perfect square or not. if product of numbers in range $l$ to$r$ is a perfect square then simply output YES else output NO.\nType 2:- $k$ $i$ $val$ Multiply the value present at index $i$ with $val$.\nNote#1: 1 based indexing in each query.\nNote#2: Values of prime factors of all numbers $val$ and $Ai$ is between 2 to 100 only.\n\n-----Input:-----\n- First line will contain $N$, denoting the size of the array. Then the next line follow. \n- N integers $Ai - An$.\n- Third line will contain $Q$, denoting the number of queries. Then the next $Q$ lines follow -description of each query. \n- Each query consists of either type 1 or type 2 and each query gives you three elements either\n-{$k$ $l$ $r$} or {$k$ $i$ $val$}\n\n-----Output:-----\nFor each Query of Type 1 Output either \"YES\" or \"NO\" Without Quotes.\n\n-----Constraints-----\n- $1 \\leq N \\leq 20000$\n- $1 \\leq Q \\leq 20000$\n- $2 \\leq Ai \\leq 1000000$\n- $1 \\leq i ,l,r \\leq N$\n- $1 \\leq val \\leq 1000000$\n- $1 \\leq l \\leq r$\n\n-----Subtasks-----\nSubtask 1 :-40 points \n- Values of prime factors of all numbers $val$ and $Ai$ is between 2 to 40 only.\nSubtask 2 :- 60 points\n- Original Constraints \n\n-----Sample Input:-----\n4\n2 2 3 4\n4\n1 1 2\n1 3 4\n2 3 3\n1 1 4\n\n-----Sample Output:-----\nYES\nNO\nYES\n\n-----EXPLANATION:-----\n-Query 1 :- product of numbers in range 1 to 2=2 * 2=4 (perfect square so YES)\n-Query 2:- product of numbers in range 3 to 4 = 3 * 4 = 12 (not perfect square so NO)\n-Query 3:- multiply number at index3 with 3 so number at index 3= 3*3 = 9 .\n-Query 4:- product of numbers in range 1 to 4 = 2 * 2 * 9 * 4 = 144 (perfect square so YES)\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\ndef update(index, value, bi_tree):\n while index < len(bi_tree):\n bi_tree[index] += value\n index += index & -index\n\n\ndef get_sum(index, bi_tree):\n ans = 0\n while index > 0:\n ans += bi_tree[index]\n index -= index & -index\n\n return ans\n\n\ndef get_range_sum(left, right, bi_tree):\n ans = get_sum(right, bi_tree) - get_sum(left - 1, bi_tree)\n return ans\n\n\ndef solve(x):\n s = set()\n res = 1\n i = 2\n while (i * i <= x):\n count = 0\n while (x % i == 0):\n x = x // i\n count += 1\n if (count % 2):\n s.add(i)\n i += 1\n if (x > 0):\n s.add(x)\n return s\n\n\nn = int(input())\nl = [0] + [int(i) for i in input().split()]\nbit = [[0 for i in range(n + 1)] for i in range(101)]\n\nfor i in range(1, n + 1):\n s = solve(l[i])\n for j in s:\n update(i, 1, bit[j])\n\nq = int(input())\nfor i in range(q):\n k, a, b = [int(i) for i in input().split()]\n if (k == 1):\n f = 1\n for i in range(2, 100):\n res = get_range_sum(a, b, bit[i])\n if (res % 2):\n f = 0\n break\n if (f):\n print(\"YES\")\n else:\n print(\"NO\")\n else:\n s = solve(b)\n for j in s:\n update(a, 1, bit[j])\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '4\\n2 2 3 4\\n4\\n1 1 2\\n1 3 4\\n2 3 3\\n1 1 4\\n', 'output': 'YES\\nNO\\nYES\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/STRT2020/problems/RANPRO'}","problem_id":"vfc_950","program":"```python\ndef update(index, value, bi_tree):\n while index < len(bi_tree):\n bi_tree[index] += value\n index += index & -index\n\n\ndef get_sum(index, bi_tree):\n ans = 0\n while index > 0:\n ans += bi_tree[index]\n index -= index & -index\n\n return ans\n\n\ndef get_range_sum(left, right, bi_tree):\n ans = get_sum(right, bi_tree) - get_sum(left - 1, bi_tree)\n return ans\n\n\ndef solve(x):\n s = set()\n res = 1\n i = 2\n while (i * i <= x):\n count = 0\n while (x % i == 0):\n x = x // i\n count += 1\n if (count % 2):\n s.add(i)\n i += 1\n if (x > 0):\n s.add(x)\n return s\n\n\nn = int(input())\nl = [0] + [int(i) for i in input().split()]\nbit = [[0 for i in range(n + 1)] for i in range(101)]\n\nfor i in range(1, n + 1):\n s = solve(l[i])\n for j in s:\n update(i, 1, bit[j])\n\nq = int(input())\nfor i in range(q):\n k, a, b = [int(i) for i in input().split()]\n if (k == 1):\n f = 1\n for i in range(2, 100):\n res = get_range_sum(a, b, bit[i])\n if (res % 2):\n f = 0\n break\n if (f):\n print(\"YES\")\n else:\n print(\"NO\")\n else:\n s = solve(b)\n for j in s:\n update(a, 1, bit[j])\n```","inputs":"4\n2 2 3 4\n4\n1 1 2\n1 3 4\n2 3 3\n1 1 4\n","output":"YES\nNO\nYES\n","actual_output":"YES\nNO\nYES\n","execution_success":true,"sample_index":140},{"source":"apps","task_type":"verifiable_code","in_source_id":"529","prompt":"Solve the following coding problem using the programming language python:\n\nGiven an integer N. Integers A and B are chosen randomly in the range [1..N]. Calculate the probability that the Greatest Common Divisor(GCD) of A and B equals to B.\n\n-----Input-----\nThe first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows. Each test case consists of a single integer N on a separate line.\n\n-----Output-----\nFor each test case, output a single line containing probability as an irreducible fraction. \n\n-----Example-----\nInput:\n3\n1\n2\n3\n\nOutput:\n1/1\n3/4\n5/9\n\n-----Constraints-----\n\n1<=T<=103\n\n1<=N<=109\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nimport math\nfor _ in range(int(input())):\n n=int(input())\n s=int(math.sqrt(n))\n ans=0\n for i in range(1,s+1):\n ans+=(n//i)\n ans=ans*2-(s*s)\n g=math.gcd(n*n,ans)\n print(str(ans//g)+\"/\"+str(n*n//g)) \n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\n1\\n2\\n3\\n', 'output': '1/1\\n3/4\\n5/9\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/COOLGUYS'}","problem_id":"vfc_958","program":"```python\nimport math\nfor _ in range(int(input())):\n n=int(input())\n s=int(math.sqrt(n))\n ans=0\n for i in range(1,s+1):\n ans+=(n//i)\n ans=ans*2-(s*s)\n g=math.gcd(n*n,ans)\n print(str(ans//g)+\"/\"+str(n*n//g)) \n```","inputs":"3\n1\n2\n3\n","output":"1/1\n3/4\n5/9\n","actual_output":"1/1\n3/4\n5/9\n","execution_success":true,"sample_index":141},{"source":"apps","task_type":"verifiable_code","in_source_id":"532","prompt":"Solve the following coding problem using the programming language python:\n\nTo help Lavanya learn all about binary numbers and binary sequences, her father has bought her a collection of square tiles, each of which has either a 0 or a 1 written on it. Her brother Nikhil has played a rather nasty prank. He has glued together pairs of tiles with 0 written on them. Lavanya now has square tiles with 1 on them and rectangular tiles with two 0's on them, made up of two square tiles with 0 stuck together). Thus, she can no longer make all possible binary sequences using these tiles.\nTo amuse herself, Lavanya has decided to pick a number $N$ and try and construct as many binary sequences of length $N$ as possible using her collection of tiles. For example if $N$ = 1, she can only make the sequence 1. For $N$=2, she can make 11 and 00. For $N$=4, there are 5 possibilities: 0011, 0000, 1001, 1100 and 1111.\nLavanya would like you to write a program to compute the number of arrangements possible with $N$ tiles so that she can verify that she has generated all of them. Since she cannot count beyond 15746, it is sufficient to report this number modulo 15746.\n\n-----Input:-----\nA single line with a single integer $N$.\n\n-----Output:-----\nA single integer indicating the number of binary sequences of length $N$, modulo 15746, that Lavanya can make using her tiles.\n\n-----Constraints:-----\nYou may assume that $N \\leq$ 1000000.\n\n-----Sample Input:-----\n4\n\n-----Sample Output:-----\n5\n\n-----Explanation:-----\nThis corresponds to the example discussed above.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nn=int(input())\nmodulo=15746\nnum=[1,1]\nfor i in range(2,n+1):\n num.append((num[i-1]+num[i-2])%modulo)\nprint(num[n])\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '4\\n', 'output': '5\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/IARCSJUD/problems/TILES01'}","problem_id":"vfc_970","program":"```python\nn=int(input())\nmodulo=15746\nnum=[1,1]\nfor i in range(2,n+1):\n num.append((num[i-1]+num[i-2])%modulo)\nprint(num[n])\n```","inputs":"4\n","output":"5\n","actual_output":"5\n","execution_success":true,"sample_index":143},{"source":"apps","task_type":"verifiable_code","in_source_id":"533","prompt":"Solve the following coding problem using the programming language python:\n\nThe chef is playing a game of long distance. Chef has a number K and he wants to find the longest distance between the index of the first and the last occurrence of K in a given array of N numbers.\n\n-----Input:-----\n- First-line will contain $T$, the number of test cases. Then the test cases follow. \n- Each test case contains two lines of input.\n- Next line with Two integers in one line $K, N$.\n- Next line with $N$ space-separated integers.\n\n-----Output:-----\nFor each test case, output in a single line answer as the index of first and last occurrence of K in the given array.\nNote: Here Indexing is from 1 not 0 based.\n\n-----Constraints-----\n- $1 \\leq T \\leq 100$\n- $1 \\leq k \\leq 10^5$\n- $1 \\leq N \\leq 10^5$\n\n-----Sample Input:-----\n2\n2 6\n2 3 4 2 1 6\n4 6\n2 3 4 2 1 6\n\n-----Sample Output:-----\n3\n0\n\n-----EXPLANATION:-----\nFor 1) Index of First and last occurrence of 2 in the given array is at 1 and 4, i.e. distance is 3. \nFor 2) 4 occurs only once in the given array hence print 0.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\nfor _ in range(int(input())):\n m,n=list(map(int,input().split()))\n a=[int(i) for i in input().split()]\n l=-1\n for i in range(n-1,-1,-1):\n if a[i]==m:\n l=i\n break\n f=-1\n for i in range(0,n):\n if a[i]==m:\n f=i\n break\n print(l-f)\n \n \n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n2 6\\n2 3 4 2 1 6\\n4 6\\n2 3 4 2 1 6\\n', 'output': '3\\n0\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/PBK32020/problems/ITGUY33'}","problem_id":"vfc_974","program":"```python\n# cook your dish here\nfor _ in range(int(input())):\n m,n=list(map(int,input().split()))\n a=[int(i) for i in input().split()]\n l=-1\n for i in range(n-1,-1,-1):\n if a[i]==m:\n l=i\n break\n f=-1\n for i in range(0,n):\n if a[i]==m:\n f=i\n break\n print(l-f)\n \n \n\n```","inputs":"2\n2 6\n2 3 4 2 1 6\n4 6\n2 3 4 2 1 6\n","output":"3\n0\n","actual_output":"3\n0\n","execution_success":true,"sample_index":144},{"source":"apps","task_type":"verifiable_code","in_source_id":"534","prompt":"Solve the following coding problem using the programming language python:\n\nVasya's older brother, Petya, attends an algorithm course in his school. Today he learned about matchings in graphs. Formally, a set of edges in a graph is called a matching if no pair of distinct edges in the set shares a common endpoint.\nPetya instantly came up with an inverse concept, an antimatching. In an antimatching, any pair of distinct edges should have a common endpoint.\nPetya knows that finding a largest matching in a graph is a somewhat formidable task. He wonders if finding the largest antimatching is any easier. Help him find the number of edges in a largest antimatching in a given graph.\n\n-----Input:-----\nThe first line contains T$T$, number of test cases per file.\nThe first line of each test case contains two integers n$n$ and m\u2212$m-$ the number of vertices and edges of the graph respectively (1\u2264n\u2264104$1 \\leq n \\leq 10^4$, 0\u2264m\u2264104$0 \\leq m \\leq 10^4$).\nThe next m$m$ lines describe the edges. The i$i$-th of these lines contains two integers ui$u_i$ and vi\u2212$v_i-$ the indices of endpoints of the i$i$-th edge (1\u2264ui,vi\u2264n$1 \\leq u_i, v_i \\leq n$, ui\u2260vi$u_i \\neq v_i$).\nIt is guaranteed that the graph does not contain self-loops nor multiple edges. It is not guaranteed that the graph is connected.\n\n-----Output:-----\nPrint a single number per test case \u2212$-$ the maximum size of an antichain in the graph.\n\n-----Constraints-----\n- 1\u2264T\u226410$1 \\leq T \\leq 10$\n- 1\u2264n\u2264104$1 \\leq n \\leq 10^4$\n- 0\u2264m\u2264104$0 \\leq m \\leq 10^4$\n- 1\u2264ui,vi\u2264n$1 \\leq u_i, v_i \\leq n$\n- ui\u2260vi$u_i \\neq v_i$\n\n-----Sample Input:-----\n3\n3 3\n1 2\n1 3\n2 3\n4 2\n1 2\n3 4\n5 0\n\n-----Sample Output:-----\n3\n1\n0\n\n-----EXPLANATION:-----\nIn the first sample all three edges form an antimatching.\nIn the second sample at most one of the two edges can be included in an antimatching since they do not share common endpoints.\nIn the third sample there are no edges, hence the answer is 0$0$.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\ndef detect_triangle(adj): \n for x in range(len(adj)):\n for y in adj[x]:\n if not set(adj[x]).isdisjoint(adj[y]):\n return True\n\n \nfor _ in range(int(input())):\n n,m=list(map(int,input().split()))\n graph=[[] for i in range(n)]\n for i in range(m):\n u,v=list(map(int,input().split()))\n graph[u-1].append(v-1)\n graph[v-1].append(u-1)\n h=[] \n for i in range(len(graph)):\n h.append(len(graph[i]))\n h1=max(h) \n if h1>=3:\n print(h1)\n continue\n if detect_triangle(graph):\n print(3)\n continue\n print(h1) # cook your dish here\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\n3 3\\n1 2\\n1 3\\n2 3\\n4 2\\n1 2\\n3 4\\n5 0\\n', 'output': '3\\n1\\n0\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/ANTMAT'}","problem_id":"vfc_978","program":"```python\ndef detect_triangle(adj): \n for x in range(len(adj)):\n for y in adj[x]:\n if not set(adj[x]).isdisjoint(adj[y]):\n return True\n\n \nfor _ in range(int(input())):\n n,m=list(map(int,input().split()))\n graph=[[] for i in range(n)]\n for i in range(m):\n u,v=list(map(int,input().split()))\n graph[u-1].append(v-1)\n graph[v-1].append(u-1)\n h=[] \n for i in range(len(graph)):\n h.append(len(graph[i]))\n h1=max(h) \n if h1>=3:\n print(h1)\n continue\n if detect_triangle(graph):\n print(3)\n continue\n print(h1) # cook your dish here\n\n```","inputs":"3\n3 3\n1 2\n1 3\n2 3\n4 2\n1 2\n3 4\n5 0\n","output":"3\n1\n0\n","actual_output":"3\n1\n0\n","execution_success":true,"sample_index":145},{"source":"apps","task_type":"verifiable_code","in_source_id":"535","prompt":"Solve the following coding problem using the programming language python:\n\nChef got in the trouble! He is the king of Chefland and Chessland. There is one queen in Chefland and one queen in Chessland and they both want a relationship with him. Chef is standing before a difficult choice\u2026\nChessland may be considered a chessboard with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$). Let's denote a unit square in row $r$ and column $c$ by $(r, c)$. Chef lives at square $(X, Y)$ of this chessboard.\nCurrently, both queens are living in Chessland too. Each queen, when alone on the chessboard, can see all squares that lie on the same row, column or diagonal as itself. A queen from $(x_q, y_q)$ cannot see a square $(r, c)$ if the square $(X, Y)$ is strictly between them. Of course, if the queens can see each other, the kingdom will soon be in chaos!\nHelp Chef calculate the number of possible configurations of the queens such that the kingdom will not be in chaos. A configuration is an unordered pair of distinct squares $(x_{q1}, y_{q1})$ and $(x_{q2}, y_{q2})$ such that neither of them is the square $(X, Y)$. Two configurations are different if the position of queen $1$ is different or the position of queen $2$ is different.\n\n-----Input-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The first and only line of each test case contains four space-separated integers $N$, $M$, $X$ and $Y$. \n\n-----Output-----\nFor each test case, print a single line containing one integer \u2014 the number of configurations such that the kingdom will not be in chaos.\n\n-----Constraints-----\n- $1 \\le T \\le 1000$\n- $1 \\le X \\le N \\le 10^2$\n- $1 \\le Y \\le M \\le 10^2$\n- $2 \\le N, M$\n\n-----Example Input-----\n2\n3 3 2 2\n4 4 2 3\n\n-----Example Output-----\n24\n94\n\n-----Explanation-----\nExample case 1: Half of these configurations are:\n- $(1, 1), (3, 3)$\n- $(1, 1), (2, 3)$\n- $(1, 1), (3, 2)$\n- $(1, 2), (3, 3)$\n- $(1, 2), (3, 2)$\n- $(1, 2), (3, 1)$\n- $(1, 3), (3, 1)$\n- $(1, 3), (3, 2)$\n- $(1, 3), (2, 1)$\n- $(2, 1), (2, 3)$\n- $(2, 1), (1, 3)$\n- $(2, 1), (3, 3)$\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\ndef C(n):\n return n*(n-1)//2\n\n\ndef sol():\n equal, mini = False, min(N,M)\n total_ways = 2*C(N * M)\n if N==M:\n equal = True\n ways = 0\n if not equal:\n ways = (N*C(M)+M*C(N))\n diag = 0\n for i in range(2, mini+1):\n diag += 2*C(i)\n for i in range(mini+1,max(N,M)):\n diag += C(mini)\n diag *= 2\n ways += diag\n ways *= 2\n else:\n ways = (N*C(M)+M*C(N))\n diag = 0\n for i in range(2, mini):\n diag += 2*C(i)\n diag += C(mini)\n diag *= 2\n ways += diag\n ways *=2\n safe = total_ways - ways\n l, r, t, d = Y-1, M-Y, X-1, N-X\n safe_add, to_remove = 0, 0\n\n for i in range(1,N+1):\n for j in range(1, M+1):\n if i==X or j==Y or abs(i-X)==abs(j-Y):\n continue\n else:\n to_remove += 1\n\n if l>0 and r>0 and t>0 and d>0:\n dtl, dtr, dbl, dbr = min(l,t), min(r,t), min(l,d), min(r,d)\n safe_add += dtl*dbr*2 + dtr*dbl*2\n safe_add += t*d*2\n safe_add += l*r*2\n elif l>0 and r>0:\n safe_add += l*r*2\n elif t>0 and d>0:\n safe_add += t*d*2\n\n safe += safe_add - to_remove*2\n\n return safe\n\n\nT = int(input())\nfor _ in range(T):\n N, M, X, Y = [int(x) for x in input().split()]\n print(sol())\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n3 3 2 2\\n4 4 2 3\\n', 'output': '24\\n94\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/CHQUEENS'}","problem_id":"vfc_982","program":"```python\ndef C(n):\n return n*(n-1)//2\n\n\ndef sol():\n equal, mini = False, min(N,M)\n total_ways = 2*C(N * M)\n if N==M:\n equal = True\n ways = 0\n if not equal:\n ways = (N*C(M)+M*C(N))\n diag = 0\n for i in range(2, mini+1):\n diag += 2*C(i)\n for i in range(mini+1,max(N,M)):\n diag += C(mini)\n diag *= 2\n ways += diag\n ways *= 2\n else:\n ways = (N*C(M)+M*C(N))\n diag = 0\n for i in range(2, mini):\n diag += 2*C(i)\n diag += C(mini)\n diag *= 2\n ways += diag\n ways *=2\n safe = total_ways - ways\n l, r, t, d = Y-1, M-Y, X-1, N-X\n safe_add, to_remove = 0, 0\n\n for i in range(1,N+1):\n for j in range(1, M+1):\n if i==X or j==Y or abs(i-X)==abs(j-Y):\n continue\n else:\n to_remove += 1\n\n if l>0 and r>0 and t>0 and d>0:\n dtl, dtr, dbl, dbr = min(l,t), min(r,t), min(l,d), min(r,d)\n safe_add += dtl*dbr*2 + dtr*dbl*2\n safe_add += t*d*2\n safe_add += l*r*2\n elif l>0 and r>0:\n safe_add += l*r*2\n elif t>0 and d>0:\n safe_add += t*d*2\n\n safe += safe_add - to_remove*2\n\n return safe\n\n\nT = int(input())\nfor _ in range(T):\n N, M, X, Y = [int(x) for x in input().split()]\n print(sol())\n```","inputs":"2\n3 3 2 2\n4 4 2 3\n","output":"24\n94\n","actual_output":"24\n94\n","execution_success":true,"sample_index":146},{"source":"apps","task_type":"verifiable_code","in_source_id":"536","prompt":"Solve the following coding problem using the programming language python:\n\n2021 was approaching and the world was about to end. So 2 gods Saurabhx and Saurabhy (from Celesta) created the Cyberverse. But this time disappointed with humans both the gods decided not to have humans in this world. So they created a world of cyborgs. A world without humans. Isn\u2019t it interesting? So let us dive into the cyberverse and have a look at their problems.\nThere are $N$ kid cyborgs with Chief Cyborg '100gods' and he has $K$ weapons with him. He wants to distribute those $K$ weapons among $N$ kid cyborgs. Since all the kid cyborgs are very good friends, so they set a rule among themselves for taking those weapons. The rule states that the difference between kid cyborg having the maximum weapons and the kid cyborg having minimum weapons should be less than or equal to $1$.\n\nFind the value of the minimum number of weapons a kid cyborg can have when all the $K$ weapons are distributed among them.\n\n-----Input:-----\n- The first line contains an integer $T$, denoting the number of test cases.\n- Each of the next $T$ lines will contain two space-separated integers denoting $N$ and $K$ respectively.\n\n-----Output:-----\n- For each test case ,output a single line containing an integer $X$ denoting the minimum number of weapons a kid cyborg can have in that test case. \n\n-----Constraints:-----\n- $1 \\leq T \\leq 10^5$\n- $1 \\leq N \\leq 10^5$\n- $1 \\leq K \\leq 10^9$\n\n-----Sample Input:-----\n1\n5 8\n\n-----Expected Output:-----\n1\n\n-----Explanation-----\n- There are $5$ kids and $8$ weapons. \n- Hence we will distribute the weapons such that $3$ kids have $2$ weapons each and the remaining $2$ kids have $1$ weapon each. \n- Hence the minimum number of weapons a kid cyborg has is $1$. ( That is, $min(1,2)$ = $1$ )\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\nt=int(input())\nfor i in range(t):\n (n,k)=tuple(map(int,input().split()))\n print(k//n)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n5 8\\n', 'output': '1\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/CYBV'}","problem_id":"vfc_986","program":"```python\n# cook your dish here\nt=int(input())\nfor i in range(t):\n (n,k)=tuple(map(int,input().split()))\n print(k//n)\n```","inputs":"1\n5 8\n","output":"1\n","actual_output":"1\n","execution_success":true,"sample_index":147},{"source":"apps","task_type":"verifiable_code","in_source_id":"537","prompt":"Solve the following coding problem using the programming language python:\n\nZonal Computing Olympiad 2015, 29 Nov 2014\n\nWe say that two integers x and y have a variation of at least K, if |x \u2212 y| \u2265 K (the absolute value of their difference is at least K). Given a sequence of N integers a1,a2,...,aN and K, the total variation count is the number of pairs of elements in the sequence with variation at least K, i.e. it is the size of the set of pairs\n\n{(i,j)|1\u2264i=k):\r\n ans+=1\r\nprint(ans)\r\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3 1\\n3 1 3\\n', 'output': '2\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/ZCOPRAC/problems/ZCO15002'}","problem_id":"vfc_990","program":"```python\nn,k=[int(x) for x in input().split()]\r\na=[int(x) for x in input().split()]\r\nans=0\r\nfor i in range(n-1):\r\n for j in range(i+1,n):\r\n if(abs(a[i]-a[j])>=k):\r\n ans+=1\r\nprint(ans)\r\n\n```","inputs":"3 1\n3 1 3\n","output":"2\n","actual_output":"2\n","execution_success":true,"sample_index":148},{"source":"apps","task_type":"verifiable_code","in_source_id":"538","prompt":"Solve the following coding problem using the programming language python:\n\nSebi goes to school daily with his father. They cross a big highway in the car to reach to the school. Sebi sits in front seat beside his father at driving seat. To kill boredom, they play a game of guessing speed of other cars on the highway. Sebi makes a guess of other car's speed being SG kph, his father FG kph. \n\nThe highway is usually empty, so the drivers use cruise control, i.e. vehicles run at a constant speed. There are markers on the highway at a gap of 50 meters. Both father-son duo wants to check the accuracy of their guesses. For that, they start a timer at the instant at which their car and the other car (which speed they are guessing) are parallel to each other (they need not to be against some marker, they can be in between the markers too). After some T seconds, they observe that both the cars are next to some markers and the number of markers in between the markers of their car and the other car is D - 1 (excluding the markers next to both the cars). Also, they can observe these markers easily because the other car is faster than their. Speed of Sebi's father's car is S. Using this information, one can find the speed of the other car accurately.\n\nAn example situation when Sebi's father starts the timer. Notice that both the car's are parallel to each other.\n\nExample situation after T seconds. The cars are next to the markers. Here the value of D is 1. The green car is Sebi's and the other car is of blue color.\n\nSebi's a child, he does not know how to find the check whose guess is close to the real speed of the car. He does not trust his father as he thinks that he might cheat. Can you help to resolve this issue between them by telling whose guess is closer. If Sebi's guess is better, output \"SEBI\". If his father's guess is better, output \"FATHER\". If both the guess are equally close, then output \"DRAW\".\n\n-----Input-----\nThe first line of the input contains an integer T denoting the number of test cases. \nEach of the next T lines contain five space separated integers S, SG, FG, D, T corresponding to the Sebi's car speed, Sebi's guess, his father's guess, D as defined in the statement and the time at which both the cars at against the markers (in seconds), respectively.\n\n-----Output-----\nOutput description.\nFor each test case, output a single line containing \"SEBI\", \"FATHER\" or \"DRAW\" (without quotes) denoting whose guess is better.\n\n-----Constraints-----\n- 1 \u2264 T \u2264 10000\n- 0 \u2264 S \u2264 130\n- 0 \u2264 SG, FG \u2264 300\n- 1 \u2264 D \u2264 30\n- 1 \u2264 T \u2264 300\n- The other car speed doesn't exceed 300 kph.\n\n-----Example-----\nInput:\n2\n100 180 200 20 60\n130 131 132 1 72\n\nOutput:\nSEBI\nFATHER\n\n-----Explanation-----\nExample case 1.\nThere are total 20 - 1 = 19 markers in between the Sebi's car and the other car. So, the distance between those cars at time T is 20 * 50 = 1000 meters = 1 km.\nAs T = 60 seconds, i.e. 1 minutes. So, the other car goes 1 km more than Sebi's car in 1 minute. So, the other car will go 60 km more than Sebi's car in 1 hour. So, its speed is 60 kmph more than Sebi's car, i.e. 160 kmph.\nSebi had made a guess of 180 kmph, while his father of 200 kmph. Other car's real speed is 160 kmph. So, Sebi's guess is better than his father. Hence he wins the game.\nExample case 2.\n\nThe situation of this example is depicted in the image provided in the statement. You can find the speed of other car and see that Father's guess is more accurate.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\nn=int(input())\nfor i in range(n):\n S, SG, FG, D, T = map(int, input().split())\n speed = (D*180)/T + S\n if abs(SG-speed) == abs(FG-speed):\n print('DRAW')\n elif abs(SG-speed) > abs(FG-speed):\n print('FATHER')\n else:\n print('SEBI')\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n100 180 200 20 60\\n130 131 132 1 72\\n\\n\\n', 'output': 'SEBI\\nFATHER\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/SEBIHWY'}","problem_id":"vfc_994","program":"```python\n# cook your dish here\nn=int(input())\nfor i in range(n):\n S, SG, FG, D, T = map(int, input().split())\n speed = (D*180)/T + S\n if abs(SG-speed) == abs(FG-speed):\n print('DRAW')\n elif abs(SG-speed) > abs(FG-speed):\n print('FATHER')\n else:\n print('SEBI')\n```","inputs":"2\n100 180 200 20 60\n130 131 132 1 72\n\n\n","output":"SEBI\nFATHER\n","actual_output":"SEBI\nFATHER\n","execution_success":true,"sample_index":149},{"source":"apps","task_type":"verifiable_code","in_source_id":"539","prompt":"Solve the following coding problem using the programming language python:\n\nBob has got some injury in his leg and due to this he can take exactly M steps in one move. \nBob enters a square field of size NxN. The field is only having one gate(for both entrance and exit) at its one of the corners. Bob started walking along the perimeter of square field.(remember Bob can only take exactly M steps in one move and cannot reverse his direction of motion).\nBob wants to know how many minimum number of moves he needs to come out(i.e. he reaches the same gate from where he entered into the field) from the square field. Tell the answer to Bob ASAP.\nLuckily, you came to know M=N+1.\n\n-----Input-----\n- The first line of the input contains an integer T denoting the number of test cases.\n- Each test case contains a single integer N denoting the sides of the square.\n\n-----Output-----\n- For each test case, output a single line containing minimum number of moves Bob required to come out from the field.\n\n-----Constraints-----\n- 1 \u2264 T \u2264 10000\n- 1 \u2264 N \u2264 1000000000\n\n-----Example-----\nInput:\n2\n1\n2\n\nOutput:\n2\n8\n\n-----Explanation-----\nExample case 1.Let four corners of square be (0,0), (0,1), (1,1), (1,0). Let gate be at (0,0). Bob takes 2 steps in one move. Let movement of Bob be as follows (0,0) -> (1,1) -> (0,0). Thus minimum moves needed were 2. \nExample case 2.Let four corners of square be (0,0), (0,2), (2,2), (2,0). Let gate be at (0,0). Bob takes 3 steps in one move. Let movement of Bob be as follows (0,0) -> (2,1) -> (0,2) -> (1,0) -> (2,2) -> (0,1) -> (2,0) -> (1,2) -> (0,0). Thus minimum number of moves needed are 8.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# By Prathmesh Maurya\nt=eval(input())\nwhile(t!=0):\n t-=1\n n=eval(input())\n if n%2 == 0:\n print(n*4)\n elif n%4==3:\n print(n)\n else:\n print(n*2)\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n1\\n2\\n', 'output': '2\\n8\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/LOCAUG16/problems/BSQUARE'}","problem_id":"vfc_998","program":"```python\n# By Prathmesh Maurya\nt=eval(input())\nwhile(t!=0):\n t-=1\n n=eval(input())\n if n%2 == 0:\n print(n*4)\n elif n%4==3:\n print(n)\n else:\n print(n*2)\n\n```","inputs":"2\n1\n2\n","output":"2\n8\n","actual_output":"2\n8\n","execution_success":true,"sample_index":150},{"source":"apps","task_type":"verifiable_code","in_source_id":"540","prompt":"Solve the following coding problem using the programming language python:\n\nChef has a sequence of positive integers $A_1, A_2, \\ldots, A_N$. He wants to choose some elements of this sequence (possibly none or all of them) and compute their MEX, i.e. the smallest positive integer which does not occur among the chosen elements. For example, the MEX of $[1, 2, 4]$ is $3$.\nHelp Chef find the largest number of elements of the sequence $A$ which he can choose such that their MEX is equal to $M$, or determine that it is impossible.\n\n-----Input-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The first line of each test case contains two space-separated integers $N$ and $M$.\n- The second line contains $N$ space-separated integers $A_1, A_2, \\ldots, A_N$.\n\n-----Output-----\nFor each test case, print a single line containing one integer \u2015 the maximum number of elements Chef can choose, or $-1$ if he cannot choose elements in such a way that their MEX is $M$.\n\n-----Constraints-----\n- $1 \\le T \\le 100$\n- $2 \\le M \\le N \\le 10^5$\n- $1 \\le A_i \\le 10^9$ for each valid $i$\n- the sum of $N$ over all test cases does not exceed $10^6$\n\n-----Example Input-----\n1\n3 3\n1 2 4\n\n-----Example Output-----\n3\n\n-----Explanation-----\nExample case 1: The MEX of whole array is 3. Hence, we can choose all the elements.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n \r\nfor __ in range(int(input())):\r\n n,m=map(int,input().split())\r\n arr=list(map(int,input().split()))\r\n s=set(arr)\r\n mex=-1\r\n ele=1\r\n for i in range(1,n+1):\r\n if i not in s:\r\n mex = i\r\n break\r\n if m>mex:\r\n print(-1)\r\n elif m==mex:\r\n print(n)\r\n else:\r\n c=arr.count(m)\r\n print(n-c)\r\n \r\n \r\n \r\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n3 3\\n1 2 4\\n\\n', 'output': '3\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/MAXMEX'}","problem_id":"vfc_1002","program":"```python\n \r\nfor __ in range(int(input())):\r\n n,m=map(int,input().split())\r\n arr=list(map(int,input().split()))\r\n s=set(arr)\r\n mex=-1\r\n ele=1\r\n for i in range(1,n+1):\r\n if i not in s:\r\n mex = i\r\n break\r\n if m>mex:\r\n print(-1)\r\n elif m==mex:\r\n print(n)\r\n else:\r\n c=arr.count(m)\r\n print(n-c)\r\n \r\n \r\n \r\n\n```","inputs":"1\n3 3\n1 2 4\n\n","output":"3\n","actual_output":"3\n","execution_success":true,"sample_index":151},{"source":"apps","task_type":"verifiable_code","in_source_id":"541","prompt":"Solve the following coding problem using the programming language python:\n\n\"Humankind cannot gain anything without first giving something in return. To obtain, something of equal value must be lost. That is alchemy's first law of Equivalent Exchange. In those days, we really believed that to be the world's one, and only truth.\"\n-- Alphonse Elric\nNow, here we have an equivalent exchange law for triangles which states that two right-angled isosceles triangles of the same color can be made into a square of the same color using Alchemy.\nYou are given N$N$ right-angled isosceles colored triangles numbered from 1$1$ to N$N$. For each triangle, the two equal sides have a length of 1$1$ unit. The Color of i$i$-th triangle is given by Ci$C_i$.\nTo create a tower, we choose some consecutive (2\u00d7k)+1$2 \\times k)+1$ triangles for any k\u22650$k \\geq 0$. We then pick some 2\u00d7k$2 \\times k$ of them (these need not be consecutive), and form k$k$ pairs of triangles such that both triangles in pair have the same color. Also, each of the 2\u00d7k$2 \\times k$ should be in exactly one pair. Then the two triangles in each pair are joined using Alchemy (following the law of equivalent exchange for triangles) to form squares and these k$k$ squares are placed one upon other. The one remaining triangle is placed as a roof to the tower. This results in a tower of the height of k$k$.\nFind the maximum height of the tower that can be formed. \nIn other words, you should select the largest consecutive segment of triangles, such that you can form a tower using every single one of those triangles. In particular, you leave out one triangle, which will form the roof, and the other triangles should all be paired up such that both triangles in a pair have the same colour.\n\n-----Input:-----\n- The first line contains T$T$, the number of test cases. Then the test cases follow. \n- For every test case, the first line contains N$N$ denoting the number of triangles.\n- For every test case, the second line contains N$N$ space-separated integers Ci$C_{i}$ denoting the color of the triangles. ( 1\u2264i\u2264N$1 \\leq i \\leq N$).\n\n-----Output:-----\nFor every test case, output a single integer denoting the maximum height of the tower that can be formed.\n\n-----Constraints-----\n- 1\u2264T\u2264100$1 \\leq T \\leq 100$ \n- 1\u2264N\u2264105$1 \\leq N \\leq 10^{5}$ \n- 1\u2264Ci\u226430$1 \\leq C_{i} \\leq 30$ \n- Sum of N$N$ over all test cases doesn't exceed 5\u00d7105$5\\times 10^{5}$ \n\n-----Sample Input:-----\n4\n14\n5 4 2 2 3 2 1 3 2 7 4 9 9 9\n3\n1 2 1\n3\n1 1 1\n5\n1 2 3 4 1\n\n-----Sample Output:-----\n3\n1\n1\n0\n\n-----EXPLANATION:-----\n- #1$1$: The subarray [2,2,3,2,1,3,2]$[2, 2, 3, 2, 1, 3, 2]$ results in a tower of height 3$3$.\n- #2$2$: The subarray [1,2,1]$[ 1, 2, 1 ]$ results in a tower of height 1$1$.\n- #3$3$: The subarray [1,1,1]$[ 1, 1, 1 ]$ results in a tower of height 1$1$. \n- #4$4$: The subarrays [1]$[ 1 ]$, [2]$[ 2 ]$ , [3]$[ 3 ]$, [4]$[ 4 ]$ and [1]$[ 1 ]$ all results in a tower of height 0$0$.\n\nThe above tower is possible by subarray [2,2,3,2,1,3,2]$[2, 2, 3, 2, 1, 3, 2]$ resulting in a height of 3$3$ in test case 1$1$.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfor i in range(int(input())):\n n = int(input())\n c = list(map(int, input().split()))\n d = {}\n d[0] = -1\n parity = 0\n ans = 0\n for i in range(n):\n parity ^= 1 << (c[i]-1)\n for t in range(30):\n x = parity^(1< b):\n tmp = a\n a = b\n b = tmp\n if (b == a):\n return 0\n if (b % a == 0):\n return int(b/a)-1\n r = g(b%a,a)\n q = int(b/a)\n if (r >= q):\n return q-1\n else:\n return q\n\ndef mex(x):\n n = len(list(x.keys()))\n for i in range(n):\n if (i not in x):\n return i\n return i\n\ndef g2(a,b):\n if (a == b):\n return 0\n if (a > b):\n tmp = a\n a = b\n b = tmp\n if (b % a == 0):\n return int(b/a)-1\n q = int(b/a)\n x = {}\n r = b % a\n for i in range(q):\n x[g2(r+i*a,a)] = True\n return mex(x)\n\n#print(str(g(6,33))+\" \"+str(g2(6,33)))\n\nwhile (t):\n\n n = int(input())\n x = 0\n while (n):\n line = input().split()\n a = int(line[0])\n b = int(line[1])\n x ^= g(a,b)\n n -= 1\n if (x):\n sys.stdout.write(\"YES\\n\")\n else:\n sys.stdout.write(\"NO\\n\")\n #print(str(g(a,b)) + \" \" + str(g2(a,b)))\n t -= 1\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\n1\\n2 3\\n2\\n4 5\\n5 6\\n2\\n2 3\\n3 5\\n', 'output': 'NO\\nNO\\nYES\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/GAMEAAM'}","problem_id":"vfc_1030","program":"```python\nimport sys\n\nt = int(input())\n\ndef g(a,b):\n if (a > b):\n tmp = a\n a = b\n b = tmp\n if (b == a):\n return 0\n if (b % a == 0):\n return int(b/a)-1\n r = g(b%a,a)\n q = int(b/a)\n if (r >= q):\n return q-1\n else:\n return q\n\ndef mex(x):\n n = len(list(x.keys()))\n for i in range(n):\n if (i not in x):\n return i\n return i\n\ndef g2(a,b):\n if (a == b):\n return 0\n if (a > b):\n tmp = a\n a = b\n b = tmp\n if (b % a == 0):\n return int(b/a)-1\n q = int(b/a)\n x = {}\n r = b % a\n for i in range(q):\n x[g2(r+i*a,a)] = True\n return mex(x)\n\n#print(str(g(6,33))+\" \"+str(g2(6,33)))\n\nwhile (t):\n\n n = int(input())\n x = 0\n while (n):\n line = input().split()\n a = int(line[0])\n b = int(line[1])\n x ^= g(a,b)\n n -= 1\n if (x):\n sys.stdout.write(\"YES\\n\")\n else:\n sys.stdout.write(\"NO\\n\")\n #print(str(g(a,b)) + \" \" + str(g2(a,b)))\n t -= 1\n```","inputs":"3\n1\n2 3\n2\n4 5\n5 6\n2\n2 3\n3 5\n","output":"NO\nNO\nYES\n","actual_output":"NO\nNO\nYES\n","execution_success":true,"sample_index":158},{"source":"apps","task_type":"verifiable_code","in_source_id":"550","prompt":"Solve the following coding problem using the programming language python:\n\nThere is Chef and Chef\u2019s Crush who are playing a game of numbers.\n\nChef\u2019s crush has a number $A$ and Chef has a number $B$.\n\nNow, Chef wants Chef\u2019s crush to win the game always, since she is his crush. The game ends when the greatest value of A^B is reached after performing some number of operations (possibly zero), Where ^ is Bitwise XOR.\n\nBefore performing any operation you have to ensure that both $A$ and $B$ have the same number of bits without any change in the values. It is not guaranteed that $A$ and $B$ should have same number of bits in the input.\nFor example, if $A$ is $2$ and $B$ is $15$, then the binary representation of both the numbers will have to be $0010$ and $1111$ respectively, before performing any operation. \nThe operation is defined as : \n- Right circular shift of the bits of only $B$ from MSB$_B$ to LSB$_B$ i.e. if we consider $B_1 B_2 B_3 B_4$ as binary number, then after one circular right shift, it would be $B_4 B_1 B_2 B_3$\nThey both are busy with themselves, can you find the number of operations to end the game?\n\n-----Input :-----\n- The first line of input contains $T$, (number of test cases) \n- Then each of the next $T$ lines contain : two integers $A$ and $B$ respectively.\n\n-----Output :-----\nFor each test case print two space-separated integers, The number of operations to end the game and value of A^B when the game ends.\n\n-----Constraints :-----\n- $1 \\leq T \\leq100$ \n- $1\\leq A,B \\leq 10^{18}$\n\n-----Subtasks :-----\n- 30 Points: $1\\leq A,B \\leq 10^5$\n- 70 Points: Original Constraints\n\n-----Sample Input :-----\n1\n4 5\n\n-----Sample Output :-----\n2 7\n\n-----Explanation :-----\nBinary representation of $4$ is $100$ and binary representation $5$ is $101$. \n- After operation $1$ : $B$ $=$ $110$, so A^B $=$ $2$ \n- After operation $2$ : $B$ $=$ $011$, so A^B $=$ $7$ \nSo, the value of A^B will be $7$. Which is the greatest possible value for A^B and the number of operations are $2$.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n\ndef main():\n t = int(input())\n while (t):\n m, n = map(int, input().split())\n a , b= bin(m)[2:],bin(n)[2:]\n #print(a,b)\n max = m^n\n if len(a)>len(b):\n diff =len(a)-len(b)\n b= (\"0\"*diff)+b\n #print(b)\n elif len(a)max:\n max =tt\n count= i+1\n b=s\n\n print(count,max)\n t-=1\n\ndef __starting_point():\n main()\n__starting_point()\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n4 5\\n', 'output': '2 7\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/CHPTRS01/problems/GAMENUM'}","problem_id":"vfc_1042","program":"```python\n\ndef main():\n t = int(input())\n while (t):\n m, n = map(int, input().split())\n a , b= bin(m)[2:],bin(n)[2:]\n #print(a,b)\n max = m^n\n if len(a)>len(b):\n diff =len(a)-len(b)\n b= (\"0\"*diff)+b\n #print(b)\n elif len(a)max:\n max =tt\n count= i+1\n b=s\n\n print(count,max)\n t-=1\n\ndef __starting_point():\n main()\n__starting_point()\n```","inputs":"1\n4 5\n","output":"2 7\n","actual_output":"2 7\n","execution_success":true,"sample_index":161},{"source":"apps","task_type":"verifiable_code","in_source_id":"551","prompt":"Solve the following coding problem using the programming language python:\n\nChef Tobby is playing a rapid fire with Bhuvan. He gives Bhuvan a string S and each time, Bhuvan has to guess whether there exists 2 equal subsequences in the string or not.\nBhuvan got a perfect score in the game with Chef Tobby. However, Chef Tobby has now asked Bhuvan to write a program that will do this automatically given a string S. Bhuvan is an intelligent man but he does not know how to write a code. Can you help him?\nFind two different subsequences such that they are equal in their value, more formally, find two sequences of indices (a1, a2, ..., ak-1, ak) and (b1, b2, ..., bk-1, bk) such that:\n\n- 1\u2264 ai, bi \u2264 |S|\n- ai < ai+1 for all valid i\n- bi < bi+1 for all valid i\n- Sai = Sbi for all valid i\n- there exist at least one i such that ai is not equal to bi\n\n-----Input section-----\nThe first line contains T, the number of test cases.\nEach of the next T lines contain one string S each.\nInput will only consist of lowercase english characters\n\n-----Output section-----\nFor each test case, output \"yes\" or \"no\" (without quotes) as the solution to the problem.\n\n-----Input constraints-----\n1 \u2264 T \u2264 1000\n1 \u2264 length of S \u2264 100\n\n-----Sample Input-----\n4\nlikecs\nvenivedivici\nbhuvan\ncodechef\n\n-----Sample Output-----\nno\nyes\nno\nyes\n\n-----Explanation-----\nIn test case 2, one of the possible equal subsequence is \"vi\" and \"vi\". (one at position {0, 3} and other at {4, 7}, assuming 0-based indexing).\nIn test case 4, one of the possible equal subsequence is \"ce\" and \"ce\". (one at position {0, 3} and other at {4, 6}, assuming 0-based indexing).\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nt = int(input())\n\nfor _ in range(t):\n s = [x for x in input()]\n \n freq = {}\n \n for i in s:\n if i in freq:\n freq[i] += 1\n else:\n freq[i] = 1\n \n flag = 0\n \n for keys, values in freq.items():\n if(values >= 2):\n flag = 1\n break\n \n if(flag == 0):\n print(\"no\")\n else:\n print(\"yes\")\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '4\\nlikecs\\nvenivedivici\\nbhuvan\\ncodechef\\n', 'output': 'no\\nyes\\nno\\nyes\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/LIKECS01'}","problem_id":"vfc_1046","program":"```python\nt = int(input())\n\nfor _ in range(t):\n s = [x for x in input()]\n \n freq = {}\n \n for i in s:\n if i in freq:\n freq[i] += 1\n else:\n freq[i] = 1\n \n flag = 0\n \n for keys, values in freq.items():\n if(values >= 2):\n flag = 1\n break\n \n if(flag == 0):\n print(\"no\")\n else:\n print(\"yes\")\n```","inputs":"4\nlikecs\nvenivedivici\nbhuvan\ncodechef\n","output":"no\nyes\nno\nyes\n","actual_output":"no\nyes\nno\nyes\n","execution_success":true,"sample_index":162},{"source":"apps","task_type":"verifiable_code","in_source_id":"552","prompt":"Solve the following coding problem using the programming language python:\n\nChef has gone shopping with his 5-year old son. They have bought N items so far. The items are numbered from 1 to N, and the item i weighs Wi grams.\n\nChef's son insists on helping his father in carrying the items. He wants his dad to give him a few items. Chef does not want to burden his son. But he won't stop bothering him unless he is given a few items to carry. So Chef decides to give him some items. Obviously, Chef wants to give the kid less weight to carry.\n\nHowever, his son is a smart kid. To avoid being given the bare minimum weight to carry, he suggests that the items are split into two groups, and one group contains exactly K items. Then Chef will carry the heavier group, and his son will carry the other group.\n\nHelp the Chef in deciding which items should the son take. Your task will be simple. Tell the Chef the maximum possible difference between the weight carried by him and the weight carried by the kid.\n\n-----Input:-----\nThe first line of input contains an integer T, denoting the number of test cases. Then T test cases follow. The first line of each test contains two space-separated integers N and K. The next line contains N space-separated integers W1, W2, ..., WN.\n\n-----Output:-----\nFor each test case, output the maximum possible difference between the weights carried by both in grams.\n\n-----Constraints:-----\n- 1 \u2264 T \u2264 100\n- 1 \u2264 K < N \u2264 100\n- 1 \u2264 Wi \u2264 100000 (105)\n\n-----Example:-----\nInput:\n2\n5 2\n8 4 5 2 10\n8 3\n1 1 1 1 1 1 1 1\n\nOutput:\n17\n2\n\n-----Explanation:-----\nCase #1: The optimal way is that Chef gives his son K=2 items with weights 2 and 4. Chef carries the rest of the items himself. Thus the difference is: (8+5+10) \u2212 (4+2) = 23 \u2212 6 = 17.\n\nCase #2: Chef gives his son 3 items and he carries 5 items himself.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\ndef main():\n T = int(input())\n for t in range(T):\n N,K = map(int, input().split())\n W = list(map(int, input().split()))\n W.sort()\n if 2*K > N:\n K = N - K\n kid = sum(W[:K])\n dad = sum(W[K:])\n\n diff = dad - kid\n\n print(diff)\n\n\ndef __starting_point():\n main()\n__starting_point()\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n5 2\\n8 4 5 2 10\\n8 3\\n1 1 1 1 1 1 1 1\\n', 'output': '17\\n2\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/MAXDIFF'}","problem_id":"vfc_1050","program":"```python\ndef main():\n T = int(input())\n for t in range(T):\n N,K = map(int, input().split())\n W = list(map(int, input().split()))\n W.sort()\n if 2*K > N:\n K = N - K\n kid = sum(W[:K])\n dad = sum(W[K:])\n\n diff = dad - kid\n\n print(diff)\n\n\ndef __starting_point():\n main()\n__starting_point()\n```","inputs":"2\n5 2\n8 4 5 2 10\n8 3\n1 1 1 1 1 1 1 1\n","output":"17\n2\n","actual_output":"17\n2\n","execution_success":true,"sample_index":163},{"source":"apps","task_type":"verifiable_code","in_source_id":"553","prompt":"Solve the following coding problem using the programming language python:\n\nConsider the following operations on a triple of integers. In one operation, you should:\n- Choose an integer $d$ and an arithmetic operation \u2015 either addition or multiplication.\n- Choose a subset of elements of the triple.\n- Apply the arithmetic operation to each of the chosen elements, i.e. either add $d$ to each of them or multiply each of them by $d$.\nFor example, if we have a triple $(3, 5, 7)$, we may choose to add $3$ to the first and third element, and we get $(6, 5, 10)$ using one operation.\nYou are given an initial triple $(p, q, r)$ and a target triple $(a, b, c)$. Find the minimum number of operations needed to transform $(p, q, r)$ into $(a, b, c)$.\n\n-----Input-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The first line of each test case contains three space-separated integers $p$, $q$ and $r$.\n- The second line contains three space-separated integers $a$, $b$ and $c$.\n\n-----Output-----\nFor each test case, print a single line containing one integer \u2015 the minimum required number of operations.\n\n-----Constraints-----\n- $1 \\le T \\le 1,000$\n- $|p|, |q|, |r|, |a|, |b|, |c| \\le 10^9$\n\n-----Subtasks-----\nSubtask #1 (10 points): $|p|, |q|, |r|, |a|, |b|, |c| \\le 10$\nSubtask #2 (90 points): original constraints\n\n-----Example Input-----\n2\n3 5 7\n6 5 10\n8 6 3\n9 7 8\n\n-----Example Output-----\n1\n2\n\n-----Explanation-----\nExample case 1: We add $3$ to the first and third element of $(3, 5, 7)$ to form $(6, 5, 10)$.\nExample case 2: We can add $1$ to each element to form $(9, 7, 4)$ and then multiply the third element by $2$.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\ndef eq_solve(v0, v1, u0, u1):\r\n den = u0 - v0\r\n num = u1 - v1\r\n if den != 0:\r\n return num / den\r\n return 1\r\n \r\ndef solve(p, q, r, a, b, c, rs):\r\n if p == a and q == b and r == c:\r\n return rs\r\n if rs >= 2:\r\n return 3\r\n res = 3\r\n adds = [a - p, b - q, c - r]\r\n muls = []\r\n if p != 0:\r\n muls.append(a / p)\r\n if q != 0:\r\n muls.append(b / q)\r\n if r != 0:\r\n muls.append(c / r)\r\n muls.append(eq_solve(p, a, q, b))\r\n muls.append(eq_solve(p, a, r, c))\r\n muls.append(eq_solve(q, b, r, c))\r\n msks = 2 ** 3\r\n for msk in range(msks):\r\n for add in adds:\r\n np = p\r\n nq = q\r\n nr = r\r\n if (msk & 1) > 0:\r\n np += add\r\n if (msk & 2) > 0:\r\n nq += add\r\n if (msk & 4) > 0:\r\n nr += add\r\n res = min(res, solve(np, nq, nr, a, b, c, rs + 1))\r\n for mul in muls:\r\n np = p\r\n nq = q\r\n nr = r\r\n if (msk & 1) > 0:\r\n np *= mul\r\n if (msk & 2) > 0:\r\n nq *= mul\r\n if (msk & 4) > 0:\r\n nr *= mul\r\n res = min(res, solve(np, nq, nr, a, b, c, rs + 1))\r\n return res\r\n \r\n \r\n \r\nt = int(input())\r\n \r\nwhile t > 0:\r\n p, q, r = map(int, input().split())\r\n a, b, c = map(int, input().split())\r\n z = solve(p, q, r, a, b, c, 0)\r\n print(z)\r\n t -= 1 \n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n3 5 7\\n6 5 10\\n8 6 3\\n9 7 8\\n\\n', 'output': '1\\n2\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/TTUPLE'}","problem_id":"vfc_1054","program":"```python\ndef eq_solve(v0, v1, u0, u1):\r\n den = u0 - v0\r\n num = u1 - v1\r\n if den != 0:\r\n return num / den\r\n return 1\r\n \r\ndef solve(p, q, r, a, b, c, rs):\r\n if p == a and q == b and r == c:\r\n return rs\r\n if rs >= 2:\r\n return 3\r\n res = 3\r\n adds = [a - p, b - q, c - r]\r\n muls = []\r\n if p != 0:\r\n muls.append(a / p)\r\n if q != 0:\r\n muls.append(b / q)\r\n if r != 0:\r\n muls.append(c / r)\r\n muls.append(eq_solve(p, a, q, b))\r\n muls.append(eq_solve(p, a, r, c))\r\n muls.append(eq_solve(q, b, r, c))\r\n msks = 2 ** 3\r\n for msk in range(msks):\r\n for add in adds:\r\n np = p\r\n nq = q\r\n nr = r\r\n if (msk & 1) > 0:\r\n np += add\r\n if (msk & 2) > 0:\r\n nq += add\r\n if (msk & 4) > 0:\r\n nr += add\r\n res = min(res, solve(np, nq, nr, a, b, c, rs + 1))\r\n for mul in muls:\r\n np = p\r\n nq = q\r\n nr = r\r\n if (msk & 1) > 0:\r\n np *= mul\r\n if (msk & 2) > 0:\r\n nq *= mul\r\n if (msk & 4) > 0:\r\n nr *= mul\r\n res = min(res, solve(np, nq, nr, a, b, c, rs + 1))\r\n return res\r\n \r\n \r\n \r\nt = int(input())\r\n \r\nwhile t > 0:\r\n p, q, r = map(int, input().split())\r\n a, b, c = map(int, input().split())\r\n z = solve(p, q, r, a, b, c, 0)\r\n print(z)\r\n t -= 1 \n```","inputs":"2\n3 5 7\n6 5 10\n8 6 3\n9 7 8\n\n","output":"1\n2\n","actual_output":"1\n2\n","execution_success":true,"sample_index":164},{"source":"apps","task_type":"verifiable_code","in_source_id":"554","prompt":"Solve the following coding problem using the programming language python:\n\nJohnny was asked by his math teacher to compute nn (n to the power of n, where n is an integer), and has to read his answer out loud. This is a bit of a tiring task, since the result is probably an extremely large number, and would certainly keep Johnny occupied for a while if he were to do it honestly. But Johnny knows that the teacher will certainly get bored when listening to his answer, and will sleep through most of it! So, Johnny feels he will get away with reading only the first k digits of the result before the teacher falls asleep, and then the last k digits when the teacher wakes up.\n\nWrite a program to help Johnny to compute the digits he will need to read out.\n\n-----Input-----\nThe first line contains t, the number of test cases (about 30000). Then t test cases follow.\nEach test case consists of one line containing two numbers n and k (1 \u2264 n \u2264 109, 1 \u2264 k \u2264 9). It is guaranteed that k is not more than the number of digits of nn.\n\n-----Output-----\nFor each test case, print out one line containing two numbers, separated by a space, which are the first and the last k digits of nn.\n\n-----Example-----\nInput\n2\n4 2\n9 3\n\nOutput\n25 56\n387 489\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfrom math import log10\nfrom decimal import Decimal\ndef solve(n,k):\n \n mod=10**k\n x=Decimal(n)\n y=x*(x.log10())%1\n p=str(pow(10,y))\n c=0\n first=''\n for v in p:\n if c==k:\n break\n if v==\".\":\n continue\n first+=v\n c+=1\n last=str(pow(n,n,mod)).zfill(k)\n return (first,last)\nqueries=[]\nfor _ in range(int(input())):\n n,k=list(map(int,input().split( )))\n queries.append((n,k))\nfor n,k in queries:\n print(\"%s %s\"%(solve(n,k)))\n \n \n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n4 2\\n9 3\\n', 'output': '25 56\\n387 489\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/A4'}","problem_id":"vfc_1058","program":"```python\nfrom math import log10\nfrom decimal import Decimal\ndef solve(n,k):\n \n mod=10**k\n x=Decimal(n)\n y=x*(x.log10())%1\n p=str(pow(10,y))\n c=0\n first=''\n for v in p:\n if c==k:\n break\n if v==\".\":\n continue\n first+=v\n c+=1\n last=str(pow(n,n,mod)).zfill(k)\n return (first,last)\nqueries=[]\nfor _ in range(int(input())):\n n,k=list(map(int,input().split( )))\n queries.append((n,k))\nfor n,k in queries:\n print(\"%s %s\"%(solve(n,k)))\n \n \n\n```","inputs":"2\n4 2\n9 3\n","output":"25 56\n387 489\n","actual_output":"25 56\n387 489\n","execution_success":true,"sample_index":165},{"source":"apps","task_type":"verifiable_code","in_source_id":"555","prompt":"Solve the following coding problem using the programming language python:\n\nSherlock Holmes has decided to start a new academy to some of the young lads. He has conducted several tests and finally selected N equally brilliant\n\nstudents.Now he don't know whether to train all the N students or not. Now since Holmes was in a confusion, Watson came up with an idea. He wanted to\n\ntest the obedience of the students. So during the camp, the students were given some Swiss Chocolates as gifts each time when they passed a level.Now some of them have\n\nfinished eating all the chocolates, some of them had some remaining. Now to test their team chemistry and IQ skills, Watson told the lads to arrange themselves in such \na way that, number of chocolates of the ith kid should be equal to the sum of (i-1)th kid and (i-2)th kid. Now they have arranged themselves in an order.\nNow Sherlock announced that he will select the students who have formed the line according to this order. But since there can be many such small groups among the\n\nentire N kids, he will select a sequence of kids such that the length of the sequence is maximized, meanwhile satisfying the above condition \n\n-----Input-----\nFirst line is an integer T which denotes the total number of test cases. Each of the next T lines contains an integer N which denotes, N students. The next \nline contains N spaced integers.where it denotes the order in which the kids arranged themselves. \n\n-----Output-----\nEach line contains an integer which denotes the maximum number of students among the N students who have arranged themselves according the rule said by Watson.It is guaranteed that Holmes will select atleast 1 or 2 students\n\n-----Constraints-----\n- 1 \u2264 T \u2264 10\n- 1 \u2264 N \u2264 10^5\n- 1 \u2264 Each of next N integers \u2264 10^9\n\n-----Subtasks-----\nSubtask #1 : (20 points)\n- 1 \u2264 T \u2264 10\n- 1 \u2264 N\u2264 100\n- 1 \u2264 Each element\u2264 10^3\n\nSubtask 2 : (80 points) \n\n- 1 \u2264 T \u2264 10\n- 1 \u2264 N\u2264 100000\n- 1 \u2264 Each element\u2264 10^9\n\n-----Example-----\nInput:\n2\n5\n2 3 5 1 2\n3\n1 2 3\n\nOutput:\n3\n3\n\n-----Explanation-----\nExample case 1. Here the first kid has 2 chocolates, second has 3 chocolates, third kid has 5 chocolates, which is the sum of first kid's total chocolates \nand second kid's chocolate. Forth student has only 1 chocolate where he did not follow the rule. So the maximum number of kids who arranged themselves in the order was \n3. That is students at index 1 to index 3.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nt = eval(input())\n\nfor i in range(t):\n n = eval(input())\n a = list(map(int, input().split()))\n cnt = 2\n cnt1 = 2\n ll = len(a)\n if ll < 3:\n cnt1 = ll\n else:\n for j in range(2,ll):\n if a[j-1] + a[j-2] == a[j]:\n cnt += 1\n cnt1 = max(cnt1, cnt)\n else:\n cnt1 = max(cnt1, cnt)\n cnt = 2\n print(cnt1) \n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n5\\n2 3 5 1 2\\n3\\n1 2 3\\n', 'output': '3\\n3\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/LOCAPR16/problems/ACDEMY'}","problem_id":"vfc_1062","program":"```python\nt = eval(input())\n\nfor i in range(t):\n n = eval(input())\n a = list(map(int, input().split()))\n cnt = 2\n cnt1 = 2\n ll = len(a)\n if ll < 3:\n cnt1 = ll\n else:\n for j in range(2,ll):\n if a[j-1] + a[j-2] == a[j]:\n cnt += 1\n cnt1 = max(cnt1, cnt)\n else:\n cnt1 = max(cnt1, cnt)\n cnt = 2\n print(cnt1) \n```","inputs":"2\n5\n2 3 5 1 2\n3\n1 2 3\n","output":"3\n3\n","actual_output":"3\n3\n","execution_success":true,"sample_index":166},{"source":"apps","task_type":"verifiable_code","in_source_id":"556","prompt":"Solve the following coding problem using the programming language python:\n\nA robot is initially at $(0,0)$ on the cartesian plane. It can move in 4 directions - up, down, left, right denoted by letter u, d, l, r respectively. More formally:\n- if the position of robot is $(x,y)$ then u makes it $(x,y+1)$\n- if the position of robot is $(x,y)$ then l makes it $(x-1,y)$\n- if the position of robot is $(x,y)$ then d makes it $(x,y-1)$\n- if the position of robot is $(x,y)$ then r makes it $(x+1,y)$\nThe robot is performing a counter-clockwise spiral movement such that his movement can be represented by the following sequence of moves -\nulddrruuulllddddrrrruuuuu\u2026 and so on.\nA single move takes 1 sec. You have to find out the position of the robot on the cartesian plane at $t$ second.\n\n-----Input:-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The first line of each test case contains a single integer $t$.\n\n-----Output:-----\nFor each test case, print two space-separated integers, $(x,y)$ \u2014 the position of the robot.\n\n-----Constraints-----\n- $1 \\leq T \\leq 10^6$\n- $1 \\leq t \\leq 10^{18}$\n\n-----Sample Input:-----\n5\n1\n2\n3\n50\n12233443\n\n-----Sample Output:-----\n0 1\n-1 1\n-1 0\n2 4\n-1749 812\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n\r\n\r\nz = int(input())\r\ni = 0\r\nwhile i < z:\r\n n = int(input())\r\n p = int(n**(0.5))\r\n if p*(p+1) < n:\r\n p += 1\r\n # print(\"P\", p)\r\n x, y = 0, 0\r\n q = 0\r\n flag = True\r\n if p*(p+1) == n:\r\n # print(\"Even steps, nice\")\r\n q = p\r\n else:\r\n # remaining steps\r\n q = p-1\r\n flag = False\r\n if q%2 :\r\n # odd\r\n x -= ((q+1)//2)\r\n y += ((q+1)//2)\r\n else :\r\n x += (q//2)\r\n y -= (q//2)\r\n if flag:\r\n print(x, y)\r\n else:\r\n # remaining steps\r\n l = q*(q+1)\r\n t = p*(p+1)\r\n diff = t-l\r\n \r\n\r\n # print(x, y)\r\n if x < 0:\r\n # left\r\n if n-l >= diff//2:\r\n y *= (-1)\r\n l += (diff//2)\r\n x += (n-l)\r\n else :\r\n y -= (n-l)\r\n \r\n else:\r\n # right\r\n if n-l >= diff//2:\r\n y *= (-1)\r\n y += 1\r\n l += (diff//2)\r\n x -= (n-l)\r\n else :\r\n y += (n-l)\r\n # print(\"Remaining steps: \", n-l)\r\n print(x, y)\r\n i+=1 \n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '5\\n1\\n2\\n3\\n50\\n12233443\\n', 'output': '0 1\\n-1 1\\n-1 0\\n2 4\\n-1749 812\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/DECO2020/problems/DECOSNKE'}","problem_id":"vfc_1066","program":"```python\n\r\n\r\nz = int(input())\r\ni = 0\r\nwhile i < z:\r\n n = int(input())\r\n p = int(n**(0.5))\r\n if p*(p+1) < n:\r\n p += 1\r\n # print(\"P\", p)\r\n x, y = 0, 0\r\n q = 0\r\n flag = True\r\n if p*(p+1) == n:\r\n # print(\"Even steps, nice\")\r\n q = p\r\n else:\r\n # remaining steps\r\n q = p-1\r\n flag = False\r\n if q%2 :\r\n # odd\r\n x -= ((q+1)//2)\r\n y += ((q+1)//2)\r\n else :\r\n x += (q//2)\r\n y -= (q//2)\r\n if flag:\r\n print(x, y)\r\n else:\r\n # remaining steps\r\n l = q*(q+1)\r\n t = p*(p+1)\r\n diff = t-l\r\n \r\n\r\n # print(x, y)\r\n if x < 0:\r\n # left\r\n if n-l >= diff//2:\r\n y *= (-1)\r\n l += (diff//2)\r\n x += (n-l)\r\n else :\r\n y -= (n-l)\r\n \r\n else:\r\n # right\r\n if n-l >= diff//2:\r\n y *= (-1)\r\n y += 1\r\n l += (diff//2)\r\n x -= (n-l)\r\n else :\r\n y += (n-l)\r\n # print(\"Remaining steps: \", n-l)\r\n print(x, y)\r\n i+=1 \n```","inputs":"5\n1\n2\n3\n50\n12233443\n","output":"0 1\n-1 1\n-1 0\n2 4\n-1749 812\n","actual_output":"0 1\n-1 1\n-1 0\n2 4\n-1749 812\n","execution_success":true,"sample_index":167},{"source":"apps","task_type":"verifiable_code","in_source_id":"557","prompt":"Solve the following coding problem using the programming language python:\n\nProf. Sergio Marquina is a mathematics teacher at the University of Spain. Whenever he comes across any good question(with complexity k), he gives that question to students within roll number range i and j.\nAt the start of the semester he assigns a score of 10 to every student in his class if a student submits a question of complexity k, his score gets multiplied by k.\nThis month he gave M questions and he is wondering what will be mean of maximum scores of all the students. He is busy planning a tour of the Bank of Spain for his students, can you help him?\n\n-----Input:-----\n- First-line will contain $T$, the number of test cases. Then the test cases follow. \n- Each test case contains the first line of input, two integers N, M i.e. Number of students in the class and number of questions given in this month.\n- Next M lines contain 3 integers -i,j,k i.e. starting roll number, end roll number, and complexity of the question\n\n-----Output:-----\n- For each test case, output in a single line answer - floor value of Mean of the maximum possible score for all students.\n\n-----Constraints-----\n- $1 \\leq T \\leq 100$\n- $1 \\leq N, M \\leq 105$\n- $1 \\leq i \\leq j \\leq N$\n- $1 \\leq k \\leq 100$\n\n-----Sample Input:-----\n1\n5 3\n1 3 5\n2 5 2\n3 4 7\n\n-----Sample Output:-----\n202\n\n-----EXPLANATION:-----\nInitial score of students will be : [10,10,10,10,10]\nafter solving question 1 scores will be: [50,50,50,10,10]\nafter solving question 2 scores will be: [50,100,100,20,20]\nafter solving question 1 scores will be: [50,100,700,140,20]\nHence after all questions mean of maximum scores will (50+100+700+140+20)/5=202\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\nfor t in range(int(input())):\n n,m=[int(x)for x in input().rstrip().split()]\n s=[]\n for p in range(n):\n s.append(10)\n for c in range(m):\n i,j,k=[int(x)for x in input().rstrip().split()]\n for q in range(i-1,j):\n s[q]=s[q]*k\n print(sum(s)//n)\n \n \n \n \n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n5 3\\n1 3 5\\n2 5 2\\n3 4 7\\n', 'output': '202\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/CMR12121/problems/ELPF'}","problem_id":"vfc_1070","program":"```python\n# cook your dish here\nfor t in range(int(input())):\n n,m=[int(x)for x in input().rstrip().split()]\n s=[]\n for p in range(n):\n s.append(10)\n for c in range(m):\n i,j,k=[int(x)for x in input().rstrip().split()]\n for q in range(i-1,j):\n s[q]=s[q]*k\n print(sum(s)//n)\n \n \n \n \n\n```","inputs":"1\n5 3\n1 3 5\n2 5 2\n3 4 7\n","output":"202\n","actual_output":"202\n","execution_success":true,"sample_index":168},{"source":"apps","task_type":"verifiable_code","in_source_id":"558","prompt":"Solve the following coding problem using the programming language python:\n\nThe city of Siruseri is impeccably planned. The city is divided into a rectangular array of cells with $M$ rows and $N$ columns. Each cell has a metro station. There is one train running left to right and back along each row, and one running top to bottom and back along each column. Each trains starts at some time $T$ and goes back and forth along its route (a row or a column) forever.\nOrdinary trains take two units of time to go from one station to the next. There are some fast trains that take only one unit of time to go from one station to the next. Finally, there are some slow trains that take three units of time to go from one station the next. You may assume that the halting time at any station is negligible.\nHere is a description of a metro system with $3$ rows and $4$ columns:\n$ $\nS(1) F(2) O(2) F(4)\nF(3) . . . .\nS(2) . . . .\nO(2) . . . .\n\n$ $\nThe label at the beginning of each row/column indicates the type of train (F for fast, O for ordinary, S for slow) and its starting time. Thus, the train that travels along row 1 is a fast train and it starts at time $3$. It starts at station ($1$, $1$) and moves right, visiting the stations along this row at times $3, 4, 5$ and $6$ respectively. It then returns back visiting the stations from right to left at times $6, 7, 8$ and $9$. It again moves right now visiting the stations at times $9, 10, 11$ and $12$, and so on. Similarly, the train along column $3$ is an ordinary train starting at time $2$. So, starting at the station ($3$,$1$), it visits the three stations on column $3$ at times $2, 4$ and $6$, returns back to the top of the column visiting them at times $6,8$ and $10$, and so on.\nGiven a starting station, the starting time and a destination station, your task is to determine the earliest time at which one can reach the destination using these trains.\nFor example suppose we start at station ($2$,$3$) at time $8$ and our aim is to reach the station ($1$,$1$). We may take the slow train of the second row at time $8$ and reach ($2$,$4$) at time $11$. It so happens that at time $11$, the fast train on column $4$ is at ($2$,$4$) travelling upwards, so we can take this fast train and reach ($1$,$4$) at time $12$. Once again we are lucky and at time $12$ the fast train on row $1$ is at ($1$,$4$), so we can take this fast train and reach ($1$, $1$) at time $15$. An alternative route would be to take the ordinary train on column $3$ from ($2$,$3$) at time $8$ and reach ($1$,$3$) at time $10$. We then wait there till time $13$ and take the fast train on row $1$ going left, reaching ($1$,$1$) at time $15$. You can verify that there is no way of reaching ($1$,$1$) earlier than that.\n\n-----Input:-----\nThe first line contains two integers $M$ and $N$ indicating the number rows and columns in the metro system. This is followed by $M$ lines, lines $2, 3, \u2026, M+1$, describing the trains along the $M$ rows. The first letter on each line is either F or O or S, indicating whether the train is a fast train, an ordinary train or a slow train. Following this, separated by a blank space, is an integer indicating the time at which this train starts running. The next $N$ lines, lines $M+2, M+3, \u2026, N+M+1$, contain similar descriptions of the trains along the $N$ columns. The last line, line $N+M+2$, contains $5$ integers $a, b, c, d$ and $e$ where ($a$,$b$) is the starting station, $c$ is the starting time and ($d$,$e$) is the destination station.\n\n-----Output:-----\nA single integer indicating the earliest time at which one may reach the destination.\n\n-----Constraints:-----\n- $1 \\leq M, N \\leq 50$.\n- $1 \\leq a, d \\leq M$\n- $1 \\leq b, e \\leq N$\n- $1 \\leq$ all times in input $\\leq 20$\n\n-----Sample Input-----\n3 4\nF 3 \nS 2\nO 2\nS 1\nF 2\nO 2\nF 4\n2 3 8 1 1 \n\n-----Sample Output-----\n15\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfrom queue import PriorityQueue\r\nm,n=list(map(int,input().split()))\r\nrr=[]\r\ncc=[]\r\nspeed={'S':3,'O':2,'F':1}\r\nvisited=set()\r\ndp=[]\r\n\r\ndef qwerty(cur,x,y,f):\r\n\tif f==0:\r\n\t\tgg=rr[x][1]+y*rr[x][0]\r\n\t\twhile gg=0 and nxx=0 and nyy=0 and nxx=0 and nyy math.pi/4 + 0.00001\n \ndef unitVector(p2, p1):\n d0 = p2[0] - p1[0]\n d1 = p2[1] - p1[1]\n d = math.sqrt(d0*d0 + d1*d1)\n if d != 0:\n return [d0/d, d1/d]\n return [0, 0]\n \ndef compVectors(P):\n V = []\n for i in range(1,len(P)):\n v = unitVector(P[i], P[i-1])\n if v[0] == 0 and v[1] == 0:\n return None\n V.append(v)\n return V\n \ndef angle(v2, v1):\n d = v2[0]*v1[0] + v2[1]*v1[1]\n if d > 1:\n d = 1\n if d < -1:\n d = -1\n return math.acos(d)\n \ndef compAngles(V):\n A = []\n for i in range(len(V)-1):\n A.append(angle(V[i+1], V[i]))\n return A\n \ndef updateAngles(i, P, V, A):\n if i-1 >= 0:\n V[i-1] = unitVector(P[i], P[i-1])\n if i+1 < len(P):\n V[i] = unitVector(P[i+1], P[i])\n if i-2 >= 0:\n A[i-2] = angle(V[i-1], V[i-2])\n if i-1 >= 0 and i+1 < len(P):\n A[i-1] = angle(V[i], V[i-1])\n if i+2 < len(P):\n A[i] = angle(V[i+1], V[i])\n \ndef checkMoves(check, P, V, A, filled):\n for i in check:\n if i < 0 or i >= len(P):\n break\n x, y = P[i]\n for j in range(51):\n for k in range(51):\n P[i][0] = j\n P[i][1] = k\n if str(P[i]) in filled:\n continue\n updateAngles(i, P, V, A)\n fixed = True\n if i-2 >= 0:\n if isSharp(A[i-2]):\n fixed = False\n if i-1 >= 0 and i-1 < len(A):\n if isSharp(A[i-1]):\n fixed = False\n if i < len(A):\n if isSharp(A[i]):\n fixed = False\n if fixed:\n return True\n P[i] = [x, y]\n updateAngles(i, P, V, A) \n return False\n \n \ndef canFix(first, last, P, V, A, filled):\n d = last - first\n if d > 2:\n return False\n if d == 2:\n check = [first+2]\n if d == 1:\n check = [first+1, first+2]\n if d == 0:\n check = [first, first+1, first+2]\n if checkMoves(check, P, V, A, filled):\n return True\n return False\n \nT=int(input())\nfor i in range(T):\n N=int(input())\n P=[]\n V=[]\n filled={}\n for i in range(N):\n P.append(list(map(int,input().split())))\n filled[str(P[i])] = 1\n V = compVectors(P)\n A = compAngles(V)\n blunt = True\n first = -1\n last = -1\n for i in range(len(A)):\n if isSharp(A[i]):\n blunt = False\n last = i\n if first < 0:\n first = i\n if blunt:\n print('yes yes')\n else:\n if canFix(first, last, P, V, A, filled):\n print('no yes')\n else:\n print('no no') \n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '5\\n3\\n0 0\\n1 1\\n2 1\\n3\\n0 0\\n1 0\\n6 1\\n3\\n0 0\\n1 0\\n1 1\\n4\\n0 0\\n1 0\\n1 1\\n6 1\\n6\\n0 0\\n1 0\\n1 1\\n2 1\\n2 2\\n3 2\\n', 'output': 'yes yes\\nyes yes\\nno yes\\nno yes\\nno no\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/TAXITURN'}","problem_id":"vfc_1078","program":"```python\nimport math\nimport copy\ntry:\n import psyco\n psyco.full()\nexcept ImportError:\n pass\n \ndef isSharp(ang):\n return ang > math.pi/4 + 0.00001\n \ndef unitVector(p2, p1):\n d0 = p2[0] - p1[0]\n d1 = p2[1] - p1[1]\n d = math.sqrt(d0*d0 + d1*d1)\n if d != 0:\n return [d0/d, d1/d]\n return [0, 0]\n \ndef compVectors(P):\n V = []\n for i in range(1,len(P)):\n v = unitVector(P[i], P[i-1])\n if v[0] == 0 and v[1] == 0:\n return None\n V.append(v)\n return V\n \ndef angle(v2, v1):\n d = v2[0]*v1[0] + v2[1]*v1[1]\n if d > 1:\n d = 1\n if d < -1:\n d = -1\n return math.acos(d)\n \ndef compAngles(V):\n A = []\n for i in range(len(V)-1):\n A.append(angle(V[i+1], V[i]))\n return A\n \ndef updateAngles(i, P, V, A):\n if i-1 >= 0:\n V[i-1] = unitVector(P[i], P[i-1])\n if i+1 < len(P):\n V[i] = unitVector(P[i+1], P[i])\n if i-2 >= 0:\n A[i-2] = angle(V[i-1], V[i-2])\n if i-1 >= 0 and i+1 < len(P):\n A[i-1] = angle(V[i], V[i-1])\n if i+2 < len(P):\n A[i] = angle(V[i+1], V[i])\n \ndef checkMoves(check, P, V, A, filled):\n for i in check:\n if i < 0 or i >= len(P):\n break\n x, y = P[i]\n for j in range(51):\n for k in range(51):\n P[i][0] = j\n P[i][1] = k\n if str(P[i]) in filled:\n continue\n updateAngles(i, P, V, A)\n fixed = True\n if i-2 >= 0:\n if isSharp(A[i-2]):\n fixed = False\n if i-1 >= 0 and i-1 < len(A):\n if isSharp(A[i-1]):\n fixed = False\n if i < len(A):\n if isSharp(A[i]):\n fixed = False\n if fixed:\n return True\n P[i] = [x, y]\n updateAngles(i, P, V, A) \n return False\n \n \ndef canFix(first, last, P, V, A, filled):\n d = last - first\n if d > 2:\n return False\n if d == 2:\n check = [first+2]\n if d == 1:\n check = [first+1, first+2]\n if d == 0:\n check = [first, first+1, first+2]\n if checkMoves(check, P, V, A, filled):\n return True\n return False\n \nT=int(input())\nfor i in range(T):\n N=int(input())\n P=[]\n V=[]\n filled={}\n for i in range(N):\n P.append(list(map(int,input().split())))\n filled[str(P[i])] = 1\n V = compVectors(P)\n A = compAngles(V)\n blunt = True\n first = -1\n last = -1\n for i in range(len(A)):\n if isSharp(A[i]):\n blunt = False\n last = i\n if first < 0:\n first = i\n if blunt:\n print('yes yes')\n else:\n if canFix(first, last, P, V, A, filled):\n print('no yes')\n else:\n print('no no') \n```","inputs":"5\n3\n0 0\n1 1\n2 1\n3\n0 0\n1 0\n6 1\n3\n0 0\n1 0\n1 1\n4\n0 0\n1 0\n1 1\n6 1\n6\n0 0\n1 0\n1 1\n2 1\n2 2\n3 2\n","output":"yes yes\nyes yes\nno yes\nno yes\nno no\n","actual_output":"yes yes\nyes yes\nno yes\nno yes\nno no\n","execution_success":true,"sample_index":170},{"source":"apps","task_type":"verifiable_code","in_source_id":"560","prompt":"Solve the following coding problem using the programming language python:\n\nChef is the judge of a competition. There are two players participating in this competition \u2014 Alice and Bob.\nThe competition consists of N races. For each i (1 \u2264 i \u2264 N), Alice finished the i-th race in Ai minutes, while Bob finished it in Bi minutes. The player with the smallest sum of finish times wins. If this total time is the same for Alice and for Bob, a draw is declared.\nThe rules of the competition allow each player to choose a race which will not be counted towards their total time. That is, Alice may choose an index x and her finish time in the race with this index will be considered zero; similarly, Bob may choose an index y and his finish time in the race with this index will be considered zero. Note that x can be different from y; the index chosen by Alice does not affect Bob's total time or vice versa.\nChef, as the judge, needs to announce the result of the competition. He knows that both Alice and Bob play optimally and will always choose the best option. Please help Chef determine the result!\n\n-----Input-----\n- The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows.\n- The first line of each test case contains a single integer N.\n- The second line contains N space-separated integers A1, A2, ..., AN.\n- The third line contains N space-separated integers B1, B2, ..., BN.\n\n-----Output-----\nFor each test case, print a single line containing the string \"Alice\" if Alice wins, \"Bob\" if Bob wins or \"Draw\" if the result is a draw (without quotes).\n\n-----Constraints-----\n- 1 \u2264 T \u2264 100\n- 2 \u2264 N \u2264 100\n- 1 \u2264 Ai \u2264 1000 for each valid i\n- 1 \u2264 Bi \u2264 1000 for each valid i\n\n-----Example-----\nInput:\n\n3\n5\n3 1 3 3 4\n1 6 2 5 3\n5\n1 6 2 5 3\n3 1 3 3 4\n3\n4 1 3\n2 2 7\n\nOutput:\n\nAlice\nBob\nDraw\n\n-----Explanation-----\nExample case 1: Alice will choose the finish time in the last race to be considered zero, which means her sum of finish times is 3 + 1 + 3 + 3 + 0 = 10, while Bob will choose the finish time of his second race to be considered zero, so his total sum of finish times is 1 + 0 + 2 + 5 + 3 = 11. Since Alice's sum is smaller, she is considered the winner.\nExample case 2: We're dealing with the same situation as in the previous case, but finish times for the players are swapped, so Bob wins this time.\nExample case 3: Alice will choose the finish time of the first race to be considered zero, which means her total time is 0 + 1 + 3 = 4. Bob will choose the finish time of his last race to be considered zero, which makes his total time 2 + 2 + 0 = 4. The competition is considered a draw because both players have equal sums of finish times.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\nfor i in range(int(input())):\n N=int(input())\n ALICE=list(map(int,input().split()))\n BOB=list(map(int,input().split()))\n ALICE[ALICE.index(max(ALICE))]=0\n BOB[BOB.index(max(BOB))]=0\n if sum(ALICE)0):\n c2+=pre[i-1][j]\n h.append(c2)\n pre.append(h)\n\nbs=[0]*((m*n)+10)\n\nfor i in range(1,n+1):\n for j in range(1,m+1):\n for k in range(1,min(m,n)+1):\n if(i-k>=0 and j-k>=0):\n c=pre[i][j]-pre[i-k][j]-pre[i][j-k]+pre[i-k][j-k]\n c=min(c,(k*k)-c)\n bs[c]=max(bs[c],k)\n\nmx=bs[0]\nfor i in range(1,len(bs)):\n mx=max(mx,bs[i])\n bs[i]=mx\n\nQ=int(input())\nq=[int(x) for x in input().split()]\nfor i in range(0,len(q)):\n qr=min(m*n,q[i])\n print(bs[qr])\n\n\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '8 8\\n00101010\\n00010101\\n10101010\\n01010101\\n10101010\\n01010101\\n10101010\\n01010101\\n4\\n1 2 0 1001\\n', 'output': '7\\n8\\n6\\n8\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/SURCHESS'}","problem_id":"vfc_1090","program":"```python\n# cook your dish here\nn,m=map(int,input().split())\nL=[]\nfor i in range(n):\n s=input()\n L.append(s)\n\ncost=[]\nh2=[0]*(m+1)\ncost.append(h2)\nfor i in range(n):\n h=[0]\n for j in range(m):\n if(L[i][j]=='0' and (i+j)%2!=0):\n h.append(1)\n elif(L[i][j]=='1' and (i+j)%2==0):\n h.append(1)\n else:\n h.append(0)\n cost.append(h)\n\npre=[]\nh2=[0]*(m+1)\npre.append(h2)\nfor i in range(1,n+1):\n h=[0]\n c=0\n for j in range(1,m+1):\n c+=cost[i][j]\n c2=c\n if(i>0):\n c2+=pre[i-1][j]\n h.append(c2)\n pre.append(h)\n\nbs=[0]*((m*n)+10)\n\nfor i in range(1,n+1):\n for j in range(1,m+1):\n for k in range(1,min(m,n)+1):\n if(i-k>=0 and j-k>=0):\n c=pre[i][j]-pre[i-k][j]-pre[i][j-k]+pre[i-k][j-k]\n c=min(c,(k*k)-c)\n bs[c]=max(bs[c],k)\n\nmx=bs[0]\nfor i in range(1,len(bs)):\n mx=max(mx,bs[i])\n bs[i]=mx\n\nQ=int(input())\nq=[int(x) for x in input().split()]\nfor i in range(0,len(q)):\n qr=min(m*n,q[i])\n print(bs[qr])\n\n\n\n```","inputs":"8 8\n00101010\n00010101\n10101010\n01010101\n10101010\n01010101\n10101010\n01010101\n4\n1 2 0 1001\n","output":"7\n8\n6\n8\n","actual_output":"7\n8\n6\n8\n","execution_success":true,"sample_index":173},{"source":"apps","task_type":"verifiable_code","in_source_id":"563","prompt":"Solve the following coding problem using the programming language python:\n\nThe land of Programmers Army is surrounded by many islands. A unique number is associated with each island. The king of the islands is a very generous person, he donates a certain amount of gold coins to travelers for visiting each island that they visited to.\nNow, you are appointed as a traveler, who will travel to all these(or some) islands as many times as the Army wants, and you will collect gold coins from the king of the island.\nIn each trip, you will be asked to give the total sum of gold coins you have collected.\n\n-----Input:-----\n- The first line of the input contains a single integer $T$. $T$ denoting the number of test cases. The description of $T$ test cases is as follows.\n- The next line of the input contains a single integer $N$. $N$ denotes the total number of Islands.\n- The next line of the input contains $N$ space-separated integers $A1, A2, A3...An$ where $ith$ number denotes the maximum number of coins that the king of $ith$ island can donate.\n- Next line contains a single integer $Q$. $Q$ denotes the total number of times traveler have to go for the trip.\n- Next $Q$ lines contains, two space-separated integers $Q1,Q2$ denoting the start and end number of islands, i.e. traveler will start the trip from $Q1th$ island and will go till $Q2th$ island, in each trip.\nNote: islands are numbered from $1$ to $N$.\n\n-----Output:-----\n- For each trip print the total number of gold coins, traveler will collect(each on a new line).\n\n-----Constraints:-----\n- $1 \\leq T \\leq 100$\n- $1 \\leq N \\leq 10^4$\n- $1 \\leq A1, A2, A3...An \\leq 10^5$\n- $1 \\leq Q \\leq 10^3$\n- $1 \\leq Q1,Q2 \\leq N$\n\n-----Sample Input:-----\n1\n4\n10 2 5 50\n2\n1 3\n2 4\n\n-----Sample Output:-----\n17\n57\n\n-----Explanation:-----\n- \nIn 1st Trip, traveler will go from 1st Island to 3rd Island, hence the total number of coins traveler can collect is 10+2+5 = 17\n- \nIn 2 d Trip, traveler will go from 2nd Island to 4th Island, hence the total number of coins traveler can collect is 2+5+50 = 57\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\nfor i in range(int(input())):\n N = int(input())\n l = list(map(int, input().split()))\n for j in range(int(input())):\n q1, q2 = map(int, input().split())\n temp = l[q1 - 1 : q2]\n print(sum(temp))\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n4\\n10 2 5 50\\n2\\n1 3\\n2 4\\n', 'output': '17\\n57\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/ARYS2020/problems/GOLDTRIP'}","problem_id":"vfc_1094","program":"```python\n# cook your dish here\nfor i in range(int(input())):\n N = int(input())\n l = list(map(int, input().split()))\n for j in range(int(input())):\n q1, q2 = map(int, input().split())\n temp = l[q1 - 1 : q2]\n print(sum(temp))\n```","inputs":"1\n4\n10 2 5 50\n2\n1 3\n2 4\n","output":"17\n57\n","actual_output":"17\n57\n","execution_success":true,"sample_index":174},{"source":"apps","task_type":"verifiable_code","in_source_id":"564","prompt":"Solve the following coding problem using the programming language python:\n\n-----Coal Company -----\n\nThe Tunisian Coal Mining company uses a train to ferry out coal blocks from its coal mines. The train has N containers numbered from 1 to N which need to\n\nbe filled with blocks of coal. Assume there are infinite coal blocks. The containers are arranged in increasing order of capacity, and the ith container\n\nhas capacity i. Every container has a specific loading cost ci. The workers fill the containers in rounds. In every round, they choose a subset of\n\ncontainers and load them with coal blocks. This subset should be such that each subsequent container chosen in a round should be more spacious than the\n\nprevious one. Also, the difference in loading cost of consecutive containers should be at least K.\n\n\n\nWhat is the least number of rounds in which all containers can be filled?\n\n\n\n-----\nInput\n-----\n\nThe first line contains the number of test cases T. T test cases follow.\n\nEach case contains an integer N and K on the first line, followed by integers c1,...,cn on the second line.\n\n\n\n1 <= T <= 100\n\n1 <= N <= 300\n\n1 <= ci <= 1000\n\n1 <= K <= 1000\n\n\n\n-----\nOutput\n-----\n\nOutput T lines, one for each test case, containing the minimum number of rounds in which all containers could be filled.\n\n-----\nExample\n-----\n\nInput:\n\n2\n\n3 2\n\n5 4 7\n\n5 1\n\n5 3 4 5 6\n\n\n\nOutput:\n\n2\n\n1\n\n\n\n\n\n\n\nExplanation:\n\nFor the first example, workers can fill the containers of cost 5 and 7 in the first round and the container with cost 4 in the next round. Note that the\n\ncontainers with cost 5 and 4 cannot be filled consecutively because the loading costs should differ by at least K (which is 2). Also, the containers cannot\n\nbe filled in order 5, 7, 4 in one round because the containers filled in a round should be in increasing capacity.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfor _ in range(int(input())):\n n,k=list(map(int,input().split()))\n c=list(map(int,input().split()))\n count=1\n for i in range(n):\n if i+1=k or c[i+1]-c[i]>=k:\n continue\n else:\n count+=1\n c[i],c[i+1]=c[i+1],c[i]\n print(count)\n \n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n3 2\\n5 4 7\\n5 1\\n5 3 4 5 6\\n', 'output': '2\\n1\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/COMS1501/problems/CM1503'}","problem_id":"vfc_1098","program":"```python\nfor _ in range(int(input())):\n n,k=list(map(int,input().split()))\n c=list(map(int,input().split()))\n count=1\n for i in range(n):\n if i+1=k or c[i+1]-c[i]>=k:\n continue\n else:\n count+=1\n c[i],c[i+1]=c[i+1],c[i]\n print(count)\n \n\n```","inputs":"2\n3 2\n5 4 7\n5 1\n5 3 4 5 6\n","output":"2\n1\n","actual_output":"2\n1\n","execution_success":true,"sample_index":175},{"source":"apps","task_type":"verifiable_code","in_source_id":"565","prompt":"Solve the following coding problem using the programming language python:\n\n\"If you didn't copy assignments during your engineering course, did you even do engineering?\"\nThere are $Q$ students in Chef's class. Chef's teacher has given the students a simple assignment:\nWrite a function that takes as arguments an array $A$ containing only unique elements and a number $X$ guaranteed to be present in the array and returns the ($1$-based) index of the element that is equal to $X$.\nThe teacher was expecting a linear search algorithm, but since Chef is such an amazing programmer, he decided to write the following binary search function:\ninteger binary_search(array a, integer n, integer x):\ninteger low, high, mid\nlow := 1\nhigh := n\nwhile low \u2264 high:\nmid := (low + high) / 2\nif a[mid] == x:\nbreak\nelse if a[mid] is less than x:\nlow := mid+1\nelse:\nhigh := mid-1\nreturn mid\n\nAll of Chef's classmates have copied his code and submitted it to the teacher.\nChef later realised that since he forgot to sort the array, the binary search algorithm may not work. Luckily, the teacher is tired today, so she asked Chef to assist her with grading the codes. Each student's code is graded by providing an array $A$ and an integer $X$ to it and checking if the returned index is correct. However, the teacher is lazy and provides the exact same array to all codes. The only thing that varies is the value of $X$.\nChef was asked to type in the inputs. He decides that when typing in the input array for each code, he's not going to use the input array he's given, but an array created by swapping some pairs of elements of this original input array. However, he cannot change the position of the element that's equal to $X$ itself, since that would be suspicious.\nFor each of the $Q$ students, Chef would like to know the minimum number of swaps required to make the algorithm find the correct answer.\n\n-----Input-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The first line of each test case contains two space-separated integers $N$ and $Q$ denoting the number of elements in the array and the number of students.\n- The second line contains $N$ space-separated integers $A_1, A_2, \\dots, A_N$.\n- The following $Q$ lines describe queries. Each of these lines contains a single integer $X$.\n\n-----Output-----\nFor each query, print a single line containing one integer \u2014 the minimum required number of swaps, or $-1$ if it is impossible to make the algorithm find the correct answer. (Do you really think Chef can fail?)\n\n-----Constraints-----\n- $1 \\le T \\le 10$\n- $1 \\le N, Q \\le 10^5$\n- $1 \\le A_i \\le 10^9$ for each valid $i$\n- $1 \\le X \\le 10^9$\n- all elements of $A$ are pairwise distinct\n- for each query, $X$ is present in $A$\n- sum of $N$ over all test cases $\\le 5\\cdot10^5$\n- sum of $Q$ over all test cases $\\le 5\\cdot10^5$\n\n-----Subtasks-----\nSubtask #1 (20 points): $1 \\le N \\le 10$\nSubtask #2 (30 points):\n- $1 \\le A_i \\le 10^6$ for each valid $i$\n- $1 \\le X \\le 10^6$\nSubtask #3 (50 points): original constraints\n\n-----Example Input-----\n1\n7 7\n3 1 6 7 2 5 4\n1\n2\n3\n4\n5\n6\n7\n\n-----Example Output-----\n0\n1\n1\n2\n1\n0\n0\n\n-----Explanation-----\nExample case 1:\n- Query 1: The algorithm works without any swaps.\n- Query 2: One solution is to swap $A_2$ and $A_4$.\n- Query 3: One solution is to swap $A_2$ and $A_6$.\n- Query 4: One solution is to swap $A_2$ with $A_4$ and $A_5$ with $A_6$.\n- Query 5: One solution is to swap $A_2$ and $A_4$.\n- Query 6: The algorithm works without any swaps.\n- Query 7: The algorithm works without any swaps.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\ndef f(a,y,index,sorted_pos):\n #print(a,y,index,sorted_pos)\n n=len(a)\n low=0\n high=n-1\n L,R=0,0\n l,r=0,0\n while(low<=high):\n mid=(low+high)//2\n #print(low,high,mid)\n if(a[mid]== y):\n break\n elif(mid > index[y]):\n high=mid-1\n L+=1\n #print(\"L\")\n if(a[mid] y):\n r+=1\n #print(\"r\")\n x=sorted_pos[y]\n #print(L,R,l,r,x,n-x-1)\n if(R>x or L> n-x-1):\n print(\"-1\")\n else:\n print(max(l,r))\n\n\ndef fun():\n test=int(input())\n for t in range(test):\n n,q=list(map(int,input().split()))\n arr=list(map(int,input().split()))\n index= dict()\n for i in range(n):\n index[arr[i]]=i\n sorted_pos=dict()\n a=sorted(arr)\n for i in range(n):\n sorted_pos[a[i]]=i\n for x in range(q):\n y=int(input())\n f(arr,y,index,sorted_pos)\n\nfun()\n\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n7 7\\n3 1 6 7 2 5 4\\n1\\n2\\n3\\n4\\n5\\n6\\n7\\n', 'output': '0\\n1\\n1\\n2\\n1\\n0\\n0\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/FAKEBS'}","problem_id":"vfc_1102","program":"```python\ndef f(a,y,index,sorted_pos):\n #print(a,y,index,sorted_pos)\n n=len(a)\n low=0\n high=n-1\n L,R=0,0\n l,r=0,0\n while(low<=high):\n mid=(low+high)//2\n #print(low,high,mid)\n if(a[mid]== y):\n break\n elif(mid > index[y]):\n high=mid-1\n L+=1\n #print(\"L\")\n if(a[mid] y):\n r+=1\n #print(\"r\")\n x=sorted_pos[y]\n #print(L,R,l,r,x,n-x-1)\n if(R>x or L> n-x-1):\n print(\"-1\")\n else:\n print(max(l,r))\n\n\ndef fun():\n test=int(input())\n for t in range(test):\n n,q=list(map(int,input().split()))\n arr=list(map(int,input().split()))\n index= dict()\n for i in range(n):\n index[arr[i]]=i\n sorted_pos=dict()\n a=sorted(arr)\n for i in range(n):\n sorted_pos[a[i]]=i\n for x in range(q):\n y=int(input())\n f(arr,y,index,sorted_pos)\n\nfun()\n\n\n```","inputs":"1\n7 7\n3 1 6 7 2 5 4\n1\n2\n3\n4\n5\n6\n7\n","output":"0\n1\n1\n2\n1\n0\n0\n","actual_output":"0\n1\n1\n2\n1\n0\n0\n","execution_success":true,"sample_index":176},{"source":"apps","task_type":"verifiable_code","in_source_id":"566","prompt":"Solve the following coding problem using the programming language python:\n\nChef likes strings a lot but he likes palindromic strings more. Today, Chef has two strings A and B, each consisting of lower case alphabets.\n\nChef is eager to know whether it is possible to choose some non empty strings s1 and s2 where s1 is a substring of A, s2 is a substring of B such that s1 + s2 is a palindromic string. Here '+' denotes the concatenation between the strings.\nNote:\nA string is a palindromic string if it can be read same both forward as well as backward. To know more about palindromes click here.\n\n-----Input-----\n- First line of input contains a single integer T denoting the number of test cases.\n- For each test case:\n\t\n- First line contains the string A\n- Second line contains the string B.\n\n-----Output-----\nFor each test case, Print \"Yes\" (without quotes) if it possible to choose such strings s1 & s2. Print \"No\" (without quotes) otherwise.\n\n\n-----Constraints-----\n- 1 \u2264 T \u2264 10 \n- 1 \u2264 |A|, |B| \u2264 1000 \n\n-----Subtasks-----\n- Subtask 1: 1 \u2264 |A|, |B| \u2264 10 : ( 40 pts )\n- Subtask 2: 1 \u2264 |A|, |B| \u2264 1000 : ( 60 pts )\n\n-----Example-----Input\n3\nabc\nabc\na\nb\nabba\nbaab\n\nOutput\nYes\nNo\nYes\n\n-----Explanation-----\n- Test 1: One possible way of choosing s1 & s2 is s1 = \"ab\", s2 = \"a\" such that s1 + s2 i.e \"aba\" is a palindrome.\n- Test 2: There is no possible way to choose s1 & s2 such that s1 + s2 is a palindrome.\n- Test 3: You can figure it out yourself.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nt=int(input())\nfor _ in range (t):\n str1=input()\n str2=input()\n res='No'\n for i in str1:\n if i in str2:\n res='Yes'\n break\n print(res)\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\nabc\\nabc\\na\\nb\\nabba\\nbaab\\n', 'output': 'Yes\\nNo\\nYes\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/STRPALIN'}","problem_id":"vfc_1106","program":"```python\nt=int(input())\nfor _ in range (t):\n str1=input()\n str2=input()\n res='No'\n for i in str1:\n if i in str2:\n res='Yes'\n break\n print(res)\n\n```","inputs":"3\nabc\nabc\na\nb\nabba\nbaab\n","output":"Yes\nNo\nYes\n","actual_output":"Yes\nNo\nYes\n","execution_success":true,"sample_index":177},{"source":"apps","task_type":"verifiable_code","in_source_id":"567","prompt":"Solve the following coding problem using the programming language python:\n\nChef's new hobby is painting, but he learned the fact that it's not easy to paint 2D pictures in a hard way, after wasting a lot of canvas paper, paint and of course time. From now on, he decided to paint 1D pictures only.\nChef's canvas is N millimeters long and is initially all white. For simplicity, colors will be represented by an integer between 0 and 105. 0 indicates white. The picture he is envisioning is also N millimeters long and the ith millimeter consists purely of the color Ci. Unfortunately, his brush isn't fine enough to paint every millimeter one by one. The brush is 3 millimeters wide and so it can only paint three millimeters at a time with the same color. Painting over the same place completely replaces the color by the new one. Also, Chef has lots of bottles of paints of each color, so he will never run out of paint of any color.\nChef also doesn't want to ruin the edges of the canvas, so he doesn't want to paint any part beyond the painting. This means, for example, Chef cannot paint just the first millimeter of the canvas, or just the last two millimeters, etc.\nHelp Chef by telling him whether he can finish the painting or not with these restrictions.\n\n-----Input-----\nThe first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.\nThe first line of each test case contains a single integer N. The second line contains N space-separated integers C1, C2, ..., CN denoting the colors of Chef's painting.\n\n-----Output-----\nFor each test case, output a single line containing either \u201cYes\u201d or \u201cNo\u201d (without quotes), denoting whether Chef can finish the painting or not.\n\n-----Constraints-----\n- 1 \u2264 T \u2264 105\n- 3 \u2264 N \u2264 105\n- The sum of the Ns over all the test cases in a single test file is \u2264 5\u00d7105\n- 1 \u2264 Ci \u2264 105\n\n-----Example-----\nInput:3\n4\n1 5 5 5\n4\n1 1 1 5\n3\n5 5 2\nOutput:Yes\nYes\nNo\n\n-----Explanation-----\nExample case 1. Chef's canvas initially contains the colors [0,0,0,0]. Chef can finish the painting by first painting the first three millimeters with color 1, so the colors become [1,1,1,0], and then the last three millimeters with color 5 so that it becomes [1,5,5,5].\nExample case 2. Chef's canvas initially contains the colors [0,0,0,0]. Chef can finish the painting by first painting the last three millimeters by color 5 so the colors become [0,5,5,5], and then the first three millimeters by color 1 so it becomes [1,1,1,5].\nExample case 3. In this test case, Chef can only paint the painting as a whole, so all parts must have the same color, and the task is impossible.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\nimport sys\nimport math\n\ndef main(arr):\n for i in range(1,len(arr)-1):\n if arr[i]==arr[i-1] and arr[i]==arr[i+1]:\n return \"Yes\"\n return \"No\"\n\ntest=int(input())\nfor _ in range(test):\n b=int(input())\n arr=list(map(int,input().split()))\n print(main(arr))\n\n \n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\n4\\n1 5 5 5\\n4\\n1 1 1 5\\n3\\n5 5 2\\n\\n', 'output': 'Yes\\nYes\\nNo\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/MAKEART'}","problem_id":"vfc_1110","program":"```python\n# cook your dish here\nimport sys\nimport math\n\ndef main(arr):\n for i in range(1,len(arr)-1):\n if arr[i]==arr[i-1] and arr[i]==arr[i+1]:\n return \"Yes\"\n return \"No\"\n\ntest=int(input())\nfor _ in range(test):\n b=int(input())\n arr=list(map(int,input().split()))\n print(main(arr))\n\n \n```","inputs":"3\n4\n1 5 5 5\n4\n1 1 1 5\n3\n5 5 2\n\n","output":"Yes\nYes\nNo\n","actual_output":"Yes\nYes\nNo\n","execution_success":true,"sample_index":178},{"source":"apps","task_type":"verifiable_code","in_source_id":"568","prompt":"Solve the following coding problem using the programming language python:\n\nKefaa has developed a novel decomposition of a tree. He claims that this decomposition solves many difficult problems related to trees. However, he doesn't know how to find it quickly, so he asks you to help him.\nYou are given a tree with $N$ vertices numbered $1$ through $N$. Let's denote an edge between vertices $u$ and $v$ by $(u, v)$. The triple-tree decomposition is a partition of edges of the tree into unordered triples of edges $(a, b), (a, c), (a, d)$ such that $a \\neq b \\neq c \\neq d$. Each edge must belong to exactly one triple.\nHelp Kefaa with this problem \u2014 find a triple-tree decomposition of the given tree or determine that no such decomposition exists.\n\n-----Input-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The first line of each test case contains a single integer $N$.\n- Each of the following $N-1$ lines contains two space-separated integers $u$ and $v$ describing an edge between vertices $u$ and $v$ of the tree.\n\n-----Output-----\n- For each test case, print a line containing the string \"YES\" if a triple-tree decomposition of the given tree exists or \"NO\" otherwise.\n- If it exists, print $\\frac{N-1}{3}$ more lines describing a decomposition.\n- Each of these lines should contain four space-separated integers $a$, $b$, $c$ and $d$ describing a triple of edges $(a, b), (a, c), (a, d)$.\nIf more than one triple-tree decomposition exists, you may output any one.\n\n-----Constraints-----\n- $1 \\le T \\le 100$\n- $2 \\le N \\le 2 \\cdot 10^5$\n- $1 \\le u, v \\le N$\n- the sum of $N$ over all test cases does not exceed $2 \\cdot 10^5$\n\n-----Subtasks-----\nSubtask #1 (20 points): $2 \\le N \\le 10$\nSubtask #2 (30 points):$2 \\le N \\le 5000$ and the sum of $N$ overall testcases doesn't exceed $5000$\nSubtask #3 (50 points): original constraints\n\n-----Example Input-----\n2\n4\n1 2\n1 3\n1 4\n7\n1 2\n2 3\n1 4\n4 5\n1 6\n6 7\n\n-----Example Output-----\nYES\n1 2 3 4\nNO\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n\ntest=int(input())\nfor t in range(test):\n n= int(input())\n\n adj=[[] for i in range(n+1)]\n\n for _ in range(n-1):\n a,b=list(map(int,input().split()))\n adj[a].append(b)\n adj[b].append(a)\n \n\n #print(adj)\n root=1\n q,s=[root],set([root])\n\n for x in q:\n adj[x]= [p for p in adj[x] if p not in s]\n q.extend(adj[x])\n s.update(adj[x])\n\n #print(adj)\n ans=True\n if(n<4):\n ans=False\n for i in range(n+1):\n if(len(adj[i]) %3!=0):\n ans=False\n if(ans):\n print(\"YES\")\n for i in range(n+1):\n while(len(adj[i])):\n print(i,adj[i][0],adj[i][1],adj[i][2])\n adj[i].pop(0)\n adj[i].pop(0)\n adj[i].pop(0)\n else:\n print(\"NO\")\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n4\\n1 2\\n1 3\\n1 4\\n7\\n1 2\\n2 3\\n1 4\\n4 5\\n1 6\\n6 7\\n', 'output': 'YES\\n1 2 3 4\\nNO\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/TREE3'}","problem_id":"vfc_1114","program":"```python\n\ntest=int(input())\nfor t in range(test):\n n= int(input())\n\n adj=[[] for i in range(n+1)]\n\n for _ in range(n-1):\n a,b=list(map(int,input().split()))\n adj[a].append(b)\n adj[b].append(a)\n \n\n #print(adj)\n root=1\n q,s=[root],set([root])\n\n for x in q:\n adj[x]= [p for p in adj[x] if p not in s]\n q.extend(adj[x])\n s.update(adj[x])\n\n #print(adj)\n ans=True\n if(n<4):\n ans=False\n for i in range(n+1):\n if(len(adj[i]) %3!=0):\n ans=False\n if(ans):\n print(\"YES\")\n for i in range(n+1):\n while(len(adj[i])):\n print(i,adj[i][0],adj[i][1],adj[i][2])\n adj[i].pop(0)\n adj[i].pop(0)\n adj[i].pop(0)\n else:\n print(\"NO\")\n\n```","inputs":"2\n4\n1 2\n1 3\n1 4\n7\n1 2\n2 3\n1 4\n4 5\n1 6\n6 7\n","output":"YES\n1 2 3 4\nNO\n","actual_output":"YES\n1 2 3 4\nNO\n","execution_success":true,"sample_index":179},{"source":"apps","task_type":"verifiable_code","in_source_id":"569","prompt":"Solve the following coding problem using the programming language python:\n\nSandu, a teacher in Chefland introduced his students to a new sequence i.e.\n0,1,0,1,2,0,1,2,3,0,1,2,3,4........\nThe Sequence starts from 0 and increases by one till $i$(initially i equals to 1), then repeat itself with $i$ changed to $i+1$\nStudents being curious about the sequence asks the Nth element of the sequence. Help Sandu to answer the Students\n\n-----Input:-----\n- The first-line will contain $T$, the number of test cases. Then the test case follows. \n- Each test case contains a single numbers N.\n\n-----Output:-----\nPrint the Nth element of the sequence\n\n-----Constraints-----\n- $1 \\leq T \\leq 1000$\n- $1 \\leq N \\leq 10^{18}$\n\n-----Sample Input:-----\n5\n8\n9\n20\n32\n109\n\n-----Sample Output:-----\n2\n3\n5\n4\n4\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfrom math import sqrt\n\nfor _ in range(int(input())):\n n = int(input())\n\n x = int(sqrt(2 * n))\n\n while x * (x+1) // 2 <= n:\n x += 1\n\n while x * (x+1) // 2 > n:\n x -= 1\n\n n -= x * (x+1) // 2\n\n print(n)\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '5\\n8\\n9\\n20\\n32\\n109\\n', 'output': '2\\n3\\n5\\n4\\n4\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/ENCD2020/problems/ECAPR203'}","problem_id":"vfc_1118","program":"```python\nfrom math import sqrt\n\nfor _ in range(int(input())):\n n = int(input())\n\n x = int(sqrt(2 * n))\n\n while x * (x+1) // 2 <= n:\n x += 1\n\n while x * (x+1) // 2 > n:\n x -= 1\n\n n -= x * (x+1) // 2\n\n print(n)\n\n```","inputs":"5\n8\n9\n20\n32\n109\n","output":"2\n3\n5\n4\n4\n","actual_output":"2\n3\n5\n4\n4\n","execution_success":true,"sample_index":180},{"source":"apps","task_type":"verifiable_code","in_source_id":"570","prompt":"Solve the following coding problem using the programming language python:\n\nAyu loves distinct letter sequences ,a distinct letter sequence is defined by a sequence of small case english alphabets such that no character appears more then once.\nBut however there are two phrases that she doesn't like these phrases are \"kar\" and \"shi\" and she is given a sequence of distinct characters and she wonders how many such sequences she can form using all the characters such that these phrases don't occur.\nHelp her finding the number of such sequences.\nNew Year Gift - It is guaranteed that for sequences of length greater then 6 letters k,a,r,s,h,i will be present(we thought of being generous, thank us later :)).\n\n-----Input:-----\n- First line will contain $T$, number of testcases. Then the testcases follow. \n- Each line consists of a string $S$ (3<=s.length<=18) of distinct characters.\n\n-----Output:-----\nPrint the number of sequences that can be formed by permuting all the characters such that phrases \"kar\" and \"shi\" don't occur.\n\n-----Constraints-----\n- $1 \\leq T \\leq 10$\n- $3 \\leq S.length \\leq 18$\n\n-----Sample Input:-----\n2\nkarp\nabcd\n\n-----Sample Output:-----\n22\n24\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\r\nfrom collections import deque, defaultdict\r\nfrom math import sqrt, ceil,factorial\r\nimport sys\r\nimport copy\r\ndef get_array(): return list(map(int, sys.stdin.readline().strip().split()))\r\ndef get_ints(): return map(int, sys.stdin.readline().strip().split())\r\ndef input(): return sys.stdin.readline().strip()\r\n\r\nfor _ in range(int(input())):\r\n\r\n s=input()\r\n if len(s)>6:\r\n ans=0\r\n rem=len(s)-6\r\n ans+=factorial(len(s))\r\n ans-=2*(factorial(len(s)-2))\r\n ans+=factorial(rem+2)\r\n print(ans)\r\n\r\n else:\r\n if 'k' in s and 'r' in s and 'a' in s and 's' in s and 'h' in s and 'i' in s:\r\n ans = 0\r\n rem = len(s) - 6\r\n ans += factorial(len(s))\r\n ans -= 2 * (factorial(len(s) - 2))\r\n ans += factorial(rem + 2)\r\n print(ans)\r\n else:\r\n if 'k' in s and 'a' in s and 'r' in s:\r\n ans=0\r\n rem=len(s)-3\r\n ans+=factorial(len(s))\r\n ans-=factorial(rem+1)\r\n print(ans)\r\n continue\r\n if 's' in s and 'h' in s and 'i' in s:\r\n ans = 0\r\n rem = len(s) - 3\r\n ans += factorial(len(s))\r\n ans -= factorial(rem + 1)\r\n print(ans)\r\n continue\r\n\r\n print(factorial(len(s)))\r\n\r\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\nkarp\\nabcd\\n', 'output': '22\\n24\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/INDC2021/problems/AYUKAR'}","problem_id":"vfc_1122","program":"```python\n# cook your dish here\r\nfrom collections import deque, defaultdict\r\nfrom math import sqrt, ceil,factorial\r\nimport sys\r\nimport copy\r\ndef get_array(): return list(map(int, sys.stdin.readline().strip().split()))\r\ndef get_ints(): return map(int, sys.stdin.readline().strip().split())\r\ndef input(): return sys.stdin.readline().strip()\r\n\r\nfor _ in range(int(input())):\r\n\r\n s=input()\r\n if len(s)>6:\r\n ans=0\r\n rem=len(s)-6\r\n ans+=factorial(len(s))\r\n ans-=2*(factorial(len(s)-2))\r\n ans+=factorial(rem+2)\r\n print(ans)\r\n\r\n else:\r\n if 'k' in s and 'r' in s and 'a' in s and 's' in s and 'h' in s and 'i' in s:\r\n ans = 0\r\n rem = len(s) - 6\r\n ans += factorial(len(s))\r\n ans -= 2 * (factorial(len(s) - 2))\r\n ans += factorial(rem + 2)\r\n print(ans)\r\n else:\r\n if 'k' in s and 'a' in s and 'r' in s:\r\n ans=0\r\n rem=len(s)-3\r\n ans+=factorial(len(s))\r\n ans-=factorial(rem+1)\r\n print(ans)\r\n continue\r\n if 's' in s and 'h' in s and 'i' in s:\r\n ans = 0\r\n rem = len(s) - 3\r\n ans += factorial(len(s))\r\n ans -= factorial(rem + 1)\r\n print(ans)\r\n continue\r\n\r\n print(factorial(len(s)))\r\n\r\n\n```","inputs":"2\nkarp\nabcd\n","output":"22\n24\n","actual_output":"22\n24\n","execution_success":true,"sample_index":181},{"source":"apps","task_type":"verifiable_code","in_source_id":"572","prompt":"Solve the following coding problem using the programming language python:\n\nToday is Chef's birthday. His mom has surprised him with truly fruity gifts: 2 fruit baskets. The first basket contains N apples, and the second one contains M oranges. Chef likes apples and oranges very much but he likes them equally, and therefore, wants to have the minimum possible difference between the number of apples and oranges he has. To do so, he can purchase 1 apple or 1 orange by paying exactly 1 gold coin (that's some expensive fruit, eh?). Chef can purchase fruits at most K times (as he has only K gold coins in his pocket) to make the difference the minimum possible.\nOur little Chef is busy in celebrating his birthday to the fullest, and therefore, he has handed this job to his best friend \u2014 you. Can you help him by finding the minimum possible difference he can achieve between the number of apples and orange he owns?\n\n-----Input-----\nThe first line of input contains a single integer T denoting the number of test cases. The first and only line of each test case contains 3 space separated integers \u2014 N, M and K \u2014 denoting the number of apples, number of oranges, and number of gold coins our little Chef has.\n\n-----Output-----\nFor each test case, output the minimum possible difference between the number of apples and oranges that Chef can achieve.\n\n-----Constraints-----\n- 1 \u2264 T \u2264 100\n- 1 \u2264 N, M, K \u2264 100\n\n-----Example-----Input\n3\n3 4 1\n5 2 1\n3 4 3\n\nOutput\n0\n2\n0\n\n-----Explanation-----\n- Test 1: Chef will buy 1 apple by paying 1 gold coin and will have equal number of apples and oranges. \n- Test 2: Chef will buy 1 orange by paying 1 gold coin and will have 5 apples and 3 oranges.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfor _ in range(int(input())):\n a,o,g=map(int,input().split())\n while g>0:\n if a0:\n if a sum(B).\n\nNOTE 1 :If there is a tie, then compare with segment's length and return segment which has maximum length \n\nNOTE 2: If there is still a tie, then return the segment with minimum starting index.\n\n-----Input-----\n\nThe first line contains the number of test cases. Each test cases contains an integer N. next line consists of N integers, the elements of the array.\n\n-----Output-----\n\nPrint out the maximum sub-array as stated above.\n\n-----Constraints-----\n- 1 \u2264 T \u2264 100 \n- 1 \u2264 N \u2264 105 \n- 1 \u2264 Ai \u2264 105 \n\n-----Example-----\nInput:\n\n1\n6\n1 2 5 -7 2 3\n\nOutput:\n\n1 2 5\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfor t in range(int(input())):\n n=int(input())\n a=list(map(int,input().split()))\n s=0\n l=[]\n for i in range(n):\n if (a[i]<0):\n e=i\n ss=sum(a[s:e])\n l.append((ss,e-s,n-s))\n s=i+1\n e=n\n ss=sum(a[s:e])\n l.append((ss,e-s,n-s))\n x=max(l)\n s=n-x[2]\n e=x[1]+s\n for i in range(s,e):\n print(a[i], end=' ')\n print(\"\")\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n6\\n1 2 5 -7 2 3\\n', 'output': '1 2 5\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/CDBU2015/problems/CDBSTR06'}","problem_id":"vfc_1138","program":"```python\nfor t in range(int(input())):\n n=int(input())\n a=list(map(int,input().split()))\n s=0\n l=[]\n for i in range(n):\n if (a[i]<0):\n e=i\n ss=sum(a[s:e])\n l.append((ss,e-s,n-s))\n s=i+1\n e=n\n ss=sum(a[s:e])\n l.append((ss,e-s,n-s))\n x=max(l)\n s=n-x[2]\n e=x[1]+s\n for i in range(s,e):\n print(a[i], end=' ')\n print(\"\")\n```","inputs":"1\n6\n1 2 5 -7 2 3\n","output":"1 2 5\n","actual_output":"1 2 5 \n","execution_success":true,"sample_index":185},{"source":"apps","task_type":"verifiable_code","in_source_id":"575","prompt":"Solve the following coding problem using the programming language python:\n\nChef found a strange string yesterday - a string of signs s, where each sign is either a '<', '=' or a '>'. Let N be the length of this string. Chef wants to insert N + 1 positive integers into this sequence and make it valid. A valid sequence is a sequence where every sign is preceded and followed by an integer, and the signs are correct. That is, if a sign '<' is preceded by the integer a and followed by an integer b, then a should be less than b. Likewise for the other two signs as well. \nChef can take some positive integers in the range [1, P] and use a number in the range as many times as he wants.\nHelp Chef find the minimum possible P with which he can create a valid sequence.\n\n-----Input-----\nThe first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.\nThe only line of each test case contains the string of signs s, where each sign is either '<', '=' or a '>'. \n\n-----Output-----\nFor each test case, output a single line containing an integer corresponding to the minimum possible P. \n\n-----Constraints-----\n- 1 \u2264 T, |s| \u2264 105\n- 1 \u2264 Sum of |s| over all test cases in a single test file \u2264 106\n\n-----Subtasks-----\nSubtask #1 (30 points)\n- 1 \u2264 T, |s| \u2264 103\n- 1 \u2264 Sum of |s| over all test cases in a single test file \u2264 104\n\nSubtask #2 (70 points)\n- Original constraints\n\n-----Example-----\nInput:\n4\n<<<\n<><\n<=>\n<=<\n\nOutput:\n4\n2\n2\n3\n\n-----Explanation-----\nHere are some possible valid sequences which can be formed with the minimum P for each of the test cases:\n1 < 2 < 3 < 4\n1 < 2 > 1 < 2\n1 < 2 = 2 > 1\n1 < 2 = 2 < 3\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfor _ in range(int(input())):\n st=input().replace(\"=\",\"\")\n if not len(st):print(1)\n else:\n cu=mx=1\n for j in range(1,len(st)):\n if st[j]==st[j-1]:cu+=1\n else:mx=max(mx,cu);cu=1\n print(max(mx+1,cu+1))\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '4\\n<<<\\n<><\\n<=>\\n<=<\\n', 'output': '4\\n2\\n2\\n3\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/CHEFSIGN'}","problem_id":"vfc_1142","program":"```python\nfor _ in range(int(input())):\n st=input().replace(\"=\",\"\")\n if not len(st):print(1)\n else:\n cu=mx=1\n for j in range(1,len(st)):\n if st[j]==st[j-1]:cu+=1\n else:mx=max(mx,cu);cu=1\n print(max(mx+1,cu+1))\n\n```","inputs":"4\n<<<\n<><\n<=>\n<=<\n","output":"4\n2\n2\n3\n","actual_output":"4\n2\n2\n3\n","execution_success":true,"sample_index":186},{"source":"apps","task_type":"verifiable_code","in_source_id":"576","prompt":"Solve the following coding problem using the programming language python:\n\nYou came across this story while reading a book. Long a ago when the modern entertainment systems did not exist people used to go to watch plays in theaters, where people would perform live in front of an audience. There was a beautiful actress who had a disability she could not pronounce the character $'r'$. To win her favours which many have been denied in past, you decide to write a whole play without the character $'r'$. Now you have to get the script reviewed by the editor before presenting it to her.\nThe editor was flattered by the script and agreed to you to proceed. The editor will edit the script in this way to suit her style. For each word replace it with a sub-sequence of itself such that it contains the character 'a'. \nA subsequence is a sequence that can be derived from another sequence by deleting some or no elements without changing the order of the remaining elements Wikipedia \nNow given a script with $N$ words, for each word in the script you wish to know the number of subsequences with which it can be replaced. \n\n-----Input:-----\n- First-line will contain $N$, the number of words in the script. Then next $N$ line with one test case each. \n- Each test case contains a single word $W_i$\n\n-----Output:-----\nFor each test case, output in a single line number of subsequences with which it can be replaced. \n\n-----Constraints-----\n- $1 \\leq N \\leq 1000$\n- $1 \\leq$ length of $W_i$ $\\leq 20$\n- $W_i$ on contains lowercase english alphabets and does not have the character 'r'\n\n-----Sample Input 1:-----\n2\nabc\naba\n\n-----Sample Output 1:-----\n4\n6\n\n-----EXPLANATION:-----\nThis subsequences with which $abc$ can be replaed : ${a,ab,ac,abc}$. \nThis subsequences with which $aba$ can be replaed : ${a,ab,aba,a,ba,a}$. \n\n-----Sample Input 2:-----\n3\nabcde\nabcdea\nxyz\n\n-----Sample Output 2:-----\n16\n48\n0\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfor _ in range(int(input())):\r\n S = input()\r\n n = len(S)\r\n a = n - S.count('a')\r\n print(2 ** n - 2 ** a)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\nabc\\naba\\n', 'output': '4\\n6\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/CFW32020/problems/OMGO'}","problem_id":"vfc_1146","program":"```python\nfor _ in range(int(input())):\r\n S = input()\r\n n = len(S)\r\n a = n - S.count('a')\r\n print(2 ** n - 2 ** a)\n```","inputs":"2\nabc\naba\n","output":"4\n6\n","actual_output":"4\n6\n","execution_success":true,"sample_index":187},{"source":"apps","task_type":"verifiable_code","in_source_id":"577","prompt":"Solve the following coding problem using the programming language python:\n\nNot everyone probably knows that Chef has younder brother Jeff. Currently Jeff learns to read.\nHe knows some subset of the letter of Latin alphabet. In order to help Jeff to study, Chef gave him a book with the text consisting of N words. Jeff can read a word iff it consists only of the letters he knows.\nNow Chef is curious about which words his brother will be able to read, and which are not. Please help him!\n\n-----Input-----\nThe first line of the input contains a lowercase Latin letter string S, consisting of the letters Jeff can read. Every letter will appear in S no more than once.\nThe second line of the input contains an integer N denoting the number of words in the book.\nEach of the following N lines contains a single lowecase Latin letter string Wi, denoting the ith word in the book.\n\n-----Output-----\nFor each of the words, output \"Yes\" (without quotes) in case Jeff can read it, and \"No\" (without quotes) otherwise.\n\n-----Constraints-----\n- 1 \u2264 |S| \u2264 26\n- 1 \u2264 N \u2264 1000\n- 1 \u2264 |Wi| \u2264 12\n- Each letter will appear in S no more than once.\n- S, Wi consist only of lowercase Latin letters.\n\n-----Subtasks-----\n- Subtask #1 (31 point): |S| = 1, i.e. Jeff knows only one letter.\n- Subtask #2 (69 point)\t: no additional constraints\n\n-----Example-----\nInput:act\n2\ncat\ndog\n\nOutput:Yes\nNo\n\n-----Explanation-----\nThe first word can be read.\nThe second word contains the letters d, o and g that aren't known by Jeff.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nknows=input()\nn=eval(input())\nwhile n!=0:\n n=n-1\n word=input()\n for x in word:\n ctr=0\n for y in knows:\n if x==y:ctr=ctr+1;break\n if ctr==0:print('No');break\n else: print('Yes')\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': 'act\\n2\\ncat\\ndog\\n', 'output': 'Yes\\nNo\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/LTIME39/problems/ALPHABET'}","problem_id":"vfc_1150","program":"```python\nknows=input()\nn=eval(input())\nwhile n!=0:\n n=n-1\n word=input()\n for x in word:\n ctr=0\n for y in knows:\n if x==y:ctr=ctr+1;break\n if ctr==0:print('No');break\n else: print('Yes')\n```","inputs":"act\n2\ncat\ndog\n","output":"Yes\nNo\n","actual_output":"Yes\nNo\n","execution_success":true,"sample_index":188},{"source":"apps","task_type":"verifiable_code","in_source_id":"578","prompt":"Solve the following coding problem using the programming language python:\n\nChef has a calculator which has two screens and two buttons. Initially, each screen shows the number zero. Pressing the first button increments the number on the first screen by 1, and each click of the first button consumes 1 unit of energy.\nPressing the second button increases the number on the second screen by the number which is currently appearing on the first screen. Each click of the second button consumes B units of energy.\nInitially the calculator has N units of energy.\nNow chef wonders what the maximum possible number is, that he gets on the second screen of the calculator, with the limited energy.\n\n-----Input-----\nThe first line of the input contains an integer T denoting the number of test cases.\nEach test case is described using a single line containing two integers, N and B.\n\n-----Output-----\nFor each test case, output a single line containing the answer to this test case.\n\n-----Constraints-----\n- 1 \u2264 T \u2264 10,000\n- 1 \u2264 N, B \u2264 1,000,000,000\n\n-----Subtasks-----\n- Subtask 1 (20 points): 1 \u2264 N, B \u2264 1,000\n- Subtask 2 (80 points): Original constraints\n\n-----Example-----\nInput:\n3\n10 2\n8 5\n6 1\n\nOutput:\n12\n3\n9\n\n-----Explanation-----\nExample case 1. There are 10 units of energy available. Pressing second button takes 2 units of energy. Chef can achieve 12 on the second screen as follows.\n\n- Press first button to get scores (1, 0). 9 units of energey is left.\n- Press first button to get scores (2, 0). 8 units of energy remaining.\n- Press first button to get scores (3, 0). 7 units of energy remaining.\n- Press first button to get scores (4, 0). 6 units of energy remaining.\n- Press second button to get scores (4, 4). 4 units of energy remaining.\n- Press second button to get scores (4, 8). 2 units of energy remaining.\n- Press second button to get scores (4, 12). 0 units of energy remaining.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\nfor i in range(int(input())):\n n,b=map(int,input().split())\n ans=round(n/(2*b))*(n-b*round((n/(2*b))));\n print(ans)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\n10 2\\n8 5\\n6 1\\n', 'output': '12\\n3\\n9\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/CALC'}","problem_id":"vfc_1154","program":"```python\n# cook your dish here\nfor i in range(int(input())):\n n,b=map(int,input().split())\n ans=round(n/(2*b))*(n-b*round((n/(2*b))));\n print(ans)\n```","inputs":"3\n10 2\n8 5\n6 1\n","output":"12\n3\n9\n","actual_output":"12\n3\n9\n","execution_success":true,"sample_index":189},{"source":"apps","task_type":"verifiable_code","in_source_id":"579","prompt":"Solve the following coding problem using the programming language python:\n\nChef has a circular sequence $A$ of $N$ non-negative integers $A_1, A_2, \\ldots, A_N$ where $A_i$ and $A_{i+1}$ are considered adjacent, and elements $A_1$ and $A_N$ are considered adjacent.\nAn operation on position $p$ in array $A$ is defined as replacing $A_p$ by the bitwise OR of elements adjacent to $A_p$. Formally, an operation is defined as:\n- If $p = 1$, replace $A_1$ with $A_N | A_{2}$\n- If $1 < p < N$, replace $A_p$ with $A_{p-1} | A_{p+1}$\n- If $p = N$, replace $A_N$ with $A_{N-1} | A_1$\nHere, '|' denotes the bitwise OR operation.\nNow, Chef must apply operations at each position exactly once, but he may apply the operations in any order.\nBeing a friend of Chef, you are required to find a sequence of operations, such that after applying all the $N$ operations, the bitwise OR of the resulting array is $K$, or determine that no such sequence of operations exist.\n\n-----Input:-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The first line of each test case contains two space-separated integers $N$ and $K$ denoting the number of elements, and the required bitwise OR after operations.\n- The second line contains $N$ space-separated integers $A_1, A_2, \\ldots, A_N$.\n\n-----Output:-----\nFor each test case, if no valid sequence of operations exist, print -1.\nOtherwise, print $N$ space-separated integers in which $i$-th integer denote the position chosen in the $i$-th operation. If there are multiple valid sequences of operations, you may print any valid sequence.\n\n-----Constraints-----\n- $1 \\le T \\le 10^5$\n- $3 \\le N \\le 2*10^5$\n- $0 \\le A_i, K \\le 10^9$\n- It's guaranteed that the total length of the arrays in one test file doesn't exceed $10^6$\n\n-----Sample Input:-----\n5\n3 6\n2 1 6\n3 6\n2 1 5\n3 7\n2 4 6\n3 7\n1 2 4\n3 7\n1 2 6\n\n-----Sample Output:-----\n2 1 3\n-1\n-1\n-1\n2 3 1\n\n-----Explanation:-----\nIn the first test case, initially, the sequence is {2, 1, 6}. \n- Chef applies the operation on the $2^{nd}$ index, so the sequence converts to {2, 6, 6}.\n- Next, Chef applies the operation on the $1^{st}$ index, so the sequence converts to {6, 6, 6}.\n- Next, Chef applies the operation on the $3^{rd}$ index, and this time sequence does not change.\nThe final sequence is {6, 6, 6}, and bitwise OR of this sequence is $6$ that is equal to given $K$.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nt=int(input())\ndef check():\n pref = [0]*n\n pref[0]=a[0]\n suff = [0]*n\n suff[-1]=a[-1]\n for i in range (1,n):\n pref[i] = pref[i-1]|a[i]\n suff[n-i-1] = suff[n-i]|a[n-i-1]\n if suff[1]==k:\n return 0\n elif pref[n-2]==k:\n return n-1\n else:\n for i in range (1,n-1):\n if pref[i-1]|suff[i+1] == k:\n return i\n return -1\nwhile(t):\n t-=1\n n,k=[int(i) for i in input().split()]\n a=[int(i) for i in input().split()]\n ans = []\n arr = [0]*n\n for i in range (n):\n if k|a[i] != k:\n a[i] = a[i-1]|a[(i+1)%(n)]\n ans.append(i+1)\n arr[i]=1\n\n x = 0\n count = 0\n for i in range (n):\n x|=a[i]\n \n if x!= k:\n print(-1)\n else:\n y = check()\n if y == -1:\n print(-1)\n else:\n for i in range (y,n+y):\n if arr[i%n]==0:\n arr[i%n]==1\n ans.append((i%n)+1)\n print(*ans)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '5\\n3 6\\n2 1 6\\n3 6\\n2 1 5\\n3 7\\n2 4 6\\n3 7\\n1 2 4\\n3 7\\n1 2 6\\n', 'output': '2 1 3\\n-1\\n-1\\n-1\\n2 3 1\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/RECNDORO'}","problem_id":"vfc_1158","program":"```python\nt=int(input())\ndef check():\n pref = [0]*n\n pref[0]=a[0]\n suff = [0]*n\n suff[-1]=a[-1]\n for i in range (1,n):\n pref[i] = pref[i-1]|a[i]\n suff[n-i-1] = suff[n-i]|a[n-i-1]\n if suff[1]==k:\n return 0\n elif pref[n-2]==k:\n return n-1\n else:\n for i in range (1,n-1):\n if pref[i-1]|suff[i+1] == k:\n return i\n return -1\nwhile(t):\n t-=1\n n,k=[int(i) for i in input().split()]\n a=[int(i) for i in input().split()]\n ans = []\n arr = [0]*n\n for i in range (n):\n if k|a[i] != k:\n a[i] = a[i-1]|a[(i+1)%(n)]\n ans.append(i+1)\n arr[i]=1\n\n x = 0\n count = 0\n for i in range (n):\n x|=a[i]\n \n if x!= k:\n print(-1)\n else:\n y = check()\n if y == -1:\n print(-1)\n else:\n for i in range (y,n+y):\n if arr[i%n]==0:\n arr[i%n]==1\n ans.append((i%n)+1)\n print(*ans)\n```","inputs":"5\n3 6\n2 1 6\n3 6\n2 1 5\n3 7\n2 4 6\n3 7\n1 2 4\n3 7\n1 2 6\n","output":"2 1 3\n-1\n-1\n-1\n2 3 1\n","actual_output":"2 1 3\n-1\n-1\n-1\n2 3 1\n","execution_success":true,"sample_index":190},{"source":"apps","task_type":"verifiable_code","in_source_id":"580","prompt":"Solve the following coding problem using the programming language python:\n\nThe chef is trying to decode some pattern problems, Chef wants your help to code it. Chef has one number K(odd) to form a new pattern. Help the chef to code this pattern problem.\n\n-----Input:-----\n- First-line will contain $T$, the number of test cases. Then the test cases follow. \n- Each test case contains a single line of input, one integer $K$. \n\n-----Output:-----\nFor each test case, output as the pattern.\n\n-----Constraints-----\n- $1 \\leq T \\leq 100$\n- $1 \\leq K \\leq 100$\n\n-----Sample Input:-----\n4\n1\n3\n5\n7\n\n-----Sample Output:-----\n1\n111\n111\n111\n11111\n11 11\n1 1 1\n11 11\n11111\n1111111\n11 11\n1 1 1 1\n1 1 1\n1 1 1 1\n11 11\n1111111\n\n-----EXPLANATION:-----\nNo need, else pattern can be decode easily.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfrom 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 i==0 or i==n-1 or j==0 or j==n-1 or i==j or i+j==n-1:\n print(1, end=\"\")\n else:\n print(\" \", end=\"\")\n print()\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '4\\n1\\n3\\n5\\n7\\n', 'output': '1\\n111\\n111\\n111\\n11111\\n11 11\\n1 1 1\\n11 11\\n11111\\n1111111\\n11 11\\n1 1 1 1\\n1 1 1\\n1 1 1 1\\n11 11\\n1111111\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/PTRN2021/problems/ITGUY54'}","problem_id":"vfc_1162","program":"```python\nfrom 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 i==0 or i==n-1 or j==0 or j==n-1 or i==j or i+j==n-1:\n print(1, end=\"\")\n else:\n print(\" \", end=\"\")\n print()\n```","inputs":"4\n1\n3\n5\n7\n","output":"1\n111\n111\n111\n11111\n11 11\n1 1 1\n11 11\n11111\n1111111\n11 11\n1 1 1 1\n1 1 1\n1 1 1 1\n11 11\n1111111\n","actual_output":"1\n111\n111\n111\n11111\n11 11\n1 1 1\n11 11\n11111\n1111111\n11 11\n1 1 1 1\n1 1 1\n1 1 1 1\n11 11\n1111111\n","execution_success":true,"sample_index":191},{"source":"apps","task_type":"verifiable_code","in_source_id":"581","prompt":"Solve the following coding problem using the programming language python:\n\nHumpy, the little elephant, has his birthday coming up. He invited all his cousins but doesn\u2019t know how many of them are really coming as some of them are having exams coming up. He will only get to know how many of them are coming on the day of his birthday.\n\nHe ordered sugarcane for his party, of length L.\n\nHumpy\u2019s mom decided that she will be dividing the sugarcane among Humty and his friends in a way such that they get the sugarcane in ratio of their ages.\n\nYour task is to determine whether it is possible to serve sugarcane to everyone as integral multiples of their ages.\n\n-----INPUT-----\nFirst line of input contains an integer N, denoting the number of test cases.\n\nThen N test cases follow.\n\nThe first line of each test case contains three integers K, L and E. K denoting the number of friends coming; L denoting the length of the sugarcane and E denoting the age of the little elephant. Next line has K space separated integers denoting the age of friends who came to the party.\n\n-----OUTPUT-----\n\nFor each test case, output \u201cYES\u201d (without quotes) if everyone gets their part as integral multiples of their ages; otherwise output \u201cNO\u201d(without quotes).\n\n-----CONSTRAINTS-----\n\n- 1 <= T<=30\n- 1 <= K<=1000\n- 1 <= L<=1000000\n- 1 <= E<=100000\n- 1 <= Age of Cousins<=100000\n\n-----Example-----\nInput:\n2\n4 10 2\n2 2 3 1\n4 12 3\n6 5 7 3\n\nOutput:\nYES \nNO\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# your code goes here\nfrom sys import stdin, stdout\nn = int(stdin.readline())\nwhile n:\n n -= 1\n k, l, e = map(int, stdin.readline().strip().split(' '))\n a = map(int, stdin.readline().strip().split(' '))\n x = float(l) / float(e + sum(a))\n if x - int(x):\n stdout.write(\"NO\\n\")\n else:\n stdout.write(\"YES\\n\")\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n4 10 2\\n2 2 3 1\\n4 12 3\\n6 5 7 3\\n', 'output': 'YES\\nNO\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/IC32016/problems/HBB'}","problem_id":"vfc_1166","program":"```python\n# your code goes here\nfrom sys import stdin, stdout\nn = int(stdin.readline())\nwhile n:\n n -= 1\n k, l, e = map(int, stdin.readline().strip().split(' '))\n a = map(int, stdin.readline().strip().split(' '))\n x = float(l) / float(e + sum(a))\n if x - int(x):\n stdout.write(\"NO\\n\")\n else:\n stdout.write(\"YES\\n\")\n```","inputs":"2\n4 10 2\n2 2 3 1\n4 12 3\n6 5 7 3\n","output":"YES\nNO\n","actual_output":"YES\nNO\n","execution_success":true,"sample_index":192},{"source":"apps","task_type":"verifiable_code","in_source_id":"582","prompt":"Solve the following coding problem using the programming language python:\n\nYou may have tried your level best to help Chef but Dr Doof has managed to come up with his masterplan in the meantime. Sadly, you have to help Chef once again. Dr Doof has designed a parenthesis-inator. It throws a stream of $N$ brackets at the target, $1$ bracket per second. The brackets can either be opening or closing. Chef appears in front of the stream at time $t$. If Chef faces an opening bracket, he gets hit. However, if he faces a closing bracket, he may choose to let it pass through him (Chef is immune to closing brackets). Chef gets a chance to counter attack Doof as soon as he finds a balanced non-empty bracket sequence. Help Chef by providing him the minimum time $x$ at which he will be able to launch his counter attack. If Chef is unable to counter attack, answer $-1$.\nFormally, you are given a string $S$ of length $N$ consisting only of opening brackets $($ and closing brackets $)$. The substring of $S$ starting at index $L$ and ending at index $R$, i.e. $S_L S_{L+1} \\ldots S_{R}$ is denoted by $S[L, R]$ . Consider $Q$ cases. In the $i^{\\text{th}}$ case, Chef appears at time $t_i$ $(1 \\leq t_i \\leq N)$ and faces all characters from index $t_i$ to $N$. Find the minimum index $x$ $(t_i \\leq x \\leq N)$ such that the substring $S[t_i, x]$ contains a non-empty balanced bracket subsequence containing the same number of opening brackets as $S[t_i, x]$ (i.e., you cannot remove any opening bracket from the substring). If such an $x$ does not exist, print $-1$.\nA string $X$ is called a subsequence of a string $Y$ if it is possible to obtain $X$ by erasing some (possibly zero) characters from $Y$ without changing the order of the remaining characters.\nA balanced bracket sequence is defined as: \n- an empty string is a balanced bracket sequence.\n- if $s$ is a balanced bracket sequence, then so is $(s)$.\n- if $s$ and $t$ are balanced bracket sequences, then so is $st$.\n$Note :-$ The input files are large. The use of Fast I/O is recommended.\n\n-----Input-----\n- The first line contains a single integer $T$ denoting the number of testcases.\n- The first line of each test case contains the string $S$.\n- The next line contains a single integer $Q$ denoting the number of cases to consider.\n- The next line contains $Q$ space separated integers, each denoting $t_i$.\n\n-----Output-----\nFor each query, print the minimum value of $x$ in a separate line. If no such $x$ exists, print $-1$.\n\n-----Constraints-----\n- $1 \\leq T \\leq 10^3$\n- $1 \\leq |S| \\leq 10^7$\n- $1 \\leq Q \\leq 10^6$\n- $1 \\leq t_i \\leq N$\n- Every character of $S$ is either $($ or $)$.\n- Sum of $|S|$ and $Q$ over all testcases for a particular test file does not exceed $10^7$ and $10^6$ respectively.\n\n-----Sample Input-----\n1\n)())((()\n3\n1 7 6\n\n-----Sample Output-----\n3\n8\n-1\n\n-----Explanation-----\nFor the first query, Chef chooses to let $S_1$ pass through him, gets hit by $S_2$ and finally completes a balanced bracket sequence by adding $S_3$ to $S_2$ at time $x$ = $3$.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nimport sys\nimport bisect as bi\nimport math\nfrom collections import defaultdict as dd\ninput=sys.stdin.readline\n##sys.setrecursionlimit(10**7)\ndef cin():\n return list(map(int,sin().split()))\ndef ain(): \n return list(map(int,sin().split()))\ndef sin():\n return input()\ndef inin():\n return int(input())\nfor _ in range(inin()):\n s=sin().strip();q=inin();a=ain();n=len(s);store=[0]*n;store1=[-1]*n;f=0;d=dd(int)#input wgera\n store[0]=1 if s[0]=='(' else -1\n d[store[0]]=1\n for i in range(1,n):\n if(s[i]=='('):\n store[i]=store[i-1]+1\n d[store[i]]=i+1\n else:\n store[i]=store[i-1]-1\n if(d[store[i-1]]):\n store1[d[store[i-1]]-1]=i+1\n post=[-1]*n;\n if(n==1 or(n==2 and s!=\"()\")):f=1 # corner case\n for i in range(n-2,-1,-1):\n if(s[i]=='('): #dekhna h ki agla agr ( h toh -1 hi rhega wrna wo jo stored tha uppr\n if(store1[i]!=-1):post[i]=store1[i] #wo iska ans ho jayega\n else:post[i]=post[i+1] #jo iske agle ka answer hoga wahi iska hoga\n for i in a:\n if(f):print(-1) #cond ki jaroorat nhi thi pr tasalli (>_<)\n else:print(post[i-1]) #wrna uska ans print kra do\n \n \n##n=m=0\n##s=''\n##t=''\n##dp=[]\n##def solve(inds,indt,k,cont):\n## ans=-999999999999999\n## print(dp)\n## if(k<0):return 0\n## elif(inds>=n and indt>=m):return 0\n## elif(dp[inds][indt][k][cont]!=-1):return dp[inds][indt][k][cont]\n## else:\n## if(indt_<)\n else:print(post[i-1]) #wrna uska ans print kra do\n \n \n##n=m=0\n##s=''\n##t=''\n##dp=[]\n##def solve(inds,indt,k,cont):\n## ans=-999999999999999\n## print(dp)\n## if(k<0):return 0\n## elif(inds>=n and indt>=m):return 0\n## elif(dp[inds][indt][k][cont]!=-1):return dp[inds][indt][k][cont]\n## else:\n## if(indt=0:\n print('YES')\n else:\n print('NO')\n else:\n for i in m:\n if i<0:\n q+=i\n else:\n p+=i\n if p>=abs(q):\n print('YES')\n else:\n print('NO')\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n1\\n-1\\n2\\n1 2\\n', 'output': 'NO\\nYES\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/WATMELON'}","problem_id":"vfc_1174","program":"```python\nn=int(input())\nfor i in range(n):\n t=int(input())\n m=list(map(int,input().split()))\n p,q=0,0\n if t==1:\n if m[0]>=0:\n print('YES')\n else:\n print('NO')\n else:\n for i in m:\n if i<0:\n q+=i\n else:\n p+=i\n if p>=abs(q):\n print('YES')\n else:\n print('NO')\n```","inputs":"2\n1\n-1\n2\n1 2\n","output":"NO\nYES\n","actual_output":"NO\nYES\n","execution_success":true,"sample_index":194},{"source":"apps","task_type":"verifiable_code","in_source_id":"584","prompt":"Solve the following coding problem using the programming language python:\n\nGiven a binary string $S$ consisting of only 1\u2019s and 0\u2019s where 1 represents a Square and 0 represents a Circle. The diameter of the circle and the side of the square must be any integer (obviously > 0) . You will have to perfectly inscribe (as shown in the example below) the respective geometric figure at $S$$i+1$ inside of $S$$i$ where $i$ $\\epsilon$ $[0,N-2]$, if it is possible. Note that, it will not be possible to inscribe if the dimension of the geometric figure you are perfectly inscribing is not an integer and you will discard the rest of the string. Find the maximum number of circles we can inscribe in a square according to the given string. \nFor a given binary string there can be only one geometric figure and this figure is concentric. \nFor example : the string 1100 can be represented as the figure below, the first two squares have the same side length and the next two circles have the same diameter. \n\nAnother example : the string 0001 can be represented as the one given below\nAgain here, we have 3 circles of the same diameter and one square inscribed in them. \n\n-----Input:-----\nThe first line contains $N$, the number of strings\n\nThen each of the next $N$ lines contains a binary string $S$. \n\n-----Output:-----\nThe $N$ lines of output should have $N$ integers in separate lines, the maximum number of circles we can inscribe in a square according to the given string $S$ . \n\n-----Constraints-----\n- 1 $\\leq$ $N$ $\\leq$ 103\n- 1 $\\leq$ length of string $S$ $\\leq$ 104\n\n-----Sample Input:-----\n3\n\n1110\n\n0010\n\n1001000 \n\n-----Sample Output:-----\n1\n\n0\n\n2 \n\n-----Explanation:-----\nIn the first case, we can inscribe the string 1110 as : three squares of side length 4 units (on top of each other) and then we can inscribe one circle of diameter 4 units.\nThe answer is 1 since, there is 1 circle inscribed in a square.\n\nIn the second case 0010, Let the first two circles be of some diameter 10, we can see that we cannot inscribe another square of any integer dimension inside them.\n\nSo, the answer is 0.\n\nIn the third case 1001000, we can take the first square of size 10, then inscribe two circles of diameter 5, then we cannot inscribe another square in this since, it will not be of any possible integer dimension and we discard the rest of the string.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfor z in range(int(input())):\n s = input()\n n = len(s)\n i = 0\n while i0).\nThat planet has a special rule made by the queen that a boy and a girl will form a couple if their Hate value is a prime number where $Hate$ is given by the formula:-\nHate = (boy's strength value) XOR (girl's strength value )\nYou are given $N$ numbers denoting the strength value of $N$ girls, and each of the $N$ girls has to form a couple with a boy such that sum of $Hate$ value of all the $N$ couples will be minimum.\nYou need to print the strength value of each boy, Where the boy at index $i$ will form a couple with the girl at index $i$, where $1 \\leq i \\leq N$.\nAssume that you can always find at least one boy having that strength for each girl.\n\n-----Input:-----\n- First line will contain $N$, the number of Girls. \n- Next line contains $N$ numbers separated by space denoting strength value for each girl.\n\n-----Output:-----\nPrint the required $N$ numbers denoting strength of boys.\n\n-----Constraints-----\n- $1 \\leq N \\leq 100000$\n- $1 \\leq A_i \\leq 10^9$ , (where $1 \\leq i \\leq N$) and $A_i$ denotes strength of i'th girl.\n\n-----Sample Input:-----\n2\n10 16\n\n-----Sample Output:-----\n8 18\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nn=int(input())\r\na=list(map(int,input().split()))\r\nc=[]\r\nfor i in range(len(a)):\r\n if a[i]==2:\r\n c.append(1)\r\n else:\r\n c.append(a[i]^2)\r\nprint(*c)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n10 16\\n', 'output': '8 18\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/INRO2021/problems/COUPLING'}","problem_id":"vfc_1190","program":"```python\nn=int(input())\r\na=list(map(int,input().split()))\r\nc=[]\r\nfor i in range(len(a)):\r\n if a[i]==2:\r\n c.append(1)\r\n else:\r\n c.append(a[i]^2)\r\nprint(*c)\n```","inputs":"2\n10 16\n","output":"8 18\n","actual_output":"8 18\n","execution_success":true,"sample_index":198},{"source":"apps","task_type":"verifiable_code","in_source_id":"588","prompt":"Solve the following coding problem using the programming language python:\n\nVasya has ordered a pizza delivery. The pizza can be considered a perfect circle. There were $n$ premade cuts in the pizza when it was delivered. Each cut is a straight segment connecting the center of the pizza with its boundary.\nLet $O$ be the center of the pizza, $P_i$ be the endpoint of the $i$-th cut lying on the boundary, and $R$ be the point of the boundary straight to the right of $O$. Then the counterclockwise-measured angle $\\angle ROP_i$ is equal to $a_i$ degrees, where $a_i$ is an integer between $0$ and $359$. Note that angles between $0$ and $180$ angles correspond to $P_i$ in the top half of the pizza, while angles between $180$ and $360$ angles correspond to the bottom half.\nVasya may cut his pizza a few more times, and the new cuts still have to be straight segments starting at the center. He wants to make the pizza separated into several equal slices, with each slice being a circular sector with no cuts inside of it. How many new cuts Vasya will have to make?\n\n-----Input:-----\nThe first line of input contains $T$ , i.e number of test cases per file.\nThe first line of each test case contains a single integer $n-$ the numbers of premade cuts ($2 \\leq n \\leq 360$).\nThe second lines contains $n$ integers $a_1, \\ldots, a_n-$ angles of the cuts $1, \\ldots, n$ respectively ($0 \\leq a_1 < \\ldots, a_{n - 1} < 360$).\n\n-----Output:-----\nPrint a single integer$-$ the smallest number of additional cuts Vasya has to make so that the pizza is divided into several equal slices.\n\n-----Constraints-----\n- $1 \\leq T \\leq 36$\n- $2 \\leq n \\leq 360$\n- $0 \\leq a_1 < \\ldots, a_{n - 1} < 360$\n\n-----Sample Input:-----\n3\n4 \n0 90 180 270\n2\n90 210\n2\n0 1\n\n-----Sample Output:-----\n0\n1\n358\n\n-----EXPLANATION:-----\nIn the first sample the pizza is already cut into four equal slices.\nIn the second sample the pizza will be cut into three equal slices after making one extra cut at $330$ degrees.\nIn the third sample Vasya will have to cut his pizza into $360$ pieces of $1$ degree angle each.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\ndef gcd(a, b):\n if a == 0:\n return b\n return(gcd(b % a, a))\n\nt = int(input())\nfor T in range(t):\n n = int(input())\n l = [int(x) for x in input().split()]\n\n ang = []\n for i in range(1, n):\n ang.append(l[i] - l[i - 1])\n ang.append(360 - (l[-1] - l[0]))\n ang.sort()\n if ang == ang[::-1]:\n print(0)\n continue\n \n g = ang[0]\n for i in range(1, n):\n g = gcd(g, ang[i])\n\n \n total = 360 // g - len(ang)\n print(total)\n## print(g, ang, total)\n\n\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\n4\\n0 90 180 270\\n2\\n90 210\\n2\\n0 1\\n', 'output': '0\\n1\\n358\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/CUTPIZ'}","problem_id":"vfc_1194","program":"```python\ndef gcd(a, b):\n if a == 0:\n return b\n return(gcd(b % a, a))\n\nt = int(input())\nfor T in range(t):\n n = int(input())\n l = [int(x) for x in input().split()]\n\n ang = []\n for i in range(1, n):\n ang.append(l[i] - l[i - 1])\n ang.append(360 - (l[-1] - l[0]))\n ang.sort()\n if ang == ang[::-1]:\n print(0)\n continue\n \n g = ang[0]\n for i in range(1, n):\n g = gcd(g, ang[i])\n\n \n total = 360 // g - len(ang)\n print(total)\n## print(g, ang, total)\n\n\n\n```","inputs":"3\n4\n0 90 180 270\n2\n90 210\n2\n0 1\n","output":"0\n1\n358\n","actual_output":"0\n1\n358\n","execution_success":true,"sample_index":199},{"source":"apps","task_type":"verifiable_code","in_source_id":"589","prompt":"Solve the following coding problem using the programming language python:\n\nDigory Kirke and Polly Plummer are two kids living next door to each other. The attics of the two houses are connected to each other through a passage. Digory's Uncle Andrew has been secretly doing strange things in the attic of his house, and he always ensures that the room is locked. Being curious, Digory suspects that there is another route into the attic through Polly's house, and being curious as kids always are, they wish to find out what it is that Uncle Andrew is secretly up to.\n\nSo they start from Polly's house, and walk along the passageway to Digory's. Unfortunately, along the way, they suddenly find that some of the floorboards are missing, and that taking a step forward would have them plummet to their deaths below.\n\nDejected, but determined, they return to Polly's house, and decide to practice long-jumping in the yard before they re-attempt the crossing of the passage. It takes them exactly one day to master long-jumping a certain length. Also, once they have mastered jumping a particular length L, they are able to jump any amount less than equal to L as well.\n\nThe next day they return to their mission, but somehow find that there is another place further up the passage, that requires them to jump even more than they had practiced for. So they go back and repeat the process.\n\nNote the following:\n\n- At each point, they are able to sense only how much they need to jump at that point, and have no idea of the further reaches of the passage till they reach there. That is, they are able to only see how far ahead is the next floorboard. \n- The amount they choose to practice for their jump is exactly the amount they need to get across that particular part of the passage. That is, if they can currently jump upto a length L0, and they require to jump a length L1(> L0) at that point, they will practice jumping length L1 that day. \n- They start by being able to \"jump\" a length of 1. \n\nFind how many days it will take them to cross the passageway. In the input, the passageway is described as a string P of '#'s and '.'s. A '#' represents a floorboard, while a '.' represents the absence of a floorboard. The string, when read from left to right, describes the passage from Polly's house to Digory's, and not vice-versa.\n\n-----Input-----\n\nThe first line consists of a single integer T, the number of testcases.\nEach of the next T lines consist of the string P for that case.\n\n-----Output-----\n\nFor each case, output the number of days it takes them to cross the passage.\n\n-----Constraints-----\n- 1 \u2264 T \u2264 1,000,000 (106)\n- 1 \u2264 |P| \u2264 1,000,000 (106)\n- The total length of P will be \u2264 5,000,000 (5 * 106)across all test-cases of a test-file \n- P will consist of only the characters # and . \n- The first and the last characters of P will be #. \n\n-----Example-----\nInput:\n4\n####\n##.#..#\n##..#.#\n##.#....#\n\nOutput:\n0\n2\n1\n2\n\n-----Explanation-----\n\nFor the first example, they do not need to learn any jump size. They are able to cross the entire passage by \"jumping\" lengths 1-1-1.\n\nFor the second example case, they get stuck at the first '.', and take one day learning to jump length 2. When they come back the next day, they get stuck at '..' and take one day to learn to jump length 3.\n\nFor the third example case, they get stuck first at '..', and they take one day to learn to jump length 3. On the second day, they are able to jump both length 3 as well as length 2 required to cross the passage.\n\nFor the last test case they need to stop and learn jumping two times. At first they need to jump a length 2 and then a length 5.\n\n-----Appendix-----\n\nIrrelevant to the problem description, if you're curious about what Uncle Andrew was up to, he was experimenting on Magic Rings that could facilitate travel between worlds. One such world, as some of you might have heard of, was Narnia.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\nfor i in range(int(input())):\n s = input()\n m = 0\n p = 0\n d = 0\n l = []\n for i in range(len(s)):\n if(s[i] == \".\"):\n m = m+1\n elif(s[i] == \"#\"):\n l.append(m)\n m=0\n for i in range(len(l)):\n if(l[i]>p):\n p = l[i]\n d = d+1\n print(d)\n \n \n \n \n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '4\\n####\\n##.#..#\\n##..#.#\\n##.#....#\\n', 'output': '0\\n2\\n1\\n2\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/ATTIC'}","problem_id":"vfc_1198","program":"```python\n# cook your dish here\nfor i in range(int(input())):\n s = input()\n m = 0\n p = 0\n d = 0\n l = []\n for i in range(len(s)):\n if(s[i] == \".\"):\n m = m+1\n elif(s[i] == \"#\"):\n l.append(m)\n m=0\n for i in range(len(l)):\n if(l[i]>p):\n p = l[i]\n d = d+1\n print(d)\n \n \n \n \n\n```","inputs":"4\n####\n##.#..#\n##..#.#\n##.#....#\n","output":"0\n2\n1\n2\n","actual_output":"0\n2\n1\n2\n","execution_success":true,"sample_index":200},{"source":"apps","task_type":"verifiable_code","in_source_id":"590","prompt":"Solve the following coding problem using the programming language python:\n\nChef has an array A consisting of N integers (1-based indexing). He asks you to perform the following operation M times:\n\n\tfor i = 2 to N:\n\t\tAi = Ai + Ai-1\n\nYour task is to find the xth element of the array (i.e., Ax) after performing the above operation M times. As the answer could be large, please output it modulo 109 + 7.\n\n-----Input-----\n- The first line of input contains an integer T denoting the number of test cases.\n- The first line of each test case contains three space-separated integers \u2014 N, x, and M \u2014 denoting the size of the array, index of the element you need to find, and the amount of times you need to repeat operation before finding the element, respectively. The second line contains N space-separated integers A1, A2, \u2026, AN.\n\n-----Output-----\nFor each test case, output a single line containing one integer: Ax modulo 109 + 7. \n\n-----Constraints-----\n- 1 \u2264 T \u2264 10\n- 1 \u2264 x \u2264 N \u2264 105\n- 1 \u2264 M \u2264 1018 \n- 1 \u2264 Ai \u2264 1018\n\n-----Subtasks-----Subtask 1 (8 points):\n- 1 \u2264 x \u2264 min{2, N}Subtask 2 (24 points):\n- 1 \u2264 N * M \u2264 106Subtask 3 (68 points): No additional constraints\n\n-----Example-----\nInput:\n2\n3 2 3\n1 2 3\n3 3 3 \n1 2 3\n\nOutput:\n5\n15\n\n-----Explanation-----\nValues in the array A:\n- Before the operations: [1, 2, 3]\n- After the first operation: [1, 3, 6]\n- After the second operation: [1, 4, 10]\n- After the third operation: [1, 5, 15]\n\nSince input file can be fairly large (about 8 MB), it's recommended to use fast I/O (for example, in C++, use scanf/printf instead of cin/cout).\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfor _ in range(int(input())):\n n,x,m = map(int,input().split())\n a = list(map(int,input().split()))\n for _ in range(m):\n for i in range(1,n):\n a[i] = a[i] + a[i-1]\n print(a[x-1]%(10**9+7))\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n3 2 3\\n1 2 3\\n3 3 3\\n1 2 3\\n', 'output': '5\\n15\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/STROPR'}","problem_id":"vfc_1202","program":"```python\nfor _ in range(int(input())):\n n,x,m = map(int,input().split())\n a = list(map(int,input().split()))\n for _ in range(m):\n for i in range(1,n):\n a[i] = a[i] + a[i-1]\n print(a[x-1]%(10**9+7))\n```","inputs":"2\n3 2 3\n1 2 3\n3 3 3\n1 2 3\n","output":"5\n15\n","actual_output":"5\n15\n","execution_success":true,"sample_index":201},{"source":"apps","task_type":"verifiable_code","in_source_id":"591","prompt":"Solve the following coding problem using the programming language python:\n\nGanesh lives in Gopalmath. He is looking for Jojo. So he decides to collect Aadhar Card Information of all the citizens of India from UIDAI.\nSomeone told Ganesh that the sum of all the digits of Jojo\u2019s Aadhar number is divisible by 10 and it is greater than zero. After finding all Aadhar numbers which are divisible by 10, Jojo\u2019s Aadhar number is $N$th smallest Aadhar number. Hence, Ganesh wants to find Jojo\u2019s Aadhar number which satisfies all of the above conditions. (In this chaotic world, Aadhar numbers can be any natural number.)\nHowever, Guruji refused Ganesh to carry out this task, because he is weak in Maths. Therefore, Ganesh assigns this task to Paritoshbhai who possesses excellent Mathematical skills. Since Paritoshbhai is busy in his jewellery business, help him in this task.\n\n-----Input:-----\n- The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows.\n- The first and only line of each test case contains a single integer N.\n\n-----Output:-----\nFor each test case, print a single line containing Aadhar number of Jojo.\n\n-----Constraints-----\n- $1 \\leq T \\leq 1000$\n- $1 \\leq N \\leq 10^{100,000}$\n\n-----Sample Input:-----\n1\n3\n\n-----Sample Output:-----\n37\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfor _ in range(int(input())):\n N = input()\n num = list(N)\n s=0\n for n in num:\n if n.isnumeric():\n s+=int(n)\n #print(s)\n x=(10-s%10)%10\n print(int(N)*10+int(x))\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n3\\n', 'output': '37\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/CORS2020/problems/JOJO'}","problem_id":"vfc_1206","program":"```python\nfor _ in range(int(input())):\n N = input()\n num = list(N)\n s=0\n for n in num:\n if n.isnumeric():\n s+=int(n)\n #print(s)\n x=(10-s%10)%10\n print(int(N)*10+int(x))\n```","inputs":"1\n3\n","output":"37\n","actual_output":"37\n","execution_success":true,"sample_index":202},{"source":"apps","task_type":"verifiable_code","in_source_id":"592","prompt":"Solve the following coding problem using the programming language python:\n\nTeddy and Tracy like to play a game based on strings. The game is as follows. Initially, Tracy writes a long random string on a whiteboard. Then, each player starting with Teddy makes turn alternately. Each turn, the player must erase a contiguous substring that exists in the dictionary. The dictionary consists of N words.\nOf course, the player that can't erase any substring in his turn loses the game, and the other player is declared the winner.\nNote that after a substring R is erased, the remaining substring becomes separated, i.e. they cannot erase a word that occurs partially to the left of R and partially to the right of R.\n\nDetermine the winner of the game, assuming that both players play optimally.\n\n-----Input-----\nThe first line contains a single integer T, the number of test cases. T test cases follow. The first line of each testcase contains a string S, the string Tracy writes on the whiteboard. The next line contains a single integer N. N lines follow. The i-th line contains a single string wi, the i-th word in the dictionary.\n\n-----Output-----\nFor each test case, output a single line containing the name of the winner of the game.\n\n-----Example-----\nInput:\n3\ncodechef\n2\ncode\nchef\nfoo\n1\nbar\nmississippi\n4\nssissi\nmippi\nmi\nppi\n\nOutput:\nTracy\nTracy\nTeddy\n\n-----Constraints-----\n- 1 <= T <= 5\n- 1 <= N <= 30\n- 1 <= |S| <= 30\n- 1 <= |wi| <= 30\n- S and wi contain only characters 'a'-'z'\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nimport sys\n\ndef mex(S,W,C,start,end):\n \"\"\"Returns Nim-number of S[start:end]\"\"\"\n key=(start,end)\n try:\n return C[key]\n except KeyError:\n pass\n A=set()\n for s in range(start,end):\n for e in range(start+1,end+1):\n if S[s:e] not in W: continue\n A.add(mex(S,W,C,start,s)^mex(S,W,C,e,end))\n a=0\n while a in A: a+=1\n C[key]=a\n return a\n \n\na=sys.stdin\n#a=open('astrgame.txt','r')\nT=int(a.readline())\nfor t in range(T):\n S=a.readline().strip()\n N=int(a.readline())\n W=set([a.readline().strip() for n in range(N)])\n print('Teddy' if mex(S,W,{},0,len(S)) else 'Tracy')\n \n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\ncodechef\\n2\\ncode\\nchef\\nfoo\\n1\\nbar\\nmississippi\\n4\\nssissi\\nmippi\\nmi\\nppi\\n\\n\\n', 'output': 'Tracy\\nTracy\\nTeddy\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/DEC10/problems/ASTRGAME'}","problem_id":"vfc_1210","program":"```python\nimport sys\n\ndef mex(S,W,C,start,end):\n \"\"\"Returns Nim-number of S[start:end]\"\"\"\n key=(start,end)\n try:\n return C[key]\n except KeyError:\n pass\n A=set()\n for s in range(start,end):\n for e in range(start+1,end+1):\n if S[s:e] not in W: continue\n A.add(mex(S,W,C,start,s)^mex(S,W,C,e,end))\n a=0\n while a in A: a+=1\n C[key]=a\n return a\n \n\na=sys.stdin\n#a=open('astrgame.txt','r')\nT=int(a.readline())\nfor t in range(T):\n S=a.readline().strip()\n N=int(a.readline())\n W=set([a.readline().strip() for n in range(N)])\n print('Teddy' if mex(S,W,{},0,len(S)) else 'Tracy')\n \n\n```","inputs":"3\ncodechef\n2\ncode\nchef\nfoo\n1\nbar\nmississippi\n4\nssissi\nmippi\nmi\nppi\n\n\n","output":"Tracy\nTracy\nTeddy\n","actual_output":"Tracy\nTracy\nTeddy\n","execution_success":true,"sample_index":203},{"source":"apps","task_type":"verifiable_code","in_source_id":"593","prompt":"Solve the following coding problem using the programming language python:\n\nMathison recently inherited an ancient papyrus that contained some text. Unfortunately, the text was not a\npangram. Now, Mathison has a particular liking for holoalphabetic strings and the text bothers him. The good news is that Mathison can buy letters from the local store in order to turn his text into a pangram.\n\nHowever, each letter has a price and Mathison is not very rich. Can you help Mathison find the cheapest way to obtain a pangram?\n\n-----Input-----\nThe first line of the input file will contain one integer, T, representing the number of tests.\nEach test will be formed from two lines. The first one contains 26 space-separated integers, representing the prices of all letters.\nThe second will contain Mathison's initial text (a string of N lowercase letters).\n\n-----Output-----\nThe output file will contain T lines, one for each test. Each line will contain the answer for the corresponding test.\n\n-----Constraints and notes-----\n- 1 \u2264 T \u2264 10\n- 1 \u2264 N \u2264 50,000\n- All prices are natural numbers between 1 and 1,000,000 (i.e. 106).\n- A pangram is a string that contains every letter of the Latin alphabet at least once.\n- All purchased letters are added to the end of the string.\n\n-----Subtaks-----\nSubtask #1 (30 points):\n\n- N = 1\n\nSubtask #2 (70 points):\n\n- Original constraints\n\n-----Example-----\nInput:\n2\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26\nabcdefghijklmopqrstuvwz\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26\nthequickbrownfoxjumpsoverthelazydog\n\nOutput:\n63\n0\n\n-----Explanation-----\nFirst test\nThere are three letters missing from the original string: n (price 14), x (price 24), and y (price 25).\nTherefore the answer is 14 + 24 + 25 = 63.\n\nSecond test\nNo letter is missing so there is no point in buying something. The answer is 0.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\n# cook your dish here\nfor i in range(int(input())):\n a=list(map(int,input().split()))\n x=input()\n t=0\n for i in range(ord('a'),ord('z')+1):\n if chr(i) not in x:\n t+=a[i-97]\n print(t)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26\\nabcdefghijklmopqrstuvwz\\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26\\nthequickbrownfoxjumpsoverthelazydog\\n', 'output': '63\\n0\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/MATPAN'}","problem_id":"vfc_1214","program":"```python\n# cook your dish here\n# cook your dish here\nfor i in range(int(input())):\n a=list(map(int,input().split()))\n x=input()\n t=0\n for i in range(ord('a'),ord('z')+1):\n if chr(i) not in x:\n t+=a[i-97]\n print(t)\n```","inputs":"2\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26\nabcdefghijklmopqrstuvwz\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26\nthequickbrownfoxjumpsoverthelazydog\n","output":"63\n0\n","actual_output":"63\n0\n","execution_success":true,"sample_index":204},{"source":"apps","task_type":"verifiable_code","in_source_id":"594","prompt":"Solve the following coding problem using the programming language python:\n\nYou are given a sequence of integers $A_1,A_2,\u2026,A_N$ and a magical non-zero integer $x$\nYou have to select a subsegment of sequence A (possibly empty), and replace the elements in that subsegment after dividing them by x.\nFormally, replace any one subsegment $A_l, A_{l+1}, ..., A_r$ with $A_l/x, A_{l+1}/x, ..., A_r/x$ where $l \\leq r$\nWhat is the minimum possible sum you can obtain?\nNote: The given operation can only be performed once\n\n-----Input -----\n- The first line of the input contains two positive integer n denoting the size of array, and x\ndenoting the magical integer\n- Next line contains $N$ space separated integers\n\n-----Output-----\nSingle line containing one real number, denoting the minimum possible sum you can obtain. Your answer will be considered correct if its absolute or relative error does not exceed $10^{-2}$\n\n-----Constraints-----\n- $1 \\leq n \\leq 10^3$\n- $1 \\leq |x| \\leq 10^3$\n- $ |A_i| \\leq 10^3$\n\n-----Sample Input-----\n3 2\n1 -2 3\n\n-----Sample Output-----\n0.5\n\n-----Explanation-----\nArray 1 -2 3, selecting subsegment {3}, you get 1 -2 1.5, which gives $sum=0.5$\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\ndef solve(a,n):\n max1=curr=a[0]\n for i in range(1,n):\n curr=max(a[i],curr+a[i])\n max1=max(max1,curr)\n return max1\n \nn,k = list(map(int,input().split()))\na = list(map(int,input().split()))\nprint(sum(a)-solve(a,n)+solve(a,n)/k)\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3 2\\n1 -2 3\\n', 'output': '0.5\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/SMALLARR'}","problem_id":"vfc_1218","program":"```python\ndef solve(a,n):\n max1=curr=a[0]\n for i in range(1,n):\n curr=max(a[i],curr+a[i])\n max1=max(max1,curr)\n return max1\n \nn,k = list(map(int,input().split()))\na = list(map(int,input().split()))\nprint(sum(a)-solve(a,n)+solve(a,n)/k)\n\n```","inputs":"3 2\n1 -2 3\n","output":"0.5\n","actual_output":"0.5\n","execution_success":true,"sample_index":205},{"source":"apps","task_type":"verifiable_code","in_source_id":"595","prompt":"Solve the following coding problem using the programming language python:\n\nYou are given a string $S$. Find the number of ways to choose an unordered pair of non-overlapping non-empty substrings of this string (let's denote them by $s_1$ and $s_2$ in such a way that $s_2$ starts after $s_1$ ends) such that their concatenation $s_1 + s_2$ is a palindrome.\nTwo pairs $(s_1, s_2)$ and $(s_1', s_2')$ are different if $s_1$ is chosen at a different position from $s_1'$ or $s_2$ is chosen at a different position from $s_2'$.\n\n-----Input-----\nThe first and only line of the input contains a single string $S$.\n\n-----Output-----\nPrint a single line containing one integer \u2014 the number of ways to choose a valid pair of substrings.\n\n-----Constraints-----\n- $1 \\le |S| \\le 1,000$\n- $S$ contains only lowercase English letters\n\n-----Subtasks-----\nSubtask #1 (25 points): $|S| \\le 100$\nSubtask #2 (75 points): original constraints\n\n-----Example Input-----\nabba\n\n-----Example Output-----\n7\n\n-----Explanation-----\nThe following pairs of substrings can be chosen: (\"a\", \"a\"), (\"a\", \"ba\"), (\"a\", \"bba\"), (\"ab\", \"a\"), (\"ab\", \"ba\"), (\"abb\", \"a\"), (\"b\", \"b\").\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\ndef binarySearch(arr, l, r, x):\n mid=0\n while l <= r: \n mid = l + (r - l)//2; \n if arr[mid] == x: \n return mid+1 \n elif arr[mid] < x: \n l = mid + 1\n else: \n r = mid - 1\n if mid!=len(arr):\n if arr[mid]=n:\n break\n if (s[i-j]==s[i+j]):\n if i-j-1>=0:\n strt[i-j-1].append(2*j+1)\n if i+j+1=n:\n break\n if (s[i-j]==s[i+j+1]):\n if i-j-1>=0:\n strt[i-j-1].append(2*j+2)\n if i+j+20 and j=n:\n break\n if (s[i-j]==s[i+j]):\n if i-j-1>=0:\n strt[i-j-1].append(2*j+1)\n if i+j+1=n:\n break\n if (s[i-j]==s[i+j+1]):\n if i-j-1>=0:\n strt[i-j-1].append(2*j+2)\n if i+j+20 and j=0 and j>=0:\n count+=1 \n if i>=0 and j-1>=0:\n count+=1 \n if i+1<=r-1 and j<=c-1:\n count+=1 \n if i<=r-1 and j+1<=c-1:\n count +=1\n if count<=p:\n ans = \"Unstable\"\n break\n print(ans) \n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n3 3\\n1 2 1\\n2 3 2\\n1 2 1\\n3 4\\n0 0 0 0\\n0 0 0 0\\n0 0 4 0\\n', 'output': 'Stable\\nUnstable\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/REACTION'}","problem_id":"vfc_1258","program":"```python\nfor _ in range(int(input())):\n r,c = map(int,input().split())\n l = []\n for k in range(r):\n a = list(map(int,input().split()))\n l.append(a)\n ans = \"Stable\" \n for i in range(r):\n for j in range(c):\n p = l[i][j]\n count=0\n if i-1>=0 and j>=0:\n count+=1 \n if i>=0 and j-1>=0:\n count+=1 \n if i+1<=r-1 and j<=c-1:\n count+=1 \n if i<=r-1 and j+1<=c-1:\n count +=1\n if count<=p:\n ans = \"Unstable\"\n break\n print(ans) \n```","inputs":"2\n3 3\n1 2 1\n2 3 2\n1 2 1\n3 4\n0 0 0 0\n0 0 0 0\n0 0 4 0\n","output":"Stable\nUnstable\n","actual_output":"Stable\nUnstable\n","execution_success":true,"sample_index":215},{"source":"apps","task_type":"verifiable_code","in_source_id":"605","prompt":"Solve the following coding problem using the programming language python:\n\nThere is a rectangular grid of cells consisting of n rows and m columns.\nYou will place a robot on one of the grid cells and provide it with a command string s, consisting of characters \u2018L\u2019, \u2018R\u2019, \u2018U\u2019, \u2018D\u2019.\nAfter being placed, the robot will follow the instructions of the command string, where 'L' corresponds moving to the left, 'R' towards the right, 'U' for moving up, and 'D' means down.\n\nYou have already selected the command string s, and are wondering if it is possible to place the robot in one of the grid cells initially and have it always stay entirely within the grid upon execution of the command string s.\nOutput \u201csafe\u201d if there is a starting cell for which the robot doesn\u2019t fall off the grid on following command s, otherwise, output \"unsafe\".\n\n-----Input-----\n\nThe first line of input will contain an integer T, the number of test cases.\n\nEach test case will be on two lines. \n\nThe first line will have two space separated integers n,m. \n\nThe second line will have the command string s.\n\n-----Output-----\n\nFor each test case, output \"safe\" (without quotes) or \"unsafe\" (without quotes) in a new line.\n\n-----Constraints-----\n- 1 \u2264 T \u2264 1,000\n- 1 \u2264 n,m \u2264 10\n- 1 \u2264 |s| \u2264 10\n\n-----Example-----\nInput:\n5\n1 1\nR\n2 3\nLLRU\n3 2\nLLRU\n4 3\nULURUDRDLD\n3 6\nRURUR\n\nOutput:\nunsafe\nsafe\nunsafe\nsafe\nsafe\n\n-----Explanation-----\n\nFor the first case, there is only one grid square, so we must place our robot there. When the robot follows the command, it'll fall off, so it is unsafe.\n\nFor the second case, we can place the robot on the bottom right grid square. Here is an image denoting the moves that the robot will make.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\ntest=int(input())\nfor _ in range(test):\n b=list(map(int,str(input()).split(' ')))\n c=str(input())\n li1=[0]\n li2=[0]\n for i1 in range(len(c)):\n if c[i1]=='R':\n li1.append(li1[len(li1)-1]+1)\n elif c[i1]=='L':\n li1.append(li1[len(li1)-1]-1)\n elif c[i1]=='U':\n li2.append(li2[len(li2)-1]+1)\n else:\n li2.append(li2[len(li2)-1]-1)\n if (max(li1)-min(li1)+1)<=b[1] and (max(li2)-min(li2)+1)<=b[0]:\n print('safe')\n else:\n print('unsafe')\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '5\\n1 1\\nR\\n2 3\\nLLRU\\n3 2\\nLLRU\\n4 3\\nULURUDRDLD\\n3 6\\nRURUR\\n', 'output': 'unsafe\\nsafe\\nunsafe\\nsafe\\nsafe\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/ROBOTG'}","problem_id":"vfc_1262","program":"```python\n# cook your dish here\ntest=int(input())\nfor _ in range(test):\n b=list(map(int,str(input()).split(' ')))\n c=str(input())\n li1=[0]\n li2=[0]\n for i1 in range(len(c)):\n if c[i1]=='R':\n li1.append(li1[len(li1)-1]+1)\n elif c[i1]=='L':\n li1.append(li1[len(li1)-1]-1)\n elif c[i1]=='U':\n li2.append(li2[len(li2)-1]+1)\n else:\n li2.append(li2[len(li2)-1]-1)\n if (max(li1)-min(li1)+1)<=b[1] and (max(li2)-min(li2)+1)<=b[0]:\n print('safe')\n else:\n print('unsafe')\n```","inputs":"5\n1 1\nR\n2 3\nLLRU\n3 2\nLLRU\n4 3\nULURUDRDLD\n3 6\nRURUR\n","output":"unsafe\nsafe\nunsafe\nsafe\nsafe\n","actual_output":"unsafe\nsafe\nunsafe\nsafe\nsafe\n","execution_success":true,"sample_index":216},{"source":"apps","task_type":"verifiable_code","in_source_id":"606","prompt":"Solve the following coding problem using the programming language python:\n\nConsider the infinite x$x$ axis. There are N$N$ impacts on this X-axis at integral points (X1$X_1$,X2$X_2$,....XN$X_N$) (all distinct) . An impact at a point X$X$i propagates such that at a point X$X$0, the effect of the impact is K|Xi\u2212X0|$K^{|X_i - X_0|}$. Given the point X0$X_0$, N$N$ and K$K$. Assume the total impact on X0$X_0$ is M$M$, find if it is possible to do so.Note: You are not required to find the set X\n\nFormally print \"yes\" if this is possible and \"no\" if not possible.\n\n-----Input:-----\n- First line will contain T$T$, number of testcases. Then the testcases follow. \n- Each testcase contains of a single line of input, four integers N$N$,K$K$,M$M$,X$X$0 \n\n-----Output:-----\n- The output of each test case is either \"yes\" or \"no\"\n\n-----Constraints -----\n- 1\u2264T\u22641000$1\\leq T \\leq 1000$\n- 1\u2264N\u2264100$1\\leq N \\leq 100$\n- 1\u2264K\u22641000$1\\leq K \\leq 1000$\n- 1\u2264M\u22641018$1\\leq M \\leq 10^{18}$\n- \u2212109\u2264X0\u2264109$-10^9 \\leq X_0 \\leq 10^9$ \n\n-----Sample Input:-----\n\t2\n\n4 3 10 10\n\n2 3 10 10\n\n-----Sample Output:-----\n\tno\n\nyes\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\nT = int(input())\nfor i in range(T):\n l = list(map(int, input().split()))\n n, k, m, x = l[0], l[1], l[2], l[3]\n if k == 1:\n if n == m:\n print(\"yes\")\n else:\n print(\"no\")\n elif m % k > 1:\n print(\"no\")\n elif k == 2:\n stack = []\n var = 0\n while m != 0:\n var += m % k\n stack.append(m % k)\n m //= k\n if var > n:\n print(\"no\")\n elif var == n:\n print(\"yes\")\n else:\n for p in range(100):\n for q in range(2, len(stack)):\n if stack[q - 1] == 0 and stack[q] >= 1:\n stack[q-1] = 2\n stack[q] -= 1\n var += 1\n if var == n:\n print(\"yes\")\n if var < n:\n print(\"no\")\n else:\n temp = 0\n rog = 1\n while m != 0:\n if m % k > 2:\n rog = 0\n print(\"no\")\n temp += m % k\n m //= k\n if rog:\n if temp == n:\n print(\"yes\")\n else:\n print(\"no\")\n\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n4 3 10 10\\n2 3 10 10\\n', 'output': 'no\\nyes\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/IMPACT'}","problem_id":"vfc_1266","program":"```python\n# cook your dish here\nT = int(input())\nfor i in range(T):\n l = list(map(int, input().split()))\n n, k, m, x = l[0], l[1], l[2], l[3]\n if k == 1:\n if n == m:\n print(\"yes\")\n else:\n print(\"no\")\n elif m % k > 1:\n print(\"no\")\n elif k == 2:\n stack = []\n var = 0\n while m != 0:\n var += m % k\n stack.append(m % k)\n m //= k\n if var > n:\n print(\"no\")\n elif var == n:\n print(\"yes\")\n else:\n for p in range(100):\n for q in range(2, len(stack)):\n if stack[q - 1] == 0 and stack[q] >= 1:\n stack[q-1] = 2\n stack[q] -= 1\n var += 1\n if var == n:\n print(\"yes\")\n if var < n:\n print(\"no\")\n else:\n temp = 0\n rog = 1\n while m != 0:\n if m % k > 2:\n rog = 0\n print(\"no\")\n temp += m % k\n m //= k\n if rog:\n if temp == n:\n print(\"yes\")\n else:\n print(\"no\")\n\n\n```","inputs":"2\n4 3 10 10\n2 3 10 10\n","output":"no\nyes\n","actual_output":"no\nyes\n","execution_success":true,"sample_index":217},{"source":"apps","task_type":"verifiable_code","in_source_id":"607","prompt":"Solve the following coding problem using the programming language python:\n\nYou are given a sequence $A_1, A_2, \\ldots, A_N$. You have to split the array into maximum number of non-empty subarrays such that the gcd of elements of each subarray is equal to 1.\n\n-----Input:-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The first line of each test case contains a single integer $N$.\n- The second line contains $N$ space-separated integers $A_1, A_2, \\ldots, A_N$.\n\n-----Output:-----\nFor each test case, print a single line containing one integer \u2015 the maximum number of subarrays formed, or $-1$ if the array cannot be split while satisfying the above condition.\n\n-----Constraints-----\n- $1 \\le T \\le 3$\n- $1 \\le N \\le 5 \\cdot 10^5$\n- $1 \\le A_i \\le 10^6$ for each valid $i$\n\n-----Sample Input:-----\n2\n3\n2 2 3\n4\n2 3 3 2\n\n-----Sample Output:-----\n1\n2\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n'''input\n2\n3\n2 2 3\n4\n2 3 3 2\n'''\nimport math\n\nfor _ in range(int(input())):\n n = int(input())\n a = list(map(int, input().split()))\n count = 0\n i = 0\n while i < len(a):\n if a[i] == 1:\n count += 1\n i += 1\n continue\n curr_gcd = a[i]\n while i < len(a) and curr_gcd != 1:\n curr_gcd = math.gcd(curr_gcd, a[i])\n if curr_gcd == 1:\n count += 1\n i += 1\n # print(i)\n break\n i += 1\n print(count)\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n3\\n2 2 3\\n4\\n2 3 3 2\\n', 'output': '1\\n2\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/DECO2020/problems/DECOGCD'}","problem_id":"vfc_1270","program":"```python\n'''input\n2\n3\n2 2 3\n4\n2 3 3 2\n'''\nimport math\n\nfor _ in range(int(input())):\n n = int(input())\n a = list(map(int, input().split()))\n count = 0\n i = 0\n while i < len(a):\n if a[i] == 1:\n count += 1\n i += 1\n continue\n curr_gcd = a[i]\n while i < len(a) and curr_gcd != 1:\n curr_gcd = math.gcd(curr_gcd, a[i])\n if curr_gcd == 1:\n count += 1\n i += 1\n # print(i)\n break\n i += 1\n print(count)\n\n```","inputs":"2\n3\n2 2 3\n4\n2 3 3 2\n","output":"1\n2\n","actual_output":"1\n2\n","execution_success":true,"sample_index":218},{"source":"apps","task_type":"verifiable_code","in_source_id":"609","prompt":"Solve the following coding problem using the programming language python:\n\nChef published a blog post, and is now receiving many queries about it. On day $i$, he receives $Q_i$ queries. But Chef can answer at most $k$ queries in a single day. \nChef always answers the maximum number of questions that he can on any given day (note however that this cannot be more than $k$). The remaining questions (if any) will be carried over to the next day.\nFortunately, after $n$ days, the queries have stopped. Chef would like to know the first day during which he has some free time, i.e. the first day when he answered less than $k$ questions. \n\n-----Input:-----\n- First line will contain $T$, the number of testcases. Then the testcases follow.\n- The first line of each testcase contains two space separated integers $n$ and $k$.\n- The second line of each testcase contains $n$ space separated integers, namely $Q_1, Q_2, ... Q_n$.\n\n-----Output:-----\nFor each testcase, output in a single line the first day during which chef answers less than $k$ questions. \n\n-----Constraints-----\n- $1 \\leq T \\leq 10^5$\n- $1 \\leq $ sum of $n$ over all testcases $ \\leq 10^5$\n- $1 \\leq k \\leq 10^8$\n- $0 \\leq Q_i \\leq 10^8$\n\n-----Subtasks-----\n- Subtask 1 - 20% points - Sum of $Q_i$ over all testcases and days $\\leq 3 . 10^6$\n- Subtask 2 - 80% points - Original constraints\n\n-----Sample Input:-----\n2 \n6 5 \n10 5 5 3 2 1 \n1 1\n100\n\n-----Sample Output:-----\n6\n101\n\n-----Explanation:-----\nTest Case 1\nOn the first day, chef answers 5 questions and leaves the remaining 5 (out of the 10) for the future days.\nOn the second day, chef has 10 questions waiting to be answered (5 received on the second day and 5 unanswered questions from day 1). Chef answers 5 of these questions and leaves the remaining 5 for the future.\nOn the third day, chef has 10 questions waiting to be answered (5 received on the third day and 5 unanswered questions from earlier). Chef answers 5 of these questions and leaves the remaining 5 for later.\nOn the fourth day, chef has 8 questions waiting to be answered (3 received on the fourth day and 5 unanswered questions from earlier). Chef answers 5 of these questions and leaves the remaining 3 for later.\nOn the fifth day, chef has 5 questions waiting to be answered (2 received on the fifth day and 3 unanswered questions from earlier). Chef answers all 5 of these questions.\nOn the sixth day, chef has 1 question, which he answers. This is the first day he answers less than 5 questions, and so the answer is 6.\nTest Case 2\nChef answers 1 question a day for the first 100 days. On day 101, he is free.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\n\nt=int(input())\nwhile(t):\n t=t-1\n n,k=list(map(int,input().split()))\n q=list(map(int,input().split()))\n days,rem=0,0\n for i in range(n):\n rem+=q[i]\n if(rem>=k):\n rem-=k\n else:\n days=i+1\n break\n days+=1\n if(rem>=k):\n days+=(rem//k)+1\n print(days)\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n6 5\\n10 5 5 3 2 1\\n1 1\\n100\\n', 'output': '6\\n101\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/CHEFEZQ'}","problem_id":"vfc_1278","program":"```python\n# cook your dish here\n\nt=int(input())\nwhile(t):\n t=t-1\n n,k=list(map(int,input().split()))\n q=list(map(int,input().split()))\n days,rem=0,0\n for i in range(n):\n rem+=q[i]\n if(rem>=k):\n rem-=k\n else:\n days=i+1\n break\n days+=1\n if(rem>=k):\n days+=(rem//k)+1\n print(days)\n\n```","inputs":"2\n6 5\n10 5 5 3 2 1\n1 1\n100\n","output":"6\n101\n","actual_output":"6\n101\n","execution_success":true,"sample_index":219},{"source":"apps","task_type":"verifiable_code","in_source_id":"610","prompt":"Solve the following coding problem using the programming language python:\n\nDue to the COVID pandemic, people have been advised to stay at least $6$ feet away from any other person. Now, people are lining up in a queue at the local shop and it is your duty to check whether they are all following this advice.\nThere are a total of $N$ spots (numbered $1$ through $N$) where people can stand in front of the local shop. The distance between each pair of adjacent spots is $1$ foot. Each spot may be either empty or occupied; you are given a sequence $A_1, A_2, \\ldots, A_N$, where for each valid $i$, $A_i = 0$ means that the $i$-th spot is empty, while $A_i = 1$ means that there is a person standing at this spot. It is guaranteed that the queue is not completely empty.\nFor example, if $N = 11$ and the sequence $A$ is $(0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1)$, then this is a queue in which people are not following the advice because there are two people at a distance of just $3$ feet from each other.\nYou need to determine whether the people outside the local shop are following the social distancing advice or not. As long as some two people are standing at a distance smaller than 6 feet from each other, it is bad and you should report it, since social distancing is not being followed.\n\n-----Input-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The first line of each test case contains a single integer $N$.\n- The next line contains $N$ space-separated integers $A_1, A_2, \\ldots, A_N$.\n\n-----Output-----\nFor each test case, print a single line containing the string \"YES\" if social distancing is being followed or \"NO\" otherwise (without quotes).\n\n-----Constraints-----\n- $1 \\le T \\le 100$\n- $1 \\le N \\le 100$\n- $0 \\le A_i \\le 1$ for each valid $i$\n- at least one spot is occupied\n\n-----Subtasks-----\nSubtask #1 (100 points): original constraints\n\n-----Example Input-----\n3\n3\n1 0 1\n7\n1 0 0 0 0 0 1\n11\n0 1 0 0 0 0 0 1 0 0 1\n\n-----Example Output-----\nNO\nYES\nNO\n\n-----Explanation-----\nExample case 1: The first and third spots are occupied and the distance between them is $2$ feet.\nExample case 2: The first and seventh spots are occupied and the distance between them is $6$ feet.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\nt=int(input())\nwhile t>0:\n n=int(input())\n l=list(map(int,input().split()))\n l1=[]\n c=1\n for i in range(len(l)):\n if l[i]==1:\n l1.append(i)\n for j in range(len(l1)-1):\n if l1[j+1]-l1[j]<6:\n c=0\n break\n if c:\n print(\"YES\")\n else:\n print(\"NO\")\n \n t-=1\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\n3\\n1 0 1\\n7\\n1 0 0 0 0 0 1\\n11\\n0 1 0 0 0 0 0 1 0 0 1\\n\\n', 'output': 'NO\\nYES\\nNO\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/COVIDLQ'}","problem_id":"vfc_1282","program":"```python\n# cook your dish here\nt=int(input())\nwhile t>0:\n n=int(input())\n l=list(map(int,input().split()))\n l1=[]\n c=1\n for i in range(len(l)):\n if l[i]==1:\n l1.append(i)\n for j in range(len(l1)-1):\n if l1[j+1]-l1[j]<6:\n c=0\n break\n if c:\n print(\"YES\")\n else:\n print(\"NO\")\n \n t-=1\n```","inputs":"3\n3\n1 0 1\n7\n1 0 0 0 0 0 1\n11\n0 1 0 0 0 0 0 1 0 0 1\n\n","output":"NO\nYES\nNO\n","actual_output":"NO\nYES\nNO\n","execution_success":true,"sample_index":220},{"source":"apps","task_type":"verifiable_code","in_source_id":"611","prompt":"Solve the following coding problem using the programming language python:\n\n\"What do you know about happiness?\" \u2014 Yoda \nChef is happy only if three conditions hold:\n- Chef finished cooking a delicious meal\n- Chef got AC for a programming problem with an almost correct code\n- Chef got a new problem with a sequence of integers\nToday, all three conditions are satisfied. Chef would like you to feel his happiness and provide him with a solution for this new problem with a sequence of integers. The problem is as follows.\nYou are given a sequence $A_1, A_2, \\dots, A_N$. You need to determine if it is possible to choose two indices $i$ and $j$ such that $A_i \\neq A_j$, but $A_{A_i}$ = $A_{A_j}$. (If it was possible, Chef would be truly happy.)\n\n-----Input-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The first line of each test case contains a single integer $N$.\n- The second line contains $N$ space-separated integers $A_1, A_2, \\ldots, A_N$.\n\n-----Output-----\nFor each test case, print a single line containing the string \"Truly Happy\" if it is possible to choose required indices or \"Poor Chef\" otherwise.\n\n-----Constraints-----\n- $1 \\le T \\le 1,000$\n- $1 \\le N \\le 10^5$\n- $1 \\le A_i \\le N$ for each valid $i$\n- the sum of $N$ over all test cases does not exceed $2 \\cdot 10^5$\n\n-----Subtasks-----\nSubtask #1 (27 points): $1 \\le N \\le 1,000$\nSubtask #2 (73 points): original constraints\n\n-----Example Input-----\n4\n4\n1 1 2 3\n4\n2 1 3 3\n5\n5 4 4 3 1\n5\n3 2 1 1 4\n\n-----Example Output-----\nTruly Happy\nPoor Chef\nPoor Chef\nTruly Happy\n\n-----Explanation-----\nExample case 1: Chef is truly happy because $A_{A_3} = A_{A_1}$ and $A_3 \\neq A_1$.\nExample case 2: There is no pair of indices which would make Chef truly happy. For instance, $A_{A_3} = A_{A_4}$, but $A_3 = A_4$,\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\n\nt=int(input())\n\nfor i in range(t):\n n=int(input())\n a=list(map(int,input().split()))\n d={}\n for i in range(n):\n if a[i]-1 not in d:\n d[a[i]-1]=[i]\n else:\n d[a[i]-1].append(i)\n ans=False\n d1={}\n \n for i in d:\n if ans==True:\n break\n for j in d:\n if i!=j:\n if a[i]==a[j] and i!=j:\n ans=True\n break\n if ans==True:\n print('Truly Happy')\n else:\n print('Poor Chef')\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '4\\n4\\n1 1 2 3\\n4\\n2 1 3 3\\n5\\n5 4 4 3 1\\n5\\n3 2 1 1 4\\n', 'output': 'Truly Happy\\nPoor Chef\\nPoor Chef\\nTruly Happy\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/CHHAPPY'}","problem_id":"vfc_1286","program":"```python\n# cook your dish here\n\nt=int(input())\n\nfor i in range(t):\n n=int(input())\n a=list(map(int,input().split()))\n d={}\n for i in range(n):\n if a[i]-1 not in d:\n d[a[i]-1]=[i]\n else:\n d[a[i]-1].append(i)\n ans=False\n d1={}\n \n for i in d:\n if ans==True:\n break\n for j in d:\n if i!=j:\n if a[i]==a[j] and i!=j:\n ans=True\n break\n if ans==True:\n print('Truly Happy')\n else:\n print('Poor Chef')\n\n```","inputs":"4\n4\n1 1 2 3\n4\n2 1 3 3\n5\n5 4 4 3 1\n5\n3 2 1 1 4\n","output":"Truly Happy\nPoor Chef\nPoor Chef\nTruly Happy\n","actual_output":"Truly Happy\nPoor Chef\nPoor Chef\nTruly Happy\n","execution_success":true,"sample_index":221},{"source":"apps","task_type":"verifiable_code","in_source_id":"612","prompt":"Solve the following coding problem using the programming language python:\n\nLots of geeky customers visit our chef's restaurant everyday. So, when asked to fill the feedback form, these customers represent the feedback using a binary string (i.e a string that contains only characters '0' and '1'. \n\nNow since chef is not that great in deciphering binary strings, he has decided the following criteria to classify the feedback as Good or Bad : \n\nIf the string contains the substring \"010\" or \"101\", then the feedback is Good, else it is Bad. Note that, to be Good it is not necessary to have both of them as substring.\n\nSo given some binary strings, you need to output whether according to the chef, the strings are Good or Bad. \n\n-----Input-----\nThe first line contains an integer T denoting the number of feedbacks. Each of the next T lines contains a string composed of only '0' and '1'.\n\n-----Output-----\nFor every test case, print in a single line Good or Bad as per the Chef's method of classification.\n\n-----Constraints-----\n- 1 \u2264 T \u2264 100 \n- 1 \u2264 |S| \u2264 105 \n\nSum of length of all strings in one test file will not exceed 6*106.\n\n-----Example-----\nInput:\n2\n11111110\n10101010101010\n\nOutput:\nBad\nGood\n\n-----Explanation-----\nExample case 1.\n\nThe string doesn't contain 010 or 101 as substrings.\n\nExample case 2.\n\nThe string contains both 010 and 101 as substrings.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\nt=int(input())\nfor i in range(t):\n s=input()\n fl=-1\n n=len(s)\n for i in range(n-2):\n if(s[i:i+3]==\"010\" or s[i:i+3]==\"101\"):\n fl=0\n print(\"Good\")\n break\n\n if(fl==-1):\n print(\"Bad\")\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n11111110\\n10101010101010\\n', 'output': 'Bad\\nGood\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/ERROR'}","problem_id":"vfc_1290","program":"```python\n# cook your dish here\nt=int(input())\nfor i in range(t):\n s=input()\n fl=-1\n n=len(s)\n for i in range(n-2):\n if(s[i:i+3]==\"010\" or s[i:i+3]==\"101\"):\n fl=0\n print(\"Good\")\n break\n\n if(fl==-1):\n print(\"Bad\")\n\n```","inputs":"2\n11111110\n10101010101010\n","output":"Bad\nGood\n","actual_output":"Bad\nGood\n","execution_success":true,"sample_index":222},{"source":"apps","task_type":"verifiable_code","in_source_id":"613","prompt":"Solve the following coding problem using the programming language python:\n\n-----Problem-----\n\n\t\t\tNikki's latest work is writing a story of letters. However, she finds writing story so boring that, after working for three hours, she realized that all she has written are M long words consisting entirely of letters A and B. Having accepted that she will never finish the story in time, Nikki has decided to at least have some fun with it by counting bubbly words.\n\n\n\t\t\tNow Nikki is connecting pairs of identical letters (A with A, B with B) by drawing lines above the word. A given word is bubbly if each letter can be connected to exactly one other letter in such a way that no two lines intersect. So here is your task. Help Nikki count how many words are bubbly.\n\n-----Input-----\n- \n\t\t\tThe first line of input contains the positive integer M, the number of words written down by Nikki.\n\t\t\t\t\n- \n\t\t\tEach of the following M lines contains a single word consisting of letters A and B, with length\n\n\t\t\tbetween 2 and 10^5, inclusive. The sum of lengths of all words doesn't exceed 10^6.\n\t\t\t\t\n\n-----Output-----\n\n\t\t\tThe first and only line of output must contain the number of bubbly words.\n\t\t\n\n-----Constraints-----\n- \n\t\t\t1 \u2264 M \u2264 100\n\t\t\t\t\n\n-----Sample Input-----\n\n3\n\nABAB\n\nAABB\n\nABBA\n\n-----Sample Output-----\n2\n\n-----Explanation-----\n- \n\t\t\t\t\t ABAB - It is not bubbly as A(indexed 1) will connect to A(indexed 3) by a line and when we try to connect B(indexed 2) with B(indexed 4) by a line then it will intersect with the line b/w A and A.\n\t\t\t\t\n- \n\t\t\t\t\tAABB - It is bubbly as line b/w A and A will not intersect with the line b/w B and B.\n\t\t\t\n- \nABBA -It is also bubbly as lines will not intersect. We can draw line b/w A and A above the line b/w B and B.\n\t\t\t\t p { text-align:justify }\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\ndef check(s):\n arr=[s[0]]\n l=len(s)\n f1=0\n for i in range(1,l):\n if arr==[]: arr.append(s[i])\n elif arr[-1]!=s[i]:arr.append(s[i])\n else: del arr[-1]\n if arr==[]: return True\n else: return False\n \ncount = 0\nfor t in range(eval(input())):\n s=input().strip()\n if check(s): count+=1\nprint(count)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\nABAB\\nAABB\\nABBA\\n', 'output': '2\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/COMN2016/problems/NIKKLIN'}","problem_id":"vfc_1294","program":"```python\ndef check(s):\n arr=[s[0]]\n l=len(s)\n f1=0\n for i in range(1,l):\n if arr==[]: arr.append(s[i])\n elif arr[-1]!=s[i]:arr.append(s[i])\n else: del arr[-1]\n if arr==[]: return True\n else: return False\n \ncount = 0\nfor t in range(eval(input())):\n s=input().strip()\n if check(s): count+=1\nprint(count)\n```","inputs":"3\nABAB\nAABB\nABBA\n","output":"2\n","actual_output":"2\n","execution_success":true,"sample_index":223},{"source":"apps","task_type":"verifiable_code","in_source_id":"614","prompt":"Solve the following coding problem using the programming language python:\n\nChef would like go shopping to buy ingredients for his special dish. The local grocery store has some special discount offers. If you want to buy some set of ingredients you will pay for all ingredients except the cheapest one. Chef would like to spend as little money as possible. You have to help him. :)\n\nThe store is pretty small and stocks only one unit of each ingredients. Opposite each ingredient is a hanging price tag corresponding to it. The salesman walked away for a minute, giving Chef an opportunity to swap some price tags. He would like to swap some tags to minimize his purchase cost.\n\n-----Input-----\nThe first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows. \n\nThe first line of each test case contains a single integer N denoting the number of ingredients Chef needs to buy. The second line contains N space-separated integers A1, A2, ... , AN denoting the value written on the price tags opposite the needed ingredients. The third line contains a single integer M denoting the number of special offers. The following M lines lists inventory of special offers, one offer per line. Each line contains an integer Ci followed by Ci integers denoting the indices of ingredients constituting the ith discount offer.\n\n-----Output-----\nFor each test case, output a single line containing the minimal purchase cost.\n\n-----Constraints-----\n- T \u2264 5\n- 1 \u2264 N \u2264 15\n- 1 \u2264 Ai \u2264 106\n- 0 \u2264 M \u2264 2N-1\n- 2 \u2264 Ci \u2264 N\n- Subtask 1 (15 points): 1 \u2264 N \u2264 5\n- Subtask 2 (25 points): 1 \u2264 N \u2264 10\n- Subtask 3 (60 points): 1 \u2264 N \u2264 15\n\n-----Example-----\nInput:\n1\n4 \n1 2 3 4\n3\n2 1 2\n2 3 4\n3 1 2 3\n\nOutput:\n6\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfrom itertools import permutations as p\ndef disc(a,b):\n for ai in a:\n for bi in b:\n if ai==bi:\n return False\n return True\n\nfor i in range(eval(input())):\n n = eval(input())\n arr = list(map(int,input().split()))\n perms = list(p(arr))\n m = eval(input())\n offer = {}\n for i in range(m):\n dup = list(map(int,input().split()))\n try:\n offer[dup[0]].append(dup[1:])\n except:\n offer[dup[0]] = [dup[1:]]\n ans = sum(arr)\n if n==1:\n print(ans)\n elif n==2:\n try:\n if len(offer[2])>=1:\n ans -= min(arr)\n except:\n pass\n print(ans)\n elif n==3:\n try:\n if len(offer[3])>=1:\n ans -= min(arr)\n except:\n pass\n try:\n if len(offer[2])>=1:\n value = 9999999999\n for item in perms:\n cur = 0\n cur += item[0]\n cur += max(item[1],item[2])\n if cur=1:\n ans -= min(arr)\n except:\n pass\n #print ans\n try:\n if len(offer[3])>=1:\n value = 9999999999\n for item in perms:\n cur = 0\n cur = sum(item)\n cur -= min(item[1],item[2],item[3])\n if cur=1:\n value = 9999999999\n for item in perms:\n cur = 0\n cur = sum(item)\n cur -= min(item[1],item[2])\n if cur=2:\n flg = False\n end = len(offer[2])\n for i in range(end):\n for j in range(i+1,end):\n if disc(offer[2][i],offer[2][j]):\n flg = True\n break\n #print flg\n if flg:\n value = 9999999999\n for item in perms:\n cur = 0\n cur = sum(item)\n cur -= min(item[1],item[0])\n cur -= min(item[2],item[3])\n if cur=1:\n ans -= min(arr)\n except:\n pass\n try:\n if len(offer[4])>=1:\n value = 9999999999\n for item in perms:\n cur = 0\n cur = sum(item)\n cur -= min(item[1],item[2],item[3],item[4])\n if cur=1:\n value = 9999999999\n for item in perms:\n cur = 0\n cur = sum(item)\n cur -= min(item[1],item[2])\n if cur=2:\n flg = False\n end = len(offer[2])\n for i in range(end):\n for j in range(i+1,end):\n if disc(offer[2][i],offer[2][j]):\n flg = True\n break\n if flg:\n value = 9999999999\n for item in perms:\n cur = 0\n cur = sum(item)\n cur -= min(item[1],item[0])\n cur -= min(item[2],item[3])\n if cur=1:\n value = 9999999999\n for item in perms:\n cur = 0\n cur = sum(item)\n cur -= min(item[1],item[2],item[3])\n if cur=1 and len(offer[2])>=1:\n flg = False\n for i in offer[3]:\n for j in offer[2]:\n if disc(i,j):\n flg = True\n break\n if flg:\n value = 9999999999\n for item in perms:\n cur = 0\n cur = sum(item)\n cur -= min(item[1],item[0])\n cur -= min(item[2],item[3],item[4])\n if cur=1:\n ans -= min(arr)\n except:\n pass\n print(ans)\n elif n==3:\n try:\n if len(offer[3])>=1:\n ans -= min(arr)\n except:\n pass\n try:\n if len(offer[2])>=1:\n value = 9999999999\n for item in perms:\n cur = 0\n cur += item[0]\n cur += max(item[1],item[2])\n if cur=1:\n ans -= min(arr)\n except:\n pass\n #print ans\n try:\n if len(offer[3])>=1:\n value = 9999999999\n for item in perms:\n cur = 0\n cur = sum(item)\n cur -= min(item[1],item[2],item[3])\n if cur=1:\n value = 9999999999\n for item in perms:\n cur = 0\n cur = sum(item)\n cur -= min(item[1],item[2])\n if cur=2:\n flg = False\n end = len(offer[2])\n for i in range(end):\n for j in range(i+1,end):\n if disc(offer[2][i],offer[2][j]):\n flg = True\n break\n #print flg\n if flg:\n value = 9999999999\n for item in perms:\n cur = 0\n cur = sum(item)\n cur -= min(item[1],item[0])\n cur -= min(item[2],item[3])\n if cur=1:\n ans -= min(arr)\n except:\n pass\n try:\n if len(offer[4])>=1:\n value = 9999999999\n for item in perms:\n cur = 0\n cur = sum(item)\n cur -= min(item[1],item[2],item[3],item[4])\n if cur=1:\n value = 9999999999\n for item in perms:\n cur = 0\n cur = sum(item)\n cur -= min(item[1],item[2])\n if cur=2:\n flg = False\n end = len(offer[2])\n for i in range(end):\n for j in range(i+1,end):\n if disc(offer[2][i],offer[2][j]):\n flg = True\n break\n if flg:\n value = 9999999999\n for item in perms:\n cur = 0\n cur = sum(item)\n cur -= min(item[1],item[0])\n cur -= min(item[2],item[3])\n if cur=1:\n value = 9999999999\n for item in perms:\n cur = 0\n cur = sum(item)\n cur -= min(item[1],item[2],item[3])\n if cur=1 and len(offer[2])>=1:\n flg = False\n for i in offer[3]:\n for j in offer[2]:\n if disc(i,j):\n flg = True\n break\n if flg:\n value = 9999999999\n for item in perms:\n cur = 0\n cur = sum(item)\n cur -= min(item[1],item[0])\n cur -= min(item[2],item[3],item[4])\n if cur start:\n final[-1][0] = start\n else:\n start = final[-1][0]\n else:\n if final[-1][1] < end:\n final[-1][1] = end\n else:\n end = final[-1][1]\n final.append([start, end])\n else:\n if len(final) != 0:\n start, end = 0, n-1\n if j%2 == 0:\n if final[-1][0] > start:\n final[-1][0] = start\n else:\n start = final[-1][0]\n else:\n if final[-1][1] < end:\n final[-1][1] = end\n else:\n end = final[-1][1]\n final.append([start, end])\n if len(final) == 0:\n print(0)\n else:\n count = 0\n for ele in final:\n count += (ele[1]-ele[0]+1)\n print(count-1+extra)\n \n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n4 5\\nN P N N P\\nN N P N N\\nN P N N N\\nP N N N N\\n3 3\\nN P P\\nP P P\\nP P N\\n', 'output': '10\\n6\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/CHPTRS01/problems/CARLOT'}","problem_id":"vfc_1306","program":"```python\nfrom sys import stdin\n\nfor _ in range(int(stdin.readline())):\n m, n = list(map(int, stdin.readline().split()))\n final = []\n arr = []\n val = 0\n extra = 0\n for j in range(m):\n ans = list(map(str, stdin.readline().split()))\n if ans.count('N') == n:\n val += 1\n else:\n if val%2 == 0:\n arr.append(ans)\n extra += val\n else:\n arr.append(['N']*n)\n arr.append(ans)\n extra += (val-1)\n val = 0\n\n for j in range(len(arr)):\n ans = arr[j]\n start = -1\n for i in range(n):\n if ans[i] == 'P':\n start = i\n break\n if start != -1:\n for i in range(n-1, -1, -1):\n if ans[i] == 'P':\n end = i\n break\n if start != -1:\n if len(final) == 0:\n final.append([start, end])\n else:\n if j%2 == 0:\n if final[-1][0] > start:\n final[-1][0] = start\n else:\n start = final[-1][0]\n else:\n if final[-1][1] < end:\n final[-1][1] = end\n else:\n end = final[-1][1]\n final.append([start, end])\n else:\n if len(final) != 0:\n start, end = 0, n-1\n if j%2 == 0:\n if final[-1][0] > start:\n final[-1][0] = start\n else:\n start = final[-1][0]\n else:\n if final[-1][1] < end:\n final[-1][1] = end\n else:\n end = final[-1][1]\n final.append([start, end])\n if len(final) == 0:\n print(0)\n else:\n count = 0\n for ele in final:\n count += (ele[1]-ele[0]+1)\n print(count-1+extra)\n \n\n```","inputs":"2\n4 5\nN P N N P\nN N P N N\nN P N N N\nP N N N N\n3 3\nN P P\nP P P\nP P N\n","output":"10\n6\n","actual_output":"10\n6\n","execution_success":true,"sample_index":226},{"source":"apps","task_type":"verifiable_code","in_source_id":"617","prompt":"Solve the following coding problem using the programming language python:\n\nWe all know that Share market is place where drastic change occurs within moments. So we have one Stockholder, Isabella, who wants to maximize her profit by selling her shares. She has $N$ shares of a Doofenshmirtz Corporation which is represented by $N$ different lines where each line contains two space separated integers $a_i$ , $b_i$ corresponding to initial and final values of the share prize. Isabella can sell any number of shares. But, she will sell those shares only if the following condition is satisfied - \n- for any pair $(i,j)$ of shares that she choses to sell, $a_i \\leq a_j$ and $b_i < b_j$ must be satisfied. \nYou need to tell Isabella the maximum number of Shares she can sell.\n\n-----Input:-----\n- First line will contain $T$, number of test cases. \n- Each test case has the following format:\n- First line of each test case contain single integer $N$, the number of shares of Isabella. \n- Next $N$ lines of each test case contain two space separated integers $a_i$, $b_i$ (initial and final value of share prize respectively) for each $1 \\leq i \\leq N$.\n\n-----Output:-----\nFor each test case output a single integer: the maximum number of shares that can be sold by Isabella.\n\n-----Constraints-----\n- $1 \\leq T \\leq 5$\n- $1 \\leq N \\leq 10^5$\n- $1 \\leq a_i , b_i \\leq 10^9 , for each $1$ \\leq $i$ \\leq $N \n\n-----Sample Input:-----\n$1$\n$4$ \n$1$ $2$\n$4$ $3$\n$3$ $5$ \n$2$ $4$ \n\n-----Sample Output:-----\n$3$ \n\n-----Explanation:-----\nHere, Isabella decided to sell share 1, share 3 and share 4 as any two pair of \nchosen share hold the given condition.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\ndef CeilIndex(A, l, r, key): \n \n while (r - l > 1): \n \n m = l + (r - l)//2\n if (A[m] >= key): \n r = m \n else: \n l = m \n return r \n \ndef LongestIncreasingSubsequenceLength(A, size): \n \n # Add boundary case, \n # when array size is one \n \n tailTable = [0 for i in range(size + 1)] \n len = 0 # always points empty slot \n \n tailTable[0] = A[0] \n len = 1\n for i in range(1, size): \n \n if (A[i] < tailTable[0]): \n \n # new smallest value \n tailTable[0] = A[i] \n \n elif (A[i] > tailTable[len-1]): \n \n # A[i] wants to extend \n # largest subsequence \n tailTable[len] = A[i] \n len+= 1\n \n else: \n # A[i] wants to be current \n # end candidate of an existing \n # subsequence. It will replace \n # ceil value in tailTable \n tailTable[CeilIndex(tailTable, -1, len-1, A[i])] = A[i] \n \n \n return len\nt=int(input())\nfor _ in range(t):\n n=int(input())\n a=[]\n for i in range(n):\n a.append(list(map(int,input().split())))\n a.sort()\n b=[0]*n\n for i in range(n):\n b[i]=a[i][1]\n \n print(LongestIncreasingSubsequenceLength(b, n)) \n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n4\\n1 2\\n4 3\\n3 5\\n2 4\\n', 'output': '3\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/CACD2020/problems/STOCKMAX'}","problem_id":"vfc_1310","program":"```python\ndef CeilIndex(A, l, r, key): \n \n while (r - l > 1): \n \n m = l + (r - l)//2\n if (A[m] >= key): \n r = m \n else: \n l = m \n return r \n \ndef LongestIncreasingSubsequenceLength(A, size): \n \n # Add boundary case, \n # when array size is one \n \n tailTable = [0 for i in range(size + 1)] \n len = 0 # always points empty slot \n \n tailTable[0] = A[0] \n len = 1\n for i in range(1, size): \n \n if (A[i] < tailTable[0]): \n \n # new smallest value \n tailTable[0] = A[i] \n \n elif (A[i] > tailTable[len-1]): \n \n # A[i] wants to extend \n # largest subsequence \n tailTable[len] = A[i] \n len+= 1\n \n else: \n # A[i] wants to be current \n # end candidate of an existing \n # subsequence. It will replace \n # ceil value in tailTable \n tailTable[CeilIndex(tailTable, -1, len-1, A[i])] = A[i] \n \n \n return len\nt=int(input())\nfor _ in range(t):\n n=int(input())\n a=[]\n for i in range(n):\n a.append(list(map(int,input().split())))\n a.sort()\n b=[0]*n\n for i in range(n):\n b[i]=a[i][1]\n \n print(LongestIncreasingSubsequenceLength(b, n)) \n\n```","inputs":"1\n4\n1 2\n4 3\n3 5\n2 4\n","output":"3\n","actual_output":"3\n","execution_success":true,"sample_index":227},{"source":"apps","task_type":"verifiable_code","in_source_id":"618","prompt":"Solve the following coding problem using the programming language python:\n\nDexter, being irritated by DD, gave her a lucrative game to play to keep her busy.\nThere are $N$ bags numbered $1$ to $N$. The $i_{th}$ bag contains $A_i$ coins. The bags are placed in a circular order such that the $N_{th}$ bag is adjacent to the $1^{st}$ bag. \nDD can select $K$ consecutive adjacent bags and take all the coins in them. Help her find the maximum number of coins she can take by making the ideal choice.\nNote that the selected bags must be consecutive. Since they are placed in circular order, bag number $1$ and $N$ are considered to be consecutive.\n\n-----Input:-----\n- First-line will contain $T$, the number of test cases. Then the test cases follow. \n- First-line contains $N$ and $K$.\n- Second-line contains $N$ numbers $A_1, A_2,...,A_N$, \n\n-----Output:-----\nFor each test case, output in a single line, the maximum money that can be collected by DD.\n\n-----Constraints-----\n- $1 \\leq T \\leq 100$\n- $5 \\leq N \\leq 10^5$\n- $1 \\leq K < N$\n- $1 \\leq A_i \\leq 10^5$\nSum of $N$ over all test cases is less than $10^6$\n\n-----Sample Input:-----\n1\n5 3\n8 6 9 4 10\n\n-----Sample Output:-----\n24\n\n-----EXPLANATION:-----\nThe ideal choice would be to take the last bag with $10$ coins and the first $2$ bags with $8$ and $6$ coins.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nt=int(input())\nfor i in range(t):\n n,k=list(map(int,input().split(\" \")))\n arr=list(map(int,input().strip().split(\" \")))[:n]\n def maxCircularSum(arr, n, k):\n if (n < k):\n print(\"Invalid\");\n return;\n\n sum = 0;\n start = 0;\n end = k - 1;\n\n for i in range(k):\n sum += arr[i];\n\n ans = sum;\n\n for i in range(k, n + k):\n sum += arr[i % n] - arr[(i - k) % n];\n\n if (sum > ans):\n ans = sum;\n start = (i - k + 1) % n;\n end = i % n;\n\n print(ans);\n\n def __starting_point():\n maxCircularSum(arr, n, k);\n__starting_point()\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n5 3\\n8 6 9 4 10\\n', 'output': '24\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/ENCD2020/problems/ECAPR206'}","problem_id":"vfc_1314","program":"```python\nt=int(input())\nfor i in range(t):\n n,k=list(map(int,input().split(\" \")))\n arr=list(map(int,input().strip().split(\" \")))[:n]\n def maxCircularSum(arr, n, k):\n if (n < k):\n print(\"Invalid\");\n return;\n\n sum = 0;\n start = 0;\n end = k - 1;\n\n for i in range(k):\n sum += arr[i];\n\n ans = sum;\n\n for i in range(k, n + k):\n sum += arr[i % n] - arr[(i - k) % n];\n\n if (sum > ans):\n ans = sum;\n start = (i - k + 1) % n;\n end = i % n;\n\n print(ans);\n\n def __starting_point():\n maxCircularSum(arr, n, k);\n__starting_point()\n```","inputs":"1\n5 3\n8 6 9 4 10\n","output":"24\n","actual_output":"24\n","execution_success":true,"sample_index":228},{"source":"apps","task_type":"verifiable_code","in_source_id":"619","prompt":"Solve the following coding problem using the programming language python:\n\nIn a regular table tennis match, the player who serves changes every time after 2 points are scored, regardless of which players scored them.\nChef and Cook are playing a different match \u2014 they decided that the player who serves would change every time after $K$ points are scored instead (again regardless of which players scored them). When the game starts, it's Chef's turn to serve.\nYou are given the current number of points scored by Chef and Cook ($P_1$ and $P_2$ respectively). Find out whether Chef or Cook has to serve next.\n\n-----Input-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The first and only line of each test case contains three space-separated integers $P_1$, $P_2$ and $K$.\n\n-----Output-----\nFor each test case, print a single line containing the string \"CHEF\" if it is Chef's turn or \"COOK\" if it is Cook's turn.\n\n-----Constraints-----\n- $1 \\le T \\le 10^5$\n- $1 \\le K \\le 10^{9}$\n- $0 \\le P_1, P_2 \\le 10^{9}$ \n\n-----Subtasks-----\nSubtask #1 (100 points): original constraints\n\n-----Example Input-----\n3\n1 3 2\n0 3 2\n34 55 2\n\n-----Example Output-----\nCHEF\nCOOK\nCHEF\n\n-----Explanation-----\nExample case 1: Chef serves for the first two points, Cook serves for the next two, so Chef has to serve again now.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nn=int(input())\nfor i in range(n):\n l=list(map(int,input().split()))\n k=l[0]+l[1]\n k=k%(2*l[2])\n \n if k>=0 and k=0 and kk:\n if a[i] not in d: \n d[a[i]]=1\n else: \n d[a[i]]+=1\n if len(d)==1:\n return True\n for i in range(mid,n):\n if a[left]>k:\n d[a[left]]-=1\n if d[a[left]]==0: \n del d[a[left]]\n if a[i]>k:\n if a[i] not in d: \n d[a[i]]=1\n else: \n d[a[i]]+=1\n if len(d)==1: \n return True\n left+=1\n return False\n \n lo,hi=0,n\n while lo<=hi:\n mid=(lo+hi)//2\n #print(mid,lo,hi)\n if check(mid):\n res=mid\n lo=mid+1\n else:\n hi=mid-1\n print(res)\n \n \n \n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n5 3\\n2 4 2 4 2\\n8 5\\n9 3 5 7 8 11 17 2\\n', 'output': '5\\n3\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/SLAEL'}","problem_id":"vfc_1322","program":"```python\nfor _ in range(int(input())):\n n,k=list(map(int,input().split()))\n a=list(map(int,input().split()))\n def check(mid):\n d,left={},0\n for i in range(mid):\n if a[i]>k:\n if a[i] not in d: \n d[a[i]]=1\n else: \n d[a[i]]+=1\n if len(d)==1:\n return True\n for i in range(mid,n):\n if a[left]>k:\n d[a[left]]-=1\n if d[a[left]]==0: \n del d[a[left]]\n if a[i]>k:\n if a[i] not in d: \n d[a[i]]=1\n else: \n d[a[i]]+=1\n if len(d)==1: \n return True\n left+=1\n return False\n \n lo,hi=0,n\n while lo<=hi:\n mid=(lo+hi)//2\n #print(mid,lo,hi)\n if check(mid):\n res=mid\n lo=mid+1\n else:\n hi=mid-1\n print(res)\n \n \n \n\n```","inputs":"2\n5 3\n2 4 2 4 2\n8 5\n9 3 5 7 8 11 17 2\n","output":"5\n3\n","actual_output":"5\n3\n","execution_success":true,"sample_index":230},{"source":"apps","task_type":"verifiable_code","in_source_id":"621","prompt":"Solve the following coding problem using the programming language python:\n\nGiven n words w[1..n], which originate from the same stem (e.g. grace, graceful, disgraceful, gracefully), we are interested in the original stem. To simplify the problem, we define the stem as the longest consecutive substring that occurs in all the n words. If there are ties, we will choose the smallest one in the alphabetical (lexicographic) order.\n\n-----Input-----\nThe first line contains an integer T denoting the total number of test cases.\nIn each test cases, the first line contains an integer n denoting the number of words. In the second line, n words w[1..n] consisting of lower case characters are given as a single space-spearated list.\n\n-----Output-----\nFor each test case, output the stem in a new line.\n\n-----Constraints-----\n- 1 <= T <= 10\n- 1 <= n <= 10\n- 1 <= |w[i]| <= 20\n\n-----Example-----\nInput:\n1\n4\ngrace graceful disgraceful gracefully\nOutput:\ngrace\n\n-----Explanation-----\nThe stem is grace.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nt = eval(input())\nfor _ in range(t):\n n = eval(input())\n a = input().strip().split()\n cb, cs = 0, \"\"\n for i in range(len(a[0])):\n for j in range(i+1,len(a[0])+1):\n al = True\n s = a[0][i:j]\n for k in a[1:]:\n if s not in k:\n al = False\n break\n if al:\n if j-i>=cb:\n cb = max(cb, j-i)\n if len(cs) < cb:\n cs = a[0][i:j]\n elif len(cs) == cb:\n cs = min(cs,a[0][i:j])\n print(cs)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n4\\ngrace graceful disgraceful gracefully\\n', 'output': 'grace\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/COOK63/problems/STEM'}","problem_id":"vfc_1326","program":"```python\nt = eval(input())\nfor _ in range(t):\n n = eval(input())\n a = input().strip().split()\n cb, cs = 0, \"\"\n for i in range(len(a[0])):\n for j in range(i+1,len(a[0])+1):\n al = True\n s = a[0][i:j]\n for k in a[1:]:\n if s not in k:\n al = False\n break\n if al:\n if j-i>=cb:\n cb = max(cb, j-i)\n if len(cs) < cb:\n cs = a[0][i:j]\n elif len(cs) == cb:\n cs = min(cs,a[0][i:j])\n print(cs)\n```","inputs":"1\n4\ngrace graceful disgraceful gracefully\n","output":"grace\n","actual_output":"grace\n","execution_success":true,"sample_index":231},{"source":"apps","task_type":"verifiable_code","in_source_id":"623","prompt":"Solve the following coding problem using the programming language python:\n\nGiven the list of numbers, you are to sort them in non decreasing order.\n\n-----Input-----\nt \u2013 the number of numbers in list, then t lines follow [t <= 10^6]. \n\nEach line contains one integer: N [0 <= N <= 10^6]\n\n-----Output-----\nOutput given numbers in non decreasing order.\n\n-----Example-----\nInput:\n5\n5\n3\n6\n7\n1\n\nOutput:\n1\n3\n5\n6\n7\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nt = int(input())\nlist_to_tri = []\nfor i in range(t):\n list_to_tri.append(int(input()))\nlist_to_tri.sort()\nfor i in list_to_tri:\n print(i)\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '5\\n5\\n3\\n6\\n7\\n1\\n', 'output': '1\\n3\\n5\\n6\\n7\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/TSORT'}","problem_id":"vfc_1334","program":"```python\nt = int(input())\nlist_to_tri = []\nfor i in range(t):\n list_to_tri.append(int(input()))\nlist_to_tri.sort()\nfor i in list_to_tri:\n print(i)\n\n```","inputs":"5\n5\n3\n6\n7\n1\n","output":"1\n3\n5\n6\n7\n","actual_output":"1\n3\n5\n6\n7\n","execution_success":true,"sample_index":233},{"source":"apps","task_type":"verifiable_code","in_source_id":"624","prompt":"Solve the following coding problem using the programming language python:\n\nOnce, a genius guy Cristo visited NASA where he met many scientists. A young intern Mark at NASA asked Cristo to observe the strange behaviour of two\n\nindependent particles (say Alpha and Beta) moving in the free space.Cristo was astonished to see the movement of Alpha and Beta. However, he formulated a procedure\n\nto evaluate the distance covered by the particles in given time.\nThe procedure calculates the distance covered by Alpha and Beta for a given time. Mark, however struggles\n\nto evaluate the procedure manually and asks you to help him. \nCristo's Procedure :- \nalpha = 0\nbeta = 0\nProcedure CristoSutra( Ti ) :\nif Ti <= 0 :\nalpha = alpha + 1 \nelse if Ti == 1 :\n\tbeta = beta + 1\nelse :\nCristoSutra(Ti-1)\n\t CristoSutra(Ti-2)\n\t CristoSutra(Ti-3)\nend procedure\nNote: Print the answer by taking mod from 109+7 .\n\n-----Constraints:-----\n- 1<=T<=105\n- 1<=Ti<=105\n\n-----Input Format:-----\nFirst line consists an integer t, number of Test cases.For each test case, there is an integer denoting time Ti.\n\n-----Output Format:-----\nFor each test case, a single output line contains two space seperated numbers ,distance covered by alpha and beta in the given time.\n\n-----Subtasks:-----\nSubtask 1 (30 points)\n- 1<=T<=10\n- 1<=Ti<=1000\nSubtask 2 (70 points)\noriginal contraints\nSample Input:\n2\n1\n2\nSample Output:\n0 1\n2 1\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfor _ in range(eval(input())):\n n=eval(input())\n mod=1000000007\n f1,f2=[0]*101000,[0]*101000\n f1[1]=0\n f1[2]=2\n f1[3]=3\n f2[1]=1\n f2[2]=1\n f2[3]=2;\n for i in range(4,100001):\n f1[i]=f1[i-1]%mod+f1[i-2]%mod+f1[i-3]%mod\n f2[i]=f2[i-1]%mod+f2[i-2]%mod+f2[i-3]%mod\n print(f1[n]%mod,f2[n]%mod) \n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n1\\n2\\n', 'output': '0 1\\n2 1\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/ICOD2016/problems/ICODE16C'}","problem_id":"vfc_1338","program":"```python\nfor _ in range(eval(input())):\n n=eval(input())\n mod=1000000007\n f1,f2=[0]*101000,[0]*101000\n f1[1]=0\n f1[2]=2\n f1[3]=3\n f2[1]=1\n f2[2]=1\n f2[3]=2;\n for i in range(4,100001):\n f1[i]=f1[i-1]%mod+f1[i-2]%mod+f1[i-3]%mod\n f2[i]=f2[i-1]%mod+f2[i-2]%mod+f2[i-3]%mod\n print(f1[n]%mod,f2[n]%mod) \n```","inputs":"2\n1\n2\n","output":"0 1\n2 1\n","actual_output":"0 1\n2 1\n","execution_success":true,"sample_index":234},{"source":"apps","task_type":"verifiable_code","in_source_id":"625","prompt":"Solve the following coding problem using the programming language python:\n\nShaun is very much interested in Subarrays. Shaun wants to count the number of subarrays in his chosen array with sum being a multiple of $10^9$. Since, Shaun is interested in huge numbers.He chose his array such that it contains only $10^8$ and $9*10^8$ as its elements.\nHelp shaun to count the number of required subarrays.\n\n-----Input:-----\n- First line will contain $T$, number of testcases. Then the testcases follow. \n- First line of each testcase contains one integer $N$,size of array $A$. \n- Second line of each testcase contains $N$ space separated array elements\n\n-----Output:-----\nFor each testcase, output in a single line number of subarrays with sum being multiple of $10^9$.\n\n-----Constraints-----\n- $1 \\leq T \\leq 10$\n- $1 \\leq N \\leq 10^5$\n- $A[i]$=$10^8$ , $9*10^8$\n\n-----Sample Input:-----\n2\n3\n100000000 900000000 100000000\n1\n900000000\n\n-----Sample Output:-----\n2\n0\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\ndef subCount(arr, n, k):\r\n\r\n mod = []\r\n for i in range(k + 1):\r\n mod.append(0)\r\n\r\n\r\n cumSum = 0\r\n for i in range(n):\r\n cumSum = cumSum + arr[i]\r\n\r\n # as the sum can be negative,\r\n # taking modulo twice\r\n mod[((cumSum % k) + k) % k] = mod[((cumSum % k) + k) % k] + 1\r\n\r\n result = 0 # Initialize result\r\n\r\n for i in range(k):\r\n\r\n\r\n if (mod[i] > 1):\r\n result = result + (mod[i] * (mod[i] - 1)) // 2\r\n\r\n\r\n result = result + mod[0]\r\n\r\n return result\r\nt=int(input())\r\nwhile t:\r\n t=t-1\r\n n=int(input())\r\n a=list(map(int,input().split()))\r\n for i in range(n):\r\n if a[i]==100000000:\r\n a[i]=1\r\n elif a[i]==900000000:\r\n a[i]=9\r\n s=10\r\n\r\n print(subCount(a,n,s))\r\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n3\\n100000000 900000000 100000000\\n1\\n900000000\\n', 'output': '2\\n0\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/COCA2020/problems/COCA2001'}","problem_id":"vfc_1342","program":"```python\ndef subCount(arr, n, k):\r\n\r\n mod = []\r\n for i in range(k + 1):\r\n mod.append(0)\r\n\r\n\r\n cumSum = 0\r\n for i in range(n):\r\n cumSum = cumSum + arr[i]\r\n\r\n # as the sum can be negative,\r\n # taking modulo twice\r\n mod[((cumSum % k) + k) % k] = mod[((cumSum % k) + k) % k] + 1\r\n\r\n result = 0 # Initialize result\r\n\r\n for i in range(k):\r\n\r\n\r\n if (mod[i] > 1):\r\n result = result + (mod[i] * (mod[i] - 1)) // 2\r\n\r\n\r\n result = result + mod[0]\r\n\r\n return result\r\nt=int(input())\r\nwhile t:\r\n t=t-1\r\n n=int(input())\r\n a=list(map(int,input().split()))\r\n for i in range(n):\r\n if a[i]==100000000:\r\n a[i]=1\r\n elif a[i]==900000000:\r\n a[i]=9\r\n s=10\r\n\r\n print(subCount(a,n,s))\r\n\n```","inputs":"2\n3\n100000000 900000000 100000000\n1\n900000000\n","output":"2\n0\n","actual_output":"2\n0\n","execution_success":true,"sample_index":235},{"source":"apps","task_type":"verifiable_code","in_source_id":"626","prompt":"Solve the following coding problem using the programming language python:\n\nThe Chef has prepared the appetizers in the shapes of letters to spell a special message for the guests. There are n appetizers numbered from 0 to n-1 such that if the appetizers are arrayed in this order, they will display the message. The Chef plans to display them in this order on a table that can be viewed by all guests as they enter. The appetizers will only be served once all guests are seated.\n\nThe appetizers are not necessarily finished in the same order as they are numbered. So, when an appetizer is finished the Chef will write the number on a piece of paper and place it beside the appetizer on a counter between the kitchen and the restaurant. A server will retrieve this appetizer and place it in the proper location according to the number written beside it.\n\nThe Chef has a penchant for binary numbers. The number of appetizers created is a power of 2, say n = 2k. Furthermore, he has written the number of the appetizer in binary with exactly k bits. That is, binary numbers with fewer than k bits are padded on the left with zeros so they are written with exactly k bits.\n\nUnfortunately, this has unforseen complications. A binary number still \"looks\" binary when it is written upside down. For example, the binary number \"0101\" looks like \"1010\" when read upside down and the binary number \"110\" looks like \"011\" (the Chef uses simple vertical lines to denote a 1 bit). The Chef didn't realize that the servers would read the numbers upside down so he doesn't rotate the paper when he places it on the counter. Thus, when the server picks up an appetizer they place it the location indexed by the binary number when it is read upside down.\n\nYou are given the message the chef intended to display and you are to display the message that will be displayed after the servers move all appetizers to their locations based on the binary numbers they read.\n\n-----Input-----\n\nThe first line consists of a single integer T \u2264 25 indicating the number of test cases to follow. Each test case consists of a single line beginning with an integer 1 \u2264 k \u2264 16 followed by a string of precisely 2k characters. The integer and the string are separated by a single space. The string has no spaces and is composed only of lower case letters from `a` to `z`.\n\n\n-----Output-----\n\nFor each test case you are to output the scrambled message on a single line.\n\n\n-----Example-----\nInput:\n2\n2 chef\n4 enjoyourapplepie\n\nOutput:\ncehf\neayejpuinpopolre\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nt=int(input())\ndef reversebinary(bits,n):\n bStr=''\n for i in range(bits):\n if n>0:\n bStr=bStr+str(n%2)\n else:\n bStr=bStr+'0'\n n=n>>1\n return int(bStr,2)\n \nfor i in range(t):\n k,msg=input().split()\n k=int(k)\n newmsg=[]\n for j in msg:\n newmsg.append(j)\n for j in range(len(msg)):\n newmsg[reversebinary(k,j)]=msg[j]\n print(''.join(newmsg))\n \n \n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n2 chef\\n4 enjoyourapplepie\\n\\n\\n', 'output': 'cehf\\neayejpuinpopolre\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/COOK02/problems/ARRANGE'}","problem_id":"vfc_1346","program":"```python\nt=int(input())\ndef reversebinary(bits,n):\n bStr=''\n for i in range(bits):\n if n>0:\n bStr=bStr+str(n%2)\n else:\n bStr=bStr+'0'\n n=n>>1\n return int(bStr,2)\n \nfor i in range(t):\n k,msg=input().split()\n k=int(k)\n newmsg=[]\n for j in msg:\n newmsg.append(j)\n for j in range(len(msg)):\n newmsg[reversebinary(k,j)]=msg[j]\n print(''.join(newmsg))\n \n \n\n```","inputs":"2\n2 chef\n4 enjoyourapplepie\n\n\n","output":"cehf\neayejpuinpopolre\n","actual_output":"cehf\neayejpuinpopolre\n","execution_success":true,"sample_index":236},{"source":"apps","task_type":"verifiable_code","in_source_id":"627","prompt":"Solve the following coding problem using the programming language python:\n\nBharat was given a problem to solve, by his brother, Lord Ram. The problem was like, given integers, $N$ and $K$, Bharat has to find the number (possibilities) of non-increasing arrays of length $K$, where each element of the array is between $1$ and $N$ (both inclusive). He was confused, regarding this problem. So, help him solve the problem, so that, he can give the answer of the problem, to his brother, Lord Rama. Since, the number of possible sub-arrays can be large, Bharat has to answer the problem as \"number of possible non-increasing arrays\", modulo $10^9$ $+$ $7$.\n\n-----Input:-----\n- Two space-seperated integers, $N$ and $K$.\n\n-----Output:-----\n- Output in a single line, the number of possible non-increasing arrays, modulo $10^9$ $+$ $7$.\n\n-----Constraints:-----\n- $1 \\leq N, K \\leq 2000$\n\n-----Sample Input:-----\n2 5\n\n-----Sample Output:-----\n6\n\n-----Explanation:-----\n- Possible Arrays, for the \"Sample Case\" are as follows: \n- {1, 1, 1, 1, 1}\n- {2, 1, 1, 1, 1}\n- {2, 2, 1, 1, 1} \n- {2, 2, 2, 1, 1}\n- {2, 2, 2, 2, 1}\n- {2, 2, 2, 2, 2}\n- Hence, the answer to the \"Sample Case\" is $6$ ($6$ % ($10^9$ $+$ $7$)).\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nimport math\np=7+10**9\nn,k=list(map(int,input().split()))\nc=math.factorial(n+k-1)//((math.factorial(k))*(math.factorial(n-1)))\nprint(c%p)\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2 5\\n', 'output': '6\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/PCR12020/problems/BHARAT'}","problem_id":"vfc_1350","program":"```python\nimport math\np=7+10**9\nn,k=list(map(int,input().split()))\nc=math.factorial(n+k-1)//((math.factorial(k))*(math.factorial(n-1)))\nprint(c%p)\n\n```","inputs":"2 5\n","output":"6\n","actual_output":"6\n","execution_success":true,"sample_index":237},{"source":"apps","task_type":"verifiable_code","in_source_id":"628","prompt":"Solve the following coding problem using the programming language python:\n\nChef and his best friend Aleksa are into mathematical games these days. Today, they have some ( \u2265 0 ) black cells represented as B, and a white cell represented as W, lying randomly in a straight line.\nThey have decided to play with these cells. In a move, a player chooses some ( > 0 ) black cells lying on any one side of the white cell and remove them. It should be noted that a player is not allowed to choose black cells from both side of the given white cell. Both the players alternate their moves, and play optimally. The player who is unable to move in his respective turn will lose the game.\nAleksa, being a girl, has a habit of playing first. But Chef is fairly smart himself, and will not play the game if he is going to lose it. Therefore, he wants to know the winner beforehand. Can you tell him who is going to win the game for the given configuration of cells?\n\n-----Input-----\nFirst line of input contains a single integer T denoting the number of test cases. First and the only line of each test case contains a string S consisting of the characters 'B' and 'W', denoting black and white cells, respectively.\n\n-----Output-----\nFor each test case, output \"Chef\" if chef wins the game for the given configuration. Else print \"Aleksa\". (quotes for clarity only).\n\n-----Constraints-----\n- 1 \u2264 T \u2264 10\n- 1 \u2264 |S| \u2264 10000\n- S contains exactly 1 white cell.\n\n-----Scoring-----\n- Subtask 1: 1 \u2264 T \u2264 10, 1 \u2264 |S| \u2264 10 : ( 30 pts )\n- Subtask 2: 1 \u2264 T \u2264 10, 1 \u2264 |S| \u2264 100 : ( 30 pts )\n- Subtask 3: 1 \u2264 T \u2264 10, 1 \u2264 |S| \u2264 10000 : ( 40 pts )\n\n-----Example-----\nInput\n3\nW\nBW\nBWBB\n\nOutput\nChef\nAleksa\nAleksa\n\n----- Explanation-----\n- Test 1 : Aleksa cannot make a move in her first turn as there is no black cell in the given configuration.\n- Test 2 : Aleksa can remove 1 black cell lying on the left of white cell in her turn. But then, Chef cannot make a move in his turn as there will be no black cells left.\n- Test 3 : Figure out yourself.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nt =int(input()) #no. of test cases\nwhile t>0:\n t=t-1\n str=input()\n size=len(str)\n pos=str.find('W')\n left=pos\n right=size-pos-1\n arr = [[0 for i in range(right+1)] for j in range(left+1)]\n #arr[i,j] = 1 if with i black cells on left and j on right 1st player can \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0win, 0 otherwise.\n #Recursion: arr[i][j]= or(arr[x][y])\n arr[0][0]=0\n for i in range(left+1):\n for j in range(right+1):\n if i==j:\n arr[i][j]=0\n else:\n arr[i][j]=1\n if(arr[left][right]==1):\n print(\"Aleksa\")\n else:\n print(\"Chef\")\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\nW\\nBW\\nBWBB\\n', 'output': 'Chef\\nAleksa\\nAleksa\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/BWCELL'}","problem_id":"vfc_1354","program":"```python\nt =int(input()) #no. of test cases\nwhile t>0:\n t=t-1\n str=input()\n size=len(str)\n pos=str.find('W')\n left=pos\n right=size-pos-1\n arr = [[0 for i in range(right+1)] for j in range(left+1)]\n #arr[i,j] = 1 if with i black cells on left and j on right 1st player can \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0win, 0 otherwise.\n #Recursion: arr[i][j]= or(arr[x][y])\n arr[0][0]=0\n for i in range(left+1):\n for j in range(right+1):\n if i==j:\n arr[i][j]=0\n else:\n arr[i][j]=1\n if(arr[left][right]==1):\n print(\"Aleksa\")\n else:\n print(\"Chef\")\n\n```","inputs":"3\nW\nBW\nBWBB\n","output":"Chef\nAleksa\nAleksa\n","actual_output":"Chef\nAleksa\nAleksa\n","execution_success":true,"sample_index":238},{"source":"apps","task_type":"verifiable_code","in_source_id":"629","prompt":"Solve the following coding problem using the programming language python:\n\nNaturally, the magical girl is very good at performing magic. She recently met her master wizard Devu, who gifted her R potions of red liquid, \nB potions of blue liquid, and G potions of green liquid.\n\n- \nThe red liquid potions have liquid amounts given by r[1], ..., r[R] liters. \n\n- \nThe green liquid potions have liquid amounts given by g[1], ..., g[G] liters. \n\n- \nThe blue liquid potions have liquid amounts given by b[1], ..., b[B] liters. \n\nShe want to play with the potions by applying magic tricks on them. In a single magic trick, she will choose a particular color. Then she will pick all the potions of the chosen color and decrease the amount of liquid in them to half (i.e. if initial amount \nof liquid is x, then the amount after decrement will be x / 2 where division is integer division, e.g. 3 / 2 = 1 and 4 / 2 = 2). \n\nBecause she has to go out of station to meet her uncle Churu, a wannabe wizard, only M minutes are left for her. In a single minute, she can perform at most one magic trick. Hence, she can perform at most M magic tricks.\n\nShe would like to minimize the maximum amount of liquid among all of Red, Green and Blue colored potions. Formally Let v be the maximum value of amount of liquid in any potion. We want to minimize the value of v.\nPlease help her.\n\n-----Input-----\n\nFirst line of the input contains an integer T denoting the number of test cases.\nThen for each test case, we have four lines.\n\nThe first line contains four space separated integers R, G, B, M. The next 3 lines will describe the amount of different color liquids (r, g, b), which are separated by space.\n\n-----Output-----\nFor each test case, print a single integer denoting the answer of the problem.\n\n-----Constraints-----\n- 1 \u2264 T \u2264 1000 \n- 1 \u2264 R, G, B, M \u2264 100 \n- 1 \u2264 r[i], g[i], b[i] \u2264 10^9 \n\n-----Example-----\nInput:\n3\n1 1 1 1\n1\n2\n3\n1 1 1 1\n2\n4\n6\n3 2 2 2\n1 2 3\n2 4\n6 8\nOutput:\n2\n4\n4\n\n-----Explanation-----\nExample case 1. Magical girl can pick the blue potion and make its liquid amount half. So the potions will now have amounts 1 2 1. Maximum of these values is 2. Hence answer is 2.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nimport sys\nimport math\nimport heapq\ndef half(n):\n return n//2\ndef main(arr,m):\n a,b,c=arr\n \n while m!=0:\n \n \n \n s=max(a,b,c)\n \n if s==a:\n a=half(a)\n elif s==b:\n b=half(b)\n else:\n c=half(c)\n m-=1\n return max(a,b,c)\n \n \n \n \n \n\nfor i in range(int(input())):\n r,g,b,m=list(map(int,input().split()))\n arr=[]\n for j in range(3):\n c=max(list(map(int,input().split())))\n arr.append(c)\n \n print(main(arr,m))\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\n1 1 1 1\\n1\\n2\\n3\\n1 1 1 1\\n2\\n4\\n6\\n3 2 2 2\\n1 2 3\\n2 4\\n6 8\\n', 'output': '2\\n4\\n4\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/PRPOTION'}","problem_id":"vfc_1358","program":"```python\nimport sys\nimport math\nimport heapq\ndef half(n):\n return n//2\ndef main(arr,m):\n a,b,c=arr\n \n while m!=0:\n \n \n \n s=max(a,b,c)\n \n if s==a:\n a=half(a)\n elif s==b:\n b=half(b)\n else:\n c=half(c)\n m-=1\n return max(a,b,c)\n \n \n \n \n \n\nfor i in range(int(input())):\n r,g,b,m=list(map(int,input().split()))\n arr=[]\n for j in range(3):\n c=max(list(map(int,input().split())))\n arr.append(c)\n \n print(main(arr,m))\n\n```","inputs":"3\n1 1 1 1\n1\n2\n3\n1 1 1 1\n2\n4\n6\n3 2 2 2\n1 2 3\n2 4\n6 8\n","output":"2\n4\n4\n","actual_output":"2\n4\n4\n","execution_success":true,"sample_index":239},{"source":"apps","task_type":"verifiable_code","in_source_id":"630","prompt":"Solve the following coding problem using the programming language python:\n\nCersei wants to be the queen of seven kingdoms.\n\nFor this to happen, she needs to address the soldiers in her army. There are n$n$ soldiers in her army (numbered 1$1$ through n$n$). Cersei passes on the message to the first soldier (soldier 1). \nThis message needs to reach every soldier in the army. For this, the soldiers communicate among themselves by one soldier passing the message to another soldier through some communication links. It is known that the message could reach every soldier using the given links.\nNow, each soldier will receive the message from exactly one soldier or Cersei and could pass on the message to atmost two soldiers. That is each soldier (except soldier 1) has only one incoming link and every soldier (including soldier 1) has atmost two outgoing links. \nNow, the High Sparrow feels that Cersei is planning to kill his people first. Hence, for the sake of his people, he decided to appoint some sparrows to overhear every conversation between the soldiers (The conversation between Cersei and the first soldier needn't be overheard due to the fear of Ser Gregor Clegane). \nTo overhear a conversation between soldiers A$A$ and B$B$, there needs to be a sparrow either at soldier A$A$ or soldier B$B$ or both.\nAlso, by his research, the High Sparrow has found that the soldiers are partitioned into some classes (1$1$ to k$k$). That is, every soldier belongs to exactly one class. He then demands the presence of atleast one sparrow with each class he knows (1$1$ to k$k$).\nFind the minimum number of sparrows the High Sparrow needs to recruit for the job or tell that he couldn't.\n\n-----Input:-----\n- The first line of the input contains the number of test cases t$t$.\n- The first line of each test case gives the number of soldiers n$n$ in the army, the number of communication links m$m$ between the soldiers and the number of classes k$k$ in soldiers.\n- The next line of the test case consists of n$n$ integers A1,A2....An$A_1,A_2....A_n$ each denoting the class of the ith$i^{th}$ soldier.\n- The next m$m$ lines of the test case contain two integers u$u$ and v$v$, which denotes that soldier u$u$ can pass a message to soldier v$v$ (u\u2260v$u \\neq v$).\n\n-----Output:-----\nFor each test case, print in a single line the minimum number of sparrows required for the above task or print \u22121$-1$ if no such way is possible.\n\n-----Constraints-----\n- 1\u2264t\u2264500$1 \\leq t \\leq 500$\n- 1\u2264n\u22642500$1 \\leq n \\leq 2500$\n- m=n\u22121$m = n - 1$\n- 1\u2264k\u226410$1 \\leq k \\leq 10$\n- 1\u2264ai\u2264k$1 \\leq a_i \\leq k$\n- The sum of n$n$ over all test cases is \u22642500$\\leq 2500$.\n\n-----Sample Input:-----\n1\n5 4 3\n1 1 2 2 3\n1 2\n1 3\n2 4\n2 5\n\n-----Sample Output:-----\n3\n\n-----EXPLANATION:-----\nSelecting soldiers 1,4,5 would satisfy all the conditions.\n\n-----Sample Input:-----\n1\n5 4 5\n1 1 2 2 3\n1 2\n1 3\n2 4\n2 5\n\n-----Sample Output:-----\n-1\n\n-----EXPLANATION:-----\nClasses 4 and 5 are not present. So, there is no way possible.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\ndt, a = None, None\ndef dfs(z):\n r = [{}, {}];ln = len(dt[z])\n if ln == 0:r[0][0] = 0;r[1][1 << a[z]] = 1\n elif ln == 1:\n l = dfs(dt[z][0]);r[0] = l[1]\n for m in l[0]: r[1][(1 << a[z]) | m] = min(r[1][(1 << a[z]) | m], l[0][m] + 1) if (1 << a[z]) | m in r[1] else l[0][m] + 1\n for m in l[1]: r[1][(1 << a[z]) | m] = min(r[1][(1 << a[z]) | m], l[1][m] + 1) if (1 << a[z]) | m in r[1] else l[1][m] + 1\n elif ln == 2:\n l0 = dfs(dt[z][0]);l1 = dfs(dt[z][1])\n for i0 in range(2):\n for i1 in range(2):\n for m0 in l0[i0]:\n for m1 in l1[i1]:r[1][(1 << a[z]) | m0 | m1] = min(r[1][(1 << a[z]) | m0 | m1], l0[i0][m0] + l1[i1][m1] + 1) if (1 << a[z]) | m0 | m1 in r[1] else l0[i0][m0] + l1[i1][m1] + 1\n for m0 in l0[1]:\n for m1 in l1[1]: r[0][m0 | m1] = min(r[0][m0 | m1], l0[1][m0] + l1[1][m1]) if m0 | m1 in r[0] else l0[1][m0] + l1[1][m1]\n return r\nfor i in range(int(input())):\n n, m, k = map(int, input().split());a = [0] + [int(x) - 1 for x in input().split()];dt = [[] for i in range(n + 1)];\n for i in range(m):u, v = map(int, input().split());dt[u].append(v)\n r = dfs(1);k = (1 << k) - 1\n if (k in r[0]): v = min(r[0][k], r[1][k])\n elif (k in r[1]): v = r[1][k]\n else: v = -1\n print(v)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n5 4 3\\n1 1 2 2 3\\n1 2\\n1 3\\n2 4\\n2 5\\n', 'output': '3\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/CERSOL'}","problem_id":"vfc_1362","program":"```python\ndt, a = None, None\ndef dfs(z):\n r = [{}, {}];ln = len(dt[z])\n if ln == 0:r[0][0] = 0;r[1][1 << a[z]] = 1\n elif ln == 1:\n l = dfs(dt[z][0]);r[0] = l[1]\n for m in l[0]: r[1][(1 << a[z]) | m] = min(r[1][(1 << a[z]) | m], l[0][m] + 1) if (1 << a[z]) | m in r[1] else l[0][m] + 1\n for m in l[1]: r[1][(1 << a[z]) | m] = min(r[1][(1 << a[z]) | m], l[1][m] + 1) if (1 << a[z]) | m in r[1] else l[1][m] + 1\n elif ln == 2:\n l0 = dfs(dt[z][0]);l1 = dfs(dt[z][1])\n for i0 in range(2):\n for i1 in range(2):\n for m0 in l0[i0]:\n for m1 in l1[i1]:r[1][(1 << a[z]) | m0 | m1] = min(r[1][(1 << a[z]) | m0 | m1], l0[i0][m0] + l1[i1][m1] + 1) if (1 << a[z]) | m0 | m1 in r[1] else l0[i0][m0] + l1[i1][m1] + 1\n for m0 in l0[1]:\n for m1 in l1[1]: r[0][m0 | m1] = min(r[0][m0 | m1], l0[1][m0] + l1[1][m1]) if m0 | m1 in r[0] else l0[1][m0] + l1[1][m1]\n return r\nfor i in range(int(input())):\n n, m, k = map(int, input().split());a = [0] + [int(x) - 1 for x in input().split()];dt = [[] for i in range(n + 1)];\n for i in range(m):u, v = map(int, input().split());dt[u].append(v)\n r = dfs(1);k = (1 << k) - 1\n if (k in r[0]): v = min(r[0][k], r[1][k])\n elif (k in r[1]): v = r[1][k]\n else: v = -1\n print(v)\n```","inputs":"1\n5 4 3\n1 1 2 2 3\n1 2\n1 3\n2 4\n2 5\n","output":"3\n","actual_output":"3\n","execution_success":true,"sample_index":240},{"source":"apps","task_type":"verifiable_code","in_source_id":"632","prompt":"Solve the following coding problem using the programming language python:\n\nSheldon is a little geek living in Texas. While his friends like to play outside, little Sheldon likes to play around with ICs and lasers in his house. He decides to build N clap activated toggle machines each with one power inlet and one outlet. Each machine works when its power source inlet is receiving power. When the machine is in 'ON' state and is receiving power at its inlet, it makes power available at its power outlet to which a bulb or another ToGgLe machine could be attached.\n\nSuppose Sheldon attached 2 such machines to one another with the power inlet of the first machine attached to a power source at his house and the outlet of the second machine to a bulb. Initially both machines are in 'OFF' state and power source to first machine is off too. Now the power source is switched on. The first machine receives power but being in the 'OFF' state it does not transmit any power. Now on clapping the first ToGgLe machine toggles to 'ON' and the second machine receives power. On clapping once more the first toggles to 'OFF' and the second toggles to 'ON'. But since the second ToGgLe machine receives no power the bulb does not light up yet. On clapping once more, the first machine which is still receiving power from the source toggles to 'ON' and the second which was already 'ON' does not toggle since it was not receiving power. So both the machine are in 'ON' state and the bulb lights up and little Sheldon is happy.\n\nBut when Sheldon goes out for a while, his evil twin sister attaches N such ToGgLe machines (after making sure they were all in 'OFF' state) and attaches the first to a power source (the power source is initially switched off) and the last ToGgLe machine to a bulb. Sheldon is horrified to find that his careful arrangement has been disturbed.\n\nCoders, help the poor boy by finding out if clapping k times for the N ToGgLe machines (all in 'OFF' state with the first one connected to a switched off power source and last one to a bulb) would light the bulb. Hurry before Sheldon has a nervous breakdown!\n\n-----Input-----\nFirst line has number of test cases, T.\n\nFollowing T lines have N, k separated by a single space where N is the number of \nToGgLe machines and k is the number of times Sheldon clapped.\n\n-----Output-----\nT lines with cach line of the form: \"ON\" (just the word on without the double quotes) if the bulb is 'ON' for the \ntest case numbered n and \"OFF\" (just the word off without the double quotes) if the bulb is 'OFF' for the test case numbered n.\n\n\n-----Example-----\nInput:\n4\n4 0\n4 47\n1 0\n1 1\n\nOutput:\nOFF\nON\nOFF\nON\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nn=int(input())\nwhile n>0:\n i=1\n a,b=(int(i) for i in input().split())\n if (b+1)%(i<0:\n i=1\n a,b=(int(i) for i in input().split())\n if (b+1)%(i<n:\r\n print(\"0\")\r\n else:\r\n k=(n-ls+1)\r\n print((k*pow(26,n-ls,1000000007))%1000000007)\r\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\n2 1\\naa\\n2 1\\nd\\n12 3\\ncdmn\\nqweewef\\nqs\\n\\n\\n', 'output': 'Case 1:\\n1\\nCase 2:\\n52\\nCase 3:\\n443568031\\n71288256\\n41317270\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/ZUBAPCNT'}","problem_id":"vfc_1394","program":"```python\nfor _ in range(int(input())):\r\n n,m=map(int,input().split())\r\n print(\"Case \"+str(_+1)+\":\")\r\n for i in range(m):\r\n s=input()\r\n ls=len(s)\r\n if ls>n:\r\n print(\"0\")\r\n else:\r\n k=(n-ls+1)\r\n print((k*pow(26,n-ls,1000000007))%1000000007)\r\n\n```","inputs":"3\n2 1\naa\n2 1\nd\n12 3\ncdmn\nqweewef\nqs\n\n\n","output":"Case 1:\n1\nCase 2:\n52\nCase 3:\n443568031\n71288256\n41317270\n","actual_output":"Case 1:\n1\nCase 2:\n52\nCase 3:\n443568031\n71288256\n41317270\n","execution_success":true,"sample_index":248},{"source":"apps","task_type":"verifiable_code","in_source_id":"639","prompt":"Solve the following coding problem using the programming language python:\n\nFor a string $S$ let the unique set of characters that occur in it one or more times be $C$. Consider a permutation of the elements of $C$ as $(c_1, c_2, c_3 ... )$. Let $f(c)$ be the number of times $c$ occurs in $S$.\nIf any such permutation of the elements of $C$ satisfies $f(c_i) = f(c_{i-1}) + f(c_{i-2})$ for all $i \\ge 3$, the string is said to be a dynamic string.\nMr Bancroft is given the task to check if the string is dynamic, but he is busy playing with sandpaper. Would you help him in such a state?\nNote that if the number of distinct characters in the string is less than 3, i.e. if $|C| < 3$, then the string is always dynamic.\n\n-----Input:-----\n- First line will contain $T$, number of testcases. Then the testcases follow. \n- Each testcase contains of a single line of input, a string $S$.\n\n-----Output:-----\nFor each testcase, output in a single line \"Dynamic\" if the given string is dynamic, otherwise print \"Not\". (Note that the judge is case sensitive)\n\n-----Constraints-----\n- $1 \\leq T \\leq 10$\n- $1 \\leq |S| \\leq 10^5$\n- $S$ contains only lower case alphabets: $a$, $b$, \u2026, $z$\n\n-----Sample Input:-----\n3\naaaabccc\naabbcc\nppppmmnnoooopp\n\n-----Sample Output:-----\nDynamic\nNot\nDynamic\n\n-----Explanation:-----\n- Testase 1: For the given string, $C = \\{a, b, c\\}$ and $f(a)=4, f(b)=1, f(c)=3$. $f(a) = f(c) + f(b)$ so the permutation $(b, c, a)$ satisfies the requirement.\n- Testcase 2: Here too $C = \\{a, b, c\\}$ but no permutation satisfies the requirement of a dynamic string.\n- Testcase 3: Here $C = \\{m, n, o, p\\}$ and $(m, n, o, p)$ is a permutation that makes it a dynamic string.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\nt=int(input())\nfor _ in range(t):\n st=input()\n s=set(st)\n a=[]\n f1=f2=0\n for i in s:\n a.append(st.count(i))\n a.sort()\n if len(a)>=3:\n for i in range(2,len(a)):\n if a[i]!=a[i-1]+a[i-2]:\n f1=1\n break\n x=a[0]\n a[0]=a[1]\n a[1]=x\n for i in range(2,len(a)):\n if a[i]!=a[i-1]+a[i-2]:\n f2=1\n break\n if f1==1 and f2==1:\n print(\"Not\")\n else:\n print(\"Dynamic\")\n else:\n print(\"Dynamic\")\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\naaaabccc\\naabbcc\\nppppmmnnoooopp\\n', 'output': 'Dynamic\\nNot\\nDynamic\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/CLFIBD'}","problem_id":"vfc_1398","program":"```python\n# cook your dish here\nt=int(input())\nfor _ in range(t):\n st=input()\n s=set(st)\n a=[]\n f1=f2=0\n for i in s:\n a.append(st.count(i))\n a.sort()\n if len(a)>=3:\n for i in range(2,len(a)):\n if a[i]!=a[i-1]+a[i-2]:\n f1=1\n break\n x=a[0]\n a[0]=a[1]\n a[1]=x\n for i in range(2,len(a)):\n if a[i]!=a[i-1]+a[i-2]:\n f2=1\n break\n if f1==1 and f2==1:\n print(\"Not\")\n else:\n print(\"Dynamic\")\n else:\n print(\"Dynamic\")\n```","inputs":"3\naaaabccc\naabbcc\nppppmmnnoooopp\n","output":"Dynamic\nNot\nDynamic\n","actual_output":"Dynamic\nNot\nDynamic\n","execution_success":true,"sample_index":249},{"source":"apps","task_type":"verifiable_code","in_source_id":"640","prompt":"Solve the following coding problem using the programming language python:\n\nChef made two laddus with sweetness X and Y respectively. Cheffina comes and sees the chef created two laddus with different sweetness (might be same). Cheffina has the magical power to make the sweetness of laddus equal. Cheffina requires 1 unit of power to increase the sweetness of laddu by its original value i.e. 1 unit to convert Z to 2Z and 2 unit to convert Z to 3Z and so on\u2026 How many units of power does cheffina want to make the sweetness equal?\n\n-----Input:-----\n- First-line will contain $T$, the number of test cases. Then the test cases follow. \n- Each test case contains a single line of input, two integers $X, Y$. \n\n-----Output:-----\nFor each test case, output in a single line answer as power required.\n\n-----Constraints-----\n- $1 \\leq T \\leq 10^5$\n- $1 \\leq X,Y \\leq 10^5$\n\n-----Sample Input:-----\n2\n2 2\n4 6\n\n-----Sample Output:-----\n0\n3\n\n-----EXPLANATION:-----\nFor 1) Sweetness are same so no need to use power.\nFor 2) \n1st laddu\n2 Unit power = 4 -> 12\n2nd Laddu\n1 Unit power = 6 -> 12\nAfter using total 3 unit power sweetness of both laddus are same.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\ndef gcd(a,b):\r\n\tif b==0:return a\r\n\telse:return gcd(b,a%b)\r\ndef lcm(a,b):\r\n\tm=a*b\r\n\tg=gcd(a,b)\r\n\treturn int(m/g)\r\nfor _ in range(int(input())):\r\n\tx,y=[int(x) for x in input().split()]\r\n\tl=lcm(x,y)\r\n\ts=int(l/x)\r\n\tt=int(l/y)\r\n\tprint(s+t-2)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n2 2\\n4 6\\n', 'output': '0\\n3\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/PBK22020/problems/ITGUY22'}","problem_id":"vfc_1402","program":"```python\ndef gcd(a,b):\r\n\tif b==0:return a\r\n\telse:return gcd(b,a%b)\r\ndef lcm(a,b):\r\n\tm=a*b\r\n\tg=gcd(a,b)\r\n\treturn int(m/g)\r\nfor _ in range(int(input())):\r\n\tx,y=[int(x) for x in input().split()]\r\n\tl=lcm(x,y)\r\n\ts=int(l/x)\r\n\tt=int(l/y)\r\n\tprint(s+t-2)\n```","inputs":"2\n2 2\n4 6\n","output":"0\n3\n","actual_output":"0\n3\n","execution_success":true,"sample_index":250},{"source":"apps","task_type":"verifiable_code","in_source_id":"641","prompt":"Solve the following coding problem using the programming language python:\n\nA key feature of the Siruseri railway network is that it has exactly one route between any pair of stations.\nThe government has chosen three contractors to run the canteens at the stations on the railway network. To ensure that there are no disputes between the contractors it has been decided that if two stations, say $A$ and $B$, are assigned to a particular contractor then all the stations that lie on the route from $A$ to $B$ will also be awarded to the same contractor.\nThe government would like the assignment of stations to the contractors to be as equitable as possible. The government has data on the number of passengers who pass through each station each year. They would like to assign stations so that the maximum number of passengers passing through any contractor's collection of stations is minimized.\nFor instance, suppose the railway network is as follows, where the volume of passenger traffic is indicated by the side of each station.\n\nOne possible assignment would to award stations $1$ and $3$ to one contractor (there by giving him a traffic of $35$ passengers), station $2$ to the second contractor (traffic of $20$) and stations $4, 5$ and $6$ to the third contractor (traffic of $100$). In this assignment, the maximum traffic for any one contractor is 100. On the other hand if we assigned stations $1, 2$ and $3$ to one contractor, station $4$ and $6$ to the second contractor and station $5$ to the third contractor the maximum traffic for any one contractor is $70$. You can check that you cannot do better. (The assignment $1$, $2$ and $3$ to one contractor, $4$ to the second contractor, and $5$ and $6$ to the third contractor has a lower value for the maximum traffic ($55$) but it is not a valid assignment as the route from $5$ to $6$ passes through $4$.)\n\n-----Input:-----\nThe first line of the input contains one integer $N$ indicating the number of railways stations in the network. The stations are numbered $1,2,..., N$. This is followed by $N$ lines of input, lines $2,3,...,N+1$, indicating the volume of traffic at each station. The volume of traffic at station $i$, $1 \\leq i \\leq N$, is given by a single integer in line $i+1$. The next $N-1$ lines of input, lines $N+2, N+3, ..., 2 \\cdot N$, describe the railway network. Each of these lines contains two integers, denoting a pair of stations that are neighbours.\n\n-----Output:-----\nThe output should be a single integer, corresponding to the minimum possible value of the maximum traffic of any contractor among all valid assignment of the stations to the three contractors.\n\n-----Constraints:-----\n- $1 \\leq N \\leq 3000$.\n\n-----Sample Input-----\n6\n10\n20\n25\n40\n30\n30\n4 5\n1 3\n3 4\n2 3\n6 4\n\n-----Sample Output-----\n70\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nn=int(input())\r\ncost=[]\r\nd={}\r\nval_desc=[0]*n\r\nvisited=set()\r\nvisited.add(0)\r\ndfstack=[]\r\ndesc = [[False for i in range(n)] for i in range(n)]\r\nfor i in range(n):\r\n\tcost.append(int(input()))\r\n\td[i]=[]\r\n\r\nfor i in range(n-1):\r\n\tj,k=list(map(int,input().split()))\r\n\td[j-1].append(k-1)\r\n\td[k-1].append(j-1)\r\n\r\ndef dfs(u):\r\n\tval_desc[u]+=cost[u]\r\n\tdfstack.append(u)\r\n\tfor i in dfstack:\r\n\t\tdesc[u][i]=True\r\n\tfor i in d[u]:\r\n\t\tif i not in visited:\r\n\t\t\tvisited.add(i)\r\n\t\t\tdfs(i)\r\n\t\t\tval_desc[u]+=val_desc[i]\t\t\t\r\n\tdfstack.pop(-1)\r\n\r\ndfs(0)\r\nmp=10**9\r\ncoco=sum(cost)\r\nfor i in range(n):\r\n\tfor j in range(i+1,n):\r\n\t\tvali=val_desc[i]\r\n\t\tvalj=val_desc[j]\r\n\t\tif desc[i][j]:\r\n\t\t\tvalj-=val_desc[i]\r\n\t\tif desc[j][i]:\r\n\t\t\tvali-=val_desc[j]\r\n\t\tp=max(vali,valj,coco-vali-valj)\r\n\t\tmp=min(mp,p)\r\n#print(desc)\r\n#print(val_desc)\r\n#print\r\nprint(mp)\r\n\r\n\r\n\t\r\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '6\\n10\\n20\\n25\\n40\\n30\\n30\\n4 5\\n1 3\\n3 4\\n2 3\\n6 4\\n', 'output': '70\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/IARCSJUD/problems/SPLIT3'}","problem_id":"vfc_1406","program":"```python\nn=int(input())\r\ncost=[]\r\nd={}\r\nval_desc=[0]*n\r\nvisited=set()\r\nvisited.add(0)\r\ndfstack=[]\r\ndesc = [[False for i in range(n)] for i in range(n)]\r\nfor i in range(n):\r\n\tcost.append(int(input()))\r\n\td[i]=[]\r\n\r\nfor i in range(n-1):\r\n\tj,k=list(map(int,input().split()))\r\n\td[j-1].append(k-1)\r\n\td[k-1].append(j-1)\r\n\r\ndef dfs(u):\r\n\tval_desc[u]+=cost[u]\r\n\tdfstack.append(u)\r\n\tfor i in dfstack:\r\n\t\tdesc[u][i]=True\r\n\tfor i in d[u]:\r\n\t\tif i not in visited:\r\n\t\t\tvisited.add(i)\r\n\t\t\tdfs(i)\r\n\t\t\tval_desc[u]+=val_desc[i]\t\t\t\r\n\tdfstack.pop(-1)\r\n\r\ndfs(0)\r\nmp=10**9\r\ncoco=sum(cost)\r\nfor i in range(n):\r\n\tfor j in range(i+1,n):\r\n\t\tvali=val_desc[i]\r\n\t\tvalj=val_desc[j]\r\n\t\tif desc[i][j]:\r\n\t\t\tvalj-=val_desc[i]\r\n\t\tif desc[j][i]:\r\n\t\t\tvali-=val_desc[j]\r\n\t\tp=max(vali,valj,coco-vali-valj)\r\n\t\tmp=min(mp,p)\r\n#print(desc)\r\n#print(val_desc)\r\n#print\r\nprint(mp)\r\n\r\n\r\n\t\r\n\n```","inputs":"6\n10\n20\n25\n40\n30\n30\n4 5\n1 3\n3 4\n2 3\n6 4\n","output":"70\n","actual_output":"70\n","execution_success":true,"sample_index":251},{"source":"apps","task_type":"verifiable_code","in_source_id":"643","prompt":"Solve the following coding problem using the programming language python:\n\nTed$Ted$ loves prime numbers. One day he is playing a game called legendary$legendary$ with his girlfriend Robin$Robin$. Ted$Ted$ writes a number N$N$ on a table and the number is in the form of :\nN = P1A1 * P2A2 * \u2026\u2026\u2026.. * PnAn\nTed$Ted$ asks Robin$Robin$ to find the sum of all the numbers which are less than or equal to N$N$ and also contains all the primes whose minimum power in the number is given by an array B$B$. \nAs Robin$Robin$ is bad with maths she asks your help to answer this question.\n\n-----Input:-----\n- 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. \n- The first line of each test case contains a single integer n$n$, represents a number of distinct prime numbers.\n- The second line of each test case contains n$n$ space separated distinct prime numbers which represents an array P$P$.\n- The third line of each test case contains n$n$ space separated integers which represents an array A$A$.\n- The fourth line of each test case contains n$n$ space separated integers which represents an array B$B$ \n\n-----Output:-----\nFor each test case, output the Answer Modulo 109 + 7 in a single line.\n\n-----Constraints-----\n- 1\u2264T\u22643$1 \\leq T \\leq 3$\n- 1\u2264n\u2264105$1 \\leq n \\leq 10^5$\n- 2\u2264Pi\u2264106$2 \\leq P_{i} \\leq 10^6$\n- 1\u2264Ai\u2264109$1 \\leq A_{i} \\leq 10^9$\n- 0\u2264Bi\u2264Ai$0 \\leq B_{i} \\leq Ai$\n\n-----Sample Input:-----\n1\n3\n2 3 5\n2 1 2\n1 1 1\n\n-----Sample Output:-----\n540\n\n-----EXPLANATION:-----\n22 * 31 * 52= 300 which is N over here. \nThe four numbers less than or equal to 300 are 30, 60, 150 and 300.\n\n30 = 21 * 31 * 51 , 60 = 22 * 31 * 51, 150 = 21 * 31 * 52 and 300 = 22 * 31 * 52. \nIn the 4 numbers, the minimum powers for 2, 3 and 5 are 1, 1 and 1 or more than them in every case.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n\r\n\r\nd = 10**9 + 7\r\n\r\nt = int(input())\r\nwhile t:\r\n t-=1\r\n n =int(input())\r\n p =list(map(int, input().strip().split()))\r\n a =list(map(int, input().strip().split()))\r\n b =list(map(int, input().strip().split()))\r\n ans = 1\r\n for i in range(n):\r\n c = a[i] - b[i] + 1\r\n tmp = (( pow(p[i],b[i],d) * ((pow(p[i],c,d) - 1 + d)%d) * pow(p[i]-1 , d-2, d)%d))\r\n ans *= tmp\r\n ans = ans%d\r\n\r\n print(ans)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n3\\n2 3 5\\n2 1 2\\n1 1 1\\n', 'output': '540\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/AARA2018/problems/ARMBH4'}","problem_id":"vfc_1414","program":"```python\n\r\n\r\nd = 10**9 + 7\r\n\r\nt = int(input())\r\nwhile t:\r\n t-=1\r\n n =int(input())\r\n p =list(map(int, input().strip().split()))\r\n a =list(map(int, input().strip().split()))\r\n b =list(map(int, input().strip().split()))\r\n ans = 1\r\n for i in range(n):\r\n c = a[i] - b[i] + 1\r\n tmp = (( pow(p[i],b[i],d) * ((pow(p[i],c,d) - 1 + d)%d) * pow(p[i]-1 , d-2, d)%d))\r\n ans *= tmp\r\n ans = ans%d\r\n\r\n print(ans)\n```","inputs":"1\n3\n2 3 5\n2 1 2\n1 1 1\n","output":"540\n","actual_output":"540\n","execution_success":true,"sample_index":253},{"source":"apps","task_type":"verifiable_code","in_source_id":"644","prompt":"Solve the following coding problem using the programming language python:\n\nThere are $N$ friends in a group. Each of them have $A_{i}$ candies.\nCan they share all of these candies among themselves such that each one of them have equal no. of candies.\n\n-----Input:-----\n- First line will contain $T$, number of testcases. Then the testcases follow. \n- First line of each testcase contains of a single line of input, an integer $N$ denoting no. of friends in the group. \n- Next line contains $N$ space separated integers $A_{i}$ denoting the no. candies $i^{th}$ friend has.\n\n-----Output:-----\nFor each testcase, output $\"Yes\"$ if it is possible to share equally else $\"No\"$ (without \" \").\n\n-----Constraints-----\n- $1 \\leq T \\leq 10$\n- $1 \\leq N \\leq 100$\n- $0 \\leq A_{i} \\leq 1000$\n\n-----Sample Input:-----\n1\n\n3\n\n1 2 3\n\n-----Sample Output:-----\nYes\n\n-----EXPLANATION:-----\nEach of them have $2$ candies after sharing.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\n\nfor _ in range(int(input())):\n friends = int(input())\n candies = list(map(int,input().split()))\n if (sum(candies) % friends == 0):\n print(\"Yes\")\n else:\n print(\"No\")\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n3\\n1 2 3\\n', 'output': 'Yes\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/ENJU2020/problems/ECJN202'}","problem_id":"vfc_1418","program":"```python\n# cook your dish here\n\nfor _ in range(int(input())):\n friends = int(input())\n candies = list(map(int,input().split()))\n if (sum(candies) % friends == 0):\n print(\"Yes\")\n else:\n print(\"No\")\n```","inputs":"1\n3\n1 2 3\n","output":"Yes\n","actual_output":"Yes\n","execution_success":true,"sample_index":254},{"source":"apps","task_type":"verifiable_code","in_source_id":"645","prompt":"Solve the following coding problem using the programming language python:\n\nChef has $K$ chocolates and he wants to distribute them to $N$ people (numbered $1$ through $N$). These people are standing in a line in such a way that for each $i$ ($1 \\le i \\le N-1$), person $i$ and person $i+1$ are adjacent.\nFirst, consider some way to distribute chocolates such that for each valid $i$, the number of chocolates the $i$-th person would receive from Chef is $A_i$ and the sum $S_1 = \\sum_{i=1}^{N-1} \\left|A_i - A_{i+1}\\right|$ is minimum possible. Of course, each person must receive a non-negative integer number of chocolates.\nThen, Chef wants to create a new sequence $B_1, B_2, \\ldots, B_N$ by rearranging (permuting) the elements of the sequence $A_1, A_2, \\ldots, A_N$. For each valid $i$, the number of chocolates the $i$-th person actually receives from Chef is $B_i$. Chef wants to distribute the chocolates (choose $B_1, B_2, \\ldots, B_N$ by permuting the sequence $A$ and give $B_i$ chocolates to the $i$-th person for each valid $i$) in such a way that $S_2 = \\sum_{i=1}^{N-1} \\left|B_i \u2013 B_{i+1}\\right|$ is maximum possible. You need to find the maximum value of $S_2$.\nIt is guaranteed that $S_2$ does not depend on the exact choice of the sequence $A_1, A_2, \\ldots, A_N$, as long as it is a sequence that minimises $S_1$.\n\n-----Input-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The first line of each test case contains a single integer $N$.\n- The second line contains a single integer $K$.\n\n-----Output-----\nFor each test case, print a single line containing one integer \u2014 the maximum value of the sum $S_2$.\n\n-----Constraints-----\n- $1 \\le T \\le 10$\n- $2 \\le N \\le 10^5$\n- $2 \\le K \\le 10^{100,000}$\n\n-----Subtasks-----\nSubtask #1 (30 points): $2 \\le N, K \\le 1,000$\nSubtask #2 (70 points): original constraints\n\n-----Example Input-----\n1\n3\n2\n\n-----Example Output-----\n2\n\n-----Explanation-----\nExample case 1: To minimise $S_1$, Chef could give $1$ chocolate to person $1$ and $1$ chocolate to person $2$, so $S_1 = |1-1| + |1-0| = 1$.\nTo maximise $S_2$, Chef can give $1$ chocolate to person $1$ and $1$ chocolate to person $3$, since the sequence $B = (1, 0, 1)$ is a permutation of $A = (1, 1, 0)$. Then, $S_2 = |1-0| + |0-1| = 2$.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nt = int(input())\nfor _ in range(t):\n n = int(input())\n k = int(input())\n num = int(k/n)\n x = max(n*(1+num) - k, 0)\n diff = abs(x - (n-x))\n if diff == 0:\n number = 2*x - 1\n else:\n number = min(x, n-x)*2\n print(number)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n3\\n2\\n', 'output': '2\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/MMAX'}","problem_id":"vfc_1422","program":"```python\nt = int(input())\nfor _ in range(t):\n n = int(input())\n k = int(input())\n num = int(k/n)\n x = max(n*(1+num) - k, 0)\n diff = abs(x - (n-x))\n if diff == 0:\n number = 2*x - 1\n else:\n number = min(x, n-x)*2\n print(number)\n```","inputs":"1\n3\n2\n","output":"2\n","actual_output":"2\n","execution_success":true,"sample_index":255},{"source":"apps","task_type":"verifiable_code","in_source_id":"646","prompt":"Solve the following coding problem using the programming language python:\n\nGiven a string $s$.\nYou can perform the following operation on given string any number of time.\nDelete two successive elements of the string if they are same.\nAfter performing the above operation you have to return the least possible length of the string.\n\n-----Input:-----\n- First line will contain $T$, number of testcases. Then the testcases follow. \n- Each testcase contains of a single line of input, a string $s$. \n\n-----Output:-----\nFor each testcase, output in a single line answer- minimum length of string possible after performing given operations.\n\n-----Constraints-----\n- $1 \\leq T \\leq 1000$\n- $2 \\leq length of string \\leq 10^5$\n$s$ contains only lowercase letters.\n\n-----Sample Input:-----\n3\nabccd\nabbac\naaaa\n\n-----Sample Output:-----\n3\n1\n0\n\n-----EXPLANATION:-----\n- In first case, $\"abd\"$ will be final string.\n- in second case, $\"c\"$ will be final string\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfrom sys import stdin,stdout\nimport math,bisect\nfrom datetime import date\nfrom collections import Counter,deque,defaultdict\nL=lambda:list(map(int, stdin.readline().strip().split()))\nM=lambda:list(map(int, stdin.readline().strip().split()))\nI=lambda:int(stdin.readline().strip())\nS=lambda:stdin.readline().strip()\nC=lambda:stdin.readline().strip().split()\ndef pr(a):return(\"\".join(list(map(str,a))))\n#_________________________________________________#\n\ndef solve():\n s = list(S())\n a=[s[0]]\n for i in range(1,len(s)):\n if a and a[-1]==s[i]:\n a.pop()\n else:\n a.append(s[i])\n print(len(a))\n \nfor _ in range(I()): \n solve()\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\nabccd\\nabbac\\naaaa\\n', 'output': '3\\n1\\n0\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/CDGO2021/problems/MINLEN'}","problem_id":"vfc_1426","program":"```python\nfrom sys import stdin,stdout\nimport math,bisect\nfrom datetime import date\nfrom collections import Counter,deque,defaultdict\nL=lambda:list(map(int, stdin.readline().strip().split()))\nM=lambda:list(map(int, stdin.readline().strip().split()))\nI=lambda:int(stdin.readline().strip())\nS=lambda:stdin.readline().strip()\nC=lambda:stdin.readline().strip().split()\ndef pr(a):return(\"\".join(list(map(str,a))))\n#_________________________________________________#\n\ndef solve():\n s = list(S())\n a=[s[0]]\n for i in range(1,len(s)):\n if a and a[-1]==s[i]:\n a.pop()\n else:\n a.append(s[i])\n print(len(a))\n \nfor _ in range(I()): \n solve()\n\n```","inputs":"3\nabccd\nabbac\naaaa\n","output":"3\n1\n0\n","actual_output":"3\n1\n0\n","execution_success":true,"sample_index":256},{"source":"apps","task_type":"verifiable_code","in_source_id":"647","prompt":"Solve the following coding problem using the programming language python:\n\nAshley wrote a random number generator code.\nDue to some reasons, the code only generates random positive integers which are not evenly divisible by 10. She gives $N$ and $S$ as input to the random number generator. The code generates a random number with number of digits equal to $N$ and sum of digits equal to $S$. The code returns -1 if no number can be generated. Print \"-1\" in such cases (without quotes). Else print the minimum possible product of digits of the random number generated.\n\n-----Input:-----\n- First line will contain a single integer $T$, the number of testcases. \n- Each testcase consists of two space separated integers, $N$ and $S$. \n\n-----Output:-----\nFor each testcase, output the answer on a new line.\n\n-----Constraints-----\n- $1 \\leq T \\leq 10^5$\n- $1 \\leq N \\leq 18$\n- $1 \\leq S \\leq 5 * N$\n\n-----Sample Input:-----\n2\n1 5\n\n2 2\n\n-----Sample Output:-----\n5\n\n1\n\n-----EXPLANATION:-----\nIn first testcase, the only possible number of length 1 having digit sum 5 is 5. And it's product of digits is 5. \nIn second testcase, only possible two digit number as a generator output is 11(as 20 is divisible by 10, it is never generated) and product of it's digits is 1.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n\"\"\"\n Author : thekushalghosh\n Team : CodeDiggers\n\"\"\"\nimport sys,math\ninput = sys.stdin.readline\n############ ---- USER DEFINED INPUT FUNCTIONS ---- ############\ndef inp():\n return(int(input()))\ndef inlt():\n return(list(map(int,input().split())))\ndef insr():\n s = input()\n return(s[:len(s) - 1])\ndef invr():\n return(map(int,input().split()))\n################################################################\n############ ---- THE ACTUAL CODE STARTS BELOW ---- ############\nt = 1\nt = inp()\nfor tt in range(t):\n n,s = invr()\n if n == 2 and s > 1:\n print(s - 1)\n elif n > 2 and s > 1:\n print(0)\n elif n == 1:\n print(s)\n else:\n print(-1)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n1 5\\n2 2\\n', 'output': '5\\n1\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/NCC2020/problems/NCC005'}","problem_id":"vfc_1430","program":"```python\n\"\"\"\n Author : thekushalghosh\n Team : CodeDiggers\n\"\"\"\nimport sys,math\ninput = sys.stdin.readline\n############ ---- USER DEFINED INPUT FUNCTIONS ---- ############\ndef inp():\n return(int(input()))\ndef inlt():\n return(list(map(int,input().split())))\ndef insr():\n s = input()\n return(s[:len(s) - 1])\ndef invr():\n return(map(int,input().split()))\n################################################################\n############ ---- THE ACTUAL CODE STARTS BELOW ---- ############\nt = 1\nt = inp()\nfor tt in range(t):\n n,s = invr()\n if n == 2 and s > 1:\n print(s - 1)\n elif n > 2 and s > 1:\n print(0)\n elif n == 1:\n print(s)\n else:\n print(-1)\n```","inputs":"2\n1 5\n2 2\n","output":"5\n1\n","actual_output":"5\n1\n","execution_success":true,"sample_index":257},{"source":"apps","task_type":"verifiable_code","in_source_id":"648","prompt":"Solve the following coding problem using the programming language python:\n\nChef is going to organize a hill jumping competition and he is going to be one of the judges in it. In this competition there are N hills in a row, and the initial height of i-th hill is Ai. Participants are required to demonstrate their jumping skills by doing what the judges tell them.\nJudges will give each participant a card which has two numbers, i and k, which means that the participant should start at the i-th hill and jump k times, where one jump should be from the current hill to the nearest hill to the right which is strictly higher (in height) than the current one. If there is no such hill or its distance (i.e. difference between their indices) is more than 100 then the participant should remain in his current hill.\nPlease help Chef by creating a program to use it during the competitions. It should read the initial heights of the hill and should support two kinds of operations:\nType 1: Given a two numbers: i and k, your program should output the index of the hill the participant is expected to finish if he starts from the i-th hill (as explained above).\nType 2: Given three numbers: L, R, X, the heights of all the hills between L and R, both end points inclusive, should be increased by X (if X is negative then their height is decreased).\n\n-----Input-----\n- First line contains two integers N and Q, denoting the number of hills and number of operations respectively.\n- Second line contains N space-separated integers A1, A2, ..., AN denoting the initial heights of the hills.\n- Each of the next Q lines describes an operation. If the first integer is equal to 1, it means that the operation is of Type 1, and it will be followed by two integers i and k. Otherwise the first number will be equal to 2, and it means that the operation is of Type 2, and so it will be followed by three integers L, R and X.\n\n-----Output-----\nFor each operation of Type 1, output the index of the hill in which the participant will finish.\n\n-----Constraints-----\n- 1 \u2264 N, Q \u2264 100,000\n- 1 \u2264 Ai \u2264 1,000,000\n- 1 \u2264 L \u2264 R \u2264 N\n- -1,000,000 \u2264 X \u2264 1,000,000\n- 1 \u2264 i, k \u2264 N\n\n-----Subtasks-----\n- Subtask 1 (20 points) : 1 \u2264 N, Q \u2264 1,000 \n- Subtask 2 (80 points) : Original constraints\n\n-----Example-----\nInput:\n5 3\n1 2 3 4 5\n1 1 2\n2 3 4 -1\n1 1 2\n\nOutput:\n3\n4\n\n-----Explanation-----\nThe initial heights are (1, 2, 3, 4, 5). The first operation is of Type 1 and starts from Hill 1 and wants to jump twice. The first jump will be to Hill 2, and the second jump will be to Hill 3. Hence the output for this is 3.\nThe second operation changes the heights to (1, 2, 2, 3, 5).\nThe last operation starts from Hill 1. The first jump is to Hill 2. But the next jump will skip Hill 3 (because it's height is not strictly greater than the current hill's height), and will go to Hill 4. Hence the output is 4.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nn,q=list(map(int,input().split()))\nfinal=[]\nheight=list(map(int,input().split()))\nfor k in range(0,q):\n b=input().split()\n if int(b[0])==1:\n step=int(b[1])-1\n for k in range(0,int(b[2])):\n temp = 0\n j=1\n while j in range(1,101) and temp==0 and step+jheight[step]:\n step=step+j\n temp=1\n j+=1\n final.append(step+1)\n elif int(b[0])==2:\n for k in range(int(b[1])-1,int(b[2])):\n height[k]=height[k]+int(b[3])\nfor l in range(0,len(final)):\n print(final[l])\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '5 3\\n1 2 3 4 5\\n1 1 2\\n2 3 4 -1\\n1 1 2\\n', 'output': '3\\n4\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/AUG17/problems/HILLJUMP'}","problem_id":"vfc_1434","program":"```python\nn,q=list(map(int,input().split()))\nfinal=[]\nheight=list(map(int,input().split()))\nfor k in range(0,q):\n b=input().split()\n if int(b[0])==1:\n step=int(b[1])-1\n for k in range(0,int(b[2])):\n temp = 0\n j=1\n while j in range(1,101) and temp==0 and step+jheight[step]:\n step=step+j\n temp=1\n j+=1\n final.append(step+1)\n elif int(b[0])==2:\n for k in range(int(b[1])-1,int(b[2])):\n height[k]=height[k]+int(b[3])\nfor l in range(0,len(final)):\n print(final[l])\n```","inputs":"5 3\n1 2 3 4 5\n1 1 2\n2 3 4 -1\n1 1 2\n","output":"3\n4\n","actual_output":"3\n4\n","execution_success":true,"sample_index":258},{"source":"apps","task_type":"verifiable_code","in_source_id":"649","prompt":"Solve the following coding problem using the programming language python:\n\nMandarin chinese\n, Russian and Vietnamese as well.\nYou are given a grid with $n$ rows and $m$ columns. Each cell of this grid can either be empty or it contains one particle. It can never contain more than one particle. Let's denote the cell in the $i$-th row and $j$-th column by $(i, j)$, with the top left corner being $(0, 0)$. From a cell $(i, j)$, a particle could move in one of the following four directions:\n- to the left, i.e. to the cell $(i, j - 1)$\n- to the right, i.e. to the cell $(i, j + 1)$\n- up, i.e. to the cell $(i - 1, j)$\n- down, i.e. to the cell $(i + 1, j)$\nIt is not possible for a particle to move to a cell that already contains a particle or to a cell that does not exist (leave the grid).\nIt is possible to apply a force in each of these directions. When a force is applied in a given direction, all particles will simultaneously start moving in this direction as long as it is still possible for them to move.\nYou are given a sequence of forces. Each subsequent force is applied only after all particles have stopped moving. Determine which cells of the grid contain particles after all forces from this sequence are applied in the given order.\n\n-----Input-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The first line of each test case contains two space-separated integers $n$ and $m$.\n- $n$ lines describing the initial grid follow. For each $i$ ($1 \\le i \\le n$), the $i$-th of these lines contains a binary string with length $m$ describing the $i$-th row of the grid. For each $j$ ($1 \\le j \\le m$), if the $j$-th character of this string is '1', then the cell $(i, j)$ contains a particle, and if it is '0', then the cell $(i, j)$ is empty.\n- The last line contains a single string $S$ describing the sequence of applied forces. Each character of this string corresponds to applying a force in some direction; forces applied in the directions left, right, up, down correspond to characters 'L', 'R', 'U', 'D' respectively.\n\n-----Output-----\nFor each test case, print $n$ lines each containing a binary string of length $m$, describing the resulting grid (after all the forces are applied) in the same format as the input grid.\n\n-----Constraints-----\n- $1 \\le T \\le 200$\n- $1 \\le n, m \\le 100$\n- $1 \\le |S| \\le 2 \\cdot 10^4$\n\n-----Subtasks-----\nSubtaks #1 (30 points):\n- $1 \\le T \\le 10$\n- $1 \\le n, m \\le 10$\n- $1 \\le |S| \\le 100$\nSubtask #2 (70 points): Original constraints\n\n-----Example Input-----\n3\n4 4\n1010\n0010\n1001\n0100\nLRDU\n4 3\n000\n010\n001\n101\nLRL\n3 2\n01\n10\n00\nD\n\n-----Example Output-----\n0011\n0011\n0001\n0001\n000\n100\n100\n110\n00\n00\n11\n\n-----Explanation-----\nExample case 1: The initial grid is:\n1010\n0010\n1001\n0100\n\nAfter applying the first force (in the direction \"L\", i.e. to the left), the grid is:\n1100\n1000\n1100\n1000\n\nAfter applying the second force (in the direction \"R\"), the grid is:\n0011\n0001\n0011\n0001\n\nAfter applying the third force (in the direction \"D\"), the grid is:\n0001\n0001\n0011\n0011\n\nAfter applying the fourth force (in the direction \"U\"), the final grid is:\n0011\n0011\n0001\n0001\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\ndef main():\n for _ in range(int(input())):\n rows,column = map(int,input().split())\n arr = []\n for i in range(rows):\n arr.append(list(input()))\n string = input()\n last = string[-1]\n operation = Find(string,last)\n for i in string[0]+operation:\n if i == \"L\":\n arr = Left(arr)\n if i == \"R\":\n arr = Right(arr)\n if i == \"U\":\n arr = Transpose(arr)\n arr = Left(arr)\n arr = Transpose(arr)\n if i == \"D\":\n arr = Transpose(arr)\n arr = Right(arr)\n arr = Transpose(arr)\n for i in arr:\n print(i)\ndef Left(arr):\n for i in range(len(arr)):\n ans = arr[i].count(\"1\")\n arr[i] = \"1\"*ans + (len(arr[i]) - ans)*\"0\"\n return arr\ndef Right(arr):\n for i in range(len(arr)):\n ans = arr[i].count(\"1\")\n arr[i] = (len(arr[i]) - ans)*\"0\"+\"1\"*ans\n return arr\ndef Transpose(arr):\n ansss = []\n ans = list(map(list, zip(*arr)))\n for i in ans:\n ass = i\n hello = \"\"\n for j in ass:\n hello += j\n ansss.append(hello)\n return ansss \ndef Find(string,last):\n for i in string[-2::-1]: \n if last == \"L\":\n if i in [\"D\",\"U\"]:\n last = i + last\n break\n if last == \"R\":\n if i in [\"D\",\"U\"]:\n last = i + last\n break\n if last == \"D\":\n if i in [\"L\",\"R\"]:\n last = i + last\n break\n if last == \"U\":\n if i in [\"L\",\"R\"]:\n last = i + last\n break\n return last\n \ndef __starting_point():\n main()\n__starting_point()\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\n4 4\\n1010\\n0010\\n1001\\n0100\\nLRDU\\n4 3\\n000\\n010\\n001\\n101\\nLRL\\n3 2\\n01\\n10\\n00\\nD\\n', 'output': '0011\\n0011\\n0001\\n0001\\n000\\n100\\n100\\n110\\n00\\n00\\n11\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/FRCPRT'}","problem_id":"vfc_1438","program":"```python\ndef main():\n for _ in range(int(input())):\n rows,column = map(int,input().split())\n arr = []\n for i in range(rows):\n arr.append(list(input()))\n string = input()\n last = string[-1]\n operation = Find(string,last)\n for i in string[0]+operation:\n if i == \"L\":\n arr = Left(arr)\n if i == \"R\":\n arr = Right(arr)\n if i == \"U\":\n arr = Transpose(arr)\n arr = Left(arr)\n arr = Transpose(arr)\n if i == \"D\":\n arr = Transpose(arr)\n arr = Right(arr)\n arr = Transpose(arr)\n for i in arr:\n print(i)\ndef Left(arr):\n for i in range(len(arr)):\n ans = arr[i].count(\"1\")\n arr[i] = \"1\"*ans + (len(arr[i]) - ans)*\"0\"\n return arr\ndef Right(arr):\n for i in range(len(arr)):\n ans = arr[i].count(\"1\")\n arr[i] = (len(arr[i]) - ans)*\"0\"+\"1\"*ans\n return arr\ndef Transpose(arr):\n ansss = []\n ans = list(map(list, zip(*arr)))\n for i in ans:\n ass = i\n hello = \"\"\n for j in ass:\n hello += j\n ansss.append(hello)\n return ansss \ndef Find(string,last):\n for i in string[-2::-1]: \n if last == \"L\":\n if i in [\"D\",\"U\"]:\n last = i + last\n break\n if last == \"R\":\n if i in [\"D\",\"U\"]:\n last = i + last\n break\n if last == \"D\":\n if i in [\"L\",\"R\"]:\n last = i + last\n break\n if last == \"U\":\n if i in [\"L\",\"R\"]:\n last = i + last\n break\n return last\n \ndef __starting_point():\n main()\n__starting_point()\n```","inputs":"3\n4 4\n1010\n0010\n1001\n0100\nLRDU\n4 3\n000\n010\n001\n101\nLRL\n3 2\n01\n10\n00\nD\n","output":"0011\n0011\n0001\n0001\n000\n100\n100\n110\n00\n00\n11\n","actual_output":"0011\n0011\n0001\n0001\n000\n100\n100\n110\n00\n00\n11\n","execution_success":true,"sample_index":259},{"source":"apps","task_type":"verifiable_code","in_source_id":"650","prompt":"Solve the following coding problem using the programming language python:\n\nChef is the event manager of his college. He has been assigned the task to manage the upcoming tech fest. There are $K$ rooms where the event can take place, and at a particular time only one event can be organized in a room for a particular time interval.\nEach event coordinator has their strictly preferred room $P_i$, and if the room is already occupied he simply cancels that event.Chef wants to maximize the total number of events,and so he allows or disallows certain events in order to achieve the task . Chef is busy handling his events so the chef needs your help .\nGiven a list of $N$ events with their start time $S_i$,end time $E_i$ and preferred room $P_i$,you need to calculate the maximum number of events that can take place.\nNote that the $i$th event wants to occupy the $p_i$ room from [$s_i$, $f_i$) .\n\n-----Input:-----\nThe first line contains an integer $T$ denoting the number of test cases . Each of the next $T$ lines contains two integers $N$ and $K$ , the number of events and the number of rooms respectively . Each of the next $N$ lines contains three integers $s_i$ ,$e_i$ and $p_i$,the start time ,end time and the preferred room of ith event.\n\n-----Output:-----\nPrint the maximum number of events that can take place.\n\n-----Constraints-----\n- $1 \\leq T \\leq 100$\n- $1 \\leq N \\leq 10^3$\n- $1 \\leq K \\leq 10^5$\n- $1 \\leq Si < Ei \\leq 10^9$\n- $1 \\leq Pi \\leq K$\n\n-----Sample Input:-----\n1\n\n4 2\n1 10 1\n10 20 2\n15 50 2\n20 30 2\n\n-----Sample Output:-----\n3\n\n-----EXPLANATION:-----\nChef can allow events 1st ,2nd and 4th,to get the maximum 3.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nimport sys\r\n# import math\r\nfrom math import gcd\r\n# import re\r\n# from heapq import *\r\n# from collections import defaultdict as dd\r\n# from collections import OrderedDict as odict\r\n# from collections import Counter as cc\r\n# from collections import deque\r\n# sys.setrecursionlimit(10**5)#thsis is must\r\n# mod = 10**9+7; md = 998244353\r\n# m = 2**32\r\ninput = lambda: sys.stdin.readline().strip()\r\ninp = lambda: list(map(int,sys.stdin.readline().strip().split()))\r\n# def C(n,r,mod):\r\n# if r>n:\r\n# return 0\r\n# num = den = 1\r\n# for i in range(r):\r\n# num = (num*(n-i))%mod\r\n# den = (den*(i+1))%mod\r\n# return (num*pow(den,mod-2,mod))%mod\r\n# M = 1000000+1\r\n# pfc = [i for i in range(M+1)]\r\n# def pfcs(M):\r\n# for i in range(2,M+1):\r\n# if pfc[i]==i:\r\n# for j in range(i+i,M+1,i):\r\n# if pfc[j]==j:\r\n# pfc[j] = i\r\n# return\r\n#______________________________________________________\r\nfor _ in range(int(input())):\r\n n,k = map(int,input().split())\r\n d = [[] for i in range(k+1)]\r\n for i in range(n):\r\n l,r,p = map(int,input().split())\r\n d[p].append([l,r])\r\n ans = 0\r\n for i in d:\r\n if len(i)==0:\r\n continue\r\n ans+=1\r\n t = sorted(i,key = lambda x:(x[1],x[0]))\r\n final = t[0][1]\r\n for j in range(1,len(t)):\r\n if t[j][0]>=final:\r\n ans+=1\r\n final = t[j][1]\r\n print(ans) \n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n4 2\\n1 10 1\\n10 20 2\\n15 50 2\\n20 30 2\\n', 'output': '3\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/ENNO2020/problems/ENCNOV4'}","problem_id":"vfc_1442","program":"```python\nimport sys\r\n# import math\r\nfrom math import gcd\r\n# import re\r\n# from heapq import *\r\n# from collections import defaultdict as dd\r\n# from collections import OrderedDict as odict\r\n# from collections import Counter as cc\r\n# from collections import deque\r\n# sys.setrecursionlimit(10**5)#thsis is must\r\n# mod = 10**9+7; md = 998244353\r\n# m = 2**32\r\ninput = lambda: sys.stdin.readline().strip()\r\ninp = lambda: list(map(int,sys.stdin.readline().strip().split()))\r\n# def C(n,r,mod):\r\n# if r>n:\r\n# return 0\r\n# num = den = 1\r\n# for i in range(r):\r\n# num = (num*(n-i))%mod\r\n# den = (den*(i+1))%mod\r\n# return (num*pow(den,mod-2,mod))%mod\r\n# M = 1000000+1\r\n# pfc = [i for i in range(M+1)]\r\n# def pfcs(M):\r\n# for i in range(2,M+1):\r\n# if pfc[i]==i:\r\n# for j in range(i+i,M+1,i):\r\n# if pfc[j]==j:\r\n# pfc[j] = i\r\n# return\r\n#______________________________________________________\r\nfor _ in range(int(input())):\r\n n,k = map(int,input().split())\r\n d = [[] for i in range(k+1)]\r\n for i in range(n):\r\n l,r,p = map(int,input().split())\r\n d[p].append([l,r])\r\n ans = 0\r\n for i in d:\r\n if len(i)==0:\r\n continue\r\n ans+=1\r\n t = sorted(i,key = lambda x:(x[1],x[0]))\r\n final = t[0][1]\r\n for j in range(1,len(t)):\r\n if t[j][0]>=final:\r\n ans+=1\r\n final = t[j][1]\r\n print(ans) \n```","inputs":"1\n4 2\n1 10 1\n10 20 2\n15 50 2\n20 30 2\n","output":"3\n","actual_output":"3\n","execution_success":true,"sample_index":260},{"source":"apps","task_type":"verifiable_code","in_source_id":"651","prompt":"Solve the following coding problem using the programming language python:\n\nIn these quarantine days, Chef and Chefina are getting bored. So, Chef came up with a game for her. He gets a pack of cards with numbers written on them. Chef then asks her to remove cards from the pack in the following manner: Chefina can choose any 3 cards at a time, having unique values, and remove the smallest and largest of them, and put back the middle one. For example, say Chefina chooses 3 cards that have numbers $x$, $y$, $z$ on them, such that $x <= y <= z$. Then she can throw away cards with number $x$ and $z$, but has to put the card with number $y$ on it back into the pack. Chefina can repeat this process any number of times. As soon as the pack contains cards with unique numbers, the game ends. If Chefina can determine the count of cards that will remain in the end, and tell it to Chef beforehand, she wins the game. Chefina asks for your help to win this game. Given the number written on the cards, help her find the count of cards in the pack when she wins.\n$Note:$ You need to maximize the array length or the number of unique elements\n\n-----Input:-----\n- The first line of the input consists of a single integer $T$, denoting the number of test cases. Description of $T$ test cases follow.\n- The first line of each test case consists of a single integer $N$, denoting the number of cards in the pack\n- The next line consists of $N$ space separated numbers $A1$, $A2$ \u2026 $An$. For each valid $i (1 <= i <= N)$, the $i$-th card has the number $Ai$ written on it.\n\n-----Output:-----\n- For each test case, print the count of the cards that remain in the end.\n\n-----Constraints-----\n- $1 \\leq T \\leq 500$\n- $1 \\leq N \\leq 10^6$\n- $1 \\leq Ai \\leq N$\n\n-----Subtasks-----\n- 30 points : $1 \\leq T \\leq 20$; $ 1 \\leq N \\leq 5*10^5$\n- 70 points : Original constraints\n\n-----Sample Input:-----\n2\n5\n1 2 2 3 5\n9\n1 2 2 3 3 5 8 8 9\n\n-----Sample Output:-----\n3\n5\n\n-----EXPLANATION:-----\nTest case 1:\nChefina chooses the cards with number: 2, 3, 5, throws away 2 & 5, and puts back 3. So, the pack now contains cards with numbers: 1, 2, 3. Since the pack contains cards with unique numbers only, these are the 3 final cards. \nTest case 2:\nChefina chooses the cards with number: 2, 3, 8, throws away 2 & 8, and puts back 3. Now the pack contains cards with numbers: 1, 2, 3, 3, 5, 8, 9. Next, she chooses cards with number: 3, 5, 8 throws away 3 & 8, and puts back 5. Now the pack contains cards with number: 1, 2, 3, 5, 9. Since the pack contains cards with unique numbers only, these are the 5 final cards.\nNote: There might be multiple options to choose the 3 cards from the pack in any turn\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\ntry:\n for i in range(int(input())):\n n=int(input())\n l=[int(j) for j in input().split()][:n]\n d={}\n for j in l:\n d[j]=d.get(j,0)+1\n a=len(d)\n c=0\n for j in list(d.keys()):\n while(d[j]>=3):\n d[j]=(d[j]//3)+(d[j]%3)\n if(d[j]==2):\n c=c+1\n if(c&1):\n s=0\n for j in list(d.values()):\n s=s+j\n print(s-c-1)\n else:\n s=0\n for j in list(d.values()):\n s=s+j\n print(s-c)\nexcept:\n pass\n \n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n5\\n1 2 2 3 5\\n9\\n1 2 2 3 3 5 8 8 9\\n', 'output': '3\\n5\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/BTCH2020/problems/UNQCARD'}","problem_id":"vfc_1446","program":"```python\n# cook your dish here\ntry:\n for i in range(int(input())):\n n=int(input())\n l=[int(j) for j in input().split()][:n]\n d={}\n for j in l:\n d[j]=d.get(j,0)+1\n a=len(d)\n c=0\n for j in list(d.keys()):\n while(d[j]>=3):\n d[j]=(d[j]//3)+(d[j]%3)\n if(d[j]==2):\n c=c+1\n if(c&1):\n s=0\n for j in list(d.values()):\n s=s+j\n print(s-c-1)\n else:\n s=0\n for j in list(d.values()):\n s=s+j\n print(s-c)\nexcept:\n pass\n \n\n```","inputs":"2\n5\n1 2 2 3 5\n9\n1 2 2 3 3 5 8 8 9\n","output":"3\n5\n","actual_output":"3\n5\n","execution_success":true,"sample_index":261},{"source":"apps","task_type":"verifiable_code","in_source_id":"652","prompt":"Solve the following coding problem using the programming language python:\n\nShubham recently learned the lexicographical order in strings.\n\nNow, he has two strings s1 and s2 of the equal size and Shubham wants to compare those two strings lexicographically.\n\nHelp Shubham with the strings comparison.\n\nNote:\n\nLetters are case insensitive. \n\n\n-----Input-----\n\nFirst line contains a integer T denoting the number of test cases. Each test case contains two strings of equal size in two separate lines.\n\n-----Output-----\n\nFor each test case,\n\nIf s1 < s2, print \"first\".\n\nIf s1 > s2, print \"second\".\n\nIf s1=s2, print \"equal\".\n\n\nin separate lines.\n\n-----Constraints-----\n\n- 1 \u2264 T \u2264 10^2\n- 1 \u2264 Length of the string \u2264 500\n\n-----Example-----\nInput:\n2\nabc\nacb\nAB\nba\n\nOutput:\nfirst\nfirst\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nt=eval(input())\nwhile t:\n t=t-1\n s1=input().lower()\n s2=input().lower()\n res=\"equal\"\n for i in range(len(s1)):\n if(s1[i]!=s2[i]):\n \n res=\"first\" if s1[i] 100\n\n-----Sample Input 1:-----\n1\n200\n100\n\n-----Sample Output 1:-----\n0\n\n-----Explanation:-----\nThe laser initially has only 100 energy. Since the only crystal requires 200 energy to destroy, we cannot perform any action here, and the game ends. The number of points is zero.\n\n-----Sample Input 2:-----\n2\n100 200\n150\n\n-----Sample Output 2:-----\n1\n\n-----Explanation:-----\nThe laser has 150 energy. We can consume 100 energy and destroy the first crystal and gain 1 point. The remaining energy is 50, which is not enough to destroy the other crystal. We end the game here as we have the maximum possible points attainable.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\ndef game(n,l,p):\n if(len(l)==0):\n return 0\n l.sort()\n if(len(l)>=1 and p=l[0]):\n p-=l[0]\n \n c+=1\n ma.add(c)\n l=l[1:]\n else:\n if(c>0):\n c-=1\n ma.add(c)\n p+=l[-1]\n l=l[:-1]\n else:\n return max(ma)\n return max(ma)\nn=int(input())\nl=list(map(int,input().split()))\np=int(input())\nprint(game(n,l,p))\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n200\\n100\\n', 'output': '0\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/COFJ2020/problems/JUN1'}","problem_id":"vfc_1454","program":"```python\ndef game(n,l,p):\n if(len(l)==0):\n return 0\n l.sort()\n if(len(l)>=1 and p=l[0]):\n p-=l[0]\n \n c+=1\n ma.add(c)\n l=l[1:]\n else:\n if(c>0):\n c-=1\n ma.add(c)\n p+=l[-1]\n l=l[:-1]\n else:\n return max(ma)\n return max(ma)\nn=int(input())\nl=list(map(int,input().split()))\np=int(input())\nprint(game(n,l,p))\n```","inputs":"1\n200\n100\n","output":"0\n","actual_output":"0\n","execution_success":true,"sample_index":263},{"source":"apps","task_type":"verifiable_code","in_source_id":"654","prompt":"Solve the following coding problem using the programming language python:\n\n\tThree numbers A, B and C are the inputs. Write a program to find second largest among them.\n\n-----Input-----\n\nThe first line contains an integer T, the total number of testcases. Then T lines follow, each line contains three integers A, B and C. \n\n-----Output-----\nFor each test case, display the second largest among A, B and C, in a new line.\n\n-----Constraints-----\n- 1 \u2264 T \u2264 1000\n- 1 \u2264 A,B,C \u2264 1000000\n\n-----Example-----\nInput\n3 \n120 11 400\n10213 312 10\n10 3 450\n\nOutput\n\n120\n312\n10\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\nx=int(input())\nfor i in range(x):\n s=list(map(int,input().split()))\n s.sort()\n print(s[1])\n \n \n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\n120 11 400\\n10213 312 10\\n10 3 450\\n', 'output': '120\\n312\\n10\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/FLOW017'}","problem_id":"vfc_1458","program":"```python\n# cook your dish here\nx=int(input())\nfor i in range(x):\n s=list(map(int,input().split()))\n s.sort()\n print(s[1])\n \n \n\n```","inputs":"3\n120 11 400\n10213 312 10\n10 3 450\n","output":"120\n312\n10\n","actual_output":"120\n312\n10\n","execution_success":true,"sample_index":264},{"source":"apps","task_type":"verifiable_code","in_source_id":"655","prompt":"Solve the following coding problem using the programming language python:\n\nChef had a sequence of positive integers with length $N + K$. He managed to calculate the arithmetic average of all elements of this sequence (let's denote it by $V$), but then, his little brother deleted $K$ elements from it. All deleted elements had the same value.\nChef still knows the remaining $N$ elements \u2014 a sequence $A_1, A_2, \\ldots, A_N$. Help him with restoring the original sequence by finding the value of the deleted elements or deciding that there is some mistake and the described scenario is impossible.\nNote that the if it is possible for the deleted elements to have the same value, then it can be proven that it is unique. Also note that this value must be a positive integer.\n\n-----Input-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The first line of each test case contains three space-separated integers $N$, $K$ and $V$.\n- The second line contains $N$ space-separated integers $A_1, A_2, \\ldots, A_N$.\n\n-----Output-----\nFor each test case, print a single line containing one integer \u2014 the value of the deleted elements, or $-1$ if there is a mistake.\n\n-----Constraints-----\n- $1 \\le T \\le 100$\n- $1 \\le N, K \\le 100$\n- $1 \\le V \\le 10^5$\n- $1 \\le A_i \\le 10^5$ for each valid $i$\n\n-----Subtasks-----\nSubtask #1 (100 points): original constraints\n\n-----Example Input-----\n3\n3 3 4\n2 7 3\n3 1 4\n7 6 5\n3 3 4\n2 8 3\n\n-----Example Output-----\n4\n-1\n-1\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\ndef __starting_point():\n t=int(input())\n for _ in range(t):\n n,k,v=map(int,input().split())\n li=list(map(int,input().split()))\n sumn=0\n for i in range(n):\n sumn=sumn+li[i]\n sumk=v*(n+k)-sumn\n e=int(sumk/k)\n r=sumk%k\n if e<=0:\n print(-1)\n elif r!=0:\n print(-1)\n else:\n print(e)\n__starting_point()\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\n3 3 4\\n2 7 3\\n3 1 4\\n7 6 5\\n3 3 4\\n2 8 3\\n', 'output': '4\\n-1\\n-1\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/AVG'}","problem_id":"vfc_1462","program":"```python\ndef __starting_point():\n t=int(input())\n for _ in range(t):\n n,k,v=map(int,input().split())\n li=list(map(int,input().split()))\n sumn=0\n for i in range(n):\n sumn=sumn+li[i]\n sumk=v*(n+k)-sumn\n e=int(sumk/k)\n r=sumk%k\n if e<=0:\n print(-1)\n elif r!=0:\n print(-1)\n else:\n print(e)\n__starting_point()\n```","inputs":"3\n3 3 4\n2 7 3\n3 1 4\n7 6 5\n3 3 4\n2 8 3\n","output":"4\n-1\n-1\n","actual_output":"4\n-1\n-1\n","execution_success":true,"sample_index":265},{"source":"apps","task_type":"verifiable_code","in_source_id":"656","prompt":"Solve the following coding problem using the programming language python:\n\nWrite a program to obtain a number $N$ and increment its value by 1 if the number is divisible by 4 $otherwise$ decrement its value by 1.\n\n-----Input:-----\n- First line will contain a number $N$.\n\n-----Output:-----\nOutput a single line, the new value of the number.\n\n-----Constraints-----\n- $0 \\leq N \\leq 1000$\n\n-----Sample Input:-----\n5\n\n-----Sample Output:-----\n4\n\n-----EXPLANATION:-----\nSince 5 is not divisible by 4 hence, its value is decreased by 1.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\nn = int(input())\nif(n%4==0):\n print(n+1)\nelse:\n print(n-1)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '5\\n', 'output': '4\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/DECINC'}","problem_id":"vfc_1466","program":"```python\n# cook your dish here\nn = int(input())\nif(n%4==0):\n print(n+1)\nelse:\n print(n-1)\n```","inputs":"5\n","output":"4\n","actual_output":"4\n","execution_success":true,"sample_index":266},{"source":"apps","task_type":"verifiable_code","in_source_id":"657","prompt":"Solve the following coding problem using the programming language python:\n\nYou will be given a two-dimensional array with row consisting values 0 or 1. \nA move consists of choosing any column or row, and toggling all the 0\u2019s as 1\u2019s and 1\u2019s as 0\u2019s. \nAfter making the required moves, every row represents a binary number and the score of the matrix will be sum of all the numbers represented as binary numbers in each row. \nFind the highest possible score. \n$Example:$ \nInput:\n\n0 0 1 1\n\n1 0 1 0\n\n1 1 0 0 \nOutput:\n\n39\nExplanation:\n\nToggled to\n\n1 1 1 1\n\n1 0 0 1\n\n1 1 1 1 \n0b1111 + 0b1001 + 0b1111 = 15 + 9 + 15 = 39\n\n-----Input:-----\n- First line will contains $m$, $n$ for the size of the 2-D array. \n- Contains $m$ lines of $n$ space-separated values each. \n\n-----Output:-----\nSingle integer which is the maximum score obtained by the sum of binary numbers.\n\n-----Constraints-----\n- $1 \\leq m, n \\leq 20$\n- $A[i][j] = 1$ or $0$ \n\n-----Sample Input:-----\n3 4 \n0 0 1 1 \n1 0 1 0 \n1 1 0 0 \n\n-----Sample Output:-----\n39\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\ndef matrixScore(A):\r\n \"\"\"\r\n :type A: List[List[int]]\r\n :rtype: int\r\n \"\"\"\r\n m,n = len(A),len(A[0])\r\n # \u884c\u53d8\u6362\r\n for i in range(m):\r\n if A[i][0] == 1: continue\r\n for j in range(n):\r\n A[i][j] = 1 - A[i][j]\r\n\r\n # \u5217\u53d8\u6362\r\n res = 0\r\n for rows in zip(*A):\r\n # \u59cb\u7ec8\u4f7f1\u7684\u4e2a\u6570\u662f\u66f4\u5927\u7684\r\n cnt1 = max(rows.count(1), rows.count(0))\r\n res += cnt1 * 2**(n-1)\r\n n -= 1\r\n return res\r\nm, n = [int(s) for s in input().split(\" \")]\r\narr = [[int(s) for s in input().split(\" \")] for i in range(m)]\r\nans = matrixScore(arr)\r\nprint(ans)\r\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3 4\\n0 0 1 1\\n1 0 1 0\\n1 1 0 0\\n', 'output': '39\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/COFDEC20/problems/COFDQ2'}","problem_id":"vfc_1470","program":"```python\ndef matrixScore(A):\r\n \"\"\"\r\n :type A: List[List[int]]\r\n :rtype: int\r\n \"\"\"\r\n m,n = len(A),len(A[0])\r\n # \u884c\u53d8\u6362\r\n for i in range(m):\r\n if A[i][0] == 1: continue\r\n for j in range(n):\r\n A[i][j] = 1 - A[i][j]\r\n\r\n # \u5217\u53d8\u6362\r\n res = 0\r\n for rows in zip(*A):\r\n # \u59cb\u7ec8\u4f7f1\u7684\u4e2a\u6570\u662f\u66f4\u5927\u7684\r\n cnt1 = max(rows.count(1), rows.count(0))\r\n res += cnt1 * 2**(n-1)\r\n n -= 1\r\n return res\r\nm, n = [int(s) for s in input().split(\" \")]\r\narr = [[int(s) for s in input().split(\" \")] for i in range(m)]\r\nans = matrixScore(arr)\r\nprint(ans)\r\n\n```","inputs":"3 4\n0 0 1 1\n1 0 1 0\n1 1 0 0\n","output":"39\n","actual_output":"39\n","execution_success":true,"sample_index":267},{"source":"apps","task_type":"verifiable_code","in_source_id":"658","prompt":"Solve the following coding problem using the programming language python:\n\nA sequence of integers ($a_1, a_2, \\ldots, a_k$) is said to be UpDown, if these inequalities hold true:\n- $a_1 \\le a_2$\n- $a_2 \\ge a_3$\n- $a_3 \\le a_4$\nand so on.\nThat is, every even-indexed element should be at least as large as its adjacent elements. And every odd-indexed element should be at most as large as its adjacent elements. Formally, $a_{2i} \\ge a_{2i+1}$ and $a_{2i+1} \\le a_{2i+2}$, for all valid positions.\nA subsegment is a consecutive portion of a sequence. That is, a subsegment of ($b_1, b_2, \\ldots, b_k$) will be of the form ($b_i, b_{i+1}, \\ldots, b_j$), for some $i$ and $j$.\nYou are given a sequence ($s_1, s_2, \\ldots, s_n$). You can insert at most one integer anywhere in this sequence. It could be any integer. After inserting an integer (or choosing not to), suppose you have the new sequence ($t_1, t_2, \\ldots, t_m$). Note that $m$ will either be $n$+1 or $n$. You want to maximize the length of the longest subsegment of ($t_1, t_2, \\ldots, t_m$) which is UpDown, and output the length of that.\n\n-----Input-----\n- The first line contains a single integer, $T$, which is the number of testcases. The description of each testcase follows.\n- The first line of every testcase contains a single integer, $n$, which is the number of integers in the original sequence.\n- The second line contains $n$ integers: $s_1, s_2, \\ldots, s_n$, which forms the original sequence.\n\n-----Output-----\nFor each testcase output a single line containing one integer, which should be the length of the longest UpDown subsegment that you can get after inserting at most one integer.\n\n-----Constraints-----\n- $1 \\le T \\le 2$\n- $1 \\le n \\le 10^6$\n- $1 \\le s_i \\le 10^9$\n\n-----Subtasks-----\nSubtask #1 (20 points): $1 \\le n \\le 100$\nSubtask #2 (10 points): $1 \\le n \\le 10000$\nSubtask #3 (70 points): Original constraints\n\n-----Sample Input-----\n2\n7\n100 1 10 3 20 25 24\n5\n3 3 2 4 1\n\n-----Sample Output-----\n7\n6\n\n-----Explanation-----\nTestcase 1: The original sequence is (100, 1, 10, 3, 20, 25, 24). Suppose you insert the element 5 between the elements 20 and 25, you will get the new sequence (100, 1, 10, 3, 20, 5, 25, 24). The longest UpDown subsegment of this sequence is (1, 10, 3, 20, 5, 25, 24), whose length is 7. You can check that you cannot do any better, and hence the answer is 7.\nTestcase 2: The original sequence is (3, 3, 2, 4, 1). Suppose you insert the element 4 at the end, you will get the new sequence (3, 3, 2, 4, 1, 4). This entire sequence is UpDown, and so the longest UpDown subsegment of this sequence is (3, 3, 2, 4, 1, 4), whose length is 6. You can check that you cannot do any better, and hence the answer is 6.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\nt=int(input())\nfor _ in range(t):\n n=int(input())\n array=list(map(int, input().split()))\n list_sub=[]\n idx=0\n counter=0\n for i in range(n-1):\n if counter%2==0 and array[i]<=array[i+1]:\n counter+=1 \n elif counter%2==1 and array[i]>=array[i+1]:\n counter+=1 \n else:\n list_sub.append((idx,i))\n if counter%2==1:\n idx=i \n counter=1\n else:\n idx=i+1 \n counter=0\n list_sub.append((idx, n-1))\n massimo=0\n if len(list_sub)==1:\n massimo=list_sub[0][1]-list_sub[0][0]+2\n for i in range(len(list_sub)-1):\n if list_sub[i][1]==list_sub[i+1][0]:\n massimo=max(massimo, list_sub[i][1]-list_sub[i][0]+2+list_sub[i+1][1]-list_sub[i+1][0])\n else:\n massimo=max(massimo, list_sub[i][1]-list_sub[i][0]+3+list_sub[i+1][1]-list_sub[i+1][0])\n print(massimo)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n7\\n100 1 10 3 20 25 24\\n5\\n3 3 2 4 1\\n', 'output': '7\\n6\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/ZCOPRAC/problems/UPDOWSEQ'}","problem_id":"vfc_1474","program":"```python\n# cook your dish here\nt=int(input())\nfor _ in range(t):\n n=int(input())\n array=list(map(int, input().split()))\n list_sub=[]\n idx=0\n counter=0\n for i in range(n-1):\n if counter%2==0 and array[i]<=array[i+1]:\n counter+=1 \n elif counter%2==1 and array[i]>=array[i+1]:\n counter+=1 \n else:\n list_sub.append((idx,i))\n if counter%2==1:\n idx=i \n counter=1\n else:\n idx=i+1 \n counter=0\n list_sub.append((idx, n-1))\n massimo=0\n if len(list_sub)==1:\n massimo=list_sub[0][1]-list_sub[0][0]+2\n for i in range(len(list_sub)-1):\n if list_sub[i][1]==list_sub[i+1][0]:\n massimo=max(massimo, list_sub[i][1]-list_sub[i][0]+2+list_sub[i+1][1]-list_sub[i+1][0])\n else:\n massimo=max(massimo, list_sub[i][1]-list_sub[i][0]+3+list_sub[i+1][1]-list_sub[i+1][0])\n print(massimo)\n```","inputs":"2\n7\n100 1 10 3 20 25 24\n5\n3 3 2 4 1\n","output":"7\n6\n","actual_output":"7\n6\n","execution_success":true,"sample_index":268},{"source":"apps","task_type":"verifiable_code","in_source_id":"660","prompt":"Solve the following coding problem using the programming language python:\n\nThe chef was busy in solving algebra, he found some interesting results, that there are many numbers which can be formed by the sum of the factorial of the digits, he wrote all those interesting numbers in the diary(in increasing order) and went to sleep. Cheffina came and stole his diary, in morning chef found that his diary is missing. Now the chef wants your help to find those numbers, Chef asks you whether N is that interesting number or not. If N is an interesting number then print 1. Else print 0. \n\n-----Input:-----\n- First-line will contain $T$, the number of test cases. Then the test cases follow. \n- Each test case contains a single line of input, $N$. \n\n-----Output:-----\nFor each test case, output in a single line answer 1 or 0.\n\n-----Constraints-----\n- $1 \\leq T \\leq 10^6$\n- $0 \\leq N \\leq 10^9$\n\n-----Sample Input:-----\n2\n2\n10\n\n-----Sample Output:-----\n1\n0\n\n-----EXPLANATION:-----\nFor 1) Factorial of 2 is 2, hence it is an interesting number.\nFor 2) conversion for 10 is 1! + 0! = 2, which is not equal to 10, hence not an interesting number.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nt = int(input())\nfor i in range(t):\n n = int(input())\n if n == 1 or n == 2 or n == 145 or n == 40585:\n print(1)\n else:\n print(0)\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n2\\n10\\n', 'output': '1\\n0\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/PBK22020/problems/ITGUY26'}","problem_id":"vfc_1482","program":"```python\nt = int(input())\nfor i in range(t):\n n = int(input())\n if n == 1 or n == 2 or n == 145 or n == 40585:\n print(1)\n else:\n print(0)\n\n```","inputs":"2\n2\n10\n","output":"1\n0\n","actual_output":"1\n0\n","execution_success":true,"sample_index":270},{"source":"apps","task_type":"verifiable_code","in_source_id":"661","prompt":"Solve the following coding problem using the programming language python:\n\nRaju has created a program to find the square root of a number. But his program can store only integers. Being a newbie, he didn't know about rounding the numbers. Hence his program returns the absolute value of the result if possible. For example, sqrt(3) = 1.73205080757\u2026\u2026. His program will return 1\nGiven a number $N$, and it's integral square root $S$, His instructor will consider the answer correct if Difference between $N$ and the square of $S$ is within less than or equal to $X$% of $N$.\n\n-----Input:-----\n- First line contains $T$ no. of test cases and $X$ separated by space\n- For every test case, a line contains an integer $N$\n\n-----Output:-----\nFor every test case, print yes if his programs return square root and (N-(S^2)) <= 0.01XN . For everything else, print no on a new line\n\n-----Constraints-----\n10 points:\n- $1 \\leq T \\leq 10$\n- $0\\leq N \\leq 10$\n20 points:\n- $1 \\leq T \\leq 30000$\n- $-10^9 \\leq N \\leq 10^9$\n70 points:\n- $1 \\leq T \\leq 10^6$\n- $-10^9 \\leq N \\leq 10^9$\n\n-----Sample Input:-----\n2 20\n5\n3\n\n-----Sample Output:-----\nyes\nno\n\n-----EXPLANATION:-----\nIn #1, sqrt(5) = 2.2360679775. Taking integral value, S = 2.\n\nS2 = 4. Difference=1 which is within 20% of 5\nIn #1, sqrt(3) = 1.73205080757. Taking integral value, S = 1.\n\nS2 = 1. Difference=2 which is not within 20% of 3\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\ntry:\n from math import sqrt\n t,x=list(map(int,input().split()))\n for _ in range(t):\n n=int(input())\n if(n<0):\n print(\"no\")\n else:\n diff=(x/100)*n\n ans=int(sqrt(n))\n ans1=ans**2\n if(n-ans1<=diff):\n print(\"yes\")\n else:\n print(\"no\")\nexcept:\n pass\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2 20\\n5\\n3\\n', 'output': 'yes\\nno\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/COMT2020/problems/ROOTSQR'}","problem_id":"vfc_1486","program":"```python\ntry:\n from math import sqrt\n t,x=list(map(int,input().split()))\n for _ in range(t):\n n=int(input())\n if(n<0):\n print(\"no\")\n else:\n diff=(x/100)*n\n ans=int(sqrt(n))\n ans1=ans**2\n if(n-ans1<=diff):\n print(\"yes\")\n else:\n print(\"no\")\nexcept:\n pass\n\n```","inputs":"2 20\n5\n3\n","output":"yes\nno\n","actual_output":"yes\nno\n","execution_success":true,"sample_index":271},{"source":"apps","task_type":"verifiable_code","in_source_id":"662","prompt":"Solve the following coding problem using the programming language python:\n\nKabir wants to impress Tara by showing her his problem solving skills. He has decided to give the correct answer to the next question which will be asked by his Algorithms teacher.\nThe question asked is:\nFind the sum of alternate consecutive d$d$ odd numbers from the range L$L$ to R$R$ inclusive.\nif d$d$ is 3 and L$L$ is 10 and R$R$ is 34, then the odd numbers between 10 and 34 are 11,13,15,17,19,21,23,25,27,29,31,33$11,13,15,17,19,21,23,25,27,29,31,33$, and the d$d$ alternate odd numbers are 11,13,15,23,25,27$11,13,15,23,25,27$.\nYou are a friend of Kabir, help him solve the question.\nNote:$Note:$ Number of odd number between L$L$ and R$R$ (both inclusive) is a multiple of d$d$.\n\n-----Input:-----\n- First line will contain T$T$, number of test cases. \n- First line of each test case contains one integer d$d$ . \n- Second line of each test case contains two space separated integer L$L$ and R$R$.\n\n-----Output:-----\nFor each test case, print the sum modulo 1000000007.\n\n-----Constraints:-----\n- 1\u2264T\u2264106$1 \\leq T \\leq 10^6$\n- 1\u2264d\u2264103$1 \\leq d \\leq 10^3$\n- 1\u2264L gar\nThen performing same operation gives :- gar -> arg\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\ndef least_rotation(S: str) -> int:\r\n \"\"\"Booth's algorithm.\"\"\"\r\n f = [-1] * len(S) # Failure function\r\n k = 0 # Least rotation of string found so far\r\n for j in range(1, len(S)):\r\n sj = S[j]\r\n i = f[j - k - 1]\r\n while i != -1 and sj != S[k + i + 1]:\r\n if sj < S[k + i + 1]:\r\n k = j - i - 1\r\n i = f[i]\r\n if sj != S[k + i + 1]: # if sj != S[k+i+1], then i == -1\r\n if sj < S[k]: # k+i+1 = k\r\n k = j\r\n f[j - k] = -1\r\n else:\r\n f[j - k] = i + 1\r\n return k\r\n\r\n\r\nfor _ in range(int(input())):\r\n l, s = input().split()\r\n if int(l) == 1:\r\n l = len(s)\r\n s += s\r\n k = least_rotation(s)\r\n print(s[k:k+l])\r\n else:\r\n print(''.join(sorted(s)))\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n1 rga\\n2 cab\\n', 'output': 'arg\\nabc\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/BIT32020/problems/BIT3B'}","problem_id":"vfc_1494","program":"```python\ndef least_rotation(S: str) -> int:\r\n \"\"\"Booth's algorithm.\"\"\"\r\n f = [-1] * len(S) # Failure function\r\n k = 0 # Least rotation of string found so far\r\n for j in range(1, len(S)):\r\n sj = S[j]\r\n i = f[j - k - 1]\r\n while i != -1 and sj != S[k + i + 1]:\r\n if sj < S[k + i + 1]:\r\n k = j - i - 1\r\n i = f[i]\r\n if sj != S[k + i + 1]: # if sj != S[k+i+1], then i == -1\r\n if sj < S[k]: # k+i+1 = k\r\n k = j\r\n f[j - k] = -1\r\n else:\r\n f[j - k] = i + 1\r\n return k\r\n\r\n\r\nfor _ in range(int(input())):\r\n l, s = input().split()\r\n if int(l) == 1:\r\n l = len(s)\r\n s += s\r\n k = least_rotation(s)\r\n print(s[k:k+l])\r\n else:\r\n print(''.join(sorted(s)))\n```","inputs":"2\n1 rga\n2 cab\n","output":"arg\nabc\n","actual_output":"arg\nabc\n","execution_success":true,"sample_index":273},{"source":"apps","task_type":"verifiable_code","in_source_id":"664","prompt":"Solve the following coding problem using the programming language python:\n\nThis year $p$ footballers and $q$ cricketers have been invited to participate in IPL (Indian Programming League) as guests. You have to accommodate them in $r$ rooms such that-\n- No room may remain empty.\n- A room may contain either only footballers or only cricketers, not both.\n- No cricketers are allowed to stay alone in a room.\nFind the number of ways to place the players. Note though, that all the rooms are identical. But each of the cricketers and footballers are unique. \nSince the number of ways can be very large, print the answer modulo $998,244,353$.\n\n-----Input-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The first and only line of each test case contains three space-separated integers $p$, $q$ and $r$ denoting the number of footballers, cricketers and rooms.\n\n-----Output-----\nFor each test case, output the number of ways to place the players modulo $998,244,353$.\n\n-----Constraints-----\n- $1 \\le T \\le 100$\n- $1 \\le p, q, r \\le 100$\n\n-----Example Input-----\n4\n2 1 4\n2 4 4\n2 5 4\n2 8 4\n\n-----Example Output-----\n0\n3\n10\n609\n\n-----Explanation-----\nExample case 2: Three possible ways are:\n- {Footballer 1}, {Footballer 2}, {Cricketer 1, Cricketer 2}, {Cricketer 3, Cricketer 4}\n- {Footballer 1}, {Footballer 2}, {Cricketer 1, Cricketer 3}, {Cricketer 2, Cricketer 4}\n- {Footballer 1}, {Footballer 2}, {Cricketer 1, Cricketer 4}, {Cricketer 2, Cricketer 3} \nPlease note that the rooms are identical.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\nMOD = 998244353\n\nfball = [ [0]*101 for _ in range(101) ]\n\ncric = [ [0]*101 for _ in range(101) ] \n\n\n\ndef calSNum(n, r):\n if n == r or r == 1:\n fball[r][n] = 1\n return\n if n > 0 and r > 0 and n > r:\n fball[r][n] = (fball[r-1][n-1]%MOD + (r*fball[r][n-1])%MOD )%MOD\n return\n fball[r][n] = 0\n \n\ndef calASNum(n, r):\n if n == 0 and r == 0 :\n cric[r][n] = 0\n return\n if n >= 2 and r == 1:\n cric[r][n] = 1\n return \n if r > 0 and n > 0 and n >= 2*r:\n cric[r][n] = ((r*cric[r][n-1])%MOD + ((n-1)*cric[r-1][n-2])%MOD )%MOD\n return\n cric[r][n] = 0\n \n\ndef preCompute():\n for r in range(1,101):\n for n in range(1, 101):\n calSNum(n, r)\n calASNum(n, r)\n\n \ndef main():\n \n preCompute()\n for _ in range(int(input())):\n f, c, r = list(map(int, input().split()))\n\n ans = 0\n \n if f + (c//2) >= r:\n minv = min(f, r)\n \n for i in range(1, minv+1):\n if r-i <= c//2:\n ans = (ans + (fball[i][f] * cric[r-i][c])%MOD )%MOD\n \n print(ans)\n \ndef __starting_point():\n main()\n\n__starting_point()\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '4\\n2 1 4\\n2 4 4\\n2 5 4\\n2 8 4\\n', 'output': '0\\n3\\n10\\n609\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/FCIPL'}","problem_id":"vfc_1498","program":"```python\n# cook your dish here\nMOD = 998244353\n\nfball = [ [0]*101 for _ in range(101) ]\n\ncric = [ [0]*101 for _ in range(101) ] \n\n\n\ndef calSNum(n, r):\n if n == r or r == 1:\n fball[r][n] = 1\n return\n if n > 0 and r > 0 and n > r:\n fball[r][n] = (fball[r-1][n-1]%MOD + (r*fball[r][n-1])%MOD )%MOD\n return\n fball[r][n] = 0\n \n\ndef calASNum(n, r):\n if n == 0 and r == 0 :\n cric[r][n] = 0\n return\n if n >= 2 and r == 1:\n cric[r][n] = 1\n return \n if r > 0 and n > 0 and n >= 2*r:\n cric[r][n] = ((r*cric[r][n-1])%MOD + ((n-1)*cric[r-1][n-2])%MOD )%MOD\n return\n cric[r][n] = 0\n \n\ndef preCompute():\n for r in range(1,101):\n for n in range(1, 101):\n calSNum(n, r)\n calASNum(n, r)\n\n \ndef main():\n \n preCompute()\n for _ in range(int(input())):\n f, c, r = list(map(int, input().split()))\n\n ans = 0\n \n if f + (c//2) >= r:\n minv = min(f, r)\n \n for i in range(1, minv+1):\n if r-i <= c//2:\n ans = (ans + (fball[i][f] * cric[r-i][c])%MOD )%MOD\n \n print(ans)\n \ndef __starting_point():\n main()\n\n__starting_point()\n```","inputs":"4\n2 1 4\n2 4 4\n2 5 4\n2 8 4\n","output":"0\n3\n10\n609\n","actual_output":"0\n3\n10\n609\n","execution_success":true,"sample_index":274},{"source":"apps","task_type":"verifiable_code","in_source_id":"665","prompt":"Solve the following coding problem using the programming language python:\n\nChef organised a chess tournament, which spanned over $M$ months. There were $N$ players, and player $i$ was rated $R_i$ before the start of the tournament. To see the progress of the players, he noted their rating changes at the end of each month.\nAfter the tournament, FIDE asked Chef to find the number of players whose peak rating and peak ranking did not occur in the same month. In other words, Chef was asked to find the ratings and ranking of each player after each of the $M$ months. Then, using this data, he should find the number of players, such that the month in which they achieved their highest rating over all the months, was different from the month in which they achieved their best rank (based on ratings), over all the months. Note that we do not consider the initial rating/ranking, but only the rating and rankings after each of the $M$ months. \nFor a particular player, if there are multiple peak rating or peak ranking months, Chef was to consider the earliest of them. If multiple players had the same rating at the end of some month, they were to be given the same rank. For example, if there were $5$ players, and their ratings at the end of some month were $(2600$, $2590$, $2600$, $2600$ and $2590)$, players $1$, $3$ and $4$ were to be given the first rank, while players $2$ and $5$ should be given the fourth rank.\nAs Chef hates statistics, he asks you, his friend, to help him find this. Can you help Chef?\n\n-----Input:-----\n- The first line contains an integer $T$, the number of test cases.\n- The first line of each test case contains two space-separated integers $N$ and $M$, the number of players and the number of months that the tournament spanned over.\n- The second line of each test case contains $N$ space-separated integers, $R_1, R_2, \\ldots, R_N$ denoting the initial ratings of the players, i.e., their ratings before the start of the tournament.\n- The next $N$ lines each contain $M$ space-separated integers. The $j^{th}$ integer of the $i^{th}$ line, $C_{i,j}$ denotes the rating change of the $i^{th}$ player after the $j^{th}$ month.\n\n-----Output:-----\nFor each test case, print the number of players whose peak ratings did not occur in the same month as their peak ranking, in a new line.\n\n-----Constraints-----\n- $1 \\le T \\le 10$\n- $1 \\le N,M \\le 500$\n- $1800 \\le R_i \\le 2800$\n- $-20 \\le C_{i,j} \\le 20$\n\n-----Subtasks-----\n- 30 points : $1 \\leq N,M \\leq 50$\n- 70 points : Original constraints.\n\n-----Sample Input:-----\n2\n3 3\n2500 2500 2520\n10 -5 -20\n10 15 20\n-15 17 13\n2 3\n2125 2098\n-20 10 -10\n10 10 -20\n\n-----Sample Output:-----\n2\n2\n\n-----Explanation:-----\nTest case 1:\n- \nThe ratings for player $1$ after each month are: $(2510$, $2505$ and $2485)$, while his rankings are first, third and third, respectively. Thus, his best rating and best ranking occur after the same month, i.e., after the first month.\n- \nThe ratings for player $2$ after each month are: $(2510$, $2525$ and $2545)$, while his rankings are first, first and first, respectively. His best rating occurs after the third month, while his best ranking occurs after the first month (we consider the first month even though his peak ranking is over all the months, because we consider only the earliest month where he attains the peak ranking).\n- \nThe ratings for player $3$ after each month are: $(2505$, $2522$ and $2535)$, while his rankings are third, second and second, respectively. His best rating occurs after the third month, while his best ranking occurs after the second month.\nSo there are two players ($2$ and $3$), whose peak ratings did not occur in the same month as their peak ranking, and hence the answer is 2.\nTest case 2:\n- \nThe ratings for player $1$ after each month are: $(2105$, $2115$ and $2105)$, while his rankings are second, second and first, respectively. Best rating is after second month, but best ranking is after third month.\n- \nThe ratings for player $2$ after each month are: $(2108$, $2118$ and $2098)$, while his rankings are first, first and second, respectively. Best rating is after second month, but best ranking is after first month.\nSo there are two players ($1$ and $2$), whose peak ratings did not occur in the same month as their peak ranking, and hence the answer is 2.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\nt=int(input())\nfor _ in range(t):\n n,m=list(map(int,input().split()))\n r=list(map(int,input().split()))\n rating=[[r[i]]*(m) for i in range(n)]\n ranking=[[0]*m for i in range(n)]\n for i in range(n):\n diff=list(map(int,input().split()))\n for j in range(m):\n rating[i][j]+=diff[j]\n if j+10 and rate[j-1][1]==rate[j][1]:\n gap+=1\n if j>0 and rate[j-1][1]!=rate[j][1]:\n c+=1+gap\n gap=0\n ranking[rate[j][0]][i]=c \n \n count=0\n for i in range(n):\n rate=rating[i].copy()\n i1=rate.index(max(rate))\n rank=ranking[i].copy()\n i2=rank.index(min(rank))\n if i1!=i2:\n count+=1\n print(count)\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n3 3\\n2500 2500 2520\\n10 -5 -20\\n10 15 20\\n-15 17 13\\n2 3\\n2125 2098\\n-20 10 -10\\n10 10 -20\\n', 'output': '2\\n2\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/ELOMAX'}","problem_id":"vfc_1502","program":"```python\n# cook your dish here\nt=int(input())\nfor _ in range(t):\n n,m=list(map(int,input().split()))\n r=list(map(int,input().split()))\n rating=[[r[i]]*(m) for i in range(n)]\n ranking=[[0]*m for i in range(n)]\n for i in range(n):\n diff=list(map(int,input().split()))\n for j in range(m):\n rating[i][j]+=diff[j]\n if j+10 and rate[j-1][1]==rate[j][1]:\n gap+=1\n if j>0 and rate[j-1][1]!=rate[j][1]:\n c+=1+gap\n gap=0\n ranking[rate[j][0]][i]=c \n \n count=0\n for i in range(n):\n rate=rating[i].copy()\n i1=rate.index(max(rate))\n rank=ranking[i].copy()\n i2=rank.index(min(rank))\n if i1!=i2:\n count+=1\n print(count)\n\n```","inputs":"2\n3 3\n2500 2500 2520\n10 -5 -20\n10 15 20\n-15 17 13\n2 3\n2125 2098\n-20 10 -10\n10 10 -20\n","output":"2\n2\n","actual_output":"2\n2\n","execution_success":true,"sample_index":275},{"source":"apps","task_type":"verifiable_code","in_source_id":"666","prompt":"Solve the following coding problem using the programming language python:\n\nThe 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.\n\n-----Input:-----\n- First-line will contain $T$, the number of test cases. Then the test cases follow. \n- Each test case contains a single line of input, one integer $K$. \n\n-----Output:-----\nFor each test case, output as the pattern.\n\n-----Constraints-----\n- $1 \\leq T \\leq 100$\n- $1 \\leq K \\leq 100$\n\n-----Sample Input:-----\n4\n1\n2\n3\n4\n\n-----Sample Output:-----\n1\n12\n34\n123\n456\n789\n1234\n5678\n9101112\n13141516\n\n-----EXPLANATION:-----\nNo need, else pattern can be decode easily.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\n\nt = int(input())\n\nfor _ in range(t):\n s = ''\n n = int(input())\n if n==1:\n print(1)\n continue\n for i in range(1, n+1):\n s = s + str(i)\n print(s)\n \n p = 1\n for i in range(n-1):\n s = ''\n for j in range(n):\n s = s + str(p + n)\n p = p+1\n \n print(s)\n \n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '4\\n1\\n2\\n3\\n4\\n', 'output': '1\\n12\\n34\\n123\\n456\\n789\\n1234\\n5678\\n9101112\\n13141516\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/PTRN2021/problems/ITGUY49'}","problem_id":"vfc_1506","program":"```python\n# cook your dish here\n\nt = int(input())\n\nfor _ in range(t):\n s = ''\n n = int(input())\n if n==1:\n print(1)\n continue\n for i in range(1, n+1):\n s = s + str(i)\n print(s)\n \n p = 1\n for i in range(n-1):\n s = ''\n for j in range(n):\n s = s + str(p + n)\n p = p+1\n \n print(s)\n \n\n```","inputs":"4\n1\n2\n3\n4\n","output":"1\n12\n34\n123\n456\n789\n1234\n5678\n9101112\n13141516\n","actual_output":"1\n12\n34\n123\n456\n789\n1234\n5678\n9101112\n13141516\n","execution_success":true,"sample_index":276},{"source":"apps","task_type":"verifiable_code","in_source_id":"667","prompt":"Solve the following coding problem using the programming language python:\n\nDiana is planning to make a very long journey. Her journey consists of $N$ bus routes, numbered from $1 to N$ in the order she must take them. The buses themselves are very fast but do not run often. The $i-th$ bus route only runs every $Xi$ days.\n\nMore specifically, she can only take the $i-th$ bus on day $Xi, 2Xi, 3Xi$, and so on. Since the buses are very fast, she can take multiple buses on the same day.\n\nDiana must finish her journey by day D, but she would like to start the journey as late as possible. What is the latest day she could take the first bus, and still finish her journey by day $D$?\nIt is guaranteed that it is possible for Diana to finish her journey by day $D$. \n\n-----Input:-----\nThe first line of the input gives the number of test cases, $T$. $T$ test cases follow. Each test case begins with a line containing the two integers N and D. Then, another line follows containing $N$ integers, the $i-th$ one is $Xi$.\n\n-----Output:-----\nFor each test case, output one line containing an integer $Y$, where $Y$ is the latest day she could take the first bus, and still finish her journey by day $D$.\n\n-----Constraints-----\n- $1 \\leq T \\leq 100$\n- $1 \\leq Xi \\leq D.$\n- $1 \\leq N \\leq 1000.$\nIt is guaranteed that it is possible for Diana to finish her journey by day $D$.\n\n-----Sample Input:-----\n3\n\n3 10\n\n3 7 2\n\n4 100\n\n11 10 5 50\n\n1 1\n\n1 \n\n-----Sample Output:-----\n6 \n\n99\n\n1 \n\n-----EXPLANATION:-----\nIn Sample $Case 1$, there are $N = 3$ bus routes and Bucket must arrive by day $D = 10$. She could:\n- Take the 1st bus on day 6 $(X1 = 3)$,\n- Take the 2nd bus on day 7 $(X2 = 7)$ and\n- Take the 3rd bus on day 8 $(X3 = 2)$. \nIn Sample $Case 2$, there are $N = 4$ bus routes and Bucket must arrive by day $D = 100$. She could:\n- Take the 1st bus on day 99 $(X1 = 11)$,\n- Take the 2nd bus on day 100$ (X2 = 10)$,\n- Take the 3rd bus on day 100 $(X3 = 5)$ and\n- Take the 4th bus on day 100 $(X4 = 50)$, \nIn Sample Case 3, there is $N = 1$ bus route, and Bucket must arrive by day $D = 1$. She could:\n- Take the 1st bus on day 1 $(X1 = 1)$.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nt = int(input())\r\nfor _ in range(t):\r\n nd = list(map(int, input().split()))\r\n n = nd[0]\r\n d = nd[1]\r\n cutOff = []\r\n x = d\r\n buses = list(map(int, input().split()))\r\n for i in range(len(buses)-1,-1,-1):\r\n x = x - x%buses[i]\r\n print(x)\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n \r\n\r\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\n3 10\\n3 7 2\\n4 100\\n11 10 5 50\\n1 1\\n1\\n', 'output': '6\\n99\\n1\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/COX22020/problems/CCODEX2'}","problem_id":"vfc_1510","program":"```python\nt = int(input())\r\nfor _ in range(t):\r\n nd = list(map(int, input().split()))\r\n n = nd[0]\r\n d = nd[1]\r\n cutOff = []\r\n x = d\r\n buses = list(map(int, input().split()))\r\n for i in range(len(buses)-1,-1,-1):\r\n x = x - x%buses[i]\r\n print(x)\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n \r\n\r\n\n```","inputs":"3\n3 10\n3 7 2\n4 100\n11 10 5 50\n1 1\n1\n","output":"6\n99\n1\n","actual_output":"6\n99\n1\n","execution_success":true,"sample_index":277},{"source":"apps","task_type":"verifiable_code","in_source_id":"668","prompt":"Solve the following coding problem using the programming language python:\n\nYou are given an array A with size N (indexed from 0) and an integer K. Let's define another array B with size N \u00b7 K as the array that's formed by concatenating K copies of array A.\nFor example, if A = {1, 2} and K = 3, then B = {1, 2, 1, 2, 1, 2}.\nYou have to find the maximum subarray sum of the array B. Fomally, you should compute the maximum value of Bi + Bi+1 + Bi+2 + ... + Bj, where 0 \u2264 i \u2264 j < N \u00b7 K.\n\n-----Input-----\n\n- The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows.\n- The first line of each test case contains two space-separated integers N and K.\n- The second line contains N space-separated integers A0, A1, ..., AN-1.\n\n-----Output-----\nFor each test case, print a single line containing the maximum subarray sum of B.\n\n-----Constraints-----\n- 1 \u2264 T \u2264 10\n- 1 \u2264 N \u2264 105\n- 1 \u2264 K \u2264 105\n- -106 \u2264 Ai \u2264 106 for each valid i\n\n-----Subtasks-----\nSubtask #1 (18 points): N \u00b7 K \u2264 105\nSubtask #2 (82 points): original constraints\n\n-----Example-----\nInput:\n\n2\n2 3\n1 2\n3 2\n1 -2 1\n\nOutput:\n\n9\n2\n\n-----Explanation-----\nExample case 1: B = {1, 2, 1, 2, 1, 2} and the subarray with maximum sum is the whole {1, 2, 1, 2, 1, 2}. Hence, the answer is 9.\nExample case 2: B = {1, -2, 1, 1, -2, 1} and the subarray with maximum sum is {1, 1}. Hence, the answer is 2.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\ndef max_sum(arr):\n # Finds the maximum sum of sub-arrays of arr\n max_till_now = -1000000 #minimum possible number \n current_sum = 0\n for i in range(len(arr)):\n if current_sum < 0:\n # If sum of previous elements is negative, then ignore them. Start fresh\n # with `current_sum = 0`\n current_sum = 0\n \n current_sum += arr[i]\n \n # Update max\n if max_till_now < current_sum:\n max_till_now = current_sum\n \n return max_till_now\n\n\ndef solve(A, k):\n if k == 1:\n return max_sum(A)\n # Find sum of elements of A\n sum_A = 0\n for i in range(len(A)):\n sum_A += A[i]\n \n Max_Suffix_Sum = -1000000\n current = 0\n for i in range(len(A)):\n current += A[-i-1]\n if current > Max_Suffix_Sum:\n Max_Suffix_Sum = current\n\n Max_Prefix_Sum = -1000000\n current = 0\n for i in range(len(A)):\n current += A[i]\n if current > Max_Prefix_Sum:\n Max_Prefix_Sum = current\n\n if sum_A <= 0:\n # Check two cases:\n\n # Case 1 : Check the max_sum of A\n case_1_max_sum = max_sum(A)\n \n # Case 2 : Check the max_sum of A + A\n case_2_max_sum = Max_Suffix_Sum + Max_Prefix_Sum\n\n # Return the maximum of the two cases\n return max([case_1_max_sum, case_2_max_sum])\n\n else: # if sum_A > 0\n #Check two cases:\n\n # Case 1 : Check the max_sum of A\n case_1_max_sum = max_sum(A)\n\n # Case 2\n # Max sum = Max_Suffix_Sum + (k - 2)*sum_A + Max_Prefix_Sum \n \n case_2_max_sum = Max_Suffix_Sum + (k - 2)*sum_A + Max_Prefix_Sum\n \n # Return the maximum of the two cases\n return max([case_1_max_sum, case_2_max_sum])\n\n\n# Main\nT = int(input()) # No of test cases\nfor i in range(T):\n [N, k] = list(map(int, input().split(\" \")))\n A = list(map(int, input().split(\" \")))\n \n answer = solve(A,k)\n print(answer)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n2 3\\n1 2\\n3 2\\n1 -2 1\\n\\n\\n', 'output': '9\\n2\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/KCON'}","problem_id":"vfc_1514","program":"```python\ndef max_sum(arr):\n # Finds the maximum sum of sub-arrays of arr\n max_till_now = -1000000 #minimum possible number \n current_sum = 0\n for i in range(len(arr)):\n if current_sum < 0:\n # If sum of previous elements is negative, then ignore them. Start fresh\n # with `current_sum = 0`\n current_sum = 0\n \n current_sum += arr[i]\n \n # Update max\n if max_till_now < current_sum:\n max_till_now = current_sum\n \n return max_till_now\n\n\ndef solve(A, k):\n if k == 1:\n return max_sum(A)\n # Find sum of elements of A\n sum_A = 0\n for i in range(len(A)):\n sum_A += A[i]\n \n Max_Suffix_Sum = -1000000\n current = 0\n for i in range(len(A)):\n current += A[-i-1]\n if current > Max_Suffix_Sum:\n Max_Suffix_Sum = current\n\n Max_Prefix_Sum = -1000000\n current = 0\n for i in range(len(A)):\n current += A[i]\n if current > Max_Prefix_Sum:\n Max_Prefix_Sum = current\n\n if sum_A <= 0:\n # Check two cases:\n\n # Case 1 : Check the max_sum of A\n case_1_max_sum = max_sum(A)\n \n # Case 2 : Check the max_sum of A + A\n case_2_max_sum = Max_Suffix_Sum + Max_Prefix_Sum\n\n # Return the maximum of the two cases\n return max([case_1_max_sum, case_2_max_sum])\n\n else: # if sum_A > 0\n #Check two cases:\n\n # Case 1 : Check the max_sum of A\n case_1_max_sum = max_sum(A)\n\n # Case 2\n # Max sum = Max_Suffix_Sum + (k - 2)*sum_A + Max_Prefix_Sum \n \n case_2_max_sum = Max_Suffix_Sum + (k - 2)*sum_A + Max_Prefix_Sum\n \n # Return the maximum of the two cases\n return max([case_1_max_sum, case_2_max_sum])\n\n\n# Main\nT = int(input()) # No of test cases\nfor i in range(T):\n [N, k] = list(map(int, input().split(\" \")))\n A = list(map(int, input().split(\" \")))\n \n answer = solve(A,k)\n print(answer)\n```","inputs":"2\n2 3\n1 2\n3 2\n1 -2 1\n\n\n","output":"9\n2\n","actual_output":"9\n2\n","execution_success":true,"sample_index":278},{"source":"apps","task_type":"verifiable_code","in_source_id":"669","prompt":"Solve the following coding problem using the programming language python:\n\nNadaca is a country with N$N$ cities. These cities are numbered 1$1$ through N$N$ and connected by M$M$ bidirectional roads. Each city can be reached from every other city using these roads.\nInitially, Ryan is in city 1$1$. At each of the following K$K$ seconds, he may move from his current city to an adjacent city (a city connected by a road to his current city) or stay at his current city. Ryan also has Q$Q$ conditions (a1,b1),(a2,b2),\u2026,(aQ,bQ)$(a_1, b_1), (a_2, b_2), \\ldots, (a_Q, b_Q)$ meaning that during this K$K$-second trip, for each valid i$i$, he wants to be in city ai$a_i$ after exactly bi$b_i$ seconds.\nSince you are very good with directions, Ryan asked you to tell him how many different trips he could make while satisfying all conditions. Compute this number modulo 109+7$10^9 + 7$. A trip is a sequence of Ryan's current cities after 1,2,\u2026,K$1, 2, \\ldots, K$ seconds.\n\n-----Input-----\n- 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.\n- The first line of each test case contains three space-separated integers N$N$, M$M$ and K$K$.\n- Each of the next M$M$ lines contains two space-separated integers u$u$ and v$v$ denoting a road between cities u$u$ and v$v$.\n- The next line contains a single integer Q$Q$.\n- Q$Q$ lines follow. For each i$i$ (1\u2264i\u2264Q$1 \\le i \\le Q$), the i$i$-th of these lines contains two space-separated integers ai$a_i$ and bi$b_i$.\n\n-----Output-----\nFor each test case, print a single line containing one integer \u2014 the number of trips Ryan can make, modulo 109+7$10^9+7$.\n\n-----Constraints-----\n- 1\u2264T\u226450$1 \\le T \\le 50$\n- 1\u2264N,M,K,Q\u22649,000$1 \\le N, M, K, Q \\le 9,000$\n- 1\u2264ui,vi\u2264N$1 \\le u_i, v_i \\le N$ for each valid i$i$\n- ui\u2260vi$u_i \\neq v_i$ for each valid i$i$\n- there is at most one road between each pair of cities\n- each city is reachable from every other city\n- 1\u2264ai\u2264N$1 \\le a_i \\le N$ for each valid i$i$\n- 0\u2264bi\u2264K$0 \\le b_i \\le K$ for each valid i$i$\n- the sum of N$N$ over all test cases does not exceed 9,000$9,000$\n- the sum of K$K$ over all test cases does not exceed 9,000$9,000$\n- the sum of M$M$ over all test cases does not exceed 9,000$9,000$\n- the sum of Q$Q$ over all test cases does not exceed 9,000$9,000$\n\n-----Subtasks-----\nSubtask #1 (20 points):\n- the sum of N$N$ over all test cases does not exceed 400$400$\n- the sum of K$K$ over all test cases does not exceed 400$400$\n- the sum of M$M$ over all test cases does not exceed 400$400$\n- the sum of Q$Q$ over all test cases does not exceed 400$400$\nSubtask #2 (80 points): original constraints\n\n-----Example Input-----\n3\n4 3 3\n1 2\n1 3\n1 4\n0\n4 3 3\n1 2\n1 3\n1 4\n1\n2 2\n4 3 3\n1 2\n1 3\n1 4\n1\n2 1\n\n-----Example Output-----\n28\n4\n6\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nT = int(input())\nfor _ in range(T):\n N, M, K = [int(x) for x in input().split()]\n UV = [[int(x) for x in input().split()] for _ in range(M)]\n Q = int(input())\n AB = [[int(x) for x in input().split()] for _ in range(Q)]\n \n X = [[i] for i in range(N)]\n for u, v in UV:\n X[u - 1] += [v - 1]\n X[v - 1] += [u - 1]\n \n A = [[1 if i > 0 or j == 0 else 0 for j in range(N)] for i in range(K + 1)]\n for a, b in AB:\n A[b] = [1 if i == a - 1 else 0 for i in range(N)]\n \n if A[0][0] == 1:\n for k in range(K - 1, -1, -1):\n for i in range(N):\n if A[k][i] != 0:\n A[k][i] = sum(A[k + 1][j] for j in X[i])\n \n print(A[0][0])\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\n4 3 3\\n1 2\\n1 3\\n1 4\\n0\\n4 3 3\\n1 2\\n1 3\\n1 4\\n1\\n2 2\\n4 3 3\\n1 2\\n1 3\\n1 4\\n1\\n2 1\\n', 'output': '28\\n4\\n6\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/WNDR'}","problem_id":"vfc_1518","program":"```python\nT = int(input())\nfor _ in range(T):\n N, M, K = [int(x) for x in input().split()]\n UV = [[int(x) for x in input().split()] for _ in range(M)]\n Q = int(input())\n AB = [[int(x) for x in input().split()] for _ in range(Q)]\n \n X = [[i] for i in range(N)]\n for u, v in UV:\n X[u - 1] += [v - 1]\n X[v - 1] += [u - 1]\n \n A = [[1 if i > 0 or j == 0 else 0 for j in range(N)] for i in range(K + 1)]\n for a, b in AB:\n A[b] = [1 if i == a - 1 else 0 for i in range(N)]\n \n if A[0][0] == 1:\n for k in range(K - 1, -1, -1):\n for i in range(N):\n if A[k][i] != 0:\n A[k][i] = sum(A[k + 1][j] for j in X[i])\n \n print(A[0][0])\n```","inputs":"3\n4 3 3\n1 2\n1 3\n1 4\n0\n4 3 3\n1 2\n1 3\n1 4\n1\n2 2\n4 3 3\n1 2\n1 3\n1 4\n1\n2 1\n","output":"28\n4\n6\n","actual_output":"28\n4\n6\n","execution_success":true,"sample_index":279},{"source":"apps","task_type":"verifiable_code","in_source_id":"670","prompt":"Solve the following coding problem using the programming language python:\n\nSereja has an array A of N positive integers : A[1], A[2], A[3], ... , A[N]. \n\nIn a single operation on the array, he performs the following two steps : \n\n- Pick two indices i, j s.t. A[i] > A[j]\n- A[i] -= A[j]\n\nSereja can apply these operations any number of times (possibly zero), such that the sum of resulting elements of the array is as small as possible.\n\nHelp Sereja find this minimum sum.\n\n-----Input-----\n\nFirst line of input contains an integer T - the number of test cases. T test cases follow.\n\nFirst line of each test case contains the integer N. The next line contains N integers \u2014 A[1], A[2], A[3], ... , A[N].\n\n-----Output-----\nFor each test case, output a single line with the answer.\n\n-----Constraints-----\n- 1 \u2264 T \u2264 10\n- 1 \u2264 N \u2264 105\n- 1 \u2264 A[i] \u2264 109\n\n-----Example-----\nInput:\n2\n1\n1\n3\n2 4 6\n\nOutput:\n1\n6\n\n-----Explanation-----\nExample case 2. In this case, one possible way in which Sereja can perform the operations could be as follows. \n\n- Pick i = 2, j = 1. A[2] -= A[1]. Now the resulting array would be [2, 2, 6].\n- Pick i = 3, j = 2. A[3] -= A[2]. Now the resulting array would be [2, 2, 4].\n- Pick i = 3, j = 2. A[3] -= A[2]. Now the resulting array would be [2, 2, 2]. \n\nAs the resulting array is [2 2 2], so the sum is 6.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\ndef gcd(a,b):\n if b==0:\n return a\n else:\n return gcd(b,a%b)\n \ndef main():\n t=int(input())\n while t!=0:\n t=t-1\n n=int(input())\n if n==1:\n print(input())\n else:\n a=list(map(int,input().split(\" \")))\n p=a[0]\n for i in range(1,n):\n p=gcd(p,a[i])\n if p==1:\n break\n print(n*p)\ndef __starting_point():\n main()\n \n \n\n__starting_point()\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n1\\n1\\n3\\n2 4 6\\n', 'output': '1\\n6\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/COOK64/problems/SEAARASU'}","problem_id":"vfc_1522","program":"```python\ndef gcd(a,b):\n if b==0:\n return a\n else:\n return gcd(b,a%b)\n \ndef main():\n t=int(input())\n while t!=0:\n t=t-1\n n=int(input())\n if n==1:\n print(input())\n else:\n a=list(map(int,input().split(\" \")))\n p=a[0]\n for i in range(1,n):\n p=gcd(p,a[i])\n if p==1:\n break\n print(n*p)\ndef __starting_point():\n main()\n \n \n\n__starting_point()\n```","inputs":"2\n1\n1\n3\n2 4 6\n","output":"1\n6\n","actual_output":"1\n6\n","execution_success":true,"sample_index":280},{"source":"apps","task_type":"verifiable_code","in_source_id":"671","prompt":"Solve the following coding problem using the programming language python:\n\nChef is going to start playing Fantasy Football League (FFL) this season. In FFL, each team consists of exactly $15$ players: $2$ goalkeepers, $5$ defenders, $5$ midfielders and $3$ forwards. Chef has already bought $13$ players; he is only missing one defender and one forward.\nThere are $N$ available players (numbered $1$ through $N$). For each valid $i$, the $i$-th player is either a defender or a forward and has a price $P_i$. The sum of prices of all players in a team must not exceed $100$ dollars and the players Chef bought already cost him $S$ dollars.\nCan you help Chef determine if he can complete the team by buying one defender and one forward in such a way that he does not exceed the total price limit?\n\n-----Input-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The first line of each test case contains two space-separated integers $N$ and $S$.\n- The second line contains $N$ space-separated integers $P_1, P_2, \\ldots, P_N$.\n- The last line contains $N$ space-separated integers. For each valid $i$, the $i$-th of these integers is $0$ if the $i$-th player is a defender or $1$ if the $i$-th player is a forward.\n\n-----Output-----\nFor each test case, print a single line containing the string \"yes\" if it is possible to build a complete team or \"no\" otherwise (without quotes).\n\n-----Constraints-----\n- $1 \\le T \\le 100$\n- $1 \\le N \\le 100$\n- $13 \\le S \\le 100$\n- $1 \\le P_i \\le 100$ for each valid $i$\n\n-----Subtasks-----\nSubtask #1 (100 points): original constraints\n\n-----Example Input-----\n2\n4 90\n3 8 6 5\n0 1 1 0\n4 90\n5 7 6 5\n0 1 1 0\n\n-----Example Output-----\nyes\nno\n\n-----Explanation-----\nExample case 1: If Chef buys the $1$-st and $3$-rd player, the total price of his team is $90 + 9 = 99$, which is perfectly fine. There is no other valid way to pick two players.\nExample case 2: Chef cannot buy two players in such a way that all conditions are satisfied.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfor i in range(int(input())):\n n,s =map(int,input().split())\n l1=list(map(int,input().split()))\n l2=list(map(int,input().split()))\n m=[]\n n=[]\n for i in range(len(l1)):\n if l2[i]==0:\n m.append(l1[i])\n else:\n n.append(l1[i])\n if len(m)>0 and len(n)>0:\n if 100-s>=(min(m)+min(n)):\n print(\"yes\")\n else:\n print(\"no\")\n else:\n print(\"no\")\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n4 90\\n3 8 6 5\\n0 1 1 0\\n4 90\\n5 7 6 5\\n0 1 1 0\\n', 'output': 'yes\\nno\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/FFL'}","problem_id":"vfc_1526","program":"```python\nfor i in range(int(input())):\n n,s =map(int,input().split())\n l1=list(map(int,input().split()))\n l2=list(map(int,input().split()))\n m=[]\n n=[]\n for i in range(len(l1)):\n if l2[i]==0:\n m.append(l1[i])\n else:\n n.append(l1[i])\n if len(m)>0 and len(n)>0:\n if 100-s>=(min(m)+min(n)):\n print(\"yes\")\n else:\n print(\"no\")\n else:\n print(\"no\")\n```","inputs":"2\n4 90\n3 8 6 5\n0 1 1 0\n4 90\n5 7 6 5\n0 1 1 0\n","output":"yes\nno\n","actual_output":"yes\nno\n","execution_success":true,"sample_index":281},{"source":"apps","task_type":"verifiable_code","in_source_id":"673","prompt":"Solve the following coding problem using the programming language python:\n\nIts Christmas time and Santa has started his ride to deliver gifts to children waiting for him in a 1-dimentional city. All houses in this city are on a number line numbered as 1, 2, 3\u2026 and so on. Santa wants to deliver to houses from n to m, but he found that all the kids living at positions that are divisible by a, a+d, a+2d, a+3d or a+4d are naughty and he does not want to deliver them any gifts. Santa wants to know how many gifts he has to carry before leaving to the city given that there is only one kid in a house. Help him out!\nFormally, Given $m, n, a, d \\in \\mathbb{N}$ where $n < m$, find the number of $x \\in \\{n, n+1, ..., m-1, m\\}$ such that $x$ is not divisible by $a$, $a+d$, $a+2d$, $a+3d$ or $a+4d$\n\n-----Input-----\nThe first line is the number $t$, corresponding to number of test cases\\\nThis is followed by $t$ lines of the format: $n$ $m$ $a$ $d$\n\n-----Output-----\nFor each test case, print a single number that is the number of gifts Santa should pack.\n\n-----Constraints-----\n- $1 < m, n, a \\leq 2^{32}$\n- $1 < d \\leq 2^{10}$\n\n-----Sample Input:-----\n1\n2 20 2 1\n\n-----Sample Output:-----\n5\n\n-----Explanation:-----\nIn the range {2, 3, 4, \u2026, 19, 20}, only {7, 11, 13, 17, 19} are not divisible by 2, 3, 4, 5, or 6\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfrom math import gcd\r\nfrom math import ceil\r\nfrom itertools import combinations as c\r\nt=int(input())\r\nfor _ in range(t):\r\n n,m,a,d=list(map(int,input().split()))\r\n \r\n l=[]\r\n for i in range(5):\r\n l.append(a+i*d)\r\n ans=m-n+1\r\n for i in range(1,6):\r\n x=list(c(l,i))\r\n for j in x:\r\n e=j[0]\r\n for v in j:\r\n e=(e*v)//gcd(e,v)\r\n #print(e)\r\n if i%2:\r\n ans-=m//e-(n-1)//e\r\n else:\r\n ans+=m//e-(n-1)//e\r\n print(ans)\r\n \r\n \r\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n2 20 2 1\\n', 'output': '5\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/NQST2020/problems/XMASGIFT'}","problem_id":"vfc_1534","program":"```python\nfrom math import gcd\r\nfrom math import ceil\r\nfrom itertools import combinations as c\r\nt=int(input())\r\nfor _ in range(t):\r\n n,m,a,d=list(map(int,input().split()))\r\n \r\n l=[]\r\n for i in range(5):\r\n l.append(a+i*d)\r\n ans=m-n+1\r\n for i in range(1,6):\r\n x=list(c(l,i))\r\n for j in x:\r\n e=j[0]\r\n for v in j:\r\n e=(e*v)//gcd(e,v)\r\n #print(e)\r\n if i%2:\r\n ans-=m//e-(n-1)//e\r\n else:\r\n ans+=m//e-(n-1)//e\r\n print(ans)\r\n \r\n \r\n\n```","inputs":"1\n2 20 2 1\n","output":"5\n","actual_output":"5\n","execution_success":true,"sample_index":283},{"source":"apps","task_type":"verifiable_code","in_source_id":"676","prompt":"Solve the following coding problem using the programming language python:\n\nThere is an event in DUCS where boys get a chance to show off their skills to impress girls. The boy who impresses the maximum number of girls will be honoured with the title \u201cCharming Boy of the year\u201d.\nThere are $N$ girls in the department. Each girl gives the name of a boy who impressed her the most. You need to find the name of a boy who will be honoured with the title. \nIf there are more than one possible winners, then the one with the lexicographically smallest name is given the title. \nIt is guaranteed that each boy participating in the event has a unique name.\n\n-----Input-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. \n- The first line of each test case contains an integer $N$ denoting the number of girls.\n- The second line contains $N$ space-separated strings $S_1, S_2, \\ldots, S_N$, denoting the respective names given by the girls.\n\n-----Output-----\nFor each test case, print a single line containing a string \u2014 the name of the boy who impressed the maximum number of girls. In case of a tie, print the lexicographically smallest name.\n\n-----Constraints-----\n- $1 \\leq T \\leq 100$\n- $1 \\leq N \\leq 10^5$\n- $1 \\leq |S_i| \\leq 10$, for each valid $i$\n$(|S_i|$ is the length of the string $S_i)$\n- For each valid $i$, $S_i$ contains only lowercase English alphabets\n- Sum of $N$ over all the test cases is $\\leq 10^6$\n\n-----Subtasks-----\n- 30 points: $1 \\leq N \\leq 100$\n- 70 points: original constraints\n\n-----Sample Input-----\n2\n\n10\n\njohn berry berry thomas thomas john john berry thomas john\n\n4\n\nramesh suresh suresh ramesh \n\n-----Sample Output-----\njohn\n\nramesh\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfrom collections import Counter\r\n\r\nfor _ in range(int(input())):\r\n n=int(input())\r\n l=[i for i in input().split()]\r\n ll=[]\r\n c=Counter(l)\r\n cc=[]\r\n m=0\r\n for l,count in c.most_common(len(l)-1):\r\n if m==0:\r\n ll.append(l)\r\n cc.append(count)\r\n \r\n if m==count:\r\n ll.append(l)\r\n cc.append(count)\r\n if counta[top][0] :\n \n b[top]+=1\n \n else:\n a.append((add,x[1]))\n \n b.append(0)\n top+=1\n \n \n elif (x[0]==\"-1\"):\n \n #print(\"%s %s\" %(b[top],a[top][1]))\n print((b[top]), end=' ')\n print(a[top][1])\n foo=a.pop()\n bar=b.pop()\n top-=1\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '6\\n9 english\\n6 mathematics\\n8 geography\\n-1\\n3 graphics\\n-1\\n', 'output': '1 mathematics\\n0 graphics\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/DEC12/problems/BEX'}","problem_id":"vfc_1558","program":"```python\nt=eval(input())\n \na=[]\nb=[]\n \ntop=-1\n \nfor __ in range(0,t):\n \n x=input().split()\n \n if(x[0]!=\"-1\" and x[0]!=\"0\"):\n \n add=int(x[0])\n \n if top!=-1 and add>a[top][0] :\n \n b[top]+=1\n \n else:\n a.append((add,x[1]))\n \n b.append(0)\n top+=1\n \n \n elif (x[0]==\"-1\"):\n \n #print(\"%s %s\" %(b[top],a[top][1]))\n print((b[top]), end=' ')\n print(a[top][1])\n foo=a.pop()\n bar=b.pop()\n top-=1\n```","inputs":"6\n9 english\n6 mathematics\n8 geography\n-1\n3 graphics\n-1\n","output":"1 mathematics\n0 graphics\n","actual_output":"1 mathematics\n0 graphics\n","execution_success":true,"sample_index":288},{"source":"apps","task_type":"verifiable_code","in_source_id":"680","prompt":"Solve the following coding problem using the programming language python:\n\nYou are given two integer sequences $A_1, A_2, \\ldots, A_N$ and $B_1, B_2, \\ldots, B_M$. For any two sequences $U_1, U_2, \\ldots, U_p$ and $V_1, V_2, \\ldots, V_q$, we define\nScore(U,V)=\u2211i=1p\u2211j=1qUi\u22c5Vj.Score(U,V)=\u2211i=1p\u2211j=1qUi\u22c5Vj.Score(U, V) = \\sum_{i=1}^p \\sum_{j=1}^q U_i \\cdot V_j \\,.\nYou should process $Q$ queries of three types:\n- $1$ $L$ $R$ $X$: Add $X$ to each of the elements $A_L, A_{L+1}, \\ldots, A_R$.\n- $2$ $L$ $R$ $X$: Add $X$ to each of the elements $B_L, B_{L+1}, \\ldots, B_R$.\n- $3$: Print $Score(A, B)$ modulo $998,244,353$.\n\n-----Input-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The first line of each test case contains two integers, $N$ and $M$, denoting the length of $A$ and $B$ respectively.\n- The second line contains $N$ integers, elements of $A$.\n- The third line contains $M$ integers, elements of $B$.\n- The next line will contain an integer, $Q$, number of queries.\n- Each of the next $Q$ lines will contain one of $3$ kinds of updates as mentioned in the statement\nIt\u2019s guaranteed that each update is a valid update operation.\n\n-----Output-----\nFor each query of the third type, print a single line containing one integer - the answer to that query.\n\n-----Constraints-----\n- $1 \\le T \\le 10$\n- $2 \\le N, M, Q \\le 10^5$\n- $0 \\le |A_i|, |B_i|, |X| \\le 10^5$\n\n-----Example Input-----\n1\n3 4\n2 -1 5\n3 3 2 4\n6\n3\n1 2 3 -2\n3\n1 1 3 1\n2 2 4 2\n3\n\n-----Example Output-----\n72\n24\n90\n\n-----Explanation-----\nBefore the first operation, $A = [2, -1, 5],\\ B = [3, 3, 2, 4]$\nSo, for the first operation,\n$Score(A,\\ B) = 2*3 + 2*3 + 2*2 + 2*4$ $+ (-1)*3$ $+ (-1)*3$ $+ (-1)*2$ $+$ $(-1)*4$ $+ 5*3$ $+ 5*3$ $+ 5*2$ $+ 5*4$ $= 72.$\nAfter the second query $A = [2, -3, 3]$, $B = [3, 3, 2, 4]$\nSo, for the third query, $Score(A, B) = 2*3 + 2*3 + 2*2$ $+ 2*4$ $+ (-3)*3$ $+ (-3)*3$ $+ (-3)*2$ $+ (-3)*4$ $+ 3*3$ $+ 3*3$ $+ 3*2$ $+ 3*4$ $= 24$.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nt = int(input())\nl,r,x = 0,0,0\nans = []\nfor i in range(t):\n (n,m) = tuple(map(int,input().split()))\n a = list(map(int,input().split()))\n b = list(map(int,input().split()))\n suma = sum(a)\n sumb = sum(b)\n q = int(input())\n for j in range(q):\n l1 = list(map(int,input().split()))\n if l1[0] == 1:\n l = l1[1]\n r = l1[2]\n x = l1[3]\n suma = suma + (r-l+1)*x\n elif l1[0] == 2:\n l = l1[1]\n r = l1[2]\n x = l1[3]\n sumb = sumb + (r-l+1)*x\n else:\n ans.append((suma*sumb)%998244353)\nfor i in range(len(ans)):\n print(ans[i])\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n3 4\\n2 -1 5\\n3 3 2 4\\n6\\n3\\n1 2 3 -2\\n3\\n1 1 3 1\\n2 2 4 2\\n3\\n', 'output': '72\\n24\\n90\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/ARRQRY'}","problem_id":"vfc_1562","program":"```python\nt = int(input())\nl,r,x = 0,0,0\nans = []\nfor i in range(t):\n (n,m) = tuple(map(int,input().split()))\n a = list(map(int,input().split()))\n b = list(map(int,input().split()))\n suma = sum(a)\n sumb = sum(b)\n q = int(input())\n for j in range(q):\n l1 = list(map(int,input().split()))\n if l1[0] == 1:\n l = l1[1]\n r = l1[2]\n x = l1[3]\n suma = suma + (r-l+1)*x\n elif l1[0] == 2:\n l = l1[1]\n r = l1[2]\n x = l1[3]\n sumb = sumb + (r-l+1)*x\n else:\n ans.append((suma*sumb)%998244353)\nfor i in range(len(ans)):\n print(ans[i])\n```","inputs":"1\n3 4\n2 -1 5\n3 3 2 4\n6\n3\n1 2 3 -2\n3\n1 1 3 1\n2 2 4 2\n3\n","output":"72\n24\n90\n","actual_output":"72\n24\n90\n","execution_success":true,"sample_index":289},{"source":"apps","task_type":"verifiable_code","in_source_id":"681","prompt":"Solve the following coding problem using the programming language python:\n\nYou are playing following game: given an array A of N natural numbers. All numbers in the array A are at most M. On every turn you may pick any two different elements Ai and Aj (i\u2260j), such that Ai, Aj \u2264 M, and add K to both. The game ends when you are not able to continue. That is, when there is no pair (i,j) left such that both of them are less than equal to M.\n\nLet's call two arrays different if the sum of all their elements is different. When the game ends, you note down the final array A. How many different final arrays can you have.\n\n-----Input-----\n\nThe first line contains three integers N, M and K. N elements of the array follow in the next line.\n\n-----Output-----\n\nOutput single integer - answer for the given problem modulo 109+7.\n\n\n-----Constraints-----\n- 1 \u2264 N \u2264 105\n- 1 \u2264 M,K \u2264 1012\n- 1 \u2264 Ai \u2264 M\n\n-----Example-----\nInput:\n3 3 2\n1 2 3\nOutput:\n2\n\n-----Explanation-----\n\nAll possible sums are 14 and 10. You can get them by, for example, these arrays:\nA=(5, 4, 5),\nA=(1, 4, 5)\n\nThe above arrays are different because their sums are different.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n\nfrom math import ceil\nfrom bisect import bisect_right as b_r\nfrom bisect import bisect_left as b_l\nar = list(map(int , input().split()))\na = [int(ceil((ar[1]-int(x)+1)/ar[2])) for x in input().split()]\ns = sum(a)\nar[1] = max(a)\nm = ar[1] - (s-ar[1])%2\nmi = s%2 \nprint(int( (m-mi)//2 +1)%(10**9+7))\n\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3 3 2\\n1 2 3\\n', 'output': '2\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/RRGAME'}","problem_id":"vfc_1566","program":"```python\n\nfrom math import ceil\nfrom bisect import bisect_right as b_r\nfrom bisect import bisect_left as b_l\nar = list(map(int , input().split()))\na = [int(ceil((ar[1]-int(x)+1)/ar[2])) for x in input().split()]\ns = sum(a)\nar[1] = max(a)\nm = ar[1] - (s-ar[1])%2\nmi = s%2 \nprint(int( (m-mi)//2 +1)%(10**9+7))\n\n\n```","inputs":"3 3 2\n1 2 3\n","output":"2\n","actual_output":"2\n","execution_success":true,"sample_index":290},{"source":"apps","task_type":"verifiable_code","in_source_id":"683","prompt":"Solve the following coding problem using the programming language python:\n\n-----Problem Statement-----\nWrite a program that accepts a number, n, and outputs the same.\n\n-----Input-----\nThe only line contains a single integer. \n\n-----Output-----\nOutput the answer in a single line.\n\n-----Constraints-----\n- 0 \u2264 n \u2264 105\n\n-----Sample Input-----\n123\n\n-----Sample Output-----\n123\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\na = int(input())\nprint(a)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '123\\n', 'output': '123\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/START01'}","problem_id":"vfc_1574","program":"```python\n# cook your dish here\na = int(input())\nprint(a)\n```","inputs":"123\n","output":"123\n","actual_output":"123\n","execution_success":true,"sample_index":291},{"source":"apps","task_type":"verifiable_code","in_source_id":"684","prompt":"Solve the following coding problem using the programming language python:\n\nCongratulations !!! You have successfully completed the heist by looting all the gifts in Santa's locker. Now it's time to decide who gets to take all the gifts, you or the Grinch, there will be no splitting. So you and Grinch decide to play a game.\nTo start the game, an Integer N will be given. The game is played in turns and for each turn, the player can make any one of the following moves:\n- Divide N by any of it's odd divisors greater than 1.\n- Subtract 1 from N if N is greater than 1.\nDivisor of a number includes the number itself.\nThe player who is unable to make a move loses the game.\nSince you are the mastermind of the heist, you get to play the first move.\n\n-----Input-----\nThe first line contains a single integer T (1 \u2264 T \u2264 100) \u2014 the number of test cases. The description of the test cases follows.\nThe only line of each test case contains a single integer \u2014 N (1 \u2264 N \u2264 109).\n\n-----Output-----\nFor each test case, print \" Me\" if you win, and \" Grinch\" if otherwise (without quotes).\n\n-----Sample Input-----\n7\n1\n2\n3\n4\n5\n6\n12\n\n-----Sample Output-----\nGrinch\nMe\nMe\nGrinch\nMe\nGrinch\nMe\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\nimport math \n \n# Function to find the Largest \n# Odd Divisor Game to check \n# which player wins \ndef findWinner(n, k): \n \n cnt = 0; \n \n # Check if n == 1 then \n # player 2 will win \n if (n == 1): \n print(\"Grinch\"); \n \n # Check if n == 2 or n is odd \n elif ((n & 1) or n == 2): \n print(\"Me\"); \n \n else: \n tmp = n; \n val = 1; \n \n # While n is greater than k and \n # divisible by 2 keep \n # incrementing tha val \n while (tmp > k and tmp % 2 == 0): \n tmp //= 2; \n val *= 2; \n \n # Loop to find greatest \n # odd divisor \n for i in range(3, int(math.sqrt(tmp)) + 1): \n while (tmp % i == 0): \n cnt += 1; \n tmp //= i; \n \n if (tmp > 1): \n cnt += 1; \n \n # Check if n is a power of 2 \n if (val == n): \n print(\"Grinch\"); \n \n elif (n / tmp == 2 and cnt == 1): \n print(\"Grinch\"); \n \n # Check if cnt is not one \n # then player 1 wins \n else: \n print(\"Me\"); \n \n# Driver code \ndef __starting_point(): \n for i in range(int(input())):\n n=int(input()) \n findWinner(n, 1); \n__starting_point()\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '7\\n1\\n2\\n3\\n4\\n5\\n6\\n12\\n', 'output': 'Grinch\\nMe\\nMe\\nGrinch\\nMe\\nGrinch\\nMe\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/NQST2020/problems/WINALL'}","problem_id":"vfc_1578","program":"```python\n# cook your dish here\nimport math \n \n# Function to find the Largest \n# Odd Divisor Game to check \n# which player wins \ndef findWinner(n, k): \n \n cnt = 0; \n \n # Check if n == 1 then \n # player 2 will win \n if (n == 1): \n print(\"Grinch\"); \n \n # Check if n == 2 or n is odd \n elif ((n & 1) or n == 2): \n print(\"Me\"); \n \n else: \n tmp = n; \n val = 1; \n \n # While n is greater than k and \n # divisible by 2 keep \n # incrementing tha val \n while (tmp > k and tmp % 2 == 0): \n tmp //= 2; \n val *= 2; \n \n # Loop to find greatest \n # odd divisor \n for i in range(3, int(math.sqrt(tmp)) + 1): \n while (tmp % i == 0): \n cnt += 1; \n tmp //= i; \n \n if (tmp > 1): \n cnt += 1; \n \n # Check if n is a power of 2 \n if (val == n): \n print(\"Grinch\"); \n \n elif (n / tmp == 2 and cnt == 1): \n print(\"Grinch\"); \n \n # Check if cnt is not one \n # then player 1 wins \n else: \n print(\"Me\"); \n \n# Driver code \ndef __starting_point(): \n for i in range(int(input())):\n n=int(input()) \n findWinner(n, 1); \n__starting_point()\n```","inputs":"7\n1\n2\n3\n4\n5\n6\n12\n","output":"Grinch\nMe\nMe\nGrinch\nMe\nGrinch\nMe\n","actual_output":"Grinch\nMe\nMe\nGrinch\nMe\nGrinch\nMe\n","execution_success":true,"sample_index":292},{"source":"apps","task_type":"verifiable_code","in_source_id":"685","prompt":"Solve the following coding problem using the programming language python:\n\nYou are given an axis-aligned rectangle in a 2D Cartesian plane. The bottom left corner of this rectangle has coordinates (0,0)$(0, 0)$ and the top right corner has coordinates (N\u22121,N\u22121)$(N-1, N-1)$. You are also given K$K$ light sources; each light source is a point inside or on the perimeter of the rectangle.\nFor each light source, let's divide the plane into four quadrants by a horizontal and a vertical line passing through this light source. The light source can only illuminate one of these quadrants (including its border, i.e. the point containing the light source and two half-lines), but the quadrants illuminated by different light sources may be different.\nYou want to assign a quadrant to each light source in such a way that when they illuminate their respective quadrants, the entire rectangle (including its perimeter) is illuminated. Find out whether it is possible to assign quadrants to light sources in such a way.\n\n-----Input-----\n- The first line of the input contains an integer T$T$ denoting the number of test cases. The description of the test cases follows.\n- The first line of each test case contains two space-separated integers K$K$ and N$N$.\n- Each of the next K$K$ lines contains two space-separated integers x$x$ and y$y$ denoting a light source with coordinates (x,y)$(x, y)$.\n\n-----Output-----\nFor each test case, print a single line containing the string \"yes\" if it is possible to illuminate the whole rectangle or \"no\" if it is impossible.\n\n-----Constraints-----\n- 1\u2264T\u22645,000$1 \\le T \\le 5,000$\n- 1\u2264K\u2264100$1 \\le K \\le 100$\n- 1\u2264N\u2264109$1 \\le N \\le 10^9$\n- 0\u2264x,y\u2264N\u22121$0 \\le x, y \\le N-1$\n- no two light sources coincide\n\n-----Example Input-----\n2\n2 10\n0 0\n1 0\n2 10\n1 2\n1 1\n\n-----Example Output-----\nyes\nno\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# https://www.codechef.com/problems/RECTLIT\r\n\r\ndef assess(sq,points):\r\n EWct = 0\r\n NSct = 0\r\n for a,b in points:\r\n EW = (a == 0 or a == sq)\r\n NS = (b == 0 or b == sq)\r\n if EW and NS:\r\n return 'yes'\r\n EWct += EW\r\n NSct += NS\r\n if NSct + EWct == 0 or len(points) == 1:\r\n return 'no'\r\n if EWct >= 2 or NSct >= 2:\r\n return 'yes'\r\n if len(points) == 2:\r\n return 'no'\r\n # now 3 points\r\n if NSct == 1 and EWct == 1:\r\n return 'yes'\r\n # 3 points, one on edge\r\n x = -1\r\n for a,b in points:\r\n if EWct > 0:\r\n if a == 0 or a == sq:\r\n e = b\r\n elif x == -1:\r\n x = b\r\n else:\r\n y = b\r\n else:\r\n if b == 0 or b == sq:\r\n e = a\r\n elif x == -1:\r\n x = a\r\n else:\r\n y = a\r\n if (e-x)*(e-y) < 0: # edge splits mids\r\n return 'no'\r\n else:\r\n return 'yes'\r\n\r\n\r\nfor ti in range(int(input())):\r\n k,n = map(int, input().split())\r\n if k > 3:\r\n for ki in range(k):\r\n input()\r\n print('yes')\r\n else:\r\n pos = [tuple(map(int, input().split())) for ki in range(k)]\r\n print(assess(n-1,pos))\r\n\r\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n2 10\\n0 0\\n1 0\\n2 10\\n1 2\\n1 1\\n', 'output': 'yes\\nno\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/RECTLIT'}","problem_id":"vfc_1582","program":"```python\n# https://www.codechef.com/problems/RECTLIT\r\n\r\ndef assess(sq,points):\r\n EWct = 0\r\n NSct = 0\r\n for a,b in points:\r\n EW = (a == 0 or a == sq)\r\n NS = (b == 0 or b == sq)\r\n if EW and NS:\r\n return 'yes'\r\n EWct += EW\r\n NSct += NS\r\n if NSct + EWct == 0 or len(points) == 1:\r\n return 'no'\r\n if EWct >= 2 or NSct >= 2:\r\n return 'yes'\r\n if len(points) == 2:\r\n return 'no'\r\n # now 3 points\r\n if NSct == 1 and EWct == 1:\r\n return 'yes'\r\n # 3 points, one on edge\r\n x = -1\r\n for a,b in points:\r\n if EWct > 0:\r\n if a == 0 or a == sq:\r\n e = b\r\n elif x == -1:\r\n x = b\r\n else:\r\n y = b\r\n else:\r\n if b == 0 or b == sq:\r\n e = a\r\n elif x == -1:\r\n x = a\r\n else:\r\n y = a\r\n if (e-x)*(e-y) < 0: # edge splits mids\r\n return 'no'\r\n else:\r\n return 'yes'\r\n\r\n\r\nfor ti in range(int(input())):\r\n k,n = map(int, input().split())\r\n if k > 3:\r\n for ki in range(k):\r\n input()\r\n print('yes')\r\n else:\r\n pos = [tuple(map(int, input().split())) for ki in range(k)]\r\n print(assess(n-1,pos))\r\n\r\n\n```","inputs":"2\n2 10\n0 0\n1 0\n2 10\n1 2\n1 1\n","output":"yes\nno\n","actual_output":"yes\nno\n","execution_success":true,"sample_index":293},{"source":"apps","task_type":"verifiable_code","in_source_id":"686","prompt":"Solve the following coding problem using the programming language python:\n\nChef has been working in a restaurant which has N floors. He wants to minimize the time it takes him to go from the N-th floor to ground floor. He can either take the elevator or the stairs. \nThe stairs are at an angle of 45 degrees and Chef's velocity is V1 m/s when taking the stairs down. The elevator on the other hand moves with a velocity V2 m/s. Whenever an elevator is called, it always starts from ground floor and goes to N-th floor where it collects Chef (collecting takes no time), it then makes its way down to the ground floor with Chef in it. \n\nThe elevator cross a total distance equal to N meters when going from N-th floor to ground floor or vice versa, while the length of the stairs is sqrt(2) * N because the stairs is at angle 45 degrees.\n\nChef has enlisted your help to decide whether he should use stairs or the elevator to minimize his travel time. Can you help him out?\n\n-----Input-----\nThe first line contains a single integer T, the number of test cases. Each test case is described by a single line containing three space-separated integers N, V1, V2. \n\n-----Output-----\nFor each test case, output a single line with string Elevator or Stairs, denoting the answer to the problem.\n\n-----Constraints-----\n- 1 \u2264 T \u2264 1000 \n- 1 \u2264 N, V1, V2 \u2264 100 \n\n-----Example-----\nInput:\n3\n5 10 15\n2 10 14\n7 14 10\n\nOutput:\nElevator\nStairs\nStairs\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nn=int(input())\nl=[]\nfor i in range(0,n):\n a,b,c=map(int,input().split())\n n1=(2**0.5)*(a/b)\n n2=2*(a/c)\n if n1>n2:\n l.append(\"Elevator\")\n else:\n l.append(\"Stairs\")\nfor i in l:\n print(i)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\n5 10 15\\n2 10 14\\n7 14 10\\n', 'output': 'Elevator\\nStairs\\nStairs\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/ELEVSTRS'}","problem_id":"vfc_1586","program":"```python\nn=int(input())\nl=[]\nfor i in range(0,n):\n a,b,c=map(int,input().split())\n n1=(2**0.5)*(a/b)\n n2=2*(a/c)\n if n1>n2:\n l.append(\"Elevator\")\n else:\n l.append(\"Stairs\")\nfor i in l:\n print(i)\n```","inputs":"3\n5 10 15\n2 10 14\n7 14 10\n","output":"Elevator\nStairs\nStairs\n","actual_output":"Elevator\nStairs\nStairs\n","execution_success":true,"sample_index":294},{"source":"apps","task_type":"verifiable_code","in_source_id":"687","prompt":"Solve the following coding problem using the programming language python:\n\nThe Little Elephant likes permutations. This time he has a permutation A[1], A[2], ..., A[N] of numbers 1, 2, ..., N.\n\nHe calls a permutation A good, if the number of its inversions is equal to the number of its local inversions. The number of inversions is equal to the number of pairs of integers (i; j) such that 1 \u2264 i < j \u2264 N and A[i] > A[j], and the number of local inversions is the number of integers i such that 1 \u2264 i < N and A[i] > A[i+1].\n\nThe Little Elephant has several such permutations. Help him to find for each permutation whether it is good or not. Print YES for a corresponding test case if it is good and NO otherwise.\n\n-----Input-----\n\nThe first line of the input contains a single integer T, the number of test cases. T test cases follow. The first line of each test case contains a single integer N, the size of a permutation. The next line contains N space separated integers A[1], A[2], ..., A[N].\n\n-----Output-----\n\nFor each test case output a single line containing the answer for the corresponding test case. It should be YES if the corresponding permutation is good and NO otherwise.\n\n-----Constraints-----\n1 \u2264 T \u2264 474 \n\n1 \u2264 N \u2264 100 \n\nIt is guaranteed that the sequence A[1], A[2], ..., A[N] is a permutation of numbers 1, 2, ..., N.\n\n-----Example-----\nInput:\n4\n1\n1\n2\n2 1\n3\n3 2 1\n4\n1 3 2 4\n\nOutput:\nYES\nYES\nNO\nYES\n\n-----Explanation-----\nCase 1. Here N = 1, so we have no pairs (i; j) with 1 \u2264 i < j \u2264 N. So the number of inversions is equal to zero. The number of local inversion is also equal to zero. Hence this permutation is good.\n\nCase 2. Here N = 2, and we have one pair (i; j) with 1 \u2264 i < j \u2264 N, the pair (1; 2). Since A[1] = 2 and A[2] = 1 then A[1] > A[2] and the number of inversions is equal to 1. The number of local inversion is also equal to 1 since we have one value of i for which 1 \u2264 i < N (the value i = 1) and A[i] > A[i+1] for this value of i since A[1] > A[2]. Hence this permutation is also good.\n\nCase 3. Here N = 3, and we have three pairs (i; j) with 1 \u2264 i < j \u2264 N. We have A[1] = 3, A[2] = 2, A[3] = 1. Hence A[1] > A[2], A[1] > A[3] and A[2] > A[3]. So the number of inversions is equal to 3. To count the number of local inversion we should examine inequalities A[1] > A[2] and A[2] > A[3]. They both are satisfied in our case, so we have 2 local inversions. Since 2 \u2260 3 this permutations is not good.\n\nCase 4. Here we have only one inversion and it comes from the pair (2; 3) since A[2] = 3 > 2 = A[3]. This pair gives also the only local inversion in this permutation. Hence the number of inversions equals to the number of local inversions and equals to one. So this permutation is good.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfrom sys import stdin\nt = int(stdin.readline())\n\ndef count(n, arr):\n loc = 0\n glob = 0\n for i in range(n-1):\n if arr[i] > arr[i+1]:\n loc += 1\n for i in range(n-1):\n for j in range(i+1, n):\n if glob > loc:\n return 0\n if arr[i] > arr[j]:\n glob += 1;\n if glob == loc:\n return 1\n return 0\n\nfor _ in range(t):\n n = int(stdin.readline())\n arr = list(map(int, stdin.readline().split()))\n result = count(n, arr)\n if result:\n print(\"YES\")\n else:\n print(\"NO\")\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '4\\n1\\n1\\n2\\n2 1\\n3\\n3 2 1\\n4\\n1 3 2 4\\n', 'output': 'YES\\nYES\\nNO\\nYES\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/COOK28/problems/LEPERMUT'}","problem_id":"vfc_1590","program":"```python\nfrom sys import stdin\nt = int(stdin.readline())\n\ndef count(n, arr):\n loc = 0\n glob = 0\n for i in range(n-1):\n if arr[i] > arr[i+1]:\n loc += 1\n for i in range(n-1):\n for j in range(i+1, n):\n if glob > loc:\n return 0\n if arr[i] > arr[j]:\n glob += 1;\n if glob == loc:\n return 1\n return 0\n\nfor _ in range(t):\n n = int(stdin.readline())\n arr = list(map(int, stdin.readline().split()))\n result = count(n, arr)\n if result:\n print(\"YES\")\n else:\n print(\"NO\")\n```","inputs":"4\n1\n1\n2\n2 1\n3\n3 2 1\n4\n1 3 2 4\n","output":"YES\nYES\nNO\nYES\n","actual_output":"YES\nYES\nNO\nYES\n","execution_success":true,"sample_index":295},{"source":"apps","task_type":"verifiable_code","in_source_id":"688","prompt":"Solve the following coding problem using the programming language python:\n\nYou are given a string s of length 8 consisting solely of '0's and '1's. Assume that the characters of the string are written in a circular fashion. You need to find the number of 0-1 or 1-0 transitions that one has to make while making a single traversal over the string. ie. start from any character and go circularly until you get back to the same character, and find the number of transitions that you made. The string is said to be said to be uniform if there are at most two such transitions. Otherwise, it is called non-uniform.\nGiven the string s, tell whether the string is uniform or not.\n\n-----Input-----\nThe first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.\nThe only line of input contains the string s.\n\n-----Output-----\nFor each test case, output \"uniform\" if the given string is uniform and \"non-uniform\" otherwise.\n\n-----Constraints-----\n- 1 \u2264 T \u2264 256\n- Length of s is 8\n\n-----Example-----\nInput\n4\n00000000\n10101010\n10000001\n10010011\n\nOutput\nuniform\nnon-uniform\nuniform\nnon-uniform\n\n-----Explanation-----\nThe number of transitions are 0, 8, 2 and 4 for the respective cases. So, the first and third one are uniform while the second and fourth one are non-uniform.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nn = int(input())\n# this code only for 8 bits string and it isn't possible to more than 8 bits of \u00a0\u00a0\u00a0\u00a0string \n\n# for i in range(n):\n# s = input()\n# subString1, subString2 = s[:4], s[4:]\n# rev = subString2[::-1]\n# print( 'uniform' if(subString1 == rev) else 'non-uniform')\n \nfor i in range(n):\n count = 0\n s = input()\n for i in range(1, len(s)):\n if(s[i-1] != s[i]):\n count += 1 \n \n if(s[0] != s[-1]): \n count += 1 \n print(\"uniform\" if(count <=2 ) else \"non-uniform\")\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '4\\n00000000\\n10101010\\n10000001\\n10010011\\n', 'output': 'uniform\\nnon-uniform\\nuniform\\nnon-uniform\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/STRLBP'}","problem_id":"vfc_1594","program":"```python\nn = int(input())\n# this code only for 8 bits string and it isn't possible to more than 8 bits of \u00a0\u00a0\u00a0\u00a0string \n\n# for i in range(n):\n# s = input()\n# subString1, subString2 = s[:4], s[4:]\n# rev = subString2[::-1]\n# print( 'uniform' if(subString1 == rev) else 'non-uniform')\n \nfor i in range(n):\n count = 0\n s = input()\n for i in range(1, len(s)):\n if(s[i-1] != s[i]):\n count += 1 \n \n if(s[0] != s[-1]): \n count += 1 \n print(\"uniform\" if(count <=2 ) else \"non-uniform\")\n\n```","inputs":"4\n00000000\n10101010\n10000001\n10010011\n","output":"uniform\nnon-uniform\nuniform\nnon-uniform\n","actual_output":"uniform\nnon-uniform\nuniform\nnon-uniform\n","execution_success":true,"sample_index":296},{"source":"apps","task_type":"verifiable_code","in_source_id":"689","prompt":"Solve the following coding problem using the programming language python:\n\nIn africa jungle , there were zebra's who liked to spit.\nThere owner watched them for whole day and noted in his sheet where each zebra spitted.\nNow he's in a confusion and wants to know if in the jungle there are two zebra's which spitted at each other.\nHelp him solve this task.\nIf the zebra is present in position a spits b metres right , he can hit only zebra in position a+b , if such a zebra exists.\n\n-----Input:-----\n- The first line contains integer t(1<=t<100)- amount of zebras in jungle.\n- Each of following t lines contains two integers a(i) and b(i)(-10^4<=x(i)<=10^4,1<|d(i)|<=2.10^4) - records in owner sheet.\n- a(i) is the position of i-th zebra and b(i) is distance at which the i-th camel spitted.\nPositive values of d(i) correspond to spits right, negative values correspond to spit left.No two zebras may stand in the same position.\n\n-----Output:-----\nIf there are two zebras , which spitted at each other , output YES, otherwise , output NO.\n\n-----Sample Input:-----\n2\n0 1\n1 -1\n\n-----Sample Output:-----\nYES\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\nt=int(input())\ni=0\na=0\nd=dict()\nwhile i0:\n j += k-1\n i = j\n break\n if i0:\n j += k-1\n i = j\n break\n i += 1\ni = k\nwhile i <= n:\n if i==k:\n s = fsum[i-1]\n else:\n s = fsum[i-1] - fsum[i-k-1]\n if s == 0 :\n c = -1\n break\n i += 1\nprint(c)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '6 2 5\\n1 1 1 1 1 1\\n', 'output': '2\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/INTW2020/problems/MORALE99'}","problem_id":"vfc_1602","program":"```python\nn,k,m = map(int,input().split())\nar = list(map(int,input().split()))\nfsum = [ar[0]]\nfor i in range(1,n):\n fsum.append(fsum[i-1]+ar[i])\ni = k\n#print(fsum)\nc = 0\nwhile i <= n:\n if i == k:\n s = fsum[i-1]\n else:\n s = fsum[i-1]-fsum[i-k-1]\n if s == 0:\n c = -1\n break\n if s < m:\n c += 1\n if i0:\n j += k-1\n i = j\n break\n if i0:\n j += k-1\n i = j\n break\n i += 1\ni = k\nwhile i <= n:\n if i==k:\n s = fsum[i-1]\n else:\n s = fsum[i-1] - fsum[i-k-1]\n if s == 0 :\n c = -1\n break\n i += 1\nprint(c)\n```","inputs":"6 2 5\n1 1 1 1 1 1\n","output":"2\n","actual_output":"2\n","execution_success":true,"sample_index":298},{"source":"apps","task_type":"verifiable_code","in_source_id":"691","prompt":"Solve the following coding problem using the programming language python:\n\nYou are given a sequence $A_1, A_2, \\ldots, A_N$. For each valid $i$, the star value of the element $A_i$ is the number of valid indices $j < i$ such that $A_j$ is divisible by $A_i$.\nChef is a curious person, so he wants to know the maximum star value in the given sequence. Help him find it.\n\n-----Input-----\n- The first line of the input contains a single integer $T$ which denotes the number of test cases.\n- The first line of each test case contains a single integer $N$ .\n- The second line of each test case contains $N$ space-separated integers $A_1, A_2, \\ldots, A_N$.\n\n-----Output-----\nFor each test case, print a single line containing one integer \u2015 the maximum star value.\n\n-----Constraints-----\n- $1 \\le T \\le 10$\n- $1 \\le N \\le 10^5$\n- $1 \\le A_i \\le 10^6$ for each valid $i$ \n- Sum of $N$ over all test cases does not exceed $100,000$.\n\n-----Subtasks-----\nSubtask #1 (20 points): sum of $N$ over all test cases does not exceed $5,000$\nSubtask #2 (80 points): original constraints\n\n-----Example Input-----\n1\n7\n8 1 28 4 2 6 7\n\n-----Example Output-----\n3\n\n-----Explanation-----\n$A_5 = 2$ divides $4$, $28$ and $8$, so its star value is $3$. There is no element with a higher star value.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nT = int(input())\nfor _ in range(T):\n n = int(input())\n arr = list(map(int, input().split()))\n a = [0 for _ in range(max(arr)+1)]\n star_val = []\n for i in range(len(arr)):\n j = 1\n val = 0\n while j*arr[i] <= len(a):\n val += a[j*arr[i]-1]\n j += 1\n star_val.append(val)\n a[arr[i]-1] += 1\n print(max(star_val))\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n7\\n8 1 28 4 2 6 7\\n', 'output': '3\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/MSV'}","problem_id":"vfc_1606","program":"```python\nT = int(input())\nfor _ in range(T):\n n = int(input())\n arr = list(map(int, input().split()))\n a = [0 for _ in range(max(arr)+1)]\n star_val = []\n for i in range(len(arr)):\n j = 1\n val = 0\n while j*arr[i] <= len(a):\n val += a[j*arr[i]-1]\n j += 1\n star_val.append(val)\n a[arr[i]-1] += 1\n print(max(star_val))\n```","inputs":"1\n7\n8 1 28 4 2 6 7\n","output":"3\n","actual_output":"3\n","execution_success":true,"sample_index":299},{"source":"apps","task_type":"verifiable_code","in_source_id":"692","prompt":"Solve the following coding problem using the programming language python:\n\nThere is crazy man named P29892P. He always tries to do crazy things as he thinks. One day he invented a machine and named it as ANGEN. The ANGEN is used to perform range operations. The range operation means performing operations on range values from {L..R}. At any time it performs operations on values in between L to R.\nANGEN can perform following operations\nU I V - Update the value present at I with value V\nA L R - Find the sum between range L and R\nM L R - Find the maximum number between L and R\nm L R - Find the minimum number between L and R\nS L R - Find second maximum value in between L and R\ns L R - Find second mimimum value in between L and R\nIf it is not possible perform operation ANGEN returns \u201cNA\u201d with out quotes.\nFor Invalid operations ANGEN returns \u201c!!!\u201d with out quotes.\nNow P29892P challenging his friends and you too, to build his invention with yourown code. So it's your time to defeat P29892P by implementing his invention with your own ability. Let's go and solve the problem.\n\n-----Input-----\nInput description.\n- The first line of the input contains an integer N denoting the number of integers. \n- The next line contains N space separated integers.\"\n- The next line contains a single integer Q denoting the number of Questions.\n- The next Q lines contains T Question type , L and R.\n\n-----Output-----\nPrint output for each question in separate line.\n\n-----Constraints-----\nShould contain all the constraints on the input data that you may have. Format it like:\n- 1 \u2264 N \u2264 100000\n- 1 \u2264 values[i] \u2264 1000000000\n- 1 \u2264 Q \u2264 10000\n- T in { A..Z, a..z }\n- 1 \u2264 L \u2264 R \u2264 N\n\n-----Example-----\nInput:\n6\n1 2 5 3 10 6\n6\nA 1 5\nM 1 3\nm 5 6\ns 3 6\nU 1 7\nS 1 2\n\nOutput:\n21\n5\n6\n5\n2\n\n-----Explanation-----\n...\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nVQ = \"UAMmSs\"\nn = int(input())\na = list(map(int, input().split()))\nfor _ in range(int(input())):\n q, x, y = input().split()\n if q not in VQ:\n print(\"!!!\")\n continue\n if q == \"U\":\n a[int(x) - 1] = int(y)\n continue\n l = int(x) - 1\n r = int(y)\n if q == \"A\":\n print(sum(a[l:r]))\n continue\n if q == \"M\":\n print(max(a[l:r]))\n continue\n if q == \"m\":\n print(min(a[l:r]))\n continue\n s = sorted(set(a[l:r]))\n if len(s) < 2:\n print(\"NA\")\n else:\n print(s[1] if q == \"s\" else s[-2])\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '6\\n1 2 5 3 10 6\\n6\\nA 1 5\\nM 1 3\\nm 5 6\\ns 3 6\\nU 1 7\\nS 1 2\\n', 'output': '21\\n5\\n6\\n5\\n2\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/CRES2016/problems/CRES104'}","problem_id":"vfc_1610","program":"```python\nVQ = \"UAMmSs\"\nn = int(input())\na = list(map(int, input().split()))\nfor _ in range(int(input())):\n q, x, y = input().split()\n if q not in VQ:\n print(\"!!!\")\n continue\n if q == \"U\":\n a[int(x) - 1] = int(y)\n continue\n l = int(x) - 1\n r = int(y)\n if q == \"A\":\n print(sum(a[l:r]))\n continue\n if q == \"M\":\n print(max(a[l:r]))\n continue\n if q == \"m\":\n print(min(a[l:r]))\n continue\n s = sorted(set(a[l:r]))\n if len(s) < 2:\n print(\"NA\")\n else:\n print(s[1] if q == \"s\" else s[-2])\n\n```","inputs":"6\n1 2 5 3 10 6\n6\nA 1 5\nM 1 3\nm 5 6\ns 3 6\nU 1 7\nS 1 2\n","output":"21\n5\n6\n5\n2\n","actual_output":"21\n5\n6\n5\n2\n","execution_success":true,"sample_index":300},{"source":"apps","task_type":"verifiable_code","in_source_id":"693","prompt":"Solve the following coding problem using the programming language python:\n\nWrite a program to find the factorial value of any number entered by the user.\n\n-----Input-----\n\nThe first line contains an integer T, the total number of testcases. Then T lines follow, each line contains an integer N. \n\n-----Output-----\nFor each test case, display the factorial of the given number N in a new line.\n\n-----Constraints-----\n- 1 \u2264 T \u2264 1000\n- 0 \u2264 N \u2264 20\n\n-----Example-----\nInput\n3 \n3 \n4\n5\n\nOutput\n\n6\n24\n120\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\nx=int(input())\nfor i in range(x):\n s=int(input())\n fact=1\n for i in range(1,s+1):\n fact=fact*i\n print(fact)\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\n3\\n4\\n5\\n', 'output': '6\\n24\\n120\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/FLOW018'}","problem_id":"vfc_1614","program":"```python\n# cook your dish here\nx=int(input())\nfor i in range(x):\n s=int(input())\n fact=1\n for i in range(1,s+1):\n fact=fact*i\n print(fact)\n\n```","inputs":"3\n3\n4\n5\n","output":"6\n24\n120\n","actual_output":"6\n24\n120\n","execution_success":true,"sample_index":301},{"source":"apps","task_type":"verifiable_code","in_source_id":"694","prompt":"Solve the following coding problem using the programming language python:\n\nThe MarkiT online virtual market startup wants to organize its grand opening in NIT Patna.\nbut they want maximum crowd for their inauguration. So the manager told this to Praveen a student in NITP who suggested them:\nThe first-year students come to campus every x hour,\nSecond-year students come to campus every y hour,\nThird-year students come to campus every z hour and \nFourth-year is very busy so they don't come regularly.\nSo Praveen being very clever told him the no of times in n days he can have an audience of all year student (1st,2nd & 3rd) at max. So can you code what Praveen has done?\n\n-----Input:-----\n- First line will contain $T$, number of testcases. Then the testcases follow. \n- Each testcase contains of a 2 line of input, first line contain one integers $N$ (No of Days). \n-Next line contain 3 space separated integer the value of x y z\n\n-----Output:-----\nFor each testcase, output in a single line answer the no of times audience consists of all year.\n\n-----Constraints-----\n- $1 \\leq T \\leq 1000$\n- $1 \\leq N \\leq 10^8$\n- $1 \\leq x,y,z \\leq 10^5$\n\n-----Sample Input:-----\n1\n10\n8 10 6\n\n-----Sample Output:-----\n2\n\n-----EXPLANATION:-----\nFirst favourable condition will come on 5th day and Second on 10th day.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nimport math\ndef fun(num1,num2):\n if num1>num2:\n a=num1\n b=num2\n else:\n a=num2\n b=num1\n rem=a%b\n while(rem!=0):\n a=b\n b=rem\n rem=a%b\n gcd=b\n return (int((num1*num2)/gcd))\n \nfor _ in range (int(input())):\n hours=int(input())*24\n x,y,z=list(map(int,input().split()))\n lcm=x\n lcm=fun(x,y)\n lcm=fun(lcm,z)\n print(int(hours//lcm))\n \n \n \n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n10\\n8 10 6\\n', 'output': '2\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/STRT2020/problems/CRWDCN'}","problem_id":"vfc_1618","program":"```python\nimport math\ndef fun(num1,num2):\n if num1>num2:\n a=num1\n b=num2\n else:\n a=num2\n b=num1\n rem=a%b\n while(rem!=0):\n a=b\n b=rem\n rem=a%b\n gcd=b\n return (int((num1*num2)/gcd))\n \nfor _ in range (int(input())):\n hours=int(input())*24\n x,y,z=list(map(int,input().split()))\n lcm=x\n lcm=fun(x,y)\n lcm=fun(lcm,z)\n print(int(hours//lcm))\n \n \n \n\n```","inputs":"1\n10\n8 10 6\n","output":"2\n","actual_output":"2\n","execution_success":true,"sample_index":302},{"source":"apps","task_type":"verifiable_code","in_source_id":"695","prompt":"Solve the following coding problem using the programming language python:\n\nYou are given three non-negative integers $X$, $Y$ and $N$. Find the number of integers $Z$ such that $0 \\le Z \\le N$ and $(X \\oplus Z) < (Y \\oplus Z)$, where $\\oplus$ denotes the bitwise XOR operation.\n\n-----Input-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The first and only line of each test case contains three space-separated integers $X$, $Y$ and $N$.\n\n-----Output-----\nFor each test case, print a single line containing one integer \u2015 the number of integers $Z$ which satisfy all conditions.\n\n-----Constraints-----\n- $1 \\le T \\le 1,000$\n- $0 \\le X, Y, N \\le 2^{30} - 1$\n\n-----Subtasks-----\nSubtask #1 (5 points): $X, Y, N \\le 2^6 - 1$\nSubtask #2 (95 points): original constraints\n\n-----Example Input-----\n3\n1 2 10\n2 1 10\n0 0 7\n\n-----Example Output-----\n6\n5\n0\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\ntc=int(input())\nfor j in range(tc):\n ip=list(map(int,input().rstrip().split()))\n x=ip[0]\n y=ip[1]\n n=ip[2]\n cnt=0\n if(x==y):\n print('0')\n continue\n ln=bin(x).replace(\"0b\", \"\") \n rn=bin(y).replace(\"0b\", \"\") \n ll=len(ln)\n rl=len(rn)\n #print(ln)\n #print(rn)\n if(ll==len(rn)):\n for i in range(ll):\n \n if(ln[i]!=rn[i]):\n ln=ln[i:]\n rn=rn[i:]\n break\n #print(ln)\n if(ln[0]=='0'):\n ln=ln[1:]\n ll-=1\n #print(rn)\n if(rn[0]=='0'):\n rn=rn[1:]\n rl-=1\n ll=len(ln)\n rl=len(rn)\n if(ll>rl):\n lb=ll \n else:\n lb=rl \n pl=2**lb \n hpl=pl//2\n amn=((n+1)//pl)*hpl \n rm=(n+1)%pl \n if((rm*2)<=pl):\n amn+=rm\n else:\n amn+=hpl \n #print(\"amn = \",amn)\n aln=(n+1)-amn\n #print(\"aln = \",aln)\n if(xrl):\n lb=ll \n else:\n lb=rl \n pl=2**lb \n hpl=pl//2\n amn=((n+1)//pl)*hpl \n rm=(n+1)%pl \n if((rm*2)<=pl):\n amn+=rm\n else:\n amn+=hpl \n #print(\"amn = \",amn)\n aln=(n+1)-amn\n #print(\"aln = \",aln)\n if(x1:\n\t\tres/=n\n\t\tres*=(n-1)\n \n\treturn int(res)\n \nwhile t:\n\ta,m = list(map(int,input().split()))\n\tg = math.gcd(a,m)\n\tprint(phi(m//g))\n\tt-=1\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\n4 9\\n5 10\\n42 9999999967\\n', 'output': '6\\n1\\n9999999966\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/NQST2020/problems/HEIST101'}","problem_id":"vfc_1634","program":"```python\nimport math\nt = int(input())\n \ndef phi(n):\n\tres = n\n\ti = 2\n\twhile i*i<=n:\n\t\tif n%i==0:\n\t\t\tres/=i\n\t\t\tres*=(i-1)\n \n\t\t\twhile n%i==0:\n\t\t\t\tn/=i\n\t\ti+=1\n\t\n\tif n>1:\n\t\tres/=n\n\t\tres*=(n-1)\n \n\treturn int(res)\n \nwhile t:\n\ta,m = list(map(int,input().split()))\n\tg = math.gcd(a,m)\n\tprint(phi(m//g))\n\tt-=1\n\n```","inputs":"3\n4 9\n5 10\n42 9999999967\n","output":"6\n1\n9999999966\n","actual_output":"6\n1\n9999999966\n","execution_success":true,"sample_index":306},{"source":"apps","task_type":"verifiable_code","in_source_id":"699","prompt":"Solve the following coding problem using the programming language python:\n\nChef wants to host some Division-3 contests. Chef has $N$ setters who are busy creating new problems for him. The $i^{th}$ setter has made $A_i$ problems where $1 \\leq i \\leq N$. \nA Division-3 contest should have exactly $K$ problems. Chef wants to plan for the next $D$ days using the problems that they have currently. But Chef cannot host more than one Division-3 contest in a day.\nGiven these constraints, can you help Chef find the maximum number of Division-3 contests that can be hosted in these $D$ days?\n\n-----Input:-----\n- The first line of input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The first line of each test case contains three space-separated integers - $N$, $K$ and $D$ respectively.\n- The second line of each test case contains $N$ space-separated integers $A_1, A_2, \\ldots, A_N$ respectively. \n\n-----Output:-----\nFor each test case, print a single line containing one integer \u2015 the maximum number of Division-3 contests Chef can host in these $D$ days.\n\n-----Constraints-----\n- $1 \\leq T \\leq 10^3$\n- $1 \\leq N \\leq 10^2$\n- $1 \\le K \\le 10^9$ \n- $1 \\le D \\le 10^9$\n- $1 \\le A_i \\le 10^7$ for each valid $i$\n\n-----Subtasks-----\nSubtask #1 (40 points):\n- $N = 1$\n- $1 \\le A_1 \\le 10^5$\nSubtask #2 (60 points): Original constraints\n\n-----Sample Input:-----\n5\n1 5 31\n4\n1 10 3\n23\n2 5 7\n20 36\n2 5 10\n19 2\n3 3 300\n1 1 1\n\n-----Sample Output:-----\n0\n2\n7\n4\n1\n\n-----Explanation:-----\n- \nExample case 1: Chef only has $A_1 = 4$ problems and he needs $K = 5$ problems for a Division-3 contest. So Chef won't be able to host any Division-3 contest in these 31 days. Hence the first output is $0$.\n- \nExample case 2: Chef has $A_1 = 23$ problems and he needs $K = 10$ problems for a Division-3 contest. Chef can choose any $10+10 = 20$ problems and host $2$ Division-3 contests in these 3 days. Hence the second output is $2$.\n- \nExample case 3: Chef has $A_1 = 20$ problems from setter-1 and $A_2 = 36$ problems from setter-2, and so has a total of $56$ problems. Chef needs $K = 5$ problems for each Division-3 contest. Hence Chef can prepare $11$ Division-3 contests. But since we are planning only for the next $D = 7$ days and Chef cannot host more than $1$ contest in a day, Chef cannot host more than $7$ contests. Hence the third output is $7$.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfor T in range(int (eval(input()))):\n N,K,D=list(map(int,input().split()))\n A=list(map(int,input().split()))\n P=sum(A)//K \n print(min(P,D))\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '5\\n1 5 31\\n4\\n1 10 3\\n23\\n2 5 7\\n20 36\\n2 5 10\\n19 2\\n3 3 300\\n1 1 1\\n', 'output': '0\\n2\\n7\\n4\\n1\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/DIVTHREE'}","problem_id":"vfc_1638","program":"```python\nfor T in range(int (eval(input()))):\n N,K,D=list(map(int,input().split()))\n A=list(map(int,input().split()))\n P=sum(A)//K \n print(min(P,D))\n\n```","inputs":"5\n1 5 31\n4\n1 10 3\n23\n2 5 7\n20 36\n2 5 10\n19 2\n3 3 300\n1 1 1\n","output":"0\n2\n7\n4\n1\n","actual_output":"0\n2\n7\n4\n1\n","execution_success":true,"sample_index":307},{"source":"apps","task_type":"verifiable_code","in_source_id":"700","prompt":"Solve the following coding problem using the programming language python:\n\nNow-a-days, Manish is becoming famous for bank robbery in the country because of his cleverness, he never robs own his own.He has four workers A , B, C, and D , all working under him.All of the four take some amount for that. There are total N banks in the country and Manish wants to rob all the banks with minimum\n\namount spent on workers.Only one worker is allowed to rob the ith bank but following a condition that if one worker robs ith bank, then he can't rob (i+1) th bank.\n\nSo ,Manish wants you to calculate minimum amount that he has to spend on all workers to rob all N banks.\n\n-----Input Format-----\nFirst line consists number of test cases T.For each test case,\n\nfirst line consists an integer N, number of banks in the country\n\nand the next N line consists 4 integers amount taken by A,B,C and D respectively to rob ith bank.\n\n-----Output format-----\nFor each test case ,output an integer, minimum amount paid by Manish in separate line .\n\n-----Constraint-----\n- 1<=T<=1000\n- 1<=N<=100000\n- 1<=amount<=100000\n\n-----Subtasks-----\nSubtask-1 (10 points)\n- 1<=T<=5\n- 1<=N<=10\n- 1<=amount<=10\nSubtask-1 (30 points)\n- 1<=T<=100\n- 1<=N<=1000\n- 1<=amount<=1000\nSubtask-1 (60 points)\nOriginal Constraints \nSample Input\n1\n3\n4 7 2 9\n5 6 4 7\n2 6 4 3\n\nSample Output\n10\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfor t in range(int(input())):\n n = int(input())\n l = []\n m = []\n x = list(map(int,input().split()))\n l.append(x)\n m.append(list(x))\n for i in range(1,n):\n x = list(map(int,input().split()))\n l.append(x)\n temp = []\n for i in range(4):\n temp.append (x[i]+min(m[-1][:i]+m[-1][i+1:]))\n m.append(temp)\n print(min(m[-1]))\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n3\\n4 7 2 9\\n5 6 4 7\\n2 6 4 3\\n', 'output': '10\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/ICOD2016/problems/ICODE16D'}","problem_id":"vfc_1642","program":"```python\nfor t in range(int(input())):\n n = int(input())\n l = []\n m = []\n x = list(map(int,input().split()))\n l.append(x)\n m.append(list(x))\n for i in range(1,n):\n x = list(map(int,input().split()))\n l.append(x)\n temp = []\n for i in range(4):\n temp.append (x[i]+min(m[-1][:i]+m[-1][i+1:]))\n m.append(temp)\n print(min(m[-1]))\n```","inputs":"1\n3\n4 7 2 9\n5 6 4 7\n2 6 4 3\n","output":"10\n","actual_output":"10\n","execution_success":true,"sample_index":308},{"source":"apps","task_type":"verifiable_code","in_source_id":"701","prompt":"Solve the following coding problem using the programming language python:\n\nYou are given a sequence of N$N$ powers of an integer k$k$; let's denote the i$i$-th of these powers by kAi$k^{A_i}$. You should partition this sequence into two non-empty contiguous subsequences; each element of the original sequence should appear in exactly one of these subsequences. In addition, the product of (the sum of elements of the left subsequence) and (the sum of elements of the right subsequence) should be maximum possible.\nFind the smallest position at which you should split this sequence in such a way that this product is maximized.\n\n-----Input-----\n- 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.\n- The first line of each test case contains two space-separated integers N$N$ and k$k$.\n- The second line contains N$N$ space-separated integers A1,A2,\u2026,AN$A_1, A_2, \\dots, A_N$.\n\n-----Output-----\nFor each test case, print a single line containing one integer \u2014 the size of the left subsequence. If there is more than one possible answer, print the smallest possible one.\n\n-----Constraints-----\n- 1\u2264T\u226410$1 \\le T \\le 10$\n- 2\u2264N\u2264105$2 \\le N \\le 10^5$\n- 2\u2264k\u2264109$2 \\le k \\le 10^9$\n- 0\u2264Ai\u2264105$0 \\le A_i \\le 10^5$ for each valid i$i$\n\n-----Subtasks-----\nSubtask #1 (30 points):\n- 2\u2264N\u22641,000$2 \\le N \\le 1,000$\n- 0\u2264Ai\u22641,000$0 \\le A_i \\le 1,000$ for each valid i$i$\nSubtask #2 (70 points): original constraints\n\n-----Example Input-----\n1\n5 2\n1 1 3 3 5\n\n-----Example Output-----\n4\n\n-----Explanation-----\nExample case 1: The actual sequence of powers is [21,21,23,23,25]=[2,2,8,8,32]$[2^1, 2^1, 2^3, 2^3, 2^5] = [2, 2, 8, 8, 32]$. The maximum product is 20\u22c532=640$20 \\cdot 32 = 640$. In the optimal solution, the sequence is partitioned into [2,2,8,8]$[2, 2, 8, 8]$ and [32]$[32]$.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\ndef main():\n for _ in range(int(input())):\n N, k = [int(x) for x in input().split()]\n Powers = [k ** int(x) for x in input().split()]\n \n s1, s2 = 0, sum(Powers)\n \n ans = (0, None)\n \n i = 0\n while i < N - 1:\n s1 += Powers[i]\n s2 -= Powers[i]\n \n z = s1 * s2 \n if z > ans[0]:\n ans = (z, i)\n # print(z)\n \n i += 1\n \n print(ans[1] + 1)\n\nmain()\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n5 2\\n1 1 3 3 5\\n', 'output': '4\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/MXM'}","problem_id":"vfc_1646","program":"```python\n# cook your dish here\ndef main():\n for _ in range(int(input())):\n N, k = [int(x) for x in input().split()]\n Powers = [k ** int(x) for x in input().split()]\n \n s1, s2 = 0, sum(Powers)\n \n ans = (0, None)\n \n i = 0\n while i < N - 1:\n s1 += Powers[i]\n s2 -= Powers[i]\n \n z = s1 * s2 \n if z > ans[0]:\n ans = (z, i)\n # print(z)\n \n i += 1\n \n print(ans[1] + 1)\n\nmain()\n```","inputs":"1\n5 2\n1 1 3 3 5\n","output":"4\n","actual_output":"4\n","execution_success":true,"sample_index":309},{"source":"apps","task_type":"verifiable_code","in_source_id":"702","prompt":"Solve the following coding problem using the programming language python:\n\nThis is a peculiar functioning setup.\nTwo Tanks are separated from each other by a wall .There is a pipe in the wall which connects both tanks which allows flow of water between them . Due to this ,there is change in temperature of both tanks , every minute temperature of Tank with larger temperature among two decreases by one and temperature of Tank with smaller temperature among two increases by two until equilibrium is reached , But there is a problem .\nThe pipe can't control this flow of water if there is Non-equilibrium (inequality of temperature on both sides ) even after $m$ minutes and the pipe will burst after it , your task is to predict whether the pipe will burst or not .\nNote: If equilibrium cannot be reached the process will continue forever.\nThe initial temperature of Cold Tank is $Tc$ , of Hot Tank it is $Th$. \n\n-----Input:-----\n- First line will contain $T$, number of testcases. Then the testcases follow. \n- Each testcase contains of a single line of input, three integers $m, Tc,Th$. \n\n-----Output:-----\nFor each testcase, output in a single line answer \"Yes\" if Pipe will burst after m minutes \"No\" if pipe will not burst.\n\n-----Constraints-----\n- $1 \\leq T \\leq 100000$\n- $1 \\leq m,Tc,Th \\leq 10^9$\n- $Tc \\leq Th $\n\n-----Sample Input:-----\n2\n4 5 10\n2 2 5\n\n-----Sample Output:-----\nYes\nNo\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfor i in range(int(input())):\n m,tc,th=map(int,input().split())\n x=(th-tc)\n if x%3!=0:\n print(\"Yes\")\n else:\n if (x//3)<=m:\n print(\"No\")\n else:\n print(\"Yes\")\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n4 5 10\\n2 2 5\\n', 'output': 'Yes\\nNo\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/COCA2020/problems/HOTNCOLD'}","problem_id":"vfc_1650","program":"```python\nfor i in range(int(input())):\n m,tc,th=map(int,input().split())\n x=(th-tc)\n if x%3!=0:\n print(\"Yes\")\n else:\n if (x//3)<=m:\n print(\"No\")\n else:\n print(\"Yes\")\n```","inputs":"2\n4 5 10\n2 2 5\n","output":"Yes\nNo\n","actual_output":"Yes\nNo\n","execution_success":true,"sample_index":310},{"source":"apps","task_type":"verifiable_code","in_source_id":"703","prompt":"Solve the following coding problem using the programming language python:\n\nChef gives an integer $K$ in the input. If the given number is beautiful binary number, print it, Else find its previous beautiful binary number. A beautiful binary number is a number whose binary representation does not contain any consecutive 1s.\nNote: 1 is also a beautiful binary number.\n\n-----Input:-----\n- First-line will contain $T$, the number of test cases. Then the test cases follow. \n- Each test case contains a single line of input, one integer $K$. \n\n-----Output:-----\nFor each test case, print a beautiful number.\n\n-----Constraints-----\n- $1 \\leq T \\leq 10^5$\n- $1 \\leq K \\leq 10^5$\n\n-----Sample Input:-----\n3\n3\n6\n8\n\n-----Sample Output:-----\n2\n5\n8\n\n-----EXPLANATION:-----\nFor 1) 3 is not a beautiful binary number because the binary representation of 3 is \"11\" which has consecutive 1s. hence 2 which is less than 3 is printed.\nFor 3) 8 is already a beautiful binary number with no consecutive 1s in its binary representation. so, print 8 as it is.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\npref = []\r\n\r\nfor i in range(10 ** 5 + 10):\r\n b = bin(i)[2:]\r\n if not any(b[j] == b[j+1] == '1' for j in range(len(b) - 1)):\r\n pref.append(i)\r\n else:\r\n pref.append(pref[-1])\r\n\r\nfor i in range(int(input())):\r\n print(pref[int(input())])\r\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\n3\\n6\\n8\\n', 'output': '2\\n5\\n8\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/PBK02020/problems/ITGUY10'}","problem_id":"vfc_1654","program":"```python\npref = []\r\n\r\nfor i in range(10 ** 5 + 10):\r\n b = bin(i)[2:]\r\n if not any(b[j] == b[j+1] == '1' for j in range(len(b) - 1)):\r\n pref.append(i)\r\n else:\r\n pref.append(pref[-1])\r\n\r\nfor i in range(int(input())):\r\n print(pref[int(input())])\r\n\n```","inputs":"3\n3\n6\n8\n","output":"2\n5\n8\n","actual_output":"2\n5\n8\n","execution_success":true,"sample_index":311},{"source":"apps","task_type":"verifiable_code","in_source_id":"704","prompt":"Solve the following coding problem using the programming language python:\n\nEugene has to do his homework. But today, he is feeling very lazy and wants to you do his homework. His homework has the following given maths problem.\nYou are given three integers: A, N, M. You write the number A appended to itself N times in a row. Let's call the resulting big number X. For example, if A = 120, N = 3, then X will be 120120120. Find out the value of X modulo M.\n\n-----Input-----\nThe first line of the input contains an integer T denoting the number of test cases. The description of T test cases follow.\nEach test case is described in one line containing three integers: A, N and M as described in the problem statement.\n\n-----Output-----\nFor each test case, output a single line containing an integer denoting the value of X modulo M.\n\n-----Constraints-----\n- 1 \u2264 T \u2264 105\n- 0 \u2264 A \u2264 109\n- 1 \u2264 N \u2264 1012\n- 2 \u2264 M \u2264 109\n\n-----Subtasks-----\nSubtask #1 (15 points):\n- 0 \u2264 A \u2264 100\n- 1 \u2264 N \u2264 105\n\nSubtask #2 (25 points):\n- 1 \u2264 N \u2264 109\n\nSubtask #3 (60 points):\n- Original constraints\n\n-----Example-----\nInput:\n2\n12 2 17\n523 3 11\n\nOutput:\n5\n6\n\n-----Explanation-----\nExample 1: As A = 12, N = 2, X = 1212, 1212 modulo 17 = 5\nExample 2. As A = 523, N = 3, X = 523523523, 523523523 modulo 11 = 6\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\nfor _ in range(int(input())):\n a,n,m = map(int,input().split(' '))\n s = len(str(a))\n #print(s)\n c = 10**s - 1\n w = c*m\n b = pow(10,n*s,w)-1\n d = b//c\n ans = (d%m)*(a%m)\n print(ans%m) \n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n12 2 17\\n523 3 11\\n\\n\\n', 'output': '5\\n6\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/KBIGNUMB'}","problem_id":"vfc_1658","program":"```python\n# cook your dish here\nfor _ in range(int(input())):\n a,n,m = map(int,input().split(' '))\n s = len(str(a))\n #print(s)\n c = 10**s - 1\n w = c*m\n b = pow(10,n*s,w)-1\n d = b//c\n ans = (d%m)*(a%m)\n print(ans%m) \n```","inputs":"2\n12 2 17\n523 3 11\n\n\n","output":"5\n6\n","actual_output":"5\n6\n","execution_success":true,"sample_index":312},{"source":"apps","task_type":"verifiable_code","in_source_id":"706","prompt":"Solve the following coding problem using the programming language python:\n\nChef has $N$ small boxes arranged on a line from $1$ to $N$. For each valid $i$, the weight of the $i$-th box is $W_i$. Chef wants to bring them to his home, which is at the position $0$. He can hold any number of boxes at the same time; however, the total weight of the boxes he's holding must not exceed K at any time, and he can only pick the ith box if all the boxes between Chef's home and the ith box have been either moved or picked up in this trip.\nTherefore, Chef will pick up boxes and carry them home in one or more round trips. Find the smallest number of round trips he needs or determine that he cannot bring all boxes home.\n\n-----Input-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The first line of each test case contains two space-separated integers $N$ and $K$.\n- The second line contains $N$ space-separated integers $W_1, W_2, \\ldots, W_N$.\n\n-----Output-----\nFor each test case, print a single line containing one integer \u2015 the smallest number of round trips or $-1$ if it is impossible for Chef to bring all boxes home.\n\n-----Constraints-----\n- $1 \\le T \\le 100$\n- $1 \\le N, K \\le 10^3$\n- $1 \\le W_i \\le 10^3$ for each valid $i$\n\n-----Example Input-----\n4\n1 1 \n2\n2 4\n1 1\n3 6\n3 4 2\n3 6\n3 4 3\n\n-----Example Output-----\n-1\n1\n2\n3\n\n-----Explanation-----\nExample case 1: Since the weight of the box higher than $K$, Chef can not carry that box home in any number of the round trip.\nExample case 2: Since the sum of weights of both boxes is less than $K$, Chef can carry them home in one round trip.\nExample case 3: In the first round trip, Chef can only pick up the box at position $1$. In the second round trip, he can pick up both remaining boxes at positions $2$ and $3$.\nExample case 4: Chef can only carry one box at a time, so three round trips are required.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nt=int(input())\nfor i in range(t):\n x,y=0,0\n n,m=list(map(int,input().split()))\n l=list(map(int,input().split()))\n if(max(l)>m):\n print(-1)\n else:\n for i in range(len(l)):\n y+=l[i]\n if(y>m):\n y=l[i]\n x+=1\n if(y>0):\n x+=1\n print(x)\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '4\\n1 1\\n2\\n2 4\\n1 1\\n3 6\\n3 4 2\\n3 6\\n3 4 3\\n', 'output': '-1\\n1\\n2\\n3\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/CHEFNWRK'}","problem_id":"vfc_1666","program":"```python\nt=int(input())\nfor i in range(t):\n x,y=0,0\n n,m=list(map(int,input().split()))\n l=list(map(int,input().split()))\n if(max(l)>m):\n print(-1)\n else:\n for i in range(len(l)):\n y+=l[i]\n if(y>m):\n y=l[i]\n x+=1\n if(y>0):\n x+=1\n print(x)\n\n```","inputs":"4\n1 1\n2\n2 4\n1 1\n3 6\n3 4 2\n3 6\n3 4 3\n","output":"-1\n1\n2\n3\n","actual_output":"-1\n1\n2\n3\n","execution_success":true,"sample_index":314},{"source":"apps","task_type":"verifiable_code","in_source_id":"707","prompt":"Solve the following coding problem using the programming language python:\n\nIn 17th century our Chef was a Wizard. He asked his small son \"Anshu\" to bring him the secret of the Magical Mountain. The boy after travelling a lot reached the Mountain.\n\nThe description of the Mountain was as follows:\n- Mountain contains N magical stones. Each of them has a unique number.\n- Mountain was divided into many levels, where at ith level atmost 2^i stones can be found.\n- Between stones there exist a magical path containing lava.\n- A stone can be connected with maximum of three stones.\n- Peak of the mountain contains stone with number 1.\n- If Stone 1 is first connected to stone 2 and then to 3. Assume 2 is to the left of 3.\n\nNow, to get the secret of the mountain, Anshu started climbing from the left. On the way he used his magical wand to protect him from lava. But, while climbing he came to know that he is able to see only the one stone at each level. After reaching the peak he slided down and did the the same process. These stones that he saw shows the secret of the mountain, if they are placed in a non decreasing order on a sunny day. Anshu doesn't remember the stones number that he saw. Help him in recollecting them and getting the secret to his father.\n\nThe mountain looks like this\n\n-----Input-----\n- First line contains T the number of test cases.\n- First line of each test test case contains N.\n- Next N-1 lines contains X and Y the stones which are connected.\n\n-----Output-----\n- Output the required non decreasing sequence.\n\n-----Constraints and Subtasks-----\n- 1 <= T <= 10\n- 1 <= X, Y <= N\nSubtask 1: 20 points\n- 3<=N<=100\nSubtask 2: 30 points\n- 3<=N<=10000\nSubtask 3: 50 points\n- 3<=N<=100000\n\n-----Example-----\nInput:\n1\n5\n1 2\n1 3\n2 4\n2 5\n\nOutput:\n1 2 3 4 5\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfor t in range(eval(input())):\n \n n = eval(input())\n \n a = [ [] for i in range(n+1) ]\n \n for i in range(n-1):\n x,y = list(map( int, input().split() ))\n a[x].append(y)\n a[y].append(x)\n \n vis = [0] * (n+1)\n vis[1] = 1\n\n ans = [1]\n\n t1 = [1]\n t2 = []\n \n while len(t1) > 0 :\n for u in t1:\n for x in a[u]:\n if vis[x] == 0 :\n vis[x] = 1\n t2.append(x)\n if len(t2) > 1 :\n ans.append(t2[0])\n ans.append(t2[-1])\n if len(t2) == 1 :\n ans.append(t2[0])\n \n t1 = t2\n t2 = []\n \n for x in sorted(ans):\n print(x, end=' ')\n \n print('')\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n5\\n1 2\\n1 3\\n2 4\\n2 5\\n', 'output': '1 2 3 4 5\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/CDVA16/problems/CDVA1602'}","problem_id":"vfc_1670","program":"```python\nfor t in range(eval(input())):\n \n n = eval(input())\n \n a = [ [] for i in range(n+1) ]\n \n for i in range(n-1):\n x,y = list(map( int, input().split() ))\n a[x].append(y)\n a[y].append(x)\n \n vis = [0] * (n+1)\n vis[1] = 1\n\n ans = [1]\n\n t1 = [1]\n t2 = []\n \n while len(t1) > 0 :\n for u in t1:\n for x in a[u]:\n if vis[x] == 0 :\n vis[x] = 1\n t2.append(x)\n if len(t2) > 1 :\n ans.append(t2[0])\n ans.append(t2[-1])\n if len(t2) == 1 :\n ans.append(t2[0])\n \n t1 = t2\n t2 = []\n \n for x in sorted(ans):\n print(x, end=' ')\n \n print('')\n```","inputs":"1\n5\n1 2\n1 3\n2 4\n2 5\n","output":"1 2 3 4 5\n","actual_output":"1 2 3 4 5 \n","execution_success":true,"sample_index":315},{"source":"apps","task_type":"verifiable_code","in_source_id":"708","prompt":"Solve the following coding problem using the programming language python:\n\nYou are given a square matrix $M$ with $N$ rows (numbered $1$ through $N$) and $N$ columns (numbered $1$ through $N$). Initially, all the elements of this matrix are equal to $A$. The matrix is broken down in $N$ steps (numbered $1$ through $N$); note that during this process, some elements of the matrix are simply marked as removed, but all elements are still indexed in the same way as in the original matrix. For each valid $i$, the $i$-th step consists of the following:\n- Elements $M_{1, N-i+1}, M_{2, N-i+1}, \\ldots, M_{i-1, N-i+1}$ are removed.\n- Elements $M_{i, N-i+1}, M_{i, N-i+2}, \\ldots, M_{i, N}$ are removed.\n- Let's denote the product of all $2i-1$ elements removed in this step by $p_i$. Each of the remaining elements of the matrix (those which have not been removed yet) is multiplied by $p_i$.\nFind the sum $p_1 + p_2 + p_3 + \\ldots + p_N$. Since this number could be very large, compute it modulo $10^9+7$.\n\n-----Input-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The first and only line of each test case contains two space-separated integers $N$ and $A$.\n\n-----Output-----\nFor each test case, print a single line containing one integer \u2015 the sum of products at each step modulo $10^9+7$.\n\n-----Constraints-----\n- $1 \\le T \\le 250$\n- $1 \\le N \\le 10^5$\n- $0 \\le A \\le 10^9$\n- the sum of $N$ over all test cases does not exceed $10^5$\n\n-----Example Input-----\n1\n3 2\n\n-----Example Output-----\n511620149\n\n-----Explanation-----\nExample case 1:\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\nfor _ in range(int(input())):\n n,k = list(map(int,input().split()))\n mod = 10**9+7\n s=0\n for i in range(1,n+1):\n p = pow(k,(2*i)-1,mod)\n # print(p)\n s=(s+p)%mod\n # print(k)\n k = (p*k)%mod\n print(s)\n\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n3 2\\n', 'output': '511620149\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/MATBREAK'}","problem_id":"vfc_1674","program":"```python\n# cook your dish here\nfor _ in range(int(input())):\n n,k = list(map(int,input().split()))\n mod = 10**9+7\n s=0\n for i in range(1,n+1):\n p = pow(k,(2*i)-1,mod)\n # print(p)\n s=(s+p)%mod\n # print(k)\n k = (p*k)%mod\n print(s)\n\n\n```","inputs":"1\n3 2\n","output":"511620149\n","actual_output":"511620149\n","execution_success":true,"sample_index":316},{"source":"apps","task_type":"verifiable_code","in_source_id":"709","prompt":"Solve the following coding problem using the programming language python:\n\n$Gogi$, $Tapu$ and $Sonu$ are the elite members of $Tapu$ $Sena$. $Gogi$ is always stoned and asks absurd questions, But this time he asked a question which seems to be very serious and interesting. $Tapu$ wants to solve this question to impress $Sonu$. He gave an array of length N to $Tapu$, $Tapu$ can perform the following operations exactly once:\n- Remove any subarray from the given array given the resulting array formed after the removal is non-empty. \n- Reverse the whole array.\nRemember you can\u2019t shuffle the elements of the array.\nTapu needs to find out the maximum possible GCD of all the numbers in the array after applying the given operations exactly once. Tapu is very weak at programming, he wants you to solve this problem so that he can impress $Sonu$.\n\n-----Input:-----\n- The first line contains $T$, the number of test cases.\n- For each test case\n-FIrst line contains $N$.\n- Last line contains $N$ numbers of the array. \n\n-----Output:-----\nA single integer in a new line, maximum possible GCD. \n\n-----Constraints-----\n- $1 \\leq T \\leq 10^2$\n- $1 \\leq N \\leq 10^4$\n- $1 \\leq a[i] \\leq 10^9$\n\nSummation of N for all testcases is less than $10^6$ \n\n-----Sample Input 1:-----\n1\n1\n2\n\n-----Sample Output 1:-----\n2\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\ntry:\n t = int(input())\n for _ in range(t):\n n = int(input())\n a = list(map(int, input().split()))\n gcd = max(a[0], a[-1])\n \n print(gcd)\nexcept EOFError:pass\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n1\\n2\\n', 'output': '2\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/CORE2020/problems/CORE2002'}","problem_id":"vfc_1678","program":"```python\n# cook your dish here\ntry:\n t = int(input())\n for _ in range(t):\n n = int(input())\n a = list(map(int, input().split()))\n gcd = max(a[0], a[-1])\n \n print(gcd)\nexcept EOFError:pass\n```","inputs":"1\n1\n2\n","output":"2\n","actual_output":"2\n","execution_success":true,"sample_index":317},{"source":"apps","task_type":"verifiable_code","in_source_id":"710","prompt":"Solve the following coding problem using the programming language python:\n\nBlob is a computer science student. He recently got an internship from Chef's enterprise. Along with the programming he has various other skills too like graphic designing, digital marketing and social media management. Looking at his skills Chef has provided him different tasks A[1\u2026N] which have their own scores. Blog wants to maximize the value of the expression A[d]-A[c]+A[b]-A[a] such that d>c>b>a.\n\nCan you help him in this?\n\n-----Input:-----\n- The first line contain the integer N\n- The second line contains N space separated integers representing A[1], A[2] \u2026 A[N]\n\n-----Output:-----\nThe maximum score that is possible\n\n-----Constraints-----\n- $4 \\leq N \\leq 10^4$\n- $0 \\leq A[i] \\leq 10^5$\n\n-----Sample Input:-----\n6\n\n3 9 10 1 30 40\n\n-----Sample Output:-----\n46\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\ndef maxval(arr):\n fn = [float('-inf')]*(len(arr)+1)\n sn = [float('-inf')]*len(arr)\n tn = [float('-inf')]*(len(arr)-1)\n fon = [float('-inf')]*(len(arr)-2)\n for i in reversed(list(range(len(arr)))):\n fn[i] = max(fn[i + 1], arr[i])\n for i in reversed(list(range(len(arr) - 1))):\n sn[i] = max(sn[i + 1], fn[i + 1] - arr[i])\n\n for i in reversed(list(range(len(arr) - 2))):\n tn[i] = max(tn[i + 1], sn[i + 1] + arr[i])\n\n for i in reversed(list(range(len(arr) - 3))):\n fon[i] = max(fon[i + 1], tn[i + 1] - arr[i])\n return fon[0]\nn = int(input())\narr = list(map(int,input().split()))\nprint(maxval(arr))\n \n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '6\\n3 9 10 1 30 40\\n', 'output': '46\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/WNTR2020/problems/WC04'}","problem_id":"vfc_1682","program":"```python\ndef maxval(arr):\n fn = [float('-inf')]*(len(arr)+1)\n sn = [float('-inf')]*len(arr)\n tn = [float('-inf')]*(len(arr)-1)\n fon = [float('-inf')]*(len(arr)-2)\n for i in reversed(list(range(len(arr)))):\n fn[i] = max(fn[i + 1], arr[i])\n for i in reversed(list(range(len(arr) - 1))):\n sn[i] = max(sn[i + 1], fn[i + 1] - arr[i])\n\n for i in reversed(list(range(len(arr) - 2))):\n tn[i] = max(tn[i + 1], sn[i + 1] + arr[i])\n\n for i in reversed(list(range(len(arr) - 3))):\n fon[i] = max(fon[i + 1], tn[i + 1] - arr[i])\n return fon[0]\nn = int(input())\narr = list(map(int,input().split()))\nprint(maxval(arr))\n \n\n```","inputs":"6\n3 9 10 1 30 40\n","output":"46\n","actual_output":"46\n","execution_success":true,"sample_index":318},{"source":"apps","task_type":"verifiable_code","in_source_id":"711","prompt":"Solve the following coding problem using the programming language python:\n\nThe notorious hacker group \"Sed\" managed to obtain a string $S$ from their secret sources. The string contains only lowercase English letters along with the character '?'.\nA substring of $S$ is a contiguous subsequence of that string. For example, the string \"chef\" is a substring of the string \"codechef\", but the string \"codeh\" is not a substring of \"codechef\".\nA substring of $S$ is good if it is possible to choose a lowercase English letter $C$ such that the following process succeeds:\n- Create a string $R$, which is a copy of the substring, but with each '?' replaced by the letter $c$. Note that all occurrences of '?' must be replaced by the same letter.\n- For each lowercase English letter:\n- Compute the number of times it occurs in $S$ and the number of times it occurs in $R$; let's denote them by $A$ and $B$ respectively. The '?' characters in the original string $S$ are ignored when computing $A$.\n- Check the parity of $A$ and $B$. If they do not have the same parity, i.e. one of them is even while the other is odd, then this process fails.\n- If the parities of the number of occurrences in $S$ and $R$ are the same for each letter, the process succeeds.\nFor different substrings, we may choose different values of $C$.\nHelp Sed find the number of good substrings in the string $S$.\n\n-----Input-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The first and only line of each test case contains a single string $S$.\n\n-----Output-----\nFor each test case, print a single line containing one integer \u2015 the number of good substrings.\n\n-----Constraints-----\n- $1 \\le T \\le 10^5$\n- $1 \\le S \\le 10^5$\n- $S$ contains only lowercase English letters ('a' through 'z') and '?'\n- the sum of $|S|$ over all test cases does not exceed $10^5$\n\n-----Example Input-----\n5\naa?\na???\n????\nasfhaslskfak\naf??avvnfed?fav?faf????\n\n-----Example Output-----\n2\n6\n4\n2\n27\n\n-----Explanation-----\nExample case 1: All letters occur an even number of times in $S$. The six substrings of $S$ are \"a\", \"a\", \"?\", \"aa\", \"a?\" and \"aa?\" (note that \"a\" is counted twice). Which of them are good?\n- \"a\" is not good as 'a' occurs an odd number of times in this substring and there are no '?' to replace.\n- \"?\" is also not good as replacing '?' by any letter causes this letter to occur in $R$ an odd number of times.\n- \"aa\" is a good substring because each letter occurs in it an even number of times and there are no '?' to replace.\n- \"a?\" is also a good substring. We can replace '?' with 'a'. Then, $R$ is \"aa\" and each letter occurs in this string an even number of times. Note that replacing '?' e.g. with 'b' would not work ($R$ would be \"ab\", where both 'a' and 'b' occur an odd number of times), but we may choose the replacement letter $C$ appropriately.\n- \"aa?\" is not a good substring. For any replacement letter $C$, we find that $C$ occurs an odd number of times in $R$.\nExample case 2: We especially note that \"a???\" is not a good substring. Since all '?' have to be replaced by the same character, we can only get strings of the form \"aaaa\", \"abbb\", \"accc\", etc., but none of them match the criteria for a good substring.\nExample case 3: Any substring with even length is good.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\ndef convertToParitys(s):\r\n \"\"\"\r\n This converts the string s to an int, which is a bitMap of the parity of each letter\r\n odd ? = first bit set\r\n odd a = second bit set\r\n odd b = third bit set \r\n etc\r\n \"\"\"\r\n keys = '?abcdefghijklmnopqrstuvwxyz'\r\n paritys = {c:0 for c in keys}\r\n for c in s:\r\n paritys[c] += 1\r\n for c, v in paritys.items():\r\n paritys[c] = v%2\r\n \r\n out = 0\r\n bitValue = 1\r\n for c in keys:\r\n if paritys[c]:\r\n out += bitValue\r\n bitValue *= 2\r\n return out\r\n\r\ndef getSolutionBitMaps(s):\r\n \"\"\"\r\n these are the 27 valid bitmaps that a substring can have\r\n even ? and the parities the same\r\n 26 cases of odd ? and one bit different in the parity compared to s\r\n \"\"\"\r\n out = []\r\n sP = convertToParitys(s)\r\n if sP%2:\r\n sP -= 1 # to remove the '?' parity\r\n #even case - \r\n out.append(sP)\r\n #odd cases - need to xor sP with 1 + 2**n n = 1 to 26 inc to flip ? bit and each of the others\r\n for n in range(1,27):\r\n out.append(sP^(1+2**n))\r\n return out\r\n\r\ndef getLeadingSubStringBitMapCounts(s):\r\n \"\"\"\r\n This calculates the bit map of each of the len(s) substrings starting with the first character and stores as a dictionary.\r\n Getting TLE calculating each individually, so calculating with a single pass\r\n \"\"\"\r\n out = {}\r\n bM = 0\r\n keys = '?abcdefghijklmnopqrstuvwxyz'\r\n paritys = {c:0 for c in keys}\r\n values = {c:2**i for i,c in enumerate(keys)}\r\n out[bM] = out.setdefault(bM, 0) + 1 #add the null substring\r\n bMis = []\r\n i = 0\r\n bMis = [0]\r\n for c in s:\r\n i += 1\r\n if paritys[c]:\r\n paritys[c] = 0\r\n bM -= values[c]\r\n else:\r\n paritys[c] = 1\r\n bM += values[c]\r\n out[bM] = out.setdefault(bM, 0) + 1\r\n bMis.append(bM)\r\n return out,bMis\r\n\r\ndef solve(s):\r\n out = 0\r\n bMjCounts,bMis = getLeadingSubStringBitMapCounts(s)\r\n #print('bMjCounts')\r\n #print(bMjCounts)\r\n solutions = getSolutionBitMaps(s)\r\n #print('solutions')\r\n #print(solutions) \r\n for bMi in bMis:\r\n for bMs in solutions:\r\n if bMs^bMi in bMjCounts:\r\n out += bMjCounts[bMs^bMi]\r\n #print(i,bMi,bMs,bMs^bMi,bMjCounts[bMs^bMi])\r\n if 0 in solutions:\r\n out -= len(s) #remove all null substrings\r\n out //= 2 # since j may be less that i each substring is counted twice\r\n return out\r\n \r\nT = int(input())\r\nfor tc in range(T):\r\n s = input()\r\n print(solve(s))\r\n \n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '5\\naa?\\na???\\n????\\nasfhaslskfak\\naf??avvnfed?fav?faf????\\n\\n', 'output': '2\\n6\\n4\\n2\\n27\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/SEDPASS'}","problem_id":"vfc_1686","program":"```python\ndef convertToParitys(s):\r\n \"\"\"\r\n This converts the string s to an int, which is a bitMap of the parity of each letter\r\n odd ? = first bit set\r\n odd a = second bit set\r\n odd b = third bit set \r\n etc\r\n \"\"\"\r\n keys = '?abcdefghijklmnopqrstuvwxyz'\r\n paritys = {c:0 for c in keys}\r\n for c in s:\r\n paritys[c] += 1\r\n for c, v in paritys.items():\r\n paritys[c] = v%2\r\n \r\n out = 0\r\n bitValue = 1\r\n for c in keys:\r\n if paritys[c]:\r\n out += bitValue\r\n bitValue *= 2\r\n return out\r\n\r\ndef getSolutionBitMaps(s):\r\n \"\"\"\r\n these are the 27 valid bitmaps that a substring can have\r\n even ? and the parities the same\r\n 26 cases of odd ? and one bit different in the parity compared to s\r\n \"\"\"\r\n out = []\r\n sP = convertToParitys(s)\r\n if sP%2:\r\n sP -= 1 # to remove the '?' parity\r\n #even case - \r\n out.append(sP)\r\n #odd cases - need to xor sP with 1 + 2**n n = 1 to 26 inc to flip ? bit and each of the others\r\n for n in range(1,27):\r\n out.append(sP^(1+2**n))\r\n return out\r\n\r\ndef getLeadingSubStringBitMapCounts(s):\r\n \"\"\"\r\n This calculates the bit map of each of the len(s) substrings starting with the first character and stores as a dictionary.\r\n Getting TLE calculating each individually, so calculating with a single pass\r\n \"\"\"\r\n out = {}\r\n bM = 0\r\n keys = '?abcdefghijklmnopqrstuvwxyz'\r\n paritys = {c:0 for c in keys}\r\n values = {c:2**i for i,c in enumerate(keys)}\r\n out[bM] = out.setdefault(bM, 0) + 1 #add the null substring\r\n bMis = []\r\n i = 0\r\n bMis = [0]\r\n for c in s:\r\n i += 1\r\n if paritys[c]:\r\n paritys[c] = 0\r\n bM -= values[c]\r\n else:\r\n paritys[c] = 1\r\n bM += values[c]\r\n out[bM] = out.setdefault(bM, 0) + 1\r\n bMis.append(bM)\r\n return out,bMis\r\n\r\ndef solve(s):\r\n out = 0\r\n bMjCounts,bMis = getLeadingSubStringBitMapCounts(s)\r\n #print('bMjCounts')\r\n #print(bMjCounts)\r\n solutions = getSolutionBitMaps(s)\r\n #print('solutions')\r\n #print(solutions) \r\n for bMi in bMis:\r\n for bMs in solutions:\r\n if bMs^bMi in bMjCounts:\r\n out += bMjCounts[bMs^bMi]\r\n #print(i,bMi,bMs,bMs^bMi,bMjCounts[bMs^bMi])\r\n if 0 in solutions:\r\n out -= len(s) #remove all null substrings\r\n out //= 2 # since j may be less that i each substring is counted twice\r\n return out\r\n \r\nT = int(input())\r\nfor tc in range(T):\r\n s = input()\r\n print(solve(s))\r\n \n```","inputs":"5\naa?\na???\n????\nasfhaslskfak\naf??avvnfed?fav?faf????\n\n","output":"2\n6\n4\n2\n27\n","actual_output":"2\n6\n4\n2\n27\n","execution_success":true,"sample_index":319},{"source":"apps","task_type":"verifiable_code","in_source_id":"712","prompt":"Solve the following coding problem using the programming language python:\n\nChef got into a fight with the evil Dr Doof. Dr Doof has decided to destroy all even numbers from the universe using his Evil-Destroy-inator. Chef has $N$ integers with him. To stop Doof, Chef has to find an odd number which is an integer multiple of all $N$ numbers that he has with him. Find if it is possible for Chef to prevent Dr Doof from destroying the even numbers.\nFormally, given $N$ positive integers, find if there exists an odd number which is an integer multiple of all the given $N$ numbers. If yes, print \"YES\", otherwise \"NO\". You can print any letter in any case.\n\n-----Input-----\n- First line contains $T$, number of testcases. Each testcase consists of $2$ lines.\n- The first line of each test case consists of a positive integer $N$, denoting the number of positive integers Chef has.\n- The second line of each test case contains $N$ space separated integers $A_i$ each denoting an integer that Chef has with him.\n\n-----Output-----\nFor every test case, if there exists such an odd number, print \"YES\" on a separate line, otherwise \"NO\". The judge is case insensitive. That means, your code can print any letter in any case ( \"Yes\", \"yes\" or \"YES\" are all accepted).\n\n-----Constraints-----\n- $1 \\leq T \\leq 10^3$\n- $1 \\leq N \\leq 10^3$\n- $1 \\leq A_i \\leq 10^3$\n\n-----Sample Input-----\n2\n5\n1 2 5 4 3\n1\n7\n\n-----Sample Output-----\nNO\nYES\n\n-----Explanation-----\nFor test $1$: There exists no odd number.\nFor test $2$: The possible odd numbers can be $7$, $21$, $49$, $315$, \u2026\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\ndef gcd(a,b):\n if b==0: return a\n return gcd(b,a%b)\n\nfor _ in range(int(input())):\n n = int(input())\n arr = list(map(int,input().split()))\n value = arr[0]\n if n!=1:\n for i in arr[1:]:\n value = value*i//gcd(value, i)\n if value%2==0:\n print(\"NO\")\n else:\n print(\"YES\")\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n5\\n1 2 5 4 3\\n1\\n7\\n', 'output': 'NO\\nYES\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/COLE2020/problems/CLLCM'}","problem_id":"vfc_1690","program":"```python\ndef gcd(a,b):\n if b==0: return a\n return gcd(b,a%b)\n\nfor _ in range(int(input())):\n n = int(input())\n arr = list(map(int,input().split()))\n value = arr[0]\n if n!=1:\n for i in arr[1:]:\n value = value*i//gcd(value, i)\n if value%2==0:\n print(\"NO\")\n else:\n print(\"YES\")\n```","inputs":"2\n5\n1 2 5 4 3\n1\n7\n","output":"NO\nYES\n","actual_output":"NO\nYES\n","execution_success":true,"sample_index":320},{"source":"apps","task_type":"verifiable_code","in_source_id":"713","prompt":"Solve the following coding problem using the programming language python:\n\nChef has a sequence of $N$ integers, $A_1, A_2, ... , A_N$. He likes this sequence if it contains a subsequence of $M$ integers, $B_1, B_2, ... , B_M$ within it.\nA subsequence is a sequence that can be derived from another sequence by deleting some or no elements without changing the order of the remaining elements.\nYou will be given a sequence of $N$ integers, $A_1, A_2, ..., A_N$ followed by another sequence of $M$ integers, $B_1, B_2, ..., B_M$. Given these, you have to tell whether Chef likes the sequence of $N$ integers($A_1, A_2, ..., A_N$) or not. \nFormally, output \"Yes\" if\n$\\exists idx_1, idx_2, ..., idx_M | 1 \\le idx_1 < idx_2 < ... < idx_M \\le N$ and $A_{idx_i} = B_i \\forall i, 1 \\le i \\le M$\nOtherwise output \"No\". Note that the quotes are for clarity.\n\n-----Input-----\nThe first line contains a single integer, $T$.\n$T$ test cases follow where each test case contains four lines:\n- The first line of a test case contains a single integer $N$\n- The second line of the test case contains $N$ space separated integers, $A_1, A_2, ..., A_N$\n- The third line of the test case contains a single integer $M$.\n- The fourth line contains $M$ space separated integers, $B_1, B_2, ..., B_M$\nSymbols have usual meanings as described in the statement.\n\n-----Output-----\nFor each test case, output a single line containing the output. Output is \"Yes\" if Chef likes the sequence $A$. Output is \"No\" if Chef dislikes the sequence $A$.\n\n-----Constraints-----\n- $1 \\le T \\le 100$\n- $1 \\le N \\le 10^3$\n- $1 \\le M \\le 10^3$\n- $1 \\le A_i, B_i \\le 10^9$\n\n-----Sample Input-----\n3\n6\n1 2 3 4 5 6\n3\n2 3 4\n6\n22 5 6 33 1 4\n2\n4 15\n4\n1 3 4 2\n2\n1 2\n\n-----Sample Output-----\nYes\nNo\nYes\n\n-----Explanation:-----\nIn sample test case $1$, the sequence $1,2,3,4,5,6$ contains the subsequence $2, 3, 4$. The subsequence is present at indices $1, 2, 3$ of the original sequence.\nHence, $1,2,3,4,5,6$ is a sequence which Chef likes it. Therefore, we output \"Yes\".\nIn sample test case $2$, the subsequence $4, 15$ is not present in sequence $22, 5, 6, 33, 1, 4$. Hence, we output \"No\".\nIn sample test case $3$, the sequence $1, 3, 4, 2$ contains the subsequence $1, 2$. The subsequence is present at indices $0, 3$. Therefore, we output \"Yes\".\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nt=int(input())\ni=0\nwhile i=a:\n a=b\n c=1\n else:\n c=0\n break\n else:\n c=0\n break\n j+=1\n if c==1:\n print(\"Yes\")\n else:\n print(\"No\")\n i+=1\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\n6\\n1 2 3 4 5 6\\n3\\n2 3 4\\n6\\n22 5 6 33 1 4\\n2\\n4 15\\n4\\n1 3 4 2\\n2\\n1 2\\n', 'output': 'Yes\\nNo\\nYes\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/CHEFSQ'}","problem_id":"vfc_1694","program":"```python\nt=int(input())\ni=0\nwhile i=a:\n a=b\n c=1\n else:\n c=0\n break\n else:\n c=0\n break\n j+=1\n if c==1:\n print(\"Yes\")\n else:\n print(\"No\")\n i+=1\n```","inputs":"3\n6\n1 2 3 4 5 6\n3\n2 3 4\n6\n22 5 6 33 1 4\n2\n4 15\n4\n1 3 4 2\n2\n1 2\n","output":"Yes\nNo\nYes\n","actual_output":"Yes\nNo\nYes\n","execution_success":true,"sample_index":321},{"source":"apps","task_type":"verifiable_code","in_source_id":"714","prompt":"Solve the following coding problem using the programming language python:\n\nIt's John's birthday; he has brought some candies in distribute among N of his friends. Being a good friend, he decided to distribute all of his candies equally among his friend and he don't want to keep any for himself. He left the task of distributing candies up to his friends, but his friends haven't done a great job in distributing them and now they all have unequal amount of candies.\nHe asked all of his friends to keep all the candies in their hands (A[1] to A[N]) so that he can redistribute the candies. Taking a candy away from someone makes them sad and makes the person who gets it happy. Thus, you do not want to do many operations on the number of candies.\nHere each operation stands for, taking away 1 candy from someone and giving it to somebody else.\nAfter applying the operations, he might not be able to distribute all the candies among all of your friends, and you might need to buy some more candies as well. Buying each candy will be counted as 1 operation as well. John is saving up for his birthday party in the evening and so he wants to spend the least amount of money on candies as possible.\nThus, he asks for your help. You have to find the minimum number of operations required to make the distributions equal.\n\n-----Input:-----\n- The first line consists of the number T representing the number of test cases.\n- Each test case consists of 2 lines.\n- The first line contains of the number N representing the number of friends.\n- The second line contains space separated numbers (A[1] to A[N]) representing the number of candies each friend currently has.\n\n-----Output:-----\nFor each test case, you much print the minimum number of operations.\n\n-----Constraints-----\n- $1 \\leq T \\leq 10$\n- $1 \\leq N \\leq 10^5$\n- $0 \\leq A[i] \\leq 10^9$\n\n-----Sample Input:-----\n3\n\n4\n\n7 8 6 4\n\n6\n\n7 3 10 2 3 8\n\n1\n\n10 \n\n-----Sample Output:-----\n4\n\n10\n\n0\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\nimport math\nfor t in range(int(input())):\n n=int(input())\n a=[int(i) for i in input().split()]\n div=sum(a)/n\n div=math.ceil(div)\n count=div*n-sum(a)\n for i in a:\n if i>div:\n count+=i-div\n print(count)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\n4\\n7 8 6 4\\n6\\n7 3 10 2 3 8\\n1\\n10\\n', 'output': '4\\n10\\n0\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/WNTR2020/problems/WC07'}","problem_id":"vfc_1698","program":"```python\n# cook your dish here\nimport math\nfor t in range(int(input())):\n n=int(input())\n a=[int(i) for i in input().split()]\n div=sum(a)/n\n div=math.ceil(div)\n count=div*n-sum(a)\n for i in a:\n if i>div:\n count+=i-div\n print(count)\n```","inputs":"3\n4\n7 8 6 4\n6\n7 3 10 2 3 8\n1\n10\n","output":"4\n10\n0\n","actual_output":"4\n10\n0\n","execution_success":true,"sample_index":322},{"source":"apps","task_type":"verifiable_code","in_source_id":"716","prompt":"Solve the following coding problem using the programming language python:\n\nChef has created a special dividing machine that supports the below given operations on an array of positive integers.\nThere are two operations that Chef implemented on the machine.\nType 0 Operation\n\nUpdate(L,R):\n\tfor i = L to R:\n\t\ta[i] = a[i] / LeastPrimeDivisor(a[i])\n\nType 1 Operation\n\nGet(L,R):\n\tresult = 1\n\tfor i = L to R:\n\t\tresult = max(result, LeastPrimeDivisor(a[i]))\n\treturn result;\n\nThe function LeastPrimeDivisor(x) finds the smallest prime divisor of a number. If the number does not have any prime divisors, then it returns 1.\nChef has provided you an array of size N, on which you have to apply M operations using the special machine. Each operation will be one of the above given two types. Your task is to implement the special dividing machine operations designed by Chef. Chef finds this task quite easy using his machine, do you too?\n\n-----Input-----\n\nThe first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows. \nThe first line of each test case contains two space-separated integers N, M, denoting the size of array A and the number of queries correspondingly.\n\nThe second line of each test case contains N space-separated integers A1, A2, ..., AN denoting the initial array for dividing machine.\nEach of following M lines contain three space-separated integers type, L, R - the type of operation (0 - Update operation, 1 - Get operation), and the arguments of function, respectively\n\n-----Output-----\nFor each test case, output answer of each query of type 1 (Get query) separated by space. Each test case from the same file should start from the new line.\n\n-----Constraints-----\n- 1 \u2264 T \u2264 100\n- 1 \u2264 Ai \u2264 106\n- 1 \u2264 L \u2264 R \u2264 N\n- 0 \u2264 type \u2264 1\n- Sum of M over all test cases in a single test file does not exceed 106\n\n-----Subtasks-----\nSubtask #1: (10 points) \n- 1 \u2264 N, M \u2264 103\n\nSubtask #2: (25 points)\n- 1 \u2264 N, M \u2264 105\n- Ai is a prime number. \n\nSubtask #3: (65 points)\n- 1 \u2264 N, M \u2264 105\n\n-----Example-----\nInput:\n2\n6 7\n2 5 8 10 3 44\n1 2 6\n0 2 3\n1 2 6\n0 4 6\n1 1 6\n0 1 6\n1 4 6\n2 2\n1 3\n0 2 2\n1 1 2\nOutput:\n5 3 5 11\n1\n\n-----Explanation-----\nExample case 1.The states of array A after each Update-operation:\nA: = [2 1 4 10 3 44]\nA: = [2 1 4 5 1 22]\nA: = [1 1 2 1 1 11]\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nimport math\nn=1001\na=[True]*n\nl=[]\nfor i in range(2,33):\n if(a[i]):\n for j in range(i*i,n,i):\n a[j]=False\nfor pr in range(2,1001):\n if(a[pr]):\n l.append(pr)\nt=int(input())\nfor j in range(t):\n n,m=list(map(int,input().strip().split()))\n arr=[int(num) for num in input().strip().split()]\n Matrix =[]\n index=[0]*100000\n factors=[0]*100000\n ans=''\n for r in range(len(arr)):\n li=[]\n for val in l:\n while((arr[r]%val)==0):\n arr[r]=arr[r]/val\n li.append(val)\n factors[r]+=1\n if(arr[r]!=1):\n li.append(arr[r])\n arr[r]=1\n factors[r]+=1\n Matrix.append(li)\n for k in range(m):\n opr=[int(o) for o in input().strip().split()]\n L=opr[1]\n R=opr[2]\n if(opr[0]==0):\n for ran in range(L-1,R):\n if(index[ran]=0:\n if pref[i]-pref[i-r]==k:\n cnt+=1\n i+=1\n else:\n i+=abs(k-(pref[i]-pref[i-r]))\n \n else:\n if pref[i]==k:\n cnt+=1\n i+=1\n else:\n i+=abs(k-(pref[i]))\n k+=1\n print(cnt)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n010001\\n10\\n', 'output': '4\\n1\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/BDGFT'}","problem_id":"vfc_1722","program":"```python\nt = int(input())\nfor _ in range(t):\n s = input()\n pref = [0]*len(s)\n if s[0]==\"1\":\n pref[0]+=1\n for i in range(1,len(s)):\n if s[i]==\"1\":\n pref[i]+=1\n pref[i]=pref[i]+pref[i-1]\n k=1\n cnt=0\n while (k+k*k)<=len(s):\n r = k+k*k\n i=r-1\n while i=0:\n if pref[i]-pref[i-r]==k:\n cnt+=1\n i+=1\n else:\n i+=abs(k-(pref[i]-pref[i-r]))\n \n else:\n if pref[i]==k:\n cnt+=1\n i+=1\n else:\n i+=abs(k-(pref[i]))\n k+=1\n print(cnt)\n```","inputs":"2\n010001\n10\n","output":"4\n1\n","actual_output":"4\n1\n","execution_success":true,"sample_index":327},{"source":"apps","task_type":"verifiable_code","in_source_id":"721","prompt":"Solve the following coding problem using the programming language python:\n\nDo you know that The Chef has a special interest in palindromes? Yes he does! Almost all of the dishes in his restaurant is named by a palindrome strings. The problem is that a name of a dish should not be too long, so The Chef has only limited choices when naming a new dish.\n\nFor the given positive integer N, your task is to calculate the number of palindrome strings of length not exceeding N, that contain only lowercase letters of English alphabet (letters from 'a' to 'z', inclusive). Recall that a palindrome is a string that reads the same left to right as right to left (as in \"radar\").\n\nFor example:\n\n- For N = 1, we have 26 different palindromes of length not exceeding N:\n\"a\", \"b\", ..., \"z\".\n- For N = 2 we have 52 different palindromes of length not exceeding N:\n\"a\", \"b\", ..., \"z\",\n\"aa\", \"bb\", ..., \"zz\".\n- For N = 3 we have 728 different palindromes of length not exceeding N:\n\"a\", \"b\", ..., \"z\",\n\"aa\", \"bb\", ..., \"zz\",\n\"aaa\", \"aba\", ..., \"aza\",\n\"bab\", \"bbb\", ..., \"bzb\",\n...,\n\"zaz\", \"zbz\", ..., \"zzz\".\n\nSince the answer can be quite large you should output it modulo 1000000007 (109 + 7). Yes, we know, most of you already hate this modulo, but there is nothing we can do with it :)\n\n-----Input-----\n\nThe first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows. The only line of each test case contains a single integer N.\n\n-----Output-----\n\nFor each test case, output a single line containing the answer for the corresponding test case.\n\n-----Constrains-----\n\n- 1 \u2264 T \u2264 1000\n- 1 \u2264 N \u2264 109\n\n-----Example-----\nInput:\n5\n1\n2\n3\n4\n100\n\nOutput:\n26\n52\n728\n1404\n508533804\n\n-----Explanation-----\n\nThe first three examples are explained in the problem statement above.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\ndef permutation(n,p):\n r=26\n if n==1:\n return 26\n elif n==2:\n return 52\n elif n==3:\n return 728\n else:\n if n%2==0:\n return ((2*(bin_expo(r,((n//2)+1),p)-r)*bin_expo(25,1000000005,p)))%p\n else:\n n=n+1\n return ((2*((bin_expo(r,(n//2+1),p)-r)*bin_expo(r-1,1000000005,p)))- bin_expo(26,n//2,p))%p\ndef bin_expo(x,n,p):\n if n==0:\n return 1\n elif n==1:\n return x%p\n else:\n temp=bin_expo(x,n//2,p)\n temp=(temp*temp)%p\n if n%2==0:\n return temp\n else:\n return ((x%p)*temp)%p\n\ntest=int(input())\nfor _ in range(test):\n n=int(input())\n p=1000000007\n print(int(permutation(n,p)))\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '5\\n1\\n2\\n3\\n4\\n100\\n\\n\\n', 'output': '26\\n52\\n728\\n1404\\n508533804\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/TAPALIN'}","problem_id":"vfc_1726","program":"```python\n# cook your dish here\ndef permutation(n,p):\n r=26\n if n==1:\n return 26\n elif n==2:\n return 52\n elif n==3:\n return 728\n else:\n if n%2==0:\n return ((2*(bin_expo(r,((n//2)+1),p)-r)*bin_expo(25,1000000005,p)))%p\n else:\n n=n+1\n return ((2*((bin_expo(r,(n//2+1),p)-r)*bin_expo(r-1,1000000005,p)))- bin_expo(26,n//2,p))%p\ndef bin_expo(x,n,p):\n if n==0:\n return 1\n elif n==1:\n return x%p\n else:\n temp=bin_expo(x,n//2,p)\n temp=(temp*temp)%p\n if n%2==0:\n return temp\n else:\n return ((x%p)*temp)%p\n\ntest=int(input())\nfor _ in range(test):\n n=int(input())\n p=1000000007\n print(int(permutation(n,p)))\n```","inputs":"5\n1\n2\n3\n4\n100\n\n\n","output":"26\n52\n728\n1404\n508533804\n","actual_output":"26\n52\n728\n1404\n508533804\n","execution_success":true,"sample_index":328},{"source":"apps","task_type":"verifiable_code","in_source_id":"722","prompt":"Solve the following coding problem using the programming language python:\n\nThe kingdom of the snakes is an NxN grid. Their most-valued possession is a huge collection of poison, which is stored in the central KxK grid. It is guaranteed that both N and K are odd. What we mean by 'central' is this: suppose in the NxN grid, (i, j) refers to the cell in the i-th row and j-th column and (1,1) refers to the top-left corner and (N,N) refers to the bottom-right corner. Then the poison is stored in the KxK square whose top-left corner is ( (N - K)/2 + 1, (N - K)/2 + 1 ).\n\nBut there are thieves who want to steal the poison. They cannot enter the NxN grid, but they can shoot arrows from outside. These arrows travel across a row (from left to right, or right to left), or across a column (top to bottom or bottom to top) in a straight line. If the arrow enters the KxK grid, some of the poison will stick to the arrow, and if it exits the NxN grid after that, the thieves will have successfully stolen some of the poison.\nAs the King of the snakes, you want to thwart these attempts. You know that the arrows will break and stop if they hit a snake's scaly skin, but won't hurt the snakes. There are some snakes already guarding the poison. Each snake occupies some consecutive cells in a straight line inside the NxN grid. That is, they are either part of a row, or part of a column. Note that there can be intersections between the snakes. A configuration of snakes is 'safe', if the thieves cannot steal poison. That is, no matter which row or column they shoot arrows from, either the arrow should hit a snake and stop (this can happen even after it has entered and exited the KxK grid), or it shouldn't ever enter the KxK grid.\nThe King has other duties for the snakes, and hence wants to remove as many snakes as possible from this configuration, such that the remaining configuration is still 'safe'. Help him find the minimum number of snakes he needs to leave behind to protect the poison.\n\n-----Input-----\n- The first line contains a single integer, T, the number of testcases.\n- The first line of each testcase contains three integers: N, K and M, where N is the size of the entire square grid, K is the size of the square containing the poison, and M is the number of initial snakes.\n- M lines follow, the i-th of which contains four integers: HXi, HYi, TXi, TYi. (HXi, HYi) is the cell which contains the head of the i-th snake. (TXi, TYi) is the cell which contains the tail of the i-th snake. It is guaranteed that both these cells will either lie in the same row, or same column. And hence the cells in between them, including these two cells, represents the i-th snake.\n\n-----Output-----\n- For each testcase, output a single integer in a new line: The minimum number of the snakes that the king can keep and still protect the poison. If it is not possible to protect the poison even with all the snakes, output -1.\n\n-----Constraints-----\n- 1 \u2264 T \u2264 4\n- 3 \u2264 N \u2264 109\n- 1 \u2264 K \u2264 N-2\n- Both N and K will be odd integers\n- 1 \u2264 M \u2264 105\n- 1 \u2264 HXi, HYi, TXi, TYi \u2264 N\n- It is guaranteed that at least one of (HXi = TXi), and (HYi = TYi) will be true for all i\n- None of the cells in the KxK grid will be occupied by any snake\n\n-----Example-----\nInput:\n2\n7 3 7\n1 1 6 1\n1 2 3 2\n5 2 5 2\n2 4 2 6\n6 2 6 4\n5 6 5 7\n7 1 7 4\n7 3 7\n1 1 6 1\n1 2 3 2\n5 2 5 2\n2 6 2 6\n6 2 6 4\n5 6 5 7\n7 1 7 4\n\nOutput:\n3\n-1\n\n-----Explanation-----\nThe first example corresponds to:\n\nNote that the top-left corner cell of the NxN grid is by definition, (1,1). The inner square contains the poison, and the seven snakes are shown in different colours. The green snake is the 1st snake in the input.\nWe can remove all but 3 snakes and protect the poison. One such configuration is this:\n\nYou can check that no arrow can enter the inner poison square and exit the outer square without hitting a snake. Hence is it safe. Also, you cannot do this with fewer snakes. Hence 3 is the answer.\nThe second testcase corresponds to:\n\nYou can check that even with all the snakes, this is not a safe configuration, because the thieves can shoot an arrow down the 5th column, and they can steal poison. Hence, the answer is -1.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n'''input\n2\n7 3 5\n5 2 5 2\n2 4 2 6\n6 2 6 4\n5 6 5 7\n7 1 7 4\n7 3 7\n1 1 6 1\n1 2 3 2\n5 2 5 2\n2 6 2 6\n6 2 6 4\n5 6 5 7\n7 1 7 4\n'''\n\nfor _ in range(int(input())):\n n, k, m = list(map(int, input().split()))\n row_s = []\n col_s = []\n for _ in range(m):\n h_x, h_y, t_x, t_y = list(map(int, input().split()))\n if h_x == t_x:\n if (h_x < (((n - k) // 2) + 1)) or (h_x > (((n - k) // 2) + k)):\n col_s.append([min(h_y, t_y), max(h_y, t_y)])\n else:\n row_s.append([h_x, h_x])\n if h_y == t_y:\n if (h_y < (((n - k) // 2) + 1)) or (h_y > (((n - k) // 2) + k)):\n row_s.append([min(h_x, t_x), max(h_x, t_x)])\n else:\n col_s.append([h_y, h_y])\n row_s.sort()\n col_s.sort()\n\n poss = True\n\n if len(col_s) == 0 or len(row_s) == 0:\n print(-1)\n continue\n\n # print(row_s, col_s)\n\n next_row = ((n - k) // 2) + 1\n i = 0\n count_row = 0\n while i < len(row_s):\n max_next = next_row\n if next_row < row_s[i][0]:\n poss = False\n break\n while i < len(row_s) and row_s[i][0] <= next_row:\n # print(max_next, row_s[i], next_row)\n max_next = max(max_next, row_s[i][1] + 1)\n # print(max_next, row_s[i], next_row)\n i += 1\n next_row = max_next\n count_row += 1\n if next_row > (((n - k) // 2) + k):\n break\n if next_row < (((n - k) // 2) + k) and i >= len(row_s) :\n poss = False\n break\n\n # print(count_row)\n\n next_col = ((n - k) // 2) + 1\n i = 0\n count_col = 0\n while i < len(col_s):\n max_next = next_col\n if next_col < col_s[i][0]:\n poss = False\n break\n while i < len(col_s) and col_s[i][0] <= next_col:\n # print(max_next, col_s[i], next_col)\n max_next = max(max_next, col_s[i][1] + 1)\n # print(max_next, col_s[i], next_col)\n i += 1\n next_col = max_next\n count_col += 1\n if next_col > (((n - k) // 2) + k):\n break\n if next_col < (((n - k) // 2) + k) and i >= len(col_s) :\n poss = False\n break\n\n # print(count_col)\n print(count_col + count_row if poss else -1)\n\n # print(row_s, col_s)\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n7 3 7\\n1 1 6 1\\n1 2 3 2\\n5 2 5 2\\n2 4 2 6\\n6 2 6 4\\n5 6 5 7\\n7 1 7 4\\n7 3 7\\n1 1 6 1\\n1 2 3 2\\n5 2 5 2\\n2 6 2 6\\n6 2 6 4\\n5 6 5 7\\n7 1 7 4\\n', 'output': '3\\n-1\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/PROTEPOI'}","problem_id":"vfc_1730","program":"```python\n'''input\n2\n7 3 5\n5 2 5 2\n2 4 2 6\n6 2 6 4\n5 6 5 7\n7 1 7 4\n7 3 7\n1 1 6 1\n1 2 3 2\n5 2 5 2\n2 6 2 6\n6 2 6 4\n5 6 5 7\n7 1 7 4\n'''\n\nfor _ in range(int(input())):\n n, k, m = list(map(int, input().split()))\n row_s = []\n col_s = []\n for _ in range(m):\n h_x, h_y, t_x, t_y = list(map(int, input().split()))\n if h_x == t_x:\n if (h_x < (((n - k) // 2) + 1)) or (h_x > (((n - k) // 2) + k)):\n col_s.append([min(h_y, t_y), max(h_y, t_y)])\n else:\n row_s.append([h_x, h_x])\n if h_y == t_y:\n if (h_y < (((n - k) // 2) + 1)) or (h_y > (((n - k) // 2) + k)):\n row_s.append([min(h_x, t_x), max(h_x, t_x)])\n else:\n col_s.append([h_y, h_y])\n row_s.sort()\n col_s.sort()\n\n poss = True\n\n if len(col_s) == 0 or len(row_s) == 0:\n print(-1)\n continue\n\n # print(row_s, col_s)\n\n next_row = ((n - k) // 2) + 1\n i = 0\n count_row = 0\n while i < len(row_s):\n max_next = next_row\n if next_row < row_s[i][0]:\n poss = False\n break\n while i < len(row_s) and row_s[i][0] <= next_row:\n # print(max_next, row_s[i], next_row)\n max_next = max(max_next, row_s[i][1] + 1)\n # print(max_next, row_s[i], next_row)\n i += 1\n next_row = max_next\n count_row += 1\n if next_row > (((n - k) // 2) + k):\n break\n if next_row < (((n - k) // 2) + k) and i >= len(row_s) :\n poss = False\n break\n\n # print(count_row)\n\n next_col = ((n - k) // 2) + 1\n i = 0\n count_col = 0\n while i < len(col_s):\n max_next = next_col\n if next_col < col_s[i][0]:\n poss = False\n break\n while i < len(col_s) and col_s[i][0] <= next_col:\n # print(max_next, col_s[i], next_col)\n max_next = max(max_next, col_s[i][1] + 1)\n # print(max_next, col_s[i], next_col)\n i += 1\n next_col = max_next\n count_col += 1\n if next_col > (((n - k) // 2) + k):\n break\n if next_col < (((n - k) // 2) + k) and i >= len(col_s) :\n poss = False\n break\n\n # print(count_col)\n print(count_col + count_row if poss else -1)\n\n # print(row_s, col_s)\n\n```","inputs":"2\n7 3 7\n1 1 6 1\n1 2 3 2\n5 2 5 2\n2 4 2 6\n6 2 6 4\n5 6 5 7\n7 1 7 4\n7 3 7\n1 1 6 1\n1 2 3 2\n5 2 5 2\n2 6 2 6\n6 2 6 4\n5 6 5 7\n7 1 7 4\n","output":"3\n-1\n","actual_output":"3\n-1\n","execution_success":true,"sample_index":329},{"source":"apps","task_type":"verifiable_code","in_source_id":"723","prompt":"Solve the following coding problem using the programming language python:\n\nIn this problem, you will be given a polynomial, you have to print what it becomes after differentiation.\n\nFollowing are the rules for differentiation:\n- For a polynomial f(x), its differentiation is defined as f'(x).\n- If a is a constant, then differentiation of af(x) is af'(x).\n- If f(x) = h(x) + g(x) , then f'(x) = h'(x) + g'(x) \n- If f(x) = x n, then f'(x) = nxn-1. This is true for all n \u2260 0 .\n- If f(x) = c, where c is a constant, f'(x) = 0.\n\nIf you are still uncomfortable with differentiation, please read the following:\n- Link to Wikihow page\n- Link to Wikipedia entry.\n\n-----Input-----\n\nFirst line contains T, the number of test cases to follow. \n\nEach test case contains the follows, the first line contains N, the number of non zero terms in the polynomial. Then N lines follow, each line contains a pair of integer which denotes a term in the polynomial, where the first element denotes the coefficient (a) and the second denotes the exponent (p) of the term.\n\n-----Output-----\nPrint the polynomial after differentiation in the desired format as described below.\n- If the coefficient of a term in the output polynomial is 3, and the corresponding exponent is 2, print it as 3x^2\n- Print \" + \" (with single space on both side) between each output term.\n- Print the terms in decreasing value of exponent.\n- For the constant term (if any), you have to just print the coefficient. You should not print x^0.\n\n-----Constraints-----\n- 1 \u2264 T \u2264 10\n- Subtask 1 (20 points)\n\n- 1 \u2264 N \u2264 3\n- 1 \u2264 a \u2264 10\n- 0 \u2264 p \u2264 10\n- Subtask 2 (80 points)\n\n- 1 \u2264 N \u2264 10000\n- 1 \u2264 a \u2264 100000000\n- 0 \u2264 p \u2264 100000000\n- No two inputs in a test case will have the same exponent.\n\n-----Example-----\nInput:\n2\n1\n1 2\n3\n1 3\n1 1\n1 0\n\nOutput:\n2x^1\n3x^2 + 1\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\ndef ans(l):\n s = \"\"\n i = 0\n while (i < len(l)):\n temp = l[i]\n k = temp[1]\n if (k != 0):\n s += str(temp[0]) + \"x^\" + str(k)\n else:\n s += str(temp[0])\n i += 1\n if (i < len(l)):\n s += \" + \"\n if (len(s) > 0):\n return s\n else:\n return \"0\"\n \ntest = int(input())\nwhile (test != 0):\n test -= 1\n N = int(input())\n l = []\n while (N != 0):\n n,m = list(map(int,input().split()))\n if (m > 0):\n l += [[n*m,m-1]]\n N -= 1\n print(ans(l))\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n1\\n1 2\\n3\\n1 3\\n1 1\\n1 0\\n', 'output': '2x^1\\n3x^2 + 1\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/LOCFEB16/problems/POLYDIFR'}","problem_id":"vfc_1734","program":"```python\ndef ans(l):\n s = \"\"\n i = 0\n while (i < len(l)):\n temp = l[i]\n k = temp[1]\n if (k != 0):\n s += str(temp[0]) + \"x^\" + str(k)\n else:\n s += str(temp[0])\n i += 1\n if (i < len(l)):\n s += \" + \"\n if (len(s) > 0):\n return s\n else:\n return \"0\"\n \ntest = int(input())\nwhile (test != 0):\n test -= 1\n N = int(input())\n l = []\n while (N != 0):\n n,m = list(map(int,input().split()))\n if (m > 0):\n l += [[n*m,m-1]]\n N -= 1\n print(ans(l))\n\n```","inputs":"2\n1\n1 2\n3\n1 3\n1 1\n1 0\n","output":"2x^1\n3x^2 + 1\n","actual_output":"2x^1\n3x^2 + 1\n","execution_success":true,"sample_index":330},{"source":"apps","task_type":"verifiable_code","in_source_id":"724","prompt":"Solve the following coding problem using the programming language python:\n\nPetya is preparing a problem for a local contest in his school. The problem is to find a longest increasing subsequence in a given permutation. A permutation of size n$n$ is a sequence of n$n$ numbers a1,\u2026,an$a_1, \\ldots, a_n$ such that every number from 1$1$ to n$n$ occurs in the sequence exactly once. An increasing subsequence of length k$k$ of the sequence a1,\u2026,an$a_1, \\ldots, a_n$ is a sequence of indices i1,\u2026,ik$i_1, \\ldots, i_k$ such that 1\u2264i1<\u20262:\n if ls[0]!=ls[1]-1:\n print(\"NO\")\n continue\n\n ans = [0 for i in range(n+1)]\n count = n\n for i in range(1,a[1]):\n if i != a[0]:\n ans[i] =count\n count-=1\n for i in a[::-1]:\n ans[i] = count\n count-=1\n for i in range(1,n+1):\n if ans[i] == 0:\n ans[i] = count\n count-=1\n print(\"YES\")\n print(*ans[1:])\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n3 2\\n1 2\\n2 1\\n1\\n', 'output': 'YES\\n2 3 1\\nNO\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/INVLIS'}","problem_id":"vfc_1738","program":"```python\n# cook your dish here\nfor _ in range(int(input())):\n n,k = [int(c) for c in input().split()]\n a = [int(c) for c in input().split()]\n ls = a\n if n==1:\n print(\"YES\")\n print(1)\n continue\n if k==1:\n print(\"NO\")\n continue\n \n if k==2 and n>2:\n if ls[0]!=ls[1]-1:\n print(\"NO\")\n continue\n\n ans = [0 for i in range(n+1)]\n count = n\n for i in range(1,a[1]):\n if i != a[0]:\n ans[i] =count\n count-=1\n for i in a[::-1]:\n ans[i] = count\n count-=1\n for i in range(1,n+1):\n if ans[i] == 0:\n ans[i] = count\n count-=1\n print(\"YES\")\n print(*ans[1:])\n```","inputs":"2\n3 2\n1 2\n2 1\n1\n","output":"YES\n2 3 1\nNO\n","actual_output":"YES\n2 3 1\nNO\n","execution_success":true,"sample_index":331},{"source":"apps","task_type":"verifiable_code","in_source_id":"725","prompt":"Solve the following coding problem using the programming language python:\n\nThe Little Elephant and his friends from the Zoo of Lviv were returning from the party. But suddenly they were stopped by the policeman Big Hippo, who wanted to make an alcohol test for elephants.\nThere were N elephants ordered from the left to the right in a row and numbered from 0 to N-1. Let R[i] to be the result of breathalyzer test of i-th elephant.\nConsidering current laws in the Zoo, elephants would be arrested if there exists K consecutive elephants among them for which at least M of these K elephants have the maximal test result among these K elephants.\nUsing poor math notations we can alternatively define this as follows. The elephants would be arrested if there exists i from 0 to N-K, inclusive, such that for at least M different values of j from i to i+K-1, inclusive, we have R[j] = max{R[i], R[i+1], ..., R[i+K-1]}.\n\nThe Big Hippo is very old and the Little Elephant can change some of the results. In a single operation he can add 1 to the result of any elephant. But for each of the elephants he can apply this operation at most once.\nWhat is the minimum number of operations that the Little Elephant needs to apply, such that the sequence of results, after all operations will be applied, let elephants to avoid the arrest? If it is impossible to avoid the arrest applying any number of operations, output -1.\n\n-----Input-----\nThe 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 three space-separated integers N, K, M. The second line contains N space-separated integers R[0], R[1], ..., R[N-1] denoting the test results of the elephants.\n\n-----Output-----\nFor each test case, output a single line containing the minimum number of operations needed to avoid the arrest.\n\n-----Constraints-----\n- 1 \u2264 T \u2264 10\n- 1 \u2264 M \u2264 K \u2264 N \u2264 17\n- 1 \u2264 R[i] \u2264 17\n\n-----Example-----\nInput:\n4\n5 3 2\n1 3 1 2 1\n5 3 3\n7 7 7 7 7\n5 3 3\n7 7 7 8 8\n4 3 1\n1 3 1 2\n\nOutput:\n0\n1\n1\n-1\n\n-----Explanation-----\nExample case 1. Let's follow the poor math definition of arrest. We will consider all values of i from 0 to N-K = 2, inclusive, and should count the number of values of j described in the definition. If it less than M = 2 then this value of i does not cause the arrest, otherwise causes.i{R[i],...,R[i+K-1]}max{R[i],...,R[i+K-1]}For which j = i, ..., i+K-1\nwe have R[j] = maxConclusioni=0{1, 3, 1}max = 3R[j] = 3 for j = 1does not cause the arresti=1{3, 1, 2}max = 3R[j] = 3 for j = 1does not cause the arresti=2{1, 2, 1}max = 2R[j] = 2 for j = 3does not cause the arrest\nSo we see that initial test results of the elephants do not cause their arrest. Hence the Little Elephant does not need to apply any operations. Therefore, the answer is 0.\nExample case 2.We have N = 5, K = 3, M = 3. Let's construct similar table as in example case 1. Here the value of i will cause the arrest if we have at least 3 values of j described in the definition.i{R[i],...,R[i+K-1]}max{R[i],...,R[i+K-1]}For which j = i, ..., i+K-1\nwe have R[j] = maxConclusioni=0{7, 7, 7}max = 7R[j] = 7 for j = 0, 1, 2causes the arresti=1{7, 7, 7}max = 7R[j] = 7 for j = 1, 2, 3causes the arresti=2{7, 7, 7}max = 7R[j] = 7 for j = 2, 3, 4causes the arrest\nSo we see that for initial test results of the elephants each value of i causes their arrest. Hence the Little Elephant needs to apply some operations in order to avoid the arrest. He could achieve his goal by adding 1 to the result R[2]. Then results will be {R[0], R[1], R[2], R[3], R[4]} = {7, 7, 8, 7, 7}. Let's check that now elephants will be not arrested.i{R[i],...,R[i+K-1]}max{R[i],...,R[i+K-1]}For which j = i, ..., i+K-1\nwe have R[j] = maxConclusioni=0{7, 7, 8}max = 8R[j] = 8 for j = 2does not cause the arresti=1{7, 8, 7}max = 8R[j] = 8 for j = 2does not cause the arresti=2{8, 7, 7}max = 8R[j] = 8 for j = 2does not cause the arrest\nSo we see that now test results of the elephants do not cause their arrest. Thus we see that using 0 operations we can't avoid the arrest but using 1 operation can. Hence the answer is 1.\nExample case 3.We have N = 5, K = 3, M = 3. Let's construct similar table as in example case 1. Here the value of i will cause the arrest if we have at least 3 values of j described in the definition.i{R[i],...,R[i+K-1]}max{R[i],...,R[i+K-1]}For which j = i, ..., i+K-1\nwe have R[j] = maxConclusioni=0{7, 7, 7}max = 7R[j] = 7 for j = 0, 1, 2causes the arresti=1{7, 7, 8}max = 8R[j] = 8 for j = 3does not cause the arresti=2{7, 8, 8}max = 8R[j] = 8 for j = 3, 4does not cause the arrest\nSo we see that for initial test results of the elephants the value of i = 0 causes their arrest. Hence the Little Elephant needs to apply some operations in order to avoid the arrest. He could achieve his goal by adding 1 to the result R[1]. Then results will be {R[0], R[1], R[2], R[3], R[4]} = {7, 8, 7, 8, 8}. Let's check that now elephants will be not arrested.i{R[i],...,R[i+K-1]}max{R[i],...,R[i+K-1]}For which j = i, ..., i+K-1\nwe have R[j] = maxConclusioni=0{7, 8, 7}max = 8R[j] = 8 for j = 1does not cause the arresti=1{8, 7, 8}max = 8R[j] = 8 for j = 1, 3does not cause the arresti=2{7, 8, 8}max = 8R[j] = 8 for j = 3, 4does not cause the arrest\nSo we see that now test results of the elephants do not cause their arrest. Thus we see that using 0 operations we can't avoid the arrest but using 1 operation can. Hence the answer is 1. Note that if we increase by 1 the result R[2] instead of R[1] then the value i = 2 will cause the arrest since {R[2], R[3], R[4]} will be {8, 8, 8} after this operation and we will have 3 values of j from 2 to 4, inclusive, for which R[j] = max{R[2], R[3], R[4]}, namely, j = 2, 3, 4.\nExample case 4. When M = 1 the Little Elephant can't reach the goal since for each value of i from 0 to N-K we have at least one value of j for which R[j] = max{R[i], R[i+1], ..., R[i+K-1]}.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\ndef magic():\n def check(art,k,m):\n n=len(art)\n for i in range(n-k+1):\n maxi=0\n maxi=max(art[i:i+k])\n\n total=0\n total=art[i:i+k].count(maxi)\n\n if total>=m:\n return False\n\n return True\n \n\n\n for _ in range(eval(input())):\n n,k,m=list(map(int,input().split()))\n arr=list(map(int,input().split()))\n dp=[]\n ans=100\n\n for mask in range(0,(1<size:\n art=list(arr)\n for i in range(n):\n if mask & (1<=m:\n return False\n\n return True\n \n\n\n for _ in range(eval(input())):\n n,k,m=list(map(int,input().split()))\n arr=list(map(int,input().split()))\n dp=[]\n ans=100\n\n for mask in range(0,(1<size:\n art=list(arr)\n for i in range(n):\n if mask & (1<0:\n n=int(input())\n li=[]\n c,o,d,e,h,f=0,0,0,0,0,0\n for i in range(0,n):\n s=input()\n \n for i in range(len(s)):\n if s[i]=='c':\n c=c+1\n elif s[i]=='o':\n o=o+1\n elif s[i]=='d':\n d=d+1\n elif s[i]=='e':\n e=e+1\n elif s[i]=='h':\n h=h+1\n elif s[i]=='f':\n f=f+1\n e=e//2\n c=c//2\n print(min(c,o,d,e,h,f)) \n t-=1\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\n6\\ncplusplus\\noscar\\ndeck\\nfee\\nhat\\nnear\\n5\\ncode\\nhacker\\nchef\\nchaby\\ndumbofe\\n5\\ncodechef\\nchefcode\\nfehcedoc\\ncceeohfd\\ncodechef\\n', 'output': '1\\n2\\n5\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/CFMM'}","problem_id":"vfc_1746","program":"```python\n# cook your dish here\nt=int(input())\nwhile t>0:\n n=int(input())\n li=[]\n c,o,d,e,h,f=0,0,0,0,0,0\n for i in range(0,n):\n s=input()\n \n for i in range(len(s)):\n if s[i]=='c':\n c=c+1\n elif s[i]=='o':\n o=o+1\n elif s[i]=='d':\n d=d+1\n elif s[i]=='e':\n e=e+1\n elif s[i]=='h':\n h=h+1\n elif s[i]=='f':\n f=f+1\n e=e//2\n c=c//2\n print(min(c,o,d,e,h,f)) \n t-=1\n```","inputs":"3\n6\ncplusplus\noscar\ndeck\nfee\nhat\nnear\n5\ncode\nhacker\nchef\nchaby\ndumbofe\n5\ncodechef\nchefcode\nfehcedoc\ncceeohfd\ncodechef\n","output":"1\n2\n5\n","actual_output":"1\n2\n5\n","execution_success":true,"sample_index":333},{"source":"apps","task_type":"verifiable_code","in_source_id":"728","prompt":"Solve the following coding problem using the programming language python:\n\nGiven a square matrix of size N\u00d7N, calculate the absolute difference between the sums of its diagonals. \n\n-----Input-----\nThe first line contains a single integer N. The next N lines denote the matrix's rows, with each line containing N space-separated integers describing the columns.\n\n-----Output-----\nPrint the absolute difference between the two sums of the matrix's diagonals as a single integer.\n\n-----Constraints-----\n1<=N<=10\n\n-----Example-----\nInput:\n3\n11 2 4\n4 5 6\n10 8 -12\n\nOutput:\n15\n\n-----Explanation-----\nThe primary diagonal is: \n11\n5\n-12\nSum across the primary diagonal: 11 + 5 - 12 = 4\nThe secondary diagonal is:\n4\n5\n10\nSum across the secondary diagonal: 4 + 5 + 10 = 19 \nDifference: |4 - 19| = 15\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\ndef diagonal_difference(matrix):\n l = sum(matrix[i][i] for i in range(N))\n r = sum(matrix[i][N-i-1] for i in range(N))\n return abs(l - r)\n\nmatrix = []\nN = eval(input())\nfor _ in range(N):\n matrix.append(list(map(int, input().split())))\n\nprint(diagonal_difference(matrix))\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\n11 2 4\\n4 5 6\\n10 8 -12\\n', 'output': '15\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/COFI2016/problems/CF212'}","problem_id":"vfc_1754","program":"```python\ndef diagonal_difference(matrix):\n l = sum(matrix[i][i] for i in range(N))\n r = sum(matrix[i][N-i-1] for i in range(N))\n return abs(l - r)\n\nmatrix = []\nN = eval(input())\nfor _ in range(N):\n matrix.append(list(map(int, input().split())))\n\nprint(diagonal_difference(matrix))\n```","inputs":"3\n11 2 4\n4 5 6\n10 8 -12\n","output":"15\n","actual_output":"15\n","execution_success":true,"sample_index":335},{"source":"apps","task_type":"verifiable_code","in_source_id":"732","prompt":"Solve the following coding problem using the programming language python:\n\nAlice and Bob are walking on an infinite straight street. Initially, both are at the position $X=0$ and they start walking in the direction of increasing $X$. After $N$ seconds, they stop. Let's denote Alice's speed and Bob's speed during the $i$-th of these seconds by $A_i$ and $B_i$ respectively.\nSometimes, Alice and Bob walk together, i.e. with the same speed side by side. Let's define the weird distance as the total distance they walk this way. Find this weird distance.\n\n-----Input-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The first line of each test case contains a single integer $N$.\n- The second line contains $N$ space-separated integers $A_1, A_2, \\ldots, A_N$.\n- The third line contains $N$ space-separated integers $B_1, B_2, \\ldots, B_N$.\n\n-----Output-----\nFor each test case, print a single line containing one integer \u2015 the total weird distance. It can be proved that this distance is an integer.\n\n-----Constraints-----\n- $1 \\le T \\le 20$\n- $1 \\le N \\le 10^5$\n- $1 \\le A_i \\le 10^5$ for each valid $i$\n- $1 \\le B_i \\le 10^5$ for each valid $i$\n- the sum of $N$ over all test cases does not exceed $10^6$\n\n-----Subtasks-----\nSubtask #1 (30 points): $1 \\le N \\le 1,000$\nSubtask #2 (70 points): original constraints\n\n-----Example Input-----\n3\n4\n1 3 3 4\n1 2 4 4\n2\n2 3\n3 2\n2\n3 3\n3 3\n\n-----Example Output-----\n5\n0\n6\n\n-----Explanation-----\nExample case 1:\n- Alice and Bob walk side by side during the first second, from $X=0$ to $X=1$.\n- Then, Alice starts walking faster than Bob, so they do not walk side by side during second $2$. At the end of second $2$, Alice is at $X=4$, while Bob is at $X=3$.\n- During the next second, they again do not walk side by side, but Bob walks faster, so they both end up at $X=7$.\n- During the last second, they both walk side by side and the distance they walk is $4$.\n- Alice and Bob walk side by side during the $1$-st and $4$-th second and the total weird distance they travel is $1+4=5$.\nExample case 2:\n- First, Alice walks with speed $2$ and Bob walks with speed $3$, so they do not walk side by side. Alice ends up at $X=2$, while Bob ends up at $X=3$ at the end of the $1$-st second.\n- Then, Alice walks with speed $3$ and Bob walks with speed $2$, so they do not walk side by side either.\n- Although Alice and Bob both end up at $X=5$ at the end of the $2$-nd second, the weird distance is $0$.\nExample case 3: We can see that Alice and Bob always walk together, so the weird distance is $3+3=6$.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\nfor tc in range(int(input())):\n \n n = int(input())\n \n li1 = list(map(int,input().split(' ')))\n li2 = list(map(int,input().split(' ')))\n walk = 0\n sum1 = 0 \n sum2 = 0\n for i in range(n):\n if li1[i] == li2[i] and sum1 == sum2:\n walk += li1[i]\n sum1 += li1[i]\n sum2 += li2[i]\n print(walk)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\n4\\n1 3 3 4\\n1 2 4 4\\n2\\n2 3\\n3 2\\n2\\n3 3\\n3 3\\n', 'output': '5\\n0\\n6\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/WWALK'}","problem_id":"vfc_1770","program":"```python\n# cook your dish here\nfor tc in range(int(input())):\n \n n = int(input())\n \n li1 = list(map(int,input().split(' ')))\n li2 = list(map(int,input().split(' ')))\n walk = 0\n sum1 = 0 \n sum2 = 0\n for i in range(n):\n if li1[i] == li2[i] and sum1 == sum2:\n walk += li1[i]\n sum1 += li1[i]\n sum2 += li2[i]\n print(walk)\n```","inputs":"3\n4\n1 3 3 4\n1 2 4 4\n2\n2 3\n3 2\n2\n3 3\n3 3\n","output":"5\n0\n6\n","actual_output":"5\n0\n6\n","execution_success":true,"sample_index":339},{"source":"apps","task_type":"verifiable_code","in_source_id":"733","prompt":"Solve the following coding problem using the programming language python:\n\nGiven a string consisting of only lowercase English alphabets, your task is to find the smallest palindromic substring.\nIn case there are multiple palindromic substrings of the same length present, print the lexicographically smallest substring. \nFormally, a substring is a contiguous sequence of characters within a string. So in a string \"abcdef\", \"abc\" is a substring whereas \"adf\" is not a substring.\nA palindrome is a word, phrase, or sequence that reads the same backwards as forwards, e.g. madam or mom.\n\n-----Input:-----\n- First-line will contain $T$, the number of test cases. Then the test cases follow. \n- Each test case contains of two lines of input, two integers.\n- First, we have a single integer $N$ which signifies the length of the substring.\n- Next, we have a string of length $N$ that only has lowercase English alphabets.\n\n-----Output:-----\nFor each testcase, output in a single line the shortest palindromic substring.\n\n-----Constraints-----\n- $1 \\leq T \\leq 100$\n- $2 \\leq N \\leq 10^5$\n\n-----Sample Input:-----\n2\n2\nzy\n1\ncd\n\n-----Sample Output:-----\ny\nc\n\n-----EXPLANATION:-----\nThere are only two possibilities. \"z\" and \"y\". Since both of them have the same length. We print the lexicographically smaller substring which is y.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\nT = int(input())\nfor t in range(T):\n N = int(input())\n s = sorted(list(str(input())))\n print(s[0])\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n2\\nzy\\n1\\ncd\\n', 'output': 'y\\nc\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/ENCD2020/problems/ECAPR201'}","problem_id":"vfc_1774","program":"```python\n# cook your dish here\nT = int(input())\nfor t in range(T):\n N = int(input())\n s = sorted(list(str(input())))\n print(s[0])\n```","inputs":"2\n2\nzy\n1\ncd\n","output":"y\nc\n","actual_output":"y\nc\n","execution_success":true,"sample_index":340},{"source":"apps","task_type":"verifiable_code","in_source_id":"735","prompt":"Solve the following coding problem using the programming language python:\n\nHarish has decided to go to Arya's hotel this morning. We all know he is crazy for masala dosas. And as usual he is always hungry. He decided to order all the masala dosas at once. But then he realised that he did not have enough money to buy all of them. So he decided to share the amount with his friend Ozil. But both of them are fans of even numbers. Both of them says they want to eat even number of dosas. Ozil is ready to put the share if and only if , he is sure that he can get even number of dosas. So given N number of dosas can you please help Harish to decide, if he will be able to get all the dosas at once from the hotel.\n\n-----Input-----\nThe first line of input contains an integer T which denotes the number of test files. Next T lines contains an integer N where N is the total number of dosas.\n\n-----Output-----\nPrint \"YES\" if both can get even number of dosas. If it is not possible print \"NO\".\n\n-----Constraints-----\n- 1 \u2264 T \u2264 10^6\n- 1 \u2264 N \u2264 10^18\n\n-----Subtasks-----\nSubtask #1 : (20 points)\n- 1 \u2264 T \u2264 10\n- 1 \u2264 N\u2264 100\n\nSubtask 2 : (80 points) \n\n- 1 \u2264 T \u2264 10^6\n- 1 \u2264 N\u2264 10^18\n\n-----Example-----\nInput:\n2 \n16 \n27\nOutput:\nYES\nNO\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfor _ in range(eval(input())):\n n=eval(input())\n if n%2:\n print('NO')\n else:\n print('YES') \n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n16\\n27\\n', 'output': 'YES\\nNO\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/LOCMAY16/problems/MDOSA'}","problem_id":"vfc_1782","program":"```python\nfor _ in range(eval(input())):\n n=eval(input())\n if n%2:\n print('NO')\n else:\n print('YES') \n```","inputs":"2\n16\n27\n","output":"YES\nNO\n","actual_output":"YES\nNO\n","execution_success":true,"sample_index":342},{"source":"apps","task_type":"verifiable_code","in_source_id":"736","prompt":"Solve the following coding problem using the programming language python:\n\nGargi is thinking of a solution to a problem. Meanwhile, her friend asks her to solve another problem. Since Gargi is busy in her own problem, she seeks your help to solve the new problem.\n\nYou are given a string S containing characters a-z (lower case letters) only. You need to change the string to a new string consisting of only one letter from a-z.\n\nFor a given character S[i] in the string, if you change it to a character having lower ASCII value than the character S[i], you gain points equal to the difference in ASCII value of the old character and the new character. Similarly, for a given character S[j] in the string, if you change it to a character having higher ASCII value than the character S[j], you lose points equal to the difference in ASCII value of the old character and the new character.\n\nHowever, Gargi does not like gaining or losing points. She has asked you to change the string in such a way that the total losing or gaining of points at the end of the string conversion is minimum.\n\nGive Gargi the absolute value of the points you have at the end of the string conversion.\n\n-----Input-----\nThe first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.\n\nThe first line of each of the T test case contains a string S containing only lower case characters (a-z)\n\n-----Output-----\nFor each test case, output a single line containing the answer.\n\n-----Constraints-----\n- 1 \u2264 T \u2264 10\n- 1 \u2264 |S| \u2264 100000\n\n-----Example-----\nInput:\n1\nabba\n\nOutput:\n2\n\n-----Explanation-----\nExample case 1. The new string can be aaaa where you have +2 points at the end of string conversion or it can be bbbb where you have -2 points at the end of string conversion. Hence the output is 2.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nt = int(input())\nfor i in range(t):\n s = input().rstrip()\n sumv = 0\n for j in range(len(s)):\n sumv += ord(s[j])\n minv = 10 ** 8;\n for i in range(ord('a'), ord('z') + 1):\n val = abs(sumv - i * len(s))\n if minv > val:\n minv = val\n print(minv)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\nabba\\n', 'output': '2\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/RECJ1601/problems/SIDSTR'}","problem_id":"vfc_1786","program":"```python\nt = int(input())\nfor i in range(t):\n s = input().rstrip()\n sumv = 0\n for j in range(len(s)):\n sumv += ord(s[j])\n minv = 10 ** 8;\n for i in range(ord('a'), ord('z') + 1):\n val = abs(sumv - i * len(s))\n if minv > val:\n minv = val\n print(minv)\n```","inputs":"1\nabba\n","output":"2\n","actual_output":"2\n","execution_success":true,"sample_index":343},{"source":"apps","task_type":"verifiable_code","in_source_id":"738","prompt":"Solve the following coding problem using the programming language python:\n\nCalculate the power of an army of numbers from 1 to $N$, both included.\n\n-----Input:-----\n- First line will contain a single integer $N$.\n\n-----Output:-----\nFor each testcase, output in a single line containing the answer.\n\n-----Constraints-----\n- $1 \\leq N \\leq 5000$\n\n-----Sample Input:-----\n24\n\n-----Sample Output:-----\n5\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\n# cook your dish here\n#powerful numbers\nn = int(input())\nplist = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313]\npower = 1\nfor i in range(2,n+1,1):\n pdiv = []\n count = 0\n for p in plist:\n if i>=p and i%p==0:\n pdiv.append(p)\n for pd in pdiv:\n if i%(pd**2)==0:\n count+=1\n if count==len(pdiv) and count!=0:\n power+=1\n\n \n \nprint(power)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '24\\n', 'output': '5\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/FULU2020/problems/ARMY1N'}","problem_id":"vfc_1794","program":"```python\n# cook your dish here\n# cook your dish here\n#powerful numbers\nn = int(input())\nplist = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313]\npower = 1\nfor i in range(2,n+1,1):\n pdiv = []\n count = 0\n for p in plist:\n if i>=p and i%p==0:\n pdiv.append(p)\n for pd in pdiv:\n if i%(pd**2)==0:\n count+=1\n if count==len(pdiv) and count!=0:\n power+=1\n\n \n \nprint(power)\n```","inputs":"24\n","output":"5\n","actual_output":"5\n","execution_success":true,"sample_index":345},{"source":"apps","task_type":"verifiable_code","in_source_id":"739","prompt":"Solve the following coding problem using the programming language python:\n\nMr. X stays in a mansion whose door opens in the North. He travels every morning to meet his friend Ms. Y walking a predefined path.\n\nTo cut the distance short, one day he decides to construct a skywalk from his place to his friend\u2019s place. Help him to find the shortest distance between the two residences.\n\n\n-----Input-----\n\nThe first line contains a single positive integer T <= 100, the number of test cases. T test cases follow. The only line of each test case contains a string which is the path from X to Y. The integer value represents the distance. The character R or L represents a Right or a Left respectively.\n\n-----Output-----\n\nFor each test case, output a single line containing the minimum distance and the direction(N,S,W,E,NE,NW,SE,SW) of Y\u2019s residence with respect to X\u2019s residence. The output distance should have only 1 decimal place with no approximation. Print \u201c0.0\u201d if X\u2019s and Y\u2019s residence coincide.\n\n-----Example-----\nInput:\n1\n2 L 2 R 2 L 1\n\nOutput:\n5.0NW\n\nExplanation\nMr. X travels 2units and then takes a Left, and then he travels 2units and takes a Right, then after travelling 2units he takes a Left and finally travels 1unit to reach Y\u2019s residence.\n(Unlike Input, Output does not have spaces between the distance and direction)\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n#!/usr/bin/env python\n\nfrom math import sqrt\n\ndef process(S):\n P = [0,0,'S']\n for i in S:\n if i == 'L':\n if P[-1] == 'N': P[-1] = 'W'\n elif P[-1] == 'S': P[-1] = 'E'\n elif P[-1] == 'E': P[-1] = 'N'\n elif P[-1] == 'W': P[-1] = 'S'\n elif i == 'R':\n if P[-1] == 'N': P[-1] = 'E'\n elif P[-1] == 'S': P[-1] = 'W'\n elif P[-1] == 'E': P[-1] = 'S'\n elif P[-1] == 'W': P[-1] = 'N'\n else:\n i = int(i)\n if P[-1] == 'N': P[1] -= i\n elif P[-1] == 'S': P[1] += i\n elif P[-1] == 'E': P[0] += i\n elif P[-1] == 'W': P[0] -= i\n #print i, P\n DIST = sqrt(P[0]**2+P[1]**2)\n\n if P[0] == 0 and P[1] == 0: DIR = ''\n elif P[0] == 0 and P[1] < 0: DIR = 'S'\n elif P[0] == 0 and P[1] > 0: DIR = 'N'\n elif P[0] < 0 and P[1] == 0: DIR = 'E'\n elif P[0] < 0 and P[1] < 0: DIR = 'SE'\n elif P[0] < 0 and P[1] > 0: DIR = 'NE'\n elif P[0] > 0 and P[1] == 0: DIR = 'W'\n elif P[0] > 0 and P[1] < 0: DIR = 'SW'\n elif P[0] > 0 and P[1] > 0: DIR = 'NW'\n\n DIST = int(DIST*10.)/10. # TOLD NO APPROXIMATION\n\n return '%.1f%s' % (DIST, DIR)\n\ndef main():\n T = int(input())\n for t in range(T):\n S = input().split()\n print(process(S))\n\nmain()\n\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n2 L 2 R 2 L 1\\n', 'output': '5.0NW\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/COZL2012/problems/RBX12R01'}","problem_id":"vfc_1798","program":"```python\n#!/usr/bin/env python\n\nfrom math import sqrt\n\ndef process(S):\n P = [0,0,'S']\n for i in S:\n if i == 'L':\n if P[-1] == 'N': P[-1] = 'W'\n elif P[-1] == 'S': P[-1] = 'E'\n elif P[-1] == 'E': P[-1] = 'N'\n elif P[-1] == 'W': P[-1] = 'S'\n elif i == 'R':\n if P[-1] == 'N': P[-1] = 'E'\n elif P[-1] == 'S': P[-1] = 'W'\n elif P[-1] == 'E': P[-1] = 'S'\n elif P[-1] == 'W': P[-1] = 'N'\n else:\n i = int(i)\n if P[-1] == 'N': P[1] -= i\n elif P[-1] == 'S': P[1] += i\n elif P[-1] == 'E': P[0] += i\n elif P[-1] == 'W': P[0] -= i\n #print i, P\n DIST = sqrt(P[0]**2+P[1]**2)\n\n if P[0] == 0 and P[1] == 0: DIR = ''\n elif P[0] == 0 and P[1] < 0: DIR = 'S'\n elif P[0] == 0 and P[1] > 0: DIR = 'N'\n elif P[0] < 0 and P[1] == 0: DIR = 'E'\n elif P[0] < 0 and P[1] < 0: DIR = 'SE'\n elif P[0] < 0 and P[1] > 0: DIR = 'NE'\n elif P[0] > 0 and P[1] == 0: DIR = 'W'\n elif P[0] > 0 and P[1] < 0: DIR = 'SW'\n elif P[0] > 0 and P[1] > 0: DIR = 'NW'\n\n DIST = int(DIST*10.)/10. # TOLD NO APPROXIMATION\n\n return '%.1f%s' % (DIST, DIR)\n\ndef main():\n T = int(input())\n for t in range(T):\n S = input().split()\n print(process(S))\n\nmain()\n\n\n```","inputs":"1\n2 L 2 R 2 L 1\n","output":"5.0NW\n","actual_output":"5.0NW\n","execution_success":true,"sample_index":346},{"source":"apps","task_type":"verifiable_code","in_source_id":"740","prompt":"Solve the following coding problem using the programming language python:\n\nThere is a field with plants \u2014 a grid with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$); out of its $NM$ cells, $K$ cells contain plants, while the rest contain weeds. Two cells are adjacent if they have a common side.\nYou want to build fences in the field in such a way that the following conditions hold for each cell that contains a plant:\n- it is possible to move from this cell to each adjacent cell containing a plant without crossing any fences\n- it is impossible to move from this cell to any cell containing weeds or to leave the grid without crossing any fences\nThe fences can only be built between cells or on the boundary of the grid, i.e. on the sides of cells. The total length of the built fences is the number of pairs of side-adjacent cells such that there is a fence built on their common side plus the number of sides of cells on the boundary of the grid which have fences built on them. Find the minimum required total length of fences that need to be built.\n\n-----Input-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The first line of each test case contains three space-separated integers $N$, $M$ and $K$.\n- $K$ lines follow. Each of these lines contains two space-separated integers $r$ and $c$ denoting that the cell in row $r$ and column $c$ contains a plant.\n\n-----Output-----\nFor each test case, print a single line containing one integer \u2014 the minimum required length of fences.\n\n-----Constraints-----\n- $1 \\le T \\le 10$\n- $1 \\le N, M \\le 10^9$\n- $1 \\le K \\le 10^5$\n- $1 \\le r \\le N$\n- $1 \\le c \\le M$\n- the cells containing plants are pairwise distinct\n\n-----Subtasks-----\nSubtask #1 (30 points): $1 \\le N, M \\le 1,000$\nSubtask #2 (70 points): original constraints\n\n-----Example Input-----\n2\n4 4 9\n1 4\n2 1 \n2 2\n2 3\n3 1\n3 3\n4 1\n4 2\n4 3\n4 4 1\n1 1\n\n-----Example Output-----\n20\n4\n\n-----Explanation-----\nExample case 1: The field looks like this ('x' denotes a cell containing a plant, '.' denotes a cell containing weeds):\n...x\nxxx.\nx.x.\nxxx.\n\nAn optimal solution is to build fences around the topmost plant (with length $4$), around the remaining eight plants (with length $12$) and around the hole between them (with length $4$). The total length is $4+12+4 = 20$.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nt=int(input())\nwhile(t):\n t-=1\n d={}\n n,m,k=[int(x) for x in list(input().split())]\n sum=0\n while(k):\n k-=1\n x,y=[int(x) for x in list(input().split())]\n a=[-1,1,0,0]\n b=[0,0,-1,1]\n for i in range(4):\n if((x+a[i],y+b[i]) in d):\n sum-=1\n else:\n sum+=1\n d[(x,y)]=1\n print(sum)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n4 4 9\\n1 4\\n2 1\\n2 2\\n2 3\\n3 1\\n3 3\\n4 1\\n4 2\\n4 3\\n4 4 1\\n1 1\\n', 'output': '20\\n4\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/FENCE'}","problem_id":"vfc_1802","program":"```python\nt=int(input())\nwhile(t):\n t-=1\n d={}\n n,m,k=[int(x) for x in list(input().split())]\n sum=0\n while(k):\n k-=1\n x,y=[int(x) for x in list(input().split())]\n a=[-1,1,0,0]\n b=[0,0,-1,1]\n for i in range(4):\n if((x+a[i],y+b[i]) in d):\n sum-=1\n else:\n sum+=1\n d[(x,y)]=1\n print(sum)\n```","inputs":"2\n4 4 9\n1 4\n2 1\n2 2\n2 3\n3 1\n3 3\n4 1\n4 2\n4 3\n4 4 1\n1 1\n","output":"20\n4\n","actual_output":"20\n4\n","execution_success":true,"sample_index":347},{"source":"apps","task_type":"verifiable_code","in_source_id":"742","prompt":"Solve the following coding problem using the programming language python:\n\nRakesh has built a model rocket and wants to test how stable it is. He usually uses a magic box which runs some tests on the rocket and tells if it is stable or not, but his friend broke it by trying to find out how stable he is (very delicate magic indeed). The box only gives a polynomial equation now which can help Rakesh find the stability (a failsafe by the manufacturers). \n\nRakesh reads the manual for the magic box and understands that in order to determine stability, he needs to take every other term and put them in two rows. Eg. If the polynomial is:\n10 x^4 + 12 x^3 + 4 x^2 + 5 x + 3, the first two rows will be: \n\nRow 1: 10 4 3\n\nRow 2: 12 5 0\n\nFor all other rows, the nth element of the rth row is found recursively by multiplying the 1st element of the (r-1)th row and (n+1)th element of the (r-2)th row and subtracting it with 1st element of the (r-2)th row multiplied by (n+1)th element of the (r-1)th row.\n\nSo Row 3 will be (12 * 4 - 10 * 5) (12 * 3 - 10 * 0)\n\nRow 3: -2 36 0\n\nRow 4: -442 0 0\n\nRow 5: -15912 0 0\n\nThere will not be any row six (number of rows = maximum power of x + 1)\n\nThe rocket is stable if there are no sign changes in the first column. \n\nIf all the elements of the rth row are 0, replace the nth element of the rth row by the nth element of the (r-1)th row multiplied by (maximum power of x + 4 - r - 2n).\n\nIf the first element of any row is 0 and some of the other elements are non zero, the rocket is unstable.\n\nCan you help Rakesh check if his rocket is stable?\n\nInput Format:\n\n1. First row with number of test cases (T).\n\n2. Next T rows with the coefficients of the polynomials for each case (10 12 4 5 3 for the case above).\n\nOutput Format:\n\n1. \"1\" if stable (without \"\")\n\n2. \"0\" if unstable (without \"\")\n\nSample Input: \n\n1\n\n10 12 4 5 3\n\nSample Output:\n\n0\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nimport random\n\ndef sign(i):\n if i>0:\n return 1\n elif i<=0:\n return 0\nbleh = []\nfor _ in range(int(input())):\n p = list(map(int,input().rstrip().split()))\n max_rows = len(p)\n if all([x==0 for x in p]):\n print(1)\n continue\n if max_rows <= 1:\n bleh.append(max_rows)\n continue\n max_pow = max_rows-1\n if len(p)%2 !=0 and len(p)>0:\n p.append(0)\n max_col = len(p)//2\n \n rows = [[0 for _ in range(max_col)] for _ in range(max_rows)]\n rows[0] = p[::2]\n rows[1] = p[1::2]\n if sign(rows[0][0]) != sign(rows[1][0]):\n print(0)\n continue\n \n for r in range(2,max_rows):\n for n in range(max_col-1):\n rows[r][n] = rows[r-1][0]*rows[r-2][n+1]-rows[r-2][0]*rows[r-1][n+1]\n \n last = sign(rows[0][0])\n flag = 1\n for i in range(1,len(rows)):\n curr = sign(rows[i][0])\n if rows[r] == [0 for _ in range(max_col)]:\n for n in range(max_col):\n rows[r][n] = rows[r-1][n]*(max_pow+4-(r+1)-2*(n+1)) \n \n elif rows[i][0] == 0:\n if any([x != 0 for x in rows[i]]):\n flag = 0\n break\n else:\n curr = last\n if curr != last:\n flag = 0\n break\n last = curr \n print(flag)\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n10 12 4 5 3\\n', 'output': '0\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/CUBE2020/problems/STROCK'}","problem_id":"vfc_1810","program":"```python\nimport random\n\ndef sign(i):\n if i>0:\n return 1\n elif i<=0:\n return 0\nbleh = []\nfor _ in range(int(input())):\n p = list(map(int,input().rstrip().split()))\n max_rows = len(p)\n if all([x==0 for x in p]):\n print(1)\n continue\n if max_rows <= 1:\n bleh.append(max_rows)\n continue\n max_pow = max_rows-1\n if len(p)%2 !=0 and len(p)>0:\n p.append(0)\n max_col = len(p)//2\n \n rows = [[0 for _ in range(max_col)] for _ in range(max_rows)]\n rows[0] = p[::2]\n rows[1] = p[1::2]\n if sign(rows[0][0]) != sign(rows[1][0]):\n print(0)\n continue\n \n for r in range(2,max_rows):\n for n in range(max_col-1):\n rows[r][n] = rows[r-1][0]*rows[r-2][n+1]-rows[r-2][0]*rows[r-1][n+1]\n \n last = sign(rows[0][0])\n flag = 1\n for i in range(1,len(rows)):\n curr = sign(rows[i][0])\n if rows[r] == [0 for _ in range(max_col)]:\n for n in range(max_col):\n rows[r][n] = rows[r-1][n]*(max_pow+4-(r+1)-2*(n+1)) \n \n elif rows[i][0] == 0:\n if any([x != 0 for x in rows[i]]):\n flag = 0\n break\n else:\n curr = last\n if curr != last:\n flag = 0\n break\n last = curr \n print(flag)\n\n```","inputs":"1\n10 12 4 5 3\n","output":"0\n","actual_output":"0\n","execution_success":true,"sample_index":349},{"source":"apps","task_type":"verifiable_code","in_source_id":"743","prompt":"Solve the following coding problem using the programming language python:\n\nYesterday, Chef found $K$ empty boxes in the cooler and decided to fill them with apples. He ordered $N$ apples, where $N$ is a multiple of $K$. Now, he just needs to hire someone who will distribute the apples into the boxes with professional passion. \nOnly two candidates passed all the interviews for the box filling job. In one minute, each candidate can put $K$ apples into boxes, but they do it in different ways: the first candidate puts exactly one apple in each box, while the second one chooses a random box with the smallest number of apples and puts $K$ apples in it.\nChef is wondering if the final distribution of apples can even depend on which candidate he hires. Can you answer that question?\nNote: The boxes are distinguishable (labeled), while the apples are not. Therefore, two distributions of apples are different if there is a box such that the number of apples in it when the first candidate finishes working can be different from the number of apples in it when the second candidate finishes working.\n\n-----Input-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The first and only line of each test case contains two space-separated integers $N$ and $K$. \n\n-----Output-----\nFor each test case, print a single line containing the string \"YES\" if the final distributions of apples can be different or \"NO\" if they will be the same (without quotes).\n\n-----Constraints-----\n- $1 \\le T \\le 250$\n- $1 \\le N, K \\le 10^{18}$\n- $N$ is divisible by $K$\n\n-----Subtasks-----\nSubtask #1 (30 points): $1 \\le N, K \\le 10^5$\nSubtask #2 (70 points): original constraints\n\n-----Example Input-----\n3\n5 1\n4 2\n10 10\n\n-----Example Output-----\nNO\nNO\nYES\n\n-----Explanation-----\nExample case 1: No matter who is hired, all apples will be in the only box at the end.\nExample case 2: At the end, there will be two apples in each box.\nExample case 3: If we hire the first candidate, there will be one apple in each box, but if we hire the second one, there will be $10$ apples in one box and none in all other boxes.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\nt=int(input())\nfor i in range(t,0,-1):\n x,y=map(int,input().split())\n k=x//y\n \n if k%y==0:\n print(\"NO\")\n else:\n print(\"YES\")\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\n5 1\\n4 2\\n10 10\\n', 'output': 'NO\\nNO\\nYES\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/DSTAPLS'}","problem_id":"vfc_1814","program":"```python\n# cook your dish here\nt=int(input())\nfor i in range(t,0,-1):\n x,y=map(int,input().split())\n k=x//y\n \n if k%y==0:\n print(\"NO\")\n else:\n print(\"YES\")\n```","inputs":"3\n5 1\n4 2\n10 10\n","output":"NO\nNO\nYES\n","actual_output":"NO\nNO\nYES\n","execution_success":true,"sample_index":350},{"source":"apps","task_type":"verifiable_code","in_source_id":"744","prompt":"Solve the following coding problem using the programming language python:\n\nThe chef is trying to solve some pattern problems, Chef wants your help to code it. Chef has one number K (odd) to form a new pattern. Help the chef to code this pattern problem.\n\n-----Input:-----\n- First-line will contain $T$, the number of test cases. Then the test cases follow. \n- Each test case contains a single line of input, one integer $K$. \n\n-----Output:-----\nFor each test case, output as the pattern.\n\n-----Constraints-----\n- $1 \\leq T \\leq 100$\n- $1 \\leq K \\leq 100$\n\n-----Sample Input:-----\n4\n1\n3\n5\n7\n\n-----Sample Output:-----\n*\n*\n**\n*\n*\n**\n* *\n**\n*\n*\n**\n* *\n* *\n* *\n**\n*\n\n-----EXPLANATION:-----\nNo need, else pattern can be decode easily.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nt=int(input())\nfor _ in range(t):\n n=int(input())\n l1=[]\n if n==1:\n print('*')\n elif n==3:\n print('*')\n print('**')\n print('*')\n else:\n s1=\"\"\n n1=n//2\n n1+=1 \n for i in range(1,n1+1):\n s1=\"\"\n if i==1:\n s1+='*'\n elif i==2:\n s1+='**'\n else:\n s1+='*'\n for j in range(2,i):\n s1+=' '\n s1+='*'\n l1.append(s1)\n for i in l1:\n print(i)\n l1.reverse()\n for i in range(1,len(l1)):\n print(l1[i])\n \n \n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '4\\n1\\n3\\n5\\n7\\n', 'output': '*\\n*\\n**\\n*\\n*\\n**\\n* *\\n**\\n*\\n*\\n**\\n* *\\n* *\\n* *\\n**\\n*\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/PEND2020/problems/ANITGUY6'}","problem_id":"vfc_1818","program":"```python\nt=int(input())\nfor _ in range(t):\n n=int(input())\n l1=[]\n if n==1:\n print('*')\n elif n==3:\n print('*')\n print('**')\n print('*')\n else:\n s1=\"\"\n n1=n//2\n n1+=1 \n for i in range(1,n1+1):\n s1=\"\"\n if i==1:\n s1+='*'\n elif i==2:\n s1+='**'\n else:\n s1+='*'\n for j in range(2,i):\n s1+=' '\n s1+='*'\n l1.append(s1)\n for i in l1:\n print(i)\n l1.reverse()\n for i in range(1,len(l1)):\n print(l1[i])\n \n \n\n```","inputs":"4\n1\n3\n5\n7\n","output":"*\n*\n**\n*\n*\n**\n* *\n**\n*\n*\n**\n* *\n* *\n* *\n**\n*\n","actual_output":"*\n*\n**\n*\n*\n**\n* *\n**\n*\n*\n**\n* *\n* *\n* *\n**\n*\n","execution_success":true,"sample_index":351},{"source":"apps","task_type":"verifiable_code","in_source_id":"745","prompt":"Solve the following coding problem using the programming language python:\n\nYou want to build a temple for snakes. The temple will be built on a mountain range, which can be thought of as n blocks, where height of i-th block is given by hi. The temple will be made on a consecutive section of the blocks and its height should start from 1 and increase by exactly 1 each time till some height and then decrease by exactly 1 each time to height 1, \ni.e. a consecutive section of 1, 2, 3, .. x-1, x, x-1, x-2, .., 1 can correspond to a temple. Also, heights of all the blocks other than of the temple should have zero height, so that the temple is visible to people who view it from the left side or right side.\nYou want to construct a temple. For that, you can reduce the heights of some of the blocks. In a single operation, you can reduce the height of a block by 1 unit. Find out minimum number of operations required to build a temple.\n\n-----Input-----\nThe first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.\nThe first line of each test case contains an integer n.\nThe next line contains n integers, where the i-th integer denotes hi\n\n-----Output-----\nFor each test case, output a new line with an integer corresponding to the answer of that testcase.\n\n-----Constraints-----\n- 1 \u2264 T \u2264 10\n- 2 \u2264 n \u2264 105\n- 1 \u2264 hi \u2264 109\n\n-----Example-----\nInput\n3\n3\n1 2 1\n4\n1 1 2 1\n5\n1 2 6 2 1\n\nOutput\n0\n1\n3\n\n-----Explanation-----\nExample 1. The entire mountain range is already a temple. So, there is no need to make any operation.\nExample 2. If you reduce the height of the first block to 0. You get 0 1 2 1. The blocks 1, 2, 1 form a temple. So, the answer is 1.\nExample 3. One possible temple can be 1 2 3 2 1. It requires 3 operations to build. This is the minimum amount you have to spend in order to build a temple.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\n\nt = int(input())\nwhile t:\n t -= 1\n n = int(input())\n arr = list(map(int, input().split()))\n sumi = sum(arr)\n prev = 1\n for i in range(n):\n arr[i] = min(arr[i], prev)\n prev = arr[i] + 1\n prev = 1\n for i in range(n - 1, -1, -1):\n arr[i] = min(arr[i], prev)\n prev = arr[i] + 1\n temp = 0\n for i in range(n):\n temp = max(temp, arr[i])\n print(sumi -( temp*temp))\n\n\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\n3\\n1 2 1\\n4\\n1 1 2 1\\n5\\n1 2 6 2 1\\n', 'output': '0\\n1\\n3\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/SNTEMPLE'}","problem_id":"vfc_1822","program":"```python\n# cook your dish here\n\nt = int(input())\nwhile t:\n t -= 1\n n = int(input())\n arr = list(map(int, input().split()))\n sumi = sum(arr)\n prev = 1\n for i in range(n):\n arr[i] = min(arr[i], prev)\n prev = arr[i] + 1\n prev = 1\n for i in range(n - 1, -1, -1):\n arr[i] = min(arr[i], prev)\n prev = arr[i] + 1\n temp = 0\n for i in range(n):\n temp = max(temp, arr[i])\n print(sumi -( temp*temp))\n\n\n\n```","inputs":"3\n3\n1 2 1\n4\n1 1 2 1\n5\n1 2 6 2 1\n","output":"0\n1\n3\n","actual_output":"0\n1\n3\n","execution_success":true,"sample_index":352},{"source":"apps","task_type":"verifiable_code","in_source_id":"746","prompt":"Solve the following coding problem using the programming language python:\n\nGiven a complete binary tree with the height of H, we index the nodes respectively top-down and left-right from 1. The i-th node stores a positive integer Vi. Define Pi as follows: Pi=Vi if the i-th node is a leaf, otherwise Pi=max(Vi*PL, Vi*PR), where L and R are the indices of the left and right children of i, respectively. Your task is to caculate the value of P1.\n\n-----Input-----\nThere are several test cases (fifteen at most), each formed as follows:\n\n- The first line contains a positive integer H (H \u2264 15).\n- The second line contains 2H-1 positive integers (each having a value of 109 at most), the i-th integer shows the value of Vi.\nThe input is ended with H = 0.\n\n-----Output-----\nFor each test case, output on a line an integer which is the respective value of P1 found, by modulo of 1,000,000,007.\n\n-----Example-----\nInput:\n2\n1 2 3\n3\n3 1 5 2 6 4 7\n0\n\nOutput:\n3\n105\n\nExplanation:\n\nThe second test case is constructed as follows:\n\n3\n/ \\\n/ \\\n1 5\n/ \\ / \\\n2 6 4 7\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\ndef treeProduct(num, h, root, ch):\n if ch >= h:\n return num[root]\n\n left = (root * 2) + 1\n right = (root * 2) + 2\n\n ret1 = treeProduct(num, h, left, ch + 1)\n ret2 = treeProduct(num, h, right, ch + 1)\n\n return num[root] * max(ret1, ret2)\n\ndef main():\n n = int(input())\n while n!=0:\n line = str(input())\n s = line.split()\n num = [int((e)) for e in s]\n print(int(treeProduct(num,n,0,1)%1000000007))\n n = int(input())\n \n \ndef __starting_point():\n main()\n\n__starting_point()\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n1 2 3\\n3\\n3 1 5 2 6 4 7\\n0\\n', 'output': '3\\n105\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/MAY11/problems/TPRODUCT'}","problem_id":"vfc_1826","program":"```python\ndef treeProduct(num, h, root, ch):\n if ch >= h:\n return num[root]\n\n left = (root * 2) + 1\n right = (root * 2) + 2\n\n ret1 = treeProduct(num, h, left, ch + 1)\n ret2 = treeProduct(num, h, right, ch + 1)\n\n return num[root] * max(ret1, ret2)\n\ndef main():\n n = int(input())\n while n!=0:\n line = str(input())\n s = line.split()\n num = [int((e)) for e in s]\n print(int(treeProduct(num,n,0,1)%1000000007))\n n = int(input())\n \n \ndef __starting_point():\n main()\n\n__starting_point()\n```","inputs":"2\n1 2 3\n3\n3 1 5 2 6 4 7\n0\n","output":"3\n105\n","actual_output":"3\n105\n","execution_success":true,"sample_index":353},{"source":"apps","task_type":"verifiable_code","in_source_id":"749","prompt":"Solve the following coding problem using the programming language python:\n\nThe Government of Siruseri is no different from any other when it comes to being \"capital-centric\" in its policies. Recently the government decided to set up a nationwide fiber-optic network to take Siruseri into the digital age. And as usual, this decision was implemented in a capital centric manner --- from each city in the country, a fiber optic cable was laid to the capital! Thus, traffic between any two cities had to go through the capital.\nSoon, it became apparent that this was not quite a clever idea, since any breakdown at the capital resulted in the disconnection of services between other cities. So, in the second phase, the government plans to connect a few more pairs of cities directly by fiber-optic cables. The government has specified that this is to be done in such a way that the disruption of services at any one city will still leave the rest of the country connected.\nThe government has data on the cost of laying fiber optic cables between every pair of cities. You task is to compute the minimum cost of additional cabling required to ensure the requirement described above is met.\nFor example, if Siruseri has $4$ cities numbered $1,2,3$ and $4$ where $1$ is the capital and further suppose that the cost of laying cables between these cities are as given in the table below:\n\nNote that the government has already connected the capital with every other city. So, if we connect the cities $2$ and $3$ as well as $3$ and $4$, you can check that disruption of service at any one city will still leave the other cities connected. The cost of connecting these two pairs is $4 + 6 = 10$. The same effect could have been achieved by connecting $2$ and $3$ as well as $2$ and $4$, which would have cost $4 + 5 = 9$. You can check that this is the best you can do.\nYour task is to write a program that allows the government to determine the minimum cost it has to incur in laying additional cables to fulfil the requirement.\n\n-----Input:-----\n- The first line of the input contains a single integer $N$ indicating the number of cities in Siruseri. You may assume that the capital city is always numbered $1$. \n- This is followed by $N$ lines of input each containing $N$ integers. \n- The $j^{th}$ integer on line $i$ is the cost of connecting city $i$ with city $j$. The $j^{th}$ integer on line $i$ will be the same as the $i^{th}$ integer on line $j$ (since the links are bidirectional) and the $i^{th}$ entry on line $i$ will always be $0$ (there is no cost in connecting a city with itself).\n\n-----Output:-----\nA single integer indicating the minimum total cost of the links to be added to ensure that disruption of services at one city does not disconnect the rest of the cities.\n\n-----Constraints:-----\n- $1 \\leq N \\leq 2000$.\n- $0 \\leq$ costs given in the input $\\leq 100000$\n\n-----Sample Input-----\n4\n0 7 8 10\n7 0 4 5 \n8 4 0 6\n10 5 6 0\n\n-----Sample Output-----\n9\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nn=int(input())\r\nl=[]\r\nfor i in range(n):\r\n\tl.append([int(x) for x in input().split()])\r\nd=[10**9]*(n)\r\nq=set([int(x) for x in range(1,n)])\r\nd[1]=0\r\n#print(q)\r\ndef extract():\r\n\tmini=10**9\r\n\to=0\r\n\tfor i in range(1,len(d)):\r\n\t\tif d[i]0):\n if((n%10)%2 == 0):\n flag = 1\n break\n n = n//10\n if(flag == 0):\n print(0)\n else:\n print(1)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n19\\n385\\n', 'output': '0\\n1\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/PEND2020/problems/ITGUY03'}","problem_id":"vfc_1858","program":"```python\n# cook your dish here\nfor i in range(int(input())):\n n = int(input())\n flag = 0\n while(n>0):\n if((n%10)%2 == 0):\n flag = 1\n break\n n = n//10\n if(flag == 0):\n print(0)\n else:\n print(1)\n```","inputs":"2\n19\n385\n","output":"0\n1\n","actual_output":"0\n1\n","execution_success":true,"sample_index":361},{"source":"apps","task_type":"verifiable_code","in_source_id":"755","prompt":"Solve the following coding problem using the programming language python:\n\nAkshay is interested in mathematics, one day he came across a problem of modulus operator.He has a list of M integers say arr[M] and has to find all integers K such that :\n- K > 1\n- arr[1]%K = arr[2]%K = arr[3]%K = \u2026 = arr[M]%K where '%' is a modulus operator.\nHelp Akshay to find all such K's.\n\n-----Input:-----\n- First line of input contains an integer M. Then M lines follow each containing one integer of the list. Input data is such that at least one integer K will always exist.\n\n-----Output:-----\n- Output all possible integers K separated by space in increasing order.\n\n-----Constraints-----\n- 2<= M <=100\n- 1< value of each integer <109\n- All integers will be distinct\n\n-----Sample Input:-----\n3\n38\n6\n34\n\n-----Sample Output:-----\n2 4\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nl = []\nfor _ in range(int(input())):\n l.append(int(input()))\nfor i in range(2,max(l)):\n r = [x%i for x in l]\n if len(set([x%i for x in l])) == 1:\n print(i, end = ' ')\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\n38\\n6\\n34\\n', 'output': '2 4\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/INEK2019/problems/IF05'}","problem_id":"vfc_1862","program":"```python\nl = []\nfor _ in range(int(input())):\n l.append(int(input()))\nfor i in range(2,max(l)):\n r = [x%i for x in l]\n if len(set([x%i for x in l])) == 1:\n print(i, end = ' ')\n\n```","inputs":"3\n38\n6\n34\n","output":"2 4\n","actual_output":"2 4 ","execution_success":true,"sample_index":362},{"source":"apps","task_type":"verifiable_code","in_source_id":"756","prompt":"Solve the following coding problem using the programming language python:\n\nFarmer Feb has three fields with potatoes planted in them. He harvested x potatoes from the first field, y potatoes from the second field and is yet to harvest potatoes from the third field. Feb is very superstitious and believes that if the sum of potatoes he harvests from the three fields is a prime number (http://en.wikipedia.org/wiki/Prime_number), he'll make a huge profit. Please help him by calculating for him the minimum number of potatoes that if harvested from the third field will make the sum of potatoes prime. At least one potato should be harvested from the third field.\n\n-----Input-----\nThe first line of the input contains an integer T denoting the number of test cases. Each of the next T lines contain 2 integers separated by single space: x and y.\n\n-----Output-----\nFor each test case, output a single line containing the answer.\n\n-----Constraints-----\n- 1 \u2264 T \u2264 1000\n- 1 \u2264 x \u2264 1000\n- 1 \u2264 y \u2264 1000\n\n-----Example-----\nInput:\n2\n1 3\n4 3\n\nOutput:\n1\n4\n\n-----Explanation-----\n\nIn example case 1: the farmer harvested a potato from the first field and 3 potatoes from the second field. The sum is 4. If he is able to harvest a potato from the third field, that will make the sum 5, which is prime. Hence the answer is 1(he needs one more potato to make the sum of harvested potatoes prime.)\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\nimport math\ntry:\n def prime(n):\n for i in range(2, int(math.sqrt(n)) + 1):\n if n % i == 0:\n return False\n return True\n \n for t in range(int(input())):\n x, y = list(map(int, input().split()))\n s = x + y \n i = s\n while(1):\n if prime(s + 1):\n ans = s + 1\n break\n else:\n s += 1\n print(ans - i)\n\nexcept: pass\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n1 3\\n4 3\\n', 'output': '1\\n4\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/POTATOES'}","problem_id":"vfc_1866","program":"```python\n# cook your dish here\nimport math\ntry:\n def prime(n):\n for i in range(2, int(math.sqrt(n)) + 1):\n if n % i == 0:\n return False\n return True\n \n for t in range(int(input())):\n x, y = list(map(int, input().split()))\n s = x + y \n i = s\n while(1):\n if prime(s + 1):\n ans = s + 1\n break\n else:\n s += 1\n print(ans - i)\n\nexcept: pass\n\n```","inputs":"2\n1 3\n4 3\n","output":"1\n4\n","actual_output":"1\n4\n","execution_success":true,"sample_index":363},{"source":"apps","task_type":"verifiable_code","in_source_id":"757","prompt":"Solve the following coding problem using the programming language python:\n\nSaket loves to play with strings. One day , while he was having fun with Cyclic Permutations of available strings to him, he observed that despite being scarce in numbers Vowels were really clingy.Being clingy means for almost every given string, there was a Cyclic Permutation in which atleast two vowels were together.\nSo he decided to check this property for all the available strings to him. As the number of strings can be very large, help Saket determine whether the given string is clingy or not.\n\n-----Input:-----\nThe 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.\nFirst line of every test case contains an integer N$N$ denoting the length of the string.\nSecond line contains a string S$S$ of length N$N$, consisting only of uppercase english alphabets.\n\n-----Output:-----\nFor each test case, print a single line containing \"Yes\" if any of the cyclic permutations of the string is clingy else print \"No\".\n\n-----Constraints-----\n- 1\u2264T\u22641000$1 \\leq T \\leq 1000$\n- 1\u2264N\u22641000$1 \\leq N \\leq 1000$\n- String S$S$ consists of only upper case english alphabets.\n\n-----Subtasks-----\n- 20 points : 1\u2264N\u22645$1 \\leq N \\leq 5$\n- 80 points : Original$Original$ Constraints$Constraints$\n\n-----Sample Input:-----\n2\n5\nAUXFC\n6\nXBCDEF\n\n-----Sample Output:-----\nYes\n\nNo\n\n-----EXPLANATION:-----\nExample$Example$ case1:$ case 1: $ One of the cyclic permutation is the original string itself, which has \"A\" and \"U\" together.\nExample$Example$ case2:$ case 2: $ None of the cyclic permutation will have 2 vowels together.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfor t in range(int(input())):\r\n\tn=int(input())\r\n\ts=input().strip()\r\n\tc=0\r\n\tflag=0\r\n\tfor i in range(n):\r\n\t\tif (s[i]==\"A\" or s[i]==\"E\" or s[i]==\"I\" or s[i]==\"O\" or s[i]==\"U\") and (s[i-1]==\"A\" or s[i-1]==\"E\" or s[i-1]==\"I\" or s[i-1]==\"O\" or s[i-1]==\"U\") :\r\n\t\t\tflag=1\r\n\tif flag and n!=1:\r\n\t\tprint(\"Yes\")\r\n\telse:\r\n\t\tprint(\"No\")\r\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n5\\nAUXFC\\n6\\nXBCDEF\\n', 'output': 'Yes\\nNo\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/ALQU2018/problems/VOWPAIR'}","problem_id":"vfc_1870","program":"```python\nfor t in range(int(input())):\r\n\tn=int(input())\r\n\ts=input().strip()\r\n\tc=0\r\n\tflag=0\r\n\tfor i in range(n):\r\n\t\tif (s[i]==\"A\" or s[i]==\"E\" or s[i]==\"I\" or s[i]==\"O\" or s[i]==\"U\") and (s[i-1]==\"A\" or s[i-1]==\"E\" or s[i-1]==\"I\" or s[i-1]==\"O\" or s[i-1]==\"U\") :\r\n\t\t\tflag=1\r\n\tif flag and n!=1:\r\n\t\tprint(\"Yes\")\r\n\telse:\r\n\t\tprint(\"No\")\r\n\n```","inputs":"2\n5\nAUXFC\n6\nXBCDEF\n","output":"Yes\nNo\n","actual_output":"Yes\nNo\n","execution_success":true,"sample_index":364},{"source":"apps","task_type":"verifiable_code","in_source_id":"759","prompt":"Solve the following coding problem using the programming language python:\n\nTara was completing an Algorithms assignment and got stuck on a question. She thought of who can help her, and got reminded of Kabir who has good problem solving skills. The question is:\nGiven N$N$ the number of elements in the sequence A1$A_1$,A2$A_2$ \u2026 An$A_n$. Find out the prime factor which occurred maximum number of times among the largest prime factor corresponding to each element. if there are more than one such prime factors print the largest one.\nYou are friends with Kabir, help him to solve the problem for Tara.\n\n-----Input:-----\n- The first line of the input contains a single integer T$T$ denoting the number of test cases. The description of T test cases follows. \n- First line of each test case contains N$N$, the number of elements in the sequence.\n- Second line contains N space separated elements A1$A_1$,A2$A_2$ \u2026 An$A_n$.\n\n-----Output:-----\n- For each test case, print a single line, the number which occurs maximum number of times from the largest prime factor corresponding to each element.\n\n-----Constraints-----\n- 1\u2264T\u226410$1 \\leq T \\leq 10$\n- 1\u2264N\u2264105$1 \\leq N \\leq 10^5$\n- 2\u2264A[i]\u2264105$2 \\leq A[i] \\leq 10^5$\n\n-----Sample Input:-----\n1\n7\n\n3 2 15 6 8 5 10\n\n-----Sample Output:-----\n5\n\n-----EXPLANATION:-----\nThe largest prime factors of numbers are:\n3 2 5 3 2 5 5 , of which 5 is most frequent.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\nstore=[0]*(10**5+1)\ndef sieve():\n\tfor i in range(2,10**5+1):\n\t\tif(store[i]==0):\n\t\t\tstore[i]=1\n\t\t\tfor j in range(i,10**5+1,i):\n\t\t\t\tstore[j]=i\nsieve()\n# print(store)\nfor _ in range(int(input())):\n\t\n\tn=int(input())\n\tli=[int(x) for x in input().split()]\n\n\tdp=[0]*(10**5+1)\n\tfor i in li:\n\t\tdp[store[i]]+=1\n\tmax_re=0\n\tres=0\n\tfor i in li:\n\t\tif(dp[store[i]]==max_re):\n\t\t\tif(store[i]>res):\n\t\t\t\tres=store[i]\n\t\telif(dp[store[i]]>max_re):\n\t\t\tmax_re=dp[store[i]]\n\t\t\tres=store[i]\n\t\n\tprint(res)\n\n\n\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n7\\n3 2 15 6 8 5 10\\n', 'output': '5\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/HECS2020/problems/CC005'}","problem_id":"vfc_1878","program":"```python\n# cook your dish here\nstore=[0]*(10**5+1)\ndef sieve():\n\tfor i in range(2,10**5+1):\n\t\tif(store[i]==0):\n\t\t\tstore[i]=1\n\t\t\tfor j in range(i,10**5+1,i):\n\t\t\t\tstore[j]=i\nsieve()\n# print(store)\nfor _ in range(int(input())):\n\t\n\tn=int(input())\n\tli=[int(x) for x in input().split()]\n\n\tdp=[0]*(10**5+1)\n\tfor i in li:\n\t\tdp[store[i]]+=1\n\tmax_re=0\n\tres=0\n\tfor i in li:\n\t\tif(dp[store[i]]==max_re):\n\t\t\tif(store[i]>res):\n\t\t\t\tres=store[i]\n\t\telif(dp[store[i]]>max_re):\n\t\t\tmax_re=dp[store[i]]\n\t\t\tres=store[i]\n\t\n\tprint(res)\n\n\n\n\n```","inputs":"1\n7\n3 2 15 6 8 5 10\n","output":"5\n","actual_output":"5\n","execution_success":true,"sample_index":366},{"source":"apps","task_type":"verifiable_code","in_source_id":"761","prompt":"Solve the following coding problem using the programming language python:\n\nChef spent N days working really hard! He planned loads of tasks: as many as Ai tasks to do on the ith day! Chef's work was brutal, so he only managed to finish Bi tasks on the ith day.\nThe good news is that Chef has a Time Machine! \nThe Time Machine has K white buttons and M black buttons. Each button has a positive integer printed on it. Now Chef goes through all N days consequently and presses buttons. Each day Chef can only press one button (either white or black). After using a button once, it becomes inactive.\nPressing a white button with integer x printed on it reduces the number of planned tasks on the day it was pressed by exactly x. Note that this white button can only be pressed if number of planned tasks on the day are greater than or equal to x.\nPressing a black button with integer x printed on it increases the number of completed tasks on the day it was pressed by exactly x. Note that this black button can only be pressed if after pressing it, number of completed tasks don't exceed the number of tasks.\nChef is interested in finding the minimum possible amount of total uncompleted tasks he will still be left with after N days using the Machine in the best way?\nBe careful! Time is sensitive! Chef cannot make a day when he completed more tasks then planned, as this may result in a more-work-than-planned paradox, killing all lazy people on the planet!\n\n-----Input-----\n- The first line of input contains a single integer T, denoting the number of test cases. Description of T test cases follows.\n- The first line of each test case contains three integers \u2014 N, K, M \u2014 denoting the number of days, white and black buttons appropriately.\n- The second line contains N space-separated integers A1, A2, \u2026 , AN, denoting the number of planned tasks.\n- The third line contains N space-separated integers B1, B2, \u2026 , BN, denoting the number of completed tasks.\n- The fourth line contains K space-separated integers C1, C2, \u2026 , CK, denoting the integers on white buttons.\n- The fifth and last line contains M space-separated integers D1, D2, \u2026 , DM, denoting the integers on black buttons.\n\n-----Output-----\n- In a single line, output an integer \u2014 the minimum possible amount of uncompleted tasks.\n\n-----Constraints-----\n- 1 \u2264 T \u2264 4\n- 1 \u2264 N, K, M \u2264 10^5\n- 1 \u2264 Bi \u2264 Ai \u2264 10^5\n- 1 \u2264 Ci, Di \u2264 10^5\n\n-----Subtasks-----\n- Subtask N \u2264 10, K, M \u2264 5. Points: 30 \n- Subtask Original constraints. Points: 70 \n\n-----Example-----\nInput:\n1\n4 2 2 \n5 7 6 1\n3 3 1 1\n6 3\n1 4\n\nOutput:\n3\n\n-----Explanation-----\nExample case 1.\nIn this example Chef goes through the following steps:\nUse black button 1 on the first day.\nUse black button 4 on the second day.\nUse white button 3 on the third day.\nThe arrays A and B are now effectively changed to:\n5 7 3 1\n4 7 1 1\nSo he will have 3 uncompleted tasks.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nt=int(input())\n\ndef diffe(a,b):\n return int(a-b)\n\nwhile t :\n t=t-1\n \n lia=[]\n lib=[]\n lik=[]\n lim=[]\n liab=[]\n likm=[]\n n,k,m=list(map(int,input().split()))\n \n \n lia=list(map(int,input().split()))\n lib=list(map(int,input().split()))\n lik=list(map(int,input().split()))\n lim=list(map(int,input().split()))\n liab=list(map(diffe,lia,lib)) \n \n likm=lik+lim\n \n \n likm.sort()\n \n liab.sort()\n liab.reverse()\n \n for i in range(0,len(liab)): \n for j in range(len(likm)-1,0-1,-1):\n a=likm.pop()\n if (liab[i]-a)>=0:\n liab[i]=liab[i]-a\n \n break\n \n \n print(sum(liab)) \n\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n4 2 2\\n5 7 6 1\\n3 3 1 1\\n6 3\\n1 4\\n', 'output': '3\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/JAN16/problems/CHEFTMA'}","problem_id":"vfc_1886","program":"```python\nt=int(input())\n\ndef diffe(a,b):\n return int(a-b)\n\nwhile t :\n t=t-1\n \n lia=[]\n lib=[]\n lik=[]\n lim=[]\n liab=[]\n likm=[]\n n,k,m=list(map(int,input().split()))\n \n \n lia=list(map(int,input().split()))\n lib=list(map(int,input().split()))\n lik=list(map(int,input().split()))\n lim=list(map(int,input().split()))\n liab=list(map(diffe,lia,lib)) \n \n likm=lik+lim\n \n \n likm.sort()\n \n liab.sort()\n liab.reverse()\n \n for i in range(0,len(liab)): \n for j in range(len(likm)-1,0-1,-1):\n a=likm.pop()\n if (liab[i]-a)>=0:\n liab[i]=liab[i]-a\n \n break\n \n \n print(sum(liab)) \n\n\n```","inputs":"1\n4 2 2\n5 7 6 1\n3 3 1 1\n6 3\n1 4\n","output":"3\n","actual_output":"3\n","execution_success":true,"sample_index":368},{"source":"apps","task_type":"verifiable_code","in_source_id":"763","prompt":"Solve the following coding problem using the programming language python:\n\nYou are given two binary strings $S$ and $P$, each with length $N$. A binary string contains only characters '0' and '1'. For each valid $i$, let's denote the $i$-th character of $S$ by $S_i$.\nYou have to convert the string $S$ into $P$ using zero or more operations. In one operation, you should choose two indices $i$ and $j$ ($1 \\leq i < j \\leq N$) such that $S_i$ is '1' and $S_j$ is '0', and swap $S_i$ with $S_j$.\nDetermine if it is possible to convert $S$ into $P$ by performing some operations.\n\n-----Input-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The first line of each test case contains a single integer $N$.\n- The second line contains a single string $S$.\n- The third line contains a single string $P$.\n\n-----Output-----\nFor each test case, print a single line containing the string \"Yes\" if it is possible to convert $S$ into $P$ or \"No\" otherwise (without quotes).\n\n-----Constraints-----\n- $1 \\leq T \\leq 10^5$\n- $1 \\leq N \\leq 10^5$\n- $S$ and $P$ contain only characters '0' and '1'\n- the sum of $N$ over all test cases does not exceed $10^5$\n\n-----Subtasks-----\nSubtask #1 (20 points):\n- $N \\leq 14$\n- the sum of $N$ over all test cases does not exceed $100$\nSubtask #2 (30 points): the sum of $N$ over all test cases does not exceed $1,000$\nSubtask #3 (50 points): original constraints\n\n-----Example Input-----\n3\n2\n00\n00\n3\n101\n010\n4\n0110\n0011\n\n-----Example Output-----\nYes\nNo\nYes\n\n-----Explanation-----\nExample case 1: The strings are already equal.\nExample case 2: It can be showed that it is impossible to convert $S$ into $P$.\nExample case 3: You can swap $S_2$ with $S_4$. The strings will then be equal.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n\ndef solve(s, p):\n diffs = 0\n for x, y in zip(s, p):\n if x == y:\n continue\n if x == '0':\n if diffs < 1:\n return \"No\"\n diffs -= 1\n else:\n diffs += 1\n return \"Yes\" if diffs == 0 else \"No\"\n\nfor _ in range(int(input())):\n l = int(input())\n s = input().strip()\n p = input().strip()\n print(solve(s, p))\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\n2\\n00\\n00\\n3\\n101\\n010\\n4\\n0110\\n0011\\n', 'output': 'Yes\\nNo\\nYes\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/SWAP10HG'}","problem_id":"vfc_1894","program":"```python\n\ndef solve(s, p):\n diffs = 0\n for x, y in zip(s, p):\n if x == y:\n continue\n if x == '0':\n if diffs < 1:\n return \"No\"\n diffs -= 1\n else:\n diffs += 1\n return \"Yes\" if diffs == 0 else \"No\"\n\nfor _ in range(int(input())):\n l = int(input())\n s = input().strip()\n p = input().strip()\n print(solve(s, p))\n\n```","inputs":"3\n2\n00\n00\n3\n101\n010\n4\n0110\n0011\n","output":"Yes\nNo\nYes\n","actual_output":"Yes\nNo\nYes\n","execution_success":true,"sample_index":370},{"source":"apps","task_type":"verifiable_code","in_source_id":"764","prompt":"Solve the following coding problem using the programming language python:\n\nChef has just found a recipe book, where every dish consists of exactly four ingredients.\nHe is going to choose some two dishes and prepare them for dinner.\nOf course, he likes diversity and wants to know whether the two dishes are similar.\nTwo dishes are called similar if at least half of their ingredients are the same.\nIn other words, at least two of four ingredients of the first dish should also be present in the second dish.\nThe order of ingredients doesn't matter.\nYour task is to examine T pairs of dishes.\nFor each pair, check if the two dishes are similar and print \"similar\" or \"dissimilar\" accordingly.\n\n-----Input-----\nThe first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.\n\nThe first line of each test case contains four distinct strings, denoting ingredients needed for the first dish.\nEach ingredient is represented by a string of length between 2 and 10 inclusive, consisting of lowercase English letters.\n\nThe second line of each test case describes the second dish in the same format.\n\n-----Output-----\nFor each test case, output a single line containing the answer \u2014 \"similar\" if at least half of the ingredients are same, and \"dissimilar\" otherwise (without the quotes).\n\n-----Constraints-----\n- 1 \u2264 T \u2264 200\n- The length of each string will be between 2 and 10 inclusive.\n\n-----Example-----\nInput:\n5\neggs sugar flour salt\nsugar eggs milk flour\naa ab ac ad\nac ad ae af\ncookies sugar grass lemon\nlemon meat chili wood\none two three four\none two three four\ngibberish jibberish lalalalala popopopopo\njibberisz gibberisz popopopopu lalalalalu\n\nOutput:\nsimilar\nsimilar\ndissimilar\nsimilar\ndissimilar\n\n-----Explanation-----\nTest case 1. The first dish consists of ingredients: eggs, sugar, flour, salt, while the second dish consists of: sugar, eggs, milk, flour. Three of four ingredients are present in both dishes (eggs, sugar, flour) so the two dishes are similar.\nTest case 2. This example shows that strings in the input don't necessarily represent real food.\nThe answer is again \"similar\", because two ingredients are present in both dishes (\"ac\" and \"ad\").\nTest case 3. The only common ingredient is lemon, so the answer is \"dissimilar\".\nRemember that at least two ingredients should be present in both dishes.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\nt=int(input())\ni=0\nwhile i=2:\n print(\"similar\")\n else:\n print(\"dissimilar\")\n i+=1\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '5\\neggs sugar flour salt\\nsugar eggs milk flour\\naa ab ac ad\\nac ad ae af\\ncookies sugar grass lemon\\nlemon meat chili wood\\none two three four\\none two three four\\ngibberish jibberish lalalalala popopopopo\\njibberisz gibberisz popopopopu lalalalalu\\n', 'output': 'similar\\nsimilar\\ndissimilar\\nsimilar\\ndissimilar\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/SIMDISH'}","problem_id":"vfc_1898","program":"```python\n# cook your dish here\nt=int(input())\ni=0\nwhile i=2:\n print(\"similar\")\n else:\n print(\"dissimilar\")\n i+=1\n```","inputs":"5\neggs sugar flour salt\nsugar eggs milk flour\naa ab ac ad\nac ad ae af\ncookies sugar grass lemon\nlemon meat chili wood\none two three four\none two three four\ngibberish jibberish lalalalala popopopopo\njibberisz gibberisz popopopopu lalalalalu\n","output":"similar\nsimilar\ndissimilar\nsimilar\ndissimilar\n","actual_output":"similar\nsimilar\ndissimilar\nsimilar\ndissimilar\n","execution_success":true,"sample_index":371},{"source":"apps","task_type":"verifiable_code","in_source_id":"765","prompt":"Solve the following coding problem using the programming language python:\n\nChef likes to travel a lot. Every day Chef tries to visit as much cities as possible. Recently he had a quite a few trips of great Chefland for learning various recipes. Chefland had N cities numbered from 1 to N. People in Chefland are very friendly, friendliness of i-th city is given by Fi.\n\nBefore starting of each trip, Chef's initial enjoyment is 1 unit. Whenever he visits a city with friendliness Fi, his enjoyment gets multiplied by Fi units. \n\nCity 1 is the home city of Chef. He starts each trip from his home city. Before starting a trip, he chooses a parameter R which denotes that he will start from city 1, and go to city 1 + R, then to 1 + 2 * R, then to 1 + 3 * R, till 1 + i * R such that i is largest integer satisfying 1 + i * R \u2264 N.\n\nNow, Chef wants you to help him recreate his visit of the cities. Specifically, he will ask you Q queries, each of which can be of following two types.\n\n- 1 p f : friendliness of p-th city changes to f, i.e. Fp = f \n- 2 R : Find out the total enjoyment Chef will have during this trip. As Chef does not like big numbers, he just asks you to output two things, first digit of the enjoyment and value of enjoyment modulo 109 + 7.\n\n-----Input-----\nThere is a single test case.\nFirst line of input contains a single integer N, denoting number of cities in Chefland.\nSecond line of the input contains N space separated integer - F1, F2, ..., FN, denoting the friendliness of the cities in order from 1 to N.\nNext line contains an integer Q, denoting number of queries.\n\nFor each of the next Q queries, each line corresponds to one of the two types of the query. First there will be an integer denoting the type of the query, followed by the actual query. For query of type 1, there will be three space separated integers \"1 p f\" as defined above. For query of type 2, there will be two space separated integers \"2 R \", as defined above.\n\n-----Output-----\nFor each query of type 2, output two space separated integers, first digit of Chef's enjoyment in this trip followed by the value of enjoyment modulo 109 + 7.\n\n-----Constraints-----\n- 1 \u2264 N, Q \u2264 105 \n- 1 \u2264 Fi \u2264 10^9 \n- 1 \u2264 f \u2264 10^9 \n- 1 \u2264 p \u2264 N \n- 1 \u2264 R \u2264 N \n\n-----Subtasks-----\nSubtask #1 (5 points) : \n\n- 1 \u2264 N \u2264 10 \n- 1 \u2264 Q \u2264 1000 \n- 1 \u2264 Fi \u2264 10 \n- 1 \u2264 f \u2264 10 \n\nSubtask #2 (15 points) : \n\n- 1 \u2264 N \u2264 1000 \n- 1 \u2264 Q \u2264 100 \n- 1 \u2264 Fi \u2264 109 \n- 1 \u2264 f \u2264 1000 \n\nSubtask #3 (80 points) : \n\n- original constraints\n\n-----Example-----\nInput:\n5\n1 2 3 4 5\n3\n2 1\n1 3 10\n2 2\n\nOutput:\n1 120\n5 50\n\n-----Explanation-----\nIn the first query, Chef is going to visit cities 1, 2, 3, 4, 5 in order. At the end of the trip, his total enjoyment will be 1 * 2 * 3 * 4 * 5 = 120. First digit of enjoyment is 1 and 120 modulo 109 + 7 is 120.\nIn the third query, Chef is going to visit cities 1, 3, 5 in order. At the end of the trip, his total enjoyment will be 1 * 10 * 5 = 50.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nn=int(input())\na=list(map(int,input().split()))\nq=int(input())\nwhile q>0:\n i=1\n tot=a[0]\n b=list(map(int,input().split()))\n if b[0]==1:\n #p,f=map(int,raw_input().split())\n a[b[1]-1]=b[2]\n else:\n #r=int(raw_input())\n tot=a[0]\n while 1+i*b[1]<=n:\n tot=tot*a[i*b[1]]\n i=i+1\n m=(str)(tot)\n tot=tot%1000000007\n print((int)(m[0]),tot)\n q=q-1\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '5\\n1 2 3 4 5\\n3\\n2 1\\n1 3 10\\n2 2\\n', 'output': '1 120\\n5 50\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/JUNE16/problems/FRJUMP'}","problem_id":"vfc_1902","program":"```python\nn=int(input())\na=list(map(int,input().split()))\nq=int(input())\nwhile q>0:\n i=1\n tot=a[0]\n b=list(map(int,input().split()))\n if b[0]==1:\n #p,f=map(int,raw_input().split())\n a[b[1]-1]=b[2]\n else:\n #r=int(raw_input())\n tot=a[0]\n while 1+i*b[1]<=n:\n tot=tot*a[i*b[1]]\n i=i+1\n m=(str)(tot)\n tot=tot%1000000007\n print((int)(m[0]),tot)\n q=q-1\n\n```","inputs":"5\n1 2 3 4 5\n3\n2 1\n1 3 10\n2 2\n","output":"1 120\n5 50\n","actual_output":"1 120\n5 50\n","execution_success":true,"sample_index":372},{"source":"apps","task_type":"verifiable_code","in_source_id":"766","prompt":"Solve the following coding problem using the programming language python:\n\nChef has an array of N natural numbers. Cheffina challenges the chef to choose the two numbers from the array and following the condition as the area of the rectangle formed from the two numbers is maximum. Cheffina also asks the chef to choose two numbers different from the previous two to form the rectangle with a minimum area.\n\n-----Input:-----\n- First-line will contain $T$, the number of test cases. Then the test cases follow. \n- Each test case contains a single line of input, $N$.\n- N space-separated natural numbers. \n\n-----Output:-----\nFor each test case, output in one line answers maximum and minimum area of a rectangle.\n\n-----Constraints-----\n- $1 \\leq T \\leq 10$\n- $4 \\leq N \\leq 10^5$\n- $1 \\leq arr[i] \\leq 10^6$\n\n-----Sample Input:-----\n1\n5\n4 2 1 5 3\n\n-----Sample Output:-----\n20 2\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nimport sys\r\nimport math\r\nimport bisect\r\nfrom sys import stdin,stdout\r\nfrom math import gcd,floor,sqrt,log\r\nfrom collections import defaultdict as dd\r\nfrom bisect import bisect_left as bl,bisect_right as br\r\n\r\nsys.setrecursionlimit(100000000)\r\n\r\nii =lambda: int(input())\r\nsi =lambda: input()\r\njn =lambda x,l: x.join(map(str,l))\r\nsl =lambda: list(map(str,input().strip()))\r\nmi =lambda: map(int,input().split())\r\nmif =lambda: map(float,input().split())\r\nlii =lambda: list(map(int,input().split()))\r\n\r\nceil =lambda x: int(x) if(x==int(x)) else int(x)+1\r\nceildiv=lambda x,d: x//d if(x%d==0) else x//d+1\r\n\r\nflush =lambda: stdout.flush()\r\nstdstr =lambda: stdin.readline()\r\nstdint =lambda: int(stdin.readline())\r\nstdpr =lambda x: stdout.write(str(x))\r\n\r\nmod=1000000007\r\n\r\n\r\n#main code\r\nfor _ in range(ii()):\r\n n=ii()\r\n arr=lii()\r\n arr.sort()\r\n ma=arr[-1]*arr[-2]\r\n mi=arr[0]*arr[1]\r\n print(ma,mi)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n5\\n4 2 1 5 3\\n', 'output': '20 2\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/PEND2020/problems/ANITGUY7'}","problem_id":"vfc_1906","program":"```python\nimport sys\r\nimport math\r\nimport bisect\r\nfrom sys import stdin,stdout\r\nfrom math import gcd,floor,sqrt,log\r\nfrom collections import defaultdict as dd\r\nfrom bisect import bisect_left as bl,bisect_right as br\r\n\r\nsys.setrecursionlimit(100000000)\r\n\r\nii =lambda: int(input())\r\nsi =lambda: input()\r\njn =lambda x,l: x.join(map(str,l))\r\nsl =lambda: list(map(str,input().strip()))\r\nmi =lambda: map(int,input().split())\r\nmif =lambda: map(float,input().split())\r\nlii =lambda: list(map(int,input().split()))\r\n\r\nceil =lambda x: int(x) if(x==int(x)) else int(x)+1\r\nceildiv=lambda x,d: x//d if(x%d==0) else x//d+1\r\n\r\nflush =lambda: stdout.flush()\r\nstdstr =lambda: stdin.readline()\r\nstdint =lambda: int(stdin.readline())\r\nstdpr =lambda x: stdout.write(str(x))\r\n\r\nmod=1000000007\r\n\r\n\r\n#main code\r\nfor _ in range(ii()):\r\n n=ii()\r\n arr=lii()\r\n arr.sort()\r\n ma=arr[-1]*arr[-2]\r\n mi=arr[0]*arr[1]\r\n print(ma,mi)\n```","inputs":"1\n5\n4 2 1 5 3\n","output":"20 2\n","actual_output":"20 2\n","execution_success":true,"sample_index":373},{"source":"apps","task_type":"verifiable_code","in_source_id":"767","prompt":"Solve the following coding problem using the programming language python:\n\nIndian National Olympiad in Informatics 2012\nThe Republic of Tutaria is celebrating its 37th year of independence. To mark the occasion, the nation is organising a contest where all its N citizens take part. The event has three tracks, a COBOL programming competition, pole vault, and a doughnut-eating competition. Each citizen takes part in these three tracks in the same order\u2014a citizen starts with the programming competition, continues with the pole vault as soon as his or her COBOL masterpiece is ready, and then starts gorging on doughnuts as soon as the pole vault is done.\nThe Supreme Leader of Tutaria closely monitors all citizens and knows the exact amount of time each citizen will take in each of the three tracks. She wants to schedule the event so that it will finish as early as possible. However, the Republic of Tutaria has only one computer, and, as a result, only one person can participate in the COBOL programming event at a time. However, any number of people may simultaneously participate in the pole vault and doughnut-eating competitions.\nThe event works as follows. The Supreme Leader fixes the order in which contestants get access to the computer. At time 0, the first citizen in the list starts writing his or her COBOL program, while the remaining citizens wait for the computer to be free. As soon as the first citizen is done, he or she proceeds to the pole vault, and the second citizen gets the computer for the programming round. In general whenever the computer becomes free, the next citizen gets to use it. Whenever a citizen is done using the computer, he or she proceeds to the pole vault immediately, regardless of what the other citizens are doing. Similarly, whenever a citizen is done with the pole vault, he or she proceeds to the doughnut- eating track immediately, independently of the others. The event ends as soon as all the citizens have finished all the three tracks of the event.\nFor example, suppose N = 3, and the time they need for the three tracks are as follows:\nCitizen id\nCOBOL\nPole vault\nDoughnut-eating\n1\n18\n7\n6\n2\n23\n10\n27\n3\n20\n9\n14\n\nIf the citizens start at time 0 and proceed in the order 1,2,3, then citizen 1 will finish at time 18+7+6 = 31, citizen 2 will finish at time 18+23+10+27 = 78, and citizen 3 will finishattime18+23+20+9+14=84. Theeventendsattimemax(31,78,84)=84.\nOn the other hand, if the citizens proceed in the order 2,3,1, you can check that the event ends at max(60, 66, 74) = 74. The Supreme Leader of Tutaria wants to fix the order in which the citizens proceed so that the event ends as early as possible. You can check that in this case 74 is the earliest time at which the event can end.\n\n-----Input format-----\nThe first line of input has a single integer, N, the number of citizens of the Republic of Tutaria. The next N lines contain 3 space-separated integers each: line i gives the time taken by the citizen i for COBOL programming, pole vault, and doughnut-eating respectively.\n\n-----Output format-----\nThe output should have a single line with a single integer, the earliest time at which the event can end.\n\n-----Test Data-----\nThe testdata is grouped into two subtasks with the following constraints on the inputs.\n\u2022 Subtask 1 [30 points] : 1 \u2264 N \u2264 3000.\n\u2022 Subtask 2 [70 points] : 1 \u2264 N \u2264 200000.\nIn both the subtasks, all the numbers in the input (except possibly N) are in the range 1 to 10000, inclusive.\n\n-----Example-----\nHere is the sample input and output corresponding to the example above.\n\n-----Sample input-----\n3\n18 7 6 \n23 10 27\n20 9 14\n\n-----Sample output-----\n74\n\n-----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!\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\nwhile True:\n try:\n n=int(input())\n lis=[]\n for i in range(n):\n k=list(map(int,input().split()))\n k.append(k[1]+k[2])\n lis.append(k)\n \n #print(lis)\n p=sorted(lis,key=lambda x:x[3],reverse=True)\n #print(p)\n maxi=0\n s=0\n w=0\n for i in range(n):\n s+=p[i][0]\n w=s+p[i][1]+p[i][2]\n maxi=max(maxi,w)\n \n print(maxi)\n \n \n except:\n break\n \n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': 'and output corresponding to the example above.\\nSample input\\n3\\n18 7 6\\n23 10 27\\n20 9 14\\nSample output\\n74\\nNote: 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!\\n', 'output': ''}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/INOIPRAC/problems/INOI1201'}","problem_id":"vfc_1910","program":"```python\n# cook your dish here\nwhile True:\n try:\n n=int(input())\n lis=[]\n for i in range(n):\n k=list(map(int,input().split()))\n k.append(k[1]+k[2])\n lis.append(k)\n \n #print(lis)\n p=sorted(lis,key=lambda x:x[3],reverse=True)\n #print(p)\n maxi=0\n s=0\n w=0\n for i in range(n):\n s+=p[i][0]\n w=s+p[i][1]+p[i][2]\n maxi=max(maxi,w)\n \n print(maxi)\n \n \n except:\n break\n \n\n```","inputs":"and output corresponding to the example above.\nSample input\n3\n18 7 6\n23 10 27\n20 9 14\nSample output\n74\nNote: 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!\n","output":"","actual_output":"","execution_success":true,"sample_index":374},{"source":"apps","task_type":"verifiable_code","in_source_id":"768","prompt":"Solve the following coding problem using the programming language python:\n\nThe MEX of a set of integers is defined as the smallest non-negative integer that does not belong to this set. For example, $\\mathrm{MEX}(\\{0,2,3\\}) = 1$ and $\\mathrm{MEX}(\\{1,3\\}) = 0$.\nChef has a tree with $N$ nodes (numbered $1$ through $N$). The tree is rooted at node $1$. Chef wants to assign a non-negative integer to each node in such a way that each integer between $0$ and $N-1$ (inclusive) is assigned to exactly one node.\nFor each node $u$, consider the integers assigned to the nodes in the subtree of $u$ (including $u$); let $a_u$ denote the MEX of these integers. Chef wants $a_1 + a_2 + \\ldots + a_N$ to be as large as possible. Find the maximum possible value of this sum.\n\n-----Input-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The first line of each test case contains a single integer $N$.\n- The second line contains $N-1$ space-separated integers $p_1, p_2, \\ldots, p_{N-1}$. For each valid $i$, the node $p_i$ is the parent of the node $i+1$.\n\n-----Output-----\nFor each test case, print a single line containing one integer \u2015 the maximum sum of subtree MEX-s which can be obtained if you assign the weights optimally.\n\n-----Constraints-----\n- $1 \\le T \\le 5$\n- $2 \\le N \\le 10^5$\n- $1 \\le p_i < i$ for each valid $i$\n\n-----Subtasks-----\nSubtask #1 (100 points): original constraints\n\n-----Example Input-----\n2\n3\n1 1\n5\n1 1 2 2\n\n-----Example Output-----\n4\n9\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\n# cook your dish here\nfrom math import log2;\nimport sys;\n\nsys.setrecursionlimit(10 ** 7)\nfrom collections import defaultdict\n\ninf = float(\"inf\")\ndef find_height(node):\n nodes[node]=1\n for i in graph[node]:\n nodes[node]+=find_height(i)\n return nodes[node]\ndef find_sum(node):\n suma=nodes[node]\n maxa=0\n for i in graph[node]:\n maxa=max(find_sum(i),maxa)\n return maxa+suma\nfor i in range(int(input())):\n n=int(input())\n l=list(map(int,input().split()))\n graph=defaultdict(set)\n for i in range(len(l)):\n\n graph[l[i]].add(i+2)\n nodes=defaultdict(int)\n find_height(1)\n ans=find_sum(1)\n print(ans)\n\n\n\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n3\\n1 1\\n5\\n1 1 2 2\\n\\n', 'output': '4\\n9\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/SUBMEXS'}","problem_id":"vfc_1914","program":"```python\n# cook your dish here\n# cook your dish here\nfrom math import log2;\nimport sys;\n\nsys.setrecursionlimit(10 ** 7)\nfrom collections import defaultdict\n\ninf = float(\"inf\")\ndef find_height(node):\n nodes[node]=1\n for i in graph[node]:\n nodes[node]+=find_height(i)\n return nodes[node]\ndef find_sum(node):\n suma=nodes[node]\n maxa=0\n for i in graph[node]:\n maxa=max(find_sum(i),maxa)\n return maxa+suma\nfor i in range(int(input())):\n n=int(input())\n l=list(map(int,input().split()))\n graph=defaultdict(set)\n for i in range(len(l)):\n\n graph[l[i]].add(i+2)\n nodes=defaultdict(int)\n find_height(1)\n ans=find_sum(1)\n print(ans)\n\n\n\n\n```","inputs":"2\n3\n1 1\n5\n1 1 2 2\n\n","output":"4\n9\n","actual_output":"4\n9\n","execution_success":true,"sample_index":375},{"source":"apps","task_type":"verifiable_code","in_source_id":"769","prompt":"Solve the following coding problem using the programming language python:\n\nPushkar is very good in Number Theory. He takes two numbers $A\\ and\\ B$ and declares them a Pushkar Pair. Pushkar Pair has a property that $A$ has a $Modular\\ Inverse$ modulo $B$. \nHe asks you to tell him the largest number $L$ that divides both of them. \n\n-----Input:-----\n- First line will contain $T$, number of testcases. Then the testcases follow. \n- Each testcase contains of a single line of input, two integers $A, B$. \n\n-----Output:-----\nFor each testcase, output in a single line the integer $L$.\n\n-----Constraints-----\n- $1 \\leq T \\leq 1000$\n- $2 \\leq A,B \\leq 10^4$\n\n-----Sample Input:-----\n1\n3 4\n\n-----Sample Output:-----\n1\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nimport math\nfor i in range(int(input())):\n a,b = map(int,input().split())\n print(math.gcd(a,b))\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n3 4\\n', 'output': '1\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/CACD2020/problems/PPPR'}","problem_id":"vfc_1918","program":"```python\nimport math\nfor i in range(int(input())):\n a,b = map(int,input().split())\n print(math.gcd(a,b))\n```","inputs":"1\n3 4\n","output":"1\n","actual_output":"1\n","execution_success":true,"sample_index":376},{"source":"apps","task_type":"verifiable_code","in_source_id":"770","prompt":"Solve the following coding problem using the programming language python:\n\nYou are given an array $a$ of length $n$. A subsequence of this array is valid, if it satisfies these two conditions:\n- There shouldn't be any two even numbers within a distance of $K$, both which have been chosen in the subsequence. i.e. there shouldn't be two indices $i, j$ such that $a_i$ and $a_j$ are even, $|i - j| \\leq K$ and $a_i$ and $a_j$ are in the subsequence. \n- Similarly, there shouldn't be any two odd numbers within a distance of $K$, both which have been chosen in the subsequence\nThe sum of a subsequence is the sum of all the numbers in it. Your task is find the maximum sum possible in a valid subsequence of the given array. Print this maximum sum.\n\n-----Input-----\n- The first line of the input contains an integer $T$ denoting the number of test cases. The description of the test cases follows.\n- The first line of each test case contains two space-separated integers $n, k$.\n- The second line of each test case contains $n$ space-separated integers denoting the array $a$.\n\n-----Output-----\nFor each test case, output an integer corresponding to the answer of the problem.\n\n-----Constraints-----\n- $1 \\le T \\le 10^5$\n- $1 \\le n \\leq 10^5$\n- $1 \\le k \\leq n$\n- $1 \\le a_i \\leq 10^9$\n- Sum of $n$ over all the test cases doesn't exceed $10^6$\n\n-----Example Input-----\n3\n1 1\n3\n2 1\n2 2\n5 2\n1 2 3 4 6\n\n-----Example Output-----\n3\n2\n11\n\n-----Explanation:-----\nTestcase 2: Only one of the two 2s can be chosen. Hence the answer is 2.\nTestcase 3: The subsequence containing the second, third and fifth numbers is a valid subsequence, and its sum is 2+3+6 = 11. You can check that this is the maximum possible, and hence is the answer.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nimport sys\nimport math\n\ndef main(arr,k):\n \n \n x=[]\n y=[]\n \n \n \n for e in arr:\n if e%2==0:\n x.append(e)\n y.append(0)\n else:\n x.append(0)\n y.append(e)\n \n a=[0]*n\n b=[0]*n\n a[0]=x[0]\n b[0]=y[0]\n for i in range(1,n):\n \n if i0 and x[j]%m==0 and check[j]==0:\n check[j]=1\n my+=1\n #print check\n for j in range(n):\n if x[j]>0 and x[j]%f==0 and check[j]==0:\n check[j]=1\n fy+=1\n if ((((my+fy)*1.0)/n)*100)>=70:\n print(\"Yes\")\n if my>fy:\n print(\"Multan\")\n elif fy>my:\n print(\"Fultan\")\n else:\n print(\"Both\")\n else:\n print(\"No\") \n #print check\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n7\\n2 3\\n4 5 7 8 9 10 14\\n6\\n5 7\\n1 2 8 9 10 11\\n', 'output': 'Yes\\nMultan\\nNo\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/CDGO2016/problems/CDGO1602'}","problem_id":"vfc_1926","program":"```python\nfrom operator import itemgetter\nt=int(input())\nfor i in range(t):\n n=int(input())\n m,f=list(map(int,input().split()))\n x=list(map(int,input().split()))\n my,fy=0,0\n check=[0]*n\n #print check\n for j in range(n):\n if x[j]>0 and x[j]%m==0 and check[j]==0:\n check[j]=1\n my+=1\n #print check\n for j in range(n):\n if x[j]>0 and x[j]%f==0 and check[j]==0:\n check[j]=1\n fy+=1\n if ((((my+fy)*1.0)/n)*100)>=70:\n print(\"Yes\")\n if my>fy:\n print(\"Multan\")\n elif fy>my:\n print(\"Fultan\")\n else:\n print(\"Both\")\n else:\n print(\"No\") \n #print check\n\n```","inputs":"2\n7\n2 3\n4 5 7 8 9 10 14\n6\n5 7\n1 2 8 9 10 11\n","output":"Yes\nMultan\nNo\n","actual_output":"Yes\nMultan\nNo\n","execution_success":true,"sample_index":378},{"source":"apps","task_type":"verifiable_code","in_source_id":"772","prompt":"Solve the following coding problem using the programming language python:\n\nYou are given a binary string S of N bits. The bits in the string are indexed starting from 1. S[i] denotes the ith bit of S.\n\nLet's say that a sequence i1, i2, \u2026, iK(1 \u2264 K; 1 \u2264 i1 < i2 < \u2026 < iK \u2264 N) produces a palindrome when applied to S, if the string S[i1] S[i2] \u2026 S[ik] is a palindrome (that is, reads the same backward or forward).\n\nIn addition, a sequence i1, i2, \u2026, iK(1 \u2264 K; 1 \u2264 i1 < i2 < \u2026 < iK \u2264 N) is said to be exponential, if ij + 1 = p * ij for each integer 1 \u2264 j < K and for some integer p > 1. Note, that a sequence of one element is always exponential.\n\nYour task is to count the number of exponential sequences that produce a palindrome when applied to S.\n\n-----Input-----\nThe first line of input contains an integer T denoting the number of test cases. The description of T test cases follows.\n\nThe only line of description for each test case contains a binary string S of N bits.\n\n-----Output-----\n\nFor each test case, output a single line containing the number of exponential sequences that produce a palindrome.\n\n-----Constraints-----\n- 1 \u2264 T \u2264 10\n- Subtask 1(20 points): 1 \u2264 N \u2264 20\n- Subtask 2(30 points): 1 \u2264 N \u2264 1000\n- Subtask 3(50 points): 1 \u2264 N \u2264 5 \u00d7 105\n\n-----Note-----\n\nThe first test of the first subtask is the example test. It's made for you to make sure that your solution produces the same verdict both on your machine and our server.\n\n-----Time Limits-----\n\nTime limit for the first and the second subtasks is 3s. Time limit for the third subtask is 6s.\n\n-----Example-----\nInput:\n2\n11010\n101001011\n\nOutput:\n9\n18\n\n-----Explanation of the first case in the example test-----\n\nThe following sequences are counted in the answer: {1}, {2}, {3}, {4}, {5}, {1, 2}, {1, 4}, {2, 4}, {1, 2, 4}.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n\n\n\ndef powerset(s):\n n = len(s)\n masks = [1 << j for j in range(n)]\n for i in range(2**n):\n yield [j + 1 for j in range(n) if (masks[j] & i)]\n\n\ndef is_power2(num):\n return num != 0 and ((num & (num - 1)) == 0)\n\n\ndef special(l):\n n = len(l)\n for i in range(n):\n lis = [i + 1]\n yield lis\n for j in range(i + 1, n):\n p = l[j] / l[i]\n if p <= 1 or int(p) != p:\n continue\n lis = [i + 1, j + 1]\n yield lis\n sk = (j + 1) * int(p)\n while sk <= n:\n lis.append(sk)\n sk *= int(p)\n yield lis\n\n\ndef expIndices(l):\n a = list(zip(l, l[1:]))\n if len(a) == 0:\n return True\n else:\n p = a[0][1] / a[0][0]\n if p <= 1 or int(p) != p:\n return False\n for i in range(1, len(a)):\n if a[i][1] / a[i][0] != p:\n return False\n return True\n\n\ndef main():\n for _ in range(eval(input())):\n S = input()\n count = 0\n\n for i in special(range(1, len(S) + 1)):\n s = [S[j - 1] for j in i]\n if s == s[::-1]:\n count += 1\n print(count)\n\ndef __starting_point():\n main()\n\n__starting_point()\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n11010\\n101001011\\n\\n\\n', 'output': '9\\n18\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/LTIME32/problems/EXPALIN'}","problem_id":"vfc_1930","program":"```python\n\n\n\ndef powerset(s):\n n = len(s)\n masks = [1 << j for j in range(n)]\n for i in range(2**n):\n yield [j + 1 for j in range(n) if (masks[j] & i)]\n\n\ndef is_power2(num):\n return num != 0 and ((num & (num - 1)) == 0)\n\n\ndef special(l):\n n = len(l)\n for i in range(n):\n lis = [i + 1]\n yield lis\n for j in range(i + 1, n):\n p = l[j] / l[i]\n if p <= 1 or int(p) != p:\n continue\n lis = [i + 1, j + 1]\n yield lis\n sk = (j + 1) * int(p)\n while sk <= n:\n lis.append(sk)\n sk *= int(p)\n yield lis\n\n\ndef expIndices(l):\n a = list(zip(l, l[1:]))\n if len(a) == 0:\n return True\n else:\n p = a[0][1] / a[0][0]\n if p <= 1 or int(p) != p:\n return False\n for i in range(1, len(a)):\n if a[i][1] / a[i][0] != p:\n return False\n return True\n\n\ndef main():\n for _ in range(eval(input())):\n S = input()\n count = 0\n\n for i in special(range(1, len(S) + 1)):\n s = [S[j - 1] for j in i]\n if s == s[::-1]:\n count += 1\n print(count)\n\ndef __starting_point():\n main()\n\n__starting_point()\n```","inputs":"2\n11010\n101001011\n\n\n","output":"9\n18\n","actual_output":"9\n18\n","execution_success":true,"sample_index":379},{"source":"apps","task_type":"verifiable_code","in_source_id":"773","prompt":"Solve the following coding problem using the programming language python:\n\nA permutation of length n is an array of size n consisting of n distinct integers in the range [1, n]. For example, (3, 2, 4, 1) is a permutation of length 4, but (3, 3, 1, 4) and (2, 3, 4, 5) are not, as (3, 3, 1, 4) contains duplicate elements, and (2, 3, 4, 5) contains elements not in range [1,4].\nA permutation p of length n is good if and only if for any 1 \u2264 i \u2264 n, pi \u2260 i.\nPlease find the lexicographically smallest good permutation p.\nDefinition for \"lexicographically smaller\":\nFor two permutations p and q, we say that p is lexicographically smaller than q if and only if there exists a index 1 \u2264 l \u2264 n such that:\n- For any 1 \u2264 i < l, pi = qi. Note that if l = 1, this constraint means nothing.\n- and, pl < ql.\n\nFor example, (2, 3, 1, 4) < (2, 3, 4, 1) < (3, 4, 1, 2). The lexicographically smallest permutation is, of course, (1, 2, ..., n), though this one is not good.\n\n-----Input-----\nFirst line of the input contains an integer T denoting number of test cases.\nFor each test case, the only line contains an integer n.\n\n-----Output-----\nFor each test case, output the lexicographically smallest good permutation of length n. It's guaranteed that this permutation exists.\n\n-----Constraints-----\n- 1 \u2264 T \u2264 10\n- 2 \u2264 n \u2264 105\n\n-----Subtasks-----\n- Subtask #1 (17 points): 2 \u2264 n \u2264 9\n- Subtask #2 (83 points): Original Constraints\n\n-----Example-----\nInput:\n4\n2\n3\n5\n6\n\nOutput:\n2 1\n2 3 1\n2 1 4 5 3\n2 1 4 3 6 5\n\n-----Explanation-----\nExample case 1. The only good permutation of length 2 is (2, 1).\nExample case 2. Consider all permutations of length 3, they are(in lexicographically order):\n- p = (1, 2, 3), it's not good since p[1] = 1, p[2] = 2 and p[3] = 3;\n- p = (1, 3, 2), it's not good since p[1] = 1;\n- p = (2, 1, 3), it's not good since p[3] = 3;\n- p = (2, 3, 1), it's good since p[1] \u2260 1, p[2] \u2260 2 and p[3] \u2260 3;\n- p = (3, 1, 2), it's good since p[1] \u2260 1, p[2] \u2260 2 and p[3] \u2260 3;\n- p = (3, 2, 1), it's not good since p[2] = 2.\nThus the minimum good one is (2, 3, 1).\nExample case 3. Consider two good permutations for third test case: p=(2, 1, 4, 5, 3) and q=(2, 4, 1, 5, 3), then p < q. You can check lexicographically condition as follows. Find the first index where the entries of two permutations are different, and compare those entries. For example, in this case, the first position where the entries differ is index 2. You can see that p[2] < q[2], as 1 < 4, so p is lexicographically smaller than q.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\ntests = int(input())\r\nfor t in range(tests):\r\n n = int(input())\r\n permut='2'\r\n permut_list=[]\r\n if n%2==0:\r\n for i in range(2, n+1):\r\n if i%2==1:\r\n permut=permut+' '+str(i+1)\r\n else:\r\n permut=permut+' '+str(i-1)\r\n print(permut)\r\n pass\r\n elif n==1:\r\n print(1)\r\n pass\r\n else:\r\n for i in range(2, n):\r\n if i%2==1:\r\n permut_list.append(str(i+1))\r\n else:\r\n permut_list.append(str(i-1))\r\n permut_list.pop(-1)\r\n permut_list.append(str(n))\r\n permut_list.append(str(n-2))\r\n this_permut='2'\r\n for el in permut_list:\r\n this_permut=this_permut+' '+el\r\n print(this_permut)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '4\\n2\\n3\\n5\\n6\\n\\n\\n', 'output': '2 1\\n2 3 1\\n2 1 4 5 3\\n2 1 4 3 6 5\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/MINPERM'}","problem_id":"vfc_1934","program":"```python\ntests = int(input())\r\nfor t in range(tests):\r\n n = int(input())\r\n permut='2'\r\n permut_list=[]\r\n if n%2==0:\r\n for i in range(2, n+1):\r\n if i%2==1:\r\n permut=permut+' '+str(i+1)\r\n else:\r\n permut=permut+' '+str(i-1)\r\n print(permut)\r\n pass\r\n elif n==1:\r\n print(1)\r\n pass\r\n else:\r\n for i in range(2, n):\r\n if i%2==1:\r\n permut_list.append(str(i+1))\r\n else:\r\n permut_list.append(str(i-1))\r\n permut_list.pop(-1)\r\n permut_list.append(str(n))\r\n permut_list.append(str(n-2))\r\n this_permut='2'\r\n for el in permut_list:\r\n this_permut=this_permut+' '+el\r\n print(this_permut)\n```","inputs":"4\n2\n3\n5\n6\n\n\n","output":"2 1\n2 3 1\n2 1 4 5 3\n2 1 4 3 6 5\n","actual_output":"2 1\n2 3 1\n2 1 4 5 3\n2 1 4 3 6 5\n","execution_success":true,"sample_index":380},{"source":"apps","task_type":"verifiable_code","in_source_id":"774","prompt":"Solve the following coding problem using the programming language python:\n\nNobody knows, but $N$ frogs live in Chef's garden.\nNow they are siting on the X-axis and want to speak to each other. One frog can send a message to another one if the distance between them is less or equal to $K$.\nChef knows all $P$ pairs of frogs, which want to send messages. Help him to define can they or not!\nNote : More than $1$ frog can be on the same point on the X-axis.\n\n-----Input-----\n- The first line contains three integers $N$, $K$ and $P$.\n- The second line contains $N$ space-separated integers $A_1$, $A_2$, \u2026, $A_N$ denoting the x-coordinates of frogs\".\n- Each of the next $P$ lines contains two integers $A$ and $B$ denoting the numbers of frogs according to the input.\n\n-----Output-----\nFor each pair print \"Yes\" without a brackets if frogs can speak and \"No\" if they cannot.\n\n-----Constraints-----\n- $1 \\le N, P \\le 10^5$\n- $0 \\le A_i, K \\le 10^9$\n- $1 \\le A, B \\le N$\n\n-----Example-----\n\n-----Sample Input:-----\n5 3 3\n0 3 8 5 12\n1 2\n1 3\n2 5\n\n-----Sample Output:-----\nYes\nYes\nNo\n\n-----Explanation-----\n- \nFor pair $(1, 2)$ frog $1$ can directly speak to the frog $2$ as the distance between them is $3 - 0 = 3 \\le K$ . \n- \nFor pair $(1, 3)$ frog $1$ can send a message to frog $2$, frog $2$ can send it to frog $4$ and it can send it to frog $3$.\n- \nFor pair $(2, 5)$ frogs can't send a message under current constraints.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\nn, k, p = [int(i) for i in input().split()]\nn_sep = list(map(int, input().split()))\ncount = 0\nsep_sort = sorted(n_sep)\nhashing = {sep_sort[0]: 0}\n\nfor j in range(1, n):\n if (abs(sep_sort[j] - sep_sort[j - 1]) > k):\n count += 1\n hashing[sep_sort[j]] = count\n#print(hashing)\nfor i in range(p):\n pair = list(map(int, input().split()))\n \n if hashing[n_sep[pair[1] - 1]] == hashing[n_sep[pair[0] - 1]]:\n print(\"Yes\")\n else:\n print(\"No\")\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '5 3 3\\n0 3 8 5 12\\n1 2\\n1 3\\n2 5\\n', 'output': 'Yes\\nYes\\nNo\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/FROGV'}","problem_id":"vfc_1938","program":"```python\n# cook your dish here\nn, k, p = [int(i) for i in input().split()]\nn_sep = list(map(int, input().split()))\ncount = 0\nsep_sort = sorted(n_sep)\nhashing = {sep_sort[0]: 0}\n\nfor j in range(1, n):\n if (abs(sep_sort[j] - sep_sort[j - 1]) > k):\n count += 1\n hashing[sep_sort[j]] = count\n#print(hashing)\nfor i in range(p):\n pair = list(map(int, input().split()))\n \n if hashing[n_sep[pair[1] - 1]] == hashing[n_sep[pair[0] - 1]]:\n print(\"Yes\")\n else:\n print(\"No\")\n\n```","inputs":"5 3 3\n0 3 8 5 12\n1 2\n1 3\n2 5\n","output":"Yes\nYes\nNo\n","actual_output":"Yes\nYes\nNo\n","execution_success":true,"sample_index":381},{"source":"apps","task_type":"verifiable_code","in_source_id":"775","prompt":"Solve the following coding problem using the programming language python:\n\nAfter six days, professor GukiZ decided to give more candies to his students. Like last time, he has $N$ students, numbered $1$ through $N$. Let's denote the number of candies GukiZ gave to the $i$-th student by $p_i$. As GukiZ has a lot of students, he does not remember all the exact numbers of candies he gave to the students. He only remembers the following properties of the sequence $p$:\n- The numbers of candies given to each of the first $K$ students ($p_1, p_2, \\dots, p_K$) are known exactly.\n- All elements of the sequence $p$ are distinct and positive.\n- GukiZ didn't give more than $x$ candies to any student (the maximum value in the sequence $p$ is not greater than $x$).\n- For each student $i$, there is at least one other student $j$ such that $|p_i - p_j| \\le D$.\n- The professor gave out the biggest possible total number of candies, i.e. $S = p_1 + p_2 + p_3 + \\ldots + p_N$ is maximum possible.\nGukiZ would like to know the total number of candies $S$ he had at the beginning. However, times change and after six days, the professor is really tired, so it is possible that there is no sequence $p$ which satisfies the constraints. Can you help GukiZ find the number of candies he gave out, or tell him that he must have made a mistake?\n\n-----Input-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The first line of each test case contains four space-separated integers $N$, $K$, $x$, $D$.\n- The second line contains $K$ distinct space-separated integers $p_1, p_2, \\dots, p_K$.\n\n-----Output-----\nFor each test case, print a single line containing one integer \u2014 the number of candies GukiZ had, or $-1$ if there is no valid sequence $p$.\n\n-----Constraints-----\n- $1 \\le T \\le 50$\n- $3 \\le N \\le 10^9$\n- $1 \\le K \\le \\mathrm{min}(N, 2 \\cdot 10^4)$ \n- $1 \\le x \\le 2 \\cdot 10^9$\n- $1 \\le D \\le 10^9$\n- $1 \\le p_i \\le x$ for each valid $i$\n- All values $p_i$ from input are distinct\n\n-----Subtasks-----\nSubtask #1 (15 points): $1 \\leq x, N, D \\leq 15$ \nSubtask #2 (35 points): $1 \\leq x, N, D \\leq 10^5$ \nSubtask #3 (50 points): original constraints\n\n-----Example Input-----\n2\n4 3 5 3\n2 1 5\n3 2 8 2\n3 8\n\n-----Example Output-----\n12\n-1\n\n-----Explanation-----\nExample case 1: There are four students. We know that the first student got $p_1 = 2$ candies, the second student got $p_2 = 1$ and the third got $p_3 = 5$ candies; we don't know the number of candies given to the last student. The maximum possible amount of candies given to some student is $x=5$. The best possible option is giving $p_4=4$ candies to the last student. Then, the fourth constraint (with $D=3$) is satisfied for all students. Only the pair of students $(2, 3)$ have numbers of candies that differ by more than $3$, but still, for each student, there are at least two other students with close enough numbers of candies.\nExample case 2: GukiZ made some mistake in distribution and there is no valid sequence $p$. The answer is $-1$.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\ntry:\n# https://www.codechef.com/LTIME63B/problems/GHMC\n# Finally.... I properly understood what needs to be done.\n\n def ctlt(arr, val):\n # find number of values in sorted arr < val\n if arr[0] >= val: return 0\n lo = 0\n hi = len(arr)\n while hi-lo > 1:\n md = (hi+lo)//2\n if arr[md] 0:\n ps = list(map(int,z[:k]))\n else:\n ps = [x]\n\n ps.sort()\n\n if x=k:\n if n == k:\n lo = x+d+1 # put out of range\n else:\n # find best maxfill (before val support)\n lo = 1\n hi = x+1\n while hi-lo>1:\n md = (hi+lo)//2\n v = (x-md+1) + ctlt(ps,md)\n if v= valchecked: \n # support all vals\n for p in ps[valchecked+1:checkto+1]:\n if lastp+d >= p:\n isolbelow = False\n elif isolbelow:\n valsdone = False\n fillval += lastp+d\n n -= 1\n isolbelow = (p > lastp + 2*d )\n else:\n isolbelow = True\n lastp = p\n valchecked = checkto\n if valsdone and isolbelow: \n # check gap to maxfill\n if lastp + d >= lo:\n isolbelow = False\n else:\n valsdone = False\n fillval += lastp\n ps[checkto] += d\n lastp += d\n isolbelow = False\n n -= 1\n\n if k > n:\n print(-1)\n elif k == n:\n print(sum(ps) + fillval)\n elif k == n-1 and lo > ps[-1]:\n print(sum(ps) + fillval + min(x,ps[-1]+d))\n else:\n tot = (x+lo)*(x-lo+1)//2 + sum(ps[:ctlt(ps,lo)])\n print(tot + fillval)\nexcept:\n pass\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n4 3 5 3\\n2 1 5\\n3 2 8 2\\n3 8\\n', 'output': '12\\n-1\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/GHMC'}","problem_id":"vfc_1942","program":"```python\ntry:\n# https://www.codechef.com/LTIME63B/problems/GHMC\n# Finally.... I properly understood what needs to be done.\n\n def ctlt(arr, val):\n # find number of values in sorted arr < val\n if arr[0] >= val: return 0\n lo = 0\n hi = len(arr)\n while hi-lo > 1:\n md = (hi+lo)//2\n if arr[md] 0:\n ps = list(map(int,z[:k]))\n else:\n ps = [x]\n\n ps.sort()\n\n if x=k:\n if n == k:\n lo = x+d+1 # put out of range\n else:\n # find best maxfill (before val support)\n lo = 1\n hi = x+1\n while hi-lo>1:\n md = (hi+lo)//2\n v = (x-md+1) + ctlt(ps,md)\n if v= valchecked: \n # support all vals\n for p in ps[valchecked+1:checkto+1]:\n if lastp+d >= p:\n isolbelow = False\n elif isolbelow:\n valsdone = False\n fillval += lastp+d\n n -= 1\n isolbelow = (p > lastp + 2*d )\n else:\n isolbelow = True\n lastp = p\n valchecked = checkto\n if valsdone and isolbelow: \n # check gap to maxfill\n if lastp + d >= lo:\n isolbelow = False\n else:\n valsdone = False\n fillval += lastp\n ps[checkto] += d\n lastp += d\n isolbelow = False\n n -= 1\n\n if k > n:\n print(-1)\n elif k == n:\n print(sum(ps) + fillval)\n elif k == n-1 and lo > ps[-1]:\n print(sum(ps) + fillval + min(x,ps[-1]+d))\n else:\n tot = (x+lo)*(x-lo+1)//2 + sum(ps[:ctlt(ps,lo)])\n print(tot + fillval)\nexcept:\n pass\n```","inputs":"2\n4 3 5 3\n2 1 5\n3 2 8 2\n3 8\n","output":"12\n-1\n","actual_output":"12\n-1\n","execution_success":true,"sample_index":382},{"source":"apps","task_type":"verifiable_code","in_source_id":"778","prompt":"Solve the following coding problem using the programming language python:\n\nGiven an Integer N, write a program to reverse it.\n\n-----Input-----\n\nThe first line contains an integer T, total number of testcases. Then follow T lines, each line contains an integer N. \n\n-----Output-----\nFor each test case, display the reverse of the given number N, in a new line.\n\n-----Constraints-----\n- 1 \u2264 T \u2264 1000\n- 1 \u2264 N \u2264 1000000\n\n-----Example-----\nInput\n4\n12345\n31203\n2123\n2300\nOutput\n54321\n30213\n3212\n32\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\nx=int(input())\nfor i in range(x):\n s=input()\n print(int(s[::-1]))\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '4\\n12345\\n31203\\n2123\\n2300\\n', 'output': '54321\\n30213\\n3212\\n32\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/FLOW007'}","problem_id":"vfc_1954","program":"```python\n# cook your dish here\nx=int(input())\nfor i in range(x):\n s=input()\n print(int(s[::-1]))\n\n```","inputs":"4\n12345\n31203\n2123\n2300\n","output":"54321\n30213\n3212\n32\n","actual_output":"54321\n30213\n3212\n32\n","execution_success":true,"sample_index":385},{"source":"apps","task_type":"verifiable_code","in_source_id":"780","prompt":"Solve the following coding problem using the programming language python:\n\n\"Ring Ring!!\" \nSherlock's phone suddenly started ringing. And it was none other than Jim Moriarty..\n\"Long time no see ! You miss me right ? Anyway we'll talk about it later . Let me first tell you something. Dr.Watson is with me . And you've got only one chance to save him . Here's your challenge:.\nGiven a number N and another number M, tell if the remainder of N%M is odd or even. If it's odd, then print \"ODD\" else print \"EVEN\" \n\nIf Sherlock can answer the query correctly, then Watson will be set free. He has approached you for help since you being a programmer.Can you help him? \n\n-----Input-----\nThe first line contains, T, the number of test cases..\nEach test case contains an integer, N and M\n\n-----Output-----\nOutput the minimum value for each test case \n\n-----Constraints-----\n1 = T = 20\n1 <= N <= 10^18 \n1 <= M<= 10^9 \n\n-----Subtasks-----\nSubtask #1 : (20 points)\n1 = T = 20\n1 <= N <= 100 \n1 <= M<= 100 \n\nSubtask 2 : (80 points) \n\n1 = T = 20\n1 <= N <= 10^18 \n1 <= M<= 10^9 \n\n-----Example-----\nInput:\n2\n4 4\n6 5\n\nOutput:\nEVEN\nODD\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nimport sys\nuser_input = sys.stdin.readline().split()\n\nT = int(user_input[0])\n\nfor j in range(T) :\n\n var = sys.stdin.readline().split()\n N = int(var[0])\n M = int(var[1])\n\n if (N%M)%2 :\n print(\"ODD\")\n else :\n print(\"EVEN\")\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n4 4\\n6 5\\n', 'output': 'EVEN\\nODD\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/LOCMAY18/problems/REMAIN'}","problem_id":"vfc_1962","program":"```python\nimport sys\nuser_input = sys.stdin.readline().split()\n\nT = int(user_input[0])\n\nfor j in range(T) :\n\n var = sys.stdin.readline().split()\n N = int(var[0])\n M = int(var[1])\n\n if (N%M)%2 :\n print(\"ODD\")\n else :\n print(\"EVEN\")\n```","inputs":"2\n4 4\n6 5\n","output":"EVEN\nODD\n","actual_output":"EVEN\nODD\n","execution_success":true,"sample_index":387},{"source":"apps","task_type":"verifiable_code","in_source_id":"781","prompt":"Solve the following coding problem using the programming language python:\n\nXorgon is an extremely delicious treat formed by the sequence $S$ of binary integers $s_1, s_2,..,s_N$. A really interesting property found in a Xorgon is that the xor of all elements in any contiguous subsequence of length $K$ in $S$ will result in $1$. \nChef has been asked to prepare a Xorgon. However, he has at his disposal a binary sequence $X$ containing the binary integers $x_1, x_2, ...x_N$. To prepare a Xorgon, the chef may flip the value of as many binary digits in $X$ as required.(i.e. turn a $1$ to a $0$ and $0$ to a $1$). Unfortunately, flipping a digit takes a lot of time and the chef has to serve many orders. Can you help the chef calculate the minimum number of flips required to cook a Xorgon from the given $X$?\n\n-----Input:-----\n- The first line will contain two space-separated integers $N, K$.\n- Next line contains N space-separated integers $x_1, x_2, ...,x_N$. \n\n-----Output:-----\nOutput in a single line minimum number of flips required to turn $X$ into a Xorgon.\n\n-----Constraints-----\n- $1 \\leq K \\leq N \\leq 3*10^6$\n- $0 \\leq x_i \\leq 1$\n\n-----Sample Input:-----\n7 5\n1 0 0 1 1 1 1\n\n-----Sample Output:-----\n1\n\n-----EXPLANATION:-----\nFlip the last bit from 1 to 0 to obtain a Xorgon.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\nfrom sys import stdin,stdout\n\na0=0\na1=1\nn,k=stdin.readline().strip().split(' ')\nn,k=int(n),int(k)\n\narr=list(map(int,stdin.readline().strip().split(' ')))\n\n\n\ndef solve(n,k,arr):\n sol=[]\n\n l=0;u=k;\n\n\n while l!=u:\n sol.append(arr[l:min(len(arr),u)])\n l=min(l+k,len(arr))\n u=min(u+k,len(arr))\n \n tiwari=[]\n for i in range(k):\n titi=0\n gao=0\n for j in range(len(sol)):\n if len(sol[j])>i:\n if sol[j][i]==0:\n titi+=1\n else:\n gao+=1\n tiwari.append((titi,gao))\n\n minflip=(-1,-1)\n ans=0\n ctr=0\n for i in tiwari:\n if i[0]i:\n if sol[j][i]==0:\n titi+=1\n else:\n gao+=1\n tiwari.append((titi,gao))\n\n minflip=(-1,-1)\n ans=0\n ctr=0\n for i in tiwari:\n if i[0] c:\n return -1\n y = arr[i][m-1] if m-1 in arr[i] else m-1\n x = arr[i][0] if 0 in arr[i] else 0\n return y-x\n\nfor i in range(n):\n print(chefbm(arr,i))\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '4 4 6\\n2 2\\n3 2\\n3 2\\n4 3\\n4 4\\n4 3\\n', 'output': '3\\n3\\n-1\\n4\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/MAY14/problems/CHEFBM'}","problem_id":"vfc_1978","program":"```python\nimport sys\nimport os\nimport random\nimport math\n#nonlocal defs\nn, m, p = list(map(int, input().split()))\narr = [dict() for _ in range(n)]\nfor _ in range(p):\n i,j = list(map(int,input().split()))\n i -= 1\n j -= 1\n if j not in arr[i]:\n arr[i][j] = j+1\n else:\n arr[i][j] += 1\n\ndef chefbm(arr,i):\n for (e,f) in arr[i].items():\n if e == m-1:\n continue\n if e+1 in arr[i]:\n c = arr[i][e+1]\n else:\n c = e+1\n if arr[i][e] > c:\n return -1\n y = arr[i][m-1] if m-1 in arr[i] else m-1\n x = arr[i][0] if 0 in arr[i] else 0\n return y-x\n\nfor i in range(n):\n print(chefbm(arr,i))\n```","inputs":"4 4 6\n2 2\n3 2\n3 2\n4 3\n4 4\n4 3\n","output":"3\n3\n-1\n4\n","actual_output":"3\n3\n-1\n4\n","execution_success":true,"sample_index":391},{"source":"apps","task_type":"verifiable_code","in_source_id":"785","prompt":"Solve the following coding problem using the programming language python:\n\nOne of Chef's friends offered him a deal: during $D$ days, they are going to exchange money. For each $i$ ($1 \\le i \\le D$), on the $i$-th day, Chef's friend would give Chef $A$ rupees, while Chef would give his friend $2^{i-1}$ rupees ($1$ rupee on day $1$, $2$ rupees on day $2$, $4$ rupees on day $3$, and so on). Chef's profit from the deal is the total number of rupees he received from his friend minus the total number of rupees he gave his friend.\nChef decided to ask for your advice before accepting the deal. You want to help him by telling him two numbers $D_1$ and $D_2$, where $D_1$ is the maximum value of $D$ such that Chef should accept the deal, i.e. his profit from the deal is positive if $D = D_1$, and $D_2$ is the value of $D$ that leads to the maximum possible profit for Chef. If there are multiple values of $D$ that lead to the maximum profit, $D_2$ is the smallest of these values.\n\n-----Input-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The first and only line of each test case contains a single integer $A$.\n\n-----Output-----\nFor each test case, print a single line containing two space-separated integers $D_1$ and $D_2$.\n\n-----Constraints-----\n- $1 \\le T \\le 100,000$\n- $5 \\le A \\le 10^9$\n\n-----Subtasks-----\nSubtask #1 (100 points): original constraints\n\n-----Example Input-----\n4\n5\n8\n9\n1000000000\n\n-----Example Output-----\n4 3\n5 3\n5 4\n35 30\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\na = int(input())\nfor i in range(a):\n b = int(input())\n li = []\n if b == 2:\n print(2,1)\n elif b == 3:\n print(3,2)\n elif b == 4:\n print(4,2)\n else:\n for t in range(b+1):\n if ((b*t)+1-(2**t))<0:\n li.append(t-1)\n break\n for o in range(b+1):\n if b<=2**(o):\n li.append(o)\n break\n print(*li)\n \n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '4\\n5\\n8\\n9\\n1000000000\\n', 'output': '4 3\\n5 3\\n5 4\\n35 30\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/TRICKYDL'}","problem_id":"vfc_1982","program":"```python\n# cook your dish here\na = int(input())\nfor i in range(a):\n b = int(input())\n li = []\n if b == 2:\n print(2,1)\n elif b == 3:\n print(3,2)\n elif b == 4:\n print(4,2)\n else:\n for t in range(b+1):\n if ((b*t)+1-(2**t))<0:\n li.append(t-1)\n break\n for o in range(b+1):\n if b<=2**(o):\n li.append(o)\n break\n print(*li)\n \n\n```","inputs":"4\n5\n8\n9\n1000000000\n","output":"4 3\n5 3\n5 4\n35 30\n","actual_output":"4 3\n5 3\n5 4\n35 30\n","execution_success":true,"sample_index":392},{"source":"apps","task_type":"verifiable_code","in_source_id":"786","prompt":"Solve the following coding problem using the programming language python:\n\nThe chef was not happy with the binary number system, so he designed a new machine which is having 6 different states, i.e. in binary there is a total of 2 states as 0 and 1. Now, the chef is confused about how to correlate this machine to get an interaction with Integer numbers, when N(Integer number) is provided to the system, what will be the Nth number that system will return(in Integer form), help the chef to design this system.\n\n-----Input:-----\n- First-line will contain $T$, the number of test cases. Then the test cases follow. \n- Each test case contains a single line of input, $N$. \n\n-----Output:-----\nFor each test case, output in a single line answer given by the system.\n\n-----Constraints-----\n- $1 \\leq T \\leq 10^5$\n- $1 \\leq N \\leq 10^5$\n\n-----Sample Input:-----\n2\n3\n5\n\n-----Sample Output:-----\n7\n37\n\n-----EXPLANATION:-----\nInitial numbers for system = [1, 6, 7, 36, 37, 42, 43, 216, \u2026..\nFor 1) 3rd Number for the system will be 7.\nFor 2) 5th Number for the system will be 37.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfrom sys import stdin, stdout\r\n#from math import gcd as g\r\n#a,b = map(int, stdin.readline().split())\r\n#l1 = list(map(int, stdin.readline().split()))\r\nl = [1,6,7]\r\nc = 1\r\nfor x in range(3,100001):\r\n if x%2==1:\r\n a = l[c]*6\r\n l.append(a)\r\n else:\r\n l.append(a+1)\r\n c+=1\r\nn = int(stdin.readline())\r\nfor _ in range(n):\r\n s = int(stdin.readline())\r\n print(l[s-1])\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n3\\n5\\n', 'output': '7\\n37\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/PBK22020/problems/ITGUY23'}","problem_id":"vfc_1986","program":"```python\nfrom sys import stdin, stdout\r\n#from math import gcd as g\r\n#a,b = map(int, stdin.readline().split())\r\n#l1 = list(map(int, stdin.readline().split()))\r\nl = [1,6,7]\r\nc = 1\r\nfor x in range(3,100001):\r\n if x%2==1:\r\n a = l[c]*6\r\n l.append(a)\r\n else:\r\n l.append(a+1)\r\n c+=1\r\nn = int(stdin.readline())\r\nfor _ in range(n):\r\n s = int(stdin.readline())\r\n print(l[s-1])\n```","inputs":"2\n3\n5\n","output":"7\n37\n","actual_output":"7\n37\n","execution_success":true,"sample_index":393},{"source":"apps","task_type":"verifiable_code","in_source_id":"787","prompt":"Solve the following coding problem using the programming language python:\n\nLimak is a little polar bear.\nHe is playing a video game and he needs your help.\nThere is a row with N cells, each either empty or occupied by a soldier, denoted by '0' and '1' respectively.\nThe goal of the game is to move all soldiers to the right (they should occupy some number of rightmost cells).\nThe only possible command is choosing a soldier and telling him to move to the right as far as possible.\nChoosing a soldier takes 1 second, and a soldier moves with the speed of a cell per second.\nThe soldier stops immediately if he is in the last cell of the row or the next cell is already occupied.\nLimak isn't allowed to choose a soldier that can't move at all (the chosen soldier must move at least one cell to the right).\nLimak enjoys this game very much and wants to play as long as possible.\nIn particular, he doesn't start a new command while the previously chosen soldier moves.\nCan you tell him, how many seconds he can play at most?\n\n-----Input-----\nThe first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.\n\nThe only line of each test case contains a string S describing the row with N cells.\nEach character is either '0' or '1', denoting an empty cell or a cell with a soldier respectively.\n\n-----Output-----\nFor each test case, output a single line containing one integer \u2014 the maximum possible number of seconds Limak will play the game.\n\n-----Constraints-----\n- 1 \u2264 T \u2264 5\n- 1 \u2264 N \u2264 105 (N denotes the length of the string S)\n\n-----Subtasks-----\n- Subtask #1 (25 points): 1 \u2264 N \u2264 10\n- Subtask #2 (25 points): 1 \u2264 N \u2264 2000\n- Subtask #3 (50 points): Original constraints.\n\n-----Example-----\nInput:\n4\n10100\n1100001\n000000000111\n001110100011010\n\nOutput:\n8\n10\n0\n48\n\n-----Explanation-----\nTest case 1.\nThe initial string is 10100.\nThere are N = 5 cells.\nThere is one soldier in the first cell, and one soldier in the third cell.\nThe following scenario maximizes the total time:\n- Limak chooses the soldier in the first cell.\nThis soldier can move only one cell to the right.\nIt takes 1 second to choose a soldier and 1 second for a soldier to move to the next cell (2 seconds in total).\nThe string is 01100 now.\n- Limak has only one choice.\nHe must choose the soldier in the third cell because the other soldier can't move at all (the soldier in the second cell can't move to the right because the next cell is already occupied).\nChoosing a soldier takes 1 second.\nThe chosen soldier moves from the third cell to the fifth cell, which takes 2 seconds.\nThis operation takes 1 + 2 = 3 seconds in total.\nThe string is 01001 now.\n- Limak has only one choice again.\nSince the soldier in the last row can't move further to the right, the soldier in the second cell must be chosen.\nHe will move 2 cells to the right.\nThis operation takes 1 + 2 = 3 seconds in total.\nThe string become 00011 and the game is over.\nThe total time is 2 + 3 + 3 = 8.\nTest case 2.\nThe initial string is 1100001.\nThere is only one possible scenario:\n- 1100001 is changed to 1000011 in 5 seconds (1 second to choose a soldier and 4 seconds for the soldier to move 4 cells to the right).\n- 1000011 is changed to 0000111 in 5 seconds.\n\nThe total time is 5 + 5 = 10 seconds.\nTest case 3.\nThe game is over immediately because all soldiers occupy rightmost cells already.\nThe answer is 0.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfor _ in range(int(input())):\n l=list(map(int,input().strip()))\n for j in range(len(l)-1,-1,-1):\n if l[j]==1:\n l.pop()\n else:\n break\n if l.count(1):\n time,prev,z,c=0,0,0,0\n for j in range(len(l)-1,-1,-1):\n if l[j]==0:\n z+=1\n continue\n if prev!=z:\n prev=z\n c+=1\n time+=c+z\n\n print(time)\n else:\n print(0)\n\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '4\\n10100\\n1100001\\n000000000111\\n001110100011010\\n', 'output': '8\\n10\\n0\\n48\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/ROWSOLD'}","problem_id":"vfc_1990","program":"```python\nfor _ in range(int(input())):\n l=list(map(int,input().strip()))\n for j in range(len(l)-1,-1,-1):\n if l[j]==1:\n l.pop()\n else:\n break\n if l.count(1):\n time,prev,z,c=0,0,0,0\n for j in range(len(l)-1,-1,-1):\n if l[j]==0:\n z+=1\n continue\n if prev!=z:\n prev=z\n c+=1\n time+=c+z\n\n print(time)\n else:\n print(0)\n\n\n```","inputs":"4\n10100\n1100001\n000000000111\n001110100011010\n","output":"8\n10\n0\n48\n","actual_output":"8\n10\n0\n48\n","execution_success":true,"sample_index":394},{"source":"apps","task_type":"verifiable_code","in_source_id":"788","prompt":"Solve the following coding problem using the programming language python:\n\nIf Give an integer N . Write a program to obtain the sum of the first and last digits of this number.\n\n-----Input-----\n\nThe first line contains an integer T, the total number of test cases. Then follow T lines, each line contains an integer N. \n\n-----Output-----\nFor each test case, display the sum of first and last digits of N in a new line.\n\n-----Constraints-----\n- 1 \u2264 T \u2264 1000\n- 1 \u2264 N \u2264 1000000\n\n-----Example-----\nInput\n3 \n1234\n124894\n242323\n\nOutput\n5\n5\n5\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nn = int(input())\nfor i in range(n):\n s = input()\n l = len(s)\n n1 = int(s[0])\n n2 = int(s[l-1])\n print(n1+n2)\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\n1234\\n124894\\n242323\\n', 'output': '5\\n5\\n5\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/FLOW004'}","problem_id":"vfc_1994","program":"```python\nn = int(input())\nfor i in range(n):\n s = input()\n l = len(s)\n n1 = int(s[0])\n n2 = int(s[l-1])\n print(n1+n2)\n\n```","inputs":"3\n1234\n124894\n242323\n","output":"5\n5\n5\n","actual_output":"5\n5\n5\n","execution_success":true,"sample_index":395},{"source":"apps","task_type":"verifiable_code","in_source_id":"792","prompt":"Solve the following coding problem using the programming language python:\n\nDustin, is the head of an Intelligence agency. He wants to send a secret message S$S$ to his colleague.The message is a single word consisting of only lowercase english letters but he decides to encrypt the message for security reasons. He makes a string M$M$ of length N$N$, such that after deleting a substring of non-zero length from M$M$, the remaining string is S$S$.\nCalculate the number of all such possible strings he can form.\n\n-----Input:-----\n- First line will contain T$T$, number of testcases. Then the testcases follow.\n- For each testcase the there is a single line which contains an integer, N$N$ and then a string S$S$.\n\n-----Output:-----\nFor each testcase, output the number of possible strings modulo 109+7$10^9+7$.\n\n-----Constraints-----\n- 1\u2264T\u226450$1 \\leq T \\leq 50$\n- 1\u2264N\u22641018$1 \\leq N \\leq 10^{18}$\n- 1\u2264|S|\u2264105$1 \\leq |S| \\leq 10^5$\n- S$S$ can contain only lowercase English letters.\n\n-----Sample Input:-----\n2\n\n3 a\n\n3 ab \n\n-----Sample Output:-----\n1326\n\n76\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\nt = int(input())\n\nfor _ in range(t):\n\n n,s = input().split()\n\n N = int(n) \n r = N - len(s)\n\n count = 0\n\n if N>len(s):\n\n count = pow(26, r-1,(10**9+7))\n count*= (26+25*len(s))\n\n count = count%(10**9 + 7)\n print(count)\n\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n3 a\\n3 ab\\n', 'output': '1326\\n76\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/ICL1904'}","problem_id":"vfc_2010","program":"```python\n# cook your dish here\nt = int(input())\n\nfor _ in range(t):\n\n n,s = input().split()\n\n N = int(n) \n r = N - len(s)\n\n count = 0\n\n if N>len(s):\n\n count = pow(26, r-1,(10**9+7))\n count*= (26+25*len(s))\n\n count = count%(10**9 + 7)\n print(count)\n\n\n```","inputs":"2\n3 a\n3 ab\n","output":"1326\n76\n","actual_output":"1326\n76\n","execution_success":true,"sample_index":399},{"source":"apps","task_type":"verifiable_code","in_source_id":"793","prompt":"Solve the following coding problem using the programming language python:\n\nAs lockdown is going on so no is allowed to go outside , so Chef has come with an innovative idea for food home delivery using drone. But there is an issue with it , the drone can move forward or backward a fix number of steps $x$ . \nAll the houses and chef restaurant are all in a straight line . Homes which need delivery are located at $H[i]$ and chef is located at $y$ coordinate . \nIf Drone is at a location $R$, then it can move to $R-x$ or $R+x$ . \nHelp chef find maximum value of $x$ to complete all the deliveries as he is busy managing the orders.\n\n-----Input:-----\n- First line will contain $n$ and $R$, number of houses that need delivery and the correct coordinate of chef (Drone).\n- Second line contains $n$ integers , the coordinate of all homes that need delivery. \n\n-----Output:-----\n- The maximum value of $x$ , so that drone delivers to all houses.\n\n-----Constraints-----\n- $1 \\leq n \\leq 1000$\n- $1 \\leq R \\leq 10^9$\n- $1 \\leq hi \\leq 10^9$\n- $1 \\leq x \\leq 10^9$\n\n-----Sample Input:-----\n3 1\n3 5 11\n\n-----Sample Output:-----\n2\n\n-----EXPLANATION:-----\nChef's drone is at 1 initially and he needs to visit 3,5,11 , so optimal solution will be (maximum value of x ) equal to 2.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\nimport math\ntry:\n n,d=map( int,input().split() )\n a=list(map(int,input().split()))\n a.sort()\n z=abs(a[0]-d)\n for j in range(n):\n x=abs(a[j]-d)\n z=math.gcd(x,z)\n print(z) \n \n \nexcept:\n pass\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3 1\\n3 5 11\\n', 'output': '2\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/LDT42020/problems/DRONEDEL'}","problem_id":"vfc_2014","program":"```python\n# cook your dish here\nimport math\ntry:\n n,d=map( int,input().split() )\n a=list(map(int,input().split()))\n a.sort()\n z=abs(a[0]-d)\n for j in range(n):\n x=abs(a[j]-d)\n z=math.gcd(x,z)\n print(z) \n \n \nexcept:\n pass\n```","inputs":"3 1\n3 5 11\n","output":"2\n","actual_output":"2\n","execution_success":true,"sample_index":400},{"source":"apps","task_type":"verifiable_code","in_source_id":"797","prompt":"Solve the following coding problem using the programming language python:\n\nChef is a very experienced and well-known cook. He has participated in many cooking competitions in the past \u2014 so many that he does not even remember them all.\nOne of these competitions lasted for a certain number of days. The first day of the competition was day $S$ of the week (i.e. Monday, Tuesday etc.) and the last day was day $E$ of the week. Chef remembers that the duration of the competition (the number of days between the first and last day, inclusive) was between $L$ days and $R$ days inclusive. Is it possible to uniquely determine the exact duration of the competition? If so, what is this duration?\n\n-----Input-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The first and only line of each test case contains two space-separated strings $S$ and $E$, followed by a space and two space-separated integers $L$ and $R$.\n\n-----Output-----\nFor each test case, print a single line containing:\n- the string \"impossible\" if there is no duration consistent with all given information\n- the string \"many\" if there is more than one possible duration\n- one integer \u2014 the duration of the competition, if its duration is unique\n\n-----Constraints-----\n- $1 \\le T \\le 10,000$\n- $1 \\le L \\le R \\le 100$\n- $S$ is one of the strings \"saturday\", \"sunday\", \"monday\", \"tuesday\", \"wednesday\", \"thursday\" or \"friday\"\n- $E$ is one of the strings \"saturday\", \"sunday\", \"monday\", \"tuesday\", \"wednesday\", \"thursday\" or \"friday\"\n\n-----Subtasks-----\nSubtask #1 (100 points): original constraints\n\n-----Example Input-----\n3\nsaturday sunday 2 4\nmonday wednesday 1 20\nsaturday sunday 3 5\n\n-----Example Output-----\n2\nmany\nimpossible\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\nd=[\"saturday\",\"sunday\",\"monday\",\"tuesday\",\"wednesday\",\"thursday\",\"friday\"]\nt=int(input())\nfor i in range(t):\n s,e,l,r=map(str,input().split())\n l,r=int(l),int(r)\n v=(d.index(e)-d.index(s)+8)%7\n c=r+1\n for i in range(l,r+1):\n if i%7==v:\n c=i\n break\n if c>r:\n print('impossible')\n elif c+7<=r:\n print('many')\n else:\n print(c)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\nsaturday sunday 2 4\\nmonday wednesday 1 20\\nsaturday sunday 3 5\\n', 'output': '2\\nmany\\nimpossible\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/EVENT'}","problem_id":"vfc_2030","program":"```python\n# cook your dish here\nd=[\"saturday\",\"sunday\",\"monday\",\"tuesday\",\"wednesday\",\"thursday\",\"friday\"]\nt=int(input())\nfor i in range(t):\n s,e,l,r=map(str,input().split())\n l,r=int(l),int(r)\n v=(d.index(e)-d.index(s)+8)%7\n c=r+1\n for i in range(l,r+1):\n if i%7==v:\n c=i\n break\n if c>r:\n print('impossible')\n elif c+7<=r:\n print('many')\n else:\n print(c)\n```","inputs":"3\nsaturday sunday 2 4\nmonday wednesday 1 20\nsaturday sunday 3 5\n","output":"2\nmany\nimpossible\n","actual_output":"2\nmany\nimpossible\n","execution_success":true,"sample_index":404},{"source":"apps","task_type":"verifiable_code","in_source_id":"798","prompt":"Solve the following coding problem using the programming language python:\n\nZonal Computing Olympiad 2013, 10 Nov 2012\n\nLittle Red Riding Hood is carrying a basket with berries through the forest to her grandmother's house. The forest is arranged in the form of a square N \u00d7 N grid of cells. The top left corner cell, where Little Red Riding Hood starts her journey, is numbered (1,1) and the bottom right corner cell, where her grandmother lives, is numbered (N,N). In each step, she can move either one position right or one position down.\n\nThe forest is full of dangerous wolves and she is looking for a safe path to reach her destination. Little Red Riding Hood's fairy godmother has placed some special anti-wolf magical charms in some of the cells in the grid. Each charm has a strength. If the charm in cell (i,j) has strength k then its zone of influence is all the cells within k steps of (i,j); that is, all cells (i',j') such that |i - i'| + |j - j'| \u2264 k. A cell within the zone of influence of a charm is safe from wolves. A safe path from (1,1) to (N,N) is one in which every cell along the path is safe.\n\nLittle Red Riding Hood is carrying a basket with berries. In each cell, she drops some berries while pushing her way through the thick forest. However, sometimes she is also able to pick up fresh berries. Each cell is labelled with an integer that indicates the net change in the number of berries in her basket on passing through the cell; that is, the number of berries she picks up in that cell minus the number of berries she drops. You can assume that there are enough berries in her basket to start with so that the basket never becomes empty.\n\nLittle Red Riding Hood knows the positions and strengths of all the magic charms and is looking for a safe path along which the number of berries she has in the basket when she reaches her grandmother's house is maximized.\n\nAs an example consider the following grid:\n\n3 3 2 4 3 \n2 1 -1 -2 2 \n-1 2 4 3 -3 \n-2 2 3 2 1 \n3 -1 2 -1 2 \n\nSuppose there are 3 magic charms, at position (1,2) with strength 2, at position (4,5) with strength 2 and one at position (4,2) with strength 1. The positions within the zone of influence of these three charms are indicated in the three grids below using X's. \n\nX X X X . . . . . . . . . . .\nX X X . . . . . . X . . . . .\n. X . . . . . . X X . X . . .\n. . . . . . . X X X X X X . .\n. . . . . . . . X X . X . . .\n\nPutting these together, the cells that are under the zone of influence of at least one charm are marked with X below.\n\nX X X X .\nX X X . X\n. X . X X\nX X X X X\n. X . X X\n\nHere are two examples of safe paths in this grid, marked using Y's. \n\nY Y X X . Y X X X .\nX Y X . X Y Y X . X\n. Y . X X . Y . X X\nX Y Y Y Y X Y Y Y X\n. X . X Y . X . Y Y\n\nAlong the first path, she accumulates 19 berries while on the second path she collects 16 berries. You can verify that among all safe paths, the maximum number of berries she can collect is 19. \n\nYour task is to help Little Red Riding Hood find out if there is at least one safe path and, if so, compute the maximum number of berries she can collect among all safe paths (which may be a negative number, in which case it is the minimum number of berries she will lose among all safe paths).\n\n-----Input format-----\nLine 1: Two space separated integers N and M, giving the dimension of the grid and the number of magic charms, respectively\n\nLines 2 to N+1: These N lines desribe the grid. Line i+1 contains N space separated integers, describing the net change in berries in the N cells along row i of the grid.\n\nLines N+2 to N+M+1: These M lines describe the magic charms. Each of these lines has 3 integers: the first two integers describe the position of the charm in the grid and the third integer describes its strength.\n\n-----Output format-----\nThe first line of output must either consist of the word YES, if there are safe paths, or the word NO, if there are no safe paths. If the output on the first line is YES then the second line should contain a single integer giving the maximum number of berries Little Red Riding Hood can collect among all safe paths. \n\n-----Sample Input-----\n5 3\n3 3 2 4 3 \n2 1 -1 -2 2 \n-1 2 4 3 -3 \n-2 2 3 2 1 \n3 -1 2 -1 2 \n1 2 2\n4 5 2\n4 2 1\n\n-----Sample Output-----\nYES\n19\n\n-----Test data-----\nIn all subtasks, you may assume that 2 \u2264 N \u2264 500. Each value on the grid is guaranteed to have absolute value not more than 1000. \nLet K denote the maximum strength among all the magic charms.\n- Subtask 1 (30 marks) : 1 \u2264 M \u2264 10, 1 \u2264 K \u2264 1,000.\n- Subtask 2 (70 marks) : 1 \u2264 M \u2264 10,000, 1 \u2264 K \u2264 10.\n\n-----Live evaluation data-----\n- Subtask 1: Testcases 0,1,2,3,4.\n- Subtask 2: Testcases 5,6,7,8.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\nimport sys \ndef dist(a,b):\n return abs(a[0]-b[0])+abs(a[1]-b[1])\nn, m = map(int, input().split())\nmatrix=[]\nid_matrix=[[0 for i in range(n)] for i in range(n)]\nfor _ in range(n):\n matrix.append(list(map(int, input().split())))\ncharms=[]\nfor _ in range(m):\n x,y,lungh = map(int, input().split())\n x-=1 \n y-=1\n charms.append([x,y,lungh])\nif m<=10:\n for i in range(n):\n for j in range(n):\n flag=0\n for charm in charms:\n if dist([i,j],charm[:2])<=charm[2]:\n flag=1\n break\n if flag==0:\n matrix[i][j]=-float('Inf')\n for i in range(1,n):\n matrix[0][i]+=matrix[0][i-1]\n matrix[i][0]+=matrix[i-1][0]\n for i in range(1,n):\n for j in range(1,n):\n matrix[i][j]+=max(matrix[i-1][j], matrix[i][j-1])\nelse:\n for charm in charms:\n for i in range(-charm[2],charm[2]+1):\n appo=charm[2]-abs(i)\n for j in range(-appo, appo+1):\n x=i+charm[0]\n y=j+charm[1]\n if x>=0 and x=0 and y=0 and x=0 and y=2):\n count+=1\n \nprint(count)\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\n1 1 0\\n1 1 1\\n1 0 0\\n', 'output': '2\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/COX22020/problems/ACODEX2'}","problem_id":"vfc_2038","program":"```python\n# cook your dish here\nn = int(input())\ncount = 0\nfor _ in range(n):\n L = list(map(int, input().split()))\n if (L.count(1)>=2):\n count+=1\n \nprint(count)\n\n```","inputs":"3\n1 1 0\n1 1 1\n1 0 0\n","output":"2\n","actual_output":"2\n","execution_success":true,"sample_index":406},{"source":"apps","task_type":"verifiable_code","in_source_id":"800","prompt":"Solve the following coding problem using the programming language python:\n\nChef has provided with a sequence of integers of length $N$ arranged in an unsorted fashion.\nThe elements of the sequence are ordered as ${A1,A2,A3.....A'N}$\nThe task of the chef is to identify the highest and lowest value among the given sequence. It is assured that the sequence given contains the highest and the lowest value always\nPlease help chef in finding the desired value.\n\n-----Input:-----\n- First line will contain $N$, number of elements in the sequence. \n- Next line contains $N$ integers of the sequence . \n\n-----Output:-----\nPrint the HIGHEST and LOWEST value of the sequence respectively.\n\n-----Constraints-----\n- $1 \\leq N \\leq 100$\n- $2 \\leq {A1,A2,A3.....A'N} \\leq 10^4$\n\n-----Sample Input:-----\n5\n3 2 7 9 4\n\n-----Sample Output:-----\n9 2\n\n-----EXPLANATION:-----\nThis list is :\n[3,2,7,9,4] so the highest value is 9 and lowest is 2 respectively.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nn=int(input())\na=list(map(int,input().split()))\na.sort()\nprint(a[-1],a[0])\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '5\\n3 2 7 9 4\\n', 'output': '9 2\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/SPTC2020/problems/CPCEJC2'}","problem_id":"vfc_2042","program":"```python\nn=int(input())\na=list(map(int,input().split()))\na.sort()\nprint(a[-1],a[0])\n\n```","inputs":"5\n3 2 7 9 4\n","output":"9 2\n","actual_output":"9 2\n","execution_success":true,"sample_index":407},{"source":"apps","task_type":"verifiable_code","in_source_id":"801","prompt":"Solve the following coding problem using the programming language python:\n\nChefina has two sequences $A_1, A_2, \\ldots, A_N$ and $B_1, B_2, \\ldots, B_N$. She views two sequences with length $N$ as identical if, after they are sorted in non-decreasing order, the $i$-th element of one sequence is equal to the $i$-th element of the other sequence for each $i$ ($1 \\le i \\le N$).\nTo impress Chefina, Chef wants to make the sequences identical. He may perform the following operation zero or more times: choose two integers $i$ and $j$ $(1 \\le i,j \\le N)$ and swap $A_i$ with $B_j$. The cost of each such operation is $\\mathrm{min}(A_i, B_j)$.\nYou have to find the minimum total cost with which Chef can make the two sequences identical.\n\n-----Input-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The first line of each test case contains a single integer $N$.\n- The second line contains $N$ space-separated integers $A_1, A_2, \\ldots, A_N$.\n- The third line contains $N$ space-separated integers $B_1, B_2, \\ldots, B_N$.\n\n-----Output-----\nFor each test case, print a single line containing one integer \u2015 the minimum cost, or $-1$ if no valid sequence of operations exists.\n\n-----Constraints-----\n- $1 \\le T \\le 2,000$\n- $1 \\le N \\le 2 \\cdot 10^5$\n- $1 \\le A_i, B_i \\le 10^9$ for each valid $i$\n- the sum of $N$ over all test cases does not exceed $2 \\cdot 10^6$\n\n-----Subtasks-----\nSubtask #1 (15 points):\n- $T \\le 20$\n- $N \\le 20$\nSubtask #2 (85 points): original constraints\n\n-----Example Input-----\n3\n1\n1\n2\n2\n1 2\n2 1\n2\n1 1\n2 2\n\n-----Example Output-----\n-1\n0\n1\n\n-----Explanation-----\nExample case 1: There is no way to make the sequences identical, so the answer is $-1$.\nExample case 2: The sequence are identical initially, so the answer is $0$.\nExample case 3: We can swap $A_1$ with $B_2$, which makes the two sequences identical, so the answer is $1$.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfrom collections import Counter\ntc=int(input())\nfor k in range(tc):\n n=int(input())\n a=list(map(int, input().rstrip().split()))\n b= list(map(int, input().rstrip().split()))\n cc=sorted(a+b)\n #print('cc = ',cc)\n p=[]\n q=[]\n #print('len(cc) = ',len(cc))\n #print('len = ',(2*n))\n #rx=0\n for i in range(0,(2*n),2):\n p.append(cc[i])\n #rx+=1\n for i in range(1,(2*n)+1,2):\n q.append(cc[i])\n \n if(p!=q):\n print('-1')\n continue\n a.sort()\n b.sort()\n #print(p)\n #print(q)\n if(a==b):\n print('0')\n continue\n xx = list((Counter(a) - Counter(p)).elements())\n yy = list((Counter(b) - Counter(p)).elements())\n #print('xx = ',xx)\n #print('yy = ',yy)\n iu=len(xx)\n gb=sorted(xx+yy)\n #print(iu)\n uu=xx[0]\n vv=yy[0]\n #print('uu = ',uu)\n #print('vv = ',vv)\n zz=min(cc[0],uu,vv)\n #print('zz = ',zz)\n ans=0\n for i in range(iu):\n if(gb[i]<=(zz*2)):\n ans+=gb[i]\n else:\n ans+=(zz*2)\n print(ans)\n \n#a = [1, 1, 1, 2, 3, 3]\n#b = [1, 1, 2, 2, 3, 4]\n\n'''c = []\ni, j = 0, 0\nwhile i < len(a) and j < len(b):\n if a[i] == b[j]:\n c.append(a[i])\n i += 1\n j += 1\n elif a[i] > b[j]:\n j += 1\n else:\n i += 1'''\n#print(c)\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\n1\\n1\\n2\\n2\\n1 2\\n2 1\\n2\\n1 1\\n2 2\\n', 'output': '-1\\n0\\n1\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/CHFNSWPS'}","problem_id":"vfc_2046","program":"```python\nfrom collections import Counter\ntc=int(input())\nfor k in range(tc):\n n=int(input())\n a=list(map(int, input().rstrip().split()))\n b= list(map(int, input().rstrip().split()))\n cc=sorted(a+b)\n #print('cc = ',cc)\n p=[]\n q=[]\n #print('len(cc) = ',len(cc))\n #print('len = ',(2*n))\n #rx=0\n for i in range(0,(2*n),2):\n p.append(cc[i])\n #rx+=1\n for i in range(1,(2*n)+1,2):\n q.append(cc[i])\n \n if(p!=q):\n print('-1')\n continue\n a.sort()\n b.sort()\n #print(p)\n #print(q)\n if(a==b):\n print('0')\n continue\n xx = list((Counter(a) - Counter(p)).elements())\n yy = list((Counter(b) - Counter(p)).elements())\n #print('xx = ',xx)\n #print('yy = ',yy)\n iu=len(xx)\n gb=sorted(xx+yy)\n #print(iu)\n uu=xx[0]\n vv=yy[0]\n #print('uu = ',uu)\n #print('vv = ',vv)\n zz=min(cc[0],uu,vv)\n #print('zz = ',zz)\n ans=0\n for i in range(iu):\n if(gb[i]<=(zz*2)):\n ans+=gb[i]\n else:\n ans+=(zz*2)\n print(ans)\n \n#a = [1, 1, 1, 2, 3, 3]\n#b = [1, 1, 2, 2, 3, 4]\n\n'''c = []\ni, j = 0, 0\nwhile i < len(a) and j < len(b):\n if a[i] == b[j]:\n c.append(a[i])\n i += 1\n j += 1\n elif a[i] > b[j]:\n j += 1\n else:\n i += 1'''\n#print(c)\n\n```","inputs":"3\n1\n1\n2\n2\n1 2\n2 1\n2\n1 1\n2 2\n","output":"-1\n0\n1\n","actual_output":"-1\n0\n1\n","execution_success":true,"sample_index":408},{"source":"apps","task_type":"verifiable_code","in_source_id":"802","prompt":"Solve the following coding problem using the programming language python:\n\nChef likes to solve difficult tasks. This time, he tried to solve the Big Famous Unsolvable $A+B=C$. One of his friends played a prank on Chef and randomly shuffled the bits in $A$ and $B$ (independently in each number). However, the funny thing is that the sum of the resulting numbers remained $C$ even after shuffling.\nChef is now wondering: in how many ways is it possible to shuffle the bits of $A$ and the bits of $B$ such that their sum after shuffling is equal to $C$? Let's denote the integers obtained by shuffling the bits of $A$ and $B$ by $A_s$ and $B_s$ respectively; two ways $(A_{s1}, B_{s1})$ and $(A_{s2}, B_{s2})$ are considered distinct if $A_{s1} \\neq A_{s2}$ or $B_{s1} \\neq B_{s2}$.\nIt is allowed to add any number (possibly zero) of leading zeroes, i.e. bits $0$, to $A$ and any number of leading zeroes to $B$ before shuffling the bits.\n\n-----Input-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The first and only line of each test case contains three space-separated integers $A$, $B$ and $C$. \n\n-----Output-----\nFor each test case, print a single line containing one integer \u2014 the number of ways to shuffle the bits.\n\n-----Constraints-----\n- $1 \\le T \\le 1,000$\n- $1 \\le A, B, C \\le 10^9$\n- $A+B = C$\n\n-----Subtasks-----\nSubtask #1 (50 points): $1 \\le A, B, C \\le 10^5$\nSubtask #2 (50 points): original constraints\n\n-----Example Input-----\n2\n1 2 3\n369 428 797\n\n-----Example Output-----\n2\n56\n\n-----Explanation-----\nExample case 1: We can consider $A=01$ and $B=10$ in binary. Then, there are two possible ways: swapping the two bits of $A$ and the two bits of $B$ ($A_s=10$, $B_s=01$ in binary, $2$ and $1$ in decimal representation) or not shuffling any bits.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nimport math\ndef csb(n): \n count = 0\n while (n): \n n &= (n-1) \n count+= 1\n \n return count\ndef f(ca,cb,i,cf,C,n,dp):\n if ca<0 or cb<0:\n return 0\n if i==n:\n if ca==0 and cb==0 and cf==0:\n return 1\n return 0\n st=str(ca)+\" \"+str(cb)+\" \"+str(cf)+\" \"+str(i)\n if dp.get(st)!=None:\n return dp[st]\n x=0 \n if (C&(1<0:\n x=1\n if x==1:\n #we will have odd num of set bits\n if cf==1:\n dp[st]=f(ca,cb,i+1,0,C,n,dp)+f(ca-1,cb-1,i+1,1,C,n,dp)\n else:\n dp[st]=f(ca-1,cb,i+1,0,C,n,dp)+f(ca,cb-1,i+1,0,C,n,dp)\n else:\n if cf==1:\n dp[st]=f(ca-1,cb,i+1,1,C,n,dp)+f(ca,cb-1,i+1,1,C,n,dp)\n else:\n dp[st]=f(ca,cb,i+1,0,C,n,dp)+f(ca-1,cb-1,i+1,1,C,n,dp)\n \n return dp[st]\ndef ip():\n \n for _ in range(int(input())):\n a,b,c=list(map(int,input().split()))\n n=int(math.log(c,2))+1\n dp={}\n print(f(csb(a),csb(b),0,0,c,n,dp))\nip()\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n1 2 3\\n369 428 797\\n', 'output': '2\\n56\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/CHEFADD'}","problem_id":"vfc_2050","program":"```python\nimport math\ndef csb(n): \n count = 0\n while (n): \n n &= (n-1) \n count+= 1\n \n return count\ndef f(ca,cb,i,cf,C,n,dp):\n if ca<0 or cb<0:\n return 0\n if i==n:\n if ca==0 and cb==0 and cf==0:\n return 1\n return 0\n st=str(ca)+\" \"+str(cb)+\" \"+str(cf)+\" \"+str(i)\n if dp.get(st)!=None:\n return dp[st]\n x=0 \n if (C&(1<0:\n x=1\n if x==1:\n #we will have odd num of set bits\n if cf==1:\n dp[st]=f(ca,cb,i+1,0,C,n,dp)+f(ca-1,cb-1,i+1,1,C,n,dp)\n else:\n dp[st]=f(ca-1,cb,i+1,0,C,n,dp)+f(ca,cb-1,i+1,0,C,n,dp)\n else:\n if cf==1:\n dp[st]=f(ca-1,cb,i+1,1,C,n,dp)+f(ca,cb-1,i+1,1,C,n,dp)\n else:\n dp[st]=f(ca,cb,i+1,0,C,n,dp)+f(ca-1,cb-1,i+1,1,C,n,dp)\n \n return dp[st]\ndef ip():\n \n for _ in range(int(input())):\n a,b,c=list(map(int,input().split()))\n n=int(math.log(c,2))+1\n dp={}\n print(f(csb(a),csb(b),0,0,c,n,dp))\nip()\n\n```","inputs":"2\n1 2 3\n369 428 797\n","output":"2\n56\n","actual_output":"2\n56\n","execution_success":true,"sample_index":409},{"source":"apps","task_type":"verifiable_code","in_source_id":"804","prompt":"Solve the following coding problem using the programming language python:\n\nBitland declared war on Chefland and sent an army to fight them, but Chefland defended efficiently and Bitland's army has been reduced to N$N$ soldiers. They have no chance of winning the war and do not want to surrender, so they are planning to commit group suicide. Josh, the leader of Bitland's remaining soldiers, has different plans \u2014 he wants to survive and somehow escape.\nThe soldiers are numbered 1$1$ through N$N$; Josh is soldier N$N$. The soldiers are going to stand in a circle in the order 1,2,\u2026,P\u22121,N,P,P+1,\u2026,N\u22121$1, 2, \\ldots, P-1, N, P, P+1, \\ldots, N-1$. Formally, they are standing in the circle in such a way that if Josh's position is P$P$ (1\u2264P\u2264N$1 \\le P \\le N$), then for each i$i$ (1\u2264i\u2264N\u22122$1 \\le i \\le N-2$, i\u2260P\u22121$i \\neq P-1$), soldier i+1$i+1$ is directly to the right of soldier i$i$, soldier P$P$ (if P\u2264N\u22121$P \\le N-1$) or 1$1$ (if P=N$P = N$) is directly to the right of Josh and Josh is directly to the right of soldier P\u22121$P-1$ (if P\u22652$P \\ge 2$) or soldier N\u22121$N-1$ (if P=1$P = 1$); if 2\u2264P\u2264N\u22122$2 \\le P \\le N-2$, soldier 1$1$ is also directly to the right of soldier N\u22121$N-1$. For each i$i$ (1\u2264i\u2264N\u22121$1 \\le i \\le N-1$), soldier i$i$ has a sword with power Ai$A_i$. Josh plans to take a shield with sufficiently high defense power D$D$.\nFirst, the soldiers start to commit group suicide according to the following rules:\n- Initially, soldier 1$1$ is the attacking soldier.\n- If the attacking soldier is not Josh, this soldier attacks the soldier that is currently to his right.\n- When Josh is attacked with power a$a$, the current defense power of his shield decreases by a$a$, and if it becomes negative, Josh dies. When a different soldier is attacked, he does not try to defend and dies immediately. The power of the attacking soldier's sword does not change.\n- Then, the next living soldier to the right of the current attacking soldier becomes the attacking soldier and the process continues until there is only one soldier left.\nIt is clear that this way, Josh cannot be the last survivor. However, Chefland's general Chef plans to interrupt this process as soon as there are exactly two living soldiers of Bitland left (Josh wants to be one of them) by attacking them with Chefland's full firepower F$F$. Since this attack is unexpected, both attacked soldiers try to defend independently with the weapons they have. Josh survives if the current defense power of his shield is at least F$F$. Any other soldier survives only if the power of his sword is strictly greater than F$F$. Since Chefland does not attack again, if both Josh and another soldier survive, then the other soldier will kill Josh. Therefore, Josh wants to be the only survivor of Chefland's attack.\nYour task is to find the minimum possible value of D$D$ such that Josh survives if he chooses his position P$P$ optimally (or determine that he cannot survive) and the lowest position P$P$ such that Josh survives if he takes a shield with this defense power D$D$.\n\n-----Input-----\n- 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.\n- The first line of each test case contains a single integer N$N$.\n- The second line contains N\u22121$N-1$ space-separated integers A1,A2,\u2026,AN\u22121$A_1, A_2, \\ldots, A_{N-1}$.\n- The third line contains a single integer F$F$.\n\n-----Output-----\nFor each test case, first, print a line containing the string \"possible\" if Josh can survive or \"impossible\" if he cannot (without quotes). Then, if he can survive, print a second line containing two space-separated integers P$P$ and D$D$.\n\n-----Constraints-----\n- 1\u2264T\u22641,000$1 \\le T \\le 1,000$\n- 2\u2264N\u22641,000,000$2 \\le N \\le 1,000,000$\n- 1\u2264Ai\u226410,000$1 \\le A_i \\le 10,000$ for each valid i$i$\n- 1\u2264F\u226410,000$1 \\le F \\le 10,000$\n- the sum of N$N$ over all test cases does not exceed 1,000,005$1,000,005$\n\n-----Subtasks-----\nSubtask #1 (30 points):\n- 1\u2264T\u226410$1 \\le T \\le 10$\n- 2\u2264N\u2264100$2 \\le N \\le 100$\n- 1\u2264Ai\u2264100$1 \\le A_i \\le 100$ for each valid i$i$\n- 1\u2264F\u2264100$1 \\le F \\le 100$\nSubtask #2 (70 points): original constraints\n\n-----Example Input-----\n2\n5\n12 34 45 5\n10\n5\n10 15 43 20\n5\n\n-----Example Output-----\npossible\n4 100\nimpossible\n\n-----Explanation-----\nExample case 1: When Josh is at the position P=4$P = 4$, the soldiers' initial powers in clockwise order around the circle, starting with soldier 1$1$, are [12,34,45,D,5]$[12, 34, 45, D, 5]$ (D$D$ denotes Josh). Then, the following happens:\n- The soldier with power 12$12$ attacks the soldier with power 34$34$ and kills him.\n- The soldier with power 45$45$ attacks Josh, who defends. The living soldiers' powers are now [12,45,D\u221245,5]$[12, 45, D-45, 5]$ and Josh is the attacking soldier.\n- Josh does not attack, so the soldier to his right (with power 5$5$) becomes the attacking soldier. He attacks the soldier with power 12$12$ and kills him.\n- The soldier with power 45$45$ attacks Josh again and Josh defends again.\n- The soldier with power 5$5$ attacks the soldier with power 45$45$ and kills him.\n- Now, two soldiers are left: Josh (with a shield with defense power D\u221290$D-90$) and the soldier with a sword with power 5$5$. Each of them is attacked with firepower F=10$F=10$, so the power of Josh's shield drops to D\u2212100$D-100$ and the other soldier dies.\nIf Josh survives, his shield's initial power D$D$ should be at least 45+45+10=100$45+45+10 = 100$. For all other positions P$P$, Josh cannot survive.\nExample case 2: Regardless of how large D$D$ is and which position Josh chooses, after Chefland's attack, a soldier of Bitland other than Josh will always survive. This soldier will then attack Josh until his shield breaks and he dies.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nimport numpy as np\nfor _ in range(int(input())):\n n = int(input())-1;soldiers = [int(j) for j in input().split()]\n force = int(input());attacks = np.zeros(2*n,dtype=int);attacks[:n] = np.array(soldiers);attacks[n:2*n] = attacks[:n];shield = [0 for _ in range(n)];pow_of_2 = 1\n while n // pow_of_2 > 0: pow_of_2 *= 2\n soldier_of_attack = (2 * n - pow_of_2) % n;pow_of_2 = attacks[soldier_of_attack] > force\n \n for i in range(n):\n if attacks[i] > force: shield[i] = 10 ** 11\n elif n == 1: shield[i] = force\n elif pow_of_2:\n shield[i] = force; num_of_survivors = n; soldiers = list(attacks[i:i+n]); starting_soldier = (n - i) % n\n if (num_of_survivors - starting_soldier) % 2 == 1: shield[i] += soldiers[-1]\n soldiers = [soldiers[i] for i in range(num_of_survivors) if i < starting_soldier or (i - starting_soldier) % 2 == 0];num_of_survivors = starting_soldier + (num_of_survivors - starting_soldier - 1) // 2\n if num_of_survivors > 1:\n pow_2 = 1\n while True:\n attacker = num_of_survivors - (num_of_survivors % pow_2); pow_2 *= 2\n if attacker == 0: break\n if attacker % pow_2 == 0: shield[i] += soldiers[attacker]\n elif i == soldier_of_attack: shield[i] = force\n else: shield[i] = force + 1 \n shield_needed = min(shield)\n if shield_needed == 10 ** 11: print(\"impossible\")\n else:\n print(\"possible\")\n for i in range(n):\n if shield[i] == shield_needed:print(str(i+1) + \" \" + str(shield_needed));break\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n5\\n12 34 45 5\\n10\\n5\\n10 15 43 20\\n5\\n', 'output': 'possible\\n4 100\\nimpossible\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/CHFWAR'}","problem_id":"vfc_2058","program":"```python\nimport numpy as np\nfor _ in range(int(input())):\n n = int(input())-1;soldiers = [int(j) for j in input().split()]\n force = int(input());attacks = np.zeros(2*n,dtype=int);attacks[:n] = np.array(soldiers);attacks[n:2*n] = attacks[:n];shield = [0 for _ in range(n)];pow_of_2 = 1\n while n // pow_of_2 > 0: pow_of_2 *= 2\n soldier_of_attack = (2 * n - pow_of_2) % n;pow_of_2 = attacks[soldier_of_attack] > force\n \n for i in range(n):\n if attacks[i] > force: shield[i] = 10 ** 11\n elif n == 1: shield[i] = force\n elif pow_of_2:\n shield[i] = force; num_of_survivors = n; soldiers = list(attacks[i:i+n]); starting_soldier = (n - i) % n\n if (num_of_survivors - starting_soldier) % 2 == 1: shield[i] += soldiers[-1]\n soldiers = [soldiers[i] for i in range(num_of_survivors) if i < starting_soldier or (i - starting_soldier) % 2 == 0];num_of_survivors = starting_soldier + (num_of_survivors - starting_soldier - 1) // 2\n if num_of_survivors > 1:\n pow_2 = 1\n while True:\n attacker = num_of_survivors - (num_of_survivors % pow_2); pow_2 *= 2\n if attacker == 0: break\n if attacker % pow_2 == 0: shield[i] += soldiers[attacker]\n elif i == soldier_of_attack: shield[i] = force\n else: shield[i] = force + 1 \n shield_needed = min(shield)\n if shield_needed == 10 ** 11: print(\"impossible\")\n else:\n print(\"possible\")\n for i in range(n):\n if shield[i] == shield_needed:print(str(i+1) + \" \" + str(shield_needed));break\n```","inputs":"2\n5\n12 34 45 5\n10\n5\n10 15 43 20\n5\n","output":"possible\n4 100\nimpossible\n","actual_output":"possible\n4 100\nimpossible\n","execution_success":true,"sample_index":410},{"source":"apps","task_type":"verifiable_code","in_source_id":"805","prompt":"Solve the following coding problem using the programming language python:\n\nin Chefland, there is a very famous street where $N$ types of street food (numbered $1$ through $N$) are offered. For each valid $i$, there are $S_i$ stores that offer food of the $i$-th type, the price of one piece of food of this type is $V_i$ (the same in each of these stores) and each day, $P_i$ people come to buy it; each of these people wants to buy one piece of food of the $i$-th type.\nChef is planning to open a new store at this street, where he would offer food of one of these $N$ types. Chef assumes that the people who want to buy the type of food he'd offer will split equally among all stores that offer it, and if this is impossible, i.e. the number of these people $p$ is not divisible by the number of these stores $s$, then only $\\left\\lfloor\\frac{p}{s}\\right\\rfloor$ people will buy food from Chef.\nChef wants to maximise his daily profit. Help Chef choose which type of food to offer and find the maximum daily profit he can make.\n\n-----Input-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The first line of each test case contains a single integer $N$. \n- $N$ lines follow. For each $i$ ($1 \\le i \\le N$), the $i$-th of these lines contains three space-separated integers $S_i$, $P_i$ and $V_i$.\n\n-----Output-----\nFor each test case, print a single line containing one integer \u2015 the maximum profit.\n\n-----Constraints-----\n- $1 \\le T \\le 100$\n- $1 \\le N \\le 100$\n- $1 \\le S_i, V_i, P_i \\le 10,000$ for each valid $i$\n\n-----Subtasks-----\nSubtask #1 (100 points): original constraints\n\n-----Example Input-----\n2\n3\n4 6 8\n2 6 6\n1 4 3\n1\n7 7 4\n\n-----Example Output-----\n12\n0\n\n-----Explanation-----\nExample case 1: Chef should offer food of the second type. On each day, two people would buy from him, so his daily profit would be $12$.\nExample case 2: Chef has no option other than to offer the only type of food, but he does not expect anyone to buy from him anyway, so his daily profit is $0$.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nt=int(input())\nwhile(t):\n n=int(input())\n l=[]\n for i in range(n):\n l.append(list(map(int,input().split())));\n m=[]\n for i in l:\n m.append((i[1]//(i[0]+1))*i[2])\n res=max(m)\n print(res)\n t=t-1\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n3\\n4 6 8\\n2 6 6\\n1 4 3\\n1\\n7 7 4\\n', 'output': '12\\n0\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/STFOOD'}","problem_id":"vfc_2062","program":"```python\nt=int(input())\nwhile(t):\n n=int(input())\n l=[]\n for i in range(n):\n l.append(list(map(int,input().split())));\n m=[]\n for i in l:\n m.append((i[1]//(i[0]+1))*i[2])\n res=max(m)\n print(res)\n t=t-1\n```","inputs":"2\n3\n4 6 8\n2 6 6\n1 4 3\n1\n7 7 4\n","output":"12\n0\n","actual_output":"12\n0\n","execution_success":true,"sample_index":411},{"source":"apps","task_type":"verifiable_code","in_source_id":"806","prompt":"Solve the following coding problem using the programming language python:\n\nJohn was learning mathematics and was very bored. Jane his best friend gave him a problem to solve. \nThe description of the problem was as follows:- \nYou are given a decimal number $N$(1<=$N$<=$10^9$) and three integers $A$, $B$, $C$. \nSteps to perform:\n1) You have to create a $LIST$. \n2) You have to initialize the $LIST$ by adding N to the $LIST$ as its first element. \n3) Divide$N$ by $A$ and if the first digit of the fractional part is Non-Zero then add this digit to the $LIST$ otherwise add the first digit of the integral part(Leftmost digit).\n(The integer part or integral part of a decimal is the integer written to the left of the decimal separator. The part from the decimal separator i.e to the right is the fractional part. )\n4) Update $N$ by Last element of the $LIST$. \nN = Last element of $LIST$\n5) You have to perform the same process from step 3 on $N$ for $B$ and $C$ respectively \n6) Repeat from step 3 \nYou have to answer$Q$(1 <= $Q$<= 100 ) queries\nFor each query you are given an integer $i$ (0 <= $i$ <= $10^9$ ). You have to print the element present at the ith position of the $LIST$. \nHelp John solve this problem.\n\n-----Input:-----\n- The First Line of input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The First Line of each test case contains the integer $N$.\n- The second line of each test case contains three integers $A$, $B$, and $C$ separated by a space\n- The third line of each test case contains an integer $Q$.\n- Then the next $Q$ line follows. \n- An integer $i$ (0 <= $i$ <= 10^9 )\n\n-----Output:-----\nYou have to answer the $Q$ queries in the next $Q$ lines. \n\n-----Constraints-----\n- $1 \\leq T \\leq 10$\n- $1 \\leq N \\leq 10^9$\n- $2 \\leq A \\leq 10$\n- $2 \\leq B \\leq 10$\n- $2 \\leq C \\leq 10$\n- $2 \\leq Q \\leq 100$\n- $0 \\leq i \\leq 10^9$\n\n-----Sample Input:-----\n1\n56\n3 5 7\n4\n0\n1\n2\n3\n\n-----Sample Output:-----\n56\n6\n2\n2\n\n-----EXPLANATION:-----\nThis list is :\n$N$ = 56 and $A$ = 3, $B$ = 5, $C$ = 7. \nInitially $LIST$ = $[ 56 ]$\n$N$$/$$A$ = 56/3 = 18.666666666666668 \nAdd 6 to the $LIST$ \n$LIST$ = $[ 56, 6 ]$\n$N$ = 6 \n$N$$/$$B$ = 6/5 = 1.2 \nAdd 2 to the$LIST$ \n$LIST$ = $[ 56, 6, 2 ]$\nN = 2 \n$N$$/$$C$ = 2/7 =0. 2857142857142857\nAdd 2 to the $LIST$. \n$LIST$ = $[ 56, 6, 2, 2 ]$\n$N$ = 2\nWe have to keep repeating this process. If any of the numbers got by $N$ dividing by either $A$, $B$, $C$ have 0 after the decimal point then we have to take the first digit of the number. \nfor example: if we got 12.005 then here we take 1 and add it to the list and then assign N = 1 \nNow the queries ask for the elements at index 0, 1, 2, 3 of the $LIST$ which is 56,6, 2, 2\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# Why do we fall ? So we can learn to pick ourselves up.\r\n\r\n\r\n\r\n\r\nt = int(input())\r\nfor _ in range(0,t):\r\n n = int(input())\r\n abc = [int(i) for i in input().split()]\r\n\r\n i = 0\r\n\r\n lst = [n]\r\n\r\n for _ in range(0,100):\r\n k = str(lst[-1]/abc[i%3]).split('.')\r\n if int(k[1][0]) > 0:\r\n lst.append(int(k[1][0]))\r\n else:\r\n lst.append(int(k[0][0]))\r\n i += 1\r\n pattern = []\r\n ind = 0\r\n while len(pattern) == 0:\r\n for i in range(ind, len(lst) - 1):\r\n check = lst[ind: i + 1] * 50\r\n check = check[:len(lst) - ind]\r\n if lst[ind:] == check:\r\n pattern = check\r\n break\r\n if len(pattern):\r\n break\r\n ind += 1\r\n final_pattern = []\r\n for i in range(0, len(pattern)):\r\n couldbe = pattern[:i + 1]\r\n check = pattern[:i + 1] * 100\r\n check = check[:len(pattern)]\r\n if check == pattern:\r\n final_pattern = couldbe\r\n break\r\n lp = len(final_pattern)\r\n q = int(input())\r\n for _ in range(0, q):\r\n qq = int(input())\r\n if qq < ind:\r\n print(lst[qq])\r\n else:\r\n qq -= ind\r\n kk = qq % lp\r\n print(final_pattern[kk])\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\"\"\"\r\n1\r\n56\r\n3 5 7\r\n4\r\n0\r\n1\r\n2\r\n3\r\n\r\n\"\"\"\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n56\\n3 5 7\\n4\\n0\\n1\\n2\\n3\\n', 'output': '56\\n6\\n2\\n2\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/PROC2020/problems/WLIST'}","problem_id":"vfc_2066","program":"```python\n# Why do we fall ? So we can learn to pick ourselves up.\r\n\r\n\r\n\r\n\r\nt = int(input())\r\nfor _ in range(0,t):\r\n n = int(input())\r\n abc = [int(i) for i in input().split()]\r\n\r\n i = 0\r\n\r\n lst = [n]\r\n\r\n for _ in range(0,100):\r\n k = str(lst[-1]/abc[i%3]).split('.')\r\n if int(k[1][0]) > 0:\r\n lst.append(int(k[1][0]))\r\n else:\r\n lst.append(int(k[0][0]))\r\n i += 1\r\n pattern = []\r\n ind = 0\r\n while len(pattern) == 0:\r\n for i in range(ind, len(lst) - 1):\r\n check = lst[ind: i + 1] * 50\r\n check = check[:len(lst) - ind]\r\n if lst[ind:] == check:\r\n pattern = check\r\n break\r\n if len(pattern):\r\n break\r\n ind += 1\r\n final_pattern = []\r\n for i in range(0, len(pattern)):\r\n couldbe = pattern[:i + 1]\r\n check = pattern[:i + 1] * 100\r\n check = check[:len(pattern)]\r\n if check == pattern:\r\n final_pattern = couldbe\r\n break\r\n lp = len(final_pattern)\r\n q = int(input())\r\n for _ in range(0, q):\r\n qq = int(input())\r\n if qq < ind:\r\n print(lst[qq])\r\n else:\r\n qq -= ind\r\n kk = qq % lp\r\n print(final_pattern[kk])\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\"\"\"\r\n1\r\n56\r\n3 5 7\r\n4\r\n0\r\n1\r\n2\r\n3\r\n\r\n\"\"\"\n```","inputs":"1\n56\n3 5 7\n4\n0\n1\n2\n3\n","output":"56\n6\n2\n2\n","actual_output":"56\n6\n2\n2\n","execution_success":true,"sample_index":412},{"source":"apps","task_type":"verifiable_code","in_source_id":"807","prompt":"Solve the following coding problem using the programming language python:\n\nYou are given an array A of size N. Let us list down all the subarrays of the given array. There will be a total of N * (N + 1) / 2 subarrays of the given array. Let us sort each of the subarrays in descending order of the numbers in it. \n\nNow you want to sort these subarrays in descending order. You can compare two subarrays B, C, as follows.\n\ncompare(B, C):\nAppend N - |B| zeros at the end of the array B.\nAppend N - |C| zeros at the end of the array C.\nfor i = 1 to N:\nif B[i] < C[i]:\nreturn B is less than C\nif B[i] > C[i]:\nreturn B is greater than C\nreturn B and C are equal.\n\nYou are given M queries asking for the maximum element in the pth subarray (1-based indexing).\n\n-----Input-----\nThe first line of input contains T, the number of test cases.\nThe first line of each test case contains two space separated integers N and M, denoting the array size and the number of queries respectively.\nThe next line contains N space-separated integers denoting the array elements.\n\nEach of the next M lines contains a single integer - p.\n\n-----Output-----\nOutput a single integer corresponding to the maximum element in the pth subarray.\n\n-----Constraints-----\n- 1 \u2264 Ai \u2264 109\n- 1 \u2264 p \u2264 N+1C2\n\n-----Subtasks-----Subtask #1 (20 points):\n- 1 \u2264 T \u2264 20\n- 1 \u2264 N \u2264 200\n- 1 \u2264 M \u2264 104\nSubtask #2 (30 points):\n- 1 \u2264 T \u2264 20\n- 1 \u2264 N \u2264 3000\n- 1 \u2264 M \u2264 104\nSubtask #3 (50 points):\n- 1 \u2264 T \u2264 5\n- 1 \u2264 N \u2264 105\n- 1 \u2264 M \u2264 105\n\n-----Example-----\nInput:1\n4 2\n3 1 2 4\n1\n5\n\nOutput:4\n3\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\nfor _ in range(int(input())):\n n,q=map(int,input().split())\n l=[int(i) for i in input().split()]\n qry=[int(input()) for i in range(q)]\n def cmp(sub1,sub2):\n for i in range(len(sub1)):\n if sub1[i]>sub2[i]:\n return 1 \n if sub1[i]sub2[i]:\n return 1 \n if sub1[i]l[i+2]):\r\n l1.append([l[i+2],l[i+1],l[i]])\r\nif(len(l1)!=0):\r\n print(\"YES\")\r\n print(*max(l1))\r\nelse:\r\n print(\"NO\")\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '5\\n4 2 10 3 5\\n', 'output': 'YES\\n5 4 3\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/COJK2020/problems/CKOJ20A'}","problem_id":"vfc_2078","program":"```python\n#from itertools import combinations as c\r\nn=int(input());l=list(map(int,input().split()))\r\nl1=[]\r\nif(n<3):\r\n print(\"NO\")\r\nelse:\r\n l.sort()\r\n for i in range(n-2):\r\n if(l[i]+l[i+1]>l[i+2]):\r\n l1.append([l[i+2],l[i+1],l[i]])\r\nif(len(l1)!=0):\r\n print(\"YES\")\r\n print(*max(l1))\r\nelse:\r\n print(\"NO\")\n```","inputs":"5\n4 2 10 3 5\n","output":"YES\n5 4 3\n","actual_output":"YES\n5 4 3\n","execution_success":true,"sample_index":414},{"source":"apps","task_type":"verifiable_code","in_source_id":"810","prompt":"Solve the following coding problem using the programming language python:\n\nChef is frustrated in this lockown. So to overcome this he plans to travel various mountains.\nHe is very strange so he sets some conditions for $each$ Type 2 query(mentioned below) (i.e. $1$ $i$) : \n- Let Chef has travelled till $ith$ mountain from left to right.\n- He does not like to travel the mountain with the height ,of which he has travelled till now. More formally, \nLet the height of peak on which he is standing is $a_{i}$ then he can only go to the peak of height $a_{j}$ \nwhich is greater than $a_{i}$ and nearest to $ith$ mountain such that there should be no other peak of same height $a_{j}$ till $a_{i}$(height of $ith$ mountain) .\n\n-----Input format:-----\n- \nThe first line contains an integer $T$ denoting the number of test cases.\n- \nThe second line of consist of a integer $N$ and $Q$ .\n- \nThe third line contains $N$ not necessarily distinct positive integers $a_{0},a_{1}, . . .,a_{n-1}$ denoting the height of \n$N$ mountains.\n- \nThen next $Q$ lines follows where each line consisting of $either$ of $2$ types of queries:\nType 1: $0$ $A$ $B$ i.e. $a_{A} = B$ (where height of $Ath$ mountain will be updated to $B$) \nType 2: $1$ $A$ i.e. you have to answer $a_k$ which is greater than $a_{A}$ and nearest to $Ath$ mountain such that there should be no other peak of same height $a_{k}$ till $a_{A}$(height of $Ath$ mountain) .\n\n-----Output format:-----\n- For every query of Type 2 there should be an integer $a_{k}$ on next line for the updated array , If no such $a_{k}$ exists then $a_{k}$= $-1$ , as query of type 1 will have no output . \n\n-----Constraints:-----\n- $1\\leq T \\leq 10^2$\n- $1 \\leq N,Q \\leq 10^4$\n- $0\\leq a_{i} \\leq 10^6$\n- $0\\leq B \\leq 10^6$\n- $0\\leq A \\leq N-1$\n\n-----Subtasks-----\n- \n1 Point : \n$1 \\leq T,N,Q \\leq 10^2$ \n$0\\leq B,a_{i} \\leq 10^2$\n- \n99 Points : Orginal Constraints\n\n-----Example:-----\n\n-----Input:-----\n1\n10 5\n1 3 5 4 5 6 7 8 4 5\n1 7\n1 3\n1 1\n0 2 7\n1 3\n\n-----Output:-----\n-1\n6\n5\n5\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\nfrom bisect import bisect_left \n \ndef BinarySearch(a, x): \n i = bisect_left(a, x) \n if i != len(a) and a[i] == x: \n return i \n else: \n return -1\n\nfor _t in range(int(input())):\n _n, q = list(map(int, input().split()))\n mounts = list(map(int, input().split()))\n for _q in range(q):\n query = list(map(int, input().split()))\n if query[0] == 0:\n mounts[query[1]] = query[2]\n else:\n curr = query[1]\n prev = set(mounts[:curr+1])\n for m in mounts[curr+1:]:\n if m > mounts[curr] and m not in prev:\n print(m)\n break\n else:\n print(-1)\n \n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n10 5\\n1 3 5 4 5 6 7 8 4 5\\n1 7\\n1 3\\n1 1\\n0 2 7\\n1 3\\n', 'output': '-1\\n6\\n5\\n5\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/STR2020/problems/CHFMNT'}","problem_id":"vfc_2082","program":"```python\n# cook your dish here\nfrom bisect import bisect_left \n \ndef BinarySearch(a, x): \n i = bisect_left(a, x) \n if i != len(a) and a[i] == x: \n return i \n else: \n return -1\n\nfor _t in range(int(input())):\n _n, q = list(map(int, input().split()))\n mounts = list(map(int, input().split()))\n for _q in range(q):\n query = list(map(int, input().split()))\n if query[0] == 0:\n mounts[query[1]] = query[2]\n else:\n curr = query[1]\n prev = set(mounts[:curr+1])\n for m in mounts[curr+1:]:\n if m > mounts[curr] and m not in prev:\n print(m)\n break\n else:\n print(-1)\n \n\n```","inputs":"1\n10 5\n1 3 5 4 5 6 7 8 4 5\n1 7\n1 3\n1 1\n0 2 7\n1 3\n","output":"-1\n6\n5\n5\n","actual_output":"-1\n6\n5\n5\n","execution_success":true,"sample_index":415},{"source":"apps","task_type":"verifiable_code","in_source_id":"811","prompt":"Solve the following coding problem using the programming language python:\n\nIndian National Olympiad in Informatics 2013\nCalvin wakes up early one morning and finds that all his friends in the hostel are asleep. To amuse himself, he decides to play the following game : he draws a sequence of N squares on the ground, numbered 1 to N, and writes an integer in each square. He starts at square k (1 \u2264 k \u2264 N). The game consists of one forward phase followed by one backward phase.\n- In the forward phase, Calvin makes zero or more moves of the following type : if his current position is p, he can jump to p+1 or p+2 as long as he stays within the N squares.\n- In the backward phase, Calvin makes zero or more moves of the following type : if his current position is p, he can jump to p\u22121 or p\u22122 as long as he stays within the N squares.\nHe plays such that he finally ends up at square 1, and then he stops. He starts with a score of 0, and each time he jumps from square i to square j, he adds the integer written in square j to his score. Find the maximum score Calvin can obtain by playing this game. Recall that Calvin must start at square k and end at square 1. The integer on the square where he starts is not included in his score.\nFor example, suppose N = 5 and the numbers in squares are 5, 3, \u22122, 1, 1. If k = 2, Calvin starts on the second square. He can make a forward move to square 4, another to square 5, a backward move to square 4, another to square 2, and another to square 1. His total score is 1+1+1+3+5 = 11. You can check that this is the maximum score possible.\n\n-----Input format-----\n\u2022 Line 1 : Two space-separated integers, N and k, with 1 \u2264 k \u2264 N.\n\u2022 Line 2 : A space-separated sequence of N integers, the numbers in squares 1, 2 . . . , N .\n\n-----Output format-----\nA single line with a single integer, the maximum score Calvin can obtain by playing the game.\n\n-----Test Data-----\nThe testdata is grouped into two subtasks with the following constraints on the inputs.\n\u2022 Subtask 1 [30 points] : 1 \u2264 N \u2264 3000.\n\u2022 Subtask 2 [70 points] : 1 \u2264 N \u2264 106.\nIn all subtasks, the number in each square is between \u22121000 and 1000 inclusive.\n\n-----Example-----\nHere is the sample input and output corresponding to the example above.\n\n-----Sample input-----\n5 2\n5 3 -2 1 1\n\n-----Sample output-----\n11\n\nNote: 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!\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\ntry:\n n, k=map(int, input().split())\n arr=list(map(int, input().split()))\n forward = [0]*(n+1)\n backward= [0]*(n+1)\n backward[0]=arr[0]\n backward[1]=arr[0]+arr[1]\n for i in range(k, n):\n forward[i]=arr[i] +max(forward[i-1],forward[i-2])\n\n for i in range(2, n):\n backward[i]=arr[i]+max(backward[i-1],backward[i-2])\n \n ans=-float(\"Inf\")\n for i in range(k-1, n):\n ans=max(ans, forward[i]+backward[i]-arr[i])\n print(ans)\nexcept Exception:\n pass\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': 'and output corresponding to the example above.\\nSample input\\n5 2\\n5 3 -2 1 1\\nSample output\\n11\\nNote : 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!\\n', 'output': ''}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/INOIPRAC/problems/INOI1301'}","problem_id":"vfc_2086","program":"```python\ntry:\n n, k=map(int, input().split())\n arr=list(map(int, input().split()))\n forward = [0]*(n+1)\n backward= [0]*(n+1)\n backward[0]=arr[0]\n backward[1]=arr[0]+arr[1]\n for i in range(k, n):\n forward[i]=arr[i] +max(forward[i-1],forward[i-2])\n\n for i in range(2, n):\n backward[i]=arr[i]+max(backward[i-1],backward[i-2])\n \n ans=-float(\"Inf\")\n for i in range(k-1, n):\n ans=max(ans, forward[i]+backward[i]-arr[i])\n print(ans)\nexcept Exception:\n pass\n```","inputs":"and output corresponding to the example above.\nSample input\n5 2\n5 3 -2 1 1\nSample output\n11\nNote : 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!\n","output":"","actual_output":"","execution_success":true,"sample_index":416},{"source":"apps","task_type":"verifiable_code","in_source_id":"812","prompt":"Solve the following coding problem using the programming language python:\n\n\tDevuLand is a very strange place. There are n villages in it. Some of the villages are occupied by dinosaurs while the remaining ones by villagers.\n\tYou are given the information of DevuLand \n\tby an array D of size n. If D[i] is non-negative, it means that there are D[i] villagers in that village. \n\tOtherwise, it means that are -D[i] \n\tdinosaurs in that village.\n\n\tIt is also guaranteed that total number of villagers in DevuLand is equal to total number of dinosaurs.\n\nOnce dinosaurs got very hungry and started eating villagers. Frightened villagers gathered immediately and met their Sarpanch Deviji. Deviji, being a very daring and negotiable person, met to the head\nof dinosaurs. Soon both parties called a truce. It was decided that the villagers will provide laddus to \nthe dinosaurs. So everyday, each villager will take exactly one laddu to one of the dinosaurs in such a way that no dinosaur remains hungry (note that this is possible because number of villagers is the same as the number of dinosaurs).\n\nActually, carrying laddus is a quite a tough job. Villagers have to use a bullock cart for that. It takes one unit of grass a bullock to \ncarry a cart with 1 laddu for 1 kilometre. Laddus used to be very heavy in DevuLand, so a bullock cart can not carry more than one laddu.\n\nIt is also given distance between village indexed i and j is |j - i| (the absolute value) kilometres.\n\nNow villagers sat down and found a strategy to feed laddus to dinosaurs so that they need to buy the least amount of grass from the nearby market. \nThey are not very good in \ncalculations, please find out what is the minimum number of units of grass they need to buy.\n\n-----Input-----\n\nFirst line of the input contains an integer T denoting number of test cases.\n\nFor each test case, there are two lines. \n\nFirst line contains a single integer denoting n: number of villages. \n\nSecond line contains n space separated integers denoting the array D.\n\n-----Output-----\n\nFor each test case, print a single line containing the integer corresponding to answer of the problem.\n\n-----Constraints-----\n\n- 1 \u2264 T \u2264 10^5 \n- 1 \u2264 n \u2264 10^5 \n- -10^4 \u2264 D[i] \u2264 10^4 \n- Sum of n over all the test cases will be \u2264 10^6 \n- It is guaranteed that sum of D[i] is zero for a single test case which ensures that there are equal number of villagers and dinosaurs. \n\n-----Example-----\nInput:\n3\n2\n5 -5\n2\n-5 5\n3\n1 2 -3\nOutput:\n5\n5\n4\n\n-----Explanation-----\nExample case 1. Each villager in village 1, need to walk 1 km to reach to the dinosaur in 2nd village.\nExample case 2. Each villager in village 2, need to walk 1 km to reach to the dinosaur 1st village.\nExample case 3. Each villager in village 1, need to walk 2 km to reach to the dinosaur in 3rd village whereas Each villager in village 2, \nneed to walk 1 km to reach to the dinosaur in 3rd village.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\nfor _ in range(int(input())):\n n = int(input())\n a = list(map(int, input().split()))\n curr = 0\n ans = 0\n for x in a:\n curr += x\n ans += abs(curr)\n print(ans)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\n2\\n5 -5\\n2\\n-5 5\\n3\\n1 2 -3\\n', 'output': '5\\n5\\n4\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/PRLADDU'}","problem_id":"vfc_2090","program":"```python\n# cook your dish here\nfor _ in range(int(input())):\n n = int(input())\n a = list(map(int, input().split()))\n curr = 0\n ans = 0\n for x in a:\n curr += x\n ans += abs(curr)\n print(ans)\n```","inputs":"3\n2\n5 -5\n2\n-5 5\n3\n1 2 -3\n","output":"5\n5\n4\n","actual_output":"5\n5\n4\n","execution_success":true,"sample_index":417},{"source":"apps","task_type":"verifiable_code","in_source_id":"813","prompt":"Solve the following coding problem using the programming language python:\n\nHarsh, like usual, started studying 6 months before for his end semester examinations. He was going to complete his 8th revision of the whole syllabus, when suddenly Pranav showed up in his room with the last year's question paper for their algorithms course. This paper contains a problem which both of them couldn't solve. Frustrated he asked you for help. But you declined him and instead try to do this problem instead:\nYou are given an array $A_1,A_2,\\dots,A_N$, a positive integer $K$, and a function $F(x)=\\displaystyle\\sum_{i=1}^{N}{\\left|{\\left({x-A_i}\\right)^K}\\right|}$. Find the smallest integer $x$ such that $F(x)$ is minimum.Input\n- The first line contains two space-seperated integers , $N$ and $K$\n- The second line contains $N$ space-seperated integers $A_1,A_2,\\dots,A_N$. Output\nIn the first and only line print the smallest integer $x$ such that $F(x)$ is minimumConstraints\n- $1 \\leq N \\leq {10}^{5}$\n- $1 \\leq K \\leq {3}$\n- $1 \\leq A_i \\leq {5}\\times{10}^{4}$ for each valid $i$Sample Input 1\n3 1\n6 1 7\nSample Output 1\n6\nExplanation 1\n$F(6) = \\displaystyle\\sum_{i=1}^{N}{\\left|{\\left({6-A_i}\\right)^K}\\right|} \\\\ F(6) = \\left|{\\left({6-6}\\right)^1}\\right| + \\left|{\\left({6-1}\\right)^1}\\right| + \\left|{\\left({6-7}\\right)^1}\\right| \\\\ F(6) = 0 + 5+ 1 \\\\ F(6) = 6 $\nHere $6$ is the minumum value for $F(x)$ for any integer value of $x$.Sample Input 2\n3 2\n6 1 7\nSample Output 2\n5\nExplanation 2\n$F(5) = \\displaystyle\\sum_{i=1}^{N}{\\left|{\\left({5-A_i}\\right)^K}\\right|} \\\\F(5) = \\left|{\\left({5-6}\\right)^2}\\right| + \\left|{\\left({5-1}\\right)^2}\\right| + \\left|{\\left({5-7}\\right)^2}\\right| \\\\F(5) = 1 + 16 + 4 \\\\F(5) = 21$ \nHere $21$ is the minumum value for $F(x)$ for any integer value of $x$.Sample Input 3\n3 3\n6 1 7\nSample Output 3\n4\nExplanation 3\n$F(4) = \\displaystyle\\sum_{i=1}^{N}{\\left|{\\left({4-A_i}\\right)^K}\\right|} \\\\F(4) = \\left|{\\left({4-6}\\right)^3}\\right| + \\left|{\\left({4-1}\\right)^3}\\right| + \\left|{\\left({4-7}\\right)^3}\\right| \\\\F(4) = 8 + 27 + 27 \\\\F(4) = 62 $\nHere $62$ is the minumum value for $F(x)$ for any integer value of $x$.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n#dt = {} for i in x: dt[i] = dt.get(i,0)+1\r\nimport sys;input = sys.stdin.readline\r\ninp,ip = lambda :int(input()),lambda :[int(w) for w in input().split()]\r\n\r\nn,k = ip()\r\nx = ip()\r\nx.sort()\r\nif k == 1:\r\n a = x[n//2]\r\n b = x[n//2-1]\r\nelse:\r\n s = sum(x)\r\n a = s//n\r\n b = a + 1\r\nsa = sum([abs((a-i)**k) for i in x])\r\nsb = sum([abs((b-i)**k) for i in x])\r\nif sa < sb:\r\n print(a)\r\nelse:\r\n print(b)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3 1\\n6 1 7\\n', 'output': '6\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/COJK2020/problems/CKOJ20B'}","problem_id":"vfc_2094","program":"```python\n#dt = {} for i in x: dt[i] = dt.get(i,0)+1\r\nimport sys;input = sys.stdin.readline\r\ninp,ip = lambda :int(input()),lambda :[int(w) for w in input().split()]\r\n\r\nn,k = ip()\r\nx = ip()\r\nx.sort()\r\nif k == 1:\r\n a = x[n//2]\r\n b = x[n//2-1]\r\nelse:\r\n s = sum(x)\r\n a = s//n\r\n b = a + 1\r\nsa = sum([abs((a-i)**k) for i in x])\r\nsb = sum([abs((b-i)**k) for i in x])\r\nif sa < sb:\r\n print(a)\r\nelse:\r\n print(b)\n```","inputs":"3 1\n6 1 7\n","output":"6\n","actual_output":"6\n","execution_success":true,"sample_index":418},{"source":"apps","task_type":"verifiable_code","in_source_id":"814","prompt":"Solve the following coding problem using the programming language python:\n\nTzuyu gave Nayeon a strip of $N$ cells (numbered $1$ through $N$) for her birthday. This strip is described by a sequence $A_1, A_2, \\ldots, A_N$, where for each valid $i$, the $i$-th cell is blocked if $A_i = 1$ or free if $A_i = 0$. Tzuyu and Nayeon are going to use it to play a game with the following rules:\n- The players alternate turns; Nayeon plays first.\n- Initially, both players are outside of the strip. However, note that afterwards during the game, their positions are always different.\n- In each turn, the current player should choose a free cell and move there. Afterwards, this cell becomes blocked and the players cannot move to it again.\n- If it is the current player's first turn, she may move to any free cell.\n- Otherwise, she may only move to one of the left and right adjacent cells, i.e. from a cell $c$, the current player may only move to the cell $c-1$ or $c+1$ (if it is free).\n- If a player is unable to move to a free cell during her turn, this player loses the game.\nNayeon and Tzuyu are very smart, so they both play optimally. Since it is Nayeon's birthday, she wants to know if she can beat Tzuyu. Find out who wins.\n\n-----Input-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The first line of each test case contains a single integer $N$.\n- The second line contains $N$ space-separated integers $A_1, A_2, \\ldots, A_N$.\n\n-----Output-----\nFor each test case, print a single line containing the string \"Yes\" if Nayeon wins the game or \"No\" if Tzuyu wins (without quotes).\n\n-----Constraints-----\n- $1 \\le T \\le 40,000$\n- $2 \\le N \\le 3\\cdot 10^5$\n- $0 \\le A_i \\le 1$ for each valid $i$\n- $A_1 = A_N = 1$\n- the sum of $N$ over all test cases does not exceed $10^6$\n\n-----Subtasks-----\nSubtask #1 (50 points): $A_i = 0$ for each $i$ ($2 \\le i \\le N-1$)\nSubtask #2 (50 points): original constraints\n\n-----Example Input-----\n4\n7\n1 1 0 0 0 1 1\n8\n1 0 1 1 1 0 0 1\n4\n1 1 0 1\n4\n1 1 1 1\n\n-----Example Output-----\nYes\nNo\nYes\nNo\n\n-----Explanation-----\nExample case 1: Since both Nayeon and Tzuyu play optimally, Nayeon can start e.g. by moving to cell $4$, which then becomes blocked. Tzuyu has to pick either the cell $3$ or the cell $5$, which also becomes blocked. Nayeon is then left with only one empty cell next to cell $4$ (the one Tzuyu did not pick); after she moves there, Tzuyu is unable to move, so she loses the game.\nExample case 2: Regardless of what cell Nayeon moves to at the start, Tzuyu will always be able to beat her.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfor _ in range(int(input())):\n n=int(input())\n\n\n def maxConsequtiveOnes(lst):\n _max = 0\n _ones = [0]\n for i in lst:\n if i == 0:\n _max += 1\n if i == 1:\n _max = 0\n _ones.append(_max)\n return max(_ones)\n\n\n a = list(map(int, input().split()))\n b = maxConsequtiveOnes(a)\n if (b % 2 == 0):\n print(\"No\")\n else:\n print(\"Yes\")\n\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '4\\n7\\n1 1 0 0 0 1 1\\n8\\n1 0 1 1 1 0 0 1\\n4\\n1 1 0 1\\n4\\n1 1 1 1\\n', 'output': 'Yes\\nNo\\nYes\\nNo\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/ARRGAME'}","problem_id":"vfc_2098","program":"```python\nfor _ in range(int(input())):\n n=int(input())\n\n\n def maxConsequtiveOnes(lst):\n _max = 0\n _ones = [0]\n for i in lst:\n if i == 0:\n _max += 1\n if i == 1:\n _max = 0\n _ones.append(_max)\n return max(_ones)\n\n\n a = list(map(int, input().split()))\n b = maxConsequtiveOnes(a)\n if (b % 2 == 0):\n print(\"No\")\n else:\n print(\"Yes\")\n\n\n```","inputs":"4\n7\n1 1 0 0 0 1 1\n8\n1 0 1 1 1 0 0 1\n4\n1 1 0 1\n4\n1 1 1 1\n","output":"Yes\nNo\nYes\nNo\n","actual_output":"Yes\nNo\nYes\nNo\n","execution_success":true,"sample_index":419},{"source":"apps","task_type":"verifiable_code","in_source_id":"815","prompt":"Solve the following coding problem using the programming language python:\n\nJohnny has some difficulty memorizing the small prime numbers. So, his computer science teacher has asked him to play with the following puzzle game frequently.\nThe puzzle is a 3x3 board consisting of numbers from 1 to 9. The objective of the puzzle is to swap the tiles until the following final state is reached:\n1 2 3\n4 5 6\n7 8 9\n\nAt each step, Johnny may swap two adjacent tiles if their sum is a prime number. Two tiles are considered adjacent if they have a common edge.\nHelp Johnny to find the shortest number of steps needed to reach the goal state.\n\n-----Input-----\nThe first line contains t, the number of test cases (about 50). Then t test cases follow. Each test case consists of a 3x3 table describing a puzzle which Johnny would like to solve.\nThe input data for successive test cases is separated by a blank line.\n\n-----Output-----\nFor each test case print a single line containing the shortest number of steps needed to solve the corresponding puzzle. If there is no way to reach the final state, print the number -1.\n\n-----Example-----\nInput:\n2\n\n7 3 2 \n4 1 5 \n6 8 9 \n\n9 8 5 \n2 4 1 \n3 7 6 \n\nOutput:\n6\n-1\n\n-----Output details-----\nThe possible 6 steps in the first test case are described in the following figure:\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\r\nfrom collections import deque\r\nprimes = {2,3,5,7,11,13,17}\r\nedges = [(0,3),(0,1),(1,2),(1,4),(2,5),(3,4),(3,6),(4,5),(4,7),(5,8),(6,7),(7,8)]\r\nx = [1,2,3,4,5,6,7,8,9]\r\navail = {tuple(x):0}\r\nq = deque([x])\r\nwhile q:\r\n curr = q.popleft();\r\n for e in edges:\r\n if curr[e[0]]+curr[e[1]] in primes:\r\n nxt = curr[0:]\r\n nxt[e[0]],nxt[e[1]] = nxt[e[1]], nxt[e[0]] \r\n nxtt = tuple(nxt)\r\n if nxtt not in avail:\r\n avail[nxtt] = avail[tuple(curr)]+1\r\n q.append(nxt)\r\nt = int(input())\r\nwhile t:\r\n inp = input()\r\n grid = []\r\n for i in range(3):\r\n inp = input()\r\n for j in inp.strip().split(\" \"):\r\n grid.append(int(j))\r\n gridt = tuple(grid)\r\n if gridt in avail: print(avail[gridt])\r\n else: print(-1);\r\n t-= 1\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n\\n7 3 2 \\n4 1 5 \\n6 8 9 \\n\\n9 8 5 \\n2 4 1 \\n3 7 6 \\n\\n\\n', 'output': '6\\n-1\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/H1'}","problem_id":"vfc_2102","program":"```python\n# cook your dish here\r\nfrom collections import deque\r\nprimes = {2,3,5,7,11,13,17}\r\nedges = [(0,3),(0,1),(1,2),(1,4),(2,5),(3,4),(3,6),(4,5),(4,7),(5,8),(6,7),(7,8)]\r\nx = [1,2,3,4,5,6,7,8,9]\r\navail = {tuple(x):0}\r\nq = deque([x])\r\nwhile q:\r\n curr = q.popleft();\r\n for e in edges:\r\n if curr[e[0]]+curr[e[1]] in primes:\r\n nxt = curr[0:]\r\n nxt[e[0]],nxt[e[1]] = nxt[e[1]], nxt[e[0]] \r\n nxtt = tuple(nxt)\r\n if nxtt not in avail:\r\n avail[nxtt] = avail[tuple(curr)]+1\r\n q.append(nxt)\r\nt = int(input())\r\nwhile t:\r\n inp = input()\r\n grid = []\r\n for i in range(3):\r\n inp = input()\r\n for j in inp.strip().split(\" \"):\r\n grid.append(int(j))\r\n gridt = tuple(grid)\r\n if gridt in avail: print(avail[gridt])\r\n else: print(-1);\r\n t-= 1\n```","inputs":"2\n\n7 3 2 \n4 1 5 \n6 8 9 \n\n9 8 5 \n2 4 1 \n3 7 6 \n\n\n","output":"6\n-1\n","actual_output":"6\n-1\n","execution_success":true,"sample_index":420},{"source":"apps","task_type":"verifiable_code","in_source_id":"816","prompt":"Solve the following coding problem using the programming language python:\n\nThis is another problem about Indraneel's library. His library has one long shelf. His books are numbered and he identifies the books by their number. Each book has a distinct number.\nHe has lost many books, since many of his friends borrow his books and never bother to return them. He does not want to lose any more books and has decided to keep a record of all books that he lends to his friends. To make the task of borrowing a book a little difficult, he has given the following instructions to his friends: when they borrow a book, they must record in a register its position from the left among the books currently on the shelf.\nSuppose there are $5$ books in the library and they are arranged as follows:\n261421532614215326 \\quad 1 \\quad 42 \\quad 15 \\quad 3\nIf someone walks in and borrows the book $42$, then he will record $3$ in the register because this book is the third from the left on the shelf. Now the shelf looks like this:\n26115326115326 \\quad 1 \\quad 15 \\quad 3\nIf the next person borrow the book $3$, he writes down $4$ in the register since this is currently the fourth book from the left on the shelf, and so on.\nIndraneel knows the initial arrangement of the books in his library at the time that he introduced the register system. After a while he examines his register and would like to know which books have been borrowed. Your task is to write a program to help Indraneel solve this problem.\n\n-----Input:-----\nThe first line of the input contains a single integer $M$ indicating the number of books in Indraneel's library. The next line contains $M$ distinct positive integers describing the sequence in which the books are arranged on the library shelf. The third line of input contains a single integer $N$ indicating the number of entries in the register. This, in turn, is followed by $N$ lines (lines $4$ to $N+3$), each containing one positive integer. The integer on line $3+i$ indicates the position from left of the book ith book borrowed. (You may assume that the number on line $3+i$ is at most $M-i+1$.)\n\n-----Output:-----\n$N$ lines with one positive integer on each line. The number on line $i$ is the book borrowed by the ith borrower.\n\n-----Constraints:-----\n- $1 \\leq M \\leq 1000000$.\n- $1 \\leq N \\leq 4000$.\n\n-----Sample Input-----\n5\n26 1 42 15 3 \n2\n3\n4\n\n-----Sample Output-----\n42\n3\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\ndef bookList():\r\n numBooks=int(input())\r\n bookNum=[int(x) for x in input().split()]\r\n takenBooks=int(input())\r\n for i in range(takenBooks):\r\n takenBookPos=(int(input()))\r\n a=bookNum[takenBookPos-1]\r\n print(a)\r\n bookNum.remove(a)\r\n\r\nbookList()\r\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '5\\n26 1 42 15 3\\n2\\n3\\n4\\n', 'output': '42\\n3\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/IARCSJUD/problems/BOOKLIST'}","problem_id":"vfc_2106","program":"```python\ndef bookList():\r\n numBooks=int(input())\r\n bookNum=[int(x) for x in input().split()]\r\n takenBooks=int(input())\r\n for i in range(takenBooks):\r\n takenBookPos=(int(input()))\r\n a=bookNum[takenBookPos-1]\r\n print(a)\r\n bookNum.remove(a)\r\n\r\nbookList()\r\n\n```","inputs":"5\n26 1 42 15 3\n2\n3\n4\n","output":"42\n3\n","actual_output":"42\n3\n","execution_success":true,"sample_index":421},{"source":"apps","task_type":"verifiable_code","in_source_id":"817","prompt":"Solve the following coding problem using the programming language python:\n\nAmit is going on a date and he wants to gift his date an array of positive numbers. But he is running short on money. He already has an array of numbers in design. Cost of an array of numbers is the sum of elements in it. But he wants to minimize the cost of making it. \nSo he does the following number of operations one by one for any number of times:\nHe chooses two adjacent elements ,replace them by one element with value = XOR of the two numbers. This operation reduces length of array (and elements are re-numerated accordingly)\nFind the minimum amount of money that Amit needs to spend to gift his date.\n\n-----Input:-----\n- First line will contain $T$, number of testcases. Then the testcases follow. \n- Each testcase contains of $2$ lines of input, first line contains a single integer $N$ and the second line contains $N$ elements - $A1,A2,A3,.....,AN$ \n\n-----Output:-----\nFor each testcase, output in a single line answer denoting the minimum cost\n\n-----Constraints-----\n- $1 \\leq T \\leq 10$\n- $1 \\leq N \\leq 10^5$\n- $0 \\leq Ai \\leq 10^9$ for $1\\leq i \\leq N$\n\n-----Sample Input:-----\n3\n5\n8 4 1 5 0\n5\n1 2 4 0 8\n2\n10 10\n\n-----Sample Output:-----\n8\n15\n0\n\n-----EXPLANATION:-----\nFor first case,\nThis array is :\n$[8,4,1,5,0] -> [8,4,4,0] -> [8,0,0]$. Sum=$8$ So the answer is 8.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfor _ in range(int(input())):\r\n n=int(input())\r\n l=list(map(int,input().split()))\r\n su=l[0]\r\n for i in range(1,n):\r\n su^=l[i]\r\n print(su)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\n5\\n8 4 1 5 0\\n5\\n1 2 4 0 8\\n2\\n10 10\\n', 'output': '8\\n15\\n0\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/INDC2021/problems/DATEGIFT'}","problem_id":"vfc_2110","program":"```python\nfor _ in range(int(input())):\r\n n=int(input())\r\n l=list(map(int,input().split()))\r\n su=l[0]\r\n for i in range(1,n):\r\n su^=l[i]\r\n print(su)\n```","inputs":"3\n5\n8 4 1 5 0\n5\n1 2 4 0 8\n2\n10 10\n","output":"8\n15\n0\n","actual_output":"8\n15\n0\n","execution_success":true,"sample_index":422},{"source":"apps","task_type":"verifiable_code","in_source_id":"818","prompt":"Solve the following coding problem using the programming language python:\n\nWe all know Gru loves Agnes very much. One day Agnes asked Gru to answer some of her queries. She lined up $N$ minions in a straight line from $1$ to $N$. \nYou are given an array $A$ which contains the height of minions. Agnes will ask him several queries. In each query, Gru has to tell whether the bitwise AND of $A[L \\ldots R]$ is EVEN or ODD. Since Gru is busy planning the biggest heist on Earth, he asks for your help.\n\n-----Input:-----\n- First line of the input contains an integer $T$ denoting the number of test cases.\nFor each test case:-\n- First line contains an integer $N$ denoting the number of elements.\n- Second line contains $N$ spaced integer representing array elements.\n- Third line contains $Q$ representing number of query.\n- Next $Q$ lines contains two integer $L$ and $R$ as defined above.\n\n-----Output:-----\nFor each query, output \"EVEN\" or \"ODD\" without quotes.\n\n-----Constraints-----\n- $1 \\leq T \\leq 10$\n- $1 \\leq N \\leq 10^5$\n- $1 \\leq A_i \\leq 10^5$\n- $1 \\leq Q \\leq 10^5$\n\n-----Sample Input:-----\n1\n5\n1 3 2 4 5\n3\n1 2 \n1 5\n3 4\n\n-----Sample Output:-----\nODD\nEVEN\nEVEN\n\n-----Explanation-----\n- For the first query, the bitwise AND of 1 and 3 is 1, which is Odd. Hence the first output is ODD.\n- For the third query, the bitwise AND of 2 and 4 is 0, which is Even. Hence the third output is EVEN.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\nfor _ in range(int(input())):\n n=int(input())\n a=[int(x) for x in input().split()]\n sum=0\n for i in range(n):\n if a[i]%2==0:\n sum+=1\n a[i]=sum \n q=int(input())\n while q:\n l,r=map(int,input().split())\n if l!=1:\n c=a[r-1]-a[l-2]\n else:\n c=a[r-1] \n if c==0:\n print(\"ODD\")\n else:\n print(\"EVEN\")\n q-=1\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n5\\n1 3 2 4 5\\n3\\n1 2\\n1 5\\n3 4\\n', 'output': 'ODD\\nEVEN\\nEVEN\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/MINIAND'}","problem_id":"vfc_2114","program":"```python\n# cook your dish here\nfor _ in range(int(input())):\n n=int(input())\n a=[int(x) for x in input().split()]\n sum=0\n for i in range(n):\n if a[i]%2==0:\n sum+=1\n a[i]=sum \n q=int(input())\n while q:\n l,r=map(int,input().split())\n if l!=1:\n c=a[r-1]-a[l-2]\n else:\n c=a[r-1] \n if c==0:\n print(\"ODD\")\n else:\n print(\"EVEN\")\n q-=1\n```","inputs":"1\n5\n1 3 2 4 5\n3\n1 2\n1 5\n3 4\n","output":"ODD\nEVEN\nEVEN\n","actual_output":"ODD\nEVEN\nEVEN\n","execution_success":true,"sample_index":423},{"source":"apps","task_type":"verifiable_code","in_source_id":"819","prompt":"Solve the following coding problem using the programming language python:\n\nMotu wants to learn Cricket from a coach, but firstly coach wants to test his IQ level, so he gave Motu $1$ $Red$ $ball$ and $1$ $Black$ $ball$ , and asked him to buy other $x \u2013 1$ red balls and other $y \u2013 1$ black balls from the market. But he put some conditions on buying balls, that if he has $R$ red and $B$ black balls then he can either buy $B$ red balls or $R$ black balls in one operation. He can perform this operation as many times as he want. But as Motu is not so good in solving problems so he needs your help. So you have to tell him whether his coach\u2019s task possible or not.\n\n-----Input:-----\n- First line will contain $T$, number of testcases. Then the testcases follow. \n- Each testcase contains of a single line of input, two integers $x , y$. \n\n-----Output:-----\nFor each testcase, print $YES$, if it is possible to complete coach task, else print $NO$(without quotes) in a separate line.\n\n-----Constraints-----\n- $1 \\leq T \\leq 100000$\n- $1 \\leq x, y \\leq$ 10^18\n\n-----Sample Input:-----\n2\n1 2\n2 3\n\n-----Sample Output:-----\nYES\nYES\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nT=int(input())\nwhile T:\n x,y=map(int,input().split())\n while(y): \n x, y = y, x % y\n if x==1:\n print(\"YES\")\n else:\n print(\"NO\")\n T-=1\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n1 2\\n2 3\\n', 'output': 'YES\\nYES\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/CCOD2020/problems/NITGOC'}","problem_id":"vfc_2118","program":"```python\nT=int(input())\nwhile T:\n x,y=map(int,input().split())\n while(y): \n x, y = y, x % y\n if x==1:\n print(\"YES\")\n else:\n print(\"NO\")\n T-=1\n```","inputs":"2\n1 2\n2 3\n","output":"YES\nYES\n","actual_output":"YES\nYES\n","execution_success":true,"sample_index":424},{"source":"apps","task_type":"verifiable_code","in_source_id":"821","prompt":"Solve the following coding problem using the programming language python:\n\nYou are given $n$ intervals on the $X$ axis. Each interval $i$ is specified by its ends $[L_i, R_i]$. You want to color each interval either blue or yellow. After coloring all the intervals, the $X$ axis will will have $4$ colors:\n- White, the part of $X$ axis contained in no interval\n- Blue, the part of $X$ axis contained in atleast one blue colored interval and no yellow colored interval.\n- Yellow, the part of $X$ axis contained in atleast one yellow colored interval and no blue colored interval.\n- Green, the part of $X$ axis contained in at least one blue colored interval and at least one yellow colored interval.\nYou want to color the intervals so that the total length of the part colored green is maximized. If there are multiple ways to color which maximize the green part, you can output any of them.\n\n-----Input:-----\n- First line will contain $T$, number of testcases. Then the testcases follow. \n- The first line of each testcase contains $n$, the number of intervals.\n- The $i^{\\text{th}}$ of the next $n$ lines contains two integers $L_i$ and $R_i$ describing the $i^{\\text{th}}$ interval.\n\n-----Output:-----\nFor each testcase, output a single string on a new line, whose $i^{\\text{th}}$ character is $0$ if you color the $i^{\\text{th}}$ interval blue, and $1$ if you color it yellow.\n\n-----Constraints-----\n- $ 1 \\leq T \\leq 10^5 $\n- $ 1 \\leq n \\leq 10^5 $\n- The sum of $n$ over all testcases doesn't exceed $10^5$.\n- $ 1 \\leq L_i \\leq R_i \\leq 10^9 $ for al $ 1 \\leq i \\leq n$.\n\n-----Sample Input:-----\n1\n3\n3 7\n2 5\n6 9\n\n-----Sample Output:-----\n100\n\n-----Explanation:-----\nThe intervals are $[3, 7]$, $[2, 5]$, $[6, 9]$. It is optimal to color them in yellow, blue and blue respectively. In this coloring:\n- $[2, 3) \\cup (7, 9]$ is colored blue.\n- $(5, 6)$ is colored yellow.\n- $[3, 5] \\cup [6, 7]$ is colored green, with a total length of $(5 - 3) + (7 - 6) = 3$.\n- Rest of the $X$ axis is colored white.\nPlease note that colors at the endpoints of the intervals don't matter when computing the lengths, and we can ignore them. Open and closed intervals have been used in the explanation section only for clarity, and it doesn't matter whether they are open or closed.\nNote that 011 is also a valid output.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfor _ in range(int(input())):\n n = int(input())\n ls = []\n rs = []\n lrs = []\n\n for i in range(n):\n l, r = map(int, input().split())\n ls.append(l)\n rs.append(r)\n lrs.append((l, r, i))\n\n lrs.sort()\n\n c = 0\n maxi = -1\n\n res = [-1] * n\n for l, r, i in lrs:\n if ls[i] > maxi:\n maxi = rs[i]\n res[i] = c\n\n elif rs[i] <= maxi:\n res[i] = 1^c\n\n else:\n maxi = rs[i]\n c ^= 1\n res[i] = c\n\n print(*res, sep='')\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n3\\n3 7\\n2 5\\n6 9\\n', 'output': '100\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/COLINT'}","problem_id":"vfc_2126","program":"```python\nfor _ in range(int(input())):\n n = int(input())\n ls = []\n rs = []\n lrs = []\n\n for i in range(n):\n l, r = map(int, input().split())\n ls.append(l)\n rs.append(r)\n lrs.append((l, r, i))\n\n lrs.sort()\n\n c = 0\n maxi = -1\n\n res = [-1] * n\n for l, r, i in lrs:\n if ls[i] > maxi:\n maxi = rs[i]\n res[i] = c\n\n elif rs[i] <= maxi:\n res[i] = 1^c\n\n else:\n maxi = rs[i]\n c ^= 1\n res[i] = c\n\n print(*res, sep='')\n```","inputs":"1\n3\n3 7\n2 5\n6 9\n","output":"100\n","actual_output":"100\n","execution_success":true,"sample_index":426},{"source":"apps","task_type":"verifiable_code","in_source_id":"822","prompt":"Solve the following coding problem using the programming language python:\n\nDoubleville, a small town in Texas, was attacked by the aliens. They have abducted some of the residents and taken them to the a spaceship orbiting around earth. After some (quite unpleasant) human experiments, the aliens cloned the victims, and released multiple copies of them back in Doubleville. So now it might happen that there are 6 identical person named Hugh F. Bumblebee: the original person and its 5 copies. The Federal Bureau of Unauthorized Cloning (FBUC) charged you with the task of determining how many copies were made from each person. To help you in your task, FBUC have collected a DNA sample from each person. All copies of the same person have the same DNA sequence, and different people have different sequences (we know that there are no identical twins in the town, this is not an issue).\n\n\n-----Input-----\n\nThe input contains several blocks of test cases. Each case begins with a line containing two integers: the number 1 <= n <= 20000 people, and the length 1 <= m <= 20 of the DNA sequences. The next n lines contain the DNA sequences: each line contains a sequence of m characters, where each character is either 'A', 'C', 'G' or 'T'.\n\nThe input is terminated by a block with n = m = 0 .\n\n-----Output-----\nFor each test case, you have to output n lines, each line containing a single integer. The first line contains the number of different people that were not copied. The second line contains the number of people that were copied only once (i.e., there are two identical copies for each such person.) The third line contains the number of people that are present in three identical copies, and so on: the i -th line contains the number of persons that are present in i identical copies. For example, if there are 11 samples, one of them is from John Smith, and all the others are from copies of Joe Foobar, then you have to print '1' in the first and the tenth lines, and '0' in all the other lines.\n\n-----Example-----\nInput:\n\n9 6\nAAAAAA\nACACAC\nGTTTTG\nACACAC\nGTTTTG\nACACAC\nACACAC\nTCCCCC\nTCCCCC\n0 0\n\nOutput:\n\n1\n2\n0\n1\n0\n0\n0\n0\n0\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\ndef main():\n while True:\n [n, m] = [int(i) for i in input().split()]\n if n == m and n == 0:\n break\n cache = {}\n for i in range(n):\n dna = input().rstrip('\\n')\n if dna in cache:\n cache[dna] = 1 + cache[dna]\n else:\n cache[dna] = 1\n c = [0 for i in range(n + 1)]\n for dna in cache:\n c[cache[dna]] = 1 + c[cache[dna]]\n for i in range(1, n + 1):\n print(c[i])\n \ndef __starting_point():\n main()\n__starting_point()\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '9 6\\nAAAAAA\\nACACAC\\nGTTTTG\\nACACAC\\nGTTTTG\\nACACAC\\nACACAC\\nTCCCCC\\nTCCCCC\\n0 0\\n\\n\\n', 'output': '1\\n2\\n0\\n1\\n0\\n0\\n0\\n0\\n0\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/PRFT2012/problems/PD11'}","problem_id":"vfc_2130","program":"```python\ndef main():\n while True:\n [n, m] = [int(i) for i in input().split()]\n if n == m and n == 0:\n break\n cache = {}\n for i in range(n):\n dna = input().rstrip('\\n')\n if dna in cache:\n cache[dna] = 1 + cache[dna]\n else:\n cache[dna] = 1\n c = [0 for i in range(n + 1)]\n for dna in cache:\n c[cache[dna]] = 1 + c[cache[dna]]\n for i in range(1, n + 1):\n print(c[i])\n \ndef __starting_point():\n main()\n__starting_point()\n```","inputs":"9 6\nAAAAAA\nACACAC\nGTTTTG\nACACAC\nGTTTTG\nACACAC\nACACAC\nTCCCCC\nTCCCCC\n0 0\n\n\n","output":"1\n2\n0\n1\n0\n0\n0\n0\n0\n","actual_output":"1\n2\n0\n1\n0\n0\n0\n0\n0\n","execution_success":true,"sample_index":427},{"source":"apps","task_type":"verifiable_code","in_source_id":"823","prompt":"Solve the following coding problem using the programming language python:\n\nChef likes problems which using some math. Now he asks you to solve next one. You have 4 integers, Chef wondering is there non-empty subset which has sum equals 0.\n\n-----Input-----\nThe first line of input contains T - number of test cases. \nEach of the next T lines containing four pairwise distinct integer numbers - a, b, c, d.\n\n-----Output-----\nFor each test case output \"Yes\", if possible to get 0 by choosing non-empty subset of {a, b, c, d} with sum equal 0, or \"No\" in another case.\n\n-----Constraints-----\n- 1 \u2264 T \u2264 103\n- -106 \u2264 a, b, c, d \u2264 106 \n\n-----Example-----\nInput:\n3\n1 2 0 3\n1 2 4 -1\n1 2 3 4\n\nOutput:\nYes\nYes\nNo\n\n-----Explanation-----\nExample case 1. We can choose subset {0} \nExample case 2. We can choose subset {-1, 1}\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\n\n# cook your dish here\n\n \n\nt = int(input())\nwhile t:\n t-=1\n c=0\n ar=[int(i) for i in input().strip().split()]\n for i in range(1,16):\n b=bin(i)[2:].zfill(4)\n s=0\n for i in range(4):\n if b[i]=='1':\n s+=ar[i]\n \n if(s==0):\n c=1\n break\n \n print(\"Yes\" if c==1 else \"No\")\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\n1 2 0 3\\n1 2 4 -1\\n1 2 3 4\\n', 'output': 'Yes\\nYes\\nNo\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/CHEFSETC'}","problem_id":"vfc_2134","program":"```python\n# cook your dish here\n\n# cook your dish here\n\n \n\nt = int(input())\nwhile t:\n t-=1\n c=0\n ar=[int(i) for i in input().strip().split()]\n for i in range(1,16):\n b=bin(i)[2:].zfill(4)\n s=0\n for i in range(4):\n if b[i]=='1':\n s+=ar[i]\n \n if(s==0):\n c=1\n break\n \n print(\"Yes\" if c==1 else \"No\")\n\n```","inputs":"3\n1 2 0 3\n1 2 4 -1\n1 2 3 4\n","output":"Yes\nYes\nNo\n","actual_output":"Yes\nYes\nNo\n","execution_success":true,"sample_index":428},{"source":"apps","task_type":"verifiable_code","in_source_id":"824","prompt":"Solve the following coding problem using the programming language python:\n\nCorruption is on the rise in the country of Freedonia, Gru's home. Gru wants to end this for good and for that he needs the help of his beloved minions.\nThis corruption network can be represented in the form of a tree having N$N$ nodes and N\u22121$N-1$ edges. The nodes are numbered from 1$1$ to N$N$, and the tree is rooted at node 1$1$. These nodes represent the corrupt officials and each corrupt official works under some other corrupt official except the Boss who is represented by node 1$1$.\nGru believes in divide and conquer and thinks that this network needs to be divided into as many sub-networks as possible.\nHe commands the minions to kill some of the corrupt officials in order to break the network into maximum sub-networks. But as you know, these corrupt officials are very sharp, and hence these assassinations need to be done very smartly and silently, without leaving any traces. To achieve this Gru devises a strategy, in which he designs an operation, and that operation can be applied by the minions any number of times (even 0). \nIn one operation the minions can select any one leaf node official [that is an official who does not have any other official beneath him] in the graph and kill him along with all his ancestors$ancestors$ officials till the root$root$ of the tree in which the operation is applied (this is done to wipe all traces of the operation). This deleted all those nodes from the graph, and also, while doing so, all the associated edges/connections$edges/connections$ of the leaf node and its ancestors are also destroyed. Hence after applying this operation on any tree, it breaks into some connected components which are also trees, which are the new sub-networks.\nNow the minions are a bit lazy and will do the task someday, but they need to submit a report to Gru containing the number of the maximum$maximum$ connected$connected$ components$components$ that they could achieve by applying the operation any number of times. To do this, the minions require your help. So help the minions by finding out the maximum$maximum$ no.$no.$ of$of$ connected$connected$ components$components$ that can be achieved.\nNote: After each operation, the topmost node (node with the lowest level. It can be proved that there will always be a unique node with the lowest level in each tree) of each of the remaining trees becomes the root of that particular tree (that is, after the first operation it can be visualized that the graph converts into a forest of rooted trees)\n\n-----Input:-----\n- First line will contain N$N$, number of nodes in the tree. \n- Next N\u22121$N-1$ lines contains 2 integers U$U$, V$V$ denoting the endpoints of the ith$i^{th}$ edge.\n\n-----Output:-----\n- Print the maximum number of connected components you can obtain after doing the operation any number of times.\n\n-----Constraints-----\n- 1\u2264N\u2264106$1 \\leq N \\leq 10^6$\n- 1\u2264U,V\u2264N$1 \\leq U,V \\leq N$\n\n-----Sample Input:-----\n7\n1 2\n1 3\n2 4\n2 5\n3 6\n3 7\n\n-----Sample Output:-----\n2\n\n-----EXPLANATION:-----\nWe have 4 leaf nodes in this tree: 4 5 6 7. Suppose we delete node 5, then along with it we also delete node 2 and node 1. so after the deletion we are left with 2 trees, one consisting of only node 4 as the root node of that particular tree, and the other consisting of node 3,6,7 with node 3 as the root node. This can also be achieved by deleting any of the other leaf nodes and it can be proved that we cannot obtain more than 2 connected components in this example.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfrom sys import stdin,stdout\r\ninput=stdin.readline\r\nn=int(input())\r\na=[[] for i in range(n)]\r\nfor i in range(n-1):\r\n u,v=map(int,input().split())\r\n a[u-1].append(v-1)\r\n a[v-1].append(u-1)\r\nb=[0]*n\r\nvis=[0]*n\r\nst=[(0,0)]\r\nvis[0]=1\r\npa=[0]*n\r\nwhile st:\r\n x,y=st.pop()\r\n b[x]=y\r\n for i in a[x]:\r\n if vis[i]==0:\r\n pa[i]=x\r\n vis[i]=1\r\n if x==0:\r\n st.append((i,y+len(a[x])-1))\r\n else:\r\n st.append((i,y+len(a[x])-2))\r\nc=[]\r\nfor i in range(1,n):\r\n if len(a[i])==1:\r\n c.append((b[i],i))\r\nc.sort()\r\nans=0\r\nwhile c:\r\n x,y=c.pop()\r\n m=y\r\n p=0\r\n while y!=0 and pa[y]!=-1:\r\n y=pa[y]\r\n if pa[y]==-1:\r\n break\r\n if y!=0:\r\n p+=(len(a[y])-2)\r\n else:\r\n p+=(len(a[y])-1)\r\n if p>=1:\r\n p=0\r\n while m!=0 and pa[m]!=-1:\r\n x=m\r\n if pa[m]==-1:\r\n break\r\n m=pa[m]\r\n pa[x]=-1\r\n if m!=0:\r\n p+=(len(a[m])-2)\r\n else:\r\n p+=(len(a[m])-1)\r\n if y==0:\r\n pa[0]=-1\r\nfor i in range(n):\r\n if pa[i]!=-1:\r\n st=[i]\r\n pa[i]=-1\r\n while st:\r\n x=st.pop()\r\n for j in a[x]:\r\n if pa[j]!=-1:\r\n pa[j]=-1\r\n st.append(j)\r\n ans+=1\r\nprint(ans)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '7\\n1 2\\n1 3\\n2 4\\n2 5\\n3 6\\n3 7\\n', 'output': '2\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/MINIKILL'}","problem_id":"vfc_2138","program":"```python\nfrom sys import stdin,stdout\r\ninput=stdin.readline\r\nn=int(input())\r\na=[[] for i in range(n)]\r\nfor i in range(n-1):\r\n u,v=map(int,input().split())\r\n a[u-1].append(v-1)\r\n a[v-1].append(u-1)\r\nb=[0]*n\r\nvis=[0]*n\r\nst=[(0,0)]\r\nvis[0]=1\r\npa=[0]*n\r\nwhile st:\r\n x,y=st.pop()\r\n b[x]=y\r\n for i in a[x]:\r\n if vis[i]==0:\r\n pa[i]=x\r\n vis[i]=1\r\n if x==0:\r\n st.append((i,y+len(a[x])-1))\r\n else:\r\n st.append((i,y+len(a[x])-2))\r\nc=[]\r\nfor i in range(1,n):\r\n if len(a[i])==1:\r\n c.append((b[i],i))\r\nc.sort()\r\nans=0\r\nwhile c:\r\n x,y=c.pop()\r\n m=y\r\n p=0\r\n while y!=0 and pa[y]!=-1:\r\n y=pa[y]\r\n if pa[y]==-1:\r\n break\r\n if y!=0:\r\n p+=(len(a[y])-2)\r\n else:\r\n p+=(len(a[y])-1)\r\n if p>=1:\r\n p=0\r\n while m!=0 and pa[m]!=-1:\r\n x=m\r\n if pa[m]==-1:\r\n break\r\n m=pa[m]\r\n pa[x]=-1\r\n if m!=0:\r\n p+=(len(a[m])-2)\r\n else:\r\n p+=(len(a[m])-1)\r\n if y==0:\r\n pa[0]=-1\r\nfor i in range(n):\r\n if pa[i]!=-1:\r\n st=[i]\r\n pa[i]=-1\r\n while st:\r\n x=st.pop()\r\n for j in a[x]:\r\n if pa[j]!=-1:\r\n pa[j]=-1\r\n st.append(j)\r\n ans+=1\r\nprint(ans)\n```","inputs":"7\n1 2\n1 3\n2 4\n2 5\n3 6\n3 7\n","output":"2\n","actual_output":"2\n","execution_success":true,"sample_index":429},{"source":"apps","task_type":"verifiable_code","in_source_id":"825","prompt":"Solve the following coding problem using the programming language python:\n\nOur Chef is doing what he is best at, COOKING A BARBECUE for his guests. He has invited all of us, and taking the help of his apprentice to smoke the barbecues. The chef has got BBQ sticks, each can take N fillings, and he presents N distinctly filled sticks in front his guests forming a N*N matrix\n\nBut here is the problem, he has got only two type of fillings, meat and capsicum, but still wants the N sticks to look \"presentable\", he is very particular about it. As a solution he fills the main diagonal of the N*N matrix with the same type of filling (either meat or capsicum) forming a \"presentable\" set\n\nThe Chef's apprentice is a fool, so the Chef asks him to cook M distinctly filled sticks ,so that the Chef is sure that among M there exist N sticks forming a \"presentable\" set. Your job is to determine smallest possible value of M.\n\n\n-----Input-----\nT, the number of test cases, followed by T lines. \nEach line containing the positive integer N >= 4\n\n-----Output-----\nT lines of output, each line contain the positive integer M\n\n-----Example-----\nInput:\n1\n4\n\nOutput:\n5\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\ntestcase = int(input())\nfor case in range(testcase):\n n = int(input())\n print(2**(n-2)+1)\n print('\\n') \n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n4\\n', 'output': '5\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/AGTK2012/problems/ALGBBQ'}","problem_id":"vfc_2142","program":"```python\ntestcase = int(input())\nfor case in range(testcase):\n n = int(input())\n print(2**(n-2)+1)\n print('\\n') \n```","inputs":"1\n4\n","output":"5\n","actual_output":"5\n\n\n","execution_success":true,"sample_index":430},{"source":"apps","task_type":"verifiable_code","in_source_id":"826","prompt":"Solve the following coding problem using the programming language python:\n\nLet's consider a rectangular table R consisting of N rows and M columns. Rows are enumerated from 1 to N from top to bottom. Columns are enumerated from 1 to M from left to right. Each element of R is a non-negative integer. R is called steady if the sum of elements in the ith row is not less then the sum of elements in the (i-1)th row for each i where 2 \u2264 i \u2264 N and the sum of elements in the Nth row is less than or equal to M. Your task is to find the number of different steady tables of size N x M modulo 1 000 000 000. \n\n-----Input-----\nThe first line of input contains a single integer T denoting number of test cases. First and the only line of each test case contains two space separated integers N and M denoting the number of rows and columns respectively.\n\n-----Output-----\nFor each test case, print a single integer corresponding to the answer.\n\n-----Constraints-----\n- 1 \u2264 T \u2264 10\n- 1 \u2264 N, M \u2264 2000\n\n-----Subtasks-----\n- Subtask 1 : 1 \u2264 T \u2264 10 , 1 \u2264 N,M \u2264 50 : ( 23 pts )\n- Subtask 2 : 1 \u2264 T \u2264 10 , 1 \u2264 N,M \u2264 500 : ( 29 pts )\n- Subtask 3 : 1 \u2264 T \u2264 10 , 1 \u2264 N,M \u2264 2000 : ( 48 pts )\n\n-----Example-----\nInput:\n3\n1 1\n2 2\n2 3\nOutput:\n2\n25\n273\n\n-----Explanation-----\nTest case 1 : There are only 2 such grids possible 0 and 1.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# This is not my code, it's Snehasish Karmakar's. Refer to http://www.codechef\u00a0\u00a0\u00a0\u00a0.com/viewsolution/7153774\n# for original version.\n# Submitting it to try and work out if it can be sped up.\n\ndef compute_nCr(n,r) :\n C[0][0]=1\n for i in range(1,n+1) :\n# print \"i\",i\n C[i][0]=1\n for j in range(1,min(i,r)+1) :\n if i!=j :\n C[i][j]=(C[i-1][j-1]+C[i-1][j])%MOD\n else :\n C[i][j]=1\n \n \ndef solve(n,m) :\n store=[C[m+i-1][i] for i in range(m+1)]\n \n for i in range(1,n+1) :\n s=1\n for j in range(1,m+1) :\n s=(s+store[j])%MOD\n store[j]=(s*C[m+j-1][j])%MOD\n # print \"a[%d][%d]=%d\"%(i,j,s)\n \n return s \n \nMOD=1000000000\nLIMIT=2000\n \nC=[[0] * (LIMIT + 1) for _ in range(2*LIMIT+1)]\ncompute_nCr(2*LIMIT,LIMIT)\nt=int(input())\n \nwhile t :\n n,m=list(map(int,input().split()))\n print(solve(n,m))\n t-=1\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\n1 1\\n2 2\\n2 3\\n', 'output': '2\\n25\\n273\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/STDYTAB'}","problem_id":"vfc_2146","program":"```python\n# This is not my code, it's Snehasish Karmakar's. Refer to http://www.codechef\u00a0\u00a0\u00a0\u00a0.com/viewsolution/7153774\n# for original version.\n# Submitting it to try and work out if it can be sped up.\n\ndef compute_nCr(n,r) :\n C[0][0]=1\n for i in range(1,n+1) :\n# print \"i\",i\n C[i][0]=1\n for j in range(1,min(i,r)+1) :\n if i!=j :\n C[i][j]=(C[i-1][j-1]+C[i-1][j])%MOD\n else :\n C[i][j]=1\n \n \ndef solve(n,m) :\n store=[C[m+i-1][i] for i in range(m+1)]\n \n for i in range(1,n+1) :\n s=1\n for j in range(1,m+1) :\n s=(s+store[j])%MOD\n store[j]=(s*C[m+j-1][j])%MOD\n # print \"a[%d][%d]=%d\"%(i,j,s)\n \n return s \n \nMOD=1000000000\nLIMIT=2000\n \nC=[[0] * (LIMIT + 1) for _ in range(2*LIMIT+1)]\ncompute_nCr(2*LIMIT,LIMIT)\nt=int(input())\n \nwhile t :\n n,m=list(map(int,input().split()))\n print(solve(n,m))\n t-=1\n```","inputs":"3\n1 1\n2 2\n2 3\n","output":"2\n25\n273\n","actual_output":"2\n25\n273\n","execution_success":true,"sample_index":431},{"source":"apps","task_type":"verifiable_code","in_source_id":"827","prompt":"Solve the following coding problem using the programming language python:\n\nLimak has a string S, that consists of N lowercase English letters.\nLimak then created a new string by repeating S exactly K times.\nFor example, for S = \"abcb\" and K = 2, he would get \"abcbabcb\".\nYour task is to count the number of subsequences \"ab\" (not necessarily consecutive) in the new string.\nIn other words, find the number pairs of indices i < j, such that the i-th and j-th characters in the new string are 'a' and 'b' respectively.\n\n-----Input-----\nThe first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.\nThe first line of each test case contains two integers N and K, denoting the length of the initial string S and the number of repetitions respectively.\nThe second line contains a string S.\nIts length is exactly N, and each of its characters is a lowercase English letter.\n\n-----Output-----\nFor each test case, output a single line containing one integer \u2014 the number of subsequences \"ab\" in the new string.\nFor the given constraints, it can be proved that the answer fits in the 64-bit signed type.\n\n-----Constraints-----\n- 1 \u2264 T \u2264 10\n- 1 \u2264 N \u2264 105\n- 1 \u2264 N * K \u2264 109 (in other words, the new string has length up to 109)\n\n-----Example-----\nInput:\n3\n4 2\nabcb\n7 1\naayzbaa\n12 80123123\nabzbabzbazab\n\nOutput:\n6\n2\n64197148392731290\n\n-----Explanation-----\nTest case 1. Limak repeated the string \"abcb\" 2 times, and so he got \"abcbabcb\". There are 6 occurrences of the subsequence \"ab\":\n- ABcbabcb (the two letters marked uppercase)\n- AbcBabcb\n- AbcbaBcb\n- AbcbabcB\n- abcbABcb\n- abcbAbcB\nTest case 2. Since K = 1, the new string is equal to the given S (\"aayzbaa\"). There are 2 occurrences of the subsequence \"ab\" in this string: AayzBaa and aAyzBaa.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\ntry:\r\n t=int(input())\r\n for i in range(t):\r\n n,k=map(int,input().split())\r\n s=input()\r\n l=[-1]*len(s)\r\n numb=s.count('b')\r\n x=numb\r\n for j in range(len(s)):\r\n if(s[j]=='a'):\r\n l[j]=numb\r\n if(s[j]=='b'):\r\n numb=numb-1\r\n #print(l)\r\n count1=0\r\n for j in range(len(l)):\r\n if(l[j]>0):\r\n count1=count1+(k*(2*l[j]+(k-1)*x))//2\r\n elif(l[j]==0):\r\n count1=count1+(k*(2*0+(k-1)*x))//2\r\n print(count1)\r\nexcept:\r\n pass\r\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\n4 2\\nabcb\\n7 1\\naayzbaa\\n12 80123123\\nabzbabzbazab\\n\\n\\n', 'output': '6\\n2\\n64197148392731290\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/ABREPEAT'}","problem_id":"vfc_2150","program":"```python\ntry:\r\n t=int(input())\r\n for i in range(t):\r\n n,k=map(int,input().split())\r\n s=input()\r\n l=[-1]*len(s)\r\n numb=s.count('b')\r\n x=numb\r\n for j in range(len(s)):\r\n if(s[j]=='a'):\r\n l[j]=numb\r\n if(s[j]=='b'):\r\n numb=numb-1\r\n #print(l)\r\n count1=0\r\n for j in range(len(l)):\r\n if(l[j]>0):\r\n count1=count1+(k*(2*l[j]+(k-1)*x))//2\r\n elif(l[j]==0):\r\n count1=count1+(k*(2*0+(k-1)*x))//2\r\n print(count1)\r\nexcept:\r\n pass\r\n\n```","inputs":"3\n4 2\nabcb\n7 1\naayzbaa\n12 80123123\nabzbabzbazab\n\n\n","output":"6\n2\n64197148392731290\n","actual_output":"6\n2\n64197148392731290\n","execution_success":true,"sample_index":432},{"source":"apps","task_type":"verifiable_code","in_source_id":"828","prompt":"Solve the following coding problem using the programming language python:\n\nChef lives in a big apartment in Chefland. The apartment charges maintenance fees that he is supposed to pay monthly on time. But Chef is a lazy person and sometimes misses the deadlines. The apartment charges 1000 Rs per month as maintenance fees. Also, they also charge a one-time fine of 100 Rs for each of the late payments. It does not matter how late the payment is done, the fine is fixed to be Rs.100.\nChef has been living in the apartment for N months. Now, he wants to switch the apartment, so he has to pay the entire dues to the apartment. The deadline for the N-th month is also over. From his bank statement, he finds the information whether he paid apartment rent for a particular month for not. You are given this information by an array A of size N, where Ai (can be either 0 or 1) specifies whether he has paid the 1000Rs in the i-th month or not. Assume that Chef paid the fees in the i-th month, then this fees will be considered for the earliest month for which Chef has not yet paid the fees.\n\nFor example, assume Chef did not pay any money in first month and 1000Rs in the second month. Then this rent of 1000Rs will be considered for 1st month. But this counts as late payment for the first month's fees, and hence he will have to pay Rs. 100 for that. And since the payment he made in the second month is not accounted for the second month, but rather for the first month, he will incur a fine of Rs.100 even for the second month. \n\nHe has not paid any of the fines so far. Can you please help in finding Chef total due (all the fines, plus all the unpaid maintenance fees) that he has to pay to apartment? \n\n-----Input-----\nFirst line of the input contains an integer T denoting number of test cases. The description of T test cases follows.\nThe first line of each test cases contains an integer N denoting the number of months for which you have to calculate the total amount of money that Chef has to pay at the end of the n month to clear all of his dues.\nNext line of each test case contains N space separated integers (each of them can be either 0 or 1) denoting whether Chef paid the 1000Rs fees in the corresponding month or not. If the corresponding integer is 1, it means that Chef paid the maintenance fees for that month, whereas 0 will mean that Chef did not pay the maintenance fees that month.\n\n-----Output-----\nFor each test case, output a single integer denoting the total amount including fine that Chef has to pay.\n\n-----Constraints-----Constraints\n- 1 \u2264 T \u2264 25\n- 0 \u2264 Ai \u2264 1\n\n-----Subtasks-----\nSubtask #1 (30 points)\n- 1 \u2264 N \u2264 103\n\nSubtask #2 (70 points)\n- 1 \u2264 N \u2264 105\n\n-----Example-----\nInput\n4\n2\n1 1\n2\n0 0\n3\n0 1 0\n2\n0 1\n\nOutput\n0\n2200\n2300\n1200\n\n-----Explanation-----\nExample case 1. Chef paid maintenance fees for both the months. So, he does not have any dues left.\nExample case 2. Chef did not pay the maintenance fees for any of the months. For the first month, he has to pay 1000Rs, and 100Rs fine as a late payment. For second month payments, he just have to pay 1100Rs. So, in total he has a due of 1100 + 1100 = 2200 Rs.\nExample case 3. In the first month, Chef did not pay his maintenance fees. He paid the maintenance of first in the second month. So, he paid a fine of 100Rs for first month. For second and third month, Chef did not pay the maintenance fees. So, he has to pay 1000Rs + 100Rs (of fine) for second month and only 1000Rs + 100Rs (of fine) for third month. In total, Chef has got to pay 100 + 1100 + 1100 = 2300 Rs. \nExample case 4. In the first month, Chef did not pay his maintenance fees. He paid the maintenance of first in the second month. So, he paid a fine of 100Rs for first month. For second month, Chef did not pay the maintenance fees. So, he has to pay 1000Rs + 100Rs (of fine) for second month. In total, Chef has got to pay 100 + 1100 = 1200 Rs.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfor i in range(int(input())):\n a=int(input())\n b=input().split()\n if '0' in b:\n print(100*(a-b.index('0'))+b.count('0')*1000)\n else:\n print(0)\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '4\\n2\\n1 1\\n2\\n0 0\\n3\\n0 1 0\\n2\\n0 1\\n\\n\\n', 'output': '0\\n2200\\n2300\\n1200\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/CHEFAPAR'}","problem_id":"vfc_2154","program":"```python\nfor i in range(int(input())):\n a=int(input())\n b=input().split()\n if '0' in b:\n print(100*(a-b.index('0'))+b.count('0')*1000)\n else:\n print(0)\n\n```","inputs":"4\n2\n1 1\n2\n0 0\n3\n0 1 0\n2\n0 1\n\n\n","output":"0\n2200\n2300\n1200\n","actual_output":"0\n2200\n2300\n1200\n","execution_success":true,"sample_index":433},{"source":"apps","task_type":"verifiable_code","in_source_id":"831","prompt":"Solve the following coding problem using the programming language python:\n\nBear Limak has a sequence of N non-negative integers A1, A2, ..., AN. He defines the score of a segment (consecutive subsequence) as its sum of elements modulo P (not necessarily prime). Find the maximum score of a non-empty segment, and also find the number of segments with this maximum score.\n\n-----Input-----\nFirst line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.\nFor each test case, the first line of the input contains two space separated integers, N and P.\nThe second line contains N space separated integers denoting the sequence.\n\n-----Output-----\nFor each test case, output two space separated integers denoting the maximum score of a segment and the number of segments with the score, respectively.\n\n-----Constraints-----\n- 1 \u2264 T \u2264 10\n- 1 \u2264 N \u2264 105\n- 1 \u2264 P \u2264 109\n- 0 \u2264 Ai \u2264 109 \n\nSubtask #1: (25 points)\n- 1 \u2264 N \u2264 100\n\nSubtask #2: (25 points)\n- 1 \u2264 N \u2264 1000\n\nSubtask #3: (50 points)\n- original constraints\n\n-----Example-----\nInput:\n4\n2 3\n1 2\n3 5\n2 4 3\n3 100\n1 3 5\n4 3\n1 2 3 4\n\nOutput:\n2 1\n4 2\n9 1\n2 2\n\n-----Explanation-----\nExample case 1. There are three segments - [1], [2] and [1, 2]. Sum of these segments are 1, 2 and 3 respectively. Sum of these segments modulo 3 will be 1, 2 and 0. Maximum score among these is 2. There is also only one segment with this score.\nExample case 2. There are six segments - [2], [4], [3], [2, 4], [4, 3] and [2, 4, 3]. Sum of these segments are 2, 4, 3, 6, 7, 9 respectively. Sum of these segments modulo 5 will be 2, 4, 3, 1, 2, 4. Maximum score among these is 4. And there are two segments with this score.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfor _ in range(int(input())):\n n,m=input().split()\n n,m=int(n),int(m)\n x=y=c=0\n l=list(map(int,input().split()))\n for i in range(n):\n for j in range(i,n):\n x=x+l[j]\n if (x%m)>y:\n y=x%m\n c=1\n elif y==(x%m):\n c+=1\n x = 0\n print(y,c)\n\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '4\\n2 3\\n1 2\\n3 5\\n2 4 3\\n3 100\\n1 3 5\\n4 3\\n1 2 3 4\\n', 'output': '2 1\\n4 2\\n9 1\\n2 2\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/BEARSEG'}","problem_id":"vfc_2166","program":"```python\nfor _ in range(int(input())):\n n,m=input().split()\n n,m=int(n),int(m)\n x=y=c=0\n l=list(map(int,input().split()))\n for i in range(n):\n for j in range(i,n):\n x=x+l[j]\n if (x%m)>y:\n y=x%m\n c=1\n elif y==(x%m):\n c+=1\n x = 0\n print(y,c)\n\n\n```","inputs":"4\n2 3\n1 2\n3 5\n2 4 3\n3 100\n1 3 5\n4 3\n1 2 3 4\n","output":"2 1\n4 2\n9 1\n2 2\n","actual_output":"2 1\n4 2\n9 1\n2 2\n","execution_success":true,"sample_index":436},{"source":"apps","task_type":"verifiable_code","in_source_id":"832","prompt":"Solve the following coding problem using the programming language python:\n\nChef has a sequence $A_1, A_2, \\ldots, A_N$. This sequence has exactly $2^N$ subsequences. Chef considers a subsequence of $A$ interesting if its size is exactly $K$ and the sum of all its elements is minimum possible, i.e. there is no subsequence with size $K$ which has a smaller sum.\nHelp Chef find the number of interesting subsequences of the sequence $A$.\n\n-----Input-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The first line of each test case contains two space-separated integers $N$ and $K$.\n- The second line contains $N$ space-separated integers $A_1, A_2, \\ldots, A_N$.\n\n-----Output-----\nFor each test case, print a single line containing one integer \u2015 the number of interesting subsequences.\n\n-----Constraints-----\n- $1 \\le T \\le 10$\n- $1 \\le K \\le N \\le 50$\n- $1 \\le A_i \\le 100$ for each valid $i$\n\n-----Subtasks-----\nSubtask #1 (30 points): $1 \\le N \\le 20$\nSubtask #2 (70 points): original constraints\n\n-----Example Input-----\n1\n4 2\n1 2 3 4\n\n-----Example Output-----\n1\n\n-----Explanation-----\nExample case 1: There are six subsequences with length $2$: $(1, 2)$, $(1, 3)$, $(1, 4)$, $(2, 3)$, $(2, 4)$ and $(3, 4)$. The minimum sum is $3$ and the only subsequence with this sum is $(1, 2)$.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\ndef fact(n):\n if n<2:\n return 1\n return n * fact(n-1)\n \ndef ncr(n, r):\n return fact(n)// (fact(r)*fact(n-r))\n \nt=int(input())\n\nfor _ in range(t):\n n, k = list(map(int, input().split()))\n a = list(map(int, input().split()))\n a.sort()\n count_z = a.count(a[k-1])\n count_z_seq = a[:k].count(a[k-1])\n \n print(ncr(count_z, count_z_seq))\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n4 2\\n1 2 3 4\\n', 'output': '1\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/CHEFINSQ'}","problem_id":"vfc_2170","program":"```python\ndef fact(n):\n if n<2:\n return 1\n return n * fact(n-1)\n \ndef ncr(n, r):\n return fact(n)// (fact(r)*fact(n-r))\n \nt=int(input())\n\nfor _ in range(t):\n n, k = list(map(int, input().split()))\n a = list(map(int, input().split()))\n a.sort()\n count_z = a.count(a[k-1])\n count_z_seq = a[:k].count(a[k-1])\n \n print(ncr(count_z, count_z_seq))\n\n```","inputs":"1\n4 2\n1 2 3 4\n","output":"1\n","actual_output":"1\n","execution_success":true,"sample_index":437},{"source":"apps","task_type":"verifiable_code","in_source_id":"833","prompt":"Solve the following coding problem using the programming language python:\n\nGalileo's latest project involves determining the density of stars in certain regions of the sky. For this purpose he started looking for datasets online, and discovered a dataset on Newton's blog. Newton had decomposed the night sky into a Voronoi tessellation with the generators arranged in a grid. He has stored the number of stars in a Voronoi cell at a position in a matrix that corresponds to the position of the generator in the grid.\nThis dataset does not directly help Galileo, because he needs to be able to query the number of stars in a rectangular portion of the sky. Galileo tried to write a program that does this on his own, but it turned out to be too slow. Can you help him?\n\n-----Input Format-----\nThe first line contains two integers n and m that denote the height and width of the matrix respectively. This is followed by n lines each containing m integers each.\nThe line following this would contain a single integer t, the number of queries to be run. Each query line consists of 4 integers px, py, qx, qy. The first two integers denote the row and column numbers of the upper left corner of the rectangular region, and the second pair of numbers correspond to the lower right corner.\n\n-----Output Format-----\nFor each query output a single line containing the number of stars in that rectangular region.\n\n-----Example-----\nInput:\n\n3 3\n10 10 10\n10 10 10\n10 10 10\n4\n1 1 1 1\n1 1 3 3\n2 1 3 3\n3 1 3 3\n\nOutput:\n\n10\n90\n60\n30\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nimport sys\n\ndef main():\n s=sys.stdin.readline\n n, m = list(map(int, s().split()))\n nums={}\n for i in range(1, n+1):\n nums[i]=list(map(int, s().split()))\n cases=int(s())\n for case in range(cases):\n px, py, qx, qy = list(map(int, s().split()))\n ans=[]\n for i in range(px, qx+1):\n for j in range(py-1, qy):\n ans.append(nums[i][j])\n print(sum(ans))\n\ndef __starting_point():\n main()\n__starting_point()\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3 3\\n10 10 10\\n10 10 10\\n10 10 10\\n4\\n1 1 1 1\\n1 1 3 3\\n2 1 3 3\\n3 1 3 3\\n', 'output': '10\\n90\\n60\\n30\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/DMNT2012/problems/COUNTSTR'}","problem_id":"vfc_2174","program":"```python\nimport sys\n\ndef main():\n s=sys.stdin.readline\n n, m = list(map(int, s().split()))\n nums={}\n for i in range(1, n+1):\n nums[i]=list(map(int, s().split()))\n cases=int(s())\n for case in range(cases):\n px, py, qx, qy = list(map(int, s().split()))\n ans=[]\n for i in range(px, qx+1):\n for j in range(py-1, qy):\n ans.append(nums[i][j])\n print(sum(ans))\n\ndef __starting_point():\n main()\n__starting_point()\n```","inputs":"3 3\n10 10 10\n10 10 10\n10 10 10\n4\n1 1 1 1\n1 1 3 3\n2 1 3 3\n3 1 3 3\n","output":"10\n90\n60\n30\n","actual_output":"10\n90\n60\n30\n","execution_success":true,"sample_index":438},{"source":"apps","task_type":"verifiable_code","in_source_id":"834","prompt":"Solve the following coding problem using the programming language python:\n\nStriver$Striver$ wants to strive hard in order to reach his goals, hence asks his mentor to give him a question for which he has to strive hard. \nThe mentor gives Striver$Striver$ a N$N$ X N$N$ matrix consisting of lowercase characters (\u2032a\u2032$'a'$ to \u2032z\u2032$'z'$) and Q$Q$ queries. Every query consists of X$X$ and Y$Y$. From any position in the matrix, one can either move towards the right or towards down. He asks striver to write down all the paths from (1,1)$(1, 1)$ to (X,Y)$(X, Y)$ and find out which string has the maximum number of character \u2032a\u2032$'a'$ in it and answer him the number of characters which are not 'a' in that string. \nStriver wants to strive hard but also wants to impress his mentor. He asks for your help to answer Q$Q$ queries given by his mentor as fast as he can so that he can impress his mentor also. Can you help him to answer the Q queries?\n\n-----Input:-----\n- First line will contain T$T$, number of test cases. Then the test cases follow. \n- First line of every test case contains a number N$N$ and Q$Q$ which denotes the dimensions of the matrix and number of queries respectively. \n- N lines follow, which contains N numbers each denoting the elements of the matrix. \n- Q line follow, every line contains X and Y. \n\n-----Output:-----\nFor every test case, print a single integer which prints the answer to mentor's every query. \n\n-----Constraints-----\n- 1\u2264T\u226410$1 \\leq T \\leq 10$\n- 1\u2264N\u2264103$1 \\leq N \\leq 10^3$\n- 1\u2264Q\u2264105$1 \\leq Q \\leq 10^5$\n- 1\u2264X,Y\u2264N$1 \\leq X, Y \\leq N$\n\n-----Sample Input:-----\n1\n3 2 \na b a \na c d \nb a b\n1 3\n3 3 \n\n-----Sample Output:-----\n1 \n2\n\n-----EXPLANATION:-----\nQuery-1: There is only one path from (1,1) to (1,3) i.e.,\"aba\" and the number of characters which are not 'a' is 1. \nQuery-2: The path which has the maximum number of 'a' in it is \"aabab\", hence non 'a' characters are 2.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\na=int(input())\r\nfor _ in range(a):\r\n c,d=list(map(int,input().split()))\r\n crr=[[[0,0] for i in range(c+1)] for j in range(c+1)]\r\n trr=[]\r\n for i in range(c):\r\n kk=list(input().split())\r\n trr.append(kk)\r\n for i in range(1,c+1):\r\n for j in range(1,c+1):\r\n if(trr[i-1][j-1]=='a'):\r\n crr[i][j][0]=max(crr[i-1][j][0],crr[i][j-1][0])+1\r\n if(j==1):\r\n crr[i][j][1]=crr[i-1][j][1]+1\r\n elif(i==1):\r\n crr[i][j][1]=crr[i][j-1][1]+1\r\n elif(crr[i-1][j][0]>crr[i][j-1][0]):\r\n crr[i][j][1]=crr[i-1][j][1]+1\r\n else:\r\n crr[i][j][1]=crr[i][j-1][1]+1\r\n else:\r\n crr[i][j][0]=max(crr[i-1][j][0],crr[i][j-1][0])\r\n if(j==1):\r\n crr[i][j][1]=crr[i-1][j][1]+1\r\n elif(i==1):\r\n crr[i][j][1]=crr[i][j-1][1]+1\r\n elif(crr[i-1][j][0]>crr[i][j-1][0]):\r\n crr[i][j][1]=crr[i-1][j][1]+1\r\n else:\r\n crr[i][j][1]=crr[i][j-1][1]+1\r\n \r\n for i in range(d):\r\n m,n=list(map(int,input().split()))\r\n print(crr[m][n][1]-crr[m][n][0])\r\n \r\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n3 2\\na b a\\na c d\\nb a b\\n1 3\\n3 3\\n', 'output': '1\\n2\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/AARA2018/problems/ARMBH5'}","problem_id":"vfc_2178","program":"```python\na=int(input())\r\nfor _ in range(a):\r\n c,d=list(map(int,input().split()))\r\n crr=[[[0,0] for i in range(c+1)] for j in range(c+1)]\r\n trr=[]\r\n for i in range(c):\r\n kk=list(input().split())\r\n trr.append(kk)\r\n for i in range(1,c+1):\r\n for j in range(1,c+1):\r\n if(trr[i-1][j-1]=='a'):\r\n crr[i][j][0]=max(crr[i-1][j][0],crr[i][j-1][0])+1\r\n if(j==1):\r\n crr[i][j][1]=crr[i-1][j][1]+1\r\n elif(i==1):\r\n crr[i][j][1]=crr[i][j-1][1]+1\r\n elif(crr[i-1][j][0]>crr[i][j-1][0]):\r\n crr[i][j][1]=crr[i-1][j][1]+1\r\n else:\r\n crr[i][j][1]=crr[i][j-1][1]+1\r\n else:\r\n crr[i][j][0]=max(crr[i-1][j][0],crr[i][j-1][0])\r\n if(j==1):\r\n crr[i][j][1]=crr[i-1][j][1]+1\r\n elif(i==1):\r\n crr[i][j][1]=crr[i][j-1][1]+1\r\n elif(crr[i-1][j][0]>crr[i][j-1][0]):\r\n crr[i][j][1]=crr[i-1][j][1]+1\r\n else:\r\n crr[i][j][1]=crr[i][j-1][1]+1\r\n \r\n for i in range(d):\r\n m,n=list(map(int,input().split()))\r\n print(crr[m][n][1]-crr[m][n][0])\r\n \r\n\n```","inputs":"1\n3 2\na b a\na c d\nb a b\n1 3\n3 3\n","output":"1\n2\n","actual_output":"1\n2\n","execution_success":true,"sample_index":439},{"source":"apps","task_type":"verifiable_code","in_source_id":"835","prompt":"Solve the following coding problem using the programming language python:\n\nChef is stuck in a two dimensional maze having N rows and M columns. He needs to get out of the maze as soon as possible and arrive at the kitchen in order to serve his hungry customers. But, he can get out of the maze only if he is able to successfully find any magical path in the given maze.\n\nA path is defined as magical if it starts from any of the cell (a,b) of the maze and ends at the cell (c,d) such that the following conditions are satisfied :-\n- |a - c| + |b - d| = 1\n- All the cells in the maze are traversed exactly once.\n- It is allowed to move only in the four directions - up, down, left and right from the current cell.\n\n-----Input-----\n- First line of the input contains an integer T denoting the number of different types of scenarios.\n- Each of the next T lines will contain two integers N, M denoting the dimensions of the maze.\n\n-----Output-----\nFor each of the T scenarios, output a single line containing \"Yes\" or \"No\" (without quotes) denoting whether the Chef can get out of the maze or not.\n\n-----Constraints-----\n- 1 \u2264 T \u2264 105\n- 1 \u2264 N, M \u2264 1018\n\n-----Subtasks-----\nSubtask #1 : (30 points)\n- 1 \u2264 T \u2264 100\n- 1 \u2264 N, M \u2264 10\n\nSubtask #2 : (70 points) \n\nOriginal Constraints\n\n-----Example-----\nInput:\n1\n2 2\n\nOutput:\nYes\n\n-----Explanation-----\nExample case 1.\n\nChef can start from (1,1), move down to (2,1), then move right to (2,2) and finally move upwards to reach (1,2). As, he is able to visit all the cells exactly once and sum of absolute differences of corresponding x and y dimension is 1, we can call this path a magical path.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nt = eval(input())\nfor _ in range(t):\n n, m = list(map(int, input().split()))\n if n*m == 2:\n print('Yes')\n elif (n*m)%2 == 0 and m != 1 and n != 1:\n print('Yes')\n else:\n print('No')\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n2 2\\n', 'output': 'Yes\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/APRIL16/problems/CHEFPATH'}","problem_id":"vfc_2182","program":"```python\nt = eval(input())\nfor _ in range(t):\n n, m = list(map(int, input().split()))\n if n*m == 2:\n print('Yes')\n elif (n*m)%2 == 0 and m != 1 and n != 1:\n print('Yes')\n else:\n print('No')\n```","inputs":"1\n2 2\n","output":"Yes\n","actual_output":"Yes\n","execution_success":true,"sample_index":440},{"source":"apps","task_type":"verifiable_code","in_source_id":"836","prompt":"Solve the following coding problem using the programming language python:\n\nLittle Egor is a huge movie fan. He likes watching different kinds of movies: from drama movies to comedy movies, from teen movies to horror movies. He is planning to visit cinema this weekend, but he's not sure which movie he should watch.\nThere are n movies to watch during this weekend. Each movie can be characterized by two integers Li and Ri, denoting the length and the rating of the corresponding movie. Egor wants to watch exactly one movie with the maximal value of Li \u00d7 Ri. If there are several such movies, he would pick a one with the maximal Ri among them. If there is still a tie, he would pick the one with the minimal index among them.\nYour task is to help Egor to pick a movie to watch during this weekend.\n\n-----Input-----\nThe first line of the input contains an integer T denoting the number of test cases.\nThe first line of the test case description contains an integer n.\nThe second line of the test case description contains n integers L1, L2, ...,Ln. The following line contains n integers R1, R2, ..., Rn.\n\n-----Output-----\nFor each test case, output a single integer i denoting the index of the movie that Egor should watch during this weekend. Note that we follow 1-based indexing.\n\n-----Constraints-----\n- 1 \u2264 T \u2264 5\n- 1 \u2264 n \u2264 100\n- 1 \u2264 Li, Ri \u2264 100\n\n-----Example-----\nInput:\n2\n2\n1 2\n2 1\n4\n2 1 4 1\n2 4 1 4\n\nOutput:\n1\n2\n\n-----Explanation-----\nIn the first example case, both films have the same value of L \u00d7 R, but the first film has a better rating.\nIn the second example case, the second and the fourth movies are equally good, but the second movie has a smaller index.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\ndef bestMovie():\n tests=int(input())\n for t in range(tests):\n n = int(input())\n L = list(map(int, input().split()))\n R = list(map(int, input().split()))\n maxIndex = -1\n maxValue = 0\n for i in range(n):\n prod = L[i]*R[i]\n if maxValue < prod:\n maxValue = prod\n maxIndex = i\n elif maxValue == prod:\n if R[maxIndex] < R[i]:\n maxIndex = i\n print(maxIndex+1)\n\nbestMovie()\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n2\\n1 2\\n2 1\\n4\\n2 1 4 1\\n2 4 1 4\\n', 'output': '1\\n2\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/COOK69/problems/MOVIEWKN'}","problem_id":"vfc_2186","program":"```python\ndef bestMovie():\n tests=int(input())\n for t in range(tests):\n n = int(input())\n L = list(map(int, input().split()))\n R = list(map(int, input().split()))\n maxIndex = -1\n maxValue = 0\n for i in range(n):\n prod = L[i]*R[i]\n if maxValue < prod:\n maxValue = prod\n maxIndex = i\n elif maxValue == prod:\n if R[maxIndex] < R[i]:\n maxIndex = i\n print(maxIndex+1)\n\nbestMovie()\n```","inputs":"2\n2\n1 2\n2 1\n4\n2 1 4 1\n2 4 1 4\n","output":"1\n2\n","actual_output":"1\n2\n","execution_success":true,"sample_index":441},{"source":"apps","task_type":"verifiable_code","in_source_id":"838","prompt":"Solve the following coding problem using the programming language python:\n\nChef and his girlfriend are going to have a promenade. They are walking along the straight road which consists of segments placed one by one. Before walking Chef and his girlfriend stay at the beginning of the first segment, they want to achieve the end of the last segment. \nThere are few problems: \n\n- At the beginning Chef should choose constant integer - the velocity of mooving. It can't be changed inside one segment. \n- The velocity should be decreased by at least 1 after achieving the end of some segment. \n- There is exactly one shop on each segment. Each shop has an attractiveness. If it's attractiveness is W and Chef and his girlfriend move with velocity V then if V < W girlfriend will run away into the shop and the promenade will become ruined. \n\nChef doesn't want to lose her girl in such a way, but he is an old one, so you should find the minimal possible velocity at the first segment to satisfy all conditions.\n\n\n-----Input-----\n- The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.\n- The first line of each test case contains a single integer N denoting the number of segments. The second line contains N space-separated integers W1, W2, ..., WN denoting the attractiveness of shops. \n\n-----Output-----\n- For each test case, output a single line containing the minimal possible velocity at the beginning.\n\n-----Constraints-----\n- 1 \u2264 T \u2264 10\n- 1 \u2264 N \u2264 10^5\n- 1 \u2264 Wi \u2264 10^6\n\n-----Example-----\nInput:\n\n2\n5\n6 5 4 3 2\n5\n3 4 3 1 1\n\nOutput:\n\n6\n5\n\n-----Explanation-----\nExample case 1. \nIf we choose velocity 6, on the first step we have 6 >= 6 everything is OK, then we should decrease the velocity to 5 and on the 2nd segment we'll receive 5 >= 5, again OK, and so on. \nExample case 2. \nIf we choose velocity 4, the promanade will be ruined on the 2nd step (we sould decrease our velocity, so the maximal possible will be 3 which is less than 4).\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nT = int(input())\nfor i in range(T):\n x = int(input())\n l= [int(x) for x in input().split()]\n t=[]\n for i in range(len(l)):\n t.append(l[i]+i) \n print(max(t))\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n5\\n6 5 4 3 2\\n5\\n3 4 3 1 1\\n', 'output': '6\\n5\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/WALK'}","problem_id":"vfc_2194","program":"```python\nT = int(input())\nfor i in range(T):\n x = int(input())\n l= [int(x) for x in input().split()]\n t=[]\n for i in range(len(l)):\n t.append(l[i]+i) \n print(max(t))\n```","inputs":"2\n5\n6 5 4 3 2\n5\n3 4 3 1 1\n","output":"6\n5\n","actual_output":"6\n5\n","execution_success":true,"sample_index":443},{"source":"apps","task_type":"verifiable_code","in_source_id":"839","prompt":"Solve the following coding problem using the programming language python:\n\nDhiraj loves Chocolates.He loves chocolates so much that he can eat up to $1000$ chocolates a day. But his mom is fed up by this habit of him and decides to take things in her hand.\nIts diwali Season and Dhiraj has got a lot of boxes of chocolates and Dhiraj's mom is afraid that dhiraj might eat all boxes of chocolates.\nSo she told Dhiraj that he can eat only exactly $k$ number of chocolates and dhiraj has to finish all the chocolates in box selected by him and then move on to next box of chocolate.Now Dhiraj is confused that whether he will be able to eat $k$ number of chocolates or not. Since dhiraj is weak at maths,he asks for your help to tell him whether he can eat $k$ number of chocolates or not. \nSo given number of chocolates are $k$ which dhiraj has to eat and the boxes of chocolates each containing some number of chocolates, tell whether dhiraj will be able to eat $k$ number of chocolates or not.\n\n-----Input:-----\n- First line will contain $T$, number of testcases. Then the testcases follow. \n- $k$, representing the number of chocolates dhiraj has to eat.\n- the third line contains $N$ representing the no. of boxes of chocolates.\n- fourth line contains list of $a[]$ size $N$ specifying the number of chocolates in each Box.\n\n-----Output:-----\n- For each testcase, output in a single line answer $0$ or $1$.\n- $0$ if dhiraj cant eat $k$ chocolates from given combination and $1$ if he can eat $k$ chocolates from given combination.\n\n-----Constraints-----\n- $1 \\leq T \\leq 100$\n- $1 \\leq K \\leq 10^7$\n- $1 \\leq N \\leq 800$\n- $1 \\leq a[i] \\leq 10^3$\n\n-----Sample Input:-----\n2\n20\n5\n8 7 2 10 5\n11\n4\n6 8 2 10\n\n-----Sample Output:-----\n1\n0\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\ndef isSubsetSum(arr, n, sum): \n subset = [ [False for j in range(sum + 1)] for i in range(3) ] \n for i in range(n + 1): \n for j in range(sum + 1): \n if (j == 0):subset[i % 2][j] = True\n elif (i == 0):subset[i % 2][j] = False\n elif (arr[i - 1] <= j):subset[i % 2][j] = subset[(i + 1) % 2][j - arr[i - 1]] or subset[(i + 1)% 2][j] \n else:subset[i % 2][j] = subset[(i + 1) % 2][j] \n return subset[n % 2][sum] \nfor _ in range(int(input())):\n k,n,a = int(input()),int(input()),list(map(int,input().split()))\n if sum(a) < k or k < min(a):print(0);continue\n print(1) if isSubsetSum(a, n, k) else print(0)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n20\\n5\\n8 7 2 10 5\\n11\\n4\\n6 8 2 10\\n', 'output': '1\\n0\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/COFY2020/problems/GKSMNLC'}","problem_id":"vfc_2198","program":"```python\ndef isSubsetSum(arr, n, sum): \n subset = [ [False for j in range(sum + 1)] for i in range(3) ] \n for i in range(n + 1): \n for j in range(sum + 1): \n if (j == 0):subset[i % 2][j] = True\n elif (i == 0):subset[i % 2][j] = False\n elif (arr[i - 1] <= j):subset[i % 2][j] = subset[(i + 1) % 2][j - arr[i - 1]] or subset[(i + 1)% 2][j] \n else:subset[i % 2][j] = subset[(i + 1) % 2][j] \n return subset[n % 2][sum] \nfor _ in range(int(input())):\n k,n,a = int(input()),int(input()),list(map(int,input().split()))\n if sum(a) < k or k < min(a):print(0);continue\n print(1) if isSubsetSum(a, n, k) else print(0)\n```","inputs":"2\n20\n5\n8 7 2 10 5\n11\n4\n6 8 2 10\n","output":"1\n0\n","actual_output":"1\n0\n","execution_success":true,"sample_index":444},{"source":"apps","task_type":"verifiable_code","in_source_id":"841","prompt":"Solve the following coding problem using the programming language python:\n\nThe Petrozavodsk camp takes place in about one month. Jafar wants to participate in the camp, but guess what? His coach is Yalalovichik.\nYalalovichik is a legendary coach, famous in the history of competitive programming. However, he is only willing to send to the camp students who solve really hard problems on Timus. The deadline that Yalalovichik set before has passed and he refuses to send Jafar to the camp.\nJafar decided to make Yalalovichik happy in hopes of changing his decision, so he invented a new sequence of numbers and named them Yalalovichik numbers. Jafar is writing a research paper about their properties and wants to publish it in the Science Eagle yearly journal.\nA Yalalovichik number is created in the following way:\n- Consider an integer $N$ in decimal notation; let's call it the base of the Yalalovichik number $Y_N$. $N$ may not contain the digit $0$.\n- Treat $N$ as a decimal string. Compute all left shifts of this string $N_0, N_1, \\ldots, N_{|N|-1}$ ($|N|$ denotes the number of digits of $N$); specifically, $N_k$ denotes the string formed by moving the first $k$ digits of $N$ to the end in the same order.\n- Concatenate the strings $N_0, N_1, \\ldots, N_{|N|-1}$. The resulting string is the decimal notation of $Y_N$.\nFor example, if $N = 123$, the left shifts are $123, 231, 312$ and thus $Y_N = 123231312$.\nYou are given the base $N$. Calculate the value of $Y_N$ modulo $10^9+7$.\n\n-----Input-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The first and only line of each test case contains a single decimal integer $N$.\n\n-----Output-----\nFor each test case, print a single line containing one integer \u2014 the value of the Yalalovichik number $Y_N$ modulo $10^9+7$.\n\n-----Constraints-----\n- $1 \\le T \\le 200$\n- $|N| \\le 10^5$\n- $N$ does not contain the digit $0$\n- the sum of $|N|$ over all test cases does not exceed $10^6$\n\n-----Example Input-----\n1\n123\n\n-----Example Output-----\n123231312\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nM = 10 ** 9 + 7\nfor _ in range(int(input())):\n s,p,m,r = list(map(int, input())),0,1,0\n for d in reversed(s):\n p += d * m\n m = m * 10 % M\n for d in s:\n r = (r * m + p) % M\n p = (p * 10 - (m - 1) * d) % M\n print(r)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n123\\n\\n', 'output': '123231312\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/YVNUM'}","problem_id":"vfc_2206","program":"```python\nM = 10 ** 9 + 7\nfor _ in range(int(input())):\n s,p,m,r = list(map(int, input())),0,1,0\n for d in reversed(s):\n p += d * m\n m = m * 10 % M\n for d in s:\n r = (r * m + p) % M\n p = (p * 10 - (m - 1) * d) % M\n print(r)\n```","inputs":"1\n123\n\n","output":"123231312\n","actual_output":"123231312\n","execution_success":true,"sample_index":446},{"source":"apps","task_type":"verifiable_code","in_source_id":"843","prompt":"Solve the following coding problem using the programming language python:\n\nYou are given N integer sequences A1, A2, ..., AN. Each of these sequences contains N elements. You should pick N elements, one from each sequence; let's denote the element picked from sequence Ai by Ei. For each i (2 \u2264 i \u2264 N), Ei should be strictly greater than Ei-1.\nCompute the maximum possible value of E1 + E2 + ... + EN. If it's impossible to pick the elements E1, E2, ..., EN, print -1 instead.\n\n-----Input-----\n\n- The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows.\n- The first line of each test case contains a single integer N.\n- N lines follow. For each valid i, the i-th of these lines contains N space-separated integers Ai1, Ai2, ..., AiN denoting the elements of the sequence Ai.\n\n-----Output-----\nFor each test case, print a single line containing one integer \u2014 the maximum sum of picked elements.\n\n-----Constraints-----\n- 1 \u2264 T \u2264 10\n- 1 \u2264 N \u2264 700\n- 1 \u2264 sum of N in all test-cases \u2264 3700\n- 1 \u2264 Aij \u2264 109 for each valid i, j\n\n-----Subtasks-----\nSubtask #1 (18 points): 1 \u2264 Aij \u2264 N for each valid i, j\nSubtask #2 (82 points): original constraints\n\n-----Example-----\nInput:\n\n1\n3\n1 2 3\n4 5 6\n7 8 9\n\nOutput:\n\n18\n\n-----Explanation-----\nExample case 1: To maximise the score, pick 3 from the first row, 6 from the second row and 9 from the third row. The resulting sum is E1+E2+E3 = 3+6+9 = 18.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nt=int(input())\nfor _ in range(t):\n n=int(input())\n \n grid=[]\n for _ in range(n):\n temp=[]\n temp=list(map(int,input().strip().split()))\n temp.sort()\n grid.append(temp)\n \n \n curr=max(grid[n-1])\n total=curr\n for i in range(n-2,0-1,-1):\n flag=0\n for j in range(n-1,0-1,-1):\n if grid[i][j] 0: \n list.pop()\n output.append(count)\n for each in output:\n print(each)\ngetInput()\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3 6\\nCLICK 1\\nCLICK 2\\nCLICK 3\\nCLICK 2\\nCLOSEALL\\nCLICK 1\\n', 'output': '1\\n2\\n3\\n2\\n0\\n1\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/COOK23/problems/TWTCLOSE'}","problem_id":"vfc_2218","program":"```python\ndef getInput():\n N_k = input().split()\n N =int(N_k[0])\n k =int(N_k[1])\n list = []\n output = []\n count = 0\n for i in range(0,k):\n val = input()\n if(val!=\"CLOSEALL\"):\n val=val.split()\n val = int (val[1])\n if val not in list:\n count= count +1\n list.append(val)\n else:\n list.remove(val)\n count= count -1\n else:\n count =0\n while len(list) > 0: \n list.pop()\n output.append(count)\n for each in output:\n print(each)\ngetInput()\n```","inputs":"3 6\nCLICK 1\nCLICK 2\nCLICK 3\nCLICK 2\nCLOSEALL\nCLICK 1\n","output":"1\n2\n3\n2\n0\n1\n","actual_output":"1\n2\n3\n2\n0\n1\n","execution_success":true,"sample_index":449},{"source":"apps","task_type":"verifiable_code","in_source_id":"845","prompt":"Solve the following coding problem using the programming language python:\n\nGive me Biscuit\n\nSunny wants to make slices of biscuit of size c * d into identical pieces.\n\nbut each piece is a square having maximum possible side length with no left over piece of biscuit.\n\nInput Format\n\nThe first line contains an integer N.\n\nN lines follow. Each line contains two space separated integers c and d.\n\nwhich denote length and breadth of the biscuit.\n\nConstraints\n\n1 <= N <= 1000\n\n1 <= c,d <= 1000\nOutput Format\n\nN lines, each containing an integer that denotes the number of squares of maximum size, when the biscuit is cut as per the given condition.\n\nSample Input \n\n2\n\n2 2\n\n6 9\n\nSample Output \n\n1\n\n6\n\nExplanation \n\t\n\nThe 1st testcase has a biscuit whose original dimensions are 2 X 2, the biscuit is uncut and is a square.\n\nHence the answer is 1.\n\nThe 2nd testcase has a biscuit of size 6 X 9 . We can cut it into 54 squares of size 1 X 1 , 6 of size 3 X 3 . For other sizes we will have leftovers.\n\nHence, the number of squares of maximum size that can be cut is 6.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\ndef __gcd(a, b): \n \n # Everything divides 0 \n if (a == 0 or b == 0): \n return 0; \n \n # base case \n if (a == b): \n return a; \n \n # a is greater \n if (a > b): \n return __gcd(a - b, b); \n return __gcd(a, b - a); \n \n# Function to find \n# number of squares \ndef NumberOfSquares(x, y): \n \n # Here in built PHP \n # gcd function is used \n s = __gcd(x, y); \n \n ans = (x * y) / (s * s); \n \n return int(ans);\n \nn=int(input())\nwhile n:\n n=n-1\n c,d=map(int,input().split())\n print(NumberOfSquares(c, d))\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n2 2\\n6 9\\n', 'output': '1\\n6\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/COM12020/problems/CODE_00'}","problem_id":"vfc_2222","program":"```python\ndef __gcd(a, b): \n \n # Everything divides 0 \n if (a == 0 or b == 0): \n return 0; \n \n # base case \n if (a == b): \n return a; \n \n # a is greater \n if (a > b): \n return __gcd(a - b, b); \n return __gcd(a, b - a); \n \n# Function to find \n# number of squares \ndef NumberOfSquares(x, y): \n \n # Here in built PHP \n # gcd function is used \n s = __gcd(x, y); \n \n ans = (x * y) / (s * s); \n \n return int(ans);\n \nn=int(input())\nwhile n:\n n=n-1\n c,d=map(int,input().split())\n print(NumberOfSquares(c, d))\n```","inputs":"2\n2 2\n6 9\n","output":"1\n6\n","actual_output":"1\n6\n","execution_success":true,"sample_index":450},{"source":"apps","task_type":"verifiable_code","in_source_id":"847","prompt":"Solve the following coding problem using the programming language python:\n\nDid you know that the people of America eat around 100 acres of pizza per day ? Having read this fact on internet, two chefs from the Elephant city, Arjuna and Bhima are set to make pizza popular in India. They organized a social awareness camp, where N people ( other than these two ) sit around a large pizza. To make it more interesting, they make some pairs among these N people and the two persons in a pair, feed each other.\n\nEach person should be a part of at most one pair and most importantly, to make feeding easy, any two pairs should not cross each other ( see figure for more clarity ). Arjuna and Bhima decided to play a game on making the pairs. In his turn, a player makes a pair ( selects two persons, as long as its valid ) and this pair start feeding each other. Arjuna and Bhima take turns alternately, by making a pair in each turn, and they play optimally ( see Notes for more clarity ). The one who can not make a pair in his turn, loses. Given N, find who wins the game, if Arjuna starts first. \n\n-----Notes-----\n- 'Optimally' means, if there is a possible move a person can take in his turn that can make him win finally, he will always take that. You can assume both are very intelligent. \n\n-----Input-----\nFirst line contains an integer T ( number of test cases, around 1000 ). Each of the next T lines contains an integer N ( 2 <= N <= 10000 )\n\n-----Output-----\nFor each test case, output the name of the winner ( either \"Arjuna\" or \"Bhima\" ( without quotes ) ) in a new line.\n\n-----Example-----\nInput:\n4\n2\n4\n5\n6\n\nOutput:\nArjuna\nArjuna\nBhima\nArjuna\n\nExplanation:\n\nLet the people around the table are numbered 1, 2, ... , N in clock-wise order as shown in the image \n\nCase 1 : N = 2. Only two persons and Arjuna makes the only possible pair (1,2)\n\nCase 2 : N = 4. Arjuna can make the pair (1,3). Bhima can not make any more pairs ( without crossing the pair (1,3) )\n\nCase 3 : N = 5. No matter which pair Arjuna makes first, Bhima can always make one more pair, and Arjuna can not make any further\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\na= [0, 0, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 0, 5, 2, 2, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 2, 7, 4, 0, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 2, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2]\n \nt = int(input())\n \nfor i in range(t):\n\tn = int(input())\n\tif a[n]>0:\n\t\tprint(\"Arjuna\")\n\telse:\n\t\tprint(\"Bhima\") \n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '4\\n2\\n4\\n5\\n6\\n', 'output': 'Arjuna\\nArjuna\\nBhima\\nArjuna\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/BIGPIZA'}","problem_id":"vfc_2230","program":"```python\na= [0, 0, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 0, 5, 2, 2, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 2, 7, 4, 0, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 2, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2]\n \nt = int(input())\n \nfor i in range(t):\n\tn = int(input())\n\tif a[n]>0:\n\t\tprint(\"Arjuna\")\n\telse:\n\t\tprint(\"Bhima\") \n```","inputs":"4\n2\n4\n5\n6\n","output":"Arjuna\nArjuna\nBhima\nArjuna\n","actual_output":"Arjuna\nArjuna\nBhima\nArjuna\n","execution_success":true,"sample_index":451},{"source":"apps","task_type":"verifiable_code","in_source_id":"848","prompt":"Solve the following coding problem using the programming language python:\n\nCoach Moony wants the best team to represent their college in ICPC. He has $N$ students standing in a circle with certain rating $X_i$ on a competitive coding platform. It is an established fact that any coder with more rating on the platform is a better coder. \nMoony wants to send his best $3$ coders based upon their rating. But all coders only want to have their friends in their team and every coder is friends with four other coders, adjacent two on left side in the circle, and adjacent two on right. So Moony comes up with a solution that team with maximum cumulative rating of all three members in a team shall be representing their college.\nYou need to give the cumulative score of the team that will be representing the college.\n\n-----Input:-----\n- First line will contain $T$, number of testcases. \n- First line of each test case contains a single integer $N$.\n- Second line of each test case takes $N$ integers, denoting rating of $ith$ coder.\n\n-----Output:-----\nFor each testcase, output a single integer denoting cumulative rating of the team.\n\n-----Constraints-----\n- $1 \\leq T \\leq 10$\n- $7 \\leq N \\leq 10^5$ \n- $0 \\leq X_i \\leq 10^9$\n\n-----Sample Input:-----\n1\n\n7\n\n10 40 30 30 20 0 0 \n\n-----Sample Output:-----\n100\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\r\n#Moony and ICPC team\r\nT = int(input())\r\n\r\nfor i in range(T):\r\n N,data = int(input()),list(map(int,input().split()))\r\n if(N==3):\r\n print(sum(data))\r\n else:\r\n best = data[0]+data[1]+data[2]\r\n overall = best\r\n k=len(data)\r\n for i in range(1,k-2):\r\n overall=overall - data[i-1] + data[i+2]\r\n if(overall>best):\r\n best = overall\r\n j=max(data[1],data[-2])\r\n l= data[-1]+data[0]+j\r\n if(best < l):\r\n best = l\r\n print(best)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n7\\n10 40 30 30 20 0 0\\n', 'output': '100\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/COG2020/problems/COG2002'}","problem_id":"vfc_2234","program":"```python\n# cook your dish here\r\n#Moony and ICPC team\r\nT = int(input())\r\n\r\nfor i in range(T):\r\n N,data = int(input()),list(map(int,input().split()))\r\n if(N==3):\r\n print(sum(data))\r\n else:\r\n best = data[0]+data[1]+data[2]\r\n overall = best\r\n k=len(data)\r\n for i in range(1,k-2):\r\n overall=overall - data[i-1] + data[i+2]\r\n if(overall>best):\r\n best = overall\r\n j=max(data[1],data[-2])\r\n l= data[-1]+data[0]+j\r\n if(best < l):\r\n best = l\r\n print(best)\n```","inputs":"1\n7\n10 40 30 30 20 0 0\n","output":"100\n","actual_output":"100\n","execution_success":true,"sample_index":452},{"source":"apps","task_type":"verifiable_code","in_source_id":"849","prompt":"Solve the following coding problem using the programming language python:\n\nWe all know how great ABD aka AB-DE-VILLIERS is. However his team mates were jealous of him and posed a problem for him to solve.The problem description is as follows :\n\nGiven an array of integers,find the length of the largest subarray(contiguous) of the given array with the maximum possible GCD (Greatest Common Divisor).\n\nFor info on GCD ,see this link: https://en.wikipedia.org/wiki/Greatest_common_divisor\n\nGCD of the subarray is defined as the GCD of all the elements of the subarray.\nAs ABD is not aware of competitive programming he asks your help. Help him!\n\n-----Input-----\nFirst line will contain integer N denoting the size of array.\n\nSecond line will contain N integers denoting array elements.\n\n-----Output-----\nThe answer as specified in the problem statement .\n\n-----Constraints-----\n1 <= N <= 1000000\n\n1 <= array[i] <=100000000000\n\n-----Example-----\nInput:\n4\n2 4 8 3\n\nOutput:\n1\n\nExplanation\nGCD of all possible subarrays of the given array are : 2 , 2 , 2 , 1 , 4 , 4, 1 , 8 , 1 , 3\n\nLargest GCD possible : 8\n\nLength of the largest subarray with GCD as 8 is 1\n\nHence answer is 1 .\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nn=eval(input())\na=list(map(int,input().split()))\nc=m=0\nmaxi=max(a)\nfor i in range(n):\n if a[i]==maxi:\n c+=1\n m=max(c,m)\n else:\n c=0\nprint(m) \n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '4\\n2 4 8 3\\n', 'output': '1\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/BYTE2016/problems/BYTES11'}","problem_id":"vfc_2238","program":"```python\nn=eval(input())\na=list(map(int,input().split()))\nc=m=0\nmaxi=max(a)\nfor i in range(n):\n if a[i]==maxi:\n c+=1\n m=max(c,m)\n else:\n c=0\nprint(m) \n```","inputs":"4\n2 4 8 3\n","output":"1\n","actual_output":"1\n","execution_success":true,"sample_index":453},{"source":"apps","task_type":"verifiable_code","in_source_id":"850","prompt":"Solve the following coding problem using the programming language python:\n\nChef has a sequence of positive integers $A_1, A_2, \\ldots, A_N$. He wants to split this sequence into two non-empty (not necessarily contiguous) subsequences $B$ and $C$ such that $\\mathrm{GCD}\\,(B) + \\mathrm{GCD}\\,(C)$ is maximum possible. Help him find this maximum value.\nNote: The greatest common divisor (GCD) of a sequence of positive integers is the largest positive integer that divides each element of this sequence. For example, the GCD of the sequence $(8, 12)$ is $4$.\n\n-----Input-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The first line of each test case contains a single integer $N$.\n- The second line contains $N$ space-separated integers $A_1, A_2, \\ldots, A_N$.\n\n-----Output-----\nFor each test case, print a single line containing one integer \u2014 the maximum value of $\\mathrm{GCD}\\,(B) + \\mathrm{GCD}\\,(C)$.\n\n-----Constraints-----\n- $1 \\le T \\le 10$\n- $2 \\le N \\le 10^5$\n- $1 \\le A_i \\le 10^9$ for each valid $i$\n\n-----Subtasks-----\nSubtask #1 (20 points): $2 \\le N \\le 20$\nSubtask #2 (80 points): original constraints\n\n-----Example Input-----\n1 \n4 \n4 4 7 6 \n\n-----Example Output-----\n9\n\n-----Explanation-----\nExample case 1: For example, the sequence $A$ can be divided into subsequences $B = (4, 4, 6)$ and $C = (7)$.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfrom math import gcd\r\n\r\n__author__ = 'Prateek'\r\n\r\n\r\ndef test():\r\n n = int(input())\r\n a = list(map(int, input().split()))\r\n a = list(set(a))\r\n n = len(a)\r\n if len(a) == 1:\r\n print(2 * a[0])\r\n return\r\n g1 = [0 for i in range(n)]\r\n g2 = [0 for i in range(n)]\r\n g1[0] = a[0]\r\n g2[n - 1] = a[n - 1]\r\n for i in range(1, n):\r\n g1[i] = gcd(g1[i - 1], a[i])\r\n for i in range(n - 2, -1, -1):\r\n g2[i] = gcd(g2[i + 1], a[i])\r\n ans = 0\r\n for i in range(n):\r\n if i == 0:\r\n ans = max(ans, g2[i + 1] + a[i])\r\n elif i == n - 1:\r\n ans = max(ans, g1[i - 1] + a[i])\r\n else:\r\n ans = max(ans, gcd(g1[i - 1], g2[i + 1]) + a[i])\r\n print(ans)\r\n\r\n\r\nif __author__ == 'Prateek':\r\n t = int(input())\r\n for _ in range(t):\r\n test()\r\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1 \\n4 \\n4 4 7 6 \\n\\n', 'output': '9\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/SUMAGCD'}","problem_id":"vfc_2242","program":"```python\nfrom math import gcd\r\n\r\n__author__ = 'Prateek'\r\n\r\n\r\ndef test():\r\n n = int(input())\r\n a = list(map(int, input().split()))\r\n a = list(set(a))\r\n n = len(a)\r\n if len(a) == 1:\r\n print(2 * a[0])\r\n return\r\n g1 = [0 for i in range(n)]\r\n g2 = [0 for i in range(n)]\r\n g1[0] = a[0]\r\n g2[n - 1] = a[n - 1]\r\n for i in range(1, n):\r\n g1[i] = gcd(g1[i - 1], a[i])\r\n for i in range(n - 2, -1, -1):\r\n g2[i] = gcd(g2[i + 1], a[i])\r\n ans = 0\r\n for i in range(n):\r\n if i == 0:\r\n ans = max(ans, g2[i + 1] + a[i])\r\n elif i == n - 1:\r\n ans = max(ans, g1[i - 1] + a[i])\r\n else:\r\n ans = max(ans, gcd(g1[i - 1], g2[i + 1]) + a[i])\r\n print(ans)\r\n\r\n\r\nif __author__ == 'Prateek':\r\n t = int(input())\r\n for _ in range(t):\r\n test()\r\n\n```","inputs":"1 \n4 \n4 4 7 6 \n\n","output":"9\n","actual_output":"9\n","execution_success":true,"sample_index":454},{"source":"apps","task_type":"verifiable_code","in_source_id":"851","prompt":"Solve the following coding problem using the programming language python:\n\nMr. X has come up with a new string compression algorithm. Consider a string of length N which contains up to K distinct characters. The compression algorithm works as follows: Replace each maximal contiguous substring containing only one distinct character (repeated an arbitrary number of times) and replace it by 2 values: the character and the length of the substring.\nFor example, the string \"aabbaaa\" will be compressed to \"a, 2, b, 2, a, 3\". Thus the length of the compressed string is 6.\n\nSince Mr. X is living in advanced times, the length of any integer is considered to be 1. For example, if a string is compressed to \"a, 111, b, 13\", then its length after compression is considered to be 4.\n\nTo test his algorithm, he needs to know the expected length of the compressed string for given N and K if the input string is randomly uniformly chosen from all possibilities. He wants to run this experiment multiple times for different N, K and needs your help.\n\n-----Input-----\nThe first line of the input contains an integer T denoting the number of queries. The description of T test cases follows.\nThe first and only line of each test case contains two integers N and K denoting the number of letters in the input string and the maximum number of distinct characters that can be present in the string.\n\n-----Output-----\n\nFor each test case, output a single line containing the expected length of the compressed string. \nYour answer will be considered correct if the absolute error is less than 10-2\n\n-----Constraints-----\n- 1 \u2264 T \u2264 105\n- 1 \u2264 N, K \u2264 109\n\n-----Example-----\nInput:\n2\n3 1\n3 2\nOutput:\n2.0\n4.0\n\n-----Explanation-----Example case 1:\n\nThere is only one string: aaa with compressed string = a, 3. Therefore length = 2\nExample case 2\n\nInput strings:\n\n\"aaa\": \"a, 3\". Length = 2\n\n\"aab\": \"a, 2, b, 1\". Length = 4 \n\n\"aba\": \"a, 1, b, 1, a, 1\". Length = 6\n\n\"abb\": \"a, 1, b, 2\". Length = 4\n\n\"baa\": \"b, 1, a, 2\". Length = 4\n\n\"bab\": \"b, 1, a, 1, b, 1\". Length = 6\n\n\"bba\": \"b, 2, a, 1\". Length = 4\n\n\"bbb\": \"b, 3\". Length = 2\n\nExpected value = (2+4+6+4+4+6+4+2)/8 = 32/8 = 4\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfor _ in range(int(input())):\n\tn,k=map(int,input().split())\n\tprint(((2*n*(k-1))+2)/k)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n3 1\\n3 2\\n\\n', 'output': '2.0\\n4.0\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/COMPEXP'}","problem_id":"vfc_2246","program":"```python\nfor _ in range(int(input())):\n\tn,k=map(int,input().split())\n\tprint(((2*n*(k-1))+2)/k)\n```","inputs":"2\n3 1\n3 2\n\n","output":"2.0\n4.0\n","actual_output":"2.0\n4.0\n","execution_success":true,"sample_index":455},{"source":"apps","task_type":"verifiable_code","in_source_id":"852","prompt":"Solve the following coding problem using the programming language python:\n\nThe 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.\n\n-----Input:-----\n- First-line will contain $T$, the number of test cases. Then the test cases follow. \n- Each test case contains a single line of input, one integer $K$. \n\n-----Output:-----\nFor each test case, output as the pattern.\n\n-----Constraints-----\n- $1 \\leq T \\leq 100$\n- $1 \\leq K \\leq 100$\n\n-----Sample Input:-----\n4\n1\n2\n3\n4\n\n-----Sample Output:-----\n0\n01\n10\n010\n101\n010\n0101\n1010\n0101\n1010\n\n-----EXPLANATION:-----\nNo need, else pattern can be decode easily.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nt=int(input())\nfor t in range(t):\n n=int(input())\n for i in range(0,n):\n for j in range(0,n):\n if i%2==0:\n if j%2==0:\n print(0,end=\"\")\n else:\n print(1,end=\"\")\n else:\n if j%2==0:\n print(1,end=\"\")\n else:\n print(0,end=\"\")\n print()\n \n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '4\\n1\\n2\\n3\\n4\\n', 'output': '0\\n01\\n10\\n010\\n101\\n010\\n0101\\n1010\\n0101\\n1010\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/PTRN2021/problems/ITGUY56'}","problem_id":"vfc_2250","program":"```python\nt=int(input())\nfor t in range(t):\n n=int(input())\n for i in range(0,n):\n for j in range(0,n):\n if i%2==0:\n if j%2==0:\n print(0,end=\"\")\n else:\n print(1,end=\"\")\n else:\n if j%2==0:\n print(1,end=\"\")\n else:\n print(0,end=\"\")\n print()\n \n\n```","inputs":"4\n1\n2\n3\n4\n","output":"0\n01\n10\n010\n101\n010\n0101\n1010\n0101\n1010\n","actual_output":"0\n01\n10\n010\n101\n010\n0101\n1010\n0101\n1010\n","execution_success":true,"sample_index":456},{"source":"apps","task_type":"verifiable_code","in_source_id":"853","prompt":"Solve the following coding problem using the programming language python:\n\nThe new Formula 1 season is about to begin and Chef has got the chance to work with the Formula 1 technical team. \nRecently, the pre-season testing ended and the technical team found out that their timing system for qualifying was a little bit buggy. So, they asked Chef to fix it before the season begins. \nHis task is to write a program to find the starting lineup of the race by taking the timings of the drivers in qualifying.\n(If you don\u2019t know the rules that make the starting grid in Formula 1, consider that the driver with the least time will start at the front). \nNote: \n- Two or more drivers can have the same name. \n- Every driver will have a distinct time. \n\n-----Input:-----\n- The first line of the input consists of a single integer $T$ denoting the number of test cases. \n- First line of each test case consists of a single integer $N$ denoting the number of drivers to set a time. \n- The following $2*N$ lines consists of the driver\u2019s name $S$ in one line and its timing details $X$ (in milliseconds) in the next line. \n\n-----Output:-----\n- For each test case output the starting lineup of the race i.e., name of each driver in the order they will start the race. Print each name in a new line. \n\n-----Constraints-----\n- 1 <= $T$ <= 10 \n- 1 <= $N$ <= 105 \n- 1 <= $|S|$ <= 20 \n- 1 <= $X$ <= 109 \n\n-----Subtasks-----\nSubtask #1 (20 points): \n- 1 <= $N$ <= 100 \nSubtask #2 (80 points): \n- Original Constraints \n\n-----Sample Input:-----\n2\n\n3\n\nHamilton\n\n75000\n\nVettel\n\n76000\n\nBottas\n\n75500\n\n2\n\nLeclerc\n\n666666\n\nVerstappen\n\n666777 \n\n-----Sample Output:-----\nHamilton\n\nBottas\n\nVettel\n\nLeclerc\n\nVerstappen \n\n-----EXPLANATION:-----\nThe drivers with the least time are ahead in the lineup.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\nt=int(input())\nfor i in range(t):\n n=int(input())\n if n<101:\n l1=[]\n l2=[]\n d=dict()\n for i in range(1,2*n+1):\n if i%2==0:\n l1.append(int(input()))\n else:\n l2.append(str(input()))\n r1=[]\n for i in l1:\n r1.append(i)\n l1.sort()\n ind=[]\n for i in l1:\n a=r1.index(i)\n ind.append(a)\n for i in ind:\n print(l2[i])\n else:\n print(0)\n break\n \n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n3\\nHamilton\\n75000\\nVettel\\n76000\\nBottas\\n75500\\n2\\nLeclerc\\n666666\\nVerstappen\\n666777\\n', 'output': 'Hamilton\\nBottas\\nVettel\\nLeclerc\\nVerstappen\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/TCFL2020/problems/TCFL20B'}","problem_id":"vfc_2254","program":"```python\n# cook your dish here\nt=int(input())\nfor i in range(t):\n n=int(input())\n if n<101:\n l1=[]\n l2=[]\n d=dict()\n for i in range(1,2*n+1):\n if i%2==0:\n l1.append(int(input()))\n else:\n l2.append(str(input()))\n r1=[]\n for i in l1:\n r1.append(i)\n l1.sort()\n ind=[]\n for i in l1:\n a=r1.index(i)\n ind.append(a)\n for i in ind:\n print(l2[i])\n else:\n print(0)\n break\n \n\n```","inputs":"2\n3\nHamilton\n75000\nVettel\n76000\nBottas\n75500\n2\nLeclerc\n666666\nVerstappen\n666777\n","output":"Hamilton\nBottas\nVettel\nLeclerc\nVerstappen\n","actual_output":"Hamilton\nBottas\nVettel\nLeclerc\nVerstappen\n","execution_success":true,"sample_index":457},{"source":"apps","task_type":"verifiable_code","in_source_id":"854","prompt":"Solve the following coding problem using the programming language python:\n\nA beautiful sequence is defined as a sequence that do not have any repeating elements in it.\nYou will be given any random sequence of integers, and you have to tell whether it is a beautiful sequence or not. \n\n-----Input:-----\n- The first line of the input contains a single integer $T$. $T$ denoting the number of test cases. The description of $T$ test cases is as follows.\n- The next line of the input contains a single integer $N$. $N$ denotes the total number of elements in the sequence.\n- The next line of the input contains $N$ space-separated integers $A1, A2, A3...An$ denoting the sequence.\n\n-----Output:-----\n- Print \"prekrasnyy\"(without quotes) if the given sequence is a beautiful sequence, else print \"ne krasivo\"(without quotes)\nNote: each test case output must be printed on new line\n\n-----Constraints:-----\n- $1 \\leq T \\leq 10^2$\n- $1 \\leq N \\leq 10^3$\n- $1 \\leq A1, A2, A3...An \\leq 10^5$\n\n-----Sample Input:-----\n2\n4\n1 2 3 4\n6\n1 2 3 5 1 4\n\n-----Sample Output:-----\nprekrasnyy\nne krasivo\n\n-----Explanation:-----\n- \nAs 1st sequence do not have any elements repeating, hence it is a beautiful sequence\n- \nAs in 2nd sequence the element 1 is repeated twice, hence it is not a beautiful sequence\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\nfor _ in range(int(input())):\n n = int(input())\n arr = list(map(int,input().split()))\n l = []\n for i in range(0, len(arr)): \n for j in range(i+1, len(arr)): \n if(arr[i] == arr[j]): \n l.append(arr[j])\n if (len(l) ==0):\n print(\"prekrasnyy\")\n else:\n print(\"ne krasivo\")\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n4\\n1 2 3 4\\n6\\n1 2 3 5 1 4\\n', 'output': 'prekrasnyy\\nne krasivo\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/ARYS2020/problems/FREQARRY'}","problem_id":"vfc_2258","program":"```python\n# cook your dish here\nfor _ in range(int(input())):\n n = int(input())\n arr = list(map(int,input().split()))\n l = []\n for i in range(0, len(arr)): \n for j in range(i+1, len(arr)): \n if(arr[i] == arr[j]): \n l.append(arr[j])\n if (len(l) ==0):\n print(\"prekrasnyy\")\n else:\n print(\"ne krasivo\")\n```","inputs":"2\n4\n1 2 3 4\n6\n1 2 3 5 1 4\n","output":"prekrasnyy\nne krasivo\n","actual_output":"prekrasnyy\nne krasivo\n","execution_success":true,"sample_index":458},{"source":"apps","task_type":"verifiable_code","in_source_id":"855","prompt":"Solve the following coding problem using the programming language python:\n\nAccepts a string from the user and print the reverse string as the output without using any built-in function.\n\n-----Input:-----\nEach testcase contains of a single line of input, a string.\n\n-----Output:-----\nFor each testcase, output in a single line answer, the reverse string.\n\n-----Sample Input:-----\n1\nTracy\n\n-----Sample Output:-----\nycarT\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\noo = int(input())\r\nfor i in range(oo):\r\n\tval = input()\r\n\tprint(val[::-1])\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\nTracy\\n', 'output': 'ycarT\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/SPNT2020/problems/AODLS002'}","problem_id":"vfc_2262","program":"```python\noo = int(input())\r\nfor i in range(oo):\r\n\tval = input()\r\n\tprint(val[::-1])\n```","inputs":"1\nTracy\n","output":"ycarT\n","actual_output":"ycarT\n","execution_success":true,"sample_index":459},{"source":"apps","task_type":"verifiable_code","in_source_id":"856","prompt":"Solve the following coding problem using the programming language python:\n\nYou are given a dataset consisting of $N$ items. Each item is a pair of a word and a boolean denoting whether the given word is a spam word or not.\nWe want to use this dataset for training our latest machine learning model. Thus we want to choose some subset of this dataset as training dataset. We want to make sure that there are no contradictions in our training set, i.e. there shouldn't be a word included in the training set that's marked both as spam and not-spam. For example item {\"fck\", 1}, and item {\"fck, 0\"} can't be present in the training set, because first item says the word \"fck\" is a spam, whereas the second item says it is not, which is a contradiction.\nYour task is to select the maximum number of items in the training set.\nNote that same pair of {word, bool} can appear multiple times in input. The training set can also contain the same pair multiple times.\n\n-----Input-----\n- First line will contain $T$, number of test cases. Then the test cases follow.\n- The first line of each test case contains a single integer $N$.\n- $N$ lines follow. For each valid $i$, the $i$-th of these lines contains a string $w_i$, followed by a space and an integer(boolean) $s_i$, denoting the $i$-th item.\n\n-----Output-----\nFor each test case, output an integer corresponding to the maximum number of items that can be included in the training set in a single line.\n\n-----Constraints-----\n- $1 \\le T \\le 10$\n- $1 \\le N \\le 25,000$\n- $1 \\le |w_i| \\le 5$ for each valid $i$\n- $0 \\le s_i \\le 1$ for each valid $i$\n- $w_1, w_2, \\ldots, w_N$ contain only lowercase English letters\n\n-----Example Input-----\n3\n3\nabc 0\nabc 1\nefg 1\n7\nfck 1\nfck 0\nfck 1\nbody 0\nbody 0\nbody 0\nram 0\n5\nvv 1\nvv 0\nvv 0\nvv 1\nvv 1\n\n-----Example Output-----\n2\n6\n3\n\n-----Explanation-----\nExample case 1: You can include either of the first and the second item, but not both. The third item can also be taken. This way the training set can contain at the very max 2 items.\nExample case 2: You can include all the items except the second item in the training set.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nt = int(input())\n\nfor _ in range(t):\n n = int(input())\n \n a = {}\n \n for i in range(n):\n l = input()\n \n if l not in a:\n a[l] = 1\n else:\n a[l] += 1\n \n done = []\n ans = 0\n \n for i in a:\n if a[i] != 0:\n temp = [x for x in i.split()]\n v = temp[0]\n \n v0 = v + \" 0\"\n v1 = v + \" 1\"\n \n if(v0 in a and v1 in a):\n if a[v0] > a[v1]:\n ans += a[v0]\n else:\n ans += a[v1]\n \n a[v0] = a[v1] = 0\n elif(v0 in a):\n ans += a[v0]\n a[v0] = 0\n elif(v1 in a):\n ans += a[v1]\n a[v1] = 0\n \n print(ans)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\n3\\nabc 0\\nabc 1\\nefg 1\\n7\\nfck 1\\nfck 0\\nfck 1\\nbody 0\\nbody 0\\nbody 0\\nram 0\\n5\\nvv 1\\nvv 0\\nvv 0\\nvv 1\\nvv 1\\n\\n', 'output': '2\\n6\\n3\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/TRAINSET'}","problem_id":"vfc_2266","program":"```python\nt = int(input())\n\nfor _ in range(t):\n n = int(input())\n \n a = {}\n \n for i in range(n):\n l = input()\n \n if l not in a:\n a[l] = 1\n else:\n a[l] += 1\n \n done = []\n ans = 0\n \n for i in a:\n if a[i] != 0:\n temp = [x for x in i.split()]\n v = temp[0]\n \n v0 = v + \" 0\"\n v1 = v + \" 1\"\n \n if(v0 in a and v1 in a):\n if a[v0] > a[v1]:\n ans += a[v0]\n else:\n ans += a[v1]\n \n a[v0] = a[v1] = 0\n elif(v0 in a):\n ans += a[v0]\n a[v0] = 0\n elif(v1 in a):\n ans += a[v1]\n a[v1] = 0\n \n print(ans)\n```","inputs":"3\n3\nabc 0\nabc 1\nefg 1\n7\nfck 1\nfck 0\nfck 1\nbody 0\nbody 0\nbody 0\nram 0\n5\nvv 1\nvv 0\nvv 0\nvv 1\nvv 1\n\n","output":"2\n6\n3\n","actual_output":"2\n6\n3\n","execution_success":true,"sample_index":460},{"source":"apps","task_type":"verifiable_code","in_source_id":"857","prompt":"Solve the following coding problem using the programming language python:\n\nProblem description.\nDominic Toretto has taken his crew to compete in this years' Race Wars, a crew-on-crew tournament in which each member of one crew competes with a member of the other crew in a quarter mile drag race. Each win counts as one point for the winning crew. Draws and loses are awarded zero points. In the end the crew with more points is declared the winner of that round and can advance while the losing crew is knocked out. One member can compete in only one race per round and all crews have the same number of members.\nDom and his crew have a reputation of being the best and naturally everyone expects them to win this year as well.\nHowever, during the tournament he spots a new crew of racers who are participating for the first time in this event. People expect them to be a dark horse so naturally Dom wants to keep an eye on their performance.\nBeing the experienced racer that he is, Dom has figured out the time in which each racer of the opposing crew completes his quarter mile race.\n\nHe also knows his own crew inside out and can estimate with absolute certainty, the time it would take each of his members to complete the race. Dominic is the reigning champion and thus has an advantage that he can select the order of the matches i.e.: he can select which member of his crew will go up against which member of the opposition. Given this data he wants to figure out the number of races he will win should his crew come face to face with their newest rivals.\n\nUnfortunately he is a racer and not a problem solver so he comes to you for help.\n\nGiven the time each member of the two crews take to complete the race you have to figure out a way to arrange the matches so that Dominic can win maximum points possible for him.\n\n-----Input-----\n\nThe first line of input is the T, the number of test cases.\n\nEach test case starts with a single number N, the number of racers on each crew.\n\nThis is followed by two lines, each having N space separated integers containing the time taken by each member of Dominic's crew and the rival crew respectively.\n\n-----Output-----\nOutput a single integer. The maximum number of points that Dominic can get.\n\n-----Constraints-----\n1<=T<=100\n1<=N<=100\nTime taken by each member will be between 1 and 500\n\n-----Example-----\nInput:\n\n1\n3\n5 4 1\n5 4 1\n\nOutput:\n2\n\n-----Explanation-----\nIf Dom selects Racer 1 of his team to go against Racer 2 of the other team, Racer 2 of his team against Racer 3 of the other team and Racer 3 of his team against Racer 1 of the other team then he ends up with two wins and a loss which gives him 2 points. ...\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\ntestcases = int(input())\n\nfor i in range(testcases):\n n = int(input())\n my = list(map(int,input().split()))\n opp = list(map(int,input().split()))\n \n my.sort(reverse = True)\n opp.sort(reverse = True)\n \n j = 0\n k = 0\n while(k < n):\n if(my[j] > opp[k]):\n j += 1\n k += 1\n\n print(j)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n3\\n5 4 1\\n5 4 1\\n', 'output': '2\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/EXCT2015/problems/RACEWARS'}","problem_id":"vfc_2270","program":"```python\ntestcases = int(input())\n\nfor i in range(testcases):\n n = int(input())\n my = list(map(int,input().split()))\n opp = list(map(int,input().split()))\n \n my.sort(reverse = True)\n opp.sort(reverse = True)\n \n j = 0\n k = 0\n while(k < n):\n if(my[j] > opp[k]):\n j += 1\n k += 1\n\n print(j)\n```","inputs":"1\n3\n5 4 1\n5 4 1\n","output":"2\n","actual_output":"2\n","execution_success":true,"sample_index":461},{"source":"apps","task_type":"verifiable_code","in_source_id":"858","prompt":"Solve the following coding problem using the programming language python:\n\nFor Diwali, Chef arranges all $K$ laddus in a row in his sweet shop. Whenever a customer comes to buy laddus, chef follows a rule that each customer must buy all laddus on odd position. After the selection of the laddu, a new row is formed, and again out of these only laddus on odd position are selected. This continues until the chef left with the last laddu. Find out the position of that last laddu in the original row.\n\n-----Input:-----\n- First line will contain $T$, number of testcases. Then the testcases follow. \n- Each testcase contains of a single line of input, one integer $K$. \n\n-----Output:-----\nFor each testcase, print the position of that laddu who is left, in the original row.\n\n-----Constraints-----\n- $1 \\leq T \\leq 10^5$\n- $1 \\leq K \\leq 10^5$\n\n-----Sample Input:-----\n3\n1\n5\n8\n\n-----Sample Output:-----\n1\n4\n8\n\n-----EXPLANATION:-----\nFor 1) Only one laddu which is last so print 1.\nFor 2) Customer 1: [1, 3, 5]\nNew row = [2, 4]\n\nCustomer 2: [2]\n\nLast laddu = 4\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\nt=int(input())\nwhile t>0:\n n=int(input())\n if n==1:\n print(1)\n else:\n c,num=1,2\n while num0:\n n=int(input())\n if n==1:\n print(1)\n else:\n c,num=1,2\n while num=3)\n\nGiven two numbers a and b, calculate how many Fibonacci numbers are in the range [a,b].\n\n\n-----Input-----\n\nThe input contains several test cases. Each test case consists of two non-negative integer numbers a and b. Input is terminated by a=b=0. Otherwise, a<=b<=10^100. The numbers a and b are given with no superfluous leading zeros.\n\n-----Output-----\n\nFor each test case output on a single line the number of Fibonacci numbers fi with a<=fi<=b.\n\n-----Example-----\nInput:\n\n10 100\n1234567890 9876543210\n0 0\n\nOutput:\n\n5\n4\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n#!/usr/bin/env python\n\nF = [1,1]\ndef fibo():\n for i in range(500):\n F.append(F[-2] + F[-1])\n\ndef main():\n fibo()\n #print len(str(F[-1]))\n #print len(str(10**100))\n while True:\n try:\n A, B = list(map(int, input().strip().split()[:2]))\n if A == 0 and B == 0: break\n print(len([x for x in F if x >= A and x <= B]))\n except:\n break\n\nmain()\n\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '10 100\\n1234567890 9876543210\\n0 0\\n', 'output': '5\\n4\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/PRFT2012/problems/PD32'}","problem_id":"vfc_2286","program":"```python\n#!/usr/bin/env python\n\nF = [1,1]\ndef fibo():\n for i in range(500):\n F.append(F[-2] + F[-1])\n\ndef main():\n fibo()\n #print len(str(F[-1]))\n #print len(str(10**100))\n while True:\n try:\n A, B = list(map(int, input().strip().split()[:2]))\n if A == 0 and B == 0: break\n print(len([x for x in F if x >= A and x <= B]))\n except:\n break\n\nmain()\n\n\n```","inputs":"10 100\n1234567890 9876543210\n0 0\n","output":"5\n4\n","actual_output":"5\n4\n","execution_success":true,"sample_index":465},{"source":"apps","task_type":"verifiable_code","in_source_id":"862","prompt":"Solve the following coding problem using the programming language python:\n\nAs we all know, Dhoni loves drinking milk. Once he and Sir Jadeja were invited in the inauguration of a Dairy company in Ranchi.\n\nThe company had arranged n jars of milk from various breeds of cows , jar number i containing a[i] litres of milk. Since Dhoni loves driking milk more than Sir Jadeja, so Kohli suggested a plan for them. His plan was that each time Dhoni will choose a jar containing the maximum amount of milk. If this jar has less than k litres of milk or if Dhoni has already drunk more than m number of times from this jar, then the milk contained in the jar will be drunk by Sir Jadeja. Sir Jadeja will drink all the milk left in that jar. Otherwise Dhoni will drink exactly k litres of milk from the jar and put it back at its position. Dhoni will do so until he has given all jars to Sir Jadeja.\n\nYou have to calculate how much milk Sir Jadega will get after Dhoni satisfies his hunger modulo 1,000,000,007.\n\n-----Input-----\n- The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.\n- The first line of each test case contains integer N , M, K denoting the number of milk jars, maximum number of time Dhoni will drink from any jar and maximum amount of milk Dhoni will drink at any time respectively. The second line contains N space-separated integers A1, A2, ..., AN denoting the amount of milk in each jar. \n\n-----Output-----\n- For each test case, output a single line containing the amount of milk Sir Jadega will get modulo 1,000,000,007.\n\n-----Constraints-----\n- 1 \u2264 T \u2264 10 \n- 1 \u2264 N \u2264 10^5 \n- 0 \u2264 M \u2264 10^6 \n- 1 \u2264 K \u2264 10^6 \n- 0 \u2264 Ai \u2264 10^9 \n\n-----Example-----\nInput:\n1\n3 3 3\n15 8 10\n\nOutput:\n9\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\ncases = int(input())\n\nfor case in range(cases):\n N, M, K = [int(i) for i in input().split()]\n A = [int(i) for i in input().split()]\n jad = 0\n P = M*K\n\n for milk in A:\n if(milk>P):\n jad += milk-P\n else:\n jad += milk%K\n\n print(jad%1000000007)\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n3 3 3\\n15 8 10\\n', 'output': '9\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/BITC2016/problems/DMILK'}","problem_id":"vfc_2290","program":"```python\ncases = int(input())\n\nfor case in range(cases):\n N, M, K = [int(i) for i in input().split()]\n A = [int(i) for i in input().split()]\n jad = 0\n P = M*K\n\n for milk in A:\n if(milk>P):\n jad += milk-P\n else:\n jad += milk%K\n\n print(jad%1000000007)\n\n```","inputs":"1\n3 3 3\n15 8 10\n","output":"9\n","actual_output":"9\n","execution_success":true,"sample_index":466},{"source":"apps","task_type":"verifiable_code","in_source_id":"863","prompt":"Solve the following coding problem using the programming language python:\n\nThe government has invited bids from contractors to run canteens at all railway stations. Contractors will be allowed to bid for the catering contract at more than one station. However, to avoid monopolistic price-fixing, the government has declared that no contractor may bid for a pair of neighbouring stations.\nThe railway network has exactly one route between any pair of stations. Each station is directly connected by a railway line to at most $50$ neighbouring stations.\nTo help contractors plan their bids, the government has provided data on the number of passengers who pass through each station each year. Contractors would like to bid for stations with a higher volume of passenger traffic to increase their turnover.\nFor instance, suppose the railway network is as follows, where the volume of passenger traffic is indicated by the side of each station.\n\nIn this network, the best option for the contractor is to bid for stations $1, 2, 5$ and $6$, for a total passenger volume of $90$.\nYour task is to choose a set of stations that the contractor should bid for so that the total volume of traffic across all the stations in the bid is maximized.\n\n-----Input:-----\nThe first line of the input contains one integer $N$ indicating the number of railways stations in the network. The stations are numbered $1,2,...,N$. This is followed by $N$ lines of input, lines $2, 3,..., N+1$, indicating the volume of traffic at each station. The volume of traffic at station $i, 1 \\leq i \\leq N$, is given by a single integer in line $i+1$. The next $N-1$ lines of input, lines $N+2, N+3, ..., 2N$, describe the railway network. Each of these lines contains two integers, denoting a pair of stations that are neighbours.\n\n-----Output:-----\nThe output should be a single integer, corresponding to the total volume of traffic across the set of stations in the optimal bid made by the contractor.\n\n-----Constraints:-----\n- $1 \\leq N \\leq 100000$. \n- Each railway station has at most $50$ neighbours.\n\n-----Sample Input-----\n6\n10\n20\n25\n40\n30\n30\n4 5\n1 3\n3 4\n2 3\n6 4\n\n-----Sample Output-----\n90\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nn=int(input())\r\nl=[]\r\ndp=[]\r\nd={}\r\nfor i in range(n):\r\n\tl.append(int(input()))\r\n\td[i]=[]\r\n\tdp.append([0,0])\r\n\r\nfor i in range(n-1):\r\n\ta,b=list(map(int,input().split()))\r\n\td[a-1].append(b-1)\r\n\td[b-1].append(a-1)\r\n#print(l)\r\n#print(d)\r\n\r\ndef dfs(ch,pa,visited):\r\n\tdp[ch][1]=l[ch]\r\n\t#print(dp[ch],ch+1)\r\n\tfor i in range(len(d[ch])):\r\n\t\tif d[ch][i] not in visited:\r\n\t\t\tvisited.add(d[ch][i])\r\n\t\t\tdfs(d[ch][i],ch,visited)\r\n\t\t\tdp[ch][0]+=max(dp[d[ch][i]][0],dp[d[ch][i]][1])\r\n\t\t\tdp[ch][1]+=dp[d[ch][i]][0]\r\n\t\t\t#print(ch+1,dp[ch])\r\nv=set()\r\nv.add(0)\r\ndfs(0,-1,v)\r\n\r\n#print(dp)\r\nprint(max(dp[0][0],dp[0][1]))\r\n\r\n\t\r\n\r\n\r\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '6\\n10\\n20\\n25\\n40\\n30\\n30\\n4 5\\n1 3\\n3 4\\n2 3\\n6 4\\n', 'output': '90\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/IARCSJUD/problems/CATERCON'}","problem_id":"vfc_2294","program":"```python\nn=int(input())\r\nl=[]\r\ndp=[]\r\nd={}\r\nfor i in range(n):\r\n\tl.append(int(input()))\r\n\td[i]=[]\r\n\tdp.append([0,0])\r\n\r\nfor i in range(n-1):\r\n\ta,b=list(map(int,input().split()))\r\n\td[a-1].append(b-1)\r\n\td[b-1].append(a-1)\r\n#print(l)\r\n#print(d)\r\n\r\ndef dfs(ch,pa,visited):\r\n\tdp[ch][1]=l[ch]\r\n\t#print(dp[ch],ch+1)\r\n\tfor i in range(len(d[ch])):\r\n\t\tif d[ch][i] not in visited:\r\n\t\t\tvisited.add(d[ch][i])\r\n\t\t\tdfs(d[ch][i],ch,visited)\r\n\t\t\tdp[ch][0]+=max(dp[d[ch][i]][0],dp[d[ch][i]][1])\r\n\t\t\tdp[ch][1]+=dp[d[ch][i]][0]\r\n\t\t\t#print(ch+1,dp[ch])\r\nv=set()\r\nv.add(0)\r\ndfs(0,-1,v)\r\n\r\n#print(dp)\r\nprint(max(dp[0][0],dp[0][1]))\r\n\r\n\t\r\n\r\n\r\n\n```","inputs":"6\n10\n20\n25\n40\n30\n30\n4 5\n1 3\n3 4\n2 3\n6 4\n","output":"90\n","actual_output":"90\n","execution_success":true,"sample_index":467},{"source":"apps","task_type":"verifiable_code","in_source_id":"864","prompt":"Solve the following coding problem using the programming language python:\n\nThese days, chef is very much interested in Mathematics. He has started attending Recitations too! His hunger for problems is increasing day by day!\nToday, chef was a given a crumpled maths problem, which he is stuck with . He needs your help to do it\nHere's what his teacher said: \"Find sum of all numbers till N, do not include numbers which are powers of K from K, K2, K3... which are less than or equal to N\"\nEasy, right? Can you solve it?\n\n-----INPUT-----\nThe 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 contains two integers N and K, as per the above given problem specification.\n\n-----OUTPUT-----\nFor each test case, output a single line printing the sum of the each test case, in format Case #T: S, where T is the Tth test case running and S is sum of corresponding test case.\n\n-----CONSTRAINTS-----\n\n10 < T < 50\n\n10 < N < 104\n\n0 < K < 100\n\n-----EXAMPLE-----\nInput:\n\n2\n\n10 3\n\n20 2\n\nOutput:\n\nCase #1: 43\n\nCase #2: 180\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\ntestCases = int(input())\nfor c in range(testCases):\n n, k = list(map(int, input().split()))\n sum = 0\n i = 0\n power = 1\n while i <= n:\n if k**power == i:\n power += 1\n else:\n sum += i\n i +=1 \n answer = \"Case #\" + str(c + 1) + \": \" + str(sum)\n print(answer)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n10 3\\n20 2\\n', 'output': 'Case #1: 43\\nCase #2: 180\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/GSTS1601/problems/BUG2K16E'}","problem_id":"vfc_2298","program":"```python\ntestCases = int(input())\nfor c in range(testCases):\n n, k = list(map(int, input().split()))\n sum = 0\n i = 0\n power = 1\n while i <= n:\n if k**power == i:\n power += 1\n else:\n sum += i\n i +=1 \n answer = \"Case #\" + str(c + 1) + \": \" + str(sum)\n print(answer)\n```","inputs":"2\n10 3\n20 2\n","output":"Case #1: 43\nCase #2: 180\n","actual_output":"Case #1: 43\nCase #2: 180\n","execution_success":true,"sample_index":468},{"source":"apps","task_type":"verifiable_code","in_source_id":"865","prompt":"Solve the following coding problem using the programming language python:\n\nGiven N, count how many permutations of [1, 2, 3, ..., N] satisfy the following property.\n\nLet P1, P2, ..., PN denote the permutation. The property we want to satisfy is that there exists an i between 2 and n-1 (inclusive) such that\n\n- Pj > Pj + 1 \u2200 i \u2264 j \u2264 N - 1.\n- Pj > Pj - 1 \u2200 2 \u2264 j \u2264 i.\n\n-----Input-----\nFirst line contains T, the number of test cases. Each test case consists of N in one line.\n\n-----Output-----\nFor each test case, output the answer modulo 109+7.\n\n-----Constraints-----\n- 1 \u2264 T \u2264 100\n- 1 \u2264 N \u2264 109\n\n-----Subtasks-----\n- Subtask #1(40 points): 1 \u2264 N \u2264 1000\n- Subtask #2(60 points): original constraints\n\n-----Example-----\nInput:\n2\n2\n3\n\nOutput:\n0\n2\n\n-----Explanation-----\n\nTest case 1:\n\nNo permutation satisfies.\n\nTest case 2:\n\nPermutations [1, 3, 2] and [2, 3, 1] satisfy the property.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\ntry:\n \n for _ in range(int(input())):\n n = int(input())\n print(0) if(n==1) else print(pow(2,n-1,10**9+7)-2) \nexcept EOFError:\n pass\n\n \n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n2\\n3\\n', 'output': '0\\n2\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/CPERM'}","problem_id":"vfc_2302","program":"```python\ntry:\n \n for _ in range(int(input())):\n n = int(input())\n print(0) if(n==1) else print(pow(2,n-1,10**9+7)-2) \nexcept EOFError:\n pass\n\n \n```","inputs":"2\n2\n3\n","output":"0\n2\n","actual_output":"0\n2\n","execution_success":true,"sample_index":469},{"source":"apps","task_type":"verifiable_code","in_source_id":"867","prompt":"Solve the following coding problem using the programming language python:\n\nFor her next karate demonstration, Ada will break some bricks.\nAda stacked three bricks on top of each other. Initially, their widths (from top to bottom) are W1,W2,W3.\nAda's strength is S. Whenever she hits a stack of bricks, consider the largest k\u22650 such that the sum of widths of the topmost k bricks does not exceed S; the topmost k bricks break and are removed from the stack. Before each hit, Ada may also decide to reverse the current stack of bricks, with no cost.\nFind the minimum number of hits Ada needs in order to break all bricks if she performs the reversals optimally. You are not required to minimise the number of reversals.\nInput\nThe first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows.\nThe first and only line of each test case contains four space-separated integers S, W1, W2 and W3.Output\nFor each test case, print a single line containing one integer \u2015 the minimum required number of hits.Constraints\n- 1\u2264T\u226464\n- 1\u2264S\u22648\n- 1\u2264Wi\u22642 for each valid i\nit is guaranteed that Ada can break all bricksExample Input\n\n3\n\n3 1 2 2\n\n2 1 1 1\n\n3 2 2 1\nExample Output\n\n2\n\n2\n\n2\nExplanation\n\nExample case 1:\n\nAda can reverse the stack and then hit it two times. Before the first hit, the widths of bricks in the stack (from top to bottom) are (2,2,1). After the first hit, the topmost brick breaks and the stack becomes (2,1). The second hit breaks both remaining bricks.\n\nIn this particular case, it is also possible to hit the stack two times without reversing. Before the first hit, it is (1,2,2). The first hit breaks the two bricks at the top (so the stack becomes (2)) and the second hit breaks the last brick.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nT = int(input())\nfor _ in range(T):\n W = list(map(int, input().strip().split()))\n S = W[0]\n W = W[1:]\n W = W[::-1]\n i = 0\n c = 0\n flag = 0\n while (len(W) != 0 or flag != 1) and i=3:\n if index%2==prev:\n dict[tuple]=function(l1,index+1,prev,count)\n return function(l1,index+1,prev,count)\n else:\n dict[tuple]=l1[index]+function(l1,index+1,prev,count);\n return dict[tuple]\n if prev==None:\n skip=l1[index]+function(l1,index+1,prev,count)\n not_skip=function(l1,index+1,index%2,count+1)\n maxa=min(skip,not_skip)\n dict[tuple]=maxa\n return maxa;\n\n if index%2==prev:\n dict[tuple]=function(l1,index+1,index%2,count)\n return dict[tuple]\n if index%2!=prev:\n skip=l1[index]+function(l1,index+1,prev,count)\n not_skip=function(l1,index+1,index%2,1+count)\n maxa = min(skip, not_skip)\n dict[tuple]=maxa\n return maxa;\n\nt=int(input())\nfor i in range(t):\n s=input()\n l=list(s)\n n=len(l)\n l=[int(i) for i in l]\n l1=fun(l)\n dict=defaultdict(int)\n theta=function(l1,0,None,0)\n print(theta)\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '4\\n010111101\\n1011100001011101\\n0110\\n111111\\n', 'output': '2\\n3\\n0\\n0\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/PRFYIT'}","problem_id":"vfc_2322","program":"```python\n# cook your dish here\nimport math;\nfrom math import gcd,sqrt,floor,factorial,ceil\nfrom bisect import bisect_left,bisect_right\nimport bisect;\nimport sys;\nfrom sys import stdin,stdout\nimport os\nsys.setrecursionlimit(pow(10,7))\nimport collections\nfrom collections import defaultdict,Counter\nfrom statistics import median\n# input=stdin.readline\n# print=stdout.write\nfrom queue import Queue\ninf = float(\"inf\")\nfrom operator import neg;\nmod=pow(10,9)+7\ndef fun(l):\n m=[[l[0]]]\n for i in range(1,n):\n if m[-1][-1]==l[i]:\n m[-1]+=[l[i]]\n else:\n m.append([l[i]])\n count=[]\n for i in range(len(m)):\n count.append(len(m[i]))\n return count;\ndef function(l1,index,prev,count):\n tuple=(index,prev,count)\n if tuple in dict:\n return dict[tuple]\n n=len(l1)\n if index==n:\n return 0;\n if count>=3:\n if index%2==prev:\n dict[tuple]=function(l1,index+1,prev,count)\n return function(l1,index+1,prev,count)\n else:\n dict[tuple]=l1[index]+function(l1,index+1,prev,count);\n return dict[tuple]\n if prev==None:\n skip=l1[index]+function(l1,index+1,prev,count)\n not_skip=function(l1,index+1,index%2,count+1)\n maxa=min(skip,not_skip)\n dict[tuple]=maxa\n return maxa;\n\n if index%2==prev:\n dict[tuple]=function(l1,index+1,index%2,count)\n return dict[tuple]\n if index%2!=prev:\n skip=l1[index]+function(l1,index+1,prev,count)\n not_skip=function(l1,index+1,index%2,1+count)\n maxa = min(skip, not_skip)\n dict[tuple]=maxa\n return maxa;\n\nt=int(input())\nfor i in range(t):\n s=input()\n l=list(s)\n n=len(l)\n l=[int(i) for i in l]\n l1=fun(l)\n dict=defaultdict(int)\n theta=function(l1,0,None,0)\n print(theta)\n\n```","inputs":"4\n010111101\n1011100001011101\n0110\n111111\n","output":"2\n3\n0\n0\n","actual_output":"2\n3\n0\n0\n","execution_success":true,"sample_index":474},{"source":"apps","task_type":"verifiable_code","in_source_id":"871","prompt":"Solve the following coding problem using the programming language python:\n\nYou are given a grid with $R$ rows (numbered $1$ through $R$) and $C$ columns (numbered $1$ through $C$). Initially, each cell of this grid is either empty, contains an ant or an anteater. Each ant is moving in a fixed direction: up, down, left or right. The anteaters do not move.\nThe movement of ants happens in discrete steps. For example, when an ant is in the cell in the $i$-th row and $j$-th column at some point in time (in some step) and it is moving down, then in the next step, it enters the cell in the $(i+1)$-th row and $j$-th column. Two ants meet each other when they enter the same cell at the same point in time (in the same step). When ants meet, they do not interact in any way and keep moving in their fixed directions.\nIf an ant reaches an anteater, that anteater eats the ant, so the ant completely disappears. If an ant attempts to leave the grid, it also disappears. When two ants enter a cell containing an anteater at the same time, they are eaten before they could meet.\nCalculate the total number of pairs of ants that meet each other.\n\n-----Input-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The first line of each test case contains two space-separated integers $R$ and $C$.\n- Each of the following $R$ lines contains a single string with length $C$. For each valid $i, j$, the $j$-th character in the $i$-th string is:\n- '#' if the cell in the $i$-th row and $j$-th column of the grid contains an anteater\n- 'U', 'D', 'L' or 'R' if this cell contains an ant moving up, down, left or right respectively\n- '-' if this cell is empty\n\n-----Output-----\nFor each test case, print a single line containing one integer \u2014 the number of pairs of ants that meet.\n\n-----Constraints-----\n- $1 \\le T \\le 10$\n- $1 \\le R, C \\le 50$\n- each string contains only characters 'U', 'D', 'L', 'R', '#' and '-'\n\n-----Example Input-----\n10\n3 3\nR--\n---\n--U\n1 4\nR--R\n2 2\n--\n--\n1 4\nR--L\n1 4\n-R-L\n1 4\n-R#L\n3 3\nR-D\n-#-\nR-U\n3 3\nR-D\n---\nR#U\n3 3\n-D-\nR-L\n-U-\n1 7\nRLLLLLL\n\n-----Example Output-----\n1\n0\n0\n0\n1\n0\n3\n2\n6\n3\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nimport sys\r\n\r\nt = int(input())\r\n# print(t)\r\nfor _ in range(t):\r\n\tn,m = map(int,input().split());\r\n\ts = [];\r\n\tfor i in range(n):\r\n\t\ts.append(input())\r\n\tans = []\r\n\tfor i in range(n):\r\n\t\tans.append([])\r\n\t\tfor j in range(m):\r\n\t\t\tans[i].append([])\r\n\tfor i in range(n):\r\n\t\tfor j in range(m):\r\n\t\t\tc = 0\r\n\t\t\tif s[i][j] == 'U':\r\n\t\t\t\tfor k in range(i,-1,-1):\r\n\t\t\t\t\tif s[k][j] == '#':\r\n\t\t\t\t\t\tbreak\r\n\t\t\t\t\tans[k][j].append(c)\r\n\t\t\t\t\tc+=1\r\n\t\t\telif s[i][j] == 'D':\r\n\t\t\t\tfor k in range(i,n):\r\n\t\t\t\t\tif s[k][j] == '#':\r\n\t\t\t\t\t\tbreak\r\n\t\t\t\t\tans[k][j].append(c)\r\n\t\t\t\t\tc+=1\r\n\t\t\telif s[i][j] == 'L':\r\n\t\t\t\tfor k in range(j,-1,-1):\r\n\t\t\t\t\tif s[i][k] == '#':\r\n\t\t\t\t\t\tbreak\r\n\t\t\t\t\tans[i][k].append(c)\r\n\t\t\t\t\tc+=1\r\n\t\t\telif s[i][j] == 'R':\r\n\t\t\t\tfor k in range(j,m):\r\n\t\t\t\t\tif s[i][k] == '#':\r\n\t\t\t\t\t\tbreak\r\n\t\t\t\t\tans[i][k].append(c)\r\n\t\t\t\t\tc+=1\r\n\tfor i in range(n):\r\n\t\tfor j in range(m):\r\n\t\t\tans[i][j].sort()\r\n\tres = []\r\n\tfor i in range(n):\r\n\t\tfor j in range(m):\r\n\t\t\tc= 1\r\n\t\t\t# print(ans[i][j])\r\n\t\t\tfor k in range(1,len(ans[i][j])):\r\n\t\t\t\t# print(ans[i][j][k])\r\n\t\t\t\tif ans[i][j][k] == ans[i][j][k-1]:\r\n\t\t\t\t\tc+=1\r\n\t\t\t\telse :\r\n\t\t\t\t\tif c!=1:\r\n\t\t\t\t\t\tres.append(c)\r\n\t\t\t\t\tc = 1\r\n\t\t\t\tif k==len(ans[i][j])-1:\r\n\t\t\t\t\tif c!=1:\r\n\t\t\t\t\t\tres.append(c)\r\n\tpairs = 0\r\n\t# print(res)\r\n\tfor i in range(len(res)):\r\n\t\tpairs += ((res[i]*(res[i]-1))//2)\r\n\t\r\n\tprint(pairs)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '10\\n3 3\\nR--\\n---\\n--U\\n1 4\\nR--R\\n2 2\\n--\\n--\\n1 4\\nR--L\\n1 4\\n-R-L\\n1 4\\n-R#L\\n3 3\\nR-D\\n-#-\\nR-U\\n3 3\\nR-D\\n---\\nR#U\\n3 3\\n-D-\\nR-L\\n-U-\\n1 7\\nRLLLLLL\\n\\n', 'output': '1\\n0\\n0\\n0\\n1\\n0\\n3\\n2\\n6\\n3\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/ANTEATER'}","problem_id":"vfc_2326","program":"```python\nimport sys\r\n\r\nt = int(input())\r\n# print(t)\r\nfor _ in range(t):\r\n\tn,m = map(int,input().split());\r\n\ts = [];\r\n\tfor i in range(n):\r\n\t\ts.append(input())\r\n\tans = []\r\n\tfor i in range(n):\r\n\t\tans.append([])\r\n\t\tfor j in range(m):\r\n\t\t\tans[i].append([])\r\n\tfor i in range(n):\r\n\t\tfor j in range(m):\r\n\t\t\tc = 0\r\n\t\t\tif s[i][j] == 'U':\r\n\t\t\t\tfor k in range(i,-1,-1):\r\n\t\t\t\t\tif s[k][j] == '#':\r\n\t\t\t\t\t\tbreak\r\n\t\t\t\t\tans[k][j].append(c)\r\n\t\t\t\t\tc+=1\r\n\t\t\telif s[i][j] == 'D':\r\n\t\t\t\tfor k in range(i,n):\r\n\t\t\t\t\tif s[k][j] == '#':\r\n\t\t\t\t\t\tbreak\r\n\t\t\t\t\tans[k][j].append(c)\r\n\t\t\t\t\tc+=1\r\n\t\t\telif s[i][j] == 'L':\r\n\t\t\t\tfor k in range(j,-1,-1):\r\n\t\t\t\t\tif s[i][k] == '#':\r\n\t\t\t\t\t\tbreak\r\n\t\t\t\t\tans[i][k].append(c)\r\n\t\t\t\t\tc+=1\r\n\t\t\telif s[i][j] == 'R':\r\n\t\t\t\tfor k in range(j,m):\r\n\t\t\t\t\tif s[i][k] == '#':\r\n\t\t\t\t\t\tbreak\r\n\t\t\t\t\tans[i][k].append(c)\r\n\t\t\t\t\tc+=1\r\n\tfor i in range(n):\r\n\t\tfor j in range(m):\r\n\t\t\tans[i][j].sort()\r\n\tres = []\r\n\tfor i in range(n):\r\n\t\tfor j in range(m):\r\n\t\t\tc= 1\r\n\t\t\t# print(ans[i][j])\r\n\t\t\tfor k in range(1,len(ans[i][j])):\r\n\t\t\t\t# print(ans[i][j][k])\r\n\t\t\t\tif ans[i][j][k] == ans[i][j][k-1]:\r\n\t\t\t\t\tc+=1\r\n\t\t\t\telse :\r\n\t\t\t\t\tif c!=1:\r\n\t\t\t\t\t\tres.append(c)\r\n\t\t\t\t\tc = 1\r\n\t\t\t\tif k==len(ans[i][j])-1:\r\n\t\t\t\t\tif c!=1:\r\n\t\t\t\t\t\tres.append(c)\r\n\tpairs = 0\r\n\t# print(res)\r\n\tfor i in range(len(res)):\r\n\t\tpairs += ((res[i]*(res[i]-1))//2)\r\n\t\r\n\tprint(pairs)\n```","inputs":"10\n3 3\nR--\n---\n--U\n1 4\nR--R\n2 2\n--\n--\n1 4\nR--L\n1 4\n-R-L\n1 4\n-R#L\n3 3\nR-D\n-#-\nR-U\n3 3\nR-D\n---\nR#U\n3 3\n-D-\nR-L\n-U-\n1 7\nRLLLLLL\n\n","output":"1\n0\n0\n0\n1\n0\n3\n2\n6\n3\n","actual_output":"1\n0\n0\n0\n1\n0\n3\n2\n6\n3\n","execution_success":true,"sample_index":475},{"source":"apps","task_type":"verifiable_code","in_source_id":"872","prompt":"Solve the following coding problem using the programming language python:\n\nAppy and Chef are participating in a contest. There are $N$ problems in this contest; each problem has a unique problem code between $1$ and $N$ inclusive. Appy and Chef decided to split the problems to solve between them \u2015 Appy should solve the problems whose problem codes are divisible by $A$ but not divisible by $B$, and Chef should solve the problems whose problem codes are divisible by $B$ but not divisible by $A$ (they decided to not solve the problems whose codes are divisible by both $A$ and $B$).\nTo win, it is necessary to solve at least $K$ problems. You have to tell Appy whether they are going to win or lose.\n\n-----Input-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The first and only line of each test case contains four space-separated integers $N$, $A$, $B$ and $K$.\n\n-----Output-----\nFor each test case, print a single line containing the string \"Win\" if they can solve at least $K$ problems or \"Lose\" otherwise (without quotes).\n\n-----Constraints-----\n- $1 \\le T \\le 15$\n- $1 \\le K \\le N \\le 10^{18}$\n- $1 \\le A, B \\le 10^9$\n\n-----Subtasks-----\nSubtask #1 (15 points):\n- $1 \\le T \\le 15$\n- $1 \\le K \\le N \\le 10^6$\n- $1 \\le A, B \\le 10^3$\nSubtask #2 (85 points): original constraints\n\n-----Example Input-----\n1\n6 2 3 3\n\n-----Example Output-----\nWin\n\n-----Explanation-----\nExample case 1: Appy is solving the problems with codes $2$ and $4$, Chef is solving the problem with code $3$. Nobody is solving problem $6$, since $6$ is divisible by both $2$ and $3$. Therefore, they can solve $3$ problems and win.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfor t in range(int(input())):\n n, a , b , k = map(int,input().split())\n solvedbychef = 0\n solvedbyappy = 0\n for i in range(n+1):\n if i % a == 0 and i % b == 0 :\n continue\n elif i%a == 0 :\n solvedbyappy+=1\n elif i%b == 0:\n solvedbychef+=1\n totalsolved = solvedbychef + solvedbyappy\n if totalsolved>=k:\n print(\"Win\")\n else :\n print(\"Lose\")\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n6 2 3 3\\n', 'output': 'Win\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/HMAPPY2'}","problem_id":"vfc_2330","program":"```python\nfor t in range(int(input())):\n n, a , b , k = map(int,input().split())\n solvedbychef = 0\n solvedbyappy = 0\n for i in range(n+1):\n if i % a == 0 and i % b == 0 :\n continue\n elif i%a == 0 :\n solvedbyappy+=1\n elif i%b == 0:\n solvedbychef+=1\n totalsolved = solvedbychef + solvedbyappy\n if totalsolved>=k:\n print(\"Win\")\n else :\n print(\"Lose\")\n```","inputs":"1\n6 2 3 3\n","output":"Win\n","actual_output":"Win\n","execution_success":true,"sample_index":476},{"source":"apps","task_type":"verifiable_code","in_source_id":"873","prompt":"Solve the following coding problem using the programming language python:\n\n\tThe following graph G is called a Petersen graph and its vertices have been numbered from 0 to 9. Some letters have also been assigned to vertices of G, as can be seen from the following picture:\n\n\tLet's consider a walk W in graph G, which consists of L vertices W1, W2, ..., WL, such that Wi is connected with Wi + 1 for 1 \u2264 i < L. A string S of L letters 'A'-'E' is realized by walk W if the sequence of letters written along W is equal to S. Vertices can be visited multiple times while walking along W.\n\nFor example, S = 'ABBECCD' is realized by W = (0, 1, 6, 9, 7, 2, 3).\nYour task is to determine whether there is a walk W which realizes a given string S in graph G, and if so, find the lexicographically least such walk.\n\n-----Input-----\n\n\tThe first line of the input contains one integer T denoting the number of testcases to process.\n\n\tThe only line of each testcase contains one string S. It is guaranteed that S only consists of symbols 'A'-'E'.\n\n-----Output-----\n\n\tThe output should contain exactly T lines, one line per each testcase in the order of their appearance. For each testcase, if there is no walk W which realizes S, then output -1. Otherwise, you should output the least lexicographical walk W which realizes S. Since all of the vertices are numbered from 0 to 9, then it can be encoded as a string consisting of symbols '0'-'9' (see the \"Examples\" section for more details).\n\n-----Constraints-----\n1 \u2264 T \u2264 8;\n1 \u2264 |S| \u2264 100000(105).\n\n-----Examples-----\nInput:\n2\nAAB\nAABE\n\nOutput:\n501\n-1\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nlet_to_num = {'A':[0,5], 'B':[1,6], 'C':[2,7], 'D':[3,8], 'E':[4,9]}\n\nnum_to_let = {0:'A', 1:'B', 2:'C', 3:'D', 4:'E',\n 5:'A', 6:'B', 7:'C', 8:'D', 9:'E'}\n\nconnections = {0:(1,4,5), 1:(0,2,6), 2:(1,3,7), 3:(2,4,8), 4:(0,3,9), 5:(0,7,8),\n 6:(1,8,9), 7:(2,5,9), 8:(3,5,6), 9:(4,6,7)}\n\nT = int(input())\n\nfor i in range(T):\n s = input()\n out_1, out_2= [],[]\n flag1, flag2 = True, True\n for c in range(len(s)):\n #print out_1, out_2, flag1, flag2\n if c == 0:\n out_1.append(let_to_num[s[c]][0])\n out_2.append(let_to_num[s[c]][1])\n #print out_1, out_2, '\\n'\n else:\n if flag1:\n conn_1 = set(connections[out_1[-1]])\n to_conn_1 = set(let_to_num[s[c]])\n \n if len(conn_1.intersection(to_conn_1))==0:\n flag1 = False\n else:\n out_1.extend(list(conn_1.intersection(to_conn_1)))\n \n #print 'out1',conn_1, to_conn_1, flag1, conn_1.intersection(to_conn_1)\n if flag2:\n conn_2 = set(connections[out_2[-1]])\n to_conn_2 = set(let_to_num[s[c]])\n \n if len(conn_2.intersection(to_conn_2))==0:\n flag2 = False\n else:\n out_2.extend(list(conn_2.intersection(to_conn_2)))\n #print 'out2', conn_2, to_conn_2, flag2, conn_2.intersection(to_conn_2)\n #print out_1, out_2, flag1, flag2, '\\n'\n if (not flag1) and (not flag2):\n break\n if (not flag1) and (not flag2):\n print(-1)\n continue\n elif flag1 and (not flag2):\n print(''.join(str(k) for k in out_1))\n continue\n elif flag2 and (not flag1):\n print(''.join(str(k) for k in out_2))\n continue\n else:\n print(min(''.join(str(k) for k in out_1), ''.join(str(k) for k in out_2)))\n continue\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\nAAB\\nAABE\\n\\n\\n', 'output': '501\\n-1\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/COOK52/problems/PETERSEN'}","problem_id":"vfc_2334","program":"```python\nlet_to_num = {'A':[0,5], 'B':[1,6], 'C':[2,7], 'D':[3,8], 'E':[4,9]}\n\nnum_to_let = {0:'A', 1:'B', 2:'C', 3:'D', 4:'E',\n 5:'A', 6:'B', 7:'C', 8:'D', 9:'E'}\n\nconnections = {0:(1,4,5), 1:(0,2,6), 2:(1,3,7), 3:(2,4,8), 4:(0,3,9), 5:(0,7,8),\n 6:(1,8,9), 7:(2,5,9), 8:(3,5,6), 9:(4,6,7)}\n\nT = int(input())\n\nfor i in range(T):\n s = input()\n out_1, out_2= [],[]\n flag1, flag2 = True, True\n for c in range(len(s)):\n #print out_1, out_2, flag1, flag2\n if c == 0:\n out_1.append(let_to_num[s[c]][0])\n out_2.append(let_to_num[s[c]][1])\n #print out_1, out_2, '\\n'\n else:\n if flag1:\n conn_1 = set(connections[out_1[-1]])\n to_conn_1 = set(let_to_num[s[c]])\n \n if len(conn_1.intersection(to_conn_1))==0:\n flag1 = False\n else:\n out_1.extend(list(conn_1.intersection(to_conn_1)))\n \n #print 'out1',conn_1, to_conn_1, flag1, conn_1.intersection(to_conn_1)\n if flag2:\n conn_2 = set(connections[out_2[-1]])\n to_conn_2 = set(let_to_num[s[c]])\n \n if len(conn_2.intersection(to_conn_2))==0:\n flag2 = False\n else:\n out_2.extend(list(conn_2.intersection(to_conn_2)))\n #print 'out2', conn_2, to_conn_2, flag2, conn_2.intersection(to_conn_2)\n #print out_1, out_2, flag1, flag2, '\\n'\n if (not flag1) and (not flag2):\n break\n if (not flag1) and (not flag2):\n print(-1)\n continue\n elif flag1 and (not flag2):\n print(''.join(str(k) for k in out_1))\n continue\n elif flag2 and (not flag1):\n print(''.join(str(k) for k in out_2))\n continue\n else:\n print(min(''.join(str(k) for k in out_1), ''.join(str(k) for k in out_2)))\n continue\n\n```","inputs":"2\nAAB\nAABE\n\n\n","output":"501\n-1\n","actual_output":"501\n-1\n","execution_success":true,"sample_index":477},{"source":"apps","task_type":"verifiable_code","in_source_id":"874","prompt":"Solve the following coding problem using the programming language python:\n\nZCO is approaching, and you want to be well prepared! \nThere are $N$ topics to cover and the $i^{th}$ topic takes $H_i$ hours to prepare (where $1 \\le i \\le N$). You have only $M$ days left to prepare, and you want to utilise this time wisely. You know that you can't spend more than $S$ hours in a day preparing, as you get tired after that. You don't want to study more than one topic in a day, and also, don't want to spend more than two days on any topic, as you feel that this is inefficient. \nGiven these constraints, can you find the maximum number of topics you can prepare, if you choose the topics wisely?\n\n-----Input:-----\n- First line will contain $T$, number of testcases. Then the testcases follow. \n- The first line of each test case contains three space-separated integers: $N$, $M$ and $S$, denoting the number of topics, the number of days remaining and the number of hours you can study in a day. \n- The second line of each test case contains $N$ space-separated integers $H_i$, denoting the number of hours needed to prepare for the $i^{th}$ topic.\n\n-----Output:-----\nFor each testcase, output in a single line: the maximum number of topics you can prepare.\n\n-----Constraints-----\n- $1 \\leq T \\leq 10$\n- $1 \\leq N \\leq 10^5$\n- $1 \\leq M \\leq 10^5$\n- $1 \\leq S \\leq 16$\n- $1 \\leq H_i \\leq 50$\n\n-----Subtasks-----\n- 30 points : Every topic takes the same number of hours to prepare (i.e. all $H_i$ are equal).\n- 70 points : Original constraints.\n\n-----Sample Input:-----\n2\n5 4 10\n10 24 30 19 40\n5 4 16\n7 16 35 10 15\n\n-----Sample Output:-----\n2\n4\n\n-----Explanation:-----\nTestcase 1:\n\nYou can choose topics $1$ and $4$. Topic $1$ will consume a single day , while topic $4$ will consume two days. Thus, you'll be able to prepare these two topics within the 4 remaining days. But you can check that you cannot do any better.\nTestcase 2:\n\nYou can choose topics $1$, $2$, $4$, and $5$. Each of them will consume one day each. Thus you'll be able to cover $4$ topics.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nimport math\nT=int(input())\nfor i in range(T):\n N,M,S=input().split()\n N=int(N)\n M=int(M)\n S=int(S)\n ls=list(map(int,input().split()))\n maxx=max(ls)\n if S<17 and maxx<=50:\n ls.sort()\n total_sum = M * S\n count = 0\n sum = 0\n for i in ls:\n if i / S > 2:\n continue\n else:\n sum = sum + math.ceil(i / S) * S\n if sum <= total_sum:\n count = count + 1\n print(count)\n# cook your dish here\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n5 4 10\\n10 24 30 19 40\\n5 4 16\\n7 16 35 10 15\\n', 'output': '2\\n4\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/ZCOPREP'}","problem_id":"vfc_2338","program":"```python\nimport math\nT=int(input())\nfor i in range(T):\n N,M,S=input().split()\n N=int(N)\n M=int(M)\n S=int(S)\n ls=list(map(int,input().split()))\n maxx=max(ls)\n if S<17 and maxx<=50:\n ls.sort()\n total_sum = M * S\n count = 0\n sum = 0\n for i in ls:\n if i / S > 2:\n continue\n else:\n sum = sum + math.ceil(i / S) * S\n if sum <= total_sum:\n count = count + 1\n print(count)\n# cook your dish here\n\n```","inputs":"2\n5 4 10\n10 24 30 19 40\n5 4 16\n7 16 35 10 15\n","output":"2\n4\n","actual_output":"2\n4\n","execution_success":true,"sample_index":478},{"source":"apps","task_type":"verifiable_code","in_source_id":"875","prompt":"Solve the following coding problem using the programming language python:\n\nVanja and Miksi really like games. After playing one game for a long time, they decided to invent another game!\nIn this game, they have a sequence $A_1, A_2, \\dots, A_N$ and two numbers $Z_1$ and $Z_2$. The rules of the game are as follows:\n- The players take turns alternately, starting with Vanja.\n- There is an integer $S$; at the beginning, $S = 0$.\n- In each turn, the current player must choose an arbitrary element of $A$ and either add that number to $S$ or subtract it from $S$. Each element can be selected multiple times.\n- Afterwards, if $S = Z_1$ or $S = Z_2$, the current player (the player who made $S$ equal to $Z_1$ or $Z_2$) is the winner of the game.\n- If the game lasts for $10^{10}$ turns, Vanja and Miksi decide to declare it a tie.\nCan you help the boys determine the winner of the game? Please note that the game can end in a tie (if nobody can make $S = Z_1$ or $S = Z_2$ in the first $10^{10}$ moves).\nBoth players play optimally, i.e. if there is a move which guarantees the current player's victory regardless of the other player's moves, the current player will make such a move. If the current player cannot win and there is a move which guarantees that the game will end in a tie, the current player will make such a move.\n\n-----Input-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The first line of each test case contains three space-separated integers $N$, $Z_1$ and $Z_2$.\n- The second line contains $N$ space-separated integers $A_1, A_2, \\dots, A_N$.\n\n-----Output-----\n- For each test case, print a single line containing one integer \u2014 the final result of the game:\n- $1$ if Vanja (the first player) has a winning strategy\n- $2$ if Miksi (the second player) has a winning strategy\n- $0$ if the game ends in a tie\n\n-----Constraints-----\n- $1 \\le T \\le 50$\n- $1 \\le N \\le 50$\n- $|Z_1|, |Z_2| \\le 10^9$\n- $|A_i| \\le 10^9$ for each valid $i$\n\n-----Subtasks-----\nSubtask #1 (25 points): $N = 2$\nSubtask #2 (75 points): original constraints\n\n-----Example Input-----\n3\n2 6 4\n-4 10\n1 1 -1\n2\n2 0 7\n3 4\n\n-----Example Output-----\n1\n0\n2\n\n-----Explanation-----\nExample case 1: The first player can choose the value $A_1 = -4$, subtract it from $S = 0$ and obtain $S = - (-4) = 4 = Z_2$. The winner is the first player. \nExample case 2: It can be proven that neither player is able to reach $S = Z_1$ or $S = Z_2$. The result is a tie.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nimport sys\nfrom collections import defaultdict as dd\nfrom collections import deque\nfrom fractions import Fraction as f\nfrom copy import *\nfrom bisect import * \nfrom heapq import *\nfrom math import *\nfrom itertools import permutations \n \ndef eprint(*args):\n print(*args, file=sys.stderr)\nzz=1\n \n#sys.setrecursionlimit(10**6)\nif zz:\n input=sys.stdin.readline\nelse: \n sys.stdin=open('input.txt', 'r')\n sys.stdout=open('all.txt','w')\ndef li():\n return [int(xx) for xx in input().split()]\ndef fli():\n return [float(x) for x in input().split()] \ndef comp(a,b):\n if(a>b):\n return 2\n return 2 if a==b else 0 \ndef gi(): \n return [xx for x in input().split()]\ndef fi():\n return int(input())\ndef swap(a,i,j):\n a[i],a[j]=a[j],a[i] \ndef si():\n return list(input().rstrip()) \ndef mi():\n return map(int,input().split()) \ndef gh():\n sys.stdout.flush()\ndef graph(n,m):\n for i in range(m):\n x,y=mi()\n a[x].append(y)\n a[y].append(x)\ndef bo(i):\n return ord(i)-ord('a')\n \n \nt=fi()\nwhile t>0:\n t-=1\n n,z1,z2=mi()\n d={}\n a=li()\n flag=0\n for i in a:\n d[i]=1\n d[-i]=1\n if i==z1 or i==z2 or i==-z1 or i==-z2:\n flag=1\n break\n if flag:\n print(1)\n continue \n for i in d:\n p=[i-z1,i-z2]\n c=1\n for j in p:\n if j in d:\n c*=0\n flag|=c \n print(0 if flag else 2) \n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\n2 6 4\\n-4 10\\n1 1 -1\\n2\\n2 0 7\\n3 4\\n', 'output': '1\\n0\\n2\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/JAGAM'}","problem_id":"vfc_2342","program":"```python\nimport sys\nfrom collections import defaultdict as dd\nfrom collections import deque\nfrom fractions import Fraction as f\nfrom copy import *\nfrom bisect import * \nfrom heapq import *\nfrom math import *\nfrom itertools import permutations \n \ndef eprint(*args):\n print(*args, file=sys.stderr)\nzz=1\n \n#sys.setrecursionlimit(10**6)\nif zz:\n input=sys.stdin.readline\nelse: \n sys.stdin=open('input.txt', 'r')\n sys.stdout=open('all.txt','w')\ndef li():\n return [int(xx) for xx in input().split()]\ndef fli():\n return [float(x) for x in input().split()] \ndef comp(a,b):\n if(a>b):\n return 2\n return 2 if a==b else 0 \ndef gi(): \n return [xx for x in input().split()]\ndef fi():\n return int(input())\ndef swap(a,i,j):\n a[i],a[j]=a[j],a[i] \ndef si():\n return list(input().rstrip()) \ndef mi():\n return map(int,input().split()) \ndef gh():\n sys.stdout.flush()\ndef graph(n,m):\n for i in range(m):\n x,y=mi()\n a[x].append(y)\n a[y].append(x)\ndef bo(i):\n return ord(i)-ord('a')\n \n \nt=fi()\nwhile t>0:\n t-=1\n n,z1,z2=mi()\n d={}\n a=li()\n flag=0\n for i in a:\n d[i]=1\n d[-i]=1\n if i==z1 or i==z2 or i==-z1 or i==-z2:\n flag=1\n break\n if flag:\n print(1)\n continue \n for i in d:\n p=[i-z1,i-z2]\n c=1\n for j in p:\n if j in d:\n c*=0\n flag|=c \n print(0 if flag else 2) \n```","inputs":"3\n2 6 4\n-4 10\n1 1 -1\n2\n2 0 7\n3 4\n","output":"1\n0\n2\n","actual_output":"1\n0\n2\n","execution_success":true,"sample_index":479},{"source":"apps","task_type":"verifiable_code","in_source_id":"876","prompt":"Solve the following coding problem using the programming language python:\n\nRachel has some candies and she decided to distribute them among $N$ kids. The ith kid receives $A_i$ candies. The kids are happy iff the difference between the highest and lowest number of candies received is less than $X$.\nFind out if the children are happy or not.\n\n-----Input:-----\n- First line will contain $T$, number of testcases. Then the testcases follow. \n- The first line contains $N$ and $X$. \n- The second line contains $N$ integers $A_1,A_2,...,A_N$. \n\n-----Output:-----\nFor each test case print either \"YES\"(without quotes) if the kids are happy else \"NO\"(without quotes)\n\n-----Constraints-----\n- $1 \\leq T \\leq 100$\n- $1 \\leq N, X \\leq 10^5$\n- $1 \\leq A_i \\leq 10^5$\n\n-----Sample Input:-----\n2\n\n5 6\n\n3 5 6 8 1\n\n3 10\n\n5 2 9\n\n-----Sample Output:-----\nNO\n\nYES\n\n-----EXPLANATION:-----\n- Example 1: Difference between maximum and minimum candies received is 8-1=7. 7 is greater than 6, therefore, the kids are not happy.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nt=int(input())\r\n\r\nfor t1 in range(t):\r\n\tn,x=map(int,input().split())\r\n\ta=list(map(int,input().split()))\r\n\t\r\n\tmx=max(a)\r\n\tmn=min(a)\r\n\t\r\n\tif (mx-mnar[j]):\n si=j-st\n c=(si*(si+1))//2\n tot+=c\n st=j\n si=n-st\n c=(si*(si+1))//2\n tot+=c\n print(tot)\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n4\\n1 4 2 3\\n1\\n5\\n', 'output': '6\\n1\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/SUBINC'}","problem_id":"vfc_2366","program":"```python\n# cook your dish here\nt=int(input())\nfor i in range(t):\n n=int(input())\n ar=list(map(int,input().split()))\n tot=0\n st=0\n for j in range(1,n):\n if(ar[j-1]>ar[j]):\n si=j-st\n c=(si*(si+1))//2\n tot+=c\n st=j\n si=n-st\n c=(si*(si+1))//2\n tot+=c\n print(tot)\n\n```","inputs":"2\n4\n1 4 2 3\n1\n5\n","output":"6\n1\n","actual_output":"6\n1\n","execution_success":true,"sample_index":485},{"source":"apps","task_type":"verifiable_code","in_source_id":"882","prompt":"Solve the following coding problem using the programming language python:\n\nAs we all know, Chef is cooking string for long days, his new discovery on string is the longest common pattern length. The longest common pattern length between two strings is the maximum number of characters that both strings have in common. Characters are case sensitive, that is, lower case and upper case characters are considered as different. Note that characters can repeat in a string and a character might have one or more occurrence in common between two strings. For example, if Chef has two strings A = \"Codechef\" and B = \"elfedcc\", then the longest common pattern length of A and B is 5 (common characters are c, d, e, e, f).\nChef wants to test you with the problem described above. He will give you two strings of Latin alphabets and digits, return him the longest common pattern length.\n\n-----Input-----\nThe first line of the input contains an integer T, denoting the number of test cases. Then the description of T test cases follows.\nThe first line of each test case contains a string A. The next line contains another character string B.\n\n-----Output-----\nFor each test case, output a single line containing a single integer, the longest common pattern length between A and B.\n\n-----Constraints-----\n- 1 \u2264 T \u2264 100\n- 1 \u2264 |A|, |B| \u2264 10000 (104), where |S| denotes the length of the string S\n- Both of A and B can contain only alphabet characters (both lower and upper case) and digits\n\n-----Example-----\nInput:\n4\nabcd\nxyz\nabcd\nbcda\naabc\nacaa\nCodechef\nelfedcc\n\nOutput:\n0\n4\n3\n5\n\n-----Explanation-----\nExample case 1. There is no common character.\nExample case 2. All the characters are same.\nExample case 3. Three characters (a, a and c) are same.\nExample case 4. This sample is mentioned by the statement.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfrom collections import Counter\r\ndef solve(A,B):\r\n a = Counter(A)\r\n b = Counter(B)\r\n ans = 0\r\n for i in a:\r\n if i in b:\r\n ans += min(a[i],b[i])\r\n \r\n return ans\r\n \r\n \r\nt = int(input())\r\n\r\nfor _ in range(t):\r\n A = input()\r\n B = input()\r\n print(solve(A,B))\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '4\\nabcd\\nxyz\\nabcd\\nbcda\\naabc\\nacaa\\nCodechef\\nelfedcc\\n\\n\\n', 'output': '0\\n4\\n3\\n5\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/LCPESY'}","problem_id":"vfc_2370","program":"```python\nfrom collections import Counter\r\ndef solve(A,B):\r\n a = Counter(A)\r\n b = Counter(B)\r\n ans = 0\r\n for i in a:\r\n if i in b:\r\n ans += min(a[i],b[i])\r\n \r\n return ans\r\n \r\n \r\nt = int(input())\r\n\r\nfor _ in range(t):\r\n A = input()\r\n B = input()\r\n print(solve(A,B))\n```","inputs":"4\nabcd\nxyz\nabcd\nbcda\naabc\nacaa\nCodechef\nelfedcc\n\n\n","output":"0\n4\n3\n5\n","actual_output":"0\n4\n3\n5\n","execution_success":true,"sample_index":486},{"source":"apps","task_type":"verifiable_code","in_source_id":"883","prompt":"Solve the following coding problem using the programming language python:\n\nIt's year 2018 and it's Christmas time! Before going for vacations, students of Hogwarts School of Witchcraft and Wizardry had their end semester exams.\n$N$ students attended the semester exam. Once the exam was over, their results were displayed as either \"Pass\" or \"Fail\" behind their magic jacket which they wore. A student cannot see his/her result but can see everyone else's results. Each of $N$ students count the number of passed students they can see.\nGiven the number of \"Pass\" verdicts that each of the $N$ students counted, we have to figure out conclusively, the number of students who failed, or report that there is some inconsistency or that we cannot be sure.\n\n-----Input:-----\n- First line will contain $T$, number of testcases. Then the testcases follow. \n- The first line of each test case will contain $N$, representing the number of students who attended the exam.\n- Next line contains $N$ spaced integers representing the number of \"Pass\" counted by each of the $N$ students.\n\n-----Output:-----\n- For each test case, output the answer in a single line. \n- If the counts reported by the students are not consistent with each other or if it's not possible to predict the number of failed students from the given input, then print -1.\n\n-----Constraints-----\n- $1 \\leq T \\leq 50$\n- $1 \\leq N \\leq 10^{5}$\n- $0 \\leq$ Count given by each Student $\\leq 10^{5}$\n\n-----Sample Input:-----\n1\n4\n3 2 2 2\n\n-----Sample Output:-----\n1\n\n-----EXPLANATION:-----\nThere are 4 students, and they counted the number of passed students as 3,2,2,2. The first student can see that all others have passed, and all other students can see only 2 students who have passed. Hence, the first student must have failed, and others have all passed. Hence, the answer is 1.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfor _ in range(int(input())):\n n = int(input())\n a = list(map(int, input().split()))\n s = set(a)\n\n if n == 1 or len(s) > 2:\n print(-1)\n continue\n\n if len(s) == 1:\n x = s.pop()\n\n if x == 0:\n print(n)\n elif x == n-1:\n print(0)\n else:\n print(-1)\n\n continue\n\n x, y = sorted(s)\n xc, yc = a.count(x), a.count(y)\n\n if xc == y and xc == x + 1:\n print(yc)\n else:\n print(-1)\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n4\\n3 2 2 2\\n', 'output': '1\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/CNTFAIL'}","problem_id":"vfc_2374","program":"```python\nfor _ in range(int(input())):\n n = int(input())\n a = list(map(int, input().split()))\n s = set(a)\n\n if n == 1 or len(s) > 2:\n print(-1)\n continue\n\n if len(s) == 1:\n x = s.pop()\n\n if x == 0:\n print(n)\n elif x == n-1:\n print(0)\n else:\n print(-1)\n\n continue\n\n x, y = sorted(s)\n xc, yc = a.count(x), a.count(y)\n\n if xc == y and xc == x + 1:\n print(yc)\n else:\n print(-1)\n\n```","inputs":"1\n4\n3 2 2 2\n","output":"1\n","actual_output":"1\n","execution_success":true,"sample_index":487},{"source":"apps","task_type":"verifiable_code","in_source_id":"884","prompt":"Solve the following coding problem using the programming language python:\n\nWrite a program that reads two numbers $X$ and $K$. The program first finds the factors of $X$ and then gives the sum of $K$th power of every factor. The program also finds the factor of $k$ and outputs the sum of $X$ times of every factor. \n\n-----Input:-----\n- First line will contain $T$, number of testcases. Then the testcases follow. \n- Each testcase contains of a single line of input, two integers $X, R$. \n\n-----Output:-----\nFor each testcase, output in a single line the factors of $X$ and the $K$th power of every factor, seperated by a space.\n\n-----Constraints-----\n- $1 \\leq T \\leq 1000$\n- $2 \\leq X, K \\leq 10^9$\n\n-----Sample Input:-----\n1\n8 6\n\n-----Sample Output:-----\n266304 88\n\n-----EXPLANATION:-----\nFactors of x = 8 are 2, 4, and 8. Also, factors of k = 6 are 2, 3, and 6.\n2^6 + 4^6 + 8^6 = 266304 and 2 \u00d7 8 + 3 \u00d7 8 + 6 \u00d7 8 = 88.\n(Where a ^b denotes a raised to the power of b).\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\ntry:\r\n for _ in range(int(input())):\r\n s,s1=0,0\r\n x,k=[int(i) for i in input().split()]\r\n for i in range(2,x+1):\r\n if(x%i==0):\r\n s=s+i**k\r\n for i in range(2,k+1):\r\n if(k%i==0):\r\n s1+=i*x\r\n print(s,s1)\r\nexcept EOFError as e:\r\n pass\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n8 6\\n', 'output': '266304 88\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/SITC2020/problems/FACPOW'}","problem_id":"vfc_2378","program":"```python\ntry:\r\n for _ in range(int(input())):\r\n s,s1=0,0\r\n x,k=[int(i) for i in input().split()]\r\n for i in range(2,x+1):\r\n if(x%i==0):\r\n s=s+i**k\r\n for i in range(2,k+1):\r\n if(k%i==0):\r\n s1+=i*x\r\n print(s,s1)\r\nexcept EOFError as e:\r\n pass\n```","inputs":"1\n8 6\n","output":"266304 88\n","actual_output":"266304 88\n","execution_success":true,"sample_index":488},{"source":"apps","task_type":"verifiable_code","in_source_id":"885","prompt":"Solve the following coding problem using the programming language python:\n\nChef solved so many hard questions, now he wants to solve some easy problems for refreshment. Chef asks Cheffina for the new question. Cheffina challenges the chef to print the total number of 0's in the binary representation of N(natural number).\n\n-----Input:-----\n- First-line will contain $T$, the number of test cases. Then the test cases follow. \n- Each test case contains a single line of input, $N$. \n\n-----Output:-----\nFor each test case, output in a single line answer.\n\n-----Constraints-----\n- $1 \\leq T \\leq 10^6$\n- $1 \\leq N \\leq 10^6$\n\n-----Sample Input:-----\n2\n2\n4\n\n-----Sample Output:-----\n1\n2\n\n-----EXPLANATION:-----\nFor 1) Binary representation of 2 is 10. i.e. only one 0 present in it.\nFor 2) Binary representation of 4 is 100, i.e. two 0's present in it.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfrom sys import stdin, stdout\r\ninput = stdin.readline\r\nfrom collections import defaultdict as dd\r\nimport math\r\ndef geti(): return list(map(int, input().strip().split()))\r\ndef getl(): return list(map(int, input().strip().split()))\r\ndef gets(): return input()\r\ndef geta(): return int(input())\r\ndef print_s(s): stdout.write(s+'\\n')\r\n\r\ndef solve():\r\n for _ in range(geta()):\r\n n=geta()\r\n n=bin(n).split('b')[1]\r\n print(n.count('0'))\r\n\r\n\r\ndef __starting_point():\r\n solve()\r\n\n__starting_point()\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n2\\n4\\n', 'output': '1\\n2\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/PBK32020/problems/ITGUY31'}","problem_id":"vfc_2382","program":"```python\nfrom sys import stdin, stdout\r\ninput = stdin.readline\r\nfrom collections import defaultdict as dd\r\nimport math\r\ndef geti(): return list(map(int, input().strip().split()))\r\ndef getl(): return list(map(int, input().strip().split()))\r\ndef gets(): return input()\r\ndef geta(): return int(input())\r\ndef print_s(s): stdout.write(s+'\\n')\r\n\r\ndef solve():\r\n for _ in range(geta()):\r\n n=geta()\r\n n=bin(n).split('b')[1]\r\n print(n.count('0'))\r\n\r\n\r\ndef __starting_point():\r\n solve()\r\n\n__starting_point()\n```","inputs":"2\n2\n4\n","output":"1\n2\n","actual_output":"1\n2\n","execution_success":true,"sample_index":489},{"source":"apps","task_type":"verifiable_code","in_source_id":"886","prompt":"Solve the following coding problem using the programming language python:\n\nChef is playing a game with his childhood friend. He gave his friend a list of N numbers named $a_1, a_2 .... a_N$ (Note: All numbers are unique). Adjust the numbers in the following order:\n$(i)$ swap every alternate number with it's succeeding number (If N is odd, do not swap the last number i.e. $a_N$ ).\n$(ii)$ add %3 of every number to itself.\n$(iii)$ swap the ith number and the (N-i-1) th number.\nAfter this, Chef will give a number to his friend and he has to give the nearest greater and smaller number to it.\nIf there is no greater or lesser number, put -1.\nHelp his friend to find the two numbers.\n\n-----Input:-----\n- First-line will contain $T$, the number of test cases. Then the test cases follow. \n- Each test case contains a single line of input, an integers $N$. \n- Next line contains $N$ integers separated by a space. \n- Next line contains a number to be found, $M$. \n\n-----Output:-----\nFor each test case, output in a single line answer given the immediate smaller and greater number separated by a space.\n\n-----Constraints-----\n- $1 \\leq T \\leq 1000$\n- $3 \\leq N \\leq 10^5$\n- $1 \\leq N_i \\leq 10^9$\n- $1 \\leq M \\leq 10^9$\n\n-----Sample Input:-----\n1\n10\n5 15 1 66 55 32 40 22 34 11\n38\n\n-----Sample Output:-----\n35 41\n\n-----Explaination:-----\nStep 1: 15 5 66 1 32 55 22 40 11 34\nStep 2: 15 7 66 2 34 56 23 41 13 35\nStep 3: 35 13 41 23 56 34 2 66 7 15\n35 is the number lesser than 38 and 41 is the number greater than 38 in the given set of numbers.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfor _ in range(int(input())):\n n=int(input())\n a=list(map(int,input().split()))\n x=int(input())\n for _ in range(1,n,2):\n a[_],a[_-1]=a[_-1],a[_]\n for _ in range(n):\n a[_]+=(a[_]%3)\n # a=a[::-1]\n # a.sort()\n # if x>a[-1]:\n # print(-1)\n # continue\n l,h=-1,9999999999\n for _ in range(n):\n # if a[_]>=x:\n # if _==n-1:\n # print(-1)\n # break\n # elif _==0:\n # print(-1)\n # break\n # else:\n # print(a[_-1],a[_])\n # break\n if a[_]>l and a[_]x :\n h=a[_]\n print(l,end=\" \")\n if h==9999999999:\n print(-1)\n else: \n print(h) \n \n \n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n10\\n5 15 1 66 55 32 40 22 34 11\\n38\\n', 'output': '35 41\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/ENDE2020/problems/ENCDEC5'}","problem_id":"vfc_2386","program":"```python\nfor _ in range(int(input())):\n n=int(input())\n a=list(map(int,input().split()))\n x=int(input())\n for _ in range(1,n,2):\n a[_],a[_-1]=a[_-1],a[_]\n for _ in range(n):\n a[_]+=(a[_]%3)\n # a=a[::-1]\n # a.sort()\n # if x>a[-1]:\n # print(-1)\n # continue\n l,h=-1,9999999999\n for _ in range(n):\n # if a[_]>=x:\n # if _==n-1:\n # print(-1)\n # break\n # elif _==0:\n # print(-1)\n # break\n # else:\n # print(a[_-1],a[_])\n # break\n if a[_]>l and a[_]x :\n h=a[_]\n print(l,end=\" \")\n if h==9999999999:\n print(-1)\n else: \n print(h) \n \n \n```","inputs":"1\n10\n5 15 1 66 55 32 40 22 34 11\n38\n","output":"35 41\n","actual_output":"35 41\n","execution_success":true,"sample_index":490},{"source":"apps","task_type":"verifiable_code","in_source_id":"887","prompt":"Solve the following coding problem using the programming language python:\n\nArya and Aryan live in a country called Nadaca. Nadaca consists of $N$ cities numbered $1$ through $N$, which are connected by some bidirectional roads. Each road has a positive (not necessarily integer) length. Arya lives in city $1$ and Aryan lives in city $N$.\nArya claims that for each city $v$, the shortest path from city $1$ to city $v$ has length $a_v$. Aryan does not disagree, but claims that for each city $v$, the shortest path from city $N$ to city $v$ has length $b_v$. You are the wisest person they know, so they asked you to tell them if it is possible for their claims to be true, i.e. if a road network which fully satisfies their claims exists. Help them!\n\n-----Input-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The first line of each test case contains a single integer $N$.\n- The second line contains $N$ space-separated integers $a_1, a_2, \\ldots, a_N$.\n- The third line contains $N$ space-separated integers $b_1, b_2, \\ldots, b_N$.\n\n-----Output-----\nFor each test case, print a single line containing the string \"Yes\" if Arya's and Aryan's claims can be true or \"No\" otherwise.\n\n-----Constraints-----\n- $1 \\le T \\le 10^3$\n- $2 \\le N \\le 10^6$\n- $0 \\le a_i, b_i \\le 10^9$ for each valid $i$\n- the sum of $N$ over all test cases does not exceed $10^6$\n\n-----Subtasks-----\nSubtask #1 (50 points): the sum of $N$ over all test cases does not exceed $10^3$\nSubtask #2 (50 points): original constraints\n\n-----Example Input-----\n2\n3\n0 1 1\n1 1 0\n3\n0 1 5\n5 1 0\n\n-----Example Output-----\nYes\nNo\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\n# cook your dish here\nfor _ in range(int(input())):\n n=int(input())\n a=list(map(int, input().split()))\n b=list(map(int, input().split()))\n\n if a[0]!=0 or b[-1]!=0 or a[-1]!=b[0]:\n print('No')\n \n else:\n ab=b[0]\n flag=0\n for i in range(1, n-1):\n if a[i]==0 or b[i]==0:\n print('No')\n flag=1 \n break\n \n elif a[i]+b[i]ab+b[i] or b[i]>ab+a[i]:\n print('No')\n flag=1 \n break\n \n if flag==0:\n print('Yes')\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n3\\n0 1 1\\n1 1 0\\n3\\n0 1 5\\n5 1 0\\n', 'output': 'Yes\\nNo\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/DIS'}","problem_id":"vfc_2390","program":"```python\n# cook your dish here\n# cook your dish here\nfor _ in range(int(input())):\n n=int(input())\n a=list(map(int, input().split()))\n b=list(map(int, input().split()))\n\n if a[0]!=0 or b[-1]!=0 or a[-1]!=b[0]:\n print('No')\n \n else:\n ab=b[0]\n flag=0\n for i in range(1, n-1):\n if a[i]==0 or b[i]==0:\n print('No')\n flag=1 \n break\n \n elif a[i]+b[i]ab+b[i] or b[i]>ab+a[i]:\n print('No')\n flag=1 \n break\n \n if flag==0:\n print('Yes')\n```","inputs":"2\n3\n0 1 1\n1 1 0\n3\n0 1 5\n5 1 0\n","output":"Yes\nNo\n","actual_output":"Yes\nNo\n","execution_success":true,"sample_index":491},{"source":"apps","task_type":"verifiable_code","in_source_id":"888","prompt":"Solve the following coding problem using the programming language python:\n\nCherry has a string S$S$ consisting of lowercase English letters. Using this string, he formed a pyramid of infinite length with certain rules:\n- N$N$-th row of pyramid contains N$N$ characters.\n- Each row of pyramid begins with the first character of the string.\n- The subsequent characters of the row are appended to the string in cyclic fashion, until the size of string for that Row is reached (See example pyramid for better understanding).\nHe has another string T$T$ of smaller (or equal) size.\nYou are asked Q$Q$ queries. Each query is provided with a row number N$N$. The answer to the query is number of occurrences of string T$T$ in that particular row of pyramid. No of occurrences of String T$T$ in a string V$V$ would mean that you'd need to find number of substrings Vi,Vi+1...Vj$V_i, V_{i+1} ... V_j$ which are equal to String T$T$, where i\u2264j$i \\leq j$.\nFor eg: If the string is code, then the pyramid will be of the form:\nc\nco\ncod\ncode\ncodec\ncodeco\ncodecod\ncodecode\ncodecodec\ncodecodeco\n...\n\n-----Input:-----\n- The first line contains string S$S$ \u2014 consisting of lowercase English letters.\n- The second line contains string T$T$ \u2014 consisting of lowercase English letters.\n- Next line contains an integer Q$Q$ \u2014 the number of queries.\n- Then follow Q$Q$ lines with queries descriptions. Each of them contains a single integer N$N$ denoting the row number of pyramid.\n\n-----Output:-----\n- Print Q$Q$ lines. The i$i$-th of them should contain a integer denoting occurrences of string T$T$ in that particular row.\n\n-----Constraints-----\n- 1\u2264|S|\u2264105$1 \\leq |S| \\leq 10^5$\n- 1\u2264|T|\u2264|S|$1 \\leq |T| \\leq |S|$\n- 1\u2264Q\u2264105$1 \\leq Q \\leq 10^5$\n- 1\u2264N\u2264109$1 \\leq N \\leq 10^9$\n\n-----Sample Input:-----\ncodechef\nchefcode\n3\n4\n12\n1455\n\n-----Sample Output:-----\n0\n1\n181\n\n-----Explanation:-----\nPyramid will be formed as explained in the statement.\nQuery 1: Row number 4 of the pyramid is code. The number of occurrences of chefcode in code is 0.\nQuery 2: Row number 12 of the pyramid is codechefcode. The number of occurrences of chefcode in codechefcode is 1.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\ndef search(arr, lenl, val):\r\n s = 0\r\n l = lenl - 1\r\n\r\n total = 0\r\n\r\n while (s <= l):\r\n m = int((s + l) / 2)\r\n\r\n if (arr[m] <= val):\r\n total = m + 1\r\n s = m + 1\r\n\r\n else:\r\n l = m - 1\r\n\r\n return total\r\n\r\n\r\ndef kmpsearch(string, lps):\r\n lis = []\r\n lens = len(string)\r\n lensh = lens // 2\r\n\r\n l = 0\r\n i = 0\r\n while i < lens:\r\n if string[i] == pat[l]:\r\n l += 1\r\n i += 1\r\n elif l > 0:\r\n l = lps[l - 1]\r\n else:\r\n i += 1\r\n\r\n if l == lenp:\r\n if i - l < lensh:\r\n lis.append(i - l)\r\n\r\n l = lps[l - 1]\r\n\r\n return lis\r\n\r\n\r\ndef kmp(pat, lenp):\r\n\r\n lps = [0]*(lenp)\r\n l = 0\r\n i = 1\r\n\r\n while i < lenp:\r\n if pat[i] == pat[l]:\r\n l += 1\r\n lps[i] = l\r\n i += 1\r\n elif l > 0:\r\n l = lps[l-1]\r\n else:\r\n lps[i] = 0\r\n i += 1\r\n\r\n return lps\r\n\r\n\r\n\r\nkeyword = input()\r\npat = input()\r\nq = int(input())\r\n\r\nlenk = len(keyword)\r\nlenp = len(pat)\r\n\r\nk = keyword * 2\r\nlis = kmpsearch(k, kmp(pat, lenp))\r\nlenl = len(lis)\r\n\r\nfor _ in range(q):\r\n n = int(input())\r\n count = 0\r\n\r\n q = n // lenk\r\n r = n % lenk\r\n\r\n count += search(lis, lenl, r - lenp)\r\n\r\n if q >= 1:\r\n count += search(lis, lenl, lenk + r - lenp)\r\n\r\n if q >= 2:\r\n count += (q - 1)*lenl\r\n\r\n print(count)\r\n \r\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': 'codechef\\nchefcode\\n3\\n4\\n12\\n1455\\n', 'output': '0\\n1\\n181\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/CENS20C'}","problem_id":"vfc_2394","program":"```python\ndef search(arr, lenl, val):\r\n s = 0\r\n l = lenl - 1\r\n\r\n total = 0\r\n\r\n while (s <= l):\r\n m = int((s + l) / 2)\r\n\r\n if (arr[m] <= val):\r\n total = m + 1\r\n s = m + 1\r\n\r\n else:\r\n l = m - 1\r\n\r\n return total\r\n\r\n\r\ndef kmpsearch(string, lps):\r\n lis = []\r\n lens = len(string)\r\n lensh = lens // 2\r\n\r\n l = 0\r\n i = 0\r\n while i < lens:\r\n if string[i] == pat[l]:\r\n l += 1\r\n i += 1\r\n elif l > 0:\r\n l = lps[l - 1]\r\n else:\r\n i += 1\r\n\r\n if l == lenp:\r\n if i - l < lensh:\r\n lis.append(i - l)\r\n\r\n l = lps[l - 1]\r\n\r\n return lis\r\n\r\n\r\ndef kmp(pat, lenp):\r\n\r\n lps = [0]*(lenp)\r\n l = 0\r\n i = 1\r\n\r\n while i < lenp:\r\n if pat[i] == pat[l]:\r\n l += 1\r\n lps[i] = l\r\n i += 1\r\n elif l > 0:\r\n l = lps[l-1]\r\n else:\r\n lps[i] = 0\r\n i += 1\r\n\r\n return lps\r\n\r\n\r\n\r\nkeyword = input()\r\npat = input()\r\nq = int(input())\r\n\r\nlenk = len(keyword)\r\nlenp = len(pat)\r\n\r\nk = keyword * 2\r\nlis = kmpsearch(k, kmp(pat, lenp))\r\nlenl = len(lis)\r\n\r\nfor _ in range(q):\r\n n = int(input())\r\n count = 0\r\n\r\n q = n // lenk\r\n r = n % lenk\r\n\r\n count += search(lis, lenl, r - lenp)\r\n\r\n if q >= 1:\r\n count += search(lis, lenl, lenk + r - lenp)\r\n\r\n if q >= 2:\r\n count += (q - 1)*lenl\r\n\r\n print(count)\r\n \r\n\n```","inputs":"codechef\nchefcode\n3\n4\n12\n1455\n","output":"0\n1\n181\n","actual_output":"0\n1\n181\n","execution_success":true,"sample_index":492},{"source":"apps","task_type":"verifiable_code","in_source_id":"889","prompt":"Solve the following coding problem using the programming language python:\n\nChef is a brilliant university student that does not attend lectures because he believes that they are boring and coding is life! However, his university follows certain rules and regulations, and a student may only take an exam for a course if he has attended at least 75% of lectures for this course.\nSince you are Chef's best friend, you want to help him reach the attendance he needs to take exams. Unfortunately, Chef is still focused on his code and refuses to attend more lectures, so the only option is to have some of his friends mark him as present by proxy. This trick is well-known in the university, but only few have the talent to pull it off.\nIn a certain course, there is exactly one lesson per day over the course of $D$ days (numbered $1$ through $D$). You are given a string $S$ with length $D$ describing the lessons Chef attended \u2014 for each valid $i$, the $i$-th character of this string is either 'A' if Chef was absent on day $i$ or 'P' if Chef was actually present on day $i$.\nFor each day $d$ when Chef is absent, one of Chef's friends can mark him as present by proxy on this day only if he was present (if he was really present, not just marked as present) on at least one of the previous two days, i.e. days $d-1$ and $d-2$, and on at least one of the following two days, i.e. days $d+1$ and $d+2$. However, it is impossible to mark him as present by proxy on the first two days and the last two days.\nFind the minimum number of times Chef has to be marked as present by proxy so that his attendance becomes at least 75% ($0.75$). Chef's attendance is number of days when he was marked as present, either by proxy or by actually being present, divided by $D$.\n\n-----Input-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The first line of each test case contains a single integer $D$.\n- The second line contains a single string $S$ with length $D$.\n\n-----Output-----\nFor each test case, print a single line containing one integer \u2014 the minimum number of times Chef needs to be marked as present by proxy, or $-1$ if it is impossible to make Chef achieve 75% attendance.\n\n-----Constraints-----\n- $1 \\le T \\le 200$\n- $1 \\le D \\le 1,000$\n- $S$ contains only characters 'A' and 'P'\n\n-----Subtasks-----\nSubtask #1 (100 points): original constraints\n\n-----Example Input-----\n1\n9\nPAAPPAPPP\n\n-----Example Output-----\n1\n\n-----Explanation-----\nExample case 1: With a proxy on the third day, the attendance string is \"PAPPPAPPP\". Now, Chef's attendance is at least 75%, so the minimum number of times Chef needs to be marked as present by proxy is $1$.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\ndef ceil(num):\n if num%1==0:\n return int(num//1)\n else:\n return int((num//1)+1)\n \nfor _ in range(int(input())):\n n=int(input())\n s=input()\n p=0\n a=[]\n for i in range(n):\n if s[i]==\"P\":\n p=p+1\n req=ceil(0.75*n)\n requirement=req-p\n for i in range(2,n-2):\n if s[i]==\"A\":\n if (s[i-1]==\"P\" or s[i-2]==\"P\") and (s[i+1]==\"P\" or s[i+2]==\"P\"):\n a.append(i)\n if requirement>len(a):\n print(-1)\n else:\n print(max(requirement,0))\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n9\\nPAAPPAPPP\\n', 'output': '1\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/PROXYC'}","problem_id":"vfc_2398","program":"```python\n# cook your dish here\ndef ceil(num):\n if num%1==0:\n return int(num//1)\n else:\n return int((num//1)+1)\n \nfor _ in range(int(input())):\n n=int(input())\n s=input()\n p=0\n a=[]\n for i in range(n):\n if s[i]==\"P\":\n p=p+1\n req=ceil(0.75*n)\n requirement=req-p\n for i in range(2,n-2):\n if s[i]==\"A\":\n if (s[i-1]==\"P\" or s[i-2]==\"P\") and (s[i+1]==\"P\" or s[i+2]==\"P\"):\n a.append(i)\n if requirement>len(a):\n print(-1)\n else:\n print(max(requirement,0))\n```","inputs":"1\n9\nPAAPPAPPP\n","output":"1\n","actual_output":"1\n","execution_success":true,"sample_index":493},{"source":"apps","task_type":"verifiable_code","in_source_id":"890","prompt":"Solve the following coding problem using the programming language python:\n\nSnakeland is a well organised city. The houses of the city are organised in an orderly rectangular fashion with dimensions 2 * n, i.e. there are total two rows and n columns. The house in the i-th row and j-th column is also said to be the house at coordinates (i, j). Some of the houses are occupied by snakes, while the others are empty. You are given this information through an array s of dimension 2 * n, where, if s[i][j] = '*', it denotes that there is a snake in the house at coordinates (i, j), and if s[i][j] = '.', it denotes that the house is empty. \nThese snakes are planning a coup against a mongoose who controls their city from outside. So, they are trying their best to meet with other snakes and spread information about the date of the coup. For spreading this information, they can just hiss from their house and usually their hiss is so loud that it will be heard in all the cells except if there is a soundproof fence built that cuts the voice. Note that the external borders of Snakeland are already built of soundproof material. The mongoose got to know about the plan, and he wants to construct sound proof fences along the borders of the houses so that no two people should be able to communicate with each other. The fence can be either vertical or horizontal. Each fence can be of any length, but the mongoose wants to minimize the number of fences to be built. Find out the minimum number of fences that the mongoose should build.\n\n-----Input-----\nThe first line of the input contains an integer T denoting number of test cases. The descriptions of the T test cases follow.\nThe first line of each test case contains a single integer, n.\nEach of the next two lines contains n characters denoting the first and the second rows of Snakeland respectively.\n\n-----Output-----\nFor each test case, output a single integer corresponding to the minimum number of fences that the mongoose needs to build.\n\n-----Constraints-----\n- 1 \u2264 T \u2264 10\n- 1 \u2264 n \u2264 105\n\n-----Example-----\nInput\n3\n2\n**\n**\n3\n***\n*..\n3\n*..\n.*.\n\nOutput\n2\n3\n1\n\n-----Explanation-----\nAll the examples are shown in the pictures. The fences built are shown by red colored horizontal or vertical segments. You can see that after putting these borders no snake can talk with any another snake.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\nt=int(input())\nwhile t:\n n=int(input())\n r1=input()\n r2=input()\n r1count=0\n r2count=0\n count=0\n for i in range(n):\n if(r1[i]==\"*\"):\n r1count+=1\n if(r2[i]==\"*\"):\n r2count+=1\n if(r1count>0) and (r2count>0):\n count=1\n r1count=0\n r2count=0\n i=0\n while(i1) or (r2count>1):\n count+=1\n r1count=0\n r2count=0\n i-=1\n i+=1\n elif(r1count==0 and r2count>0) or (r2count==0 and r1count>0):\n count=max(r1count,r2count)-1\n else:\n count=0\n print(count)\n t-=1\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\n2\\n**\\n**\\n3\\n***\\n*..\\n3\\n*..\\n.*.\\n', 'output': '2\\n3\\n1\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/SNCOUP'}","problem_id":"vfc_2402","program":"```python\n# cook your dish here\nt=int(input())\nwhile t:\n n=int(input())\n r1=input()\n r2=input()\n r1count=0\n r2count=0\n count=0\n for i in range(n):\n if(r1[i]==\"*\"):\n r1count+=1\n if(r2[i]==\"*\"):\n r2count+=1\n if(r1count>0) and (r2count>0):\n count=1\n r1count=0\n r2count=0\n i=0\n while(i1) or (r2count>1):\n count+=1\n r1count=0\n r2count=0\n i-=1\n i+=1\n elif(r1count==0 and r2count>0) or (r2count==0 and r1count>0):\n count=max(r1count,r2count)-1\n else:\n count=0\n print(count)\n t-=1\n```","inputs":"3\n2\n**\n**\n3\n***\n*..\n3\n*..\n.*.\n","output":"2\n3\n1\n","actual_output":"2\n3\n1\n","execution_success":true,"sample_index":494},{"source":"apps","task_type":"verifiable_code","in_source_id":"891","prompt":"Solve the following coding problem using the programming language python:\n\nAndrii is good in Math, but not in Programming. He is asking you to solve following problem: Given an integer number N and two sets of integer A and B. Let set A contain all numbers from 1 to N and set B contain all numbers from N + 1 to 2N. Multiset C contains all sums a + b such that a belongs to A and b belongs to B. Note that multiset may contain several elements with the same values. For example, if N equals to three, then A = {1, 2, 3}, B = {4, 5, 6} and C = {5, 6, 6, 7, 7, 7, 8, 8, 9}. Andrii has M queries about multiset C. Every query is defined by a single integer q. Andrii wants to know the number of times q is contained in C. For example, number 6 is contained two times, 1 is not contained in C at all. \n\nPlease, help Andrii to answer all the queries.\n\n-----Input-----\n\nThe first line of the input contains two integers N and M. Each of the next M line contains one integer q, the query asked by Andrii.\n\n-----Output-----\nOutput the answer for each query in separate lines as in example.\n\n-----Constraints-----\n- 1 \u2264 N \u2264 109\n- 1 \u2264 M \u2264 105\n- 1 \u2264 q \u2264 3N\n\n-----Example-----\nInput:\n3 5\n6\n2\n9\n7\n5\nOutput:\n2\n0\n1\n3\n1\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\nimport math;\nfrom math import gcd,sqrt,floor,factorial,ceil\nfrom bisect import bisect_left,bisect_right\nimport bisect;\nimport sys;\nfrom sys import stdin,stdout\nimport os\nsys.setrecursionlimit(pow(10,7))\nimport collections\nfrom collections import defaultdict,Counter\nfrom statistics import median\n# input=stdin.readline\n# print=stdout.write\nfrom queue import Queue\ninf = float(\"inf\")\nfrom operator import neg;\nn,m=map(int,input().split())\nfor i in range(m):\n k=int(input())\n print(max(0,min(k-n-1,3*n+1-k)))\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3 5\\n6\\n2\\n9\\n7\\n5\\n\\n', 'output': '2\\n0\\n1\\n3\\n1\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/RRSUM'}","problem_id":"vfc_2406","program":"```python\n# cook your dish here\nimport math;\nfrom math import gcd,sqrt,floor,factorial,ceil\nfrom bisect import bisect_left,bisect_right\nimport bisect;\nimport sys;\nfrom sys import stdin,stdout\nimport os\nsys.setrecursionlimit(pow(10,7))\nimport collections\nfrom collections import defaultdict,Counter\nfrom statistics import median\n# input=stdin.readline\n# print=stdout.write\nfrom queue import Queue\ninf = float(\"inf\")\nfrom operator import neg;\nn,m=map(int,input().split())\nfor i in range(m):\n k=int(input())\n print(max(0,min(k-n-1,3*n+1-k)))\n\n```","inputs":"3 5\n6\n2\n9\n7\n5\n\n","output":"2\n0\n1\n3\n1\n","actual_output":"2\n0\n1\n3\n1\n","execution_success":true,"sample_index":495},{"source":"apps","task_type":"verifiable_code","in_source_id":"892","prompt":"Solve the following coding problem using the programming language python:\n\nThere are $N$ cells numbered 1,2,\u2026.., N, and every cell has some positive value. you will be given an array $A_1$,$A_2$,\u2026,$A_N$ where $A_i$ is the value of $ith$ cell and an integer $K$.\nThere is a monkey who wants to reach the $right$ side of the last ($Nth$) cell, initially, the monkey was left side of the first ($1st$) cell. \nIn the first step, he can jump into any cell numbered 1,2,\u2026.., K.Once he jumped into any cell $i$ next he can only jump to the cell $j$ such that-\n- j>i\n- j-i <= K \n- A[i]%2 == A[j]%2\nYou have to find out what is the minimum number of steps required to reach the right side of the cell or In case it's not possible to reach the right side of the cell your answer should be $-1$.NOTE: As soon as monkey reach any cell whose distance from the last cell is less than K, then in the last step, he will jump out to the right side of the ($Nth$) cell.\n\n-----Input:-----\n- First-line will contain $T$, the number of test cases. Then the test cases follow. \n- The first line of each test case contains two space-separated integers $N$ and $K$.\n- The second line contains $N$ space-separated integers $A_1$,$A_2$,\u2026,$A_N$\n\n-----Output:-----\nFor each test case, output in a single line minimum steps or $-1$.\n\n-----Constraints-----\n- $1 \\leq T \\leq 100$\n- $1 \\leq N \\leq 2*10^5$\n- $1 \\leq K \\leq N$\n- $0 \\leq A_i \\leq 10^6$\n- $\\text{the sum of N over all test cases does not exceed $5*10^{5}$}$\n\n-----Sample Input:-----\n1\n2 2\n3 4\n\n-----Sample Output:-----\n2 \n\n-----EXPLANATION:-----\nin the first step, you can jump into any cell 1 or 2 and then in the second step you will jump \nout to the right side of 2nd cell\nremember we don't want to reach $Nth$ cell we want to reach the right side of the nth cell.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfrom sys import setrecursionlimit\r\nsetrecursionlimit(10 * 9)\r\n\r\ndef solve(i):\r\n if i + k >= n:\r\n return 1\r\n\r\n if i in dp:\r\n return dp[i]\r\n\r\n mini = float('inf')\r\n for j in range(i+1, min(n, i+k+1)):\r\n if i == -1 or a[i] == a[j]:\r\n mini = min(mini, solve(j) + 1)\r\n\r\n dp[i] = mini\r\n return dp[i]\r\n\r\n\r\nfor _ in range(int(input())):\r\n n, k = map(int, input().split())\r\n a = list(map(lambda x: int(x) % 2, input().split()))\r\n\r\n le = lo = -1\r\n se = so = -1\r\n\r\n for i in range(n-k, n):\r\n if a[i] == 0:\r\n le = i\r\n break\r\n\r\n for i in range(n-k, n):\r\n if a[i] == 1:\r\n lo = i\r\n break\r\n\r\n m1 = float('inf')\r\n if le != -1:\r\n m1 = 0\r\n while True:\r\n lle = -1\r\n\r\n for i in range(se + 1, se + k + 1):\r\n if i == le:\r\n m1 += 2\r\n break\r\n\r\n if a[i] == 0:\r\n lle = i\r\n\r\n else:\r\n if lle == -1:\r\n m1 = float('inf')\r\n break\r\n\r\n se = lle\r\n m1 += 1\r\n continue\r\n\r\n break\r\n\r\n m2 = float('inf')\r\n if lo != -1:\r\n m2 = 0\r\n while True:\r\n llo = -1\r\n\r\n for i in range(so + 1, so + k + 1):\r\n if i == lo:\r\n m2 += 2\r\n break\r\n\r\n if a[i] == 1:\r\n llo = i\r\n\r\n else:\r\n if llo == -1:\r\n m2 = float('inf')\r\n break\r\n\r\n so = llo\r\n m2 += 1\r\n continue\r\n\r\n break\r\n\r\n if min(m1, m2) != float('inf'):\r\n print(min(m1, m2))\r\n else:\r\n print(-1)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n2 2\\n3 4\\n', 'output': '2\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/BIT32020/problems/BIT3D'}","problem_id":"vfc_2410","program":"```python\nfrom sys import setrecursionlimit\r\nsetrecursionlimit(10 * 9)\r\n\r\ndef solve(i):\r\n if i + k >= n:\r\n return 1\r\n\r\n if i in dp:\r\n return dp[i]\r\n\r\n mini = float('inf')\r\n for j in range(i+1, min(n, i+k+1)):\r\n if i == -1 or a[i] == a[j]:\r\n mini = min(mini, solve(j) + 1)\r\n\r\n dp[i] = mini\r\n return dp[i]\r\n\r\n\r\nfor _ in range(int(input())):\r\n n, k = map(int, input().split())\r\n a = list(map(lambda x: int(x) % 2, input().split()))\r\n\r\n le = lo = -1\r\n se = so = -1\r\n\r\n for i in range(n-k, n):\r\n if a[i] == 0:\r\n le = i\r\n break\r\n\r\n for i in range(n-k, n):\r\n if a[i] == 1:\r\n lo = i\r\n break\r\n\r\n m1 = float('inf')\r\n if le != -1:\r\n m1 = 0\r\n while True:\r\n lle = -1\r\n\r\n for i in range(se + 1, se + k + 1):\r\n if i == le:\r\n m1 += 2\r\n break\r\n\r\n if a[i] == 0:\r\n lle = i\r\n\r\n else:\r\n if lle == -1:\r\n m1 = float('inf')\r\n break\r\n\r\n se = lle\r\n m1 += 1\r\n continue\r\n\r\n break\r\n\r\n m2 = float('inf')\r\n if lo != -1:\r\n m2 = 0\r\n while True:\r\n llo = -1\r\n\r\n for i in range(so + 1, so + k + 1):\r\n if i == lo:\r\n m2 += 2\r\n break\r\n\r\n if a[i] == 1:\r\n llo = i\r\n\r\n else:\r\n if llo == -1:\r\n m2 = float('inf')\r\n break\r\n\r\n so = llo\r\n m2 += 1\r\n continue\r\n\r\n break\r\n\r\n if min(m1, m2) != float('inf'):\r\n print(min(m1, m2))\r\n else:\r\n print(-1)\n```","inputs":"1\n2 2\n3 4\n","output":"2\n","actual_output":"2\n","execution_success":true,"sample_index":496},{"source":"apps","task_type":"verifiable_code","in_source_id":"895","prompt":"Solve the following coding problem using the programming language python:\n\nZonal Computing Olympiad 2012, 26 Nov 2011\n\nIt's dinner time in Castle Camelot, and the fearsome Knights of the Round Table are clamouring for dessert. You, the chef, are in a soup. There are N knights, including King Arthur, each with a different preference for dessert, but you cannot afford to make desserts for all of them.\n\nYou are given the cost of manufacturing each Knight's preferred dessert\u2013since it is a round table, the list starts with the cost of King Arthur's dessert, and goes counter-clockwise.\n\nYou decide to pick the cheapest desserts to make, such that for every pair of adjacent Knights, at least one gets his dessert. This will ensure that the Knights do not protest.

A strange feature of the Knights is that they will not complain about not getting dessert unless they get support from both their neighbours. So, you decide to pick the cheapest desserts to make, such that for every pair of adjacent Knights, at least one gets his dessert.

\n\nWhat is the minimum cost of tonight's dinner, given this condition?\n\nFor instance, suppose there are 5 Knights and their desserts cost 1, 2, 1, 2 and 2. In this case, the minimum cost is 4, which you can achieve by feeding the first, third and fourth (or fifth) Knights. \n\n-----Input format-----\nThere are 2 lines of input. The first line contains a single integer N, the number of seats at the table. The next line contains N space separated integers, each being the cost of the dessert of a Knight, listed in counterclockwise order around the table, starting with King Arthur.\n\n-----Output format-----\nThe output should be a single line containing a single integer, the minimum possible cost for you, the chef.\n\n-----Testdata-----\nEach Knight's dessert costs strictly more than 0 and strictly less than 1000. You may assume that 1 \u2264 N \u2264 106. In 30% of the test cases, 1 \u2264 N \u2264 103.\n\n- Subtask 1 (30 marks)\n- Subtask 2 (70 marks)\n\n-----Sample Input-----\n5\n1 2 1 2 2\n\n-----Sample Output-----\n4\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nn=int(input())\r\nar=list(map(int,input().split()))\r\ndp=[0]*n \r\ndp[0]=ar[0]\r\ndp[1]=ar[1]\r\nfor i in range(2,n):\r\n dp[i]=min(dp[i-2],dp[i-1])+ar[i]\r\n \r\nar.reverse()\r\n#print(ar)\r\ndp1=[0]*n \r\ndp1[0]=ar[0]\r\ndp1[1]=ar[1]\r\nfor i in range(2,n):\r\n dp1[i]=min(dp1[i-2],dp1[i-1])+ar[i]\r\nprint(min(dp[-1],dp1[-1]))\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '5\\n1 2 1 2 2\\n', 'output': '4\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/ZCOPRAC/problems/ZCO12004'}","problem_id":"vfc_2422","program":"```python\nn=int(input())\r\nar=list(map(int,input().split()))\r\ndp=[0]*n \r\ndp[0]=ar[0]\r\ndp[1]=ar[1]\r\nfor i in range(2,n):\r\n dp[i]=min(dp[i-2],dp[i-1])+ar[i]\r\n \r\nar.reverse()\r\n#print(ar)\r\ndp1=[0]*n \r\ndp1[0]=ar[0]\r\ndp1[1]=ar[1]\r\nfor i in range(2,n):\r\n dp1[i]=min(dp1[i-2],dp1[i-1])+ar[i]\r\nprint(min(dp[-1],dp1[-1]))\n```","inputs":"5\n1 2 1 2 2\n","output":"4\n","actual_output":"4\n","execution_success":true,"sample_index":499},{"source":"apps","task_type":"verifiable_code","in_source_id":"897","prompt":"Solve the following coding problem using the programming language python:\n\nChef had an array A with length N, but some of its elements got lost. Now, each element of this array is either unknown (denoted by -1) or a positive integer not exceeding K.\nChef decided to restore the array A by replacing each unknown element by a positive integer not exceeding K.\nHowever, Chef has M restrictions that must hold for the restored array. There are two types of restrictions:\n\n- I L R, meaning that for each i such that L < i \u2264 R, the condition Ai - Ai-1 = 1 should be satisfied.\n- D L R, meaning that for each i such that L < i \u2264 R, the condition Ai - Ai-1 = -1 should be satisfied.\n\nChef would like to know the number of ways to restore the array while satisfying all restrictions, modulo 109+7.\n\n-----Input-----\n- The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows.\n- The first line of each test case contains three space-separated integers N, M and K.\n- The second line contains N integers A1, A2, ..., AN.\n- Each of the following M lines contains one restriction in the form I L R or D L R.\n\n-----Output-----\nFor each test case, print a single line containing one integer - the number of ways to restore the array modulo 109+7.\n\n-----Constraints-----\n- 1 \u2264 T \u2264 10\n- 1 \u2264 N, M \u2264 100,000\n- 1 \u2264 K \u2264 1,000,000,000\n- 1 \u2264 L < R \u2264 N\n- 1 \u2264 Ai \u2264 K or Ai = -1 for each valid i\n- 1 \u2264 sum of N over all test cases \u2264 500,000\n- 1 \u2264 sum of M over all test cases \u2264 500,000\n\n-----Example-----\nInput:\n\n3\n4 2 10\n2 3 5 4\nI 1 2 \nD 3 4\n5 2 10\n-1 -1 -1 -1 -1\nI 1 3\nD 3 5\n6 2 2\n-1 -1 -1 -1 -1 -1\nI 1 4\nD 4 6\n\nOutput:\n\n1\n8\n0\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\n# cook your dish here\nMOD = 10 ** 9 + 7\n \nfor t in range(int(input())):\n N, M, K = map(int, input().split())\n A = list(map(int, input().split()))\n I, D = [0] * (N + 2), [0] * (N + 2)\n for i in range(M):\n x, L, R = input().split()\n L, R = int(L), int(R)\n if x == 'I':\n I[L] += 1\n I[R] -= 1\n else:\n D[L] += 1\n D[R] -= 1\n \n impossibru = mx = mn = 0\n ans = 1\n for i in range(N):\n I[i] += I[i - 1]\n D[i] += D[i - 1]\n if I[i] and D[i]:\n impossibru = 1\n break\n if not I[i] and not D[i]:\n ans = ans * (mx - mn + 1) % MOD\n mn, mx = 1, K\n elif I[i]:\n mx = min(mx + 1, K)\n mn += 1\n elif D[i]:\n mn = max(1, mn - 1)\n mx -= 1\n if mn > mx:\n impossibru = 1\n break\n if A[i] != -1:\n if not mn <= A[i] <= mx:\n impossibru = 1\n break\n mn = mx = A[i]\n ans = ans * (mx - mn + 1) % MOD\n \n print(0 if impossibru else ans) \n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\n4 2 10\\n2 3 5 4\\nI 1 2\\nD 3 4\\n5 2 10\\n-1 -1 -1 -1 -1\\nI 1 3\\nD 3 5\\n6 2 2\\n-1 -1 -1 -1 -1 -1\\nI 1 4\\nD 4 6\\n', 'output': '1\\n8\\n0\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/CO92REST'}","problem_id":"vfc_2430","program":"```python\n# cook your dish here\n# cook your dish here\nMOD = 10 ** 9 + 7\n \nfor t in range(int(input())):\n N, M, K = map(int, input().split())\n A = list(map(int, input().split()))\n I, D = [0] * (N + 2), [0] * (N + 2)\n for i in range(M):\n x, L, R = input().split()\n L, R = int(L), int(R)\n if x == 'I':\n I[L] += 1\n I[R] -= 1\n else:\n D[L] += 1\n D[R] -= 1\n \n impossibru = mx = mn = 0\n ans = 1\n for i in range(N):\n I[i] += I[i - 1]\n D[i] += D[i - 1]\n if I[i] and D[i]:\n impossibru = 1\n break\n if not I[i] and not D[i]:\n ans = ans * (mx - mn + 1) % MOD\n mn, mx = 1, K\n elif I[i]:\n mx = min(mx + 1, K)\n mn += 1\n elif D[i]:\n mn = max(1, mn - 1)\n mx -= 1\n if mn > mx:\n impossibru = 1\n break\n if A[i] != -1:\n if not mn <= A[i] <= mx:\n impossibru = 1\n break\n mn = mx = A[i]\n ans = ans * (mx - mn + 1) % MOD\n \n print(0 if impossibru else ans) \n```","inputs":"3\n4 2 10\n2 3 5 4\nI 1 2\nD 3 4\n5 2 10\n-1 -1 -1 -1 -1\nI 1 3\nD 3 5\n6 2 2\n-1 -1 -1 -1 -1 -1\nI 1 4\nD 4 6\n","output":"1\n8\n0\n","actual_output":"1\n8\n0\n","execution_success":true,"sample_index":501},{"source":"apps","task_type":"verifiable_code","in_source_id":"898","prompt":"Solve the following coding problem using the programming language python:\n\nNote : This question carries $150$ $points$\nThere is an outcry in Middle Earth, as the greatest war between Orgs of Dark Lord Sauron and Frodo Baggins is about to begin. To end the war, Frodo decides to destroy the ring in the volcano of Mordor. There are many ships that lead Frodo to Mordor, and he is confused about which one he should board. Given two-ship numbers $M$ and $N$, Frodo has to solve a problem to find the ship which he should board.\nFind the number of pairs (x, y), such that $1<=x<=M$ and $1<=y<=N$, for which $x*y + x+ y = string(x)+string(y)$ is true. \nAlso, calculate the number of distinct x satisfying the given condition. The number of pairs and the number of distinct x will help select Frodo the boat he should board. Help Frodo defeat Sauron. \n\n-----Input :-----\n- First line contains $T$ as number of test cases \n- Each test case contains two integers $M$ and $N$ \n\n-----Output :-----\n- For each test case, print two integers - the number of such pairs (x,y) and the number of distinct x\n\n-----Constraints :-----\n- 1 \u2264 T \u2264 5000\n- 1 \u2264 M, N \u2264 10^9\n\n-----Sample Input :-----\n1\n1 9\n\n-----Sample Output :-----\n1 1\n\n-----Explanation :-----\nFor test case two M=1 and N=9 Pair (1,9) satisfies the above condition 1*9+1+9= \u201c19\u201d and only x=1 satisfies the equation.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\nfrom math import pow\nt = int(input())\nfor _ in range(t):\n m,n = map(int,input().rstrip().split())\n cnt = len(str(n))\n x = pow(10,cnt)\n if n == x-1:\n print(m*cnt,m)\n else:\n print(m*(cnt-1),m)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n1 9\\n', 'output': '1 1\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/PCO12020/problems/LOTR1'}","problem_id":"vfc_2434","program":"```python\n# cook your dish here\nfrom math import pow\nt = int(input())\nfor _ in range(t):\n m,n = map(int,input().rstrip().split())\n cnt = len(str(n))\n x = pow(10,cnt)\n if n == x-1:\n print(m*cnt,m)\n else:\n print(m*(cnt-1),m)\n```","inputs":"1\n1 9\n","output":"1 1\n","actual_output":"1 1\n","execution_success":true,"sample_index":502},{"source":"apps","task_type":"verifiable_code","in_source_id":"899","prompt":"Solve the following coding problem using the programming language python:\n\nChef wants to teach a lesson of sharing to the students.\nThere are $N$ students (numbered from $1$ to $N$ from left to right) who are asked to stand in a row. Initially Chef gave $A$$i$ candies to the $i$$th$ child. In one operation any child can give any number of candies to the child standing to his immediate left (i.e. $i$$th$ child can give any amount of candies to the $(i-1)$$th$ child. In particular 1st child cannot give his candies to anyone). \nHe asked them to minimize the maximum value of candies a student can possess after performing any number of operations (possibly zero). \nHelp the students finding such maximum value.\n\n-----Input:-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- First line of each test case contains a single integer $N$ denoting the number of students.\n- Second line contains $N$ space-separated integers $A$$1$,$A$$2$,$.....$ $A$$N$ denoting the initial amount of candies chef gave to them.\n\n-----Output:-----\n- For each test case, print a single line containing one integer \u2015 maximum value after sharing.\n\n-----Constraints-----\n- $1 \\leq T \\leq 100$\n- $1 \\leq N \\leq 10^5$\n- $0$ $\\leq$ $A$$i$ $\\leq$ $10^9$\n- Sum of $N$ over all Test Cases does not exceed $10^5$\n\n-----Sample Input-----\n2 \n5 \n1 2 3 4 5 \n5\n5 4 3 2 1\n\n-----Sample Output-----\n3 \n5 \n\n-----Explanation-----\n- \nFor First Test Case:\nThe $5$$th$ student will give $2$ candies to $4$$th$ student and $4$$th$ will give $3$ candies to $3$$rd$ and $3$$rd$ will give $3$ candies to $2$$nd$ and $2$$nd$ will give $2$ candies to $1$$st$. So finally the number of candies that they will have are \n$[3,3,3,3,3]$ and the value of maximum candies is $3$.\n- \nFor Second Test Case:\nSharing to the left student will not change the maximum value as $1$$st$ cannot share to anyone. So the maximum value will remain $5$.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfrom math import ceil\n\nfor _ in range(int(input())):\n n = int(input())\n arr = [int(x) for x in input().split()]\n sarr = sum(arr)\n mavg = sarr/n\n while n>1:\n sarr -= arr.pop()\n n-=1\n mavg = max(mavg, sarr/n)\n print(int(ceil(mavg)))\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n5\\n1 2 3 4 5\\n5\\n5 4 3 2 1\\n', 'output': '3\\n5\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/CROS2020/problems/COCR106'}","problem_id":"vfc_2438","program":"```python\nfrom math import ceil\n\nfor _ in range(int(input())):\n n = int(input())\n arr = [int(x) for x in input().split()]\n sarr = sum(arr)\n mavg = sarr/n\n while n>1:\n sarr -= arr.pop()\n n-=1\n mavg = max(mavg, sarr/n)\n print(int(ceil(mavg)))\n```","inputs":"2\n5\n1 2 3 4 5\n5\n5 4 3 2 1\n","output":"3\n5\n","actual_output":"3\n5\n","execution_success":true,"sample_index":503},{"source":"apps","task_type":"verifiable_code","in_source_id":"900","prompt":"Solve the following coding problem using the programming language python:\n\nOn her way to ChefLand, Marichka noticed $10^K$ road signs (numbered $0$ through $10^K - 1$). For each valid $i$, the sign with number $i$ had the integer $i$ written on one side and $10^K-i-1$ written on the other side.\nNow, Marichka is wondering \u2014 how many road signs have exactly two distinct decimal digits written on them (on both sides in total)? Since this number may be large, compute it modulo $10^9+7$.\nFor example, if $K = 3$, the two integers written on the road sign $363$ are $363$ and $636$, and they contain two distinct digits $3$ and $6$, but on the road sign $362$, there are integers $362$ and $637$, which contain four distinct digits \u2014 $2$, $3$, $6$ and $7$. On the road sign $11$, there are integers $11$ and $988$, which contain three distinct digits \u2014 $1$, $9$ and $8$.\n\n-----Input-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The first and only line of each test case contains a single integer $K$.\n\n-----Output-----\nFor each test case, print a single line containing one integer \u2014 the number of road signs with exactly two digits, modulo $10^9+7$.\n\n-----Constraints-----\n- $1 \\le T \\le 10^5$\n- $1 \\le K \\le 10^9$\n\n-----Subtasks-----\nSubtask #1 (20 points): $1 \\le T, K \\le 5$\nSubtask #2 (80 points): original constraints\n\n-----Example Input-----\n1\n1\n\n-----Example Output-----\n10\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nimport math\r\nt=int(input())\r\nfor i in range(t):\r\n k=int(input())\r\n res=((pow(2,k,1000000007))*5)%1000000007\r\n print(res)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n1\\n\\n', 'output': '10\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/RSIGNS'}","problem_id":"vfc_2442","program":"```python\nimport math\r\nt=int(input())\r\nfor i in range(t):\r\n k=int(input())\r\n res=((pow(2,k,1000000007))*5)%1000000007\r\n print(res)\n```","inputs":"1\n1\n\n","output":"10\n","actual_output":"10\n","execution_success":true,"sample_index":504},{"source":"apps","task_type":"verifiable_code","in_source_id":"902","prompt":"Solve the following coding problem using the programming language python:\n\nTweedle-Dee and Tweedle-Dum are playing a fierce match of binary Nim. This novel game is played with $N$ stacks, each of them containing only $1$-s and $0$-s.\nJust like in normal Nim, Tweedle-Dee and Tweedle-Dum alternate turns; in their turn, a player must choose one non-empty stack and remove a positive number of elements from the top of this stack. However, Tweedle-Dee may only choose a stack with $0$ at the top (and remove elements from it afterwards), and similarly, Tweedle-Dum may only choose a stack with $1$ at the top. the player that cannot make a move loses\nSuzumo does not want to wait for the end of the game, so given the starting player he asks you to determine the winner. Remember that Tweedle-Dee and Tweedle-Dum are legendary grandmasters of combinatorial games, so both always play optimally.\n\n-----Input-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The first line of each test case contains an integer $N$, a string $S$ denoting the number of stacks, the player that starts the game, respectively.\n- Each of the following $N$ lines contains a single binary string $B$ representing a stack; the first character of $B$ corresponds to the top element of the stack and the last character to the bottom element.\n\n-----Output-----\nFor each test case, print a single line containing the string \"Dee\" if Tweedle-Dee wins the match or \"Dum\" if Tweedle-Dum wins.\n\n-----Constraints-----\n- $1 \\le T \\le 500$\n- $1 \\le N \\le 50$\n- $1 \\le |B| \\le 50$\n- each character in $B$ is either '1' or '0'\n- $S$ is either \"Dee\" or \"Dum\"\n\n-----Example Input-----\n2\n2 Dee\n101\n010\n2 Dum\n101\n010\n\n-----Example Output-----\nDum\nDee\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfor u in range(int(input())):\n p=input().split()\n n=int(p[0])\n s=p[1]\n x,y=0,0\n for i in range(n):\n l=input()\n if(l[0]=='1'):\n y+=l.count('1')\n else:\n x+=l.count('0')\n if(xbattery[0]:\n \n power-=battery.pop(0)\n power+=temp[0]\n pos=bisect.bisect_right(battery, temp[0], lo=0, hi=len(battery))\n battery.insert(pos,temp[0])\n \n i+=1\n \n \n if power>=x:\n print('YES')\n else:\n print('NO')\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\n4 8\\n5 1 4 2\\n3 4\\n3 1 2\\n2 7\\n5 5\\n', 'output': 'YES\\nYES\\nNO\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/BATTERY'}","problem_id":"vfc_2458","program":"```python\n# cook your dish here\nimport bisect\nfor _ in range(int(input())):\n \n n,x=list(map(int,input().split()))\n \n l=list(map(int,input().split()))\n battery=[]\n \n power=0\n i=0\n t=(n+1)//2\n while powerbattery[0]:\n \n power-=battery.pop(0)\n power+=temp[0]\n pos=bisect.bisect_right(battery, temp[0], lo=0, hi=len(battery))\n battery.insert(pos,temp[0])\n \n i+=1\n \n \n if power>=x:\n print('YES')\n else:\n print('NO')\n\n```","inputs":"3\n4 8\n5 1 4 2\n3 4\n3 1 2\n2 7\n5 5\n","output":"YES\nYES\nNO\n","actual_output":"YES\nYES\nNO\n","execution_success":true,"sample_index":508},{"source":"apps","task_type":"verifiable_code","in_source_id":"905","prompt":"Solve the following coding problem using the programming language python:\n\nOnce upon a time, a king and a few of his soldiers were caught by an enemy king in a war. \n\nHe puts them in a circle. The first man in the circle has to kill the second man, the third man has to kill the fourth, fifth man to kill the sixth and so on. When the circle is completed, the remaining people have to form a circle and the process has to repeat. The last man standing will be set free.\n\nIf the king has to be set free, which position must he take? For any given N number of people, write a program to find the position that the king has to take.\n\n-----Input-----\nAny positive integer in the range 1 to 10000.\n\n-----Output-----\nA positive integer indicating safest position\n\n-----Example-----\nInput:\n9\n\nOutput:\n3\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nn=int(input())\narr=[]\nfor i in range(1,n+1):\n arr.append(i)\nc=0\ni=0\nf=0;\nwhile(c1:\n break\n if c<0:\n break\n if c==0:\n print('Valid')\n else:\n print('Invalid')\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '6\\n18\\n..H..T...HTH....T.\\n3\\n...\\n10\\nH..H..T..T\\n2\\nHT\\n11\\n.T...H..H.T\\n7\\nH..T..H\\n', 'output': 'Valid\\nValid\\nInvalid\\nValid\\nInvalid\\nInvalid\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/SNAKPROC'}","problem_id":"vfc_2470","program":"```python\n# cook your dish here\nt=int(input())\nfor i in range(t):\n n=int(input())\n s=input().strip()\n c=0\n for i in range(len(s)):\n if s[i]=='.':\n continue\n if s[i]=='H':\n c+=1\n if s[i]=='T':\n c-=1\n if c>1:\n break\n if c<0:\n break\n if c==0:\n print('Valid')\n else:\n print('Invalid')\n```","inputs":"6\n18\n..H..T...HTH....T.\n3\n...\n10\nH..H..T..T\n2\nHT\n11\n.T...H..H.T\n7\nH..T..H\n","output":"Valid\nValid\nInvalid\nValid\nInvalid\nInvalid\n","actual_output":"Valid\nValid\nInvalid\nValid\nInvalid\nInvalid\n","execution_success":true,"sample_index":511},{"source":"apps","task_type":"verifiable_code","in_source_id":"908","prompt":"Solve the following coding problem using the programming language python:\n\nChef belongs to a very rich family which owns many gold mines. Today, he brought N gold coins and decided to form a triangle using these coins. Isn't it strange?\nChef has a unusual way of forming a triangle using gold coins, which is described as follows:\n- He puts 1 coin in the 1st row.\n- then puts 2 coins in the 2nd row.\n- then puts 3 coins in the 3rd row.\n- and so on as shown in the given figure.\nChef is interested in forming a triangle with maximum possible height using at most N coins. Can you tell him the maximum possible height of the triangle?\n\n-----Input-----\nThe first line of input contains a single integer T denoting the number of test cases. \nThe first and the only line of each test case contains an integer N denoting the number of gold coins Chef has.\n\n-----Output-----\nFor each test case, output a single line containing an integer corresponding to the maximum possible height of the triangle that Chef can get.\n\n-----Constraints-----\n- 1 \u2264 T \u2264 100\n- 1 \u2264 N \u2264 109\n\n-----Subtasks-----\n- Subtask 1 (48 points) : 1 \u2264 N \u2264 105\n- Subtask 2 (52 points) : 1 \u2264 N \u2264 109\n\n-----Example-----\nInput3\n3\n5\n7\n\nOutput2\n2\n3\n\n-----Explanation-----\n- Test 1: Chef can't form a triangle with height > 2 as it requires atleast 6 gold coins.\n- Test 2: Chef can't form a triangle with height > 2 as it requires atleast 6 gold coins.\n- Test 3: Chef can't form a triangle with height > 3 as it requires atleast 10 gold coins.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nt = eval(input())\n\ndef moneda(m):\n h = 1\n triange = []\n while m >= h:\n triange.append(h)\n m -= h \n h += 1\n return len(triange)\n\ntriangulo = []\nfor i in range(t):\n n = eval(input())\n triangulo.append(n)\n\nfor i in triangulo:\n print(moneda(i))\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\n3\\n5\\n7\\n', 'output': '2\\n2\\n3\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/LTIME35/problems/TRICOIN'}","problem_id":"vfc_2474","program":"```python\nt = eval(input())\n\ndef moneda(m):\n h = 1\n triange = []\n while m >= h:\n triange.append(h)\n m -= h \n h += 1\n return len(triange)\n\ntriangulo = []\nfor i in range(t):\n n = eval(input())\n triangulo.append(n)\n\nfor i in triangulo:\n print(moneda(i))\n\n```","inputs":"3\n3\n5\n7\n","output":"2\n2\n3\n","actual_output":"2\n2\n3\n","execution_success":true,"sample_index":512},{"source":"apps","task_type":"verifiable_code","in_source_id":"909","prompt":"Solve the following coding problem using the programming language python:\n\n-----Problem Statement-----\nA classroom has several students, half of whom are boys and half of whom are girls. You need to arrange all of them in a line for the morning assembly such that the following conditions are satisfied:\n- The students must be in order of non-decreasing height.\n- Two boys or two girls must not be adjacent to each other.\nYou have been given the heights of the boys in the array $b$ and the heights of the girls in the array $g$. Find out whether you can arrange them in an order which satisfies the given conditions. Print \"YES\" if it is possible, or \"NO\" if it is not.\nFor example, let's say there are $n = 3$ boys and $n = 3$ girls, where the boys' heights are $b = [5, 3, 8]$ and the girls' heights are $g = [2, 4, 6]$. These students can be arranged in the order $[g_0, b_1, g_1, b_0, g_2, b_2]$, which is $[2, 3, 4, 5, 6, 8]$. Because this is in order of non-decreasing height, and no two boys or two girls are adjacent to each other, this satisfies the conditions. Therefore, the answer is \"YES\".\n\n-----Input-----\n- The first line contains an integer, $t$, denoting the number of test cases.\n- The first line of each test case contains an integer, $n$, denoting the number of boys and girls in the classroom.\n- The second line of each test case contains $n$ space separated integers, $b_1,b_2, ... b_n$, denoting the heights of the boys.\n- The second line of each test case contains $n$ space separated integers, $g_1,g_2,... g_n$, denoting the heights of the girls.\n\n-----Output-----\nPrint exactly $t$ lines. In the $i^{th}$ of them, print a single line containing \"$YES$\" without quotes if it is possible to arrange the students in the $i^{th}$ test case, or \"$NO$\" without quotes if it is not.\n\n-----Constraints-----\n- $1 \\leq t \\leq 10$\n- $1 \\leq n \\leq 100$\n- $1 \\leq b_i, g_i \\leq 100$\n\n-----Sample Input-----\n1\n2\n1 3\n2 4\n\n-----Sample Output-----\nYES\n\n-----EXPLANATION-----\nThe following arrangement would satisfy the given conditions: $[b_1, g_1, b_2, g_2]$. This is because the boys and girls and separated, and the height is in non-decreasing order.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfor u in range(int(input())):\n n=int(input())\n l=list(map(int,input().split()))\n d=list(map(int,input().split()))\n ka=[]\n k=[]\n l.sort()\n d.sort()\n for i in range(n):\n ka.append(d[i])\n ka.append(l[i])\n for i in range(n):\n k.append(l[i])\n k.append(d[i])\n if(ka==sorted(ka)):\n print(\"YES\")\n elif(k==sorted(k)):\n print(\"YES\")\n else:\n print(\"NO\")\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n2\\n1 3\\n2 4\\n', 'output': 'YES\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/SCAT2020/problems/SC_02'}","problem_id":"vfc_2478","program":"```python\nfor u in range(int(input())):\n n=int(input())\n l=list(map(int,input().split()))\n d=list(map(int,input().split()))\n ka=[]\n k=[]\n l.sort()\n d.sort()\n for i in range(n):\n ka.append(d[i])\n ka.append(l[i])\n for i in range(n):\n k.append(l[i])\n k.append(d[i])\n if(ka==sorted(ka)):\n print(\"YES\")\n elif(k==sorted(k)):\n print(\"YES\")\n else:\n print(\"NO\")\n\n```","inputs":"1\n2\n1 3\n2 4\n","output":"YES\n","actual_output":"YES\n","execution_success":true,"sample_index":513},{"source":"apps","task_type":"verifiable_code","in_source_id":"910","prompt":"Solve the following coding problem using the programming language python:\n\nRecently, Chef got obsessed with piano. He is a just a rookie in this stuff and can not move his fingers from one key to other fast enough. He discovered that the best way to train finger speed is to play scales.\n\nThere are different kinds of scales which are divided on the basis of their interval patterns. For instance, major scale is defined by pattern T-T-S-T-T-T-S, where \u2018T\u2019 stands for a whole tone whereas \u2018S\u2019 stands for a semitone. Two semitones make one tone. To understand how they are being played, please refer to the below image of piano\u2019s octave \u2013 two consecutive keys differ by one semitone.\n\nIf we start playing from first key (note C), then we\u2019ll play all white keys in a row (notes C-D-E-F-G-A-B-C \u2013 as you can see C and D differ for a tone as in pattern, and E and F differ for a semitone).\n\nThis pattern could be played some number of times (in cycle).\n\n\nEach time Chef takes some type of a scale and plays using some number of octaves. Sometimes Chef can make up some scales, so please don\u2019t blame him if you find some scale that does not exist in real world.\n\nFormally, you have a set of 12 keys (i.e. one octave) and you have N such sets in a row. So in total, you have 12*N keys. You also have a pattern that consists of letters 'T' and 'S', where 'T' means move forward for two keys (from key x to key x + 2, and 'S' means move forward for one key (from key x to key x + 1).\n\nNow, you can start playing from any of the 12*N keys. In one play, you can repeat the pattern as many times as you want, but you cannot go outside the keyboard.\n\nRepeating pattern means that if, for example, you have pattern STTST, you can play STTST as well as STTSTSTTST, as well as STTSTSTTSTSTTST, as well as any number of repeating. For this pattern, if you choose to repeat it once, if you start at some key x, you'll press keys: x (letter 'S')-> x + 1 (letter 'T')-> x + 3 (letter 'T')-> x + 5 (letter 'S') -> x + 6 (letter 'T')-> x + 8. Also 1 \u2264 x, x + 8 \u2264 12*N so as to avoid going off the keyboard.\n\nYou are asked to calculate number of different plays that can be performed. Two plays differ if and only if they start at different keys or patterns are repeated different number of times.\n\n-----Input-----\nThe first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.\n\nFirst line of each test case contains scale\u2019s pattern \u2013 string s consisting of letters \u2018T\u2019 and \u2018S\u2019 only.\n\nSecond line contains one integer N \u2013 number of octaves he\u2019ll be using.\n\n-----Output-----\nFor each test case output a single number in a line corresponding to number of different scales he\u2019ll play. \n\n-----Constraints-----\n- 1 \u2264 T \u2264 105\n- 1 \u2264 |S| \u2264 100\n- 1 \u2264 n \u2264 7\n\n-----Subtasks-----\nSubtask 1: T < 10 4, N = 1 \nSubtask 2: No additional constraints.\n\n-----Example-----\nInput:\n2 \nTTTT\n1\nTTSTTTS\n3\n\nOutput:\n4\n36\n\n-----Explanation-----\nExample case 1. In the first case there is only one octave and Chef can play scale (not in cycle each time) starting with notes C, C#, D, D# - four together.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nt =int(input())\r\nfor i in range(t):\r\n C=[ord(x)-ord('R') for x in list(input())]\r\n N=int(input())\r\n L=sum(C)\r\n r=1\r\n c=0\r\n while(r*L0$. \n- Subtask 2 [34 points]: $K \\le 10$.\n- Subtask 3 [49 points]: No additional constraints.\n\n-----Sample Input 1:-----\n5 4 3\n2 3 4 1\n1 4 5 2\n3 3 5 3\n\n-----Sample Output 1:-----\n16\n\n-----Explanation:-----\n\nSalmon can turn the 3rd horizontal road into a highway.\n- For the first delivery, we can go 2 units to the right taking 2 units of time, and 2 units down taking 4 units of time. The time taken is $2 + 4 = 6$.\n- For the second delivery, we can go 1 unit down taking 2 units of time, 4 units right taking 4 units of time, and 1 unit down taking 2 units of time. The time taken is $2 + 4 + 2 = 8$.\n- For the third delivery, we can go 2 units right taking 2 units of time.\nTherefore, the total time taken is $6 + 8 + 2 = 16$.\n\n-----Sample Input 2:-----\n10 2 3\n1 2 10 2\n2 1 9 1\n4 1 7 1\n\n-----Sample Output 2:-----\n23\n\n-----Explanation:-----\n\nSalmon can turn the 1st horizontal road into a highway.\n- For the first delivery, we can go 1 unit down taking 2 units of time, 9 units right taking 9 units of time, and 1 unit up taking 2 units of time. The time taken is $2 + 9 + 2 = 13$.\n- For the second delivery, we can go 7 units right taking 7 units of time.\n- For the third delivery, we can go 3 units to the right taking 3 units of time.\nTherefore, the total time taken is $13 + 7 + 3 = 23$.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nn,m,k=map(int, input().split())\na = []\ncheck = [0]*m\nwhile k!= 0:\n x1,y1,x2,y2 =map(int,input().split())\n a.append([x1,y1,x2,y2])\n check[y1-1] += 1\n check[y2-1] += 1\n k-= 1\nmaxi = check.index(max(check))+1\nsum = 0\nk = 0\nfor i in range(len(a)):\n x1,y1,x2,y2 = a[i]\n if (y1 > maxi and y2 > maxi) or (y1 maxi and y2 > maxi) or (y1 0):\r\n t -= 1\r\n n,m = list(map(int,input().split()))\r\n a = [list(map(int,input().split())) for _ in range(n)]\r\n dp = [[0 for _ in range(m)] for _ in range(n)]\r\n ans = [['0' for _ in range(m)] for _ in range(n)]\r\n for i in range(n):\r\n for j in range(m):\r\n if i-1 < n:\r\n if 0 <= j-1 and j+1 < m:\r\n dp[i][j] = max(dp[i-1][j-1],dp[i-1][j],dp[i-1][j+1])\r\n elif j == 0:\r\n dp[i][j] = max(dp[i-1][j],dp[i-1][j+1])\r\n elif j == m-1:\r\n dp[i][j] = max(dp[i-1][j-1],dp[i-1][j])\r\n \r\n if dp[i][j] > a[i][j]:\r\n ans[i][j] = '0'\r\n else:\r\n ans[i][j] = '1'\r\n dp[i][j] = a[i][j]\r\n \r\n for i in ans:\r\n print(''.join(i))\r\nexcept:\r\n pass\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n3 4\\n1 3 7 10\\n9 2 4 11\\n8 12 5 6 \\n\\n', 'output': '1111\\n1001\\n0100\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/APARTS'}","problem_id":"vfc_2498","program":"```python\ntry:\r\n t = int(input())\r\n while(t > 0):\r\n t -= 1\r\n n,m = list(map(int,input().split()))\r\n a = [list(map(int,input().split())) for _ in range(n)]\r\n dp = [[0 for _ in range(m)] for _ in range(n)]\r\n ans = [['0' for _ in range(m)] for _ in range(n)]\r\n for i in range(n):\r\n for j in range(m):\r\n if i-1 < n:\r\n if 0 <= j-1 and j+1 < m:\r\n dp[i][j] = max(dp[i-1][j-1],dp[i-1][j],dp[i-1][j+1])\r\n elif j == 0:\r\n dp[i][j] = max(dp[i-1][j],dp[i-1][j+1])\r\n elif j == m-1:\r\n dp[i][j] = max(dp[i-1][j-1],dp[i-1][j])\r\n \r\n if dp[i][j] > a[i][j]:\r\n ans[i][j] = '0'\r\n else:\r\n ans[i][j] = '1'\r\n dp[i][j] = a[i][j]\r\n \r\n for i in ans:\r\n print(''.join(i))\r\nexcept:\r\n pass\n```","inputs":"1\n3 4\n1 3 7 10\n9 2 4 11\n8 12 5 6 \n\n","output":"1111\n1001\n0100\n","actual_output":"1111\n1001\n0100\n","execution_success":true,"sample_index":517},{"source":"apps","task_type":"verifiable_code","in_source_id":"915","prompt":"Solve the following coding problem using the programming language python:\n\nDevu has n weird friends. Its his birthday today, so they thought that this is the best occasion for testing their friendship with him. They put up conditions before Devu that they will break the friendship unless he gives them a grand party on their chosen day. Formally, ith friend will break his friendship if he does not receive a grand party on dith day.\n\nDevu despite being as rich as Gatsby, is quite frugal and can give at most one grand party daily. Also, he wants to invite only one person in a party. So he just wonders what is the maximum number of friendships he can save. Please help Devu in this tough task !!\n\n-----Input-----\n- The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.\n- First line will contain a single integer denoting n.\n\n- Second line will contain n space separated integers where ith integer corresponds to the day dith as given in the problem.\n\n-----Output-----\nPrint a single line corresponding to the answer of the problem.\n\n-----Constraints-----\n- 1 \u2264 T \u2264 104\n- 1 \u2264 n \u2264 50\n- 1 \u2264 di \u2264 100\n\n-----Example-----\nInput:\n2\n2\n3 2\n2\n1 1\nOutput:\n2\n1\n\n-----Explanation-----\nExample case 1. Devu can give party to second friend on day 2 and first friend on day 3, so he can save both his friendships.\nExample case 2. Both the friends want a party on day 1, and as the Devu can not afford more than one party a day, so he can save only one of the friendships, so answer is 1.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\ntest = int(input())\n\nfor _ in range(0,test):\n n = int(input())\n lister = set(map(int,input().split()))\n print(len(lister))\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n2\\n3 2\\n2\\n1 1\\n', 'output': '2\\n1\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/CFRTEST'}","problem_id":"vfc_2502","program":"```python\n# cook your dish here\ntest = int(input())\n\nfor _ in range(0,test):\n n = int(input())\n lister = set(map(int,input().split()))\n print(len(lister))\n```","inputs":"2\n2\n3 2\n2\n1 1\n","output":"2\n1\n","actual_output":"2\n1\n","execution_success":true,"sample_index":518},{"source":"apps","task_type":"verifiable_code","in_source_id":"916","prompt":"Solve the following coding problem using the programming language python:\n\nChef was bored staying at home in the lockdown. He wanted to go out for a change. Chef and Chefu are fond of eating Cakes,so they decided to go the Cake shop where cakes of all possible price are available .\nThey decided to purchase cakes of equal price and each of them will pay for their cakes. Chef only has coins of denomination $N$ whereas Chefu has that of denomination $M$.\nSo they want your help to find out the minimum amount to be spent in order to purchase the cakes.\n\n-----Input:-----\n- First line will contain $T$, number of testcases. Then the testcases follow. \n- Each testcase contains of a single line of input, two integers $N, M$. \n\n-----Output:-----\nFor each testcase, output in a single line answer the minimum amount to be spent in order to purchase the cake.\n\n-----Constraints-----\n- $1 \\leq T \\leq 1000$\n- $2 \\leq N,M \\leq 10^7$\n\n-----Sample Input:-----\n1\n2 3\n\n-----Sample Output:-----\n6\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\nimport math\nT=int(input())\nfor i in range(T):\n a=list(map(int,input().split()))\n n=a[0]\n m=a[1]\n print(m*n//math.gcd(m,n))\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n2 3\\n', 'output': '6\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/ENAU2020/problems/ECAUG201'}","problem_id":"vfc_2506","program":"```python\n# cook your dish here\nimport math\nT=int(input())\nfor i in range(T):\n a=list(map(int,input().split()))\n n=a[0]\n m=a[1]\n print(m*n//math.gcd(m,n))\n```","inputs":"1\n2 3\n","output":"6\n","actual_output":"6\n","execution_success":true,"sample_index":519},{"source":"apps","task_type":"verifiable_code","in_source_id":"917","prompt":"Solve the following coding problem using the programming language python:\n\nYou are given an array of N integers a1, a2, ..., aN and an integer K. Find the number of such unordered pairs {i, j} that \n\n- i \u2260 j\n- |ai + aj - K| is minimal possible\n\nOutput the minimal possible value of |ai + aj - K| (where i \u2260 j) and the number of such pairs for the given array and the integer K.\n\n-----Input-----\nThe first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.\n\nThe first line of each test case consists of two space separated integers - N and K respectively.\n\nThe second line contains N single space separated integers - a1, a2, ..., aN respectively.\n\n-----Output-----\nFor each test case, output a single line containing two single space separated integers - the minimal possible value of |ai + aj - K| and the number of unordered pairs {i, j} for which this minimal difference is reached.\n\n-----Constraints-----\n\n- 1 \u2264 T \u2264 50\n- 1 \u2264 ai, K \u2264 109\n- N = 2 - 31 point.\n- 2 \u2264 N \u2264 1000 - 69 points.\n\n-----Example-----\nInput:\n1 \n4 9\n4 4 2 6\n\nOutput:\n1 4\n\n-----Explanation:-----\nThe minimal possible absolute difference of 1 can be obtained by taking the pairs of a1 and a2, a1 and a4, a2 and a4, a3 and a4.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfor _ in range(int(input())):\n n,k=list(map(int, input().split()))\n l=list(map(int, input().split()))\n l.sort()\n \n c=0\n mn=abs(l[0]+l[1]-k)\n for i in range(n-1):\n for j in range(i+1, n):\n temp=abs(l[i]+l[j]-k)\n if temp==mn:\n c+=1 \n \n elif tempmn:\n break\n \n print(mn, c)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n4 9\\n4 4 2 6\\n', 'output': '1 4\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/APPROX2'}","problem_id":"vfc_2510","program":"```python\nfor _ in range(int(input())):\n n,k=list(map(int, input().split()))\n l=list(map(int, input().split()))\n l.sort()\n \n c=0\n mn=abs(l[0]+l[1]-k)\n for i in range(n-1):\n for j in range(i+1, n):\n temp=abs(l[i]+l[j]-k)\n if temp==mn:\n c+=1 \n \n elif tempmn:\n break\n \n print(mn, c)\n```","inputs":"1\n4 9\n4 4 2 6\n","output":"1 4\n","actual_output":"1 4\n","execution_success":true,"sample_index":520},{"source":"apps","task_type":"verifiable_code","in_source_id":"918","prompt":"Solve the following coding problem using the programming language python:\n\nMr. Wire Less is not that good at implementing circuit in a breadboard. In his Digital Logic Design course, he has to implement several boolean functions using the breadboard. In a breadboard, inputs are given through the switches and outputs are taken through the LEDs. Each input switch can be either in ground state or in high state. So, if he wishes to implement a boolean function, f(x1, x2, .., xn) that takes n boolean values as input and returns m boolean values as output, he will use n switches and m LEDs. \nMr. Wire Less can quickly assemble the necessary ICs and wires, but the key problem is testing. While testing he has to check with all possible input combination, to make sure whether the output of LED corresponds to the expected output or not. This is taking too long for him, as most of the switches are jammed and difficult to toggle. \nMr. Wire Less is asking for help to minimize his time of testing. So, your task is to minimize the total number of switch-toggle throughout the testing.\nFor example, if Mr. Wire Less has to test a function f(x0, x1) of two variables, he may choose this switching-sequence for testing 00, 11, 10, 01. In this case, the total number of switch-toggle will be 2+1+2 = 5. But if he tests in this sequence 00, 10, 11, 01 total number of toggle will be 1+1+1 = 3.\nGiven n, you have to output the minimum number of toggle needed for complete testing. Though it seems impractical, he wants you to solve the problem for a very large value of n. But, then the toggle value can be quite big. So, he is completely okay with the toggle value modulo 8589934592 (233).\u2028\u2028\n\n-----Input-----\nThe first line of the input contains a positive integer T(T \u2264 105), denoting the number of test-case. Each of the following T lines contains a single non-negative integer n(n \u2264 1020).\n\n-----Output-----\nFor every test-case, output a single containing test-case number and the minimum number of switch-toggle modulo 8589934592 (233).\n\n-----Sample----- \nInput \n2\n1\n2\n\nOutput\nCase 1: 1\nCase 2: 3\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\nmod=8589934592\nlist1=[]\nfor i in range(int(input())):\n x=int(input())\n ans=(pow(2,x,mod)-1)%mod\n list1.append((i+1,ans))\nfor i in list1:\n print(f'Case {i[0]}: {i[1]}')\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n1\\n2\\n\\n\\n', 'output': 'Case 1: 1\\nCase 2: 3\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/KOL16H'}","problem_id":"vfc_2514","program":"```python\n# cook your dish here\nmod=8589934592\nlist1=[]\nfor i in range(int(input())):\n x=int(input())\n ans=(pow(2,x,mod)-1)%mod\n list1.append((i+1,ans))\nfor i in list1:\n print(f'Case {i[0]}: {i[1]}')\n```","inputs":"2\n1\n2\n\n\n","output":"Case 1: 1\nCase 2: 3\n","actual_output":"Case 1: 1\nCase 2: 3\n","execution_success":true,"sample_index":521},{"source":"apps","task_type":"verifiable_code","in_source_id":"919","prompt":"Solve the following coding problem using the programming language python:\n\nAn even sequence has the following property: each maximal contiguous subsequence which contains only equal integers (i.e. the same integer repeated a number of times) has an even length. In particular, the empty sequence is even. A subsequence is maximal if it is not contained in a larger contiguous subsequence which contains only equal integers.\nChef was given an integer sequence $A_1, A_2, \\ldots, A_N$ by his friend Mr. Z. He may perform the following operation any number of times: either delete an element of the current sequence (if it is non-empty) or insert an integer anywhere in the current sequence (possibly at the beginning or at the end).\nFind the minimum number of operations needed to make the sequence even.\n\n-----Input-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The first line of each test case contains a single integer $N$.\n- The second line contains $N$ space-separated integers $A_1, A_2, \\ldots, A_N$.\n\n-----Output-----\nFor each test case, print a single line containing one integer \u2014 the minimum number of operations.\n\n-----Constraints-----\n- $1 \\leq T \\leq 10$\n- $1 \\leq N \\leq 2 \\cdot 10^5$\n- $1 \\leq A_i \\leq N$ for each valid $i$\n- the sum of $N$ over all test cases does not exceed $2 \\cdot 10^6$\n\n-----Subtasks-----\nSubtask #1 (10 points): $N \\leq 18$\nSubtask #2 (10 points): $A_i \\leq A_{i+1}$ for each valid $i$\nSubtask #3 (20 points): $N \\leq 3,000$\nSubtask #4 (20 points): $A_i \\leq 26$ for each valid $i$\nSubtask #5 (40 points): original constraints\n\n-----Example Input-----\n2\n4\n1 1 2 1\n11\n2 2 2 10 2 10 1 1 5 3 5\n\n-----Example Output-----\n2\n3\n\n-----Explanation-----\nExample case 1: Here are two ways to make the sequence even using $2$ operations:\n- Delete the first element $1$ and the only element $2$, resulting in a sequence $(1, 1)$, which is even.\n- Delete the last element $1$ and insert $2$ at the end, resulting in a sequence $(1,1,2,2)$, which is even.\nIt can be proved that one operation is not enough to make the initial sequence even.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n'''Author- Akshit Monga'''\nfrom sys import stdin, stdout\ninput = stdin.readline\nt=int(input())\nfor _ in range(t):\n n=int(input())\n a=[int(x) for x in input().split()]\n ans=0\n dp=[-1 for i in range(0,n+1)]\n for i in a:\n var1=dp[i]\n var2=ans\n ans=max(ans,var1+1)\n dp[i]=max(dp[i],var2+1)\n print(n-ans)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n4\\n1 1 2 1\\n11\\n2 2 2 10 2 10 1 1 5 3 5\\n', 'output': '2\\n3\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/EVSTR'}","problem_id":"vfc_2518","program":"```python\n'''Author- Akshit Monga'''\nfrom sys import stdin, stdout\ninput = stdin.readline\nt=int(input())\nfor _ in range(t):\n n=int(input())\n a=[int(x) for x in input().split()]\n ans=0\n dp=[-1 for i in range(0,n+1)]\n for i in a:\n var1=dp[i]\n var2=ans\n ans=max(ans,var1+1)\n dp[i]=max(dp[i],var2+1)\n print(n-ans)\n```","inputs":"2\n4\n1 1 2 1\n11\n2 2 2 10 2 10 1 1 5 3 5\n","output":"2\n3\n","actual_output":"2\n3\n","execution_success":true,"sample_index":522},{"source":"apps","task_type":"verifiable_code","in_source_id":"920","prompt":"Solve the following coding problem using the programming language python:\n\nYou are teaching a class of $N$ students. Today, during the morning prayer, all the students are standing in a line. You are given a string $s$ with length $N$; for each valid $i$, the $i$-th character of this string is 'b' if the $i$-th student in the line is a boy or 'g' if this student is a girl.\nThe awkwardness of this configuration of students is defined as the sum of pairwise distances between each boy and girl. The distance between the $i$-th and $j$-th student in the line is $|i - j|$. Formally, the awkwardness is \u2211i=1N\u2211j=i+1sj\u2260siN(j\u2212i).\u2211i=1N\u2211j=i+1sj\u2260siN(j\u2212i).\\sum\\limits_{i=1}^N \\, \\sum\\limits_{j=i+1\\\\ s_j \\neq s_i}^N (j - i)\\,.\nAs the teacher, it is your responsibility to reorder the students in such a way that the awkwardness of the resulting configuration is the smallest possible. You may reorder the students in the line in any way you want. Find the minimum awkwardness that can be achieved.\n\n-----Input-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The first and only line of each test case contains a single string $s$.\n\n-----Output-----\nFor each test case, print a single line containing one integer - the minimum possible awkwardness.\n\n-----Constraints-----\n- $1 \\le T \\le 10^5$\n- $1 \\le |s| \\le 10^5$\n- each character of $s$ is either 'b' or 'g'\n- the sum of $|s|$ over all test cases does not exceed $4 \\cdot 10^6$\n\n-----Example Input-----\n3\ngb\nbgg\nbbgg\n\n-----Example Output-----\n1\n2\n6\n\n-----Explanation-----\nExample case 1: The total awkwardness is $|1 - 0| = 1$, no matter how you arrange the students.\nExample case 2: Initially, the awkwardness is $|1 - 0| + |2 - 0| = 1 + 2 = 3$. However, you can move the boy between the two girls, i.e. choose the configuration \"gbg\". Here, the awkwardness is $|1 - 0| + |2 - 1| = 1 + 1 = 2$.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfrom collections import Counter \nfor _ in range(int(input())):\n s = input()\n c = Counter(list(s))\n if len(c) == 1:\n print(0)\n else:\n m = min(c['b'], c['g'])\n ma = max(c['b'], c['g'])\n l = (ma - m + 1) // 2\n r = (ma - m + 1) // 2 + (ma - m + 1) % 2\n res = (l * (l + 1)) // 2\n re = res\n for i in range(1, m):\n res += 2 * l + 1\n re += res\n l += 1\n res2 = (r * (r + 1)) // 2\n re += res2\n for i in range(1, m):\n res2 += 2 * r + 1\n re += res2\n r += 1\n print(re)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\ngb\\nbgg\\nbbgg\\n', 'output': '1\\n2\\n6\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/AWKMINI'}","problem_id":"vfc_2522","program":"```python\nfrom collections import Counter \nfor _ in range(int(input())):\n s = input()\n c = Counter(list(s))\n if len(c) == 1:\n print(0)\n else:\n m = min(c['b'], c['g'])\n ma = max(c['b'], c['g'])\n l = (ma - m + 1) // 2\n r = (ma - m + 1) // 2 + (ma - m + 1) % 2\n res = (l * (l + 1)) // 2\n re = res\n for i in range(1, m):\n res += 2 * l + 1\n re += res\n l += 1\n res2 = (r * (r + 1)) // 2\n re += res2\n for i in range(1, m):\n res2 += 2 * r + 1\n re += res2\n r += 1\n print(re)\n```","inputs":"3\ngb\nbgg\nbbgg\n","output":"1\n2\n6\n","actual_output":"1\n2\n6\n","execution_success":true,"sample_index":523},{"source":"apps","task_type":"verifiable_code","in_source_id":"922","prompt":"Solve the following coding problem using the programming language python:\n\nChef has three baskets and two of them have multiple balls(Natural numbers written on them). The first basket has N balls, the second basket has M balls and the third basket is empty. Chef starts choosing all the unique balls(only occurring once in both the baskets) and puts into the third basket and throw the repetitive ones. Print numbers on the balls of the third basket in ascending order. \n\n-----Input:-----\n- First line will contain $T$, number of testcases. Then the testcases follow. \n- Each testcase contains three lines of input.\n- First-line has two integers $N, M$. \n- Second-line with N space-separated numbers.\n- Third-line with M space-separated numbers.\n\n-----Output:-----\nFor each testcase, output in a single line answer.\n\n-----Constraints-----\n- $1 \\leq T \\leq 10$\n- $1 \\leq N \\leq 10^5$\n- $1 \\leq M \\leq 10^5$\n\n-----Sample Input:-----\n1\n4 5\n1 2 3 4\n2 3 4 5 6\n\n-----Sample Output:-----\n1 5 6\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nt = int(input())\nfor i in range(t):\n n, m = map(int, input().split())\n arr1 = list(map(int, input().split()))\n arr2 = list(map(int, input().split()))\n hmap = {}\n for i in range(n):\n if arr1[i] in hmap:\n hmap[arr1[i]] += 1\n else:\n hmap[arr1[i]] = 1\n \n for i in range(m):\n if arr2[i] in hmap:\n hmap[arr2[i]] += 1\n else:\n hmap[arr2[i]] = 1\n ans = []\n #print(hmap)\n for key in hmap:\n if hmap[key]==1:\n ans.append(key)\n ans.sort()\n for x in ans:\n print(x,end=' ')\n print()\n \n \n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n4 5\\n1 2 3 4\\n2 3 4 5 6\\n', 'output': '1 5 6\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/PEND2020/problems/ITGUY08'}","problem_id":"vfc_2530","program":"```python\nt = int(input())\nfor i in range(t):\n n, m = map(int, input().split())\n arr1 = list(map(int, input().split()))\n arr2 = list(map(int, input().split()))\n hmap = {}\n for i in range(n):\n if arr1[i] in hmap:\n hmap[arr1[i]] += 1\n else:\n hmap[arr1[i]] = 1\n \n for i in range(m):\n if arr2[i] in hmap:\n hmap[arr2[i]] += 1\n else:\n hmap[arr2[i]] = 1\n ans = []\n #print(hmap)\n for key in hmap:\n if hmap[key]==1:\n ans.append(key)\n ans.sort()\n for x in ans:\n print(x,end=' ')\n print()\n \n \n```","inputs":"1\n4 5\n1 2 3 4\n2 3 4 5 6\n","output":"1 5 6\n","actual_output":"1 5 6 \n","execution_success":true,"sample_index":525},{"source":"apps","task_type":"verifiable_code","in_source_id":"923","prompt":"Solve the following coding problem using the programming language python:\n\nLike all minions Dave also like to eat bananas. So as to his obsession, he is eating banana, but this time in different way. There are N bananas in dish. Dave wants to eat all of them. He starts eating at speed 1 banana/second. He can increase or decrease speed of eating by one only. The condition is that he must end eating at speed 1 banana/second. So, your task is to find minimum time required to finish all bananas in a dish.\n\n-----Input-----\nFirst line contain number of test cases T. Next T lines contain one integer N. Where N is number of bananas in a dish.\n\n-----Output-----\nFor each test case print minimum time require to eat all N bananas.\n\n-----Constraints-----\n- 1 \u2264 T \u2264 100\n- 1 \u2264 N \u2264 105\n\n-----Example-----\nInput:\n2\n2\n4\n\nOutput:\n2\n3\n\n\n-----Explanation-----\nExample case 1.Dave will start to eat with rate of 1 banana/second. Then only one banana will remain. He will eat that banana in 1 second. Thus, Total time is 2 seconds.\nExample case 2.Dave starts with rate of 1 banana/second, and then increase it to 2 bananas/second and again decrease it to 1 banana/second. So total time is 3 seconds.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nt=int(input())\nwhile(t):\n k=1\n j=0\n n=int(input())\n while(n>0):\n if(n<=k):\n j+=1\n n=0\n elif n>2*k:\n j+=2\n n=n-2*k\n k+=1\n else:\n j+=2\n n=0\n print(j)\n t-=1\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n2\\n4\\n', 'output': '2\\n3\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/CFSN2015/problems/PUNBAN'}","problem_id":"vfc_2534","program":"```python\nt=int(input())\nwhile(t):\n k=1\n j=0\n n=int(input())\n while(n>0):\n if(n<=k):\n j+=1\n n=0\n elif n>2*k:\n j+=2\n n=n-2*k\n k+=1\n else:\n j+=2\n n=0\n print(j)\n t-=1\n```","inputs":"2\n2\n4\n","output":"2\n3\n","actual_output":"2\n3\n","execution_success":true,"sample_index":526},{"source":"apps","task_type":"verifiable_code","in_source_id":"924","prompt":"Solve the following coding problem using the programming language python:\n\nGiven an empty array A of infinite length and a positive integer K you have to process \nQ queries of type: \n- ! l r x: Fill the value x in all the empty places in the array from index l to r (both inclusive).\n- ? l r: Print the number of prime factors of K which is also a prime factor of at least one number in A[l], A[l + 1], A[l + 2], \u2026 A[r]. \n\n-----Input-----\n- The first line contains two space separated integers K and Q respectively.\n- Then Q lines follow:\n- Each of the $i^{th}$ line contains one of the above two types of queries.\n\n-----Output-----\nFor each query of the second type, print in a new line the answer to that query. i.e. number of prime factors of K which is also a prime factor of at least one number in A[l], A[l + 1], A[l + 2], \u2026 A[r]. \n\n-----Constraints-----\n- $1 \\leq K, x \\leq 10^9$\n- $ 1 \\leq l \\leq r \\leq 10^5$\n- $ 1 \\leq Q \\leq 10^5$ \n\n-----Sample Input-----\n20 5\n\n? 1 5\n\n! 3 5 4\n\n? 1 5\n\n! 1 4 15\n\n? 1 5 \n\n-----Sample Output-----\n0\n\n1\n\n2 \n\n-----EXPLANATION-----\nInitially, all the places in the array are empty. i.e _ _ _ _ _\n\nAfter first update the array looks like: _ _ 4 4 4\n\nIn the range [1, 5] the only factor of 20 which is also a prime factor of at least one number in _ _ 4 4 4 is 2.\n\nAfter the second update the array looks like: 15 15 4 4 4\n\nIn the range [1, 5] the prime factors of 20 i.e. 5 is a prime factor of 15, 15 and 2 is the prime factor of 4, 4, 4.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\n# cook your dish here\n\nimport math\ndef distinctPrimeFactors(num) :\n primes,sqrt = set(),int(math.sqrt(num))\n if (num == 2) :primes.add(num)\n for j in range(2, sqrt + 1) :\n if (num % j == 0) :\n primes.add(j)\n while (num % j == 0) :num //= j\n if (num > 2) :primes.add(num)\n return (primes)\nres,c,lst,primes,rangeData = [],0,{},{},{};k, q = map(int, input().split());primes[k] = distinctPrimeFactors(k)\nfor tc in range(q) :\n query = input()\n if (query[0] == '!') :\n cmd, l, r, x = query.split();l,r,x = int(l),int(r),int(x);start,end,startflag = l,r,False\n for i in sorted(rangeData) :\n rangeVal = i\n if (start > rangeVal[1]) :continue\n if (end < rangeVal[0]) :break \n startRange,endRange = start,end\n if (start >= rangeVal[0] and start <= rangeVal[1]) :start = rangeVal[1] + 1;continue\n if (end >= rangeVal[0]) :endRange = rangeVal[0] - 1\n if (startRange <= endRange) :\n rangeData[(startRange, endRange)] = x;start = max(endRange + 1, rangeVal[1] + 1)\n if (start <= end) :rangeData[(start,end)] = x\n elif (query[0] == '?') :\n cmd, l, r = query.split();l,r,count = int(l),int(r),0\n for primenum in primes[k] :\n for currRange in rangeData :\n if (not (r < currRange[0] or l > currRange[1])) :\n if (rangeData[currRange] % primenum == 0) :count += 1;break\n c += 1;res.append(count) \nfor i in range(c):print(res[i])\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '20 5\\n? 1 5\\n! 3 5 4\\n? 1 5\\n! 1 4 15\\n? 1 5\\n', 'output': '0\\n1\\n2\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/PRMRANGE'}","problem_id":"vfc_2538","program":"```python\n# cook your dish here\n# cook your dish here\n\nimport math\ndef distinctPrimeFactors(num) :\n primes,sqrt = set(),int(math.sqrt(num))\n if (num == 2) :primes.add(num)\n for j in range(2, sqrt + 1) :\n if (num % j == 0) :\n primes.add(j)\n while (num % j == 0) :num //= j\n if (num > 2) :primes.add(num)\n return (primes)\nres,c,lst,primes,rangeData = [],0,{},{},{};k, q = map(int, input().split());primes[k] = distinctPrimeFactors(k)\nfor tc in range(q) :\n query = input()\n if (query[0] == '!') :\n cmd, l, r, x = query.split();l,r,x = int(l),int(r),int(x);start,end,startflag = l,r,False\n for i in sorted(rangeData) :\n rangeVal = i\n if (start > rangeVal[1]) :continue\n if (end < rangeVal[0]) :break \n startRange,endRange = start,end\n if (start >= rangeVal[0] and start <= rangeVal[1]) :start = rangeVal[1] + 1;continue\n if (end >= rangeVal[0]) :endRange = rangeVal[0] - 1\n if (startRange <= endRange) :\n rangeData[(startRange, endRange)] = x;start = max(endRange + 1, rangeVal[1] + 1)\n if (start <= end) :rangeData[(start,end)] = x\n elif (query[0] == '?') :\n cmd, l, r = query.split();l,r,count = int(l),int(r),0\n for primenum in primes[k] :\n for currRange in rangeData :\n if (not (r < currRange[0] or l > currRange[1])) :\n if (rangeData[currRange] % primenum == 0) :count += 1;break\n c += 1;res.append(count) \nfor i in range(c):print(res[i])\n\n```","inputs":"20 5\n? 1 5\n! 3 5 4\n? 1 5\n! 1 4 15\n? 1 5\n","output":"0\n1\n2\n","actual_output":"0\n1\n2\n","execution_success":true,"sample_index":527},{"source":"apps","task_type":"verifiable_code","in_source_id":"926","prompt":"Solve the following coding problem using the programming language python:\n\nToday is Chocolate day and Kabir and Tara are visiting a Valentine fair. Upon arriving, they find a stall with an interesting game.\nThere are N$N$ jars having some chocolates in them. To win the game, one has to select the maximum number of consecutive jars such that the sum of count of chocolates in maximum and second maximum jar is less than or equal to k$k$ in that range.\nKabir wants to win the game so that he can gift the chocolates to Tara. You are a friend of Kabiir, help him win the game.\nThere will be at least one possible answer.\nNote$Note$ :\n- You have to select at least two jars. \n- Count of chocolates in maximum and second maximum jar among selected consecutive jars may be equal.\n\n-----Input:-----\n- First line will contain T$T$, number of test cases.\n- First line of each test case contains two space separated integers N,k$N, k$.\n- Second line of each test case contains N$N$ space separated integer ai$a_i$ denotes number of chocolates in the jar. \n\n-----Output:-----\nFor each test case print maximum number of jars.\n\n-----Constraints:-----\n- 1\u2264T\u226410$1 \\leq T \\leq 10$\n- 2\u2264N\u2264105$2 \\leq N \\leq 10^5$\n- 1\u2264ai\u2264105$1 \\leq a_i \\leq 10^5$\n\n-----Sample Input:-----\n1\n6 5\n\n1 3 3 1 1 5\n\n-----Sample Output:-----\n3\n\n-----EXPLANATION:-----\nYou can select 3rd$3^{rd}$, 4th$4^{th}$, and 5th$5^{th}$ jar as the sum of max and second max is equal to 4 which is less then 5.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\nfor u in range(int(input())):\n n,r=list(map(int,input().split()))\n l=list(map(int,input().split()))\n m=0\n for i in range(n-1):\n d=[]\n d.append(l[i])\n c=1\n while(i+cm):\n m=c\n print(m)\n\n\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n6 5\\n1 3 3 1 1 5\\n', 'output': '3\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/HECS2020/problems/CC003'}","problem_id":"vfc_2546","program":"```python\n# cook your dish here\nfor u in range(int(input())):\n n,r=list(map(int,input().split()))\n l=list(map(int,input().split()))\n m=0\n for i in range(n-1):\n d=[]\n d.append(l[i])\n c=1\n while(i+cm):\n m=c\n print(m)\n\n\n\n```","inputs":"1\n6 5\n1 3 3 1 1 5\n","output":"3\n","actual_output":"3\n","execution_success":true,"sample_index":529},{"source":"apps","task_type":"verifiable_code","in_source_id":"927","prompt":"Solve the following coding problem using the programming language python:\n\nMohit(Ex GenSec ) is the most active member of the roasting club who loves giving tasks to other members. One day he observed that none of the members were paying attention to the online classes, so he decided to have some fun and overcome the boring lectures. He wrote N numbers on the virtual board (where the first number is 1, the last one is N and the ith number being i).\nThen he asked M questions to every other member of the club. In each question, a number K was given by Mohit and the members had to give a single integer as an answer which will be the sum of all numbers present on the whiteboard.\nThere are some conditions that every member has to follow while answering.\n- If K is already present on the whiteboard then swap the first and last number.\n- Otherwise, replace the last number with K.\n\n-----Input:-----\n- First-line will consist of space-separated integers N and M. The board will contain the list of numbers from 1 to N and M is the number of questions that Mohit will ask.\n- Next M lines contain the number Ki, which will be provided by Mohit and (1<=i<=M).\n\n-----Output:-----\nFor each question, report the sum of all integers present\n\n-----Constraints-----\n- $1 \\leq N,M \\leq 1000000$\n- $2 \\leq K \\leq 10^9$\n\n-----Sample Input:-----\n5 4\n7\n12 \n10 \n1 \n\n-----Sample Output:-----\n17\n22 \n20\n20\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nn, m = map(int, input().split())\nl = n\nf = 1\ns = ((n)*(n+1))//2 - l - f\nfor _ in range(m):\n k = int(input())\n if 2 <= k <= n-1 or k in [f, l]:\n l, f = f, l\n else:\n l = k\n print(s+l+f)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '5 4\\n7\\n12\\n10\\n1\\n', 'output': '17\\n22\\n20\\n20\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/CGRL2020/problems/CGMN1'}","problem_id":"vfc_2550","program":"```python\nn, m = map(int, input().split())\nl = n\nf = 1\ns = ((n)*(n+1))//2 - l - f\nfor _ in range(m):\n k = int(input())\n if 2 <= k <= n-1 or k in [f, l]:\n l, f = f, l\n else:\n l = k\n print(s+l+f)\n```","inputs":"5 4\n7\n12\n10\n1\n","output":"17\n22\n20\n20\n","actual_output":"17\n22\n20\n20\n","execution_success":true,"sample_index":530},{"source":"apps","task_type":"verifiable_code","in_source_id":"928","prompt":"Solve the following coding problem using the programming language python:\n\nBeing a crewmate in the Among Us game, you will have to solve a task to win against the imposter. \nThe task : You are given a certain number of bulbs(Say n) which are initially in OFF position. \nThe bulbs are numbered from 1 to n. There will be n current fluctuations in such a way that in the 1st fluctuation all bulbs are toggled, in the 2nd fluctuation every 2nd bulb is toggled, in the 3rd fluctuation every 3rd bulb is toggled and so on.\nYour job as a crewmate is to find the number of bulbs which are ON at the end of n fluctuations. But, the imposter has a special power which alerts it when a bulb with a number divisible by 3 is kept ON at the end of n fluctuations. \nSo, you will have to switch off the bulbs with numbers divisible by 3 and give the final result to complete the task and win the game.\n\n-----Input:-----\n- First line will contain $T$, number of testcases. Then the testcases follow. \n- Each testcase contains of a single line of input, an integer $n$. \n\n-----Output:-----\n- For each testcase, output a single integer - the number of bulbs that will remain ON after $n$ fluctuations.\n\n-----Constraints :-----\n- $1 \\leq T \\leq 1000$\n- $2 \\leq n \\leq 10^9$\n\n-----Sample Input:-----\n2\n2\n20\n\n-----Sample Output:-----\n1\n\n3\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nimport math\r\ndef CountSquares(a, b):\r\n return (math.floor(math.sqrt(b)) - math.ceil(math.sqrt(a)) + 1)\r\nfor _ in range(int(input())):\r\n n=int(input())\r\n val=CountSquares(1,n)\r\n ans=val-val//3\r\n print(ans)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n2\\n20\\n', 'output': '1\\n3\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/ENNO2020/problems/ENCNOV11'}","problem_id":"vfc_2554","program":"```python\nimport math\r\ndef CountSquares(a, b):\r\n return (math.floor(math.sqrt(b)) - math.ceil(math.sqrt(a)) + 1)\r\nfor _ in range(int(input())):\r\n n=int(input())\r\n val=CountSquares(1,n)\r\n ans=val-val//3\r\n print(ans)\n```","inputs":"2\n2\n20\n","output":"1\n3\n","actual_output":"1\n3\n","execution_success":true,"sample_index":531},{"source":"apps","task_type":"verifiable_code","in_source_id":"929","prompt":"Solve the following coding problem using the programming language python:\n\nYou are given a tree with $N$ vertices (numbered $1$ through $N$) and a bag with $N$ markers. There is an integer written on each marker; each of these integers is $0$, $1$ or $2$. You must assign exactly one marker to each vertex.\nLet's define the unattractiveness of the resulting tree as the maximum absolute difference of integers written on the markers in any two vertices which are connected by an edge.\nFind the minimum possible unattractiveness of the resulting tree.\n\n-----Input-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The first line of each test case contains a single integer $N$.\n- The second line contains $N$ space-separated integers denoting the numbers on markers in the bag.\n- Each of the next $N-1$ lines contains two space-separated integers $u$ and $v$ denoting an edge between vertices $u$ and $v$.\n\n-----Output-----\nFor each test case, print a single line containing one integer \u2014 the minimum unattractiveness.\n\n-----Constraints-----\n- $1 \\le T \\le 30$\n- $1 \\le N \\le 100$\n- $1 \\le u, v \\le N$\n- the graph described on the input is a tree\n\n-----Example Input-----\n3\n3\n0 1 1\n1 2\n1 3\n3\n0 1 2\n1 2\n1 3\n4\n2 2 2 2\n1 2\n1 3\n3 4\n\n-----Example Output-----\n1\n1\n0\n\n-----Explanation-----\nExample case 1:\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\nimport numpy as np\ntests = int(input())\nfor _ in range(tests):\n n = int(input())\n weights = [int(j) for j in input().split()]\n edges = [[0] for _ in range(n-1)]\n for i in range(n-1):\n edges[i] = [int(j)-1 for j in input().split()]\n vertex_set = [[] for _ in range(n)]\n for i in range(n-1):\n vertex_set[edges[i][0]].append(edges[i][1])\n vertex_set[edges[i][1]].append(edges[i][0])\n counts = [0 for _ in range(3)]\n for i in range(n):\n counts[weights[i]] += 1\n if counts[1] == 0:\n print(2 * (counts[0] != 0 and counts[2] != 0))\n elif counts[1] == n:\n print(0)\n else:\n visited = [0]\n for i in range(n):\n vertex = visited[i]\n for v in vertex_set[vertex]:\n if v not in visited:\n visited.append(v)\n vertex_nums = [[0] for _ in range(n)]\n for i in range(n-1,-1,-1):\n vertex = visited[i]\n for v in vertex_set[vertex]:\n if v in visited[i:]:\n vertex_nums[vertex].append(sum(vertex_nums[v])+1)\n for i in range(n):\n vertex_nums[i].append(n-1-sum(vertex_nums[i]))\n sums = np.zeros(n,dtype=bool)\n sums[0] = True\n for i in range(n):\n new_sums = np.zeros(n,dtype=bool)\n new_sums[0] = True\n for num in vertex_nums[i]:\n new_sums[num:n] = np.logical_or(new_sums[num:n],new_sums[:n-num])\n sums = np.logical_or(sums,new_sums)\n solved = False\n for i in range(n):\n if sums[i] and counts[0] <= i and counts[2] <= n - 1 - i:\n solved = True\n break\n if solved or counts[1] > 1:\n print(1)\n else:\n print(2)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\n3\\n0 1 1\\n1 2\\n1 3\\n3\\n0 1 2\\n1 2\\n1 3\\n4\\n2 2 2 2\\n1 2\\n1 3\\n3 4\\n', 'output': '1\\n1\\n0\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/TREEUNAT'}","problem_id":"vfc_2558","program":"```python\n# cook your dish here\nimport numpy as np\ntests = int(input())\nfor _ in range(tests):\n n = int(input())\n weights = [int(j) for j in input().split()]\n edges = [[0] for _ in range(n-1)]\n for i in range(n-1):\n edges[i] = [int(j)-1 for j in input().split()]\n vertex_set = [[] for _ in range(n)]\n for i in range(n-1):\n vertex_set[edges[i][0]].append(edges[i][1])\n vertex_set[edges[i][1]].append(edges[i][0])\n counts = [0 for _ in range(3)]\n for i in range(n):\n counts[weights[i]] += 1\n if counts[1] == 0:\n print(2 * (counts[0] != 0 and counts[2] != 0))\n elif counts[1] == n:\n print(0)\n else:\n visited = [0]\n for i in range(n):\n vertex = visited[i]\n for v in vertex_set[vertex]:\n if v not in visited:\n visited.append(v)\n vertex_nums = [[0] for _ in range(n)]\n for i in range(n-1,-1,-1):\n vertex = visited[i]\n for v in vertex_set[vertex]:\n if v in visited[i:]:\n vertex_nums[vertex].append(sum(vertex_nums[v])+1)\n for i in range(n):\n vertex_nums[i].append(n-1-sum(vertex_nums[i]))\n sums = np.zeros(n,dtype=bool)\n sums[0] = True\n for i in range(n):\n new_sums = np.zeros(n,dtype=bool)\n new_sums[0] = True\n for num in vertex_nums[i]:\n new_sums[num:n] = np.logical_or(new_sums[num:n],new_sums[:n-num])\n sums = np.logical_or(sums,new_sums)\n solved = False\n for i in range(n):\n if sums[i] and counts[0] <= i and counts[2] <= n - 1 - i:\n solved = True\n break\n if solved or counts[1] > 1:\n print(1)\n else:\n print(2)\n```","inputs":"3\n3\n0 1 1\n1 2\n1 3\n3\n0 1 2\n1 2\n1 3\n4\n2 2 2 2\n1 2\n1 3\n3 4\n","output":"1\n1\n0\n","actual_output":"1\n1\n0\n","execution_success":true,"sample_index":532},{"source":"apps","task_type":"verifiable_code","in_source_id":"930","prompt":"Solve the following coding problem using the programming language python:\n\nConsider the following $4 \\times 4$ pattern:\n1 2 4 7\n3 5 8 11\n6 9 12 14\n10 13 15 16\n\nYou are given an integer $N$. Print the $N \\times N$ pattern of the same kind (containing integers $1$ through $N^2$).\n\n-----Input-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The first and only line of each test case contains a single integer $N$.\n\n-----Output-----\nFor each test case, print $N$ lines; each of them should contain $N$ space-separated integers.\n\n-----Constraints-----\n- $1 \\le T \\le 10$\n- $1 \\le N \\le 100$\n\n-----Subtasks-----\nSubtask #1 (100 points): Original constraints\n\n-----Example Input-----\n1\n4\n\n-----Example Output-----\n1 2 4 7\n3 5 8 11\n6 9 12 14\n10 13 15 16\n\n-----Explanation-----\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfor i in range(int(input())):\n t=int(input())\n n=0\n for i in range(1,t+1):\n n=n+i\n x=[n]\n y=n\n for j in range(i,t+i-1):\n if j d2: d1,d2 = d2, d1\n if (d1 == 1) and (d2 == 2):\n print(\"Yes\")\n else:\n print(\"No\")\n else:\n print(\"Error\")\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '4\\na1-b3\\nd2-h8\\na3 c4\\nErrorError\\n', 'output': 'Yes\\nNo\\nError\\nError\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/COOK11/problems/KNIGHTMV'}","problem_id":"vfc_2574","program":"```python\n#!/usr/bin/env python2\n \ndef gc(c):\n return 'a' <= c <= 'h'\ndef gd(c):\n return '1' <= c <= '8'\n \nt = int(input())\nfor i in range(t):\n line = input()\n if len(line) != 5:\n print(\"Error\")\n continue\n if line[2] != '-':\n print(\"Error\")\n continue\n x1 = line[0]\n y1 = line[1]\n x2 = line[3]\n y2 = line[4]\n if gc(x1) and gd(y1) and gc(x2) and gd(y2):\n d1 = abs(ord(x1) - ord(x2))\n d2 = abs(ord(y1) - ord(y2))\n if d1 > d2: d1,d2 = d2, d1\n if (d1 == 1) and (d2 == 2):\n print(\"Yes\")\n else:\n print(\"No\")\n else:\n print(\"Error\")\n```","inputs":"4\na1-b3\nd2-h8\na3 c4\nErrorError\n","output":"Yes\nNo\nError\nError\n","actual_output":"Yes\nNo\nError\nError\n","execution_success":true,"sample_index":536},{"source":"apps","task_type":"verifiable_code","in_source_id":"934","prompt":"Solve the following coding problem using the programming language python:\n\nGiven a triplet of integers (X , Y , Z), such that X \u2264 Y and Y \u2265 Z, we define f(X , Y , Z) to be (X + Y) * (Y + Z). If either X > Y or Y < Z, or both, then f(X , Y , Z) is defined to be 0.\nYou are provided three arrays A , B and C of any length (their lengths may or may not be equal). \nYour task is to find the sum of f(X , Y , Z) over all triplets (X, Y , Z) where X, Y and Z belong to A, B and C respectively.\nOutput your sum for each test case modulo 1000000007.\n\n-----Input-----\n- The first line contains a single integer, T, which is the number of test cases. The description of each testcase follows:\n- The first line of each testcase contains 3 integers: p, q and r. These denote the lengths of A,B and C respectively. \n- The second line contains p integers, which are the elements of A\n- The third line contains q integers, which are the elements of B\n- The fourth line contains r integers, which are the elements of C\n\n-----Output-----\nOutput the required sum modulo 1000000007 for each test case in a new line.\n\n-----Constraints-----\n- 1 \u2264 T \u2264 10 \n- 1 \u2264 p, q, r \u2264 100000 \n- 1 \u2264 every array element \u2264 1000000000\n\n-----Subtasks -----\n- Subtask #1 (30 points): 1 \u2264 p,q,r \u2264 100 \n- Subtask #2 (70 points): 1 \u2264 p,q,r \u2264 100000 \n\n-----Example : -----\nInput:\n1 \n3 1 3\n1 2 3\n5\n4 5 6\n\nOutput:\n399\n\n-----Explanation: -----\nAs there is only one choice for Y which equals to 5, to get a non-zero function value,we can choose any element for X from the set { 1 , 2 , 3 } and for Z from the set { 4 , 5 } \nSo triplets which give non-zero function values are: \n{ 1 , 5 , 4 } : ( 1 + 5 ) * ( 5 + 4 ) = 54 \n{ 1 , 5 , 5 } : ( 1 + 5 ) * ( 5 + 5 ) = 60 \n{ 2 , 5 , 4 } : ( 2 + 5 ) * ( 5 + 4 ) = 63 \n{ 2 , 5 , 5 } : ( 2 + 5 ) * ( 5 + 5 ) = 70 \n{ 3 , 5 , 4 } : ( 3 + 5 ) * ( 5 + 4 ) = 72 \n{ 3 , 5 , 5 } : ( 3 + 5 ) * ( 5 + 5 ) = 80 \nFinal answer : 54 + 60 + 63 + 70 + 72 + 80 = 399\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nT=int(input()) # cook your dish here\nfor i in range(T): \n n=list(map(int,input().split()))\n a=n[0]\n b=n[1]\n c=n[2]\n l=[]\n A=list(map(int,input().split()))\n B=list(map(int,input().split()))\n C=list(map(int,input().split()))\n for i in range(b):\n for j in range(a):\n for k in range(c):\n if(A[j]<=B[i] and B[i]>=C[k]):\n sum=((A[j]+B[i])*(B[i]+C[k]))\n l.append(int(sum))\n \n \n \n \n sum=0\n for i in range(len(l)):\n sum+=int(l[i])\n print(sum%1000000007)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1 \\n3 1 3\\n1 2 3\\n5\\n4 5 6\\n\\n\\n', 'output': '399\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/SUMQ'}","problem_id":"vfc_2578","program":"```python\nT=int(input()) # cook your dish here\nfor i in range(T): \n n=list(map(int,input().split()))\n a=n[0]\n b=n[1]\n c=n[2]\n l=[]\n A=list(map(int,input().split()))\n B=list(map(int,input().split()))\n C=list(map(int,input().split()))\n for i in range(b):\n for j in range(a):\n for k in range(c):\n if(A[j]<=B[i] and B[i]>=C[k]):\n sum=((A[j]+B[i])*(B[i]+C[k]))\n l.append(int(sum))\n \n \n \n \n sum=0\n for i in range(len(l)):\n sum+=int(l[i])\n print(sum%1000000007)\n```","inputs":"1 \n3 1 3\n1 2 3\n5\n4 5 6\n\n\n","output":"399\n","actual_output":"399\n","execution_success":true,"sample_index":537},{"source":"apps","task_type":"verifiable_code","in_source_id":"935","prompt":"Solve the following coding problem using the programming language python:\n\nChef Two and Chef Ten are playing a game with a number $X$. In one turn, they can multiply $X$ by $2$. The goal of the game is to make $X$ divisible by $10$.\nHelp the Chefs find the smallest number of turns necessary to win the game (it may be possible to win in zero turns) or determine that it is impossible.\n\n-----Input-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The first and only line of each test case contains a single integer denoting the initial value of $X$. \n\n-----Output-----\nFor each test case, print a single line containing one integer \u2014 the minimum required number of turns or $-1$ if there is no way to win the game.\n\n-----Constraints-----\n- $1 \\le T \\le 1000$\n- $0 \\le X \\le 10^9$\n\n-----Subtasks-----\nSubtask #1 (100 points): original constraints\n\n-----Example Input-----\n3\n10\n25\n1\n\n-----Example Output-----\n0\n1\n-1\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\nt=int(input())\nfor i in range(t):\n x=int(input())\n if x%10==0:\n print(0)\n elif x%5==0:\n print(1)\n else:\n print(-1)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\n10\\n25\\n1\\n', 'output': '0\\n1\\n-1\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/TWOVSTEN'}","problem_id":"vfc_2582","program":"```python\n# cook your dish here\nt=int(input())\nfor i in range(t):\n x=int(input())\n if x%10==0:\n print(0)\n elif x%5==0:\n print(1)\n else:\n print(-1)\n```","inputs":"3\n10\n25\n1\n","output":"0\n1\n-1\n","actual_output":"0\n1\n-1\n","execution_success":true,"sample_index":538},{"source":"apps","task_type":"verifiable_code","in_source_id":"936","prompt":"Solve the following coding problem using the programming language python:\n\nChef Ada has a matrix with $N$ rows (numbered $1$ through $N$ from top to bottom) and $N$ columns (numbered $1$ through $N$ from left to right) containing all integers between $1$ and $N^2$ inclusive. For each valid $i$ and $j$, let's denote the cell in the $i$-th row and $j$-th column by $(i,j)$.\nAda wants to sort the matrix in row-major order \u2015 for each valid $i$ and $j$, she wants the cell $(i, j)$ to contain the value $(i-1) \\cdot N + j$.\nIn one operation, Ada should choose an integer $L$ and transpose the submatrix between rows $1$ and $L$ and columns $1$ and $L$ (inclusive). Formally, for each $i$ and $j$ ($1 \\le i, j \\le L$), the value in the cell $(i, j)$ after this operation is equal to the value in $(j, i)$ before it.\nThe initial state of the matrix is chosen in such a way that it is possible to sort it using a finite number of operations (possibly zero). Find the smallest number of operations required to sort the matrix.\n\n-----Input-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The first line of each test case contains a single integer $N$.\n- The next $N$ lines describe the matrix. For each valid $i$, the $i$-th of these lines contains $N$ space-separated integers \u2015 the initial values in cells $(i, 1), (i, 2), \\ldots, (i, N)$.\n\n-----Output-----\nFor each test case, print a single line containing one integer \u2015 the smallest number of operations required to sort the matrix.\n\n-----Constraints-----\n- $4 \\le N \\le 64$\n- the sum of $N^2$ over all test files does not exceed $3 \\cdot 10^5$\n\n-----Subtasks-----\nSubtask #1 (10 points):\n- $T \\le 50$\n- $N = 4$\nSubtask #2 (90 points): original constraints\n\n-----Example Input-----\n1\n4\n1 2 9 13\n5 6 10 14\n3 7 11 15\n4 8 12 16\n\n-----Example Output-----\n2\n\n-----Explanation-----\nExample case 1: After the first operation, with $L = 2$, the resulting matrix is\n1 5 9 13\n2 6 10 14\n3 7 11 15\n4 8 12 16\n\nAfter the second operation, with $L = 4$, the matrix becomes sorted\n1 2 3 4\n5 6 7 8\n9 10 11 12\n13 14 15 16\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfor _ in range(int(input())):\n n=int(input())\n a=[]\n l=0\n for i in range(n):\n a.append(list(map(int,input().split())))\n for i in range(n-1,0,-1):\n r=a[i][i-1]+1\n if a[i][i]!=r:\n l+=1\n n=i+1\n for j in range(n):\n for k in range(j,n):\n a[j][k],a[k][j]=a[k][j],a[j][k]\n \n print(l)\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n4\\n1 2 9 13\\n5 6 10 14\\n3 7 11 15\\n4 8 12 16\\n', 'output': '2\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/ADAMAT'}","problem_id":"vfc_2586","program":"```python\nfor _ in range(int(input())):\n n=int(input())\n a=[]\n l=0\n for i in range(n):\n a.append(list(map(int,input().split())))\n for i in range(n-1,0,-1):\n r=a[i][i-1]+1\n if a[i][i]!=r:\n l+=1\n n=i+1\n for j in range(n):\n for k in range(j,n):\n a[j][k],a[k][j]=a[k][j],a[j][k]\n \n print(l)\n\n```","inputs":"1\n4\n1 2 9 13\n5 6 10 14\n3 7 11 15\n4 8 12 16\n","output":"2\n","actual_output":"2\n","execution_success":true,"sample_index":539},{"source":"apps","task_type":"verifiable_code","in_source_id":"937","prompt":"Solve the following coding problem using the programming language python:\n\nChef's daily routine is very simple. He starts his day with cooking food, then he eats the food and finally proceeds for sleeping thus ending his day. Chef carries a robot as his personal assistant whose job is to log the activities of Chef at various instants during the day. Today it recorded activities that Chef was doing at N different instants. These instances are recorded in chronological order (in increasing order of time). This log is provided to you in form of a string s of length N, consisting of characters 'C', 'E' and 'S'. If s[i] = 'C', then it means that at the i-th instant Chef was cooking, 'E' denoting he was eating and 'S' means he was sleeping.\nYou have to tell whether the record log made by the robot could possibly be correct or not. \n\n-----Input-----\nThe first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.\nThe only line of each test case contains string s.\n\n-----Output-----\nFor each test case, output a single line containing \"yes\" or \"no\" (without quotes) accordingly.\n\n-----Constraints-----\n- 1 \u2264 T \u2264 20\n- 1 \u2264 N \u2264 105\n\n-----Subtasks-----\n- Subtask #1 (40 points) : 1 \u2264 N \u2264 100\n- Subtask #2 (60 points) : original constraints\n\n-----Example-----\nInput:\n5\nCES\nCS\nCCC\nSC\nECCC\n\nOutput:\nyes\nyes\nyes\nno\nno\n\n-----Explanation-----\nExample case 1. \"CES\" can correspond to a possible record of activities of Chef. He starts the day with cooking, then eating and then sleeping.\nExample case 2. \"CS\" can also correspond to a possible record of activities of Chef. He starts the day with cooking, then eating and then sleeping. Robot recorded his cooking and sleeping in order. He might not have recorded his eating activity.\nExample case 4. \"SC\" can not correspond to Chef's activities. Here it means that Chef slept first, then he cooked the food, which is impossible for Chef to do on some particular day.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\nt=int(input())\nfor _ in range(t):\n s=input()\n k=len(s)\n count=0\n for i in range(k-1):\n if(s[i]==\"C\"):\n if(s[i+1]=='E'or s[i+1]=='S' or s[i+1]==\"C\"):\n count+=1 \n elif(s[i]==\"E\"):\n if(s[i+1]==\"S\"or s[i+1]=='E'):\n count+=1 \n elif(s[i]==\"S\"):\n if(s[i+1]==\"S\"):\n count+=1 \n if (count==k-1):\n print(\"yes\")\n else:\n print(\"no\")\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '5\\nCES\\nCS\\nCCC\\nSC\\nECCC\\n', 'output': 'yes\\nyes\\nyes\\nno\\nno\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/CHEFROUT'}","problem_id":"vfc_2590","program":"```python\n# cook your dish here\nt=int(input())\nfor _ in range(t):\n s=input()\n k=len(s)\n count=0\n for i in range(k-1):\n if(s[i]==\"C\"):\n if(s[i+1]=='E'or s[i+1]=='S' or s[i+1]==\"C\"):\n count+=1 \n elif(s[i]==\"E\"):\n if(s[i+1]==\"S\"or s[i+1]=='E'):\n count+=1 \n elif(s[i]==\"S\"):\n if(s[i+1]==\"S\"):\n count+=1 \n if (count==k-1):\n print(\"yes\")\n else:\n print(\"no\")\n```","inputs":"5\nCES\nCS\nCCC\nSC\nECCC\n","output":"yes\nyes\nyes\nno\nno\n","actual_output":"yes\nyes\nyes\nno\nno\n","execution_success":true,"sample_index":540},{"source":"apps","task_type":"verifiable_code","in_source_id":"939","prompt":"Solve the following coding problem using the programming language python:\n\nChef loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.\n\nLet F(X) equals to the number of lucky digits in decimal representation of X. Chef wants to know the number of such integers X, that L \u2264 X \u2264 R and F(X) is a lucky number. Help him and calculate that number modulo 109+7.\n\n-----Input-----\nFirst line contains one integer T, the number of test cases. Each of the following T lines contains two space separated positive integers L and R.\n\n-----Output-----\nFor each of the T test cases print one integer, the number of such X, that L \u2264 X \u2264 R and F(X) is a lucky number, modulo 1000000007.\n\n-----Constraints-----\n\n1 \u2264 T \u2264 10\n\n1 \u2264 L \u2264 R \u2264 101000\n\n-----Example-----\nInput:\n4\n1 100\n1 10000\n1 100000\n4444 4447\n\nOutput:\n0\n16\n640\n2\n\n-----Notes-----\nFirst test case: of course, any number of less than 4 digits can't contain lucky number of lucky digits, so the answer is 0.\n\nSecond test case: 16 required numbers are 4444 4447 4474 4477 4744 4747 4774 4777 7444 7447 7474 7477 7744 7747 7774 7777.\n\nThird test case: there are 640 required lucky numbers. Some of them are 4474, 14747, 41474, 77277, 44407, 74749.\n\nFourth test case: the only two required numbers are 4444 and 4447.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nlucky = {4, 774, 7, 744, 777, 74, 747, 44, 77, 47, 474, 444, 477, 447}\nfrom functools import lru_cache\nimport sys \nsys.setrecursionlimit(10 ** 6)\nmod = 10 ** 9 + 7\nfact = [1]\nfor i in range(1, 1001):\n fact.append(fact[-1] * i % mod)\ninv = [pow(i, mod-2, mod) for i in fact]\nC = lambda k, n: fact[n] * inv[n-k] * inv[k] % mod\ndef f(n):\n n = [int(x) for x in n]\n @lru_cache(None)\n def dp(pos, cnt, free):\n if cnt > 777:\n return 0\n diff = len(n) - pos \n ans = 0\n if free:\n for i in lucky:\n i -= cnt\n if 0 <= i <= diff:\n ans += C(i, diff) * pow(2, i, mod) * pow(8, diff - i, mod)\n ans %= mod \n return ans\n if pos == len(n):\n return int(cnt in lucky)\n for i in range(10 if free else n[pos]+1):\n ans += dp(pos+1, cnt + int(i == 4 or i == 7), free or i < n[pos])\n ans %= mod \n return ans \n return dp(0, 0, 0)\n \nt = int(input())\nfor _ in range(t):\n l, r = input().split()\n l = str(int(l) -1) \n print((f(r) - f(l)) % mod)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '4\\n1 100\\n1 10000\\n1 100000\\n4444 4447\\n\\n\\n', 'output': '0\\n16\\n640\\n2\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/LUCKY2'}","problem_id":"vfc_2598","program":"```python\nlucky = {4, 774, 7, 744, 777, 74, 747, 44, 77, 47, 474, 444, 477, 447}\nfrom functools import lru_cache\nimport sys \nsys.setrecursionlimit(10 ** 6)\nmod = 10 ** 9 + 7\nfact = [1]\nfor i in range(1, 1001):\n fact.append(fact[-1] * i % mod)\ninv = [pow(i, mod-2, mod) for i in fact]\nC = lambda k, n: fact[n] * inv[n-k] * inv[k] % mod\ndef f(n):\n n = [int(x) for x in n]\n @lru_cache(None)\n def dp(pos, cnt, free):\n if cnt > 777:\n return 0\n diff = len(n) - pos \n ans = 0\n if free:\n for i in lucky:\n i -= cnt\n if 0 <= i <= diff:\n ans += C(i, diff) * pow(2, i, mod) * pow(8, diff - i, mod)\n ans %= mod \n return ans\n if pos == len(n):\n return int(cnt in lucky)\n for i in range(10 if free else n[pos]+1):\n ans += dp(pos+1, cnt + int(i == 4 or i == 7), free or i < n[pos])\n ans %= mod \n return ans \n return dp(0, 0, 0)\n \nt = int(input())\nfor _ in range(t):\n l, r = input().split()\n l = str(int(l) -1) \n print((f(r) - f(l)) % mod)\n```","inputs":"4\n1 100\n1 10000\n1 100000\n4444 4447\n\n\n","output":"0\n16\n640\n2\n","actual_output":"0\n16\n640\n2\n","execution_success":true,"sample_index":542},{"source":"apps","task_type":"verifiable_code","in_source_id":"940","prompt":"Solve the following coding problem using the programming language python:\n\nChef has a circular plot of land of radius $R$ on which he wants to construct a swimming pool.\nHe wants the swimming pool to be square in shape with maximum possible area,so that he along\nwith his friends can enjoy themselves during their summer vacations.\nHelp Chef to find out the maximum area of the swimming pool that can be constructed in his \ncircular plot.\n\n-----Input:-----\n- First line will contain $T$, number of testcases. Then the testcases follow. \n- Each testcase contains of a single line of input, $R$ i.e the radius of the plot. \n\n-----Output:-----\nFor each testcase, output in a single line answer displaying the maximum possible area of the swimming pool.\n\n-----Constraints-----\n- $1 \\leq T \\leq 1000$\n- $1 \\leq R \\leq 10^8$\n\n-----Sample Input:-----\n2\n\n5\n\n10 \n\n-----Sample Output:-----\n50\n\n200\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nT=int(input())\r\nl=[]\r\nfor t in range(T):\r\n R=int(input())\r\n a=2*(R**2)\r\n l.append(a)\r\nfor s in l:\r\n print(s)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n5\\n10\\n', 'output': '50\\n200\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/ENCD2020/problems/ECAPR202'}","problem_id":"vfc_2602","program":"```python\nT=int(input())\r\nl=[]\r\nfor t in range(T):\r\n R=int(input())\r\n a=2*(R**2)\r\n l.append(a)\r\nfor s in l:\r\n print(s)\n```","inputs":"2\n5\n10\n","output":"50\n200\n","actual_output":"50\n200\n","execution_success":true,"sample_index":543},{"source":"apps","task_type":"verifiable_code","in_source_id":"941","prompt":"Solve the following coding problem using the programming language python:\n\nYou are given two positive integers $A$ and $B$. Find the number of pairs of positive integers $(X, Y)$ such that $1 \\le X \\le A$, $1 \\le Y \\le B$ and $X + Y$ is even.\n\n-----Input-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The first and only line of each test case contains two space-separated integers $A$ and $B$.\n\n-----Output-----\nFor each test case, print a single line containing one integer \u2015 the number of valid pairs.\n\n-----Constraints-----\n- $1 \\le T \\le 1,000$\n- $1 \\le A, B \\le 10^9$\n\n-----Subtasks-----\nSubtask #1 (10 points): $A, B \\le 10$\nSubtask #2 (10 points): $A, B \\le 1,000$\nSubtask #3 (80 points): original constraints\n\n-----Example Input-----\n4\n1 1\n2 3\n4 6\n8 9\n\n-----Example Output-----\n1\n3\n12\n36\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\ntry:\n t=int(input())\n while t>0:\n [a,b]=[int(x) for x in input().split()]\n if a==1 and b==1:\n print(1)\n continue\n if a%2==0:\n o1=a//2\n e1=a//2\n else:\n o1=a//2+1\n e1=a//2\n \n if b%2==0:\n o2=b//2\n e2=b//2\n else:\n o2=b//2+1\n e2=b//2\n \n print(e1*e2+o1*o2)\n t-=1\nexcept:\n pass\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '4\\n1 1\\n2 3\\n4 6\\n8 9\\n', 'output': '1\\n3\\n12\\n36\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/EVENPSUM'}","problem_id":"vfc_2606","program":"```python\ntry:\n t=int(input())\n while t>0:\n [a,b]=[int(x) for x in input().split()]\n if a==1 and b==1:\n print(1)\n continue\n if a%2==0:\n o1=a//2\n e1=a//2\n else:\n o1=a//2+1\n e1=a//2\n \n if b%2==0:\n o2=b//2\n e2=b//2\n else:\n o2=b//2+1\n e2=b//2\n \n print(e1*e2+o1*o2)\n t-=1\nexcept:\n pass\n```","inputs":"4\n1 1\n2 3\n4 6\n8 9\n","output":"1\n3\n12\n36\n","actual_output":"1\n3\n12\n36\n","execution_success":true,"sample_index":544},{"source":"apps","task_type":"verifiable_code","in_source_id":"942","prompt":"Solve the following coding problem using the programming language python:\n\nYou are given $N$ integers in an array: $A[1], A[2], \\ldots, A[N]$. You also have another integer $L$.\nConsider a sequence of indices ($i_1, i_2, \\ldots, i_k$). Note that a particular index can occur multiple times in the sequence, and there is no order in which these indices have to occur. ($i_1, i_2, \\ldots, i_k$) is a sequence of size $k$. It is said to be an $Interesting$ sequence, if $A[i_1] \\ge A[i_2] \\ge \\ldots \\ge A[i_k]$.\nThe $Cost$ of an Interesting sequence ($i_1, i_2, \\ldots, i_k$), is defined to be the minimum absolute difference between any two adjacent indices. In other words, the Cost is $min \\{ |i_2 - i_1|, |i_3 - i_2|, \\ldots, |i_k - i_{k-1}| \\}$.\nYour job is to consider the Costs of all the Interesting sequences of size $L$ associated with the given array, and output the maximum Cost. Note that you can show that there is always at least one Interesting sequence for the given constraints.\n\n-----Input-----\n- The first line contains a single integer, $T$, which is the number of testcases. The description of each testcase follows.\n- The first line of each testcase contains two space separated integers: $N$ and $L$.\n- The second line of each testcase contains $N$ space separated integers: $A[1], A[2], \\ldots, A[N]$.\n\n-----Output-----\n- For each testcase, output the answer in a new line.\n\n-----Constraints-----\n- $1 \\leq T \\leq 3$\n- $1 \\leq A[i] \\leq 10^9$\n- $2 \\leq L \\leq 10^9$\n\n-----Subtasks-----\n- Subtask 1: 7 points\n- It is guaranteed that $A[1] > A[2] > \\ldots > A[N]$\n- Note that the above condition implies that all elements are distinct.\n- $1 \\leq N \\leq 500$\n- Subtask 2: 7 points\n- It is guaranteed that $A[1] \\ge A[2] \\ge \\ldots \\ge A[N]$\n- $1 \\leq N \\leq 500$\n- Subtask 3: 14 points\n- It is guaranteed that all elements are distinct.\n- $1 \\leq N \\leq 500$\n- Subtask 4: 14 points\n- $1 \\leq N \\leq 500$\n- Subtask 5: 25 points\n- It is guaranteed that all elements are distinct.\n- $1 \\leq N \\leq 3000$\n- Subtask 6: 33 points\n- $1 \\leq N \\leq 3000$\n\n-----Sample Input-----\n1\n6 3\n2 4 1 12 3 5\n\n-----Sample Output-----\n3\n\n-----Explanation-----\nWe are looking for Interesting sequences of length 3. Some of them are:\n- (4, 2, 3): This is Interesting because $A[4] \\ge A[2] \\ge A[3]$. Its cost is $min \\{ |2-4|, |3-2|\\} = 1$.\n- (5, 1, 1): Cost is 0.\n- (2, 2, 2): Cost is 0.\n- (6, 1, 3): Cost is 2.\n- (6, 2, 5): Cost is 3.\nThere are other Interesting Sequences of length 3 as well. But if you list them all out, you'll see that the maximum Cost is 3. Hence the answer is 3.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\n# from queue import PriorityQueue\n# import bisect\ndef insort(l, v):\n s = 0\n e = len(l)\n while True:\n mid = (s+e)//2\n if s == e or mid > len(l):\n break\n if l[mid][0] < v[0]:\n s = mid+1\n elif l[mid][0] > v[0]:\n e = mid\n else:\n break\n l.insert(mid, v)\n \nfor _ in range(int(input())):\n n,l = map(int, input().split())\n a_l = list(map(int, input().split()))\n \n dic = {}\n dif = 0\n for i,v in enumerate(a_l, start=1):\n if v not in dic:\n dic[v] = [i, i]\n else:\n dic[v][0] = min(dic[v][0], i)\n dic[v][1] = max(dic[v][1], i)\n dif = max(dif, dic[v][1]-dic[v][0])\n \n ans = dif\n if l <= len(set(a_l)):\n i_l = [[v,i] for i,v in enumerate(a_l, start=1)]\n i_l.sort(reverse=True)\n \n dp = [[-1 for _ in range(l)] for _ in range(n)]\n pq_l = [[] for _ in range(l)]\n for i in range(1,n):\n il = 1\n dif_l = []\n for j in range(i):\n dif = abs(i_l[i][1]-i_l[j][1])\n dif_l.append(dif)\n dp[i][il] = max(dp[i][il], dif)\n \n for il in range(2,min(l,i+1)):\n for prev_max, ind in reversed(pq_l[il-1]):\n if ind == i:\n continue\n if prev_max < dp[i][il]:\n break\n else:\n dp[i][il] = max(dp[i][il], min(dif_l[ind], prev_max))\n insort(pq_l[il], [dp[i][il], i])\n # tmp = [v[0] for v in pq_l[il]]\n # ind = bisect.bisect_right(tmp, dp[i][il])\n # pq_l[il].insert(ind, [dp[i][il], i])\n \n il = 1\n insort(pq_l[il], [dp[i][il], i])\n # tmp = [v[0] for v in pq_l[il]]\n # ind = bisect.bisect_right(tmp, dp[i][il])\n # pq_l[il].insert(ind, [dp[i][il], i])\n \n # print(i, pq_l, dif_l)\n \n \n # dp[i][1] = max(dp[i][1], dif)\n # for il in range(2,l):\n # if dp[j][il-1] == -1:\n # break\n # dp[i][il] = max(dp[i][il], min(dif, dp[j][il-1]))\n ans = max(ans, dp[i][-1])\n # print(dp)\n # print(dic)\n print(ans)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n6 3\\n2 4 1 12 3 5\\n', 'output': '3\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/INOIPRAC/problems/INOI1902'}","problem_id":"vfc_2610","program":"```python\n# cook your dish here\n# from queue import PriorityQueue\n# import bisect\ndef insort(l, v):\n s = 0\n e = len(l)\n while True:\n mid = (s+e)//2\n if s == e or mid > len(l):\n break\n if l[mid][0] < v[0]:\n s = mid+1\n elif l[mid][0] > v[0]:\n e = mid\n else:\n break\n l.insert(mid, v)\n \nfor _ in range(int(input())):\n n,l = map(int, input().split())\n a_l = list(map(int, input().split()))\n \n dic = {}\n dif = 0\n for i,v in enumerate(a_l, start=1):\n if v not in dic:\n dic[v] = [i, i]\n else:\n dic[v][0] = min(dic[v][0], i)\n dic[v][1] = max(dic[v][1], i)\n dif = max(dif, dic[v][1]-dic[v][0])\n \n ans = dif\n if l <= len(set(a_l)):\n i_l = [[v,i] for i,v in enumerate(a_l, start=1)]\n i_l.sort(reverse=True)\n \n dp = [[-1 for _ in range(l)] for _ in range(n)]\n pq_l = [[] for _ in range(l)]\n for i in range(1,n):\n il = 1\n dif_l = []\n for j in range(i):\n dif = abs(i_l[i][1]-i_l[j][1])\n dif_l.append(dif)\n dp[i][il] = max(dp[i][il], dif)\n \n for il in range(2,min(l,i+1)):\n for prev_max, ind in reversed(pq_l[il-1]):\n if ind == i:\n continue\n if prev_max < dp[i][il]:\n break\n else:\n dp[i][il] = max(dp[i][il], min(dif_l[ind], prev_max))\n insort(pq_l[il], [dp[i][il], i])\n # tmp = [v[0] for v in pq_l[il]]\n # ind = bisect.bisect_right(tmp, dp[i][il])\n # pq_l[il].insert(ind, [dp[i][il], i])\n \n il = 1\n insort(pq_l[il], [dp[i][il], i])\n # tmp = [v[0] for v in pq_l[il]]\n # ind = bisect.bisect_right(tmp, dp[i][il])\n # pq_l[il].insert(ind, [dp[i][il], i])\n \n # print(i, pq_l, dif_l)\n \n \n # dp[i][1] = max(dp[i][1], dif)\n # for il in range(2,l):\n # if dp[j][il-1] == -1:\n # break\n # dp[i][il] = max(dp[i][il], min(dif, dp[j][il-1]))\n ans = max(ans, dp[i][-1])\n # print(dp)\n # print(dic)\n print(ans)\n```","inputs":"1\n6 3\n2 4 1 12 3 5\n","output":"3\n","actual_output":"3\n","execution_success":true,"sample_index":545},{"source":"apps","task_type":"verifiable_code","in_source_id":"943","prompt":"Solve the following coding problem using the programming language python:\n\nTejas has invited the Clash Team for a Dinner Party. He places V empty plates (numbered from 1 to V inclusive) in a straight line on a table. He has prepared 2 kinds of Delicious Dishes named dish A and dish B.\n\nHe has exactly V servings of Dish A and W servings of dish B. \n\nNow he wants to serve the dishes in such a way that if theith plate has serving of Dish A then (i-1)th plate should not have serving of Dish B. Assuming all the Dishes are identical find number of ways Tejas can serve the Clash Team.\n\n-----Input-----\n- The first line of the input contains an integer T denoting the number of test cases . The description of T testcases follow.\n\n- The first line of each test case contains two space seperated integers V W .\n\n-----Output-----\nFor each test case, output the number of ways Tejas can serve the Clash Team.\n\n\n-----Constraints-----\n\n- 1 \u2264 T \u2264 100\n- 1 \u2264 V \u2264 1000\n- 1 \u2264 W \u2264 1000\n\n-----Example-----\nInput:\n\n1\n\n3 3 \n\nOutput:\n4\n\n\n\n-----Explanation-----\n\nIn the above example the 4 ways are:\n\nAAA\n\nAAB\n\nABB\n\nBBB\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\nt=int(input())\nfor i in range(t):\n v,w=list(map(int,input().strip().split(\" \")))\n if v==w:\n print(v+1)\n elif v1:\n prev=graph[i][0]\n for j in range(1,len(graph[i])):\n index2=graph[i][j]\n index1=prev\n prev=index2\n #print(index1,index2)\n if i%2==0:\n val=prefix_even[index2]-prefix_even[index1]-1\n #print(val)\n if val%2==0:\n temp_sum=prefix_sum[index2]-prefix_sum[index1]-i\n #print(temp_sum)\n if temp_sum>max_sum:\n max_sum=temp_sum\n else:\n val=prefix_odd[index2]-prefix_odd[index1]-1\n #print(val)\n if val%2!=0:\n temp_sum=prefix_sum[index2]-prefix_sum[index1]-i\n #print(temp_sum)\n if temp_sum>max_sum:\n max_sum=temp_sum\n\n '''max_sum=-1\n for i in range(n):\n if count[lst[i]]>1:\n index2=dict[lst[i]]\n index1=i\n print(index1,index2)\n if lst[i]%2==0:\n val=prefix_even[index2]-prefix_even[index1]-1\n print(val)\n if val%2==0:\n temp_sum=prefix_sum[index2]-prefix_sum[index1]-lst[i]\n print(temp_sum)\n if temp_sum>max_sum:\n max_sum=temp_sum\n else:\n val=prefix_odd[index2]-prefix_odd[index1]-1\n print(val)\n if val%2!=0:\n temp_sum=prefix_sum[index2]-prefix_sum[index1]-lst[i]\n print(temp_sum)\n if temp_sum>max_sum:\n max_sum=temp_sum'''\n \n stdout.write(str(max_sum)+'\\n')\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n10\\n1 2 3 2 1 5 1 2 8 2\\n', 'output': '7\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/CFUS2020/problems/CFS2002'}","problem_id":"vfc_2618","program":"```python\n# cook your dish here\nfrom sys import stdin, stdout\nfrom collections import defaultdict\nfor _ in range(int(stdin.readline())):\n n=int(stdin.readline())\n lst=list(map(int, stdin.readline().split()))\n prefix_odd=[0]*n\n prefix_even=[0]*n\n odd_val=0\n even_val=0\n for i in range(n):\n if lst[i]%2==0:\n even_val+=1 \n else:\n odd_val+=1\n prefix_even[i]=even_val\n prefix_odd[i]=odd_val\n #print(prefix_odd,prefix_even)\n prefix_sum=[0]*n\n s=0\n for i in range(n):\n s+=lst[i]\n prefix_sum[i]=s\n #print(prefix_sum)\n dict={}\n count={}\n for i in range(n):\n if lst[i] not in dict:\n dict[lst[i]]=i\n count[lst[i]]=1\n else:\n dict[lst[i]]=i\n count[lst[i]]+=1\n #print(dict)\n graph=defaultdict(list)\n for i in range(n):\n graph[lst[i]].append(i)\n max_sum=0\n for i in graph:\n if len(graph[i])>1:\n prev=graph[i][0]\n for j in range(1,len(graph[i])):\n index2=graph[i][j]\n index1=prev\n prev=index2\n #print(index1,index2)\n if i%2==0:\n val=prefix_even[index2]-prefix_even[index1]-1\n #print(val)\n if val%2==0:\n temp_sum=prefix_sum[index2]-prefix_sum[index1]-i\n #print(temp_sum)\n if temp_sum>max_sum:\n max_sum=temp_sum\n else:\n val=prefix_odd[index2]-prefix_odd[index1]-1\n #print(val)\n if val%2!=0:\n temp_sum=prefix_sum[index2]-prefix_sum[index1]-i\n #print(temp_sum)\n if temp_sum>max_sum:\n max_sum=temp_sum\n\n '''max_sum=-1\n for i in range(n):\n if count[lst[i]]>1:\n index2=dict[lst[i]]\n index1=i\n print(index1,index2)\n if lst[i]%2==0:\n val=prefix_even[index2]-prefix_even[index1]-1\n print(val)\n if val%2==0:\n temp_sum=prefix_sum[index2]-prefix_sum[index1]-lst[i]\n print(temp_sum)\n if temp_sum>max_sum:\n max_sum=temp_sum\n else:\n val=prefix_odd[index2]-prefix_odd[index1]-1\n print(val)\n if val%2!=0:\n temp_sum=prefix_sum[index2]-prefix_sum[index1]-lst[i]\n print(temp_sum)\n if temp_sum>max_sum:\n max_sum=temp_sum'''\n \n stdout.write(str(max_sum)+'\\n')\n```","inputs":"1\n10\n1 2 3 2 1 5 1 2 8 2\n","output":"7\n","actual_output":"7\n","execution_success":true,"sample_index":547},{"source":"apps","task_type":"verifiable_code","in_source_id":"945","prompt":"Solve the following coding problem using the programming language python:\n\nNow that Chef has finished baking and frosting his cupcakes, it's time to package them. Chef has N cupcakes, and needs to decide how many cupcakes to place in each package. Each package must contain the same number of cupcakes. Chef will choose an integer A between 1 and N, inclusive, and place exactly A cupcakes into each package. Chef makes as many packages as possible. Chef then gets to eat the remaining cupcakes. Chef enjoys eating cupcakes very much. Help Chef choose the package size A that will let him eat as many cupcakes as possible.\n\n-----Input-----\n\nInput begins with an integer T, the number of test cases. Each test case consists of a single integer N, the number of cupcakes.\n\n-----Output-----\n\nFor each test case, output the package size that will maximize the number of leftover cupcakes. If multiple package sizes will result in the same number of leftover cupcakes, print the largest such size.\n\n-----Constraints-----\n- 1 \u2264 T \u2264 1000\n- 2 \u2264 N \u2264 100000000 (108)\n\n-----Sample Input-----\n2\n2\n5\n\n-----Sample Output-----\n2\n3\n\n-----Explanation-----\n\nIn the first test case, there will be no leftover cupcakes regardless of the size Chef chooses, so he chooses the largest possible size. In the second test case, there will be 2 leftover cupcakes.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfor i in range(int(input())):\n n=int(input())\n print(n//2+1)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n2\\n5\\n', 'output': '2\\n3\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/MUFFINS3'}","problem_id":"vfc_2622","program":"```python\nfor i in range(int(input())):\n n=int(input())\n print(n//2+1)\n```","inputs":"2\n2\n5\n","output":"2\n3\n","actual_output":"2\n3\n","execution_success":true,"sample_index":548},{"source":"apps","task_type":"verifiable_code","in_source_id":"947","prompt":"Solve the following coding problem using the programming language python:\n\nIn this problem we are concerned with words constructed using the lowercase letters of the English alphabet - that is, a,b,c,\u2026,z. These words need not necessarily be meaningful: any sequence of letters forms a word. For example, abbca is a word.\nWe say that we can \"hop\" from the word $w_1$ to the word $w_2$ if they are \"sufficiently close\". We define $w_2$ to be sufficiently close to $w_1$ if one of the following holds:\n- $w_2$ is obtained from $w_1$ by deleting one letter.\n- $w_2$ is obtained from $w_1$ by replacing one of the letters in $w_1$ by some letter that appears to its right in $w_1$ and which is also to its right in alphabetical order.\nFor example, we can hop from abbca to abca by deleting the second (or third letter). We can hop from aabca to abbca by replacing the a in the second position by the letter b that appears to the right of the a in aabca and which is also to its right in alphabetical order. On the other hand we cannot hop from abbca to aabca since we would need to replace the b in the second position by a, but a is to the left of b in alphabetical order.\nYou will be given a collection of words $W$. Your task is to find the length of the longest sequence $w_1, w_2, \\ldots $ of distinct words from $W$ such that we may hop from $w_1$ to $w_2$, $w_2$ to $w_3$ and so on. We call this the hopping number for this set.\nFor example, if\n$W$ = {abacd, bcdada, dd, abcd,bcdd, adcd, addd, aa, ccd, add, ad}\nthen, the hopping number is 7 corresponding to the sequence\nabacd, abcd, adcd, addd, add, ad, dd\n\n-----Input Format:-----\n- The first line of the input contains one integer $N$ indicating the number of words in the input. \n- This is followed by $N$ lines of input, lines 2, 3,\u2026, $N$+1, each containing one word over the letters {a,b,\u2026, z}.\n\n-----Output Format:-----\nThe output should be a single integer, indicating the hopping number of the given set of words.\n\n-----Test Data:-----\n- $N \\leq 100$\n- You may assume that each word has at most 10 letters.\n\n-----Sample Input:-----\n11\nabacd\nbcdada\ndd\nabcd\nbcdd\nadcd\naddd\naa\nccd\nadd\nad\n\n-----Sample Output:-----\n7\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\ndef codn1(s1,s2,p):\r\n\tc=0\r\n\tind=0\r\n\tfor i in range(len(s1)):\r\n\t\tif s1[i]!=s2[i]:\r\n\t\t\tc+=1\r\n\t\t\tind=i\r\n\tif c>1 or ind==len(s1)-1:\r\n\t\treturn 0\r\n\tif s1[ind]>s2[ind] and s1[ind] in s2[ind+1:]:\r\n\t\tp[0]=True\r\n\tif s1[ind]0:\r\n\t\treturn cost[k]\r\n\tfor i in list(d[k]):\r\n\t\t\tcost[k]=max(cost[k],longest(i)+1)\r\n\treturn cost[k]\r\n\r\nn=int(input())\r\nl=[]\r\n#parent=[0]*n\r\nd={}\r\ncost={}\r\nfor i in range(n):\r\n\tl.append(input())\r\n\td[i]=[]\r\n\tcost[i]=0\r\n\r\nfor i in range(n):\r\n\tfor j in range(n):\r\n\t\tif i!=j:\r\n\t\t\tp=[False,False]\r\n\t\t\tif len(l[i])==len(l[j]):\r\n\t\t\t\tif codn1(l[i],l[j],p):\r\n\t\t\t\t\tif p[0]==True:\r\n\t\t\t\t\t\td[j].append(i)\r\n\t\t\t\t\tif p[1]==True:\r\n\t\t\t\t\t\td[i].append(j)\r\n\t\t\telif abs(len(l[i])-len(l[j]))==1:\r\n\t\t\t\ty=codn2(l[i],l[j])\r\n\t\t\t\tif y==1:\r\n\t\t\t\t\td[j].append(i)\r\n\t\t\t\tif y==2:\r\n\t\t\t\t\td[i].append(j)\r\nans=0\r\n#print(d)\r\n\r\nfor i in range(n):\r\n\tans=max(ans,longest(i))\r\nprint(ans+1)\r\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '11\\nabacd\\nbcdada\\ndd\\nabcd\\nbcdd\\nadcd\\naddd\\naa\\nccd\\nadd\\nad\\n', 'output': '7\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/IARCSJUD/problems/WORDHOP'}","problem_id":"vfc_2630","program":"```python\ndef codn1(s1,s2,p):\r\n\tc=0\r\n\tind=0\r\n\tfor i in range(len(s1)):\r\n\t\tif s1[i]!=s2[i]:\r\n\t\t\tc+=1\r\n\t\t\tind=i\r\n\tif c>1 or ind==len(s1)-1:\r\n\t\treturn 0\r\n\tif s1[ind]>s2[ind] and s1[ind] in s2[ind+1:]:\r\n\t\tp[0]=True\r\n\tif s1[ind]0:\r\n\t\treturn cost[k]\r\n\tfor i in list(d[k]):\r\n\t\t\tcost[k]=max(cost[k],longest(i)+1)\r\n\treturn cost[k]\r\n\r\nn=int(input())\r\nl=[]\r\n#parent=[0]*n\r\nd={}\r\ncost={}\r\nfor i in range(n):\r\n\tl.append(input())\r\n\td[i]=[]\r\n\tcost[i]=0\r\n\r\nfor i in range(n):\r\n\tfor j in range(n):\r\n\t\tif i!=j:\r\n\t\t\tp=[False,False]\r\n\t\t\tif len(l[i])==len(l[j]):\r\n\t\t\t\tif codn1(l[i],l[j],p):\r\n\t\t\t\t\tif p[0]==True:\r\n\t\t\t\t\t\td[j].append(i)\r\n\t\t\t\t\tif p[1]==True:\r\n\t\t\t\t\t\td[i].append(j)\r\n\t\t\telif abs(len(l[i])-len(l[j]))==1:\r\n\t\t\t\ty=codn2(l[i],l[j])\r\n\t\t\t\tif y==1:\r\n\t\t\t\t\td[j].append(i)\r\n\t\t\t\tif y==2:\r\n\t\t\t\t\td[i].append(j)\r\nans=0\r\n#print(d)\r\n\r\nfor i in range(n):\r\n\tans=max(ans,longest(i))\r\nprint(ans+1)\r\n\n```","inputs":"11\nabacd\nbcdada\ndd\nabcd\nbcdd\nadcd\naddd\naa\nccd\nadd\nad\n","output":"7\n","actual_output":"7\n","execution_success":true,"sample_index":550},{"source":"apps","task_type":"verifiable_code","in_source_id":"948","prompt":"Solve the following coding problem using the programming language python:\n\nChang's new maths teacher is very enthusiastic about making sure that students understand the concept rather than remembering it. On her first day at teaching, she gives an assignment to all the students to test their potential. Chang wants to demonstrate that he understands the concept rather than rote learning. Help Chang in doing this by solving the hardest problem in the assignment. The problem is written as follows. \n\nA perfect function is defined in the following manner.\n\n- F(x, y) = x2 + y for 1 \u2264 x \u2264 A, 1 \u2264 y \u2264 B\n- F(x, y) = 2 otherwise\n\nFind the number of integral pairs (x, y) such that F(x, y) is a perfect square.\n\n-----Input-----\nFirst and the only line of the input contains two single space separated integers A and B.\n\n-----Output-----\nOutput a single integer indicating the output to the only test case.\n\n-----Constraints-----\n- 1 \u2264 A, B \u2264 106\n\n-----Example-----\nInput:\n4 4\n\nOutput:\n1\n\n-----Explanation-----\nExample case 1.\n(1, 3) is the only pair such that x = 1, y = 3 satisfying x <= 4 and y <= 4. 1^2 + 3 = 4 which is a perfect square.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfrom math import sqrt\n\na, b = map(int, input().split())\npairs = 0\n\nfor i in range(1, a+1):\n for j in range(1, b+1):\n root = sqrt(i**2 + j)\n\n if not root - int(root):\n pairs += 1\n\nprint(pairs)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '4 4\\n', 'output': '1\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/CHNGFUNC'}","problem_id":"vfc_2634","program":"```python\nfrom math import sqrt\n\na, b = map(int, input().split())\npairs = 0\n\nfor i in range(1, a+1):\n for j in range(1, b+1):\n root = sqrt(i**2 + j)\n\n if not root - int(root):\n pairs += 1\n\nprint(pairs)\n```","inputs":"4 4\n","output":"1\n","actual_output":"1\n","execution_success":true,"sample_index":551},{"source":"apps","task_type":"verifiable_code","in_source_id":"949","prompt":"Solve the following coding problem using the programming language python:\n\nFizza is a cute girl and she wants to be more beautiful.\nSo she approached a magician to increase her beauty magically. But the magician's \nglasses accidently got locked inside the locker and he forgot the password. Without\nglasses he can't help her. The password is hidden in N integers i.e. $a[1], a[2], ..... a[N]$ \nwritten on his magical stick.The password is the maximum number of moves Fizza can perform, for any position $i$ such that 1 < = $i$ < = $N$ and integer $X$ is present at $i$-th\nposition. In one move she can perform one of the following operations ->\n$(1)$ If ( $i$ + 1 < = $N$ ) she can go to position ($i$ + 1 ) if integer at ( $i$ + 1 )-th \nposition is equal to $X$.\n$(2)$ if ( $i$ + 2 < = $N$ ) she can go to position ($i$ + 2 ) if integer at ($i$ + 2)-th \nposition is equal to $X$.\nFizza is a bit worried about her beauty so she can't focus on the problem but she asked for \nyour help to find the password.\n\n-----Input:-----\n- First line will contain $T$, number of testcases. Then the testcases follow. \n- Each testcase consists of two lines of input.\n- Input $N$.\n- Input $N$ integers . \n\n-----Output:-----\nFor each testcase, output in a single line Maximum number of moves.\n\n-----Constraints-----\n- $1 \\leq T \\leq 100$\n- $1 \\leq N \\leq 10^5$\n- $1 \\leq a[i] \\leq 2*10^5$\n\n-----Sample Input:-----\n3\n8\n6 3 6 4 5 4 3 6\n9\n5 5 4 5 2 1 3 4 2\n6\n1 2 3 4 5 6\n\n-----Sample Output:-----\n1\n2\n0\n\n-----EXPLANATION:-----\nIn the first case, integers at position 1 and 3 are the same and at alternate positions.\nIn the second case, integers at position 1, 2, 4 follow the conditions.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\ndef check(l,n):\n m = 0\n for i in range(n-1):\n x = l[i]\n c = 0\n j = i\n while (j+2=perimeter(diff(b,i)):\r\n good = val(i)\r\n yes.append(i)\r\n break\r\n #yes.sort(key = lambda x: len(x))\r\n print(\" \".join([str(b.index(i)+1) for i in yes[0]]))\r\n x = round(av(yes[0])-perimeter(diff(b,yes[0])),2)\r\n print(f'{x:.2f}')\r\n\r\n\r\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n6\\n0 0 8 3\\n1 4 3 2\\n2 1 7 1\\n4 1 2 3\\n3 5 4 6\\n2 3 9 8\\n3\\n3 0 10 2\\n5 5 20 25\\n7 -3 30 32\\n', 'output': '2 4 5\\n3.16\\n2\\n15.00\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/CUBE2020/problems/BDRYIIST'}","problem_id":"vfc_2646","program":"```python\nimport math\r\nfrom itertools import permutations as p\r\ndef diff(li1, li2): \r\n li_dif = [i for i in li1 if i not in li2]\r\n return li_dif \r\ndef segments(b):\r\n \"\"\"A sequence of (x,y) numeric coordinates pairs \"\"\"\r\n poly = [(i[0],i[1]) for i in b]\r\n return zip(poly, poly[1:] + [poly[0]])\r\ndef perimeter(poly):\r\n \"\"\"A sequence of (x,y) numeric coordinates pairs \"\"\"\r\n return abs(sum(math.hypot(x0-x1,y0-y1) for ((x0, y0), (x1, y1)) in segments(poly)))\r\ndef av(b):\r\n return sum([i[3] for i in b])\r\ndef val(b):\r\n return sum([i[2] for i in b])\r\nfor _ in range(int(input())):\r\n b = []\r\n for _ in range(int(input())):\r\n b.append(list(map(int,input().split())))\r\n perm = []\r\n for i in range(1,len(b)):\r\n for e in p(b,i):\r\n perm.append(e)\r\n perm.sort(key=lambda x:val(x))\r\n yes = []\r\n for i in perm:\r\n if av(i)>=perimeter(diff(b,i)):\r\n good = val(i)\r\n yes.append(i)\r\n break\r\n #yes.sort(key = lambda x: len(x))\r\n print(\" \".join([str(b.index(i)+1) for i in yes[0]]))\r\n x = round(av(yes[0])-perimeter(diff(b,yes[0])),2)\r\n print(f'{x:.2f}')\r\n\r\n\r\n\n```","inputs":"2\n6\n0 0 8 3\n1 4 3 2\n2 1 7 1\n4 1 2 3\n3 5 4 6\n2 3 9 8\n3\n3 0 10 2\n5 5 20 25\n7 -3 30 32\n","output":"2 4 5\n3.16\n2\n15.00\n","actual_output":"2 4 5\n3.16\n2\n15.00\n","execution_success":true,"sample_index":554},{"source":"apps","task_type":"verifiable_code","in_source_id":"952","prompt":"Solve the following coding problem using the programming language python:\n\nChef has a string of size $N$ which consists only lowercase English alphabet. The chef doesn't like the consonant alphabet at all. So he is thinking of changing every single consonant alphabet to any vowel alphabet. There is some cost for performing this operation.\n- Number all alphabet [a,b,c,\u2026\u2026,z] as [1,2,3,\u2026..,26]\n- So if you want to change c to e then cost will be |e-c| = |5-3| = 2\nYou need the answer at what minimum cost chef can change every single consonant alphabet to any vowel alphabet. \n\n-----Input:-----\n- First-line will contain $T$, the number of test cases. Then the test cases follow. \n- Each test case contains of a single line of input, a string of lowercase alphabet. \n\n-----Output:-----\nFor each test case, output in a single line answer.\n\n-----Constraints-----\n- $1 \\leq T \\leq 100$\n- $1 \\leq |s| \\leq 10^2$\n\n-----Sample Input:-----\n2\naeiou\ndbcc \n\n-----Sample Output:-----\n0\n6\n\n-----EXPLANATION:-----\nIn the first test case, all characters are already vowel so we don't need to change.\nIn the second tect case\n|e-d|=|5-4|=1\n|a-b|=|1-2|=1\n|a-c|=|1-3|=2\n|a-c|=|1-3|=2\n1+1+2+2=6\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\r\nstr1=int(input())\r\nfor i in range(str1):\r\n l1=[]\r\n str2=input()\r\n for i in str2:\r\n l1.append(i)\r\n \r\n count=0\r\n d=dict()\r\n d={'a':1,'b':2,'c':3,'d':4,'e':5,'f':6,'g':7,'h':8,'i':9,'j':10,'k':11,'l':12,'m':13,'n':14}\r\n d1={'o':15,'p':16,'q':17,'r':18,'s':19,'t':20,'u':21,'v':22,'w':23,'x':24,'y':25,'z':26}\r\n d.update(d1)\r\n for j in l1:\r\n if j not in ['a','e','i','o','u']:\r\n a=abs(d[j]-d['a'])\r\n e=abs(d[j]-d['e'])\r\n i=abs(d[j]-d['i'])\r\n o=abs(d[j]-d['o'])\r\n u=abs(d[j]-d['u'])\r\n \r\n count+=min([a,e,i,o,u])\r\n print(count)\r\n\r\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\naeiou\\ndbcc\\n', 'output': '0\\n6\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/BIT32020/problems/BIT3F'}","problem_id":"vfc_2650","program":"```python\n# cook your dish here\r\nstr1=int(input())\r\nfor i in range(str1):\r\n l1=[]\r\n str2=input()\r\n for i in str2:\r\n l1.append(i)\r\n \r\n count=0\r\n d=dict()\r\n d={'a':1,'b':2,'c':3,'d':4,'e':5,'f':6,'g':7,'h':8,'i':9,'j':10,'k':11,'l':12,'m':13,'n':14}\r\n d1={'o':15,'p':16,'q':17,'r':18,'s':19,'t':20,'u':21,'v':22,'w':23,'x':24,'y':25,'z':26}\r\n d.update(d1)\r\n for j in l1:\r\n if j not in ['a','e','i','o','u']:\r\n a=abs(d[j]-d['a'])\r\n e=abs(d[j]-d['e'])\r\n i=abs(d[j]-d['i'])\r\n o=abs(d[j]-d['o'])\r\n u=abs(d[j]-d['u'])\r\n \r\n count+=min([a,e,i,o,u])\r\n print(count)\r\n\r\n\n```","inputs":"2\naeiou\ndbcc\n","output":"0\n6\n","actual_output":"0\n6\n","execution_success":true,"sample_index":555},{"source":"apps","task_type":"verifiable_code","in_source_id":"953","prompt":"Solve the following coding problem using the programming language python:\n\nChef has $N$ doggo (dogs) , Lets number them $1$ to $N$.\n\nChef decided to build houses for each, but he soon realizes that keeping so many dogs at one place may be messy. So he decided to divide them into several groups called doggo communities. Let the total no. of groups be $K$ . In a community, paths between pairs of houses can be made so that doggo can play with each other. But there cannot be a path between two houses of different communities for sure. Chef wanted to make maximum no. of paths such that the total path is not greater then $K$.\nLet\u2019s visualize this problem in an engineer's way :)\nThe problem is to design a graph with max edge possible such that the total no. of edges should not be greater than the total no. of connected components.\n\n-----INPUT FORMAT-----\n- First line of each test case file contain $T$ , denoting total number of test cases.\n- $ith$ test case contain only one line with a single integer $N$ , denoting the number of dogs(vertex)\n\n-----OUTPUT FORMAT-----\n- For each test case print a line with a integer , denoting the maximum possible path possible.\n\n-----Constraints-----\n- $1 \\leq T \\leq 10000$\n- $1 \\leq N \\leq 10^9$ \n\n-----Sub-Tasks-----\n- $20 Points$\n- $1 \\leq N \\leq 10^6$ \n\n-----Sample Input-----\n1\n\n4\n\n-----Sample Output-----\n2\n\n-----Explanation-----\n4 houses can be made with like this:\n\ncommunity #1 : [1 - 2 ]\n\ncommunity #2 : [3 - 4 ]\n\nor [1 - 2 - 3] , [ 4 ]\n\nIn both cases the maximum possible path is 2.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\nimport sys\ndef get_array(): return list(map(int , sys.stdin.readline().strip().split()))\ndef get_ints(): return list(map(int, sys.stdin.readline().strip().split()))\ndef input(): return sys.stdin.readline().strip()\nimport math\nfrom collections import defaultdict\nfrom itertools import combinations_with_replacement,permutations\nimport bisect\nimport math as mt \nfrom functools import reduce\nimport time\n\ndef __starting_point():\n for _ in range(int(input())):\n n = int(input())\n a=1\n b=1\n c=(-2*n)\n dis = b * b - 4 * a * c \n sqrt_val = math.sqrt(abs(dis))\n r1=(-b + sqrt_val)/(2 * a)\n # r2=(-b - sqrt_val)/(2 * a)\n\n # print(r1)\n r1 = math.floor(r1)+1\n print(n-r1+1)\n\n\n\n\n\n\n\n\n\n\n\n__starting_point()\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n4\\n', 'output': '2\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/STR2020/problems/DOGGO'}","problem_id":"vfc_2654","program":"```python\n# cook your dish here\nimport sys\ndef get_array(): return list(map(int , sys.stdin.readline().strip().split()))\ndef get_ints(): return list(map(int, sys.stdin.readline().strip().split()))\ndef input(): return sys.stdin.readline().strip()\nimport math\nfrom collections import defaultdict\nfrom itertools import combinations_with_replacement,permutations\nimport bisect\nimport math as mt \nfrom functools import reduce\nimport time\n\ndef __starting_point():\n for _ in range(int(input())):\n n = int(input())\n a=1\n b=1\n c=(-2*n)\n dis = b * b - 4 * a * c \n sqrt_val = math.sqrt(abs(dis))\n r1=(-b + sqrt_val)/(2 * a)\n # r2=(-b - sqrt_val)/(2 * a)\n\n # print(r1)\n r1 = math.floor(r1)+1\n print(n-r1+1)\n\n\n\n\n\n\n\n\n\n\n\n__starting_point()\n```","inputs":"1\n4\n","output":"2\n","actual_output":"2\n","execution_success":true,"sample_index":556},{"source":"apps","task_type":"verifiable_code","in_source_id":"954","prompt":"Solve the following coding problem using the programming language python:\n\nChef has an old machine if the chef enters any natural number, the machine will display 1, 2, \u2026n, n-1, n-2, n-3,\u20261 series and in next line prints sum of cubes of each number in the series. Chef wants to create a computer program which can replicate the functionality of the machine. Help the chef to code.\n\n-----Input:-----\n- First-line will contain $T$, the number of test cases. Then the test cases follow. \n- Each test case contains a single line of input, $N$. \n\n-----Output:-----\nFor each test case, output in a single line answer.\n\n-----Constraints-----\n- $1 \\leq T \\leq 50$\n- $1 \\leq N \\leq 50$\n\n-----Sample Input:-----\n2\n1\n3\n\n-----Sample Output:-----\n1\n45\n\n-----EXPLANATION:-----\nFor 2) series will be 1, 2, 3, 2, 1 and the sum will be = 1 + 8 + 27 + 8+ 1\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nt=int(input())\r\nwhile(t!=0):\r\n t=t-1\r\n n=int(input())\r\n ans=0\r\n for i in range(1,n+1,1):\r\n sum=0;\r\n for j in range(1,i+1,1):\r\n sum=sum+j\r\n s=sum-i\r\n sum=sum+s\r\n if(i!=n):\r\n ans=ans+2*sum*i\r\n else:\r\n ans=ans+sum*i\r\n print(ans)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n1\\n3\\n', 'output': '1\\n45\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/PEND2020/problems/ANITGUY4'}","problem_id":"vfc_2658","program":"```python\nt=int(input())\r\nwhile(t!=0):\r\n t=t-1\r\n n=int(input())\r\n ans=0\r\n for i in range(1,n+1,1):\r\n sum=0;\r\n for j in range(1,i+1,1):\r\n sum=sum+j\r\n s=sum-i\r\n sum=sum+s\r\n if(i!=n):\r\n ans=ans+2*sum*i\r\n else:\r\n ans=ans+sum*i\r\n print(ans)\n```","inputs":"2\n1\n3\n","output":"1\n45\n","actual_output":"1\n45\n","execution_success":true,"sample_index":557},{"source":"apps","task_type":"verifiable_code","in_source_id":"955","prompt":"Solve the following coding problem using the programming language python:\n\n-----Problem Statement-----\nLevy's conjecture, named after Hyman Levy, states that all odd integers greater than 5 can be represented as the sum of an odd prime number and an even semiprime. To put it algebraically, 2n + 1 = p + 2q always has a solution in primes p and q (not necessary to be distinct) for n > 2. (Source: Wikipedia)\nIn this problem, given a positive integer N (not necessary to be odd integer greater than 5). Your task is to calculate how many distinct ordered pairs (p, q) such that N = p + 2q, where p and q are primes.\n\n-----Input-----\nThe first line of input contains an integer T, denoting the number of test cases. Then T test cases follow.\n\nEach test case consists of exactly one line containing an integer N.\n\n-----Constraints-----\n- 1 \u2264 T \u2264 100000 (105)\n- 1 \u2264 N \u2264 10000 (104)\n\n-----Output-----\nFor each test case, output the number of ordered pairs (p, q) of primes such that N = p + 2q.\n\n-----Example-----\nInput:\n3\n2\n7\n11\n\nOutput:\n0\n1\n2\n\n-----Explanation-----\nCase #1: There are no ordered pairs (p, q) such that p + 2q = 2.\nCase #2: There is only one ordered pair (p, q) = (3, 2) such that p + 2q = 7.\nCase #3: There are two ordered pairs (p, q) = (7, 2), (5, 3) such that p + 2q = 11.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nisPrime=[1 for i in range(10001)]\ncnt=[0 for i in range(10001)]\nisPrime[0]=0\nisPrime[1]=0\nprime=[]\nfor i in range(2,10001):\n if isPrime[i]:\n prime.append(i)\n for j in range(i*i,10001,i):\n isPrime[j]=0\n#print(prime)\nfor i in prime:\n for j in prime:\n if (i + 2*j)>10000:\n break\n else:\n cnt[i + 2*j]+=1\n#print(le)\nfor _ in range(int(input())):\n n=int(input())\n print(cnt[n])\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\n2\\n7\\n11\\n', 'output': '0\\n1\\n2\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/LEVY'}","problem_id":"vfc_2662","program":"```python\nisPrime=[1 for i in range(10001)]\ncnt=[0 for i in range(10001)]\nisPrime[0]=0\nisPrime[1]=0\nprime=[]\nfor i in range(2,10001):\n if isPrime[i]:\n prime.append(i)\n for j in range(i*i,10001,i):\n isPrime[j]=0\n#print(prime)\nfor i in prime:\n for j in prime:\n if (i + 2*j)>10000:\n break\n else:\n cnt[i + 2*j]+=1\n#print(le)\nfor _ in range(int(input())):\n n=int(input())\n print(cnt[n])\n```","inputs":"3\n2\n7\n11\n","output":"0\n1\n2\n","actual_output":"0\n1\n2\n","execution_success":true,"sample_index":558},{"source":"apps","task_type":"verifiable_code","in_source_id":"957","prompt":"Solve the following coding problem using the programming language python:\n\nTired of the overpopulated world, Miu - The introverted cat visits a new continent in search for a new house. \nThere are $N$ houses lying on the X-axis.\n\nTheir positions are given by $X$$i$ , where $i$ refers to the $i$th house. ( $1 <= i <= N$ )\n\nEach of these positions are pairwise distinct \nMiu is supposed to choose one of these houses for herself.\n\nMiu defines a term - The Distance of Peace, as the minimum distance from her house to any other house. \nMiu wonders what is maximum Distance of Peace she can obtain. Can you help her?\n\n-----Input:-----\n- The first line of the input consists of a single integer $T$, denoting the number of test cases \n- The first line of each test case consists of a single integer $N$ \n- The second line of each test case consists of $N$ space-separated integers\n$X$$1$ $X$$2$ $X$$3$ \u2026 $X$$N$\n\n-----Output:-----\n- For each test case print the answer in a single line, the maximum Distance of Peace Miu can obtain\n\n-----Constraints-----\n- 1 <= $T$ <= 100 \n- 2 <= $N$ <= 105 \n- -109 <= $X$$i$ <= 109 \n- Sum of $N$ over all test cases does not exceed 106 \n\n-----Subtasks-----\nSubtask #1 (30 points): \n- $N$ <= 103 \nSubtask #2 (70 points): \n- Original Constraints\n\n-----Sample Input:-----\n2\n\n6\n\n7 -1 2 13 -5 15\n\n4\n\n6 10 3 12 \n\n-----Sample Output:-----\n5\n\n3 \n\n-----EXPLANATION:-----\nTest Case 1:\n\nThe $1$st house has the maximum Distance of Peace, which is from the $3$rd house:\n$| 7 - 2 | = 5$\n\nHence, the answer is $5$\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nn = int(input())\nfor i in range(n) :\n t = int(input())\n li = sorted(list(map(int , input().split())))\n ans = 1\n dp = [li[1]-li[0]] + [0] * (t-2) + [li[t-1] - li[t-2]]\n for i in range(1 , t-1) :\n dp[i] = min(li[i] - li[i-1] , li[i+1] - li[i])\n print(max(dp))\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n6\\n7 -1 2 13 -5 15\\n4\\n6 10 3 12\\n', 'output': '5\\n3\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/TCFL2020/problems/TCFL20A'}","problem_id":"vfc_2670","program":"```python\nn = int(input())\nfor i in range(n) :\n t = int(input())\n li = sorted(list(map(int , input().split())))\n ans = 1\n dp = [li[1]-li[0]] + [0] * (t-2) + [li[t-1] - li[t-2]]\n for i in range(1 , t-1) :\n dp[i] = min(li[i] - li[i-1] , li[i+1] - li[i])\n print(max(dp))\n\n```","inputs":"2\n6\n7 -1 2 13 -5 15\n4\n6 10 3 12\n","output":"5\n3\n","actual_output":"5\n3\n","execution_success":true,"sample_index":560},{"source":"apps","task_type":"verifiable_code","in_source_id":"959","prompt":"Solve the following coding problem using the programming language python:\n\nYou are given an array with $N$ integers: $A[1], A[2], \\ldots, A[N]$ (where $N$ is even). You are allowed to permute the elements however you want. Say, after permuting the elements, you end up with the array $A'[1], A'[2], \\ldots, A'[N]$. Your goal is to maximize the following sum:\n|A\u2032[1]\u2212A\u2032[2]| + |A\u2032[3]\u2212A\u2032[4]| + ... + |A\u2032[N\u22121]\u2212A\u2032[N]||A\u2032[1]\u2212A\u2032[2]| + |A\u2032[3]\u2212A\u2032[4]| + ... + |A\u2032[N\u22121]\u2212A\u2032[N]|\n|A'[1] - A'[2]| \\ + \\ |A'[3] - A'[4]| \\ + \\ ... \\ + \\ |A'[N - 1] - A'[N]|\n\nHere, $|x|$ denotes the absolute value of $x$.\nYou have to print the maximum sum achievable.\n\n-----Input-----\n- The first line contains $T$, the number of test cases.\n- Each test case starts with an integer $N$ in the first line.\n- The second line of each test case contains $N$ space separated integers, denoting the values of array $A$.\n\n-----Output-----\nFor each test case, output the maximum sum achievable in a new line.\n\n-----Constraints-----\n- $1 \\le T \\le 10^5$\n- $1 \\le N \\le 10^5$\n- $N$ is even\n- $|A[i]| \\le 10^9$\n- Sum of $N$ over all test cases $\\le 2 * 10^5$\n\n-----Example Input 1-----\n1\n4\n1 -3 2 -3\n\n-----Example Output 1-----\n9\n\n-----Explanation 1-----\nThe original array is {$1, -3, 2, -3$}. Suppose you permute it and get the array {$2, 1, -3, -3$}. Then the corresponding sum would be $|2 - 1| \\ + \\ |-3 - (-3)| = 1 + 0 = 1$.\nBut suppose you permute it differently and get the array {$-3, 2, 1, -3$}. Then the corresponding sum would be $|-3 - 2| \\ + \\ |1 - (-3)| = 5 + 4 = 9$. You can check that you cannot do any better, and hence the answer is 9.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfor i in range(int(input())):\n n=int(input())\n m=list(map(int,input().split()))[:n]\n m.sort()\n t=0\n for j in range(n//2):\n t+=abs(m[j]-m[n-j-1])\n print(t)\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n4\\n1 -3 2 -3\\n', 'output': '9\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/NOMATCH'}","problem_id":"vfc_2678","program":"```python\nfor i in range(int(input())):\n n=int(input())\n m=list(map(int,input().split()))[:n]\n m.sort()\n t=0\n for j in range(n//2):\n t+=abs(m[j]-m[n-j-1])\n print(t)\n\n```","inputs":"1\n4\n1 -3 2 -3\n","output":"9\n","actual_output":"9\n","execution_success":true,"sample_index":562},{"source":"apps","task_type":"verifiable_code","in_source_id":"960","prompt":"Solve the following coding problem using the programming language python:\n\nThe 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.\n\n-----Input:-----\n- First-line will contain $T$, the number of test cases. Then the test cases follow. \n- Each test case contains a single line of input, one integer $K$. \n\n-----Output:-----\nFor each test case, output as the pattern.\n\n-----Constraints-----\n- $1 \\leq T \\leq 100$\n- $1 \\leq K \\leq 100$\n\n-----Sample Input:-----\n4\n1\n2\n3\n4\n\n-----Sample Output:-----\n1 \n1 10 \n11 100 \n1 10 11 \n100 101 110 \n111 1000 1001 \n1 10 11 100 \n101 110 111 1000 \n1001 1010 1011 1100 \n1101 1110 1111 10000 \n\n-----EXPLANATION:-----\nNo need, else pattern can be decode easily.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nt = int(input())\r\n\r\nfor _ in range(t):\r\n k = int(input())\r\n count = 1\r\n for _ in range(k):\r\n output = []\r\n for index in range(1,k+1):\r\n output.append(bin(count).replace(\"0b\", \"\"))\r\n count += 1\r\n print(*output)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '4\\n1\\n2\\n3\\n4\\n', 'output': '1\\n1 10\\n11 100\\n1 10 11\\n100 101 110\\n111 1000 1001\\n1 10 11 100\\n101 110 111 1000\\n1001 1010 1011 1100\\n1101 1110 1111 10000\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/PTRN2021/problems/ITGUY52'}","problem_id":"vfc_2682","program":"```python\nt = int(input())\r\n\r\nfor _ in range(t):\r\n k = int(input())\r\n count = 1\r\n for _ in range(k):\r\n output = []\r\n for index in range(1,k+1):\r\n output.append(bin(count).replace(\"0b\", \"\"))\r\n count += 1\r\n print(*output)\n```","inputs":"4\n1\n2\n3\n4\n","output":"1\n1 10\n11 100\n1 10 11\n100 101 110\n111 1000 1001\n1 10 11 100\n101 110 111 1000\n1001 1010 1011 1100\n1101 1110 1111 10000\n","actual_output":"1\n1 10\n11 100\n1 10 11\n100 101 110\n111 1000 1001\n1 10 11 100\n101 110 111 1000\n1001 1010 1011 1100\n1101 1110 1111 10000\n","execution_success":true,"sample_index":563},{"source":"apps","task_type":"verifiable_code","in_source_id":"961","prompt":"Solve the following coding problem using the programming language python:\n\nThe chef has one array of N natural numbers (might be in sorted order). Cheffina challenges chef to find the total number of inversions in the array.\n\n-----Input:-----\n- First-line will contain $T$, the number of test cases. Then the test cases follow. \n- Each test case contains two lines of input, $N$.\n- N space-separated natural numbers. \n\n-----Output:-----\nFor each test case, output in a single line answer as the total number of inversions.\n\n-----Constraints-----\n- $1 \\leq T \\leq 10$\n- $1 \\leq N \\leq 10^5$\n- $1 \\leq arr[i] \\leq 10^5$\n\n-----Sample Input:-----\n1\n5\n5 4 1 3 2\n\n-----Sample Output:-----\n8\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\ndef mergeSort(arr, n): \n # A temp_arr is created to store \n # sorted array in merge function \n temp_arr = [0]*n \n return _mergeSort(arr, temp_arr, 0, n-1) \n \n# This Function will use MergeSort to count inversions \n \ndef _mergeSort(arr, temp_arr, left, right): \n \n # A variable inv_count is used to store \n # inversion counts in each recursive call \n \n inv_count = 0\n \n # We will make a recursive call if and only if \n # we have more than one elements \n \n if left < right: \n \n # mid is calculated to divide the array into two subarrays \n # Floor division is must in case of python \n \n mid = (left + right)//2\n \n # It will calculate inversion \n # counts in the left subarray \n \n inv_count += _mergeSort(arr, temp_arr, \n left, mid) \n \n # It will calculate inversion \n # counts in right subarray \n \n inv_count += _mergeSort(arr, temp_arr, \n mid + 1, right) \n \n # It will merge two subarrays in \n # a sorted subarray \n \n inv_count += merge(arr, temp_arr, left, mid, right) \n return inv_count \n \n# This function will merge two subarrays \n# in a single sorted subarray \ndef merge(arr, temp_arr, left, mid, right): \n i = left # Starting index of left subarray \n j = mid + 1 # Starting index of right subarray \n k = left # Starting index of to be sorted subarray \n inv_count = 0\n \n # Conditions are checked to make sure that \n # i and j don't exceed their \n # subarray limits. \n \n while i <= mid and j <= right: \n \n # There will be no inversion if arr[i] <= arr[j] \n \n if arr[i] <= arr[j]: \n temp_arr[k] = arr[i] \n k += 1\n i += 1\n else: \n # Inversion will occur. \n temp_arr[k] = arr[j] \n inv_count += (mid-i + 1) \n k += 1\n j += 1\n \n # Copy the remaining elements of left \n # subarray into temporary array \n while i <= mid: \n temp_arr[k] = arr[i] \n k += 1\n i += 1\n \n # Copy the remaining elements of right \n # subarray into temporary array \n while j <= right: \n temp_arr[k] = arr[j] \n k += 1\n j += 1\n \n # Copy the sorted subarray into Original array \n for loop_var in range(left, right + 1): \n arr[loop_var] = temp_arr[loop_var] \n \n return inv_count \n \nfor _ in range(int(input())):\n n = int(input())\n a = list(map(int,input().split()))\n print(mergeSort(a, n) )\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n5\\n5 4 1 3 2\\n', 'output': '8\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/PSTR2020/problems/ANITGUY3'}","problem_id":"vfc_2686","program":"```python\n# cook your dish here\ndef mergeSort(arr, n): \n # A temp_arr is created to store \n # sorted array in merge function \n temp_arr = [0]*n \n return _mergeSort(arr, temp_arr, 0, n-1) \n \n# This Function will use MergeSort to count inversions \n \ndef _mergeSort(arr, temp_arr, left, right): \n \n # A variable inv_count is used to store \n # inversion counts in each recursive call \n \n inv_count = 0\n \n # We will make a recursive call if and only if \n # we have more than one elements \n \n if left < right: \n \n # mid is calculated to divide the array into two subarrays \n # Floor division is must in case of python \n \n mid = (left + right)//2\n \n # It will calculate inversion \n # counts in the left subarray \n \n inv_count += _mergeSort(arr, temp_arr, \n left, mid) \n \n # It will calculate inversion \n # counts in right subarray \n \n inv_count += _mergeSort(arr, temp_arr, \n mid + 1, right) \n \n # It will merge two subarrays in \n # a sorted subarray \n \n inv_count += merge(arr, temp_arr, left, mid, right) \n return inv_count \n \n# This function will merge two subarrays \n# in a single sorted subarray \ndef merge(arr, temp_arr, left, mid, right): \n i = left # Starting index of left subarray \n j = mid + 1 # Starting index of right subarray \n k = left # Starting index of to be sorted subarray \n inv_count = 0\n \n # Conditions are checked to make sure that \n # i and j don't exceed their \n # subarray limits. \n \n while i <= mid and j <= right: \n \n # There will be no inversion if arr[i] <= arr[j] \n \n if arr[i] <= arr[j]: \n temp_arr[k] = arr[i] \n k += 1\n i += 1\n else: \n # Inversion will occur. \n temp_arr[k] = arr[j] \n inv_count += (mid-i + 1) \n k += 1\n j += 1\n \n # Copy the remaining elements of left \n # subarray into temporary array \n while i <= mid: \n temp_arr[k] = arr[i] \n k += 1\n i += 1\n \n # Copy the remaining elements of right \n # subarray into temporary array \n while j <= right: \n temp_arr[k] = arr[j] \n k += 1\n j += 1\n \n # Copy the sorted subarray into Original array \n for loop_var in range(left, right + 1): \n arr[loop_var] = temp_arr[loop_var] \n \n return inv_count \n \nfor _ in range(int(input())):\n n = int(input())\n a = list(map(int,input().split()))\n print(mergeSort(a, n) )\n```","inputs":"1\n5\n5 4 1 3 2\n","output":"8\n","actual_output":"8\n","execution_success":true,"sample_index":564},{"source":"apps","task_type":"verifiable_code","in_source_id":"962","prompt":"Solve the following coding problem using the programming language python:\n\nThe 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.\n\n-----Input:-----\n- First-line will contain $T$, the number of test cases. Then the test cases follow. \n- Each test case contains a single line of input, one integer $K$. \n\n-----Output:-----\nFor each test case, output as the pattern.\n\n-----Constraints-----\n- $1 \\leq T \\leq 100$\n- $1 \\leq K \\leq 100$\n\n-----Sample Input:-----\n3\n2\n3\n4\n\n-----Sample Output:-----\n21\n1\n123\n21\n1\n4321\n123\n21\n1\n\n-----EXPLANATION:-----\nNo need, else pattern can be decode easily.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfor _ in range(int(input())):\n n = int(input())\n s = ''\n for i in range(1, n + 1): s += str(i)\n for i in range(n, 0, -1):\n if i % 2 == 0:\n for j in range(i, 0, -1): print(j, end = '')\n else:\n for j in range(1, i + 1): print(j, end = '')\n print()\n\n\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\n2\\n3\\n4\\n', 'output': '21\\n1\\n123\\n21\\n1\\n4321\\n123\\n21\\n1\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/PTRN2020/problems/ITGUY40'}","problem_id":"vfc_2690","program":"```python\nfor _ in range(int(input())):\n n = int(input())\n s = ''\n for i in range(1, n + 1): s += str(i)\n for i in range(n, 0, -1):\n if i % 2 == 0:\n for j in range(i, 0, -1): print(j, end = '')\n else:\n for j in range(1, i + 1): print(j, end = '')\n print()\n\n\n\n```","inputs":"3\n2\n3\n4\n","output":"21\n1\n123\n21\n1\n4321\n123\n21\n1\n","actual_output":"21\n1\n123\n21\n1\n4321\n123\n21\n1\n","execution_success":true,"sample_index":565},{"source":"apps","task_type":"verifiable_code","in_source_id":"963","prompt":"Solve the following coding problem using the programming language python:\n\nIn ChefLand, there is a mountain range consisting of $N$ hills (numbered $1$ through $N$) in a straight line. Let's denote the height of the $i$-th hill from the left by $h_i$.\nAda is working on the water supply system of ChefLand. On some of the hills, she wants to place water reservoirs; then, for each reservoir, she will decide in which direction the water should flow from it \u2014 either to the left or to the right (water may not flow in both directions from the same reservoir). From a reservoir on a hill with height $h$, water flows in the chosen direction until it reaches the first hill that is strictly higher than $h$; all hills before this hill (including the hill containing the reservoir) are therefore supplied with water.\nFor example, suppose we have hills with heights $[7, 2, 3, 5, 8]$. If we place a reservoir on the hill with height $5$, and pump water from it to the left, then the hills with heights $2$, $3$ and $5$ are supplied with water.\nHelp Ada find the minimum numer of reservoirs needed to provide water to all the hills if she chooses the directions optimally.\n\n-----Input-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The first line of each test case contains a single integer $N$.\n- The second line contains $N$ space-separated integers $h_1, h_2, \\dots, h_N$.\n\n-----Output-----\nFor each test case, print a single line containing one integer \u2014 the minimum required number of reservoirs.\n\n-----Constraints-----\n- $2 \\le N \\le 10^5$\n- $1 \\le h_i \\le 10^9$ for each valid $i$\n- $h_i \\neq h_j $ for any valid $i \\neq j$\n- the sum of $N$ over all test cases does not exceed $5 \\cdot 10^5$\n\n-----Example Input-----\n1\n6\n4 16 32 6 8 2\n\n-----Example Output-----\n2 \n\n-----Explanation-----\nExample case 1: We can place reservoirs on the second and third hill, pumping water to the left and right respectively.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\ndef solve(l):\r\n m = l.index(max(l))\r\n if m == 0 or m == len(l) - 1:\r\n return 1\r\n return 1 + min(solve(l[0:m]), solve(l[m+1:]))\r\n\r\ntc = int(input())\r\nfor test in range(tc):\r\n n = int(input())\r\n l = list(map(int, input().split()))\r\n print(solve(l))\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n6\\n4 16 32 6 8 2\\n\\n', 'output': '2 \\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/PUMPWAT'}","problem_id":"vfc_2694","program":"```python\ndef solve(l):\r\n m = l.index(max(l))\r\n if m == 0 or m == len(l) - 1:\r\n return 1\r\n return 1 + min(solve(l[0:m]), solve(l[m+1:]))\r\n\r\ntc = int(input())\r\nfor test in range(tc):\r\n n = int(input())\r\n l = list(map(int, input().split()))\r\n print(solve(l))\n```","inputs":"1\n6\n4 16 32 6 8 2\n\n","output":"2 \n","actual_output":"2\n","execution_success":true,"sample_index":566},{"source":"apps","task_type":"verifiable_code","in_source_id":"965","prompt":"Solve the following coding problem using the programming language python:\n\nCyael is a teacher at a very famous school in Byteland and she is known by her students for being very polite to them and also to encourage them to get good marks on their tests.\nThen, if they get good marks she will reward them with candies :) However, she knows they are all very good at Mathematics, so she decided to split the candies evenly to all the students she considers worth of receiving them, so they don't fight with each other. \nShe has a bag which initially contains N candies and she intends to split the candies evenly to K students. To do this she will proceed as follows: while she has more than K candies she will give exactly 1 candy to each student until she has less than K candies. On this situation, as she can't split candies equally among all students she will keep the remaining candies to herself.\nYour job is to tell how many candies will each student and the teacher\nreceive after the splitting is performed.\n\n-----Input-----\nThe first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.\nEach test case will consist of 2 space separated integers, N and K denoting the number of candies and the number of students as described above.\n\n-----Output-----\nFor each test case, output a single line containing two space separated integers, the first one being the number of candies each student will get, followed by the number of candies the teacher will get.\n\n-----Constraints-----\n- T<=100 in each test file \n- 0 <= N,K <= 233 - 1 \n\n-----Example-----Input:\n2\n10 2\n100 3\n\nOutput:\n5 0\n33 1\n\n-----Explanation-----\nFor the first test case, all students can get an equal number of candies and teacher receives no candies at all \nFor the second test case, teacher can give 33 candies to each student and keep 1 candy to herselfUpdate:\nThere may be multiple whitespaces before, after or between the numbers in input.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\ntry:\n t = int(input())\n for _ in range(t):\n n, k = map(int, input().split())\n if k == 0:\n print(0, n)\n else:\n print(n//k, n%k)\nexcept:\n pass\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n10 2\\n100 3\\n', 'output': '5 0\\n33 1\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/SPCANDY'}","problem_id":"vfc_2702","program":"```python\n# cook your dish here\ntry:\n t = int(input())\n for _ in range(t):\n n, k = map(int, input().split())\n if k == 0:\n print(0, n)\n else:\n print(n//k, n%k)\nexcept:\n pass\n```","inputs":"2\n10 2\n100 3\n","output":"5 0\n33 1\n","actual_output":"5 0\n33 1\n","execution_success":true,"sample_index":567},{"source":"apps","task_type":"verifiable_code","in_source_id":"966","prompt":"Solve the following coding problem using the programming language python:\n\nThere are N hills in a row numbered 1 through N from left to right. Each hill has a height; for each valid i, the height of the i-th hill is Hi. Chef is initially on the leftmost hill (hill number 1). He can make an arbitrary number of jumps (including zero) as long as the following conditions are satisfied:\n\n- Chef can only jump from each hill to the next hill, i.e. from the i-th hill, he can jump to the i+1-th hill (if it exists).\n- It's always possible to jump to a hill with the same height as the current hill.\n- It's possible to jump to a taller hill if it's higher than the current hill by no more than U.\n- It's possible to jump to a lower hill if it's lower than the current hill by no more than D.\n- Chef can use a parachute and jump to a lower hill regardless of its height (as long as it's lower than the current hill). This jump can only be performed at most once.\n\nChef would like to move as far right as possible. Determine the index of the rightmost hill Chef can reach.\n\n-----Input-----\n- The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows.\n- The first line of each test case contains three space-separated integers N, U and D.\n- The second line contains N space-separated integers H1, H2, ..., HN.\n\n-----Output-----\nFor each test case, print a single line containing one integer \u2014 the index of the rightmost reachable hill.\n\n-----Constraints-----\n- 1 \u2264 T \u2264 100\n- 1 \u2264 N \u2264 100\n- 1 \u2264 U, D \u2264 1,000,000\n- 1 \u2264 Hi \u2264 1,000,000 for each valid i\n\n-----Subtasks-----\nSubtask #1 (100 points): original constraints\n\n-----Example-----\nInput:\n\n3\n5 3 2\n2 5 2 6 3\n5 2 3\n4 4 4 4 4\n5 2 7\n1 4 3 2 1\n\nOutput:\n\n3\n5\n1\n\n-----Explanation-----\nExample case 1: Chef can jump to second hill because it's higher by no more than U=3 than first hill, to jump to third hill Chef has to use parachute \nbecause it's lower than second hill by 3 which is more than D=2, Chef can't jump to fourth hill because it's higher than third hill by 4 which is more than U=3\nExample case 2: All hills are of the same height, so chef can reach the last hill with no problems.\nExample case 3: Chef can't jump to second hill because it's too high for him\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfor _ in range(int(input())):\n N,U,D=list(map(int,input().split()))\n H=list(map(int,input().split()))\n jumps=0\n paracount=0\n for i in range(len(H)-1):\n if H[i+1]-H[i]<=U and H[i+1]>=H[i]:\n jumps+=1\n elif H[i]>=H[i+1] and H[i]-H[i+1]<=D:\n jumps+=1\n elif H[i]-H[i+1]>D and paracount==0:\n jumps+=1\n paracount=1\n else: break\n print(jumps+1)\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\n5 3 2\\n2 5 2 6 3\\n5 2 3\\n4 4 4 4 4\\n5 2 7\\n1 4 3 2 1\\n', 'output': '3\\n5\\n1\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/HILLS'}","problem_id":"vfc_2706","program":"```python\nfor _ in range(int(input())):\n N,U,D=list(map(int,input().split()))\n H=list(map(int,input().split()))\n jumps=0\n paracount=0\n for i in range(len(H)-1):\n if H[i+1]-H[i]<=U and H[i+1]>=H[i]:\n jumps+=1\n elif H[i]>=H[i+1] and H[i]-H[i+1]<=D:\n jumps+=1\n elif H[i]-H[i+1]>D and paracount==0:\n jumps+=1\n paracount=1\n else: break\n print(jumps+1)\n\n```","inputs":"3\n5 3 2\n2 5 2 6 3\n5 2 3\n4 4 4 4 4\n5 2 7\n1 4 3 2 1\n","output":"3\n5\n1\n","actual_output":"3\n5\n1\n","execution_success":true,"sample_index":568},{"source":"apps","task_type":"verifiable_code","in_source_id":"967","prompt":"Solve the following coding problem using the programming language python:\n\nSince due to COVID 19, India has undergone a complete 21 day lockdown. So Amol was attending an online lecture where his professor asked him to solve a question. Amol was unable to solve the question so he asked you to solve the question and give him the correct answer. \n\nThe question was asked a such that his professor gave him a number M and a list of integers of length N (i.e. A1, A2,..... AN) and you have to find out all the subsets that add up to M and the total number of subsets will be the final answer. \n\nInput: \n\u2022 The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows. \n\n\u2022 The first line of each test case contains a single integer N. \n\n\u2022 The second line of each test case contains a single integer M. \n\n\u2022 The third line contains N space-separated integers A1, A2,..... AN. \n\nOutput: \nFor each test case, print a single line containing one integer \u2015 the no. of subsets that adds upto M.\n\nConstraints: \n\u2022 1\u2264T\u22645\n\n\u2022 1\u2264N\u2264100 \n\n\u2022 10\u2264M\u2264100 \n\n\u2022 1\u2264Ai\u2264100\n\nExampleInput:\n\n2\n\n4\n\n16\n\n2 4 6 10 \n\n4 \n\n20 \n\n2 8 12 10 \n\nOutput:\n\n2\n\n2\n\nExplanation:\nIn the 1st example there are two subsets {2,4,10} and {6,10} that adds upto 16 so the output is 2.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\ntry:\n def countsubsetsum(S,arr,n):\n k=[[0 for i in range(S+1)] for i in range(n+1)]\n for i in range(n+1):\n for j in range(S+1):\n if(j==0):\n k[i][j]=1\n elif(i==0):\n k[i][j]=0\n elif(arr[i-1]<=j):\n k[i][j]=k[i-1][j-arr[i-1]]+k[i-1][j]\n else:\n k[i][j]=k[i-1][j]\n return k[n][S]\n for _ in range(int(input())):\n m=int(input())\n S=int(input()) \n arr=[int(i) for i in input().split()]\n \n n=len(arr)\n\n print(countsubsetsum(S, arr, n))\nexcept EOFError as e:\n pass\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n4\\n16\\n2 4 6 10\\n4\\n20\\n2 8 12 10\\n', 'output': '2\\n2\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/CY302020/problems/CODY303'}","problem_id":"vfc_2710","program":"```python\ntry:\n def countsubsetsum(S,arr,n):\n k=[[0 for i in range(S+1)] for i in range(n+1)]\n for i in range(n+1):\n for j in range(S+1):\n if(j==0):\n k[i][j]=1\n elif(i==0):\n k[i][j]=0\n elif(arr[i-1]<=j):\n k[i][j]=k[i-1][j-arr[i-1]]+k[i-1][j]\n else:\n k[i][j]=k[i-1][j]\n return k[n][S]\n for _ in range(int(input())):\n m=int(input())\n S=int(input()) \n arr=[int(i) for i in input().split()]\n \n n=len(arr)\n\n print(countsubsetsum(S, arr, n))\nexcept EOFError as e:\n pass\n```","inputs":"2\n4\n16\n2 4 6 10\n4\n20\n2 8 12 10\n","output":"2\n2\n","actual_output":"2\n2\n","execution_success":true,"sample_index":569},{"source":"apps","task_type":"verifiable_code","in_source_id":"968","prompt":"Solve the following coding problem using the programming language python:\n\nYou are given a rooted tree on N vertices. The nodes are numbered from 1 to N, and Node 1 is the root. Each node u has an associated value attached to it: Au.\nFor each vertex v, we consider the path going upwards from v to the root. Suppose that path is v1, v2, .., vk, where v1 = v and vk = 1. The cost of any node on this path is equal to the minimum value among all the nodes to its left in the path sequence, including itself. That is, cost(vi) = min1 <= j <= i{Avj}. And the cost of the path is the sum of costs of all the nodes in it.\nFor every node in the tree, find the cost of the path from that node to the root.\n\n-----Input-----\n- The first line of the input contains a single integer, N, denoting the number of nodes in the tree.\n- The next line contains N-1 integers, the i-th of which denotes the parent of node i+1.\n- The next line contains N integers, the i-th of which denotes Ai.\n\n-----Output-----\nOutput a single line containing N integers, the i-th of which should be the cost of the path from node i to the root.\n\n-----Constraints-----\n- 1 \u2264 N \u2264 100,000\n- -1,000,000,000 \u2264 Av \u2264 1,000,000,000\n\n-----Subtasks-----\n- Subtask #1 (30 points): 1 \u2264 N \u2264 2000\n- Subtask #2 (70 points): Original constraints.\n\n-----Example-----\nInput:\n8\n1 1 1 1 5 8 6\n1 2 3 4 5 15 70 10\n\nOutput: \n1 3 4 5 6 21 96 26\n\n-----Explanation-----\nFor example, take a look at the path from vertex 7: The path is 7 -> 8 -> 6 -> 5 -> 1.\nCost(7) has no choice but to be A7. So Cost(7) = 70.\nCost(8) will be minimum of A7 and A8, which turns out to be A8. So Cost(8) = 10.\nCost(6) = minimum {A7, A8, A6} = minimum {70, 10, 15} = 10.\nCost(5) = minimum {70, 10, 15, 5} = 5.\nCost(1) = minimum {70, 10, 15, 5, 1} = 1. \nSo, the cost of the path from 7 to the root is 70 + 10 + 10 + 5 + 1 = 96.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nimport sys\nn = eval(input())\nparents = [int(x)-1 for x in input().split(' ')]\nvalues = list(map(int , input().split(' ')))\nparents = [0]+parents\n# print(parents)\n# print(values)\ndef single_node_cost(i):\n cost = 0\n # print('started with ',i)\n min_value = sys.maxsize\n while i != 0:\n min_value = min(min_value,values[i])\n cost += min_value\n # print(i,min_value)\n i = parents[i]\n cost += min(values[0],min_value)\n return cost\nfor i in range(n):\n print(single_node_cost(i), end=' ')\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '8\\n1 1 1 1 5 8 6\\n1 2 3 4 5 15 70 10\\n', 'output': '1 3 4 5 6 21 96 26\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/POSTTREE'}","problem_id":"vfc_2714","program":"```python\nimport sys\nn = eval(input())\nparents = [int(x)-1 for x in input().split(' ')]\nvalues = list(map(int , input().split(' ')))\nparents = [0]+parents\n# print(parents)\n# print(values)\ndef single_node_cost(i):\n cost = 0\n # print('started with ',i)\n min_value = sys.maxsize\n while i != 0:\n min_value = min(min_value,values[i])\n cost += min_value\n # print(i,min_value)\n i = parents[i]\n cost += min(values[0],min_value)\n return cost\nfor i in range(n):\n print(single_node_cost(i), end=' ')\n```","inputs":"8\n1 1 1 1 5 8 6\n1 2 3 4 5 15 70 10\n","output":"1 3 4 5 6 21 96 26\n","actual_output":"1 3 4 5 6 21 96 26 ","execution_success":true,"sample_index":570},{"source":"apps","task_type":"verifiable_code","in_source_id":"969","prompt":"Solve the following coding problem using the programming language python:\n\nYou might have heard about our new goodie distribution program aka the \"Laddu Accrual System\". This problem is designed to give you a glimpse of its rules. You can read the page once before attempting the problem if you wish, nonetheless we will be providing all the information needed here itself. \n\nLaddu Accrual System is our new goodie distribution program. In this program, we will be distributing Laddus in place of goodies for your winnings and various other activities (described below), that you perform on our system. Once you collect enough number of Laddus, you can then redeem them to get yourself anything from a wide range of CodeChef goodies. \n\nLet us know about various activities and amount of laddus you get corresponding to them.\n\n- Contest Win (CodeChef\u2019s Long, Cook-Off, LTIME, or any contest hosted with us) : 300 + Bonus (Bonus = 20 - contest rank). Note that if your rank is > 20, then you won't get any bonus.\n- Top Contributor on Discuss : 300\n- Bug Finder\t: 50 - 1000 (depending on the bug severity). It may also fetch you a CodeChef internship! \n- Contest Hosting\t : 50 \n\nYou can do a checkout for redeeming laddus once a month. The minimum laddus redeemable at Check Out are 200 for Indians and 400 for the rest of the world.\n\nYou are given history of various activities of a user. The user has not redeemed any of the its laddus accrued.. Now the user just wants to redeem as less amount of laddus he/she can, so that the laddus can last for as long as possible. Find out for how many maximum number of months he can redeem the laddus.\n\n-----Input-----\n- The first line of input contains a single integer T denoting number of test cases\n- For each test case:\n\t\n- First line contains an integer followed by a string denoting activities, origin respectively, where activities denotes number of activities of the user, origin denotes whether the user is Indian or the rest of the world. origin can be \"INDIAN\" or \"NON_INDIAN\".\n- For each of the next activities lines, each line contains an activity. \n\n\t\t\tAn activity can be of four types as defined above. \n\t\t\t\n- Contest Win : Input will be of form of CONTEST_WON rank, where rank denotes the rank of the user. \n- Top Contributor : Input will be of form of TOP_CONTRIBUTOR.\n- Bug Finder : Input will be of form of BUG_FOUND severity, where severity denotes the severity of the bug. \n- Contest Hosting : Input will be of form of CONTEST_HOSTED.\n\n-----Output-----\n- For each test case, find out the maximum number of months for which the user can redeem the laddus accrued.\n\n-----Constraints-----\n- 1 \u2264 T, activities \u2264 100\n- 1 \u2264 rank \u2264 5000\n- 50 \u2264 severity \u2264 1000\n\n-----Subtasks-----\nThere is only a single subtask with 100 points.\n\n-----Example-----\nInput:\n2\n4 INDIAN\nCONTEST_WON 1\nTOP_CONTRIBUTOR\nBUG_FOUND 100\nCONTEST_HOSTED\n4 NON_INDIAN\nCONTEST_WON 1\nTOP_CONTRIBUTOR\nBUG_FOUND 100\nCONTEST_HOSTED\n\nOutput:\n3\n1\n\n-----Explanation-----\nIn the first example, \n\n- For winning contest with rank 1, user gets 300 + 20 - 1 = 319 laddus. \n- For top contributor, user gets 300 laddus. \n- For finding a bug with severity of 100, user gets 100 laddus. \n- For hosting a contest, user gets 50 laddus. \n\nSo, overall user gets 319 + 300 + 100 + 50 = 769 laddus.\nNow, the user is an Indian user, he can redeem only 200 laddus per month. So, for first three months, he will redeem 200 * 3 = 600 laddus. The remaining 169 laddus, he can not redeem as he requires at least 200 laddues in a month to redeem. \n\nSo, answer is 3.\n\nIn the second example, user is a non-Indian user, he can redeem 400 laddues per month. So, in the first month, he will redeem 400 laddus. The remaining 369 laddus, he can not redeem as he requires at least 400 laddues in a month to redeem. \n\nSo, answer is 1.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfor i in range(int(input())):\n n,k=input().split()\n laddus=0\n for j in range(int(n)):\n t=input().split()\n if t[0]=='CONTEST_WON':\n if(int(t[1])<=20):\n laddus+=300+20-int(t[1])\n else:\n laddus+=300\n elif t[0]=='TOP_CONTRIBUTOR':\n laddus+=300\n elif t[0]=='BUG_FOUND':\n laddus+=int(t[1])\n elif t[0]=='CONTEST_HOSTED':\n laddus+=50\n if(k=='INDIAN'):\n print(laddus//200)\n else:\n print(laddus//400)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n4 INDIAN\\nCONTEST_WON 1\\nTOP_CONTRIBUTOR\\nBUG_FOUND 100\\nCONTEST_HOSTED\\n4 NON_INDIAN\\nCONTEST_WON 1\\nTOP_CONTRIBUTOR\\nBUG_FOUND 100\\nCONTEST_HOSTED\\n', 'output': '3\\n1\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/LADDU'}","problem_id":"vfc_2718","program":"```python\nfor i in range(int(input())):\n n,k=input().split()\n laddus=0\n for j in range(int(n)):\n t=input().split()\n if t[0]=='CONTEST_WON':\n if(int(t[1])<=20):\n laddus+=300+20-int(t[1])\n else:\n laddus+=300\n elif t[0]=='TOP_CONTRIBUTOR':\n laddus+=300\n elif t[0]=='BUG_FOUND':\n laddus+=int(t[1])\n elif t[0]=='CONTEST_HOSTED':\n laddus+=50\n if(k=='INDIAN'):\n print(laddus//200)\n else:\n print(laddus//400)\n```","inputs":"2\n4 INDIAN\nCONTEST_WON 1\nTOP_CONTRIBUTOR\nBUG_FOUND 100\nCONTEST_HOSTED\n4 NON_INDIAN\nCONTEST_WON 1\nTOP_CONTRIBUTOR\nBUG_FOUND 100\nCONTEST_HOSTED\n","output":"3\n1\n","actual_output":"3\n1\n","execution_success":true,"sample_index":571},{"source":"apps","task_type":"verifiable_code","in_source_id":"970","prompt":"Solve the following coding problem using the programming language python:\n\nYou may have helped Chef and prevented Doof from destroying the even numbers. But, it has only angered Dr Doof even further. However, for his next plan, he needs some time. Therefore, Doof has built $N$ walls to prevent Chef from interrupting him. You have to help Chef by telling him the number of walls he needs to destroy in order to reach Dr Doof.\nFormally, the whole area can be represented as the first quadrant with the origin at the bottom-left corner. Dr. Doof is located at the origin $(0, 0)$. There are $N$ walls, the i-th wall is a straight line segment joining the points $(a_i, 0)$ and $(0, a_i)$. For every initial position of Chef $(x_j, y_j)$, find the number of walls he needs to break before reaching Doof. Obviously, chef can't start from a point on the wall. Therefore, if $(x_j, y_j)$ lies on any of the given walls, print $-1$ in a new line.\n\n-----Input-----\n- First line contains $T$, denoting the number of testcases.\n- The first line of every test case contains a single integer $N$ denoting the number of walls Dr Doof has built.\n- The next line contains $N$ space separated distinct integers each denoting $a_i$.\n- The next line contains a single integer $Q$ denoting the number of times Chef asks for your help.\n- The next $Q$ lines contains two space separated integers $x_j$ and $y_j$, each denoting the co-ordinates of the starting point of Chef.\n\n-----Output-----\nFor each query, print the number of walls Chef needs to break in order to reach Dr Doof in a separate line. If Chef tries to start from a point on any of the walls, print $-1$.\n\n-----Constraints-----\n- $1 \\leq T \\leq 2 * 10^2$\n- $1 \\leq N, Q \\leq 2 * 10^5$\n- $1 \\leq a_i \\leq 10^9$\n- $0 \\leq x_j, y_j \\leq 10^9$\n- $a_1 < a_2 < a_3 < .... < a_N$\n- Sum of $N$ and $Q$ over all testcases for a particular test file does not exceed $2 * 10^5$\n\n-----Sample Input-----\n1\n2\n1 3\n5\n0 0\n2 0\n0 4\n1 1\n1 2\n\n-----Sample Output-----\n0\n1\n2\n1\n-1\n\n-----Explanation-----\nThe sample input can be represented by the graph given below:\n\nIf Chef starts from $(0, 0)$, he can reach Dr Doof without destroying any wall.\n\nIf Chef starts from $(2, 0)$, he has to destroy the $1st$ wall.\n\nIf Chef starts from $(0, 4)$, he has to destroy both the walls.\n\nIf Chef starts from $(1, 1)$, he has to destroy the $1st$ wall.\n\nAs $(1, 2)$ lies on the second wall, the answer is $-1$ for the last query.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\ndef posSearch(arr, num):\n l = 0\n r = len(arr)\n if num < arr[l]:\n return 0\n elif num > arr[r-1]:\n return r\n while l < r:\n m = (l+r)//2\n if arr[m] == num:\n return -1\n if arr[m] < num < arr[m+1]:\n return m+1\n if arr[m] > num:\n r = m\n elif arr[m] < num:\n l = m+1 \n \nfor _ in range(int(input())):\n n = int(input())\n narr = list(map(int, input().split()))\n q = int(input())\n for i in range(q):\n x, y = list(map(int, input().split()))\n a = x+y\n j = posSearch(narr, a)\n print(j)\n \n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n2\\n1 3\\n5\\n0 0\\n2 0\\n0 4\\n1 1\\n1 2\\n', 'output': '0\\n1\\n2\\n1\\n-1\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/CLPNT'}","problem_id":"vfc_2722","program":"```python\ndef posSearch(arr, num):\n l = 0\n r = len(arr)\n if num < arr[l]:\n return 0\n elif num > arr[r-1]:\n return r\n while l < r:\n m = (l+r)//2\n if arr[m] == num:\n return -1\n if arr[m] < num < arr[m+1]:\n return m+1\n if arr[m] > num:\n r = m\n elif arr[m] < num:\n l = m+1 \n \nfor _ in range(int(input())):\n n = int(input())\n narr = list(map(int, input().split()))\n q = int(input())\n for i in range(q):\n x, y = list(map(int, input().split()))\n a = x+y\n j = posSearch(narr, a)\n print(j)\n \n\n```","inputs":"1\n2\n1 3\n5\n0 0\n2 0\n0 4\n1 1\n1 2\n","output":"0\n1\n2\n1\n-1\n","actual_output":"0\n1\n2\n1\n-1\n","execution_success":true,"sample_index":572},{"source":"apps","task_type":"verifiable_code","in_source_id":"971","prompt":"Solve the following coding problem using the programming language python:\n\nYou are given a sequence $A_1, A_2, \\ldots, A_N$. You want all the elements of the sequence to be equal. In order to achieve that, you may perform zero or more moves. In each move, you must choose an index $i$ ($1 \\le i \\le N$), then choose $j = i-1$ or $j = i+1$ (it is not allowed to choose $j = 0$ or $j = N+1$) and change the value of $A_i$ to $A_j$ \u2014 in other words, you should replace the value of one element of the sequence by one of its adjacent elements.\nWhat is the minimum number of moves you need to make in order to make all the elements of the sequence equal?\n\n-----Input-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The first line of each test case contains a single integer $N$.\n- The second line contains $N$ space-separated integers $A_1, A_2, \\ldots, A_N$.\n\n-----Output-----\nFor each test case, print a single line containing one integer \u2014 the minimum required number of moves.\n\n-----Constraints-----\n- $1 \\le T \\le 100$\n- $1 \\le N \\le 100$\n- $1 \\le A_i \\le 100$ for each valid $i$\n\n-----Example Input-----\n3\n5\n1 1 1 1 1\n4\n9 8 1 8\n2\n1 9\n\n-----Example Output-----\n0\n2\n1\n\n-----Explanation-----\nExample case 1: No moves are needed since all the elements are already equal.\nExample case 3: We can perform one move on either $A_1$ or $A_2$.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfor _ in range(int(input())):\n n=int(input())\n a=[int(z) for z in input().split()]\n m=0\n a1=list(set(a))\n for i in range(len(a1)):\n if a.count(a1[i])>m:\n m=a.count(a1[i])\n print(n-m)\n \n \n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\n5\\n1 1 1 1 1\\n4\\n9 8 1 8\\n2\\n1 9\\n', 'output': '0\\n2\\n1\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/CHNGIT'}","problem_id":"vfc_2726","program":"```python\nfor _ in range(int(input())):\n n=int(input())\n a=[int(z) for z in input().split()]\n m=0\n a1=list(set(a))\n for i in range(len(a1)):\n if a.count(a1[i])>m:\n m=a.count(a1[i])\n print(n-m)\n \n \n\n```","inputs":"3\n5\n1 1 1 1 1\n4\n9 8 1 8\n2\n1 9\n","output":"0\n2\n1\n","actual_output":"0\n2\n1\n","execution_success":true,"sample_index":573},{"source":"apps","task_type":"verifiable_code","in_source_id":"972","prompt":"Solve the following coding problem using the programming language python:\n\n-----\nHALLOWEEN EVE\n-----\n\nIn some other world, today is Halloween Eve.There are N trees planted in Mr. Smith\u2019s\ngarden. The height of the i-th tree (1\u2264i\u2264N) is h i meters.\nHe decides to choose K trees from these trees and decorate them with electric lights.\nTo make the scenery more beautiful, the heights of the decorated trees should be as\nclose to each other as possible.\n\n\t\n\nMore specifically, let the height of the tallest decorated tree be hmax meters, and the\nheight of the shortest decorated tree be hmin meters.\nThe smaller the value hmax\u2212hmin is, the better. What is the minimum possible value of\nhmax\u2212hmin?\n\n\t\t\n\t\t\n\n-----Constraints-----\n\n\t 2\u2264K< N \u2264105 \n\n1\u2264hi\u2264109\n\nhi is an integer\n\t\n\n-----Input Format-----\n\nInput is given from Standard Input in the following format:\n\nN K \n\nh1 \n\nh2 \n\n: \n\nhN\n\n-----Output-----\n\nPrint the minimum possible value of hmax\u2212hmin.\n\n\t\t\n\t\t\n\n-----Example Text Case-----\nInput:\n\n5 3\n10\n15\n11\n14\n12\n\nOutput:\n\n2\n\nExplanation\n\nIf we decorate the first, third and fifth trees, hmax=12,hmin=10 so hmax\u2212hmin=2. This is\noptimal.\n\t\t\n\t\t\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\ntry:\n a=list(map(int,input().split()))\n n=a[0]\n k=a[1]\n hi=[]\n for i in range(n):\n hi.append(int(input()))\n hi.sort()\n diff=[]\n for i in range(n-k+1):\n diff.append(hi[i+k-1]-hi[i])\n print(min(diff))\nexcept:\n pass\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '5 3\\n10\\n15\\n11\\n14\\n12\\n', 'output': '2\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/APO12020/problems/APOC2_03'}","problem_id":"vfc_2730","program":"```python\ntry:\n a=list(map(int,input().split()))\n n=a[0]\n k=a[1]\n hi=[]\n for i in range(n):\n hi.append(int(input()))\n hi.sort()\n diff=[]\n for i in range(n-k+1):\n diff.append(hi[i+k-1]-hi[i])\n print(min(diff))\nexcept:\n pass\n```","inputs":"5 3\n10\n15\n11\n14\n12\n","output":"2\n","actual_output":"2\n","execution_success":true,"sample_index":574},{"source":"apps","task_type":"verifiable_code","in_source_id":"973","prompt":"Solve the following coding problem using the programming language python:\n\nYou are given an $array$ of size $N$ and an integer $K$ ( $N > 1 , K > 0$ ).\nEach element in the array can be incremented by $K$ or decremented by $K$ $at$ $most$ $once$.\nSo there will be $3^n$ possible combinations of final array. (As there are 3 options for every element).\n\nOut of these combinations, you have to select a combination, in which the $absolute$ difference between the largest and the smallest element is $maximum$.\nYou have to print the $maximum$ $absolute$ $difference$.\n\n-----Input:-----\n- First line will contain $T$, number of testcases. Then the testcases follow. \n- Each testcase contains of a two lines of input\n- First line contains two integers $N, K$. \n- Second line contains $N$ space separated integers.\n\n-----Output:-----\nFor each testcase, output the maximum absolute difference that can be achieved on a new line.\n\n-----Constraints-----\n- $1 \\leq T \\leq 10$\n- $2 \\leq N \\leq 1000$\n- $1 \\leq K , arr[i] \\leq 10000$\n$NOTE$: Large input files, Use of fastio is recommended.\n\n-----Sample Input:-----\n2\n\n4 3\n\n4 2 5 1\n\n3 5\n\n2 5 3\n\n-----Sample Output:-----\n10\n\n13\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\ntestcases=int(input())\n\nfor _ in range(testcases):\n (N,K)=list(map(int,input().split()))\n array=list(map(int,input().split()))\n \n max=array[0]\n min=array[0]\n \n for i in array:\n if i>max:\n max=i\n if imax:\n max=i\n if i0:\n a=list(map(int,input().split()))\n if y>0:\n b=list(map(int,input().split()))\n if x>0 and y>0:\n a=a+b\n c=n-len(list(set(a)))\n else:\n l=x+y\n c=n-l\n x=min(c,r)\n print(x)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\n5 3 0 1\\n4\\n10 2 4 6\\n3 1 7 6\\n4 3 1 5 9 7\\n10 4 4 6\\n3 1 7 6\\n4 3 1 5 9 7\\n', 'output': '3\\n2\\n3\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/SCHTEST'}","problem_id":"vfc_2742","program":"```python\nfor _ in range(int(input())):\n n,r,x,y=map(int,input().split())\n if x>0:\n a=list(map(int,input().split()))\n if y>0:\n b=list(map(int,input().split()))\n if x>0 and y>0:\n a=a+b\n c=n-len(list(set(a)))\n else:\n l=x+y\n c=n-l\n x=min(c,r)\n print(x)\n```","inputs":"3\n5 3 0 1\n4\n10 2 4 6\n3 1 7 6\n4 3 1 5 9 7\n10 4 4 6\n3 1 7 6\n4 3 1 5 9 7\n","output":"3\n2\n3\n","actual_output":"3\n2\n3\n","execution_success":true,"sample_index":577},{"source":"apps","task_type":"verifiable_code","in_source_id":"976","prompt":"Solve the following coding problem using the programming language python:\n\nZonal Computing Olympiad 2012, 26 Nov 2011\n\nWe consider sequences of opening and closing brackets with two types of brackets, () and []. A bracket sequence is well-bracketed if we can pair up each opening bracket with a matching closing bracket in the usual sense. For instance, the sequences (), [] ([]) and []([]) are well-bracketed, while (, ()], (], )( and [(]) are not well-bracketed. In the last case, each opening bracket has a matching closing bracket and vice versa, but the intervals spanned by the different types of brackets intersect each other instead of being contained one within the other.\n\nThe alternating depth of a well-bracketed sequence tells us the maximum number of times we switch between the two types of brackets when we have inner matched brackets enclosed within outer matched brackets. For instance, the alternating depth of (), [[[]]] and ()[][] is 1, the alternating depth of [()] and ()([]) is 2, the alternating depth of ([()]) and [()][(([]))] is 3, and so on.\n\nGiven a well-bracketed sequence, we are interested in computing three quantities.\n- The alternating depth of the sequence.\n- The maximum number of symbols between any pair of matched brackets of the type ( and ), including both the outer brackets.\n- The maximum number of symbols between any pair of matched brackets of the type [ and ], including both the outer brackets.\n\nFor instance, the alternating depth of (([]))[[[()]]] is 2, the maximum number of symbols between a matched pair () is 6 and the maximum number of symbols between a matched pair [] is 8.\n\n\n\n-----Input format-----\nThe input consists of two lines. The first line is a single integer N, the length of the bracket sequence. Positions in the sequence are numbered 1,2,\u2026,N. The second line is a sequence of N space-separated integers that encode the bracket expression as follows: 1 denotes an opening bracket (, 2 denotes a closing bracket ), 3 denotes an opening bracket [ and 4 denotes a closing bracket ]. Nothing other than 1, 2, 3 or 4 appears in the second line of input and the corresponding expression is guaranteed to be well-bracketed.\n\n-----Output format-----\nYour program should print 3 space-separated integers in a line, denoting the three quantities asked for in the following order: alternating depth, length of the maximum sequence between matching () brackets and length of the maximum sequence between matching [] brackets. \n\n-----Testdata-----\nYou may assume that 2 \u2264 N \u2264 105. In 30% of the test cases, 2 \u2264 N \u2264 103.\n\n- Subtask 1 (30 marks)\n- Subtask 2 (70 marks)\n\n-----Sample Input-----\n14\n1 1 3 4 2 2 3 3 3 1 2 4 4 4\n\n-----Sample Output-----\n2 6 8\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\nn=int(input())\nstringa=list(map(int,input().split()))\ncounter=0\ncounter1=0\ncounter3=0\nsomma1=0\nsomma2=0\nmassimo=0\nmassimo1=0\nmassimo3=0 \nstack=[]\nfor par in stringa:\n if par==1 or par==3:\n if counter1==0 and par==1:\n counter1=1\n somma1=1\n massimo1=max(massimo1, 1)\n elif counter1>0:\n counter1+=1 \n somma1+=1\n massimo1=max(massimo1, somma1)\n if counter3==0 and par==3:\n counter3=1\n somma3=1\n massimo3=max(massimo3, 1)\n elif counter3>0:\n counter3+=1\n somma3+=1\n massimo3=max(massimo3, somma3)\n if counter==0:\n counter=1 \n massimo=max(massimo,1)\n if len(stack)>0 and par!=stack[-1]:\n counter+=1 \n massimo=max(massimo,counter)\n stack.append(par)\n else:\n if counter1>0:\n counter1-=1 \n somma1+=1\n massimo1=max(massimo1, somma1)\n if counter3>0:\n counter3-=1 \n somma3+=1\n massimo3=max(massimo3, somma3)\n appo=stack.pop()\n if len(stack)>0 and appo==stack[-1]:\n pass\n else:\n counter-=1\nprint(massimo, massimo1, massimo3)\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '14\\n1 1 3 4 2 2 3 3 3 1 2 4 4 4\\n', 'output': '2 6 8\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/ZCOPRAC/problems/ZCO12003'}","problem_id":"vfc_2746","program":"```python\n# cook your dish here\nn=int(input())\nstringa=list(map(int,input().split()))\ncounter=0\ncounter1=0\ncounter3=0\nsomma1=0\nsomma2=0\nmassimo=0\nmassimo1=0\nmassimo3=0 \nstack=[]\nfor par in stringa:\n if par==1 or par==3:\n if counter1==0 and par==1:\n counter1=1\n somma1=1\n massimo1=max(massimo1, 1)\n elif counter1>0:\n counter1+=1 \n somma1+=1\n massimo1=max(massimo1, somma1)\n if counter3==0 and par==3:\n counter3=1\n somma3=1\n massimo3=max(massimo3, 1)\n elif counter3>0:\n counter3+=1\n somma3+=1\n massimo3=max(massimo3, somma3)\n if counter==0:\n counter=1 \n massimo=max(massimo,1)\n if len(stack)>0 and par!=stack[-1]:\n counter+=1 \n massimo=max(massimo,counter)\n stack.append(par)\n else:\n if counter1>0:\n counter1-=1 \n somma1+=1\n massimo1=max(massimo1, somma1)\n if counter3>0:\n counter3-=1 \n somma3+=1\n massimo3=max(massimo3, somma3)\n appo=stack.pop()\n if len(stack)>0 and appo==stack[-1]:\n pass\n else:\n counter-=1\nprint(massimo, massimo1, massimo3)\n\n```","inputs":"14\n1 1 3 4 2 2 3 3 3 1 2 4 4 4\n","output":"2 6 8\n","actual_output":"2 6 8\n","execution_success":true,"sample_index":578},{"source":"apps","task_type":"verifiable_code","in_source_id":"977","prompt":"Solve the following coding problem using the programming language python:\n\nChef recently graduated Computer Science in university, so he was looking for a job. He applied for several job offers, but he eventually settled for a software engineering job at ShareChat. Chef was very enthusiastic about his new job and the first mission assigned to him was to implement a message encoding feature to ensure the chat is private and secure.\nChef has a message, which is a string $S$ with length $N$ containing only lowercase English letters. It should be encoded in two steps as follows: \n- Swap the first and second character of the string $S$, then swap the 3rd and 4th character, then the 5th and 6th character and so on. If the length of $S$ is odd, the last character should not be swapped with any other.\n- Replace each occurrence of the letter 'a' in the message obtained after the first step by the letter 'z', each occurrence of 'b' by 'y', each occurrence of 'c' by 'x', etc, and each occurrence of 'z' in the message obtained after the first step by 'a'.\nThe string produced in the second step is the encoded message. Help Chef and find this message.\n\n-----Input-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The first line of each test case contains a single integer $N$.\n- The second line contains the message string $S$.\n\n-----Output-----\nFor each test case, print a single line containing one string \u2014 the encoded message.\n\n-----Constraints-----\n- $1 \\le T \\le 1,000$\n- $1 \\le N \\le 100$\n- $|S| = N$\n- $S$ contains only lowercase English letters\n\n-----Example Input-----\n2\n9\nsharechat\n4\nchef\n\n-----Example Output-----\nshizxvzsg\nsxuv\n\n-----Explanation-----\nExample case 1: The original message is \"sharechat\". In the first step, we swap four pairs of letters (note that the last letter is not swapped), so it becomes \"hsraceaht\". In the second step, we replace the first letter ('h') by 's', the second letter ('s') by 'h', and so on, so the resulting encoded message is \"shizxvzsg\".\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\ntry:\n for _ in range(int(input())):\n n = int(input())\n li = [i for i in input()]\n a = 0\n while a+1fh:\n li.append(chr(fh-(ord(i)-sh)))\n else:\n li.append(chr(sh+(fh-ord(i))))\n for i in li:\n print(i,end=\"\")\n print()\nexcept:\n pass \n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n9\\nsharechat\\n4\\nchef\\n', 'output': 'shizxvzsg\\nsxuv\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/ENCMSG'}","problem_id":"vfc_2750","program":"```python\n# cook your dish here\ntry:\n for _ in range(int(input())):\n n = int(input())\n li = [i for i in input()]\n a = 0\n while a+1fh:\n li.append(chr(fh-(ord(i)-sh)))\n else:\n li.append(chr(sh+(fh-ord(i))))\n for i in li:\n print(i,end=\"\")\n print()\nexcept:\n pass \n```","inputs":"2\n9\nsharechat\n4\nchef\n","output":"shizxvzsg\nsxuv\n","actual_output":"shizxvzsg\nsxuv\n","execution_success":true,"sample_index":579},{"source":"apps","task_type":"verifiable_code","in_source_id":"979","prompt":"Solve the following coding problem using the programming language python:\n\nYou are given a grid of size M x N, where each square is colored with some random color among K colors with each having equal probability.\n\nA Good Rectangle is defined as one where all squares lying on the inner border are of the same color.\n\nWhat is the expected number of Good Rectangles in the given grid.\n\n-----Input-----\n\n- \nFirst Line contains M, N, K\n\n-----Output-----\nA single value rounded off to the nearest Integer corresponding to the required answer.\n\n-----Constraints-----\n- 1 <= N <= 105 \n- 1 <= M <= 105 \n- 1 <= K <= 105 \n\n-----Example-----\nInput:\n1 3 1\nOutput:\n6\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\ndef for1(M,k):\n ret = 0.0\n x = k*k+0.0\n z=x\n for m in range(1,M):\n ret+=(M-m)/x\n x*=z\n return ret \n \ndef for2(M,k):\n ret = 0.0\n x = k+0.0\n for m in range(1,M):\n ret+=(M-m)/x\n \n x*=k\n return ret \n \ndef ans(M,N,K):\n\n return int(round(M*N+M*for2(N,K)+N*for2(M,K)+K*for1(M,K)*for1(N,K),0))\nM,N,K = list(map(int,input().split()))\nprint(ans(M,N,K)) \n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1 3 1\\n', 'output': '6\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/IPC15P1C/problems/GRECT'}","problem_id":"vfc_2758","program":"```python\ndef for1(M,k):\n ret = 0.0\n x = k*k+0.0\n z=x\n for m in range(1,M):\n ret+=(M-m)/x\n x*=z\n return ret \n \ndef for2(M,k):\n ret = 0.0\n x = k+0.0\n for m in range(1,M):\n ret+=(M-m)/x\n \n x*=k\n return ret \n \ndef ans(M,N,K):\n\n return int(round(M*N+M*for2(N,K)+N*for2(M,K)+K*for1(M,K)*for1(N,K),0))\nM,N,K = list(map(int,input().split()))\nprint(ans(M,N,K)) \n\n```","inputs":"1 3 1\n","output":"6\n","actual_output":"6\n","execution_success":true,"sample_index":581},{"source":"apps","task_type":"verifiable_code","in_source_id":"981","prompt":"Solve the following coding problem using the programming language python:\n\nChef is very fond of horses. He enjoys watching them race. As expected, he has a stable full of horses. He, along with his friends, goes to his stable during the weekends to watch a few of these horses race. Chef wants his friends to enjoy the race and so he wants the race to be close. This can happen only if the horses are comparable on their skill i.e. the difference in their skills is less.\nThere are N horses in the stable. The skill of the horse i is represented by an integer S[i]. The Chef needs to pick 2 horses for the race such that the difference in their skills is minimum. This way, he would be able to host a very interesting race. Your task is to help him do this and report the minimum difference that is possible between 2 horses in the race.\n\n-----Input:-----\nFirst line of the input file contains a single integer T, the number of test cases.\n\nEvery test case starts with a line containing the integer N.\n\nThe next line contains N space separated integers where the i-th integer is S[i].\n\n-----Output:-----\nFor each test case, output a single line containing the minimum difference that is possible.\n\n-----Constraints:-----\n1 \u2264 T \u2264 10\n2 \u2264 N \u2264 5000\n1 \u2264 S[i] \u2264 1000000000\n\n-----Example:-----Input:\n1\n5\n4 9 1 32 13\n\nOutput:\n3\n\nExplanation: The minimum difference can be achieved if we pick horses with skills 1 and 4 for the race.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nt=eval(input())\nfor q in range(t):\n l=eval(input())\n a=input().split()\n a=[int(x) for x in a]\n a=sorted(a)\n for i in range(l-1):\n a[i]=(a[i+1]-a[i]) \n print(min(a[0:l-1]))\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n5\\n4 9 1 32 13\\n', 'output': '3\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/SEP12/problems/HORSES'}","problem_id":"vfc_2766","program":"```python\nt=eval(input())\nfor q in range(t):\n l=eval(input())\n a=input().split()\n a=[int(x) for x in a]\n a=sorted(a)\n for i in range(l-1):\n a[i]=(a[i+1]-a[i]) \n print(min(a[0:l-1]))\n\n```","inputs":"1\n5\n4 9 1 32 13\n","output":"3\n","actual_output":"3\n","execution_success":true,"sample_index":583},{"source":"apps","task_type":"verifiable_code","in_source_id":"982","prompt":"Solve the following coding problem using the programming language python:\n\nSpecial Numbers \nMani has encountered a problem on Special numbers in Bytecode. A number S is called a special number if its digits are in an arithmetic progression modulo 10. He has an array consisting of all numbers from 1 to N and needs your help to find the number of special numbers in the array. He has promised you a significant share of the prize money if he wins the contest :p \nNote:\n123,99,802 are special numbers.\n146 is not a special number \n\n-----Input-----\n\nInput consists of 1 integer - the value of N\n\n-----Output-----\nPrint one integer in the first line - the solution to this problem\n\n-----Constraints-----\n- 1 \u2264 Number of digits in N \u2264 105\n\nExample\n\nInput\n\n123\n\nOutput\n\n102\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your code here\nn=input()\nx=len(n)\nno=list(map(int,n))\ntemp=[0]*x\nif (x>2):\n sum=99\n for i in range(3,x):\n sum=sum+90\n sum=sum+10*(int(n[0])-1)\n sum=sum+int(n[1])\n f=int(n[0])%10\n \n s=int(n[1])%10\n \n cd=s-f\n \n temp[0]=n[0]\n temp[1]=n[1]\n for i in range(2,x):\n nxt=(s+cd)%10\n temp[i]=(chr(nxt+48))\n s=nxt\n temp=list(map(int,temp))\n if(temp<=no):\n sum=sum+1\n print(sum)\nelse:\n print(n)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '123\\n', 'output': '102\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/BYCO2016/problems/BYCD1603'}","problem_id":"vfc_2770","program":"```python\n# cook your code here\nn=input()\nx=len(n)\nno=list(map(int,n))\ntemp=[0]*x\nif (x>2):\n sum=99\n for i in range(3,x):\n sum=sum+90\n sum=sum+10*(int(n[0])-1)\n sum=sum+int(n[1])\n f=int(n[0])%10\n \n s=int(n[1])%10\n \n cd=s-f\n \n temp[0]=n[0]\n temp[1]=n[1]\n for i in range(2,x):\n nxt=(s+cd)%10\n temp[i]=(chr(nxt+48))\n s=nxt\n temp=list(map(int,temp))\n if(temp<=no):\n sum=sum+1\n print(sum)\nelse:\n print(n)\n```","inputs":"123\n","output":"102\n","actual_output":"102\n","execution_success":true,"sample_index":584},{"source":"apps","task_type":"verifiable_code","in_source_id":"983","prompt":"Solve the following coding problem using the programming language python:\n\nOmy and Ish were learning the pattern printing. In order to learn they give themselves a task. In this task they are given a string and they have to form a pyramid with the pattern as follows:\nRowNumber are one based indexed.\n- \nIf (RowNumber % 3 == 0) then string is written in left to right while in other cases it is written in right to left order.\n- \nif the string end it will be started again and end of the pyramid need not to be the end of string.\nFor eg: string is \u201c$CODING$\u201d and height of pyramid is \u201c$5$\u201d\nC\nD O\nI N G\nI D O C\nD O C G N\n\nOmi will be asked $Q$ queries and he has to tell the frequency of a character C in that particular row $R$ of pyramid.\n\n-----Input:-----\n- First line will contain $N$, height of pyramid.\n- Next line contain a string consists only of Uppercase English Alphabets, length not exceed $10^6$\n- Third line contain a single integer $Q$, the number of queries to be asked.\n- Each query contain two space separated integers, $R$ and $C$, where $R$ is the row number and $C$ is the character.\n\n-----Output:-----\n- For each query, output in a single line the frequency of the alphabet in the given row.\n\n-----Constraints:-----\n- $1$ $\\leq$ $N$ $\\leq$ $10$^$18$\n- $1$ $\\leq$ $Q$ $\\leq$ $50000$\n- $1 \\leq R \\leq N$\n- $A \\leq C \\leq Z$\n\n-----Sample Input:-----\n5\nCODING\n2\n1 C\n2 D\n\n-----Sample Output:-----\n1\n1\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nimport sys\r\n\r\nn = int(sys.stdin.readline().strip())\r\ns = sys.stdin.readline().strip()\r\n\r\nalph = \"ABCDEFGHIJKLMNOPQRSTUVWXYZ\"\r\n\r\narr = [0]*26\r\npref = []\r\n\r\nfor i in range(len(s)):\r\n\tfor j in range(26):\r\n\t\tif alph[j] == s[i]:\r\n\t\t\tarr[j] += 1\r\n\t\t\tbreak\r\n\tpref += [arr[:]]\r\n\r\n# for x in pref:\r\n# \tprint(x)\r\n\r\nq = int(sys.stdin.readline().strip())\r\n\r\nfor _ in range(q):\r\n\tr, c = sys.stdin.readline().strip().split()\r\n\r\n\tfor i in range(26):\r\n\t\tif alph[i] == c:\r\n\t\t\tind = i\r\n\t\t\tbreak\r\n\r\n\tr = int(r)\r\n\r\n\tprev = ((r-1)**2 + r-1)//2\r\n\r\n\tdone = prev%len(s)\r\n\r\n\tans = 0\r\n\trem = (len(s) - done)%len(s)\r\n\r\n\tif r <= rem:\r\n\t\tprint(pref[done+r-1][ind] - pref[done-1][ind])\r\n\t\tcontinue\r\n\r\n\tif rem != 0:\r\n\t\tans += pref[-1][ind] - pref[done-1][ind]\r\n\t\tr -= rem\r\n\r\n\tans += pref[-1][ind] * (r//len(s))\r\n\tr %= len(s)\r\n\r\n\t# print(\"AA\", ans, r)\r\n\r\n\tif r != 0:\r\n\t\tans += pref[r-1][ind]\r\n\r\n\tprint(ans)\r\n\r\n\r\n\t# print(rem, done, prev)\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '5\\nCODING\\n2\\n1 C\\n2 D\\n', 'output': '1\\n1\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/LICO2020/problems/PATTERNG'}","problem_id":"vfc_2774","program":"```python\nimport sys\r\n\r\nn = int(sys.stdin.readline().strip())\r\ns = sys.stdin.readline().strip()\r\n\r\nalph = \"ABCDEFGHIJKLMNOPQRSTUVWXYZ\"\r\n\r\narr = [0]*26\r\npref = []\r\n\r\nfor i in range(len(s)):\r\n\tfor j in range(26):\r\n\t\tif alph[j] == s[i]:\r\n\t\t\tarr[j] += 1\r\n\t\t\tbreak\r\n\tpref += [arr[:]]\r\n\r\n# for x in pref:\r\n# \tprint(x)\r\n\r\nq = int(sys.stdin.readline().strip())\r\n\r\nfor _ in range(q):\r\n\tr, c = sys.stdin.readline().strip().split()\r\n\r\n\tfor i in range(26):\r\n\t\tif alph[i] == c:\r\n\t\t\tind = i\r\n\t\t\tbreak\r\n\r\n\tr = int(r)\r\n\r\n\tprev = ((r-1)**2 + r-1)//2\r\n\r\n\tdone = prev%len(s)\r\n\r\n\tans = 0\r\n\trem = (len(s) - done)%len(s)\r\n\r\n\tif r <= rem:\r\n\t\tprint(pref[done+r-1][ind] - pref[done-1][ind])\r\n\t\tcontinue\r\n\r\n\tif rem != 0:\r\n\t\tans += pref[-1][ind] - pref[done-1][ind]\r\n\t\tr -= rem\r\n\r\n\tans += pref[-1][ind] * (r//len(s))\r\n\tr %= len(s)\r\n\r\n\t# print(\"AA\", ans, r)\r\n\r\n\tif r != 0:\r\n\t\tans += pref[r-1][ind]\r\n\r\n\tprint(ans)\r\n\r\n\r\n\t# print(rem, done, prev)\n\n```","inputs":"5\nCODING\n2\n1 C\n2 D\n","output":"1\n1\n","actual_output":"1\n1\n","execution_success":true,"sample_index":585},{"source":"apps","task_type":"verifiable_code","in_source_id":"984","prompt":"Solve the following coding problem using the programming language python:\n\nGiven an array $A$ of size $N$ , count number of pairs of index $i,j$ such that $A_i$ is even, $A_j$ is odd and $i < j$\n\n-----Input-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. \n- The first line of each test case contains integer $N$. \n- The second line of each test case contains $N$ space separated integers $A_i$. \n\n-----Output-----\nFor each test case, print a single line containing an integer denoting number of pairs.\n\n-----Constraints-----\n- $1 \\le T \\le 100$\n- $2 \\le N \\le 10^5$ \n- $1 \\le A_i \\le 10^9$\n- Sum of $N$ over all test cases doesn't exceed $10^6 $ \n\n-----Subtasks-----\nSubtask #1 (30 points):\n- $2 \\le N \\le 100$ \nSubtask #2 (70 points): original constraints\n\n-----Example Input-----\n2\n4\n1 2 1 3\n5\n5 4 1 2 3\n\n-----Example Output-----\n2\n3\n\n-----Explanation-----\nExample case 1:$(A_2,A_3)$ and $(A_2,A_4)$ . \nExample case 2:$(A_2,A_3)$ , $(A_2,A_5)$ and $(A_4,A_5)$ .\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nt = int(input())\nfor i in range(t):\n n = int(input())\n l = list(map(int, input().split()))\n counter = 0\n even = 0\n for num in l:\n if num % 2 == 0:\n even += 1 \n if num % 2 == 1:\n counter += even\n print(counter)\n \n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n4\\n1 2 1 3\\n5\\n5 4 1 2 3\\n', 'output': '2\\n3\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/CPAIRS'}","problem_id":"vfc_2778","program":"```python\nt = int(input())\nfor i in range(t):\n n = int(input())\n l = list(map(int, input().split()))\n counter = 0\n even = 0\n for num in l:\n if num % 2 == 0:\n even += 1 \n if num % 2 == 1:\n counter += even\n print(counter)\n \n\n```","inputs":"2\n4\n1 2 1 3\n5\n5 4 1 2 3\n","output":"2\n3\n","actual_output":"2\n3\n","execution_success":true,"sample_index":586},{"source":"apps","task_type":"verifiable_code","in_source_id":"987","prompt":"Solve the following coding problem using the programming language python:\n\nBack in 2015, Usain Bolt announced that he'll be retiring after the 2017 World Championship. Though his final season did not end gloriously, we all know that he is a true legend and we witnessed his peak during 2008 - 2013. \nPost retirement, Usain Bolt is still leading an adventurous life. He's exploring the unexplored parts of the globe. But sometimes he gets bored, and reads questions asked about him on Quora. One such question he read was, \"Who would win a race between Usain Bolt and a tiger if the race is on a straight line track and the tiger is $distancetoBolt$ meters behind Bolt? The finishing point is $finish$ meters away from Bolt's starting position. The tiger starts with an initial speed of $0$ $meter/second$, and will accelerate itself with $tigerAccelaration$ $m/s^2$. Bolt can run with a constant speed of $boltSpeed$ $m/s$ from start to finish. Given these values, find out who will win the race - Bolt or the tiger? \"\nNote that Bolt will win the race if and only if he touches the finishing line before the tiger touches it. If both of them finish together, the tiger is announced as the winner since Bolt was given an initial advantage. See the figure below for more clarity.\n\nSince Bolt was busy practicing in the tracks during his Physics school classes, he is asking for your help to solve the question. Can you please help him?\nHe just remembers two formulae from the class, and thinks that they will be useful to you:\n$Displacement (S) $ = $ut$ +$ (1/2)at^2$ where $u$ is the initial velocity , #$ $is the acceleration and $t$ is the time taken.\n$Velocity$ = $Displacement /Time$\n\n-----Input:-----\n- The first line will contain $T$, the number of testcases. Then the description of each test case follow. \n- Each test case contains 4 integers $finish, distancetoBolt, tigerAccelaration, boltSpeed$. \n\n-----Output:-----\nFor each testcase, output in a single line, the word \"Bolt\" or \"Tiger\" without quotes, depending on whether Bolt wins or the tiger wins.\n\n-----Constraints-----\n- $1 \\leq T \\leq 100000$\n- $1 \\leq finish\\leq 10^5$\n- $1 \\leq distancetoBolt\\leq 10^5$\n- $1 \\leq tigerAccelaration\\leq 10^5$\n- $1 \\leq boltSpeed\\leq 10^5$\n\n-----Sample Input:-----\n2\n10 100 10 10\n100 10 5 10\n\n-----Sample Output:-----\nBolt\nTiger\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfor i in range(int(input())):\n finish,distanetobolt,tigerAcceleration,boltspeed=map(int,input().split())\n t1=((2*(finish+distanetobolt)/(tigerAcceleration))**0.5)\n t2=(finish/boltspeed)\n if t1>t2:\n print(\"Bolt\")\n elif t1t2:\n print(\"Bolt\")\n elif t1(n//2)):\n res+=\"0\"\n mysum+=(n-mycount)*int(pow(2,i))\n else:\n res+=\"1\"\n mysum+=mycount*int(pow(2,i))\n print(mysum)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\n5\\n2 3 4 5 6\\n4\\n7 7 7 7\\n3\\n1 1 3\\n', 'output': '14\\n0\\n2\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/MINARRS'}","problem_id":"vfc_2794","program":"```python\n# cook your dish here\n# cook your dish here\ntest=int(input())\nfor _ in range(test):\n n=int(input())\n a=[(bin(int(x))[2:][::-1]+(\"0\")*32)for x in input().split()]\n res=\"\"\n mysum=0\n for i in range(32):\n mycount=0\n for j in range(n):\n if(a[j][i]==\"0\"):\n mycount+=1\n if(mycount==n):\n break\n if(mycount>(n//2)):\n res+=\"0\"\n mysum+=(n-mycount)*int(pow(2,i))\n else:\n res+=\"1\"\n mysum+=mycount*int(pow(2,i))\n print(mysum)\n```","inputs":"3\n5\n2 3 4 5 6\n4\n7 7 7 7\n3\n1 1 3\n","output":"14\n0\n2\n","actual_output":"14\n0\n2\n","execution_success":true,"sample_index":590},{"source":"apps","task_type":"verifiable_code","in_source_id":"989","prompt":"Solve the following coding problem using the programming language python:\n\nChef and Paja are bored, so they are playing an infinite game of ping pong. The rules of the game are as follows:\n- The players play an infinite number of games. At the end of each game, the player who won it scores a point.\n- In each game, one of the players serves. Chef serves in the first game.\n- After every $K$ points are scored (regardless of which players scored them), i.e. whenever $K$ games have been played since the last time the serving player changed, the player that serves in the subsequent games changes: if Chef served in the game that just finished, then Paja will serve in the next game and all subsequent games until the serving player changes again; if Paja served, then Chef will serve.\nThe players got a little too caught up in the game and they forgot who is supposed to serve in the next game. Will you help them determine that? So far, Chef has scored $X$ points and Paja has scored $Y$ points.\n\n-----Input-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The first and only line of each test case contains three space-separated integers $X$, $Y$ and $K$.\n\n-----Output-----\nFor each test case, print a single line containing the string \"Chef\" if Chef is supposed to serve next or \"Paja\" otherwise (without quotes).\n\n-----Constraints-----\n- $1 \\le T \\le 50$\n- $0 \\le X, Y \\le 10^9$\n- $1 \\le K \\le 10^9$\n\n-----Subtasks-----\nSubtask #1 (100 points): original constraints\n\n-----Example Input-----\n3\n1 3 3\n5 7 2\n38657 76322 564\n\n-----Example Output-----\nPaja\nChef\nPaja\n\n-----Explanation-----\nExample case 1: Chef served for the first three games, after that Paja started serving. He only served in one game, so he is supposed to serve next.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nn=int(input())\nwhile(n>0):\n x,y,z=map(int,input().split())\n t=(x+y)//z\n if t%2==0:\n print('Chef')\n else:\n print('Paja')\n n-=1\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\n1 3 3\\n5 7 2\\n38657 76322 564\\n', 'output': 'Paja\\nChef\\nPaja\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/PAJAPONG'}","problem_id":"vfc_2798","program":"```python\nn=int(input())\nwhile(n>0):\n x,y,z=map(int,input().split())\n t=(x+y)//z\n if t%2==0:\n print('Chef')\n else:\n print('Paja')\n n-=1\n```","inputs":"3\n1 3 3\n5 7 2\n38657 76322 564\n","output":"Paja\nChef\nPaja\n","actual_output":"Paja\nChef\nPaja\n","execution_success":true,"sample_index":591},{"source":"apps","task_type":"verifiable_code","in_source_id":"990","prompt":"Solve the following coding problem using the programming language python:\n\nTheatre Square in the capital city of Berland has a rectangular shape with the size n\u2009\u00d7\u2009m meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size a\u2009\u00d7\u2009a.\nWhat is the least number of flagstones needed to pave the Square? It's allowed to cover the surface larger than the Theatre Square, but the Square has to be covered. It's not allowed to break the flagstones. The sides of flagstones should be parallel to the sides of the Square.\nInput\nThe input contains three positive integer numbers in the first line: n,\u2009\u2009m and a (1\u2009\u2264\u2009\u2009n,\u2009m,\u2009a\u2009\u2264\u200910^9).\nOutput\nPrint the needed number of flagstones in new line.\nExamples\ninput\n6 6 4\noutput\n4\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\ntry:\r\n n,m,a=map(int,input().split())\r\n if n%a!=0:\r\n number1=(n//a)+1\r\n else:\r\n number1=(n//a)\r\n if m%a!=0:\r\n number2=(m//a)+1\r\n else:\r\n number2=(m//a)\r\n print(number1*number2)\r\nexcept:\r\n pass\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': 's\\ninput\\n6 6 4\\noutput\\n4\\n', 'output': ''}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/CSTR2020/problems/MALLTILE'}","problem_id":"vfc_2802","program":"```python\ntry:\r\n n,m,a=map(int,input().split())\r\n if n%a!=0:\r\n number1=(n//a)+1\r\n else:\r\n number1=(n//a)\r\n if m%a!=0:\r\n number2=(m//a)+1\r\n else:\r\n number2=(m//a)\r\n print(number1*number2)\r\nexcept:\r\n pass\n```","inputs":"s\ninput\n6 6 4\noutput\n4\n","output":"","actual_output":"","execution_success":true,"sample_index":592},{"source":"apps","task_type":"verifiable_code","in_source_id":"991","prompt":"Solve the following coding problem using the programming language python:\n\nThe Chef once decided to prepare some nice dishes on his birthday. There are N items kept on his shelf linearly from position 1 to N. Taste of the i-th item is denoted by a integer Ai.\n\nHe wants to make Q dishes. A dish will be made using some ingredients in the continuous range AL, AL + 1, , , AR (1-base indexing). Quality of the dish will be determined by the ingredient with minimum taste.\n\nChef wants help of his assistant Rupsa to find out sum and product of qualities of the dishes. As product of the qualities of the dishes could be very large, print it modulo 109 + 7. Also, you are given an integer K and you are assured that for each dish, the size of continuous range of the ingredients (i.e. R - L + 1) will always lie between K and 2 * K, both inclusive.\n\nMethod of generation of Array A \n\nYou are given non-negative integer parameters a, b, c, d, e, f, r, s, t, m, A[1]\n\nfor x = 2 to N:\n\tif(t^x mod s <= r) // Here t^x signifies \"t to the power of x\"\n\t\tA[x] = (a*A[x-1]^2 + b*A[x-1] + c) mod m\n\telse\n\t\tA[x] = (d*A[x-1]^2 + e*A[x-1] + f) mod m\n\nMethod of generation of range of ingredients for Q dishes \n\nYou are given non-negative integer parameters L1, La, Lc, Lm, D1, Da, Dc, Dm\n\nfor i = 1 to Q:\n\tL1 = (La * L1 + Lc) mod Lm;\n\tD1 = (Da * D1 + Dc) mod Dm; \n\tL = L1 + 1;\n\tR = min(L + K - 1 + D1, N);\n\n-----Input-----\n- The first line contains three integers N, K and Q.\n- The second line contains the integers a, b, c, d, e, f, r, s, t, m, and A[1].\n- Then third line contains the integers L1, La, Lc, Lm, D1, Da, Dc, and Dm\n\n-----Output-----\nOutput two space separated integers:\n\n- The sum of qualities of the dishes.\n- The product of qualities of the dishes modulo 109+7.\n\n-----Constraints-----\n- 1 \u2264 N, Q \u2264 107\n- 1 \u2264 K \u2264 N\n- 0 \u2264 a, b, c, d, e, f, r, s, t, m, A[1] \u2264 109+7\n- 1 \u2264 Lm \u2264 N - K + 1\n- 1 \u2264 Dm \u2264 K + 1\n- 1 \u2264 La, Lc \u2264 Lm\n- 1 \u2264 Da, Dc \u2264 Dm\n- 1 \u2264 L1 \u2264 N\n- 1 \u2264 D1 \u2264 K\n\n-----Sub tasks-----\n- Subtask #1: 1 \u2264 N, Q \u2264 1000 (10 points)\n- Subtask #2: 1 \u2264 Q \u2264 104 (20 points)\n- Subtask #3: original constraints (70 points)\n\n-----Example-----\nInput:\n4 2 1\n1 1 1 1 1 1 1 1 1 100 1 \n1 1 1 3 1 1 1 2\n\nOutput:\n13 13\n\n-----Explanation-----\n- The array A comes out to be {1, 3, 13, 83} and the first dish has L = 3 and R = 4. The minimum in this range is 13, thus the sum and product both are 13 and hence the answer.\n\n-----Note-----\nMultiplier for C# and Java have been reduced to 1.5 instead of 2.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nn,k, q = list(map(int, input().split()))\nmod = 10 ** 9 + 7\nA = [0] * n\na, b, c, d, e, f, r, s, t, m, x = list(map(int, input().split())) \nA[0] = x \n\nfor x in range(1, n):\n if pow(t, x+1, s) <= r:\n A[x] = (a*pow(A[x-1], 2, m) + b*A[x-1] + c) % m\n else:\n A[x] = (d*pow(A[x-1], 2, m) + e*A[x-1] + f) % m\n \ndef SRMQ(arr, k):\n from collections import deque\n n = len(arr)\n ans = [None] * n\n deque = deque()\n for i in range(len(arr)):\n while deque and deque[-1] > arr[i]:\n deque.pop()\n deque.append(arr[i])\n if i >= k and arr[i-k] == deque[0]:\n deque.popleft()\n if i >= k-1:\n ans[i-k+1] = deque[0]\n return ans\n \nv = SRMQ(A, k) \n\nL1, La, Lc, Lm, D1, Da, Dc, Dm = list(map(int, input().split()))\ns = 0 \nprod = 1 \nfor _ in range(q):\n L1 = (La * L1 + Lc) % Lm;\n D1 = (Da * D1 + Dc) %Dm; \n L = L1 + 1;\n R = min(L + k - 1 + D1, n);\n z = min(v[L-1], v[R-k])\n s += z \n \n prod = (prod * z) % mod\nprint(s, prod)\n\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '4 2 1\\n1 1 1 1 1 1 1 1 1 100 1\\n1 1 1 3 1 1 1 2\\n', 'output': '13 13\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/CHEFCK'}","problem_id":"vfc_2806","program":"```python\nn,k, q = list(map(int, input().split()))\nmod = 10 ** 9 + 7\nA = [0] * n\na, b, c, d, e, f, r, s, t, m, x = list(map(int, input().split())) \nA[0] = x \n\nfor x in range(1, n):\n if pow(t, x+1, s) <= r:\n A[x] = (a*pow(A[x-1], 2, m) + b*A[x-1] + c) % m\n else:\n A[x] = (d*pow(A[x-1], 2, m) + e*A[x-1] + f) % m\n \ndef SRMQ(arr, k):\n from collections import deque\n n = len(arr)\n ans = [None] * n\n deque = deque()\n for i in range(len(arr)):\n while deque and deque[-1] > arr[i]:\n deque.pop()\n deque.append(arr[i])\n if i >= k and arr[i-k] == deque[0]:\n deque.popleft()\n if i >= k-1:\n ans[i-k+1] = deque[0]\n return ans\n \nv = SRMQ(A, k) \n\nL1, La, Lc, Lm, D1, Da, Dc, Dm = list(map(int, input().split()))\ns = 0 \nprod = 1 \nfor _ in range(q):\n L1 = (La * L1 + Lc) % Lm;\n D1 = (Da * D1 + Dc) %Dm; \n L = L1 + 1;\n R = min(L + k - 1 + D1, n);\n z = min(v[L-1], v[R-k])\n s += z \n \n prod = (prod * z) % mod\nprint(s, prod)\n\n\n```","inputs":"4 2 1\n1 1 1 1 1 1 1 1 1 100 1\n1 1 1 3 1 1 1 2\n","output":"13 13\n","actual_output":"13 13\n","execution_success":true,"sample_index":593},{"source":"apps","task_type":"verifiable_code","in_source_id":"992","prompt":"Solve the following coding problem using the programming language python:\n\nJanuary and February are usually very cold in ChefLand. The temperature may reach -20 and even -30 degrees Celsius. Because of that, many people seal up windows in their houses.\nSergey also lives in ChefLand. He wants to seal the window in his house. The window has the shape of a simple convex polygon with N vertices.\nFor the sealing, there are M kinds of sticky stripes, which are sold in the shops. The stripe of the ith type has the length of Li millimeters and the cost of Ci rubles.\nThe sealing process consists in picking the stripe and sticking it on the border of the window. The stripe can't be cut (it is made of very lasting material) and can only be put straight, without foldings. It is not necessary to put the strip strictly on the window border, it can possibly extend outside the border side of window too (by any possible amount). The window is considered sealed up if every point on its' border is covered with at least one stripe.\nNow Sergey is curious about the stripes he needs to buy. He wonders about the cheapest cost, at which he can seal his window. Please help him.\n\n-----Input-----\nThe first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.\nThe first line of each test case contains a single integer N denoting the number of number of vertices in the polygon denoting Sergey's window.\nEach of the following N lines contains a pair of space-separated integer numbers Xi Yi, denoting the coordinates of the ith points.\nThe following line contains a single integer M denoting the number of types of sticky stripe which is sold in the shop.\nEach of the following M lines contains a pair of space-separated integers Li Ci denoting the length and the cost of the sticky stripe of the ith type respectively.\n\n-----Output-----\nFor each test case, output a single line containing the minimum cost of sealing up the window.\n\n-----Constraints-----\n- 1 \u2264 T \u2264 10\n- The coordinates of the window are given either in clockwise or in a counter-clockwise order.\n- No three or more vertices lie on the same line (i.e. are collinear).\n- 0 \u2264 Xi, Yi \u2264 106\n- 1 \u2264 Li, Ci \u2264 106\n\n-----Subtasks-----\n- Subtask #1 (17 points): 3 \u2264 N \u2264 10, M = 1\n- Subtask #2 (24 points): 3 \u2264 N \u2264 42, M \u2264 2\n- Subtask #3 (59 points): 3 \u2264 N \u2264 2000, 1 \u2264 M \u2264 10\n\n-----Example-----\nInput:1\n4\n0 0\n1000 0\n1000 2000\n0 2000\n2\n1000 10\n2000 15\n\nOutput:50\n\n-----Explanation-----\nExample case 1. In this case, Sergey's window is a rectangle with the side lengths of 1000 and 2000. There are two types of the sticky stripes in the shop - the one of the length 1000 with the cost of 10 rubles and with the length of 2000 and the cost of 15 rubles. The optimal solution would be to buy 2 stripes of the first type 2 stripes of the second type. The cost will be 2 \u00d7 15 + 2 \u00d7 10 = 50 rubles.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfrom math import sqrt\nimport sys\nsys.setrecursionlimit(10**8)\nintMax = 10**18\ndef knapsack(rl,l,c,m):\n if m==0 and rl>0:\n return intMax\n if rl<=0:\n return 0\n return min(c[m-1]+knapsack(rl-l[m-1],l,c,m),knapsack(rl,l,c,m-1))\nfor _ in range(int(input())):\n n= int(input())\n cost=[]\n length=[]\n sides=[]\n for i in range(n):\n x,y = map(int,input().split())\n if i == 0:\n x0 = x\n y0 = y\n prevx = x\n prevy = y\n elif i == n-1:\n sides.append(sqrt((prevx-x)**2 + (prevy-y)**2))\n sides.append(sqrt((x0-x)**2 + (y0-y)**2))\n else:\n sides.append(sqrt((prevx-x)**2 + (prevy-y)**2))\n prevx = x\n prevy = y\n m = int(input())\n for j in range(m):\n li,ci = map(int,input().split())\n length.append(li)\n cost.append(ci)\n ans=0\n #print(sides)\n for k in sides:\n ans= ans + knapsack(k,length,cost,m)\n print(int(ans))\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n4\\n0 0\\n1000 0\\n1000 2000\\n0 2000\\n2\\n1000 10\\n2000 15\\n', 'output': '50\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/SEALUP'}","problem_id":"vfc_2810","program":"```python\nfrom math import sqrt\nimport sys\nsys.setrecursionlimit(10**8)\nintMax = 10**18\ndef knapsack(rl,l,c,m):\n if m==0 and rl>0:\n return intMax\n if rl<=0:\n return 0\n return min(c[m-1]+knapsack(rl-l[m-1],l,c,m),knapsack(rl,l,c,m-1))\nfor _ in range(int(input())):\n n= int(input())\n cost=[]\n length=[]\n sides=[]\n for i in range(n):\n x,y = map(int,input().split())\n if i == 0:\n x0 = x\n y0 = y\n prevx = x\n prevy = y\n elif i == n-1:\n sides.append(sqrt((prevx-x)**2 + (prevy-y)**2))\n sides.append(sqrt((x0-x)**2 + (y0-y)**2))\n else:\n sides.append(sqrt((prevx-x)**2 + (prevy-y)**2))\n prevx = x\n prevy = y\n m = int(input())\n for j in range(m):\n li,ci = map(int,input().split())\n length.append(li)\n cost.append(ci)\n ans=0\n #print(sides)\n for k in sides:\n ans= ans + knapsack(k,length,cost,m)\n print(int(ans))\n```","inputs":"1\n4\n0 0\n1000 0\n1000 2000\n0 2000\n2\n1000 10\n2000 15\n","output":"50\n","actual_output":"50\n","execution_success":true,"sample_index":594},{"source":"apps","task_type":"verifiable_code","in_source_id":"993","prompt":"Solve the following coding problem using the programming language python:\n\nSupermarket Dilemma\nChef is going to local supermarket but there appears a problem with chef as he is confused about which Supermarket he can choose to go as he is not able to decide whether he can park his car in that particular supermarket\u2019s parking lot or not! There are N parking slots in each supermarket which are marked from 1,2,3,4\u2026N.\nChef will go to that supermarket in which he gets to know that there is exactly 1 empty parking slot having number K that exactly divides the total number of slots (N) available in that supermarket.\nThe 1st and Nth parking slots are always occupied by the staff of every supermarket. Rest parking slots are empty as Chef is arriving early morning to the supermarket.\nNow Chef needs your help in determining whether he can park his car in a supermarket or not!\nInput\nThe first line contains the single integer N showing how many supermarkets are there for the chef to choose.\nThe next N lines contain a number \u2018ai\u2019 which represents the total parking slots available in ith supermarket.\nOutput\nYou need to output \"YES\" (without the quotes), if a supermarket can be reached by Chef, and \"NO\" (without the quotes), if it can't.\nConstraints\n1<=N<=10^5\n1<=ai<=10^12\nSample Input :\n2\n4\n5\nSample Output :\nYES\nNO\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nimport math\r\n\r\ndef check(s):\r\n if s==2:\r\n return 1\r\n \r\n for i in range(2,math.ceil(math.sqrt(s))+1):\r\n if s%i == 0:\r\n return 0\r\n \r\n return 1\r\n \r\n\r\ndef Solve(slots):\r\n if slots<3:\r\n return 0\r\n \r\n #check\r\n s = math.sqrt(slots)\r\n if math.floor(s) == math.ceil(s):\r\n return check(s)\r\n \r\n return 0\r\n\r\n\r\nN = int(input())\r\n\r\nfor t in range(N):\r\n \r\n slots = int(input())\r\n \r\n if (Solve(slots)):\r\n print(\"YES\")\r\n \r\n else:\r\n print(\"NO\")\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n4\\n5\\n', 'output': 'YES\\nNO\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/NITJ2021/problems/CIN002'}","problem_id":"vfc_2814","program":"```python\nimport math\r\n\r\ndef check(s):\r\n if s==2:\r\n return 1\r\n \r\n for i in range(2,math.ceil(math.sqrt(s))+1):\r\n if s%i == 0:\r\n return 0\r\n \r\n return 1\r\n \r\n\r\ndef Solve(slots):\r\n if slots<3:\r\n return 0\r\n \r\n #check\r\n s = math.sqrt(slots)\r\n if math.floor(s) == math.ceil(s):\r\n return check(s)\r\n \r\n return 0\r\n\r\n\r\nN = int(input())\r\n\r\nfor t in range(N):\r\n \r\n slots = int(input())\r\n \r\n if (Solve(slots)):\r\n print(\"YES\")\r\n \r\n else:\r\n print(\"NO\")\n```","inputs":"2\n4\n5\n","output":"YES\nNO\n","actual_output":"YES\nNO\n","execution_success":true,"sample_index":595},{"source":"apps","task_type":"verifiable_code","in_source_id":"994","prompt":"Solve the following coding problem using the programming language python:\n\nYou are given an integer sequence $A_1, A_2, \\ldots, A_N$ and an integer $X$. Consider a $N \\times N$ matrix $B$, where $B_{i,j} = A_i + A_j$ for each valid $i$ and $j$.\nYou need to find the number of square submatrices of $B$ such that the sum of their elements is $X$. Formally, find the number of quartets $(x_1, y_1, x_2, y_2)$ such that $1 \\le x_1 \\le x_2 \\le N$, $1 \\le y_1 \\le y_2 \\le N$, $x_2-x_1 = y_2-y_1$ and $\\sum_{i=x_1}^{x_2}\\sum_{j=y_1}^{y_2} B_{i,j} = X$.\n\n-----Input-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The first line of each test case contains two space-separated integers $N$ and $X$.\n- The second line contains $N$ space-separated integers $A_1, A_2, \\ldots, A_N$.\n\n-----Output-----\nFor each test case, print a single line containing one integer \u2015 the number of square submatrices with sum $X$.\n\n-----Constraints-----\n- $1 \\le T \\le 100$\n- $1 \\le X \\le 10^6$\n- $1 \\le N \\le 10^5$\n- $1 \\le A_i \\le 10^6$ for each valid $i$\n- the sum of $N$ over all test cases does not exceed $10^6$\n\n-----Subtasks-----\nSubtask #1 (50 points): the sum of $N$ over all test cases does not exceed $1,000$\nSubtask #2 (50 points): original constraints\n\n-----Example Input-----\n2\n5 36\n1 2 3 1 12\n4 54\n3 3 3 3\n\n-----Example Output-----\n6\n4\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\nimport sys\ninput=sys.stdin.readline\nfor _ in range(int(input())):\n n,x=list(map(int,input().split()))\n l=[0]\n pre=[0]*(n+1)\n sum=0\n i=1\n for m in input().split():\n l.append(int(m))\n sum+=int(m)\n pre[i]=sum\n i+=1\n dict={}\n k=[]\n i=1\n while (i*i)<=x:\n if x%i==0:\n k.append(i)\n if (i*i)!=x:\n k.append(x//i)\n else:\n break\n i+=1 \n ans=0 \n for a in k:\n if a>n:\n continue\n z=x//a \n for j in range(a,n+1):\n s=pre[j]-pre[j-a]\n if s>z:\n continue\n if s in dict:\n dict[s]+=1\n else:\n dict[s]=1\n for j in range(a,n+1):\n s=pre[j]-pre[j-a]\n if s>z:\n continue\n if (z-s) in dict:\n ans+=dict[z-s]\n for j in range(a,n+1):\n s=pre[j]-pre[j-a]\n if s>z:\n continue\n dict[s]=0\n \n print(ans) \n \n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n5 36\\n1 2 3 1 12\\n4 54\\n3 3 3 3\\n', 'output': '6\\n4\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/SQRSUBMA'}","problem_id":"vfc_2818","program":"```python\n# cook your dish here\nimport sys\ninput=sys.stdin.readline\nfor _ in range(int(input())):\n n,x=list(map(int,input().split()))\n l=[0]\n pre=[0]*(n+1)\n sum=0\n i=1\n for m in input().split():\n l.append(int(m))\n sum+=int(m)\n pre[i]=sum\n i+=1\n dict={}\n k=[]\n i=1\n while (i*i)<=x:\n if x%i==0:\n k.append(i)\n if (i*i)!=x:\n k.append(x//i)\n else:\n break\n i+=1 \n ans=0 \n for a in k:\n if a>n:\n continue\n z=x//a \n for j in range(a,n+1):\n s=pre[j]-pre[j-a]\n if s>z:\n continue\n if s in dict:\n dict[s]+=1\n else:\n dict[s]=1\n for j in range(a,n+1):\n s=pre[j]-pre[j-a]\n if s>z:\n continue\n if (z-s) in dict:\n ans+=dict[z-s]\n for j in range(a,n+1):\n s=pre[j]-pre[j-a]\n if s>z:\n continue\n dict[s]=0\n \n print(ans) \n \n\n```","inputs":"2\n5 36\n1 2 3 1 12\n4 54\n3 3 3 3\n","output":"6\n4\n","actual_output":"6\n4\n","execution_success":true,"sample_index":596},{"source":"apps","task_type":"verifiable_code","in_source_id":"995","prompt":"Solve the following coding problem using the programming language python:\n\nMr. Krabs loves money. He enters a bank and sees that there are n rooms arranged in a row. The only rooms with doors are the two rooms on either corner. Initially, all the rooms are locked (including the corner ones). To enter a room, it must be unlocked with a key.\nMr. Krabs is able to steal k keys from the sleeping night guard. Each key can be used to unlock only one room. To reach one of the inner rooms, he has to unlock an adjacent room first.\nEg: If there are 5 rooms labelled: 1 2 3 4 5\nOnly Rooms 1 and 5 can be accessed initially. To unlock room 2, either room 1 or room 3 must be unlocked. Similarly to unlock Room 4, he must unlock room 5 or room 3 first.\nEach room has some money in it. The money present in room i is given by A[i]. Using the k keys, calculate what is the maximum possible amount of money obtainable.\n\n-----Input:-----\n- First line will contain n, number of rooms.\n- Second line will contain space separated integers, denoting A[i], money present in each room.\n- Third line will contain an integer, k, the number of keys available.\n\n-----Output:-----\nMaximum money obtained.\n\n-----Constraints-----\n- 1 <= Number of Rooms <= 10^5\n- 1 <= A[i] <= 10^4\n- 1 <= k <= Number of Rooms\n\n-----Subtasks-----\n- 40 points : 1 <= Number of Rooms <= 100\n- 60 points : Number of Rooms > 100\n\n-----Sample Input:-----\n7\n1 2 3 4 5 6 1\n3\n\n-----Sample Output:-----\n12\n\n-----Explanation:-----\nFor the first step, Mr. Krabs can only unlock the room at the left corner or the right corner. If he unlocks the room in the right corner, he obtains 1 dollar. He can then go on to unlock the second last room and gain 6 dollars, for a total of 7 dollars. Finally he can unlock the third last room and get 5 dollars, for a total of 12 dollars. \nThis is the maximum amount of money he can get with only 3 keys.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nrooms=int(input())\r\nmoney=list(map(int,input().split()))\r\nkeys=int(input())\r\nrev=-1\r\na,b=0,-1\r\ntot=[]\r\n#print(money[-3:-1])\r\nx=0\r\nfor i in range(keys):\r\n #print(money[b:-1],money[0:a])\r\n x=sum(money[b:])+sum(money[0:keys-abs(b)])\r\n tot.append(x)\r\n b-=1\r\nprint(max(tot))\r\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '7\\n1 2 3 4 5 6 1\\n3\\n', 'output': '12\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/COFJ2020/problems/JUN2'}","problem_id":"vfc_2822","program":"```python\nrooms=int(input())\r\nmoney=list(map(int,input().split()))\r\nkeys=int(input())\r\nrev=-1\r\na,b=0,-1\r\ntot=[]\r\n#print(money[-3:-1])\r\nx=0\r\nfor i in range(keys):\r\n #print(money[b:-1],money[0:a])\r\n x=sum(money[b:])+sum(money[0:keys-abs(b)])\r\n tot.append(x)\r\n b-=1\r\nprint(max(tot))\r\n\n```","inputs":"7\n1 2 3 4 5 6 1\n3\n","output":"12\n","actual_output":"12\n","execution_success":true,"sample_index":597},{"source":"apps","task_type":"verifiable_code","in_source_id":"996","prompt":"Solve the following coding problem using the programming language python:\n\nThe game of billiards involves two players knocking 3 balls around\non a green baize table. Well, there is more to it, but for our\npurposes this is sufficient.\nThe game consists of several rounds and in each round both players\nobtain a score, based on how well they played. Once all the rounds\nhave been played, the total score of each player is determined by\nadding up the scores in all the rounds and the player with the higher\ntotal score is declared the winner.\nThe Siruseri Sports Club organises an annual billiards game where\nthe top two players of Siruseri play against each other. The Manager\nof Siruseri Sports Club decided to add his own twist to the game by\nchanging the rules for determining the winner. In his version, at the\nend of each round, the cumulative score for each player is calculated, and the leader and her current lead are found. Once\nall the rounds are over the player who had the maximum lead at the\nend of any round in the game is declared the winner.\n\nConsider the following score sheet for a game with 5 rounds:\nRoundPlayer 1Player 2114082289134390110411210658890\n\nThe total scores of both players, the leader and the lead after\neach round for this game is given below:RoundPlayer 1Player 2LeaderLead114082Player 1582229216Player 1133319326Player 274431432Player 215519522Player 23\nNote that the above table contains the cumulative scores.\nThe winner of this game is Player 1 as he had the maximum lead (58\nat the end of round 1) during the game.\nYour task is to help the Manager find the winner and the winning\nlead. You may assume that the scores will be such that there will\nalways be a single winner. That is, there are no ties.\nInput\nThe first line of the input will contain a single integer N (N\n\u2264 10000) indicating the number of rounds in the game. Lines\n2,3,...,N+1 describe the scores of the two players in the N rounds.\nLine i+1 contains two integer Si and Ti, the scores of the Player 1\nand 2 respectively, in round i. You may assume that 1 \u2264 Si \u2264\n1000 and 1 \u2264 Ti \u2264 1000. \nOutput\nYour output must consist of a single line containing two integers\nW and L, where W is 1 or 2 and indicates the winner and L is the\nmaximum lead attained by the winner.\nExample\nInput:\n5\n140 82\n89 134\n90 110\n112 106\n88 90\n\nOutput:\n1 58\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\ns1=s2=lead=0\nmlead1=mlead2=0\nfor _ in range(int(input())):\n x, y= list(map(int, input().split()))\n s1, s2= s1+x, s2+y\n if(s1>s2):\n lead=(s1-s2)\n mlead1= max(mlead1, lead)\n else:\n lead=(s2-s1)\n mlead2= max(mlead2, lead)\nif(mlead1<(mlead2)):\n print('2', mlead2)\nelse:\n print('1', mlead1)\n\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '5\\n140 82\\n89 134\\n90 110\\n112 106\\n88 90\\n', 'output': '1 58\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/TLG'}","problem_id":"vfc_2826","program":"```python\ns1=s2=lead=0\nmlead1=mlead2=0\nfor _ in range(int(input())):\n x, y= list(map(int, input().split()))\n s1, s2= s1+x, s2+y\n if(s1>s2):\n lead=(s1-s2)\n mlead1= max(mlead1, lead)\n else:\n lead=(s2-s1)\n mlead2= max(mlead2, lead)\nif(mlead1<(mlead2)):\n print('2', mlead2)\nelse:\n print('1', mlead1)\n\n\n```","inputs":"5\n140 82\n89 134\n90 110\n112 106\n88 90\n","output":"1 58\n","actual_output":"1 58\n","execution_success":true,"sample_index":598},{"source":"apps","task_type":"verifiable_code","in_source_id":"997","prompt":"Solve the following coding problem using the programming language python:\n\nDr. S. De teaches computer architecture in NIT Patna. Whenever he comes across any good question(with complexity $k$), he gives that question to students within roll number range $i$ and $j$\nAt the start of semester he assigns score of $10$ to every student in his class if a student submits a question of complexity $k$, his score gets multiplied by $k$\nThis month he gave $M$ questions and he is wondering what will be mean of maximum scores of all the student. He is busy in improving his finger print attendance module, can you help him?\nInput file may be large so try to use fast input output\n\n-----Input:-----\n- First line will contain $T$, number of testcases. Then the testcases follow. \n- Each testcase contains of a First line of input, two integers $N, M$ i.e. Number of students in the class and number of questions given in this month. \n- Next $M$ lines contains 3 integers -$i, j, k$ i.e. starting roll number, end roll number and complexity of the question\n\n-----Output:-----\nFor each testcase, output in a single line answer - $floor$ value of Mean of maximum possible score for all students.\n\n-----Constraints-----\n- $1 \\leq T \\leq 100$\n- $1 \\leq N, M \\leq 10^5$\n- $1 \\leq i \\leq j \\leq N$\n- $1 \\leq k \\leq 100$\n\n-----Subtasks-----\nSubtask1 \n- \n$1 \\leq T \\leq 10$\n- \n$1 \\leq N, M \\leq 10^4$\nSubtask2\n- \nOriginal Constraints \n\n-----Sample Input:-----\n1\n5 3\n1 3 5\n2 5 2\n3 4 7\n\n-----Sample Output:-----\n202\n\n-----EXPLANATION:-----\nInitial score of students will be : $[10, 10, 10, 10, 10]$\nafter solving question 1 scores will be: $[50, 50, 50, 10, 10]$\nafter solving question 2 scores will be: $[50, 100, 100, 20, 20]$\nafter solving question 1 scores will be: $[50, 100, 700, 140, 20]$\nHence after all questions mean of maximum scores will $(50+100+700+140+20)/5 = 202$\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\ntry:\n t=int(input())\n for a in range(t):\n l=input().split()\n n=int(l[0])\n m=int(l[1])\n d={}\n s=0\n for b in range(m):\n l1=input().split()\n i=int(l1[0])\n j=int(l1[1])\n k=int(l1[2])\n for c in range(i,j+1):\n if c not in d:\n d[c]=10\n for c in range(i,j+1):\n d[c]=d[c]*k\n for i in d:\n s=s+d[i]\n print(s//n)\nexcept:\n pass\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n5 3\\n1 3 5\\n2 5 2\\n3 4 7\\n', 'output': '202\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/STRT2020/problems/PROFDE'}","problem_id":"vfc_2830","program":"```python\ntry:\n t=int(input())\n for a in range(t):\n l=input().split()\n n=int(l[0])\n m=int(l[1])\n d={}\n s=0\n for b in range(m):\n l1=input().split()\n i=int(l1[0])\n j=int(l1[1])\n k=int(l1[2])\n for c in range(i,j+1):\n if c not in d:\n d[c]=10\n for c in range(i,j+1):\n d[c]=d[c]*k\n for i in d:\n s=s+d[i]\n print(s//n)\nexcept:\n pass\n```","inputs":"1\n5 3\n1 3 5\n2 5 2\n3 4 7\n","output":"202\n","actual_output":"202\n","execution_success":true,"sample_index":599},{"source":"apps","task_type":"verifiable_code","in_source_id":"998","prompt":"Solve the following coding problem using the programming language python:\n\nYou are given an N \u00d7 N grid initially filled by zeros. Let the rows and columns of the grid be numbered from 1 to N, inclusive. There are two types of operations can be applied to the grid:\n\n- RowAdd R X: all numbers in the row R should be increased by X.\n- ColAdd C X: all numbers in the column C should be increased by X.\n\nNow after performing the sequence of such operations you need to find the maximum element in the grid.\n\n-----Input-----\nThe first line of the input contains two space separated integers N and Q denoting the size of the grid and the number of performed operations respectively. Each of the following Q lines describe an operation in the format described above.\n\n-----Output-----\nOutput a single line containing the maximum number at the grid after performing all the operations.\n\n-----Constraints-----\n- 1 \u2264 N \u2264 314159\n- 1 \u2264 Q \u2264 314159\n- 1 \u2264 X \u2264 3141\n- 1 \u2264 R, C \u2264 N\n\n-----Example-----\nInput:\n2 4\nRowAdd 1 3\nColAdd 2 1\nColAdd 1 4\nRowAdd 2 1\n\nOutput:\n7\n\n-----Explanation-----\nThe grid changes as follows:\n00 33 34 74 74\n00 00 01 41 52\n\nThe maximum number in the final grid is 7.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nn,q=map(int,input().split())\ndr={}\ndc={}\nfor i in range(1,n+1):\n dr[i]=0\n dc[i]=0\nmer=0\nmec=0\nfor i in range(q):\n s,j,k=input().split()\n j=int(j)\n k=int(k)\n if s==\"RowAdd\":\n dr[j]+=k\n if dr[j]>mer:\n mer=dr[j]\n else:\n dc[j]+=k\n if mecm:\n# m=ar[i][j]\n\nprint(mer+mec)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2 4\\nRowAdd 1 3\\nColAdd 2 1\\nColAdd 1 4\\nRowAdd 2 1\\n', 'output': '7\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/ROWCOLOP'}","problem_id":"vfc_2834","program":"```python\nn,q=map(int,input().split())\ndr={}\ndc={}\nfor i in range(1,n+1):\n dr[i]=0\n dc[i]=0\nmer=0\nmec=0\nfor i in range(q):\n s,j,k=input().split()\n j=int(j)\n k=int(k)\n if s==\"RowAdd\":\n dr[j]+=k\n if dr[j]>mer:\n mer=dr[j]\n else:\n dc[j]+=k\n if mecm:\n# m=ar[i][j]\n\nprint(mer+mec)\n```","inputs":"2 4\nRowAdd 1 3\nColAdd 2 1\nColAdd 1 4\nRowAdd 2 1\n","output":"7\n","actual_output":"7\n","execution_success":true,"sample_index":600},{"source":"apps","task_type":"verifiable_code","in_source_id":"1000","prompt":"Solve the following coding problem using the programming language python:\n\nThe activity of a panipuri seller is \"making a panipuri and putting it on the palte of his customer\". \n$N$ customers are eating panipuri, Given an array $A$ of length $N$, $i^{th}$ customer takes $A_i$ seconds to eat a panipuri. \nThe Speed of Panipuri seller refers to the number of customers served per second. Determine the minimum speed of panipuri seller so that no customer has to wait for panipuri after getting his/her first panipuri. \nAssume that the plate can hold infinite panipuris, and customer starts eating next panipuri just after finishing the current one. You would be provided with the time taken by each customer to eat a panipuri.\nPanpuri seller serves panipuri in round robin manner (first to last and then again first).\n\n-----Input:-----\n- First line will contain $T$, number of testcases. Then the test cases follow.\n- For each test case, the first line contains $N$ number of customers.\n- Then the second line will contain $N$ space separated integers, $A_1$ to $A_N$, eating time taken by each customer(in seconds).\n\n-----Output:-----\n- For each test case, print a single line containing the minimum integral speed of panipuri seller so that no customer has to wait. \n\n-----Constraints-----\n- $0 < T \\leq 100$\n- $0 < N \\leq 10^6$\n- $0 < A_i \\leq 10^9$\n- Sum of $N$ over all test cases does not exceed $10^6$\n\n-----Sample Input:-----\n2\n4\n2 4 6 3\n5\n2 3 4 6 5\n\n-----Sample Output:-----\n2\n\n3\n\n-----EXPLANATION:-----\n$Test case$ $1$:\n\nLet's assume speed of panipuri seller be 1.\n\nSo starting from $0^{th}$ second, in $0$ to $1$ second seller make a panipuri and put it into the plate of first customer, and first customer completely eat it in $1$ to $3$ second as he takes $2$ second to eat a panipuri. But in $3$ to $4$ second panipuri seller is serving to $4^{th}$ customer, and hence first customer have to wait, so 1 cannot be our answer.\n\nNext possible speed can be $2$ .\n\nStarting from $0^{th}$ second, at half second seller make a panipuri and put it into the plate of first customer, first customer completely eat it on $2.5$ second as he takes $2$ second to eat a panipuri. In $0.5$ to $1$ second, seller serve the second customer. similarly in $1$ to $2$ second $3^{rd}$ and $4^{th}$ customer will be serve, in $2$ to $2.5$ second, seller will again serve the first customer so at $2.5$ sec $1^{st}$ customer will have a panipuri to eat.\n\nSimilarly proceeding further we will find that no customer have to wait when speed is $2$.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\nfrom math import ceil\nfor _ in range(int(input())):\n n=int(input())\n a=list(map(int,input().split()))\n ans=ceil(n/min(a))\n print(int(ans))\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n4\\n2 4 6 3\\n5\\n2 3 4 6 5\\n', 'output': '2\\n3\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/ECPG2020/problems/ECPC10B'}","problem_id":"vfc_2842","program":"```python\n# cook your dish here\nfrom math import ceil\nfor _ in range(int(input())):\n n=int(input())\n a=list(map(int,input().split()))\n ans=ceil(n/min(a))\n print(int(ans))\n```","inputs":"2\n4\n2 4 6 3\n5\n2 3 4 6 5\n","output":"2\n3\n","actual_output":"2\n3\n","execution_success":true,"sample_index":602},{"source":"apps","task_type":"verifiable_code","in_source_id":"1001","prompt":"Solve the following coding problem using the programming language python:\n\nChef wants to buy a new phone, but he is not willing to spend a lot of money. Instead, he checks the price of his chosen model everyday and waits for the price to drop to an acceptable value. So far, he has observed the price for $N$ days (numbere $1$ through $N$); for each valid $i$, the price on the $i$-th day was $P_i$ dollars.\nOn each day, Chef considers the price of the phone to be good if it is strictly smaller than all the prices he has observed during the previous five days. If there is no record of the price on some of the previous five days (because Chef has not started checking the price on that day yet), then Chef simply ignores that previous day \u2015 we could say that he considers the price on that day to be infinite.\nNow, Chef is wondering \u2015 on how many days has he considered the price to be good? Find the number of these days.\n\n-----Input-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The first line of each test case contains a single integer $N$.\n- The second line contains $N$ space-separated integers $P_1, P_2, \\dots, P_N$.\n\n-----Output-----\nFor each test case, print a single line containing one integer \u2015 the number of days with a good price.\n\n-----Constraints-----\n- $1 \\le T \\le 100$\n- $7 \\le N \\le 100$\n- $350 \\le P_i \\le 750$ for each valid $i$\n\n-----Subtasks-----\nSubtask #1 (30 points): $N = 7$\nSubtask #2 (70 points): original constraints\n\n-----Example Input-----\n1\n7\n375 750 723 662 647 656 619\n\n-----Example Output-----\n2\n\n-----Explanation-----\nExample case 1: Chef considers the price to be good on day $1$, because he has not observed any prices on the previous days. The prices on days $2, 3, 4, 5, 6$ are not considered good because they are greater than the price on day $1$. Finally, the price on day $7$ is considered good because it is smaller than all of the prices on days $2, 3, 4, 5, 6$.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfor _ in range(int(input())):\n n=int(input())\n a=list(map(int,input().split()))\n g=1\n for j in range(1,n):\n if j-5<0:\n mi=min(a[0:j])\n #print(a[0:j])\n if mi>a[j]:\n g=g+1\n else:\n mi=min(a[j-5:j])\n #print(a[j-5:j])\n if mi>a[j]:\n g=g+1\n print(g)\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n7\\n375 750 723 662 647 656 619\\n', 'output': '2\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/S10E'}","problem_id":"vfc_2846","program":"```python\nfor _ in range(int(input())):\n n=int(input())\n a=list(map(int,input().split()))\n g=1\n for j in range(1,n):\n if j-5<0:\n mi=min(a[0:j])\n #print(a[0:j])\n if mi>a[j]:\n g=g+1\n else:\n mi=min(a[j-5:j])\n #print(a[j-5:j])\n if mi>a[j]:\n g=g+1\n print(g)\n\n```","inputs":"1\n7\n375 750 723 662 647 656 619\n","output":"2\n","actual_output":"2\n","execution_success":true,"sample_index":603},{"source":"apps","task_type":"verifiable_code","in_source_id":"1002","prompt":"Solve the following coding problem using the programming language python:\n\nChef works in a similar way to a travelling salesman \u2015 he always travels to new cities in order to sell his delicious dishes.\nToday, Chef is planning to visit $N$ cities (numbered $1$ through $N$). There is a direct way to travel between each pair of cities. Each city has a specific temperature; let's denote the temperature in the $i$-th city by $C_i$. Chef has a fixed temperature tolerance $D$ with the following meaning: for each pair of cities $a$ and $b$, he may travel from city $a$ directly to city $b$ only if $|C_a-C_b| \\le D$, otherwise he would catch a heavy flu because of the sudden change in temperature.\nChef starts from city $1$. Is he able to visit all $N$ cities in such a way that each city is visited exactly once?\nNotes:\n- Chef is not able to travel through a city without visiting it.\n- City $1$ is visited at the beginning.\n- It is not necessary to be able to travel directly to city $1$ from the last city Chef visits.\n\n-----Input-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The first line of each test case contains two space-separated integers $N$ and $D$.\n- The second line contains $N$ space-separated integers $C_1, C_2, \\ldots, C_N$.\n\n-----Output-----\nFor each test case, print a single line containing the string \"YES\" (without quotes) if Chef can visit all cities or \"NO\" (without quotes) if he cannot.\n\n-----Constraints-----\n- $1 \\le T \\le 1,000$\n- $2 \\le N \\le 10^5$\n- $0 \\le D \\le 10^9$\n- $0 \\le C_i \\le 10^9$ for each valid $i$\n- the sum of $N$ over all test cases does not exceed $10^6$\n\n-----Subtasks-----\nSubtask #1 (20 points):\n- $N \\le 1,000$\n- the sum of $N$ over all test cases does not exceed $10,000$\nSubtask #2 (80 points): original constraints\n\n-----Example Input-----\n2\n5 3\n3 2 1 4 5\n5 4\n10 1 3 2 9\n\n-----Example Output-----\nYES\nNO\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\ndef solution(b,n1,d):\n first=b[0]\n b.sort()\n for j in range(n1-1):\n if(a[j+1]-a[j]>d):\n return \"NO\"\n for j in range(n1):\n if(b[j]==first):\n pos=j\n if(pos==0 or pos==n1-1):\n return \"YES\"\n rec=1\n for j in range(pos-1,n1-2):\n if(a[j+2]-a[j]>d):\n rec=0\n break\n if(rec):\n return \"YES\"\n rec=1\n for j in range(pos+1,1,-1):\n if(a[j]-a[j-2]>d):\n rec=0\n break\n if(rec):\n return \"YES\"\n else:\n return \"NO\"\n \ntestcase=int(input())\nfor i in range(testcase):\n n,d=list(map(int,input().split()))\n a=list(map(int,input().split()))\n print(solution(a,n,d))\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n5 3\\n3 2 1 4 5\\n5 4\\n10 1 3 2 9\\n', 'output': 'YES\\nNO\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/TRVLCHEF'}","problem_id":"vfc_2850","program":"```python\n# cook your dish here\ndef solution(b,n1,d):\n first=b[0]\n b.sort()\n for j in range(n1-1):\n if(a[j+1]-a[j]>d):\n return \"NO\"\n for j in range(n1):\n if(b[j]==first):\n pos=j\n if(pos==0 or pos==n1-1):\n return \"YES\"\n rec=1\n for j in range(pos-1,n1-2):\n if(a[j+2]-a[j]>d):\n rec=0\n break\n if(rec):\n return \"YES\"\n rec=1\n for j in range(pos+1,1,-1):\n if(a[j]-a[j-2]>d):\n rec=0\n break\n if(rec):\n return \"YES\"\n else:\n return \"NO\"\n \ntestcase=int(input())\nfor i in range(testcase):\n n,d=list(map(int,input().split()))\n a=list(map(int,input().split()))\n print(solution(a,n,d))\n\n```","inputs":"2\n5 3\n3 2 1 4 5\n5 4\n10 1 3 2 9\n","output":"YES\nNO\n","actual_output":"YES\nNO\n","execution_success":true,"sample_index":604},{"source":"apps","task_type":"verifiable_code","in_source_id":"1003","prompt":"Solve the following coding problem using the programming language python:\n\nIn the world of DragonBool there are fierce warriors called Soints. Also there are even fiercer warriors called Sofloats \u2013 the mortal enemies of Soints.\n\nThe power of each warrior is determined by the amount of chakra he possesses which is some positive integer. Warriors with zero level of chakra are dead warriors :) When the fight between Soint with power CI and Sofloat with power CF occurs the warrior with lower power will die and the winner will lose the amount of chakra that his enemy have possessed before the fight. So three cases are possible:\n\n- CI > CF. Then Sofloat will die while the new power of Soint will be CI \u2013 CF.\n- CI < CF. Then Soint will die while the new power of Sofloat will be CF \u2013 CI.\n- CI = CF. In this special case both warriors die.\n\nEach warrior (Soint or Sofloat) has his level of skills which is denoted by some positive integer. The fight between two warriors can occur only when these warriors are Soint and Sofloat of the same level. In particual, friendly fights are not allowed, i.e., a Soint cannot fight with another Soint and the same holds for Sofloats.\n\nLets follow the following convention to denote the warriors. A Soint of level L and power C will be denoted as (I, C, L), while Sofloat of level L and power C will be denoted as (F, C, L). Consider some examples. If A = (I, 50, 1) fights with B = (F, 20, 1), B dies and A becomes (I, 30, 1). On the other hand, (I, 50, 1) cannot fight with (F, 20, 2) as they have different levels.\n\nThere is a battle between Soints and Sofloats. There are N Soints and M Sofloats in all. The battle will consist of series of fights. As was mentioned above in each fight one Soint and one Sofloat of the same level take part and after the fight the warrior with lower power will die (or both will die if they have the same power). The battle proceeds as long as there exists at least one pair of warriors who can fight. The distribution of warriors by levels satisfies the following condition: for every Soint of level L there exists at least one Sofloat of the same level L and vice-versa. So if for some level L we have at least one warrior of this level then there is at least one Soint of level L and at least one Sofloat of level L.\n\nThere is a powerful wizard, whose name is SoChef, on the side of Soints. He can increase the amount of chakra of each Soint by any number. SoChef wants the army of Soints to win this battle. But increasing amount of chakra of any Soint by one costs him a lot of his magic power. Hence he wants to minimize the total amount of additional chakra he should give to Soints in order for them to win. Note, however, that the win here means that all Sofloats should be dead irregardless of whether any Soint is alive. Also note that the battle can proceed by different scenarios and the SoChef need to distribute additional chakra among the Soints in such a way that they will win for any possible battle scenario. Help SoChef and find the minimal amount of additional chakra he should give to Soints in order for them to win.\n\n-----Input-----\n\nThe first line of the input contains an integer T, the number of test cases. T test cases follow. The first line of each test case contains two space separated integers N and M. Here N is the number of Soints participating in the battle and M is the number of Sofloats for the same. Each of the next N lines contains two space separated integers Ci and Li, the amount of chakra and level of i-th Soint correspondingly. The next M lines describe power and level of Sofloats participating in the battle in the same format.\n\n-----Output-----\n\nFor each test case output a single integer on a single line, the minimum amount of chakra SoChef should give to Soints in order for them to win the battle.\n\n-----Constraints-----\nEach integer in the input file is positive and does not exceed 100. That is1 \u2264 T \u2264 100\n1 \u2264 N \u2264 100\n1 \u2264 M \u2264 100\n1 \u2264 Ci \u2264 100\n1 \u2264 Li \u2264 100\n\nFor every Soint of level L there exists at least one Sofloat of the same level L and vice-versa.\nIt is guaranteed that each official test file will satisfy all these constraints. You DON'T need to verify them in your program.\n\n-----Example-----\nInput:\n2\n2 3\n10 1\n20 2\n5 2\n5 2\n18 1\n5 5\n73 87\n69 13\n36 36\n77 46\n43 93\n49 46\n74 93\n78 87\n99 13\n59 36\n\nOutput:\n8\n89\n\n-----Explanation-----\nCase 1.\nThe warriors are I1 = (I, 10, 1), I2 = (I, 20, 2), F1 = (F, 5, 2), F2 = (F, 5, 2), F3 = (F, 18, 1). Without the SoChef help the battle can proceed as follows.\n\n- I2 fights with F1, F1 dies, I2 becomes (I, 15, 2).\n- I2 fights with F2, F2 dies, I2 becomes (I, 10, 2).\n- I1 fights with F3, I1 dies, F3 becomes (F, 8, 1).\n\nSo if SoChef will give 8 additional units of chakra to I1 the Soints will win the battle and even one Soint (I2) will left alive. Hence the answer is 8.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nt=eval(input())\nfor i in range(0,t):\n x=input()\n nm=x.split(' ')\n nm[0]=int(nm[0])\n nm[1]=int(nm[1])\n csoint=[]\n lsoint=[]\n csofloat=[]\n lsofloat=[]\n for j in range(0,nm[0]):\n a=input()\n b=a.split(' ')\n b[0]=int(b[0])\n b[1]=int(b[1])\n csoint.append(b[0])\n lsoint.append(b[1])\n for k in range(0,nm[1]):\n a=input()\n b=a.split(' ')\n b[0]=int(b[0])\n b[1]=int(b[1])\n csofloat.append(b[0])\n lsofloat.append(b[1])\n chakra=0\n\n## for j in range(0,nm[0]):\n## if csofloat==[0]*nm[1]:\n## print chakra\n## break\n## for k in range(0,nm[1]):\n## if csofloat==[0]*nm[1]:\n## print chakra\n## break\n## if lsoint[j]==lsofloat[k]:\n## if csoint[j]>csofloat[k]:\n## csoint[j]-=csofloat[k]\n## csofloat[k]=0\n## lsofloat[k]=0\n## elif csofloat[k]>csoint[j]:\n## if lsoint.count(lsoint[j])==1==lsofloat.count(lsofloat[k]):\n## chakra+=csofloat[k]-csoint[j]\n## csoint[j]=csofloat[k]\n## csoint[j]=0\n## csofloat[k]=0\n## lsoint[j]=0\n## lsofloat[k]=0\n## elif lsoint.count(lsoint[j])==1 and lsofloat.count(lsofloat[k])>lsoint.count(lsoint[j]):\n## csoint[j]=csofloat[k]+1\n## chakra+=csofloat[k]-csoint[j]+1\n## csoint[j]=1\n## csofloat[k]=0\n## lsofloat[k]=0\n## else:\n## csofloat[k]-=csoint[j]\n## csoint[j]=0\n## lsoint[j]=0\n## break\n## else:\n## if lsoint.count(lsoint[j])==1 and lsoint.count(lsoint[j])>=lsofloat.count(lsofloat[k]):\n## csoint[j]=0\n## csofloat[k]=0\n## lsoint[j]=0\n## lsofloat[k]=0\n## break\n## elif lsoint.count(lsoint[j])==1 and lsoint.count(lsoint[j])csofloat[k]:\n## csoint[j]-=csofloat[k]\n## csofloat[k]=0\n## lsofloat[k]=0\n## elif csofloat[k]>csoint[j]:\n## if lsoint.count(lsoint[j])==1==lsofloat.count(lsofloat[k]):\n## chakra+=csofloat[k]-csoint[j]\n## csoint[j]=csofloat[k]\n## csoint[j]=0\n## csofloat[k]=0\n## lsoint[j]=0\n## lsofloat[k]=0\n## elif lsoint.count(lsoint[j])==1 and lsofloat.count(lsofloat[k])>lsoint.count(lsoint[j]):\n## csoint[j]=csofloat[k]+1\n## chakra+=csofloat[k]-csoint[j]+1\n## csoint[j]=1\n## csofloat[k]=0\n## lsofloat[k]=0\n## else:\n## csofloat[k]-=csoint[j]\n## csoint[j]=0\n## lsoint[j]=0\n## break\n## else:\n## if lsoint.count(lsoint[j])==1 and lsoint.count(lsoint[j])>=lsofloat.count(lsofloat[k]):\n## csoint[j]=0\n## csofloat[k]=0\n## lsoint[j]=0\n## lsofloat[k]=0\n## break\n## elif lsoint.count(lsoint[j])==1 and lsoint.count(lsoint[j])int(d):\n k.pop(n-x-1)\n c+=1 \n else:\n d=k[n-x-1]\n print(''.join(k)+c*dd)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\n35 4\\n42 4\\n24 9\\n', 'output': '34\\n24\\n24\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/CHDIGER'}","problem_id":"vfc_2866","program":"```python\nfor _ in range(int(input())):\n n,d=map(str,input().split())\n k=list(n)\n dd,c,n=d,0,len(n)\n for x in range(n):\n if int(k[n-x-1])>int(d):\n k.pop(n-x-1)\n c+=1 \n else:\n d=k[n-x-1]\n print(''.join(k)+c*dd)\n```","inputs":"3\n35 4\n42 4\n24 9\n","output":"34\n24\n24\n","actual_output":"34\n24\n24\n","execution_success":true,"sample_index":608},{"source":"apps","task_type":"verifiable_code","in_source_id":"1007","prompt":"Solve the following coding problem using the programming language python:\n\nGiven an array A1,A2...AN, you have to print the size of the largest contiguous subarray such that \nGCD of all integers in that subarray is 1.\n\nFormally,\nFor a subarray Ai,Ai+1...Aj where 1 \u2264 i < j \u2264 N to be valid: GCD(Ai,Ai+1...Aj) should be 1. You have to print the size of the largest valid subarray.\nIf no valid subarray exists, output -1.\nNote:A single element is not considered as a subarray according to the definition of this problem.\n\n-----Input-----\nFirst line contains T, the number of testcases. Each testcase consists of N in one line followed by N integers in the next line.\n\n-----Output-----\nFor each testcase, print the required answer in one line.\n\n-----Constraints-----\n- 1 \u2264 T \u2264 10\n- 2 \u2264 N \u2264 105\n- 1 \u2264 Ai \u2264 105\n\n-----Example-----\nInput:\n2\n2\n7 2\n3\n2 2 4\n\nOutput:\n2\n-1\n\n-----Explanation-----\nExample case 1.GCD(2,7)=1. So the subarray [A1,A2] is valid.\nExample case 2.No subarray satisfies.\nNote: Use scanf/print instead of cin/cout. Large input files.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nimport math\nfor _ in range(int(input())):\n n=int(input())\n ar=[int(x) for x in input().split()]\n # dp=[1]*n\n f=0\n g=ar[0]\n for i in range(1,n):\n g=math.gcd(g,ar[i])\n if g==1:\n f=1\n print(n)\n break\n if f==0:\n print(-1)\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n2\\n7 2\\n3\\n2 2 4\\n', 'output': '2\\n-1\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/SUBGCD'}","problem_id":"vfc_2870","program":"```python\nimport math\nfor _ in range(int(input())):\n n=int(input())\n ar=[int(x) for x in input().split()]\n # dp=[1]*n\n f=0\n g=ar[0]\n for i in range(1,n):\n g=math.gcd(g,ar[i])\n if g==1:\n f=1\n print(n)\n break\n if f==0:\n print(-1)\n\n```","inputs":"2\n2\n7 2\n3\n2 2 4\n","output":"2\n-1\n","actual_output":"2\n-1\n","execution_success":true,"sample_index":609},{"source":"apps","task_type":"verifiable_code","in_source_id":"1009","prompt":"Solve the following coding problem using the programming language python:\n\nChef is playing a game on a sequence of $N$ positive integers, say $A_1, A_2, ... A_N$ The game is played as follows.\n- If all the numbers are equal, the game ends.\n- Otherwise\n- Select two numbers which are unequal\n- Subtract the smaller number from the larger number\n- Replace the larger number with the result from above\nChef has already figured out that the game always terminates. He also knows, for a given sequence of integers, the game will always terminate on the same value, no matter how the game is played. Chef wants you to simulate the game for him and tell him if the game terminates on $1$.\nIn fact, there may be many such games. Given a sequence of integers Chef wants to know the number of sub-sequences of the given sequence, for which, playing the above game on the subsuquence will terminate on $1$. A sub-sequence can be obtained from the original sequence by deleting $0$ or more integers from the original sequence. See the explanation section for clarity.\n\n-----Input-----\n- The first line of the input contains an integer $T$, the number of test cases. Then follow the description of $T$ test cases. \n- The first line of each test case contains a single integer $N$, the length of the sequence. \n- The second line contains $N$ positive integers, each separated by a single space.\n\n-----Output-----\nFor each test case, output a single integer - the number of sub-sequences of the original sequence, such that, playing the game on the sub-sequence results in ending the game with all the values equal to $1$.\n\n-----Constraints-----\n- $1 \\le T \\le 100$ \n- $1 \\le N \\le 60$ \n- $1 \\le A_i \\le 10^4$ \n- All $A_i$ will be distinct.\n\n-----Sample Input-----\n3\n4\n2 3 5 7\n4\n3 4 8 16\n3\n6 10 15\n\n-----Sample Output-----\n11\n7\n1\n\n-----Explanation-----\nTest Case 1: The following $11$ sub-sequences are counted.\n- $\\{ 2, 3 \\}$\n- $\\{ 2, 5 \\}$\n- $\\{ 2, 7 \\}$\n- $\\{ 3, 5 \\}$\n- $\\{ 3, 7 \\}$\n- $\\{ 5, 7 \\}$\n- $\\{ 2, 3, 5 \\}$\n- $\\{ 2, 3, 7 \\}$\n- $\\{ 2, 5, 7 \\}$\n- $\\{ 3, 5, 7 \\}$\n- $\\{ 2, 3, 5, 7 \\}$\nTest Case 2: The following $7$ sub-sequences are counted.\n- $\\{ 3, 4 \\}$\n- $\\{ 3, 8 \\}$\n- $\\{ 3, 16 \\}$\n- $\\{ 3, 4, 8 \\}$\n- $\\{ 3, 4, 16 \\}$\n- $\\{ 3, 8, 16 \\}$\n- $\\{ 3, 4, 8, 16 \\}$\nTest Case 3: There are $8$ subsequences of $\\{ 6, 10, 15 \\}$\n- $\\{\\}$ => The game cannot be played on this sub-sequence\n- $\\{ 6 \\}$ => The game cannot be played on this sub-sequence\n- $\\{ 10 \\}$ => The game cannot be played on this sub-sequence\n- $\\{ 15 \\}$ => The game cannot be played on this sub-sequence\n- $\\{ 6, 10 \\}$ => The game cannot end at $\\{ 1, 1 \\}$\n- $\\{ 6, 15 \\}$ => The game cannot end at $\\{ 1, 1 \\}$\n- $\\{ 10, 15 \\}$ => The game cannot end at $\\{ 1, 1 \\}$\n- $\\{ 6, 10, 15 \\}$ => The game ends at $\\{ 1, 1, 1 \\}$. Hence this is the only sub-sequence that is counted in the result.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\nfrom sys import stdin\nimport functools\ndef gcd(a, b): \n if (a == 0): \n return b \n return gcd(b % a, a) \n \nMAX=10001\ndef func(ind, g, dp, n, a): \n if (ind == n): \n if (g == 1): \n return 1\n else: \n return 0\n if (dp[ind][g] != -1): \n return dp[ind][g] \n ans = (func(ind + 1, g, dp, n, a) + \n func(ind + 1, gcd(a[ind], g), \n dp, n, a)) \n dp[ind][g] = ans \n return dp[ind][g] \n \ndef countSubsequences(a, n): \n dp = [[-1 for i in range(MAX)] \n for i in range(n)] \n count = 0\n for i in range(n): \n count += func(i + 1, a[i], dp, n, a) \n return count \n\ntest=int(stdin.readline())\nfor _ in range(test):\n n=int(stdin.readline())\n list1=list(map(int,stdin.readline().split()))\n print(countSubsequences(list1,n))\n\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\n4\\n2 3 5 7\\n4\\n3 4 8 16\\n3\\n6 10 15\\n', 'output': '11\\n7\\n1\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/AMSGAME2'}","problem_id":"vfc_2878","program":"```python\n# cook your dish here\nfrom sys import stdin\nimport functools\ndef gcd(a, b): \n if (a == 0): \n return b \n return gcd(b % a, a) \n \nMAX=10001\ndef func(ind, g, dp, n, a): \n if (ind == n): \n if (g == 1): \n return 1\n else: \n return 0\n if (dp[ind][g] != -1): \n return dp[ind][g] \n ans = (func(ind + 1, g, dp, n, a) + \n func(ind + 1, gcd(a[ind], g), \n dp, n, a)) \n dp[ind][g] = ans \n return dp[ind][g] \n \ndef countSubsequences(a, n): \n dp = [[-1 for i in range(MAX)] \n for i in range(n)] \n count = 0\n for i in range(n): \n count += func(i + 1, a[i], dp, n, a) \n return count \n\ntest=int(stdin.readline())\nfor _ in range(test):\n n=int(stdin.readline())\n list1=list(map(int,stdin.readline().split()))\n print(countSubsequences(list1,n))\n\n\n```","inputs":"3\n4\n2 3 5 7\n4\n3 4 8 16\n3\n6 10 15\n","output":"11\n7\n1\n","actual_output":"11\n7\n1\n","execution_success":true,"sample_index":611},{"source":"apps","task_type":"verifiable_code","in_source_id":"1011","prompt":"Solve the following coding problem using the programming language python:\n\nChef is a really nice and respectful person, in sharp contrast to his little brother, who is a very nasty and disrespectful person. Chef always sends messages to his friends in all small letters, whereas the little brother sends messages in all capital letters.\nYou just received a message given by a string s. You don't know whether this message is sent by Chef or his brother. Also, the communication channel through which you received the message is erroneous and hence can flip a letter from uppercase to lowercase or vice versa. However, you know that this channel can make at most K such flips.\nDetermine whether the message could have been sent only by Chef, only by the little brother, by both or by none.\n\n-----Input-----\n\n- The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows.\n- The first line of each test case contains two space-separated integers N and K denoting the length of the string s and the maximum number of flips that the erroneous channel can make.\n- The second line contains a single string s denoting the message you received.\n\n-----Output-----\nFor each test case, output a single line containing one string \u2014 \"chef\", \"brother\", \"both\" or \"none\".\n\n-----Constraints-----\n- 1 \u2264 T \u2264 1000\n- 1 \u2264 N \u2264 100\n- 0 \u2264 K \u2264 N\n- s consists only of (lowercase and uppercase) English letters\n\n-----Example-----\nInput\n\n4\n5 1\nfrauD\n5 1\nFRAUD\n4 4\nLife\n10 4\nsTRAWBerry\n\nOutput\n\nchef\nbrother\nboth\nnone\n\n-----Explanation-----\nExample case 1: Only one flip is possible. So it is possible that Chef sent \"fraud\" and the channel flipped the last character to get \"frauD\". However, it is not possible for the brother to have sent \"FRAUD\", because then it would need 4 flips. Hence the answer is \"chef\".\nExample case 2: Only one flip is possible. So it is possible that the brother sent \"FRAUD\" and the channel didn't flip anything. However, it is not possible for Chef to have sent \"fraud\", because then it would need 5 flips. Hence the answer is \"brother\".\nExample case 3: Four flips are allowed. It is possible that Chef sent \"life\" and the channel flipped the first character to get \"Life\". It is also possible that the brother sent \"LIFE\" and the channel flipped the last three characters to get \"Life\". Hence the answer is \"both\".\nExample case 4: Four flips are allowed. It is not possible that Chef sent \"strawberry\", because it would need five flips to get \"sTRAWBerry\". It is also not possible that the brother sent \"STRAWBERRY\", because that would also need five flips. Hence the answer is \"none\".\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nt=int(input())\ndef do():\n n,k=map(int,input().split())\n s=input()\n upper=0\n lower=0\n for i in s:\n if i.isupper():\n upper+=1\n else:\n lower+=1\n if lower>k and upper<=k:\n print('chef')\n elif(upper>k and lower<=k):\n print('brother')\n elif(upper<=k and lower<=k):\n print('both')\n else:\n print('none')\n return\nfor i in range(t):\n do()\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '4\\n5 1\\nfrauD\\n5 1\\nFRAUD\\n4 4\\nLife\\n10 4\\nsTRAWBerry\\n', 'output': 'chef\\nbrother\\nboth\\nnone\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/GOODBAD'}","problem_id":"vfc_2886","program":"```python\nt=int(input())\ndef do():\n n,k=map(int,input().split())\n s=input()\n upper=0\n lower=0\n for i in s:\n if i.isupper():\n upper+=1\n else:\n lower+=1\n if lower>k and upper<=k:\n print('chef')\n elif(upper>k and lower<=k):\n print('brother')\n elif(upper<=k and lower<=k):\n print('both')\n else:\n print('none')\n return\nfor i in range(t):\n do()\n```","inputs":"4\n5 1\nfrauD\n5 1\nFRAUD\n4 4\nLife\n10 4\nsTRAWBerry\n","output":"chef\nbrother\nboth\nnone\n","actual_output":"chef\nbrother\nboth\nnone\n","execution_success":true,"sample_index":612},{"source":"apps","task_type":"verifiable_code","in_source_id":"1012","prompt":"Solve the following coding problem using the programming language python:\n\nAlice likes prime numbers. According to Alice, only those strings are nice whose sum of character values at a prime position is prime. She has a string $S$. Now, she has to count the number of nice strings which come before string $S$( including $S$) in the dictionary and are of the same length as $S$. \nStrings are zero-indexed from left to right.\nTo find the character value she uses the mapping {'a': 0, 'b':1, 'c':2 \u2026\u2026. 'y': 24, 'z':25} .\nFor example, for string $abcde$ Characters at prime positions are $'c'$ and $'d'$. c + d = 2 + 3 = 5. Since, 5 is a prime number, the string is $nice$.\nSince there could be many nice strings print the answer modulo $10^{9}+7$.\n\n-----Input:-----\n- First line will contain $T$, number of testcases. Then the testcases follow. \n- Each testcase contains of a single line of input, the string $S$. \n\n-----Output:-----\nFor each testcase, output in a single line number of nice strings modulo $10^{9}+7$.\n\n-----Constraints-----\n- $1 \\leq T \\leq 10$\n- $2 \\leq |S| \\leq 10^2$\nString $S$ contains only lowercase letters.\n\n-----Sample Input:-----\n1\nabc\n\n-----Sample Output:-----\n10\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nimport sys\r\nfrom collections import defaultdict\r\nfrom copy import copy\r\n\r\nMOD = 10**9 + 7\r\n\r\nR = lambda t = int: t(input())\r\nRL = lambda t = int: [t(x) for x in input().split()]\r\nRLL = lambda n, t = int: [RL(t) for _ in range(n)]\r\n\r\n# primes up to n\r\ndef primes(n):\r\n P = []\r\n n = int(n)\r\n U = [1] * (n+1)\r\n p = 2\r\n while p <= n:\r\n if U[p]:\r\n P += [p]\r\n x = p\r\n while x <= n:\r\n U[x] = 0\r\n x += p\r\n p += 1\r\n return P\r\n \r\n \r\n \r\ndef solve():\r\n S = R(str).strip()\r\n X = [ord(c)-ord('a') for c in S]\r\n P = primes(10000)\r\n L = defaultdict(lambda : 0)\r\n s = 0\r\n for i in range(len(S)):\r\n p = i in P\r\n NL = defaultdict(lambda : 0)\r\n for a in range(26):\r\n for l in L:\r\n NL[l + a * p] += L[l]\r\n for a in range(X[i]):\r\n NL[s + a * p] += 1\r\n s += X[i] * p\r\n L = NL\r\n L[s] += 1\r\n r = 0 \r\n for p in P:\r\n r += L[p]\r\n print(r % MOD)\r\n \r\nT = R()\r\nfor t in range(1, T + 1):\r\n solve()\r\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\nabc\\n', 'output': '10\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/ENJU2020/problems/ECJN207'}","problem_id":"vfc_2890","program":"```python\nimport sys\r\nfrom collections import defaultdict\r\nfrom copy import copy\r\n\r\nMOD = 10**9 + 7\r\n\r\nR = lambda t = int: t(input())\r\nRL = lambda t = int: [t(x) for x in input().split()]\r\nRLL = lambda n, t = int: [RL(t) for _ in range(n)]\r\n\r\n# primes up to n\r\ndef primes(n):\r\n P = []\r\n n = int(n)\r\n U = [1] * (n+1)\r\n p = 2\r\n while p <= n:\r\n if U[p]:\r\n P += [p]\r\n x = p\r\n while x <= n:\r\n U[x] = 0\r\n x += p\r\n p += 1\r\n return P\r\n \r\n \r\n \r\ndef solve():\r\n S = R(str).strip()\r\n X = [ord(c)-ord('a') for c in S]\r\n P = primes(10000)\r\n L = defaultdict(lambda : 0)\r\n s = 0\r\n for i in range(len(S)):\r\n p = i in P\r\n NL = defaultdict(lambda : 0)\r\n for a in range(26):\r\n for l in L:\r\n NL[l + a * p] += L[l]\r\n for a in range(X[i]):\r\n NL[s + a * p] += 1\r\n s += X[i] * p\r\n L = NL\r\n L[s] += 1\r\n r = 0 \r\n for p in P:\r\n r += L[p]\r\n print(r % MOD)\r\n \r\nT = R()\r\nfor t in range(1, T + 1):\r\n solve()\r\n\n```","inputs":"1\nabc\n","output":"10\n","actual_output":"10\n","execution_success":true,"sample_index":613},{"source":"apps","task_type":"verifiable_code","in_source_id":"1014","prompt":"Solve the following coding problem using the programming language python:\n\nA number K$K$ is said to be magical if it can be represented as a power of 2 only.That is K$K$=2x$2^{x}$ for some natural number x$x$. \nGiven a string of digits S$S$ of length N$N$, Let P be a valid arrangement of S.\nBy valid arrangement we mean that it should not have any leading zeroes.\nFind the sum of all such distinct Pi's, which, when treated as a number is magical.\nTwo arrangements are said to be distinct, if there is atleast one index where they differ. \nAs the sum can be very large, print the sum modulo 109+7$10^{9}+7$.\n\n-----Input:-----\n-The first line of the input contains a single integer T$T$ denoting the number of test cases. \n-Only line of each test case contains a string S$S$ of length N$N$, consisting only of digits between 0 to 9.\n\n-----Output:-----\nFor each test case, print a single integer denoting the sum of all such magical Pi\u2032s$Pi's$ modulo 109+7$10^{9}+7$.\nIf no such Pi$Pi$ exists print \"-1\".\n\n-----Constraints-----\n- 1\u2264T\u22641000$1 \\leq T \\leq 1000$\n- 2\u2264N\u22641000$2 \\leq N \\leq 1000$\n- String only consists of digits between 0 to 9, both inclusive.\n\n-----Subtasks-----\n- 10 points : 1\u2264N\u22645$1 \\leq N \\leq 5$\n- 40 points : 1\u2264N\u2264100$1 \\leq N \\leq 100$\n- 50 points : Original Constraints\n\n-----Sample Input:-----\n2\n35566\n\n31\n\n-----Sample Output:-----\n65536\n\n-1\n\n-----EXPLANATION:-----\nOnly arrangement is 65536.\nNo arrangement of 31 gives us a power of two.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfrom math import log2, ceil\r\nMOD = int(1e9 + 7)\r\nsrt = lambda s: ''.join(sorted(s))\r\nfor _ in range(int(input())):\r\n s = srt(input())\r\n res = -1\r\n for p in range(ceil(log2(int(s))), int(log2(int(s[::-1]))) + 1):\r\n if int(srt(str(pow(2, p)))) == int(s):\r\n if res == -1: res = 0\r\n res = (res + pow(2, p, MOD)) % MOD\r\n print(res)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n35566\\n31\\n', 'output': '65536\\n-1\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/ALQU2018/problems/POWTWO'}","problem_id":"vfc_2898","program":"```python\nfrom math import log2, ceil\r\nMOD = int(1e9 + 7)\r\nsrt = lambda s: ''.join(sorted(s))\r\nfor _ in range(int(input())):\r\n s = srt(input())\r\n res = -1\r\n for p in range(ceil(log2(int(s))), int(log2(int(s[::-1]))) + 1):\r\n if int(srt(str(pow(2, p)))) == int(s):\r\n if res == -1: res = 0\r\n res = (res + pow(2, p, MOD)) % MOD\r\n print(res)\n```","inputs":"2\n35566\n31\n","output":"65536\n-1\n","actual_output":"65536\n-1\n","execution_success":true,"sample_index":614},{"source":"apps","task_type":"verifiable_code","in_source_id":"1015","prompt":"Solve the following coding problem using the programming language python:\n\nThe 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.\n\n-----Input:-----\n- First-line will contain $T$, the number of test cases. Then the test cases follow. \n- Each test case contains a single line of input, one integer $K$. \n\n-----Output:-----\nFor each test case, output as the pattern.\n\n-----Constraints-----\n- $1 \\leq T \\leq 100$\n- $1 \\leq K \\leq 100$\n\n-----Sample Input:-----\n4\n1\n2\n3\n4\n\n-----Sample Output:-----\n2\n24\n68\n246\n81012\n141618\n2468\n10121416\n18202224\n26283032\n\n-----EXPLANATION:-----\nNo need, else pattern can be decode easily.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\ntry:\n for _ in range(int(input())):\n k = int(input())\n num = 1\n for i in range(1,k+1,1):\n for j in range(1,k+1,1):\n print(num*2,end=\"\")\n num = num +1\n print(\"\")\nexcept:\n pass\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '4\\n1\\n2\\n3\\n4\\n', 'output': '2\\n24\\n68\\n246\\n81012\\n141618\\n2468\\n10121416\\n18202224\\n26283032\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/PTRN2021/problems/ITGUY50'}","problem_id":"vfc_2902","program":"```python\n# cook your dish here\ntry:\n for _ in range(int(input())):\n k = int(input())\n num = 1\n for i in range(1,k+1,1):\n for j in range(1,k+1,1):\n print(num*2,end=\"\")\n num = num +1\n print(\"\")\nexcept:\n pass\n```","inputs":"4\n1\n2\n3\n4\n","output":"2\n24\n68\n246\n81012\n141618\n2468\n10121416\n18202224\n26283032\n","actual_output":"2\n24\n68\n246\n81012\n141618\n2468\n10121416\n18202224\n26283032\n","execution_success":true,"sample_index":615},{"source":"apps","task_type":"verifiable_code","in_source_id":"1016","prompt":"Solve the following coding problem using the programming language python:\n\nYou have been recently hired as a developer in CodeChef. Your first mission is to implement a feature that will determine the number of submissions that were judged late in a contest.\nThere are $N$ submissions, numbered $1$ through $N$. For each valid $i$, the $i$-th submission was submitted at time $S_i$ and judged at time $J_i$ (in minutes). Submitting and judging both take zero time. Please determine how many submissions received their verdicts after a delay of more than $5$ minutes.\n\n-----Input-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The first line of the input contains a single integer $N$.\n- $N$ lines follow. For each valid $i$, the $i$-th of these lines contains two space-separated integers $S_i$ and $J_i$.\n\n-----Output-----\nFor each test case, print a single line containing one integer \u2014 the number of submissions for which the judging was delayed by more than 5 minutes.\n\n-----Constraints-----\n- $1 \\le T \\le 100$\n- $1 \\le N \\le 100$\n- $1 \\le S_i \\le J_i \\le 300$ for each valid $i$\n\n-----Subtasks-----\nSubtask #1 (100 points): original constraints\n\n-----Example Input-----\n1\n5\n1 3\n4 4\n4 10\n1 11\n2 7\n\n-----Example Output-----\n2\n\n-----Explanation-----\nExample case 1: The delays of the respective submissions are $2$ minutes, $0$ minutes, $6$ minutes, $10$ minutes and $5$ minutes. Only submissions $3$ and $4$ are delayed by more than $5$ minutes, hence the answer is $2$.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\nfor t in range(int(input())):\n c=0\n for i in range(int(input())):\n s,j=list(map(int,input().split()))\n if (j-s)>5:\n c+=1 \n print(c)\n \n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n5\\n1 3\\n4 4\\n4 10\\n1 11\\n2 7\\n', 'output': '2\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/JDELAY'}","problem_id":"vfc_2906","program":"```python\n# cook your dish here\nfor t in range(int(input())):\n c=0\n for i in range(int(input())):\n s,j=list(map(int,input().split()))\n if (j-s)>5:\n c+=1 \n print(c)\n \n\n```","inputs":"1\n5\n1 3\n4 4\n4 10\n1 11\n2 7\n","output":"2\n","actual_output":"2\n","execution_success":true,"sample_index":616},{"source":"apps","task_type":"verifiable_code","in_source_id":"1017","prompt":"Solve the following coding problem using the programming language python:\n\nChef recently started working at ABC corporation. Let's number weekdays (Monday through Friday) by integers $1$ through $5$. For each valid $i$, the number of hours Chef spent working at the office on weekday $i$ was $A_i$.\nUnfortunately, due to the COVID-19 pandemic, Chef started working from home and his productivity decreased by a considerable amount. As per Chef's analysis, $1$ hour of work done at the office is equivalent to $P$ hours of work done at home.\nNow, in order to complete his work properly, Chef has to spend more hours working from home, possibly at the cost of other things like sleep. However, he does not have to do the same work on each day as he would have in the office \u2015 for each weekday, he can start the work for this day on an earlier day and/or complete it on a later day. The only requirement is that his work does not pile up indefinitely, i.e. he can complete his work for each week during the same week. One day has $24$ hours.\nIf Chef is unable to complete his work for a week during those five weekdays, then he has to work during the weekend too. Chef wishes to know whether he has to work on weekends or if he can complete his work by working only on weekdays. Help him answer that question. (It is possible that Chef would be unable to finish his work even if he worked all the time, but he does not want to know about that.)\n\n-----Input-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The first and only line of each test case contains six space-separated integers $A_1$, $A_2$, $A_3$, $A_4$, $A_5$ and $P$.\n\n-----Output-----\nFor each test case, print a single line containing the string \"Yes\" if Chef has to work on weekends or \"No\" otherwise (without quotes).\n\n-----Constraints-----\n- $1 \\le T \\le 1,000$\n- $0 \\le A_i \\le 24$ for each valid $i$\n- $1 \\le P \\le 24$\n\n-----Subtasks-----\nSubtask #1 (100 points): original constraints\n\n-----Example Input-----\n2\n14 10 12 6 18 2\n10 10 10 10 10 3\n\n-----Example Output-----\nNo\nYes\n\n-----Explanation-----\nExample case 1: Here, $P=2$, so the number of hours Chef has to work from home to handle his workload for days $1$ through $5$ is $[28,20,24,12,36]$. If he works for full $24$ hours on each of the five weekdays, he finishes all the work, so he does not have to work on weekends.\nExample case 2: No matter what Chef does, he will have to work on weekends.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\nfor t in range(int(input())):\n a1,a2,a3,a4,a5,p=[int(x)for x in input().rstrip().split()]\n if (a1+a2+a3+a4+a5)*p >120:\n print(\"Yes\")\n else:\n print(\"No\")\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n14 10 12 6 18 2\\n10 10 10 10 10 3\\n', 'output': 'No\\nYes\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/LOSTWKND'}","problem_id":"vfc_2910","program":"```python\n# cook your dish here\nfor t in range(int(input())):\n a1,a2,a3,a4,a5,p=[int(x)for x in input().rstrip().split()]\n if (a1+a2+a3+a4+a5)*p >120:\n print(\"Yes\")\n else:\n print(\"No\")\n\n```","inputs":"2\n14 10 12 6 18 2\n10 10 10 10 10 3\n","output":"No\nYes\n","actual_output":"No\nYes\n","execution_success":true,"sample_index":617},{"source":"apps","task_type":"verifiable_code","in_source_id":"1018","prompt":"Solve the following coding problem using the programming language python:\n\nChef has a garden with $N$ plants arranged in a line in decreasing order of height. Initially the height of the plants are $A_1, A_2, ..., A_N$.\nThe plants are growing, after each hour the height of the $i$-th plant increases by $i$ millimeters. Find the minimum number of integer hours that Chef must wait to have two plants of the same height.\n\n-----Input:-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The first line of each test case contains a single integer $N$.\n- The second line contains $N$ space separated integers $A_1,A_2,..A_N$. \n\n-----Output:-----\nFor each test case print a single line containing one integer, the minimum number of integer hours that Chef must wait to have two plants of the same height.\n\n-----Constraints-----\n- $1 \\leq T \\leq 1000$\n- $2 \\leq N \\leq 10^5$\n- $0\\leq A_i \\leq 10^{18}$\n- $A_i >A_{i+1}$, for each valid $i$\n- The Sum of $N$ over all test cases does not exceed $10^6$\n\n-----Sample Input:-----\n1\n3\n8 4 2\n\n-----Sample Output:-----\n2\n\n-----EXPLANATION:-----\nAfter $2$ hours there are two plants with the same height. \n$[8,4,2] \\rightarrow [9,6,5] \\rightarrow [10,8,8]$.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n\nfor _ in range(int(input())):\n n = int(input())\n arr = list(map(int, input().split()))\n hrs = arr[0] - arr[1]\n\n for i in range(1, n-1):\n if hrs > arr[i] - arr[i+1]:\n hrs = arr[i] - arr[i+1]\n\n print(hrs)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n3\\n8 4 2\\n', 'output': '2\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/INFTINCR'}","problem_id":"vfc_2914","program":"```python\n\nfor _ in range(int(input())):\n n = int(input())\n arr = list(map(int, input().split()))\n hrs = arr[0] - arr[1]\n\n for i in range(1, n-1):\n if hrs > arr[i] - arr[i+1]:\n hrs = arr[i] - arr[i+1]\n\n print(hrs)\n```","inputs":"1\n3\n8 4 2\n","output":"2\n","actual_output":"2\n","execution_success":true,"sample_index":618},{"source":"apps","task_type":"verifiable_code","in_source_id":"1019","prompt":"Solve the following coding problem using the programming language python:\n\nThe snakes want to build a temple for Lord Cobra. There are multiple strips of land that they are looking at, but not all of them are suitable. They need the strip of land to resemble a coiled Cobra. You need to find out which strips do so.\nFormally, every strip of land, has a length. Suppose the length of the i-th strip is is Ni, then there will be Ni integers, Hi1, Hi2, .. HiNi, which represent the heights of the ground at various parts of the strip, in sequential order. That is, the strip has been divided into Ni parts and the height of each part is given. This strip is valid, if and only if all these conditions are satisfied:\n- There should be an unique 'centre' part. This is where the actual temple will be built. By centre, we mean that there should be an equal number of parts to the left of this part, and to the right of this part.\n- Hi1 = 1\n- The heights keep increasing by exactly 1, as you move from the leftmost part, to the centre part.\n- The heights should keep decreasing by exactly 1, as you move from the centre part to the rightmost part. Note that this means that HiNi should also be 1.\nYour job is to look at every strip and find if it's valid or not.\n\n-----Input-----\n- The first line contains a single integer, S, which is the number of strips you need to look at. The description of each of the S strips follows\n- The first line of the i-th strip's description will contain a single integer: Ni, which is the length and number of parts into which it has been divided.\n- The next line contains Ni integers: Hi1, Hi2, .., HiNi. These represent the heights of the various parts in the i-th strip.\n\n-----Output-----\n- For each strip, in a new line, output \"yes\" if is a valid strip, and \"no\", if it isn't.\n\n-----Constraints-----\n- 1 \u2264 S \u2264 100 \n- 3 \u2264 Ni \u2264 100 \n- 1 \u2264 Hij \u2264 100 \n\n-----Example-----\nInput:\n7\n5\n1 2 3 2 1\n7\n2 3 4 5 4 3 2\n5\n1 2 3 4 3\n5\n1 3 5 3 1\n7\n1 2 3 4 3 2 1\n4\n1 2 3 2\n4\n1 2 2 1\n\nOutput:\nyes\nno\nno\nno\nyes\nno\nno\n\n-----Explanation-----\nIn the first strip, all the conditions are satisfied, hence it is valid.\nIn the second strip, it does not start with a 1, and hence is invalid.\nIn the third strip, it keeps increasing even past the centre, instead of decreasing. Hence invalid.\nThe fourth strip does not increase and decrease by exactly 1. Hence invalid.\nThe fifth satisfies all conditions and hence is valid.\nThe sixth and seventh strip do not have a 'centre' part. Because for every part, there are either more parts to its right than its left, or more parts on its left than its right. Hence both the strips are invalid.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\nfor i in range(int(input())):\n N=int(input())\n L=list(map(int,input().split()))\n l,h=0,N-1 \n flag=1\n if L[l]!=1 and L[h]!=1:\n flag=0\n else:\n while(l=k:\n print(1)\n else:\n print(2)\n \n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n2 1\\n1 0\\n3 5\\n0 1 0\\n', 'output': '1\\n2\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/MIXGA'}","problem_id":"vfc_2922","program":"```python\n# cook your dish here\nfor _ in range(int(input())):\n n,k=list(map(int,input().split()))\n a=list(map(int,input().split()))\n m=0\n for i in range(n):\n if i%2==0:\n if m<0:\n m-=a[i]\n else:\n m+=a[i]\n else:\n if m<0:\n m+=a[i]\n else:\n m-=a[i]\n if abs(m)>=k:\n print(1)\n else:\n print(2)\n \n\n```","inputs":"2\n2 1\n1 0\n3 5\n0 1 0\n","output":"1\n2\n","actual_output":"1\n2\n","execution_success":true,"sample_index":620},{"source":"apps","task_type":"verifiable_code","in_source_id":"1021","prompt":"Solve the following coding problem using the programming language python:\n\nThe chef likes to play with numbers. He takes some integer number x, writes it down on his iPad, and then performs with it n\u22121 operations of the two kinds:\n- divide the number x by 3 (x must be divisible by 3);\n- multiply the number x by 2.\nAfter each iteration, Chef writes down the result on his iPad and replaces x with the result. So there will be n numbers on the iPad after all.\nYou are given a sequence of length n \u2014 the numbers that Chef wrote down. This sequence is given in the order of the sequence can mismatch the order of the numbers written on the iPad.\nYour problem is to rearrange elements of this sequence in such a way that it can match a possible Chef's game in the order of the numbers written on the board. I.e. each next number will be exactly two times the previous number or exactly one-third of the previous number.\nI can give a guarantee that the answer exists.\n\n-----Input:-----\n- The first line of the input contains an integer number N i.e the number of the elements in the sequence. \n- The second line of the input contains n integer numbers a1,a2,\u2026, an i.e rearranged (reordered) sequence that Chef can write down on the iPad.\n\n-----Output:-----\nPrint N integer numbers \u2014 rearranged (reordered) input sequence that can be the sequence that Chef could write down on the iPad.\nIt is guaranteed that the answer exists\n\n-----Constraints-----\n- $2 \\leq N \\leq 100$\n- $1 \\leq A[i] \\leq 3* 10^{18} $\n\n-----Sample Input:-----\n6\n4 8 6 3 12 9\n\n-----Sample Output:-----\n9 3 6 12 4 8 \n\n-----EXPLANATION:-----\nIn the first example, the given sequence can be rearranged in the following way: [9,3,6,12,4,8]. It can match possible Polycarp's game which started with x=9.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nclass Node:\r\n def __init__(self,x):\r\n self.x=x\r\n self.next=None\r\n self.prev=None\r\n self.flag=True\r\n\r\nfor t in range(1):\r\n n=int(input())\r\n arr=list(map(int,input().split()))\r\n for i in range(n):\r\n arr[i]=Node(arr[i])\r\n for i in arr:\r\n d=[i.x%3==0,i.x,i.x//3,i.x*2]\r\n if d[0]:\r\n for j in arr:\r\n if j.x==d[2]:\r\n i.next=j\r\n j.prev=i\r\n break\r\n else:\r\n for j in arr:\r\n if j.x == d[3]:\r\n i.next = j\r\n j.prev = i\r\n break\r\n else:\r\n for j in arr:\r\n if j.x==d[3]:\r\n i.next=j\r\n j.prev=i\r\n break\r\n f,l=None,None\r\n for i in arr:\r\n if i.prev==None:\r\n f=i\r\n elif i.next==None:\r\n l=i\r\n while f!=l and l!=None:\r\n print(f.x,end=\" \")\r\n f=f.next\r\n print(f.x)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '6\\n4 8 6 3 12 9\\n', 'output': '9 3 6 12 4 8\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/BRBG2020/problems/THTOG'}","problem_id":"vfc_2926","program":"```python\nclass Node:\r\n def __init__(self,x):\r\n self.x=x\r\n self.next=None\r\n self.prev=None\r\n self.flag=True\r\n\r\nfor t in range(1):\r\n n=int(input())\r\n arr=list(map(int,input().split()))\r\n for i in range(n):\r\n arr[i]=Node(arr[i])\r\n for i in arr:\r\n d=[i.x%3==0,i.x,i.x//3,i.x*2]\r\n if d[0]:\r\n for j in arr:\r\n if j.x==d[2]:\r\n i.next=j\r\n j.prev=i\r\n break\r\n else:\r\n for j in arr:\r\n if j.x == d[3]:\r\n i.next = j\r\n j.prev = i\r\n break\r\n else:\r\n for j in arr:\r\n if j.x==d[3]:\r\n i.next=j\r\n j.prev=i\r\n break\r\n f,l=None,None\r\n for i in arr:\r\n if i.prev==None:\r\n f=i\r\n elif i.next==None:\r\n l=i\r\n while f!=l and l!=None:\r\n print(f.x,end=\" \")\r\n f=f.next\r\n print(f.x)\n```","inputs":"6\n4 8 6 3 12 9\n","output":"9 3 6 12 4 8\n","actual_output":"9 3 6 12 4 8\n","execution_success":true,"sample_index":621},{"source":"apps","task_type":"verifiable_code","in_source_id":"1022","prompt":"Solve the following coding problem using the programming language python:\n\nThere are $N$ cities on a circle, numbered $1$ through $N$. For each $i$ ($1 \\le i \\le N-1$), cities $i$ and $i+1$ are directly connected by a bidirectional road with length $A_i$, and cities $N$ and $1$ are also directly connected by a bidirectional road with length $A_N$. However, we do not know the lengths of some roads.\nFor each city $i$, we do know that it has an opposite city \u2014 formally, there is a city $j \\neq i$ such that the clockwise distance between cities $i$ and $j$ is equal to the counterclockwise distance between these cities.\nPlease find the lengths of all roads in such a way that the above condition is satisfied and the sum of lengths of all roads is minimised.\n\n-----Input-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The first line of the input contains a single integer $N$.\n- The second line contains $N$ space-separated integers $A_1, A_2, \\dots, A_N$. For each valid $i$, $A_i = -1$ denotes that the length of road $i$ is unknown.\n\n-----Output-----\nFor each test case, print a line containing the string \"NO\" if there is no solution or \"YES\" otherwise. If a solution exists, print a second line containing $N$ space-separated positive integers \u2014 the lengths of all roads in your solution. Each of these integers should be $\\le 10^9$. If there are multiple solutions, you may print any one.\n\n-----Constraints-----\n- $1 \\le T \\le 100$\n- $3 \\le N \\le 10^5$\n- $1 \\le A_i \\le 10^9$ or $A_i = -1$ for each valid $i$\n- the sum of $N$ for all test cases does not exceed $3\\cdot 10^5$\n\n-----Subtasks-----\nSubtask #1 (10 points): $N \\le 4$\nSubtask #2 (20 points): $A_i = \\pm 1$ for each valid $i$\nSubtask #3 (70 points): original constraints\n\n-----Example Input-----\n4\n4\n1 1 1 1\n4\n1 1 1 2\n4\n1 -1 -1 4\n4\n1 -1 2 -1\n\n-----Example Output-----\nYES\n1 1 1 1\nNO\nYES\n1 4 1 4\nNO\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\n# cook your dish here\nimport math\ntest=int(input())\nfor _ in range(test):\n n=int(input())\n l=list(map(int,input().split()))\n f=0\n for i in range(math.ceil(n//2)):\n if n%2==1:\n f=1\n break\n else:\n if l[i]!=l[i+n//2]:\n if min(l[i],l[i+n//2])==-1:\n l[i]=max(l[i],l[i+n//2])\n l[i+n//2]=max(l[i],l[i+n//2])\n else:\n f=1\n break\n else:\n if l[i]==-1:\n l[i]=1\n l[i+n//2]=1\n if f==1:\n print(\"NO\")\n else:\n print(\"YES\")\n print(*l)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '4\\n4\\n1 1 1 1\\n4\\n1 1 1 2\\n4\\n1 -1 -1 4\\n4\\n1 -1 2 -1\\n', 'output': 'YES\\n1 1 1 1\\nNO\\nYES\\n1 4 1 4\\nNO\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/OPPOSITE'}","problem_id":"vfc_2930","program":"```python\n# cook your dish here\n# cook your dish here\nimport math\ntest=int(input())\nfor _ in range(test):\n n=int(input())\n l=list(map(int,input().split()))\n f=0\n for i in range(math.ceil(n//2)):\n if n%2==1:\n f=1\n break\n else:\n if l[i]!=l[i+n//2]:\n if min(l[i],l[i+n//2])==-1:\n l[i]=max(l[i],l[i+n//2])\n l[i+n//2]=max(l[i],l[i+n//2])\n else:\n f=1\n break\n else:\n if l[i]==-1:\n l[i]=1\n l[i+n//2]=1\n if f==1:\n print(\"NO\")\n else:\n print(\"YES\")\n print(*l)\n```","inputs":"4\n4\n1 1 1 1\n4\n1 1 1 2\n4\n1 -1 -1 4\n4\n1 -1 2 -1\n","output":"YES\n1 1 1 1\nNO\nYES\n1 4 1 4\nNO\n","actual_output":"YES\n1 1 1 1\nNO\nYES\n1 4 1 4\nNO\n","execution_success":true,"sample_index":622},{"source":"apps","task_type":"verifiable_code","in_source_id":"1023","prompt":"Solve the following coding problem using the programming language python:\n\nThe 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.\n\n-----Input:-----\n- First-line will contain $T$, the number of test cases. Then the test cases follow. \n- Each test case contains a single line of input, one integer $K$. \n\n-----Output:-----\nFor each test case, output as the pattern.\n\n-----Constraints-----\n- $1 \\leq T \\leq 50$\n- $1 \\leq K \\leq 50$\n\n-----Sample Input:-----\n5\n1\n2\n3\n4\n5\n\n-----Sample Output:-----\n1\n1\n23\n1\n23\n456\n1\n23\n4 5\n6789\n1\n23\n4 5\n6 7\n89101112\n\n-----EXPLANATION:-----\nNo need, else pattern can be decode easily.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\nfor _ in range(int(input())):\n n = int(input())\n count = 1\n l = 3*(n-1)\n i = 0\n if n==1:\n print(1)\n continue\n while count<=l-n:\n for j in range(i+1):\n if j==i:\n print(count)\n count += 1\n elif j==0:\n print(count,end=\"\")\n count += 1\n else:\n print(\" \",end=\"\") \n i+=1\n while count<=l:\n print(count,end=\"\")\n count += 1\n print()\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '5\\n1\\n2\\n3\\n4\\n5\\n', 'output': '1\\n1\\n23\\n1\\n23\\n456\\n1\\n23\\n4 5\\n6789\\n1\\n23\\n4 5\\n6 7\\n89101112\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/PSTR2020/problems/ITGUY05'}","problem_id":"vfc_2934","program":"```python\n# cook your dish here\nfor _ in range(int(input())):\n n = int(input())\n count = 1\n l = 3*(n-1)\n i = 0\n if n==1:\n print(1)\n continue\n while count<=l-n:\n for j in range(i+1):\n if j==i:\n print(count)\n count += 1\n elif j==0:\n print(count,end=\"\")\n count += 1\n else:\n print(\" \",end=\"\") \n i+=1\n while count<=l:\n print(count,end=\"\")\n count += 1\n print()\n```","inputs":"5\n1\n2\n3\n4\n5\n","output":"1\n1\n23\n1\n23\n456\n1\n23\n4 5\n6789\n1\n23\n4 5\n6 7\n89101112\n","actual_output":"1\n1\n23\n1\n23\n456\n1\n23\n4 5\n6789\n1\n23\n4 5\n6 7\n89101112\n","execution_success":true,"sample_index":623},{"source":"apps","task_type":"verifiable_code","in_source_id":"1024","prompt":"Solve the following coding problem using the programming language python:\n\nNote : This question carries $100$ $points$\nCodeLand is celebrating a festival by baking cakes! In order to avoid wastage, families follow a unique way of distributing cakes.\nFor $T$ families in the locality, $i$-th family (1 <= $i$ <= $T$) has $N$ members. They baked $S$ slices of cakes. The smallest member of the family gets $K$ slices of cakes. Each family has a lucky number of $R$ and they agree to distribute the slices such that the member gets $R$ times more slices than the member just smaller than them. Since the family is busy in festival preparations, find out if the number of slices would be sufficient for the family or not. Also, find how many extra slices they have or how many slices are they short of.\nAlso, the locality is kind and believes in sharing. So, you also need to determine if each family would have sufficient slices if families shared their cakes among each other!\n\n-----Input :-----\n- First line of input will have a single integer $T$ i.e. the number of families in the locality\n- For next $T$ lines, each line will describe one family through 4 integers i.e. $S$, $N$, $K$, $R$ separated by spaces\n\n-----Output-----\n- First $T$ lines of output will show if slices are enough for the family or not, followed by extra or required slices. For example, if slices are sufficient, the output would be $POSSIBLE$ $10$ which implies 10 slices are extra. If slices are insufficient, the output would be $IMPOSSIBLE$ $15$ which implies 15 slices are required to fulfill the requirement.\n- Last line of output would be $IMPOSSIBLE$ or $POSSIBLE$ depending on whether each family would get enough slices after sharing.\n\n-----Constraints:-----\n- 1 \u2264 $T$ \u2264 50\n- 1 \u2264 $N$ \u2264 15\n- 1 \u2264 $S$ \u2264 10^9\n- 1 \u2264 $K$ \u2264 5\n- 1 \u2264 $R$ \u2264 5\n\n-----Sample Input:-----\n5\n100 4 2 2\n100 4 3 2\n100 4 3 3\n200 4 4 2\n10 3 2 2\n\n-----Sample Output:-----\nPOSSIBLE 70\nPOSSIBLE 55\nIMPOSSIBLE 20\nPOSSIBLE 140\nIMPOSSIBLE 4\nPOSSIBLE\n\n-----Explanation-----\nFor the first home, the youngest member has got 2 slices, the one older than them gets 2 times more slices, and so forth. So, first home needs 2 + 4 + 8 + 16 = 30 slices. But since they made 100, they have 70 extra, hence we print 'POSSIBLE 70'.\nDoing the same for other houses, we find 20 + 4 = 24 slices extra are required so that all families have enough slices. In this case we have 70 + 55 + 140 = 265 extra slices which is > 24, so we print 'POSSIBLE' in last line.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\nextra, less = 0,0\nfor _ in range(int(input())):\n sli,mem,sma,luc = list(map(int, input().split()))\n total = sma\n t = sma\n while mem > 1:\n t *= luc\n total += t\n mem -= 1\n if total <= sli:\n extra += sli-total\n print('POSSIBLE',sli-total)\n else:\n less += total-sli\n print('IMPOSSIBLE',total-sli)\nif extra >= less:\n print('POSSIBLE')\nelse:\n print('IMPOSSIBLE')\n \n \n \n \n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '5\\n100 4 2 2\\n100 4 3 2\\n100 4 3 3\\n200 4 4 2\\n10 3 2 2\\n', 'output': 'POSSIBLE 70\\nPOSSIBLE 55\\nIMPOSSIBLE 20\\nPOSSIBLE 140\\nIMPOSSIBLE 4\\nPOSSIBLE\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/PCO12020/problems/MORECAKE'}","problem_id":"vfc_2938","program":"```python\n# cook your dish here\nextra, less = 0,0\nfor _ in range(int(input())):\n sli,mem,sma,luc = list(map(int, input().split()))\n total = sma\n t = sma\n while mem > 1:\n t *= luc\n total += t\n mem -= 1\n if total <= sli:\n extra += sli-total\n print('POSSIBLE',sli-total)\n else:\n less += total-sli\n print('IMPOSSIBLE',total-sli)\nif extra >= less:\n print('POSSIBLE')\nelse:\n print('IMPOSSIBLE')\n \n \n \n \n\n```","inputs":"5\n100 4 2 2\n100 4 3 2\n100 4 3 3\n200 4 4 2\n10 3 2 2\n","output":"POSSIBLE 70\nPOSSIBLE 55\nIMPOSSIBLE 20\nPOSSIBLE 140\nIMPOSSIBLE 4\nPOSSIBLE\n","actual_output":"POSSIBLE 70\nPOSSIBLE 55\nIMPOSSIBLE 20\nPOSSIBLE 140\nIMPOSSIBLE 4\nPOSSIBLE\n","execution_success":true,"sample_index":624},{"source":"apps","task_type":"verifiable_code","in_source_id":"1025","prompt":"Solve the following coding problem using the programming language python:\n\nYou are given a tree rooted at node $1$ with $N$ vertices. The $i$$th$ vertex initially has value $A_i (1 \\leq i \\leq N)$. You are also given $Q$ queries. \nIn each query you are given a vertex $V$. Let $S = \\{ S_1 , S_2 , ... S_x \\} $ denote the set of vertices such that $S_i$ is in the subtree of $V$, distance between $S_i$ and $V$ is even and $S_i \\neq V$ for all $i$. For all $S_i$ , add $A$$S_i$ to $A_V$ and change the value of $A$$S_i$ to zero.\nFind the values of all the vertices after all queries are performed. \nNote-The distance between two vertices is defined as the number of edges\ntraversed on the shortest path from one vertex to the other.\n\n-----Input:-----\n- The first line contains an integer $T$ denoting the number of test cases.\n- The first line of each test case contain two integers $N$ and $Q$.\n- The second line contains $N$ space separated integers, $A_1, A_2, ..., A_n$ denoting the initial values of the vertices.\n- The next $N-1$ lines contain two integers $u$ and $v$ denoting an edge between $u$and $v$.\n- The next $Q$ lines contain a single integer which is the query.\n\n-----Output:-----\n- Print a single line containing $N$ integers for each test case which is the final values of the vertices.\n\n-----Constraints:-----\n- $1\\leq T \\leq 10$\n- $1 \\leq N \\leq 200000$\n- $1 \\leq Q \\leq 200000$\n- $0 \\leq A_i \\leq 10^9$\n- The sum of $N$ over all test cases does not exceed $200000$.\n- The sum of $Q$ over all test cases does not exceed $200000$.\n\n-----Sample Input-----\n1\n4 3\n6 2 7 3\n1 2\n2 3\n3 4\n3\n2\n1\n\n-----Sample Output-----\n13 5 0 0\n\n-----Explanation-----\nNode $3$ has no child in its subtree which is at an even distance so there is no change in the values. Values of nodes after $1st$ query: $6, 2, 7, 3$.\nNode $4$ is at an even distance in the subtree of node $2$ so $A_4$ gets added to $A_2$ and $A_4$ becomes 0. Values of nodes after $2nd$ query: $6, 5, 7, 0$.\nNode $3$ is at an even distance in the subtree of node $1$ so $A_3$ gets added to $A_1$ and $A_3$ becomes 0. Values of nodes after $3rd$ query: $13, 5, 0, 0$.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfrom collections import defaultdict as dd,deque as dq\ndef opbfs(u,vis,ll,parr):\n q=dq([(u,0)])\n uu=u\n su=0\n while q:\n \n u,lol=q.pop()\n par=parr[u]\n if(lol%2==0):\n vis[u]=1\n su+=ll[u-1]\n ll[u-1]=0\n for j in d[u]:\n if(j!=par):\n q.appendleft((j,lol+1))\n ll[uu-1]=su\ndef bfs(height,d,parr):\n q=dq([1])\n while q:\n u=q.pop()\n height[u]=height[parr[u]]+1\n for i in d[u]:\n if(i!=parr[u]):\n q.appendleft(i)\n parr[i]=u\nt=int(input())\nwhile t:\n n,q=map(int,input().split())\n ll=list(map(int,input().split()))\n d=dd(list)\n for i in range(n-1):\n u,v=map(int,input().split())\n d[u].append(v)\n d[v].append(u)\n vis=[0]*(n+1)\n l=[]\n height=[0]*(n+1)\n parr=[0]*(n+1)\n bfs(height,d,parr)\n for i in range(q):\n u=int(input())\n l.append((height[u],u,i))\n l.sort()\n vis=[0]*(n+1)\n #print(l)\n for i in l:\n he,u,ind=i\n if(vis[u]==0):\n #print(u)\n opbfs(u,vis,ll,parr)\n print(*ll)\n t-=1\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n4 3\\n6 2 7 3\\n1 2\\n2 3\\n3 4\\n3\\n2\\n1\\n', 'output': '13 5 0 0\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/CENS20F'}","problem_id":"vfc_2942","program":"```python\nfrom collections import defaultdict as dd,deque as dq\ndef opbfs(u,vis,ll,parr):\n q=dq([(u,0)])\n uu=u\n su=0\n while q:\n \n u,lol=q.pop()\n par=parr[u]\n if(lol%2==0):\n vis[u]=1\n su+=ll[u-1]\n ll[u-1]=0\n for j in d[u]:\n if(j!=par):\n q.appendleft((j,lol+1))\n ll[uu-1]=su\ndef bfs(height,d,parr):\n q=dq([1])\n while q:\n u=q.pop()\n height[u]=height[parr[u]]+1\n for i in d[u]:\n if(i!=parr[u]):\n q.appendleft(i)\n parr[i]=u\nt=int(input())\nwhile t:\n n,q=map(int,input().split())\n ll=list(map(int,input().split()))\n d=dd(list)\n for i in range(n-1):\n u,v=map(int,input().split())\n d[u].append(v)\n d[v].append(u)\n vis=[0]*(n+1)\n l=[]\n height=[0]*(n+1)\n parr=[0]*(n+1)\n bfs(height,d,parr)\n for i in range(q):\n u=int(input())\n l.append((height[u],u,i))\n l.sort()\n vis=[0]*(n+1)\n #print(l)\n for i in l:\n he,u,ind=i\n if(vis[u]==0):\n #print(u)\n opbfs(u,vis,ll,parr)\n print(*ll)\n t-=1\n```","inputs":"1\n4 3\n6 2 7 3\n1 2\n2 3\n3 4\n3\n2\n1\n","output":"13 5 0 0\n","actual_output":"13 5 0 0\n","execution_success":true,"sample_index":625},{"source":"apps","task_type":"verifiable_code","in_source_id":"1026","prompt":"Solve the following coding problem using the programming language python:\n\nThis is probably the simplest problem ever. You just need to count the number of ordered triples of different numbers (X1, X2, X3), where Xi could be any positive integer from 1 to Ni, inclusive (i = 1, 2, 3).\nNo, wait. I forgot to mention that numbers N1, N2, N3 could be up to 1018. Well, in any case it is still quite simple :)\nBy the way, because of this the answer could be quite large. Hence you should output it modulo 109 + 7. That is you need to find the remainder of the division of the number of required triples by 109 + 7.\n\n-----Input-----\nThe first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows. The only line of each test case contains three space-separated integers N1, N2, N3.\n\n-----Output-----\nFor each test case, output a single line containing the number of required triples modulo 109 + 7.\n\n-----Constraints-----\n- 1 \u2264 T \u2264 1000\n- 1 \u2264 Ni \u2264 1018\n\n-----Example-----\nInput:\n5\n3 3 3\n2 4 2\n1 2 3\n25 12 2012\n1 1 2013\n\nOutput:\n6\n4\n1\n578880\n0\n\n-----Explanation-----\nExample case 1. We have the following triples composed of different numbers up to 3:\n(1, 2, 3)\n(1, 3, 2)\n(2, 1, 3)\n(2, 3, 1)\n(3, 1, 2)\n(3, 2, 1)\nExample case 2. Here the triples are:\n(1, 3, 2)\n(1, 4, 2)\n(2, 3, 1)\n(2, 4, 1)\nExample case 3. Here the only triple is (1, 2, 3).\nExample case 4. Merry Christmas! \nExample case 5. ... and Happy New Year! By the way here the answer is zero since the only choice for X1 and for is X2 is 1, so any such triple will have equal numbers.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nd=1000000007\nfor _ in range(int(input())):\n l=sorted(list(map(int,input().split())))\n ans=(l[0]%d)*((l[1]-1)%d)*((l[2]-2)%d)\n print(ans%d)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '5\\n3 3 3\\n2 4 2\\n1 2 3\\n25 12 2012\\n1 1 2013\\n', 'output': '6\\n4\\n1\\n578880\\n0\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/THREEDIF'}","problem_id":"vfc_2946","program":"```python\nd=1000000007\nfor _ in range(int(input())):\n l=sorted(list(map(int,input().split())))\n ans=(l[0]%d)*((l[1]-1)%d)*((l[2]-2)%d)\n print(ans%d)\n```","inputs":"5\n3 3 3\n2 4 2\n1 2 3\n25 12 2012\n1 1 2013\n","output":"6\n4\n1\n578880\n0\n","actual_output":"6\n4\n1\n578880\n0\n","execution_success":true,"sample_index":626},{"source":"apps","task_type":"verifiable_code","in_source_id":"1027","prompt":"Solve the following coding problem using the programming language python:\n\nChef recently learned about concept of periodicity of strings. A string is said to have a period P, if P divides N and for each i, the i-th of character of the string is same as i-Pth character (provided it exists), e.g. \"abab\" has a period P = 2, It also has a period of P = 4, but it doesn't have a period of 1 or 3.\nChef wants to construct a string of length N that is a palindrome and has a period P. It's guaranteed that N is divisible by P. This string can only contain character 'a' or 'b'. Chef doesn't like the strings that contain all a's or all b's.\nGiven the values of N, P, can you construct one such palindromic string that Chef likes? If it's impossible to do so, output \"impossible\" (without quotes)\n\n-----Input-----\nThe first line of the input contains an integer T denoting the number of test cases.\nThe only line of each test case contains two space separated integers N, P.\n\n-----Output-----\nFor each test case, output a single line containing the answer of the problem, i.e. the valid string if it exists otherwise \"impossible\" (without quotes). If there are more than possible answers, you can output any.\n\n-----Constraints-----\n- 1 \u2264 T \u2264 20\n- 1 \u2264 P, N \u2264 105\n\n-----Subtasks-----\n- Subtask #1 (25 points) : P = N\n- Subtask #2 (75 points) : No additional constraints\n\n-----Example-----\nInput\n5\n3 1\n2 2\n3 3\n4 4\n6 3\n\nOutput\nimpossible\nimpossible\naba\nabba\nabaaba\n\n-----Explanation-----\nExample 1: The only strings possible are either aaa or bbb, which Chef doesn't like. So, the answer is impossible.\nExample 2: There are four possible strings, aa, ab, ba, bb. Only aa and bb are palindromic, but Chef doesn't like these strings. Hence, the answer is impossible.\nExample 4: The string abba is a palindrome and has a period of 4.\nExample 5: The string abaaba is a palindrome and has a period of length 3.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nT=int(input())\nfor i in range(T):\n n,m=list(map(int,input().split()))\n if(m<=2):\n print(\"impossible\")\n else:\n l=[0]*m\n\n if(m%2==0):\n a=m//2\n else:\n a=(m//2)+1\n for j in range(a):\n if(j%2==0):\n l[j]=\"a\"\n l[m-j-1]=\"a\"\n \n else:\n l[j]=\"b\"\n l[m-j-1]=\"b\"\n \n \n r=\"\"\n s=n//m\n for e in l:\n r=r+e\n print(r*s)\n \n \n\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '5\\n3 1\\n2 2\\n3 3\\n4 4\\n6 3\\n', 'output': 'impossible\\nimpossible\\naba\\nabba\\nabaaba\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/PERPALIN'}","problem_id":"vfc_2950","program":"```python\nT=int(input())\nfor i in range(T):\n n,m=list(map(int,input().split()))\n if(m<=2):\n print(\"impossible\")\n else:\n l=[0]*m\n\n if(m%2==0):\n a=m//2\n else:\n a=(m//2)+1\n for j in range(a):\n if(j%2==0):\n l[j]=\"a\"\n l[m-j-1]=\"a\"\n \n else:\n l[j]=\"b\"\n l[m-j-1]=\"b\"\n \n \n r=\"\"\n s=n//m\n for e in l:\n r=r+e\n print(r*s)\n \n \n\n\n```","inputs":"5\n3 1\n2 2\n3 3\n4 4\n6 3\n","output":"impossible\nimpossible\naba\nabba\nabaaba\n","actual_output":"impossible\nimpossible\naba\nabba\nabaaba\n","execution_success":true,"sample_index":627},{"source":"apps","task_type":"verifiable_code","in_source_id":"1028","prompt":"Solve the following coding problem using the programming language python:\n\nChef has some numbers. His girlfriend Chefina feels good when chef gives her a particular pattern number also called as Armstrong number.\nArmstrong number is a number whose sum of its all individual digit raise to the power of the number of digit in that number is equal to that number itself\neg.. 153 = 1^3 + 5^3 + 3^3 (153 is an Armstrong number)\n1634 = 1^4 + 6^4 + 3^4 + 4^4 (1634 is an Armstrong number)\nAs a love guru of chef you have to help chef to find Armstrong numbers Among the numbers which chef has initially so that Chefina feels good\n\n-----Input:-----\nFirst line will contain a positive Integer $T$ which is the number of testcases\nNext $T$ lines follows an Integer $N$.\n\n-----Output:-----\nFor Every n You have to print \"FEELS GOOD\" without qoutes if it is an armstrong number otherwise Print \"FEELS BAD\" without quotes\n\n-----Constraints-----\n- $1 \\leq T \\leq 10$\n- $2 \\leq N \\leq 10^6$\n\n-----Sample Input:-----\n3\n153\n11\n1634\n\n-----Sample Output:-----\nFEELS GOOD\nFEELS BAD\nFEELS GOOD\n\n-----EXPLANATION:-----\nFor test case 1 --> 153 = 1^3 + 5^3 + 3^3 (153 is an armstrong number)\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\ndef power(x, y):\n\tif y == 0:\n\t\treturn 1\n\tif y % 2 == 0:\n\t\treturn power(x, y // 2) * power(x, y // 2)\n\n\treturn x * power(x, y // 2) * power(x, y // 2)\n\n\n# Function to calculate order of the number\ndef order(x):\n\t# Variable to store of the number\n\tn = 0\n\twhile (x != 0):\n\t\tn = n + 1\n\t\tx = x // 10\n\n\treturn n\n\n\n# Function to check whether the given\n# number is Armstrong number or not\ndef isArmstrong(x):\n\tn = order(x)\n\ttemp = x\n\tsum1 = 0\n\n\twhile (temp != 0):\n\t\tr = temp % 10\n\t\tsum1 = sum1 + power(r, n)\n\t\ttemp = temp // 10\n\n\t# If condition satisfies\n\treturn (sum1 == x)\n\n\n# Driver code\n\nfor _ in range(int(input())):\n\tnum = int(input())\n\tif isArmstrong(num):\n\t\tprint(\"FEELS GOOD\")\n\telse:\n\t\tprint(\"FEELS BAD\")\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\n153\\n11\\n1634\\n', 'output': 'FEELS GOOD\\nFEELS BAD\\nFEELS GOOD\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/SPTC2020/problems/CPCEJC5'}","problem_id":"vfc_2954","program":"```python\ndef power(x, y):\n\tif y == 0:\n\t\treturn 1\n\tif y % 2 == 0:\n\t\treturn power(x, y // 2) * power(x, y // 2)\n\n\treturn x * power(x, y // 2) * power(x, y // 2)\n\n\n# Function to calculate order of the number\ndef order(x):\n\t# Variable to store of the number\n\tn = 0\n\twhile (x != 0):\n\t\tn = n + 1\n\t\tx = x // 10\n\n\treturn n\n\n\n# Function to check whether the given\n# number is Armstrong number or not\ndef isArmstrong(x):\n\tn = order(x)\n\ttemp = x\n\tsum1 = 0\n\n\twhile (temp != 0):\n\t\tr = temp % 10\n\t\tsum1 = sum1 + power(r, n)\n\t\ttemp = temp // 10\n\n\t# If condition satisfies\n\treturn (sum1 == x)\n\n\n# Driver code\n\nfor _ in range(int(input())):\n\tnum = int(input())\n\tif isArmstrong(num):\n\t\tprint(\"FEELS GOOD\")\n\telse:\n\t\tprint(\"FEELS BAD\")\n```","inputs":"3\n153\n11\n1634\n","output":"FEELS GOOD\nFEELS BAD\nFEELS GOOD\n","actual_output":"FEELS GOOD\nFEELS BAD\nFEELS GOOD\n","execution_success":true,"sample_index":628},{"source":"apps","task_type":"verifiable_code","in_source_id":"1030","prompt":"Solve the following coding problem using the programming language python:\n\nLet's consider a rooted binary tree with the following properties:\n- The number of nodes and edges in the tree is infinite\n- The tree root is labeled by $1$\n- A node labeled by $v$ has two children: $2 \\cdot v$ (the left child of $v$), and $2 \\cdot v + 1$ (the right child of $v$).\nHere is an image of the first several layers of such a tree:\n\nLet's consider four operations that you are allowed to apply during the tree traversal:\n- move to the left child - move from $v$ to $2 \\cdot v$\n- move to the right child - move from $v$ to $2 \\cdot v + 1$\n- move to the parent as a left child - move from $v$ to $\\frac{v}{2}$ if $v$ is an even integer\n- move to the parent as a right child - move from $v$ to $\\frac{v - 1}{2}$ if $v$ is an odd integer\nIt can be proven, that for any pair of nodes $u$ and $v$, there is only one sequence of commands that moves from $u$ to $v$ and visits each node of the tree at most once. Let's call such a sequence of commands a path configuration for a pair of nodes $(u, v)$.\nYou are asked to process a series of the following queries: \nYou are given three integers $n$, $u$ and $v$ ($1 \\leq u, v \\leq n$). Count the pairs of nodes $(w, t)$ ($1 \\leq w, t \\leq n$) such that the path configuration for $(w, t)$ is the same with the path configuration for $(u, v)$.\n\n-----Input-----\n- The first line of input contains a single integer $Q$, denoting the number of queries to process.\n- Each of the next $Q$ lines contains three space-separated integers $n$, $u$ and $v$ denoting a query.\n\n-----Output-----\nFor each query, print the answer on a separate line.\n\n-----Constraints-----\n- $1 \\leq Q \\leq 2 \\cdot 10^4$\n- $1 \\leq u, v \\leq n \\leq 10^{9}$\n\n-----Example Input-----\n3\n11 9 11\n10 2 2\n8 1 8\n\n-----Example Output-----\n2\n10\n1\n\n-----Explanation-----\nIn the first query from the example test case, you should count pairs $(5, 7)$ and $(9, 11)$.\nIn the second query from the example test case, you should count the following pairs: $(1, 1)$, $(2, 2)$, $(3, 3)$, $(4, 4)$, $(5, 5)$, $(6, 6)$, $(7, 7)$, $(8, 8)$, $(9, 9)$ and $(10, 10)$.\nIn the third query from the example test case, you should only count a pair $(1, 8)$.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nt = int(input())\nwhile(t>0):\n t-=1;\n n,l,r = list(map(int,input().split()));\n a = bin(l)[2:];\n b = bin(r)[2:];\n # find matching\n z = 0;\n l = min(len(a),len(b));\n for i in range(l):\n if a[i]==b[i]:\n z+=1;\n else:\n break;\n\n #find base string\n a = a[z:]\n b = b[z:]\n if(len(a)==0 and len(b)==0):\n print(n);\n else :\n m = max(len(a),len(b))\n #print m;\n zz = bin(n)[2:]\n x= len(zz)\n y = zz[:x-m]\n \n f1 = y+a;\n f2 = y+b;\n ans = int(y,2)\n if(int(f1,2)>n or int(f2,2)>n):\n ans-=1;\n \n print(ans) \n \n\n \n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\n11 9 11\\n10 2 2\\n8 1 8\\n', 'output': '2\\n10\\n1\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/COOK69/problems/BINTREEQ'}","problem_id":"vfc_2962","program":"```python\nt = int(input())\nwhile(t>0):\n t-=1;\n n,l,r = list(map(int,input().split()));\n a = bin(l)[2:];\n b = bin(r)[2:];\n # find matching\n z = 0;\n l = min(len(a),len(b));\n for i in range(l):\n if a[i]==b[i]:\n z+=1;\n else:\n break;\n\n #find base string\n a = a[z:]\n b = b[z:]\n if(len(a)==0 and len(b)==0):\n print(n);\n else :\n m = max(len(a),len(b))\n #print m;\n zz = bin(n)[2:]\n x= len(zz)\n y = zz[:x-m]\n \n f1 = y+a;\n f2 = y+b;\n ans = int(y,2)\n if(int(f1,2)>n or int(f2,2)>n):\n ans-=1;\n \n print(ans) \n \n\n \n\n```","inputs":"3\n11 9 11\n10 2 2\n8 1 8\n","output":"2\n10\n1\n","actual_output":"2\n10\n1\n","execution_success":true,"sample_index":630},{"source":"apps","task_type":"verifiable_code","in_source_id":"1032","prompt":"Solve the following coding problem using the programming language python:\n\nHelp Saurabh with his Chemistry Assignment.\n\nSaurabh has been given a chemistry assignment by Ruby Mam. Though the assignment is simple but\n\nSaurabh has to watch India vs Pakistan Match and he has no time to do the assignment by himself.\n\nSo Saurabh wants you to do his assignment so that he doesn\u2019t get scolded by Ruby Mam . The assignment\n\nis as follows , Suppose there are X particles initially at time t=0 in a box. At a time t the number of particles in\n\nbox becomes t times the number of particles at time t-1 . You will be given N and X where N is time at which the\n\nnumber of particles in box is to be calculated and X is the number of particles at time t=0.\n\n-----Input-----\nThe first line will contain the integer T, the number of test cases. Each test case consists of two space\n\nseparated integers N and X .\n\n-----Output-----\nFor each test case, output the answer to the query. Since the output can be very large, output the answer modulo\n\n10^6+3\n\n-----Constraints-----\n- 1 \u2264 T \u2264 100000\n- 1 \u2264 N,X \u2264 10^18\n\n-----Example-----\nInput:\n2\n1 2\n2 1\n\nOutput:\n2\n2\n\n-----Explanation-----\nExample case 2.At t=0 particles are 1 ,so at t=1 ,particles are 1*1 = 1 particles. At t=2, particles are 2*1 = 2 particles.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\na = [1]\nM = 10**6 + 3\nfor ii in range(1, 1000005):\n a.append((a[-1]*ii)%M)\nfor __ in range(eval(input())):\n n, x = list(map(int, input().split()))\n if n>=M: print(0)\n else: print((a[n]*x)%M)\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n1 2\\n2 1\\n', 'output': '2\\n2\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/REC2016/problems/RECIICHA'}","problem_id":"vfc_2970","program":"```python\na = [1]\nM = 10**6 + 3\nfor ii in range(1, 1000005):\n a.append((a[-1]*ii)%M)\nfor __ in range(eval(input())):\n n, x = list(map(int, input().split()))\n if n>=M: print(0)\n else: print((a[n]*x)%M)\n\n```","inputs":"2\n1 2\n2 1\n","output":"2\n2\n","actual_output":"2\n2\n","execution_success":true,"sample_index":632},{"source":"apps","task_type":"verifiable_code","in_source_id":"1033","prompt":"Solve the following coding problem using the programming language python:\n\nGiven the values at the leaf nodes of a complete binary tree. The total number of nodes in the binary tree, is also given. Sum of the values at both the children of a node is equal to the value of the node itself. You can add any value or subtract any value from a node. Print the minimum change(difference made) in the sum of values of all the nodes in the tree, such that all the leaf nodes have the same value.\n\nNote: If a value transfers from one node to another, then that is not a change, but if an extra is needed to be added or subtracted to the entire total value of the nodes, then that is a change.\n\nInput Description:\n\nInput will contain an integer N, the number of nodes in the tree on a newline, followed by N space separated integers representing the values at the leaf nodes of the tree.\n\nOutput Description:\n\nPrint the required value on a newline.\n\nConstraints:\n\n1<=N<=20000\n1<=Value at each node in the leaves<=1000\n\nExample 1:\nInput:\n\n1\n\n50\nOutput:\n\n0\n\nExplanation: Since there is only one node, it is a leaf node itself and no change needs to be made.\n\nExample 2:\nInput:\n\n3\n\n200 800\nOutput:\n\n0 \n\nExplanation: There are two leaf nodes, and they can be made to 500 500, since no change in the total was made so difference made is 0. \n\nExample 3:\nInput:\n\n30\n\n29 33 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17\nOutput:\n\n6\n\nOutput: A total change of 6 needs to be changed to the entire value of the nodes, to get the leaf nodes equal.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nprint(0)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1:\\nInput:\\n1\\n50\\n', 'output': '0\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/KM252020/problems/KM25P5C'}","problem_id":"vfc_2974","program":"```python\nprint(0)\n```","inputs":"1:\nInput:\n1\n50\n","output":"0\n","actual_output":"0\n","execution_success":true,"sample_index":633},{"source":"apps","task_type":"verifiable_code","in_source_id":"1034","prompt":"Solve the following coding problem using the programming language python:\n\nA manufacturing project consists of exactly $K$ tasks. The board overviewing the project wants to hire $K$ teams of workers \u2014 one for each task. All teams begin working simultaneously.\nObviously, there must be at least one person in each team. For a team of $A$ workers, it takes exactly $A$ days to complete the task they are hired for. Each team acts independently, unaware of the status of other teams (whether they have completed their tasks or not), and submits their result for approval on the $A$-th day.\nHowever, the board approves the project only if all $K$ teams complete their tasks on the same day \u2014 it rejects everything submitted on any other day. The day after a team finds out that its result was rejected, it resumes work on the same task afresh. Therefore, as long as a team of $A$ workers keeps getting rejected, it submits a new result of their task for approval on the $A$-th, $2A$-th, $3A$-th day etc.\nThe board wants to hire workers in such a way that it takes exactly $X$ days to complete the project. Find the smallest number of workers it needs to hire.\n\n-----Input-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The first and only line of each test case contains two space-separated integers $K$ and $X$.\n\n-----Output-----\nFor each test case, print a single line containing one integer \u2014 the smallest required number of workers.\n\n-----Constraints-----\n- $1 \\le T \\le 40$\n- $2 \\le K, X \\le 10^6$\n\n-----Example Input-----\n2\n2 3\n2 6\n\n-----Example Output-----\n4\n5\n\n-----Explanation-----\nExample case 1: We can hire a team of $3$ workers for task $1$ and $1$ worker for task $2$. The one-man team working on task $2$ completes it and submits the result for approval on each day, but it is rejected on the first and second day. On the third day, the team working on task $1$ also completes their task, so the project gets approved after exactly $3$ days.\nExample case 2: We can hire a team of $3$ workers for task $1$ and a team of $2$ workers for task $2$.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfrom math import log2;\nimport bisect;\nfrom bisect import bisect_left,bisect_right\nimport sys;\nfrom math import gcd,sqrt\nsys.setrecursionlimit(10**7)\nfrom collections import defaultdict\ninf=float(\"inf\")\n# n=int(input())\n# n,m=map(int,input().split())\n# l=list(map(int,input().split()))\ndef get_factors(x):\n if x==1:\n return [];\n sqrta=int(sqrt(x))+1\n for i in range(2,sqrta):\n if x%i==0:\n return [i]+get_factors(x//i)\n return [x]\ndef min_generator(fac,k,index,new_list):\n if index==len(fac):\n return sum(new_list)\n mina=inf;\n for i in range(0,min(index+1,len(new_list))):\n new_list[i]*=fac[index]\n theta=min_generator(fac,k,index+1,new_list)\n if theta=b2 and a2<=b1:\n print(\"yes\")\n else:\n print(\"no\")\n elif (x1==x2)and(x1==x3)and(x1==x4):\n a1=max(y1,y2);a2=min(y1,y2)\n b1=max(y3,y4);b2=min(y3,y4)\n if a1>=b2 and a2<=b1:\n print(\"yes\")\n else:\n print(\"no\")\n else:\n print(\"no\")\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '4\\n2 1 8 1\\n11 1 7 1\\n2 1 8 1\\n11 1 9 1\\n2 1 8 1\\n3 1 3 -2\\n2 1 8 1\\n2 1 2 -2\\n', 'output': 'yes\\nno\\nno\\nyes\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/SAMESNAK'}","problem_id":"vfc_2986","program":"```python\n# cook your dish here\nt=int(input())\nfor _ in range(t):\n x1,y1,x2,y2=map(int,input().split())\n x3,y3,x4,y4=map(int,input().split())\n if (x1==x3 and y1==y3)or(x2==x4 and y2==y4):\n print(\"yes\")\n elif (x1==x4 and y1==y4)or(x2==x3 and y2==y3):\n print(\"yes\")\n else:\n if(y1==y2)and(y1==y3)and(y1==y4):\n a1=max(x1,x2);a2=min(x1,x2)\n b1=max(x3,x4);b2=min(x3,x4)\n if a1>=b2 and a2<=b1:\n print(\"yes\")\n else:\n print(\"no\")\n elif (x1==x2)and(x1==x3)and(x1==x4):\n a1=max(y1,y2);a2=min(y1,y2)\n b1=max(y3,y4);b2=min(y3,y4)\n if a1>=b2 and a2<=b1:\n print(\"yes\")\n else:\n print(\"no\")\n else:\n print(\"no\")\n```","inputs":"4\n2 1 8 1\n11 1 7 1\n2 1 8 1\n11 1 9 1\n2 1 8 1\n3 1 3 -2\n2 1 8 1\n2 1 2 -2\n","output":"yes\nno\nno\nyes\n","actual_output":"yes\nno\nno\nyes\n","execution_success":true,"sample_index":636},{"source":"apps","task_type":"verifiable_code","in_source_id":"1037","prompt":"Solve the following coding problem using the programming language python:\n\nAda is playing pawn chess with Suzumo.\nPawn chess is played on a long board with N$N$ squares in one row. Initially, some of the squares contain pawns.\nNote that the colours of the squares and pawns do not matter in this game, but otherwise, the standard chess rules apply:\n- no two pawns can occupy the same square at the same time\n- a pawn cannot jump over another pawn (they are no knights!), i.e. if there is a pawn at square i$i$, then it can only be moved to square i\u22122$i-2$ if squares i\u22121$i-1$ and i\u22122$i-2$ are empty\n- pawns cannot move outside of the board (outs are forbidden)\nThe players alternate turns; as usual, Ada plays first. In each turn, the current player must choose a pawn and move it either one or two squares to the left of its current position. The player that cannot make a move loses.\nCan Ada always beat Suzumo? Remember that Ada is a chess grandmaster, so she always plays optimally.\n\n-----Input-----\n- 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.\n- The first and only line of each test case contains a single string S$S$ with length N$N$ describing the initial board from left to right. An empty square and a square containing a pawn are denoted by the characters '.' and 'P' respectively.\n\n-----Output-----\nFor each test case, print a single line containing the string \"Yes\" if Ada wins the game or \"No\" otherwise (without quotes).\n\n-----Constraints-----\n- 1\u2264T\u2264500$1 \\le T \\le 500$\n- 2\u2264N\u2264128$2 \\le N \\le 128$\n- S$S$ contains only characters '.' and 'P'\n\n-----Example Input-----\n1\n..P.P\n\n-----Example Output-----\nYes\n\n-----Explanation-----\nExample case 1: Ada can move the first pawn two squares to the left; the board after this move looks like\nP...P\n\nand now, Suzumo can only move the second pawn. If he moves it one square to the left, Ada will move it two squares to the left on her next move, and if he moves it two squares to the left, Ada will move it one square to the left, so the board after Ada's next move will look like\nPP...\n\nand Suzumo cannot make any move here.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfor _ in range(int(input())):\n s = input().strip()\n a = []\n last = 0\n for i in range(len(s)):\n if s[i] == 'P':\n a.append(i - last)\n last = i + 1\n x = 0\n a = a[::-1]\n for v in a[::2]:\n x ^= v % 3\n print('Yes' if x else 'No')\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n..P.P\\n', 'output': 'Yes\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/ADAPWNS'}","problem_id":"vfc_2990","program":"```python\nfor _ in range(int(input())):\n s = input().strip()\n a = []\n last = 0\n for i in range(len(s)):\n if s[i] == 'P':\n a.append(i - last)\n last = i + 1\n x = 0\n a = a[::-1]\n for v in a[::2]:\n x ^= v % 3\n print('Yes' if x else 'No')\n```","inputs":"1\n..P.P\n","output":"Yes\n","actual_output":"Yes\n","execution_success":true,"sample_index":637},{"source":"apps","task_type":"verifiable_code","in_source_id":"1038","prompt":"Solve the following coding problem using the programming language python:\n\nTwo's company, three's a crowd!\nIt's been one year since Chef met his brother. Last year, his younger brother came to visit him during this time of the year. This year, the Chef is planning to go visit his brother. Chef's brother has planned to throw a \"Welcome Party\" for him. He wants to invite people from his neighbourhood (i.e. from the street where he lives). There are N houses on the street in a single line (not considering the brother's house). He wants the party to be fun and he will not like to invite people who might spoil the mood of the party. If people are invited from three consecutive houses on the street, they might create trouble. As they say, three's a crowd! He doesn't want to ruin the Chef's Welcome Party and so he will not want to send invites to any three consecutive houses. He wants you to tell him how many ways are there for him to go wrong. Note that he can play safe by not inviting anyone to avoid a crowd.\n\n-----Input:-----\nFirst line of the input contains a single integer T, the number of test cases.\n\nEach test case contains a line containing a single integer N described above.\n\n-----Output:-----\nFor each test case output a single integer denoting the number of ways the brother can go wrong with planning the party.\n\nThe answer can get quite large. So output the total number of ways modulo 109+7.\n\n-----Constraints:-----\n1<=T<=10000\n1<=N<=1015\n\n-----Example:-----Input:\n2\n3\n4\n\nOutput:\n1\n3\n\nExplanation:\nCase 1: The only way he can go wrong is by inviting all the houses.\nCase 2: First way of getting wrong is by inviting houses (1,2,3). Second way to get wrong is by inviting houses (2,3,4). Third way of going wrong is by inviting all 4 houses i.e. (1,2,3,4).\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nMOD = int(1e9+7)\n\ndef mult(a, b):\n rsp = [[0, 0, 0],\n [0, 0, 0],\n [0, 0, 0]]\n\n for i in range(3):\n for j in range(3):\n for k in range(3):\n rsp[i][j] += a[i][k] * b[k][j]\n rsp[i][j] %= MOD\n\n return rsp\n\nident = [[1, 0, 0],\n [0, 1, 0],\n [0, 0, 1]]\nm = [[1, 1, 0],\n [1, 0, 1],\n [1, 0, 0]]\n\npowers = [m]\nfor _ in range(53):\n p = powers[-1]\n powers.append(mult(p ,p))\n\ndef pow2(e):\n y = ident\n i = 0\n for p in powers:\n if e & (1 << i):\n y = mult(p, y)\n i += 1\n return y\n\nt = eval(input())\n\nfor _ in range(t):\n n = eval(input())\n\n if n < 3:\n print(0)\n continue\n\n r = pow(2, n, MOD)\n b = pow2(n - 2)\n # print(b)\n r -= (4 * b[0][0]) % MOD\n r -= (2 * b[1][0]) % MOD\n r -= b[2][0]\n r = (MOD + r) % MOD\n print(r)\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n3\\n4\\n', 'output': '1\\n3\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/CROWD'}","problem_id":"vfc_2994","program":"```python\nMOD = int(1e9+7)\n\ndef mult(a, b):\n rsp = [[0, 0, 0],\n [0, 0, 0],\n [0, 0, 0]]\n\n for i in range(3):\n for j in range(3):\n for k in range(3):\n rsp[i][j] += a[i][k] * b[k][j]\n rsp[i][j] %= MOD\n\n return rsp\n\nident = [[1, 0, 0],\n [0, 1, 0],\n [0, 0, 1]]\nm = [[1, 1, 0],\n [1, 0, 1],\n [1, 0, 0]]\n\npowers = [m]\nfor _ in range(53):\n p = powers[-1]\n powers.append(mult(p ,p))\n\ndef pow2(e):\n y = ident\n i = 0\n for p in powers:\n if e & (1 << i):\n y = mult(p, y)\n i += 1\n return y\n\nt = eval(input())\n\nfor _ in range(t):\n n = eval(input())\n\n if n < 3:\n print(0)\n continue\n\n r = pow(2, n, MOD)\n b = pow2(n - 2)\n # print(b)\n r -= (4 * b[0][0]) % MOD\n r -= (2 * b[1][0]) % MOD\n r -= b[2][0]\n r = (MOD + r) % MOD\n print(r)\n\n```","inputs":"2\n3\n4\n","output":"1\n3\n","actual_output":"1\n3\n","execution_success":true,"sample_index":638},{"source":"apps","task_type":"verifiable_code","in_source_id":"1039","prompt":"Solve the following coding problem using the programming language python:\n\n\u201cI am not in danger, Skyler. I am the danger. A guy opens his door and gets shot, and you think that of me? No! I am the one who knocks!\u201d\nSkyler fears Walter and ponders escaping to Colorado. Walter wants to clean his lab as soon as possible and then go back home to his wife. \nIn order clean his lab, he has to achieve cleaning level of lab as $Y$. The current cleaning level of the lab is $X$. \nHe must choose one positive odd integer $a$ and one positive even integer $b$. Note that, he cannot change $a$ or $b$ once he starts cleaning.\nHe can perform any one of the following operations for one round of cleaning: \n- Replace $X$ with $X+a$. \n- Replace $X$ with $X-b$.\nFind minimum number of rounds (possibly zero) to make lab clean.\n\n-----Input:-----\n- First line will contain $T$, number of test cases. $T$ testcases follow : \n- Each test case contains two space separated integers $X, Y$. \n\n-----Output:-----\nFor each test case, output an integer denoting minimum number of rounds to clean the lab.\n\n-----Constraints-----\n- $1 \\leq T \\leq 10^5$\n- $ |X|,|Y| \\leq 10^9$\n\n-----Sample Input:-----\n3\n0 5\n4 -5\n0 10000001\n\n-----Sample Output:-----\n1\n2\n1\n\n-----EXPLANATION:-----\n- \nFor the first testcase, you can convert $X$ to $Y$ by choosing $a=5$ and $b=2$.\n\nIt will cost minimum of $1$ cleaning round. You can select any other combination of $a, b$ satisfying above condition but will take minimum of $1$ cleaning round in any case.\n- \nFor the second testcase, you can convert $X$ to $Y$ by choosing $a=1$ and $b=10$. In first round they will replace $X$ to $X+a$ and then in second round replace to $X-b$. You can perform only one operation in one round.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nt=int(input())\nfor i in range(t):\n ans=0\n x,y=list(map(int,input().split()))\n if y>x:\n if (y-x)%4==0:ans=3\n elif (y-x)%2==0: ans=2\n else: ans=1\n if yx:\n if (y-x)%4==0:ans=3\n elif (y-x)%2==0: ans=2\n else: ans=1\n if y0:\n print('YES')\n else:\n print('NO')\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n10 2\\nhelloworld\\n1 3\\n1 10\\n', 'output': 'NO\\nYES\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/RICHSTR'}","problem_id":"vfc_3002","program":"```python\nt=int(input())\n\nfor _ in range(t):\n n,q=map(int,input().split())\n s=input()\n l=[0]*(n-1)\n for i in range(n-2):\n a,b,c=s[i],s[i+1],s[i+2]\n if len(set([a,b,c]))<3:\n l[i]=l[i-1]+1\n else:\n l[i]=l[i-1]\n \n for i in range(q):\n left,right=map(int,input().split())\n left-=1\n right-=1\n if right-left+1 <3:\n print('NO')\n continue\n if (l[right-2]-l[left-1])>0:\n print('YES')\n else:\n print('NO')\n```","inputs":"1\n10 2\nhelloworld\n1 3\n1 10\n","output":"NO\nYES\n","actual_output":"NO\nYES\n","execution_success":true,"sample_index":640},{"source":"apps","task_type":"verifiable_code","in_source_id":"1041","prompt":"Solve the following coding problem using the programming language python:\n\nRipul was skilled in the art of lapidary. He used to collect stones and convert it into decorative items for sale. There were n stone shops. Each shop was having one exclusive stone of value s[i] , where 1<=i<=n. If number of stones collected are more than 1, then total value will be product of values of all the stones he collected. Ripul wants to have maximum value of stones he collected. Help Ripul in picking up the subarray which leads to maximum value of stones he collected.\n\n-----Input:-----\n- First line will contain $T$, number of testcases. Then the testcases follow. \n- The first line of each testcase contains an integer $N$, denoting number of elements in the given array.\n- The second line contains $N$ space-separated integers $S1$, $S2$, \u2026, $SN$ denoting the value of stone in each shop. \n\n-----Output:-----\nFor each testcase, output the maximum value of stones possible, the starting index and ending index of the chosen subarray (0-based indexing). If there are multiple subarrays with same value, print the one with greater starting index. If there are multiple answer subarrays with same starting index, print the one with greater ending index. (The answer will fit in 64 bit binary number).\n\n-----Constraints-----\n- $1 \\leq T \\leq 10$\n- $1 \\leq N \\leq 10^5$\n- $-100 \\leq S[i] \\leq 100$\n\n-----Subtasks-----\n- 30 points : $1 \\leq N \\leq 10^3$\n- 70 points : $1 \\leq N \\leq 10^5$\n\n-----Sample Input:-----\n1\n3\n\n1 2 3\n\n-----Sample Output:-----\n6 1 2\n\n-----EXPLANATION:-----\nIf Ripul collects all the all the three gems, total value will be 6 (1 * 2 * 3).\nIf Ripul collects last two gems, total value will be 6 (1 * 2 * 3).\nSo, he picks the subarray with greater starting index.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\nfor u in range(int(input())):\n n=int(input())\n l=list(map(int,input().split()))\n d=[]\n dd=[]\n s=1\n for i in range(n-1):\n s=l[i]\n d.append(s)\n dd.append([i,i])\n for j in range(i+1,n):\n s=s*l[j]\n d.append(s)\n dd.append([i,j])\n d.append(l[n-1])\n dd.append([n-1,n-1])\n k=len(d)\n m=max(d)\n x,y=0,0\n for i in range(k):\n if(d[i]==m):\n x=dd[i]\n print(m,*x)\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n3\\n1 2 3\\n', 'output': '6 1 2\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/COH12020/problems/RIPUGEMS'}","problem_id":"vfc_3006","program":"```python\n# cook your dish here\nfor u in range(int(input())):\n n=int(input())\n l=list(map(int,input().split()))\n d=[]\n dd=[]\n s=1\n for i in range(n-1):\n s=l[i]\n d.append(s)\n dd.append([i,i])\n for j in range(i+1,n):\n s=s*l[j]\n d.append(s)\n dd.append([i,j])\n d.append(l[n-1])\n dd.append([n-1,n-1])\n k=len(d)\n m=max(d)\n x,y=0,0\n for i in range(k):\n if(d[i]==m):\n x=dd[i]\n print(m,*x)\n\n```","inputs":"1\n3\n1 2 3\n","output":"6 1 2\n","actual_output":"6 1 2\n","execution_success":true,"sample_index":641},{"source":"apps","task_type":"verifiable_code","in_source_id":"1042","prompt":"Solve the following coding problem using the programming language python:\n\nChef wants to gift pairs to his friends this new year. But his friends like good pairs\nonly.\nA pair (a , b) is called a good pair if 1 <= a < b <= N such that GCD(a*b , P) = 1.\nSince Chef is busy in preparation for the party, he wants your help to find all the\ngood pairs.\n\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\nINPUT\n\u2022 The first line of the input contains a single integer T.\n\u2022 The first and only line of each test case contain two integer N,P.\n\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\nOUTPUT\nFor each test case, print a single line containing one integer \u2014 the total number of good\npairs\n\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\nCONSTRAINTS\n\u2022 1 \u2264 T\u2264 50\n\u2022 2 \u2264 N,P \u226410^5\n\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\nExample Input\n2\n2 3\n3 3\n\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\nExample Output\n1\n1\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\n \ndef G(x, y): \n while(y): \n x, y = y, x % y \n return x \n# t=int(input())\n# l=list(map(int,input().split()))\nfor _ in range(int(input())):\n n,p=map(int,input().split())\n\n c=0\n for i in range(1,n+1):\n if G(i,p)==1:\n c+=1\n ans=c*(c-1)//2\n print(ans)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n2 3\\n3 3\\n\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\\n', 'output': '1\\n1\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/NITJ2021/problems/CIN004'}","problem_id":"vfc_3010","program":"```python\n# cook your dish here\n \ndef G(x, y): \n while(y): \n x, y = y, x % y \n return x \n# t=int(input())\n# l=list(map(int,input().split()))\nfor _ in range(int(input())):\n n,p=map(int,input().split())\n\n c=0\n for i in range(1,n+1):\n if G(i,p)==1:\n c+=1\n ans=c*(c-1)//2\n print(ans)\n```","inputs":"2\n2 3\n3 3\n\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\n","output":"1\n1\n","actual_output":"1\n1\n","execution_success":true,"sample_index":642},{"source":"apps","task_type":"verifiable_code","in_source_id":"1044","prompt":"Solve the following coding problem using the programming language python:\n\nYou're given an integer N. Write a program to calculate the sum of all the digits of N. \n\n-----Input-----\n\nThe first line contains an integer T, the total number of testcases. Then follow T lines, each line contains an integer N. \n\n-----Output-----\nFor each test case, calculate the sum of digits of N, and display it in a new line.\n\n-----Constraints-----\n- 1 \u2264 T \u2264 1000\n- 1 \u2264 N \u2264 1000000\n\n-----Example-----\nInput\n3 \n12345\n31203\n2123\nOutput\n15\n9\n8\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\nnumber = int(input())\nfor i in range(number):\n a = list(input())\n for k in range(len(a)):\n a[k] = eval(a[k])\n print(sum(a))\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\n12345\\n31203\\n2123\\n', 'output': '15\\n9\\n8\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/FLOW006'}","problem_id":"vfc_3018","program":"```python\n# cook your dish here\nnumber = int(input())\nfor i in range(number):\n a = list(input())\n for k in range(len(a)):\n a[k] = eval(a[k])\n print(sum(a))\n```","inputs":"3\n12345\n31203\n2123\n","output":"15\n9\n8\n","actual_output":"15\n9\n8\n","execution_success":true,"sample_index":644},{"source":"apps","task_type":"verifiable_code","in_source_id":"1045","prompt":"Solve the following coding problem using the programming language python:\n\nYou are given Name of chef's friend and using chef's new method of calculating value of string , chef have to find the value of all the names. Since chef is busy , he asked you to do the work from him .\nThe method is a function $f(x)$ as follows - \n- \n$f(x)$ = $1$ , if $x$ is a consonent\n- \n$f(x)$ = $0$ , if $x$ is a vowel \nYour task is to apply the above function on all the characters in the string $S$ and convert the obtained binary string in decimal number N. Since the number N can be very large, compute it modulo $10^9+7$ .\nInput:\n- First line will contain $T$, number of testcases. Then the testcases follow. \n- Each test line contains one String $S$ composed of lowercase English alphabet letters. \n\n-----Output:-----\nFor each case, print a single line containing one integer $N$ modulo $10^9+7$ .\n\n-----Constraints-----\n- $1 \\leq T \\leq 50$\n- $1 \\leq |S| \\leq 10^5$\n\n-----Sample Input:-----\n1\ncodechef\n\n-----Sample Output:-----\n173\n\n-----EXPLANATION:-----\nThe string \"codechef\" will be converted to 10101101 ,using the chef's method function . Which is equal to 173.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n\n\nvow = ['a', 'e', 'i','o', 'u']\nfor _ in range(int(input())):\n name = str(input())\n tmp = ''\n for i in range(len(name)):\n if name[i] not in vow and name[i].isalpha():\n tmp+='1'\n elif name[i] in vow and name[i].isalpha():\n tmp+='0'\n \n print( int(tmp, 2)% (10**9 + 7))\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\ncodechef\\n', 'output': '173\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/LDT42020/problems/NAMEVAL'}","problem_id":"vfc_3022","program":"```python\n\n\nvow = ['a', 'e', 'i','o', 'u']\nfor _ in range(int(input())):\n name = str(input())\n tmp = ''\n for i in range(len(name)):\n if name[i] not in vow and name[i].isalpha():\n tmp+='1'\n elif name[i] in vow and name[i].isalpha():\n tmp+='0'\n \n print( int(tmp, 2)% (10**9 + 7))\n```","inputs":"1\ncodechef\n","output":"173\n","actual_output":"173\n","execution_success":true,"sample_index":645},{"source":"apps","task_type":"verifiable_code","in_source_id":"1046","prompt":"Solve the following coding problem using the programming language python:\n\nBears love candies and games involving eating them. Limak and Bob play the following game. Limak eats 1 candy, then Bob eats 2 candies, then Limak eats 3 candies, then Bob eats 4 candies, and so on. Once someone can't eat what he is supposed to eat, he loses.\nLimak can eat at most A candies in total (otherwise he would become sick), while Bob can eat at most B candies in total.\nWho will win the game?\nPrint \"Limak\" or \"Bob\" accordingly.\n\n-----Input-----\nThe first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.\nThe only line of each test case contains two integers A and B denoting the maximum possible number of candies Limak can eat and the maximum possible number of candies Bob can eat respectively.\n\n-----Output-----\nFor each test case, output a single line containing one string \u2014 the name of the winner (\"Limak\" or \"Bob\" without the quotes).\n\n-----Constraints-----\n- 1 \u2264 T \u2264 1000\n- 1 \u2264 A, B \u2264 1000\n\n-----Example-----\nInput:\n10\n3 2\n4 2\n1 1\n1 2\n1 3\n9 3\n9 11\n9 12\n9 1000\n8 11\n\nOutput:\nBob\nLimak\nLimak\nBob\nBob\nLimak\nLimak\nBob\nBob\nBob\n\n-----Explanation-----\nTest case 1. We have A = 3 and B = 2. Limak eats 1 candy first, and then Bob eats 2 candies. Then Limak is supposed to eat 3 candies but that would mean 1 + 3 = 4 candies in total. It's impossible because he can eat at most A candies, so he loses. Bob wins, and so we print \"Bob\".\nTest case 2. Now we have A = 4 and B = 2. Limak eats 1 candy first, and then Bob eats 2 candies, then Limak eats 3 candies (he has 1 + 3 = 4 candies in total, which is allowed because it doesn't exceed A). Now Bob should eat 4 candies but he can't eat even a single one (he already ate 2 candies). Bob loses and Limak is the winner.\nTest case 8. We have A = 9 and B = 12. The game looks as follows:\n- Limak eats 1 candy.\n- Bob eats 2 candies.\n- Limak eats 3 candies (4 in total).\n- Bob eats 4 candies (6 in total).\n- Limak eats 5 candies (9 in total).\n- Bob eats 6 candies (12 in total).\n- Limak is supposed to eat 7 candies but he can't \u2014 that would exceed A. Bob wins.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfor t in range(int(input())):\n limakMax, bobMax = list(map(int, input().split()))\n limakEat = 0; bobEat = 0\n eating = 1\n while limakEat <= limakMax or bobEat <= bobMax:\n\n if eating % 2 != 0 and limakEat <= limakMax:\n limakEat += eating\n eating += 1\n if limakEat > limakMax:\n print(\"Bob\")\n break\n elif eating % 2 == 0 and bobEat <= bobMax:\n bobEat += eating\n eating += 1\n if bobEat > bobMax:\n print(\"Limak\")\n break\n\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '10\\n3 2\\n4 2\\n1 1\\n1 2\\n1 3\\n9 3\\n9 11\\n9 12\\n9 1000\\n8 11\\n', 'output': 'Bob\\nLimak\\nLimak\\nBob\\nBob\\nLimak\\nLimak\\nBob\\nBob\\nBob\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/CANDY123'}","problem_id":"vfc_3026","program":"```python\nfor t in range(int(input())):\n limakMax, bobMax = list(map(int, input().split()))\n limakEat = 0; bobEat = 0\n eating = 1\n while limakEat <= limakMax or bobEat <= bobMax:\n\n if eating % 2 != 0 and limakEat <= limakMax:\n limakEat += eating\n eating += 1\n if limakEat > limakMax:\n print(\"Bob\")\n break\n elif eating % 2 == 0 and bobEat <= bobMax:\n bobEat += eating\n eating += 1\n if bobEat > bobMax:\n print(\"Limak\")\n break\n\n\n```","inputs":"10\n3 2\n4 2\n1 1\n1 2\n1 3\n9 3\n9 11\n9 12\n9 1000\n8 11\n","output":"Bob\nLimak\nLimak\nBob\nBob\nLimak\nLimak\nBob\nBob\nBob\n","actual_output":"Bob\nLimak\nLimak\nBob\nBob\nLimak\nLimak\nBob\nBob\nBob\n","execution_success":true,"sample_index":646},{"source":"apps","task_type":"verifiable_code","in_source_id":"1047","prompt":"Solve the following coding problem using the programming language python:\n\nChef bought a huge (effectively infinite) planar island and built $N$ restaurants (numbered $1$ through $N$) on it. For each valid $i$, the Cartesian coordinates of restaurant $i$ are $(X_i, Y_i)$.\nNow, Chef wants to build $N-1$ straight narrow roads (line segments) on the island. The roads may have arbitrary lengths; restaurants do not have to lie on the roads. The slope of each road must be $1$ or $-1$, i.e. for any two points $(x_1, y_1)$ and $(x_2, y_2)$ on the same road, $|x_1-x_2| = |y_1-y_2|$ must hold.\nLet's denote the minimum distance Chef has to walk from restaurant $i$ to reach a road by $D_i$. Then, let's denote $a = \\mathrm{max}\\,(D_1, D_2, \\ldots, D_N)$; Chef wants this distance to be minimum possible.\nChef is a busy person, so he decided to give you the job of building the roads. You should find a way to build them that minimises $a$ and compute $a \\cdot \\sqrt{2}$.\n\n-----Input-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The first line of each test case contains a single integer $N$.\n- $N$ lines follow. For each valid $i$, the $i$-th of these lines contains two space-separated integers $X_i$ and $Y_i$.\n\n-----Output-----\nFor each test case, print a single line containing one real number \u2014 the minimum distance $a$ multiplied by $\\sqrt{2}$. Your answer will be considered correct if its absolute or relative error does not exceed $10^{-6}$.\n\n-----Constraints-----\n- $1 \\le T \\le 100$\n- $2 \\le N \\le 10^4$\n- $|X_i|, |Y_i| \\le 10^9$ for each valid $i$\n\n-----Subtasks-----\nSubtask #1 (10 points):\n- $1 \\le T \\le 10$\n- $2 \\le N \\le 5$\n- $|X_i|, |Y_i| \\le 10$ for each valid $i$\n- $a \\cdot \\sqrt{2}$ is an integer\nSubtask #2 (90 points): original constraints\n\n-----Example Input-----\n2\n3\n0 0\n0 1\n0 -1\n3\n0 1\n1 0\n-1 0\n\n-----Example Output-----\n0.5\n0\n\n-----Explanation-----\nExample case 1: We should build roads described by equations $y-x+0.5 = 0$ and $y-x-0.5 = 0$.\nExample case 2: We should build roads described by equations $y-x-1 = 0$ and $y+x-1 = 0$.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nimport sys\n\ndef input(): return sys.stdin.readline().strip()\ndef iinput(): return int(input())\ndef rinput(): return list(map(int, sys.stdin.readline().strip().split())) \ndef get_list(): return list(map(int, sys.stdin.readline().strip().split()))\n\n\nt=iinput()\n\nfor _ in range(t):\n n=iinput()\n p=[]\n mi=[]\n for i in range(n):\n x,y=rinput()\n p.append(x+y)\n mi.append(x-y)\n\n p.sort()\n mi.sort()\n m=float('inf')\n for i in range(1,n):\n if(p[i]-p[i-1]\" , which she will use on the design of her language, L++ :D.\nShe is using it as an abstraction for generating XML code Tags in an easier fashion and she understood that, for an expression to be valid, a \"<\" symbol must always have a corresponding \">\" character somewhere (not necessary immediately) after it. Moreover, each \">\" symbol should correspond to exactly one \"<\" symbol.\nSo, for instance, the instructions:\n<<>> \n<> \n<><> \nare all valid. While:\n>> \n><>< \nare not.\nGiven some expressions which represent some instructions to be analyzed by Lira's compiler, you should tell the length of the longest prefix of each of these expressions that is valid, or 0 if there's no such a prefix.\n\n-----Input-----\nInput will consist of an integer T denoting the number of test cases to follow.\nThen, T strings follow, each on a single line, representing a possible expression in L++.\n\n-----Output-----\nFor each expression you should output the length of the longest prefix that is valid or 0 if there's no such a prefix. \n\n\n-----Constraints-----\n- 1 \u2264 T \u2264 500\n- 1 \u2264 The length of a single expression \u2264 106\n- The total size all the input expressions is no more than 5*106\n\n-----Example-----\nInput:\n3\n<<>>\n><\n<>>>\nOutput:\n4\n0\n2\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\nt=int(input())\nfor j in range(t):\n s=input()\n st=[]\n ans=0\n\n for i in range(len(s)):\n \n if(s[i]=='>'):\n if(len(st)!=0 and st[-1]=='<'):\n st.pop()\n if(len(st)==0):\n ans=i+1\n else:\n break\n\n else:\n st.append('<')\n\n print(ans)\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\n<<>>\\n><\\n<>>>\\n\\n', 'output': '4\\n0\\n2\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/COMPILER'}","problem_id":"vfc_3042","program":"```python\n# cook your dish here\nt=int(input())\nfor j in range(t):\n s=input()\n st=[]\n ans=0\n\n for i in range(len(s)):\n \n if(s[i]=='>'):\n if(len(st)!=0 and st[-1]=='<'):\n st.pop()\n if(len(st)==0):\n ans=i+1\n else:\n break\n\n else:\n st.append('<')\n\n print(ans)\n\n```","inputs":"3\n<<>>\n><\n<>>>\n\n","output":"4\n0\n2\n","actual_output":"4\n0\n2\n","execution_success":true,"sample_index":650},{"source":"apps","task_type":"verifiable_code","in_source_id":"1051","prompt":"Solve the following coding problem using the programming language python:\n\nThe 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.\n\n-----Input:-----\n- First-line will contain $T$, the number of test cases. Then the test cases follow. \n- Each test case contains a single line of input, one integer $K$. \n\n-----Output:-----\nFor each test case, output as the pattern.\n\n-----Constraints-----\n- $1 \\leq T \\leq 100$\n- $1 \\leq K \\leq 100$\n\n-----Sample Input:-----\n3\n2\n3\n4\n\n-----Sample Output:-----\n0\n*1\n**2\n0\n*1\n**2\n***3\n0\n*1\n**2\n***3\n****4\n\n-----EXPLANATION:-----\nNo need, else pattern can be decode easily.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\nt=int(input())\nfor i in range(0,t):\n my_ip = int(input().strip())\n for xyz in range(my_ip+1):\n for abc in range(0,xyz+1):\n if abc == xyz:\n print(xyz,end=\"\")\n else:\n print('*',end=\"\")\n\n print()\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\n2\\n3\\n4\\n\\n', 'output': '0\\n*1\\n**2\\n0\\n*1\\n**2\\n***3\\n0\\n*1\\n**2\\n***3\\n****4\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/PTRN2020/problems/ITGUY38'}","problem_id":"vfc_3046","program":"```python\n# cook your dish here\nt=int(input())\nfor i in range(0,t):\n my_ip = int(input().strip())\n for xyz in range(my_ip+1):\n for abc in range(0,xyz+1):\n if abc == xyz:\n print(xyz,end=\"\")\n else:\n print('*',end=\"\")\n\n print()\n```","inputs":"3\n2\n3\n4\n\n","output":"0\n*1\n**2\n0\n*1\n**2\n***3\n0\n*1\n**2\n***3\n****4\n","actual_output":"0\n*1\n**2\n0\n*1\n**2\n***3\n0\n*1\n**2\n***3\n****4\n","execution_success":true,"sample_index":651},{"source":"apps","task_type":"verifiable_code","in_source_id":"1052","prompt":"Solve the following coding problem using the programming language python:\n\nYou are given positive integers $N$ and $D$. You may perform operations of the following two types:\n- add $D$ to $N$, i.e. change $N$ to $N+D$\n- change $N$ to $\\mathop{\\mathrm{digitsum}}(N)$\nHere, $\\mathop{\\mathrm{digitsum}}(x)$ is the sum of decimal digits of $x$. For example, $\\mathop{\\mathrm{digitsum}}(123)=1+2+3=6$, $\\mathop{\\mathrm{digitsum}}(100)=1+0+0=1$, $\\mathop{\\mathrm{digitsum}}(365)=3+6+5=14$.\nYou may perform any number of operations (including zero) in any order. Please find the minimum obtainable value of $N$ and the minimum number of operations required to obtain this value.\n\n-----Input-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The first and only line of each test case contains two space-separated integers $N$ and $D$.\n\n-----Output-----\nFor each test case, print a single line containing two space-separated integers \u2014 the minimum value of $N$ and the minimum required number of operations.\n\n-----Constraints-----\n- $1 \\le T \\le 10$\n- $1 \\le N, D \\le 10^{10}$\n\n-----Subtasks-----\nSubtask #1 (30 points): $1 \\le N, D \\le 100$\nSubtask #2 (70 points): original constraints\n\n-----Example Input-----\n3\n2 1\n9 3\n11 13\n\n-----Example Output-----\n1 9\n3 2\n1 4\n\n-----Explanation-----\nExample case 1: The value $N=1$ can be achieved by 8 successive \"add\" operations (changing $N$ to $10$) and one \"digit-sum\" operation.\nExample case 2: You can prove that you cannot obtain $N=1$ and $N=2$, and you can obtain $N=3$.\nThe value $N=3$ can be achieved by one \"add\" and one \"digitsum\" operation, changing $9$ to $12$ and $12$ to $3$. \nExample case 3: $N=1$ can be achieved by operations \"add\", \"add\", \"digitsum\", \"digitsum\": $11 \\rightarrow 24 \\rightarrow 37 \\rightarrow 10 \\rightarrow 1$.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfrom collections import deque \r\nT=int(input())\r\ndef break_down(num):\r\n count=0\r\n while(len(num)!=1):\r\n temp=0\r\n for i in range(0,len(num)):\r\n temp=temp+int(num[i])\r\n num=str(temp)\r\n count=count+1\r\n return (int(num),count)\r\ndef digit_sum(num):\r\n temp=0\r\n for i in range(0,len(num)):\r\n temp=temp+int(num[i])\r\n num=temp\r\n return (num)\r\nwhile(T):\r\n queue=deque()\r\n count_n=0\r\n count_d=0\r\n T=T-1\r\n N,d=[i for i in input().split()]\r\n n,count_n=break_down(N)\r\n D,count_D=break_down(d)\r\n dic={}\r\n if(D==1 or D==2 or D==4 or D==5 or D==7 or D==8):\r\n mini=1 \r\n elif(D==3 or D==6):\r\n mini=min(digit_sum(str(n+3)),digit_sum(str(n+6)),digit_sum(str(n+9)))\r\n else:\r\n mini=n\r\n queue.append((int(N),0))\r\n ele=int(N)\r\n count=0\r\n while(len(queue)!=0):\r\n ele,count=queue.popleft()\r\n if(ele==mini):\r\n break\r\n else:\r\n if(len(str(ele))==1):\r\n temp1=ele+int(d)\r\n queue.append((temp1,count+1))\r\n else:\r\n temp2=digit_sum(str(ele))\r\n temp1=ele+int(d)\r\n queue.append((temp2,count+1))\r\n queue.append((temp1,count+1))\r\n print(ele,count)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\n2 1\\n9 3\\n11 13\\n\\n', 'output': '1 9\\n3 2\\n1 4\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/MINDSUM'}","problem_id":"vfc_3050","program":"```python\nfrom collections import deque \r\nT=int(input())\r\ndef break_down(num):\r\n count=0\r\n while(len(num)!=1):\r\n temp=0\r\n for i in range(0,len(num)):\r\n temp=temp+int(num[i])\r\n num=str(temp)\r\n count=count+1\r\n return (int(num),count)\r\ndef digit_sum(num):\r\n temp=0\r\n for i in range(0,len(num)):\r\n temp=temp+int(num[i])\r\n num=temp\r\n return (num)\r\nwhile(T):\r\n queue=deque()\r\n count_n=0\r\n count_d=0\r\n T=T-1\r\n N,d=[i for i in input().split()]\r\n n,count_n=break_down(N)\r\n D,count_D=break_down(d)\r\n dic={}\r\n if(D==1 or D==2 or D==4 or D==5 or D==7 or D==8):\r\n mini=1 \r\n elif(D==3 or D==6):\r\n mini=min(digit_sum(str(n+3)),digit_sum(str(n+6)),digit_sum(str(n+9)))\r\n else:\r\n mini=n\r\n queue.append((int(N),0))\r\n ele=int(N)\r\n count=0\r\n while(len(queue)!=0):\r\n ele,count=queue.popleft()\r\n if(ele==mini):\r\n break\r\n else:\r\n if(len(str(ele))==1):\r\n temp1=ele+int(d)\r\n queue.append((temp1,count+1))\r\n else:\r\n temp2=digit_sum(str(ele))\r\n temp1=ele+int(d)\r\n queue.append((temp2,count+1))\r\n queue.append((temp1,count+1))\r\n print(ele,count)\n```","inputs":"3\n2 1\n9 3\n11 13\n\n","output":"1 9\n3 2\n1 4\n","actual_output":"1 9\n3 2\n1 4\n","execution_success":true,"sample_index":652},{"source":"apps","task_type":"verifiable_code","in_source_id":"1053","prompt":"Solve the following coding problem using the programming language python:\n\nChef has a binary array in an unsorted manner. Cheffina challenges chef to find the transition point in the sorted (ascending) binary array. Here indexing is starting from 0.\nNote: Transition point always exists.\n\n-----Input:-----\n- First-line will contain $T$, the number of test cases. Then the test cases follow. \n- Each test case contains two lines of input, $N$.\n- N space-separated binary numbers. \n\n-----Output:-----\nFor each test case, output in a single line answer.\n\n-----Constraints-----\n- $1 \\leq T \\leq 10$\n- $1 \\leq N \\leq 10^5$\n\n-----Sample Input:-----\n1\n5\n0 1 0 0 1\n\n-----Sample Output:-----\n3\n\n-----EXPLANATION:-----\nbinary array in sorted form will look like = [0, 0, 0, 1, 1]\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\nfor _ in range(int(input())):\n n=int(input())\n A=list(map(int,input().split()))\n A.sort()\n for i in range(len(A)):\n if A[i]==1:\n print(i)\n break\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n5\\n0 1 0 0 1\\n\\n', 'output': '3\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/PSTR2020/problems/ANITGUY5'}","problem_id":"vfc_3054","program":"```python\n# cook your dish here\nfor _ in range(int(input())):\n n=int(input())\n A=list(map(int,input().split()))\n A.sort()\n for i in range(len(A)):\n if A[i]==1:\n print(i)\n break\n```","inputs":"1\n5\n0 1 0 0 1\n\n","output":"3\n","actual_output":"3\n","execution_success":true,"sample_index":653},{"source":"apps","task_type":"verifiable_code","in_source_id":"1054","prompt":"Solve the following coding problem using the programming language python:\n\nChef likes strings a lot but he likes palindromic strings even more. Today he found an old string s in his garage. The string is so old that some of its characters have faded and are unidentifiable now. Faded characters in the string are represented by '.' whereas other characters are lower case Latin alphabets i.e ['a'-'z'].\n\nChef being the palindrome lover decided to construct the lexicographically smallest palindrome by filling each of the faded character ('.') with a lower case Latin alphabet. Can you please help him completing the task?\n\n-----Input-----\nFirst line of input contains a single integer T denoting the number of test cases. T test cases follow.\nFirst and the only line of each case contains string s denoting the old string that chef has found in his garage.\n\n-----Output-----\nFor each test case, print lexicographically smallest palindrome after filling each faded character - if it possible to construct one. Print -1 otherwise.\n\n-----Constraints-----\n- 1 \u2264 T \u2264 50\n- 1 \u2264 |s| \u2264 12345\n- String s consists of ['a'-'z'] and '.' only.\n\n-----Subtasks-----Subtask #1 (47 points)\n- 1 \u2264 T \u2264 50, 1 \u2264 |S| \u2264 123\nSubtask #2 (53 points)\n- 1 \u2264 T \u2264 50, 1 \u2264 |S| \u2264 12345\n\n-----Example-----Input\n3\na.ba\ncb.bc\na.b\n\nOutput\nabba\ncbabc\n-1\n\n-----Explanation-----\nIn example 1, you can create a palindrome by filling the faded character by 'b'.\nIn example 2, you can replace the faded character by any character from 'a' to 'z'. We fill it by 'a', as it will generate the lexicographically smallest palindrome.\nIn example 3, it is not possible to make the string s a palindrome.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\ntest=int(input())\nfor i in range(test):\n s=input()\n b=len(s)\n list1=[]\n for j in range(len(s)):\n if s[j]=='.':\n list1.append(j)\n for i in list1:\n if b-i-1 in list1 :\n if i!=b-i-1 and ((s[i] and s[b-i-1]) != 'a' ):\n s=s[:i]+'a'+s[i+1:b-i-1]+'a'+s[b-i:]\n else:\n s=s[:i]+'a'+s[i+1:]\n else:\n s=s[:i]+s[b-i-1]+s[i+1:]\n\n if s==s[::-1]:\n print(s)\n else:\n print(-1)\n\n \n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\na.ba\\ncb.bc\\na.b\\n', 'output': 'abba\\ncbabc\\n-1\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/LEXOPAL'}","problem_id":"vfc_3058","program":"```python\ntest=int(input())\nfor i in range(test):\n s=input()\n b=len(s)\n list1=[]\n for j in range(len(s)):\n if s[j]=='.':\n list1.append(j)\n for i in list1:\n if b-i-1 in list1 :\n if i!=b-i-1 and ((s[i] and s[b-i-1]) != 'a' ):\n s=s[:i]+'a'+s[i+1:b-i-1]+'a'+s[b-i:]\n else:\n s=s[:i]+'a'+s[i+1:]\n else:\n s=s[:i]+s[b-i-1]+s[i+1:]\n\n if s==s[::-1]:\n print(s)\n else:\n print(-1)\n\n \n```","inputs":"3\na.ba\ncb.bc\na.b\n","output":"abba\ncbabc\n-1\n","actual_output":"abba\ncbabc\n-1\n","execution_success":true,"sample_index":654},{"source":"apps","task_type":"verifiable_code","in_source_id":"1055","prompt":"Solve the following coding problem using the programming language python:\n\nChef is planning a huge party for all of you and has ordered M pizzas. He wants to invite as many people to the party. However, he knows that everyone will have exactly one slice of a pizza (regardless of the size) and he wants to make sure that he has enough pizza slices. \nChef is very lazy and will only make a total of N straight cuts among all the pizzas. Each pizza is also of different size and to avoid the slices getting too small the chef can only make a max of Ai cuts to the ith pizza. He wants to maximize the number of slices of pizza. Since chef is busy with preparing other aspects of the party he wants you to find out the maximum number of slices he can get following the constraints. \nIf a pizza is not cut at all then it is considered as 1 slice. \n\n-----Input-----\nFirst line contains two integers M and N.\nThe second line of input contains the array A.\n\n-----Output-----\nOutput a single integer - the maximum number of slices chef can get.\n\n-----Constraints-----\n- 1 \u2264 M \u2264 2*105\n- 1 \u2264 N,Ai \u2264 2*105\n\n-----Subtasks-----\n- Subtask 1: 1 \u2264 M,N \u2264 100 - 10 points \n- Subtask 2: 1 \u2264 N \u2264 100, \n1 \u2264 M \u2264 105 - 20 points\n- Subtask 3: Original Constraints - 70 points\n\n-----Example-----\nInput:\n5 10\n1 2 3 4 5\nOutput:\n31\n\n-----Explanation-----\nExample case 1. One of the optimal way to cut would be to do {0, 1, 0, 4, 5} cuts.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\r\nm,n=[int(i) for i in input().split()]\r\narr=list(map(int,input().split()))\r\narr=sorted(arr,reverse=True)\r\nans=0\r\nw=0\r\nq=m\r\nfor m in range(q):\r\n if(arr[m]>n):\r\n w=1\r\n break \r\n ans+=1+(arr[m]*(arr[m]+1))//2\r\n n-=arr[m]\r\n\r\nif(n==0):\r\n print(ans)\r\nelse:\r\n if(w==1):\r\n print(ans+q-m+(n*(n+1))//2)\r\n else:\r\n print(ans)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '5 10\\n1 2 3 4 5\\n\\n', 'output': '31\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/PIZPAR'}","problem_id":"vfc_3062","program":"```python\n# cook your dish here\r\nm,n=[int(i) for i in input().split()]\r\narr=list(map(int,input().split()))\r\narr=sorted(arr,reverse=True)\r\nans=0\r\nw=0\r\nq=m\r\nfor m in range(q):\r\n if(arr[m]>n):\r\n w=1\r\n break \r\n ans+=1+(arr[m]*(arr[m]+1))//2\r\n n-=arr[m]\r\n\r\nif(n==0):\r\n print(ans)\r\nelse:\r\n if(w==1):\r\n print(ans+q-m+(n*(n+1))//2)\r\n else:\r\n print(ans)\n```","inputs":"5 10\n1 2 3 4 5\n\n","output":"31\n","actual_output":"31\n","execution_success":true,"sample_index":655},{"source":"apps","task_type":"verifiable_code","in_source_id":"1056","prompt":"Solve the following coding problem using the programming language python:\n\nWrite a program to check whether a triangle is valid or not, when the three angles of the triangle are the inputs. A triangle is valid if the sum of all the three angles is equal to 180 degrees.\n\n-----Input-----\n\nThe first line contains an integer T, the total number of testcases. Then T lines follow, each line contains three angles A, B and C, of the triangle separated by space. \n\n-----Output-----\nFor each test case, display 'YES' if the triangle is valid, and 'NO', if it is not, in a new line.\n\n-----Constraints-----\n- 1 \u2264 T \u2264 1000\n- 1 \u2264 A,B,C \u2264 180\n\n-----Example-----\nInput\n\n3 \n40 40 100\n45 45 90\n180 1 1\nOutput\n\nYES\nYES\nNO\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nn=int(input())\nfor i in range(n):\n a,b,c=map(int,input().split())\n if a>0 and b>0 and c>0 and a+b+c==180:\n print(\"YES\")\n else:\n print(\"NO\")\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3 \\n40 40 100\\n45 45 90\\n180 1 1\\n\\n', 'output': 'YES\\nYES\\nNO\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/FLOW013'}","problem_id":"vfc_3066","program":"```python\nn=int(input())\nfor i in range(n):\n a,b,c=map(int,input().split())\n if a>0 and b>0 and c>0 and a+b+c==180:\n print(\"YES\")\n else:\n print(\"NO\")\n```","inputs":"3 \n40 40 100\n45 45 90\n180 1 1\n\n","output":"YES\nYES\nNO\n","actual_output":"YES\nYES\nNO\n","execution_success":true,"sample_index":656},{"source":"apps","task_type":"verifiable_code","in_source_id":"1057","prompt":"Solve the following coding problem using the programming language python:\n\nAlice is a very brilliant student. He considers '4' and '7' as Magic numbers. The numbers containing only magic numbers are also magical. Given a magic number N ,he wants to know what could be the next magical number greater than the given number.\n\n-----Input-----\n\nFirst line of input contains number of test cases T. For each test case, there is exits only one line containing a magic number N. \n\n-----Output-----\n\nFor each test case, output a single line containing the next greater magical number.\n\n-----Constraints-----\n1<=T<=1000\n4<= N<=10^100\n\n-----Example-----\nInput:\n2\n4\n47\n\nOutput:\n7\n74\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nimport math\n\ndef magic(a,digits):\n m=a%10\n if(m==4):\n return a+3\n elif(m==7):\n p=list(str(a))\n #print p\n for i in range(digits-1,-1,-1):\n #print p[i]\n if (p[i]=='4'):\n #print 'four'\n p[i]='7'\n p = ''.join(str(n) for n in p)\n return int(p)\n if ((p[i]=='7')&(i==0)):\n #print 'seven'\n p[i]='4'\n p.insert(0,4)\n p = ''.join(str(n) for n in p)\n return int(p)\n\n if(p[i]=='7'):\n #print 'seven only'\n p[i]='4'\n \n #print p[i]\n \n \n \n\nt=eval(input())\n\nn=[]\nop=[]\n\nfor i in range(0,t):\n n.append(eval(input()))\n\nfor i in range(0,t):\n digits = int(math.log10(n[i]))+1\n #print digits\n op.append(magic(n[i],digits))\n \n#for i in range(0,t):\n #print n[i]\n\nfor i in range(0,t):\n print(op[i])\n\n\n\n \n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n4\\n47\\n\\n\\n', 'output': '7\\n74\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/ALKH2012/problems/NMAGIC'}","problem_id":"vfc_3070","program":"```python\nimport math\n\ndef magic(a,digits):\n m=a%10\n if(m==4):\n return a+3\n elif(m==7):\n p=list(str(a))\n #print p\n for i in range(digits-1,-1,-1):\n #print p[i]\n if (p[i]=='4'):\n #print 'four'\n p[i]='7'\n p = ''.join(str(n) for n in p)\n return int(p)\n if ((p[i]=='7')&(i==0)):\n #print 'seven'\n p[i]='4'\n p.insert(0,4)\n p = ''.join(str(n) for n in p)\n return int(p)\n\n if(p[i]=='7'):\n #print 'seven only'\n p[i]='4'\n \n #print p[i]\n \n \n \n\nt=eval(input())\n\nn=[]\nop=[]\n\nfor i in range(0,t):\n n.append(eval(input()))\n\nfor i in range(0,t):\n digits = int(math.log10(n[i]))+1\n #print digits\n op.append(magic(n[i],digits))\n \n#for i in range(0,t):\n #print n[i]\n\nfor i in range(0,t):\n print(op[i])\n\n\n\n \n\n```","inputs":"2\n4\n47\n\n\n","output":"7\n74\n","actual_output":"7\n74\n","execution_success":true,"sample_index":657},{"source":"apps","task_type":"verifiable_code","in_source_id":"1058","prompt":"Solve the following coding problem using the programming language python:\n\nThere is a popular apps named \u201cExbook\u201d like \u201cFacebook\u201d. To sign up in this app , You have to make a strong password with more than 3 digits and less than 10 digits . But I am a pro hacker and so I make a Exbook hacking site . You need to login in this site to hack exbook account and then you will get a portal. You can give any user exbook login link using this site and when anyone login into exbook using your link ,you can see his/her password .\nBut I made a mistake and so you cannot find original password in your portal . The portal showing you by adding two in every digit . So , now you have to find out the original password of an user if I give you the password which is showing in your portal .\n\n-----Input:-----\nThe first line contains a single integer t (1 \u2264 t \u2264 1000) \u2014 the number of test cases.\nThe first line of each test case contains a single integer n which is showing in your portal . Mind it , every digit of n is greater than one .\n\n-----Output:-----\nPrint , original password of user .\n\n-----Sample Input:-----\n2\n3527\n47269\n\n-----Sample Output:-----\n1305\n25047\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\nt=int(input())\nfor i in range(0,t):\n p=input()\n l=list(p)\n for j in range(0,len(l)):\n l[j]=int(l[j])\n l[j]=l[j]-2\n for j in range(0,len(l)):\n l[j]=str(l[j])\n q=''.join(l)\n print(q)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n3527\\n47269\\n', 'output': '1305\\n25047\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/ABCC2020/problems/PASSHACK'}","problem_id":"vfc_3074","program":"```python\n# cook your dish here\nt=int(input())\nfor i in range(0,t):\n p=input()\n l=list(p)\n for j in range(0,len(l)):\n l[j]=int(l[j])\n l[j]=l[j]-2\n for j in range(0,len(l)):\n l[j]=str(l[j])\n q=''.join(l)\n print(q)\n```","inputs":"2\n3527\n47269\n","output":"1305\n25047\n","actual_output":"1305\n25047\n","execution_success":true,"sample_index":658},{"source":"apps","task_type":"verifiable_code","in_source_id":"1059","prompt":"Solve the following coding problem using the programming language python:\n\nYou have an array A of size N containing only positive numbers. You have to output the maximum possible value of A[i]%A[j] where 1<=i,j<=N. \n\n-----Input-----\nThe first line of each test case contains a single integer N denoting the size of the array. The next N lines contains integers A1, A2, ..., AN denoting the numbers\n\n-----Output-----\nOutput a single integer answering what is asked in the problem.\n\n-----Subtask 1 (20 points)-----\n- 1 \u2264 N \u2264 5000\n- 1 \u2264 A[i] \u2264 2*(10^9)\n\n-----Subtask 2 (80 points)-----\n- 1 \u2264 N \u2264 1000000\n- 1 \u2264 A[i] \u2264 2*(10^9)\n\n-----Example-----\nInput:\n2\n1\n2\n\nOutput:\n1\n\n-----Explanation-----\nThere will be four values, A[0]%A[0] = 0, A[0]%A[1]=1, A[1]%A[0]=0, A[1]%A[1]=0, and hence the output will be the maximum among them all, that is 1.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nn = int(input())\na = []\nfor i in range(n):\n a.append(int(input()))\nm1 = 0\nm2 = 0\nfor e in a:\n if (e > m1):\n m2 = m1\n m1 = e\n elif (e > m2 and e != m1):\n m2 = e\nans = 0\nfor e in a:\n temp = m1%e\n if (temp>ans):\n ans = temp\nprint(max(m2%m1,ans))\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n1\\n2\\n', 'output': '1\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/LOCMAR16/problems/MOD'}","problem_id":"vfc_3078","program":"```python\nn = int(input())\na = []\nfor i in range(n):\n a.append(int(input()))\nm1 = 0\nm2 = 0\nfor e in a:\n if (e > m1):\n m2 = m1\n m1 = e\n elif (e > m2 and e != m1):\n m2 = e\nans = 0\nfor e in a:\n temp = m1%e\n if (temp>ans):\n ans = temp\nprint(max(m2%m1,ans))\n```","inputs":"2\n1\n2\n","output":"1\n","actual_output":"1\n","execution_success":true,"sample_index":659},{"source":"apps","task_type":"verifiable_code","in_source_id":"1060","prompt":"Solve the following coding problem using the programming language python:\n\nChef and Abhishek both are fighting for the post of Chairperson to be part of ACE committee and are trying their best. To select only one student their teacher gave them a binary string (string consisting of only 0's and 1's) and asked them to find number of sub-strings present in the given string that satisfy the following condition:\nThe substring should start with 0 and end with 1 or the substring should start with 1 and end with 0 but not start with 0 and end with 0 and start with 1 and end with 1.\nMore formally, strings such as 100,0101 are allowed since they start and end with different characters. But strings such as 0110,1101 are not allowed because they start and end with same characters.\nBoth Chef and Abhishek try their best to solve it but couldn't do it. You being a very good friend of Chef, he asks for your help so that he can solve it and become the Chairperson.\n\n-----Input:-----\nThe first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows.\nThe first line of each test case contains a single integer N denoting the length of the string.\nThe second line of each test case contains a binary string of length N.\n\n-----Output:-----\nFor each test case, print a single line containing one integer \u2015 the number of sub strings satisfying above conditions.\n\n-----Constraints-----\n- $1 \\leq T \\leq 1000$\n- $2 \\leq N \\leq 10^9$\nBinary string consist's only 0 and 1.\n\n-----Sample Input:-----\n1\n4\n\n1010\n\n-----Sample Output:-----\n4\n\n-----EXPLANATION:-----\nAll possible substring are : { (1),(0),(1),(0),(10),(01),(10),(101),(010),(1010) }. Out of these only 4 substrings {(10),(01),(10),(1010)} start and end with different characters. Hence the answer 4.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\ndef countSubstr(str, n, x, y): \r\n \r\n tot_count = 0\r\n \r\n count_x = 0\r\n \r\n for i in range(n): \r\n if str[i] == x: \r\n count_x += 1\r\n if str[i] == y: \r\n tot_count += count_x \r\n return tot_count \r\n \r\nt=int(input())\r\nfor _ in range(t):\r\n n=int(input())\r\n str=input()\r\n x='0'\r\n y='1'\r\n x1='1'\r\n y1='0'\r\n c1=countSubstr(str,n,x,y)\r\n c2=countSubstr(str,n,x1,y1)\r\n print(c1+c2)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n4\\n1010\\n', 'output': '4\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/CEFT2020/problems/QFUN'}","problem_id":"vfc_3082","program":"```python\ndef countSubstr(str, n, x, y): \r\n \r\n tot_count = 0\r\n \r\n count_x = 0\r\n \r\n for i in range(n): \r\n if str[i] == x: \r\n count_x += 1\r\n if str[i] == y: \r\n tot_count += count_x \r\n return tot_count \r\n \r\nt=int(input())\r\nfor _ in range(t):\r\n n=int(input())\r\n str=input()\r\n x='0'\r\n y='1'\r\n x1='1'\r\n y1='0'\r\n c1=countSubstr(str,n,x,y)\r\n c2=countSubstr(str,n,x1,y1)\r\n print(c1+c2)\n```","inputs":"1\n4\n1010\n","output":"4\n","actual_output":"4\n","execution_success":true,"sample_index":660},{"source":"apps","task_type":"verifiable_code","in_source_id":"1061","prompt":"Solve the following coding problem using the programming language python:\n\nChef is playing with an expression which consists of integer operands and the following binary\nBitwise operators - AND, OR and XOR. He is trying to figure out that what could be the Maximum possible answer of the expression, given that he can perform the operation in any order i.e not necessarily follow the rule of Precedence of operators while evaluating the expression.\nAfter some time of consistent work Chef starts feeling exhausted and wants you to automate this process for him. Can you help him out?\nThe expression has Bitwise operators in symbol format:\n- & stands for AND \n- | stands for OR\n- ^ stands for XOR\nNOTE : It is guaranteed that the expression will always be valid, also each OPERATOR will always be preceded and succeeded by an OPERAND.\n\n-----Input:-----\n- The first line of input contains a single integer $T$ denoting the number of test cases.\n- The only line of input for each test case is a $string$ which is the Chef's expression to evaluate.\n\n-----Output:-----\nFor each test case print a single integer i.e the maximum possible value of Chef's expression.\n\n-----Constraints-----\n- $1 \\leq T \\leq 100$.\n- The number of OPERATORS in the expression will be atleast 1 and atmost 10.\n- Each OPERAND may range from 0 to $10^9$.\n\n-----Subtasks-----\n- 10 points : The number of OPERATORS in the expression will be atmost 5.\n- 20 points : The number of OPERATORS in the expression will be atmost 8.\n- 70 points : Original constraints.\n\n-----Sample Input:-----\n2\n3^40|10^2\n\n92^95|56&2&3\n\n-----Sample Output:-----\n43\n\n95\n\n-----EXPLANATION:-----CASE 2 :\n- If we first compute (56 & 2), the expression becomes 92^95|0&3, since (56 & 2) yields $0$.\n- Now on computing (95 | 0), the expression becomes 92^95&3.\n- Further on computing (95 & 3), the expression becomes 92^3.\n- Finally (92 ^ 3) yields 95, which is the maximum value of the expression.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\ndef value(a, b, c):\n if(c == '&'):\n return a&b\n elif(c == '^'):\n return a^b\n elif(c == '|'):\n return a|b\n\ndef break_rules(n, operator):\n if(len(n) == 1):\n return n\n elif(len(n) == 2):\n return [value(n[0], n[1], operator[0])]\n else:\n cont_ans = []\n for i in range(1,len(n)):\n l1 = n[:i]\n l2 = n[i:]\n o1 = operator[:i]\n o2 = operator[i:]\n l1_ans = break_rules(l1, o1)\n l2_ans = break_rules(l2, o2)\n for k in l1_ans:\n for j in l2_ans:\n cont_ans.append(value(k, j, operator[i - 1]))\n return cont_ans\n\nt = int(input())\nwhile t > 0 :\n operator = []\n num = []\n exp = input()\n temp = ''\n for i in range(len(exp)):\n if(ord(exp[i]) > 47 and ord(exp[i]) < 58):\n temp = temp + exp[i]\n else:\n num.append(int(temp))\n temp = ''\n operator.append(exp[i])\n if(i == len(exp) - 1):\n num.append(int(temp))\n t -= 1\n # print(num,operator)\n print(max(break_rules(num, operator)))\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n3^40|10^2\\n92^95|56&2&3\\n', 'output': '43\\n95\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/BIT2C'}","problem_id":"vfc_3086","program":"```python\n# cook your dish here\ndef value(a, b, c):\n if(c == '&'):\n return a&b\n elif(c == '^'):\n return a^b\n elif(c == '|'):\n return a|b\n\ndef break_rules(n, operator):\n if(len(n) == 1):\n return n\n elif(len(n) == 2):\n return [value(n[0], n[1], operator[0])]\n else:\n cont_ans = []\n for i in range(1,len(n)):\n l1 = n[:i]\n l2 = n[i:]\n o1 = operator[:i]\n o2 = operator[i:]\n l1_ans = break_rules(l1, o1)\n l2_ans = break_rules(l2, o2)\n for k in l1_ans:\n for j in l2_ans:\n cont_ans.append(value(k, j, operator[i - 1]))\n return cont_ans\n\nt = int(input())\nwhile t > 0 :\n operator = []\n num = []\n exp = input()\n temp = ''\n for i in range(len(exp)):\n if(ord(exp[i]) > 47 and ord(exp[i]) < 58):\n temp = temp + exp[i]\n else:\n num.append(int(temp))\n temp = ''\n operator.append(exp[i])\n if(i == len(exp) - 1):\n num.append(int(temp))\n t -= 1\n # print(num,operator)\n print(max(break_rules(num, operator)))\n```","inputs":"2\n3^40|10^2\n92^95|56&2&3\n","output":"43\n95\n","actual_output":"43\n95\n","execution_success":true,"sample_index":661},{"source":"apps","task_type":"verifiable_code","in_source_id":"1062","prompt":"Solve the following coding problem using the programming language python:\n\nHo, Ho, Ho!\nIt's Christmas time and our friendly grandpa Santa Claus is busy distributing gifts to all the nice children. With the rising population, Santa's workload every year gets increased and he seeks your help to wrap the gifts with fancy wrapping papers while he gets them distributed. \nEverything was going great until you realised that you'll fall short of wrapping paper. But luckily, you get a very innovative idea, that will allow you to pack all the remaining gifts without worrying about lack of wrapping paper. Any guesses what the idea is? Using ice for wrapping, obviously! That's the only thing available at the North Pole.\nNow, in order to reduce your trips to the ice factory, you decide to write a program that helps you visualize how much ice is needed for a particular gift. \n\n-----Input:-----\nInput will consist of a single line with size $n$.\n\n-----Output:-----\nPrint the ice wrapped gift box for the given size. \n\n-----Constraints-----\n- $0 \\leq n \\leq 1000$\n\n-----Sample Input:-----\n4\n\n-----Sample Output:-----\n4 4 4 4 4 4 4\n4 3 3 3 3 3 4\n4 3 2 2 2 3 4\n4 3 2 1 2 3 4\n4 3 2 2 2 3 4 \n4 3 3 3 3 3 4\n4 4 4 4 4 4 4\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\ndef read_i_l(l=False):\n m = list(map(int, input().strip().split(\" \")))\n if l:\n return list(m)\n else:\n return m\ndef i():\n return int(input().strip())\nT = i()\nL = []\n\"\"\"for current in range(T):\n line = \"\"\n for i in range(current):\n line+=str((T-i)%10)\n for i in range(2*(T-current)-1):\n line+=str((T-current)%10)\n for i in range(current-1,-1,-1):\n line+=str((T-i)%10)\n L.append(line)\nL += L[-2::-1]\"\"\"\n\nif T >= 1:\n L = [\"1\"]\n\nfor i in range(2,T+1):\n nL = [str(i)+(2*i-2)*(\" \"+str(i))]\n for l in L:\n nL.append(str(i)+\" \"+l+\" \"+str(i))\n nL.append(str(i)+(2*i-2)*(\" \"+str(i)))\n L = nL\nfor l in L:\n print(l)\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '4\\n', 'output': '4 4 4 4 4 4 4\\n4 3 3 3 3 3 4\\n4 3 2 2 2 3 4\\n4 3 2 1 2 3 4\\n4 3 2 2 2 3 4\\n4 3 3 3 3 3 4\\n4 4 4 4 4 4 4\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/NQST2020/problems/ICEWRAP'}","problem_id":"vfc_3090","program":"```python\n# cook your dish here\ndef read_i_l(l=False):\n m = list(map(int, input().strip().split(\" \")))\n if l:\n return list(m)\n else:\n return m\ndef i():\n return int(input().strip())\nT = i()\nL = []\n\"\"\"for current in range(T):\n line = \"\"\n for i in range(current):\n line+=str((T-i)%10)\n for i in range(2*(T-current)-1):\n line+=str((T-current)%10)\n for i in range(current-1,-1,-1):\n line+=str((T-i)%10)\n L.append(line)\nL += L[-2::-1]\"\"\"\n\nif T >= 1:\n L = [\"1\"]\n\nfor i in range(2,T+1):\n nL = [str(i)+(2*i-2)*(\" \"+str(i))]\n for l in L:\n nL.append(str(i)+\" \"+l+\" \"+str(i))\n nL.append(str(i)+(2*i-2)*(\" \"+str(i)))\n L = nL\nfor l in L:\n print(l)\n\n```","inputs":"4\n","output":"4 4 4 4 4 4 4\n4 3 3 3 3 3 4\n4 3 2 2 2 3 4\n4 3 2 1 2 3 4\n4 3 2 2 2 3 4\n4 3 3 3 3 3 4\n4 4 4 4 4 4 4\n","actual_output":"4 4 4 4 4 4 4\n4 3 3 3 3 3 4\n4 3 2 2 2 3 4\n4 3 2 1 2 3 4\n4 3 2 2 2 3 4\n4 3 3 3 3 3 4\n4 4 4 4 4 4 4\n","execution_success":true,"sample_index":662},{"source":"apps","task_type":"verifiable_code","in_source_id":"1063","prompt":"Solve the following coding problem using the programming language python:\n\nWrite a program to find the remainder when an integer A is divided by an integer B.\n\n-----Input-----\n\nThe first line contains an integer T, the total number of test cases. Then T lines follow, each line contains two Integers A and B. \n\n-----Output-----\nFor each test case, find the remainder when A is divided by B, and display it in a new line.\n\n-----Constraints-----\n- 1 \u2264 T \u2264 1000\n- 1 \u2264 A,B \u2264 10000\n\n-----Example-----\nInput\n3 \n1 2\n100 200\n40 15\n\nOutput\n1\n100\n10\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nnumber = int(input())\nfor i in range(number):\n x = list(map(int, input().split(' ')))\n print(x[0]%x[1])\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\n1 2\\n100 200\\n40 15\\n', 'output': '1\\n100\\n10\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/FLOW002'}","problem_id":"vfc_3094","program":"```python\nnumber = int(input())\nfor i in range(number):\n x = list(map(int, input().split(' ')))\n print(x[0]%x[1])\n```","inputs":"3\n1 2\n100 200\n40 15\n","output":"1\n100\n10\n","actual_output":"1\n100\n10\n","execution_success":true,"sample_index":663},{"source":"apps","task_type":"verifiable_code","in_source_id":"1064","prompt":"Solve the following coding problem using the programming language python:\n\nChef Ciel wants to put a fancy neon signboard over the entrance of her restaurant. She has not enough money to buy the new one so she bought some old neon signboard through the internet. Ciel was quite disappointed when she received her order - some of its letters were broken. But she realized that this is even better - she could replace each broken letter by any letter she wants. So she decided to do such a replacement that the resulting signboard will contain the word \"CHEF\" as many times as possible.\nWe can model the signboard as a string S having capital letters from 'A' to 'Z', inclusive, and question marks '?'. Letters in the string indicate the intact letters at the signboard, while question marks indicate broken letters. So Ciel will replace each question mark with some capital letter and her goal is to get the string that contains as many substrings equal to \"CHEF\" as possible. If there exist several such strings, she will choose the lexicographically smallest one.\nNote 1. The string S = S1...SN has the substring \"CHEF\" if for some i we have SiSi+1Si+2Si+3 = \"CHEF\". The number of times \"CHEF\" is the substring of S is the number of those i for which SiSi+1Si+2Si+3 = \"CHEF\".\nNote 2. The string A = A1...AN is called lexicographically smaller than the string B = B1...BN if there exists K from 1 to N, inclusive, such that Ai = Bi for i = 1, ..., K-1, and AK < BK. In particular, A is lexicographically smaller than B if A1 < B1. We compare capital letters by their positions in the English alphabet. So 'A' is the smallest letter, 'B' is the second smallest letter, ..., 'Z' is the largest letter.\n\n-----Input-----\nThe first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows. The only line of each test case contains a string S.\n\n-----Output-----\nFor each test case, output a single line containing the content of the signboard Chef Ciel will come up with. That is you should output the lexicographically smallest string that could be obtained from the input string by replacing all its question marks by some capital letters and having as many substrings equal to \"CHEF\" as possible.\n\n-----Constraints-----\n- 1 \u2264 T \u2264 2013\n- 1 \u2264 length of S \u2264 2013\n- Each character in S is either a capital letter from 'A' to 'Z', inclusive, or the question mark '?'.\n\n-----Example-----\nInput:\n5\n????CIELIS???E?\n????CIELISOUR???F\nT?KEITE?SY\n????????\n???C???\n\nOutput:\nCHEFCIELISACHEF\nCHEFCIELISOURCHEF\nTAKEITEASY\nCHEFCHEF\nAAACHEF\n\n-----Explanation -----\nExample Case 1. Here the resulting string can have at most 2 substrings equal to \"CHEF\". For example, some possible such strings are:\n\n- CHEFCIELISACHEF\n- CHEFCIELISQCHEF\n- CHEFCIELISZCHEF\nHowever, lexicographically smallest one is the first one.\n\nExample Case 3. Here the resulting string cannot have \"CHEF\" as its substring. Therefore, you must simply output the lexicographically smallest string that can be obtained from the given one by replacing question marks with capital letters.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfrom math import gcd\nimport sys\ninput=lambda : sys.stdin.readline().strip()\nc=lambda x: 10**9 if(x==\"?\") else int(x)\ndef main():\n for _ in range(int(input())):\n s=list(input())[::-1]\n l=['F','E','H','C']\n i=0\n while(ig) or(j==g and k>h):\n if c[g][h]-c[j][k]>=0:\n i.append(c[g][h]-c[j][k]+j-g)\n else:\n i.append(-1*(c[g][h]-c[j][k])+j-g)\n l=[m for m in range(1,N+M-1)]\n for n in l:\n print(i.count(n),end=' ')\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n3 4\\n0011\\n0000\\n0100\\n', 'output': '1 0 1 1 0\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/AVGMAT'}","problem_id":"vfc_3102","program":"```python\n# cook your dish here\nfor a in range(int(input())):\n N,M=map(int,input().split())\n b=[]\n for o in range(N):\n b.append(input())\n c=[]\n for d in b:\n f=[]\n for e in range(len(d)):\n if d[e]=='1':\n f.append(e)\n c.append(f)\n i=[]\n for g in range(len(c)):\n for h in range(len(c[g])):\n for j in range(len(c)):\n for k in range(len(c[j])):\n if (j>g) or(j==g and k>h):\n if c[g][h]-c[j][k]>=0:\n i.append(c[g][h]-c[j][k]+j-g)\n else:\n i.append(-1*(c[g][h]-c[j][k])+j-g)\n l=[m for m in range(1,N+M-1)]\n for n in l:\n print(i.count(n),end=' ')\n```","inputs":"1\n3 4\n0011\n0000\n0100\n","output":"1 0 1 1 0\n","actual_output":"1 0 1 1 0 ","execution_success":true,"sample_index":665},{"source":"apps","task_type":"verifiable_code","in_source_id":"1066","prompt":"Solve the following coding problem using the programming language python:\n\n-----\nCHEF N TIMINGS\n-----\n\nOne day chef was working with some random numbers. Then he found something\ninteresting. He observed that no 240, 567, 9999 and 122 and called these numbers\nnice as the digits in numbers are in increasing order. Also he called 434, 452, 900\nare not nice as digits are in decreasing order\n\n\t\n\nNow you are given a no and chef\nwants you to find out largest \"nice\" integer which is smaller than or equal to the\ngiven integer.\n\n\t\t\n\t\t\n\n-----Constraints-----\n\n1< t < 1000 \n\n1< N < 10^18\n\t\n\n-----Input Format-----\n\nFirst line contains no. of test cases t. Then t test cases follow. Each test case\ncontain a integer n.\n\n-----Output-----\n\nOutput a integer for each test case in a new line which is largest nice\ninteger smaller or equal to the given integer. \n\n\t\t\n\t\t\n\n-----Example Text Case-----\nInput:\n\n1\n132\n\nOutput:\n\n129\n\t\n\t\t\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfor _ in range(int(input())):\n n=input().rstrip()\n n=[ele for ele in n]\n l=len(n)\n m=10**18+8\n ini=1\n for i in range(l-1,-1,-1):\n if int(n[i])<=m:\n if ini==1:\n m=int(n[i])\n else:\n m=max(m,n[i])\n else:\n m=int(n[i])-1\n n[i]=str(m)\n for j in range(l-1,i,-1):\n n[j]='9'\n \n i=0\n while n[i]=='0':\n i+=1\n print(\"\".join(n[i:]))\n \n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n132\\n', 'output': '129\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/APO12020/problems/APOC2_04'}","problem_id":"vfc_3106","program":"```python\nfor _ in range(int(input())):\n n=input().rstrip()\n n=[ele for ele in n]\n l=len(n)\n m=10**18+8\n ini=1\n for i in range(l-1,-1,-1):\n if int(n[i])<=m:\n if ini==1:\n m=int(n[i])\n else:\n m=max(m,n[i])\n else:\n m=int(n[i])-1\n n[i]=str(m)\n for j in range(l-1,i,-1):\n n[j]='9'\n \n i=0\n while n[i]=='0':\n i+=1\n print(\"\".join(n[i:]))\n \n\n```","inputs":"1\n132\n","output":"129\n","actual_output":"129\n","execution_success":true,"sample_index":666},{"source":"apps","task_type":"verifiable_code","in_source_id":"1067","prompt":"Solve the following coding problem using the programming language python:\n\nChef has a strip of length $N$ units and he wants to tile it using $4$ kind of tiles\n\n-A Red tile of $2$ unit length\n\n-A Red tile of $1$ unit length\n\n-A Blue tile of $2$ unit length\n\n-A Blue tile of $1$ unit length \nChef is having an infinite supply of each of these tiles. He wants to find out the number of ways in which he can tile the strip. Help him find this number.\nSince this number can be large, output your answer modulo 1000000007 ($10^9 + 7$).\n\n-----Input:-----\n- First line will contain $T$, number of testcases. Then the testcases follow. \n- Each testcase contains of a single line of input, an integer $N$. \n\n-----Output:-----\nFor each testcase, output in a single line your answer modulo 1000000007.\n\n-----Constraints-----\n- $1 \\leq T \\leq 1000$\n- $2 \\leq N \\leq 10^{18}$\n\n-----Sample Input:-----\n1\n2\n\n-----Sample Output:-----\n6\n\n-----EXPLANATION:-----\n\nIt can be seen that for a strip of length $2$, there are $6$ possible configurations. \n$NOTE : $ 2 tiles of 1 unit length are different from 1 tile of 2 unit length.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# Fibonacci Series using \r\n# Optimized Method \r\n\r\n# function that returns nth \r\n# Fibonacci number\r\nMOD = 1000000007\r\ndef fib(n):\r\n F = [[2, 2],\r\n [1, 0]]\r\n power(F, n - 1)\r\n ans = [6, 2]\r\n return (F[0][0] * 6 + F[0][1] * 2) % MOD\r\n # return F[0][0]\r\n\r\n\r\ndef multiply(F, M):\r\n x = (F[0][0] * M[0][0] +\r\n F[0][1] * M[1][0]) % MOD\r\n y = (F[0][0] * M[0][1] +\r\n F[0][1] * M[1][1]) % MOD\r\n z = (F[1][0] * M[0][0] +\r\n F[1][1] * M[1][0]) % MOD\r\n w = (F[1][0] * M[0][1] +\r\n F[1][1] * M[1][1]) % MOD\r\n\r\n F[0][0] = x\r\n F[0][1] = y\r\n F[1][0] = z\r\n F[1][1] = w\r\n\r\n\r\ndef power(F, n):\r\n if n == 0 or n == 1:\r\n return\r\n M = [[2, 2],\r\n [1, 0]]\r\n\r\n power(F, n // 2)\r\n multiply(F, F)\r\n\r\n if n % 2 != 0:\r\n multiply(F, M)\r\n\r\n\r\nfor _ in range(int(input())):\r\n n = int(input())\r\n ans = 1\r\n if n == 0:\r\n ans = 1\r\n elif n == 1:\r\n ans = 2\r\n elif n == 2:\r\n ans = 6\r\n else:\r\n ans = fib(n-1)\r\n print(ans)\r\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n2\\n', 'output': '6\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/COG2020/problems/COG2004'}","problem_id":"vfc_3110","program":"```python\n# Fibonacci Series using \r\n# Optimized Method \r\n\r\n# function that returns nth \r\n# Fibonacci number\r\nMOD = 1000000007\r\ndef fib(n):\r\n F = [[2, 2],\r\n [1, 0]]\r\n power(F, n - 1)\r\n ans = [6, 2]\r\n return (F[0][0] * 6 + F[0][1] * 2) % MOD\r\n # return F[0][0]\r\n\r\n\r\ndef multiply(F, M):\r\n x = (F[0][0] * M[0][0] +\r\n F[0][1] * M[1][0]) % MOD\r\n y = (F[0][0] * M[0][1] +\r\n F[0][1] * M[1][1]) % MOD\r\n z = (F[1][0] * M[0][0] +\r\n F[1][1] * M[1][0]) % MOD\r\n w = (F[1][0] * M[0][1] +\r\n F[1][1] * M[1][1]) % MOD\r\n\r\n F[0][0] = x\r\n F[0][1] = y\r\n F[1][0] = z\r\n F[1][1] = w\r\n\r\n\r\ndef power(F, n):\r\n if n == 0 or n == 1:\r\n return\r\n M = [[2, 2],\r\n [1, 0]]\r\n\r\n power(F, n // 2)\r\n multiply(F, F)\r\n\r\n if n % 2 != 0:\r\n multiply(F, M)\r\n\r\n\r\nfor _ in range(int(input())):\r\n n = int(input())\r\n ans = 1\r\n if n == 0:\r\n ans = 1\r\n elif n == 1:\r\n ans = 2\r\n elif n == 2:\r\n ans = 6\r\n else:\r\n ans = fib(n-1)\r\n print(ans)\r\n\n```","inputs":"1\n2\n","output":"6\n","actual_output":"6\n","execution_success":true,"sample_index":667},{"source":"apps","task_type":"verifiable_code","in_source_id":"1068","prompt":"Solve the following coding problem using the programming language python:\n\nAda's classroom contains $N \\cdot M$ tables distributed in a grid with $N$ rows and $M$ columns. Each table is occupied by exactly one student.\nBefore starting the class, the teacher decided to shuffle the students a bit. After the shuffling, each table should be occupied by exactly one student again. In addition, each student should occupy a table that is adjacent to that student's original table, i.e. immediately to the left, right, top or bottom of that table.\nIs it possible for the students to shuffle while satisfying all conditions of the teacher?\n\n-----Input-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The first and only line of each test case contains two space-separated integers $N$ and $M$.\n\n-----Output-----\nFor each test case, print a single line containing the string \"YES\" if it is possible to satisfy the conditions of the teacher or \"NO\" otherwise (without quotes).\n\n-----Constraints-----\n- $1 \\le T \\le 5,000$\n- $2 \\le N, M \\le 50$\n\n-----Example Input-----\n2\n3 3\n4 4\n\n-----Example Output-----\nNO\nYES\n\n-----Explanation-----\nExample case 2: The arrows in the following image depict how the students moved.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\nt=int(input())\nfor _ in range(t):\n N, M=map(int,input().split())\n if(N%2==0 or M%2==0):\n print(\"YES\")\n else:\n print(\"NO\")\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n3 3\\n4 4\\n', 'output': 'NO\\nYES\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/ADASCOOL'}","problem_id":"vfc_3114","program":"```python\n# cook your dish here\nt=int(input())\nfor _ in range(t):\n N, M=map(int,input().split())\n if(N%2==0 or M%2==0):\n print(\"YES\")\n else:\n print(\"NO\")\n```","inputs":"2\n3 3\n4 4\n","output":"NO\nYES\n","actual_output":"NO\nYES\n","execution_success":true,"sample_index":668},{"source":"apps","task_type":"verifiable_code","in_source_id":"1069","prompt":"Solve the following coding problem using the programming language python:\n\nShivam is the youngest programmer in the world, he is just 12 years old. Shivam is learning programming and today he is writing his first program. \n\nProgram is very simple, Given two integers A and B, write a program to add these two numbers.\n\n-----Input-----\n\nThe first line contains an integer T, the total number of test cases. Then follow T lines, each line contains two Integers A and B. \n\n-----Output-----\nFor each test case, add A and B and display it in a new line.\n\n-----Constraints-----\n- 1 \u2264 T \u2264 1000\n- 0 \u2264 A,B \u2264 10000\n\n-----Example-----\nInput\n3 \n1 2\n100 200\n10 40\n\nOutput\n3\n300\n50\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n#Note that it's python3 Code. Here, we are using input() instead of raw_input().\n#You can check on your local machine the version of python by typing \"python --version\" in the terminal.\n\n#Read the number of test cases.\nT = int(input())\nfor tc in range(T):\n\t# Read integers a and b.\n\t(a, b) = list(map(int, input().split(' ')))\n\t\n\tans = a + b\n\tprint(ans)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\n1 2\\n100 200\\n10 40\\n', 'output': '3\\n300\\n50\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/FLOW001'}","problem_id":"vfc_3118","program":"```python\n#Note that it's python3 Code. Here, we are using input() instead of raw_input().\n#You can check on your local machine the version of python by typing \"python --version\" in the terminal.\n\n#Read the number of test cases.\nT = int(input())\nfor tc in range(T):\n\t# Read integers a and b.\n\t(a, b) = list(map(int, input().split(' ')))\n\t\n\tans = a + b\n\tprint(ans)\n```","inputs":"3\n1 2\n100 200\n10 40\n","output":"3\n300\n50\n","actual_output":"3\n300\n50\n","execution_success":true,"sample_index":669},{"source":"apps","task_type":"verifiable_code","in_source_id":"1070","prompt":"Solve the following coding problem using the programming language python:\n\nand Bengali as well.\nThere are N$N$ cats (numbered 1$1$ through N$N$) and M$M$ rats (numbered 1$1$ through M$M$) on a line. Each cat and each rat wants to move from some point to some (possibly the same) point on this line. Naturally, the cats also want to eat the rats when they get a chance. Both the cats and the rats can only move with constant speed 1$1$.\nFor each valid i$i$, the i$i$-th cat is initially sleeping at a point a_i$a_i$. At a time s_i$s_i$, this cat wakes up and starts moving to a final point b_i$b_i$ with constant velocity and without any detours (so it arrives at this point at the time e_i = s_i + |a_i-b_i|$e_i = s_i + |a_i-b_i|$). After it arrives at the point b_i$b_i$, it falls asleep again.\nFor each valid i$i$, the i$i$-th rat is initially hiding at a point c_i$c_i$. At a time r_i$r_i$, this rat stops hiding and starts moving to a final point d_i$d_i$ in the same way as the cats \u2015 with constant velocity and without any detours, arriving at the time q_i = r_i + |c_i-d_i|$q_i = r_i + |c_i-d_i|$ (if it does not get eaten). After it arrives at the point d_i$d_i$, it hides again.\nIf a cat and a rat meet each other (they are located at the same point at the same time), the cat eats the rat, the rat disappears and cannot be eaten by any other cat. A sleeping cat cannot eat a rat and a hidden rat cannot be eaten \u2015 formally, cat i$i$ can eat rat j$j$ only if they meet at a time t$t$ satisfying s_i \\le t \\le e_i$s_i \\le t \\le e_i$ and r_j \\le t \\le q_j$r_j \\le t \\le q_j$.\nYour task is to find out which rats get eaten by which cats. It is guaranteed that no two cats will meet a rat at the same time.\n\n-----Input-----\n- 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.\n- The first line of each test case contains two space-separated integers N$N$ and M$M$.\n- N$N$ lines follow. For each i$i$ (1 \\le i \\le N$1 \\le i \\le N$), the i$i$-th of these lines contains three space-separated integers a_i$a_i$, b_i$b_i$ and s_i$s_i$.\n- M$M$ more lines follow. For each i$i$ (1 \\le i \\le M$1 \\le i \\le M$), the i$i$-th of these lines contains three space-separated integers c_i$c_i$, d_i$d_i$ and r_i$r_i$.\n\n-----Output-----\nFor each test case, print M$M$ lines. For each valid i$i$, the i$i$-th of these lines should contain a single integer \u2015 the number of the cat that will eat the i$i$-th rat, or -1$-1$ if no cat will eat this rat.\n\n-----Constraints-----\n- 1 \\le T \\le 10$1 \\le T \\le 10$\n- 0 \\le N \\le 1,000$0 \\le N \\le 1,000$\n- 1 \\le M \\le 1,000$1 \\le M \\le 1,000$\n- 1 \\le a_i, b_i, s_i \\le 10^9$1 \\le a_i, b_i, s_i \\le 10^9$ for each valid i$i$\n- 1 \\le c_i, d_i, r_i \\le 10^9$1 \\le c_i, d_i, r_i \\le 10^9$ for each valid i$i$\n- all initial and final positions of all cats and rats are pairwise distinct\n\n-----Example Input-----\n2\n8 7\n2 5 1\n1 4 1\n9 14 10\n20 7 9\n102 99 1\n199 202 1\n302 299 3\n399 402 3\n6 3 1\n10 15 10\n100 101 1\n201 200 1\n300 301 5\n401 400 5\n1000 1010 1020\n8 8\n2 8 2\n12 18 2\n22 28 4\n32 38 4\n48 42 2\n58 52 3\n68 62 1\n78 72 3\n3 6 3\n13 19 3\n21 25 3\n31 39 3\n46 43 4\n59 53 2\n65 61 4\n79 71 2\n\n-----Example Output-----\n1\n4\n5\n6\n7\n8\n-1\n1\n2\n3\n4\n5\n6\n7\n8\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\n# cook your dish here\nclass Animal:\n def __init__(self):\n start, end, starting_time = map(int, input().split())\n \n self.ending_time = starting_time + abs(start - end)\n self.velocity = 1 if end >= start else -1 \n \n self.eaten_by = -1, 10 ** 10\n \n self.start = start \n self.end = end \n self.starting_time = starting_time \n \n def will_collide(self, z):\n if self.starting_time > z.ending_time or self.ending_time < z.starting_time:\n return False \n \n if self.velocity == z.velocity:\n if self.starting_time > z.starting_time:\n self, z = z, self\n if z.start == self.start + self.velocity * (z.starting_time - self.starting_time):\n return z.starting_time\n else:\n return False\n \n if self.velocity == -1:\n self, z = z, self\n \n t = ( z.start - self.start + z.starting_time + self.starting_time ) / 2 \n \n return t if self.starting_time <= t <= self.ending_time and z.starting_time <= t <= z.ending_time else False\n \n \n \ndef main():\n for _ in range(int(input())):\n no_cats, no_rats = map(int, input().split())\n \n Cats = [Animal() for i in range(no_cats)]\n \n for i in range(no_rats):\n rat = Animal() \n for j in range(no_cats):\n time = rat.will_collide(Cats[j])\n if time:\n # print(time)\n if time < rat.eaten_by[1]:\n rat.eaten_by = j + 1, time \n \n \n print(rat.eaten_by[0])\n \n \n \nmain()\n \n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n8 7\\n2 5 1\\n1 4 1\\n9 14 10\\n20 7 9\\n102 99 1\\n199 202 1\\n302 299 3\\n399 402 3\\n6 3 1\\n10 15 10\\n100 101 1\\n201 200 1\\n300 301 5\\n401 400 5\\n1000 1010 1020\\n8 8\\n2 8 2\\n12 18 2\\n22 28 4\\n32 38 4\\n48 42 2\\n58 52 3\\n68 62 1\\n78 72 3\\n3 6 3\\n13 19 3\\n21 25 3\\n31 39 3\\n46 43 4\\n59 53 2\\n65 61 4\\n79 71 2\\n', 'output': '1\\n4\\n5\\n6\\n7\\n8\\n-1\\n1\\n2\\n3\\n4\\n5\\n6\\n7\\n8\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/CATSRATS'}","problem_id":"vfc_3122","program":"```python\n# cook your dish here\n# cook your dish here\nclass Animal:\n def __init__(self):\n start, end, starting_time = map(int, input().split())\n \n self.ending_time = starting_time + abs(start - end)\n self.velocity = 1 if end >= start else -1 \n \n self.eaten_by = -1, 10 ** 10\n \n self.start = start \n self.end = end \n self.starting_time = starting_time \n \n def will_collide(self, z):\n if self.starting_time > z.ending_time or self.ending_time < z.starting_time:\n return False \n \n if self.velocity == z.velocity:\n if self.starting_time > z.starting_time:\n self, z = z, self\n if z.start == self.start + self.velocity * (z.starting_time - self.starting_time):\n return z.starting_time\n else:\n return False\n \n if self.velocity == -1:\n self, z = z, self\n \n t = ( z.start - self.start + z.starting_time + self.starting_time ) / 2 \n \n return t if self.starting_time <= t <= self.ending_time and z.starting_time <= t <= z.ending_time else False\n \n \n \ndef main():\n for _ in range(int(input())):\n no_cats, no_rats = map(int, input().split())\n \n Cats = [Animal() for i in range(no_cats)]\n \n for i in range(no_rats):\n rat = Animal() \n for j in range(no_cats):\n time = rat.will_collide(Cats[j])\n if time:\n # print(time)\n if time < rat.eaten_by[1]:\n rat.eaten_by = j + 1, time \n \n \n print(rat.eaten_by[0])\n \n \n \nmain()\n \n```","inputs":"2\n8 7\n2 5 1\n1 4 1\n9 14 10\n20 7 9\n102 99 1\n199 202 1\n302 299 3\n399 402 3\n6 3 1\n10 15 10\n100 101 1\n201 200 1\n300 301 5\n401 400 5\n1000 1010 1020\n8 8\n2 8 2\n12 18 2\n22 28 4\n32 38 4\n48 42 2\n58 52 3\n68 62 1\n78 72 3\n3 6 3\n13 19 3\n21 25 3\n31 39 3\n46 43 4\n59 53 2\n65 61 4\n79 71 2\n","output":"1\n4\n5\n6\n7\n8\n-1\n1\n2\n3\n4\n5\n6\n7\n8\n","actual_output":"1\n4\n5\n6\n7\n8\n-1\n1\n2\n3\n4\n5\n6\n7\n8\n","execution_success":true,"sample_index":670},{"source":"apps","task_type":"verifiable_code","in_source_id":"1071","prompt":"Solve the following coding problem using the programming language python:\n\nBob just learned about bitwise operators. Since Alice is an expert, she decided to play a game, she will give a number $x$ to Bob and will ask some questions:\nThere will be 4 different kinds of queries:-\n- \nAlice gives an integer $i$ and Bob has to report the status of the $i^{th}$ bit in $x$, the answer is $\"ON\"$ if it is on else $\"OFF\"$.\n- \nAlice gives an integer $i$ and Bob has to turn on the $i^{th}$ bit in $x$.\n- \nAlice gives an integer $i$ and Bob has to turn off the $i^{th}$ bit in $x$.\n- \nAlice gives two integers $p$ and $q$ and in the binary representation of $x$ Bob has to swap the $p^{th}$ and the $q^{th}$ bits.\nThe value of $x$ changes after any update operation.\npositions $i$, $p$, and $q$ are always counted from the right or from the least significant bit.\nIf anyone of $i$, $p$, or $q$ is greater than the number of bits in the binary representation of $x$, consider $0$ at that position.\n\n-----Input:-----\n- First-line will contain $T$, the number of test cases. Then the test cases follow. \n- the first line of each test case contains two space-separated integers $x, Q$.\n- $2Q$ lines follow.\n- first line is an integer, the query type.\n- for each query of type 1 to 3, there will be the integer $i$\n- for the query of type 4, there will be two space-separated integers, the integers $p, q$\n\n-----Output:-----\nFor the queries of the first kind, print $\"ON\"$ or $\"OFF\"$.\n\n-----Constraints-----\n- $1 \\leq T \\leq 10^3$\n- $1 \\leq x \\leq 10^9$\n- $1 \\leq Q \\leq 10^3$\n- $1 \\leq i,p,q \\leq 30$\n\n-----Sample Input-----\n1\n2 2\n2 \n1\n1 \n1\n\n-----Sample Output:-----\nON\n\n-----EXPLANATION:-----\nthe binary representation of 2 is 10\nfor query 1, we just have to update x to 11 (or 3 in decimal).\nfor the next query, x is now 3 or 11 in binary so the answer is ON.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\nt=int(input())\nwhile t>0:\n n,q=list(map(int,input().split()))\n blst=[0]\n for i in range(1,65):\n blst.append(0)\n i=1\n while n>0:\n if n%2:\n blst[i]=1\n n//=2\n i+=1\n while q>0:\n n=int(input())\n if n==1:\n p=int(input())\n if blst[p]:\n print('ON')\n else:\n print('OFF')\n elif n==2:\n p=int(input())\n if blst[p]==0:\n blst[p]=1\n elif n==3:\n p=int(input())\n if blst[p]==1:\n blst[p]=0\n else:\n p,r=list(map(int,input().split()))\n if blst[p]!=blst[r]:\n blst[p]+=1\n blst[p]%=2\n blst[r]+=1\n blst[r]%=2\n q-=1\n t-=1\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n2 2\\n2\\n1\\n1\\n1\\n', 'output': 'ON\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/ENDE2020/problems/ENCDEC03'}","problem_id":"vfc_3126","program":"```python\n# cook your dish here\nt=int(input())\nwhile t>0:\n n,q=list(map(int,input().split()))\n blst=[0]\n for i in range(1,65):\n blst.append(0)\n i=1\n while n>0:\n if n%2:\n blst[i]=1\n n//=2\n i+=1\n while q>0:\n n=int(input())\n if n==1:\n p=int(input())\n if blst[p]:\n print('ON')\n else:\n print('OFF')\n elif n==2:\n p=int(input())\n if blst[p]==0:\n blst[p]=1\n elif n==3:\n p=int(input())\n if blst[p]==1:\n blst[p]=0\n else:\n p,r=list(map(int,input().split()))\n if blst[p]!=blst[r]:\n blst[p]+=1\n blst[p]%=2\n blst[r]+=1\n blst[r]%=2\n q-=1\n t-=1\n\n```","inputs":"1\n2 2\n2\n1\n1\n1\n","output":"ON\n","actual_output":"ON\n","execution_success":true,"sample_index":671},{"source":"apps","task_type":"verifiable_code","in_source_id":"1072","prompt":"Solve the following coding problem using the programming language python:\n\nProblem description.\nWinston and Royce love sharing memes with each other. They express the amount of seconds they laughed ar a meme as the number of \u2018XD\u2019 subsequences in their messages. Being optimization freaks, they wanted to find the string with minimum possible length and having exactly the given number of \u2018XD\u2019 subsequences.\n\n-----Input-----\n- The first line of the input contains an integer T denoting the number of test cases.\n- Next T lines contains a single integer N, the no of seconds laughed.\n\n-----Output-----\n- \nFor each input, print the corresponding string having minimum length. If there are multiple possible answers, print any.\n\n-----Constraints-----\n- 1 \u2264 T \u2264 1000\n- 1 \u2264 N \u2264 109\n- 1 \u2264 Sum of length of output over all testcases \u2264 5*105\n\n-----Example-----\nInput:\n1\n9\n\nOutput:\nXXXDDD\n\n-----Explanation-----\nSome of the possible strings are - XXDDDXD,XXXDDD,XDXXXDD,XDXDXDD etc. Of these, XXXDDD is the smallest.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nt=int(input())\nfor i in range(t):\n n=int(input())\n r=int(n**(.5))\n d=n-r*r\n m=d%r\n print('X'*m+'D'*(m>0)+'X'*(r-m)+'D'*(r+d//r))\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n9\\n', 'output': 'XXXDDD\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/XDS'}","problem_id":"vfc_3130","program":"```python\nt=int(input())\nfor i in range(t):\n n=int(input())\n r=int(n**(.5))\n d=n-r*r\n m=d%r\n print('X'*m+'D'*(m>0)+'X'*(r-m)+'D'*(r+d//r))\n\n```","inputs":"1\n9\n","output":"XXXDDD\n","actual_output":"XXXDDD\n","execution_success":true,"sample_index":672},{"source":"apps","task_type":"verifiable_code","in_source_id":"1073","prompt":"Solve the following coding problem using the programming language python:\n\nYou are given two integers $N$ and $M$. Find the number of sequences $A_1, A_2, \\ldots, A_N$, where each element is an integer between $1$ and $M$ (inclusive) and no three consecutive elements are equal. Since this number could be very large, compute it modulo $10^9+7$.\n\n-----Input-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The first and only line of each test case contains two space-separated integers $N$ and $M$.\n\n-----Output-----\nFor each test case, print a single line containing one integer \u2015 the number of valid sequences modulo $10^9+7$.\n\n-----Constraints-----\n- $1 \\le T \\le 10^5$\n- $1 \\le N, M \\le 10^{18}$\n\n-----Subtasks-----\nSubtask #1 (50 points):\n- $T \\le 20$\n- $N \\le 10^5$\nSubtask #2 (50 points): original constraints\n\n-----Example Input-----\n2 \n2 2\n3 4\n\n-----Example Output-----\n4\n60\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nimport sys\ndef fin(): return sys.stdin.readline().strip()\ndef fout(s, end=\"\\n\"): sys.stdout.write(str(s)+end)\n\nMOD = pow(10, 9)+7\nt = int(input())\nwhile t>0:\n t -= 1\n n, m = list(map(int, fin().split()))\n if n == 1:\n print(m%MOD)\n continue\n dp1 = m*(m-1)\n dp2 = m\n for i in range(3, n+1):\n temp = dp2\n dp2 = dp1 \n dp1 = (temp*(m-1))%MOD+(dp1*(m-1))%MOD\n print((dp1+dp2)%MOD)\n\n \n\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n2 2\\n3 4\\n', 'output': '4\\n60\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/CARR'}","problem_id":"vfc_3134","program":"```python\nimport sys\ndef fin(): return sys.stdin.readline().strip()\ndef fout(s, end=\"\\n\"): sys.stdout.write(str(s)+end)\n\nMOD = pow(10, 9)+7\nt = int(input())\nwhile t>0:\n t -= 1\n n, m = list(map(int, fin().split()))\n if n == 1:\n print(m%MOD)\n continue\n dp1 = m*(m-1)\n dp2 = m\n for i in range(3, n+1):\n temp = dp2\n dp2 = dp1 \n dp1 = (temp*(m-1))%MOD+(dp1*(m-1))%MOD\n print((dp1+dp2)%MOD)\n\n \n\n\n```","inputs":"2\n2 2\n3 4\n","output":"4\n60\n","actual_output":"4\n60\n","execution_success":true,"sample_index":673},{"source":"apps","task_type":"verifiable_code","in_source_id":"1074","prompt":"Solve the following coding problem using the programming language python:\n\nChef is making Window frames for his new office, for this he has n wooden Logs whose lengths are l1,\u2009l2,\u2009\u2026 ln respectively. Chef Doesn\u2019t want to break any logs or Stick 2 or more logs together.\nTo make a h\u2009\u00d7\u2009w Window Frame, he needs two Logs with lengths equal h and two with length . \nThe Chef wants as much sunlight in as possible and for it he has decided to make from the available logs as many frames as possible. Help him in finding the number of window Frames that he can make. \nNote : Chef do not need to use all the logs\nInput:\nThe first line of the input contains a single integer T denoting the number of test cases. The description of each test case follows :.\nThe first line of each test case contains a single integer n the number of wooden logs. \nThe second line contains n space-separated integers l1,l2,l3\u2026.ln The length of each wooden log\nOutput: \nThe only line in Output Contains single Integer denoting the maximum possible number of Wooden Frames.\nConstraints:\n1 \u2264 T \u2264 10\n1 \u2264 n \u2264 100\n1 \u2264 li \u2264 10000\nExample Input:\n2\n4\n1 2 1 2\n8\n1 2 1 3 4 1 5 6\nExample Output:\n1\n0\nExplanation :\nFirst Case : We can build a frame of dimension 1x2 as two logs of each dimension are available.\nSecond Case : We can\u2019t build any Frame as no logs of length except 1 have more than one piece.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\nt=int(input())\nj=0\nwhile j=w1+w2+w3:\n print(1)\n elif n>=w1+w2 or n>=w2+w3:\n print(2)\n else:\n print(3)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\n3 1 2 2\\n2 1 1 1\\n3 2 2 1\\n', 'output': '2\\n2\\n2\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/BRKBKS'}","problem_id":"vfc_3154","program":"```python\nt=int(input())\nfor i in range(t):\n n,w1,w2,w3=map(int,input().split())\n if n>=w1+w2+w3:\n print(1)\n elif n>=w1+w2 or n>=w2+w3:\n print(2)\n else:\n print(3)\n```","inputs":"3\n3 1 2 2\n2 1 1 1\n3 2 2 1\n","output":"2\n2\n2\n","actual_output":"2\n2\n2\n","execution_success":true,"sample_index":678},{"source":"apps","task_type":"verifiable_code","in_source_id":"1079","prompt":"Solve the following coding problem using the programming language python:\n\nKostya likes the number 4 much. Of course! This number has such a lot of properties, like:\n\n- Four is the smallest composite number;\n- It is also the smallest Smith number;\n- The smallest non-cyclic group has four elements;\n- Four is the maximal degree of the equation that can be solved in radicals;\n- There is four-color theorem that states that any map can be colored in no more than four colors in such a way that no two adjacent regions are colored in the same color;\n- Lagrange's four-square theorem states that every positive integer can be written as the sum of at most four square numbers;\n- Four is the maximum number of dimensions of a real division algebra;\n- In bases 6 and 12, 4 is a 1-automorphic number;\n- And there are a lot more cool stuff about this number!\n\nImpressed by the power of this number, Kostya has begun to look for occurrences of four anywhere. He has a list of T integers, for each of them he wants to calculate the number of occurrences of the digit 4 in the decimal representation. He is too busy now, so please help him.\n\n-----Input-----\nThe first line of input consists of a single integer T, denoting the number of integers in Kostya's list.\nThen, there are T lines, each of them contain a single integer from the list.\n\n-----Output-----\nOutput T lines. Each of these lines should contain the number of occurences of the digit 4 in the respective integer from Kostya's list.\n\n-----Constraints-----\n- 1 \u2264 T \u2264 105\n- (Subtask 1): 0 \u2264 Numbers from the list \u2264 9 - 33 points.\n- (Subtask 2): 0 \u2264 Numbers from the list \u2264 109 - 67 points.\n\n-----Example-----\nInput:\n5\n447474\n228\n6664\n40\n81\n\nOutput:\n4\n0\n1\n1\n0\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\nx=int(input())\nfor i in range(x):\n h=input()\n print(h.count('4'))\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '5\\n447474\\n228\\n6664\\n40\\n81\\n', 'output': '4\\n0\\n1\\n1\\n0\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/LUCKFOUR'}","problem_id":"vfc_3158","program":"```python\n# cook your dish here\nx=int(input())\nfor i in range(x):\n h=input()\n print(h.count('4'))\n\n```","inputs":"5\n447474\n228\n6664\n40\n81\n","output":"4\n0\n1\n1\n0\n","actual_output":"4\n0\n1\n1\n0\n","execution_success":true,"sample_index":679},{"source":"apps","task_type":"verifiable_code","in_source_id":"1080","prompt":"Solve the following coding problem using the programming language python:\n\nEvery day, Mike goes to his job by a bus, where he buys a ticket. On the ticket, there is a letter-code that can be represented as a string of upper-case Latin letters.\nMike believes that the day will be successful in case exactly two different letters in the code alternate. Otherwise, he believes that the day will be unlucky. Please see note section for formal definition of alternating code.\nYou are given a ticket code. Please determine, whether the day will be successful for Mike or not. Print \"YES\" or \"NO\" (without quotes) corresponding to the situation.\n\n-----Input-----\nThe first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.\nThe first and only line of each test case contains a single string S denoting the letter code on the ticket.\n\n-----Output-----\nFor each test case, output a single line containing \"YES\" (without quotes) in case the day will be successful and \"NO\" otherwise.\n\n-----Note-----\nTwo letters x, y where x != y are said to be alternating in a code, if code is of form \"xyxyxy...\".\n\n-----Constraints-----\n\n- 1 \u2264 T \u2264 100\n- S consists only of upper-case Latin letters\n\nSubtask 1 (50 points):\n\n- |S| = 2\n\nSubtask 2 (50 points):\n\n- 2 \u2264 |S| \u2264 100\n\n-----Example-----\nInput:\n2\nABABAB\nABC\n\nOutput:\nYES\nNO\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\ndef res(s):\n if len(s) == 2:\n if s[0] == s[1]:\n print(\"NO\")\n else:\n print(\"YES\")\n\n elif s[0] != s[1]:\n counte = 0\n for i in range(2, len(s)):\n if i % 2 == 0:\n if s[i] != s[0]:\n counte = 1\n break\n else:\n if s[i] != s[1]:\n counte = 1\n break\n\n if counte == 0:\n print(\"YES\")\n else:\n print(\"NO\")\n else:\n print(\"NO\")\n\n\ndef __starting_point():\n t = int(input())\n for _ in range(t):\n stri = str(input())\n res(stri)\n__starting_point()\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\nABABAB\\nABC\\n', 'output': 'YES\\nNO\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/TICKETS5'}","problem_id":"vfc_3162","program":"```python\ndef res(s):\n if len(s) == 2:\n if s[0] == s[1]:\n print(\"NO\")\n else:\n print(\"YES\")\n\n elif s[0] != s[1]:\n counte = 0\n for i in range(2, len(s)):\n if i % 2 == 0:\n if s[i] != s[0]:\n counte = 1\n break\n else:\n if s[i] != s[1]:\n counte = 1\n break\n\n if counte == 0:\n print(\"YES\")\n else:\n print(\"NO\")\n else:\n print(\"NO\")\n\n\ndef __starting_point():\n t = int(input())\n for _ in range(t):\n stri = str(input())\n res(stri)\n__starting_point()\n```","inputs":"2\nABABAB\nABC\n","output":"YES\nNO\n","actual_output":"YES\nNO\n","execution_success":true,"sample_index":680},{"source":"apps","task_type":"verifiable_code","in_source_id":"1081","prompt":"Solve the following coding problem using the programming language python:\n\nA spy needs your help to encrypt a 5 letter message. \nTo encrypt the message the following steps are need to be done:\n1)Each letter of the message will be converted to it's equivalent number (i.e A=0, B=1,..Z=25) \n2)98, 57, 31, 45, 46 are the 5 numbers in the key.\n3)Add the equivalent number of the first letter of the message to the first number of the key, then the equivalent number of the second letter of the message to the second number of the key and so on.\n4)Take modulo 26 of the sum of each expression.\n5)Convert the newly obtained numbers into it's equivalent letters (i.e 0=A, 1=B,\u202625=Z)\nPrint the final encrypted string.\nNote: It is guaranteed that the given string only contains Only Upper-case Latin Letters.\n\n-----Input:-----\n- The first line of the input contains a single Integer $T$. $T$ denoting the number of testcases, description of each testcases contains.\n- The first line of the each testcase contains a single string $S$. $S$ denoting the string which you need to encrypt\n\n-----Output:-----\n- For each test case, print encypted string i.e result of above operation.\nNote: Each testcase output must be printed on new line\n\n-----Constraints:-----\n- $1 \\leq T \\leq 100$\n- $1 \\leq S \\leq 5$\n\n-----Sample Input:-----\n2\nHELLO\nHELL\n\n-----Sample Output:-----\nBJQEI\nBJQE\n\n-----Explanation:-----\n- For 1st Testcase : The conversion of \"HELLO\" to its equivalent number will be 7, 4, 11, 11, 14 respectively.\nThen we add each equivalent number of the message with corresponding number in the key:\n7 + 98 = 105\n4 + 57 = 61 \n11 + 31 = 42 \n11 + 45 = 56\n14 + 46 = 60\nFurther we take the sum:\n105 modulo 26 = 1\n61 modulo 26 = 9\n42 modulo 26 = 16\n56 modulo 26 = 4\n60 modulo 26 = 8 \nFinally, convert the newly obtained numbers into it's equivalent letters:\nB\nJ\nQ\nE\nI\nPrint the final string:\nBJQEI\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\nimport string \nfrom collections import OrderedDict\nfrom itertools import zip_longest\ndic = OrderedDict(zip(string.ascii_uppercase, range(0, 26)))\nkeys = [98, 57, 31, 45, 46]\nt = int(input()) # number of test cases\ns1 = []\nfor i in range(t):\n s = input()\n for i in s:\n if i in dic.keys():\n s1.append(int(i.replace(i, str(dic[i]))))\n s2 = [sum(t) for t in zip_longest(s1, keys, fillvalue=0)]\n inv_dic = {v:k for k,v in dic.items()}\n s_1 = list()\n for i in range(len(s1)):\n s_1.append(s2[i]%26)\n res= [inv_dic[i] for i in s_1]\n print(''.join(res))\n inv_dic.clear()\n res.clear()\n s1.clear()\n s2.clear()\n s_1.clear()\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\nHELLO\\nHELL\\n', 'output': 'BJQEI\\nBJQE\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/STRG2020/problems/ENCYP'}","problem_id":"vfc_3166","program":"```python\n# cook your dish here\nimport string \nfrom collections import OrderedDict\nfrom itertools import zip_longest\ndic = OrderedDict(zip(string.ascii_uppercase, range(0, 26)))\nkeys = [98, 57, 31, 45, 46]\nt = int(input()) # number of test cases\ns1 = []\nfor i in range(t):\n s = input()\n for i in s:\n if i in dic.keys():\n s1.append(int(i.replace(i, str(dic[i]))))\n s2 = [sum(t) for t in zip_longest(s1, keys, fillvalue=0)]\n inv_dic = {v:k for k,v in dic.items()}\n s_1 = list()\n for i in range(len(s1)):\n s_1.append(s2[i]%26)\n res= [inv_dic[i] for i in s_1]\n print(''.join(res))\n inv_dic.clear()\n res.clear()\n s1.clear()\n s2.clear()\n s_1.clear()\n```","inputs":"2\nHELLO\nHELL\n","output":"BJQEI\nBJQE\n","actual_output":"BJQEI\nBJQE\n","execution_success":true,"sample_index":681},{"source":"apps","task_type":"verifiable_code","in_source_id":"1084","prompt":"Solve the following coding problem using the programming language python:\n\nYou are given a binary string S. You need to transform this string into another string of equal length consisting only of zeros, with the minimum number of operations.\nA single operation consists of taking some prefix of the string S and flipping all its values. That is, change all the 0s in this prefix to 1s, and all the 1s in the prefix to 0s. You can use this operation as many number of times as you want over any prefix of the string.\n\n-----Input-----\nThe only line of the input contains the binary string, S . \n\n-----Output-----\nOutput a single line containing one integer, the minimum number of operations that are needed to transform the given string S into the string of equal length consisting only of zeros.\n\n-----Constraints-----\n- 1 \u2264 |S| \u2264 100,000\n\n-----Subtasks-----\n- Subtask #1 (30 points): 1 \u2264 |S| \u2264 2000\n- Subtask #2 (70 points): Original constraints.\n\n-----Example-----\nInput:\n01001001\n\nOutput:\n6\n\n-----Explanation-----\nFor the given sample case, let us look at the way where we achieved minimum number of operations.\n\nOperation 1: You flip values in the prefix of length 8 and transform the string into 10110110 \nOperation 2: You flip values in the prefix of length 7 and transform the string into 01001000 \nOperation 3: You flip values in the prefix of length 5 and transform the string into 10110000 \nOperation 4: You flip values in the prefix of length 4 and transform the string into 01000000 \nOperation 5: You flip values in the prefix of length 2 and transform the string into 10000000 \nOperation 6: You flip values in the prefix of length 1 and finally, transform the string into 00000000\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\ns=input()\ns1=s[::-1]\narr=[]\ncnt=0\nfor i in range(len(s1)):\n arr.append(s1[i])\nfor i in range(len(arr)):\n if(arr[i]==\"1\"):\n for j in range(i,len(arr)):\n if(arr[j]==\"1\"):\n arr[j]=\"0\"\n else:\n arr[j]=\"1\"\n cnt+=1\nprint(cnt)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '01001001\\n', 'output': '6\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/PREFINVS'}","problem_id":"vfc_3178","program":"```python\n# cook your dish here\ns=input()\ns1=s[::-1]\narr=[]\ncnt=0\nfor i in range(len(s1)):\n arr.append(s1[i])\nfor i in range(len(arr)):\n if(arr[i]==\"1\"):\n for j in range(i,len(arr)):\n if(arr[j]==\"1\"):\n arr[j]=\"0\"\n else:\n arr[j]=\"1\"\n cnt+=1\nprint(cnt)\n```","inputs":"01001001\n","output":"6\n","actual_output":"6\n","execution_success":true,"sample_index":683},{"source":"apps","task_type":"verifiable_code","in_source_id":"1085","prompt":"Solve the following coding problem using the programming language python:\n\n-----Problem-----\n\n\t\t\tOnce THANMAY met PK who is from a different planet visiting earth. THANMAY was very fascinate to learn PK's language. The language contains only lowercase English letters and is based on a simple logic that only certain characters can follow a particular character.\n\n\n\t\t\tNow he is interested in calculating the number of possible words of length L and ending at a particular character C. Help THANMAY to calculate this value. \n\n-----Input-----\n\n\t\t\tThe input begins with 26 lines, each containing 26 space-separated integers. The integers can be either 0 or 1. The jth integer at ith line depicts whether jth English alphabet can follow ith English alphabet or not.\n\n\n\t\t\t Next line contains an integer T. T is the number of queries.\n\n\t\t\t Next T lines contains a character C and an integer L.\n\n-----Output-----\n\n\t\t\tFor each query output the count of words of length L ending with the character C. Answer to each query must be followed by newline character.\n\n\n\t\t\tThe answer may be very large so print it modulo 1000000007.\n\n-----Constraints-----\n- \n\t\t\t\t\t1 \u2264 T \u2264 100\n- \nC is lowercase English alphabet.\n\n- \n\t\t\t\t\t2 \u2264 L \u2264 10000000\n\t\t\n\n-----Sample Input-----\n0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n\n1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n\n0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n\n2\n\nc 3\n\nb 2\n\n-----Sample Output-----\n1\n\n2\n\n-----Explanation-----\n\n\t\t\tFor query 1, Words of length 3 are: aba, acb, bab, bac, cba. The only word ending with 'c' is bac.\n\t\t p { text-align:justify }\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nd = {}\nfor i in range(26):\n char = chr(i+ord('a'))\n d[char] = []\nfor i in range(26):\n char = chr(i+ord('a'))\n temp = list(map(int,input().strip().split()))\n for j in range(26):\n if (temp[j] == 1):\n follow= chr(j+ord('a'))\n d[follow].append(char)\n \ndef f(char,i,n,count):\n if (i==n):\n return count+1\n else:\n ans = 0\n for c in d[char]:\n ans+=f(c,i+1,n,0)\n ans%=(10**9+7)\n return ans\n\nfor q in range(int(input().strip())):\n c, n = input().strip().split()\n n = int(n)\n print(f(c,1,n,0))\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\\n1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\\n0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\\n2\\nc 3\\nb 2\\n', 'output': '1\\n2\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/COMN2016/problems/THANPK'}","problem_id":"vfc_3182","program":"```python\nd = {}\nfor i in range(26):\n char = chr(i+ord('a'))\n d[char] = []\nfor i in range(26):\n char = chr(i+ord('a'))\n temp = list(map(int,input().strip().split()))\n for j in range(26):\n if (temp[j] == 1):\n follow= chr(j+ord('a'))\n d[follow].append(char)\n \ndef f(char,i,n,count):\n if (i==n):\n return count+1\n else:\n ans = 0\n for c in d[char]:\n ans+=f(c,i+1,n,0)\n ans%=(10**9+7)\n return ans\n\nfor q in range(int(input().strip())):\n c, n = input().strip().split()\n n = int(n)\n print(f(c,1,n,0))\n```","inputs":"0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n2\nc 3\nb 2\n","output":"1\n2\n","actual_output":"1\n2\n","execution_success":true,"sample_index":684},{"source":"apps","task_type":"verifiable_code","in_source_id":"1086","prompt":"Solve the following coding problem using the programming language python:\n\nLet's define the niceness of a sequence of positive integers X1,X2,\u2026,XN$X_1, X_2, \\dots, X_N$ as the sum of greatest common divisors of all pairs of its elements, i.e.\nN\u2211i=1N\u2211j=i+1gcd(Xi,Xj).\u2211i=1N\u2211j=i+1Ngcd(Xi,Xj).\\sum_{i=1}^N \\sum_{j=i+1}^N \\mathrm{gcd}(X_i, X_j)\\;.\nFor example, the niceness of the sequence [1,2,2]$[1, 2, 2]$ is gcd(1,2)+gcd(1,2)+gcd(2,2)=4$gcd(1, 2) + gcd(1, 2) + gcd(2, 2) = 4$.\nYou are given a sequence A1,A2,\u2026,AN$A_1, A_2, \\dots, A_N$; each of its elements is either a positive integer or missing.\nConsider all possible ways to replace each missing element of A$A$ by a positive integer (not necessarily the same for each element) such that the sum of all elements is equal to S$S$. Your task is to find the total niceness of all resulting sequences, i.e. compute the niceness of each possible resulting sequence and sum up all these values. Since the answer may be very large, compute it modulo 109+7$10^9 + 7$.\n\n-----Input-----\n- 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.\n- The first line of each test case contains two space-separated integers N$N$ and S$S$. \n- The second line contains N$N$ space-separated integers A1,A2,\u2026,AN$A_1, A_2, \\dots, A_N$. Missing elements in this sequence are denoted by \u22121$-1$.\n\n-----Output-----\nFor each test case, print a single line containing one integer \u2014 the total niceness modulo 109+7$10^9 + 7$.\n\n-----Constraints-----\n- 1\u2264T\u226420$1 \\le T \\le 20$\n- 1\u2264N,S\u226450$1 \\le N, S \\le 50$\n- 1\u2264Ai\u226450$1 \\le A_i \\le 50$ or Ai=\u22121$A_i = -1$ for each valid i$i$\n\n-----Subtasks-----\nSubtask #1 (30 points):\n- 1\u2264N,S\u226418$1 \\le N, S \\le 18$\n- 1\u2264Ai\u226418$1 \\le A_i \\le 18$ or Ai=\u22121$A_i = -1$ for each valid i$i$\nSubtask #2 (70 points): original constraints\n\n-----Example Input-----\n3\n3 3\n1 1 -1\n4 8\n1 -1 -1 3\n3 10\n-1 -1 -1\n\n-----Example Output-----\n3\n23\n150\n\n-----Explanation-----\nExample case 1: There is only one possible way to fill in the missing element; the resulting sequence is [1,1,1]$[1, 1, 1]$. Its niceness is 3$3$.\nExample case 2: There is only three possible ways to fill in the missing elements; the resulting sequences are [1,1,3,3]$[1, 1, 3, 3]$, [1,3,1,3]$[1, 3, 1, 3]$, and [1,2,2,3]$[1, 2, 2, 3]$. The sum of their niceness is 8+8+7=23$8 + 8 + 7 = 23$.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\nmod = 10**9 + 7\nfrom math import gcd\ndef fac50():\n f = [0]*51\n f[0] ,f[1] = 1,1\n for i in range(1,51):f[i] = (f[i-1]*i)%mod\n return f\ndef gcd110():\n gc = [[0]*111 for i in range(111)]\n for i in range(111):\n for j in range(111):gc[i][j] = gcd(i,j)\n return gc\nfactorials,gcds = fac50(),gcd110()\ndef rule_asc(n,l):\n a,k = [0 for i in range(n + 1)],1\n a[1] = n\n while k != 0:\n x,y = a[k - 1] + 1,a[k] - 1 \n k -= 1\n while x <= y and k < l - 1:\n a[k],y = x,y-x\n k += 1\n a[k] = x + y\n yield a[:k + 1]\ndef niceness(s):\n t = 0\n for i in range(len(s)):\n for j in range(i+1,len(s)):t = (t + gcds[s[i]][s[j]])%mod\n return t\ndef permcount(s,c):\n f,p = [s.count(x) for x in set(s)],factorials[c] \n for e in f:p = (p*pow(factorials[e],mod-2,mod))%mod\n return p\ndef main():\n for i in range(int(input())):\n n,s = [int(item) for item in input().split()]\n a = [int(item) for item in input().split()]\n b = [i for i in a if i != -1]\n s , ones = s - sum(b),a.count(-1) \n if s < 0:print(0)\n elif (s == 0 and ones == 0):print(niceness(a)%mod)\n elif (s > 0 and ones == 0):print(0)\n else:\n t = 0\n for seq in rule_asc(s,ones):\n if len(seq) == ones: t = (t + (((permcount(seq,ones))%mod)*(niceness(b+seq)%mod))%mod)%mod\n print(t) \ndef __starting_point():main()\n__starting_point()\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\n3 3\\n1 1 -1\\n4 8\\n1 -1 -1 3\\n3 10\\n-1 -1 -1\\n\\n', 'output': '3\\n23\\n150\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/NICARRAY'}","problem_id":"vfc_3186","program":"```python\n# cook your dish here\nmod = 10**9 + 7\nfrom math import gcd\ndef fac50():\n f = [0]*51\n f[0] ,f[1] = 1,1\n for i in range(1,51):f[i] = (f[i-1]*i)%mod\n return f\ndef gcd110():\n gc = [[0]*111 for i in range(111)]\n for i in range(111):\n for j in range(111):gc[i][j] = gcd(i,j)\n return gc\nfactorials,gcds = fac50(),gcd110()\ndef rule_asc(n,l):\n a,k = [0 for i in range(n + 1)],1\n a[1] = n\n while k != 0:\n x,y = a[k - 1] + 1,a[k] - 1 \n k -= 1\n while x <= y and k < l - 1:\n a[k],y = x,y-x\n k += 1\n a[k] = x + y\n yield a[:k + 1]\ndef niceness(s):\n t = 0\n for i in range(len(s)):\n for j in range(i+1,len(s)):t = (t + gcds[s[i]][s[j]])%mod\n return t\ndef permcount(s,c):\n f,p = [s.count(x) for x in set(s)],factorials[c] \n for e in f:p = (p*pow(factorials[e],mod-2,mod))%mod\n return p\ndef main():\n for i in range(int(input())):\n n,s = [int(item) for item in input().split()]\n a = [int(item) for item in input().split()]\n b = [i for i in a if i != -1]\n s , ones = s - sum(b),a.count(-1) \n if s < 0:print(0)\n elif (s == 0 and ones == 0):print(niceness(a)%mod)\n elif (s > 0 and ones == 0):print(0)\n else:\n t = 0\n for seq in rule_asc(s,ones):\n if len(seq) == ones: t = (t + (((permcount(seq,ones))%mod)*(niceness(b+seq)%mod))%mod)%mod\n print(t) \ndef __starting_point():main()\n__starting_point()\n```","inputs":"3\n3 3\n1 1 -1\n4 8\n1 -1 -1 3\n3 10\n-1 -1 -1\n\n","output":"3\n23\n150\n","actual_output":"3\n23\n150\n","execution_success":true,"sample_index":685},{"source":"apps","task_type":"verifiable_code","in_source_id":"1087","prompt":"Solve the following coding problem using the programming language python:\n\nYou are given an unweighted, undirected graph. Write a program to check if it's a tree topology.\n\n-----Input-----\n\nThe first line of the input file contains two integers N and M --- number of nodes and number of edges in the graph (0 < N <= 10000, 0 <= M <= 20000). Next M lines contain M edges of that graph --- Each line contains a pair (u, v) means there is an edge between node u and node v (1 <= u,v <= N).\n\n-----Output-----\n\nPrint YES if the given graph is a tree, otherwise print NO.\n\n-----Example-----\nInput:\n3 2\n1 2\n2 3\n\nOutput:\nYES\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n#!/usr/bin/env python\n\ndef iscycle(E, v, EXPLORED_NODES, EXPLORED_EDGES):\n EXPLORED_NODES.add(v)\n r = False\n for e in [x for x in E if v in x]:\n if e in EXPLORED_EDGES: continue\n if e[0] == v: w = e[1]\n else: w = e[0]\n if w in EXPLORED_NODES:\n return True\n else:\n EXPLORED_EDGES.add(e)\n r = r or iscycle(E, w, EXPLORED_NODES, EXPLORED_EDGES)\n if r: break\n return r\n\ndef process(E):\n return iscycle(E, 1, set(), set()) and 'NO' or 'YES'\n\ndef main():\n N, M = list(map(int, input().split()))\n E = []\n for m in range(M):\n U, V = list(map(int, input().split()))\n if U > V: U, V = V, U\n E.append((U, V))\n print(process(E))\n\nmain()\n\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3 2\\n1 2\\n2 3\\n', 'output': 'YES\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/PRFT2012/problems/PD31'}","problem_id":"vfc_3190","program":"```python\n#!/usr/bin/env python\n\ndef iscycle(E, v, EXPLORED_NODES, EXPLORED_EDGES):\n EXPLORED_NODES.add(v)\n r = False\n for e in [x for x in E if v in x]:\n if e in EXPLORED_EDGES: continue\n if e[0] == v: w = e[1]\n else: w = e[0]\n if w in EXPLORED_NODES:\n return True\n else:\n EXPLORED_EDGES.add(e)\n r = r or iscycle(E, w, EXPLORED_NODES, EXPLORED_EDGES)\n if r: break\n return r\n\ndef process(E):\n return iscycle(E, 1, set(), set()) and 'NO' or 'YES'\n\ndef main():\n N, M = list(map(int, input().split()))\n E = []\n for m in range(M):\n U, V = list(map(int, input().split()))\n if U > V: U, V = V, U\n E.append((U, V))\n print(process(E))\n\nmain()\n\n\n```","inputs":"3 2\n1 2\n2 3\n","output":"YES\n","actual_output":"YES\n","execution_success":true,"sample_index":686},{"source":"apps","task_type":"verifiable_code","in_source_id":"1088","prompt":"Solve the following coding problem using the programming language python:\n\nTwo cheeky thieves (Chef being one of them, the more talented one of course) have came across each other in the underground vault of the State Bank of Churuland. They are shocked! Indeed, neither expect to meet a colleague in such a place with the same intentions to carry away all the money collected during Churufest 2015.\n\nThey have carefully counted a total of exactly 1 billion (109) dollars in the bank vault. Now they must decide how to divide the booty. But there is one problem: the thieves have only M minutes to leave the bank before the police arrives. Also, the more time they spend in the vault, the less amount could carry away from the bank. Formally speaking, they can get away with all of the billion dollars right now, but after t minutes they can carry away only 1 billion * pt dollars, where p is some non-negative constant less than or equal to unity, and at t = M, they get arrested and lose all the money.\nThey will not leave the vault until a decision on how to divide the money has been made.\n\nThe money division process proceeds in the following way: at the beginning of each minute starting from the 1st (that is, t = 0), one of them proposes his own way to divide the booty. If his colleague agrees, they leave the bank with pockets filled with the proposed amounts of dollars. If not, the other one proposes his way at the next minute etc. To escape arrest, they can only propose plans till the beginning of the Mth minute (i.e., till t = M-1).\nEach thief wants to maximize his earnings, but if there are two plans with the same amounts for him, he would choose the one which leads to a larger total amount of stolen dollars.\n\nChef is about to start this procedure, and he is the first to propose a plan. You are wondering what will be the final division of money, if each thief chooses the optimal way for himself and money is considering real.\n\n-----Input-----\nThe first line of input contains an integer T denoting the number of test cases. The description of T test cases follows. The only line of input for each test case contains an integer M denoting the number of minutes until arrest and a double denoting the constant p.\n\n-----Output-----\nFor each test case, output a single line containing two space-separated doubles denoting the amount of dollars each thief will get in the optimal division. First number: dollars amassed by Chef, and second: by his colleague. The answer will be considered correct if its absolute error doesn't exceed 10-2.\n\n\n-----Constraints and subtasks-----\n- 1 \u2264 T \u2264 105\n- 0 \u2264 p \u2264 1 \nSubtask 1 (15 points) : \n1 \u2264 M \u2264 3\nSubtask 2 (55 points) : \n1 \u2264 M \u2264 103\nSubtask 3 (30 points) : \n1 \u2264 M \u2264 109\n\n-----Example-----\nInput:\n2\n1 0.5\n2 0.5\nOutput:\n1000000000.0 0.0\n500000000.0 500000000.0\n\n-----Explanation-----\nExample case 1. In the second case, if decision isn't made at t = 0, total amount of money decreases to 5*108 at t = 1 which leads to a situation worse than the given solution.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nt=int(input())\nwhile(t):\n s=input().split()\n m=int(s[0])\n p=float(s[1])\n if(m%2==0):\n r=(1-p**m)/(p+1)\n else:\n r=(1+p**m)/(p+1)\n print(1000000000*r,1000000000*(1-r))\n t-=1\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n1 0.5\\n2 0.5\\n', 'output': '1000000000.0 0.0\\n500000000.0 500000000.0\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/BANROB'}","problem_id":"vfc_3194","program":"```python\nt=int(input())\nwhile(t):\n s=input().split()\n m=int(s[0])\n p=float(s[1])\n if(m%2==0):\n r=(1-p**m)/(p+1)\n else:\n r=(1+p**m)/(p+1)\n print(1000000000*r,1000000000*(1-r))\n t-=1\n```","inputs":"2\n1 0.5\n2 0.5\n","output":"1000000000.0 0.0\n500000000.0 500000000.0\n","actual_output":"1000000000.0 0.0\n500000000.0 500000000.0\n","execution_success":true,"sample_index":687},{"source":"apps","task_type":"verifiable_code","in_source_id":"1090","prompt":"Solve the following coding problem using the programming language python:\n\nYou are given a sequence of n integers a1, a2, ..., an and an integer d.\nFind the length of the shortest non-empty contiguous subsequence with sum of elements at least d. Formally, you should find the smallest positive integer k with the following property: there is an integer s (1 \u2264 s \u2264 N-k+1) such that as + as+1 + ... + as+k-1 \u2265 d.\n\n-----Input-----\n\n- The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows.\n- The first line of each test case contains two space-separated integers n and d.\n- The second line contains n space-separated integers a1, a2, ..., an.\n\n-----Output-----\nFor each test case, print a single line containing one integer \u2014 the length of the shortest contiguous subsequence with sum of elements \u2265 d. If there is no such subsequence, print -1 instead.\n\n-----Constraints-----\n- 1 \u2264 T \u2264 105\n- 1 \u2264 n \u2264 105\n- -109 \u2264 d \u2264 109\n- -104 \u2264 ai \u2264 104\n- 1 \u2264 sum of n over all test cases \u2264 2 \u00b7 105\n\n-----Example-----\nInput:\n\n2\n5 5\n1 2 3 1 -5\n5 1\n1 2 3 1 -5\n\nOutput:\n\n2\n1\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\n\nimport collections\n\ndef shortestSubarray(A, K):\n \n \n N = len(A)\n P = [0]\n\n for x in A:\n P.append(P[-1] + x)\n\n #Want smallest y-x with Py - Px >= K\n ans = N+1 # N+1 is impossible\n monoq = collections.deque() #opt(y) candidates, represented as indices \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0of P\n for y, Py in enumerate(P):\n #Want opt(y) = largest x with Px <= Py - K\n if not monoq: \n if Py>=K: return 1\n while monoq and Py <= P[monoq[-1]]:\n monoq.pop()\n\n while monoq and Py - P[monoq[0]] >= K:\n ans = min(ans, y - monoq.popleft())\n\n monoq.append(y)\n\n return ans if ans < N+1 else -1\n \n \nfor t in range(int(input())):\n N, D = [int(x) for x in input().split()]\n \n A = [int(x) for x in input().split()] \n \n print(shortestSubarray(A, D))\n \n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n5 5\\n1 2 3 1 -5\\n5 1\\n1 2 3 1 -5\\n', 'output': '2\\n1\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/MINSUBAR'}","problem_id":"vfc_3202","program":"```python\n# cook your dish here\n\nimport collections\n\ndef shortestSubarray(A, K):\n \n \n N = len(A)\n P = [0]\n\n for x in A:\n P.append(P[-1] + x)\n\n #Want smallest y-x with Py - Px >= K\n ans = N+1 # N+1 is impossible\n monoq = collections.deque() #opt(y) candidates, represented as indices \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0of P\n for y, Py in enumerate(P):\n #Want opt(y) = largest x with Px <= Py - K\n if not monoq: \n if Py>=K: return 1\n while monoq and Py <= P[monoq[-1]]:\n monoq.pop()\n\n while monoq and Py - P[monoq[0]] >= K:\n ans = min(ans, y - monoq.popleft())\n\n monoq.append(y)\n\n return ans if ans < N+1 else -1\n \n \nfor t in range(int(input())):\n N, D = [int(x) for x in input().split()]\n \n A = [int(x) for x in input().split()] \n \n print(shortestSubarray(A, D))\n \n\n```","inputs":"2\n5 5\n1 2 3 1 -5\n5 1\n1 2 3 1 -5\n","output":"2\n1\n","actual_output":"2\n1\n","execution_success":true,"sample_index":688},{"source":"apps","task_type":"verifiable_code","in_source_id":"1091","prompt":"Solve the following coding problem using the programming language python:\n\nRupsa really loves triangles. One day she came across an equilateral triangle having length of each side as an integer N. She started wondering if it was possible to transform the triangle keeping two sides fixed and alter the third side such that it still remains a triangle, but the altered side will have its length as an even integer, and the line drawn from the opposite vertex to the mid-point of the altered side is of integral length.\nSince Rupsa is in a hurry to record a song for Chef as he really loves her songs, you must help her solve the problem as fast as possible.\n\n-----Input-----\nThe first line of input contains an integer T denoting the number of test cases.\nEach test-case contains a single integer N.\n\n-----Output-----\n\nFor each test case, output \"YES\" if the triangle transformation is possible, otherwise \"NO\" (quotes for clarity only, do not output).\n\n-----Constraints-----\n- 1 \u2264 T \u2264 106\n- 1 \u2264 N \u2264 5 x 106\n\n-----Sub tasks-----\n- Subtask #1: 1 \u2264 T \u2264 100, 1 \u2264 N \u2264 104 (10 points)\n- Subtask #2: 1 \u2264 T \u2264 104, 1 \u2264 N \u2264 106 (30 points)\n- Subtask #3: Original Constraints (60 points)\n\n-----Example-----\nInput:2\n5\n3\n\nOutput:YES\nNO\n\n-----Explanation-----\n- In test case 1, make the length of any one side 6, and it will suffice.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\nimport math\ndef isPos(num):\n if num%2==0:\n for i in range(num,2*num,1):\n if ((num**2)-((i/2)**2))**(1/2)==int(((num**2)-((i/2)**2))**(1/2)):\n return 'YES'\n return 'NO'\n else:\n for i in range(num+1,2*num,1):\n if ((num**2)-((i/2)**2))**(1/2)==int(((num**2)-((i/2)**2))**(1/2)):\n return 'YES'\n return 'NO'\n\ntest = int(input())\nfor __ in range(test):\n num=int(input())\n print(isPos(num))\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n5\\n3\\n', 'output': 'YES\\nNO\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/ADTRI'}","problem_id":"vfc_3206","program":"```python\n# cook your dish here\nimport math\ndef isPos(num):\n if num%2==0:\n for i in range(num,2*num,1):\n if ((num**2)-((i/2)**2))**(1/2)==int(((num**2)-((i/2)**2))**(1/2)):\n return 'YES'\n return 'NO'\n else:\n for i in range(num+1,2*num,1):\n if ((num**2)-((i/2)**2))**(1/2)==int(((num**2)-((i/2)**2))**(1/2)):\n return 'YES'\n return 'NO'\n\ntest = int(input())\nfor __ in range(test):\n num=int(input())\n print(isPos(num))\n\n```","inputs":"2\n5\n3\n","output":"YES\nNO\n","actual_output":"YES\nNO\n","execution_success":true,"sample_index":689},{"source":"apps","task_type":"verifiable_code","in_source_id":"1092","prompt":"Solve the following coding problem using the programming language python:\n\nThe faculty of application management and consulting services (FAMCS) of the Berland State University (BSU) has always been popular among Berland's enrollees. This year, N students attended the entrance exams, but no more than K will enter the university. In order to decide who are these students, there are series of entrance exams. All the students with score strictly greater than at least (N-K) students' total score gets enrolled.\nIn total there are E entrance exams, in each of them one can score between 0 and M points, inclusively. The first E-1 exams had already been conducted, and now it's time for the last tribulation.\nSergey is the student who wants very hard to enter the university, so he had collected the information about the first E-1 from all N-1 enrollees (i.e., everyone except him). Of course, he knows his own scores as well.\nIn order to estimate his chances to enter the University after the last exam, Sergey went to a fortune teller. From the visit, he learnt about scores that everyone except him will get at the last exam. Now he wants to calculate the minimum score he needs to score in order to enter to the university. But now he's still very busy with minimizing the amount of change he gets in the shops, so he asks you to help him.\n\n-----Input-----\nThe first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.\nThe first line of each test case contains four space separated integers N, K, E, M denoting the number of students, the maximal number of students who'll get enrolled, the total number of entrance exams and maximal number of points for a single exam, respectively.\nThe following N-1 lines will contain E integers each, where the first E-1 integers correspond to the scores of the exams conducted. The last integer corresponds to the score at the last exam, that was predicted by the fortune-teller.\nThe last line contains E-1 integers denoting Sergey's score for the first E-1 exams.\n\n-----Output-----\n\nFor each test case, output a single line containing the minimum score Sergey should get in the last exam in order to be enrolled. If Sergey doesn't have a chance to be enrolled, output \"Impossible\" (without quotes).\n\n-----Constraints-----\n\n- 1 \u2264 T \u2264 5\n- 1 \u2264 K < N \u2264 104\n- 1 \u2264 M \u2264 109\n- 1 \u2264 E \u2264 4\n\n-----Example-----\nInput:1\n4 2 3 10\n7 7 7\n4 6 10\n7 10 9\n9 9\n\nOutput:4\n\n-----Explanation-----\nExample case 1. If Sergey gets 4 points at the last exam, his score will be equal to 9+9+4=22. This will be the second score among all the enrollees - the first one will get 21, the second one will get 20 and the third will have the total of 26. Thus, Sergey will enter the university.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\nt=int(input())\nfor i in range(t):\n (n,k,e,m)=tuple(map(int,input().split()))\n scores=[]\n for j in range(n-1):\n scores.append(sum(list(map(int,input().split()))))\n scores.sort(reverse=True);\n bsc=scores[k-1];\n msc=sum(list(map(int,input().split())))\n mini=bsc-msc+1\n if(mini<0):\n print(0)\n elif(mini>m):\n print(\"Impossible\")\n else:\n print(mini)\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n4 2 3 10\\n7 7 7\\n4 6 10\\n7 10 9\\n9 9\\n', 'output': '4\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/ENTEXAM'}","problem_id":"vfc_3210","program":"```python\n# cook your dish here\nt=int(input())\nfor i in range(t):\n (n,k,e,m)=tuple(map(int,input().split()))\n scores=[]\n for j in range(n-1):\n scores.append(sum(list(map(int,input().split()))))\n scores.sort(reverse=True);\n bsc=scores[k-1];\n msc=sum(list(map(int,input().split())))\n mini=bsc-msc+1\n if(mini<0):\n print(0)\n elif(mini>m):\n print(\"Impossible\")\n else:\n print(mini)\n\n```","inputs":"1\n4 2 3 10\n7 7 7\n4 6 10\n7 10 9\n9 9\n","output":"4\n","actual_output":"4\n","execution_success":true,"sample_index":690},{"source":"apps","task_type":"verifiable_code","in_source_id":"1093","prompt":"Solve the following coding problem using the programming language python:\n\nChef likes toys. His favourite toy is an array of length N. This array contains only integers. He plays with this array every day. His favourite game with this array is Segment Multiplication. In this game, the second player tells the left and right side of a segment and some modulo. The first player should find the multiplication of all the integers in this segment of the array modulo the given modulus. Chef is playing this game. Of course, he is the first player and wants to win all the games. To win any game he should write the correct answer for each segment. Although Chef is very clever, he has no time to play games. Hence he asks you to help him. Write the program that solves this problem.\n\n-----Input-----\nThe first line of the input contains an integer N denoting the number of elements in the given array. Next line contains N integers Ai separated with spaces. The third line contains the number of games T. Each of the next T lines contain 3 integers Li, Ri and Mi, the left side of the segment, the right side of segment and the modulo.\n\n-----Output-----\nFor each game, output a single line containing the answer for the respective segment.\n\n-----Constrdaints-----\n- 1 \u2264 N \u2264 100,000\n- 1 \u2264 Ai \u2264 100\n- 1 \u2264 T \u2264 100,000\n- 1 \u2264 Li \u2264 Ri \u2264 N\n- 1 \u2264 Mi \u2264 109\n\n-----Example-----\nInput:\n5\n1 2 3 4 5\n4\n1 2 3\n2 3 4\n1 1 1\n1 5 1000000000\n\nOutput:\n2\n2\n0\n120\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# # # # n = int(input())\r\n# # # # arr = list(map(int , input().split()))\r\n# # # # for _ in range(int(input())):\r\n# # # # \tl,r,mod = map(int , input().split())\r\n# # # # \tpro = 1\r\n# # # # \tfor i in range(l - 1,r):\r\n# # # # \t\tpro *= arr[i]\r\n# # # # \tprint(pro % mod) #sample testcases passed #TLE\r\n# # # import numpy #or use math\r\n# # # n = int(input())\r\n# # # arr = list(map(int , input().split()))\r\n# # # for _ in range(int(input())):\r\n# # # \tl,r,mod = map(int , input().split())\r\n# # # \tprint(numpy.prod(arr[l - 1:r]) % mod) #sample cases passed, WA\r\n# # import math\r\n# # primes,dic,t = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97],{},0\r\n# # for i in primes:\r\n# # dic[i] = t\r\n# # t += 1\r\n# # def primeFactors(n,arr): \r\n# # for i in range(2,int(math.sqrt(n)) + 1,2): \r\n# # while(n % i == 0): \r\n# # arr[dic[i]] += 1 \r\n# # n /= i\r\n# # if(n > 2):\r\n# # arr[dic[n]] += 1\r\n# # return arr\r\n# # n = int(input())\r\n# # A = list(map(int , input().split()))\r\n# # dp = [0]*len(primes)\r\n# # for i in range(1,n + 1):\r\n# # r = [dp[i - 1]].copy()\r\n# # dp.append(primeFactors(A[i - 1],r))\r\n# # for _ in range(int(input())):\r\n# # li,ri,m=list(map(int,input().split()))\r\n# # ans = 1\r\n# # for i in range(len(primes)):\r\n# # ans *= (pow(primes[i],dp[ri][i] - dp[li - 1][i],m)) % m\r\n# # print(ans % m) #NZEC\r\n# import math\r\n# primes=[2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97]\r\n# dic={}\r\n# t=0\r\n# for i in primes:\r\n# dic[i]=t\r\n# t+=1\r\n# def primeFactors(n,arr): \r\n# while(n % 2 == 0):\r\n# arr[dic[2]] += 1 \r\n# n /= 2\r\n# for i in range(3,int(math.sqrt(n))+1,2): \r\n# while(n % i == 0): \r\n# arr[dic[i]] += 1 \r\n# n /= i\r\n# if(n > 2): \r\n# arr[dic[n]] += 1\r\n# return arr\r\n# N = int(input())\r\n# A = list(map(int , input().split()))\r\n# dp = [[0]*len(primes)]\r\n# for i in range(1,N + 1):\r\n# r = dp[i - 1].copy()\r\n# dp.append(primeFactors(A[i - 1],r))\r\n# for _ in range(int(input())):\r\n# l,r,m = list(map(int , input().split()))\r\n# ans = 1\r\n# for i in range(len(primes)):\r\n# ans *= (pow(primes[i],dp[r][i] - dp[l - 1][i],m)) % m\r\n# print(ans % m)\r\nimport sys \r\nimport math\r\ninput = sys.stdin.readline\r\nprimes=[2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97]\r\ndic={}\r\nt=0\r\nfor i in primes:\r\n dic[i]=t\r\n t+=1\r\ndef primeFactors(n,arr): \r\n while n % 2 == 0: \r\n arr[dic[2]]+=1 \r\n n = n / 2\r\n\r\n for i in range(3,int(math.sqrt(n))+1,2): \r\n while n % i== 0: \r\n arr[dic[i]]+=1 \r\n n = n / i \r\n\r\n if n > 2: \r\n arr[dic[n]]+=1\r\n return arr\r\ndef main():\r\n N=int(input())\r\n A=list(map(int,input().split()))\r\n tp=[0]*len(primes)\r\n dp=[]\r\n dp.append(tp)\r\n for i in range(1,N+1):\r\n # print(i)\r\n r=dp[i-1].copy()\r\n t=primeFactors(A[i-1],r)\r\n dp.append(t)\r\n t=int(input())\r\n for _ in range(t):\r\n l,r,m=list(map(int,input().split()))\r\n if(m==1):\r\n print(0)\r\n else:\r\n ans=1\r\n for i in range(len(primes)):\r\n ans=ans*(pow(primes[i],dp[r][i]-dp[l-1][i],m))%m\r\n print(ans%m)\r\n \r\ndef __starting_point():\r\n main()\n__starting_point()\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '5\\n1 2 3 4 5\\n4\\n1 2 3\\n2 3 4\\n1 1 1\\n1 5 1000000000\\n', 'output': '2\\n2\\n0\\n120\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/CHMOD'}","problem_id":"vfc_3214","program":"```python\n# # # # n = int(input())\r\n# # # # arr = list(map(int , input().split()))\r\n# # # # for _ in range(int(input())):\r\n# # # # \tl,r,mod = map(int , input().split())\r\n# # # # \tpro = 1\r\n# # # # \tfor i in range(l - 1,r):\r\n# # # # \t\tpro *= arr[i]\r\n# # # # \tprint(pro % mod) #sample testcases passed #TLE\r\n# # # import numpy #or use math\r\n# # # n = int(input())\r\n# # # arr = list(map(int , input().split()))\r\n# # # for _ in range(int(input())):\r\n# # # \tl,r,mod = map(int , input().split())\r\n# # # \tprint(numpy.prod(arr[l - 1:r]) % mod) #sample cases passed, WA\r\n# # import math\r\n# # primes,dic,t = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97],{},0\r\n# # for i in primes:\r\n# # dic[i] = t\r\n# # t += 1\r\n# # def primeFactors(n,arr): \r\n# # for i in range(2,int(math.sqrt(n)) + 1,2): \r\n# # while(n % i == 0): \r\n# # arr[dic[i]] += 1 \r\n# # n /= i\r\n# # if(n > 2):\r\n# # arr[dic[n]] += 1\r\n# # return arr\r\n# # n = int(input())\r\n# # A = list(map(int , input().split()))\r\n# # dp = [0]*len(primes)\r\n# # for i in range(1,n + 1):\r\n# # r = [dp[i - 1]].copy()\r\n# # dp.append(primeFactors(A[i - 1],r))\r\n# # for _ in range(int(input())):\r\n# # li,ri,m=list(map(int,input().split()))\r\n# # ans = 1\r\n# # for i in range(len(primes)):\r\n# # ans *= (pow(primes[i],dp[ri][i] - dp[li - 1][i],m)) % m\r\n# # print(ans % m) #NZEC\r\n# import math\r\n# primes=[2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97]\r\n# dic={}\r\n# t=0\r\n# for i in primes:\r\n# dic[i]=t\r\n# t+=1\r\n# def primeFactors(n,arr): \r\n# while(n % 2 == 0):\r\n# arr[dic[2]] += 1 \r\n# n /= 2\r\n# for i in range(3,int(math.sqrt(n))+1,2): \r\n# while(n % i == 0): \r\n# arr[dic[i]] += 1 \r\n# n /= i\r\n# if(n > 2): \r\n# arr[dic[n]] += 1\r\n# return arr\r\n# N = int(input())\r\n# A = list(map(int , input().split()))\r\n# dp = [[0]*len(primes)]\r\n# for i in range(1,N + 1):\r\n# r = dp[i - 1].copy()\r\n# dp.append(primeFactors(A[i - 1],r))\r\n# for _ in range(int(input())):\r\n# l,r,m = list(map(int , input().split()))\r\n# ans = 1\r\n# for i in range(len(primes)):\r\n# ans *= (pow(primes[i],dp[r][i] - dp[l - 1][i],m)) % m\r\n# print(ans % m)\r\nimport sys \r\nimport math\r\ninput = sys.stdin.readline\r\nprimes=[2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97]\r\ndic={}\r\nt=0\r\nfor i in primes:\r\n dic[i]=t\r\n t+=1\r\ndef primeFactors(n,arr): \r\n while n % 2 == 0: \r\n arr[dic[2]]+=1 \r\n n = n / 2\r\n\r\n for i in range(3,int(math.sqrt(n))+1,2): \r\n while n % i== 0: \r\n arr[dic[i]]+=1 \r\n n = n / i \r\n\r\n if n > 2: \r\n arr[dic[n]]+=1\r\n return arr\r\ndef main():\r\n N=int(input())\r\n A=list(map(int,input().split()))\r\n tp=[0]*len(primes)\r\n dp=[]\r\n dp.append(tp)\r\n for i in range(1,N+1):\r\n # print(i)\r\n r=dp[i-1].copy()\r\n t=primeFactors(A[i-1],r)\r\n dp.append(t)\r\n t=int(input())\r\n for _ in range(t):\r\n l,r,m=list(map(int,input().split()))\r\n if(m==1):\r\n print(0)\r\n else:\r\n ans=1\r\n for i in range(len(primes)):\r\n ans=ans*(pow(primes[i],dp[r][i]-dp[l-1][i],m))%m\r\n print(ans%m)\r\n \r\ndef __starting_point():\r\n main()\n__starting_point()\n```","inputs":"5\n1 2 3 4 5\n4\n1 2 3\n2 3 4\n1 1 1\n1 5 1000000000\n","output":"2\n2\n0\n120\n","actual_output":"2\n2\n0\n120\n","execution_success":true,"sample_index":691},{"source":"apps","task_type":"verifiable_code","in_source_id":"1094","prompt":"Solve the following coding problem using the programming language python:\n\nTwo words rhyme if their last 3 letters are a match. Given N words, print the test case number (of the format Case : num) followed by the rhyming words in separate line adjacent to each other.\n\nThe output can be in anyorder.\n\n-----Input-----\nFirst line contains the number of test case T\n\nThe next line contains the number of words N\n\nNext N words follow . They\u2019ll contain only alphabets from \u2018a\u2019-\u2018z\u2019.\n\n-----Output-----\nPrint case number (for each test case) of the format Case : num followed by the words that rhyme in a new line.\n\n-----Constraints-----\n1 <= T <= 5\n\n1 <= N <= 1000\n\n3 <= length of each word <= 1000\n\n-----Example-----\nInput:\n3\n3\nnope qwerty hope\n5 \nbrain drain request grain nest\n4\nthese words dont rhyme\n\n\nOutput:\nCase : 1\nhope nope\nqwerty\nCase : 2\nbrain drain grain\nnest request\nCase : 3\nthese\ndont\nwords\nrhyme\n\n\n\n-----Explanation-----\nCase : 2\n\nbrain drain grain\n\nnest request\n\nCase : 3\n\nthese\n\ndont\n\nwords\n\nrhyme\nExplanation for case 1: since hope and nope rhyme (suffix \u201cope\u201d matches), we print them in the same line and qwerty In a new line.\n\nNote that\n\nqwerty\n\nnope hope\n\nis also correct (the output can be in any order )\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nt = int(input())\nfor i in range(t):\n n = int(input())\n suffixes = {}\n xx = input().split()\n for x in range(n):\n try:\n a = suffixes[xx[x][-3:]]\n except Exception as e:\n a = []\n a.append(xx[x])\n\n suffixes.update({xx[x][-3:]: a})\n\n print(\"Case : %d\" % (i + 1))\n for a in sorted(suffixes):\n print(\"\".join(b + \" \" for b in sorted(suffixes[a])).strip())\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\n3\\nnope qwerty hope\\n5\\nbrain drain request grain nest\\n4\\nthese words dont rhyme\\n', 'output': 'Case : 1\\nhope nope\\nqwerty\\nCase : 2\\nbrain drain grain\\nnest request\\nCase : 3\\nthese\\ndont\\nwords\\nrhyme\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/COWA2016/problems/CWAM1502'}","problem_id":"vfc_3218","program":"```python\nt = int(input())\nfor i in range(t):\n n = int(input())\n suffixes = {}\n xx = input().split()\n for x in range(n):\n try:\n a = suffixes[xx[x][-3:]]\n except Exception as e:\n a = []\n a.append(xx[x])\n\n suffixes.update({xx[x][-3:]: a})\n\n print(\"Case : %d\" % (i + 1))\n for a in sorted(suffixes):\n print(\"\".join(b + \" \" for b in sorted(suffixes[a])).strip())\n```","inputs":"3\n3\nnope qwerty hope\n5\nbrain drain request grain nest\n4\nthese words dont rhyme\n","output":"Case : 1\nhope nope\nqwerty\nCase : 2\nbrain drain grain\nnest request\nCase : 3\nthese\ndont\nwords\nrhyme\n","actual_output":"Case : 1\nhope nope\nqwerty\nCase : 2\nbrain drain grain\nnest request\nCase : 3\nthese\ndont\nwords\nrhyme\n","execution_success":true,"sample_index":692},{"source":"apps","task_type":"verifiable_code","in_source_id":"1095","prompt":"Solve the following coding problem using the programming language python:\n\nIndraneel has to sort the books in his library. His library has one long shelf. His books are numbered $1$ through $N$ and he wants to rearrange the books so that they appear in the sequence $1,2, ..., N$.\nHe intends to do this by a sequence of moves. In each move he can pick up any book from the shelf and insert it at a different place in the shelf. Suppose Indraneel has $5$ books and they are initially arranged in the order\n21453214532 \\quad 1 \\quad 4 \\quad 5 \\quad 3\nIndraneel will rearrange this in ascending order by first moving book $1$ to the beginning of the shelf to get\n12453124531 \\quad 2 \\quad 4 \\quad 5 \\quad 3\nThen, moving book $3$ to position $3$, he gets\n12345123451 \\quad 2 \\quad 3 \\quad 4 \\quad 5\nYour task is to write a program to help Indraneel determine the minimum number of moves that are necessary to sort his book shelf.\n\n-----Input:-----\nThe first line of the input will contain a single integer $N$ indicating the number of books in Indraneel's library. This is followed by a line containing a permutation of $1, 2, ..., N$ indicating the intial state of Indraneel's book-shelf.\n\n-----Output:-----\nA single integer indicating the minimum number of moves necessary to sort Indraneel's book-shelf.\n\n-----Constraints:-----\n- $1 \\leq N \\leq 200000$.\n- You may also assume that in $50 \\%$ of the inputs, $1 \\leq N \\leq 5000$.\n\n-----Sample Input-----\n5\n2 1 4 5 3 \n\n-----Sample Output-----\n2\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nn=int(input())\narr=[int(x) for x in input().split()]\nl=[1]*n\nif sorted(arr)==arr:\n print('0')\nelse:\n for i in range(0,len(arr)):\n for j in range(i):\n if arr[i]>=arr[j] and l[i]=arr[j] and l[i] k[0]:\n break\n start = v_time[i]\n for j in range(y):\n if w_time[j] >= k[1]:\n end = w_time[j]\n break\n if start == -1:\n continue\n score = min(score, (end-start+1))\n if score-1 <= v:\n break\n\nprint(score)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3 4 2\\n15 21\\n5 10\\n7 25\\n4 14 25 2\\n13 21\\n', 'output': '8\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/ZCOPRAC/problems/ZCO12002'}","problem_id":"vfc_3226","program":"```python\nimport sys\nn, x, y = input().split(' ')\nn = int(n)\nx = int(x)\ny = int(y)\ncontests = {}\n\nfor i in range(n):\n s, e = input().split(' ')\n s = int(s)\n e = int(e)\n contests[(s, e)] = abs(s-e)\n\nv_time = input().split(' ')\nw_time = input().split(' ')\n\nv_time, w_time = list(map(int, v_time)), list(map(int, w_time))\nv_time.sort()\nw_time.sort()\n\n\nscore = sys.maxsize\n\ncontests = dict(sorted(contests.items(), key=lambda item: item[1]))\nfor k, v in contests.items():\n start=-1\n end = sys.maxsize\n for i in range(x):\n if v_time[i] > k[0]:\n break\n start = v_time[i]\n for j in range(y):\n if w_time[j] >= k[1]:\n end = w_time[j]\n break\n if start == -1:\n continue\n score = min(score, (end-start+1))\n if score-1 <= v:\n break\n\nprint(score)\n```","inputs":"3 4 2\n15 21\n5 10\n7 25\n4 14 25 2\n13 21\n","output":"8\n","actual_output":"8\n","execution_success":true,"sample_index":694},{"source":"apps","task_type":"verifiable_code","in_source_id":"1097","prompt":"Solve the following coding problem using the programming language python:\n\nSinchan and his friends loves to eat. They have a 2D rectangular cake which they want to share. Sinchan is very kind and offers his friends to eat the cake first, all friends goes one by one to eat the cake. Each friend will cut cake into two parts. First part of the cake will be largest possible square from the cake, that the friend will eat, and will leave the second part for others, it continues untill cake is over or every friend gets to eat the cake.\nNow Sinchan wonder how much cake would he be able to get.\n\n-----Input-----\n- First line of input contain T, denoting number of test case.\n- First line of each test case contains N, denoting number of friends.\n- Second line of test case contain L, B (L x B) denoting dimension of cake.\n\n-----Output-----\n- For each test case, if Sinchan gets to eat the cake print (without quotes) \"Yes #\" where # is area of cake that Sinchan gets. Otherwise print (without quotes) \"No\"\n\n-----Constraints-----\n- 1 \u2264 T, N, L, B \u2264 1000\n\n-----Example-----\nInput:\n3\n2\n5 3\n4\n4 8\n1\n1 2\n\nOutput:\nYes 2\nNo\nYes 1\n\n-----Explanation-----\nExample case 1. First friend divides 5x3 cake in 3x3 and 2x3 since 3x3 is largest possible square, second Friend divides 2x3 cake in 2x2 and 1x2 and eat 2x2 piece. Finaly Sinchan gets to eat and area of cake is 1*2 hence Output is (without quotes) \"Yes 2\"\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\ntestcases=int(input())\nresults=[]\nfor i in range(0,testcases):\n friends=int(input())\n l,b=list(map(int,input().split()))\n over=False\n if b>l:\n temp=b\n b=l\n l=temp\n for counter in range(0,friends):\n if l==b:\n over=True\n break\n elif l>b:\n l=l-b\n if b>l:\n temp=b\n b=l\n l=temp\n \n if over:\n results.append(\"No\")\n else:\n results.append(\"Yes \"+str(l*b))\n\nfor i in range(0,testcases):\n print(results[i])\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\n2\\n5 3\\n4\\n4 8\\n1\\n1 2\\n', 'output': 'Yes 2\\nNo\\nYes 1\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/CDGO2016/problems/CDGO1601'}","problem_id":"vfc_3230","program":"```python\ntestcases=int(input())\nresults=[]\nfor i in range(0,testcases):\n friends=int(input())\n l,b=list(map(int,input().split()))\n over=False\n if b>l:\n temp=b\n b=l\n l=temp\n for counter in range(0,friends):\n if l==b:\n over=True\n break\n elif l>b:\n l=l-b\n if b>l:\n temp=b\n b=l\n l=temp\n \n if over:\n results.append(\"No\")\n else:\n results.append(\"Yes \"+str(l*b))\n\nfor i in range(0,testcases):\n print(results[i])\n\n```","inputs":"3\n2\n5 3\n4\n4 8\n1\n1 2\n","output":"Yes 2\nNo\nYes 1\n","actual_output":"Yes 2\nNo\nYes 1\n","execution_success":true,"sample_index":695},{"source":"apps","task_type":"verifiable_code","in_source_id":"1098","prompt":"Solve the following coding problem using the programming language python:\n\nChef and Roma are playing a game. Rules of the game are quite simple.\nInitially there are N piles of stones on the table.\nIn each turn, a player can choose one pile and remove it from the table.\nEach player want to maximize the total number of stones removed by him.\nChef takes the first turn. \n\nPlease tell Chef the maximum number of stones he can remove assuming that both players play optimally.\n\n-----Input-----\nThe first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.\nThe first line of each test case contains a single integer N denoting the number of piles.\nThe second line contains N space separated integers A1, A2, ..., AN denoting the number of stones in each pile.\n\n-----Output-----\nFor each test case, output a single line containg the maximum number of stones that Chef can remove.\n\n-----Constraints-----\n- 1 \u2264 Ai \u2264 109\n- Subtask 1 (35 points): T = 10, 1 \u2264 N \u2264 1000\n- Subtask 2 (65 points): T = 10, 1 \u2264 N \u2264 105 \n\n-----Example-----\nInput:\n2\n3\n1 2 3\n3\n1 2 1\n\nOutput:\n4\n3\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\nfor i in range(int(input())):\n n = int(input())\n l = list(map(int,input().split()))\n s = 0\n l.sort(reverse = True)\n for i in range(0,n,2):\n s = s+l[i]\n print(s)\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n3\\n1 2 3\\n3\\n1 2 1\\n', 'output': '4\\n3\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/CHEFA'}","problem_id":"vfc_3234","program":"```python\n# cook your dish here\nfor i in range(int(input())):\n n = int(input())\n l = list(map(int,input().split()))\n s = 0\n l.sort(reverse = True)\n for i in range(0,n,2):\n s = s+l[i]\n print(s)\n\n```","inputs":"2\n3\n1 2 3\n3\n1 2 1\n","output":"4\n3\n","actual_output":"4\n3\n","execution_success":true,"sample_index":696},{"source":"apps","task_type":"verifiable_code","in_source_id":"1099","prompt":"Solve the following coding problem using the programming language python:\n\nDid you know that there are over 40,000 varieties of Rice in the world ? There are so many dishes that can be prepared with Rice too. A famous chef from Mumbai, Tid Gusto prepared a new dish and named it 'Tid Rice'. He posted the recipe in his newly designed blog for community voting, where a user can plus (+) or minus (-) the recipe. The final score is just the sum of all votes, where (+) and (-) are treated as +1 and -1 respectively. But, being just a chef ( and not a codechef ) he forgot to take care of multiple votes by the same user.\n\nA user might have voted multiple times and Tid is worried that the final score shown is not the correct one. Luckily, he found the user logs, which had all the N votes in the order they arrived. Remember that, if a user votes more than once, the user's previous vote is first nullified before the latest vote is counted ( see explanation for more clarity ). Given these records in order ( and being a codechef yourself :) ), calculate the correct final score.\n\n-----Input-----\nFirst line contains T ( number of testcases, around 20 ). T cases follow. Each test case starts with N ( total number of votes, 1 <= N <= 100 ). Each of the next N lines is of the form \"userid vote\" ( quotes for clarity only ), where userid is a non-empty string of lower-case alphabets ( 'a' - 'z' ) not more than 20 in length and vote is either a + or - . See the sample cases below, for more clarity.\n\n-----Output-----\nFor each test case, output the correct final score in a new line\n\n-----Example-----\nInput:\n3\n4\ntilak +\ntilak +\ntilak -\ntilak +\n3\nratna +\nshashi -\nratna -\n3\nbhavani -\nbhavani +\nbhavani -\n\nOutput:\n1\n-2\n-1\n\nExplanation\n\nCase 1 : Initially score = 0. Updation of scores in the order of user tilak's votes is as follows,\n\n( + ): +1 is added to the final score. This is the 1st vote by this user, so no previous vote to nullify. score = 1\n( + ): 0 should be added ( -1 to nullify previous (+) vote, +1 to count the current (+) vote ). score = 1\n( - ) : -2 should be added ( -1 to nullify previous (+) vote, -1 to count the current (-) vote ). score = -1\n( + ): +2 should be added ( +1 to nullify previous (-) vote, +1 to count the current (+) vote ). score = 1\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nimport sys\n\ndef f(p):\n votes = {}\n for x in range(p):\n str = sys.stdin.readline()\n t = str.split()\n votes[t[0]] = t[1]\n\n ans = 0\n for per in votes:\n if votes[per] == \"+\":\n ans= ans+1\n else:\n ans = ans-1\n\n return ans\n\nx = sys.stdin.readline()\nfor t in range(int(x)):\n p = sys.stdin.readline()\n print(f(int(p)))\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\n4\\ntilak +\\ntilak +\\ntilak -\\ntilak +\\n3\\nratna +\\nshashi -\\nratna -\\n3\\nbhavani -\\nbhavani +\\nbhavani -\\n', 'output': '1\\n-2\\n-1\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/COOK10/problems/TIDRICE'}","problem_id":"vfc_3238","program":"```python\nimport sys\n\ndef f(p):\n votes = {}\n for x in range(p):\n str = sys.stdin.readline()\n t = str.split()\n votes[t[0]] = t[1]\n\n ans = 0\n for per in votes:\n if votes[per] == \"+\":\n ans= ans+1\n else:\n ans = ans-1\n\n return ans\n\nx = sys.stdin.readline()\nfor t in range(int(x)):\n p = sys.stdin.readline()\n print(f(int(p)))\n\n```","inputs":"3\n4\ntilak +\ntilak +\ntilak -\ntilak +\n3\nratna +\nshashi -\nratna -\n3\nbhavani -\nbhavani +\nbhavani -\n","output":"1\n-2\n-1\n","actual_output":"1\n-2\n-1\n","execution_success":true,"sample_index":697},{"source":"apps","task_type":"verifiable_code","in_source_id":"1100","prompt":"Solve the following coding problem using the programming language python:\n\nThis question is similar to the $\"Operation$ $on$ $a$ $Tuple\"$ problem in this month's Long Challenge but with a slight variation.\n\nConsider the following operations on a triple of integers. In one operation, you should:\n\n- Choose a positive integer $d>0$ and an arithmetic operation - in this case, it will only be addition.\n\n- Choose a subset of elements of the triple.\n\n- Apply arithmetic operation to each of the chosen elements.\n\nFor example, if we have a triple $(3,5,7)$, we may choose to add $3$ to the first and third element, and we get $(6,5,10)$ using one operation.\n\nYou are given an initial triple $(p,q,r)$ and a target triple $(a,b,c)$. Find the maximum number of operations needed to transform $(p,q,r)$ into $(a,b,c)$ or say the conversion is impossible .\nInput:\n- The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows.\n- The first line of each test case contains three space-separated integers p, q and r.\n- The second line contains three space-separated integers a, b and c.Output:\nFor each test case, print a single line containing one integer \u2015 the maximum required number of operations(if the conversion is possible), or else print \"-1\"\n\nConstraints:\n- $1 \\leq T \\leq 1,000$\n- $2 \\leq |p|,|q|,|r|,|a|,|b|,|c| \\leq 10^9$Sample Input:\n\t1\n\n\t2 2 1\n\n\t3 3 2\n\nSample Output:\n\t3\n\t\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\n\"\"\"\nInput:\nThe first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows.\nThe first line of each test case contains three space-separated integers p, q and r.\nThe second line contains three space-separated integers a, b and c.\nOutput:\nFor each test case, print a single line containing one integer \u2015 the maximum required number of operations(if the conversion is possible), or else print \"-1\"\n\"\"\"\n\nT=int(input())\nwhile T>0:\n T-=1 \n p,q,r=list(map(int,input().split()))\n a,b,c=list(map(int,input().split()))\n #ds=list()\n s=0\n d1=a-p\n if d1>0:\n #ds.append(d1)\n s+=d1\n d2=b-q\n if d2>0:\n #ds.append(d2)\n s+=d2\n d3=c-r\n if d3>0:\n #ds.append(d3)\n s+=d3\n \n if(d1==0 and d2==0 and d3==0):\n print(0)\n elif(d1<0 or d2<0 or d3<0):\n print(-1)\n else:\n print(s)\n \n \n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n2 2 1\\n3 3 2\\n', 'output': '3\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/ENJU2020/problems/ECJN201'}","problem_id":"vfc_3242","program":"```python\n# cook your dish here\n\"\"\"\nInput:\nThe first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows.\nThe first line of each test case contains three space-separated integers p, q and r.\nThe second line contains three space-separated integers a, b and c.\nOutput:\nFor each test case, print a single line containing one integer \u2015 the maximum required number of operations(if the conversion is possible), or else print \"-1\"\n\"\"\"\n\nT=int(input())\nwhile T>0:\n T-=1 \n p,q,r=list(map(int,input().split()))\n a,b,c=list(map(int,input().split()))\n #ds=list()\n s=0\n d1=a-p\n if d1>0:\n #ds.append(d1)\n s+=d1\n d2=b-q\n if d2>0:\n #ds.append(d2)\n s+=d2\n d3=c-r\n if d3>0:\n #ds.append(d3)\n s+=d3\n \n if(d1==0 and d2==0 and d3==0):\n print(0)\n elif(d1<0 or d2<0 or d3<0):\n print(-1)\n else:\n print(s)\n \n \n\n```","inputs":"1\n2 2 1\n3 3 2\n","output":"3\n","actual_output":"3\n","execution_success":true,"sample_index":698},{"source":"apps","task_type":"verifiable_code","in_source_id":"1101","prompt":"Solve the following coding problem using the programming language python:\n\nAfter failing to clear his school mathematics examination, infinitepro decided to prepare very hard for his upcoming re-exam, starting with the topic he is weakest at \u2015 computational geometry.\nBeing an artist, infinitepro has C$C$ pencils (numbered 1$1$ through C$C$); each of them draws with one of C$C$ distinct colours. He draws N$N$ lines (numbered 1$1$ through N$N$) in a 2D Cartesian coordinate system; for each valid i$i$, the i$i$-th line is drawn with the ci$c_i$-th pencil and it is described by the equation y=ai\u22c5x+bi$y = a_i \\cdot x + b_i$.\nNow, infinitepro calls a triangle truly-geometric if each of its sides is part of some line he drew and all three sides have the same colour. He wants to count these triangles, but there are too many of them! After a lot of consideration, he decided to erase a subset of the N$N$ lines he drew. He wants to do it with his eraser, which has length K$K$.\nWhenever erasing a line with a colour i$i$, the length of the eraser decreases by Vi$V_i$. In other words, when the eraser has length k$k$ and we use it to erase a line with a colour i$i$, the length of the eraser decreases to k\u2212Vi$k-V_i$; if k2 and s[i][1]<=k:\r\n if s[i][0]>3:\r\n ch=(nc3(s[i][0])-nc3(s[i][0]-1))/s[i][1]\r\n else:\r\n ch=1/s[i][1]\r\n if t2:\r\n re=re+nc3(i[0])\r\n print(int(re))\r\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n7 2 13\\n1 10 1\\n1 14 2\\n6 4 1\\n2 2 1\\n0 12 2\\n2 11 2\\n0 6 1\\n8 10\\n6 1 20\\n1 5 1\\n2 11 1\\n4 0 1\\n6 8 1\\n0 11 1\\n3 3 1\\n9\\n', 'output': '2\\n4\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/ACCBIP'}","problem_id":"vfc_3246","program":"```python\nfrom collections import Counter\r\nfrom math import factorial\r\ndef nc3(n):\r\n a=factorial(n)\r\n b=factorial(n-3)\r\n return ((a)/(b*6))\r\ndef rem(s,k):\r\n t=-1\r\n x=-1\r\n for i in range(len(s)):\r\n if s[i][0]>2 and s[i][1]<=k:\r\n if s[i][0]>3:\r\n ch=(nc3(s[i][0])-nc3(s[i][0]-1))/s[i][1]\r\n else:\r\n ch=1/s[i][1]\r\n if t2:\r\n re=re+nc3(i[0])\r\n print(int(re))\r\n\n```","inputs":"2\n7 2 13\n1 10 1\n1 14 2\n6 4 1\n2 2 1\n0 12 2\n2 11 2\n0 6 1\n8 10\n6 1 20\n1 5 1\n2 11 1\n4 0 1\n6 8 1\n0 11 1\n3 3 1\n9\n","output":"2\n4\n","actual_output":"2\n4\n","execution_success":true,"sample_index":699},{"source":"apps","task_type":"verifiable_code","in_source_id":"1102","prompt":"Solve the following coding problem using the programming language python:\n\nOn Miu's smart phone, there is a search feature which lets her search for a contact name by typing digits on the keypad where each digit may correspond to any of the characters given below it. For example, to search for TOM, she can type 866 and for MAX she can type 629.\n+------+-----+------+\n| 1 | 2 | 3 |\n| | ABC | DEF |\n+------+-----+------+\n| 4 | 5 | 6 |\n| GHI | JKL | MNO |\n+------+-----+------+\n| 7 | 8 | 9 |\n| PQRS | TUV | WXYZ |\n+------+-----+------+\n| | 0 | |\n+------+-----+------+\n\nMiu typed a random string of digits $S$ on the keypad while playing around, where each digit is between 2 and 9 inclusive. Now she wants to know the number of possible strings which would map to $S$. \nSince this number can be very large, output it modulo 10^9 + 7 (1000000007)\n\n-----Input:-----\n- \nThe first line of the input consists of a single integer $T$ denoting the number of test cases.\n- \nEach test case consists of a string $S$.\n\n-----Output:-----\n- For each test case, print a single line containing one integer - the count of all possible strings mod 1,000,000,007\n\n-----Constraints-----\n- \n1 <= $T$ <= 10\n- \n1 <= $|S|$ <= 105\n\n-----Subtasks-----\nSubtask #1 (10 points):\n- 1 <= $|S|$ <= 10\nSubtask #2 (90 points):\n- Original Constraints\n\n-----Sample Input:-----\n2\n\n5\n\n72 \n\n-----Sample Output:-----\n3\n\n12 \n\n-----EXPLANATION:-----\n- \nExample Case 1:\n\nOn the key 5, we have the character set JKL.\n\nHence the possible strings are J,K,L.\n\nHence the answer is 3 % (1000000007) = 3. \n- \nExample Case 2:\nOn key 7, we have the character set PQRS.\n\nOn key 2, we have the character set ABC.\n\nHence the possible strings are PA,PB,PC,QA,QB,QC,RA,RB,RC,SA,SB,SC.\n\nHence the answer is 12 % (1000000007) = 12.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfor _ in range(int(input())):\n n=int(input())\n n1=0\n ans=1\n while(n>0):\n d=int(n % 10)\n if(d!=0):\n if(d!=9 and d!=7 and d!=1):\n n1=3\n elif(d==1):\n n1=1\n else:\n n1=4\n ans=(int(ans)*int(n1))% (1000000007)\n n/=10\n else:\n n/=10\n if(ans==1):\n print(\"0\")\n else:\n print(ans %(1000000007))\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n5\\n72\\n', 'output': '3\\n12\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/TCFL2020/problems/TCFL20C'}","problem_id":"vfc_3250","program":"```python\nfor _ in range(int(input())):\n n=int(input())\n n1=0\n ans=1\n while(n>0):\n d=int(n % 10)\n if(d!=0):\n if(d!=9 and d!=7 and d!=1):\n n1=3\n elif(d==1):\n n1=1\n else:\n n1=4\n ans=(int(ans)*int(n1))% (1000000007)\n n/=10\n else:\n n/=10\n if(ans==1):\n print(\"0\")\n else:\n print(ans %(1000000007))\n\n```","inputs":"2\n5\n72\n","output":"3\n12\n","actual_output":"3\n12\n","execution_success":true,"sample_index":700},{"source":"apps","task_type":"verifiable_code","in_source_id":"1103","prompt":"Solve the following coding problem using the programming language python:\n\nLeha is a bright mathematician. Today he is investigating whether an integer is divisible by some square number or not.\nHe has a positive integer X represented as a product of N integers a1, a2, .... aN. He has somehow figured out that there exists some integer P such that the number X is divisible by P2, but he is not able to find such P himself. Can you find it for him? If there are more than one possible values of P possible, you can print any one of them.\n\n-----Input-----\nThe first line of the input contains an integer T denoting the number of test cases. T test cases follow.\nThe first line of each test case contains one integer N denoting the number of intgers in presentation of X.\nThe second line contains N space-separated integers a1, a2, .... aN.\n\n-----Output-----\nFor each test case, output a single integer P deoting the answer for this test case. Note that P must be in range from 2 to 1018 inclusive. It's guaranteed that at least one answer exists. If there are more than one possible answers, print any.\n\n-----Constraints-----\n- 1 \u2264 T \u2264 5\n- 1 \u2264 N \u2264 100\n- 1 \u2264 ai \u2264 1018\n\n-----Subtasks-----\n- Subtask 1[19 points]: 1 \u2264 a1*a2*...*aN \u2264 106\n- Subtask 2[22 points]: 1 \u2264 a1*a2*...*aN \u2264 1012\n- Subtask 3[23 points]: 1 \u2264 ai \u2264 1012\n- Subtask 4[36 points]: no additional constraints\n\n-----Example-----\nInput:\n1\n3\n21 11 6\n\nOutput:\n3\n\n-----Explanation-----\nExample case 1. X = 21 * 11 * 6 = 1386. It's divisible by 9 which is a square number, as 9 = 32. So P = 3.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nimport sys\nimport math\nr=int(input())\nfor v in range (0,r):\n n = int(input())\n x=1\n arr=list(map(int,input().strip().split(\" \")))\n for i in range (0,n):\n x=x*arr[i]\n \n for i in range (2,100000000):\n if(x%(pow(i,2))==0):\n ans1=i\n break\n \n \n print(ans1) \n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n3\\n21 11 6\\n', 'output': '3\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/LTIME37/problems/SQNUMBF'}","problem_id":"vfc_3254","program":"```python\nimport sys\nimport math\nr=int(input())\nfor v in range (0,r):\n n = int(input())\n x=1\n arr=list(map(int,input().strip().split(\" \")))\n for i in range (0,n):\n x=x*arr[i]\n \n for i in range (2,100000000):\n if(x%(pow(i,2))==0):\n ans1=i\n break\n \n \n print(ans1) \n\n```","inputs":"1\n3\n21 11 6\n","output":"3\n","actual_output":"3\n","execution_success":true,"sample_index":701},{"source":"apps","task_type":"verifiable_code","in_source_id":"1104","prompt":"Solve the following coding problem using the programming language python:\n\nKabir Singh is playing a game on the non-negative side of x-axis. It takes him $1 second$ to reach from Pth position to (P\u22121)th position or (P+1)th position. \nKabir never goes to the negative side and also doesn't stop at any moment of time.\nThe movement can be defined as : \n- At the beginning he is at $x=0$ , at time $0$\n- During the first round, he moves towards $x=1$ and comes back to the $x=0$ position.\n- In the second round, he moves towards the $x=2$ and comes back again to $x=0$.\n- So , at $Kth$ round , he moves to $x=K$ and comes back to $x=0$\nSo in this way game goes ahead.\nFor Example, the path of Kabir for $3rd$ round is given below.\n$0\u22121\u22122\u22123\u22122\u22121\u22120$\nThe overall path followed by Kabir would look somewhat like this:\n$0\u22121\u22120\u22121\u22122\u22121\u22120\u22121\u22122\u22123\u22122\u22121\u22120\u22121\u22122\u22123\u22124\u22123\u2212\u2026$\nNow the task is , You are given Two Non-Negative integers $N$ , $K$ .\nYou have to tell the time at which Kabir arrives at $x=N$ for the $Kth$ time.\nNote - Kabir visits all the points , he can not skip or jump over one point.\n\n-----Input:-----\n- First line will contain $T$, number of testcases. Then the testcases follow. \n- Each testcase contains of a single line of input, two integers $N, K$. \n\n-----Output:-----\nFor each testcase, output in a single line answer i.e Time Taken by Kabir Singh modulo 1000000007.\n\n-----Constraints-----\n- $1 \\leq T \\leq 10^5$\n- $0 \\leq N \\leq 10^9$\n- $1 \\leq K \\leq 10^9$\n\n-----Sample Input:-----\n4\n\n0 1\n1 1\n1 3\n4 6\n\n-----Sample Output:-----\n0\n1\n5\n46\n\n-----EXPLANATION:-----\nTest Case 1:\nKabir starts the journey from the $N=0$ at time $t=0$ and it's the first time$ (K=1)$, he is here. So, the answer is $0$.\nTest Case 3:\nThe path followed by Kabir to reach 1 for the third time is given below.\n$0\u22121\u22120\u22121\u22122\u22121$\nHe reaches $1$ for the third time at $ t=5$.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\nT=int(input())\nMOD=int(1e9+7)\nfor t in range(T):\n N,K=[int(a) for a in input().split()]\n M=K//2\n # ans= ((K%2)?( (N+M)*(N+M) + M ):( (N+M)*(N+M) - M) )\n ans=(N+M)*(N+M) -M\n if(K%2):\n ans+=2*M\n if(N==0):\n ans=K*(K-1)\n print(ans%MOD) \n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '4\\n0 1\\n1 1\\n1 3\\n4 6\\n', 'output': '0\\n1\\n5\\n46\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/LDT42020/problems/WALKREC'}","problem_id":"vfc_3258","program":"```python\n# cook your dish here\nT=int(input())\nMOD=int(1e9+7)\nfor t in range(T):\n N,K=[int(a) for a in input().split()]\n M=K//2\n # ans= ((K%2)?( (N+M)*(N+M) + M ):( (N+M)*(N+M) - M) )\n ans=(N+M)*(N+M) -M\n if(K%2):\n ans+=2*M\n if(N==0):\n ans=K*(K-1)\n print(ans%MOD) \n```","inputs":"4\n0 1\n1 1\n1 3\n4 6\n","output":"0\n1\n5\n46\n","actual_output":"0\n1\n5\n46\n","execution_success":true,"sample_index":702},{"source":"apps","task_type":"verifiable_code","in_source_id":"1105","prompt":"Solve the following coding problem using the programming language python:\n\nChef Ada is preparing $N$ dishes (numbered $1$ through $N$). For each valid $i$, it takes $C_i$ minutes to prepare the $i$-th dish. The dishes can be prepared in any order.\nAda has a kitchen with two identical burners. For each valid $i$, to prepare the $i$-th dish, she puts it on one of the burners and after $C_i$ minutes, removes it from this burner; the dish may not be removed from the burner before those $C_i$ minutes pass, because otherwise it cools down and gets spoiled. Any two dishes may be prepared simultaneously, however, no two dishes may be on the same burner at the same time. Ada may remove a dish from a burner and put another dish on the same burner at the same time.\nWhat is the minimum time needed to prepare all dishes, i.e. reach the state where all dishes are prepared?\n\n-----Input-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The first line of each test case contains a single integer $N$.\n- The second line contains $N$ space-separated integers $C_1, C_2, \\ldots, C_N$.\n\n-----Output-----\nFor each test case, print a single line containing one integer \u2015 the minimum number of minutes needed to prepare all dishes.\n\n-----Constraints-----\n- $1 \\le T \\le 1,000$\n- $1 \\le N \\le 4$\n- $1 \\le C_i \\le 5$ for each valid $i$\n\n-----Subtasks-----\nSubtask #1 (1 points): $C_1 = C_2 = \\ldots = C_N$\nSubtask #2 (99 points): original constraints\n\n-----Example Input-----\n3\n3\n2 2 2\n3\n1 2 3\n4\n2 3 4 5\n\n-----Example Output-----\n4\n3\n7\n\n-----Explanation-----\nExample case 1: Place the first two dishes on the burners, wait for two minutes, remove both dishes and prepare the last one on one burner.\nExample case 2: Place the first and third dish on the burners. When the first dish is prepared, remove it and put the second dish on the same burner.\nExample case 3: Place the third and fourth dish on the burners. When the third dish is prepared, remove it and put the second dish on the same burner. Similarly, replace the fourth dish (when it is prepared) by the first dish on the other burner.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfor i in range(int(input())):\n n=int(input())\n c=[int(z) for z in input().split()]\n c.sort()\n c.reverse()\n b1,b2=0,0\n for i in range(n):\n if b1 10$, this participant does not receive a certificate.\n- Participant $4$ watched $1 + 1 + 1 + 3 = 6$ minutes of lectures and asked the question $12$ times. Since $6 < M$ and $12 > 10$, this participant does not receive a certificate.\nOnly participant $2$ receives a certificate.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nN,M,K=map(int,input().split())\nc=0\nfor i in range(N):\n T=list(map(int,input().split()))\n Q=T[-1]\n T.pop(-1)\n if Q<=10 and sum(T)>=M:\n c+=1\nprint(c)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '4 8 4\\n1 2 1 2 5\\n3 5 1 3 4\\n1 2 4 5 11\\n1 1 1 3 12\\n', 'output': '1\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/IPCCERT'}","problem_id":"vfc_3274","program":"```python\nN,M,K=map(int,input().split())\nc=0\nfor i in range(N):\n T=list(map(int,input().split()))\n Q=T[-1]\n T.pop(-1)\n if Q<=10 and sum(T)>=M:\n c+=1\nprint(c)\n```","inputs":"4 8 4\n1 2 1 2 5\n3 5 1 3 4\n1 2 4 5 11\n1 1 1 3 12\n","output":"1\n","actual_output":"1\n","execution_success":true,"sample_index":706},{"source":"apps","task_type":"verifiable_code","in_source_id":"1109","prompt":"Solve the following coding problem using the programming language python:\n\nSumit and Dhiraj are roommates in a hostel of NIT Jamshedpur,One day after completing there boring assignments of Artificial Intelligence, they decided to play a game as it was dhiraj,s idea to play a game so he started explaining the rules of the game to sumit.\nSo the game was as follows-They randomly took a number N after that they find all its divisors.Suppose first sumit took a divisor then dhiraj and so on.The player who will be having the last divisor with him will win the game.Rohit their mutual friend,was observing them play. Can you help Rohit predict the outcome of game? If Sumit wins print \"YES\" without quotes and \"NO\" without quotes, if Dhiraj wins\nthe game.\n\n-----Input-----\nInput starts with an integer T denoting the number of test cases Each test case starts with a line containing an integer N the number.\n\n-----Output-----\nOutcome of each game in a separate line\n\n-----Constraints-----\n- 1 \u2264 T \u2264 10^3\n- 1 \u2264 N \u2264 10^18\n\n-----Sub tasks-----\n- Subtask #1:(10 points)\n\n- 1 \u2264 T \u2264 10\n- 1 \u2264 N \u2264 103\n- Subtask #2:(25 points)\n\n- 1 \u2264 T \u2264 50\n- 1 \u2264 N \u2264 1016\n- Subtask #3:(65 points)\n\n- 1 \u2264 T \u2264 103\n- 1 \u2264 N \u2264 1018\n\n-----Example-----\nInput:\n2\n4\n5\n\nOutput:\nYES\nNO\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nimport math\nfor t in range(int(input())):\n n = int(input())\n temp = math.sqrt(n)\n if (temp == int(temp)):\n print(\"YES\")\n else:\n print(\"NO\")\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n4\\n5\\n', 'output': 'YES\\nNO\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/COYA2016/problems/CDYPA01'}","problem_id":"vfc_3278","program":"```python\nimport math\nfor t in range(int(input())):\n n = int(input())\n temp = math.sqrt(n)\n if (temp == int(temp)):\n print(\"YES\")\n else:\n print(\"NO\")\n```","inputs":"2\n4\n5\n","output":"YES\nNO\n","actual_output":"YES\nNO\n","execution_success":true,"sample_index":707},{"source":"apps","task_type":"verifiable_code","in_source_id":"1110","prompt":"Solve the following coding problem using the programming language python:\n\nYou are given an array of integers [A1,A2,\u2026,AN]$[A_1, A_2, \\ldots, A_N]$. Let's call adding an element to this array at any position (including the beginning and the end) or removing an arbitrary element from it a modification. It is not allowed to remove an element from the array if it is empty.\nFind the minimum number of modifications which must be performed so that the resulting array can be partitioned into permutations. Formally, it must be possible to partition elements of the resulting array into zero or more groups (multisets; not necessarily identical) in such a way that each element belongs to exactly one group and for each group, if it contains L$L$ elements, then it must contain only integers 1$1$ through L$L$, each of them exactly once.\n\n-----Input-----\n- 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.\n- The first line of each test case contains a single integer N$N$.\n- The second line contains N$N$ space-separated integers A1,A2,\u2026,AN$A_1, A_2, \\ldots, A_N$.\n\n-----Output-----\nFor each test case, print a single line containing one integer \u2015 the minimum required number of modifications.\n\n-----Constraints-----\n- 1\u2264T\u22641,000$1 \\le T \\le 1,000$\n- 1\u2264N\u2264106$1 \\le N \\le 10^6$\n- 1\u2264Ai\u2264109$1 \\le A_i \\le 10^9$ for each valid i$i$\n- the sum of N$N$ over all test cases does not exceed 106$10^6$\n\n-----Subtasks-----\nSubtask #1 (50 points):\n- 1\u2264N\u22641,000$1 \\le N \\le 1,000$\n- the sum of N$N$ over all test cases does not exceed 10,000$10,000$\nSubtask #2 (50 points): original constraints\n\n-----Example Input-----\n2\n5\n1 4 1 2 2\n4\n2 3 2 3\n\n-----Example Output-----\n1\n2\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\nfor _ in range(int(input())):\n n=int(input());li=list(map(int,input().split()));dli=dict();modi=0\n for i in li:\n if i not in dli:dli[i]=1\n else:dli[i]+=1\n op=sorted(list(dli))\n if(len(dli)!=0):\n while 1:\n tmp=[]\n for i in op:\n if dli[i]==0:continue\n tmp.append(i);dli[i]-=1\n l=len(tmp);mn=l\n for i in range(l):mn=min(mn,tmp[i]-1-i+l-1-i)\n modi+=mn\n if(l==0):break\n print(modi)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n5\\n1 4 1 2 2\\n4\\n2 3 2 3\\n', 'output': '1\\n2\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/PERMPART'}","problem_id":"vfc_3282","program":"```python\n# cook your dish here\nfor _ in range(int(input())):\n n=int(input());li=list(map(int,input().split()));dli=dict();modi=0\n for i in li:\n if i not in dli:dli[i]=1\n else:dli[i]+=1\n op=sorted(list(dli))\n if(len(dli)!=0):\n while 1:\n tmp=[]\n for i in op:\n if dli[i]==0:continue\n tmp.append(i);dli[i]-=1\n l=len(tmp);mn=l\n for i in range(l):mn=min(mn,tmp[i]-1-i+l-1-i)\n modi+=mn\n if(l==0):break\n print(modi)\n```","inputs":"2\n5\n1 4 1 2 2\n4\n2 3 2 3\n","output":"1\n2\n","actual_output":"1\n2\n","execution_success":true,"sample_index":708},{"source":"apps","task_type":"verifiable_code","in_source_id":"1111","prompt":"Solve the following coding problem using the programming language python:\n\nUsing his tip-top physique, Kim has now climbed up the mountain where the base is located. Kim has found the door to the (supposedly) super secret base. Well, it is super secret, but obviously no match for Kim's talents. \nThe door is guarded by a row of $N$ buttons. Every button has a single number $A_i$ written on it. Surprisingly, more than one button can have the same number on it. Kim recognises this as Soum's VerySafe door, for which you need to press two buttons to enter the password. More importantly, the sum of the two numbers on the buttons you press must be odd. Kim can obviously break through this door easily, but he also wants to know how many different pairs of buttons he can pick in order to break through the door.\nCan you help Kim find the number of different pairs of buttons he can press to break through the door? \nNote: Two pairs are considered different if any of the buttons pressed in the pair is different (by position of the button pressed). Two pairs are not considered different if they're the same position of buttons, pressed in a different order. \nPlease refer to the samples for more details.\n\n-----Input:-----\n- The first line contains a single integer $T$, representing the number of testcases. $2T$ lines follow, 2 for each testcase.\n- For each testcase, the first line contains a single integer $N$, the number of buttons.\n- The second line of each testcase contains $N$ space-separated integers, $A_1, A_2, \\ldots, A_N$, representing the numbers written on each button.\n\n-----Output:-----\nPrint a single number, $K$, representing the number of pairs of buttons in $A$ which have an odd sum.\n\n-----Subtasks-----\nFor all subtasks, $1 \\leq T \\leq 10$, $1 \\leq N \\leq 100000$, and $1 \\leq A_i \\leq 100000$ for all $A_i$.\nSubtask 1 [15 points] : $N \\leq 2$, There are at most 2 buttons\nSubtask 2 [45 points] : $N \\leq 1000$, There are at most 1000 buttons\nSubtask 3 [40 points] : No additional constraints.\n\n-----Sample Input:-----\n3\n4\n3 5 3 4\n2\n5 7\n1\n4\n\n-----Sample Output:-----\n3\n0\n0\n\n-----EXPLANATION:-----\nThis section uses 1-indexing.\nIn the first sample, the buttons are: $[3, 5, 3, 4]$\n$A[1] + A[4] = 3 + 4 = 7$ which is odd.\n$A[2] + A[4] = 5 + 4 = 9$ which is odd.\n$A[3] + A[4] = 3 + 4 = 7$ which is odd.\nIn total, there are 3 pairs with an odd sum, so the answer is 3.\nIn the second sample, the buttons are: $[5, 7]$. There are no odd pairs, so the answer is $0$.\nIn the third sample, the buttons are: $[4]$. There are no pairs at all, so the answer is $0$.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\nfor _ in range(int(input())):\n n=int(input())\n a=list(map(int,input().split()))\n even=[]\n odd=[]\n for i in a:\n if(i & 1):\n even.append(i)\n else:\n odd.append(i)\n print(len(even)*len(odd))\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\n4\\n3 5 3 4\\n2\\n5 7\\n1\\n4\\n', 'output': '3\\n0\\n0\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/UWCOI20B'}","problem_id":"vfc_3286","program":"```python\n# cook your dish here\nfor _ in range(int(input())):\n n=int(input())\n a=list(map(int,input().split()))\n even=[]\n odd=[]\n for i in a:\n if(i & 1):\n even.append(i)\n else:\n odd.append(i)\n print(len(even)*len(odd))\n```","inputs":"3\n4\n3 5 3 4\n2\n5 7\n1\n4\n","output":"3\n0\n0\n","actual_output":"3\n0\n0\n","execution_success":true,"sample_index":709},{"source":"apps","task_type":"verifiable_code","in_source_id":"1112","prompt":"Solve the following coding problem using the programming language python:\n\nThe 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.\n\n-----Input:-----\n- First-line will contain $T$, the number of test cases. Then the test cases follow. \n- Each test case contains a single line of input, one integer $K$. \n\n-----Output:-----\nFor each test case, output as the pattern.\n\n-----Constraints-----\n- $1 \\leq T \\leq 100$\n- $1 \\leq K \\leq 100$\n\n-----Sample Input:-----\n4\n1\n2\n3\n4\n\n-----Sample Output:-----\n1\n12\n3\n123\n45\n6\n1234\n567\n89\n10\n\n-----EXPLANATION:-----\nNo need, else pattern can be decode easily.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\nfor _ in range(int(input())):\n n = int(input())\n m = n\n x= 1\n for i in range(n):\n for j in range(m):\n print(x, end = '')\n x += 1\n print()\n m -= 1\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '4\\n1\\n2\\n3\\n4\\n', 'output': '1\\n12\\n3\\n123\\n45\\n6\\n1234\\n567\\n89\\n10\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/PSTR2020/problems/ITGUY58'}","problem_id":"vfc_3290","program":"```python\n# cook your dish here\nfor _ in range(int(input())):\n n = int(input())\n m = n\n x= 1\n for i in range(n):\n for j in range(m):\n print(x, end = '')\n x += 1\n print()\n m -= 1\n```","inputs":"4\n1\n2\n3\n4\n","output":"1\n12\n3\n123\n45\n6\n1234\n567\n89\n10\n","actual_output":"1\n12\n3\n123\n45\n6\n1234\n567\n89\n10\n","execution_success":true,"sample_index":710},{"source":"apps","task_type":"verifiable_code","in_source_id":"1113","prompt":"Solve the following coding problem using the programming language python:\n\nGiven an array A of length N, your task is to find the element which repeats in A maximum number of times as well as the corresponding count. In case of ties, choose the smaller element first.\n\n-----Input-----\nFirst line of input contains an integer T, denoting the number of test cases. Then follows description of T cases. Each case begins with a single integer N, the length of A. Then follow N space separated integers in next line. Assume that 1 <= T <= 100, 1 <= N <= 100 and for all i in [1..N] : 1 <= A[i] <= 10000\n\n-----Output-----\nFor each test case, output two space separated integers V & C. V is the value which occurs maximum number of times and C is its count.\n\n-----Example-----\nInput:\n2\n5\n1 2 3 2 5\n6\n1 2 2 1 1 2\n\nOutput:\n2 2\n1 3\n\nDescription:\nIn first case 2 occurs twice whereas all other elements occur only once. \nIn second case, both 1 and 2 occur 3 times but 1 is smaller than 2.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nt = input();\n\na = [0 for i in range(10001)]\n\ni = 0;\n\nwhile i < int(t):\n\n\tn = input();\n\n\tk = input();\n\n\tassert(len(k.split(' ')) == int(n));\n\n\tfor each in k.split(' '):\n\n\t\ta[int(each)] += 1;\n\n\n\tV = 0;\n\n\tC = a[V];\n\n\tfor j in range(10001):\n\n\t\tif C < a[j]:\n\n\t\t\tV = j;\n\n\t\t\tC = a[V];\n\n\t\ta[j] = 0;\n\n\ti += 1;\n\n\tprint(V, C);\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n5\\n1 2 3 2 5\\n6\\n1 2 2 1 1 2\\n\\n\\n', 'output': '2 2\\n1 3\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/FEB12/problems/MAXCOUNT'}","problem_id":"vfc_3294","program":"```python\nt = input();\n\na = [0 for i in range(10001)]\n\ni = 0;\n\nwhile i < int(t):\n\n\tn = input();\n\n\tk = input();\n\n\tassert(len(k.split(' ')) == int(n));\n\n\tfor each in k.split(' '):\n\n\t\ta[int(each)] += 1;\n\n\n\tV = 0;\n\n\tC = a[V];\n\n\tfor j in range(10001):\n\n\t\tif C < a[j]:\n\n\t\t\tV = j;\n\n\t\t\tC = a[V];\n\n\t\ta[j] = 0;\n\n\ti += 1;\n\n\tprint(V, C);\n\n```","inputs":"2\n5\n1 2 3 2 5\n6\n1 2 2 1 1 2\n\n\n","output":"2 2\n1 3\n","actual_output":"2 2\n1 3\n","execution_success":true,"sample_index":711},{"source":"apps","task_type":"verifiable_code","in_source_id":"1115","prompt":"Solve the following coding problem using the programming language python:\n\nYou are given a tree with $N$ vertices (numbered $1$ through $N$) and a sequence of integers $A_1, A_2, \\ldots, A_N$. You may choose an arbitrary permutation $p_1, p_2, \\ldots, p_N$ of the integers $1$ through $N$. Then, for each vertex $i$, you should assign the value $A_{p_i}$ to this vertex.\nThe profit of a path between two vertices $u$ and $v$ is the sum of the values assigned to the vertices on that path (including $u$ and $v$).\nLet's consider only (undirected) paths that start at a leaf and end at a different leaf. Calculate the maximum possible value of the sum of profits of all such paths. Since this value could be very large, compute it modulo $10^9 + 7$.\n\n-----Input-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The first line of each test case contains a single integer $N$.\n- The second line contains $N$ space-separated integers $A_1, A_2, \\ldots, A_N$.\n- Each of the following $N\u22121$ lines contains two space-separated integers $u$ and $v$ denoting that vertices $u$ and $v$ are connected by an edge.\n\n-----Output-----\nFor each test case, print a single line containing one integer \u2014 the maximum sum of profits, modulo $10^9 + 7$.\n\n-----Constraints-----\n- $1 \\le T \\le 1,000$\n- $1 \\le N \\le 300,000$\n- $1 \\le A_i \\le 10^9$ for each valid $i$\n- the sum of $N$ over all test cases does not exceed $5 \\cdot 10^5$\n\n-----Example Input-----\n2\n4\n1 2 3 4\n1 2\n2 3\n2 4\n5\n1 2 3 4 5\n1 2\n2 3\n3 4\n4 5\n\n-----Example Output-----\n24\n15\n\n-----Explanation-----\nExample case 1: $(1, 4, 2, 3)$ is one of the possible permutations that give the optimal answer. Then, the profits of paths between pairs of vertices $(1, 3)$, $(1, 4)$ and $(3, 4)$ are $7$, $8$ and $9$ respectively.\nExample case 2: Here, any permutation could be chosen.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nT = int(input())\n\nM = 10 ** 9 + 7\n\nfor _ in range(T):\n N = int(input())\n\n A = list(map(int, input().split()))\n\n if N == 1:\n print(0)\n continue\n\n B = {}\n C = {}\n\n for i in range(N - 1):\n u, v = input().split()\n u = int(u) - 1\n v = int(v) - 1\n\n if u not in B:\n B[u] = []\n\n if v not in B:\n B[v] = []\n\n B[u].append(v)\n B[v].append(u)\n\n total_leaves = 0\n\n for i in B:\n if len(B[i]) == 1:\n total_leaves += 1\n\n S = [0]\n\n visited = [False] * N\n\n parent = [-1] * N\n\n total_visits = [0] * N\n\n while len(S) > 0:\n current = S.pop(len(S) - 1)\n\n if visited[current]:\n p = parent[current]\n if p != -1:\n total_visits[p] += total_visits[current]\n if p not in C:\n C[p] = {}\n C[p][current] = total_visits[current]\n if current not in C:\n C[current] = {}\n C[current][p] = total_leaves - C[p][current]\n else:\n S.append(current)\n visited[current] = True\n for i, j in enumerate(B[current]):\n if not visited[j]:\n parent[j] = current\n S.append(j)\n if len(B[current]) == 1:\n total_visits[current] = 1\n p = parent[current]\n if p != -1:\n if p not in C:\n C[p] = {}\n C[p][current] = 1\n\n D = {}\n for i in C:\n sum1 = 0\n for j in C[i]:\n sum1 += C[i][j]\n D[i] = sum1\n\n E = [0] * N\n for i in C:\n sum1 = 0\n for j in C[i]:\n D[i] -= C[i][j]\n sum1 += C[i][j] * D[i]\n E[i] = sum1\n\n for i, j in enumerate(E):\n if j == 0:\n for k in C[i]:\n E[i] = C[i][k]\n\n E.sort()\n E.reverse()\n A.sort()\n A.reverse()\n\n E = [x % M for x in E]\n A = [x % M for x in A]\n\n ans = 0\n for i, j in zip(E, A):\n a = i * j\n a %= M\n ans += a\n ans %= M\n\n print(ans)\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n4\\n1 2 3 4\\n1 2\\n2 3\\n2 4\\n5\\n1 2 3 4 5\\n1 2\\n2 3\\n3 4\\n4 5\\n', 'output': '24\\n15\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/PRT'}","problem_id":"vfc_3302","program":"```python\nT = int(input())\n\nM = 10 ** 9 + 7\n\nfor _ in range(T):\n N = int(input())\n\n A = list(map(int, input().split()))\n\n if N == 1:\n print(0)\n continue\n\n B = {}\n C = {}\n\n for i in range(N - 1):\n u, v = input().split()\n u = int(u) - 1\n v = int(v) - 1\n\n if u not in B:\n B[u] = []\n\n if v not in B:\n B[v] = []\n\n B[u].append(v)\n B[v].append(u)\n\n total_leaves = 0\n\n for i in B:\n if len(B[i]) == 1:\n total_leaves += 1\n\n S = [0]\n\n visited = [False] * N\n\n parent = [-1] * N\n\n total_visits = [0] * N\n\n while len(S) > 0:\n current = S.pop(len(S) - 1)\n\n if visited[current]:\n p = parent[current]\n if p != -1:\n total_visits[p] += total_visits[current]\n if p not in C:\n C[p] = {}\n C[p][current] = total_visits[current]\n if current not in C:\n C[current] = {}\n C[current][p] = total_leaves - C[p][current]\n else:\n S.append(current)\n visited[current] = True\n for i, j in enumerate(B[current]):\n if not visited[j]:\n parent[j] = current\n S.append(j)\n if len(B[current]) == 1:\n total_visits[current] = 1\n p = parent[current]\n if p != -1:\n if p not in C:\n C[p] = {}\n C[p][current] = 1\n\n D = {}\n for i in C:\n sum1 = 0\n for j in C[i]:\n sum1 += C[i][j]\n D[i] = sum1\n\n E = [0] * N\n for i in C:\n sum1 = 0\n for j in C[i]:\n D[i] -= C[i][j]\n sum1 += C[i][j] * D[i]\n E[i] = sum1\n\n for i, j in enumerate(E):\n if j == 0:\n for k in C[i]:\n E[i] = C[i][k]\n\n E.sort()\n E.reverse()\n A.sort()\n A.reverse()\n\n E = [x % M for x in E]\n A = [x % M for x in A]\n\n ans = 0\n for i, j in zip(E, A):\n a = i * j\n a %= M\n ans += a\n ans %= M\n\n print(ans)\n\n```","inputs":"2\n4\n1 2 3 4\n1 2\n2 3\n2 4\n5\n1 2 3 4 5\n1 2\n2 3\n3 4\n4 5\n","output":"24\n15\n","actual_output":"24\n15\n","execution_success":true,"sample_index":713},{"source":"apps","task_type":"verifiable_code","in_source_id":"1116","prompt":"Solve the following coding problem using the programming language python:\n\n-----Problem Statement-----\nWe have an integer sequence $A$, whose length is $N$.\nFind the number of the non-empty contiguous subsequences of $A$ whose sum is $0$. Note that we are counting the ways to take out subsequences. That is, even if the contents of some two subsequences are the same, they are counted individually if they are taken from different positions.\n\n-----Input-----\nInput is given in the following format:\n$N$\n$A_1$ $A_2$ . . . $A_N$\n\n-----Output-----\nFind the number of the non-empty contiguous subsequences of $A$ whose sum is $0$.\n\n-----Constraints-----\n- $1 \\leq N \\leq 2\\times10^5$\n- $-10^9 \\leq A_i \\leq 10^9$\n- All values in input are integers.\n\n-----Sample Input-----\n6\n1 3 -4 2 2 -2\n\n-----Sample Output-----\n3\n\n-----EXPLANATION-----\nThere are three contiguous subsequences whose sums are $0$: $(1, 3, -4)$, $(-4, 2, 2)$ and $(2, -2)$\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfrom collections import defaultdict \ndef findSubarraySum(arr, n, Sum): \n \n # Dictionary to store number of subarrays \n # starting from index zero having \n # particular value of sum. \n prevSum = defaultdict(lambda : 0) \n \n res = 0 \n \n # Sum of elements so far. \n currsum = 0 \n \n for i in range(0, n): \n \n # Add current element to sum so far. \n currsum += arr[i] \n \n # If currsum is equal to desired sum, \n # then a new subarray is found. So \n # increase count of subarrays. \n if currsum == Sum: \n res += 1 \n \n # currsum exceeds given sum by currsum - sum. \n # Find number of subarrays having \n # this sum and exclude those subarrays \n # from currsum by increasing count by \n # same amount. \n if (currsum - Sum) in prevSum: \n res += prevSum[currsum - Sum] \n \n \n # Add currsum value to count of \n # different values of sum. \n prevSum[currsum] += 1 \n \n return res \nn=int(input())\nlst=list(map(int,input().split()))\nif(n==1):\n if(lst[0]==0):\n print(1)\n else:\n print(0)\nelse: \n print(findSubarraySum(lst,n,0)) \n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '6\\n1 3 -4 2 2 -2\\n', 'output': '3\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/SCAT2020/problems/SC_01'}","problem_id":"vfc_3306","program":"```python\nfrom collections import defaultdict \ndef findSubarraySum(arr, n, Sum): \n \n # Dictionary to store number of subarrays \n # starting from index zero having \n # particular value of sum. \n prevSum = defaultdict(lambda : 0) \n \n res = 0 \n \n # Sum of elements so far. \n currsum = 0 \n \n for i in range(0, n): \n \n # Add current element to sum so far. \n currsum += arr[i] \n \n # If currsum is equal to desired sum, \n # then a new subarray is found. So \n # increase count of subarrays. \n if currsum == Sum: \n res += 1 \n \n # currsum exceeds given sum by currsum - sum. \n # Find number of subarrays having \n # this sum and exclude those subarrays \n # from currsum by increasing count by \n # same amount. \n if (currsum - Sum) in prevSum: \n res += prevSum[currsum - Sum] \n \n \n # Add currsum value to count of \n # different values of sum. \n prevSum[currsum] += 1 \n \n return res \nn=int(input())\nlst=list(map(int,input().split()))\nif(n==1):\n if(lst[0]==0):\n print(1)\n else:\n print(0)\nelse: \n print(findSubarraySum(lst,n,0)) \n\n```","inputs":"6\n1 3 -4 2 2 -2\n","output":"3\n","actual_output":"3\n","execution_success":true,"sample_index":714},{"source":"apps","task_type":"verifiable_code","in_source_id":"1117","prompt":"Solve the following coding problem using the programming language python:\n\nIt is the end of 2019 \u2014 the 17th of November, the Cooking Challenge day.\nThere are N$N$ players participating in this competition, numbered 1$1$ through N$N$. Initially, the skill level of each player is zero. There are also M$M$ challenges (numbered 1$1$ through M$M$). For each valid i$i$, the i$i$-th challenge has three parameters Li$L_i$, Ri$R_i$ and Xi$X_i$ with the following meaning: for each player between the Li$L_i$-th and Ri$R_i$-th inclusive, if this player participates in this challenge, their skill level increases by Xi$X_i$ (Xi$X_i$ does not have to be positive).\nThe organizers of the Cooking Challenge decided that the contest would be boring if they let the participants participate in the challenges directly, so they decided to use the compos.\nThere are Q$Q$ compos (numbered 1$1$ through Q$Q$). For each valid i$i$, the i$i$-th compo has two parameters Ai$A_i$ and Bi$B_i$, which means that it includes the challenges Ai,Ai+1,\u2026,Bi$A_i, A_i+1, \\ldots, B_i$.\nEach participant has to select a subset of the compos (possibly empty or the set of all Q$Q$ compos) and participate in all challenges those compos include. A participant may not select the same compo twice, but may participate in the same challenge more than once if it is included in multiple chosen compos.\nFor each player, find the maximum skill level this player can reach if the compos are chosen optimally.\n\n-----Input-----\n- 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.\n- The first line of each test case contains three space-separated integers N$N$, M$M$ and Q$Q$.\n- M$M$ lines follow. For each valid i$i$, the i$i$-th of these lines contains three space-separated integers Li$L_i$, Ri$R_i$ and Xi$X_i$.\n- Q$Q$ more lines follow. For each valid i$i$, the i$i$-th of these lines contains two space-separated integers Ai$A_i$ and Bi$B_i$.\n\n-----Output-----\nFor each test case, print a single line containing N$N$ space-separated integers. For each valid i$i$, the i$i$-th of these integers should denote the maximum skill level of the i$i$-th player.\n\n-----Constraints-----\n- 1\u2264T\u22641,000$1 \\le T \\le 1,000$\n- 1\u2264N\u2264100,000$1 \\le N \\le 100,000$\n- 1\u2264M\u22641,000$1 \\le M \\le 1,000$\n- 1\u2264Q\u226410,000$1 \\le Q \\le 10,000$\n- 1\u2264Li\u2264Ri\u2264N$1 \\le L_i \\le R_i \\le N$ for each valid i$i$\n- 1\u2264Ai\u2264Bi\u2264M$1 \\le A_i \\le B_i \\le M$ for each valid i$i$\n- |Xi|\u22641,000,000$|X_i| \\le 1,000,000$ for each valid i$i$\n- the sum of N$N$ over all test cases does not exceed 1,000,000$1,000,000$\n- the sum of M$M$ over all test cases does not exceed 5,000$5,000$\n- the sum of Q$Q$ over all test cases does not exceed 50,000$50,000$\n\n-----Example Input-----\n1\n5 3 4\n1 1 3\n1 2 -4\n4 5 2\n1 2\n1 3\n1 1\n2 3\n\n-----Example Output-----\n3 0 0 4 4\n\n-----Explanation-----\nExample case 1:\n- The first player will select the 3$3$-rd compo.\n- The second and third players will not select any compo.\n- The fourth player will select the 1$1$-st, 2$2$-nd and 4$4$-th compos.\n- The fifth player will select all the compos.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nimport numpy as np\n\ndef sort_it(array):\n new_list = []\n for i in range(len(array)):\n start = 0\n value = array[i][0]\n last = len(new_list)\n while start != last:\n mid = (start + last) // 2\n if new_list[mid][0] > value:\n last = mid\n else:\n start = mid+1\n new_list.insert(start,array[i])\n return new_list\n\ntests = int(input())\nfor _ in range(tests):\n n, m, q = [int(j) for j in input().split()]\n challenges = [[0] * 3 for _ in range(m)]\n combos = [[0] * 2 for _ in range(q)]\n for i in range(m):\n challenges[i] = [int(j) for j in input().split()]\n for i in range(q):\n combos[i] = [int(j) for j in input().split()]\n \n sorted_chalenges = np.zeros((2 * m, 3),dtype=np.intc)\n for i in range(m):\n sorted_chalenges[2*i] = [challenges[i][0]-1,challenges[i][2],i]\n sorted_chalenges[2*i+1] = [challenges[i][1],-challenges[i][2],i]\n sorted_chalenges = np.array(sort_it(sorted_chalenges))\n types_of_players = np.zeros((m + 1, 2 * m + 1),dtype=np.intc)\n player_type = np.zeros(n,dtype=np.intc)\n last_player = 0\n for i in range(2 * m):\n start, value, chal = sorted_chalenges[i]\n types_of_players[chal+1:,i+1:] += value\n player_type[last_player:start] = i\n last_player = start\n player_type[last_player:] = 2 * m\n \n combo_types = np.zeros((q, 2 * m + 1),dtype = np.intc)\n for i in range(q):\n first, last = combos[i]\n r, p = [types_of_players[first - 1], types_of_players[last]]\n combo_types[i] = np.maximum(p-r,0)\n output = np.sum(combo_types,axis=0)[player_type]\n for i in range(n):\n print(output[i], end = \" \")\n print(\"\")\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n5 3 4\\n1 1 3\\n1 2 -4\\n4 5 2\\n1 2\\n1 3\\n1 1\\n2 3\\n', 'output': '3 0 0 4 4\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/CHADAY'}","problem_id":"vfc_3310","program":"```python\nimport numpy as np\n\ndef sort_it(array):\n new_list = []\n for i in range(len(array)):\n start = 0\n value = array[i][0]\n last = len(new_list)\n while start != last:\n mid = (start + last) // 2\n if new_list[mid][0] > value:\n last = mid\n else:\n start = mid+1\n new_list.insert(start,array[i])\n return new_list\n\ntests = int(input())\nfor _ in range(tests):\n n, m, q = [int(j) for j in input().split()]\n challenges = [[0] * 3 for _ in range(m)]\n combos = [[0] * 2 for _ in range(q)]\n for i in range(m):\n challenges[i] = [int(j) for j in input().split()]\n for i in range(q):\n combos[i] = [int(j) for j in input().split()]\n \n sorted_chalenges = np.zeros((2 * m, 3),dtype=np.intc)\n for i in range(m):\n sorted_chalenges[2*i] = [challenges[i][0]-1,challenges[i][2],i]\n sorted_chalenges[2*i+1] = [challenges[i][1],-challenges[i][2],i]\n sorted_chalenges = np.array(sort_it(sorted_chalenges))\n types_of_players = np.zeros((m + 1, 2 * m + 1),dtype=np.intc)\n player_type = np.zeros(n,dtype=np.intc)\n last_player = 0\n for i in range(2 * m):\n start, value, chal = sorted_chalenges[i]\n types_of_players[chal+1:,i+1:] += value\n player_type[last_player:start] = i\n last_player = start\n player_type[last_player:] = 2 * m\n \n combo_types = np.zeros((q, 2 * m + 1),dtype = np.intc)\n for i in range(q):\n first, last = combos[i]\n r, p = [types_of_players[first - 1], types_of_players[last]]\n combo_types[i] = np.maximum(p-r,0)\n output = np.sum(combo_types,axis=0)[player_type]\n for i in range(n):\n print(output[i], end = \" \")\n print(\"\")\n\n```","inputs":"1\n5 3 4\n1 1 3\n1 2 -4\n4 5 2\n1 2\n1 3\n1 1\n2 3\n","output":"3 0 0 4 4\n","actual_output":"3 0 0 4 4 \n","execution_success":true,"sample_index":715},{"source":"apps","task_type":"verifiable_code","in_source_id":"1118","prompt":"Solve the following coding problem using the programming language python:\n\nChef is playing a game which contains a binary string. \nHe can perform one operation only:\n- Toggle the i_th bit of the string (0 to 1 or 1 to 0)\nBy performing operations on the string (can be zero times), you have to convert the string with no adjacent bit being the same.\nCan you help chef ?\n\n-----Input:-----\n- First line will contain $T$, number of test cases. Then the test cases follow. \n- First line of each test case, contains the size of the string $N$\n- Seond line contains a single line of input, the binary string. \n\n-----Output:-----\nFor each testcase, output in a single line answer - the minimum operations.\n\n-----Constraints-----\n- $1 \\leq T \\leq 100$\n- $2 \\leq |S| \\leq 10^3$\n\n-----Sample Input:-----\n1\n4\n1011\n\n-----Sample Output:-----\n1\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n'''\nName : Jaymeet Mehta\ncodechef id :mj_13\nProblem : Avenir Strings\n'''\nfrom sys import stdin,stdout\ntest=int(stdin.readline())\nfor _ in range(test):\n N=int(stdin.readline())\n seq=list(input())\n fp,fp1,fl,fl1=0,0,0,1\n for i in range(N):\n if fl!=int(seq[i])-0:\n fp+=1\n fl=1-fl\n for i in range(N):\n if fl1!=int(seq[i])-0:\n fp1+=1\n fl1=1-fl1\n print(fp) if fp0:\n a=input().split(\":\")\n a1=int(a[0])\n a2=int(a[1])\n b1=a1%12 \n if a2%5!=0:\n b2=(a2//5)*5+5\n else:\n b2=a2\n \n c1=b1*30 \n \n extra=0.5*b2 \n c1+=extra\n c1%=360\n\n d1=(b2//5)*30 \n d1%=360 \n \n if c1>d1:\n ans1=c1-d1 \n ans2=360-ans1\n else:\n ans1=d1-c1\n ans2=360-ans1\n ans=min(ans1,ans2)\n if ans==int(ans):\n ans3=int(ans)\n y=str(ans3)+\" degree\"\n print(y)\n else:\n y=str(ans)+\" degree\"\n print(y)\n \n t-=1\n \n \n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\n14:20\\n02:10\\n09:30\\n', 'output': '50 degree\\n5 degree\\n105 degree\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/PAHC2020/problems/CHEFJUMP'}","problem_id":"vfc_3326","program":"```python\n# cook your dish here\nt=int(input())\nwhile t>0:\n a=input().split(\":\")\n a1=int(a[0])\n a2=int(a[1])\n b1=a1%12 \n if a2%5!=0:\n b2=(a2//5)*5+5\n else:\n b2=a2\n \n c1=b1*30 \n \n extra=0.5*b2 \n c1+=extra\n c1%=360\n\n d1=(b2//5)*30 \n d1%=360 \n \n if c1>d1:\n ans1=c1-d1 \n ans2=360-ans1\n else:\n ans1=d1-c1\n ans2=360-ans1\n ans=min(ans1,ans2)\n if ans==int(ans):\n ans3=int(ans)\n y=str(ans3)+\" degree\"\n print(y)\n else:\n y=str(ans)+\" degree\"\n print(y)\n \n t-=1\n \n \n\n```","inputs":"3\n14:20\n02:10\n09:30\n","output":"50 degree\n5 degree\n105 degree\n","actual_output":"50 degree\n5 degree\n105 degree\n","execution_success":true,"sample_index":718},{"source":"apps","task_type":"verifiable_code","in_source_id":"1122","prompt":"Solve the following coding problem using the programming language python:\n\nRavi is very good student in mathematics and he also like Even numbers very much .\n\nOn the other hand his friend Jhon like Odd numbers . Both of them are preparing for IIT JEE Advance .One day they are solving a question together the question was Find the sum of first $n$ terms of the given series $1^2+2.2^2+3^2+2.4^2+5^2+2.6^2+...........$\nIf the sum is odd then Jhon will be happy and will solve 2 more questions,and Ravi will not attempt more questions. If sum is even Ravi will be happy and will solve 2 more questions and Jhon will not attempt more questions. \nSo Your task is to decide who will solve more questions.\n\n-----Input:-----\n- First line will contain $n$, number of terms in the given series.\n\n-----Output:-----\nOutput single line \"Ravi\" if he solve more questions or \"Jhon\" if he solve more questions.\n\n-----Constraints-----\n- $1 \\leq n \\leq 100$\n\n-----Sample Input:-----\n2\n\n3 \n\n-----Sample Output:-----\nJhon \nRavi \n\n-----EXPLANATION:-----\nIn the first test cases sum of 2 terms is 9 (according to the given series) which is an odd number so Jhon will solve 2 more questions and Ravi will not attempt more questions.\nIn second test case sum of 3 terms is 18 (according to the given series) which is an even number according to the given series so Ravi will solve 3 more questions and Jhon will not attempt more questions.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\nwhile True:\n\ttry:\n\t\tm=int(input())\n\t\t\n\t\tn=int(m/2)\n\t\t\n\t\ta=m-n\n\t\n\t\tsum_even= int(2*(2*n*(n+1)*(2*n+1))/3)\n\t\t\n\t\tsum_odd= int(((4*a*a*a)-a)/3)\n\t\t\n\t\tresult=sum_odd+sum_even\n\t\t\n\t\tif result%2==0:\n\t\t\tprint('Ravi')\n\t\telse:\n\t\t\tprint('Jhon')\n\texcept:\n\t\tbreak;\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n3\\n', 'output': 'Jhon\\nRavi\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/CFUN2020/problems/CODSTAN7'}","problem_id":"vfc_3330","program":"```python\n# cook your dish here\nwhile True:\n\ttry:\n\t\tm=int(input())\n\t\t\n\t\tn=int(m/2)\n\t\t\n\t\ta=m-n\n\t\n\t\tsum_even= int(2*(2*n*(n+1)*(2*n+1))/3)\n\t\t\n\t\tsum_odd= int(((4*a*a*a)-a)/3)\n\t\t\n\t\tresult=sum_odd+sum_even\n\t\t\n\t\tif result%2==0:\n\t\t\tprint('Ravi')\n\t\telse:\n\t\t\tprint('Jhon')\n\texcept:\n\t\tbreak;\n```","inputs":"2\n3\n","output":"Jhon\nRavi\n","actual_output":"Jhon\nRavi\n","execution_success":true,"sample_index":719},{"source":"apps","task_type":"verifiable_code","in_source_id":"1123","prompt":"Solve the following coding problem using the programming language python:\n\nChef has decided to start home delivery from his restaurant. He hopes that he will get a lot of orders for delivery, however there is a concern. He doesn't have enough work forces for all the deliveries. For this he has came up with an idea - he will group together all those orders which have to be delivered in nearby areas. \n\nIn particular, he has identified certain bidirectional roads which he calls as fast roads. They are short and usually traffic free, so the fast travel is possible along these roads. His plan is that he will send orders to locations A and B together if and only if it is possible to travel between A and B using only fast roads. Your task is, given the configuration of fast roads, identify which orders are to be sent together.\n\n-----Input-----\nFirst line of input contains an integer T, the number of test cases. Then T test cases follow. First line of each test case contains two space separated integers N and M, denoting number of locations and the number of fast roads. Then M lines follow each containing two space separated integers A and B, denoting that there is a fast road between locations A and B. Assume that locations are indexed by numbers from 0 to N-1. \n\nNext line contains an integer Q denoting the number of queries. Each of the next Q lines contain two integers X and Y. For each query you have to find out if orders meant for locations X and Y are to be sent together or not.\n\nNote that there might be multiple fast roads between same pair of locations, also there might be a fast road that links a location to itself.\n\n-----Output-----\nFor each test case print Q lines - one for each query. Output \"YO\" if the orders are to be \ndelivered together and \"NO\" otherwise (quotes for clarity).\n\n-----Constraints-----\n1 \u2264 T \u2264 100\n1 \u2264 N \u2264 100\n1 \u2264 M \u2264 1000\n0 \u2264 A, B, X, Y \u2264 N-1\n1 \u2264 Q \u2264 3000\n\n-----Example-----\nInput:\n1\n4 2\n0 1\n1 2\n3\n0 2\n0 3\n2 1\n\nOutput:\nYO\nNO\nYO\n\n-----Warning!-----\nThere are large input and output files in this problem. Make sure you use fast enough I/O methods.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\nfrom sys import stdin, stdout\nfrom math import ceil\n\n\ndef solve():\n for _ in range(int(input())):\n n, m = map(int, stdin.readline().split())\n par = [i for i in range(n)]\n for i in range(m):\n ta, tb = map(int, stdin.readline().strip().split())\n a, b = min(ta, tb), max(ta, tb)\n for j in range(n):\n if par[j] == par[b] and j != b:\n par[j] = par[a]\n par[b] = par[a]\n\n q = int(input())\n while q:\n q -= 1\n x, y = map(int, stdin.readline().split())\n if par[x] == par[y]:\n print(\"YO\")\n else:\n print(\"NO\")\n\n\ndef __starting_point():\n solve()\n\n__starting_point()\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n4 2\\n0 1\\n1 2\\n3\\n0 2\\n0 3\\n2 1\\n\\n\\n', 'output': 'YO\\nNO\\nYO\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/HDELIVER'}","problem_id":"vfc_3334","program":"```python\n# cook your dish here\nfrom sys import stdin, stdout\nfrom math import ceil\n\n\ndef solve():\n for _ in range(int(input())):\n n, m = map(int, stdin.readline().split())\n par = [i for i in range(n)]\n for i in range(m):\n ta, tb = map(int, stdin.readline().strip().split())\n a, b = min(ta, tb), max(ta, tb)\n for j in range(n):\n if par[j] == par[b] and j != b:\n par[j] = par[a]\n par[b] = par[a]\n\n q = int(input())\n while q:\n q -= 1\n x, y = map(int, stdin.readline().split())\n if par[x] == par[y]:\n print(\"YO\")\n else:\n print(\"NO\")\n\n\ndef __starting_point():\n solve()\n\n__starting_point()\n```","inputs":"1\n4 2\n0 1\n1 2\n3\n0 2\n0 3\n2 1\n\n\n","output":"YO\nNO\nYO\n","actual_output":"YO\nNO\nYO\n","execution_success":true,"sample_index":720},{"source":"apps","task_type":"verifiable_code","in_source_id":"1124","prompt":"Solve the following coding problem using the programming language python:\n\nLumpy is a bus driver. Today, the conductor is absent so Lumpy has to do the conductor's job as well. There are N creatures in the bus. Sometimes the creatures don't carry change and can't pay the exact amount of the fare. Each creature in the bus today has paid an amount\ngreater than his/her fare. You are given information about the extra amount paid by each creature, by an array A of size N, where Ai denotes the extra amount paid by the i-th creature, in rupees.\nAfter the end of the trip, Lumpy noticed that he had P one rupee coins and Q two rupee coins. He wants to pay back the creatures using this money. Being a kind hearted moose, Lumpy wants to pay back as many creatures as he can. Note that Lumpy will \nnot pay back the i-th creature if he can't pay the exact amount that the i-th creature requires with the coins that he possesses. \nLumpy is busy driving the bus and doesn't want to calculate the maximum number of creatures he can satisfy - He will surely cause an accident if he tries to do so. Can you help him out with this task? \n\n-----Input-----\n- The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.\n- For each test case, first line consists of three space separated integers N, P and Q.\n- Second line consists of N space separated integers A containing N space integers, where i-th integer denotes Ai.\n\n-----Output-----\n- For each test case, output a single line containing an integer corresponding to maximum number of creatures that Lumpy can pay back.\n\n-----Constraints-----\n- 1 \u2264 T \u2264 106\n- 1 \u2264 N \u2264 105\n- 1 \u2264 Ai \u2264 109\n- 0 \u2264 P, Q \u2264 1014\n- Sum of N over all the cases does not exceed 106\n\n-----Subtasks-----\n- Subtask #1 (15 points): P = 0\n- Subtask #2 (15 points): Q = 0\n- Subtask #3 (70 points): Original constraints\n\n-----Example-----\nInput:3\n3 3 0\n1 2 2\n3 2 1\n1 2 1\n4 5 4\n2 3 4 5\n\nOutput:2\n3\n3\n\n-----Explanation-----\nExample 1. Lumpy has just 3 one rupee coins. \n\nHe can pay creatures numbered {1, 2} or creatures numbered {1, 3} with these coins. Thus, answer is 2. \nExample 2. Lumpy has 2 one rupee coins and 1 two rupee coin. \n\nIn the optimal solution, Lumpy can give the two rupee coin to creature 2 and the one rupee coins to creatures 1 and 3. Thus, answer is 3.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\n# cook your dish here\nt=int(input())\nfor _ in range(t):\n n,p,q=list(map(int,input().split(\" \")))\n l=list(map(int,input().split(\" \")))\n l.sort()\n s=sum(l)\n a=p+2*q\n b=0\n for i in l:\n if(p==0):\n if(i%2==0 and a>=i):\n a=a-i\n b=b+1\n elif(q==0):\n if(a>=i):\n a=a-i\n b=b+1\n else:\n if(i%2==0 and a>=i):\n a=a-i\n b=b+1\n elif(i%2!=0 and p!=0 and a>=i):\n a=a-i\n b=b+1\n p=p-1\n\n print(b) \n \n \n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\n3 3 0\\n1 2 2\\n3 2 1\\n1 2 1\\n4 5 4\\n2 3 4 5\\n', 'output': '2\\n3\\n3\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/LUMPYBUS'}","problem_id":"vfc_3338","program":"```python\n# cook your dish here\n# cook your dish here\nt=int(input())\nfor _ in range(t):\n n,p,q=list(map(int,input().split(\" \")))\n l=list(map(int,input().split(\" \")))\n l.sort()\n s=sum(l)\n a=p+2*q\n b=0\n for i in l:\n if(p==0):\n if(i%2==0 and a>=i):\n a=a-i\n b=b+1\n elif(q==0):\n if(a>=i):\n a=a-i\n b=b+1\n else:\n if(i%2==0 and a>=i):\n a=a-i\n b=b+1\n elif(i%2!=0 and p!=0 and a>=i):\n a=a-i\n b=b+1\n p=p-1\n\n print(b) \n \n \n\n```","inputs":"3\n3 3 0\n1 2 2\n3 2 1\n1 2 1\n4 5 4\n2 3 4 5\n","output":"2\n3\n3\n","actual_output":"2\n3\n3\n","execution_success":true,"sample_index":721},{"source":"apps","task_type":"verifiable_code","in_source_id":"1125","prompt":"Solve the following coding problem using the programming language python:\n\nYou are the principal of the Cake school in chefland and today is your birthday. You want to treat each of the children with a small cupcake which is made by you. But there is a problem, You don't know how many students are present today.\nThe students have gathered of the morning assembly in $R$ rows and $C$ columns. Now you have to calculate how many cakes you have to make such that each child gets a cupcake. \n\n-----Input:-----\n- First-line will contain $T$, the number of test cases. Then the test cases follow. \n- Each test case contains a single line of input, two integers $R$ and $C$. \n\n-----Output:-----\nFor each test case, output number of cupcakes you have to make.\n\n-----Constraints-----\n- $1 \\leq T \\leq 1000$\n- $2 \\leq R,C \\leq 10^6$\n\n-----Sample Input:-----\n1\n5 10\n\n-----Sample Output:-----\n50\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\nfor _ in range(int(input())):\n n=list(map(int,input().split()))\n print(n[0]*n[1])\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n5 10\\n', 'output': '50\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/ENDE2020/problems/ENCDEC2'}","problem_id":"vfc_3342","program":"```python\n# cook your dish here\nfor _ in range(int(input())):\n n=list(map(int,input().split()))\n print(n[0]*n[1])\n\n```","inputs":"1\n5 10\n","output":"50\n","actual_output":"50\n","execution_success":true,"sample_index":722},{"source":"apps","task_type":"verifiable_code","in_source_id":"1126","prompt":"Solve the following coding problem using the programming language python:\n\n\"How did you get the deal,how did he agree?\"\n\"Its's simple Tom I just made him an offer he couldn't refuse\" \nAyush is the owner of a big construction company and a close aide of Don Vito The Godfather, recently with the help of the Godfather his company has been assigned a big contract according to the contract he has to make n number of V shaped infinitely long roads(two V shaped roads may or not intersect) on an infinitely large field.\nNow the company assigning the contract needs to know the maximum number of regions they can get after making n such roads.\nHelp Ayush by answering the above question.\n\n-----Input:-----\n- The first line consists of the number of test cases $T$. \n- Next T lines consists of the number of V shaped roads $n$.\n\n-----Output:-----\nFor each test case print a single line consisting of the maximum regions obtained.\n\n-----Constraints-----\n- $1 \\leq T \\leq 10$\n- $1 \\leq n \\leq 10^9$\n\n-----Sample Input:-----\n2\n1\n2\n\n-----Sample Output:-----\n2\n7\n\n-----EXPLANATION:-----\nTest case 1: For one V shaped road there will be 2 regions\n\nTest case 2: For n=2 the following figure depicts the case of maximum regions:\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfor _ in range(int(input())):\n n=int(input())\n print((2*(pow(n,2)))-n+1)\n\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n1\\n2\\n', 'output': '2\\n7\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/CFW32020/problems/AYUSCRT'}","problem_id":"vfc_3346","program":"```python\nfor _ in range(int(input())):\n n=int(input())\n print((2*(pow(n,2)))-n+1)\n\n\n```","inputs":"2\n1\n2\n","output":"2\n7\n","actual_output":"2\n7\n","execution_success":true,"sample_index":723},{"source":"apps","task_type":"verifiable_code","in_source_id":"1128","prompt":"Solve the following coding problem using the programming language python:\n\nThe Chef is given an array of numbers and asked to find the first balance point of an array. A balance point is an index in the array N where the sum of the integers to the left of N is equal to the sum of the integers to the right of N. If there is no such balance point, print -1\n\n-----Input-----\nThe first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.\nThe first line of each test case contains a single integer N denoting the number of weights on the array. The second line contains N space-separated integers A1, A2, ..., AN denoting the weights\n\n-----Output-----\nFor each test case, output a single line containing the index of the first balance point. If no such index exists, output -1\n\n-----Constraints-----\nFor Subtask 1:\n- 1 \u2264 T \u2264 10\n- 1 \u2264 N \u2264 10\n- -1000 \u2264 A1, A2, ..., AN \u2264 1000\nFor Subtask 1:\n- 1 \u2264 T \u2264 10\n- 1 \u2264 N \u2264 1000\n- -10000 \u2264 A1, A2, ..., AN \u2264 10000\n\n-----Example-----\nInput:\n2\n7\n7 8 9 1 9 8 7\n6\n1 100 50 -51 1 1\n\nOutput:\n3\n1\n\n-----Explanation-----\nExample case 1. In the first case, at the midpoint of the array 1, the sum of the left side {7,8,9} is equal to the sum of the right side {9,8,7}\nExample case 1. In the second case, at index 1, the sum of left side =1 is equal to the sum of the right side {50,-51,1,1}\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nimport sys\n\nt = eval(input())\nfor j in range(t):\n n = eval(input())\n a = list(map(int, input().split()))\n ch = 0\n sm = 0 ; x = sum(a)\n s1 = [0] * n ; s2 = [0] * n\n for i in range(n):\n sm += a[i]\n s1[i] = sm\n s2[i] = x\n x -= a[i]\n if(sum(a) - a[0] == 0):\n print(0)\n elif(sum(a) - a[n - 1] == 0):\n print(n - 1)\n else:\n for i in range(1, n - 1):\n if(s1[i - 1] == s2[i + 1]):\n print(i)\n ch = 1\n break\n if(ch == 0):\n if(n == 1):\n print(0)\n else:\n print(-1)\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n7\\n7 8 9 1 9 8 7\\n6\\n1 100 50 -51 1 1\\n', 'output': '3\\n1\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/TSCO2017/problems/TSECJ101'}","problem_id":"vfc_3354","program":"```python\nimport sys\n\nt = eval(input())\nfor j in range(t):\n n = eval(input())\n a = list(map(int, input().split()))\n ch = 0\n sm = 0 ; x = sum(a)\n s1 = [0] * n ; s2 = [0] * n\n for i in range(n):\n sm += a[i]\n s1[i] = sm\n s2[i] = x\n x -= a[i]\n if(sum(a) - a[0] == 0):\n print(0)\n elif(sum(a) - a[n - 1] == 0):\n print(n - 1)\n else:\n for i in range(1, n - 1):\n if(s1[i - 1] == s2[i + 1]):\n print(i)\n ch = 1\n break\n if(ch == 0):\n if(n == 1):\n print(0)\n else:\n print(-1)\n\n```","inputs":"2\n7\n7 8 9 1 9 8 7\n6\n1 100 50 -51 1 1\n","output":"3\n1\n","actual_output":"3\n1\n","execution_success":true,"sample_index":725},{"source":"apps","task_type":"verifiable_code","in_source_id":"1129","prompt":"Solve the following coding problem using the programming language python:\n\nChef\u2019s girlfriend is angry with him because he forgot her birthday. Chef decided to please her by gifting her a Love Graph. \nChef has $N$ vertices: $V_1, V_2, \\dots, V_N$. Love Graph is an undirected multigraph with no self-loops and can be constructed by performing the following operations:-\n- Choose an integer $i$ ($1 \\leq i \\leq N$)\n- Choose another integer $j \\space \\space \\{ (i \\neq j) \\text{ and } (1 \\leq j \\leq N) \\}$\n- Make an edge between $V_i$ and $V_j$\n- Set $i = j$\n- Repeat steps $2, 3$ and $4$ in order $M-1$ more times.\nFind the number of ways in which Chef can construct a Love Graph. Since the answer can be very large, compute it modulo $10^9+7$.\n\n-----Input-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. \n- The first line of each test case contains two space-separated integers $N$ and $M$.\n\n-----Output-----\nFor each test case, print a single line containing one integer \u2014 the number of ways in which Chef can construct a Love Graph modulo $10^9+7$.\n\n-----Constraints-----\n- $1 \\leq T \\leq 10^5$\n- $2 \\leq N \\leq 10^9$\n- $1 \\leq M \\leq 10^{18}$\n\n-----Subtasks-----\n- 30 points:\n- $1 \\leq T \\leq 100$\n- $2 \\leq N \\leq 10$\n- $1 \\leq M \\leq 10$ \n- 70 points: original constraints\n\n-----Sample Input-----\n1\n\n2 1 \n\n-----Sample Output-----\n2 \n\n-----Explanation-----\nThere are two ways of constructing Love Graph.\n\nIn first way, we pick Vertex 1 and then join with Vertex 2.\n\nIn second way, we pick Vertex 2 and then join with Vertex 1.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\ndef fastpow(base, power):\n result = 1\n while power > 0:\n if power % 2 == 0:\n power = power // 2\n\n base = base * base\n else:\n power = power - 1\n result = result * base\n power = power // 2\n base = base * base\n return result\n\nt=int(input())\nfor i in range(t):\n a=list(map(int,input().split()))\n n,r=a[0],a[1]\n w=(n*(fastpow(n-1,r)))%((10**9)+7)\n \n print(w)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n2 1\\n', 'output': '2\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/DCC2020/problems/DCC201'}","problem_id":"vfc_3358","program":"```python\ndef fastpow(base, power):\n result = 1\n while power > 0:\n if power % 2 == 0:\n power = power // 2\n\n base = base * base\n else:\n power = power - 1\n result = result * base\n power = power // 2\n base = base * base\n return result\n\nt=int(input())\nfor i in range(t):\n a=list(map(int,input().split()))\n n,r=a[0],a[1]\n w=(n*(fastpow(n-1,r)))%((10**9)+7)\n \n print(w)\n```","inputs":"1\n2 1\n","output":"2\n","actual_output":"2\n","execution_success":true,"sample_index":726},{"source":"apps","task_type":"verifiable_code","in_source_id":"1130","prompt":"Solve the following coding problem using the programming language python:\n\nFinally, a COVID vaccine is out on the market and the Chefland government has asked you to form a plan to distribute it to the public as soon as possible. There are a total of $N$ people with ages $a_1, a_2, \\ldots, a_N$.\nThere is only one hospital where vaccination is done and it is only possible to vaccinate up to $D$ people per day. Anyone whose age is $\\ge 80$ or $\\le 9$ is considered to be at risk. On each day, you may not vaccinate both a person who is at risk and a person who is not at risk. Find the smallest number of days needed to vaccinate everyone.\n\n-----Input-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The first line of each test case contains two space-separated integers $N$ and $D$.\n- The second line contains $N$ space-separated integers $a_1, a_2, \\ldots, a_N$.\n\n-----Output-----\nFor each test case, print a single line containing one integer \u2015 the smallest required number of days.\n\n-----Constraints-----\n- $1 \\le T \\le 10$\n- $1 \\le N \\le 10^4$\n- $1 \\le D \\le 10^5$\n- $1 \\le a_i \\le 100$ for each valid $i$\n\n-----Subtasks-----\nSubtask #1 (100 points): original constraints\n\n-----Example Input-----\n2\n10 1\n10 20 30 40 50 60 90 80 100 1\n5 2\n9 80 27 72 79\n\n-----Example Output-----\n10\n3\n\n-----Explanation-----\nExample case 1: We do not need to worry about how the people are grouped, since only one person can be vaccinated in a single day. We require as many days as there are people.\nExample case 2: There are two people at risk and three people who are not at risk. One optimal strategy is to vaccinate the two people at risk on day $1$ and the remaining three on the next $2$ days.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfor _ in range(int(input())):\n f,d=list(map(int,input().split()))\n arr=list(map(int,input().split()))\n risk=0\n days_risk=0\n days_norm=0\n if d==1:\n print(f)\n else:\n for a in arr:\n if a>=80 or a<=9:\n risk+=1\n norm=f-risk\n if risk%d==0:\n days_risk=risk//d\n else:\n days_risk=(risk//d)+1\n if norm%d==0:\n days_norm=norm//d\n else:\n days_norm=(norm//d)+1\n print(days_risk+days_norm)\n \n \n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n10 1\\n10 20 30 40 50 60 90 80 100 1\\n5 2\\n9 80 27 72 79\\n', 'output': '10\\n3\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/VACCINE2'}","problem_id":"vfc_3362","program":"```python\nfor _ in range(int(input())):\n f,d=list(map(int,input().split()))\n arr=list(map(int,input().split()))\n risk=0\n days_risk=0\n days_norm=0\n if d==1:\n print(f)\n else:\n for a in arr:\n if a>=80 or a<=9:\n risk+=1\n norm=f-risk\n if risk%d==0:\n days_risk=risk//d\n else:\n days_risk=(risk//d)+1\n if norm%d==0:\n days_norm=norm//d\n else:\n days_norm=(norm//d)+1\n print(days_risk+days_norm)\n \n \n\n```","inputs":"2\n10 1\n10 20 30 40 50 60 90 80 100 1\n5 2\n9 80 27 72 79\n","output":"10\n3\n","actual_output":"10\n3\n","execution_success":true,"sample_index":727},{"source":"apps","task_type":"verifiable_code","in_source_id":"1131","prompt":"Solve the following coding problem using the programming language python:\n\nChef has an array of N natural numbers most of them are repeated. Cheffina challenges chef to find all numbers(in ascending order) whose frequency is strictly more than K.\n\n-----Input:-----\n- First-line will contain $T$, the number of test cases. Then the test cases follow. \n- Each test case contains two lines of input, two integers $N, K$.\n- N space-separated natural numbers.\n\n-----Output:-----\nFor each test case, output in a single line answer.\n\n-----Constraints-----\n- $1 \\leq T \\leq 10$\n- $1 \\leq N, K \\leq 10^5$\n- $1 \\leq arr[i] \\leq 10^5$\n\n-----Sample Input:-----\n1\n5 1\n5 2 1 2 5\n\n-----Sample Output:-----\n2 5\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfor _ in range(int(input())):\n n,k=[int(x) for x in input().split()]\n a=list(map(int,input().split()))\n dp=[0]*(max(a)+1)\n for _ in range(n):\n dp[a[_]]+=1\n for _ in range(1,len(dp)):\n if dp[_]>k:\n print(_,end=\" \")\n print()\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n5 1\\n5 2 1 2 5\\n', 'output': '2 5\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/PEND2020/problems/ANITGUY8'}","problem_id":"vfc_3366","program":"```python\nfor _ in range(int(input())):\n n,k=[int(x) for x in input().split()]\n a=list(map(int,input().split()))\n dp=[0]*(max(a)+1)\n for _ in range(n):\n dp[a[_]]+=1\n for _ in range(1,len(dp)):\n if dp[_]>k:\n print(_,end=\" \")\n print()\n```","inputs":"1\n5 1\n5 2 1 2 5\n","output":"2 5\n","actual_output":"2 5 \n","execution_success":true,"sample_index":728},{"source":"apps","task_type":"verifiable_code","in_source_id":"1132","prompt":"Solve the following coding problem using the programming language python:\n\nShaun was given $N$ pairs of parenthesis ( ) by his teacher who gave him a difficult task.The task consists of two steps. First,Shaun should colour all $N$ pairs of parenthesis each with different color but opening and closing bracket of a particular pair should be of same colour. Then,Shaun should report to his teacher the number of ways he can arrange all $2*N$ brackets such that sequence form is valid. Teacher defined valid sequence by these rules:\n- Any left parenthesis '(' must have a corresponding right parenthesis ')'.\n- Any right parenthesis ')' must have a corresponding left parenthesis '('.\n- Left parenthesis '(' must go before the corresponding right parenthesis ')'. \nNote: Shaun could match opening and closing brackets of different colours. \nSince number of ways can be large, Shaun would report the answer as modulo 1000000007 ($10^9 + 7$).\n\n-----Input:-----\n- First line will contain $T$, number of testcases. Then the testcases follow. \n- Each testcase contains of a single line of input, one integer $N$. \n\n-----Output:-----\nFor each testcase, output in a single line answer given by Shaun to his teacher modulo 1000000007.\n\n-----Constraints-----\n- $1 \\leq T \\leq 100000$\n- $1 \\leq N \\leq 100000$\n\n-----Sample Input:-----\n3\n1\n2\n3\n\n-----Sample Output:-----\n1\n6\n90\n\n-----EXPLANATION:-----\nHere numbers from $1$ to $N$ have been used to denote parenthesis.A unique number corresponds to a unique pair of parenthesis.\n-In the first test case , you can use only one color to color the parenthesis you could arrange it only in one way i.e, 1 1\n-In the second test case you can use two colors and the possible ways of arranging it are\n1 1 2 2\n1 2 2 1\n1 2 1 2\n2 2 1 1\n2 1 1 2\n2 1 2 1\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nmod = 1000000007\r\nfac = [1,1]\r\nmaxn = (10**5)+5\r\nfor i in range(2,maxn):\r\n x = (fac[-1]*i)%mod\r\n fac.append(x)\r\n\r\npre = [1]\r\nfor i in range(2,maxn):\r\n x = 2*i-1\r\n x = (pre[-1]*x)%mod\r\n pre.append(x)\r\n\r\nfor _ in range(int(input())):\r\n n = int(input())\r\n x = fac[n]\r\n y = pre[n-1]\r\n print((x*y)%mod)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\n1\\n2\\n3\\n', 'output': '1\\n6\\n90\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/COCA2020/problems/COCA2003'}","problem_id":"vfc_3370","program":"```python\nmod = 1000000007\r\nfac = [1,1]\r\nmaxn = (10**5)+5\r\nfor i in range(2,maxn):\r\n x = (fac[-1]*i)%mod\r\n fac.append(x)\r\n\r\npre = [1]\r\nfor i in range(2,maxn):\r\n x = 2*i-1\r\n x = (pre[-1]*x)%mod\r\n pre.append(x)\r\n\r\nfor _ in range(int(input())):\r\n n = int(input())\r\n x = fac[n]\r\n y = pre[n-1]\r\n print((x*y)%mod)\n```","inputs":"3\n1\n2\n3\n","output":"1\n6\n90\n","actual_output":"1\n6\n90\n","execution_success":true,"sample_index":729},{"source":"apps","task_type":"verifiable_code","in_source_id":"1133","prompt":"Solve the following coding problem using the programming language python:\n\nShivam is working on electric circuits. He requires some connecting wires. He needs to make a total of N connections and he has mentioned his wire length requirements for each connection in an integer sequence A. For buying wires, he need to decide the length of each wire piece, and he\u2019ll get as many wire pieces of the chosen length each at unit cost (cost 1 per piece) but he can't get wires of different lengths. Also, he can't cut wire pieces to make new pieces of different (smaller) length(s).\nBut he can connect any number of wires together to form a new single wire piece whose length is the sum of lengths of the wires connected. So, Shivam needs to choose an integer length for buying wires. Shivam hates to waste anything, and he hates it even more if that thing is money.\nShivam is weak in mathematics and is asking you to help him in this situation. Help him decide the length of wires and total number of wires so as to minimize the total expenditure.\nNote: You cannot make a connection which requires a wire piece of length X with a wire piece of length Y if X\u2260Y.\nInput:\n\u00b7 The first line of the input contains T = Number of Test cases\n\u00b7 The first line of each test case contains an integer N\n\u00b7 The second line contains N space separated integers A1, A2, \u2026., AN.\nOutput:\nFor each test case print a single line containing two space separated integers, length of each wire and the corresponding minimum cost.\nConstraints:\n\u00b7 1 <= T <= 10\n\u00b7 1 <= N <= 10^5\n\u00b7 1 <= Ai <= 10^5, for each valid i\nSample Input:\n1\n3\n2 4 8\nSample Output:\n2 7\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfrom sys import stdin,stdout\nfrom math import gcd\nnmbr=lambda:int(stdin.readline())\nlst=lambda:list(map(int, stdin.readline().split()))\n\nfor _ in range(nmbr()):\n n=nmbr()\n a=lst()\n g=a[0]\n ans=0\n for v in a[1:]:\n g=gcd(v,g)\n for i in a:\n ans+=i//g\n print(g,ans)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n3\\n2 4 8\\n', 'output': '2 7\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/CSTR2020/problems/ELECTRIC'}","problem_id":"vfc_3374","program":"```python\nfrom sys import stdin,stdout\nfrom math import gcd\nnmbr=lambda:int(stdin.readline())\nlst=lambda:list(map(int, stdin.readline().split()))\n\nfor _ in range(nmbr()):\n n=nmbr()\n a=lst()\n g=a[0]\n ans=0\n for v in a[1:]:\n g=gcd(v,g)\n for i in a:\n ans+=i//g\n print(g,ans)\n```","inputs":"1\n3\n2 4 8\n","output":"2 7\n","actual_output":"2 7\n","execution_success":true,"sample_index":730},{"source":"apps","task_type":"verifiable_code","in_source_id":"1134","prompt":"Solve the following coding problem using the programming language python:\n\nDaenerys Targaryen has been suggested by her counselors to leave the Meereen and start conquering other parts of the world. But she knows giving up on the people of Meereen means victory of slavery. Her plan is to start conquering rest of the world while she remains in Meereen. She can only trust her bravest and most beloved Daario Naharis to undertake this risk. She asks him to conquer a few nations and promises him a help from her dragons. She also promises to marry him if he successfully conquers all the nations and not if he is defeated.\nDaario has to conquer 'N' number of nations each nation with army size A[i]. He attacks the nations serially. As promised, he gets help from Daenerys's Dragons. His first 'M' attacks are made with the help of Dragons.\n\nFor first 'M' attacks, he gains A[i] soldiers.\n\nFor the rest, he looses ceiling of A[i]/2 soldiers.\n\nHe is defeated if he is left with no army before he conquers all the 'N' nations. He has no army initially and only has Dragons.\n\n-----Input-----\nFirst line has 'T' which is the number of test cases.\nFor each test cases there are two space separated integers 'N' and 'M' denoting the number of nations and the number of nations he has Dragon's help for respectively.\nFollows N space separated integers denoting the size of army of each nation.\n\n-----Output-----\nPrint 'VICTORY' if Daario conquers all nations and 'DEFEAT' if he doesn't. \n\n-----Constraints-----\n- 1 \u2264 T \u2264 500\n- 1 \u2264 M \u2264N \u2264 100000\n- 1 \u2264 A[i] \u2264 100000\n\n-----Example-----\nInput:\n\n3\n5 3\n1 2 3 4 5\n6 2\n4 4 4 4 4 4\n7 4 \n10 10 10 10 50 60 70\nOutput:\n\nVICTORY\nVICTORY\nDEFEAT \n\n-----Explanation-----\nExample case 1.\n\nFirst 3 attacks add 1,2,3 to his army making it 6. (1+2+3 = 6)\n\nThen he looses 2 and 3 making it 1. (6-2-3 = 1)\n\nHe conquers all so VICTORY.\n\nExample case 2.\n\nFirst 2 attacks add 4,4 to his army making it 8. (4+4 = 8)\n\nThen he looses 2,2,2,2 making it 0. (8-2-2-2-2 = 0)\n\nHe conquers all so VICTORY.\n\nExample case 3.\n\nFirst 4 attacks add 10,10,10,10 to his army making it 40. (10+10+10+10 = 40)\n\nThen he looses 25 and then all 15 out of possible 30 making it 0. (40-25-15 = 0)\n\nHe is defeated on 6th attack so DEFEAT.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nt=int(input())\nfor i in range(t):\n n,m=list(map(int,input().split()))\n a=list(map(int,input().split()))\n army=0\n if n>m:\n \n for i in range(0,m):\n army+=a[i]\n \n \n for j in range(m,n):\n army=army-(a[j]/2)\n if army<0:\n print('DEFEAT')\n break\n else:\n continue\n else:\n print('VICTORY')\n \n if n<=m:\n print('VICTORY')\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\n5 3\\n1 2 3 4 5\\n6 2\\n4 4 4 4 4 4\\n7 4\\n10 10 10 10 50 60 70\\n', 'output': 'VICTORY\\nVICTORY\\nDEFEAT\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/KOKT2015/problems/KOKT03'}","problem_id":"vfc_3378","program":"```python\nt=int(input())\nfor i in range(t):\n n,m=list(map(int,input().split()))\n a=list(map(int,input().split()))\n army=0\n if n>m:\n \n for i in range(0,m):\n army+=a[i]\n \n \n for j in range(m,n):\n army=army-(a[j]/2)\n if army<0:\n print('DEFEAT')\n break\n else:\n continue\n else:\n print('VICTORY')\n \n if n<=m:\n print('VICTORY')\n```","inputs":"3\n5 3\n1 2 3 4 5\n6 2\n4 4 4 4 4 4\n7 4\n10 10 10 10 50 60 70\n","output":"VICTORY\nVICTORY\nDEFEAT\n","actual_output":"VICTORY\nVICTORY\nDEFEAT\n","execution_success":true,"sample_index":731},{"source":"apps","task_type":"verifiable_code","in_source_id":"1136","prompt":"Solve the following coding problem using the programming language python:\n\nChef has N laddus of K sweetness each. Chef wants to eat all laddus, but Chef is restricted with the given condition that he must not eat two adjacent laddus. Chef starts calculating the maximum sweetness that he will get from the laddus. Find the maximum sweetness that chef gets at the end of all calculations. \n\n-----Input:-----\n- First-line will contain $T$, the number of test cases. Then the test cases follow. \n- Each test case contains a single line of input, two integers $N, K$. \n\n-----Output:-----\nFor each test case, output in a single line answer as Maximum sweetness the chef will have.\n\n-----Constraints-----\n- $1 \\leq T \\leq 10^5$\n- $1 \\leq N \\leq 10^5$\n- $1 \\leq K \\leq 10^5$\n\n-----Sample Input:-----\n2\n1 2\n4 3\n\n-----Sample Output:-----\n2\n6\n\n-----EXPLANATION:-----\nFor 1) Chef will get only 1 laddu with sweetness 2.\nFor 2) Chef will have multiple ways as\n[1,3], [2,4], [1,4] with sweetness 6\n[1],[2],[3],[4] with sweetness 3.\nMaximum sweetness will be 6.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n\r\nt = int(input())\r\n\r\nfor _ in range(t):\r\n n,m = map(int,input().split())\r\n\r\n if n==1:\r\n print(m)\r\n else:\r\n \r\n if n%2==0:\r\n print((n//2)*m)\r\n \r\n else:\r\n print(((n//2)+1)*m)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n1 2\\n4 3\\n', 'output': '2\\n6\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/PBK12020/problems/ITGUY17'}","problem_id":"vfc_3386","program":"```python\n\r\nt = int(input())\r\n\r\nfor _ in range(t):\r\n n,m = map(int,input().split())\r\n\r\n if n==1:\r\n print(m)\r\n else:\r\n \r\n if n%2==0:\r\n print((n//2)*m)\r\n \r\n else:\r\n print(((n//2)+1)*m)\n```","inputs":"2\n1 2\n4 3\n","output":"2\n6\n","actual_output":"2\n6\n","execution_success":true,"sample_index":733},{"source":"apps","task_type":"verifiable_code","in_source_id":"1137","prompt":"Solve the following coding problem using the programming language python:\n\nVishal Wants to buy 2 gifts for his best friend whose name is Annabelle(her age is 20), So they both went for shopping in a store. But Annabelle gave, Vishal a condition that she will accept this gifts only when the total price of the gifts is the same as her age times 100.\nThe store contains, a list of items whose prices are also displayed, Now Vishal is asking for your help to buy gifts, as he wants to impress Annabelle this time.\nNote: Vishal cannot buy the same item more than once.\n\n-----Input:-----\n- The first line of the input contains a single integer $T$. $T$ denoting the number of test cases. The description of $T$ test cases is as follows.\n- The next line of the input contains a single integer $N$. $N$ denotes the total number of items in store.\n- The next line of the input contains $N$ space-separated integers $A1, A2, A3...An$ where $ith$ number denotes the price of $ith$ element.\n\n-----Output:-----\n- For each test-case print \"Accepted\"(without quotes) if the gifts are accepted by Annabelle, else print \"Rejected\"(without quotes)\n\n-----Constraints:-----\n- $1 \\leq T \\leq 10^3$\n- $1 \\leq N \\leq 10^5$\n- $1 \\leq A1, A2, A3...An \\leq 10^7$\n\n-----Sample Input:-----\n1\n5\n10 2 1000 50 1000\n\n-----Sample Output:-----\nAccepted\n\n-----Explanation:-----\n- As the given list of items have 2 items whose price sum up to the age times 100 of Annabelle i.e. 1000+1000 = (20 *100)\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\ntest = int(input())\nANS = list()\nfor i in range(test):\n n = int(input())\n items = sorted(list(map(int, input().split())))\n c = 1\n for j in range(len(items)):\n if items[j] < 2000:\n t = 2000 - items[j]\n if t in items[j+1:]:\n ANS.append(\"Accepted\")\n c = 2\n break\n else:\n pass\n else:\n break\n if c==1:\n ANS.append(\"Rejected\")\nfor ans in ANS:\n print(ans)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n5\\n10 2 1000 50 1000\\n', 'output': 'Accepted\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/ARYS2020/problems/BDYGFT'}","problem_id":"vfc_3390","program":"```python\ntest = int(input())\nANS = list()\nfor i in range(test):\n n = int(input())\n items = sorted(list(map(int, input().split())))\n c = 1\n for j in range(len(items)):\n if items[j] < 2000:\n t = 2000 - items[j]\n if t in items[j+1:]:\n ANS.append(\"Accepted\")\n c = 2\n break\n else:\n pass\n else:\n break\n if c==1:\n ANS.append(\"Rejected\")\nfor ans in ANS:\n print(ans)\n```","inputs":"1\n5\n10 2 1000 50 1000\n","output":"Accepted\n","actual_output":"Accepted\n","execution_success":true,"sample_index":734},{"source":"apps","task_type":"verifiable_code","in_source_id":"1138","prompt":"Solve the following coding problem using the programming language python:\n\nSereja is hosting his birthday dinner. He invited his N close friends. Let us number the people from 1 to N according to the order in which they arrive at the event. The dinner is being held in long straight corridor in which people sit in a way such that they won't leave any empty space in between two consecutive persons at any given time. \n\nWhen a person number i arrives at the corridor, he must go and stand to the immediate right of the person numbered A[i] (if A[i] = 0, then this person just stands at the leftmost end of the line). \n\nBut there is a problem, as there is no space between two consecutive persons at any given time, so for this person to sit, space must be created by moving either all the persons to left of the place to the left one step each, or all the persons to right of the place to the right one step each. \n\nNow, Sereja is wondering about what could be the minimum number of steps people will take so as to sit in the dinner party. Please find it fast, so that Sereja can peacefully entertain his guests.\n\n-----Input-----\nFirst line of input contain an integer T \u2014 the number of test cases. T tests follow.\nFirst line of each test case contain the integer N, and the next line contains N integers \u2014 A[1], A[2], ... , A[N].\n\n-----Output-----\nFor each test case, output a single line with the answer \u2014 the minimal number of steps required.\n\n-----Constraints-----\n- 1 \u2264 T \u2264 100\n- 1 \u2264 N \u2264 100\n- 0 \u2264 A[i] < i\n\n-----Example-----\nInput:\n3\n1\n0\n3\n0 0 0\n5\n0 1 2 1 4\n\nOutput:\n0\n0\n3\n\n-----Explanation-----\nExample case 3.\n- First three persons don't need any steps to sit. The line after the arrangement of these persons will look like [1, 2, 3]. \n\n- When person #4 comes in, he wants to sit to the right of person 1, so we need to either move the first person to the left, or the second and third persons to the right. The first case is clearly better. Now the line will look like [1, 4, 2, 3]. \n\n- When person #5 arrives, he will need to move 2 persons in either case. The final arrangement will be [1, 4, 5, 2, 3]. \n\nSo total number of steps people moved during the entire process is 1 + 2 = 3. So the answer is 3.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\na=eval(input())\nwhile(a):\n\n x=eval(input())\n b=list(map(int,input().split()))\n z=[0]*100\n k=1\n j=0\n c=0\n for i in b:\n \n if i==0:\n \n z.insert(i,k)\n \n else:\n \n if z[z.index(i)+1]==0:\n \n z.insert(j,k)\n else:\n m=z.index(i)\n n=m+1\n p=(len(z)-z.count(0))-n\n c=c+min(n,p)\n \n z.insert(m+1,k)\n \n \n k+=1\n j+=1\n m=0\n n=0\n p=0\n \n print(c)\n \n \n \n \n \n \n \n \n \n \n\n\n a-=1\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\n1\\n0\\n3\\n0 0 0\\n5\\n0 1 2 1 4\\n', 'output': '0\\n0\\n3\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/COOK64/problems/SEALINE'}","problem_id":"vfc_3394","program":"```python\na=eval(input())\nwhile(a):\n\n x=eval(input())\n b=list(map(int,input().split()))\n z=[0]*100\n k=1\n j=0\n c=0\n for i in b:\n \n if i==0:\n \n z.insert(i,k)\n \n else:\n \n if z[z.index(i)+1]==0:\n \n z.insert(j,k)\n else:\n m=z.index(i)\n n=m+1\n p=(len(z)-z.count(0))-n\n c=c+min(n,p)\n \n z.insert(m+1,k)\n \n \n k+=1\n j+=1\n m=0\n n=0\n p=0\n \n print(c)\n \n \n \n \n \n \n \n \n \n \n\n\n a-=1\n\n```","inputs":"3\n1\n0\n3\n0 0 0\n5\n0 1 2 1 4\n","output":"0\n0\n3\n","actual_output":"0\n0\n3\n","execution_success":true,"sample_index":735},{"source":"apps","task_type":"verifiable_code","in_source_id":"1139","prompt":"Solve the following coding problem using the programming language python:\n\nThe chef is very expert in coding, so to keep his password safe from the hackers. He always enters a decoded code of his password. You are a hacker and your work is to find the maximum number of possible ways to unlock his password in encoded form.\n\nThe encoded message containing only letters from A-Z is being encoded with numbers using the following mapping: \n\n'A' -> 1 \n\n'B' -> 2 ... \n\n'Z' -> 26\n\nYou have given a non-empty string containing only digits, determine the total number of ways to encode it. \n\nIf the total number of ways are even then you are able to unlock the password. \n\nInput: \nThe first line has a single integer T, denoting the number of test cases. The first line of each test case contains string \u201cS\u201d decoded number.\n\nOutput:\nFor each test case, in a new line, print 'YES' if number of maximum ways are even, otherwise\n'NO'. (without quotes)\n\nConstraints:\n1 \u2264 T \u2264 50\n\n1 \u2264 S \u2264 30\n\nSample Input:\n2\n\n12\n\n223\n\nSample Output:\nYES\n\nNO\n\nExplanation:\nFor first test case, It could be encoded as \"AB\" (1 2) or \"L\" (12), hence the number of\nmaximum possible ways are 2 so output is \u201cYES\u201d.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nt = int(input())\nwhile t>0:\n s = input().strip()\n if not s:\n print('NO')\n\n dp = [0 for x in range(len(s) + 1)]\n dp[0] = 1\n dp[1] = 1 if 0 < int(s[0]) <= 9 else 0\n\n for i in range(2, len(s) + 1):\n if 0 < int(s[i-1:i]) <= 9:\n dp[i] += dp[i - 1]\n if s[i-2:i][0] != '0' and int(s[i-2:i]) <= 26:\n dp[i] += dp[i - 2]\n \n if dp[len(s)]%2 == 0:\n print('YES')\n else:\n print('NO')\n t -= 1\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n12\\n223\\n', 'output': 'YES\\nNO\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/CY302020/problems/CODEY302'}","problem_id":"vfc_3398","program":"```python\nt = int(input())\nwhile t>0:\n s = input().strip()\n if not s:\n print('NO')\n\n dp = [0 for x in range(len(s) + 1)]\n dp[0] = 1\n dp[1] = 1 if 0 < int(s[0]) <= 9 else 0\n\n for i in range(2, len(s) + 1):\n if 0 < int(s[i-1:i]) <= 9:\n dp[i] += dp[i - 1]\n if s[i-2:i][0] != '0' and int(s[i-2:i]) <= 26:\n dp[i] += dp[i - 2]\n \n if dp[len(s)]%2 == 0:\n print('YES')\n else:\n print('NO')\n t -= 1\n```","inputs":"2\n12\n223\n","output":"YES\nNO\n","actual_output":"YES\nNO\n","execution_success":true,"sample_index":736},{"source":"apps","task_type":"verifiable_code","in_source_id":"1140","prompt":"Solve the following coding problem using the programming language python:\n\nConsider the following algorithm\norder(arr, i) {\nif length(arr) <= 1 {\nreturn arr\n}\nl = [] \nr = []\nn = length(arr) - 1\nfor j in 0, 1, ..., n {\nif ( (arr[j] modulo power(2,i+1)) < power(2,i) ) {\nappend arr[j] to l\n}else{\nappend arr[j] to r\n}\n}\nl = order(l, i + 1)\nr = order(r, i + 1)\nc = concatenate(l, r)\nreturn c\n}\n\nNote that $concatenate(l, r)$ returns an array which is the array $l$, followed by the array $r$. Similarly $power(x,y)$ returns $x^y$.\nLet $a$ be the array $a_0,a_1,a_2,a_3, \\ldots,a_n$ where $a_j = j$ for each index $j$ and the last index $n = (2^p-1)$ for a fixed integer parameter $p$. Given an integer $p$ and an index $idx$, your task is calculate the element at index $idx$ in the array returned by executing $order(a, 0)$.\nFor example, suppose $ p = 3$ and $idx = 3$.\n- The initial array is $a = [0, 1, 2, 3, 4, 5, 6, 7]$.\n- Executing $order(a, 0)$ first creates two new arrays $l == [0, 2, 4, 6]$ and $r == [1, 3, 5, 7]$.\n- Next, $order(l, 1)$ and $order(r, 1)$ are executed.\n- $order(l, 1)$, in turn, executes $order([0, 4], 2)$ and $order([2, 6], 2)$ which return $[0, 4]$ and $[2, 6]$, respectively. These are then concatenated, so $order(l, 1)$ returns $[0, 4, 2, 6]$.\n- Similarly, $order(r, 1)$ returns $[1, 5, 3, 7]$.\n- These two are concatenated as the final result, so the array returned by $order(a, 0)$ is $[0, 4, 2, 6, 1, 5, 3, 7]$.\nSo, if the input is $p = 3$, and $idx = 3$, the answer is $6$. If $p = 3$ and $idx = 7$, the answer should be $7$.\n\n-----Input Format:-----\n- The first line contains a single integer, $T$, which is the number of testcases. The description of each testcase follows.\n- Each testcase is described by a single line with two integers: $p$ and $idx$, where $p$ is the parameter that determines the length of the array $a$ and $idx$ is the index at which you have to report the value in the output of $order(a, 0)$.\n\n-----Output Format:-----\n- You should print the answer in a new line for each testcase, which should be a single integer, the element at index $idx$ after executing $order(a, 0)$ for the array $a$ defined by the parameter $p$.\n\n-----Constraints:-----\n- $1 \\leq T \\leq 10$ \n- $1 \\leq p \\leq 50$\n- $0 \\leq idx \\leq 2^p-1$\n\n-----SUBTASKS:-----\n- Subtask 1: 20% points : $1 \\leq p \\leq 20$\n- Subtask 2: 80% points: Original constraints\n\n-----Sample Input:-----\n2\n3 3\n3 7\n\n-----Sample Output:-----\n6\n7\n\n-----Explanation:-----\nBoth the testcases have been explained in the problem statement.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfor _ in range(int(input())):\n p, idx = map(int, input().split())\n b = bin(idx)[2:]\n b = ('0' * (p - len(b)) + b)[::-1]\n print(int(b, 2))\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n3 3\\n3 7\\n', 'output': '6\\n7\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/ZCOPRAC/problems/ZCO20001'}","problem_id":"vfc_3402","program":"```python\nfor _ in range(int(input())):\n p, idx = map(int, input().split())\n b = bin(idx)[2:]\n b = ('0' * (p - len(b)) + b)[::-1]\n print(int(b, 2))\n```","inputs":"2\n3 3\n3 7\n","output":"6\n7\n","actual_output":"6\n7\n","execution_success":true,"sample_index":737},{"source":"apps","task_type":"verifiable_code","in_source_id":"1141","prompt":"Solve the following coding problem using the programming language python:\n\nA tourist is visiting Byteland. The tourist knows English very well. The language of Byteland is rather different from English. To be exact it differs in following points:\n\n- Bytelandian alphabet has the same letters as English one, but possibly different in meaning. Like 'A' in Bytelandian may be 'M' in English. However this does not mean that 'M' in Bytelandian must be 'A' in English. More formally, Bytelindian alphabet is a permutation of English alphabet. It will be given to you and could be any possible permutation. Don't assume any other condition.\n- People of Byteland don't like to use invisible character for separating words. Hence instead of space (' ') they use underscore ('_'). Other punctuation symbols, like '?', '!' remain the same as in English.\n\nThe tourist is carrying \"The dummies guide to Bytelandian\", for translation. The book is serving his purpose nicely. But he is addicted to sharing on BaceFook, and shares his numerous conversations in Byteland on it. The conversations are rather long, and it is quite tedious to translate for his English friends, so he asks you to help him by writing a program to do the same.\n\n-----Input-----\nThe first line of the input contains an integer T, denoting the length of the conversation, and the string M, denoting the English translation of Bytelandian string \"abcdefghijklmnopqrstuvwxyz\". T and M are separated by exactly one space. Then T lines follow, each containing a Bytelandian sentence S which you should translate into English. See constraints for details.\n\n-----Output-----\nFor each of the sentence in the input, output its English translation on a separate line. Replace each underscores ('_') with a space (' ') in the output. Each punctuation symbol (see below) should remain the same. Note that the uppercase letters in Bytelandian remain uppercase in English, and lowercase letters remain lowercase. See the example and its explanation for clarity.\n\n-----Constraints-----\n\n- 1 \u2264 T \u2264 100\n- M is a permutation of \"abcdefghijklmnopqrstuvwxyz\"\n- Each sentence is non-empty and contains at most 100 characters\n- Each sentence may contain only lowercase letters ('a'-'z'), uppercase letters ('A'-'Z'), underscores ('_') and punctuation symbols: dot ('.'), comma (','), exclamation ('!'), question-mark('?')\n\n-----Example-----\nInput:\n5 qwertyuiopasdfghjklzxcvbnm\nPh\nPcssi\nBpke_kdc_epclc_jcijsc_mihyo?\nEpcf_kdc_liswhyo_EIED_hy_Vimcvpcn_Zkdvp_siyo_viyecle.\nIpp!\n\nOutput:\nHi\nHello\nWhat are these people doing?\nThey are solving TOTR in Codechef March long contest.\nOhh!\n\n-----Explanation-----\nThe string \"qwertyuiopasdfghjklzxcvbnm\" means that 'a' in Bytelandian is 'q' in English, 'b' in Bytelandian is 'w' in English, 'c' in Bytelandian is 'e' in English and so on.\nThus to translate \"Ph\" (first sentence in example) to English:\n1) We find that 'p' in Bytelandian means 'h' in English. So we replace 'P' with 'H'.\n2) Then we see that 'h' in Bytelandian means 'i' in English. So we replace 'h' with 'i'.\n3) Therefore, the translation is \"Hi\".\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\ntry:\n t,m=input().split()\n t=int(t)\n m=list(m)\n letters=list(\"abcdefghijklmnopqrstuvwxyz\")\n trans={}\n for i in range(len(letters)):\n trans[letters[i]]=m[i]\n for i in range(t):\n x=list(input())\n y=\"\"\n for j in x:\n if(j.isalpha()==True):\n if(j.isupper()==True):\n y+=trans[j.lower()].upper()\n else:\n y+=trans[j]\n else:\n if(j=='_'):\n y+=\" \"\n else:\n y+=j\n print(y)\n \nexcept:pass\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': 'and its\\n', 'output': ''}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/TOTR'}","problem_id":"vfc_3406","program":"```python\ntry:\n t,m=input().split()\n t=int(t)\n m=list(m)\n letters=list(\"abcdefghijklmnopqrstuvwxyz\")\n trans={}\n for i in range(len(letters)):\n trans[letters[i]]=m[i]\n for i in range(t):\n x=list(input())\n y=\"\"\n for j in x:\n if(j.isalpha()==True):\n if(j.isupper()==True):\n y+=trans[j.lower()].upper()\n else:\n y+=trans[j]\n else:\n if(j=='_'):\n y+=\" \"\n else:\n y+=j\n print(y)\n \nexcept:pass\n```","inputs":"and its\n","output":"","actual_output":"","execution_success":true,"sample_index":738},{"source":"apps","task_type":"verifiable_code","in_source_id":"1142","prompt":"Solve the following coding problem using the programming language python:\n\nThis is one more story about our old friend, the Despotic King. Once every year, it was customary for the king to give audience to the rich merchants of his country in a large hall. On that day, the merchants were ushered in to meet the king one by one and after paying their respects to the king they were seated in the auditorium.\nIt was the job of the minister to introduce each merchant, as he arrived, to the others in the hall. He would announce his name and his wealth. However, our quirky king demanded that in addition, he should also announce the rank of the merchant among all those in the hall (at the time of his arrival) in terms of his wealth.\nFor example, let us suppose that the wealth of the 6 merchants who met the king (in the order in which they arrived) is given by the sequence\n78246840398978246840398978 \\quad 24 \\quad 68 \\quad 40 \\quad 39 \\quad 89\nThen, clearly the first merchant is the richest in the hall when he enters it (since there are no others in the hall) and so his rank is $1$. Since $24 < 78$ the rank of the second merchant when he enters the hall is $2$. The rank of the third merchant is also $2$ since $24 < 68 < 78$. The rank of the fourth merchant is $3$ since $24 < 40 < 68 < 78$, the rank of the fifth merchant is $4$ since $24 < 39 < 40 < 68 < 78$ and finally the rank of the sixth merchant is $1$ since $24 < 39 < 40 < 68 < 78 < 89$. The sequence of ranks announced by the minister would thus be:\n1223411223411 \\quad 2 \\quad 2 \\quad 3 \\quad 4 \\quad 1\nYour task is to write a program that takes as input a sequence of distinct positive integers indicating the wealth of the merchants in the order in which they visit the king and outputs the sequence of ranks announced by the minister.\n\n-----Input:-----\nThe first line contains a single integer $N$ indicating the number of merchants. The next $N$ lines (line $2,...,N+1$) describe the wealth of these $N$ merchants. Line $i+1$ contains a single positive integer indicating the wealth of the $i^{th}$ merchant to enter the hall.\n\n-----Output:-----\nYour output should consist of $N$ lines. Line $i$ should be the rank announced when the $i^{th}$ minister enters the hall.\n\n-----Constraints:-----\n- $1 \\leq N \\leq 45000$.\n- No two merchants have the same wealth.\n- You may also assume that in $30 \\%$ of of the inputs $1 \\leq N \\leq 8000$.\n\n-----Sample Input-----\n6\n78\n24\n68\n40\n39\n89\n\n-----Sample Output-----\n1\n2\n2\n3\n4\n1\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\narr=[]\nn=int(input())\nfor i in range(n):\n a=int(input())\n arr.append(a)\n arr.sort()\n p=arr.index(a)\n print((i-p)+1)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '6\\n78\\n24\\n68\\n40\\n39\\n89\\n', 'output': '1\\n2\\n2\\n3\\n4\\n1\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/IARCSJUD/problems/IARANK'}","problem_id":"vfc_3410","program":"```python\narr=[]\nn=int(input())\nfor i in range(n):\n a=int(input())\n arr.append(a)\n arr.sort()\n p=arr.index(a)\n print((i-p)+1)\n```","inputs":"6\n78\n24\n68\n40\n39\n89\n","output":"1\n2\n2\n3\n4\n1\n","actual_output":"1\n2\n2\n3\n4\n1\n","execution_success":true,"sample_index":739},{"source":"apps","task_type":"verifiable_code","in_source_id":"1143","prompt":"Solve the following coding problem using the programming language python:\n\nYash likes playing with numbers. He has a challenge for you. Yash gives\nyou a number that he made by multiplying two numbers. He claims that the\npossible sum of the two numbers he multiplied is as minimum as possible. He\nchallenges you to find that minimum sum.\n\nFormally, for a given value of N, you are required to find the minimum sum of two distinct numbers x and y such that x, y > 0 and xy = N. \n\n-----Input:-----\nThe first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows.\n\nEach testcase contains single integer N.\n\n-----Output:-----\nFor each testcase, output minimum x + y such that x*y = N and x,y >0.\n\n-----Constraints :-----\n$1 \\leq T \\leq 100$\n$1 < N \\leq 10^{12}$\n\n-----Sample Input:-----\n1\n\n852140\n\n-----Sample Output:-----\n1929\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\ndef isPrime(n) : \n \n # Corner cases \n if (n <= 1) : \n return False\n if (n <= 3) : \n return True\n \n # This is checked so that we can skip \n # middle five numbers in below loop \n if (n % 2 == 0 or n % 3 == 0) : \n return False\n \n i = 5\n while(i * i <= n) : \n if (n % i == 0 or n % (i + 2) == 0) : \n return False\n i = i + 6\n \n return True\nt=int(input())\nfor i in range(0,t):\n n=int(input())\n if n==1:\n print(\"2\")\n continue\n if isPrime(n):\n print(n+1)\n continue\n if n%2==0:\n k=n//2\n min=2+k\n else:\n min=n+1\n for j in range(2,(n//2)+1):\n if n%j==0:\n k=n//j\n if k!=j:\n l=j+k\n if l k:\n if(j+1 k:\n if(j+1=y[0] and x[1]>=y[1] and x[2]>=y[2]\n e= x[0]>y[0] or x[1]>y[1] or x[2]>y[2]\n return d and e\nt=int(input())\nfor _ in range(t):\n a=list(map(int,input().split()))\n b=list(map(int,input().split()))\n c=list(map(int,input().split()))\n\n if g(a,b) and g(b,c):\n print('yes')\n elif g(a,c) and g(c,b):\n print('yes')\n elif g(b,a) and g(a,c):\n print('yes')\n elif g(b,c) and g(c,a):\n print('yes')\n elif g(c,a) and g(a,b):\n print('yes')\n elif g(c,b) and g(b,a):\n print('yes')\n else:\n print('no')\n \n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\n1 2 3\\n2 3 4\\n2 3 5\\n1 2 3\\n2 3 4\\n2 3 4\\n5 6 5\\n1 2 3\\n2 3 4\\n', 'output': 'yes\\nno\\nyes\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/ORDTEAMS'}","problem_id":"vfc_3434","program":"```python\ndef g(x,y):\n d = x[0]>=y[0] and x[1]>=y[1] and x[2]>=y[2]\n e= x[0]>y[0] or x[1]>y[1] or x[2]>y[2]\n return d and e\nt=int(input())\nfor _ in range(t):\n a=list(map(int,input().split()))\n b=list(map(int,input().split()))\n c=list(map(int,input().split()))\n\n if g(a,b) and g(b,c):\n print('yes')\n elif g(a,c) and g(c,b):\n print('yes')\n elif g(b,a) and g(a,c):\n print('yes')\n elif g(b,c) and g(c,a):\n print('yes')\n elif g(c,a) and g(a,b):\n print('yes')\n elif g(c,b) and g(b,a):\n print('yes')\n else:\n print('no')\n \n\n```","inputs":"3\n1 2 3\n2 3 4\n2 3 5\n1 2 3\n2 3 4\n2 3 4\n5 6 5\n1 2 3\n2 3 4\n","output":"yes\nno\nyes\n","actual_output":"yes\nno\nyes\n","execution_success":true,"sample_index":745},{"source":"apps","task_type":"verifiable_code","in_source_id":"1150","prompt":"Solve the following coding problem using the programming language python:\n\nIn the 2-D world of Flatland, the Circles were having their sports day and wanted to end it with a nice formation. So, they called upon Mr. Sphere from Spaceland for help. Mr Sphere decides to arrange the Circles in square formations. He starts with $N$ Circles and forms the largest possible square using these Circles. He then takes the remaining Circles and repeats the procedure. A square of side $S$ requires $S^2$ Circles to create.\nFind the number of squares he will be able to form at the end of the process.\n\n-----Input:-----\n- First line will contain $T$, number of testcases. Then the testcases follow.\n- Each testcase contains of a single integer $N$.\n\n-----Output:-----\nFor each testcase, output a single integer denoting the number of squares.\n\n-----Constraints-----\n- $1 \\leq T \\leq 1000$\n- $1 \\leq N \\leq 1000$\n\n-----Sample Input:-----\n2\n\n85\n\n114 \n\n-----Sample Output:-----\n2\n\n4\n\n-----EXPLANATION:-----\nTest case 1 : Mr Sphere forms a square of side 9 using 81 Circles and then forms a square of side 2 using the remaining 4.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\nimport math\nfor _ in range(int(input())):\n n=int(input())\n c=0\n while(n>0):\n i=int(math.sqrt(n))\n c+=1\n n=n-i**2\n print(c)\n \n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n85\\n114\\n', 'output': '2\\n4\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/ICL1902'}","problem_id":"vfc_3442","program":"```python\n# cook your dish here\nimport math\nfor _ in range(int(input())):\n n=int(input())\n c=0\n while(n>0):\n i=int(math.sqrt(n))\n c+=1\n n=n-i**2\n print(c)\n \n\n```","inputs":"2\n85\n114\n","output":"2\n4\n","actual_output":"2\n4\n","execution_success":true,"sample_index":747},{"source":"apps","task_type":"verifiable_code","in_source_id":"1151","prompt":"Solve the following coding problem using the programming language python:\n\nThere is a city with $N$ numbered $0 - N-1$ shops. A market is a place where we can reach from one shop to another using some road. There are $M$ roads in this city connecting each connecting any two shops. \nFind the number of markets in the city.\nNOTE: A market having only one shop is also a valid market.\n\n-----Input:-----\n- First line will contain $T$, number of testcases. Then the testcases follow. \n- First line of Each Test Case is $N, M$, denoting the number of shops and the number of roads respectively.\n- Next M lines consist of two integers $A$ and $B$ denoting that there exists a road between Shop A and Shop B\n\n-----Output:-----\nFor each testcase, output the number of markets.\n\n-----Constraints-----\n- $1 \\leq T \\leq 100$\n- $1 \\leq N,M \\leq 10^3$\n- $0 \\leq A,B < N$\n\n-----Sample Input:-----\n1\n5 3\n0 1\n2 3\n3 4\n\n-----Sample Output:-----\n2\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfrom sys import stdin\r\nfrom math import ceil, gcd\r\n\r\n# Input data\r\n#stdin = open(\"input\", \"r\")\r\n\r\n\r\ndef dfs(src, visit):\r\n visit[src] = 1\r\n for nbr in d[src]:\r\n if visit[nbr] == 0:\r\n dfs(nbr, visit)\r\n\r\nfor _ in range(int(stdin.readline())):\r\n n, m = list(map(int, stdin.readline().split()))\r\n d = {}\r\n for i in range(m):\r\n u, v = list(map(int, stdin.readline().split()))\r\n if u in d:\r\n d[u].append(v)\r\n else:\r\n d[u] = [v]\r\n if v in d:\r\n d[v].append(u)\r\n else:\r\n d[v] = [u]\r\n visited = {}\r\n for i in range(n):\r\n visited[i] = 0\r\n ans = 0\r\n for i in range(n):\r\n if visited[i] == 0:\r\n ans += 1\r\n if i in d:\r\n dfs(i, visited)\r\n print(ans)\r\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n5 3\\n0 1\\n2 3\\n3 4\\n', 'output': '2\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/ENAU2020/problems/ECAUG206'}","problem_id":"vfc_3446","program":"```python\nfrom sys import stdin\r\nfrom math import ceil, gcd\r\n\r\n# Input data\r\n#stdin = open(\"input\", \"r\")\r\n\r\n\r\ndef dfs(src, visit):\r\n visit[src] = 1\r\n for nbr in d[src]:\r\n if visit[nbr] == 0:\r\n dfs(nbr, visit)\r\n\r\nfor _ in range(int(stdin.readline())):\r\n n, m = list(map(int, stdin.readline().split()))\r\n d = {}\r\n for i in range(m):\r\n u, v = list(map(int, stdin.readline().split()))\r\n if u in d:\r\n d[u].append(v)\r\n else:\r\n d[u] = [v]\r\n if v in d:\r\n d[v].append(u)\r\n else:\r\n d[v] = [u]\r\n visited = {}\r\n for i in range(n):\r\n visited[i] = 0\r\n ans = 0\r\n for i in range(n):\r\n if visited[i] == 0:\r\n ans += 1\r\n if i in d:\r\n dfs(i, visited)\r\n print(ans)\r\n\n```","inputs":"1\n5 3\n0 1\n2 3\n3 4\n","output":"2\n","actual_output":"2\n","execution_success":true,"sample_index":748},{"source":"apps","task_type":"verifiable_code","in_source_id":"1152","prompt":"Solve the following coding problem using the programming language python:\n\nChef Jessie has a lot of recipes with her (N). She often remembered the starting few characters of the recipe and forgot the rest. As all the great chefs do, Jessie also numbered the recipes depending on the priority. So, given the list of recipes along with their priorities answer Jessie\u2019s queries.\nJessie\u2019s queries are as follows:\n\nShe gives you the first few characters of a recipe; you have to print the complete recipe with the highest priority.\nNote:\n\nEvery recipe has a unique priority\n\n-----Input-----\n\nFirst line contains an integer N - the number of recipes.\n\nFollowed by N strings Si along with an integer each Vi.\nSi stands for the recipe and Vi for the priority.\n\nIt is followed by an integer Q - the number of queries.\n\nFollowed by Q strings Qi.\n\nEach string Si, Qi contain only lowercase Latin alphabets ('a' - 'z') and '-'.\n\n-----Output-----\nQ \u2013 lines, each contain the answer for each of the query.\n\nIf for a query no recipe matches print \"NO\". (Without quotes)\nConstraints:\n0 <= N <= 1000\n\n0 <= Q <= 1000\n\n-10^9 <= Vi <= 10^9\n\n1 <= |Si| <= 1000 (length of Si)\n\n1 <= |Qi| <= 1000 (length of Qi)\n\n-----Example-----\nInput:\n4\nflour-with-eggs 100\nchicken-ham -10\nflour-without-eggs 200\nfish-with-pepper 1100\n6\nf\nflour-with\nflour-with-\nc\nfl\nchik\n\nOutput:\nfish-with-pepper\nflour-without-eggs\nflour-with-eggs\nchicken-ham\nflour-without-eggs\nNO\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nnr=int(input())\nd={}\nfor r in range(nr):\n s,v=list(map(str,input().split()))\n d[int(v)]=s\nq=int(input())\nlis=[]\nfor i in range(q):\n lis.append(input())\nl=list(d.keys())\nl.sort(reverse=True)\nans='NO'\n\n\nfor j in lis:\n ans='NO'\n for k in l:\n if len(j)<=len(d[k]):\n a=d[k]\n if j==a[0:len(j)]:\n ans=a\n break\n print(ans) \n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '4\\nflour-with-eggs 100\\nchicken-ham -10\\nflour-without-eggs 200\\nfish-with-pepper 1100\\n6\\nf\\nflour-with\\nflour-with-\\nc\\nfl\\nchik\\n', 'output': 'fish-with-pepper\\nflour-without-eggs\\nflour-with-eggs\\nchicken-ham\\nflour-without-eggs\\nNO\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/TWSTR'}","problem_id":"vfc_3450","program":"```python\nnr=int(input())\nd={}\nfor r in range(nr):\n s,v=list(map(str,input().split()))\n d[int(v)]=s\nq=int(input())\nlis=[]\nfor i in range(q):\n lis.append(input())\nl=list(d.keys())\nl.sort(reverse=True)\nans='NO'\n\n\nfor j in lis:\n ans='NO'\n for k in l:\n if len(j)<=len(d[k]):\n a=d[k]\n if j==a[0:len(j)]:\n ans=a\n break\n print(ans) \n\n```","inputs":"4\nflour-with-eggs 100\nchicken-ham -10\nflour-without-eggs 200\nfish-with-pepper 1100\n6\nf\nflour-with\nflour-with-\nc\nfl\nchik\n","output":"fish-with-pepper\nflour-without-eggs\nflour-with-eggs\nchicken-ham\nflour-without-eggs\nNO\n","actual_output":"fish-with-pepper\nflour-without-eggs\nflour-with-eggs\nchicken-ham\nflour-without-eggs\nNO\n","execution_success":true,"sample_index":749},{"source":"apps","task_type":"verifiable_code","in_source_id":"1153","prompt":"Solve the following coding problem using the programming language python:\n\n-----Problem Statement-----\nSereja has a sequence of n integers a[1], a[2], ..., a[n]. Sereja can do following transformation of the array:\n\n- create a new sequence of n integers b[1], b[2], ..., b[n]in this way: (1\u2009\u2264\u2009i\u2009\u2264\u2009n)\n\n- Replace the sequence a by b, i.e., a[i] = b[i] for all i in [1, n] \n\nSereja decided to use his transformation k times. Then he computed the value of , where r \u2014 the sequence obtained after k transformations of sequence a, as described above.\n\nSereja lost sequence a, but he was left with the numbers q(r) and k. Now Sereja is interested in the question : what is the number of the sequences of the integers \u0441[1], \u0441[2], ..., \u0441[n], such that 1\u2009\u2264\u2009c[i]\u2009\u2264\u2009m and q(d)\u2009=\u2009q(r), where d \u2014 the sequence obtained after k transformations of sequence c, as described above.\n\n-----Input-----\nThe first lines contains a single integer T, denoting the number of test cases. Each test case consist of four integers : n, m, q(r), k.\n\n-----Output-----\nIn a single line print the remainder of division the answer of the problem on number 10^9\u2009+\u20097.\n\n-----Constraints-----\n\n- 1 \u2264 T \u2264 10000\n- 1 \u2264 n,\u2009m,\u2009q(r), k \u2264 10^9\n\n-----Example-----\nInput:\n3\n1 1 1 1\n2 2 1 1\n2 3 1 1\n\nOutput:\n0\n2\n4\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\ndef mod(a,b,c):\n x = 1\n y = a\n while(b>0):\n if(b%2==1):\n x = (x*y)%c\n y = (y*y)%c\n b /=2\n return x%c\nt = int(input())\nnum = 10**9+7\nfor i in range(t):\n n,m,q,k = list(map(int,input().split()))\n if m<=q:\n print(0)\n else:\n a1 = m-q\n a2 = mod(q+1,n,num)\n a3 = mod(q-1,n,num)\n a4 = mod(q,n,num)\n a5 = a2-2*a4+a3\n ans = a1*a5\n print(ans%num)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\n1 1 1 1\\n2 2 1 1\\n2 3 1 1\\n', 'output': '0\\n2\\n4\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/SEATRSF'}","problem_id":"vfc_3454","program":"```python\ndef mod(a,b,c):\n x = 1\n y = a\n while(b>0):\n if(b%2==1):\n x = (x*y)%c\n y = (y*y)%c\n b /=2\n return x%c\nt = int(input())\nnum = 10**9+7\nfor i in range(t):\n n,m,q,k = list(map(int,input().split()))\n if m<=q:\n print(0)\n else:\n a1 = m-q\n a2 = mod(q+1,n,num)\n a3 = mod(q-1,n,num)\n a4 = mod(q,n,num)\n a5 = a2-2*a4+a3\n ans = a1*a5\n print(ans%num)\n```","inputs":"3\n1 1 1 1\n2 2 1 1\n2 3 1 1\n","output":"0\n2\n4\n","actual_output":"0\n2\n4\n","execution_success":true,"sample_index":750},{"source":"apps","task_type":"verifiable_code","in_source_id":"1154","prompt":"Solve the following coding problem using the programming language python:\n\nChef and his friends are playing the game AMONG US. They all have chosen their names as numbers. There are N people in Chef\u2019s group including him, and each swears that he is not the imposter. However, it turns out there were N+1 people in the game. Now all that Chef needs to know is the name of the imposter, which is a number. Also remember that numbers can be duplicate. Can you help out Chef in finding the imposter?\nInput : \nFirst line contains the value of N. Second line contains the N numbers that Chef\u2019s friends used as their names. Third line contains the N+1 numbers that people in the game have used as their names.\nOutput : \nPrint the extra number in new line.\nConstraints : \n1 \u2264 Numbers used as names \u2264 1,000\n1 \u2264 N \u2264 1,000,000\nSample Input : \n3\n4 2 5\n4 2 3 5\nSample Output : \n3\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\ntry:\n\tn=int(input())\n\tx=[*list(map(int, input().split()))]\n\ty=[*list(map(int, input().split()))]\n\tfor i in y:\n\t\td=x.count(i)-y.count(i)\n\t\tif d!=0:\n\t\t\tprint(i)\n\t\t\tbreak\nexcept: pass\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\n4 2 5\\n4 2 3 5\\n', 'output': '3\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/CSTR2020/problems/AMONGUS'}","problem_id":"vfc_3458","program":"```python\ntry:\n\tn=int(input())\n\tx=[*list(map(int, input().split()))]\n\ty=[*list(map(int, input().split()))]\n\tfor i in y:\n\t\td=x.count(i)-y.count(i)\n\t\tif d!=0:\n\t\t\tprint(i)\n\t\t\tbreak\nexcept: pass\n\n```","inputs":"3\n4 2 5\n4 2 3 5\n","output":"3\n","actual_output":"3\n","execution_success":true,"sample_index":751},{"source":"apps","task_type":"verifiable_code","in_source_id":"1156","prompt":"Solve the following coding problem using the programming language python:\n\nWrite a program, which takes an integer N and if the number is less than 10 then display \"Thanks for helping Chef!\" otherwise print \"-1\".\n\n-----Input-----\n\nThe first line contains an integer T, total number of testcases. Then follow T lines, each line contains an integer N. \n\n-----Output-----\nFor each test case, output the given string or -1 depending on conditions, in a new line.\n\n-----Constraints-----\n- 1 \u2264 T \u2264 1000\n- -20 \u2264 N \u2264 20\n\n-----Example-----\nInput\n3 \n1\n12\n-5\nOutput\nThanks for helping Chef!\n-1\nThanks for helping Chef!\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\nfor i in range(int(input())):\n x=int(input())\n if x<10:\n print(\"Thanks for helping Chef!\")\n else:\n print(\"-1\")\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\n1\\n12\\n-5\\n', 'output': 'Thanks for helping Chef!\\n-1\\nThanks for helping Chef!\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/FLOW008'}","problem_id":"vfc_3466","program":"```python\n# cook your dish here\nfor i in range(int(input())):\n x=int(input())\n if x<10:\n print(\"Thanks for helping Chef!\")\n else:\n print(\"-1\")\n\n```","inputs":"3\n1\n12\n-5\n","output":"Thanks for helping Chef!\n-1\nThanks for helping Chef!\n","actual_output":"Thanks for helping Chef!\n-1\nThanks for helping Chef!\n","execution_success":true,"sample_index":753},{"source":"apps","task_type":"verifiable_code","in_source_id":"1157","prompt":"Solve the following coding problem using the programming language python:\n\nToday is the planned day tor Thik and Ayvak's wedding. Kark is infatuated with Ayvak. He offers to play a game with Thik. Whosoever wins, will get to marry Ayvak. Ayvak, who values games of chance over all the other things in life, agrees to this.\n\nKark sets up an N by M grid (N rows, M columns), labelled from left to right and top to bottom consecutively with numbers from 1 to M*N, with 1 at the top left corner and M*N at the bottom right corner. For example, a labelled 3 by 6 grid looks as follows:\n\nKark has already painted K unit squares of the grid with a heart each. Next, Thik randomly picks a rectangle with sides on the grid lines, and having a positive area, with each valid rectangle having an equal probability of being chosen. Three distinct possibilities for Thik's rectangle in the 3 by 6 grid are shown below: \n\nThe nine different rectangles in a 2 by 2 grid are shown below:\n\n\nIf Thik's rectangle contains at least half of the hearts, Thik gets to marry Ayvak. Otherwise, Kark will marry Ayvak. Kark wants to know whether or not he has an advantage here, so he wants to know the expected value of the number of hearts a randomly chosen rectangle will cover. I'm sure that you have a good heart, so please, cover this job for him. \n\n-----Input-----\nThe first line of input contains one integer T, the number of test cases.\nFor each test case, the first line contains 3 space-separated integers N, M, K, as described in the problem statement. The next line contains K space-separated integers, each a single number from 1 to M*N, representing a square that is painted with a heart. It is guaranteed that all K integers are distinct.\n\n-----Output-----\nOutput T lines, each containing a single real number, containing the expected number of hearts that a randomly chosen rectangle will contain. The answer will be considered correct if its relative or absolute error does not exceed 10-6.\n\n-----Constraints-----\n- 1 \u2264 T \u2264 5 \n- 1 \u2264 N, M \u2264 107 \n- 1 \u2264 K \u2264 105 \n- Each of the K integers representing a heart are between 1 and N*M, inclusive. All K integers are distinct. \n\n-----Subtasks-----Subtask 1 (15 points) : \n\n- 1 \u2264 N, M \u2264 10\n- 1 \u2264 K \u2264 N * M \nSubtask 2 (85 points) : no additional constraints \n\n\n-----Example-----\nInput:\n1\n2 2 2\n1 2\n\nOutput:\n0.8888888888888888\n\n-----Explanation-----\nThere are a total of 9 possible rectangles Thik could draw, shown in the figure above, and grid squares 1 and 2 are painted with a heart. The top row of possible selections (shown in the figure) contain 1, 0, 1, 2, and 2 hearts (from left to right), and the bottom row of possible selections (in the figure) contain 1, 0, 1, and 0 hearts. Therefore, 3/9 of the time 0 hearts are contained in the rectangle, 4/9 of the times 1 heart is contained in the rectangle, and 2/9 of the time 2 hearts are contained in the rectangle. The expected value is then 0 * 3/9 + 1 * 4/9 + 2 * 2/9 = 8/9.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\n# cook your dish here\nfor i in range(int(input())):\n n,m,k=map(int,input().split())\n l,ans = list(map(int,input().split())),0\n for i in l:\n r=i//m + 1;c=i%m\n if(c==0):c=m;r-=1\n ans+=r*(n+1-r)*c*(m+1-c)\n ans/=((n+1)*(m+1)*n*m)//4\n print(ans)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n2 2 2\\n1 2\\n\\n\\n', 'output': '0.8888888888888888\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/RECTLOVE'}","problem_id":"vfc_3470","program":"```python\n# cook your dish here\n# cook your dish here\nfor i in range(int(input())):\n n,m,k=map(int,input().split())\n l,ans = list(map(int,input().split())),0\n for i in l:\n r=i//m + 1;c=i%m\n if(c==0):c=m;r-=1\n ans+=r*(n+1-r)*c*(m+1-c)\n ans/=((n+1)*(m+1)*n*m)//4\n print(ans)\n```","inputs":"1\n2 2 2\n1 2\n\n\n","output":"0.8888888888888888\n","actual_output":"0.8888888888888888\n","execution_success":true,"sample_index":754},{"source":"apps","task_type":"verifiable_code","in_source_id":"1159","prompt":"Solve the following coding problem using the programming language python:\n\nAbhi and his friends (Shanky,Anku and Pandey) love to play with strings. Abhi invented a simple game. He will give a string S to his friends. Shanky and Anku will play the game while Pandey is just a spectator. Shanky will traverse the string from beginning (left to right) while Anku will traverse from last (right to left). Both have to find the first character they encounter during their traversal,that appears only once in the entire string. Winner will be one whose character is alphabetically more superior(has higher ASCII value). When it is not possible to decide the winner by comparing their characters, Pandey will be the winner.\n\n-----Input-----\nThe first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.\n\nEach test case contains a string S having only lowercase alphabets ( a..z ).\n\n-----Output-----\nFor each test case, output a single line containing \"SHANKY\" if Shanky is the winner or \"ANKU\" if Anku is the winner or \"PANDEY\" if the winner is Pandey. Output your answer without quotes.\n\n-----Constraints-----\n- 1 \u2264 T \u2264 100\n- 1 < |S| \u2264 10^5\n\n-----Example-----\nInput:\n3\ngoogle\nbreakraekb\naman\n\nOutput:\nSHANKY\nPANDEY\nANKU\n\n-----Explanation-----\nExample case 2. Both Shanky and Anku can not find any such character. Hence it is not possible to decide the winner between these two. So Pandey is the winner.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nt = int(input())\n\nfor e in range(t):\n\n str = input()\n\n dict = {}\n\n for x in range(len(str)):\n if str[x] in dict:\n dict[str[x]] = -1\n else:\n dict[str[x]] = x\n\n shankyIndex = len(str)\n ankuIndex = -1\n for x in dict:\n if dict[x] != -1:\n if dict[x] < shankyIndex:\n shankyIndex = dict[x]\n if dict[x] > ankuIndex:\n ankuIndex = dict[x]\n\n ankuLetter = 0\n shankyLetter = 0\n\n if ankuIndex != -1:\n ankuLetter = str[ankuIndex]\n else:\n print('PANDEY')\n continue\n\n if shankyIndex != len(str):\n shankyLetter = str[shankyIndex]\n else:\n print('PANDEY')\n continue\n\n if shankyLetter > ankuLetter:\n print('SHANKY')\n elif ankuLetter > shankyLetter:\n print('ANKU')\n else:\n print('PANDEY')\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\ngoogle\\nbreakraekb\\naman\\n', 'output': 'SHANKY\\nPANDEY\\nANKU\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/RECJ1601/problems/ABHSTR'}","problem_id":"vfc_3478","program":"```python\nt = int(input())\n\nfor e in range(t):\n\n str = input()\n\n dict = {}\n\n for x in range(len(str)):\n if str[x] in dict:\n dict[str[x]] = -1\n else:\n dict[str[x]] = x\n\n shankyIndex = len(str)\n ankuIndex = -1\n for x in dict:\n if dict[x] != -1:\n if dict[x] < shankyIndex:\n shankyIndex = dict[x]\n if dict[x] > ankuIndex:\n ankuIndex = dict[x]\n\n ankuLetter = 0\n shankyLetter = 0\n\n if ankuIndex != -1:\n ankuLetter = str[ankuIndex]\n else:\n print('PANDEY')\n continue\n\n if shankyIndex != len(str):\n shankyLetter = str[shankyIndex]\n else:\n print('PANDEY')\n continue\n\n if shankyLetter > ankuLetter:\n print('SHANKY')\n elif ankuLetter > shankyLetter:\n print('ANKU')\n else:\n print('PANDEY')\n```","inputs":"3\ngoogle\nbreakraekb\naman\n","output":"SHANKY\nPANDEY\nANKU\n","actual_output":"SHANKY\nPANDEY\nANKU\n","execution_success":true,"sample_index":756},{"source":"apps","task_type":"verifiable_code","in_source_id":"1160","prompt":"Solve the following coding problem using the programming language python:\n\nChef is an advocate for Go Green Initiative. Today he had n trees planted in a row outside his his restaurant. Today, the height of i-th tree is hi feet. The trees grow at a rate of mi feet per day.\nChef knows that trees will look beautiful if they form a zig-zag sequence. The trees will be said to be in Zig-zag sequence if the heights of tree first increases or decreases, then alternates between decreasing/increasing respectively. Formally, the trees will be said to in Zig-zag sequence if one of the following two conditions holds.\n\n- h1 < h2 > h3 < h4 and so on..\n- h1 > h2 < h3 > h4 and so on..\n\nChef wants to know intervals of time when the heights of the trees will form a zig-zag sequence.\n\n-----Input-----\nThe first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.\nThe first line of each test case contains a single integer n, denoting the number of trees.\nThe ith of following N lines contains two space separated integers hi and mi, denoting the initial height and the growth speed for ith tree.\n\n-----Output-----\nFor each test case, output an integer Q - the amount of the periods of consecutive moments of time, when the trees for a zig-zag sequence.\nOn the following Q lines, output the intervals of time when the trees' heights form a zig-zag sequence. For each intervals, output its' smallest and the largest instants of time. If the range is infinite, output Inf as the right bound.\nThe test cases are designed in such a way that the total output won't exceed 2 MB.\n\n-----Constraints-----\n\n- 1 \u2264 T \u2264 105\n- 1 \u2264 n \u2264 10\n- Subtask 1 (23 points): 0 \u2264 hi, mi \u2264 10\n- Subtask 2 (77 points): 0 \u2264 hi, mi \u2264 109\n- 1 \u2264 sum of n over a test cases in a single test file \u2264 5 \u00d7 105\n\n-----Example-----\nInput:3\n3\n0 1\n2 2\n0 3\n2\n2 1\n1 2\n3\n1 1\n2 2\n3 3\n\nOutput:1\n0 1\n2\n0 0\n2 Inf\n0\n\n-----Explanation-----\nExample case 1. In the first case 0 2 0 is already a zig-zag sequence, but on the 2nd second it will become 2 6 6 and will never turn back into zig-zag\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\ndef get(l,n):\n l1,l2 = [],[]\n i = 1\n h1,m1 = l[0]\n while (i < len(l)):\n h2,m2 = l[i]\n if (h1>h2):\n if (m1 >= m2):\n l1 += [(0,10**20)]\n l2 += [(-1,-1)]\n else:\n d = (h1-h2)//(m2-m1)\n if (((h1-h2)%(m2-m1)) == 0):\n l1 += [(0,d-1)]\n l2 += [(d+1,10**20)]\n else:\n l1 += [(0,d)]\n l2 += [(d+1,10**20)]\n elif(h1==h2):\n if (m1 > m2):\n l1 += [(1,10**20)]\n l2 += [(-1,-1)]\n elif(m1==m2):\n l1 += [(-1,-1)]\n l2 += [(-1,-1)]\n else:\n l2 += [(1,10**20)]\n l1 += [(-1,-1)]\n else:\n if (m1 <= m2):\n l2 += [(0,10**20)]\n l1 += [(-1,-1)]\n else:\n d = (h2-h1)//(m1-m2)\n if ((h2-h1)%(m1-m2) == 0):\n l2 += [(0,d-1)]\n l1 += [(d+1,10**20)]\n else:\n l2 += [(0,d)]\n l1 += [(d+1,10**20)]\n i += 1\n h1,m1 = h2,m2\n return l1,l2\n \ndef intersect(k1,k2):\n k1,k2 = min(k1,k2),max(k1,k2)\n c1,c2 = k1\n c3,c4 = k2\n l = [c1,c2,c3,c4]\n l.sort()\n if (l[2]==c2):\n return (c3,min(c2,c4))\n elif (l[3]==c2):\n return k2\n else:\n return (-1,-1)\n \n \n \ndef union(k1,k2):\n k1,k2 = min(k1,k2),max(k1,k2)\n c1,c2 = k1\n c3,c4 = k2\n l = [c1,c2,c3,c4]\n l.sort()\n if (c2==l[3]):\n return ([c1,c2])\n elif(c2==l[2] or ((c3-c2) == 1)):\n return([c1,c4])\n else:\n return([c1,c2,c3,c4])\n \n \ndef aa(l1,l2,n):\n c1,c2 = 0,10**20\n i = 0\n n -= 1\n while (i < n):\n if (i%2 == 0):\n k1,k2 = l1[i]\n else:\n k1,k2 = l2[i]\n i += 1\n if ((k1,k2) == (-1,-1)):\n return (-1,-1)\n c1,c2 = intersect((c1,c2),(k1,k2))\n if ((c1,c2) == (-1,-1)):\n return (c1,c2)\n return (c1,c2)\n \n \ntest = int(input())\nwhile (test != 0):\n test -= 1\n n = int(input())\n l = []\n i = 0\n while (i < n):\n c1,c2 = list(map(int,input().split()))\n l += [(c1,c2)]\n i += 1\n if (n == 1):\n print(1)\n print(\"0 Inf\")\n else:\n l1,l2 = (get(l,n))\n k1,k2 = aa(l1,l2,n)\n if ((k1,k2) == (-1,-1)):\n k1,k2 = aa(l2,l1,n)\n if ((k1,k2) == (-1,-1)):\n print(0)\n else:\n print(1)\n if (k2 == 10**20):\n k2 = \"Inf\"\n print(str(k1) + \" \" +str(k2))\n else:\n k3,k4 = aa(l2,l1,n)\n if ((k3,k4) == (-1,-1)):\n print(1)\n if (k2 == 10**20):\n k2 = \"Inf\"\n print(str(k1) + \" \" +str(k2))\n else:\n p = union((k1,k2),(k3,k4))\n if (len(p)==2):\n c1,c2 = p\n if (c2==10**20):\n c2 = \"Inf\"\n print(1)\n print(str(c1) + \" \" +str(c2))\n else:\n c1,c2,c3,c4 = p\n if (c4 == 10**20):\n c4 = \"Inf\"\n print(2)\n print(str(c1) + \" \" +str(c2))\n print(str(c3) + \" \" +str(c4))\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\n3\\n0 1\\n2 2\\n0 3\\n2\\n2 1\\n1 2\\n3\\n1 1\\n2 2\\n3 3\\n', 'output': '1\\n0 1\\n2\\n0 0\\n2 Inf\\n0\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/AUG16/problems/CHAHG'}","problem_id":"vfc_3482","program":"```python\ndef get(l,n):\n l1,l2 = [],[]\n i = 1\n h1,m1 = l[0]\n while (i < len(l)):\n h2,m2 = l[i]\n if (h1>h2):\n if (m1 >= m2):\n l1 += [(0,10**20)]\n l2 += [(-1,-1)]\n else:\n d = (h1-h2)//(m2-m1)\n if (((h1-h2)%(m2-m1)) == 0):\n l1 += [(0,d-1)]\n l2 += [(d+1,10**20)]\n else:\n l1 += [(0,d)]\n l2 += [(d+1,10**20)]\n elif(h1==h2):\n if (m1 > m2):\n l1 += [(1,10**20)]\n l2 += [(-1,-1)]\n elif(m1==m2):\n l1 += [(-1,-1)]\n l2 += [(-1,-1)]\n else:\n l2 += [(1,10**20)]\n l1 += [(-1,-1)]\n else:\n if (m1 <= m2):\n l2 += [(0,10**20)]\n l1 += [(-1,-1)]\n else:\n d = (h2-h1)//(m1-m2)\n if ((h2-h1)%(m1-m2) == 0):\n l2 += [(0,d-1)]\n l1 += [(d+1,10**20)]\n else:\n l2 += [(0,d)]\n l1 += [(d+1,10**20)]\n i += 1\n h1,m1 = h2,m2\n return l1,l2\n \ndef intersect(k1,k2):\n k1,k2 = min(k1,k2),max(k1,k2)\n c1,c2 = k1\n c3,c4 = k2\n l = [c1,c2,c3,c4]\n l.sort()\n if (l[2]==c2):\n return (c3,min(c2,c4))\n elif (l[3]==c2):\n return k2\n else:\n return (-1,-1)\n \n \n \ndef union(k1,k2):\n k1,k2 = min(k1,k2),max(k1,k2)\n c1,c2 = k1\n c3,c4 = k2\n l = [c1,c2,c3,c4]\n l.sort()\n if (c2==l[3]):\n return ([c1,c2])\n elif(c2==l[2] or ((c3-c2) == 1)):\n return([c1,c4])\n else:\n return([c1,c2,c3,c4])\n \n \ndef aa(l1,l2,n):\n c1,c2 = 0,10**20\n i = 0\n n -= 1\n while (i < n):\n if (i%2 == 0):\n k1,k2 = l1[i]\n else:\n k1,k2 = l2[i]\n i += 1\n if ((k1,k2) == (-1,-1)):\n return (-1,-1)\n c1,c2 = intersect((c1,c2),(k1,k2))\n if ((c1,c2) == (-1,-1)):\n return (c1,c2)\n return (c1,c2)\n \n \ntest = int(input())\nwhile (test != 0):\n test -= 1\n n = int(input())\n l = []\n i = 0\n while (i < n):\n c1,c2 = list(map(int,input().split()))\n l += [(c1,c2)]\n i += 1\n if (n == 1):\n print(1)\n print(\"0 Inf\")\n else:\n l1,l2 = (get(l,n))\n k1,k2 = aa(l1,l2,n)\n if ((k1,k2) == (-1,-1)):\n k1,k2 = aa(l2,l1,n)\n if ((k1,k2) == (-1,-1)):\n print(0)\n else:\n print(1)\n if (k2 == 10**20):\n k2 = \"Inf\"\n print(str(k1) + \" \" +str(k2))\n else:\n k3,k4 = aa(l2,l1,n)\n if ((k3,k4) == (-1,-1)):\n print(1)\n if (k2 == 10**20):\n k2 = \"Inf\"\n print(str(k1) + \" \" +str(k2))\n else:\n p = union((k1,k2),(k3,k4))\n if (len(p)==2):\n c1,c2 = p\n if (c2==10**20):\n c2 = \"Inf\"\n print(1)\n print(str(c1) + \" \" +str(c2))\n else:\n c1,c2,c3,c4 = p\n if (c4 == 10**20):\n c4 = \"Inf\"\n print(2)\n print(str(c1) + \" \" +str(c2))\n print(str(c3) + \" \" +str(c4))\n\n```","inputs":"3\n3\n0 1\n2 2\n0 3\n2\n2 1\n1 2\n3\n1 1\n2 2\n3 3\n","output":"1\n0 1\n2\n0 0\n2 Inf\n0\n","actual_output":"1\n0 1\n2\n0 0\n2 Inf\n0\n","execution_success":true,"sample_index":757},{"source":"apps","task_type":"verifiable_code","in_source_id":"1161","prompt":"Solve the following coding problem using the programming language python:\n\nIn Snakeland, there are some snakes and mongooses. They are lined up in a row. The information about how exactly they are lined up it is provided to you by a string of length n. If the i-th character of this string is 's', then it means that there is a snake at the i-th position, whereas the character 'm' denotes a mongoose.\nYou might have heard about the age-old rivalry between hares and tortoises, but in Snakeland, the rivalry between snakes and mongooses is much more famous. The snakes and the mongooses want to hold a final poll in which the ultimate winner of this age-old battle will be decided. If the snakes get more votes than the mongooses, they will be the ultimate winners. Similarly, if the mongooses get more votes than snakes, they will be the ultimate winners. Obviously, each animal is loyal to their species, i.e. each snake will vote for the snakes to be the ultimate champions and each mongoose for the mongooses.\n\nTomorrow's the election day. Before the elections, the mongooses decided to cheat. They planned that each mongoose will eat at most one of its neighbor snakes. Two animals are said to be neighbors of each other if they are consecutive to each other in the row. After this, the elections will be held. The mongooses planned in such a way that the number of snakes eaten is maximized. Can you find out who will win the final poll? Output \"snakes\", \"mongooses\" or \"tie\" correspondingly.\n\n-----Input-----\nFirst line of the input contains an integer T denoting the number of test cases. The description of T test cases follow.\nThe only line of each test case contains a string consisting of characters 's' and 'm'. \n\n-----Output-----\nFor each test case output a single line containing \"snakes\", \"mongooses\" or \"tie\" correspondingly (without quotes).\n\n-----Constraints-----\n- 1 \u2264 T \u2264 100\n- 1 \u2264 |s| \u2264 100\n\n-----Example-----\nInput\n4\nsm\nssm\nsms\nssmmmssss\n\nOutput\nmongooses\ntie\ntie\nsnakes\n\n-----Explanation-----\nExample 1. The mongoose will eat the snake. Only the mongoose will be left. So, on the election day, there is one mongoose and zero snakes. So mongooses will win.\nExample 2. The mongoose will eat the snake at position 2 (1-based indexing). One mongoose and one snake will be left. Hence, there will be a tie.\nExample 3. The mongoose can eat either the snake to its left or to the right. But, it can eat only one of them. Afterwards, there will be a single snake and mongoose. So, it will result in a tie. \nExample 4. The mongooses can eat at max two snakes. For example, s*mmm*sss, where * denotes the snakes that were eaten by mongooses. After this, we have four snakes and three mongooses. So, the snakes win.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfor i in range(int(input())):\n a=input()\n c=a.count('m')\n d=a.count('s')\n t=0\n while td:\n print('mongooses')\n elif d>c:\n print('snakes')\n else:\n print('tie')\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '4\\nsm\\nssm\\nsms\\nssmmmssss\\n', 'output': 'mongooses\\ntie\\ntie\\nsnakes\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/SNELECT'}","problem_id":"vfc_3486","program":"```python\nfor i in range(int(input())):\n a=input()\n c=a.count('m')\n d=a.count('s')\n t=0\n while td:\n print('mongooses')\n elif d>c:\n print('snakes')\n else:\n print('tie')\n\n```","inputs":"4\nsm\nssm\nsms\nssmmmssss\n","output":"mongooses\ntie\ntie\nsnakes\n","actual_output":"mongooses\ntie\ntie\nsnakes\n","execution_success":true,"sample_index":758},{"source":"apps","task_type":"verifiable_code","in_source_id":"1163","prompt":"Solve the following coding problem using the programming language python:\n\nWho's interested in football?\nRayne Wooney has been one of the top players for his football club for the last few years. But unfortunately, he got injured during a game a few months back and has been out of play ever since.\nHe's got proper treatment and is eager to go out and play for his team again. Before doing that, he has to prove to his fitness to the coach and manager of the team. Rayne has been playing practice matches for the past few days. He's played N practice matches in all.\nHe wants to convince the coach and the manager that he's improved over time and that his injury no longer affects his game. To increase his chances of getting back into the team, he's decided to show them stats of any 2 of his practice games. The coach and manager will look into the goals scored in both the games and see how much he's improved. If the number of goals scored in the 2nd game(the game which took place later) is greater than that in 1st, then he has a chance of getting in. Tell Rayne what is the maximum improvement in terms of goal difference that he can show to maximize his chances of getting into the team. If he hasn't improved over time, he's not fit to play. Scoring equal number of goals in 2 matches will not be considered an improvement. Also, he will be declared unfit if he doesn't have enough matches to show an improvement.\n\n-----Input:-----\nThe first line of the input contains a single integer T, the number of test cases.\nEach test case begins with a single integer N, the number of practice matches Rayne has played.\n\nThe next line contains N integers. The ith integer, gi, on this line represents the number of goals Rayne scored in his ith practice match. The matches are given in chronological order i.e. j > i means match number j took place after match number i.\n\n-----Output:-----\nFor each test case output a single line containing the maximum goal difference that Rayne can show to his coach and manager. If he's not fit yet, print \"UNFIT\".\n\n-----Constraints:-----\n1<=T<=10\n\n1<=N<=100000\n\n0<=gi<=1000000 (Well, Rayne's a legend! You can expect him to score so many goals!)\n\n-----Example:-----Input:\n\n3\n\n6\n\n3 7 1 4 2 4\n\n5\n\n5 4 3 2 1\n\n5\n\n4 3 2 2 3\n\nOutput:\n\n4\n\nUNFIT\n\n1\n\nExplanation:\n\nIn the first test case, Rayne can choose the first and second game. Thus he gets a difference of 7-3=4 goals. Any other pair would give him a lower improvement.\nIn the second test case, Rayne has not been improving in any match. Thus he's declared UNFIT.\nNote: Large input data. Use faster I/O methods. Prefer scanf,printf over cin/cout.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nT = int(input())\nfor j in range(0,T):\n line1, line2 = input(), input()\n seq = line2.split()\n current_min = 1000001\n current_max = 0\n max_spread = 0\n for i in range(0,len(seq)):\n current_value = int(seq[i])\n if current_min > current_value:\n current_min = current_value\n current_max = current_value\n elif current_max < current_value:\n current_max = current_value\n if max_spread < (current_max - current_min):\n max_spread = current_max - current_min \n if max_spread > 0:\n print(max_spread)\n else:\n print(\"UNFIT\")\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\n6\\n3 7 1 4 2 4\\n5\\n5 4 3 2 1\\n5\\n4 3 2 2 3\\n', 'output': '4\\nUNFIT\\n1\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/APRIL12/problems/PLAYFIT'}","problem_id":"vfc_3494","program":"```python\nT = int(input())\nfor j in range(0,T):\n line1, line2 = input(), input()\n seq = line2.split()\n current_min = 1000001\n current_max = 0\n max_spread = 0\n for i in range(0,len(seq)):\n current_value = int(seq[i])\n if current_min > current_value:\n current_min = current_value\n current_max = current_value\n elif current_max < current_value:\n current_max = current_value\n if max_spread < (current_max - current_min):\n max_spread = current_max - current_min \n if max_spread > 0:\n print(max_spread)\n else:\n print(\"UNFIT\")\n```","inputs":"3\n6\n3 7 1 4 2 4\n5\n5 4 3 2 1\n5\n4 3 2 2 3\n","output":"4\nUNFIT\n1\n","actual_output":"4\nUNFIT\n1\n","execution_success":true,"sample_index":760},{"source":"apps","task_type":"verifiable_code","in_source_id":"1164","prompt":"Solve the following coding problem using the programming language python:\n\nMandarin chinese\n, Russian and Vietnamese as well.\nChef is organising a contest with $P$ problems (numbered $1$ through $P$). Each problem has $S$ subtasks (numbered $1$ through $S$).\nThe difficulty of a problem can be calculated as follows:\n- Let's denote the score of the $k$-th subtask of this problem by $SC_k$ and the number of contestants who solved it by $NS_k$.\n- Consider the subtasks sorted in the order of increasing score.\n- Calculate the number $n$ of valid indices $k$ such that $NS_k > NS_{k + 1}$.\n- For problem $i$, the difficulty is a pair of integers $(n, i)$.\nYou should sort the problems in the increasing order of difficulty levels. Since difficulty level is a pair, problem $a$ is more difficult than problem $b$ if the number $n$ is greater for problem $a$ than for problem $b$, or if $a > b$ and $n$ is the same for problems $a$ and $b$.\n\n-----Input-----\n- The first line of the input contains two space-separated integers $P$ and $S$ denoting the number of problems and the number of subtasks in each problem.\n- $2P$ lines follow. For each valid $i$, the $2i-1$-th of these lines contains $S$ space-separated integers $SC_1, SC_2, \\dots, SC_S$ denoting the scores of the $i$-th problem's subtasks, and the $2i$-th of these lines contains $S$ space-separated integers $NS_1, NS_2, \\dots, NS_S$ denoting the number of contestants who solved the $i$-th problem's subtasks.\n\n-----Output-----\nPrint $P$ lines containing one integer each \u2014 the indices of the problems in the increasing order of difficulty.\n\n-----Constraints-----\n- $1 \\le P \\le 100,000$\n- $2 \\le S \\le 30$\n- $1 \\le SC_i \\le 100$ for each valid $i$\n- $1 \\le NS_i \\le 1,000$ for each valid $i$\n- in each problem, the scores of all subtasks are unique\n\n-----Subtasks-----\nSubtask #1 (25 points): $S = 2$\nSubtask #2 (75 points): original constraints\n\n-----Example Input-----\n3 3\n16 24 60\n498 861 589\n14 24 62\n72 557 819\n16 15 69\n435 779 232\n\n-----Example Output-----\n2\n1\n3\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\np,s = [int(i) for i in input().split()]\nscores = {}\n\nfor j in range(1, p + 1):\n sc = [int(i) for i in input().split()]\n ns = [int(i) for i in input().split()]\n nsc = dict(list(zip(sc,ns)))\n ssc = sorted(sc)\n score = 0\n for a,b in zip(ssc[:-1], ssc[1:]):\n if nsc[a] > nsc[b]:\n score += 1\n if score in list(scores.keys()) :\n scores[score].append(j)\n else :\n scores[score] = [j]\n\ntotal_scores = sorted(list(scores.keys()))\nfinal_list = []\nfor val in total_scores :\n final_list += sorted(scores[val])\n\nfor val in final_list :\n print(val)\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3 3\\n16 24 60\\n498 861 589\\n14 24 62\\n72 557 819\\n16 15 69\\n435 779 232\\n', 'output': '2\\n1\\n3\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/PROBLEMS'}","problem_id":"vfc_3498","program":"```python\np,s = [int(i) for i in input().split()]\nscores = {}\n\nfor j in range(1, p + 1):\n sc = [int(i) for i in input().split()]\n ns = [int(i) for i in input().split()]\n nsc = dict(list(zip(sc,ns)))\n ssc = sorted(sc)\n score = 0\n for a,b in zip(ssc[:-1], ssc[1:]):\n if nsc[a] > nsc[b]:\n score += 1\n if score in list(scores.keys()) :\n scores[score].append(j)\n else :\n scores[score] = [j]\n\ntotal_scores = sorted(list(scores.keys()))\nfinal_list = []\nfor val in total_scores :\n final_list += sorted(scores[val])\n\nfor val in final_list :\n print(val)\n\n```","inputs":"3 3\n16 24 60\n498 861 589\n14 24 62\n72 557 819\n16 15 69\n435 779 232\n","output":"2\n1\n3\n","actual_output":"2\n1\n3\n","execution_success":true,"sample_index":761},{"source":"apps","task_type":"verifiable_code","in_source_id":"1165","prompt":"Solve the following coding problem using the programming language python:\n\nChef will not be able to attend the birthday of his best friend Rock. He promised Rock that this will not be the case on his half birthday. To keep his promise Chef must know Rock\u2019s next half birthday accurately. Being busy, he is assigning this work to you.\nHalf birthday is the day that occurs exactly between two subsequent birthdays. \nYou will be provided with Rock\u2019s birthdate and birth month, you will have to figure out his half birthday.\n$Note$: Consider every year to be a leap year and all months are displayed in lowercase English characters.\n\n-----Input:-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. \n- The description of each of the $T$ test cases contains an integer $d$ followed by a string, denoting month $m$.\n- Here $d$ denotes day of a month and $m$ denotes the month of a year respectively.\n\n-----Output:-----\nFor each test case print an integer $d1$ followed by a string, denoting month $m1$, which overall denotes date and month of Rock\u2019s half birthday.\n\n-----Constraints:-----\n- $1 \\leq T \\leq 10^5$\n- $1 \\leq d , d1 \\leq 31$\n- $january \\leq m , m1 \\leq december$\n\n-----Sample Input:-----\n3\n15 january\n31 august\n10 october\n\n-----Sample Output:-----\n16 july\n1 march\n10 april\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\nd = {'january':31,'february':29,'march':31,\n 'april':30,'may':31,'june':30,'july':31,\n 'august':31,'september':30,'october':31,\n 'november':30,'december':31}\n \n#l=[[15,'january'],[31,'august'],[10,'october']]\nl2 = list(d.keys())\nfor _ in range(int(input())):\n l=input().split()\n l[0]=int(l[0])\n a = l[1]\n ind = l2.index(a)\n b = 183 - (d[l[1]] - l[0])\n while b!=0:\n if ind!=11:\n ind+=1\n else:\n ind = 0\n if b<=d[l2[ind]]:\n print(b,l2[ind])\n break\n b-=d[l2[ind]]\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\n15 january\\n31 august\\n10 october\\n', 'output': '16 july\\n1 march\\n10 april\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/PAHC2020/problems/HALFBDAY'}","problem_id":"vfc_3502","program":"```python\n# cook your dish here\nd = {'january':31,'february':29,'march':31,\n 'april':30,'may':31,'june':30,'july':31,\n 'august':31,'september':30,'october':31,\n 'november':30,'december':31}\n \n#l=[[15,'january'],[31,'august'],[10,'october']]\nl2 = list(d.keys())\nfor _ in range(int(input())):\n l=input().split()\n l[0]=int(l[0])\n a = l[1]\n ind = l2.index(a)\n b = 183 - (d[l[1]] - l[0])\n while b!=0:\n if ind!=11:\n ind+=1\n else:\n ind = 0\n if b<=d[l2[ind]]:\n print(b,l2[ind])\n break\n b-=d[l2[ind]]\n```","inputs":"3\n15 january\n31 august\n10 october\n","output":"16 july\n1 march\n10 april\n","actual_output":"16 july\n1 march\n10 april\n","execution_success":true,"sample_index":762},{"source":"apps","task_type":"verifiable_code","in_source_id":"1166","prompt":"Solve the following coding problem using the programming language python:\n\nLittle Elephant is playing a game with arrays. He is given an array A0, A1, ..., AN\u22121 of N integers. And then Q queries are given, each containing an integer K. He has to tell how many subarrays satisfy the condition: the function foo returns K when it is applied to the subarray.\n\nIn this problem, a subarray is defined as a sequence of continuous elements Ai, Ai+1, ..., Aj where 0 \u2264 i \u2264 j \u2264 N\u22121. The function foo, when applied to an array, returns the minimum of all the elements in the array.\n\nFor example, foo returns 5 when it is applied to the array [7, 5, 10, 7, 5, 8]. Please note that the subarrays Ai, Ai+1, ..., Aj and Ak, Ak+1, ..., Al are different if and only if i \u2260 k or j \u2260 l in this problem.\n\n-----Input-----\nThe first line of input contains N, denoting the size of the array. The next line contains N space separated integers A0, A1, ..., AN\u22121, denoting the array. Then the next line contains Q, denoting the number of queries. Each query consists of one integer per line, denoting K.\n\n-----Output-----\nFor each query, print the required number of subarrays.\n\n-----Constraints-----\n- 1 \u2264 N \u2264 50\n- 1 \u2264 Ai \u2264 1000000 (106)\n- 1 \u2264 Q \u2264 10\n- 1 \u2264 K \u2264 1000000 (106)\n\n-----Example-----\nInput:\n5\n4 1 2 3 4\n4\n3\n4\n6\n1\n\nOutput:\n2\n2\n0\n8\n\n-----Explanation-----\nQuery 1. Only the two subarrays [3, 4] and [3] satisfy.\nQuery 2. Again only the two subarrays [4] and [4] satisfy. Please note that these subarrays (A0 and A4) are considered different.\nQuery 3. No subarray satisfies.\nQuery 4. The eight subarrays [4, 1], [4, 1, 2], [4, 1, 2, 3], [4, 1, 2, 3, 4], [1], [1, 2], [1, 2, 3] and [1, 2, 3, 4] satisfy.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nimport sys\nimport math\n\ndef main(arr,k):\n \n ans=0\n for i in range(len(arr)):\n curr_min=float('inf')\n for j in range(i,len(arr)):\n curr_min=min(curr_min,arr[j])\n \n if curr_min==k:\n ans+=1 \n return ans\n \n\nn=int(input())\narr=list(map(int,input().split()))\n\n\nfor i in range(int(input())):\n \n print(main(arr,int(input())))\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '5\\n4 1 2 3 4\\n4\\n3\\n4\\n6\\n1\\n\\n\\n', 'output': '2\\n2\\n0\\n8\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/SUBMIN'}","problem_id":"vfc_3506","program":"```python\nimport sys\nimport math\n\ndef main(arr,k):\n \n ans=0\n for i in range(len(arr)):\n curr_min=float('inf')\n for j in range(i,len(arr)):\n curr_min=min(curr_min,arr[j])\n \n if curr_min==k:\n ans+=1 \n return ans\n \n\nn=int(input())\narr=list(map(int,input().split()))\n\n\nfor i in range(int(input())):\n \n print(main(arr,int(input())))\n```","inputs":"5\n4 1 2 3 4\n4\n3\n4\n6\n1\n\n\n","output":"2\n2\n0\n8\n","actual_output":"2\n2\n0\n8\n","execution_success":true,"sample_index":763},{"source":"apps","task_type":"verifiable_code","in_source_id":"1167","prompt":"Solve the following coding problem using the programming language python:\n\nTom has finally taken over the business empire and now looking for \na new Name of the business to make a new start.\n\nJoe (Tom's dear friend) suggested a string $S$ consisting of\nUppercase and lowercase letters \n\nTom wants to make some changes as per the following criteria:\n\n1) String should $not$ have any vowels .\n\n2) Every other uppercase consonant(other characters except vowels) should \nbe in lowercase\n\nFor ex:\n\nIf the consonant character is Z then it should be z\n\n3) There should be a character \".\" before each consonant.\n\nHelp Tom to make the required Changes.\n\n-----Input:-----\n- First line will contain string $S$,This string only consists of uppercase and lowercase letters.\n\n-----Output:-----\nPrint the resulting string. It is guaranteed that this string is not empty.\n\n-----Constraints-----\n- Length of string is in [1 .. 100]\n\n-----Sample Input:-----\n$CodeSprInT$\n\n-----Sample Output:-----\n.c.d.s.p.r.n.t \n\n-----EXPLANATION:-----\nC is a consonant and it is in uppercase so turn it in lower case and add a \u201c.\u201d before it\no is a vowel so it is deleted\nd is a consonant and in lowercase so just add a \u201c.\u201d before it\ne is a vowel so it is deleted\nS is a consonant and it is in uppercase so turn it in lower case and add a \u201c.\u201d before it\np is a consonant and in lowercase so just add a \u201c.\u201d before it\nr is a consonant and in lowercase so just add a \u201c.\u201d before it\nI is a vowel so it is deleted\nn is a consonant and in lowercase so just add a \u201c.\u201d before it\nT is a consonant and it is in uppercase so turn it in lower case and add a \u201c.\u201d before it\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\ns = input().lower()\r\nvow = [\"a\", \"e\", \"i\", \"o\", \"u\", \"y\"]\r\nans = \"\"\r\nfor ch in s:\r\n if ch in vow:\r\n continue\r\n if ch.isalpha():\r\n ans += \".\" + ch\r\nprint(ans)\r\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': 'CodeSprInT\\n', 'output': '.c.d.s.p.r.n.t\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/SPRT2020/problems/EMPRNM'}","problem_id":"vfc_3510","program":"```python\ns = input().lower()\r\nvow = [\"a\", \"e\", \"i\", \"o\", \"u\", \"y\"]\r\nans = \"\"\r\nfor ch in s:\r\n if ch in vow:\r\n continue\r\n if ch.isalpha():\r\n ans += \".\" + ch\r\nprint(ans)\r\n\n```","inputs":"CodeSprInT\n","output":".c.d.s.p.r.n.t\n","actual_output":".c.d.s.p.r.n.t\n","execution_success":true,"sample_index":764},{"source":"apps","task_type":"verifiable_code","in_source_id":"1168","prompt":"Solve the following coding problem using the programming language python:\n\nAbhishek is fond of playing cricket very much. One morning, he is playing cricket with his friends. Abhishek is a right-hand batsman\n\n.He has to face all types of balls either good or bad. There are total 26 balls in the game and each ball is represented\n\nby one of the following two ways:-\n1. \"g\" denotes a good ball.\n2. \"b\" denotes a bad ball.\nAll 26 balls are represented by lower case letters (a,b,.....z).\nBalls faced by Abhishek are represented as a string s, all the characters of which are lower case i.e, within 26 above mentioned balls.\nA substring s[l...r] (1\u2264l\u2264r\u2264|s|) of string s=s1s2...s|s| (where |s| is the length of string s) is string slsl+1...sr.\nThe substring s[l...r] is good, if among the letters slsl+1...sr, there are at most k bad ones (refer sample explanation ).\nYour task is to find out the number of distinct good substrings for the given string s. Two substrings s[x...y] and s[p...q] are considered distinct if their contents are different, i.e. s[x...y]\u2260s[p...q].\n\n-----Input Format-----\nFirst Line contains an integer T, number of test cases. For each test case, first line contains a string - a sequence of balls faced by Abhishek.\n\nAnd, next line contains a string of characters \"g\" and \"b\" of length 26 characters. If the ith character of this string equals \"1\", then the i-th English letter is good, otherwise it's bad. That is, the first character of this string corresponds to letter \"a\", the second one corresponds to letter \"b\" and so on.\n\nAnd, the third line of the test case consists of a single integer k (0\u2264k\u2264|s|) \u2014 the maximum acceptable number of bad characters in a good substring.\n\n-----Output Format -----\nFor each test case, print a single integer \u2014 the number of distinct good substrings of string s.\n\n-----Constraints-----\n- 1<=T<=1000\n- 1<=|s|<=2000\n- 0<=k<=|s|\n\n-----Subtasks-----\nSubtask 1 : 20 Points\n- 1<=T<=10\n- 1<=|s|<=20\n- 0<=k<=|s|\nSubtask 2 : 80 Points \nOriginal Constraints\nSample Input\n2\nababab\nbgbbbbbbbbbbbbbbbbbbbbbbbb\n1\nacbacbacaa\nbbbbbbbbbbbbbbbbbbbbbbbbbb\n2\nSample Output\n5\n8\n\nExplanation\nIn the first test case there are following good substrings: \"a\", \"ab\", \"b\", \"ba\", \"bab\".\n\nIn the second test case there are following good substrings: \"a\", \"aa\", \"ac\", \"b\", \"ba\", \"c\", \"ca\", \"cb\".\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nimport sys\nfor _ in range(0,eval(input())): \n d,inp,mp,n,q=set(),list(map(ord,list(sys.stdin.readline().strip()))),[x=='b' for x in list(sys.stdin.readline().strip())],eval(input()),ord('a')\n inps = [inp[i:] for i in range(len(inp))]\n inps.sort()\n op,prev= 0,''\n for ip in inps:\n \ti,ct=0,0\n \twhile i < min(len(ip),len(prev)):\n \t\tif prev[i] != ip[i]:\n \t\t\tbreak\n \t\tif mp[ip[i]-q]:\n \t\t\tct = ct+ 1\n \t\ti = i+1\n \twhile i < len(ip):\n \t\tif mp[ip[i]-q]:\n \t\t\tct = ct + 1\n \t\tif ct > n:\n \t\t\tbreak\n \t\top,i= op+1,i+1\n \tprev = ip\n print(op)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\nababab\\nbgbbbbbbbbbbbbbbbbbbbbbbbb\\n1\\nacbacbacaa\\nbbbbbbbbbbbbbbbbbbbbbbbbbb\\n2\\n', 'output': '5\\n8\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/ICOD2016/problems/ICODE16G'}","problem_id":"vfc_3514","program":"```python\nimport sys\nfor _ in range(0,eval(input())): \n d,inp,mp,n,q=set(),list(map(ord,list(sys.stdin.readline().strip()))),[x=='b' for x in list(sys.stdin.readline().strip())],eval(input()),ord('a')\n inps = [inp[i:] for i in range(len(inp))]\n inps.sort()\n op,prev= 0,''\n for ip in inps:\n \ti,ct=0,0\n \twhile i < min(len(ip),len(prev)):\n \t\tif prev[i] != ip[i]:\n \t\t\tbreak\n \t\tif mp[ip[i]-q]:\n \t\t\tct = ct+ 1\n \t\ti = i+1\n \twhile i < len(ip):\n \t\tif mp[ip[i]-q]:\n \t\t\tct = ct + 1\n \t\tif ct > n:\n \t\t\tbreak\n \t\top,i= op+1,i+1\n \tprev = ip\n print(op)\n```","inputs":"2\nababab\nbgbbbbbbbbbbbbbbbbbbbbbbbb\n1\nacbacbacaa\nbbbbbbbbbbbbbbbbbbbbbbbbbb\n2\n","output":"5\n8\n","actual_output":"5\n8\n","execution_success":true,"sample_index":765},{"source":"apps","task_type":"verifiable_code","in_source_id":"1169","prompt":"Solve the following coding problem using the programming language python:\n\nThis is a simple game you must have played around with during your school days, calculating FLAMES of you and your crush! Given the names of two people, cancel out the common letters (repeated occurrence of a letter is treated separately, so 2A's in one name and one A in the other would cancel one A in each name), count the total number of remaining letters (n) and repeatedly cut the letter in the word FLAMES which hits at the nth number when we count from F in cyclic manner.\n\nFor example:\nNAME 1: SHILPA\nNAME 2: AAMIR\nAfter cutting the common letters: \nNAME 1: SHILPA \nNAME 2: AAMIR\nTotal number of letters left=7\nFLAMES, start counting from F : 1=F, 2=L, 3=A, 4=M, 5=E, 6=S,7=F...So cut F\nFLAMES: repeat this process with remaining letters of FLAMES for number 7 (start count from the letter after \nthe last letter cut) . In the end, one letter remains. Print the result corresponding to the last letter:\nF=FRIENDS\nL=LOVE\nA=ADORE\nM=MARRIAGE\nE=ENEMIES\nS=SISTER\n\n-----Input-----\nThe no. of test cases (<100)\ntwo names (may include spaces) for each test case.\n\n\n-----Output-----\nFLAMES result (Friends/Love/...etc) for each test case\n\n-----Example-----\nInput:\n2\nSHILPA\nAAMIR\nMATT\nDENISE\n\nOutput:\nENEMIES\nLOVE\n\n\n\nBy:\nChintan, Asad, Ashayam, Akanksha\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nimport sys\n\ndef joseph(k, n=6):\n\tif k==0:\n\t\tk = 1\n\tx = 0\n\tfor i in range(2,n+1):\n\t\tx = (x+k)%i\n\treturn x\n\nFLAMES = ['FRIENDS', 'LOVE', 'ADORE', 'MARRIAGE', 'ENEMIES', 'SISTER']\n\nnCase = int(sys.stdin.readline())\nfor _ in range(nCase):\n\ta = ''.join(sys.stdin.readline().split())\n\tb = ''.join(sys.stdin.readline().split())\n\tn = 0\n\tfor ch in set(a+b):\n\t\tn += abs(a.count(ch)-b.count(ch))\n\tprint(FLAMES[joseph(n)])\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\nSHILPA\\nAAMIR\\nMATT\\nDENISE\\n\\n\\n\\n', 'output': 'ENEMIES\\nLOVE\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/IGNS2012/problems/IG01'}","problem_id":"vfc_3518","program":"```python\nimport sys\n\ndef joseph(k, n=6):\n\tif k==0:\n\t\tk = 1\n\tx = 0\n\tfor i in range(2,n+1):\n\t\tx = (x+k)%i\n\treturn x\n\nFLAMES = ['FRIENDS', 'LOVE', 'ADORE', 'MARRIAGE', 'ENEMIES', 'SISTER']\n\nnCase = int(sys.stdin.readline())\nfor _ in range(nCase):\n\ta = ''.join(sys.stdin.readline().split())\n\tb = ''.join(sys.stdin.readline().split())\n\tn = 0\n\tfor ch in set(a+b):\n\t\tn += abs(a.count(ch)-b.count(ch))\n\tprint(FLAMES[joseph(n)])\n\n```","inputs":"2\nSHILPA\nAAMIR\nMATT\nDENISE\n\n\n\n","output":"ENEMIES\nLOVE\n","actual_output":"ENEMIES\nLOVE\n","execution_success":true,"sample_index":766},{"source":"apps","task_type":"verifiable_code","in_source_id":"1170","prompt":"Solve the following coding problem using the programming language python:\n\nIn order to establish dominance amongst his friends, Chef has decided that he will only walk in large steps of length exactly $K$ feet. However, this has presented many problems in Chef\u2019s life because there are certain distances that he cannot traverse. Eg. If his step length is $5$ feet, he cannot travel a distance of $12$ feet. Chef has a strict travel plan that he follows on most days, but now he is worried that some of those distances may become impossible to travel. Given $N$ distances, tell Chef which ones he cannot travel.\n\n-----Input:-----\n- The first line will contain a single integer $T$, the number of test cases.\n- The first line of each test case will contain two space separated integers - $N$, the number of distances, and $K$, Chef\u2019s step length.\n- The second line of each test case will contain $N$ space separated integers, the $i^{th}$ of which represents $D_i$, the distance of the $i^{th}$ path.\n\n-----Output:-----\nFor each testcase, output a string consisting of $N$ characters. The $i^{th}$ character should be $1$ if the distance is traversable, and $0$ if not. \n\n-----Constraints-----\n- $1 \\leq T \\leq 1000$\n- $1 \\leq N \\leq 1000$\n- $1 \\leq K \\leq 10^9$\n- $1 \\leq D_i \\leq 10^9$\n\n-----Subtasks-----\n- 100 points : No additional constraints.\n\n-----Sample Input:-----\n1\n5 3\n12 13 18 20 27216\n\n-----Sample Output:-----\n10101\n\n-----Explanation:-----\nThe first distance can be traversed in $4$ steps.\n\nThe second distance cannot be traversed.\n\nThe third distance can be traversed in $6$ steps.\n\nThe fourth distance cannot be traversed.\n\nThe fifth distance can be traversed in $9072$ steps.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nt=int(input())\nfor i in range(0,t):\n n,k=map(int,input().split())\n a1,*a=map(int,input().split())\n a.insert(0,a1)\n j=0\n while j= 3 and even >= 2:\n total += (odd*(odd-1)*(odd-2))//6\n total += odd*(even*(even-1))//2\n elif odd >= 3 and even < 2:\n total += (odd*(odd-1)*(odd-2))//6\n elif 0= 2:\n total += odd*(even*(even-1))//2\n \n print(total%(10**9+7))\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n4\\n1 1 2 3\\n', 'output': '1\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/LOG_EQN'}","problem_id":"vfc_3538","program":"```python\nfrom math import *\nt = int(input())\nfor _ in range(t):\n n = int(input())\n a = [int(d) for d in input().split()]\n odd,even = 0,0\n for i in range(n):\n if bin(a[i]).count(\"1\")%2 == 1:\n odd += 1\n else:\n even +=1\n total = 0\n if odd >= 3 and even >= 2:\n total += (odd*(odd-1)*(odd-2))//6\n total += odd*(even*(even-1))//2\n elif odd >= 3 and even < 2:\n total += (odd*(odd-1)*(odd-2))//6\n elif 0= 2:\n total += odd*(even*(even-1))//2\n \n print(total%(10**9+7))\n```","inputs":"1\n4\n1 1 2 3\n","output":"1\n","actual_output":"1\n","execution_success":true,"sample_index":770},{"source":"apps","task_type":"verifiable_code","in_source_id":"1175","prompt":"Solve the following coding problem using the programming language python:\n\nOliver and Nova are true lovers. Inspite of knowing that Nova will die Oliver married her at the lake where they met. But they had a conflict about even and odd numbers. Nova likes the odd numbers and Oliver prefers even. One day they went to a fair where Oliver bought some square shaped marshmallows and Nova bought some round shaped. Then they decided to play a game. They will pick a natural number N . Nova will sum up the odd numbers from 1 to N and and she will notedown LCM of R(R is defined in the picture) and the sum she calculated before. And Oliver will sum up the even numbers from 1 to N and and he will notedown LCM of S(S is defined in the picture) and the sum he calculated before. You must use the ceil value of R and S.\n\nNow whose LCM is strictly greater than the other will win.If both of their LCM is equal Nova will win because Oliver is afraid of Nova.\n$N.B.$ define the value of pi with $acos(-1)$.\n$N.B.$ Sum of all odd number and sum of all even number will not exceed 10^18. \n\n-----Input:-----\nThe first line contains an integer $T$ \u2014 the number of test cases in the input. Next, T test cases are given, one per line.\nEach test case is a positive integer $N$ . \n\n-----Output:-----\nPrint T answers to the test cases.\nIn each test cases,\nIf Oliver wins the game, print \"Nova's gonna kill me\" (without quotes) .\nIf Nova wins the game, print \"YESS(sunglass emo)\" (without quotes) .\n\n-----Constraints-----\n- $1 \\leq T \\leq 2000$\n- $1 \\leq N \\leq 1845271$\n\n-----Sample Input:-----\n1\n111\n\n-----Sample Output:-----\nYESS(sunglass emo)\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nimport math\n\ndef lcm(a, b):\n return (a*b)//gcd(a, b)\n\ndef gcd(a, b):\n if b == 0:\n return a\n return gcd(b, a%b) \n \nfor _ in range(int(input())):\n n = int(input())\n\n na = math.ceil((2*n)/math.acos(-1))\n nb = ((n+1)//2)**2\n\n nlcm = lcm(na, nb)\n\n oa = math.ceil(n/2)\n ob = (n//2)*(n//2+1)\n\n olcm = lcm(oa, ob)\n\n if olcm > nlcm:\n print(\"Nova's gonna kill me\")\n else:\n print(\"YESS(sunglass emo)\")\n\n# cook your dish here\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n111\\n', 'output': 'YESS(sunglass emo)\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/NEWB2020/problems/CNFCT'}","problem_id":"vfc_3542","program":"```python\nimport math\n\ndef lcm(a, b):\n return (a*b)//gcd(a, b)\n\ndef gcd(a, b):\n if b == 0:\n return a\n return gcd(b, a%b) \n \nfor _ in range(int(input())):\n n = int(input())\n\n na = math.ceil((2*n)/math.acos(-1))\n nb = ((n+1)//2)**2\n\n nlcm = lcm(na, nb)\n\n oa = math.ceil(n/2)\n ob = (n//2)*(n//2+1)\n\n olcm = lcm(oa, ob)\n\n if olcm > nlcm:\n print(\"Nova's gonna kill me\")\n else:\n print(\"YESS(sunglass emo)\")\n\n# cook your dish here\n\n```","inputs":"1\n111\n","output":"YESS(sunglass emo)\n","actual_output":"YESS(sunglass emo)\n","execution_success":true,"sample_index":771},{"source":"apps","task_type":"verifiable_code","in_source_id":"1176","prompt":"Solve the following coding problem using the programming language python:\n\nThere are $5$ cities in the country.\nThe map of the country is given below.\nThe tour starts from the red city.\n\nEach road is associated with a character.\nInitially, there is an empty string.\nEvery time a road has been travelled the character associated gets appended to the string.\nAt the green city either the string can be printed or the tour can be continued.\nIn the problem, you are given a string tell whether it is possible to print the string while following the rules of the country?\n\n-----Input:-----\n- First line will contain $T$, number of testcases. Then the testcases follow. \n- Each testcase contains a single line of input, a string $ s $. The string consists only of $0's$ and $1's$.\n\n-----Output:-----\nFor each testcase, output \"YES\" or \"NO\" depending on the input.\n\n-----Constraints-----\n- \n$1 \\leq T \\leq 10000$\n- \n$1 \\leq length of each string \\leq 10000$\n- \n$ 1 \\leq Summation length \\leq 10^5$\n\n-----Sample Input:-----\n1\n100\n\n-----Sample Output:-----\nNO\n\n-----EXPLANATION:-----\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfor _ in range(int(input())):\n s=input()\n if len(s)<4:\n print(\"NO\")\n else:\n if s[-4:]==\"1000\":\n print(\"YES\")\n else:\n print(\"NO\")\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n100\\n', 'output': 'NO\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/ICM2006'}","problem_id":"vfc_3546","program":"```python\nfor _ in range(int(input())):\n s=input()\n if len(s)<4:\n print(\"NO\")\n else:\n if s[-4:]==\"1000\":\n print(\"YES\")\n else:\n print(\"NO\")\n```","inputs":"1\n100\n","output":"NO\n","actual_output":"NO\n","execution_success":true,"sample_index":772},{"source":"apps","task_type":"verifiable_code","in_source_id":"1178","prompt":"Solve the following coding problem using the programming language python:\n\nTonight, Chef would like to hold a party for his $N$ friends.\nAll friends are invited and they arrive at the party one by one in an arbitrary order. However, they have certain conditions \u2014 for each valid $i$, when the $i$-th friend arrives at the party and sees that at that point, strictly less than $A_i$ other people (excluding Chef) have joined the party, this friend leaves the party; otherwise, this friend joins the party.\nHelp Chef estimate how successful the party can be \u2014 find the maximum number of his friends who could join the party (for an optimal choice of the order of arrivals).\n\n-----Input-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The first line of each test case contains a single integer $N$.\n- The second line contains $N$ space-separated integers $A_1, A_2, \\ldots, A_N$.\n\n-----Output-----\nFor each test case, print a single line containing one integer \u2014 the maximum number of Chef's friends who could join the party.\n\n-----Constraints-----\n- $1 \\le T \\le 1,000$\n- $1 \\le N \\le 10^5$\n- the sum of $N$ over all test cases does not exceed $10^6$\n\n-----Example Input-----\n3\n2\n0 0\n6\n3 1 0 0 5 5\n3\n1 2 3\n\n-----Example Output-----\n2\n4\n0\n\n-----Explanation-----\nExample case 1: Chef has two friends. Both of them do not require anyone else to be at the party before they join, so they will both definitely join the party.\nExample case 2: At the beginning, friends $3$ and $4$ can arrive and join the party, since they do not require anyone else to be at the party before they join. After that, friend $2$ can arrive; this friend would see that there are two people at the party and therefore also join. Then, friend $1$ will also join, so in the end, there would be $4$ people attending the party.\nExample case 3: No one will attend the party because each of Chef's friends will find zero people at the party and leave, regardless of the order in which they arrive.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\ntest=int(input())\nfor _ in range(test):\n n=int(input())\n ls=list(map(int,input().split()))\n ls.sort()\n s=0\n for i in range(n):\n if s>=ls[i]:\n s=s+1\n else:\n break\n print(s)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\n2\\n0 0\\n6\\n3 1 0 0 5 5\\n3\\n1 2 3\\n', 'output': '2\\n4\\n0\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/CHFPARTY'}","problem_id":"vfc_3554","program":"```python\ntest=int(input())\nfor _ in range(test):\n n=int(input())\n ls=list(map(int,input().split()))\n ls.sort()\n s=0\n for i in range(n):\n if s>=ls[i]:\n s=s+1\n else:\n break\n print(s)\n```","inputs":"3\n2\n0 0\n6\n3 1 0 0 5 5\n3\n1 2 3\n","output":"2\n4\n0\n","actual_output":"2\n4\n0\n","execution_success":true,"sample_index":774},{"source":"apps","task_type":"verifiable_code","in_source_id":"1179","prompt":"Solve the following coding problem using the programming language python:\n\nYou are given a positive integer $N$. Consider the sequence $S = (1, 2, \\ldots, N)$. You should choose two elements of this sequence and swap them.\nA swap is nice if there is an integer $M$ ($1 \\le M < N$) such that the sum of the first $M$ elements of the resulting sequence is equal to the sum of its last $N-M$ elements. Find the number of nice swaps.\n\n-----Input-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The first and only line of each test case contains a single integer $N$.\n\n-----Output-----\nFor each test case, print a single line containing one integer \u2015 the number of nice swaps.\n\n-----Constraints-----\n- $1 \\le T \\le 10^6$\n- $1 \\le N \\le 10^9$\n\n-----Subtasks-----\nSubtask #1 (10 points):\n- $T \\le 10$\n- $N \\le 10^3$\nSubtask #2 (30 points):\n- $T \\le 10$\n- $N \\le 10^6$\nSubtask #3 (60 points): original constraints\n\n-----Example Input-----\n5\n1\n2\n3\n4\n7\n\n-----Example Output-----\n0\n0\n2\n2\n3\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\nfrom math import sqrt\nfor _ in range(int(input())):\n n=int(input())\n sum=(n*(n+1))//2\n #print(sum)\n if(sum%2!=0):\n print(0)\n continue\n m=(int((sqrt(1+4*(sum)))-1)//2)\n if(m*(m+1)//2==sum//2):\n print((((m-1)*m)//2)+n-m+((n-m-1)*(n-m))//2)\n else:\n print(n-m)\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '5\\n1\\n2\\n3\\n4\\n7\\n', 'output': '0\\n0\\n2\\n2\\n3\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/CHFNSWAP'}","problem_id":"vfc_3558","program":"```python\n# cook your dish here\nfrom math import sqrt\nfor _ in range(int(input())):\n n=int(input())\n sum=(n*(n+1))//2\n #print(sum)\n if(sum%2!=0):\n print(0)\n continue\n m=(int((sqrt(1+4*(sum)))-1)//2)\n if(m*(m+1)//2==sum//2):\n print((((m-1)*m)//2)+n-m+((n-m-1)*(n-m))//2)\n else:\n print(n-m)\n\n```","inputs":"5\n1\n2\n3\n4\n7\n","output":"0\n0\n2\n2\n3\n","actual_output":"0\n0\n2\n2\n3\n","execution_success":true,"sample_index":775},{"source":"apps","task_type":"verifiable_code","in_source_id":"1180","prompt":"Solve the following coding problem using the programming language python:\n\nYou are playing a Billiards-like game on an $N \\times N$ table, which has its four corners at the points $\\{(0, 0), (0, N), (N, 0),$ and $(N, N)\\}$. You start from a coordinate $(x,y)$, $(0 < x < N, 0 < y < N)$ and shoot the ball at an angle $45^{\\circ}$ with the horizontal. On hitting the sides, the ball continues to move with the same velocity and ensuring that the angle of incidence is equal to the angle of reflection with the normal, i.e, it is reflected with zero frictional loss. On hitting either of the four corners, the ball stops there and doesn\u2019t move any further. \nFind the coordinates of the point of collision, when the ball hits the sides for the $K^{th}$ time. If the ball stops before hitting the sides $K$ times, find the coordinates of the corner point where the ball stopped instead.\n\n-----Input:-----\n- The first line of the input contains an integer $T$, the number of testcases.\n- Each testcase contains a single line of input, which has four space separated integers - $N$, $K$, $x$, $y$, denoting the size of the board, the number of collisions to report the answer for, and the starting coordinates.\n\n-----Output:-----\nFor each testcase, print the coordinates of the ball when it hits the sides for the $K^{th}$ time, or the coordinates of the corner point if it stopped earlier.\n\n-----Constraints-----\n- $1 \\leq T \\leq 10^5$\n- $2 \\leq N \\leq 10^9$\n- $1 \\leq K \\leq 10^9$\n\n-----Subtasks-----\n- $30$ points : Sum of $K$ over all test cases $\\le 10^7$\n- $70$ points : Original constraints.\n\n-----Sample Input:-----\n2\n5 5 4 4\n5 2 3 1\n\n-----Sample Output:-----\n5 5\n3 5\n\n-----Explanation:-----\n- Sample Case $1$ : \nWe are given a $5$ by $5$ board. We shoot the ball from coordinates $(4,4)$, and we need to find its coordinates after it has collided with sides $5$ times. However, after shooting, the ball goes directly to the corner $(5,5)$, and stops there. So we report the coordinates $(5,5)$.\n\n- Sample Case $2$ : \nWe are given a $5$ by $5$ board. We shoot the ball from the coordinates $(3,1)$, and we need to find its coordinates after it has collided with the sides twice. After shooting, it first hits the right side at $(5,3)$, and then the top side at $(3,5)$. So, we report $(3,5)$.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\nt=int(input())\nfor i in range(t):\n a=0\n b=0\n N,K,x,y=map(int,input().split())\n if x==y:\n a=N\n b=N\n elif x>y:\n if K%4==1:\n a=N \n b=y-x+N\n elif K%4==2:\n a=y-x+N\n b=N\n elif K%4==3:\n a=0\n b=x-y\n else:\n a=x-y\n b=0\n else:\n if K%4==1:\n a=x-y+N \n b=N\n elif K%4==2:\n a=N\n b=x-y+N\n elif K%4==3:\n a=y-x\n b=0\n else:\n a=0\n b=y-x\n print(a,b)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n5 5 4 4\\n5 2 3 1\\n', 'output': '5 5\\n3 5\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/BILLRD'}","problem_id":"vfc_3562","program":"```python\n# cook your dish here\nt=int(input())\nfor i in range(t):\n a=0\n b=0\n N,K,x,y=map(int,input().split())\n if x==y:\n a=N\n b=N\n elif x>y:\n if K%4==1:\n a=N \n b=y-x+N\n elif K%4==2:\n a=y-x+N\n b=N\n elif K%4==3:\n a=0\n b=x-y\n else:\n a=x-y\n b=0\n else:\n if K%4==1:\n a=x-y+N \n b=N\n elif K%4==2:\n a=N\n b=x-y+N\n elif K%4==3:\n a=y-x\n b=0\n else:\n a=0\n b=y-x\n print(a,b)\n```","inputs":"2\n5 5 4 4\n5 2 3 1\n","output":"5 5\n3 5\n","actual_output":"5 5\n3 5\n","execution_success":true,"sample_index":776},{"source":"apps","task_type":"verifiable_code","in_source_id":"1181","prompt":"Solve the following coding problem using the programming language python:\n\nChef has a natural number N. Cheffina challenges chef to check whether the given number is divisible by the sum of its digits or not. If the given number is divisible then print \"Yes\" else \"No\".\n\n-----Input:-----\n- First-line will contain $T$, the number of test cases. Then the test cases follow. \n- Each test case contains a single line of input, $N$. \n\n-----Output:-----\nFor each test case, output in a single line answer.\n\n-----Constraints-----\n- $1 \\leq T \\leq 10^6$\n- $1 \\leq N \\leq 10^6$\n\n-----Sample Input:-----\n2\n16\n27\n\n-----Sample Output:-----\nNo\nYes\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nimport sys,io,os,math\nfrom math import ceil,log,gcd,inf\nfrom itertools import permutations\nmod=1000000007\nmod1=998244353\ndef printlist(n):\n sys.stdout.write(\" \".join(map(str,n)) + \"\\n\")\nprintf=lambda n:sys.stdout.write(str(n)+\"\\n\")\ndef printns(n):\n sys.stdout.write(str(n)) \ndef intinp():\n return int(sys.stdin.readline())\ndef strinp():\n return sys.stdin.readline()\ndef arrinp():\n return list(map(int,sys.stdin.readline().strip().split()))\ndef mulinp():\n return list(map(int,sys.stdin.readline().strip().split()))\ndef flush():\n return sys.stdout.flush()\ndef power_two(x):\n return (1<countOccurences(3,3)->countOccurences(3,4)->countOccurences(3,5)\n->countOccurences(3,6)->countOccurences(3,7)->countOccurences(3,8)\n->countOccurences(3,9)->countOccurences(3,10).\n\n\nWhen the countOccurences(3,10) is called, it will return 0. Total 9 function calls.\n\nFor the second query, the brute force will do the same as above.\n\nBut the DP will check whether solution for countOccurences(3,4) is available or not.\n\nAs it was calculated while solving the first query, it won\u2019t solve it again and will directly give the answer. \n\nTotal 1 function calls.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfor __ in range(eval(input())):\n x = eval(input())\n a = list(map(int,input().split()))\n key = eval(input())\n query = eval(input())\n maxvisited = x #maximum visted value\n j = x-1\n ans = []\n val = 0\n while j>=0:\n if a[j]==key:\n ans.append(val+1)\n val = val +1\n else: ans.append(val)\n j-=1\n ans.reverse()\n #print ans\n for ii in range(query):\n W = eval(input())\n print(ans[W], end=' ')\n print(x-W, end=' ')\n #print maxvisited, W\n if maxvisited>W:\n print(maxvisited-W+1)\n maxvisited = W\n else: print('1')\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n10\\n1 2 3 1 2 3 1 2 3 1\\n3\\n5\\n2\\n4\\n6\\n8\\n2\\n\\n', 'output': '3 8 9\\n2 6 1\\n1 4 1\\n1 2 1\\n3 8 1\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/AIPC2015/problems/AN01'}","problem_id":"vfc_3574","program":"```python\nfor __ in range(eval(input())):\n x = eval(input())\n a = list(map(int,input().split()))\n key = eval(input())\n query = eval(input())\n maxvisited = x #maximum visted value\n j = x-1\n ans = []\n val = 0\n while j>=0:\n if a[j]==key:\n ans.append(val+1)\n val = val +1\n else: ans.append(val)\n j-=1\n ans.reverse()\n #print ans\n for ii in range(query):\n W = eval(input())\n print(ans[W], end=' ')\n print(x-W, end=' ')\n #print maxvisited, W\n if maxvisited>W:\n print(maxvisited-W+1)\n maxvisited = W\n else: print('1')\n\n```","inputs":"1\n10\n1 2 3 1 2 3 1 2 3 1\n3\n5\n2\n4\n6\n8\n2\n\n","output":"3 8 9\n2 6 1\n1 4 1\n1 2 1\n3 8 1\n","actual_output":"3 8 9\n2 6 1\n1 4 1\n1 2 1\n3 8 1\n","execution_success":true,"sample_index":779},{"source":"apps","task_type":"verifiable_code","in_source_id":"1184","prompt":"Solve the following coding problem using the programming language python:\n\nChef's friend Alex runs a movie theatre. Due to the increasing number of platforms for watching movies online, his business is not running well. As a friend, Alex asked Chef to help him maximise his profits. Since Chef is a busy person, he needs your help to support his friend Alex. \nAlex's theatre has four showtimes: 12 PM, 3 PM, 6 PM and 9 PM. He has four movies which he would like to play \u2015 let's call them A, B, C and D. Each of these movies must be played exactly once and all four must be played at different showtimes. For each showtime, the price of a ticket must be one of the following: Rs 25, Rs 50, Rs 75 or Rs 100. The prices of tickets for different showtimes must also be different.\nThrough his app, Alex receives various requests from his customers. Each request has the form \"I want to watch this movie at this showtime\". Let's assume that the number of people who come to watch a movie at a given showtime is the same as the number of requests for that movie at that showtime.\nIt is not necessary to accommodate everyone's requests \u2015 Alex just wants to earn the maximum amount of money. There is no restriction on the capacity of the theatre. However, for each movie that is not watched by anyone, Alex would suffer a loss of Rs 100 (deducted from the profit).\nYou are given $N$ requests Alex received during one day. Find the maximum amount of money he can earn on that day by choosing when to play which movies and with which prices. \n\n-----Input-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The first line of each test case contains a single integer $N$.\n- $N$ lines follow. Each of these lines contains a character $m$, followed by a space and an integer $t$, describing a request to see the movie $m$ at the showtime $t$.\n\n-----Output-----\nFor each test case, print a single line containing one integer \u2015 the maximum profit Alex can earn (possibly negative).\nFinally, print a line containing one integer \u2015 the total profit over all test cases, i.e. over $T$ days.\n\n-----Constraints-----\n- $1 \\le T \\le 150$\n- $0 \\le N \\le 100$\n- $m$ is 'A', 'B', 'C' or 'D'\n- $t$ is $12$, $3$, $6$ or $9$\n\n-----Subtasks-----\nSubtask #1 (30 points): it is possible to fulfill all requests\nSubtask #2 (70 points): original constraints\n\n-----Example Input-----\n5\n12\nA 3\nB 12\nC 6\nA 9\nB 12\nC 12\nD 3\nB 9\nD 3\nB 12\nB 9\nC 6\n7\nA 9\nA 9\nB 6\nC 3\nD 12\nA 9\nB 6\n2\nA 9\nB 6\n1\nD 12\n0 \n\n-----Example Output-----\n575\n525\n-25 \n-200 \n-400\n475\n\n-----Explanation-----\nExample case 1: The following table shows the number of people that want to watch the movies at the given showtimes: 12 3 6 9 A 0 1 0 1 B 3 0 0 2 C 1 0 2 0 D 0 2 0 0 \nThe maximum number of requests was sent for movie B at 12 PM. Therefore, we play this movie at this time and the tickets cost Rs 100. Next, we play movie D at 3 PM with ticket price Rs 75 and movie C at 6 PM with ticket price Rs 50. Finally, we have a slot for 9 PM and the only movie we can play at that time now is movie A, with ticket price Rs 25. The total profit is $3 \\cdot 100 + 2 \\cdot 75 + 2 \\cdot 50 + 1 \\cdot 25 = 300 + 150 + 100 + 25 = 575$. Since each movie was watched by at least one person, there is no additional loss.\nExample case 2: Just like above, we show the requests in a table: 12 3 6 9 A 0 0 0 3 B 0 0 2 0 C 0 1 0 0 D 1 0 0 0 \nThe optimal solution is to play movie A at 9 PM, movie B at 6 PM, movie C at 3 PM and movie D at 12 PM, with decreasing ticket prices in this order. The profit is $3 \\cdot 100 + 2 \\cdot 75 + 1 \\cdot 50 + 1 \\cdot 25 = 300+150+50+25 = 525$.\nExample case 3: Again, we show the requests in a table: 12 3 6 9 A 0 0 0 1 B 0 0 1 0 C 0 0 0 0 D 0 0 0 0 \nThe optimal solution is to play movie A at 9 PM with ticket price Rs 100, movie B at 6 PM with ticket price Rs 75 and the remaining two movies in any order at 12 PM and 3 PM \u2015 either way, there will be nobody watching them. We earn $1 \\cdot 100 + 1 \\cdot 75 = 175$, but we have to deduct Rs 200, so the resulting profit is $175 - 200 = -25$.\nExample case 4: The optimal solution is to play movie D at 12 PM; the other three movies go unattended. We have to deduct Rs 300, so the profit is $1 \\cdot 100 - 300 = -200$.\nExample case 5: Since there are no requests for any movie at any time, all movies go unattended and Alex just suffers a loss of Rs 400.\nThe total profit for all 5 days is $575+525-25-200-400 = 475$.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfrom itertools import permutations\nC = list(permutations(['A','B','C','D']))\nV = list(permutations([3,6,9,12]))\nP = list(permutations([25,50,75,100]))\nR = []\n\ndef test():\n d = {}\n n = int(input())\n for i in C[0]:\n for j in V[0]:\n d[i+str(j)] = 0\n for i in range(n):\n x,y = input().split()\n d[x+y] += 1\n ans = -1000000000\n for i in C:\n for j in V:\n for k in P:\n c = 0\n for l in range(4): \n if d[i[l]+str(j[l])] == 0:\n c -= 100\n else:\n c += (d[i[l]+str(j[l])]*k[l])\n ans = max(ans,c)\n R.append(ans)\n print(ans)\n\ndef __starting_point():\n t = int(input())\n for i in range(t):\n test()\n print(sum(R))\n\n__starting_point()\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '5\\n12\\nA 3\\nB 12\\nC 6\\nA 9\\nB 12\\nC 12\\nD 3\\nB 9\\nD 3\\nB 12\\nB 9\\nC 6\\n7\\nA 9\\nA 9\\nB 6\\nC 3\\nD 12\\nA 9\\nB 6\\n2\\nA 9\\nB 6\\n1\\nD 12\\n0\\n', 'output': '575\\n525\\n-25\\n-200\\n-400\\n475\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/THEATRE'}","problem_id":"vfc_3578","program":"```python\nfrom itertools import permutations\nC = list(permutations(['A','B','C','D']))\nV = list(permutations([3,6,9,12]))\nP = list(permutations([25,50,75,100]))\nR = []\n\ndef test():\n d = {}\n n = int(input())\n for i in C[0]:\n for j in V[0]:\n d[i+str(j)] = 0\n for i in range(n):\n x,y = input().split()\n d[x+y] += 1\n ans = -1000000000\n for i in C:\n for j in V:\n for k in P:\n c = 0\n for l in range(4): \n if d[i[l]+str(j[l])] == 0:\n c -= 100\n else:\n c += (d[i[l]+str(j[l])]*k[l])\n ans = max(ans,c)\n R.append(ans)\n print(ans)\n\ndef __starting_point():\n t = int(input())\n for i in range(t):\n test()\n print(sum(R))\n\n__starting_point()\n```","inputs":"5\n12\nA 3\nB 12\nC 6\nA 9\nB 12\nC 12\nD 3\nB 9\nD 3\nB 12\nB 9\nC 6\n7\nA 9\nA 9\nB 6\nC 3\nD 12\nA 9\nB 6\n2\nA 9\nB 6\n1\nD 12\n0\n","output":"575\n525\n-25\n-200\n-400\n475\n","actual_output":"575\n525\n-25\n-200\n-400\n475\n","execution_success":true,"sample_index":780},{"source":"apps","task_type":"verifiable_code","in_source_id":"1185","prompt":"Solve the following coding problem using the programming language python:\n\nTaru likes reading. Every month he gets a copy of the magazine \"BIT\". The magazine contains information about the latest advancements in technology. Taru \n\nreads the book at night and writes the page number to which he has read on a piece of paper so that he can continue from there the next day. But sometimes \n\nthe page number is not printed or is so dull that it is unreadable. To make matters worse Taru's brother who is really naughty tears of some of the pages of \n\nthe Magazine and throws them in the dustbin. He remembers the number of leaves he had torn but he does not remember which page numbers got removed. When Taru \n\nfinds this out he is furious and wants to beat him up. His brother apologizes, and says he won't ever do this again. But Taru did not want to be easy on him \n\nand he says \"I will leave you only if you help me find the answer to this. I will tell you how many pages (Printed sides) were there in the Magazine plus the \n\npages on which the page numbers were not printed. You already know the number of leaves you tore (T). Can you tell me the expected sum of the page numbers \n\nleft in the Magazine?\" Taru's brother replied \"huh!! This is a coding problem\". Please help Taru's brother.\n\nNote: The magazine is like a standard book with all odd page numbers in front and the successive even page number on its back. If the book contains 6 pages, \n\nPage number 1 and Page number 2 are front and back respectively. Tearing a leaf removes both the front and back page numbers.\n\n\n-----Input-----\nThe first line contains the number of test cases t. 3t lines follow. The first line of each test case contains the number of pages (printed sides) in the \n\nbook. The second line's first integer is F, F integers follow which tell us the numbers of the page numbers not printed. The third line contains a single integer telling us the number of leaves Taru's brother tore.\n\n-----Output-----\nOutput one real number correct up to 4 decimal digits which is equal to the expected sum of the page numbers left in the book.\n\n-----Constraints-----\n\nNumber of printed Sides<=2000. All other values abide by the number of printed sides.\n\n-----Example-----\nInput:\n2\n10\n2 1 2\n2\n10\n1 8\n0\n\nOutput:\n31.2000\n47.0000\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nimport sys\n\nrl=sys.stdin.readline\nT=int(rl())\nfor t in range(T):\n P=int(rl())\n T=(P+1)//2\n F=list(map(int,rl().split()))[1:]\n numtorn=int(rl())\n t=sum(range(1,P+1))-sum(F)\n K=T-numtorn\n print('%.4f' % (t*K/float(T)))\n \n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n10\\n2 1 2\\n2\\n10\\n1 8\\n0\\n', 'output': '31.2000\\n47.0000\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/SEPT11/problems/TRMAG'}","problem_id":"vfc_3582","program":"```python\nimport sys\n\nrl=sys.stdin.readline\nT=int(rl())\nfor t in range(T):\n P=int(rl())\n T=(P+1)//2\n F=list(map(int,rl().split()))[1:]\n numtorn=int(rl())\n t=sum(range(1,P+1))-sum(F)\n K=T-numtorn\n print('%.4f' % (t*K/float(T)))\n \n\n```","inputs":"2\n10\n2 1 2\n2\n10\n1 8\n0\n","output":"31.2000\n47.0000\n","actual_output":"31.2000\n47.0000\n","execution_success":true,"sample_index":781},{"source":"apps","task_type":"verifiable_code","in_source_id":"1186","prompt":"Solve the following coding problem using the programming language python:\n\nBhallaladeva was an evil king who ruled the kingdom of Maahishmati. He wanted to erect a 100ft golden statue of himself and he looted gold from several places for this. He even looted his own people, by using the following unfair strategy:\nThere are N houses in Maahishmati, and the ith house has Ai gold plates. Each gold plate costs exactly 1 Nimbda, which is the unit of currency in the kingdom of Maahishmati. Bhallaladeva would choose an integer K, and loots all the houses in several steps. In each step:\n\n- He would choose a house i which hasn't been looted yet, pay the owner exactly Ai Nimbdas, and take away all the gold plates in that house (Hence, he also ends up looting this house).\n- He would now choose atmost K houses which haven't been looted yet and take away all the gold plates from these houses without paying a single Nimbda (Yes, he takes all of them for free).\n\nHe repeats the above steps until all the N houses have been looted. Your task is to devise a strategy for Bhallaladeva to loot the houses in some order, so that the number of nimbdas he has to pay is minimium. You'll also be given multiple values of K (Q of them to be precise), and you need to find the minimum number of nimbdas for each of these values.\n\n-----Input-----\nThe first line of input consists of a single integer N denoting the number of houses in Maahishmati. The second line of input consists of N space separated integers denoting A1, A2, ..., AN, where Ai denotes the number of gold plates in the ith house. The third line of input consists of a single integer Q denoting the number of values of K to follow. Each of the following Q lines consist of a single integer, where the value on the ith line denotes the value of K for the ith query.\n\n-----Output-----\nOutput exactly Q integers on separate lines, where the output on the ith line denotes the answer for the ith value of K.\n\n-----Constraints-----\n- 1 \u2264 N \u2264 105\n- 1 \u2264 Q \u2264 105\n- 0 \u2264 K \u2264 N-1\n- 1 \u2264 Ai \u2264 104\n\n-----Example-----\nInput:\n4\n3 2 1 4\n2\n0\n2\n\nOutput:\n10\n3\n\n-----Explanation-----\nFor the first query, K = 0. Hence, Bhallaladeva cannot take gold plates from any of the houses for free. It will cost him 3 + 2 + 1 + 4 = 10 nimbdas.\nFor the second query, K = 2. In the first step Bhallaladeva can pay 2 nimbdas for gold plates in house number 2, and take the gold in houses 1 and 4 for free (Note that house 1 has 3 gold plates and house 4 has 4 gold plates). Now, he has looted houses 1, 2 & 4. Now in the second step, he loots house 3, by paying 1 nimbda. Hence, the total cost = 1 + 2 = 3. Note that there might be multiple ways to achieve the minimum cost, and we have explained only one of them.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nimport math\nn = int(input())\na = sorted(map(int,input().split()))\nl = [0]*n\nfor i in range(n):\n l[i] = a[i] + l[i-1]\nfor q in range(int(input())):\n print(l[int(math.ceil(float(n)/(int(input())+1)))-1])\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '4\\n3 2 1 4\\n2\\n0\\n2\\n', 'output': '10\\n3\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/AMR15ROL/problems/AMR15D'}","problem_id":"vfc_3586","program":"```python\nimport math\nn = int(input())\na = sorted(map(int,input().split()))\nl = [0]*n\nfor i in range(n):\n l[i] = a[i] + l[i-1]\nfor q in range(int(input())):\n print(l[int(math.ceil(float(n)/(int(input())+1)))-1])\n```","inputs":"4\n3 2 1 4\n2\n0\n2\n","output":"10\n3\n","actual_output":"10\n3\n","execution_success":true,"sample_index":782},{"source":"apps","task_type":"verifiable_code","in_source_id":"1187","prompt":"Solve the following coding problem using the programming language python:\n\nChef wants to select a subset $S$ of the set $\\{1, 2, \\ldots, N\\}$ such that there are no two integers $x, y \\in S$ which satisfy $\\frac{x}{y} = M$.\nHelp Chef find the maximum size of a subset $S$ he can choose and the number of ways in which he can choose a subset $S$ with this maximum size. Since the number of ways to choose $S$ can be very large, calculate it modulo $998,244,353$.\n\n-----Input-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The first and only line of each test case contains two space-separated integers $N$ and $M$.\n\n-----Output-----\nFor each test case, print a single line containing two space-separated integers \u2015 the maximum size of a subset Chef can choose and the number of ways to choose a subset with this maximum size modulo $998,244,353$. Note that only the number of ways to choose a subset should be printed modulo $998,244,353$.\n\n-----Constraints-----\n- $1 \\le T \\le 10,000$\n- $2 \\le M \\le N \\le 10^{18}$\n\n-----Example Input-----\n3\n5 2\n10 2\n100 3\n\n-----Example Output-----\n4 1\n6 12\n76 49152\n\n-----Explanation-----\nExample case 1: The only subset $S$ with the maximum size which Chef can choose is $\\{1, 3, 4, 5\\}$.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfor _ in range(int(input())):\n N,M = list(map(int,input().split()))\n count,e,perm = 0,0,1\n while(True):\n lim,start = N//(M**e),N//(M**(e + 1)) + 1\n num = lim - start + 1\n divs = num//M\n if((start + divs*M) <= lim):\n r = (start+divs*M)%M\n if(r == 0 or (r + (lim - (start + divs*M)) >= M)):\n divs += 1\n cmon = num - divs\n if(e % 2 == 0):\n count += cmon*((e+2)//2)\n else:\n count += cmon*(e//2 + 1)\n perm = (perm * pow((e + 3)//2,cmon ,998244353))%998244353\n e += 1\n if(start == 1):\n break\n print(count,perm)\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\n5 2\\n10 2\\n100 3\\n', 'output': '4 1\\n6 12\\n76 49152\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/BANQUNT'}","problem_id":"vfc_3590","program":"```python\nfor _ in range(int(input())):\n N,M = list(map(int,input().split()))\n count,e,perm = 0,0,1\n while(True):\n lim,start = N//(M**e),N//(M**(e + 1)) + 1\n num = lim - start + 1\n divs = num//M\n if((start + divs*M) <= lim):\n r = (start+divs*M)%M\n if(r == 0 or (r + (lim - (start + divs*M)) >= M)):\n divs += 1\n cmon = num - divs\n if(e % 2 == 0):\n count += cmon*((e+2)//2)\n else:\n count += cmon*(e//2 + 1)\n perm = (perm * pow((e + 3)//2,cmon ,998244353))%998244353\n e += 1\n if(start == 1):\n break\n print(count,perm)\n\n```","inputs":"3\n5 2\n10 2\n100 3\n","output":"4 1\n6 12\n76 49152\n","actual_output":"4 1\n6 12\n76 49152\n","execution_success":true,"sample_index":783},{"source":"apps","task_type":"verifiable_code","in_source_id":"1188","prompt":"Solve the following coding problem using the programming language python:\n\nChef is a private detective. He was asked to investigate a case of murder in the city of Frangton.\nChef arrived in Frangton to find out that the mafia was involved in the case. Chef spent some time watching for people that belong to the clan and was able to build a map of relationships between them. He knows that a mafia's organizational structure consists of a single Don, heading a hierarchical criminal organization. Each member reports exactly to one other member of the clan. It's obvious that there are no cycles in the reporting system of the mafia.\nThere are N people in the clan, for simplicity indexed from 1 to N, and Chef knows who each of them report to. Member i reports to member Ri.\nNow, Chef needs to identfy all potential killers to continue his investigation. Having considerable knowledge about the mafia's activities, Chef knows that the killer must be a minor criminal, that is, one of the members who nobody reports to. Please find the list of potential killers for Chef. Since Don reports to nobody, his Ri will be equal to 0.\n\n-----Input-----\nThe first line of input contains one integer N.\nNext line has N space-separated integers, the ith integer denotes Ri \u2014 the person whom the ith member reports to.\n\n-----Output-----\nOutput a list of space-separated integers in ascending order \u2014 the indices of potential killers.\n\n-----Constraints-----\n- 1 \u2264 N \u2264 105\n- 1 \u2264 Ri \u2264 N except for Don, whose Ri equals to 0.\n- It is guaranteed that there are no cycles in the reporting structure.\n\n-----Subtasks-----\n- Subtask #1 [50 points]: N \u2264 10000\n- Subtask #2 [50 points]: No additional constraints\n\n-----Example-----\nInput:\n6\n0 1 1 2 2 3\n\nOutput:\n4 5 6\n\n-----Explanation-----\nThe reporting structure:\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nn = eval(input())\nr = list(map(int, input().split()))\n\ntree = dict()\ni = 1\nfor j in r:\n c = tree.get(j)\n if c:\n tree[j].append(i)\n else:\n tree[j] = [i]\n if not tree.get(i):\n tree[i] = []\n i += 1\ns = []\nfor elem in tree:\n if not tree[elem]:\n s.append(str(elem))\nprint(' '.join(s))\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '6\\n0 1 1 2 2 3\\n', 'output': '4 5 6\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/FEB16/problems/CHEFDETE'}","problem_id":"vfc_3594","program":"```python\nn = eval(input())\nr = list(map(int, input().split()))\n\ntree = dict()\ni = 1\nfor j in r:\n c = tree.get(j)\n if c:\n tree[j].append(i)\n else:\n tree[j] = [i]\n if not tree.get(i):\n tree[i] = []\n i += 1\ns = []\nfor elem in tree:\n if not tree[elem]:\n s.append(str(elem))\nprint(' '.join(s))\n```","inputs":"6\n0 1 1 2 2 3\n","output":"4 5 6\n","actual_output":"4 5 6\n","execution_success":true,"sample_index":784},{"source":"apps","task_type":"verifiable_code","in_source_id":"1189","prompt":"Solve the following coding problem using the programming language python:\n\nYou are given a sequence $A_1, A_2, \\ldots, A_N$. For each $k$ ($1 \\le k \\le N$), let's define a function $f(k)$ in the following way:\n- Consider a sequence $B_1, B_2, \\ldots, B_N$, which is created by setting $A_k = 0$. Formally, $B_k = 0$ and $B_i = A_i$ for each valid $i \\neq k$.\n- $f(k)$ is the number of ways to split the sequence $B$ into two non-empty contiguous subsequences with equal sums.\nFind the sum $S = f(1) + f(2) + \\ldots + f(N)$.\n\n-----Input-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The first line of each test case contains a single integer $N$.\n- The second line contains $N$ space-separated integers $A_1, A_2, \\ldots, A_N$.\n\n-----Output-----\nFor each test case, print a single line containing one integer \u2014 the sum $S$.\n\n-----Constraints-----\n- $1 \\le T \\le 10$\n- $2 \\le N \\le 2 \\cdot 10^5$\n- $1 \\le |A_i| \\le 10^9$ for each valid $i$\n\n-----Example Input-----\n2\n6\n1 2 1 1 3 1\n3\n4 1 4\n\n-----Example Output-----\n6\n2\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfrom sys import stdin\ndef gt(num):\n if num:\n return num\n return 0\nfor __ in range(int(stdin.readline().split()[0])):\n n = int(stdin.readline().split()[0])\n a = list(map(int, stdin.readline().split()))\n cnta = dict()\n cnta.setdefault(0)\n cntb = dict()\n cntb.setdefault(0)\n for i in a:\n cnta[i] = gt(cnta.get(i)) + 1\n asum = 0\n bsum = sum(a)\n ans = 0\n for i in range(n-1):\n asum += a[i]\n bsum -= a[i]\n cnta[a[i]] = gt(cnta.get(a[i])) - 1\n cntb[a[i]] = gt(cntb.get(a[i])) + 1\n ans += gt(cnta.get(bsum-asum))\n ans += gt(cntb.get(asum-bsum))\n print(ans)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n6\\n1 2 1 1 3 1\\n3\\n4 1 4\\n', 'output': '6\\n2\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/CFINASUM'}","problem_id":"vfc_3598","program":"```python\nfrom sys import stdin\ndef gt(num):\n if num:\n return num\n return 0\nfor __ in range(int(stdin.readline().split()[0])):\n n = int(stdin.readline().split()[0])\n a = list(map(int, stdin.readline().split()))\n cnta = dict()\n cnta.setdefault(0)\n cntb = dict()\n cntb.setdefault(0)\n for i in a:\n cnta[i] = gt(cnta.get(i)) + 1\n asum = 0\n bsum = sum(a)\n ans = 0\n for i in range(n-1):\n asum += a[i]\n bsum -= a[i]\n cnta[a[i]] = gt(cnta.get(a[i])) - 1\n cntb[a[i]] = gt(cntb.get(a[i])) + 1\n ans += gt(cnta.get(bsum-asum))\n ans += gt(cntb.get(asum-bsum))\n print(ans)\n```","inputs":"2\n6\n1 2 1 1 3 1\n3\n4 1 4\n","output":"6\n2\n","actual_output":"6\n2\n","execution_success":true,"sample_index":785},{"source":"apps","task_type":"verifiable_code","in_source_id":"1190","prompt":"Solve the following coding problem using the programming language python:\n\nTomya is a girl. She loves Chef Ciel very much.\n\nTomya like a positive integer p, and now she wants to get a receipt of Ciel's restaurant whose total price is exactly p.\nThe current menus of Ciel's restaurant are shown the following table.\nName of Menupriceeel flavored water1deep-fried eel bones2clear soup made with eel livers4grilled eel livers served with grated radish8savory egg custard with eel16eel fried rice (S)32eel fried rice (L)64grilled eel wrapped in cooked egg128eel curry rice256grilled eel over rice512deluxe grilled eel over rice1024eel full-course2048\n\nNote that the i-th menu has the price 2i-1 (1 \u2264 i \u2264 12).\n\nSince Tomya is a pretty girl, she cannot eat a lot.\nSo please find the minimum number of menus whose total price is exactly p.\nNote that if she orders the same menu twice, then it is considered as two menus are ordered. (See Explanations for details)\n\n-----Input-----\n\nThe first line contains an integer T, the number of test cases.\nThen T test cases follow.\nEach test case contains an integer p.\n\n-----Output-----\n\nFor each test case, print the minimum number of menus whose total price is exactly p.\n\n-----Constraints-----\n\n1 \u2264 T \u2264 5\n\n1 \u2264 p \u2264 100000 (105)\n\nThere exists combinations of menus whose total price is exactly p.\n\n-----Sample Input-----\n4\n10\n256\n255\n4096\n\n-----Sample Output-----\n2\n1\n8\n2\n\n-----Explanations-----\n\nIn the first sample, examples of the menus whose total price is 10 are the following:\n\n1+1+1+1+1+1+1+1+1+1 = 10 (10 menus)\n\n1+1+1+1+1+1+1+1+2 = 10 (9 menus)\n\n2+2+2+2+2 = 10 (5 menus)\n\n2+4+4 = 10 (3 menus)\n\n2+8 = 10 (2 menus)\n\nHere the minimum number of menus is 2.\n\nIn the last sample, the optimal way is 2048+2048=4096 (2 menus).\nNote that there is no menu whose price is 4096.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nt= int(input())\nwhile(t>0):\n n = int(input())\n m=0\n m=n//(2**11)\n n%=(2**11)\n while(n>0):\n num=n%2\n m+=num\n n//=2\n print(m)\n t-=1\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '4\\n10\\n256\\n255\\n4096\\n', 'output': '2\\n1\\n8\\n2\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/CIELRCPT'}","problem_id":"vfc_3602","program":"```python\nt= int(input())\nwhile(t>0):\n n = int(input())\n m=0\n m=n//(2**11)\n n%=(2**11)\n while(n>0):\n num=n%2\n m+=num\n n//=2\n print(m)\n t-=1\n```","inputs":"4\n10\n256\n255\n4096\n","output":"2\n1\n8\n2\n","actual_output":"2\n1\n8\n2\n","execution_success":true,"sample_index":786},{"source":"apps","task_type":"verifiable_code","in_source_id":"1191","prompt":"Solve the following coding problem using the programming language python:\n\nSandy is a professor at a very reputed institute. The institute mandates that all the lectures be communicated in English. As Sandy is not very good at English(or anything actually) the presentations he displays in class have a lot of spelling mistakes in them.\nAs you have a dictionary on you containing $N$ words in it, the responsibility of correctly deducing the misspelt word falls upon your shoulders. Sandy's presentation contains in them, $Q$ words which you $think$ are wrongly spelt. A word is misspelt if a $single$ letter in it is missing or is different from the corresponding correctly spelled word in your dictionary.\nFor each of the misspelt word in the presentation find out the corresponding correct word from your dictionary.\nNote : \n- For each misspelt word in Sandy's presentation, there exists one and only one correctly spelt word in your dictionary that corresponds to it. \n- Out of the $Q$ misspelt words given to you, there might be some which are correctly spelt i.e., that word completely matches a word in your dictionary. (Give Sandy some credit, he's a teacher after all). For such words print the word corresponding to it in your dictionary.\n- The maximum length of each string can be $L$.\n\n-----Input:-----\n- First line contains a single integer $T$ denoting the number of testcases. Then the testcases follow. \n- The first line of each test case contains two space-separated integers $N, Q$ corresponding to the number of words in your dictionary and the number of misspelt word in Sandy's dictionary respectively.\n- $N$ lines follow each containing a single string $S$ denoting a word in your dictionary.\n- $Q$ lines follow each containing a single string $M$ denoting a misspelt word in Sandy's presentation.\n\n-----Output:-----\nIn each testcase, for each of the $Q$ misspelt words, print a single word $S$ corresponding to the correctly spelt word in your dictionary.\n\n-----Constraints-----\n- $1 \\leq T \\leq 100$\n- $1 \\leq N \\leq 200$\n- $1 \\leq Q \\leq 200$\n- $1 \\leq L \\leq 100$\n- None of the words contain any spaces in them.\n- Each letter in every word is in lower case.\n\n-----Subtasks-----\n- \nSubtask 1 : 10 points\n- $1 \\leq N \\leq 50$\n- $1 \\leq Q \\leq 10$\n- \nSubtask 2 : 90 points\n- Original Constraints\n\n-----Sample Input:-----\n1\n5 2\nszhbdvrngk\nqzhxibnuec\njfsalpwfkospl\nlevjehdkjy\nwdfhzgatuh\nszhbdvcngk\nqzhxbnuec\n\n-----Sample Output:-----\nszhbdvrngk\nqzhxibnuec\n\n-----EXPLANATION:-----\n- In the first misspelt word $szhbdvcngk$, a single letter $c$ is different from the original word $szhbdvrngk$.\n- The second misspelt word $qzhxbnuec$ is missing the letter $i$ that was in the original word $qzhxibnuec$.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\nfrom difflib import get_close_matches \nimport sys, os\n\ndef closeMatches(patterns, word): \n return get_close_matches(word, patterns, 1, 0.9)[0]\n\ndef get_string(): \n return sys.stdin.readline().strip() \n\ndef get_ints(): \n return map(int, sys.stdin.readline().strip().split()) \nans = []\ntest = int(input())\nfor i in range(test):\n n,q = get_ints()\n #ans = []\n n = int(n)\n q = int(q)\n patterns=[]\n for j in range(n):\n s = get_string()\n patterns.append(s)\n for j in range(q):\n word = get_string()\n ans.append(closeMatches(patterns, word))\nfor j in ans:\n sys.stdout.write(j+\"\\n\") \n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n5 2\\nszhbdvrngk\\nqzhxibnuec\\njfsalpwfkospl\\nlevjehdkjy\\nwdfhzgatuh\\nszhbdvcngk\\nqzhxbnuec\\n', 'output': 'szhbdvrngk\\nqzhxibnuec\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/PROC2020/problems/ENGRIS'}","problem_id":"vfc_3606","program":"```python\n# cook your dish here\nfrom difflib import get_close_matches \nimport sys, os\n\ndef closeMatches(patterns, word): \n return get_close_matches(word, patterns, 1, 0.9)[0]\n\ndef get_string(): \n return sys.stdin.readline().strip() \n\ndef get_ints(): \n return map(int, sys.stdin.readline().strip().split()) \nans = []\ntest = int(input())\nfor i in range(test):\n n,q = get_ints()\n #ans = []\n n = int(n)\n q = int(q)\n patterns=[]\n for j in range(n):\n s = get_string()\n patterns.append(s)\n for j in range(q):\n word = get_string()\n ans.append(closeMatches(patterns, word))\nfor j in ans:\n sys.stdout.write(j+\"\\n\") \n```","inputs":"1\n5 2\nszhbdvrngk\nqzhxibnuec\njfsalpwfkospl\nlevjehdkjy\nwdfhzgatuh\nszhbdvcngk\nqzhxbnuec\n","output":"szhbdvrngk\nqzhxibnuec\n","actual_output":"szhbdvrngk\nqzhxibnuec\n","execution_success":true,"sample_index":787},{"source":"apps","task_type":"verifiable_code","in_source_id":"1192","prompt":"Solve the following coding problem using the programming language python:\n\nYou are given a sequence of integers $A_1, A_2, \\ldots, A_N$. This sequence is circular \u2015 for each valid $i$, the element $A_{i+1}$ follows after $A_i$, and the element $A_1$ follows after $A_N$.\nYou may insert any positive integers at any positions you choose in this sequence; let's denote the resulting sequence by $B$. This sequence is also circular. For each pair of its elements $B_s$ and $B_f$, let's denote the (non-circular) sequence created by starting at $B_s$ and moving from each element to the one that follows after it, until we reach $B_f$, by $B(s, f)$. This sequence includes the elements $B_s$ and $B_f$.\nFor each $K$ from $2$ to $N$ inclusive, find the smallest possible number of elements that need to be inserted into $A$ to form a sequence $B$ for which there is no subsequence $B(p, q)$ such that:\n- The size of $B(p, q)$ is at least $K$.\n- There is no pair of consecutive elements in $B(p, q)$ such that their GCD is equal to $1$.\n\n-----Input-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The first line of each test case contains a single integer $N$.\n- The second line contains $N$ space-separated integers $A_1, A_2, \\ldots, A_N$.\n\n-----Output-----\nFor each test case, print a single line containing $N-1$ space-separated integers. For each $i$ ($1 \\le i \\le N-1$), the $i$-th of these integers should be the smallest number of inserted elements in a valid sequence $B$ for $K = i+1$.\n\n-----Constraints-----\n- $1 \\le T \\le 2,000$\n- $2 \\le N \\le 10^5$\n- $1 \\le A_i \\le 10^9$ for each valid $i$\n- the sum of $N$ over all test cases does not exceed $2 \\cdot 10^6$\n\n-----Example Input-----\n1\n5\n3 6 4 5 9\n\n-----Example Output-----\n3 1 1 0\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfrom math import gcd\nfrom itertools import groupby\n\ndef gcd_split(seq):\n gcds= [int(gcd(a,b)==1) for a,b in zip(seq[1:],seq[:-1])]\n gcds.append(int(gcd(seq[0],seq[-1])==1))\n # print(gcds)\n if max(gcds)==0:\n return -1\n else:\n splits=[len(list(x))+1 for num,x in groupby(gcds) if num==0]\n # print(splits)\n if gcds[0]==gcds[-1]==0:\n splits[0] += splits[-1]-1\n splits = splits[:-1]\n return splits\n\nfor _ in range(int(input())):\n N=int(input())\n A=[int(x) for x in input().split()]\n split = gcd_split(A)\n # print(split)\n \n res=[]\n if split!=-1:\n for K in range(2,N+1):\n temp=(x for x in split if x>=K)\n ins = sum([(x//(K-1)-1 if x%(K-1)==0 else x//(K-1)) for x in temp])\n if ins==0:\n break\n else:\n res.append(ins)\n else:\n for K in range(2,N+1):\n ins = N//(K-1)+(N%(K-1)>0)\n if ins==0:\n break\n else:\n res.append(ins)\n \n res = res + [0]*(N-1 -len(res))\n print(*res)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n5\\n3 6 4 5 9\\n', 'output': '3 1 1 0\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/MININS'}","problem_id":"vfc_3610","program":"```python\nfrom math import gcd\nfrom itertools import groupby\n\ndef gcd_split(seq):\n gcds= [int(gcd(a,b)==1) for a,b in zip(seq[1:],seq[:-1])]\n gcds.append(int(gcd(seq[0],seq[-1])==1))\n # print(gcds)\n if max(gcds)==0:\n return -1\n else:\n splits=[len(list(x))+1 for num,x in groupby(gcds) if num==0]\n # print(splits)\n if gcds[0]==gcds[-1]==0:\n splits[0] += splits[-1]-1\n splits = splits[:-1]\n return splits\n\nfor _ in range(int(input())):\n N=int(input())\n A=[int(x) for x in input().split()]\n split = gcd_split(A)\n # print(split)\n \n res=[]\n if split!=-1:\n for K in range(2,N+1):\n temp=(x for x in split if x>=K)\n ins = sum([(x//(K-1)-1 if x%(K-1)==0 else x//(K-1)) for x in temp])\n if ins==0:\n break\n else:\n res.append(ins)\n else:\n for K in range(2,N+1):\n ins = N//(K-1)+(N%(K-1)>0)\n if ins==0:\n break\n else:\n res.append(ins)\n \n res = res + [0]*(N-1 -len(res))\n print(*res)\n```","inputs":"1\n5\n3 6 4 5 9\n","output":"3 1 1 0\n","actual_output":"3 1 1 0\n","execution_success":true,"sample_index":788},{"source":"apps","task_type":"verifiable_code","in_source_id":"1193","prompt":"Solve the following coding problem using the programming language python:\n\nThere are $N$ robots who work for $Y$ days and on each day they\nproduce some toys .on some days a few robots are given rest.\nSo depending on the availability of robots owner has \nmade a time table which decides which robots will work on \nthe particular day.\nOnly contiguous robots must be selected as they can form \na link of communication among themselves.\nInitially, all robots have the capacity of one toy.\nOn each day capacity for the chosen robot is updated i.e\ncapacity = capacity $+$$ ($minimum capacity of given range % $1000000007)$ .\nAfter calculating the minimum capacity of a given range, compute\nit as modulo 1000000007 ($10^9 + 7$).\nAfter $Y$ days find the minimum capacity of the $N$ robots and compute it as modulo 1000000007 ($10^9 + 7$). \n\n-----Input:-----\n- First-line will contain $T$, the number of test cases. Then the test cases follow. \n- Next Line contains a single integer N.\n- Next Line contains a single integer Y.\n- Next $Y$ lines contains l and r range of chosen robots .\n\n-----Output:-----\nFor each testcase, output in a single line answer , the minimum capacity of the $N$ robots after $Y$ days and compute it as modulo 1000000007 ($10^9 + 7$) .\n\n-----Constraints-----\n- $1 \\leq T \\leq 100$\n- $100 \\leq N \\leq 10^4$\n- $200 \\leq Y \\leq 1000$\n- $0<=l , r<=N-1$ , $l<=r$\n\n-----Sample Input:-----\n1\n5\n4\n0 3\n1 2\n4 4\n0 4\n\n-----Sample Output:-----\n4\n\n-----EXPLANATION:-----\nInitial capacity of the $5$ robots\n1 1 1 1 1 \nMinimum in range [0,3] = 1\nUpdate the capacity in the range [0,3]\nNow capacity becomes, \nDay 1 - 2 2 2 2 1\nSimilarly capacities changes for each day \nDay 2 - 2 4 4 2 1\nDay 3 - 2 4 4 2 2\nDay 4 - 4 6 6 4 4\nso after 4 days minimum capacity is $4$.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nMAX = 100005\ntree = [0] * MAX; \nlazy = [0] * MAX;\n \ndef updateRangeUtil(si, ss, se, us, ue, diff) :\n if (lazy[si] != 0) :\n tree[si] += lazy[si];\n if (ss != se) :\n lazy[si * 2 + 1] += lazy[si];\n lazy[si * 2 + 2] += lazy[si];\n lazy[si] = 0;\n \n if (ss > se or ss > ue or se < us) :\n return; \n \n if (ss >= us and se <= ue) :\n tree[si] += diff;\n if (ss != se) :\n lazy[si * 2 + 1] += diff;\n lazy[si * 2 + 2] += diff;\n return; \n \n mid = (ss + se) // 2;\n updateRangeUtil(si * 2 + 1, ss,mid, us, ue, diff);\n updateRangeUtil(si * 2 + 2, mid + 1,se, us, ue, diff);\n tree[si] = min(tree[si * 2 + 1],tree[si * 2 + 2]); \n \ndef updateRange(n, us, ue, diff) : \n updateRangeUtil(0, 0, n - 1, us, ue, diff); \n \ndef getSumUtil(ss, se, qs, qe, si) :\n if (lazy[si] != 0) :\n tree[si] += lazy[si];\n if (ss != se) :\n lazy[si * 2 + 1] += lazy[si];\n lazy[si * 2 + 2] += lazy[si];\n lazy[si] = 0;\n \n if (ss > se or ss > qe or se < qs) :\n return 10e9; \n \n if (ss >= qs and se <= qe) :\n return tree[si]; \n \n mid = (ss + se) // 2; \n return min(getSumUtil(ss, mid, qs, qe, 2 * si + 1),getSumUtil(mid + 1, se, qs, qe, 2 * si + 2)); \n \ndef getSum(n, qs, qe) : \n if (qs < 0 or qe > n - 1 or qs > qe) :\n #print(\"Invalid Input\", end = \"\");\n return -1;\n \n return getSumUtil(0, n - 1, qs, qe, 0); \n \ndef constructSTUtil(arr, ss, se, si) : \n if (ss > se) :\n return;\n if (ss == se) :\n tree[si] = arr[ss];\n return; \n mid = (ss + se) // 2;\n constructSTUtil(arr, ss, mid, si * 2 + 1);\n constructSTUtil(arr, mid + 1, se, si * 2 + 2);\n tree[si] = min(tree[si * 2 + 1], tree[si * 2 + 2]); \n \ndef constructST(arr, n) :\n constructSTUtil(arr, 0, n - 1, 0); \n \n# Driver code \nfor _ in range(int(input())):\n tree = [0] * MAX; \n lazy = [0] * MAX;\n n=int(input());\n y=int(input());\n arr=[1]*n;\n constructST(arr, n);\n for xyz in range(y):\n l,r=list(map(int,input().split()));\n updateRange(n, l, r, getSum(n, l, r)%1000000007);\n print((getSum(n, 0, n-1)%1000000007));\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n5\\n4\\n0 3\\n1 2\\n4 4\\n0 4\\n', 'output': '4\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/ENDE2020/problems/ENCDEC6'}","problem_id":"vfc_3614","program":"```python\nMAX = 100005\ntree = [0] * MAX; \nlazy = [0] * MAX;\n \ndef updateRangeUtil(si, ss, se, us, ue, diff) :\n if (lazy[si] != 0) :\n tree[si] += lazy[si];\n if (ss != se) :\n lazy[si * 2 + 1] += lazy[si];\n lazy[si * 2 + 2] += lazy[si];\n lazy[si] = 0;\n \n if (ss > se or ss > ue or se < us) :\n return; \n \n if (ss >= us and se <= ue) :\n tree[si] += diff;\n if (ss != se) :\n lazy[si * 2 + 1] += diff;\n lazy[si * 2 + 2] += diff;\n return; \n \n mid = (ss + se) // 2;\n updateRangeUtil(si * 2 + 1, ss,mid, us, ue, diff);\n updateRangeUtil(si * 2 + 2, mid + 1,se, us, ue, diff);\n tree[si] = min(tree[si * 2 + 1],tree[si * 2 + 2]); \n \ndef updateRange(n, us, ue, diff) : \n updateRangeUtil(0, 0, n - 1, us, ue, diff); \n \ndef getSumUtil(ss, se, qs, qe, si) :\n if (lazy[si] != 0) :\n tree[si] += lazy[si];\n if (ss != se) :\n lazy[si * 2 + 1] += lazy[si];\n lazy[si * 2 + 2] += lazy[si];\n lazy[si] = 0;\n \n if (ss > se or ss > qe or se < qs) :\n return 10e9; \n \n if (ss >= qs and se <= qe) :\n return tree[si]; \n \n mid = (ss + se) // 2; \n return min(getSumUtil(ss, mid, qs, qe, 2 * si + 1),getSumUtil(mid + 1, se, qs, qe, 2 * si + 2)); \n \ndef getSum(n, qs, qe) : \n if (qs < 0 or qe > n - 1 or qs > qe) :\n #print(\"Invalid Input\", end = \"\");\n return -1;\n \n return getSumUtil(0, n - 1, qs, qe, 0); \n \ndef constructSTUtil(arr, ss, se, si) : \n if (ss > se) :\n return;\n if (ss == se) :\n tree[si] = arr[ss];\n return; \n mid = (ss + se) // 2;\n constructSTUtil(arr, ss, mid, si * 2 + 1);\n constructSTUtil(arr, mid + 1, se, si * 2 + 2);\n tree[si] = min(tree[si * 2 + 1], tree[si * 2 + 2]); \n \ndef constructST(arr, n) :\n constructSTUtil(arr, 0, n - 1, 0); \n \n# Driver code \nfor _ in range(int(input())):\n tree = [0] * MAX; \n lazy = [0] * MAX;\n n=int(input());\n y=int(input());\n arr=[1]*n;\n constructST(arr, n);\n for xyz in range(y):\n l,r=list(map(int,input().split()));\n updateRange(n, l, r, getSum(n, l, r)%1000000007);\n print((getSum(n, 0, n-1)%1000000007));\n\n```","inputs":"1\n5\n4\n0 3\n1 2\n4 4\n0 4\n","output":"4\n","actual_output":"4\n","execution_success":true,"sample_index":789},{"source":"apps","task_type":"verifiable_code","in_source_id":"1194","prompt":"Solve the following coding problem using the programming language python:\n\nToby has found a game to entertain himself.The game is like this:\n\nYou are in a coordinate system initially at (0,0) and you are given a sequence of steps which lead to your destination.The steps are given in the form of directions: \u2019U\u2019 ,\u2019D\u2019 , \u2019L\u2019 and \u2018R\u2019 for up, down, left and right respectively.If you are at position (x,y) then:\n- U:move to (x,y+1)\n- D:move to (x,y-1)\n- L:move to (x-1,y)\n- R:move to (x+1,y)\nThe sequence is provided as a string \u2018s\u2019 of characters where $s_i$ $(1 \\leq i \\leq N)$ is one of the direction character as mentioned above.An example of a sequence of steps is: UULRUDR\n\nThe destination according to this string is (1,2).\n\nYou want to remove maximum number of characters from the string such that the resulting string leads to the same destination as before.\nFor example in the example above we can remove characters at positions 1,3,4,6 and the resulting path will be UUR which will lead to the same destination i.e (1,2).so we reduced the number of steps by 4,and this is our score.\nYou need to get maximum score.\n\n-----Input:-----\n- First line will contain $T$, number of testcases. Then the testcases follow. \n- First line of each testcase contains a single integer $N$,size of string. \n- Second line of testcase contains a string $s$ of size $N$.\n\n-----Output:-----\nFor each testcase, output a single line containing the maximum score possible.\n\n-----Constraints-----\n- $1 \\leq T \\leq 1000$\n- $1 \\leq N \\leq 10^5$\n\n-----Sample Input:-----\n3\n\n7\n\nULUDLLU\n\n4\n\nRUUR\n\n4\n\nLRLR \n\n-----Sample Output:-----\n2\n\n0\n\n4 \n\n-----EXPLANATION:-----\n- \ntest case 1:\nThe final destination after moving according to the sequence is (-3,2).\n\nOne way is to remove characters at positions 3,4 and the resulting string will be ULLLU and destination still remains (-3,2).\n- \ntest case 2: No character can be removed in this case.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfrom collections import Counter\ntry:\n for _ in range(int(input())):\n n=int(input())\n s=input()\n d1=dict(Counter(s))\n \n u,d,r,l=0,0,0,0\n if 'U' in d1:\n u=d1['U']\n else:\n u=0\n if 'D' in d1:\n d=d1['D']\n else:\n d=0\n if 'R' in d1:\n r=d1['R']\n else:\n r=0\n if 'L' in d1:\n l=d1['L']\n else:\n l=0\n x=0\n y=0\n if l==r:\n x=0\n elif l>r:\n x=-(l-r)\n elif r>l:\n x=r-l\n if u==d:\n y=0\n elif d>u:\n y=-(d-u)\n elif u>d:\n y=u-d\n # print(x,y)\n if x==0 and y==0:\n print(n)\n continue\n \n print(n-(abs(x)+abs(y)))\nexcept:\n pass\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\n7\\nULUDLLU\\n4\\nRUUR\\n4\\nLRLR\\n', 'output': '2\\n0\\n4\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/CSEP2020/problems/TOBY'}","problem_id":"vfc_3618","program":"```python\nfrom collections import Counter\ntry:\n for _ in range(int(input())):\n n=int(input())\n s=input()\n d1=dict(Counter(s))\n \n u,d,r,l=0,0,0,0\n if 'U' in d1:\n u=d1['U']\n else:\n u=0\n if 'D' in d1:\n d=d1['D']\n else:\n d=0\n if 'R' in d1:\n r=d1['R']\n else:\n r=0\n if 'L' in d1:\n l=d1['L']\n else:\n l=0\n x=0\n y=0\n if l==r:\n x=0\n elif l>r:\n x=-(l-r)\n elif r>l:\n x=r-l\n if u==d:\n y=0\n elif d>u:\n y=-(d-u)\n elif u>d:\n y=u-d\n # print(x,y)\n if x==0 and y==0:\n print(n)\n continue\n \n print(n-(abs(x)+abs(y)))\nexcept:\n pass\n\n```","inputs":"3\n7\nULUDLLU\n4\nRUUR\n4\nLRLR\n","output":"2\n0\n4\n","actual_output":"2\n0\n4\n","execution_success":true,"sample_index":790},{"source":"apps","task_type":"verifiable_code","in_source_id":"1195","prompt":"Solve the following coding problem using the programming language python:\n\nChefland has all the cities on a straight line. There are $N$ cities in Chefland numbered $1$ to $N$. City $i$ is located at coordinate $x_i$ on the x-axis. Guru wants to travel from city $A$ to city $B$. He starts at time t=0. He has following choices to travel.\n- He can walk $1$ metre in $P$ secs.\n- There is a train that travels from city $C$ to city $D$ which travels $1$ metre in $Q$ secs which starts at time t=$Y$ secs. Guru can take the train only at city $C$ and leave the train only at city $D$.\nCan you help Guru find the minimum time he will need to travel from city $A$ to $B$. Note that you cannot board the train after time t =$Y$.\n\n-----Input:-----\n- First line will contain $T$, number of testcases. Then the testcases follow. \n- First line of each testcase contains eight space separated integers $N, A, B, C, D, P, Q, Y $. \n- Second line of each testcase contains $N$ space-separated integers with the $i$-th integer representing $x_i$.\n\n-----Output:-----\nFor each testcase, output in a single line containing the minimum travel time.\n\n-----Constraints-----\n- $1 \\leq T \\leq 300$\n- $2 \\leq N \\leq 300$\n- $-1000 \\leq x_i \\leq 1000$\n- $0 \\leq Y \\leq 100000$\n- $1 \\leq A,B,C,D \\leq n $\n- $A \\neq B$\n- $C \\neq D$\n- $1 \\leq P, Q \\leq 100$\n- $x_i < x_j$ if $i < j$\n\n-----Sample Input:-----\n1\n4 1 3 2 4 3 2 4\n1 2 3 4\n\n-----Sample Output:-----\n6\n\n-----EXPLANATION:-----\nGuru can walk directly in 6 secs.\nIf Guru takes train, then he will need atleast 11 secs.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nt=int(input())\nfor _ in range(t):\n n,a,b,c,d,p,q,y=list(map(int,input().split()))\n l=list(map(int,input().split()))\n ans = abs((l[b-1]-l[a-1]))*p\n x=abs(l[c-1]-l[a-1])*p\n if x<=y:\n x=y+abs(l[d-1]-l[c-1])*q+abs(l[b-1]-l[d-1])*p\n ans=min(ans,x)\n print(ans)\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n4 1 3 2 4 3 2 4\\n1 2 3 4\\n', 'output': '6\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/WALKFAST'}","problem_id":"vfc_3622","program":"```python\nt=int(input())\nfor _ in range(t):\n n,a,b,c,d,p,q,y=list(map(int,input().split()))\n l=list(map(int,input().split()))\n ans = abs((l[b-1]-l[a-1]))*p\n x=abs(l[c-1]-l[a-1])*p\n if x<=y:\n x=y+abs(l[d-1]-l[c-1])*q+abs(l[b-1]-l[d-1])*p\n ans=min(ans,x)\n print(ans)\n\n```","inputs":"1\n4 1 3 2 4 3 2 4\n1 2 3 4\n","output":"6\n","actual_output":"6\n","execution_success":true,"sample_index":791},{"source":"apps","task_type":"verifiable_code","in_source_id":"1196","prompt":"Solve the following coding problem using the programming language python:\n\nEvery college has a stud\u2212max$stud-max$ buoy. JGEC$JGEC$ has its own Atul$Atul$ who loves to impress everyone with his smile. A presentation is going on at the auditorium where there are N$N$ rows of M$M$ chairs with people sitting on it. Everyone votes for Atul's presentation skills, but Atul is interested in knowing the maximum$maximum$ amount of vote that he receives either taking K$K$ people vertically$vertically$ or horizontally$horizontally$. Atul$Atul$, however, wants to finish up the presentation party soon, hence asks for your help so that he can wrap up things faster. \n\n-----Input:-----\n- First line will contain T$T$, number of test cases. Then the test cases follow. \n- Each testcase contains of a single line of input, three integers N$N$, M$M$ and K$K$. \n- N lines follow, where every line contains M numbers$numbers$ denoting the size of the sugar cube\n\n-----Output:-----\nFor each test case, output in a single line the maximum votes Atul can get. \n\n-----Constraints-----\n- 1\u2264T\u2264$1 \\leq T \\leq $5\n- 1\u2264N,M\u2264500$1 \\leq N,M \\leq 500$\n- K\u2264min(N,M)$K \\leq min(N,M)$ \n- 1\u2264numbers\u2264109$1 \\leq numbers \\leq 10^9$\n\n-----Sample Input:-----\n1\n4 4 3 \n1 4 5 7 \n2 3 8 6\n1 4 8 9 \n5 1 5 6 \n\n-----Sample Output:-----\n22\n\n-----EXPLANATION:-----\nIf Atul starts counting votes from (1,4), then he can take the 3 consecutive elements vertically downwards and those are 7,6 and 9 which is the maximum sum possible.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nt = int(input())\r\nfor i in range(t):\r\n q = input().split()\r\n n = int(q[0])\r\n m = int(q[1])\r\n k = int(q[2])\r\n sumax = 0\r\n b = []\r\n for j in range(n):\r\n a = [int(k) for k in input().split()]\r\n b = b + [a]\r\n for j in range(n):\r\n su = 0\r\n for x in range(k):\r\n su = su +b[j][x]\r\n if su > sumax:\r\n sumax = su\r\n for a in range(1, m-k+1):\r\n su = su - b[j][a-1] +b[j][k+a-1]\r\n if su > sumax:\r\n sumax = su\r\n for j in range(m):\r\n su = 0\r\n for x in range(k):\r\n su = su + b[x][j]\r\n if su > sumax:\r\n sumax = su\r\n for a in range(1, n-k+1):\r\n su = su - b[a-1][j] + b[a+k-1][j]\r\n if su > sumax:\r\n sumax = su\r\n print(sumax)\r\n \r\n \r\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n4 4 3\\n1 4 5 7\\n2 3 8 6\\n1 4 8 9\\n5 1 5 6\\n', 'output': '22\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/AARA2018/problems/ARMBH2'}","problem_id":"vfc_3626","program":"```python\nt = int(input())\r\nfor i in range(t):\r\n q = input().split()\r\n n = int(q[0])\r\n m = int(q[1])\r\n k = int(q[2])\r\n sumax = 0\r\n b = []\r\n for j in range(n):\r\n a = [int(k) for k in input().split()]\r\n b = b + [a]\r\n for j in range(n):\r\n su = 0\r\n for x in range(k):\r\n su = su +b[j][x]\r\n if su > sumax:\r\n sumax = su\r\n for a in range(1, m-k+1):\r\n su = su - b[j][a-1] +b[j][k+a-1]\r\n if su > sumax:\r\n sumax = su\r\n for j in range(m):\r\n su = 0\r\n for x in range(k):\r\n su = su + b[x][j]\r\n if su > sumax:\r\n sumax = su\r\n for a in range(1, n-k+1):\r\n su = su - b[a-1][j] + b[a+k-1][j]\r\n if su > sumax:\r\n sumax = su\r\n print(sumax)\r\n \r\n \r\n\n```","inputs":"1\n4 4 3\n1 4 5 7\n2 3 8 6\n1 4 8 9\n5 1 5 6\n","output":"22\n","actual_output":"22\n","execution_success":true,"sample_index":792},{"source":"apps","task_type":"verifiable_code","in_source_id":"1198","prompt":"Solve the following coding problem using the programming language python:\n\nChef recently took a course in linear algebra and learned about linear combinations of vectors. Therefore, in order to test his intelligence, Raj gave him a \"fuzzy\" problem to solve.\nA sequence of integers $B_1, B_2, \\ldots, B_M$ generates an integer $K$ if it is possible to find a sequence of integers $C_1, C_2, \\ldots, C_M$ such that $C_1 \\cdot B_1 + C_2 \\cdot B_2 + \\ldots + C_M \\cdot B_M = K$.\nIn this problem, Chef has a sequence $A_1, A_2, \\ldots, A_N$ and he should answer $Q$ queries. In each query, he is given an integer $K$; the answer to this query is the number of pairs $(l, r)$ such that $1 \\le l \\le r \\le N$ and the subsequence $(A_l, A_{l+1}, \\ldots, A_r)$ generates $K$.\nChef has no idea how to solve this problem \u2015 can you help him find the answers to all queries?\n\n-----Input-----\n- The first line of the input contains a single integer $N$.\n- The second line contains $N$ space-separated integers $A_1, A_2, \\ldots, A_N$.\n- The third line contains a single integer $Q$.\n- The following $Q$ lines describe queries. Each of these lines contains a single integer $K$.\n\n-----Output-----\nFor each query, print a single line containing one integer \u2015 the number of contiguous subsequences that generate $K$.\n\n-----Constraints-----\n- $1 \\le N, Q \\le 10^5$\n- $1 \\le A_i \\le 10^9$ for each valid $i$\n- $1 \\le K \\le 10^6$\n\n-----Subtasks-----\nSubtask #1 (10 points): $1 \\le N \\le 1,000$\nSubtask #2 (90 points): original constraints\n\n-----Example Input-----\n2\n2 4\n3\n1\n2\n8\n\n-----Example Output-----\n0\n2\n3\n\n-----Explanation-----\nThe sequence $(2, 4)$ has three contiguous subsequences: $(2)$, $(4)$ and $(2, 4)$. \n- In the first query, $1$ cannot be generated by any subsequence.\n- In the second query, $2$ is generated by subsequences $(2)$ and $(2, 4)$. For example, for the subsequence $(2, 4)$, we can choose $C_1 = 1$ and $C_2 = 0$.\n- In the third query, $8$ is generated by all three subsequences.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nimport math\nimport bisect\nfrom functools import reduce\nfrom collections import defaultdict\n# import sys\n# input = sys.stdin.readline\n\ndef inn():\n return int(input())\n\ndef inl():\n return list(map(int, input().split()))\n\nMOD = 10**9+7\nINF = inf = 10**18+5\n\nn = inn()\na = inl()\nk = []\nfor q in range(inn()):\n k.append(inn())\n\ngcdn = reduce(math.gcd, a)\nlim = max(k)+1\nans = defaultdict(int)\nans[1] = 0\n\nfor i in range(n):\n cur_gcd = a[i]\n for j in range(i, n):\n cur_gcd = math.gcd(cur_gcd, a[j])\n if cur_gcd==1 or cur_gcd//gcdn==1:\n ans[cur_gcd] += (n-j)\n break\n ans[cur_gcd] += 1\n# print(ans)\n\nkeys = list(ans.keys())\nans1 = [0]*lim\nfor i in keys:\n for j in range(i, lim, i):\n ans1[j] += ans[i]\n# print(ans1[:10])\nfor i in k:\n print(ans1[i])\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n2 4\\n3\\n1\\n2\\n8\\n', 'output': '0\\n2\\n3\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/FUZZYLIN'}","problem_id":"vfc_3634","program":"```python\nimport math\nimport bisect\nfrom functools import reduce\nfrom collections import defaultdict\n# import sys\n# input = sys.stdin.readline\n\ndef inn():\n return int(input())\n\ndef inl():\n return list(map(int, input().split()))\n\nMOD = 10**9+7\nINF = inf = 10**18+5\n\nn = inn()\na = inl()\nk = []\nfor q in range(inn()):\n k.append(inn())\n\ngcdn = reduce(math.gcd, a)\nlim = max(k)+1\nans = defaultdict(int)\nans[1] = 0\n\nfor i in range(n):\n cur_gcd = a[i]\n for j in range(i, n):\n cur_gcd = math.gcd(cur_gcd, a[j])\n if cur_gcd==1 or cur_gcd//gcdn==1:\n ans[cur_gcd] += (n-j)\n break\n ans[cur_gcd] += 1\n# print(ans)\n\nkeys = list(ans.keys())\nans1 = [0]*lim\nfor i in keys:\n for j in range(i, lim, i):\n ans1[j] += ans[i]\n# print(ans1[:10])\nfor i in k:\n print(ans1[i])\n```","inputs":"2\n2 4\n3\n1\n2\n8\n","output":"0\n2\n3\n","actual_output":"0\n2\n3\n","execution_success":true,"sample_index":794},{"source":"apps","task_type":"verifiable_code","in_source_id":"1199","prompt":"Solve the following coding problem using the programming language python:\n\nIn a country called Chef Land, there was a lot of monetary fraud, so Chefu, the head of the country, decided to choose new denominations of the local currency \u2015 all even-valued coins up to an integer $N$ should exist. After a few days, a citizen complained that there was no way to create an odd value, so Chefu decided that he should also introduce coins with value $1$. Formally, you are given an integer $N$; for $v = 1$ and each even positive integer $v \\le N$, coins with value $v$ exist.\nYou are also given an integer $S$. To handle transactions quickly, find the minimum number of coins needed to pay a price $S$.\n\n-----Input-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The first and only line of each test case contains two space-separated integers $S$ and $N$.\n\n-----Output-----\nFor each test case, print a single line containing one integer \u2015 the minimum number of coins.\n\n-----Constraints-----\n- $1 \\le T \\le 10,000$\n- $1 \\le S \\le 10^9$\n- $2 \\le N \\le 10^9$\n- $N$ is even\n\n-----Subtasks-----\nSubtask #1 (100 points): original constraints\n\n-----Example Input-----\n4\n2 2\n1 14\n30 10\n31 4\n\n-----Example Output-----\n1\n1\n3\n9\n\n-----Explanation-----\nExample case 1: One coin with value $2$ is sufficient.\nExample case 2: We need to use one coin with value $1$.\nExample case 3: We need $3$ coins, each with value $10$.\nExample case 4: We can use seven coins with value $4$, one coin with value $2$ and one coin with value $1$.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfor i in range(int(input())):\n n,k=list(map(int,input().split()))\n t=0\n if n%2!=0:\n n-=1\n t+=1\n t+=(n//k)\n if n%k!=0:\n t+=1\n print(t)\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '4\\n2 2\\n1 14\\n30 10\\n31 4\\n', 'output': '1\\n1\\n3\\n9\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/CHFMOT18'}","problem_id":"vfc_3638","program":"```python\nfor i in range(int(input())):\n n,k=list(map(int,input().split()))\n t=0\n if n%2!=0:\n n-=1\n t+=1\n t+=(n//k)\n if n%k!=0:\n t+=1\n print(t)\n\n```","inputs":"4\n2 2\n1 14\n30 10\n31 4\n","output":"1\n1\n3\n9\n","actual_output":"1\n1\n3\n9\n","execution_success":true,"sample_index":795},{"source":"apps","task_type":"verifiable_code","in_source_id":"1200","prompt":"Solve the following coding problem using the programming language python:\n\nTwo sisters, A and B, play the piano every day. During the day, they can play in any order. That is, A might play first and then B, or it could be B first and then A. But each one of them plays the piano exactly once per day. They maintain a common log, in which they write their name whenever they play.\nYou are given the entries of the log, but you're not sure if it has been tampered with or not. Your task is to figure out whether these entries could be valid or not.\n\n-----Input-----\n- The first line of the input contains an integer $T$ denoting the number of test cases. The description of the test cases follows.\n- The first line of each test case contains a string $s$ denoting the entries of the log.\n\n-----Output-----\n- For each test case, output yes or no according to the answer to the problem.\n\n-----Constraints-----\n- $1 \\le T \\le 500$\n- $2 \\le |s| \\le 100$\n- $|s|$ is even\n- Each character of $s$ is either 'A' or 'B'\n\n-----Example Input-----\n4\nAB\nABBA\nABAABB\nAA\n\n-----Example Output-----\nyes\nyes\nno\nno\n\n-----Explanation-----\nTestcase 1: There is only one day, and both A and B have played exactly once. So this is a valid log. Hence 'yes'.\nTestcase 2: On the first day, A has played before B, and on the second day, B has played first. Hence, this is also a valid log.\nTestcase 3: On the first day, A played before B, but on the second day, A seems to have played twice. This cannot happen, and hence this is 'no'.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\ndef checkValidity(s):\n count = 0\n previous = \"\"\n\n for x in s:\n if count == 0:\n previous = x\n count += 1\n elif count == 1:\n count = 0\n if previous == x:\n return \"no\"\n\n return \"yes\"\n\nt = int(input())\n\nfor _ in range(t):\n s = input()\n print(checkValidity(s))\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '4\\nAB\\nABBA\\nABAABB\\nAA\\n', 'output': 'yes\\nyes\\nno\\nno\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/PLAYPIAN'}","problem_id":"vfc_3642","program":"```python\ndef checkValidity(s):\n count = 0\n previous = \"\"\n\n for x in s:\n if count == 0:\n previous = x\n count += 1\n elif count == 1:\n count = 0\n if previous == x:\n return \"no\"\n\n return \"yes\"\n\nt = int(input())\n\nfor _ in range(t):\n s = input()\n print(checkValidity(s))\n\n```","inputs":"4\nAB\nABBA\nABAABB\nAA\n","output":"yes\nyes\nno\nno\n","actual_output":"yes\nyes\nno\nno\n","execution_success":true,"sample_index":796},{"source":"apps","task_type":"verifiable_code","in_source_id":"1201","prompt":"Solve the following coding problem using the programming language python:\n\nKim has broken in to the base, but after walking in circles, perplexed by the unintelligible base design of the JSA, he has found himself in a large, empty, and pure white, room. \nThe room is a grid with H\u2217W$H*W$ cells, divided into H$H$ rows and W$W$ columns. The cell (i,j)$(i,j)$ is at height A[i][j]$A[i][j]$. Unfortunately, his advanced sense of smell has allowed him to sense a mercury leak, probably brought in by Jishnu to end his meddling. The mercury leak has a power (which determines what height the mercury can reach before dissipating into harmless quantities) and a source cell. It spreads from cells it has already reached to other cells in the four cardinal directions: north, south, east, and west. (That is, the mercury can spread up, down, right, or left in the grid, but not diagonally.) Mercury can only spread to a cell if the cell's height is strictly less than the power value. \nUnfortunately, Kim does not exactly know the starting cell or the power value of the mercury leak. However, his impressive brain has determined that it must be one of Q$Q$ (power, starting cell) combinations. For each combination, he wants to find out how many cells are dangerous for him to go to: that is, how many cells will eventually be reached by the mercury. This will help him determine a suitable cell to stay in and slowly fix the leak from above.\nCan you help Kim achieve this objective?\nNote: If the starting cell's height is not less than the power level, the mercury immediately dissipates. So, in this case, output 0.\n\n-----Input:-----\n- First line will contain T$T$, number of testcases. Then the testcases follow. \n- The first line in each testcase contains three integers, H$H$, W$W$, and Q$Q$.\n- On the 2$2$nd to (H+1)$(H+1)$th lines of each testcase: The (i+1)$(i+1)$th line contains W$W$ space-separated integers, representing the heights of the cells on the i$i$th row of the grid.\n- On the (H+2)$(H+2)$th to (H+Q+1)$(H+Q+1)$th lines of each testcase: The (i+H+1)$(i+H+1)$th line contains 3 space-separated integers, r[i]$r[i]$, c[i]$c[i]$, and p[i]$p[i]$, which represents a (power, starting cell) combination. For this specific combination, the mercury leak originates on the cell (r[i],c[i])$(r[i],c[i])$ and has power p[i]$p[i]$.\n\n-----Output:-----\nFor each testcase, output Q$Q$ lines, with each line containing one integer. The i$i$th line should output the number of dangerous cells, given that the leak originated on cell (r[i],c[i])$(r[i],c[i])$ with power p[i]$p[i]$, as defined in the input. Read the sample and sample explanation for more details.\n\n-----Constraints-----\n- 1\u2264T\u22642$1 \\leq T \\leq 2$ \n- 1\u2264H\u22641000$1 \\leq H \\leq 1000$\n- 1\u2264W\u22641000$1 \\leq W \\leq 1000$\n- 1\u2264Q\u22642\u2217105$1 \\leq Q \\leq 2*10^5$\n- 1\u2264r[i]\u2264H$1 \\leq r[i] \\leq H$ for all i$i$\n- 1\u2264c[i]\u2264W$1 \\leq c[i] \\leq W$ for all i$i$\n- 0\u2264A[i][j]\u2264109$0 \\leq A[i][j] \\leq 10^9$ for all (i,j)$(i,j)$\n- 0\u2264p[i]\u2264109$0 \\leq p[i] \\leq 10^9$ for all i$i$.\n\n-----Subtasks-----\n- 10 points : A[i][j]=$A[i][j] =$ constant k$k$ for all (i,j)$(i,j)$ (the heights of all cells are equal). \n- 20 points : H=1$H=1$, Q\u22641000$Q \\leq 1000$. \n- 30 points: r[i]=$r[i] =$ constant x$x$, c[i]=$c[i] =$ constant y$y$ for all i$i$ (the starting cell is fixed). \n- 40 points: No additional constraints. \n\n-----Sample Input:-----\n1\n5 5 3\n4 3 9 7 2\n8 6 5 2 8\n1 7 3 4 3\n2 2 4 5 6\n9 9 9 9 9\n3 4 6\n3 2 5\n1 4 9\n\n-----Sample Output:-----\n10\n0\n19\n\n-----EXPLANATION:-----\nFor the first query, the cell (3,4)$(3,4)$ has height 4. The mercury can reach the following cells: (2,3)$(2,3)$, (2,4)$(2,4)$, (3,1)$(3,1)$, (3,3)$(3,3)$, (3,4)$(3,4)$, (3,5)$(3,5)$, (4,1)$(4,1)$, (4,2)$(4,2)$, (4,3)$(4,3)$, (4,4)$(4,4)$, for a total of 10. Note that it cannot reach cell (4,5)$(4,5)$ because the height (6) is equal to the power value (6).\nFor the second query, the cell (3,2)$(3,2)$ has height 7. Since the power value of 5 is less than or equal to the height of 7, the mercury immediately dissipates and so it reaches 0 cells.\nFor the third query, the mercury can reach all cells except the bottom row and the cell (1,3)$(1,3)$.\nNote that (x,y)$(x,y)$ means the cell on the x$x$-th row and y$y$-th column.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\ndef solve(l,r,c,row,col,po):\n count=0\n visited=set()\n stack=set()\n stack.add((l[row][col],row,col))\n while stack:\n ele=stack.pop()\n visited.add((ele[1],ele[2]))\n if ele[0]=0 and (ele[1]-1,ele[2]) not in visited:\n if l[ele[1]-1][ele[2]]=0 and (ele[1],ele[2]-1) not in visited:\n if l[ele[1]][ele[2]-1]=0 and (ele[1]-1,ele[2]) not in visited:\n if l[ele[1]-1][ele[2]]=0 and (ele[1],ele[2]-1) not in visited:\n if l[ele[1]][ele[2]-1] Cycling > Walking\n\n-----Input:-----\n- It is a one line string consisting of the names(initial letter) of all the chocolates he has eaten.\n\n-----Output:-----\nPrint three lines. First line representing how much he ran(in km), second line representing how much he cycled(in km), third line representing how much he walked(in km).\n\n-----Constraints-----\n- 1 <= length of input string <= 10. \n\n-----Sample Input:-----\nDDTM\n\n-----Sample Output:-----\n17\n1\n6\n\n-----EXPLANATION:-----\nCalorie intake = 238 + 238 + 244 + 138 = 858\n( 17km x 50 ) + ( 1km x 5 ) + ( 6km x 0.5 ) = 858.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\n\nd = { 'D': 238, 'T': 244, 'M': 138, 'B': 279, 'C': 186 }\n\ns = list(input())\ntotalCal = 0\n\nfor i in range(len(s)):\n if s[i] == 'D':\n totalCal += d['D']\n if s[i] == 'T':\n totalCal += d['T']\n if s[i] == 'M':\n totalCal += d['M']\n if s[i] == 'B':\n totalCal += d['B']\n if s[i] == 'C':\n totalCal += d['C']\n\nR = totalCal // 50\nRm = totalCal % 50\nC = Rm // 5\nCm = Rm % 5\nx = totalCal - (R * 50 + C * 5)\n# print(totalCal - R * 50 + C * 5)\nW = int(x * 4 * 0.5)\n# print(R * 50 + C * 5 + W * 0.5)\nprint(R)\nprint(C)\nprint(W)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': 'DDTM\\n', 'output': '17\\n1\\n6\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/RTCG2020/problems/RTCG002'}","problem_id":"vfc_3650","program":"```python\n# cook your dish here\n\nd = { 'D': 238, 'T': 244, 'M': 138, 'B': 279, 'C': 186 }\n\ns = list(input())\ntotalCal = 0\n\nfor i in range(len(s)):\n if s[i] == 'D':\n totalCal += d['D']\n if s[i] == 'T':\n totalCal += d['T']\n if s[i] == 'M':\n totalCal += d['M']\n if s[i] == 'B':\n totalCal += d['B']\n if s[i] == 'C':\n totalCal += d['C']\n\nR = totalCal // 50\nRm = totalCal % 50\nC = Rm // 5\nCm = Rm % 5\nx = totalCal - (R * 50 + C * 5)\n# print(totalCal - R * 50 + C * 5)\nW = int(x * 4 * 0.5)\n# print(R * 50 + C * 5 + W * 0.5)\nprint(R)\nprint(C)\nprint(W)\n```","inputs":"DDTM\n","output":"17\n1\n6\n","actual_output":"17\n1\n6\n","execution_success":true,"sample_index":798},{"source":"apps","task_type":"verifiable_code","in_source_id":"1204","prompt":"Solve the following coding problem using the programming language python:\n\nYou are given two strings $S$ and $R$. Each of these strings has length $N$. We want to make $S$ equal to $R$ by performing the following operation some number of times (possibly zero):\n- Choose two integers $a$ and $b$ such that $1 \\le a \\le b \\le N$.\n- For each $i$ such that $a \\le i \\le b$, replace the $i$-th character of $S$ by the $i$-th character of $R$.\nSuppose that we make $S$ equal to $R$ by performing this operation $k$ times, in such a way that the total number of replaced characters (i.e. the sum of all $k$ values of $b-a+1$) is $l$. Then, the cost of this process is defined as $k \\cdot l$.\nFind the minimum cost with which we can make $S$ equal to $R$.\n\n-----Input-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The first line of each test case contains a single string $S$.\n- The second line contains a single string $R$.\n\n-----Output-----\nFor each test case, print a single line containing one integer \u2015 the minimum cost.\n\n-----Constraints-----\n- $1 \\le T \\le 4,000$\n- $1 \\le N \\le 10^6$\n- $|S| = |R| = N$\n- $S$ and $R$ contain only lowercase English letters\n- the sum of $N$ over all test cases does not exceed $2 \\cdot 10^6$\n\n-----Example Input-----\n1\nadefb\nbdefa\n\n-----Example Output-----\n4\n\n-----Explanation-----\nExample case 1: $S$ can be made equal to $R$ in two moves. First, we replace $S_1$ by $R_1$ and then replace $S_5$ by $R_5$. We have $k = l = 2$, so the cost is $2 \\cdot 2 = 4$. If we wanted to perform only one operation, the cost would be $5$.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfor t in range(int(input())):\n s = input()\n r = input()\n diff = list()\n index = list()\n cnt = 0\n for i in range(len(s)):\n if s[i] != r[i]:\n cnt += 1\n index.append(i)\n for i in range(1, len(index)):\n diff.append(index[i] - index[i - 1] - 1)\n diff.sort()\n fmin = cnt ** 2\n oper = cnt ; moves = cnt\n for i in diff:\n moves += i\n oper -= 1\n fmin = min(fmin, moves * oper)\n print(fmin)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\nadefb\\nbdefa\\n', 'output': '4\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/MINOPS'}","problem_id":"vfc_3658","program":"```python\nfor t in range(int(input())):\n s = input()\n r = input()\n diff = list()\n index = list()\n cnt = 0\n for i in range(len(s)):\n if s[i] != r[i]:\n cnt += 1\n index.append(i)\n for i in range(1, len(index)):\n diff.append(index[i] - index[i - 1] - 1)\n diff.sort()\n fmin = cnt ** 2\n oper = cnt ; moves = cnt\n for i in diff:\n moves += i\n oper -= 1\n fmin = min(fmin, moves * oper)\n print(fmin)\n```","inputs":"1\nadefb\nbdefa\n","output":"4\n","actual_output":"4\n","execution_success":true,"sample_index":800},{"source":"apps","task_type":"verifiable_code","in_source_id":"1205","prompt":"Solve the following coding problem using the programming language python:\n\nDo you know Professor Saeed? He is the algorithms professor at Damascus University. Yesterday, he gave his students hard homework (he is known for being so evil) - for a given binary string $S$, they should compute the sum of $F(S, L, R)$ over all pairs of integers $(L, R)$ ($1 \\le L \\le R \\le |S|$), where the function $F(S, L, R)$ is defined as follows:\n- Create a string $U$: first, set $U = S$, and for each $i$ ($L \\le i \\le R$), flip the $i$-th character of $U$ (change '1' to '0' or '0' to '1').\n- Then, $F(S, L, R)$ is the number of valid pairs $(i, i + 1)$ such that $U_i = U_{i+1}$.\nAs usual, Professor Saeed will give more points to efficient solutions. Please help the students solve this homework.\n\n-----Input-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The first and only line of each test case contains a single string $S$.\n\n-----Output-----\nFor each test case, print a single line containing one integer $\\sum_{1 \\le L \\le R \\le |S|} F(S, L, R)$.\n\n-----Constraints-----\n- $1 \\le T \\le 100$\n- $1 \\le |S| \\le 3 \\cdot 10^6$\n- the sum of $|S|$ over all test cases does not exceed $6 \\cdot 10^6$\n\n-----Subtasks-----\nSubtask #1 (50 points):\n- $1 \\le |S| \\le 300$\n- the sum of $|S|$ over all test cases does not exceed $600$\nSubtask #2 (50 points): original constraints\n\n-----Example Input-----\n1\n001\n\n-----Example Output-----\n6\n\n-----Explanation-----\nExample case 1:\n- $L = 1, R = 1$: $U$ is \"101\", $F = 0$\n- $L = 2, R = 2$: $U$ is \"011\", $F = 1$\n- $L = 3, R = 3$: $U$ is \"000\", $F = 2$\n- $L = 1, R = 2$: $U$ is \"111\", $F = 2$\n- $L = 2, R = 3$: $U$ is \"010\", $F = 0$\n- $L = 1, R = 3$: $U$ is \"110\", $F = 1$\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfor _ in range(int(input())):\n s=input()\n n=len(s)\n t=0\n ans=0\n for i in range(n-1):\n if(s[i]==s[i+1]):\n t=t+1\n x=t\n for i in range(n):\n t=x\n if(i!=0):\n if(s[i]==s[i-1]):\n t=t-1\n else:\n t=t+1\n y=t\n for j in range(i,n):\n t=y\n try:\n if(s[j]==s[j+1]):\n t=t-1\n else:\n t=t+1\n except:\n pass\n ans=ans+t\n print(ans)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n001\\n', 'output': '6\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/EVIPRO'}","problem_id":"vfc_3662","program":"```python\nfor _ in range(int(input())):\n s=input()\n n=len(s)\n t=0\n ans=0\n for i in range(n-1):\n if(s[i]==s[i+1]):\n t=t+1\n x=t\n for i in range(n):\n t=x\n if(i!=0):\n if(s[i]==s[i-1]):\n t=t-1\n else:\n t=t+1\n y=t\n for j in range(i,n):\n t=y\n try:\n if(s[j]==s[j+1]):\n t=t-1\n else:\n t=t+1\n except:\n pass\n ans=ans+t\n print(ans)\n```","inputs":"1\n001\n","output":"6\n","actual_output":"6\n","execution_success":true,"sample_index":801},{"source":"apps","task_type":"verifiable_code","in_source_id":"1207","prompt":"Solve the following coding problem using the programming language python:\n\nChef is the new king of the country Chefland. As first and most important responsibility he wants to reconstruct the road system of Chefland. There are N (1 to N) cities in the country and each city i has a population Pi. Chef wants to build some bi-directional roads connecting different cities such that each city is connected to every other city (by a direct road or through some other intermediate city) and starting from any city one can visit every other city in the country through these roads. Cost of building a road between two cities u and v is Pu x Pv. Cost to build the road system is the sum of cost of every individual road that would be built. \nHelp king Chef to find the minimum cost to build the new road system in Chefland such that every city is connected to each other.\n\n-----Input-----\nThe first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows. \nFirst line contains an integer N denoting the number of cities in the country. Second line contains N space separated integers Pi, the population of i-th city.\n\n-----Output-----\nFor each test case, print a single integer, the minimum cost to build the new road system on separate line.\n\n-----Constraints-----\n- 1 \u2264 T \u2264 10\n- 1 \u2264 N \u2264 105\n- 1 \u2264 Pi \u2264 106\n\n-----Example-----\nInput:\n2\n2\n5 10\n4\n15 10 7 13\n\nOutput:\n50\n266\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nt=int(input())\nfor _ in range(t):\n n=int(input())\n a=list(map(int,input().split()))\n a.sort()\n s=sum(a)\n if a[0]*(s-a[0])<=a[n-1]*(s-a[n-1]):\n print(a[0]*(s-a[0]))\n else:\n print(a[n-1]*(s-a[n-1]))\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n2\\n5 10\\n4\\n15 10 7 13\\n', 'output': '50\\n266\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/KINGSHIP'}","problem_id":"vfc_3670","program":"```python\nt=int(input())\nfor _ in range(t):\n n=int(input())\n a=list(map(int,input().split()))\n a.sort()\n s=sum(a)\n if a[0]*(s-a[0])<=a[n-1]*(s-a[n-1]):\n print(a[0]*(s-a[0]))\n else:\n print(a[n-1]*(s-a[n-1]))\n```","inputs":"2\n2\n5 10\n4\n15 10 7 13\n","output":"50\n266\n","actual_output":"50\n266\n","execution_success":true,"sample_index":803},{"source":"apps","task_type":"verifiable_code","in_source_id":"1208","prompt":"Solve the following coding problem using the programming language python:\n\nChef is solving mathematics problems. He is preparing for Engineering Entrance exam. He's stuck in a problem.\n$f(n)=1^n*2^{n-1}*3^{n-2} * \\ldots * n^{1} $ \nHelp Chef to find the value of $f(n)$.Since this number could be very large, compute it modulo $1000000007$.\n\n-----Input:-----\n- First line will contain $T$, number of testcases. Then the testcases follow. \n- Each testcase contains of a single line of input, $N$. \n\n-----Output:-----\nFor each testcase, output in a single line the value of $f(n)$ mod $1000000007$.\n\n-----Constraints-----\n- $1 \\leq T \\leq 10^6$\n- $1 \\leq N \\leq 10^6$\n\n-----Subtasks-----\nSubtask 1(24 points) : \n- $1 \\leq T \\leq 5000$\n- $1 \\leq N \\leq 5000$\nSubtask 2(51 points) : original constraints\n\n-----Sample Input:-----\n1\n3\n\n-----Sample Output:-----\n12\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nT=int(input())\nt=[]\nfor _ in range(T):\n N=int(input())\n t.append(N)\nN=max(t)+1\nl=[0 for i in range(N)]\np=1\na=1\nfor i in range(1,N):\n a=(a*i)%1000000007\n p=p*a%1000000007\n l[i]=p\nfor i in t:\n print(l[i])\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n3\\n', 'output': '12\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/MATHL'}","problem_id":"vfc_3674","program":"```python\nT=int(input())\nt=[]\nfor _ in range(T):\n N=int(input())\n t.append(N)\nN=max(t)+1\nl=[0 for i in range(N)]\np=1\na=1\nfor i in range(1,N):\n a=(a*i)%1000000007\n p=p*a%1000000007\n l[i]=p\nfor i in t:\n print(l[i])\n\n```","inputs":"1\n3\n","output":"12\n","actual_output":"12\n","execution_success":true,"sample_index":804},{"source":"apps","task_type":"verifiable_code","in_source_id":"1209","prompt":"Solve the following coding problem using the programming language python:\n\nIt's winter and taking a bath is a delicate matter. Chef has two buckets of water. The first bucket has $v_1$ volume of cold water at temperature $t_1$. The second has $v_2$ volume of hot water at temperature $t_2$. Chef wants to take a bath with at least $v_3$ volume of water which is at exactly $t_3$ temperature. To get the required amount of water, Chef can mix some water obtained from the first and second buckets.\nMixing $v_x$ volume of water at temperature $t_x$ with $v_y$ volume of water at temperature $t_y$ yields $v_x + v_y$ volume of water at temperature calculated as\nvxtx+vytyvx+vyvxtx+vytyvx+vy\\frac{v_x t_x + v_y t_y}{v_x + v_y}\nHelp Chef figure out if it is possible for him to take a bath with at least $v_3$ volume of water at temperature $t_3$.\nAssume that Chef has no other source of water and that no heat is lost by the water in the buckets with time, so Chef cannot simply wait for the water to cool.\n\n-----Input-----\n- The first line contains $n$, the number of test cases. $n$ cases follow.\n- Each testcase contains of a single line containing 6 integers $v_1, t_1, v_2, t_2, v_3, t_3$.\n\n-----Output-----\n- For each test case, print a single line containing \"YES\" if Chef can take a bath the way he wants and \"NO\" otherwise.\n\n-----Constraints-----\n- $1 \\leq n \\leq 10^5$\n- $1 \\leq v_1, v_2, v_3 \\leq 10^6$\n- $1 \\leq t_1 < t_2 \\leq 10^6$\n- $1 \\leq t_3 \\leq 10^6$\n\n-----Sample Input-----\n3\n5 10 5 20 8 15\n5 10 5 20 1 30\n5 10 5 20 5 20\n\n-----Sample Output-----\nYES\nNO\nYES\n\n-----Explanation-----\n- Case 1: Mixing all the water in both buckets yields 10 volume of water at temperature 15, which is more than the required 8.\n- Case 2: It is not possible to get water at 30 temperature.\n- Case 3: Chef can take a bath using only the water in the second bucket.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\ntry:\n for i in range(int(input())):\n v1,t1,v2,t2,v3,t3=map(int,input().split())\n ok = 0\n if t1 <= t3 <= t2:\n x, y = t2 - t3, t3 - t1\n ok = x * v3 <= (x + y) * v1 and y * v3 <= (x + y) * v2\n print('YES' if ok else 'NO')\n \nexcept:\n pass\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\n5 10 5 20 8 15\\n5 10 5 20 1 30\\n5 10 5 20 5 20\\n', 'output': 'YES\\nNO\\nYES\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/CLBATH'}","problem_id":"vfc_3678","program":"```python\n# cook your dish here\ntry:\n for i in range(int(input())):\n v1,t1,v2,t2,v3,t3=map(int,input().split())\n ok = 0\n if t1 <= t3 <= t2:\n x, y = t2 - t3, t3 - t1\n ok = x * v3 <= (x + y) * v1 and y * v3 <= (x + y) * v2\n print('YES' if ok else 'NO')\n \nexcept:\n pass\n```","inputs":"3\n5 10 5 20 8 15\n5 10 5 20 1 30\n5 10 5 20 5 20\n","output":"YES\nNO\nYES\n","actual_output":"YES\nNO\nYES\n","execution_success":true,"sample_index":805},{"source":"apps","task_type":"verifiable_code","in_source_id":"1210","prompt":"Solve the following coding problem using the programming language python:\n\n-----Problem Statement-----\nOne of the things JEC is known for is its GR (Group Recreation) where juniors and seniors do friendly interaction ;P\nAs for the new session of 2020 seniors decided to have their first GR and give them some treat. Juniors were excited about it they came to college canteen aligned in a line and counted themselves one by one from left to right so that every junior gets his/her treat. But seniors played a game and they will treat only the ones who passes in this game. Game is simple all they need to do is to alternate their language (between Hindi and English) while telling their positions that is if the junior just before you told 2 in English you need to say 3 in Hindi . You do not want to be the one left without a treat. \nYou are the junior standing at position $X$ from left and the counting could start from left or right you have to predict which number you have to speak and in which language when your turn comes.\n\n-----Input:-----\n- \nFirst line will contain $T$, number of testcases. Then the testcases follow. \n- \nEach testcase contains 2 lines first consist 2 space separated integers, $N$ (total count) , $X$ (your position from left), next line consist of 2 space separated characters L or R (Direction from which counting starts L-left, R-Right) and H or E (the language to start counting).\n\n-----Output:-----\nFor each testcase, output a single line consisting space seperated Integer P and Character L\nwhere P is the number you will speak and L is the language (H or E).\n\n-----Constraints-----\n- $1 \\leq T \\leq 1000$\n- $1 \\leq N \\leq 120$\n- $1 \\leq X \\leq N$\n\n-----Sample Input:-----\n2\n15 5\nL H\n20 14\nR E\n\n*try to trim extra white spaces like new line during input in case of wrong answer\n\n-----Sample Output:-----\n5 H\n7 E\n\n-----EXPLANATION:-----\n- When counting starts from left with H it alternates like H E H E H\u2026.. on the fifth position H comes\n- When Count starts from right with E it alternates like E H E H E H E\u2026.. with E on the position of 14th student from right.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nt=int(input())\nwhile t:\n t=t-1\n n,x=input().split()\n n=int(n)\n x=int(x)\n d,l=input().split()\n\n if d=='L':\n p=x\n elif d=='R':\n p=(n-x)+1\n\n if p%2==1:\n if l=='H':\n lang='H'\n else:\n lang='E'\n elif p%2==0:\n if l=='H':\n lang='E'\n else:\n lang='H'\n print(p,lang)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n15 5\\nL H\\n20 14\\nR E\\n*try to trim extra white spaces like new line during input in case of wrong answer\\n', 'output': '5 H\\n7 E\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/COPT2020/problems/GRDAY1'}","problem_id":"vfc_3682","program":"```python\nt=int(input())\nwhile t:\n t=t-1\n n,x=input().split()\n n=int(n)\n x=int(x)\n d,l=input().split()\n\n if d=='L':\n p=x\n elif d=='R':\n p=(n-x)+1\n\n if p%2==1:\n if l=='H':\n lang='H'\n else:\n lang='E'\n elif p%2==0:\n if l=='H':\n lang='E'\n else:\n lang='H'\n print(p,lang)\n```","inputs":"2\n15 5\nL H\n20 14\nR E\n*try to trim extra white spaces like new line during input in case of wrong answer\n","output":"5 H\n7 E\n","actual_output":"5 H\n7 E\n","execution_success":true,"sample_index":806},{"source":"apps","task_type":"verifiable_code","in_source_id":"1211","prompt":"Solve the following coding problem using the programming language python:\n\nThe chef is having one string of English lower case alphabets only. The chef wants to remove all \"abc\" special pairs where a,b,c are occurring consecutively. After removing the pair, create a new string and again remove \"abc\" special pair from a newly formed string. Repeate the process until no such pair remains in a string.\n\n-----Input:-----\n- First line will contain $T$, number of testcases. Then the testcases follow. \n- Each testcase contains of a single line of input, $String$. \n\n-----Output:-----\nFor each testcase, output in a single line answer, new String with no \"abc\" special pair.\n\n-----Constraints:-----\n$T \\leq 2 $\n$1 \\leq String length \\leq 1000 $\n\n-----Sample Input:-----\n2\naabcc\nbababccc\n\n-----Sample Output:-----\nac\nbc\n\n-----EXPLANATION:-----\nFor 1) after removing \"abc\" at middle we get a new string as ac.\nFor 2) string = bababccc\nnewString1 = babcc // After removing middle \"abc\"\nnewString2 = bc //After removing \"abc\"\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\nfor _ in range(int(input())):\n s=input()\n while(s.count(\"abc\")!=0):\n s=s.replace(\"abc\",\"\")\n print(s) \n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\naabcc\\nbababccc\\n', 'output': 'ac\\nbc\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/PBK12020/problems/ITGUY15'}","problem_id":"vfc_3686","program":"```python\n# cook your dish here\nfor _ in range(int(input())):\n s=input()\n while(s.count(\"abc\")!=0):\n s=s.replace(\"abc\",\"\")\n print(s) \n\n```","inputs":"2\naabcc\nbababccc\n","output":"ac\nbc\n","actual_output":"ac\nbc\n","execution_success":true,"sample_index":807},{"source":"apps","task_type":"verifiable_code","in_source_id":"1212","prompt":"Solve the following coding problem using the programming language python:\n\n\"Everything in the universe is balanced. Every disappointment you face in life will be balanced by something good for you! Keep going, never give up.\"\nLet's call a string balanced if all characters that occur in this string occur in it the same number of times.\nYou are given a string $S$; this string may only contain uppercase English letters. You may perform the following operation any number of times (including zero): choose one letter in $S$ and replace it by another uppercase English letter. Note that even if the replaced letter occurs in $S$ multiple times, only the chosen occurrence of this letter is replaced.\nFind the minimum number of operations required to convert the given string to a balanced string.\n\n-----Input-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The first and only line of each test case contains a single string $S$.\n\n-----Output-----\nFor each test case, print a single line containing one integer \u2015 the minimum number of operations.\n\n-----Constraints-----\n- $1 \\le T \\le 10,000$\n- $1 \\le |S| \\le 1,000,000$\n- the sum of $|S|$ over all test cases does not exceed $5,000,000$\n- $S$ contains only uppercase English letters\n\n-----Subtasks-----\nSubtask #1 (20 points):\n- $T \\le 10$\n- $|S| \\le 18$\nSubtask #2 (80 points): original constraints\n\n-----Example Input-----\n2\nABCB\nBBC\n\n-----Example Output-----\n1\n1\n\n-----Explanation-----\nExample case 1: We can change 'C' to 'A'. The resulting string is \"ABAB\", which is a balanced string, since the number of occurrences of 'A' is equal to the number of occurrences of 'B'.\nExample case 2: We can change 'C' to 'B' to make the string \"BBB\", which is a balanced string.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfrom sys import stdin\nfrom collections import Counter\n\ndef func(arr,n,l):\n count=0\n k=l//n\n if nt2:\n print(\"Kefa\")\n elif t1==t2:\n print(\"Draw\")\n else:\n pass\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\n1 3 2 1 2\\n1 5 2 1 2\\n1 5 3 2 2\\n', 'output': 'Kefa\\nChef\\nDraw\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/CHEFRUN'}","problem_id":"vfc_3694","program":"```python\n# cook your dish here\nfor t in range(int(input())):\n x1,x2,x3,v1,v2=[int(x)for x in input().rstrip().split()]\n t1=abs(x3-x1)/v1\n t2=abs(x3-x2)/v2\n if t1t2:\n print(\"Kefa\")\n elif t1==t2:\n print(\"Draw\")\n else:\n pass\n\n```","inputs":"3\n1 3 2 1 2\n1 5 2 1 2\n1 5 3 2 2\n","output":"Kefa\nChef\nDraw\n","actual_output":"Kefa\nChef\nDraw\n","execution_success":true,"sample_index":809},{"source":"apps","task_type":"verifiable_code","in_source_id":"1214","prompt":"Solve the following coding problem using the programming language python:\n\nEverybody is worried about Rakesh as the boy does not have much knowledge about the real world. He can not go from one place to another on his own. It's high time he learned to explore the city. He is going to a relative's house situated on the other side of the city on his own. As this is his first time, he is carrying a GPS tracker of a special kind. The tracker continuously sends information to the family of Rakesh about his movement. The information is sent using the following four letters: U, D, R, and L. Those letters indicate the moves taken by Rakesh. \n\nThe city can be considered as a grid. Rakesh starts his journey from (0, 0) position of the grid. His relative's house is situated at (Rx, Ry). Rakesh can move in four directions: up, down, right, or left indicated by U, D, R, and L respectively. \n\nAny position of the city with x ordinate negative or greater than M is considered as dangerous. Also, any position of the city with y ordinate negative or greater than N is considered as dangerous. You will be given the total sequence of Rakesh's movement. You need to determine if Rakesh ended up being at his relative's house, at a dangerous place, or at a random place in the city.\n\nTo make things clear,\n\n- U indicates a move that increases position along y-axis by 1 \n- D indicates a move that decreases position along y-axis by 1 \n- R indicates a move that increases position along x-axis by 1 \n- L indicates a move that decreases position along x-axis by 1 \n\nNote that we are interested in the position of Rakesh at the end of his journey only. He may visit some dangerous place or his relative's house at some intermediate point but that won't affect the answer.\n\n-----Input-----\n- The first line of the input contains an integer T denoting the number of test cases. The description of each test case follows.\n\n- The first line of each test case contains two integers M and N.\n- The second line contains two integers Rx and Ry.\n- The third line contains the length of Rakesh's move sequence.\n- The next line contains the move sequence containing letters U, D, R, and L only with no space.\n\n-----Output-----\nFor each test case, print \"Case i: \", and then the answer, where i is the testcase number, 1-indexed. The answer should be any of the following three strings:\n- \"REACHED\" if Rakesh could reach his relative's house \n- \"DANGER\" if Rakesh ended up being in a dangerous place \n- \"SOMEWHERE\" if Rakesh ended up being in somewhere safe place in the city other than his relative's place \nDon't print any quotation mark. Check the sample output.\n\n-----Constraints-----\n\n- 1 \u2264 T \u2264 10\n- 0 \u2264 M, N \u2264 10000\n- 0 \u2264 Rx \u2264 M \n- 0 \u2264 Ry \u2264 N \n- 0 \u2264 Sum of the lengths of all sequences \u2264 10000\n\n-----Example-----\nInput:\n2\n20 20\n4 5\n13\nLLUUUUURRRRRR\n10 10\n3 4\n7\nUDUDDRR\n\nOutput:\nCase 1: REACHED\nCase 2: DANGER\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\ntry:\n t=int(input())\n for i in range(t):\n print(\"Case {}:\".format(i+1), end=\" \")\n m, n = map(int,input().split())\n x, y = map(int,input().split())\n l = int(input())\n a=input()\n destx = a.count(\"R\")-a.count(\"L\")\n desty = a.count(\"U\")-a.count(\"D\")\n #print(destx, desty)\n \n if (destx<0 or destx>m) or (desty<0 or desty>n):\n result = \"DANGER\"\n elif destx == x and desty == y:\n result = \"REACHED\"\n else:\n result = \"SOMEWHERE\"\n \n print(result)\nexcept:\n pass\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n20 20\\n4 5\\n13\\nLLUUUUURRRRRR\\n10 10\\n3 4\\n7\\nUDUDDRR\\n', 'output': 'Case 1: REACHED\\nCase 2: DANGER\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/ZUBREACH'}","problem_id":"vfc_3698","program":"```python\ntry:\n t=int(input())\n for i in range(t):\n print(\"Case {}:\".format(i+1), end=\" \")\n m, n = map(int,input().split())\n x, y = map(int,input().split())\n l = int(input())\n a=input()\n destx = a.count(\"R\")-a.count(\"L\")\n desty = a.count(\"U\")-a.count(\"D\")\n #print(destx, desty)\n \n if (destx<0 or destx>m) or (desty<0 or desty>n):\n result = \"DANGER\"\n elif destx == x and desty == y:\n result = \"REACHED\"\n else:\n result = \"SOMEWHERE\"\n \n print(result)\nexcept:\n pass\n```","inputs":"2\n20 20\n4 5\n13\nLLUUUUURRRRRR\n10 10\n3 4\n7\nUDUDDRR\n","output":"Case 1: REACHED\nCase 2: DANGER\n","actual_output":"Case 1: REACHED\nCase 2: DANGER\n","execution_success":true,"sample_index":810},{"source":"apps","task_type":"verifiable_code","in_source_id":"1215","prompt":"Solve the following coding problem using the programming language python:\n\nTwo friends David and Rojer were preparing for their weekly class-test.\nThe are preparing for the math test, but because of continuously adding big integers and solving equations they got exhausted. They decided to take break and play a game. They play a game which will help them in both(for having fun and will also help to prepare for math test).\nThere are N words and they have to find RESULT with the help of these words (just like they have N integers and they have to find integer RESULT=sum of N integers) . Since they are playing this game for the first time! They are not too good in this. Help them in finding weather their RESULT is correct or not. \nNOTE:- Total number of unique characters in N words are not greater than 10. All input words and RESULT are in UPPER-CASE only!\nRefer Here for how to add numbers : https://en.wikipedia.org/wiki/Verbal_arithmetic\n\n-----Input:-----\n- First line consist of an integer N (total number of words).\n- Next N line contains words with which they have to find RESULT.\n- Last line consist of the RESULT they found.\n\n-----Output:-----\nIf RESULT is correct print true else print false.\n\n-----Sample Input:-----\n3\n\nTHIS\n\nIS\n\nTOO\n\nFUNNY \n\n-----Sample Output:-----\ntrue\n\n-----Constraints-----\n- $2 \\leq N \\leq 10$\n- $1 \\leq Length of The word \\leq 10$\n- $1 \\leq Length of The Result \\leq 11$\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\ndef isSolvable( W, R):\r\n LW, LR, F, ML, AW, V, LMap = len(W), len(R), set([w[0] for w in W+[R]]), max(map(len, W+[R])), W+[R], set(), {}\r\n if LR < ML: return False\r\n def dfs(d,i,c):\r\n if d == ML: return c == 0\r\n if i == len(W) + 1:\r\n s = sum(LMap[w[-d-1]] if d < len(w) else 0 for w in W) + c\r\n return dfs(d+1,0,s//10) if s % 10 == LMap[R[-d-1]] else False\r\n if i < LW and d >= len(W[i]): return dfs(d,i+1,c)\r\n ch = AW[i][-d-1]\r\n if ch in LMap: return dfs(d,i+1,c)\r\n for x in range((ch in F), 10):\r\n if x not in V:\r\n LMap[ch], _ = x, V.add(x)\r\n if dfs(d,i+1,c): return True\r\n V.remove(LMap.pop(ch))\r\n return dfs(0,0,0)\r\nn=int(input())\r\nW=[]\r\nfor i in range(n):\r\n W.append(str(input()))\r\nR=input() \r\na=(isSolvable(W,R))\r\nif a==True:\r\n print(\"true\")\r\nelse:\r\n print(\"false\")\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\nTHIS\\nIS\\nTOO\\nFUNNY\\n', 'output': 'true\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/CHLG2020/problems/MATH88'}","problem_id":"vfc_3702","program":"```python\ndef isSolvable( W, R):\r\n LW, LR, F, ML, AW, V, LMap = len(W), len(R), set([w[0] for w in W+[R]]), max(map(len, W+[R])), W+[R], set(), {}\r\n if LR < ML: return False\r\n def dfs(d,i,c):\r\n if d == ML: return c == 0\r\n if i == len(W) + 1:\r\n s = sum(LMap[w[-d-1]] if d < len(w) else 0 for w in W) + c\r\n return dfs(d+1,0,s//10) if s % 10 == LMap[R[-d-1]] else False\r\n if i < LW and d >= len(W[i]): return dfs(d,i+1,c)\r\n ch = AW[i][-d-1]\r\n if ch in LMap: return dfs(d,i+1,c)\r\n for x in range((ch in F), 10):\r\n if x not in V:\r\n LMap[ch], _ = x, V.add(x)\r\n if dfs(d,i+1,c): return True\r\n V.remove(LMap.pop(ch))\r\n return dfs(0,0,0)\r\nn=int(input())\r\nW=[]\r\nfor i in range(n):\r\n W.append(str(input()))\r\nR=input() \r\na=(isSolvable(W,R))\r\nif a==True:\r\n print(\"true\")\r\nelse:\r\n print(\"false\")\n```","inputs":"3\nTHIS\nIS\nTOO\nFUNNY\n","output":"true\n","actual_output":"true\n","execution_success":true,"sample_index":811},{"source":"apps","task_type":"verifiable_code","in_source_id":"1216","prompt":"Solve the following coding problem using the programming language python:\n\nToday Chef wants to evaluate the dishes of his $N$ students. He asks each one to cook a dish and present it to him.\nChef loves his secret ingredient, and only likes dishes with at least $X$ grams of it.\nGiven $N$, $X$ and the amount of secret ingredient used by each student $A_i$, find out whether Chef will like at least one dish. \n\n-----Input:-----\n- First line will contain $T$, number of testcases. Then the testcases follow. \n- The first line of each testcase contains two integers $N$ \n(number of students) and $X$ (minimum amount of secret ingredient that a dish must contain for Chef to like it).\n- The next line contains $N$ space separated integers, $A_i$ denoting the amount of secret ingredient used by the students in their dishes.\n\n-----Output:-----\nFor each testcase, print a single string \"YES\" if Chef likes at least one dish. Otherwise, print \"NO\". (Without quotes).\n\n-----Constraints:-----\n- $1 \\leq T \\leq 100$\n- $1 \\leq N \\leq 1000$\n- $1 \\leq X \\leq 1000000$\n- $1 \\leq A_i \\leq 1000000$\n\n-----Sample Input:-----\n3\n5 100\n11 22 33 44 55\n5 50\n10 20 30 40 50\n5 45\n12 24 36 48 60\n\n-----Sample Output:-----\nNO\nYES\nYES\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nt=int(input())\nfor i in range(t):\n n,k=map(int,input().split())\n m=list(map(int,input().split()))\n a=0\n for i in m:\n if i>=k:\n a=1\n break\n if a==1:\n print('YES')\n else:\n print('NO')\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\n5 100\\n11 22 33 44 55\\n5 50\\n10 20 30 40 50\\n5 45\\n12 24 36 48 60\\n', 'output': 'NO\\nYES\\nYES\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/PCJ18A'}","problem_id":"vfc_3706","program":"```python\nt=int(input())\nfor i in range(t):\n n,k=map(int,input().split())\n m=list(map(int,input().split()))\n a=0\n for i in m:\n if i>=k:\n a=1\n break\n if a==1:\n print('YES')\n else:\n print('NO')\n```","inputs":"3\n5 100\n11 22 33 44 55\n5 50\n10 20 30 40 50\n5 45\n12 24 36 48 60\n","output":"NO\nYES\nYES\n","actual_output":"NO\nYES\nYES\n","execution_success":true,"sample_index":812},{"source":"apps","task_type":"verifiable_code","in_source_id":"1217","prompt":"Solve the following coding problem using the programming language python:\n\nChef has an array A = (A1, A2, ..., AN), which has N integers in it initially. Chef found that for i \u2265 1, if Ai > 0, Ai+1 > 0, and Ai+2 exists, then he can decrease both Ai, and Ai+1 by one and increase Ai+2 by one. If Ai+2 doesn't exist, but Ai > 0, and Ai+1 > 0, then he can decrease both Ai, and Ai+1 (which will be the currently last two elements of the array) by one and add a new element at the end, whose value is 1.\nNow Chef wants to know the number of different arrays that he can make from A using this operation as many times as he wishes. Help him find this, and because the answer could be very large, he is fine with you reporting the answer modulo 109+7.\nTwo arrays are same if they have the same number of elements and if each corresponding element is the same. For example arrays (2,1,1) and (1,1,2) are different. \n\n-----Input-----\n- The first line of the input contains a single integer T denoting the number of test cases.\n- The first line contains a single integer N denoting the initial number of elements in A.\n- The second line contains N space-separated integers: A1, A2, ... , AN. \n\n-----Output-----\nFor each test case, output answer modulo 109+7 in a single line. \n\n-----Constraints-----\n- 1 \u2264 T \u2264 5\n- 1 \u2264 N \u2264 50\n- 0 \u2264 Ai \u2264 50\n\n-----Subtasks-----\n- Subtask 1 (20 points) : 1 \u2264 N \u2264 8, 0 \u2264 Ai \u2264 4\n- Subtask 2 (80 points) : Original constraints\n\n-----Example-----\nInput:\n3\n3\n2 3 1\n2\n2 2\n3\n1 2 3\n\nOutput:\n9\n4\n9\n\n-----Explanation-----\nExample case 1.\nWe'll list the various single steps that you can take (ie. in one single usage of the operation):\n- (2, 3, 1) \u2192 (2, 2, 0, 1)\n- (2, 2, 0, 1) \u2192 (1, 1, 1, 1)\n- (1, 1, 1, 1) \u2192 (1, 1, 0, 0, 1)\n- (1, 1, 0, 0, 1) \u2192 (0, 0, 1, 0, 1)\n- (1, 1, 1, 1) \u2192 (1, 0, 0, 2)\n- (1, 1, 1, 1) \u2192 (0, 0, 2, 1)\n- (2, 3, 1) \u2192 (1, 2, 2)\n- (1, 2, 2) \u2192 (0, 1, 3)\n\nSo all the arrays you can possibly get are: \n(2, 3, 1), (2, 2, 0, 1), (1, 1, 1, 1), (1, 1, 0, 0, 1), (0, 0, 1, 0, 1), (1, 0, 0, 2), (0, 0, 2, 1), (1, 2, 2), and (0, 1, 3)\nSince there are 9 different arrays that you can reach, the answer is 9.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\ndef fun(a,cur,n,cnt):\n if cur>=n-1:\n return\n for i in range(cur,n-1):\n if i0 and a[i+1]>0:\n a[i]-=1\n a[i+1]-=1\n a[i+2]+=1\n cnt[0]=(cnt[0]+1)%1000000007\n fun(a,i,n,cnt)\n a[i]+=1\n a[i+1]+=1\n a[i+2]-=1\n else:\n if a[i]>0 and a[i+1]>0:\n a[i]-=1\n a[i+1]-=1\n a.append(1)\n cnt[0]=(cnt[0]+1)%1000000007\n fun(a,i,n+1,cnt)\n a[i]+=1\n a[i+1]+=1\n a.pop()\ntc=int(input())\nfor case in range(tc):\n n=int(input())\n a=list(map(int,input().split()))\n cnt=[1]\n fun(a,0,n,cnt)\n print(cnt[0]%1000000007)\n \n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\n3\\n2 3 1\\n2\\n2 2\\n3\\n1 2 3\\n\\n\\n', 'output': '9\\n4\\n9\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/AUG17/problems/CHEFFA'}","problem_id":"vfc_3710","program":"```python\ndef fun(a,cur,n,cnt):\n if cur>=n-1:\n return\n for i in range(cur,n-1):\n if i0 and a[i+1]>0:\n a[i]-=1\n a[i+1]-=1\n a[i+2]+=1\n cnt[0]=(cnt[0]+1)%1000000007\n fun(a,i,n,cnt)\n a[i]+=1\n a[i+1]+=1\n a[i+2]-=1\n else:\n if a[i]>0 and a[i+1]>0:\n a[i]-=1\n a[i+1]-=1\n a.append(1)\n cnt[0]=(cnt[0]+1)%1000000007\n fun(a,i,n+1,cnt)\n a[i]+=1\n a[i+1]+=1\n a.pop()\ntc=int(input())\nfor case in range(tc):\n n=int(input())\n a=list(map(int,input().split()))\n cnt=[1]\n fun(a,0,n,cnt)\n print(cnt[0]%1000000007)\n \n\n```","inputs":"3\n3\n2 3 1\n2\n2 2\n3\n1 2 3\n\n\n","output":"9\n4\n9\n","actual_output":"9\n4\n9\n","execution_success":true,"sample_index":813},{"source":"apps","task_type":"verifiable_code","in_source_id":"1218","prompt":"Solve the following coding problem using the programming language python:\n\nRichik$Richik$ has just completed his engineering and has got a job in one of the firms at Sabrina$Sabrina$ which is ranked among the top seven islands in the world in terms of the pay scale. \nSince Richik$Richik$ has to travel a lot to reach the firm, the owner assigns him a number X$X$, and asks him to come to work only on the day which is a multiple of X$X$. Richik joins the firm on 1-st day but starts working from X-th day. Richik$Richik$ is paid exactly the same amount in Dollars as the day number. For example, if Richik$Richik$ has been assigned X=3$X = 3$, then he will be paid 3$3$ dollars and 6$6$ dollars on the 3rd$3rd$ and 6th$6th$ day on which he comes for work. \nOn N\u2212th$N-th$ day, the owner calls up Richik$Richik$ and asks him not to come to his firm anymore. Hence Richik$Richik$ demands his salary of all his working days together. Since it will take a lot of time to add, Richik$Richik$ asks help from people around him, let's see if you can help him out. \n\n-----Input:-----\n- First line will contain T$T$, number of testcases. Then the testcases follow. \n- Each testcase contains of a single line of input, two integers X,N$X, N$. \n\n-----Output:-----\nFor each testcase, output in a single line which is the salary which Richik$Richik$ demands. \n\n-----Constraints-----\n- 1\u2264T\u22641000$1 \\leq T \\leq 1000$\n- 1\u2264X<=N\u2264107$1 \\leq X<=N \\leq 10^7$\n\n-----Sample Input:-----\n1\n3 10\n\n-----Sample Output:-----\n18\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nt=int(input())\r\nfor i in range(t):\r\n x,n=[int(g) for g in input().split()]\r\n sal=0\r\n day=x\r\n while day>b) & 1:\r\n S[i] += [p]\r\n B = set(B)\r\n I = [0] * len(B)\r\n\r\n for _ in range(Q):\r\n b, K = RL()\r\n s = RL()\r\n x = 0\r\n for b in s:\r\n x += 1<>b) & 1:\r\n S[i] += [p]\r\n B = set(B)\r\n I = [0] * len(B)\r\n\r\n for _ in range(Q):\r\n b, K = RL()\r\n s = RL()\r\n x = 0\r\n for b in s:\r\n x += 1< Y$.\n- Change $X$ to $P$.\n- Add $P \\cdot P$ to $Y$.\nUnfortunately, Chef has a bad memory and he has forgotten the moves he made. He only remembers the value of $X$ after the game finished; let's denote it by $X_f$. Can you tell him the maximum possible number of moves he could have made in the game?\n\n-----Input-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The first and only line of each test case contains a single integer $X_f$.\n\n-----Output-----\nFor each test case, print a single line containing one integer \u2014 the maximum number of moves Chef could have made.\n\n-----Constraints-----\n- $1 \\le T \\le 10^5$\n- $1 \\le X_f \\le 10^9$\n\n-----Example Input-----\n3\n3\n8\n9\n\n-----Example Output-----\n3\n5\n6\n\n-----Explanation-----\nExample case 2: One possible sequence of values of $X$ is $0 \\rightarrow 1 \\rightarrow 2 \\rightarrow 3 \\rightarrow 5 \\rightarrow 8$.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfrom math import sqrt\n\nT = int(input())\nans = []\n\nfor _ in range(T):\n X = int(input())\n\n count = 0\n x = 0\n y = 0\n while(x<=X):\n p = int(sqrt(y))\n count += 1\n if(p*p>y):\n x = p\n y += p**2\n else:\n x = p+1\n y += (p+1)**2\n if(x<=X):\n ans.append(count)\n else:\n ans.append(count-1)\n\nfor i in ans:\n print(i)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\n3\\n8\\n9\\n', 'output': '3\\n5\\n6\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/TWOVRIBL'}","problem_id":"vfc_3726","program":"```python\nfrom math import sqrt\n\nT = int(input())\nans = []\n\nfor _ in range(T):\n X = int(input())\n\n count = 0\n x = 0\n y = 0\n while(x<=X):\n p = int(sqrt(y))\n count += 1\n if(p*p>y):\n x = p\n y += p**2\n else:\n x = p+1\n y += (p+1)**2\n if(x<=X):\n ans.append(count)\n else:\n ans.append(count-1)\n\nfor i in ans:\n print(i)\n```","inputs":"3\n3\n8\n9\n","output":"3\n5\n6\n","actual_output":"3\n5\n6\n","execution_success":true,"sample_index":817},{"source":"apps","task_type":"verifiable_code","in_source_id":"1222","prompt":"Solve the following coding problem using the programming language python:\n\nThe EEE classes are so boring that the students play games rather than paying attention during the lectures. Harsha and Dubey are playing one such game.\n\nThe game involves counting the number of anagramic pairs of a given string (you can read about anagrams from here). Right now Harsha is winning. Write a program to help Dubey count this number quickly and win the game!\n\n-----Input-----\nThe first line has an integer T which is the number of strings. Next T lines each contain a strings. Each string consists of lowercase english alphabets only.\n\n-----Output-----\nFor each string, print the answer in a newline.\n\n-----Constraints-----\n- 1 \u2264 T \u2264 1000\n- 1 \u2264 length of each string \u2264 100\n\n-----Example-----\nInput:\n3\nrama\nabba\nabcd\nOutput:\n2\n4\n0\n\n-----Explanation-----\nrama has the following substrings:\n\n- r\n- ra\n- ram\n- rama\n- a\n- am\n- ama\n- m\n- ma\n- a\nOut of these, {5,10} and {6,9} are anagramic pairs.\n\nHence the answer is 2.\n\nSimilarly for other strings as well.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\ndef sort_str(s):\n o = []\n for c in s:\n o.append(c)\n o.sort()\n return \"\".join(o)\ndef find_ana(s):\n if len(s) <= 1:\n return 0\n h = {}\n c = 0\n for i in range(len(s)):\n for j in range(i+1, len(s)+1):\n t = sort_str(s[i:j])\n if t in h:\n c += h[t]\n h[t] += 1\n else:\n h[t] = 1\n return c\nt = int(input())\nfor _ in range(t):\n print(find_ana(input()))\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\nrama\\nabba\\nabcd\\n', 'output': '2\\n4\\n0\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/COCU2016/problems/CURR2'}","problem_id":"vfc_3730","program":"```python\ndef sort_str(s):\n o = []\n for c in s:\n o.append(c)\n o.sort()\n return \"\".join(o)\ndef find_ana(s):\n if len(s) <= 1:\n return 0\n h = {}\n c = 0\n for i in range(len(s)):\n for j in range(i+1, len(s)+1):\n t = sort_str(s[i:j])\n if t in h:\n c += h[t]\n h[t] += 1\n else:\n h[t] = 1\n return c\nt = int(input())\nfor _ in range(t):\n print(find_ana(input()))\n```","inputs":"3\nrama\nabba\nabcd\n","output":"2\n4\n0\n","actual_output":"2\n4\n0\n","execution_success":true,"sample_index":818},{"source":"apps","task_type":"verifiable_code","in_source_id":"1223","prompt":"Solve the following coding problem using the programming language python:\n\nIt's the annual military parade, and all the soldier snakes have arrived at the parade arena, But they aren't standing properly. The entire parade must be visible from the main podium, and all the snakes must be in a line. But the soldiers are lazy, and hence you must tell the soldiers to move to their new positions in such a manner that the total movement is minimized.\nFormally, the entire parade strip can be thought of as the integer line. There are N snakes, where each snake is a line segment of length L. The i-th snake is initially at the segment [Si, Si + L]. The initial positions of the snakes can overlap. The only segment of the strip visible from the podium is [A, B], and hence all the snakes should be moved so that all of them are visible from the podium. They should also all be in a line without gaps and every consecutive pair touching each other. In other words, they should occupy the segments [X, X + L], [X + L, X + 2*L], ... , [X + (N-1)*L, X + N*L], for some X, such that A \u2264 X \u2264 X + N*L \u2264 B. You are guaranteed that the visible strip is long enough to fit all the snakes.\n\nIf a snake was initially at the position [X1, X1 + L] and finally is at the position [X2, X2 + L], then the snake is said to have moved a distance of |X2 - X1|. The total distance moved by the snakes is just the summation of this value over all the snakes. You need to move the snakes in such a manner that it satisfies all the conditions mentioned above, as well as minimize the total distance. You should output the minimum total distance achievable.\n\n-----Input-----\n- The first line contains a single integer, T, the number of testcases. The description of each testcase follows.\n- The first line of each testcase contains four integers, N, L, A and B, where N denotes the number of snakes, L denotes the length of each snake, and [A, B] is the segment visible from the podium.\n- The next line contains N integers, the i-th of which is Si. This denotes that the i-th snake is initially in the segment [Si, Si + L].\n\n-----Output-----\n- For each testcase, output a single integer in a new line: the minimum total distance achievable.\n\n-----Constraints-----\n- 1 \u2264 T \u2264 10\n- 1 \u2264 N \u2264 105\n- 1 \u2264 Si \u2264 109\n- 1 \u2264 L \u2264 109\n- 1 \u2264 A \u2264 B \u2264 109\n- N * L \u2264 B - A\n\n-----Example-----\nInput:\n2\n3 4 11 23\n10 11 30\n3 4 11 40\n10 11 30\n\nOutput:\n16\n16\n\n-----Explanation-----\nIn the first testcase, the three snakes are initially at segments [10, 14], [11, 15], and [30, 34]. One optimal solution is to move the first snake which was at [10, 14] to [15, 19] and the third snake which was at [30, 34] to [19, 23]. After this, the snakes would form a valid parade because they will be from [11, 15], [15, 19] and [19, 23]. Hence they are all in a line without any gaps in between them, and they are all visible, because they all lie in the visible segment, which is [11, 23].\nThe distance traveled by the first snake is |15 - 10| = 5, by the second snake is |11 - 11| = 0 and by the third snake is |19 - 30| = 11. Hence the total distance traveled is 5 + 0 + 11 = 16. This is the best that you can do, and hence the answer is 16.\nIn the second testcase, only the visible segment has increased. But you can check that the same final configuration as in the first subtask is still optimal here. Hence the answer is 16.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nt=int(input())\n \ndef vsense(val,a,l):\n sense=0\n ctr=a\n for c in range(n):\n if val[c]<=ctr:\n sense+=-1\n else:\n sense+=1\n ctr+=l\n return sense\n \nwhile t:\n n,l,a,b=list(map(int,input().split()))\n val=list(map(int,input().split()))\n val.sort()\n sense=0\n if b==a+n*l or vsense(val,a,l)<=0:\n loc=a\n else:\n st=a\n end=b-n*l\n while st<=end:\n m=(st+end)/2\n chk=vsense(val,m,l)\n if chk==0:\n loc=m\n break\n elif chk<0:\n end=m-1\n else:\n loc=m\n st=m+1\n ans=0\n st=loc\n for c in range(n):\n ans+=abs(st-val[c])\n st+=l\n print(ans)\n \n t-=1\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n3 4 11 23\\n10 11 30\\n3 4 11 40\\n10 11 30\\n', 'output': '16\\n16\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/CONSESNK'}","problem_id":"vfc_3734","program":"```python\nt=int(input())\n \ndef vsense(val,a,l):\n sense=0\n ctr=a\n for c in range(n):\n if val[c]<=ctr:\n sense+=-1\n else:\n sense+=1\n ctr+=l\n return sense\n \nwhile t:\n n,l,a,b=list(map(int,input().split()))\n val=list(map(int,input().split()))\n val.sort()\n sense=0\n if b==a+n*l or vsense(val,a,l)<=0:\n loc=a\n else:\n st=a\n end=b-n*l\n while st<=end:\n m=(st+end)/2\n chk=vsense(val,m,l)\n if chk==0:\n loc=m\n break\n elif chk<0:\n end=m-1\n else:\n loc=m\n st=m+1\n ans=0\n st=loc\n for c in range(n):\n ans+=abs(st-val[c])\n st+=l\n print(ans)\n \n t-=1\n\n```","inputs":"2\n3 4 11 23\n10 11 30\n3 4 11 40\n10 11 30\n","output":"16\n16\n","actual_output":"16\n16\n","execution_success":true,"sample_index":819},{"source":"apps","task_type":"verifiable_code","in_source_id":"1225","prompt":"Solve the following coding problem using the programming language python:\n\nTomya is a girl. She loves Chef Ciel very much.\n\nToday, too, Tomya is going to Ciel's restaurant.\nOf course, Tomya would like to go to Ciel's restaurant as soon as possible.\nTherefore Tomya uses one of the shortest paths from Tomya's house to Ciel's restaurant.\nOn the other hand, Tomya is boring now to use the same path many times.\nSo Tomya wants to know the number of shortest paths from Tomya's house to Ciel's restaurant.\nYour task is to calculate the number under the following assumptions.\n\nThis town has N intersections and M two way roads.\nThe i-th road connects from the Ai-th intersection to the Bi-th intersection, and its length is \n\nCi.\nTomya's house is in the 1st intersection, and Ciel's restaurant is in the N-th intersection.\n\n-----Input-----\n\nThe first line contains an integer T, the number of test cases.\nThen T test cases follow.\nThe first line of each test case contains 2 integers N, M.\nThen next M lines contains 3 integers denoting Ai, Bi and Ci.\n\n-----Output-----\n\nFor each test case, print the number of shortest paths from Tomya's house to Ciel's restaurant.\n\n-----Constraints-----\n\n1 \u2264 T \u2264 10\n\n2 \u2264 N \u2264 10\n\n1 \u2264 M \u2264 N \u2219 (N \u2013 1) / 2\n\n1 \u2264 Ai, Bi \u2264 N\n\n1 \u2264 Ci \u2264 10\nAi \u2260 Bi\n\nIf i \u2260 j and Ai = Aj, then Bi \u2260 Bj\n\nThere is at least one path from Tomya's house to Ciel's restaurant.\n\n-----Sample Input-----\n2\n3 3\n1 2 3\n2 3 6\n1 3 7\n3 3\n1 2 3\n2 3 6\n1 3 9\n\n-----Sample Output-----\n1\n2\n\n-----Explanations-----\n\nIn the first sample, only one shortest path exists, which is 1-3.\n\nIn the second sample, both paths 1-2-3 and 1-3 are the shortest paths.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nt=eval(input())\ndef func(k,n,x,dist,graph):\n if k==n:\n x+=[dist[n]]\n return\n for i in range(1,n+1):\n if graph[k][i]!=0 and dist[i]==-1:\n dist[i]=dist[k]+graph[k][i]\n func(i,n,x,dist,graph)\n dist[i]=-1\n \nwhile t:\n graph=[[0 for i in range(11)]for j in range(11)]\n v,e=list(map(int,input().split()))\n for i in range(e):\n x,y,w=list(map(int,input().split()))\n graph[x][y]=w\n graph[y][x]=w\n x=[]\n dist=[-1]*(v+1)\n dist[1]=0\n func(1,v,x,dist,graph)\n x.sort()\n val=x[0]\n ans=0\n for i in range(len(x)):\n if val==x[i]:\n ans+=1\n print(ans)\n t-=1\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n3 3\\n1 2 3\\n2 3 6\\n1 3 7\\n3 3\\n1 2 3\\n2 3 6\\n1 3 9\\n', 'output': '1\\n2\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/CIELTOMY'}","problem_id":"vfc_3742","program":"```python\nt=eval(input())\ndef func(k,n,x,dist,graph):\n if k==n:\n x+=[dist[n]]\n return\n for i in range(1,n+1):\n if graph[k][i]!=0 and dist[i]==-1:\n dist[i]=dist[k]+graph[k][i]\n func(i,n,x,dist,graph)\n dist[i]=-1\n \nwhile t:\n graph=[[0 for i in range(11)]for j in range(11)]\n v,e=list(map(int,input().split()))\n for i in range(e):\n x,y,w=list(map(int,input().split()))\n graph[x][y]=w\n graph[y][x]=w\n x=[]\n dist=[-1]*(v+1)\n dist[1]=0\n func(1,v,x,dist,graph)\n x.sort()\n val=x[0]\n ans=0\n for i in range(len(x)):\n if val==x[i]:\n ans+=1\n print(ans)\n t-=1\n\n```","inputs":"2\n3 3\n1 2 3\n2 3 6\n1 3 7\n3 3\n1 2 3\n2 3 6\n1 3 9\n","output":"1\n2\n","actual_output":"1\n2\n","execution_success":true,"sample_index":821},{"source":"apps","task_type":"verifiable_code","in_source_id":"1226","prompt":"Solve the following coding problem using the programming language python:\n\nIt is well-known that the elephants are afraid of mouses. The Little Elephant from the Zoo of Lviv is not an exception.\n\nThe Little Elephant is on a board A of n rows and m columns (0-based numeration). At the beginning he is in cell with coordinates (0; 0) and he wants to go to cell with coordinates (n-1; m-1). From cell (x; y) Little Elephant can go either to (x+1; y) or (x; y+1).\n\nEach cell of the board contains either 1 or 0. If A[i][j] = 1, then there is a single mouse in cell (i; j). Mouse at cell (i; j) scared Little Elephants if and only if during the path there was at least one such cell (x; y) (which belongs to that path) and |i-x| + |j-y| <= 1.\n\nLittle Elephant wants to find some correct path from (0; 0) to (n-1; m-1) such that the number of mouses that have scared the Little Elephant is minimal possible. Print that number.\n\n-----Input-----\nFirst line contains single integer T - the number of test cases. Then T test cases follow. First line of each test case contain pair of integers n and m - the size of the board. Next n lines contain n strings, each of size m and consisted of digits 0 and 1.\n\n-----Output-----\nIn T lines print T integer - the answers for the corresponding test.\n\n-----Constraints-----\n1 <= T <= 50\n2 <= n, m <= 100\n\n-----Example-----\nInput:\n2\n3 9\n001000001\n111111010\n100100100\n7 9\n010101110\n110110111\n010011111\n100100000\n000010100\n011011000\n000100101\n\nOutput:\n9\n10\n\n-----Explanation-----\nExample case 1: \nThe optimized path is: (0, 0) -> (0, 1) -> (0, 2) -> (0, 3) -> (0, 4) -> (0, 5) -> (0, 6) -> (0, 7) -> (0, 8) -> (1, 8) -> (2, 8). The mouses that scared the Little Elephant are at the following cells: (1, 0), (1, 1), (1, 2), (1, 3), (1, 4), (1, 5), (1, 7), (0, 2), (0, 8).\n\nExample case 2: \nThe optimized path is: (0, 0) -> (1, 0) -> (1, 1) -> (2, 1) -> (2, 2) -> (3, 2) -> (3, 3) -> (4, 3) -> (4, 4) -> (5, 4) -> (5, 5) -> (6, 5) -> (6, 6) -> (6, 7) -> (6, 8). The 10 mouses that scared the Little Elephant are at the following cells: (0, 1), (1, 0), (1, 1), (2, 1), (3, 3), (4, 4), (5, 4), (5, 5), (6, 6), (6, 8).\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfrom collections import defaultdict\nfrom itertools import product\n\ndef solve(mouse,n,m):\n \n # shadow matrix will contains the count of mice which affect (i,j) position\n # if there is a mice at position (i,j) then in shadow matrix it will affect \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0all four adjacent blocks \n shadow=[[0 for i in range(m)]for j in range(n)]\n for i,j in product(list(range(n)),list(range(m))):\n if mouse[i][j]==1:\n if i>0:\n shadow[i-1][j]+=1\n if j>0:\n shadow[i][j-1]+=1\n if iwe are \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0coming at destination (i,j) from left side\n # (i,j,1)=> we are coming at destination (i,j) from top \n dp=defaultdict(int)\n \n # \n dp[(0,0,0)]=dp[(0,0,1)]=shadow[0][0]-mouse[0][0]\n \n # fill only first row\n # in first row we can only reach at (0,j) from (0,j-1,0) as we can't come \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0from top.\n \n # so here we will assign count of mices which will affect current cell\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0(shadow[0][i]) + previous result i.e,(0,j-1,0) and \n # if mouse is in the current cell than we have to subtract it bcoz we have \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0add it twice i.e, when we enter at this block \n # and when we leave this block \n for i in range(1,m):\n dp[(0,i,0)]=dp[(0,i,1)]=shadow[0][i]-mouse[0][i]+dp[(0,i-1,0)]\n \n # same goes for first column\n # we can only come at (i,0) from (i-1,0) i.e top\n for i in range(1,n):\n dp[(i,0,0)]=dp[(i,0,1)]=shadow[i][0]-mouse[i][0]+dp[(i-1,0,1)]\n \n \n # for rest of the blocks \n # for a block (i,j) we have to add shadow[i][j] and subtract mouse[i][j] \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0from it for double counting\n # now for each block we have two choices, either take its previous block \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0with same direction or take previous block with different \n # direction and subtract corner double counted mouse. We have to take min of \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0both to find optimal answer\n for i,j in product(list(range(1,n)),list(range(1,m))):\n a=shadow[i][j]-mouse[i][j]\n b=a\n a+=min(dp[(i,j-1,0)],dp[(i,j-1,1)]-mouse[i-1][j])\n b+=min(dp[(i-1,j,1)],dp[(i-1,j,0)]-mouse[i][j-1])\n dp[(i,j,0)]=a\n dp[(i,j,1)]=b\n \n # what if [0][0] and [n-1][m-1] have mice, so we have to add them as we \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0haven't counted them yet.\n \n return min(dp[(n-1,m-1,0)],dp[(n-1,m-1,1)])+mouse[0][0]+mouse[n-1][m-1]\n \nfor _ in range(int(input())):\n n,m=list(map(int,input().split( )))\n mouse=[]\n for i in range(n):\n x=input()\n mouse.append(list(map(int,x)))\n print(solve(mouse,n,m))\n \n \n \n \n \n \n \n \n \n \n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n3 9\\n001000001\\n111111010\\n100100100\\n7 9\\n010101110\\n110110111\\n010011111\\n100100000\\n000010100\\n011011000\\n000100101\\n', 'output': '9\\n10\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/LEMOUSE'}","problem_id":"vfc_3746","program":"```python\nfrom collections import defaultdict\nfrom itertools import product\n\ndef solve(mouse,n,m):\n \n # shadow matrix will contains the count of mice which affect (i,j) position\n # if there is a mice at position (i,j) then in shadow matrix it will affect \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0all four adjacent blocks \n shadow=[[0 for i in range(m)]for j in range(n)]\n for i,j in product(list(range(n)),list(range(m))):\n if mouse[i][j]==1:\n if i>0:\n shadow[i-1][j]+=1\n if j>0:\n shadow[i][j-1]+=1\n if iwe are \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0coming at destination (i,j) from left side\n # (i,j,1)=> we are coming at destination (i,j) from top \n dp=defaultdict(int)\n \n # \n dp[(0,0,0)]=dp[(0,0,1)]=shadow[0][0]-mouse[0][0]\n \n # fill only first row\n # in first row we can only reach at (0,j) from (0,j-1,0) as we can't come \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0from top.\n \n # so here we will assign count of mices which will affect current cell\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0(shadow[0][i]) + previous result i.e,(0,j-1,0) and \n # if mouse is in the current cell than we have to subtract it bcoz we have \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0add it twice i.e, when we enter at this block \n # and when we leave this block \n for i in range(1,m):\n dp[(0,i,0)]=dp[(0,i,1)]=shadow[0][i]-mouse[0][i]+dp[(0,i-1,0)]\n \n # same goes for first column\n # we can only come at (i,0) from (i-1,0) i.e top\n for i in range(1,n):\n dp[(i,0,0)]=dp[(i,0,1)]=shadow[i][0]-mouse[i][0]+dp[(i-1,0,1)]\n \n \n # for rest of the blocks \n # for a block (i,j) we have to add shadow[i][j] and subtract mouse[i][j] \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0from it for double counting\n # now for each block we have two choices, either take its previous block \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0with same direction or take previous block with different \n # direction and subtract corner double counted mouse. We have to take min of \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0both to find optimal answer\n for i,j in product(list(range(1,n)),list(range(1,m))):\n a=shadow[i][j]-mouse[i][j]\n b=a\n a+=min(dp[(i,j-1,0)],dp[(i,j-1,1)]-mouse[i-1][j])\n b+=min(dp[(i-1,j,1)],dp[(i-1,j,0)]-mouse[i][j-1])\n dp[(i,j,0)]=a\n dp[(i,j,1)]=b\n \n # what if [0][0] and [n-1][m-1] have mice, so we have to add them as we \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0haven't counted them yet.\n \n return min(dp[(n-1,m-1,0)],dp[(n-1,m-1,1)])+mouse[0][0]+mouse[n-1][m-1]\n \nfor _ in range(int(input())):\n n,m=list(map(int,input().split( )))\n mouse=[]\n for i in range(n):\n x=input()\n mouse.append(list(map(int,x)))\n print(solve(mouse,n,m))\n \n \n \n \n \n \n \n \n \n \n\n```","inputs":"2\n3 9\n001000001\n111111010\n100100100\n7 9\n010101110\n110110111\n010011111\n100100000\n000010100\n011011000\n000100101\n","output":"9\n10\n","actual_output":"9\n10\n","execution_success":true,"sample_index":822},{"source":"apps","task_type":"verifiable_code","in_source_id":"1227","prompt":"Solve the following coding problem using the programming language python:\n\nOne day, Chef found a cube which has each of its sides painted in some color out of black, blue, red, green, yellow and orange.\nNow he asks you to check if he can choose three sides such that they are pairwise adjacent and painted in the same color.\n\n-----Input-----\n- The first line of the input contains an integer T denoting the number of test cases.\n- A single line of each test case contains six words denoting the colors of painted sides in the order: front, back, left, right, top and bottom, respectively.\n\n-----Output-----\nFor each test case, output a single line containing the word \"YES\" or \"NO\" (without quotes) corresponding to the answer of the problem.\n\n-----Constraints-----\n- 1 \u2264 T \u2264 50000 \n- Each color will be from the list {\"black\", \"blue\", \"red\", \"green\", \"yellow\", \"orange\"}\n\n-----Subtasks-----\nSubtask 1: (25 points)\n- 1 \u2264 T \u2264 12000 \n- For each test case there will be at most three different colors\n\nSubtask 2: (75 points)\n- Original constraints\n\n-----Example-----\nInput:\n2\nblue yellow green orange black green\ngreen yellow green orange black green\n\nOutput:\nNO\nYES\n\n-----Explanation-----\n\nExample case 1.\nThere are no three sides with the same color.\n\nExample case 2.\nIn this test case, the front, bottom and left sides are green (see picture).\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfor _ in range(int(input())):\n l=list(map(str,input().split()))\n a=[(1,3,5),(1,3,6),(1,4,5),(1,4,6),(2,3,5),(2,3,6),(2,4,5),(2,4,6)]\n c=0\n for i in a:\n if len(set([l[i[0]-1],l[i[1]-1],l[i[2]-1]]))==1:\n c=1\n break\n if c==1:\n print(\"YES\")\n else:\n print(\"NO\")\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\nblue yellow green orange black green\\ngreen yellow green orange black green\\n', 'output': 'NO\\nYES\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/CHCUBE'}","problem_id":"vfc_3750","program":"```python\nfor _ in range(int(input())):\n l=list(map(str,input().split()))\n a=[(1,3,5),(1,3,6),(1,4,5),(1,4,6),(2,3,5),(2,3,6),(2,4,5),(2,4,6)]\n c=0\n for i in a:\n if len(set([l[i[0]-1],l[i[1]-1],l[i[2]-1]]))==1:\n c=1\n break\n if c==1:\n print(\"YES\")\n else:\n print(\"NO\")\n\n```","inputs":"2\nblue yellow green orange black green\ngreen yellow green orange black green\n","output":"NO\nYES\n","actual_output":"NO\nYES\n","execution_success":true,"sample_index":823},{"source":"apps","task_type":"verifiable_code","in_source_id":"1228","prompt":"Solve the following coding problem using the programming language python:\n\nChef has $N$ axis-parallel rectangles in a 2D Cartesian coordinate system. These rectangles may intersect, but it is guaranteed that all their $4N$ vertices are pairwise distinct.\nUnfortunately, Chef lost one vertex, and up until now, none of his fixes have worked (although putting an image of a point on a milk carton might not have been the greatest idea after all\u2026). Therefore, he gave you the task of finding it! You are given the remaining $4N-1$ points and you should find the missing one.\n\n-----Input-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The first line of each test case contains a single integer $N$.\n- Then, $4N-1$ lines follow. Each of these lines contains two space-separated integers $x$ and $y$ denoting a vertex $(x, y)$ of some rectangle.\n\n-----Output-----\nFor each test case, print a single line containing two space-separated integers $X$ and $Y$ \u2015 the coordinates of the missing point. It can be proved that the missing point can be determined uniquely.\n\n-----Constraints-----\n- $T \\le 100$\n- $1 \\le N \\le 2 \\cdot 10^5$\n- $|x|, |y| \\le 10^9$\n- the sum of $N$ over all test cases does not exceed $2 \\cdot 10^5$\n\n-----Subtasks-----\nSubtask #1 (20 points):\n- $T = 5$\n- $N \\le 20$\nSubtask #2 (30 points): $|x|, |y| \\le 10^5$\nSubtask #3 (50 points): original constraints\n\n-----Example Input-----\n1\n2\n1 1\n1 2\n4 6\n2 1\n9 6\n9 3\n4 3\n\n-----Example Output-----\n2 2\n\n-----Explanation-----\nThe original set of points are:\n\nUpon adding the missing point $(2, 2)$, $N = 2$ rectangles can be formed:\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfor _ in range(int(input())):\n n=int(input())\n a=[]\n b=[]\n for i in range(4*n-1):\n c,d=list(map(int,input().split()))\n a.append(c)\n b.append(d)\n c1=0\n c2=0\n for i in a:\n c1^=i\n for i in b:\n c2^=i\n print(c1,c2)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n2\\n1 1\\n1 2\\n4 6\\n2 1\\n9 6\\n9 3\\n4 3\\n', 'output': '2 2\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/PTMSSNG'}","problem_id":"vfc_3754","program":"```python\nfor _ in range(int(input())):\n n=int(input())\n a=[]\n b=[]\n for i in range(4*n-1):\n c,d=list(map(int,input().split()))\n a.append(c)\n b.append(d)\n c1=0\n c2=0\n for i in a:\n c1^=i\n for i in b:\n c2^=i\n print(c1,c2)\n```","inputs":"1\n2\n1 1\n1 2\n4 6\n2 1\n9 6\n9 3\n4 3\n","output":"2 2\n","actual_output":"2 2\n","execution_success":true,"sample_index":824},{"source":"apps","task_type":"verifiable_code","in_source_id":"1229","prompt":"Solve the following coding problem using the programming language python:\n\nMotu and Tomu are very good friends who are always looking for new games to play against each other and ways to win these games. One day, they decided to play a new type of game with the following rules:\n- The game is played on a sequence $A_0, A_1, \\dots, A_{N-1}$.\n- The players alternate turns; Motu plays first, since he's earlier in lexicographical order.\n- Each player has a score. The initial scores of both players are $0$.\n- On his turn, the current player has to pick the element of $A$ with the lowest index, add its value to his score and delete that element from the sequence $A$.\n- At the end of the game (when $A$ is empty), Tomu wins if he has strictly greater score than Motu. Otherwise, Motu wins the game.\nIn other words, Motu starts by selecting $A_0$, adding it to his score and then deleting it; then, Tomu selects $A_1$, adds its value to his score and deletes it, and so on.\nMotu and Tomu already chose a sequence $A$ for this game. However, since Tomu plays second, he is given a different advantage: before the game, he is allowed to perform at most $K$ swaps in $A$; afterwards, the two friends are going to play the game on this modified sequence.\nNow, Tomu wants you to determine if it is possible to perform up to $K$ swaps in such a way that he can win this game.\n\n-----Input-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The first line of each test case contains two space-separated integers $N$ and $K$ denoting the number of elements in the sequence and the maximum number of swaps Tomu can perform.\n- The second line contains $N$ space-separated integers $A_0, A_1, \\dots, A_{N-1}$.\n\n-----Output-----\nFor each test case, print a single line containing the string \"YES\" if Tomu can win the game or \"NO\" otherwise (without quotes).\n\n-----Constraints-----\n- $1 \\le T \\le 100$\n- $1 \\le N \\le 10,000$\n- $0 \\le K \\le 10,000$\n- $1 \\le A_i \\le 10,000$ for each valid $i$\n\n-----Subtasks-----\nSubtask #1 (20 points): $1 \\le N \\le 100$\nSubtask #2 (80 points): original constraints\n\n-----Example Input-----\n2\n6 0\n1 1 1 1 1 1\n5 1\n2 4 6 3 4\n\n-----Example Output-----\nNO\nYES\n\n-----Explanation-----\nExample case 1: At the end of the game, both Motu and Tomu will have scores $1+1+1 = 3$. Tomu is unable to win that game, so the output is \"NO\".\nExample case 2: If no swaps were performed, Motu's score would be $2+6+4 = 12$ and Tomu's score would be $4+3 = 7$. However, Tomu can swap the elements $A_2 = 6$ and $A_3 = 3$, which makes Motu's score at the end of the game equal to $2+3+4 = 9$ and Tomu's score equal to $4+6 = 10$. Tomu managed to score higher than Motu, so the output is \"YES\".\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfor _ in range(int(input())):\n n, k = map(int, input().split())\n arr= list(map(int, input().split()))\n motu, tomu = [], []\n for i in range(n):\n if i%2 == 0:\n motu.append(arr[i])\n else:\n tomu.append((arr[i]))\n motu.sort(reverse=True)\n tomu.sort()\n for i in range(len(motu)):\n if len(tomu)-1 sum(motu):\n print(\"YES\")\n else:\n print(\"NO\")\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n6 0\\n1 1 1 1 1 1\\n5 1\\n2 4 6 3 4\\n', 'output': 'NO\\nYES\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/MTYFRI'}","problem_id":"vfc_3758","program":"```python\nfor _ in range(int(input())):\n n, k = map(int, input().split())\n arr= list(map(int, input().split()))\n motu, tomu = [], []\n for i in range(n):\n if i%2 == 0:\n motu.append(arr[i])\n else:\n tomu.append((arr[i]))\n motu.sort(reverse=True)\n tomu.sort()\n for i in range(len(motu)):\n if len(tomu)-1 sum(motu):\n print(\"YES\")\n else:\n print(\"NO\")\n```","inputs":"2\n6 0\n1 1 1 1 1 1\n5 1\n2 4 6 3 4\n","output":"NO\nYES\n","actual_output":"NO\nYES\n","execution_success":true,"sample_index":825},{"source":"apps","task_type":"verifiable_code","in_source_id":"1231","prompt":"Solve the following coding problem using the programming language python:\n\nThe chef won a duet singing award at Techsurge & Mridang 2012. From that time he is obsessed with the number 2.\n\nHe just started calculating the powers of two. And adding the digits of the results.\n\nBut he got puzzled after a few calculations. So gave you the job to generate the solutions to 2^n and find their sum of digits.\n\n-----Input-----\nN : number of inputs N<=100\n\nthen N lines with input T<=2000\n\n-----Output-----\nThe output for the corresponding input T\n\n-----Example-----\nInput:\n3\n5\n10\n4\n\nOutput:\n5\n7\n7\n\nExplanation:\n2^5=32\n3+2=5\n2^10=1024\n1+0+2+4=7\n2^4=16\n1+6=7\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfrom operator import add\nfrom functools import reduce\n\nchoices=[]\n\nfor x in range(1800):\n num_str = list(map (int, str (2**x)))\n suma = reduce (add, num_str)\n choices.append(suma)\nN=int(input())\n\nfor x in range(N):\n t=int(input())\n print(choices[t])\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\n5\\n10\\n4\\n', 'output': '5\\n7\\n7\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/AGTK2012/problems/ALG2N'}","problem_id":"vfc_3766","program":"```python\nfrom operator import add\nfrom functools import reduce\n\nchoices=[]\n\nfor x in range(1800):\n num_str = list(map (int, str (2**x)))\n suma = reduce (add, num_str)\n choices.append(suma)\nN=int(input())\n\nfor x in range(N):\n t=int(input())\n print(choices[t])\n\n```","inputs":"3\n5\n10\n4\n","output":"5\n7\n7\n","actual_output":"5\n7\n7\n","execution_success":true,"sample_index":826},{"source":"apps","task_type":"verifiable_code","in_source_id":"1232","prompt":"Solve the following coding problem using the programming language python:\n\nAND gates and OR gates are basic components used in building digital circuits. Both gates have two input lines and one output line. The output of an AND gate is 1 if both inputs are 1, otherwise the output is 0. The output of an OR gate is 1 if at least one input is 1, otherwise the output is 0.\n\nYou are given a digital circuit composed of only AND and OR gates where one node (gate or input) is specially designated as the output. Furthermore, for any gate G and any input node I, at most one of the inputs to G depends on the value of node I.\n\nNow consider the following random experiment. Fix some probability p in [0,1] and set each input bit to 1 independently at random with probability p (and to 0 with probability 1-p). The output is then 1 with some probability that depends on p. You wonder what value of p causes the circuit to output a 1 with probability 1/2.\n\n-----Input-----\n\nThe first line indicates the number of test cases to follow (about 100).\n\nEach test case begins with a single line containing a single integer n with 1 \u2264 n \u2264 100 indicating the number of nodes (inputs and gates) in the circuit. Following this, n lines follow where the i'th line describes the i'th node. If the node is an input, the line simply consists of the integer 0. Otherwise, if the node is an OR gate then the line begins with a 1 and if the node is an AND gate then the line begins with a 2. In either case, two more integers a,b follow, both less than i, which indicate that the outputs from both a and b are used as the two input to gate i.\n\nAs stated before, the circuit will be such that no gate has both of its inputs depending on the value of a common input node.\n\nTest cases are separated by a blank line including a blank line preceding the first test case.\n\n\n-----Output-----\n\nFor each test case you are to output a single line containing the value p for which the output of node n is 1 with probability exactly 1/2 if the inputs are independently and randomly set to value 1 with probability p. The value p should be printed with exactly 5 digits after the decimal.\n\n\n-----Example-----\nInput:\n\n4\n\n1\n0\n\n3\n0\n0\n1 1 2\n\n3\n0\n0\n2 1 2\n\n5\n0\n0\n0\n2 1 2\n1 3 4\n\nOutput:\n\n0.50000\n0.29289\n0.70711\n0.40303\n\n-----Temporary Stuff-----\n\nA horizontal rule follows.\n\n***\n\nHere's a definition list (with `definitionLists` option):\n\napples\n: Good for making applesauce.\noranges\n: Citrus!\ntomatoes\n: There's no \"e\" in tomatoe.\n\n#PRACTICE\n- This must be done\n[http:codechef.com/users/dpraveen](http:codechef.com/users/dpraveen)\n\n(0.8944272\u22120.44721360.4472136\u22120.8944272)(10005)(0.89442720.4472136\u22120.4472136\u22120.8944272)(10005)\n\\left(\\begin{array}{cc} \n0.8944272 & 0.4472136\\\\\n-0.4472136 & -0.8944272\n\\end{array}\\right)\n\\left(\\begin{array}{cc} \n10 & 0\\\\ \n0 & 5\n\\end{array}\\right)\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\nclass node:\n\tdef __init__(self,a,b=0,c=0):\n\t\tself.val=a\n\t\tself.a=b\n\t\tself.b=c\n\narr=[]\n\ndef finder(node,val):\n\tif(arr[node].val==0):\n\t\treturn val\n\telse:\n\t\ta=finder(arr[node].a,val)\n\t\tb=finder(arr[node].b,val)\n\t\tif(arr[node].val==1):\n\t\t\treturn a+b-a*b\n\t\telse:\n\t\t\treturn a*b\n\nt=int(input())\nwhile(t>0):\n\tx=input()\n\tn=int(input())\n\tarr.append(node(0))\n\tfor i in range(0,n):\n\t\tvals=input().split()\n\t\tsz=len(vals)\n\t\tfor i in range(0,sz):\n\t\t\tvals[i]=int(vals[i])\n\t\tif(vals[0]==0):\n\t\t\tnext=node(0)\n\t\t\tarr.append(next)\n\t\telse:\n\t\t\tnext=node(vals[0],vals[1],vals[2])\n\t\t\tarr.append(next)\n\tlower=0.0\n\thigher=1.0\n\teps=1e-9\n\twhile((higher-lower)>eps):\n\t\tmid=(higher+lower)/2.0 \n\t\tif(finder(n,mid)>0.5):\n\t\t\thigher=mid\n\t\telse:\n\t\t\tlower=mid\n\tprint(\"%.5f\" %(higher))\n\tarr=[]\n\t# print(higher)\n\tt-=1\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '4\\n\\n1\\n0\\n\\n3\\n0\\n0\\n1 1 2\\n\\n3\\n0\\n0\\n2 1 2\\n\\n5\\n0\\n0\\n0\\n2 1 2\\n1 3 4\\n\\n\\n', 'output': '0.50000\\n0.29289\\n0.70711\\n0.40303\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/CIRCUITS'}","problem_id":"vfc_3770","program":"```python\n# cook your dish here\nclass node:\n\tdef __init__(self,a,b=0,c=0):\n\t\tself.val=a\n\t\tself.a=b\n\t\tself.b=c\n\narr=[]\n\ndef finder(node,val):\n\tif(arr[node].val==0):\n\t\treturn val\n\telse:\n\t\ta=finder(arr[node].a,val)\n\t\tb=finder(arr[node].b,val)\n\t\tif(arr[node].val==1):\n\t\t\treturn a+b-a*b\n\t\telse:\n\t\t\treturn a*b\n\nt=int(input())\nwhile(t>0):\n\tx=input()\n\tn=int(input())\n\tarr.append(node(0))\n\tfor i in range(0,n):\n\t\tvals=input().split()\n\t\tsz=len(vals)\n\t\tfor i in range(0,sz):\n\t\t\tvals[i]=int(vals[i])\n\t\tif(vals[0]==0):\n\t\t\tnext=node(0)\n\t\t\tarr.append(next)\n\t\telse:\n\t\t\tnext=node(vals[0],vals[1],vals[2])\n\t\t\tarr.append(next)\n\tlower=0.0\n\thigher=1.0\n\teps=1e-9\n\twhile((higher-lower)>eps):\n\t\tmid=(higher+lower)/2.0 \n\t\tif(finder(n,mid)>0.5):\n\t\t\thigher=mid\n\t\telse:\n\t\t\tlower=mid\n\tprint(\"%.5f\" %(higher))\n\tarr=[]\n\t# print(higher)\n\tt-=1\n```","inputs":"4\n\n1\n0\n\n3\n0\n0\n1 1 2\n\n3\n0\n0\n2 1 2\n\n5\n0\n0\n0\n2 1 2\n1 3 4\n\n\n","output":"0.50000\n0.29289\n0.70711\n0.40303\n","actual_output":"0.50000\n0.29289\n0.70711\n0.40303\n","execution_success":true,"sample_index":827},{"source":"apps","task_type":"verifiable_code","in_source_id":"1233","prompt":"Solve the following coding problem using the programming language python:\n\nThere are players standing in a row each player has a digit written on their T-Shirt (multiple players can have the same number written on their T-Shirt). \nYou have to select a group of players, note that players in this group should be standing in $\\textbf{consecutive fashion}$. For example second player of chosen group next to first player of chosen group, third player next to second and similarly last player next to second last player of chosen group. Basically You've to choose a contiguous group of players.\nAfter choosing a group, players can be paired if they have the same T-Shirt number (one player can be present in at most one pair), finally the chosen group is called \u201cgood\u201d if at most one player is left unmatched. Your task is to find the size of the maximum \u201cgood\u201d group.\nFormally, you are given a string $S=s_{1}s_{2}s_{3}...s_{i}...s_{n}$ where $s_{i}$ can be any digit character between $'0'$ and $'9'$ and $s_{i}$ denotes the number written on the T-Shirt of $i^{th}$ player. Find a value $length$ such that there exist pair of indices $(i,j)$ which denotes $S[i...j]$ is a \u201cgood\u201d group where $i\\geq1$ and $j\\leq S.length$ and $i\\leq j$ and $(j-i+1)=length$ and there exist no other pair $(i\u2019,j\u2019)$ such that $(j\u2019-i\u2019+1)>length$ and $S[i'...j']$ is a \"good\" group.\n\n-----Input:-----\n- First line will contain $T$, number of testcases. Then the testcases follow. \n- $i^{th}$ testcase consist of a single line of input, a string $S$. \n\n-----Output:-----\nFor each testcase, output in a single line maximum possible size of a \"good\" group.\n\n-----Constraints-----\n$\\textbf{Subtask 1} (20 points)$\n- $1 \\leq T \\leq 10$\n- $S.length \\leq 10^{3}$\n$\\textbf{Subtask 2} (80 points)$\n- $1 \\leq T \\leq 10$\n- $S.length \\leq 10^{5}$\n\n-----Sample Input:-----\n1\n\n123343\n\n-----Sample Output:-----\n3\n\n-----EXPLANATION:-----\n1$\\textbf{$\\underline{2 3 3}$}$43\nUnderlined group is a \u201cgood\u201d group because the second player(number 2 on T-Shirt) is the only player who is left unmatched and third and fourth player can form a pair, no other group has length greater than 3 that are \u201cgood\u201d. However note that we have other \u201cgood\u201d group also 12$\\textbf{$\\underline{334}$}$3 but length is 3 which is same as our answer.\n\n-----Sample Input:-----\n1\n\n95665\n\n-----Sample Output:-----\n5\n\n-----EXPLANATION:-----\n$\\textbf{$\\underline{95665}$}$ is \u201cgood\u201d group because first player is the only player who is left unmatched second and fifth player can form pair and third and fourth player also form pair.\n\n-----Sample Input:-----\n2\n\n2323\n\n1234567\n\n-----Sample Output:-----\n4\n\n1\n\n-----EXPLANATION:-----\nFor first test case\n$\\textbf{$\\underline{2323}$}$ is a \u201cgood\u201d group because there are no players who are left unmatched first and third player form pair and second and fourth player form pair.\n\nFor second test\n\nOnly length one \"good\" group is possible.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nimport sys\n\ndef GRIG(L):\n\n LENT = len(L)\n MINT = 1\n GOT = 0\n\n DY = [ [{x: 0 for x in range(0, 10)}, 0, 0] ]\n\n for i in L:\n\n DY.append([{x: 0 for x in range(0, 10)}, 0, 0])\n GOT += 1\n\n for j in range(0, GOT):\n\n if DY[j][0][i] == 1:\n DY[j][0][i] = 0\n DY[j][1] -= 1\n else:\n DY[j][0][i] = 1\n DY[j][1] += 1\n\n DY[j][2] += 1\n\n if DY[j][1] <= 1 and DY[j][2] > MINT:\n MINT = DY[j][2]\n\n return MINT\n\nTESTCASES = int(input().strip())\n\nfor i in range(0, TESTCASES):\n \n L = [int(x) for x in list(input().strip())]\n \n print(GRIG(L))\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n123343\\n', 'output': '3\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/COVO2020/problems/GRIG'}","problem_id":"vfc_3774","program":"```python\nimport sys\n\ndef GRIG(L):\n\n LENT = len(L)\n MINT = 1\n GOT = 0\n\n DY = [ [{x: 0 for x in range(0, 10)}, 0, 0] ]\n\n for i in L:\n\n DY.append([{x: 0 for x in range(0, 10)}, 0, 0])\n GOT += 1\n\n for j in range(0, GOT):\n\n if DY[j][0][i] == 1:\n DY[j][0][i] = 0\n DY[j][1] -= 1\n else:\n DY[j][0][i] = 1\n DY[j][1] += 1\n\n DY[j][2] += 1\n\n if DY[j][1] <= 1 and DY[j][2] > MINT:\n MINT = DY[j][2]\n\n return MINT\n\nTESTCASES = int(input().strip())\n\nfor i in range(0, TESTCASES):\n \n L = [int(x) for x in list(input().strip())]\n \n print(GRIG(L))\n\n```","inputs":"1\n123343\n","output":"3\n","actual_output":"3\n","execution_success":true,"sample_index":828},{"source":"apps","task_type":"verifiable_code","in_source_id":"1234","prompt":"Solve the following coding problem using the programming language python:\n\nThere is a new prodigy in town and he has challenged people to a game. They have to give him an integer N and he will immediately respond with a number which has more than N factors.\nWhat the prodigy really does is to do some complex calculations in his head to find out the smallest integer with more than N factors. However, he has a weakness - he knows to do those calculation only on numbers up to 1019, so if the answer to be reported is more than 1019, he will not be able to come up with his solution and will lose the game.\nGiven the integer the people give to the prodigy, you need to report whether he wins the game or not. If he wins, also output his answer.\n\n-----Input-----\nThe first line of input contains T (T \u2264 25), the number of test cases. Following this are T lines, each containing an integer N (1 \u2264 N \u2264 109) - the number which is given to the prodigy.\n\n-----Output-----\nOutput one line per test case. If the smallest integer X with more than N factors is bigger than 1019 so that the prodigy does not win, print \"lose\". Otherwise print \"win X\" (quotes for clarity).\n\n-----Example-----\nInput:\n3\n3\n5\n12345678\n\nOutput:\nwin 6\nwin 12\nlose\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\ndivisors = [1 , 2 , 3 , 4 , 6 , 8 , 9 , 10 , 12 , 16 , 18 , 20 , 24 , 30 , 32 , 36 , 40 , 48 , 60 , 64 , 72 , 80 , 84 , 90 , 96 , 100 , 108 , 120 , 128 , 144 , 160 , 168 , 180 , 192 , 200 , 216 , 224 , 240 , 256 , 288 , 320 , 336 , 360 , 384 , 400 , 432 , 448 , 480 , 504 , 512 , 576 , 600 , 640 , 672 , 720 , 768 , 800 , 864 , 896 , 960 , 1008 , 1024 , 1152 , 1200 , 1280 , 1344 , 1440 , 1536 , 1600 , 1680 , 1728 , 1792 , 1920 , 2016 , 2048 , 2304 , 2400 , 2688 , 2880 , 3072 , 3360 , 3456 , 3584 , 3600 , 3840 , 4032 , 4096 , 4320 , 4608 , 4800 , 5040 , 5376 , 5760 , 6144 , 6720 , 6912 , 7168 , 7200 , 7680 , 8064 , 8192 , 8640 , 9216 , 10080 , 10368 , 10752 , 11520 , 12288 , 12960 , 13440 , 13824 , 14336 , 14400 , 15360 , 16128 , 16384 , 17280 , 18432 , 20160 , 20736 , 21504 , 23040 , 24576 , 25920 , 26880 , 27648 , 28672 , 28800 , 30720 , 32256 , 32768 , 34560 , 36864 , 40320 , 41472 , 43008 , 46080 , 48384 , 49152 , 51840 , 53760 , 55296 , 57600 , 61440 , 62208 , 64512 , 65536 , 69120 , 73728 , 80640 , 82944 , 86016 , 92160 , 96768 , 98304 , 103680 , 107520 , 110592 , 115200 , 122880 , 124416 , 129024 , 131072 , 138240 , 147456 , 153600 , 161280 , 165888 , 172032 , 184320 , 193536 , 196608 , 207360 , 215040 , 221184 , 230400 , 245760]\nnumbers = [1 , 2 , 4 , 6 , 12 , 24 , 36 , 48 , 60 , 120 , 180 , 240 , 360 , 720 , 840 , 1260 , 1680 , 2520 , 5040 , 7560 , 10080 , 15120 , 20160 , 25200 , 27720 , 45360 , 50400 , 55440 , 83160 , 110880 , 166320 , 221760 , 277200 , 332640 , 498960 , 554400 , 665280 , 720720 , 1081080 , 1441440 , 2162160 , 2882880 , 3603600 , 4324320 , 6486480 , 7207200 , 8648640 , 10810800 , 14414400 , 17297280 , 21621600 , 32432400 , 36756720 , 43243200 , 61261200 , 73513440 , 110270160 , 122522400 , 147026880 , 183783600 , 245044800 , 294053760 , 367567200 , 551350800 , 698377680 , 735134400 , 1102701600 , 1396755360 , 2095133040 , 2205403200 , 2327925600 , 2793510720 , 3491888400 , 4655851200 , 5587021440 , 6983776800 , 10475665200 , 13967553600 , 20951330400 , 27935107200 , 41902660800 , 48886437600 , 64250746560 , 73329656400 , 80313433200 , 97772875200 , 128501493120 , 146659312800 , 160626866400 , 240940299600 , 293318625600 , 321253732800 , 481880599200 , 642507465600 , 963761198400 , 1124388064800 , 1606268664000 , 1686582097200 , 1927522396800 , 2248776129600 , 3212537328000 , 3373164194400 , 4497552259200 , 6746328388800 , 8995104518400 , 9316358251200 , 13492656777600 , 18632716502400 , 26985313555200 , 27949074753600 , 32607253879200 , 46581791256000 , 48910880818800 , 55898149507200 , 65214507758400 , 93163582512000 , 97821761637600 , 130429015516800 , 195643523275200 , 260858031033600 , 288807105787200 , 391287046550400 , 577614211574400 , 782574093100800 , 866421317361600 , 1010824870255200 , 1444035528936000 , 1516237305382800 , 1732842634723200 , 2021649740510400 , 2888071057872000 , 3032474610765600 , 4043299481020800 , 6064949221531200 , 8086598962041600 , 10108248702552000 , 12129898443062400 , 18194847664593600 , 20216497405104000 , 24259796886124800 , 30324746107656000 , 36389695329187200 , 48519593772249600 , 60649492215312000 , 72779390658374400 , 74801040398884800 , 106858629141264000 , 112201560598327200 , 149602080797769600 , 224403121196654400 , 299204161595539200 , 374005201994424000 , 448806242393308800 , 673209363589963200 , 748010403988848000 , 897612484786617600 , 1122015605983272000 , 1346418727179926400 , 1795224969573235200 , 2244031211966544000 , 2692837454359852800 , 3066842656354276800 , 4381203794791824000 , 4488062423933088000 , 6133685312708553600 , 8976124847866176000 , 9200527969062830400]\nt = int(input())\nfor x in range(0, t):\n a = int(input())\n i = 0\n for y in divisors:\n if y > a:\n print(\"win\", numbers[i])\n break\n i = i+1\n else:\n print(\"lose\")\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\n3\\n5\\n12345678\\n', 'output': 'win 6\\nwin 12\\nlose\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/IOPC2012/problems/IOPC1211'}","problem_id":"vfc_3778","program":"```python\ndivisors = [1 , 2 , 3 , 4 , 6 , 8 , 9 , 10 , 12 , 16 , 18 , 20 , 24 , 30 , 32 , 36 , 40 , 48 , 60 , 64 , 72 , 80 , 84 , 90 , 96 , 100 , 108 , 120 , 128 , 144 , 160 , 168 , 180 , 192 , 200 , 216 , 224 , 240 , 256 , 288 , 320 , 336 , 360 , 384 , 400 , 432 , 448 , 480 , 504 , 512 , 576 , 600 , 640 , 672 , 720 , 768 , 800 , 864 , 896 , 960 , 1008 , 1024 , 1152 , 1200 , 1280 , 1344 , 1440 , 1536 , 1600 , 1680 , 1728 , 1792 , 1920 , 2016 , 2048 , 2304 , 2400 , 2688 , 2880 , 3072 , 3360 , 3456 , 3584 , 3600 , 3840 , 4032 , 4096 , 4320 , 4608 , 4800 , 5040 , 5376 , 5760 , 6144 , 6720 , 6912 , 7168 , 7200 , 7680 , 8064 , 8192 , 8640 , 9216 , 10080 , 10368 , 10752 , 11520 , 12288 , 12960 , 13440 , 13824 , 14336 , 14400 , 15360 , 16128 , 16384 , 17280 , 18432 , 20160 , 20736 , 21504 , 23040 , 24576 , 25920 , 26880 , 27648 , 28672 , 28800 , 30720 , 32256 , 32768 , 34560 , 36864 , 40320 , 41472 , 43008 , 46080 , 48384 , 49152 , 51840 , 53760 , 55296 , 57600 , 61440 , 62208 , 64512 , 65536 , 69120 , 73728 , 80640 , 82944 , 86016 , 92160 , 96768 , 98304 , 103680 , 107520 , 110592 , 115200 , 122880 , 124416 , 129024 , 131072 , 138240 , 147456 , 153600 , 161280 , 165888 , 172032 , 184320 , 193536 , 196608 , 207360 , 215040 , 221184 , 230400 , 245760]\nnumbers = [1 , 2 , 4 , 6 , 12 , 24 , 36 , 48 , 60 , 120 , 180 , 240 , 360 , 720 , 840 , 1260 , 1680 , 2520 , 5040 , 7560 , 10080 , 15120 , 20160 , 25200 , 27720 , 45360 , 50400 , 55440 , 83160 , 110880 , 166320 , 221760 , 277200 , 332640 , 498960 , 554400 , 665280 , 720720 , 1081080 , 1441440 , 2162160 , 2882880 , 3603600 , 4324320 , 6486480 , 7207200 , 8648640 , 10810800 , 14414400 , 17297280 , 21621600 , 32432400 , 36756720 , 43243200 , 61261200 , 73513440 , 110270160 , 122522400 , 147026880 , 183783600 , 245044800 , 294053760 , 367567200 , 551350800 , 698377680 , 735134400 , 1102701600 , 1396755360 , 2095133040 , 2205403200 , 2327925600 , 2793510720 , 3491888400 , 4655851200 , 5587021440 , 6983776800 , 10475665200 , 13967553600 , 20951330400 , 27935107200 , 41902660800 , 48886437600 , 64250746560 , 73329656400 , 80313433200 , 97772875200 , 128501493120 , 146659312800 , 160626866400 , 240940299600 , 293318625600 , 321253732800 , 481880599200 , 642507465600 , 963761198400 , 1124388064800 , 1606268664000 , 1686582097200 , 1927522396800 , 2248776129600 , 3212537328000 , 3373164194400 , 4497552259200 , 6746328388800 , 8995104518400 , 9316358251200 , 13492656777600 , 18632716502400 , 26985313555200 , 27949074753600 , 32607253879200 , 46581791256000 , 48910880818800 , 55898149507200 , 65214507758400 , 93163582512000 , 97821761637600 , 130429015516800 , 195643523275200 , 260858031033600 , 288807105787200 , 391287046550400 , 577614211574400 , 782574093100800 , 866421317361600 , 1010824870255200 , 1444035528936000 , 1516237305382800 , 1732842634723200 , 2021649740510400 , 2888071057872000 , 3032474610765600 , 4043299481020800 , 6064949221531200 , 8086598962041600 , 10108248702552000 , 12129898443062400 , 18194847664593600 , 20216497405104000 , 24259796886124800 , 30324746107656000 , 36389695329187200 , 48519593772249600 , 60649492215312000 , 72779390658374400 , 74801040398884800 , 106858629141264000 , 112201560598327200 , 149602080797769600 , 224403121196654400 , 299204161595539200 , 374005201994424000 , 448806242393308800 , 673209363589963200 , 748010403988848000 , 897612484786617600 , 1122015605983272000 , 1346418727179926400 , 1795224969573235200 , 2244031211966544000 , 2692837454359852800 , 3066842656354276800 , 4381203794791824000 , 4488062423933088000 , 6133685312708553600 , 8976124847866176000 , 9200527969062830400]\nt = int(input())\nfor x in range(0, t):\n a = int(input())\n i = 0\n for y in divisors:\n if y > a:\n print(\"win\", numbers[i])\n break\n i = i+1\n else:\n print(\"lose\")\n\n```","inputs":"3\n3\n5\n12345678\n","output":"win 6\nwin 12\nlose\n","actual_output":"win 6\nwin 12\nlose\n","execution_success":true,"sample_index":829},{"source":"apps","task_type":"verifiable_code","in_source_id":"1235","prompt":"Solve the following coding problem using the programming language python:\n\nGiven a number n. Find the last two digits of 5 ^ n ( 5 to the power of n ).\nRemember that overflow can occur.\n\n-----Input:-----\n- N \u2014 the power in which you need to raise number 5.\n\n-----Output:-----\nLast two digits of 5^n.\n\n-----Constraints-----\n- $2 \\leq N \\leq 2.1018$\n\n-----Sample Input:-----\n2\n\n-----Sample Output:-----\n25\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nprint(25)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n', 'output': '25\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/CMR12121/problems/DGLST'}","problem_id":"vfc_3782","program":"```python\nprint(25)\n```","inputs":"2\n","output":"25\n","actual_output":"25\n","execution_success":true,"sample_index":830},{"source":"apps","task_type":"verifiable_code","in_source_id":"1236","prompt":"Solve the following coding problem using the programming language python:\n\nYou are given a set of n pens, each of them can be red, blue, green, orange, and violet in color. Count a minimum number of pens that should be taken out from the set so that any two neighboring pens have different colors. Pens are considered to be neighboring if there are no other pens between them.\n\n-----Input:-----\n- \nThe first line contains t denoting the number of test cases.\n- \nThe first line of each test case will contain a single integer n.\n- \nThe second line of each test case will contain a string s.\n(s contains only 'R', 'B', 'G', 'O', and 'V' characters denoting red, blue, green, orange, and violet respectively)\n\n-----Output:-----\nFor each test case, print single line containing one integer - The minimum number of pens that need to be taken out.\n\n-----Constraints-----\n- $1 \\leq T \\leq 100$\n- $1 \\leq n \\leq 1000$\n\n-----Sample Input:-----\n2\n5\nRBBRG\n5\nRBGOV\n\n-----Sample Output:-----\n1\n0\n\n-----EXPLANATION:-----\nIn first test case, two blue pens are neighboring each other, if we take out any one of them then the string will be RBRG in which each pen has different neighbors.\nIn second test case, no pen needs to be taken out as each pen has different neighbors.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nt = int(input())\n\nfor _ in range(t):\n n = int(input())\n a = input().strip()\n prev = a[0]\n ans = -1\n for i in a:\n if prev == i:\n ans += 1\n prev = i\n print(ans)\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n5\\nRBBRG\\n5\\nRBGOV\\n', 'output': '1\\n0\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/CDGO2021/problems/DIFFPENS'}","problem_id":"vfc_3786","program":"```python\nt = int(input())\n\nfor _ in range(t):\n n = int(input())\n a = input().strip()\n prev = a[0]\n ans = -1\n for i in a:\n if prev == i:\n ans += 1\n prev = i\n print(ans)\n\n```","inputs":"2\n5\nRBBRG\n5\nRBGOV\n","output":"1\n0\n","actual_output":"1\n0\n","execution_success":true,"sample_index":831},{"source":"apps","task_type":"verifiable_code","in_source_id":"1237","prompt":"Solve the following coding problem using the programming language python:\n\nYou are standing near a very strange machine. If you put C cents in the machine, the remaining money in your purse will transform in an unusual way. If you have A dollars and B cents remaining in your purse after depositing the C cents, then after the transformation you will have B dollars and A cents. You can repeat this procedure as many times as you want unless you don't have enough money for the machine. If at any point C > B and A > 0, then the machine will allow you to break one of the A dollars into 100 cents so you can place C cents in the machine. The machine will not allow you to exchange a dollar for 100 cents if B >= C.\n\nOf course, you want to do this to maximize your profit. For example if C=69 and you have 9 dollars and 77 cents then after you put 69 cents in the machine you will have 8 dollars and 9 cents (9.77 --> 9.08 --> 8.09). But I should warn you that you can't cheat. If you try to throw away 9 cents before the transformation (in order to obtain 99 dollars and 8 cents after), the machine will sense you are cheating and take away all of your money. You need to know how many times you should do this transformation in order to make a maximum profit. Since you are very busy man, you want to obtain the maximum possible profit in the minimum amount of time.\n\n-----Input-----\nThe first line contains a single integer T <= 40, the number of test cases. T test cases follow. The only line of each test case contains three nonnegative integers A, B and C where A, B, C < 100. It means that you have A dollars and B cents in your purse and you need to put C cents in the machine to make the transformation.\n\n-----Output-----\nFor each test case, output a single line containing the minimal number of times you should do this transformation in order to make a maximal profit. It is guaranteed that the answer is less than 10000.\n\n-----Example-----\nInput:\n2\n9 77 69\n98 99 69\n\nOutput:\n4\n0\n\n-----Explanation-----\nIn the first test we have the following sequence: 9.77, 8.09, 40.07, 38.39, 70.37, 68.69, 0.68. After last step we have not enough money for further transformations. The maximal profit will be after 4 transformations.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\r\nfor _ in range(int(input())):\r\n a,b,c=list(map(int, input().split()))\r\n p=a*100+b\r\n mx=p \r\n ans, cnt = 0, 0\r\n while True:\r\n cnt+=1 \r\n if pmx:\r\n mx=p\r\n ans=cnt\r\n \r\n print(ans) \n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n9 77 69\\n98 99 69\\n\\n\\n', 'output': '4\\n0\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/MONTRANS'}","problem_id":"vfc_3790","program":"```python\n# cook your dish here\r\nfor _ in range(int(input())):\r\n a,b,c=list(map(int, input().split()))\r\n p=a*100+b\r\n mx=p \r\n ans, cnt = 0, 0\r\n while True:\r\n cnt+=1 \r\n if pmx:\r\n mx=p\r\n ans=cnt\r\n \r\n print(ans) \n```","inputs":"2\n9 77 69\n98 99 69\n\n\n","output":"4\n0\n","actual_output":"4\n0\n","execution_success":true,"sample_index":832},{"source":"apps","task_type":"verifiable_code","in_source_id":"1240","prompt":"Solve the following coding problem using the programming language python:\n\nThe chef is having one array of natural numbers. Cheffina challenges chef that find the sum of weights all the natural numbers present in the array, but the main problem is that all numbers have not original weights. After every 6 natural numbers weight is set to 1 as weight increases by 1 after that. (i.e. weight of 1 is 1, weight of 2 is 2 but the weight of 7 is 1 and weight of 8 is 2 and so on\u2026). Help the chef to find the sum. \n\n-----Input:-----\n- First line will contain $T$, number of testcases. Then the testcases follow. \n- Each testcase contains two lines of input, one integer $N$.\n- Next line has N space separate natural numbers. \n\n-----Output:-----\nFor each testcase, output in a single line answer.\n\n-----Constraints-----\n- $1 \\leq T \\leq 10$\n- $1 \\leq N \\leq 10^5$\n- $1 \\leq arr[i] \\leq 10^6$\n\n-----Sample Input:-----\n1\n6\n6 7 9 11 4 16\n\n-----Sample Output:-----\n23\n\n-----EXPLANATION:-----\nArray after conversion = [6, 1, 3, 5, 4, 4]\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\nt = int(input())\nwhile t:\n x = int(input())\n arr = [int(i) for i in input().split()]\n total = 0\n for i in arr:\n if i % 6 == 0:\n total += 6\n else:\n total += (i % 6)\n print(total)\n t -= 1\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n6\\n6 7 9 11 4 16\\n', 'output': '23\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/PEND2020/problems/ITGUY00'}","problem_id":"vfc_3802","program":"```python\n# cook your dish here\nt = int(input())\nwhile t:\n x = int(input())\n arr = [int(i) for i in input().split()]\n total = 0\n for i in arr:\n if i % 6 == 0:\n total += 6\n else:\n total += (i % 6)\n print(total)\n t -= 1\n```","inputs":"1\n6\n6 7 9 11 4 16\n","output":"23\n","actual_output":"23\n","execution_success":true,"sample_index":835},{"source":"apps","task_type":"verifiable_code","in_source_id":"1241","prompt":"Solve the following coding problem using the programming language python:\n\n\"Don't Drink and Drive, but when you do, Better Call Saul.\"\nOnce Jesse and Walter were fighting over extra cash, and Saul decided to settle it with a game of stone piles whose winner gets the extra money. The game is described as follows :\nThere are N$N$ piles of stones with A$A$1$1$,$,$ A$A$2$2$,$,$ ...$...$ A$A$N$N$ stones in each pile. \nJesse and Walter move alternately, and in one move, they remove one pile entirely. \nAfter a total of X$X$ moves, if the Sum of all the remaining piles is odd, Walter wins the game and gets the extra cash, else Jesse is the winner.\nWalter moves first. \nDetermine the winner of the game if both of them play optimally. \n\n-----Input:-----\n- The first line will contain T$T$, number of testcases. T$T$ testcases follow : \n- The first line of each testcase contains two space-separated integers N,X$N, X$. \n- The second line of each testcase contains N$N$ space-separated integers A$A$1$1$,$,$ A$A$2$2$,$,$ ...,$...,$A$A$N$N$.\n\n-----Output:-----\nFor each test case, print a single line containing the string \"Jesse\" (without quotes), if Jesse wins the game or \"Walter\" (without quotes) if Walter wins.\n\n-----Constraints-----\n- 1\u2264T\u2264104$1 \\leq T \\leq 10^4$\n- 2\u2264N\u2264105$2 \\leq N \\leq 10^5$\n- 1\u2264X\u2264N\u22121$1 \\leq X \\leq N-1$\n- 1\u2264A$1 \\leq A$i$i$ \u2264100$ \\leq 100$\n- The sum of N$N$ over all test cases does not exceed 106$10^6$\n\n-----Sample Input:-----\n2\n5 3\n4 4 4 3 4\n7 4\n3 3 1 1 1 2 4\n\n-----Sample Output:-----\nJesse\nWalter\n\n-----EXPLANATION:-----\n- \nFor Test Case 1 : Playing optimally, Walter removes 4. Jesse removes 3 and then Walter removes 4. Jesse wins as 4+4=8$4 + 4 = 8$ is even.\n- \nFor Test Case 2 : Playing optimally, Walter removes 4, Jesse removes 3, Walter removes 2 and Jesse removes 1. Walter wins as 3+3+1=7$3 + 3 + 1 = 7$ is odd.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nn=int(input())\nfor i in range(n):\n k,x=map(int,input().split())\n l=list(map(int,input().split()))\n f,e,o=0,0,0\n for i in l:\n if(i%2==0):\n e+=1\n else:\n o+=1\n if(o<=x//2):\n f=1\n elif(e<=x//2):\n if((k-x)%2!=0):\n f=0\n else:\n f=1\n else:\n if(x%2==0):\n f=1\n else:\n f=0\n if(f==1):\n print('Jesse')\n else:\n print('Walter')\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n5 3\\n4 4 4 3 4\\n7 4\\n3 3 1 1 1 2 4\\n', 'output': 'Jesse\\nWalter\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/GMSTN'}","problem_id":"vfc_3806","program":"```python\nn=int(input())\nfor i in range(n):\n k,x=map(int,input().split())\n l=list(map(int,input().split()))\n f,e,o=0,0,0\n for i in l:\n if(i%2==0):\n e+=1\n else:\n o+=1\n if(o<=x//2):\n f=1\n elif(e<=x//2):\n if((k-x)%2!=0):\n f=0\n else:\n f=1\n else:\n if(x%2==0):\n f=1\n else:\n f=0\n if(f==1):\n print('Jesse')\n else:\n print('Walter')\n```","inputs":"2\n5 3\n4 4 4 3 4\n7 4\n3 3 1 1 1 2 4\n","output":"Jesse\nWalter\n","actual_output":"Jesse\nWalter\n","execution_success":true,"sample_index":836},{"source":"apps","task_type":"verifiable_code","in_source_id":"1242","prompt":"Solve the following coding problem using the programming language python:\n\nChef loves to play with arrays by himself. Today, he has an array A consisting of N distinct integers. He wants to perform the following operation on his array A.\n\n- Select a pair of adjacent integers and remove the larger one of these two. This decreases the array size by 1. Cost of this operation will be equal to the smaller of them.\n\nFind out minimum sum of costs of operations needed to convert the array into a single element.\n\n-----Input-----\nFirst line of input contains a single integer T denoting the number of test cases. First line of each test case starts with an integer N denoting the size of the array A. Next line of input contains N space separated integers, where the ith integer denotes the value Ai.\n\n-----Output-----\nFor each test case, print the minimum cost required for the transformation.\n\n-----Constraints-----\n- 1 \u2264 T \u2264 10 \n- 2 \u2264 N \u2264 50000 \n- 1 \u2264 Ai \u2264 105 \n\n-----Subtasks-----\n- Subtask 1 : 2 \u2264 N \u2264 15 : 35 pts \n- Subtask 2 : 2 \u2264 N \u2264 100 : 25 pts \n- Subtask 3 : 2 \u2264 N \u2264 50000 : 40 pts \n\n-----Example-----\nInput\n2\n2\n3 4\n3\n4 2 5\n\nOutput\n3\n4\n\n-----Explanation-----Test 1 : Chef will make only 1 move: pick up both the elements (that is, 3 and 4), remove the larger one (4), incurring a cost equal to the smaller one (3).\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfrom math import *\nfor t in range(int(input())):\n n = int(input())\n numberlist = list(map(int,input().split()))\n numberlist.sort()\n print(numberlist[0]* ( len(numberlist) -1))\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n2\\n3 4\\n3\\n4 2 5\\n', 'output': '3\\n4\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/MNMX'}","problem_id":"vfc_3810","program":"```python\nfrom math import *\nfor t in range(int(input())):\n n = int(input())\n numberlist = list(map(int,input().split()))\n numberlist.sort()\n print(numberlist[0]* ( len(numberlist) -1))\n```","inputs":"2\n2\n3 4\n3\n4 2 5\n","output":"3\n4\n","actual_output":"3\n4\n","execution_success":true,"sample_index":837},{"source":"apps","task_type":"verifiable_code","in_source_id":"1243","prompt":"Solve the following coding problem using the programming language python:\n\nChef has a number N, Cheffina challenges the chef to check the divisibility of all the permutation of N by 5. If any of the permutations is divisible by 5 then print 1 else print 0.\n\n-----Input:-----\n- First-line will contain $T$, the number of test cases. Then the test cases follow. \n- Each test case contains a single line of input,$N$. \n\n-----Output:-----\nFor each test case, output in a single line answer 1 or 0.\n\n-----Constraints-----\n- $1 \\leq T \\leq 10^6$\n- $1 \\leq N \\leq 10^6$\n\n-----Sample Input:-----\n2\n19\n385\n\n-----Sample Output:-----\n0\n1\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\na = int(input())\r\nfor i in range(a):\r\n\tb = input()\r\n\tif '5' in b or '0' in b:\r\n\t\tprint(1)\r\n\t\tcontinue\r\n\tprint(0)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n19\\n385\\n', 'output': '0\\n1\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/PSTR2020/problems/ITGUY06'}","problem_id":"vfc_3814","program":"```python\na = int(input())\r\nfor i in range(a):\r\n\tb = input()\r\n\tif '5' in b or '0' in b:\r\n\t\tprint(1)\r\n\t\tcontinue\r\n\tprint(0)\n```","inputs":"2\n19\n385\n","output":"0\n1\n","actual_output":"0\n1\n","execution_success":true,"sample_index":838},{"source":"apps","task_type":"verifiable_code","in_source_id":"1244","prompt":"Solve the following coding problem using the programming language python:\n\nA Train started its journey at x=-infinity is travelling on the x-Coordinate Axis. Given n passengers and the coordinates $b_i$ and $d_i$ for each of the $ith$ passenger at which they board and leave from the train respectively. Due to current COVID-19 crisis, the train is monitored at each mile/coordinate. The infection degree of the train at each mile is equal to the total passengers present in the train at that mile/coordinate. The train stops its journey if no more passengers are there to board the train. The term infection severity of the journey is defined as the sum of infection degrees noted at each mile. Find the Infection severity of the journey. Note: A passenger is considered for calculation of infection degree at both boarding and leaving stations.\n\nSince the answer can be very large, print it modulo $(10^9)+7$.\n\n-----Input:-----\n- First line will contain $N$, number of passengers. Then the $N$ lines follow. \n- $i$th line contains two integers $b_i, d_i$ , the boarding and departure mile of $i$th passenger.\n\n-----Output:-----\nPrint a single value, the Infection Severity of the journey modulo $(10^9)+7$.\n\n-----Constraints-----\n- $0 \\leq N \\leq 100000$\n- $-500000 \\leq b_i \\leq 500000$\n- $-500000 \\leq d_i \\leq 500000$\n\n-----Sample Input:-----\n3\n\n0 2\n\n1 3\n\n-1 4 \n\n-----Sample Output:-----\n12 \n\n-----EXPLANATION:-----\nInfection degree at :\n\n-1 is 1\n\n0 is 2\n\n1 is 3\n\n2 is 3\n\n3 is 2\n\n4 is 1\n\nCalculation started at mile -1 and ended at mile 4. Infection Severity = 1+2+3+3+2+1 =12\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nc=0\nfor i in range (int(input ())):\n\ta, b=map(int, input().split())\n\tc+=abs(a-b)+1\nprint(c%((10**9) +7)) \n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\n0 2\\n1 3\\n-1 4\\n', 'output': '12\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/COW42020/problems/COW3C'}","problem_id":"vfc_3818","program":"```python\nc=0\nfor i in range (int(input ())):\n\ta, b=map(int, input().split())\n\tc+=abs(a-b)+1\nprint(c%((10**9) +7)) \n```","inputs":"3\n0 2\n1 3\n-1 4\n","output":"12\n","actual_output":"12\n","execution_success":true,"sample_index":839},{"source":"apps","task_type":"verifiable_code","in_source_id":"1245","prompt":"Solve the following coding problem using the programming language python:\n\nThe 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.\n\n-----Input:-----\n- First-line will contain $T$, the number of test cases. Then the test cases follow. \n- Each test case contains a single line of input, one integer $K$. \n\n-----Output:-----\nFor each test case, output as the pattern.\n\n-----Constraints-----\n- $1 \\leq T \\leq 100$\n- $1 \\leq K \\leq 100$\n\n-----Sample Input:-----\n4\n1\n2\n3\n4\n\n-----Sample Output:-----\n1\n13\n57\n135\n7911\n131517\n1357\n9111315\n17192123\n25272931\n\n-----EXPLANATION:-----\nNo need, else pattern can be decode easily.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nn = int(input())\r\nl = [0] * n\r\nfor x in range(n):\r\n l[x] = int(input())\r\nfor i in range(n):\r\n z = 1\r\n for j in range(1,l[i]+1):\r\n for k in range(1,l[i]+1):\r\n print(z,end='')\r\n z += 2\r\n print()\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '4\\n1\\n2\\n3\\n4\\n', 'output': '1\\n13\\n57\\n135\\n7911\\n131517\\n1357\\n9111315\\n17192123\\n25272931\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/PTRN2021/problems/ITGUY51'}","problem_id":"vfc_3822","program":"```python\nn = int(input())\r\nl = [0] * n\r\nfor x in range(n):\r\n l[x] = int(input())\r\nfor i in range(n):\r\n z = 1\r\n for j in range(1,l[i]+1):\r\n for k in range(1,l[i]+1):\r\n print(z,end='')\r\n z += 2\r\n print()\n```","inputs":"4\n1\n2\n3\n4\n","output":"1\n13\n57\n135\n7911\n131517\n1357\n9111315\n17192123\n25272931\n","actual_output":"1\n13\n57\n135\n7911\n131517\n1357\n9111315\n17192123\n25272931\n","execution_success":true,"sample_index":840},{"source":"apps","task_type":"verifiable_code","in_source_id":"1246","prompt":"Solve the following coding problem using the programming language python:\n\nWalter White and Jesse Pinkman (a drug addict) both love to play with chemicals. One day they were playing with some chemicals to make an energy drink. Unknowingly they made a highly powerful drink. To test the drink on others also they called some of their friends and gave a drop of it to everyone. Now they all were feeling highly energetic and thought of an unique game to play with each other.\nAfter pondering for a while, Jesse came up with an extraordinary idea of competing in a race around a circular globe with N checkpoints each of one unit. Walter and all their other friends agreed with it.They divided themselves in $2$ teams with $N$ teammates in each team.This race has two commencing points $A$ and $B$ strictly facing each other. Walter and his team commences from $A$ point and other team starts from $B$. Both the teams start running at the same time clockwise around the globe. Speed of every player is constant throughout the race. If a player has a speed $X$ then it means that he covers a distance of $X$ units in one second.The race ends when some member of one team overtakes all members of opposite team at any point of time. Now you have to tell if any team will win the race or not.They all are stubborn and can run forever just to win the race. Help them to know if it is possible in anyway that the race will come to an end. \nFor Clarity, you can visualize the path as a circular paths where $A$ and $B$ are opposite ends of diameter. It can be proven that the actual circumference of circle do not affect the answer.\nIt is also possible that someone don't run at all.Keep in mind that the fastest one wins the race so does the code.\n\n-----Input:------\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. \n- The first line of each test case contains a single integer $N$ number of teammates in both team.\n- The second line contains $N$ space-separated integers $A_1, A_2 \\ldots A_N$ denoting speed of A's Team\n- The third line contains $N$ space-separated integers $B_1, B_2 \\ldots B_N$ denoting speed of B's Team\n\n-----Output:------\nFor each test case, print a single line denoting YES if the race ends at any point of time else NO\n\n-----Constraints-----\n- $1 \\leq T \\leq 10$\n- $1 \\leq N \\leq 10^5$\n- $0 \\leq A_i \\leq 2^{15}$\n- $0 \\leq B_i \\leq 2^{15}$\n\n-----Subtasks-----\nSubtask #1 (30 points): \n- $1 \\le N \\le 20$\n- $0 \\le A_i \\le 11$\n- $0 \\le B_i \\le 11$\nSubtask #2 (70 points): \n- Original constraints\n\n-----Sample input:-----\n1\n5\n1 2 3 4 5\n2 7 8 9 9\n\n-----Sample output-----\nYES\n\n-----Sample Explanation:------\nTeam B can overtake all members of Team A.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\nl1=int(input())\nfor i in range(l1):\n x=int(input())\n y=list(map(int,input().split()))\n z=list(map(int,input().split()))\n if max(z)!=max(y):\n print('YES')\n else:\n print('NO')\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n5\\n1 2 3 4 5\\n2 7 8 9 9\\n\\n', 'output': 'YES\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/CHPTRS01/problems/FUNRUN'}","problem_id":"vfc_3826","program":"```python\n# cook your dish here\nl1=int(input())\nfor i in range(l1):\n x=int(input())\n y=list(map(int,input().split()))\n z=list(map(int,input().split()))\n if max(z)!=max(y):\n print('YES')\n else:\n print('NO')\n```","inputs":"1\n5\n1 2 3 4 5\n2 7 8 9 9\n\n","output":"YES\n","actual_output":"YES\n","execution_success":true,"sample_index":841},{"source":"apps","task_type":"verifiable_code","in_source_id":"1247","prompt":"Solve the following coding problem using the programming language python:\n\nChef received a permutation $P_1, P_2, \\ldots, P_N$ and also an integer $D$ from his good friend Grux, because Grux was afraid he would forget them somewhere. However, since Grux was just playing with the permutation, it was all shuffled, and Chef only likes sorted permutations, so he decided to sort it by performing some swaps.\nChef wants to use the integer $D$ he just received, so he is only willing to swap two elements of the permutation whenever their absolute difference is exactly $D$. He has limited time, so you should determine the minimum number of swaps he needs to perform to sort the permutation, or tell him that it is impossible to sort it his way.\n\n-----Input-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The first line of each test case contains two space-separated integers $N$ and $D$.\n- The second line contains $N$ space-separated integers $P_1, P_2, \\ldots, P_N$.\n\n-----Output-----\nFor each test case, print a single line containing one integer \u2015 the minimum number of swaps, or $-1$ if it is impossible to sort the permutation.\n\n-----Constraints-----\n- $1 \\le T \\le 20$\n- $1 \\le N \\le 200,000$\n- $1 \\le D \\le N$\n- $1 \\le P_i \\le N$ for each valid $i$\n- $P_1, P_2, \\ldots, P_N$ are pairwise distinct\n- the sum of $N$ over all test cases does not exceed $10^6$\n\n-----Subtasks-----\nSubtask #1 (20 points): $D = 1$\nSubtask #2 (30 points):\n- $N \\le 1,000$\n- the sum of $N$ over all test cases does not exceed $10,000$\nSubtask #3 (50 points): original constraints\n\n-----Example Input-----\n2\n5 2 \n3 4 5 2 1\n5 2 \n4 3 2 1 5 \n\n-----Example Output-----\n3\n-1\n\n-----Explanation-----\nExample case 1: Chef can perform the following swaps in this order:\n- swap the first and fifth element\n- swap the third and fifth element\n- swap the second and fourth element\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nimport sys\nsys.setrecursionlimit(10000000)\ndef mergeSortInversions(arr):\n if len(arr) == 1:\n return arr, 0\n larr=len(arr)\n a = arr[:larr//2]\n b = arr[larr//2:]\n a, ai = mergeSortInversions(a)\n b, bi = mergeSortInversions(b)\n c = []\n i = 0\n j = 0\n inversions = 0 + ai + bi\n la=len(a)\n while i < la and j < len(b):\n if a[i] <= b[j]:\n c.append(a[i])\n i += 1\n else:\n c.append(b[j])\n j += 1\n inversions += (la-i)\n c += a[i:]\n c += b[j:]\n return c, inversions \nfor _ in range(int(input())):\n n,d=list(map(int,input().split()))\n p=[int(o) for o in input().split()]\n array=[[] for i in range(d)]\n flag=0\n for i in range(n):\n array[i%d].append(p[i])\n if p[i]%((i%d)+1)!=0:\n flag=1\n \n \n ans=0\n dumarr=[0]*n\n for i in range(d):\n array[i],v=mergeSortInversions(array[i])\n for j in range(len(array[i])):\n dumarr[i+j*d]=array[i][j]\n ans+=v\n p=sorted(p)\n # print(dumarr)\n if dumarr==p:\n print(ans)\n else:\n print(-1)\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n5 2\\n3 4 5 2 1\\n5 2\\n4 3 2 1 5\\n', 'output': '3\\n-1\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/DPERM'}","problem_id":"vfc_3830","program":"```python\nimport sys\nsys.setrecursionlimit(10000000)\ndef mergeSortInversions(arr):\n if len(arr) == 1:\n return arr, 0\n larr=len(arr)\n a = arr[:larr//2]\n b = arr[larr//2:]\n a, ai = mergeSortInversions(a)\n b, bi = mergeSortInversions(b)\n c = []\n i = 0\n j = 0\n inversions = 0 + ai + bi\n la=len(a)\n while i < la and j < len(b):\n if a[i] <= b[j]:\n c.append(a[i])\n i += 1\n else:\n c.append(b[j])\n j += 1\n inversions += (la-i)\n c += a[i:]\n c += b[j:]\n return c, inversions \nfor _ in range(int(input())):\n n,d=list(map(int,input().split()))\n p=[int(o) for o in input().split()]\n array=[[] for i in range(d)]\n flag=0\n for i in range(n):\n array[i%d].append(p[i])\n if p[i]%((i%d)+1)!=0:\n flag=1\n \n \n ans=0\n dumarr=[0]*n\n for i in range(d):\n array[i],v=mergeSortInversions(array[i])\n for j in range(len(array[i])):\n dumarr[i+j*d]=array[i][j]\n ans+=v\n p=sorted(p)\n # print(dumarr)\n if dumarr==p:\n print(ans)\n else:\n print(-1)\n\n```","inputs":"2\n5 2\n3 4 5 2 1\n5 2\n4 3 2 1 5\n","output":"3\n-1\n","actual_output":"3\n-1\n","execution_success":true,"sample_index":842},{"source":"apps","task_type":"verifiable_code","in_source_id":"1248","prompt":"Solve the following coding problem using the programming language python:\n\nChef has recently learned about number bases and is becoming fascinated.\nChef learned that for bases greater than ten, new digit symbols need to be introduced, and that the convention is to use the first few letters of the English alphabet. For example, in base 16, the digits are 0123456789ABCDEF. Chef thought that this is unsustainable; the English alphabet only has 26 letters, so this scheme can only work up to base 36. But this is no problem for Chef, because Chef is very creative and can just invent new digit symbols when she needs them. (Chef is very creative.)\nChef also noticed that in base two, all positive integers start with the digit 1! However, this is the only base where this is true. So naturally, Chef wonders: Given some integer N, how many bases b are there such that the base-b representation of N starts with a 1?\n\n-----Input-----\nThe first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.\nEach test case consists of one line containing a single integer N (in base ten).\n\n-----Output-----\nFor each test case, output a single line containing the number of bases b, or INFINITY if there are an infinite number of them.\n\n-----Constraints-----\n\n-----Subtasks-----Subtask #1 (16 points):\n- 1 \u2264 T \u2264 103\n- 0 \u2264 N < 103\nSubtask #2 (24 points):\n- 1 \u2264 T \u2264 103\n- 0 \u2264 N < 106\nSubtask #3 (28 points):\n- 1 \u2264 T \u2264 103\n- 0 \u2264 N < 1012\nSubtask #4 (32 points):\n- 1 \u2264 T \u2264 105\n- 0 \u2264 N < 1012\n\n-----Example-----\nInput:4\n6\n9\n11\n24\n\nOutput:4\n7\n8\n14\n\n-----Explanation-----\nIn the first test case, 6 has a leading digit 1 in bases 2, 4, 5 and 6: 610 = 1102 = 124 = 115 = 106.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\ndef finder(n):\n cnt=0\n for i in range(2,n+1):\n a=n\n while a!=0:\n r=a%i\n a=a//i\n if r==1:\n cnt+=1\n return cnt\n\nt=int(input())\nfor _ in range(t):\n n=int(input())\n if n==0:\n print(0)\n elif n==1:\n print('INFINITY')\n else:\n print(finder(n))\n \n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '4\\n6\\n9\\n11\\n24\\n', 'output': '4\\n7\\n8\\n14\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/BASE'}","problem_id":"vfc_3834","program":"```python\n# cook your dish here\ndef finder(n):\n cnt=0\n for i in range(2,n+1):\n a=n\n while a!=0:\n r=a%i\n a=a//i\n if r==1:\n cnt+=1\n return cnt\n\nt=int(input())\nfor _ in range(t):\n n=int(input())\n if n==0:\n print(0)\n elif n==1:\n print('INFINITY')\n else:\n print(finder(n))\n \n```","inputs":"4\n6\n9\n11\n24\n","output":"4\n7\n8\n14\n","actual_output":"4\n7\n8\n14\n","execution_success":true,"sample_index":843},{"source":"apps","task_type":"verifiable_code","in_source_id":"1250","prompt":"Solve the following coding problem using the programming language python:\n\nOur chef has been assigned a task to make a necklace of length N, from gold, diamond and platinum.There is single kind of gold, two types of diamond and three types of platinum available.\nA necklace can be represented as strings of the form (G)\u2217(D1|D2)\u2217(P1|P2|P3)\u2217$ (G)*(D1|D2)*(P1|P2|P3)* $ where (x|y) means we can use x or y and \u2217$ * $ means we can repeat the previous parenthesized expression 0 or more times.\nInstead of making necklace he choose to count all such distinct necklaces possible for a given length N.\n\n-----Input:-----\n-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.\n-Only line of every test case contains an integer N$N$ denoting the length of the necklace required.\n\n-----Output:-----\nFor each test case, print the number of all such distinct necklaces, with given length. As the number can be really large, print it modulo 109+7$10^{9}+7$.\n\n-----Constraints-----\n- 1\u2264T\u226410000$1 \\leq T \\leq 10000$\n- 2\u2264N\u22641000000000$2 \\leq N \\leq 1000000000$\n- String S$S$ consists of only upper case english alphabets.\n\n-----Subtasks-----\n- 20 points : 1\u2264N\u22645$1 \\leq N \\leq 5$\n- 70 points : Original$Original$ Constraints$Constraints$\n\n-----Sample Input:-----\n2\n1\n2\n\n-----Sample Output:-----\n6\n25\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nt=int(input())\r\nfor _ in range(t):\r\n n=int(input())\r\n p=10**9+7\r\n a=(pow(3,n+1,p)-1)\r\n \r\n b=(pow(2,n+1,p)-1)\r\n \r\n print((((3*a)//2)%p-(2*(b))%p+p)%p)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n1\\n2\\n', 'output': '6\\n25\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/ALQU2018/problems/GDP'}","problem_id":"vfc_3842","program":"```python\nt=int(input())\r\nfor _ in range(t):\r\n n=int(input())\r\n p=10**9+7\r\n a=(pow(3,n+1,p)-1)\r\n \r\n b=(pow(2,n+1,p)-1)\r\n \r\n print((((3*a)//2)%p-(2*(b))%p+p)%p)\n```","inputs":"2\n1\n2\n","output":"6\n25\n","actual_output":"6\n25\n","execution_success":true,"sample_index":845},{"source":"apps","task_type":"verifiable_code","in_source_id":"1251","prompt":"Solve the following coding problem using the programming language python:\n\nChef likes to travel very much. He plans some travel routes and wants to know their lengths. He hired you to make these calculations. But be careful, some of the routes are incorrect. There may be some misspelling in city names or there will be no road between some two consecutive cities in the route. Also note that Chef hates to visit the same city twice during his travel. Even the last city should differ from the first. Two consecutive cities in the route should also be different. So you need to check these conditions for the given routes too.\n\nYou will be given the list of all cities and all roads between them with their lengths. All roads are one-way. Also you will be given the list of all travel routes that Chef plans. For each route you should check whether it is correct and find its length in this case.\n\n-----Input-----\n\nThe first line contains positive integer N, the number of cities. The second line contains space separated list of N strings, city names. All city names are distinct.\n\nThe third line contains non-negative integer M, the number of available roads. Each of the next M lines describes one road and contains names C1 and C2 of two cities followed by the positive integer D, the length of the one-way road that connects C1 with C2. It is guaranteed that C1 and C2 will be correct names of two different cities from the list of N cities given in the second line of the input file. For each pair of different cities there is at most one road in each direction and each road will be described exactly once in the input file.\n\nNext line contains positive integer T, the number of travel routes planned by the Chef. Each of the next T lines contains positive integer K followed by K strings, names of cities of the current route. Cities are given in order in which Chef will visit them during his travel.\n\nAll strings in the input file composed only of lowercase, uppercase letters of the English alphabet and hyphens. Each string is non-empty and has length at most 20. If some line of the input file contains more then one element than consecutive elements of this line are separated by exactly one space. Each line of the input file has no leading or trailing spaces.\n\n-----Output-----\nFor each travel route from the input file output a single line containing word ERROR if the route is incorrect and its length otherwise.\n\n-----Constraints-----\n\n1 <= N <= 50\n\n0 <= M <= N * (N - 1)\n\n1 <= D <= 20000\n\n1 <= T <= 50\n\n1 <= K <= 50\n\n1 <= length of each string <= 20\n\n-----Example-----\nInput:\n5\nDonetsk Kiev New-York Miami Hollywood\n9\nDonetsk Kiev 560\nKiev New-York 7507\nNew-York Miami 1764\nMiami Hollywood 28\nHollywood Miami 30\nMiami New-York 1764\nKiev Donetsk 550\nHollywood New-York 1736\nNew-York Hollywood 1738\n13\n5 Donetsk Kiev New-York Miami Hollywood\n5 Hollywood Miami New-York Kiev Donetsk\n3 Donetsk Kiev Donetsk\n2 Kyiv New-York\n3 New-York Hollywood Miami\n2 New-York Miami\n3 Hollywood New-York Miami\n4 Donetsk Kiev Miami Hollywood\n2 Donetsk Hollywood\n1 Donetsk\n2 Mumbai Deli\n6 Donetsk Kiev New-York Miami Hollywood New-York\n2 Miami Miami\n\nOutput:\n9859\nERROR\nERROR\nERROR\n1768\n1764\n3500\nERROR\nERROR\n0\nERROR\nERROR\nERROR\n\n-----Explanation-----\nThe 2nd route is incorrect since there is no road from New-York to Kiev. Note however that inverse road from Kiev to New-York exists. \n\nThe 3rd route is incorrect since the first city coincides with the last one. \n\nThe 4th route is incorrect since there is no city with name Kyiv (Probably Chef means Kiev but he misspells this word). \n\nThe 8th route is incorrect since there is no road from Miami to Kiev. \n\nThe 9th route is incorrect since there is no road from Donetsk to Hollywood. \n\nThe 10th route is correct. Note that a route composed of exactly one city is always correct provided that city name is written correctly. \n\nThe 11th route is incorrect since there is no cities with names Mumbai and Deli. (Probably Chef is not so good in geography :)) \n\nThe 12th route is incorrect since city New-York is visited twice. \n\nFinally the 13th route is incorrect since we have equal consecutive cities.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nimport 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\nn = _r(int)\nlookup = dict([(x, i) for i, x in enumerate(_ra(str))])\ng = [(set(), dict()) for _ in range(n)]\n\nm = _r(int)\nfor _ in range(m) :\n c1, c2, d = _r(str, str, int)\n i1 = lookup[c1]\n\n g[i1][0].add(c2)\n g[i1][1][c2] = d\n\n\nt = _r(int)\nfor _ in range(t) :\n k = _ra(str)[1:]\n \n failed = False\n if len(set(k)) != len(k) :\n failed = True\n\n if not failed :\n if k[0] not in lookup : \n failed = True\n else : \n r = 0\n v = g[lookup[k[0]]]\n\n for i in range(1, len(k)) : \n if k[i] not in v[0] : \n failed = True\n break\n\n r += v[1][k[i]]\n v = g[lookup[k[i]]]\n \n if not failed : \n print(r)\n \n if failed : \n print('ERROR')\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '5\\nDonetsk Kiev New-York Miami Hollywood\\n9\\nDonetsk Kiev 560\\nKiev New-York 7507\\nNew-York Miami 1764\\nMiami Hollywood 28\\nHollywood Miami 30\\nMiami New-York 1764\\nKiev Donetsk 550\\nHollywood New-York 1736\\nNew-York Hollywood 1738\\n13\\n5 Donetsk Kiev New-York Miami Hollywood\\n5 Hollywood Miami New-York Kiev Donetsk\\n3 Donetsk Kiev Donetsk\\n2 Kyiv New-York\\n3 New-York Hollywood Miami\\n2 New-York Miami\\n3 Hollywood New-York Miami\\n4 Donetsk Kiev Miami Hollywood\\n2 Donetsk Hollywood\\n1 Donetsk\\n2 Mumbai Deli\\n6 Donetsk Kiev New-York Miami Hollywood New-York\\n2 Miami Miami\\n', 'output': '9859\\nERROR\\nERROR\\nERROR\\n1768\\n1764\\n3500\\nERROR\\nERROR\\n0\\nERROR\\nERROR\\nERROR\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/TRAVELER'}","problem_id":"vfc_3846","program":"```python\nimport 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\nn = _r(int)\nlookup = dict([(x, i) for i, x in enumerate(_ra(str))])\ng = [(set(), dict()) for _ in range(n)]\n\nm = _r(int)\nfor _ in range(m) :\n c1, c2, d = _r(str, str, int)\n i1 = lookup[c1]\n\n g[i1][0].add(c2)\n g[i1][1][c2] = d\n\n\nt = _r(int)\nfor _ in range(t) :\n k = _ra(str)[1:]\n \n failed = False\n if len(set(k)) != len(k) :\n failed = True\n\n if not failed :\n if k[0] not in lookup : \n failed = True\n else : \n r = 0\n v = g[lookup[k[0]]]\n\n for i in range(1, len(k)) : \n if k[i] not in v[0] : \n failed = True\n break\n\n r += v[1][k[i]]\n v = g[lookup[k[i]]]\n \n if not failed : \n print(r)\n \n if failed : \n print('ERROR')\n\n```","inputs":"5\nDonetsk Kiev New-York Miami Hollywood\n9\nDonetsk Kiev 560\nKiev New-York 7507\nNew-York Miami 1764\nMiami Hollywood 28\nHollywood Miami 30\nMiami New-York 1764\nKiev Donetsk 550\nHollywood New-York 1736\nNew-York Hollywood 1738\n13\n5 Donetsk Kiev New-York Miami Hollywood\n5 Hollywood Miami New-York Kiev Donetsk\n3 Donetsk Kiev Donetsk\n2 Kyiv New-York\n3 New-York Hollywood Miami\n2 New-York Miami\n3 Hollywood New-York Miami\n4 Donetsk Kiev Miami Hollywood\n2 Donetsk Hollywood\n1 Donetsk\n2 Mumbai Deli\n6 Donetsk Kiev New-York Miami Hollywood New-York\n2 Miami Miami\n","output":"9859\nERROR\nERROR\nERROR\n1768\n1764\n3500\nERROR\nERROR\n0\nERROR\nERROR\nERROR\n","actual_output":"9859\nERROR\nERROR\nERROR\n1768\n1764\n3500\nERROR\nERROR\n0\nERROR\nERROR\nERROR\n","execution_success":true,"sample_index":846},{"source":"apps","task_type":"verifiable_code","in_source_id":"1252","prompt":"Solve the following coding problem using the programming language python:\n\nGiven a number $n$, give the last digit of sum of all the prime numbers from 1 to $n$ inclusive.\n\n-----Input:-----\n- First line contains number of testcase $t$.\n- Each testcase contains of a single line of input, number $n$. \n\n-----Output:-----\nLast digit of sum of every prime number till n.\n\n-----Constraints-----\n- $1 \\leq T \\leq 10$\n- $2 \\leq N \\leq 10^6$\n\n-----Sample Input:-----\n1\n10\n\n-----Sample Output:-----\n7\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\nimport math\nN = 10**6\nsum_arr = [0] * (N + 1) \ndef lprime():\n arr = [0] * (N + 1) \n arr[0] = 1\n arr[1] = 1\n for i in range(2, math.ceil(math.sqrt(N) + 1)): \n if arr[i] == 0: \n for j in range(i * i, N + 1, i): \n arr[j] = 1\n \n curr_prime_sum = 0\n\n for i in range(1, N + 1): \n if arr[i] == 0: \n curr_prime_sum += i \n sum_arr[i] = curr_prime_sum \n \nn=int(input())\nlprime()\nfor _ in range(n):\n x=int(input())\n print(sum_arr[x]%10)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n10\\n', 'output': '7\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/CSEP2020/problems/IRVS'}","problem_id":"vfc_3850","program":"```python\n# cook your dish here\nimport math\nN = 10**6\nsum_arr = [0] * (N + 1) \ndef lprime():\n arr = [0] * (N + 1) \n arr[0] = 1\n arr[1] = 1\n for i in range(2, math.ceil(math.sqrt(N) + 1)): \n if arr[i] == 0: \n for j in range(i * i, N + 1, i): \n arr[j] = 1\n \n curr_prime_sum = 0\n\n for i in range(1, N + 1): \n if arr[i] == 0: \n curr_prime_sum += i \n sum_arr[i] = curr_prime_sum \n \nn=int(input())\nlprime()\nfor _ in range(n):\n x=int(input())\n print(sum_arr[x]%10)\n```","inputs":"1\n10\n","output":"7\n","actual_output":"7\n","execution_success":true,"sample_index":847},{"source":"apps","task_type":"verifiable_code","in_source_id":"1253","prompt":"Solve the following coding problem using the programming language python:\n\nPeople in Karunanagar are infected with Coronavirus. To understand the spread of disease and help contain it as early as possible, Chef wants to analyze the situation in the town. Therefore, he does the following:\n- Chef represents the population of Karunanagar as a binary string of length $N$ standing in a line numbered from $1$ to $N$ from left to right, where an infected person is represented as $1$ and an uninfected person as $0$.\n- Every day, an infected person in this binary string can infect an adjacent (the immediate left and right) uninfected person.\n- Therefore, if before Day 1, the population is $00100$, then at the end of Day 1, it becomes $01110$ and at the end of Day 2, it becomes $11111$.\nBut people of Karunanagar are smart and they know that if they 'socially isolate' themselves as early as possible, they reduce the chances of the virus spreading. Therefore on $i$-th day, person numbered $P_i$ isolates himself from person numbered $P_i - 1$, thus cannot affect each other. This continues in the town for $D$ days.\nGiven the population binary string before Day 1, Chef wants to calculate the total number of infected people in Karunanagar at the end of the day $D$. Since Chef has gone to wash his hands now, can you help do the calculation for him?\n\n-----Input:-----\n- First line will contain $T$, number of testcases. Then the test cases follow. \n- The first line of each test case contains a single integer $N$ denoting the length of the binary string.\n- The next line contains a binary string of length $N$ denoting the population before the first day, with $1$ for an infected person and $0$ for uninfected.\n- The next line contains a single integer $D$ - the number of days people isolate themselves.\n- The next line contains $P$ - a list of $D$ distinct space-separated integers where each $P_{i}$ denotes that at the start of $i^{th}$ day, person $P_{i}$ isolated him/herself from the person numbered $P_i-1$.\n\n-----Output:-----\nFor each test case, print a single integer denoting the total number of people who are infected after the end of $D^{th}$ day.\n\n-----Constraints-----\n- $1 \\leq T \\leq 200$\n- $2 \\leq N \\leq 10^{4}$\n- $1 \\leq D < N$\n- $2 \\leq P_{i} \\leq N$ for $1 \\le i \\le D$\n\n-----Subtasks-----\nSubtask #1(30 points): $1 \\leq T \\leq 100$, $2 \\leq N \\leq 2000$\nSubtask #2(70 points): Original Constraints\n\n-----Sample Input:-----\n2\n9\n000010000\n3\n2 5 8\n5\n00001\n1\n5\n\n-----Sample Output:-----\n6\n1\n\n-----EXPLANATION:-----\nFor the purpose of this explanation, a social distance can be denoted with a '$|$'.\nFor the first testcase:\n- \nBefore Day $1$, the population is: $0|00010000$\n- \nBefore Day $2$, the population is: $0|001|11000$\n- \nBefore Day $3$, the population is: $0|011|111|00$\n- \nTherefore, after Day $3$, the population will be: $0|111|111|00$\nSo, there are $6$ infected persons.\nFor the second testcase:\nBefore Day $1$, the population is: $0000|1$\nTherefore, there is one infected person.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\nT = int(input())\n\nfor i in range(T):\n N,data,D,People = int(input()),list(map(int,list(input()))),int(input()),list(map(int,input().split()))\n \n data.insert(0,\"|\"),data.append(\"|\")\n infected = []\n for i in range(1,N+1):\n if(data[i]==1):\n infected.append(i)\n \n i = 0\n while(i=boundary):\n index+=1\n infected[p]+=1\n if(data[index]==1):\n if(data[index+1]==0):\n data[index+1] = 1\n infected.append(index+1)\n if(data[index-1]==0):\n data[index-1] = 1\n infected.append(index-1)\n else:\n infected.remove(index)\n times-=1\n i+=1\n infected.sort()\n \n print(data.count(1))\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n9\\n000010000\\n3\\n2 5 8\\n5\\n00001\\n1\\n5\\n', 'output': '6\\n1\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/CHPTRS01/problems/WASHHAND'}","problem_id":"vfc_3854","program":"```python\n# cook your dish here\nT = int(input())\n\nfor i in range(T):\n N,data,D,People = int(input()),list(map(int,list(input()))),int(input()),list(map(int,input().split()))\n \n data.insert(0,\"|\"),data.append(\"|\")\n infected = []\n for i in range(1,N+1):\n if(data[i]==1):\n infected.append(i)\n \n i = 0\n while(i=boundary):\n index+=1\n infected[p]+=1\n if(data[index]==1):\n if(data[index+1]==0):\n data[index+1] = 1\n infected.append(index+1)\n if(data[index-1]==0):\n data[index-1] = 1\n infected.append(index-1)\n else:\n infected.remove(index)\n times-=1\n i+=1\n infected.sort()\n \n print(data.count(1))\n```","inputs":"2\n9\n000010000\n3\n2 5 8\n5\n00001\n1\n5\n","output":"6\n1\n","actual_output":"6\n1\n","execution_success":true,"sample_index":848},{"source":"apps","task_type":"verifiable_code","in_source_id":"1254","prompt":"Solve the following coding problem using the programming language python:\n\nChef wants to organize a contest. Predicting difficulty levels of the problems can be a daunting task. Chef wants his contests to be balanced in terms of difficulty levels of the problems.\nAssume a contest had total P participants. A problem that was solved by at least half of the participants (i.e. P / 2 (integer division)) is said to be cakewalk difficulty. A problem solved by at max P / 10 (integer division) participants is categorized to be a hard difficulty.\nChef wants the contest to be balanced. According to him, a balanced contest must have exactly 1 cakewalk and exactly 2 hard problems. You are given the description of N problems and the number of participants solving those problems. Can you tell whether the contest was balanced or not?\n\n-----Input-----\nThe first line of the input contains an integer T denoting the number of test cases.\nThe first line of each test case contains two space separated integers, N, P denoting the number of problems, number of participants respectively.\nThe second line contains N space separated integers, i-th of which denotes number of participants solving the i-th problem.\n\n-----Output-----\nFor each test case, output \"yes\" or \"no\" (without quotes) denoting whether the contest is balanced or not.\n\n-----Constraints-----\n- 1 \u2264 T, N \u2264 500 \n- 1 \u2264 P \u2264 108 \n- 1 \u2264 Number of participants solving a problem \u2264 P\n\n-----Subtasks-----\n- Subtask #1 (40 points): P is a multiple of 10\n- Subtask #2 (60 points): Original constraints\n\n-----Example-----\nInput\n6\n3 100\n10 1 100\n3 100\n11 1 100\n3 100\n10 1 10\n3 100\n10 1 50\n4 100\n50 50 50 50\n4 100\n1 1 1 1\n\nOutput\nyes\nno\nno\nyes\nno\nno\n\n-----Explanation-----\nExample case 1.: The problems are of hard, hard and cakewalk difficulty. There is 1 cakewalk and 2 hard problems, so the contest is balanced.\nExample case 2.: The second problem is hard and the third is cakewalk. There is 1 cakewalk and 1 hard problem, so the contest is not balanced.\nExample case 3.: All the three problems are hard. So the contest is not balanced.\nExample case 4.: The problems are of hard, hard, cakewalk difficulty. The contest is balanced.\nExample case 5.: All the problems are cakewalk. The contest is not balanced.\nExample case 6.: All the problems are hard. The contest is not balanced.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nt = int(input())\nfor z in range(t) :\n n,p = [int(x) for x in input().split()]\n a = [int(x) for x in input().split()] \n c = [x for x in a if x >= p//2]\n h = [x for x in a if x <= p//10]\n if len(c)==1 and len(h)==2 :\n print(\"yes\")\n else:\n print(\"no\")\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '6\\n3 100\\n10 1 100\\n3 100\\n11 1 100\\n3 100\\n10 1 10\\n3 100\\n10 1 50\\n4 100\\n50 50 50 50\\n4 100\\n1 1 1 1\\n', 'output': 'yes\\nno\\nno\\nyes\\nno\\nno\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/PERFCONT'}","problem_id":"vfc_3858","program":"```python\nt = int(input())\nfor z in range(t) :\n n,p = [int(x) for x in input().split()]\n a = [int(x) for x in input().split()] \n c = [x for x in a if x >= p//2]\n h = [x for x in a if x <= p//10]\n if len(c)==1 and len(h)==2 :\n print(\"yes\")\n else:\n print(\"no\")\n```","inputs":"6\n3 100\n10 1 100\n3 100\n11 1 100\n3 100\n10 1 10\n3 100\n10 1 50\n4 100\n50 50 50 50\n4 100\n1 1 1 1\n","output":"yes\nno\nno\nyes\nno\nno\n","actual_output":"yes\nno\nno\nyes\nno\nno\n","execution_success":true,"sample_index":849},{"source":"apps","task_type":"verifiable_code","in_source_id":"1255","prompt":"Solve the following coding problem using the programming language python:\n\nYou are teaching students to generate strings consisting of unique lowercase latin characters (a-z). You give an example reference string $s$ to the students.\nYou notice that your students just copy paste the reference string instead of creating their own string. So, you tweak the requirements for strings submitted by the students.\nLet us define a function F(s, t) where s and t are strings as the number of characters that are same in both the strings. Note that the position doesn't matter. Here are a few examples of F(s, t):\nF(\"abc\", \"def\") = 0\nF(\"abc\", \"acb\") = 3\nF(\"back\", \"abcd\") = 3\nNow you ask your students to output a string t with lowercase unique characters of the same length as $s$, such that F(s, t) $\\leq k$ where you are also given the value of $k$. If there are multiple such strings, you ask them to output the lexicographically smallest possible string. If no such string is possible, output the string \"NOPE\" without quotes.\n\n-----Input:-----\n- The first line will contain $T$, the number of testcases. Then the testcases follow. \n- Each testcase contains of a single line of input, which contains a string $s$ and an integer $k$.\n\n-----Output:-----\nFor each testcase, output in a single line the lexicographically smallest string t such that F(s, t) <= k or \"NOPE\" without quotes if no such string exists.\n\n-----Constraints-----\n- $1 \\leq T \\leq 10000$\n- $1 \\leq $length of string s $(|s|) \\leq 26$\n- $s$ only consists of characters $a$ to $z$\n- There are no repeating characters in s\n- $0 \\leq k \\leq |s|$\n\n-----Sample Input:-----\n4\nhelowrd 0\nbackground 0\nabcdefghijklmnopqrstuvwxyz 0\nb 1\n\n-----Sample Output:-----\nabcfgij\nefhijlmpqs\nNOPE\na\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfor _ in range(int(input())):\n s,k=map(str,input().split())\n k=int(k)\n n=\"NOPE\"\n al=[0]*26\n for ele in s:\n al[ord(ele)-ord('a')]=1\n l=len(s)\n ans=[]\n # print(al)\n for i in range(26):\n if len(ans)==l:\n break\n elif al[i]==1 and k>0:\n k-=1\n ans.append(chr(i+ord('a')))\n elif al[i]==0:\n ans.append(chr(i+ord('a')))\n \n if len(ans)!=l:\n print(n)\n else:\n print(\"\".join(ans))\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '4\\nhelowrd 0\\nbackground 0\\nabcdefghijklmnopqrstuvwxyz 0\\nb 1\\n', 'output': 'abcfgij\\nefhijlmpqs\\nNOPE\\na\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/SDIFFSTR'}","problem_id":"vfc_3862","program":"```python\nfor _ in range(int(input())):\n s,k=map(str,input().split())\n k=int(k)\n n=\"NOPE\"\n al=[0]*26\n for ele in s:\n al[ord(ele)-ord('a')]=1\n l=len(s)\n ans=[]\n # print(al)\n for i in range(26):\n if len(ans)==l:\n break\n elif al[i]==1 and k>0:\n k-=1\n ans.append(chr(i+ord('a')))\n elif al[i]==0:\n ans.append(chr(i+ord('a')))\n \n if len(ans)!=l:\n print(n)\n else:\n print(\"\".join(ans))\n```","inputs":"4\nhelowrd 0\nbackground 0\nabcdefghijklmnopqrstuvwxyz 0\nb 1\n","output":"abcfgij\nefhijlmpqs\nNOPE\na\n","actual_output":"abcfgij\nefhijlmpqs\nNOPE\na\n","execution_success":true,"sample_index":850},{"source":"apps","task_type":"verifiable_code","in_source_id":"1256","prompt":"Solve the following coding problem using the programming language python:\n\nLittle chef has just been introduced to the world of numbers! While experimenting with addition and multiplication operations, the little chef came up with the following problem:\n\nGiven an array A of non-negative integers, how many pairs of indices i and j exist such that A[i]*A[j] > A[i]+A[j] where i < j .\n\nNow being a learner, little chef isn't able to solve this problem efficiently and hence turns to you for help. \n\n-----Input-----\nFirst line of input contains an integer T denoting the number of test cases. For each test case, the first line contains an integer N denoting the number of integers in the array. The next line contains N space separated integers where the ith integer represents A[i]. \nNote : There may be trailing spaces on each line of input. \n\n-----Output-----\nFor each test, print the required number of pairs in a single line.\n\n-----Constraints-----\n- 1 \u2264 T \u2264 10 \n- 2 \u2264 N \u2264 100000 (105) \n- 0 \u2264 A[i] \u2264 1000000 (106)\n\n-----Example-----\nInput:\n2\n3\n3 4 5\n4\n1 1 1 1\n\nOutput:\n3\n0\n\n-----Explanation-----\n\nExample case 1.\n\nAll pairs of numbers satisfy the criteria. Total number of pairs equals 3.\n\nExample case 2.\n\nNo pair of numbers satisfy the criteria.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\nt = int(input())\n\nres = []\nfor i in range(t):\n n = int(input())\n arr = [int(i) for i in input().split()]\n \n num_2 = 0\n num = 0\n \n for j in range(len(arr)):\n if arr[j] == 2:\n num_2 += 1\n \n if arr[j] > 2:\n num += 1\n \n res.append(num_2 * num + (num * (num - 1)) // 2)\n \nfor z in res:\n print(z)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n3\\n3 4 5\\n4\\n1 1 1 1\\n', 'output': '3\\n0\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/PROSUM'}","problem_id":"vfc_3866","program":"```python\n# cook your dish here\nt = int(input())\n\nres = []\nfor i in range(t):\n n = int(input())\n arr = [int(i) for i in input().split()]\n \n num_2 = 0\n num = 0\n \n for j in range(len(arr)):\n if arr[j] == 2:\n num_2 += 1\n \n if arr[j] > 2:\n num += 1\n \n res.append(num_2 * num + (num * (num - 1)) // 2)\n \nfor z in res:\n print(z)\n```","inputs":"2\n3\n3 4 5\n4\n1 1 1 1\n","output":"3\n0\n","actual_output":"3\n0\n","execution_success":true,"sample_index":851},{"source":"apps","task_type":"verifiable_code","in_source_id":"1257","prompt":"Solve the following coding problem using the programming language python:\n\nThe chef was chatting with his friend who was a mathematician.\nChef said \"Hi !\".\n\nHis friend replied that '!' is the symbol of factorial.\n\nChef had never heard about it and he asked more about it. Then his friend taught him how to calculate the factorial of a number.\n\nChef loved that But as always he got tired after calculating a few values and asked you to do it for him.\n\n-----Input-----\nN : Number of inputs\nthen N lines with input T\n\nN<10\n\nT<=200\n\n-----Output-----\nThe result for the corresponding value of T\n\n-----Example-----\nInput:\n3\n5\n4\n6\n\nOutput:\n120\n24\n720\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfactorials=[1]\n\nfor x in range(1,201):\n factorials.append(factorials[x-1]*x)\n \nx=int(input())\n\nfor x in range(x):\n n=int(input())\n print(factorials[n])\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\n5\\n4\\n6\\n', 'output': '120\\n24\\n720\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/AGTK2012/problems/ALGFACT'}","problem_id":"vfc_3870","program":"```python\nfactorials=[1]\n\nfor x in range(1,201):\n factorials.append(factorials[x-1]*x)\n \nx=int(input())\n\nfor x in range(x):\n n=int(input())\n print(factorials[n])\n```","inputs":"3\n5\n4\n6\n","output":"120\n24\n720\n","actual_output":"120\n24\n720\n","execution_success":true,"sample_index":852},{"source":"apps","task_type":"verifiable_code","in_source_id":"1258","prompt":"Solve the following coding problem using the programming language python:\n\nChef Zidane likes the number 9. He has a number N, and he wants to turn it into a multiple of 9. He cannot add or remove digits, and he can only change one digit at a time. The only allowed operation is to increment or decrement a digit by one, and doing this takes exactly one second. Note that he cannot increase a digit 9 or decrease a digit 0, and the resulting number must not contain any leading zeroes unless N has a single digit.\n\nChef Zidane wants to know the minimum amount of time (in seconds) needed to accomplish this. Please help him, before his kitchen gets overwhelmed with mist!\n\n-----Input-----\nThe first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.\nEach test case consists of one line containing a single positive integer N.\n\n-----Output-----\nFor each test case, output a single line containing the answer.\n\n-----Constraints-----\n- 1 \u2264 T \u2264 105\n- 1 \u2264 N \u2264 10105\n- N will not contain leading zeroes.\n- Each test file is at most 3Mb in size.\n\n-----Example-----\nInput:4\n1989\n86236\n90210\n99999999999999999999999999999999999999988\n\nOutput:0\n2\n3\n2\n\n-----Explanation-----\nExample case 1. 1989 is already divisible by 9, so no operations are needed to be performed.\nExample case 2. 86236 can be turned into a multiple of 9 by incrementing the first and third digit (from the left), to get 96336. This takes 2 seconds.\nExample case 3. 90210 can be turned into a multiple of 9 by decrementing the third digit twice and the fourth digit once, to get 90000. This takes 3 seconds.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\ns=int(input())\nwhile(s>0):\n s-=1\n a=input()\n c=0\n for x in a:\n c+=int(x)\n if(c<9 and len(a)!=1):\n print(9-c%9)\n else:\n print(min(9-c%9,c%9))\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '4\\n1989\\n86236\\n90210\\n99999999999999999999999999999999999999988\\n', 'output': '0\\n2\\n3\\n2\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/DIVNINE'}","problem_id":"vfc_3874","program":"```python\ns=int(input())\nwhile(s>0):\n s-=1\n a=input()\n c=0\n for x in a:\n c+=int(x)\n if(c<9 and len(a)!=1):\n print(9-c%9)\n else:\n print(min(9-c%9,c%9))\n\n```","inputs":"4\n1989\n86236\n90210\n99999999999999999999999999999999999999988\n","output":"0\n2\n3\n2\n","actual_output":"0\n2\n3\n2\n","execution_success":true,"sample_index":853},{"source":"apps","task_type":"verifiable_code","in_source_id":"1259","prompt":"Solve the following coding problem using the programming language python:\n\nVasya likes the number $239$. Therefore, he considers a number pretty if its last digit is $2$, $3$ or $9$. \nVasya wants to watch the numbers between $L$ and $R$ (both inclusive), so he asked you to determine how many pretty numbers are in this range. Can you help him?\n\n-----Input-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The first and only line of each test case contains two space-separated integers $L$ and $R$.\n\n-----Output-----\nFor each test case, print a single line containing one integer \u2014 the number of pretty numbers between $L$ and $R$.\n\n-----Constraints-----\n- $1 \\le T \\le 100$\n- $1 \\le L \\le R \\le 10^5$\n\n-----Subtasks-----\nSubtask #1 (100 points): original constraints\n\n-----Example Input-----\n2\n1 10\n11 33\n\n-----Example Output-----\n3\n8\n\n-----Explanation-----\nExample case 1: The pretty numbers between $1$ and $10$ are $2$, $3$ and $9$.\nExample case 2: The pretty numbers between $11$ and $33$ are $12$, $13$, $19$, $22$, $23$, $29$, $32$ and $33$.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\nt=int(input())\nfor _ in range(t):\n n,m = map(int,input().split())\n count=0\n for i in range(n,m+1):\n p=str(i)\n if p[-1]=='2' or p[-1]=='3' or p[-1]=='9':\n count+=1\n print(count)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n1 10\\n11 33\\n', 'output': '3\\n8\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/NUM239'}","problem_id":"vfc_3878","program":"```python\n# cook your dish here\nt=int(input())\nfor _ in range(t):\n n,m = map(int,input().split())\n count=0\n for i in range(n,m+1):\n p=str(i)\n if p[-1]=='2' or p[-1]=='3' or p[-1]=='9':\n count+=1\n print(count)\n```","inputs":"2\n1 10\n11 33\n","output":"3\n8\n","actual_output":"3\n8\n","execution_success":true,"sample_index":854},{"source":"apps","task_type":"verifiable_code","in_source_id":"1260","prompt":"Solve the following coding problem using the programming language python:\n\nLavanya and Nikhil have K months of holidays ahead of them, and they want to go on exactly K road trips, one a month. They have a map of the various cities in the world with the roads that connect them. There are N cities, numbered from 1 to N. We say that you can reach city B from city A if there is a sequence of roads that starts from city A and ends at city B. Note that the roads are bidirectional. Hence, if you can reach city B from city A, you can also reach city A from city B. \nLavanya first decides which city to start from. In the first month, they will start from that city, and they will visit every city that they can reach by road from that particular city, even if it means that they have to pass through cities that they have already visited previously. Then, at the beginning of the second month, Nikhil picks a city that they haven't visited till then. In the second month, they first fly to that city and visit all the cities that they can reach from that city by road. Then, in the third month, Lavanya identifies a city, and they fly there and visit all cities reachable from there by road. Then in the fourth month it is Nikhil's turn to choose an unvisited city to start a road trip, and they alternate like this. Note that the city that they fly to (that is, the city from where they start each month's road trip) is also considered as being visited.\nEach city has some museums, and when they visit a city for the first time, Lavanya makes them visit each of the museums there. Lavanya loves going to museums, but Nikhil hates them. Lavanya always makes her decisions so that they visit the maximum number of museums possible that month, while Nikhil picks cities so that the number of museums visited that month is minimized.\nGiven a map of the roads, the number of museums in each city, and the number K, find the total number of museums that they will end up visiting at the end of K months. Print -1 if they will have visited all the cities before the beginning of the Kth month, and hence they will be left bored at home for some of the K months.\n\n-----Input-----\n- The first line contains a single integer, T, which is the number of testcases. The description of each testcase follows.\n- The first line of each testcase contains three integers: N, M and K, which represents the number of cities, number of roads and the number of months.\n- The ith of the next M lines contains two integers, ui and vi. This denotes that there is a direct road between city ui and city vi.\n- The next line contains N integers, the ith of which represents the number of museums in city i.\n\n-----Output-----\nFor each test case, if they can go on K road trips, output a single line containing a single integer which should be the total number of museums they visit in the K months. Output -1 if they can't go on K road trips.\n\n-----Constraints-----\n- 1 \u2264 T \u2264 3\n- 1 \u2264 N \u2264 106\n- 0 \u2264 M \u2264 106\n- 1 \u2264 K \u2264 106\n- 1 \u2264 ui, vi \u2264 N\n- There is no road which goes from one city to itself. ie. ui \u2260 vi.\n- There is at most one direct road between a pair of cities.\n- 0 \u2264 Number of museums in each city \u2264 1000\n- Sum of N over all testcases in a file will be \u2264 1.5 * 106\n\n-----Subtasks-----\n- Subtask 1 (11 points): M = 0\n- Subtask 2 (21 points): Each city has at most two roads of which it is an end point. That is, for every i, there are at most two roads (u, v) in the input, such that u = i or v = i.\n- Subtask 3 (68 points): Original constraints.\n\n-----Example-----\nInput:\n3\n10 10 3\n1 3\n3 5\n5 1\n1 6\n6 2\n5 6\n2 5\n7 10\n4 7\n10 9\n20 0 15 20 25 30 30 150 35 20\n10 10 2\n1 3\n3 5\n5 1\n1 6\n6 2\n5 6\n2 5\n7 10\n4 7\n10 9\n20 0 15 20 25 30 30 150 35 20\n10 10 5\n1 3\n3 5\n5 1\n1 6\n6 2\n5 6\n2 5\n7 10\n4 7\n10 9\n20 0 15 20 25 30 30 150 35 20\n\nOutput:\n345\n240\n-1\n\n-----Explanation-----\nNotice that in all the three testcases, everything is the same, except for the value of K. The following figure represents the road map in these testcases. Each node denotes a city, with a label of the form \"n (m)\", where n is the city number, between 1 and N, and m is the number of museums in this city. For example, the node with label \"5 (25)\" represents city 5, which has 25 museums.\n\nTestcase 1: Lavanya will first choose to fly to city 8. In the first month, they visit only that city, but they visit 150 museums.\nThen in the second month, Nikhil could choose to fly to city 3, and they visit the cities 1, 2, 3, 5 and 6, and visit 20 + 0 + 15 + 25 + 30 = 90 museums that month. Note that Nikhil could have instead chosen to fly to city 1 or 2 or 5 or 6, and they would all result in the same scenario.\nThen, Lavanya could choose city 7, and in the third month they will visit the cities 7, 4, 10 and 9. Note that Lavanya could have chosen to fly to city 4 or 10 or 9, and they would all result in the same scenario.\nIn total, they have visited 345 museums in the three months (which is in fact all the museums), and that is the answer.\nTestcase 2: It is same as the previous testcase, but now they have only 2 months. So they visit only 150 + 90 = 240 museums in total.\nTestcase 3: It is same as the previous testcase, but now they have 5 months of holidays. But sadly, they finish visiting all the cities within the first three months itself, and hence the answer is -1.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\ndef merge(intervals,start,mid,end):\n al = mid-start+1\n bl = end-mid\n \n A = intervals[start:mid+1]\n B = intervals[mid+1:end+1]\n \n p=0;q=0;k=start;\n while(plen(li)):\n print(-1)\n else:\n sum = 0\n front = 0\n rear = len(li)-1\n for i in range(k):\n if(i%2==0):\n sum += li[rear]\n rear -= 1\n else:\n sum += li[front]\n front += 1\n print(sum)\n \n if(m == 0):\n specialfunction()\n continue\n \n for i in range(n):\n cities[i][0] = li[i]\n \n visited = [-1 for i in range(n)]\n count = 0\n museummonths = []\n def searchUnvisited():\n for i in range(n):\n if(visited[i] == -1):\n return i\n return -1\n \n def bfs(ind,count):\n museumcount = 0\n queue = []\n queue.append(ind)\n visited[ind] = 1\n museumcount += cities[ind][0]\n count += 1\n front = 0\n rear = 0\n while(front<=rear):\n noe = len(cities[ind][1])\n for i in range(noe):\n if(visited[cities[ind][1][i]] == -1):\n queue.append(cities[ind][1][i])\n rear += 1\n count += 1\n museumcount += cities[cities[ind][1][i]][0]\n visited[cities[ind][1][i]] = 1\n front += 1\n try:\n ind = queue[front]\n except:\n break\n museummonths.append(museumcount)\n return count\n \n while(countlen(museummonths)):\n print(-1)\n else:\n sum = 0\n front = 0\n rear = len(museummonths)-1\n for i in range(k):\n if(i%2==0):\n sum += museummonths[rear]\n rear -= 1\n else:\n sum += museummonths[front]\n front += 1\n print(sum)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\n10 10 3\\n1 3\\n3 5\\n5 1\\n1 6\\n6 2\\n5 6\\n2 5\\n7 10\\n4 7\\n10 9\\n20 0 15 20 25 30 30 150 35 20\\n10 10 2\\n1 3\\n3 5\\n5 1\\n1 6\\n6 2\\n5 6\\n2 5\\n7 10\\n4 7\\n10 9\\n20 0 15 20 25 30 30 150 35 20\\n10 10 5\\n1 3\\n3 5\\n5 1\\n1 6\\n6 2\\n5 6\\n2 5\\n7 10\\n4 7\\n10 9\\n20 0 15 20 25 30 30 150 35 20\\n', 'output': '345\\n240\\n-1\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/INOIPRAC/problems/ROADTRIP'}","problem_id":"vfc_3882","program":"```python\ndef merge(intervals,start,mid,end):\n al = mid-start+1\n bl = end-mid\n \n A = intervals[start:mid+1]\n B = intervals[mid+1:end+1]\n \n p=0;q=0;k=start;\n while(plen(li)):\n print(-1)\n else:\n sum = 0\n front = 0\n rear = len(li)-1\n for i in range(k):\n if(i%2==0):\n sum += li[rear]\n rear -= 1\n else:\n sum += li[front]\n front += 1\n print(sum)\n \n if(m == 0):\n specialfunction()\n continue\n \n for i in range(n):\n cities[i][0] = li[i]\n \n visited = [-1 for i in range(n)]\n count = 0\n museummonths = []\n def searchUnvisited():\n for i in range(n):\n if(visited[i] == -1):\n return i\n return -1\n \n def bfs(ind,count):\n museumcount = 0\n queue = []\n queue.append(ind)\n visited[ind] = 1\n museumcount += cities[ind][0]\n count += 1\n front = 0\n rear = 0\n while(front<=rear):\n noe = len(cities[ind][1])\n for i in range(noe):\n if(visited[cities[ind][1][i]] == -1):\n queue.append(cities[ind][1][i])\n rear += 1\n count += 1\n museumcount += cities[cities[ind][1][i]][0]\n visited[cities[ind][1][i]] = 1\n front += 1\n try:\n ind = queue[front]\n except:\n break\n museummonths.append(museumcount)\n return count\n \n while(countlen(museummonths)):\n print(-1)\n else:\n sum = 0\n front = 0\n rear = len(museummonths)-1\n for i in range(k):\n if(i%2==0):\n sum += museummonths[rear]\n rear -= 1\n else:\n sum += museummonths[front]\n front += 1\n print(sum)\n```","inputs":"3\n10 10 3\n1 3\n3 5\n5 1\n1 6\n6 2\n5 6\n2 5\n7 10\n4 7\n10 9\n20 0 15 20 25 30 30 150 35 20\n10 10 2\n1 3\n3 5\n5 1\n1 6\n6 2\n5 6\n2 5\n7 10\n4 7\n10 9\n20 0 15 20 25 30 30 150 35 20\n10 10 5\n1 3\n3 5\n5 1\n1 6\n6 2\n5 6\n2 5\n7 10\n4 7\n10 9\n20 0 15 20 25 30 30 150 35 20\n","output":"345\n240\n-1\n","actual_output":"345\n240\n-1\n","execution_success":true,"sample_index":855},{"source":"apps","task_type":"verifiable_code","in_source_id":"1261","prompt":"Solve the following coding problem using the programming language python:\n\nYou have been appointed as the designer for your school's computer network.\nIn total, there are N computers in the class, and M computer-to-computer connections need to be made. Also, there are three mandatory conditions the design should fulfill.\nThe first requirement is that any computer in the network should be able to communicate with any other computer through the connections, possibly, through some other computers.\nNetwork attacks are possible, so the second requirement is that even if any one computer from the network gets disabled so that the rest of the computers are unable to communicate with it, the rest of the computers can still communicate with each other. In other words, the first requirement still holds for any subset of (N-1) computers.\nThe third requirement is that there shouldn't be any irrelevant connections in the network. We will call a connection irrelevant if and only if after its' removal, the above two requirements are still held.\nGiven N, M, please build a network with N computers and M connections, or state that it is impossible.\n\n-----Input-----\nThe first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.\nThe first and only line of each test case contains a pair of space-separated integers N and M denoting the number of computers and the number of connections.\n\n-----Output-----\nOutput T blocks.\nIf it is impossible to construct a network with the given parameters for the corresponding test case, output just -1 -1. Otherwise, output M lines, each of which contains a space-separated pairs of integers denoting the IDs of the computers that should be connected. Note that multiple connections between any pair of computers and connections connecting a computer to itself are implicitly not allowed due to the third requirement.\n\n-----Constraints-----\n\n- 1 \u2264 T \u2264 1000\n- 1 \u2264 M \u2264 N * (N - 1) / 2\n- 1 \u2264 Sum of all N \u2264 1000\n- Subtask 1 (21 point): 1 \u2264 N \u2264 4\n- Subtask 2 (79 points): 1 \u2264 N \u2264 100\n\n-----Example-----\nInput:2\n10 1\n5 5\n\nOutput:-1 -1\n1 2\n2 3\n3 4\n4 5\n5 1\n\n-----Explanation-----\nExample case 1. There are not enough connections even to satisfy the first requirement.\nExample case 2. The obtained network satisfies all the requirements.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n\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(N, M):\n if M != N:\n return [(-1, -1)]\n r = [(i+1, ((i+1) % N)+1) for i in range(N)]\n return r\n\nT = int(f.readline().strip())\n\nfor case_id in range(1, T+1):\n N, M = list(map(int, f.readline().strip().split()))\n\n rr = calc(N, M)\n\n for a, b in rr:\n print(a, b)\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n10 1\\n5 5\\n', 'output': '-1 -1\\n1 2\\n2 3\\n3 4\\n4 5\\n5 1\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/LTIME31/problems/EXNETWRK'}","problem_id":"vfc_3886","program":"```python\n\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(N, M):\n if M != N:\n return [(-1, -1)]\n r = [(i+1, ((i+1) % N)+1) for i in range(N)]\n return r\n\nT = int(f.readline().strip())\n\nfor case_id in range(1, T+1):\n N, M = list(map(int, f.readline().strip().split()))\n\n rr = calc(N, M)\n\n for a, b in rr:\n print(a, b)\n\n```","inputs":"2\n10 1\n5 5\n","output":"-1 -1\n1 2\n2 3\n3 4\n4 5\n5 1\n","actual_output":"-1 -1\n1 2\n2 3\n3 4\n4 5\n5 1\n","execution_success":true,"sample_index":856},{"source":"apps","task_type":"verifiable_code","in_source_id":"1263","prompt":"Solve the following coding problem using the programming language python:\n\nThe chef was playing with numbers and he found that natural number N can be obtained by sum various unique natural numbers, For challenging himself chef wrote one problem statement, which he decided to solve in future.\nProblem statement: N can be obtained as the sum of Kth power of integers in multiple ways, find total number ways?\nAfter that Cheffina came and read what chef wrote in the problem statement, for having some fun Cheffina made some changes in the problem statement as.\nNew problem statement: N can be obtained as the sum of Kth power of unique +ve integers in multiple ways, find total number ways?\nBut, the chef is now confused, how to solve a new problem statement, help the chef to solve this new problem statement.\n\n-----Input:-----\n- First-line will contain $T$, the number of test cases. Then the test cases follow. \n- Each test case contains a single line of input, two integers $N, K$. \n\n-----Output:-----\nFor each test case, output in a single line answer to the problem statement.\n\n-----Constraints-----\n- $1 \\leq T \\leq 10$\n- $1 \\leq N \\leq 1000$\n- $1 \\leq K \\leq 6$\n\n-----Sample Input:-----\n2\n4 1\n38 2\n\n-----Sample Output:-----\n2\n1\n\n-----EXPLANATION:-----\nFor 1) 4 can be obtained by as [ 4^1 ], [1^1, 3^1], [2^1, 2^1]. (here ^ stands for power)\nBut here [2^1, 2^1] is not the valid way because it is not made up of unique +ve integers. \nFor 2) 38 can be obtained in the way which is [2^2, 3^2, 5^2] = 4 + 9 + 25\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfor _ in range(int(input())):\n x,n = map(int,input().split())\n reach = [0]*(x+1)\n reach[0] = 1\n i=1\n while i**n<=x:\n j = 1\n while j+i**n<=x:\n j+=1\n j-=1\n while j>=0:\n if reach[j]>0:\n reach[j+i**n]+=reach[j]\n j-=1\n i+=1\n #print(reach)\n print(reach[-1])\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n4 1\\n38 2\\n', 'output': '2\\n1\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/PBK22020/problems/ITGUY24'}","problem_id":"vfc_3894","program":"```python\nfor _ in range(int(input())):\n x,n = map(int,input().split())\n reach = [0]*(x+1)\n reach[0] = 1\n i=1\n while i**n<=x:\n j = 1\n while j+i**n<=x:\n j+=1\n j-=1\n while j>=0:\n if reach[j]>0:\n reach[j+i**n]+=reach[j]\n j-=1\n i+=1\n #print(reach)\n print(reach[-1])\n```","inputs":"2\n4 1\n38 2\n","output":"2\n1\n","actual_output":"2\n1\n","execution_success":true,"sample_index":858},{"source":"apps","task_type":"verifiable_code","in_source_id":"1264","prompt":"Solve the following coding problem using the programming language python:\n\nMohit's girlfriend is playing a game with Nicky. The description of the game is as follows:\n- Initially on a table Player 1 will put N gem-stones.\n- Players will play alternatively, turn by turn.\n- At each move a player can take at most M gem-stones (at least 1 gem-stone must be taken) from the available gem-stones on the table.(Each gem-stone has same cost.)\n- Each players gem-stone are gathered in player's side.\n- The player that empties the table purchases food from it (using all his gem-stones; one gem-stone can buy one unit of food), and the other one puts all his gem-stones back on to the table. Again the game continues with the \"loser\" player starting.\n- The game continues until all the gem-stones are used to buy food.\n- The main objective of the game is to consume maximum units of food.\n\n\tMohit's girlfriend is weak in mathematics and prediction so she asks help from Mohit, in return she shall kiss Mohit. Mohit task is to predict the maximum units of food her girlfriend can eat, if, she starts first. Being the best friend of Mohit, help him in predicting the answer.\n\n-----Input-----\n- Single line contains two space separated integers N and M.\n\n-----Output-----\n- The maximum units of food Mohit's girlfriend can eat.\n\n-----Constraints and Subtasks-----\n- 1 <= M <= N <= 100\nSubtask 1: 10 points\n- 1 <= M <= N <= 5\nSubtask 2: 20 points\n- 1 <= M <= N <= 10\nSubtask 3: 30 points\n- 1 <= M <= N <= 50\nSubtask 3: 40 points\n- Original Constraints.\n\n-----Example-----\nInput:\n4 2\n\nOutput:\n2\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nr=[0,1,1,2,1,4,2,6,1,8,4]\n\nn,m=[int(x) for x in input().split()]\nif m==1:\n while n%2!=1:\n n=n/2\n if n==1:\n print(1)\n else: \n print(n-1) \nelif (n+1)/2(2,2). This coin cannot be moved any further. And so, the Chef wins.\nNotice that if the Chef moves it to any other valid position, i.e. either to (1,2) or (2,1) he will lose!\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nres=\"\"\nfor _ in range(int(input())):\n ans=0\n c=int(input())\n for i in range(c):\n n,m=list(map(int,input().split( )))\n ans^=(n+m-2)%3\n if ans:\n res+=\"MasterChef\\n\"\n else:\n res+=\"Football\\n\"\nprint(res)\n \n \n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n1\\n2 2\\n', 'output': 'MasterChef\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/CHEFBRO'}","problem_id":"vfc_3906","program":"```python\nres=\"\"\nfor _ in range(int(input())):\n ans=0\n c=int(input())\n for i in range(c):\n n,m=list(map(int,input().split( )))\n ans^=(n+m-2)%3\n if ans:\n res+=\"MasterChef\\n\"\n else:\n res+=\"Football\\n\"\nprint(res)\n \n \n\n```","inputs":"1\n1\n2 2\n","output":"MasterChef\n","actual_output":"MasterChef\n\n","execution_success":true,"sample_index":861},{"source":"apps","task_type":"verifiable_code","in_source_id":"1267","prompt":"Solve the following coding problem using the programming language python:\n\nChef likes problems related to learning new languages. He only knows first N letters of English alphabet. Also he explores all M-letter words formed by the characters he knows. Define cost for a given M-letter word S, cost(S) = P1, S1+P2, S2+...+PM, SM, where Pi, j is i, jth entry of matrix P. Sort all the words by descending cost, if costs are equal, sort them lexicographically. You need to find K-th M-letter word in Chef's order.\n\n-----Input-----\nFirst line contains three positive integer numbers N, M and K.\nNext M lines contains N integers per line, denoting the matrix P.\n\n-----Output-----\nOutput in a single line K-th M-letter in Chef's order.\n\n-----Constraints-----\n- 1 \u2264 N \u2264 16 \n- 1 \u2264 M \u2264 10 \n- 1 \u2264 K \u2264 NM\n- 0 \u2264 Pi, j \u2264 109\n\n-----Subtasks-----\n- Subtask #1: (20 points) 1 \u2264 K \u2264 10000\n- Subtask #2: (20 points) 1 \u2264 M \u2264 5\n- Subtask #3: (60 points) Original constraints\n\n-----Example-----\nInput:2 5 17\n7 9\n13 18\n10 12\n4 18\n3 9\n\nOutput:aaaba\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\ndef dfs(ind,m,n,k):\n if(ind == m):\n return [\"\"]\n else:\n temp = dfs(ind+1,m,n,k)\n ans = []\n if(len(temp)= k and T2 >= k:\n return i\n\n if i >= len(arr):\n return float('inf')\n\n if (T1, T2) in memo:\n return memo[(T1, T2)]\n\n t1 = recurse(arr, T1 + arr[i], T2, k, i+1)\n t2 = recurse(arr, T1, T2 + arr[i], k, i+1) \n\n memo[(T1, T2)] = min(t1, t2)\n return memo[(T1, T2)]\n\nfor _ in range(int(input())):\n n, k = list(map(int, input().split()))\n lst = list(map(int, input().split()))\n\n lst.sort(reverse = True)\n memo = {}\n res = recurse(lst, 0, 0, k, 0)\n\n if res == float('inf'):\n print(-1)\n else:\n print(res)\n\n\n\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n8 38\\n7 8 19 7 8 7 10 20\\n4 5\\n2 10 4 9\\n', 'output': '7\\n2\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/WIPL'}","problem_id":"vfc_3922","program":"```python\nimport sys\nsys.setrecursionlimit(100000)\n\nmemo = {}\ndef recurse(arr, T1, T2, k, i):\n if T1 >= k and T2 >= k:\n return i\n\n if i >= len(arr):\n return float('inf')\n\n if (T1, T2) in memo:\n return memo[(T1, T2)]\n\n t1 = recurse(arr, T1 + arr[i], T2, k, i+1)\n t2 = recurse(arr, T1, T2 + arr[i], k, i+1) \n\n memo[(T1, T2)] = min(t1, t2)\n return memo[(T1, T2)]\n\nfor _ in range(int(input())):\n n, k = list(map(int, input().split()))\n lst = list(map(int, input().split()))\n\n lst.sort(reverse = True)\n memo = {}\n res = recurse(lst, 0, 0, k, 0)\n\n if res == float('inf'):\n print(-1)\n else:\n print(res)\n\n\n\n\n```","inputs":"2\n8 38\n7 8 19 7 8 7 10 20\n4 5\n2 10 4 9\n","output":"7\n2\n","actual_output":"7\n2\n","execution_success":true,"sample_index":865},{"source":"apps","task_type":"verifiable_code","in_source_id":"1271","prompt":"Solve the following coding problem using the programming language python:\n\nYou are given a set $S$ and $Q$ queries. Initially, $S$ is empty. In each query:\n- You are given a positive integer $X$.\n- You should insert $X$ into $S$.\n- For each $y \\in S$ before this query such that $y \\neq X$, you should also insert $y \\oplus X$ into $S$ ($\\oplus$ denotes the XOR operation).\n- Then, you should find two values $E$ and $O$: the number of elements of $S$ with an even number of $1$-s and with an odd number of $1$-s in the binary representation, respectively.\nNote that a set cannot have duplicate elements, so if you try to insert into $S$ an element that is already present in $S$, then nothing happens.\n\n-----Input-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The first line of each test case contains a single integer $Q$.\n- Each of the next $Q$ lines contains a single integer $X$ describing a query.\n\n-----Output-----\nFor each query, print a single line containing two space-separated integers $E$ and $O$.\n\n-----Constraints-----\n- $1 \\le T \\le 5$\n- $1 \\le Q, X \\le 10^5$\n\n-----Subtasks-----\nSubtask #1 (30 points):\n- $1 \\le Q \\le 1,000$\n- $1 \\le X \\le 128$\nSubtask #2 (70 points): original constraints\n\n-----Example Input-----\n1\n3\n4\n2\n7\n\n-----Example Output-----\n0 1\n1 2\n3 4\n\n-----Explanation-----\nExample case 1:\n- Initially, the set is empty: $S = \\{\\}$.\n- After the first query, $S = \\{4\\}$, so there is only one element with an odd number of $1$-s in the binary representation (\"100\").\n- After the second query, $S = \\{4,2,6\\}$, there is one element with an even number of $1$-s in the binary representation ($6$ is \"110\") and the other two elements have an odd number of $1$-s.\n- After the third query, $S = \\{4,2,6,7,3,5,1\\}$.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# fast io\nimport sys\ndef fop(s): sys.stdout.write(str(s)+'\\n')\ndef fip(): return sys.stdin.readline()\nfintinp = lambda : int(fip()) \ndef flistinp(func= int): return list(map(func,fip().split())) \ndef fnsepline(n,func=str): return [func(fip()) for _ in range(n)]\n#-------------------code------------------------\ndef even(x):\n x = bin(x).count('1')\n return x%2==0\n \nfor _ in range(fintinp()):\n q =fintinp()\n o = e =0 \n nums = set()\n for qn in range(q):\n qn = fintinp()\n if qn not in nums:\n if even(qn): e+=1 \n else: o+=1 \n \n for n in set(nums):\n x = n^qn\n if x not in nums:\n if even(x): e+=1 \n else: o+=1 \n \n nums.add(x)\n \n nums.add(qn)\n print(e,o)\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n3\\n4\\n2\\n7\\n', 'output': '0 1\\n1 2\\n3 4\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/PRTAGN'}","problem_id":"vfc_3926","program":"```python\n# fast io\nimport sys\ndef fop(s): sys.stdout.write(str(s)+'\\n')\ndef fip(): return sys.stdin.readline()\nfintinp = lambda : int(fip()) \ndef flistinp(func= int): return list(map(func,fip().split())) \ndef fnsepline(n,func=str): return [func(fip()) for _ in range(n)]\n#-------------------code------------------------\ndef even(x):\n x = bin(x).count('1')\n return x%2==0\n \nfor _ in range(fintinp()):\n q =fintinp()\n o = e =0 \n nums = set()\n for qn in range(q):\n qn = fintinp()\n if qn not in nums:\n if even(qn): e+=1 \n else: o+=1 \n \n for n in set(nums):\n x = n^qn\n if x not in nums:\n if even(x): e+=1 \n else: o+=1 \n \n nums.add(x)\n \n nums.add(qn)\n print(e,o)\n\n```","inputs":"1\n3\n4\n2\n7\n","output":"0 1\n1 2\n3 4\n","actual_output":"0 1\n1 2\n3 4\n","execution_success":true,"sample_index":866},{"source":"apps","task_type":"verifiable_code","in_source_id":"1273","prompt":"Solve the following coding problem using the programming language python:\n\nThere is a haunted town called HauntedLand. The structure of HauntedLand can be thought of as a grid of size n * m. There is a house in each cell of the grid. Some people have fled from their houses because they were haunted. '.' represents a haunted house whereas '*' represents a house in which people are living.\n\nOne day, Devu, the famous perfumer came to town with a perfume whose smell can hypnotize people. Devu can put the perfume in at most one of the houses. This takes Devu one second. Then, the perfume spreads from one house (need not be inhabited by people) to all its adjacent houses in one second, and the cycle continues. Two houses are said to be a adjacent to each other, if they share a corner or an edge, i.e., each house (except those on the boundaries) will have 8 adjacent houses.\n\nYou want to save people from Devu's dark perfumery by sending them a message to flee from the town. So, you need to estimate the minimum amount of time Devu needs to hypnotize all the people? Note that if there are no houses inhabited by people, Devu doesn't need to put perfume in any cell.\n\n-----Input-----\nThe first line of input contains an integer T denoting the number of test cases. The description of T test cases follows.\nFirst line of each test case contains two space separated integers n, m denoting the dimensions of the town.\nFor each of next n lines, each line has m characters (without any space) denoting a row of houses of the town.\n\n-----Output-----\nFor each test case, output a single integer corresponding to the answer of the problem.\n\n-----Constraints-----\n- 1 \u2264 T \u2264 20\nSubtask #1: (40 points) \n\n- 1 \u2264 n, m \u2264 100Subtask #2: (60 points) \n\n- 1 \u2264 n, m \u2264 1000\n\n-----Example-----\nInput:\n2\n2 2\n*...\n3 4\n.*..***..*..\n\nOutput:\n1\n2\n\n-----Explanation-----\nIn the first example, it will take Devu one second for putting the perfume at the only house. So, the answer is 1.\n\nIn the second example, He will first put the perfume at the * at cell (1, 1) (assuming 0-based indexing).\n\nNow, it will take Devu 1 secs to put perfume. In the next second, the perfume will spread to all of its adjacent cells, thus making each house haunted.\nSo, the answer is 2.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nimport math\n\n\nt = int(input().strip())\n\nfor _ in range(t):\n n, m = list(map(int, input().strip().split()))\n a = []\n v = [-1] * 4\n\n for i in range(n):\n a.append(input().strip())\n\n for i, ai in enumerate(a):\n if ai.find('*') > -1:\n v[2] = i\n break\n\n if v[2] == -1:\n print(0)\n else:\n\n for i, ai in reversed(list(enumerate(a))):\n if ai.find('*') > -1:\n v[3] = i\n break\n\n for i in range(m):\n x = [ai[i] for ai in a]\n if '*' in x:\n v[0] = i\n break\n\n for i in reversed(range(m)):\n x = [ai[i] for ai in a]\n if '*' in x:\n v[1] = i\n break\n\n if v.count(v[0]) == len(v):\n print(1)\n else:\n print(int(math.ceil(max(v[3] - v[2], v[1] - v[0]) / 2.0)) + 1)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n2 2\\n*.\\n..\\n3 4\\n.*..\\n***.\\n.*..\\n', 'output': '1\\n2\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/JAN16/problems/DEVPERF'}","problem_id":"vfc_3934","program":"```python\nimport math\n\n\nt = int(input().strip())\n\nfor _ in range(t):\n n, m = list(map(int, input().strip().split()))\n a = []\n v = [-1] * 4\n\n for i in range(n):\n a.append(input().strip())\n\n for i, ai in enumerate(a):\n if ai.find('*') > -1:\n v[2] = i\n break\n\n if v[2] == -1:\n print(0)\n else:\n\n for i, ai in reversed(list(enumerate(a))):\n if ai.find('*') > -1:\n v[3] = i\n break\n\n for i in range(m):\n x = [ai[i] for ai in a]\n if '*' in x:\n v[0] = i\n break\n\n for i in reversed(range(m)):\n x = [ai[i] for ai in a]\n if '*' in x:\n v[1] = i\n break\n\n if v.count(v[0]) == len(v):\n print(1)\n else:\n print(int(math.ceil(max(v[3] - v[2], v[1] - v[0]) / 2.0)) + 1)\n```","inputs":"2\n2 2\n*.\n..\n3 4\n.*..\n***.\n.*..\n","output":"1\n2\n","actual_output":"1\n2\n","execution_success":true,"sample_index":868},{"source":"apps","task_type":"verifiable_code","in_source_id":"1274","prompt":"Solve the following coding problem using the programming language python:\n\nThe 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.\n\n-----Input:-----\n- First-line will contain $T$, the number of test cases. Then the test cases follow. \n- Each test case contains a single line of input, one integer $K$. \n\n-----Output:-----\nFor each test case, output as the pattern.\n\n-----Constraints-----\n- $1 \\leq T \\leq 100$\n- $1 \\leq K \\leq 100$\n\n-----Sample Input:-----\n3\n2\n3\n4\n\n-----Sample Output:-----\n1121\n1222\n112131\n122232\n132333\n11213141\n12223242\n13233343\n14243444\n\n-----EXPLANATION:-----\nNo need, else pattern can be decode easily.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfor _ in range(int(input().strip())):\n n = int(input().strip())\n lst = []\n for i in range(n):\n lst.append(i+1)\n lst.append(1)\n #print(lst)\n for i in range(n):\n print(''.join(str(e) for e in lst))\n for x in range(n):\n lst[x * 2 + 1] += 1\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\n2\\n3\\n4\\n', 'output': '1121\\n1222\\n112131\\n122232\\n132333\\n11213141\\n12223242\\n13233343\\n14243444\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/PTRN2020/problems/ITGUY35'}","problem_id":"vfc_3938","program":"```python\nfor _ in range(int(input().strip())):\n n = int(input().strip())\n lst = []\n for i in range(n):\n lst.append(i+1)\n lst.append(1)\n #print(lst)\n for i in range(n):\n print(''.join(str(e) for e in lst))\n for x in range(n):\n lst[x * 2 + 1] += 1\n\n```","inputs":"3\n2\n3\n4\n","output":"1121\n1222\n112131\n122232\n132333\n11213141\n12223242\n13233343\n14243444\n","actual_output":"1121\n1222\n112131\n122232\n132333\n11213141\n12223242\n13233343\n14243444\n","execution_success":true,"sample_index":869},{"source":"apps","task_type":"verifiable_code","in_source_id":"1278","prompt":"Solve the following coding problem using the programming language python:\n\nA plot of land can be described by $M x N$ dots such that horizontal and vertical distance between any two dots is 10m.\nMr. Wolf would like to build a house in the land such that all four sides of the house are equal. Help Mr. Wolf to find the total number of unique positions where houses can be built. Two positions are different if and only if their sets of four dots are different.\n\n-----Input:-----\nThe first line of the input gives the number of test cases, $T$. $T$ lines follow. Each line has two integers $M$ and $N$: the number of dots in each row and column of the plot, respectively.\n\n-----Output:-----\nFor each test case, output one single integer containing the total number of different positions where the house can be built.\n\n-----Constraints-----\n- $1 \\leq T \\leq 100$\n- $2 \\leq M \\leq 10^9$\n- $2 \\leq N \\leq 10^9$\n\n-----Sample Input:-----\n4\n\n2 4\n\n3 4\n\n4 4\n\n1000 500 \n\n-----Sample Output:-----\n3\n\n10\n\n20\n\n624937395 \n\n-----EXPLANATION:-----\nMap 1\n\nMap 2\n\nMap 3\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\nfrom sys import stdin,stdout,setrecursionlimit\nfrom math import ceil\n\nmod = 1000000007\nt = int(stdin.readline())\nfor _ in range(t):\n m,n = list(map(int,input().split()))\n if m < n:\n m,n = n,m\n\n y = n-1\n s1 = ((y*(y+1)) //2)%mod\n s2 = ((y*(y+1)*(2*y+1)) //6)%mod\n s3 = ((y*y*(y+1)*(y+1)) //4)%mod\n \n \n ans = (m*n*s1 - (m+n)*s2+s3)%mod\n # ans = (m*(m+1)*(2*m*n + 4*n + 2 - m*m - m)//12)\n \n print(ans)\n \n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '4\\n2 4\\n3 4\\n4 4\\n1000 500\\n', 'output': '3\\n10\\n20\\n624937395\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/COX22020/problems/DCODEX2'}","problem_id":"vfc_3954","program":"```python\n# cook your dish here\nfrom sys import stdin,stdout,setrecursionlimit\nfrom math import ceil\n\nmod = 1000000007\nt = int(stdin.readline())\nfor _ in range(t):\n m,n = list(map(int,input().split()))\n if m < n:\n m,n = n,m\n\n y = n-1\n s1 = ((y*(y+1)) //2)%mod\n s2 = ((y*(y+1)*(2*y+1)) //6)%mod\n s3 = ((y*y*(y+1)*(y+1)) //4)%mod\n \n \n ans = (m*n*s1 - (m+n)*s2+s3)%mod\n # ans = (m*(m+1)*(2*m*n + 4*n + 2 - m*m - m)//12)\n \n print(ans)\n \n\n```","inputs":"4\n2 4\n3 4\n4 4\n1000 500\n","output":"3\n10\n20\n624937395\n","actual_output":"3\n10\n20\n624937395\n","execution_success":true,"sample_index":873},{"source":"apps","task_type":"verifiable_code","in_source_id":"1279","prompt":"Solve the following coding problem using the programming language python:\n\nChef hates unoptimized codes and people who write such codes. One fine day he decided to look through the kitchen's codebase and found a function whose pseudo-code is given here:\n\ninput: integer N, list X[1, 2, ..., N], list Y[1, 2, ..., N]\n\noutput: integer res\n\nfunction:\n\nset res = 0;\nfor i := 1 to N do\nfor j := 1 to N do\nfor k := 1 to N do\nif (X[i] = X[j]) OR (X[j] = X[k]) OR (X[k] = X[i])\ncontinue\nelse\nset res = max(res, Y[i] + Y[j] + Y[k])\nreturn res\n\nLuckily enough this code gets triggered only if the Head Chef makes a submission. But still there is a possibility that this can crash the judge. So help Chef by writing a new function which does the same thing but is faster.\n\n-----Input-----\n- The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.\n- The first line of each test case contains an integer N denoting the number of elements in the two lists.\n- The i-th of the next N lines contains a pair of space-separated integers denoting the values of X[i] and Y[i] respectively.\n\n-----Output-----\nFor each test case, output an integer corresponding to the return value of the function.\n\n-----Constraints-----\n- 1 \u2264 T \u2264 10\n- 1 \u2264 N \u2264 105\n- 1 \u2264 X[i], Y[i] \u2264 108\n\n-----Example-----\nInput\n2\n3\n1 3\n3 1\n1 2\n5\n1 3\n2 4\n1 2\n3 2\n3 4\n\nOutput\n0\n11\n\n-----Explanation-----\nTestcase 2: The maximum is attained when i = 1, j = 2 and k = 5. This leads to res being 3 + 4 + 4 = 11. This value is attained in other iterations as well, but it never exceeds this, and hence this is the answer.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\nfor _ in range(int(input())):\n d=dict()\n ls=[]\n for i in range(int(input())):\n ls=list(map(int,input().split()))\n if ls[0] in d:\n d[ls[0]]=max(ls[1],d[ls[0]])\n else:\n d[ls[0]]=ls[1]\n # print(d)\n if len(d)<3:\n print(0)\n else:\n kd=list(d.values())\n kd.sort()\n # print(kd)\n print(kd[-1]+kd[-2]+kd[-3])\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n3\\n1 3\\n3 1\\n1 2\\n5\\n1 3\\n2 4\\n1 2\\n3 2\\n3 4\\n', 'output': '0\\n11\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/OPTCODE'}","problem_id":"vfc_3958","program":"```python\n# cook your dish here\nfor _ in range(int(input())):\n d=dict()\n ls=[]\n for i in range(int(input())):\n ls=list(map(int,input().split()))\n if ls[0] in d:\n d[ls[0]]=max(ls[1],d[ls[0]])\n else:\n d[ls[0]]=ls[1]\n # print(d)\n if len(d)<3:\n print(0)\n else:\n kd=list(d.values())\n kd.sort()\n # print(kd)\n print(kd[-1]+kd[-2]+kd[-3])\n\n```","inputs":"2\n3\n1 3\n3 1\n1 2\n5\n1 3\n2 4\n1 2\n3 2\n3 4\n","output":"0\n11\n","actual_output":"0\n11\n","execution_success":true,"sample_index":874},{"source":"apps","task_type":"verifiable_code","in_source_id":"1280","prompt":"Solve the following coding problem using the programming language python:\n\nEmily and Mia are friends. Emily got Mia\u2019s essay paper, but since she is a prankster, she decided to meddle with the words present in the paper. She changes all the words in the paper into palindromes. To do this, she follows two rules: \n- In one operation she can only reduce the value of an alphabet by 1, i.e. she can change \u2018d\u2019 to \u2018c\u2019, but she cannot change \u2018c\u2019 to \u2018d\u2019 or \u2018d\u2019 to \u2018b\u2019. \n- The alphabet \u2018a\u2019 will not be reduced any further. \nEach reduction in the value of any alphabet is counted as a single operation. Find the minimum number of operations required to convert a given string into a palindrome.\n\n-----Input:-----\n- The first line contains an integer $T$, denoting the number of test cases. \n- Each test case consists of a string $S$ containing only lowercase characters with no spaces.\n\n-----Output:-----\nFor each test case on a new line, print the minimum number of operations for the corresponding test case.\n\n-----Constraints-----\n- $1<=T<=10$\n- $1<=|S|<=10^7$, where $|S|$ denotes length of string S.\n\n-----Sample Input:-----\n4 \nabc \nabcba \nabcd \ncba\n\n-----Sample Output:-----\n2 \n0\n4\n2\n\n-----EXPLANATION:-----\nFor the first test case string = \u201cabc\u201d \nc->b->a so the string become \u201caba\u201d which is a palindrome. For this we perform 2 operations\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nt=int(input())\r\nfor _ in range(t):\r\n xyz = input().strip()\r\n \r\n string = 0\r\n\r\n for i in range(len(xyz)//2):\r\n string = string + (abs(ord(xyz[i])-ord(xyz[len(xyz)-i-1])))\r\n \r\n print(string)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '4\\nabc\\nabcba\\nabcd\\ncba\\n', 'output': '2\\n0\\n4\\n2\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/RTCG2020/problems/RTCG004'}","problem_id":"vfc_3962","program":"```python\nt=int(input())\r\nfor _ in range(t):\r\n xyz = input().strip()\r\n \r\n string = 0\r\n\r\n for i in range(len(xyz)//2):\r\n string = string + (abs(ord(xyz[i])-ord(xyz[len(xyz)-i-1])))\r\n \r\n print(string)\n```","inputs":"4\nabc\nabcba\nabcd\ncba\n","output":"2\n0\n4\n2\n","actual_output":"2\n0\n4\n2\n","execution_success":true,"sample_index":875},{"source":"apps","task_type":"verifiable_code","in_source_id":"1281","prompt":"Solve the following coding problem using the programming language python:\n\nChef likes all arrays equally. But he likes some arrays more equally than others. In particular, he loves Rainbow Arrays. \nAn array is Rainbow if it has the following structure:\n- First a1 elements equal 1. \n- Next a2 elements equal 2. \n- Next a3 elements equal 3. \n- Next a4 elements equal 4. \n- Next a5 elements equal 5. \n- Next a6 elements equal 6. \n- Next a7 elements equal 7. \n- Next a6 elements equal 6. \n- Next a5 elements equal 5. \n- Next a4 elements equal 4. \n- Next a3 elements equal 3. \n- Next a2 elements equal 2. \n- Next a1 elements equal 1. \n- ai can be any non-zero positive integer.\n- There are no other elements in array. \n\nHelp Chef in finding out if the given array is a Rainbow Array or not. \n\n-----Input-----\n- The first line of the input contains an integer T denoting the number of test cases.\n- The first line of each test case contains an integer N, denoting the number of elements in the given array. \n- The second line contains N space-separated integers A1, A2, ..., AN denoting the elements of array. \n\n-----Output-----\n- For each test case, output a line containing \"yes\" or \"no\" (without quotes) corresponding to the case if the array is rainbow array or not. \n\n-----Constraints-----\n- 1 \u2264 T \u2264 100\n- 7 \u2264 N \u2264 100\n- 1 \u2264 Ai \u2264 10\n\n-----Subtasks-----\n- Subtask 1 (100 points) : Original constraints\n\n-----Example-----\nInput\n3\n19\n1 2 3 4 4 5 6 6 6 7 6 6 6 5 4 4 3 2 1\n14\n1 2 3 4 5 6 7 6 5 4 3 2 1 1\n13\n1 2 3 4 5 6 8 6 5 4 3 2 1\n\nOutput\nyes\nno\nno\n\n-----Explanation-----\nThe first example satisfies all the conditions. \nThe second example has 1 element of value 1 at the beginning and 2 elements of value 1 at the end. \nThe third one has no elements with value 7 after elements with value 6.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nt=int(input())\nx=[1,2,3,4,5,6,7]\nfor i in range(t):\n N=int(input())\n a=list(map(int,input().split())) \n rev=a[::-1] \n dup=set(a) \n if rev== a and list(dup) ==x: \n print(\"yes\")\n else:\n print(\"no\")\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\n19\\n1 2 3 4 4 5 6 6 6 7 6 6 6 5 4 4 3 2 1\\n14\\n1 2 3 4 5 6 7 6 5 4 3 2 1 1\\n13\\n1 2 3 4 5 6 8 6 5 4 3 2 1\\n', 'output': 'yes\\nno\\nno\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/RAINBOWA'}","problem_id":"vfc_3966","program":"```python\nt=int(input())\nx=[1,2,3,4,5,6,7]\nfor i in range(t):\n N=int(input())\n a=list(map(int,input().split())) \n rev=a[::-1] \n dup=set(a) \n if rev== a and list(dup) ==x: \n print(\"yes\")\n else:\n print(\"no\")\n```","inputs":"3\n19\n1 2 3 4 4 5 6 6 6 7 6 6 6 5 4 4 3 2 1\n14\n1 2 3 4 5 6 7 6 5 4 3 2 1 1\n13\n1 2 3 4 5 6 8 6 5 4 3 2 1\n","output":"yes\nno\nno\n","actual_output":"yes\nno\nno\n","execution_success":true,"sample_index":876},{"source":"apps","task_type":"verifiable_code","in_source_id":"1282","prompt":"Solve the following coding problem using the programming language python:\n\nYou are given positive integers $L$ and $R$. You have to find the sum\nS=\u2211i=LR(L\u2227(L+1)\u2227\u2026\u2227i),S=\u2211i=LR(L\u2227(L+1)\u2227\u2026\u2227i),S = \\sum_{i=L}^R \\left(L \\wedge (L+1) \\wedge \\ldots \\wedge i\\right) \\,,\nwhere $\\wedge$ denotes the bitwise AND operation. Since the sum could be large, compute it modulo $10^9+7$.\n\n-----Input-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The first and only line of each test case contains two space-separated integers $L$ and $R$.\n\n-----Output-----\nFor each test case, print a single line containing one integer \u2014 the sum $S$ modulo $10^9+7$.\n\n-----Constraints-----\n- $1 \\le T \\le 10^5$\n- $1 \\le L \\le R \\le 10^{18}$\n\n-----Example Input-----\n2\n1 4\n4 10\n\n-----Example Output-----\n1\n16\n\n-----Explanation-----\nExample case 1: The sum is 1 + 1 AND 2 + 1 AND 2 AND 3 + 1 AND 2 AND 3 AND 4 = 1 + 0 + 0 + 0 = 1.\nExample case 2: The sum is 4 + 4 AND 5 + 4 AND 5 AND 6 + 4 AND 5 AND 6 AND 7 + \u2026 + 4 AND 5 AND \u2026 AND 10 = 4 + 4 + \u2026 + 0 = 16.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nl= []\nfor i in range(62):\n l.append(2**i)\nT = int(input())\n\nflag = 0\nfor t in range(T):\n L,R = [int(i) for i in input().split()]\n bL = bin(L)\n lL = len(bL)-2\n index = 1\n ans = 0\n temp = 0\n \n while(index<=lL):\n temp = L%l[index]\n if temp>=l[index-1]:\n if(l[index]-temp<=R-L+1):\n ans= (ans +(l[index-1])*(l[index]-temp))%1000000007\n else :\n ans=(ans+(l[index-1])*(R-L+1))%1000000007\n \n \n index+=1\n print(ans)\n# 4378578345 584758454958\n# 18091037982636824985 8589934592 4429185025 4294967296\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n1 4\\n4 10\\n', 'output': '1\\n16\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/RGAND'}","problem_id":"vfc_3970","program":"```python\nl= []\nfor i in range(62):\n l.append(2**i)\nT = int(input())\n\nflag = 0\nfor t in range(T):\n L,R = [int(i) for i in input().split()]\n bL = bin(L)\n lL = len(bL)-2\n index = 1\n ans = 0\n temp = 0\n \n while(index<=lL):\n temp = L%l[index]\n if temp>=l[index-1]:\n if(l[index]-temp<=R-L+1):\n ans= (ans +(l[index-1])*(l[index]-temp))%1000000007\n else :\n ans=(ans+(l[index-1])*(R-L+1))%1000000007\n \n \n index+=1\n print(ans)\n# 4378578345 584758454958\n# 18091037982636824985 8589934592 4429185025 4294967296\n\n```","inputs":"2\n1 4\n4 10\n","output":"1\n16\n","actual_output":"1\n16\n","execution_success":true,"sample_index":877},{"source":"apps","task_type":"verifiable_code","in_source_id":"1283","prompt":"Solve the following coding problem using the programming language python:\n\nChef likes prime numbers. However, there is one thing he loves even more. Of course, it's semi-primes! A semi-prime number is an integer which can be expressed as a product of two distinct primes. For example, $15 = 3 \\cdot 5$ is a semi-prime number, but $1$, $9 = 3 \\cdot 3$ and $5$ are not.\nChef is wondering how to check if an integer can be expressed as a sum of two (not necessarily distinct) semi-primes. Help Chef with this tough task!\n\n-----Input-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The first and only line of each test case contains a single integer $N$.\n\n-----Output-----\nFor each test case, print a single line containing the string \"YES\" if it is possible to express $N$ as a sum of two semi-primes or \"NO\" otherwise.\n\n-----Constraints-----\n- $1 \\le T \\le 200$\n- $1 \\le N \\le 200$\n\n-----Example Input-----\n3\n30\n45\n62\n\n-----Example Output-----\nYES\nYES\nNO\n\n-----Explanation-----\nExample case 1: $N=30$ can be expressed as $15 + 15 = (3 \\cdot 5) + (3 \\cdot 5)$.\nExample case 2: $45$ can be expressed as $35 + 10 = (5 \\cdot 7) + (2 \\cdot 5)$.\nExample case 3: $62$ cannot be expressed as a sum of two semi-primes.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\r\nimport sys\r\nn = 201\r\nv = [0 for i in range(n + 1)] \r\n\r\ndef gen():\r\n for i in range(1, n + 1): \r\n v[i] = i \r\n \r\n countDivision = [0 for i in range(n + 1)] \r\n \r\n for i in range(n + 1): \r\n countDivision[i] = 2\r\n \r\n for i in range(2, n + 1, 1): \r\n \r\n \r\n if (v[i] == i and countDivision[i] == 2): \r\n for j in range(2 * i, n + 1, i): \r\n if (countDivision[j] > 0): \r\n v[j] = int(v[j] / i) \r\n countDivision[j] -= 1\r\ntry:\r\n t=int(sys.stdin.readline())\r\n for _ in range(t):\r\n gen()\r\n x=int(sys.stdin.readline())\r\n flag=0\r\n for i in range(2,x//2+1):\r\n if v[i]==1 and v[x-i]==1:\r\n flag=1\r\n #print(i,x-i)\r\n if flag==1:\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\nexcept:\r\n pass\r\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\n30\\n45\\n62\\n\\n', 'output': 'YES\\nYES\\nNO\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/CHEFPRMS'}","problem_id":"vfc_3974","program":"```python\n# cook your dish here\r\nimport sys\r\nn = 201\r\nv = [0 for i in range(n + 1)] \r\n\r\ndef gen():\r\n for i in range(1, n + 1): \r\n v[i] = i \r\n \r\n countDivision = [0 for i in range(n + 1)] \r\n \r\n for i in range(n + 1): \r\n countDivision[i] = 2\r\n \r\n for i in range(2, n + 1, 1): \r\n \r\n \r\n if (v[i] == i and countDivision[i] == 2): \r\n for j in range(2 * i, n + 1, i): \r\n if (countDivision[j] > 0): \r\n v[j] = int(v[j] / i) \r\n countDivision[j] -= 1\r\ntry:\r\n t=int(sys.stdin.readline())\r\n for _ in range(t):\r\n gen()\r\n x=int(sys.stdin.readline())\r\n flag=0\r\n for i in range(2,x//2+1):\r\n if v[i]==1 and v[x-i]==1:\r\n flag=1\r\n #print(i,x-i)\r\n if flag==1:\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\nexcept:\r\n pass\r\n\n```","inputs":"3\n30\n45\n62\n\n","output":"YES\nYES\nNO\n","actual_output":"YES\nYES\nNO\n","execution_success":true,"sample_index":878},{"source":"apps","task_type":"verifiable_code","in_source_id":"1284","prompt":"Solve the following coding problem using the programming language python:\n\nCoach Khaled is a swag teacher in HIT (Hag Institute of Technology). However, he has some obsession problems.\nRecently, coach Khaled was teaching a course in building 8G networks using TV antennas and programming them with assembly. There are $N$ students (numbered $1$ through $N$) in his class; for some reason, this number is always a multiple of $4$. The final exam has finished and Khaled has all the scores of his $N$ students. For each valid $i$, the score of the $i$-th student is $A_i$; each score is an integer between $0$ and $100$. Currently, the score-grade distribution is as follows:\n- grade D for score smaller than $60$\n- grade C for score greater or equal to $60$, but smaller than $75$\n- grade B for score greater or equal to $75$, but smaller than $90$\n- grade A for score greater or equal to $90$\nHowever, coach Khaled is not satisfied with this. He wants exactly $N/4$ students to receive each grade (A, B, C and D), so that the grades are perfectly balanced. The scores cannot be changed, but the boundaries between grades can. Therefore, he wants to choose three integers $x$, $y$ and $z$ and change the grade distribution to the following (note that initially, $x = 60$, $y = 75$ and $z = 90$):\n- grade D for score smaller than $x$\n- grade C for score greater or equal to $x$, but smaller than $y$\n- grade B for score greater or equal to $y$, but smaller than $z$\n- grade A for score greater or equal to $z$\nYour task is to find thresholds $x$, $y$ and $z$ that result in a perfect balance of grades. If there are multiple solutions, choose the one with the maximum value of $x+y+z$ (because coach Khaled wants seem smarter than his students); it can be proved that there is at most one such solution. Sometimes, there is no way to choose the thresholds and coach Khaled would resign because his exam questions were low-quality.\n\n-----Input-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The first line of each test case contains a single integer $N$.\n- The second line contains $N$ space-separated integers $A_1, A_2, \\ldots, A_N$.\n\n-----Output-----\nFor each test case, if there is no solution, print a single line containing the integer $-1$; otherwise, print a single line containing three space-separated integers $x$, $y$ and $z$.\n\n-----Constraints-----\n- $1 \\le T \\le 1,000$\n- $4 \\le N \\le 100$\n- $N$ is divisible by $4$\n- $0 \\le A_i \\le 100$ for each valid $i$\n- the sum of $N$ over all test cases does not exceed $5,000$\n\n-----Subtasks-----\nSubtask #1 (100 points): original constraints\n\n-----Example Input-----\n6\n4\n90 25 60 75\n8\n27 29 92 92 67 67 85 92\n4\n0 1 2 3\n4\n100 100 100 100\n4\n30 30 40 50\n4\n30 40 40 50\n\n-----Example Output-----\n60 75 90\n-1\n1 2 3\n-1\n-1\n-1\n\n-----Explanation-----\nExample case 1: The default distribution is the correct one.\nExample case 4: All students have the same score and grade, so there is no way to choose the thresholds and coach Khaled must resign.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\nfor _ in range(int(input())):\n n = int(input())\n k = n//4\n # a,b,c = map(int,input().split())\n a = sorted(map(int,input().split()))\n a60 = (a[k-1],a[k])\n a75 = (a[2*k-1],a[2*k])\n a90 = (a[3*k-1],a[3*k])\n if a60[0]==a60[1] or a75[0]==a75[1] or a90[0]==a90[1] :\n print(-1)\n else :\n print(a60[1],a75[1],a90[1])\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '6\\n4\\n90 25 60 75\\n8\\n27 29 92 92 67 67 85 92\\n4\\n0 1 2 3\\n4\\n100 100 100 100\\n4\\n30 30 40 50\\n4\\n30 40 40 50\\n', 'output': '60 75 90\\n-1\\n1 2 3\\n-1\\n-1\\n-1\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/HIT'}","problem_id":"vfc_3978","program":"```python\n# cook your dish here\nfor _ in range(int(input())):\n n = int(input())\n k = n//4\n # a,b,c = map(int,input().split())\n a = sorted(map(int,input().split()))\n a60 = (a[k-1],a[k])\n a75 = (a[2*k-1],a[2*k])\n a90 = (a[3*k-1],a[3*k])\n if a60[0]==a60[1] or a75[0]==a75[1] or a90[0]==a90[1] :\n print(-1)\n else :\n print(a60[1],a75[1],a90[1])\n\n```","inputs":"6\n4\n90 25 60 75\n8\n27 29 92 92 67 67 85 92\n4\n0 1 2 3\n4\n100 100 100 100\n4\n30 30 40 50\n4\n30 40 40 50\n","output":"60 75 90\n-1\n1 2 3\n-1\n-1\n-1\n","actual_output":"60 75 90\n-1\n1 2 3\n-1\n-1\n-1\n","execution_success":true,"sample_index":879},{"source":"apps","task_type":"verifiable_code","in_source_id":"1285","prompt":"Solve the following coding problem using the programming language python:\n\nChef is learning linear algebra. Recently, he learnt that for a square matrix $M$, $\\mathop{\\rm trace}(M)$ is defined as the sum of all elements on the main diagonal of $M$ (an element lies on the main diagonal if its row index and column index are equal).\nNow, Chef wants to solve some excercises related to this new quantity, so he wrote down a square matrix $A$ with size $N\\times N$. A square submatrix of $A$ with size $l\\times l$ is a contiguous block of $l\\times l$ elements of $A$. Formally, if $B$ is a submatrix of $A$ with size $l\\times l$, then there must be integers $r$ and $c$ ($1\\le r, c \\le N+1-l$) such that $B_{i,j} = A_{r+i-1, c+j-1}$ for each $1 \\le i, j \\le l$.\nHelp Chef find the maximum trace of a square submatrix of $A$.\n\n-----Input-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The first line of each test case contains a single integer $N$.\n- $N$ lines follow. For each $i$ ($1 \\le i \\le N$), the $i$-th of these lines contains $N$ space-separated integers $A_{i,1}, A_{i,2}, \\dots, A_{i, N}$ denoting the $i$-th row of the matrix $A$.\n\n-----Output-----\nFor each test case, print a single line containing one integer \u2014 the maximum possible trace.\n\n-----Constraints-----\n- $1 \\le T \\le 100$\n- $2 \\le N \\le 100$\n- $1 \\le A_{i,j} \\le 100$ for each valid $i, j$\n\n-----Subtasks-----\nSubtask #1 (100 points): original constraints\n\n-----Example Input-----\n1\n3\n1 2 5\n6 3 4\n2 7 1\n\n-----Example Output-----\n13\n\n-----Explanation-----\nExample case 1: The submatrix with the largest trace is \n6 3\n2 7\n\nwhich has trace equal to $6 + 7 = 13$. (This submatrix is obtained for $r=2, c=1, l=2$.)\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\nT=int(input())\nfor k in range(0,T):\n N=int(input())\n matrix=[]\n for i in range(0,N):\n a=list(map(int, input().split()))\n matrix.append(a)\n max_trace = []\n for i in range(0,N):\n trace1=0\n trace2=0\n for j in range(0,i+1):\n trace1+=matrix[j][N+j-i-1]\n trace2+=matrix[N+j-i-1][j]\n max_trace.append(trace1)\n max_trace.append(trace2)\n print(max(max_trace))\n\n \n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n3\\n1 2 5\\n6 3 4\\n2 7 1\\n', 'output': '13\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/TRACE'}","problem_id":"vfc_3982","program":"```python\n# cook your dish here\nT=int(input())\nfor k in range(0,T):\n N=int(input())\n matrix=[]\n for i in range(0,N):\n a=list(map(int, input().split()))\n matrix.append(a)\n max_trace = []\n for i in range(0,N):\n trace1=0\n trace2=0\n for j in range(0,i+1):\n trace1+=matrix[j][N+j-i-1]\n trace2+=matrix[N+j-i-1][j]\n max_trace.append(trace1)\n max_trace.append(trace2)\n print(max(max_trace))\n\n \n\n```","inputs":"1\n3\n1 2 5\n6 3 4\n2 7 1\n","output":"13\n","actual_output":"13\n","execution_success":true,"sample_index":880},{"source":"apps","task_type":"verifiable_code","in_source_id":"1286","prompt":"Solve the following coding problem using the programming language python:\n\nWet Shark once had 2 sequences: \n{a_n}= {a_1, a_2, a_3, ... , a_(109)} \n{b_n} = {b_1, b_2, b_3, ... , b_(109)} \nHowever, he only kept one element from each sequence. Luckily, both the elements that Wet Shark kept have the same index in Wet Shark's sequences: that is, he took a_i and b_i for some 1 \u2264 i \u2264 109. \nRight after Wet Shark loses his sequences, he finds that he actually needs them to break the code of Cthulhu to escape a labyrinth. Cthulhu's code is a single floating point number Q. However, the code verifier is faulty. If Wet Shark enters any code c such that |c - Q| \u2264 0.01 , Cthulhu's code checker will allow him to escape.\nWet Shark now starts to panic, and consults Dry Dolphin for help via ultrasonic waves. After the Dry Dolphin Sequence Processing Factory processes data of Wet Shark's sequences, the machines give Wet Shark the following 2 relations his sequences follow for all 1 \u2264 n < 109, where x = sqrt(2) and y = sqrt(3).\n\nWet Shark is now clueless on how to compute anything, and asks you for help.\nWet Shark has discovered that Cthulhu's code is actually defined as Q = (a_k + b_k) / (2^s), where s is a predetermined number, k is the index of another element in Wet Shark's sequence, and a_k, b_k are precisely the kth elements of Wet Shark's sequences {a_n} and {b_n}, respectively.\nGiven k, i, and the 2 elements of the arrays Wet Shark has lost, find any value of the code c that will allow Wet Shark to exit Cthulhu's labyrinth.\n\n-----Input-----\nThe first line of input contains 3 space separated integers i, k, s \u2014 the common index of the two elements Wet Shark kept, the index of Wet Shark's array needed to break Cthulhu's code, and the number s described in the problem statement, respectively. It is guaranteed that Cthulhu's code, Q, is between -109 and 109 (both inclusive).\nThe second line of the input contains 2 space separated integers a_i and b_i, representing the ith element of sequence {a_n} and the ith element of sequence {b_n}, respectively.\n\n-----Output-----\nOutput any number c that will crack Cthulhu's code. Recall that if Wet Shark enters any code c such that |c - Q| \u2264 0.01 , Cthulhu's code checker will allow him to exit the labyrinth.\n\n----- Constraints -----\n- SUBTASK 1: 20 POINTS \n- 1 \u2264 i \u2264 103 \n- 1 \u2264 k \u2264 103 \n- -103 \u2264 s \u2264 103 \n- 1\u2009\u2264\u2009a_i,\u2009b_i\u2009\u2264\u2009103 \n\n- SUBTASK 2: 80 POINTS \n- 1 \u2264 i \u2264 1010 \n- 1 \u2264 k \u2264 1010 \n- -1010 \u2264 s \u2264 1010 \n- 1\u2009\u2264\u2009a_i,\u2009b_i\u2009\u2264\u20091010 \nIt is guaranteed that -1010 \u2264\u2009Q \u2264\u2009 1010.\n\n-----Example-----\nInput:\n1 1 5\n4 5\n\nOutput:\n0.28125\n\n-----Explanation-----\nExample case 1. In this case, a_1 = 4, b_1 = 5, and s = 5. Cthulhu's code in this case is (a_1 + b_1) / (2s) = 9/32 = 0.28125.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nimport math\r\n\r\ndef main():\r\n #print(\"enter i, k, s\")\r\n IN = '11 6 5'\r\n z = IN.split()\r\n z = input().split()\r\n i = int(z[0])\r\n k = int(z[1])\r\n s = int(z[2])\r\n\r\n #print(\"enter a_i and b_i\")\r\n IN = '4 5'\r\n z = IN.split()\r\n z = input().split()\r\n a_i = int(z[0])\r\n b_i = int(z[1])\r\n\r\n #print( \"i = %d k = %d s = %d \" % (i, k, s) )\r\n #print( \"a_i = %d b_i = %d\" % (a_i, b_i) )\r\n\r\n x = math.sqrt(2)\r\n y = math.sqrt(3)\r\n #print(x,y)\r\n\r\n # Obtaining the k-th element when k >= i\r\n if(i<=k):\r\n diff = k-i\r\n #if both k and i are odd or even\r\n if(k-i)%2==0:\r\n #print(\"#1\")\r\n ans = (a_i + b_i) * math.pow(2,2*(k-i)-s)\r\n #diff = int(diff/2) \r\n #ans = (a_i + b_i) * math.pow(2,4*diff-s)\r\n \r\n #if i and k are of different parities then obtaining first\r\n # a_(i+1) and b_(i+1)\r\n else:\r\n #print(\"#2\")\r\n ans = (2*x*a_i + 2*x*y*b_i) * math.pow(2,2*(k-(i+1))-s )\r\n diff = int(diff/2)\r\n ans = (2*x*a_i + 2*x*y*b_i) * math.pow(2,4*diff - s)\r\n #print(\"1: \", (2*x*a_i + 2*x*y*b_i))\r\n #print(\"2: \", math.pow(2,4*diff - 2- s)) \r\n #print(\"2 sol: \", math.pow(2,4*int(diff)-s))\r\n #print(\"diff: \",diff)\r\n\r\n\r\n # Obtaining the k_th element when k < i\r\n else:\r\n diff = i-k\r\n #if both k and i are odd or even\r\n if(i-k)%2==0:\r\n #print(\"#3\")\r\n ans = (a_i + b_i) / math.pow(2,2*(i-k)+s)\r\n #diff = int(diff/2)\r\n #ans = (a_i + b_i) / math.pow(2,4*diff+s)\r\n\r\n #if i and k are of different parities then obtaining first\r\n # a_(i+1) and b_(i+1)\r\n else:\r\n #print(\"#4\")\r\n ans = (2*x*a_i + 2*x*y*b_i) / math.pow(2,2*(i+1-k)+s)\r\n diff = int(diff/2)\r\n ans = (2*x*a_i + 2*x*y*b_i) / math.pow(2,4*diff + 4 + s)\r\n\r\n\r\n print(ans)\r\n \r\nmain()\r\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1 1 5\\n4 5\\n', 'output': '0.28125\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/CODECRCK'}","problem_id":"vfc_3986","program":"```python\nimport math\r\n\r\ndef main():\r\n #print(\"enter i, k, s\")\r\n IN = '11 6 5'\r\n z = IN.split()\r\n z = input().split()\r\n i = int(z[0])\r\n k = int(z[1])\r\n s = int(z[2])\r\n\r\n #print(\"enter a_i and b_i\")\r\n IN = '4 5'\r\n z = IN.split()\r\n z = input().split()\r\n a_i = int(z[0])\r\n b_i = int(z[1])\r\n\r\n #print( \"i = %d k = %d s = %d \" % (i, k, s) )\r\n #print( \"a_i = %d b_i = %d\" % (a_i, b_i) )\r\n\r\n x = math.sqrt(2)\r\n y = math.sqrt(3)\r\n #print(x,y)\r\n\r\n # Obtaining the k-th element when k >= i\r\n if(i<=k):\r\n diff = k-i\r\n #if both k and i are odd or even\r\n if(k-i)%2==0:\r\n #print(\"#1\")\r\n ans = (a_i + b_i) * math.pow(2,2*(k-i)-s)\r\n #diff = int(diff/2) \r\n #ans = (a_i + b_i) * math.pow(2,4*diff-s)\r\n \r\n #if i and k are of different parities then obtaining first\r\n # a_(i+1) and b_(i+1)\r\n else:\r\n #print(\"#2\")\r\n ans = (2*x*a_i + 2*x*y*b_i) * math.pow(2,2*(k-(i+1))-s )\r\n diff = int(diff/2)\r\n ans = (2*x*a_i + 2*x*y*b_i) * math.pow(2,4*diff - s)\r\n #print(\"1: \", (2*x*a_i + 2*x*y*b_i))\r\n #print(\"2: \", math.pow(2,4*diff - 2- s)) \r\n #print(\"2 sol: \", math.pow(2,4*int(diff)-s))\r\n #print(\"diff: \",diff)\r\n\r\n\r\n # Obtaining the k_th element when k < i\r\n else:\r\n diff = i-k\r\n #if both k and i are odd or even\r\n if(i-k)%2==0:\r\n #print(\"#3\")\r\n ans = (a_i + b_i) / math.pow(2,2*(i-k)+s)\r\n #diff = int(diff/2)\r\n #ans = (a_i + b_i) / math.pow(2,4*diff+s)\r\n\r\n #if i and k are of different parities then obtaining first\r\n # a_(i+1) and b_(i+1)\r\n else:\r\n #print(\"#4\")\r\n ans = (2*x*a_i + 2*x*y*b_i) / math.pow(2,2*(i+1-k)+s)\r\n diff = int(diff/2)\r\n ans = (2*x*a_i + 2*x*y*b_i) / math.pow(2,4*diff + 4 + s)\r\n\r\n\r\n print(ans)\r\n \r\nmain()\r\n\n```","inputs":"1 1 5\n4 5\n","output":"0.28125\n","actual_output":"0.28125\n","execution_success":true,"sample_index":881},{"source":"apps","task_type":"verifiable_code","in_source_id":"1287","prompt":"Solve the following coding problem using the programming language python:\n\nYou are given a string $s$. And you have a function $f(x)$ defined as:\nf(x) = 1, if $x$ is a vowel\nf(x) = 0, if $x$ is a constant\n\nYour task is to apply the above function on all the characters in the string s and convert \nthe obtained binary string in decimal number $M$.\nSince the number $M$ can be very large, compute it modulo $10^9+7$. \n\n-----Input:-----\n- The first line of the input contains a single integer $T$ i.e the no. of test cases. \n- Each test line contains one String $s$ composed of lowercase English alphabet letters. \n\n-----Output:-----\nFor each case, print a single line containing one integer $M$ modulo $10^9 + 7$.\n\n-----Constraints-----\n- $1 \u2264 T \u2264 50$\n- $|s|\u226410^5$\n\n-----Subtasks-----\n- 20 points : $|s|\u226430$\n- 80 points : $ \\text{original constraints}$\n\n-----Sample Input:-----\n1\nhello\n\n-----Sample Output:-----\n9\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nt=int(input())\nMOD=(10**9)+7\nl=['a','e','i','o','u']\nfor i in range(t):\n s=input()\n k=[]\n for j in s:\n if j in l:\n k.append(1)\n else:\n k.append(0)\n r=bin(int(''.join(map(str, k)), 2) << 1)\n print((int(r,2)//2)%MOD)\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\nhello\\n', 'output': '9\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/CBEN2020/problems/STRNM'}","problem_id":"vfc_3990","program":"```python\nt=int(input())\nMOD=(10**9)+7\nl=['a','e','i','o','u']\nfor i in range(t):\n s=input()\n k=[]\n for j in s:\n if j in l:\n k.append(1)\n else:\n k.append(0)\n r=bin(int(''.join(map(str, k)), 2) << 1)\n print((int(r,2)//2)%MOD)\n\n```","inputs":"1\nhello\n","output":"9\n","actual_output":"9\n","execution_success":true,"sample_index":882},{"source":"apps","task_type":"verifiable_code","in_source_id":"1288","prompt":"Solve the following coding problem using the programming language python:\n\nChef Shifu wanted to celebrate the success of his new restaurant with all his employees. He was willing to host a party and he had decided the location of the party as well. However, Chef Shifu was a shy person and wanted to communicate with the least possible employees to inform them about the party, and that these employees could inform their friends.\n\nNote that an employee could only inform his/her immediate friends about the party, not his/her friends\u2019 friends.\n\nChef Shifu has a list of all the friendships among his employees. Help him find the minimum number of employees he should inform, so that every employee knows about the celebration party.\n\n-----Input-----\nFirst line contains a single integer T - the total number of testcases.\n\nT testcases follow. For each testcase:\n\nThe first line contains 2 space-separated integers N and M - the total number of employees working under Chef Shifu and the number of friendship relations.\n\nM lines follow - each line contains 2 space-separated integers u and v, indicating that employee u is a friend of employee v and vice-versa.\n\nThe employees are numbered from 1 to N, and each employee is assigned a distinct integer.\n\n\n\n-----Output-----\nFor each testcase, print the minimum number of employees to be informed on a new line.\n\n-----Constraints-----\nSubtask 1: 5 points\n\n1 \u2264 T \u2264 5\n\n1 \u2264 N \u2264 4\n\n0 \u2264 M \u2264 N*(N-1)/2\n\n\n\nSubtask 2: 35 points\n\n1 \u2264 T \u2264 5\n\n1 \u2264 N \u2264 15\n\n0 \u2264 M \u2264 N*(N-1)/2\n\n\n\nSubtask 3: 60 points\n\n1 \u2264 T \u2264 5\n\n1 \u2264 N \u2264 20\n\n0 \u2264 M \u2264 N*(N-1)/2\n\n\n-----Example-----\nInput\n2\n3 3\n1 2\n2 3\n1 3\n4 3\n1 2\n2 3\n3 4\n\nOutput\n1\n2\n\nExplanation\n\nIn testcase 1, since every employee is a friend of every other employee, we just need to select 1 employee.\nIn testcase 2, selecting employees 2 and 4 would ensure that all 4 employees are represented.\n\nSimilarly, selecting employees 1 and 3 would also ensure that all 4 employees are selected.\n\nIn both cases, we must select 2 employees in the best case.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nt=int(input())\nfor _ in range(t):\n n,m=map(int,input().split())\n mat=[0 for i in range(n)]\n #mat=[[0 for i in range(n)] for j in range(n)]\n for i in range(m):\n u,v=map(int,input().split())\n u,v=(u-1),(v-1)\n mat[u]|=(1<0):\n \n n=int(input())\n if(n<=0):\n print(0)\n \n fact=1\n start=1\n for i in range(1,n+1):\n fact*=start\n start+=2\n print(fact)\n \n t=t-1\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\n2\\n5\\n18\\n', 'output': '3\\n945\\n221643095476699771875\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/AGTK2012/problems/ALGPAN'}","problem_id":"vfc_3998","program":"```python\nt = int(input())\n\nwhile(t>0):\n \n n=int(input())\n if(n<=0):\n print(0)\n \n fact=1\n start=1\n for i in range(1,n+1):\n fact*=start\n start+=2\n print(fact)\n \n t=t-1\n\n```","inputs":"3\n2\n5\n18\n","output":"3\n945\n221643095476699771875\n","actual_output":"3\n945\n221643095476699771875\n","execution_success":true,"sample_index":884},{"source":"apps","task_type":"verifiable_code","in_source_id":"1290","prompt":"Solve the following coding problem using the programming language python:\n\nWrite a program to obtain a number $(N)$ from the user and display whether the number is a one digit number, 2 digit number, 3 digit number or more than 3 digit number\n\n-----Input:-----\n- First line will contain the number $N$,\n\n-----Output:-----\nPrint \"1\" if N is a 1 digit number.\nPrint \"2\" if N is a 2 digit number.\nPrint \"3\" if N is a 3 digit number.\nPrint \"More than 3 digits\" if N has more than 3 digits.\n\n-----Constraints-----\n- $0 \\leq N \\leq 1000000$\n\n-----Sample Input:-----\n9\n\n-----Sample Output:-----\n1\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\nx=input ()\ny=len (x)\nif y==1:\n print('1')\nelif y==2:\n print('2')\nelif y==3:\n print('3')\nelif y>3:\n print('More than 3 digits')\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '9\\n', 'output': '1\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/HOWMANY'}","problem_id":"vfc_4002","program":"```python\n# cook your dish here\nx=input ()\ny=len (x)\nif y==1:\n print('1')\nelif y==2:\n print('2')\nelif y==3:\n print('3')\nelif y>3:\n print('More than 3 digits')\n```","inputs":"9\n","output":"1\n","actual_output":"1\n","execution_success":true,"sample_index":885},{"source":"apps","task_type":"verifiable_code","in_source_id":"1291","prompt":"Solve the following coding problem using the programming language python:\n\nDid you hear about the Nibiru collision ? It is a supposed disastrous encounter between the earth and a large planetary object. Astronomers reject this idea. But why listen to other people's beliefs and opinions. We are coders above all, so what better way than to verify it by a small code. The earth and N asteroids are in the 2D plane. Each of them is initially located at some integer coordinates at time = 0 and is moving parallel to one of the X or Y axis with constant velocity of 1 unit per second. \n\nDirection of movement is given as 'U' ( Up = towards positive Y ), 'D' ( Down = towards negative Y ), 'R' ( Right = towards positive X ), 'L' ( Left = towards negative X ). Given the initial position and the direction of movement of the earth and each of the N asteroids, find the earliest time at which the earth collides with one of the asteroids. If there can not be any collisions with the earth, print \"SAFE\" ( without quotes ). You can ignore the collisions between asteroids ( i.e., they continue to move in same direction even after collisions between them ).\n\n-----Input-----\n\nFirst line contains T, number of test cases. T cases follow. In each test case, first line contains XE YE DIRE, where (XE,YE) is the initial position of the Earth, DIRE is the direction in which it moves. Second line contains N, the number of\nasteroids. N lines follow, each containing XA YA DIRA, the initial position and the direction of movement of each asteroid. No asteroid is initially located at (XE,YE)\n\n-----Output-----\n\nFor each test case, output the earliest time at which the earth can collide with an asteroid (rounded to 1 position after decimal). If there can not be any collisions with the earth, print \"SAFE\" (without quotes).\n\n-----Constraints-----\n\n1 \u2264 T \u2264 10\n\n1 \u2264 N \u2264 2012\n\n-100 \u2264 XE, YE, XA, YA \u2264 100\n\n(XE,YE) != any of (XA,YA)\n\nDIRE, DIRA is one of 'U', 'R', 'D', 'L'\n\n\n-----Example-----\nInput:\n3\n0 0 R\n2\n1 -2 U\n2 2 D\n1 1 U\n1\n1 0 U\n0 0 R\n1\n3 0 L\n\nOutput:\n2.0\nSAFE\n1.5\n\nExplanation:\n\nCase 1 : \n\nTime 0 - Earth (0,0) Asteroids { (1,-2), (2,2) }\n\nTime 1 - Earth (1,0) Asteroids { (1,-1), (2,1) }\n\nTime 2 - Earth (2,0) Asteroids { (1,0 ), (2,0) }\n\nCase 2 : \n\nThe only asteroid is just one unit away below the earth and following us always, but it will never collide :)\n\nCase 3 : \n\nTime 0 - Earth (0,0) Asteroid (3,0)\n\nTime 1 - Earth (1,0) Asteroid (2,0)\n\nTime 1.5 - Earth (1.5,0) Asteroid (1.5,0)\n\nNote : There are multiple test sets, and the judge shows the sum of the time taken over all test sets of your submission, if Accepted.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n#-*- coding:utf-8 -*-\n\nimport sys\n\n\n# class Point:\n# def __init__(self, x, y):\n# self.x = x\n# self.y = y\n\n# def mul(self, k):\n# return Point(k * self.x, k * self.y)\n\n# def __add__(self, other):\n# return Point(self.x + other.x, self.y + other.y)\n\n# def __sub__(self, other):\n# return self + (-other)\n\n# def __neg__(self):\n# return Point(-self.x, -self.y)\n\n# def __eq__(self, other):\n# return self.x == other.x and self.y == other.y\n\n# def __getitem__(self, index):\n# return (self.x, self.y)[index]\n\n# def __str__(self):\n# return \"(%d;%d)\" % (self.x, self.y)\n\n\nDIRS = dict(\n U=(0, 1),\n D=(0, -1),\n R=(1, 0),\n L=(-1, 0)\n)\nKOEF = 0.2\n\n\ndef div(a, b):\n return round(float(a) / b, 1)\n\n\n# class Moving:\n# def __init__(self, x, y, dir):\n# self.p = Point(x, y)\n# self.dir = Point(*DIRS[dir.upper()])\n\n# def collide(self, other):\n# times = []\n# for coord in range(2):\n# d = abs(self.p[coord] - other.p[coord])\n# d2 = abs((self.p + self.dir.mul(KOEF) - other.p)[coord])\n# d3 = abs((other.p + other.dir.mul(KOEF) - self.p)[coord])\n# d_next = abs((self.p + self.dir.mul(KOEF) - (other.p + other.dir\u00a0\u00a0\u00a0\u00a0.mul(KOEF)))[coord])\n# if d2 > d or d3 > d:\n# return None\n\n# speed = abs(d_next - d)\n# if speed == 0:\n# if self.p[coord] != other.p[coord]:\n# return None\n# continue\n# times.append( div(d, speed / KOEF) )\n\n# if len(times) == 2 and times[0] != times[1]:\n# return\n# return times[0]\n\n\ndef collide_coord(ex, edx, x, dx):\n d = abs(ex - x)\n d2 = abs(ex + edx - x)\n d3 = abs(ex - x - dx)\n if d2 > d or d3 > d:\n return False\n\n d_next = abs(ex + edx * KOEF - x - dx * KOEF)\n speed = abs(d_next - d)\n if speed == 0:\n if ex != x:\n return\n return \"all\" # all\n else:\n return div(d, speed / KOEF)\n\n\ndef main():\n t = int(input())\n for _ in range(t):\n ex, ey, dir = sys.stdin.readline().strip().split()\n ex = int(ex)\n ey = int(ey)\n edx, edy = DIRS[dir]\n\n n = int(sys.stdin.readline())\n min_time = float(\"+inf\")\n for _ in range(n):\n x, y, dir = sys.stdin.readline().strip().split()\n x = int(x)\n y = int(y)\n dx, dy = DIRS[dir]\n\n tx = collide_coord(ex, edx, x, dx)\n if tx is False:\n continue\n ty = collide_coord(ey, edy, y, dy)\n if ty is False:\n continue\n\n if tx == \"all\":\n min_time = min(min_time, ty)\n elif ty == \"all\":\n min_time = min(min_time, tx)\n elif tx == ty:\n min_time = min(min_time, tx)\n\n print(min_time if min_time < 1000000 else \"SAFE\")\n\n\ndef __starting_point():\n main()\n\n__starting_point()\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\n0 0 R\\n2\\n1 -2 U\\n2 2 D\\n1 1 U\\n1\\n1 0 U\\n0 0 R\\n1\\n3 0 L\\n', 'output': '2.0\\nSAFE\\n1.5\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/COLLIDE'}","problem_id":"vfc_4006","program":"```python\n#-*- coding:utf-8 -*-\n\nimport sys\n\n\n# class Point:\n# def __init__(self, x, y):\n# self.x = x\n# self.y = y\n\n# def mul(self, k):\n# return Point(k * self.x, k * self.y)\n\n# def __add__(self, other):\n# return Point(self.x + other.x, self.y + other.y)\n\n# def __sub__(self, other):\n# return self + (-other)\n\n# def __neg__(self):\n# return Point(-self.x, -self.y)\n\n# def __eq__(self, other):\n# return self.x == other.x and self.y == other.y\n\n# def __getitem__(self, index):\n# return (self.x, self.y)[index]\n\n# def __str__(self):\n# return \"(%d;%d)\" % (self.x, self.y)\n\n\nDIRS = dict(\n U=(0, 1),\n D=(0, -1),\n R=(1, 0),\n L=(-1, 0)\n)\nKOEF = 0.2\n\n\ndef div(a, b):\n return round(float(a) / b, 1)\n\n\n# class Moving:\n# def __init__(self, x, y, dir):\n# self.p = Point(x, y)\n# self.dir = Point(*DIRS[dir.upper()])\n\n# def collide(self, other):\n# times = []\n# for coord in range(2):\n# d = abs(self.p[coord] - other.p[coord])\n# d2 = abs((self.p + self.dir.mul(KOEF) - other.p)[coord])\n# d3 = abs((other.p + other.dir.mul(KOEF) - self.p)[coord])\n# d_next = abs((self.p + self.dir.mul(KOEF) - (other.p + other.dir\u00a0\u00a0\u00a0\u00a0.mul(KOEF)))[coord])\n# if d2 > d or d3 > d:\n# return None\n\n# speed = abs(d_next - d)\n# if speed == 0:\n# if self.p[coord] != other.p[coord]:\n# return None\n# continue\n# times.append( div(d, speed / KOEF) )\n\n# if len(times) == 2 and times[0] != times[1]:\n# return\n# return times[0]\n\n\ndef collide_coord(ex, edx, x, dx):\n d = abs(ex - x)\n d2 = abs(ex + edx - x)\n d3 = abs(ex - x - dx)\n if d2 > d or d3 > d:\n return False\n\n d_next = abs(ex + edx * KOEF - x - dx * KOEF)\n speed = abs(d_next - d)\n if speed == 0:\n if ex != x:\n return\n return \"all\" # all\n else:\n return div(d, speed / KOEF)\n\n\ndef main():\n t = int(input())\n for _ in range(t):\n ex, ey, dir = sys.stdin.readline().strip().split()\n ex = int(ex)\n ey = int(ey)\n edx, edy = DIRS[dir]\n\n n = int(sys.stdin.readline())\n min_time = float(\"+inf\")\n for _ in range(n):\n x, y, dir = sys.stdin.readline().strip().split()\n x = int(x)\n y = int(y)\n dx, dy = DIRS[dir]\n\n tx = collide_coord(ex, edx, x, dx)\n if tx is False:\n continue\n ty = collide_coord(ey, edy, y, dy)\n if ty is False:\n continue\n\n if tx == \"all\":\n min_time = min(min_time, ty)\n elif ty == \"all\":\n min_time = min(min_time, tx)\n elif tx == ty:\n min_time = min(min_time, tx)\n\n print(min_time if min_time < 1000000 else \"SAFE\")\n\n\ndef __starting_point():\n main()\n\n__starting_point()\n```","inputs":"3\n0 0 R\n2\n1 -2 U\n2 2 D\n1 1 U\n1\n1 0 U\n0 0 R\n1\n3 0 L\n","output":"2.0\nSAFE\n1.5\n","actual_output":"2.0\nSAFE\n1.5\n","execution_success":true,"sample_index":886},{"source":"apps","task_type":"verifiable_code","in_source_id":"1292","prompt":"Solve the following coding problem using the programming language python:\n\nYou are given a grid of size N x M consisting of '.' (empty), 'W' (white) or 'B' (black) cells. We follow the convention that the top left corner is the position (1,1) and bottom right corner is (N,M). \nFrom every '.' cell (i, j), a ray is shot towards the right. If the ray reaches a 'B' cell, it loses it's strength fully and stops there. When a ray\nreaches a 'W' cell, it's strength drops drastically so that the ray stops when it reaches a second 'W' cell. That is, if there is no 'B'\ncell in between, a ray can cross at most one 'W' cell, and it will stop when it reaches the second 'W' cell. It passes unchanged through any '.' cell. If it reaches a boundary cell (ie. (i,M), for some i), it stops there.\nLet L(i, j) be length travelled by the ray starting from the cell (i, j). If (i,j) is 'W' or 'B', no ray starts from here, and hence L(i,j) is defined to be 0. If a ray starts from (i,j) and stops at (i,k), then the distance travelled by this ray is k-j+1. i.e, inclusive of both starting and ending cells.\nFor the given grid your task is to find the sum of L(i, j) over all 1 <= i <= N and 1 <= j <= M. \nThe description of the grid is given as follows: In addition to N and M, you are given the number of 'W' cells (w) and the number of 'B' cells (b)\nand you are given the locations of these w + b cells. (The other cells contain '.')\n\n-----Constraints:-----\nFor all testcases,\n- 1 <= N, M <= 10^6. \n- 0 <= w,b <= 10^5\nSubtask 1: 15%\nIt is guaranteed that 1 <= N,M <= 500\nSubtask 2: 25%\nIt is guaranteed that 1 <= N,M <= 2000\nSubtask 3: 60%\nNo additional guarantees.\n\n-----Input format:-----\n- There is only one line of input which contains 4 + 2w + 2b space separated integers. The first four integers are N, M, w and b. \n- The next 2*w integers denote the cells which contains a 'W': x1 y1 x2 y2 .. xw yw. These denote that (xi,yi) contains 'W'.\n- The next 2*b integers denote the cells which contains a 'B': x1 y1 x2 y2 .. xb yb. These denote that (xi,yi) contains 'B'.\n- The cells which are not in the input have to be assumed to be '.' \n\n-----Output format:-----\nOutput a single integer which is the sum of L(i,j) over all 1 <= i <= N and 1 <= j <= M.\n\n-----Sample Input 1:-----\n4 4 5 2 1 3 2 1 3 2 3 3 4 3 1 4 2 3\n\n-----Sample Output 1:-----\n22\n\n-----Explanation:-----\nThe grid is:\n. . W B\nW . B .\n. W W .\n. . W .\n\nL(i,j) for each cell is:\n4 3 0 0\n0 2 0 1\n3 0 0 1\n4 3 0 1\n\nTherefore, the total is 22.\n\n-----Note:-----\nAs the answer might be large, please use 64 bit integers (long long int in C/C++ and long in Java) instead of 32 bit int.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\nfrom operator import itemgetter\ninp=list(map(int, input().split()))\nn, m, w, b = inp[:4]\nstops=[]\nfor i in range(w):\n stops.append((inp[4+2*i]-1,inp[5+2*i]-1,'w'))\nfor i in range(b):\n stops.append((inp[4+2*w+2*i]-1,inp[5+2*w+2*i]-1,'b'))\nstops.sort(key=itemgetter(1))\nstops.sort(key=itemgetter(0))\ncounter=0\nstop_rows=[[] for _ in range(n)]\nfor stop in stops:\n stop_rows[stop[0]].append(stop[1:])\nfor row in stop_rows:\n idx=0\n for i in range(len(row)):\n if idx==row[i][0]:\n idx+=1\n else:\n if row[i][1]=='w':\n if i>1)-1\n idx=row[i][0]+1\n num=row[i+1][0]-row[i][0]+1\n counter-=((num*(num+1))>>1)-1\n else:\n num=m-idx\n counter+=((num*(num+1))>>1)-1\n idx=row[i][0]+1\n num=m-row[i][0]\n counter-=((num*(num+1))>>1)-1\n else:\n num=row[i][0]-idx+1\n counter+=((num*(num+1))>>1)-1\n idx=row[i][0]+1\n num=m-idx\n counter+=(num*(num+1))>>1\nprint(counter)\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '4 4 5 2 1 3 2 1 3 2 3 3 4 3 1 4 2 3\\n', 'output': '22\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/ZCOPRAC/problems/ZCO17002'}","problem_id":"vfc_4010","program":"```python\n# cook your dish here\nfrom operator import itemgetter\ninp=list(map(int, input().split()))\nn, m, w, b = inp[:4]\nstops=[]\nfor i in range(w):\n stops.append((inp[4+2*i]-1,inp[5+2*i]-1,'w'))\nfor i in range(b):\n stops.append((inp[4+2*w+2*i]-1,inp[5+2*w+2*i]-1,'b'))\nstops.sort(key=itemgetter(1))\nstops.sort(key=itemgetter(0))\ncounter=0\nstop_rows=[[] for _ in range(n)]\nfor stop in stops:\n stop_rows[stop[0]].append(stop[1:])\nfor row in stop_rows:\n idx=0\n for i in range(len(row)):\n if idx==row[i][0]:\n idx+=1\n else:\n if row[i][1]=='w':\n if i>1)-1\n idx=row[i][0]+1\n num=row[i+1][0]-row[i][0]+1\n counter-=((num*(num+1))>>1)-1\n else:\n num=m-idx\n counter+=((num*(num+1))>>1)-1\n idx=row[i][0]+1\n num=m-row[i][0]\n counter-=((num*(num+1))>>1)-1\n else:\n num=row[i][0]-idx+1\n counter+=((num*(num+1))>>1)-1\n idx=row[i][0]+1\n num=m-idx\n counter+=(num*(num+1))>>1\nprint(counter)\n\n```","inputs":"4 4 5 2 1 3 2 1 3 2 3 3 4 3 1 4 2 3\n","output":"22\n","actual_output":"22\n","execution_success":true,"sample_index":887},{"source":"apps","task_type":"verifiable_code","in_source_id":"1293","prompt":"Solve the following coding problem using the programming language python:\n\nChef and his friend Miron were getting bored and decided to play a game. \nMiron thinks of a sequence of N integers (A1, A2, \u2026., AN) and gives Chef a matrix B, where Bi,j = |Ai - Aj|. He further tells Chef that A1 = 0. The game is for Chef to guess the sequence that Miron thought of. \nBut Miron is an adversarial player. Every time Chef tries to guess the sequence, he makes a change to the matrix. He makes such a change Q times. Each time, he replaces an entry in some row and the corresponding column with a new one leaving Chef to guess the sequence after each change. \nChef needs a friend to help him against such an adversarial player. Can you be that friend and help Chef find a suitable sequence A for the initial matrix B and also after each change Miron makes? \nNote that if several answers exist, then print the lexicographically smallest answer. Further, the numbers in the sequence can be negative.\n\n-----Input-----\n\nThe first line contains two space-separated integers N, Q. Each of the N subsequent lines contains N space-separated integers, denoting the matrix B.\n\nQ queries follow. Each query has two lines. The first line of each query contains an integer p, denoting the number of row and column that is changed. The second line of each query contains N space-separated integers F1, F2, F3, ... FN, denoting the new values to the corresponding cells of the matrix (you should make the following assignments Bi,p = Bp,i = Fi for all valid i). \n\n-----Output-----\nPrint Q + 1 lines which contain N space-separated integers, Miron's initial array and Miron's array after each query.\n\n-----Constraints-----\n- 3 \u2264 N \u2264 1000 \n- 1 \u2264 Q \u2264 1000 \n- 0 \u2264 Bi,j \u2264 5000 \n- 1 \u2264 p \u2264 n \n- 0 \u2264 Fi \u2264 5000 \n- it's guaranteed there's always an answer\n\n-----Example-----\nInput:\n3 2\n0 1 2\n1 0 1\n2 1 0\n1\n0 4 3\n2\n4 0 7\nOutput:\n0 -1 -2\n0 -4 -3\n0 -4 3\n\n-----Explanation-----\nExample case 1. Initially, sequence {0, 1, 2} is also suitable, but {0, -1, -2} is lexicografically smaller.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\ndef update_B(B, query):\n p, R = query\n for i in range(len(R)):\n B[p][i] = R[i]\n B[i][p] = R[i]\n\ndef get_A(B):\n N = len(B)\n A = [0] * N\n i = 0\n for j in range(N):\n if B[0][j] != 0:\n i = j\n A[i] = -B[0][i]\n break\n\n for j in range(i + 1, N):\n if abs(A[i] - B[0][j]) == B[i][j]:\n A[j] = B[0][j]\n else:\n A[j] = -B[0][j]\n\n return A\n\ndef print_list(A):\n print(' '.join([str(a) for a in get_A(B)]))\n\n\nN, Q = [int(x) for x in input().rstrip().split()]\nB = []\nfor i in range(N):\n B += [[int(x) for x in input().rstrip().split()]]\nqueries = []\nfor i in range(Q):\n p = int(input()) - 1\n arr = input().rstrip().split()\n queries += [(p, [int(x) for x in arr])]\n\nprint_list(get_A(B))\nfor q in queries:\n update_B(B, q)\n print_list(' '.join([str(a) for a in get_A(B)]))\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3 2\\n0 1 2\\n1 0 1\\n2 1 0\\n1\\n0 4 3\\n2\\n4 0 7\\n', 'output': '0 -1 -2\\n0 -4 -3\\n0 -4 3\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/MTRXMOD'}","problem_id":"vfc_4014","program":"```python\ndef update_B(B, query):\n p, R = query\n for i in range(len(R)):\n B[p][i] = R[i]\n B[i][p] = R[i]\n\ndef get_A(B):\n N = len(B)\n A = [0] * N\n i = 0\n for j in range(N):\n if B[0][j] != 0:\n i = j\n A[i] = -B[0][i]\n break\n\n for j in range(i + 1, N):\n if abs(A[i] - B[0][j]) == B[i][j]:\n A[j] = B[0][j]\n else:\n A[j] = -B[0][j]\n\n return A\n\ndef print_list(A):\n print(' '.join([str(a) for a in get_A(B)]))\n\n\nN, Q = [int(x) for x in input().rstrip().split()]\nB = []\nfor i in range(N):\n B += [[int(x) for x in input().rstrip().split()]]\nqueries = []\nfor i in range(Q):\n p = int(input()) - 1\n arr = input().rstrip().split()\n queries += [(p, [int(x) for x in arr])]\n\nprint_list(get_A(B))\nfor q in queries:\n update_B(B, q)\n print_list(' '.join([str(a) for a in get_A(B)]))\n\n```","inputs":"3 2\n0 1 2\n1 0 1\n2 1 0\n1\n0 4 3\n2\n4 0 7\n","output":"0 -1 -2\n0 -4 -3\n0 -4 3\n","actual_output":"0 -1 -2\n0 -4 -3\n0 -4 3\n","execution_success":true,"sample_index":888},{"source":"apps","task_type":"verifiable_code","in_source_id":"1294","prompt":"Solve the following coding problem using the programming language python:\n\n\"Say my Name\".\nTodd Alquist is being taught the process of cooking methamphetamine, but to see whether he's really capable of learning it, Walt gives him a problem to solve. Since he can't solve it, he asks you for help.\nYou are given a tree with $N$ vertices (numbered $1$ through $N$), rooted at the vertex $1$. There is an integer written at each vertex; for each valid $i$, the value of vertex $i$ is $A$$i$.There also exists a special integer $K$. \nChoose any leaf node, denoted by $X$, and go down a simple path from $root$ to $X$.\nLet $S$ denote the set of all nodes lying on the simple path from $root$ to $X$.\nFor all $ i $ $\\epsilon $ $ S $, choose an integer $D$ $\\epsilon$ $[2^{A[i]-1},2^{A[i]})$.\n\nInformally, for every node $i$ lying on the simple path from $root$ to $X$, you have to choose an integer $D$ such that $2^{A[i]-1}\\leq D < 2^{A[i]}$. \nYou now have to perform one of the two following operations : \n- Bitwise XOR of all chosen integers. \n- Bitwise AND of all chosen integers. \nYou have to determine whether you can choose the values in such a way that after performing one of the given operations you can get an integer equal to $K$. \n- Note : A leaf is a node of the tree without any child nodes.\nDetermine if it is possible to obtain the value $K$ by performing the given operations.\n\n-----Input:-----\n- First line will contain $T$, number of testcases. Then the testcases follow. \n- First line of each testcase contains two space separated integers $N, K$ denoting the number of nodes and the value of the special integer .\n- $N-1$ lines follow , each line contains two space separated integers $u,v$ denoting an edge between $u$ and $v$. \n- A single line follows containing $N$ space separated integers denoting the value of nodes.\n\n-----Output:-----\nFor each testcase, output in a single line \"YES\"(without quotes) or \"NO\"(without quotes).\n\n-----Constraints-----\n- $1 \\leq T \\leq 10000$\n- $2 \\leq N \\leq 5*10^5$\n- $1 \\leq K \\leq 10^{18}$\n- $1 \\leq u,v \\leq N$\n- $ 1\\leq A[i] \\leq 64$\n- Sum of $N$ over all test cases does not exceed 1e6.\n\n-----Sample Input:-----\n1\n6 85\n1 2\n2 3\n2 4\n4 5\n3 6\n3 5 4 7 1 9\n\n-----Sample Output:-----\nYES\n\n-----EXPLANATION:-----\nThere are two leaf nodes, 5 and 6\nconsidering path from root to 5\nwe have nodes\n1->2->4->5\nwe can select the values\n5,26,75,1 and perform operation 1 that is XOR of all numbers to get 85\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\nimport sys,collections\ninput=sys.stdin.readline\ndef main():\n T=int(input())\n for _ in range(T):\n N,K=map(int,input().split())\n Tree={}\n for j in range(N):\n Tree[j]=[]\n \n for i in range(N-1):\n u,v=map(int,input().split())\n Tree[u-1].append(v-1)\n Tree[v-1].append(u-1)\n \n A=list(map(int,input().split()))\n \n vis=[0 for i in range(N)] #to mark visited vertices 0 for visited and \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a01 for not visited\n maxval=[[0,0] for i in range(N)] #Nx2 list where each i stores max \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0value till now and its count \n minval=[0 for i in range(N)] #Nx2 list where each i stores min value \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0till now \n lfnode=[] #list to store leaf nodes\n \n #Appending node 1\n vis[0]=1\n Q=collections.deque([0])\n maxval[0][0],maxval[0][1]=A[0],1\n minval[0]=A[0]\n \n \n while(len(Q)!=0):\n a=Q.pop()\n mv1=maxval[a][0]\n mv2=minval[a]\n \n flag=0 #to check leaf node\n \n for i in Tree[a]:\n if (vis[i]==0):\n vis[i]=1\n flag=1 #not a leaf node\n v=A[i]\n Q.append(i)\n \n #Comparing maximum value of parent node\n if (mv1v):\n minval[i]=v\n elif(v==mv2):\n minval[i]=mv2\n else:\n minval[i]=minval[a]\n \n \n if (flag==0):\n lfnode.append(a)\n \n \n flag=0 #For answer if 0 then NO else YES\n \n K1=len(bin(K))-2 #length of K\n \n #print(lfnode,val)\n for i in lfnode:\n v1,v2=maxval[i][0],maxval[i][1]\n \n if (v1>K1 and v2%2==0):\n flag=1\n elif(v1==K1 and v2%2==1):\n flag=1\n \n \n v11=minval[i]\n if (v11>K1 and v11!=v1):\n flag=1\n elif(v11==K1):\n flag=1\n \n \n if(flag==1):\n break\n \n if (flag==1):\n print(\"YES\")\n else:\n print(\"NO\")\nmain()\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n6 85\\n1 2\\n2 3\\n2 4\\n4 5\\n3 6\\n3 5 4 7 1 9\\n', 'output': 'YES\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/KTREE'}","problem_id":"vfc_4018","program":"```python\n# cook your dish here\nimport sys,collections\ninput=sys.stdin.readline\ndef main():\n T=int(input())\n for _ in range(T):\n N,K=map(int,input().split())\n Tree={}\n for j in range(N):\n Tree[j]=[]\n \n for i in range(N-1):\n u,v=map(int,input().split())\n Tree[u-1].append(v-1)\n Tree[v-1].append(u-1)\n \n A=list(map(int,input().split()))\n \n vis=[0 for i in range(N)] #to mark visited vertices 0 for visited and \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a01 for not visited\n maxval=[[0,0] for i in range(N)] #Nx2 list where each i stores max \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0value till now and its count \n minval=[0 for i in range(N)] #Nx2 list where each i stores min value \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0till now \n lfnode=[] #list to store leaf nodes\n \n #Appending node 1\n vis[0]=1\n Q=collections.deque([0])\n maxval[0][0],maxval[0][1]=A[0],1\n minval[0]=A[0]\n \n \n while(len(Q)!=0):\n a=Q.pop()\n mv1=maxval[a][0]\n mv2=minval[a]\n \n flag=0 #to check leaf node\n \n for i in Tree[a]:\n if (vis[i]==0):\n vis[i]=1\n flag=1 #not a leaf node\n v=A[i]\n Q.append(i)\n \n #Comparing maximum value of parent node\n if (mv1v):\n minval[i]=v\n elif(v==mv2):\n minval[i]=mv2\n else:\n minval[i]=minval[a]\n \n \n if (flag==0):\n lfnode.append(a)\n \n \n flag=0 #For answer if 0 then NO else YES\n \n K1=len(bin(K))-2 #length of K\n \n #print(lfnode,val)\n for i in lfnode:\n v1,v2=maxval[i][0],maxval[i][1]\n \n if (v1>K1 and v2%2==0):\n flag=1\n elif(v1==K1 and v2%2==1):\n flag=1\n \n \n v11=minval[i]\n if (v11>K1 and v11!=v1):\n flag=1\n elif(v11==K1):\n flag=1\n \n \n if(flag==1):\n break\n \n if (flag==1):\n print(\"YES\")\n else:\n print(\"NO\")\nmain()\n```","inputs":"1\n6 85\n1 2\n2 3\n2 4\n4 5\n3 6\n3 5 4 7 1 9\n","output":"YES\n","actual_output":"YES\n","execution_success":true,"sample_index":889},{"source":"apps","task_type":"verifiable_code","in_source_id":"1295","prompt":"Solve the following coding problem using the programming language python:\n\nIn the year 4242, the language Haskell has evolved so much that it has become an AI. It can solve very challenging problems, in very little time. Humanity is worried that Haskell will take over the world. All hopes remain tied to the Competitive Programming community as they are the expert in shaving milliseconds off code runtime. Haskell creators have found one particular task that if solved faster than Haskell itself, can be used to hack into Haskell's codebase and thus defeat it. The exact details of the task are as follows,\n\n\n\" Calculate the sum, S(N, K) = , for Q queries. Here Fi is ith Fibonacci number defined as: Fi = i if i = 0 or 1 and Fi = Fi-1 + Fi-2 if i >= 2. \"\n\n\nYou being a member of the Competitive Programming community are encouraged to make a submission to this task.\n\n-----Input-----\n\nThe first line contains a single integer Q, the number of queries.\n\nEach of the next Q lines contain two integers each, Ni and Ki.\n\n-----Output-----\n\nOutput Q lines with one integer each. The ith line should contain the value S(Ni, Ki).\n\n-----Constraints-----\n- 1 <= Q <= 5*104\n- 1 <= N <= 1018\n- 1 <= K <= 1018\n\n-----Example-----\nInput:\n1\n1 1\nOutput:\n1\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nmod=10**9+7\ndef fibonacci(n):\n if n < 0:\n raise ValueError(\"Negative arguments not implemented\")\n return (_fib(n)[0]%mod + mod)%mod;\ndef _fib(n):\n if n == 0:\n return (0, 1)\n else:\n a, b = _fib(n // 2)\n c = (a * (b * 2 - a))%mod\n d = (a * a + b * b)%mod\n if n % 2 == 0:\n return (c, d)\n else:\n return (d, c + d)\ndef inv(n):\n return pow(n,mod-2,mod)\ndef brute(n,k):\n ret = 0\n for i in range(0,n+1):\n ret+=fibonacci(i)*pow(k,i,mod)\n return ret%mod\ndef ans(n,k):\n k%=mod\n a = pow(k,n+1,mod)\n b=(a*k)%mod\n x = a*(fibonacci(n+1))+b*fibonacci(n)-k\n y = inv((k*k+k-1)%mod)\n return ((x*y)%mod+mod)%mod\nfor t in range(0,eval(input())):\n n,k = list(map(int,input().split()))\n print(ans(n,k))\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n1 1\\n', 'output': '1\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/IPC15P3B/problems/FIBEQN'}","problem_id":"vfc_4022","program":"```python\nmod=10**9+7\ndef fibonacci(n):\n if n < 0:\n raise ValueError(\"Negative arguments not implemented\")\n return (_fib(n)[0]%mod + mod)%mod;\ndef _fib(n):\n if n == 0:\n return (0, 1)\n else:\n a, b = _fib(n // 2)\n c = (a * (b * 2 - a))%mod\n d = (a * a + b * b)%mod\n if n % 2 == 0:\n return (c, d)\n else:\n return (d, c + d)\ndef inv(n):\n return pow(n,mod-2,mod)\ndef brute(n,k):\n ret = 0\n for i in range(0,n+1):\n ret+=fibonacci(i)*pow(k,i,mod)\n return ret%mod\ndef ans(n,k):\n k%=mod\n a = pow(k,n+1,mod)\n b=(a*k)%mod\n x = a*(fibonacci(n+1))+b*fibonacci(n)-k\n y = inv((k*k+k-1)%mod)\n return ((x*y)%mod+mod)%mod\nfor t in range(0,eval(input())):\n n,k = list(map(int,input().split()))\n print(ans(n,k))\n```","inputs":"1\n1 1\n","output":"1\n","actual_output":"1\n","execution_success":true,"sample_index":890},{"source":"apps","task_type":"verifiable_code","in_source_id":"1296","prompt":"Solve the following coding problem using the programming language python:\n\nIn Byteland there are N cities, numbered 1 through N. Some pairs of cities are connected by bi-directional roads in such a way that starting from any one city you can visit all other cities either directly or indirectly.\n\nChef is currently at city A and wants to visit all other cities in Byteland. Chef can only move according to following rule. \n\nIf Chef is at city A then he continues to move from city A to city B, city B to city C (provided A is directly connected to B, B is directly connected to C) and so on unless there are no more cities leading from current city.\n\nIf so he jumps back to previous city and repeat the same tour with other cities leading from it which are not visited. Chef repeat this step unless all cities are not visited.\n\nHelp Chef to count number of ways in which he can visit all other cities . As this number can be large print it modulo 109+7\n\n-----Input-----\n- The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.\n- The first line of each test case contains a single integer N denoting the number of cities in Byteland.\n- Next N-1 lines contain two space-separated integers u and v denoting there is bi-directional road between city numbered u and v. \n- Next line contains a single integer A denoting the city number where Chef is present.\n\n-----Output-----\n- For each test case, output a single line containing number of ways in which Chef can visit all cities modulo 109+7.\n\n-----Constraints-----\n- 1 \u2264 T \u2264 5\n- 1 \u2264 N \u2264 105\n- 1 \u2264 A \u2264 N\n\n-----Subtasks-----\nSubtask #1 : (10 points) \n- 1 \u2264 N \u2264 5\nSubtask #2 : (30 points) \n- 1 \u2264 N \u2264 100\nSubtask #3 : (60 points) \n- 1 \u2264 N \u2264 105\n\n-----Example-----\nInput:\n2\n3\n1 2\n1 3\n1\n5\n1 2\n1 3\n2 4\n2 5\n1\n\nOutput:\n2\n4\n\n-----Explanation-----\nExample case 1. Chef can visit cities in two ways according to the problem: 1-2-3 and 1-3-2\nExample case 1. Chef can visit cities in four ways according to the problem:\n\n1-2-4-5-3\n1-2-5-4-3\n1-3-2-4-5\n1-3-2-5-4\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nimport sys\nsys.setrecursionlimit(10**8)\n\nMOD = 10**9+7\n\nfac = [0]*(10**5+1)\ndef pre() :\n fac[0] = 1\n for i in range(1,10**5+1) :\n fac[i] = fac[i-1]*i\n fac[i] = fac[i]%MOD\n\ndef dfs(gp , vertex , visited , deg , ans) :\n visited[vertex] = 1\n stack = []\n stack.append(vertex)\n while len(stack)>0 :\n vertex = stack.pop()\n ans = ans%MOD * fac[deg[vertex]]%MOD\n ans %= MOD\n for i in gp[vertex] :\n if not visited[i] :\n visited[i] = 1\n if vertex in gp[i] :\n deg[i] -= 1\n stack.append(i)\n return ans%MOD\n\npre()\nfor __ in range(eval(input())) :\n n = eval(input())\n deg = [0]*(n+1)\n st = [[] for __ in range(n+1)]\n for _ in range(n-1) :\n a , b = list(map(int,sys.stdin.readline().split()))\n st[a].append(b)\n st[b].append(a)\n deg[a] += 1\n deg[b] += 1\n k = eval(input())\n visited = [0]*(n+1)\n print(dfs(st ,k,visited,deg , 1)%MOD)\n \n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n3\\n1 2\\n1 3\\n1\\n5\\n1 2\\n1 3\\n2 4\\n2 5\\n1\\n', 'output': '2\\n4\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/LOCAPR16/problems/BLTOUR'}","problem_id":"vfc_4026","program":"```python\nimport sys\nsys.setrecursionlimit(10**8)\n\nMOD = 10**9+7\n\nfac = [0]*(10**5+1)\ndef pre() :\n fac[0] = 1\n for i in range(1,10**5+1) :\n fac[i] = fac[i-1]*i\n fac[i] = fac[i]%MOD\n\ndef dfs(gp , vertex , visited , deg , ans) :\n visited[vertex] = 1\n stack = []\n stack.append(vertex)\n while len(stack)>0 :\n vertex = stack.pop()\n ans = ans%MOD * fac[deg[vertex]]%MOD\n ans %= MOD\n for i in gp[vertex] :\n if not visited[i] :\n visited[i] = 1\n if vertex in gp[i] :\n deg[i] -= 1\n stack.append(i)\n return ans%MOD\n\npre()\nfor __ in range(eval(input())) :\n n = eval(input())\n deg = [0]*(n+1)\n st = [[] for __ in range(n+1)]\n for _ in range(n-1) :\n a , b = list(map(int,sys.stdin.readline().split()))\n st[a].append(b)\n st[b].append(a)\n deg[a] += 1\n deg[b] += 1\n k = eval(input())\n visited = [0]*(n+1)\n print(dfs(st ,k,visited,deg , 1)%MOD)\n \n\n```","inputs":"2\n3\n1 2\n1 3\n1\n5\n1 2\n1 3\n2 4\n2 5\n1\n","output":"2\n4\n","actual_output":"2\n4\n","execution_success":true,"sample_index":891},{"source":"apps","task_type":"verifiable_code","in_source_id":"1297","prompt":"Solve the following coding problem using the programming language python:\n\nChef has just started Programming, he is in first year of Engineering. Chef is reading about Relational Operators. \n\nRelational Operators are operators which check relatioship between two values. Given two numerical values A and B you need to help chef in finding the relationship between them that is, \n\n- First one is greater than second or,\n- First one is less than second or,\n- First and second one are equal.\n\n-----Input-----\nFirst line contains an integer T, which denotes the number of testcases. Each of the T lines contain two integers A and B. \n\n-----Output-----\nFor each line of input produce one line of output. This line contains any one of the relational operators\n\n'<' , '>' , '='.\n\n-----Constraints-----\n\n- 1 \u2264 T \u2264 10000\n- 1 \u2264 A, B \u2264 1000000001\n\n-----Example-----\nInput:\n3\n10 20\n20 10\n10 10\n\nOutput:\n<\n>\n=\n\n-----Explanation-----\nExample case 1. In this example 1 as 10 is lesser than 20.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\nfor _ in range(int(input())):\n x, y= map(int, input().split())\n if xy:\n print('>')\n else:\n print('=')\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\n10 20\\n20 10\\n10 10\\n', 'output': '<\\n>\\n=\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/CHOPRT'}","problem_id":"vfc_4030","program":"```python\n# cook your dish here\nfor _ in range(int(input())):\n x, y= map(int, input().split())\n if xy:\n print('>')\n else:\n print('=')\n```","inputs":"3\n10 20\n20 10\n10 10\n","output":"<\n>\n=\n","actual_output":"<\n>\n=\n","execution_success":true,"sample_index":892},{"source":"apps","task_type":"verifiable_code","in_source_id":"1298","prompt":"Solve the following coding problem using the programming language python:\n\nBatman is about to face Superman so he decides to prepare for the battle by upgrading his Batmobile. He manufactures multiple duplicates of his standard Batmobile each tweaked in a different way such that the maximum speed of each is never less than that of the standard model.\nAfter carrying out this process, he wishes to know how many of his prototypes are faster than his standard Batmobile?\n\n-----Input-----\n- The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follow: \n- The first line of each test case contains a single integer N denoting the number of copies of the standard Batmobile.\n- The second line contains a sequence of N+1 space-separated integers, S0 to SN, sorted in non-decreasing order separated by space. S0 is the maximum speed of the standard Batmobile. S1 to SN denote the maximum speeds of the prototypes.\n\n-----Output-----\n- For each test case, output a single line containing an integer denoting the answer.\n\n-----Constraints-----\n- 1 \u2264 T \u2264 1000\n- 1 \u2264 N \u2264 1000\n- 1 \u2264 Si \u2264 109\n\n-----Example-----\nInput:\n2\n4\n1 2 3 4 5\n5\n1 10 100 1000 10000 100000\n\nOutput:\n4\n5\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nt = int(input())\nwhile(t):\n n = int(input())\n ar = list(map(int,input().strip().split(\" \")))\n print(len([x for x in ar[1:len(ar)] if ar[0] mod):\n ans[i] = ans[i] - mod\n print(ans[k])\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n12 4 3\\n4 5 6 7 1 4 6 9 0 0 10 2\\n', 'output': '8\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/GRUMPMA'}","problem_id":"vfc_4054","program":"```python\n# cook your dish here\nmod = 10**9 + 7\nfor i in range(int(input())):\n n,k,m = tuple(map(int, input().split()))\n a = list(map(int, input().split()))\n ans = [0 for i in range(k+1)]\n ans[0] = 1\n curr_ending = 1\n for i in range(n):\n mod_a = a[i]%m\n start = curr_ending - (curr_ending%m - mod_a)%m\n if(mod_a == curr_ending%m and curr_ending mod):\n ans[i] = ans[i] - mod\n print(ans[k])\n```","inputs":"1\n12 4 3\n4 5 6 7 1 4 6 9 0 0 10 2\n","output":"8\n","actual_output":"8\n","execution_success":true,"sample_index":898},{"source":"apps","task_type":"verifiable_code","in_source_id":"1304","prompt":"Solve the following coding problem using the programming language python:\n\nIt is an interesting exercise to write a program to print out all permutations of $1, 2, \u2026, n$. However, since there are $6227020800$ permutations of $1, 2, \u2026, 13$, it is unlikely that we would ever run this program on an input of size more than $10$.\nHowever, here is another interesting problem whose solution can also be used to generate permutations. We can order the permutations of $1, 2, \u2026, n$ under the lexicographic (or dictionary) order. Here are the permutations of $1,2,3$ in lexicographic order:\n123132213231312321123132213231312321 1 \\, 2 \\, 3 \\quad 1 \\, 3 \\, 2 \\quad 2 \\, 1 \\, 3 \\quad 2 \\, 3 \\, 1 \\quad 3 \\, 1 \\, 2 \\quad 3 \\, 2 \\, 1 \nThe problem we have is the following: given a permutation of $1,2, \u2026, n$, generate the next permutation in lexicographic order. For example, for $2 3 1 4$ the answer is $2 3 4 1$.\n\n-----Input:-----\nThe first line of the input contains two integers, $N$ and $K$. This is followed by $K$ lines, each of which contains one permutation of $1, 2,\u2026,N$.\n\n-----Output:-----\nThe output should consist of $K$ lines. Line $i$ should contain the lexicographically next permutation correponding to the permutation on line $i+1$ in the input.\n\n-----Constraints:-----\n- $1 \\leq N \\leq 1000$.\n- $1 \\leq K \\leq 10$.\n\n-----Sample input-----\n3 2\n3 1 2\n2 3 1\n\n-----Sample output-----\n3 2 1\n3 1 2\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nimport sys\n# import math as mt\n# from collections import Counter\n# from itertools import permutations\n# from functools import reduce\n# from heapq import nsmallest, nlargest, heapify, heappop, heappush, heapreplace\n\ndef get_inpt(): return sys.stdin.readline().strip()\ndef get_int(): return int(sys.stdin.readline().strip())\ndef get_ints(): return map(int, sys.stdin.readline().strip().split())\ndef get_array(): return list(map(int, sys.stdin.readline().strip().split()))\n\n# sys.setrecursionlimit(10**7)\n# INF = float('inf')\n# MOD1, MOD2 = 10**9+7, 998244353\n\nn, k = get_ints()\n\nfor _ in range(k):\n \n arr = get_array()\n \n for i in reversed(range(n-1)):\n \n if arr[i] < arr[i+1]:\n \n ind = i+1\n minn = arr[i+1]\n for j in range(i+1, n):\n if arr[j] > arr[i]:\n minn = min(arr[j], minn)\n ind = j\n \n arr[i], arr[ind] = arr[ind], arr[i]\n \n arr = arr[:i+1] + sorted(arr[i+1:])\n \n break\n \n print(*arr)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3 2\\n3 1 2\\n2 3 1\\n\\n', 'output': '3 2 1\\n3 1 2 \\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/IARCSJUD/problems/NEXTPERM'}","problem_id":"vfc_4058","program":"```python\nimport sys\n# import math as mt\n# from collections import Counter\n# from itertools import permutations\n# from functools import reduce\n# from heapq import nsmallest, nlargest, heapify, heappop, heappush, heapreplace\n\ndef get_inpt(): return sys.stdin.readline().strip()\ndef get_int(): return int(sys.stdin.readline().strip())\ndef get_ints(): return map(int, sys.stdin.readline().strip().split())\ndef get_array(): return list(map(int, sys.stdin.readline().strip().split()))\n\n# sys.setrecursionlimit(10**7)\n# INF = float('inf')\n# MOD1, MOD2 = 10**9+7, 998244353\n\nn, k = get_ints()\n\nfor _ in range(k):\n \n arr = get_array()\n \n for i in reversed(range(n-1)):\n \n if arr[i] < arr[i+1]:\n \n ind = i+1\n minn = arr[i+1]\n for j in range(i+1, n):\n if arr[j] > arr[i]:\n minn = min(arr[j], minn)\n ind = j\n \n arr[i], arr[ind] = arr[ind], arr[i]\n \n arr = arr[:i+1] + sorted(arr[i+1:])\n \n break\n \n print(*arr)\n```","inputs":"3 2\n3 1 2\n2 3 1\n\n","output":"3 2 1\n3 1 2 \n","actual_output":"3 2 1\n3 1 2\n","execution_success":true,"sample_index":899},{"source":"apps","task_type":"verifiable_code","in_source_id":"1305","prompt":"Solve the following coding problem using the programming language python:\n\nDue to the COVID pandemic, there has been an increase in the number of cases if a hospital. The management has decided to clear a large square area for the patients and arrange for beds. But the beds can't be too near to each other.\nThe area is of dimension $N$ x $N$\nThe whole area is already divided into blocks. $1$ means there's a bed in the block, $0$ denotes there isn't. Note, beds placed on consecutive diagonal blocks are safe.\nThis is a SAFE example:\n1 0\n0 1\nThis is an UNSAFE example:\n0 1 1\n0 0 0\n1 0 0\nTo avoid spreading the virus even further, you have to make sure no two adjacent blocks have beds in them. This is done to maintain distance between beds.\nReturn an output of \"SAFE\" if you find the workers have arranged the beds with due consideration to the distance needed. Return \"UNSAFE\" otherwise.\n\n-----Input:-----\n- First line will contain $T$, number of testcases. Then the testcases follow. \n- Next line contains $N$.\n- Next $N$ lines will contain $N$ number of space-separated integers $Ai$ which make denote the beds in the area.\n\n-----Output:-----\nFor each test case, output in a single line whether the total arrangement is \"SAFE\" or \"UNSAFE\". Even if there's a single unsafe bed in the whole area, report the whole area as \"UNSAFE\".\n\n-----Constraints-----\n- $1 \\leq T \\leq 100$\n- $0 \\leq Ai \\leq 1$\n- $2 \\leq N \\leq 100$\n\n-----Subtasks-----\n- 30 points : $1 \\leq N \\leq 7$\n- 70 points : Original constraints\n\n-----Sample Input:-----\n2\n4\n1 0 1 0\n0 0 0 1\n0 1 0 0\n1 0 0 1\n4\n1 0 1 0\n0 0 0 0\n1 0 1 1\n0 1 0 0\n\n-----Sample Output:-----\nSAFE\nUNSAFE\n\n-----EXPLANATION:-----\nBeds placed on blocks diagonally are not a problem.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nres = []\nfor _ in range(int(input())):\n lst = []\n flag = 0\n n = int(input())\n for i in range(n):\n lst.append(list(map(int, input().split())))\n for i in lst:\n for j in range(n-1):\n if i[j] == i[j+1] == 1:\n res.append(\"UNSAFE\")\n flag = 1\n break\n if flag != 0:\n break\n for i in range(n-1):\n for j in range(n):\n if lst[i][j] == lst[i+1] == 1:\n res.append(\"UNSAFE\")\n flag = 1\n break\n if flag != 0:\n break\n if flag == 0:\n res.append(\"SAFE\")\nfor i in res:\n print(i)\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n4\\n1 0 1 0\\n0 0 0 1\\n0 1 0 0\\n1 0 0 1\\n4\\n1 0 1 0\\n0 0 0 0\\n1 0 1 1\\n0 1 0 0\\n', 'output': 'SAFE\\nUNSAFE\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/QTST2020/problems/HOSPBEDS'}","problem_id":"vfc_4062","program":"```python\nres = []\nfor _ in range(int(input())):\n lst = []\n flag = 0\n n = int(input())\n for i in range(n):\n lst.append(list(map(int, input().split())))\n for i in lst:\n for j in range(n-1):\n if i[j] == i[j+1] == 1:\n res.append(\"UNSAFE\")\n flag = 1\n break\n if flag != 0:\n break\n for i in range(n-1):\n for j in range(n):\n if lst[i][j] == lst[i+1] == 1:\n res.append(\"UNSAFE\")\n flag = 1\n break\n if flag != 0:\n break\n if flag == 0:\n res.append(\"SAFE\")\nfor i in res:\n print(i)\n\n```","inputs":"2\n4\n1 0 1 0\n0 0 0 1\n0 1 0 0\n1 0 0 1\n4\n1 0 1 0\n0 0 0 0\n1 0 1 1\n0 1 0 0\n","output":"SAFE\nUNSAFE\n","actual_output":"SAFE\nUNSAFE\n","execution_success":true,"sample_index":900},{"source":"apps","task_type":"verifiable_code","in_source_id":"1306","prompt":"Solve the following coding problem using the programming language python:\n\nYou are given a string S constisting of uppercase Latin letters. Is it possible to reorder the characters in this string to get a string with prefix \"LTIME\" and suffix \"EMITL\"?\nWe remind you that a prefix of a string is any substring which contains its first character, while a suffix of a string is substring containing its last character.\n\n-----Input-----\nThe first line contains a single integer T, denoting the number of testcases. The descriptions of T test cases follow.\nThe first and only line of the test case description has one non-empty string S consisting of uppercase Latin letters only.\n\n-----Output-----\nFor each testcase output a single line containing the string \"YES\" (without quotes) if it's possible to reorder the characters to get the required prefix and suffix, or \"NO\" (without quotes) otherwise.\n\n-----Constraints-----\n- Subtask 1 (23 points) : 1 \u2264 T \u2264 100, 1 \u2264 |S| \u2264 9\n- Subtask 2 (77 points) : 1 \u2264 T \u2264 1000, 1 \u2264 |S| \u2264 100\n\n-----Example-----\nInput:3\nLTIMEAZAZAITLME\nLLLTTTIIIMMMEEEAHA\nLTIMEM\n\nOutput:YES\nYES\nNO\n\n-----Explanation-----\nTest case 1: we can permute the last 5 letters and get LTIMEAZAZAEMITL\nTest case 2: we have 3 copies of each of the letters 'L', 'T', 'I', 'M', 'E' so we can leave 5 of them in the beginning and move 5 of them to the end.\nTest case 3: we have only one letter 'L' so we can't make necessary prefix and suffix at the same time.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\nfrom collections import Counter\nfor i in range(int(input())):\n s=input().upper()\n res=Counter(s)\n if res[\"L\"]>=2 and res[\"T\"]>=2 and res[\"I\"]>=2 and res[\"M\"]>=2 :\n if len(s)==9:\n if res[\"E\"] >=1 :\n print(\"YES\")\n else:\n print(\"NO\")\n elif len(s)>9:\n if res[\"E\"]>=2:\n print(\"YES\")\n else:\n print(\"NO\")\n else:\n print(\"NO\")\n else:\n print(\"NO\")\n \n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\nLTIMEAZAZAITLME\\nLLLTTTIIIMMMEEEAHA\\nLTIMEM\\n', 'output': 'YES\\nYES\\nNO\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/EMITL'}","problem_id":"vfc_4066","program":"```python\n# cook your dish here\nfrom collections import Counter\nfor i in range(int(input())):\n s=input().upper()\n res=Counter(s)\n if res[\"L\"]>=2 and res[\"T\"]>=2 and res[\"I\"]>=2 and res[\"M\"]>=2 :\n if len(s)==9:\n if res[\"E\"] >=1 :\n print(\"YES\")\n else:\n print(\"NO\")\n elif len(s)>9:\n if res[\"E\"]>=2:\n print(\"YES\")\n else:\n print(\"NO\")\n else:\n print(\"NO\")\n else:\n print(\"NO\")\n \n\n```","inputs":"3\nLTIMEAZAZAITLME\nLLLTTTIIIMMMEEEAHA\nLTIMEM\n","output":"YES\nYES\nNO\n","actual_output":"YES\nYES\nNO\n","execution_success":true,"sample_index":901},{"source":"apps","task_type":"verifiable_code","in_source_id":"1307","prompt":"Solve the following coding problem using the programming language python:\n\nAs we all know, F.C. Barcelona is the best soccer team of our era! Their entangling and mesmerizing game style usually translates into very high ball possession, consecutive counter-attack plays and goals. Lots of goals, thanks to the natural talent of their attacker and best player in history, Lionel Andres Messi.\nHowever, at the most prestigious tournament of individual teams, the UEFA Champions League, there are no guarantees and believe it or not, Barcelona is in trouble.... They are tied versus Chelsea, which is a very defending team that usually relies on counter-strike to catch opposing teams off guard and we are in the last minute of the match. So Messi decided to settle things down for good and now he is conducting the ball on his teams' midfield and he will start a lethal counter-attack :D\nAfter dribbling the 2 strikers from Chelsea, he now finds himself near the center of the field and he won't be able to dribble the entire team on his own, so he will need to pass the ball to one of his teammates, run forward and receive the ball once again to score the final goal.\nExactly K players are with him on his counter-attack and the coach, Tito Villanova knows that this counter-attack will end in a goal only if after exactly N passes are performed between the players, Messi ends up with the ball.\n(Note that the ball only needs to end with Messi after exactly N passes are performed between all the K+1 players, i.e. Messi can receive the ball several times during the N passes. See the 2nd test case explanation for further clarification. ) \nHowever, he realized that there are many scenarios possible for this, so he asked you, his assistant coach, to tell him in how many ways can Messi score the important victory goal. So help him!!\n\n-----Input-----\nInput will contain a number T denoting the number of test cases.\nThen T test cases follow, each one consisting of two space-sparated integers N and K.\n\n-----Output-----\nFor each test case, output a single integer, the number of ways the winning play might happen modulo 1000000007 (109+7).\n\n-----Constraints-----\n\n- 1 \u2264 T \u2264 100\n- 2 \u2264 N \u2264 1000\n- 1 \u2264 K \u2264 10\n\n-----Example-----\nInput:\n2\n2 4\n4 2\n\nOutput:\n4\n6\n\n-----Explanation-----\nIn the first test case, say four players with Messi are Xavi, Busquets, Iniesta and Jordi Alba. Then the ways of the winning play to happen when exactly 2 passes are to be performed are:\n1) Messi - Xavi - Messi\n2) Messi - Busquets - Messi\n3) Messi - Iniesta - Messi\n4) Messi - Alba - Messi\n\nIn the second test case, also say that two players with Messi are Xavi and Iniesta. There are 6 ways for the winning play to happen when exactly 4 passes are performed. All the examples of such winning play are:\n1) Messi - Xavi - Messi - Iniesta - Messi\n2) Messi - Xavi - Iniesta - Xavi - Messi\n3) Messi - Xavi - Messi - Xavi - Messi\n4) Messi - Iniesta - Messi - Iniesta - Messi\n5) Messi - Iniesta - Messi - Xavi - Messi\n6) Messi - Iniesta - Xavi - Iniesta - Messi\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nT = int(input())\nfor _ in range(T):\n p,n=map(int,input().split())\n mod = 1000000007\n if p == 2:\n print(n)\n else:\n f=n\n t=n\n for i in range(p-2):\n f=(f%mod*n)%mod\n a=(f-t+mod)%mod\n t=a\n print(a)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n2 4\\n4 2\\n', 'output': '4\\n6\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/FCBARCA'}","problem_id":"vfc_4070","program":"```python\nT = int(input())\nfor _ in range(T):\n p,n=map(int,input().split())\n mod = 1000000007\n if p == 2:\n print(n)\n else:\n f=n\n t=n\n for i in range(p-2):\n f=(f%mod*n)%mod\n a=(f-t+mod)%mod\n t=a\n print(a)\n```","inputs":"2\n2 4\n4 2\n","output":"4\n6\n","actual_output":"4\n6\n","execution_success":true,"sample_index":902},{"source":"apps","task_type":"verifiable_code","in_source_id":"1308","prompt":"Solve the following coding problem using the programming language python:\n\nRaj is suffering from shot term memory loss so he is unable to remember his laptop password but he has a list of some string and the only thing that he remember about his password is alphanumeric and also that all the characters are unique.\nGiven a list of strings, your task is to find a valid password.\n\n-----Input-----\nEach String contains lower case alphabets and 0-9.\n\n-----Output-----\nprint \"Invalid\"(without quotes) if password is not valid else print \"Valid\"(without quotes) and stop processing input after it.\n\n-----Constraints-----\n1<=length of string <=100\n\n-----Example-----\nInput:\nabsdbads\nasdjenfef\ntyerbet\nabc564\n\nOutput:\nInvalid\nInvalid\nInvalid\nValid\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nimport collections\n\nwhile True:\n d = input().strip()\n myCounter = collections.Counter(d)\n flag = 1\n\n for x in list(myCounter.keys()):\n if myCounter[x] > 1:\n flag = 0\n break\n\n isAlp = sum([myCounter[x] for x in list(myCounter.keys()) if x.isalnum()])\n\n if flag and isAlp:\n print(\"Valid\")\n break\n else:\n print(\"Invalid\")\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': 'absdbads\\nasdjenfef\\ntyerbet\\nabc564\\n', 'output': 'Invalid\\nInvalid\\nInvalid\\nValid\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/CYPH2016/problems/LOSTPW'}","problem_id":"vfc_4074","program":"```python\nimport collections\n\nwhile True:\n d = input().strip()\n myCounter = collections.Counter(d)\n flag = 1\n\n for x in list(myCounter.keys()):\n if myCounter[x] > 1:\n flag = 0\n break\n\n isAlp = sum([myCounter[x] for x in list(myCounter.keys()) if x.isalnum()])\n\n if flag and isAlp:\n print(\"Valid\")\n break\n else:\n print(\"Invalid\")\n\n```","inputs":"absdbads\nasdjenfef\ntyerbet\nabc564\n","output":"Invalid\nInvalid\nInvalid\nValid\n","actual_output":"Invalid\nInvalid\nInvalid\nValid\n","execution_success":true,"sample_index":903},{"source":"apps","task_type":"verifiable_code","in_source_id":"1309","prompt":"Solve the following coding problem using the programming language python:\n\nThe 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.\n\n-----Input:-----\n- First-line will contain $T$, the number of test cases. Then the test cases follow. \n- Each test case contains a single line of input, one integer $K$. \n\n-----Output:-----\nFor each test case, output as the pattern.\n\n-----Constraints-----\n- $1 \\leq T \\leq 100$\n- $1 \\leq K \\leq 100$\n\n-----Sample Input:-----\n4\n1\n2\n3\n4\n\n-----Sample Output:-----\n1\n21\n*1\n321\n*21\n**1\n4321\n*321\n**21\n***1\n\n-----EXPLANATION:-----\nNo need, else pattern can be decode easily.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfor _ in range(int(input())):\r\n n = int(input())\r\n s = [str(i) for i in range(n,0,-1)]\r\n for i in range(n):\r\n print('*'*i+''.join(s))\r\n del(s[0])\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '4\\n1\\n2\\n3\\n4\\n', 'output': '1\\n21\\n*1\\n321\\n*21\\n**1\\n4321\\n*321\\n**21\\n***1\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/PTRN2020/problems/ITGUY37'}","problem_id":"vfc_4078","program":"```python\nfor _ in range(int(input())):\r\n n = int(input())\r\n s = [str(i) for i in range(n,0,-1)]\r\n for i in range(n):\r\n print('*'*i+''.join(s))\r\n del(s[0])\n```","inputs":"4\n1\n2\n3\n4\n","output":"1\n21\n*1\n321\n*21\n**1\n4321\n*321\n**21\n***1\n","actual_output":"1\n21\n*1\n321\n*21\n**1\n4321\n*321\n**21\n***1\n","execution_success":true,"sample_index":904},{"source":"apps","task_type":"verifiable_code","in_source_id":"1310","prompt":"Solve the following coding problem using the programming language python:\n\nBohan loves milk tea so much and he drinks one cup of milk tea every day. The local shop sells milk tea in two sizes: a Medium cup for $3 and a Large cup for $4. For every cup of milk tea purchased Bohan receives a promotional stamp. Bohan may redeem 6 stamps for a free drink of milk tea regardless of the size. No stamp will be given for a free drink.\n\n\nDetermine the amount of money Bohan have spent on milk tea, given a sequence of milk tea sizes he got in the past a few days. Assume Bohan had no stamps in the beginning and he always redeemed the stamps for the next drink once he had collected 6 stamps.\n\n-----Input-----\nThe input begins with the number of test cases T.\nEach test case has a single line of letters. The i-th letter is either 'M' or 'L' denoting a Medium cup or a Large cup of milk tea Bohan got on the i-th day.\n\n-----Output-----\nFor each case, output the amount of money in dollars Bohan have spent on milk tea.\n\n-----Constraints-----\n- T \u2264 100 \n- 1 \u2264 length of each sequence \u2264 100 \n\n-----Example-----\nInput:\n3\nMLM\nMMLLMMLL\nMMMMMMML\n\nOutput:\n10\n24\n22\n\n-----Explanation-----\nExample 1: Bohan didn't redeem any stamps.\nExample 2: Bohan redeemed 6 stamps for the Large cup of milk tea on the 7th day.\nExample 3: Bohan redeemed 6 stamps for the Medium cup of milk tea on the 7th day.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nt = int(input())\nfor tc in range(t):\n seq = input()\n dollar = 0\n stamp = 0\n for ct in seq:\n if stamp >= 6:\n stamp -= 6\n continue\n elif ct == 'M':\n dollar += 3\n elif ct == 'L':\n dollar += 4\n stamp += 1\n print(dollar)\n\n\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\nMLM\\nMMLLMMLL\\nMMMMMMML\\n', 'output': '10\\n24\\n22\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/NUPNMR15/problems/NYUMTEA'}","problem_id":"vfc_4082","program":"```python\nt = int(input())\nfor tc in range(t):\n seq = input()\n dollar = 0\n stamp = 0\n for ct in seq:\n if stamp >= 6:\n stamp -= 6\n continue\n elif ct == 'M':\n dollar += 3\n elif ct == 'L':\n dollar += 4\n stamp += 1\n print(dollar)\n\n\n\n```","inputs":"3\nMLM\nMMLLMMLL\nMMMMMMML\n","output":"10\n24\n22\n","actual_output":"10\n24\n22\n","execution_success":true,"sample_index":905},{"source":"apps","task_type":"verifiable_code","in_source_id":"1311","prompt":"Solve the following coding problem using the programming language python:\n\nYou are given two positive integers $N$ and $K$, where $K \\le N$. Find a sequence $A_1, A_2, \\ldots, A_N$ such that:\n- for each valid $i$, $A_i$ is either $i$ or $-i$\n- there are exactly $K$ values of $i$ such that $1 \\le i \\le N$ and $A_1 + A_2 + \\ldots + A_i > 0$\nIf there are multiple solutions, you may print any one of them. It can be proved that at least one solution always exists.\n\n-----Input-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The first and only line of each test case contains two space-separated integers $N$ and $K$.\n\n-----Output-----\nFor each test case, print a single line containing $N$ space-separated integers $A_1, A_2, \\ldots, A_N$.\n\n-----Constraints-----\n- $1 \\le T \\le 1,000$\n- $1 \\le K \\le N \\le 1,000$\n\n-----Subtasks-----\nSubtask #1 (10 points): $N \\le 10$\nSubtask #2 (90 points): original constraints\n\n-----Example Input-----\n1\n3 3\n\n-----Example Output-----\n1 2 3\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\ntest=int(input())\nfor i in range(test):\n n,k=map(int,input().split())\n x=n-k\n for j in range(1,n+1):\n if(j%2==0 and x>0):\n print(-j,end=' ')\n x-=1\n elif(k<=0):\n print(-j,end=' ')\n else:\n print(j,end=' ')\n k-=1\n print()\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n3 3\\n', 'output': '1 2 3\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/POSPREFS'}","problem_id":"vfc_4086","program":"```python\ntest=int(input())\nfor i in range(test):\n n,k=map(int,input().split())\n x=n-k\n for j in range(1,n+1):\n if(j%2==0 and x>0):\n print(-j,end=' ')\n x-=1\n elif(k<=0):\n print(-j,end=' ')\n else:\n print(j,end=' ')\n k-=1\n print()\n```","inputs":"1\n3 3\n","output":"1 2 3\n","actual_output":"1 2 3 \n","execution_success":true,"sample_index":906},{"source":"apps","task_type":"verifiable_code","in_source_id":"1312","prompt":"Solve the following coding problem using the programming language python:\n\nChef recently saw the movie Matrix. He loved the movie overall but he didn't agree with some things in it. Particularly he didn't agree with the bald boy when he declared - There is no spoon. Being a chef, he understands the importance of the spoon and realizes that the universe can't survive without it. Furthermore, he is sure there is a spoon; he saw it in his kitchen this morning. So he has set out to prove the bald boy is wrong and find a spoon in the matrix. He has even obtained a digital map already. Can you help him?\n\nFormally you're given a matrix of lowercase and uppercase Latin letters. Your job is to find out if the word \"Spoon\" occurs somewhere in the matrix or not. A word is said to be occurred in the matrix if it is presented in some row from left to right or in some column from top to bottom. Note that match performed has to be case insensitive. \n\n-----Input-----\nThe first line of input contains a positive integer T, the number of test cases. After that T test cases follow. The first line of each test case contains two space separated integers R and C, the number of rows and the number of columns of the matrix M respectively. Thereafter R lines follow each containing C characters, the actual digital map itself.\n\n-----Output-----\nFor each test case print one line. If a \"Spoon\" is found in Matrix, output \"There is a spoon!\" else output \"There is indeed no spoon!\" (Quotes only for clarity).\n\n-----Constraints-----\n\n1 \u2264 T \u2264 100\n\n1 \u2264 R, C \u2264 100\n\n-----Sample Input-----\n3\n3 6\nabDefb\nbSpoon\nNIKHil\n6 6\naaaaaa\nssssss\nxuisdP\noooooo\nioowoo\nbdylan\n6 5\nbdfhj\ncacac\nopqrs\nddddd\nindia\nyucky\n\n-----Sample Output-----\nThere is a spoon!\nThere is a spoon!\nThere is indeed no spoon!\n\n-----Explanation-----\nIn the first test case, \"Spoon\" occurs in the second row. In the second test case, \"spOon\" occurs in the last column.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nimport sys\n\nspoon = [ \"SPOON\", \"spoon\" ]\n\ndef main():\n try:\n tc=int(input())\n while tc>0:\n tc=tc-1\n [r,c] = input().split()\n r=int(r)\n c=int(c)\n k=0\n flag=0\n matrix=[0]*r\n i=0\n while i0:\n tc=tc-1\n [r,c] = input().split()\n r=int(r)\n c=int(c)\n k=0\n flag=0\n matrix=[0]*r\n i=0\n while i 1 such that x is a divisor of all integers from array A. More formally, this x should satisfy the following relations:\n\nA[1] mod x = 0, A[2] mod x = 0, ..., A[N] mod x = 0,\n\nwhere mod stands for the modulo operation. For example, 8 mod 3 = 2, 2 mod 2 = 0, 100 mod 5 = 0 and so on. If such number does not exist, output -1.\n\n-----Input-----\n\nThe first line of the input contains a single integer T, the number of test cases. T test cases follow. The first line of each test case contains a single integer N, the size of the array A for the corresponding test case. The second line contains N space separated integers A[1], A[2], ..., A[N].\n\n-----Output-----\n\nFor each test case output a single line containing the answer for the corresponding test case.\n\n-----Constraints-----\n1 \u2264 T \u2264 100000\n\n1 \u2264 N \u2264 100000\n\nThe sum of values of N in each test file does not exceed 100000\n\n1 \u2264 A[i] \u2264 100000\n\n-----Example-----\nInput:\n2\n3\n2 4 8\n3\n4 7 5\n\nOutput:\n2\n-1\n\n-----Explanation-----\nCase 1. Clearly 2 is a divisor of each of the numbers 2, 4 and 8. Since 2 is the least number greater than 1 then it is the answer.\n\nCase 2. Let's perform check for several first values of x.\n\nx4 mod x7 mod x5 mod x20113112403154206415740584759475\n\nAs we see each number up to 9 does not divide all of the numbers in the array. Clearly all larger numbers also will fail to do this. So there is no such number x > 1 and the answer is -1.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfrom math import sqrt,gcd\n\nfor _ in range(int(input())):\n n=int(input())\n ar=[int(x) for x in input().split()]\n g=ar[0]\n for i in range(1,n):\n g=gcd(g,ar[i])\n \n f=g\n for i in range(2,int(sqrt(g))+1):\n if g%i==0:\n f=i\n break\n if g!=1:\n print(f)\n else:\n print(-1)\n \n \n \n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n3\\n2 4 8\\n3\\n4 7 5\\n\\n\\n', 'output': '2\\n-1\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/LEDIV'}","problem_id":"vfc_4094","program":"```python\nfrom math import sqrt,gcd\n\nfor _ in range(int(input())):\n n=int(input())\n ar=[int(x) for x in input().split()]\n g=ar[0]\n for i in range(1,n):\n g=gcd(g,ar[i])\n \n f=g\n for i in range(2,int(sqrt(g))+1):\n if g%i==0:\n f=i\n break\n if g!=1:\n print(f)\n else:\n print(-1)\n \n \n \n```","inputs":"2\n3\n2 4 8\n3\n4 7 5\n\n\n","output":"2\n-1\n","actual_output":"2\n-1\n","execution_success":true,"sample_index":908},{"source":"apps","task_type":"verifiable_code","in_source_id":"1314","prompt":"Solve the following coding problem using the programming language python:\n\nDevu and Churu love to play games a lot. Today, they have an array A consisting of N positive integers. First they listed all N \u00d7 (N+1) / 2 non-empty continuous subarrays of the array A on a piece of paper and then replaced all the subarrays on the paper with the maximum element present in the respective subarray.\nDevu and Churu decided to play a game with numbers on the paper. They both have decided to make moves turn by turn. In one turn, the player picks some number from the list and discards that number. The one who is not able to make a valid move will be the loser. To make the game more interesting, they decided to put some constraints on their moves.\nA constraint on a game can be any of following three types :\n- > K : They are allowed to choose numbers having values strictly greater than K only.\n- < K : They are allowed to choose numbers having values strictly less than K only.\n- = K : They are allowed to choose numbers having values equal to K only.\n\nGiven M constraints and who goes first, you have to tell the outcome of each game. Print 'D' if Devu wins otherwise print 'C' without quotes.\nNote that M games are independent, that is, they'll rewrite numbers by using array A after each game. (This is the task for the loser of the previous game!)\n\n-----Input -----\nFirst line of input contains two space separated integers N and M denoting the size of array A and number of game played by them. Next line of input contains N space-separated integers denoting elements of array A. Each of the next M lines of input contains three space-separated parameters describing a game. First two parameter are a character C \u2208 {<, >, =} and an integer K denoting the constraint for that game. The last parameter is a character X \u2208 {D, C} denoting the player who will start the game. \n\n----- Output -----\nOutput consists of a single line containing a string of length M made up from characters D and C only, where ith character in the string denotes the outcome of the ith game.\n\n----- Constraints: -----\n- 1 \u2264 N, M \u2264 106\n- 1 \u2264 Ai, K \u2264 109 \n- X \u2208 {D, C}\n- C \u2208 {<, >, =}\n\n-----Subtasks: -----\n- Subtask 1 : 1 \u2264 N, M \u2264 104 : ( 20 pts )\n- Subtask 2 : 1 \u2264 N, M \u2264 105 : ( 30 pts )\n- Subtask 3 : 1 \u2264 N, M \u2264 106 : ( 50 pts )\n\n-----Example:-----\nInput:\n3 5\n1 2 3\n> 1 D\n< 2 C\n= 3 D\n> 4 C\n< 5 D\n\nOutput:\nDCDDC\n\n-----Explanation: -----\nSubarray List :\n- [1]\n\n- [2]\n\n- [3]\n\n- [1,2]\n\n- [2,3]\n\n- [1,2,3]\n\nNumbers on the paper after replacement :\n\n- [1]\n\n- [2]\n\n- [3]\n\n- [2]\n\n- [3]\n\n- [3]\n\nGame 1 : There are only 5 numbers > 1 in the list.\nGame 2 : There is only 1 number < 2 in the list.\nGame 3 : There are only 3 numbers = 3 in the list.\nGame 4 : There are no numbers > 4 in the list. So the first player cannot make his move.\nGame 5 : There are 6 numbers < 5 in the list.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\ndef left_span(arr,n):\n ans=[0]\n span=[0]\n for i in range(1,n):\n \n while span and arr[i]>arr[span[-1]]:\n span.pop()\n \n if not span:\n ans.append(0)\n \n else:\n ans.append(span[-1]+1)\n span.append(i)\n return ans\n\ndef right_span(arr,n):\n ans=[n+1]\n span=[n-1]\n for i in range(n-2,-1,-1):\n \n while span and arr[i]>=arr[span[-1]]:\n span.pop()\n \n if not span:\n ans.append(n+1)\n else:\n ans.append(span[-1]+1)\n span.append(i)\n return ans[::-1]\nfrom collections import Counter\nfrom bisect import bisect_left,bisect_right\nfrom operator import itemgetter\nn,q=list(map(int,input().split( )))\narr=list(map(int,input().split( )))\n\nleft=left_span(arr,n)\nright=right_span(arr,n)\nc=Counter()\nfor i in range(n):\n c[arr[i]]+=(right[i]-(i+1))*(i+1-left[i])\na=sorted(c)\nf=[]\nfor v in a:\n f.append(c[v])\nprefix_sum=[f[0]]\nn=len(f)\nfor i in range(1,n):\n prefix_sum.append(f[i]+prefix_sum[-1])\nr=[0]*q\nfor i in range(q):\n sign,k,player=list(map(str,input().split( )))\n k=int(k)\n if sign==\"=\":\n if k in c:\n res=c[k]\n else:\n res=0\n elif sign==\">\":\n j=bisect_left(a,k)\n if j==n:\n res=0\n elif a[j]==k:\n res=prefix_sum[-1] - prefix_sum[j]\n else:\n if j>0:\n res=prefix_sum[-1] - prefix_sum[j-1]\n else:\n res=prefix_sum[-1]\n else:\n j=bisect_left(a,k)\n if j==0:\n res=0\n else:\n res=prefix_sum[j-1]\n \n if res%2==0:\n if player==\"D\":\n r[i]=\"C\"\n else:\n r[i]=\"D\"\n else:\n r[i]=player\nprint(''.join(r))\n \n \n\n\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3 5\\n1 2 3\\n> 1 D\\n< 2 C\\n= 3 D\\n> 4 C\\n< 5 D\\n', 'output': 'DCDDC\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/DCGAME'}","problem_id":"vfc_4098","program":"```python\ndef left_span(arr,n):\n ans=[0]\n span=[0]\n for i in range(1,n):\n \n while span and arr[i]>arr[span[-1]]:\n span.pop()\n \n if not span:\n ans.append(0)\n \n else:\n ans.append(span[-1]+1)\n span.append(i)\n return ans\n\ndef right_span(arr,n):\n ans=[n+1]\n span=[n-1]\n for i in range(n-2,-1,-1):\n \n while span and arr[i]>=arr[span[-1]]:\n span.pop()\n \n if not span:\n ans.append(n+1)\n else:\n ans.append(span[-1]+1)\n span.append(i)\n return ans[::-1]\nfrom collections import Counter\nfrom bisect import bisect_left,bisect_right\nfrom operator import itemgetter\nn,q=list(map(int,input().split( )))\narr=list(map(int,input().split( )))\n\nleft=left_span(arr,n)\nright=right_span(arr,n)\nc=Counter()\nfor i in range(n):\n c[arr[i]]+=(right[i]-(i+1))*(i+1-left[i])\na=sorted(c)\nf=[]\nfor v in a:\n f.append(c[v])\nprefix_sum=[f[0]]\nn=len(f)\nfor i in range(1,n):\n prefix_sum.append(f[i]+prefix_sum[-1])\nr=[0]*q\nfor i in range(q):\n sign,k,player=list(map(str,input().split( )))\n k=int(k)\n if sign==\"=\":\n if k in c:\n res=c[k]\n else:\n res=0\n elif sign==\">\":\n j=bisect_left(a,k)\n if j==n:\n res=0\n elif a[j]==k:\n res=prefix_sum[-1] - prefix_sum[j]\n else:\n if j>0:\n res=prefix_sum[-1] - prefix_sum[j-1]\n else:\n res=prefix_sum[-1]\n else:\n j=bisect_left(a,k)\n if j==0:\n res=0\n else:\n res=prefix_sum[j-1]\n \n if res%2==0:\n if player==\"D\":\n r[i]=\"C\"\n else:\n r[i]=\"D\"\n else:\n r[i]=player\nprint(''.join(r))\n \n \n\n\n\n```","inputs":"3 5\n1 2 3\n> 1 D\n< 2 C\n= 3 D\n> 4 C\n< 5 D\n","output":"DCDDC\n","actual_output":"DCDDC\n","execution_success":true,"sample_index":909},{"source":"apps","task_type":"verifiable_code","in_source_id":"1315","prompt":"Solve the following coding problem using the programming language python:\n\n-----\nRANJANA QUIZ\n-----\n\nProf. Ranjana decided to conduct a quiz in her class. She divided all the students of her\nclass into groups of three. Consider that no student was left out after the division. She gave\ndifferent sets of questions to every group. A set is said to be unique if there is no other team that\nreceived the same number of maths, science and english questions. In every set, maximum\nquestions for each group were related to maths, then science, and the least number of\nquestions were related to English. Total number of questions given to each team can be\ndifferent. \n\n\t\n\t\n\nAfter the test, the CR of the class asked every team to report the number of questions\nthey got on each subject. The CR wants to know the number of unique sets of questions that\nwere given to the teams, the problem is that all the students have just submitted the number of\nquestions of each subject but in no particular order. Help the CR to find the number of unique\nsets\n\n\t\t\n\t\t\n\n-----Input Format-----\n\nLine 1 contains the number of teams \u2018n\u2019. In the next n lines, each line contains three space separated integers,i.e, the number of questions of each subject(in no particular order).\nemployee\n\n-----Output-----\n\nPrint the number of unique sets\n\n\t\t\n\t\t\n\n-----Example Text Case-----\nInput:\n\n5\n6 5 4\n2 3 7\n4 6 5\n7 2 3\n5 3 1\n\t\nOutput:\n1\n\t\t\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nn=int(input())\nl=[]\ncount=0\nwhile n:\n n-=1\n a,b,c=sorted(map(int,input().split()))\n if (a,b,c) in l:\n count-=1\n else:\n l.append((a,b,c))\n count+=1\nprint(count)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '5\\n6 5 4\\n2 3 7\\n4 6 5\\n7 2 3\\n5 3 1\\n', 'output': '1\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/APO12020/problems/APOC2_01'}","problem_id":"vfc_4102","program":"```python\nn=int(input())\nl=[]\ncount=0\nwhile n:\n n-=1\n a,b,c=sorted(map(int,input().split()))\n if (a,b,c) in l:\n count-=1\n else:\n l.append((a,b,c))\n count+=1\nprint(count)\n```","inputs":"5\n6 5 4\n2 3 7\n4 6 5\n7 2 3\n5 3 1\n","output":"1\n","actual_output":"1\n","execution_success":true,"sample_index":910},{"source":"apps","task_type":"verifiable_code","in_source_id":"1316","prompt":"Solve the following coding problem using the programming language python:\n\nYou are given a weighted undirected graph consisting of n$n$ nodes and m$m$ edges. The nodes are numbered from 1$1$ to n$n$. The graph does not contain any multiple edges or self loops.\nA walk W$W$ on the graph is a sequence of vertices (with repetitions of vertices and edges allowed) such that every adjacent pair of vertices in the sequence is an edge of the graph. We define the cost of a walk W$W$, Cost(W)$Cost(W)$, as the maximum over the weights of the edges along the walk. \nYou will be given q$q$ queries. In each query, you will be given an integer X$X$.\n\nYou have to count the number of different walks W$W$ of length 4$4$ such that Cost(W)$Cost(W)$ = X$X$.\n\nTwo walks are considered different if they do not represent the same edge sequence.\n\n-----Input:-----\n- First line contains 2 integers : the number of nodes n$n$ and number of edges m$m$.\n- Next m$m$ lines each describe u$u$, v$v$ and w$w$, describing an edge between u$u$ and v$v$ with weight w$w$.\n- Next line contains q$q$, the number of queries.\n- Next q$q$ lines each describe an integer X$X$ - the cost of the walk in the query.\n\n-----Output:-----\nFor each query, output in a single line the number of different possible walks.\n\n-----Constraints-----\n- 1\u2264n\u2264100$1 \\leq n \\leq 100$\n- 1\u2264m\u2264n(n\u22121)2$1 \\leq m \\leq \\frac{n (n-1)}{2}$\n- 1\u2264u,v\u2264n$1 \\leq u, v \\leq n$\n- 1\u2264w\u2264100$1 \\leq w \\leq 100$\n- 1\u2264q\u2264100$1 \\leq q \\leq 100$\n- 1\u2264X\u2264100$1 \\leq X \\leq 100$\n\n-----Sample Input:-----\n3 3\n1 2 1\n2 3 2\n3 1 3\n3\n1\n2\n3\n\n-----Sample Output:-----\n2\n10\n36\n\n-----EXPLANATION:-----\nFor X=2$X = 2$, all possible 10$10$ walks are listed below :\n- 1 -> 2 -> 1 -> 2 -> 3\n- 1 -> 2 -> 3 -> 2 -> 1\n- 1 -> 2 -> 3 -> 2 -> 3\n- 2 -> 1 -> 2 -> 3 -> 2\n- 2 -> 3 -> 2 -> 1 -> 2\n- 2 -> 3 -> 2 -> 3 -> 2\n- 3 -> 2 -> 1 -> 2 -> 1\n- 3 -> 2 -> 1 -> 2 -> 3\n- 3 -> 2 -> 3 -> 2 -> 1\n- 3 -> 2 -> 3 -> 2 -> 3\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\nfrom collections import defaultdict\n\nclass sol():\n def __init__(self,n,edges):\n self.n = n\n self.edges = edges\n self.graph = self.create_graph()\n self.precompute()\n \n def create_graph(self):\n graph = defaultdict(list)\n for e in self.edges:\n u = e[0]\n v = e[1]\n w = e[2]\n graph[u].append([v,w])\n graph[v].append([u,w])\n return graph\n \n def precompute(self):\n self.maxiedges = [0]*6\n self.B = [[0 for i in range(101)] for i in range(101)]\n def func(u,v,l):\n if l==2:\n self.B[u][self.maxiedges[l]] += 1\n else:\n for j in self.graph[v]:\n self.maxiedges[l+1] = max(self.maxiedges[l],j[1])\n func(u,j[0],l+1)\n for i in range(1,self.n+1):\n func(i,i,0)\n \n def paths(self,X):\n freq = 0\n for u in range(1,self.n+1):\n for x in range(X+1):\n freq += 2*self.B[u][X]*self.B[u][x]\n freq -= self.B[u][X]*self.B[u][X]\n return freq\n \nn, m = map(int, input().split())\nedges = []\nwhile m:\n uvw = list(map(int, input().split()))\n edges.append(uvw)\n m -= 1\nq = int(input())\nGraph = sol(n,edges)\nwhile q:\n query = int(input())\n print(Graph.paths(query))\n q -= 1\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3 3\\n1 2 1\\n2 3 2\\n3 1 3\\n3\\n1\\n2\\n3\\n', 'output': '2\\n10\\n36\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/WALK4'}","problem_id":"vfc_4106","program":"```python\n# cook your dish here\nfrom collections import defaultdict\n\nclass sol():\n def __init__(self,n,edges):\n self.n = n\n self.edges = edges\n self.graph = self.create_graph()\n self.precompute()\n \n def create_graph(self):\n graph = defaultdict(list)\n for e in self.edges:\n u = e[0]\n v = e[1]\n w = e[2]\n graph[u].append([v,w])\n graph[v].append([u,w])\n return graph\n \n def precompute(self):\n self.maxiedges = [0]*6\n self.B = [[0 for i in range(101)] for i in range(101)]\n def func(u,v,l):\n if l==2:\n self.B[u][self.maxiedges[l]] += 1\n else:\n for j in self.graph[v]:\n self.maxiedges[l+1] = max(self.maxiedges[l],j[1])\n func(u,j[0],l+1)\n for i in range(1,self.n+1):\n func(i,i,0)\n \n def paths(self,X):\n freq = 0\n for u in range(1,self.n+1):\n for x in range(X+1):\n freq += 2*self.B[u][X]*self.B[u][x]\n freq -= self.B[u][X]*self.B[u][X]\n return freq\n \nn, m = map(int, input().split())\nedges = []\nwhile m:\n uvw = list(map(int, input().split()))\n edges.append(uvw)\n m -= 1\nq = int(input())\nGraph = sol(n,edges)\nwhile q:\n query = int(input())\n print(Graph.paths(query))\n q -= 1\n\n```","inputs":"3 3\n1 2 1\n2 3 2\n3 1 3\n3\n1\n2\n3\n","output":"2\n10\n36\n","actual_output":"2\n10\n36\n","execution_success":true,"sample_index":911},{"source":"apps","task_type":"verifiable_code","in_source_id":"1317","prompt":"Solve the following coding problem using the programming language python:\n\nChef just come up with a very good idea for his business. He needs to hire two group of software engineers. Each group of engineers will work on completely different things and people from different groups don't want to disturb (and even hear) each other. Chef has just rented a whole floor for his purposes in business center \"Cooking Plaza\". The floor is a rectangle with dimensions N over M meters. For simplicity of description the floor's structure, let's imagine that it is split into imaginary squares of size 1x1 called \"cells\".\nThe whole floor is split into rooms (not necessarily rectangular). There are some not noise-resistant walls between some of the cells. Two adjacent cells belong to the same room if they don't have the wall between them. Cells are considered adjacent if and only if they share an edge. Also, we say that relation \"belong to the same room\" is transitive. In other words we say that if cells A and B belong to the same room and B and C belong to the same room then A and C belong to the same room.\nSo we end up having a partition of the floor into rooms. It also means, that each point on the floor belongs to some room.\nChef have to distribute the rooms between engineers of two groups. Engineers from the different groups cannot seat in the same room. If engineers from a different groups seat in adjacent rooms, the walls these rooms share have to be noise-resistant. The cost of having one meter of wall isolated is K per month. Due to various reasons Chef has to pay an additional cost for support of each of the room (e.g. cleaning costs money as well). Interesting to know that support cost for a particular room may differ depending on engineers of which group seat in this room.\nChef doesn't know the number of people he needs in each group of engineers so he wants to minimize the money he needs to pay for all the floor rent and support. He will see how it goes and then redistribute the floor or find another floor to rent or whatever. Either way, you don't need to care about this.\nPlease pay attention to the restriction that all the rooms should be occupied by engineers of one of the teams. Also, it might happen that all the rooms will be assigned to the same team and this is completely okay.\n\n-----Input-----\nThe first line of the input contains three integers N, M, W, K and R, where N and M denote size of the floor, W denote number of one-meter-length walls, K denote cost of having one-meter-length wall be noise-resistant and R denote the number of rooms in which floor is partitioned.\nNext W lines contain four integers each X1, Y1, X2, Y2. This means that cells with coordinates X1, Y1 and X2, Y2 have a wall between them. It's guaranteed that this cells share an edge.\nNext R lines will contain four space separated integers each X, Y, C1, C2. This should be treated as support cost per month in a room that contain cell X, Y is C1 for first group of engineers and C2 for second group of engineers. It's guaranteed that all of cells among these R cells belong to different rooms. All coordinates are indexed starting from 1.\n\n-----Output-----\nOutput a single integer - sum of the rent and support costs per month.\n\n-----Constraints-----\n- 1 \u2264 N, M \u2264 1000\n- 1 \u2264 W \u2264 min(2*N*M, 150000)\n- 1 \u2264 X1 \u2264 N\n- 1 \u2264 Y1 \u2264 M\n- 1 \u2264 X2 \u2264 N\n- 1 \u2264 Y2 \u2264 M\n- 1 \u2264 K \u2264 10000\n- 1 \u2264 C1, C2 \u2264 10000\n- Limitations on R is described in subtasks section.\n\n-----Subtasks-----\n- Subtask #1 [30 points]: 1 \u2264 R \u2264 50\n- Subtask #2 [70 points]: 1 \u2264 R \u2264 500\n\n-----Example-----\nInput:\n2 4 5 5 3\n1 2 1 3\n1 2 2 2\n1 3 2 3\n1 4 2 4\n2 1 2 2\n1 1 30 12\n1 3 10 15\n2 3 11 22\nOutput:\n48\n\n-----Explanation-----\nHere's the scheme of the floor\nThe correct assignment is the following.\n\n- The blue color denotes assignment to the first team. Total cost for renting two rooms for this team is 11 + 10 = 21.\n- The red color denotes assignment to the second team. Total cost for renting the only room for the team is 12.\n- There are 3 meters of walls between them, resulting in isolating cost of 15.\nThe grand total is 21 + 12 + 15 = 48\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nimport sys\n \ndef findRoom(x,y,i):\n R = [(x,y)]\n GRID[x][y] = i\n for n in R:\n GRID[n[0]][n[1]] = i\n if n[0]>0 and GRID[n[0]-1][n[1]]==0 and H[n[0]-1][n[1]]:\n GRID[n[0]-1][n[1]] = i\n R.append((n[0]-1,n[1]))\n if n[0]0 and GRID[n[0]][n[1]-1]==0 and V[n[0]][n[1]-1]:\n GRID[n[0]][n[1]-1] = i\n R.append((n[0],n[1]-1))\n if n[1]Rooms[r][1])\n Stable[r] = True\ndef try_teams():\n for r in range(R):\n if not Stable[r]:\n T[r] = 1+(r&1)\n change = True\n while change:\n change = False\n for r in range(R):\n price = roomPrice(r)\n if price[T[r]-1]>price[2-T[r]]:\n T[r] = 3-T[r]\n change = True\n print(total_price())\n#try_teams() \nprint(solve(0))\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2 4 5 5 3\\n1 2 1 3\\n1 2 2 2\\n1 3 2 3\\n1 4 2 4\\n2 1 2 2\\n1 1 30 12\\n1 3 10 15\\n2 3 11 22\\n', 'output': '48\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/MARCH16/problems/FLOORDIS'}","problem_id":"vfc_4110","program":"```python\nimport sys\n \ndef findRoom(x,y,i):\n R = [(x,y)]\n GRID[x][y] = i\n for n in R:\n GRID[n[0]][n[1]] = i\n if n[0]>0 and GRID[n[0]-1][n[1]]==0 and H[n[0]-1][n[1]]:\n GRID[n[0]-1][n[1]] = i\n R.append((n[0]-1,n[1]))\n if n[0]0 and GRID[n[0]][n[1]-1]==0 and V[n[0]][n[1]-1]:\n GRID[n[0]][n[1]-1] = i\n R.append((n[0],n[1]-1))\n if n[1]Rooms[r][1])\n Stable[r] = True\ndef try_teams():\n for r in range(R):\n if not Stable[r]:\n T[r] = 1+(r&1)\n change = True\n while change:\n change = False\n for r in range(R):\n price = roomPrice(r)\n if price[T[r]-1]>price[2-T[r]]:\n T[r] = 3-T[r]\n change = True\n print(total_price())\n#try_teams() \nprint(solve(0))\n\n```","inputs":"2 4 5 5 3\n1 2 1 3\n1 2 2 2\n1 3 2 3\n1 4 2 4\n2 1 2 2\n1 1 30 12\n1 3 10 15\n2 3 11 22\n","output":"48\n","actual_output":"48\n","execution_success":true,"sample_index":912},{"source":"apps","task_type":"verifiable_code","in_source_id":"1318","prompt":"Solve the following coding problem using the programming language python:\n\nYou are given an equilateral triangle \u0394ABC with the side BC being the base. Each side of the triangle is of length L. There are L-1 additional points on each of the sides dividing the sides into equal parts of unit lengths. Points on the sides of the triangle are called major points. Joining these points with lines parallel to the sides of \u0394ABC will produce some more equilateral triangles. The intersection points of these parallel lines are called minor points. \n\nLook at the picture below. It contains \n\n- Major points: A, B, C, P1, P2, Q1, Q3, R1, R4, S1, S2, S3 (note that we consider A, B, C as major points as well)\n- Minor points: Q2, R2, R3\n- Equilateral triangles \u0394P1Q1Q2, \u0394Q2S1S3, etc\n\nWe consider an equilateral triangle to be valid if\n\n- Each of its vertices is either a major or a minor point, and\n- The distance from its base (the base of a triangle is the side parallel to BC) to BC is less than the distance from the other vertex of the triangle (i.e. opposite vertex that doesn't lie on the base of triangle) to BC.\n\nIn the figure above, \u0394Q2P1P2 is not a valid triangle but \u0394Q2R2R3 is a valid triangle.\n\nYou will be given L, the length of the original triangle \u0394ABC. You need to find out the number of valid equilateral triangles with side length exactly K.\n\n-----Input-----\n- The first line of the input contains an integer T denoting the number of test cases. The description of each testcase follows.\n- Each test case has one line containing two space-separated integers: L and K.\n\n-----Output-----\nFor each testcase, print \"Case i: \", and then the answer, where i is the testcase number, 1-indexed.\n\n-----Constraints-----\n- 1 \u2264 T \u2264 500\n- 1 \u2264 L, K \u2264 5000\n\n-----Example-----\nInput:\n2\n4 3\n4 4\n\nOutput:\nCase 1: 3\nCase 2: 1\n\n-----Explanation-----\n\nThe figure presented in the problem description is a triangle with side length 4.\nIn testcase 1, the valid triangles are \u0394AR1R4, \u0394P1BS3, \u0394P2S1C\n\nIn testcase 2, the only valid triangle is \u0394ABC\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\ntry:\n\n for j in range(1,int(input())+1):\n n,k = map(int,input().split())\n\n if k>n:\n c=0\n else:\n c = n-k+1\n\n s = c*(c+1)//2\n print('Case', str(j)+':',s)\nexcept:\n pass\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n4 3\\n4 4\\n', 'output': 'Case 1: 3\\nCase 2: 1\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/ZUBTRCNT'}","problem_id":"vfc_4114","program":"```python\ntry:\n\n for j in range(1,int(input())+1):\n n,k = map(int,input().split())\n\n if k>n:\n c=0\n else:\n c = n-k+1\n\n s = c*(c+1)//2\n print('Case', str(j)+':',s)\nexcept:\n pass\n```","inputs":"2\n4 3\n4 4\n","output":"Case 1: 3\nCase 2: 1\n","actual_output":"Case 1: 3\nCase 2: 1\n","execution_success":true,"sample_index":913},{"source":"apps","task_type":"verifiable_code","in_source_id":"1319","prompt":"Solve the following coding problem using the programming language python:\n\nA despotic king decided that his kingdom needed to be rid of corruption and disparity. He called his prime minister and ordered that all corrupt citizens be put to death. Moreover, he wanted this done quickly.\nThe wily prime minister realised that investigating every citizen to decide who was corrupt and who was not was rather difficult. So he decided on the following plan: He ordered all the citizens to appear in the court one by one and declare their wealth.\nThe king does not sit in the court all the time (he has other important business to attend to - for instance, meet dignitaries from neighbouring kingdoms, spend time with his family \u2026) Whenever the king walks into the court, the prime minister pulls out the richest man who has appeared before the court so far and is still alive and beheads him for being corrupt. Since the rich are more likely to be corrupt, he hopes to get rid of most of the corrupt and the king is happy as he sees his policy being implemented enthusiastically.\nSuppose the wealth of the citizens trooping into the court is\n1376518911241376518911241\\; 3\\; 7\\; 6\\; 5\\; 18\\; 9\\; 11\\; 2\\; 4\nand the king walked in three times: the first time after the first four persons have seen the minister, the second time after the first five persons have seen the minister and, finally after the first nine persons have seen the minister.\nAt the king's first visit the richest person to have met the minister has wealth $7$ and he would be beheaded. At the second visit, the wealth of the richest person who has met the minister and is still alive has wealth $6$ and so he would be beheaded. At the third visit the richest person to have met the minister who is still alive has wealth $18$ and so he would be beheaded.\nYou may assume that the input is such that whenever the king walks in, it is always possible to behead someone.\nYour aim is to write a program that will enable the prime minister to identify the richest man to have met the minister and who is still alive quickly. You may assume that no two citizens have the same wealth.\n\n-----Input:-----\nThe first line of the input consists of two numbers $N$ and $M$, where $N$ is the number of citizens in the kingdom and M is the number of visits to the court by the king.\nThe next $N+M$ lines describe the order in which the $N$ citizens' appearances are interleaved with the $M$ visits by the king. A citizen's visit is denoted by a positive integer, signifying his wealth. You may assume that no two citizens have the same wealth. A visit by the king is denoted by $-1$.\n\n-----Output:-----\nYour output should consist of $M$ lines, where the $i^{th}$ line contains the wealth of the citizen who is beheaded at the $i^{th}$ visit of the king.\n\n-----Constraints:-----\n- $1 \\leq M \\leq 10000$.\n- $1 \\leq N \\leq 100000$.\n- You may assume that in $50 \\%$ of the inputs $1 \\leq M \\leq 1000$ and $1 \\leq N \\leq 8000$.\n\n-----Sample Input-----\n10 3\n1 \n3 \n7 \n6 \n-1 \n5 \n-1 \n18 \n9 \n11\n2\n-1\n4\n\n-----Sample Output-----\n7\n6\n18\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nn,m=map(int,input().split())\r\nl=[]\r\nleng=0\r\nfor i in range(n+m):\r\n w=int(input())\r\n if w==-1:\r\n cm=0\r\n mi=0\r\n for j in range(leng):\r\n if l[j]>cm:\r\n cm=l[j]\r\n mi=j\r\n \r\n print(cm)\r\n l[mi]=-1\r\n else:\r\n l.append(w)\r\n leng+=1\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '10 3\\n1\\n3\\n7\\n6\\n-1\\n5\\n-1\\n18\\n9\\n11\\n2\\n-1\\n4\\n', 'output': '7\\n6\\n18\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/IARCSJUD/problems/ENDCORR'}","problem_id":"vfc_4118","program":"```python\nn,m=map(int,input().split())\r\nl=[]\r\nleng=0\r\nfor i in range(n+m):\r\n w=int(input())\r\n if w==-1:\r\n cm=0\r\n mi=0\r\n for j in range(leng):\r\n if l[j]>cm:\r\n cm=l[j]\r\n mi=j\r\n \r\n print(cm)\r\n l[mi]=-1\r\n else:\r\n l.append(w)\r\n leng+=1\n```","inputs":"10 3\n1\n3\n7\n6\n-1\n5\n-1\n18\n9\n11\n2\n-1\n4\n","output":"7\n6\n18\n","actual_output":"7\n6\n18\n","execution_success":true,"sample_index":914},{"source":"apps","task_type":"verifiable_code","in_source_id":"1320","prompt":"Solve the following coding problem using the programming language python:\n\nChef has many friends, but his best friend is Hemant. They both love to watch anime.\nIn fact, their weekends are meant for that only. Also, Hemant is highly into games, of which Chef is unaware. Hemant once gave a game to Chef and asked him to determine the winner of the game. Since the Chef is busy, and you are also his friend, he asked you to help him.\nThe Game is played between two players, $A$ and $B$. There are $N$ marbles. $A$ and $B$ plays alternately, and $A$ goes first. Each player can choose $1$ marble or $even$ number of marbles in his turn. The player who is not able to choose any marbles loses the game.\n\n-----Input:-----\n- The first line consists of a single integer $T$ denoting the number of test cases.\n- The Second line contains an integers $N$, denoting the number of marbles.\n\n-----Output:-----\nFor each test case, print the name of the player who loses the game.\n\n-----Constraints-----\n- $1 \\leq T \\leq 10^5$\n- $1 \\leq N \\leq 10^9$\n\n-----Sample Input:-----\n3\n1 \n3\n7 \n\n-----Sample Output:-----\nB\nA\nB\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n\nfor _ in range(int(input())):\n n=int(input())\n if(n<3):\n print(\"B\")\n else:\n if(n==3):\n print(\"A\")\n elif(n%2):\n print(\"B\")\n else:\n print(\"B\")\n\n\n\n\n\n\n\n\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\n1\\n3\\n7\\n', 'output': 'B\\nA\\nB\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/ENCO2020/problems/ENC2020A'}","problem_id":"vfc_4122","program":"```python\n\nfor _ in range(int(input())):\n n=int(input())\n if(n<3):\n print(\"B\")\n else:\n if(n==3):\n print(\"A\")\n elif(n%2):\n print(\"B\")\n else:\n print(\"B\")\n\n\n\n\n\n\n\n\n\n```","inputs":"3\n1\n3\n7\n","output":"B\nA\nB\n","actual_output":"B\nA\nB\n","execution_success":true,"sample_index":915},{"source":"apps","task_type":"verifiable_code","in_source_id":"1321","prompt":"Solve the following coding problem using the programming language python:\n\nThe chef is trying to solve some series problems, Chef wants your help to code it. Chef has one number N. Help the chef to find N'th number in the series.\n0, 1, 5, 14, 30, 55 \u2026..\n\n-----Input:-----\n- First-line will contain $T$, the number of test cases. Then the test cases follow. \n- Each test case contains a single line of input, one integer $N$. \n\n-----Output:-----\nFor each test case, output as the pattern.\n\n-----Constraints-----\n- $1 \\leq T \\leq 10^4$\n- $1 \\leq N \\leq 10^4$\n\n-----Sample Input:-----\n3\n1\n7\n8\n\n-----Sample Output:-----\n0\n91\n140\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nT=int(input())\nfor i in range(T):\n n=int(input())\n if n==1:\n print(\"0\")\n else:\n n=n-2\n l=(n+1)*(2*n+3)*(n+2)/6\n print(int(l))\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\n1\\n7\\n8\\n', 'output': '0\\n91\\n140\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/PEND2020/problems/ITGUY04'}","problem_id":"vfc_4126","program":"```python\nT=int(input())\nfor i in range(T):\n n=int(input())\n if n==1:\n print(\"0\")\n else:\n n=n-2\n l=(n+1)*(2*n+3)*(n+2)/6\n print(int(l))\n\n```","inputs":"3\n1\n7\n8\n","output":"0\n91\n140\n","actual_output":"0\n91\n140\n","execution_success":true,"sample_index":916},{"source":"apps","task_type":"verifiable_code","in_source_id":"1322","prompt":"Solve the following coding problem using the programming language python:\n\nSnackdown 2019 is coming! There are two rounds (round A and round B) after the qualification round. From both of them, teams can qualify to the pre-elimination round. According to the rules, in each of these two rounds, teams are sorted in descending order by their score and each team with a score greater or equal to the score of the team at the $K=1500$-th place advances to the pre-elimination round (this means it is possible to have more than $K$ qualified teams from each round in the case of one or more ties after the $K$-th place).\nToday, the organizers ask you to count the number of teams which would qualify for the pre-elimination round from round A for a given value of $K$ (possibly different from $1500$). They provided the scores of all teams to you; you should ensure that all teams scoring at least as many points as the $K$-th team qualify.\n\n-----Input-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The first line of each test case contains two space-separated integers $N$ and $K$.\n- The second line contains $N$ space-separated integers $S_1, S_2, \\dots, S_N$.\n\n-----Output-----\nFor each test case, print a single line containing one integer \u2014 the number of qualified teams.\n\n-----Constraints-----\n- $1 \\le T \\le 1,000$\n- $1 \\le K \\le N \\le 10^5$\n- $1 \\le S_i \\le 10^9$ for each valid $i$\n- the sum of $N$ for all test cases does not exceed $10^6$\n\n-----Example Input-----\n2\n5 1\n3 5 2 4 5\n6 4\n6 5 4 3 2 1\n\n-----Example Output-----\n2\n4\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\n#t = int(input())\nfor i in range(int(input())):\n n,k = map(int,input().split())\n l = list(map(int,input().split()))\n l.sort(reverse = True)\n c = 0\n for i in l:\n if i >= l[k-1]:\n c += 1\n print(c)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n5 1\\n3 5 2 4 5\\n6 4\\n6 5 4 3 2 1\\n', 'output': '2\\n4\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/QUALPREL'}","problem_id":"vfc_4130","program":"```python\n# cook your dish here\n#t = int(input())\nfor i in range(int(input())):\n n,k = map(int,input().split())\n l = list(map(int,input().split()))\n l.sort(reverse = True)\n c = 0\n for i in l:\n if i >= l[k-1]:\n c += 1\n print(c)\n```","inputs":"2\n5 1\n3 5 2 4 5\n6 4\n6 5 4 3 2 1\n","output":"2\n4\n","actual_output":"2\n4\n","execution_success":true,"sample_index":917},{"source":"apps","task_type":"verifiable_code","in_source_id":"1324","prompt":"Solve the following coding problem using the programming language python:\n\nGru wants to distribute $N$ bananas to $K$ minions on his birthday.\nGru does not like to just give everyone the same number of bananas, so instead, he wants to distribute bananas in such a way that each minion gets a $distinct$ amount of bananas. That is, no two minions should get the same number of bananas.\nGru also loves $gcd$. The higher the $gcd$, the happier Gru and the minions get. So help Gru in distributing the bananas in such a way that each Minion gets a distinct amount of bananas and gcd of this distribution is highest possible. Output this maximum gcd. If such a distribution is not possible output $-1$.\nNote: You have to distribute $all$ $N$ bananas. \n\n-----Input:-----\n- First line will contain $T$, number of testcases. Then the testcases follow. \n- Each testcase consists of a single line of input, which has two integers: $N, K$. \n\n-----Output:-----\nFor each testcase, output in a single line the maximum gcd or -1.\n\n-----Constraints-----\n- $1 \\leq T \\leq 100$\n- $1 \\leq N, K \\leq 10^9$\n\n-----Sample Input:-----\n1\n6 3\n\n-----Sample Output:-----\n1\n\n-----EXPLANATION:-----\nThe only possible distribution is $[1, 2, 3]$. So the answer is 1.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfrom math import sqrt\n\nfor _ in range(int(input())):\n \n n, k = map(int, input().split())\n fact,i = [],1\n \n while i<=sqrt(n):\n\n if n%i==0:\n if (n // i != i):\n fact.append(n//i)\n \n fact.append(i)\n \n i+=1\n \n tot = (k*(k+1))//2\n mx = -1\n \n for i in fact:\n if i>=tot:\n mx = max(mx,n//i)\n \n print(mx)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n6 3\\n', 'output': '1\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/GRUBAN'}","problem_id":"vfc_4138","program":"```python\nfrom math import sqrt\n\nfor _ in range(int(input())):\n \n n, k = map(int, input().split())\n fact,i = [],1\n \n while i<=sqrt(n):\n\n if n%i==0:\n if (n // i != i):\n fact.append(n//i)\n \n fact.append(i)\n \n i+=1\n \n tot = (k*(k+1))//2\n mx = -1\n \n for i in fact:\n if i>=tot:\n mx = max(mx,n//i)\n \n print(mx)\n```","inputs":"1\n6 3\n","output":"1\n","actual_output":"1\n","execution_success":true,"sample_index":918},{"source":"apps","task_type":"verifiable_code","in_source_id":"1325","prompt":"Solve the following coding problem using the programming language python:\n\nTeacher brought a fruit basket for three students. The basket contains only Apples, Mangoes and Oranges. Student A knows a value $a$, the total number of Apples and Mangoes in the Basket, B knows a value $b$, the total number of Mangoes and Oranges in the basket and Student C knows a value $c$, the total number of Oranges and Apples in the Basket. Since the teacher brought it he knows a value $d$ , the total number of fruits in the basket. You have to determine the exact number of Apples , Mangoes and Oranges in the basket separately.\n\n-----Input:-----\n- First line will contain $T$, number of testcases. Then the testcases follow. \n- Each testcase contains of a single line of input, four integers $a,b,c,d$. \n\n-----Output:-----\nFor each testcase, output in a single line the number of Apples , Mangoes and Oranges in this order.\n\n-----Constraints-----\n- $1 \\leq T \\leq 100$\n- $0 \\leq a \\leq 1000$\n- $0 \\leq b \\leq 1000$\n- $0 \\leq c \\leq 1000$\n- $0 \\leq d \\leq 1000$ \n-The Solution always exisits\n\n-----Sample Input:-----\n2\n\n7 9 8 12\n\n3 8 7 9\n\n-----Sample Output:-----\n3 4 5\n\n1 2 6\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\nfor j in range(int(input())):\n \n p,q,r,s =map(int,input().split())\n x=(s-p)\n y=(s-q)\n z=(s-r)\n print(y,z,x)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n7 9 8 12\\n3 8 7 9\\n', 'output': '3 4 5\\n1 2 6\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/COW42020/problems/COW3A'}","problem_id":"vfc_4142","program":"```python\n# cook your dish here\nfor j in range(int(input())):\n \n p,q,r,s =map(int,input().split())\n x=(s-p)\n y=(s-q)\n z=(s-r)\n print(y,z,x)\n```","inputs":"2\n7 9 8 12\n3 8 7 9\n","output":"3 4 5\n1 2 6\n","actual_output":"3 4 5\n1 2 6\n","execution_success":true,"sample_index":919},{"source":"apps","task_type":"verifiable_code","in_source_id":"1326","prompt":"Solve the following coding problem using the programming language python:\n\nThere are $N$ cars (numbered $1$ through $N$) on a circular track with length $N$. For each $i$ ($2 \\le i \\le N$), the $i$-th of them is at a distance $i-1$ clockwise from car $1$, i.e. car $1$ needs to travel a distance $i-1$ clockwise to reach car $i$. Also, for each valid $i$, the $i$-th car has $f_i$ litres of gasoline in it initially.\nYou are driving car $1$ in the clockwise direction. To move one unit of distance in this direction, you need to spend $1$ litre of gasoline. When you pass another car (even if you'd run out of gasoline exactly at that point), you steal all its gasoline. Once you do not have any gasoline left, you stop.\nWhat is the total clockwise distance travelled by your car? \n\n-----Input-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The first line of each test case contains a single integer $N$.\n- The second line contains $N$ space-separated integers $f_1, f_2, \\ldots, f_N$.\n\n-----Output-----\nFor each test case, print a single line containing one integer \u2015 the total clockwise distance travelled.\n\n-----Constraints-----\n- $1 \\le T \\le 100$\n- $1 \\le N \\le 100$\n- $0 \\le f_i \\le 100$ for each valid $i$\n\n-----Subtasks-----\nSubtask #1 (100 points): original constraints\n\n-----Example Input-----\n3\n5\n3 0 0 0 0\n5\n1 1 1 1 1\n5\n5 4 3 2 1\n\n-----Example Output-----\n3\n5\n15\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfor _ in range(int(input())):\n n=int(input())\n f=list(map(int,input().split()))\n sum1=f[0]\n d=0\n i=1 \n while sum1!=0 and i 0:\n dp2[i] = min(dp2[i], dp2[i ^ submask] + dp1[submask])\n submask = (submask-1) & i\n \n print(dp2[(1 << n)-1])\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n3 3\\n3 5 6\\n11 3 1 2 3\\n5 2 1 2\\n5 2 1 3\\n', 'output': '10\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/FFCOMB'}","problem_id":"vfc_4158","program":"```python\nT = int(input())\nfor t in range(T):\n n, m = list(map(int, input().split()))\n c = list(map(int, input().split()))\n dp1 = [1e9]*((1 << n)+1)\n for i in range(n):\n dp1[1 << i] = c[i] \n \n dp1[1 << (n-1)] = min(dp1[1 << (n-1)], sum(c))\n \n for i in range(m):\n l = list(map(int, input().split()))\n cost = l[0]\n s = l[1]\n items = l[2:]\n mask = 0\n for j in items:\n mask = mask | (1 << (j-1))\n dp1[mask] = min(dp1[mask], cost)\n \n for i in range((1< 0:\n dp2[i] = min(dp2[i], dp2[i ^ submask] + dp1[submask])\n submask = (submask-1) & i\n \n print(dp2[(1 << n)-1])\n\n```","inputs":"1\n3 3\n3 5 6\n11 3 1 2 3\n5 2 1 2\n5 2 1 3\n","output":"10\n","actual_output":"10\n","execution_success":true,"sample_index":923},{"source":"apps","task_type":"verifiable_code","in_source_id":"1330","prompt":"Solve the following coding problem using the programming language python:\n\nThe country of Siruseri has A\u2217B$A*B$ districts. You want to create A$A$ states from these districts, such that each state has exactly B$B$ districts, and each district is part of exactly one state. You don't care about the geographical location of the districts. You can pick any B$B$ districts and make it into a state.\nThere are only two parties contesting in the coming elections: P1$P_1$ and P2$P_2$. You know the number of votes that each party receives in each district. In the i-th district, P1$P_1$ gets ci$c_i$ votes and P2$P_2$ gets di$d_i$ votes. You are guaranteed that all these 2\u2217A\u2217B$2*A*B$ integers (the number of votes received by each party in the districts) are distinct. Also, both A$A$ and B$B$ are odd. \nSuppose you have chosen which districts belong to which states, then, to find out who wins any particular state, they follow a weird rule: Suppose the number of votes that P1$P_1$ gets in the B$B$ districts of a particular state are x1,x2,\u2026,xB$x_1, x_2, \\ldots, x_B$, and the number of votes that P2$P_2$ gets in the B$B$ districts of this state are y1,y2,\u2026,yB$y_1, y_2, \\ldots, y_B$. Then among all these 2\u2217B$2*B$ numbers, the largest number is chosen (note that we are guaranteed of an unique largest number). If that number is some xi$x_i$, then P1$P_1$ wins this state. If the largest number is some yj$y_j$, then P2$P_2$ wins this state.\nYou secretly support the party P1$P_1$, and hence you want to assign the districts to states, in such a way, that the number of states won by P1$P_1$ is maximized. Find this maximum number of states that P1$P_1$ can win.\nNote that ci$c_i$ and di$d_i$ will always remain associated with the i-th district. If the i-th district gets assigned to a particular state, then both ci$c_i$ and di$d_i$ will be considered when deciding who won that state.\n\n-----Input:-----\n- The first line of the input contains a single integer, T$T$, the number of testcases. The description of each testcase follows.\n- The first line of each testcase contains two integers, A$A$ and B$B$.\n- The second line of each testcase contains A\u2217B$A*B$ integers: c1,c2,\u2026,cA\u2217B$c_1, c_2, \\ldots, c_{A*B}$, the number of votes won by P1$P_1$ in the districts.\n- The third line of each testcase contains A\u2217B$A*B$ integers: d1,d2,\u2026,dA\u2217B$d_1, d_2, \\ldots, d_{A*B}$, the number of votes won by P2$P_2$ in the districts.\n\n-----Output:-----\nFor each testcase output a single line which contains the maximum number of states that P1$P_1$ can win.\n\n-----Constraints:-----\n- 1\u2264T\u22645$1 \\leq T \\leq 5$\n- 1\u2264A,B$1 \\leq A, B$\n- A\u2217B\u2264105$A*B \\leq 10^5$\n- A$A$, B$B$ are odd\n- 1\u2264ci,di\u2264109$1 \\leq c_i, d_i \\leq 10^9$\n- All the ci$c_i$ and di$d_i$ will be distinct.\n\n-----Sample Input:-----\n3\n1 3\n4 2 9\n5 6 7\n1 3\n4 2 9\n5 10 7\n3 3\n7 14 11 4 15 5 20 1 17\n2 13 16 9 19 6 12 8 10\n\n-----Sample Output:-----\n1\n0\n3\n\n-----Explanation:-----\nTestcase 1: Since you have to form only 1 state, there is no choice, but to put all the 3 districts in that same state. Now to figure out who wins that single state, we take the maximum among {4, 2, 9, 5, 6, 7}. The maximum is 9, and that belongs to P1$P_1$. Hence P1$P_1$ wins this state. And because they have won 1 state, the answer is 1.\nTestcase 2: Similarly, there is no choice here. To figure out who wins that single state, we take the maximum among {4, 2, 9, 5, 10, 7}. The maximum is 10, and that belongs to P2$P_2$. Hence P2$P_2$ wins this state. And because P1$P_1$ have won no states, the answer is 0.\nTestcase 3: We need to make three states with three districts each. Suppose we that the 3rd, 5th and 7th districts and form a state, the votes in them would be {11, 16, 15, 19, 20, 12}. The max among these is 20, and that belongs to P1$P_1$. Hence P1$P_1$ would win this state. \nSimilarly, suppose we make the second state with the 2nd, 4th and 8th districts, the votes in them would be {14, 13, 4, 9, 1, 8}. The max among these is 14, and that belongs to P1$P_1$. Hence P1$P_1$ would win this state. \nThe remaining three districts: 1st, 6th and 9th districts form the third state. The votes in them would be {7, 2, 5, 6, 17, 10}. The max among these is 17, and that belongs to P1$P_1$. Hence P1$P_1$ would win this state. \nIn this situation, P1$P_1$ wins three states. You obviously cannot do any better. Hence the answer is 3.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\nfor _ in range(int(input())):\n A,B=list(map(int,input().split()))\n l1=list(map(int,input().split()))\n l2=list(map(int,input().split()))\n for i in range(A*B):\n if l1[i]l2[d]:\n w+=1\n c+=1\n d+=B-1\n else:\n d+=B\n print(w)\n \n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\n1 3\\n4 2 9\\n5 6 7\\n1 3\\n4 2 9\\n5 10 7\\n3 3\\n7 14 11 4 15 5 20 1 17\\n2 13 16 9 19 6 12 8 10\\n', 'output': '1\\n0\\n3\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/SIRUSERI'}","problem_id":"vfc_4162","program":"```python\n# cook your dish here\nfor _ in range(int(input())):\n A,B=list(map(int,input().split()))\n l1=list(map(int,input().split()))\n l2=list(map(int,input().split()))\n for i in range(A*B):\n if l1[i]l2[d]:\n w+=1\n c+=1\n d+=B-1\n else:\n d+=B\n print(w)\n \n\n```","inputs":"3\n1 3\n4 2 9\n5 6 7\n1 3\n4 2 9\n5 10 7\n3 3\n7 14 11 4 15 5 20 1 17\n2 13 16 9 19 6 12 8 10\n","output":"1\n0\n3\n","actual_output":"1\n0\n3\n","execution_success":true,"sample_index":924},{"source":"apps","task_type":"verifiable_code","in_source_id":"1332","prompt":"Solve the following coding problem using the programming language python:\n\nConsider an infinite full binary tree (each node has two children except the leaf nodes) defined as follows. For a node labelled v its left child will be labelled 2*v and its right child will be labelled 2*v+1. The root is labelled as 1.\nYou are given N queries of the form i j. For each query, you have to print the length of the shortest path between node labelled i and node labelled j.\n\n-----Input-----\nFirst line contains N, the number of queries. Each query consists of two space separated integers i and j in one line.\n\n-----Output-----\nFor each query, print the required answer in one line.\n\n-----Constraints-----\n- 1 \u2264 N \u2264 105\n- 1 \u2264 i,j \u2264 109\n\n-----Example-----\nInput:\n3\n1 2\n2 3\n4 3\n\nOutput:\n1\n2\n3\n\n-----Explanation-----\nFor first query, 1 is directly connected to 2 by an edge. Hence distance 1.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nt=eval(input())\nfor _ in range(t):\n i,j=list(map(int,input().split()))\n bi=bin(i)[2:]\n bj=bin(j)[2:]\n k=0\n while k<(min(len(bi),len(bj))):\n if bi[k]!=bj[k]:\n break\n else:\n k+=1\n print(len(bi)-k+len(bj)-k)\n \n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\n1 2\\n2 3\\n4 3\\n', 'output': '1\\n2\\n3\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/APRIL14/problems/BINTREE'}","problem_id":"vfc_4170","program":"```python\nt=eval(input())\nfor _ in range(t):\n i,j=list(map(int,input().split()))\n bi=bin(i)[2:]\n bj=bin(j)[2:]\n k=0\n while k<(min(len(bi),len(bj))):\n if bi[k]!=bj[k]:\n break\n else:\n k+=1\n print(len(bi)-k+len(bj)-k)\n \n\n```","inputs":"3\n1 2\n2 3\n4 3\n","output":"1\n2\n3\n","actual_output":"1\n2\n3\n","execution_success":true,"sample_index":926},{"source":"apps","task_type":"verifiable_code","in_source_id":"1333","prompt":"Solve the following coding problem using the programming language python:\n\nChef has invited Alice for his birthday party. Now, Alice is thinking about what to give Chef as a present. She should obviously choose a sequence \u2015 what could possibly be a better birthday gift than a sequence!\nAfter some thinking, Alice chose a sequence of integers $A_1, A_2, \\ldots, A_N$. However, she does not want to simply give this sequence to Chef. Instead, she decided to give Chef a sequence $B_1, B_2, \\ldots, B_N$, where $B_i = \\bigvee_{j=1}^i A_j$ for each valid $i$ and $\\bigvee$ denotes the bitwise OR operation. Chef can try to generate a sequence $A$ from $B$, but there could be more than one such possible sequence.\nNow, Alice is wondering how many sequences $A$ correspond to the given sequence $B$. Since this number could be very large, compute it modulo $10^9 + 7$. Note that it is not guaranteed that the given sequence $B$ was generated from some sequence $A$.\n\n-----Input-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The first line of each test case contains a single integer $N$.\n- The second line contains $N$ space-separated integers $B_1, B_2, \\ldots, B_N$.\n\n-----Output-----\nFor each test case, print a single line containing one integer \u2015 the number of possible sequences $A$ modulo $10^9 + 7$.\n\n-----Constraints-----\n- $1 \\le T \\le 25$\n- $1 \\le N \\le 5 \\cdot 10^4$\n- $0 \\le B_i < 2^{30}$ for each valid $i$\n\n-----Example Input-----\n2\n2\n2 3\n4\n2 6 7 7\n\n-----Example Output-----\n2\n64\n\n-----Explanation-----\nExample case 1: There are two possible options for $A$: $(2, 1)$ and $(2, 3)$.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nmod=10**9+7\ndef pow2(x):\n p,n=1,2\n while(x):\n if(x & 1): p=((p%mod) * (n%mod))%mod\n\n n=((n%mod) * (n%mod))%mod\n x//=2\n\n return p\n\ndef count_bit(val):\n bit=0\n while(val):\n bit+=1\n val &=(val-1)\n return bit\n \ndef answer():\n\n val=b[0]\n po2=0\n for i in range(1,len(b)):\n if(val > b[i]):return 0\n po2+=count_bit(val & b[i])\n val=b[i]\n\n return pow2(po2)%mod\n\n\nfor T in range(int(input())):\n n=int(input())\n b=list(map(int,input().split()))\n\n print(answer())\n \n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n2\\n2 3\\n4\\n2 6 7 7\\n', 'output': '2\\n64\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/MYSARA'}","problem_id":"vfc_4174","program":"```python\nmod=10**9+7\ndef pow2(x):\n p,n=1,2\n while(x):\n if(x & 1): p=((p%mod) * (n%mod))%mod\n\n n=((n%mod) * (n%mod))%mod\n x//=2\n\n return p\n\ndef count_bit(val):\n bit=0\n while(val):\n bit+=1\n val &=(val-1)\n return bit\n \ndef answer():\n\n val=b[0]\n po2=0\n for i in range(1,len(b)):\n if(val > b[i]):return 0\n po2+=count_bit(val & b[i])\n val=b[i]\n\n return pow2(po2)%mod\n\n\nfor T in range(int(input())):\n n=int(input())\n b=list(map(int,input().split()))\n\n print(answer())\n \n\n```","inputs":"2\n2\n2 3\n4\n2 6 7 7\n","output":"2\n64\n","actual_output":"2\n64\n","execution_success":true,"sample_index":927},{"source":"apps","task_type":"verifiable_code","in_source_id":"1335","prompt":"Solve the following coding problem using the programming language python:\n\nDinesh is very fond of sweets recently his aunt Riya gifted him an array $a$ of sweets of size $N$. The ith sweet is of the type $a[i]$. His mother told him that he can choose one type of sweet in a day and eat at most 2 sweets of that type. Since he has to eat all the sweets as quickly as possible because his cousins are arriving. Find out the minimum number of days in which he can eat all the sweets gifted by his aunt Riya. \n\n-----Input:-----\n- First-line will contain $N$, the number of sweets. \n- The next line will contain $N$ space integers denoting the type of sweets.\n\n-----Output:-----\nOutput the minimum number of days in which he can eat all the sweets.\n\n-----Constraints-----\n- $1 \\leq N \\leq 10000$\n- $1 \\leq a[i] \\leq 10^3$\n\n-----Sample Input:-----\n3\n1 2 2\n\n-----Sample Output:-----\n2\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\nn=int(input())\nlst=list(map(int,input().split()))\ndict1={}.fromkeys(lst,0)\nfor key in lst:\n dict1[key]+=1\nsum1=0\nfor key in dict1:\n sum1+=dict1[key]//2\n if(dict1[key]%2==1):\n sum1+=1\nprint(sum1) \n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\n1 2 2\\n', 'output': '2\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/POPU2021/problems/POPPUSH1'}","problem_id":"vfc_4182","program":"```python\n# cook your dish here\nn=int(input())\nlst=list(map(int,input().split()))\ndict1={}.fromkeys(lst,0)\nfor key in lst:\n dict1[key]+=1\nsum1=0\nfor key in dict1:\n sum1+=dict1[key]//2\n if(dict1[key]%2==1):\n sum1+=1\nprint(sum1) \n```","inputs":"3\n1 2 2\n","output":"2\n","actual_output":"2\n","execution_success":true,"sample_index":929},{"source":"apps","task_type":"verifiable_code","in_source_id":"1336","prompt":"Solve the following coding problem using the programming language python:\n\nA printer \u2013 who still uses moveable type \u2013 is preparing to print a set of pages for a book. These pages are to be numbered, as usual. The printer needs to know how many instances of each decimal digit will be required to set up the page numbers in the section of the book to be printed.\n\nFor example, if pages 10, 11, 12, 13, 14 and 15 are to be printed, computing the number of digits is relatively simple: just look at the page numbers that will appear, and count the number of times each digit appears. The digit 0 appears only once, the digit 1 appears 7 times, the digits 2, 3, 4 and 5 each appear once, and 6, 7, 8 and 9 don\u2019t appear at all.\n\nYour task in this problem is to provide the printer with the appropriate counts of the digits. You will be given the numbers of the two pages that identify the section of the book to be printed. You may safely assume that all pages in that section are to be numbered, that no leading zeroes will be printed, that page numbers are positive, and that no page will have more than three digits in its page number.\n\n-----Input-----\n\nThere will be multiple cases to consider. The input for each case has two integers, A and B, each of which is guaranteed to be positive. These identify the pages to be printed. That is, each integer P between A and B, including A and B, is to be printed. A single zero will follow the input for the last case.\n\n-----Output-----\n\nFor each input case, display the case number (1, 2, \u2026) and the number of occurrences of each decimal digit 0 through 9 in the specified range of page numbers. Display your results in the format shown in the examples below.\n\n-----Example-----\nInput:\n\n10 15\n912 912\n900 999\n0\n\nOutput:\n\nCase 1: 0:1 1:7 2:1 3:1 4:1 5:1 6:0 7:0 8:0 9:0\nCase 2: 0:0 1:1 2:1 3:0 4:0 5:0 6:0 7:0 8:0 9:1\nCase 3: 0:20 1:20 2:20 3:20 4:20 5:20 6:20 7:20 8:20 9:120\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nline = input()\ntest = 0\n\nwhile line != \"0\":\n test += 1\n d = {'0':0,'1':0,'2':0,'3':0,'4':0,'5':0,'6':0,'7':0,'8':0,'9':0}\n a = list(map(int,line.split()))\n for i in range(min(a),max(a)+1):\n for c in str(i):\n d[c] += 1\n pairs = list(d.items())\n pairs.sort() \n print(\"Case %s: %s\" % (test, \" \".join([\"%s:%s\" % (k,v) for k,v in pairs])))\n line = input()\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '10 15\\n912 912\\n900 999\\n0\\n\\n\\n', 'output': 'Case 1: 0:1 1:7 2:1 3:1 4:1 5:1 6:0 7:0 8:0 9:0\\nCase 2: 0:0 1:1 2:1 3:0 4:0 5:0 6:0 7:0 8:0 9:1\\nCase 3: 0:20 1:20 2:20 3:20 4:20 5:20 6:20 7:20 8:20 9:120\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/PRFT2012/problems/PD21'}","problem_id":"vfc_4186","program":"```python\nline = input()\ntest = 0\n\nwhile line != \"0\":\n test += 1\n d = {'0':0,'1':0,'2':0,'3':0,'4':0,'5':0,'6':0,'7':0,'8':0,'9':0}\n a = list(map(int,line.split()))\n for i in range(min(a),max(a)+1):\n for c in str(i):\n d[c] += 1\n pairs = list(d.items())\n pairs.sort() \n print(\"Case %s: %s\" % (test, \" \".join([\"%s:%s\" % (k,v) for k,v in pairs])))\n line = input()\n```","inputs":"10 15\n912 912\n900 999\n0\n\n\n","output":"Case 1: 0:1 1:7 2:1 3:1 4:1 5:1 6:0 7:0 8:0 9:0\nCase 2: 0:0 1:1 2:1 3:0 4:0 5:0 6:0 7:0 8:0 9:1\nCase 3: 0:20 1:20 2:20 3:20 4:20 5:20 6:20 7:20 8:20 9:120\n","actual_output":"Case 1: 0:1 1:7 2:1 3:1 4:1 5:1 6:0 7:0 8:0 9:0\nCase 2: 0:0 1:1 2:1 3:0 4:0 5:0 6:0 7:0 8:0 9:1\nCase 3: 0:20 1:20 2:20 3:20 4:20 5:20 6:20 7:20 8:20 9:120\n","execution_success":true,"sample_index":930},{"source":"apps","task_type":"verifiable_code","in_source_id":"1337","prompt":"Solve the following coding problem using the programming language python:\n\nThe $String$ Family gave birth to a new $Tripartite$ $trio$ $sisters$ and named them $Hema$, $Rekha$ and $Sushma$. Hema and Rekha are very fond of parties whereas Sushma hates them. One day Hema and Rekha asked their parents to buy them candies to distribute to people in their birthday party. (Remember Hema, Rekha and Sushma were born on the same day). But Sushma was uninterested in the party and only wanted candies for herself.\nYou will be given a list $P$ of possible number of candidates coming to the party. Were $P[i]$ denotes the count of people coming in the i th possibility. In each case every person should get maximum possible equal number of candies such that after distributing the candies, there are always $R$ candies remaining for Sushma. You have to calculate the minimum number of candies required to buy so that, in any possible situation of the given array, each person coming to party gets equal number of candies (at least 1 and maximum possible out of total) and there are always $R$ candies remaining for Sushma.\n\n-----Input:-----\n- First line will contain $T$, number of testcases. Then the testcases follow. \n- First line of each test case contain $N$, number of possible count of people coming to party\n- Next line contain $N$ spaced integers denoting the count of people \n- Next line contain $R$ the number of candies always remaining after maximum equal distribution\n\n-----Output:-----\nFor each testcase, output in a single line answer, the minimum number of candies required to buy.\n\n-----Constraints-----\n- $1 \\leq T \\leq 100$\n- $1 \\leq N \\leq 10^4$\n- $1 \\leq P[i] \\leq 41$\n- $0 \\leq R < min(P[i])$\n\n-----Sample Input:-----\n1\n2\n2 3\n1\n\n-----Sample Output:-----\n7\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfrom math import gcd\r\ndef compute_lcm(x, y):\r\n lcm = (x*y)//gcd(x,y)\r\n return lcm\r\n\r\ndef LCMofArray(a):\r\n lcm = a[0]\r\n for i in range(1,len(a)):\r\n lcm = lcm*a[i]//gcd(lcm, a[i])\r\n return lcm\r\n\r\nfor _ in range(int(input())):\r\n lens = int(input())\r\n arrs = [int(x) for x in input().split()]\r\n rest = int(input())\r\n print(LCMofArray(arrs) + rest)\r\n\r\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n2\\n2 3\\n1\\n', 'output': '7\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/COMX2020/problems/CMX1P02'}","problem_id":"vfc_4190","program":"```python\nfrom math import gcd\r\ndef compute_lcm(x, y):\r\n lcm = (x*y)//gcd(x,y)\r\n return lcm\r\n\r\ndef LCMofArray(a):\r\n lcm = a[0]\r\n for i in range(1,len(a)):\r\n lcm = lcm*a[i]//gcd(lcm, a[i])\r\n return lcm\r\n\r\nfor _ in range(int(input())):\r\n lens = int(input())\r\n arrs = [int(x) for x in input().split()]\r\n rest = int(input())\r\n print(LCMofArray(arrs) + rest)\r\n\r\n\n```","inputs":"1\n2\n2 3\n1\n","output":"7\n","actual_output":"7\n","execution_success":true,"sample_index":931},{"source":"apps","task_type":"verifiable_code","in_source_id":"1338","prompt":"Solve the following coding problem using the programming language python:\n\n-----General Statement:-----\nRead a number in scientific notation and output its equivalent decimal value.\n\n-----Input:-----\nAll data is on a single line. The first integer indicates how many pairs of numbers follow. The first of each pair is A, the base number, and the second is E, the power of 10.\n\n-----Output:-----\nRound each answer to 2 decimal places. Trailing zeros to the right of the decimal point are required. A leading zero to the left of the decimal point is not required.\nThe output is to be formatted exactly like that for the sample output given below.\n\n-----Assumptions:-----\nE is in the range \u201310 .. 10. A is 1 or larger but less than 10.\nDiscussion: \nIf A = 3.926 and E = 4, the number represented is 3.926 X 104 or 39260, which is 39260.00 when rounded to 2 decimal places.\n\n-----Sample Input:-----\n4 4.296 3 3.8 -2 1.8 2 2.8678 1\n\n-----Sample Output:-----\n4296.00\n0.04\n180.00\n28.68\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n#In the Name of God\r\nimport math\r\n\r\nx = input().split()\r\nn = int(x[0])\r\narr = []\r\ni = 1\r\nwhile(i=a[p+1]):\n return p\n return n-1 \n \ndef suf(a):\n for s in range(1,n):\n if(a[n-s]<=a[n-s-1]):\n return n-s\n return 0\n \n \n\nt=int(input())\nfor _ in range(t):\n n=int(input())\n a=list(map(int,input().split()))\n \n p=pre(a)\n s=suf(a)\n \n b=a[s:n]\n count=0\n for i in range(p+1):\n k=bisect.bisect(b,a[i])\n k+=s\n count+=n-k+1\n \n if(s==0):\n print((n*(n+1))//2-1)\n else:\n print(count+n-s)\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n3\\n1 1 2\\n4\\n2 4 3 5\\n', 'output': '4\\n7\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/DELARRAY'}","problem_id":"vfc_4206","program":"```python\nimport bisect\n\ndef pre(a):\n for p in range(n-1):\n if(a[p]>=a[p+1]):\n return p\n return n-1 \n \ndef suf(a):\n for s in range(1,n):\n if(a[n-s]<=a[n-s-1]):\n return n-s\n return 0\n \n \n\nt=int(input())\nfor _ in range(t):\n n=int(input())\n a=list(map(int,input().split()))\n \n p=pre(a)\n s=suf(a)\n \n b=a[s:n]\n count=0\n for i in range(p+1):\n k=bisect.bisect(b,a[i])\n k+=s\n count+=n-k+1\n \n if(s==0):\n print((n*(n+1))//2-1)\n else:\n print(count+n-s)\n\n```","inputs":"2\n3\n1 1 2\n4\n2 4 3 5\n","output":"4\n7\n","actual_output":"4\n7\n","execution_success":true,"sample_index":935},{"source":"apps","task_type":"verifiable_code","in_source_id":"1342","prompt":"Solve the following coding problem using the programming language python:\n\nChef is multi-talented. He has developed a cure for coronavirus called COVAC-19. Now that everyone in the world is infected, it is time to distribute it throughout the world efficiently to wipe out coronavirus from the Earth. Chef just cooks the cure, you are his distribution manager.\nIn the world, there are $N$ countries (numbered $1$ through $N$) with populations $a_1, a_2, \\ldots, a_N$. Each cure can be used to cure one infected person once. Due to lockdown rules, you may only deliver cures to one country per day, but you may choose that country arbitrarily and independently on each day. Days are numbered by positive integers. On day $1$, Chef has $x$ cures ready. On each subsequent day, Chef can supply twice the number of cures that were delivered (i.e. people that were cured) on the previous day. Chef cannot supply leftovers from the previous or any earlier day, as the cures expire in a day. The number of cures delivered to some country on some day cannot exceed the number of infected people it currently has, either.\nHowever, coronavirus is not giving up so easily. It can infect a cured person that comes in contact with an infected person again \u2015 formally, it means that the number of infected people in a country doubles at the end of each day, i.e. after the cures for this day are used (obviously up to the population of that country).\nFind the minimum number of days needed to make the world corona-free.\n\n-----Input-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The first line of each test case contains two space-separated integers $N$ and $x$.\n- The second line contains $N$ space-separated integers $a_1, a_2, \\ldots, a_N$.\n\n-----Output-----\nFor each test case, print a single line containing one integer \u2015 the minimum number of days.\n\n-----Constraints-----\n- $1 \\le T \\le 10^3$\n- $1 \\le N \\le 10^5$\n- $1 \\le a_i \\le 10^9$ for each valid $i$\n- $1 \\le x \\le 10^9$\n- the sum of $N$ over all test cases does not exceed $10^6$\n\n-----Subtasks-----\nSubtask #1 (20 points): $a_1 = a_2 = \\ldots = a_N$\nSubtask #2 (80 points): original constraints\n\n-----Example Input-----\n3\n5 5\n1 2 3 4 5\n5 1\n40 30 20 10 50\n3 10\n20 1 110\n\n-----Example Output-----\n5\n9\n6\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nimport math\nfor i in range(int(input())):\n n,x=list(map(int,input().split()))\n l=list(map(int,input().split()))\n l.sort()\n flag=0\n d=0\n \n for j in range(n):\n \n if l[j]>x:\n for k in range(j,n):\n \n if xx:\n for k in range(j,n):\n \n if x=len(b)):\n return False\n index+=1 \n return True\ndef Dob_String(n):\n size=len(n)\n midpoint=size//2\n if(check_equal(n[0:midpoint],n[midpoint:size])):\n return(\"YES\")\n elif(size%2!=0 and check_equal(n[midpoint+1:size],n[0:midpoint+1])):\n return(\"YES\")\n else:\n return(\"NO\")\nT=int(input()) \nfor _ in range(T):\n n=input()\n if(len(n)>1):\n print(Dob_String(n))\n else:\n print(\"NO\")\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\naba\\nabac\\nabcd\\n', 'output': 'YES\\nNO\\nNO\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/CHEFSPL'}","problem_id":"vfc_4214","program":"```python\n# cook your dish here\ndef check_equal(a,b):\n index=0\n for i in a:\n while index=len(b)):\n return False\n index+=1 \n return True\ndef Dob_String(n):\n size=len(n)\n midpoint=size//2\n if(check_equal(n[0:midpoint],n[midpoint:size])):\n return(\"YES\")\n elif(size%2!=0 and check_equal(n[midpoint+1:size],n[0:midpoint+1])):\n return(\"YES\")\n else:\n return(\"NO\")\nT=int(input()) \nfor _ in range(T):\n n=input()\n if(len(n)>1):\n print(Dob_String(n))\n else:\n print(\"NO\")\n```","inputs":"3\naba\nabac\nabcd\n","output":"YES\nNO\nNO\n","actual_output":"YES\nNO\nNO\n","execution_success":true,"sample_index":937},{"source":"apps","task_type":"verifiable_code","in_source_id":"1344","prompt":"Solve the following coding problem using the programming language python:\n\nYou are given a sequence a1, a2, ..., aN. Find the smallest possible value of ai + aj, where 1 \u2264 i < j \u2264 N.\n\n-----Input-----\nThe first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows. \nThe first line of each description consists of a single integer N.\nThe second line of each description contains N space separated integers - a1, a2, ..., aN respectively.\n\n-----Output-----\nFor each test case, output a single line containing a single integer - the smallest possible sum for the corresponding test case.\n\n-----Constraints-----\n\n- T = 105, N = 2 : 13 points.\n- T = 105, 2 \u2264 N \u2264 10 : 16 points.\n- T = 1000, 2 \u2264 N \u2264 100 : 31 points.\n- T = 10, 2 \u2264 N \u2264 105 : 40 points.\n- 1 \u2264 ai \u2264 106\n\n-----Example-----\nInput:\n1\n4\n5 1 3 4\n\nOutput:\n4\n\n-----Explanation-----\nHere we pick a2 and a3. Their sum equals to 1 + 3 = 4.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\ndef __starting_point():\n try:\n for _ in range (int(input())):\n element = int(input())\n l = list(map(int,input().split()))\n a=min(l)\n l.remove(a)\n b=min(l)\n print(a+b)\n except EOFError :\n print('EOFError')\n\n__starting_point()\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n4\\n5 1 3 4\\n', 'output': '4\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/SMPAIR'}","problem_id":"vfc_4218","program":"```python\n# cook your dish here\ndef __starting_point():\n try:\n for _ in range (int(input())):\n element = int(input())\n l = list(map(int,input().split()))\n a=min(l)\n l.remove(a)\n b=min(l)\n print(a+b)\n except EOFError :\n print('EOFError')\n\n__starting_point()\n```","inputs":"1\n4\n5 1 3 4\n","output":"4\n","actual_output":"4\n","execution_success":true,"sample_index":938},{"source":"apps","task_type":"verifiable_code","in_source_id":"1345","prompt":"Solve the following coding problem using the programming language python:\n\nAt the legendary times of Nonsenso wars in ISM Dhanbad, there was a neck to neck competition between Barney Stinson and Sheldon Cooper. They both were on level 19. After trying too hard both of them could not decipher the nonsense, so they decided to play alongside. Sheldon Cooper had to pass a message to Barney Stinson. So he decided to convert each letter of the sentence to their corresponding to their ASCII codes. When Barney received the message he could not get anything. Now you have to design a code which converts the encrypted message to readable format.\n\n-----Input-----\nThe input will consist of the first line containing the number of test cases \u2018n\u2019 followed by n lines of test cases.\n\n-----Output-----\n\nFor each input print the decoded line.\n\n-----Example-----\nInput:\n2\n721011081081113287111114108100\n871011089911110910132116111327311010010597\n\nOutput:\nHello World\nWelcome to India\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfor _ in range(int(input())):\n code=input().strip()+'0'\n message=''\n asc=int(code[0])\n \n for i in range(len(code)-1):\n \n if int(str(asc)+code[i+1])>256:\n message+=chr(asc)\n asc=int(code[i+1])\n else: \n asc=int(str(asc)+code[i+1])\n \n print(message)\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n721011081081113287111114108100\\n871011089911110910132116111327311010010597\\n', 'output': 'Hello World\\nWelcome to India\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/CDSC2012/problems/CDS003'}","problem_id":"vfc_4222","program":"```python\nfor _ in range(int(input())):\n code=input().strip()+'0'\n message=''\n asc=int(code[0])\n \n for i in range(len(code)-1):\n \n if int(str(asc)+code[i+1])>256:\n message+=chr(asc)\n asc=int(code[i+1])\n else: \n asc=int(str(asc)+code[i+1])\n \n print(message)\n\n```","inputs":"2\n721011081081113287111114108100\n871011089911110910132116111327311010010597\n","output":"Hello World\nWelcome to India\n","actual_output":"Hello World\nWelcome to India\n","execution_success":true,"sample_index":939},{"source":"apps","task_type":"verifiable_code","in_source_id":"1346","prompt":"Solve the following coding problem using the programming language python:\n\nVK gave a problem to Chef, but Chef is too lazy, so he asked you to solve the problem for him. The statement of the problem follows.\nConsider an integer with $N$ digits (in decimal notation, without leading zeroes) $D_1, D_2, D_3, \\dots, D_N$. Here, $D_1$ is the most significant digit and $D_N$ the least significant. The weight of this integer is defined as \u2211i=2N(Di\u2212Di\u22121).\u2211i=2N(Di\u2212Di\u22121).\\sum_{i=2}^N (D_i - D_{i-1})\\,.\nYou are given integers $N$ and $W$. Find the number of positive integers with $N$ digits (without leading zeroes) and weight equal to $W$. Compute this number modulo $10^9+7$.\n\n-----Input-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The first and only line of each test case contains two space-separated integers $N$ and $W$ denoting the number of digits and the required weight.\n\n-----Output-----\nFor each test case, print a single line containing one integer \u2014 the number of $N$-digit positive integers with weight $W$, modulo $10^9+7$.\n\n-----Constraints-----\n- $1 \\le T \\le 10^5$\n- $2 \\le N \\le 10^{18}$\n- $|W| \\le 300$\n\n-----Subtasks-----\nSubtask #1 (20 points):\n- $1 \\le T \\le 10^3$\n- $2 \\le N \\le 10^3$\nSubtask #2 (80 points): original constraints\n\n-----Example Input-----\n\n1\n2 3\n\n-----Example Output-----\n\n6\n\n-----Explanation-----\nExample case 1: Remember that the digits are arranged from most significant to least significant as $D_1, D_2$. The two-digit integers with weight $3$ are $14, 25, 36, 47, 58, 69$. For example, the weight of $14$ is $D_2-D_1 = 4-1 = 3$. We can see that there are no other possible numbers.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfor _ in range(int(input())):\n n,w = map(int , input().split())\n sigma = 1\n #len(str(num)) == n and D[i] - D[i - 1] ... = w\n if(w > 9 or w < -9):\n print(0)\n continue\n sigma = pow(10,n - 2,1000000007)\n if(w >= 0):\n sigma *= (9 - w)\n else:\n sigma *= (w + 10)\n print(sigma % 1000000007)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n2 3\\n', 'output': '6\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/WGHTNUM'}","problem_id":"vfc_4226","program":"```python\nfor _ in range(int(input())):\n n,w = map(int , input().split())\n sigma = 1\n #len(str(num)) == n and D[i] - D[i - 1] ... = w\n if(w > 9 or w < -9):\n print(0)\n continue\n sigma = pow(10,n - 2,1000000007)\n if(w >= 0):\n sigma *= (9 - w)\n else:\n sigma *= (w + 10)\n print(sigma % 1000000007)\n```","inputs":"1\n2 3\n","output":"6\n","actual_output":"6\n","execution_success":true,"sample_index":940},{"source":"apps","task_type":"verifiable_code","in_source_id":"1347","prompt":"Solve the following coding problem using the programming language python:\n\nChef Watson uses a social network called ChefBook, which has a new feed consisting of posts by his friends. Each post can be characterized by f - the identifier of the friend who created the post, p - the popularity of the post(which is pre-calculated by ChefBook platform using some machine learning algorithm) and s - the contents of the post which is a string of lower and uppercase English alphabets.\nAlso, Chef has some friends, which he has marked as special.\nThe algorithm used by ChefBook for determining the order of posts in news feed is as follows:\n\n- Posts of special friends should be shown first, irrespective of popularity. Among all such posts the popular ones should be shown earlier.\n- Among all other posts, popular posts should be shown earlier.\n\nGiven, a list of identifiers of Chef's special friends and a list of posts, you have to implement this algorithm for engineers of ChefBook and output the correct ordering of posts in the new feed. \n\n-----Input-----\nFirst line contains N, number of special friends of Chef and M, the number of posts. Next line contains N integers A1, A2, ..., AN denoting the identifiers of special friends of Chef. Each of the next M lines contains a pair of integers and a string denoting f, p and s, identifier of the friend who created the post, the popularity of the post and the contents of the post, respectively. It is guaranteed that no two posts have same popularity, but the same friend might make multiple posts.\n\n-----Output-----\nOutput correct ordering of posts in news feed in M lines. Output only the contents of a post.\n\n-----Constraints-----\n- 1 \u2264 N, M \u2264 103\n- 1 \u2264 Ai, f, p \u2264 105\n- 1 \u2264 length(s) \u2264 100\n\n-----Example-----\nInput:\n2 4\n1 2\n1 1 WhoDoesntLoveChefBook\n2 2 WinterIsComing\n3 10 TheseViolentDelightsHaveViolentEnds\n4 3 ComeAtTheKingBestNotMiss\n\nOutput:\nWinterIsComing\nWhoDoesntLoveChefBook\nTheseViolentDelightsHaveViolentEnds\nComeAtTheKingBestNotMiss\n\n-----Explanation-----\n\nFirst we should show posts created by friends with identifiers 1 and 2. Among the posts by these friends, the one with more popularity should be shown first.\n\nAmong remaining posts, we show those which are more popular first.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nimport sys\nans=0\nn,m=list(map(int,input().split()))\naaaaa=100\nli=list(map(int,input().split()))\nnon_special,special=[],[]\nfor i in range(m):\n ans+=1\n f,p,s=list(map(str,input().split()))\n f=int(f)\n poww=pow(1,2)\n p=int(p)\n if f not in li:\n ans+=1\n non_special.append((p,s))\n ans-=1\n else:\n ans+=1\n special.append((p,s))\n \nnon_special.sort(reverse=True)\naaaa=pow(1,2)\nspecial.sort(reverse=True)\n\nfor temp in range(len(special)):\n ans+=1\n print(special[temp][1])\nfor temp in non_special:\n ans+=1\n print(temp[1])\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2 4\\n1 2\\n1 1 WhoDoesntLoveChefBook\\n2 2 WinterIsComing\\n3 10 TheseViolentDelightsHaveViolentEnds\\n4 3 ComeAtTheKingBestNotMiss\\n', 'output': 'WinterIsComing\\nWhoDoesntLoveChefBook\\nTheseViolentDelightsHaveViolentEnds\\nComeAtTheKingBestNotMiss\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/COOK75/problems/BOOKCHEF'}","problem_id":"vfc_4230","program":"```python\nimport sys\nans=0\nn,m=list(map(int,input().split()))\naaaaa=100\nli=list(map(int,input().split()))\nnon_special,special=[],[]\nfor i in range(m):\n ans+=1\n f,p,s=list(map(str,input().split()))\n f=int(f)\n poww=pow(1,2)\n p=int(p)\n if f not in li:\n ans+=1\n non_special.append((p,s))\n ans-=1\n else:\n ans+=1\n special.append((p,s))\n \nnon_special.sort(reverse=True)\naaaa=pow(1,2)\nspecial.sort(reverse=True)\n\nfor temp in range(len(special)):\n ans+=1\n print(special[temp][1])\nfor temp in non_special:\n ans+=1\n print(temp[1])\n```","inputs":"2 4\n1 2\n1 1 WhoDoesntLoveChefBook\n2 2 WinterIsComing\n3 10 TheseViolentDelightsHaveViolentEnds\n4 3 ComeAtTheKingBestNotMiss\n","output":"WinterIsComing\nWhoDoesntLoveChefBook\nTheseViolentDelightsHaveViolentEnds\nComeAtTheKingBestNotMiss\n","actual_output":"WinterIsComing\nWhoDoesntLoveChefBook\nTheseViolentDelightsHaveViolentEnds\nComeAtTheKingBestNotMiss\n","execution_success":true,"sample_index":941},{"source":"apps","task_type":"verifiable_code","in_source_id":"1349","prompt":"Solve the following coding problem using the programming language python:\n\nChef has a number N, Cheffina challenges the chef to check the divisibility of all the permutation of N by 3. If any of the permutations is divisible by 3 then print 1 else print 0.\n\n-----Input:-----\n- First-line will contain $T$, the number of test cases. Then the test cases follow. \n- Each test case contains a single line of input, two integers $N$. \n\n-----Output:-----\nFor each test case, output in a single line answer 1 or 0.\n\n-----Constraints-----\n- $1 \\leq T \\leq 10^6$\n- $1 \\leq N \\leq 10^6$\n\n-----Sample Input:-----\n2\n18\n308\n\n-----Sample Output:-----\n1\n0\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfrom sys import *\ninput=stdin.readline\nfor u in range(int(input())):\n s=int(input())\n if(s%3==0):\n print(1)\n else:\n print(0)\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n18\\n308\\n', 'output': '1\\n0\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/PBK32020/problems/ITGUY34'}","problem_id":"vfc_4238","program":"```python\nfrom sys import *\ninput=stdin.readline\nfor u in range(int(input())):\n s=int(input())\n if(s%3==0):\n print(1)\n else:\n print(0)\n\n```","inputs":"2\n18\n308\n","output":"1\n0\n","actual_output":"1\n0\n","execution_success":true,"sample_index":943},{"source":"apps","task_type":"verifiable_code","in_source_id":"1352","prompt":"Solve the following coding problem using the programming language python:\n\nChef is very organised in whatever he does and likes to maintain statistics of his work. Chef has expertise in web development and hence is a regular contributor on a forum. Chef sometimes makes multiple contributions in a single day.. Each day chef makes at least 1 contribution he is assigned a shade of green. The greater the number of contribution in a single day the darker shade of green he gets assigned and vice versa. Your job is to find out the number of days chef is assigned a same shade of green and print the number of times chef is assigned a unique shade of green.\n\n-----INPUT-----\nThe first line of input contains an integer T denoting the number of test cases. T test cases follow.\n\nThe first line of each test case contains an integer N denoting the number of days chef has contributed towards the forum.\n\nThe next line contains N spaced integers the number of contributions chef has made if he has made any.\n\n-----OUTPUT-----\n\nThe output will contain numbers on separate lines that show the number of individual green shades chef has earned in ascending order of intensity of the shades of green.\n\n-----CONSTRAINTS-----\n1 <= T <= 25\n\n5 <= N <= 50\n\n1 <= Ai <= 50\n\n-----EXAMPLE-----Input:\n\n1\n\n7\n\n20 6 5 3 3 1 1\nOutput:\n\n1: 2\n\n3: 2\n\n5: 1\n\n6: 1\n\n20: 1\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfrom collections import Counter\nt=int(input())\nfor i in range(t):\n k=int(input())\n l=list(map(int,input().split()))\n a=Counter(l)\n b=list(a.keys())\n b.sort()\n for x in b:\n s=str(x)+': '+str(a[x])\n print(s)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n7\\n20 6 5 3 3 1 1\\n', 'output': '1: 2\\n3: 2\\n5: 1\\n6: 1\\n20: 1\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/GSTS1601/problems/BUG2K16B'}","problem_id":"vfc_4250","program":"```python\nfrom collections import Counter\nt=int(input())\nfor i in range(t):\n k=int(input())\n l=list(map(int,input().split()))\n a=Counter(l)\n b=list(a.keys())\n b.sort()\n for x in b:\n s=str(x)+': '+str(a[x])\n print(s)\n```","inputs":"1\n7\n20 6 5 3 3 1 1\n","output":"1: 2\n3: 2\n5: 1\n6: 1\n20: 1\n","actual_output":"1: 2\n3: 2\n5: 1\n6: 1\n20: 1\n","execution_success":true,"sample_index":945},{"source":"apps","task_type":"verifiable_code","in_source_id":"1353","prompt":"Solve the following coding problem using the programming language python:\n\nYou are in the future. It's the time of autonomous cars. Switching lanes is a pretty difficult task for autonomous cars, and you have the logs from an experiment you had run with two cars. You want to verify whether the logs are corrupted, or could be valid.\nIn that experiment, you had a highway consisting of two lanes. These were represented by 2 rows of an infinite grid. The cell (1, 1) is the top left cell which is the starting point of the first lane. Cell (2, 1) is the bottom left cell of the grid which is the starting point of the second lane.\nThere are two cars, 1 and 2 that start from the cell (1, 1) and (2, 1). \nAt each instant, a car has the following choices.\n- Stay at the current position.\n- Move one cell to the right.\n- Switch Lanes. When a car switches its lane, it stays in the same column. That is, from (1, i) it could go to (2, i), or from (2, i) it could go to (1, i). But both both cars shouldn't end up at the same cell at any point. Note that there could have been a car which had moved at the very instant that you move into it.\nConsider one such scenario of driving cars.\nTime $t = 0$\n1.....\n2.....\n\nTime $t = 1$. Car 2 advances one cell right. Car 1 stays at the same place.\n1.....\n.2....\n\nTime $t = 2$. Car 2 stays at its place. Car 1 switches the lane.\n......\n12....\n\nTime $t = 3$. Car 2 moves one cell to the right. Car 1 also moves one cell to the right.\n......\n.12...\n\nTime $t = 4$. Both the cars stay in the same place.\n......\n.12...\n\nYou are given positions of the car at $n$ instants. Your task is to check whether this situation is feasible or not.\n\n-----Input-----\n- The first line of the input contains an integer $T$ denoting the number of test cases. The description of the test cases follows.\n- The first line of each test case contains an integer $n$ denoting the number of instants where the positions of the cars were recorded.\n- Each of next $n$ lines contains 5 space separated integers denoting $t_i, x_i, y_i, X_i, Y_i$ denoting time, $x$ and $y$ coordinate of the first car, and that of second car.\n\n-----Output-----\nFor each test case, output either yes or no according to the answer to the problem.\n\n-----Constraints-----\n- $1 \\le T \\le 10^5$\n- $1 \\le n \\leq 10^5$\n- $1 \\le t_i, y_i, X_i, Y_i \\leq 10^9$\n- $1 \\leq x_i \\leq 2$\n- $t_i < t_{i+1}$\n- Sum of $n$ over all the test cases doesn't exceed $10^6$\n\n-----Example Input-----\n2\n3\n1 1 1 2 2\n2 2 1 2 2\n4 2 2 2 3\n1\n1 1 3 2 2\n\n-----Example Output-----\nyes\nno\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\ndef check(px,x):\n if px[1]==x[1]:\n return (x[2]-px[2])<=(x[0]-px[0]) and (x[2]>=px[2])\n else:\n return (x[2]-px[2]+1)<=(x[0]-px[0]) and (x[2]>=px[2])\n \ndef checkdouble(px,x):\n if px[3]==x[3]:\n return (x[4]-px[4])<=(x[0]-px[0]) and (x[4]>=px[4])\n else:\n return (x[4]-px[4]+1)<=(x[0]-px[0]) and (x[4]>=px[4])\n \n\nfor _ in range(int(input())):\n px=[0,1,1,2,1]\n g=True\n for _ in range(int(input())):\n x=list(map(int,input().split()))\n if x[1]==x[3] and x[2]==x[4]:\n g=False\n if not g:\n continue\n g=check(px,x)\n if g:\n g=checkdouble(px,x)\n px=x\n if not g:\n print(\"no\")\n else:\n print(\"yes\")\n \n \n \n \n \n \n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n3\\n1 1 1 2 2\\n2 2 1 2 2\\n4 2 2 2 3\\n1\\n1 1 3 2 2\\n', 'output': 'yes\\nno\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/AUTOCARS'}","problem_id":"vfc_4254","program":"```python\n# cook your dish here\ndef check(px,x):\n if px[1]==x[1]:\n return (x[2]-px[2])<=(x[0]-px[0]) and (x[2]>=px[2])\n else:\n return (x[2]-px[2]+1)<=(x[0]-px[0]) and (x[2]>=px[2])\n \ndef checkdouble(px,x):\n if px[3]==x[3]:\n return (x[4]-px[4])<=(x[0]-px[0]) and (x[4]>=px[4])\n else:\n return (x[4]-px[4]+1)<=(x[0]-px[0]) and (x[4]>=px[4])\n \n\nfor _ in range(int(input())):\n px=[0,1,1,2,1]\n g=True\n for _ in range(int(input())):\n x=list(map(int,input().split()))\n if x[1]==x[3] and x[2]==x[4]:\n g=False\n if not g:\n continue\n g=check(px,x)\n if g:\n g=checkdouble(px,x)\n px=x\n if not g:\n print(\"no\")\n else:\n print(\"yes\")\n \n \n \n \n \n \n\n```","inputs":"2\n3\n1 1 1 2 2\n2 2 1 2 2\n4 2 2 2 3\n1\n1 1 3 2 2\n","output":"yes\nno\n","actual_output":"yes\nno\n","execution_success":true,"sample_index":946},{"source":"apps","task_type":"verifiable_code","in_source_id":"1354","prompt":"Solve the following coding problem using the programming language python:\n\nYou have a tree consisting of n vertices. You want to color each vertex of the tree in one of the k colors such that for any pair of vertices having same color, all the vertices belonging to the path joining them should also have same color. In other words, for any two vertices u, v with same color, all the vertices in the path joining them should also have color same as that of the u (or same as v, as u and v have same color). \n\nFind out possible number of ways in which you can color the tree satisfying the above property. As the answer could be large, print your answer modulo 109 + 7.\n\n-----Input-----\nThe first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.\nFor each test case, first line contains two space separated integers n, k denoting number of vertices in the tree and total number of colors, respectively\nEach of the next n - 1 lines contain two space separated integers ui, vi, denoting that there is an edge between vertices ui and vi in the tree.\n\n-----Output-----\nFor each test case, output a single line corresponding to number of ways of coloring the tree.\n\n-----Constraints-----\n- 1 \u2264 T \u2264 50\n- 1 \u2264 n, k \u2264 50\n- 1 \u2264 ui, vi \u2264 n\n- ui \u2260 vi\n\n-----Example-----\nInput\n3\n3 2\n1 2\n2 3\n3 1\n1 2\n2 3\n4 3\n1 2\n2 3\n2 4\n\nOutput:\n6\n1\n39\n\n-----Explanation-----\nIn the first example, You can color the vertices in the following 6 ways - {1, 1, 1}, {2, 2, 2}, {1, 2, 2}, {1, 1, 2}, {2, 1, 1}, {2, 2, 1}. Note that you can't color the tree in {1, 2, 1} as the vertices in the path connecting vertex 1 and 3, (i.e. 1, 2, 3) don't have same color. You can see that the color of 2nd vertex is not same as that of 1st and 3rd.\nIn the second example, Only possible coloring you can do is to color all the vertices with color 1.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nA = [0] * 100001\nM = 1000000007\n\ndef nCk(n, k):\n if k ==0 or k ==n:\n return 1\n r = (A[n-k]*A[k])%M\n x = (A[n]*pow(r, M-2, M))%M\n return x\n\nfor _ in range(int(input())):\n n, k = list(map(int, input().split()))\n for i in range(n-1):\n u,v = input().split()\n summ = 0\n A[0] = 1\n for i in range(1, len(A)):\n A[i] = (i*A[i-1])%M\n for i in range(min(n, k)):\n b = nCk(k,i+1)\n c = (nCk(n-1,i)*b)%M\n c *= A[i+1]\n summ += (c%M)\n summ %= M\n print(summ)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\n3 2\\n1 2\\n2 3\\n3 1\\n1 2\\n2 3\\n4 3\\n1 2\\n2 3\\n2 4\\n', 'output': '6\\n1\\n39\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/SNCKEL16/problems/COLTREE'}","problem_id":"vfc_4258","program":"```python\nA = [0] * 100001\nM = 1000000007\n\ndef nCk(n, k):\n if k ==0 or k ==n:\n return 1\n r = (A[n-k]*A[k])%M\n x = (A[n]*pow(r, M-2, M))%M\n return x\n\nfor _ in range(int(input())):\n n, k = list(map(int, input().split()))\n for i in range(n-1):\n u,v = input().split()\n summ = 0\n A[0] = 1\n for i in range(1, len(A)):\n A[i] = (i*A[i-1])%M\n for i in range(min(n, k)):\n b = nCk(k,i+1)\n c = (nCk(n-1,i)*b)%M\n c *= A[i+1]\n summ += (c%M)\n summ %= M\n print(summ)\n```","inputs":"3\n3 2\n1 2\n2 3\n3 1\n1 2\n2 3\n4 3\n1 2\n2 3\n2 4\n","output":"6\n1\n39\n","actual_output":"6\n1\n39\n","execution_success":true,"sample_index":947},{"source":"apps","task_type":"verifiable_code","in_source_id":"1355","prompt":"Solve the following coding problem using the programming language python:\n\nChef likes to play with array elements. His teacher has given him an array problem. But now he is busy as Christmas is coming. So, he needs your help. Can you help him to solve this problem.\nYou are given an array $(A1,A2,A3\u2026\u2026AN)$ of length $N$. You have to create an another array using the given array in the following ways:\n\nFor each valid i, the ith element of the output array will be the sum of the ith element and (A[i])th element if $A[i]$ is less equal $N$.\n\nOther wise for each valid i following the step below\n\ni) Divide the value of $A[i]$ by 2 untill it will be less than$N$.\n\nii) then find the difference ($D$) between $N$ and $A[i]$.\n\niii) the ith element of the output array will be $Dth$ element. \n\n-----Input:-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of T test cases follows. \n- The first line of each test case contains a single integer $N$. \n- The second line contains $N$ space-separated integers $A1,A2,\u2026,AN$. \n\n-----Output:-----\n- For each testcase, print new array in each line.\n\n-----Constraints-----\n- $1 \\leq T \\leq 1000$\n- $1 \\leq N \\leq 10^5$\n- $1\\leq A1,A2.....AN \\leq 10^7$\n\n-----Sample Input:-----\n2\n\n5\n\n2 4 5 7 9\n\n4\n\n5 4 2 3\n\n-----Sample Output:-----\n6 11 14 4 2\n\n4 7 6 5\n\n-----EXPLANATION:-----\nFor 1st test case: A1 = 2+4 =6, A2 = 4+7 =11 , A3 = 5+9 =14 , A4 > N (5) ,So A4/2 = 3 then A4 = A[5 -3] , A4=A[2]=4, And A5 =A[1]=2. Then array becomes 6,11,14,4,2.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\ndef index(n,val):\n while(val >= n):\n val = val//2\n return n - val\nt = int(input())\nfor _ in range(t):\n n = int(input())\n arr = list(map(int,input().split())) \n new = [0 for i in range(n)]\n for i in range(n):\n if arr[i]<=n :\n new[i] = arr[i] + arr[arr[i]-1]\n else:\n new[i] = arr[index(n,arr[i]) - 1]\n print(*new)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n5\\n2 4 5 7 9\\n4\\n5 4 2 3\\n', 'output': '6 11 14 4 2\\n4 7 6 5\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/NOOB2020/problems/NBC006'}","problem_id":"vfc_4262","program":"```python\n# cook your dish here\ndef index(n,val):\n while(val >= n):\n val = val//2\n return n - val\nt = int(input())\nfor _ in range(t):\n n = int(input())\n arr = list(map(int,input().split())) \n new = [0 for i in range(n)]\n for i in range(n):\n if arr[i]<=n :\n new[i] = arr[i] + arr[arr[i]-1]\n else:\n new[i] = arr[index(n,arr[i]) - 1]\n print(*new)\n```","inputs":"2\n5\n2 4 5 7 9\n4\n5 4 2 3\n","output":"6 11 14 4 2\n4 7 6 5\n","actual_output":"6 11 14 4 2\n4 7 6 5\n","execution_success":true,"sample_index":948},{"source":"apps","task_type":"verifiable_code","in_source_id":"1356","prompt":"Solve the following coding problem using the programming language python:\n\nChef is good at making pancakes. Generally he gets requests to serve N pancakes at once.\nHe serves them in the form of a stack.\nA pancake can be treated as a circular disk with some radius.\nChef needs to take care that when he places a pancake on the top of the stack the radius of the pancake should not exceed the radius of the largest pancake in the stack by more than 1. \nAdditionally all radii should be positive integers, and the bottom most pancake should have its radius as 1.\nChef wants you to find out in how many ways can he create a stack containing N pancakes.\nInput\nFirst line of the input contains T (T <= 1000) denoting the number of test cases.\nT lines follow each containing a single integer N (1 <= N <= 1000) denoting the size of the required stack.\nOutput\nFor each case the output should be a single integer representing the number of ways a stack of size N can be created. As the answer can be large print it modulo 1000000007.\nExample\nInput\n2\n1\n2\n\nOutput\n1\n2\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nt=[[1]]\ndef bell_numbers(start, stop):\n ## Swap start and stop if start > stop\n if stop < start: start, stop = stop, start\n if start < 1: start = 1\n if stop < 1: stop = 1\n c = 1 ## Bell numbers count\n while c <= stop:\n if c >= start:\n yield t[-1][0] ## Yield the Bell number of the previous \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0row\n row = [t[-1][-1]] ## Initialize a new row\n for b in t[-1]:\n row.append((row[-1] + b)%1000000007)\n c += 1 ## We have found another Bell number\n t.append(row) ## Append the row to the triangle\n\nar=[0]*1001\ni=0\nfor b in bell_numbers(1,1001):\n ar[i]=b\n i+=1\nT=eval(input())\nwhile T:\n N=eval(input())\n print(ar[N])\n T-=1\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n1\\n2\\n', 'output': '1\\n2\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/APRIL12/problems/PANSTACK'}","problem_id":"vfc_4266","program":"```python\nt=[[1]]\ndef bell_numbers(start, stop):\n ## Swap start and stop if start > stop\n if stop < start: start, stop = stop, start\n if start < 1: start = 1\n if stop < 1: stop = 1\n c = 1 ## Bell numbers count\n while c <= stop:\n if c >= start:\n yield t[-1][0] ## Yield the Bell number of the previous \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0row\n row = [t[-1][-1]] ## Initialize a new row\n for b in t[-1]:\n row.append((row[-1] + b)%1000000007)\n c += 1 ## We have found another Bell number\n t.append(row) ## Append the row to the triangle\n\nar=[0]*1001\ni=0\nfor b in bell_numbers(1,1001):\n ar[i]=b\n i+=1\nT=eval(input())\nwhile T:\n N=eval(input())\n print(ar[N])\n T-=1\n\n```","inputs":"2\n1\n2\n","output":"1\n2\n","actual_output":"1\n2\n","execution_success":true,"sample_index":949},{"source":"apps","task_type":"verifiable_code","in_source_id":"1357","prompt":"Solve the following coding problem using the programming language python:\n\nChef owns an icecream shop in Chefland named scoORZ. There are only three types of coins in Chefland: Rs. 5, Rs. 10 and Rs. 15. An icecream costs Rs. 5.\nThere are $N$ people (numbered $1$ through $N$) standing in a queue to buy icecream from scoORZ. Each person wants to buy exactly one icecream. For each valid $i$, the $i$-th person has one coin with value $a_i$. It is only possible for someone to buy an icecream when Chef can give them back their change exactly \u2015 for example, if someone pays with a Rs. 10 coin, Chef needs to have a Rs. 5 coin that he gives to this person as change.\nInitially, Chef has no money. He wants to know if he can sell icecream to everyone in the queue, in the given order. Since he is busy eating his own icecream, can you tell him if he can serve all these people?\n\n-----Input-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The first line of each test case contains a single integer $N$.\n- The second line contains $N$ space-separated integers $a_1, a_2, \\ldots, a_N$.\n\n-----Output-----\nFor each test case, print a single line containing the string \"YES\" if all people can be served or \"NO\" otherwise (without quotes).\n\n-----Constraints-----\n- $1 \\le T \\le 100$\n- $1 \\le N \\le 10^3$\n- $a_i \\in \\{5, 10, 15\\}$ for each valid $i$\n\n-----Subtasks-----\nSubtask #1 (40 points): $a_i \\in \\{5, 10\\}$ for each valid $i$\nSubtask #2 (60 points): original constraints\n\n-----Example Input-----\n3\n2\n5 10\n2\n10 5\n2\n5 15\n\n-----Example Output-----\nYES\nNO\nNO\n\n-----Explanation-----\nExample case 1: The first person pays with a Rs. 5 coin. The second person pays with a Rs. 10 coin and Chef gives them back the Rs. 5 coin (which he got from the first person) as change.\nExample case 2: The first person already cannot buy an icecream because Chef cannot give them back Rs. 5.\nExample case 3: The first person pays with a Rs. 5 coin. The second person cannot buy the icecream because Chef has only one Rs. 5 coin, but he needs to give a total of Rs. 10 back as change.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\nfor _ in range(int(input())):\n n=int(input())\n lst=list(map(int,input().split()))\n f=0\n t=0\n p=1\n for i in lst:\n if(i==5):\n f+=1\n elif(i==10):\n if(f>0):\n f-=1\n t+=1\n else:\n p=0\n break\n else:\n if(t>0):\n t-=1\n else:\n if(f>1):\n f-=2\n else:\n p=0\n break\n if(p==1):\n print(\"YES\")\n else:\n print(\"NO\")\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\n2\\n5 10\\n2\\n10 5\\n2\\n5 15\\n\\n', 'output': 'YES\\nNO\\nNO\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/CHFICRM'}","problem_id":"vfc_4270","program":"```python\n# cook your dish here\nfor _ in range(int(input())):\n n=int(input())\n lst=list(map(int,input().split()))\n f=0\n t=0\n p=1\n for i in lst:\n if(i==5):\n f+=1\n elif(i==10):\n if(f>0):\n f-=1\n t+=1\n else:\n p=0\n break\n else:\n if(t>0):\n t-=1\n else:\n if(f>1):\n f-=2\n else:\n p=0\n break\n if(p==1):\n print(\"YES\")\n else:\n print(\"NO\")\n```","inputs":"3\n2\n5 10\n2\n10 5\n2\n5 15\n\n","output":"YES\nNO\nNO\n","actual_output":"YES\nNO\nNO\n","execution_success":true,"sample_index":950},{"source":"apps","task_type":"verifiable_code","in_source_id":"1358","prompt":"Solve the following coding problem using the programming language python:\n\nChef Al Gorithm was reading a book about climate and oceans when he encountered the word \u201cglaciological\u201d. He thought it was quite curious, because it has the following interesting property: For every two letters in the word, if the first appears x times and the second appears y times, then |x - y| \u2264 1.\nChef Al was happy about this and called such words 1-good words. He also generalized the concept: He said a word was K-good if for every two letters in the word, if the first appears x times and the second appears y times, then |x - y| \u2264 K.\nNow, the Chef likes K-good words a lot and so was wondering: Given some word w, how many letters does he have to remove to make it K-good?\n\n-----Input-----\nThe first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.\nEach test case consists of a single line containing two things: a word w and an integer K, separated by a space.\n\n-----Output-----\nFor each test case, output a single line containing a single integer: the minimum number of letters he has to remove to make the word K-good.\n\n-----Constraints-----\n- 1 \u2264 T \u2264 30\n- 1 \u2264 |w| \u2264 105\n- 0 \u2264 K \u2264 105\n- w contains only lowercase English letters.\n\n-----Example-----\nInput:\n4\nglaciological 1\nteammate 0\npossessions 3\ndefenselessness 3\n\nOutput:\n0\n0\n1\n2\n\n-----Explanation-----\nExample case 1. The word \u201cglaciological\u201d is already 1-good, so the Chef doesn't have to remove any letter.\nExample case 2. Similarly, \u201cteammate\u201d is already 0-good.\nExample case 3. The word \u201cpossessions\u201d is 4-good. To make it 3-good, the Chef can remove the last s to make \u201cpossession\u201d.\nExample case 4. The word \u201cdefenselessness\u201d is 4-good. To make it 3-good, Chef Al can remove an s and an e to make, for example, \u201cdefenslesness\u201d. Note that the word doesn't have to be a valid English word.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\nimport bisect\n\nfor _ in range(int(input())):\n w,k=map(str, input().split())\n k=int(k)\n n=len(w)\n w=list(w)\n w.sort()\n w.append('0')\n c=1\n l=0\n l1=[]\n l2=[]\n for i in range(1, n+1):\n if w[i]==w[i-1]:\n c+=1\n else:\n a=bisect.bisect_left(l1, c)\n if a==l:\n l1.append(c)\n l2.append(1)\n l+=1\n elif l1[a]==c:\n l2[a]=l2[a]+1\n else:\n l1.insert(a, c)\n l2.insert(a, 1)\n l+=1\n c=1\n a=l1[-1]-l1[0]\n if a<=k:\n print(0)\n else:\n ans=n \n for i in range(l):\n temp=l2[i]*l1[i]\n for j in range(i+1, l):\n p=l1[j]-l1[i]\n if p<=k:\n temp+=(l2[j]*l1[j])\n else:\n p1=p-k\n temp+=(l2[j]*(l1[j]-p1))\n ans=min(ans, (n-temp))\n \n print(ans)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '4\\nglaciological 1\\nteammate 0\\npossessions 3\\ndefenselessness 3\\n', 'output': '0\\n0\\n1\\n2\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/KGOOD'}","problem_id":"vfc_4274","program":"```python\n# cook your dish here\nimport bisect\n\nfor _ in range(int(input())):\n w,k=map(str, input().split())\n k=int(k)\n n=len(w)\n w=list(w)\n w.sort()\n w.append('0')\n c=1\n l=0\n l1=[]\n l2=[]\n for i in range(1, n+1):\n if w[i]==w[i-1]:\n c+=1\n else:\n a=bisect.bisect_left(l1, c)\n if a==l:\n l1.append(c)\n l2.append(1)\n l+=1\n elif l1[a]==c:\n l2[a]=l2[a]+1\n else:\n l1.insert(a, c)\n l2.insert(a, 1)\n l+=1\n c=1\n a=l1[-1]-l1[0]\n if a<=k:\n print(0)\n else:\n ans=n \n for i in range(l):\n temp=l2[i]*l1[i]\n for j in range(i+1, l):\n p=l1[j]-l1[i]\n if p<=k:\n temp+=(l2[j]*l1[j])\n else:\n p1=p-k\n temp+=(l2[j]*(l1[j]-p1))\n ans=min(ans, (n-temp))\n \n print(ans)\n```","inputs":"4\nglaciological 1\nteammate 0\npossessions 3\ndefenselessness 3\n","output":"0\n0\n1\n2\n","actual_output":"0\n0\n1\n2\n","execution_success":true,"sample_index":951},{"source":"apps","task_type":"verifiable_code","in_source_id":"1359","prompt":"Solve the following coding problem using the programming language python:\n\nThere is a task in Among Us in which $N$ temperature scale with unique readings are given and you have to make all of them equal. In one second you can choose an odd number and add or subtract that number in any one temperature value. Find minimum time (in seconds) required to complete the task.\n$Note$: Equal value may or may not belong to array.\n\n-----Input:-----\n- First line will contain $T$, number of testcases. Then the testcases follow. \n- First line of each testcase contains single integer $N$, the number of temperature scales\n- Next line contain $A_i$ for $1 \\leq i \\leq N$, reading of temperature scales\n\n-----Output:-----\nFor each testcase, output a single line the time (in seconds) required to complete the task.\n\n-----Constraints-----\n- $1 \\leq T \\leq 10^3$\n- $1 \\leq N \\leq 10^3$\n- $0 \\leq A_i \\leq 10^9$\n\n-----Sample Input:-----\n3\n\n5\n\n1 2 3 4 5\n\n4\n\n5 2 3 8\n\n2\n\n50 53 \n\n-----Sample Output:-----\n5\n\n4\n\n1 \n\n-----EXPLANATION:-----\n- In the $2^{nd}$ test case we need $2$ seconds to change $2$ to $8$ , $1$ second to change $3$ and $5$ to $8$ . So total time required is $2+1+1=4$ seconds.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\nfor _ in range(int(input())):\n n=int(input())\n ar=list(map(int,input().split()))\n odd=0\n even=0\n if n==1:\n print(0)\n continue\n for i in range(n):\n if ar[i]%2==1:\n odd+=1\n else:\n even+=1\n if odd>0:\n vo=(odd-1)*2+even\n else:\n vo=even\n if even>0:\n ve=(even-1)*2+odd\n else:\n ve=odd\n print(min(vo,ve))\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\n5\\n1 2 3 4 5\\n4\\n5 2 3 8\\n2\\n50 53\\n', 'output': '5\\n4\\n1\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/RC152020/problems/REC15A'}","problem_id":"vfc_4278","program":"```python\n# cook your dish here\nfor _ in range(int(input())):\n n=int(input())\n ar=list(map(int,input().split()))\n odd=0\n even=0\n if n==1:\n print(0)\n continue\n for i in range(n):\n if ar[i]%2==1:\n odd+=1\n else:\n even+=1\n if odd>0:\n vo=(odd-1)*2+even\n else:\n vo=even\n if even>0:\n ve=(even-1)*2+odd\n else:\n ve=odd\n print(min(vo,ve))\n\n```","inputs":"3\n5\n1 2 3 4 5\n4\n5 2 3 8\n2\n50 53\n","output":"5\n4\n1\n","actual_output":"5\n4\n1\n","execution_success":true,"sample_index":952},{"source":"apps","task_type":"verifiable_code","in_source_id":"1360","prompt":"Solve the following coding problem using the programming language python:\n\nWatson gives to Sherlock two strings S1 and S2 consisting of uppercase English alphabets. Next he wants Sherlock to build a flower in the following way:\n\nHe puts both strings perpendicular to each other in such a way that they overlap at the same character. For example, if he has two strings \"ABCDEF\" and \"XXBCZQ\", one possible way to make a flower is:\n\nLength of petals in the above flower are 2, 2, 3 and 3.\nA flower's ugliness is sum of absolute difference of adjacent petal lengths i.e. i.e. if adjacent petal lengths are L1, L2, L3, L4, then ugliness of flower is |L1 - L2| + |L2 - L3| + |L3 - L4| + |L4 - L1|. \nSherlock wants to find minimum value of ugliness if we consider all possible flower configurations. Note that a configuration is valid even if any of the petal length is 0.\n\n-----Input-----\nFirst line contains T, number of test cases. Each test case consists of string S1 in one line followed by string S2 in the next line. It is guaranteed that there exists at least one possible way to make a flower.\n\n-----Output-----\nFor each test case, output in one line the required answer.\n\n-----Constraints-----\n- 1 \u2264 T \u2264 10\n- 1 \u2264 length(S1), length(S2) \u2264 105\n\n-----Example-----\nInput:\n2\nABCDE\nXXBCZQ\nBBB\nBBBBBB\n\nOutput: \n2\n6\n\n-----Explanation-----\n\nTest case 1:\n\nIf we keep the configuration shown in statement, the ugliness is 2, which is minimum possible.\n\nTest case 2:\n\nOne of the best configurations is\n\nB \nB B B B B B\nB\n\nwhere petal lengths are 1, 3, 1, 2.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfor _ in range(eval(input())):\n S1=input()\n m1=len(S1)/2\n\n S2=input()\n m2=len(S2)/2\n d1={}\n d2={}\n for i in range(len(S1)):\n c=S1[i]\n v=abs(m1-i)\n if c in d1:\n if v0:\n ans = (ans*aans)%val\n aans = (aans*aans)%val\n b/=2\n return ans%val\n \n\n\nfor i in range(eval(input())): \n n,d= list(map(int,input().split()))\n a=int(str(d)*n)\n sqr = str(a*a)\n ans =0\n count=0\n for ii in sqr :\n ans= ans+int(ii)*23**count\n count+=1\n z=int(ii)*ans\n print(ans % (10**9+7))\n \n \n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\n1 4\\n3 6\\n3 5\\n', 'output': '139\\n40079781\\n32745632\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/LTIME29/problems/FSTSQ'}","problem_id":"vfc_4294","program":"```python\nval = 10**9 + 7\ndef MOD(a,b):\n aans = a\n ans = 1\n while b>0:\n ans = (ans*aans)%val\n aans = (aans*aans)%val\n b/=2\n return ans%val\n \n\n\nfor i in range(eval(input())): \n n,d= list(map(int,input().split()))\n a=int(str(d)*n)\n sqr = str(a*a)\n ans =0\n count=0\n for ii in sqr :\n ans= ans+int(ii)*23**count\n count+=1\n z=int(ii)*ans\n print(ans % (10**9+7))\n \n \n\n```","inputs":"3\n1 4\n3 6\n3 5\n","output":"139\n40079781\n32745632\n","actual_output":"139\n40079781\n32745632\n","execution_success":true,"sample_index":956},{"source":"apps","task_type":"verifiable_code","in_source_id":"1364","prompt":"Solve the following coding problem using the programming language python:\n\nChef has $N$ points (numbered $1$ through $N$) in a 2D Cartesian coordinate system. For each valid $i$, the $i$-th point is $(x_i, y_i)$. He also has a fixed integer $c$ and he may perform operations of the following type: choose a point $(x_i, y_i)$ and move it to $(x_i + c, y_i + c)$ or $(x_i - c, y_i - c)$.\nNow, Chef wants to set up one or more checkpoints (points in the same coordinate system) and perform zero or more operations in such a way that after they are performed, each of his (moved) $N$ points is located at one of the checkpoints.\nChef's primary objective is to minimise the number of checkpoints. Among all options with this minimum number of checkpoints, he wants to choose one which minimises the number of operations he needs to perform.\nCan you help Chef find the minimum number of required checkpoints and the minimum number of operations he needs to perform to move all $N$ points to these checkpoints?\n\n-----Input-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The first line of each test case contains two space-separated integers $N$ and $c$.\n- $N$ lines follow. For each valid $i$, the $i$-th of these lines contains two space-separated integers $x_i$ and $y_i$.\n\n-----Output-----\nFor each test case, print a single line containing two integers \u2015 the minimum number of checkpoints and the minimum number of moves.\n\n-----Constraints-----\n- $1 \\le T \\le 5$\n- $1 \\le N \\le 5 \\cdot 10^5$\n- $|x_i|, |y_i| \\le 10^9$ for each valid $i$\n- $0 < c \\le 10^9$\n- the sum of $N$ over all test cases does not exceed $5 \\cdot 10^5$\n\n-----Example Input-----\n1\n3 1\n1 1\n1 0\n3 2\n\n-----Example Output-----\n2 2\n\n-----Explanation-----\nExample case 1: One optimal solution is to set up checkpoints at coordinates $(1, 1)$ and $(1, 0)$. Since the points $(1, 1)$ and $(1, 0)$ are already located at checkpoints, Chef can just move the point $(3, 2)$ to the checkpoint $(1, 0)$ in two moves: $(3, 2) \\rightarrow (2, 1) \\rightarrow (1, 0)$.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nt = int(input())\n\nfor i in range(t):\n n, c = list(map(int,input().split()))\n\n pts = {}\n moves = 0\n\n for i in range(n):\n x, y = list(map(int,input().split()))\n if (y-x,x%c) in pts:\n pts[(y-x,x%c)].append(x)\n else:\n pts[(y-x,x%c)] = [x]\n \n for i in pts:\n arc = sorted(pts[i])\n \n for j in arc:\n moves = moves + abs((j-arc[len(arc)//2]))//c\n \n print(len(pts),moves)\n\n\n \n\n\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n3 1\\n1 1\\n1 0\\n3 2\\n', 'output': '2 2\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/CHKPTS'}","problem_id":"vfc_4298","program":"```python\nt = int(input())\n\nfor i in range(t):\n n, c = list(map(int,input().split()))\n\n pts = {}\n moves = 0\n\n for i in range(n):\n x, y = list(map(int,input().split()))\n if (y-x,x%c) in pts:\n pts[(y-x,x%c)].append(x)\n else:\n pts[(y-x,x%c)] = [x]\n \n for i in pts:\n arc = sorted(pts[i])\n \n for j in arc:\n moves = moves + abs((j-arc[len(arc)//2]))//c\n \n print(len(pts),moves)\n\n\n \n\n\n\n```","inputs":"1\n3 1\n1 1\n1 0\n3 2\n","output":"2 2\n","actual_output":"2 2\n","execution_success":true,"sample_index":957},{"source":"apps","task_type":"verifiable_code","in_source_id":"1366","prompt":"Solve the following coding problem using the programming language python:\n\nMaster Shifu is training Po to become The Dragon Warrior and as a final assignment he must obtain maximum deliciousness from dumplings. There are $N$ plates of dumplings in front of him with deliciousness $A_1, A_2, \\ldots, A_N$, Po can choose any number of continuous plates of dumplings. The total deliciousness is the sum of deliciousness of all the chosen dumplings.\nWhat is the minimum number of plates he must choose so that total deliciousness is maximum possible?\nNote: Po must choose atleast one plate.\n\n-----Input:-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The first line of each test case contains a single integer $N$.\n- The second line contains $N$ space-separated integers $A_1, A_2, \\ldots, A_N$.\n\n-----Output:-----\nFor each test case, print a single line containing one integer.\n\n-----Constraints-----\n- $1 \\le T \\le 10$\n- $1 \\le N \\le 2 \\cdot 10^5$\n- $0 \\le A_i \\le 10^9$\n\n-----Sample Input:-----\n2\n4\n1 2 3 4\n5\n3 2 0 3 0\n\n-----Sample Output:-----\n4\n4\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\nN=int(input())\nfor _ in range(N):\n n=int(input())\n arr=list(map(int,input().split()))[:n]\n count=0\n last=0\n for i in range(n):\n if(arr[i]!=0):\n break\n last=i\n count+=1\n for i in arr[-1:last:-1]:\n if(i!=0):\n break\n count+=1\n ans=n-count\n if(ans==0):\n print(1)\n else:\n print(ans)\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n4\\n1 2 3 4\\n5\\n3 2 0 3 0\\n', 'output': '4\\n4\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/ALRA2020/problems/ALR20A'}","problem_id":"vfc_4306","program":"```python\n# cook your dish here\nN=int(input())\nfor _ in range(N):\n n=int(input())\n arr=list(map(int,input().split()))[:n]\n count=0\n last=0\n for i in range(n):\n if(arr[i]!=0):\n break\n last=i\n count+=1\n for i in arr[-1:last:-1]:\n if(i!=0):\n break\n count+=1\n ans=n-count\n if(ans==0):\n print(1)\n else:\n print(ans)\n\n```","inputs":"2\n4\n1 2 3 4\n5\n3 2 0 3 0\n","output":"4\n4\n","actual_output":"4\n4\n","execution_success":true,"sample_index":959},{"source":"apps","task_type":"verifiable_code","in_source_id":"1368","prompt":"Solve the following coding problem using the programming language python:\n\nThe students of Codechef Middle School are visiting an amusement park. The children want to go on a ride, however, there is a minimum height requirement of $X$ cm. Determine if the children are eligible to go on the ride. \nPrint \"Yes\" if they are eligible, \"No\" otherwise.\n\n-----Input:-----\n- First line will contain $T$, number of testcases. Then the testcases follow. \n- Each testcase contains of a single line of input, two integers $H$ which is a child's height in cm and $X$ which is the minimum permissible height. \n\n-----Output:-----\nFor each testcase, output in a single line $\"Yes\"$ or $\"No\"$. You cannot give your answer as \"YeS\", \"YES\", \"yes\" or any other variation.\n\n-----Constraints-----\n- $1 \\leq T \\leq 10^4$\n- $50 \\leq H \\leq 200$\n- $50 \\leq X \\leq 200$\n\n-----Sample Input:-----\n2\n120 100\n90 100\n\n-----Sample Output:-----\nYes\nNo\n\n-----EXPLANATION:-----\nThe first child has height more than minimum permissible height, so he can go on the ride while the other person cannot!\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\nfor _ in range(int(input())):\n h,x=map(int,input().split())\n if(h>=x):\n print(\"Yes\")\n else:\n print(\"No\")\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n120 100\\n90 100\\n', 'output': 'Yes\\nNo\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/ENNO2020/problems/ECNOV09'}","problem_id":"vfc_4314","program":"```python\n# cook your dish here\nfor _ in range(int(input())):\n h,x=map(int,input().split())\n if(h>=x):\n print(\"Yes\")\n else:\n print(\"No\")\n```","inputs":"2\n120 100\n90 100\n","output":"Yes\nNo\n","actual_output":"Yes\nNo\n","execution_success":true,"sample_index":960},{"source":"apps","task_type":"verifiable_code","in_source_id":"1369","prompt":"Solve the following coding problem using the programming language python:\n\nChef Vivek is good in mathematics and likes solving problems on prime numbers. One day his friend Jatin told him about Victory numbers. Victory number can be defined as a number formed after summing up all the prime numbers till given number n. Now, chef Vivek who is very fond of solving questions on prime numbers got busy in some other tasks. Your task is to help him finding victory number.\n\n-----Input:-----\n- First line will contain $T$, number of test cases. Then the test cases follow. \n- Each test case contains of a single line of input $N$ till which sum of all prime numbers between 1 to n has to be calculated.\n\n-----Output:-----\nFor each test case, output in a single line answer to the victory number.\n\n-----Constraints-----\n- $1 <= T <= 1000$\n- $1 <= N <= 10^6$\n\n-----Sample Input:-----\n3\n22\n13\n10\n\n-----Sample Output:-----\n77\n41\n17\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfrom math import sqrt \n\ntest = int(input())\nfor i in range(test):\n sum = 0\n max = int(input())\n if max==1:\n sum = 0\n elif max==2:\n sum += 2\n else: \n sum = sum + 2\n for x in range(3,max+1):\n half = int(sqrt(x)) + 1\n if all(x%y!=0 for y in range(2,half)):\n sum = sum + x\n print(sum) \n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\n22\\n13\\n10\\n', 'output': '77\\n41\\n17\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/BGS12020/problems/BSP1'}","problem_id":"vfc_4318","program":"```python\nfrom math import sqrt \n\ntest = int(input())\nfor i in range(test):\n sum = 0\n max = int(input())\n if max==1:\n sum = 0\n elif max==2:\n sum += 2\n else: \n sum = sum + 2\n for x in range(3,max+1):\n half = int(sqrt(x)) + 1\n if all(x%y!=0 for y in range(2,half)):\n sum = sum + x\n print(sum) \n```","inputs":"3\n22\n13\n10\n","output":"77\n41\n17\n","actual_output":"77\n41\n17\n","execution_success":true,"sample_index":961},{"source":"apps","task_type":"verifiable_code","in_source_id":"1370","prompt":"Solve the following coding problem using the programming language python:\n\nYou were strolling outside the restaurant at the end of the universe. On a metaspiral path you stumble upon a weird device which takes a three-digit number as input and processes it. The Hitchhiker's guide to the galaxy explains that it processes the input in the following manner: \n- Multiplies it with 13, followed by 11 and then 7 \n- Outputs all the distinct three-digit numbers possible from the digits of the new number (each digit can only be used once) \nYour friend Zaphod is in a playful mood, and does the following with the device- \n- Given a three-digit positive number $K$, he feeds it to the device for processing. \n- He then takes the numbers it gives as output, and send each of them through the device and again collect all the numbers sent out. \n- Repeats the above step $N$ times. \nTo test your wit, he challenges you to find the number of distinct 3-digit numbers which the device outputs over the $N$ steps. Can you?\n\n-----Input:-----\n- First line will contain $T$, number of testcases. Then the testcases follow.\n- Each testcase contains of a single line of input, two integers $K, N$.\n\n-----Output:-----\nFor each testcase, output a single integer denoting the number of distinct 3-digit numbers which the device outputs over the $N$ steps.\n\n-----Constraints-----\n- $1 \\leq T \\leq 1000$ \n- $5 \\leq N \\leq 10^9$ \n- Each digit of $K$ is non-zero \n\n-----Sample Input:-----\n1\n\n123 5 \n\n-----Sample Output:-----\n27\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfor _ in range(int(input())):\n k, n = input().split()\n\n while int(n) >= 5:\n print(len(set(k)) ** 3)\n break\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n123 5\\n', 'output': '27\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/ICL1901'}","problem_id":"vfc_4322","program":"```python\nfor _ in range(int(input())):\n k, n = input().split()\n\n while int(n) >= 5:\n print(len(set(k)) ** 3)\n break\n```","inputs":"1\n123 5\n","output":"27\n","actual_output":"27\n","execution_success":true,"sample_index":962},{"source":"apps","task_type":"verifiable_code","in_source_id":"1371","prompt":"Solve the following coding problem using the programming language python:\n\nGru has not been in the limelight for a long time and is, therefore, planning something particularly nefarious. Frustrated by his minions' incapability which has kept him away from the limelight, he has built a transmogrifier \u2014 a machine which mutates minions.\n\nEach minion has an intrinsic characteristic value (similar to our DNA), which is an integer. The transmogrifier adds an integer K to each of the minions' characteristic value. \n\nGru knows that if the new characteristic value of a minion is divisible by 7, then it will have Wolverine-like mutations.\n\nGiven the initial characteristic integers of N minions, all of which are then transmogrified, find out how many of them become Wolverine-like.\n\n-----Input Format:-----\nThe first line contains one integer, T, which is the number of test cases. Each test case is then described in two lines.\nThe first line contains two integers N and K, as described in the statement.\nThe next line contains N integers, which denote the initial characteristic values for the minions.\n\n-----Output Format:-----\nFor each testcase, output one integer in a new line, which is the number of Wolverine-like minions after the transmogrification.\n\n-----Constraints:-----\n- 1 \u2264 T \u2264 100\n- 1 \u2264 N \u2264 100\n- 1 \u2264 K \u2264 100\n- All initial characteristic values lie between 1 and 105, both inclusive.\n\n-----Example-----\nInput:\n1\n5 10\n2 4 1 35 1\n\nOutput:\n1\n\n-----Explanation:-----\nAfter transmogrification, the characteristic values become {12,14,11,45,11}, out of which only 14 is divisible by 7. So only the second minion becomes Wolverine-like.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfor i in range(int(input())):\n yy=input()\n y=[int(e) for e in yy.split()]\n zz=input()\n z=[int(e) for e in zz.split()]\n count=0\n for i in z:\n a=i+y[1]\n if a%7==0:\n count+=1\n print(count)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n5 10\\n2 4 1 35 1\\n', 'output': '1\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/CHN15A'}","problem_id":"vfc_4326","program":"```python\nfor i in range(int(input())):\n yy=input()\n y=[int(e) for e in yy.split()]\n zz=input()\n z=[int(e) for e in zz.split()]\n count=0\n for i in z:\n a=i+y[1]\n if a%7==0:\n count+=1\n print(count)\n```","inputs":"1\n5 10\n2 4 1 35 1\n","output":"1\n","actual_output":"1\n","execution_success":true,"sample_index":963},{"source":"apps","task_type":"verifiable_code","in_source_id":"1372","prompt":"Solve the following coding problem using the programming language python:\n\nThe Jones Trucking Company tracks the location of each of its trucks on a grid similar to an (x, y) plane. The home office is at the location (0, 0). Read the coordinates of truck A and the coordinates of truck B and determine which is closer to the office.\n\n-----Input:-----\nThe first line of the data set for this problem is an integer representing the number of collections of data that follow. Each collection contains 4 integers: the x-coordinate and then the \ny-coordinate of truck A followed by the x-coordinate and then the y-coordinate of truck B.\n\n-----Output:-----\nAll letters are upper case.\nThe output is to be formatted exactly like that for the sample output given below.\n\n-----Assumptions:-----\nThe x-coordinate is in the range \u201320 .. 20. The y-coordinate is in the range \u201320 .. 20.\n\n-----Discussion:-----\nThe distance between point #1 with coordinates (x1, y1) and point #2 with coordinates (x2, y2) is:\n\n-----Sample Input:-----\n4\n3 -2 -5 -3\n0 6 1 2\n-7 8 4 -1\n3 3 -2 2\n\n-----Sample Output:-----\nA IS CLOSER\nB IS CLOSER\nB IS CLOSER\nB IS CLOSER\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\ntry:\n t = int(input())\n for i in range(t):\n ar=list(map(int,input().split()))\n if (ar[0]**2 + ar[1]**2 > ar[2]**2 + ar[3]**2):\n print(\"B IS CLOSER\")\n else:\n print(\"A IS CLOSER\")\n \n \n \nexcept:\n pass\n \n \n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '4\\n3 -2 -5 -3\\n0 6 1 2\\n-7 8 4 -1\\n3 3 -2 2\\n', 'output': 'A IS CLOSER\\nB IS CLOSER\\nB IS CLOSER\\nB IS CLOSER\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/QTCC2020/problems/VIEW2002'}","problem_id":"vfc_4330","program":"```python\n# cook your dish here\ntry:\n t = int(input())\n for i in range(t):\n ar=list(map(int,input().split()))\n if (ar[0]**2 + ar[1]**2 > ar[2]**2 + ar[3]**2):\n print(\"B IS CLOSER\")\n else:\n print(\"A IS CLOSER\")\n \n \n \nexcept:\n pass\n \n \n\n```","inputs":"4\n3 -2 -5 -3\n0 6 1 2\n-7 8 4 -1\n3 3 -2 2\n","output":"A IS CLOSER\nB IS CLOSER\nB IS CLOSER\nB IS CLOSER\n","actual_output":"A IS CLOSER\nB IS CLOSER\nB IS CLOSER\nB IS CLOSER\n","execution_success":true,"sample_index":964},{"source":"apps","task_type":"verifiable_code","in_source_id":"1373","prompt":"Solve the following coding problem using the programming language python:\n\nChef made $N$ pieces of cakes, numbered them $1$ through $N$ and arranged them in a row in this order. There are $K$ possible types of flavours (numbered $1$ through $K$); for each valid $i$, the $i$-th piece of cake has a flavour $A_i$.\nChef wants to select a contiguous subsegment of the pieces of cake such that there is at least one flavour which does not occur in that subsegment. Find the maximum possible length of such a subsegment of cakes.\n\n-----Input-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The first line of each test case contains two integers $N$ and $K$.\n- The second line contains $N$ space-separated integers $A_1, A_2, \\ldots, A_N$.\n\n-----Output-----\nFor each test case, print a single line containing one integer \u2015 the maximum length of a valid subsegment.\n\n-----Constraints-----\n- $1 \\le T \\le 1,000$\n- $1 \\le N \\le 10^5$\n- $2 \\le K \\le 10^5$\n- $1 \\le A_i \\le K$ for each valid $i$\n- the sum of $N$ over all test cases does not exceed $10^6$\n\n-----Subtasks-----\nSubtask #1 (50 points):\n- $N \\le 10^3$\n- $K = 2$\n- the sum of $N$ over all test cases does not exceed $10^4$\nSubtask #2 (50 points): original constraints\n\n-----Example Input-----\n2\n6 2\n1 1 1 2 2 1\n5 3\n1 1 2 2 1\n\n-----Example Output-----\n3\n5\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\ndef main():\n t= int(input())\n while(t!=0):\n n,k = list(map(int , input().split()))\n arr = list(map(int, input().split()))\n freq = [0]*100001\n k=k-1\n st=0\n end=0\n currentCount=0\n previousElement = 0\n for i in range(n):\n freq[arr[i]]+=1\n if(freq[arr[i]]==1):\n currentCount+=1\n\n while(currentCount>k):\n freq[arr[previousElement]]-=1\n if(freq[arr[previousElement]]==0):\n currentCount-=1\n\n previousElement+=1\n\n if(i-previousElement+1 >= end-st+1):\n end=i\n st=previousElement\n\n print(end-st+1)\n t=t-1\n\ndef __starting_point():\n main()\n\n\n\n\n\n__starting_point()\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n6 2\\n1 1 1 2 2 1\\n5 3\\n1 1 2 2 1\\n', 'output': '3\\n5\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/NOTALLFL'}","problem_id":"vfc_4334","program":"```python\ndef main():\n t= int(input())\n while(t!=0):\n n,k = list(map(int , input().split()))\n arr = list(map(int, input().split()))\n freq = [0]*100001\n k=k-1\n st=0\n end=0\n currentCount=0\n previousElement = 0\n for i in range(n):\n freq[arr[i]]+=1\n if(freq[arr[i]]==1):\n currentCount+=1\n\n while(currentCount>k):\n freq[arr[previousElement]]-=1\n if(freq[arr[previousElement]]==0):\n currentCount-=1\n\n previousElement+=1\n\n if(i-previousElement+1 >= end-st+1):\n end=i\n st=previousElement\n\n print(end-st+1)\n t=t-1\n\ndef __starting_point():\n main()\n\n\n\n\n\n__starting_point()\n```","inputs":"2\n6 2\n1 1 1 2 2 1\n5 3\n1 1 2 2 1\n","output":"3\n5\n","actual_output":"3\n5\n","execution_success":true,"sample_index":965},{"source":"apps","task_type":"verifiable_code","in_source_id":"1374","prompt":"Solve the following coding problem using the programming language python:\n\nChef Hari has got a new obsession now: he has started playing chess (read about it here) and he is liking this game very much. Since Hari has spent several months playing chess with his friends, he has now decided to take part in some chess tournament in Cheftown.\n\nThere are currently two tournaments going on in Cheftown and each tournament has its own entry fee. Due to this economical restriction and his budget, Hari can take part in only one tournament.\n\nThe entry fee for first tournament is F1 units of money. The structure of tournament is as follows: first there will be group matches and then there will be finals. If Hari reaches in finals and wins it, he'll get R1 units of money. If after reaching in finals, Hari loses, he'll get R2 units of money. If Hari fails to reach in finals, he'll get nothing. The probability of reaching in finals of first tournament for Hari is p1 and probability of winning in finals after reaching is p2.\n\nThe entry fee for second tournament is F2 units of money. The structure of tournament is as follows: first there will be group matches and then there will be finals. If Hari reaches in finals, he'll immediately get R3 units of money, otherwise he'll get nothing. If after reaching in finals, Hari wins, he'll get R4 units of money. The probability of reaching in finals of second tournament for Hari is p3 and probability of winning in finals after reaching is p4.\n\nNow, Hari wants to maximise his profit. He wants to know which tournament he should participate in such that his expected profit is maximised. Help Hari in deciding this.\n\nNote:\nIn the tournaments of Cheftown, the game never ends with a draw. So, either Hari wins a game, or he loses.\n\n-----Input-----\n\nFirst line of the input contains T, the number of test cases. The description of each test case is as following:\n\nFirst line of each test case contains 6 integers F1, F2, R1, R2, R3 and R4.\n\nNext line of each test case contains 4 floating point numbers p1, p2, p3 and p4.\nEach number has exactly 2 digits after decimal point.\n\n-----Output-----\n\nFor each test case, output a single line having \"FIRST\" if expected profit of first tournament is maximum or \"SECOND\" if expected profit of second tournament is maximum or \"BOTH\" if expected profits of both the tournaments is exactly same.\n\n-----Constraints-----\n- 1 \u2264 T \u2264 100\n- 1 \u2264 F1, F2, R1, R2, R3, R4 \u2264 100\n- 0.00 \u2264 p1, p2, p3, p4 \u2264 1.00\n\n-----Subtasks-----\nSubtask#1: 30 points\n- p1 = p3 and p2 = p4\n\nSubtask#2: 70 points\n- All usual constraints.\n\n-----Example-----\nInput:\n2\n30 50 70 10 40 30\n0.25 0.10 0.30 0.05\n50 36 80 38 65 32\n0.55 0.12 0.33 0.54\n\nOutput:\nFIRST\nSECOND\n\n-----Explanation-----\n\nIn the first case, the expected profit for first tournament is -26.00 and expected profit for second tournament is -37.55. So, first tournament has better expected profit.\n\nIn the second case, the expected profit for first tournament is -26.328 and expected profit for second tournament is -8.8476. So, second tournament has better expected profit.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nt=eval(input())\nwhile t>0:\n t=t-1\n f1,f2,r1,r2,r3,r4=list(map(int,input().split()))\n p1,p2,p3,p4=list(map(float,input().split()))\n s1=(1-p1)*(-f1)+(r2-f1)*(1-p2)*p1+p1*p2*(r1-f1)\n s2=(1-p3)*(-f2)+(r3-f2)*(p3)*(1-p4)+p3*p4*(r3+r4-f2)\n if s1>s2:\n print('FIRST')\n elif s10:\n t=t-1\n f1,f2,r1,r2,r3,r4=list(map(int,input().split()))\n p1,p2,p3,p4=list(map(float,input().split()))\n s1=(1-p1)*(-f1)+(r2-f1)*(1-p2)*p1+p1*p2*(r1-f1)\n s2=(1-p3)*(-f2)+(r3-f2)*(p3)*(1-p4)+p3*p4*(r3+r4-f2)\n if s1>s2:\n print('FIRST')\n elif s1 0:\n\n s = int(input())\n\n while s % 10 == 0 : \n s /= 10\n\n print(''.join(reversed(str(s))))\n\n t = t - 1\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\n1234\\n4567\\n1\\n', 'output': '4321\\n7654\\n1\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/SRMC2016/problems/INTROSRM'}","problem_id":"vfc_4342","program":"```python\nt = int(input())\nwhile t > 0:\n\n s = int(input())\n\n while s % 10 == 0 : \n s /= 10\n\n print(''.join(reversed(str(s))))\n\n t = t - 1\n```","inputs":"3\n1234\n4567\n1\n","output":"4321\n7654\n1\n","actual_output":"4321\n7654\n1\n","execution_success":true,"sample_index":967},{"source":"apps","task_type":"verifiable_code","in_source_id":"1378","prompt":"Solve the following coding problem using the programming language python:\n\nThere are K nuclear reactor chambers labelled from 0 to K-1. Particles are bombarded onto chamber 0. The particles keep collecting in the chamber 0. However if at any time, there are more than N particles in a chamber, a reaction will cause 1 particle to move to the immediate next chamber(if current chamber is 0, then to chamber number 1), and all the particles in the current chamber will be be destroyed and same continues till no chamber has number of particles greater than N. Given K,N and the total number of particles bombarded (A), find the final distribution of particles in the K chambers. Particles are bombarded one at a time. After one particle is bombarded, the set of reactions, as described, take place. After all reactions are over, the next particle is bombarded. If a particle is going out from the last chamber, it has nowhere to go and is lost.\n\n-----Input-----\n\nThe input will consist of one line containing three numbers A,N and K separated by spaces.\nA will be between 0 and 1000000000 inclusive.\nN will be between 0 and 100 inclusive.\nK will be between 1 and 100 inclusive.\nAll chambers start off with zero particles initially.\n\n-----Output-----\n\nConsists of K numbers on one line followed by a newline. The first number is the number of particles in chamber 0, the second number is the number of particles in chamber 1 and so on.\n\n-----Example-----\nInput:\n3 1 3\nOutput:\n1 1 0\nExplanation\nTotal of 3 particles are bombarded. After particle 1 is bombarded, the chambers have particle distribution as\n\"1 0 0\". After second particle is bombarded, number of particles in chamber 0 becomes 2 which is greater\nthan 1. So, num of particles in chamber 0 becomes 0 and in chamber 1 becomes 1. So now distribution is\n\"0 1 0\". After the 3rd particle is bombarded, chamber 0 gets 1 particle and so distribution is \"1 1 0\" after all\nparticles are bombarded one by one.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\na,n,k = map(int,input().split())\nfor i in range(k):\n print(a%(n+1),end=' ')\n a=a//(n+1)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3 1 3\\n', 'output': '1 1 0\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/NUKES'}","problem_id":"vfc_4354","program":"```python\na,n,k = map(int,input().split())\nfor i in range(k):\n print(a%(n+1),end=' ')\n a=a//(n+1)\n```","inputs":"3 1 3\n","output":"1 1 0\n","actual_output":"1 1 0 ","execution_success":true,"sample_index":970},{"source":"apps","task_type":"verifiable_code","in_source_id":"1380","prompt":"Solve the following coding problem using the programming language python:\n\nThe chef was searching for his pen in the garage but he found his old machine with a display and some numbers on it. If some numbers entered then some different output occurs on the display. Chef wants to crack the algorithm that the machine is following.\nExample to identify the pattern :\nInput Output\n9 36\n5 10\n1 0\n2 1\n\n-----Input:-----\n- First-line will contain $T$, the number of test cases. Then the test cases follow. \n- Each test case contains a single line of input, $N$. \n\n-----Output:-----\nFor each test case, output in a single line answer as displayed on the screen.\n\n-----Constraints-----\n- $1 \\leq T \\leq 10^6$\n- $1 \\leq N \\leq 10^6$\n\n-----Sample Input:-----\n1\n7\n\n-----Sample Output:-----\n21\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\nT = int(input())\n\nfor t in range(T):\n N = int(input())\n \n print(int(((N-1)*(N))/2))\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n7\\n', 'output': '21\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/PBK32020/problems/ITGUY29'}","problem_id":"vfc_4362","program":"```python\n# cook your dish here\nT = int(input())\n\nfor t in range(T):\n N = int(input())\n \n print(int(((N-1)*(N))/2))\n```","inputs":"1\n7\n","output":"21\n","actual_output":"21\n","execution_success":true,"sample_index":971},{"source":"apps","task_type":"verifiable_code","in_source_id":"1381","prompt":"Solve the following coding problem using the programming language python:\n\nChef works as a cook in a restaurant. Each morning, he has to drive down a straight road with length K$K$ to reach the restaurant from his home. Let's describe this road using a coordinate X$X$; the position of Chef's home is X=0$X = 0$ and the position of the restaurant is X=K$X = K$.\nThe road has exactly two lanes (numbered 1$1$ and 2$2$), but there are N$N$ obstacles (numbered 1$1$ through N$N$) on it. For each valid i$i$, the i$i$-th obstacle blocks the lane Li$L_i$ at the position X=Xi$X = X_i$ and does not block the other lane.\nWhen driving, Chef cannot pass through an obstacle. He can switch lanes in zero time at any integer X$X$-coordinate which does not coincide with the X$X$-coordinate of any obstacle. However, whenever he switches lanes, he cannot switch again until driving for at least D$D$ units of distance, and he can travel only in the direction of increasing X$X$. Chef can start driving in any lane he wants. He can not switch lanes at non-integer X$X$-coordinate.\nSometimes, it is impossible to reach the restaurant without stopping at an obstacle. Find the maximum possible distance Chef can travel before he has to reach an obstacle which is in the same lane as him. If he can avoid all obstacles and reach the restaurant, the answer is K$K$.\n\n-----Input-----\n- 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.\n- The first line of each test case contains three space-separated integers N$N$, K$K$ and D$D$.\n- The second line contains N$N$ space-separated integers X1,X2,\u2026,XN$X_1, X_2, \\ldots, X_N$.\n- The third line contains N$N$ space-separated integers L1,L2,\u2026,LN$L_1, L_2, \\ldots, L_N$.\n\n-----Output-----\nFor each test case, print a single line containing one integer \u2015 the maximum distance Chef can travel.\n\n-----Constraints-----\n- 1\u2264T\u22641,000$1 \\le T \\le 1,000$\n- 1\u2264N\u2264105$1 \\le N \\le 10^5$\n- 2\u2264K\u2264109$2 \\le K \\le 10^9$\n- 1\u2264D\u2264109$1 \\le D \\le 10^9$\n- 1\u2264Xi\u2264K\u22121$1 \\le X_i \\le K-1$ for each valid i$i$\n- Xin:\n ans=sum(l)\n else:\n ans=sum(l[m-x:])\nprint(ans)\n\n \n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\n-1 -2 -3\\n2\\n', 'output': '5\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/INTEG'}","problem_id":"vfc_4370","program":"```python\nn=int(input())\na=list(map(int,input().split()))\nx=int(input())\nl=[]\nfor i in a:\n if i<0:\n l.append(-i)\nl.sort()\nm=len(l)\nans=0\nif l:\n if x>n:\n ans=sum(l)\n else:\n ans=sum(l[m-x:])\nprint(ans)\n\n \n\n```","inputs":"3\n-1 -2 -3\n2\n","output":"5\n","actual_output":"5\n","execution_success":true,"sample_index":973},{"source":"apps","task_type":"verifiable_code","in_source_id":"1383","prompt":"Solve the following coding problem using the programming language python:\n\nDue to COVID19 all employees of chemical factory are quarantined in home. So, company is organized by automated robots. There are $N$ Containers in company, which are labelled with $1$ to $N$ numbers. There are Total $N$ robots in Company, which are labelled $1$ to $N$. \nEach Robot adds $1$ litter Chemical in containers whose labels are multiple of robots\u2019 label. (E.g. robot labelled 2 will add Chemical in containers labelled 2, 4, 6, \u2026.). \nRobots follow few rules mentioned below:\n- Chemical with $pH<7$ is acidic.\n- Chemical with $pH=7$ is neutral.\n- Chemical with $pH>7$ is basic.\n- Mixture of $1$ litter acid and $1$ litter base makes neutral solution.\n- If Container is empty or pH of Chemical in container is equal to \n- $7$ then robot adds $1$ litter acidic Chemical.\n- If pH of Chemical in container is less than $7$ then robots adds $1$ litter basic Chemical.\nNow Chemical is packed in $4$ ways:\n- Containers with exactly $2$ litter acid and $1$ litter base are packed at $P1$ cost. \n- Containers with acidic Chemical are packed at $P2$ cost. (Here Don\u2019t consider containers with exactly $2$ litter acid and $1$ litter base as we counted them in above rule)\n- Containers with $pH=7$ Chemical is packed at $P3$ cost.\n- Containers with Basic Chemical are packed at $P4$ cost.\nNow $1$ employee given task to find packing cost of containers with labels in range $[ k1, k2]$ (Inclusive). Help him out. As Cost can be large find cost in modulo of $100000007$\n\n-----Input:-----\n- The first line of the input contains a single integer T denoting the number of test cases. The description of $T$ test cases follows.\n- The first line of each test case contains $3$ space separated Integers $N$, $K1$ and $K2$.\n- The second and last line contains $4$ space separated Integers $P1$, $P2$, $P3$ and $P4$\n\n-----Output:-----\nFor each test case, print total cost of packing of containers modulo 100000007.\n\n-----Constraints-----\n- $1 \\leq T \\leq 50000$\n- $1 \\leq P1, P2, P3, P4 \\leq 2*10^7$\n- $2 \\leq N \\leq 2*10^7$\n- $1 \\leq K1, K2 \\leq N$\n\n-----Subtasks-----Subtask #1 (20 points):\n- $1 \\leq T \\leq 10$\n- $1 \\leq P1, P2, P3, P4 \\leq 2*10^7$\n- $2 \\leq N \\leq 1000$\n- $1 \\leq K1, K2 \\leq N$Subtask #2 (80 points) :\n- Original Constraint\n\n-----Sample Input:-----\n1\n4 1 4\n2 2 2 2\n\n-----Sample Output:-----\n8\n\n-----Explanation:-----\nLet\u2019s use notation, \n0 for acidic Chemical, \n1 for Chemical with pH=7, \n2 for basic Chemical,\n3 for Containers with exactly 2 litter acid and 1 litter base,\n-1 for empty containers\nInitially 4 containers are empty so\n[-1, -1, -1, -1]\nRobot 1 adds 1 litter acid in all containers.\n[0, 0, 0, 0]\nRobot 2 adds base in containers labelled 2, 4\n[0, 1, 0, 1]\nRobot 3 adds base in containers labelled 3\n[0, 1, 1, 1]\nRobot 4 adds acid in containers labelled 4 because it contains Chemical with pH=7. After adding acid, it also contains exactly 2 litter acid and 1 litter base, so denoting it with 3.\n[0, 1, 1, 3]\nCorresponding cost of packing container\n[P2, P3, P3, P1]\nNow, calculate total cost,\nCost = P2+P3+P3+P1 = 2+2+2+2 = 8\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nT = int(input())\r\nfor _ in range(T):\r\n N, K1, K2 = list(map(int, input().split()))\r\n P1, P2, P3, P4 = list(map(int, input().split()))\r\n ans = 0\r\n arr = [0] * (1005)\r\n\r\n length = len(arr)\r\n for i in range(1,N+1):\r\n\r\n j = 0\r\n while j < length:\r\n arr[j] += 1\r\n j += i\r\n\r\n for i in range(K1,K2+1):\r\n if arr[i]==3:\r\n ans += P1\r\n elif arr[i]%2==1:\r\n ans += P2\r\n else:\r\n ans += P3\r\n\r\n print(ans)\r\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n4 1 4\\n2 2 2 2\\n', 'output': '8\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/QFUN2020/problems/CHEMFACT'}","problem_id":"vfc_4374","program":"```python\nT = int(input())\r\nfor _ in range(T):\r\n N, K1, K2 = list(map(int, input().split()))\r\n P1, P2, P3, P4 = list(map(int, input().split()))\r\n ans = 0\r\n arr = [0] * (1005)\r\n\r\n length = len(arr)\r\n for i in range(1,N+1):\r\n\r\n j = 0\r\n while j < length:\r\n arr[j] += 1\r\n j += i\r\n\r\n for i in range(K1,K2+1):\r\n if arr[i]==3:\r\n ans += P1\r\n elif arr[i]%2==1:\r\n ans += P2\r\n else:\r\n ans += P3\r\n\r\n print(ans)\r\n\n```","inputs":"1\n4 1 4\n2 2 2 2\n","output":"8\n","actual_output":"8\n","execution_success":true,"sample_index":974},{"source":"apps","task_type":"verifiable_code","in_source_id":"1384","prompt":"Solve the following coding problem using the programming language python:\n\nOn each of the following $N$ days (numbered $1$ through $N$), Chef is planning to cook either pizza or broccoli. He wrote down a string $A$ with length $N$, where for each valid $i$, if the character $A_i$ is '1', then he will cook pizza on the $i$-th day, while if $A_i$ is '0', he will cook broccoli on this day.\nChefu, his son, loves pizza but hates broccoli \u2015 just like most kids. He wants to select a substring of $A$ with length $K$ and change each character '0' in this substring to '1'. Afterwards, let's define pizza time as the maximum number of consecutive days where Chef will cook pizza. Find the maximum pizza time Chefu can achieve.\n\n-----Input-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The first line of each test case contains two space-separated integers $N$ and $K$. \n- The second line contains a string $A$ with length $N$.\n\n-----Output-----\nFor each test case, print a single line containing one integer \u2015 the maximum pizza time.\n\n-----Constraints-----\n- $1 \\le T \\le 1,000$\n- $1 \\le K \\le N \\le 10^5$\n- $A$ contains only characters '0' and '1'\n- the sum of $N$ over all test cases does not exceed $10^6$\n\n-----Subtasks-----\nSubtask #1 (50 points):\n- $N \\le 10^3$\n- the sum of $N$ over all test cases does not exceed $10^4$\nSubtask #2 (50 points): original constraints\n\n-----Example Input-----\n2\n13 2\n0101110000101\n6 3\n100001\n\n-----Example Output-----\n5\n4\n\n-----Explanation-----\nExample case 1: Chefu can choose the substring $A[2, 3]$ = \"10\", and change the third character of $A$ to '1'. Then, the pizza time is $5$ days: from day $2$ to day $6$.\nExample case 2: Chefu can choose the substring $A[2, 4]$ = \"000\". Then, the pizza time is $4$ days: from day $1$ to day $4$.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfor _ in range(int(input())):\n\n n, k = map(int, input().split())\n l = [*map(int, input())]\n\n count = [0] * (n + 1)\n\n for i in range(n - 1, -1, -1):\n if l[i] == 1:\n count[i] = count[i + 1] + 1\n\n x,y = 0,0\n for i in range(n):\n if l[i] == 1:\n x += 1\n else:\n try:\n y = max(y, x + k + count[i + k])\n\n except:\n y = max(y, x + min(k, n - i))\n x = 0\n y = max(y,x)\n print(y)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n13 2\\n0101110000101\\n6 3\\n100001\\n', 'output': '5\\n4\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/PIBRO'}","problem_id":"vfc_4378","program":"```python\nfor _ in range(int(input())):\n\n n, k = map(int, input().split())\n l = [*map(int, input())]\n\n count = [0] * (n + 1)\n\n for i in range(n - 1, -1, -1):\n if l[i] == 1:\n count[i] = count[i + 1] + 1\n\n x,y = 0,0\n for i in range(n):\n if l[i] == 1:\n x += 1\n else:\n try:\n y = max(y, x + k + count[i + k])\n\n except:\n y = max(y, x + min(k, n - i))\n x = 0\n y = max(y,x)\n print(y)\n```","inputs":"2\n13 2\n0101110000101\n6 3\n100001\n","output":"5\n4\n","actual_output":"5\n4\n","execution_success":true,"sample_index":975},{"source":"apps","task_type":"verifiable_code","in_source_id":"1385","prompt":"Solve the following coding problem using the programming language python:\n\nGru has a string $S$ of length $N$, consisting of only characters $a$ and $b$ for banana and $P$ points to spend.\nNow Gru wants to replace and/or re-arrange characters of this given string to get the lexicographically smallest string possible. For this, he can perform the following two operations any number of times.\n1) Swap any two characters in the string. This operation costs $1$ $point$. (any two, need not be adjacent)\n2) Replace a character in the string with any other lower case english letter. This operation costs $2$ $points$.\nHelp Gru in obtaining the lexicographically smallest string possible, by using at most $P$ points.\n\n-----Input:-----\n- First line will contain $T$, number of testcases. Then the testcases follow. \n- Each testcase contains two lines of input, first-line containing two integers $N$ , $P$.\n- The second line contains a string $S$ consisting of $N$ characters.\n\n-----Output:-----\nFor each testcase, output in a single containing the lexicographically smallest string obtained.\n\n-----Constraints-----\n- $1 \\leq T \\leq 10$\n- $1 \\leq N \\leq 10^5$\n- $0 \\leq P \\leq 2N$\n- $S$ only consists of $'a'$ and $'b'$\n\n-----Sample Input:-----\n1\n3 3\nbba\n\n-----Sample Output:-----\naab\n\n-----Explanation:-----\nWe swap $S[0]$ and $S[2]$, to get $abb$. With the 2 remaining points, we replace $S[1]$ to obtain $aab$ which is the lexicographically smallest string possible for this case.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\ndef __starting_point():\n t=int(input())\n for _ in range(t):\n n,p=input().split()\n n,p=int(n),int(p)\n s=input()\n a,b=0,0\n arr=[0]*n\n for i in range(n):\n arr[i]=s[i]\n for c in s:\n if c=='a':\n a+=1\n else:\n b+=1\n swap=0\n for i in range(a):\n if s[i]=='b':\n swap+=1\n tmpp=p\n if p<=swap:\n for i in range(n):\n if p==0:\n break\n if arr[i]=='b':\n arr[i]='a'\n p-=1\n p=tmpp\n for i in range(n-1,-1,-1):\n if p==0:\n break\n if arr[i]=='a':\n arr[i]='b'\n p-=1\n for c in arr:\n print(c,end=\"\")\n print()\n else:\n for i in range(n):\n if i=2:\n p-=2\n arr[i]='a'\n if s[i]=='a' and p>=1:\n p-=1\n arr[i]='a'\n for c in arr:\n print(c,end=\"\")\n print()\n__starting_point()\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n3 3\\nbba\\n', 'output': 'aab\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/BANSTR'}","problem_id":"vfc_4382","program":"```python\ndef __starting_point():\n t=int(input())\n for _ in range(t):\n n,p=input().split()\n n,p=int(n),int(p)\n s=input()\n a,b=0,0\n arr=[0]*n\n for i in range(n):\n arr[i]=s[i]\n for c in s:\n if c=='a':\n a+=1\n else:\n b+=1\n swap=0\n for i in range(a):\n if s[i]=='b':\n swap+=1\n tmpp=p\n if p<=swap:\n for i in range(n):\n if p==0:\n break\n if arr[i]=='b':\n arr[i]='a'\n p-=1\n p=tmpp\n for i in range(n-1,-1,-1):\n if p==0:\n break\n if arr[i]=='a':\n arr[i]='b'\n p-=1\n for c in arr:\n print(c,end=\"\")\n print()\n else:\n for i in range(n):\n if i=2:\n p-=2\n arr[i]='a'\n if s[i]=='a' and p>=1:\n p-=1\n arr[i]='a'\n for c in arr:\n print(c,end=\"\")\n print()\n__starting_point()\n```","inputs":"1\n3 3\nbba\n","output":"aab\n","actual_output":"aab\n","execution_success":true,"sample_index":976},{"source":"apps","task_type":"verifiable_code","in_source_id":"1387","prompt":"Solve the following coding problem using the programming language python:\n\n-----Problem Statement-----\nChef studies combinatorics. He tries to group objects by their rang (a positive integer associated with each object). He also gives the formula for calculating the number of different objects with rang N as following:\n\nthe number of different objects with rang N = F(N) = A0 + A1 * N + A2 * N2 + A3 * N3.\n\nNow Chef wants to know how many different multisets of these objects exist such that sum of rangs of the objects in the multiset equals to S. You are given the coefficients in F(N) and the target sum S. Please, find the number of different multisets modulo 1,000,000,007.\n\nYou should consider a multiset as an unordered sequence of integers. Two multisets are different if and only if there at least exists one element which occurs X times in the first multiset but Y times in the second one, where (X \u2260 Y).\n\n-----Input-----\nThe first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows. \n\nThe first line of each test case contains four integers A0, A1, A2, A3. The second line contains an integer S.\n\n-----Output-----\nFor each test case, output a single line containing a single integer - the answer to the test case modulo 1,000,000,007.\n\n-----Constraints-----\n- 1 \u2264 T \u2264 500\n- 1 \u2264 S \u2264 100\n- 0 \u2264 Ai \u2264 1000\n- Sum of all S for all test cases is not greater than 500. It's guaranteed that at least one Ai is non-zero.\n\n-----Example-----\nInput:\n4\n1 0 0 0\n1\n1 0 0 0\n3\n0 1 0 0\n2\n2 3 1 4\n10\n\nOutput:\n1\n3\n3\n213986343\n\n-----Explanation-----\nExample case 2. \n\nIn the second example function looks as follows F(N) = 1. So for each rang there is a single object of the rang. To get multiset with sum of rangs equal to 3, you can pick: three objects of rang 1, or one object of rang 1 and one of rang 2, or only one object of rang 3. \nExample case 3. \n\nIn the third example function looks as follows F(N) = N. So, you have one distinct object of rang 1, two distinct objects of rang 2, three distinct objects of rang 3 and so on. To get\nmultiset with sum of rangs equal to 2, you can pick: two objects of rang 1, one of objects of rang 2 (two ways).\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\nimport sys\n\nmod_val = 1000000007\nrang = [0]*101\npow_cache = [0]*102\nmultisets = {}\n\n\ndef mod_pow(base, pow):\n result = 1\n while pow:\n if pow&1:\n result = (result*base) % mod_val\n base = (base*base) % mod_val\n pow = pow>>1\n return result\n\n\ndef precalculate():\n\n for i in range(1, 102):\n pow_cache[i] = mod_pow(i, mod_val-2)\n\n\ndef cal_recurse(i, target_sum):\n if target_sum == 0:\n return 1\n if i>=target_sum:\n return 0\n if (i, target_sum) in multisets:\n return multisets[(i, target_sum)]\n ans = cal_recurse(i+1, target_sum)\n max_pos = target_sum//(i+1)\n choose = rang[i+1]%mod_val\n for j in range(1, max_pos+1):\n temp = choose*cal_recurse(i+1, target_sum-j*(i+1))\n # temp%=mod_val\n ans += temp\n ans %= mod_val\n choose *= rang[i+1]+j\n # choose %= mod_val\n choose *= pow_cache[j+1]\n choose %= mod_val\n multisets[i, target_sum] = ans\n return ans\n\n\ndef calculate(target_sum, rang_index):\n populate(target_sum, rang_index)\n return cal_recurse(0, target_sum)\n\n\ndef populate(target_sum, rang_i):\n for i in range(1, target_sum+1):\n rang[i] = rang_i[0] + (rang_i[1] + (rang_i[2] + rang_i[3]*i)*i)*i\n\n\n_test_cases = int(input())\nprecalculate()\nfor _a_case in range(_test_cases):\n rang = [0]*101\n multisets = {}\n _rang_index = [int(i) for i in input().split(' ')]\n _target_sum = int(input())\n print(calculate(_target_sum, _rang_index))\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '4\\n1 0 0 0\\n1\\n1 0 0 0\\n3\\n0 1 0 0\\n2\\n2 3 1 4\\n10\\n', 'output': '1\\n3\\n3\\n213986343\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/GERALD05'}","problem_id":"vfc_4390","program":"```python\n# cook your dish here\nimport sys\n\nmod_val = 1000000007\nrang = [0]*101\npow_cache = [0]*102\nmultisets = {}\n\n\ndef mod_pow(base, pow):\n result = 1\n while pow:\n if pow&1:\n result = (result*base) % mod_val\n base = (base*base) % mod_val\n pow = pow>>1\n return result\n\n\ndef precalculate():\n\n for i in range(1, 102):\n pow_cache[i] = mod_pow(i, mod_val-2)\n\n\ndef cal_recurse(i, target_sum):\n if target_sum == 0:\n return 1\n if i>=target_sum:\n return 0\n if (i, target_sum) in multisets:\n return multisets[(i, target_sum)]\n ans = cal_recurse(i+1, target_sum)\n max_pos = target_sum//(i+1)\n choose = rang[i+1]%mod_val\n for j in range(1, max_pos+1):\n temp = choose*cal_recurse(i+1, target_sum-j*(i+1))\n # temp%=mod_val\n ans += temp\n ans %= mod_val\n choose *= rang[i+1]+j\n # choose %= mod_val\n choose *= pow_cache[j+1]\n choose %= mod_val\n multisets[i, target_sum] = ans\n return ans\n\n\ndef calculate(target_sum, rang_index):\n populate(target_sum, rang_index)\n return cal_recurse(0, target_sum)\n\n\ndef populate(target_sum, rang_i):\n for i in range(1, target_sum+1):\n rang[i] = rang_i[0] + (rang_i[1] + (rang_i[2] + rang_i[3]*i)*i)*i\n\n\n_test_cases = int(input())\nprecalculate()\nfor _a_case in range(_test_cases):\n rang = [0]*101\n multisets = {}\n _rang_index = [int(i) for i in input().split(' ')]\n _target_sum = int(input())\n print(calculate(_target_sum, _rang_index))\n\n```","inputs":"4\n1 0 0 0\n1\n1 0 0 0\n3\n0 1 0 0\n2\n2 3 1 4\n10\n","output":"1\n3\n3\n213986343\n","actual_output":"1\n3\n3\n213986343\n","execution_success":true,"sample_index":978},{"source":"apps","task_type":"verifiable_code","in_source_id":"1388","prompt":"Solve the following coding problem using the programming language python:\n\nIn India, every individual is charged with income tax on the total income each year. This tax is applied to specific ranges of income, which are called income tax slabs. The slabs of income tax keep changing from year to year. This fiscal year (2020-21), the tax slabs and their respective tax rates are as follows:Total income (in rupees)Tax rateup to Rs. 250,0000%from Rs. 250,001 to Rs. 500,0005%from Rs. 500,001 to Rs. 750,00010%from Rs. 750,001 to Rs. 1,000,00015%from Rs. 1,000,001 to Rs. 1,250,00020%from Rs. 1,250,001 to Rs. 1,500,00025%above Rs. 1,500,00030%\nSee the sample explanation for details on how the income tax is calculated.\nYou are given Chef's total income: $N$ rupees (Rs.). Find his net income. The net income is calculated by subtracting the total tax (also called tax reduction) from the total income. Note that you do not need to worry about any other kind of tax reductions, only the one described above.\n\n-----Input-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The first and only line of each test case contains a single integer $N$.\n\n-----Output-----\nFor each test case, print a single line containing one integer \u2014 Chef's net income.\n\n-----Constraints-----\n- $1 \\le T \\le 10^3$\n- $0 \\le N \\le 10^7$\n- $N$ is a multiple of $100$\n\n-----Example Input-----\n2\n600000\n250000\n\n-----Example Output-----\n577500\n250000\n\n-----Explanation-----\nExample case 1: We know that the total income is Rs. $6$ lakh ($1$ lakh rupees = $10^5$ rupees). The total tax for each slab is calculated as follows:\n- Up to $2.5$ lakh, the tax is Rs. $0$, since the tax rate is $0$ percent.\n- From above Rs. $2.5$ lakh to Rs. $5$ lakh, the tax rate is $5$ percent. Therefore, this tax is $0.05 \\cdot (500,000-250,000)$, which is Rs. $12,500$.\n- From above Rs. $5$ lakh to Rs. $6$ lakh, the tax rate is $10$ percent. Therefore, this tax is $0.10 \\cdot (600,000-500,000)$, which is Rs. $10,000$.\n- Summing them up, we get that the total tax on Chef's whole income is Rs. $22,500$. Since the net income is the total income minus the tax reduction, it is Rs. $600,000$ minus Rs. $22,500$, which is Rs. $577,500$.\nExample case 2: For income up to Rs. $2.5$ lakh, we have no tax, so the net income is the same as the total income: Rs. $2.5$ lakh.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\narr = [0]*6\n\narr[1] = 250000*(0.05)\narr[2] = 250000*(0.10)\narr[3] = 250000*(0.15)\narr[4] = 250000*(0.20)\narr[5] = 250000*(0.25)\n\nfor _ in range(int(input())):\n n = int(input())\n\n tax = 0\n\n if n<=250000:\n tax = 0\n\n elif 2500001500000:\n tax = sum(arr[:6])\n\n rem = n - 1500000\n\n tax+= (rem)*(0.30)\n \n res = int(n - tax)\n \n print(res)\n\n\n\n \n\n\n \n\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n600000\\n250000\\n', 'output': '577500\\n250000\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/SLAB'}","problem_id":"vfc_4394","program":"```python\narr = [0]*6\n\narr[1] = 250000*(0.05)\narr[2] = 250000*(0.10)\narr[3] = 250000*(0.15)\narr[4] = 250000*(0.20)\narr[5] = 250000*(0.25)\n\nfor _ in range(int(input())):\n n = int(input())\n\n tax = 0\n\n if n<=250000:\n tax = 0\n\n elif 2500001500000:\n tax = sum(arr[:6])\n\n rem = n - 1500000\n\n tax+= (rem)*(0.30)\n \n res = int(n - tax)\n \n print(res)\n\n\n\n \n\n\n \n\n\n```","inputs":"2\n600000\n250000\n","output":"577500\n250000\n","actual_output":"577500\n250000\n","execution_success":true,"sample_index":979},{"source":"apps","task_type":"verifiable_code","in_source_id":"1391","prompt":"Solve the following coding problem using the programming language python:\n\nOur chef has recently opened a new restaurant with a unique style. The restaurant is divided into K compartments (numbered from 1 to K) and each compartment can be occupied by at most one customer. \nEach customer that visits the restaurant has a strongly preferred compartment p (1 \u2264 p \u2264 K), and if that compartment is already occupied, then the customer simply leaves. Now obviously, the chef wants to maximize the total number of customers that dine at his restaurant and so he allows (or disallows) certain customers so as to achieve this task. You are to help him with this. \nGiven a list of N customers with their arrival time, departure time and the preferred compartment, you need to calculate the maximum number of customers that can dine at the restaurant. \n\n-----Input-----\nThe first line contains an integer T denoting the number of test cases. Each of the next T lines contains two integers N and K , the number of customers that plan to visit the chef's restaurant and the number of compartments the restaurant is divided into respectively. Each of the next N lines contains three integers si, fi and pi , the arrival time, departure time and the strongly preferred compartment of the ith customer respectively. \n\nNote that the ith customer wants to occupy the pith compartment from [si, fi) i.e the ith customer leaves just before fi so that another customer can occupy that compartment from fi onwards.\n\n-----Output-----\nFor every test case, print in a single line the maximum number of customers that dine at the restaurant.\n\n-----Constraints-----\n- 1 \u2264 T \u2264 30 \n- 0 \u2264 N \u2264 105 \n- 1 \u2264 K \u2264 109 \n- 0 \u2264 si < fi \u2264 109 \n- 1 \u2264 pi \u2264 K \n\n-----Example-----\nInput:\n2\n3 3\n1 3 1\n4 6 2\n7 10 3\n4 2\n10 100 1\n100 200 2\n150 500 2\n200 300 2\n\nOutput:\n3\n3\n\n-----Explanation-----\nExample case 1.\n\nAll three customers want different compartments and hence all 3 can be accommodated.\n\nExample case 2.\n\nIf we serve the 1st, 2nd and 4th customers, then we can get a maximum of 3.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\ntry:\n for _ in range(int(input())):\n N, K = map(int, input().split())\n cell = []\n count = 0\n l = []\n for __ in range(N):\n inserted = list(map(int, input().split()))\n cell.append(inserted)\n\n\n\n \n\n\n\n\n cell.sort(key=lambda x: x[1])\n time = {}\n\n for number in cell:\n if number[2] not in time:\n time[number[2]] = number[1]\n\n count += 1\n elif number[0] >= time[number[2]]:\n time[number[2]] = number[1]\n count += 1\n\n\n\n\n\n print(count)\n\n\nexcept:\n pass\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n3 3\\n1 3 1\\n4 6 2\\n7 10 3\\n4 2\\n10 100 1\\n100 200 2\\n150 500 2\\n200 300 2\\n', 'output': '3\\n3\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/FGFS'}","problem_id":"vfc_4406","program":"```python\ntry:\n for _ in range(int(input())):\n N, K = map(int, input().split())\n cell = []\n count = 0\n l = []\n for __ in range(N):\n inserted = list(map(int, input().split()))\n cell.append(inserted)\n\n\n\n \n\n\n\n\n cell.sort(key=lambda x: x[1])\n time = {}\n\n for number in cell:\n if number[2] not in time:\n time[number[2]] = number[1]\n\n count += 1\n elif number[0] >= time[number[2]]:\n time[number[2]] = number[1]\n count += 1\n\n\n\n\n\n print(count)\n\n\nexcept:\n pass\n```","inputs":"2\n3 3\n1 3 1\n4 6 2\n7 10 3\n4 2\n10 100 1\n100 200 2\n150 500 2\n200 300 2\n","output":"3\n3\n","actual_output":"3\n3\n","execution_success":true,"sample_index":982},{"source":"apps","task_type":"verifiable_code","in_source_id":"1392","prompt":"Solve the following coding problem using the programming language python:\n\nChef and Chefina are best friends. Chefina wants to test the Problem Solving skills of chef so she provides Chef 2 integer number $X$ and $Y$\nThe task of chef is to take the two numbers $X$ and $Y$ and return their SUM.\nIdentify whether Chef can solve the problem or not? \n\n-----Input:-----\n- First line will contain the two integers $X$ and $Y$.\n\n-----Output:-----\nFor each testcase, output in a single line the SUM of these two numbers $X$ and $Y$.\n\n-----Constraints-----\n- $1 \\leq X \\leq 100$\n- $1 \\leq Y \\leq 100$\n\n-----Sample Input:-----\n6 70\n\n-----Sample Output:-----\n76\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\na,b=map(int,input().split())\r\nprint(a+b)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '6 70\\n', 'output': '76\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/SPTC2020/problems/CPCEJC4'}","problem_id":"vfc_4410","program":"```python\na,b=map(int,input().split())\r\nprint(a+b)\n```","inputs":"6 70\n","output":"76\n","actual_output":"76\n","execution_success":true,"sample_index":983},{"source":"apps","task_type":"verifiable_code","in_source_id":"1394","prompt":"Solve the following coding problem using the programming language python:\n\nChef's pizza is the tastiest pizza to exist, and the reason for that is his special, juicy homegrown tomatoes. \nTomatoes can be grown in rectangular patches of any side lengths. However, Chef only has a limited amount of land. \nConsider the entire town of Chefville to be consisting of cells in a rectangular grid of positive coordinates. \nChef own all cells (x,y)$(x, y)$ that satisfy x\u2217y\u2264N$x*y \\leq N$\nAs an example if N=4$N = 4$, Chef owns the following cells: \n(1,1),(1,2),(1,3),(1,4),(2,1),(2,2),(3,1),(4,1)$(1, 1), (1, 2), (1, 3), (1, 4), (2, 1), (2, 2), (3, 1), (4, 1) $\nChef can only grow tomatoes in rectangular patches consisting only of cells which belong to him. Also, if he uses a cell, he must use it entirely. He cannot use only a portion of it. \nHelp Chef find the number of unique patches of rectangular land that he can grow tomatoes in! Since this number can be very large, output it modulo 1000000007$1000000007$.\n\n-----Input:-----\n- The first line of the input contains T$T$, the number of test cases.\n- The next T$T$ lines of input contains one integer N$N$.\n\n-----Output:-----\nFor each testcase, output the number of ways modulo 1000000007$1000000007$.\n\n-----Constraints-----\n- 1\u2264T\u22645$1 \\leq T \\leq 5$\n- 1\u2264N\u22641010$1 \\leq N \\leq 10^{10}$\n\n-----Sample Input:-----\n2\n4\n10000000000\n\n-----Sample Output:-----\n23\n227374950\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfrom math import *\ndef list_input():\n return list(map(int,input().split()))\ndef map_input():\n return list(map(int,input().split()))\ndef map_string():\n return input().split()\ndef g(n):\n return (n*(n+1)*(2*n+1))//6\ndef f(n):\n ans = 0\n for i in range(1,floor(sqrt(n))+1):\n ans+=i*(i+floor(n/i))*(floor(n/i)+1-i)\n return ans-g(floor(sqrt(n)))\nfor _ in range(int(input())):\n n=int(input())\n print(f(n)%1000000007)\n\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n4\\n10000000000\\n', 'output': '23\\n227374950\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/PCJ18G'}","problem_id":"vfc_4418","program":"```python\nfrom math import *\ndef list_input():\n return list(map(int,input().split()))\ndef map_input():\n return list(map(int,input().split()))\ndef map_string():\n return input().split()\ndef g(n):\n return (n*(n+1)*(2*n+1))//6\ndef f(n):\n ans = 0\n for i in range(1,floor(sqrt(n))+1):\n ans+=i*(i+floor(n/i))*(floor(n/i)+1-i)\n return ans-g(floor(sqrt(n)))\nfor _ in range(int(input())):\n n=int(input())\n print(f(n)%1000000007)\n\n\n```","inputs":"2\n4\n10000000000\n","output":"23\n227374950\n","actual_output":"23\n227374950\n","execution_success":true,"sample_index":985},{"source":"apps","task_type":"verifiable_code","in_source_id":"1395","prompt":"Solve the following coding problem using the programming language python:\n\nRam and Shyam are sitting next to each other, hoping to cheat on an exam. However, the examination board has prepared $p$ different sets of questions (numbered $0$ through $p-1$), which will be distributed to the students in the following way:\n- The students are assigned roll numbers \u2014 pairwise distinct positive integers.\n- If a student's roll number is $r$, this student gets the $((r-1)\\%p)$-th set of questions.\nObviously, Ram and Shyam can cheat only if they get the same set of questions.\nYou are given the roll numbers of Ram and Shyam: $A$ and $B$ respectively. Find the number of values of $p$ for which they can cheat, or determine that there is an infinite number of such values.\n\n-----Input-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The first and only line of each test case contains two space-separated integers $A$ and $B$.\n\n-----Output-----\nFor each test case, print a single line \u2014 the number of values of $p$ for which Ram and Shyam can cheat, or $-1$ if there is an infinite number of such values.\n\n-----Constraints-----\n- $1 \\le T \\le 100$\n- $1 \\le A, B \\le 10^8$\n\n-----Example Input-----\n1\n2 6\n\n-----Example Output-----\n3\n\n-----Explanation-----\nExample case 1: They can cheat for $p = 1$, $p = 2$ or $p = 4$.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\nfor test in range(0,int(input())):\n A,B = map(int,input().split())\n diff = abs(A-B)\n count=0\n if not(A^B):\n print(-1)\n else:\n for i in range(1,int(diff**(1/2))+1):\n if diff%i==0:\n if diff/i==i:\n count+=1 \n else:\n count+=2\n print(count)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n2 6\\n', 'output': '3\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/EXAMCHT'}","problem_id":"vfc_4422","program":"```python\n# cook your dish here\nfor test in range(0,int(input())):\n A,B = map(int,input().split())\n diff = abs(A-B)\n count=0\n if not(A^B):\n print(-1)\n else:\n for i in range(1,int(diff**(1/2))+1):\n if diff%i==0:\n if diff/i==i:\n count+=1 \n else:\n count+=2\n print(count)\n```","inputs":"1\n2 6\n","output":"3\n","actual_output":"3\n","execution_success":true,"sample_index":986},{"source":"apps","task_type":"verifiable_code","in_source_id":"1396","prompt":"Solve the following coding problem using the programming language python:\n\nMysterious Chefland\u2026 Recently, Chef realised that Discuss, the educational system of Chefland, is out of date. Therefore, he is trying to find ways to update the infrastructure in the country. One possible way is to move all materials from Discuss to Discourse.\nChef will have access to Discourse if his knowledge and power become exactly equal to $N$ and $M$ respectively. Initially, he has power $1$ and knowledge $1$.\nChef can perform actions of the following types to improve his skills:\n- solve a problem \u2014 increase his knowledge by $X$\n- do a push-up \u2014 increase his power by $Y$\n- install ShareChat to keep in touch with friends \u2014 increase both knowledge and power by $1$\nChef can only install ShareChat at most once. The remaining actions may be performed any number of times and the actions may be performed in any order.\nHelp Chef find out whether it is possible to move from Discuss to Discourse.\n\n-----Input-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The first and only line of each test case contains four space-separated integers $N$, $M$, $X$ and $Y$.\n\n-----Output-----\nFor each test case, print a single line containing the string \"Chefirnemo\" if it is possible to reach the required knowledge and power or \"Pofik\" if it is impossible.\n\n-----Constraints-----\n- $1 \\le T \\le 1,000$\n- $1 \\le N, M, X, Y \\le 10^9$\n\n-----Subtasks-----\nSubtask #1 (30 points): $1 \\le N, M, X, Y \\le 100$\nSubtask #2 (70 points): original constraints\n\n-----Example Input-----\n5\n2 2 1 2\n11 10 5 9\n11 11 5 9\n12 11 5 9\n1 2 1 100\n\n-----Example Output-----\nChefirnemo\nChefirnemo\nPofik\nChefirnemo\nPofik\n\n-----Explanation-----\nExample case 2: We add $Y=9$ once to the power to get power $10$. We add $X=5$ twice to the knowledge to get knowledge $11$.\nExample case 3: We can see that it is impossible to reach power $M=11$ no matter which or how many operations we do. Note that the ShareChat operation will increase both knowledge and power by $1$, and hence it will still be impossible to attain the given values of knowledge and power at the same time.\nExample case 4: We can reach knowledge $11$ and power $10$ like in example case 2, the only difference is that we also use the ShareChat operation to increase both by $1$.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nt = input()\nt = int(t)\n\nfor _ in range(t):\n n, m, x, y = input().split()\n n = int(n)\n m = int(m)\n x = int(x)\n y = int(y)\n n -= 1\n m -= 1\n flag = 0\n if n % x == 0 and m % y == 0:\n flag = 1\n n -= 1\n m -= 1\n if n >= 0 and m >= 0:\n if n % x == 0 and m % y == 0:\n flag = 1\n \n if flag == 1:\n print(\"Chefirnemo\")\n else:\n print(\"Pofik\")\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '5\\n2 2 1 2\\n11 10 5 9\\n11 11 5 9\\n12 11 5 9\\n1 2 1 100\\n', 'output': 'Chefirnemo\\nChefirnemo\\nPofik\\nChefirnemo\\nPofik\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/CHEFADV'}","problem_id":"vfc_4426","program":"```python\nt = input()\nt = int(t)\n\nfor _ in range(t):\n n, m, x, y = input().split()\n n = int(n)\n m = int(m)\n x = int(x)\n y = int(y)\n n -= 1\n m -= 1\n flag = 0\n if n % x == 0 and m % y == 0:\n flag = 1\n n -= 1\n m -= 1\n if n >= 0 and m >= 0:\n if n % x == 0 and m % y == 0:\n flag = 1\n \n if flag == 1:\n print(\"Chefirnemo\")\n else:\n print(\"Pofik\")\n```","inputs":"5\n2 2 1 2\n11 10 5 9\n11 11 5 9\n12 11 5 9\n1 2 1 100\n","output":"Chefirnemo\nChefirnemo\nPofik\nChefirnemo\nPofik\n","actual_output":"Chefirnemo\nChefirnemo\nPofik\nChefirnemo\nPofik\n","execution_success":true,"sample_index":987},{"source":"apps","task_type":"verifiable_code","in_source_id":"1397","prompt":"Solve the following coding problem using the programming language python:\n\nChef has a sequence $A_1, A_2, \\ldots, A_N$. For a positive integer $M$, sequence $B$ is defined as $B = A*M$ that is, appending $A$ exactly $M$ times. For example, If $A = [1, 2]$ and $M = 3$, then $B = A*M = [1, 2, 1, 2, 1, 2]$\nYou have to help him to find out the minimum value of $M$ such that the length of the longest strictly increasing subsequence is maximum possible.\n\n-----Input:-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The first line of each test case contains a single integer $N$.\n- The second line contains $N$ space-separated integers $A_1, A_2, \\ldots, A_N$.\n\n-----Output:-----\nFor each test case, print a single line containing one integer \u2015 the minimum value of $M$.\n\n-----Constraints-----\n- $1 \\le T \\le 500$\n- $1 \\le N \\le 2*10^5$\n- $1 \\le A_i \\le 10^9$\n- It's guaranteed that the total length of the sequence $A$ in one test file doesn't exceed $2*10^6$\n\n-----Sample Input:-----\n3\n2\n2 1\n2\n1 2\n5\n1 3 2 1 2\n\n-----Sample Output:-----\n2\n1\n2\n\n-----Explanation:-----\nIn the first test case, Choosing $M = 2$ gives $B = [2, 1, 2, 1]$ which has a longest strictly increasing sequence of length $2$ which is the maximum possible.\nIn the second test case, Choosing $M = 1$ gives $B = [1, 2]$ which has a longest strictly increasing sequence of length $2$ which is the maximum possible.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\ndef mForMaxSeq(arr, n):\r\n eim = dict()\r\n for i in range(n):\r\n if arr[i] in eim:\r\n eim[arr[i]].append(i)\r\n else:\r\n eim[arr[i]] = [i]\r\n \r\n keys = sorted(eim.keys())\r\n \r\n # print(eim, keys)\r\n\r\n connected = False\r\n count = 0\r\n pI = -1\r\n\r\n nKeys = len(keys)\r\n for i in range(nKeys-1):\r\n \r\n if not connected:\r\n pI = eim[keys[i]][0]\r\n \r\n for idx in eim[keys[i+1]]:\r\n if idx >pI:\r\n connected = True\r\n count += 1\r\n pI = idx\r\n break\r\n else:\r\n connected = False\r\n\r\n for idx in eim[keys[i+1]]:\r\n if idx > pI:\r\n connected = True\r\n count += 1\r\n pI = idx\r\n break\r\n\r\n \r\n return (nKeys - count)\r\n\r\n\r\ndef __starting_point():\r\n for _ in range(int(input())):\r\n n = int(input())\r\n arr = list(map(int, input().split()))\r\n \r\n print(mForMaxSeq(arr, n))\r\n \r\n \r\n\n__starting_point()\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\n2\\n2 1\\n2\\n1 2\\n5\\n1 3 2 1 2\\n', 'output': '2\\n1\\n2\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/RC122020/problems/RECNDROT'}","problem_id":"vfc_4430","program":"```python\ndef mForMaxSeq(arr, n):\r\n eim = dict()\r\n for i in range(n):\r\n if arr[i] in eim:\r\n eim[arr[i]].append(i)\r\n else:\r\n eim[arr[i]] = [i]\r\n \r\n keys = sorted(eim.keys())\r\n \r\n # print(eim, keys)\r\n\r\n connected = False\r\n count = 0\r\n pI = -1\r\n\r\n nKeys = len(keys)\r\n for i in range(nKeys-1):\r\n \r\n if not connected:\r\n pI = eim[keys[i]][0]\r\n \r\n for idx in eim[keys[i+1]]:\r\n if idx >pI:\r\n connected = True\r\n count += 1\r\n pI = idx\r\n break\r\n else:\r\n connected = False\r\n\r\n for idx in eim[keys[i+1]]:\r\n if idx > pI:\r\n connected = True\r\n count += 1\r\n pI = idx\r\n break\r\n\r\n \r\n return (nKeys - count)\r\n\r\n\r\ndef __starting_point():\r\n for _ in range(int(input())):\r\n n = int(input())\r\n arr = list(map(int, input().split()))\r\n \r\n print(mForMaxSeq(arr, n))\r\n \r\n \r\n\n__starting_point()\n```","inputs":"3\n2\n2 1\n2\n1 2\n5\n1 3 2 1 2\n","output":"2\n1\n2\n","actual_output":"2\n1\n2\n","execution_success":true,"sample_index":988},{"source":"apps","task_type":"verifiable_code","in_source_id":"1398","prompt":"Solve the following coding problem using the programming language python:\n\nYou have initially a string of N characters, denoted by A1,A2...AN. You have to print the size of the largest subsequence of string A such that all the characters in that subsequence are distinct ie. no two characters in that subsequence should be same.\n\nA subsequence of string A is a sequence that can be derived from A by deleting some elements and without changing the order of the remaining elements.\n\n-----Input-----\nFirst line contains T, number of testcases. Each testcase consists of a single string in one line. Each character of the string will be a small alphabet(ie. 'a' to 'z').\n\n-----Output-----\nFor each testcase, print the required answer in one line.\n\n-----Constraints-----\n- 1 \u2264 T \u2264 10\n- Subtask 1 (20 points):1 \u2264 N \u2264 10\n- Subtask 2 (80 points):1 \u2264 N \u2264 105\n\n-----Example-----\nInput:\n2\nabc\naba\n\nOutput:\n3\n2\n\n-----Explanation-----\nFor first testcase, the whole string is a subsequence which has all distinct characters.\n\nIn second testcase, the we can delete last or first 'a' to get the required subsequence.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\ndef solve(S):\n a = set(S)\n return len(a)\n \n \nt = int(input())\n\nfor _ in range(t):\n s = input()\n print(solve(s))\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\nabc\\naba\\n', 'output': '3\\n2\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/DISCHAR'}","problem_id":"vfc_4434","program":"```python\ndef solve(S):\n a = set(S)\n return len(a)\n \n \nt = int(input())\n\nfor _ in range(t):\n s = input()\n print(solve(s))\n```","inputs":"2\nabc\naba\n","output":"3\n2\n","actual_output":"3\n2\n","execution_success":true,"sample_index":989},{"source":"apps","task_type":"verifiable_code","in_source_id":"1399","prompt":"Solve the following coding problem using the programming language python:\n\nRecently, Chef found a new formula for computing powers of a sequence:\n- You are given two sequences $A_1, A_2, \\ldots, A_N$ and $(l_1, r_1), (l_2, r_2), \\ldots, (l_N, r_N)$.\n- The $1$-st power of the sequence $A$ is $A^1 = A$.\n- For each $k > 1$, the $k$-th power of the sequence $A$ (denoted by $A^k$) is a sequence with length $N$ such that for each valid $i$, the $i$-th element of this sequence is (Ak)i=(Ak\u22121)li\u2295(Ak\u22121)li+1\u2295\u2026\u2295(Ak\u22121)ri\u22121\u2295(Ak\u22121)ri.(Ak)i=(Ak\u22121)li\u2295(Ak\u22121)li+1\u2295\u2026\u2295(Ak\u22121)ri\u22121\u2295(Ak\u22121)ri.(A^k)_i = (A^{k-1})_{l_i} \\oplus (A^{k-1})_{l_i+1} \\oplus \\ldots \\oplus (A^{k-1})_{r_i-1} \\oplus (A^{k-1})_{r_i} \\,.\nAfter discovering this new formula, Chef tried to find $A^K$, but he felt that it is very time consuming. Therefore, Chef wants you to do it. Can you find the $K$-th power of $A$ for Chef?\n\n-----Input-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The first line of each test case contains two space-separated integers $N$ and $K$.\n- The second line contains $N$ space-separated integers $A_1, A_2, \\ldots, A_N$.\n- $N$ lines follow. For each valid $i$, the $i$-th of these lines contains two space-separated integers $l_i$ and $r_i$.\n\n-----Output-----\nFor each test case, print a single line containing $N$ space-separated integers $(A^K)_1, (A^K)_2, \\ldots, (A^K)_N$.\n\n-----Constraints-----\n- $1 \\le T \\le 3$\n- $1 \\le N \\le 500$\n- $1 \\le K \\le 5 \\cdot 10^7$\n- $1 \\le A_i \\le 10^{18}$ for each valid $i$\n- $1 \\le l_i \\le r_i \\le N$ for each valid $i$\n\n-----Subtasks-----\nSubtask #1 (50 points):\n- $T = 1$\n- $N \\le 100$\nSubtask #2 (50 points): original constraints\n\n-----Sample Input-----\n1\n3 2\n1 2 3\n1 2\n2 3\n1 3\n\n-----Example Ouput-----\n3 1 0\n\n-----Explanation-----\nExample case 1:\n- $(A^2)_1 = A_1 \\oplus A_2 = 1 \\oplus 2 = 3$\n- $(A^2)_2 = A_2 \\oplus A_3 = 2 \\oplus 3 = 1$\n- $(A^2)_3 = A_1 \\oplus A_2 \\oplus A_3 =1 \\oplus 2 \\oplus 3 = 0$\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nimport numpy as np\r\n\r\ndef solve(n,k,a,l,r):\r\n shape = (n,n)\r\n mat = np.zeros(shape, dtype=np.int64)\r\n for i in range(n):\r\n for j in range(l[i], r[i]):\r\n mat[i][j]=1\r\n \r\n ans = np.eye(n,n, dtype=np.int64)\r\n while(k>0):\r\n if k%2 == 1:\r\n ans = np.matmul(mat, ans)\r\n ans%=2\r\n mat = np.matmul(mat, mat)\r\n mat%=2\r\n k = k//2\r\n result = []\r\n for i in range(n):\r\n aux = 0\r\n for j in range(n):\r\n if ans[i][j] == 1:\r\n aux^=a[j]\r\n result.append(aux)\r\n return result\r\n \r\n\r\n\r\n\r\n\r\nt = int(input())\r\nfor i in range(t):\r\n s = input().split()\r\n n = int(s[0])\r\n k = int(s[1])\r\n a = []\r\n l = []\r\n r = []\r\n s = input().split()\r\n for i in range(n):\r\n a.append(int(s[i]))\r\n for i in range(n):\r\n s = input().split()\r\n l.append(int(s[0])-1)\r\n r.append(int(s[1]))\r\n arr = solve(n,k-1,a,l,r)\r\n s = \"\"\r\n for e in arr:\r\n s += str(e)\r\n s +=\" \"\r\n print(s)\r\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n3 2\\n1 2 3\\n1 2\\n2 3\\n1 3\\n', 'output': '3 1 0\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/HXR'}","problem_id":"vfc_4438","program":"```python\nimport numpy as np\r\n\r\ndef solve(n,k,a,l,r):\r\n shape = (n,n)\r\n mat = np.zeros(shape, dtype=np.int64)\r\n for i in range(n):\r\n for j in range(l[i], r[i]):\r\n mat[i][j]=1\r\n \r\n ans = np.eye(n,n, dtype=np.int64)\r\n while(k>0):\r\n if k%2 == 1:\r\n ans = np.matmul(mat, ans)\r\n ans%=2\r\n mat = np.matmul(mat, mat)\r\n mat%=2\r\n k = k//2\r\n result = []\r\n for i in range(n):\r\n aux = 0\r\n for j in range(n):\r\n if ans[i][j] == 1:\r\n aux^=a[j]\r\n result.append(aux)\r\n return result\r\n \r\n\r\n\r\n\r\n\r\nt = int(input())\r\nfor i in range(t):\r\n s = input().split()\r\n n = int(s[0])\r\n k = int(s[1])\r\n a = []\r\n l = []\r\n r = []\r\n s = input().split()\r\n for i in range(n):\r\n a.append(int(s[i]))\r\n for i in range(n):\r\n s = input().split()\r\n l.append(int(s[0])-1)\r\n r.append(int(s[1]))\r\n arr = solve(n,k-1,a,l,r)\r\n s = \"\"\r\n for e in arr:\r\n s += str(e)\r\n s +=\" \"\r\n print(s)\r\n\n```","inputs":"1\n3 2\n1 2 3\n1 2\n2 3\n1 3\n","output":"3 1 0\n","actual_output":"3 1 0 \n","execution_success":true,"sample_index":990},{"source":"apps","task_type":"verifiable_code","in_source_id":"1400","prompt":"Solve the following coding problem using the programming language python:\n\nChandler has a list of non zero positive integers with him. He made a very interesting observation about the list. He noticed that the number of unique integers in an array of size $N$ is in the range $L$ to $R$ (both inclusive) and every element was either 1 or an even number x, in which case x/2 was also definitely present in the array. \nChandler has misplaced the list of integers but he wants to impress Monica with his problem solving skills by finding out the minimum and maximum possible sum of all elements of the list of integers.\nCan you also help him solve the problem so that he can win over Monica?\n\n-----Input:-----\n- First line will contain $T$, the number of testcases. \n- The first line of each test case contains integers $N$, $L$, and $R$. \n\n-----Output:-----\nFor each test case print 2 space-separated integers, the minimum and the maximum possible sum of N elements based on the above facts.\n\n-----Constraints-----\n- $1 \\leq T \\leq 100$\n- $1 \\leq N \\leq 1000$\n- $1 \\leq L \\leq R \\leq min(N,20)$\n\n-----Sample Input:-----\n2\n\n4 2 2\n\n5 1 5\n\n-----Sample Output:-----\n5 7\n\n5 31\n\n-----EXPLANATION:-----\n- \nExample 1: For an array of size 4, with minimum 2 unique integers and maximum 2 unique integers, the possible arrays are (1,1,1,2), (1,1,2,2), (1,2,2,2)\nOut of these, the minimum possible sum of elements is 5(1+1+1+2) and maximum possible sum is 7(1+2+2+2)\n- \nExample 2: For an array of size 5, with minimum 1 unique integer and maximum 5 unique integers, minimum possible sum of elements is 5(1+1+1+1+1) and maximum possible sum is 31(1+2+4+8+16)\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\nfor _ in range(int(input())):\n n,l,h=list(map(int,input().split()))\n print(n-l+1+2**(l)-2,1+2**(h)-2+2**(h-1)*(n-h))\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n4 2 2\\n5 1 5\\n', 'output': '5 7\\n5 31\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/ENNO2020/problems/ENCNOV'}","problem_id":"vfc_4442","program":"```python\n# cook your dish here\nfor _ in range(int(input())):\n n,l,h=list(map(int,input().split()))\n print(n-l+1+2**(l)-2,1+2**(h)-2+2**(h-1)*(n-h))\n\n```","inputs":"2\n4 2 2\n5 1 5\n","output":"5 7\n5 31\n","actual_output":"5 7\n5 31\n","execution_success":true,"sample_index":991},{"source":"apps","task_type":"verifiable_code","in_source_id":"1401","prompt":"Solve the following coding problem using the programming language python:\n\nGive me Chocolate\n\nAnushka wants to buy chocolates.there are many chocolates in front of her, tagged with their prices.\n\nAnushka has only a certain amount to spend, and she wants to maximize the number of chocolates she buys with this money.\n\nGiven a list of prices and an amount to spend, what is the maximum number of chocolates Anushka can buy? \n\nFor example, \n\nif prices =[1,2,3,4]\nand Anushka has k=7 to spend, she can buy items [1,2,3] for 6 , or [3,4] for 7 units of currency. she would choose the first group of 3 items.\n\nInput Format\n\nThe first line contains two integers, n and k , the number of priced chocolates and the amount Anushka has to spend.\n\nThe next line contains n space-separated integers prices[i]\n\nConstraints\n\n1<= n <= 105\n\n1<= k <= 109\n\n1<= prices[i] <= 109\n\n\n\nA chocolate can't be bought multiple times.\n\nOutput Format\n\nAn integer that denotes the maximum number of chocolates Anushka can buy for her.\n\nSample Input\n\n7 50\n\n1 12 5 111 200 1000 10\n\nSample Output\n\n4\n\nExplanation\n\nshe can buy only 4 chocolatess at most. These chocolates have the following prices: 1, 12, 5, 10.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nn,k = map(int,input().split())\nprices = list(map(int,input().split()))\nprices.sort()\nsum,cnt = 0, 0\nfor price in prices:\n sum += price\n if sum <= k: cnt += 1\n else: break\nprint(cnt)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '7 50\\n1 12 5 111 200 1000 10\\n', 'output': '4\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/COM12020/problems/CODE_01'}","problem_id":"vfc_4446","program":"```python\nn,k = map(int,input().split())\nprices = list(map(int,input().split()))\nprices.sort()\nsum,cnt = 0, 0\nfor price in prices:\n sum += price\n if sum <= k: cnt += 1\n else: break\nprint(cnt)\n```","inputs":"7 50\n1 12 5 111 200 1000 10\n","output":"4\n","actual_output":"4\n","execution_success":true,"sample_index":992},{"source":"apps","task_type":"verifiable_code","in_source_id":"1402","prompt":"Solve the following coding problem using the programming language python:\n\nRecently, Chef studied the binary numeral system and noticed that it is extremely simple to perform bitwise operations like AND, XOR or bit shift on non-negative integers, while it is much more complicated to perform arithmetic operations (e.g. addition, multiplication or division).\nAfter playing with binary operations for a while, Chef invented an interesting algorithm for addition of two non-negative integers $A$ and $B$:\nfunction add(A, B):\nwhile B is greater than 0:\nU = A XOR B\nV = A AND B\nA = U\nB = V * 2\nreturn A\n\nNow Chef is wondering how fast this algorithm is. Given the initial values of $A$ and $B$ (in binary representation), he needs you to help him compute the number of times the while-loop of the algorithm is repeated.\n\n-----Input-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The first line of each test case contains a single string $A$.\n- The second line contains a single string $B$.\n\n-----Output-----\nFor each test case, print a single line containing one integer \u2015 the number of iterations the algorithm will perform during addition of the given numbers $A$ and $B$.\n\n-----Constraints-----\n- $1 \\le T \\le 10^5$\n- $1 \\le |A|, |B| \\le 10^5$\n- $A$ and $B$ contain only characters '0' and '1'\n- the sum of $|A| + |B|$ over all test cases does not exceed $10^6$\n\n-----Subtasks-----\nSubtask #1 (20 points): $|A|, |B| \\le 30$\nSubtask #2 (30 points):\n- $|A|, |B| \\le 500$\n- the sum of $|A| + |B|$ over all test cases does not exceed $10^5$\nSubtask #3 (50 points): original constraints\n\n-----Example Input-----\n3\n100010\n0\n0\n100010\n11100\n1010\n\n-----Example Output-----\n0\n1\n3\n\n-----Explanation-----\nExample case 1: The initial value of $B$ is $0$, so while-loop is not performed at all.\nExample case 2: The initial values of $A$ and $B$ are $0_2 = 0$ and $100010_2 = 34$ respectively. When the while-loop is performed for the first time, we have:\n- $U = 34$\n- $V = 0$\n- $A$ changes to $34$\n- $B$ changes to $2 \\cdot 0 = 0$\nThe while-loop terminates immediately afterwards, so it is executed only once.\nExample case 3: The initial values of $A$ and $B$ are $11100_2 = 28$ and $1010_2 = 10$ respectively. After the first iteration, their values change to $22$ and $16$ respectively. After the second iteration, they change to $6$ and $32$, and finally, after the third iteration, to $38$ and $0$.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\ndef add(A, B):\n cnt = 0\n while B > 0:\n U = A ^ B\n B = (A & B) * 2\n A = U\n cnt += 1\n return cnt\n\nfor _ in range(int(input())):\n print(add(int(input(),2), int(input(), 2)))\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\n100010\\n0\\n0\\n100010\\n11100\\n1010\\n', 'output': '0\\n1\\n3\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/BINADD'}","problem_id":"vfc_4450","program":"```python\ndef add(A, B):\n cnt = 0\n while B > 0:\n U = A ^ B\n B = (A & B) * 2\n A = U\n cnt += 1\n return cnt\n\nfor _ in range(int(input())):\n print(add(int(input(),2), int(input(), 2)))\n```","inputs":"3\n100010\n0\n0\n100010\n11100\n1010\n","output":"0\n1\n3\n","actual_output":"0\n1\n3\n","execution_success":true,"sample_index":993},{"source":"apps","task_type":"verifiable_code","in_source_id":"1403","prompt":"Solve the following coding problem using the programming language python:\n\nDhruvil has always been a studious person and will be completing his Engineering soon. He is always kneen about solving problems and is preparing hard for his next interview at Hackerrank. He has practiced lots of problems and now he came across this problem.\nGiven a message containing English letters(A-Z), it is being encoded to numbers using the following mapping:\n'A' -> 1,'B' -> 2 \u2026\u2026\u2026\u2026\u2026\u2026 'Z' -> 26.\nNow, given a non-empty string containing only digits, help Dhruvil determine the total number of ways to decode it.\nWhile decoding you need to choose a substring of charachters and not a subsequence. Also a chosen substring should not contain any leading \"0\"s, but can contain trailing \"0\"s. Since the output can be very large print the answer as modulo 10^9 + 7 i.e 1000000007.\n\n-----Input:-----\nThe first line of the input consists of single integer T, the number of test cases.\nEach test case consists of a string.\n\n-----Output:-----\nFor each test case print a single integer - the total number of ways to decode the digit string.\n\n-----Constraints-----\n- $1 \\leq T \\leq 1000$\n- $2 \\leq S \\leq 10^9$\n\n-----Sample Input:-----\n2\n12\n\n226\n\n-----Sample Output:-----\n2\n\n3\n\n-----EXPLANATION:-----\nThere are 2 possible ways. It could be decoded as \"AB\" {1,2} or \"L\" {12}.\nThere are 3 possible ways. It could be decoded as \"BZ\" {2,26}, \"VF\" {22,6}, or \"BBF\" {2,2,6}.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\n# cook your dish here\ndef numDec(s):\n if not s:\n return 0\n\n dp = [0 for _ in range(len(s) + 1)]\n\n dp[0] = 1\n dp[1] = 0 if s[0] == '0' else 1\n\n\n for i in range(2, len(dp)):\n\n if s[i-1] != '0':\n dp[i] += dp[i-1]\n\n two_digit = int(s[i-2 : i])\n if two_digit >= 10 and two_digit <= 26:\n dp[i] += dp[i-2]\n return dp[len(s)]\n\nt = int(input())\n\nwhile(t):\n t-=1\n s = input()\n print(numDec(s)%1000000007)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n12\\n226\\n', 'output': '2\\n3\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/CEFT2020/problems/INTER'}","problem_id":"vfc_4454","program":"```python\n# cook your dish here\n# cook your dish here\ndef numDec(s):\n if not s:\n return 0\n\n dp = [0 for _ in range(len(s) + 1)]\n\n dp[0] = 1\n dp[1] = 0 if s[0] == '0' else 1\n\n\n for i in range(2, len(dp)):\n\n if s[i-1] != '0':\n dp[i] += dp[i-1]\n\n two_digit = int(s[i-2 : i])\n if two_digit >= 10 and two_digit <= 26:\n dp[i] += dp[i-2]\n return dp[len(s)]\n\nt = int(input())\n\nwhile(t):\n t-=1\n s = input()\n print(numDec(s)%1000000007)\n```","inputs":"2\n12\n226\n","output":"2\n3\n","actual_output":"2\n3\n","execution_success":true,"sample_index":994},{"source":"apps","task_type":"verifiable_code","in_source_id":"1405","prompt":"Solve the following coding problem using the programming language python:\n\nThere are $N$ sabotages available in the game Among Us, initially all at level $0$. \n$N$ imposters are allotted the task to upgrade the level of the sabotages. \nThe $i^{th}$ imposter $(1 \\leq i \\leq N)$ increases the level of $x^{th}$ sabotage $(1 \\leq x \\leq N)$ by one level if $gcd(i,x)=i$.\nYou need to find the number of sabotages at LEVEL 5 after all the imposters have completed their tasks.\n\n-----Input:-----\n- First line will contain $T$, number of testcases. Then the testcases follow. \n- Each testcase contains of a single line of input, one integer $N$. \n\n-----Output:-----\nFor each testcase, output in a single line the number of sabotages at LEVEL 5.\n\n-----Constraints-----\n- $1 \\leq T \\leq 10^5$\n- $1 \\leq N \\leq 10^{18}$\n\n-----Sample Input:-----\n1\n6\n\n-----Sample Output:-----\n0\n\n-----EXPLANATION:-----\nThe $1^{st}$ sabotage is at level $1$, the $2^{nd}$, $3^{rd}$ and $5^{th}$ sabotages are at level $2$, the $4^{th}$ sabotage is at level $3$ and the $6^{th}$ sabotage is at level $4$.\nNone of them reach level $5$. Hence the output is $0$.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfrom bisect import bisect\nn = 32000\ndef primeSeive(n):\n prime = [True for i in range(n + 1)]\n primes = []\n p = 2\n while (p * p <= n):\n if (prime[p] == True):\n for i in range(p * 2, n + 1, p):\n prime[i] = False\n p += 1\n prime[0] = False\n prime[1] = False\n for p in range(n + 1):\n if prime[p]:\n primes.append(p)\n return primes\narr = primeSeive(n)\nfin = []\nfor i in arr:\n fin.append(pow(i,4))\nfor _ in range(int(input())):\n n = int(input())\n print(bisect(fin,n))\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n6\\n', 'output': '0\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/RC152020/problems/REC15B'}","problem_id":"vfc_4462","program":"```python\nfrom bisect import bisect\nn = 32000\ndef primeSeive(n):\n prime = [True for i in range(n + 1)]\n primes = []\n p = 2\n while (p * p <= n):\n if (prime[p] == True):\n for i in range(p * 2, n + 1, p):\n prime[i] = False\n p += 1\n prime[0] = False\n prime[1] = False\n for p in range(n + 1):\n if prime[p]:\n primes.append(p)\n return primes\narr = primeSeive(n)\nfin = []\nfor i in arr:\n fin.append(pow(i,4))\nfor _ in range(int(input())):\n n = int(input())\n print(bisect(fin,n))\n\n```","inputs":"1\n6\n","output":"0\n","actual_output":"0\n","execution_success":true,"sample_index":995},{"source":"apps","task_type":"verifiable_code","in_source_id":"1406","prompt":"Solve the following coding problem using the programming language python:\n\nA sophomore Computer Science student is frustrated with boring college lectures. Professor X agreed to give him some questions; if the student answers all questions correctly, then minimum attendance criteria will not apply to him.\nProfessor X chooses a sequence $A_1, A_2, \\ldots, A_N$ and asks $Q$ queries. In each query, the student is given an integer $P$; he has to construct a sequence $B_1, B_2, \\ldots, B_N$, where $P \\oplus A_i = B_i$ for each valid $i$ ($\\oplus$ denotes bitwise XOR), and then he has to find the number of elements of this sequence which have an even number of $1$-s in the binary representation and the number of elements with an odd number of $1$-s in the binary representation. Help him answer the queries.\n\n-----Input-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The first line of each test case contains two space-separated integers $N$ and $Q$.\n- The second line contains $N$ space-separated integers $A_1, A_2, \\ldots, A_N$.\n- $Q$ lines follow. Each of these lines contains a single integer $P$ describing a query.\n\n-----Output-----\nFor each query, print a single line containing two space-separated integers \u2015 the number of elements with an even number of $1$-s and the number of elements with an odd number of $1$-s in the binary representation.\n\n-----Constraints-----\n- $1 \\le T \\le 100$\n- $1 \\le N, Q \\le 10^5$\n- $ T \\cdot (N+Q) \\leq 4 \\cdot 10^6 $\n- $1 \\le A_i \\le 10^8$ for each valid $i$\n- $1 \\le P \\le 10^5$\nThe input/output is quite large, please use fast reading and writing methods.\n\n-----Subtasks-----\nSubtask #1 (30 points): $N, Q \\le 1,000$\nSubtask #2 (70 points): original constraints\n\n-----Example Input-----\n1\n6 1\n4 2 15 9 8 8\n3\n\n-----Example Output-----\n2 4\n\n-----Explanation-----\nExample case 1: The elements of the sequence $B$ are $P \\oplus 4 = 7$, $P \\oplus 2 = 1$, $P \\oplus 15 = 12$, $P \\oplus 9 = 10$, $P \\oplus 8 = 11$ and $P \\oplus 8 = 11$. The elements which have an even number of $1$-s in the binary representation are $12$ and $10$, while the elements with an odd number of $1$-s are $7$, $1$, $11$ and $11$.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\nfrom sys import stdin, stdout\n\nfor _ in range(int(stdin.readline())):\n n, q = list(map(int, stdin.readline().split()))\n arr = list(map(int, stdin.readline().split()))[:n]\n od = ev = 0\n for i in arr:\n if bin(i).count('1')%2==0:\n ev += 1\n else:\n od += 1\n for _ in range(q):\n p = int(stdin.readline())\n if bin(p).count('1')%2==0:\n stdout.write(str(ev) + \" \" + str(od) + \"\\n\")\n else:\n stdout.write(str(od) + \" \" + str(ev) + \"\\n\")\n\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n6 1\\n4 2 15 9 8 8\\n3\\n', 'output': '2 4\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/ENGXOR'}","problem_id":"vfc_4466","program":"```python\n# cook your dish here\nfrom sys import stdin, stdout\n\nfor _ in range(int(stdin.readline())):\n n, q = list(map(int, stdin.readline().split()))\n arr = list(map(int, stdin.readline().split()))[:n]\n od = ev = 0\n for i in arr:\n if bin(i).count('1')%2==0:\n ev += 1\n else:\n od += 1\n for _ in range(q):\n p = int(stdin.readline())\n if bin(p).count('1')%2==0:\n stdout.write(str(ev) + \" \" + str(od) + \"\\n\")\n else:\n stdout.write(str(od) + \" \" + str(ev) + \"\\n\")\n\n\n```","inputs":"1\n6 1\n4 2 15 9 8 8\n3\n","output":"2 4\n","actual_output":"2 4\n","execution_success":true,"sample_index":996},{"source":"apps","task_type":"verifiable_code","in_source_id":"1408","prompt":"Solve the following coding problem using the programming language python:\n\nChef's loves his dog so much! Once his dog created two strings a and b each of length n consisting of digits 1 and 2, and even a problem about them!\nChef's Dog will tell by barking if a string x (also containing only digits 1 and 2 and with length N) is good or not by performing the following actions.\n\n- It starts at first digit of the string, i.e. at i = 1. \n- It can move from digit i to either i - 1 or i + 1 if xi equals 1 and the corresponding digits exist. \n- It can move from digit i to either i - 2 or i + 2 if xi equals 2 and the corresponding digits exist. \n- It must visit each digit exactly once. \n- It must finish at the last digit (XN). \n\nChef's dog wants to make both the strings a and b good by choosing some subset S (possibly empty) of indices of set {1, 2, ..., n} and swapping each index i \u03f5 S between string a and b, i.e. swapping ai and bi. Can you find how many such subsets S exist out there? As the answer could be large, output it modulo 109 + 7.\n\n-----Input-----\nThe first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.\nThe first line contains string a.\nThe second line contains string b.\n\n-----Output-----\nFor each test case, output a single line containing answer of the problem.\n\n-----Constraints-----\n- 1 \u2264 T \u2264 20\n- 1 \u2264 |a| = |b| \u2264 105\n- '1' \u2264 ai, bi \u2264 '2'\n\n-----Subtasks-----\n- Subtask #1 (30 points) |a|, |b| \u2264 10\n- Subtask #2 (70 points) original constraints\n\n-----Example-----\nInput:\n2\n1111\n2211\n222\n111\n\nOutput:\n8\n0\n\n-----Explanation-----\nTest case 1.\nPossible subsets are: \n{}, {1, 2}, {1, 2, 3}, {1, 2, 4}, {1, 2, 3, 4}, {3}, {4}, {3, 4}.\n\nTest case 2. There are no possible sets S which can make both the strings good.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nmod = 10 ** 9 + 7\nfrom collections import Counter\nchoice = {'1' : ['11', '21', '22'], '2' : ['11', '12', '21']}\ndef solve(a,b):\n n = len(a)\n if n == 1:\n return 2\n dp = Counter([('11', '11')])\n for i in range(n-1):\n new = Counter()\n for x,y in (a[i], b[i]), (b[i], a[i]):\n for p in choice[x]:\n for q in choice[y]:\n m = p[-1] + x \n n = q[-1] + y\n new[m,n] += dp[p,q]\n new[m,n] %= mod\n dp = new\n ans = 0 \n for i in '11', '21', :\n for j in '11', '21':\n ans += dp[i,j]\n return (ans * 2) % mod\n\n \nt = int(input())\nfor _ in range(t):\n a = input()\n b = input()\n print(solve(a,b))\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n1111\\n2211\\n222\\n111\\n', 'output': '8\\n0\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/CHEFTWOS'}","problem_id":"vfc_4474","program":"```python\nmod = 10 ** 9 + 7\nfrom collections import Counter\nchoice = {'1' : ['11', '21', '22'], '2' : ['11', '12', '21']}\ndef solve(a,b):\n n = len(a)\n if n == 1:\n return 2\n dp = Counter([('11', '11')])\n for i in range(n-1):\n new = Counter()\n for x,y in (a[i], b[i]), (b[i], a[i]):\n for p in choice[x]:\n for q in choice[y]:\n m = p[-1] + x \n n = q[-1] + y\n new[m,n] += dp[p,q]\n new[m,n] %= mod\n dp = new\n ans = 0 \n for i in '11', '21', :\n for j in '11', '21':\n ans += dp[i,j]\n return (ans * 2) % mod\n\n \nt = int(input())\nfor _ in range(t):\n a = input()\n b = input()\n print(solve(a,b))\n```","inputs":"2\n1111\n2211\n222\n111\n","output":"8\n0\n","actual_output":"8\n0\n","execution_success":true,"sample_index":998},{"source":"apps","task_type":"verifiable_code","in_source_id":"1409","prompt":"Solve the following coding problem using the programming language python:\n\nChef solved so many hard questions, now he wants to solve some easy problems for refreshment. Chef asks Cheffina for the new question. Cheffina challanges the chef to print the total number of 1's in the binary representation of N(natural number).\n\n-----Input:-----\n- First-line will contain $T$, the number of test cases. Then the test cases follow. \n- Each test case contains a single line of input, $N$. \n\n-----Output:-----\nFor each test case, output in a single line answer.\n\n-----Constraints-----\n- $1 \\leq T \\leq 10^6$\n- $1 \\leq N \\leq 10^6$\n\n-----Sample Input:-----\n2\n2\n5\n\n-----Sample Output:-----\n1\n2\n\n-----EXPLANATION:-----\nFor 1) Binary representation of 2 is 10. i.e. only one 1 present in it.\nFor 2) Binary representation of 5 is 101, i.e. two 1's present in it.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfor t in range(int(input())):\r\n n=int(input())\r\n print(bin(n).count(\"1\")) \n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n2\\n5\\n', 'output': '1\\n2\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/PBK22020/problems/ITGUY25'}","problem_id":"vfc_4478","program":"```python\nfor t in range(int(input())):\r\n n=int(input())\r\n print(bin(n).count(\"1\")) \n```","inputs":"2\n2\n5\n","output":"1\n2\n","actual_output":"1\n2\n","execution_success":true,"sample_index":999},{"source":"apps","task_type":"verifiable_code","in_source_id":"1411","prompt":"Solve the following coding problem using the programming language python:\n\nMotu and Patlu are racing against each other on a circular track of radius $R$. Initially they are at the same point on the track and will run in same direction .The coach ordered them to run $X$ rounds of the circular field. Patlu wants to know how many times they will meet after the race starts and before any of them finishes $X$ rounds. But he is busy in warm up so he wants you to calculate this. You are given speed of both Motu and Patlu ($A$ and $B$). \n\n-----Input:-----\n- First line will contain $T$, number of testcases. Then the testcases follow. \n- Each testcase contains of a single line of input, four integers $X, R, A, B$. \n\n-----Output:-----\nFor each testcase, output in a single line answer the number of times whey will meet before any of them completes $X$ rounds.\n\n-----Constraints-----\n- $1 \\leq T \\leq 1000$\n- $1 \\leq R \\leq 10^9$\n- $1 \\leq X \\leq 10^9$\n- $1 \\leq A \\leq 10^9$\n- $1 \\leq B \\leq 10^9$\n- Speed of both are different\n\n-----Sample Input:-----\n2\n3 10 2 5\n2 20 5 10\n\n-----Sample Output:-----\n1\n0\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\nimport math\ndef swap(a,b):\n return b,a\n\nt = int(input())\nwhile(t!=0):\n z = list(map(int,input().strip().split(\" \")))\n x=z[0]\n r=z[1]\n a=z[2]\n b=z[3]\n #p = math.pi\n peri = 2*r\n tp = x*peri\n \n if(asum2 :\n print(' '.join(map(str,s1[0])))\n print(' '.join(map(str,new1)))\n else :\n print(' '.join(map(str,new1)))\n print(' '.join(map(str,s1[0])))\nelse :\n z = len(s1[0])//2\n n = list(itertools.combinations(s1[0],z))\n for j in range(len(n)) :\n x = sum(n[j])\n if x==sum1//2 :\n lis = n[j]\n break\n #print lis,len(lis)\n new1 = list(lis)\n sum2 = sum(new1)\n for j in range(len(lis)) :\n y = lis[j]\n s1[0].remove(y)\n sum3 = sum(s1[0])\n if sum3>sum2 :\n print(' '.join(map(str,s1[0])))\n print(' '.join(map(str,new1)))\n else :\n print(' '.join(map(str,new1)))\n print(' '.join(map(str,s1[0])))\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '7\\n1 2 3 4 5 6 7\\n', 'output': '1 2 4 7\\n3 5 6\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/SOPC2015/problems/SOPC1504'}","problem_id":"vfc_4506","program":"```python\ns,n,s1,lis,new1=[],[],[],[],[]\nimport itertools\nq = int(input())\ns.append(input().split(' '))\ns1 = list([list(map(int,x)) for x in s])\nsum1 = sum(s1[0])\nif len(s1[0])%2!=0 :\n z = (len(s1[0])+1)//2\n n = list(itertools.combinations(s1[0],z))\n for j in range(len(n)) :\n x = sum(n[j])\n if x==sum1//2 :\n lis = n[j]\n break\n new1 = list(lis)\n sum2 = sum(new1)\n for j in range(len(lis)) :\n y = lis[j]\n s1[0].remove(y)\n sum3=sum(s1[0])\n if sum3>sum2 :\n print(' '.join(map(str,s1[0])))\n print(' '.join(map(str,new1)))\n else :\n print(' '.join(map(str,new1)))\n print(' '.join(map(str,s1[0])))\nelse :\n z = len(s1[0])//2\n n = list(itertools.combinations(s1[0],z))\n for j in range(len(n)) :\n x = sum(n[j])\n if x==sum1//2 :\n lis = n[j]\n break\n #print lis,len(lis)\n new1 = list(lis)\n sum2 = sum(new1)\n for j in range(len(lis)) :\n y = lis[j]\n s1[0].remove(y)\n sum3 = sum(s1[0])\n if sum3>sum2 :\n print(' '.join(map(str,s1[0])))\n print(' '.join(map(str,new1)))\n else :\n print(' '.join(map(str,new1)))\n print(' '.join(map(str,s1[0])))\n```","inputs":"7\n1 2 3 4 5 6 7\n","output":"1 2 4 7\n3 5 6\n","actual_output":"1 2 4 7\n3 5 6\n","execution_success":true,"sample_index":1006},{"source":"apps","task_type":"verifiable_code","in_source_id":"1417","prompt":"Solve the following coding problem using the programming language python:\n\nRaj loves to listen to songs in his free time. It\u2019s his birthday tomorrow and his friend Neelansh wants his gift to be the most unique. Being great at making music, he decides to produce a song for him. However, Raj likes songs according to their beauty. He determines the beauty of the song as the number of times all the octave musical tones are completed in ascending order.\n\nHe begins with a jumbled tone of length N and numbers each octave tone as 1,2,3\u2026.8.\n\nNeelansh wants to maximize the beauty of the song but since he uses the trial version of the software,\n- He cannot change the size of N.\n- He cannot introduce any new tone, but can choose any two tones and swap their positions\n\nHowever, Neelansh just received a mail that he needs to submit all his pending assignments by tomorrow. He has tons of assignments left to do, but he doesn\u2019t want to spoil the idea of his gift. Can you help him? \n\n-----INPUT-----\n- The first line contains a single integer T- the number of test cases \n- The first line of each test case contains a single integer N- the length of the song \n- The second line contains N- space separated integers ai, ai+1,.....aN \n\n-----OUTPUT-----\nFor each test case, print a single line containing one integer- the maximum possible beauty of the song \n\n-----CONSTRAINTS-----\n1<=T<=102\n1<=N<=105\n1<=a<=8\n\n-----EXAMPLE INPUT-----\n2\n\n8\n\n1 2 3 4 5 6 7 8\n\n16\n\n1 2 1 2 3 3 4 4 5 5 6 6 7 8 7 8\n\n-----EXAMPLE OUTPUT-----\n1\n\n2\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfor _ in range(int(input())):\r\n n = int(input())\r\n ar = list(map(int,input().split()))\r\n d = {}\r\n for ele in ar:\r\n if ele in d:\r\n d[ele] += 1\r\n else:\r\n d[ele] = 1\r\n m = 99999\r\n count = 0\r\n for ele in d:\r\n count+=1\r\n if m>d[ele]:\r\n m = d[ele]\r\n if count!=8:\r\n print(0)\r\n else:\r\n print(m)\r\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n8\\n1 2 3 4 5 6 7 8\\n16\\n1 2 1 2 3 3 4 4 5 5 6 6 7 8 7 8\\n', 'output': '1\\n2\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/CSPR2020/problems/OCTAVE'}","problem_id":"vfc_4510","program":"```python\nfor _ in range(int(input())):\r\n n = int(input())\r\n ar = list(map(int,input().split()))\r\n d = {}\r\n for ele in ar:\r\n if ele in d:\r\n d[ele] += 1\r\n else:\r\n d[ele] = 1\r\n m = 99999\r\n count = 0\r\n for ele in d:\r\n count+=1\r\n if m>d[ele]:\r\n m = d[ele]\r\n if count!=8:\r\n print(0)\r\n else:\r\n print(m)\r\n\n```","inputs":"2\n8\n1 2 3 4 5 6 7 8\n16\n1 2 1 2 3 3 4 4 5 5 6 6 7 8 7 8\n","output":"1\n2\n","actual_output":"1\n2\n","execution_success":true,"sample_index":1007},{"source":"apps","task_type":"verifiable_code","in_source_id":"1418","prompt":"Solve the following coding problem using the programming language python:\n\nYou are given a sequence $A_1, A_2, \\ldots, A_N$. You may perform the following operation an arbitrary number of times (including zero): choose two adjacent elements of this sequence, i.e. $A_i$, $A_{i+1}$ for some valid $i$, and swap them. However, for each valid $i$, it is not allowed to choose $A_i$ (the element with the index $i$, regardless of its value at any point in time) more than once in total during this process.\nFind the maximum of the sum $S = \\sum_{i=1}^N A_i \\cdot i$.\n\n-----Input-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The first line of each test case contains a single integer $N$.\n- The second line contains $N$ space-separated integers $A_1, A_2, \\ldots, A_N$.\n\n-----Output-----\nFor each test case, print a single line containing one integer \u2015 the maximum possible value of $S$.\n\n-----Constraints-----\n- $1 \\le T \\le 1,000$\n- $1 \\le N \\le 10^5$\n- $1 \\le A_i \\le 10^9$ for each valid $i$\n- the sum of $N$ over all test cases does not exceed $10^6$\n\n-----Subtasks-----\nSubtask #1 (50 points):\n- $N \\le 20$\n- the sum of $N$ over all test cases does not exceed $200$\nSubtask #2 (50 points): original constraints\n\n-----Example Input-----\n2\n4\n2 1 4 3\n4\n7 6 3 2\n\n-----Example Output-----\n30\n39\n\n-----Explanation-----\nExample case 1: Swap the first and second element of the initial sequence. Then, swap the third and fourth element of the resulting sequence. The final sequence $A$ is $(1, 2, 3, 4)$.\nExample case 2: Swap the second and third element to make the sequence $(7, 3, 6, 2)$.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\n# cook your dish here\nfor _ in range(int(input())):\n n=int(input())\n l=list(map(int, input().split()))\n l.insert(0, 0)\n l1=[0]*(n+1)\n l1[1]=l[1]\n for i in range(2, n+1):\n l1[i]=max(l1[i-1]+l[i]*i, l1[i-2]+l[i-1]*i+l[i]*(i-1))\n \n print(l1[-1]) \n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n4\\n2 1 4 3\\n4\\n7 6 3 2\\n', 'output': '30\\n39\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/SFRV'}","problem_id":"vfc_4514","program":"```python\n# cook your dish here\n# cook your dish here\nfor _ in range(int(input())):\n n=int(input())\n l=list(map(int, input().split()))\n l.insert(0, 0)\n l1=[0]*(n+1)\n l1[1]=l[1]\n for i in range(2, n+1):\n l1[i]=max(l1[i-1]+l[i]*i, l1[i-2]+l[i-1]*i+l[i]*(i-1))\n \n print(l1[-1]) \n```","inputs":"2\n4\n2 1 4 3\n4\n7 6 3 2\n","output":"30\n39\n","actual_output":"30\n39\n","execution_success":true,"sample_index":1008},{"source":"apps","task_type":"verifiable_code","in_source_id":"1419","prompt":"Solve the following coding problem using the programming language python:\n\nMr. Wilson was planning to record his new Progressive Rock music album called \"Digits. Cannot. Separate\". Xenny and PowerShell, popular pseudo-number-theoreticists from the Land of Lazarus were called by him to devise a strategy to ensure the success of this new album. Xenny and Powershell took their Piano Lessons and arrived at the Studio in different Trains.\nMr. Wilson, creative as usual, had created one single, long music track S. The track consisted of N musical notes. The beauty of each musical note was represented by a decimal digit from 0 to 9.\nMr. Wilson told them that he wanted to create multiple musical tracks out of this long song. Since Xenny and Powershell were more into the number theory part of music, they didn\u2019t know much about their real workings. Mr. Wilson told them that a separator could be placed between 2 digits. After placing separators, the digits between 2 separators would be the constituents of this new track and the number formed by joining them together would represent the Quality Value of that track. He also wanted them to make sure that no number formed had greater than M digits.\nMr. Wilson had Y separators with him. He wanted Xenny and PowerShell to use at least X of those separators, otherwise he would have to ask them to Drive Home.\nXenny and PowerShell knew straight away that they had to put place separators in such a way that the Greatest Common Divisor (GCD) of all the Quality Values would eventually determine the success of this new album. Hence, they had to find a strategy to maximize the GCD.\nIf you find the maximum GCD of all Quality Values that can be obtained after placing the separators, Xenny and PowerShell shall present you with a Porcupine Tree.\nNote:\n- \nYou can read about GCD here.\n\n- \nGreatest Common Divisor of 0 and 0 is defined as 0.\n\n-----Input-----\nThe first line of input consists of a single integer T - the number of testcases.\nEach test case is of the following format:\nFirst line contains a single integer N - the length of the long musical track.\nSecond line contains the string of digits S.\nThird line contains 3 space-separated integers - M, X and Y - the maximum number of digits in a number, the minimum number of separators to be used and the maximum number of separators to be used.\n\n-----Output-----\nFor each testcase, output a single integer on a new line - the maximum GCD possible after placing the separators.\n\n-----Constraints-----\nSubtask 1: 20 points\n\n- 1 \u2264 T \u2264 10\n- 1 \u2264 N \u2264 18\n- 1 \u2264 M \u2264 2\n- 1 \u2264 X \u2264 Y \u2264 (N - 1)\n\nSubtask 2: 80 points\n\n- 1 \u2264 T \u2264 10\n- 1 \u2264 N \u2264 300\n- 1 \u2264 M \u2264 10\n- 1 \u2264 X \u2264 Y \u2264 (N - 1)\n\nFor both Subtask 1 and Subtask 2:\n\n- 1 \u2264 X \u2264 Y \u2264 (N - 1)\n- M*(Y+1) \u2265 N\n- S may contain leading 0s.\n\n-----Example-----Input:\n2\n3\n474\n2 1 1\n34\n6311861109697810998905373107116111\n10 4 25\n\nOutput:\n2\n1\n\n-----Explanation-----\nTest case 1. \nSince only 1 separator can be placed, we can only have 2 possibilities:\n\na. 4 | 74\n\nThe GCD in this case is 2.\n\nb. 47 | 4\n\nThe GCD in this case is 1.\n\nHence, the maximum GCD is 2.\nTest case 2.\n\nOne of the optimal partitions is:\n63|118|61|109|69|78|109|98|90|53|73|107|116|111\nBonus: Decode the above partition to unlock a hidden treasure.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n\n\n\nt = int(input())\n\ndef gcd (a, b):\n if (b == 0): return a\n return gcd (b, a % b)\n\ndp = {}\n\ndef solve (p, k, g, s, m, x, y, n):\n if ((p, k, g) in dp): return dp[(p, k, g)];\n \n ans = 0\n\n if (p == n): \n if k >= x and k <= y:\n ans = g\n else:\n ans = 0 \n else: \n for i in range (p, n):\n \n if (i - p + 1 > m): break\n \n temp = solve (i + 1, k + 1, gcd(g, int(s[p:i + 1])), s, m, x, y, n)\n if (temp > ans):\n ans = temp\n \n dp[(p, k, g)] = ans\n return ans\n \n\nwhile t != 0:\n dp = {}\n t -= 1\n n = int(input())\n s = input()\n m, x, y = list(map (int, input().split()))\n x += 1\n y += 1\n \n print(solve (0, 0, 0, s, m, x, y, n))\n \n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n3\\n474\\n2 1 1\\n34\\n6311861109697810998905373107116111\\n10 4 25\\n', 'output': '2\\n1\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/DIGITSEP'}","problem_id":"vfc_4518","program":"```python\n\n\n\nt = int(input())\n\ndef gcd (a, b):\n if (b == 0): return a\n return gcd (b, a % b)\n\ndp = {}\n\ndef solve (p, k, g, s, m, x, y, n):\n if ((p, k, g) in dp): return dp[(p, k, g)];\n \n ans = 0\n\n if (p == n): \n if k >= x and k <= y:\n ans = g\n else:\n ans = 0 \n else: \n for i in range (p, n):\n \n if (i - p + 1 > m): break\n \n temp = solve (i + 1, k + 1, gcd(g, int(s[p:i + 1])), s, m, x, y, n)\n if (temp > ans):\n ans = temp\n \n dp[(p, k, g)] = ans\n return ans\n \n\nwhile t != 0:\n dp = {}\n t -= 1\n n = int(input())\n s = input()\n m, x, y = list(map (int, input().split()))\n x += 1\n y += 1\n \n print(solve (0, 0, 0, s, m, x, y, n))\n \n\n```","inputs":"2\n3\n474\n2 1 1\n34\n6311861109697810998905373107116111\n10 4 25\n","output":"2\n1\n","actual_output":"2\n1\n","execution_success":true,"sample_index":1009},{"source":"apps","task_type":"verifiable_code","in_source_id":"1421","prompt":"Solve the following coding problem using the programming language python:\n\nPatlu has recently got a new problem based on Pallindromes. A Pallindrome is a number that is same from front and back, example $121$ is pallindrome but $123$ is not . He wants to calculate sum of all $N$ digit number which are Pallindromic in nature and divisible by $9$ and does not contain any zero in their decimal representation. As the answer can be very large so print the sum modulo $10^9 + 7$.\n\n-----Input:-----\n- First line of input contain $T$, number of testcases. Then the testcases follow.\n- Each testcase contains single line of input , one integer $N$.\n\n-----Output:-----\n- For each testcase, output in a single line answer having $N$ digits pallindromic string.\n\n-----Constraints-----\n- $1\\leq T \\leq 100$\n- $1\\leq N \\leq 10^5$\n\n-----Sample Input:-----\n2\n1\n2\n\n-----Sample Output:-----\n9\n99\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\ndef getsum(N):\n\tif N==1:\n\t\treturn 9\n\tif N==2:\n\t\treturn 99\n\ts = \"\"\n\tfor i in range(0,N):\n\t\ts = s+'5'\n\ts = int(s)\n\tif N%2==0:\n\t\ts = s*pow(9,N//2-1)\n\telse:\n\t\ts = s*pow(9,N//2)\n\treturn s%(pow(10,9)+7)\n\ndef main():\n\tt = int(input())\n\tfor _ in range(0,t):\n\t\tN = int(input())\n\t\tresult = getsum(N)\n\t\tprint(result)\ndef __starting_point():\n\tmain()\n\n__starting_point()\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n1\\n2\\n', 'output': '9\\n99\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/CCOD2020/problems/PALL9'}","problem_id":"vfc_4526","program":"```python\ndef getsum(N):\n\tif N==1:\n\t\treturn 9\n\tif N==2:\n\t\treturn 99\n\ts = \"\"\n\tfor i in range(0,N):\n\t\ts = s+'5'\n\ts = int(s)\n\tif N%2==0:\n\t\ts = s*pow(9,N//2-1)\n\telse:\n\t\ts = s*pow(9,N//2)\n\treturn s%(pow(10,9)+7)\n\ndef main():\n\tt = int(input())\n\tfor _ in range(0,t):\n\t\tN = int(input())\n\t\tresult = getsum(N)\n\t\tprint(result)\ndef __starting_point():\n\tmain()\n\n__starting_point()\n```","inputs":"2\n1\n2\n","output":"9\n99\n","actual_output":"9\n99\n","execution_success":true,"sample_index":1010},{"source":"apps","task_type":"verifiable_code","in_source_id":"1422","prompt":"Solve the following coding problem using the programming language python:\n\nThe Little Elephant from the Zoo of Lviv currently is on the military mission. There are N enemy buildings placed in a row and numbered from left to right strating from 0. Each building i (except the first and the last) has exactly two adjacent buildings with indices i-1 and i+1. The first and the last buildings have just a single adjacent building.\n\nSome of the buildings contain bombs. When bomb explodes in some building it destroys it and all adjacent to it buildings.\n\nYou are given the string S of length N, where Si is 1 if the i-th building contains bomb, 0 otherwise. Find for the Little Elephant the number of buildings that will not be destroyed after all bombs explode. Please note that all bombs explode simultaneously.\n\n-----Input-----\nThe first line contains single integer T - the number of test cases. T test cases follow. The first line of each test case contains the single integer N - the number of buildings. The next line contains the string S of length N consisted only of digits 0 and 1.\n\n-----Output-----\nIn T lines print T inetgers - the answers for the corresponding test cases.\n\n-----Constraints-----\n\n1 <= T <= 100\n\n1 <= N <= 1000\n\n-----Example-----\nInput:\n3\n3\n010\n5\n10001\n7\n0000000\n\nOutput:\n0\n1\n7\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nimport sys\nT = int(sys.stdin.readline().strip())\nfor t in range(T):\n sys.stdin.readline().strip()\n st = '0'+sys.stdin.readline().strip()+'0'\n res = 0\n for i in range(1,len(st)-1):\n if st[i] == st[i-1] == st[i+1] == '0':\n res+=1\n print(res)\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\n3\\n010\\n5\\n10001\\n7\\n0000000\\n', 'output': '0\\n1\\n7\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/AUG12/problems/LEBOMBS'}","problem_id":"vfc_4530","program":"```python\nimport sys\nT = int(sys.stdin.readline().strip())\nfor t in range(T):\n sys.stdin.readline().strip()\n st = '0'+sys.stdin.readline().strip()+'0'\n res = 0\n for i in range(1,len(st)-1):\n if st[i] == st[i-1] == st[i+1] == '0':\n res+=1\n print(res)\n\n```","inputs":"3\n3\n010\n5\n10001\n7\n0000000\n","output":"0\n1\n7\n","actual_output":"0\n1\n7\n","execution_success":true,"sample_index":1011},{"source":"apps","task_type":"verifiable_code","in_source_id":"1423","prompt":"Solve the following coding problem using the programming language python:\n\nVlad enjoys listening to music. He lives in Sam's Town. A few days ago he had a birthday, so his parents gave him a gift: MP3-player! Vlad was the happiest man in the world! Now he can listen his favorite songs whenever he wants!\nVlad built up his own playlist. The playlist consists of N songs, each has a unique positive integer length. Vlad likes all the songs from his playlist, but there is a song, which he likes more than the others. It's named \"Uncle Johny\".\nAfter creation of the playlist, Vlad decided to sort the songs in increasing order of their lengths. For example, if the lengths of the songs in playlist was {1, 3, 5, 2, 4} after sorting it becomes {1, 2, 3, 4, 5}. Before the sorting, \"Uncle Johny\" was on K-th position (1-indexing is assumed for the playlist) in the playlist.\nVlad needs your help! He gives you all the information of his playlist. Your task is to find the position of \"Uncle Johny\" in the sorted playlist.\n\n-----Input-----\nThe first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows. \n\nThe first line of each test case contains one integer N denoting the number of songs in Vlad's playlist. The second line contains N space-separated integers A1, A2, ..., AN denoting the lenghts of Vlad's songs.\nThe third line contains the only integer K - the position of \"Uncle Johny\" in the initial playlist.\n\n-----Output-----\nFor each test case, output a single line containing the position of \"Uncle Johny\" in the sorted playlist.\n\n-----Constraints-----\n1 \u2264 T \u2264 1000\n\n1 \u2264 K \u2264 N \u2264 100\n\n1 \u2264 Ai \u2264 109\n\n-----Example-----\nInput:\n3\n4\n1 3 4 2\n2\n5\n1 2 3 9 4\n5\n5\n1 2 3 9 4 \n1\n\nOutput:\n3\n4\n1\n\n-----Explanation-----\nIn the example test there are T=3 test cases.\nTest case 1\nIn the first test case N equals to 4, K equals to 2, A equals to {1, 3, 4, 2}. The answer is 3, because {1, 3, 4, 2} -> {1, 2, 3, 4}. A2 now is on the 3-rd position.\nTest case 2\nIn the second test case N equals to 5, K equals to 5, A equals to {1, 2, 3, 9, 4}. The answer is 4, because {1, 2, 3, 9, 4} -> {1, 2, 3, 4, 9}. A5 now is on the 4-th position.\nTest case 3\nIn the third test case N equals to 5, K equals to 1, A equals to {1, 2, 3, 9, 4}. The answer is 1, because {1, 2, 3, 9, 4} -> {1, 2, 3, 4, 9}. A1 stays on the 1-th position.\n\n-----Note-----\n\"Uncle Johny\" is a real song performed by The Killers.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\nt=int(input())\nfor i in range(t):\n n=int(input())\n nums=list(map(int,input().split()))\n k=int(input())\n an=nums[k-1]\n cn=0\n for i in range(n):\n if(nums[i]0) :\n d=(d&(d+1))-1\n count[i]+=1\n\n\nfor i in range(t) :\n print(count[i])\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '4\\n001 100 011 4\\n1000 1101 100 3\\n1010 001 101 4\\n010 101 000 4\\n', 'output': '6\\n12\\n8\\n10\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/FENWITER'}","problem_id":"vfc_4542","program":"```python\nt=int(input())\ncount=[]\n\nfor i in range(t) :\n s = input()\n a,b,c,n = s.split()\n n=int(n)\n d = int(a+b*n+c,2)\n count.append(0)\n while(d>0) :\n d=(d&(d+1))-1\n count[i]+=1\n\n\nfor i in range(t) :\n print(count[i])\n\n```","inputs":"4\n001 100 011 4\n1000 1101 100 3\n1010 001 101 4\n010 101 000 4\n","output":"6\n12\n8\n10\n","actual_output":"6\n12\n8\n10\n","execution_success":true,"sample_index":1014},{"source":"apps","task_type":"verifiable_code","in_source_id":"1426","prompt":"Solve the following coding problem using the programming language python:\n\nChef is operating a slush machine. The machine produces slush drinks with $M$ flavors (numbered $1$ through $M$); for each valid $i$, the maximum number of drinks with flavour $i$ the machine can produce is $C_i$.\nChef expects $N$ customers to come buy slush drinks today. The customers are numbered $1$ through $N$ in the order in which they buy the drinks. For each valid $i$, the favorite flavour of the $i$-th customer is $D_i$ and this customer is willing to pay $F_i$ units of money for a drink with this flavour, or $B_i$ units of money for a drink with any other flavuor. Whenever a customer wants to buy a drink:\n- if it is possible to sell this customer a drink with their favourite flavour, Chef must sell them a drink with this flavour\n- otherwise, Chef must sell this customer a drink, but he may choose its flavour\nChef wants to make the maximum possible profit. He is asking you to help him decide the flavours of the drinks he should sell to the customers in order to maximise the profit.\n\n-----Input-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The first line of each test case contains two space-separated integers $N$ and $M$.\n- The second line contains $M$ space-separated integers $C_1, C_2, \\ldots, C_M$.\n- $N$ lines follow. For each valid $i$, the $i$-th of these lines contains three space-separated integers $D_i$, $F_i$ and $B_i$.\n\n-----Output-----\nFor each test case, print two lines:\n- The first of these lines should contain a single integer \u2014 the maximum profit.\n- The second line should contain $N$ space-separated integers denoting the flavours of the drinks Chef should sell, in this order.\nIf there are multiple solutions, you may find any one.\n\n-----Constraints-----\n- $1 \\le T \\le 1,000$\n- $2 \\le N, M \\le 10^5$\n- $1 \\le D_i \\le M$ for each valid $i$\n- $1 \\le C_i \\le N$ for each valid $i$\n- $1 \\le B_i < F_i \\le 10^9$ for each valid $i$\n- $C_1+C_2+\\ldots+C_M \\ge N$\n- the sum of $N$ over all test cases does not exceed $10^6$\n- the sum of $M$ over all test cases does not exceed $10^6$\n\n-----Example Input-----\n1\n5 3\n1 2 3\n2 6 3\n2 10 7\n2 50 3\n1 10 5\n1 7 4\n\n-----Example Output-----\n33\n2 2 3 1 3\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nt=int(input())\nfor i in range(t):\n n,m=list(map(int,input().split()))\n l=[0]+list(map(int,input().split()))\n s=0\n c=1\n m1=[]\n for i in range(n):\n d,f,b=list(map(int,input().split()))\n if(l[d]>0):\n m1.append(d)\n s+=f\n l[d]-=1\n else:\n m1.append(0)\n s+=b\n for i in range(n):\n if(m1[i]==0):\n for j in range(c,m+1):\n if(l[j]>0):\n m1[i]=j\n l[j]-=1\n c=j\n break\n print(s)\n print(*m1)\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n5 3\\n1 2 3\\n2 6 3\\n2 10 7\\n2 50 3\\n1 10 5\\n1 7 4\\n', 'output': '33\\n2 2 3 1 3\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/SLUSH'}","problem_id":"vfc_4546","program":"```python\nt=int(input())\nfor i in range(t):\n n,m=list(map(int,input().split()))\n l=[0]+list(map(int,input().split()))\n s=0\n c=1\n m1=[]\n for i in range(n):\n d,f,b=list(map(int,input().split()))\n if(l[d]>0):\n m1.append(d)\n s+=f\n l[d]-=1\n else:\n m1.append(0)\n s+=b\n for i in range(n):\n if(m1[i]==0):\n for j in range(c,m+1):\n if(l[j]>0):\n m1[i]=j\n l[j]-=1\n c=j\n break\n print(s)\n print(*m1)\n\n```","inputs":"1\n5 3\n1 2 3\n2 6 3\n2 10 7\n2 50 3\n1 10 5\n1 7 4\n","output":"33\n2 2 3 1 3\n","actual_output":"33\n2 2 3 1 3\n","execution_success":true,"sample_index":1015},{"source":"apps","task_type":"verifiable_code","in_source_id":"1427","prompt":"Solve the following coding problem using the programming language python:\n\nToday, puppy Tuzik is going to a new dog cinema. He has already left his home and just realised that he forgot his dog-collar! This is a real problem because the city is filled with catchers looking for stray dogs.\nA city where Tuzik lives in can be considered as an infinite grid, where each cell has exactly four neighbouring cells: those sharing a common side with the cell. Such a property of the city leads to the fact, that the distance between cells (xA, yA) and (xB, yB) equals |xA - xB| + |yA - yB|.\nInitially, the puppy started at the cell with coordinates (0, 0). There are N dog-catchers located at the cells with the coordinates (xi, yi), where 1 \u2264 i \u2264 N. Tuzik's path can be described as a string S of M characters, each of which belongs to the set {'D', 'U', 'L', 'R'} (corresponding to it moving down, up, left, and right, respectively). To estimate his level of safety, Tuzik wants to know the sum of the distances from each cell on his path to all the dog-catchers. You don't need to output this sum for the staring cell of the path (i.e. the cell with the coordinates (0, 0)).\n\n-----Input-----\nThe first line of the input contains two integers N and M.\nThe following N lines contain two integers xi and yi each, describing coordinates of the dog-catchers.\nThe last line of the input contains string S of M characters on the set {'D', 'U', 'L', 'R'}.\n- 'D' - decrease y by 1\n- 'U' - increase y by 1\n- 'L' - decrease x by 1\n- 'R' - increase x by 1\n\n-----Output-----\nOutput M lines: for each cell of the path (except the starting cell), output the required sum of the distances.\n\n-----Constraints-----\n- 1 \u2264 N \u2264 3 \u2715 105\n- 1 \u2264 M \u2264 3 \u2715 105\n- -106 \u2264 xi, yi \u2264 106\n\n-----Example-----\nInput:\n2 3\n1 2\n0 1\nRDL\n\nOutput:\n4\n6\n6\n\n-----Explanation-----\n\nInitially Tuzik stays at cell (0, 0). Let's consider his path:\n\n- Move 'R' to the cell (1, 0). Distance to the catcher (1, 2) equals 2, distance to the catcher (0, 1) equals 2, so the total distance equals 4\n- Move 'D' to the cell (1, -1). Distance to the catcher (1, 2) equals 3, distance to the catcher (0, 1) equals 3, so the total distance equals 6\n- Move 'L' to the cell (0, -1). Distance to the catcher (1, 2) equals 4, distance to the catcher (0, 1) equals 2, so the total distance equals 6\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\nfrom sys import stdin,stdout\na,b=list(map(int,stdin.readline().split()))\nleft=[]\ntop=[]\nfor i in range(a):\n c,d=list(map(int,stdin.readline().split()))\n left.append(c)\n top.append(d)\nleft.sort()\ntop.sort()\nfrom bisect import bisect_right as br\nfrom bisect import bisect_left as bl\nrow=0\ncol=0\ntotal=0\ncons_x=0\ncons_y=0\nfor i in range(len(left)):\n cons_x+=(abs(left[i]))\n cons_y+=(abs(top[i]))\ntotal=cons_x+cons_y\ncc=stdin.readline().rstrip()\nfor i in cc:\n if i==\"R\":\n kk=br(left,col)\n cons_x=(cons_x+kk-(a-kk))\n col+=1\n if i==\"L\":\n kk=bl(left,col)\n cons_x=(cons_x+(a-kk)-kk)\n col-=1\n if i==\"U\":\n kk=br(top,row)\n cons_y=(cons_y+kk-(a-kk))\n row+=1\n if i==\"D\":\n kk=bl(top,row)\n cons_y=(cons_y+(a-kk)-kk)\n row-=1\n stdout.write(str(cons_x+cons_y))\n stdout.write(\"\\n\")\n \n\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2 3\\n1 2\\n0 1\\nRDL\\n', 'output': '4\\n6\\n6\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/PPCTS'}","problem_id":"vfc_4550","program":"```python\n# cook your dish here\nfrom sys import stdin,stdout\na,b=list(map(int,stdin.readline().split()))\nleft=[]\ntop=[]\nfor i in range(a):\n c,d=list(map(int,stdin.readline().split()))\n left.append(c)\n top.append(d)\nleft.sort()\ntop.sort()\nfrom bisect import bisect_right as br\nfrom bisect import bisect_left as bl\nrow=0\ncol=0\ntotal=0\ncons_x=0\ncons_y=0\nfor i in range(len(left)):\n cons_x+=(abs(left[i]))\n cons_y+=(abs(top[i]))\ntotal=cons_x+cons_y\ncc=stdin.readline().rstrip()\nfor i in cc:\n if i==\"R\":\n kk=br(left,col)\n cons_x=(cons_x+kk-(a-kk))\n col+=1\n if i==\"L\":\n kk=bl(left,col)\n cons_x=(cons_x+(a-kk)-kk)\n col-=1\n if i==\"U\":\n kk=br(top,row)\n cons_y=(cons_y+kk-(a-kk))\n row+=1\n if i==\"D\":\n kk=bl(top,row)\n cons_y=(cons_y+(a-kk)-kk)\n row-=1\n stdout.write(str(cons_x+cons_y))\n stdout.write(\"\\n\")\n \n\n\n```","inputs":"2 3\n1 2\n0 1\nRDL\n","output":"4\n6\n6\n","actual_output":"4\n6\n6\n","execution_success":true,"sample_index":1016},{"source":"apps","task_type":"verifiable_code","in_source_id":"1428","prompt":"Solve the following coding problem using the programming language python:\n\nPied Piper is a startup company trying to build a new Internet called Pipernet. Currently, they have $A$ users and they gain $X$ users everyday. There is also another company called Hooli, which has currently $B$ users and gains $Y$ users everyday.\nWhichever company reaches $Z$ users first takes over Pipernet. In case both companies reach $Z$ users on the same day, Hooli takes over.\nHooli is a very evil company (like E-Corp in Mr. Robot or Innovative Online Industries in Ready Player One). Therefore, many people are trying to help Pied Piper gain some users.\nPied Piper has $N$ supporters with contribution values $C_1, C_2, \\ldots, C_N$. For each valid $i$, when the $i$-th supporter contributes, Pied Piper gains $C_i$ users instantly. After contributing, the contribution value of the supporter is halved, i.e. $C_i$ changes to $\\left\\lfloor C_i / 2 \\right\\rfloor$. Each supporter may contribute any number of times, including zero. Supporters may contribute at any time until one of the companies takes over Pipernet, even during the current day.\nFind the minimum number of times supporters must contribute (the minimum total number of contributions) so that Pied Piper gains control of Pipernet.\n\n-----Input-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The first line of each test case contains six space-separated integers $N$, $A$, $B$, $X$, $Y$ and $Z$.\n- The second line contains $N$ space-separated integers $C_1, C_2, \\ldots, C_N$ \u2014 the initial contribution values.\n\n-----Output-----\nFor each test case, if Hooli will always gain control of Pipernet, print a single line containing the string \"RIP\" (without quotes). Otherwise, print a single line containing one integer \u2014 the minimum number of times supporters must contribute.\n\n-----Constraints-----\n- $1 \\le T \\le 10$\n- $1 \\le N \\le 10^5$\n- $1 \\le A, B, X, Y, Z \\le 10^9$\n- $A, B < Z$\n- $0 \\le C_i \\le 10^9$ for each valid $i$\n\n-----Example Input-----\n3\n3 10 15 5 10 100\n12 15 18\n3 10 15 5 10 100\n5 5 10\n4 40 80 30 30 100\n100 100 100 100\n\n-----Example Output-----\n4\nRIP\n1\n\n-----Explanation-----\nExample case 1: After $8$ days, Pied Piper will have $50$ users and Hooli will have $95$ users. Then, if each supporter contributes once, Pied Piper will also have $95$ users. After that, they still need $5$ more users, so supporter $3$ can contribute again, with $18/2 = 9$ more users. So the answer will be $4$.\nExample case 2: There is no way to beat Hooli.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\nimport heapq as hq\nfrom math import floor\nfor _ in range(int(input())):\n n,a,b,x,y,z=map(int,input().split())\n arr=[-int(i) for i in input().split()]\n days=((z-b-1)//y)\n ans=0\n hq.heapify(arr)\n curr=a+days*x\n while curr=z:\n print(ans)\n else:\n print(\"RIP\")\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\n3 10 15 5 10 100\\n12 15 18\\n3 10 15 5 10 100\\n5 5 10\\n4 40 80 30 30 100\\n100 100 100 100\\n', 'output': '4\\nRIP\\n1\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/PEWDSVTS'}","problem_id":"vfc_4554","program":"```python\n# cook your dish here\nimport heapq as hq\nfrom math import floor\nfor _ in range(int(input())):\n n,a,b,x,y,z=map(int,input().split())\n arr=[-int(i) for i in input().split()]\n days=((z-b-1)//y)\n ans=0\n hq.heapify(arr)\n curr=a+days*x\n while curr=z:\n print(ans)\n else:\n print(\"RIP\")\n```","inputs":"3\n3 10 15 5 10 100\n12 15 18\n3 10 15 5 10 100\n5 5 10\n4 40 80 30 30 100\n100 100 100 100\n","output":"4\nRIP\n1\n","actual_output":"4\nRIP\n1\n","execution_success":true,"sample_index":1017},{"source":"apps","task_type":"verifiable_code","in_source_id":"1430","prompt":"Solve the following coding problem using the programming language python:\n\nChef wants you to distribute candies among $N$ kids who are sitting in a circle. However, he wants to make some kids jealous of others. Thus, he wants you to distribute candies in such a way that there is a difference of at least $K$ candies between two adjacent kids. \nGiven the value of $N$ and $K$, you need to find the minimum number of candies you need to satisfy the given conditions, such that, each kid gets at least one candy.\n\n-----Input:-----\n- First line will contain $T$, the number of testcases. Then the testcases follow. \n- The only line of each testcase contains two space-separated integers $N$ and $K$. \n\n-----Output:-----\nFor each test case, print a single line containing one integer \u2015 the number of candies you need.\n\n-----Constraints-----\n- $1 \\leq T \\leq 10^6$\n- $2 \\leq N \\leq 10^3$\n- $0 \\leq K \\leq 10^4$ \n\n-----Sample Input:-----\n1 \n2 1\n\n-----Sample Output:-----\n3\n\n-----EXPLANATION:-----\nThe minimum number of candies required is $3$. One kid needs to have $1$ candy and the other needs to have $2$ candy to have a difference of $1$ candy between them.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\nfor _ in range(int(input())):\n n,k = [int(v) for v in input().split()]\n ans = (n//2)*(k+2)\n if n%2 == 0:\n ans = ans\n else:\n ans += 1 + 2*k\n \n print(ans)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n2 1\\n', 'output': '3\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/AGPR2020/problems/ALPR2000'}","problem_id":"vfc_4562","program":"```python\n# cook your dish here\nfor _ in range(int(input())):\n n,k = [int(v) for v in input().split()]\n ans = (n//2)*(k+2)\n if n%2 == 0:\n ans = ans\n else:\n ans += 1 + 2*k\n \n print(ans)\n```","inputs":"1\n2 1\n","output":"3\n","actual_output":"3\n","execution_success":true,"sample_index":1019},{"source":"apps","task_type":"verifiable_code","in_source_id":"1431","prompt":"Solve the following coding problem using the programming language python:\n\nAfter the hundred years of war started by the Fire Nation, its time for the Water Tribes to bring it to an end. Avatar asked Sokka to go to the Southern WarZone from The Northern WarZone and gave him some money in a bag for his journey. Sokka has the World Map to guide him during his journey . The World Map is described as a $N$x$N$ grid where the Northern WarZone is denoted by $(0,0)$ and the Southern WarZone is denoted by $(N-1,N-1)$. Each location on the world map is denoted in a similar way by two integers r and c. For each location having: \n- $r = c$ denotes neutral land ( $(0,0)$ and $(N-1,N-1)$ also come under this category) \n- $r < c$ denotes the land under the rule of Water Tribes \n- $r > c$ denotes the land under the rule of Fire Kingdom \nBeing wise Sokka travels only from one location to any other valid location (by valid location we mean a location which exists on the world map grid i.e. for that location $0 \\leq r < N$ and $0 \\leq c < N$ ) just to the right $(r,c+1)$ or below $(r+1,c)$ the current location randomly. Due to the times of war , Sokka has to pay one coin each time he transitions from one nation to another. Here a transition is counted when Sokka is in Water Tribe land and moves to Fire Nation Land crossing the neutral land or vice versa .The first move is obviously never counted as a transition. Moreover , the coin is to be payed exactly once for one such transition (eg. if he makes this transition k times he has to pay k coins). \nThe initial number of coins Sokka has is $2*N$. The probability that the coins he has when he reaches his destination is lesser than the number of coins he started his journey with can be expressed as a fraction $P/Q$, where P and Q are integers $(P \\geq 0, Q > 0)$ and Q is co-prime with $(10^9)+7$. You should compute $P/Q$ modulo $(10^9)+7$ for $T$ values of $N$.\n\n-----Input:-----\n- First line will contain $T$, number of testcases. Then the testcases follow. \n- Each testcase contains of a single line of input, one integer $N$, the size of the world map grid. \n\n-----Output:-----\nFor each testcase, output in a single line , the Probability modulo (10^9)+7.\n\n-----Constraints-----\n- $1 \\leq T \\leq 100000$\n- $2 \\leq N \\leq 10^9$\n\n-----Sample Input:-----\n2 \n\n5\n\n2 \n\n-----Sample Output:-----\n200000002 \n\n0 \n\n-----EXPLANATION:-----\nFor N=2, there is no possible path in which Sokka has to spend money, so the final number of coins in the bag is not lesser than the initial amount.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nm=1000000007\r\ndef gcd(a, b): \r\n if (a == 0): \r\n return b \r\n return gcd(b % a, a)\r\ndef modexp(x, n): \r\n if (n == 0) : \r\n return 1\r\n elif (n % 2 == 0) : \r\n return modexp((x * x) % m, n // 2) \r\n else : \r\n return (x * modexp((x * x) % m, \r\n (n - 1) / 2) % m)\r\ndef getFractionModulo(a, b): \r\n c = gcd(a, b)\r\n a = a // c \r\n b = b // c \r\n d = modexp(b, m - 2) \r\n ans = ((a % m) * (d % m)) % m\r\n return ans\r\nt=int(input())\r\nfor i in range(t):\r\n n=int(input())\r\n n=n-1\r\n print(getFractionModulo(n-1,n+1))\r\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n5\\n2\\n', 'output': '200000002\\n0\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/COW42020/problems/COW3F'}","problem_id":"vfc_4566","program":"```python\nm=1000000007\r\ndef gcd(a, b): \r\n if (a == 0): \r\n return b \r\n return gcd(b % a, a)\r\ndef modexp(x, n): \r\n if (n == 0) : \r\n return 1\r\n elif (n % 2 == 0) : \r\n return modexp((x * x) % m, n // 2) \r\n else : \r\n return (x * modexp((x * x) % m, \r\n (n - 1) / 2) % m)\r\ndef getFractionModulo(a, b): \r\n c = gcd(a, b)\r\n a = a // c \r\n b = b // c \r\n d = modexp(b, m - 2) \r\n ans = ((a % m) * (d % m)) % m\r\n return ans\r\nt=int(input())\r\nfor i in range(t):\r\n n=int(input())\r\n n=n-1\r\n print(getFractionModulo(n-1,n+1))\r\n\n```","inputs":"2\n5\n2\n","output":"200000002\n0\n","actual_output":"200000002\n0\n","execution_success":true,"sample_index":1020},{"source":"apps","task_type":"verifiable_code","in_source_id":"1432","prompt":"Solve the following coding problem using the programming language python:\n\nBandwidth of a matrix A is defined as the smallest non-negative integer K such that A(i, j) = 0 for |i - j| > K.\nFor example, a matrix with all zeros will have its bandwith equal to zero. Similarly bandwith of diagonal matrix will also be zero.\n\nFor example, for the below given matrix, the bandwith of this matrix is 2.\n\n1 0 0\n0 1 1\n1 1 0 \n\nBandwidth of the below matrix is 1. \n\nBandwidth of the below matrix is 2. \n\nBandwidth of the below matrix is also 2. \n\nYou will be a given a binary matrix A of dimensions N \u00d7 N. You are allowed to make following operation as many times as you wish (possibly zero or more). In a single operation, you can swap any two entries of the matrix. Your aim is to minimize the bandwidth of the matrix. Find the minimum bandwidth of the matrix A you can get after making as many operations of above type as you want.\n\n-----Input-----\nThe first line of the input contains an integer T denoting the number of test cases. The description of T test cases follow.\nFirst line of each test case contains an integer N denoting the height/width of the matrix.\nNext N lines of each test case contain N space separated binary integers (either zero or one) corresponding to the entries of the matrix.\n\n-----Output-----\nFor each test case, output a single integer corresponding to the minimum bandwidth that you can obtain.\n\n-----Constraints-----\n- 1 \u2264 T \u2264 10\n- 1 \u2264 N \u2264 500\n- 0 \u2264 A(i, j) \u2264 1\n\n-----Subtasks-----\n- Subtask #1 (40 points) : 1 \u2264 N \u2264 100\n- Subtask #2 (60 points) : original constraints\n\n-----Example-----\nInput:\n6\n2\n0 0\n0 0\n2\n1 0\n0 1\n2\n1 0\n1 0\n2\n1 0\n1 1\n3\n1 0 0\n0 1 1\n1 1 0\n4\n1 1 1 1\n1 1 1 1\n1 1 1 1\n1 1 1 1\n\nOutput:\n0\n0\n0\n1\n1\n3\n\n-----Explanation-----\nExample case 1. The bandwidth of a matrix will all zero entries will be zero. This is the minimum bandwidth you can get, so there is no need of performing any swap operation.\nExample case 2. The bandwidth of a diagonal matrix will also be zero.\nExample case 3. You can make the given matrix a diagonal matrix by swapping A(2, 1) and A(2, 2), which will have zero bandwidth.\nExample case 4. You can not make swaps in any way that can reduce the bandwidth of this matrix. Bandwidth of this matrix is equal to 1, which is the minimum bandwidth that you can get.\nExample case 5. Bandwidth of the given matrix is 2. You can make it equal to be 1 by swapping A(3, 1) and A(3, 3), i.e. the matrix after the operation will look like\n\n1 0 0\n0 1 1\n0 1 1\n\nThe bandwidth of this matrix is 1.\n\nExample case 6. The swap operations won't have any effect on the matrix. Its bandwidth is equal to 3.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nt = int(input())\r\nfor i in range(t):\r\n n = int(input())\r\n A = []\r\n for i in range(0, n):\r\n A.append([int(i) for i in input().split()])\r\n ones = sum([sum(i) for i in A])\r\n compare = n\r\n ans = 0\r\n for i in range(0, n):\r\n if ones <= compare:\r\n ans = i\r\n break\r\n compare += 2*(n-1-i)\r\n print(ans)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '6\\n2\\n0 0\\n0 0\\n2\\n1 0\\n0 1\\n2\\n1 0\\n1 0\\n2\\n1 0\\n1 1\\n3\\n1 0 0\\n0 1 1\\n1 1 0\\n4\\n1 1 1 1\\n1 1 1 1\\n1 1 1 1\\n1 1 1 1\\n\\n\\n', 'output': '0\\n0\\n0\\n1\\n1\\n3\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/BANDMATR'}","problem_id":"vfc_4570","program":"```python\nt = int(input())\r\nfor i in range(t):\r\n n = int(input())\r\n A = []\r\n for i in range(0, n):\r\n A.append([int(i) for i in input().split()])\r\n ones = sum([sum(i) for i in A])\r\n compare = n\r\n ans = 0\r\n for i in range(0, n):\r\n if ones <= compare:\r\n ans = i\r\n break\r\n compare += 2*(n-1-i)\r\n print(ans)\n```","inputs":"6\n2\n0 0\n0 0\n2\n1 0\n0 1\n2\n1 0\n1 0\n2\n1 0\n1 1\n3\n1 0 0\n0 1 1\n1 1 0\n4\n1 1 1 1\n1 1 1 1\n1 1 1 1\n1 1 1 1\n\n\n","output":"0\n0\n0\n1\n1\n3\n","actual_output":"0\n0\n0\n1\n1\n3\n","execution_success":true,"sample_index":1021},{"source":"apps","task_type":"verifiable_code","in_source_id":"1433","prompt":"Solve the following coding problem using the programming language python:\n\nThe Little Elephant loves lucky strings. Everybody knows that the lucky string is a string of digits that contains only the lucky digits 4 and 7. For example, strings \"47\", \"744\", \"4\" are lucky while \"5\", \"17\", \"467\" are not.\n\nThe Little Elephant has the strings A and B of digits. These strings are of equal lengths, that is |A| = |B|. He wants to get some lucky string from them. For this he performs the following operations. At first he arbitrary reorders digits of A. Then he arbitrary reorders digits of B. After that he creates the string C such that its i-th digit is the maximum between the i-th digit of A and the i-th digit of B. In other words, C[i] = max{A[i], B[i]} for i from 1 to |A|. After that he removes from C all non-lucky digits saving the order of the remaining (lucky) digits. So C now becomes a lucky string. For example, if after reordering A = \"754\" and B = \"873\", then C is at first \"874\" and then it becomes \"74\".\n\nThe Little Elephant wants the resulting string to be as lucky as possible. The formal definition of this is that the resulting string should be the lexicographically greatest possible string among all the strings that can be obtained from the given strings A and B by the described process.\nNotes\n- |A| denotes the length of the string A.\n- A[i] denotes the i-th digit of the string A. Here we numerate the digits starting from 1. So 1 \u2264 i \u2264 |A|.\n- The string A is called lexicographically greater than the string B if either there exists some index i such that A[i] > B[i] and for each j < i we have A[j] = B[j], or B is a proper prefix of A, that is, |A| > |B| and first |B| digits of A coincide with the corresponding digits of B.\n\n-----Input-----\n\nThe first line of the input contains a single integer T, the number of test cases. T test cases follow. Each test case consists of two lines. The first line contains the string A. The second line contains the string B.\n\n-----Output-----\n\nFor each test case output a single line containing the answer for the corresponding test case. Note, that the answer can be an empty string. In this case you should print an empty line for the corresponding test case.\n\n-----Constraints-----\n1 \u2264 T \u2264 10000\n1 \u2264 |A| \u2264 20000\n\n|A| = |B|\n\nEach character of A and B is a digit.\n\nSum of |A| across all the tests in the input does not exceed 200000.\n\n-----Example-----\nInput:\n4\n4\n7\n435\n479\n7\n8\n1675475\n9756417\n\nOutput:\n7\n74\n\n777744\n\n-----Explanation-----\nCase 1. In this case the only possible string C we can get is \"7\" and it is the lucky string.\n\nCase 2. If we reorder A and B as A = \"543\" and B = \"749\" the string C will be at first \"749\" and then becomes \"74\". It can be shown that this is the lexicographically greatest string for the given A and B.\n\nCase 3. In this case the only possible string C we can get is \"8\" and it becomes and empty string after removing of non-lucky digits.\n\nCase 4. If we reorder A and B as A = \"7765541\" and B = \"5697714\" the string C will be at first \"7797744\" and then becomes \"777744\". Note that we can construct any lexicographically greater string for the given A and B since we have only four \"sevens\" and two \"fours\" among digits of both strings A and B as well the constructed string \"777744\".\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n\nt = int(input())\n\nfor i in range(0,t):\n\ta = input()\n\tb = input()\n\t\n\tagts=bgts=afour=bfour=aseven=bseven=altf=bltf=afts=bfts=0;\n\t\n\tfor j in a:\n\t\tif j >= '7':\n\t\t\tif j > '7':\n\t\t\t\tagts += 1\n\t\t\telse:\n\t\t\t\taseven += 1\n\t\telif j >= '4':\n\t\t\tif j > '4':\n\t\t\t\tafts += 1\n\t\t\telse:\n\t\t\t\tafour += 1\n\t\telse:\n\t\t\taltf += 1\n\t\n\tfor j in b:\n\t\tif j >= '7':\n\t\t\tif j > '7':\n\t\t\t\tbgts += 1\n\t\t\telse:\n\t\t\t\tbseven += 1\n\t\telif j >= '4':\n\t\t\tif j > '4':\n\t\t\t\tbfts += 1\n\t\t\telse:\n\t\t\t\tbfour += 1\n\t\telse:\n\t\t\tbltf += 1\n\t\t\n\tnseven = 0\n\tnfour = 0\n\t\n\tif aseven > bfts:\n\t\taseven -= bfts;\n\t\tnseven += bfts;\n\t\tbfts = 0;\n\telse:\n\t\tbfts -= aseven;\n\t\tnseven += aseven;\n\t\taseven = 0;\n\t\n\tif bseven > afts:\n\t\tbseven -= afts;\n\t\tnseven += afts;\n\t\tafts = 0;\n\telse:\n\t\tafts -= bseven;\n\t\tnseven += bseven;\n\t\tbseven = 0;\n\t\n\tif aseven > bltf:\n\t\taseven -= bltf;\n\t\tnseven += bltf;\n\t\tbltf = 0;\n\telse:\n\t\tbltf -= aseven;\n\t\tnseven += aseven;\n\t\taseven = 0;\n\t\n\tif bseven > altf:\n\t\tbseven -= altf;\n\t\tnseven += altf;\n\t\taltf = 0;\n\telse:\n\t\taltf -= bseven;\n\t\tnseven += bseven;\n\t\tbseven = 0;\n\t\n\tif aseven > bfour:\n\t\taseven -= bfour;\n\t\tnseven += bfour;\n\t\tbfour = 0;\n\telse:\n\t\tbfour -= aseven;\n\t\tnseven += aseven;\n\t\taseven = 0;\n\t\n\tif bseven > afour:\n\t\tbseven -= afour;\n\t\tnseven += afour;\n\t\tafour = 0;\n\telse:\n\t\tafour -= bseven;\n\t\tnseven += bseven;\n\t\tbseven = 0;\n\t\n\tnseven += min(aseven,bseven)\n\t\n\tif afour > bltf:\n\t\tafour -= bltf;\n\t\tnfour += bltf;\n\t\tbltf = 0\n\telse:\n\t\tbltf -= afour;\n\t\tnfour += afour;\n\t\tafour = 0;\n\t\n\tif bfour > altf:\n\t\tbfour -= altf;\n\t\tnfour += altf;\n\t\taltf = 0\n\telse:\n\t\taltf -= bfour;\n\t\tnfour += bfour;\n\t\tbfour = 0;\n\t\n\tnfour += min(afour,bfour)\n\t\n\tprint('7'*nseven + '4'*nfour)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '4\\n4\\n7\\n435\\n479\\n7\\n8\\n1675475\\n9756417\\n\\n\\n', 'output': '7\\n74\\n\\n777744\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/OCT12/problems/LUCKY10'}","problem_id":"vfc_4574","program":"```python\n\nt = int(input())\n\nfor i in range(0,t):\n\ta = input()\n\tb = input()\n\t\n\tagts=bgts=afour=bfour=aseven=bseven=altf=bltf=afts=bfts=0;\n\t\n\tfor j in a:\n\t\tif j >= '7':\n\t\t\tif j > '7':\n\t\t\t\tagts += 1\n\t\t\telse:\n\t\t\t\taseven += 1\n\t\telif j >= '4':\n\t\t\tif j > '4':\n\t\t\t\tafts += 1\n\t\t\telse:\n\t\t\t\tafour += 1\n\t\telse:\n\t\t\taltf += 1\n\t\n\tfor j in b:\n\t\tif j >= '7':\n\t\t\tif j > '7':\n\t\t\t\tbgts += 1\n\t\t\telse:\n\t\t\t\tbseven += 1\n\t\telif j >= '4':\n\t\t\tif j > '4':\n\t\t\t\tbfts += 1\n\t\t\telse:\n\t\t\t\tbfour += 1\n\t\telse:\n\t\t\tbltf += 1\n\t\t\n\tnseven = 0\n\tnfour = 0\n\t\n\tif aseven > bfts:\n\t\taseven -= bfts;\n\t\tnseven += bfts;\n\t\tbfts = 0;\n\telse:\n\t\tbfts -= aseven;\n\t\tnseven += aseven;\n\t\taseven = 0;\n\t\n\tif bseven > afts:\n\t\tbseven -= afts;\n\t\tnseven += afts;\n\t\tafts = 0;\n\telse:\n\t\tafts -= bseven;\n\t\tnseven += bseven;\n\t\tbseven = 0;\n\t\n\tif aseven > bltf:\n\t\taseven -= bltf;\n\t\tnseven += bltf;\n\t\tbltf = 0;\n\telse:\n\t\tbltf -= aseven;\n\t\tnseven += aseven;\n\t\taseven = 0;\n\t\n\tif bseven > altf:\n\t\tbseven -= altf;\n\t\tnseven += altf;\n\t\taltf = 0;\n\telse:\n\t\taltf -= bseven;\n\t\tnseven += bseven;\n\t\tbseven = 0;\n\t\n\tif aseven > bfour:\n\t\taseven -= bfour;\n\t\tnseven += bfour;\n\t\tbfour = 0;\n\telse:\n\t\tbfour -= aseven;\n\t\tnseven += aseven;\n\t\taseven = 0;\n\t\n\tif bseven > afour:\n\t\tbseven -= afour;\n\t\tnseven += afour;\n\t\tafour = 0;\n\telse:\n\t\tafour -= bseven;\n\t\tnseven += bseven;\n\t\tbseven = 0;\n\t\n\tnseven += min(aseven,bseven)\n\t\n\tif afour > bltf:\n\t\tafour -= bltf;\n\t\tnfour += bltf;\n\t\tbltf = 0\n\telse:\n\t\tbltf -= afour;\n\t\tnfour += afour;\n\t\tafour = 0;\n\t\n\tif bfour > altf:\n\t\tbfour -= altf;\n\t\tnfour += altf;\n\t\taltf = 0\n\telse:\n\t\taltf -= bfour;\n\t\tnfour += bfour;\n\t\tbfour = 0;\n\t\n\tnfour += min(afour,bfour)\n\t\n\tprint('7'*nseven + '4'*nfour)\n```","inputs":"4\n4\n7\n435\n479\n7\n8\n1675475\n9756417\n\n\n","output":"7\n74\n\n777744\n","actual_output":"7\n74\n\n777744\n","execution_success":true,"sample_index":1022},{"source":"apps","task_type":"verifiable_code","in_source_id":"1434","prompt":"Solve the following coding problem using the programming language python:\n\nThere's a tree and every one of its nodes has a cost associated with it. Some of these nodes are labelled special nodes. You are supposed to answer a few queries on this tree. In each query, a source and destination node (SNODE$SNODE$ and DNODE$DNODE$) is given along with a value W$W$. For a walk between SNODE$SNODE$ and DNODE$DNODE$ to be valid you have to choose a special node and call it the pivot P$P$. Now the path will be SNODE$SNODE$ ->P$ P$ -> DNODE$DNODE$. For any valid path, there is a path value (PV$PV$) attached to it. It is defined as follows:\nSelect a subset of nodes(can be empty) in the path from SNODE$SNODE$ to P$P$ (both inclusive) such that sum of their costs (CTOT1$CTOT_{1}$) doesn't exceed W$W$.\nSelect a subset of nodes(can be empty) in the path from P$P$ to DNODE$DNODE$ (both inclusive) such that sum of their costs (CTOT2$CTOT_{2}$) doesn't exceed W$W$.\nNow define PV=CTOT1+CTOT2$PV = CTOT_{1} + CTOT_{2}$ such that the absolute difference x=|CTOT1\u2212CTOT2|$x = |CTOT_{1} - CTOT_{2}|$ is as low as possible. If there are multiple pairs of subsets that give the same minimum absolute difference, the pair of subsets which maximize PV$PV$ should be chosen.\nFor each query, output the path value PV$PV$ minimizing x$x$ as defined above. \nNote that the sum of costs of an empty subset is zero.\n\n-----Input-----\n- First line contains three integers N$N$ - number of vertices in the tree, NSP$NSP$ - number of special nodes in the tree and Q$Q$ - number of queries to answer. \n- Second line contains N\u22121$N-1$ integers. If the i$i$th integer is Vi$V_i$ then there is an undirected edge between i+1$i + 1$ and Vi$V_i$ (i$i$ starts from 1$1$ and goes till N\u22121$N-1$). \n- Third line contains N$N$ integers, the i$i$th integer represents cost of the i$i$th vertex. \n- Fourth line contains NSP$NSP$ integers - these represent which nodes are the special nodes. \n- Following Q$Q$ lines contains three integers each - SNODE$SNODE$, DNODE$DNODE$ and W$W$ for each query.\n\n-----Output-----\nFor each query output a single line containing a single integer - the path value PV$PV$ between SNODE$SNODE$ and DNODE$DNODE$.\n\n-----Constraints:-----\n- 1\u2264$1 \\leq $ Number of nodes \u22641000$ \\leq 1000 $ \n- 0\u2264W\u22641000$ 0 \\leq W \\leq 1000 $ \n- 1\u2264$ 1 \\leq $ Number of special nodes \u226410$ \\leq 10 $ \n- 0\u2264$ 0 \\leq $ Cost of each node \u22641000$ \\leq 1000 $ \n- 1\u2264$ 1 \\leq $ Number of queries \u22641000$ \\leq 1000 $\n\n-----Sample Input-----\n7 1 5\n\n1 1 2 2 3 3\n\n3 5 4 2 7 9 1\n\n1\n\n2 3 100\n\n1 1 100\n\n2 1 100\n\n4 5 100\n\n4 7 100 \n\n-----Sample Output:-----\n6\n\n6\n\n6\n\n20\n\n16 \n\n-----Explanation:-----\nConsider query 4$4$. The only path is 4\u2212>2\u2212>1\u2212>2\u2212>5$4->2->1->2->5$. The two sets defined for this path are {3,2,5${3,2,5}$} and {3,5,7${3,5,7}$}. Pick subsets {3,2,5${3,2,5}$} and {3,7${3,7}$} from each set which minimizes PV$PV$. Note that node 2$2$ can repeat as it is in different paths (both to and from the pivot).\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\n# cook your dish here\nimport numpy as np\nn, s, q = [int(j) for j in input().split()]\nedges = [int(j)-1 for j in input().split()]\ncosts = [int(j) for j in input().split()]\nspecial = [int(j)-1 for j in input().split()]\nqueries = [[0] * 3 for _ in range(q)]\nfor i in range(q):\n queries[i] = [int(j)-1 for j in input().split()]\n\nedge_set = [[] for _ in range(n)]\nfor i in range(n-1):\n edge_set[i+1].append(edges[i])\n edge_set[edges[i]].append(i+1)\n\nstored = np.zeros((s,n,1001),dtype=bool)\nvisited = [[] for _ in range(s)]\nfor i in range(s):\n s_vertex = special[i]\n s_cost = costs[s_vertex]\n s_visited = visited[i]\n s_visited.append(s_vertex)\n s_stored = stored[i]\n s_stored[s_vertex][0] = True\n s_stored[s_vertex][s_cost] = True\n for edge in edge_set[s_vertex]:\n s_visited.append(edge)\n s_stored[edge] = np.array(s_stored[s_vertex])\n for j in range(1,n):\n vertex = s_visited[j]\n cost = costs[vertex]\n s_stored[vertex][cost:1001] = np.logical_or(s_stored[vertex][0:1001-cost],s_stored[vertex][cost:1001])\n for edge in edge_set[vertex]:\n if edge not in s_visited:\n s_visited.append(edge)\n s_stored[edge] = np.array(s_stored[vertex])\n\nfor i in range(q):\n first, second, max_cost = queries[i]\n bool_array = np.zeros(max_cost+2,dtype=bool)\n for j in range(s):\n bool_array = np.logical_or(bool_array,np.logical_and(stored[j][first][:max_cost+2],stored[j][second][:max_cost+2]))\n for j in range(max_cost+1,-1,-1):\n if bool_array[j]:\n print(2 * j)\n break\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '7 1 5\\n1 1 2 2 3 3\\n3 5 4 2 7 9 1\\n1\\n2 3 100\\n1 1 100\\n2 1 100\\n4 5 100\\n4 7 100\\n', 'output': '6\\n6\\n6\\n20\\n16\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/DEMTREE'}","problem_id":"vfc_4578","program":"```python\n# cook your dish here\n# cook your dish here\nimport numpy as np\nn, s, q = [int(j) for j in input().split()]\nedges = [int(j)-1 for j in input().split()]\ncosts = [int(j) for j in input().split()]\nspecial = [int(j)-1 for j in input().split()]\nqueries = [[0] * 3 for _ in range(q)]\nfor i in range(q):\n queries[i] = [int(j)-1 for j in input().split()]\n\nedge_set = [[] for _ in range(n)]\nfor i in range(n-1):\n edge_set[i+1].append(edges[i])\n edge_set[edges[i]].append(i+1)\n\nstored = np.zeros((s,n,1001),dtype=bool)\nvisited = [[] for _ in range(s)]\nfor i in range(s):\n s_vertex = special[i]\n s_cost = costs[s_vertex]\n s_visited = visited[i]\n s_visited.append(s_vertex)\n s_stored = stored[i]\n s_stored[s_vertex][0] = True\n s_stored[s_vertex][s_cost] = True\n for edge in edge_set[s_vertex]:\n s_visited.append(edge)\n s_stored[edge] = np.array(s_stored[s_vertex])\n for j in range(1,n):\n vertex = s_visited[j]\n cost = costs[vertex]\n s_stored[vertex][cost:1001] = np.logical_or(s_stored[vertex][0:1001-cost],s_stored[vertex][cost:1001])\n for edge in edge_set[vertex]:\n if edge not in s_visited:\n s_visited.append(edge)\n s_stored[edge] = np.array(s_stored[vertex])\n\nfor i in range(q):\n first, second, max_cost = queries[i]\n bool_array = np.zeros(max_cost+2,dtype=bool)\n for j in range(s):\n bool_array = np.logical_or(bool_array,np.logical_and(stored[j][first][:max_cost+2],stored[j][second][:max_cost+2]))\n for j in range(max_cost+1,-1,-1):\n if bool_array[j]:\n print(2 * j)\n break\n```","inputs":"7 1 5\n1 1 2 2 3 3\n3 5 4 2 7 9 1\n1\n2 3 100\n1 1 100\n2 1 100\n4 5 100\n4 7 100\n","output":"6\n6\n6\n20\n16\n","actual_output":"6\n6\n6\n20\n16\n","execution_success":true,"sample_index":1023},{"source":"apps","task_type":"verifiable_code","in_source_id":"1435","prompt":"Solve the following coding problem using the programming language python:\n\nIndraneel's student has given him data from two sets of experiments that the student has performed. Indraneel wants to establish a correlation between the two sets of data. Each data set is a sequence of $N$ numbers. The two data sets do not match number for number, but Indraneel believes that this is because data has been shifted due to inexact tuning of the equipment.\nFor example, consider the following two sequences:\n$ $\n3 8 4 23 9 11 28\n2 3 22 26 8 16 12\n\n$ $\nIndraneel observes that if we consider the subsequences $3,4,23,9$ and $2,3,22,8$ and examine their successive differences we get $1,19,-14$. He considers these two subsequences to be \"identical\". He would like to find the longest such pair of subsequences so that the successive differences are identical. Your task is to help him do this.\n\n-----Input:-----\nThe first line of the input will contain a single integer $N$ indicating the number of data points in each of Indraneel's student's data sets. This is followed by two lines, each containing $N$ integers.\n\n-----Output:-----\nThe output consists of three lines. The first line of output contains a single integer indicating the length of the longest pair of subsequences (one from each sequence) that has identical successive differences. This is followed by two lines each containing the corresponding subsequences. If there is more than one answer, it suffices to print one.\n\n-----Constraints:-----\n- $1 \\leq N \\leq 150$.\n- $0 \\leq$ Each data point $\\leq 1000$\n\n-----Sample Input-----\n7\n3 8 4 23 9 11 28 \n2 3 22 26 8 16 12 \n\n-----Sample Output-----\n4\n3 4 23 9\n2 3 22 8\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nimport copy\r\nn=int(input())\r\na=[int(x) for x in input().split()]\r\nb=[int(x) for x in input().split()]\r\nc=[]\r\nd=[]\r\nlcs=[]\r\ndef lcsfn(a,c,corda,cordb):\r\n\tfor i in range(n+1):\r\n\t\td.append([0]*(n+1))\r\n\t\tlcs.append([0]*(n+1))\r\n\tfor i in range(1,n+1):\r\n\t\tfor j in range(1,n+1):\r\n\t\t\tif a[i-1]==c[j-1]:\r\n\t\t\t\tlcs[i][j]=lcs[i-1][j-1]+1\r\n\t\t\t\td[i][j]='d'\r\n\t\t\telif lcs[i-1][j]>lcs[i][j-1]:\r\n\t\t\t\tlcs[i][j]=lcs[i-1][j]\r\n\t\t\t\td[i][j]='u'\r\n\t\t\telse:\r\n\t\t\t\tlcs[i][j]=lcs[i][j-1]\r\n\t\t\t\td[i][j]='l'\r\n\ti=n\r\n\tj=n\r\n\tcost=0\r\n\twhile i>=1 and j>=1:\r\n\t\tif d[i][j]=='d':\r\n\t\t\tcorda.append(a[i-1])\r\n\t\t\tcordb.append(b[j-1])\r\n\t\t\ti-=1\r\n\t\t\tj-=1\r\n\t\t\tcost+=1\r\n\t\telif d[i][j]=='l':\r\n\t\t\tj-=1\r\n\t\telif d[i][j]=='u':\r\n\t\t\ti-=1\r\n\treturn cost\r\n\r\n\r\nma=-10**9\r\np1=[]\r\np2=[]\r\nfor i in range(-1000,1001):\r\n\tc=[]\r\n\tcorda=[]\r\n\tcordb=[]\r\n\tfor j in range(n):\r\n\t\tc.append(b[j]+i)\r\n\tp=lcsfn(a,c,corda,cordb)\r\n\tif malcs[i][j-1]:\r\n\t\t\t\tlcs[i][j]=lcs[i-1][j]\r\n\t\t\t\td[i][j]='u'\r\n\t\t\telse:\r\n\t\t\t\tlcs[i][j]=lcs[i][j-1]\r\n\t\t\t\td[i][j]='l'\r\n\ti=n\r\n\tj=n\r\n\tcost=0\r\n\twhile i>=1 and j>=1:\r\n\t\tif d[i][j]=='d':\r\n\t\t\tcorda.append(a[i-1])\r\n\t\t\tcordb.append(b[j-1])\r\n\t\t\ti-=1\r\n\t\t\tj-=1\r\n\t\t\tcost+=1\r\n\t\telif d[i][j]=='l':\r\n\t\t\tj-=1\r\n\t\telif d[i][j]=='u':\r\n\t\t\ti-=1\r\n\treturn cost\r\n\r\n\r\nma=-10**9\r\np1=[]\r\np2=[]\r\nfor i in range(-1000,1001):\r\n\tc=[]\r\n\tcorda=[]\r\n\tcordb=[]\r\n\tfor j in range(n):\r\n\t\tc.append(b[j]+i)\r\n\tp=lcsfn(a,c,corda,cordb)\r\n\tif ma 1:\n factors.add(n)\n return factors\nfor _ in range(int(input())):\n n=int(input())\n a=list(map(int,input().split()))\n ans=0\n s=[]\n for i in range(n):\n s.append(sum(prime_factors(a[i])))\n for i in range(n):\n for j in range(n):\n if i!=j and a[j]%a[i]==0 and s[j]%s[i]==0:\n ans=ans+1\n print(ans)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n5\\n2 30 2 4 3\\n', 'output': '6\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/PRMDIV'}","problem_id":"vfc_4594","program":"```python\n# cook your dish here\ndef prime_factors(n):\n i = 2\n factors =set()\n while i * i <= n:\n if n % i:\n i += 1\n else:\n n //= i\n factors.add(i)\n if n > 1:\n factors.add(n)\n return factors\nfor _ in range(int(input())):\n n=int(input())\n a=list(map(int,input().split()))\n ans=0\n s=[]\n for i in range(n):\n s.append(sum(prime_factors(a[i])))\n for i in range(n):\n for j in range(n):\n if i!=j and a[j]%a[i]==0 and s[j]%s[i]==0:\n ans=ans+1\n print(ans)\n```","inputs":"1\n5\n2 30 2 4 3\n","output":"6\n","actual_output":"6\n","execution_success":true,"sample_index":1027},{"source":"apps","task_type":"verifiable_code","in_source_id":"1440","prompt":"Solve the following coding problem using the programming language python:\n\nYou are given an array $A$ of $N$ positive and pairwise distinct integers. \nYou can permute the elements in any way you want. \nThe cost of an ordering $(A_1, A_2, \\ldots, A_N)$ is defined as $ (((A_1 \\bmod A_2) \\bmod A_3)......) \\bmod A_N$ where $X \\bmod Y$ means the remainder when $X$ is divided by $Y$. \nYou need to find the maximum cost which can be attained through any possible ordering of the elements.\n\n-----Input:-----\n- The first line contains $T$ denoting the number of test cases.\n- The first line of each testcase contains a single integer $N$. \n- The second line of each testcase contains $N$ space-separated integers, the elements of $A$. \n\n-----Output:-----\n- For each testcase, output the maximum possible cost in a new line. \n\n-----Constraints-----\n- $1 \\leq T \\leq 5*10^5$\n- $2 \\leq N \\leq 5*10^5$\n- $1 \\leq A_i \\leq 10^9$\n- Sum of $N$ over all testcases is less than or equal to $10^6$\n- All elements in a single testcase are distinct.\n\n-----Subtasks-----\n- 100 points : Original constraints.\n\n-----Sample Input:-----\n1\n2\n7 12\n\n-----Sample Output:-----\n7\n\n-----Explanation:-----\nThe two possible ways to order the elements are [7, 12] and [12, 7]. In the first case, the cost is $7 \\bmod 12 = 7$ and in the second case the cost is $12 \\bmod 7 = 5$. Clearly the answer is 7.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\nt=int(input())\nfor i in range(t):\n n=int(input())\n a=list(map(int,input().split()))\n print(min(a))\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n2\\n7 12\\n', 'output': '7\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/EXUNA'}","problem_id":"vfc_4602","program":"```python\n# cook your dish here\nt=int(input())\nfor i in range(t):\n n=int(input())\n a=list(map(int,input().split()))\n print(min(a))\n```","inputs":"1\n2\n7 12\n","output":"7\n","actual_output":"7\n","execution_success":true,"sample_index":1029},{"source":"apps","task_type":"verifiable_code","in_source_id":"1441","prompt":"Solve the following coding problem using the programming language python:\n\nChef is again playing a game with his best friend Garry. As usual, the rules of this game are extremely strange and uncommon.\nFirst, they are given a stack of $N$ discs. Each disc has a distinct, non-negative integer written on it. The players exchange turns to make a move. Before the start of the game, they both agree upon a set of positive integers $S$ of size $K$. It is guaranteed that S contains the integer $1$. In a move, a player can select any value $x$ from $S$ and pop exactly $x$ elements from the top of the stack. The game ends when there are no discs remaining. Chef goes first.\nScoring: For every disc a player pops, his score increases by $2^p$ where $p$ is the integer written on the disc. For example, if a player pops the discs, with integers $p_1, p_2, p_3, \\dots, p_m$ written on it, during the entire course of the game, then his total score will be $2^{p_1} + 2^{p_2} + 2^{p_3} + \\dots + 2^{p_m}$.\nThe player with higher score wins the game. Determine the winner if both the players play optimally, or if the game ends in a draw.\n\n-----Input:-----\n- First line contains $T$, the number of testcases. Then the testcases follow.\n- The first line of each test case contains two space separated integers $N$ and $K$, denoting the size of the stack and the set S respectively.\n- Next line contains $N$ space separated integers $A_i$ where $A_1$ is the topmost element, denoting the initial arrangement of the stack.\n- The last line of each test case contains $K$ space separated integers each denoting $x_i$.\n\n-----Output:-----\nFor each testcase, output \"Chef\" (without quotes) if Chef wins, \"Garry\" (without quotes) if Garry wins, otherwise \"Draw\" (without quotes) in a separate line.\n\n-----Constraints-----\n- $1 \\leq T \\leq 1000$\n- $1 \\leq N \\leq 10^5$\n- $1 \\leq K \\leq \\min(100, N)$\n- $0 \\leq A_i \\leq 10^9$\n- $1 \\leq x_i \\leq N$\n- $x_i \\neq x_j$ for all $i \\neq j$\n- $A_i \\neq A_j$ for all $i \\neq j$\n- Set $S$ contains integer $1$. \n- Sum of $N$ over all test cases does not exceed $10^5$.\n\n-----Sample Input:-----\n1\n3 2\n5 7 1\n1 2\n\n-----Sample Output:-----\nChef\n\n-----Explanation:-----\nChef can select 2 from the set and draw the top two discs (with integers 5 and 7 written on it) from the stack. Garry cannot select 2 from the set as there is only 1 disc left in the stack. However, he can select 1 from the set and pop the last disc.\nSo, Chef's score = $2^5$ + $2^7$ = $160$\n\nGarry's score = $2^1$ = $2$\n\nChef wins.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfor _ in range(int(input())):\n n, k = map(int, input().split())\n a = list(map(int, input().split()))\n b = list(map(int, input().split()))\n\n a = [-1] + a[::-1]\n mx = a.index(max(a))\n dp = [0] * (n + 1)\n for i in range(1, n + 1):\n for x in b:\n if i - x < 0: continue\n if i - x < mx <= i:\n dp[i] = 1\n else:\n dp[i] |= not dp[i - x]\n\n print('Chef' if dp[-1] else 'Garry')\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n3 2\\n5 7 1\\n1 2\\n', 'output': 'Chef\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/CLGAME'}","problem_id":"vfc_4606","program":"```python\nfor _ in range(int(input())):\n n, k = map(int, input().split())\n a = list(map(int, input().split()))\n b = list(map(int, input().split()))\n\n a = [-1] + a[::-1]\n mx = a.index(max(a))\n dp = [0] * (n + 1)\n for i in range(1, n + 1):\n for x in b:\n if i - x < 0: continue\n if i - x < mx <= i:\n dp[i] = 1\n else:\n dp[i] |= not dp[i - x]\n\n print('Chef' if dp[-1] else 'Garry')\n```","inputs":"1\n3 2\n5 7 1\n1 2\n","output":"Chef\n","actual_output":"Chef\n","execution_success":true,"sample_index":1030},{"source":"apps","task_type":"verifiable_code","in_source_id":"1443","prompt":"Solve the following coding problem using the programming language python:\n\nOnce N boys and M girls attended a party. You are given a matrix A of N rows and M columns where Aij is 1 if the i-th boy likes the j-th girl, otherwise it will be 0. Note that it is not necessary that if a boy x likes girl y, then girl y should like boy x.\nYou know that if there are two different boys x and y, who both like girl z, then there will be a collision.\nCan you calculate the number of different collisions at this party? Note that order of boys in the collision doesn't matter.\n\n-----Input-----\nThe first line contains a single integer T denoting the number of test cases. Then T test cases follow.\nThe first line of each test case contains two space separated integers N, M denoting the number of boys and girls, respectively.\nEach of the following N lines contain M characters, each of them is either '0' or '1'.\n\n-----Output-----\nFor each test case output a single line containing an integer corresponding to the number of collisions at the party.\n\n-----Constraints-----\n- 1 \u2264 T \u2264 100\n- 1 \u2264 N, M \u2264 10\n\n-----Example-----\nInput:\n2\n4 3\n111\n100\n110\n000\n2 2\n10\n01\n\nOutput:\n4\n0\n\n-----Explanation-----\nExample Case 1. All three boys like the first girl, so there are (1, 2, 1), (1, 3, 1), (2, 3, 1) collisions with her. Boys 1 and 3 both like the second girl so this is one more collision. Only one boy likes the third girl, so there are no collisions with her and thus we have 4 collisions total.\nExample Case 2. For each girl there is only one boy who likes her, so there are no collisions at all.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfor i in range(int(input())):\n n,k=map(int,input().split())\n m=[]\n for j in range(n):\n l=list(input())\n m.append(l)\n a=0\n for k in range(k):\n b=0\n for p in range(n):\n if m[p][k]=='1':\n b+=1\n if b>1:\n a+=((b*(b-1))//2)\n print(a)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n4 3\\n111\\n100\\n110\\n000\\n2 2\\n10\\n01\\n', 'output': '4\\n0\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/LCOLLIS'}","problem_id":"vfc_4614","program":"```python\nfor i in range(int(input())):\n n,k=map(int,input().split())\n m=[]\n for j in range(n):\n l=list(input())\n m.append(l)\n a=0\n for k in range(k):\n b=0\n for p in range(n):\n if m[p][k]=='1':\n b+=1\n if b>1:\n a+=((b*(b-1))//2)\n print(a)\n```","inputs":"2\n4 3\n111\n100\n110\n000\n2 2\n10\n01\n","output":"4\n0\n","actual_output":"4\n0\n","execution_success":true,"sample_index":1032},{"source":"apps","task_type":"verifiable_code","in_source_id":"1444","prompt":"Solve the following coding problem using the programming language python:\n\nChef is a big fan of soccer! He loves soccer so much that he even invented soccer for dogs! Here are the rules of soccer for dogs:\n- N$N$ dogs (numbered 1$1$ through N$N$) stand in a line in such a way that for each valid i$i$, dogs i$i$ and i+1$i + 1$ are adjacent.\n- Each dog has a skill level, which is either 1$1$ or 2$2$.\n- At the beginning of the game, Chef passes a ball to dog 1$1$ (dog 1$1$ receives the ball).\n- For each valid i$i$, if dog i$i$ has skill level s$s$, this dog can pass the ball to any dog with number j$j$ such that 1\u2264|i\u2212j|\u2264s$1 \\le |i-j| \\le s$.\n- Each dog (including dog 1$1$) may receive the ball at most once.\n- Whenever a dog receives the ball, it must either pass it to another dog or finish the game by scoring a goal.\nWhile the dogs were playing, Chef also created a game for developers. He defined the result of a game of soccer for dogs as the sequence of dogs which received the ball in the order in which they received it. The last dog in the sequence is the dog that decided to score a goal; if a dog never received the ball, it does not appear in the sequence. In the game for developers, you should find the number of possible results of soccer for dogs.\nFind this number of possible results modulo 109+7$10^9 + 7$. Two results of soccer for dogs (sequences of dogs' numbers) are considered different if these sequences have different lengths or if there is a valid index i$i$ such that the i$i$-th dog in one sequence is different from the i$i$-th dog in the other sequence.\n\n-----Input-----\n- 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.\n- The first line of each test case contains a single integer N$N$.\n- The second line contains N$N$ space-separated integers A1,A2,\u2026,AN$A_1, A_2, \\ldots, A_N$ denoting the skill levels of the dogs.\n\n-----Output-----\nFor each test case, print a single line containing one integer - the number of different results of soccer for dogs, modulo 109+7$10^9 + 7$.\n\n-----Constraints-----\n- 1\u2264T\u226410$1 \\le T \\le 10$\n- 1\u2264N\u2264105$1 \\le N \\le 10^5$\n- 1\u2264Ai\u22642$1 \\le A_i \\le 2$ for each valid i$i$\n\n-----Subtasks-----\nSubtask #1 (10 points): N\u226410$N \\le 10$\nSubtask #2 (30 points): N\u2264103$N \\le 10^3$\nSubtask #3 (60 points): original constraints\n\n-----Example Input-----\n3\n4\n1 1 1 1\n3\n2 2 2\n4\n1 2 1 1\n\n-----Example Output-----\n4\n5\n6\n\n-----Explanation-----\nExample case 1: The following results are possible: 1$1$, [1,2]$[1, 2]$, [1,2,3]$[1, 2, 3]$, [1,2,3,4]$[1, 2, 3, 4]$.\nExample case 2: The following results are possible: [1]$[1]$, [1,2]$[1, 2]$, [1,2,3]$[1, 2, 3]$, [1,3,2]$[1, 3, 2]$, [1,3]$[1, 3]$.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfor _ in range(int(input())):\r\n\tnum=int(input())\r\n\tarr=list(map(int,input().split()))\r\n\tdp=[0]*num\r\n\tdp[0]=1\r\n\tans=1\r\n\tj=0\r\n\tfor i in range(1,num):\r\n\t\tj=i+1\r\n\t\tcount=1\r\n\t\tdp[i]=dp[i-1]%1000000007\r\n\t\tif i-2>=0 and arr[i-2]==2:\r\n\t\t\tdp[i]+=dp[i-2]%1000000007\r\n\t\t\tif i-3>=0 and arr[i-3]==2:\r\n\t\t\t\tdp[i]+=dp[i-3]\r\n\t\tans+=dp[i]%1000000007\r\n\t\tif arr[i-1]==2 and i=j or j==0:\r\n\t\t\t\tj=i+1\r\n\t\t\twhile j=0 and arr[i-2]==2:\r\n\t\t\tdp[i]+=dp[i-2]%1000000007\r\n\t\t\tif i-3>=0 and arr[i-3]==2:\r\n\t\t\t\tdp[i]+=dp[i-3]\r\n\t\tans+=dp[i]%1000000007\r\n\t\tif arr[i-1]==2 and i=j or j==0:\r\n\t\t\t\tj=i+1\r\n\t\t\twhile j R we mean by S[L, R] an empty string.\n\n-----Input-----\nThe first line of the input file contains a single integer T, the number of test cases. Each of the following T lines contains one string, the string S for the corresponding test case. The input file does not contain any whitespaces.\n\n-----Output-----\nFor each test case output a single line containing the answer for this test case.\n\n-----Constraints-----\n1 \u2264 T \u2264 10\n\n1 \u2264 |S| \u2264 100000\n\nS consists only of the lucky digits 4 and 7.\n\n\n-----Example-----\nInput:\n4\n47\n74\n477\n4747477\n\nOutput:\n2\n2\n3\n23\n\n-----Explanation-----\n\nIn the first test case balance substrings are S[1, 1] = 4 and S[1, 2] = 47.\nIn the second test case balance substrings are S[2, 2] = 4 and S[1, 2] = 74.\nUnfortunately, we can't provide you with the explanations of the third and the fourth test cases. You should figure it out by yourself. Please, don't ask about this in comments.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nx=eval(input())\nfor x in range(0,x):\n\tans=0\n\td=input()\n\ta=0\n\tcont=0\n\tfor i in range(0,len(d)):\n\t\ta+=len(d)-i\n\t\tif d[i]=='7':\n\t\t\tans+=1+cont\n\t\t\tcont+=1\n\t\telse:\n\t\t\tcont=0\n\tans=a-ans\n\tprint(ans)\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '4\\n47\\n74\\n477\\n4747477\\n\\n\\n', 'output': '2\\n2\\n3\\n23\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/COOK22/problems/LUCKYBAL'}","problem_id":"vfc_4638","program":"```python\nx=eval(input())\nfor x in range(0,x):\n\tans=0\n\td=input()\n\ta=0\n\tcont=0\n\tfor i in range(0,len(d)):\n\t\ta+=len(d)-i\n\t\tif d[i]=='7':\n\t\t\tans+=1+cont\n\t\t\tcont+=1\n\t\telse:\n\t\t\tcont=0\n\tans=a-ans\n\tprint(ans)\n\n```","inputs":"4\n47\n74\n477\n4747477\n\n\n","output":"2\n2\n3\n23\n","actual_output":"2\n2\n3\n23\n","execution_success":true,"sample_index":1038},{"source":"apps","task_type":"verifiable_code","in_source_id":"1450","prompt":"Solve the following coding problem using the programming language python:\n\nCheffina challanges chef to rearrange the given array as arr[i] > arr[i+1] < arr[i+2] > arr[i+3].. and so on\u2026, i.e. also arr[i] < arr[i+2] and arr[i+1] < arr[i+3] and arr[i] < arr[i+3] so on.. Chef accepts the challenge, chef starts coding but his code is not compiling help him to write new code.\n\n-----Input:-----\n- First-line will contain $T$, the number of test cases. Then the test cases follow. \n- Each test case contains two lines of input, First $N$ as the size of the array. \n- N space-separated distinct integers.\n\n-----Output:-----\nFor each test case, output in a single line answer given to the Chefffina.\n\n-----Constraints-----\n- $1 \\leq T \\leq 10$\n- $1 \\leq N \\leq 10^5$\n- $1 \\leq arr[i] \\leq 10^5$\n\n-----Sample Input:-----\n2\n4\n4 1 6 3\n5\n4 5 1 6 3\n\n-----Sample Output:-----\n3 1 6 4\n3 1 5 4 6\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\nfor _ in range(int(input())):\n n = int(input())\n a = list(map(int,input().split()))\n a.sort()\n i=1\n while(i=1:\n count = (x+1)//2\n sum_A += count * 2**power\n x = x - count\n power += 1\n sum_B = summation_N - sum_A\n ans = sum_B - (int(math.log(initial,2))+1)\n return ans\n \nfor _ in range(int(input())):\n l,r = list(map(int,input().split()))\n if l==1:\n print(GLR(r))\n else:\n print((GLR(r) - GLR(l-1)))# cook your dish here\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '5\\n1 10\\n3 6\\n4 10\\n10 17\\n100 159\\n', 'output': '28\\n9\\n28\\n79\\n7485\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/XORIT'}","problem_id":"vfc_4666","program":"```python\nimport math\ndef GLR(x):\n summation_N = (x*(x+1))//2\n initial = x\n power = 0\n sum_A = 0\n while x>=1:\n count = (x+1)//2\n sum_A += count * 2**power\n x = x - count\n power += 1\n sum_B = summation_N - sum_A\n ans = sum_B - (int(math.log(initial,2))+1)\n return ans\n \nfor _ in range(int(input())):\n l,r = list(map(int,input().split()))\n if l==1:\n print(GLR(r))\n else:\n print((GLR(r) - GLR(l-1)))# cook your dish here\n\n```","inputs":"5\n1 10\n3 6\n4 10\n10 17\n100 159\n","output":"28\n9\n28\n79\n7485\n","actual_output":"28\n9\n28\n79\n7485\n","execution_success":true,"sample_index":1044},{"source":"apps","task_type":"verifiable_code","in_source_id":"1457","prompt":"Solve the following coding problem using the programming language python:\n\nThe purpose of this problem is to verify whether the method you are using to read input data is sufficiently fast to handle problems branded with the enormous Input/Output warning. You are expected to be able to process at least 2.5MB of input data per second at runtime.\n\n-----Input-----\nThe input begins with two positive integers n k (n, k<=107). The next n lines of input contain one positive integer ti, not greater than 109, each.\n\n-----Output-----\nWrite a single integer to output, denoting how many integers ti are divisible by k.\n\n-----Example-----\nInput:\n7 3\n1\n51\n966369\n7\n9\n999996\n11\n\nOutput:\n4\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n#Note that it's python3 Code. Here, we are using input() instead of raw_input().\n#You can check on your local machine the version of python by typing \"python --version\" in the terminal.\n\n(n, k) = list(map(int, input().split(' ')))\n\nans = 0\n\nfor i in range(n):\n\tx = int(input())\n\tif x % k == 0:\n\t\tans += 1\n\nprint(ans)\t\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '7 3\\n1\\n51\\n966369\\n7\\n9\\n999996\\n11\\n', 'output': '4\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/INTEST'}","problem_id":"vfc_4670","program":"```python\n#Note that it's python3 Code. Here, we are using input() instead of raw_input().\n#You can check on your local machine the version of python by typing \"python --version\" in the terminal.\n\n(n, k) = list(map(int, input().split(' ')))\n\nans = 0\n\nfor i in range(n):\n\tx = int(input())\n\tif x % k == 0:\n\t\tans += 1\n\nprint(ans)\t\n```","inputs":"7 3\n1\n51\n966369\n7\n9\n999996\n11\n","output":"4\n","actual_output":"4\n","execution_success":true,"sample_index":1045},{"source":"apps","task_type":"verifiable_code","in_source_id":"1458","prompt":"Solve the following coding problem using the programming language python:\n\nChef has recently been playing a lot of chess in preparation for the ICCT (International Chef Chess Tournament).\nSince putting in long hours is not an easy task, Chef's mind wanders elsewhere. He starts counting the number of squares with odd side length on his chessboard..\nHowever, Chef is not satisfied. He wants to know the number of squares of odd side length on a generic $N*N$ chessboard.\n\n-----Input:-----\n- The first line will contain a single integer $T$, the number of test cases.\n- The next $T$ lines will have a single integer $N$, the size of the chess board.\n\n-----Output:-----\nFor each test case, print a integer denoting the number of squares with odd length.\n\n-----Constraints-----\n- $1 \\leq T \\leq 100$\n- $1 \\leq N \\leq 1000$\n\n-----Sample Input:-----\n2\n3\n8\n\n-----Sample Output:-----\n10\n120\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\nt=int(input())\nfor i in range(t):\n a=0\n n=int(input())\n while(n>0):\n a += n*n\n n=n-2\n print(a)\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n3\\n8\\n', 'output': '10\\n120\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/PCJ18B'}","problem_id":"vfc_4674","program":"```python\n# cook your dish here\nt=int(input())\nfor i in range(t):\n a=0\n n=int(input())\n while(n>0):\n a += n*n\n n=n-2\n print(a)\n\n```","inputs":"2\n3\n8\n","output":"10\n120\n","actual_output":"10\n120\n","execution_success":true,"sample_index":1046},{"source":"apps","task_type":"verifiable_code","in_source_id":"1460","prompt":"Solve the following coding problem using the programming language python:\n\nMia is working as a waitress at a breakfast diner. She can take up only one shift from 6 shifts a day i.e. from 10 am to 4 pm. She needs to save 300$ after completion of the month. She works only for $D$ days in the month. She estimates that she gets her highest tip in the first shift and the tip starts decreasing by 2% every hour as the day prolongs. She gets a minimum wage of $X$ $ for every shift. And her highest tip in the first shift is $Y$ $. Determine whether Mia will be able to save 300$ from her wages and tips after working $D$ days of the month. If she can, print YES, else print NO.\n\n-----Constraints-----\n- 8 <= D <=30\n- 7 <= X <=30\n- 4 <= Y <= 20\n\n-----Input:-----\n- First line has three parameters $D$, $X$ and $Y$ i.e. number of days worked, minimum wage and highest tip.\n- Second line contains D integers indicating her shifts every $i$-th day she has worked.\n\n-----Output:-----\n- Print YES, if Mia has saved 300$, NO otherwise.\n\n-----Sample Input:-----\n9 17 5\n1 3 2 4 5 6 1 2 2\n\n-----Sample Output:-----\nNO\n\n-----Explanation:-----\nNo. of days Mia worked (D) is 9, so minimum wage she earns (X) is 17 dollars. Highest tip at first hour (Y) = 5 dollars, 1st day she took 1st shift and 2nd day she took 3rd shift and so on. Upon calculation we will find that Mia was not able to save 300 dollars.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\n\nl=[int(k) for k in input().split()]\ns=[int(k) for k in input().split()]\nx=l[1]*l[0]\nfor i in range(l[0]):\n if(s[i]==1):\n x+=l[2]\n elif(s[i]==2):\n x+=(l[2]*98/100)\n elif(s[i]==3):\n x+=(l[2]*96/100)\n elif(s[i]==4):\n x+=(l[2]*94/100)\n elif(s[i]==5):\n x+=(l[2]*92/100)\n elif(s[i]==6):\n x+=(l[2]*90/100)\nif(x>=300):\n print(\"YES\")\nelse:\n print(\"NO\")\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '9 17 5\\n1 3 2 4 5 6 1 2 2\\n', 'output': 'NO\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/TAWY2020/problems/TAWY002'}","problem_id":"vfc_4682","program":"```python\n# cook your dish here\n\nl=[int(k) for k in input().split()]\ns=[int(k) for k in input().split()]\nx=l[1]*l[0]\nfor i in range(l[0]):\n if(s[i]==1):\n x+=l[2]\n elif(s[i]==2):\n x+=(l[2]*98/100)\n elif(s[i]==3):\n x+=(l[2]*96/100)\n elif(s[i]==4):\n x+=(l[2]*94/100)\n elif(s[i]==5):\n x+=(l[2]*92/100)\n elif(s[i]==6):\n x+=(l[2]*90/100)\nif(x>=300):\n print(\"YES\")\nelse:\n print(\"NO\")\n```","inputs":"9 17 5\n1 3 2 4 5 6 1 2 2\n","output":"NO\n","actual_output":"NO\n","execution_success":true,"sample_index":1048},{"source":"apps","task_type":"verifiable_code","in_source_id":"1461","prompt":"Solve the following coding problem using the programming language python:\n\nConsider the fraction, $a/b$, where $a$ and $b$ are positive integers. If $a < b$ and $GCD(a,b) = 1$, it is called a reduced proper fraction.\nIf we list the set of a reduced proper fraction for $d \\leq 8$, (where $d$ is the denominator) in ascending order of size, we get:\n$1/8$, $1/7$, $1/6$, $1/5$, $1/4$, $2/7$, $1/3$, $3/8$, $2/5$ , $3/7$, $1/2$, $4/7$, $3/5$, $5/8$, $2/3$, $5/7$, $3/4$, $4/5$, $5/6$, $6/7$, $7/8$\nIt can be seen that $2/5$ is the fraction immediately to the left of $3/7$.\nBy listing the set of reduced proper fractions for $d \\leq N$ in ascending order of value, find the numerator and denominator of the fraction immediately to the left of $a/b$ when $a$ and $b$ are given.\n\n-----Input:-----\n- First line of input contains an integer $T$, number of test cases\n- Next $T$ lines contain $a$ $b$ $N$ separated by space\n\n-----Output:-----\nPrint the numerator and denominator separated by a space corresponding to each test case on a new line\n\n-----Constraints-----\n- $1 \\leq T \\leq 50$\n- $1 \\leq a < b \\leq 10^9$\n- $GCD(a,b) = 1$\n- $b < N \\leq 10^{15}$\n\n-----Subtasks-----\n- 10 points: $1 \\leq N \\leq 100$\n- 30 points : $1 \\leq N \\leq 10^6$\n- 60 points : $1 \\leq N \\leq 10^{15}$\n\n-----Sample Input:-----\n5\n3 7 8\n3 5 8\n4 5 8\n6 7 8\n1 5 8\n\n-----Sample Output:-----\n2 5\n4 7\n3 4\n5 6\n1 6\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfrom sys import stdin\nfrom fractions import Fraction\n\ninput = stdin.readline\n\nfor _ in range(int(input())):\n a, b, n = list(map(int, input().split()))\n ab = Fraction(a, b)\n\n p = set()\n\n for i in range(1, n+1):\n for j in range(n, 0, -1):\n x = Fraction(i, j)\n\n if x > ab:\n break\n\n p.add(x)\n\n x = sorted(p)[-2]\n\n print(x.numerator, x.denominator)\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '5\\n3 7 8\\n3 5 8\\n4 5 8\\n6 7 8\\n1 5 8\\n', 'output': '2 5\\n4 7\\n3 4\\n5 6\\n1 6\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/QTST2020/problems/NEGBFRAC'}","problem_id":"vfc_4686","program":"```python\nfrom sys import stdin\nfrom fractions import Fraction\n\ninput = stdin.readline\n\nfor _ in range(int(input())):\n a, b, n = list(map(int, input().split()))\n ab = Fraction(a, b)\n\n p = set()\n\n for i in range(1, n+1):\n for j in range(n, 0, -1):\n x = Fraction(i, j)\n\n if x > ab:\n break\n\n p.add(x)\n\n x = sorted(p)[-2]\n\n print(x.numerator, x.denominator)\n\n```","inputs":"5\n3 7 8\n3 5 8\n4 5 8\n6 7 8\n1 5 8\n","output":"2 5\n4 7\n3 4\n5 6\n1 6\n","actual_output":"2 5\n4 7\n3 4\n5 6\n1 6\n","execution_success":true,"sample_index":1049},{"source":"apps","task_type":"verifiable_code","in_source_id":"1462","prompt":"Solve the following coding problem using the programming language python:\n\nThe name of our college is \"Government College of Engineering and Textile Technology Berhampore\". There is another college named \"Government College of Engineering and Textile Technology Serampore\". As the names are quite similar, those who are unaware of existence of both the colleges, often get confused. And mistake one with other.\n\nGiven a string, if it contains the word berhampore (case insensitive), print GCETTB or if it contains serampore(case-insensitive), print GCETTS . If the string contains neither print Others. If it contains both Berhampore and Serampore print Both \nInput \n- First line contains single integer T, No. of test case \n- Next line for every test contain case a string S \nOutput\n\nPrint GCETTB or GCETTS or Others or Both on a new line\nConstraints \n- 1 <= T <= 10 \n- 0 <= len(S) <= 100 \n- S contain a-z and A-Z and space only\nSample Input\n3\nGovernment clg Berhampore\nSeRaMporE textile college \nGirls college Kolkata\n\nSample Output\n\nGCETTB\n\nGCETTS\n\nOthers \nExplanation\n\nSelf-Explanatory\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\ntry:\n t=int(input()) \n for i in range(t):\n n=input() \n n=n.lower()\n a=\"berhampore\"\n b=\"serampore\"\n if a in n:\n if b in n:\n print(\"Both\")\n else:\n print(\"GCETTB\")\n elif b in n:\n if a in n:\n print(\"Both\")\n else:\n print(\"GCETTS\")\n else:\n print(\"Others\")\nexcept Exception as e:\n pass\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\nGovernment clg Berhampore\\nSeRaMporE textile college\\nGirls college Kolkata\\n', 'output': 'GCETTB\\nGCETTS\\nOthers\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/COMT2020/problems/BHPORSRP'}","problem_id":"vfc_4690","program":"```python\n# cook your dish here\ntry:\n t=int(input()) \n for i in range(t):\n n=input() \n n=n.lower()\n a=\"berhampore\"\n b=\"serampore\"\n if a in n:\n if b in n:\n print(\"Both\")\n else:\n print(\"GCETTB\")\n elif b in n:\n if a in n:\n print(\"Both\")\n else:\n print(\"GCETTS\")\n else:\n print(\"Others\")\nexcept Exception as e:\n pass\n```","inputs":"3\nGovernment clg Berhampore\nSeRaMporE textile college\nGirls college Kolkata\n","output":"GCETTB\nGCETTS\nOthers\n","actual_output":"GCETTB\nGCETTS\nOthers\n","execution_success":true,"sample_index":1050},{"source":"apps","task_type":"verifiable_code","in_source_id":"1463","prompt":"Solve the following coding problem using the programming language python:\n\nChef has a recipe book. He wishes to read it completely as soon as possible so that he could try to cook the dishes mentioned in the book.\nThe pages of the book are numbered $1$ through $N$. Over a series of days, Chef wants to read each page. On each day, Chef can choose to read any set of pages such that there is no prime that divides the numbers of two or more of these pages, i.e. the numbers of pages he reads on the same day must be pairwise coprime. For example, Chef can read pages $1$, $3$ and $10$ on one day, since $(1, 3)$, $(3, 10)$ and $(1, 10)$ are pairs of coprime integers; however, he cannot read pages $1$, $3$ and $6$ on one day, as $3$ and $6$ are both divisible by $3$. Since chef might get bored by reading the same recipe again and again, Chef will read every page exactly once.\nGiven $N$, determine the minimum number of days Chef needs to read the entire book and the pages Chef should read on each of these days.\n\n-----Input-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The first and only line of each test case contains a single integer $N$.\n\n-----Output-----\nFor each test case:\n- First, print a line containing a single integer $D$ \u2015 the minimum number of days required to read the book. Let's number these days $1$ through $D$.\n- Then, print $D$ lines describing the pages Chef should read. For each valid $i$, the $i$-th of these lines should contain an integer $C_i$ followed by a space and $C_i$ space-separated integers \u2015 the numbers of pages Chef should read on the $i$-th day.\nIf there are multiple solutions with the minimum number of days, you may print any one.\n\n-----Constraints-----\n- $1 \\le T \\le 10$\n- $1 \\le N \\le 10^6$\n\n-----Subtasks-----\nSubtask #1 (20 points): $N \\le 100$\nSubtask #2 (80 points): original constraints\n\n-----Example Input-----\n1\n5\n\n-----Example Output-----\n2\n3 1 2 5\n2 3 4\n\n-----Explanation-----\nExample case 1:\n- On the first day, Chef should read three pages: $1$, $2$ and $5$.\n- On the second day, Chef should read the remaining two pages: $3$ and $4$.\nThere are other valid solutions as well.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\ndef ugcd(n):\r\n ans = [[1]]\r\n if(n==1):\r\n return ans\r\n elif(n%2==1):\r\n ans = [[1, 2, n]]\r\n else:\r\n ans = [[1, 2]]\r\n for k in range(1, int(n//2)):\r\n ans.append([k*2+1, k*2+2])\r\n return ans\r\nt = int(input())\r\nfor i in range(t):\r\n n = int(input())\r\n s = (ugcd(n))\r\n print(len(s))\r\n for j in range(len(s)):\r\n print(len(s[j]), end=\" \")\r\n print(*s[j])\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n5\\n\\n', 'output': '2\\n3 1 2 5\\n2 3 4\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/UNITGCD'}","problem_id":"vfc_4694","program":"```python\ndef ugcd(n):\r\n ans = [[1]]\r\n if(n==1):\r\n return ans\r\n elif(n%2==1):\r\n ans = [[1, 2, n]]\r\n else:\r\n ans = [[1, 2]]\r\n for k in range(1, int(n//2)):\r\n ans.append([k*2+1, k*2+2])\r\n return ans\r\nt = int(input())\r\nfor i in range(t):\r\n n = int(input())\r\n s = (ugcd(n))\r\n print(len(s))\r\n for j in range(len(s)):\r\n print(len(s[j]), end=\" \")\r\n print(*s[j])\n```","inputs":"1\n5\n\n","output":"2\n3 1 2 5\n2 3 4\n","actual_output":"2\n3 1 2 5\n2 3 4\n","execution_success":true,"sample_index":1051},{"source":"apps","task_type":"verifiable_code","in_source_id":"1464","prompt":"Solve the following coding problem using the programming language python:\n\nYou visit a doctor on a date given in the format $yyyy:mm:dd$. Your doctor suggests you to take pills every alternate day starting from that day. You being a forgetful person are pretty sure won\u2019t be able to remember the last day you took the medicine and would end up in taking the medicines on wrong days. \nSo you come up with the idea of taking medicine on the dates whose day is odd or even depending on whether $dd$ is odd or even. Calculate the number of pills you took on right time before messing up for the first time.\n\n-----Note:-----\nEvery year that is exactly divisible by four is a leap year, except for years that are exactly divisible by 100; the centurial years that are exactly divisible by 400 are still leap years. For example, the year 1900 is not a leap year; the year 2000 is a leap year.\n\n-----Input:-----\n- First line will contain $T$, number of testcases. Then the testcases follow. \n- Each testcase contains of a single line of input, in the format $yyyy:mm:dd$\n\n-----Output:-----\nFor each testcase, output in a single line the required answer.\n\n-----Constraints-----\n- $ 1 \\leq T \\leq 1000 $\n- $ 1900 \\leq yyyy \\leq\u20092038 $\n- $yyyy:mm:dd$ is a valid date\n\n-----Sample Input:-----\n1\n2019:03:31\n\n-----Sample Output:-----\n1\n\n-----EXPLANATION:-----\nYou can take pill on the right day only on 31st March. Next you will take it on 1st April which is not on the alternate day.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nt=int(input())\nli1=[31,29,31,30,31,30,31,31,30,31,30,31]\nli2=[31,28,31,30,31,30,31,31,30,31,30,31]\nfor z in range(t):\n y,m,d=list(map(int,input().split(':')))\n if y%4 == 0:\n if y%100 == 0:\n if y%400 == 0:\n li=li1\n else:\n li=li2\n else:\n li=li1\n else:\n li=li2\n c=0\n if d%2 == 0:\n while d%2 == 0:\n c+=1\n d+=2\n if d>li[m-1]:\n d=d%li[m-1]\n m+=1\n else: \n while d%2 != 0:\n c+=1\n d+=2\n if d>li[m-1]:\n d=d%li[m-1]\n m+=1\n print(c)\n \n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n2019:03:31\\n', 'output': '1\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/MEDIC'}","problem_id":"vfc_4698","program":"```python\nt=int(input())\nli1=[31,29,31,30,31,30,31,31,30,31,30,31]\nli2=[31,28,31,30,31,30,31,31,30,31,30,31]\nfor z in range(t):\n y,m,d=list(map(int,input().split(':')))\n if y%4 == 0:\n if y%100 == 0:\n if y%400 == 0:\n li=li1\n else:\n li=li2\n else:\n li=li1\n else:\n li=li2\n c=0\n if d%2 == 0:\n while d%2 == 0:\n c+=1\n d+=2\n if d>li[m-1]:\n d=d%li[m-1]\n m+=1\n else: \n while d%2 != 0:\n c+=1\n d+=2\n if d>li[m-1]:\n d=d%li[m-1]\n m+=1\n print(c)\n \n\n```","inputs":"1\n2019:03:31\n","output":"1\n","actual_output":"1\n","execution_success":true,"sample_index":1052},{"source":"apps","task_type":"verifiable_code","in_source_id":"1465","prompt":"Solve the following coding problem using the programming language python:\n\nYou are given a tree consisting of n nodes numbered from 1 to n. The weights of edges of the tree can be any binary integer satisfying following Q conditions.\n\n- \n\t\tEach condition is of form u, v, x where u, v are nodes of the tree and x is a binary number. \n\n\t\tFor satisfying this condition, sum of the weight of all the edges present in the path from node u to v of the tree, should have even if x = 0, odd otherwise. \n\t\n\nNow, you have to find out number of ways of assigning 0/1 (binary) weights to the edges of the tree satisfying the above conditions.\nAs the answer could be quite large, print your answer modulo 109 + 7.\n\n-----Input-----\n- The first line of input contains a single integer T denoting number of test cases.\n- For each test case:\n\t\n- First line contains two space separated integers n, Q.\n- Each of the next n - 1 lines will contain two space separated integer u, v denoting that there is an edge between vertex u and v in the tree.\n- Each of the next Q lines will contain three space separated integer u, v, x denoting a condition as stated in the probelm.\n\n-----Output-----\n- For each test case, output a single integer corresponding to the answer of the problem.\n\n-----Constraints-----\n- 1 \u2264 u, v \u2264 n\n- 0 \u2264 x \u2264 1\n\n-----Subtasks-----\nSubtask #1 : (10 points)\n- Sum of each of variables n and Q over all the test cases \u2264 20\n\nSubtask #2 : (20 points)\n- Sum of each of variables n and Q over all the test cases \u2264 100\n\nSubtask #3 : (30 points)\n- Sum of each of variables n and Q over all the test cases \u2264 5000\n\nSubtask #4 : (40 points)\n- Sum of each of variables n and Q over all the test cases \u2264 100000\n\n-----Example-----\nInput:\n3\n3 2\n1 2\n1 3\n1 2 0\n1 3 0\n3 0\n1 2\n2 3\n3 1\n1 2\n2 3\n1 2 1\n\nOutput:\n1\n4\n2\n\n-----Explanation-----\nIn the first example, \nYou can only set the weight of each edge equal to 0 for satisfying the given condition. So, there is exactly one way of doing this. Hence answer is 1.\n\nIn the second example, \nThere are two edges and there is no condition on the edges. So, you can assign them in 4 ways. \n\nIn the third example, \nYou have to assign the weight of edge between node 1 and 2 to 1. You can assign the remaining edge from 2 to 3 either 0 or 1. So, the answer is 2.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nimport sys\n\ndef powc(x,n,m):\n res = 1\n xx=x\n while n:\n if n&1:\n res = (res*xx)%m\n xx=xx*xx%m\n n >>= 1\n return res\n\ndef circles(u):\n r = 0\n S = [(u,-1,0)]\n Visited[u] = 0\n for s in S:\n for e in V[s[0]]:\n if e[0] != s[1]:\n if Visited[e[0]]==-1: \n Visited[e[0]] = s[2]^e[1]\n S.append((e[0], s[0], s[2]^e[1])) \n elif Visited[e[0]] != s[2]^e[1]:\n return -1\n else:\n r += s[0]>= 1\n return res\n\ndef circles(u):\n r = 0\n S = [(u,-1,0)]\n Visited[u] = 0\n for s in S:\n for e in V[s[0]]:\n if e[0] != s[1]:\n if Visited[e[0]]==-1: \n Visited[e[0]] = s[2]^e[1]\n S.append((e[0], s[0], s[2]^e[1])) \n elif Visited[e[0]] != s[2]^e[1]:\n return -1\n else:\n r += s[0] N$, $F_i$ is calculated as $f(F_{i-1}, F_{i-2}, \\ldots, F_{i-N})$, where $f$ is some function. A XOR $N$-bonacci sequence is an $N$-bonacci sequence for which $f(F_{i-1}, F_{i-2}, \\ldots, F_{i-N}) = F_{i-1} \\oplus F_{i\u22122} \\oplus \\ldots \\oplus F_{i\u2212N}$, where $\\oplus$ denotes the bitwise XOR operation.\nRecently, Chef has found an interesting sequence $S_1, S_2, \\ldots$, which is obtained from prefix XORs of a XOR $N$-bonacci sequence $F_1, F_2, \\ldots$. Formally, for each positive integer $i$, $S_i = F_1 \\oplus F_2 \\oplus \\ldots \\oplus F_i$. You are given the first $N$ elements of the sequence $F$, which uniquely determine the entire sequence $S$.\nYou should answer $Q$ queries. In each query, you are given an index $k$ and you should calculate $S_k$. It is guaranteed that in each query, $S_k$ does not exceed $10^{50}$.\n\n-----Input-----\n- The first line of the input contains two space-separated integers $N$ and $Q$.\n- The second line contains $N$ space-separated integers $F_1, F_2, \\ldots, F_N$.\n- The following $Q$ lines describe queries. Each of these lines contains a single integer $k$.\n\n-----Output-----\nFor each query, print a single line containing one integer $S_k$.\n\n-----Constraints-----\n- $1 \\le N, Q \\le 10^5$\n- $0 \\le F_i \\le 10^9$ for each $i$ such that $1 \\le i \\le N$\n- $1 \\le k \\le 10^9$\n\n-----Example Input-----\n3 4\n0 1 2\n7\n2\n5\n1000000000\n\n-----Example Output-----\n3\n1\n0\n0\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\nn,q=map(int,input().split())\nls=[int(i) for i in input().split()]\ncur=0\ns=[0]\nfor i in ls:\n cur=cur^i\n s.append(cur)\nfor i in range(q):\n k=int(input())\n print(s[k%(n+1)])\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3 4\\n0 1 2\\n7\\n2\\n5\\n1000000000\\n', 'output': '3\\n1\\n0\\n0\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/NBONACCI'}","problem_id":"vfc_4706","program":"```python\n# cook your dish here\nn,q=map(int,input().split())\nls=[int(i) for i in input().split()]\ncur=0\ns=[0]\nfor i in ls:\n cur=cur^i\n s.append(cur)\nfor i in range(q):\n k=int(input())\n print(s[k%(n+1)])\n```","inputs":"3 4\n0 1 2\n7\n2\n5\n1000000000\n","output":"3\n1\n0\n0\n","actual_output":"3\n1\n0\n0\n","execution_success":true,"sample_index":1054},{"source":"apps","task_type":"verifiable_code","in_source_id":"1467","prompt":"Solve the following coding problem using the programming language python:\n\nAlice and Johnny are playing a simple guessing game. Johnny picks an arbitrary positive integer n (1<=n<=109) and gives Alice exactly k hints about the value of n. It is Alice's task to guess n, based on the received hints. \n\nAlice often has a serious problem guessing the value of n, and she's beginning to suspect that Johnny occasionally cheats, that is, gives her incorrect hints. \nAfter the last game, they had the following little conversation:\n\n- [Alice] Johnny, you keep cheating!\n\n- [Johnny] Indeed? You cannot prove it.\n\n- [Alice] Oh yes I can. In fact, I can tell you with the utmost certainty that in the last game you lied to me at least *** times.\n\nSo, how many times at least did Johnny lie to Alice? Try to determine this, knowing only the hints Johnny gave to Alice.\n\n-----Input-----\nThe first line of input contains t, the number of test cases (about 20). Exactly t test cases follow. \n\nEach test case starts with a line containing a single integer k, denoting the number of hints given by Johnny (1<=k<=100000). Each of the next k lines contains exactly one hint. The i-th hint is of the form:\noperator li logical_value\nwhere operator denotes one of the symbols < , > , or =; li is an integer (1<=li<=109), while logical_value is one of the words: Yes or No. The hint is considered correct if logical_value is the correct reply to the question: \"Does the relation: n operator li hold?\", and is considered to be false (a lie) otherwise.\n\n-----Output-----\nFor each test case output a line containing a single integer, equal to the minimal possible number of Johnny's lies during the game.\n\n-----Example-----\nInput:\n3\n2\n< 100 No\n> 100 No\n3\n< 2 Yes\n> 4 Yes\n= 3 No\n6\n< 2 Yes\n> 1 Yes\n= 1 Yes\n= 1 Yes\n> 1 Yes\n= 1 Yes\n\nOutput:\n0\n1\n2\n\nExplanation: for the respective test cases, the number picked by Johnny could have been e.g. n=100, n=5, and n=1.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\ndef guessingGame (l):\n a = []\n m = 1000000001\n for i in range (len(l)):\n k=int(l[i][1])\n if (l[i][0]=='<' and l[i][2]=='Yes'):\n a.append((1,1))\n a.append((k,-1))\n \n if (l[i][0]=='<' and l[i][2]=='No'):\n a.append((k,1))\n a.append((m,-1))\n \n if (l[i][0]=='=' and l[i][2]=='Yes'):\n a.append((k,1))\n a.append((k+1,-1))\n\n if (l[i][0]=='=' and l[i][2]=='No'):\n a.append((1,1))\n a.append((k,-1))\n a.append((k+1,1))\n a.append((m,-1))\n\n if (l[i][0]=='>' and l[i][2]=='Yes'):\n a.append((k+1,1))\n a.append((m,-1))\n\n if (l[i][0]=='>' and l[i][2]=='No'):\n a.append((1,1))\n a.append((k+1,-1))\n\n a.sort()\n w=0\n r=0\n\n for i in range (len(a)):\n w+=a[i][1]\n r=max(w,r)\n\n return len(l)-r\n \n \ndef __starting_point():\n\n T = int(input())\n answer = []\n\n for _ in range (T):\n e = int(input())\n temp = []\n for q_t in range (e):\n q = list(map(str,input().rstrip().split()))\n temp.append(q)\n result = guessingGame(temp)\n print(result)\n__starting_point()\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\n2\\n< 100 No\\n> 100 No\\n3\\n< 2 Yes\\n> 4 Yes\\n= 3 No\\n6\\n< 2 Yes\\n> 1 Yes\\n= 1 Yes\\n= 1 Yes\\n> 1 Yes\\n= 1 Yes\\n', 'output': '0\\n1\\n2\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/A3'}","problem_id":"vfc_4710","program":"```python\n# cook your dish here\ndef guessingGame (l):\n a = []\n m = 1000000001\n for i in range (len(l)):\n k=int(l[i][1])\n if (l[i][0]=='<' and l[i][2]=='Yes'):\n a.append((1,1))\n a.append((k,-1))\n \n if (l[i][0]=='<' and l[i][2]=='No'):\n a.append((k,1))\n a.append((m,-1))\n \n if (l[i][0]=='=' and l[i][2]=='Yes'):\n a.append((k,1))\n a.append((k+1,-1))\n\n if (l[i][0]=='=' and l[i][2]=='No'):\n a.append((1,1))\n a.append((k,-1))\n a.append((k+1,1))\n a.append((m,-1))\n\n if (l[i][0]=='>' and l[i][2]=='Yes'):\n a.append((k+1,1))\n a.append((m,-1))\n\n if (l[i][0]=='>' and l[i][2]=='No'):\n a.append((1,1))\n a.append((k+1,-1))\n\n a.sort()\n w=0\n r=0\n\n for i in range (len(a)):\n w+=a[i][1]\n r=max(w,r)\n\n return len(l)-r\n \n \ndef __starting_point():\n\n T = int(input())\n answer = []\n\n for _ in range (T):\n e = int(input())\n temp = []\n for q_t in range (e):\n q = list(map(str,input().rstrip().split()))\n temp.append(q)\n result = guessingGame(temp)\n print(result)\n__starting_point()\n```","inputs":"3\n2\n< 100 No\n> 100 No\n3\n< 2 Yes\n> 4 Yes\n= 3 No\n6\n< 2 Yes\n> 1 Yes\n= 1 Yes\n= 1 Yes\n> 1 Yes\n= 1 Yes\n","output":"0\n1\n2\n","actual_output":"0\n1\n2\n","execution_success":true,"sample_index":1055},{"source":"apps","task_type":"verifiable_code","in_source_id":"1468","prompt":"Solve the following coding problem using the programming language python:\n\nMs. E.T. came from planet Hex. She has 8 fingers in each hand which makes her count in hexadecimal way. When she meets you, she tells you that she came from 7E light years from the planet Earth. You see she means that it is 126 light years far away and she is telling you the numbers in hexadecimal. Now, you are in trouble to understand what those numbers really mean. Therefore, you have to convert the hexadecimal numbers to decimals.\n\nInput:\n\nFirst line of code contain T test cases.\n\nevery line of text case contain a Hex-value \n\nOutput:\n\nEvery line of output contain a decimal conversion of given nunmber\n\nSample Input:\n\n3\n\nA\n\n1A23\n\n2C2A\n\nSample Output:\n\n10\n\n6691\n\n11306\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\ntry:\n t=int(input())\n for i in range(t):\n s=input()\n i=int(s,16)\n print(i)\nexcept EOFError as e:\n print(e)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\nA\\n1A23\\n2C2A\\n', 'output': '10\\n6691\\n11306\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/JLUG2020/problems/HXTDC'}","problem_id":"vfc_4714","program":"```python\n# cook your dish here\ntry:\n t=int(input())\n for i in range(t):\n s=input()\n i=int(s,16)\n print(i)\nexcept EOFError as e:\n print(e)\n```","inputs":"3\nA\n1A23\n2C2A\n","output":"10\n6691\n11306\n","actual_output":"10\n6691\n11306\n","execution_success":true,"sample_index":1056},{"source":"apps","task_type":"verifiable_code","in_source_id":"1469","prompt":"Solve the following coding problem using the programming language python:\n\nThe 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.\n\n-----Input:-----\n- First-line will contain $T$, the number of test cases. Then the test cases follow. \n- Each test case contains a single line of input, one integer $K$. \n\n-----Output:-----\nFor each test case, output as the pattern.\n\n-----Constraints-----\n- $1 \\leq T \\leq 100$\n- $1 \\leq K \\leq 100$\n\n-----Sample Input:-----\n4\n1\n2\n3\n4\n\n-----Sample Output:-----\n2\n23\n34\n234\n345\n456\n2345\n3456\n4567\n5678\n\n-----EXPLANATION:-----\nNo need, else pattern can be decode easily.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\ntry:\r\n tc=int(input())\r\n for _ in range(tc):\r\n n=int(input())\r\n st=\"\"\r\n b=1\r\n for i in range(1,n+1):\r\n b+=1\r\n a=b\r\n for j in range(1,n+1):\r\n print(a,end='')\r\n a+=1\r\n print() \r\nexcept:\r\n pass\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '4\\n1\\n2\\n3\\n4\\n', 'output': '2\\n23\\n34\\n234\\n345\\n456\\n2345\\n3456\\n4567\\n5678\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/PTRN2021/problems/ITGUY53'}","problem_id":"vfc_4718","program":"```python\ntry:\r\n tc=int(input())\r\n for _ in range(tc):\r\n n=int(input())\r\n st=\"\"\r\n b=1\r\n for i in range(1,n+1):\r\n b+=1\r\n a=b\r\n for j in range(1,n+1):\r\n print(a,end='')\r\n a+=1\r\n print() \r\nexcept:\r\n pass\n```","inputs":"4\n1\n2\n3\n4\n","output":"2\n23\n34\n234\n345\n456\n2345\n3456\n4567\n5678\n","actual_output":"2\n23\n34\n234\n345\n456\n2345\n3456\n4567\n5678\n","execution_success":true,"sample_index":1057},{"source":"apps","task_type":"verifiable_code","in_source_id":"1470","prompt":"Solve the following coding problem using the programming language python:\n\nAhmed Gafer failed to pass the test, but he got the job because of his friendship with Said and Shahhoud. After working in the kitchen for a while, he blew it. The customers didn't like the food anymore and one day he even burned the kitchen. Now the master Chef is very upset.\nAhmed isn't useful anymore at being a co-Chef, so S&S decided to give him a last chance. They decided to give Ahmed a new job, and make him work as the cashier of the restaurant. Nevertheless, in order not to repeat their previous mistake, they decided to give him a little test to check if his counting skills are good enough for the job. The problem is as follows: \nGiven a string A of lowercase English letters, Ahmad was asked to find the number of good substrings.\nA substring A[L,\u2009R] is good if:\n\n- The length of the substring is exactly 2 and AL = AR, OR\n- The length of the substring is greater than 2,AL = AR and the substring A[L\u2009+\u20091,\u2009R\u2009-\u20091] has only one distinct letter.\n\nAnyways, Ahmed struggled trying to find a solution for the problem. Since his mathematical skills are very poor as it turned out, he decided to cheat and contacted you asking for your help. Can you help him in this challenge?\n\n-----Input-----\nThe first line of the input contains the integer T, indicating the number of test cases.\nEach of the following T lines, contains a string A.\n\n-----Output-----\nFor each test case, output a single line containing a single number, indicating the number of good substrings.\n\n-----Constraints-----\n\n- 1 \u2264 T \u2264 100 \n- 1 \u2264 |A| \u2264 105 \n- It's guaranteed that the sum of |A| over all test cases doesn't exceed 5x105. \n\n-----Example-----\nInput:\n2\na\nabba\n\nOutput:\n0\n2\n\n\n-----Explanation-----\nExample case 2. The good substrings of abba are: { bb } and { abba }.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\nfor _ in range(int(input())):\n s=input()\n count=0\n i=0\n while i (2, 1) -> (3, 1) -> (4, 1) -> (4, 2) -> (4, 3), and robot 2 can move (1, 4) -> (2, 4) -> (3, 4) -> (4, 4) -> (4, 3) -> (4, 3), they meet at cell (4, 3) after 5 moves.\nExample case 2. Because the movable range of both robots is 1, robot 1 can not move from (3, 1) to (4, 2), and robot 2 can not move from (3, 4) to (4, 3. Hence, they can not meet each other.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nimport sys\n\ndef spaces(a,n,m,k,visit1,visit2,dist,position):\n queue = [position]\n lastedit = []\n dist[position[0]][position[1]] = 0 \n while queue!=[]:\n point = queue[0]\n i = point[0]\n j = point[1]\n #print 'point',i,j\n if visit1[i][j]==False:\n visit1[i][j] = True\n startx = max(i-k,0)\n endx = min(i+k,n-1)\n for x in range(startx,endx+1):\n starty = max(0,j+abs(x-i)-k)\n endy = min(m-1,j-abs(x-i)+k)\n for y in range(starty,endy+1):\n if (a[x][y]==0 and visit1[x][y]==False):\n if visit2[x][y]==True:\n lastedit.append([x,y])\n #print x,y,\n if dist[x][y]>dist[i][j]+1:\n dist[x][y]=dist[i][j]+1\n queue.append([x,y])\n #print queue,dist\n queue = queue[1:]\n #print\n return lastedit\n\nfor t in range(int(input())):\n n,m,k1,k2 = list(map(int,input().split()))\n a = []\n for i in range(n):\n a.append(list(map(int,input().split())))\n #print a\n value = sys.maxsize\n listing = []\n visit1 = [[False for i in range(m)]for j in range(n)]\n visit2 = [[False for i in range(m)]for j in range(n)]\n dist1 = [[sys.maxsize for i in range(m)]for j in range(n)]\n dist2 = [[sys.maxsize for i in range(m)]for j in range(n)]\n if k1>=k2:\n spaces(a,n,m,k1,visit1,visit2,dist1,[0,0])\n else:\n spaces(a,n,m,k2,visit1,visit2,dist1,[0,m-1])\n listing = spaces(a,n,m,k1,visit2,visit1,dist2,[0,0])\n if k1>k2:\n listing = spaces(a,n,m,k2,visit2,visit1,dist2,[0,m-1])\n #print visit1\n #sprint visit2\n if k1==k2:\n if dist1[0][m-1]==sys.maxsize:\n print('-1')\n else:\n print(int((dist1[0][m-1]+1)/2))\n else:\n d = len(listing)\n for i in range(d-1,-1,-1):\n x = listing[i][0]\n y = listing[i][1]\n if visit1[x][y]==True and dist2[x][y]dist[i][j]+1:\n dist[x][y]=dist[i][j]+1\n queue.append([x,y])\n #print queue,dist\n queue = queue[1:]\n #print\n return lastedit\n\nfor t in range(int(input())):\n n,m,k1,k2 = list(map(int,input().split()))\n a = []\n for i in range(n):\n a.append(list(map(int,input().split())))\n #print a\n value = sys.maxsize\n listing = []\n visit1 = [[False for i in range(m)]for j in range(n)]\n visit2 = [[False for i in range(m)]for j in range(n)]\n dist1 = [[sys.maxsize for i in range(m)]for j in range(n)]\n dist2 = [[sys.maxsize for i in range(m)]for j in range(n)]\n if k1>=k2:\n spaces(a,n,m,k1,visit1,visit2,dist1,[0,0])\n else:\n spaces(a,n,m,k2,visit1,visit2,dist1,[0,m-1])\n listing = spaces(a,n,m,k1,visit2,visit1,dist2,[0,0])\n if k1>k2:\n listing = spaces(a,n,m,k2,visit2,visit1,dist2,[0,m-1])\n #print visit1\n #sprint visit2\n if k1==k2:\n if dist1[0][m-1]==sys.maxsize:\n print('-1')\n else:\n print(int((dist1[0][m-1]+1)/2))\n else:\n d = len(listing)\n for i in range(d-1,-1,-1):\n x = listing[i][0]\n y = listing[i][1]\n if visit1[x][y]==True and dist2[x][y] max:\n max = i.count(X)\n ans = i\n return ans\n\n\n\nfor i in range(T):\n N = int(input())\n A = list(map(str,input().split()))\n X = input()\n print(call_me(N,A,X))\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n5\\n345 1323 165 98 456\\n3\\n5\\n335 876 98 1323 349\\n3\\n', 'output': '1323\\n335\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/CFSN2015/problems/LINNUM'}","problem_id":"vfc_4738","program":"```python\nT = int(input())\n\ndef call_me(N,A,X):\n max = 0\n ans = ''\n for i in A:\n if i.count(X) > max:\n max = i.count(X)\n ans = i\n return ans\n\n\n\nfor i in range(T):\n N = int(input())\n A = list(map(str,input().split()))\n X = input()\n print(call_me(N,A,X))\n\n```","inputs":"2\n5\n345 1323 165 98 456\n3\n5\n335 876 98 1323 349\n3\n","output":"1323\n335\n","actual_output":"1323\n335\n","execution_success":true,"sample_index":1062},{"source":"apps","task_type":"verifiable_code","in_source_id":"1475","prompt":"Solve the following coding problem using the programming language python:\n\nAbhiram needs to search for an antidote. He comes to know that clue for finding the antidote is carefully hidden by KrishnaMurthy in the form of a puzzle.\n\nThe puzzle consists of a string S and a keywordK. Abhiram needs to find the string of position of anagrams R of the keyword in the string which is the clue. \nThe antidote is found in the box numbered R. Help him find his clue R.\nAnagram: A word or phrase that is made by arranging the letters of another word or phrase in a different order. Eg: 'elvis' and 'lives' are both anagrams of each other.\nNote: Consider, Tac and act are not anagrams(case sensitive).\n\n-----Input:-----\nThe first line contains a string S of length land the second line contains a keyword K.\n\n-----Output:-----\n\nOutput contains a line\"The antidote is found in R.\" Where R= string of positions of anagrams.(the position of the first word in the string is 1).\n\n-----Constraints:-----\n1<=l<=500\n\n1<=k<=50\n\n-----Example:-----\nInput:\ncat is the act of tac\ncat\n\nOutput:\nThe antidote is found in 46.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nx = input().split(\" \")\ny = input()\nans = ''\nl = 1\nfor i in x:\n if i!=y and sorted(i) == sorted(y):\n ans = ans + (str)(l)\n l=l+1\nans+='.'\nprint(\"The antidote is found in\",ans)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': 'cat is the act of tac\\ncat\\n', 'output': 'The antidote is found in 46.\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/ITRA2016/problems/ITRA10'}","problem_id":"vfc_4742","program":"```python\nx = input().split(\" \")\ny = input()\nans = ''\nl = 1\nfor i in x:\n if i!=y and sorted(i) == sorted(y):\n ans = ans + (str)(l)\n l=l+1\nans+='.'\nprint(\"The antidote is found in\",ans)\n```","inputs":"cat is the act of tac\ncat\n","output":"The antidote is found in 46.\n","actual_output":"The antidote is found in 46.\n","execution_success":true,"sample_index":1063},{"source":"apps","task_type":"verifiable_code","in_source_id":"1477","prompt":"Solve the following coding problem using the programming language python:\n\nYou have a string S consisting of N uppercase English letters. You are allowed to perform at most one operation of following kind: Choose any position in the string, remove the character at that position and insert it back to any other place in the string.\n\nFind the lexicographically smallest string you can achieve.\n\n-----Input-----\nThe first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.\nThe first line of each test case contains the single integer N denoting length of string S.\nThe second line contains the string S.\n\n-----Output-----\nFor each test case, output a single line containing the answer to the corresponding test case.\n\n-----Constraints-----\n- 1 \u2264 T \u2264 50\n- 1 \u2264 N \u2264 50\n- S will consist of uppercase English letters.\n\n-----Example-----\nInput:\n2\n4\nDCBA\n7\nXYZZYZZ\n\nOutput:\nADCB\nXYYZZZZ\n\n-----Explanation-----\nExample case 1. The optimal solution here is to choose the last character and put it in the beginning of the string. So the answer will be ADCB\nExample case 2. The optimal solution here is to choose the 5-th character (1-based index) and put it between the 2-nd and the 3-rd characters. So the answer will be XYYZZZZ\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfor _1 in range(int(input())):\n n=int(input())\n s=input().strip()\n answer=s\n for i in range(len(s)):\n c=s[i]\n string=s[:i]+s[i+1:]\n for j in range(len(string)+1):\n answer=min(answer, string[:j]+c+string[j:])\n print(answer)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n4\\nDCBA\\n7\\nXYZZYZZ\\n', 'output': 'ADCB\\nXYYZZZZ\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/DIVGOLD'}","problem_id":"vfc_4750","program":"```python\nfor _1 in range(int(input())):\n n=int(input())\n s=input().strip()\n answer=s\n for i in range(len(s)):\n c=s[i]\n string=s[:i]+s[i+1:]\n for j in range(len(string)+1):\n answer=min(answer, string[:j]+c+string[j:])\n print(answer)\n```","inputs":"2\n4\nDCBA\n7\nXYZZYZZ\n","output":"ADCB\nXYYZZZZ\n","actual_output":"ADCB\nXYYZZZZ\n","execution_success":true,"sample_index":1065},{"source":"apps","task_type":"verifiable_code","in_source_id":"1478","prompt":"Solve the following coding problem using the programming language python:\n\nLet's define a periodic infinite sequence S$S$ (0$0$-indexed) with period K$K$ using the formula Si=(i%K)+1$S_i = (i \\% K) + 1$.\nChef has found a sequence of positive integers A$A$ with length N$N$ buried underground. He suspects that it is a contiguous subsequence of some periodic sequence. Unfortunately, some elements of A$A$ are unreadable. Can you tell Chef the longest possible period K$K$ of an infinite periodic sequence which contains A$A$ (after suitably filling in the unreadable elements) as a contiguous subsequence?\n\n-----Input-----\n- 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.\n- The first line of each test case contains a single integer N$N$. \n- The second line contains N$N$ space-separated integers A1,A2,\u2026,AN$A_1, A_2, \\dots, A_N$. Unreadable elements are denoted by \u22121$-1$.\n\n-----Output-----\nFor each test case, print a single line.\n- If the period can be arbitrarily large, this line should contain a single string \"inf\".\n- Otherwise, if A$A$ cannot be a contiguous subsequence of a periodic sequence, it should contain a single string \"impossible\".\n- Otherwise, it should contain a single integer \u2014 the maximum possible period.\n\n-----Constraints-----\n- 1\u2264T\u2264100$1 \\le T \\le 100$\n- 2\u2264N\u2264105$2 \\le N \\le 10^5$\n- the sum of N$N$ over all test cases does not exceed 106$10^6$\n- for each valid i$i$, 1\u2264Ai\u2264106$1 \\le A_i \\le 10^6$ or Ai=\u22121$A_i = -1$\n\n-----Subtasks-----\nSubtask #1 (50 points):\n- 2\u2264N\u22641,000$2 \\le N \\le 1,000$\n- the sum of N$N$ over all test cases does not exceed 10,000$10,000$\nSubtask #2 (50 points): original constraints\n\n-----Example Input-----\n3\n3\n-1 -1 -1\n5\n1 -1 -1 4 1\n4\n4 6 7 -1\n\n-----Example Output-----\ninf\n4\nimpossible\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\nfrom math import gcd\nfor _ in range(int(input())):\n n,a,k,min_k,e = int(input()),[int(i) for i in input().split()],0,0,-1 \n for j in range(n):\n if(a[j] != -1):break \n for i in range(j,n):\n if min_k==0:min_k,e = a[i],a[i]+1 \n else:\n if min_k < a[i]:min_k = a[i] \n if(a[i] == -1):pass\n else:\n if(a[i] == e):pass\n else:\n if( k == 0):k = e-a[i]\n else:\n new_k = e-a[i]\n if(new_k < 0):k = -1\n else:k = gcd(k,new_k)\n if(ka[x-1]:\n a[x-1]=y\n print(sum(a))\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n5\\n2 45\\n9 100\\n8 0\\n2 15\\n8 90\\n1\\n11 1\\n', 'output': '135\\n0\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/WATSCORE'}","problem_id":"vfc_4758","program":"```python\n# cook your dish here\np=int(input())\nfor z in range(p):\n n=int(input())\n a=[]\n for i in range(8):\n a.append(0)\n for i in range(n):\n x,y=list(map(int,input().split()))\n if x<=8 and y>a[x-1]:\n a[x-1]=y\n print(sum(a))\n\n```","inputs":"2\n5\n2 45\n9 100\n8 0\n2 15\n8 90\n1\n11 1\n","output":"135\n0\n","actual_output":"135\n0\n","execution_success":true,"sample_index":1067},{"source":"apps","task_type":"verifiable_code","in_source_id":"1480","prompt":"Solve the following coding problem using the programming language python:\n\nThere are n cabs in a city numbered from 1 to n. The city has a rule that only one cab can run in the city at a time. Cab picks up the customer and drops him to his destination. Then the cab gets ready to pick next customer. There are m customers in search of cab. First customer will get the taxi first. You have to find the nearest cab for each customer. If two cabs have same distance then the cab with lower number is preferred.\n\nYour task is to find out minimum distant cab for each customer.\n\nInput:\n\nThe first line of the input contains an integer T denoting the number of test cases.\nThe description of T test cases follows.\nThe first line of each test case contains two space-separated integers N and M, denoting the number of cabs and the number of customers.\n\nThe next N lines contain two space-separated integers x[i] and y[i], denoting the initial position of the ith cab.\n\nNext line contains an integer M denoting number of customers.\nThe next M lines contain four space seperated integers sx[i], sy[i], dx[i], dy[i], denoting the current location and the destination of the ith customer.\n\nOutput:\n\nOutput the nearest cab number for each customer.\n\nConstraints:\n\n1<=t<=10\n\n1<=n,m<=1000\n\n-10^9<=x[i] , y[i] , sx[i] , sy[i] , dx[i] , dy[i]<=10^9\n\nExample:\nInput:\n\n1\n\n3 2\n\n1 3\n\n3 2\n\n3 5\n\n2 3 3 4\n\n5 3 4 1\n\nOutput:\n\n1\n\n1\n\nExplanation:\n\nThe distance of cab1 from customer1 = sqrt((1-2)^2 + (3-3)^2) = 1\n\nThe distance of cab2 from customer1 = sqrt(2)\n\nThe distance of cab3 from customer1 = sqrt(5)\n\nSo output for customer1 is 1\n\nNow location of cab1 is (3,4)\n\nThe distance of cab1 from customer2 = sqrt((3-5)^2 + (4-3)^2) = sqrt(5)\n\nThe distance of cab2 from customer2 = sqrt(5)\n\nThe distance of cab3 from customer2 = sqrt(8)\n\nSo output for customer2 is 1\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nimport math\ndef dist(w,x,y,z):\n return math.hypot(y - w, z - x)\n\nt = int(input())\nwhile (t>0):\n t = t -1\n n, m = list(map(int,input().split()))\n a = []\n for i in range(0,n):\n x,y = list(map(int,input().split()))\n a.append([x,y])\n for j in range(0,m):\n p,q,r,s = list(map(int,input().split()))\n nearest = -1\n distance = 10000000000\n for i in range(0,n):\n way = dist(a[i][0],a[i][1],p,q)\n if way < distance:\n distance = way\n nearest = i\n print(nearest + 1)\n a[nearest][0] = r\n a[nearest][1] = s\n\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n3 2\\n1 3\\n3 2\\n3 5\\n2 3 3 4\\n5 3 4 1\\n', 'output': '1\\n1\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/SIC2016/problems/NEAR'}","problem_id":"vfc_4762","program":"```python\nimport math\ndef dist(w,x,y,z):\n return math.hypot(y - w, z - x)\n\nt = int(input())\nwhile (t>0):\n t = t -1\n n, m = list(map(int,input().split()))\n a = []\n for i in range(0,n):\n x,y = list(map(int,input().split()))\n a.append([x,y])\n for j in range(0,m):\n p,q,r,s = list(map(int,input().split()))\n nearest = -1\n distance = 10000000000\n for i in range(0,n):\n way = dist(a[i][0],a[i][1],p,q)\n if way < distance:\n distance = way\n nearest = i\n print(nearest + 1)\n a[nearest][0] = r\n a[nearest][1] = s\n\n\n```","inputs":"1\n3 2\n1 3\n3 2\n3 5\n2 3 3 4\n5 3 4 1\n","output":"1\n1\n","actual_output":"1\n1\n","execution_success":true,"sample_index":1068},{"source":"apps","task_type":"verifiable_code","in_source_id":"1481","prompt":"Solve the following coding problem using the programming language python:\n\nA binary string is called a self-destructing string if it can reduced to an empty string by performing the following operation some number of times (possibly zero): Choose a valid integer $i$ such that the $i$-th character of the current string is different from the $i+1$-th character, and remove these two characters from the string.\nYou are given a binary string $s$. Your task is to convert $s$ to a self-destructing string. To do that, you may perform the following operation any number of times (possibly zero): Choose an integer $i$ ($1 \\le i \\le |s|-1$) such that the $i$-th character of $s$ is different from the $i+1$-th character, and invert one of these characters (inverting a character means changing '0' to '1' or '1' to '0', e.g. the string \"01\" can be changed to \"00\").\nFind the smallest number of operations required to convert $s$ to a self-destructing string or determine that it is impossible.\n\n-----Input-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The first and only line of each test case contains a single string $s$.\n\n-----Output-----\nFor each test case, print a single line containing one integer \u2015 the smallest required number of operations or $-1$ if it is impossible to convert $s$ to a self-destructing string.\n\n-----Constraints-----\n- $1 \\le T \\le 1,000$\n- $1 \\le |s| \\le 10^6$\n- $s$ contains only characters '0' and '1'\n- the sum of $|s|$ over all test cases does not exceed $10^6$\n\n-----Example Input-----\n3\n001101\n1101\n110\n\n-----Example Output-----\n0\n1\n-1\n\n-----Explanation-----\nExample case 1: We already have a self-destructing string because \"001101\" can be converted to \"0101\", to \"01\" and finally to an empty string.\nExample case 2: We can choose $i=3$ (since $s_3 \\neq s_4$) and then invert $s_4$ to obtain \"1100\", which is a self-destructing string.\nExample case 3: It can be shown that \"110\" cannot be converted to a self-destructing string.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nt=int(input())\nfor i in range(t):\n s=input()\n zeroes=s.count('0')\n ones=s.count('1')\n if (len(s)%2==1 or zeroes==0 or ones==0):\n ans= -1\n else:\n ans=abs(zeroes-ones)//2\n print(ans) \n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\n001101\\n1101\\n110\\n', 'output': '0\\n1\\n-1\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/SDSTRING'}","problem_id":"vfc_4766","program":"```python\nt=int(input())\nfor i in range(t):\n s=input()\n zeroes=s.count('0')\n ones=s.count('1')\n if (len(s)%2==1 or zeroes==0 or ones==0):\n ans= -1\n else:\n ans=abs(zeroes-ones)//2\n print(ans) \n```","inputs":"3\n001101\n1101\n110\n","output":"0\n1\n-1\n","actual_output":"0\n1\n-1\n","execution_success":true,"sample_index":1069},{"source":"apps","task_type":"verifiable_code","in_source_id":"1482","prompt":"Solve the following coding problem using the programming language python:\n\nChef's company wants to make ATM PINs for its users, so that they could use the PINs for withdrawing their hard-earned money. One of these users is Reziba, who lives in an area where a lot of robberies take place when people try to withdraw their money. \nChef plans to include a safety feature in the PINs: if someone inputs the reverse of their own PIN in an ATM machine, the Crime Investigation Department (CID) are immediately informed and stop the robbery. However, even though this was implemented by Chef, some people could still continue to get robbed. The reason is that CID is only informed if the reverse of a PIN is different from that PIN (so that there wouldn't be false reports of robberies).\nYou know that a PIN consists of $N$ decimal digits. Find the probability that Reziba could get robbed. Specifically, it can be proven that this probability can be written as a fraction $P/Q$, where $P \\ge 0$ and $Q > 0$ are coprime integers; you should compute $P$ and $Q$.\n\n-----Input-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The first and only line of each test case contains a single integer $N$ denoting the length of each PIN. \n\n-----Output-----\nFor each test case, print a single line containing two space-separated integers \u2014 the numerator $P$ and denominator $Q$ of the probability.\n\n-----Constraints-----\n- $1 \\le T \\le 100$\n- $1 \\le N \\le 10^5$\n\n-----Subtasks-----\nSubtask #1 (10 points): $N \\le 18$\nSubtask #2 (20 points): $N \\le 36$\nSubtask #3 (70 points): original constraints\n\n-----Example Input-----\n1\n1\n\n-----Example Output-----\n1 1\n\n-----Explanation-----\nExample case 1: A PIN containing only one number would fail to inform the CID, since when it's input in reverse, the ATM detects the same PIN as the correct one. Therefore, Reziba can always get robbed \u2014 the probability is $1 = 1/1$.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfor i in range(int(input())):\n n = int(input())\n q = \"1\"+\"0\"*(n//2)\n print(1,q)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n1\\n', 'output': '1 1\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/PINS'}","problem_id":"vfc_4770","program":"```python\nfor i in range(int(input())):\n n = int(input())\n q = \"1\"+\"0\"*(n//2)\n print(1,q)\n```","inputs":"1\n1\n","output":"1 1\n","actual_output":"1 1\n","execution_success":true,"sample_index":1070},{"source":"apps","task_type":"verifiable_code","in_source_id":"1484","prompt":"Solve the following coding problem using the programming language python:\n\nYoung Sheldon is given the task to teach Chemistry to his brother Georgie. After teaching him how to find total atomic weight, Sheldon gives him some formulas which consist of $x$, $y$ and $z$ atoms as an assignment. \nYou already know that Georgie doesn't like Chemistry, so he want you to help him solve this assignment.\nLet the chemical formula be given by the string $S$. It consists of any combination of x, y and z with some value associated with it as well as parenthesis to encapsulate any combination. Moreover, the atomic weight of x, y and z are 2, 4 and 10 respectively.\nYou are supposed to find the total atomic weight of the element represented by the given formula.\nFor example, for the formula $(x_2y_2)_3z$, given string $S$ will be: $(x2y2)3z$. Hence, substituting values of x, y and z, total atomic weight will be \n$(2*2+4*2)*3 + 10 = 46$.\n\n-----Input:-----\n- First line will contain $T$, number of testcases. Then the testcases follow. \n- Each testcase contains of a single line of input $S$. \n\n-----Output:-----\nFor each testcase, output in a single line, the total atomic weight.\n\n-----Constraints-----\n- $1 \\leq T \\leq 100$\n- Length of string $S \\leq 100$\n- String contains $x, y, z, 1, 2,..., 9$ and parenthesis\n\n-----Sample Input:-----\n2\n(xy)2\nx(x2y)3(z)2\n\n-----Sample Output:-----\n12\n46\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfor _ in range(int(input())):\n s = list(input().strip())\n\n i = 0\n\n while i < len(s) - 1:\n if s[i].isalpha() or s[i] == ')':\n if s[i + 1].isdigit():\n if i + 2 >= len(s) or s[i + 2] == ')':\n s = s[:i+1] + ['*', s[i+1]] + s[i+2:]\n else:\n s = s[:i+1] + ['*', s[i+1], '+'] + s[i+2:]\n i += 1\n elif s[i + 1].isalpha() or s[i + 1] == '(':\n s = s[:i+1] + ['+'] + s[i+1:]\n\n i += 1\n\n s = ''.join(s)\n\n s = s.strip('+')\n\n x = 2\n y = 4\n z = 10\n\n print(eval(s))\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n(xy)2\\nx(x2y)3(z)2\\n', 'output': '12\\n46\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/CORS2020/problems/PENEVAL'}","problem_id":"vfc_4778","program":"```python\nfor _ in range(int(input())):\n s = list(input().strip())\n\n i = 0\n\n while i < len(s) - 1:\n if s[i].isalpha() or s[i] == ')':\n if s[i + 1].isdigit():\n if i + 2 >= len(s) or s[i + 2] == ')':\n s = s[:i+1] + ['*', s[i+1]] + s[i+2:]\n else:\n s = s[:i+1] + ['*', s[i+1], '+'] + s[i+2:]\n i += 1\n elif s[i + 1].isalpha() or s[i + 1] == '(':\n s = s[:i+1] + ['+'] + s[i+1:]\n\n i += 1\n\n s = ''.join(s)\n\n s = s.strip('+')\n\n x = 2\n y = 4\n z = 10\n\n print(eval(s))\n\n```","inputs":"2\n(xy)2\nx(x2y)3(z)2\n","output":"12\n46\n","actual_output":"12\n46\n","execution_success":true,"sample_index":1072},{"source":"apps","task_type":"verifiable_code","in_source_id":"1485","prompt":"Solve the following coding problem using the programming language python:\n\nChef has a pepperoni pizza in the shape of a $N \\times N$ grid; both its rows and columns are numbered $1$ through $N$. Some cells of this grid have pepperoni on them, while some do not. Chef wants to cut the pizza vertically in half and give the two halves to two of his friends. Formally, one friend should get everything in the columns $1$ through $N/2$ and the other friend should get everything in the columns $N/2+1$ through $N$.\nBefore doing that, if Chef wants to, he may choose one row of the grid and reverse it, i.e. swap the contents of the cells in the $i$-th and $N+1-i$-th column in this row for each $i$ ($1 \\le i \\le N/2$).\nAfter the pizza is cut, let's denote the number of cells containing pepperonis in one half by $p_1$ and their number in the other half by $p_2$. Chef wants to minimise their absolute difference. What is the minimum value of $|p_1-p_2|$?\n\n-----Input-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The first line of each test case contains a single integer $N$.\n- $N$ lines follow. For each $i$ ($1 \\le i \\le N$), the $i$-th of these lines contains a string with length $N$ describing the $i$-th row of the grid; this string contains only characters '1' (denoting a cell with pepperonis) and '0' (denoting a cell without pepperonis).\n\n-----Output-----\nFor each test case, print a single line containing one integer \u2014 the minimum absolute difference between the number of cells with pepperonis in the half-pizzas given to Chef's friends.\n\n-----Constraints-----\n- $1 \\le T \\le 1,000$\n- $2 \\le N \\le 1,000$\n- $N$ is even\n- the sum of $N \\cdot N$ over all test cases does not exceed $2 \\cdot 10^6$\n\n-----Example Input-----\n2\n6\n100000\n100000\n100000\n100000\n010010\n001100\n4\n0011\n1100\n1110\n0001\n\n-----Example Output-----\n2\n0\n\n-----Explanation-----\nExample case 1: Initially, $|p_1-p_2| = 4$, but if Chef reverses any one of the first four rows from \"100000\" to \"000001\", $|p_1-p_2|$ becomes $2$.\nExample case 2: Initially, $|p_1-p_2| = 0$. We cannot make that smaller by reversing any row.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\nfor _ in range(int(input())):\n n=int(input())\n l1=[]\n l2=[]\n \n for i in range(n):\n s=input()\n a=s[ :n//2].count('1')\n b=s[n//2: ].count('1')\n if a>b:\n l1.append(a-b)\n \n elif aq:\n diff=p-q\n flag=0\n for i in range(diff//2, 0, -1):\n a=diff-i\n if (i in l1) or (a in l1):\n print(abs(a-i))\n flag=1\n break\n \n if flag==0:\n print(diff)\n \n else:\n diff=q-p\n flag=0\n for i in range(diff//2, 0, -1):\n a=diff-i\n if (i in l2) or (a in l2):\n print(abs(a-i))\n flag=1\n break\n \n if flag==0:\n print(diff)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n6\\n100000\\n100000\\n100000\\n100000\\n010010\\n001100\\n4\\n0011\\n1100\\n1110\\n0001\\n', 'output': '2\\n0\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/PEPPERON'}","problem_id":"vfc_4782","program":"```python\n# cook your dish here\nfor _ in range(int(input())):\n n=int(input())\n l1=[]\n l2=[]\n \n for i in range(n):\n s=input()\n a=s[ :n//2].count('1')\n b=s[n//2: ].count('1')\n if a>b:\n l1.append(a-b)\n \n elif aq:\n diff=p-q\n flag=0\n for i in range(diff//2, 0, -1):\n a=diff-i\n if (i in l1) or (a in l1):\n print(abs(a-i))\n flag=1\n break\n \n if flag==0:\n print(diff)\n \n else:\n diff=q-p\n flag=0\n for i in range(diff//2, 0, -1):\n a=diff-i\n if (i in l2) or (a in l2):\n print(abs(a-i))\n flag=1\n break\n \n if flag==0:\n print(diff)\n```","inputs":"2\n6\n100000\n100000\n100000\n100000\n010010\n001100\n4\n0011\n1100\n1110\n0001\n","output":"2\n0\n","actual_output":"2\n0\n","execution_success":true,"sample_index":1073},{"source":"apps","task_type":"verifiable_code","in_source_id":"1487","prompt":"Solve the following coding problem using the programming language python:\n\nChef has $N$ boxes arranged in a line.Each box has some candies in it,say $C[i]$. Chef wants to distribute all the candies between of his friends: $A$ and $B$, in the following way:\n$A$ starts eating candies kept in the leftmost box(box at $1$st place) and $B$ starts eating candies kept in the rightmost box(box at $N$th place). $A$ eats candies $X$ times faster than $B$ i.e. $A$ eats $X$ candies when $B$ eats only $1$. Candies in each box can be eaten by only the person who reaches that box first. If both reach a box at the same time, then the one who has eaten from more number of BOXES till now will eat the candies in that box. If both have eaten from the same number of boxes till now ,then $A$ will eat the candies in that box.\nFind the number of boxes finished by both $A$ and $B$.\nNOTE:- We assume that it does not take any time to switch from one box to another.\n\n-----Input:-----\n- First line will contain $T$, number of testcases. Then the testcases follow. \n- Each testcase contains three lines of input.\nThe first line of each test case contains $N$, the number of boxes.\n- The second line of each test case contains a sequence,$C_1$ ,$C_2$ ,$C_3$ . . . $C_N$ where $C_i$ denotes the number of candies in the i-th box. \n- The third line of each test case contains an integer $X$ .\n\n-----Output:-----\nFor each testcase, print two space separated integers in a new line - the number of boxes eaten by $A$ and $B$ respectively. \n\n-----Constraints-----\n- $1 \\leq T \\leq 100$\n- $1 \\leq N \\leq 200000$\n- $1 \\leq C_i \\leq 1000000$\n- $1 \\leq X \\leq 10$\n- Sum of $N$ over all test cases does not exceed $300000$\n\n-----Subtasks-----\nSubtask 1(24 points):\n- $1 \\leq T \\leq 10$\n- $1 \\leq N \\leq 1000$\n- $1 \\leq C_i \\leq 1000$\n- $1 \\leq X \\leq 10$\nSubtask 2(51 points): original constraints\n\n-----Sample Input:-----\n1\n5\n2 8 8 2 9\n2\n\n-----Sample Output:-----\n4 1\n\n-----EXPLANATION:-----\n$A$ will start eating candies in the 1st box(leftmost box having 2 candies) . $B$ will start eating candies in the 5th box(rightmost box having 9 candies) .As $A's$ speed is 2 times as that of $B's$, $A$ will start eating candies in the 2nd box while $B$ would still be eating candies in the 5th box.$A$ will now start eating candies from the 3rd box while $B$ would still be eating candies in the 5th box.Now both $A$ and $B$ will finish candies in their respective boxes at the same time($A$ from the 3rd box and $B$ from 5th box). Since $A$ has eaten more number of boxes($A$ has eaten 3 boxes while $B$ has eaten 1 box) till now,so $A$ will be eating candies in the 4th box.\nHence $A$ has eaten 4 boxes and $B$ has eaten 1 box.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nimport sys\n\n# stdin = open(\"testdata.txt\", \"r\")\nip = sys.stdin \n\ndef solve(C, n, x):\n if n==1:\n return (1, 0)\n\n b1, b2 = 1, 1\n a , b = C[0], C[-1]\n while b1 + b2 < n:\n if a < b*x:\n a += C[b1]\n b1 += 1\n elif a > b*x:\n b2 += 1\n b += C[n-b2] \n else:\n if b1 >= b2:\n a += C[b1]\n b1 += 1\n else:\n b2 += 1\n b += C[b2]\n return (b1, b2)\n\nt = int(ip.readline())\n\nfor _ in range(t):\n n = int(ip.readline())\n C = list(map(int, ip.readline().split()))\n x = int(ip.readline())\n\n ans = solve(C, n, x)\n print(*ans)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n5\\n2 8 8 2 9\\n2\\n', 'output': '4 1\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/BIT2B'}","problem_id":"vfc_4790","program":"```python\nimport sys\n\n# stdin = open(\"testdata.txt\", \"r\")\nip = sys.stdin \n\ndef solve(C, n, x):\n if n==1:\n return (1, 0)\n\n b1, b2 = 1, 1\n a , b = C[0], C[-1]\n while b1 + b2 < n:\n if a < b*x:\n a += C[b1]\n b1 += 1\n elif a > b*x:\n b2 += 1\n b += C[n-b2] \n else:\n if b1 >= b2:\n a += C[b1]\n b1 += 1\n else:\n b2 += 1\n b += C[b2]\n return (b1, b2)\n\nt = int(ip.readline())\n\nfor _ in range(t):\n n = int(ip.readline())\n C = list(map(int, ip.readline().split()))\n x = int(ip.readline())\n\n ans = solve(C, n, x)\n print(*ans)\n```","inputs":"1\n5\n2 8 8 2 9\n2\n","output":"4 1\n","actual_output":"4 1\n","execution_success":true,"sample_index":1075},{"source":"apps","task_type":"verifiable_code","in_source_id":"1488","prompt":"Solve the following coding problem using the programming language python:\n\nYou have a sequence $a$ with length $N$ created by removing some elements (possibly zero) from a permutation of numbers $(1, 2, \\dots, N)$. When an element is removed, the length of the sequence doesn't change, but there is an empty spot left where the removed element was. You also have an integer $K$.\nLet's call a permutation $p_1, p_2, \\dots, p_N$ good if:\n- it is possible replace empty spots in $a$ by numbers in such a way that we obtain the permutation $p$\n- the number of positions $i$ ($1 < i \\le N$) such that $p_i > p_{i-1}$ is equal to $K$\nYour task is to find the number of good permutations.\n\n-----Input-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The first line of each test case contains two space-separated integers $N$ and $K$.\n- The second line contains $N$ space-separated integers $a_1, a_2, \\dots, a_N$. Each element of this sequence is either $0$ (indicating an empty spot previously occupied by a removed element) or an integer between $1$ and $N$ inclusive.\n\n-----Output-----\nFor each test case, print a single line containing one integer \u2014 the number of good permutations.\n\n-----Constraints-----\n- $1 \\le T \\le 300$\n- $0 \\le K < N \\le 8$\n- each integer between $1$ and $N$ inclusive appears in $a$ at most once\n\n-----Example Input-----\n1\n3 1\n2 0 0\n\n-----Example Output-----\n2\n\n-----Explanation-----\nExample case 1: The two possible good permutations are $(2,3,1)$ and $(2,1,3)$.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfrom itertools import permutations\n\nfor _ in range(int(input())):\n N,K=list(map(int,input().split()))\n arr=list(map(int,input().split()))\n arr1=[]\n arr2=[]\n for i in range(1,len(arr)+1):\n arr1.append(i)\n indexzero=[]\n for i in range(0,len(arr)):\n if(arr[i]==0):\n indexzero.append(i)\n else:\n arr2.append(arr[i])\n # arr3 = [x for x in arr1 if x not in arr2]\n arr3= list(set(arr1)-set(arr2))\n result=permutations(arr3)\n perm=[]\n for i in result:\n perm.append(i)\n step=0\n count=0\n for p in range(0,len(perm)):\n temp=[]\n for q in range(0,len(arr)):\n if(arr[q]==0):\n temp.append(perm[p][step])\n step+=1 \n else:\n temp.append(arr[q])\n k=0\n step=0\n for m in range(0,len(temp)-1):\n if(temp[m]p):\r\n print(maxx)\r\n else:\r\n q=p-maxx*2\r\n maxx+=ceil(q/2)\r\n print(maxx)\r\n \r\n \r\n \r\n\r\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n10\\n178 184 178 177 171 173 171 183 171 175\\n', 'output': '5\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/COFY2020/problems/GKSMNRSK'}","problem_id":"vfc_4802","program":"```python\nfrom math import ceil\r\nt=int(input())\r\nfor i in range(t):\r\n p=int(input())\r\n l=list(map(int,input().split()))\r\n maxx=1\r\n for i in range(len(l)):\r\n maxx=max(maxx,l.count(l[i]))\r\n if(maxx*2>p):\r\n print(maxx)\r\n else:\r\n q=p-maxx*2\r\n maxx+=ceil(q/2)\r\n print(maxx)\r\n \r\n \r\n \r\n\r\n\n```","inputs":"1\n10\n178 184 178 177 171 173 171 183 171 175\n","output":"5\n","actual_output":"5\n","execution_success":true,"sample_index":1078},{"source":"apps","task_type":"verifiable_code","in_source_id":"1491","prompt":"Solve the following coding problem using the programming language python:\n\nChef recently learned about ratios and proportions. He wrote some positive integers a, b, c, d on a paper. Chef wants to know whether he can shuffle these numbers so as to make some proportion? Formally, four numbers x, y, z, w are said to make a proportion if ratio of x : y is same as that of z : w.\n\n-----Input-----\nOnly line of the input contains four space separated positive integers - a, b, c, d.\n\n-----Output-----\nPrint \"Possible\" if it is possible to shuffle a, b, c, d to make proportion, otherwise \"Impossible\" (without quotes).\n\n-----Constraints-----\n- 1 \u2264 a, b, c, d \u2264 1000\n\n-----Example-----\nInput:\n1 2 4 2\n\nOutput:\nPossible\n\n-----Explanation-----\nBy swapping 4 and the second 2, we get 1 2 2 4. Note that 1 2 2 4 make proportion as 1 : 2 = 2 : 4. Hence answer is \"Possible\"\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\ndef permutate(arr):\n if len(arr) == 1:\n yield arr\n for x in range(len(arr)):\n for perm in permutate(arr[:x] + arr[x+1:]):\n yield [arr[x]] + perm\n\nvals = [int(x) for x in input().split()]\n\nfounded = False\nfor val in permutate(vals):\n if (val[0] / float(val[1]) == val[2] / float(val[3])):\n print(\"Possible\")\n founded = True \n break\nif not founded:\n print(\"Impossible\")\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1 2 4 2\\n', 'output': 'Possible\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/COOK72/problems/CHEFCBA'}","problem_id":"vfc_4806","program":"```python\ndef permutate(arr):\n if len(arr) == 1:\n yield arr\n for x in range(len(arr)):\n for perm in permutate(arr[:x] + arr[x+1:]):\n yield [arr[x]] + perm\n\nvals = [int(x) for x in input().split()]\n\nfounded = False\nfor val in permutate(vals):\n if (val[0] / float(val[1]) == val[2] / float(val[3])):\n print(\"Possible\")\n founded = True \n break\nif not founded:\n print(\"Impossible\")\n\n```","inputs":"1 2 4 2\n","output":"Possible\n","actual_output":"Possible\n","execution_success":true,"sample_index":1079},{"source":"apps","task_type":"verifiable_code","in_source_id":"1492","prompt":"Solve the following coding problem using the programming language python:\n\nDevu is a disastrous oracle: his predictions about various events of your life are horrifying. Instead of providing good luck, he \"blesses\" you with bad luck. The secret behind his wickedness is a hidden omen which is a string of length m. On your visit to him, you can ask a lot of questions about your future, each of which should be a string of length m. In total you asked him n such questions, denoted by strings s1, s2, ... , sn of length m each. Each of the question strings is composed of the characters 'a' and 'b' only.\n\nAmount of bad luck this visit will bring you is equal to the length of longest common subsequence (LCS) of all the question strings and the hidden omen string. Of course, as the omen string is hidden, you are wondering what could be the least value of bad luck you can get.\n\nCan you find out what could be the least bad luck you can get? Find it fast, before Devu tells you any bad omens.\n\n-----Input-----\nThe first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.\nFirst line of each test case contains a single integer n denoting number of strings.\nFor each of next n lines, the ith line contains the string si.\n\n-----Output-----\nFor each test case, output a single integer corresponding to the answer of the problem. \n\n\n-----Constraints-----\n- All the strings (including the hidden omen) contain the characters 'a' and 'b' only.\n\nSubtask #1: (40 points) \n\n- 1 \u2264 T, n, m \u2264 14\n\nSubtask #2: (60 points) \n\n- 1 \u2264 T, n, m \u2264 100\n\n-----Example-----\nInput:3\n2\nab\nba\n2\naa\nbb\n3\naabb\nabab\nbaab\n\nOutput:1\n0\n2\n\n-----Explanation-----\nIn the first example, the minimum value of LCS of all the strings is 1, the string by oracle can be one of these {aa, ab, ba, bb}. \n\nIn the second example, whatever string oracle has does not matter, LCS will always be zero.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nt = int(input())\nfor j in range(0, t):\n n = int(input())\n m = 100\n for i in range(0, n):\n str = input()\n p = min(str.count(\"a\",0,len(str)),str.count(\"b\",0,len(str)))\n if (m > p):\n m = p\n print(m)\n t = t-1\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\n2\\nab\\nba\\n2\\naa\\nbb\\n3\\naabb\\nabab\\nbaab\\n', 'output': '1\\n0\\n2\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/DEC15/problems/ORACLCS'}","problem_id":"vfc_4810","program":"```python\nt = int(input())\nfor j in range(0, t):\n n = int(input())\n m = 100\n for i in range(0, n):\n str = input()\n p = min(str.count(\"a\",0,len(str)),str.count(\"b\",0,len(str)))\n if (m > p):\n m = p\n print(m)\n t = t-1\n```","inputs":"3\n2\nab\nba\n2\naa\nbb\n3\naabb\nabab\nbaab\n","output":"1\n0\n2\n","actual_output":"1\n0\n2\n","execution_success":true,"sample_index":1080},{"source":"apps","task_type":"verifiable_code","in_source_id":"1493","prompt":"Solve the following coding problem using the programming language python:\n\nDevu is a class teacher of a class of n students. One day, in the morning prayer of the school, all the students of his class were standing in a line. You are given information of their arrangement by a string s. The string s consists of only letters 'B' and 'G', where 'B' represents a boy and 'G' represents a girl.\nDevu wants inter-gender interaction among his class should to be maximum. So he does not like seeing two or more boys/girls standing nearby (i.e. continuous) in the line. e.g. he does not like the arrangements BBG and GBB, but he likes BG, GBG etc.\nNow by seeing the initial arrangement s of students, Devu may get furious and now he wants to change this arrangement into a likable arrangement. For achieving that, he can swap positions of any two students (not necessary continuous). Let the cost of swapping people from position i with position j (i \u2260 j) be c(i, j). You are provided an integer variable type, then the cost of the the swap will be defined by c(i, j) = |j \u2212 i|type.\n\nPlease help Devu in finding minimum cost of swaps needed to convert the current arrangement into a likable one.\n\n-----Input-----\nThe first line of input contains an integer T, denoting the number of test cases. Then T test cases are follow.\nThe first line of each test case contains an integer type, denoting the type of the cost function. Then the next line contains string s of length n, denoting the initial arrangement s of students.\nNote that the integer n is not given explicitly in input.\n\n-----Output-----\nFor each test case, print a single line containing the answer of the test case, that is, the minimum cost to convert the current arrangement into a likable one. If it is not possible to convert the current arrangement into a likable one, then print -1 instead of the minimum cost.\n\n-----Constraints and Subtasks-----Subtask 1: 25 points\n- 1 \u2264 T \u2264 105\n- 1 \u2264 n \u2264 105\n- type = 0\n- Sum of n over all the test cases in one test file does not exceed 106. \nSubtask 2: 25 points\n- 1 \u2264 T \u2264 105\n- 1 \u2264 n \u2264 105\n- type = 1\n- Sum of n over all the test cases in one test file does not exceed 106. \nSubtask 3: 25 points\n- 1 \u2264 T \u2264 105\n- 1 \u2264 n \u2264 105\n- type = 2\n- Sum of n over all the test cases in one test file does not exceed 106. \nSubtask 4: 25 points\n- 1 \u2264 T \u2264 102\n- 1 \u2264 n \u2264 103\n- type can be 0, 1 or 2, that is type \u2208 {0, 1, 2}.\n\n-----Example-----\nInput:\n8\n0\nBB\n0\nBG\n0\nBBGG\n1\nBGG\n1\nBGGB\n1\nBBBGG\n2\nBBGG\n2\nBGB\n\nOutput:\n-1\n0\n1\n1\n1\n3\n1\n0\n\n-----Explanation-----\nNote type of the first 3 test cases is 0. So c(i, j) = 1. Hence we just have to count minimum number of swaps needed.\nExample case 1. There is no way to make sure that both the boys does not stand nearby. So answer is -1.\nExample case 2. Arrangement is already valid. No swap is needed. So answer is 0.\nExample case 3. Swap boy at position 1 with girl at position 2. After swap the arrangement will be BGBG which is a valid arrangement. So answer is 1.\nNow type of the next 3 test cases is 1. So c(i, j) = |j \u2212 i|, that is, the absolute value of the difference between i and j.\nExample case 4. Swap boy at position 0 with girl at position 1. After swap the arrangement will be GBG which is a valid arrangement. So answer is |1 - 0| = 1.\nExample case 5. Swap boy at position 0 with girl at position 1. After swap the arrangement will be GBGB which is a valid arrangement. So answer is |1 - 0| = 1.\nExample case 6. Swap boy at position 1 with girl at position 4. After swap the arrangement will be BGBGB which is a valid arrangement. So answer is |4 - 1| = 3.\nThen type of the last 2 test cases is 2. So c(i, j) = (j \u2212 i)2\nExample case 7. Swap boy at position 1 with girl at position 2. After swap the arrangement will be BGBG which is a valid arrangement. So answer is (2 - 1)2 = 1.\nExample case 8. Arrangement is already valid. No swap is needed. So answer is 0.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\ndef outOfIndex(boys,girls,COST):\n if COST == 0:\n return len(boys)\n else:\n total_cost = [ abs(x-y) for x,y in zip(boys,girls)]\n total_cost = sum(total_cost)\n return total_cost\n\nfor _ in range(int(input())):\n COST = int(input())\n queue = input()\n B = queue.count('B')\n G = queue.count('G')\n boys=[]\n girls = []\n if (abs(B-G)>1):\n print(-1)\n else:\n if B > G:\n for c in range(len(queue)):\n if c%2!=0 and queue[c]=='B':\n boys.append(c)\n if c%2==0 and queue[c] =='G':\n girls.append(c)\n print(outOfIndex(boys,girls,COST))\n boys.clear()\n girls.clear()\n elif B < G:\n for c in range(len(queue)):\n if c%2!=0 and queue[c]=='G':\n girls.append(c)\n if c%2==0 and queue[c] =='B':\n boys.append(c)\n print(outOfIndex(boys,girls,COST))\n boys.clear()\n girls.clear()\n else:\n for c in range(len(queue)):\n if c%2!=0 and queue[c]=='B':\n boys.append(c)\n if c%2==0 and queue[c] =='G':\n girls.append(c)\n attempt1 = outOfIndex(boys,girls,COST)\n boys.clear()\n girls.clear()\n for c in range(len(queue)):\n if c%2!=0 and queue[c]=='G':\n girls.append(c)\n if c%2==0 and queue[c] =='B':\n boys.append(c)\n attempt2 = outOfIndex(boys,girls,COST)\n print(min(attempt1,attempt2))\n boys.clear()\n girls.clear() \n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '8\\n0\\nBB\\n0\\nBG\\n0\\nBBGG\\n1\\nBGG\\n1\\nBGGB\\n1\\nBBBGG\\n2\\nBBGG\\n2\\nBGB\\n', 'output': '-1\\n0\\n1\\n1\\n1\\n3\\n1\\n0\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/DEVCLASS'}","problem_id":"vfc_4814","program":"```python\ndef outOfIndex(boys,girls,COST):\n if COST == 0:\n return len(boys)\n else:\n total_cost = [ abs(x-y) for x,y in zip(boys,girls)]\n total_cost = sum(total_cost)\n return total_cost\n\nfor _ in range(int(input())):\n COST = int(input())\n queue = input()\n B = queue.count('B')\n G = queue.count('G')\n boys=[]\n girls = []\n if (abs(B-G)>1):\n print(-1)\n else:\n if B > G:\n for c in range(len(queue)):\n if c%2!=0 and queue[c]=='B':\n boys.append(c)\n if c%2==0 and queue[c] =='G':\n girls.append(c)\n print(outOfIndex(boys,girls,COST))\n boys.clear()\n girls.clear()\n elif B < G:\n for c in range(len(queue)):\n if c%2!=0 and queue[c]=='G':\n girls.append(c)\n if c%2==0 and queue[c] =='B':\n boys.append(c)\n print(outOfIndex(boys,girls,COST))\n boys.clear()\n girls.clear()\n else:\n for c in range(len(queue)):\n if c%2!=0 and queue[c]=='B':\n boys.append(c)\n if c%2==0 and queue[c] =='G':\n girls.append(c)\n attempt1 = outOfIndex(boys,girls,COST)\n boys.clear()\n girls.clear()\n for c in range(len(queue)):\n if c%2!=0 and queue[c]=='G':\n girls.append(c)\n if c%2==0 and queue[c] =='B':\n boys.append(c)\n attempt2 = outOfIndex(boys,girls,COST)\n print(min(attempt1,attempt2))\n boys.clear()\n girls.clear() \n\n```","inputs":"8\n0\nBB\n0\nBG\n0\nBBGG\n1\nBGG\n1\nBGGB\n1\nBBBGG\n2\nBBGG\n2\nBGB\n","output":"-1\n0\n1\n1\n1\n3\n1\n0\n","actual_output":"-1\n0\n1\n1\n1\n3\n1\n0\n","execution_success":true,"sample_index":1081},{"source":"apps","task_type":"verifiable_code","in_source_id":"1494","prompt":"Solve the following coding problem using the programming language python:\n\nRohit has n empty boxes lying on the ground in a line. The size of the boxes is given in the form of an array $a$. The size of the ith box is denoted by $a[i]$. Since Rohit has a tiny room, there is a shortage of space. Therefore, he has to reduce the number of boxes on the ground by putting a box into another box that is at least twice the size of the current box i.e if we have to put the ith box into the jth box then $( 2*a[i] ) <= a[j]$.\nEach box can contain a maximum of one box and the box which is kept in another box cannot\nhold any box itself.\nFind the minimum number of boxes that will remain on the ground after putting boxes into each other.\n\n-----Input:-----\n- The first line contains a single integer n.\n- The next n lines contain the integer a[i] - the size of the i-th box.\n\n-----Output:-----\nOutput a single integer denoting the minimum number of boxes remaining on the ground.\n\n-----Constraints-----\n- $1 \\leq n \\leq 5*10^5$\n- $1 \\leq a[i] \\leq 10^5$\n\n-----Subtasks-----\n- 30 points : $1 \\leq n \\leq 10^2$\n- 70 points : $1 \\leq n \\leq 5*10^5$\n\n-----Sample Input:-----\n5\n16\n1\n4\n8\n2\n\n-----Sample Output:-----\n3\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nn=int(input())\r\nl=[0]*n\r\nfor i in range(n):\r\n l[i]=int(input())\r\nl.sort()\r\ns=0\r\ni=n-1\r\nwhile i>=0:\r\n x=2*l[i]\r\n if l[-1]>=x:\r\n j=i\r\n while j=x:\r\n l.pop(j)\r\n l.pop(i)\r\n s+=1\r\n break\r\n j+=1\r\n i-=1\r\ns+=len(l)\r\nprint(s)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '5\\n16\\n1\\n4\\n8\\n2\\n', 'output': '3\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/POPU2021/problems/BXRED'}","problem_id":"vfc_4818","program":"```python\nn=int(input())\r\nl=[0]*n\r\nfor i in range(n):\r\n l[i]=int(input())\r\nl.sort()\r\ns=0\r\ni=n-1\r\nwhile i>=0:\r\n x=2*l[i]\r\n if l[-1]>=x:\r\n j=i\r\n while j=x:\r\n l.pop(j)\r\n l.pop(i)\r\n s+=1\r\n break\r\n j+=1\r\n i-=1\r\ns+=len(l)\r\nprint(s)\n```","inputs":"5\n16\n1\n4\n8\n2\n","output":"3\n","actual_output":"3\n","execution_success":true,"sample_index":1082},{"source":"apps","task_type":"verifiable_code","in_source_id":"1495","prompt":"Solve the following coding problem using the programming language python:\n\nAfter completing some serious investigation, Watson and Holmes are now chilling themselves in the Shimla hills. Very soon Holmes became bored. Holmes lived entirely for his profession. We know he is a workaholic. So Holmes wants to stop his vacation and get back to work. But after a tiresome season, Watson is in no mood to return soon. So to keep Holmes engaged, he decided to give Holmes one math problem. And Holmes agreed to solve the problem and said as soon as he solves the problem, they should return back to work. Watson too agreed. \nThe problem was as follows. Watson knows Holmes\u2019 favorite numbers are 6 and 5. So he decided to give Holmes N single digit numbers. Watson asked Holmes to form a new number with the given N numbers in such a way that the newly formed number should be completely divisible by 5 and 6. Watson told Holmes that he should also form the number from these digits in such a way that the formed number is maximum. He may or may not use all the given numbers. But he is not allowed to use leading zeros. Though he is allowed to leave out some of the numbers, he is not allowed to add any extra numbers, which means the maximum count of each digit in the newly formed number, is the same as the number of times that number is present in those given N digits.\n\n-----Input-----\nThe first line of input contains one integers T denoting the number of test cases.\nEach test case consists of one integer N, number of numbers.\nNext line contains contains N single digit integers \n\n-----Output-----\nFor each test case output a single number, where the above said conditions are satisfied. If it is not possible to create such a number with the given constraints print -1.If there exists a solution, the maximised number should be greater than or equal to 0. \n\n-----Constraints-----\n- 1 \u2264 T \u2264 100\n- 1 \u2264 N \u2264 10000\n- 0 \u2264 Each digit \u2264 9\n\n-----Subtasks-----\nSubtask #1 : (90 points)\n- 1 \u2264 T \u2264 100\n- 1 \u2264 N \u2264 10000\n\nSubtask 2 : (10 points) \n\n- 1 \u2264 T \u2264 10\n- 1 \u2264 N\u2264 10\n\n-----Example-----\nInput:\n2\n12\n3 1 2 3 2 0 2 2 2 0 2 3\n11\n3 9 9 6 4 3 6 4 9 6 0\n\nOutput:\n33322222200\n999666330\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nt=int(input())\nfor i in range(0,t):\n n=int(input())\n lis=list(map(int,input().split()))\n lis2=[]\n for j in range(0,10):\n lis2.append(0)\n for j in range(0,len(lis)):\n lis2[lis[j]]+=1;\n s=sum(lis)\n while s%3!=0:\n if s%3==2:\n if lis2[2]>=1:\n lis2[2]-=1\n s=s-2\n elif lis2[5]>=1:\n lis2[5]-=1\n s=s-5\n elif lis2[8]>=1:\n lis2[8]-=1\n s=s-8\n elif lis2[1]>=2:\n lis2[1]-=2\n s=s-2\n elif lis2[1]>=1 and lis2[4]>=1:\n lis2[1]-=1\n lis2[4]-=1\n s=s-5\n elif lis2[4]>=2:\n lis2[4]-=2\n s=s-8\n elif lis2[1]>=1 and lis2[7]>=1:\n lis2[1]-=1\n lis2[7]-=1\n s=s-8\n elif lis2[4]>=1 and lis2[7]>=1:\n lis2[4]-=1\n lis2[7]-=1\n s=s-11\n elif lis2[7]>=2:\n lis2[7]-=2\n s=s-14\n elif s%3==1:\n if lis2[1]>=1:\n lis2[1]-=1\n s=s-1\n elif lis2[4]>=1:\n lis2[4]-=1\n s=s-4\n elif lis2[7]>=1:\n lis2[7]-=1\n s=s-7\n elif lis2[2]>=2:\n lis2[2]-=2\n s=s-4\n elif lis2[5]>=1 and lis2[2]>=1:\n lis2[2]-=1\n lis2[5]-=1\n s=s-7\n elif lis2[5]>=2:\n lis2[5]-=2\n s=s-10\n elif lis2[2]>=1 and lis2[8]>=1:\n lis2[2]-=1\n lis2[8]-=1\n s=s-10\n elif lis2[8]>=1 and lis2[5]>=1:\n lis2[8]-=1\n lis2[5]-=1\n s=s-13\n elif lis2[8]>=2:\n lis2[8]-=2\n s=s-16\n lis3=[]\n for j in range(1,10):\n if lis2[j]>=1:\n for k in range(0,lis2[j]):\n lis3.append(j)\n lis3.reverse()\n for k in range(0,lis2[0]):\n lis3.append(0)\n sol=''\n for k in range(0,len(lis3)):\n sol+=str(lis3[k])\n print(sol)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n12\\n3 1 2 3 2 0 2 2 2 0 2 3\\n11\\n3 9 9 6 4 3 6 4 9 6 0\\n', 'output': '33322222200\\n999666330\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/LOCJUL16/problems/NUMHOLMS'}","problem_id":"vfc_4822","program":"```python\nt=int(input())\nfor i in range(0,t):\n n=int(input())\n lis=list(map(int,input().split()))\n lis2=[]\n for j in range(0,10):\n lis2.append(0)\n for j in range(0,len(lis)):\n lis2[lis[j]]+=1;\n s=sum(lis)\n while s%3!=0:\n if s%3==2:\n if lis2[2]>=1:\n lis2[2]-=1\n s=s-2\n elif lis2[5]>=1:\n lis2[5]-=1\n s=s-5\n elif lis2[8]>=1:\n lis2[8]-=1\n s=s-8\n elif lis2[1]>=2:\n lis2[1]-=2\n s=s-2\n elif lis2[1]>=1 and lis2[4]>=1:\n lis2[1]-=1\n lis2[4]-=1\n s=s-5\n elif lis2[4]>=2:\n lis2[4]-=2\n s=s-8\n elif lis2[1]>=1 and lis2[7]>=1:\n lis2[1]-=1\n lis2[7]-=1\n s=s-8\n elif lis2[4]>=1 and lis2[7]>=1:\n lis2[4]-=1\n lis2[7]-=1\n s=s-11\n elif lis2[7]>=2:\n lis2[7]-=2\n s=s-14\n elif s%3==1:\n if lis2[1]>=1:\n lis2[1]-=1\n s=s-1\n elif lis2[4]>=1:\n lis2[4]-=1\n s=s-4\n elif lis2[7]>=1:\n lis2[7]-=1\n s=s-7\n elif lis2[2]>=2:\n lis2[2]-=2\n s=s-4\n elif lis2[5]>=1 and lis2[2]>=1:\n lis2[2]-=1\n lis2[5]-=1\n s=s-7\n elif lis2[5]>=2:\n lis2[5]-=2\n s=s-10\n elif lis2[2]>=1 and lis2[8]>=1:\n lis2[2]-=1\n lis2[8]-=1\n s=s-10\n elif lis2[8]>=1 and lis2[5]>=1:\n lis2[8]-=1\n lis2[5]-=1\n s=s-13\n elif lis2[8]>=2:\n lis2[8]-=2\n s=s-16\n lis3=[]\n for j in range(1,10):\n if lis2[j]>=1:\n for k in range(0,lis2[j]):\n lis3.append(j)\n lis3.reverse()\n for k in range(0,lis2[0]):\n lis3.append(0)\n sol=''\n for k in range(0,len(lis3)):\n sol+=str(lis3[k])\n print(sol)\n```","inputs":"2\n12\n3 1 2 3 2 0 2 2 2 0 2 3\n11\n3 9 9 6 4 3 6 4 9 6 0\n","output":"33322222200\n999666330\n","actual_output":"33322222200\n999666330\n","execution_success":true,"sample_index":1083},{"source":"apps","task_type":"verifiable_code","in_source_id":"1496","prompt":"Solve the following coding problem using the programming language python:\n\nChef has a nice complete binary tree in his garden. Complete means that each node has exactly two sons, so the tree is infinite. Yesterday he had enumerated the nodes of the tree in such a way: \n- Let's call the nodes' level a number of nodes that occur on the way to this node from the root, including this node. This way, only the root has the level equal to 1, while only its two sons has the level equal to 2.\n- Then, let's take all the nodes with the odd level and enumerate them with consecutive odd numbers, starting from the smallest levels and the leftmost nodes, going to the rightmost nodes and the highest levels.\n- Then, let's take all the nodes with the even level and enumerate them with consecutive even numbers, starting from the smallest levels and the leftmost nodes, going to the rightmost nodes and the highest levels.\n- For the better understanding there is an example: \n1\n/ \\\n2 4\n/ \\ / \\\n3 5 7 9\n/ \\ / \\ / \\ / \\\n6 8 10 12 14 16 18 20 \n\nHere you can see the visualization of the process. For example, in odd levels, the root was enumerated first, then, there were enumerated roots' left sons' sons and roots' right sons' sons.\nYou are given the string of symbols, let's call it S. Each symbol is either l or r. Naturally, this sequence denotes some path from the root, where l means going to the left son and r means going to the right son.\nPlease, help Chef to determine the number of the last node in this path.\n\n-----Input-----\nThe first line contains single integer T number of test cases.\nEach of next T lines contain a string S consisting only of the symbols l and r.\n\n-----Output-----\nPer each line output the number of the last node in the path, described by S, modulo 109+7.\n\n-----Constraints-----\n- 1 \u2264 |T| \u2264 5\n- 1 \u2264 |S| \u2264 10^5\n- Remember that the tree is infinite, so each path described by appropriate S is a correct one.\n\n-----Example-----\nInput:\n4\nlrl\nrll\nr\nlllr\nOutput:\n10\n14\n4\n13\n\n-----Explanation-----\nSee the example in the statement for better understanding the samples.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\nMOD=10**9+7\nfor _ in range(int(input())):\n s=input()\n ind=1\n level=1\n for i in range(len(s)):\n if s[i]=='l':\n if level%2==1:\n ind=ind*2\n else:\n ind=ind*2-1\n if s[i]=='r':\n if level%2==1:\n ind=ind*2+2\n else:\n ind=ind*2+1\n level+=1\n ind%=MOD\n print(ind)\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '4\\nlrl\\nrll\\nr\\nlllr\\n\\n', 'output': '10\\n14\\n4\\n13\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/CHEFLR'}","problem_id":"vfc_4826","program":"```python\n# cook your dish here\nMOD=10**9+7\nfor _ in range(int(input())):\n s=input()\n ind=1\n level=1\n for i in range(len(s)):\n if s[i]=='l':\n if level%2==1:\n ind=ind*2\n else:\n ind=ind*2-1\n if s[i]=='r':\n if level%2==1:\n ind=ind*2+2\n else:\n ind=ind*2+1\n level+=1\n ind%=MOD\n print(ind)\n\n```","inputs":"4\nlrl\nrll\nr\nlllr\n\n","output":"10\n14\n4\n13\n","actual_output":"10\n14\n4\n13\n","execution_success":true,"sample_index":1084},{"source":"apps","task_type":"verifiable_code","in_source_id":"1497","prompt":"Solve the following coding problem using the programming language python:\n\nDivya's watch of worth Rs10 cr is abducted by N thieves(1,2....i...N). The fight over the watch leads to a final decision that it should belong to the thief who wins a simple game. The rules of the game state that every thief registers a time in the format HH:MM:SS . Accordingly the average A of three clockwise angles between the hours , minutes and seconds hands is calculated . Thus the ith thief with the maximum A wins the game and gets to keep the watch.\n\nThe thieves are poor in mathematics and will need your help . Given the number of thieves and their registered time resolves the conflict and help them in choosing the winner \n\n-----Input-----\nFirst line of input contains T which denotes the number of test cases.\n\nThe first line of each test case consists of an integer which denotes the number of thieves thereby N line follow which give the time choosen by each thieve in the format HH:MM:SS.\n\n-----Output:-----\nOutput single integer i which denotes the ith thief.\n\n-----Constraints:-----\n\n1<=T<=100\n\n1<=N<=50\n\n01<=HH<=12\n\n00<=MM<=60\n\n00<=SS<=60\n\n-----Example:-----\nInput:\n2\n3\n12:28:26\n07:26:04\n11:23:17\n2\n07:43:25\n06:23:34\n\nOutput:\n3\n1\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfor t in range(int(input())):\n n = int(input())\n mx = -1\n for i in range(n):\n h, m, s = list(map(int,input().split(\":\")))\n h %= 12\n m %= 60\n s %= 60\n ha = h*30 + m*0.5 + s*0.5/60\n ma = m*6 + s*0.1\n sa = s*6\n \n hm1 = abs(ha - ma)\n hm2 = 360 - hm1\n hm3 = abs(hm1 - hm2)\n hm = min(hm1, hm2, hm3)\n \n ms1 = abs(ma - sa)\n ms2 = 360 - ms1\n ms3 = abs(ms1 - ms2)\n ms = min(ms1, ms2, ms3)\n \n sh1 = abs(sa - ha)\n sh2 = 360 - sh1\n sh3 = abs(sh1 - sh2)\n sh = min(sh1, sh2, sh3)\n \n avg = (hm + ms + sh) / 3\n if (mx < avg):\n ans = i+1\n mx = avg\n print(ans)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n3\\n12:28:26\\n07:26:04\\n11:23:17\\n2\\n07:43:25\\n06:23:34\\n', 'output': '3\\n1\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/ITRA2016/problems/ITRA06'}","problem_id":"vfc_4830","program":"```python\nfor t in range(int(input())):\n n = int(input())\n mx = -1\n for i in range(n):\n h, m, s = list(map(int,input().split(\":\")))\n h %= 12\n m %= 60\n s %= 60\n ha = h*30 + m*0.5 + s*0.5/60\n ma = m*6 + s*0.1\n sa = s*6\n \n hm1 = abs(ha - ma)\n hm2 = 360 - hm1\n hm3 = abs(hm1 - hm2)\n hm = min(hm1, hm2, hm3)\n \n ms1 = abs(ma - sa)\n ms2 = 360 - ms1\n ms3 = abs(ms1 - ms2)\n ms = min(ms1, ms2, ms3)\n \n sh1 = abs(sa - ha)\n sh2 = 360 - sh1\n sh3 = abs(sh1 - sh2)\n sh = min(sh1, sh2, sh3)\n \n avg = (hm + ms + sh) / 3\n if (mx < avg):\n ans = i+1\n mx = avg\n print(ans)\n```","inputs":"2\n3\n12:28:26\n07:26:04\n11:23:17\n2\n07:43:25\n06:23:34\n","output":"3\n1\n","actual_output":"3\n1\n","execution_success":true,"sample_index":1085},{"source":"apps","task_type":"verifiable_code","in_source_id":"1498","prompt":"Solve the following coding problem using the programming language python:\n\nAsh is on his way to becoming the Pokemon Master. His pokemon can perform the following moves: \n- Tackle - Deal damage worth $X$ points \n- Grow - Increase damage by $Y$ points i.e. $X$ = $X$ + $Y$ \nBut, it can only perform Grow first (0 or more times) and then tackle (0 or more) times after which it cannot perform Grow again.\n\nThat is, it cannot perform the Grow operation once it has performed the tackle operation. \nA pokemon can be caught only if it\u2019s health is exactly 1. A wild pokemon has appeared and has health worth $H$ points. Find the minimum number of moves required to catch it or say that it is not possible. \n\n-----Input:-----\n- \nThe first line of the input consists of a single integer $T$ denoting the number of test cases.\n- \nEach test case consists of 3 space-separated integers $H$, $X$ and $Y$.\n\n-----Output:-----\n- For each test case, print a single line containing one integer - the minimum number of moves required to catch the pokemon if it is possible to catch it else print -1.\n\n-----Constraints-----\n- \n1 <= $T$ <= 103\n- \n1 <= $X$, $Y$ < $H$ <= 109\n\n-----Subtasks-----\nSubtask #1 (30 points):\n- 1 <= $X$, $Y$ < $H$ <= 1000\nSubtask #2 (70 points):\n- Original Constraints\n\n-----Sample Input:-----\n2\n\n101 10 10\n\n11 3 3 \n\n-----Sample Output:-----\n6\n\n-1 \n\n-----EXPLANATION:-----\n- \nExample Case 1:\n\nAsh can make use of Grow once. So $X$ = 10 + 10 = 20\n\nThen he can do Tackle 5 times to decrease $H$ to 1.\n\nOR\n\nAsh can make use of Grow 4 times. So $X$ = 10 + 4*10 = 50\n\nThen he can do Tackle 2 times to decrease $H$ to 1.\n\nHence, a total of 6 moves are required either way which is minimum. \n- \nExample Case 2:\n\nNo matter how many times Ash uses Grow or Tackle, pokemon can never be caught.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\ndef Testcase():\n h,x,y = [int(x) for x in input().strip().split()]\n \n h = h-1\n yt = h//y +1\n # print(yt)\n flag=0\n ans = 100000000009\n \n for i in range(0,yt):\n temp = x+i*y\n if h%temp==0:\n flag = 1\n cl =i+int(h/temp)\n # print(temp,cl)\n ans = min(ans,cl)\n # print(temp,ans,i)\n print(ans if flag==1 else '-1')\n \n \nt = int(input())\nwhile t>0:\n Testcase()\n \n t-=1\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n101 10 10\\n11 3 3\\n', 'output': '6\\n-1\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/TCFL2020/problems/TCFL20D'}","problem_id":"vfc_4834","program":"```python\ndef Testcase():\n h,x,y = [int(x) for x in input().strip().split()]\n \n h = h-1\n yt = h//y +1\n # print(yt)\n flag=0\n ans = 100000000009\n \n for i in range(0,yt):\n temp = x+i*y\n if h%temp==0:\n flag = 1\n cl =i+int(h/temp)\n # print(temp,cl)\n ans = min(ans,cl)\n # print(temp,ans,i)\n print(ans if flag==1 else '-1')\n \n \nt = int(input())\nwhile t>0:\n Testcase()\n \n t-=1\n```","inputs":"2\n101 10 10\n11 3 3\n","output":"6\n-1\n","actual_output":"6\n-1\n","execution_success":true,"sample_index":1086},{"source":"apps","task_type":"verifiable_code","in_source_id":"1499","prompt":"Solve the following coding problem using the programming language python:\n\nGiven $N *M$ matrix containing elements either $1$ or $0$ and string S of length $N+M-1$ containing characters $0$ or $1$. Your task is to make all the paths from top left corner to the bottom right corner of the matrix same as the given string .You can perform two types of operations any time .Path means you can only allow it to take right or down. \nOperations :\n- Changing the matrix elements from $1$ to $0$ or vice versa will cost P rupees per element.\n- Changing the character of string from $1$ to $0$ or vice versa will cost Q rupees per character.\nYou have to minimize the cost, (possibly 0) .\n\n-----Input:-----\n- First line of input contains the total no. of test cases $T$. \n- For every test case, first line of input contains two spaced positive integers, $N$ and $M$.\n- Next $N$ lines contains $M$-spaced integers which can be only $0$ or $1$.\n- Next line of input contains a string $S$ of length $N+M-1$.\n- Last line of input contains two spaced integers, $P$ and $Q$.\n\n-----Output:-----\n- $You$ $have$ $to$ $print$ $the$ $minimum$ $cost .$\n\n-----Constraints-----\n- $1 \\leq T \\leq 20$\n- $1 \\leq N, M \\leq 1000$\n- $|S| = N+M-1$\n- $0 \\leq P, Q \\leq 1000$The input/output is quite large, please use fast reading and writing methods.\n\n-----Sample Input-----\n2\n3 3\n1 0 1\n0 1 1\n1 1 0\n10111\n10 5\n3 3 \n0 0 1\n0 1 1\n0 1 1\n00011\n2 9\n\n-----Sample Output-----\n5\n4\n\n-----Explanation-----\n- You can change the last element of the matrix and also can change the last element of string but the minimum cost will produce by changing string element , therefore it will cost 5 rupees.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfrom sys import stdin,stdout\nimport math,bisect\nfrom collections import Counter,deque,defaultdict\nL=lambda:list(map(int, stdin.readline().strip().split()))\nM=lambda:list(map(int, stdin.readline().strip().split()))\nI=lambda:int(stdin.readline().strip())\nS=lambda:stdin.readline().strip()\nC=lambda:stdin.readline().strip().split()\ndef pr(a):return(\" \".join(list(map(str,a))))\n#_________________________________________________#\n\n\ndef solve():\n n, m = M()\n a = []\n for i in range(n):\n a += [L()]\n s = S()\n p, q = M()\n ans = [[0,0] for i in range(n+m)]\n for i in range(n):\n for j in range(m):\n if a[i][j]==0:\n ans[i+j][0]+=1\n else:\n ans[i+j][1]+=1\n c = 0\n for i in range(n+m-1):\n A,B,C,D = 0,0,0,0\n if s[i]=='0':\n A = ans[i][1]*p\n B = q + ans[i][0]*p\n c+=min(A,B)\n else:\n C = ans[i][0]*p\n D = q + ans[i][1]*p\n c+=min(C,D)\n print(c)\nfor _ in range(I()):\n solve()\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n3 3\\n1 0 1\\n0 1 1\\n1 1 0\\n10111\\n10 5\\n3 3\\n0 0 1\\n0 1 1\\n0 1 1\\n00011\\n2 9\\n', 'output': '5\\n4\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/LOGI2020/problems/MATMIN1'}","problem_id":"vfc_4838","program":"```python\nfrom sys import stdin,stdout\nimport math,bisect\nfrom collections import Counter,deque,defaultdict\nL=lambda:list(map(int, stdin.readline().strip().split()))\nM=lambda:list(map(int, stdin.readline().strip().split()))\nI=lambda:int(stdin.readline().strip())\nS=lambda:stdin.readline().strip()\nC=lambda:stdin.readline().strip().split()\ndef pr(a):return(\" \".join(list(map(str,a))))\n#_________________________________________________#\n\n\ndef solve():\n n, m = M()\n a = []\n for i in range(n):\n a += [L()]\n s = S()\n p, q = M()\n ans = [[0,0] for i in range(n+m)]\n for i in range(n):\n for j in range(m):\n if a[i][j]==0:\n ans[i+j][0]+=1\n else:\n ans[i+j][1]+=1\n c = 0\n for i in range(n+m-1):\n A,B,C,D = 0,0,0,0\n if s[i]=='0':\n A = ans[i][1]*p\n B = q + ans[i][0]*p\n c+=min(A,B)\n else:\n C = ans[i][0]*p\n D = q + ans[i][1]*p\n c+=min(C,D)\n print(c)\nfor _ in range(I()):\n solve()\n\n```","inputs":"2\n3 3\n1 0 1\n0 1 1\n1 1 0\n10111\n10 5\n3 3\n0 0 1\n0 1 1\n0 1 1\n00011\n2 9\n","output":"5\n4\n","actual_output":"5\n4\n","execution_success":true,"sample_index":1087},{"source":"apps","task_type":"verifiable_code","in_source_id":"1500","prompt":"Solve the following coding problem using the programming language python:\n\n\tA valid parentheses sequence is a non-empty string where each character is either '(' or ')', which satisfies the following constraint:\n\nYou can find a way to repeat erasing adjacent pairs of parentheses '()' until it becomes empty.\n\n\tFor example, '(())' and '()((()()))' are valid parentheses sequences, but ')()(' and '(()' are not.\n\n\tMike has a valid parentheses sequence. He really likes everything about his sequence, except the fact that it is quite long. So Mike has recently decided that he will replace his parentheses sequence with a new one in the near future. But not every valid parentheses sequence will satisfy him. To help you understand his requirements we'll introduce the pseudocode of function F(S):\n\n\tFUNCTION F( S - a valid parentheses sequence )\n\tBEGIN\n\t\tbalance = 0\n\t\tmax_balance = 0\n\t\tFOR index FROM 1 TO LENGTH(S)\n\t\tBEGIN\n\t\t\tif S[index] == '(' then balance = balance + 1\n\t\t\tif S[index] == ')' then balance = balance - 1\n\t\t\tmax_balance = max( max_balance, balance )\n\t\tEND\n\t\tRETURN max_balance\n\tEND\n\n\tIn other words, F(S) is equal to the maximal balance over all prefixes of S.\n\n\tLet's denote A as Mike's current parentheses sequence, and B as a candidate for a new one. Mike is willing to replace A with B if F(A) is equal to F(B). He would also like to choose B with the minimal possible length amongst ones satisfying the previous condition. If there are several such strings with the minimal possible length, then Mike will choose the least one lexicographically, considering '(' to be less than ')'.\n\n\tHelp Mike!\n\n-----Input-----\n\n\tThe first line of the input contains one integer T denoting the number of testcases to process.\n\n\tThe only line of each testcase contains one string A denoting Mike's parentheses sequence. It is guaranteed that A only consists of the characters '(' and ')'. It is also guaranteed that A is a valid parentheses sequence.\n\n-----Output-----\n\n\tThe output should contain exactly T lines, one line per each testcase in the order of their appearance. The only line of each testcase should contain one string B denoting the valid parentheses sequence that should be chosen by Mike to replace A.\n\n-----Constraints-----\n1 \u2264 T \u2264 5;\n1 \u2264 |A| \u2264 100000(105).\n\n-----Example-----\nInput:\n1\n()((()()))\n\nOutput:\n((()))\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\ntry:\n for i in range(int(input())):\n s=input()\n balance=0\n max_balance=0\n for i in s:\n if i=='(':balance+=1\n else:\n balance-=1\n max_balance=max(max_balance,balance)\n print('('*max_balance,')'*max_balance,sep=\"\")\nexcept Exception as e:\n print(e)\n \n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n()((()()))\\n\\n\\n', 'output': '((()))\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/BRACKETS'}","problem_id":"vfc_4842","program":"```python\ntry:\n for i in range(int(input())):\n s=input()\n balance=0\n max_balance=0\n for i in s:\n if i=='(':balance+=1\n else:\n balance-=1\n max_balance=max(max_balance,balance)\n print('('*max_balance,')'*max_balance,sep=\"\")\nexcept Exception as e:\n print(e)\n \n```","inputs":"1\n()((()()))\n\n\n","output":"((()))\n","actual_output":"((()))\n","execution_success":true,"sample_index":1088},{"source":"apps","task_type":"verifiable_code","in_source_id":"1501","prompt":"Solve the following coding problem using the programming language python:\n\nGiven a Complete Binary Tree of \u2018n\u2019 depth, you can perform 4 types of mirror operation on the tree:-\n\nMirror on the right. The tree is mirrored to the right and rightmost node on every level is connected with the mirrored corresponding node.\n\nMirror on the left. The tree is mirrored to the left and leftmost node on every level is connected with the mirrored corresponding node.\n\nMirror on the top. The tree is mirrored to the top and topmost nodes are connected with corresponding nodes.\n\nMirror on the bottom. The tree is mirrored to the bottom and bottom most nodes are connected with the corresponding nodes.\n\nSee the image for details. \nMirror Right: \n\nMirror Bottom: \n\nYou are given \u2018q\u2019 queries, each performing this type of operation or asking for the no of edges in the produced graph.\n\nQueries are of the form \u201c1 x\u201d or \u201c2\u201d where x is 1 for right, 2 for left, 3 for top or 4 for bottom.\n\n1 x: Perform x operation on the result graph.\n\n2: Print the no of edges in the graph. Since it can be very large, print it modulo 1000000007. \n\n-----Input:-----\n- First line will contain $n$, the depth of the initial tree and $q$, the number of queries. \n- Next $q$ lines contain queries of the form \"1 $x$\" or \"2\".\n\n-----Output:-----\nFor each query of type \"2\", output a single line containing the no of edges in the graph modulo 1000000007.\n\n-----Constraints-----\n- $1 \\leq n \\leq 1000$\n- $1 \\leq q \\leq 10^5$\n- $1 \\leq x \\leq 4$\n\n-----Sample Input:-----\n2 3\n1 1\n1 4\n2\n\n-----Sample Output:-----\n38\n\n-----EXPLANATION:-----\nInitial no of edges = 6\n\nAfter the operation 1 1, no of edges = 15\n\nAfter the operation 1 4, no of edges = 38\n\nAt operation 2, we print the no of edges that is 38.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nimport os,sys\nfrom io import BytesIO, IOBase\n\ndef ii(): return int(input())\ndef si(): return input()\ndef mi(): return list(map(int,input().split()))\ndef li(): return list(mi())\nimport math \n\nimport collections \n\ndef CountFrequency(arr): \n return collections.Counter(arr) \n\nfor i in range(1):\n n,q=mi()\n p=pow(2,n+1)-2 \n t=1 \n b=pow(2,n)\n s=n+1\n for i in range(q):\n a=li()\n if len(a)==2:\n if a[1]==1 or a[1]==2:\n p*=2 \n p+=s\n t*=2 \n b*=2\n else:\n p*=2 \n if a[1]==3:\n p+=t\n t=b \n s*=2\n else:\n p+=b\n b=t\n s*=2\n else:\n print(p%1000000007)\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2 3\\n1 1\\n1 4\\n2\\n', 'output': '38\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/MIRTREE'}","problem_id":"vfc_4846","program":"```python\nimport os,sys\nfrom io import BytesIO, IOBase\n\ndef ii(): return int(input())\ndef si(): return input()\ndef mi(): return list(map(int,input().split()))\ndef li(): return list(mi())\nimport math \n\nimport collections \n\ndef CountFrequency(arr): \n return collections.Counter(arr) \n\nfor i in range(1):\n n,q=mi()\n p=pow(2,n+1)-2 \n t=1 \n b=pow(2,n)\n s=n+1\n for i in range(q):\n a=li()\n if len(a)==2:\n if a[1]==1 or a[1]==2:\n p*=2 \n p+=s\n t*=2 \n b*=2\n else:\n p*=2 \n if a[1]==3:\n p+=t\n t=b \n s*=2\n else:\n p+=b\n b=t\n s*=2\n else:\n print(p%1000000007)\n\n```","inputs":"2 3\n1 1\n1 4\n2\n","output":"38\n","actual_output":"38\n","execution_success":true,"sample_index":1089},{"source":"apps","task_type":"verifiable_code","in_source_id":"1502","prompt":"Solve the following coding problem using the programming language python:\n\nYour are given a string $S$ containing only lowercase letter and a array of character $arr$. Find whether the given string only contains characters from the given character array. \nPrint $1$ if the string contains characters from the given array only else print $0$.\nNote: string contains characters in lower case only.\n\n-----Input:-----\n- First line will contain $T$, number of testcases. Then the testcases follow. \n- Each testcase contains- \na string $S$ of lowercase letter\na integer $n$ denoting length of character array $arr$\nnext line contains $n$ space separated characters.\n\n-----Output:-----\nFor each testcase, Print $1$ if the string contains characters from the given array only else print $0$.\n\n-----Constraints-----\n- $1 \\leq T \\leq 1000$\n- $0 \\leq n \\leq 10^5$\n\n-----Sample Input:-----\n3\nabcd\n4\na b c d\naabbbcccdddd\n4\na b c d\nacd\n3\na b d\n\n-----Sample Output:-----\n1\n1\n0\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nt=int(input())\r\nfor _ in range(t):\r\n S=set(input().strip())\r\n n=int(input().strip())\r\n a=set(input().strip().split(\" \"))\r\n g=True\r\n for i in S:\r\n if(i not in a):\r\n g=False\r\n if(g):\r\n print(1)\r\n else:\r\n print(0)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\nabcd\\n4\\na b c d\\naabbbcccdddd\\n4\\na b c d\\nacd\\n3\\na b d\\n', 'output': '1\\n1\\n0\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/CDGO2021/problems/STRNCHAR'}","problem_id":"vfc_4850","program":"```python\nt=int(input())\r\nfor _ in range(t):\r\n S=set(input().strip())\r\n n=int(input().strip())\r\n a=set(input().strip().split(\" \"))\r\n g=True\r\n for i in S:\r\n if(i not in a):\r\n g=False\r\n if(g):\r\n print(1)\r\n else:\r\n print(0)\n```","inputs":"3\nabcd\n4\na b c d\naabbbcccdddd\n4\na b c d\nacd\n3\na b d\n","output":"1\n1\n0\n","actual_output":"1\n1\n0\n","execution_success":true,"sample_index":1090},{"source":"apps","task_type":"verifiable_code","in_source_id":"1503","prompt":"Solve the following coding problem using the programming language python:\n\nSantosh has a farm at Byteland. He has a very big family to look after. His life takes a sudden turn and he runs into a financial crisis. After giving all the money he has in his hand, he decides to sell his plots. The speciality of his land is that it is rectangular in nature. Santosh comes to know that he will get more money if he sells square shaped plots. So keeping this in mind, he decides to divide his land into minimum possible number of square plots, such that each plot has the same area, and the plots divide the land perfectly. He does this in order to get the maximum profit out of this. \nSo your task is to find the minimum number of square plots with the same area, that can be formed out of the rectangular land, such that they divide it perfectly.\n\n-----Input-----\n- The first line of the input contains $T$, the number of test cases. Then $T$ lines follow.\n- The first and only line of each test case contains two space-separated integers, $N$ and $M$, the length and the breadth of the land, respectively.\n\n-----Output-----\nFor each test case, print the minimum number of square plots with equal area, such that they divide the farm land perfectly, in a new line.\n\n-----Constraints-----\n$1 \\le T \\le 20$\n$1 \\le M \\le 10000$\n$1 \\le N \\le 10000$ \n\n-----Sample Input:-----\n2\n10 15\n4 6\n\n-----SampleOutput:-----\n6\n6\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\nimport math\nN=int(input())\nfor i in range(N):\n a,b=list(map(int,input().split()))\n c=a//math.gcd(a,b)*b//math.gcd(a,b)\n print(c)\n \n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n10 15\\n4 6\\n', 'output': '6\\n6\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/RECTSQ'}","problem_id":"vfc_4854","program":"```python\n# cook your dish here\nimport math\nN=int(input())\nfor i in range(N):\n a,b=list(map(int,input().split()))\n c=a//math.gcd(a,b)*b//math.gcd(a,b)\n print(c)\n \n\n```","inputs":"2\n10 15\n4 6\n","output":"6\n6\n","actual_output":"6\n6\n","execution_success":true,"sample_index":1091},{"source":"apps","task_type":"verifiable_code","in_source_id":"1505","prompt":"Solve the following coding problem using the programming language python:\n\nZonal Computing Olympiad 2012, 26 Nov 2011\n\nA sequence of opening and closing brackets is well-bracketed if we can pair up each opening bracket with a matching closing bracket in the usual sense. For instance, the sequences (), (()) and ()(()) are well-bracketed, while (, ()), (()(), and )( are not well-bracketed.\n\nThe nesting depth of a well-bracketed sequence tells us the maximum number of levels of inner matched brackets enclosed within outer matched brackets. For instance, the nesting depth of () and ()()() is 1, the nesting depth of (()) and ()(()) is 2, the nesting depth of ((())) is 3, and so on. \n\nGiven a well-bracketed sequence, we are interested in computing the following: \n- The nesting depth, and the first position where it occurs\u2013this will be the position of the first opening bracket at this nesting depth, where the positions are numbered starting with 1.\n- The maximum number of symbols between any pair of matched brackets, including both the outer brackets, and the first position where this occurs\u2013that is, the position of the first opening bracket of this segment\n\nFor instance, the nesting depth of ()(())()(()())(()()) is 2 and the first position where this occurs is 4. The opening bracket at position 10 is also at nesting depth 2 but we have to report the first position where this occurs, which is 4.\n\nIn this sequence, the maximum number of symbols between a pair of matched bracket is 6, starting at position 9. There is another such sequence of length 6 starting at position 15, but this is not the first such position.\n\n-----Input format-----\nThe input consists of two lines. The first line is a single integer N, the length of the bracket sequence. Positions in the sequence are numbered 1,2,\u2026,N. The second line is a sequence of N space-separated integers that encode the bracket expression as follows: 1 denotes an opening bracket ( and 2 denotes a closing bracket ). Nothing other than 1 or 2 appears in the second line of input and the corresponding expression is guaranteed to be well-bracketed.\n\n-----Output format-----\nYour program should print 4 space-separated integers in a line, denoting the four quantities asked for in the following order: nesting depth, first position that achieves the nesting depth, length of the maximum sequence between matching brackets and the first position where such a maximum length sequence occurs. \n\n-----Testdata-----\n\nYou may assume that 2 \u2264 N \u2264 105. In 30% of the test cases, 2 \u2264 N \u2264 103.\n\n- Subtask 1 (30 marks)\n- Subtask 2 (70 marks)\n\n-----Sample Input-----\n20\n1 2 1 1 2 2 1 2 1 1 2 1 2 2 1 1 2 1 2 2\n\n-----Sample Output-----\n2 4 6 9\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\n\nT = int(input())\nl = list(map(int, input().strip().split(\" \")))\n\ndepth = 0\nmax_depth = 0\nmax_depth_index = 0\n\nmax_l=0\nmax_l_index=0\nlast_zero=-1\n\nfor i in range(T):\n if l[i] == 1:\n depth += 1\n if depth > max_depth:\n max_depth = depth\n max_depth_index = i + 1\n else:\n depth-=1\n if depth == 0:\n length = i - last_zero\n if length > max_l:\n max_l = length\n max_l_index = last_zero + 2\n last_zero = i\n \nprint(max_depth, max_depth_index, max_l, max_l_index)\n\n\"\"\"\n2 4 6 9\n\"\"\"\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '20\\n1 2 1 1 2 2 1 2 1 1 2 1 2 2 1 1 2 1 2 2\\n', 'output': '2 4 6 9\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/ZCOPRAC/problems/ZCO12001'}","problem_id":"vfc_4862","program":"```python\n# cook your dish here\n\nT = int(input())\nl = list(map(int, input().strip().split(\" \")))\n\ndepth = 0\nmax_depth = 0\nmax_depth_index = 0\n\nmax_l=0\nmax_l_index=0\nlast_zero=-1\n\nfor i in range(T):\n if l[i] == 1:\n depth += 1\n if depth > max_depth:\n max_depth = depth\n max_depth_index = i + 1\n else:\n depth-=1\n if depth == 0:\n length = i - last_zero\n if length > max_l:\n max_l = length\n max_l_index = last_zero + 2\n last_zero = i\n \nprint(max_depth, max_depth_index, max_l, max_l_index)\n\n\"\"\"\n2 4 6 9\n\"\"\"\n```","inputs":"20\n1 2 1 1 2 2 1 2 1 1 2 1 2 2 1 1 2 1 2 2\n","output":"2 4 6 9\n","actual_output":"2 4 6 9\n","execution_success":true,"sample_index":1093},{"source":"apps","task_type":"verifiable_code","in_source_id":"1506","prompt":"Solve the following coding problem using the programming language python:\n\nCherry has a binary matrix $A$ consisting of $N$ rows and $M$ columns. The rows are numbered from $1$ to $N$, columns are numbered from $1$ to $M$. Element at row $i$ ($1$\u2009\u2264\u2009$i$\u2009\u2264\u2009$N$) and column $j$ ($1$\u2009\u2264\u2009$j$\u2009\u2264 $M$) is denoted as $A_{ij}$. All elements of $A$ are either $0$ or $1$.\nHe performs $Q$ queries on matrix. Each query is provided by four integers $x_{1}$, $y_{1}$, $x_{2}$, $y_{2}$ which define the rectangle, where ($x_{1}$,\u2009$y_{1}$) stands for the coordinates of the top left cell of the rectangle, while ($x_{2}$,\u2009$y_{2}$) stands for the coordinates of the bottom right cell. You need to flip all the bits i.e. ($0$ to $1$, $1$ to $0$) that are located fully inside the query rectangle.\nFinally, print the matrix after performing all the queries.\nNote: $x_{1}$ represents the row number while $y_{1}$ represents the column number.\n\n-----Input:-----\n- The first line of the input contains two integers $N$ and $M$ \u2014 the number of rows and the number of columns in the matrix.\n- Each of the next $N$ lines contains a string of length $M$, where the $j^{th}$ character of $i^{th}$ line denotes the value of $A_{i,j}$. \n- Next line contains an integer $Q$ \u2014 the number of queries.\n- Then follow $Q$ lines with queries descriptions. Each of them contains four space-seperated integers $x_{1}$, $y_{1}$, $x_{2}$, $y_{2}$ \u2014 coordinates of the up left and bottom right cells of the query rectangle.\n\n-----Output:-----\nPrint the matrix, in the form of $N$ strings, after performing all the queries.\n\n-----Constraints-----\n- $1 \\leq N,M \\leq 1000$\n- $0 \\leq A_{ij} \\leq 1$\n- $1 \\leq Q \\leq 10^6$\n- $1 \\leq x_{1} \\leq x_{2} \\leq N$\n- $1 \\leq y_{1} \\leq y_{2} \\leq M$\n\n-----Sample Input:-----\n2 2\n00\n00\n3\n1 1 1 1\n2 2 2 2\n1 1 2 2 \n\n-----Sample Output:-----\n01\n10\n\n-----Explanation:-----\nExample case 1:\nAfter processing the 1st query 1 1 1 1, matrix becomes:\n[1000][1000]\\begin{bmatrix} 10 \\\\ 00 \\end{bmatrix}\nAfter processing the 2nd query 2 2 2 2, the matrix becomes:\n[1001][1001]\\begin{bmatrix} 10 \\\\ 01 \\end{bmatrix}\nAfter processing the 3rd query 1 1 2 2, matrix becomes:\n[0110][0110]\\begin{bmatrix} 01 \\\\ 10 \\end{bmatrix}\nWe need to output the matrix after processing all queries.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nimport sys,os,io,time,copy,math,queue,bisect\nfrom collections import deque\nfrom functools import lru_cache\n\nif os.path.exists('input.txt'):\n sys.stdin = open('input.txt', 'r')\n sys.stdout = open('output.txt', 'w') \n\nsys.setrecursionlimit(100000000)\n\ndef main():\n n,m=map(int,input().split())\n mat=[]\n for _ in range(n):\n s=input()\n a=[]\n for i in s:\n a.append(int(i))\n mat.append(a)\n \n Q=int(input())\n ans=[[0 for i in range(m+1)] for j in range(n+1)]\n for i in range(Q):\n x1,y1,x2,y2=map(int,input().split())\n x1-=1\n y1-=1\n x2-=1\n y2-=1\n ans[x1][y1]+=1\n ans[x2+1][y1]-=1\n ans[x1][y2+1]-=1\n ans[x2+1][y2+1]+=1\n for j in range(m+1):\n for i in range(1,n+1):\n ans[i][j]=ans[i-1][j]+ans[i][j]\n for i in range(n+1):\n for j in range(1,m+1):\n ans[i][j]=ans[i][j-1]+ans[i][j]\n \n for i in range(n):\n for j in range(m):\n mat[i][j]=(ans[i][j]+mat[i][j])%2\n for m in mat:\n for i in m:\n print(i,end=\"\")\n print(\"\")\n\n \nmain()\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2 2\\n00\\n00\\n3\\n1 1 1 1\\n2 2 2 2\\n1 1 2 2\\n', 'output': '01\\n10\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/CENS20A'}","problem_id":"vfc_4866","program":"```python\nimport sys,os,io,time,copy,math,queue,bisect\nfrom collections import deque\nfrom functools import lru_cache\n\nif os.path.exists('input.txt'):\n sys.stdin = open('input.txt', 'r')\n sys.stdout = open('output.txt', 'w') \n\nsys.setrecursionlimit(100000000)\n\ndef main():\n n,m=map(int,input().split())\n mat=[]\n for _ in range(n):\n s=input()\n a=[]\n for i in s:\n a.append(int(i))\n mat.append(a)\n \n Q=int(input())\n ans=[[0 for i in range(m+1)] for j in range(n+1)]\n for i in range(Q):\n x1,y1,x2,y2=map(int,input().split())\n x1-=1\n y1-=1\n x2-=1\n y2-=1\n ans[x1][y1]+=1\n ans[x2+1][y1]-=1\n ans[x1][y2+1]-=1\n ans[x2+1][y2+1]+=1\n for j in range(m+1):\n for i in range(1,n+1):\n ans[i][j]=ans[i-1][j]+ans[i][j]\n for i in range(n+1):\n for j in range(1,m+1):\n ans[i][j]=ans[i][j-1]+ans[i][j]\n \n for i in range(n):\n for j in range(m):\n mat[i][j]=(ans[i][j]+mat[i][j])%2\n for m in mat:\n for i in m:\n print(i,end=\"\")\n print(\"\")\n\n \nmain()\n\n```","inputs":"2 2\n00\n00\n3\n1 1 1 1\n2 2 2 2\n1 1 2 2\n","output":"01\n10\n","actual_output":"01\n10\n","execution_success":true,"sample_index":1094},{"source":"apps","task_type":"verifiable_code","in_source_id":"1507","prompt":"Solve the following coding problem using the programming language python:\n\nYou are given a grid with dimension $n$ x $m$ and two points with coordinates $X(x1,y1)$ and $Y(x2,y2)$ . Your task is to find the number of ways in which one can go from point $A(0, 0)$ to point $B (n, m)$ using the $shortest$ possible path such that the shortest path neither passes through $X$ nor through $Y$. \n\nConsider the above 4 x 4 grid . Our shortest path can't pass through points (1,3) and (3,3) (marked by yellow dots). One of the possible shortest path is from $A$ to $C$ and then from $C$ to $B$.\n\n-----Input:-----\n- First line contains $T$, number of testcases. Then the testcases follow. \n- Each testcase contains of a single line of input, six space separated integers $n, m, x1, y1, x2, y2$. \n\n-----Output:-----\n- For each testcase, output in a single line number of ways modulo $998244353$.\n\n-----Constraints-----\n- $1 \\leq T \\leq 10^5$\n- $3 \\leq n,m \\leq 10^5$\n- $1 \\leq x1, x2 \\leq n - 1$\n- $1 \\leq y1, y2 \\leq m - 1$\n- $x1 \\leq x2$\n- $y1 \\leq y2$\n- $X$ and $Y$ never coincide.\n\n-----Sample Input:-----\n1\n3 3 1 1 1 2\n\n-----Sample Output:-----\n5\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n#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 = 100001\r\np = 998244353\r\nfactorialNumInverse = [0]*(N+1) \r\nnaturalNumInverse = [0]*(N+1)\r\nfact = [0]*(N+1)\r\n \r\ndef InverseofNumber(p): \r\n naturalNumInverse[0] = naturalNumInverse[1] = 1\r\n for i in range(2,N+1): \r\n naturalNumInverse[i] = (naturalNumInverse[p % i] * (p - (p // i)) % p)\r\n \r\ndef InverseofFactorial(p): \r\n factorialNumInverse[0] = factorialNumInverse[1] = 1\r\n for i in range(2,N+1): \r\n factorialNumInverse[i] = (naturalNumInverse[i] * factorialNumInverse[i - 1]) % p \r\n \r\ndef factorial(p): \r\n fact[0] = 1\r\n for i in range(1, N + 1): \r\n fact[i] = (fact[i - 1] * i) % p\r\n\r\ndef f(num,den1,den2):\r\n # n C r = n!*inverse(r!)*inverse((n-r)!) \r\n #ans = ((fact[N] * factorialNumInverse[R])% p * factorialNumInverse[N-R])% p\r\n ans = ((fact[num]*factorialNumInverse[den1])%p*factorialNumInverse[den2])%p\r\n return ans \r\n\r\nInverseofNumber(p) \r\nInverseofFactorial(p) \r\nfactorial(p)\r\n\r\nfor _ in range(inp()):\r\n n,m,x1,y1,x2,y2 = ip()\r\n tot = f(m+n,m,n)\r\n a = f(m-y1+n-x1,m-y1,n-x1)\r\n aa = f(x1+y1,x1,y1)\r\n b = f(m-y2+n-x2,m-y2,n-x2)\r\n bb = f(x2+y2,x2,y2)\r\n c = f(y2-y1+x2-x1,y2-y1,x2-x1)\r\n ans = (tot - a*aa - b*bb + c*aa*b)%p\r\n print(ans)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n3 3 1 1 1 2\\n', 'output': '5\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/CFUS2020/problems/CFS2005'}","problem_id":"vfc_4870","program":"```python\n#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 = 100001\r\np = 998244353\r\nfactorialNumInverse = [0]*(N+1) \r\nnaturalNumInverse = [0]*(N+1)\r\nfact = [0]*(N+1)\r\n \r\ndef InverseofNumber(p): \r\n naturalNumInverse[0] = naturalNumInverse[1] = 1\r\n for i in range(2,N+1): \r\n naturalNumInverse[i] = (naturalNumInverse[p % i] * (p - (p // i)) % p)\r\n \r\ndef InverseofFactorial(p): \r\n factorialNumInverse[0] = factorialNumInverse[1] = 1\r\n for i in range(2,N+1): \r\n factorialNumInverse[i] = (naturalNumInverse[i] * factorialNumInverse[i - 1]) % p \r\n \r\ndef factorial(p): \r\n fact[0] = 1\r\n for i in range(1, N + 1): \r\n fact[i] = (fact[i - 1] * i) % p\r\n\r\ndef f(num,den1,den2):\r\n # n C r = n!*inverse(r!)*inverse((n-r)!) \r\n #ans = ((fact[N] * factorialNumInverse[R])% p * factorialNumInverse[N-R])% p\r\n ans = ((fact[num]*factorialNumInverse[den1])%p*factorialNumInverse[den2])%p\r\n return ans \r\n\r\nInverseofNumber(p) \r\nInverseofFactorial(p) \r\nfactorial(p)\r\n\r\nfor _ in range(inp()):\r\n n,m,x1,y1,x2,y2 = ip()\r\n tot = f(m+n,m,n)\r\n a = f(m-y1+n-x1,m-y1,n-x1)\r\n aa = f(x1+y1,x1,y1)\r\n b = f(m-y2+n-x2,m-y2,n-x2)\r\n bb = f(x2+y2,x2,y2)\r\n c = f(y2-y1+x2-x1,y2-y1,x2-x1)\r\n ans = (tot - a*aa - b*bb + c*aa*b)%p\r\n print(ans)\n```","inputs":"1\n3 3 1 1 1 2\n","output":"5\n","actual_output":"5\n","execution_success":true,"sample_index":1095},{"source":"apps","task_type":"verifiable_code","in_source_id":"1508","prompt":"Solve the following coding problem using the programming language python:\n\nThe 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.\n\n-----Input:-----\n- First-line will contain $T$, the number of test cases. Then the test cases follow. \n- Each test case contains a single line of input, one integer $K$. \n\n-----Output:-----\nFor each test case, output as the pattern.\n\n-----Constraints-----\n- $1 \\leq T \\leq 100$\n- $1 \\leq K \\leq 100$\n\n-----Sample Input:-----\n4\n1\n2\n3\n4\n\n-----Sample Output:-----\n0\n01\n10\n012\n101\n210\n0123\n1012\n2101\n3210\n\n-----EXPLANATION:-----\nNo need, else pattern can be decode easily.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\nfor _ in range(int(input())):\n n=int(input())\n if n==1:\n print(\"0\")\n else:\n s=[]\n for i in range(n):\n s.append(str(i))\n print(''.join(s))\n p=1\n for i in range(n-1):\n s.pop(n-1)\n s=[str(p)]+s\n print(''.join(s))\n p+=1\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '4\\n1\\n2\\n3\\n4\\n', 'output': '0\\n01\\n10\\n012\\n101\\n210\\n0123\\n1012\\n2101\\n3210\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/PEND2020/problems/ITGUY59'}","problem_id":"vfc_4874","program":"```python\n# cook your dish here\nfor _ in range(int(input())):\n n=int(input())\n if n==1:\n print(\"0\")\n else:\n s=[]\n for i in range(n):\n s.append(str(i))\n print(''.join(s))\n p=1\n for i in range(n-1):\n s.pop(n-1)\n s=[str(p)]+s\n print(''.join(s))\n p+=1\n\n```","inputs":"4\n1\n2\n3\n4\n","output":"0\n01\n10\n012\n101\n210\n0123\n1012\n2101\n3210\n","actual_output":"0\n01\n10\n012\n101\n210\n0123\n1012\n2101\n3210\n","execution_success":true,"sample_index":1096},{"source":"apps","task_type":"verifiable_code","in_source_id":"1509","prompt":"Solve the following coding problem using the programming language python:\n\nThe Siruseri amusement park has a new attraction. It consists of a rectangular array of discs. Each disc is divided into four equal sectors and the four sectors are coloured with the colours Red, Blue, Green and Yellow (in some order). The ordering may be different in different discs. Here is a possible arrangment of the discs:\n\nYou start at the top left disc. Your task is to walk down to the bottom right disc. In each step, you can rotate the current disc by $90$ degrees in the clockwise direction or move to a neighbouring disc. However, you can move to a neighbouring disc only if adjacent sectors of these two discs have the same colour. For example, in the figure above, you can move from the disc at position ($1$, $1$) to either of its neighbours. However, from the disc at position ($1$, $2$) you can only move to the disc at position ($1$, $1$). If you wish to move from ($1$, $2$) to ($1$, $3$) then you would have to rotate this disc three times so that the colour (red) on the adjacent sectors are the same.\nFor each rotate move, a penalty point is added to the score. The aim is to reach the bottom right with as few penalty points as possible. For example, in the arrangement described in the above figure, the best possible score is $2$, corresponding to the following path: Move from ($1$, $1$) to ($2$, $1$). Move from ($2$, $1$) to ($2$, $2$). Rotate. Rotate. Move from ($2$, $2$) to ($2$, $3$). Move from ($2$, $3$) to ($1$, $3$). Move from ($1$, $3$) to ($1$, $4$). Finally, move from ($1$, $4$) to ($2$, $4$).\nYour task is to determine the minimum number of penalty points required to go from the top left disc to the bottom right disc for the given arrangement of discs.\n\n-----Input:-----\nThe first line contains two integers $M$ and $N$. $M$ is the number of rows and $N$ is the number of columns in the given arrangment. This is followed by $M \\times N$ lines of input. Lines $2$ to $N+1$, describe the colours on the discs on the first row, Lines $N+2$ to $2 \\cdot N+1$ describe the colours on discs in the second row and so on. Each of these lines contain a permutation of the set {R, G, B, Y} giving the colours in the top, right, bottom and left sectors in that order.\n\n-----Output:-----\nA single integer on a single line indicating the minimum number of penalty points required to go from the top left disc to the bottom right disc for the given arrangement of discs.\n\n-----Constraints:-----\n- In $80 \\%$ of the input, $1 \\leq M,N \\leq 60$.\n- In all the inputs $1 \\leq M,N \\leq 1000$.\n\n-----Sample Input-----\n2 4\nG Y B R\nB G R Y\nG Y B R\nG R B Y\nB Y G R\nG B R Y\nB R G Y\nB R G Y\n\n-----Sample Output-----\n2\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n#for _ in range(int(input()):\n#n,m = map(int,input().split())\n#x = [int(w) for w in input().split()]\n#n = int(input())\n#x = [int(input()) for _ in range(n)]\n#for i in range(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])}\n\nm,n = map(int,input().split()) # top,right,bottom,left\nx = []\nfor i in range(m):\n x.append([])\n for j in range(n):\n clr = [w for w in input().split()]\n x[i].append(clr)\n\nimport queue as Q \ndp = [float('inf')]*m\nfor i in range(m):\n dp[i] = [float('inf')]*n\ndp[m-1][n-1] = 0\npq = Q.PriorityQueue()\npq.put([dp[m-1][n-1],m-1,n-1])\nvisited = set()\nxx,yy = [-1,0,1,0],[0,1,0,-1] # top,right,bottom,left\nwhile not pq.empty():\n pop = pq.get()\n cx,cy = pop[1],pop[2]\n if (cx,cy) not in visited:\n visited.add((cx,cy))\n for k in range(4):\n nx,ny = cx+xx[k],cy+yy[k]\n if 0<=nx 0$ and there are no blocked cells between the cells $i$ and $j$.\nChef wants to choose some magnets (possibly none) and to each of these magnets, assign a piece of iron which this magnet should attract. Each piece of iron may only be attracted by at most one magnet and only if the attraction power between them is positive and there are no blocked cells between them. Find the maximum number of magnets Chef can choose.\n\n-----Input-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The first line of each test case contains two space-separated integers $N$ and $K$.\n- The second line contains a single string $S$ with length $N$.\n\n-----Output-----\nFor each test case, print a single line containing one integer \u2015 the maximum number of magnets that can attract iron.\n\n-----Constraints-----\n- $1 \\le T \\le 2,000$\n- $1 \\le N \\le 10^5$\n- $0 \\le K \\le 10^5$\n- $S$ contains only characters 'I', 'M', '_', ':' and 'X'\n- the sum of $N$ over all test cases does not exceed $5 \\cdot 10^6$\n\n-----Subtasks-----\nSubtask #1 (30 points): there are no sheets, i.e. $S$ does not contain the character ':'\nSubtask #2 (70 points): original constraints\n\n-----Example Input-----\n2\n4 5\nI::M\n9 10\nMIM_XII:M\n\n-----Example Output-----\n1\n2\n\n-----Explanation-----\nExample case 1: The attraction power between the only magnet and the only piece of iron is $5+1-3-2 = 1$. Note that it decreases with distance and the number of sheets.\nExample case 2:\nThe magnets in cells $1$ and $3$ can attract the piece of iron in cell $2$, since the attraction power is $10$ in both cases. They cannot attract iron in cells $6$ or $7$ because there is a wall between them.\nThe magnet in cell $9$ can attract the pieces of iron in cells $7$ and $6$; the attraction power is $8$ and $7$ respectively.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\n# cook your dish here\nfor _ in range(int(input())) :\n n,k=map(int,input().split())\n #reading the string \n s=input()\n i,j=0,0\n q=0\n while(ij) :\n p=s[j:i]\n cnt=p.count(':')\n else :\n p=s[i:j]\n cnt=p.count(':')\n t=k+1-abs(i-j)-cnt\n if(t>0) :\n q+=1\n i+=1\n j+=1\n else:\n if(ij) :\n p=s[j:i]\n cnt=p.count(':')\n else :\n p=s[i:j]\n cnt=p.count(':')\n t=k+1-abs(i-j)-cnt\n if(t>0) :\n q+=1\n i+=1\n j+=1\n else:\n if(is):\n nans=nans+par[r][1]\n r=par[r][0]\n else:\n nans=nans+par[s][1]\n s=par[s][0]\n if((r==Z[0]) or (r==Z[1])):\n if(Z[0]s):\n nans=nans+par[r][1]\n r=par[r][0]\n else:\n nans=nans+par[s][1]\n s=par[s][0]\n if((r==Z[0]) or (r==Z[1])):\n if(Z[0] 0$) unreachable if there is no way to obtain an ingredient with tastiness $v$; otherwise, tastiness $v$ is reachable. Chef wants to make ingredients with all reachable values of tastiness and he would like to know the number of unreachable values. Help him solve this problem. Since the answer may be large, compute it modulo $1,000,000,007$ ($10^9+7$).\nNote that there is an infinite number of reachable values of tastiness, but it can be proven that the number of unreachable values is always finite for $N \\ge 2$.\n\n-----Input-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The first and only line of each test case contains two space-separated integers $N$ and $K$.\n\n-----Output-----\nFor each test case, print a single line containing one integer \u2014 the number of unreachable values of tastiness, modulo $1,000,000,007$.\n\n-----Constraints-----\n- $1 \\le T \\le 10^5$\n- $2 \\le N \\le 10^{18}$\n- $1 \\le K \\le 10^{18}$\n\n-----Subtasks-----\nSubtask #1 (20 points): $N = 2$\nSubtask #2 (80 points): original constraints\n\n-----Example Input-----\n2\n2 1\n3 3\n\n-----Example Output-----\n0\n2\n\n-----Explanation-----\nExample case 1: It is possible to obtain ingredients with all values of tastiness.\nExample case 2: Ingredients with tastiness $1$ and $2$ cannot be made.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n__author__ = 'Prateek'\n\nMOD = int(10**9+7)\n\ndef test():\n n,k=list(map(int,input().split()))\n l = k\n d =n-1\n ans = l-1\n ans = ans%MOD\n a = k-n\n term = (d+a)//d\n ll = (a%MOD - (((term-1)%MOD)*(d%MOD))%MOD)%MOD\n if ll < 0:\n ll = (ll +MOD)%MOD\n m = ((term%MOD)*((a%MOD+ll%MOD)%MOD))%MOD\n m = (m*pow(2,MOD-2,MOD))%MOD\n ans += m\n ans = ans%MOD\n print(ans)\n\n\nif __author__ == 'Prateek':\n t = int(input())\n for _ in range(t):\n test()\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n2 1\\n3 3\\n', 'output': '0\\n2\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/CHFING'}","problem_id":"vfc_4906","program":"```python\n__author__ = 'Prateek'\n\nMOD = int(10**9+7)\n\ndef test():\n n,k=list(map(int,input().split()))\n l = k\n d =n-1\n ans = l-1\n ans = ans%MOD\n a = k-n\n term = (d+a)//d\n ll = (a%MOD - (((term-1)%MOD)*(d%MOD))%MOD)%MOD\n if ll < 0:\n ll = (ll +MOD)%MOD\n m = ((term%MOD)*((a%MOD+ll%MOD)%MOD))%MOD\n m = (m*pow(2,MOD-2,MOD))%MOD\n ans += m\n ans = ans%MOD\n print(ans)\n\n\nif __author__ == 'Prateek':\n t = int(input())\n for _ in range(t):\n test()\n\n```","inputs":"2\n2 1\n3 3\n","output":"0\n2\n","actual_output":"0\n2\n","execution_success":true,"sample_index":1104},{"source":"apps","task_type":"verifiable_code","in_source_id":"1517","prompt":"Solve the following coding problem using the programming language python:\n\nConsider a number X on which K Mag-Inc operations are to be performed. In a Mag-Inc operation, the number X undergoes an increment of A/B times of X where A and B are two integers.\n\nThere is a numerator and a denominator array of size K which contain the ith values of A and B. After K Mag-Inc operations, the number X turns to M.\n\nNow your job is to find what percentage of M is to be decremented from M if it has to be converted back to X. Let this percentage be denoted by Z.\n\nPrint the integral part of Z.\n\n-----Input:-----\n\nFirst line contains an integer T denoting the number of test cases.\n\nFirst line of every test case contains two space separated integers X and K.\n\nThe second and third line of every test case will contain K space separated integers \n\ndenoting the Numerator and Denominator array.\n\n-----Output:-----\n\nFor each test case, print the required result in a single line.\n\n-----Constraints:-----\n1 \u2264 T \u2264 100\n1 \u2264 K, A, B \u2264 40000\n1\u2264X\u226410^100\n\n-----Example:-----Input:\n2\n100 1\n1 \n4\n100 2\n1 1\n2 3Output:\n20\n50\n\n-----Explanation:-----\n\nCase 2: 100 undergoes an increment of (1/2)*100. Therefore M = 100 + 50.\n\nNow M = 150.\n\nNow again, \n\nM undergoes an increment of (1/3)*150. Therefore, M = 150 + 50. \n\nNow as we want to revert back M = 200 to X i.e. 100, we need to decrement it by a value \n\nof 100 and we know that 100 is 50% of 200.\n\nHence, we print 50.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nimport sys\nimport math\n\ndef solution():\n T = int(input().strip())\n for _ in range(T):\n x, k = list(map(float, input().strip().split(' ')))\n original_x = x\n if k == 1:\n a = [float(input().strip())]\n b = [float(input().strip())]\n else:\n a = list(map(float, input().strip().split(' ')))\n b = list(map(float, input().strip().split(' ')))\n for i in range(int(k)):\n x = x + (a[i]/b[i])*(x)\n percentage = ((x - original_x) / x)*100\n print(\"%d\"%(int(percentage)))\n\nsolution()\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n100 1\\n1\\n4\\n100 2\\n1 1\\n2 3\\n', 'output': '20\\n50\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/CCWR2016/problems/CCWR02'}","problem_id":"vfc_4910","program":"```python\nimport sys\nimport math\n\ndef solution():\n T = int(input().strip())\n for _ in range(T):\n x, k = list(map(float, input().strip().split(' ')))\n original_x = x\n if k == 1:\n a = [float(input().strip())]\n b = [float(input().strip())]\n else:\n a = list(map(float, input().strip().split(' ')))\n b = list(map(float, input().strip().split(' ')))\n for i in range(int(k)):\n x = x + (a[i]/b[i])*(x)\n percentage = ((x - original_x) / x)*100\n print(\"%d\"%(int(percentage)))\n\nsolution()\n```","inputs":"2\n100 1\n1\n4\n100 2\n1 1\n2 3\n","output":"20\n50\n","actual_output":"20\n50\n","execution_success":true,"sample_index":1105},{"source":"apps","task_type":"verifiable_code","in_source_id":"1518","prompt":"Solve the following coding problem using the programming language python:\n\nThe 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. \n\n-----Input:-----\n- First-line will contain $T$, the number of test cases. Then the test cases follow. \n- Each test case contains a single line of input, two integers $N, K$.\n\n-----Output:-----\nFor each test case, output in a single line answer as 1 or 0.\n\n-----Constraints-----\n- $1 \\leq T \\leq 10^5$\n- $2 \\leq N \\leq 10^5$\n- $1 \\leq K \\leq 10^5$\n\n-----Sample Input:-----\n2\n12 2\n11 2\n\n-----Sample Output:-----\n1\n0\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfrom 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\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n12 2\\n11 2\\n', 'output': '1\\n0\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/PBK22020/problems/ITGUY27'}","problem_id":"vfc_4914","program":"```python\nfrom 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\n```","inputs":"2\n12 2\n11 2\n","output":"1\n0\n","actual_output":"1\n0\n","execution_success":true,"sample_index":1106},{"source":"apps","task_type":"verifiable_code","in_source_id":"1519","prompt":"Solve the following coding problem using the programming language python:\n\nIn 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.\nAfter 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$ . \nBut 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.\nCan 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.\n\n-----Input Format-----\n- First line contain an interger $T$, which denotes number of testcases. Next $T$ lines contain single interger $X$. \n\n-----Output Format-----\n- For every testcase print one integer, i.e. minimum donation Jon needs to make.\n\n-----Constriants-----\n- $ 1 \\leq T \\leq 100000 $ \n- $ 2 \\leq X \\leq 10^{18} $ \n\n-----Sample Input-----\n2\n\n3\n\n7 \n\n-----Sample Output-----\n4\n\n8\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# 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)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n3\\n7\\n', 'output': '4\\n8\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/INSO2020/problems/INQU2000'}","problem_id":"vfc_4918","program":"```python\n# 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)\n```","inputs":"2\n3\n7\n","output":"4\n8\n","actual_output":"4\n8\n","execution_success":true,"sample_index":1107},{"source":"apps","task_type":"verifiable_code","in_source_id":"1520","prompt":"Solve the following coding problem using the programming language python:\n\nGiven 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.\n\n-----Input:-----\n- First line contains an integer n$n$, denoting the length of the array. \n- Second line will contain n$n$ space separated integers, denoting the elements of the array.\n\n-----Output:-----\nOutput a single integer denoting the longest size of subsequence with the given property.\n\n-----Constraints-----\n- 1\u2264n\u2264103$1 \\leq n \\leq 10^3$\n- 0\u2264Ai\u22641018$0 \\leq A_i \\leq 10^{18}$\n\n-----Sample Input:-----\n8\n1 200 3 0 400 4 1 7\n\n-----Sample Output:-----\n6\n\n-----EXPLANATION:-----\nThe subsequence of maximum length is {1, 3, 0, 4, 1, 7} with Xor of adjacent indexes as {2,3,4,5,6} (non-decreasing)\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# 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)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '8\\n1 200 3 0 400 4 1 7\\n', 'output': '6\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/XOMMON'}","problem_id":"vfc_4922","program":"```python\n# 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)\n```","inputs":"8\n1 200 3 0 400 4 1 7\n","output":"6\n","actual_output":"6\n","execution_success":true,"sample_index":1108},{"source":"apps","task_type":"verifiable_code","in_source_id":"1521","prompt":"Solve the following coding problem using the programming language python:\n\nThe 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. \nShe 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$}. \nThe 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$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.\nYou 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.\n\n-----Input-----\n- The first line contains a single integer, $T$, which is the number of testcases. The description of each testcase follows.\n- The first line of every testcase contains a single integer, $N$, which is the number of singers.\n- $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.\n\n-----Output-----\nFor 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. \n\n-----Constraints-----\n- $1 \\le T \\le 5$\n- $2 \\le N \\le 10^5$\n- $1 \\le L_i < U_i \\le 10^9$\n- All the $2*N$ integers (lower bounds and upper bounds) are distinct.\n\n-----Subtasks-----\nSubtask #1 (15 points): $1 \\le N \\le 10^3$\nSubtask #2 (25 points):\n- $1 \\le N \\le 10^5$\n- It is guaranteed that no match ends in a draw.\nSubtask #3 (60 points): Original constraints.\n\n-----Sample Input-----\n2\n3\n10 20\n13 18\n15 19\n3\n10 22\n13 21\n15 20\n\n-----Sample Output-----\n4 1 1\n4 2 0\n\n-----Explanation-----\nTestcase 1: There are three singers, with the lower bounds and upper bounds as (10, 20), (13, 18) and (15, 19).\nWhen 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.\nWhen 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.\nWhen 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.\nThus at the end of the tournament, the total score of first player is 2 + 2 = 4.\nTotal score of the second player is 0 + 1 = 1.\nTotal score of the third player is 0 + 1 = 1.\nHence the output is 4 1 1\nTestcase 2: There are three singers, with the lower bounds and upper bounds as (10, 22), (13, 21) and (15, 20).\nWe 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.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# 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]))\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n3\\n10 20\\n13 18\\n15 19\\n3\\n10 22\\n13 21\\n15 20\\n', 'output': '4 1 1\\n4 2 0\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/ZCOPRAC/problems/SINGTOUR'}","problem_id":"vfc_4926","program":"```python\n# 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]))\n```","inputs":"2\n3\n10 20\n13 18\n15 19\n3\n10 22\n13 21\n15 20\n","output":"4 1 1\n4 2 0\n","actual_output":"4 1 1\n4 2 0\n","execution_success":true,"sample_index":1109},{"source":"apps","task_type":"verifiable_code","in_source_id":"1522","prompt":"Solve the following coding problem using the programming language python:\n\nKira 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.\nFor example, the W string can be formed from \"aaaaa#bb#cc#dddd\" such as:\na\na d\na # d\na b c d\na b c d\n# #\n\nHe also call the strings which can generate a 'W' shape (satisfying the above conditions) W strings.\nMore 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):\n- The string S contains exactly 3 '#' characters. Let the indexes of all '#' be P1 < P2 < P3 (indexes are 0-origin).\n- Each substring of S[0, P1\u22121], S[P1+1, P2\u22121], S[P2+1, P3\u22121], S[P3+1, |S|\u22121] 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).\nNow, 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.\nHelp Kira and he won't write your name in the Death Note.\nNote:\nFor 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 \u2264 a \u2264 b < |S|. And a subsequence of a string S is a string S[i0] S[i1] ... S[in\u22121], where 0 \u2264 i0 < i1 < ... < in\u22121 < |S|.\nFor 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.\nFrom 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.\n\n-----Input-----\nFirst line of input contains an integer T, denoting the number of test cases. Then T lines follow. Each line contains a string S.\n\n-----Output-----\nOutput 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.\n\n-----Constraints-----\n\n- 1 \u2264 T \u2264 100 \n- 1 \u2264 |S| \u2264 10000 (104)\n- S contains no characters other than lower English characters ('a' to 'z') and '#' (without quotes)\n\n-----Example-----\nInput:\n3\naaaaa#bb#cc#dddd\nacb#aab#bab#accba\nabc#dda#bb#bb#aca\n\nOutput:\n16\n10\n11\n\n-----Explanation-----\nIn the first case: the whole string forms a W String.\nIn the second case: acb#aab#bab#accba, the longest W string is acb#aab#bab#accba\nIn 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\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\ndef 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 \n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\naaaaa#bb#cc#dddd\\nacb#aab#bab#accba\\nabc#dda#bb#bb#aca\\n\\n\\n', 'output': '16\\n10\\n11\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/WSTRING'}","problem_id":"vfc_4930","program":"```python\ndef 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 \n```","inputs":"3\naaaaa#bb#cc#dddd\nacb#aab#bab#accba\nabc#dda#bb#bb#aca\n\n\n","output":"16\n10\n11\n","actual_output":"16\n10\n11\n","execution_success":true,"sample_index":1110},{"source":"apps","task_type":"verifiable_code","in_source_id":"1524","prompt":"Solve the following coding problem using the programming language python:\n\nZombies zombies everywhere!! \nIn 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.\n\nA 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.\n\nNow, 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.\n\nOut 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.\n\nProfessor 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.\n\n-----Input-----\nThe first line consists of a single integer T, the number of test-cases.\n\nEach 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.\n\n-----Output-----\nFor each test-case, output a single line denoting the answer of the problem.\n\n-----Constraints-----\n- 1 \u2264 T \u2264 100\n- 1 \u2264 N \u2264 10^9\n- 1 \u2264 K \u2264 10^9\n\n-----Subtasks-----\nSubtask #1 : (10 points)\n- 1 \u2264 T \u2264 20\n- 1 \u2264 N, K \u2264 10\n\nSubtask 2 : (20 points) \n\n- 1 \u2264 T \u2264 10\n- 1 \u2264 N, K \u2264 10000\n\nSubtask 3 : (70 points) \n\n- 1 \u2264 T \u2264 100\n- 1 \u2264 N, K \u2264 10^9\n\n-----Example-----\nInput\n2\n2 2\n3 3\nOutput:\n2\n12\n\n-----Explanation\nIn 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. \nNote 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.\nSo there maximum number of possible ways is 2.\n\nIn the second example, we have 3 Zombies say Z1, Z2, Z3 and cars of 3 colors, suppose red, blue and green.\nA hierarchy to maximize the number of possibilities is Z1 is the parent of Z2, Z2 is the parent of Z3.\nZombie 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.\n\n-----\nIn 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. \n\nNote 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.\n\nSo there maximum number of possible ways is 2.\n\nIn the second example, we have 3 Zombies say Z1, Z2, Z3 and cars of 3 colors, suppose red, blue and green.\n\nA hierarchy to maximize the number of possibilities is Z1 is the parent of Z2, Z2 is the parent of Z3.\n\nZombie 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.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nways=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\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n2 2\\n3 3\\n', 'output': '2\\n12\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/APRIL16/problems/BIPIN3'}","problem_id":"vfc_4938","program":"```python\nways=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\n```","inputs":"2\n2 2\n3 3\n","output":"2\n12\n","actual_output":"2\n12\n","execution_success":true,"sample_index":1112},{"source":"apps","task_type":"verifiable_code","in_source_id":"1525","prompt":"Solve the following coding problem using the programming language python:\n\nThe 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.\nOh, 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.\nNow 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?\nNote 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.\nPlease see the example test case for more details.\n\n-----Input-----\nThe first line contains t, the number of test cases (about 50). Then t test cases follow. Each test case has the following form:\n- The first line contains N (3 \u2264 N \u2264 109)\n- 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.\n\n-----Output-----\nFor 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.\n\n-----Example-----\nInput:\n3\n3\n01000010\n11000001\n00000000\n00011000\n00011000\n00010100\n00001000\n00000000\n4\n01000010\n11000001\n00000000\n00011000\n00011000\n00010100\n00001000\n00000000\n1000000000\n11111111\n11111111\n11111111\n11111111\n11111111\n11111111\n11111111\n11111111\n\nOutput:\n6\n22\n1\n\n-----Output details-----\n\nCase 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).\nCase 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.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nimport 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\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\n3\\n01000010\\n11000001\\n00000000\\n00011000\\n00011000\\n00010100\\n00001000\\n00000000\\n4\\n01000010\\n11000001\\n00000000\\n00011000\\n00011000\\n00010100\\n00001000\\n00000000\\n1000000000\\n11111111\\n11111111\\n11111111\\n11111111\\n11111111\\n11111111\\n11111111\\n11111111\\n\\n\\n', 'output': '6\\n22\\n1\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/AUG09/problems/F3'}","problem_id":"vfc_4942","program":"```python\nimport 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\n```","inputs":"3\n3\n01000010\n11000001\n00000000\n00011000\n00011000\n00010100\n00001000\n00000000\n4\n01000010\n11000001\n00000000\n00011000\n00011000\n00010100\n00001000\n00000000\n1000000000\n11111111\n11111111\n11111111\n11111111\n11111111\n11111111\n11111111\n11111111\n\n\n","output":"6\n22\n1\n","actual_output":"6\n22\n1\n","execution_success":true,"sample_index":1113},{"source":"apps","task_type":"verifiable_code","in_source_id":"1527","prompt":"Solve the following coding problem using the programming language python:\n\nToday 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 \u2260 B) is available in the market.\nShe purchases the string A and tries to convert it to string B by applying any of following three operations zero or more times.\nAND Operation:\nShe will choose a pair of indices i and j such that i != j and perform following sequence of operations.\n\n- result = Ai & Aj \n- Ai = result & Ai \n- Aj = result & Aj \n\nOR Operation:\nShe will choose a pair of indices i and j such that i != j and perform following sequence of operations.\n\n- result = Ai | Aj \n- Ai = result | Ai \n- Aj = result | Aj \n\nXOR Operation:\nShe will choose a pair of indices i and j such that i != j and perform following sequence of operations.\n\n- result = Ai ^ Aj \n- Ai = result ^ Ai \n- Aj = result ^ Aj \n\nChef'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.\n\n-----Input-----\nFirst line of input contains a single integer T denoting the number of test cases. T test cases follow.\nFirst line of each test case, will contain binary string A.\nSecond line of each test case, will contain binary string B.\n\n-----Output-----\nFor 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.\n\n-----Constraints-----\n- 1 \u2264 T \u2264 105\n- 1 \u2264 |A| \u2264 106\n- 1 \u2264 |B| \u2264 106\n- A != B\n- |A| = |B|\n- sum of |A| over all test cases does not exceed 106\n- sum of |B| over all test cases does not exceed 106\n\n-----Subtasks-----\n- Subtask #1 (40 points) : Sum of |A| & |B| over all test cases does not exceed 103\n- Subtask #2 (60 points) : Sum of |A| & |B| over all test cases does not exceed 106\n\n-----Example-----\nInput\n2\n101\n010\n1111\n1010\nOutput\nLucky Chef\n2\nUnlucky Chef\n\n-----Explanation-----\nExample case 1.\n- Applying XOR operation with indices i = 1 and j = 2. Resulting string will be 011.\n- Then, Applying AND operation with indices i = 1 and j = 3. Resulting string will be 010.\n\nExample case 2.\n- It is impossible to convert string A to string B.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfor 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))\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n101\\n010\\n1111\\n1010\\n', 'output': 'Lucky Chef\\n2\\nUnlucky Chef\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/BINOP'}","problem_id":"vfc_4950","program":"```python\nfor 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))\n```","inputs":"2\n101\n010\n1111\n1010\n","output":"Lucky Chef\n2\nUnlucky Chef\n","actual_output":"Lucky Chef\n2\nUnlucky Chef\n","execution_success":true,"sample_index":1115},{"source":"apps","task_type":"verifiable_code","in_source_id":"1528","prompt":"Solve the following coding problem using the programming language python:\n\nYou are Dastan, the great Prince of Persia!\nAfter 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:\nThere 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.)\nThe 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\u2026\n\n-----Input-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The first line of each test case contains two space-separated integers $N$ and $K$.\n- 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.\n\n-----Output-----\nFor each test case, print a single line containing one integer \u2015 the number of coins that are showing heads after $K$ operations.\n\n-----Constraints-----\n- $1 \\le T \\le 200$\n- $1 \\le K < N \\le 100$\n\n-----Subtasks-----\nSubtask #1 (100 points): original constraints\n\n-----Example Input-----\n3\n5 3\nH T T H T\n7 4\nH H T T T H H\n6 1\nT H T H T T\n\n-----Example Output-----\n1\n2\n2\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nt=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']))\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\n5 3\\nH T T H T\\n7 4\\nH H T T T H H\\n6 1\\nT H T H T T\\n', 'output': '1\\n2\\n2\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/POPGATES'}","problem_id":"vfc_4954","program":"```python\nt=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']))\n```","inputs":"3\n5 3\nH T T H T\n7 4\nH H T T T H H\n6 1\nT H T H T T\n","output":"1\n2\n2\n","actual_output":"1\n2\n2\n","execution_success":true,"sample_index":1116},{"source":"apps","task_type":"verifiable_code","in_source_id":"1529","prompt":"Solve the following coding problem using the programming language python:\n\nDuring 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.\nNow, 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$).\nChef 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.\n\n-----Input:-----\n- First line will contain $T$, number of testcases. Then the testcases follow. \n- The first line of each test case contains a single integer $N$ denoting number of cakes.\n- The second line contains $N$ space-separated integers $L1$ $L2$ \u2026 $LN$ layers of the cake.\n\n-----Output:-----\nFor each test case, print a single line containing sum of all the possible numbers which is generated by arranging cake in different sequence.\n\n-----Constraints :-----\n- $1 \\leq T \\leq 2*10^5$\n- $1 \\leq N, L1, L2, L3,\u2026, LN \\leq 9$\n\n-----Sample Input:-----\n1\n3\n2 3 5\n\n-----Sample Output:-----\n2220\n\n-----Explanation:-----\nSum of all possibilities :\n$235 + 532 + 253 + 352 + 523 + 325 = 2220 $\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n#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))\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n3\\n2 3 5\\n', 'output': '2220\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/QFUN2020/problems/CHEFCAKE'}","problem_id":"vfc_4958","program":"```python\n#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))\n```","inputs":"1\n3\n2 3 5\n","output":"2220\n","actual_output":"2220\n","execution_success":true,"sample_index":1117},{"source":"apps","task_type":"verifiable_code","in_source_id":"1530","prompt":"Solve the following coding problem using the programming language python:\n\nThe 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.\n\n-----Input:-----\n- First-line will contain $T$, the number of test cases. Then the test cases follow. \n- Each test case contains a single line of input, one integer $K$. \n\n-----Output:-----\nFor each test case, output as the pattern.\n\n-----Constraints-----\n- $1 \\leq T \\leq 100$\n- $1 \\leq K \\leq 100$\n\n-----Sample Input:-----\n5\n1\n2\n3\n4\n5\n\n-----Sample Output:-----\n1\n1\n32\n1\n32\n654\n1\n32\n654\n10987\n1\n32\n654\n10987\n1514131211\n\n-----EXPLANATION:-----\nNo need, else pattern can be decode easily.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nt = 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\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '5\\n1\\n2\\n3\\n4\\n5\\n', 'output': '1\\n1\\n32\\n1\\n32\\n654\\n1\\n32\\n654\\n10987\\n1\\n32\\n654\\n10987\\n1514131211\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/PTRN2020/problems/ITGUY44'}","problem_id":"vfc_4962","program":"```python\nt = 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\n```","inputs":"5\n1\n2\n3\n4\n5\n","output":"1\n1\n32\n1\n32\n654\n1\n32\n654\n10987\n1\n32\n654\n10987\n1514131211\n","actual_output":"1\n1\n32\n1\n32\n654\n1\n32\n654\n10987\n1\n32\n654\n10987\n1514131211\n","execution_success":true,"sample_index":1118},{"source":"apps","task_type":"verifiable_code","in_source_id":"1532","prompt":"Solve the following coding problem using the programming language python:\n\nAs you know America\u2019s 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.\n\nHe 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].\n\nHe 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.\nSo he needs your help to find out the number of ways in which he can do that. If no solution is possible print 0\n\n-----Input-----\nThe 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.\n\nThe 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. \n\n-----Output-----\nFor 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\n\n-----Constraints-----\n- 1 \u2264 T \u2264 100\n- 1 \u2264 N \u2264 50\n- 1 \u2264 Maxnumber[i] \u2264 3000\n\n-----Example-----\nInput:\n3\n1\n4\n2\n10 5\n4\n2 3 1 3\n\nOutput:\n4\n45\n0\n\n\n-----Explanation-----\nIn case 1, He can choose any number from 1 to 4\n\nIn case 2,Out of the total 50 combination he can not take (1,1) ,(2,2) , (3,3) ,(4,4) or (5,5).\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfor 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) \n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\n1\\n4\\n2\\n10 5\\n4\\n2 3 1 3\\n', 'output': '4\\n45\\n0\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/CDGF2016/problems/CDGLF01'}","problem_id":"vfc_4970","program":"```python\nfor 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) \n```","inputs":"3\n1\n4\n2\n10 5\n4\n2 3 1 3\n","output":"4\n45\n0\n","actual_output":"4\n45\n0\n","execution_success":true,"sample_index":1120},{"source":"apps","task_type":"verifiable_code","in_source_id":"1533","prompt":"Solve the following coding problem using the programming language python:\n\nYou 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.\n\n-----Input-----\n- 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. \n- The next line contains $K$ space-separated distinct integers $A_{1}$, $A_{2}$, $\\ldots$, $A_{K}$, denoting the special nodes.\n- 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$.\n\n-----Output-----\nOutput the shortest pairwise distance between any two different special nodes.\n\n-----Constraints-----\n- The given graph is connected.\n- The given graph doesn't contain self loops and multiple edges.\n- $1 \\leq A_{i} \\leq N$\n- $1 \\leq Z_{j} \\leq 10^{4}$\n- $1 \\leq X_{j}, Y_{j} \\leq N$\n\n-----Subtasks-----\nSubtask #1 (20 points): \n- $2 \\leq N \\leq 300$\n- $N-1 \\leq M \\leq \\frac{N \\cdot (N-1)}{2}$\n- $2 \\leq K \\leq N$\nSubtask #2 (25 points):\n- $2 \\leq N \\leq 10^5$\n- $N-1 \\leq M \\leq 10^5$\n- $2 \\leq K \\leq 10$\nSubtask #3 (55 points):\n- $2 \\leq N \\leq 10^5$\n- $N-1 \\leq M \\leq 3 \\cdot 10^5$\n- $2 \\leq K \\leq 10^4$\n\n-----Example Input-----\n5 5 3\n1 3 5\n1 2 3\n2 3 4\n3 4 1\n4 5 8\n1 5 19\n\n-----Example Output-----\n7\n\n-----Explanation-----\nNodes $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\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nn,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\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '5 5 3\\n1 3 5\\n1 2 3\\n2 3 4\\n3 4 1\\n4 5 8\\n1 5 19\\n', 'output': '7\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/LTIME34/problems/PAIRCLST'}","problem_id":"vfc_4974","program":"```python\nn,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\n```","inputs":"5 5 3\n1 3 5\n1 2 3\n2 3 4\n3 4 1\n4 5 8\n1 5 19\n","output":"7\n","actual_output":"7\n","execution_success":true,"sample_index":1121},{"source":"apps","task_type":"verifiable_code","in_source_id":"1534","prompt":"Solve the following coding problem using the programming language python:\n\nSereja has two integers \u2014 A and B \u2014 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.\n\nPlease, help Sereja calculate the number C modulo 7L.\n\n-----Input-----\n\nFirst line of input contains an integer T \u2014 the number of test cases. T tests follow.\n\nFor 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.\n\n-----Output-----\nOutput the answer in 7-ary system.\n\n-----Constraints-----\n- 1 \u2264 T \u2264 10\n- A and B are both positive integers.\n- Length of A is a positive integer and doesn't exceed 106.\n- L and length of B are positive integers and do not exceed 10000.\n\n-----Subtasks-----\n- Sub task #1 (20 points): Length of A is a positive integer and doesn't exceed 20.\n- Sub task #2 (30 points): Length of A is a positive integer and doesn't exceed 2000.\n- Sub task #3 (50 points): Original constraints.\n\n-----Example-----\nInput:3\n21\n5\n10\n202\n13\n1\n202\n13\n2\n\nOutput:3\n3\n13\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nt=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 z0 :\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 z0:\n x,y = list(map(int,input().split()))\n print(GCD(x,y),LCM(x,y)) \n t -=1\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\n120 140\\n10213 312\\n10 30\\n', 'output': '20 840\\n1 3186456\\n10 30\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/FLOW016'}","problem_id":"vfc_4994","program":"```python\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 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\n```","inputs":"3\n120 140\n10213 312\n10 30\n","output":"20 840\n1 3186456\n10 30\n","actual_output":"20 840\n1 3186456\n10 30\n","execution_success":true,"sample_index":1126},{"source":"apps","task_type":"verifiable_code","in_source_id":"1539","prompt":"Solve the following coding problem using the programming language python:\n\nSoma 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. \n\nMore 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. \n\n-----Input-----\n\nFirst 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. \nYou can assume that 1 <= T <= 100, 1 <= |J|, |S| <= 100\n\n\n-----Output-----\nOutput for each test case, a single integer, the number of jewels mined. \n\n-----Example-----\nInput:\n4\nabc\nabcdef\naA\nabAZ\naaa\na\nwhat\nnone\n\nOutput:\n3\n2\n1\n0\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nn = 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)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '4\\nabc\\nabcdef\\naA\\nabAZ\\naaa\\na\\nwhat\\nnone\\n', 'output': '3\\n2\\n1\\n0\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/MAY12/problems/STONES'}","problem_id":"vfc_4998","program":"```python\nn = 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)\n```","inputs":"4\nabc\nabcdef\naA\nabAZ\naaa\na\nwhat\nnone\n","output":"3\n2\n1\n0\n","actual_output":"3\n2\n1\n0\n","execution_success":true,"sample_index":1127},{"source":"apps","task_type":"verifiable_code","in_source_id":"1540","prompt":"Solve the following coding problem using the programming language python:\n\nThere 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\".\n\n-----Input:-----\nThe first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows.\nThe first line of each test case contains a integers N.\nThe second line of each test case contains K.\n\n-----Output:-----\nFor each test case, print a single line containing \"YES\" if the given conditions are true else \"NO\" if the given conditions are false.\n\n-----Constraints-----\n1<=T<=10\n1<=N<=10^6\n1<=K<=10^6\n\n-----Sample Input:-----\n2\n10\n20\n12\n5\n\n-----Sample Output:-----\nYES\nNO\n\n-----EXPLANATION:-----\nExplanation case 1: since there are 10 friends and 20 pizza slice, so each can get 2 slices, so \"YES\".\nExplanation 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\".\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\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\")\n\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n10\\n20\\n12\\n5\\n', 'output': 'YES\\nNO\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/SPTC2020/problems/CPCEJC1'}","problem_id":"vfc_5002","program":"```python\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\")\n\n```","inputs":"2\n10\n20\n12\n5\n","output":"YES\nNO\n","actual_output":"YES\nNO\n","execution_success":true,"sample_index":1128},{"source":"apps","task_type":"verifiable_code","in_source_id":"1542","prompt":"Solve the following coding problem using the programming language python:\n\nEvery character in the string \u201cIITMANDI\u201d 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 \u201cIITMANDI\u201d such that your score is maximized. \nDouble Letter - Doubles the number of points you get for the letter placed on the double letter.\nTriple Letter - Triples the number of points you get for the letter placed on the triple letter.\nDouble Word - Doubles the number of points you get for the word. Applied after applying above modifiers.\nTriple Word - Triples the number of points you get for the word. Applied after applying the above modifiers.\nThe word has to be read from left to right. You can\u2019t place it in the reverse direction.\n\nThe letters have to be placed continuously on the board.\n\nIf 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.\n\n-----Input Format-----\n- First line containes a single integer $T$ - the number of test cases.\n- First line of each test case contains a single integer $N$ - the size of the board. \n- Second line of each test case contains a string of size $N$ representing the board according to the following convention:\n\n'.' - No modifier\n\n'd' - Double letter\n\n't' - Triple letter\n\n'D' - Double word\n\n'T' - Triple word \n- 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.\n\n-----Output Format-----\nFor each test case, output a single integer in a new line, the maximum possible score. \n\n-----Constraints-----\n$ 1 \\leq T \\leq 1000 $\n$ 8 \\leq N \\leq 100 $\n$ 0 \\leq $ Points for each character $ \\leq 10^5 $ \n\n-----Sample Input-----\n2\n\n10\n\n..d.t.D..d\n\n10 11 12 9 8 10 11 15\n\n22\n\ndtDtTD..ddT.TtTdDT..TD\n\n12297 5077 28888 17998 12125 27400 31219 21536\n\n-----Sample Output-----\n270\n\n35629632\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# 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\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n10\\n..d.t.D..d\\n10 11 12 9 8 10 11 15\\n22\\ndtDtTD..ddT.TtTdDT..TD\\n12297 5077 28888 17998 12125 27400 31219 21536\\n', 'output': '270\\n35629632\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/MAXSCRAB'}","problem_id":"vfc_5010","program":"```python\n# 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\n```","inputs":"2\n10\n..d.t.D..d\n10 11 12 9 8 10 11 15\n22\ndtDtTD..ddT.TtTdDT..TD\n12297 5077 28888 17998 12125 27400 31219 21536\n","output":"270\n35629632\n","actual_output":"270\n35629632\n","execution_success":true,"sample_index":1130},{"source":"apps","task_type":"verifiable_code","in_source_id":"1543","prompt":"Solve the following coding problem using the programming language python:\n\nLet 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.\n\nYour 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 \u2260 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.\n\n-----Input-----\n\nThe first line contains a single positive integer t \u2264 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.\n\nYou are guaranteed that 1 \u2264 n \u2264 100 and 1 \u2264 m \u2264 \n30. Furthermore, each number between 0 and n-1 will appear in at least one set Si.\n\n-----Output-----\n\nFor 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.\n\n-----Example-----\nInput:\n2\n5 2\n3 0 1 2\n3 2 3 4\n4 3\n2 0 1\n2 1 2\n2 2 3\n\nOutput:\n3\n4\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\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\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n5 2\\n3 0 1 2\\n3 2 3 4\\n4 3\\n2 0 1\\n2 1 2\\n2 2 3\\n', 'output': '3\\n4\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/ATOMS'}","problem_id":"vfc_5014","program":"```python\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\n```","inputs":"2\n5 2\n3 0 1 2\n3 2 3 4\n4 3\n2 0 1\n2 1 2\n2 2 3\n","output":"3\n4\n","actual_output":"3\n4\n","execution_success":true,"sample_index":1131},{"source":"apps","task_type":"verifiable_code","in_source_id":"1544","prompt":"Solve the following coding problem using the programming language python:\n\nThe 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.\n\n-----Input:-----\n- First-line will contain $T$, the number of test cases. Then the test cases follow. \n- Each test case contains a single line of input, one integer $K$. \n\n-----Output:-----\nFor each test case, output as the pattern.\n\n-----Constraints-----\n- $1 \\leq T \\leq 100$\n- $1 \\leq K \\leq 100$\n\n-----Sample Input:-----\n5\n1\n2\n3\n4\n5\n\n-----Sample Output:-----\n*\n*\n**\n*\n**\n***\n*\n**\n* *\n****\n*\n**\n* *\n* *\n*****\n\n-----EXPLANATION:-----\nNo need, else pattern can be decode easily.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# cook your dish here\ndef solve():\n n=int(input())\n i=0\n while i0):\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\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n3 4 5\\n1 3 4\\n', 'output': 'YES\\nNO\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/ENFE2020/problems/ECFEB201'}","problem_id":"vfc_5026","program":"```python\n# 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\n```","inputs":"2\n3 4 5\n1 3 4\n","output":"YES\nNO\n","actual_output":"YES\nNO\n","execution_success":true,"sample_index":1134},{"source":"apps","task_type":"verifiable_code","in_source_id":"1547","prompt":"Solve the following coding problem using the programming language python:\n\nIncreasing 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.\nThere 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$.\nWe 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$.\n\n-----Input-----\n- The first and only line of the input contains five space-separated integers $D_1$, $V_1$, $D_2$, $V_2$ and $P$.\n\n-----Output-----\nPrint a single line containing one integer \u2015 the smallest required number of days.\n\n-----Constraints-----\n- $1 \\le D_1, V_1, D_2, V_2 \\le 100$\n- $1 \\le P \\le 1,000$\n\n-----Subtasks-----\nSubtask #1 (30 points): $D_1 = D_2$\nSubtask #2 (70 points): original constraints\n\n-----Example Input 1-----\n1 2 1 3 14\n\n-----Example Output 1-----\n3\n\n-----Explanation-----\nSince $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.\n\n-----Example Input 2-----\n5 4 2 10 100\n\n-----Example Output 2-----\n9\n\n-----Explanation-----\nThere 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.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# 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\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1 2 1 3 14\\n', 'output': '3\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/VACCINE1'}","problem_id":"vfc_5030","program":"```python\n# 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\n```","inputs":"1 2 1 3 14\n","output":"3\n","actual_output":"3\n","execution_success":true,"sample_index":1135},{"source":"apps","task_type":"verifiable_code","in_source_id":"1550","prompt":"Solve the following coding problem using the programming language python:\n\nThe 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:\nX(n) = X(n-1) XOR X(n-2)\nThe second sequence that uses the bitwise XNOR operation instead of the addition method is called the XNoronacci number. It is described as follows:\nE(n) = E(n-1) XNOR E(n-2)\nThe first and second numbers of the sequence are as follows:\nX(1) = E(1) = a\nX(2) = E(2) = b\nYour 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.\n\n-----Input:-----\nThe first line consists of a single integer T denoting the number of test cases.\nThe first and the only line of each test case consists of three space separated integers a, b and n.\n\n-----Output:-----\nFor each test case print a single integer max(X(n),E(n)).\n\n-----Constraints-----\n- $1 \\leq T \\leq 1000$\n- $2 \\leq a,b,n \\leq 1000000000000$\n\n-----Sample Input:-----\n1\n3 4 2 \n\n-----Sample Output:-----\n4\n\n-----EXPLANATION:-----\nXoronacci Sequence : 3 4 7 \u2026\u2026.\nXNoronacci Sequence : 3 4 0 \u2026\u2026.\nHere n = 2. Hence max(X(2),E(2)) = 4\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\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=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```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n3 4 2\\n', 'output': '4\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/CEFT2020/problems/SERIESTO'}","problem_id":"vfc_5042","program":"```python\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=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```","inputs":"1\n3 4 2\n","output":"4\n","actual_output":"4\n","execution_success":true,"sample_index":1138},{"source":"apps","task_type":"verifiable_code","in_source_id":"1551","prompt":"Solve the following coding problem using the programming language python:\n\n\"I don't have any fancy quotes.\" - vijju123\nChef 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.\nYou are given some quotes. For each quote, you need to tell Chef if it is Real Fancy or just regularly fancy.\n\n-----Input-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The first and only line of each test case contains a single string $S$ denoting a quote.\n\n-----Output-----\nFor each test case, print a single line containing the string \"Real Fancy\" or \"regularly fancy\" (without quotes).\n\n-----Constraints-----\n- $1 \\le T \\le 50$\n- $1 \\le |S| \\le 100$\n- each character of $S$ is either a lowercase English letter or a space\n\n-----Subtasks-----\nSubtask #1 (100 points): original constraints\n\n-----Example Input-----\n2\ni do not have any fancy quotes\nwhen nothing goes right go left\n\n-----Example Output-----\nReal Fancy\nregularly fancy\n\n-----Explanation-----\nExample case 1: \"i do not have any fancy quotes\"\nExample case 2: The word \"not\" does not appear in the given quote.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# 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\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\ni do not have any fancy quotes\\nwhen nothing goes right go left\\n', 'output': 'Real Fancy\\nregularly fancy\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/FANCY'}","problem_id":"vfc_5046","program":"```python\n# 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\n```","inputs":"2\ni do not have any fancy quotes\nwhen nothing goes right go left\n","output":"Real Fancy\nregularly fancy\n","actual_output":"Real Fancy\nregularly fancy\n","execution_success":true,"sample_index":1139},{"source":"apps","task_type":"verifiable_code","in_source_id":"1553","prompt":"Solve the following coding problem using the programming language python:\n\nThe GoC Timber Mafia is notorious for its deforestation\nactivities in the forests near Siruseri. These activities have\nincreased multifold after the death of the bandit who used to\nlord over these jungles. Having lost the battle to prevent the\nMafia from illegally felling the teak trees in this forest, the\ngovernment of Siruseri came up with a novel idea. Why not\nlegalise the deforestation activity and at least make some money\nin the process? So the Government decided to lease out parts of\nthe forest to the Timber Mafia.\nMost of the teak trees in the forests of Siruseri were planted\nduring the colonial times, after the native trees had been cut.\nLike everything European, the forest is very regular and\norderly. It is rectangular in shape and the trees are arranged in\nuniformly spaced rows and coloumns.\nSince the trees differ in height and girth, the timber value\ndiffers from tree to tree. The forest department has collected\ndata on each tree and knows the volume of wood (in cubic feet)\navailable in each tree in the forest.\nThe forest department maintains this information in the form of\nan $M \\times N$ array of integers, where the\n$(i, j)$th entry is the volume, in cubic feet, of the\n$i^{th}$ tree on the $i^{th}$ row (or, equivalently, the\n$i^{th}$ tree on the $i^{th}$ column). We assume that\nour rows are numbered top to bottom and the columns are numbered\nfrom left to right. For example, such an array could look like\n\nThis array tells us that the volume of the tree at position $(3,4)$ is $15$\ncubic feet and so on.\nAny rectangular piece of land with trees at each corner can be\nleased out. In order to fix the lease price for any rectangular\nplot of the forest the forest department needs to know the amount\nof wood available inside the plot.\nA rectangular plot is described by the positions of the trees in\nits top left corner and the bottom right corner. For example the\npositions $(2,2)$ and $(3,4)$ describes the following part\nrectangular part of the above forest.\n\nThe total amount of wood available in this rectangular plot is $76$\ncubic feet. Similarly $(4,2)$ and $(4,2)$ describes the rectangle\nwith just one tree and its volume is $20$ cubic feet.\nYour task is to write a program that helps the forest department\nto compute the total volume of the trees insides any specfied\nrectangular plot.\n\n-----Input:-----\n- The first line of the input contains two integers $M$ and $N$ indicating the number of rows and columns of trees in the forest. \n- 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. \n- Line $M+2$ contains a single integer $C$ indicating the number of rectangles for which the total volume is to be computed. \n- 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)$.\n\n-----Output:-----\nYour 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.\n\n-----Constraints-----\n- In $30 \\%$ of inputs, $1 \\leq C \\leq 100$.\n- In all inputs, $2 \\leq N, M \\leq 1000$ and $1 \\leq C \\leq 1000000$\n- $0 \\leq$ volume of wood in each tree $\\leq 1000$\n- $1 \\leq x_1 \\leq x_2 \\leq M$\n- $1 \\leq y_1 \\leq y_2 \\leq N$\n\n-----Sample Input-----\n4 4 \n3 4 15 23 \n14 20 12 9\n3 8 12 15\n12 20 7 5\n2\n2 2 3 4 \n4 2 4 2\n\n-----Sample Output-----\n76\n20\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# 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)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '4 4\\n3 4 15 23\\n14 20 12 9\\n3 8 12 15\\n12 20 7 5\\n2\\n2 2 3 4\\n4 2 4 2\\n', 'output': '76\\n20\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/IARCSJUD/problems/TIMBER'}","problem_id":"vfc_5054","program":"```python\n# 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)\n```","inputs":"4 4\n3 4 15 23\n14 20 12 9\n3 8 12 15\n12 20 7 5\n2\n2 2 3 4\n4 2 4 2\n","output":"76\n20\n","actual_output":"76\n20\n","execution_success":true,"sample_index":1141},{"source":"apps","task_type":"verifiable_code","in_source_id":"1554","prompt":"Solve the following coding problem using the programming language python:\n\nMeliodas 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.\n\nCan you help Elizabeth predict the total no of chocolates they'll be left with at the end of their war?\n\n-----Input:-----\n- First line will contain $T$, number of testcases. Then the testcases follow. \n- Each testcase contains of a single line of input, which contains two integers $X, Y$, the no of chocolates Meliodas and Ban have, respectively. \n\n-----Output:-----\nFor each testcase, output in a single line the no of chocolates that remain after Ban and Meliodas stop fighting.\n\n-----Constraints-----\n- $1 \\leq T \\leq 100000$\n- $0 \\leq X,Y \\leq 10^9$\n\n-----Sample Input:-----\n3\n\n5 3\n\n10 10\n\n4 8 \n\n-----Sample Output:-----\n2\n\n20\n\n8 \n\n-----EXPLANATION:-----\nDenoting Meliodas as $M$, Ban as $B$.\nTestcase 1:\n$M$=5, $B$=3\n\nBan eates 3 chocolates of Meliodas.\n$M$=2, $B$=3\n\nMeliodas eats 2 chocolates of Ban.\n$M$=2, $B$=1\n\nBan eates 1 chocolate of Meliodas.\n$M$=1, $B$=1\n\nSince they have the same no of candies, they stop quarreling.\n\nTotal candies left: 2 \nTestcase 2:\n$M$=10, $B$=10\n\nSince both of them had the same candies to begin with, there was no point in fighting.\n\nTotal candies left: 20 \nTestcase 3:\n$M$=4, $B$=8\n\nMeliodas eats 4 chocolates of Ban.\n$M$=4, $B$=4\n\nSince they have the same no of candies, they stop quarreling.\n\nTotal candies left: 8\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfrom 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))\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\n5 3\\n10 10\\n4 8\\n', 'output': '2\\n20\\n8\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/SINS'}","problem_id":"vfc_5058","program":"```python\nfrom 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))\n```","inputs":"3\n5 3\n10 10\n4 8\n","output":"2\n20\n8\n","actual_output":"2\n20\n8\n","execution_success":true,"sample_index":1142},{"source":"apps","task_type":"verifiable_code","in_source_id":"1555","prompt":"Solve the following coding problem using the programming language python:\n\nChef is interested to solve series problems. Chef wants to solve a series problem but he can't \nsolve it till now.Can you help Chef to solve the series problem?\n- In series problem, the series goes as follows 1,9,31,73,141 . . . . . . . . \nYour 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$ ).\n\n-----Input:-----\n- First line will contain $T$, number of testcases. Then the testcases follow. \n- Each testcase contains of a single integer $N$. \n\n-----Output:-----\nFor each testcase, output in a single line answer i.e. The $N$th term of series modulo 1000000007.\n\n-----Constraints-----\n- $1 \\leq T \\leq 10^5$\n- $1 \\leq N \\leq 10^9$\n\n-----Sample Input:-----\n2\n\n8\n\n10\n\n-----Sample Output:-----\n561\n\n1081\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# 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\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n8\\n10\\n', 'output': '561\\n1081\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/NOOB2020/problems/NBC004'}","problem_id":"vfc_5062","program":"```python\n# 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\n```","inputs":"2\n8\n10\n","output":"561\n1081\n","actual_output":"561\n1081\n","execution_success":true,"sample_index":1143},{"source":"apps","task_type":"verifiable_code","in_source_id":"1556","prompt":"Solve the following coding problem using the programming language python:\n\nThe 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.\n\n-----Input:-----\n- First-line will contain $T$, the number of test cases. Then the test cases follow. \n- Each test case contains a single line of input, one integer $K$. \n\n-----Output:-----\nFor each test case, output as the pattern.\n\n-----Constraints-----\n- $1 \\leq T \\leq 100$\n- $1 \\leq K \\leq 100$\n\n-----Sample Input:-----\n4\n1\n2\n3\n4\n\n-----Sample Output:-----\n1\n10\n10\n101\n101\n101\n1010\n1010\n1010\n1010\n\n-----EXPLANATION:-----\nNo need, else pattern can be decode easily.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfor _ 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\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '4\\n1\\n2\\n3\\n4\\n', 'output': '1\\n10\\n10\\n101\\n101\\n101\\n1010\\n1010\\n1010\\n1010\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/PTRN2021/problems/ITGUY55'}","problem_id":"vfc_5066","program":"```python\nfor _ 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\n```","inputs":"4\n1\n2\n3\n4\n","output":"1\n10\n10\n101\n101\n101\n1010\n1010\n1010\n1010\n","actual_output":"1\n10\n10\n101\n101\n101\n1010\n1010\n1010\n1010\n","execution_success":true,"sample_index":1144},{"source":"apps","task_type":"verifiable_code","in_source_id":"1557","prompt":"Solve the following coding problem using the programming language python:\n\nChef 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).\nFor 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.\n\n-----Input-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The first line of each test case contains a single integer $N$.\n- The second line contains a binary string $S$.\n- The third line contains a binary string $R$.\n\n-----Output-----\nFor 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).\n\n-----Constraints-----\n- $1 \\le T \\le 400$\n- $1 \\le N \\le 100$\n- $|S| = |R| = N$\n- $S$ and $R$ will consist of only '1' and '0'\n\n-----Example Input-----\n2\n5\n11000\n01001\n3\n110\n001\n\n-----Example Output-----\nYES\nNO\n\n-----Explanation-----\nExample case 1: Chef can perform one operation with $(i, j) = (1, 5)$. Then, $S$ will be \"01001\", which is equal to $R$.\nExample case 2: There is no sequence of operations which would make $S$ equal to $R$.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfor _ 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\")\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n5\\n11000\\n01001\\n3\\n110\\n001\\n', 'output': 'YES\\nNO\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/PLAYSTR'}","problem_id":"vfc_5070","program":"```python\nfor _ 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\")\n```","inputs":"2\n5\n11000\n01001\n3\n110\n001\n","output":"YES\nNO\n","actual_output":"YES\nNO\n","execution_success":true,"sample_index":1145},{"source":"apps","task_type":"verifiable_code","in_source_id":"1558","prompt":"Solve the following coding problem using the programming language python:\n\nAnas 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.\nAnas wants to destroy this grid. To do that, he wants to send two heroes from the top left cell to the bottom right cell:\n- 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)$.\n- 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)$.\nWe 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.\nAnas 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?\n\n-----Input-----\n- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The first and only line of each test case contains two space-separated integers $N$ and $M$.\n\n-----Output-----\nFor each test case, print a single line containing $N \\cdot M$ space-separated integers as described above.\n\n-----Constraints-----\n- $1 \\le T \\le 100$\n- $2 \\le N, M \\le 1,000$\n- the sum of $N \\cdot M$ over all test cases does not exceed $2 \\cdot 10^6$\n\n-----Subtasks-----\nSubtask #1 (30 points):\n- $2 \\le N, M \\le 50$\n- the sum of $N \\cdot M$ over all test cases does not exceed $5,000$\nSubtask #2 (70 points): original constraints\n\n-----Example Input-----\n1\n2 3\n\n-----Example Output-----\n6 4 3 3 2 1\n\n-----Explanation-----\nExample case 1:\n- $K = 0$: All cells will be destroyed by the heroes.\n- $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)]$.\n- $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)]$.\n- $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)]$.\n- $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)]$.\n- $K = 5$ : The first hero will destroy the cell $(1,1)$ and the second one will also destroy the cell $(1,1)$.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n\"\"\"\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\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n2 3\\n', 'output': '6 4 3 3 2 1\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/DESTCELL'}","problem_id":"vfc_5074","program":"```python\n\"\"\"\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\n```","inputs":"1\n2 3\n","output":"6 4 3 3 2 1\n","actual_output":"6 4 3 3 2 1\n","execution_success":true,"sample_index":1146},{"source":"apps","task_type":"verifiable_code","in_source_id":"1559","prompt":"Solve the following coding problem using the programming language python:\n\nScheme? - 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.\n\n-----Input-----\n\nThe 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.\n\n-----Output-----\n\nFor each test case output a single integer in a separate line, the answer for the corresponding test case.\n\n-----Constraints-----1 \u2264 T \u2264 100\n2 \u2264 N \u2264 109\n\n-----Example-----\nInput:\n3\n2\n3\n5\n\nOutput:\n12\n24\n240\n\n-----Explanation-----\nCase 1. For N = 2 days we have the following 12 schedules:\nFirst 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 \n\nCase 2. For N = 3 we have the following 24 schedules:\nFirst 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 \n\nCase 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.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nr = 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\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '3\\n2\\n3\\n5\\n', 'output': '12\\n24\\n240\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/OCT12/problems/NEWSCH'}","problem_id":"vfc_5078","program":"```python\nr = 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\n```","inputs":"3\n2\n3\n5\n","output":"12\n24\n240\n","actual_output":"12\n24\n240\n","execution_success":true,"sample_index":1147},{"source":"apps","task_type":"verifiable_code","in_source_id":"1563","prompt":"Solve the following coding problem using the programming language python:\n\nA 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.\n\n\n-----Input-----\nThe 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.\n\n\n-----Output-----\nFor each case, print exactly one line containing only one integer- the reversed sum of two reversed numbers. Omit any leading zeroes in the output.\n\n\n-----Example-----\nInput:\n1\n24 1\n\nOutput:\n34\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nn = 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)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n24 1\\n', 'output': '34\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/ADR2012/problems/A112'}","problem_id":"vfc_5094","program":"```python\nn = 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)\n```","inputs":"1\n24 1\n","output":"34\n","actual_output":"34\n","execution_success":true,"sample_index":1151},{"source":"apps","task_type":"verifiable_code","in_source_id":"1566","prompt":"Solve the following coding problem using the programming language python:\n\nA matrix B (consisting of integers) of dimension N \u00d7 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.\nYou are given a partially filled matrix B of dimension N \u00d7 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.\n\n-----Input-----\nThe first line of the input contains an integer T denoting the number of test cases. \nThe first line of each test case contains two space separated integers N, Q.\nEach of the next Q lines contain three space separated integers i, j, val, which means that B[i][j] is filled with value val.\n\n-----Output-----\nFor each test case, output \"yes\" or \"no\" (without quotes) in a single line corresponding to the answer of the problem.\n\n-----Constraints-----\n- 1 \u2264 T \u2264 106\n- 2 \u2264 N \u2264 105\n- 1 \u2264 Q \u2264 106\n- 1 \u2264 i, j \u2264 N\n- 0 \u2264 val \u2264 1\n- Sum of each of N, Q over all test cases doesn't exceed 106\n\n-----Subtasks-----\n- Subtask #1 (40 points) 2 \u2264 N \u2264 103, 1 \u2264 Q \u2264 103, Sum of each of N, Q over all test cases doesn't exceed 104\n- Subtask #2 (60 points) Original Constraints\n\n-----Example-----\nInput\n4\n2 2\n1 1 0\n1 2 1\n2 3\n1 1 0\n1 2 1\n2 1 0\n3 2\n2 2 0\n2 3 1\n3 3\n1 2 1\n2 3 1\n1 3 1\n\nOutput\nyes\nno\nyes\nno\n\n-----Explanation-----\nExample 1. You can fill the entries of matrix B as follows. \n\n0 1\n1 0\nThis matrix corresponds to the array A = [1, 2].\n\nExample 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.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nimport 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\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '4\\n2 2\\n1 1 0\\n1 2 1\\n2 3\\n1 1 0\\n1 2 1\\n2 1 0\\n3 2\\n2 2 0\\n2 3 1\\n3 3\\n1 2 1\\n2 3 1\\n1 3 1\\n', 'output': 'yes\\nno\\nyes\\nno\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/FILLMTR'}","problem_id":"vfc_5106","program":"```python\nimport 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\n```","inputs":"4\n2 2\n1 1 0\n1 2 1\n2 3\n1 1 0\n1 2 1\n2 1 0\n3 2\n2 2 0\n2 3 1\n3 3\n1 2 1\n2 3 1\n1 3 1\n","output":"yes\nno\nyes\nno\n","actual_output":"yes\nno\nyes\nno\n","execution_success":true,"sample_index":1154},{"source":"apps","task_type":"verifiable_code","in_source_id":"1567","prompt":"Solve the following coding problem using the programming language python:\n\nAshley likes playing with strings.\n\nShe 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).\n\nShe 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.\n\nAs Mojo is busy playing with cats, solve the problem for him.\n\nPrint \"YES\" (without quotes) if given string can be rearranged to form a \"Doublindrome\" else print \"NO\" (without quotes).\n\n-----Input:-----\n- First line will contain a single integer $T$, the number of testcases. \n- 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$. \n\n-----Output:-----\nFor each testcase, print \"YES\"(without quotes) or \"NO\"(without quotes) on a new line.\n\n-----Constraints-----\n- $1 \\leq T \\leq 10^5$\n- $1 \\leq N \\leq 100$\n- $N$ is always even.\n- String $S$ consists only of lowercase English alphabets.\n\n-----Sample Input:-----\n1\n8\nabbacddc\n\n-----Sample Output:-----\nYES\n\n-----EXPLANATION:-----\nThe given string is a Doublindrome as its 2 halves \"abba\" and \"cddc\" are palindromes.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfor _ 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\")\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n8\\nabbacddc\\n', 'output': 'YES\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/NCC2020/problems/NCC002'}","problem_id":"vfc_5110","program":"```python\nfor _ 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\")\n```","inputs":"1\n8\nabbacddc\n","output":"YES\n","actual_output":"YES\n","execution_success":true,"sample_index":1155},{"source":"apps","task_type":"verifiable_code","in_source_id":"1568","prompt":"Solve the following coding problem using the programming language python:\n\nDhote 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. \n\n-----Input:-----\n- First line will contain T$T$, number of testcases. Then the testcases follow. \n- Each testcase contains of a single line of input, one integers N$N$.\n- next line conatins N$N$ integers that represents weight of bag \n\n-----Output:-----\nFor each testcase, print required answer in new line .\n\n-----Constraints-----\n- 1\u2264T\u22641000$1 \\leq T \\leq 1000$\n- 1\u2264N\u2264105$1 \\leq N \\leq 10^5$\n- 1\u2264weightofbag\u2264105$ 1\\leq weight of bag \\leq 10^5$ \n\n-----Sample Input:-----\n1\n4 \n1 2 3 4\n\n-----Sample Output:-----\n3\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nt=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\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n4\\n1 2 3 4\\n', 'output': '3\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/INEK2019/problems/IF10'}","problem_id":"vfc_5114","program":"```python\nt=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\n```","inputs":"1\n4\n1 2 3 4\n","output":"3\n","actual_output":"3\n","execution_success":true,"sample_index":1156},{"source":"apps","task_type":"verifiable_code","in_source_id":"1569","prompt":"Solve the following coding problem using the programming language python:\n\nDio 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.\nOnly 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 ) \u201cZa Warudo\u201d ,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.\nIn order to stop Dio ,Jotaro asks your help to decipher the code since he can\u2019t do so while fighting Dio at the same time.\nYou 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.\nFor example : \u201cbbbacdaddb\u201d\nshortest substring will be \u201cbacd\u201d and based on the alphabetical ordering\nthe answer is 2134\n\n-----NOTE:-----\nA 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\n\nS[l;r]=SlSl+1\u2026Sr.\n\n-----Input :-----\nThe first line contains $T$,number of test cases.\nThe second line contains a string $S$.\n\n-----Output:-----\nFor each test cases ,output the number you can get from the shortest string \n\n-----Constraints:-----\n$1 \\leq t \\leq 100$\n$1 \\leq |S| \\leq 10^6$\n\n-----Test Cases:-----\n\n-----Sample Input:-----\n6\n\nabcdfgh\n\nurdrdrav\n\njojojojoj\n\nbbbbaaa\n\ncddfsccs\n\ntttttttttttt \n\n-----Sample Output:-----\n1234678\n\n2118418418122\n\n1015\n\n21\n\n46193\n\n20\n\n-----Explanation:-----\nTest case 1: abcdfgh is the shortest substring containing all char of itself and the number is 1234678\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# 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\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '6\\nabcdfgh\\nurdrdrav\\njojojojoj\\nbbbbaaa\\ncddfsccs\\ntttttttttttt\\n', 'output': '1234678\\n2118418418122\\n1015\\n21\\n46193\\n20\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/CSEP2020/problems/JOJOA'}","problem_id":"vfc_5118","program":"```python\n# 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\n```","inputs":"6\nabcdfgh\nurdrdrav\njojojojoj\nbbbbaaa\ncddfsccs\ntttttttttttt\n","output":"1234678\n2118418418122\n1015\n21\n46193\n20\n","actual_output":"1234678\n2118418418122\n1015\n21\n46193\n20\n","execution_success":true,"sample_index":1157},{"source":"apps","task_type":"verifiable_code","in_source_id":"1570","prompt":"Solve the following coding problem using the programming language python:\n\nThe 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.\n\n-----Input:-----\n- First-line will contain $T$, the number of test cases. Then the test cases follow. \n- Each test case contains a single line of input, one integer $N$. \n\n-----Output:-----\nFor each test case, output in a single line answer as maximum squares on plate satisfying the condition.\n\n-----Constraints-----\n- $1 \\leq T \\leq 1000$\n- $1 \\leq N \\leq 10^5$\n\n-----Sample Input:-----\n2\n1\n2 \n\n-----Sample Output:-----\n1\n5\n\n-----EXPLANATION:-----\nFor 1) Only 1 Square\nFor 2) 4 squares with area 1 sq.unit\n1 square with area 4 sq.unit\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# 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```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n1\\n2\\n', 'output': '1\\n5\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/PBK12020/problems/ITGUY18'}","problem_id":"vfc_5122","program":"```python\n# 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```","inputs":"2\n1\n2\n","output":"1\n5\n","actual_output":"1\n5\n","execution_success":true,"sample_index":1158},{"source":"apps","task_type":"verifiable_code","in_source_id":"1571","prompt":"Solve the following coding problem using the programming language python:\n\nChef is making polygon cakes in his kitchen today! \nSince the judge panel is very strict, Chef's cakes must be beautiful and have sharp and precise $internal$ angles in arithmetic progression. \nGiven 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.\n\n-----Input:-----\n- The first line contains a single integer $T$, the number of test cases. \n- 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. \n\n-----Output:-----\nFor 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$\n\n-----Constraints-----\n- $1 \\leq T \\leq 50$\n- $3 \\leq N \\leq 1000$\n- $1 \\leq A \\leq 1000000000$\n- $1 \\leq K \\leq N$\n- It is guaranteed the answer is always valid.\n\n-----Sample Input:-----\n1\n3 30 2\n\n-----Sample Output:-----\n60 1\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# 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)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n3 30 2\\n', 'output': '60 1\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/PCJ18C'}","problem_id":"vfc_5126","program":"```python\n# 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)\n```","inputs":"1\n3 30 2\n","output":"60 1\n","actual_output":"60 1\n","execution_success":true,"sample_index":1159},{"source":"apps","task_type":"verifiable_code","in_source_id":"1573","prompt":"Solve the following coding problem using the programming language python:\n\nA tennis tournament is about to take place with $N$ players participating in it.\nEvery player plays with every other player exactly once and there are no ties. That is, every match has a winner and a loser. \nWith Naman's birthday approaching, he wants to make sure that each player wins the same number of matches so that nobody gets disheartened. \nYour task is to determine if such a scenario can take place and if yes find one such scenario.\n\n-----Input:-----\n- First line will contain $T$, number of testcases. Then the testcases follow. \n- Each testcase contains of a single integer $N$ denoting number of players.\n\n-----Output:-----\n- If it's impossible for everyone to win the same number of matches, print \"NO\" (without quotes).\n- 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$. \n- If the jth character in the ith line is 1 then it means in the match between $i$ and $j$ , $i$ wins. \n- You will get a WA if the output does not correspond to a valid tournament, or if the constraints are not satisfied.\n- You will get also WA verdict if any 2 lines have contradicting results or if a player beats himself.\n\n-----Constraints-----\n- $1 \\leq T \\leq 100$\n- $2 \\leq N \\leq 100$\n\n-----Subtasks-----\n- 10 points : $2 \\leq N \\leq 6$\n- 90 points : Original Constraints. \n\n-----Sample Input:-----\n2\n3\n2\n\n-----Sample Output:-----\nYES\n010\n001\n100\nNO\n\n-----Explanation:-----\nOne 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.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\n# 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)\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '2\\n3\\n2\\n', 'output': 'YES\\n010\\n001\\n100\\nNO\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/EXUNB'}","problem_id":"vfc_5134","program":"```python\n# 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)\n```","inputs":"2\n3\n2\n","output":"YES\n010\n001\n100\nNO\n","actual_output":"YES\n010\n001\n100\nNO\n","execution_success":true,"sample_index":1160},{"source":"apps","task_type":"verifiable_code","in_source_id":"1574","prompt":"Solve the following coding problem using the programming language python:\n\nYou like tracking airplane flights a lot. Specifically, you maintain history of an airplane\u2019s 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 \nyou 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.\n\nYou are interested in finding the maximum integer K such that the plane was at some height exactly K times during the flight.\n\n-----Input-----\nThere is a single test case.\nFirst line of the input contains an integer N denoting the number of records of heights of the plane.\nSecond line contains N space separated integers denoting h1, h2, ..., hN.\n\n-----Output-----\nOutput a single maximum integer K in one line, such that the plane was at some height exactly K times during the flight.\n\n-----Constraints-----\n- hi \u2260 hi+1\n\n-----Subtasks-----\nSubtask #1: (30 points)\n- 1 \u2264 N \u2264 1000\n- 1 \u2264 hi \u2264 1000\n\nSubtask #2: (70 points)\n- 1 \u2264 N \u2264 105\n- 1 \u2264 hi \u2264 109\n\n-----Example-----\nInput:\n5\n1 2 3 2 3\n\nOutput:\n3\n\n-----Explanation-----\n\nThe flight can be draw as:\n\n3 /\\/\n2 /\n1\n\nThere 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.\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\ndef 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))\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '5\\n1 2 3 2 3\\n', 'output': '3\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/problems/FLYMODE'}","problem_id":"vfc_5138","program":"```python\ndef 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))\n```","inputs":"5\n1 2 3 2 3\n","output":"3\n","actual_output":"3\n","execution_success":true,"sample_index":1161},{"source":"apps","task_type":"verifiable_code","in_source_id":"1575","prompt":"Solve the following coding problem using the programming language python:\n\nYou must have tried to solve the Rubik\u2019s cube. You might even have succeeded at it. Rubik\u2019s cube is a 3x3x3 cube which has 6 different color for each face.The Rubik\u2019s 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.\n\nApple has come up with a variation of the Rubik\u2019s Cube, it\u2019s the Rubik\u2019s cuboid which has different colors on its 6 faces. The Rubik\u2019s Cuboid comes in various sizes represented by M x N x O (M,N,O are natural numbers). Apple is giving away 100 Rubik\u2019s cuboid for free to people who can answer a simple questions. Apple wants to know, in a Rubik\u2019s cuboid with arbitrary dimensions, how many cubies would be there, which comprise of exactly 2 color.\n\n-----Input-----\nThe input contains several test cases.The first line of the input contains an integer T denoting the number of test cases.\n\nEach test case comprises of 3 natural numbers, M,N & O, which denote the dimensions of the Rubiks Cuboid.\n\n-----Output-----\nFor 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.\n\n-----Constraints-----\n- 1 \u2264 T \u2264 <1000\n- 1 \u2264 M \u2264 <100000\n- 1 \u2264 N \u2264 <100000\n- 1 \u2264 O \u2264 <100000\n\n-----Example-----\nInput:\n1\n3\n3\n3\n\nOutput:\n\n12\n\nThe input will be stdin and you should print your solution to stdout\n\n\nNow solve the problem and return the code.","gold_standard_solution":"```python\nfor _ 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\n```","verification_info":"{'test_cases': [{'type': 'stdin_stdout', 'input': '1\\n3\\n3\\n3\\n', 'output': '12\\n'}], 'language': 'python'}","metadata":"{'difficulty': 'interview', 'problem_url': 'https://www.codechef.com/INLO2016/problems/INLO22'}","problem_id":"vfc_5142","program":"```python\nfor _ 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\n```","inputs":"1\n3\n3\n3\n","output":"12\n","actual_output":"12\n","execution_success":true,"sample_index":1162}]