#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); dp[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); rep(i,0,h+1){ if (i+px <= h) { chmax(ndp[i+px], dp[i] + py); } if (i+ax-px <= h) { chmax(ndp[i+ax-px], dp[i] + ay-py); } } swap(dp, ndp); } ll ans = 1e18; rep(i,0,h+1){ if (dp[i] >= 0){ chmin(ans, (ll)(h - i) * (w - dp[i]) + (ll)i * dp[i]); } } ans = h * w - ans; cout << ans << '\n'; }