#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; using Int = long long; template ostream &operator<<(ostream &os, const pair &a) { return os << "(" << a.first << ", " << a.second << ")"; }; template ostream &operator<<(ostream &os, const vector &as) { const int sz = as.size(); os << "["; for (int i = 0; i < sz; ++i) { if (i >= 256) { os << ", ..."; break; } if (i > 0) { os << ", "; } os << as[i]; } return os << "]"; } template void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; } template bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; } template bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; } int N[3], M; vector U, V; int main() { for (; ~scanf("%d%d%d%d", &N[0], &N[1], &N[2], &M); ) { for (int h = 0; h < 3; ++h) { ++N[h]; } U.resize(M); V.resize(M); for (int m = 0; m < M; ++m) { scanf("%d%d", &U[m], &V[m]); } const int src = (N[0] - 1) + (N[1] - 1) + (N[2] - 1) + 1; const int snk = src + 1; const int offs[3] = {0, (N[0] - 1), (N[0] - 1) + (N[1] - 1)}; auto decode = [&](int h, int u) -> int { if (u == src) return 0; if (u == snk) return N[h]; u -= offs[h]; if (0 < u && u < N[h]) return u; return -1; }; vector> pss[3][3]; for (int m = 0; m < M; ++m) { for (int h0 = 0; h0 < 3; ++h0) for (int h1 = h0; h1 < 3; ++h1) { { const int u = decode(h0, U[m]); const int v = decode(h1, V[m]); if (~u && ~v && (h0 < h1 || u < v)) { pss[h0][h1].emplace_back(u, v); } } { const int u = decode(h0, V[m]); const int v = decode(h1, U[m]); if (~u && ~v && (h0 < h1 || u < v)) { pss[h0][h1].emplace_back(u, v); } } } } // for(int h0=0;h0<3;++h0)for(int h1=h0;h1<3;++h1)cerr<<"pss["< fss[3], gss[3]; for (int h = 0; h < 3; ++h) { fss[h].assign(N[h] + 1, 0); for (const auto &p : pss[h][h]) { ++fss[h][p.first]; --fss[h][p.second]; } for (int x = 0; x < N[h]; ++x) { fss[h][x + 1] += fss[h][x]; } gss[h].assign(N[h] + 1, 0); for (int x = 0; x < N[h]; ++x) { gss[h][x + 1] = gss[h][x] + ((!fss[h][x]) ? 1 : 0); } // cerr<<"fss["< bool { for(int h0=0;h0<3;++h0)for(int h1=h0;h1<3;++h1){ for(const auto &p:pss[h0][h1]){ if((xs[h0]