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

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
int main(){
  int h,w,d;cin>>h>>w>>d;
  int mp[h][w];
  vector<pair<int,pair<int,int> > > a[d];
  for(int i = 0; h > i; i++){
    for(int j = 0; w > j; j++){
      cin>>mp[i][j];
      a[mp[i][j]%d].push_back(make_pair(mp[i][j],make_pair(i,j)));
    }
  }
  int q;cin>>q;
  for(int _ = 0; q > _; _++){
    int x,y;cin>>x>>y;
    sort(a[x%d].begin(),a[x%d].end());
    long long ans = 0;
    for(int i = 1; a.size() > i; i++){
      ans += abs(a[i].second.first-a[i-1].second.first)+abs(a[i].second.second-a[i-1].second.second);
    }
    cout << ans << endl;
  }
}    

Compiler output:
a.cc: In function 'int main()':
a.cc:21:22: error: request for member 'size' in 'a', which is of non-class type 'std::vector<std::pair<int, std::pair<int, int> > > [d]'
   21 |     for(int i = 1; a.size() > i; i++){
      |                      ^~~~
a.cc:22:23: error: 'class std::vector<std::pair<int, std::pair<int, int> > >' has no member named 'second'
   22 |       ans += abs(a[i].second.first-a[i-1].second.first)+abs(a[i].second.second-a[i-1].second.second);
      |                       ^~~~~~
a.cc:22:43: error: 'class std::vector<std::pair<int, std::pair<int, int> > >' has no member named 'second'
   22 |       ans += abs(a[i].second.first-a[i-1].second.first)+abs(a[i].second.second-a[i-1].second.second);
      |                                           ^~~~~~
a.cc:22:66: error: 'class std::vector<std::pair<int, std::pair<int, int> > >' has no member named 'second'
   22 |       ans += abs(a[i].second.first-a[i-1].second.first)+abs(a[i].second.second-a[i-1].second.second);
      |                                                                  ^~~~~~
a.cc:22:87: error: 'class std::vector<std::pair<int, std::pair<int, int> > >' has no member named 'second'
   22 |       ans += abs(a[i].second.first-a[i-1].second.first)+abs(a[i].second.second-a[i-1].second.second);
      |                                                                                       ^~~~~~
Language: C++

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
typedef nwt pair<int,pair<int,int> >
int main(){
  int h,w,d;cin>>h>>w>>d;
  int mp[h][w];
  for(int i = 0; h > i; i++){
    for(int j = 0; w > j; j++){
      cin>>mp[i][j];
    }
  }
  int q;cin>>q;
  for(int z = 0; q > z; z++){
    int x,y;cin>>x>>y;
    vector<nwt> a;
    for(int i = 0; h > i; i++){
      for(int j = 0; w > j; j++){
        if(mp[i][j] <= y && x <= mp[i][j] && (mp[i][j]-x)%d==0){
          a.push_back(make_pair(mp[i][j],make_pair(i,j)));
        }
      }
    }
    sort(a.begin(),a.end());
    long long ans = 0;
    for(int i = 1; a.size() > i; i++){
      ans += abs(a[i].second.first-a[i-1].second.first)+abs(a[i].second.second-a[i-1].second.second);
    }
    cout << ans << endl;
  }
}    

Compiler output:
a.cc:6:9: error: 'nwt' does not name a type
    6 | typedef nwt pair<int,pair<int,int> >
      |         ^~~
Language: C++

#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
ll mod = 1000000007;

int main() {
    int h, w, d, a, q, l, r;
    int px[90010], py[90010], dist[90010] = {};
    cin >> h >> w >> d;
    rep(i, h) {
        rep(j, w) {
            cin >> a;
            px[a] = i;
            py[a] = j;
        }    
    }

    for(int i = d+1; i <= h*w; i++) {
        dist[i] = dist[i-d] + abs(px[i] - px[i-d]) + abs(py[i] - py[i-d]);
    }

    cin >> q;
    while(q--) {
        cin >> l >> r;
        cout << d[r] - d[l] << "\n";
    }

    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:33:18: error: invalid types 'int[int]' for array subscript
   33 |         cout << d[r] - d[l] << "\n";
      |                  ^
a.cc:33:25: error: invalid types 'int[int]' for array subscript
   33 |         cout << d[r] - d[l] << "\n";
      |                         ^
Language: C++

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func main() {
	fp := os.Stdin
	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(os.Stdout)

	h := getNextInt(scanner)
	w := getNextInt(scanner)
	d := getNextInt(scanner)
	var aa [300][300]int

	points := make([]Point, h*w)
	sums := make([]int, h*w)

	for y := 0; y < h; y++ {
		for x := 0; x < w; x++ {
			aa[y][x] = getNextInt(scanner) - 1
			points[aa[y][x]] = Point{
				x: x,
				y: y,
			}
		}
	}
	for i := 0; i < h*w; i++ {
		if i-d < 0 {
			continue
		}
		sums[i] = sums[i-d]
		sums[i] += absint(points[i].x-points[i-d].x) + absint(points[i].y-points[i-d].y)
	}
	q := getNextInt(scanner)

	for i := 0; i < q; i++ {
		l := getNextInt(scanner) - 1
		r := getNextInt(scanner) - 1
		fmt.Fprintln(writer, sums[r]-sums[l])
	}

	writer.Flush()
}

type Point struct {
	x, y int
}

func absint(a int) int {
	if a < 0 {
		return -a
	}
	return a
}


Compiler output:
a.cc:1:1: error: 'package' does not name a type
    1 | package main
      | ^~~~~~~
a.cc:17:1: error: 'func' does not name a type
   17 | func getNextString(scanner *bufio.Scanner) string {
      | ^~~~
a.cc:22:1: error: 'func' does not name a type
   22 | func getNextInt(scanner *bufio.Scanner) int {
      | ^~~~
a.cc:27:1: error: 'func' does not name a type
   27 | func getNextInt64(scanner *bufio.Scanner) int64 {
      | ^~~~
a.cc:32:1: error: 'func' does not name a type
   32 | func main() {
      | ^~~~
a.cc:76:1: error: 'type' does not name a type; did you mean 'typeof'?
   76 | type Point struct {
      | ^~~~
      | typeof
a.cc:80:1: error: 'func' does not name a type
   80 | func absint(a int) int {
      | ^~~~
Language: C++

#include < cstdio >
#define abs ( x ) (( x >0)? x :( -( x )))
int H ,W ,D , A ;
int Q ,L , R ;
int px [90001] , py [90001];
int d [90001];
int main ()
{
scanf ("% d % d % d " ,&H ,& W ,& D );
for ( int i =0; i < H ; i ++)
{
for ( int j =0; j < W ; j ++)
{
scanf ("% d " ,& A );
px [ A ]= i , py [ A ]= j ;
}
}
for ( int i = D +1; i <= H * W ; i ++)
d[ i ]= d [i - D ]+ abs ( px [ i ] - px [i - D ])+ abs ( py [ i ] - py [i - D ]);
scanf ("% d " ,& Q );
while (Q - -)
{
scanf ("% d % d " ,&L ,& R );
printf ("% d \ n " , d [ R ] - d [ L ]);
}
}


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

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

using namespace std;

int dis(pair<int,int> x,pair<int,int> y){
    return (abs(x.first-y.first)+abs(x.second-y.second));
}

int main(){
    int h,w,d;
    cin >> h >> w >> d;
    vector<pair<int,int>> da(h*w);
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            int x;
            cin >> x;
            da[x-1]=make_pair(i,j);
        }
    }
    vector<vector<int>> dp(d,vector<int>(0));
    for(int i=0;i<h*w;i++){
        int x=i%d,y=i/d;
        if (y==0){
            dp[x].push_back(0);
        }
        else{
            dp[x].push_back(dp[x][dp[x].size()-1]+dis(da[i],da[i-d]));
        }
    }
    int q;
    cin >> q;
    for(int i=0;i<q;i++){
        int ans=0
        int r,l;
        cin >> l >> r;
        ans=(long long)ans+dp[(r-1)%d][(r-1)/d]-dp[(l-1)%d][(l-1)/d];
    	cout << ans << endl;
    }
}

Compiler output:
a.cc: In function 'int main()':
a.cc:42:9: error: expected ',' or ';' before 'int'
   42 |         int r,l;
      |         ^~~
a.cc:43:16: error: 'l' was not declared in this scope
   43 |         cin >> l >> r;
      |                ^
a.cc:43:21: error: 'r' was not declared in this scope
   43 |         cin >> l >> r;
      |                     ^
Language: C++

#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
const double PI = acos(-1);
const double EPS = 1e-15;
long long INF=(long long)1E17;
#define i_7 (long long)(1E9+7)
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
using namespace std;
bool prime(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}

long long gcd(long long a, long long b){
  if(a<b){
    swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd(b,a%b);
  }
}
 
long long lcm(long long x, long long y){
  return (x/gcd(x,y))*y;
}
 
class UnionFind {
    public:
    //各頂点の親の番号を格納する。その頂点自身が親だった場合は-(その集合のサイズ)を入れる。
    vector<int> Parent;
    
    //クラスを作るときは、Parentの値を全て-1にする。
    //以下のようにすると全てバラバラの頂点として解釈できる。
    UnionFind(int N) {
        Parent = vector<int>(N, -1);
    }
    
    //Aがどのグループに属しているか調べる
    int root(int A) {
        if (Parent[A] < 0) return A;
        return Parent[A] = root(Parent[A]);
    }
    
    //自分のいるグループの頂点数を調べる
    int size(int A) {
        return -Parent[root(A)];//先祖をrootで取っておきたい。
    }
    
    //AとBをくっ付ける
    bool connect(int A, int B) {
        //AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
        A = root(A);
        B = root(B);
        if (A == B) {
            //すでにくっついてるからくっ付けない
            return false;
        }
        
        //大きい方(A)に小さいほう(B)をくっ付けたい
        //大小が逆だったらAとBをひっくり返す。
        if (size(A) < size(B)) swap(A, B);
        
        //Aのサイズを更新する
        Parent[A] += Parent[B];
        //Bの親をAに変更する
        Parent[B] = A;
        
        return true;
    }
};

struct Position{
  int x;int y;
}

int main(){
  int h,w,d;
  cin>>h>>w>>d;
  int a[h][w];
  vector<Position> numToPos(h*w);
  REP(i,h){
    REP(j,w){
      cin>>a[i][j];
      a[i][j]--;
      numToPos[a[i][j]]=Position{i,j};
    }
  }
  
  vector<int> dist[d];
  int temp;
  Position pos;
  REP(i,d){
    temp=i;
    dist[i].push_back(0);
    while(temp<h*w){
      dist[i].push_back(dist[i][(temp-i)/d]+abs(numToPos[temp+d].x-numToPos[temp].x)+abs(numToPos[temp+d].y-numToPos[temp].y));
      temp += d;
    }
  }
  
  int q;
  cin>>q;
  int l,r;
  int rest;
  int res;
  REP(i,q){
    cin>>l>>r;
    l--;r--;
    rest = l%d;
    res = dist[rest][r/d]-dist[rest][l/d];
    cout<<res<<endl;
  }
  
  return 0;
}


Compiler output:
a.cc:91:2: error: expected ';' after struct definition
   91 | }
      |  ^
      |  ;
Language: C++

#include <iostream>

using namespace std;
typedef pair<int, int> P;
const int MAXH = 301;
const int MAXW = 301;
const int MAXQ = 1e5 + 10;

int a[MAXH][MAXW];
P field[MAXH*MAXW];
bool visited[MAXH*MAXW];
int cost[MAXH*MAXW][MAXH*MAXW];
int l[MAXQ], r[MAXQ];

int h, w, d, q;
void solve() {
  for (int y=0;y<h;y++) {
    for (int x=0;x<w;x++) {
      field[a[y][x] - 1] = P(x, y);
    }
  }

  for (int i=0;i<=w*h;i++) {
    if (!visited[i]) {
      cost[i][0] = 0;
      for (int j=1;i + j * d<=w*h;j++) {
        visited[i + j * d] = true;
        P& p1 = field[i + (j-1) * d];
        P& p2 = field[i + j * d];
        cost[i][j] = cost[i][j-1] + abs(p1.first - p2.first) + abs(p1.second - p2.second);
      }
    }
  }


  for (int i=0;i<q;i++) {
    l[i]--;r[i]--;
    int start = l[i] % d;
    cout << (cost[start][(r[i] - start) / d] - cost[start][(l[i] - start) / d]) << endl;
  }
}

int main() {
  cin >> h >> w >> d;
  for (int y=0;y<h;y++) {
    for (int x=0;x<w;x++) {
      cin >> a[y][x];
    }
  }
  cin >> q;
  for (int i=0;i<q;i++) {
    cin >> l[i] >> r[i];
  }
  solve();
}


Compiler output:
/tmp/cc0lORG8.o: in function `solve()':
a.cc:(.text+0x8f): relocation truncated to fit: R_X86_64_PC32 against symbol `w' defined in .bss section in /tmp/cc0lORG8.o
a.cc:(.text+0xa5): relocation truncated to fit: R_X86_64_PC32 against symbol `h' defined in .bss section in /tmp/cc0lORG8.o
a.cc:(.text+0x100): relocation truncated to fit: R_X86_64_PC32 against symbol `d' defined in .bss section in /tmp/cc0lORG8.o
a.cc:(.text+0x124): relocation truncated to fit: R_X86_64_PC32 against symbol `d' defined in .bss section in /tmp/cc0lORG8.o
a.cc:(.text+0x14a): relocation truncated to fit: R_X86_64_PC32 against symbol `d' defined in .bss section in /tmp/cc0lORG8.o
a.cc:(.text+0x1fe): relocation truncated to fit: R_X86_64_PC32 against symbol `d' defined in .bss section in /tmp/cc0lORG8.o
a.cc:(.text+0x210): relocation truncated to fit: R_X86_64_PC32 against symbol `w' defined in .bss section in /tmp/cc0lORG8.o
a.cc:(.text+0x216): relocation truncated to fit: R_X86_64_PC32 against symbol `h' defined in .bss section in /tmp/cc0lORG8.o
a.cc:(.text+0x22b): relocation truncated to fit: R_X86_64_PC32 against symbol `w' defined in .bss section in /tmp/cc0lORG8.o
a.cc:(.text+0x231): relocation truncated to fit: R_X86_64_PC32 against symbol `h' defined in .bss section in /tmp/cc0lORG8.o
a.cc:(.text+0x25d): additional relocation overflows omitted from the output
collect2: error: ld returned 1 exit status
Language: C++


def main():
    buf = input()
    buflist = buf.split()
    H = int(buflist[0])
    W = int(buflist[1])
    D = int(buflist[2])
    board = []
    for i in range(H):
        buf = input()
        buflist = buf.split()
        board.append(list(map(int, buflist)))
    buf = input()
    Q = int(buf)
    query = []
    for i in range(Q):
        buf = input()
        buflist = buf.split()
        L = int(buflist[0])
        R = int(buflist[1])
        query.append((L, R))
    moddivxy = []
    for i in range(H):
        for j in range(W):
            moddivxy.append((board[i][j] % D, board[i][j] // D, i, j))
    moddivxy = list(sorted(moddivxy))
    mp_table = [[0]]
    mod = 0
    last_xy = (-1, -1)
    for x in moddivxy:
        if x[0] == 0 and x[1] == 1: # first element
            mp_table[mod].append(0)
        elif x[0] > mod:
            mod = x[0]
            mp_table.append([0])
        else:
            mp_table[mod].append(mp_table[mod][-1] + abs(last_xy[0] - x[2]) + abs(last_xy[1] - x[3]))
        last_xy = (x[2], x[3])
    for q in query:
        m = q[0] % D
        d_start = q[0] // D
        d_end = q[1] // D
        print(mp_table[m][d_end] - mp_table[m][d_start])


if __name__ == '__main__':
    main()


Compiler output:
a.cc:31:37: error: stray '#' in program
   31 |         if x[0] == 0 and x[1] == 1: # first element
      |                                     ^
a.cc:46:16: warning: multi-character literal with 8 characters exceeds 'int' size of 4 bytes
   46 | if __name__ == '__main__':
      |                ^~~~~~~~~~
a.cc:2:1: error: 'def' does not name a type
    2 | def main():
      | ^~~
Language: Java

import java.util.*;
import static java.lang.System.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		D(sc);
	}
	public static void D(Scanner sc) {
		int H = sc.nextInt();
		int W = sc.nextInt();
		int D = sc.nextInt();
		HashMap<Integer, int[]> map = new HashMap<Integer, int[]>();
		for(int i=1;i<H+1;i++) {
			for(int j=1;j<W+1;j++) {
				map.put(sc.nextInt(),new int[] {i,j});
			}
		}
		int[] dist = makedist2(map,D,H*W);
		int q = sc.nextInt();
		for(int i=0;i<q;i++) {
			int l = sc.nextInt();
			int r = sc.nextInt();
			out.println(dist[r]-dist[l]);
		}
		
	}
	
	//
	public static int[] makedist2(HashMap<Integer, int[]> map, int d, int hw) {
		int[] ret = new int[hw+1];
		for(int i=1;i<=d;i++) {
			for(int j=i+d;j<=hw;j++) {
				ret[j] = ret[j-d]+ Math.abs(map.get(j)[0]-map.get(j-d)[0]) + Math.abs(map.get(j)[1]-map.get(j-d)[1]);
			}
		}
		return ret;
	}


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

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

using namespace std;

#define lli long long int
#define REP(i,n) for(int i=0;i<n;i++)
#define REP2(i,n) for(int i=1;i<=n;i++)
#define DEBUG 0

lli px[90001],py[90001];
lli  d[90001];

int main(){

	lli h,w,d;
	cin>>h>>w>>d;

	REP(i,h)REP(j,w){
		lli num;
		cin>>num;
		px[num]=i;
		py[num]=j;
	}

	for(lli i=d+i;i<=h*w;j++){
		d[i]=d[i-d]+abs(px[i]-px[i-d])+abs(py[i]-py[i-d]);
	}

	lli q;
	cin>>q;
	REP(i,q){
		lli l,r;
		cin>>l>>r;
		cout<<d[r]-d[l]<<endl;
	}

	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:31:30: error: 'j' was not declared in this scope
   31 |         for(lli i=d+i;i<=h*w;j++){
      |                              ^
a.cc:32:18: error: invalid types 'long long int[long long int]' for array subscript
   32 |                 d[i]=d[i-d]+abs(px[i]-px[i-d])+abs(py[i]-py[i-d]);
      |                  ^
a.cc:32:23: error: invalid types 'long long int[long long int]' for array subscript
   32 |                 d[i]=d[i-d]+abs(px[i]-px[i-d])+abs(py[i]-py[i-d]);
      |                       ^
a.cc:40:24: error: invalid types 'long long int[long long int]' for array subscript
   40 |                 cout<<d[r]-d[l]<<endl;
      |                        ^
a.cc:40:29: error: invalid types 'long long int[long long int]' for array subscript
   40 |                 cout<<d[r]-d[l]<<endl;
      |                             ^
Language: C++

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

#define MP make_pair
#define PB push_back
#define ALL(x)      (x).begin(),(x).end()
#define REP(i,n)    for(int i=0;i<(n);i++)
#define REP1(i,n)   for(int i=1;i<(n);i++)
#define REP2(i,d,n) for(int i=(d);i<(n);i++)
#define RREP(i,n)   for(int i=(n);i>=0;i--)
#define CLR(a)      memset((a),0,sizeof(a))
#define MCLR(a)     memset((a),-1,sizeof(a))
#define RANGE(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))

typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI > VVI;
typedef vector<string> VS;
typedef vector<LL> VLL;
typedef pair<int,int> PII;

const int INF = 0x3f3f3f3f;
const LL INFL = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;

const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};

int main(){
    int H, W, D;
    cin >> H >> W >> D;
    VI x(H*W+1), y(H*W+1);
    int a;
    REP(i, H) REP(j, W) {
        cin >> a;
        x[a] = j;
        y[a] = i;
    }

    vector<VI> memo(D);
    REP1(i, D + 1) {
        int cost = 0;
        int now_idx = i;

        while(true) {
            memo[i%D].PB(cost);
            now_idx += D;
            if(H*W < now_idx) break;
            int prev_idx = now_idx - D;
           

Compiler output:
a.cc: In function 'int main()':
a.cc:49:40: error: expected '}' at end of input
   49 |             int prev_idx = now_idx - D;
      |                                        ^
a.cc:45:21: note: to match this '{'
   45 |         while(true) {
      |                     ^
a.cc:49:40: error: expected '}' at end of input
   49 |             int prev_idx = now_idx - D;
      |                                        ^
a.cc:41:20: note: to match this '{'
   41 |     REP1(i, D + 1) {
      |                    ^
a.cc:49:40: error: expected '}' at end of input
   49 |             int prev_idx = now_idx - D;
      |                                        ^
a.cc:29:11: note: to match this '{'
   29 | int main(){
      |           ^
Language: C++

#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;
typedef long long ll;
// const int INF = 2000000000;
// const ll MOD = 1000000007;

int H, W, D;
int Q;

int magic(int i, int j, int x, int y) { return abs(x - i) + abs(y - j); }

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> H >> W >> D;
  unordered_map<int, pair<int, int>> a_map;
  for (int i = 1; i <= H; i++) {
    for (int j = 1; j <= W; j++) {
      int ai;
      cin >> ai;
      a_map[ai] = make_pair(i, j);
    }
  }
  cin >> Q;

  map<pair<int, int>, int> sum_map;
  for (int q = 1; q <= Q; q++) {
    int Li, Ri;
    cin >> Li >> Ri;
    pair<int, int> p = make_pair(Li, Ri);

    int sum_magic = 0;
    int value = Li;
    while (value != Ri) {
      pair<int, int> p2 = make_pair(value, Ri);
      if (sum_map.find(p2) != sum_map.end()) {
        sum_magic += sum_map[p2];
        break;
      }

      auto pos = a_map[value];
      int value += D;
      auto next_pos = a_map[value];
      sum_magic +=
          magic(pos.first, pos.second, next_pos.first, next_pos.second);
      sum_map[make_pair(Li, value)] = sum_magic;
    }
    cout << sum_magic << endl;
    sum_map[p] = sum_magic;
  }
  return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:53:17: error: expected initializer before '+=' token
   53 |       int value += D;
      |                 ^~
Language: C++

from collections import defaultdict
h, w, d = map(int, input().split())
D = defaultdict(list)
for i in range(h):
    for j, x in enumerate(map(int, input().split())):
        D[x%d].append((x, i, j))
q = int(input())
for i in range(q):
    a, b = map(int, input().split())
    tmp = sorted([x for x in D[a%d] if b>= x[0] >= a])
    _, s, t = tmp[0]
    ans = 0
    for _,  u, v in tmp[1:]:
        ans += abs(u-s)+abs(v-t)
        s, t = u, v
    print(ans)


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

#include "stdafx.h"


#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <cmath>   
#include<cctype>
#include<string>
#include<set>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include <deque>
#include <utility> 

#define rep(i,m,n) for(int i = m;i < n;++i)
using namespace std;
using ll = long long;
using R = double;
const ll inf = 1LL << 50;
const ll MOD = 1e9 + 7;




int main() {
	int h, w, d;
	cin >> h >> w >> d;

	vector< vector<int> >a(h,vector<int>(w,0));
	rep(i, 0, h)rep(j, 0, w)cin >> a[i][j];

	map<int, pair<int,int>>mp;
	rep(i, 0, h) {
		rep(j, 0, w) {
			mp[a[i][j]] = {i,j};
		}
	}


	vector< vector<int> >cost(h*w+1,vector<int>(h*w+1,0));
	rep(i, 0, h) {
		rep(j, 0, w) {
			for (int k = a[i][j]+d; k <= h * w;k+=d) {
				cost[a[i][j]][k] = cost[a[i][j]][k-d]+abs(mp[k].first-mp[k-d].first)+abs(mp[k].second-mp[k-d].second);
			}
		}
	}

	int q;
	cin >> q;
	rep(i, 0, q) {
		int l, r;
		cin >> l >> r;
		cout << cost[l][r] << endl;
	}

	return 0;
}


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

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#define int ll

#define rep(i, a) for (int i = 0; (i) < (int) (a); (i)++)
#define reps(i, a, b) for (int i = (int) (a); (i) < (int) (b); (i)++)
#define rrep(i, a) for (int i = (int) a-1; (i) >= 0; (i)--)
#define rreps(i, a, b) for (int i = (int) (a)-1; (i) >= (int) (b); (i)--)
#define MP(a, b) make_pair((a), (b))
#define PB(a) push_back((a))
#define all(v) (v).begin(), (v).end()
#define PERM(v) next_permutation(all(v))
#define UNIQUE(v) sort(all(v));(v).erase(unique(all(v)), v.end())
#define CIN(type, x) type x;cin >> x
#define TRUE__  "Yes"
#define FALSE__ "No"
#define PRINT(f) if((f)){cout << (TRUE__) << endl;}else{cout << FALSE__ << endl;}
#define RS resize
#define CINV(v, N) do {\
	v.RS(N);\
	rep(i, N) cin >> v[i];\
} while (0);
#define RCINV(v, N) do {\
	v.RS(N);\
	rrep(i, N) cin >> v[i];\
} while (0);

#define MOD 1000000007

template<class T>
inline T GET() {
	T x;
	cin >> x;
	return x;
}

void init();
void solve();

signed main()
{
	init();
	solve();
}

int H, W, D;
int dp[500][500];
int r[100000];
int c[100000];

void calc(int x, int y)
{
  return abs(r[x] - r[y]) + abs(c[x] - c[y]);
}

int dfs(int x, int y)
{
  int& res = dp[x][y];
  if (y - x > D) {
    return res = dp[x+D][y] + calc(x, y);
  }
  return res = calc(x, y);
}

void init()
{
  cin >> H >> W >> D;
  rep(i, H) {
    rep(j, W) {
      int t;
      cin >> t;
      r[t] = i;
      c[t] = j;
    }
  }
  rreps(i, H*W+1, 1) {
    for (int j = i-D; j >= 0; j-=D) {
      dfs(j, i);
    }
  }
}

void solve()
{
  int q;
  cin >> q;
  while(q--) {
    int l, r;
    cin >> l >> r;
    cout << dp[l][r] << endl;
  }
}





Compiler output:
a.cc: In function 'void calc(ll, ll)':
a.cc:56:27: error: return-statement with a value, in function returning 'void' [-fpermissive]
   56 |   return abs(r[x] - r[y]) + abs(c[x] - c[y]);
      |          ~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~
a.cc: In function 'll dfs(ll, ll)':
a.cc:63:29: error: invalid operands of types 'll' {aka 'long long int'} and 'void' to binary 'operator+'
   63 |     return res = dp[x+D][y] + calc(x, y);
      |                  ~~~~~~~~~~ ^ ~~~~~~~~~~
      |                           |       |
      |                           |       void
      |                           ll {aka long long int}
a.cc:65:20: error: void value not ignored as it ought to be
   65 |   return res = calc(x, y);
      |                ~~~~^~~~~~
Language: C++

#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define int long long
#define INF 1e9
int h,w,d;
int a[344][334];
vector<int>v[100000];
map<pair<int,int>>
signed main(){
	cin>>h>>w>>d;
	rep(i,h){
		rep(j,w){
			cin>>a[i][j];
		}
	}
	
	int q;
	while(q--){
		int l,r;
		cin>>l>>r;
	}
	return 0;
}


Compiler output:
a.cc:9:17: error: wrong number of template arguments (1, should be at least 2)
    9 | map<pair<int,int>>
      |                 ^~
In file included from /usr/include/c++/14/map:63,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:152,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_map.h:102:11: note: provided for 'template<class _Key, class _Tp, class _Compare, class _Alloc> class std::map'
  102 |     class map
      |           ^~~
Language: C++

# include<stdio.h>
# define abs ( x ) (( x >0)? x :( -( x )))
int H ,W ,D , A ;
int Q ,L , R ;
int px [90001] , py [90001];
int d [90001];
int main ()
{
scanf ("% d % d % d " ,&H ,& W ,& D );
for ( int i =0; i < H ; i ++)
{
for ( int j =0; j < W ; j ++)
{
scanf ("% d " ,& A );
px [ A ]= i , py [ A ]= j ;
}
}
for ( int i = D +1; i <= H * W ; i ++)
d[ i ]= d [i - D ]+ abs ( px [ i ] - px [i - D ])+ abs ( py [ i ] - py [i - D ]);
scanf ("% d " ,& Q );
while (Q>0)
{
scanf ("% d % d " ,&L ,& R );
printf ("% d \ n " , d [ R ] - d [ L ]);
Q--;
}
}

Compiler output:
a.cc: In function 'int main()':
a.cc:2:16: error: 'x' was not declared in this scope
    2 | # define abs ( x ) (( x >0)? x :( -( x )))
      |                ^
a.cc:19:21: note: in expansion of macro 'abs'
   19 | d[ i ]= d [i - D ]+ abs ( px [ i ] - px [i - D ])+ abs ( py [ i ] - py [i - D ]);
      |                     ^~~
a.cc:24:9: warning: unknown escape sequence: '\040'
   24 | printf ("% d \ n " , d [ R ] - d [ L ]);
      |         ^~~~~~~~~~
Language: C++

#include <cstdio>
#define abs ( x ) (( x >0)? x :( -( x )))
int H ,W ,D , A ;
int Q ,L , R ;
int px [90001] , py [90001];
int d [90001];
int main ()
{
scanf ("% d % d % d " ,&H ,& W ,& D );
for ( int i =0; i < H ; i ++)
{
for ( int j =0; j < W ; j ++)
{
scanf ("% d " ,& A );
px [ A ]= i , py [ A ]= j ;
}
}
for ( int i = D +1; i <= H * W ; i ++)
d[ i ]= d [i - D ]+ abs ( px [ i ] - px [i - D ])+ abs ( py [ i ] - py [i - D ]);
scanf ("% d " ,& Q );
while (Q - -)
{
scanf ("% d % d " ,&L ,& R );
printf ("% d \ n " , d [ R ] - d [ L ]);
}
}

Compiler output:
a.cc: In function 'int main()':
a.cc:2:15: error: 'x' was not declared in this scope
    2 | #define abs ( x ) (( x >0)? x :( -( x )))
      |               ^
a.cc:19:21: note: in expansion of macro 'abs'
   19 | d[ i ]= d [i - D ]+ abs ( px [ i ] - px [i - D ])+ abs ( py [ i ] - py [i - D ]);
      |                     ^~~
a.cc:21:13: error: expected primary-expression before ')' token
   21 | while (Q - -)
      |             ^
a.cc:24:9: warning: unknown escape sequence: '\040'
   24 | printf ("% d \ n " , d [ R ] - d [ L ]);
      |         ^~~~~~~~~~
Language: C++

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define show(x) cout << #x << " = " << (x) << endl;
using namespace std;
using ll = long long;
using pii = pair<int,int>;
int main(){
    int h,w,d;
    cin >> h >> w >> d;
    vector<pii>pos(h*w+1);
    rep(i,h){
        rep(j,w){
            int a;
            cin >> a;
            pos[a] = pii(i,j);
        }
    }
    vector<vector<int>>sum(d);
    for(int i = 1; i <= h*w; i++){
        int k = i%d;
        if(sum[k].size()==0){
            sum[k].push_back(0);
        }else{
            // cerr << i << " " << i-d << endl;
            // cerr << cost(pos[i],pos[i-d]) << endl;
            sum[k].push_back(cost(pos[i],pos[i-d]));
        }
    }
    rep(i,d){
        rep(j,(int)sum[i].size()-1){
            sum[i][j+1] += sum[i][j];
        }
        // rep(j,sum[i].size()){
        //     cout << sum[i][j] << " ";
        // }
        // cout << endl;
    }
    int q;
    cin >> q;
    while(q--){
        int a,b;
        cin >> a >> b;
        int k = a%d;
        a/=d;
        b/=d;
        // cerr << a << " " << b << " " << k << endl;
        a--,b--;
        if(a)cout << sum[k][b] - sum[k][a] << endl;
        else cout << sum[k][b] << endl;
    }
}

Compiler output:
a.cc: In function 'int main()':
a.cc:48:30: error: 'cost' was not declared in this scope; did you mean 'cosl'?
   48 |             sum[k].push_back(cost(pos[i],pos[i-d]));
      |                              ^~~~
      |                              cosl
Language: C++

#include <iostream>
#include <vector>
#include <map>
#include <cmath>
using namespace std;
typedef long long LL;
#define rep(i,n) for(int i=0;i<n;++i)
int main(){
	int h,w,d;
	cin >>h>>w>>d;
	vector<vector<int>> a(h,vector<int>(w));
	rep(i,h)
		rep(j,w)
			cin >>a[i][j];
	vector<pair<int,int>>r(h*w);
	rep(i,h)
		rep(j,w){
			r[a[i][j]]=pair<int,int>(i,j);
		}
	vector<LL> s(h*w+1);
	rep(i,h*w)
		s[i]=0;
	for (int i=1;i+d<h*w;++i)
		s[i+d]+=s[i]+abs(r[i].first-r[i+d].first)+abs(r[i].second-r[i+d].second);
	}
	int q;
	cin >>q;
	rep(kk,q){
	int l,r;
	cin >>l>>r;
	cout <<s[r]-s[l]<<endl;
	}
}

Compiler output:
a.cc:27:9: error: 'cin' does not name a type
   27 |         cin >>q;
      |         ^~~
a.cc:7:18: error: expected unqualified-id before 'for'
    7 | #define rep(i,n) for(int i=0;i<n;++i)
      |                  ^~~
a.cc:28:9: note: in expansion of macro 'rep'
   28 |         rep(kk,q){
      |         ^~~
a.cc:28:13: error: 'kk' does not name a type
   28 |         rep(kk,q){
      |             ^~
a.cc:7:30: note: in definition of macro 'rep'
    7 | #define rep(i,n) for(int i=0;i<n;++i)
      |                              ^
a.cc:7:34: error: expected unqualified-id before '++' token
    7 | #define rep(i,n) for(int i=0;i<n;++i)
      |                                  ^~
a.cc:28:9: note: in expansion of macro 'rep'
   28 |         rep(kk,q){
      |         ^~~
a.cc:33:1: error: expected declaration before '}' token
   33 | }
      | ^
Language: C++

#include<bits/stdc++.h>
#include<iostream>
#include<vector>
#include<utility>
#include<numeric>
#include<functional>
#include<algorithm>
#include<queue>
#include<map>
#include<string>


#define FOR(i, a, b) for(int i=a; i<b; i++)
#define COUT(a) cout << a << endl;

using namespace std;
using Int = long long;
using P = pair<Int, Int>;

Int H, W, D, Q;

vector<P> locs;

int memo[301*301*301*301];

Int dist(Int x, Int r){
    if (x == r){
        return 0;
    }
    if (memo[x + 301*301*r] != 0){
        return memo[x + 301*301*r];
    }

    P px = locs[x];
    P px_ = locs[x+D];

    Int d = abs(px.first - px_.first) + abs(px.second - px_.second);
    Int ret = d + dist(x+D, r);
    memo[x + 301*301*r] = ret; 
    return ret;
}

int main(){
    Int N;

    cin >> H >> W >> D;

    
    locs = vector<P>((H+1)*(W+1));

    FOR(i, 0, H){
        FOR(j, 0, W){
            Int n;
            cin >> n;
            locs[n] = P(j+1, i+1);
        }
    }

    cin >> Q;

    FOR (i, 0, Q){
        Int L, R;
        cin >> L >> R;
        cout << dist(L, R) << endl;
    }

}


Compiler output:
a.cc:24:21: warning: integer overflow in expression of type 'int' results in '-381393391' [-Woverflow]
   24 | int memo[301*301*301*301];
      |          ~~~~~~~~~~~^~~~
a.cc:24:21: error: size '-381393391' of array 'memo' is negative
Language: C++

#include<cstdio>
#include <utility>
#include<algorithm>
#include<cstdlib>
#define MAX 90005
using namespace std;

int main(){
  int h, w, d, i, j, a, q, sum[MAX], l, r, ans;
  pair<int, int> p[MAX];
  scanf("%d%d%d", &h, &w, &d);
  for(i = 0; i < h; i++){
    for(j = 0; j < w; j++){
      scanf("%d", &a);
      p[a] = make_pair(i, j);
    }
  }
  for(i = 1; i <= d; i++){
    sum[i] = 0;
    for(j = i; j <= a-d; j += d;){
      sum[j+d] += sum[j] + 
        abs(p[j].first - p[j+d].first) + 
        abs(p[j].second - p[j+d].second);
    }
  }
  scanf("%d", &q);
  for(i = 0; i < q; i++){
    scanf("%d%d", &l, &r);
    ans = sum[r] - sum[l];
    printf("%d\n", ans);
  }
}

Compiler output:
a.cc: In function 'int main()':
a.cc:20:32: error: expected ')' before ';' token
   20 |     for(j = i; j <= a-d; j += d;){
      |        ~                       ^
      |                                )
a.cc:20:33: error: expected primary-expression before ')' token
   20 |     for(j = i; j <= a-d; j += d;){
      |                                 ^
Language: C++

#include <cstdio>
#define abs(x) ((x>0)?x:(-(x))) int H,W,D,A;
int Q,L,R;
int px[90001],py[90001];
int d[90001];
int main ()
{
scanf("%d%d%d",&H,&W,&D); for(int i=0;i<H;i++)
{
for(int j=0;j<W;j++) {
scanf("%d",&A); px[A]=i,py[A]=j;
}
}
for(int i=D+1;i<=H*W;i++)
d[i]=d[i-D]+abs(px[i]-px[i-D])+abs(py[i]-py[i-D]); scanf("%d",&Q);
while(Q--) {
scanf("%d%d",&L,&R); printf("%d\n",d[R]-d[L]);
}


Compiler output:
a.cc: In function 'int main()':
a.cc:8:17: error: 'H' was not declared in this scope
    8 | scanf("%d%d%d",&H,&W,&D); for(int i=0;i<H;i++)
      |                 ^
a.cc:8:20: error: 'W' was not declared in this scope
    8 | scanf("%d%d%d",&H,&W,&D); for(int i=0;i<H;i++)
      |                    ^
a.cc:8:23: error: 'D' was not declared in this scope
    8 | scanf("%d%d%d",&H,&W,&D); for(int i=0;i<H;i++)
      |                       ^
a.cc:11:13: error: 'A' was not declared in this scope
   11 | scanf("%d",&A); px[A]=i,py[A]=j;
      |             ^
a.cc:15:39: error: 'i' was not declared in this scope
   15 | d[i]=d[i-D]+abs(px[i]-px[i-D])+abs(py[i]-py[i-D]); scanf("%d",&Q);
      |                                       ^
a.cc:2:18: note: in definition of macro 'abs'
    2 | #define abs(x) ((x>0)?x:(-(x))) int H,W,D,A;
      |                  ^
a.cc:18:2: error: expected '}' at end of input
   18 | }
      |  ^
a.cc:7:1: note: to match this '{'
    7 | {
      | ^
Language: C++

#include <cstdio >
#define abs(x) ((x>0)?x:(-(x))) int H,W,D,A;
int Q,L,R;
int px[90001],py[90001];
int d[90001];
int main ()
{
scanf("%d%d%d",&H,&W,&D); for(int i=0;i<H;i++)
{
for(int j=0;j<W;j++) {
scanf("%d",&A); px[A]=i,py[A]=j;
}
}
for(int i=D+1;i<=H*W;i++)
d[i]=d[i-D]+abs(px[i]-px[i-D])+abs(py[i]-py[i-D]); scanf("%d",&Q);
while(Q--) {
scanf("%d%d",&L,&R); printf("%d\n",d[R]-d[L]);
}

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

#include <iostream>
#include <vector>
#include <math.h>
#include <cmath>
#include <algorithm>
#include <string>
#include <cstring>
#include <regex>

using namespace std;

using ll = long long;
using pii = pair<int,int>;
using vi = vector<int>;
using vs = vector<string>;
using vll = vector<ll>;
using vpii = vector<pii>;

#define fi first
#define se second
#define mp make_pair
#define pb push_back

#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define rFOR(i,a,b) for(int i=(b);i>=(a);i--)
#define SORT(a) sort((a).begin(),(a).end());
#define rSORT(a) sort((a).rbegin(),(a).rend());
#define UNIQUE(a) (a).erase(unique((a).begin(),(a).end()),(a).end());
#define yn(a) cout <<((a)?"yes":"no")<<endl;
#define Yn(a) cout <<((a)?"Yes":"No")<<endl;
#define YN(a) cout <<((a)?"YES":"NO")<<endl;

const ll MOD = 1e9+7;

//sankou
//vvi = vector<vector<int>>(20, vector<int>(10, 0));

//seiki
//#include <regex>
/*bubun*/
//regex_search("u32", regex("[0-9]"));      // true
/*kanzen*/
//regex_match("u32", regex("(i|u)\\d+"));   // true

int isP(int n) {
    if(n<=1) return 0;
    FOR(i,2,(int)sqrt(n)) {
        if(n%i==0) return 0;
    }
    return 1;
}

int main() {

    ll H,W,D,Q;
    cin >>H>>W>>D;
    vector<vi> A(H+1,vi(W+1));
    vpii HW(H*W+1);
    vi kyo(H*W+1,0);
    FOR(w,1,W){
        FOR(h,1,H){
            cin >>A[h][w];
            HW[A[h][w]]=mp(h,w);
        }
    }
    FOR(i,1+D,H*W){
        kyo[i]=kyo[i-D]+abs(HW[i].fi-HW[i-D].fi)+abs(HW[i].se-HW[i-D].se);
    }
    cin >>Q;
    int L,R
    FOR(i,1,Q){
        cin >>L>>R;
        cout <<(kyo[R]-kyo[L])<<endl;
    }

    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:24:20: error: expected initializer before 'for'
   24 | #define FOR(i,a,b) for(int i=(a);i<=(b);i++)
      |                    ^~~
a.cc:71:5: note: in expansion of macro 'FOR'
   71 |     FOR(i,1,Q){
      |     ^~~
a.cc:71:9: error: 'i' was not declared in this scope
   71 |     FOR(i,1,Q){
      |         ^
a.cc:24:34: note: in definition of macro 'FOR'
   24 | #define FOR(i,a,b) for(int i=(a);i<=(b);i++)
      |                                  ^
Language: C++

#include <iostream>
#include <math.h>
#include <algorithm>
#include <vector>
#include <numeric>
#include <string>
using namespace std;
const double PI = acos(-1.0);
const string alp = "abcdefghijklmnopqrstuvwxyz";
const string ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define REP1(i,n) FOR(i,1,n+1)
#define SUM(c) accumulate((c).begin(),(c).end(),0)
#define UNIQ(c) (c).erase(unique((c).begin(), (c).end()), (c).end());
#define Yn(b) puts(b?"Yes":"No")
#define YN(b) puts(b?"YES":"NO")

bool isprime(int p) {
  if (p==1) return false;
  FOR(i,2,p) {
    if (p%i==0) return false;
  }
  return true;
}

int main(){
  int h,w,d,q,l,r,x[300*300],y[300*300],z[300*300];
  cin >> h >> w >> d;
  REP(i,h*w){
    int j;
    cin >> j;
    x[j]=i%w;
    y[j]=i/w;
  }
  cin >> q;
  FOR(i,d,h*w){
    z[i]=z[i-d]+abs(x[i]-x[i-d])+abs(y[i]-y[i-d]);
  }
  REP(i,q){
    t=0;
    cin >> l >> r;
    cout << z[r]-z[l] << endl;
  }
  return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:43:5: error: 't' was not declared in this scope
   43 |     t=0;
      |     ^
Language: C++

#include <iostream>
#include <math.h>
#include <algorithm>
#include <vector>
#include <numeric>
#include <string>
using namespace std;
const double PI = acos(-1.0);
const string alp = "abcdefghijklmnopqrstuvwxyz";
const string ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define REP1(i,n) FOR(i,1,n+1)
#define SUM(c) accumulate((c).begin(),(c).end(),0)
#define UNIQ(c) (c).erase(unique((c).begin(), (c).end()), (c).end());
#define Yn(b) puts(b?"Yes":"No")
#define YN(b) puts(b?"YES":"NO")

bool isprime(int p) {
  if (p==1) return false;
  FOR(i,2,p) {
    if (p%i==0) return false;
  }
  return true;
}

int main(){
  int h,w,d,q,t,l,r,x[300*300],y[300*300],z[300*300];
  cin >> h >> w >> d;
  REP(i,h*w){
    int j;
    cin >> j;
    x[j]=i%w;
    y[j]=i/w;
  }
  cin >> q;
  FOR(i,d,h*w){
    z[i]=abs(x[i]-x[i-d])+abs(y[i]-y[i-d])
  }
  REP(i,q){
    t=0;
    cin >> l >> r;
    for(int j=l+d;j<=r;j+=d){
      t+=z[i];
    }
    cout << t << endl;
  }
  return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:40:43: error: expected ';' before '}' token
   40 |     z[i]=abs(x[i]-x[i-d])+abs(y[i]-y[i-d])
      |                                           ^
      |                                           ;
   41 |   }
      |   ~
Language: C++

#include <iostream>
#include <math.h>
#include <algorithm>
#include <vector>
#include <numeric>
#include <string>
using namespace std;
const double PI = acos(-1.0);
const string alp = "abcdefghijklmnopqrstuvwxyz";
const string ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define REP1(i,n) FOR(i,1,n+1)
#define SUM(c) accumulate((c).begin(),(c).end(),0)
#define UNIQ(c) (c).erase(unique((c).begin(), (c).end()), (c).end());
#define Yn(b) puts(b?"Yes":"No")
#define YN(b) puts(b?"YES":"NO")

bool isprime(int p) {
  if (p==1) return false;
  FOR(i,2,p) {
    if (p%i==0) return false;
  }
  return true;
}

int main(){
  int h,w,d,q,t,l,r,x[300*300],y[300*300];
  cin >> h >> w >> d;
  REP(i,h*w){
    int j;
    cin >> j;
    x[j]=i%w;
    y[j]=i/w;
  }
  cin >> q;
  REP(i,q){
    t=0;
    cin >> l >> r;
    px=x[l];
    py=y[l];
    for(int j=l+d;j<=r;j+=d){
      t+=abs(x[j]-x[j-d])+abs(y[j]-x[j-d]);
    }
    cout << t << endl;
  }
  return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:42:5: error: 'px' was not declared in this scope; did you mean 'x'?
   42 |     px=x[l];
      |     ^~
      |     x
a.cc:43:5: error: 'py' was not declared in this scope; did you mean 'y'?
   43 |     py=y[l];
      |     ^~
      |     y
Language: C++

#include <iostream>
#include <math.h>
#include <algorithm>
#include <vector>
#include <numeric>
#include <string>
using namespace std;
const double PI = acos(-1.0);
const string alp = "abcdefghijklmnopqrstuvwxyz";
const string ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define REP1(i,n) FOR(i,1,n+1)
#define SUM(c) accumulate((c).begin(),(c).end(),0)
#define UNIQ(c) (c).erase(unique((c).begin(), (c).end()), (c).end());
#define Yn(b) puts(b?"Yes":"No")
#define YN(b) puts(b?"YES":"NO")

bool isprime(int p) {
  if (p==1) return false;
  FOR(i,2,p) {
    if (p%i==0) return false;
  }
  return true;
}

int main(){
  int h,w,d,q,t,l,r,px,py,x[300],y[300];
  cin >> h >> w >> d;
  REP(i,h*w){
    int j;
    cin >> j;
    x[j]=i%w;
    y[j]=i/w;
  }
  cin >> q;
  REP(i,q){
    t=0;
    cin >> l >> r;
    px=x[l];
    py=y[j];
    for(int j=l+d;j<=r;j+=d){
      t+=abs(x[j]-px)+abs(y[j]-py);
      px=x[j];
      py=y[j];
    }
    cout << t << endl;
  }
  return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:43:10: error: 'j' was not declared in this scope
   43 |     py=y[j];
      |          ^
Language: C++

#include <cstdio >
#define abs(x) ((x>0)?x:(-(x)))
int H,W,D,A;
int Q,L,R;
int px[90001],py[90001];
int d[90001];
int main() {
    scanf("%d%d%d",&H,&W,&D);
    for(int i=0;i<H;i++) {
        for(int j=0;j<W;j++) {
            scanf("%d",&A);
            px[A]=i,py[A]=j;
           }
         }
    for(int i=D+1;i<=H*W;i++)
        d[i]=d[i-D]+abs(px[i]-px[i-D])+abs(py[i]-py[i-D]);
    scanf("%d",&Q);
    while(Q--) {
        scanf("%d%d",&L,&R);
        printf("%d\n",d[R]-d[L]);
       } 
    }

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

#include <bits/stdc++.h>
using namespace std;
#ifdef _DEBUG
#define _GLIBCXX_DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
// typedef __int128_t Int;
#define DBG 1
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define loop(n) rep(loop, (0), (n))
#define all(c) begin(c), end(c)
const int INF =
    sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(12);

  int H, W, D;
  cin >> H >> W >> D;
  vector<vector<int>> A(H, vector<int>(W));
  rep(i, 0, H) rep(j, 0, W) { cin >> A[i][j]; }
  int Q;
  cin >> Q;
  vector<int> L(Q), R(Q);
  rep(i, 0, Q) { cin >> L[i] >> R[i]; }
  map<int, pair<int, int>> mp;
  rep(i, 0, H) rep(j, 0, W) { mp[A[i][j]] = make_pair(i + 1, j + 1); }
  vector<int> check(H * W + 1);
  map<int, vector<int>> sum;
  int ans = 0;
  auto cal = [&](pair<int, int> &a, pair<int, int> &b) {
    return abs(a.first - b.first) + abs(a.second - b.second);
  };
  rep(d, 1, D + 1) {
    if (check[d])
      continue;

    int x = d;
    while (x + D <= H * W) {
      check[x] = 1;
      sum[d].push_back(cal(mp[x], mp[x + D]));
      x += D;
    }
  }

  for (auto &y : sum) {
    vector<int> &v(y.second);
    rep(i, 1, v.size()) v[i] += v[i - 1];
    dump(v);
  }

  rep(i, 0, Q) {
    int re = L[i] % D;
    int mi = 1;
    if (re == 0)
      re = D, mi++;

    ans = sum[re][max(R[i] / D - mi,0)] - sum[re][max(L[i] / D - mi,)];
    cout << ans << endl;
  }

  return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:82:69: error: expected primary-expression before ')' token
   82 |     ans = sum[re][max(R[i] / D - mi,0)] - sum[re][max(L[i] / D - mi,)];
      |                                                                     ^
Language: C

#include <iostream>
#include <algorithm>
using namespace std;
#define int long long
#define MAX 301

typedef pair<int, int> P;

int h, w, d;
int a[MAX][MAX];

P search(int n) {
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (a[i][j] == n) {
        return P(i, j);
      }
    }
  }
  return P(-1, -1);
}

signed main() {
  cin >> h >> w >> d;
  for (int i = 0; i < h; i++) {
    for (int j = 0 ; j < w; j++) {
      cin >> a[i][j];
    }
  }
  int res[h * w + 1];
  for (int i = 1; i <= d; i++) {
    res[i] = 0;
  }
  for (int i = 1; i <= d; i++) {
    for (int j = i; j <= h * w - d; j += d) {
      P current = search(j);
      P next = search(j + d);
      int tmp = abs(current.first - next.first) + abs(current.second - next.second);
      res[j + d] = res[j] + tmp;
    }
  }
  int q;
  cin >> q;
  while (q--) {
    int l, r;
    cin >> l >> r;
    cout << res[r] - res[l] << endl;
  }
  return 0;
}


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