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

#include<bits/stdc++.h>
using namespace std;
int n;
long long int a[305][305];
int count[305][305];
int main(){
    cin >> n;
    for(int i=0;i<n;i++)for(int j=0;j<n;j++)cin >> a[i][j];
    for (int k = 0; k < n; k++){       // 経由する頂点
        for (int i = 0; i < n; i++) {    // 始点
            for (int j = 0; j < n; j++) {  // 終点
                if(a[i][j]>a[i][k] + a[k][j]){
                    cout << -1;
                    return 0;
                }
                else if(a[i][j] < a[i][k] + a[k][j])count[i][j]++;
            }
        }
    }
    long long int ans=0;
    for (int i = 0; i < n; i++) {    // 始点
        for (int j = 0; j < n; j++) {  // 終点
            if(count[i][j]==n-2)ans+=a[i][j];
        }
    }
    cout << ans;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:16:53: error: reference to 'count' is ambiguous
   16 |                 else if(a[i][j] < a[i][k] + a[k][j])count[i][j]++;
      |                                                     ^~~~~
In file included from /usr/include/c++/14/algorithm:86,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/pstl/glue_algorithm_defs.h:101:1: note: candidates are: 'template<class _ExecutionPolicy, class _ForwardIterator, class _Tp> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, typename std::iterator_traits<_II>::difference_type> std::count(_ExecutionPolicy&&, _ForwardIterator, _ForwardIterator, const _Tp&)'
  101 | count(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, const _Tp& __value);
      | ^~~~~
In file included from /usr/include/c++/14/algorithm:61:
/usr/include/c++/14/bits/stl_algo.h:4025:5: note:                 'template<class _IIter, class _Tp> typename std::iterator_traits< <template-parameter-1-1> >::difference_type std::count(_IIter, _IIter, const _Tp&)'
 4025 |     count(_InputIterator __first, _InputIterator __last, const _Tp& __value)
      |     ^~~~~
a.cc:5:5: note:                 'int count [305][305]'
    5 | int count[305][305];
      |     ^~~~~
a.cc:23:16: error: reference to 'count' is ambiguous
   23 |             if(count[i][j]==n-2)ans+=a[i][j];
      |                ^~~~~
/usr/include/c++/14/pstl/glue_algorithm_defs.h:101:1: note: candidates are: 'template<class _ExecutionPolicy, class _ForwardIterator, class _Tp> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, typename std::iterator_traits<_II>::difference_type> std::count(_ExecutionPolicy&&, _ForwardIterator, _ForwardIterator, const _Tp&)'
  101 | count(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, const _Tp& __value);
      | ^~~~~
/usr/include/c++/14/bits/stl_algo.h:4025:5: note:                 'template<class _IIter, class _Tp> typename std::iterator_traits< <template-parameter-1-1> >::difference_type std::count(_IIter, _IIter, const _Tp&)'
 4025 |     count(_InputIterator __first, _InputIterator __last, const _Tp& __value)
      |     ^~~~~
a.cc:5:5: note:                 'int count [305][305]'
    5 | int count[305][305];
      |     ^~~~~
Language: C++

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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e12
typedef long long ll;

int N;
vector<vector<ll>> A(300, vector<ll>(300,INF));
vector<vector<ll>> dp(300, vector<ll>(300,INF));

int main() {
    cin >> N;

    REP(i,N){
        REP(j,N){
            cin >> A[i][j];
            dp[i][j] = A[i][j];
        }
    }

    ll dup = 0;
    REP(i,N){
        REP(j,N){
            REP(k,N){
                if (j==k || k==i || i==j) continue;
                if (dp[j][k] > dp[j][i] + dp[i][k]){
                    cout << -1 << endl;
                    return 0;
                }else if (dp[j][k] == dp[j][i] + dp[i][k]){
                    dup += dp[j][k];
                }
            }
        }
    }

    ll ans = 0;

     REP(i,N){
        REP(j,N){
            ans += dp[i][j];
    }
    cout << (ans - dup)/2 << endl;

    return 0;
}

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

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

#define ll long long
ll n,a[305][305];
int main()
{
    cin>>n;
    ll i,j;
    bool flag=false;
    for(i=1; i<=n; i++)
        for(j=1; j<=n; j++)
            scanf("%lld",&a[i][j]);
    ll ans=0;
for(i=1;i<=n;i++)
{
    for(j=1;j<=i;j++)
    {flag=false;
        for(int k=1;k<=n;k++)
        {
            if(a[i][j]>a[i][k]+a[k][j])
            {
                printf("-1\n");
                exit(0);
            }
            if(a[i][j]==a[i][k]+a[k][j]&&i!=k&&j!=k)
                {
                    flag=true;
                }
        }
        if(!flag)
                {ans+=a[i][j];
                }
    }
}
 cout<<ans<<"\n";
    return 0;
}


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


#include <iostream>
#include <algorithm>
#include<bits/stdc++.h>
using namespace std;
 
#define ll long long
ll n,a[305][305];
int main()
{
    cin>>n;
    ll i,j;
    bool flag=false;
    for(i=1; i<=n; i++)
        for(j=1; j<=n; j++)
            scanf("%lld",&a[i][j]);
    ll ans=0;
for(i=1;i<=n;i++)
{
    for(j=1;j<=i;j++)
    {flag=false;
        for(int k=1;k<=n;k++)
        {
            if(a[i][j]>a[i][k]+a[k][j])
            {
                printf("-1\n");
                exit(0);
            }
            if(a[i][j]==a[i][k]+a[k][j]&&i!=k&&j!=k)
                {
                    flag=true;
                }
        }
        if(!flag)
                {ans+=a[i][j];
                }
    }
}
cout<<ans<<"\n";
    return 0;
}

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

Select Code
#include <iostream>
#include <algorithm>
#include<bits/stdc++.h>
using namespace std;
 
#define ll long long
ll n,a[305][305];
int main()
{
    cin>>n;
    ll i,j;
    bool flag=false;
    for(i=1; i<=n; i++)
        for(j=1; j<=n; j++)
            scanf("%lld",&a[i][j]);
    ll ans=0;
for(i=1;i<=n;i++)
{
    for(j=1;j<=i;j++)
    {flag=false;
        for(int k=1;k<=n;k++)
        {
            if(a[i][j]>a[i][k]+a[k][j])
            {
                printf("-1\n");
                exit(0);
            }
            if(a[i][j]==a[i][k]+a[k][j]&&i!=k&&j!=k)
                {
                    flag=true;
                }
        }
        if(!flag)
                {ans+=a[i][j];
                }
    }
}
cout<<ans<<"\n";
    return 0;
}

Compiler output:
main.c:1:1: error: unknown type name 'Select'
    1 | Select Code
      | ^~~~~~
main.c:2:10: fatal error: iostream: No such file or directory
    2 | #include <iostream>
      |          ^~~~~~~~~~
compilation terminated.
Language: C

#include<iostream>
#include<cstdio>
#include<stdlib.h>
using namespace std;
#define ll long long
ll n,a[305][305];
int main()
{
    cin>>n;
    ll i,j;
    bool flag=false;
    for(i=1; i<=n; i++)
        for(j=1; j<=n; j++)
            scanf("%lld",&a[i][j]);
    ll ans=0;
    for(i=1; i<=n; i++)
    {
        for(j=1; j<=i; j++)
        {
            flag=false;
            for(int k=1; k<=n; k++)
            {
                if(a[i][j]>a[i][k]+a[k][j])
                {
                    printf("-1\n");
                    exit(0);
                }
                if(a[i][j]==a[i][k]+a[k][j]&&i!=k&&j!=k)
                    flag=true;
            }
            if(!flag)
                ans+=a[i][j];
        }
    }
    cout<<ans<<"\n";
    return 0;
}


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

#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll n,a[305][305];
int main()
{
    cin>>n;
    ll i,j;
    bool flag=false;
    for(i=1; i<=n; i++)
        for(j=1; j<=n; j++)
            scanf("%lld",&a[i][j]);
    ll ans=0;
    for(i=1; i<=n; i++)
    {
        for(j=1; j<=i; j++)
        {
            flag=false;
            for(int k=1; k<=n; k++)
            {
                if(a[i][j]>a[i][k]+a[k][j])
                {
                    printf("-1\n");
                    exit(0);
                }
                if(a[i][j]==a[i][k]+a[k][j]&&i!=k&&j!=k)
                    flag=true;
            }
            if(!flag)
                ans+=a[i][j];
        }
    }
    cout<<ans<<"\n";
    return 0;
}


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

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

#ifdef LOCAL
#define debug(var) cerr << #var << " = " << var << endl;
#else
#define debug(var)
#endif

void init() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
}

const int N = 321;
const int inf = 2e9;

long long a[N][N];
bool important[N][N];

void solve() {
	int n; scanf("%d", &n);
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < n; ++j) {
			scanf("%lld", a[i]+j);
			important[i][j] = 1;
		}
	}
	long long sum = 0;
	for (int k = 0; k < n; ++k) {
		for (int i = 0; i < n; ++i) {
			if (i == k) continue;
			for (int j = 0; j < n; ++j) {
				if (j == i || j == k) continue;
				if (a[i][j] > a[i][k]+a[k][j]) {
					printf("-1");
					return;
				}
				if (a[k][i] == a[k][j]+a[j][i]) important[k][i] = 0;
			}
			if (important[i][j]) sum += a[i][j];
		}
	}

	printf("%lld", sum/2);
}

