We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
  • HackerRank Home
  • |
  • Prepare
  • Certify
  • Compete
  • Apply
  • Hiring developers?
  1. Prepare
  2. Mathematics
  3. Geometry
  4. Stars

Stars

Problem
Submissions
Leaderboard
Discussions
Editorial

Little John has drawn stars on his paper where each star has a weight . He draws a straight line that divides the paper into two parts such that each part has a subset of stars in them. Let the weight of each part be the summation of weights of the stars in the part. He wants to draw the line such that the difference in the sum of weights between the two parts is as small as possible while maximizing the smaller part's weight.

Your task is to compute the weight of smaller part corresponding to this line where no stars are allowed to be on the line and line can be of any slope.

Input Format
The first line of the input contains an integer .
Each of next lines contains three integers and specifying the positions of star and .
No three points lie on a line.

Constraints


Output Format
Print an integer being the answer to the test.

Sample Input 0

4
1 1 2
-1 1 2
-1 -1 4
1 -1 5

Sample Output 0

6

Explanation
You can imagine a line along the and see that point and lie on left side summing up to 6, while the other side has sum as .

Sample Input 1

10
748798831 -200797120 595
-774675771 179630170 159
-338760201 945958360 750
955629379 -312997434 516
755005057 -672683474 405
-743176829 190325067 86
-301478753 -718170081 923
-795908444 985440803 854
-102868895 671114060 246
-698209449 12550066 190

Sample Output 1

2358

Explanation

and are two sets of weights.

Author

HackerRank

Difficulty

Medium

Max Score

50

Submitted By

1212

Need Help?


View discussions
View editorial
View top submissions

rate this challenge

MORE DETAILS

Download problem statement
Download sample test cases
Suggest Edits
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Helpdesk
  • Careers
  • Terms Of Service
  • Privacy Policy

Cookie support is required to access HackerRank

Seems like cookies are disabled on this browser, please enable them to open this website

Join us

Create a HackerRank account

Be part of a 26 million-strong community of developers

Please signup or login in order to view this challenge

or
Already have an account?Log in