K Closest Points to Origin

Medium

Given an array of points, where points[i] = [x_i, y_i] is a point on the X-Y plane, and an integer k, return the k points closest to the origin (0, 0).

Distance is the ordinary Euclidean distance, sqrt(x² + y²).

You may return the points in any order. The tests are chosen so the answer is unique apart from that order: there is never a tie for the last spot.

Examples

Example 1

Input:  points = [[1,3],[-2,2]], k = 1
Output: [[-2,2]]

[1,3] is sqrt(1 + 9) = sqrt(10) from the origin and [-2,2] is sqrt(4 + 4) = sqrt(8). sqrt(8) is smaller, so [-2,2] is the closest point.

Example 2

Input:  points = [[3,3],[5,-1],[-2,4]], k = 2
Output: [[3,3],[-2,4]]

The squared distances are 18, 26 and 20. The two smallest are 18 and 20. [[-2,4],[3,3]] would also be accepted.

Example 3

Input:  points = [[6,0],[4,4]], k = 1
Output: [[4,4]]

By |x| + |y|, [6,0] (6) looks closer than [4,4] (8). By real distance it's the other way around: 36 > 32. Compare x² + y², not the coordinates' absolute values.

Example 4

Input:  points = [[1,1],[1,1],[5,5]], k = 2
Output: [[1,1],[1,1]]

Points can repeat. Each copy is a separate point, so both copies of [1,1] are returned.

Example 5

Input:  points = [[0,1],[1,0]], k = 2
Output: [[0,1],[1,0]]

When k equals the number of points, every point is returned.

Constraints

  • 1 <= k <= points.length <= 10^4
  • points[i].length == 2
  • -10^4 <= x_i, y_i <= 10^4
  • The answer is unique apart from its order.