int main() {
	init();
	int t = 1; //scanf("%d", &t);
	while (t--) {
		solve();
	}
	return 0;
}


Compiler output:
a.cc: In function 'void solve()':
a.cc:41:42: error: 'j' was not declared in this scope
   41 |                         if (important[i][j]) sum += a[i][j];
      |                                          ^
Language: C++

#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
#define Priq priority_queue<int,vi,greater<int>>
#define pb push_back
#define mp make_pair
#define INF (1ll<<60)
signed main(){
  int N; cin>>N;
  vii A(N,vi(N));
  rep(i,0,N){
    rep(j,0,N)
      cin>>A[i][j];
  }
  vii B(N,vi(N));
  int ans=0;
  rep(i,0,N){
    priority_queue<pii,vector<pii>,greater<pii>> Q;
    Q.push(mp(0,i));
    while(Q.size()>0){
      int X=Q.front().second,Y=Q.front().first;
      Q.pop();
      rep(j,0,N){
        if(j!=X){
        if(Y+A[X][j]==A[i][j]){
          B[i][j]++;
          Q.push(mp(Y+A[X][j],j));
        }
        else if(Y+A[X][j]<A[i][j]){
          cout<<-1<<endl;
          return 0;
        }
        }
      }
    }
  }
  rep(i,0,N){
    rep(j,0,N){
      if(B[i][j]==1)
        ans+=A[i][j];
    }
  }
  cout<<ans/2<<endl;
  return 0;
  }


Compiler output:
a.cc: In function 'int main()':
a.cc:32:15: error: 'class std::priority_queue<std::pair<long long int, long long int>, std::vector<std::pair<long long int, long long int> >, std::greater<std::pair<long long int, long long int> > >' has no member named 'front'
   32 |       int X=Q.front().second,Y=Q.front().first;
      |               ^~~~~
