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

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define int ll
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(c) begin(c), end(c)
#define dump(x) cerr << __LINE__ << ":\t" #x " = " << x << endl

template <typename T>
struct rmq {
    static const int INF = std::numeric_limits<int>::max() / 2;
    int n;
    std::vector<pair<T, int>> dat;
    rmq(vector<int> a) : n(a.size()) {
        for (n = 1; n < (int)a.size(); n <<= 1);
        dat.resize(2 * n);
        a.resize(n, -INF);
        for (int i = n; i < n + n; ++i) {
            dat[i] = make_pair(a[i - n], i - n);
        }
        for (int i = n - 1; i >= 1; --i) {
            dat[i] = std::min(dat[i * 2], dat[i * 2 + 1]); // todo
        }
    }
    pair<T, int> query(int v, int w, int l, int r) const {
        if (r <= l || w == 0) return make_pair(INF, -1); // todo
        if (r - l == w) return dat[v];
        int m = w / 2;
        return std::min(
            query(v * 2, m, l, std::min(r, m)), // todo
            query(v * 2 + 1, m, std::max<int>(0, l - m), r - m)); // todo
    }
    void update(int i, const T &x) {
        dat[i + n].first = x;
        i += n;
        for (; i != 1; i /= 2) dat[i / 2] = std::min(dat[i], dat[i ^ 1]); // todo
    }
    pair<T, int> query(int l, int r) { return query(1, n, l, r); }
};

int n;
vector<int> a;

bool solve() {
    ll s = accumulate(all(a), 0LL);
    if (s % (n*(n + 1) / 2)) {
        return false;
    }
    int times = s / (n*(n + 1) / 2);
    if (times > 300000) {
        return (rand() + getpid()) % 2;
    }
    
    vector<int> diff(n);
    for (int i = 0; i < n; i++) {
        diff[i] = a[(i + 1) % n] - a[i];
    }

    int a0 = a[0];
    rmq<int> rm(diff);
    for (int i = 0; i < min<ll>(times, 300000); i++) {
        int val, k;
        tie(val, k) = rm.query(0, n);
        rm.update(k, val + n);
        a0 -= (n - k) % n;
        // dump(a0);
        if (a0 == 0) break;
    }
    for (int i = 0; i < n; i++) {
        if (rm.query(i, i + 1).first != times) {
            return false;
        }
    }
    return true;
}

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    while (cin >> n) {
        a.resize(n);
        for (int i = 0; i < n; i++) {
            cin >> a[i];
        }
        cout << (solve() ? "YES" : "NO") << endl;
    }
}

Compiler output:
/usr/bin/ld: /tmp/cccdBpRP.o: warning: relocation against `_ZN3rmqIxE3INFE' in read-only section `.text._ZNK3rmqIxE5queryExxxx[_ZNK3rmqIxE5queryExxxx]'
/usr/bin/ld: /tmp/cccdBpRP.o: in function `rmq<long long>::query(long long, long long, long long, long long) const':
a.cc:(.text._ZNK3rmqIxE5queryExxxx[_ZNK3rmqIxE5queryExxxx]+0x5a): undefined reference to `rmq<long long>::INF'
/usr/bin/ld: warning: creating DT_TEXTREL in a PIE
collect2: error: ld returned 1 exit status
Language: C++

#include <iostream>
#include <iterator>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int n;
	vector<int>a;
	
	cin >> n;
	
	for(int i = 0; i < n; ++i){
		int buf;
		cin >> buf;
		a.push_back(buf);
	}
	
	while(true){
		size_t max_index = distance(a.begin(), std::max_element(a.begin(), a.end()));
		for(int i = 1; i <= n; ++i){
			if(a[(max_index + i) % n] < 0){
				cout << "NO";
				goto END;
			}else if(a[(max_index + i) % n] == 0) {
				goto JUDGE;
			}else{
				a[(max_index + i) % n] -= i;
			}
		}
	}
JUDGE:
	bool z = false;
	for(int i = 0; i < n; ++i){
		if(a[i] != 0)z = true;
	}
	cout << (z ? "NO" : "YES");
END:
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:43:1: error: jump to label 'END'
   43 | END:
      | ^~~
a.cc:29:38: note:   from here
   29 |                                 goto END;
      |                                      ^~~
a.cc:38:14: note:   crosses initialization of 'bool z'
   38 |         bool z = false;
      |              ^
Language: Java

import java.util.*;
public class Main{
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
long sub=0l;
int t1;
int t2;
t1=sc.nextInt();
for(int i=0;i<n-1;i++){
t2=sc.nextInt();
sub+=(long)(t2-t1);
t1=t2;
}
)if(sub%(long)(2n-2)==0l){System.out.println("YES");}else{System.out.println("NO");}
}
}

Compiler output:
Main.java:15: error: illegal start of expression
)if(sub%(long)(2n-2)==0l){System.out.println("YES");}else{System.out.println("NO");}
^
Main.java:15: error: ')' expected
)if(sub%(long)(2n-2)==0l){System.out.println("YES");}else{System.out.println("NO");}
                ^
Main.java:15: error: not a statement
)if(sub%(long)(2n-2)==0l){System.out.println("YES");}else{System.out.println("NO");}
                 ^
Main.java:15: error: ';' expected
)if(sub%(long)(2n-2)==0l){System.out.println("YES");}else{System.out.println("NO");}
                   ^
Main.java:15: error: 'else' without 'if'
)if(sub%(long)(2n-2)==0l){System.out.println("YES");}else{System.out.println("NO");}
                                                     ^
5 errors
Language: Java

import java.util.*;
public class Main{
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
long sub=0l;
int t1;
int t2;
t1=sc.nextInt();
for(int i=0;i<n-1;i++){
t2=sc.nextInt();
sub+=(long)(t2-t1);
t1=t2;
}
if(sub%(long)(2n-2)==0l){System.out.println("YES");}else{System.out.println("NO");}
}
}

Compiler output:
Main.java:15: error: ')' expected
if(sub%(long)(2n-2)==0l){System.out.println("YES");}else{System.out.println("NO");}
               ^
Main.java:15: error: not a statement
if(sub%(long)(2n-2)==0l){System.out.println("YES");}else{System.out.println("NO");}
                ^
