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

#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <cmath>
#include <set>
#include <algorithm>

typedef long long ll;
const ll MOD = 1e9 + 7;
const long long INF = 1LL<<60;
const double PI=3.14159265358979323846;
const int NMAX=100005;
using namespace std;

ll pow(ll a, ll b) {
  if (b == 0) {
    return 1;
  } else if (b % 2 == 0) {
    ll d = pow(a, b / 2);
    return (d * d) % MOD;
  } else {
    ll d = pow(a, b - 1);
    return (a * d) % MOD;
  }
}

int main(){
    int n;
    cin >> n;
    vector<ll> a(n+1);
    for(int i = 0; i <= n; i++){
        cin >> a[i];
    }

    if(a[0] == 1){
        if(n == 0){
            cout << 1 << endl;
        } else {
            cout << -1 << endl;
        }
        return 0;
    }

    if(a[n] == 0){
        cout << -1 << endl;
        return 0;
    }

    ll ans = 0;
    vector<ll> pos(n+1,0);
    ll calc = 1;
    for(int i = 0; i <= n; i++){
        ll diff = 0;
        if(i != 0){
            diff = pos[i-1]*2 - a[i];
            if(diff < 0  )
        }
        if(a[i] > calc || (i!=0 && (pos[i-1]*2 < a[i] || pos[i-1] == 0))){
            cout << -1 << endl;
            return 0;
        } else {
            if(i!=0){
                pos[i] = pos[i-1]*2-a[i];
                ans += a[i];
            } else {
                pos[i] = 1;
            }
        }
        if(calc < 1000000000){
            calc *= 2;
        }
    }

    pos[n] = a[n];
    for(int i = n-1; i >= 0; i--){
        pos[i] = min(pos[i+1],pos[i]);
        ans += pos[i];
        pos[i] += a[i];
    }

    cout << ans << endl;

    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:59:9: error: expected primary-expression before '}' token
   59 |         }
      |         ^
Language: C++

/*

Coded by peyha X

*/

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int NMAX = 1e5 + 2;
ll n, a[NMAX],k, n_min[NMAX], n_max[NMAX], ans = 0;
bool possible= true;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	cin >> n;
	
	for(int i = 0; i <= n; i++)
		cin >> a[i];
		
	
	ll noeud_min = 1, noeud_max = 1;
	
	for(int h = 0; h <= n; h++)
	{
		n_min[h] = noeud_min;
		n_max[h] = noeud_max;
		
		
		noeud_min = max(0, noeud_min - a[h]);
		noeud_max = 2 * (noeud_max - a[h]);
	}
	

	
	noeud_min = a[n];
	noeud_max = a[n];
	
	for(int h = n; h >= 0; h--)
	{
		if(h != n)
		{
			noeud_max = min(n_max[h], noeud_max + a[h]);
			noeud_min = max(n_min[h], (noeud_min + a[h] + 1) / 2);		
		}
		ans += noeud_max; 
		//cout << noeud_max << ' ' << noeud_min << ' ' << h << '\n';
		if(n_max[h] < noeud_min || noeud_max < n_min[h])
			possible = false;
			

	}
	
	if(possible)
		cout << ans << '\n';
	else
		cout << "-1\n";
	
}


Compiler output:
a.cc: In function 'int main()':
a.cc:35:32: error: no matching function for call to 'max(int, ll)'
   35 |                 noeud_min = max(0, noeud_min - a[h]);
      |                             ~~~^~~~~~~~~~~~~~~~~~~~~
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:7:
/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:35:32: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'll' {aka 'long long int'})
   35 |                 noeud_min = max(0, noeud_min - a[h]);
      |                             ~~~^~~~~~~~~~~~~~~~~~~~~
/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:35:32: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   35 |                 noeud_min = max(0, noeud_min - a[h]);
      |                             ~~~^~~~~~~~~~~~~~~~~~~~~
Language: C++

#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <set>
#include <queue>
#include <map>
#include <numeric>
#include <functional>
#include <math.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

#define INF ((int)1e9)
#define INFLL ((ll)1e18)
#define MOD (1000000007LL)


int main(int argc, const char * argv[]) {
    ios_base::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<int> A(N+1);
    vector<int> B(N+1, INT_MAX);
    for (int n = 0; n <= N; ++n) {
        cin >> A[n];
    }
    
    if (N == 0) {
        if (A[0] == 1) cout << 1 << endl;
        else cout << -1 << endl;
        return 0;
    }
    
    if (A[0] != 0) {
        cout << -1 << endl;
        return 0;
    }
    
    B[0] = 1;
    B[N] = 0;
    bool bUpdate = true;
    bool bImp = false;
    while (bUpdate) {
        bUpdate = false;
        
        for (int n = N; n > 0; --n) {
            int tmpB = A[n] + B[n];
            if (tmpB < B[n-1]) {
                B[n-1] = tmpB;
                bUpdate = true;
            }
        }
        
        for (int n = 0; n < N; ++n) {
            int tmpB = 2 * B[n] - A[n+1];
            if (tmpB < B[n+1]) {
                if (tmpB < 0) {
                    bImp = true;
                    break;
                }
                B[n+1] = tmpB;
                bUpdate = true;
            }
        }
    }
    
    if (bImp || B[0] == 0) {
        cout << -1 << endl;
        return 0;
    }
    
    int Res = 0;
    for (int n = 0; n <= N; ++n) {
        Res += A[n] + B[n];
    }
    cout << Res << endl;

    return 0;
}


Compiler output:
a.cc: In function 'int main(int, const char**)':
a.cc:30:24: error: 'INT_MAX' was not declared in this scope
   30 |     vector<int> B(N+1, INT_MAX);
      |                        ^~~~~~~
a.cc:13:1: note: 'INT_MAX' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>'
   12 | #include <math.h>
  +++ |+#include <climits>
   13 |
Language: C++

#include "bits/stdc++.h"
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll =long long;
using P =pair<int,int>;

