criyle/codenet-compile-errors huggingface dataset:
Language: Java

import java.io.*;
import java.util.StringTokenizer;

public class SportsFestG18B {
    public static void main(String[] args) throws IOException {
        FastScanner in = new FastScanner();
        
        int n = in.nextInt();
        int m = in.nextInt();
        
        int matrix[][] = new int[n][m];
        
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                matrix[i][j] = in.nextInt() - 1;
            }
        }
        
        int curIndex[] = new int[n];
        int numPlayers[] = new int[m];
        
        
        int best = 301;
        
        for (int i = 0; i < n; i++) numPlayers[matrix[i][0]]++;
        
        for (int i = 0; i < n-1; i++) {
            int curMax = 0;
            int maxSport = -1;
            for (int j = 0; j < m; j++) {
                if (numPlayers[j] > curMax) {
                    curMax = numPlayers[j];
                    maxSport = j;
                }
            }
            
            if (curMax < best) best = curMax;
            
            numPlayers[maxSport] = -1;
            
            for (int j = 0; j < m; j++) if (numPlayers[j] != -1) numPlayers[j] = 0;
            
            for (int j = 0; j < n; j++) {
                while (numPlayers[matrix[j][curIndex[j]]] == -1) curIndex[j]++;
                numPlayers[matrix[j][curIndex[j]]]++;
            }
        }
        System.out.println(best);
    }

    public static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner(String s) {
            try {
                br = new BufferedReader(new FileReader(s));
            } catch (FileNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }

        public FastScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String nextToken() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        String nextLine() {
            st = null;
            try {
                return br.readLine();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            return null;
        }

        int nextInt() {
            return Integer.parseInt(nextToken());
        }

        long nextLong() {
            return Long.parseLong(nextToken());
        }

        double nextDouble() {
            return Double.parseDouble(nextToken());
        }
    }
}


Compiler output:
Main.java:4: error: class SportsFestG18B is public, should be declared in a file named SportsFestG18B.java
public class SportsFestG18B {
       ^
1 error
Language: C++

///****In the name of ALLAH, most Gracious, most Compassionate****//

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair <ll, ll> pii;

#define ALL(a) a.begin(), a.end()
#define FastIO ios::sync_with_stdio(false); cin.tie(0);cout.tie(0)
#define IN freopen("input.txt","r+",stdin)
#define OUT freopen("output.txt","w+",stdout)

#define DBG(a) cerr<< "line "<<__LINE__ <<" : "<< #a <<" --> "<<(a)<<endl
#define NL cout<<endl

template < class T1,class T2>
ostream &operator <<(ostream &os,const pair < T1,T2 > &p)
{
    os<<"{"<<p.first<<","<<p.second<<"}";
    return os;
}

const ll N=1e6+5;


ll lft[N];
ll rht[N];

ll a[N];
ll b[N];
ll c[N];

bool a_b(ll l,ll r)
{
    return a[l]-b[l] >= a[r]-b[r];
}

ll32_t main()
{
    FastIO;
    ll x,y,z;
    cin>>x>>y>>z;
    ll n = x+y+z;
    vector < ll  > p (n,0);
    ll ans = 0;
    for(ll i=0; i<n; i++)
    {
        cin>>a[i]>>b[i]>>c[i];
        p[i] = i;
    }
    sort(ALL(p), a_b);

    {
        priority_queue<ll > pq;
        ll now = 0, q = 0;
        for(ll i=0; i<n; i++)
        {
            ll ii = p[i];
            now+=c[ii];
            ll d= a[ii]-c[ii];
            q+=d;
            pq.push(-d);
            if(pq.size() > x)
            {
//                assert(pq.size());
                q+=pq.top();
                pq.pop();
            }
            lft[i] =now + q;
        }
    }
    {
        priority_queue<ll > pq;
        ll now = 0, q = 0;
        for(ll i=n-1; i>=0; i--)
        {
            ll ii = p[i];
            now+=c[ii];
            ll d= b[ii]-c[ii];
            q+=d;
            pq.push(-d);
            if(pq.size() > y)
            {
                q+=pq.top();
                pq.pop();
            }
            rht[i] =now + q;
        }
    }
    for(ll i=0; i<n-1; i++)
    {
        if(i+1 >= x and n-i-1 >= y)
            ans = max(ans, lft[i] + rht[i+1]);
    }
    cout<<ans<<"\n";
}


Compiler output:
a.cc:39:1: error: 'll32_t' does not name a type
   39 | ll32_t main()
      | ^~~~~~
Language: C++

#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
// run : ctrl + c 

template<class T>bool chmax(T &a,T b){if(a<b){a=b;return 1;} return 0;}
template<class T>bool chmin(T &a,T b){if(b<a){a=b;return 1;} return 0;}



signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    int x,y,z;
    cin>>x>>y>>z;
    int n = x+y+z;
    ll a[n],b[n],c[n];
    array<ll,3> v[n];
    for(int i=0;i<n;i++){
        cin>>a[i]>>b[i]>>c[i];
        v[i] = {b[i] - a[i],c[i],a[i]};
    }
    sort(v,v+n);
    ll pre[n]={}, pos[n]={};
    priority_queue<ll> pq;
    for(int i=0;i<x;i++){
        pq.push(v[i][1] - v[i][2]);
        pre[i] = v[i][2];
        if(i) pre[i] += pre[i-1];
        //cerr << pre[i] << endl;
    }
    for(int i=x;i<x+z;i++){
        pq.push(v[i][1] - v[i][2]);
        ll p = pq.top();
        pq.pop();
        pre[i] += v[i][2];
        pre[i] += pre[i-1] + p;
        //cerr << pre[i] << endl;
    }
    while(pq.size()) pq.pop();
    for(int i=0;i<y;i++){
        pq.push(v[n-1-i][1] - (v[n-1-i][0]+v[n-1-i][2]));
        pos[n-1-i] = v[n-1-i][0] + v[n-1-i][2];
        if(i) pos[n-1-i] += pos[n-i];
    }
    for(int i=y;i<z+y;i++){
        pq.push(v[n-1-i][1] - (v[n-1-i][0] + v[n-1-i][2]));
        ll p = pq.top();
        pq.pop();
        pos[n-1-i] = v[n-1-i][0] + v[n-1-i][2];
        pos[n-1-i] += pos[n-i] + p;
    }
    ll ans = 0;
    for(int i=x-1;i<x+z;i++){
        chmax(ans,pre[i]+pos[i+1]));
        
    }
    cout << ans << endl;



}


Compiler output:
a.cc: In function 'int main()':
a.cc:57:35: error: expected ';' before ')' token
   57 |         chmax(ans,pre[i]+pos[i+1]));
      |                                   ^
      |                                   ;
Language: C++

#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
// run : ctrl + c 

template<class T>bool chmax(T &a,T b){if(a<b){a=b;return 1;} return 0;}
template<class T>bool chmin(T &a,T b){if(b<a){a=b;return 1;} return 0;}



signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    int x,y,z;
    cin>>x>>y>>z;
    int n = x+y+z;
    ll a[n],b[n],c[n];
    array<ll,3> v[n];
    for(int i=0;i<n;i++){
        cin>>a[i]>>b[i]>>c[i];
        v[i] = {b[i] - a[i],c[i],a[i]};
    }
    sort(v,v+n);
    ll pre[n]={}, pos[n]={};
    priority_queue<ll> pq;
    for(int i=0;i<x;i++){
        pq.push(v[i][1] - v[i][2]);
        pre[i] = v[i][2];
        if(i) pre[i] += pre[i-1];
        //cerr << pre[i] << endl;
    }
    for(int i=x;i<x+z;i++){
        pq.push(v[i][1] - v[i][2]);
        ll p = pq.top();
        pq.pop();
        pre[i] += v[i][2];
        pre[i] += pre[i-1] + p;
        //cerr << pre[i] << endl;
    }
    while(pq.size()) pq.pop();
    for(int i=0;i<y;i++){
        pq.push(v[n-1-i][1] - (v[n-1-i][0]+v[n-1-i][2]));
        pos[n-1-i] = v[n-1-i][0] + v[n-1-i][2];
        if(i) pos[n-1-i] += pos[n-i];
    }
    for(int i=y;i<z+y;i++){
        pq.push(v[n-1-i][1] - (v[n-1-i][0] + v[n-1-i][2]));
        ll p = pq.top();
        pq.pop();
        pos[n-1-i] = v[n-1-i][0] + v[n-1-i][2];
        pos[n-1-i] += pos[n-i] + p;
    }
    ll ans = 0;
    for(int i=x-1;i<x+z;i++){
        chmax(ans,pre[i]+pos[i+1]))
        
    }
    cout << ans << endl;



}


Compiler output:
a.cc: In function 'int main()':
a.cc:57:35: error: expected ';' before ')' token
   57 |         chmax(ans,pre[i]+pos[i+1]))
      |                                   ^
      |                                   ;
Language: C++

#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
#pragma GCC optimize("O3")
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define EPS (1e-9)
#define INF (1e17)
#define PI (acos(-1))
//const double PI = acos(-1);
//const double EPS = 1e-15;
//long long INF=(long long)1E17;
//#define i_7 (long long)(1e9+7)
#define i_7 998'244'353
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
long long po(long a, long b){
    if(b==0){
        return 1;
    }
    
    long long z = po(a,b/2);
    z = mod(z*z);
    if(b%2!=0){
        z = mod(a*z);
    }
    return z;
}
using namespace std;
//using namespace boost::multiprecision;

bool prime_(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}

long long gcd_(long long a, long long b){
  if(a<b){
    swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd_(b,a%b);
  }
}
 
long long lcm_(long long x, long long y){
  return (x/gcd_(x,y))*y;
}



int main(){
  
  int x,y,z;
  cin>>x>>y>>z;
  int n = x + y + z;
  long long a[n],b[n],c[n];
  typedef P pair<long long, long long>;
  vector<pair<long long, P>> vec;
  REP(i,n){
    cin>>a[i]>>b[i]>>c[i];
    long long d = a[i] - b[i];
    long long ta = a[i] - c[i];
    long long tb = b[i] - c[i];
    vec.push_back(make_pair(d, P(ta,tb)));
  }
  
  
  
  
  return 0; 
}


Compiler output:
a.cc: In function 'int main()':
a.cc:73:11: error: 'P' does not name a type; did you mean 'PI'?
   73 |   typedef P pair<long long, long long>;
      |           ^
      |           PI
a.cc:74:26: error: 'P' was not declared in this scope
   74 |   vector<pair<long long, P>> vec;
      |                          ^
a.cc:74:26: error: template argument 2 is invalid
a.cc:74:27: error: template argument 1 is invalid
   74 |   vector<pair<long long, P>> vec;
      |                           ^~
a.cc:74:27: error: template argument 2 is invalid
a.cc:80:9: error: request for member 'push_back' in 'vec', which is of non-class type 'int'
   80 |     vec.push_back(make_pair(d, P(ta,tb)));
      |         ^~~~~~~~~
Language: C++

#include<bits/stdc++.h>
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define For(i,a,b) for(int i=a;i>=b;i--)
#define Maxn 100002
#define inf 100002
#define int long long

using namespace std;

int read(){
    char c=getchar(); int flag=1, x=0;
    while(!isdigit(c)){ if(c=='-') flag=-1; c=getchar(); }
    while( isdigit(c)){ x=x*10+(c-'0'); c=getchar(); }
    return flag*x;
}

int X,Y,Z;
int S,T;

struct FYL{
    struct LINE{
        int st,en,lim,val,pre;
    }line[Maxn*10+10];
    int head[Maxn+10], tot=1;
    void add(int a,int b,int z,int c){
        line[++tot]=(LINE){ a,b,z,c,head[a] }; head[a]=tot;
    }
    #define make_pair mp
    int visit[Maxn+10], dist[Maxn+10], last[Maxn+10], minflow[Maxn+10];
    priority_queue < pair<int,int> > Q;
    bool spfa(int S,int T){
        //cout<<" Do \n";
        //queue< int > Q;
        //priority_queue< pair<int,int> > Q;
        memset(visit,0,sizeof(visit));
        memset(dist,0,sizeof(dist));
        minflow[S]=inf;
        Q.push(mp(0,S)); dist[S]=0; visit[S]=0; last[S]=0;
        while(Q.size()){
            int now=Q.top().second; Q.pop();
            if(visit[now]) continue;
            visit[now]=1; 
            for(int i=head[now];i;i=line[i].pre){
                int E=line[i].en;
                if(!line[i].lim) continue;
                if(dist[now]+line[i].val>dist[E]){
                    dist[E]=dist[now]+line[i].val;
                    minflow[E]=min(minflow[now],line[i].lim);
                    last[E]=i;
                    Q.push(mk(dist[E],E));
                    //if(!visit[E]) Q.push(E), visit[E]=1;
                }
            }
        }
        if(dist[T]==dist[T+1]) return false;
        return true;
        //return dist[T];
    }
    int maxflow, ans;
    void update(int S,int T){
        int now=T;
        while(now!=S){
            int i=last[now];
            line[i].lim-=minflow[T];
            line[i^1].lim+=minflow[T];
            now=line[i].st;
        }
        maxflow+=minflow[T];
        ans+=dist[T]*minflow[T];
    }
}deal;

void init(){
    S=0, T=X+Y+Z+4;
    deal.add(0,1,X,0); deal.add(1,0,0,0);
    deal.add(0,2,Y,0); deal.add(2,0,0,0);
    deal.add(0,3,Z,0); deal.add(3,0,0,0);
    FOR(i,1,X+Y+Z){
        deal.add(i+3,T,1,0), deal.add(T,i+3,0,0);
    }
}

signed main(){

    X=read(), Y=read(), Z=read();
    init();

    FOR(i,1,X+Y+Z){
        int v1=read(), v2=read(), v3=read();
        deal.add(1,i+3,1,v1), deal.add(i+3,1,0,-v1);
        deal.add(2,i+3,1,v2), deal.add(i+3,2,0,-v2);
        deal.add(3,i+3,1,v3), deal.add(i+3,3,0,-v3);
    }
    while( deal.spfa(S,T) ) deal.update(S,T);

    cout<<-deal.ans<<endl;

    return 0;
}


