#include <algorithm>
#include <iostream>
#include <cassert>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cstdio>
#include <string>
#include <vector>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <map>
#include <set>
using namespace std;
#define F first
#define S second
#define endl '\n'
#define mp make_pair
#define pb push_back
#define FOR(i, a, b) for(int i = a; i <= b; i++)
#define ROF(i, a, b) for(int i = a; i >= b; i--)
#define type(x) __typeof((x).begin())
#define foreach(i, x) for(type(x) i = (x).begin(); i != (x).end(); i++)
#define sol (root + root)
#define sag (root + root + 1)
#define orta ((bas + son) >> 1)
#define bit __builtin_popcount
#ifndef D
#define dbg(x) 0
#define dbgs(x) 0
#else
#define dbg(x) cerr << (#x) << " --> " << (x) << endl
#define dbgs(x) cerr << (#x) << " --> " << (x) << ' '
#endif
typedef long long ll;
typedef pair < int, int > pii;
const int inf = 1e9 + 5;
const ll linf = 1e18 + 5;
const int N = 1000 + 5;
const int K = 100000;
const double PI = acos(-1);
int n;
pair < pair < double, double >, int > a[N];
int main () {
ios :: sync_with_stdio(0);
cin >> n;
int all = 0;
FOR(i, 1, n) {
cin >> a[i].F.F >> a[i].F.S >> a[i].S;
all += a[i].S;
}
int ans = inf;
double x, y, c = cos(PI / K), s = sin(PI / K);
FOR(i, 1, K) {
bool flag = 1;
while(flag) {
flag = 0;
FOR(i, 1, n - 1)
if(a[i].F.F > a[i + 1].F.F + (1e-6)) {
flag = 1;
swap(a[i], a[i + 1]);
}
}
int sum = 0;
FOR(i, 1, n) {
sum += a[i].S;
ans = min(ans, abs(all - sum - sum));
x = a[i].F.F;
y = a[i].F.S;
a[i].F.F = x * c - y * s;
a[i].F.S = x * s + y * c;
}
}
cout << ans << endl;
return 0;
}
I2luY2x1ZGUgPGFsZ29yaXRobT4KI2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8Y2Fzc2VydD4KI2luY2x1ZGUgPGNsaW1pdHM+CiNpbmNsdWRlIDxjc3R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