#include namespace { #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wunused-function" #include #pragma GCC diagnostic pop using namespace std; using namespace atcoder; #define rep(i,n) for(int i = 0; i < (int)(n); i++) #define rrep(i,n) for(int i = (int)(n) - 1; i >= 0; i--) #define all(x) begin(x), end(x) #define rall(x) rbegin(x), rend(x) template bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; } template bool chmin(T& a, const T& b) { if (b < a) { a = b; return true; } else return false; } using ll = long long; using P = pair; using VI = vector; using VVI = vector; using VL = vector; using VVL = vector; struct S { int il, jl, ir, jr; friend ostream& operator<<(ostream& os, const S& r) { return os << "(" << r.il << ", " << r.jl << ", " << r.ir << ", " << r.jr << ")"; } }; } int main() { ios::sync_with_stdio(false); cin.tie(0); int n1, n2, n3, m; cin >> n1 >> n2 >> n3 >> m; bool ok = true; vector

e11, e22, e33, e12, e13, e23; rep(_, m) { int u, v; cin >> u >> v; if (u > v) swap(u, v); if (v <= n1) { e11.emplace_back(u, v); } else if (v <= n1 + n2) { if (u <= n1) e12.emplace_back(u, v - n1); else e22.emplace_back(u - n1, v - n1); } else if (v <= n1 + n2 + n3) { if (u <= n1) e13.emplace_back(u, v - (n1 + n2)); else if (u <= n1 + n2) e23.emplace_back(u - n1, v - (n1 + n2)); else e33.emplace_back(u - (n1 + n2), v - (n1 + n2)); } else if (v == n1 + n2 + n3 + 1) { if (u <= n1) e11.emplace_back(0, u); else if (u <= n1 + n2) e22.emplace_back(0, u - n1); else e33.emplace_back(0, u - (n1 + n2)); } else { if (u <= n1) e11.emplace_back(u, n1 + 1); else if (u <= n1 + n2) e22.emplace_back(u - n1, n2 + 1); else if (u <= n1 + n2 + n3) e33.emplace_back(u - (n1 + n2), n3 + 1); else ok = false; } } if (!ok) { cout << 0 << '\n'; return 0; } n1++, n2++, n3++; sort(all(e12)); vector st{{0, 0, -1, -1}}; for(auto [i, j]: e12) { if (i == st.back().il) { st.back().jl = j; } else if (j <= st.back().jl) { S r = st.back(); st.pop_back(); r.il = i; while(!st.empty() && st.back().jl >= j) st.pop_back(); if (!st.empty()) chmin(st.back().jr, j); st.emplace_back(r); } else { st.back().ir = i; st.back().jr = j; st.push_back(S{i, j, -1, -1}); } } st.back().ir = n1; st.back().jr = n2; constexpr int INF = 1001001001; rep(_, 2) { int bad_l = INF, bad_r = -INF; for(auto [l, r]: e11) chmin(bad_l, l), chmax(bad_r, r); vector nst; for(S r: st) { if (r.il < bad_l) { chmin(r.ir, bad_l); } else if (r.ir <= bad_r) { continue; } else { chmax(r.il, bad_r); } nst.emplace_back(r); } for(auto& [il, jl, ir, jr]: st) swap(il, jl), swap(ir, jr); swap(e11, e22); } int sz = st.size(); VL acc(sz + 1); rep(i, sz) { auto [il, jl, ir, jr] = st[i]; acc[i+1] = acc[i] + ll(ir - il) * (jr - jl); } multiset> imn{-INF}, jmn{-INF}; multiset imx{INF}, jmx{INF}; VVI ev1(n3 + 1), ev2(n3 + 1); for(auto [i, k]: e13) { imx.insert(i); ev1[k].emplace_back(i); } for(auto [j, k]: e23) { jmx.insert(j); ev2[k].emplace_back(j); } int bad_l = INF, bad_r = -INF; for(auto [l, r]: e33) chmin(bad_l, l), chmax(bad_r, r); auto get_area = [](const S& r1, const S& r2) { int il = max(r1.il, r2.il); int jl = max(r1.jl, r2.jl); int ir = min(r1.ir, r2.ir); int jr = min(r1.jr, r2.jr); if (il >= ir || jl >= jr) return 0LL; return ll(ir - il) * (jr - jl); }; ll ans = 0; rep(z, n3) { for(int i: ev1[z]) imx.erase(imx.find(i)), imn.insert(i); for(int j: ev2[z]) jmx.erase(jmx.find(j)), jmn.insert(j); if (bad_l <= z && z < bad_r) continue; S r{*imn.begin(), *jmn.begin(), *imx.begin(), *jmx.begin()}; int from = max(lower_bound(all(st), r, [](const S& x, const S& y) { return x.il < y.il; }) - st.begin(), lower_bound(all(st), r, [](const S& x, const S& y) { return x.jl < y.jl; }) - st.begin()); int to = min(upper_bound(all(st), r, [](const S& x, const S& y) { return x.ir < y.ir; }) - st.begin(), upper_bound(all(st), r, [](const S& x, const S& y) { return x.jr < y.jr; }) - st.begin()); if (from < to) ans += acc[to] - acc[from]; if (from) ans += get_area(st[from - 1], r); if (to < sz && to != from - 1) ans += get_area(st[to], r); } cout << ans << '\n'; }