#include <bits/stdc++.h>

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}
struct Info {
	int64_t get;
	int64_t score;
	int64_t lose;
};
// {money, score}
std::vector<std::pair<int64_t, int64_t> > solve(const std::vector<Info> &a, int head) {
	int n = a.size();
	if (n == head) return {{0, 0}};
	std::vector<std::pair<int64_t, int64_t> > res = solve(a, head + 1);
	for (auto &i : res) i.first += a[head].get;
	if (head + 1 < n) {
		auto tmp = solve(a, head + 2);
		for (auto &i : tmp) i.first -= a[head + 1].lose, i.second += a[head + 1].score;
		res.insert(res.end(), tmp.begin(), tmp.end());
	}
	return res;
}

int main() {
	int n = ri();
	if (n == 1) {
		std::cout << 0 << std::endl;
		return 0;
	}
	std::vector<Info> a(n);
	for (auto &i : a) std::cin >> i.get >> i.score >> i.lose;
	int half = n / 2;
	int64_t res = 0;
	auto merge = [&] (int split) {
		auto r0 = solve(std::vector<Info>(a.begin(), a.begin() + split), 0);
		auto r1 = solve(std::vector<Info>(a.begin() + split, a.end()), 0);
		std::sort(r1.begin(), r1.end(), [] (auto i, auto j) { return i.first > j.first; });
		int64_t max = -1000000000000000000;
		int head = 0;
		std::sort(r0.begin(), r0.end(), [] (auto i, auto j) { return i.first < j.first; });
		for (auto &i : r0) {
			while (head < (int) r1.size() && r1[head].first + i.first >= 0) max = std::max(max, r1[head].second), head++;
			res = std::max(res, max + i.second);
		}
	};
	merge(half);
	merge(half + 1);
	std::cout << res << std::endl;
	return 0;
}