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

#include <bits/stdc++.h>

using namespace std;

#define int long long
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define fr(i,j,k) for(i = j; i < (k); i++)
#define all(x) x.begin(), x.end()
#define el '\n'
#define remax(a,b) a = max(a, b)
#define remin(a,b) a = min(a, b)
#define sz(x) int32_t(x.size())

typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpi;
// --------------------------------------------------------------------

const pii dxy[] = { {-1, 0}, {1, 0}, {0, 1}, {0, -1} };
const int mod = 1e9 + 7;
const int inf = 2e18;
const ld eps = 1e-9;
const int NN = 2003;


string to_string(string s) {
      return '"' + s + '"';
}
string to_string(const char* s) {
      return to_string((string) s);
}
string to_string(bool b) {
      return (b ? "true" : "false");
}
template <typename A, typename B>
string to_string(pair<A, B> p) {
      return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
      bool first = true;  string res = "{";
      for (const auto &x : v) {
            if (!first) { res += ", "; }
            first = false; res += to_string(x);
      }
      res += "}";	  return res;
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
      cerr << " " << to_string(H);
      debug_out(T...);
}

// #define TRACE

#ifdef TRACE
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

vpi a;

int dp[NN][NN];

int recur(int i, int j) {
      int left = j - i + 1;
      debug(i, j, left);
      if(left == 0) {
            return 0;
      }

      if(dp[i][j] != -1)
            return dp[i][j];
      int idx = a[left - 1].se;
      int v1 = abs(j - idx) * a[left-1].fi + recur(i, j - 1);
      int v2 = abs(idx - i) * a[left-1].fi + recur(i + 1, j);
      debug(i, j, v1, v2);
      return dp[i][j] = max(v1, v2);     
}


void solve() {
      int i = 0, j = 0, k = 0, n = 0, m = 0;
      cin >> n;
      // vpi a(n);
      a.resize(n);
      fr(i, 0, n) {
            cin >> a[i].fi;
            a[i].se = i;
      } 
      memset(dp, -1, sizeof(dp));

      sort(all(a), [](pii &a, pii &b) {
            if (a.fi == b.fi) return a.se < b.se;
            return a.fi < b.fi;
      });
      debug(a);
      cout << recur(0, n - 1) << el; 

}

int32_t main() {
      ios::sync_with_stdio(false); cin.tie(0); 
      int T = 1; 
      // cin >> T;
      for(int tc = 1; tc <= T; tc++) {
            solve();
       }

      return 0;
}

Compiler output:
main.c:1:10: fatal error: bits/stdc++.h: No such file or directory
    1 | #include <bits/stdc++.h>
      |          ^~~~~~~~~~~~~~~
compilation terminated.
Language: C

#include<bits/stdc++.h>
using namespace std;
struct abcd{long long i,v;}al[2001],ar[2001];
bool cmp(abcd i,abcd j){return i.v>j.v;}
long long n,a[2001],ans,l,r,ansm;
int main()
{
	scanf("%lld",&n);
	l=1,r=n;
	for(int i=1;i<=n;i++)scanf("%lld",&a[i]),al[i].v=a[i],al[i].i=i;
	for(int mid=0;mid<=n;mid++)
	{
		ans=0;
		sort(al+1,al+mid+1,cmp);
		for(int i=mid+1;i<=n;i++)ar[i-mid].v=a[i],ar[i-mid].i=i;
		sort(ar+1,ar+n-mid+1,cmp);
		for(int i=1;i<=mid;i++)ans+=abs(n-i+1-al[i].i)*al[i].v;
		for(int i=1;i<=n-mid;i++)ans+=abs(i-ar[i].i)*ar[i].v;
		ansm=max(ans,ansm);
	}
	printf("%lld",ansm);
	return 0;
}

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

#include<stdio.h>

int main()

{

int A[1000000000],N,n, i, sum=0;

scanf("%d",&N);

if(N>=2&&N<=2000)

{

for(i=1;i<=N;i++)

  {

  scanf("%d", &A[i]) ;

  }

  n=1;

for(i=1;i<=N;i++) 

{

if(n>=A[i])

  sum=sum+n*(A[i]-n) ;

  n++;

else

  sum=sum+n*(n-A[i]) ;

  n++;

}

printf("%d",sum);

}

}



Compiler output:
main.c: In function 'main':
main.c:35:1: error: 'else' without a previous 'if'
   35 | else
      | ^~~~
Language: C

#include <bits/stdc++.h>
using namespace std;
 
 
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
 
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
 
#define rep(i, n)    for(int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(int i = a; i <= (n); ++i)
#define repD(i, a, n)  for(int i = a; i >= (n); --i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define fill(a)  memset(a, 0, sizeof (a))
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
typedef long double ld;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

void pre(){


}
 
void solve(){
 
 
}

ll dp[2009][2009];
int main() {
	cin.sync_with_stdio(0); cin.tie(0);
	cin.exceptions(cin.failbit);
	pre();

    vector<pair<ll, ll>> a;
    int n;cin>>n;
    a.resize(n,{0,0});
    rep(i,n)cin>>a[i].fst,a[i].fst*=-1,a[i].snd=i;
    sort(all(a));
    repA(s,1,n)repA(l,0,n-s){
        int r=l+s;
        dp[l][r]=max(dp[l][r], a[n-s].fst*-1ll*abs(a[n-s].snd-l)+dp[l+1][r]);
        dp[l][r]=max(dp[l][r], a[n-s].fst*-1ll*abs(a[n-s].snd-r+1)+dp[l][r-1]);
    }
    cout<<dp[0][n];



	return 0;
}
 



Compiler output:
main.c:1:10: fatal error: bits/stdc++.h: No such file or directory
    1 | #include <bits/stdc++.h>
      |          ^~~~~~~~~~~~~~~
compilation terminated.
Language: C

#include <bits/stdc++.h>
#define rep(i,n) for(ll i = 0; i < (n); ++i)
#define srep(i,s,t) for (ll i = s; i < t; ++i)
#define drep(i,n) for(ll i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005

