This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<iostream>
#include<algorithm>
using ll = int;
using namespace std;
#define pll pair <ll,ll>
#define fi first
#define se second
#define sz(a) (ll((a).size()))
#define BIT(mask,i) (((mask) >> (i))&1)
#define MASK(i) (1LL << (i))
#define MP make_pair
ll t;
ll n;
const ll MAXN=1.5e5;
bool del[MAXN+100];
pll a[3][MAXN+100];
ll val[3][MAXN+100];
int main(){
    ios_base::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);
    cin>>n;
    for (ll i = 1;i <= n;i ++){
        for (ll j = 0;j < 3;j ++){
            cin>>a[j][i].fi;
            a[j][i].se=i;
            val[j][i] = a[j][i].fi;
        }
    }
    for (ll j = 0;j < 3;j ++){
        sort(a[j]+1,a[j]+1+n);
    }
    ll p[3];
    p[0]=p[1]=p[2]=n;
    for (ll i = 1;i <= n;i ++){
        for (ll j = 0;j < 3;j ++){
            while (del[a[j][p[j]].se])p[j]--;
        }
        bool ok = 1;
        for (ll j1 = 0;j1 < 3 && ok;j1 ++){
            for (ll j2 = 0;j2 < 3 && ok;j2 ++){
                if (j2==j1)continue;
                ll bad = a[j1][p[j1]].se;
                ll good = a[j2][p[j2]].se;
                if (val[j2][bad] == val[j2][good]){
                    del[bad] = 1;
//                    cout<<i<<' '<<bad<<' '<<good<<endl;
                    ok = 0;
                }
            }
        }
        if (ok){
            ll sum = 0;
            for (ll j = 0;j < 3;j ++){
                sum += a[j][p[j]].fi;
            }
        cout<<sum;
            return 0;
        }
    }
    cout<<-1<<'\n';
}
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... |