#include #include int main() { int H, W, N; std::cin >> H >> W >> N; atcoder::dsu uf(H + W); for (int i = 0; i < N; i++) { int A, B; std::cin >> A >> B; A--; B--; uf.merge(A, H + B); } std::vector> g = uf.groups(); int L = g.size(); std::vector c(L), d(L); for (int i = 0; i < L; i++) { for (int u: g[i]) { if (u < H) c[i]++; else d[i]++; } } std::vector dp1(H + 1, -1), dp2(H + 1, 1e9); dp1[0] = 0; dp2[0] = 0; for (int i = 0; i < L; i++) { for (int j = H; j >= 0; j--) { if (dp1[j] != -1 && j + c[i] <= H) { dp1[j + c[i]] = std::max(dp1[j + c[i]], dp1[j] + d[i]); dp2[j + c[i]] = std::min(dp2[j + c[i]], dp2[j] + d[i]); } } } int ans = 0; for (int i = 0; i <= H; i++) { if (dp1[i] != -1) ans = std::max(ans, i * (W - dp1[i]) + (H - i) * dp1[i]); if (dp2[i] != 1e9) ans = std::max(ans, i * (W - dp2[i]) + (H - i) * dp2[i]); } std::cout << ans << '\n'; }