int main(){
    int n;
    cin >> n;
    vector <ll> a(n+1);
    rep(i,n+1){
        cin >> a[i];
    }

    vector <ll> ma(n+2);
    ma[0]=1;
    ll ans;
    ans=0;
    rep(i,n+1){
        if((ma[i]-a[i])<=0 and i!=n){
            ans=-1;
            break;
        }
        
        ma[i+1]=(ma[i]-a[i])*2;
    }
    if(ma[n]<a[i]){
        ans=-1;
    }

    vector <ll> mi(n+1);
    mi[n]=a[n];
    rep(i,n){
        mi[n-i-1]=mi[n-i]+a[n-i-1];
    }

    //rep(i,n+1){
    //    cout << ma[i] << " " << mi[i] << endl;
   // }

    int k=0;
    ll ans2;
    ans2=0;
    rep(i,n+1){
        if(ma[i]>=mi[i]){
            k=1;
        }
        if(k==0){
            ans2+=ma[i];
        }
        else{
            ans2+=mi[i];
        }
    }
    
    if(ans==0){
    cout << ans2 << endl;
    }
    else{
        cout << -1 << endl;
    }
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:27:16: error: 'i' was not declared in this scope
   27 |     if(ma[n]<a[i]){
      |                ^
Language: C++

int main()
{
	cout << -1 << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:3:9: error: 'cout' was not declared in this scope
    3 |         cout << -1 << endl;
      |         ^~~~
a.cc:3:23: error: 'endl' was not declared in this scope
    3 |         cout << -1 << endl;
      |                       ^~~~
Language: C++

#include<cstdio>
#include<cstring>
#include<cmath>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<queue>

using namespace std;

using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int,int>;
using vll=vector<ll>;
using vvll=vector<vll>;
using vpii=vector<pii>;

#define PI 3.1415926535897932384626433832795


ll solve(int n, vi&a)
{
	ll s=accumulate(a.begin(), a.end(), 0);
	vll limit(n+1, s);

	ll b=1;
	for(int i=0;i<=n;i++)
	{
		if(b<a[i]) return -1;
		limit[i]=b;
		if(b>=s) break;
		b-=a[i];
		b*=2;
	}

	ll ret=0;
	ll c=0;
	for(int i=n;i>=0;i--)
	{
		c=min(limit[i], c+a[i]);
		ret+=c;
	}

	return ret;
}

int main(void)
{
	int n;
	while(scanf("%d", &n)==1)
	{
		vi a(n+1);

		for(int i=0;i<=n;i++) scanf("%d", &a[i]);

		printf("%lld\n", solve(n, a));
	}
	return 0;
}


Compiler output:
a.cc: In function 'll solve(int, vi&)':
a.cc:25:14: error: 'accumulate' was not declared in this scope
   25 |         ll s=accumulate(a.begin(), a.end(), 0);
      |              ^~~~~~~~~~
Language: C++

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
typedef long long ll;
typedef pair<int,int> pii;
ll INF = LLONG_MAX

int main(){
    ll n;
    cin>>n;
    vector<ll> a(n+1);
    vector<ll> lim(n+1);
    rep(i,n+1) cin>>a[i];
    lim[0]=1;
    REP(i,n){
        lim[i]=(min(INF/2,lim[i-1]-a[i-1]))*2; //深さiで許されるnodeの数
        if(lim[i]-a[i]<=0){
            cout<<-1<<endl;
            return 0;
        }

    }

    ll ans=0;
    ll t=0; //現状のあるランクのnode数
    for(int i=n;i>=0;i--){
        t=min(t,lim[i]-a[i]);
        t+=a[i];
        ans+=t;
    }

    cout<<ans<<endl;
    return 0;
}

Compiler output:
a.cc:9:1: error: expected ',' or ';' before 'int'
    9 | int main(){
      | ^~~
Language: C++

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<(n);i++)
typedef long long ll;

int main(){
    ll n; cin >>n;
    vector<ll> a(n+1);
    rep(i,n+1){
        cin >> a[i];
    }
    vector<ll> lft(n+1,0);
    lft[n]=a[n];
    for(int i=n-1;i>=0;i--){
        lft[i]=lft[i+1]+a[i];
        // cout << lft[i] << endl;
    }
    ll now=1;
    ll ans=1;
    if(a[0]>0 && lft[1]>0){
        cout << -1 << endl;
        return 0;
    }
    rep2(i,n+1){
        now=min(now*2,lft[i]);
        ans+=now;
        now-=a[i];
        //  cout << now << endl;
        if(now=<0 && lft[i+1]>0){
            cout << -1 << endl;
            return 0;
        }
    }
    cout << ans << endl;
    
}

Compiler output:
a.cc: In function 'int main()':
a.cc:30:16: error: expected primary-expression before '<' token
   30 |         if(now=<0 && lft[i+1]>0){
      |                ^
Language: C++

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

int main(){
  int n;
  cin >> n;
  vector<int> leaf(n+1);
  for(int i=0; i<n+1; ++i) cin >> leaf[i];
  vector<ll> rui(n+1);
  rui[n] = leaf[n];
  for(int i=n-1; i>=0; --i){
    rui[i] = rui[i+1] + (ll)leaf[i];
  }
  int tnpoint;
  ll maxroot=1;
  for(int i=0; i<n+1; ++i){
    if(maxroot >= rui[i]){
      tnpoint = i;
      break;
    }
    maxroot -= leaf[i];
    maxroot *= 2;
    if(i==n || mxroot<0){
      cout << -1 << endl;
      return 0;
    }
  }
  ll ans=0;
  ll notl = 1;
  for(int i=0; i<tnpoint; ++i){
    ans += notl;
    notl -= leaf[i];
    notl *= 2;
  }
  for(int i=tnpoint; i<n+1; ++i){
    ans += rui[i];
  }
  cout << ans << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:24:16: error: 'mxroot' was not declared in this scope; did you mean 'maxroot'?
   24 |     if(i==n || mxroot<0){
      |                ^~~~~~
      |                maxroot
Language: C++

n=int(input())
l=list(map(int, input().split()))
power=[1]
for i in range(n+1):
    power.append(power[-1]*2)


imsi=0   
for i in range(n+1):
    imsi+=l[i]*power[n-i]


if(imsi<=power[n]):
    sum=0
    for i in range(n+1):
        sum+=l[i]
    yuksum=[sum]
    for i in range(n+1):
        yuksum.append(yuksum[-1]-l[i])

    x=1
    parent=1
    for i in range(n+1):
        if i==0:
            pass
        else:
            if (2*parent-l[i])>yuksum[i+1]:
                x+=yuksum[i+1]+l[i]
                parent=yuksum[i+1]
            else:
                x+=2*parent
                parent=2*parent-l[i]
    print(x)
else:
    print("-1")

Compiler output:
a.cc:1:1: error: 'n' does not name a type
    1 | n=int(input())
      | ^
Language: C++

N=int(input())
A = list(map(int,input().split()))

ok = True
max_l =[1-A[0]]

for i in range(1,N+1):
    max_l.append(min(max_l[i-1] * 2 - A[i], 1e10))
    if max_l[i] < 0 :
        ok=False

ans = A[N]
now = A[N]

for i in reversed(range(N)):
    now_l = min(now,max_l[i])
    now = now_l + A[i]
    ans += now

if ok == False:
    print(-1)
else:
    print(ans)


Compiler output:
a.cc:1:1: error: 'N' does not name a type
    1 | N=int(input())
      | ^
Language: C++

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

long long MAXXX = 1000000000000000;

int main() {
  long long N;
  cin >> N;
  
  vector<long long> A(N+1),Bmin(N),Bmax(N),ans(N+1);
  
  for (int i=0; i<N+1; i++) {
    cin >> A[i];
  }
  
  if (N == 0) {
    if (A[0] == 1) {
      cout << 1 << endl;
    }
    else {
      cout << -1 << endl;
    }
    return 0;
  }
  
  ans[0] = 1;
  ans[N] = 0;
  Bmin[0] = 1;
  Bmax[0] = 1;
  
  if (A[0] != 0) {
    cout << -1 << endl;
    return 0;
  }
  
  for (int i=1; i<N; i++) {
    Bmax[i] = Bmax[i-1] * 2ll - A[i];
    Bmax[i] = min(Bmax[i],MAXXX)
    if (Bmax[i] < 0) {
      cout << -1 << endl;
      return 0;
    }
    Bmin[i] = max(0ll,Bmin[i-1] - A[i]);
  }
  
  Bmax[N-1] = min(Bmax[N-1],A[N]);
  Bmin[N-1] = max(Bmin[N-1],(A[N]+1ll) / 2ll);
  
  if (Bmin[N-1] > Bmax[N-1]) {
    cout << -1 << endl;
    return 0;
  }
  
  ans[N-1] = Bmax[N-1];
  
  for (int i=N-2; i>0; i--) {
    ans[i] = min(Bmax[i],ans[i+1] + A[i+1]);
  }
  
  long long kotae = 0;
  
  for (int i=0; i<N+1; i++) {
    kotae += ans[i];
    kotae += A[i];
  }
  
  cout << kotae << endl;
  
  
  return 0;
  
}

Compiler output:
a.cc: In function 'int main()':
a.cc:38:33: error: expected ';' before 'if'
   38 |     Bmax[i] = min(Bmax[i],MAXXX)
      |                                 ^
      |                                 ;
   39 |     if (Bmax[i] < 0) {
      |     ~~
Language: C++

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

int main(){
  int64_t N;
  cin >> N;
  int F=0;
  vector<int64_t> A(N+1);
  for(int64_t i=0; i<=N; i++){
    cin >> A.at(i);
  }
  vector<int64_t> Up(N+1);
  vector<int64_t> Down(N+1);
  Up.at(0)=1;
  for(int64_t i=1; i<=N; i++){
    if(Up.at(i-1)-A.at(i-1)>9223372036854775807/2){
      Up.at(i)=9223372036854775807;
    }
    else{
      Up.at(i)=(Up.at(i-1)-A.at(i-1))*2;
    }
  }
  Down.at(N)=A.at(N);
  for(int64_t i=N-1; i>=0; i--){
    else{
      Down.at(i)=Down.at(i+1)+A.at(i);
    }
  }
  int64_t Ans=0;
  int64_t M=0;
  if(A.at(0)!=0){
    cout << -1 << endl;
    goto finish;
  }
  for(int64_t i=0; i<=N; i++){
    M=min(Up.at(i), Down.at(i));
    if(A.at(i)>M){
      cout << -1 << endl;
      goto finish;
    }
    else{
      Ans+=M;
    }
  }
  if(N==0){
    cout << -1 << endl;
    goto finish;
  }
  if(F==0){
    cout << Ans << endl;
  }
  finish: N=0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:25:5: error: 'else' without a previous 'if'
   25 |     else{
      |     ^~~~
Language: C++

#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define rrep(i,x) for(ll i = (ll)(x)-1;0 <= i; i--)
#define reps(i,x) for(ll i = 1; i < (ll)(x)+1; i++)
#define rreps(i,x) for(ll i = (ll)(x); 1 <= i; i--)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
constexpr ll INF = numeric_limits<ll>::max()/4;
constexpr ll n_max = 2e5+10;
#define int ll

template <typename A, typename B>
string to_string(pair<A, B> p);
string to_string(const string &s) {return '"' + s + '"';}
string to_string(const char c) {return to_string((string) &c);}
string to_string(bool b) {return (b ? "true" : "false");}
template <size_t N>
string to_string(bitset<N> v){
    string res = "";
    for(size_t i = 0; i < N; i++) res += static_cast<char>('0' + v[i]);
    return res;
}
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;
}
template <typename A, typename B>
string to_string(pair<A, B> p){return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}

void debug_out() {cerr << endl;}
template<typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}

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

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

// 多倍長テンプレ
/* ---------------------- ここから ---------------------- */
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;
// 任意長整数型
using Bint = mp::cpp_int;
// 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする)
using Real = mp::number<mp::cpp_dec_float<1024>>;
/* ---------------------- ここまで ---------------------- */

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll n; cin >> n;
    vector<ll> v(n+1);
    rep(i,n+1) cin >> v[i];
    vector<Bint> node(n+1);
    node[0] = 1 - v[0];
    reps(i,n){
        node[i] = node[i-1] * 2 - v[i];
    }
    debug(node);
    if(node[n] < 0){
        cout << -1 << endl;
        return 0;
    }
    vector<Bint> rev(n+1);
    rev[n] = 0;
    rrep(i,n){
        rev[i] = min(node[i], (rev[i+1] + v[i+1]));
    }
    debug(rev);

    ll ans = 0;
    rep(i,n+1){
        ans += v[i] + rev[i];
    }
    // bool ok = true;
    // rep(i,n)ok &= rev[i] > 0;

    cout << ans << endl;
}

Compiler output:
a.cc:67:10: fatal error: boost/multiprecision/cpp_dec_float.hpp: No such file or directory
   67 | #include <boost/multiprecision/cpp_dec_float.hpp>
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
Language: C++

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i, a, b) for (int i = a; i < b; i++)
typedef pair<ll,ll> pi;
typedef vector<ll> vi;
ll n;
ll leave[100005];
ll answer = 0;
pi whyi[100005];
const ll INF = 1000000000;

ll power(ll a, ll b){
	if (b == 0) return 1;
	if (b == 1) return a;
	ll half = power(a, b/2);
	half *= half;
	if (b % 2) half *= a;
	return half;
}

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin >> n;
	REP(i, 0, n + 1){
		cin >> leave[i];
	}
	if (n == 0 && leave[0] == 1){
		cout << 1 << endl;
		return 0;
	} else if (n == 0){
		cout << -1 << endl;
		return 0;
	}
	for (int i = 0; i <= n; i++){
		if (i == 0){
			whyi[i] = make_pair(1, 1);
			continue;
		}
		
		whyi[i] = MP(max(whyi[i - 1].F - leave[i - 1], (ll)0), min(INF, 2*(whyi[i - 1].S - leave[i - 1])));
		if (whyi[i].S < leave[i]){
			cout << -1 << endl;
			return 0;
		}
		if (whi[i].F > leave[i]){
			cout << -1 << endl;
			return 0;
		}
	}
	ll node;
	for (int i = n; i >= 0; i--){
		if (i == n){
			answer += leave[i];
			node = leave[i];
			continue;
		}
		node += leave[i];
		node = min(node, whyi[i].S);
		answer += node;
	}
	cout << answer << endl;
	

}

Compiler output:
a.cc: In function 'int main()':
a.cc:51:21: error: 'whi' was not declared in this scope; did you mean 'whyi'?
   51 |                 if (whi[i].F > leave[i]){
      |                     ^~~
      |                     whyi
Language: C++

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

// macro
#define rep(i,n) for(i=0;i<n;i++)
#define ll long long
#define all(v) v.begin(), v.end()

// code starts
#define M_MAX 10000000000000

int main()
{
  int n;cin>>n;
  vector<int> a(n+1);
  int i,j;
  rep(i,n+1)cin>>a[i];
  bool ok=true;
  int left=1;
  vector<ll> marg(n+1);
  rep(i,n+1)
  {
    left-=a[i];
    if(left<0)
    {
      ok=false;
      break;
    }
    marg[i]=left;
    if(left>=M_MAX)
    {
      ok=true;
      for(j=i;j<=n;j++)
      {
        marg[j]=M_MAX;
      }
      break;
    }
    left*=2;
  }
  if(!ok)cout<<-1<<endl;
  else
  {
    ll ans=0;
    int kuki=0;
    for(i=n;i>=0;i--)
    {
      if(i!=0)
      {
        ans+=(kuki+a[i]);
        kuki=min(marg[i-1],kuki+a[i]);
      }
      else ans+=(a[i]+kuki);
    }
    cout<<ans<<endl;
  }
  
}


Compiler output:
a.cc: In function 'int main()':
a.cc:51:17: error: no matching function for call to 'min(__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type&, int)'
   51 |         kuki=min(marg[i-1],kuki+a[i]);
      |              ~~~^~~~~~~~~~~~~~~~~~~~~
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:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  233 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note:   template argument deduction/substitution failed:
a.cc:51:17: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   51 |         kuki=min(marg[i-1],kuki+a[i]);
      |              ~~~^~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  281 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:281: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:5686:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)'
 5686 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5686:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)'
 5696 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5696:5: note:   template argument deduction/substitution failed:
a.cc:51:17: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   51 |         kuki=min(marg[i-1],kuki+a[i]);
      |              ~~~^~~~~~~~~~~~~~~~~~~~~
Language: C

#include <bits/stdc++.h>

#define rep2(x,fr,to) for(int x=(fr);x<(to);x++)
#define rep(x,to) for(int x=0;x<(to);x++)
#define repr(x,fr,to) for(int x=(fr);x>=(to);x--)
#define all(c) c.begin(),c.end()
#define sz(v) (int)v.size()

using namespace std;
typedef int64_t ll; typedef vector<int> VI; typedef pair<int,int> pii;
typedef vector<ll> VL; const int MD = 1e9 + 7;
void dbg(){cerr<<"\n";} template <typename T,typename ...T2> void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }


int main()
{
	cin.tie(0); ios_base::sync_with_stdio(false);
	int n;
	cin >>n;
	VI a(n+1);
	rep(i, n+1) cin >>a[i];
	if(a[0]>0 && n>0){ puts("-1");return 0;}
	if(a[0]==1 && n==0) { puts("1");return 0;}
	
	VL mz(n+1), pz(n+1);
	mz[0]=1;
	rep(i, n){
		mz[i+1]=(mz[i] - a[i])*2;
	}
	ll cr=0;
	repr(i, n, 0){
		cr += a[i];
		pz[i] = cr;
	}
	//for(auto x :mz) cerr<<x<<" "; dbg();
	//for(auto x :pz) cerr<<x<<" "; dbg();
	ll ans = 0;
	rep(i, n+1){
		if(mz[i] < a[i]){puts("-1");return 0;}
		ans += min(pz[i], mz[i]);
	}
	cout << ans <<"\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>
using namespace std;
typedef long long ll;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef map<int,int> mii;
typedef map<ll,ll> mll;
typedef vector<pii> vii;
typedef vector<pll> vll;
#define fi first
#define se second
#define pi 3.141592653589793
#define mod 998244353
#define pb push_back
#define all(v) v.begin(),v.end()
#define tc int t;cin>>t;while(t--)
#define pqmax priority_queue<int>
#define pqmin priority_queue<int,vi,greater<int>>
#define fast_io ios_base::sync_with_stdio(0), cin.tie(NULL)
#define tc_g int tt;cin>>tt;for(int ti=1;ti<=tt;ti++)
#define case_g "Case #"<<ti<<": "
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_multiset;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef tree<int, int, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_map;

int main() {
	fast_io;
	int n;
	cin >> n;
	vl a(n + 1);
	for (int i = 0;i <= n;i++)
		cin >> a[i];
	vl l(n + 1);
	l[0] = 1 - a[0];
	for (int i = 1;i <= n;i++) {
		l[i] = l[i - 1] * 2 - a[i];
		if (l[i] < 0) {
			cout << "-1\n";
			return 0;
		}
	}
	vl r(n + 2, 0);
	unsigned ll ans = 0;
	for (int i = n;i >= 0;i--) {
		r[i] = min(r[i + 1], l[i]) + a[i];
		ans += r[i];
	}
	cout << ans << '\n';
}


Compiler output:
a.cc: In function 'int main()':
a.cc:49:21: error: expected initializer before 'ans'
   49 |         unsigned ll ans = 0;
      |                     ^~~
a.cc:52:17: error: 'ans' was not declared in this scope; did you mean 'abs'?
   52 |                 ans += r[i];
      |                 ^~~
      |                 abs
a.cc:54:17: error: 'ans' was not declared in this scope; did you mean 'abs'?
   54 |         cout << ans << '\n';
      |                 ^~~
      |                 abs
Language: C++

#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using ii=pair<ll,ll>;
using vi=vector<ll>;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define INF (ll)1e18
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define print(a); for(auto x:a)cout<<x<<" "; cout<<"\n";
#define mset(a); memset(a,0,sizeof(a));

int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
    ll n;cin>>n;
    ll arr[n+1];
    ll sum=0;
    bool state=0;
    for(int i=0;i<=n;i++){
        cin>>arr[i];
        sum+=arr[i];
        if(sum>pow(2,i))state=1;
    }
    if(state||arr[0]>0||arr[sz(arr)-1]==0){cout<<"-1\n";return 0;}
    ll cnt=1;
    ll an=1;
    for(int i=1;i<=n;i++){
        an=min(an*2,sum);
        cnt+=an;
        an-=arr[i];
        sum-=arr[i];
    }
    cout<<cnt<<"\n";
}


Compiler output:
a.cc: In function 'int main()':
a.cc:14:25: error: request for member 'size' in 'arr', which is of non-class type 'll [(n + 1)]' {aka 'long long int [(n + 1)]'}
   14 | #define sz(x) ((int)(x).size())
      |                         ^~~~
a.cc:29:29: note: in expansion of macro 'sz'
   29 |     if(state||arr[0]>0||arr[sz(arr)-1]==0){cout<<"-1\n";return 0;}
      |                             ^~
Language: C++

#pragma GCC optimize("Ofast")
#include<stdio.h>
#include<algorithm>
using namespace std;
long long d[100005];
int main(){
	long long i,n,ans=1;
	scanf("%lld",&n);
	for(i=0;i<=n;i++)
		scanf("%lld",&d[i]);
	assert(n);
	if(d[0]){
		if(d[0]==1&&!n)
			puts("1");
		else
			puts("-1");
		return 0;
	}
	if(!n){
		puts("0");
		return 0;
	}
	if(n==1){
		if(d[1]==1)
			puts("2");
		else if(d[1]==2)
			puts("3");
		else
			puts("-1");
		return 0;
	}
	long long now=1,prev;
	for(i=1;i<n;i++){
		if(d[i]>=2*now){
			puts("-1");
			return 0;
		}
		ans+=now*2;
		prev=now*2;
		now=now*2-d[i];
	}
	ans-=prev;
	ans+=d[i-1];
	if(d[i]>2*now){
		puts("-1");
		return 0;
	}
	printf("%lld\n",ans+d[i]+min(d[i],now));
}


Compiler output:
a.cc: In function 'int main()':
a.cc:11:9: error: 'assert' was not declared in this scope
   11 |         assert(n);
      |         ^~~~~~
a.cc:4:1: note: 'assert' is defined in header '<cassert>'; this is probably fixable by adding '#include <cassert>'
    3 | #include<algorithm>
  +++ |+#include <cassert>
    4 | using namespace std;
Language: C

/**
 * Dont raise your voice, improve your argument.
 * --Desmond Tutu
 */

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

const bool ready = [](){
    ios_base::sync_with_stdio(false); cin.tie(0);
    cout << fixed << setprecision(12);
    return true;
}();

const double PI = acos(-1);
using ll= long long;
#define int ll
#define fori(n) for(int i=0; i<int(n); i++)

#define cini(i) int i; cin>>i;
#define cins(s) string s; cin>>s;
#define cind(d) double d; cin>>d;
#define cinai(a,n) vi a(n); fori(n) { cin>>a[i]; }
#define cinas(s,n) vs s(n); fori(n) { cin>>s[i]; }
#define cinad(a,n) vd a(n); fori(n) { cin>>a[i]; }

using pii= pair<int, int>;
using pdd= pair<double, double>;
using vd= vector<double>;
using vb= vector<bool>;
using vi= vector<int>;
using vvi= vector<vi>;
using vs= vector<string>;

/* Every non leaf vertex has one or two childs.
 *
 * On each level there is a number of non-leaf vertex,
 * which determines the max number of vertex of next level.
 *
 * Count bottom up, since in last level there are no 
 * non-leaf nodes it is greedy.
 *
 * The possible number of non leaf vertex on a level is bounded
 * by the number of child vertex (min) and parent vertex (max).
 */
void solve() {
    cini(n);
    cinai(a,n+1);

    if(n==0) {
        if(a[0]==1)
            cout<<1<<endl;
        else
            cout<<-1<<endl;
        return;
    }

    if(a[0]!=0) {
        cout<<-1<<endl;
        return;
    }

    const int INF=1e9;
    vi amin(n+1);           // min number of nodes on level i
    vi amax(n+1, INF);      // max number of nodes on level i

    amin[0]=amax[0]=1;
    
    for(int i=1; i<=n; i++) {
        amax[i]=min(amax[i], (amax[i-1]-a[i-1])*2);
//cerr<<"p1 i="<<i<<" amax[i]="<<amax[i]<<endl;
    }

    bool imp=false;
    int ans=a[n];
    amax[n]=a[n];
//cerr<<"p2 i="<<n<<" amax[i]="<<amax[n]<<endl;
    for(int i=n-1; i>=0; i--) {
        amax[i]=min(amax[i], amax[i+1]+a[i]);
        ans+=amax[i];
        if(amax[i]<a[i])
            imp=true;
//cerr<<"p2 i="<<i<<" amax[i]="<<amax[i]<<endl;
    }

    if(imp)
        cout<<-1<<endl;
    else
        cout<<ans<<endl;
}

signed main() {
    solve();
}

// FIRST THINK, THEN CODE
// DO NOT JUMP BETWEEN PROBLEMS


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

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

int main(){
  int64_t N;
  cin >> N;
  if(N==0){
    cout << -1 << endl;
    goto finish;
  }
  vector<int64_t> A(N+1);
  for(int64_t i=0; i<=N; i++){
    cin >> A.at(i);
  }
  vector<int64_t> Up(N+1);
  vector<int64_t> Down(N+1);
  Up.at(0)=1;
  for(int64_t i=1; i<=N; i++){
    if(Up.at(i-1)-A.at(i-1)>9223372036854775807/2){
      Up.at(i)=9223372036854775807;
    }
    else{
      Up.at(i)=(Up.at(i-1)-A.at(i-1))*2;
    }
  }
  Down.at(N)=A.at(N);
  for(int64_t i=N-1; i>=0; i--){
    if(9223372036854775807-Down.at(i+1)<A.at(i)){
      Down.at(i)=9223372036854775807;
    }
    else{
      Down.at(i)=Down.at(i+1)+A.at(i);
    }
  }
  int64_t Ans=0;
  int64_t M=0;
  if(A.at(0)!=0){
    cout << -1 << endl;
    goto finish;
  }
  for(int64_t i=0; i<=N; i++){
    M=min(Up.at(i), Down.at(i));
    if(A.at(i)>M){
      cout << -1 << endl;
      goto finish;
    }
    else{
      Ans+=M;
    }
  }
  cout << Ans << endl;
  finish: N=0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:52:3: error: jump to label 'finish'
   52 |   finish: N=0;
      |   ^~~~~~
a.cc:9:10: note:   from here
    9 |     goto finish;
      |          ^~~~~~
a.cc:36:11: note:   crosses initialization of 'int64_t M'
   36 |   int64_t M=0;
      |           ^
a.cc:35:11: note:   crosses initialization of 'int64_t Ans'
   35 |   int64_t Ans=0;
      |           ^~~
a.cc:16:19: note:   crosses initialization of 'std::vector<long int> Down'
   16 |   vector<int64_t> Down(N+1);
      |                   ^~~~
a.cc:15:19: note:   crosses initialization of 'std::vector<long int> Up'
   15 |   vector<int64_t> Up(N+1);
      |                   ^~
a.cc:11:19: note:   crosses initialization of 'std::vector<long int> A'
   11 |   vector<int64_t> A(N+1);
      |                   ^
Language: C++

#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  cin >> n;
  
  long long a[n+1];
  for(int i=0; i<n+1; i++) {
    cin >> a[i];
  }
 
   num=1;
  int sum=0;
  while(num >= 0){
  for(int j=0; j<n+1; j++){
    sum = sum + num;
    num = 2*(num - a[j-1]);
  }
  }
  
  if(num < 0){
    cout << -1 << endl;
  }
  else{
    cout << sum << endl;
  }
  
  
}

Compiler output:
a.cc: In function 'int main()':
a.cc:13:4: error: 'num' was not declared in this scope; did you mean 'enum'?
   13 |    num=1;
      |    ^~~
      |    enum
Language: C++

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

int main(){
  int64_t N;
  cin >> N;
  if(N==0){
    cout << -1 << endl;
    goto finish;
  }
  vector<int64_t> A(N+1);
  for(int64_t i=0; i<=N; i++){
    cin >> A.at(i);
  }
  vector<int64_t> Up(N+1);
  vector<int64_t> Down(N+1);
  Up.at(0)=1;
  for(int64_t i=1; i<=N; i++){
    if(Up.at(i-1)-A.at(i-1)>9223372036854775807/2){
      Up.at(i)=9223372036854775807;
    }
    else{
      Up.at(i)=(Up.at(i-1)-A.at(i-1))*2;
    }
  }
  Down.at(N)=A.at(N);
  for(int64_t i=N-1; i>=0; i--){
    if(9223372036854775807-Down.at(i+1)<A.at(i)){
      Down.at(i)=9223372036854775807;
    }
    else{
      Down.at(i)=Down.at(i+1)+A.at(i);
    }
  }
  int64_t Ans=0;
  int64_t M=0;
  if(A.at(0)!=0){
    cout << -1 << endl;
    goto finish;
  }
  for(int64_t i=0; i<=N; i++){
    M=min(Up.at(i), Down.at(i));
    if(A.at(i)>M){
      cout << -1 << endl;
      goto finish;
    }
    else{
      Ans+=M;
    }
  }
  cout << Ans << endl;
  finish: Ans=0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:52:3: error: jump to label 'finish'
   52 |   finish: Ans=0;
      |   ^~~~~~
a.cc:9:10: note:   from here
    9 |     goto finish;
      |          ^~~~~~
a.cc:36:11: note:   crosses initialization of 'int64_t M'
   36 |   int64_t M=0;
      |           ^
a.cc:35:11: note:   crosses initialization of 'int64_t Ans'
   35 |   int64_t Ans=0;
      |           ^~~
a.cc:16:19: note:   crosses initialization of 'std::vector<long int> Down'
   16 |   vector<int64_t> Down(N+1);
      |                   ^~~~
a.cc:15:19: note:   crosses initialization of 'std::vector<long int> Up'
   15 |   vector<int64_t> Up(N+1);
      |                   ^~
a.cc:11:19: note:   crosses initialization of 'std::vector<long int> A'
   11 |   vector<int64_t> A(N+1);
      |                   ^
Language: C++

from collections import deque
import sys

def input(): return sys.stdin.readline().rstrip()


N = int(input())
v = list(map(int, input().split()))

ans, nd = 0, 0
lim = [1 for _ in range(N + 2)]
for i in range(N + 1) :
    lim[i+1] = (lim[i] - v[i]) * 2

for i in range(N, -1, -1):
    if (v[i] + nd > lim[i]):
        nd = (nd + 1) // 2
        if (v[i] + nd > lim[i]):
            print(-1)
            sys.exit(0)

    nd += v[i]
    ans += nd

print(ans)

Compiler output:
a.cc:1:1: error: 'from' does not name a type
    1 | from collections import deque
      | ^~~~
Language: C++

n = int(input())
a = list(map(int, input().split()))
r = 1
maxi = [0] * (n + 1)

ok = True

for i in range(n + 1):
    if r <= 0 or a[i] > r:
        ok = False
        break
    maxi[i] = r
    r = 2 * (r - a[i])

branches = a[n]
ans = a[n]
for i in range(n - 1, -1, -1):
    branches = min(branches + a[i], maxi[i])
    ans += branches

if not ok:
    ans = -1

print(ans)


Compiler output:
a.cc:1:1: error: 'n' does not name a type
    1 | n = int(input())
      | ^
Language: C++

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

typedef long long ll;
typedef unsigned long long ull;

int main()
{
    ll N;
    cin >> N;
    vector<ll> A(N+1);
    for(int i=0;i<N+1;i++){
        cin >> A[i];
    }
    if(A[0] > 0){
        cout << "-1" << endl;
        return 0;
    }
    vector<ll> n_available(N+1, 1);
    for(int i=1;i<N+1;i++){
        n_available[i] = 2 * n_available[i-1] - A[i];
        if(n_available[i] >= ((ll)1 << 62)) n_available[i] = ((ll)1 << 62));
        if(i < N && n_available[i] <= 0){
            cout << "-1" << endl;
            return 0;
        }
    }
    ll res = 0;
    ll n_occ = A.back();
    res += n_occ;
    for(int i=N-1; i>=0; i--){
        n_occ = min(n_occ, n_available[i]) + A[i];
        res += n_occ;
    }
    cout << res << endl;

    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:22:75: error: expected ';' before ')' token
   22 |         if(n_available[i] >= ((ll)1 << 62)) n_available[i] = ((ll)1 << 62));
      |                                                                           ^
      |                                                                           ;
Language: C++

#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,b=2;
  cin>>n;
  vector<int> a(n);
  for(int i=0;i<n;i++) cin>>a.at(i);
  int ans=1;
  if(a.at(0)!=0) ans=-1;
  else{
    for(int i=0;i<n;i++){
      if(a.at(i)<=b){
        ans+=b;
        b=2*(b-a.at(i));
      }
      else{
        ans=-1;
        break;
      }
    }
  }
  cout<<ans<<endl;
        
      
  }
}

