name
stringlengths 2
112
| description
stringlengths 29
9.39k
| public_tests
dict | private_tests
dict | generated_tests
dict | source
int64 1
6
| difficulty
int64 0
23
| solutions
dict | cf_contest_id
int64 0
1.55k
| cf_index
stringclasses 39
values | cf_points
float64 0
5k
| cf_rating
int64 0
3.5k
| cf_tags
sequencelengths 0
8
| is_description_translated
bool 2
classes | time_limit
null | memory_limit_bytes
int64 0
1.07B
|
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
brcktsrm | Problem description.
Vipul is a hardworking super-hero who maintains the bracket ratio of all the strings in the world. Recently he indulged himself in saving the string population so much that he lost his ability for checking brackets (luckily, not permanently ).Being his super-hero friend help him in his time of hardship.
Input
The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.
The first line of each test case contains a single string S denoting the string to be checked.
Output
For each test case, output a single line printing "YES" or "NO" (without " " and in uppercase only) , denoting if the brackets in the given string is balanced or not .
Constraints
1 ≤ T ≤ 10
1 ≤ length of S ≤ 60
Example
Input:
3
((()))
(())()
()(()
Output:
YES
YES
NO
Explanation
Example is self-explanatory. | {
"input": [
"3\n((()))\n(())()\n()(()"
],
"output": [
"YES\nYES\nNO"
]
} | {
"input": [],
"output": []
} | {
"input": [
"3\n((()))\n(())()\n()())",
"3\n((()()\n(())()\n()(()",
"3\n((()))\n(())))\n()())",
"3\n)))(((\n(())))\n()())",
"3\n((()))\n(())()\n))(((",
"3\n((()()\n(())()\n()(((",
"3\n((()))\n(())()\n()()(",
"3\n((()()\n'())()\n()(((",
"3\n)))(((\n(())))\n()(*)",
"3\n)(()()\n'())()\n()(((",
"3\n))*(((\n(())))\n()(*)",
"3\n)()(()\n'())()\n()(((",
"3\n)*)(((\n(())))\n()(*)",
"3\n)()())\n'())()\n()(((",
"3\n)*)(((\n(()())\n()(*)",
"3\n)()())\n'()())\n()(((",
"3\n)*)(((\n(()())\n))(*(",
"3\n)()()(\n'()())\n()(((",
"3\n)()(*(\n(()())\n))(*(",
"3\n)()()(\n))()('\n()(((",
"3\n)()(*(\n(())))\n))(*(",
"3\n)')()(\n))()('\n()(((",
"3\n)()(*(\n(())))\n))()(",
"3\n)')()(\n)(())'\n()(((",
"3\n)()(*(\n(())))\n()())",
"3\n))'()(\n)(())'\n()(((",
"3\n)('()(\n)(())'\n()(((",
"3\n)('()(\n)('))(\n()(((",
"3\n)('()(\n)('))(\n')(((",
"3\n)('()(\n())'()\n')(((",
"3\n)('()(\n)())'(\n')(((",
"3\n)('()(\n)())'(\n((()'",
"3\n)('()(\n))))'(\n((()'",
"3\n((()))\n)())()\n()(()",
"3\n)))(((\n(())()\n()())",
"3\n((()()\n(())()\n()(')",
"3\n)))(((\n(())()\n))(((",
"3\n)((())\n(())))\n()())",
"3\n((()()\n(())()\n((()(",
"3\n((()))\n(())()\n')()(",
"3\n)))(()\n(())))\n()())",
"3\n((()()\n&())()\n()(((",
"3\n)))(((\n))))((\n()(*)",
"3\n)(()()\n'())()\n(((((",
"3\n))*(((\n(())))\n)*()(",
"3\n)()(()\n'())((\n()(((",
"3\n)*)(((\n(())))\n*)(()",
"3\n)()())\n'())()\n()('(",
"3\n)*)(((\n))()((\n()(*)",
"3\n)')())\n'()())\n()(((",
"3\n)()()(\n'()())\n()()(",
"3\n)()(*(\n(()())\n))(*)",
"3\n)()()(\n))()('\n((()(",
"3\n)')')(\n))()('\n()(((",
"3\n)()(*(\n(())))\n)())(",
"3\n()()')\n)(())'\n()(((",
"3\n(*)(()\n(())))\n()())",
"3\n))'()(\n'))(()\n()(((",
"3\n)('(((\n)(())'\n()(((",
"3\n)('()(\n((')))\n()(((",
"3\n)('()(\n)('))(\n')()(",
"3\n)('()(\n())'()\n((()'",
"3\n)('()(\n)())((\n')(((",
"3\n)('()(\n)())'(\n((()(",
"3\n()('))\n))))'(\n((()'",
"3\n((())(\n)())()\n()(()",
"3\n)))(((\n)())()\n()())",
"3\n((()()\n(()(()\n()(')",
"3\n)))(((\n(())()\n*)(((",
"3\n)((())\n'())))\n()())",
"3\n((()()\n(())()\n()()(",
"3\n((()))\n)()(()\n')()(",
"3\n)))((*\n(())))\n()())",
"3\n()((()\n&())()\n()(((",
"3\n)))(((\n))))((\n(*(*)",
"3\n)(()()\n)())('\n(((((",
"3\n))*(((\n()()))\n)*()(",
"3\n)()())\n'())()\n()(''",
"3\n)')())\n'()())\n((()(",
"3\n)()()(\n&()())\n()()(",
"3\n)()(*(\n(()())\n*)(*)",
"3\n)()()(\n))()('\n(())(",
"3\n)')')(\n))()('\n()(('",
"3\n)()(*(\n(())))\n)()((",
"3\n)')())\n)(())'\n()(((",
"3\n)*)(()\n(())))\n()())",
"3\n))'()(\n'))((*\n()(((",
"3\n)('(((\n)(())'\n()(('",
"3\n)('()(\n((')))\n(((((",
"3\n)('()'\n)('))(\n')()(",
"3\n)('()(\n)())((\n')('(",
"3\n)('()(\n'()))(\n((()(",
"3\n()('))\n('))))\n((()'",
"3\n((())(\n*())()\n()(()",
"3\n)))(((\n)())()\n((())",
"3\n((()))\n(())()\n*)(((",
"3\n)((())\n'())))\n()'))",
"3\n((()()\n(())()\n')()(",
"3\n((()))\n)()(()\n()()'",
"3\n)))((*\n(())))\n))())"
],
"output": [
"YES\nYES\nNO\n",
"NO\nYES\nNO\n",
"YES\nNO\nNO\n",
"NO\nNO\nNO\n",
"YES\nYES\nNO\n",
"NO\nYES\nNO\n",
"YES\nYES\nNO\n",
"NO\nNO\nNO\n",
"NO\nNO\nNO\n",
"NO\nNO\nNO\n",
"NO\nNO\nNO\n",
"NO\nNO\nNO\n",
"NO\nNO\nNO\n",
"NO\nNO\nNO\n",
"NO\nYES\nNO\n",
"NO\nNO\nNO\n",
"NO\nYES\nNO\n",
"NO\nNO\nNO\n",
"NO\nYES\nNO\n",
"NO\nNO\nNO\n",
"NO\nNO\nNO\n",
"NO\nNO\nNO\n",
"NO\nNO\nNO\n",
"NO\nNO\nNO\n",
"NO\nNO\nNO\n",
"NO\nNO\nNO\n",
"NO\nNO\nNO\n",
"NO\nNO\nNO\n",
"NO\nNO\nNO\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NO\nYES\nNO\n",
"YES\nNO\nNO\n",
"NO\nNO\nNO\n"
]
} | 1 | 6 | {
"language": [
1,
1,
1
],
"solution": [
"for _ in range(input()):\n try:\n eval(raw_input())\n print 'YES'\n except TypeError:\n print 'YES'\n except:\n print 'NO'",
"for _ in range(input()):\n ins = raw_input().strip()\n stck = []\n res = \"YES\"\n for x in ins:\n if x == \"(\":\n stck.append(x)\n else:\n if len(stck)>0:\n stck.pop()\n else:\n res = \"NO\"\n break\n if len(stck) > 0: res = \"NO\" \n print res",
"for _ in range(input()):\n try: eval(raw_input()); print 'YES'\n except TypeError: print 'YES'\n except: print 'NO'"
]
} | 0 | 0 | 0 | [] | false | null | 0 |
|
comm3 | The Chef likes to stay in touch with his staff. So, the Chef, the head server, and the sous-chef all carry two-way transceivers so they can stay in constant contact. Of course, these transceivers have a limited range so if two are too far apart, they cannot communicate directly.
The Chef invested in top-of-the-line transceivers which have a few advanced features. One is that even if two people cannot talk directly because they are out of range, if there is another transceiver that is close enough to both, then the two transceivers can still communicate with each other using the third transceiver as an intermediate device.
There has been a minor emergency in the Chef's restaurant
and he needs to communicate with both the head server and the sous-chef right away. Help the Chef determine if it is possible for all three people to communicate with each other, even if two must communicate through the third because they are too far apart.
Input
The first line contains a single positive integer T ≤ 100 indicating the number of test cases to follow. The first line of each test case contains a positive integer R ≤ 1,000 indicating that two transceivers can communicate directly without an intermediate transceiver if they are at most R meters away from each other. The remaining three lines of the test case describe the current locations of the Chef, the head server, and the sous-chef, respectively. Each such line contains two integers X,Y (at most 10,000 in absolute value) indicating that the respective person is located at position X,Y.
Output
For each test case you are to output a single line containing a single string. If it is possible for all three to communicate then you should output "yes". Otherwise, you should output "no".
To be clear, we say that two transceivers are close enough to communicate directly if the length of the straight line connecting their X,Y coordinates is at most R.
Example
Input:
3
1
0 1
0 0
1 0
2
0 1
0 0
1 0
2
0 0
0 2
2 1
Output:
yes
yes
no | {
"input": [
"3\n1\n0 1\n0 0\n1 0\n2\n0 1\n0 0\n1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 2\n1 1",
"3\n4\n0 -1\n-1 -1\n1 1\n2\n0 -1\n0 0\n2 -1\n2\n2 0\n1 2\n0 1"
],
"output": [
"no\nyes\nno\n",
"yes\nyes\nno\n",
"yes\nyes\nyes\n",
"no\nyes\nyes\n",
"no\nno\nyes\n",
"yes\nno\nyes\n",
"no\nno\nno\n",
"yes\nno\nno\n",
"yes\nyes\nno\n",
"yes\nyes\nno\n",
"yes\nyes\nno\n",
"yes\nyes\nno\n",
"yes\nyes\nyes\n",
"yes\nyes\nyes\n",
"yes\nyes\nyes\n",
"yes\nyes\nyes\n",
"yes\nyes\nyes\n",
"yes\nyes\nyes\n",
"no\nyes\nyes\n",
"no\nyes\nyes\n",
"no\nyes\nyes\n",
"no\nno\nyes\n",
"no\nno\nyes\n",
"yes\nyes\nno\n",
"no\nyes\nno\n",
"yes\nyes\nno\n",
"yes\nyes\nno\n",
"yes\nyes\nno\n",
"yes\nyes\nno\n",
"yes\nyes\nyes\n",
"yes\nyes\nyes\n",
"yes\nyes\nyes\n",
"yes\nyes\nyes\n",
"no\nyes\nyes\n",
"yes\nyes\nyes\n",
"yes\nyes\nyes\n",
"no\nyes\nyes\n",
"no\nyes\nyes\n",
"no\nyes\nyes\n",
"no\nyes\nyes\n",
"no\nno\nyes\n",
"no\nno\nyes\n",
"yes\nyes\nno\n",
"yes\nyes\nno\n",
"yes\nyes\nno\n",
"yes\nyes\nno\n",
"yes\nyes\nyes\n",
"yes\nyes\nyes\n",
"yes\nyes\nyes\n",
"no\nyes\nyes\n",
"yes\nyes\nyes\n",
"yes\nyes\nyes\n",
"no\nyes\nyes\n",
"no\nno\nyes\n",
"no\nno\nyes\n",
"yes\nno\nyes\n",
"no\nno\nyes\n",
"yes\nyes\nno\n",
"yes\nyes\nno\n",
"yes\nyes\nno\n",
"yes\nyes\nno\n",
"yes\nyes\nyes\n",
"yes\nyes\nyes\n",
"no\nyes\nno\n",
"yes\nno\nyes\n",
"yes\nyes\nyes\n",
"no\nyes\nyes\n",
"no\nno\nyes\n",
"no\nno\nyes\n",
"yes\nno\nyes\n",
"no\nno\nyes\n",
"yes\nyes\nno\n",
"yes\nyes\nno\n",
"yes\nyes\nno\n",
"yes\nyes\nyes\n",
"yes\nyes\nyes\n",
"yes\nyes\nno\n",
"no\nyes\nno\n",
"yes\nno\nyes\n",
"yes\nyes\nyes\n",
"no\nyes\nyes\n",
"no\nno\nyes\n",
"yes\nno\nyes\n",
"no\nno\nyes\n",
"yes\nyes\nno\n",
"yes\nyes\nno\n",
"yes\nyes\nyes\n",
"yes\nyes\nyes\n",
"yes\nyes\nno\n",
"no\nno\nyes\n",
"yes\nyes\nyes\n",
"no\nyes\nyes\n",
"no\nno\nyes\n",
"yes\nno\nyes\n",
"no\nno\nyes\n",
"yes\nyes\nno\n",
"yes\nyes\nno\n",
"yes\nyes\nyes\n",
"yes\nyes\nyes\n",
"yes\nyes\nno\n"
]
} | 1 | 1 | {
"language": [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
],
"solution": [
"import math\nno_of_testcases = int(input())\nfor each in range(no_of_testcases):\n dist = int(input())\n point_1 = map(int,raw_input().split())\n point_2 = map(int,raw_input().split())\n point_3 = map(int,raw_input().split()) \n point_12 =math.sqrt( math.pow((point_1[0] -point_2[0]),2) + math.pow((point_1[1] -point_2[1]),2))\n point_23 =math.sqrt( math.pow((point_2[0] -point_3[0]),2) + math.pow((point_2[1] -point_3[1]),2))\n point_31 =math.sqrt( math.pow((point_3[0] -point_1[0]),2) + math.pow((point_3[1] -point_1[1]),2))\n count =0\n if point_12 <= dist:\n count =count+1\n if point_23 <= dist:\n count =count+1\n if point_31 <= dist:\n count =count+1\n if count >=2:\n print \"yes\"\n else:\n print \"no\"",
"def distance(x1,y1,x2,y2):\n dist = ((x1-x2)**2 + (y1-y2)**2)**0.5\n return dist\n\n\nt = input()\nfor i in range(t):\n r = input()\n chef_x,chef_y = map(int,raw_input().split(' '))\n head_server_x,head_server_y = map(int,raw_input().split(' '))\n sous_chef_x,sous_chef_y = map(int,raw_input().split(' '))\n \n chef_head_server_distance = distance(chef_x,chef_y,head_server_x,head_server_y)\n chef_sous_chef_distance = distance(chef_x,chef_y,sous_chef_x,sous_chef_y)\n sous_chef_head_server_distance = distance(sous_chef_x, sous_chef_y, head_server_x, head_server_y)\n \n communicate = 0\n \n if(chef_head_server_distance <= r):\n communicate+=1\n if(chef_sous_chef_distance <= r):\n communicate+=1\n if(sous_chef_head_server_distance <= r):\n communicate+=1\n \n if(communicate >= 2):\n print \"yes\"\n else:\n print \"no\"",
"#COMM3\ntest = input()\nwhile test > 0:\n test -= 1\n dist = input()**2\n a,b = map(int, raw_input().split())\n c,d = map(int, raw_input().split())\n e,f = map(int, raw_input().split())\n dist1 = (a-c)**2 + (b-d)**2\n dist2 = (a-e)**2 + (b-f)**2\n dist3 = (c-e)**2 + (d-f)**2 \n if (dist1 <= dist and dist2 <=dist) or (dist2 <= dist and dist3 <=dist) or (dist1 <= dist and dist3 <=dist):\n print \"yes\"\n else:\n print \"no\"",
"from sys import stdin as ip\nfor _ in xrange(int(ip.readline())):\n r=int(ip.readline())**2\n a,b=map(int,ip.readline().split())\n x,y=map(int,ip.readline().split())\n p,q=map(int,ip.readline().split())\n d1=pow(x-a,2)+pow(y-b,2)\n d2=pow(p-x,2)+pow(q-y,2)\n d3=pow(p-a,2)+pow(q-b,2)\n if d1<=r and d2<=r or d2<=r and d3<=r or d1<=r and d3<=r:\n print \"yes\"\n else:\n print \"no\"",
"import math as m\ndef leng(a,c,b,d):\n return m.sqrt(((a-c)**2)+((b-d)**2))\nt=input()\nans=[]\nfor i in range(t):\n n=input()\n x1,y1=raw_input().split()\n x2,y2=raw_input().split()\n x3,y3=raw_input().split()\n d1=leng(int(x1),int(x2),int(y1),int(y2))\n d2=leng(int(x1),int(x3),int(y1),int(y3))\n d3=leng(int(x3),int(x2),int(y3),int(y2))\n l=[d1,d2,d3]\n l.sort()\n if l[0]<=n and l[1]<=n and l[0]+l[1]>=l[2]:\n ans.append('yes')\n else:\n ans.append('no')\nfor i in range(t):\n print ans[i]",
"t=input()\ndef dist(a,b,c,d):\n return (((a-c)**2)+((b-d)**2))**0.5\nfor i in range(0,t):\n r=input()\n e=[]\n for j in range(0,3):\n e.append(map(int,raw_input().split(' ')))\n if dist(e[0][0],e[0][1],e[2][0],e[2][1])<=r:\n print \"yes\"\n elif dist(e[0][0],e[0][1],e[1][0],e[1][1])<=r and dist(e[1][0],e[1][1],e[2][0],e[2][1])<=r:\n print \"yes\"\n else:\n print \"no\"",
"# -*- coding: utf-8 -*-\n\"\"\"\nCreated on Wed Mar 16 12:29:47 2016\n\n@author: matteoarno\n\"\"\"\n\nimport sys\n\ndata = sys.stdin.readlines()\nt = int(data.pop(0))\noutput = []\n\nfor i in range(t):\n r = int(data.pop(0))\n chef = map(int,(data.pop(0).split(' ')))\n head = map(int,(data.pop(0).split(' ')))\n sous = map(int,(data.pop(0).split(' ')))\n \n def distance (first, second):\n dist = ((first[0]-second[0])**2 + (first[1]-second[1])**2)**(0.5)\n return dist\n \n ch = distance(chef, head)\n hs = distance(head, sous)\n cs = distance(chef, sous)\n \n if ch > r:\n if (hs <= r and cs <= r):\n output.append('yes')\n else:\n output.append('no')\n else:\n if (hs <= r or cs <= r):\n output.append('yes')\n else:\n output.append('no')\n\nfor k in output:\n print k",
"import math\n\ndef cal_dist(x1,y1,x2,y2):\n\tdis = math.sqrt(((x1-x2)**2)+((y1-y2)**2))\n\treturn dis\n\ntest = int(input())\nwhile test:\n\tR = int(input())\n\tcx1,cy1=map(int, raw_input().split())\n\tcx2,cy2=map(int, raw_input().split())\n\tcx3,cy3=map(int, raw_input().split())\n\td1 = cal_dist(cx1,cy1,cx2,cy2)\n\td2 = cal_dist(cx1,cy1,cx3,cy3)\n\td3 = cal_dist(cx3,cy3,cx2,cy2)\n\tif((d1<=R and d2<=R) or (d1<=R and d3<=R) or (d3<=R and d2<=R)):\n\t\tprint \"yes\"\n\telse:\n\t\tprint \"no\"\n\ttest = test-1",
"import math\ndef distance(x1, y1, x2, y2):\n return math.sqrt((x2-x1)**2 + (y2-y1)**2)\n\nimport math\nn = int(raw_input())\nrs = []\nwhile n != 0:\n max_d = int(raw_input())\n p1 = map(int,raw_input().split())\n p2 = map(int,raw_input().split())\n p3 = map(int,raw_input().split())\n ds = []\n ds.append(distance(p1[0], p1[1], p2[0], p2[1]))\n ds.append(distance(p1[0], p1[1], p3[0], p3[1]))\n ds.append(distance(p2[0], p2[1], p3[0], p3[1]))\n ds = sorted(ds)\n if ds[0] <= max_d and ds[1] <= max_d:\n rs.append(\"yes\")\n else:\n rs.append(\"no\")\n n -= 1\n\nfor i in rs:\n print i",
"class Solution:\n\tdef threeWayComm(self):\n\t\tt = int(raw_input())\n\t\n\t\twhile t > 0:\n\t\t\tr = int(raw_input())\n\t\t\tif r <= 0 or r > 1000:\n\t\t\t\tbreak\n\t\t\tx1, y1 = map(int, raw_input().split())\n\t\t\tx2, y2 = map(int, raw_input().split())\n\t\t\tx3, y3 = map(int, raw_input().split())\n\n\t\t\tif x1 > 10000 or y1 > 10000 or x2 > 10000 or y2 > 10000 or x3 > 10000 or y3 > 10000:\n\t\t\t\tbreak;\n\t\t\tcount = 0\n\t\t\tif self.isClose(x1, y1, x2, y2, r):\n\t\t\t\tcount+=1\n\t\t\tif self.isClose(x2, y2, x3, y3, r):\n\t\t\t\tcount+=1\n\t\t\tif self.isClose(x3, y3, x1, y1, r):\n\t\t\t\tcount+=1\t\n\n\t\t\tif count >=2:\n\t\t\t\tprint \"yes\"\n\t\t\telse:\n\t\t\t\tprint \"no\"\n\n\t\t\tt -= 1\n\n\tdef isClose(self, a, b, c, d, r):\n\t\treturn (a-c)**2 + (b-d)**2 <= r**2\n\ns = Solution()\ns.threeWayComm()",
"from math import hypot\nt = input()\nfor _ in xrange(t):\n r = input()\n x1, y1 = map(int, raw_input().split())\n x2, y2 = map(int, raw_input().split())\n x3, y3 = map(int, raw_input().split())\n ab = hypot(x1 - x2, y1 - y2)\n bc = hypot(x2 - x3, y2 - y3)\n ac = hypot(x3 - x1, y3 - y1)\n if (ab <= r and bc <= r) or (ab <= r and ac <= r) or (bc <= r and ac <= r):\n print \"yes\"\n else:\n print \"no\"",
"from math import sqrt\n\ndef dist(x1,y1,x2,y2):\n\ta=(abs(x1-x2))**2\n\tb=(abs(y1-y2))**2\n\treturn sqrt(a+b)\n\nfor testcases in xrange(int(raw_input())):\n\tr=int(raw_input())\n\tx=[]\n\ty=[]\n\tc=0\n\tfor i in xrange(3):\n\t\ta,b=map(int,raw_input().split())\n\t\tx.append(a)\n\t\ty.append(b)\n\tif dist(x[0],y[0],x[1],y[1]) <= r:\n\t\tc+=1\n\tif dist(x[1],y[1],x[2],y[2]) <= r:\n\t\tc+=1\n\tif dist(x[0],y[0],x[2],y[2]) <= r:\n\t\tc+=1\n\tif c>=2:\n\t\tprint 'yes'\n\telse:\n\t\tprint 'no'",
"import math\n\nt = int(input())\nl = []\n\nwhile(t):\n r = int(input())\n l = list(map(int, raw_input().split()))\n x1 = l[0]\n y1 = l[1]\n l = list(map(int, raw_input().split()))\n x2 = l[0]\n y2 = l[1]\n l = list(map(int, raw_input().split()))\n x3 = l[0]\n y3 = l[1]\n d1 = math.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2)\n d2 = math.sqrt((x3 - x2) ** 2 + (y3 - y2) ** 2)\n d3 = math.sqrt((x1 - x3) ** 2 + (y1 - y3) ** 2)\n\n if((d1 <= r) and (d2 <= r) and (d3 <= r)):\n print \"yes\"\n elif ((d1 <= r) and (d2 <= r) or (d2 <= r) and (d3 <= r) or (d3 <= r) and (d1 <= r)):\n print \"yes\"\n else:\n print \"no\"\n t -= 1",
"from math import hypot\nT=int(raw_input())\nfor t in range(T):\n R=int(raw_input())\n x1,y1=map(int,raw_input().split())\n x2,y2=map(int,raw_input().split())\n x3,y3=map(int,raw_input().split())\n dist_1=hypot(x2-x1,y2-y1)\n dist_2=hypot(x3-x2,y3-y2)\n dist_3=hypot(x3-x1,y3-y1)\n if (dist_1 <=R and dist_2 <=R) or (dist_2<=R and dist_3<=R) or (dist_1<=R and dist_3<=R):\n print \"yes\"\n else:\n print \"no\"",
"def commute():\n for i in range(int(raw_input())):\n j =int(raw_input())\n a = []\n for i in range(3):\n a.append((map(int,raw_input().split())))\n print \"yes\" if len([i for i in chek(a) if i<=j]) >= 2 else \"no\"\n \n\n \ndef chek(a):\n return [((a[t][0] - a[(t+1)%3][0])**2 + (a[t][1] - a[(t+1)%3][1])**2)**0.5 for t in range(len(a))]\n \ncommute()",
"'''input\n3\n1\n0 1\n0 0\n1 0\n2\n0 1\n0 0\n1 0\n2\n0 0\n0 2\n2 1\n'''\n\nfrom math import sqrt\ndef solve(a, b): return sqrt((a[0] - b[0]) ** 2 + (a[1] - b[1]) ** 2)\n\nfor T in range(input()):\n\td, coords = input(), [[int(i) for i in raw_input().rstrip().split()] for j in range(3)]\n\tdists = []\n\tdists.append(solve(coords[0], coords[1]))\n\tdists.append(solve(coords[1], coords[2]))\n\tdists.append(solve(coords[2], coords[0]))\n\tprint 'yes' if len(filter(lambda x: x <= d, dists)) >= 2 else 'no'",
"def dist(x,y,r):\n if ((x[0]-y[0])**2 + (x[1]-y[1])**2)**(0.5) <= r:\n return 1\n else:\n return 0\nt = int(raw_input())\nfor i in xrange(t):\n r = float(raw_input())\n x = list()\n for q in xrange(3):\n x += [map(float,raw_input().strip().split())]\n isposs = 0\n isposs = dist(x[0],x[1],r) + dist(x[0],x[2],r) + dist(x[1],x[2],r)\n print 'yes' if (isposs >= 2) else 'no'",
"def diff(a,b,c,d) :\n return float(((a-c)**2 + (b-d)**2)**0.5)\nfor i in xrange(int(raw_input())) :\n k = int(raw_input().strip())\n k = float(k)\n l = []\n for j in xrange(3) :\n l.append(map(int,raw_input().split(' ')))\n diff_12 = diff(l[0][0],l[0][1],l[1][0],l[1][1])\n diff_23 = diff(l[1][0],l[1][1],l[2][0],l[2][1])\n diff_13 = diff(l[0][0],l[0][1],l[2][0],l[2][1])\n if (diff_12 <= k) and (diff_23 <= k) :\n print 'yes'\n elif (diff_13 <= k) and (diff_23 <= k) :\n print 'yes'\n elif (diff_12 <= k) and (diff_13 <= k) :\n print 'yes'\n else :\n print 'no'",
"# -*- coding: utf-8 -*-\n\"\"\"\nCreated on Wed Jan 27 22:23:20 2016\n\n@author: shashank\n\"\"\"\nimport sys\nimport math\n\ndef distance(x,y):\n return math.sqrt((x[0] - y[0])**2 + (x[1] - y[1])**2)\n \nT = input()\nfor i in range(T):\n R = input()\n chef = [int(x) for x in sys.stdin.readline().split()]\n head = [int(x) for x in sys.stdin.readline().split()]\n sous = [int(x) for x in sys.stdin.readline().split()]\n dist1 = distance(chef,head)\n dist2 = distance(chef,sous)\n dist3 = distance(sous,head)\n if ((dist1 <= R and dist2 <= R) or (dist1 <= R and dist3 <= R) or (dist2 <= R and dist3 <= R)):\n print \"yes\"\n else:\n print \"no\"",
"def out_of_reach(xyA, xyB, reach):\n return ((xyB[0]-xyA[0])**2 + (xyB[1]-xyA[1])**2)**.5 > reach\n \nfor tests in xrange(int(raw_input())):\n r = int(raw_input())\n coordinates = []\n for _ in range(3):\n coordinates.append(map(int, raw_input().split()))\n for pair in coordinates:\n t_coordinates = coordinates[:]\n t_coordinates.remove(pair)\n if len([t_pair for t_pair in t_coordinates if out_of_reach(pair, t_pair, r)]) == 2:\n print 'no'\n break\n else:\n print 'yes'",
"t=int(raw_input())\nfor k in range(t):\n a=[[],[],[]]\n r=int(raw_input())\n for j in range (3):\n b=map(int,raw_input().split())\n a[j].append(b[0])\n a[j].append(b[1])\n f=0\n for j in range(3):\n if (pow((a[j][0]-a[(j+1)%3][0]),2)+pow((a[j][1]-a[(j+1)%3][1]),2))<=(float)(r*r) and (pow((a[j][0]-a[(j+2)%3][0]),2)+pow((a[j][1]-a[(j+2)%3][1]),2))<=(float)(r*r):\n f=1\n break;\n if f==1:\n print \"yes\"\n else:\n print \"no\"",
"#!/usr/bin/python\nfrom math import sqrt\nN=input()\nfor i in range(N):\n\tR=input()\n\tx,y=map(int,raw_input().split())\n\tp,q=map(int,raw_input().split())\n\ta,b=map(int,raw_input().split())\n\tl=sqrt(((x-p)**2)+((y-q)**2))\n\tm=sqrt(((x-a)**2)+((y-b)**2))\n\tn=sqrt(((a-p)**2)+((b-q)**2))\n\t#print \"(%0.2f %0.2f)->(%0.2f %0.2f) = %0.2f \" %(x,y,p,q,l)\n\t#print \"(%0.2f %0.2f)->(%0.2f %0.2f) = %0.2f \" %(x,y,a,b,m)\n\t#print \"(%0.2f %0.2f)->(%0.2f %0.2f) = %0.2f \" %(p,q,a,b,n)\n\tcount=0\n\tif l>R:\n\t\tcount+=1\n\tif m>R:\n\t\tcount+=1\n\tif n>R:\n\t\tcount+=1\n\tif count>=2:\n\t\tprint \"no\"\n\telse:\n\t\tprint \"yes\"",
"def distance(t1,t2):\n return ((t1[0]-t2[0])**2+(t1[1]-t2[1])**2)**0.5\n\nt = int(input())\nfor test in xrange(t):\n r = int(input())\n x1,y1 = map(int,raw_input().split())\n x2,y2 = map(int,raw_input().split())\n x3,y3 = map(int,raw_input().split())\n dis_list = map(distance,[(x1,y1),(x1,y1),(x3,y3)],[(x2,y2),(x3,y3),(x2,y2)])\n fil_list = filter(lambda x:x>r,dis_list)\n if len(fil_list)<2:\n print \"yes\"\n else:\n print \"no\"",
"def checker( pt1, pt2, R ) :\n dist2 = ( ( (pt1[0] - pt2[0]) **2 ) + ( (pt1[1] - pt2[1]) **2 ) )\n return True if (dist2 <= (R**2)) else False\n\nfor testcases in xrange(int(raw_input() ) ) :\n maxD = int( raw_input() )\n A = map(int, raw_input().split() )\n B = map(int, raw_input().split() )\n C = map(int, raw_input().split() )\n commList = [ checker(A, B, maxD), checker(B, C, maxD), checker(C, A, maxD) ]\n print 'yes' if commList.count(True) > 1 else 'no'",
"def is_in_range(x1, y1, x2, y2, limit):\n if((x1-x2)*(x1-x2)+((y1-y2)*(y1-y2)) <= limit*limit):\n return 1\n else:\n return 0\n \ntc=int(raw_input())\nfor _ in range(tc):\n limit=int(raw_input())\n x1, y1=map(int, raw_input().split())\n x2, y2=map(int, raw_input().split())\n x3, y3=map(int, raw_input().split())\n if(is_in_range(x1, y1, x2, y2,limit) + is_in_range(x1, y1, x3, y3, limit) + is_in_range(x2, y2, x3, y3, limit) > 1):\n print \"yes\"\n else:\n print \"no\"",
"def dis(x1,y1,x2,y2):\n dist=(((x1-x2)**2)+((y1-y2)**2))\n return dist\nt=int(raw_input())\nwhile(t>0):\n x=0\n r=int(raw_input())\n chefx,chefy=raw_input().split()\n chefx,chefy=[int(chefx),int(chefy)]\n headx,heady=raw_input().split()\n headx,heady=[int(headx),int(heady)]\n sousx,sousy=raw_input().split()\n sousx,sousy=[int(sousx),int(sousy)]\n if(dis(chefx,chefy,headx,heady)<=r*r):\n x=x+1\n if(dis(chefx,chefy,sousx,sousy)<=r*r):\n x=x+1\n if(dis(sousx,sousy,headx,heady)<=r*r):\n x=x+1\n if(x>1):\n print \"yes\"\n else:\n print \"no\"\n t=t-1",
"import sys\nimport math\nt=int(sys.stdin.readline())\nfor i in xrange(t):\n r=int(sys.stdin.readline())\n a=map(int,sys.stdin.readline().split())\n b=map(int,sys.stdin.readline().split())\n c=map(int,sys.stdin.readline().split())\n ab=math.sqrt(((b[0]-a[0])**2)+((b[1]-a[1])**2))\n bc=math.sqrt(((b[0]-c[0])**2)+((b[1]-c[1])**2))\n ac=math.sqrt(((c[0]-a[0])**2)+((c[1]-a[1])**2))\n if ((ab<=r)&(bc<=r))|((bc<=r)&(ac<=r))|((ac<=r)&(ab<=r)):\n print 'yes'\n else:\n print 'no'",
"import math\n\ndef distance (a, b):\n return float(math.sqrt((a[0] - b[0])**2 + (a[1] - b[1])**2))\n\nfor i in range (input()):\n maxrange = int(input())\n a = [int(j) for j in raw_input().split()]\n b = [int(j) for j in raw_input().split()]\n c = [int(j) for j in raw_input().split()]\n\n distList = []\n distList.append(distance(a, b))\n distList.append(distance(b, c))\n distList.append(distance(a, c))\n\n if (sum(j > maxrange for j in distList)) >= 2: print \"no\"\n else: print \"yes\"",
"for _ in range(int(raw_input())):\n r=int(raw_input())\n cx,cy=map(int,raw_input().split())\n hsx,hsy=map(int,raw_input().split())\n scx,scy=map(int,raw_input().split())\n chsd = (((cx-hsx)**2)+((cy-hsy)**2))**0.5\n cscd = (((cx-scx)**2)+((cy-scy)**2))**0.5\n hsscd= (((scx-hsx)**2)+((scy-hsy)**2))**0.5\n c=0\n if chsd<=r:\n c+=1\n if cscd<=r:\n c+=1\n if hsscd<=r:\n c+=1\n if c>=2:\n print \"yes\"\n else:\n print \"no\"",
"import math \nt = int(raw_input())\ndef distance(fir,sec):\n val1 = int(fir[0]) - int(sec[0])\n val2 = int(fir[1]) - int(sec[1])\n dis = math.sqrt(val1 * val1 + val2 * val2)\n return dis \nfor i in range(0,t):\n R = int(raw_input()) \n arr1 = []\n arr2 = []\n arr3 = []\n array1 = raw_input()\n array2 = raw_input()\n array3 = raw_input()\n arr1 += array1.split(\" \")\n arr2 += array2.split(\" \")\n arr3 += array3.split(\" \")\n res1 = distance(arr1,arr2)\n res2 = distance(arr2,arr3)\n res3 = distance(arr1,arr3)\n count = 0\n if R >= res1 :\n count += 1\n if R >= res2 :\n count += 1 \n if R >= res3 :\n count += 1\n if count >= 2:\n print(\"yes\")\n else:\n print(\"no\")",
"t = int(raw_input())\nt1 = []\nfor q in range(t):\n x = int(raw_input())\n a = []\n for i in range(3):\n a.append(map(int,raw_input().split()))\n for i in range(3):\n z = 0\n for j in range(3):\n if j != i :\n if abs((((a[i][1]-a[j][1])**2)+((a[i][0]-a[j][0])**2))**0.5) > x :\n for p in range(3):\n if p != i and p!= j :\n if abs((((a[i][1]-a[p][1])**2)+((a[i][0]-a[p][0])**2))**0.5) <= x and abs((((a[j][1]-a[p][1])**2)+((a[j][0]-a[p][0])**2))**0.5) <= x :\n pass\n else :\n z = 1\n if z == 0:\n t1.append(\"yes\")\n else :\n t1.append(\"no\")\nfor i in range(len(t1)):\n print t1[i]",
"def dist(p1,p2):\n return ((p1[0]-p2[0])**2 + (p1[1]-p2[1])**2)**0.5\n\nx=int(raw_input())\nanswers=[]\nfor i in range(x):\n R=int(raw_input())\n p1=[0]*2\n p2=[0]*2\n p3=[0]*2\n p1=map(int,raw_input().split())\n p2=map(int,raw_input().split())\n p3=map(int,raw_input().split())\n d1=dist(p1,p2)\n d2=dist(p2,p3)\n d3=dist(p1,p3)\n if ((d1<=R and d2<=R) or (d1<R and d3<=R) or (d2<=R and d3<=R)):\n answers.append('yes')\n else:\n answers.append('no')\nfor i in answers:\n print i",
"import math\nfor _ in xrange(input()):\n dist = input()\n ax, ay = map(int, raw_input().split())\n bx, by = map(int, raw_input().split())\n cx, cy = map(int, raw_input().split())\n l = [math.sqrt((by - ay)**2 + (bx - ax)**2), math.sqrt((cy - by)**2 + (cx - bx)**2), math.sqrt((cy - ay)**2 + (cx - ax)**2)]\n l1 = [c for c in l if c > dist]\n if len(l1) > 1:\n print \"no\"\n if len(l1) == 0:\n print \"yes\"\n else:\n sum1 = 0\n for k in l:\n if k not in l1:\n sum1 += k\n if sum1 >= l1[0]:\n print \"yes\"",
"#CODECHEF PROBLEM: COMM3\n#AUTHOR: diksham1\n\nt = int(raw_input())\nwhile(t>0):\n\trange = int(raw_input())\n\tx1,y1 = map(float, raw_input().split())\n\tx2,y2 = map(float, raw_input().split())\n\tx3,y3 = map(float, raw_input().split())\n\tctr = 0;\n\tif ((y2-y1)**2 + (x2-x1)**2)**0.5 <=range:\n\t\tctr += 1;\n\tif ((y3-y1)**2 + (x3-x1)**2)**0.5 <=range:\n\t\tctr += 1;\n\tif ((y2-y3)**2 + (x2-x3)**2)**0.5 <=range:\n\t\tctr += 1;\t\n\tif\tctr >=2:\n\t\tprint \"yes\"\n\telse:\n\t\tprint \"no\"\n\tt -= 1",
"def is_in_range(x1, y1, x2, y2, limit):\n if((x1-x2)**2+(y1-y2)**2 <= limit**2):\n return 1\n else:\n return 0\n \ntc=int(raw_input())\nfor _ in range(tc):\n limit=int(raw_input())\n x1, y1=map(int, raw_input().split())\n x2, y2=map(int, raw_input().split())\n x3, y3=map(int, raw_input().split())\n if(is_in_range(x1, y1, x2, y2,limit) + is_in_range(x1, y1, x3, y3, limit) + is_in_range(x2, y2, x3, y3, limit) > 1):\n print \"yes\"\n else:\n print \"no\"",
"n=int(raw_input())\nimport math\n\n\nfor _ in range(n):\n d=int(raw_input())\n x=[int(i) for i in raw_input().strip().split(' ')]\n y=[int(i) for i in raw_input().strip().split(' ')]\n z=[int(i) for i in raw_input().strip().split(' ')]\n a=math.sqrt((x[0]-y[0])**2+(x[1]-y[1])**2)\n b=math.sqrt((x[0]-z[0])**2+(x[1]-z[1])**2)\n c=math.sqrt((z[0]-y[0])**2+(z[1]-y[1])**2)\n if (a<=d and b<=d) or (a<=d and c<=d) or (c<=d and b<=d):\n print 'yes'\n else:\n print 'no'",
"# @author Kilari Teja\n# FLOW001\n\nfor Cycle in xrange(int(raw_input().strip())):\n\tMaxRadiax = int(raw_input().strip())\n\tTruss = False\n\n\tChefOrds = []\n\tfor Chefs in xrange(0, 3):\n\t\tChefOrds.append(map(int, raw_input().strip().split(\" \")))\n\n\tfor Chef in ChefOrds:\n\t\tPair = 0\n\t\tfor Zerga in ChefOrds:\n\t\t\tPointData = ((Zerga[0] - Chef[0])**2 + (Zerga[1] - Chef[1])**2)**0.5\n\t\t\tif PointData <= MaxRadiax and PointData != 0:\n\t\t\t\tPair += 1\n\n\t\tif Pair >= 2:\n\t\t\tprint \"yes\"\n\t\t\tTruss = True\n\t\t\tbreak\n\n\tif not Truss:\n\t\tprint \"no\"",
"#Begineers Codechef 3way communication\nt=input()\nout=[]\nfor i in range (0, t):\n r=input()\n p=[]\n A=raw_input()\n B=raw_input()\n C=raw_input()\n a=A.split()\n b=B.split()\n c=C.split()\n for i in range(0, 2):\n a[i]=int(a[i])\n b[i]=int(b[i])\n c[i]=int(c[i])\n p.append((((a[0]-b[0])**2)+((a[1]-b[1])**2))**(0.5))\n p.append((((a[0]-c[0])**2)+((a[1]-c[1])**2))**(0.5))\n p.append((((c[0]-b[0])**2)+((c[1]-b[1])**2))**(0.5))\n count=0\n #print p[0], p[1], p[2]\n for i in range(0, 3):\n if p[i]<=r:\n count=count+1\n #print count\n if count>=2.0:\n out.append(\"yes\")\n else:\n out.append(\"no\")\nk=0\nwhile k<t:\n print out[k]\n k=k+1",
"T = int(raw_input())\nfor t in range (T):\n R = int(raw_input())**2\n a,b = map(int,raw_input().split())\n c,d = map(int,raw_input().split())\n x,y = map(int,raw_input().split())\n d1 = (a-c)**2 + (b-d)**2\n d2 = (c-x)**2 + (d-y)**2\n d3 = (a-x)**2 + (b-y)**2\n if d1<=R:\n if d2<=R:\n print \"yes\"\n elif d3<=R:\n print \"yes\"\n else:\n print \"no\"\n elif d2<=R:\n if d3<=R:\n print \"yes\"\n else:\n print \"no\"\n else:\n print \"no\"",
"#The Three Way Communications\n\nfrom math import *\n\ndef dist(x1, x2, y1, y2):\n d = sqrt((pow((x1 - x2), 2)) + (pow((y1 - y2), 2)))\n return d\n\ndef leng(d1, d2, d3, n):\n l = [d1, d2, d3]\n l.sort()\n if float(l[0]) <= n and float(l[1]) <= n and float(l[0]) + float(l[1]) >= l[2]:\n return True\n else:\n return False\n\ndef main():\n T = int(raw_input())\n while(T!=0):\n T-=1\n n = int(raw_input())\n x1, y1 = raw_input().split()\n x2, y2 = raw_input().split()\n x3, y3 = raw_input().split()\n d1 = dist(int(x1), int(x2), int(y1), int(y2))\n d2 = dist(int(x1), int(x3), int(y1), int(y3))\n d3 = dist(int(x3), int(x2), int(y3), int(y2))\n if leng(d1,d2,d3,n):\n print 'yes'\n else:\n print 'no'\n\nif __name__ == '__main__':\n main()",
"T = int(raw_input())\n\nfor i in range(T):\n R = int(raw_input())\n p1 = map(int, raw_input().split()) \n p2 = map(int, raw_input().split()) \n p3 = map(int, raw_input().split())\n count = 0\n if ((p1[0]-p2[0])**2 + (p1[1] - p2[1])**2) > R**2:\n count += 1\n if ((p2[0]-p3[0])**2 + (p2[1] - p3[1])**2) > R**2:\n count += 1\n if ((p1[0]-p3[0])**2 + (p1[1] - p3[1])**2) > R**2:\n count += 1\n print \"yes\" if count <= 1 else \"no\"",
"t = input()\nwhile(t>0):\n\tt-=1\n\tr = input()\n\ta=map(int,raw_input().split())\n\tb=map(int,raw_input().split())\n\tc=map(int,raw_input().split())\n\tcount=0\n\tif( (a[0]-b[0])**2 +(a[1]-b[1])**2 <=r**2 ):\n\t\tcount+=1\n\tif( (b[0]-c[0])**2 +(c[1]-b[1])**2 <=r**2):\n\t\tcount+=1\n\tif( (c[0]-a[0])**2 +(c[1]-a[1])**2 <=r**2):\n\t\tcount+=1\n\tif(count>=2):\n\t\tprint \"yes\"\n\telse:\n\t\tprint \"no\"",
"import math\nT=int(raw_input())\nwhile T>0:\n T-=1\n R=int(raw_input())\n x1,y1=map(int,raw_input().split())\n x2,y2=map(int,raw_input().split())\n x3,y3=map(int,raw_input().split())\n dist_1=math.hypot(x2-x1,y2-y1)\n dist_2=math.hypot(x3-x2,y3-y2)\n dist_3=math.hypot(x3-x1,y3-y1)\n if (dist_1 <=R and dist_2 <=R) or (dist_2<=R and dist_3<=R) or (dist_1<=R and dist_3<=R):\n print \"yes\"\n else:\n print \"no\"",
"def main():\n t=int(raw_input())\n while t :\n t=t-1\n r=int(raw_input())\n z=[]\n k=[]\n for i in range(3):\n x=raw_input().split()\n x=map(int,x)\n z.append(x)\n r1=((z[0][0]-z[1][0])**2+(z[0][1]-z[1][1])**2)**0.5\n r2=((z[1][0]-z[2][0])**2+(z[1][1]-z[2][1])**2)**0.5\n r3=((z[0][0]-z[2][0])**2+(z[0][1]-z[2][1])**2)**0.5\n k=[r1,r2,r3]\n k=sorted(k)\n if k[0]<=r and k[1]<=r :\n print \"yes\"\n else:\n print \"no\"\n \nif __name__=='__main__':\n main()"
]
} | 0 | 0 | 0 | [] | false | null | 0 |
|
gcd2 | Frank explained its friend Felman the algorithm of Euclides to calculate the GCD
of two numbers. Then Felman implements it algorithm
int gcd(int a, int b)
{
if (b==0)
return a;
else
return gcd(b,a%b);
}
and it proposes to Frank that makes it
but with a little integer and another integer that has up to 250 digits.
Your task is to help Frank programming an efficient code for the challenge of Felman.
Input
The first line of the input file contains a number representing the number of lines to follow.
Each line consists of two number A and B (0 ≤ A ≤ 40000 and A ≤ B < 10^250).
Output
Print for each pair (A,B) in the input one integer representing the GCD of A and B.
Example
Input:
2
2 6
10 11
Output:
2
1 | {
"input": [
"2\n2 6\n10 11"
],
"output": [
"2\n1\n"
]
} | {
"input": [],
"output": []
} | {
"input": [
"2\n3 6\n10 11",
"2\n1 3\n10 11",
"2\n0 6\n10 11",
"2\n0 6\n0 11",
"2\n3 6\n8 22",
"2\n3 6\n8 4",
"2\n5 2\n10 2",
"2\n4 10\n8 6",
"2\n7 14\n8 6",
"2\n7 14\n8 4",
"2\n2 6\n5 2",
"2\n0 14\n16 2",
"2\n0 11\n10 1",
"2\n0 14\n16 1",
"2\n1 3\n10 5",
"2\n0 12\n0 11",
"2\n3 8\n8 4",
"2\n0 5\n8 6",
"2\n7 14\n8 5",
"2\n0 6\n0 2",
"2\n0 20\n10 1",
"2\n0 6\n12 20",
"2\n0 4\n5 2",
"2\n0 18\n7 1",
"2\n0 4\n16 6",
"2\n0 20\n12 2",
"2\n3 6\n9 15",
"2\n1 2\n14 7",
"2\n1 2\n14 14",
"2\n0 1\n9 6",
"2\n0 4\n20 4",
"2\n0 12\n21 2",
"2\n7 15\n16 16",
"2\n0 2\n14 14",
"2\n0 2\n9 6",
"2\n0 12\n21 3",
"2\n0 10\n1 10",
"2\n0 10\n3 3",
"2\n8 18\n16 16",
"2\n0 17\n1 17",
"2\n1 6\n11 22",
"2\n0 17\n0 17",
"2\n0 23\n39 1",
"2\n0 2\n10 30",
"2\n0 5\n1 17",
"2\n0 2\n12 30",
"2\n1 2\n0 12",
"2\n1 2\n0 20",
"2\n0 2\n0 20",
"2\n0 8\n2 5",
"2\n0 3\n0 20",
"2\n0 8\n0 5",
"2\n0 4\n0 11",
"2\n0 6\n10 5",
"2\n3 6\n8 8",
"2\n3 6\n6 6",
"2\n0 9\n5 1",
"2\n0 13\n10 1",
"2\n0 26\n11 1",
"2\n2 6\n4 20",
"2\n2 3\n10 20",
"2\n0 2\n0 11",
"2\n3 8\n8 8",
"2\n3 6\n0 14",
"2\n0 2\n5 25",
"2\n0 25\n0 2",
"2\n0 32\n12 1",
"2\n3 6\n9 18",
"2\n0 4\n9 6",
"2\n0 10\n8 10",
"2\n0 8\n4 2",
"2\n0 6\n21 28",
"2\n3 9\n0 15",
"2\n7 7\n16 16",
"2\n5 10\n14 14",
"2\n0 10\n0 10",
"2\n0 9\n3 3",
"2\n0 19\n26 3",
"2\n0 17\n0 14",
"2\n0 34\n39 1",
"2\n1 3\n6 42",
"2\n0 2\n15 30",
"2\n2 3\n0 25",
"2\n2 2\n0 12",
"2\n1 8\n0 9",
"2\n0 4\n10 5",
"2\n0 52\n11 1",
"2\n3 3\n10 11",
"2\n3 6\n8 11",
"2\n5 3\n10 11",
"2\n2 3\n10 11",
"2\n5 1\n10 11",
"2\n2 3\n14 11",
"2\n5 2\n10 11",
"2\n2 3\n14 13",
"2\n3 6\n8 3",
"2\n2 1\n14 13",
"2\n3 6\n8 6",
"2\n5 3\n10 2",
"2\n0 1\n14 13"
],
"output": [
"3\n1\n",
"1\n1\n",
"6\n1\n",
"6\n11\n",
"3\n2\n",
"3\n4\n",
"1\n2\n",
"2\n2\n",
"7\n2\n",
"7\n4\n",
"2\n1\n",
"14\n2\n",
"11\n1\n",
"14\n1\n",
"1\n5\n",
"12\n11\n",
"1\n4\n",
"5\n2\n",
"7\n1\n",
"6\n2\n",
"20\n1\n",
"6\n4\n",
"4\n1\n",
"18\n1\n",
"4\n2\n",
"20\n2\n",
"3\n3\n",
"1\n7\n",
"1\n14\n",
"1\n3\n",
"4\n4\n",
"12\n1\n",
"1\n16\n",
"2\n14\n",
"2\n3\n",
"12\n3\n",
"10\n1\n",
"10\n3\n",
"2\n16\n",
"17\n1\n",
"1\n11\n",
"17\n17\n",
"23\n1\n",
"2\n10\n",
"5\n1\n",
"2\n6\n",
"1\n12\n",
"1\n20\n",
"2\n20\n",
"8\n1\n",
"3\n20\n",
"8\n5\n",
"4\n11\n",
"6\n5\n",
"3\n8\n",
"3\n6\n",
"9\n1\n",
"13\n1\n",
"26\n1\n",
"2\n4\n",
"1\n10\n",
"2\n11\n",
"1\n8\n",
"3\n14\n",
"2\n5\n",
"25\n2\n",
"32\n1\n",
"3\n9\n",
"4\n3\n",
"10\n2\n",
"8\n2\n",
"6\n7\n",
"3\n15\n",
"7\n16\n",
"5\n14\n",
"10\n10\n",
"9\n3\n",
"19\n1\n",
"17\n14\n",
"34\n1\n",
"1\n6\n",
"2\n15\n",
"1\n25\n",
"2\n12\n",
"1\n9\n",
"4\n5\n",
"52\n1\n",
"3\n1\n",
"3\n1\n",
"1\n1\n",
"1\n1\n",
"1\n1\n",
"1\n1\n",
"1\n1\n",
"1\n1\n",
"3\n1\n",
"1\n1\n",
"3\n2\n",
"1\n2\n",
"1\n1\n"
]
} | 1 | 2 | {
"language": [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
],
"solution": [
"def gcd(a,b):\n while(b):\n a,b=b,a%b\n return a\nt=input()\nwhile(t):\n a,b=map(int,raw_input().split())\n print(gcd(a,b))\n t=t-1;",
"def gcd(a,b):\n\tif(a%b==0):\n\t\treturn b;\n\treturn gcd(b,a%b)\n\nt = int(raw_input())\n\nfor i in range(t):\n\ta = raw_input().split(\" \")\n\tprint gcd(int(a[0]),int(a[1]))",
"def gcd(a,b):\n if(b==0):\n return a\n else:\n return gcd(b,a%b)\nt=input()\nfor i in range (0,t):\n a,b=map(int, raw_input().split())\n print gcd(a,b)",
"def gcd(a,b):\n if(b==0):\n return a\n else:\n return gcd(b,a%b)\n\nt = int(raw_input())\nfor i in range(t):\n a,b = map(int,raw_input().split())\n print gcd(a,b)",
"def gcd(a,b):\n while b:\n a,b=b,a%b\n return a\nfor i in range(int(raw_input())):\n a,b=map(int,raw_input().split())\n print gcd(a,b)",
"from fractions import gcd\nt=input()\nfor i in xrange(t):\n\tn1,n2=map(int,raw_input().split())\n\tprint gcd(n1,n2)",
"##Using the Eucledian Method to find gcd\nt=input()\nfor i in range(t):\n l=map(int,raw_input().split())\n if l[0]>l[1]:\n a,b=l[0],l[1]\n else:\n a,b=l[1],l[0]\n while True:\n if b==0:\n print a\n break\n else:\n r=a%b\n a=b\n b=r",
"def gcd(a,b):\n\tif (b==0):\n\t\treturn a\n\telse:\n\t\treturn gcd(b,a%b)\n \n \ntest = int(raw_input())\nfor i in range(test):\n\ta,b = map(int,raw_input().split())\n\tprint gcd(a,b)",
"from fractions import gcd\nt=input()\nwhile t:\n\ta,b=map(int,raw_input().split())\n\tprint gcd(a,b)\n\tt=t-1",
"def gcd(a,b):\n if b==0:\n return a\n else:\n return gcd(b,a%b)\n\nfor i in range(int(raw_input())):\n a,b=map(int,raw_input().split())\n print gcd(a,b)",
"def gcd(a,b):\n if b==0:\n return a\n else:\n return gcd(b,a%b)\n\nfor _ in range(input()):\n m,n = map(int,raw_input().split())\n print gcd(m,n)",
"def gcd(a,b):\n if(b == 0):\n return a\n else:\n return gcd(b,a%b)\n\nfor _ in range(int(input())):\n a,b=map(int,raw_input().split())\n print gcd(a,b)",
"import sys\n\ndef gcd(a,b):\n\tif b == 0 :\n\t\treturn a\n\telse:\n\t\treturn gcd(b,a%b)\n\ntry:\n\tt=int(input())\n\n\tfor _ in xrange(t):\n\t\ta,b = map(int,sys.stdin.readline().rstrip().split(' '))\n\t\tprint gcd(a,b)\n\t\t\nexcept EOFError:\n\tprint(\"\")",
"from fractions import gcd\nfor i in xrange(input()):\n a,b=map(int,raw_input().split())\n print gcd(a,b)",
"def gcd(a, b):\n\tif min(a,b) == 0:\n\t\treturn max(a,b)\n\telse:\n\t\tif b > a:\n\t\t\treturn gcd(a, b%a)\n\t\telse:\n\t\t\treturn gcd(b, a%b)\ntest_case = int(raw_input())\nfor t in range(test_case):\n\ta, b = map(int, raw_input().split())\n\tprint gcd(a,b)",
"for t in xrange(int(raw_input())):\n a, b = map(int, raw_input().split())\n while b:\n a, b = b, a % b\n print a",
"def gcd(a,b):\n if b == 0:\n \treturn a\n else: \n\treturn gcd(b, a % b)\n \nt = int(raw_input())\nfor i in xrange(t):\n\tli = map(int, raw_input().split())\n\tprint(gcd(li[0], li[1]))",
"def gcd(a,b):\n if(b==0):\n return a\n else:\n return gcd(b,a%b)\nt=(int)(input())\nfor i in range(t):\n a=map(int, raw_input().split())\n print(gcd(a[0],a[1]))",
"# your code goes here\ndef gcd(a,b):\n\tif b==0:\n\t\treturn a\n\telse:\n\t\treturn gcd(b,a%b)\nT = input()\nfor t in xrange(T):\n\tval = raw_input().split(\" \")\n\ta = long(val[0])\n\tb = long(val[1])\n\tprint gcd(a,b)",
"def gcd(a,b):\n if b == 0:\n return a\n else:\n return gcd(b,a%b)\n\nT = int(raw_input())\nwhile T :\n a,b = map(int, raw_input().split())\n print gcd(a,b)\n T -= 1",
"def gcd(a,b):\n while b:\n a,b=b,a%b\n return a\nt = input()\nwhile t:\n t=~(-t)\n a,b=map(int,raw_input().split())\n print gcd(a,b)",
"def gcd(a,b) :\n\tif b==0 :\n\t\treturn a\n\telse :\n\t\treturn gcd(b,a%b)\nt=int(input())\nwhile t :\n\ta,b=map(int,raw_input().split())\n\tprint gcd(a,b)\n\tt-=1",
"def gcd(A,B):\n\tif B == 0: return A\n\telse: return gcd(B,A%B)\ndef GCD2():\n\tt = int(raw_input())\n\twhile t:\n\t\tA,B = map(int,raw_input().split())\n\t\tprint gcd(A,B); t-=1\nif __name__ == '__main__': GCD2()",
"t=input()\ndef gcd(a,b):\n\tif a==0:\n\t\treturn b\n\telse:\n\t\treturn gcd(b%a,a)\n\nfor i in range(t):\n\n\tl=[int(x) for x in raw_input().split()]\n\tprint gcd(l[0],l[1])",
"def gcd(a,b):\n if(b==0):\n return a;\n else:\n return gcd(b,a%b)\n \nt = input()\n\nwhile t>0:\n inp = raw_input().split()\n a = (int)(inp[0])\n b = (int)(inp[1])\n ans = gcd(a,b)\n print ans\n t-=1",
"def gcd(a,b):\n while(b>0):\n a,b=b,a%b\n return a\n\nT = int(raw_input())\nfor i in xrange(T):\n a,b = map(int,raw_input().split())\n print gcd(a,b)",
"def gcd(a,b):\n if b==0:\n return a\n else:\n return gcd(b,a%b)\nt=int(input())\nfor i in range(0,t):\n p,q=raw_input().split()\n p=int(p)\n q=int(q)\n print gcd(p,q)",
"def gcd(a,b):\n if b==0:\n return a\n else:\n return gcd(b,a%b)\n\nt=input()\nwhile t :\n a,b =map(int,raw_input().split())\n print(gcd(a,b))\n t=t-1",
"def gcd (a, b):\n\tif b == 0:\n\t\treturn a\n\telse:\n\t\treturn gcd (b, a % b) \n \nt=int(raw_input())\nwhile t:\n a, b = map(int, raw_input().split())\n print gcd(a,b) \n t-=1",
"t = int(raw_input())\ndef gcd(a,b):\n\tif(b==0):\n\t\treturn a\n\telse:\n\t\treturn gcd(b,a%b);\nwhile(t):\n\tx = raw_input()\n\tx = x.split()\n\ta = int(x[0])\n\tb = int(x[1])\n\tprint gcd(a,b)\n\tt = t-1",
"def gcd(a, b):\n if (b==0):\n return a\n else:\n return gcd(b, a%b)\n\n\ndef main():\n tc=input()\n i=0\n for i in range (0, tc):\n string_input=raw_input()\n input_list=string_input.split()\n input_list=[int(a) for a in input_list]\n print gcd(input_list[0], input_list[1])\nmain()",
"def hcf(a,b):\n if b==0:\n return a;\n else:\n return hcf(b,a%b)\n \n \nfor i in range(int(raw_input())):\n a=map(int,raw_input().split())\n print hcf(a[0],a[1])",
"import sys\n\ndef gcd(k,m):\n while m!=0:\n r = k % m\n k = m\n m = r\n \n return k\n\n\n\nn = input()\nwhile n!=0:\n a, b = [int(i) for i in sys.stdin.readline().strip().split()]\n ans = gcd(a,b)\n print ans\n n = n-1",
"from fractions import gcd\nst = input()\nfor t in range(st):\n\ta, b = map(int, raw_input().split())\n\tprint gcd(a, b)",
"def gcd(a, b):\n\tif a == 0:\n\t\treturn b\n\telse:\n\t\treturn gcd(b % a, a)\n\n\ncases = int(raw_input())\nfor _dummy in range(cases):\n\ta, b = map(int,raw_input().split())\n\tprint gcd(a, b)",
"a = input()\ndef gcd(a,b):\n if b == 0:\n return a\n else:\n return gcd(b, a%b)\n\nfor b in range(a):\n d = raw_input().split()\n print gcd(int(d[0]), int(d[1]))",
"def gcd(a,b):\n\tif b==0:\n\t\treturn a\n\telse:\n\t\treturn gcd(b,a%b)\nntc = int(raw_input())\nwhile ntc!=0:\n\ta,b = map(int,raw_input().split(\" \"))\n\tprint gcd(a,b)\n\tntc-=1",
"def gcd(x,y):\n\twhile True:\n if y==0:\n return x\n\t\tr=x%y\n\t\tif r==0:\n\t\t\treturn y\n\t\telse:\n\t\t\tx=y\n\t\t\ty=r\n \n \nn=input()\nfor i in range(0,n):\n\tlis=list(raw_input().split())\n\tn1=int(lis[0])\n\tn2=int(lis[1])\n\tprint gcd(n2,n1)",
"import sys\n\n#print \"AMIT\"\nn=raw_input(\"\")\ndef module(a2,b2):\n if len(a2)<len(b2):\n return a2\n else:\n c =int(a2)%int(b2)\n c1=str(c)\n return c1\ndef hcf(a,b):\n a1=a\n b1=b\n b2=b\n if b1=='0':\n print a1\n return\n b1=module(a1,b1)\n hcf(b2,b1)\ni=0\nwhile i<int(n):\n a, b = raw_input(\"\").split()\n #tokenizedInput = sys.stdin.read().split()\n #a, b = map(str, tokenizedInput[:2])\n \n hcf(a,b)\n i=i+1",
"def gcd(a,b):\n if(b==0):\n return a\n else:\n return gcd(b,a%b)\n \n \ncases=int(raw_input())\nfor i in range(cases):\n a,b=map(str,raw_input().split())\n a=int(a);\n ans=0;\n if a==0:\n print b\n else:\n for i in b:\n ans=(ans*10 + int(i))%a\n print gcd(a,ans)",
"import sys\ndef GCD(A,B):\n\tif B==0:\n\t\treturn A\n\telse:\n\t\treturn GCD(B, A%B)\n\n\nn= int(input())\nwhile n>0:\n\tA,B= map(int, sys.stdin.readline().split())\n\tprint GCD(A,B)\n\tn-= 1",
"def gcd(at,bt):\n if(bt==0):\n return at;\n else:\n return gcd(bt,at%bt)\n \nt = input()\n# main \nwhile t>0:\n inp = raw_input().split()\n a = (int)(inp[0])\n b = (int)(inp[1])\n ans = gcd(a,b)\n print ans\n t-=1",
"def gcd(a,b):\n\tif(b==0):\n\t\treturn a\n\telse:\n\t\treturn gcd(b,a%b)\ndef main():\n\tt=input()\n\tt1=t\n\tlt=[]\n\twhile(t>0):\n\t\ta,b=raw_input().split()\n\t\ta,b=int(a),int(b)\n\t\tx=gcd(a,b)\n\t\tlt.append(x)\n\t\tt=t-1\n\t#print lt\n\tfor i in range(t1):\n\t\tprint lt[i]\n\n\nif __name__ == '__main__':\n\tmain()",
"# cook your code here\n\ndef getModuloOf(a, two):\n i=1;\n b = int(two[:i]);\n while(b<a and i<len(two)):\n i=i+1;\n b=int(two[:i]);\n if(b<a or i==len(two)):\n return b%a;\n else:\n rem=b%a;\n s=str(rem)+two[i:];\n return getModuloOf(a,s);\n \ndef findHCF(a, b):\n if(a==0):\n return b;\n return findHCF(b%a,a);\n\nt=int(raw_input());\n#waste=raw_input();\nwhile(t>0):\n a,two = raw_input().split(' ');\n a=int(a);\n if(a==0):\n print two;\n else:\n b=getModuloOf(a,two);\n ans=findHCF(b,a);\n print ans;\n t=t-1;",
"def gcd(a,b):\n if b==0:\n return a\n else:\n return gcd(b,a%b)\n\nt=input()\nwhile t>0:\n a,b = map(int, raw_input().split(\" \"))\n print gcd(a,b)\n t-=1",
"def gcd(a, b):\n\tif(a == 0):\treturn b;\n\treturn gcd(b % a, a);\nt = input();\nwhile(t > 0):\n\ta, b = map(int, raw_input().split());\n\tprint gcd(a, b);\n\tt -= 1;",
"import math\nimport sys\ndef parseIntList(str):\n return [long(x) for x in str.split()]\ndef printBS(li):\n if len(li) is 0:\n print\n else:\n for i in range(len(li)-1):\n print li[i],\n print li[-1]\ndef gcd(a,b):\n if b==0: return a\n return gcd(b,a%b)\ncases=input()\nfor case in range(cases):\n b,a=raw_input().split()\n b=int(b)\n if b==0:\n print a\n else:\n num=0\n for i in a:\n num=(num*10+int(i))%b\n print gcd(b,num)"
]
} | 0 | 0 | 0 | [] | false | null | 0 |
|
luckybal | A Little Elephant from the Zoo of Lviv likes lucky strings, i.e., the strings that consist only of the lucky digits 4 and 7.
The Little Elephant calls some string T of the length M balanced if there exists at least one integer X (1 ≤ X ≤ M) such that the number of digits 4 in the substring T[1, X - 1] is equal to the number of digits 7 in the substring T[X, M]. For example, the string S = 7477447 is balanced since S[1, 4] = 7477 has 1 digit 4 and S[5, 7] = 447 has 1 digit 7. On the other hand, one can verify that the string S = 7 is not balanced.
The Little Elephant has the string S of the length N. He wants to know the number of such pairs of integers (L; R) that 1 ≤ L ≤ R ≤ N and the substring S[L, R] is balanced. Help him to find this number.
Notes.
Let S be some lucky string. Then
|S| denotes the length of the string S;
S[i] (1 ≤ i ≤ |S|) denotes the i^th character of S (the numeration of characters starts from 1);
S[L, R] (1 ≤ L ≤ R ≤ |S|) denotes the string with the following sequence of characters: S[L], S[L + 1], ..., S[R], and is called a substring of S. For L > R we mean by S[L, R] an empty string.
Input
The 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.
Output
For each test case output a single line containing the answer for this test case.
Constraints
1 ≤ T ≤ 10
1 ≤ |S| ≤ 100000
S consists only of the lucky digits 4 and 7.
Example
Input:
4
47
74
477
4747477
Output:
2
2
3
23
Explanation
In the first test case balance substrings are S[1, 1] = 4 and S[1, 2] = 47.
In the second test case balance substrings are S[2, 2] = 4 and S[1, 2] = 74.
Unfortunately, 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. | {
"input": [
"4\n47\n74\n477\n4747477"
],
"output": [
"2\n2\n3\n23\n"
]
} | {
"input": [],
"output": []
} | {
"input": [
"4\n47\n47\n477\n4747477",
"4\n7\n47\n477\n4747477",
"4\n4\n47\n477\n4747477",
"4\n7\n7\n477\n4747477",
"4\n7\n44\n477\n4747477",
"4\n44\n74\n477\n4747477",
"4\n7\n44\n7\n4747477",
"4\n47\n44\n477\n4747477",
"4\n47\n4\n477\n4747477",
"4\n7\n7\n447\n4747477",
"4\n47\n7\n477\n4747477",
"4\n44\n44\n477\n4747477",
"4\n4\n44\n477\n4747477",
"4\n74\n47\n477\n4747477",
"4\n44\n47\n477\n4747477",
"4\n7\n74\n477\n4747477",
"4\n7\n77\n477\n4747477",
"4\n47\n77\n477\n4747477",
"4\n4\n74\n477\n4747477"
],
"output": [
"2\n2\n3\n23\n",
"0\n2\n3\n23\n",
"1\n2\n3\n23\n",
"0\n0\n3\n23\n",
"0\n3\n3\n23\n",
"3\n2\n3\n23\n",
"0\n3\n0\n23\n",
"2\n3\n3\n23\n",
"2\n1\n3\n23\n",
"0\n0\n5\n23\n",
"2\n0\n3\n23\n",
"3\n3\n3\n23\n",
"1\n3\n3\n23\n",
"2\n2\n3\n23\n",
"3\n2\n3\n23\n",
"0\n2\n3\n23\n",
"0\n0\n3\n23\n",
"2\n0\n3\n23\n",
"1\n2\n3\n23\n"
]
} | 1 | 2 | {
"language": [
1,
1,
1,
1,
1
],
"solution": [
"n = input()\nfor i in range(n):\n str = raw_input()\n l = len(str)\n megacounter = 0\n counter = 0\n i = 0\n while(1):\n while(i<l and str[i]=='7'):\n i=i+1\n counter=counter+1\n if(i>=l):\n break\n megacounter = megacounter + (counter*(counter+1))/2\n i=i+1\n counter=0\n megacounter = megacounter + (counter*(counter+1))/2\n supercounter = (l*(l+1))/2 - megacounter\n print supercounter",
"def calc(str):\n\tlength = len(str)\n\tprev_four = -1 \n\tcount = 0 \n\tfor i in range(0,length):\n\t\tif str[i] == \"4\":\n\t\t\tcount+=(i-prev_four)*(length-i)\n\t\t\tprev_four = i\n\treturn count\n\t\t\n\n\nt = int(raw_input())\nfor i in range(0,t):\n\tstr = raw_input()\n\tprint calc(str)",
"#Program question at: http://www.codechef.com/problems/LUCKYBAL\n\nt = int(raw_input())\n\nfor t in range(t):\n\ts = raw_input()\n\tn=0\n\tl = len(s)\n\ts += '4'\n\tans = (l*(l+1))/2\n\tfor ch in s:\n\t\tif ch == '7': n+=1\n\t\telse:\n\t\t\tans -= (n*(n+1))/2\n\t\t\tn=0\n\tprint ans",
"t=int(raw_input())\nfor z in xrange(t):\n s=raw_input()\n n=len(s)\n c=s.count('4')+(n*(n-1))/2\n i=0\n while (i<(n-1)):\n cur=s[i]\n l=0\n while (i<n and s[i]==cur):\n i+=1\n l+=1\n if (cur=='7'):\n c-=(l*(l-1))/2\n \n \n print c",
"for i in range(input()):\n s=raw_input()\n pos=-1\n ans=0\n for j in range(len(s)):\n if s[j]=='4':\n pos=j\n if pos!=-1:\n ans+=pos+1\n print ans"
]
} | 0 | 0 | 0 | [] | false | null | 0 |
|
prpaln | Given a string s. Can you make it a palindrome by deleting exactly one character? Note that size of the string after deletion would be one less than it was before.
Input
First line of the input contains a single integer T denoting number of test cases.
For each test case, you are given a single line containing string s.
Output
For each test case, print YES or NO depending on the answer of the problem.
Constraints
Example
Input:
4
aaa
abc
abdbca
abba
Output:
YES
NO
YES
YES
Explanation
Example case 1. Delete any one 'a', resulting string is "aa" which is a palindrome.
Example case 2. It is not possible to delete exactly one character and having a palindrome.
Example case 3. Delete 'c', resulting string is "abdba" which is a palindrome.
Example case 4. Delete 'b', resulting string is "aba" which is a palindrome. | {
"input": [
"4\naaa\nabc\nabdbca\nabba"
],
"output": [
"YES\nNO\nYES\nYES\n"
]
} | {
"input": [],
"output": []
} | {
"input": [
"4\naaa\nabc\nabdbca\nabca",
"4\naaa\nabc\nabdbc`\naaca",
"4\naab\nacc\n`bd`cb\naaad",
"4\nbaa\nabc\n`bd`bb\naabd",
"4\nbab\nabb\nbb`db`\naabd",
"4\nbaa\n`aa\nbb`c`b\ndba`",
"4\nba`\n`aa\nbb`c_c\ndba`",
"4\n`a_\naa`\ndda`^c\nca^a",
"4\n_c`\n]`_\ncdad^`\n`c_^",
"4\n_c`\n]`_\ncdac^`\n_c_^",
"4\ne`_\n_\\^\nd_`c_d\nbc^_",
"4\naaa\nabc\nabdbca\naaca",
"4\naaa\nabc\n`bdbc`\naaca",
"4\naab\nabc\n`bdbc`\naaca",
"4\nbaa\nabc\n`bdbc`\naaca",
"4\nbaa\nabc\nabdbc`\naaca",
"4\nbaa\nabc\nabd`cb\naaca",
"4\nbaa\nabc\nabd`cb\nacaa",
"4\nbaa\nabc\n`bd`cb\nacaa",
"4\nbaa\nabc\n`bd`cb\nadaa",
"4\nbaa\nabc\n`bd`cb\naaad",
"4\naab\nabc\n`bd`cb\naaad",
"4\naab\nacc\n`bd`bb\naaad",
"4\naab\nacc\n`cd`bb\naaad",
"4\nbaa\nacc\n`cd`bb\naaad",
"4\nbaa\nacc\n`bd`bb\naaad",
"4\nbaa\nabc\n`bd`bb\naaad",
"4\nbaa\nabc\nbb`db`\naabd",
"4\nbab\nabc\nbb`db`\naabd",
"4\nbab\nacb\nbb`db`\naabd",
"4\nbab\naca\nbb`db`\naabd",
"4\nbab\naba\nbb`db`\naabd",
"4\nbab\naba\nbb`cb`\naabd",
"4\nbab\naba\ncb`cb`\naabd",
"4\naab\naba\ncb`cb`\naabd",
"4\naab\naba\n`bc`bc\naabd",
"4\nbaa\naba\ncb`cb`\naabd",
"4\nbaa\naaa\ncb`cb`\naabd",
"4\nbaa\naaa\ncb`cb`\ndbaa",
"4\nbaa\naaa\nbb`cb`\ndbaa",
"4\nbaa\naaa\nbb`cb`\ndba`",
"4\nbaa\n`aa\nbb`cb`\ndba`",
"4\nbaa\na`a\nbb`c`b\ndba`",
"4\nbaa\na`a\nbb`c`c\ndba`",
"4\nbaa\na`a\nbb`c_c\ndba`",
"4\nbaa\n`aa\nbb`c_c\ndba`",
"4\nba_\n`aa\nbb`c_c\ndba`",
"4\nba_\n`aa\nbb_c_c\ndba`",
"4\nba_\n`aa\nbb_c_c\nabd`",
"4\naa_\n`aa\nbb_c_c\nabd`",
"4\nab_\n`aa\nbb_c_c\nabd`",
"4\nab_\n`aa\nbb_c_c\nab`d",
"4\nab_\n`aa\nbb_c_c\nba`d",
"4\nab_\n`aa\nbb_c_c\nbad`",
"4\nab_\n`aa\nbb_c_c\n`dab",
"4\n_ba\n`aa\nbb_c_c\n`dab",
"4\n_ba\n`aa\n_b_cbc\n`dab",
"4\n_ba\n`aa\ncbc_b_\n`dab",
"4\nab_\n`aa\ncbc_b_\n`dab",
"4\nab_\naa`\ncbc_b_\n`dab",
"4\n_ba\naa`\ncbc_b_\n`dab",
"4\n_ba\naa`\ncbc__b\n`dab",
"4\n^ba\naa`\ncbc__b\n`dab",
"4\n^ba\naa`\ncbc__b\n`cab",
"4\n^ba\naa`\ncbc__b\n_cab",
"4\n^aa\naa`\ncbc__b\n_cab",
"4\n^aa\naa`\ncbc__b\n_caa",
"4\n^aa\naa`\ncbc__c\n_caa",
"4\n^aa\naa`\ncbc__c\n^caa",
"4\naa^\naa`\ncbc__c\n^caa",
"4\naa^\n`aa\ncbc__c\n^caa",
"4\naa^\n`aa\ncbc`_c\n^caa",
"4\naa^\n``a\ncbc`_c\n^caa",
"4\naa^\n`a`\ncbc`_c\n^caa",
"4\naa^\n`a`\ncbc`_c\nc^aa",
"4\naa^\n`a`\ndbc`_c\nc^aa",
"4\naa_\n`a`\ndbc`_c\nc^aa",
"4\naa_\n`a`\ndac`_c\nc^aa",
"4\naa_\n`a`\nc_`cad\nc^aa",
"4\n`a_\n`a`\nc_`cad\nc^aa",
"4\n`a_\n`a`\nc_`dad\nc^aa",
"4\n`a_\n`a`\ndad`_c\nc^aa",
"4\n`a_\n`a`\ndad`^c\nc^aa",
"4\n`a_\n`a`\ndad`^c\naa^c",
"4\n`a_\na``\ndad`^c\naa^c",
"4\n`a_\na``\ndda`^c\naa^c",
"4\n`a_\naa`\ndda`^c\naa^c",
"4\n`a_\naa`\nc^`add\nca^a",
"4\n`a_\naa`\ndda`^c\ncb^a",
"4\n`a_\naa`\ndda`^c\na^bc",
"4\n`a_\na``\ndda`^c\na^bc",
"4\n`a_\na``\ndda`^c\n`^bc",
"4\n`a_\na``\ncda`^c\n`^bc",
"4\n_a`\na``\ncda`^c\n`^bc",
"4\n`a_\n``a\ncda`^c\n`^bc",
"4\n`a_\na``\ncd``^c\n`^bc",
"4\n`a_\na``\ncd``^c\nb^`c",
"4\n`b_\na``\ncd``^c\nb^`c",
"4\n_b`\na``\ncd``^c\nb^`c",
"4\n_b`\na``\ncd``^c\nb^_c"
],
"output": [
"YES\nNO\nYES\nYES\n",
"YES\nNO\nNO\nYES\n",
"YES\nYES\nNO\nYES\n",
"YES\nNO\nNO\nNO\n",
"YES\nYES\nNO\nNO\n",
"YES\nYES\nYES\nNO\n",
"NO\nYES\nNO\nNO\n",
"NO\nYES\nNO\nYES\n",
"NO\nNO\nNO\nNO\n",
"NO\nNO\nNO\nYES\n",
"NO\nNO\nYES\nNO\n",
"YES\nNO\nYES\nYES\n",
"YES\nNO\nYES\nYES\n",
"YES\nNO\nYES\nYES\n",
"YES\nNO\nYES\nYES\n",
"YES\nNO\nNO\nYES\n",
"YES\nNO\nNO\nYES\n",
"YES\nNO\nNO\nYES\n",
"YES\nNO\nNO\nYES\n",
"YES\nNO\nNO\nYES\n",
"YES\nNO\nNO\nYES\n",
"YES\nNO\nNO\nYES\n",
"YES\nYES\nNO\nYES\n",
"YES\nYES\nNO\nYES\n",
"YES\nYES\nNO\nYES\n",
"YES\nYES\nNO\nYES\n",
"YES\nNO\nNO\nYES\n",
"YES\nNO\nNO\nNO\n",
"YES\nNO\nNO\nNO\n",
"YES\nNO\nNO\nNO\n",
"YES\nYES\nNO\nNO\n",
"YES\nYES\nNO\nNO\n",
"YES\nYES\nNO\nNO\n",
"YES\nYES\nNO\nNO\n",
"YES\nYES\nNO\nNO\n",
"YES\nYES\nNO\nNO\n",
"YES\nYES\nNO\nNO\n",
"YES\nYES\nNO\nNO\n",
"YES\nYES\nNO\nNO\n",
"YES\nYES\nNO\nNO\n",
"YES\nYES\nNO\nNO\n",
"YES\nYES\nNO\nNO\n",
"YES\nYES\nYES\nNO\n",
"YES\nYES\nNO\nNO\n",
"YES\nYES\nNO\nNO\n",
"YES\nYES\nNO\nNO\n",
"NO\nYES\nNO\nNO\n",
"NO\nYES\nNO\nNO\n",
"NO\nYES\nNO\nNO\n",
"YES\nYES\nNO\nNO\n",
"NO\nYES\nNO\nNO\n",
"NO\nYES\nNO\nNO\n",
"NO\nYES\nNO\nNO\n",
"NO\nYES\nNO\nNO\n",
"NO\nYES\nNO\nNO\n",
"NO\nYES\nNO\nNO\n",
"NO\nYES\nNO\nNO\n",
"NO\nYES\nNO\nNO\n",
"NO\nYES\nNO\nNO\n",
"NO\nYES\nNO\nNO\n",
"NO\nYES\nNO\nNO\n",
"NO\nYES\nNO\nNO\n",
"NO\nYES\nNO\nNO\n",
"NO\nYES\nNO\nNO\n",
"NO\nYES\nNO\nNO\n",
"YES\nYES\nNO\nNO\n",
"YES\nYES\nNO\nNO\n",
"YES\nYES\nNO\nNO\n",
"YES\nYES\nNO\nNO\n",
"YES\nYES\nNO\nNO\n",
"YES\nYES\nNO\nNO\n",
"YES\nYES\nNO\nNO\n",
"YES\nYES\nNO\nNO\n",
"YES\nYES\nNO\nNO\n",
"YES\nYES\nNO\nNO\n",
"YES\nYES\nNO\nNO\n",
"YES\nYES\nNO\nNO\n",
"YES\nYES\nNO\nNO\n",
"YES\nYES\nNO\nNO\n",
"NO\nYES\nNO\nNO\n",
"NO\nYES\nNO\nNO\n",
"NO\nYES\nNO\nNO\n",
"NO\nYES\nNO\nNO\n",
"NO\nYES\nNO\nNO\n",
"NO\nYES\nNO\nNO\n",
"NO\nYES\nNO\nNO\n",
"NO\nYES\nNO\nNO\n",
"NO\nYES\nNO\nYES\n",
"NO\nYES\nNO\nNO\n",
"NO\nYES\nNO\nNO\n",
"NO\nYES\nNO\nNO\n",
"NO\nYES\nNO\nNO\n",
"NO\nYES\nNO\nNO\n",
"NO\nYES\nNO\nNO\n",
"NO\nYES\nNO\nNO\n",
"NO\nYES\nNO\nNO\n",
"NO\nYES\nNO\nNO\n",
"NO\nYES\nNO\nNO\n",
"NO\nYES\nNO\nNO\n",
"NO\nYES\nNO\nNO\n"
]
} | 1 | 2 | {
"language": [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
],
"solution": [
"import math\nimport sys\ndef checkpal(s):\n return s==s[::-1]\nfor a in range(input()):\n s=raw_input()\n l=len(s)\n if(l==2):\n print \"YES\"\n else:\n if checkpal(s):\n print \"YES\"\n else:\n while s[0] == s[-1] and len(s)>2:\n\t s=s[1:-1]\n\t if checkpal(s[1:]) or checkpal(s[:-1]):\n\t\tprint \"YES\"\n else:\n\t\tprint \"NO\"",
"def palin():\n for i in xrange(input()):\n lst=raw_input()\n lst=list(lst)\n b=lst[::-1]\n if b==lst:\n print \"YES\"\n else:\n for i in xrange(len(lst)):\n if b[i]!=lst[i]:\n c=b[::1];d=lst[::1]\n del c[i];del d[len(lst)-i-1]\n del b[len(b)-i-1];del lst[i]\n if c==d or b==lst:\n print \"YES\"\n break\n else:\n print \"NO\"\n break\npalin()",
"#!/usr/bin/py\nt=raw_input()\ndef pal(s):\n sl=len(s)\n for l1 in range(0,sl/2+(sl%2)):\n if s[l1]!=s[sl-l1-1]:\n return 0\n return 1\n \n \nfor l in range(0,int(t)):\n s=raw_input()\n r=len(s)\n flag=0\n for l1 in range(0,len(s)/2+(len(s)%2)):\n if s[l1]!= s[r-1]:\n c1=pal(s[l1+1:r])\n c2=pal(s[l1:r-1])\n flag=flag+1\n if c2:\n print \"YES\"\n\t break\n elif c1:\n print \"YES\"\n\t break\n else:\n print \"NO\"\n break\n r=r-1\n if flag==0:\n print \"YES\"",
"def isPal(s):\n l=len(s)\n for x in xrange(l/2):\n if s[x]!=s[-1-x]:\n return False\n return True\n\ndef isPos():\n s=raw_input()\n n=len(s)\n for i in xrange(n/2):\n if s[i]!=s[n-1-i]:\n if isPal(s[i:n-1-i]) or isPal(s[i+1:n-i]):\n return \"YES\"\n else:\n return \"NO\"\n return \"YES\"\n\ndef solve():\n t=input()\n for x in xrange(t):\n print isPos() \nsolve()",
"t=int(raw_input())\nwhile t>0:\n s=raw_input()\n length=len(s)\n i=0\n j=length-1\n counter=0\n while(i<j):\n if(s[i]!=s[j]):\n counter+=1\n i+=1\n else:\n i+=1\n j-=1\n if(counter<=1):\n print \"YES\"\n else:\n i=0\n j=length-1\n counter=0\n while(i<j):\n if(s[i]!=s[j]):\n counter+=1\n j-=1\n else:\n i+=1\n j-=1 \n if(counter<=1):\n print \"YES\" \n else:\n print \"NO\"\n t-=1",
"def check(s,x):\n\tn=len(s)\n\tif (s==s[::-1]):\n\t\treturn 1\n\telse:\n\t\tif (x==0):\n\t\t\tfor i in range(n):\n\t\t\t\tif (s[i]!=s[n-i-1]):\n\t\t\t\t\tt=s[:i]+s[i+1:]\n\t\t\t\t\tu=s[:n-i-1]+s[n-i:]\n\t\t\t\t\treturn (check(t,1) or check(u,1))\n\t\telse:\n\t\t\treturn 0\nfor t in range(int(raw_input())):\n\ts=raw_input()\n\tif (check(s,0)):\n\t\tprint \"YES\"\n\telse:\n\t\tprint \"NO\"",
"t=input()\nwhile t>0:\n\tt-=1\n\ts=raw_input()\n\ti,j=0,len(s)-1\n\tlim=0\n\twhile i<j:\n\t\tif s[i]!=s[j]:\n\t\t\tlim+=1\n\t\t\tif s[i]==s[j-1]:\n\t\t\t\tk,l=i,j-1\n\t\t\t\tflag=0\n\t\t\t\twhile k<l:\n\t\t\t\t\tif s[k]!=s[l]:\n\t\t\t\t\t\tflag=1\n\t\t\t\t\t\tbreak\n\t\t\t\t\tk+=1\n\t\t\t\t\tl-=1\n\t\t\t\tif(flag==0):\n\t\t\t\t\tbreak\n\t\t\tif s[i+1]==s[j]:\n\t\t\t\tk,l=i+1,j\n\t\t\t\tflag=0\n\t\t\t\twhile k<l:\n\t\t\t\t\tif s[k]!=s[l]:\n\t\t\t\t\t\tflag=1\n\t\t\t\t\t\tbreak\n\t\t\t\t\tk+=1\n\t\t\t\t\tl-=1\n\t\t\t\tif(flag==0):\n\t\t\t\t\tbreak\n\t\t\t\n\t\t\tlim=2\n\t\t\tbreak\n\n\t\ti+=1\n\t\tj-=1\n\t\tif lim>1:\n\t\t\tbreak\n\tif lim>1:\n\t\tprint 'NO'\n\telse:\n\t\tprint 'YES'",
"def check_palindrome(s):\n\t#s = list(s)\n\tl = len(s)\n\tj = l-1\n\tfor i in range(l/2):\n\t\tif s[i] != s[j]:\n\t\t\treturn False\n\t\tj = j-1\n\treturn True\n\n#if (__name__ == \"__main__\"):\nif(True):\n\tt = raw_input()\n\tt = int(t)\n\tfor i in range(t):\n\t\ts = raw_input()\n\t\tl = len(s)\n\t\ty = 0\n\t\tj = l-1\n\t\tcnt = 0\n\t\tfor k in range(l/2):\n\t\t\tif(s[k] == s[j]):\n\t\t\t\ty = 1\n\t\t\t\tj = j-1\n\t\t\telse:\n\t\t\t\tlist1 = list(s)\n\t\t\t\tlist1.pop(k)\n\t\t\t\tstr1 = ''.join(list1)\n\t\t\t\tlist1 = list(s)\n\t\t\t\tlist1.pop(j)\n\t\t\t\tstr2 = ''.join(list1)\n\t\t\t\tif(check_palindrome(str1)or check_palindrome(str2)):\n\t\t\t\t\ty = 1\n\t\t\t\t\tbreak;\n\t\t\t\telse:\n\t\t\t\t\ty = 0\n\t\t\t\t\tbreak;\n\t\t\t\t\n\t\tif(y == 1):\n\t\t\tprint 'YES'\n\t\telse:\n\t\t\tprint 'NO'",
"t = input()\n\nwhile(t>0):\n t = t-1\n s = raw_input()\n length = len(s)\n if(length==2):\n print \"YES\"\n continue\n \n freq = [0]*26\n \n for x in (s):\n pos=ord(x)\n freq[pos-97] = freq[pos-97]+1\n\n \n evenfreq=0\n oddfreq=0\n diffcharfreq=0\n for x in range(0,26):\n if(freq[x]==0):\n continue;\n if(freq[x]%2==0):\n evenfreq=evenfreq+1\n if(freq[x]%2==1):\n oddfreq=oddfreq+1\n if(freq[x]>0):\n diffcharfreq = diffcharfreq+1\n\n\n if(diffcharfreq==1):\n print \"YES\"\n continue\n\n if(diffcharfreq==length):\n print \"NO\"\n continue\n\n\n if(oddfreq>=3):\n print \"NO\"\n continue\n\n flag=0\n\n i=0\n j=length-1\n si=0\n li=0;\n while(i<=j):\n if(s[i]==s[j]):\n i=i+1\n j=j-1\n else:\n flag=1\n si=i\n li=j\n break\n\n\n sic=si\n lic=li\n siflag=0\n liflag=0\n if(flag==1):\n #si wala deleted\n si=si+1\n while(si<=li):\n if(s[si]!=s[li]):\n siflag=1\n break\n else:\n si=si+1\n li=li-1\n\n if(siflag==0):\n print \"YES\"\n continue\n \n #lic wala deleted\n lic = lic -1\n # print \"lic = \"+lic\n # print \"sic = \"+sic\n while(sic<=lic):\n if(s[sic]!=s[lic]):\n liflag=1\n break\n else:\n sic=sic+1\n lic=lic-1\n \n\n if(liflag==0):\n print \"YES\"\n continue\n\n if(siflag==1):\n print \"NO\"\n continue\n if(liflag==1):\n print \"NO\"\n continue\n \n else:\n pflag=0\n if(flag==0):\n if(length%2==1):\n pi=0\n pj=length-1\n while(pi<pj):\n if(s[pi]==s[pj]):\n pi=pi+1\n pj=pj-1\n else:\n pflag=1\n\n if(pflag==0):\n print \"YES\"\n continue\n\n if(length%2==0):\n t1=length/2\n t2=(length-2)/2\n\n if(s[t1]==s[t2]):\n print \"YES\"\n continue",
"def check_palin(val, i, j):\n flag = False\n while i < j:\n if val[i] != val[j]:\n flag = True\n break\n i += 1\n j -= 1\n\n if flag:\n return (i, j)\n return (-1, -1)\n\ndef process():\n val = raw_input()\n i, j = check_palin(val, 0, len(val)-1)\n if i == -1 or j == -1:\n print \"YES\"\n return\n\n ii, jj = check_palin(val, i+1, j)\n if ii == -1 or jj == -1:\n print \"YES\"\n return\n\n ii, jj = check_palin(val, i, j-1)\n if ii == -1 or jj == -1:\n print \"YES\"\n return\n\n print \"NO\"\n\ndef main():\n T = input()\n for i in xrange(T):\n process()\nif __name__ == '__main__':\n main()",
"for _ in range(int(raw_input())):\n s=list(raw_input())\n s1c=list(s)\n s2c=list(s)\n n=len(s)\n flag=0\n for i in range(n/2):\n if s[i]!=s[n-1-i]:\n del s1c[i]\n if s1c==s1c[::-1]:\n print \"YES\"\n flag=1\n break\n del s2c[n-1-i]\n if s2c==s2c[::-1]:\n print \"YES\"\n flag=1\n break\n print \"NO\"\n flag=1\n break\n if flag==0:\n print \"YES\"",
"import sys\n \nfor __ in range(input()) :\n a=list(raw_input())\n answered=False\n s=[i for i in reversed(a)]\n for i in range(len(s)) :\n if s[i]!=a[i] :\n s.pop(i)\n a.pop(i)\n #print s,a\n if s==s[::-1] or a==a[::-1] :\n print \"YES\"\n answered=True\n break\n else :\n print \"NO\"\n answered=True\n break\n if not answered :\n print \"YES\""
]
} | 0 | 0 | 0 | [] | false | null | 0 |
|
tf01 | An established group of scientists are working on finding solution to NP hard problems. They claim Subset Sum as an NP-hard problem. The problem is to determine whether there exists a subset of a given set S whose sum is a given number K.
You are a computer engineer and you claim to solve this problem given that all numbers in the set are non-negative. Given a set S of size N of non-negative integers, find whether there exists a subset whose sum is K.
Input
First line of input contains T, the number of test cases. T test cases follow.
Each test case contains 2 lines. First line contains two integers N and K. Next line contains N space separated non-negative integers (each less than 100000).
0 < T < 1000
0 < N < 1000
0 < K < 1000
Output
Output T lines, one for each test case. Every line should be either 0 or 1 depending on whether such a subset exists or not.
Example
Input:
2
5 10
3 4 6 1 9
3 2
1 3 4
Output:
1
0 | {
"input": [
"2\n5 10\n3 4 6 1 9\n3 2\n1 3 4"
],
"output": [
"1\n0"
]
} | {
"input": [],
"output": []
} | {
"input": [],
"output": []
} | 1 | 6 | {
"language": [
1
],
"solution": [
"import sys\n\nfor __ in range(input()) :\n n , k = map(int,sys.stdin.readline().split())\n lists = map(int,sys.stdin.readline().split())\n dp = [0]*(k+1)\n dp[0]=1\n for i in lists :\n for j in range(k-i,-1,-1) :\n if dp[k] :\n break\n if dp[j] :\n dp[j+i] = 1\n print dp[k]"
]
} | 0 | 0 | 0 | [] | false | null | 0 |
|
1012_E. Cycle sort | "You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following ope(...TRUNCATED) | {"input":["5 5\n3 2 3 1 1\n","4 3\n2 1 4 3\n","2 0\n2 2\n"],"output":["1\n5\n1 4 2 3 5 \n","-1\n","0(...TRUNCATED) | {"input":["5 0\n884430748 884430748 708433020 708433020 708433020\n","2 1\n1 1\n","2 0\n2 1\n","5 2\(...TRUNCATED) | {"input":["5 0\n884430748 884430748 182474629 708433020 708433020\n","5 2\n65390026 1454694739 65390(...TRUNCATED) | 2 | 11 | {"language":[2,2,2,4,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,4,2,2,2,2,2,2,2,2,2,2(...TRUNCATED) | 1,012 | E | 2,500 | 3,100 | [
"dsu",
"math"
] | false | null | 256,000,000 |
1037_E. Trips | "There are n persons who initially don't know each other. On each morning, two of them, who were not(...TRUNCATED) | {"input":["4 4 2\n2 3\n1 2\n1 3\n1 4\n","5 8 2\n2 1\n4 2\n5 4\n5 2\n4 3\n5 1\n4 1\n3 2\n","5 7 2\n1 (...TRUNCATED) | {"input":["16 20 2\n10 3\n5 3\n10 5\n12 7\n7 6\n9 12\n9 6\n1 10\n11 16\n11 1\n16 2\n10 2\n14 4\n15 1(...TRUNCATED) | {"input":["16 20 2\n10 3\n5 3\n10 5\n12 7\n7 6\n9 10\n9 6\n1 10\n11 16\n11 1\n16 2\n10 2\n14 4\n15 1(...TRUNCATED) | 2 | 11 | {"language":[2,2,2,4,4,2,2,2,2,2,4,2,2,2,4,2,4,2,4,4,2,4,2,4,2,2,4,2,2,2,4,2,2,4,4,4,2,4,2,4,4,1,4,4(...TRUNCATED) | 1,037 | E | 2,250 | 2,200 | [
"graphs"
] | false | null | 256,000,000 |
1060_A. Phone Numbers | "Let's call a string a phone number if it has length 11 and fits the pattern \"8xxxxxxxxxx\", where (...TRUNCATED) | {"input":["22\n0011223344556677889988\n","11\n00000000008\n","11\n31415926535\n"],"output":["2\n","1(...TRUNCATED) | {"input":["51\n882889888888689888850888388887688788888888888858888\n","55\n7271714707719515303911625(...TRUNCATED) | {"input":["51\n1732111733638718702525811518175029394157760329139501\n","55\n815096522892298714932212(...TRUNCATED) | 2 | 7 | {"language":[3,2,3,1,2,3,3,3,4,4,2,3,1,2,3,1,3,1,1,3,4,3,4,2,3,2,4,3,3,1,2,3,3,2,3,1,3,1,2,4,3,3,4,3(...TRUNCATED) | 1,060 | A | 500 | 800 | [
"brute force"
] | false | null | 512,000,000 |
1081_G. Mergesort Strikes Back | "Chouti thought about his very first days in competitive programming. When he had just learned to wr(...TRUNCATED) | {"input":["3 2 998244353\n","9 3 998244353\n","3 1 998244353\n","9 4 998244353\n"],"output":["665496(...TRUNCATED) | {"input":["53812 4 967428361\n","7 2 400166453\n","75727 16 485722667\n","65536 10 802338989\n","655(...TRUNCATED) | {"input":["53812 5 967428361\n","12 2 400166453\n","27203 10 802338989\n","59715 12 196344479\n","14(...TRUNCATED) | 2 | 13 | {"language":[2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2(...TRUNCATED) | 1,081 | G | 3,500 | 3,200 | [
"math",
"probabilities"
] | false | null | 256,000,000 |
End of preview. Expand
in Dataset Viewer.
No dataset card yet
New: Create and edit this dataset card directly on the website!
Contribute a Dataset Card- Downloads last month
- 6