Compiler output:
a.cc: In member function 'bool FYL::spfa(long long int, long long int)':
a.cc:38:16: error: 'mp' was not declared in this scope
   38 |         Q.push(mp(0,S)); dist[S]=0; visit[S]=0; last[S]=0;
      |                ^~
a.cc:50:28: error: 'mk' was not declared in this scope
   50 |                     Q.push(mk(dist[E],E));
      |                            ^~
Language: C++

#include<bits/stdc++.h>
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define For(i,a,b) for(int i=a;i>=b;i--)
#define Maxn 100002
#define inf 100002
#define int long long

using namespace std;

int read(){
    char c=getchar(); int flag=1, x=0;
    while(!isdigit(c)){ if(c=='-') flag=-1; c=getchar(); }
    while( isdigit(c)){ x=x*10+(c-'0'); c=getchar(); }
    return flag*x;
}

int X,Y,Z;
int S,T;

struct FYL{
    struct LINE{
        int st,en,lim,val,pre;
    }line[Maxn*10+10];
    int head[Maxn+10], tot=1;
    void add(int a,int b,int z,int c){
        line[++tot]=(LINE){ a,b,z,c,head[a] }; head[a]=tot;
    }
    #define make_pair mp
    int visit[Maxn+10], dist[Maxn+10], last[Maxn+10], minflow[Maxn+10];
    bool spfa(int S,int T){
        //cout<<" Do \n";
        //queue< int > Q;
        priority_queue< pair<int,int> > Q;
        memset(visit,0,sizeof(visit));
        memset(dist,0,sizeof(dist));
        minflow[S]=inf;
        Q.push(mp(0,S)); dist[S]=0; visit[S]=0; last[S]=0;
        while(Q.size()){
            int now=Q.top().second; Q.pop();
            if(visit[now]) continue;
            visit[now]=1; 
            for(int i=head[now];i;i=line[i].pre){
                int E=line[i].en;
                if(!line[i].lim) continue;
                if(dist[now]+line[i].val>dist[E]){
                    dist[E]=dist[now]+line[i].val;
                    minflow[E]=min(minflow[now],line[i].lim);
                    last[E]=i;
                    Q.push(mk(dist[E],E));
                    //if(!visit[E]) Q.push(E), visit[E]=1;
                }
            }
        }
        if(dist[T]==dist[T+1]) return false;
        return true;
        //return dist[T];
    }
    int maxflow, ans;
    void update(int S,int T){
        int now=T;
        while(now!=S){
            int i=last[now];
            line[i].lim-=minflow[T];
            line[i^1].lim+=minflow[T];
            now=line[i].st;
        }
        maxflow+=minflow[T];
        ans+=dist[T]*minflow[T];
    }
}deal;

void init(){
    S=0, T=X+Y+Z+4;
    deal.add(0,1,X,0); deal.add(1,0,0,0);
    deal.add(0,2,Y,0); deal.add(2,0,0,0);
    deal.add(0,3,Z,0); deal.add(3,0,0,0);
    FOR(i,1,X+Y+Z){
        deal.add(i+3,T,1,0), deal.add(T,i+3,0,0);
    }
}

signed main(){

    X=read(), Y=read(), Z=read();
    init();

    FOR(i,1,X+Y+Z){
        int v1=read(), v2=read(), v3=read();
        deal.add(1,i+3,1,v1), deal.add(i+3,1,0,-v1);
        deal.add(2,i+3,1,v2), deal.add(i+3,2,0,-v2);
        deal.add(3,i+3,1,v3), deal.add(i+3,3,0,-v3);
    }
    while( deal.spfa(S,T) ) deal.update(S,T);

    cout<<-deal.ans<<endl;

    return 0;
}


Compiler output:
a.cc: In member function 'bool FYL::spfa(long long int, long long int)':
a.cc:37:16: error: 'mp' was not declared in this scope
   37 |         Q.push(mp(0,S)); dist[S]=0; visit[S]=0; last[S]=0;
      |                ^~
a.cc:49:28: error: 'mk' was not declared in this scope
   49 |                     Q.push(mk(dist[E],E));
      |                            ^~
Language: C++