Compiler output:
a.cc:26:1: error: expected declaration before '}' token
   26 | }
      | ^
Language: Java

import java.util.*;

public class Main{
	
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
  	int n=Integer.parseInt(sc.next()),f=0;
    long[] a=new long[n];
    long sum=0;
    for(int i=0;i<n;i++){
      a[i]=Long.parseLong(sc.next());
      if(a[i]>=Math.pow(2,i)){
        System.out.println(-1);
        f++;
        break;
    }
    if(f==0){
    }
  }
}


Compiler output:
Main.java:20: error: reached end of file while parsing
}
 ^
1 error
Language: Java

import java.util.*;

public class Main{
	
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
  	int n=Integer.parseInt(sc.next()),f=0;
    long[] a=new long[n];
    long sum=0;
    for(int i=0;i<n;i++){
      a[i]=Long.parseLong(sc.next());
      if(a[i]>=Math.pow(2,i)){
        System.out.println(-1);
        f++;
        break;
    }
    if(f==0){
      
  }
}


Compiler output:
Main.java:20: error: reached end of file while parsing
}
 ^
1 error
Language: C++

//https://atcoder.jp/contests/nomura2020/tasks/nomura2020_d
#include<bits\stdc++.h>
using namespace std;
#define nn 5008
#define mod 1000000007
#define int long long 
vector<int> v[nn];int n,pa[nn];
int unknown[nn];int og[nn];
int find(int x){
	if(pa[x]==x) return x;
	return pa[x]=find(pa[x]);	
}
void link(int x,int y){
	pa[find(x)]=find(y);
}
int qpow(int x,int y){
	int res=1;
	while(y){
		if(y&1) res=res*x%mod;
		x=x*x%mod;y=y/2;
	}
	return res;
}
void add(int&x,int y){
	x=(x+y)%mod;
}

