#include #define rep(i,s,n) for (int i = (int)(s); i < (int)(n); i++) #define all(v) begin(v),end(v) using namespace std; using ll = long long; bool chmin(auto &a, auto b){ return a > b ? a = b, 1 : 0; } bool chmax(auto &a, auto b){ return a < b ? a = b, 1 : 0; } int main(){ cin.tie(0)->sync_with_stdio(0); int h, w, n; cin >> h >> w >> n; vector a(n), b(n); vector ikeru(2*(h+w), vector(0)); rep(i,0,n) { cin >> a[i] >> b[i]; a[i] -= 1; b[i] -= 1; ikeru[a[i]].push_back(b[i]+w); ikeru[b[i]+w].push_back(a[i]); ikeru[a[i]+h+w].push_back(b[i]+h+h+w); ikeru[b[i]+h+h+w].push_back(a[i]+h+w); } vector dp(h+1,-1e18); vector dp2(h+1,1e18); dp[0] = 0; dp2[0] = 0; vector seen(2*(h+w)); int px = 0, py = 0; int ax = 0, ay = 0; auto dfs = [&](auto self, int i) -> void { if (0 <= i && i < h){ px++; ax++; } if (h <= i && i < h + w){ py++; ay++; } if (h + w <= i && i < h + w + h) { ax++; } if (h + w + h <= i && i < h + w + h + w){ ay++; } seen[i] = true; seen[(i + h + w) % (2 * (h + w))] = true; for (int j: ikeru[i]){ if (seen[j]) continue; self(self, j); } }; rep(i,0,h+w){ if (seen[i] || seen[i+h+w]) continue; px = 0; py = 0; ax = 0; ay = 0; dfs(dfs, i); vector ndp(h+1,-1e18); vector ndp2(h+1,1e18); rep(j,0,h+1){ if (j+px <= h) { chmax(ndp[j+px], dp[j] + py); chmin(ndp2[j+px], dp2[j] + py); } if (j+ax-px <= h) { chmax(ndp[j+ax-px], dp[j] + ay-py); chmin(ndp2[j+ax-px], dp2[j] + ay-py); } } swap(dp, ndp); swap(dp2, ndp2); } ll ans = 0; rep(i,0,h+1){ if (dp[i] >= 0){ chmax(ans, (ll)i * w + (ll)dp[i] * h - 2 * (ll)i * dp[i]); chmax(ans, (ll)i * w + (ll)dp2[i] * h - 2 * (ll)i * dp2[i]); } } cout << ans << '\n'; }