Language: C++

#include <algorithm>
#include <cstdio>
#include <iostream>
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define lson u << 1, l, mid
#define rson u << 1 | 1, mid + 1, r
using namespace std;
inline char nc() {
//	return getchar();
	static char buf[100000], *l = buf, *r = buf;
	return l==r&&(r=(l=buf)+fread(buf,1,100000,stdin),l==r)?EOF:*l++;
}
template<class T> void read(T &x) {
	x = 0; int f = 1, ch = nc();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=nc();}
	while(ch>='0'&&ch<='9'){x=x*10-'0'+ch;ch=nc();}
	x *= f;
}
const int inf = 1e9;
const int maxn = 3e5 + 10;
int W, H, N;
int x[maxn], y[maxn];
int p[2];
int xL[maxn];
int xR[maxn];
int h[2][maxn];
namespace seg {
	int mx[maxn << 2];
	int tag[maxn << 2];
	inline void change(int u, int d) {
		mx[u] += d;
		tag[u] += d;
	}
	inline void pushup(int u) {
		mx[u] = max(mx[u << 1], mx[u << 1 | 1]);
	}
	inline void pushdown(int u) {
		if(tag[u]) {
			change(u << 1, tag[u]);
			change(u << 1 | 1, tag[u]);
			tag[u] = 0;
		}
	}
	void build(int u, int l, int r, int *a) {
		tag[u] = 0;
		if(l == r) {
			mx[u] = -a[l];
			return;
		}
		int mid = (l + r) >> 1;
		build(lson, a);
		build(rson, a);
		pushup(u);
	}
	void update(int u, int l, int r, int ql, int qr, int qv) {
		if(ql > qr) return;
		if(l == ql && r == qr) {
			change(u, qv);
			return;
		}
		int mid = (l + r) >> 1;
		pushdown(u);
		if(qr <= mid) update(lson, ql, qr, qv);
		else if(ql > mid) update(rson, ql, qr, qv);
		else {
			update(lson, ql, mid, qv);
			update(rson, mid + 1, qr, qv);
		}
		pushup(u);
	}
}
int solve(int W, int H, int *x, int *y, int *Hx, int *Hy, int mid) {
	static int mn[maxn], mnt; mnt = 0;
	static int mx[maxn], mxt; mxt = 0;
	for(int i = 1; i <= H; ++i) xL[i] = 0, xR[i] = Hx[W];
	for(int i = 1; i <= N; ++i) {
		if(x[i] < mid) {
			xL[y[i]] = max(xL[y[i]], Hx[x[i]]);
		}
		else {
			xR[y[i]] = min(xR[y[i]], Hx[x[i]]);
		}
	}
	int an = Hx[W] + 1;
	seg :: build(1, 0, H, Hy);
	for(int i = 1; i <= H; ++i) {
		an = max(an, Hy[i] + seg :: mx[1]);
		while(mxt && xL[i] >= xL[mx[mxt]]) {
			seg :: update(1, 0, H, mx[mxt - 1], mx[mxt] - 1, xL[mx[mxt]]);
			--mxt;
		}
		mx[++mxt] = i;
		seg :: update(1, 0, H, mx[mxt - 1], i - 1, -xL[i]);
		while(mnt && xR[i] <= xR[mn[mnt]]) {
			seg :: update(1, 0, H, mn[mnt - 1], mn[mnt] - 1, -xR[mn[mnt]]);
			--mnt;
		}
		mn[++mnt] = i;
		seg :: update(1, 0, H, mn[mnt - 1], i - 1, xR[i]);
	}
	return an;
} 
int solve() {
	h[0][++p[0]] = 0, h[0][++p[0]] = W / 2, h[0][++p[0]] = W / 2 + 1, h[0][++p[0]] = W;
	h[1][++p[1]] = 0, h[1][++p[1]] = H / 2, h[1][++p[1]] = H / 2 + 1, h[1][++p[1]] = H;
	sort(h[0] + 1, h[0] + p[0] + 1);
	sort(h[1] + 1, h[1] + p[1] + 1);
	p[0] = unique(h[0] + 1, h[0] + p[0] + 1) - h[0] - 1;
	p[1] = unique(h[1] + 1, h[1] + p[1] + 1) - h[1] - 1;1
	for(int i = 1; i <= N; ++i) {
		x[i] = lower_bound(h[0] + 1, h[0] + p[0] + 1, x[i]) - h[0];
		y[i] = lower_bound(h[1] + 1, h[1] + p[1] + 1, y[i]) - h[1];
	}
	int an = 0;
	h[0][0] = h[1][0] = inf;
	an = max(an, solve(p[0], p[1], x, y, h[0], h[1], lower_bound(h[0] + 1, h[0] + p[0] + 1, W / 2) - h[0]));
	an = max(an, solve(p[0], p[1], x, y, h[0], h[1], lower_bound(h[0] + 1, h[0] + p[0] + 1, W / 2 + 1) - h[0]));
	an = max(an, solve(p[1], p[0], y, x, h[1], h[0], lower_bound(h[1] + 1, h[1] + p[1] + 1, H / 2) - h[1]));
	an = max(an, solve(p[1], p[0], y, x, h[1], h[0], lower_bound(h[1] + 1, h[1] + p[1] + 1, H / 2 + 1) - h[1]));
	return an << 1;
}
int main() {
	read(W), read(H), read(N);
	for(int i = 1; i <= N; ++i) {
		read(x[i]), read(y[i]);
		h[0][++p[0]] = x[i];
		h[1][++p[1]] = y[i]; 
	}
	printf("%d\n", solve());
	return 0;
}

Compiler output:
a.cc: In function 'int solve()':
a.cc:109:62: error: expected ';' before 'for'
  109 |         p[1] = unique(h[1] + 1, h[1] + p[1] + 1) - h[1] - 1;1
      |                                                              ^
      |                                                              ;
  110 |         for(int i = 1; i <= N; ++i) {
      |         ~~~                                                   
a.cc:110:24: error: 'i' was not declared in this scope
  110 |         for(int i = 1; i <= N; ++i) {
      |                        ^