int dp[nn],sze[nn],ans,f[nn];;
signed main(){
	f[0]=1;for(int i=1;i<nn;i++) f[i]=f[i-1]*i%mod;
	scanf("%lld",&n);for(int i=1;i<=n;i++) pa[i]=i;int uk=0;
	for(int i=1;i<=n;i++){
		int pp;scanf("%lld",&pp);
		if(pp==-1) og[i]=1,uk++;
		else link(pp,i);
	}
	for(int i=1;i<=n;i++) unknown[find(i)]+=og[i],sze[find(i)]++;
	for(int i=1;i<=n;i++) if(i==find(i) and !unknown[i]) ans+=qpow(n-1,uk),ans%=mod;
	vector<int> dope;
	for(int i=1;i<=n;i++) if(find(i)==i and unknown[i]) dope.push_back(sze[i]),add(ans,(sze[i]-1)*qpow(n-1,uk-1));
	
	
	dp[0]=1;for(int i=0;i<dope.size();i++) for(int j=nn-2;j>=0;j--) add(dp[j+1],dp[j]*dope[i]);
	
	for(int i=2;i<nn;i++) add(ans,dp[i]*f[i-1]%mod*qpow(n-1,uk-i));
			
		
	ans=qpow(n-1,uk)*n-ans;ans%=mod;ans+=mod;ans%=mod;cout<<ans;
	return 0;
} 

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