a.cc:36:12: error: 'Y' was not declared in this scope
   36 |         if(Y+A[X][j]==A[i][j]){
      |            ^
Language: C++

#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
#define Priq priority_queue<int,vi,greater<int>>
#define pb push_back
#define mp make_pair
#define INF (1ll<<60)
signed main(){
  int N; cin>>N;
  vii A(N,vi(N));
  rep(i,0,N){
    rep(j,0,N)
      cin>>A[i][j];
  }
  vii B(N,vi(N));
  rep(i,0,N){
    queue<pii> Q;
    Q.push(mp(0,i));
    while(Q.size()>0){
      int X=Q.front().second,Y=Q.front().first;
      Q.pop();
      rep(j,0,N){
        if(Y+A[X][j]==A[i][j]){
          B[i][j]++;
          Q.push(mp(Y+A[X][j],j));
        }
        else if(Y+A[X][j]<A[i][j]){
          cout<<-1<<endl;
          goto XYZ;
        }
      }
    }
  }
  int ans=0;
  rep(i,0,N){
    rep(j,0,N){
      if(B[i][j]==1)
        ans+=A[i][j];
    }
  }
  cout<<ans<<endl;
  XYZ:;
  }


Compiler output:
a.cc: In function 'int main()':
a.cc:53:3: error: jump to label 'XYZ'
   53 |   XYZ:;
      |   ^~~
a.cc:40:16: note:   from here
   40 |           goto XYZ;
      |                ^~~
a.cc:45:7: note:   crosses initialization of 'long long int ans'
   45 |   int ans=0;
      |       ^~~
Language: C++


typedef long long ll;
typedef pair<int, int> pii;
#define mp make_pair
 
const int N = 303;
int n;
ll a[N][N];
ll ans = 0;
 
int main()
{
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
 
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
		for (int j = 0; j < n; j++) {
			scanf("%lld", &a[i][j]);
		}
	for (int i = 0; i < n; i++)
		for (int j = 0; j < i; j++) {
			ll w = a[i][j] + 1;
			for (int k = 0; k < n; k++) {
				if (i == k || j == k) continue;
				w = min(w, a[i][k] + a[k][j]);
			}
			if (w < a[i][j]) {
				printf("-1\n");
				return 0;
			}
			if (w > a[i][j]) ans += a[i][j];
		}
	printf("%lld\n", ans);
 
	return 0;
}

Compiler output:
a.cc:3:9: error: 'pair' does not name a type
    3 | typedef pair<int, int> pii;
      |         ^~~~
a.cc: In function 'int main()':
a.cc:16:9: error: 'scanf' was not declared in this scope
   16 |         scanf("%d", &n);
      |         ^~~~~
a.cc:26:37: error: 'min' was not declared in this scope; did you mean 'main'?
   26 |                                 w = min(w, a[i][k] + a[k][j]);
      |                                     ^~~
      |                                     main
a.cc:29:33: error: 'printf' was not declared in this scope
   29 |                                 printf("-1\n");
      |                                 ^~~~~~
a.cc:1:1: note: 'printf' is defined in header '<cstdio>'; this is probably fixable by adding '#include <cstdio>'
  +++ |+#include <cstdio>
    1 | 
a.cc:34:9: error: 'printf' was not declared in this scope
   34 |         printf("%lld\n", ans);
      |         ^~~~~~
a.cc:34:9: note: 'printf' is defined in header '<cstdio>'; this is probably fixable by adding '#include <cstdio>'
Language: C++

#include <bits/stdc++.h>
typedef long long ll;
int n;
ll a[311][311];
ll ans=0;
int main()
{
	cin >>n;
	for(int i=0;i<n;i++)
	for(int j=0;j<n;j++)
	cin >>a[i][j];
	for (int i=0;i<n;i++)
	for (int j=0;j<i;j++)
	{
		ll w=a[i][j]+1;
		for(int k=0;k<n;k++)
		{
			w = min(w, a[i][k] + a[k][j]);
		}
		if (w < a[i][j])
		{
			printf("-1\n");
			return 0;
		}
			if (w > a[i][j]) ans += a[i][j];
		}
	cout <<ans;
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:8:9: error: 'cin' was not declared in this scope; did you mean 'std::cin'?
    8 |         cin >>n;
      |         ^~~
      |         std::cin
In file included from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:146,
                 from a.cc:1:
/usr/include/c++/14/iostream:62:18: note: 'std::cin' declared here
   62 |   extern istream cin;           ///< Linked to standard input
      |                  ^~~
a.cc:18:29: error: 'min' was not declared in this scope; did you mean 'std::min'?
   18 |                         w = min(w, a[i][k] + a[k][j]);
      |                             ^~~
      |                             std::min
In file included from /usr/include/c++/14/algorithm:61,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51:
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: 'std::min' declared here
 5696 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
a.cc:27:9: error: 'cout' was not declared in this scope; did you mean 'std::cout'?
   27 |         cout <<ans;
      |         ^~~~
      |         std::cout
/usr/include/c++/14/iostream:63:18: note: 'std::cout' declared here
   63 |   extern ostream cout;          ///< Linked to standard output
      |                  ^~~~
Language: C++

#include <bits/stdc++.h>
typedef long long ll;
typedef pair<int, int> pii;
#define mp make_pair
const int N = 303;
int n;
ll a[N][N];
ll ans = 0;
 
int main()
{
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
 
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
		for (int j = 0; j < n; j++) {
			scanf("%lld", &a[i][j]);
		}
	for (int i = 0; i < n; i++)
		for (int j = 0; j < i; j++) {
			ll w = a[i][j] + 1;
			for (int k = 0; k < n; k++) {
				if (i == k || j == k) continue;
				w = min(w, a[i][k] + a[k][j]);
			}
			if (w < a[i][j]) {
				printf("-1\n");
				return 0;
			}
			if (w > a[i][j]) ans += a[i][j];
		}
	printf("%lld\n", ans);
 
	return 0;
}

Compiler output:
a.cc:3:9: error: 'pair' does not name a type
    3 | typedef pair<int, int> pii;
      |         ^~~~
a.cc: In function 'int main()':
a.cc:25:37: error: 'min' was not declared in this scope; did you mean 'std::min'?
   25 |                                 w = min(w, a[i][k] + a[k][j]);
      |                                     ^~~
      |                                     std::min
In file included from /usr/include/c++/14/algorithm:61,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: 'std::min' declared here
 5696 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
Language: C++

#pragma GCC optimize("Ofast",3,"inline")
#include<bits/stdc++.h>
using namespace std;
#define fir first
#define sec second
#define m_p make_pair
#define y1 ygftgfgcdtfgxffgx
#define y2 yfdsesgvtyghftfvv
#define x1 xvyr6cf6fgcfgf676
#define x2 xcr6rfc5r66y6r6fr
#define up_bound upper_bound
#define low_bound lower_bound
#define next_per next_permutation
#define pb push_back
#define i_to_s to_string
typedef priority_queue<int> p_queue;
typedef priority_queue<int, vector<int>, greater<int> > min_p_queue;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
ll gcd(ll x,ll y){return ((y==0)?x:gcd(y,x%y));}
int a[1000][1000];
bool vis[1000][1000];
int n;
ll res;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	cin>>n;
	for(int i=0;i<n;i++) for(int j=0;j<n;j++) cin>>a[i][j];
	ffor(int i=0;i<n;i++) for(int j=0;j<n;j++) if(k!=j&&k!=i&&i!=j){
        if(a[i][j]==a[i][k]+a[k][j]) vis[i][j]=1;
        if(a[i][j]>a[i][k]+a[k][j]){
            cout<<"-1"<<'\n';
            return 0;
        }
    }
    for(int i=0;i<n;i++)
    	for(int j=0;j<n;j++)
    		if(!vis[i][j])res+=a[i][j];
    cout<<res/2;
	return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:34:14: error: expected primary-expression before 'int'
   34 |         ffor(int i=0;i<n;i++) for(int j=0;j<n;j++) if(k!=j&&k!=i&&i!=j){
      |              ^~~
a.cc:34:22: error: 'i' was not declared in this scope
   34 |         ffor(int i=0;i<n;i++) for(int j=0;j<n;j++) if(k!=j&&k!=i&&i!=j){
      |                      ^
a.cc:34:43: error: 'j' was not declared in this scope
   34 |         ffor(int i=0;i<n;i++) for(int j=0;j<n;j++) if(k!=j&&k!=i&&i!=j){
      |                                           ^
Language: C++

#include<iostream>
#include<queue>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
using namespace std;
/****************************/
#define ll long long
#define vi vector<int>
#define pii pair<int,int>
#define vpii vector<pair<int,int> >
#define qi queue<int>
#define mii map<int,int>
#define msi map<string,int>
/****************************/
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep2(i,n) for(ll i=(n)-1;i>=0;i--)
#define rep3(i,a,n) for(ll i=(a);i<(n);i++)
#define mp make_pair
#define pb push_back
#define st first
#define nd second
#define pi 3.1415926535897932384626433832795
#define zero(n) memset(n,0,sizeof(n));
#define SZ(n) n.size()
#define ss st.st
#define sn st.nd
#define mod 100000007
#define INF 1e9
/****************************/
typedef long long ll;
typedef pair<int, int> pii;
#define mp make_pair
 
const int N = 303;
int n;
ll a[N][N];
ll ans = 0;
 
int main()
{
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
 
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
		for (int j = 0; j < n; j++) {
			scanf("%lld", &a[i][j]);
		}
	for (int i = 0; i < n; i++)
		for (int j = 0; j < i; j++) {
			ll w = a[i][j] + 1;
			for (int k = 0; k < n; k++) {
				if (i == k || j == k) continue;
				w = min(w, a[i][k] + a[k][j]);
			}
			if (w < a[i][j]) {
				printf("-1\n");
				return 0;
			}
			if (w > a[i][j]) ans += a[i][j];
		}
	printf("%lld\n", ans);
 
	return 0;
}

Compiler output:
a.cc:20:12: error: 'long long long' is too long for GCC
   20 | #define ll long long
      |            ^~~~
a.cc:43:19: note: in expansion of macro 'll'
   43 | typedef long long ll;
      |                   ^~
a.cc:20:17: error: 'long long long' is too long for GCC
   20 | #define ll long long
      |                 ^~~~
a.cc:43:19: note: in expansion of macro 'll'
   43 | typedef long long ll;
      |                   ^~
a.cc:20:17: error: declaration does not declare anything [-fpermissive]
   20 | #define ll long long
      |                 ^~~~
a.cc:43:19: note: in expansion of macro 'll'
   43 | typedef long long ll;
      |                   ^~
a.cc:44:27: error: invalid declarator before ';' token
   44 | typedef pair<int, int> pii;
      |                           ^
Language: C++

#include<iostream>
#include<cstring>
using namespace std;
int main(){

    long long int n,ans=0,i,j,k;
    cin>>n;
    long long int a[n+1][n+1];
    bool p[n+1][n+1];
    memset(p,0,sizeof(p));
    for(i=1;i<=n;i++)
        for(j=1;j<=n;j++)
            cin>>a[i][j];
    //读入数据以及初始化操作

    for(k=1;k<=n;k++)      
        for(i=1;i<=n;i++)
            for(j=1;j<=n;j++){
                if(k!=j&&k!=i&&i!=j){
                    if(a[i][j]==a[i][k]+a[k][j])
                        p[i][j]=1; 
                    if(a[i][j]>a[i][k]+a[k][j]){
                        cout<<"-1"<<endl;  
                        return 0;
                    }
                }
            }
    for(i=1;i<=n;i++)
        for(j=1;j<=n;j++)
            if(p[i][j]==0)
                ans+=a[i][j];
    cout<<ans/2<<endl；
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:32:18: error: 'endl\U0000ff1b' was not declared in this scope
   32 |     cout<<ans/2<<endl；
      |                  ^~~~~~
Language: C++

#include <bits/stdc++.h>
using namespace std;
const int maxn = 333;
long long f[maxn][maxn], g[maxn][maxn];
int main(){
  iota(u, u + maxn, 0);
  int n; cin >> n;
  for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) {
    cin >> f[i][j]; g[i][j] = f[i][j];
  }
  for(int k = 0; k < n; k++) for(int i = 0; i < n; i++) for(int j = 0; j < n; j++)
    g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
  bool good = true;
  for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) good &= f[i][j] == g[i][j];
  if(!good) cout << -1 << endl;
  else {
    long long ans = 0;
    for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) {
    	bool someone = false;
      	for(int k = 0; k < n; k++) if(k != i && k != j){
          if(f[i][k] + f[k][j] == f[i][j]) someone = true;
        }
      	if(!someone) ans += f[i][j];
    }
    cout << ans << endl;
  }
  return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:6:8: error: 'u' was not declared in this scope
    6 |   iota(u, u + maxn, 0);
      |        ^
Language: C++

#include <bits/stdc++.h>
using namespace std;
const int maxn = 333;
long long f[maxn][maxn], g[maxn][maxn];
int u[maxn];
int find(int x){
  if(x == u[x]) return x;
  return u[x] = find(u[x]);
}
int main(){
  iota(u, u + maxn, 0);
  int n; cin >> n;
  for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) {
    cin >> f[i][j]; g[i][j] = f[i][j];
  }
  for(int k = 0; k < n; k++) for(int i = 0; i < n; i++) for(int j = 0; j < n; j++)
    g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
  bool good = true;
  for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) ok &= f[i][j] == g[i][j];
  if(!good) cout << -1 << endl;
  else {
    vector<tuple<long long, int, int> > ed;
    for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) ed.push_back(make_tuple(f[i][j], i, j));
    sort(ed.begin(), ed.end());
    long long ans = 0;
    for(auto e : ed){
      long long w; int u,v; tie(w, u, v) = e;
      if(find(u) ^ find(v)){
      	u[find(u)] = find(v);
        ans += w;
      }
    }
    cout << ans << endl;
  }
  return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:19:57: error: 'ok' was not declared in this scope
   19 |   for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) ok &= f[i][j] == g[i][j];
      |                                                         ^~
a.cc:29:10: error: invalid types 'int[int]' for array subscript
   29 |         u[find(u)] = find(v);
      |          ^
Language: C++

#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define ull unsigned long long
#define vi vector<ll>
#define vvi vector<vi>
#define DBG_N(hoge) cerr<<"!"<<" "<<(hoge)<<endl;
#define DBG cerr<<"!"<<endl;
#define BITLE(n) (1LL<<((ll)n))
#define BITCNT(n) (__builtin_popcountll(n))
#define SUBS(s,f,t) ((s).substr((f)-1,(t)-(f)+1))
#define ALL(a) (a).begin(),(a).end()
using namespace std;
ll dist[1111][1111];
ll dist2[1111][1111];
bool used[1111][1111];
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n;cin>>n;
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      cin>>dist[i][j];
      dist2[i][j]=dist[i][j];
    }
  }
  for(int k=0;k<n;k++){
    for(int i=0;i<n;i++){
      for(int j=j+1;j<n;j++){
	dist2[i][j]=min(dist2[i][j],dist[i][k]+dist[k][j]);
	if(i!=k && j!=k)
	  if(dist[i][j] == dist[i][k]+dist[k][j])used[i][j]=true;
    }
  }
  bool fl=true;
  for(int i=0;i<n;i++)
    for(int j=0;j<n;j++)
      if(dist[i][j]!=dist2[i][j])fl=false;
  if(fl){
    ll ans=0;

    for(int i=0;i<n;i++)
      for(int j=i+1;j<n;j++)
	if(used[i][j]==false)
	  ans+=dist[i][j];
    cout<<ans<<endl;
  }else{
    cout<<-1<<endl;
  }
  return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:57:2: error: expected '}' at end of input
   57 | }
      |  ^
