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

#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef pair<ll, ll> PP;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define rrep(i, n) for(ll i = n - 1; i > -1; i--)
#define all(v) v.begin(), v.end()
#define pb push_back
#define fi first
#define se second
const ll INF = 1LL << 61;
const ll MOD = 1000000007 /*988244353*/;
const ll MAX_N = 500010;
ll a, b, c, d, e, f, h, x, y, z, p, q, m, n, t, r, k, w, l, ans, i, j;
string S, T;
vl A, B;
vl g[MAX_N];
vl visited(MAX_N, 0), used(MAX_N, 0);
vl D(MAX_N);
void solve() {
    rep(i, n) {
        rep(j, n - 1) {
            g[i * n + j].pb(i * n + j + 1);
            g[i * n + j + 1].pb(i * n + j);
            g[(j + 1) * n + i].pb(j * n + i);
            g[j * n + i].pb((j + 1) * n + i);
        }
    }

    rep(i, n) {
        rep(j, n) { D[i * n + j] = min({i, n - 1 - i, j, n - 1 - j}); }
    }

    rep(i, n * n) {
        x = A[i];
        // cout << x << endl;
        used[x] = 1;
        p = 0;
        queue<ll> Q;
        Q.push(x);
      vl K;
        visited[x] = 1;
      K.pb(x);
        while(!Q.empty()) {
            int v = Q.front();
            Q.pop();
            for(ll x : g[v]) {
                if(visited[x] == 0 && D[x] > D[v] + 1 && used[v] == 0) {
                    visited[x] = 1;
                  K.pb(x);
                    Q.push(x);
                    D[x] = D[v] + 1;
                }
                if(visited[x] == 0 && D[x] > D[v] && used[v] == 1) {
                    visited[x] = 1;
                    Q.push(x);
                  K.pb(x);
                    D[x] = D[v];
                }
            }
        }
      
      for(i:K)visited[i]--;

        /*rep(j, n) {
            rep(k, n) { cout << D[j * n + k]; }
            cout << " ";
            rep(k, n) { cout << used[j * n + k]; }
            cout << endl;
        }*/

        ans += D[x];

        // cout << endl;
    }

    cout << ans << endl;
}
int main() {
    // cout<<fixed<<setprecision(15);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    rep(i, n * n) {
        cin >> a;
        a--;
        A.pb(a);
    }
    solve();
}


Compiler output:
a.cc: In function 'void solve()':
a.cc:65:12: error: found ':' in nested-name-specifier, expected '::'
   65 |       for(i:K)visited[i]--;
      |            ^
      |            ::
a.cc:65:11: error: 'i' is not a class, namespace, or enumeration
   65 |       for(i:K)visited[i]--;
      |           ^
a.cc:77:5: error: expected primary-expression before '}' token
   77 |     }
      |     ^
a.cc:74:21: error: expected ')' before '}' token
   74 |         ans += D[x];
      |                     ^
      |                     )
......
   77 |     }
      |     ~                
a.cc:65:10: note: to match this '('
   65 |       for(i:K)visited[i]--;
      |          ^
a.cc:77:5: error: expected primary-expression before '}' token
   77 |     }
      |     ^
Language: C++

#include <iostream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <cstring>
#include <bitset>
#include <functional>
#include <random>
#define REP(_i,_a,_n) for(int _i=_a;_i<=_n;++_i)
#define PER(_i,_a,_n) for(int _i=_n;_i>=_a;--_i)
#define hr putchar(10)
#define pb push_back
#define lc (o<<1)
#define rc (lc|1)
#define mid ((l+r)>>1)
#define ls lc,l,mid
#define rs rc,mid+1,r
#define x first
#define y second
#define io std::ios::sync_with_stdio(false)
#define endl '\n'
#define DB(_a) ({REP(_i,1,n) cout<<_a[_i]<<',';hr;})
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int P = 1e9+7, INF = 0x3f3f3f3f;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll qpow(ll a,ll n) {ll r=1%P;for (a%=P;n;a=a*a%P,n>>=1)if(n&1)r=r*a%P;return r;}
ll inv(ll x){return x<=1?1:inv(P%x)*(P-P/x)%P;}
inline int rd() {int x=0;char p=getchar();while(p<'0'||p>'9')p=getchar();while(p>='0'&&p<='9')x=x*10+p-'0',p=getchar();return x;}
//head



#ifdef __APPLE__
const int N = 1e2+50;
#else
const int N = 1e6+50;
#endif


const int dx[]={0,0,-1,1};
const int dy[]={-1,1,0,0};
int n,a[N][N],vis[N*N],ans[N*N];
pii pos[N*N];
queue<int> q;
int main() {
	scanf("%d", &n);
	int now = 0;
	REP(i,1,n) REP(j,1,n) {
		a[i][j]=++now,vis[now]=1;
		pos[now]=pii(i,j);
		ans[now]=min({i-1,j-1,n-i,n-j});
	}
	int tot = 0;
	REP(i,1,n*n) {
		int t;
		scanf("%d", &t);
		tot+=ans[t],vis[t]=0;
		q.push(t);
		while (q.size()) {
			int u(q.front()); q.pop();
			REP(k,0,3) {
				int x=pos[u].x+dx[k],y=pos[u].y+dy[k];
				if (1<=x&&x<=n&&1<=y&&y<=n&&ans[a[x][y]]>ans[u]+vis[u]) {
					ans[a[x][y]]=ans[u]+vis[u];
					q.push(a[x][y]);
				}
			}
		}
	}
	printf("%d\n", tot);
}









Compiler output:
a.cc:49:20: warning: integer overflow in expression of type 'int' results in '-627377468' [-Woverflow]
   49 | int n,a[N][N],vis[N*N],ans[N*N];
      |                   ~^~
a.cc:49:20: error: size '-627377468' of array 'vis' is negative
a.cc:49:29: warning: integer overflow in expression of type 'int' results in '-627377468' [-Woverflow]
   49 | int n,a[N][N],vis[N*N],ans[N*N];
      |                            ~^~
a.cc:49:29: error: size '-627377468' of array 'ans' is negative
a.cc:50:10: warning: integer overflow in expression of type 'int' results in '-627377468' [-Woverflow]
   50 | pii pos[N*N];
      |         ~^~
a.cc:50:10: error: size '-627377468' of array 'pos' is negative
Language: C++