TypeScript
Loading editor…
Test cases31
Case 1
points = [[1,3],[-2,2]]
k = 1
Case 2
points = [[3,3],[5,-1],[-2,4]]
k = 2
Case 3
points = [[0,1],[1,0]]
k = 2
Case 4
points = [[1,1],[1,1],[5,5]]
k = 2
Case 5
points = [[-5,4],[-6,-5],[4,6]]
k = 2
Case 6
points = [[0,0]]
k = 1
Case 7
points = [[10000,10000]]
k = 1
Case 8
points = [[-10000,-10000],[10000,9999]]
k = 1
Case 9
points = [[1,2],[2,1],[3,3]]
k = 2
Case 10
points = [[3,3],[2,2],[1,1]]
k = 1
Case 11
points = [[3,3],[2,2],[1,1]]
k = 3
Case 12
points = [[-1,0],[0,-2],[3,0],[0,4]]
k = 3
Case 13
points = [[2,2],[2,2],[2,2],[3,3]]
k = 3
Case 14
points = [[7,7],[-7,-7],[0,0]]
k = 1
Case 15
points = [[5,0],[0,4],[3,3],[-2,-4],[4,-1]]
k = 2
Case 16
points = [[6,10],[-3,3],[-2,5],[0,2]]
k = 3
Case 17
points = [[6,0],[4,4]]
k = 1
Case 18
points = [[0,6],[-4,4],[10,10]]
k = 1
Case 19
points = [[4,4],[5,0]]
k = 1
Case 20
points = [[10000,0],[0,-10000],[9999,9999],[-7071,7071]]
k = 3
Case 21
points = [[4195,2426],[-7265,8734],[-1581,-62],[2011,-3916],[3325,-8564],[6893,8914],[8429,7200],[-9309,-9636]]
k = 3
Case 22
points = [[-4650,7588],[-222,4855],[-799,-7226],[-4820,-1739],[-3054,8642],[-9266,-3382],[5183,7270],[-2548,-6740],[1816,7168],[5869,2969],[6900,-3751],[1988,5099],[5394,4618],[-3916,-9506],[-2127,4289]]
k = 1
Case 23
points = [[1310,-7859],[6709,5039],[-9935,5634],[-9327,-6429],[5953,-9859],[-515,-1797],[510,-4861],[-4897,-7616],[-5814,-1471],[-240,-4540],[7870,-3751],[-2071,9762],[-8906,9074],[-9339,-6283],[3334,5687],[6523,7736],[-3349,-2083],[1306,-5211],[9563,-4342],[-723,-960],[-3723,-5290],[-5597,-1833],[2532,-7896],[782,4840],[6153,-2621]]
k = 25
Case 24
points = [[-3933,2428],[2515,1790],[-289,-2087],[2648,-7089],[-4212,3694],[-3559,4261],[44,9499],[-2318,6007],[3863,4847],[9221,-538],[-7135,-7864],[-5063,2633],[-2938,-888],[-1350,-7260],[5913,2971],[-6687,-5419],[-1160,7604],[-1524,7865],[-2627,-3962],[-8693,6973],[6580,-3391],[-211,-5895],[-6506,-1605],[-932,9178],[-7257,-818],[-7145,-8422],[-2005,-3970],[6426,-2753],[3204,-2734],[8438,3670],[-8521,1526],[-5574,-1907],[-1594,-6238],[8418,-1431],[9480,-404],[5845,-3155],[5243,-7205],[-4964,1664],[-1751,-1609],[5262,8469]]
k = 10
Case 25
points = [[9237,7048],[-1572,958],[-3166,556],[1971,4184],[552,666],[-3169,-9952],[-6131,4773],[-1937,-5411],[4916,-1345],[6506,-2772],[770,2093],[9286,-9991],[6860,-4824],[1343,-1077],[-5901,-152],[-1178,-8515],[1841,1712],[-3840,6057],[6506,5329],[2853,8771],[-92,-2671],[984,-7094],[8125,-4069],[8265,-9337],[-1867,4587],[6319,-2642],[2029,5471],[-1634,-1789],[-7430,2607],[-4870,-5479],[5083,6598],[-8656,1923],[8975,-5226],[-1129,4269],[6191,4552],[2395,-5909],[-9749,-182],[3586,-6477],[5682,-5701],[-339,1120],[7389,8774],[-3207,-1067],[-3913,-7879],[-3081,4093],[2665,-8075],[970,3744],[-3652,-776],[-2271,1166],[-5961,2942],[-5288,8391],[-5726,1931],[-7215,6120],[2902,178],[-9059,717],[7630,5607],[-2226,7266],[7106,1651],[7168,1278],[5559,-7084],[-7288,-4871]]
k = 59
Case 26
points = [[-4509,-3576],[-9302,6711],[-8811,-9373],[2852,2817],[-9887,-1930],[-4997,2764],[-6314,-6994],[3066,5377],[-27,-3515],[9037,9541],[-3582,6078],[5111,-4053],[-8530,-2879],[1031,7221],[7748,6771],[-3433,-46],[9059,792],[2825,-5312],[-4624,3762],[5353,7857],[8927,-372],[-4908,6350],[-1998,-5940],[8639,-4564],[2943,5568],[4170,694],[-5589,2136],[-6616,7296],[6557,-9319],[8616,-275],[5627,-2260],[-9695,-3808],[-8169,1],[-2863,4877],[6041,-48],[-6556,3764],[-4178,4724],[-2251,-401],[4881,5128],[85,553],[-428,-9549],[5419,5892],[9411,-4772],[7741,-4823],[786,-4254],[2800,6620],[-6874,460],[6204,2153],[-8352,6907],[4585,9283],[-5047,-1743],[6267,5996],[2266,-9729],[-2818,-5308],[-6601,-5682],[-2614,8849],[6936,8804],[1614,-8398],[-4668,-6178],[-129,6092],[-9722,-9712],[-4844,7982],[4377,2696],[2992,3587],[1857,-6063],[4643,-2322],[4759,3005],[3495,5470],[-6818,5892],[-5495,3737],[-6194,-3341],[-7867,-4283],[-7833,-1773],[4994,5831],[8979,2235],[-8229,-6199],[9813,558],[5630,2431],[-481,-510],[-749,-7510],[-5395,5469],[-4623,-6715],[-6726,5905],[2030,6424],[-1350,7401],[-9544,6070],[9360,-5955],[835,-2812],[-2323,8299],[-143,3554],[-7920,-9343],[-7613,-5044],[-8855,4215],[1513,9973],[3473,1967],[-4077,-3802],[-3197,4690],[1472,4915],[-597,-5960],[-2795,-1130],[1668,-330],[8575,5743],[5119,2187],[-9540,360],[3191,2288],[7001,-998],[838,-1822],[8912,-1410],[-6007,-8478],[-7607,2389],[-4149,1034],[-3825,-6026],[4456,3000],[-6614,-6832],[6658,-1519],[135,1976],[-6243,-2455],[-4811,668],[5662,7092],[-7415,-3572],[-2191,-1998],[1678,9895],[150,6054],[-4563,7085],[2727,-8908],[5505,-2832],[-7044,9820],[-7482,-8067],[3495,9028],[-6776,-8304],[4407,9597],[-5566,7854],[-6886,2566],[5688,-291],[957,7295],[-4966,-6486],[-9924,-9698],[-2582,3214],[-8604,-2213],[-6482,6042],[-5915,-9747],[9024,-1108],[-3105,5187],[-8081,-7891],[-987,-9574],[6961,-6739],[1656,-9477],[-9189,-5972],[-2250,5686],[-5789,-9096],[9413,9653],[9594,-8401],[-6664,-4076],[-4904,6788],[-3929,1273],[2380,-2078],[-54,-8789],[3355,-4665],[-8795,5144],[-9875,-355],[7184,-7953],[4139,7176],[-8517,254],[-3190,5876],[8184,2110],[2660,8589],[-4008,6350],[-7845,-6029],[-9077,-5270],[4162,3033],[-6267,-5827],[2717,-1141],[-1267,3539],[-8112,-4365],[-4834,-7676],[1717,6115],[1135,-5463],[4527,-3819],[6446,6993],[5358,7762],[1123,8315],[-6213,-1096],[701,7058],[456,-61],[-6951,-5199],[-3932,415],[-9508,7101],[-907,-2003],[3685,5589],[-1844,-8913],[-2839,-4323],[-6841,-3422],[-6990,3269],[7688,-5861],[-1617,-6680],[414,6440],[-5528,-1577],[-5585,-9379],[-4937,-4405],[8839,-4487]]
k = 50
Case 27
points = [[5138,-4980],[7296,-1581],[8849,-4156],[-1425,-3291],[1274,-4153],[5308,7915],[9505,9807],[-4373,3872],[6830,1039],[379,5065],[5328,-3259],[-209,2497],[-9322,-9544],[-5545,-3166],[-3631,-9800],[5121,5635],[7737,-7977],[-2104,6701],[7738,-6064],[-8850,6823],[7505,1716],[4989,-5145],[-2750,-2473],[4378,-9369],[-2735,-69],[-3157,7708],[-6929,90],[-5605,-8906],[-5931,3696],[-8264,2077],[8422,-5142],[-2401,4430],[-9279,9319],[6821,861],[-9361,7118],[6645,3698],[-9699,7624],[-9363,-795],[-8307,-1621],[9096,-2480],[5043,-2760],[6474,-5726],[-5805,9677],[284,7696],[-9906,584],[-4503,-8953],[-3459,1453],[-3880,-1536],[-1760,9473],[-7405,2058],[-9288,-2090],[-588,-2246],[4231,-6436],[-9579,-496],[5540,-9287],[-1429,2493],[2783,6025],[3649,-9434],[4816,-6147],[-5901,-6203],[2264,2215],[2406,9836],[9275,-2522],[8095,-3425],[-1892,-1910],[-2790,-3156],[-73,-1112],[4665,6260],[-4854,-2175],[777,-5525],[-7925,-3547],[3593,2007],[-145,7342],[-9001,2327],[-9102,3363],[-4227,7798],[-8687,-5314],[2434,-6272],[1446,627],[8216,850],[1851,5627],[-8443,-7330],[-8769,-8095],[-7458,-6338],[-6113,-2878],[-5907,4060],[-4162,-8605],[634,-4403],[-951,-4746],[3141,-2287],[2593,1533],[-622,6222],[-7910,-834],[-7772,7366],[2315,1612],[6982,5004],[-733,4056],[9060,5573],[-8204,-1373],[6327,3338],[762,323],[-3025,8296],[6320,-1806],[-3546,8529],[-7013,-8593],[6980,-5356],[-9649,-2548],[4205,8999],[-4808,-9988],[-8856,5052],[-324,-5561],[-4312,58],[2436,-1527],[1990,-2395],[829,5154],[5753,3407],[1607,5880],[-5119,-47],[-9183,8271],[-3100,6169],[-6422,2276],[2087,-9838],[-103,-2966],[-7546,6516],[-3822,1689],[4273,3313],[5823,-7802],[4606,689],[1841,-4965],[9720,2695],[4020,3387],[386,1565],[-108,-8561],[4639,5687],[-1937,6959],[4355,-9477],[-9909,-8062],[3246,-6636],[-5790,-269],[-5693,-6648],[-6138,-6206],[5917,4160],[7101,-8552],[-8250,-6309],[3911,-8735],[-4827,-4862],[-1630,-8877],[5352,-7997],[-2750,9935],[-9381,-2352],[-9173,7159],[-6576,1438],[-8944,-8670],[6601,-8319],[2593,-7387],[-8407,7899],[-4986,-6205],[-7990,1169],[9139,-496],[4161,-8577],[3948,-9219],[-2831,6110],[7954,6280],[-8548,-7676],[1163,-4458],[-3660,4622],[1406,2478],[2598,-646],[-1260,-7189],[5618,6754],[-73,-6794],[-6477,-6993],[-9648,-7609],[6889,-9454],[-2502,2526],[3414,-734],[9479,-7878],[2477,-3015],[3596,6776],[-1574,3015],[4934,-2634],[8109,6873],[-7581,8885],[9127,2998],[-7224,-7142],[1567,5084],[9394,-1221],[-1186,3524],[-6516,-7421],[2680,-9376],[-5903,8610],[1501,-3655],[1842,-949],[-2794,4802],[9381,2076],[943,1003],[-2178,1765],[-395,-6230],[7073,1998],[-5461,2692],[-2696,7021],[6919,-596],[2045,-2310],[-532,-8537],[178,-5414],[1112,-2036],[-8517,-8665],[3661,6306],[-6745,3751],[1582,2651],[-5190,3562],[2960,-1375],[3618,-5484],[7509,2766],[8144,-1387],[4687,5138],[-62,1714],[5215,8464],[-9445,-7883],[-5566,-9139],[7730,1356],[500,-3931],[3555,7578],[-4004,-5719],[1742,-739],[9545,-89],[-4333,-6158],[486,-9316],[3984,6147],[-8462,-678],[-9763,-3416],[-1684,8108],[-288,-6179],[7383,-1323],[7830,2846],[2826,5458],[-5849,-8904],[-114,2275],[9200,7972],[6236,7167],[-5771,7863],[3585,-8753],[8113,8746],[-8606,-109],[-1683,4924],[-2158,1350],[2573,5087],[1642,-8637],[-6735,106],[5048,3460],[1930,1007],[790,4207],[-6409,5142],[-4708,-5189],[4728,4435],[-5069,4521],[886,-5656],[-9712,1407],[-6713,-5666],[9199,9157],[-3150,-6899],[9781,-5913],[-6063,-1700],[7950,329],[-1747,6866],[-7419,356],[-7306,4910],[-5031,-4493],[688,-6322],[4795,4001],[-8570,-1572],[-5884,9112],[3460,5245],[-3880,-4084],[8655,7107],[-3401,8956],[-302,-6389],[7595,-8082],[-7618,5107],[5268,6899],[6753,-2070],[-5934,-690],[3915,-2207],[5948,-8800],[-334,-9447],[-8110,-3582],[-4266,5134],[-8803,-1765],[8719,-4267],[7322,2282],[8773,294],[8634,3],[-3388,6500],[9167,-7237],[-6715,7086],[-1033,-3595],[-8804,7201],[2496,6058],[2522,6340],[8369,-5856],[-291,-2129],[-9931,-3395],[-313,-5975],[-2370,-1490],[-8314,-3570],[5852,-7900],[-8051,3376],[-3921,9602],[-9356,7381],[-2927,4384],[-1612,5715],[3540,-4037],[199,-1451],[-538,2361],[-2168,4121],[7418,-9490],[2194,6651],[-201,5489],[-1646,3929],[-5281,8987],[-4769,-5418],[-7705,-4506],[-1412,-4191],[-1261,1032],[-7210,9378],[-8653,-8265],[-1708,-3160],[-5166,-6941],[3929,-2136],[8919,-9846],[3523,-6127],[-8839,9628],[-7515,-6532],[-9365,-4062],[-1380,-7144],[-8383,3901],[3547,-9204],[-1695,-6864],[-652,-9009],[-8175,-4654],[7349,9183],[158,19],[-2642,-8680],[4820,6333],[-9834,5340],[7178,1904],[-7062,8336],[9598,-5805],[-9647,4729],[-329,-7166],[-7194,220],[5158,-1865],[-6442,3523],[1402,-6639],[4510,-3762],[4800,6010],[6064,267],[4764,-1705],[9790,6369],[-2091,-5349],[-7052,-7355],[2664,-9601],[4116,6506],[-8023,3739],[-7041,-2180],[8170,6562],[543,-1953],[391,-9350],[-1199,9444],[-8994,7550],[61,9052],[-5495,7921],[6104,-3161],[5468,-390],[-8527,-3028],[-7466,-7234],[-3778,-163],[-6710,-8542],[-8021,4654],[5669,7635],[-2350,8759],[-9977,3654],[-3354,-5271],[8608,-6512],[5218,-8281],[3857,-2173],[9486,3098],[-376,7014],[-2501,-702],[-8377,-4172],[-3825,4228],[-6314,6420],[7022,-199],[6644,-9308],[-116,5244],[-7808,9896],[-2825,-9043],[-7883,8898],[-1899,9859],[4584,9905],[7818,-9690],[628,6882],[-6367,6085],[8983,3579],[4273,4677],[1991,-984],[-3293,-5821],[-6114,-7575],[7577,4972],[6416,-1198],[3495,-5419],[-7662,9777],[-8671,6663],[1305,-5442],[8934,-173],[8808,2551],[-2576,-7039],[-3762,-6171],[-7802,-1487],[-6884,5562],[539,4244],[4746,-3999],[8070,-3037],[-1608,2178],[-3078,6572],[2688,3834],[3499,-7833],[5312,7681],[-650,525],[4834,4197],[-4545,-9953],[9648,2394],[-5401,-8517],[6140,-2821],[7501,-4245],[-6864,-6387],[-9652,-2100],[4014,3571],[-2041,3618],[1564,8336],[-5763,-1609],[7816,-9436],[-3382,3848],[2558,8189],[-4695,-5945],[9056,6782],[-4506,3559],[-3762,-6138],[4788,-2041],[3435,-614],[-1025,-4906],[7526,7227],[-4463,-5885],[5454,-7190],[8180,-8506],[6533,-4350],[-7152,7161],[9101,-4601],[2649,-5136],[1928,2226],[-135,3139],[8102,-6880],[2724,-6612],[-4989,-1738],[-5976,-9260],[-5278,-4745],[-3139,-4832],[-8493,6121],[5611,-9552],[6164,-8549],[-4077,9064],[-3807,-7960],[5883,4231],[3667,309],[-1502,-314],[-6469,-5738],[-959,7181],[-1431,-3477],[-3808,-3969],[-8188,9355],[-8731,-1977],[-1130,2600],[-8502,3434],[-7758,1058],[6393,6261],[4098,-7070],[-5913,-6119],[7862,-7446],[-3221,1984],[-3153,7367],[-7554,318],[4576,8450],[-4709,7417],[5969,7214],[-7847,-3834],[7003,-4163],[-443,-5596],[3984,960],[1909,-5291],[-7206,2782]]
k = 1
Case 28
points = [[9701,3814],[-6697,8946],[6869,6854],[-6676,-6256],[897,7730],[3591,-1026],[-7586,-9242],[1714,214],[-1927,3817],[-4668,3353],[-7203,9881],[8150,-6016],[7919,-7894],[5636,7312],[-9979,8393],[-9331,-585],[2181,-4856],[5418,-5576],[1237,-9766],[2647,578],[-3873,-4218],[-3254,-5988],[688,-3011],[-6518,-2895],[8716,65],[-4422,5308],[-8964,3723],[-7444,8885],[-8182,3369],[-2971,-887],[-3380,2172],[-6194,8502],[-2993,-7254],[-1022,3017],[7087,9091],[-6452,3860],[336,7400],[2413,-3959],[3587,-5817],[5179,-8876],[-5543,9569],[-9877,-9694],[6025,-9980],[2607,-9145],[2927,2984],[8555,-1436],[3346,-1679],[-6671,-7279],[-8792,2574],[-8385,-9220],[8815,-2070],[1757,-3151],[-6271,2989],[-9999,2272],[-6031,-6898],[-853,-1707],[8165,5456],[-6466,-766],[4727,-3386],[-3932,6144],[-9509,-5253],[9973,3677],[2052,-9879],[-7103,-4924],[-1388,-2658],[-6008,-222],[2826,-6101],[-6590,-5543],[2216,7933],[7493,-4593],[8315,426],[2775,2939],[-6781,5123],[-3576,7383],[-1366,-2484],[-3186,5937],[2885,-1783],[4816,-6463],[6864,-7748],[-1085,-6072],[9223,533],[3490,-2138],[-2937,-3269],[-4499,232],[-528,1689],[-1087,-4052],[-2975,4393],[9913,4739],[8286,-1029],[-7047,1752],[-5003,-1658],[-9324,-5575],[136,-7707],[1330,3241],[9293,-986],[-4119,-9128],[216,2333],[8878,-8230],[-6693,-8334],[-6767,-4734],[253,-7242],[-6419,7090],[-3069,-8965],[3197,-2698],[2515,-5363],[-4160,-2277],[5679,-4927],[-6984,6632],[-5797,-2527],[8478,646],[-4347,6445],[9102,-3051],[-6518,-7270],[-9699,2328],[9873,-4234],[-14,-8479],[5534,2915],[7120,8395],[-3291,1908],[-5985,-4476],[-2584,-7323],[-8921,2791],[3913,-1132],[437,7665],[3428,-5670],[5832,-8986],[-1121,-8079],[4093,-1723],[-7660,4434],[-1393,-2617],[695,-9918],[-2693,7320],[-4044,-1487],[-6581,-4902],[-995,620],[1703,-8296],[5401,3832],[9493,-2515],[-7494,-2293],[1474,-2000],[1440,8055],[778,-5000],[9492,-7962],[-1695,3458],[-6922,-5321],[-1495,-9194],[-4531,1349],[-5608,-6644],[-5261,7574],[908,9815],[-8730,-5060],[1033,824],[-5782,-1361],[9422,-8115],[8443,403],[-3174,-4480],[-1105,5800],[58,1392],[-6608,-4695],[1632,3565],[-1379,1921],[8376,2402],[-1124,8483],[3802,7984],[9500,449],[2895,-9534],[-5482,-1893],[-8582,4037],[-8261,-958],[-3609,8790],[-7903,9623],[-7592,3401],[-9412,7926],[8648,4675],[-9607,-5224],[-6173,1518],[-704,-994],[-4584,8282],[625,2235],[-4826,-9399],[-860,-5900],[6928,-1347],[-5809,-5075],[782,-1990],[1374,-1852],[1766,-8991],[9130,-3394],[-855,7618],[-2238,-8524],[-4315,7148],[1151,9562],[8635,3133],[3695,704],[-4052,-2623],[4203,-1223],[5420,7680],[-7084,-3661],[-7710,992],[8917,9521],[5998,-6432],[5518,-3906],[8133,8393],[9904,-3488],[2052,7555],[1150,6939],[-4518,-6002],[-8160,-3265],[-4917,-7639],[408,3214],[-6569,1115],[-1116,-9435],[-7366,3889],[-8246,-2915],[-4526,-8147],[7465,2817],[9472,-9440],[-5392,-8915],[-442,-5081],[2550,7472],[5146,7467],[-2201,-471],[-4516,-3209],[-57,4487],[4854,7169],[9730,-6298],[-6259,9079],[-1029,-8219],[-6975,-9373],[-1219,-8429],[-805,4417],[9445,-1309],[8503,-5802],[9220,9709],[-1778,6859],[2372,8688],[-9392,-4670],[5612,-7295],[6505,-9841],[7243,-9141],[-5458,6652],[-5886,347],[-9951,1459],[-7844,6706],[3955,5045],[-610,-2700],[-5725,5745],[6427,-3494],[9521,10000],[8584,-14],[9943,140],[1503,5205],[-796,5425],[2460,-5379],[7057,-5367],[-5224,-822],[-8427,4378],[2090,-6127],[3079,-4977],[7,-2237],[-7875,-1092],[9768,-5872],[3926,5351],[5420,-4165],[4332,-2185],[-3505,2823],[4509,1249],[9375,7593],[243,3588],[771,170],[982,-801],[6206,1665],[-5324,-2420],[4038,-7863],[-8557,8085],[-6975,-2443],[7207,-6546],[-3591,-6151],[-3808,9441],[-4846,-9153],[-2385,-7876],[5848,7802],[-6600,-9052],[-3226,-1258],[-5038,-2788],[1828,6246],[1174,-1143],[6788,-4792],[-961,6070],[-8130,-1219],[1095,-5100],[-5332,68],[471,-5693],[6848,402],[4444,-7804],[-9717,-1772],[9356,7119],[3054,7953],[5158,7716],[898,-447],[2328,-7556],[667,-7800],[3947,-2733],[-1208,4660],[-3914,9658],[9332,-4392],[-2697,-535],[6770,-6347],[-4671,5468],[-8890,-8888],[-7465,-1013],[-2150,-2006],[2981,-2996],[5454,6422],[9626,-4645],[-8387,-4319],[-9836,4182],[-7795,-3755],[-8131,263],[-3096,-4783],[6337,1605],[7151,-2422],[256,8415],[4027,-6559],[-3504,1619],[4804,4322],[-8404,-409],[-6931,-7792],[2757,5065],[-383,640],[8258,8323],[-5397,-4627],[-8442,-321],[5396,-4196],[4278,5693],[-5128,-8216],[9815,-6851],[2047,-681],[4477,9361],[-8836,-5651],[-8257,8243],[-5169,6191],[-846,-2864],[3136,5204],[-9669,1043],[4425,5085],[5195,6651],[-2278,-2239],[9794,7553],[-4247,196],[-8325,4664],[-8287,-8358],[2731,-1099],[6650,-477],[4868,1067],[6402,-4695],[-6497,860],[7031,-2846],[3418,-195],[-670,-2664],[-5817,4382],[5200,4126],[-3240,4797],[-5631,5512],[-4750,5819],[1950,-3387],[-2505,-7308],[1496,9200],[-9700,-690],[128,-5273],[7595,1761],[9022,1459],[6330,-9688],[127,-1071],[9612,6429],[-9104,-6449],[465,2117],[3318,2793],[8812,-6789],[8310,8637],[5637,-4947],[-2297,7311],[-137,-6496],[-7864,5878],[6000,-8224],[7337,-9028],[-3524,9528],[658,-9083],[-2881,3984],[2550,-6331],[-1606,-7754],[-3760,-9887],[8739,-3714],[-8955,998],[-8977,6599],[4994,1008],[-7335,-749],[4286,-1866],[-7333,-3108],[-5990,3274],[-7326,2841],[3794,1067],[5182,-1359],[-5676,-5179],[3772,-5649],[-4321,5223],[-6266,3931],[-4345,-2303],[-6927,-7424],[-9130,-4087],[-3549,-7743],[-6789,770],[3573,-9956],[6471,-8119],[5184,6724],[-4117,5688],[4959,-3018],[-8771,7513],[72,-5274],[-8649,114],[-8201,-4612],[8360,-4197],[5380,2267],[1367,-4104],[1454,-6541],[4561,-1580],[-9081,-5109],[-4249,5857],[-9724,-7701],[1727,-5975],[4809,2522],[-2469,5209],[7024,1146],[-2643,-7205],[-5409,-3432],[7132,7404],[9267,4462],[1785,-9885],[6071,3642],[3302,6881],[-5667,8890],[5334,6999],[9140,1200],[6076,785],[6238,-6736],[7915,-7893],[-2811,-2100],[3806,4231],[1026,-2917],[-2637,-5153],[825,-9368],[-7352,-2372],[7087,-5796],[-8767,-2868],[-5217,667],[-4983,4547],[9348,-8701],[-8456,-1668],[7256,-5092],[-8107,1096],[6719,2536],[-1990,4216],[-3291,4849],[-6642,-5124],[4683,7560],[9536,923],[3419,-4358],[4820,8909],[-2725,5222],[2265,2309],[-7670,-9992],[-1553,6950],[6709,8483],[-780,-5348],[9558,-4989],[1425,1475],[7513,3315],[1040,-3605],[-519,9108],[-3963,4367],[3899,945],[8459,-7003],[2463,-7187],[1269,9892],[-8369,-6509],[-6667,-4800],[5302,5301],[-1466,2798],[-7734,6402],[7730,-5926],[-313,1407],[-5416,3538],[-5713,-8751],[-9067,4767],[5923,-7644],[-7248,4159],[7635,-9556],[4977,6987],[53,1226],[9185,5193],[7211,-5967],[1777,-2742],[-5677,-285],[1117,7471],[-1361,-161],[-3412,-2750],[8787,3220],[4898,9847],[9813,7027],[-7183,6428],[-4053,3045],[-1298,3597],[-6981,-6724],[-8484,4992],[-4,-9637],[-5350,-2862],[-6392,4404],[-3367,5316],[-5926,7585],[-5487,6859],[3063,3986],[-8058,-8692],[7197,-9114],[1806,8358],[6493,-9143],[-1208,5710],[-9503,5686],[3601,-7473],[938,7383],[4255,-6024],[8665,-2044],[2479,861],[-4313,9379],[8318,9024],[829,-452],[-2298,116],[-3066,8108],[4825,-8048],[-8810,-8259],[-1542,3701],[5002,-7969],[-5981,1114],[3167,3328],[8421,5241],[951,4144],[1302,-627],[6549,100],[2307,-9592],[-7299,7497],[-7823,9876],[-1125,-1881],[6349,8578],[-8177,-3584],[-4299,4860],[-6399,1321],[-546,-5127],[281,-6499],[-4000,2549],[5250,3057],[-5834,9595],[3451,-2268],[-8576,-383],[-7120,-1587],[-9232,6438],[3832,6559],[-4197,1230],[-7851,-7698],[7462,-5568],[-9416,6333],[504,9206],[4359,2161],[6271,-3847],[2695,1663],[-9895,-8108],[320,7680],[-8195,8970],[5467,5313],[3101,-3104],[-2148,-8973],[229,-5141],[-2943,9278],[2159,9945],[6784,-4247],[-9924,6397],[-3781,2066],[-7513,-8482],[4292,450],[2714,8572],[-9297,6452],[9036,-4732],[9387,-4137],[-4840,-9832],[-9353,-7878],[-7330,8020],[-4794,4303],[4541,892],[935,8061],[1522,-7895],[-5664,758],[3150,-2162],[-227,4722]]
k = 300
Case 29
points = [[-2003,-5270],[4681,5894],[-7772,-9631],[-2823,5177],[9628,-8762],[-1663,1055],[9649,-8982],[3853,7779],[8312,-4193],[-4895,-8425],[4558,8103],[-3746,558],[-2450,-530],[6042,2549],[-6647,7224],[-4053,-9166],[1632,-2966],[1482,-7455],[-2227,-6605],[3220,8241],[5529,3768],[4776,-1797],[-577,-4216],[6331,-7864],[4645,6383],[-8816,-9656],[-8768,-7365],[-5521,1517],[9521,-4919],[-9072,-49],[9952,4756],[8321,7300],[-7757,8928],[-7148,2032],[8601,-679],[-473,-1084],[-2596,2369],[-3417,-3539],[-9856,-5000],[-8132,-3894],[817,-6289],[-8810,3338],[-4319,-4056],[2169,1436],[7367,5925],[-8964,-4424],[-69,-5591],[-2394,-8931],[-3927,4405],[9225,-2360],[4439,7302],[6933,-8944],[-1860,-7311],[7978,8632],[-8186,-6744],[6803,-9910],[4892,-4161],[1121,-38],[-8603,6520],[7972,-1393],[-5082,9701],[2013,-6681],[-2513,8330],[1346,7207],[-6301,2580],[3005,-1947],[3661,-9420],[-8458,-9114],[665,-6982],[6862,7939],[206,7089],[-8229,-6918],[-5888,-2752],[-1654,2608],[-1335,4094],[8167,5436],[-8550,-9382],[2309,5761],[4151,-9714],[219,5822],[648,-2291],[-7281,8371],[-2288,1903],[6843,3253],[-4167,4043],[9555,-3399],[-3947,8849],[-2554,-5804],[-241,6498],[-9044,-1175],[-8289,-1836],[6876,-6157],[-5241,5883],[9756,-9621],[7593,-6352],[9824,-4780],[6167,-7868],[367,374],[-787,7723],[-8347,-1318],[-5677,-9929],[5868,4489],[-6529,-2425],[7903,-4371],[8488,5894],[-7874,-8167],[-7076,2360],[1313,-8158],[4104,-7437],[183,2720],[1691,-1512],[6286,-3933],[-3725,-9422],[-9617,-8040],[-7409,-4829],[-7035,7659],[2530,-5441],[-1877,5086],[-5562,-2297],[1078,3571],[2284,1756],[1279,-8187],[1776,-5603],[9678,-9583],[9804,-8263],[-9136,2570],[8335,-4455],[6200,4462],[-5706,6560],[1500,-9733],[-1961,1542],[-9053,500],[1313,3422],[-1375,-7801],[4074,693],[9178,6747],[414,-5140],[9920,-3389],[-3267,-3322],[-2621,7906],[-3145,1694],[1692,4982],[2595,-3428],[7428,5720],[5000,-7562],[231,6917],[-4270,-3459],[5238,1967],[-2752,-140],[-6513,-8782],[6333,-2474],[-2891,-4460],[-7414,-1533],[-8552,-5342],[2173,4148],[6482,-9570],[-2575,9901],[-6743,-8770],[7088,-914],[9182,-7788],[-892,-2555],[7868,2520],[9853,3728],[1409,1613],[-4814,-1245],[9483,2584],[8525,316],[2043,-349],[-9669,3973],[7560,8774],[8022,9758],[5985,-45],[-8622,-8149],[2577,868],[-3431,-9131],[2771,9850],[-9759,-9667],[-915,-5651],[-8233,7010],[4294,-6553],[5280,6968],[3545,-3733],[1375,-5928],[7146,5334],[-2280,-1273],[-3305,2295],[8767,1970],[-1872,2042],[-5926,-4868],[-8545,-881],[-2548,9428],[-5720,5728],[475,-5343],[-9925,-9104],[6552,-8437],[-1946,5755],[-1768,-132],[5635,4307],[-2657,-5352],[6959,3982],[-4610,-7363],[-207,1164],[2071,1967],[-2360,-8275],[9156,-9826],[1030,-1294],[2130,70],[-9667,2192],[-5114,1817],[7903,7780],[4947,5855],[3476,1585],[-9371,-6445],[5319,-5557],[1292,8703],[-5498,549],[-8055,-8364],[1675,7426],[2447,-7729],[-2892,-1296],[8445,-4689],[6945,-981],[9678,-3302],[-8325,-7118],[1738,-4799],[3525,5708],[-3791,-2406],[-6823,-6954],[-489,-7249],[3574,3488],[-7129,-9516],[-8575,-3054],[-878,-3180],[3907,-2882],[1695,7768],[2628,524],[6679,2956],[92,-2692],[-3354,1085],[-6819,-8081],[5473,-8436],[-3245,293],[-8282,-9600],[1183,-5112],[8514,1503],[-8040,-7963],[1843,-4789],[2209,1453],[-9866,8293],[-5410,-5964],[9953,5690],[8013,-8529],[2585,158],[9323,2804],[8348,-1733],[-4420,3117],[-7796,7837],[8785,-3806],[-2674,4683],[9263,9515],[-3529,-2507],[-3617,4412],[-6306,1460],[-348,5104],[9270,6031],[-7724,8994],[-8057,-7614],[-8639,3039],[-6928,-3403],[2016,-7048],[-4859,-9554],[3024,8045],[-4434,8904],[8221,-11],[-2204,-8215],[7154,-2478],[-5596,-2187],[-4247,6531],[-8853,-7137],[7034,9008],[-7905,-2736],[-7548,-6842],[-6958,9333],[-1281,-256],[7312,-2993],[2397,4046],[-1704,-4148],[-9571,-2091],[5150,-7527],[-9127,-3674],[2834,1286],[5071,-2483],[9750,-8099],[4232,-4353],[8484,811],[9922,-9356],[-9986,5721],[-6393,-6323],[2794,-827],[6687,-6700],[6115,6170],[7513,2149],[6284,1236],[-4051,-5797],[-1933,-1451],[2641,9199],[-7694,-416],[-8838,8501],[-1137,-5988],[9682,-2874],[4230,2760],[-6497,-9441],[5142,6911],[2273,-2122],[3651,-8310],[-4124,9479],[-7064,-519],[-328,-1626],[9929,6375],[8206,6925],[-471,-2579],[-4617,7952],[5259,-892],[8387,7531],[-6719,-581],[7722,-8826],[-9459,206],[4449,-4546],[-5486,-5221],[-9109,2094],[2485,4469],[9678,4642],[7075,-480],[4717,4500],[4599,-8579],[-7155,-4347],[-28,-3635],[-5422,-8669],[-9926,8704],[421,6073],[845,-5931],[-110,1026],[8464,-3194],[-7144,-1662],[-7032,-7246],[9059,1475],[5426,7917],[8303,-1219],[-7577,1263],[1241,5551],[3674,9869],[6105,2652],[-3515,-458],[7303,9074],[-7291,-3577],[-9506,-6058],[-350,-5942],[-8709,-3889],[154,-392],[8735,4871],[3926,6715],[-4016,-4349],[1246,-3378],[4927,-3834],[-9854,3846],[-6094,-1],[3526,-9543],[5330,6896],[7189,-7848],[-3232,-3170],[2803,9413],[5530,-3015],[9450,164],[5383,6914],[8464,-1355],[-9816,-325],[4985,5206],[-9762,-223],[488,-5027],[-6529,-89],[-5861,-8782],[7943,3786],[6389,212],[4253,5097],[6124,9999],[6491,6574],[-8323,-9640],[3415,-8411],[-3368,3171],[-4690,4393],[9269,-725],[2720,-9515],[6424,-6808],[-6691,4186],[5146,2653],[-673,-1471],[5319,-7198],[7460,-8340],[577,-8214],[5863,4031],[243,1977],[-5599,-7385],[4457,-3872],[-740,-1552],[-9083,3725],[-2202,-3355],[-6981,-6696],[9427,-8486],[-190,-6904],[-6297,8129],[7635,795],[-899,2669],[-1648,-6947],[7305,1037],[8829,5111],[-2926,-3733],[-8716,6839],[-4316,-6917],[464,6286],[-9736,-4522],[4490,-6804],[-6622,-5422],[1917,4772],[8902,-3192],[-288,4486],[3475,-1509],[4173,2807],[2962,-683],[7096,1112],[-6666,7629],[9707,-941],[-3378,-596],[-9446,-7776],[-7863,-3539],[4496,1102],[666,8141],[4015,9692],[3230,8226],[-4465,5572],[-2404,3583],[2913,-8284],[315,6816],[-9298,-4951],[6572,-5632],[-6801,-1068],[-8670,9413],[-4128,4940],[4399,7265],[5321,-5418],[4510,5310],[6403,186],[2919,6677],[319,5903],[9585,-4943],[-9551,1058],[3212,-1712],[-8684,-8398],[-5780,247],[-8454,6798],[-1590,6042],[-1916,-1854],[9037,-4331],[4940,-6083],[4499,8351],[-8183,7477],[73,-7658],[-2025,5715],[5510,9872],[-2613,-7252],[-15,3490],[9063,3452],[-3975,-8479],[-1856,-8848],[1611,-6952],[-2380,-3836],[5910,-5460],[-517,7613],[-4377,-9400],[7598,708],[-6734,7380],[6239,6465],[4175,8538],[-7336,6767],[-7391,-9808],[-7700,6620],[-6159,7008],[-7397,-1699],[5366,-2712],[-7177,6548],[-1149,9535],[8685,-3128],[5799,-524],[5367,8641],[-3763,-7284],[-3896,-7335],[2763,6570],[-2358,-1553],[9940,-7862],[-3600,2394],[-4478,6911],[-1289,1392],[7394,9059],[1989,4068],[-5293,3231],[-1428,6540],[-8464,7242],[9481,3254],[-1579,-5920],[-8319,-2528],[-5480,7556],[4485,-5752],[-6631,1366],[-6785,1465],[-5031,7420],[-8347,6993],[-8408,9065],[4696,161],[-570,9650],[-6484,-3754],[-5686,-4742],[-8663,-8215],[5273,3462],[-3631,-6602],[103,3649],[-7507,-6894],[3531,-4773],[-531,-4019],[-8234,-7569],[3904,6635],[278,-6497],[-3696,4421],[8906,7336],[1328,-6000],[-6231,-8060],[917,-9657],[-5537,-1128],[5392,-8694],[-2596,-20],[-9366,-1588],[-3112,-6093],[7148,3594],[-3812,-5814],[-667,-442],[9139,3128],[149,7402],[7969,3990],[2091,9003],[5563,983],[-7426,5401],[5410,-308],[6679,4076],[-8578,5093],[-8138,-106],[-5058,-4606],[-2988,-1522],[1916,-9706],[-2670,-5751],[4903,5399],[-2147,-7749],[-1615,-2893],[-8881,-4076],[8329,-9889],[9911,-9241],[8561,-1272],[9300,-4162],[-567,-718],[6854,4350],[-938,-3866],[-3281,-2496],[-1452,-6812],[-900,-7009],[-4484,-1549],[-8920,4497],[-6264,3701],[-8624,-7224],[-2500,8528],[6467,-2653],[-5090,-3905],[-7819,-7515],[-812,8714],[6828,777],[6643,-9634],[-7591,-7204],[-6855,9214],[-2442,-1539],[2991,5075],[984,8955],[-6315,-568],[7764,8638],[1685,9954],[-474,794],[-3730,2032],[-5456,8372],[-1518,6815],[4227,5271],[9008,-7058],[1830,4480],[-3046,-7138],[8660,-9731],[-7068,4602],[5798,2106],[3680,3227],[4238,2713],[-5859,9309],[-893,9524],[-5858,-4708],[2790,-2126],[2170,-9675],[1492,503],[3009,-7876],[-6157,5144],[6188,279],[5285,-8315],[-7254,-7200],[-6731,7048],[-157,5503],[-384,-7028],[-3393,5784],[-384,3142],[-2298,1164],[-398,3230],[-1920,-1228],[-4644,1270],[7388,2502],[-8254,-7727],[-9552,-3205],[-8693,-7172],[8204,9161],[-3991,2998],[-116,-9340],[3949,3233],[3378,-1144],[6830,-7718],[1209,-9050],[8098,-9233],[2540,-4076],[2069,-4431],[-2486,5076],[-7076,-714],[-9248,3547],[-1793,-1422],[6020,523],[-339,4649],[-7032,2009],[4516,-2837],[8264,-4050],[-8910,3847],[-5178,4685],[-6024,5879],[2118,8908],[6268,-8599],[3861,-9611],[1613,-7721],[7600,-4993],[5151,5623],[-3248,-3847],[-8063,-2625],[-4422,-3649],[-9173,382],[-3037,4305],[-926,-7064],[-9767,-2200],[-2887,-2435],[300,4234],[-1292,9413],[2812,3496],[-7615,6680],[-1003,-5405],[-3816,-6267],[5718,-3232],[3565,-2544],[-9616,-1451],[6775,-8924],[-5318,6720],[-1604,-5953],[2497,2531],[4875,2554],[8316,-5865],[-3292,9735],[-552,3577],[7425,1188],[8344,9097],[6969,-9655],[-6631,5912],[4397,-5098],[-3707,-1926],[2439,-5463],[941,-29],[5439,5132],[-6853,-3932],[-1402,-5140],[-2916,-9305],[2427,363],[8434,5698],[-1228,-5961],[3937,6859],[-7691,-5899],[-6312,-1045],[-6082,-868],[-2469,-7978],[1334,-5679],[6085,430],[4824,8662],[6305,-4323],[9110,-3872],[1178,3817],[-6345,2141],[-9160,-1339],[-5291,1214],[-5333,6600],[9952,-4252],[8445,3467],[-7060,9527],[518,-7558],[-4364,-9426],[-6317,-4053],[5057,-7997],[4381,1207],[3482,-2584],[-6282,9508],[-14,61],[9909,1493],[-5787,-8379],[-6438,396],[-8331,-1729],[-3489,2081],[1096,9331],[5004,-734],[-9223,8987],[-8568,-8926],[-3925,-8919],[-1700,2619],[1448,5663],[-5646,7990],[-9327,3339],[5555,4003],[5223,-7536],[-6810,-63],[106,692],[-4292,-2324],[2010,-5844],[1930,-2629],[-627,5469],[-3698,7781],[4752,-6883],[2859,-7552],[-7703,-1215],[-4301,-3529],[1605,4979],[-638,-9793],[-6398,-2876],[9216,-8164],[1999,483],[4086,8674],[-835,-3326],[3203,-8337],[2848,8861],[9100,-2364],[8163,8385],[-4616,5084],[4009,-9289],[-3541,-667],[8676,-6770],[-5972,3779],[4045,2597],[6993,-2840],[857,-8093],[-2128,5479],[2730,-7448],[-126,-5057],[6523,-2955],[1198,5036],[-1566,628],[2290,-3218],[-4307,5848],[4032,5159],[-5066,-1327],[19,9378],[-8992,6378],[-4401,2215],[-6392,1704],[6707,7928],[3143,5773],[-7627,-9560],[-5783,6271],[-7107,6742],[-8107,-8652],[-2075,251],[6037,-985],[4750,-8446],[3233,-7518],[-7786,2612],[-8289,-6556],[2454,1002],[7426,-2837],[3991,2238],[5749,9254],[-3666,1871],[717,4179],[-181,-1848],[9828,-4966],[-6421,6948],[5545,-436],[8516,-6929],[-936,-5874],[9313,8766],[9573,8993],[3826,-4556],[-4206,-1086],[799,2633],[9718,-1164],[-9880,-6220],[1920,2020],[-3709,6063],[6870,-4233],[8638,6215],[-191,9125],[-9613,-3990],[2808,5302],[7438,378],[3600,-8620],[2498,-9111],[-8561,8047],[-6902,-5156],[3190,6068],[-1844,-8683],[-5627,6299],[2770,8637],[3917,-7884],[2489,-9940],[5699,3446],[7002,1095],[-8814,5991],[744,3387],[-9186,-359],[-7495,-1766],[-5449,3874],[-2104,-1187],[-4232,461],[-8783,-1756],[-9608,-933],[-4850,-2942],[-8933,1704],[-3352,-7285],[2868,3509],[-1796,2697],[-5990,-9627],[8764,-4116],[-5388,-2940],[-8914,-8272],[-9912,9903],[9359,-9120],[-298,112],[-2982,-1393],[-1271,-1865],[2065,-2963],[-3219,-8935],[-8892,-5727],[3043,-6637],[124,338],[4728,-8711],[2310,8212],[7410,7859],[-5043,-2473],[-5251,-9439],[4936,-1369],[-7079,-9235],[-9623,6382],[35,354],[-6266,675],[-2583,2012],[1008,454],[-2773,9485],[1281,323],[-6404,-1435],[8495,4961],[-350,-2414],[-2521,9581],[5483,-8100],[6205,1915],[-5158,9811],[-3280,5225],[5414,664],[-1009,-5779],[-2404,4684],[2804,7483],[-191,-7468],[-6114,-5343],[-562,-1640],[-4879,9075],[6488,597],[-7332,3464],[4284,7006],[-5910,750],[7829,3316],[7004,-3323],[-8090,-4238],[2114,8637],[-6930,6768],[4169,7347]]
k = 30
Case 30
points = [[4,-6],[-1,-3],[0,2],[-1,2],[1,0],[4,2],[-6,-4],[5,-6],[1,-1],[2,-4],[-6,6],[-1,1],[-2,-3],[3,-4],[-4,-3],[-5,-3],[3,2],[4,-4],[-5,-1],[0,-2],[-1,-2],[1,6],[2,-3],[3,0],[-5,-3],[1,4],[-6,5],[2,-5],[-4,5],[-3,-5]]
k = 12
Case 31
points = [[-1,5],[5,-4],[1,-4],[0,1],[3,0],[0,4],[3,-3],[5,1],[0,-5],[3,5],[0,1],[-4,-6],[2,5],[3,-4],[-2,-4],[-4,-4],[-4,3],[0,0],[6,-2],[-1,-1],[-3,-1],[2,3],[-6,-2],[-1,2],[-6,-2],[-2,5],[-4,-3],[-2,-2],[0,6],[4,2],[5,2],[-2,4],[-2,-4],[-5,-3],[-5,-1],[0,-2],[5,5],[-3,3],[5,-1],[4,-1],[-1,3],[-5,2],[2,-1],[-2,1],[5,1],[0,0],[2,0],[1,-4],[1,0],[-4,-2]]
k = 20