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

#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const ll MOD = 1000000007;
ll memo[100000][100000];
ll A[10000][10000];
map<int, P> s;
int dfs(int l, int r, int d) {
  if (l == r) return 0;
  if (memo[l][r] != 0) return memo[l][r];
  return memo[l][r] = abs(s[l].first - s[l + d].first) +
                      abs(s[l].second - s[l + d].second) + dfs(l + d, r, d);
}
int main() {
  int H, W, D;
  cin >> H >> W >> D;
  REP(i, H) REP(j, W) {
    // cin >> A[i][j];
    int a;
    cin >> a;
    s[a] = P(i + 1, j + 1);
  }
  int Q;
  cin >> Q;
  REP(i, Q) {
    int l, r;
    cin >> l >> r;
    cout << dfs(l, r, D) << endl;
  }
}

Compiler output:
/tmp/ccoXBkpn.o: in function `dfs(int, int, int)':
a.cc:(.text+0x8a): relocation truncated to fit: R_X86_64_PC32 against symbol `s' defined in .bss section in /tmp/ccoXBkpn.o
a.cc:(.text+0xad): relocation truncated to fit: R_X86_64_PC32 against symbol `s' defined in .bss section in /tmp/ccoXBkpn.o
a.cc:(.text+0xd2): relocation truncated to fit: R_X86_64_PC32 against symbol `s' defined in .bss section in /tmp/ccoXBkpn.o
a.cc:(.text+0xf7): relocation truncated to fit: R_X86_64_PC32 against symbol `s' defined in .bss section in /tmp/ccoXBkpn.o
/tmp/ccoXBkpn.o: in function `main':
a.cc:(.text+0x229): relocation truncated to fit: R_X86_64_PC32 against symbol `s' defined in .bss section in /tmp/ccoXBkpn.o
/tmp/ccoXBkpn.o: in function `__static_initialization_and_destruction_0()':
a.cc:(.text+0x2f9): relocation truncated to fit: R_X86_64_PC32 against symbol `s' defined in .bss section in /tmp/ccoXBkpn.o
a.cc:(.text+0x312): relocation truncated to fit: R_X86_64_PC32 against symbol `s' defined in .bss section in /tmp/ccoXBkpn.o
collect2: error: ld returned 1 exit status
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: Java

import java.util.Scanner;

public class abc089_d {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt(), M = sc.nextInt(), D = sc.nextInt();
		int row[] = new int[N * M], col[] = new int[N * M];
		for (int i = 1; i <= N; i++) {
			for (int j = 1; j <= M; j++) {
				int k = sc.nextInt() - 1;
				row[k] = i;
				col[k] = j;
			}
		}
		int O[][] = new int[D][N * M / D + 1];
		int P[][] = new int[D][N * M / D + 1];
		for (int r = 0; r < D; r++) {
			for (int k = 1; k * D + r < N * M; k++) {
				int f = (k - 1) * D + r;
				int s = k * D + r;
				O[r][k] = Math.abs(row[f] - row[s]) + Math.abs(col[f] - col[s]);
			}
		}
		for (int r = 0; r < D; r++) {
			for (int k = 1; k * D + r < N * M; k++) {
				P[r][k] = P[r][k - 1] + O[r][k];
			}
		}
		int Q = sc.nextInt();
		while (Q-- > 0) {
			int l = sc.nextInt() - 1, r = sc.nextInt() - 1;
			System.out.println(P[r % D][r / D] - P[l % D][l / D]);
		}
	}

}

Compiler output:
Main.java:3: error: class abc089_d is public, should be declared in a file named abc089_d.java
public class abc089_d {
       ^
1 error
Language: C++

import java.util.HashMap;
import java.util.Scanner;

public class Main {

	static class Vec2 {
		int x, y;

		public Vec2(int x, int y) {
			this.x = x;
			this.y = y;
		}

		int diff(Vec2 other) {
			return Math.abs(x - other.x) + Math.abs(y - other.y);
		}

		@Override
		public boolean equals(Object obj) {
			if (obj.getClass() != Vec2.class)
				return false;
			Vec2 o = (Vec2) obj;
			return x == o.x && y == o.y;
		}

		@Override
		public int hashCode() {
			return x ^ (y << 16);
		}
	}

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int h = sc.nextInt(), w = sc.nextInt(), d = sc.nextInt();

		Vec2[] map = new Vec2[h * w + 1];
		int[][] A = new int[h][w];
		for (int i = 0; i < A.length; i++) {
			for (int j = 0; j < A[i].length; j++) {
				A[i][j] = sc.nextInt();
				map[A[i][j]] = new Vec2(i, j);
			}
		}

		HashMap<Integer, Vec2> cache = new HashMap<Integer, Vec2>();
		int q = sc.nextInt();
		for (int i = 0; i < q; i++) {
			int l = sc.nextInt(), r = sc.nextInt();
			int cost = 0;
			Vec2 pos = map[l];
			while (A[pos.x][pos.y] != r) {
				if (cache.containsKey(A[pos.x][pos.y])) {
					Vec2 v = cache.get(A[pos.x][pos.y]);
					pos = map[v.x];
					cost += v.y;
					continue;
				}
				cost += map[A[pos.x][pos.y] + d].diff(pos);
				pos = map[A[pos.x][pos.y] + d];
			}
			cache.put(l, new Vec2(r, cost));
			System.out.println(cost);
		}
	}

}

Compiler output:
a.cc:18:17: error: stray '@' in program
   18 |                 @Override
      |                 ^
a.cc:26:17: error: stray '@' in program
   26 |                 @Override
      |                 ^
a.cc:1:1: error: 'import' does not name a type
    1 | import java.util.HashMap;
      | ^~~~~~
a.cc:1:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:2:1: error: 'import' does not name a type
    2 | import java.util.Scanner;
      | ^~~~~~
