#include #include using namespace std; using namespace atcoder; using ll=long long; int main() { int n; cin>>n; ll sum=0; vector>> v(2); for(int i=0;i>c>>x>>y; if(x>=y){ v[0].push_back(make_pair(n-c,x-y)); sum+=y; }else{ v[1].push_back(make_pair(c,y-x)); sum+=x; } } auto solve=[n](vector> v)->ll{ int m=v.size(); sort(v.begin(),v.end()); ll res=0; priority_queue,greater> pq; int l=0; for(int i=0;i<=n;i++){ while(li){ pq.pop(); } } while(!pq.empty()){ res+=pq.top(); pq.pop(); } return res; }; cout<