#include <iostream>
#include <vector>
#include <list>
#include <set>
#include <string>
#include <algorithm>

int main(int, char* [])
{
    size_t N;
    std::cin >> N;
    //if (N == 5000)
    //    throw "error";

    size_t sequenceCount = 0;
    for (size_t i = 1; i <= N; ++i)
    {
        int pi = 0;
        in >> pi;
        if (pi == -1)
            ++sequenceCount;
    }

    if (N == sequenceCount)
        throw "error";

    return 0;
}

Compiler output:
a.cc: In function 'int main(int, char**)':
a.cc:20:9: error: 'in' was not declared in this scope; did you mean 'i'?
   20 |         in >> pi;
      |         ^~
      |         i
Language: C++

#include <iostream>
 
using namespace std;

void gen_ys(int* ys, int n, unsigned long long result[])
{
  int ys2[5001], i=1;
  for ( ; i<=n; i++)
    ys2[i] = ys[i];
  
  for (i=1; i<=n; i++)
  {
    if (ys[i] == -1)
    {
      for (int j=1; j<=n; j++)
      {
        if (i != j)
        {
          ys2[i] = j;
          gen_ys(ys2, n);
        }
      }
      
      return;
    }
  }
  
  char rd[5001][5001] = {{0}};
  for (i=1; i<=n; i++)
  {
    if (rd[i][ys[i]] == 0)
    {
      *result = (*result + 1) % 1000000007;
      rd[i][ys[1]] = 1;
      rd[ys[1]][i] = 1;
    }
  }
}

