malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 100;   pair<long long, long long> p[maxn];   long long m[maxn][2], mm[maxn][2], ycords[maxn], xcords[maxn];   int n;   bool can(long long l) {     for (int i = 0; i < n; i++) {       if (i > 0 && p[i - 1].second == p[i].second) continue;       long long newY = p[i].second + l;       int ind = upper_bound(ycords, ycords + n, newY) - ycords;       int ind1 = lower_bound(ycords, ycords + n, p[i].second) - ycords - 1;       long long left =           min(ind1 < 0 ? INT_MAX : mm[ind1][0], ind < n ? m[ind][0] : INT_MAX);       long long right =           max(ind1 < 0 ? -INT_MAX : mm[ind1][1], ind < n ? m[ind][1] : -INT_MAX);       if (right - left <= l || (left == INT_MAX && right == -INT_MAX)) {         return true;       }       newY = p[i].second - l;       ind = upper_bound(ycords, ycords + n, p[i].second) - ycords;       ind1 = lower_bound(ycords, ycords + n, newY) - ycords - 1;       left =           min(ind1 >= 0 ? mm[ind1][0] : INT_MAX, ind < n ? m[ind][0] : INT_MAX);       right =           max(ind1 >= 0 ? mm[ind1][1] : -INT_MAX, ind < n ? m[ind][1] : -INT_MAX);       if (right - left <= l || (left == INT_MAX && right == -INT_MAX)) {         return true;       }     }     return false;   }   int main() {     cin >> n;     for (long long i = 0; i < n; i++) {       cin >> p[i].first >> p[i].second;     }     pair<long long, long long> rot[n];     for (long long i = 0; i < n; i++) {       rot[i].first = p[i].first - p[i].second;       rot[i].second = p[i].second + p[i].first;       p[i] = rot[i];     }     sort(p, p + n,          [](pair<long long, long long> a, pair<long long, long long> b) {            swap(a.first, a.second);            swap(b.first, b.second);            return a < b;          });     for (int i = 0; i < n; i++) {       ycords[i] = p[i].second;     }     m[n - 1][0] = p[n - 1].first;     m[n - 1][1] = p[n - 1].first;     for (int i = n - 2; i >= 0; i--) {       m[i][0] = min(m[i + 1][0], p[i].first);       m[i][1] = max(m[i + 1][1], p[i].first);     }     mm[0][0] = p[0].first;     mm[0][1] = p[0].first;     for (int i = 1; i < n; i++) {       mm[i][0] = min(mm[i - 1][0], p[i].first);       mm[i][1] = max(mm[i - 1][1], p[i].first);     }     long long l = 0, r = 4 * (2e9 + 100);     while (l < r) {       long long mid = (l + r) / 2;       bool result = can(mid);       if (result) {         r = mid;       } else {         l = mid + 1;       }     }     cout << fixed << l / 2.f <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int a, m, p, k = 0;     cin >> a >> m;     p = a + m;     while (1) {       if ((k % 2) == 0) {         p = p - 2;         a--;         m--;         if (p == 1 || p == 0 || a == 0 || m == 0) {           cout <<  Akshat ;           break;         }       } else {         p = p - 2;         a--;         m--;         if (p == 1 || p == 0 || a == 0 || m == 0) {           cout <<  Malvika ;           break;         }       }       k++;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int f(string s1, string s2) {     int k = 0;     while (s2 != s1) {       s2 += s2[0];       s2 = s2.substr(1);       k++;       if (k > s2.length()) return 1000000;     }     return k;   }   int main() {     int n;     cin >> n;     vector<string> V(n);     for (int i = 0; i < n; i++) cin >> V[i];     int MIN = 1000000, ans;     for (int i = 0; i < n; i++) {       ans = 0;       for (int j = 0; j < n; j++)         if (j != i) ans += f(V[i], V[j]);       if (ans < MIN) MIN = ans;     }     if (MIN == 1000000)       cout << -1 << endl;     else       cout << MIN << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using pii = pair<int, int>;   using graph = vector<vector<int>>;   const ll mod = 1e9 + 7;   const int MAX = 2e5;   int n;   map<pii, ll> memo;   int size[MAX];   void dfs1(int v, int prev, const graph& G, const vector<ll>& V) {     pii p(prev, v);     ll res = 0;     int cnt = 1;     for (auto to : G[v])       if (to != prev) {         dfs1(to, v, G, V);         pii q(v, to);         cnt += size[to];         res = (res - memo[q] + mod) % mod;       }     res = (res + cnt * V[v] % mod) % mod;     size[v] = cnt;     memo[p] = res;   }   void dfs2(int v, int prev, const graph& G, const vector<ll>& V) {     ll val = memo[pii(-1, v)];     for (auto to : G[v])       if (to != prev) {         ll x = memo[pii(v, to)];         ll c = size[to];         ll tmp = memo[pii(to, v)] = (val + x - V[v] * c % mod + mod) % mod;         memo[pii(-1, to)] = (x - tmp + mod + V[to] * (n - c) % mod) % mod;         dfs2(to, v, G, V);       }   }   int main() {     ios::sync_with_stdio(false), cin.tie(0);     cin >> n;     vector<ll> V(n);     for (int i = 0; i < n; i++) {       cin >> V[i];       V[i] = (V[i] + mod) % mod;     }     graph G(n);     for (int i = 0; i < n - 1; i++) {       int a, b;       cin >> a >> b;       a--, b--;       G[a].push_back(b);       G[b].push_back(a);     }     dfs1(0, -1, G, V);     dfs2(0, -1, G, V);     ll res = 0;     for (int i = 0; i < n; i++) {       res = (res + memo[pii(-1, i)]) % mod;     }     cout << res << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     vector<int> a, b;     int n, m;     cin >> n;     for (int i = 0; i < n; i++) {       int tmp;       cin >> tmp;       a.push_back(tmp);     }     cin >> m;     for (int i = 0; i < m; i++) {       int tmp;       cin >> tmp;       b.push_back(tmp);     }     sort(a.begin(), a.end());     sort(b.begin(), b.end());     int a3 = 0, b3 = 0;     for (int i = a.size() - 1; i >= 0; i--) {       int l = 0, r = m;       while (l < r) {         int mid = (l + r) / 2;         if (b[mid] >= a[i]) {           r = mid;         } else           l = mid + 1;       }       if ((n - i) - (m - l) >= (a3 - b3)) {         a3 = n - i;         b3 = m - l;       }     }     cout << a3 * 3 + (n - a3) * 2 <<  :  << b3 * 3 + (m - b3) * 2 << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   inline T bigmod(T b, T p, T M) {     long long ret = 1;     for (; p > 0; p >>= 1) {       if (p & 1) ret = (ret * b) % M;       b = (b * b) % M;     }     return (T)ret;   }   template <class T>   inline T lcm(T a, T b) {     return (a * b) / __gcd(a, b);   }   int dx4[] = {-1, 0, 1, 0};   int dy4[] = {0, 1, 0, -1};   int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};   int dy8[] = {1, -1, -1, 0, 1, -1, 0, 1};   int kx8[] = {1, 1, 2, 2, -1, -1, -2, -2};   int ky8[] = {2, -2, 1, -1, 2, -2, 1, -1};   const double PI = acos(-1.0), EPS = 1e-7;   const long long INF = (long long)1e18 + 7;   const int N = 2e5 + 5, M = 1e9 + 7;   string s, t;   int ok[N];   char re[N];   void fun() {     ok[ A ]++;     re[ A ] =  A ;     ok[ b ]++;     re[ b ] =  d ;     ok[ d ]++;     re[ d ] =  b ;     ok[ H ]++;     re[ H ] =  H ;     ok[ I ]++;     re[ I ] =  I ;     ok[ M ]++;     re[ M ] =  M ;     ok[ O ]++;     re[ O ] =  O ;     ok[ o ]++;     re[ o ] =  o ;     ok[ p ]++;     re[ p ] =  q ;     ok[ q ]++;     re[ q ] =  p ;     ok[ T ]++;     re[ T ] =  T ;     ok[ U ]++;     re[ U ] =  U ;     ok[ V ]++;     re[ V ] =  V ;     ok[ v ]++;     re[ v ] =  v ;     ok[ W ]++;     re[ W ] =  W ;     ok[ w ]++;     re[ w ] =  w ;     ok[ X ]++;     re[ X ] =  X ;     ok[ x ]++;     re[ x ] =  x ;     ok[ Y ]++;     re[ Y ] =  Y ;   }   int main() {     fun();     cin >> s;     t = s;     reverse(s.begin(), s.end());     for (int i = 0; i < s.size(); i++) {       if (ok[s[i]] && re[s[i]] == t[i])         ;       else {         puts( NIE );         return 0;       }     }     puts( TAK );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, k, x, y;   int main() {     cin >> n >> k;     int l = 1, r = n, mid;     while (l <= r) {       if (l == r) {         x = l;         break;       }       mid = l + r >> 1;       cout <<  1   << mid <<     << mid + 1 << endl;       fflush(stdout);       string s;       cin >> s;       if (s ==  TAK )         r = mid;       else         l = mid + 1;     }     l = 1, r = x - 1;     while (l <= r) {       if (l == r) {         y = l;         break;       }       mid = l + r >> 1;       cout <<  1   << mid <<     << mid + 1 << endl;       fflush(stdout);       string s;       cin >> s;       if (s ==  TAK )         r = mid;       else         l = mid + 1;     }     if (y > 0) {       cout <<  1   << y <<     << x << endl;       fflush(stdout);       string s;       cin >> s;       if (s ==  TAK ) {         cout <<  2   << x <<     << y << endl;         fflush(stdout);         return 0;       }     }     l = x + 1, r = n;     while (l <= r) {       if (l == r) {         y = l;         break;       }       mid = l + r >> 1;       cout <<  1   << mid <<     << mid + 1 << endl;       fflush(stdout);       string s;       cin >> s;       if (s ==  TAK )         r = mid;       else         l = mid + 1;     }     cout <<  2   << x <<     << y << endl;     fflush(stdout);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int r;   bool check(int x, int y) { return 1ll * x * x + 3ll * y * y <= 4ll * r * r; }   int main(void) {     scanf( %d , &r);     int i = 1, j = 1;     long long ans = 1;     while (check(i, j + 2)) {       ans += 2;       j += 2;     }     do {       i += 3;       ++j;       while ((j > 0) && ((!check(i, j)) || (!check(i + 1, j - 1)))) j -= 2;       if (j > 0) ans += j * 2;     } while (j > 0);     printf( %I64d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 110000;   const int B = 60;   int n, q, mc;   int aint[4 * N][B];   void update(int nod, int pozx, int pozy, int poz, int val) {     int i;     if (pozx == pozy) {       for (i = 0; i < B; ++i) {         aint[nod][i] = 1;         if (i % val == 0) aint[nod][i]++;       }       return;     }     int mid = (pozx + pozy) / 2;     if (mid >= poz)       update(2 * nod, pozx, mid, poz, val);     else       update(2 * nod + 1, mid + 1, pozy, poz, val);     for (i = 0; i < B; ++i)       aint[nod][i] =           aint[2 * nod][i] + aint[2 * nod + 1][(i + aint[2 * nod][i]) % B];   }   int query(int nod, int pozx, int pozy, int poz1, int poz2) {     if (poz1 <= pozx && pozy <= poz2) {       int rez = aint[nod][mc];       mc = (mc + aint[nod][mc]) % B;       return rez;     }     int mid = (pozx + pozy) / 2, rez = 0;     if (mid >= poz1) rez = query(2 * nod, pozx, mid, poz1, poz2);     if (mid < poz2) rez += query(2 * nod + 1, mid + 1, pozy, poz1, poz2);     return rez;   }   int main() {     int i;     cin >> n;     for (i = 1; i <= n; ++i) {       int x;       cin >> x;       update(1, 1, n, i, x);     }     cin >> q;     for (i = 1; i <= q; ++i) {       char a;       int p1, p2;       cin >> a >> p1 >> p2;       if (a ==  A ) {         mc = 0;         cout << query(1, 1, n, p1, p2 - 1) <<   n ;       } else         update(1, 1, n, p1, p2);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int64_t a[4][4] = {0};   int64_t b[4][4] = {0};   int64_t chk(int64_t aa, int64_t bb) {     if (aa == bb) return 0;     if (aa == 3 && bb == 2) return 1;     if (aa == 2 && bb == 1) return 1;     if (aa == 1 && bb == 3) return 1;     return 2;   }   int64_t ma[4][4] = {0};   signed main() {     int64_t k, A, B;     cin >> k >> A >> B;     for (int64_t i = 1; i <= 3; ++i) {       for (int64_t j = 1; j <= 3; ++j) cin >> a[i][j];     }     for (int64_t i = 1; i <= 3; ++i) {       for (int64_t j = 1; j <= 3; ++j) cin >> b[i][j];     }     if (k <= 100 * 1000) {       int64_t curr1 = A;       int64_t curr2 = B;       int64_t la = 0, lb = 0;       int64_t score1 = 0;       int64_t score2 = 0;       int64_t len = 0;       int64_t hey_a = -1, hey_b = -1;       for (int64_t t = 1; t <= k; ++t) {         if (chk(curr1, curr2) == 1)           score1++;         else if (chk(curr1, curr2) == 2)           score2++;         int64_t _c1 = curr1, _c2 = curr2;         curr1 = a[_c1][_c2];         curr2 = b[_c1][_c2];       }       cout << score1 <<     << score2 <<   n ;       return 0;     }     int64_t curr1 = A;     int64_t curr2 = B;     int64_t la = 0, lb = 0;     int64_t score1 = 0;     int64_t score2 = 0;     int64_t len = 0;     int64_t hey_a = -1, hey_b = -1;     for (int64_t t = 1; t <= k; ++t) {       if (ma[curr1][curr2] > 0) {         hey_a = curr1, hey_b = curr2;         len = t - ma[curr1][curr2];         break;       }       ma[curr1][curr2] = t;       int64_t _c1 = curr1, _c2 = curr2;       curr1 = a[_c1][_c2];       curr2 = b[_c1][_c2];     }     int64_t tstart = -1;     int64_t cnt1 = 0;     curr1 = A, curr2 = B;     for (int64_t t = 1; t <= k; ++t) {       if (curr1 == hey_a && curr2 == hey_b) {         tstart = t;         break;       }       cnt1++;       if (chk(curr1, curr2) == 1)         la++;       else if (chk(curr1, curr2) == 2)         lb++;       int64_t _c1 = curr1, _c2 = curr2;       curr1 = a[_c1][_c2];       curr2 = b[_c1][_c2];     }     for (int64_t t = tstart; t <= k; ++t) {       if (chk(curr1, curr2) == 1)         score1++;       else if (chk(curr1, curr2) == 2)         score2++;       int64_t _c1 = curr1, _c2 = curr2;       curr1 = a[_c1][_c2];       curr2 = b[_c1][_c2];       if (curr1 == hey_a && curr2 == hey_b) {         break;       }     }     if (len > 0 && (k - cnt1) / len > 0) {       score1 = ((k - cnt1) / len) * score1;       score2 = ((k - cnt1) / len) * score2;     }     score1 += la;     score2 += lb;     int64_t rem = 0;     if (len > 0) rem = (k - cnt1) % len;     if (rem > 0) {       curr1 = hey_a;       curr2 = hey_b;       while (rem--) {         if (chk(curr1, curr2) == 1)           score1++;         else if (chk(curr1, curr2) == 2)           score2++;         int64_t _c1 = curr1, _c2 = curr2;         curr1 = a[_c1][_c2];         curr2 = b[_c1][_c2];       }     }     cout << score1 <<     << score2 <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int pow_mod(int a, long long k, int mod) {     if (k == 0) {       return 1;     }     int sub = pow_mod(a, k / 2, mod);     if (k % 2 == 0) {       return ((long long)sub * sub) % mod;     } else {       return (((long long)sub * sub) % mod * a) % mod;     }   }   int main() {     int h, i, j, l;     int t, n, m, k, q;     int r, c;     scanf( %d %d %d %d %d , &n, &m, &k, &r, &c);     int ax, ay, bx, by;     scanf( %d %d %d %d , &ax, &ay, &bx, &by);     long long count;     long long mod = 1e9 + 7;     if (ax == bx && ay == by) {       count = (long long)n * m;     } else {       count = (long long)n * m - (long long)r * c;     }     printf( %d n , pow_mod(k, count, mod));   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5;   const int mod = 1e9 + 7;   long long a[N], n, mx, cnt;   vector<int> v, e;   long long ans = 1;   long long pw(long long a, long long b) {     if (b == 0) return 1;     long long res = pw(a, b / 2);     res = res * res % mod;     if (b % 2) res = res * a % mod;     return res;   }   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) scanf( %d , &a[i]), mx = max(mx, a[i]);     sort(a, a + n);     for (int i = 2; i <= mx; i++) {       v.clear();       e.clear();       for (int j = 1; j * j <= i; j++) {         if (i % j == 0) {           v.push_back(j);           if (j * j != i) e.push_back(i / j);         }       }       for (int j = (int)e.size() - 1; j >= 0; j--) v.push_back(e[j]);       int now = 0;       long long sum = 1, sum2 = 1;       for (int j = 1; j < (int)v.size(); j++) {         int to = lower_bound(a + now, a + n, v[j]) - a;         sum = sum * pw(j, to - now) % mod;         now = to;       }       sum = sum * pw((int)v.size(), n - now) % mod;       now = 0;       for (int j = 1; j < v.size() - 1; j++) {         int to = lower_bound(a + now, a + n, v[j]) - a;         sum2 = sum2 * pw(j, to - now) % mod;         now = to;       }       sum2 = sum2 * pw((int)v.size() - 1, n - now) % mod;       ans = (ans + sum) % mod;       ans = (ans + mod - sum2) % mod;     }     ans = (ans + mod) % mod;     printf( %lld n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   map<int, int> s;   int a[2000];   int main(int argc, char const *argv[]) {     int n;     cin >> n;     for (int i = 0; i < n; ++i) cin >> a[i];     for (int i = 0; i < n; ++i) {       for (int j = i + 1; j < n; ++j) {         int sum = a[i] + a[j];         if (s.find(sum) == s.end())           s[sum] = 1;         else           s[sum]++;       }     }     int ans = 0;     for (auto i : s) {       ans = max(ans, i.second);     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void solve(const vector<int>& pearl) {     vector<pair<int, int>> ans;     ans.reserve(pearl.size());     set<int> app;     int l = 0;     for (int i = 0; i < pearl.size(); i++) {       int cur = pearl[i];       if (app.find(cur) != end(app)) {         ans.push_back(make_pair(l + 1, i + 1));         l = i + 1;         set<int>().swap(app);       } else         app.insert(cur);     }     if (l != pearl.size()) {       if (l == 0) {         printf( -1 n );         return;       }       ans[ans.size() - 1].second = pearl.size();     }     printf( %d n , ans.size());     for (const auto& a : ans) printf( %d %d n , a.first, a.second);   }   int main() {     int n;     scanf( %d , &n);     vector<int> pearl(n);     for (int i = 0; i < n; i++) scanf( %d , &pearl[i]);     solve(pearl);   }
#include <bits/stdc++.h>   const int MAXN = 5E5 + 10;   int n;   int a[MAXN << 1];   int main() {     scanf( %d , &n);     for (int i = 1; i < n; ++i) {       int t = i + 1 >> 1;       if (i & 1)         a[t] = a[n - t + 1] = i;       else         a[n + t] = a[n * 2 - t] = i;     }     a[2 * n] = n;     if (n & 1)       a[n + 1 >> 1] = n;     else       a[n + (n >> 1)] = n;     for (int i = 2 * n; i > 0; --i) printf( %d%c , a[i],   n  [i > 1]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   double const pi = 3.1415926535897932384626433832795;   int const inf = (int)1e9;   long long const inf64 = (long long)2e18;   const string name =  d ;   vector<pair<int, int> > ans;   int n, d[21];   void rec(int n, int x, int y, int z, bool rev) {     if (n == 0) return;     int now = n - 1;     while (now >= 0 && d[now] == d[n - 1]) now--;     if (now == -1) {       if (rev)         for (int i = 0; i < (int)n; i++) ans.push_back(make_pair(x, y));       else {         for (int i = 0; i < (int)n - 1; i++) ans.push_back(make_pair(x, z));         ans.push_back(make_pair(x, y));         for (int i = 0; i < (int)n - 1; i++) ans.push_back(make_pair(z, y));       }       return;     }     if (now + 1 == n - 1) {       rec(now + 1, x, z, y, 1);       ans.push_back(make_pair(x, y));       rec(now + 1, z, y, x, 1);     } else {       if (!rev) {         rec(now + 1, x, y, z, 1);         for (int it = 0; it < (int)n - now - 1; it++)           ans.push_back(make_pair(x, z));         rec(now + 1, y, x, z, 1);         for (int it = 0; it < (int)n - now - 1; it++)           ans.push_back(make_pair(z, y));         rec(now + 1, x, y, z, 0);       } else {         rec(now + 1, x, z, y, 1);         for (int it = 0; it < (int)n - now - 1; it++)           ans.push_back(make_pair(x, y));         rec(now + 1, z, y, x, 1);       }     }   }   int main() {     cin >> n;     for (int i = 0; i < (int)n; i++) cin >> d[i];     reverse(d, d + n);     rec(n, 0, 2, 1, 0);     cout << ans.size() << endl;     for (int i = 0; i < (int)ans.size(); i++)       printf( %d %d n , ans[i].first + 1, ans[i].second + 1);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, r;   int main() {     cin >> n >> r;     int ans = 0, Max = -1, mark = false;     for (int i = 1; i <= r; i++) {       int t = i, b = r, num = 0, cnt = 0;       while (t > 0 && b > 0) {         bool flag = false;         if (b > t) {           int c = b / t - 1;           num += c;           b -= t * c;           if (b > t) {             b -= t;             num++;           }           flag = true;         } else {           if (t > b) {             int c = t / b - 1;             num += c;             t -= b * c;             if (t > b) {               t -= b;               num++;             }           }         }         cnt++;         if (t == b) {           num++;           t -= b;           cnt++;           if (b == r) cnt--;           if (cnt > Max && (max(b, t) == 1 && min(b, t) == 0) && num == n) {             if (!flag)               mark = true;             else               mark = false;             Max = cnt;             ans = i;           }         }       }     }     if (Max == -1) {       cout <<  IMPOSSIBLE  << endl;       return 0;     }     string s;     int t = ans, b = r;     if (mark) swap(b, t);     while (t > 0 && b > 0) {       if (t >= b) {         t -= b;         s +=  T ;       } else {         b -= t;         s +=  B ;       }     }     reverse(s.begin(), s.end());     cout << n - Max << endl << s << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 2e6;   vector<int> g[MAXN], g1[MAXN];   int n, p, mp, m, all_n;   void add(int t1, int t2) {     g[t1 ^ 1].push_back(t2);     g1[t2].push_back(t1 ^ 1);     g[t2 ^ 1].push_back(t1);     g1[t1].push_back(t2 ^ 1);   }   vector<int> order;   bool vis[MAXN];   int comp[MAXN];   vector<int> res;   void dfs1(int u) {     vis[u] = 1;     for (auto v : g[u]) {       if (vis[v] == 1) continue;       dfs1(v);     }     order.push_back(u);   }   void dfs2(int u, int c) {     comp[u] = c;     for (auto v : g1[u]) {       if (comp[v] == 0) dfs2(v, c);     }   }   bool solveSAT() {     for (int i = 0; i <= all_n * 2 - 3; i++) {       if (vis[i] == 0) dfs1(i);     }     reverse(order.begin(), order.end());     int cnt = 1;     for (auto u : order) {       if (comp[u] == 0) dfs2(u, cnt++);     }     for (int i = 0; i < all_n - 1; i++) {       if (comp[2 * i] == comp[2 * i + 1]) {         return 0;       }       if (comp[2 * i] > comp[2 * i + 1]) {         res.push_back(i);       }     }     return 1;   }   int main() {     cin >> n >> p >> mp >> m;     for (int i = 0; i < n; i++) {       int x, y;       cin >> x >> y;       x--;       y--;       add(x * 2, y * 2);     }     all_n = mp + p;     for (int i = 0; i < p; i++) {       int l, r;       cin >> l >> r;       if (l != 1) {         add((l + p - 2) * 2, i * 2 + 1);       }       if (r != mp) {         add((r + p - 1) * 2 + 1, i * 2 + 1);       }     }     for (int i = 0; i < m; i++) {       int x, y;       cin >> x >> y;       x--;       y--;       add(x * 2 + 1, y * 2 + 1);     }     for (int i = 2; i < mp; i++) {       add((i + p - 2) * 2, (i + p - 1) * 2 + 1);     }     if (!solveSAT()) {       cout <<  -1 n ;       return 0;     }     vector<int> st;     int k = 1;     for (auto t : res) {       if (t < p) {         st.push_back(t);       } else {         k = max(k, t - p + 2);       }     }     cout << st.size() <<     << k << endl;     for (int i = 0; i < st.size(); i++) cout << st[i] + 1 <<    ;     cout << endl;     return 0;   }