#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define re(i,a,b) for(int i=(a);i<(b);i++)
#define repd(i,a,b) for(int i=(a);i>=(b);i--)
#define clr(a) memset(a,0,sizeof(a));
#define il inline
#define sz(a) ((int)a.size())
#define all(a) a.begin(),a.end()
#define mp make_pair
#define pb push_back 
#define w1 first
#define w2 second
#define adm(a,b,c) {a=a+b;if(a>=c)a-=c;else if(a<0)a+=c;}
typedef double db;
typedef long long ll;typedef long double ld;typedef unsigned long long ull;
typedef pair<ll,ll> pa;
const int N=3e6+5,M=2e2+5,INF=1e9,mod=998244353;
const ll linf=1e18;const double eps=1e-8,pi=acos(-1);
il int gmin(int &a,int b){if(a>b)a=b;}il ll gmin(ll &a,ll b){if(a>b)a=b;}il int gmax(int &a,int b){if(a<b)a=b;}il ll gmax(ll &a,ll b){if(a<b)a=b;}
il void read(ll&x){ll f=1,t=0;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){t=t*10+ch-'0';ch=getchar();}x=t*f;}il ll read(ll&x,ll&y){read(x);read(y);}
il void read(int&x){int f=1,t=0;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){t=t*10+ch-'0';ch=getchar();}x=t*f;}il int read(int&x,int&y){read(x);read(y);}
il void read(int&a,int&b,int&c){read(a);read(b);read(c);}il void read(ll&a,ll&b,ll&c){read(a);read(b);read(c);}
il int read(){int x;read(x);return x;}
il ll qpow(ll a,ll b,ll p){ll ret=1;for(;b;b>>=1,a=a*a%p)if(b&1)ret=ret*a%p;return ret;}il ll qpow(ll a,ll b){ll ret=1;for(;b;b>>=1,a=a*a%mod)if(b&1)ret=ret*a%mod;return ret;}
il ll qmul(ll a,ll b,ll p){ll ret=0;for(;b;b>>=1,a=(a<<1)%p)if(b&1)adm(ret,a,p);return ret;}il ll qmul(ll a,ll b){ll ret=0;for(;b;b>>=1,a=(a<<1)%mod)if(b&1)adm(ret,a,mod);return ret;}
il void judge(){
	freopen("loopy10.in","r",stdin);
	freopen("loopy10.out","w",stdout);}
struct P{int x,y;}p[N];
int w,h,n;
bool cmp(P a,P b){return a.x<b.x;}
#define ls (k<<1)
#define rs (k<<1|1)
#define mid (((l)+(r))>>1)
#define lson ls,l,mid
#define rson rs,mid+1,r
#define rt 1,1,n
int tg[N],mx[N],res,st1[N],st2[N];
void build(int k,int l,int r){tg[k]=0;
	if(l==r){mx[k]=-p[l-1].x;return;}
	build(lson);build(rson);
	mx[k]=max(mx[ls],mx[rs]);
}
void modi(int k,int l,int r,int x,int y,int ad){
	if(l==x&&r==y){tg[k]+=ad;mx[k]+=ad;return;}
	if(y<=mid)modi(lson,x,y,ad);else
	if(x> mid)modi(rson,x,y,ad);else
		modi(lson,x,mid,ad),modi(rson,mid+1,y,ad);
	mx[k]=max(mx[ls],mx[rs])+tg[k];
}
void print(int k,int l,int r,int ad=0){
	if(l==r){printf("%d ",ad+mx[k]);return;}
	print(lson,ad+tg[k]);
	print(rson,ad+tg[k]);
}
void solve(){
	sort(p+1,p+1+n,cmp);
	if(p[n].x!=w)p[++n]=(P){w,-1};
	//print(rt);puts("");
	build(rt);int p1=0,p2=0;
	rep(i,1,n)if(p[i].y>h/2){
		modi(rt,i,i,h);
		//print(rt);puts("");
		gmax(res,2*(p[i].x+mx[1]));
		modi(rt,st1[p1]+1,i,p[i].y-h);
		//print(rt);puts("");
		while(p1&&p[st1[p1]].y>p[i].y)modi(rt,st1[p1-1]+1,st1[p1],p[i].y-p[st1[p1]].y),p1--;
		//print(rt);puts("");
		st1[++p1]=i;
	}else{
		modi(rt,i,i,h);
		//print(rt);puts("");
		gmax(res,2*(p[i].x+mx[1]));
		modi(rt,st2[p2]+1,i,-p[i].y);
		//print(rt);puts("");
		while(p2&&p[st2[p2]].y<p[i].y)modi(rt,st2[p2-1]+1,st2[p2],p[st2[p2]].y-p[i].y),p2--;
		//print(rt);puts("");
		st2[++p2]=i;
	}if(p[n].y<0)n--;
}
int main(){
	read(w,h,n);
	rep(i,1,n)read(p[i].x,p[i].y);
	solve();
	rep(i,1,n)swap(p[i].x,p[i].y);swap(w,h);
	solve();
	cout<<res<<endl;
}

Measured memory_bytes: 20992