#include #include #include using namespace std; using namespace atcoder; using mint = modint998244353; #define rep(i,n) for (int i = 0; i < (n); ++i) #define Inf32 1000000001 #define Inf64 1000000000000000000LL long long get(vector c,vector x){ vector> t; set S; rep(i,c.size()){ t.push_back({x[i],c[i]}); S.insert(i+1); } long long res = 0; sort(t.rbegin(),t.rend()); rep(i,t.size()){ auto it = S.upper_bound(t[i].second); if(it == S.begin())continue; it--; res += t[i].first; S.erase(it); } return res; } int main(){ int n; cin>>n; vector c(n),x(n),y(n); long long ans = 0; vector> cc(2),xx(2),yy(2); rep(i,n){ long long c,x,y; cin>>c>>x>>y; swap(x,y); if(x==y)ans += x; else if(x