a.cc:2:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:4:1: error: expected unqualified-id before 'public'
    4 | public class Main {
      | ^~~~~~
Language: C++

/**
 *    author:  FromDihPout
 *    created: 2020-08-15
**/

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

int h, w, d;
map<pair<int,int>, int> cost;
map<int, pair<int,int>> mp;

int totalCost(int l, int r) {
    if (l == r) return 0;
    if (cost[{l, r}] != 0) return cost[{l, r}];
    
    auto pos1 = mp[l];
    auto pos2 = mp[l + d];
    cost[{l, r}] = abs(pos2.f - pos1.f) + abs(pos2.s - pos1.s)
                    + totalCost(l + d, r);
    return cost[{l, r}];
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    cin >> h >> w >> d;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            int x;
            cin >> x;
            mp[x] = {i, j};
        }
    }
    
    int q;
    cin >> q;
    while (q--) {
        int l, r;
        cin >> l >> r;
        cout << totalCost(l, r) << '\n';
    }
    return 0;
}

Compiler output:
a.cc: In function 'int totalCost(int, int)':
a.cc:19:29: error: 'struct std::pair<int, int>' has no member named 'f'
   19 |     cost[{l, r}] = abs(pos2.f - pos1.f) + abs(pos2.s - pos1.s)
      |                             ^
a.cc:19:38: error: 'struct std::pair<int, int>' has no member named 'f'
   19 |     cost[{l, r}] = abs(pos2.f - pos1.f) + abs(pos2.s - pos1.s)
      |                                      ^
a.cc:19:52: error: 'struct std::pair<int, int>' has no member named 's'
   19 |     cost[{l, r}] = abs(pos2.f - pos1.f) + abs(pos2.s - pos1.s)
      |                                                    ^
a.cc:19:61: error: 'struct std::pair<int, int>' has no member named 's'
   19 |     cost[{l, r}] = abs(pos2.f - pos1.f) + abs(pos2.s - pos1.s)
      |                                                             ^
Language: C++

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll>
#define cvector vector<char>
#define svector vector<string>
#define lque queue<ll>
#define lpque priority_queue<ll>
#define dlpque priority_queue<ll,lvector,greater<ll>>
#define P pair<ll,ll>
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define rep(i,n) for(ll i=0; i<n; ++i)
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll h,w,d,a;cin>>h>>w>>d;
  map<ll,P> m;
  rep(i,h)rep(j,w) {cin>>a;m[a]=P(i+1,j+1);}
  lvector c(h*w+1,0);
  for(ll i=d+1;i<=h*w;++i) c[i]=c[i-d]+abs(m[i].first-m[i-d].first)+abs(m[i].second-m[i-d].second);
  ll q,l,r;cin>>q;
  rep(i,q) {
    cin>>l>>r;
    print(cost[r]-cost[l]);
  }
  return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:27:11: error: 'cost' was not declared in this scope; did you mean 'cosl'?
   27 |     print(cost[r]-cost[l]);
      |           ^~~~
a.cc:14:27: note: in definition of macro 'print'
   14 | #define print(a) cout << (a) << endl
      |                           ^
Language: C++

#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

using namespace std;

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

const ll mod=998244353;

int main(){
    ll h,w,d;
    cin >> h >> w >> d;
    vector<vector<ll>> a(h,vector<ll>(w));
    vector<vector<pair<ll,pll>> v(d);
    vector<vector<ll>> sum(d);
    rep(i,h){
        rep(j,w){
            cin >> a[i][j];
            pll s=make_pair(i,j);
            v[a[i][j]%d].push_back(make_pair(a[i][j],s));
        }
    }
    rep(i,d){
        sort(v[i].begin(),v[i].end());
        rep(j,v[i].size()){
            if(j){
                
            }
        }
    }
    ll q;
    cin >> q;
    rep(i,q){
        
    }
} 


Compiler output:
a.cc: In function 'int main()':
a.cc:26:36: error: template argument 1 is invalid
   26 |     vector<vector<pair<ll,pll>> v(d);
      |                                    ^
a.cc:26:36: error: template argument 2 is invalid
a.cc:32:13: error: 'v' was not declared in this scope
   32 |             v[a[i][j]%d].push_back(make_pair(a[i][j],s));
      |             ^
a.cc:36:14: error: 'v' was not declared in this scope
   36 |         sort(v[i].begin(),v[i].end());
      |              ^
Language: C++

#include <bits/stdc++.h>
using namespace std;
#define REP(i, init, n) for(int i = (int)(init); i < (int)(n); i++)

#define vi vector<int>
#define vl vector<long>
#define vvi vector<vector<int>>
#define vvl vector<vector<long>>
#define pint pair<int, int>
#define plong pair<long, long>

int main() {
    int H, W, D;
    cin>>H>>W>>D;
    vvi A(H, vi(W, 0));
    vector<pint> B(H*W);
    REP(i, 0, H){
        REP(j, 0, W){
            int a;
            cin >> a;
            A[i][j] = a;
            a--;
            B[a] = {i, j};
        }
    }

    vl move(H*W);
    REP(i, 0, H*W/D+1){
        int count = i;
        while(count < H*W){
            if(count < D){
                move[count] = 0;
            }else{
                move[count] = move[count-D] + abs(B[count].first - B[count - D].first) + abs(B[count].second - B[count - D].second);
            }
            count += D;
        }
    }
    REP(i, 0, H*W) cout << move[i] << endl;
    int Q, L, R;
    cin >> Q;
    REP(i, 0, Q){
        cin >> L >> R;
        L--; R--;
        long ans = move[R] - move[L]
        cout << ans << endl;
    }
}

Compiler output:
a.cc: In function 'int main()':
a.cc:46:9: error: expected ',' or ';' before 'cout'
   46 |         cout << ans << endl;
      |         ^~~~
Language: C++