int main()
{
  int n, ys[5001];
  unsigned long long result = 0;
  cin >> n;
  for (int i=1; i<=n; i++)
    cin >> ys[i];

  gen_ys(ys, n, &result);
  cout << result;
}

Compiler output:
a.cc: In function 'void gen_ys(int*, int, long long unsigned int*)':
a.cc:20:17: error: too few arguments to function 'void gen_ys(int*, int, long long unsigned int*)'
   20 |           gen_ys(ys2, n);
      |           ~~~~~~^~~~~~~~
a.cc:5:6: note: declared here
    5 | void gen_ys(int* ys, int n, unsigned long long result[])
      |      ^~~~~~
Language: C++

#include <iostream>
 
using namespace std;
 
long check(int rd[5001][5001], int f, int t, int n)
{
  if (rd[f][t] == 1)
    return 0;
  
  rd[f][t] = 1;
  rd[t][f] = 1;
  
  for (int i=1; i<=n; i++)
  {
    if (rd[i][f] == 1)
      rd[i][t] = 1;
    else if (rd[i][t] == 1)
      rd[i][f] = 1;
  }
  return 1;
}
 
long chk2(int rd[5001][5001], int j, unsigned long cnt, int n, int* ys)
{
  for (int i=j+1; i<=n; i++)
  {
    if (ys[i] == -1)
    {
      int ys2[5001], rd2[5001][5001];
      for (int k=1; k<=n; k++)
      {
        ys2[k] = ys[k];
        for (int l=1; l<=n; l++)
          rd2[k][l] = rd[k][l];
      }
      
      for (int k=1; k<=n; k++)
      {
        if (i == k)
          continue;
        
        ys2[i] = k;
        cnt += check(rd2, i, k, n);
        cnt += chk2(rd2, i, cnt, n, ys2);
      	cnt = cnt % 1000000007;
      }
    }
    
    return cnt;
  }
 
  return cnt;
}
 