Main.java:15: error: ';' expected
if(sub%(long)(2n-2)==0l){System.out.println("YES");}else{System.out.println("NO");}
                  ^
Main.java:15: error: 'else' without 'if'
if(sub%(long)(2n-2)==0l){System.out.println("YES");}else{System.out.println("NO");}
                                                    ^
4 errors
Language: C++

#include<iostream>
#include<vector>
#include<algorithm>


using namespace std;

bool canberemoved(vector<int>& A, int N) {
  int sum = 0;
  sum = A[0] - A[N];
  for (int i =0; i < N-1) {
    sum += A[i+1] - A[i];
  }
  return sum == 0;
}

int main() {
  int N;
  int x;
  vector<int> A;
  cin >> N;
  for (int i=0; i< N; i++) {
    cin >> x;
    A.push_back(x);
  }

  if (canberemoved(A, N)) {
    cout << "YES" <<endl;
  }
  else {
    cout << "NO" << endl;
  }

}


Compiler output:
a.cc: In function 'bool canberemoved(std::vector<int>&, int)':
a.cc:11:25: error: expected ';' before ')' token
   11 |   for (int i =0; i < N-1) {
      |                         ^
      |                         ;
Language: C++

#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <algorithm>
#define int long long
#define MAX(a,b) ((a) > (b)) ? (a) : (b)
#define MIN(a,b) ((a) < (b)) ? (a) : (b)
using namespace std;

signed main()
{
	int n;
	cin >> n;
	int a[100000];
	int min = INT_MAX;
	int min_ind = -1;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
		if (a[i] < min)
		{
			min = a[i];
			min_ind = i;
		}
	}

	while(true)
	{
		int next_min = INT_MAX;
		int next_min_ind = -1;
		for (int i = 0; i < n; i++)
		{
			int ind = (i + min_ind) % n;
			a[ind] -= (i + 1);
			if (a[ind] < next_min)
			{
				next_min = a[ind];
				next_min_ind = ind;
			}
		}
		min = next_min;
		min_ind = next_min_ind;

		if (min < 0)
		{
			cout << "NO";
			return 0;
		}

		if (min == 0)
		{
			for (int i = 0; i < n; i++)
			{
				if (a[i] > 0)
				{
					cout << "NO";
					return 0;
				}
			}
			cout << "YES";
			return 0;
		}
	}
}


Compiler output:
a.cc: In function 'int main()':
a.cc:16:19: error: 'INT_MAX' was not declared in this scope
   16 |         int min = INT_MAX;
      |                   ^~~~~~~
a.cc:6:1: note: 'INT_MAX' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>'
    5 | #include <algorithm>
  +++ |+#include <climits>
    6 | #define int long long
Language: Java

import java.util.*;
public class Main{
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
long sub=0l;
int t1,t2;
t1=sc.nextInt();
for(int i=0;i<n-1;i++){
t2=sc.nextInt();
sub+=(long)(t2-t1);
t1=t2;
}
if(sub%(long)(2n-2)==0l){System.out.println("YES");}else{System.out.println("NO");}
}
}

Compiler output:
Main.java:14: error: ')' expected
if(sub%(long)(2n-2)==0l){System.out.println("YES");}else{System.out.println("NO");}
               ^
Main.java:14: error: not a statement
if(sub%(long)(2n-2)==0l){System.out.println("YES");}else{System.out.println("NO");}
                ^
Main.java:14: error: ';' expected
if(sub%(long)(2n-2)==0l){System.out.println("YES");}else{System.out.println("NO");}
                  ^
Main.java:14: error: 'else' without 'if'
if(sub%(long)(2n-2)==0l){System.out.println("YES");}else{System.out.println("NO");}
                                                    ^
4 errors
Language: C++

#include<bits/stdc++.h>

using namespace std;
const int maxn=1e5+100;
int a[maxn],mx=maxn-1,s,n;

int main()
{
  cin>>n;
  for(int i=0;i<n;i++)
    cin>>a[i];
  for(int i=0;i<n;i++)
    s+=a[i];
  if(s % ((n*(n+1))/2) )
    {
      cout<<"NO";
      return 0;
    }

Compiler output:
a.cc: In function 'int main()':
a.cc:18:6: error: expected '}' at end of input
   18 |     }
      |      ^
a.cc:8:1: note: to match this '{'
    8 | {
      | ^
Language: Java

import java.util.*;
public class Main{
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
long sub=0l;
int t1,t2;
t1=sc.nextInt();
for(int i=0;i<n-1;i++){
t2=sc.nextInt();
sub+=(long)(t2-t1);
t1=t2;
}
;
if(sub/(long)(2n-2)==(long)(sub/(long)(2n-2))){
System.out.println("YES");
}else{
System.out.println("NO");
}
}
}