a.cc:23:11: note: to match this '{'
   23 | int main(){
      |           ^
Language: C++

def restoring_road_network(N: int, A: list)->int:
    total = 0
    for i in range(N):
        for j in range(i+1, N):
            ok = True
            for k in range(N):
                if i == k or k == j:
                    continue
                if A[i][k] + A[k][j] < A[i][j]:
                    return -1
                if A[i][k] + A[k][j] == A[i][j]:
                    ok = False
            if ok:
                total += A[i][j]

    return total


if __name__ == "__main__":
    N = int(input())
    A = [[int(s) for s in input().split()] for _ in range(N)]
    ans = restoring_road_network(N, A)
    print(ans)


Compiler output:
a.cc:1:1: error: 'def' does not name a type
    1 | def restoring_road_network(N: int, A: list)->int:
      | ^~~
Language: C++

#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#define mkp(a, b) make_pair(a, b)
#define ft first
#define sc second
#define pt(num) cout << num << "\n"
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define chmax(a, b) (a<b ? a=b : 0)
#define chmin(a, b) (a>b ? a=b : 0)
#define INF 1000000000000000000
#define MOD 1000000007LL
#define MAX 101010
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef map<ll, ll> Map;

ll N;
int main(void) {
    cin >> N;
    ll a[333][333];
    ll d[333][333];
    ll i, j, k;
    
    for(i=0; i<N; i++)
        for(j=0; j<N; j++) {
            cin >> a[i][j];
            d[i][j]=a[i][j];
        }
    
    for(k=0; k<N; k++) {
        for(i=0; i<N; i++) {
            for(j=0; j<N; j++) {
                if(k==i || k==j || i==j || d[i][k]==INF || d[k][j]) continue;
                if(d[i][k]+d[k][j]==a[i][j]) d[i][j]=INF;
                else if(d[i][k]+d[k][j]<a[i][j]) {
                    pt(-1);
                    return 0;
                }
        }
    }
    ll ans=0;
    for(i=0; i<N; i++)
        for(j=0; j<N; j++)
            if(d[i][j]!=INF) ans+=d[i][j];
    
    pt(ans/2);
    
    
}

























Compiler output:
a.cc: In function 'int main()':
a.cc:63:2: error: expected '}' at end of input
   63 | }
      |  ^
a.cc:32:16: note: to match this '{'
   32 | int main(void) {
      |                ^
Language: C++

G=[]
for _ in range(n):
    tmp=list(map(int,input().split()))
    G.append(tmp)

Dij=Dijkstra()
for i in range(n):
    result=Dij.dijkstra(G,i)
    dis=result[0]
    pre=result[1]
    for j in range(n):
        if(dis[j] < G[i][j]):
            print(-1)
            sys.exit()
        if(dis[j] == G[i][j] and pre[j]!=i):
            G[i][j]=float("inf")

ans=0
for i in range(n):
    for j in range(n):
        if(G[i][j]!=float("inf")):
            ans+=G[i][j]
print(ans//2)

Compiler output:
a.cc:1:1: error: 'G' does not name a type
    1 | G=[]
      | ^
Language: C++

#include <iostream>
#include<bits/stdc++.h>
using namespace std;
long long int a[1000][1000],b[1000][1000],c[1000][1000];//d[200000],b[200000];
//char x[1050][150],y[100050][20];

int main()
{
    long long int i,n,m,j,k,x,y;
    long long  int sum=0;
    scanf("%lld",&n);
    //memset(b,1,sizeof(b));
    for(i=1; i<=n; i++)
    {
        for(j=1; j<=n; j++)
        {
            scanf("%lld",&a[i][j]);

        }
    }

    for(k=1;k<=n;k++)
    {
        for(i=1;i<=n;i++)
        {
            for(j=1;j<=n;j++)
            {
                b[i][j]=min(a[i][j],a[i][k]+a[k][j]);
                if((a[i][j]>=a[i][k]+a[k][j])&&(i!=k&&j!=k))
                {
                    c[i][j]=1;
                }
            }
        }
    }
    int f=0;
    for(i=1;i<=n;i++)
    {
        for(j=i+1;j<=n;j++)
        {
            if(a[i][j]!=b[i][j])
            {
                f=-1;
                break;
            }if(c[i][j]!=1&&a[i][j]==b[i][j])
            {
                sum+=a[i][j];
            }
        }0
        if(f==-1)
        {
            break;
        }
    }
    if(f==-1)
    {
        printf("-1");
    }else
    {
        printf("%lld",sum);
    }
    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:49:11: error: expected ';' before 'if'
   49 |         }0
      |           ^
      |           ;
   50 |         if(f==-1)
      |         ~~
Language: C++

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, int> P;
typedef pair<ll,pair<int, int> > P3;

const ll MOD = ll(1e9 + 7);
const ll LLINF = LLONG_MAX;
const int IINF = INT32_MAX;
const int MAX_N = int(1e5) + 5;
const int MAX_V = 305;
const double EPS = 1e-8;
int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)

ll n, d[305][305];

bool wf() {
    REP(k, n) {
        REP(i, n) {
            REP(j, n) {
                if (d[i][j] > d[i][k] + d[k][j]) {
                    return false;
                }
            }
        }
    }
    return true;
}

ll solve(){
    ll sum = 0:
    REP(i, n) {
        REP(j, n) {
            bool flag = true;
            REP(k, n) {
                if (d[i][j] == d[i][k] + d[k][j]) {
                    flag = false;
                }
            }
            if(flag)sum += d[i][j];
        }
    }
    return sum;
}

int main() {
    cin >> n;
    REP(i, n) {
        REP(j, n) { cin >> d[i][j]; }
    }
    if (!wf())
        cout << -1 << endl;
    else {
        cout << solve() << endl;
    }
    return 0;
}


Compiler output:
a.cc: In function 'll solve()':
a.cc:36:15: error: expected ',' or ';' before ':' token
   36 |     ll sum = 0:
      |               ^
a.cc:37:9: error: 'i' was not declared in this scope
   37 |     REP(i, n) {
      |         ^
a.cc:16:35: note: in definition of macro 'REP'
   16 | #define REP(i, n) for (int i = 0; i < n; i++)
      |                                   ^
Language: C++

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

long long int a[300][300],b[300][300];
set<long long int> s;
vector<long long int> v;

int main() {

    int n;

    cin >> n;

    for(int i=0; i<n; i++){
        for(int j=0; j<n; j++){
            cin >> a[i][j];
            b[i][j] = a[i][j];
        }
    }

    for(int k=0; k<n; k++){
        for(int i=0; i<n; i++){
            for(int j=0; j<n; j++){
                b[i][j] = min(b[i][j],b[i][k] + b[k][j]);
            }
        }
    }

    

    for(int i=0; i<n; i++){
        for(int j=0; j<n; j++){
            if(a[i][j] > b[i][j]){
                cout << -1 << endl;
                return 0;
            }
        }
    }
    
    /*

    long long int ans = 0;

    for(int i=0; i<n; i++){
        for(int j=i+1; j<n; j++){
            v.push_back(a[i][j]);
        }
    }

    for(int i=0; i<v.size(); i++){
        for(int j=i+1; j<v.size(); j++){
            s.insert(v[i]+v[j]);
        }
    }

    for(int i=0; i<n; i++){
        for(int j=i+1; j<n; j++){
            if(s.find(a[i][j]) == s.end()){
                ans += a[i][j];
            }
        }
    }

    cout << ans << endl;

     

    cout << -1 << endl;

    return 0;
}

Compiler output:
a.cc:40:5: error: unterminated comment
   40 |     /*
      |     ^
a.cc: In function 'int main()':
a.cc:38:6: error: expected '}' at end of input
   38 |     }
      |      ^
a.cc:8:12: note: to match this '{'
    8 | int main() {
      |            ^
Language: C++

#include "stdafx.h"
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <queue>
#include <cmath>

#define	MOD 1000000007;
#define PI 3.14159265358979323846;
#define rep(i,n) for(int i = 0;i<(int)n;i++)
using namespace std;
typedef long long ll;
ll mod = 1000000007;
static const long long INFTY = (1LL << 32);
static const long long MAX = 300;

bool diff = false;
int n;
ll M[MAX][MAX];
bool d_n[MAX][MAX];
void floyd() {
	for (int k = 0; k < n; k++)
	{
		for (int i = 0; i < n; i++)
		{
			if (M[i][k] == INFTY) continue;
			for (int j = 0; j < n; j++)
			{
				if (M[k][j] == INFTY) continue;

				if (M[i][j] > M[i][k] + M[k][j]) {
					diff = true;
					M[i][j] = M[i][k] + M[k][j];
				}

				if (M[i][j] == M[i][k] + M[k][j] && M[i][k] > 0 && M[k][j] > 0) {
					d_n[i][j] = true;
				}
			}
		}
	}
}

int main()
{
	cin >> n;
	rep(i, n)rep(j, n) {
		cin >> M[i][j];
	}

	floyd();

	ll ans = 0;
	if (!diff) {
		rep(i, n)rep(j, n) {
			if (d_n[i][j] == false) ans += M[i][j];
		}
		cout << ans / 2 << endl;
	}
	else {
		cout << -1 << endl;
	}

	return 0;
}

Compiler output:
a.cc:1:10: fatal error: stdafx.h: No such file or directory
    1 | #include "stdafx.h"
      |          ^~~~~~~~~~
compilation terminated.
Language: C++

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

using namespace std;

int main() {
    int N;
    cin >> N;

    vector<vector<long long>> A(N, vector<long long>(N));
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            cin >> A[i][j];
        }
    }

    long long sum = 0;
    for (int i = 0; i < N; i++) {
        for (int j = i + 1; j < N; j++) {
            long long orig = A[i][j];
            long long via_shortest = LONG_LONG_MAX;
            for (int k = 0; k < N; k++) {
                long long via = A[i][k] + A[k][j];
                if (via < orig) {
                    cout << -1 << endl;
                    return 0;
                } else if (k != i && k != j) {
                    via_shortest = min(via, via_shortest);
                }
            }
            if (via_shortest > orig) {
                sum += orig;
            }
        }
    }
    cout << sum << endl;
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:22:38: error: 'LONG_LONG_MAX' was not declared in this scope
   22 |             long long via_shortest = LONG_LONG_MAX;
      |                                      ^~~~~~~~~~~~~
Language: C++

#include <bits/stdc++.h>
#define ll long long

int arr[350][350]={0};
int n;


int main(){
	cin>>n;
	for (int i =0;i<n;i++){
		for (int j=0;j<n;j++){
			cin>>arr[i][j];
		}
	}	
	for (int i =0;i<n;i++){
		for (int j=0;i<n;j++){
			for (int k=0;k<n;k++){
				if(arr[i][k]+arr[k][j]<arr[i][j]){
					cout<<-1;
					return 0;
				}
			}
		}
	}
	
	ll summ =0;
	for (int i=0;i<n;i++){
		for (int j=0;j<n;j++){
			summ+=arr[i][j];
		}
	}
	cout<<summ/2;
	
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:9:9: error: 'cin' was not declared in this scope; did you mean 'std::cin'?
    9 |         cin>>n;
      |         ^~~
      |         std::cin
In file included from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:146,
                 from a.cc:1:
/usr/include/c++/14/iostream:62:18: note: 'std::cin' declared here
   62 |   extern istream cin;           ///< Linked to standard input
      |                  ^~~
a.cc:19:41: error: 'cout' was not declared in this scope; did you mean 'std::cout'?
   19 |                                         cout<<-1;
      |                                         ^~~~
      |                                         std::cout
/usr/include/c++/14/iostream:63:18: note: 'std::cout' declared here
   63 |   extern ostream cout;          ///< Linked to standard output
      |                  ^~~~
a.cc:32:9: error: 'cout' was not declared in this scope; did you mean 'std::cout'?
   32 |         cout<<summ/2;
      |         ^~~~
      |         std::cout
/usr/include/c++/14/iostream:63:18: note: 'std::cout' declared here
   63 |   extern ostream cout;          ///< Linked to standard output
      |                  ^~~~
Language: C++

1 #include<iostream>
  2 using namespace std;
  3
  4 int N,ans;
  5 int c[305][305];
  6 bool IsRoad[305][305];
  7
  8 int main(){
  9   for(int i=0;i<305;i++){
 10     for(int j=0;j<305;j++){
 11       IsRoad[i][j]=true;
 12     }
 13   }
 14   cin>>N;
 15   for(int i=0;i<N;i++){
 16     for(int j=0;j<N;j++){
 17       cin>>c[i][j];
 18     }
 19   }
 20
 21   for(int k=0;k<N;k++){
 22     for(int i=0;i<N;i++){
 23       for(int j=0;j<N;j++){
 24         if(c[i][j]>c[i][k] + c[k][j]){
 25           cout<<-1<<endl;
 26           return 0;
 27         }
 28         else if(c[i][j]==c[i][k]+c[k][j]&&k!=j&&k!=i){
 29           IsRoad[i][j]=false;
 30         }
 31       }
 32     }
 33   }
 34   ans=0;
 35   for(int i=0;i<N;i++){
        for(int j=i;j<N;j++){
 37       if(IsRoad[i][j])ans+=c[i][j];
 38     }
 39   }
 40   cout<<ans<<endl;
 41 }

       

Compiler output:
a.cc:1:3: error: stray '#' in program
    1 | 1 #include<iostream>
      |   ^
a.cc:1:1: error: expected unqualified-id before numeric constant
    1 | 1 #include<iostream>
      | ^
a.cc:3:3: error: expected unqualified-id before numeric constant
    3 |   3
      |   ^
a.cc:5:3: error: expected unqualified-id before numeric constant
    5 |   5 int c[305][305];
      |   ^
a.cc:6:3: error: expected unqualified-id before numeric constant
    6 |   6 bool IsRoad[305][305];
      |   ^
a.cc:7:3: error: expected unqualified-id before numeric constant
    7 |   7
      |   ^
Language: C++

#include<iostream>
using namespace std;

int N,ans;
int c[305][305];
bool IsRoad[305][305];

int main(){
  for(int i=0;i<305;i++){
    for(int j=0;j<305;j++){
      IsRoad[i][j]=true;
    }
  }
  cin>>N;
  for(int i=0;i<N;i++){
    for(int j=0;j<N;j++){
      cin>>c[i][j];
    }
  }
  
  for(int k=0;k<N;k++){
    for(int i=0;i<N;k++){
      for(int j=0;j<N;j++){
        if(d[i][j]<d[i][k] + d[k][j]){
          cout<<-1<<endl;
          return 0;
        }
        else if(d[i][j]==d[i][j]){
          IsRoad[i][j]=false;
        }
      }
    }
  }
  ans=0;
  for(int i=0;i<N;i++){
    for(int i=j;i<N;i++){
      if(IsRoad)ans+=c[i][j];
    }
  }
  cout<<ans<<endl;
}
          
          

Compiler output:
a.cc: In function 'int main()':
a.cc:24:12: error: 'd' was not declared in this scope
   24 |         if(d[i][j]<d[i][k] + d[k][j]){
      |            ^
a.cc:36:15: error: 'j' was not declared in this scope
   36 |     for(int i=j;i<N;i++){
      |               ^
Language: C++

#include<iostream>
using namespace std;
int c[305][305];

int main(){
  cin>N;

  for(int i=0;i<N;i++){
    for(int j=0;j<N;j++){ 
      cin>>c[i][j];
}
}
int ans =0;
for(int k=0;k<N;k++){
  for(int i=0;i<N;i++){
    for(int j=0;j<N;j++){
        if(c[i][j]>c[i][k]+c[k][j]){
          cout<<-1<<endl;
          return 0;
          }
         else if(c[i][j]<c[i][k]+c[k][j]){
           ans+=c[i][j];
         }
       }
    }
  }

cout<<ans<<endl;
           


return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:6:7: error: 'N' was not declared in this scope
    6 |   cin>N;
      |       ^
Language: C++

#include <iostream>
#include <vector>
#include <array>
using namespace std;
typedef long long LL;

int main(void) {
  int N;
  scanf("%d", &N);
  array<array<int, 300>, 300 >A(N,vector<LL>(N));
  for(int i=0;i<N;i++)
    for(int j=0;j<N;j++)
      scanf("%d", &A[i][j]);

  for(int k=0;k<N;k++)
    for(int i=0;i<N;i++)
      for(int j=0;j<i;j++)
        if(A[i][j] > A[i][k]+A[k][j]){
          cout << -1 << endl;
          return 0;
        }

  LL ans=0;
  for(int i=0;i<N;i++){
    for(int j=0;j<i;j++){
      int need=1;
      for(int k=0;k<N;k++){
        if(k!=i and k!=j and A[i][j]==A[i][k]+A[k][j])
          need=0;
      }
      if(need) ans+=A[i][j];
    }
  }
  
    printf("%d\n", -1);
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:10:48: error: no matching function for call to 'std::array<std::array<int, 300>, 300>::array(int&, std::vector<long long int>)'
   10 |   array<array<int, 300>, 300 >A(N,vector<LL>(N));
      |                                                ^
In file included from a.cc:3:
/usr/include/c++/14/array:100:12: note: candidate: 'std::array<std::array<int, 300>, 300>::array()'
  100 |     struct array
      |            ^~~~~
/usr/include/c++/14/array:100:12: note:   candidate expects 0 arguments, 2 provided
/usr/include/c++/14/array:100:12: note: candidate: 'constexpr std::array<std::array<int, 300>, 300>::array(const std::array<std::array<int, 300>, 300>&)'
/usr/include/c++/14/array:100:12: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/array:100:12: note: candidate: 'constexpr std::array<std::array<int, 300>, 300>::array(std::array<std::array<int, 300>, 300>&&)'
/usr/include/c++/14/array:100:12: note:   candidate expects 1 argument, 2 provided
Language: C++

#include <vector>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>
#include <ctime>
#include <map>
#include <stack>
#include <sstream>
#include <set>
#include <cmath>
#include <functional>
#include <numeric>

using namespace std;

const int Max = 300;
int main(void)
{
	int road[Max][Max];
	int n;
	long long int res = 0;
	bool flag = false;
	bool flag2[Max][Max];

	memset(flag2, true, sizeof(flag2));

	cin >> n;

	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < n; j++)
		{
			cin >> road[i][j];
		}
	}

	for (int k = 0; k < n; k++)
	{
		for (int i = 0; i < n; i++)
		{
			for (int j = 0; j < n; j++)
			{
				if (road[i][j] > road[i][k] + road[k][j])
				{
					flag = true;

				}

				if (road[i][j] == road[i][k] + road[k][j])
				{
					if (road[i][k] != 0 && road[k][j] != 0)
					{
						flag2[i][j] = false;
					}
				}
			}
		}
	}
	 
	for (int i = 0; i < n; i++)
	{
		for (int j = i + 1; j < n; j++)
		{
			if (flag2[i][j] == true)
			{
				res += road[i][j];
			}
		}
	}

	if (flag == true)
	{
		cout << "-1" << endl;
	}
	else
	{
		cout << res << endl;
	}

	return 0;

}

Compiler output:
a.cc: In function 'int main()':
a.cc:26:9: error: 'memset' was not declared in this scope
   26 |         memset(flag2, true, sizeof(flag2));
      |         ^~~~~~
a.cc:14:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
   13 | #include <numeric>
  +++ |+#include <cstring>
   14 |