int main() {
    int n;
    cin >> n;
    ll a[n];
    rep(i,n)cin >> a[i];
    ll f[n] = {};
    int flag[n] = {};
    rep(i,n){
        int ma = 0;
        int arg = -1;
        rep(j,n){
            if(flag[j] == 1)continue;
            if(ma < a[j]){
                ma = a[j];
                arg = j;
            }
        }
        f[i] = arg;
        flag[arg] = 1;
    }

    ll dp[n][n+1];
    rep(i,n)rep(j,n+1)dp[i][j] = 0;

    rep(i,n){
        int x = f[i];
        if(i == 0){
            dp[i][0] = a[x] * (n - 1 - x);
            dp[i][1] = a[x] * x;
        }else{
            rep(j,n+1){
                if(j > i + 1)break;
                if(j > 0)dp[i][j] = max(dp[i][j], dp[i-1][j-1] + a[x] * abs(x-(j-1)));
                dp[i][j] = max(dp[i][j], dp[i-1][j] + a[x] * abs(n-1-(i-j)-x));
            }
        }
    }

    /*
    rep(i,n){
        rep(j,n+1)cout << dp[i][j] << ' ';
        cout << endl;
    }
    */

    ll ans = 0;
    rep(j,n+1)ans = max(ans, dp[n-1][j]);
    cout << ans << endl;
    return 0;
}
 
 


Compiler output:
main.c:1:10: fatal error: bits/stdc++.h: No such file or directory
    1 | #include <bits/stdc++.h>
      |          ^~~~~~~~~~~~~~~
compilation terminated.
Language: C

/*
AuThOr GaRyMr
*/
#include<bits/stdc++.h>
#define rb(a,b,c) for(int a=b;a<=c;++a)
#define rl(a,b,c) for(int a=b;a>=c;--a)
#define LL long long
#define IT iterator
#define PB push_back
#define II(a,b) make_pair(a,b)
#define FIR first
#define SEC second
#define FREO freopen("check.out","w",stdout)
#define rep(a,b) for(int a=0;a<b;++a)
#define KEEP while(1)
#define SRAND mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define random(a) rng()%a
#define ALL(a) a.begin(),a.end()
#define POB pop_back
#define ff fflush(stdout)
#define fastio ios::sync_with_stdio(false)
#define debug_pair(A) cerr<<A.FIR<<" "<<A.SEC<<endl;
using namespace std;
const int INF=0x3f3f3f3f;
typedef pair<int,int> mp;
typedef pair<mp,mp> superpair;
LL dp[2000+20][2000+20];
vector<mp> ch;
int n;
int main(){
	fastio;
	cin>>n;
	rb(i,1,n){
		mp now;
		cin>>now.FIR;
		now.FIR*=-1;
		now.SEC=i;
		ch.PB(now);
	}
	sort(ALL(ch));
	rb(i,1,n)
		ch[i-1].FIR*=-1;
	rb(i,1,n){
		LL now=ch[i-1].FIR;
		LL pos=ch[i-1].SEC;
//		cout<<now<<" "<<pos<<endl;
		rb(j,0,i){
			//左边
			if(j!=i)
			dp[i][j]=max(dp[i][j],dp[i-1][j]+now*(LL)(abs(n-(i-1-j)-pos)));
			if(j)
			dp[i][j]=max(dp[i][j],dp[i-1][j-1]+now*(LL)(abs(j-pos)));
//			cout<<dp[i][j]<<":"<<j<<endl; 
		}	
	}
	LL res=0;
	rb(i,0,n){
		res=max(res,dp[n][i]);
	}
	cout<<res<<endl;
	return 0;
}


Compiler output:
main.c:4:9: fatal error: bits/stdc++.h: No such file or directory
    4 | #include<bits/stdc++.h>
      |         ^~~~~~~~~~~~~~~
compilation terminated.
Language: C

    //For higher stack size use g++ -O2 -std=c++11 -Wall -Wl,--stack=268435456 a.cpp -o a.exe in cmd
    #include <bits/stdc++.h>
    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <cstring>
    #include <chrono>
    #include <complex>
    #define ll long long
    #define ld long double
    #define vi vector<int>
    #define vll vector<ll>
    #define vvi vector < vi >
    #define pii pair<int,int>
    #define pll pair<long long, long long>
    #define mod 1000000007
    #define inf 1000000000000000001;
    #define all(c) c.begin(),c.end()
    #define mp(x,y) make_pair(x,y)
    #define mem(a,val) memset(a,val,sizeof(a))
    #define eb emplace_back
    #define pb push_back
    #define f first
    #define s second
    
    using namespace std;
    int main()
    {
        std::ios::sync_with_stdio(false);
        int T;
        T=1;
        // cin.ignore(); must be there when using getline(cin, s)
        while(T--)
        {
            int n,i,j;
            cin>>n;
            vector<pll> v;
            ll ar[n+1],flag[n+1];
            for(i=1;i<=n;++i)
            {
                cin>>ar[i];
                flag[i]=0;
            }
            ll l=1,r=n;
            ll ans=0,ans2,pos;
            while(l<=r)
            {
                ans2=0;
                for(i=1;i<=n;++i)
                {
                    if(flag[i]==0)
                    {
                        if(ans2<ar[i]*abs(i-l))
                        {
                            ans2=ar[i]*abs(i-l);
                            pos=i;
                        }
                        if(ans2<ar[i]*abs(i-r))
                        {
                            ans2=ar[i]*abs(i-r);
                            pos=i;
                        }
                    }
                }
                ans=ans+ans2;
                i=pos;
                flag[pos]=1;
                if(ans2==ar[i]*abs(i-l))
                {
                    ++l;
                }
                else
                {
                    --r;
                }
            }
            cout<<ans<<endl;
        }
        return 0;
    }


Compiler output:
main.c:2:14: fatal error: bits/stdc++.h: No such file or directory
    2 |     #include <bits/stdc++.h>
      |              ^~~~~~~~~~~~~~~
compilation terminated.
Language: C++

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define REP(i,n) for (ll i = 0; i < (n); ++i)
#define RREP(i, n) for (ll i = (n) - 1; i >= 0; --i)
#define ALL(v) (v).begin(), (v).end()


int main(){
    ll n;
    cin >> n;
    vector<ll> a(n);
    REP(i, n){
        cin >> a.at(i);
    }

    vector<array<ll, 3>> gain;
    REP(i, n){
        REP(j, m){
            gain.push_back({a.at(i) * abs(i - j), i, j});
        }
    }
    sort(gain.rbegin(), gain.rend());

    ll ans = 0;
    vector<bool> flag_child(n, false), flag_pos(n, false);
    for(const auto p : gain){
        if(!flag_child.at(p.at(1)) && !flag_pos.at(p.at(2))){
            ans += p.at(0);
            flag_child.at(p.at(1)) = true;
            flag_pos.at(p.at(2)) = true;
        }
    }
    cout << ans << endl;
    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:20:16: error: 'm' was not declared in this scope
   20 |         REP(j, m){
      |                ^
a.cc:5:38: note: in definition of macro 'REP'
    5 | #define REP(i,n) for (ll i = 0; i < (n); ++i)
      |                                      ^
Language: C

#include<bits/stdc++.h>
using namespace std;
long long n,ans,dp[2020][2020];
pair<long long,long long>p[2020];
bool cmp(pair<long long,long long>a,pair<long long,long long>b)
{
	if(a.first!=b.first)
	{
		return a.first>b.first;
	}
	return a.second<b.second;
}
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		long long a;
		cin>>a;
		p[i]=make_pair(a,i);
	}
	sort(p+1,p+n+1,cmp);
	for(int i=1;i<=n;i++)
	{
		for(int l=1;l<=n;l++)
		{
			int r=n-(i-l);
			if(r>n)
			{
				continue;
			}
			dp[l+1][r]=max(dp[l+1][r],dp[l][r]+p[i].first*abs(p[i].second-l));
			dp[l][r-1]=max(dp[l][r-1],dp[l][r]+p[i].first*abs(p[i].second-r));
		}
	}
	for(int i=1;i<=n+1;i++)
	{
		ans=max(ans,dp[i][i-1]);
	}
	cout<<ans<<endl;
	return 0;
}

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

