func_code_string: #include <bits/stdc++.h>   using namespace std;   const int N = 2012;   int f[N][N][2];   int n, m, k, flag;   int ex, ey;   inline int find(int x, int y, int p) {     if (y < 0) return y;     return f[x][y][p] == y ? y : f[x][y][p] = find(x, f[x][y][p], p);   }   int dis(int x, int y) { return abs(ex - x) + abs(ey - y); }   inline void chk(int &ans, int nx, int ny, int &x, int &y) {     int d = dis(nx, ny);     if (d < ans) {       ans = d, x = nx, y = ny;     } else if (ans == d) {       if (!flag) {         if (nx < x) {           x = nx, y = ny;         } else if (nx == x && ny < y)           y = ny;       } else {         if (ny < y) {           x = nx, y = ny;         } else if (ny == y && nx < x)           x = nx;       }     }   }   void update(int r, int &ans, int &x, int &y) {     int nx = r, ny = find(r, ey, 0);     if (ny > 0) chk(ans, nx, ny, x, y);     ny = find(r, ey, 1);     if (ny <= m) chk(ans, nx, ny, x, y);   }   int main() {     for (int i = 0; i < N; i++)       for (int j = 0; j < N; j++) f[i][j][0] = f[i][j][1] = j;     int x, y;     scanf( %d%d%d , &n, &m, &k);     if (n > m) swap(n, m), flag = 1;     while (k--) {       scanf( %d%d , &x, &y);       if (flag) swap(x, y);       ex = x, ey = y;       int d = 0, ans = ~0u >> 2, nx, ny;       while (d <= ans) {         int pre = ans;         int r = x - d;         if (r > 0 && r <= n) update(r, ans, nx, ny);         r = x + d;         if (r > 0 && r <= n) update(r, ans, nx, ny);         d++;       }       f[nx][ny][0] = ny - 1;       f[nx][ny][1] = ny + 1;       if (flag) swap(nx, ny);       printf( %d %d n , nx, ny);     }     return 0;   }   