#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <set>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <memory.h>
#include <string>
#include <sstream>
#include <cstdlib>
#include <ctime>
#include <cassert>
#include <math.h>
#define FF first
#define SS second
#define MP make_pair
#define PB push_back
#define MOD 1000000007
#define INF 2000000000
#define PI 3.141592653
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
const int MAXN = 1010;
double x[MAXN], y[MAXN]; int a[MAXN];
const int MAGIC = 20010;
int n; double m;
bool cmp(int i, int j) { return y[i] - m * x[i] < y[j] - m * x[j]; }
vector<int> indices;
int main() {
cin >> n; int atot = 0;
for (int i = 0; i < n; i++) {
cin >> x[i] >> y[i] >> a[i];
atot += a[i];
}
for (int i = 0; i < n; i++) indices.PB(i);
srand((unsigned) time(NULL));
int res = atot;
for (int i = 0; i < MAGIC; i++) {
double A = ((double)rand()/(double)RAND_MAX);
A = (A - 0.5) * PI;
m = tan(A);
sort(indices.begin(), indices.end(), cmp);
int acurr = 0;
for (int i = 0; i < n; i++) {
acurr += a[indices[i]];
res = min(res, abs(atot - 2 * acurr));
}
}
printf("%d\n", res);
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8aW9tYW5pcD4KI2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzZXQ+CiNpbmNsdWRlIDx2ZWN0b3I+CiNpbmNsdWRlIDxtYXA+CiNpbmNsdWRlIDxjbWF0aD4KI2luY2x1ZGUgPGFsZ29yaXRobT4KI2luY2x1ZGUgPG1lbW9yeS5oPgojaW5jbHVkZSA8c3RyaW5nPgojaW5jbHVkZSA8c3N0cmVhbT4KI2luY2x1ZGUgPGNzdGRsaWI+CiNpbmNsdWRlIDxjdGltZT4KI2luY2x1ZGUgPGNhc3NlcnQ+CgojaW5jbHVkZSA8bWF0aC5oPgoKI2RlZmluZSBGRiBmaXJzdAojZGVmaW5lIFNTIHNlY29uZAojZGVmaW5lIE1QIG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