#include #include using namespace std; using ll = long long; int main() { std::ios_base::sync_with_stdio(false); std::cin.tie(nullptr); int h, w, n; cin >> h >> w >> n; atcoder::dsu uf(h + w); vector a(n), b(n); for (int i = 0; i < n; i++) { cin >> a[i] >> b[i]; a[i]--, b[i]--; uf.merge(a[i], b[i] + h); } vector dp(h + 1, vector(w + 1)); dp[0][0] = 1; auto G = uf.groups(); const int K = G.size(); assert((ll)K * h * w <= 2e6); for (int i = 0; i < K; i++) { int r = 0, c = 0; for (int x : G[i]) { r += x < h; c += x >= h; } vector ndp = dp; for (int j = 0; j <= h; j++) { for (int k = 0; k <= w; k++) { if (dp[j][k]) { ndp[j + r][k + c] = 1; } } } dp = std::move(ndp); } ll ans = 0; for (int i = 0; i <= h; i++) { for (int j = 0; j <= w; j++) { if (dp[i][j]) ans = max(ans, i * w + j * h - 2 * i * j); } } cout << ans << "\n"; }