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

#include <iostream>
using namespace std;

int count(int H, int W, int D, int A[300][300], int L[100000], int R[100000], int k){
	int i, j=0,l=0,x[H*W],y[H*W],S;
	while(L[k]!=R[k]){
		for(i=0;i<H;i++){
			if(A[i][j]==L[k]){
				x[l]=i;
				y[l]=j;
				l++;
				break;
			}
			else{j++;}
		}
		L[k] += D;
		i=0;
		j=0;
	}
	for(i=0;i<l-1;i++){
		S += abs(x[l]-x[l+1])+abs(y[l]-y[l+1]);
	}
	return S;
}
int main(){
	int H,W,D,A[H][W],i,j,Q,L[Q],R[Q],MP=0;
	cin >> H >> W >> D;
	for(i=0;i<H;i++){
		for(j=0;j<W;j++){
			cin >> A[i][j];
		}
	}
	cin >> Q;
	for(i=0;i<Q;i++){
		cin >> L[i] >> R[i];
	}

	for(i=0;i<Q;i++){
		MP += count(H, W, D, A, L, R, i);
	}
	cout << MP << endl;
			
}


Compiler output:
a.cc: In function 'int main()':
a.cc:39:38: error: cannot convert 'int (*)[W]' to 'int (*)[300]'
   39 |                 MP += count(H, W, D, A, L, R, i);
      |                                      ^
      |                                      |
      |                                      int (*)[W]