Compiler output:
Main.java:15: error: ')' expected
if(sub/(long)(2n-2)==(long)(sub/(long)(2n-2))){
               ^
Main.java:15: error: not a statement
if(sub/(long)(2n-2)==(long)(sub/(long)(2n-2))){
                ^
Main.java:15: error: ';' expected
if(sub/(long)(2n-2)==(long)(sub/(long)(2n-2))){
                  ^
Main.java:15: error: not a statement
if(sub/(long)(2n-2)==(long)(sub/(long)(2n-2))){
                      ^
Main.java:15: error: ';' expected
if(sub/(long)(2n-2)==(long)(sub/(long)(2n-2))){
                          ^
Main.java:15: error: ')' expected
if(sub/(long)(2n-2)==(long)(sub/(long)(2n-2))){
                                        ^
Main.java:15: error: not a statement
if(sub/(long)(2n-2)==(long)(sub/(long)(2n-2))){
                               ^
Main.java:15: error: not a statement
if(sub/(long)(2n-2)==(long)(sub/(long)(2n-2))){
                                         ^
Main.java:15: error: ';' expected
if(sub/(long)(2n-2)==(long)(sub/(long)(2n-2))){
                                           ^
Main.java:17: error: 'else' without 'if'
}else{
 ^
10 errors
Language: Java

import java.util.*;
public class Main{
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
long sub=0l;
int t1,t2;
t1=sc.nextInt();
for(int i=0;i<n-1;i++){
t2=sc.nextInt();
sub+=(long)(t2-t1);
t1=t2;
}

if(sub/(long)(2n-2)==(long)(sub/(long)(2n-2))){
System.out.println("YES");
}else{
System.out.println("NO");
}
}
}

Compiler output:
Main.java:15: error: ')' expected
if(sub/(long)(2n-2)==(long)(sub/(long)(2n-2))){
               ^
Main.java:15: error: not a statement
if(sub/(long)(2n-2)==(long)(sub/(long)(2n-2))){
                ^
Main.java:15: error: ';' expected
if(sub/(long)(2n-2)==(long)(sub/(long)(2n-2))){
                  ^
Main.java:15: error: not a statement
if(sub/(long)(2n-2)==(long)(sub/(long)(2n-2))){
                      ^
Main.java:15: error: ';' expected
if(sub/(long)(2n-2)==(long)(sub/(long)(2n-2))){
                          ^
Main.java:15: error: ')' expected
if(sub/(long)(2n-2)==(long)(sub/(long)(2n-2))){
                                        ^
Main.java:15: error: not a statement
if(sub/(long)(2n-2)==(long)(sub/(long)(2n-2))){
                               ^
Main.java:15: error: not a statement
if(sub/(long)(2n-2)==(long)(sub/(long)(2n-2))){
                                         ^
Main.java:15: error: ';' expected
if(sub/(long)(2n-2)==(long)(sub/(long)(2n-2))){
                                           ^
Main.java:17: error: 'else' without 'if'
}else{
 ^
10 errors
Language: C++

#include <iostream>
#include <vector>
#include <numeric>

int main() {
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(nullptr);
  int n;
  std::cin >> n;
  std::vector<int> as(n), diffs(n);
  for (auto& i : as) std::cin >> i;
  std::adjacent_difference(std::begin(as), std::end(as), std::begin(diffs));
  bool ok = true;
  if (n == 1) {
    std::cout << (as.front() == 1 ? "YES" : "NO") << std::endl;
    return 0;
  }
  std::for_each(std::begin(diffs) + 1, std::end(diffs),
      [&, first = diffs[1]] (auto d) { 
        if ((d - first) % n) ok = false;
      });
  std::cout << (ok ? "YES" : "NO") << std::endl;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:18:8: error: 'for_each' is not a member of 'std'
   18 |   std::for_each(std::begin(diffs) + 1, std::end(diffs),
      |        ^~~~~~~~
Language: Java

import java.util.*;
public class Main{
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
long sub=0l;
int t1,t2;
t1=sc.nextInt();
for(int i=0;i<n-1;i++){
t2=sc.nextInt();
sub+=(long)(t2-t1);
t1=t2;
}
if(sub/(long)(2n-2)==(long)(sub/(long)(2n-2))){System.out.println("YES");}else{System.out.println("NO");}
}
}

Compiler output:
Main.java:14: error: ')' expected
if(sub/(long)(2n-2)==(long)(sub/(long)(2n-2))){System.out.println("YES");}else{System.out.println("NO");}
               ^
Main.java:14: error: not a statement
if(sub/(long)(2n-2)==(long)(sub/(long)(2n-2))){System.out.println("YES");}else{System.out.println("NO");}
                ^
Main.java:14: error: ';' expected
if(sub/(long)(2n-2)==(long)(sub/(long)(2n-2))){System.out.println("YES");}else{System.out.println("NO");}
                  ^
Main.java:14: error: not a statement
if(sub/(long)(2n-2)==(long)(sub/(long)(2n-2))){System.out.println("YES");}else{System.out.println("NO");}
                      ^
Main.java:14: error: ';' expected
if(sub/(long)(2n-2)==(long)(sub/(long)(2n-2))){System.out.println("YES");}else{System.out.println("NO");}
                          ^
Main.java:14: error: ')' expected
if(sub/(long)(2n-2)==(long)(sub/(long)(2n-2))){System.out.println("YES");}else{System.out.println("NO");}
                                        ^
Main.java:14: error: not a statement
if(sub/(long)(2n-2)==(long)(sub/(long)(2n-2))){System.out.println("YES");}else{System.out.println("NO");}
                               ^
Main.java:14: error: not a statement
if(sub/(long)(2n-2)==(long)(sub/(long)(2n-2))){System.out.println("YES");}else{System.out.println("NO");}
                                         ^
Main.java:14: error: ';' expected
if(sub/(long)(2n-2)==(long)(sub/(long)(2n-2))){System.out.println("YES");}else{System.out.println("NO");}
                                           ^
Main.java:14: error: 'else' without 'if'
if(sub/(long)(2n-2)==(long)(sub/(long)(2n-2))){System.out.println("YES");}else{System.out.println("NO");}
                                                                          ^
10 errors
Language: C++

#include<bits/stdc++.h>
 
using namespace std;
 
#define pb push_back
#define mp make_pair
#define F first
#define S second
 
#define fo(i, n) for(int i = 1; i <= n; ++i)
#define rep(i, a, b) for(int (i) = (a); (i) < (b); ++(i))
 
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
 
const int N = 200200;
const int mod = 1e9 + 7;
const ll INF = 1e18;
ll a[N],b[N],pref[N];
 
int main()
{
	ios::sync_with_stdio(0); cin.tie(0);
	int n;
	cin>>n;
	for(int i=1;i<=n;++i)
	{
		cin>>a[i];
		b[i]=i-a[i];
		pref[i]=pref[i-1]+a[i];
	}
	ll k=(n*1ll*(n+1)/2);
	if(pref[n]%k!=0)
		return cout<<"NO",0;
	ll x=pref[n]/k;
	a[n+1]=a[1];
	a[n+2]=a[2];
	ll cnt=0;
	for(int i=2;i<=n+2;++i)
	{
		ll y=a[i]-a[i-1];
		b[i]=y;
		if(i>2&&b[i]!=b[i-1])
		{                 
			if(abs(b[i]-b[i-1])%n!=0||abs(b[i]-b[i-1])%x!=0)
			{
				return cout<<"NO",0;
			}
		}
	}
	cout<<"YES"
	return 0;	
}

Compiler output:
a.cc: In function 'int main()':
a.cc:52:20: error: expected ';' before 'return'
   52 |         cout<<"YES"
      |                    ^
      |                    ;
   53 |         return 0;
      |         ~~~~~~
Language: C++

#include <iostream>
#include <unordered_map>
#define REP(i, a, n) for(int i = a; i <= n; i++)
using namespace std;

int main(void) {
  const int SIZE = 100001;
  int N, A[SIZE];
  cin >> N;
  REP(i, 1, N) cin >> A[i];

  int mod = N * (N + 1) / 2;
  int sum = 0;
  bool uniq = true;
  unordered_map<int, bool> map;
  REP(i, 1, N) {
    sum += A[i]; sum %= mod;
    if(map[A[i]]) {
      uniq = false;
      break;
    } else {
      map[A[i]] = true;
    }
  }

  bool diff = true;
  long mx= 0;
  REP(i, 1, N - 1) {
    mx = max(mx, abs(A[i] - A[i + 1]));
    if(abs(A[i] - A[i + 1]) > N) diff = false;
  }
  mx *= N;
  REP(i, 1, N) {
    if(A[i] > mx) diff = false;
  }

  cout << (uniq && sum == 0 && diff ? "YES" : "NO") << endl;

  return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:29:13: error: no matching function for call to 'max(long int&, int)'
   29 |     mx = max(mx, abs(A[i] - A[i + 1]));
      |          ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
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:1:
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:29:13: note:   deduced conflicting types for parameter 'const _Tp' ('long int' and 'int')
   29 |     mx = max(mx, abs(A[i] - A[i + 1]));
      |          ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 2 provided
Language: Java

import java.util.*;
public class Main{
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
long sub=0;
int t1,t2;
t1=sc.nextInt();
for(int i=0;i<n-1;i++){
t2=sc.nextInt();
sub+=(long)(t2-t1);
t1=t2;
}
if(sub/(long)(2n-2)==(long)(sub/(long)(2n-2))) System.out.println("YES"); else System.out.println("NO");
}
}

Compiler output:
Main.java:14: error: ')' expected
if(sub/(long)(2n-2)==(long)(sub/(long)(2n-2))) System.out.println("YES"); else System.out.println("NO");
               ^
Main.java:14: error: not a statement
if(sub/(long)(2n-2)==(long)(sub/(long)(2n-2))) System.out.println("YES"); else System.out.println("NO");
                ^
Main.java:14: error: ';' expected
if(sub/(long)(2n-2)==(long)(sub/(long)(2n-2))) System.out.println("YES"); else System.out.println("NO");
                  ^
Main.java:14: error: not a statement
if(sub/(long)(2n-2)==(long)(sub/(long)(2n-2))) System.out.println("YES"); else System.out.println("NO");
                      ^
Main.java:14: error: ';' expected
if(sub/(long)(2n-2)==(long)(sub/(long)(2n-2))) System.out.println("YES"); else System.out.println("NO");
                          ^
Main.java:14: error: ')' expected
if(sub/(long)(2n-2)==(long)(sub/(long)(2n-2))) System.out.println("YES"); else System.out.println("NO");
                                        ^
Main.java:14: error: not a statement
if(sub/(long)(2n-2)==(long)(sub/(long)(2n-2))) System.out.println("YES"); else System.out.println("NO");
                               ^
Main.java:14: error: not a statement
if(sub/(long)(2n-2)==(long)(sub/(long)(2n-2))) System.out.println("YES"); else System.out.println("NO");
                                         ^
Main.java:14: error: ';' expected
if(sub/(long)(2n-2)==(long)(sub/(long)(2n-2))) System.out.println("YES"); else System.out.println("NO");
                                           ^
Main.java:14: error: 'else' without 'if'
if(sub/(long)(2n-2)==(long)(sub/(long)(2n-2))) System.out.println("YES"); else System.out.println("NO");
                                                                          ^
10 errors
Language: Java

import java.util.*;
public class Main{
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
long sub=0;
int t1,t2;
t1=sc.nextInt();
for(int i=0;i<n-1;i++){
t2=sc.nextInt();
sub+=(long)(t2-t1);
t1=t2;
}
if(sub/(long)(2n-2)==(long)(sub/(long)(2n-2)))System.out.println("YES"); else System.out.println("NO");
}
}

Compiler output:
Main.java:14: error: ')' expected
if(sub/(long)(2n-2)==(long)(sub/(long)(2n-2)))System.out.println("YES"); else System.out.println("NO");
               ^
Main.java:14: error: not a statement
if(sub/(long)(2n-2)==(long)(sub/(long)(2n-2)))System.out.println("YES"); else System.out.println("NO");
                ^
Main.java:14: error: ';' expected
if(sub/(long)(2n-2)==(long)(sub/(long)(2n-2)))System.out.println("YES"); else System.out.println("NO");
                  ^
Main.java:14: error: not a statement
if(sub/(long)(2n-2)==(long)(sub/(long)(2n-2)))System.out.println("YES"); else System.out.println("NO");
                      ^
Main.java:14: error: ';' expected
if(sub/(long)(2n-2)==(long)(sub/(long)(2n-2)))System.out.println("YES"); else System.out.println("NO");
                          ^
Main.java:14: error: ')' expected
if(sub/(long)(2n-2)==(long)(sub/(long)(2n-2)))System.out.println("YES"); else System.out.println("NO");
                                        ^
Main.java:14: error: not a statement
if(sub/(long)(2n-2)==(long)(sub/(long)(2n-2)))System.out.println("YES"); else System.out.println("NO");
                               ^
Main.java:14: error: not a statement
if(sub/(long)(2n-2)==(long)(sub/(long)(2n-2)))System.out.println("YES"); else System.out.println("NO");
                                         ^
Main.java:14: error: ';' expected
if(sub/(long)(2n-2)==(long)(sub/(long)(2n-2)))System.out.println("YES"); else System.out.println("NO");
                                           ^
Main.java:14: error: 'else' without 'if'
if(sub/(long)(2n-2)==(long)(sub/(long)(2n-2)))System.out.println("YES"); else System.out.println("NO");
                                                                         ^
10 errors
Language: C++

#include <sstream>
#include <cstring>
#include <cstdio>
int main(void) {
	uint64_t n;
	std::cin >> n;
	uint64_t* a = new uint64_t[n];
	uint64_t sum;
	for (int i = 0; i < n; i++) {
		std::cin >> a[i];
		sum += a[i];
	}
	if (sum % (n * (n-1)) == 0) {
		std::cout << "YES" << std::endl;
	}
	else {
		std::cout << "NO" << std::endl;
	}
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:5:9: error: 'uint64_t' was not declared in this scope
    5 |         uint64_t n;
      |         ^~~~~~~~
a.cc:4:1: note: 'uint64_t' is defined in header '<cstdint>'; this is probably fixable by adding '#include <cstdint>'
    3 | #include <cstdio>
  +++ |+#include <cstdint>
    4 | int main(void) {
a.cc:6:14: error: 'cin' is not a member of 'std'
    6 |         std::cin >> n;
      |              ^~~
a.cc:4:1: note: 'std::cin' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
    3 | #include <cstdio>
  +++ |+#include <iostream>
    4 | int main(void) {
a.cc:6:21: error: 'n' was not declared in this scope
    6 |         std::cin >> n;
      |                     ^
a.cc:7:19: error: 'a' was not declared in this scope
    7 |         uint64_t* a = new uint64_t[n];
      |                   ^
a.cc:7:27: error: 'uint64_t' does not name a type
    7 |         uint64_t* a = new uint64_t[n];
      |                           ^~~~~~~~
a.cc:7:27: note: 'uint64_t' is defined in header '<cstdint>'; this is probably fixable by adding '#include <cstdint>'
a.cc:8:17: error: expected ';' before 'sum'
    8 |         uint64_t sum;
      |                 ^~~~
      |                 ;
a.cc:10:22: error: 'cin' is not a member of 'std'
   10 |                 std::cin >> a[i];
      |                      ^~~
a.cc:10:22: note: 'std::cin' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:11:17: error: 'sum' was not declared in this scope
   11 |                 sum += a[i];
      |                 ^~~
a.cc:13:13: error: 'sum' was not declared in this scope
   13 |         if (sum % (n * (n-1)) == 0) {
      |             ^~~
a.cc:14:22: error: 'cout' is not a member of 'std'
   14 |                 std::cout << "YES" << std::endl;
      |                      ^~~~
a.cc:14:22: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:17:22: error: 'cout' is not a member of 'std'
   17 |                 std::cout << "NO" << std::endl;
      |                      ^~~~
a.cc:17:22: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
Language: C++

#include <bits/stdc++.h>
using namespace std;
typedef long long               ll;
const int mod = 1e9+7;
#ifndef M_PI
#define M_PI acos(-1.0)
#endif

int main(){
	int n;
	cin>>n;
	vector<int> a(n);
	ll sum=0;
	for(int i=0; i<n; ++i){
		scanf("%d", &a[i]);
		sum += a[i];
	}
	if(sum % ((n+1)*n/2)){
		cout<<"NO\n";
		return 0;
	}
	ll cnt = sum/((n+1)*n/2);
	ll cn2 = 0;
	for(int i=0; i<n; ++i){
		ll diff = a[(i+1)%n] - a[i];
		if((diff-cnt) % n){
			cout<<"NO\n";
			return 0;
		}
		cnt2 -= (diff-cnt)/n
	}
	if(cnt != cnt2){
		cout<<"NO\n";
		return 0;
	}
	cout<<"YES\n";
	return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:30:17: error: 'cnt2' was not declared in this scope; did you mean 'cn2'?
   30 |                 cnt2 -= (diff-cnt)/n
      |                 ^~~~
      |                 cn2
a.cc:32:19: error: 'cnt2' was not declared in this scope; did you mean 'cn2'?
   32 |         if(cnt != cnt2){
      |                   ^~~~
      |                   cn2
Language: C++

//I_F_A
#include "bits/stdc++.h"
using namespace std;

bool func(long long *arr,long long n){

	long long ans = 0;
	for(long long i=1;i<=n;i++)
		if(arr[i] == i)
			ans++;

	if(ans == 0)
		return 1;
	for(long long i=1;i<=n;i++)
		if(arr[i] != 0)
			return 0;
	return 1;
}
int main(){

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);


	long long arr[n+1];
	for(long long i=1;i<=n;i++)
		cin >> arr[i];

	long long sum = 0;

	for(long long i=1;i<n;i++){

		if(arr[i] > arr[i-1]){

			sum = sum + n - i + 1;
		}
	}

	for(long long i=1;i<=n;i++){

		sum = sum%n;
		if(sum == 0)
			sum = n;
		arr[i] = arr[i] - sum;
		sum = sum + 1;
	}


	if(func(arr,n)){

		cout <<"YES\n";
	}
	else{

		cout << "NO\n";
	}
}

Compiler output:
a.cc: In function 'int main()':
a.cc:25:23: error: 'n' was not declared in this scope; did you mean 'yn'?
   25 |         long long arr[n+1];
      |                       ^
      |                       yn
a.cc:27:24: error: 'arr' was not declared in this scope
   27 |                 cin >> arr[i];
      |                        ^~~
a.cc:33:20: error: 'arr' was not declared in this scope
   33 |                 if(arr[i] > arr[i-1]){
      |                    ^~~
a.cc:44:17: error: 'arr' was not declared in this scope
   44 |                 arr[i] = arr[i] - sum;
      |                 ^~~
a.cc:49:17: error: 'arr' was not declared in this scope
   49 |         if(func(arr,n)){
      |                 ^~~
Language: Java


public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		sc.nextLine();
		int[] a = new int[n];
		boolean b = false;
		for (int i=0;i<n;i++){
			a[i] = sc.nextInt();
			if (a[i]>=n){
				b = true;
			}
		}
		if (b==true){
			System.out.println("YES");
		}
		else{
			System.out.println("NO");
		}
		
	}
}

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

#include<bits/stdc++.h>
#define MN 100005
struct edge{
	int to,nxt;
}e[MN<<1];
int n,a[MN],rt,l[MN],r[MN],du[MN],h[MN];
void ins(int x,int y) {
	static int cnt=0;
	du[x]++;
	e[++cnt].nxt=h[x];e[cnt].to=y;h[x]=cnt;
}
void dfs(int x,int f) {
	if(x!=rt&&du[x]==1) {
		l[x]=r[x]=a[x];
		return ;
	}
	int MI=0;
	for(int i=h[x];i;i=e[i].nxt)
		if(e[i].to!=f) {
			dfs(e[i].to,x);
			if(l[e[i].to]>=l[MI])  MI=e[i].to;
			r[x]+=r[e[i].to];
		}
	if(r[x]<a[x]||l[MI]>a[x]) {
		puts("NO");
		exit(0);
	}
	if(l[MI]>r[x]-r[MI]) l[x]=a[x]-l[MI];
	else l[x]=0;
	r[x]=a[x];
	if(x==rt&&l[x]) {
		puts("NO");
		exit(0);
	}
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	for(int i=1;i<n;i++) {
		int x,y;
		scanf("%d%d",&x,&y);
		ins(x,y);ins(y,x);
	}
	for(int i=1;i<=n;i++) if(du[i]==1){rt=i;break;}
	dfs(rt,0\);
	puts("YES");
}

Compiler output:
a.cc:46:17: error: stray '\' in program
   46 |         dfs(rt,0\);
      |                 ^
Language: C++

#include <bits/stdc++.h>
#define f first
#define s second
using namespace std;
using ll = long long;
using ii = pair<int, int>;

ll A[100001];
vector<int> G[100001];

inline ll dfs(int u, int p) {
    if (G[u].size() == 1) return A[u];
    ll ret = 2*A[u], m = 0;
    for (int v : G[u]) if (v != p) {
        int x = dfs(v, u);
        ret -= x;
        m = max(x, m);
    }
    if (ret < 0 || ret > A[u] || m > A[u]) {
        cout << "NO";
        exit(0);
    }
    return ret;
}

int main() {
    if (fopen("in", "r")) freopen("in", "r", stdin), freopen("out", "w", stdout);
    ios_base::sync_with_stdio(0), cin.tie(0);

    int N; cin >> N;
    for (int u = 1; u <= N; ++u) cin >> A[u];
    for (int i = 1; i < N; ++i) {
        int a, b; cin >> a >> b;
        G[a].push_back(b), G[b].push_back(a);
    }

    if (N == 2) {
        cout << (A[1] == A[2] ? "YES" : "NO");
        return 0;
    }

    int s = 1;
    while (G[s].size() == 1) ++s;
    cout << (dfs(s, 0) ? "NO" : "YES");
    return 0;
}

Compiler output:
a.cc: In function 'll dfs(int, int)':
a.cc:17:16: error: no matching function for call to 'max(int&, ll&)'
   17 |         m = max(x, m);
      |             ~~~^~~~~~
In file included from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:17:16: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'll' {aka 'long long int'})
   17 |         m = max(x, m);
      |             ~~~^~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61:
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:17:16: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   17 |         m = max(x, m);
      |             ~~~^~~~~~
Language: C++

#pragma 03
#pragma GCC optimization ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.2,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
using namespace std;
#define ll long long
#define eb emplace_back
#define ef emplace_front
#define rep(i, x, n) for (int i = x; i < n; ++i)
#define mp make_pair
#define fi first
#define se second
#define ii pair<int, int>
#define endl '\n'
#define vi vector<int>
#define vii vector<pair<int, int>>
#define reverse(s) reverse(s.begin(), s.end())
#define ld long double
#define vs vector<string>
#define inf INT_MAX
#define vc vector<char>
#define fastio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define vb vector<bool>
#define lb(a, x) lower_bound(a.begin(), a.end(), x)
#define ub(a, x) upper_bound(a.begin(), a.end(), x) 
#define vvi vector<vi>
#define mine(a) min_element(a.begin(),a.end())
#define maxe(a) max_element(a.begin(), a.end())
#define iota(a,i) iota(a.begin(),a.end(),i)
#define fileopen(filename) if (fopen(filename".INP", "r")) {freopen(filename".INP", "r", stdin);freopen(filename".OUT", "w", stdout);}
int n;
vi a, par;
vvi adj, son;
void dfs(int x, int p) {
    int sum = 0;
    bool d = 0;
    for (int i : adj[x]) {
        if (i != p) {
            d = 1;
            son[x].emplace_back(i);
            par[i] = x;
            dfs(i, x);
            sum += a[i];
        }
    }
    if (d == 1) {
        int u = sum - a[x], v = a[x] - u;
        if (u < 0 || v < 0) {
            cout << sum << " " << x << endl;
            cout << "NO";
            exit(0);
        }
        a[x] = v;
    }
}
signed main() {
    fastio;
    cin >> n;
    a.resize(n + 1);
    adj.resize(n + 1);
    son.resize(n + 1);
    par.resize(n + 1, -1);
    rep(i, 1, n + 1) cin >> a[i];
    rep(i, 0, n - 1) {
        int x, y;
        cin >> x >> y;
        adj[x].emplace_back(y);
        adj[y].emplace_back(x);
    }
    dfs(1, 1);
    cout << "YES";
}

Compiler output:
In file included from /usr/include/c++/14/string:43,
                 from /usr/include/c++/14/bitset:52,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:52,
                 from a.cc:5:
/usr/include/c++/14/bits/allocator.h: In destructor 'std::_Vector_base<int, std::allocator<int> >::_Vector_impl::~_Vector_impl()':
/usr/include/c++/14/bits/allocator.h:182:7: error: inlining failed in call to 'always_inline' 'std::allocator< <template-parameter-1-1> >::~allocator() noexcept [with _Tp = int]': target specific option mismatch
  182 |       ~allocator() _GLIBCXX_NOTHROW { }
      |       ^
In file included from /usr/include/c++/14/vector:66,
                 from /usr/include/c++/14/functional:64,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:53:
/usr/include/c++/14/bits/stl_vector.h:132:14: note: called from here
  132 |       struct _Vector_impl
      |              ^~~~~~~~~~~~
Language: C++

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

#define int long long
#define fi first
#define se second
#define pb push_back

typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef pair<ii, ii> iiii;

int n, A[100005];
vector<int> vc[100005];
bool ck = 1;

int dfs(int u, int p){
	int ans = 0;
	for(int i = 0; i < vc[u].size(); i++){
		int v = vc[u][i];
		if(v == p) continue;
		if(vc[v].size() == 1) ans += A[v];
		else{
			int tmp = 2 * A[v] - dfs(v, u);
			ck &= (tmp >= 0);
			ans += tmp;
		}
	}
	//cout << u << " " << ans << "\n";
	return ans;
	//sum_d[d[u]] += A[u];
}

signed main(){
	ios_base::sync_with_stdio(0);
	cin >> n;
	for(int i = 1; i <= n; i++) cin >> A[i];
	for(int i = 1; i < n; i++){
		int x, y;
		cin >> x >> y;
		vc[x].pb(y);
		vc[y].pb(x);
	}
	int root = 1;
	if(vc[1].size() == 1) root = vc[1][0];
	//cout << dfs(1, 1) << "\n";
	if(A[root] * 2 == dfs(root, root))) cout << "YES";
	else cout << "NO";
}


Compiler output:
a.cc: In function 'int main()':
a.cc:47:43: error: expected primary-expression before ')' token
   47 |         if(A[root] * 2 == dfs(root, root))) cout << "YES";
      |                                           ^
Language: C++

#include <iostream>
#include <vector>

#define int long long
#define MAXN 200000

int a[MAXN];
int n;
std::vector<int> Adj[MAXN];

int dfs(int u, int p = -1) {
  int ret = a[u];

  if(Adj[u].size() == 1 && p != -1)
    return ret;

  int sum = 0;
  int max = 0;
  for(int j : Adj[u]) {
    if(j == p)
      continue;

    int next = dfs(j, u);

    if(next == -1)
      return -1;

    sum += next;
    max = std::max(max, next);
  }

  ret = 2*a[u] - sum;

  if(ret < std::max(2*max - sum, 0))
    return -1;

  return ret;
}

signed main() {
  std::cin >> n;

  for(int i = 0; i < n; i++) 
    std::cin >> a[i];

  int root = 0;
  for(int i = 1; i < n; i++) {
    int u, v;
    std::cin >> u >> v;
    u--; v--;
    Adj[u].push_back(v);
    Adj[v].push_back(u);

    if(Adj[u].size() > 1)
      root = u;
    if(Adj[v].size() > 1)
      root = v;
  }

  if(dfs(root) == 0 || (n = 2 && a[0] == a[1]))
    std::cout << "YES";
  else
    std::cout << "NO";

  std::cout << std::endl;

  return 0;
}


Compiler output:
a.cc: In function 'long long int dfs(long long int, long long int)':
a.cc:34:20: error: no matching function for call to 'max(long long int, int)'
   34 |   if(ret < std::max(2*max - sum, 0))
      |            ~~~~~~~~^~~~~~~~~~~~~~~~
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:1:
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:34:20: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   34 |   if(ret < std::max(2*max - sum, 0))
      |            ~~~~~~~~^~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 2 provided
Language: C++

#include <bits/stdc++.h>

template <typename T> inline void rd(T& x) {
	int si = 1; char c = getchar(); x = 0;
	while(!isdigit(c)) si = c == '-' ? -1 : si, c = getchar();
	while(isdigit(c)) x = x * 10 + c - 48, c = getchar();
	x *= si;
}
template <typename T, typename... Args>
inline void rd(T& x, Args&... args) { rd(x); rd(args...); }

#define fi first
#define se second

typedef long long ll;
typedef double ff;
typedef std::pair<int, int> pii;

const int kN = 1e5 + 5;

int a[kN], dg[kN], fa[kN]; ll f[kN]; std::vector <int> E[kN];

void Dfs(int cur) {
	if(dg[cur] == 1) return;
	ll s = 0, mx = 0;
	for(auto x : E[cur])
		if(x != fa[cur]) {
			fa[x] = cur; Dfs(x); s += f[x];
			mx = std::max(mx, f[x]);
		}
	f[cur] = 2 * a[cur] - s;
	if(f[cur] < 0 || f[cur] > a[cur] || mx > a[u]) {
		printf("NO"); exit(0);
	}
}

int main() {
	int n; rd(n);
	for(int i = 1; i <= n; ++i) rd(a[i]);
	if(n == 2) { printf(a[1] == a[2] ? "YES" : "NO"); return 0; }
	for(int i = 1; i < n; ++i) {
		int u, v; rd(u, v);
		E[v].push_back(u);
		E[u].push_back(v);
		++dg[u]; ++dg[v];
	}
	int rt;
	for(int i = 1; i <= n; ++i) {
		if(dg[i] != 1) rt = i;
		else f[i] = a[i];
	}
	Dfs(rt);
	printf(!f[rt] ? "YES" : "NO");
	return 0;
}

Compiler output:
a.cc: In function 'void Dfs(int)':
a.cc:32:52: error: 'u' was not declared in this scope
   32 |         if(f[cur] < 0 || f[cur] > a[cur] || mx > a[u]) {
      |                                                    ^
Language: C++

#include <bits/stdc++.h>

template <typename T> inline void rd(T& x) {
	int si = 1; char c = getchar(); x = 0;
	while(!isdigit(c)) si = c == '-' ? -1 : si, c = getchar();
	while(isdigit(c)) x = x * 10 + c - 48, c = getchar();
	x *= si;
}
template <typename T, typename... Args>
inline void rd(T& x, Args&... args) { rd(x); rd(args...); }

#define fi first
#define se second

typedef long long ll;
typedef double ff;
typedef std::pair<int, int> pii;

const int kN = 1e5 + 5;

int a[kN], dg[kN], fa[kN]; ll f[kN]; std::vector <int> E[kN];

void Dfs(int cur) {
	if(dg[cur] == 1) return;
	ll s = 0;
	for(auto x : E[cur])
		if(x != fa[cur]) {
			fa[x] = cur; Dfs(x); s += f[x];
		}
	f[cur] = 2 * a[cur] - s;
	if(f[cur] < 0 || f[cur] > a[cur] || f[u] > s) {
		printf("NO"); exit(0);
	}
}

int main() {
	int n; rd(n);
	for(int i = 1; i <= n; ++i) rd(a[i]);
	if(n == 2) { printf(a[1] == a[2] ? "YES" : "NO"); return 0; }
	for(int i = 1; i < n; ++i) {
		int u, v; rd(u, v);
		E[v].push_back(u);
		E[u].push_back(v);
		++dg[u]; ++dg[v];
	}
	int rt;
	for(int i = 1; i <= n; ++i) {
		if(dg[i] != 1) rt = i;
		else f[i] = a[i];
	}
	Dfs(rt);
	printf(!f[rt] ? "YES" : "NO");
	return 0;
}

Compiler output:
a.cc: In function 'void Dfs(int)':
a.cc:31:47: error: 'u' was not declared in this scope
   31 |         if(f[cur] < 0 || f[cur] > a[cur] || f[u] > s) {
      |                                               ^
Language: C++

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i=0; i<(n); i++)
int n, a[100005], v, u, t;
bool out;
vector<int> G[100005];
ll dfs(int u, int p){
	if(G[u].size() == 1) return a[u];
	ll mxv = 0, ac = 0, ret;
	for(int nx: G[u]) if(nx != p){
		ll tmp = dfs(nx,u);
		ac += tmp;
		mxv = max(mxv, tmp);
	}
	ret = a[u] * 2 - ac;
	mxv = max(mxv, ret);
	if(ret < 0 || a[u] < mxv) out = true;
	return ret;
}
int main(){
	scanf("%d", &n);
	rep(i,n) scanf("%d", a+i);
	rep(i,n-1){
		scanf("%d%d", &v, &u);
		v--; u--;
		G[v].push_back(u);
		G[u].push_back(v);
	}
	if(n == 2){
		puts(a[0] == a[1] ? "YES" : "NO");
		return;
	}
	for(; G[t].size() == 1; t++);
	if(dfs(t,t) > 0 || out) puts("NO");
	else puts("YES");
}

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

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

static vector<long long> adj[100005];
static long long arr[100005];

long long dfs(long long u, long long p){
	if(adj[u].size() == 1) return arr[u];
	long long rope = 0;
	long long maxChildRope = 0;
	for(long long v : adj[u]){
		if(v == p) continue;
		long long childRope = dfs(v,u);
		rope += childRope;
		maxChildRope = max(maxChildRope, childRope);
	}

	long long connect = rope - arr[u];
	long long maxConnect = min(rope / 2, rope - childRope); 
	rope = rope - 2 * connect;
	if(connect < 0 || rope < 0 || connect > maxConnect){
		cout << "NO";
		exit(0);
	}
	return rope;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	long long n; cin >> n;
	for(long long i = 1;i <= n;i++) cin >> arr[i];
	for(long long i = 1;i < n;i++){
		long long a, b; cin >> a >> b;
		adj[a].push_back(b);
		adj[b].push_back(a);
	} 
	for(long long i = 1;i <= n;i++){
		if(adj[i].size() != 1){
			if(dfs(i,0) == 0) cout << "YES";
			else cout << "NO";
			return 0;
		}
	}
	if(arr[1] == arr[2]) cout << "YES";
	else cout << "NO";
}


Compiler output:
a.cc: In function 'long long int dfs(long long int, long long int)':
a.cc:19:53: error: 'childRope' was not declared in this scope; did you mean 'maxChildRope'?
   19 |         long long maxConnect = min(rope / 2, rope - childRope);
      |                                                     ^~~~~~~~~
      |                                                     maxChildRope
Language: C++

#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define ULL unsigned long long
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define pll pair<LL,LL>
#define x first
#define y second
#define pi acos(-1)
#define sqr(x) ((x)*(x))
#define pdd pair<double,double>
#define MEMS(x) memset(x,-1,sizeof(x))
#define MEM(x) memset(x,0,sizeof(x))
#define less Less
#define EPS 1e-4
#define arg ARG
#define cpdd const pdd
#define rank Rank
#define KK 500
#define MXN 200005
vector<int> v[100005];
LL val[100005];
LL Max[100005];
LL Min[100005];
int ok=1;
void dfs(int x,int f){
    if(v[x].size()==1&&f!=0){
        Max[x]=val[x];
        Min[x]=val[x]&1;
        return ;
    }
    vector<pll> tmp;
    for(auto it:v[x]){
        if(it!=f){
            dfs(it,x);
            tmp.pb(mp(Max[it],Min[it]));
        }
    }
   // printf("%d",x);
    sort(tmp.begin(),tmp.end());
    for(auto it:tmp){
        Max[x]+=it.x;
      //  printf(" %lld %lld",it.x,it.y);
    }
  //  printf("\n");
    if(tmp.back().y>Max[x]-tmp.back().x){
        Min[x]=max(tmp.back().y-(Max[x]-tmp.back().x),2*val[x]-Max[x]);
    }
    else{
        Min[x]=max(Max[x]&1,2*val[x]-Max[x]);
    }
   /* if(val[x]%2!=Max[x]%2){
        ok=0;
    }*/
    LL tot=0;
    for(auto it:tmp){
        tot+=Min[it];
    }
    if((tot+1)/2>val[x]){
        ok=0;
    }
    if(val[x]>Max[x]){
        ok=0;
    }
    Max[x]=val[x];
    if(tmp.size()==1){
        Min[x]=val[x];
    }
}
int main(){
    int n;
    scanf("%d",&n);
    for(int i = 1;i<=n;i++)
        scanf("%lld",&val[i]);
    for(int i = 1;i<n;i++){
        int x,y;
        scanf("%d %d",&x,&y);
        v[x].pb(y);
        v[y].pb(x);
    }
    if(n==2){
        if(val[1]%2==val[2]%2){
            printf("YES\n");
        }
        else{
            printf("NO\n");
        }
    }
    else{
        for(int i=1;i<=n;i++){
            if(v[i].size()!=1){
                dfs(i,0);
                if(Min[i]!=0){
                    ok=0;
                }
                break;
            }
        }
        int tot=0;
        for(int i = 1;i<=n;i++){
            if(v[i].size()==1){
                tot+=val[i];
            }
        }
        if(tot&1)ok=0;
        if(ok){
            printf("YES\n");
        }
        else{
            printf("NO\n");
        }
    }
}

Compiler output:
a.cc: In function 'void dfs(int, int)':
a.cc:59:17: error: no match for 'operator[]' (operand types are 'long long int [100005]' and 'std::pair<long long int, long long int>')
   59 |         tot+=Min[it];
      |                 ^