5 5 4
13 25 7 15 17
16 22 20 2 9
14 11 12 1 19
10 6 23 8 18
3 21 5 24 4
3
13 13
2 10
13 13

Compiler output:
a.cc:1:1: error: expected unqualified-id before numeric constant
    1 | 5 5 4
      | ^
Language: C++

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<ll> vll;
typedef vector<vector<int>> vvi;
typedef vector<vector<string>> vvs;
typedef vector<vector<char>> vvc;
typedef vector<vector<bool>> vvb;
typedef pair<int,int> P;
typedef pair<ll, ll> Pll;
#define vrep(v,n) for(int i=0;i<n;i++){cin >> v.at(i);} 
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repn(i, n) for (int i = 0; i <= (int)(n); i++)
#define srep(i, l, n) for (int i = l; i < (int)(n); i++)
#define srepn(i, l, n) for (int i = l; i <= (int)(n); i++)
#define pb push_back 
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

const int mod = 1000000007;
const int inf = 1e9;
#define PI 3.14159265369;
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};


int main(){
    int h, w, d;
    cin >> h >> w >> d;
    vector<P> a(h*w+5);
    rep(i,h)rep(j,w){
        scanf("%d", &p);
        cin >> p;
        a[p] = make_pair(i,j);
    }
    vector<vector<int>> u(d, vector<int>(h*w+5));
    for(int i = 0; i < d; i++){
        for(int j = i; j <= h*w; j+=d){
            if(j==i){u[i][j] = 0;continue;}
            u[i][j] = u[i][j-d] + abs(a[j].first-a[j-d].first)+abs(a[j].second-a[j-d].second); 
        }
    }
    int q;
    cin >> q;
    while(q--){
        int l, r;
        cin >> l >> r;
        int p = l%d;
        cout << u[p][r]-u[p][l] << endl;
    }
}

Compiler output:
a.cc: In function 'int main()':
a.cc:39:22: error: 'p' was not declared in this scope
   39 |         scanf("%d", &p);
      |                      ^
Language: C++

#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include <cassert>
#include <cmath>
#include<cstdint>

#define INF 1e9
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<int,int>;

vector<int>bitSearch(int bit,int n){
    vector<int>S;
    rep(i,n)if(bit&(1<<i))S.push_back(i);
    return S;
}


ll cost[400]][400];
int main(){
   int h, w, d;
   cin >> h >> w >> d;
   vector<P>coord(h * w + 100);
   rep(i, h){
       rep(j, w){
           int a;
           cin >> a;
           coord[a] = P(i, j);
       }
   }

   rep(i, 400)rep(j, 400){
       if(i == j)cost[i][j] = 0;
       else cost[i][j] = INF;
   }

   REP(i, 1, h*w-d){
       cost[i][i + d] = abs(coord[i].first - coord[i + d].first) + abs(coord[i].second - coord[i + d].second);
   }

   //warshall_floyd
   REP(k, 1, h * w){
       REP(i, 1,  h * w){
           REP(j, 1,  h * w ){
               cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j]);
           }
       }
   }

   int q;
   ll res = 0;
   cin >> q;
   while(q--){
       int l, r;
       cin >> l >> r;
       cout << cost[l][r] << endl;
   }
}



Compiler output:
a.cc:40:13: error: expected initializer before ']' token
   40 | ll cost[400]][400];
      |             ^
a.cc: In function 'int main()':
a.cc:54:18: error: 'cost' was not declared in this scope; did you mean 'cosl'?
   54 |        if(i == j)cost[i][j] = 0;
      |                  ^~~~
      |                  cosl
a.cc:55:13: error: 'cost' was not declared in this scope; did you mean 'cosl'?
   55 |        else cost[i][j] = INF;
      |             ^~~~
      |             cosl
a.cc:59:8: error: 'cost' was not declared in this scope; did you mean 'cosl'?
   59 |        cost[i][i + d] = abs(coord[i].first - coord[i + d].first) + abs(coord[i].second - coord[i + d].second);
      |        ^~~~
      |        cosl
a.cc:66:16: error: 'cost' was not declared in this scope; did you mean 'cosl'?
   66 |                cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j]);
      |                ^~~~
      |                cosl
a.cc:77:16: error: 'cost' was not declared in this scope; did you mean 'cosl'?
   77 |        cout << cost[l][r] << endl;
      |                ^~~~
      |                cosl
Language: C++