int main()
{
  int n, ys[5001], rd[5001][5001];
  unsigned long cnt1 = 0;
  cin >> n;
  for (int i=1; i<=n; i++)
  {
    cin >> ys[i];
    if (ys[i] != -1)
    {
      cnt += check(rd, i, ys[i], n);
      cnt = cnt % 1000000007;
    }
  }
  
  cout << chk2(rd, 0, cnt, n, ys);
  return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:65:7: error: 'cnt' was not declared in this scope; did you mean 'cnt1'?
   65 |       cnt += check(rd, i, ys[i], n);
      |       ^~~
      |       cnt1
a.cc:70:23: error: 'cnt' was not declared in this scope; did you mean 'cnt1'?
   70 |   cout << chk2(rd, 0, cnt, n, ys);
      |                       ^~~
      |                       cnt1
Language: C++

#include <iostream>

using namespace std;

long check(int rd[5001][5001], int f, int t, int n)
{
  if (rd[f][t] == 1)
    return 0;
  
  rd[f][t] = 1;
  rd[t][f] = 1;
  
  for (int i=1; i<=n; i++)
  {
    if (rd[i][f] == 1)
      rd[i][t] = 1;
    else if (rd[i][t] == 1)
      rd[i][f] = 1;
  }
  return 1;
}

long chk2(int rd[5001][5001], int j, unsigned long cnt, int n, int* ys)
{
  for (int i=j+1; i<=n; i++)
  {
    if (ys[i] == -1)
    {
      int ys2[5001], rd2[5001][5001];
      for (int k=1; k<=n; k++)
      {
        ys2[k] = ys[k];
        for (int l=1; l<=n; l++)
          rd2[k][l] = rd[k][l];
      }
      
      for (int k=1; k<=n; k++)
      {
        if (i == k)
          continue;
        
        ys2[i] = k;
        cnt += check(rd2, i, k, n);
        cnt += chk2(rd2, i, cnt, n, ys2);
      	cnt = cnt % 1000000007;
      }
    }
    
    return cnt;
  }

  return cnt;
}

int main()
{
  int n, ys[5001], rd[5001][5001];
  unsigned long cnt1 = 0;
  cin >> n;
  for (int i=1; i<=n; i++)
  {
    cin >> ys[i];
    if (ys[i] != -1)
    {
      cnt += check(rd, i, ys[i]);
      cnt = cnt % 1000000007;
    }
  }
  
  cout << chk2(rd, 0, cnt, n, ys);
  return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:65:7: error: 'cnt' was not declared in this scope; did you mean 'cnt1'?
   65 |       cnt += check(rd, i, ys[i]);
      |       ^~~
      |       cnt1
a.cc:65:19: error: too few arguments to function 'long int check(int (*)[5001], int, int, int)'
   65 |       cnt += check(rd, i, ys[i]);
      |              ~~~~~^~~~~~~~~~~~~~
a.cc:5:6: note: declared here
    5 | long check(int rd[5001][5001], int f, int t, int n)
      |      ^~~~~
a.cc:70:23: error: 'cnt' was not declared in this scope; did you mean 'cnt1'?
   70 |   cout << chk2(rd, 0, cnt, n, ys);
      |                       ^~~
      |                       cnt1