//
// Created by yamunaku on 2020/04/19.
//

#include <bits/stdc++.h>

using namespace std;

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repl(i, l, r) for(int i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perl(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD9 998244353
#define MOD1 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP <<" "<<
#define CYES cout<<"Yes"<<endl
#define CNO cout<<"No"<<endl
#define CFS cin.tie(0);ios::sync_with_stdio(false)
#define CST(x) cout<<fixed<<setprecision(x)

using ll = long long;
using ld = long double;
using vi = vector<int>;
using mti = vector<vector<int>>;
using vl = vector<ll>;
using mtl = vector<vector<ll>>;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
template<typename T>
using heap = priority_queue<T, vector<T>, function<bool(const T, const T)>>;

int main(){
    //CFS;
    int n;
    cin >> n;
    vl a(n);
    rep(i, n) cin >> a[i];
    vi idx(n);
    iota(all(idx), 0);
    sort(all(idx), [&](int &l, int &r){
        return a[l] > a[r];
    });
    vl dp(n + 1, 0);
    rep(i, n){
        vl ndp(n, 0);
        rep(j, i + 1){
            ndp[j + 1] = max(ndp[j + 1], dp[j] + a[idx[i]] * abs(j - idx[i]));
            ndp[j] = max(ndp[j], dp[j] + a[idx[i]] * abs(n - 1 - (i - j) - idx[i]));
        }
        dp = ndp;
    }
    ll ans = 0;
    rep(i, n + 1){
        ans = max(ans, dp[i]);
    }
    cout << ans << endl;
    return 0;
}

Compiler output:
main.c:5:10: fatal error: bits/stdc++.h: No such file or directory
    5 | #include <bits/stdc++.h>
      |          ^~~~~~~~~~~~~~~
compilation terminated.
Language: C

#include<bits/stdc++.h>
#define inf 0x3f3f3f3f3f3f3f3fll
using namespace std;
typedef long long ll;
const int N=2005;
int n;
ll a[N],b[N],dp[N][N];
bool cmp(int x,int y){return a[x]>a[y];}
int main()
{
    memset(dp,-inf,sizeof(dp));
    scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%lld",&a[i]),b[i]=i;
    sort(b+1,b+1+n,cmp);
    dp[1][n]=0;
    ll ans=0;
    for(int i=n-1;i>=0;i--)
    {
        int pos=b[n-i];
        for(int l=1;l+i<=n;l++)
        {
            if(i==0)
            {
                ans=max(ans,a[pos]*abs(pos-l)+dp[l][l]);
                continue;
            }
            int r=l+i;
            dp[l+1][r]=max(dp[l+1][r],dp[l][r]+a[pos]*abs(pos-l));
            dp[l][r-1]=max(dp[l][r-1],dp[l][r]+a[pos]*abs(pos-r));
        }
    }
    printf("%lld\n",ans);
}


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

#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <chrono>
#include <random>
#include <functional>

using namespace std;

#define int long long

signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);

	int n;
	cin >> n;
	vector<int> a(n);
	for (auto &t : a) {
		cin >> t;
	}
	vector<int> ind(n);
	iota(ind.begin(), ind.end(), 0);
	for (int j = 0; j < n; j++) {
		for (int i = 0; i + 1 < n; i++) {
			auto f = abs(i - ind[i]) * a[ind[i]] + abs(i + 1 - ind[i + 1]) * a[ind[i + 1]];
			auto s = abs(i + 1 - ind[i]) * a[ind[i]] + abs(i - ind[i + 1]) * a[ind[i + 1]];
			if (f < s) {
				swap(ind[i], ind[i + 1]);
			}
		}
	}
	int ans = 0;
	for (int i = 0; i < n; i++) {
		ans += abs(i - ind[i]) * a[ind[i]];
	}
	cout << ans << endl;
}


Compiler output:
main.c:1:10: fatal error: iostream: No such file or directory
    1 | #include <iostream>
      |          ^~~~~~~~~~
compilation terminated.
Language: C

#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <deque>
#include <queue>
#include <string>
#include <string.h>
#include <math.h>
#include <iomanip>
#include <stdio.h>
using namespace std;

#define int64 long long
#define pii pair <int64, int64>
#define fr first
#define sc second
#define heap priority_queue
struct piii{
    int64 fr, sc, th;
    bool operator < (const piii &b){
        if (fr != b.fr) return fr < b.fr;
        if (sc != b.sc) return sc < b.sc;
        return th < b.th;
    }
};
///////////////////////////////////////////////
///////////////////////////////////////////////

int64 val, n;
pii a[2002];
int64 f[2002][2002];
bool cmp(const pii &a, const pii &b){
    return a.fr > b.fr;
}

int main(){
    cout << setprecision(2) << fixed;
    ios::sync_with_stdio(false), cin.tie(0);
    //freopen("input.txt", "r", stdin);
    cin >> n;
    for (int i = 1; i <= n; i++){
        cin >> val;
        a[i] = pii({val, i});
    }
    sort(a + 1, a + 1 + n, cmp);
    for (int i = 1; i <= n; i++){
        for (int j = 0; j <= i; j++){
            f[i][j] = -1e18;
            if (j > 0)
                f[i][j] = max(f[i][j], f[i - 1][j - 1] + a[i].fr * abs(a[i].sc - j));
            if (j < i)
                f[i][j] = max(f[i][j], f[i - 1][j] + a[i].fr * abs(a[i].sc - (n + 1 - (i - j))));
        }
    }
    int64 res = 0;
    for (int i = 0; i <= n; i++) res = max(res, f[n][i]);
    cout << res;
    return 0;
}


Compiler output:
main.c:1:10: fatal error: iostream: No such file or directory
    1 | #include <iostream>
      |          ^~~~~~~~~~
compilation terminated.
Language: C