a.cc:4:36: note:   initializing argument 4 of 'int count(int, int, int, int (*)[300], int*, int*, int)'
    4 | int count(int H, int W, int D, int A[300][300], int L[100000], int R[100000], int k){
      |                                ~~~~^~~~~~~~~~~
Language: C++

#include <iostream>
using namespace std;

int count(int H, int W, int D, int A[300][300], int L[100000], int R[100000], int k){
	int i, j=0,l=0,x[H*W],y[H*W],S;
	while(L[k]!=R[k]){
		for(i=0;i<H;i++){
			if(A[i][j]==L[k]){
				x[l]=i;
				y[l]=j;
				l++;
				break;
			}
			else{j++;}
		}
		L[k] += D;
		i=0;
		j=0;
	}
	for(i=0;i<l-1;i++){
		S += abs(x[l]-x[l+1])+abs(y[l]-y[l+1]);
	}
	return S;
}
int main(){
	int H,W,D,A[H][W],i,j,Q,L[Q],R[Q],MP=0;
	cin >> H >> W >> D;
	for(i=0;i<H;i++){
		for(j=0;j<W;j++){
			cin >> A[i][j];
		}
	}
	cin >> Q;
	for(i=0;i<Q;i++){
		cin >> L[i] >> R[Q];
	}

	for(i=0;i<Q;i++){
		MP += count(H, W, D, A[H][W], L[Q], R[Q], i);
	}
	cout << MP << endl;
			
}


Compiler output:
a.cc: In function 'int main()':
a.cc:39:44: error: invalid conversion from 'int' to 'int (*)[300]' [-fpermissive]
   39 |                 MP += count(H, W, D, A[H][W], L[Q], R[Q], i);
      |                                      ~~~~~~^
      |                                            |
      |                                            int
a.cc:4:36: note:   initializing argument 4 of 'int count(int, int, int, int (*)[300], int*, int*, int)'
    4 | int count(int H, int W, int D, int A[300][300], int L[100000], int R[100000], int k){
      |                                ~~~~^~~~~~~~~~~
a.cc:39:50: error: invalid conversion from 'int' to 'int*' [-fpermissive]
   39 |                 MP += count(H, W, D, A[H][W], L[Q], R[Q], i);
      |                                               ~~~^
      |                                                  |
      |                                                  int
a.cc:4:53: note:   initializing argument 5 of 'int count(int, int, int, int (*)[300], int*, int*, int)'
    4 | int count(int H, int W, int D, int A[300][300], int L[100000], int R[100000], int k){
      |                                                 ~~~~^~~~~~~~~
a.cc:39:56: error: invalid conversion from 'int' to 'int*' [-fpermissive]
   39 |                 MP += count(H, W, D, A[H][W], L[Q], R[Q], i);
      |                                                     ~~~^
      |                                                        |
      |                                                        int
a.cc:4:68: note:   initializing argument 6 of 'int count(int, int, int, int (*)[300], int*, int*, int)'
    4 | int count(int H, int W, int D, int A[300][300], int L[100000], int R[100000], int k){
      |                                                                ~~~~^~~~~~~~~
Language: C++

#include <string>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <functional>
#include <queue>
using namespace std;
const int INT_INF = 500000000;
const long long LONG_LONG_INF = (long long)pow(10, 18);
const int MOD = pow(10, 9) + 7;
/* contest template */
vector<pair<int, int>> p(90000);
int H, W, D, Q, l, r;
vector<vector<int>> A(300, vector<int>(300, 0));
vector<vector<int>> ans(300, vector<int>(300,INT_INF);
int nageru[100000];

int main()
{

    cin >> H >> W >> D;
    for (int i = 0; i < H; i++)
    {
        for (int j = 0; j < W; j++)
        {
            cin >> A[i][j];
            p[A[i][j]] = make_pair(i, j);
        }
    }
    cin >> Q;
    for (int i = 0; i < Q; i++)
    {
        int m = 0;
        cin >> l >> r;
        if (ans[l][r] != INT_INF)
        {
            nageru[i] = ans[l][r];
        }
        else
        {
            while (l != r)
            {
                pair<int, int> a = p[l];
                pair<int, int> b = p[l + D];
                m += abs(a.first - b.first) + abs(a.second - b.second);
                l += D;
            }
            ans[l][r] = m;
            nageru[i] = m;
        }
    }
    for (int i = 0; i < Q; i++)
    {
        cout << nageru[i] << endl;
    }

    return 0;
}

Compiler output:
a.cc:19:54: error: expected ')' before ';' token
   19 | vector<vector<int>> ans(300, vector<int>(300,INT_INF);
      |                        ~                             ^
      |                                                      )
Language: C

#include <stdio.h>

int h, w, d, i, j, x[301], y[301], l, r, q, sum[90001];

int myabs(int w)
{
	return w<0?-w:w;
}

int main()
{
	scanf("%d %d %d", &h, &w, &d);
	for(i=1; i<=w; i++)
		for(j=1; j<=h; j++)
		{
			scanf("%d", &a[i][j]);
			x[a[i][j]]=i;
			y[a[i][j]]=j;
		}
	for(i=d+1; i<=w*h; i++)
		sum[i]=sum[i-d]+myabs(x[i]-x[i-d])+myabs(y[i]-y[i-d]);
	scanf("%d", &q);
	for(i=0; i<q; i++)
	{
		scanf("%d %d", &l, &r);
		printf("%d\n", sum[r]-sum[l]);
	}
}

Compiler output:
main.c: In function 'main':
main.c:16:38: error: 'a' undeclared (first use in this function)
   16 |                         scanf("%d", &a[i][j]);
      |                                      ^
main.c:16:38: note: each undeclared identifier is reported only once for each function it appears in
Language: C++

#include<iostream>
#include<cstdlib>
using namespace std;

int main(){
    int H,W;
    long D,Q,L,R,A;
    int Dict[90001][2];
    unsigned long long int magic=0;
    cin >> H >> W >> D;
    for(int i=1;i<=H;i++){
        for(int j=1;j<=W;j++){
            cin >> A;
            Dict[A][0]=i;
            Dict[A][1]=j;
        }
    }
    cin >> Q;
    if(D>300){
        for(int i=0;i<Q;i++){
            cin >> L >> R;
            magic=0;
            while(L!=R){
                magic+=abs(Dict[L+D][0]-Dict[L][0])+abs(Dict[L+D][1]-Dict[L][1]);
                L+=D;
            }
            cout << magic << "\n";
        }
    }
    else{
        print("mokemoke")
    }
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:31:9: error: 'print' was not declared in this scope; did you mean 'printf'?
   31 |         print("mokemoke")
      |         ^~~~~
      |         printf
Language: C++

#include <iostream>
using namespace std;

int count(int H, int W, int D, int A[300][300], int L[100000], int R[100000], int k){
	int i, j=0,l=0,x[H*W],y[H*W],S;
	while(L[k]!=R[k]){
		for(i=0;i<H;i++){
			if(A[i][j]==L[k]){
				x[l]=i;
				y[l]=j;
				l++;
				break;
			}
			else{j++;}
		}
		L[k] += D;
		i=0;
		j=0;
	}
	for(i=0;i<l-1;i++){
		S += abs(x[l]-x[l+1])+abs(y[l]-y[l+1]);
	}
	return S;
}
int main(){
	int H,W,D,A[H][W],i,j,Q,L[Q],R[Q],MP=0;
	cin >> H >> W >> D;
	for(i=0;i<H;i++){
		for(j=0;j<W;j++){
			cin >> A[i][j];
		}
	}
	cin >> Q;
	for(i=0;i<Q;i++){
		cin >> L[i] >> R[Q];
	}

	for(i=0;i<Q;i++){
		MP += count(H, W, D, A[H][W], L[Q], R[Q], k){
	}
	cout << MP << endl;
			
}


Compiler output:
a.cc: In function 'int main()':
a.cc:39:59: error: 'k' was not declared in this scope
   39 |                 MP += count(H, W, D, A[H][W], L[Q], R[Q], k){
      |                                                           ^
a.cc:43:2: error: expected '}' at end of input
   43 | }
      |  ^
a.cc:25:11: note: to match this '{'
   25 | int main(){
      |           ^
Language: C++

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

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

#define pb push_back
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define dep(i, a, n) for(int i = (a); i >= (n); i--)
#define mod (ll)(1e9+7)

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

map<int, P> mp;
int g[301][301];
int a[d + 1][(h * w) / d + 1] = {};

signed main() {
  int h, w, d;
  cin >> h >> w >> d;
  rep(i, 0, h) rep(j, 0, w) {
    cin >> g[i][j];
    mp[g[i][j]] = P(i, j);
  }
  int q;
  cin >> q;
  rep(i, 0, d) {
    for(int j = 1; j <= (h * w) / d; j++) {
      a[i][j] += abs(mp[i + j * d].first - mp[i + j * d - d].first);
      a[i][j] += abs(mp[i + j * d].second - mp[i + j * d - d].second);
      a[i][j] += a[i][j - 1];
    }
  }
  rep(i, 0, q) {
    int l, r;
    cin >> l >> r;
    cout << a[l % d][r / d] - a[l % d][l / d] << endl;
  }
}


Compiler output:
a.cc:21:7: error: 'd' was not declared in this scope
   21 | int a[d + 1][(h * w) / d + 1] = {};
      |       ^
a.cc:21:15: error: 'h' was not declared in this scope
   21 | int a[d + 1][(h * w) / d + 1] = {};
      |               ^
a.cc:21:19: error: 'w' was not declared in this scope
   21 | int a[d + 1][(h * w) / d + 1] = {};
      |                   ^
a.cc:21:24: error: 'd' was not declared in this scope
   21 | int a[d + 1][(h * w) / d + 1] = {};
      |                        ^
a.cc: In function 'int main()':
a.cc:34:7: error: 'a' was not declared in this scope
   34 |       a[i][j] += abs(mp[i + j * d].first - mp[i + j * d - d].first);
      |       ^
a.cc:42:13: error: 'a' was not declared in this scope
   42 |     cout << a[l % d][r / d] - a[l % d][l / d] << endl;
      |             ^
Language: C++

#include <iostream>
using namespace std;

int count(int H, int W, int D, int A[300][300], int L[100000], int R[100000], int k){
	int i, j=0,l=0,x[H*W],y[H*W],S;
	while(L[k]!=R[k]){
		for(i=0;i<H;i++){
			if(A[i][j]==L[k]){
				x[l]=i;
				y[l]=j;
				l++;
				break;
			}
			else{j++;}
		}
		L[k] += D;
		i=0;
		j=0;
	}
	for(i=0;i<l-1;i++)
		S += abs(x[l]-x[l+1])+abs(y[l]-y[l+1]);
	}
	return S;
}
int main(){
	int H,W,D,A[H][W],i,j,Q,L[Q],R[Q],MP=0;
	cin >> H >> W >> D;
	for(i=0;i<H;i++){
		for(j=0;j<W;j++){
			cin >> A[i][j];
		}
	}
	cin >> Q;
	for(i=0;i<Q;i++){
		cin >> L[i] >> R[Q];
	}

	for(i=0;i<Q;i++){
		MP += count(H, W, D, A[H][W], L[Q], R[Q], k){
	}
	cout << MP << endl;
			
}


Compiler output:
a.cc: In function 'int count(int, int, int, int (*)[300], int*, int*, int)':
a.cc:22:9: warning: no return statement in function returning non-void [-Wreturn-type]
   22 |         }
      |         ^
a.cc: At global scope:
a.cc:23:9: error: expected unqualified-id before 'return'
   23 |         return S;
      |         ^~~~~~
a.cc:24:1: error: expected declaration before '}' token
   24 | }
      | ^
a.cc: In function 'int main()':
a.cc:39:59: error: 'k' was not declared in this scope
   39 |                 MP += count(H, W, D, A[H][W], L[Q], R[Q], k){
      |                                                           ^
a.cc:43:2: error: expected '}' at end of input
   43 | }
      |  ^
a.cc:25:11: note: to match this '{'
   25 | int main(){
      |           ^
Language: C++

#include <iostream>
using namespace std;

int count(int H, int W, int D, int A[90000], int L[100000], int R[100000], int k){
	int i, j=0,l=0,x[H*W],y[H*W],S;
	while(L[k]!=R[k]){
		for(i=0;i<H;i++){
			if(A[i][j]==L[k]){
				x[l]=i;
				y[l]=j;
				l++;
				break;
			}
			else{j++;}
		}
		L[k] += D;
		i=0;
		j=0;
	}
	for(i=0;i<l-1;i++)
		S += abs(x[l]-x[l+1])+abs(y[l]-y[l+1]);
	}
	return S;
}
int main(){
	int H,W,D,A[H][W],i,j,Q,L[Q],R[Q],MP=0;
	cin >> H >> W >> D;
	for(i=0;i<H;i++){
		for(j=0;j<W;j++){
			cin >> A[i][j];
		}
	}
	cin >> Q;
	for(i=0;i<Q;i++){
		cin >> L[i] >> R[Q];
	}

	for(i=0;i<Q;i++){
		MP += count(H, W, D, A[H][W], L[Q], R[Q], k){
	}
	cout << MP << endl;
			
}


Compiler output:
a.cc: In function 'int count(int, int, int, int*, int*, int*, int)':
a.cc:8:32: error: invalid types 'int[int]' for array subscript
    8 |                         if(A[i][j]==L[k]){
      |                                ^
a.cc:22:9: warning: no return statement in function returning non-void [-Wreturn-type]
   22 |         }
      |         ^
a.cc: At global scope:
a.cc:23:9: error: expected unqualified-id before 'return'
   23 |         return S;
      |         ^~~~~~
a.cc:24:1: error: expected declaration before '}' token
   24 | }
      | ^
a.cc: In function 'int main()':
a.cc:39:59: error: 'k' was not declared in this scope
   39 |                 MP += count(H, W, D, A[H][W], L[Q], R[Q], k){
      |                                                           ^
a.cc:43:2: error: expected '}' at end of input
   43 | }
      |  ^
a.cc:25:11: note: to match this '{'
   25 | int main(){
      |           ^
Language: C++

#include <iostream>
using namespace std;

int count(int H, int W, int D, int A[90000], int L[100000], int R[100000], int k){
	int i, j=0,l=0;x[H*W],y[H*W],S;
	while(L[k]!=R[k]){
		for(i=0;i<H;i++){
			if(A[i][j]==L[k]){
				x[l]=i;
				y[l]=j;
				l++;
				break;
			}
			else{j++;}
		}
		L[k] += D;
		i=0;
		j=0;
	}
	for(i=0;i<l-1;i++)
		S += abs(x[l]-x[l+1])+abs(y[l]-y[l+1]);
	}
	return S;
}
int main(){
	int H,W,D,A[H][W],i,j,Q,L[Q],R[Q],MP=0;
	cin >> H >> W >> D;
	for(i=0;i<H;i++){
		for(j=0;j<W;j++){
			cin >> A[i][j];
		}
	}
	cin >> Q;
	for(i=0;i<Q;i++){
		cin >> L[i] >> R[Q];
	}

	for(i=0;i<Q;i++){
		MP += count(H, W, D, A[H][W], L[Q], R[Q], k){
	}
	cout << MP << endl;
			
}


Compiler output:
a.cc: In function 'int count(int, int, int, int*, int*, int*, int)':
a.cc:5:24: error: 'x' was not declared in this scope
    5 |         int i, j=0,l=0;x[H*W],y[H*W],S;
      |                        ^
a.cc:5:31: error: 'y' was not declared in this scope
    5 |         int i, j=0,l=0;x[H*W],y[H*W],S;
      |                               ^
a.cc:5:38: error: 'S' was not declared in this scope
    5 |         int i, j=0,l=0;x[H*W],y[H*W],S;
      |                                      ^
a.cc:8:32: error: invalid types 'int[int]' for array subscript
    8 |                         if(A[i][j]==L[k]){
      |                                ^
a.cc:22:9: warning: no return statement in function returning non-void [-Wreturn-type]
   22 |         }
      |         ^
a.cc: At global scope:
a.cc:23:9: error: expected unqualified-id before 'return'
   23 |         return S;
      |         ^~~~~~
a.cc:24:1: error: expected declaration before '}' token
   24 | }
      | ^
a.cc: In function 'int main()':
a.cc:39:59: error: 'k' was not declared in this scope
   39 |                 MP += count(H, W, D, A[H][W], L[Q], R[Q], k){
      |                                                           ^
a.cc:43:2: error: expected '}' at end of input
   43 | }
      |  ^
a.cc:25:11: note: to match this '{'
   25 | int main(){
      |           ^
Language: Java

//package solve;
import java.util.*;
public class Main{

	public static void main(String[] args) {
		Scanner in=new Scanner(System.in);
		int N=in.nextInt(),H=in.nextInt(),d=in.nextInt();
		int num[]=new int[N*H];
		for(int i=0;i<N*H;i++)num[i]=in.nextInt();
		int Q=in.nextInt();
		while(Q-->0) {
			int L=in.nextInt(),R=in.nextInt();
			int	a = 0,b = 0;
			for(int i=0;i<num.length;i++)
				if(num[i]==L) {
					 a=(i+1)%H;b=(i+1)/H;
					break;
				}
			long sum=0;
			while(L<R+d) {
			for(int i1=0;i1<num.length;i1++) {
				if(num[i1]==L) {
					int n=(i1+1)%H,m=(i1+1)/H;
					sum+=Math.abs(n-a)+Math.abs(b-m);
					a=n;b=m;
					break;
				}
			}	
			L+=d;	
			}
			System.out.println(sum);
	}

}

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

#include <iostream>
using namespace std;

int count(int H, int W, int D, int A[H][W], int L[Q], int R[Q], int k){
	int i, j=0,l=0;x[H*W],y[H*W],S;
	while(L[k]!=R[k]){
		for(i=0;i<H;i++){
			if(A[i][j]==L[k]){
				x[l]=i;
				y[l]=j;
				l++;
				break;
			}
			else{j++;}
		}
		L[k] += D;
		i=0;
		j=0;
	}
	for(i=0;i<l-1;i++)
		S += abs(x[l]-x[l+1])+abs(y[l]-y[l+1]);
	}
	return S;
}
int main(){
	int H,W,D,A[H][W],i,j,Q,L[Q],R[Q],MP=0;
	cin >> H >> W >> D;
	for(i=0;i<H;i++){
		for(j=0;j<W;j++){
			cin >> A[i][j];
		}
	}
	cin >> Q;
	for(i=0;i<Q;i++){
		cin >> L[i] >> R[Q];
	}

	for(i=0;i<Q;i++){
		MP += count(H, W, D, A[H][W], L[Q], R[Q], k){
	}
	cout << MP << endl;
			
}


Compiler output:
a.cc:4:39: error: use of parameter outside function body before ']' token
    4 | int count(int H, int W, int D, int A[H][W], int L[Q], int R[Q], int k){
      |                                       ^
a.cc:4:42: error: use of parameter outside function body before ']' token
    4 | int count(int H, int W, int D, int A[H][W], int L[Q], int R[Q], int k){
      |                                          ^
a.cc:4:43: error: expected ')' before ',' token
    4 | int count(int H, int W, int D, int A[H][W], int L[Q], int R[Q], int k){
      |          ~                                ^
      |                                           )
a.cc:4:45: error: expected unqualified-id before 'int'
    4 | int count(int H, int W, int D, int A[H][W], int L[Q], int R[Q], int k){
      |                                             ^~~
a.cc:23:9: error: expected unqualified-id before 'return'
   23 |         return S;
      |         ^~~~~~
a.cc:24:1: error: expected declaration before '}' token
   24 | }
      | ^
a.cc: In function 'int main()':
a.cc:39:59: error: 'k' was not declared in this scope
   39 |                 MP += count(H, W, D, A[H][W], L[Q], R[Q], k){
      |                                                           ^
a.cc:43:2: error: expected '}' at end of input
   43 | }
      |  ^
a.cc:25:11: note: to match this '{'
   25 | int main(){
      |           ^
Language: C++

#include <iostream>
#include <stdlib.h>
using namespace std;

int main() {
  int total_cost(int H, int W, int A_place[][2], int L, int R, int D);
  int H, W, D;
  cin >> H >> W >> D;
  #define size1 H
  #define size2 W
  int A[size1][size2];
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> A[i][j];
    }
  }
  int Q;
  cin >> Q;
  int LR[Q][2];
  for (int i = 0; i < Q; i++) {
    for (int j = 0; j < 2; j++) {
      cin >> LR[i][j];
    }
  }
  int A_place[size1 * size2][2];
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      A_place[A[i][j]][0] = i;
      A_place[A[i][j]][1] = j;
    }
  }
  for (int i = 0; i < Q; i++) {
    cout << total_cost(H, W, A_place[size1 * size2][2], LR[i][0], LR[i][1], D) << endl;
  }
}

int cost(int A_place[][2], int x, int y) {
  int cost = abs(A_place[y][0] - A_place[x][0]) +
             abs(A_place[y][1] - A_place[x][1]);
  return cost;
}

int total_cost(int H, int W, int A_place[][2], int L, int R, int D) {
  int total = 0;
  for (int i = L; L < R; L += D) {
    total += cost(A_place[H * W][2], L, L + D);
  }
  return total;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:33:54: error: invalid conversion from 'int' to 'int (*)[2]' [-fpermissive]
   33 |     cout << total_cost(H, W, A_place[size1 * size2][2], LR[i][0], LR[i][1], D) << endl;
      |                              ~~~~~~~~~~~~~~~~~~~~~~~~^
      |                                                      |
      |                                                      int
a.cc:6:36: note:   initializing argument 3 of 'int total_cost(int, int, int (*)[2], int, int, int)'
    6 |   int total_cost(int H, int W, int A_place[][2], int L, int R, int D);
      |                                ~~~~^~~~~~~~~~~~
a.cc: In function 'int total_cost(int, int, int (*)[2], int, int, int)':
a.cc:46:35: error: invalid conversion from 'int' to 'int (*)[2]' [-fpermissive]
   46 |     total += cost(A_place[H * W][2], L, L + D);
      |                   ~~~~~~~~~~~~~~~~^
      |                                   |
      |                                   int
a.cc:37:14: note:   initializing argument 1 of 'int cost(int (*)[2], int, int)'
   37 | int cost(int A_place[][2], int x, int y) {
      |          ~~~~^~~~~~~~~~~~
Language: C

#include <cstdio>
#define MAXN 300
int abs(int x,int y)
{
	if(x>y)
		return x-y;
	else
		return y-x;

}

int hamiltondistance(int i1,int i2,int j1,int j2)
{
	//printf("(%d,%d),(%d,%d)\n",i1,j1,i2,j2);
	return abs(i1,i2)+abs(j1,j2);
}

int main(void)
{

	int i,j,H,W,D,s,N;
	int x1,x2,y1,y2;
	int r[MAXN][MAXN];
	scanf("%d %d %d",&H,&W,&D);
	for(i=0;i<H;i++)
		for(j=0;j<W;j++)
			scanf("%d",&r[i][j]);

	scanf("%d",&N);
	int target1,target2,curr,ckflag;
	while(N--){
		scanf("%d %d",&target1,&target2);
		ckflag=1;
		for(i=0;i<H && ckflag;i++)
			for(j=0;j<W && ckflag;j++)
			{
				if(r[i][j]==target1){
					x1=i+1;
					y1=j+1;
					ckflag=0;
				}
		}
		curr=target1+D;
		s=0;
		while(curr<=target2)
		{
			
			ckflag=1;
		for(i=0;i<H && ckflag;i++)
			for(j=0;j<W && ckflag;j++)
			{
				if(r[i][j]==curr){
					x2=i+1;
					y2=j+1;
					ckflag=0;
				}
		}
		curr=curr+D;
	ckflag=1;

		s+=hamiltondistance(x1,x2,y1,y2);
		x1=x2;
			y1=y2;
		}
		printf("%d\n",s);
	}

	return 0;
}

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

#include <iostream>
#include <stdlib.h>
using namespace std;

int main() {
  int total_cost(int H, int W, int A_place[][2], int L, int R, int D));
  int H, W, D;
  cin >> H >> W >> D;
  #define size1 H
  #define size2 W
  int A[size1][size2];
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> A[i][j];
    }
  }
  int Q;
  cin >> Q;
  int LR[Q][2];
  for (int i = 0; i < Q; i++) {
    for (int j = 0; j < 2; j++) {
      cin >> LR[i][j];
    }
  }
  int A_place[size1 * size2][2];
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      A_place[A[i][j]][0] = i;
      A_place[A[i][j]][1] = j;
    }
  }
  for (int i = 0; i < Q; i++) {
    cout << total_cost(H, W, A_place[size1 * size2][2], LR[i][0], LR[i][1]) << endl;
  }
}

int cost(int A_place[][2], int x, int y) {
  int cost = abs(A_place[y][0] - A_place[x][0]) +
             abs(A_place[y][1] - A_place[x][1]);
  return cost;
}

int total_cost(int H, int W, int A_place[][2], int L, int R, int D) {
  int total = 0;
  for (int i = L; L < R; L += D) {
    total += cost(A_place[H * W][2], L, L + D);
  }
  return total;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:6:70: error: expected initializer before ')' token
    6 |   int total_cost(int H, int W, int A_place[][2], int L, int R, int D));
      |                                                                      ^
a.cc:33:13: error: 'total_cost' was not declared in this scope
   33 |     cout << total_cost(H, W, A_place[size1 * size2][2], LR[i][0], LR[i][1]) << endl;
      |             ^~~~~~~~~~
a.cc: In function 'int total_cost(int, int, int (*)[2], int, int, int)':
a.cc:46:35: error: invalid conversion from 'int' to 'int (*)[2]' [-fpermissive]
   46 |     total += cost(A_place[H * W][2], L, L + D);
      |                   ~~~~~~~~~~~~~~~~^
      |                                   |
      |                                   int
a.cc:37:14: note:   initializing argument 1 of 'int cost(int (*)[2], int, int)'
   37 | int cost(int A_place[][2], int x, int y) {
      |          ~~~~^~~~~~~~~~~~
Language: C++

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

typedef pair<int, int> PII;

long long int dp[90001][90001];
vector<PII> place(90001);

long long int cal(int l, int r);


int main()
{
    int h, w, d, q;
    int i, j, k, p, m;
    
    cin >> h >> w >> d;
    
    int a[h][w];
    
    for(i = 0; i < h; i++) {
        for(j = 0; j < w; j++) {
            cin >> a[i][j];
            
            place[a[i][j]].first = j;
            place[a[i][j]].second = i;
        }
    }
    
    cin >> q;
    
    int l[q], r[q];
    long long int cost[q];
    
    for(k = 0; k < q; k++) {
        cin >> l[k] >> r[k];
        cost[k] = 0;
        
        if(l[k] != r[k]) {
            
            p = l[k];
            m = l[k] + d;
            
            while(m <= r[k]) {
                
                if(dp[p][m] != 0) {
                    cost[k] += dp[p][m];
                } else {
                    cost[k] += cal(p, m);
                }
                
                p += d; m += d;
            }
        }
    }
    
    for(k = 0; k < q; k++) {
         cout << cost[k] << endl;
    }
    
    return 0;
}

long long int cal(int l, int r)
{
    dp[l][r] = abs(place[l].first - place[r].first) + abs(place[l].second - place[r].second);
    
    return dp[l][r];
}

Compiler output:
/tmp/ccnElzWR.o: in function `main':
a.cc:(.text+0x1a8): relocation truncated to fit: R_X86_64_PC32 against symbol `place' defined in .bss section in /tmp/ccnElzWR.o
a.cc:(.text+0x1e2): relocation truncated to fit: R_X86_64_PC32 against symbol `place' defined in .bss section in /tmp/ccnElzWR.o
/tmp/ccnElzWR.o: in function `cal(int, int)':
a.cc:(.text+0x529): relocation truncated to fit: R_X86_64_PC32 against symbol `place' defined in .bss section in /tmp/ccnElzWR.o
a.cc:(.text+0x542): relocation truncated to fit: R_X86_64_PC32 against symbol `place' defined in .bss section in /tmp/ccnElzWR.o
a.cc:(.text+0x568): relocation truncated to fit: R_X86_64_PC32 against symbol `place' defined in .bss section in /tmp/ccnElzWR.o
a.cc:(.text+0x583): relocation truncated to fit: R_X86_64_PC32 against symbol `place' defined in .bss section in /tmp/ccnElzWR.o
/tmp/ccnElzWR.o: in function `__static_initialization_and_destruction_0()':
a.cc:(.text+0x61e): relocation truncated to fit: R_X86_64_PC32 against symbol `place' defined in .bss section in /tmp/ccnElzWR.o
a.cc:(.text+0x644): relocation truncated to fit: R_X86_64_PC32 against symbol `place' defined in .bss section in /tmp/ccnElzWR.o
collect2: error: ld returned 1 exit status
Language: C++

#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<queue>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<complex>
#define INF 2147483647
#define llINF 9223372036854775807
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long

using namespace std;
int main(){
  int h,w,d;
  cin>>h>>w>>d;
  pair<int,int> num[h*w+100]={};
  if(d<1000){
    int nu[d+1][h*w+10];
    int A[h+1][w+1]={};
    for(int i=0;i<h;i++)
      for(int j=0;j<w;j++){
	cin>>A[i][j];
	num[A[i][j]]=mp(i,j);
      }
    for(int i=1;i<=d;i++){
      for(int j=i;j<h*w;j++){
	if(j+d>h*w)break;
	nu[i][j+d]=nu[i][j]+abs(num[j].F-num[j+d].F)+abs(num[j].S-num[j+d].S);
      }
    }
    int q;cin>>q;
    for(int i=0;i<q;i++){
      int x,y;cin>>x>>y;
      cout<<nu[x/d][y]-nu[x/d][x]<<endl;
    }
  }else{
    int nu[h*w+10];
    int A[h+1][w+1]={};
    for(int i=0;i<h;i++)
      for(int j=0;j<w;j++){
	cin>>A[i][j];
	num[A[i][j]]=mp(i,j);
      }
    int q;cin>>q;
    for(int i=0;i<q;i++){
    int ans=0;
    int x,y;cin>>x>>y;
    while(x!=y){
      ans+=abs(num[x+d].F-num[x].F)+abs(num[x+d].S-num[x].S);
      x+=d;
    }
    cout<<ans<<endl;
  }
  return 0;
}


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

#include <iostream>
#include <stdlib.h>
using namespace std;

int main() {
  int H, W, D;
  cin >> H >> W >> D;
  #define size1 H
  #define size2 W
  int A[size1][size2];
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> A[i][j];
    }
  }
  int Q;
  cin >> Q;
  int LR[Q][2];
  for (int i = 0; i < Q; i++) {
    for (int j = 0; j < 2; j++) {
      cin >> LR[i][j];
    }
  }
  int A_place[size1 * size2][2];
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      A_place[A[i][j]][0] = i;
      A_place[A[i][j]][1] = j;
    }
  }
  for (int i = 0; i < Q; i++) {
    cout << total_cost(A_place[size1 * size2][2], LR[i][0], LR[i][1]) << endl;
  }
}

int cost(int A_place[][2], int x, int y) {
  int cost = abs(A_place[y][0] - A_place[x][0]) +
             abs(A_place[y][1] - A_place[x][1]);
  return cost;
}

int total_cost(int A_place[][2], int L, int R, int D) {
  int total = 0;
  for (int i = L; L < R; L += D) {
    total += cost(A_place[][2], L, L + D);
  }
  return total;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:32:13: error: 'total_cost' was not declared in this scope
   32 |     cout << total_cost(A_place[size1 * size2][2], LR[i][0], LR[i][1]) << endl;
      |             ^~~~~~~~~~
a.cc: In function 'int total_cost(int (*)[2], int, int, int)':
a.cc:45:27: error: expected primary-expression before ']' token
   45 |     total += cost(A_place[][2], L, L + D);
      |                           ^
Language: C++

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

typedef pair<int, int> PII;

long long int dp[90001][90001];
vector<PII> place(90001);

long long int cal(int l, int r);


int main()
{
    int h, w, d, q;
    int i, j, k, p, m;
    
    cin >> h >> w >> d;
    
    int a[h][w];
    
    for(i = 0; i < h; i++) {
        for(j = 0; j < w; j++) {
            cin >> a[i][j];
            
            place[a[i][j]].first = j;
            place[a[i][j]].second = i;
        }
    }
    
    cin >> q;
    
    int l[q], r[q];
    long long int cost[q];
    
    for(k = 0; k < q; k++) {
        cin >> l[k] >> r[k];
        cost[k] = 0;
        
        if(l[k] != r[k]) {
            
            p = l[k];
            m = l[k] + d;
            
            while(m <= r[k]) {
                
                if(dp[p][m] != 0) {
                    cost[k] += dp[p][m];
                } else {
                    cost[k] += cal(p, m);
                }
                
                p += d; m += d;
            }
        }
    }
    
    for(k = 0; k < q; k++) {
         cout << cost[k] << endl;
    }
    
    return 0;
}

long long int cal(int l, int r)
{
    dp[l][r] = abs(place[l].first - place[r].first) + abs(place[l].second - place[r].second);
    
    return dp[l][r];
}


Compiler output:
/tmp/cc3aFmED.o: in function `main':
a.cc:(.text+0x1a8): relocation truncated to fit: R_X86_64_PC32 against symbol `place' defined in .bss section in /tmp/cc3aFmED.o
a.cc:(.text+0x1e2): relocation truncated to fit: R_X86_64_PC32 against symbol `place' defined in .bss section in /tmp/cc3aFmED.o
/tmp/cc3aFmED.o: in function `cal(int, int)':
a.cc:(.text+0x529): relocation truncated to fit: R_X86_64_PC32 against symbol `place' defined in .bss section in /tmp/cc3aFmED.o
a.cc:(.text+0x542): relocation truncated to fit: R_X86_64_PC32 against symbol `place' defined in .bss section in /tmp/cc3aFmED.o
a.cc:(.text+0x568): relocation truncated to fit: R_X86_64_PC32 against symbol `place' defined in .bss section in /tmp/cc3aFmED.o
a.cc:(.text+0x583): relocation truncated to fit: R_X86_64_PC32 against symbol `place' defined in .bss section in /tmp/cc3aFmED.o
/tmp/cc3aFmED.o: in function `__static_initialization_and_destruction_0()':
a.cc:(.text+0x61e): relocation truncated to fit: R_X86_64_PC32 against symbol `place' defined in .bss section in /tmp/cc3aFmED.o
a.cc:(.text+0x644): relocation truncated to fit: R_X86_64_PC32 against symbol `place' defined in .bss section in /tmp/cc3aFmED.o
collect2: error: ld returned 1 exit status
Language: C++

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

int main() {
    int H, W, D;
    cin >> H >> W >> D;
    vector<pair<int, int>> r(H * W + 1);
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            int A;
            cin >> A;
            r[A] = { i, j };
        }
    }

    vector<int> cost(H * W + 1, -1);
    for (int i = 1; i <= D; i++) {
        pair<int, int> curr_sq = r[i];
        cost[i] = 0;

        int as = 0;
        for (int j = i + D; j <= H * W; j += D) {
            cost[j] = abs(r[j].first - curr_sq.first) + abs(r[j].second - curr_sq.second) + as;
            as = cost[j];
            curr_sq = r[j];
        }
    }

    int Q;
    cin >> Q;
    for (int i = 0; i < Q; i++) {
        int L, R;
        cin >> L >> R;
        cout << cost[R % D == 0 ? D : R % D][R] - cost[L % D == 0 ? D : L % D][L] << endl;
    }
}

Compiler output:
a.cc: In function 'int main()':
a.cc:34:45: error: invalid types '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type {aka int}[int]' for array subscript
   34 |         cout << cost[R % D == 0 ? D : R % D][R] - cost[L % D == 0 ? D : L % D][L] << endl;
      |                                             ^
a.cc:34:79: error: invalid types '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type {aka int}[int]' for array subscript
   34 |         cout << cost[R % D == 0 ? D : R % D][R] - cost[L % D == 0 ? D : L % D][L] << endl;
      |                                                                               ^
Language: C++

#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<queue>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<complex>
#define INF 2147483647
#define llINF 9223372036854775807
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long

using namespace std;
int main(){
  int h,w,d;
  cin>>h>>w>>d;
  pair<int,int> num[h*w+100]={};
  if(d<1000){
    int nu[d][h*w+10];
    int A[h+1][w+1]={};
    for(int i=0;i<h;i++)
      for(int j=0;j<w;j++){
	cin>>A[i][j];
	num[A[i][j]]=mp(i,j);
      }
    for(int i=1;i<=d;i++){
      for(int j=i;j<h*w;j++){
	if(j+d>h*w)break;
	nu[j+d]=nu[j]+abs(num[j].F-num[j+d].F)+abs(num[j].S-num[j+d].S);
      }
    }
    int q;cin>>q;
    for(int i=0;i<q;i++){
      int x,y;cin>>x>>y;
      cout<<nu[x/d][y]-nu[x/d][x]<<endl;
    }
  }else{
    int nu[h*w+10];
    int A[h+1][w+1]={};
    for(int i=0;i<h;i++)
      for(int j=0;j<w;j++){
	cin>>A[i][j];
	num[A[i][j]]=mp(i,j);
      }
    int q;cin>>q;
    for(int i=0;i<q;i++){
    int ans=0;
    int x,y;cin>>x>>y;
    while(x!=y){
      ans+=abs(num[x+d].F-num[x].F)+abs(num[x+d].S-num[x].S);
      x+=d;
    }
    cout<<ans<<endl;
  }
  return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:36:16: error: incompatible types in assignment of 'int*' to 'int [((h * w) + 10)]'
   36 |         nu[j+d]=nu[j]+abs(num[j].F-num[j+d].F)+abs(num[j].S-num[j+d].S);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:63:2: error: expected '}' at end of input
   63 | }
      |  ^
a.cc:21:11: note: to match this '{'
   21 | int main(){
      |           ^
Language: C++

#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>

using namespace std;

#define PB push_back
#define MP make_pair
#define F first
#define S second

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

const int MOD = 1e9+7;
const int INF = 1e9;
const int MAX_HW = 300;

int H, W, D, Q, L, R;
int dist[MAX_HW*MAX_HW][MAX_HW*MAX_HW];
pii A[MAX_HW * MAX_HW];

int main() {
  cin >> H >> W >> D;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      int tmp;
      // cin >> tmp; tmp--;
      A[i*W + j] = MP(i, j);
    }
  }
  for (int i = 0; i < H * W; i++) {
    int p = i;
    while (p + D < H * W) {
      int np = p + D;
      if (dist[i][np] != 0) break;
      dist[i][np] = dist[i][p] + abs(A[np].F - A[p].F) + abs(A[np].S - A[p].S);
      p = np;
    }
  }

  int ans = 0;
  cin >> Q;
  for (int i = 0; i < Q; i++) {
    cin >> L >> R; L--; R--;
    cout << dist[L][R]<< endl;
  }
  return 0;
}


Compiler output:
/tmp/ccr6xu8m.o: in function `main':
a.cc:(.text+0x92): relocation truncated to fit: R_X86_64_PC32 against symbol `A' defined in .bss section in /tmp/ccr6xu8m.o
a.cc:(.text+0x15f): relocation truncated to fit: R_X86_64_PC32 against symbol `A' defined in .bss section in /tmp/ccr6xu8m.o
a.cc:(.text+0x177): relocation truncated to fit: R_X86_64_PC32 against symbol `A' defined in .bss section in /tmp/ccr6xu8m.o
a.cc:(.text+0x19a): relocation truncated to fit: R_X86_64_PC32 against symbol `A' defined in .bss section in /tmp/ccr6xu8m.o
a.cc:(.text+0x1b2): relocation truncated to fit: R_X86_64_PC32 against symbol `A' defined in .bss section in /tmp/ccr6xu8m.o
collect2: error: ld returned 1 exit status
Language: C++

#include <iostream>
using namespace std;

count(int *p, int H, int W, int D, int L, int R, int k){
	int i, j=0,x,y;
	while(L[k]!=R[k]){
		for(i=0;i<H;i++){
			if(A[i][j]==L[k]){
				x=i;
				y=j;
				break;
			}
			else{j++;}
		}
		L[k] += D;
		*p += abs(x-i) + abs (y-j);
		i=0;
		j=0;
	}
}
int main(){
	int H,W,D,A[H][W],i,j,Q,L[Q],R[Q],MP=0,*p=&MP;
	cin >> H >> W >> D;
	for(i=0;i<H;i++){
		for(j=0;j<W;j++){
			cin >> A[i][j];
		}
	}
	cin >> Q;
	for(i=0;i<Q;i++){
		cin >> L[i] >> R[Q];
	}

	for(i=0;i<Q;i++){
		count(*p,H, W, D, L, R, i);
	}
	cout << MP << endl;
			
}


Compiler output:
a.cc:4:1: error: ISO C++ forbids declaration of 'count' with no type [-fpermissive]
    4 | count(int *p, int H, int W, int D, int L, int R, int k){
      | ^~~~~
a.cc: In function 'int count(int*, int, int, int, int, int, int)':
a.cc:6:16: error: invalid types 'int[int]' for array subscript
    6 |         while(L[k]!=R[k]){
      |                ^
a.cc:6:22: error: invalid types 'int[int]' for array subscript
    6 |         while(L[k]!=R[k]){
      |                      ^
a.cc:8:28: error: 'A' was not declared in this scope
    8 |                         if(A[i][j]==L[k]){
      |                            ^
a.cc:8:38: error: invalid types 'int[int]' for array subscript
    8 |                         if(A[i][j]==L[k]){
      |                                      ^
a.cc:15:18: error: invalid types 'int[int]' for array subscript
   15 |                 L[k] += D;
      |                  ^
a.cc:20:1: warning: no return statement in function returning non-void [-Wreturn-type]
   20 | }
      | ^
a.cc: In function 'int main()':
a.cc:35:23: error: invalid conversion from 'int' to 'int*' [-fpermissive]
   35 |                 count(*p,H, W, D, L, R, i);
      |                       ^~
      |                       |
      |                       int
a.cc:4:12: note:   initializing argument 1 of 'int count(int*, int, int, int, int, int, int)'
    4 | count(int *p, int H, int W, int D, int L, int R, int k){
      |       ~~~~~^
a.cc:35:35: error: invalid conversion from 'int*' to 'int' [-fpermissive]
   35 |                 count(*p,H, W, D, L, R, i);
      |                                   ^
      |                                   |
      |                                   int*
a.cc:4:40: note:   initializing argument 5 of 'int count(int*, int, int, int, int, int, int)'
    4 | count(int *p, int H, int W, int D, int L, int R, int k){
      |                                    ~~~~^
a.cc:35:38: error: invalid conversion from 'int*' to 'int' [-fpermissive]
   35 |                 count(*p,H, W, D, L, R, i);
      |                                      ^
      |                                      |
      |                                      int*
a.cc:4:47: note:   initializing argument 6 of 'int count(int*, int, int, int, int, int, int)'
    4 | count(int *p, int H, int W, int D, int L, int R, int k){
      |                                           ~~~~^
Language: C++

#include <iostream>
#include <algorithm>
#include <array>

long main()
{
    long H, W, D;
    std::array<std::array<long, 2>, 90000> map{};
    std::cin >> H >> W >> D;
    for (auto i = 0; i < H; i++) {
        for (auto j = 0; j < W; j++) {
            long z;
            std::cin >> z;
            map.at(z) = {i, j};
        }
    }
    long Q;
    std::cin >> Q;

    for (auto i = 0; i < Q; i++) {
        long L, R;
        std::cin >> L >> R;
        std::array<long, 2> pre = map.at(L);
        long power = 0;
        for (auto x = L + D; x <= R; x += D) {
            std::array<long, 2> now = map.at(x);
            power += std::abs(pre.at(0) - now.at(0)) + std::abs(pre.at(1) - now.at(1));
            pre = map.at(x);
        }
        std::cout << power << std::endl;
    }

    return 0;
}

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

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

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

    int H, W, D;
    //cin >> H >> W >> D;
    scanf_s("%d%d%d", &H, &W, &D);
    vector<pair<int, int>> r(H * W + 1);
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            int A;
            //cin >> A;
            scanf_s("%d", &A);
            r[A] = { i, j };
        }
    }

    vector<vector<int>> cost(D + 1, vector<int>(H * W + 1, -1));
    for (int i = 1; i <= D; i++) {
        pair<int, int> curr_sq = r[i];
        cost[i][i] = 0;

        int as = 0;
        for (int j = i + D; j <= H * W; j += D) {
            cost[i][j] = abs(r[j].first - curr_sq.first) + abs(r[j].second - curr_sq.second) + as;
            as = cost[i][j];
            curr_sq = r[j];
        }
    }

    int Q;
    //cin >> Q;
    scanf_s("%d", &Q);
    for (int i = 0; i < Q; i++) {
        int L, R;
        //cin >> L >> R;
        scanf_s("%d%d", &L, &R);
        //cout << cost[R % D == 0 ? D : R % D][R] - cost[L % D == 0 ? D : L % D][L] << endl;
        printf("%d\n", cost[R % D == 0 ? D : R % D][R] - cost[L % D == 0 ? D : L % D][L]);
    }
}

Compiler output:
a.cc: In function 'int main()':
a.cc:11:5: error: 'scanf_s' was not declared in this scope; did you mean 'scanf'?
   11 |     scanf_s("%d%d%d", &H, &W, &D);
      |     ^~~~~~~
      |     scanf
Language: C++

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

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

    int H, W, D;
    //cin >> H >> W >> D;
    scanf_s("%d%d%d", &H, &W, &D);
    vector<pair<int, int>> r(H * W + 1);
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            int A;
            //cin >> A;
            scanf_s("%d", &A);
            r[A] = { i, j };
        }
    }

    vector<vector<int>> cost(D + 1, vector<int>(H * W + 1, -1));
    for (int i = 1; i <= D; i++) {
        pair<int, int> curr_sq = r[i];
        cost[i][i] = 0;

        int as = 0;
        for (int j = i + D; j <= H * W; j += D) {
            cost[i][j] = abs(r[j].first - curr_sq.first) + abs(r[j].second - curr_sq.second) + as;
            as = cost[i][j];
            curr_sq = r[j];
        }
    }

    int Q;
    //cin >> Q;
    scanf_s("%d", &Q);
    for (int i = 0; i < Q; i++) {
        int L, R;
        //cin >> L >> R;
        scanf_s("%d%d", &L, &R);
        //cout << cost[R % D == 0 ? D : R % D][R] - cost[L % D == 0 ? D : L % D][L] << endl;
        printf("%d\n", cost[R % D == 0 ? D : R % D][R] - cost[L % D == 0 ? D : L % D][L]);
    }
}

Compiler output:
a.cc: In function 'int main()':
a.cc:10:5: error: 'scanf_s' was not declared in this scope; did you mean 'scanf'?
   10 |     scanf_s("%d%d%d", &H, &W, &D);
      |     ^~~~~~~
      |     scanf
Language: C++

#include <cstdio>
#include <cstring>
#include <cmath>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <stack>
using namespace std;

#define ll long long
#define mst(a) memset(a, 0, sizeof a)

const int mod = 1e9+7;
const int maxn = 1e5+50;
const int inf = 1e9;

int x[maxn], y[maxn];
ll pre[maxn];

int main()
{
    \\freopen("in", "r", stdin);
    int n, m, d;
    scanf("%d %d %d", &n, &m, &d);
    for (int i = 0; i < n; ++i)
        for (int j = 0; j < m; ++j)
        {
            int a;
            scanf("%d", &a);
            x[a] = i;
            y[a] = j;
        }
    mst(pre);
    for (int i = 1; i <= d; ++i)
    {
        int p = i+d;
        while (p <= n*m)
        {
            pre[p] = pre[p-d] + abs(x[p]-x[p-d]) + abs(y[p]-y[p-d]);
            p += d;
        }
    }
    int Q;
    scanf("%d", &Q);
    while (Q--)
    {
        int l, r;
        scanf("%d %d", &l, &r);
        printf("%lld\n", pre[r]-pre[l]);
    }
    return 0;
}

Compiler output:
a.cc:27:5: error: stray '\' in program
   27 |     \\freopen("in", "r", stdin);
      |     ^
a.cc:27:6: error: stray '\' in program
   27 |     \\freopen("in", "r", stdin);
      |      ^
Language: C++

#include <bits/stdc++.h>

using namespace std;

struct Node { 
	int x, y;
}S[90001];
int sum[301][301];
int res;
int n;
int m;
int d;

int main() {
	scanf("%d%d%d", &n, &m, &d);
	for(int i = 1; i <= n; i++)
		for(int j = 1; j <= m; j++){
			int k;
			scanf("%d", &k);
			S[k].x = i;
			S[k].y = j;
		}
	for(int i = d + 1; i <= n * m; i++)
		sum[i] = sum[i - d] + abs(S[i].x - S[i - d].x) + abs(S[i].y - S[i - d].y);
	int Q;
	scanf("%d", &Q);
	while(Q--) {
		int l, r;
		scanf("%d%d", &l, &r);
		printf("%d\n", sum[r] - sum[l]);
		res = 0;
	}
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:24:24: error: incompatible types in assignment of 'int*' to 'int [301]'
   24 |                 sum[i] = sum[i - d] + abs(S[i].x - S[i - d].x) + abs(S[i].y - S[i - d].y);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Language: C++

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

#define rep(i,st,en) for(int i=st;i<=en;i++)
#define eps 1e-8
#define PI acos(-1.0)
#define INF 0x3f3f3f3f
#define FAST_IO ios::sync_with_stdio(false)

const int N=555;
typedef long long LL;
const LL MOD=1000000007;
LL a[N][N];
LL ans[N];
map < LL, pair<LL,LL> > M;

int main(){
    pair <LL,LL> p,now;
    FAST_IO;
    LL n,m,d,q;
    cin>>n>>m>>d;
    for(LL i=1;i<=n;i++){
        for(LL j=1;j<=m;j++){
            cin>>a[i][j];
            p.first=i;p.second=j;
            M[a[i][j]]=p;
        }
    }
    LL sum=0;
    now=
    for(LL i=1+d;i<=n*m;i+=d){
        p=M[i];
        sum+=abs(p.first-now.first)+abs(p.second-now.second);
        ans[i]=sum;
        now=p;
    }
    sum=0;
    now.first=0;now.second=0;
    for(LL i=2;i<=n*m;i+=d){
        p=M[i];
        sum+=abs(p.first-now.first)+abs(p.second-now.second);
        ans[i]=sum;
        now=p;
    }

    LL l,r;
    cin>>q;
    while(q--){
        cin>>l>>r;
        cout<<ans[r]-ans[l-1]<<endl;
    }
    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:31:5: error: expected primary-expression before 'for'
   31 |     for(LL i=1+d;i<=n*m;i+=d){
      |     ^~~
a.cc:31:18: error: 'i' was not declared in this scope
   31 |     for(LL i=1+d;i<=n*m;i+=d){
      |                  ^
Language: C++

#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
 
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=(n)-1;i>=0;i--)
#define VSORT(v) sort(v.begin(), v.end())
#define DVSORT(v) sort(v.begin(), v.end(),greater<int>())
#define SORT(v, n) sort(v, v+n)
#define DSORT(v,n) sort(v, v+n,greater<int>())
#define vi vector<int>
#define pb push_back
#define P pair<int,int>
#define Pll pair<ll,ll>

template <class T> void chmin(T&a,const T&b) { a = min(a,b); }
template <class T> void chmax(T&a,const T&b) { a = max(a,b); }
 
void print(){cout<<endl;}
template <class Head, class... Tail>
void print(Head&& h,Tail&&... t){ 
	if(sizeof...(t)==0)
		cout<<h;
	else
		cout<<h<<' ';
	print(move(t)...);
}
 
const double EPS =1e-9;
const int INF =2e+9;
const ll INFL =9e+18;
const long MOD =1e+9+7;
#define PI 3.14159265258979

int dy[]={0, 0, 1, -1, 1, 1, -1, -1};
int dx[]={1, -1, 0, 0, 1, -1, -1, 1};

int main(void){
	int H,W,D,A,Q,L,R;
	map<int,P> mp;
	map<P,int> mp2;
	
	cin>>H>>W>>D;
	REP(i,H){
		REP(j,W){
			cin>>A;
			mp[A]=P(i+1,j+1);
		}
	}

	cin>>Q;
	REP(i,Q){
		ll sum=0;
		cin>>L>>R;
		if(L==R) print(0);
		else{
			while(1){
				if(mp[L]==mp[R]) break;
				else{
					sum+=(ll)abs(mp[L+D].first-mp[L].first);
					sum+=(ll)abs(mp[L+D].second-mp[L].second);
					L+=D;
				}
			}
			print(sum);
		}
	return 0;
}




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