#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/rope>

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) for (int i = 0; i < (a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= (a); i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define trav(a, x) for (auto& a : x)

#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound

#define sz(x) (int)x.size()
#define beg(x) x.begin()
#define en(x) x.end()
#define all(x) beg(x), en(x)
#define resz resize

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001;
const ld PI = 4*atan((ld)1);

template<class T> void ckmin(T &a, T b) { a = min(a, b); }
template<class T> void ckmax(T &a, T b) { a = max(a, b); }

namespace io {
    // TYPE ID (StackOverflow)
    
    template<class T> struct like_array : is_array<T>{};
    template<class T, size_t N> struct like_array<array<T,N>> : true_type{};
    template<class T> struct like_array<vector<T>> : true_type{};
    template<class T> bool is_like_array(const T& a) { return like_array<T>::value; }

    // I/O 
    
    void setIn(string s) { freopen(s.c_str(),"r",stdin); }
    void setOut(string s) { freopen(s.c_str(),"w",stdout); }
    void setIO(string s = "") {
        ios_base::sync_with_stdio(0); cin.tie(0);
        if (sz(s)) { setIn(s+".in"), setOut(s+".out"); }
    }
    
    // INPUT 
    
    template<class T> void re(T& x) { cin >> x; }
    template<class Arg, class... Args> void re(Arg& first, Args&... rest);
    void re(double& x) { string t; re(t); x = stod(t); }
    void re(ld& x) { string t; re(t); x = stold(t); }
    
    template<class T> void re(complex<T>& x);
    template<class T1, class T2> void re(pair<T1,T2>& p);
    template<class T> void re(vector<T>& a);
    template<class T, size_t SZ> void re(array<T,SZ>& a);
    
    template<class Arg, class... Args> void re(Arg& first, Args&... rest) { re(first); re(rest...); }
    template<class T> void re(complex<T>& x) { T a,b; re(a,b); x = cd(a,b); }
    template<class T1, class T2> void re(pair<T1,T2>& p) { re(p.f,p.s); }
    template<class T> void re(vector<T>& a) { F0R(i,sz(a)) re(a[i]); }
    template<class T, size_t SZ> void re(array<T,SZ>& a) { F0R(i,SZ) re(a[i]); }
    
    // OUTPUT 
    
    template<class T1, class T2> ostream& operator<<(ostream& os, const pair<T1,T2>& a) {
        os << '{' << a.f << ", " << a.s << '}'; return os;
    }
    template<class T> ostream& printArray(ostream& os, const T& a, int SZ) {
        os << '{';
        F0R(i,SZ) {
            if (i) {
                os << ", ";
                if (is_like_array(a[i])) cout << "\n";
            }
            os << a[i];
        }
        os << '}';
        return os;
    }
    template<class T, size_t SZ> ostream& operator<<(ostream& os, const array<T,SZ>& a) {
        return printArray(os,a,SZ);
    }
    template<class T> ostream& operator<<(ostream& os, const vector<T>& a) {
        return printArray(os,a,sz(a));
    }
    template<class T> ostream& operator<<(ostream& os, const set<T>& a) {
        os << vector<T>(all(a)); return os;
    }
    template<class T1, class T2> ostream& operator<<(ostream& os, const map<T1,T2>& a) {
        os << vector<pair<T1,T2>>(all(a)); return os;
    }
    
    template<class T> void pr(const T& x) { cout << x << '\n'; }
    template<class Arg, class... Args> void pr(const Arg& first, const Args&... rest) { 
        cout << first << ' '; pr(rest...); 
    }
}

using namespace io;

int W,H,N;
ll ans;

void normalize(vector<pair<int,pi>>& x, int lo, int hi) {
    F0Rd(i,sz(x)) {
        if (i) x[i].s = x[i-1].s;
        else x[i].s = {lo,hi};
    }
    FOR(i,1,sz(x)) {
        ckmax(x[i].s.f,x[i-1].s.f);
        ckmin(x[i].s.s,x[i-1].s.s);
    }
}


struct MaxDeque { 
    int lo = 0, hi = -1;
    deque<pl> d;
    
    void ins(ll x) { // add to back
        while (sz(d) && d.back().f <= x) d.pop_back();
        d.pb({x,++hi});
    }
    
    void del() { // delete from front
        if (d.front().s == lo++) d.pop_front();
    }
    
    ll get() { 
        return sz(d) ? d.front().f : -INF;
    }
};

bool contain(pi a, pi b) {
    return a.f <= b.f && b.s <= a.s;
}

MaxDeque d[2];

void del() {
    d[0].del(), d[1].del();
}

void ins(vector<pair<int,pi>>& a, int ind, pi x) {
    if (a[ind].s.f < x.f) d[0].ins(a[ind].f+a[ind].s.s);
    else d[0].ins(-INF);
    if (a[ind].s.s > x.s) d[1].ins(a[ind].f-a[ind].s.f);
    else d[1].ins(-INF);
}

void tri(int lo, int med, int hi, vpi v) {
    vector<pair<int,pi>> a, b;
    d[0] = d[1] = MaxDeque();
    // <= W/2 
    // <= med, > med 
    b.pb({W/2,{lo,hi}});
    trav(x,v) {
        if (x.f > W/2) {
            if (x.s <= med) a.pb({x.f-W/2,{x.s,hi}});
            else a.pb({x.f-W/2,{lo,x.s}});
        } else {
            if (x.s <= med) b.pb({W/2-x.f,{x.s,hi}});
            else b.pb({W/2-x.f,{lo,x.s}});
        }
    }
    a.pb({W-W/2,{lo,hi}});
    reverse(all(b));
    normalize(a,lo,hi), normalize(b,lo,hi);
    int ind = sz(a)-1, ind2 = sz(a), cons = 0;
    F0Rd(i,sz(b)) {
        while (!contain(a[ind].s,b[i].s)) {
            ins(a,ind,b[i].s);
            ind --;
        }
        while (ind2 > ind+1 && contain(b[i].s,a[ind2-1].s)) {
            ind2 --;
            ckmax(cons,a[ind2].s.s-a[ind2].s.f+a[ind2].f);
            del();
        }
        ckmax(ans,(ll)b[i].f+b[i].s.s-b[i].s.f+a[ind].f);
        ckmax(ans,b[i].f+b[i].s.s+d[1].get());
        ckmax(ans,b[i].f-b[i].s.f+d[0].get());
        ckmax(ans,(ll)b[i].f+cons);
    }
}

void solve(int lo, int hi, vpi v) {
    if (sz(v) == 0) {
        ckmax(ans,(ll)W+hi-lo);
        return;
    }
    vi y; trav(x,v) y.pb(x.s);
    nth_element(y.begin(),y.begin()+sz(y)/2,y.end());
    int med = y[sz(y)/2];
    tri(lo,med,hi,v);
    vpi V[2];
    trav(x,v) {
        if (x.s < med) V[0].pb(x);
        else if (x.s > med) V[1].pb(x);
    }
    solve(lo,med,V[0]);
    solve(med,hi,V[1]);
}

int main() {
    // you should actually read the stuff at the bottom
    setIO(); re(W,H,N); vpi v(N); re(v);
    sort(all(v)); solve(0,H,v);
    swap(W,H); trav(x,v) swap(x.f,x.s); 
    sort(all(v)); solve(0,H,v);
    pr(2*ans);
    // you should actually read the stuff at the bottom
}

/* stuff you should look for
    * int overflow, array bounds
    * special cases (n=1?), set tle
    * do smth instead of nothing and stay organized
*/


Measured memory_bytes: 22212