#include "template.cpp"


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

  int n; cin >> n;

  VI p(n*n); rep(i, n*n) cin >> p[i];

  auto cost = make_v(n, n, 0);
  rep(r, n) rep(c, n) cost[r][c] = min({r, c, n-r-1, n-c-1}) + 1;
  dump(cost);

  ll res = 0;

  int dr[] = {0,0,-1,1}; // LRUD
  int dc[] = {1,-1,0,0};
  auto inside = [&](int r, int c) { return r >= 0 and r < n and c >= 0 and c < n; };

  auto occupied = make_v(n, n, true);

  rep(i, n*n) {
    dump(p[i]);
    p[i]--;
    int rp = p[i] / n, cp = p[i] % n;
    res += cost[rp][cp]-1;
    occupied[rp][cp] = false;
    cost[rp][cp] = rp == 0 or rp == n-1 or cp == 0 or cp == n-1 ? 0 : INF;
    rep(j, 4) {
      int r2 = rp + dr[j], c2 = cp + dc[j];
      if (inside(r2, c2)) chmin(cost[rp][cp], cost[r2][c2]);
    }
    deque<PII> togo;
    togo.emplace_back(rp, cp);
    while (not togo.empty()) {
      auto [r, c] = togo.front(); togo.pop_front();
      // bool dbg = false;
      // if (p[i] == 8 and r == 2 and c == 1) dbg = true;
      rep(j, 4) {
        int r2 = r + dr[j], c2 = c + dc[j];
        // if (dbg) dump(r, c, cost[r][c], r2, c2, cost[r2][c2], cost[r2][c2]+occupied[r2][c2]);
        if (inside(r2, c2) and chmin(cost[r2][c2], cost[r][c] + occupied[r2][c2])) {
          if (occupied[r2][c2]) togo.emplace_back(r2, c2);
          else togo.emplace_front(r2, c2);
        }
      }
    }
    // dump(cost);
  }
  cout << res << newl;
}

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

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

int ijToNum(int nLine, int i, int j){
  	int seatNum = j*nLine+i+1;
  	return seatNum;
}

int numToJ(int nLine, int seatNum){
 	int jGuest = ( (seatNum-1) / nLine);// [0,N-1]
  	return jGuest;
}

int numToI(int nLine, int seatNum){
 	int yGuest = numToJ(nLine, seatNum) + 1;// [1,N]
    int xGuest = seatNum - nLine*(yGuest-1);// [1,N]
  	return xGuest-1;
}

int main(){
  	int answer =0;
  	
	int nLine;
  	cin >> nLine;
    int mvCost[nLine][nLine];
  	bool isMan[nLine][nLine];
  	for(int i=0;i<nLine;i++){
    	for(int j=0;j<nLine;j++){
          	mvCost[i][j] = std::min( {i,j,nLine-1-i,nLine-1-j} );
          	isMan[i][j] = true;
        }
    }
  	
  	int nGuest = nLine*nLine;
  	int seatNum[nGuest];
  	for(int iGuest=0;iGuest<nGuest;iGuest++){
  		cin >> seatNum[iGuest];
    }
  	
  	std::vector<int> subtrSeat;
  	for(int iGuest=0;iGuest<nGuest;iGuest++){
      	subtrSeat.push_back(seatNum[iGuest]);
      	answer += mvCost[numToI(nLine, subtrSeat[0])][numToJ(nLine, subtrSeat[0])];
      	isMan[numToI(nLine, subtrSeat[0])][numToJ(nLine, subtrSeat[0])] = false;
      	
    }
      	while( (int)subtrSeat.size() > 0){
	      	int iGuest = numToI(nLine, subtrSeat[0]);
    	  	int jGuest = numToJ(nLine, subtrSeat[0]);
          	
          	//cout << "seatNum = " << subtrSeat[0] <<endl;
          	if(0< iGuest && iGuest<nLine-1 && 0< jGuest && jGuest<nLine-1){
 	         	if(mvCost[iGuest][jGuest] < mvCost[iGuest+1][jGuest]){
    	          	subtrSeat.push_back(ijToNum(nLine,iGuest+1,jGuest));
        	    }
            }
          	if(0< iGuest && iGuest<nLine-1 && 0< jGuest && jGuest<nLine-1){
          		if(mvCost[iGuest][jGuest] < mvCost[iGuest-1][jGuest]){
              		subtrSeat.push_back(ijToNum(nLine,iGuest-1,jGuest));
    	        }
            }
          	if(0< iGuest && iGuest<nLine-1 && 0< jGuest && jGuest<nLine-1){
	          	if(mvCost[iGuest][jGuest] < mvCost[iGuest][jGuest+1]){
    	          	subtrSeat.push_back(ijToNum(nLine,iGuest,jGuest+1));
        	    }
            }
          	if(0< iGuest && iGuest<nLine-1 && 0< jGuest && jGuest<nLine-1){
            	if(mvCost[iGuest][jGuest] < mvCost[iGuest][jGuest-1]){
              		subtrSeat.push_back(ijToNum(nLine,iGuest,jGuest-1));
                }
            }
          	//cout<< "cost = "<< mvCost[iGuest][jGuest]<<endl;
          	mvCost[iGuest][jGuest]--;
      		subtrSeat.erase(subtrSeat.begin());
          	subtrSeat.shrink_to_fit();
        }
    }
  	
  	cout << answer;
}


Compiler output:
a.cc:82:9: error: 'cout' does not name a type
   82 |         cout << answer;
      |         ^~~~
a.cc:83:1: error: expected declaration before '}' token
   83 | }
      | ^
Language: C

include <stdio.h>
int main(){
    int a,input[25000],exit[200000]={},blank[25000]={},num=1,ans=0,flag;
    scanf("%d",&a);  
  
  for(int i=0;i<a*a;i++){
  scanf("%d",&input[i]);
  }
  
 for(int i=0;i<a-1;i++){
  exit[i]=i+1;
  exit[a-1+i]=a*(i+1);
  exit[2*a-2+i]=a*(i+1)+1;
  exit[3*a-3+i]=a*a-a+i+2;
 }
 int k=4*a-4;
  for(int i=0;i<25000;i++){
    flag=0;
    for(int j=0;j<k;j++){
   if(input[i]==exit[j]) 
     flag++;
    }
    if(flag){
      int n;
     exit[++k]=input[i]-1;
     exit[++k]=input[i]+1;
     exit[++k]=input[i]-a;
     exit[++k]=input[i]+a;
       for(int m=0;m<i;m++){
        if(input[i]-1==blank[m]||input[i]+1==blank[m]||input[i]-a==blank[m]||input[i]+a==blank[m]){
            exit[++k]=blank[m]-1;
            exit[++k]=blank[m]+1;
            exit[++k]=blank[m]-a;
            exit[++k]=blank[m]+a;
          
        }
       }
      
    }
    else {
      ans++;
      blank[i]=input[i];
    }
  }
   
  printf("%d",ans);
  return 0;
}


Compiler output:
main.c:1:9: error: expected '=', ',', ';', 'asm' or '__attribute__' before '<' token
    1 | include <stdio.h>
      |         ^
Language: C++