#include <iostream>
#include <vector>
#include <queue>
using namespace std;
struct P{
    int a, b, c;
    P(int x, int y, int z){
        a = x; b = y; c = z;
    }
    bool operator<(const P &x)const{
        return a-b < x.a-x. b;
    };
};
int main(void){
    int x, y, z;
    long long ans = 0, left[100000], right[100000];
    vector<P> v;
    priority_queue<int> q;
    cin >> x >> y >> z;
    for(int i=0;i<x+y+z;i++){
        int a, b, c;
        cin >> a >> b >> c;
        v.push_back(P(a, b, c));
    }
    sort(v.begin(), v.end());
    left[0] = 0;
    for(int i=0;i<y;i++){
        left[0] += v[i].b;
        q.push(v[i].c-v[i].b);
    }
    for(int i=1;i<=z;i++){
        int t = y-1+i;
        left[i] = left[i-1] + v[t].b;
        q.push(v[t].c - v[t].b);
        left[i] += q.top();
        q.pop();
    }
    while(!q.empty())q.pop();
    right[0] = 0;
    for(int i=y+z;i<x+y+z;i++){
        right[0] += v[i].a;
        q.push(v[i].c-v[i].a);
    }
    for(int i=1;i<=z;i++){
        int t = y+z-i;
        right[i] = right[i-1] + v[t].a;
        q.push(v[t].c - v[t].a);
        right[i] += q.top();
        q.pop();
    }
    for(int i=0;i<=z;i++){
        ans = max(ans, left[i] + right[z-i]);
    }
    cout << ans << endl;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:25:5: error: 'sort' was not declared in this scope; did you mean 'short'?
   25 |     sort(v.begin(), v.end());
      |     ^~~~
      |     short
Language: C++

from heapq import*
f=lambda*z:map(int,raw_input().split())
X,Y,Z=f()
P=[]
Q=[]
L=[0]
R=[0]
r=range(X+Y+Z)
A=sorted(map(f,r),key=lambda a:a[0]-a[1])
for i in r:L[i]-=i>Y and heappop(P);a=A[i];L+=[L[i]+a[1]];heappush(P,a[1]-a[2]);R[i]-=i>X and heappop(Q);a=A[~i];R+=[R[i]+a[0]];heappush(Q,a[0]-a[2])
#print max(L[i]+R[~i]for i in range(Y,Y+Z+1))
print max(Z<i-Y<0 or L[i]+R[~i]for i in r)

Compiler output:
a.cc:11:2: error: invalid preprocessing directive #print
   11 | #print max(L[i]+R[~i]for i in range(Y,Y+Z+1))
      |  ^~~~~
a.cc:1:1: error: 'from' does not name a type
    1 | from heapq import*
      | ^~~~
a.cc:10:37: error: 'a' does not name a type
   10 | for i in r:L[i]-=i>Y and heappop(P);a=A[i];L+=[L[i]+a[1]];heappush(P,a[1]-a[2]);R[i]-=i>X and heappop(Q);a=A[~i];R+=[R[i]+a[0]];heappush(Q,a[0]-a[2])
      |                                     ^
a.cc:10:44: error: 'L' does not name a type
   10 | for i in r:L[i]-=i>Y and heappop(P);a=A[i];L+=[L[i]+a[1]];heappush(P,a[1]-a[2]);R[i]-=i>X and heappop(Q);a=A[~i];R+=[R[i]+a[0]];heappush(Q,a[0]-a[2])
      |                                            ^
a.cc:10:67: error: expected constructor, destructor, or type conversion before '(' token
   10 | for i in r:L[i]-=i>Y and heappop(P);a=A[i];L+=[L[i]+a[1]];heappush(P,a[1]-a[2]);R[i]-=i>X and heappop(Q);a=A[~i];R+=[R[i]+a[0]];heappush(Q,a[0]-a[2])
      |                                                                   ^
a.cc:10:81: error: 'R' does not name a type
   10 | for i in r:L[i]-=i>Y and heappop(P);a=A[i];L+=[L[i]+a[1]];heappush(P,a[1]-a[2]);R[i]-=i>X and heappop(Q);a=A[~i];R+=[R[i]+a[0]];heappush(Q,a[0]-a[2])
      |                                                                                 ^
a.cc:10:106: error: 'a' does not name a type
   10 | for i in r:L[i]-=i>Y and heappop(P);a=A[i];L+=[L[i]+a[1]];heappush(P,a[1]-a[2]);R[i]-=i>X and heappop(Q);a=A[~i];R+=[R[i]+a[0]];heappush(Q,a[0]-a[2])
      |                                                                                                          ^
a.cc:10:114: error: 'R' does not name a type
   10 | for i in r:L[i]-=i>Y and heappop(P);a=A[i];L+=[L[i]+a[1]];heappush(P,a[1]-a[2]);R[i]-=i>X and heappop(Q);a=A[~i];R+=[R[i]+a[0]];heappush(Q,a[0]-a[2])
      |                                                                                                                  ^
a.cc:10:137: error: expected constructor, destructor, or type conversion before '(' token
   10 | for i in r:L[i]-=i>Y and heappop(P);a=A[i];L+=[L[i]+a[1]];heappush(P,a[1]-a[2]);R[i]-=i>X and heappop(Q);a=A[~i];R+=[R[i]+a[0]];heappush(Q,a[0]-a[2])
      |                                                                                                                                         ^
Language: C++

#include<cctype>
#include<cstring>
#include<algorithm>
#define int long long
using namespace std;
const int N=1e5+500,inf=0x7fffffff;

int gti(void)
{
    char c=getchar();
    int ret=0,st=1;
    for (;!isdigit(c);c=getchar()) if (c=='-') st=-1;
    for (;isdigit(c);c=getchar()) ret=ret*10+c-'0';
    return ret*st;
}

struct P
{
    int b,c;
    bool operator<(const P &y)const
    {
        return b>y.b||(b==y.b&&c>y.c);
    }
}p[N];

struct Treap
{
    struct T{int s[2],val,id,tot,sum;}t[N];
    int rt,cnt;
#define ls t[v].s[0]
#define rs t[v].s[1]
    void pu(int v)
    {
        t[v].tot=t[ls].tot+t[rs].tot+1;
        t[v].sum=t[v].val+t[ls].sum+t[rs].sum;
    }
    void split(int v,int k,int &x,int &y)
    {
        if (!v) return (void)(x=y=0);
        if (k<=t[ls].tot)
            split(ls,k,x,y),ls=y,y=v;
        else split(rs,k-t[ls].tot-1,x,y),rs=x,x=v;
        pu(v);
    }
    int merge(int a,int b)
    {
        if (!a||!b) return a|b;
        int v;
        if (t[a].id<t[b].id)
            v=a,rs=merge(rs,b);
        else v=b,ls=merge(a,ls);
        pu(v);
        return v;
    }
    int getrank(int v,int val)
    {
        if (!v) return 1;
        if (t[v].val<val)
            return t[ls].tot+1+getrank(rs,val);
        return getrank(ls,val);
    }
    void insert(int val)
    {
        int k=getrank(rt,val),x,y;
        split(rt,k-1,x,y);
        t[++cnt]=(T){{0,0},val,rand(),1,val};
        rt=merge(x,cnt);
        rt=merge(rt,y);
    }
    void clear(void)
    {
        rt=cnt=0;
    }
    int query(int k)
    {
        int x,y,ret;
        split(rt,t[rt].tot-k,x,y);
        ret=t[y].sum;
        rt=merge(x,y);
        return ret;
    }
}t;

int ans[N];
#undef int
int main(void)
#define int long long
{
    int x=gti(),y=gti(),z=gti(),sum=0,n=x+y+z;
    for (int i=1;i<=n;i++)
    {
        int a=gti();
        p[i].b=gti()-a,p[i].c=gti()-a;
        sum+=a;
    }
    sort(p+1,p+1+n);
    int sum2=0;
    for (int i=1;i<=n;i++)
    {
        sum2+=p[i].b,t.insert(p[i].c-p[i].b);
        if (i>=y)
            ans[i]=sum2+t.query(i-y);
    }
    t.clear();
    for (int i=n;i>=1;i--)
    {
        if (i<=y+z)
            ans[i]+=t.query(y+z-i);
        t.insert(p[i].c);
    }
    int mx=-inf;
    for (int i=y;i<=y+z;i++)
        mx=max(mx,ans[i]);
    printf("%lld\n",mx+sum);
    return 0;
}


Compiler output:
a.cc: In function 'long long int gti()':
a.cc:10:12: error: 'getchar' was not declared in this scope
   10 |     char c=getchar();
      |            ^~~~~~~
a.cc:4:1: note: 'getchar' is defined in header '<cstdio>'; this is probably fixable by adding '#include <cstdio>'
    3 | #include<algorithm>
  +++ |+#include <cstdio>
    4 | #define int long long
a.cc: In function 'int main()':
a.cc:114:5: error: 'printf' was not declared in this scope
  114 |     printf("%lld\n",mx+sum);
      |     ^~~~~~
a.cc:114:5: note: 'printf' is defined in header '<cstdio>'; this is probably fixable by adding '#include <cstdio>'
Language: C++

#include<cstdio>
#include<iostream>
#include<stdlib.h>
#include<algorithm>
#include<queue>
#include<string.h>
#include<vector>
using namespace std;
namespace io {
	const int SIZE = (1 << 21) + 1;
	char ibuf[SIZE], *iS, *iT, obuf[SIZE], *oS = obuf, *oT = oS + SIZE - 1, c, qu[55]; int f, qr;
	// getchar
	#define gc() (iS == iT ? (iT = (iS = ibuf) + fread (ibuf, 1, SIZE, stdin), (iS == iT ? EOF : *iS ++)) : *iS ++)
	// print the remaining part
	inline void flush () {
		fwrite (obuf, 1, oS - obuf, stdout);
		oS = obuf;
	}
	// putchar
	inline void putc (char x) {
		*oS ++ = x;
		if (oS == oT) flush ();
	}
	// input a signed integer
	template <class I>
	inline void read (I &x) {
		for (f = 1, c = gc(); c < '0' || c > '9'; c = gc()) if (c == '-') f = -1;
		for (x = 0; c <= '9' && c >= '0'; c = gc()) x = x * 10 + (c & 15); x *= f;
	}
	// print a signed integer
	template <class I>
	inline void print (I x) {
		if (!x) putc ('0'); if (x < 0) putc ('-'), x = -x;
		while (x) qu[++ qr] = x % 10 + '0',  x /= 10;
		while (qr) putc (qu[qr --]);
	}
	//no need to call flush at the end manually!
	struct Flusher_ {~Flusher_(){flush();}}io_flusher_;
}
using io :: read;
using io :: putc;
using io :: print;

typedef long long LL;
const int MaxN = 1e5;
 
struct node{
	LL a, b, c;
	bool operator <(const node &A) const{
		return (a-b) < A.a - A.b;
	}
}a[100005];
 
int n, x, y, z;
LL tot, ans;
priority_queue<LL, vector<LL>, greater<LL> > q;
LL lef[MaxN + 5];
 
int main(){
	int i,j,k;
	read(x),read(y),read(z);
	n=x+y+z;
	for(i = 1; i <= n; i++){
		read(a[i].a),read(a[i].b),read(a[i].c);
		tot += a[i].c;
	}
	sort(a + 1, a + 1 + n);
	LL ans = 0, sum = 0;
	for(i = 1; i <= y; i++){
		sum += a[i].b - a[i].c;
		q.push(a[i].b - a[i].c);
	}
	for(i = y + 1; i <= n - x + 1; i++){
		lef[i] = sum;
		sum += a[i].b - a[i].c;
		q.push(a[i].b - a[i].c);
		sum -= q.top();
		q.pop();
	}
	while(!q.empty()) q.pop(); sum = 0;
	for(i = n; i > n - x; i--){
		sum += a[i].a - a[i].c;
		q.push(a[i].a - a[i].c);
	}
	for(i=n-x;i>=y;i--)
	{
		ans=max(ans,tot+lef[i+1],sum);
		sum+=a[i].a-a[i].c;
		q.push(a[i].a-a[i].c);
		sum-=q.top();
		q.pop();
	}
	print(ans),putc('\n');
	return 0;
}


Compiler output:
In file included from /usr/include/c++/14/string:51,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:2:
/usr/include/c++/14/bits/stl_algobase.h: In instantiation of 'constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare) [with _Tp = long long int; _Compare = long long int]':
a.cc:87:10:   required from here
   87 |                 ans=max(ans,tot+lef[i+1],sum);
      |                     ~~~^~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:306:17: error: '__comp' cannot be used as a function
  306 |       if (__comp(__a, __b))
      |           ~~~~~~^~~~~~~~~~
Language: C++

6 2 4
33189 87907 277349742
71616 46764 575306520
8801 53151 327161251
58589 4337 796697686
66854 17565 289910583
50598 35195 478112689
13919 88414 103962455
7953 69657 699253752
44255 98144 468443709
2332 42580 752437097
39752 19060 845062869
60126 74101 382963164

Compiler output:
a.cc:1:1: error: expected unqualified-id before numeric constant
    1 | 6 2 4
      | ^
Language: C++

#include <ctime>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <map>
using namespace std;

typedef long long ll;
typedef double lf;
typedef long double Lf;
typedef pair <int,int> pii;
typedef pair <ll, ll> pll;

#define TRACE(x) cerr << #x << "  " << x << endl
#define FOR(i, a, b) for (int i = (a); i < int(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define _ << " " <<

#define fi first
#define sec second
#define mp make_pair

const int MAXN = 100100;
const ll INF = 1e18;
const lf EPS = 1e-8;

inline bool lt(const lf &a, const lf &b) {return a + EPS < b;}
inline bool eq(const lf &a, const lf &b) {return max(a - b, b - a) < EPS;}

int X, Y, Z;
ll a[MAXN], b[MAXN], c[MAXN];
int n;

ll dp[MAXN];

inline void update(int i, int i1, ll t) {
		if (dp[i1] < t) dp[i1] = t;
}

int retA, retB;

pair <ll, int> checkA(lf x, ll y) {
	REP(i, n + 1) dp[i] = -INF;
	dp[0] = 0;
	REP(i, n) {
		update(i, i + 1, dp[i] + c[i]);
		update(i, i + 1, dp[i] + a[i] + y);
		update(i, i + 1, dp[i] + b[i] + x);
	}

	retA = retB = 0;
	for (int i = n; i; i--) {
		if (dp[i] == dp[i - 1] + c[i - 1]) continue;
		if (dp[i - 1] + a[i - 1] + y == dp[i]) retA++;
		else retB++;
	}

	return mp(dp[n], retA);
}

pair <ll, int> checkB(lf x) {
	ll lo = -(1LL << 25), hi = (1LL << 25), mid;
	REP(i, 40) {
		mid = (lo + hi) / 2;
		pair <ll, int> t = checkA(x, mid);
		if (t.sec == X) {
			lo = mid;
			break;
		}
		if (t.sec < X) lo = mid;
		else hi = mid;
	}

	ll Ret = checkA(x, lo).fi - lo * X;
	return mp(Ret, retB);
}

int main() {
	scanf("%d %d %d",&X,&Y,&Z);
	n = X + Y + Z;
	REP(i, n) scanf("%lld %lld %lld",&a[i],&b[i],&c[i]);

	ll lo = -(1LL << 25), hi = (1LL << 25), mid;

	REP(i, 40) {
		mid = (lo + hi) / 2;
		pair <ll, int> t = checkB(mid);
		if (t.sec < Y) lo = mid;
		if (t.sec == Y) {
			lo = mid;
			break;
		}
		if (t.sec > Y) hi = mid;
	}

	pair <ll, int> t = checkB(lo);
	printf("%lld\n",t.fi - i * Y);
	return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:106:32: error: 'i' was not declared in this scope
  106 |         printf("%lld\n",t.fi - i * Y);
      |                                ^
Language: C++

#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
typedef long long LL;
int X,Y,Z;
LL A[100001];
LL B[100001];
LL C[100001];
bool used[100001];
typedef pair<LL,LL> P;
vector<P>v;
vector<P>v2;
vector<LL>v3;

LL ans=0;
int main(){
   cin>>X>>Y>>Z;
   REP(i,X+Y+Z){
       cin>>A[i]>>B[i]>>C[i];
       ans+=C[i];
       A[i]-=C[i];
       B[i]-=C[i];
       v.push_back(P(A[i],i));
       v2.push_back(P(B[i],i));
   }
   sort(v.begin(),v.end(),greater<P>());
   sort(v2.begin(),v2.end(),greater<P>());
   REP(i,100001){
       used[i]=false;
   }
   REP(i,X){
       used[v[i].second]=true;
   }
   int c=0;
   REP(i,Y){
       if(used[v2[i].second]==false){
          ans+=v2[i].first;
          c++;
       }else{
          int num=v2[i].second;
          used[num]=false;
          ans+=v2[i].first;
          v3.push_back(A[num]-B[num]);
       }
   }
   Y-=c;
   c=0;
   REP(i,X){
       if(used[v[i].second]==true){
          ans+=v[i].first;
          c++;
       }
   }
   X-=c;
   sort(v3.begin(),v3.end()greater<LL>());
   REP(i,v3.size()){
       if(i<X){
          ans+=v3[i];
       }else{
       }
   }
   cout<<ans<<endl;
   return(0);
}

Compiler output:
a.cc: In function 'int main()':
a.cc:58:28: error: expected ')' before 'greater'
   58 |    sort(v3.begin(),v3.end()greater<LL>());
      |        ~                   ^~~~~~~
      |                            )
Language: C++

//#include<bits/stdc++.h>
#include<iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <queue>
#include <deque>
#include <map>
#include <stack>
#include<bitset>
#include<list>
#include<cassert>
#include<numeric>

using namespace std;

const long long N = 1e5 + 5;

long long mini = 1e9 + 7;
long long dp[N];
long long dp2[N];
bool mark[N];
bool check = false;
vector<pair<long long, long long>> graph[N];
vector<edge > vec;
long long n, m;
long long ans;

void dfs(long long v)
{
	mark[v] = true;
	dp[v] = 1;
	for (long long i = 0; i < graph[v].size(); i++)
	{
		long long u = graph[v][i].first;
		if (!mark[u])
		{
			dfs(u);
			dp[v] += dp[u];
		}
	}
}

void dfs2(long long v)
{
	mark[v] = true;
	for (long long i = 0; i < graph[v].size(); i++)
	{
		long long u = graph[v][i].first;
		long long w = graph[v][i].second;
		if (!mark[u])
		{
			long long cnt1 = dp[u];
			long long cnt2 = n - dp[u];
			if (cnt1 == cnt2)
			{
				check = true;
				cnt1 = 2 * cnt1 - 1;
			}
			else
			{
				cnt1 = 2 * min(cnt1, cnt2);
			}
			ans += cnt1 * w;
			dfs2(u);
		}
	}
}


int main() 
{
	cin >> n;
	for (long long i = 0; i < n - 1; i++)
	{
		long long u, v, w;
		cin >> u >> v >> w;
		graph[u - 1].push_back({v - 1, w});
		graph[v - 1].push_back({u - 1, w});
		mini = min(mini, w);
	}
	dfs(0);
	memset(mark, 0, sizeof mark);
	dfs2(0);
	if (!check)
	{
		ans -= mini;
	}
	cout << ans << endl;


	
}





Compiler output:
a.cc:26:8: error: 'edge' was not declared in this scope
   26 | vector<edge > vec;
      |        ^~~~
a.cc:26:13: error: template argument 1 is invalid
   26 | vector<edge > vec;
      |             ^
a.cc:26:13: error: template argument 2 is invalid
a.cc: In function 'int main()':
a.cc:84:9: error: 'memset' was not declared in this scope
   84 |         memset(mark, 0, sizeof mark);
      |         ^~~~~~
a.cc:15:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
   14 | #include<numeric>
  +++ |+#include <cstring>
   15 |
Language: C++

#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
const int MAX=2e7;
const ll MOD=1e9+7;
const int INF=1<<30;

ll gcd(ll a,ll b){
  if(a%b==0)
    return b;
  return gcd(b,a%b);
}

int main(){
  int N,K;
  cin >> N >> K;
  vector<int> A(N);
  rep(i,N){
    cin >> A[i];
  }
  int maxA=0;
  int GCD=A[0];
  rep(i,N){
    if(A[i]>maxA) maxA=A[i];
    GCD=gcd(GCD,A[i]);
  }
  if(maxA=>K&&(maxA-K)%GCD==0) cout << "POSSIBLE" << endl;
  else cout << "IMPOSSIBLE" << endl;
}



Compiler output:
a.cc: In function 'int main()':
a.cc:31:11: error: expected primary-expression before '>' token
   31 |   if(maxA=>K&&(maxA-K)%GCD==0) cout << "POSSIBLE" << endl;
      |           ^
Language: C++

#include <bits/stdc++.h>
using namespace std;
#define maxn 100020
int n,head[maxn],tot = 0,sze[maxn],max_sze[maxn],mind,root;
long long ans = 0;
struct edge {
	int v,nxt,w;
}e[maxn<<1];
inline void add_(int u,int v,int w) {
	e[++tot].v = v;
	e[tot].w = w;
	e[tot].nxt = head[u];
	head[u] = tot;
}

void dfs_(int u,int fa)  {
	sze[u] = 1;
	for(int i = head[u];~i;i = e[i].nxt)  {
		int v = e[i].v;
		if( v == fa ) continue;
		dfs_(v,u);
		sze[u] += sze[v];
		max_sze[u] = max( max_sze[u],sze[v] );
		ans += (long long) 2 * e[i].w * min( sze[v],n - sze[v] );
	}
	max_sze[u] = max( max_sze[u],n - sze[u] );
	if( max_sze[u] < mind ) {
		mind = max_sze[u];
		root = u;
	}
}

int main() {
//	memset(head,-1,sizeof(head));
	n = read_();int x,y,z;
	for(int i = 1;i < n;++i) {
		x = read_();y = read_();z = read_();
		add_(x,y,z);add_(y,x,z);
	}
	mind = n + 1;
	dfs_(1,0);
	mind = 200000000;
	for(int i = head[root];~i;i = e[i].nxt) {
		int v = e[i].v;
		if( max_sze[root] == max_sze[v] ) {ans -= e[i].w;printf("%lld",ans);return 0;}
		mind = min( mind,e[i].w );
	}	
	printf("%lld",ans-mind);
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:35:13: error: 'read_' was not declared in this scope; did you mean 'read'?
   35 |         n = read_();int x,y,z;
      |             ^~~~~
      |             read
Language: C++

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

const int MAXN = 1e5 + 10;
vector<pair<int, int> > Mat[MAXN];
long long ans, val[MAXN];
int a[MAXN], b[MAXN], n;
int dfs(int v, int p, int w) {
	int cnt = 1;
	for (int i = 0; i < Mat[v].size(); i++) {
		int u = Mat[v][i].first, o = Mat[v][i].second;
		if (u != p)
			cnt += dfs(u, v, o);
	}
	ans += min(cnt, n - cnt) * 2 * w;
	if (cnt == n - cnt)
		val[1] += w;
	else if (cnt < n - cnt)
		val[v] += w;
	else
		val[1] += w, val[v] -= w;
	return cnt;
}
void dfso(int v, int p, long long tmp) {
	val[v] += tmp;
	for (int i = 0; i < Mat[v].size(); i++) {
		int u = Mat[v][i].first, o = Mat[v][i].second;
		if (u != p)
			dfso(u, v, val[v]);
	}
}

int main() {
	cin >> n;
	for (int i = 0; i < n - 1; i++) {
		int a, b, w;
		cin >> a >> b >> w;
		Mat[a].push_back({ b, w });
		Mat[b].push_back({ a, w });
	}
	dfs(1, 1, 0);
	dfso(1, 1, 0);
	long long mn[2] = { 1e9, 1e9 };
	for (int i = 1; i <= n; i++) {
		mn[1] = min(mn[1], val[i]);
		if (mn[1] < mn[0])
			swap(mn[1], mn[0]);
	}
	cout << ans - mn[0] - mn[1];
}

Compiler output:
a.cc: In function 'int main()':
a.cc:45:29: error: narrowing conversion of '1.0e+9' from 'double' to 'long long int' [-Wnarrowing]
   45 |         long long mn[2] = { 1e9, 1e9 };
      |                             ^~~
a.cc:45:34: error: narrowing conversion of '1.0e+9' from 'double' to 'long long int' [-Wnarrowing]
   45 |         long long mn[2] = { 1e9, 1e9 };
      |                                  ^~~
Language: C++

#include<bits\stdc++.h>
#define inf 0x7f7f7f7f
using namespace std;
typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
inline char gc()
{
  static char buf[1000000],*p1=buf,*p2=buf;
  return p1==p2&&(p2=(p1=buf)+fread(buf,1,1000000,stdin),p1==p2)?EOF:*p1++;
}
inline int frd()
{
  int x=0,f=1;char ch=gc();
  for(;ch<'0'||ch>'9';ch=gc())  if (ch=='-')  f=-1;
  for(;ch>='0'&&ch<='9';ch=gc())  x=(x<<1)+(x<<3)+ch-'0';
  return x*f;
}
inline int read()
{
  int x=0,f=1;char ch=getchar();
  for(;ch<'0'||ch>'9';ch=getchar())  if (ch=='-')  f=-1;
  for(;ch>='0'&&ch<='9';ch=getchar())  x=(x<<1)+(x<<3)+ch-'0';
  return x*f;
}
inline void print(int x)
{
  if(x<0)  putchar('-'),x=-x;
  if(x>9)  print(x/10);
  putchar(x%10+'0');
}
const int N=2e5;
int n,tot,rize,root;
int pre[(N<<1)+10],now[N+10],child[(N<<1)+10],val[(N<<1)+10],size[N+10],Msize[N+10];
ll Ans;
void join(int x,int y,int z){pre[++tot]=now[x],now[x]=tot,child[tot]=y,val[tot]=z;}
void insert(int x,int y,int z){join(x,y,z),join(y,x,z);}
void dfs(int x,int fa,int v)
{
  int Max=0;size[x]=1;
  for(int p=now[x],son=child[p];p;p=pre[p],son=child[p])
  {
    if(son==fa)  continue;
    dfs(son,x,val[p]),size[x]+=size[son];
    Max=max(Max,size[son]);
  }
  Ans+=1ll*min(size[x],n-size[x])*v*2;
  Max=max(Max,n-size[x]);Msize[x]=Max;
  if(Max<rize)  {rize=Max;root=x;}
}
int main()
{	
  n=read(),rize=inf;
  for(int i=1;i<n;i++)
  {
    int x=read(),y=read(),z=read();
    insert(x,y,z);
  }
  dfs(1,0,0);
  int tmp=inf;
  for(int p=now[root],son=child[p];p;p=pre[p],son=child[p])
  {
    tmp=min(tmp,val[p]);
    if(Msize[root]==Msize[son])
	{
      Ans-=val[p];
      printf("%lld\n",Ans);
      return 0;
    }
  }
  printf("%lld\n",Ans-tmp);
  return 0;
}

Compiler output:
a.cc:1:9: fatal error: bits\stdc++.h: No such file or directory
    1 | #include<bits\stdc++.h>
      |         ^~~~~~~~~~~~~~~
compilation terminated.
Language: C++

#include<bits/stdc++.h>
#define int long long
#define rint register int
using namespace std;

template<typename tp> inline void read(tp &x) {
  x = 0; char c = getchar(); int f = 0;
  for (; c < '0' || c > '9'; f |= c == '-', c = getchar());
  for (; c >= '0' && c <= '9'; x = (x << 3) + (x << 1) + c - '0', c = getchar());
  if (f) x = -x;
}
const int N = 3e5 + 2333;
const int M = N * 2;
struct Edge {
  int nxt, to, w;
}e[M];
int head[N], e_cnt = 0;
int n, m, ans = 0, mn = 1e18;
int sz[N], dp[N], f[N], isheart[N];
inline void add(int x, int y, int w) {
  e[++ e_cnt] = (Edge) {head[x], y, w}; head[x] = e_cnt;
}

inline void upd(int u, int v, int w) {
  sz[u] += sz[v];
  dp[u] += min(sz[v], n - sz[v]) * w + dp[v];
}

inline void del(int u, int v, int w) {
  sz[u] -= sz[v];
  dp[u] -= min(sz[v], n - sz[v]) * w + dp[v];
}

inline void dfs(int u, int fat) {
  sz[u] = 1; f[u] = 0;
  for (int i = head[u]; i; i = e[i].nxt) {
    int v = e[i].to;
    int w = e[i].w;
    if (v != fat) {
      dfs(v, u);
      upd(u, v, w);
      f[u] = max(f[u], sz[v]);
    }
  }
  f[u] = max(f[u], n - sz[u]);
  if (f[u] * 2 <= n)
    ishear[u] = true;
}

inline void gao(int u, int v, int w) {
  int res = dp[u] + dp[v];
  res += min(sz[u], sz[v]) * w;
  // cout << u << " " << v << " " << dp[u] << " " << dp[v] << " " << res << "\n";
  if (abs(sz[u] - sz[v]) <= 1 || isheart[u])
    ans = max(ans, res * 2 - (sz[u] == sz[v] ? w : mn));
}

inline void fsd(int u, int fat) {
  for (int i = head[u]; i; i = e[i].nxt) {
    int v = e[i].to;
    int w = e[i].w;
    if (v != fat) {
      del(u, v, w); gao(u, v, w); upd(v, u, w);
      fsd(v, u);
      del(v, u, w); upd(u, v, w);
    }
  }
}

main(void) {
  read(n);
  for (int i = 2; i <= n; i ++) {
    int x, y, w; read(x); read(y); read(w);
    add(x, y, w); add(y, x, w); mn = min(mn, w);
  }
  dfs(2, 0); fsd(2, 0);
  cout << ans << "\n";
}


Compiler output:
a.cc: In function 'void dfs(long long int, long long int)':
a.cc:47:5: error: 'ishear' was not declared in this scope; did you mean 'isheart'?
   47 |     ishear[u] = true;
      |     ^~~~~~
      |     isheart
a.cc: At global scope:
a.cc:70:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   70 | main(void) {
      | ^~~~
Language: C++

#include <bits/stdc++.h>

#define pb push_back
#define all(v) v.begin(), v.end()
#define sz(v) int(v.size())
#define pii pair<int, int>
#define mp make_pair
#define f first
#define ll long long
#define s second
#define vec vector<int>

using namespace std;

const int N = (int) 5e5 + 10;
const int M = (int) 1e6 + 10;
const int K = (int) 500 + 10;
const int mod = (int) 1e9 + 7;
const ll LINF = (ll) 1e18;

int n;
vec v[N];
map<pii, int> e;
int sz[N];

void calc_sizes(int x = 1, int p = -1) {
	sz[x] = 1;
	for (auto it : v[x]) {
		if (it == p)
			continue;
		calc_sizes(it, x);
		sz[x] += sz[it];
	}
}

int main() {
	#ifdef sony
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif
	srand(time(0));
	cin >> n;
	for (int i = 1, x, y, c; i < n; i++) {
		cin >> x >> y >> c;
		v[x].pb(y);
		v[y].pb(x);
		e[mp(x, y)] = e[mp(y, x)] = c;
	}
	calc_sizes();
	ll ans = 0;
	for (auto it : e) {
		//it.f.f, it.f.s, it.s
		//cout << sz[it.f.f] << ' ' << (n - sz[it.f.f]) << ' ' << it.s << "\n";
		int x = it.f.f, y = it.f.s;
		if (sz[x] < sz[y])
			swap(x, y); 
		//cout << x << ' ' << y << ' ' << sz[y] << '\n';
		ans += 1ll * min(sz[y], (n - sz[y])) * it.s;
	}
	vec centroids;
	for (int i = 1; i <= n; i++) {
		bool centroid = true;
		for (auto it : v[i]) {
			if (sz[it] < sz[i] && sz[it] > n / 2)
				centroid = false;
		}
		if (centroid && n - sz[i] <= n / 2) {
			centroids.pb(i);
		}
	}
	for (auto it : centroids) {
	//	cout << it << ' ';
	//} cout << '\n';
	if (sz(centroids) == 1) {
		int cmin = mod;
		for (auto it : e) {
			if (it.f.f == centroids[0]) {
				cmin = min(cmin, it.s);
			}
		}
		ans -= cmin;
	} else {
		assert(sz(centroids) == 2);
		ans -= e[mp(centroids[0], centroids[1])];
	}
	cout << ans;
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:88:2: error: expected '}' at end of input
   88 | }
      |  ^
a.cc:36:12: note: to match this '{'
   36 | int main() {
      |            ^
Language: Java

import java.util.*;
import java.lang.*;

public class Main{
    static int [] head;
    static int [] next;
    static int [] to;
    static long [] cost;
    static int [] size;
    static int edgeCount = 0;
    static long ans = 0;
    static int N;

    public static void main(String [] args) {
        Scanner sc = new Scanner(new BufferedInputStream(System.in));
        N = sc.nextInt();
        head = new int  [N + 1];
        size = new int  [N + 1];
        next = new int  [N + N + 1];
        to   = new int  [N + N + 1];
        cost = new long [N + N + 1];
        for(int i = 0; i < N - 1; i++) {
            int A = sc.nextInt();
            int B = sc.nextInt();
            int C = sc.nextInt();
            addEdge(A,B,C);
            addEdge(B,A,C);
        }
        calcSize(1);
        dfs(1);
        System.out.println(ans);
    }

    public static void dfs(int root) {
        int maxNodeSize = N - size[root];
        long minEdgeCost = Long.MAX_VALUE;

        for(int e = head[root]; e != 0; e = next[e]) {
            int destination = to[e];
            minEdgeCost = Math.min(minEdgeCost,cost[e]);

            if(size[destination] < size[root]) {
                maxNodeSize = Math.max(maxNodeSize,size[destination]);

                long min = Math.min(size[destination], N - size[destination]);
                ans = ans + min * cost[e] * 2;
                dfs(destination);

                if(min + min == N) {
                    ans = ans - cost[e];
                }
            }
        }

        if(maxNodeSize * 2 < N) {
            ans = ans - minEdgeCost;
        }
    }

    public static int calcSize(int root) {
        size[root] = 1;
        for(int e = head[root]; e != 0; e = next[e]) {
            if(size[to[e]] == 0) {
                size[root] += calcSize(to[e]);
            }
        }
        return size[root];
    }

    public static void addEdge(int A, int B, int C) {
        edgeCount += 1;
        to[edgeCount] = B;
        cost[edgeCount] = C;
        next[edgeCount] = head[A];
        head[A] = edgeCount;
    }
}


Compiler output:
Main.java:15: error: cannot find symbol
        Scanner sc = new Scanner(new BufferedInputStream(System.in));
                                     ^
  symbol:   class BufferedInputStream
  location: class Main
1 error
Language: C++

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<int,int> PP;

/*
    freopen("input","r",stdin);
    freopen("output","w",stdout);
*/

vector<vector<int> > G;
unordered_map<ll, ll> C;

unordered_map<ll, int> D;
unordered_map<ll, ll> E;

ll mp(int a, int b) {
	return a * (1LL << 30) + b;
}

void cal(int a, int b) {
	// Calculate following contents:
	// (1) Number of child in subtree root as a, without branch b.
	// (2) Sum of path sum till subtree a.
	if (D.count(mp(a, b))) return;
	int child = 1;
	ll sum = 0;
	for (int n = 0;n < G[a].size();n++) {
		int m = G[a][n];
		if (m == b) continue;
		cal(m, a);
		child += D[mp(m, a)];
		sum += E[mp(m, a)];
	}
	sum += C[mp(a, b)] * 2 * child;
	E[mp(a, b)] = sum;
	D[mp(a, b)] = child;
	return;
}

int main() {
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    G.resize(N);
    for (int i = 1;i < N;i++) {
    	int a, b, c;
    	cin >> a >> b >> c;
    	a--;
    	b--;
    	G[a].push_back(b);
    	G[b].push_back(a);
    	C[mp(a, b)] = c;
    	C[mp(b, a)] = c;
    }
    for (int i = 0;i < N;i++) {
    	for (int j = 0;j < G[i].size();j++) {
    		cal(i, G[i][j]);
    	}
    }
    cout << 0 << endl;
    return;
    ll ans = 0;
    for (int i = 0;i < N;i++) {
    	// Try use i as root.
    	int ma = 0;
    	int idx = 0;
    	ll sol = 0;
    	bool ok = 1;
    	for (int j = 0;j < G[i].size() && ok;j++) {
    		ll k = mp(G[i][j], i);
    		if (D[k] > ma) {
	    		ma = max(ma, D[k]); // Maximum branch.
	    		if (ma > N - 1 - ma + 1) ok = 0;
	    		idx = G[i][j];
	    	}
    		sol += E[k];
    	}
    	if (ok == 0) continue;
    	int rem = N - 1 - ma;
    	if (ma > rem + 1) continue; // Could not pair.
    	if (ma == rem + 1) {
    		sol -= C[mp(i, idx)];
    	}
    	else {
    		// Remove one branch.
    		ll mi = 1E9;
    		for (int j = 0;j < G[i].size();j++) {
    			mi = min(mi, C[mp(i, G[i][j])]);
    		}
    		sol -= mi;
    	}
    	ans = max(ans, sol);
    }
    cout << ans << endl;
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:84:5: error: return-statement with no value, in function returning 'int' [-fpermissive]
   84 |     return;
      |     ^~~~~~