#include <algorithm>
#include <map>
using namespace std;
int main() {
	int h, w, d;
	scanf("%d%d%d", &h, &w, &d);
	map<int, pair<int, int>> mp;
	for (int i = 0; i < h; i++)
		for (int j = 0; j < w; j++) {
			int a;
			scanf("%d", &a);
			mp[a] = {i, j};
		}
	vector<int> dist(h * w);
	for (int i = d; i < h * w; i++) {
		dist[i] = dist[i - d] + abs(mp[i + 1].first - mp[i + 1 - d].first)
		          + abs(mp[i + 1].second - mp[i + 1 - d].second);
	}
	int q;
	scanf("%d", &q);
	while (q--) {
		int l, r;
		scanf("%d%d", &l, &r);
		printf("%d\n", dist[r - 1] - dist[l - 1]);
	}
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:6:9: error: 'scanf' was not declared in this scope
    6 |         scanf("%d%d%d", &h, &w, &d);
      |         ^~~~~
a.cc:14:9: error: 'vector' was not declared in this scope
   14 |         vector<int> dist(h * w);
      |         ^~~~~~
a.cc:3:1: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
    2 | #include <map>
  +++ |+#include <vector>
    3 | using namespace std;
a.cc:14:16: error: expected primary-expression before 'int'
   14 |         vector<int> dist(h * w);
      |                ^~~
a.cc:16:17: error: 'dist' was not declared in this scope
   16 |                 dist[i] = dist[i - d] + abs(mp[i + 1].first - mp[i + 1 - d].first)
      |                 ^~~~
a.cc:24:32: error: 'dist' was not declared in this scope
   24 |                 printf("%d\n", dist[r - 1] - dist[l - 1]);
      |                                ^~~~
a.cc:24:17: error: 'printf' was not declared in this scope
   24 |                 printf("%d\n", dist[r - 1] - dist[l - 1]);
      |                 ^~~~~~
a.cc:3:1: note: 'printf' is defined in header '<cstdio>'; this is probably fixable by adding '#include <cstdio>'
    2 | #include <map>
  +++ |+#include <cstdio>
    3 | using namespace std;
Language: C++

// clang-format off
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <numeric>
#include <array>
#include <cmath>
#include <memory>
#include <map>
using namespace std;
#define DEB(variable) cout << #variable << '=' << variable << endl

#define FOR(LoopVariable,numberOFbegin,numberOFend) for (long long int LoopVariable = (numberOFbegin); (LoopVariable) < (numberOFend); (LoopVariable)++)
#define DEFOR(LoopVariable,numberOFbegin,numberOFend) for (long long int LoopVariable = (numberOFbegin)-1; (LoopVariable) >= (numberOFend); (LoopVariable)--)
#define REP(LoopVariable,numberOFend) for(long long int LoopVariable = 0;(LoopVariable)<(numberOFend);LoopVariable++)

using llint = long long int;

constexpr long long int linf = numeric_limits<long long int>::max()-5;
constexpr long long int inf= numeric_limits<int>::max()-5;
constexpr long long int mod = 1000000007;

// clang-format on
struct Point {
    int y, x;
};
int kyori(Point a, Point b) {
    return abs(a.x - b.x) + abs(a.y - b.y);
}
int main() {

    int h, w, d;
    cin >> h >> w >> d;

    map<int, Point> mp;
    int tmp;
    REP(i, h) {
        REP(j, w) {
            cin >> tmp;
            mp[tmp] = {(int)i, (int)j};
        }
    }
    vector<vector<int>> grid(d, vector<int>((h * 2 + 3 * d - 1) / d, 0ll));
    for(auto x : mp) {
        grid[x.first % d][x.first / d] = kyori(mp[x.first], mp[x.first + d]);

        if(x.first == h * w - d) {
            break;
        }
    }
    mp.clear();
    vector<vector<int>> sum(d, vector<int>((h * 2 + 4 * d - 1) / d, 0ll));
    REP(i, d) {
        REP(j, (h * 2 + 2 * d - 1) / d) {
            sum[i][j + 1] = sum[i][j] + grid[i][j];
        }  
    }
    grid.clear();
    int q;
    cin >> q;
    int a, b;
    REP(i,q){
        scanf(%lld %lld, &a,&b);
        cout << sum[b % d][b / d] - sum[a % d][a / d] << endl;
    //    cout << "unko" << endl;
    }
    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:65:15: error: expected primary-expression before '%' token
   65 |         scanf(%lld %lld, &a,&b);
      |               ^
a.cc:65:16: error: 'lld' was not declared in this scope
   65 |         scanf(%lld %lld, &a,&b);
      |                ^~~
Language: C++

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

typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1e18+7;
#define rep(i,N) for(ll i=0; i<(N); i++)
#define rep1(i,N) for(ll i=1; i<(N); i++)
#define pb push_back

int H,W,D;
P A[90005];
int cost[90005][90005];
int Q;

ll calc(ll a1,ll a2){
	ll x=A[a1].second;
	ll y=A[a1].first;
	ll i=A[a2].second;
	ll j=A[a2].first;
	return abs(x-i)+abs(y-j);
}

int main(){

cin.tie(0);
ios::sync_with_stdio(false);

cin>>H>>W>>D;

rep(h,H){
	rep(w,W){
		ll a;
		cin>>a;
		A[a].first=h+1;
		A[a].second=w+1;
	}
}

rep(i,D){
	ll to=i+1;
	while(1){
		if(to>D) cost[i+1][to]=cost[i+1][to-D]+calc(to-D,to);
		to+=D;
		if(to>H*W) break;
	}
}

cin>>Q;
rep(i,Q){
	ll L,R,d;
	cin>>L>>R;
	d=L%D;
	if(d==0) d=D;
	cout<<cost[d][R]-cost[d][L]<<endl;
}


}
	


Compiler output:
/tmp/ccaM9i02.o: in function `main':
a.cc:(.text+0x28d): relocation truncated to fit: R_X86_64_PC32 against symbol `Q' defined in .bss section in /tmp/ccaM9i02.o
a.cc:(.text+0x375): relocation truncated to fit: R_X86_64_PC32 against symbol `Q' defined in .bss section in /tmp/ccaM9i02.o
collect2: error: ld returned 1 exit status
Language: C++

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

typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1e18+7;
#define rep(i,N) for(ll i=0; i<(N); i++)
#define rep1(i,N) for(ll i=1; i<(N); i++)
#define pb push_back

int H,W,D;
P A[90005];
int cost[90005][90005];
int Q;

ll calc(ll a1,ll a2){
	ll x=A[a1].second;
	ll y=A[a1].first;
	ll i=A[a2].second;
	ll j=A[a2].first;
	return abs(x-i)+abs(y-j);
}

int main(){

cin.tie(0);
ios::sync_with_stdio(false);

cin>>H>>W>>D;

rep(h,H){
	rep(w,W){
		ll a;
		cin>>a;
		A[a].first=h+1;
		A[a].second=w+1;
	}
}

rep(i,D){
	ll to=i+1;
	while(1){
		if(to>D) cost[i+1][to]=cost[i+1][to-D]+calc(to-D,to);
		to+=D;
		if(to>H*W) break;
	}
}

cin>>Q;
rep(i,Q){
	ll L,R,d;
	cin>>L>>R;
	d=L%D;
	if(d==0) d=D;
	cout<<cost[d][R]-cost[d][L]<<endl;
}


}
	


Compiler output:
/tmp/cczEEmLU.o: in function `main':
a.cc:(.text+0x28d): relocation truncated to fit: R_X86_64_PC32 against symbol `Q' defined in .bss section in /tmp/cczEEmLU.o
a.cc:(.text+0x375): relocation truncated to fit: R_X86_64_PC32 against symbol `Q' defined in .bss section in /tmp/cczEEmLU.o
collect2: error: ld returned 1 exit status
Language: C++

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

typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1e18+7;
#define rep(i,N) for(ll i=0; i<(N); i++)
#define rep1(i,N) for(ll i=1; i<(N); i++)
#define pb push_back

ll H,W,D;
P A[90005];
ll cost[90005][90005];
ll Q;

ll calc(ll a1,ll a2){
	ll x=A[a1].second;
	ll y=A[a1].first;
	ll i=A[a2].second;
	ll j=A[a2].first;
	return abs(x-i)+abs(y-j);
}

int main(){

cin.tie(0);
ios::sync_with_stdio(false);

cin>>H>>W>>D;

rep(h,H){
	rep(w,W){
		ll a;
		cin>>a;
		A[a].first=h+1;
		A[a].second=w+1;
	}
}

rep(i,D){
	ll to=i+1;
	while(1){
		if(to>D) cost[i+1][to]=cost[i+1][to-D]+calc(to-D,to);
		to+=D;
		if(to>H*W) break;
	}
}

cin>>Q;
rep(i,Q){
	ll L,R,d;
	cin>>L>>R;
	d=L%D;
	if(d==0) d=D;
	cout<<cost[d][R]-cost[d][L]<<endl;
}


}
	


Compiler output:
/tmp/ccG7TnwK.o: in function `main':
a.cc:(.text+0x27e): relocation truncated to fit: R_X86_64_PC32 against symbol `Q' defined in .bss section in /tmp/ccG7TnwK.o
a.cc:(.text+0x368): relocation truncated to fit: R_X86_64_PC32 against symbol `Q' defined in .bss section in /tmp/ccG7TnwK.o
collect2: error: ld returned 1 exit status
Language: C++

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

typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1e18+7;
#define rep(i,N) for(ll i=0; i<(N); i++)
#define rep1(i,N) for(ll i=1; i<(N); i++)
#define pb push_back

ll H,W,D;
P A[90005];
ll cost[90005][90005];
ll Q;

ll calc(ll a1,ll a2){
	ll x=A[a1].second;
	ll y=A[a1].first;
	ll i=A[a2].second;
	ll j=A[a2].first;
	return abs(x-i)+abs(y-j);
}

int main(){

cin.tie(0);
ios::sync_with_stdio(false);

cin>>H>>W>>D;

rep(h,H){
	rep(w,W){
		ll a;
		cin>>a;
		A[a].first=h+1;
		A[a].second=w+1;
	}
}

rep(i,D){
	ll to=i+1;
	while(1){
		if(to>D) cost[i+1][to]=cost[i+1][to-D]+calc(to-D,to);
		to+=D;
		if(to>H*W) break;
	}
}

cin>>Q;
rep(i,Q){
	ll L,R,d;
	cin>>L>>R;
	d=L%D;
	if(d==0) d=D;
	cout<<cost[d][R]-cost[d][L]<<endl;
}


}
	


Compiler output:
/tmp/cc39pd5e.o: in function `main':
a.cc:(.text+0x27e): relocation truncated to fit: R_X86_64_PC32 against symbol `Q' defined in .bss section in /tmp/cc39pd5e.o
a.cc:(.text+0x368): relocation truncated to fit: R_X86_64_PC32 against symbol `Q' defined in .bss section in /tmp/cc39pd5e.o
collect2: error: ld returned 1 exit status
Language: C++

#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
int main(){
int h,w,d,a;
cin>>h>>w>>d;
vector<pair<oint,int>> vp(h*w+1);
rep(i,h)
  rep(j,w){
     cin>>a;
     vp[a].first=i;
     vp[a].second=j;
  }
  vector<int> v(h*w+1);
  for(int i=1;i<=d;i++){
     int f=vp[i].first,s=vp[i].second,b=0;
     for(int j=i;j<=h*w;j+=d){
        v[j]=abs(vp[j].first-f)+abs(vp[j].second-s)+b;
        b=v[j];
        f=vp[j].first;
        s=vp[j].second; 
     }
  }
  int q,l,r;
  cin>>q;
  rep(i,q){
     cin>>l>>r;
     cout<<v[r]-v[l]<<endl; 
  }
  return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:7:13: error: 'oint' was not declared in this scope; did you mean 'uint'?
    7 | vector<pair<oint,int>> vp(h*w+1);
      |             ^~~~
      |             uint
a.cc:7:18: error: template argument 1 is invalid
    7 | vector<pair<oint,int>> vp(h*w+1);
      |                  ^~~
a.cc:7:21: error: template argument 1 is invalid
    7 | vector<pair<oint,int>> vp(h*w+1);
      |                     ^~
a.cc:7:21: error: template argument 2 is invalid
a.cc:11:8: error: invalid types 'int[int]' for array subscript
   11 |      vp[a].first=i;
      |        ^
a.cc:12:8: error: invalid types 'int[int]' for array subscript
   12 |      vp[a].second=j;
      |        ^
a.cc:16:14: error: invalid types 'int[int]' for array subscript
   16 |      int f=vp[i].first,s=vp[i].second,b=0;
      |              ^
a.cc:18:20: error: invalid types 'int[int]' for array subscript
   18 |         v[j]=abs(vp[j].first-f)+abs(vp[j].second-s)+b;
      |                    ^
a.cc:18:39: error: invalid types 'int[int]' for array subscript
   18 |         v[j]=abs(vp[j].first-f)+abs(vp[j].second-s)+b;
      |                                       ^
a.cc:18:50: error: 's' was not declared in this scope
   18 |         v[j]=abs(vp[j].first-f)+abs(vp[j].second-s)+b;
      |                                                  ^
a.cc:18:53: error: 'b' was not declared in this scope
   18 |         v[j]=abs(vp[j].first-f)+abs(vp[j].second-s)+b;
      |                                                     ^
a.cc:20:13: error: invalid types 'int[int]' for array subscript
   20 |         f=vp[j].first;
      |             ^
a.cc:21:13: error: invalid types 'int[int]' for array subscript
   21 |         s=vp[j].second;
      |             ^
Language: C++

#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<endl
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define mp make_pair
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define sz(x) (int)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pll = pair<ll, ll>;
using vc = vector<char>;
using vvc = vector<vc>;
ll dx[4]={0,1,0,-1};
ll dy[4]={1,0,-1,0};
int main(){
  ll h,w,d;
  cin>>h>>w>>d;
  vector<pll> p(h*w);
  rep(i,h)rep(j,w) {
    ll a;
    cin>>a;
    a--;
    p[a]=mp(i+1,j+1);
  }
  ll q;
  cin>>q;
  ll ans=0;
  rep(i,q){
    ll a,b;
    cin>>a>>b;
    while(){
      ans+=(abs(p[a].F-p[a+d].F)+abs(p[a].S-p[a+d].S));
      if(a+d==b) break;
      a+=d;
    }
  }
  COUT(ans);
}


Compiler output:
a.cc: In function 'int main()':
a.cc:58:11: error: expected primary-expression before ')' token
   58 |     while(){
      |           ^
Language: C++

#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<endl
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define mp make_pair
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define sz(x) (int)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pll = pair<ll, ll>;
using vc = vector<char>;
using vvc = vector<vc>;
ll dx[4]={0,1,0,-1};
ll dy[4]={1,0,-1,0};
int main(){
  h,w,d;
  cin>>h>>w>>d;
  vector<pll> p(h*w);
  rep(i,h)rep(j,w) {
    ll a;
    cin>>a;
    a--;
    p[a]=mp(i+1,j+1);
  }
  ll q;
  cin>>q;
  ll ans=0;
  rep(i,q){
    ll a,b;
    cin>>a>>b;
    while(){
      ans+=(abs(p[a].F-p[a+d].F)+abs(p[a].S-p[a+d].S));
      if(a+d==b) break;
      a+=d;
    }
  }
  COUT(ans);
}

Compiler output:
a.cc: In function 'int main()':
a.cc:43:3: error: 'h' was not declared in this scope
   43 |   h,w,d;
      |   ^
a.cc:43:5: error: 'w' was not declared in this scope
   43 |   h,w,d;
      |     ^
a.cc:43:7: error: 'd' was not declared in this scope; did you mean 'dy'?
   43 |   h,w,d;
      |       ^
      |       dy
a.cc:58:11: error: expected primary-expression before ')' token
   58 |     while(){
      |           ^
Language: C++

n,m,d = map(int, input().split())

grid = [list(map(int, input().split())) for _ in range(n)]

q = int(input())

for _ in range(q):
    l,r = map(int, input().split())
    prev_x= -1
    prev_y = -1
    s = 0

    for j in range(l,r+1,d):
        for k in range(n):
            if j in grid[k]:
                y = (grid[k].index(j))+1
                x = k+1
                break
        if prev_x == -1 and prev_y == -1:
            prev_x = x
            prev_y = y
        else:
            s += abs(prev_x-x) + abs(prev_y-y)
            prev_x = x
            prev_y = y
    print(s)
            
                


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

#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define max3(a,b,c) max(max(a,b),c)
#define min3(a,b,c) min(min(a,b),c)
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define mod 1000000007
using namespace std;
typedef long long ll;
template<class T> using V=vector<T>;
using Graph = vector<vector<int>>;
using P=pair<ll,ll>;
typedef unsigned long long ull;
typedef long double ldouble;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//V,P(大文字)使用不可

const ll INF=1000000000000000000;

ll a[310][310];
map<ll,P> mp;
ll G[90010][90010];
ll h,w,d;

void solve(){
    rep(i,h){
        rep(j,w){
            mp[a[i][j]]=P(i,j);
        }
    }
    for(ll i=1;i<=d;i++){
        ll t=1;
        while(i+t*d<=h*w){
            G[i][i+t*d]=G[i][i+(t-1)*d]+abs(mp[i+t*d].ft-mp[i+(t-1)*d].ft)+abs(mp[i+t*d].sc-mp[i+(t-1)*d].sc);
            t++;
        }
    }
}

signed main(){
    cin>>h>>w>>d;
    rep(i,h){
        rep(j,w) cin>>a[i][j];
    }
    solve();
    int q;
    cin>>q;
    while(q--){
        ll l,r;
        cin>>l>>r;
        ll m;
        if(l%d==0) m=d;
        else m=l%d;
        cout<<G[m][r]-G[m][l]<<endl;
    }
}

Compiler output:
/tmp/ccozZxT9.o: in function `solve()':
a.cc:(.text+0x11): relocation truncated to fit: R_X86_64_PC32 against symbol `h' defined in .bss section in /tmp/ccozZxT9.o
a.cc:(.text+0x29): relocation truncated to fit: R_X86_64_PC32 against symbol `w' defined in .bss section in /tmp/ccozZxT9.o
a.cc:(.text+0xbb): relocation truncated to fit: R_X86_64_PC32 against symbol `w' defined in .bss section in /tmp/ccozZxT9.o
a.cc:(.text+0xc7): relocation truncated to fit: R_X86_64_PC32 against symbol `h' defined in .bss section in /tmp/ccozZxT9.o
a.cc:(.text+0x133): relocation truncated to fit: R_X86_64_PC32 against symbol `d' defined in .bss section in /tmp/ccozZxT9.o
a.cc:(.text+0x143): relocation truncated to fit: R_X86_64_PC32 against symbol `w' defined in .bss section in /tmp/ccozZxT9.o
a.cc:(.text+0x1e9): relocation truncated to fit: R_X86_64_PC32 against symbol `d' defined in .bss section in /tmp/ccozZxT9.o
a.cc:(.text+0x221): relocation truncated to fit: R_X86_64_PC32 against symbol `d' defined in .bss section in /tmp/ccozZxT9.o
a.cc:(.text+0x239): relocation truncated to fit: R_X86_64_PC32 against symbol `d' defined in .bss section in /tmp/ccozZxT9.o
a.cc:(.text+0x27b): relocation truncated to fit: R_X86_64_PC32 against symbol `d' defined in .bss section in /tmp/ccozZxT9.o
a.cc:(.text+0x285): additional relocation overflows omitted from the output
collect2: error: ld returned 1 exit status
Language: C++

#include<bits/stdc++.h>
using namespace std;
int H ,W ,D , A ;
int Q ,L , R ;
int px [90001] , py [90001];
int d [90001];
int main ()
{
cin>>H>>W>>D;
for ( int i =0; i < H ; i ++)
{
for ( int j =0; j < W ; j ++)
{
cin>>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 ]);
cin>>Q;
while (Q - -)
{
cin>>L>>R;
  cout<<d[R]-d[L]<<endl;
}
}


Compiler output:
a.cc: In function 'int main()':
a.cc:21:13: error: expected primary-expression before ')' token
   21 | while (Q - -)
      |             ^
Language: C++

#include<bits/stdc++.h>
using namespace std;
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: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 < bits/stdc++.h >

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:11: fatal error:  bits/stdc++.h : No such file or directory
    1 | # include < bits/stdc++.h >
      |           ^~~~~~~~~~~~~~~~~
compilation terminated.
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:
main.c:1:11: fatal error:  cstdio : No such file or directory
    1 | # include < cstdio >
      |           ^~~~~~~~~~
compilation terminated.
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:11: fatal error:  cstdio : No such file or directory
    1 | # include < cstdio >
      |           ^~~~~~~~~~
compilation terminated.
Language: C

#include <bits/stdc++.h>
using namespace std;
#define rep0(i,n) for(ll (i) = 0; (i) < (n); ++(i))
#define rrep0(i,n) for(ll (i) = (n) - 1; (i) >= 0; --(i))
#define rep1(i,n) for(ll (i) = 1; (i) <= (n); ++(i))
#define rrep1(i,n) for(ll (i) = (n); (i) >= 1; --(i))
#define nfor(i,a,b) for(ll (i) = (a); (i) < (b); ++(i))
#define rfor(i,a,b) for(ll (i) = (a); (i) > (b); --(i))
#define ll long long
#define mod (1000000007)
#define pf(x) cout << (x) << endl;
#define all(x) (x).begin(),(x).end()

ll gcd(ll a,ll b){
    if(b == 0) return a;
    return gcd(b,a%b);
}

ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b;
}

ll factorial(ll n){
    ll t = 1;
    rep1(i, n)t *= i;
    return t;
}

ll combinations(ll n, ll k) {
    ll r = 1;
    for (ll i = 1; i <= k; ++i) {
        r *= n--;
        r /= i;
    }
    return r;
}

ll f(unsigned ll n){
    if(n < 2)return 1;
    else return n * f(n - 2);
}

int main()
{
    ll h,w,d,q;
    cin >> h >> w >> d;
    map<ll, pair<ll,ll>> c;
    vector<vector<ll>> a(h + 1,vector<ll>(w + 1));
    rep1(i, h)rep1(j, w){
        cin >> a[i][j];
        c.insert(make_pair(a[i][j], make_pair(i, j)));
    }
    cin >> q;
    vector<ll> l(q),r(q);
    rep0(i, q)cin >> l[i] >> r[i];
    rep0(i, q){
        ll ans = 0;
        ll nl = l[i],nr = r[i];
        while (nl != nr) {
            ans += abs(c[nl].first - c[nl + d].first) + abs(c[nl].second - c[nl + d].second);
            nl += d;
        }
        pf(ans)
    }
    return 0;
}


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

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i<(int)(n); ++i)
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using Graph = vector<vector<int>>;  // int <=> ll
using P = pair<int, int>;  // int <=> ll
const int INFTY = 1e9+7;

int main() {
  int H, W, D; cin >> H >> W >> D;
  vector<P> place(H*W);
  rep(i,H) {
    rep(j,W) {
      int a; cin >> a; --a;
      place[a] = P(i,j);
    }
  }

  vi power(H*W);
  rep(i,H*W) {
    if (i<D) power[i] = 0;
    else {
      int x, y, nx, ny;
      tie(x,y) = place[i-D];
      tie(nx,ny) = place[i];
      power[i] += power[i-D] + abs(nx-x) + abs(ny-y);
  }
  
  int Q; cin >> Q;
  rep(i,Q) {
    int L, R; cin >> L >> R; --L; --R;
    cout << power[R] - power[L] << endl;
  }
  return 0;
}


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

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

// types
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};


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

  ll h,w,d;
  cin >> h >> w >> d;

  vector<pll> a(h*w);
  ll x;
  REP(i, h){
    REP(j, w){
      cin >> x;
      x--;
      a[x] = make_pair(h, w);
    }
  }    

  ll q;
  cin >> q;
  vector<pll> lr(q);
  REP(i, q)
    cin >> lr[i].FI >> lr[i].SE;    
  
  vector<vll>> dp(hw
}


Compiler output:
a.cc: In function 'int main()':
a.cc:61:13: error: expected unqualified-id before '>' token
   61 |   vector<vll>> dp(hw
      |             ^~
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)));
     }
   }
   vector<long long> b[d];
   for(int i = 0; d > i; i++){
     sort(a[i].begin(),a[i].end());
     b[i].push_back(0);
     b[i].push_back(a[i][1].second.first+a[i][1].second.second);
     for(int j = 1; a[i].size() >= j; j++){
       b[i].push_back(b[i][j]+abs(a[i][j].second.first-a[i][j-1].second.first)+abs(a[i][j].second.second-a[i][j-1].second.second));
     }
   }
   int q;cin>>q;
   for(int _ = 0; q > _; _++){
     int x,y;cin>>x>>y;
     int ans = b[x%d][(y-1)/d+1]-b[x%d][(x-1)/d+1];
     cout << ans << endl;
   }
 }   

Compiler output:
a.cc: In function 'int main()':
a.cc:14:21: error: expected ';' before 'a'
   14 |        cin>>mp[i][j]
      |                     ^
      |                     ;
   15 |        a[mp[i][j]%d].push_back(make_pair(mp[i][j],make_pair(i,j)));
      |        ~
Language: C++

#include <bits/stdc++.h>

#include <math.h>
#include <stdlib.h>


#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

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

//INT_MAX	2,147,483,647 = 2*1.0e9

int main(){

    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    int H, W, D;
    cin >> H >> W >> D;

    vector<int> x(H*W+1);
    vector<int> y(H*W+1);
    for(int i = 0; i < H*W; i++){
        int a; cin >> a;
        x[a] = (i%W)+1;
        y[a] = (i/W)+1;
    }

    vector<int> dist(H*W+1, 0);
    for(int i = D+1; i < H*W+1; i++){
        dist[i] = dist[i-D] + abs(x[i-D] - x[i]) + abs(y[i-D] - y[i]);
    }

    int Q; cin >> Q;
    for(int i=0; i<Q; i++){
        int l, r; cin >> l >> r;
      	cout << dist[r]-dist[l]; << endl;
    }

    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:40:34: error: expected primary-expression before '<<' token
   40 |         cout << dist[r]-dist[l]; << endl;
      |                                  ^~
Language: C++

#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
const ll mod=1e9+7;

int main(){
	int H,W,D,Q;
	cin >> H >> W >> D;
	vector<vi> B(H*W,vi(2));
	for(int i=1; i<=H; i++){
		for(int j=1; j<=W; j++){
			int A;
			cin >> A;
			A--;
			B[A][0]=i;
			B[A][1]=j;
		}
	}
	cin >> Q;
	vi L(Q),R(Q);
	for(int i=0; i<Q; i++){
		cin >> L[i] >> R[i];
		L[i]--;
		R[i]--;
	}

/*	vector<vi> dp(D,vi(0));
	for(int i=0; i<D; i++){
		dp[i%D].push_back(abs(B[i+D][0]-B[i][0])+abs(B[i+D][1]-B[i][1]));
	}
	for(int i=D; i<H*W-D; i++){
		dp[i%D].push_back(dp[i%D][dp[i%D].size()-1]+abs(B[i+D][0]-B[i][0])+abs(B[i+D][1]-B[i][1]));
	}
*/
	vi dp(H*W,0);
	for(int i=0; i<H*W-D; i++){
		dp[i+D]=dp[i]+abs(B[i+D][0]-B[i][0])+abs(B[i+D][1]-B[i][1]);
	}

	for(int i=0; i<Q; i++){
		int ans=0;
		if(R[i]>0){
			ans=dp[R[i]-dp[L[i-1];
		}else{
			ans=dp[R[i]];
		}
		cout << ans << endl;
	}

	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:51:46: error: expected ']' before ';' token
   51 |                         ans=dp[R[i]-dp[L[i-1];
      |                                              ^
      |                                              ]
a.cc:51:46: error: expected ']' before ';' token
   51 |                         ans=dp[R[i]-dp[L[i-1];
      |                                              ^
      |                                              ]
Language: C++

#include <stdio.h>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
int main(){
  int h,w,d;
  scanf("%d %d %d",&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++){
      scanf("%d",&mp[i][j]);
      a[mp[i][j]%d].push_back(make_pair(mp[i][j],make_pair(i,j)));
    }
  }
  for(int i = 0; d > i; i++){
    sort(a[i%d].begin(),a[i%d].end());
  int q;
  scanf("%d",&q);
  for(int _ = 0; q > _; _++){
    int x,y;
    scanf("%d %d",&x,&y);
    int ans = 0;
    for(int i = (x-1)/d+1; (y-1)/d+1 > i; i++){
      ans += abs(a[x%d][i].second.first-a[x%d][i-1].second.first)+abs(a[x%d][i].second.second-a[x%d][i-1].second.second);
    }
    printf("%d\n",ans);
  }
}    

Compiler output:
a.cc: In function 'int main()':
a.cc:30:2: error: expected '}' at end of input
   30 | }
      |  ^
a.cc:6:11: note: to match this '{'
    6 | int main(){
      |           ^
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)));
    }
  }
  for(int i = 0; d > i; i++){
    sort(a[x%d].begin(),a[x%d].end());
  }
  int q;cin>>q;
  for(int _ = 0; q > _; _++){
    int x,y;cin>>x>>y;
    long long ans = 0;
    for(int i = (x-1)/d+1; (y-1)/d+1 > i; i++){
      //cerr << i << ":" << a[x%d][i].second.first << " " << a[x%d][i-1].second.first << " " << a[x%d][i].second.second << " " << a[x%d][i-1].second.second << endl;
      ans += abs(a[x%d][i].second.first-a[x%d][i-1].second.first)+abs(a[x%d][i].second.second-a[x%d][i-1].second.second);
      //cout << ans << endl;
    }
    cout << ans << endl;
  }
}    

Compiler output:
a.cc: In function 'int main()':
a.cc:17:12: error: 'x' was not declared in this scope
   17 |     sort(a[x%d].begin(),a[x%d].end());
      |            ^