#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i=0; i<(int)(n); i++)
int main(){
int N; cin >> N; int P[N*N], now[N][N]={}, ans=0; bool flg[N][N]={};
REP(i, N*N){ cin >> P[i]; P[i]--; }
REP(i, N){ REP(j, N){ now[i][j]=min(min(i, j), min(N-1-i, N-1-j)); } }

REP(i, N*N){ 
  int x=P[i]/N, y=P[i]%N, n=now[x][y]; ans+=now[x][y]; flg[x][y]=true;
  vector< vector<int> > V={{x, y, 0}};
  for(int k=0; k<V.size(); k++){
  int a=V[k][0], b=V[k][1], c=V[k][2]//, n=now[a][b];
  if(a>0 && now[a-1][b]>n+c){ now[a-1][b]--; if(flg[a-1][b]){ V.push_back({a-1, b, 0}); }else{ V.push_back({a-1, b, c+1}); } }
  if(b>0 && now[a][b-1]>n+c){ now[a][b-1]--; if(flg[a][b-1]){ V.push_back({a, b-1, 0}); }else{ V.push_back({a, b-1, c+1}); } }
  if(a<N-1 && now[a+1][b]>n+c){ now[a+1][b]--; if(flg[a+1][b]){ V.push_back({a+1, b, 0}); }else{ V.push_back({a+1, b, c+1}); } }
  if(b<N-1 && now[a][b+1]>n+c){ now[a][b+1]--; if(flg[a][b+1]){ V.push_back({a, b+1, 0}); }else{ V.push_back({a, b+1, c+1}); } }
  }
}
cout << ans << "\n";
}


Compiler output:
a.cc: In function 'int main()':
a.cc:14:3: error: expected ',' or ';' before 'if'
   14 |   if(a>0 && now[a-1][b]>n+c){ now[a-1][b]--; if(flg[a-1][b]){ V.push_back({a-1, b, 0}); }else{ V.push_back({a-1, b, c+1}); } }
      |   ^~
Language: C++

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

int m,n,k;