#include<bits/stdc++.h>
#define god dimasi5eks
#pragma GCC optimize("O3")
#define fi first
#define se second
#define pb push_back
#define pf push_front
#define mod 1000000007
#define dancila 3.14159265359
#define eps 1e-9

// #define fisier 1

using namespace std;

typedef long long ll;


int add(int a, int b)
{
    int x = a+b;
    if(x >= mod)
        x -= mod;
    if(x < 0)
        x += mod;
    return x;
}
ll mul(ll a, ll b)
{
    return (a*b) % mod;
}

ll pw(ll a, ll b)
{
    ll ans = 1;
    while(b)
    {
        if(b & 1)
            ans = (ans * a) % mod;
        a = (a * a) % mod;
        b >>= 1;
    }
    return ans;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
long long rand_seed()
{
    long long a = rng();
    return a;
}


int n;
pair<int, int> val[2002];

ll dp[2002][2002];
int main()
{

    #ifdef fisier
        ifstream f("input.in");
        ofstream g("output.out");
    #endif

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    cin >> n;
    for(int i = 1; i <= n; ++i)
		cin >> val[i].fi, val[i].se = i;
	ll ans = 0;
	sort(val + 1, val + n + 1);
	for(int len = n; len >= 1; --len)
		for(int st = 1; st + len - 1 <= n; ++st)
		{
			if(len == 1)
				ans = max(ans, dp[st][st] + 1LL * val[len].fi * abs(val[len].se - st));
			else
			{
				dp[st+1][st + len - 1] = max(dp[st+1][st + len - 1], dp[st][st + len - 1] + 1LL * val[len].fi * abs(val[len].se - st));
				dp[st][st + len - 2] = max(dp[st][st + len - 2], dp[st][st + len - 1] + 1LL * val[len].fi * abs(val[len].se - (st + len - 1)));
			}
		}
	cout << ans;
	return 0;
}


Compiler output:
main.c: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>
using namespace std;
struct undoable_dsu{
  struct dat{
    int p,sz;
  };
  int cc;
  vector<dat>t;
  vector<pair<int, dat> >hist;
  undoable_dsu(int n=0): cc(n) t(n,{-1, 1}) {}
  int root(int v) const{
    while (t[v].p!=-1) v=t[v].p;
    return v;
  }
  void unite(int u, int v){
    u=root(u),v=root(v);
    assert(u!=v);
    --cc;
    if (t[u].sz<t[v].sz) swap(u,v);
    hist.emplace_back(u,t[u]);
    hist.emplace_back(v,t[v]);
    t[v].p=u;
    t[u].sz+=t[v].sz;
  }
  void undo(){
    ++cc;
    for (int _=2;_--;){
      t[hist.back().first]=hist.back().second;
      hist.pop_back();
    }
  }
  bool same(int u,int v)const {return root(u)==root(v);}
  int size(int v) const {return t[root(v)].sz;}
};
int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n;
  cin>>n;
  vector<int>c(n);
  for (auto&&  e:c){
    cin>>e;
    --e;
  }
  vector<pair<int, int> > edges(n-1);
  vector<vector<int> >g(n);
  for (auto&& [u,v]:edges){
    cin>>u>>v;
    --u,--v;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  vector<vector<int> > seg(2 * n);
  auto add = [&](int l,int r,int i){
    for (l+=n,r+=n;l<r;l>>=1,r>>=1){
      if (l&1){
        seg[l++].push_back(i);
      }
      if (r&1){
        seg[--r].push_back(i);
      }
    }
  };
  for (int i=0;i<n-1;++i){
    auto [u, v]=edges[i];
    if (c[u]>c[v]){
      swap(u,v);
    }
    if (c[u]==c[v]){
      add(0,c[u],i);
      add(c[u]+1,n,i);
    }else{
      add(0,c[u],i);
      add(c[u]+1,c[v],i);
      add(c[v]+1,n,i);
    }
  }
  vector<vector<int> >vs(n);
  for (int v=0;v<n;++v){
    vs[c[v]].push_back(v);
  }
  undoable_dsu ud(n);
  vector res(n,(long long)n*(n+1)/2);
  for (int k=0;k<n;++k){
    if (empty(vs[k])){
      res[k]=0;
    }
  }
  auto dfs=[&](auto&& self, int k)->void{
    for (int i:seg[k]){
      ud.unite(edges[i].first,edges[i].second);
    }
    if (k<n){
      self(self,2*k);
      self(self,2*k+1);
    }else{
      set<int>se;
      for (int v:vs[k-n]){
        for (int u:g[v]){
          if (c[u]!=k-n){
            se.insert(ud.root(u));
          }
        }
      }
      long long cur=0;
      for (int v:se){
        long long sz=ud.size(v);
        cur+=sz*(sz+1)/2;
      }
      res[k-n]-=cur;
    }
    for (int i:seg[k]){
      ud.undo();
    }
  };
  dfs(dfs,1);
  for (auto e:res){
    cout<<e<<'\n';
  }
}

Compiler output:
a.cc: In constructor 'undoable_dsu::undoable_dsu(int)':
a.cc:10:32: error: expected '{' before 't'
   10 |   undoable_dsu(int n=0): cc(n) t(n,{-1, 1}) {}
      |                                ^
Language: C++

#include <bits/stdc++.h>
using namespace std;
int main(){
    int N;
    cin>>N;
    vector<int>C(N);
    for(int i=0;i<N;i++){
        cin>>C[i];
        C[i]--;
    }
    vector<int>edges[200000];
    for(int i=0;i<N-1;i++){
        int a,b;
        cin>>a>>b;
        a-;b--;
        edges[a].push_back(b);
        edges[b].push_back(a);
    }
    vector<vector<int> >res(N);
    vector<int>cnt(N);
    vector<map<int,int> >dp(N);
    auto dfs=[&](auto&& dfs,int i,int p)->void{
        for(int j:edges[i])if(j!=p){
            dfs(dfs,j,i);
            cnt[i]+=cnt[j];
            int c=cnt[j];
            if(dp[j].count(C[i]))c-=dp[j][C[i]];
            res[C[i]].push_back(c);
            if(dp[i].size()<dp[j].size())swap(dp[i],dp[j]);
            for(auto& p:dp[j])dp[i][p.first]+=p.second;
        }
        cnt[i]++;
        dp[i][C[i]]=cnt[i];
    };
    dfs(dfs,0,-1);
    for(int i=0;i<N;i++)res[i].push_back(N-dp[0][i]);
    int64_t all=int64_t(N)*(N+1)/2;
    vector<int64_t>ans(N,all);
    for(int i=0;i<N;i++)for(int64_t a:res[i]) ans[i]-=a*(a+1)/2;
    for(auto a:ans)cout<<a<<endl;
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:15:11: error: expected primary-expression before ';' token
   15 |         a-;b--;
      |           ^
Language: C

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mit map<int,int>::iterator
#define sit set<pii>::iterator
#define itrm(g,x) for(mit g=x.begin();g!=x.end();g++)
#define itrs(g,x) for(sit g=x.begin();g!=x.end();g++)
#define ltype int
#define rep(i,j,k) for(ltype(i)=(j);(i)<=(k);(i)++)
#define rap(i,j,k) for(ltype(i)=(j);(i)<(k);(i)++)
#define per(i,j,k) for(ltype(i)=(j);(i)>=(k);(i)--)
#define pii pair<int,int>
#define fi first
#define se second
#define mpr make_pair
#define pb push_back
#define fastio ios::sync_with_stdio(false)
const int inf=0x3f3f3f3f,mod=1000000007;
const double pi=3.1415926535897932,eps=1e-6;
void chmax(int &x,int y){if(x < y) x = y;}
void chmin(int &x,int y){if(x > y) x = y;}
int n,c[200005],cnt,in[200005],out[200005];ll ans[200005];
vector<int> v[200005];
set<pii> s[200005];
void dfs1(int x,int fa){
    in[x] = ++cnt;
    rap(i,0,v[x].size()){
        int to = v[x][i];
        if(to == fa) continue;
        dfs1(to,x);
    }
    out[x] = cnt;
}
void dfs(int x,int fa){
    rap(i,0,v[x].size()){
        int to = v[x][i];
        if(to == fa) continue;
        dfs(to,x);
        int cur = out[to] - in[to] + 1;
        sit l = s[c[x]].lower_bound(mpr(in[to],0)), r = s[c[x]].lower_bound(mpr(out[to]+1,0));
        vector<pii> del;
        for(;l != r;l++) {
            cur -= l -> se;
            del.pb(*l);
        }
        ans[c[x]] -= (ll)cur * (cur + 1) / 2;
        while(del.size()){s[c[x]].erase(del.back());del.pop_back();}
    }
    s[c[x]].insert(mpr(in[x],out[x] - in[x] + 1));
}
int main()
{
    scanf("%d",&n);
    rep(i,1,n) scanf("%d",c+i);
    rap(i,1,n){
        int t1,t2;
        scanf("%d%d",&t1,&t2);
        v[t1].pb(t2);
        v[t2].pb(t1);
    }
    dfs1(1,0);
    rep(i,1,n) ans[i] = (ll)n * (n + 1) / 2;
    dfs(1,0);
    rep(i,1,n) if(c[1] != i){
        int cur = n;
        for(sit it = s[i].begin();it != s[i].end();it++) cur -= it -> se;
        ans[i] -= (ll)cur * (cur + 1) / 2;
    }
    rep(i,1,n) printf("%lld\n",ans[i]);
    return 0;
}

Compiler output:
main.c: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>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

#define pb push_back
#define mp make_pair
#define endl '\n'
#define f first
#define s second
#define sz(a) ((int)(a).size())
#define rep(i,a,b) for(int i=(a); i<(b); i++)
#define read(v, a, b) for(int i=(a); i<(b); i++) cin>>v[i]
#define printv(v, a, b) for(int i=(a); i < (b); i++) cout << v[i] << ' '
#define clr(a,v) memset(a, v, sizeof(a))
#define all(a) (a).begin(),(a).end()
#define FAST cin.tie(0), cout.tie(0), ios::sync_with_stdio(0)
#define db(x) cerr << #x << " == " << x << endl
#define _ << " " <<

const int maxn = 2e5 + 100;
int c[maxn], used[maxn], sz[maxn], n;
vi g[maxn];
ll ans[maxn];

void dfs(int v = 0, int p=-1){
	sz[v] = 1;
	for(auto u : g[v]){
		if(u == p) continue;
		dfs(u, v);
		sz[v] += sz[u];
	}
}

void solve(int v=0, int p=-1){
	
	int last = used[c[v]];
	
	ll sum = sz[v]-1; //sum of all subtrees (-1 to remove itself)
	
	ans[c[v]] += 1ll*(n - last - sz[v] + 1)*(sz[v]);
	
	for(auto u : g[v]){
        if(u == p) continue;
        sum -= sz[u];
        ans[c[v]] += sz[u] * sum;
    }
	
	for(auto u : g[v]){
		if(u == p) continue;
		used[c[v]] = n-sz[u];
		solve(u, v);
	}
	
	used[c[v]] = last + sz[v];
}

int main(){
	FAST;
	
	cin >> n;
	
	for(int i = 0, val; i < n; i++){
		cin >> val;
		c[i] = --val;
	}
	
	for(int i = 1; i < n; i++){
		int a, b;
		cin >> a >> b;
		a--, b--;
		g[a].pb(b);
		g[b].pb(a);
	}
		
	dfs();
	solve();
	
	for(int i = 0; i < n; i++)
		cout << ans[i] << '\n';
}


Compiler output:
main.c:1:10: 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 pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell        1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)
using namespace std;
int n,c[200005],ans[200005],ent[200005],s[200005],tim;
vi a[200005],f[200005];
void dfs(int node,int par){
    ent[node]=++tim;
    s[node]=1;
    for(auto i:a[node]){
        if(i!=par){
            dfs(i,node);
            int w=s[i];
            while(sz(f[c[node])) w-=s[f[c[node]].back()],f[c[node]].pop_back();
            s[node]+=s[i];
            ans[c[node]]+=w*(w+1)/2;
        }
    }
    f[c[node]].pb(node);
}
void solve(){
    cin>>n;
    rep(i,1,n+1) cin>>c[i];
    rep(i,0,n-1){
        int x,y;
        cin>>x>>y;
        a[x].pb(y);
        a[y].pb(x);
    }
    dfs(1,0);
    rep(i,1,n+1){
        int w=n;
        while(sz(f[i])) w-=s[f[i].back()],f[i].pop_back();
        ans[i]+=w*(w+1)/2;
        cout<<n*(n+1)/2-ans[i]<<endl;
    }
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    // cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

Compiler output:
a.cc: In function 'void dfs(long long int, long long int)':
a.cc:13:28: error: request for member 'size' in 'c[node]', which is of non-class type 'long long int'
   13 | #define sz(x)       (int)x.size()
      |                            ^~~~
a.cc:27:19: note: in expansion of macro 'sz'
   27 |             while(sz(f[c[node])) w-=s[f[c[node]].back()],f[c[node]].pop_back();
      |                   ^~
a.cc:27:32: error: expected ']' before ')' token
   27 |             while(sz(f[c[node])) w-=s[f[c[node]].back()],f[c[node]].pop_back();
      |                                ^
Language: C

#include <bits/stdc++.h>

#define int         long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell        1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)
using namespace std;
int n,c[200005],ans[200005],ent[200005],s[200005],tim;
vi a[200005],f[200005];
void dfs(int node,int par){
    ent[node]=++tim;
    s[node]=1;
    for(auto i:a[node]){
        if(i!=par){
            dfs(i,node);
            int w=s[i];
            while(sz(f[c[node])) w-=s[f[c[node]].back()],f[c[node]].pop_back();
            s[node]+=s[i];
            ans[c[node]]+=w*(w+1)/2;
        }
    }
    f[c[node]].pb(node);
}
void solve(){
    cin>>n;
    rep(i,1,n+1) cin>>c[i];
    rep(i,0,n-1){
        int x,y;
        cin>>x>>y;
        a[x].pb(y);
        a[y].pb(x);
    }
    dfs(1,0);
    rep(i,1,n+1){
        int w=n;
        while(sz(f[i])) w-=s[f[i].back()],f[i].pop_back();
        ans[i]+=w*(w+1)/2;
        cout<<n*(n+1)/2-ans[i]<<endl;
    }
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    // cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

Compiler output:
main.c:1:10: fatal error: bits/stdc++.h: No such file or directory
    1 | #include <bits/stdc++.h>
      |          ^~~~~~~~~~~~~~~
compilation terminated.
Language: C

#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define ll long long 
#define FI first 
#define SE second
#define pb push_back 
#define eb emplace_back
#define mod 1000000007
#define all(c) (c).begin(),(c).end()
#define LB  lower_bound
#define UB  upper_bound
#define max3(a,b,c) max(c,max(a,b))
#define min3(a,b,c) min(c,min(a,b))
#define mems(s, n) memset(s, n, sizeof(s))
#define NINF -1e18
#define INF 1e18
#define int ll int
#define OOK order_of_key  //no of elements less than
#define FBO find_by_order //iterator pointing kth element;indexing starts from 0
#define CK3(x,y,z) cout<<(x)<<" "<<(y)<<" "<<(z)<<endl
#define CK4(a,b,c,d) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<endl

typedef pair<int,int> PII;
typedef pair<pair<int,int>,int> PPII;
typedef pair<int,pair<int,int>> PIPI;
typedef map<int,int>MII;
typedef vector<int> VI;
template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

/*int power(int a, int b)
{int x=1,y=a;while(b>0){if(b%2){x =(x*y)%mod;}y =(y*y)%mod;b/=2;}return x%mod;}
*/
//int modInverse(int a, int m) {return power(a, m-2);} //gcd(a,m)=1 

int t[1000000];vector<VI>adj;VI ans(1000000,0);VI colour(1000000,0);int n;
void update(int v, int tl, int tr, int l, int r, int add) {
    if (l > r)
        return;
    if (l == tl && r == tr) {
        t[v] += add;
    } else {
        int tm = (tl + tr) / 2;
        update(v*2, tl, tm, l, min(r, tm), add);
        update(v*2+1, tm+1, tr, max(l, tm+1), r, add);
    }
}

int get(int v, int tl, int tr, int pos) {
    if (tl == tr)
        return t[v];
    int tm = (tl + tr) / 2;
    if (pos <= tm)
        return t[v] + get(v*2, tl, tm, pos);
    else
        return t[v] + get(v*2+1, tm+1, tr, pos);
}
void dfs(int v,int par)
{   int px=get(1,1,n,colour[v]);update(1,1,n,colour[v],colour[v],-px);
    for(auto it:adj[v])
    {
        if(it!=par)
        {
            dfs(it,v);
            int x=get(1,1,n,colour[v]);
            if(x>0)
            ans[colour[v]]+=(x*(x+1))/2;
            update(1,1,n,colour[v],colour[v],-x);
        }
    }
    update(1,1,n,1,colour[v]-1,1);update(1,1,n,colour[v]+1,n,1);
    int x=get(1,1,n,colour[v]);
    update(1,1,n,colour[v],colour[v],-x);
    update(1,1,n,colour[v],colour[v],px);
}
signed main()
{
ios::sync_with_stdio(false); cin.tie(0);
int T=1,T1=0;//cin>>T;
while(T1++<T)
{//cout<<"Case #"<<T1<<": ";
    
    cin>>n;adj.resize(n+1);
    for(int i=1;i<=n;i++)cin>>colour[i];
    for(int i=0;i<n-1;i++)
    {
        int x,y;
        cin>>x>>y;
        adj[x].pb(y);
        adj[y].pb(x);
    }
    dfs(1,-1);
    for(int i=1;i<=n;i++)
    {
    	int x=get(1,1,n,i);
    	if(x>0)
    	ans[i]+=(x*(x+1))/2;
    }
    for(int i=1;i<=n;i++)cout<<(n*(n+1))/2-ans[i]<<endl;
}


return 0;
}





Compiler output:
main.c:1:10: fatal error: bits/stdc++.h: No such file or directory
    1 | #include <bits/stdc++.h>
      |          ^~~~~~~~~~~~~~~
compilation terminated.
Language: C++

#include <map>
#include <cstdio>
#include <vector>
#include <cstring>
#define pii pair<int,int>
#define s1 first
#define s2 second
#define N 200001
using namespace std;struct edge{int v,next;edge(){}edge(int _v,int _next){v=_v;next=_next;}}e[N<<1];int head[N],sz;
void init(){memset(head,-1,sizeof(head));sz=0;}void insert(int u,int v){e[++sz]=edge(v,head[u]);head[u]=sz;}
map<int,int> dp[N];vector<int> cc[N];int siz[N],n,c[N];long long ans[N];
void dfs(int u,int f)
{
	for(int i=head[u];~i;i=e[i].next)
	{
		if(e[i].v==f)continue;dfs(e[i].v,u);siz[u]+=siz[e[i].v];int tmp=siz[e[i].v];
		if(dp[e[i].v].count(c[u]))tmp-=dp[e[i].v][c[u]];cc[c[u]].push_back(tmp);
		if(dp[u].size()<dp[e[i].v].size())swap(dp[u],dp[e[i].v]);
		for(map<int,int>::iterator it=dp[e[i].v].begin();it!=dp[e[i].v].end();++it)dp[u][it->s1]+=it->s2;
	}dp[u][c[u]]=++siz[u];
}
int main()
{
	init();scanf("%d",&n);for(int i=1;i<=n;++i)scanf("%d",c+i);for(int i=1,u,v;i<n;++i)scanf("%d%d",&u,&v),insert(u,v),insert(v,u);
	dfs(1,1);for(int i=1;i<=n;++i)ans[i]=1ll*n*(n+1)/2;for(int i=1;i<=n;++i)cc[i].push_back(n-dp[1][i])
	for(int i=1;i<=n;++i)for(int j=0;j<cc[i].size();++j)ans[i]-=1ll*cc[i][j]*(cc[i][j]+1)/2;for(int i=1;i<=n;++i)printf("%lld\n",ans[i]);putchar(10);return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:25:108: error: expected ';' before 'for'
   25 |         dfs(1,1);for(int i=1;i<=n;++i)ans[i]=1ll*n*(n+1)/2;for(int i=1;i<=n;++i)cc[i].push_back(n-dp[1][i])
      |                                                                                                            ^
      |                                                                                                            ;
   26 |         for(int i=1;i<=n;++i)for(int j=0;j<cc[i].size();++j)ans[i]-=1ll*cc[i][j]*(cc[i][j]+1)/2;for(int i=1;i<=n;++i)printf("%lld\n",ans[i]);putchar(10);return 0;
      |         ~~~                                                                                                 
a.cc:26:21: error: 'i' was not declared in this scope
   26 |         for(int i=1;i<=n;++i)for(int j=0;j<cc[i].size();++j)ans[i]-=1ll*cc[i][j]*(cc[i][j]+1)/2;for(int i=1;i<=n;++i)printf("%lld\n",ans[i]);putchar(10);return 0;
      |                     ^
a.cc:26:42: error: 'j' was not declared in this scope
   26 |         for(int i=1;i<=n;++i)for(int j=0;j<cc[i].size();++j)ans[i]-=1ll*cc[i][j]*(cc[i][j]+1)/2;for(int i=1;i<=n;++i)printf("%lld\n",ans[i]);putchar(10);return 0;
      |                                          ^
Language: C

#include <map>
#include <cstdio>
#include <vector>
#include <cstring>
#define pii pair<int,int>
#define s1 first
#define s2 second
#define N 200001
using namespace std;struct edge{int v,next;edge(){}edge(int _v,int _next){v=_v;next=_next;}}e[N<<1];int head[N],sz;
void init(){memset(head,-1,sizeof(head));sz=0;}void insert(int u,int v){e[++sz]=edge(v,head[u]);head[u]=sz;}
map<int,int> dp[N];vector<int> cc[N];int siz[N],n,c[N];long long ans[N];
void dfs(int u,int f)
{
	for(int i=head[u];~i;i=e[i].next)
	{
		if(e[i].v==f)continue;dfs(e[i].v,u);siz[u]+=siz[e[i].v];int tmp=siz[u];
		if(dp[e[i].v].count(c[u]))tmp-=dp[e[i].v][c[u]];cc[c[u]].push_back(tmp);
		if(dp[u].size()<dp[e[i].v].size())swap(dp[u],dp[e[i].v]);
		for(map<int,int>::iterator it=dp[e[i].v].begin();it!=dp[e[i].v].end();++it)dp[u][it->s1]+=it->s2;
	}dp[u][c[u]]=++siz[u];
}
int main()
{
	init();scanf("%d",&n);for(int i=1;i<=n;++i)scanf("%d",c+i);for(int i=1,u,v;i<n;++i)scanf("%d%d",&u,&v),insert(u,v),insert(v,u);
	dfs(1,1);for(int i=1;i<=n;++i)ans[i]=1ll*n*(n+1)/2;for(int i=1;i<=n;++i)cc[i].push_back(n-dp[1][i]);
	for(int i=1;i<=n;++i)for(int j=0;j<cc[i].size();++j)ans[i]-=1ll*cc[i][j]*(cc[i][j]+1)/2;for(int i=1;i<=n;++i)printf("%lld\n",ans[i]);putchar(10);return 0;
}

Compiler output:
main.c:1:10: fatal error: map: No such file or directory
    1 | #include <map>
      |          ^~~~~
compilation terminated.
Language: C

#include<bits/stdc++.h>
using namespace std;
 
#define pb push_back
#define ll long long
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
#define f1(n) fr(i,1,n+1)
#define ms(i) memset(i,0,sizeof(i));
#define ms1(i) memset(i,-1,sizeof(i));
#define pll pair<ll,ll>
#define pii pair<int,int>
#define F first
#define S second
const int maxn = 2e5 + 5;
const int mod = 998244353;
ll ans[200005];
int c[200005];
ll cnt[200005];
ll cur[200005];
ll sz[200005];
vector<int>g[200005];
void dfs(int now, int pre) {
    sz[now] = 1;
    int in = cur[c[now]];
    for (auto i : g[now]) {
        if (i == pre) continue;
        int be = cur[c[now]];
        dfs(i, now);
        int af = cur[c[now]];
        int mt = sz[i] - (af-be);
        ans[c[now]] -= cnt[mt];
        sz[now] += sz[i];
    }
    cur[c[now]] = in + sz[now];
}
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    ll n;
    cin >> n;
    f1 (n) {
        ans[i] = n * (n + 1) / 2;
        cnt[i] = (ll)i * (i + 1) / 2;
        cin >> c[i];
    }
    f (n - 1) {
        int x, y;
        cin >> x >> y;
        g[x].pb(y);
        g[y].pb(x);
    }
    dfs(1, 0);
    f1 (n) {
        ans[i] -= cnt[n - cur[i]];
        cout << ans[i] << '\n';
    }
}


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

#include<cmath>
#include<math.h>
#include<ctype.h>
#include<algorithm>
#include<string.h>
#include<stdio.h>
#include<iostream>
#define int long long
#define N (int) 3e5
#define INF (int) 1e18
using namespace std;
int n;
int a[N];

int sum1[N], sum2[N], sum3[N];

signed main () {
	cin >> n;
	for (int i = 1; i <= n; i ++) cin >> a[i];
	
	sum1[1] = a[1], sum1[2] = a[2];
	for (int i = 3; i <= n; i ++) {
		sum1[i] = sum1[i-2] + a[i];
	}
	sum2[n] = a[n], sum2[n-1] = a[n-1];
	for (int i = n-2; i >= 1; i --) {
		sum2[i] = sum2[i+2] + a[i];
	}
	
	int ans = max (sum1[n-1], sum1[n]);
	for (int i = 1; i+3 <= n; i += 2) {
		ans = max (ans, sum1[i] + sum2[i+3]);
	}
	
	if (n % 2 == 0) {
		cout << ans << endl;
	} else {
		int tmp = INF;
		for (int i = 1; i <= n; i += 2) tmp = min (tmp, a[i]);
		ans = max (ans, sum1[n]-tmp);
		
		for (int i = 2; i+3 <= n; i += 2) ans = max (ans, sum1[i] + sum2[i+3]);
		
		for (int i = n-3; i >= 2; i -= 2) sum3[i] = max (sum3[i+2], sum2[i+3]) + a[i];
		for (int i = 1; i+6 <= n; i += 2) ans = max (ans, sum1[i] + sum3[i+3]);
		
		cout << ans << endl;
	}
	
	return 0;
}

Compiler output:
main.c:1:9: fatal error: cmath: No such file or directory
    1 | #include<cmath>
      |         ^~~~~~~
compilation terminated.
Language: C

#include <bits/stdc++.h>
#define int long long
#define N (int) 3e5
#define INF (int) 1e18
using namespace std;
int n;
int a[N];

int sum1[N], sum2[N], sum3[N];

signed main () {
	cin >> n;
	for (int i = 1; i <= n; i ++) cin >> a[i];
	
	sum1[1] = a[1], sum1[2] = a[2];
	for (int i = 3; i <= n; i ++) {
		sum1[i] = sum1[i-2] + a[i];
	}
	sum2[n] = a[n], sum2[n-1] = a[n-1];
	for (int i = n-2; i >= 1; i --) {
		sum2[i] = sum2[i+2] + a[i];
	}
	
	int ans = max (sum1[n-1], sum1[n]);
	for (int i = 1; i+3 <= n; i += 2) {
		ans = max (ans, sum1[i] + sum2[i+3]);
	}
	
	if (n % 2 == 0) {
		cout << ans << endl;
	} else {
		int tmp = INF;
		for (int i = 1; i <= n; i += 2) tmp = min (tmp, a[i]);
		ans = max (ans, sum1[n]-tmp);
		
		for (int i = 2; i+3 <= n; i += 2) ans = max (ans, sum1[i] + sum2[i+3]);
		
		for (int i = n-3; i >= 2; i -= 2) sum3[i] = max (sum3[i+2], sum2[i+3]) + a[i];
		for (int i = 1; i+6 <= n; i += 2) ans = max (ans, sum1[i] + sum3[i+3]);
		
		cout << ans << endl;
	}
	
	return 0;
}

Compiler output:
main.c:1:10: fatal error: bits/stdc++.h: No such file or directory
    1 | #include <bits/stdc++.h>
      |          ^~~~~~~~~~~~~~~
compilation terminated.
Language: C

#include<bits/stdc++.h>
using namespace std;
#define sqr(x) 1ll*x*(x+1)>>1ll
typedef long long ll;
int n,col[200100],sz[200100];
map<int,int>f[200100];
vector<int>v[200100],res[200100];
void dfs(int x,int fa){
	sz[x]=1;
	for(int y:v[x]){
		if(y==fa)continue;
		dfs(y,x),sz[x]+=sz[y];
		int cc=sz[y];
		if(f[y].find(col[x])!=f[y].end())cc-=f[y][col[x]];
		res[col[x]].push_back(cc);
		if(f[x].size()<f[y].size())swap(f[x],f[y]);
		for(auto i:f[y])f[x][i.first]+=i.second; 
	}
	f[x][col[x]]=sz[x];
}
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",&col[i]);
	for(int i=1,x,y;i<n;i++)scanf("%d%d",&x,&y),v[x].push_back(y),v[y].push_back(x);
	dfs(1,0);
	for(int i=1;i<=n;i++)res[i].push_back(n-f[1][i]);
	for(int i=1;i<=n;i++){
		ll ans=sqr(n);
		for(auto j:res[i])ans-=sqr(j);
		printf("%lld\n",ans);
	}
	return 0;
}

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

#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>
#include <assert.h>
#include <unordered_set>
#include <random>


using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e18;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(ll i = 0; i < n; i++)


















int main(){
    ll n;
    cin >> n;
    vector<ll> c(n);
    REP(i, n){
        cin >> c[i];
        c[i]--;
    }
    vector<vector<ll>> g(n);
    REP(i, n - 1){
        ll a, b;
        cin >> a >> b;
        a--; b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    vector<ll> a(n, n * (n + 1) / 2), d(n);
    ll s = 0;
    auto dfs = [&](auto &&dfs, ll now, ll par) -> void {
        ll tmp = s + d[c[now]];
        s++;
        for(auto &ch : g[now]){
            if(ch == par) continue;
            d[c[now]] = -s;
            dfs(dfs, ch, now);
            a[c[now]] -= (s + d[c[now]]) * (s + d[c[now]] + 1) / 2;
        }
        d[c[now]] = tmp - s;
    };
    dfs(dfs, 0, -1);
    REP(i, n){
        cout << a[i] - (s + d[i]) * (s + d[i] + 1) / 2 << endl;
    }
}

Compiler output:
main.c:1:10: fatal error: cstdio: No such file or directory
    1 | #include <cstdio>
      |          ^~~~~~~~
compilation terminated.
Language: C

#include<bits/stdc++.h>
#define fo(i,a,b) for((i)=(a);i<=(b);i++)
#define rfo(i,a,b) for((i)=(a);i>=(b);i--)
#define inrange(x,y,z) (((x)>=(y))&&((x)<=(z)))
#define ALL(vec) ((vec).begin(),(vec).end())
#define SOR(vec) sort(ALL(vec))
#define UNI(vec) (vec).erase(unique(ALL(vec)),(vec).end())
using namespace std;
int n,c[200100],sz[200100],uu,vv;
vector<int> ga[200100];
long long sum[200100],res[200100];
long long Magic(long long x){
	return x*(x+1LL)/2LL;
}
void dfs(int u,int p){
	int co=c[u];
	long long pre=sum[co];
	sz[u]=1;
	for(int v:ga[u]){
		if(v==p)
			continue;
		long long lst=sum[co];
		dfs(v,u);
		long long delta=sum[co]-lst;
		sz[u]+=sz[v];
		res[co]-=Magic(sz[v]-delta);
	}
	sum[co]=pre+sz[u];
}
int main(){
	#ifdef FILIN
		#ifndef LOCAL
			freopen(FILIN,"r",stdin);
			freopen(FILOUT,"w",stdout);
		#endif
	#endif
	ios::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>c[i];
		res[i]=Magic(n); 
	}
	for(int i=1;i<n;i++){
		cin>>uu>>vv;
		ga[uu].push_back(vv);
		ga[vv].push_back(uu);
	}
	dfs(1,0);
	for(int i=1;i<=n;i++){
		res[i]-=Magic(n-sum[i]);
		cout<<res[i]<<endl;
	}
	return 0;
}


Compiler output:
main.c:1:9: fatal error: bits/stdc++.h: No such file or directory
    1 | #include<bits/stdc++.h>
      |         ^~~~~~~~~~~~~~~
compilation terminated.