func_code_string: #include <bits/stdc++.h>   inline int read() {     char c = getchar();     while (c !=  -  && (c <  0  || c >  9 )) c = getchar();     int k = 0, kk = 1;     if (c ==  - ) c = getchar(), kk = -1;     while (c >=  0  && c <=  9 ) k = k * 10 + c -  0 , c = getchar();     return kk * k;   }   using namespace std;   void write(int x) {     if (x < 0) x = -x, putchar( - );     if (x / 10) write(x / 10);     putchar(x % 10 +  0 );   }   void writeln(int x) {     write(x);     puts(  );   }   int n, m, k, x[1000000], y[1000000], l[1000000], r[1000000], f[1000000];   struct lsg {     int x, y, d, bj;   } a[1000000], ff[1000000];   bool cmp1(lsg x, lsg y) { return x.d < y.d; }   bool cmp2(lsg x, lsg y) { return x.x < y.x; }   bool cmp3(lsg x, lsg y) { return x.y > y.y; }   bool pd(int kkk) {     int d = 0, dd = 0, ddd = 0;     memset(a, 0, sizeof(a));     for (int i = 1; i <= k; i++) {       a[++d].d = x[i] - kkk;       a[d].x = y[i] - kkk;       a[d].y = y[i] + kkk;       a[d].bj = i;       a[++d].d = x[i] + kkk + 1;       a[d].bj = -i;     }     a[++d].d = 1;     a[++d].d = n;     sort(a + 1, a + 1 + d, cmp1);     a[d + 1].d = -1e9;     for (int i = 1; i <= d; i++) {       if (a[i].bj > 0) {         ff[++dd].x = a[i].x;         ff[dd].y = a[i].y;         ff[dd].bj = a[i].bj;       } else if (a[i].bj < 0) {         int kk = 0;         for (int j = 1; j <= dd; j++)           if (ff[j].bj != -a[i].bj) ff[++kk] = ff[j];         dd = kk;       }       if (a[i].d != a[i + 1].d && a[i].d >= 1 && a[i].d <= n) {         sort(ff + 1, ff + 1 + dd, cmp2);         l[++ddd] = 1;         r[ddd] = m;         f[ddd] = a[i].d;         for (int j = 1; j <= dd; j++) {           if (l[ddd] >= ff[j].x) l[ddd] = max(l[ddd], ff[j].y + 1);         }         sort(ff + 1, ff + 1 + dd, cmp3);         for (int j = 1; j <= dd; j++) {           if (r[ddd] <= ff[j].y) r[ddd] = min(r[ddd], ff[j].x - 1);         }       }     }     int ll = 1, rr = ddd, lll = m, rrr = 1;     f[ddd + 1] = n;     f[ddd + 2] = n + 1;     while (l[ll] > r[ll] && ll <= rr) ll++;     while (l[rr] > r[rr] && ll <= rr) rr--;     if (f[rr + 1] - 1 - f[ll] > kkk * 2) return 0;     for (int i = ll; i <= rr; i++) lll = min(lll, l[i]), rrr = max(rrr, r[i]);     if (rrr - lll > kkk * 2) return 0;     return 1;   }   signed main() {     n = read();     m = read();     k = read();     for (int i = 1; i <= k; i++) x[i] = read(), y[i] = read();     int l = 0, r = max(n, m);     while (l < r) {       int m = (l + r) / 2;       if (pd(m))         r = m;       else         l = m + 1;     }     cout << l << endl;   }   