int main () {
  long i = 0;
  long count = 0;

  cin >> m;

  long n = m * m;
  vector<long> v(n);

  for (i = 0; i < n; i++){
    cin >> k;
    v[i] = k;
  }

  for (i = 0; i < n; i++){
    if ((v[i] <= n) || (v[i] >= (n * (n - 1))+ 1) || (v[i] % n == 1) || (v[i] % n == n - 1)){
      v[i] = 0;
    }
  }

  for (i = 0; i < n; i++){
    if (v[i] != 0){
      long h = v[i]; 
      long syou = i / n;
      long p = n * syou;
      long q = ((n * (syou + 1)) - 1);
      long cb = count_if(v.begin(), v.end(), [&h, &p] (int x) {return x >= p && x < h;});
      long ca = count_if(v.begin(), v.end(), [&h, &q] (int y) {return y > h && y <= q;});
    }

    if (cb > ca){
      count += ca;
    }

    else{
      count += cb;
    }
    
  cout << cb <<endl;
      
}

Compiler output:
a.cc: In function 'int main()':
a.cc:38:9: error: 'cb' was not declared in this scope
   38 |     if (cb > ca){
      |         ^~
a.cc:38:14: error: 'ca' was not declared in this scope
   38 |     if (cb > ca){
      |              ^~
a.cc:46:11: error: 'cb' was not declared in this scope
   46 |   cout << cb <<endl;
      |           ^~
a.cc:48:2: error: expected '}' at end of input
   48 | }
      |  ^
a.cc:8:13: note: to match this '{'
    8 | int main () {
      |             ^
Language: C++

#include <bits/stdc++.h>

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n;

    cin >> n;

    vector<int> p(n * n);

    for(int i = 0; i < n * n; ++i) {
        cin >> p.at(i);
    }

    vector<vector<int>> h((n + 2), vector<int>(n + 2));

    for(int i = 0; i < n + 2; ++i) {
        for(int j = 0; j < n + 2; ++j) {
            h.at(i).at(j) = min(min(min(i, n + 1 - i), j), n + 1 - j);
        }
    }

    int ans = 0;
    int d, m, a;    

    for(int i = 0; i < n * n; ++i) {
        d = (p.at(i) - 1) / n;
        m = (p.at(i) - 1) % n;
        a = min(min(min(h.at(d).at(m), h.at(d).at(m + 2)), h.at(d + 2).at(m)), h.at(d + 2).at(m + 2));
        ans += a;
        h.at(i) = a;
    }

    printf("%d\n", ans);

    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:35:19: error: no match for 'operator=' (operand types are '__gnu_cxx::__alloc_traits<std::allocator<std::vector<int> >, std::vector<int> >::value_type' {aka 'std::vector<int>'} and 'int')
   35 |         h.at(i) = a;
      |                   ^
In file included from /usr/include/c++/14/vector:72,
                 from /usr/include/c++/14/functional:64,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:53,
                 from a.cc:1:
/usr/include/c++/14/bits/vector.tcc:210:5: note: candidate: 'std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(const std::vector<_Tp, _Alloc>&) [with _Tp = int; _Alloc = std::allocator<int>]'
  210 |     vector<_Tp, _Alloc>::
      |     ^~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/vector.tcc:211:42: note:   no known conversion for argument 1 from 'int' to 'const std::vector<int>&'
  211 |     operator=(const vector<_Tp, _Alloc>& __x)
      |               ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
In file included from /usr/include/c++/14/vector:66:
/usr/include/c++/14/bits/stl_vector.h:766:7: note: candidate: 'std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(std::vector<_Tp, _Alloc>&&) [with _Tp = int; _Alloc = std::allocator<int>]'
  766 |       operator=(vector&& __x) noexcept(_Alloc_traits::_S_nothrow_move())
      |       ^~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:766:26: note:   no known conversion for argument 1 from 'int' to 'std::vector<int>&&'
  766 |       operator=(vector&& __x) noexcept(_Alloc_traits::_S_nothrow_move())
      |                 ~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_vector.h:788:7: note: candidate: 'std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(std::initializer_list<_Tp>) [with _Tp = int; _Alloc = std::allocator<int>]'
  788 |       operator=(initializer_list<value_type> __l)
      |       ^~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:788:46: note:   no known conversion for argument 1 from 'int' to 'std::initializer_list<int>'
  788 |       operator=(initializer_list<value_type> __l)
      |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
Language: C++

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  ll n;
  cin>>n;
  ll arr[n*n] ={0};
  ll enpty[n*n] ={0};
  fr(i,n*n){
    arr[i] = min({i/n,i%n,n-i/n-1,n-i%n-1});
  }
  ll ans,k;
  ans=0;
  l=1;
  queue<ll> que;
  fr(i,n*n){
    ll b;
    cin>>b;
    --b;
    ans += arr[b];
    enpty[b] = 1;
    que.push(b);
    while (!que.empty()) {
    k = que.front();
    if(k/n>0){
      if(arr[k-n] > arr[k]-enpty[k]+1 and arr[k-n]>0){
      arr[k-n]=arr[k]-enpty[k]*1;
      que.push(k-n);
    }}
    if(k%n>0){
      if (arr[k-1] > arr[k]-enpty[k]+1 and arr[k-1]>0){
      arr[k-1]=arr[k]-enpty[k]+1;
      que.push(k-1);
    }}
    if(k/n<n){
      if(arr[k+n] > arr[k]-enpty[k]+1 and arr[k+n]>0){
      arr[k+n]=arr[k]-enpty[k]+1;
      que.push(k+n);
    }}
    if(k%n<n){
      if(arr[k+1]> arr[k]-enpty[k]+1 and arr[k+1]>0){
      arr[k+1]=arr[k]-enpty[k]+1;
      que.push(k+1);
    }}
    que.pop();
  }
  }
  cout<<ans;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:21:3: error: 'l' was not declared in this scope
   21 |   l=1;
      |   ^
Language: C++

0完＼(^o^)／太陽
0完＼(^o^)／太陽
0完＼(^o^)／太陽
0完＼(^o^)／太陽
0完＼(^o^)／太陽
0完＼(^o^)／太陽
0完＼(^o^)／太陽
0完＼(^o^)／太陽
0完＼(^o^)／太陽
0完＼(^o^)／太陽
0完＼(^o^)／太陽
0完＼(^o^)／太陽
0完＼(^o^)／太陽
0完＼(^o^)／太陽
0完＼(^o^)／太陽
0完＼(^o^)／太陽
0完＼(^o^)／太陽
0完＼(^o^)／太陽


Compiler output:
a.cc:1:1: error: expected unqualified-id before numeric constant
    1 | 0完＼(^o^)／太陽
      | ^~~~~
Language: C++

#include <iostream>
#include <bits/stdc++.h>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;



int main(){
    int n;
    cin >> n;
    int p[n];
    rep(i,0,n){
        cin >> p[i+1];
    }
    cout << n/2 << endl;
    //--------------
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:14:9: error: 'i' was not declared in this scope
   14 |     rep(i,0,n){
      |         ^
a.cc:14:5: error: 'rep' was not declared in this scope
   14 |     rep(i,0,n){
      |     ^~~
Language: C++

#include <iostream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <cstring>
#include <bitset>
#include <functional>
#include <random>
#define REP(_i,_a,_n) for(int _i=_a;_i<=_n;++_i)
#define PER(_i,_a,_n) for(int _i=_n;_i>=_a;--_i)
#define hr putchar(10)
#define pb push_back
#define lc (o<<1)
#define rc (lc|1)
#define mid ((l+r)>>1)
#define ls lc,l,mid
#define rs rc,mid+1,r
#define x first
#define y second
#define io std::ios::sync_with_stdio(false)
#define endl '\n'
#define DB(_a) ({REP(_i,1,n) cout<<_a[_i]<<',';hr;})
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int P = 1e9+7, INF = 0x3f3f3f3f;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll qpow(ll a,ll n) {ll r=1%P;for (a%=P;n;a=a*a%P,n>>=1)if(n&1)r=r*a%P;return r;}
ll inv(ll x){return x<=1?1:inv(P%x)*(P-P/x)%P;}
inline int rd() {int x=0;char p=getchar();while(p<'0'||p>'9')p=getchar();while(p>='0'&&p<='9')x=x*10+p-'0',p=getchar();return x;}
//head



#ifdef __APPLE__
const int N = 1e2+50;
#else
const int N = 1e6+50;
#endif


const int dx[]={0,0,1,-1};
const int dy[]={-1,1,0,0};
int n,a[N][N],vis[N*N],d[N*N],c[N*N],clk;
pii pos[N*N];
deque<int> q;
int main() {
	scanf("%d", &n);
	int now = 0;
	REP(i,1,n) REP(j,1,n) { 
		a[i][j] = ++now;
		pos[now] = pii(i,j);
		c[now] = 1;
	}
	int tot = 0;
	REP(t,1,n*n) {
		q.clear();
		int s;
		scanf("%d", &s);
		q.push_back(s);
		vis[s]=++clk,d[s]=c[s]=0;
		int ok = s==5;
		while (q.size()) {
			int u(q.back()); q.pop_back();
			if (pos[u].x==1||pos[u].x==n||pos[u].y==1||pos[u].y==n) {
				tot += d[u];
				break;
			}
			REP(k,0,3) {
				int x=pos[u].x+dx[k],y=pos[u].y+dy[k];
				if (1<=x&&x<=n&&1<=y&&y<=n&&vis[a[x][y]]!=clk) {
					d[a[x][y]] = d[u]+c[a[x][y]];
					vis[a[x][y]] = clk;
					if (c[a[x][y]]) q.push_front(a[x][y]);
					else q.push_back(a[x][y]);
				}
			}
		}
	}
	printf("%d\n", tot);
}









Compiler output:
a.cc:49:20: warning: integer overflow in expression of type 'int' results in '-627377468' [-Woverflow]
   49 | int n,a[N][N],vis[N*N],d[N*N],c[N*N],clk;
      |                   ~^~
a.cc:49:20: error: size '-627377468' of array 'vis' is negative
a.cc:49:27: warning: integer overflow in expression of type 'int' results in '-627377468' [-Woverflow]
   49 | int n,a[N][N],vis[N*N],d[N*N],c[N*N],clk;
      |                          ~^~
a.cc:49:27: error: size '-627377468' of array 'd' is negative
a.cc:49:34: warning: integer overflow in expression of type 'int' results in '-627377468' [-Woverflow]
   49 | int n,a[N][N],vis[N*N],d[N*N],c[N*N],clk;
      |                                 ~^~
a.cc:49:34: error: size '-627377468' of array 'c' is negative
a.cc:50:10: warning: integer overflow in expression of type 'int' results in '-627377468' [-Woverflow]
   50 | pii pos[N*N];
      |         ~^~
a.cc:50:10: error: size '-627377468' of array 'pos' is negative
Language: C++

#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
const int INF =1001001001;
using P = pair<int,int>;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};

struct edge {
    int to;
    int cost;
};

int main()
{
   int n;
   cin >> n;
   vector<int> p(n*n);
   rep(i,n*n) cin >> p[i];

   //1    2  3 .......n
   //n+1 n+2 .....    2n 
   //1 2 3
   //4 5 6
   //7 8 9
   vector<vector<bool>> dist(n,vector<bool>(n,false));
   ll ans = 0;
   for(int target: p)
   {
      queue<P> que;
      int x = target%n - 1; if(x == -1) x = n-1;
      int y = (target-1)/n;
      que.push(P(x,y));
      vector<vector<int>> dist2(n,vector<int>(n, INF));
      dist2[x][y] = 0;
      while(!que.empty())
      {
         int x = que.front().first;
         int y = que.front().second; que.pop();
         rep(i,4)
         {
            int nx = x + dx[i];
            int ny = y + dy[i];

            if(nx < 0 || ny < 0 || nx >=n || ny >= n) continue;
            int nn = 0;
            if(!dist[nx][ny]) nn = dist2[x][y] + 1;
            else nn = dist2[x][y];
            if(dist2[nx][ny] <= nn)continue;
            dist2[nx][ny] = nn;
            que.push(P(nx,ny));
         }
      }
      int tmp = min(dist2[0][0], dist2[n-1][n-1]);
      tmp = min(dist2[0][n-1], tmp);
      tmp = min(dist2[n-1][0],tmp);
      if(tmp != 0) ans++;
      dist[x][y] = true;
   }
   cout << ans << endl;
   return 0;
}

Compiler output:
a.cc:31:20: error: stray '\16' in program
   31 |       queue<P> que;<U+000E>
      |                    ^~~~~~~~
a.cc:41:18: error: stray '\16' in program
   41 |          rep(i,4)<U+000E>
      |                  ^~~~~~~~
a.cc:43:32: error: stray '\16' in program
   43 |             int nx = x + dx[i];<U+000E>
      |                                ^~~~~~~~
Language: C++

#include "bits/stdc++.h"
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/adaptors.hpp>
#include <boost/dynamic_bitset.hpp>
namespace adaptor = boost::adaptors;
using index_t = std::size_t;

namespace lib
{
	using graph_t = std::vector<std::set<index_t>>;
	template<class T>using weighted_graph_t = std::vector<std::map<index_t, T>>;

	namespace impl
	{
		struct max_t
		{
			template<class T>constexpr T operator()(T&& lhs, T&& rhs)const
			{
				return std::max(lhs, rhs);
			}
		};
		struct min_t
		{
			template<class T>constexpr T operator()(T&& lhs, T&& rhs)const
			{
				return std::min(lhs, rhs);
			}
		};
	}
	constexpr impl::max_t max;
	constexpr impl::min_t min;

	template<class T>auto orderby(T func)
	{
		return [=](auto&& lhs, auto&& rhs)
		{
			return func(lhs) < func(rhs);
		};
	}

	template<class T>constexpr auto max_v = std::numeric_limits<T>::max();
	template<class T>constexpr auto min_v = std::numeric_limits<T>::min(); 

	template<class T>using p_queue = std::priority_queue<T, std::vector<T>, std::greater<>>;
}

void Main()
{
	int N;
	std::cin >> N;
	auto decode = [&](int idx)
	{
		--idx;
		return std::make_pair(idx / N, idx % N);
	};
	std::vector<std::pair<int, int>> vec;
	for (auto _ : boost::irange(N * N))
	{
		int code;
		std::cin >> code;
		vec.push_back(decode(code));
	}
	boost::multi_array<bool, 2> opened(boost::extents[N][N]), checked(boost::extents[N][N]);
	std::deque<std::tuple<int, int, int>> queue;
	int count = 0;
	auto push = [&](int a, int b, int c)
	{
		if (0 <= a && a < N && 0 <= b && b < N && !checked[a][b])
		{
			checked[a][b] = true;
			if (opened[a][b])
			{
				queue.emplace_front(a, b, c);
			}
			else
			{
				queue.emplace_back(a, b, c + 1);
			}
		}
	};
	for (auto [i, k] : vec)
	{
		for (auto x : boost::irange(N))
		{
			for (auto y : boost::irange(N))
			{
				checked[x][y] = false;
			}
		}
		opened[i][k] = true;
		push(i, k, 0);
		while (queue.size())
		{
			auto p = queue.front();
			auto [a, b, c] = p;
			lib::print::debug(a + 1, b + 1, c);
			queue.pop_front();
			if (a == 0 || a == N - 1 || b == 0 || b == N - 1)
			{
				count += c;
				break;
			}
			push(a - 1, b, c);
			push(a + 1, b, c);
			push(a, b - 1, c);
			push(a, b + 1, c);
		}
		queue.clear();
	}
	std::cout << count << std::endl;
}

int main()
{
	std::cin.tie(nullptr);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	Main();
}

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

#include<cstdio>
using namespace std;
int main(){
	return !printf("ans")
}

Compiler output:
a.cc: In function 'int main()':
a.cc:4:30: error: expected ';' before '}' token
    4 |         return !printf("ans")
      |                              ^
      |                              ;
    5 | }
      | ~
Language: C++

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

int main(){
  long long n,count;
  cin>>n;
  vector<long long> vec(n*n);
  for(int i=0;i<n*n;i++){
cin>>vec.at(i);
  }
  vector<long long> a(n*n+n);
  for(int i=0;i<n*n;i++){
if((i+1)%n==0||(i+1)%n==1||(0<=i&&i<n)||(n*(n-1)<i+1&&i+1<=n*n)){
a.at(i)=0;
}
    else{
a.at(i)=1;
    }
  }
for(int i=0;i<n*n;i++){
if(a.at(vec.at(i)-1)==1){
  count++;
  a.at(i)=2;
}
  else if(a.at(vec.at(i)-1)==0){
if(i%n>=1){
a.at(i-1)=0;
}
    if(i%n<=4){
a.at(i+1)=0;
    }
    if(i/n>=1){
a.at(i-6)=0;
    }
    if(i/n<5){
a.at(i+6)=0;
    }
  }
  for(int j=n+1;j<n*n;j++){
if (a.at(j)==2){
if(a.at(j+6)==0||a.at(j-6)==0||(a.at(j-1)==0&&j%n>0)||(a.at(j+1)==0&&j%n<5)){
a.at(j-6)=0;
  a.at(j+6);
  if(j%n>0){
a.at(j-1)=0;
  }
  if(j%n<5){
a.at(j+1)=0;
  }
}
}
  }

    cout<<count<<endl;
  
}  


  



Compiler output:
a.cc: In function 'int main()':
a.cc:43:7: warning: ignoring return value of 'std::vector<_Tp, _Alloc>::reference std::vector<_Tp, _Alloc>::at(size_type) [with _Tp = long long int; _Alloc = std::allocator<long long int>; reference = long long int&; size_type = long unsigned int]', declared with attribute 'nodiscard' [-Wunused-result]
   43 |   a.at(j+6);
      |   ~~~~^~~~~
In file included from /usr/include/c++/14/vector:66,
                 from /usr/include/c++/14/functional:64,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:53,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_vector.h:1180:7: note: declared here
 1180 |       at(size_type __n)
      |       ^~
a.cc:56:2: error: expected '}' at end of input
   56 | }
      |  ^
a.cc:4:11: note: to match this '{'
    4 | int main(){
      |           ^
Language: C++

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

int main(){
  long long n,count;
  cin>>n;
  vector<long long> vec(n*n);
  for(int i=0;i<n*n;i++){
cin>>vec.at(i);
  }
  vector<long long> a(n*n+n);
  for(int i=0;i<n*n;i++){
if((i+1)%n==0||(i+1)%n==1||(0<=i&&i<n)||(n*(n-1)<i+1&&i+1<=n*n)){
a.at(i)=0;
}
    else{
a.at(i)=1;
    }
  }
for(int i=0;i<n*n;i++){
if(a.at(vec.at(i)-1)==1){
  count++;
  a.at(i)=2;
}
  else if(a.at(vec.at(i)-1)==0){
if(i%n>=1){
a.at(i-1)=0;
}
    if(i%n<=4){
a.at(i+1)=0;
    }
    if(i/n>=1){
a.at(i-6)=0;
    }
    if(i/n<5){
a.at(i+6)=0;
    }
  }
  for(int j=n+1;j<n*n;j++){
if (a.at(j)==2){
if(a.at(j+6)==0||a.at(j-6)==0||(a.at(j-1)==0&&j%n>0)||(a.at(j+1)==0&&j%n<5)){
a.at(j-6)=0;
  a.at(j+6);
  if(j%n>0){
a.at(j-1)=0;
  }
  if(j%n<5){
a.at(j+1)=0;
  }
}
}

    cout<<count<<endl;
  
}  


  



Compiler output:
a.cc: In function 'int main()':
a.cc:43:7: warning: ignoring return value of 'std::vector<_Tp, _Alloc>::reference std::vector<_Tp, _Alloc>::at(size_type) [with _Tp = long long int; _Alloc = std::allocator<long long int>; reference = long long int&; size_type = long unsigned int]', declared with attribute 'nodiscard' [-Wunused-result]
   43 |   a.at(j+6);
      |   ~~~~^~~~~
In file included from /usr/include/c++/14/vector:66,
                 from /usr/include/c++/14/functional:64,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:53,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_vector.h:1180:7: note: declared here
 1180 |       at(size_type __n)
      |       ^~
a.cc:55:2: error: expected '}' at end of input
   55 | }
      |  ^
a.cc:20:23: note: to match this '{'
   20 | for(int i=0;i<n*n;i++){
      |                       ^
a.cc:55:2: error: expected '}' at end of input
   55 | }
      |  ^
a.cc:4:11: note: to match this '{'
    4 | int main(){
      |           ^
Language: C++

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

int main(){
  long long n,count;
  cin>>n;
  vector<long long> vec(n*n);
  for(int i=0;i<n*n;i++){
cin>>vec.at(i);
  }
  vector<long long> a(n*n+n);
  for(int i=0;i<n*n;i++){
if((i+1)%n==0||(i+1)%n==1||(0<=i&&i<n)||(n*(n-1)<i+1&&i+1<=n*n)){
a.at(i)=0;
}
    else{
a.at(i)=1;
    }
  }
for(int i=0;i<n*n;i++){
if(a.at(vec.at(i)-1)==1){
  count++;
  a.at(i)=2;
}
  else if(a.at(vec.at(i)-1)==0){
if(i%n>=1){
a.at(i-1)=0;
}
    if(i%n<=4){
a.at(i+1)=0;
    }
    if(i/n>=1){
a.at(i-6)=0;
    }
    if(i/n<5){
a.at(i+6)=0;
    }
  }
  for(int j=n+1;j<n*n;j++){
if (a.at(j)==2){
if(a.at(j+6)==0||a.at(j-6)==0||(a.at(j-1)==0&&j%n>0)||(a.at(j+1)==0&&j%n<5)){
a.at(j-6)=0;
  a.at(j+6);
  if(j%n>0){
a.at(i-1)=0;
  }
  if(j%n<5){
a.at(i+1)=0;
  }
}
}
  }

    cout<<count<<endl;
  
}  


  



Compiler output:
a.cc: In function 'int main()':
a.cc:43:7: warning: ignoring return value of 'std::vector<_Tp, _Alloc>::reference std::vector<_Tp, _Alloc>::at(size_type) [with _Tp = long long int; _Alloc = std::allocator<long long int>; reference = long long int&; size_type = long unsigned int]', declared with attribute 'nodiscard' [-Wunused-result]
   43 |   a.at(j+6);
      |   ~~~~^~~~~
In file included from /usr/include/c++/14/vector:66,
                 from /usr/include/c++/14/functional:64,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:53,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_vector.h:1180:7: note: declared here
 1180 |       at(size_type __n)
      |       ^~
a.cc:56:2: error: expected '}' at end of input
   56 | }
      |  ^
a.cc:4:11: note: to match this '{'
    4 | int main(){
      |           ^
Language: C++

#include<bits/stdc++.h>

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;++A)
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////


ll  N, P[1000*1000];


ll mk[1000 * 1000];
ll mk2[1000 * 1000];
ll g[8];
ll i, j, k;
int main(){
    scanf("%lld", &N);
    fornum(i,0,N*N){
        scanf("%lld", &P[i]);
        P[i]--;
    }
    fornum(i,0,N){
        fornum(j,0,N){
            mk[i * N + j] = min(min(i, N - i - 1), min(j, N - j - 1));
        }
    }
    g[0] = 1;
    g[1] = N;
    g[2] = -1;
    g[3] = -N;
    uf.init(N * N + 5);
    ll ans = 0;
    fornum(i,0,N*N){
        //printf("%lld ", P[i]);
        ans += nx[P[i]];
        mk2[P[i]]++;
        queue<ll> q;
        q.push(P[i]);
        while(q.size()){
            ll qa = q.front();
            q.pop();
            fornum(j,0,4){
                ll nx = P[qa] + g[j];
                if(nx<0||N*N<=nx||(qa%N!=nx%N&&qa/N!=nx/N))
                    continue;
                if(mk[qa] + 1 - mk[qa]<mk[nx]){
                    mk[nx] = mk[qa] + 1 - mk[qa];
                    q.push(nx);
                }
            }
        }

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

Compiler output:
a.cc: In function 'int main()':
a.cc:35:5: error: 'uf' was not declared in this scope
   35 |     uf.init(N * N + 5);
      |     ^~
a.cc:39:16: error: 'nx' was not declared in this scope
   39 |         ans += nx[P[i]];
      |                ^~
Language: C++

//
//  ROIGold.cpp
//  Main calisma
//
//  Created by Rakhman on 05/02/2019.
//  Copyright © 2019 Rakhman. All rights reserved.
//

#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstdlib>
#include <ctime>
#include <cassert>
#include <iterator>
#include <unordered_map>
#include <math.h>
#include <unordered_set>
#define ios ios_base::sync_with_stdio(0), cout.tie(0), cin.tie(0);
#define S second
#define F first
#define pb push_back
#define nl '\n'
#define NL cout << '\n';
#define EX exit(0)
#define all(s) s.begin(), s.end()
#define FOR(i, start, finish, k) for(int i = start; i <= finish; i += k)

const int MXN = 2e5 + 1;
const long long MNN = 1e6 + 200;
const long long MOD = 1e9 + 7;
const long long INF = 1e18;
const int OO = 1e9 + 500;

typedef long long llong;
typedef unsigned long long ullong;

using namespace std;

#define PI 3.14159265358979323846

void istxt(bool yes){
    freopen("/Users/mac/Desktop/input.txt", "r", stdin);
    freopen("/Users/mac/Desktop/output.txt", "w", stdout);
}

int n;
vector<vector<int>> table;

int ans = 0;

int dfs(int row, int col, vector<vector<int>> &table) {
    if (row < 0 || row >= n || col < 0 || col >= n) {
        return 0;
    }
    
    if (table[row][col] == 2) {
        return INT_MAX / 2;
    }
    
    int count = table[row][col] == 1;
    
    table[row][col] = 2;
    
    bool up = dfs(row-1, col, table) + count;
    bool down = dfs(row+1, col, table) + count;
    bool left = dfs(row, col-1, table) + count;
    bool right = dfs(row, col+1, table) + count;
    
    table[row][col] = 1;
    
    return min({up, down, left, right});
}

void solve() {
    
    cin >> n;
    
    vector<int> p(n * n);
    
    table.assign(n+1, vector<int>(n+1, 1));
    
    for (int i = 0; i < n * n; ++i) {
        cin >> p[i];
    }
    
    int count = 0;
    
    for (int i = 0; i < p.size(); ++i) {
        int person = p[i];
        
        int row = (person + n - 1)/ n;
        int total = row * n;
        int start = total - n + 1;
        int col = person - start + 1;
        
        table[row-1][col-1] = 0;
        
        int a = dfs(row-1, col-1, table);
        count += a;
    }
    
    cout << count << endl;
}

int main () {
//    ios;
//    istxt(0);

    solve();
 
    return 0;
}



Compiler output:
a.cc: In function 'int dfs(int, int, std::vector<std::vector<int> >&)':
a.cc:72:16: error: 'INT_MAX' was not declared in this scope
   72 |         return INT_MAX / 2;
      |                ^~~~~~~
a.cc:33:1: note: 'INT_MAX' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>'
   32 | #include <unordered_set>
  +++ |+#include <climits>
   33 | #define ios ios_base::sync_with_stdio(0), cout.tie(0), cin.tie(0);
Language: C++

#ifdef DEBUG
#include "utils.cpp"
#endif
#include <bits/stdc++.h>


using namespace std;
using ll = int64_t;
#define int int64_t

 
/* ==== declarations ====== */
// functions
void solve();
void getInput();
 
// global variables
int N;
vector<vector<int>> C;
vector<vector<bool>> O;
vector<pair<int, int>> operations;

/* ======================== */
void getInput() {
    cin>>N;
    operations = vector<pair<int, int>>(N*N);
    for(int i=0; i<N*N; ++i) {
        int num;
        cin>>num;
        // operations[num-1] = {i/N, i%N};
        num--;
        operations[i] = {num/N, num%N};
    }

    O = vector<vector<bool>>(N, vector<bool>(N, true));
    C = vector<vector<int>>(N, vector<int>(N, 0));


    for(int i=0; i<N; ++i) {
        for (int j=0; j<N; ++j) {
            int a = min(i, N-1-i);
            int b = min(j, N-1-j);
            C[i][j] = min(a, b);
        }
    }
}
 
void updateNeighbors(pair<int, int> pos) {
    vector<int> ret;
    queue<pair<int, int>> que;
    que.push(pos);
    int cost = C[pos.first][pos.second];
    // print("update: ", pos, "cost: ", cost);
    
    vector<vector<bool>> visit(N, vector<bool>(N, false));
    while(!que.empty()) {
        auto op = que.front();
        que.pop();
        if(visit[op.first][op.second]) continue;
        
        visit[op.first][op.second] = true;
        vector<int> dx = {1, -1, 0, 0};
        vector<int> dy = {0, 0, 1, -1};
        
        for (int i=0; i<4; ++i) {
            int x = op.first + dx[i];
            int y = op.second + dy[i];
            if (x<0 or y<0 or x>=N or y>=N) continue;

            
            
            if (O[x][y]) {
                C[x][y] = min(C[x][y], cost);
            } else {
                que.push({x, y});
            }
        }
        
    }
    
}
 
void solve() {
    int ans;
    for(auto op: operations) {
        ans += C[op.first][op.second];
        O[op.first][op.second] = false;


        // print("====================================");
        updateNeighbors(op);
        
        // print(op);
        // print(C);
        
        // vector<int> dx = {1, -1, 0, 0};
        // vector<int> dy = {0, 0, 1, -1};
        // for (int i=0; i<4; ++i) {
        //     int x = op.first + dx[i];
        //     int y = op.second + dy[i];
        //     if (x<0 or y<0 or x>=N or y>=N) continue;

        // }

    }
    print(ans);
}
 
 
 
signed main(){
    getInput();
    solve();
    return 0;
}

Compiler output:
a.cc: In function 'void solve()':
a.cc:106:5: error: 'print' was not declared in this scope; did you mean 'rint'?
  106 |     print(ans);
      |     ^~~~~
      |     rint
Language: C++

#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define rrep(i,a,b) for(int i=(a);i>=(b);--i)
#define PB push_back
#define ar2 array<int, 2>
typedef long long LL;
const LL P = 998244353;
const int N = 505;
mt19937 rng(time(0));

int n, x, y, a[N*n], dp[N][N], v[N][N];
int dx[] = {-1,0,0,1}, dy[] = {0,-1,1,0};

void update(int x, int y){
	v[x][y] = 0;
	queue<ar2> Q;
	Q.push({x, y});
	while(!Q.empty()){
		ar2 ele = Q.front();
		Q.pop();
		int x = ele[0], y = ele[1];
		rep(i,0,3){
			int x1 = x + dx[i], y1 = y + dy[i];
			if(dp[x][y] + v[x][y] < dp[x1][y1]){
				dp[x1][y1] = dp[x][y] + v[x][y];
				Q.push({x1, y1});
			}
		}
	}
}

int main(){
	#ifndef ONLINE_JUDGE
	//freopen("test.in","r",stdin);
	#endif
	scanf("%d",&n);
	rep(i,1,n*n) scanf("%d",a+i);
	
	rep(i,1,n) rep(j,1,n)
		dp[i][j] = min(min(i-1, n-i), min(j-1, n-j)),
		v[i][j] = 1;
	
	int ans = 0;
	rep(q,1,n*n){
		x = a[q] - 1;
		y = x % n + 1, x = x / n + 1;
		
		ans += dp[x][y];
		update(x, y);		
	}
	cout<<ans<<endl;
	return 0;
}

Compiler output:
a.cc:12:17: error: size of array 'a' is not an integral constant-expression
   12 | int n, x, y, a[N*n], dp[N][N], v[N][N];
      |                ~^~
Language: C++

#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <math.h>
#include <string>
#include <cstring>
#include <set>
#include <map>
#include <unordered_map>

using namespace std;

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

#define ri(a) scanf("%d", &a)
#define rii(a,b) scanf("%d %d", &a, &b)
#define riii(a,b,c) scanf("%d %d %d", &a, &b, &c)
#define rl(a) scanf("%lld", &a)
#define rll(a,b) scanf("%lld %lld", &a, &b)
#define FOR(i,n,m) for(int i=n; i<m; i++)
#define ROF(i,n,m) for(int i=n; i>m; i--)
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define F first
#define S second

const int INF = 0x3f3f3f3f;
const ll LLINF = 1e18;
const int maxN = 505; // CAMBIAR ESTE

// GJNM
int n;
int mat[maxN][maxN];
int A[maxN*maxN];
ll dp[maxN*maxN][4];

ll f(int ind, int choice){ 
	if ( ind == n*n )
		return 0;
	if ( dp[ind][choice] != -1 )
		return dp[ind][choice];

	ll &ret = dp[ind][choice];
	ret = LLINF;
	
	int row = get_row(A[ind]), col = get_col(A[ind]);
	ll aux = 0;
	if ( choice == 0 ){ // go up
		mat[row][col] = 0;
		FOR(i,0,row)
			aux += mat[i][col];
	
		FOR(i,0,4)
			ret = min(ret, aux + f(ind+1, i) );
		
		mat[row][col] = 1;
	}
	else if ( choice == 1 ){ // go down	
		mat[row][col] = 0;
		FOR(i,row+1,n)
			aux += mat[i][col];
	
		FOR(i,0,4)
			ret = min(ret, aux + f(ind+1, i) );
		
		mat[row][col] = 1;	
	}
	else if ( choice == 2 ){ // go left
		mat[row][col] = 0;

		FOR(i,0,col)
			aux += mat[row][i];
	
		FOR(i,0,4)
			ret = min(ret, aux + f(ind+1, i) );
		
		mat[row][col] = 1;
	}
	else{ // go right
		mat[row][col] = 0;

		FOR(i,col,n)
			aux += mat[row][i];
	
		FOR(i,0,4)
			ret = min(ret, aux + f(ind+1, i) );
		
		mat[row][col] = 1;
	}
	return ret;
}

int main(){
	ri(n);
	FOR(i,0,n){
		FOR(j,0,n){
			mat[i][j] = 1;
		}
	}
	
	FOR(i,0,n*n){
		ri(A[i]);
		A[i]--;
	}

	FOR(i,0,maxN){
		dp[i][0] = dp[i][1] = dp[i][2] = dp[i][3] = -1;
	}

	printf("%lld\n", min( min( f(0,0), f(0,1) ), min( f(0,2), f(0,3) ) ) );
	return 0;
}

Compiler output:
a.cc: In function 'll f(int, int)':
a.cc:53:19: error: 'get_row' was not declared in this scope; did you mean 'getw'?
   53 |         int row = get_row(A[ind]), col = get_col(A[ind]);
      |                   ^~~~~~~
      |                   getw
a.cc:56:26: error: 'col' was not declared in this scope; did you mean 'cosl'?
   56 |                 mat[row][col] = 0;
      |                          ^~~
      |                          cosl
a.cc:66:26: error: 'col' was not declared in this scope; did you mean 'cosl'?
   66 |                 mat[row][col] = 0;
      |                          ^~~
      |                          cosl
a.cc:76:26: error: 'col' was not declared in this scope; did you mean 'cosl'?
   76 |                 mat[row][col] = 0;
      |                          ^~~
      |                          cosl
a.cc:87:26: error: 'col' was not declared in this scope; did you mean 'cosl'?
   87 |                 mat[row][col] = 0;
      |                          ^~~
      |                          cosl
Language: C

#pragma GCC optimize(2)
#pragma GCC optimize(3)
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define per(i, a, b) for (int i = a; i >= b; i--)
using namespace std;
 
typedef unsigned long long ull;
typedef pair <int, int> pii;
typedef long long ll;
 
template <typename _T>
inline void read(_T &f) {
	f = 0; _T fu = 1; char c = getchar();
	while (c < '0' || c > '9') { if (c == '-') { fu = -1; } c = getchar(); }
	while (c >= '0' && c <= '9') { f = (f << 3) + (f << 1) + (c & 15); c = getchar(); }
	f *= fu;
}
 
template <typename T>
void print(T x) {
	if (x < 0) putchar('-'), x = -x;
	if (x < 10) putchar(x + 48);
	else print(x / 10), putchar(x % 10 + 48);
}
 
template <typename T>
void print(T x, char t) {
	print(x); putchar(t);
}

const int N = 505;
const int dx[4] = {1, -1, 0, 0};
const int dy[4] = {0, 0, 1, -1};

struct ele {
	int x, y;
	ele (int a = 0, int b = 0) : x(a), y(b) {}
};

queue <ele> q;
int a[N][N], dis[N][N];
int n, ans;

int main() {
	read(n);
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++) {
			dis[i][j] = min(min(i, j), min(n - i + 1, n - j + 1));
			a[i][j] = 1;
		}
	}
	for (int i = 1; i <= n * n; i++) {
		int v, x, y; read(v);
		x = (v - 1) / n + 1; y = (v - 1) % n + 1;
		--dis[x][y]; a[x][y] = 0; ans += dis[x][y]; q.push(ele(x, y));
		while (!q.empty()) {
			ele u = q.front(); q.pop();
			for (int j = 0; j < 4; j++) {
				int _x = u.x + dx[j], _y = u.y + dy[j];
				if (dis[_x][_y] > dis[u.x][u.y] + a[_x][_y]) {
					dis[_x][_y] = dis[u.x][u.y] + a[_x][_y];
					q.push(ele(_x, _y));
				}
			}
		}
	}
	print(ans, '\n');
	return 0;
}

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

//xor and insert hackerearth using trie ds
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define mod 1000000007
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    int a[n][n];
    for(int i=0;i<n;i++)
    for(int j=0;j<n;j++)
    a[i][j]=1;
    vector<int>v(n*n);
    for(int i=0;i<n*n;i++)
    cin>>v[i];
    int res=0;
    for(int i=0;i<n*n;i++)
    {
        int r=(v[i]-1)/n;
        int c=v[i]-n*r-1;
        int m=n;
        int co=0;
        for(int j=r+1;j<n;j++)
        {
            if(a[j][c])
            co++;
        }
        m=min(m,co);
        co=0;
        for(int j=r-1;j>=0;j--)
        {
            if(a[j][c])
            co++;
        }
        m=min(m,co);
        co=0;
        for(int j=c-1;j>=0;j--)
        {
            if(a[r][j])
            co++;
        }
        m=min(m,co);
        co=0;
        for(int j=c+1;j<n;j++)
        {
            if(a[r][j])
            co++;
        }
        m=min(m,co);
        res+=m;
        a[r][c]=0;
    }
    cout<<res;
    return 0;
}

Compiler output:
cc1plus: error: '::main' must return 'int'
Language: C++

#include <iostream>


using namespace std;

long long int N;
string T;

void R(int *data);
void S(int *data1, int *data2);
int X(int x, int y);

int main(){
  int n;
  string s1;
  string s2;
  cin >> n;
  cin >> T;
  N = X(3, n);
  int L[N];
  int K[N];
  int O[N];
  
  for(long long int i=0;i<N;i++){
    L[i] = i;
  }
  
  for(long long int i=0;i<N/3;i++){
    int k = i;
    int tmp = 0;
    int m = 3;
    int q = i*3;
    
    while(k>0){
      if(k%3==1){
        tmp = tmp +2*m;
      }else if(k%3==2){
        tmp = tmp +1*m;
      }
      k = k/3;
      m = m*3;
    }
    K[tmp] = q;
    K[tmp + 1] = q+2;
    K[tmp + 2] = q+1;
  }
  
  
  for(int i=0;i<(int)(T.length());i++){
    s1 = T[i];
    s2 = T[i+1];
    if(s1=="R"){
      R(L);
    }else if(s1=="S" && s2=="S"){
      i++;
    }else{
      S(L,K);
    }
  }
  


  for(long long int i=0;i<N;i++){
    cout << L[i] << " ";
  }
  return 0;
}

void R(int *data){
  for(long long int i=0;i<N;i++){
    data[i] = data[i] + 1;
    if(data[i]==N){
      data[i]=0;
    }
  }
}

void S(int *data1, int *data2){
  for(long long int i=0;i<N;i++){
    data1[i] = data2[data1[i]];
  }
}


long long int X(int x,int y){
  long long int a = 1;
  for(int i=0;i<y;i++){
    a = a*x;
  }
  return a;
}


Compiler output:
a.cc:85:15: error: ambiguating new declaration of 'long long int X(int, int)'
   85 | long long int X(int x,int y){
      |               ^
a.cc:11:5: note: old declaration 'int X(int, int)'
   11 | int X(int x, int y);
      |     ^