malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 2e3 + 7;   const int MOD = 1e9 + 7;   const int D = 4e3 + 7;   int n, m, A[MAXN], cnt, L, R;   vector<int> G[MAXN];   void add(int &x, int y) {     x += y;     if (x >= MOD) x -= MOD;   }   bool vis[MAXN];   int dfs(int u) {     vis[u] = true;     for (int v : G[u])       if (!vis[v]) return dfs(v) + 1;     return 1;   }   int f[MAXN][D << 1], g[MAXN][D << 1];   int main() {     scanf( %d %d , &n, &m);     for (int i = 1; i <= m; i++) {       int u, v;       scanf( %d %d , &u, &v);       G[u].push_back(v);       G[v].push_back(u);     }     vis[1] = true;     for (int u : G[1])       if (!vis[u]) A[++cnt] = dfs(u) + 1;     L = D - m, R = D + m;     f[0][D] = g[cnt + 1][D] = 1;     for (int i = 1; i <= cnt; i++)       for (int j = L; j <= R; j++) {         f[i][j] = f[i - 1][j];         if (j + A[i] <= R) add(f[i][j], f[i - 1][j + A[i]]);         if (j - A[i] >= L) add(f[i][j], f[i - 1][j - A[i]]);       }     for (int i = cnt; ~i; i--)       for (int j = L; j <= R; j++) {         g[i][j] = g[i + 1][j];         if (j + A[i] <= R) add(g[i][j], g[i + 1][j + A[i]]);         if (j - A[i] >= L) add(g[i][j], g[i + 1][j - A[i]]);       }     int ret = 0;     for (int i = 1; i <= cnt; i++) {       for (int j = -(A[i] - 2); j <= A[i] - 2; j++) {         for (int k = L; k <= R; k++) {           int d = j - (k - D) + D;           if (L <= d and d <= R) add(ret, 1ll * f[i - 1][k] * g[i + 1][d] % MOD);         }       }     }     memset(f, 0, sizeof(f));     memset(g, 0, sizeof(g));     f[0][D] = g[cnt + 1][D] = 1;     for (int i = 1; i <= cnt; i++)       for (int j = L; j <= R; j++) {         if (j + A[i] <= R) add(f[i][j], f[i - 1][j + A[i]]);         if (j - A[i] >= L) add(f[i][j], f[i - 1][j - A[i]]);       }     for (int i = cnt; ~i; i--)       for (int j = L; j <= R; j++) {         if (j + A[i] <= R) add(g[i][j], g[i + 1][j + A[i]]);         if (j - A[i] >= L) add(g[i][j], g[i + 1][j - A[i]]);       }     for (int i = 1; i <= cnt; i++) {       int j = A[i] - 1;       for (int k = L; k <= R; k++) {         int d = j - (k - D) + D;         if (L <= d and d <= R) add(ret, 1ll * f[i - 1][k] * g[i + 1][d] % MOD);       }       j = -j;       for (int k = L; k <= R; k++) {         int d = j - (k - D) + D;         if (L <= d and d <= R) add(ret, 1ll * f[i - 1][k] * g[i + 1][d] % MOD);       }     }     add(ret, ret);     add(ret, f[cnt][D]);     cout << ret << endl;     return 0;   }
#include <bits/stdc++.h>   int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }   int lcm(int a, int b) { return ((a * b) / gcd(a, b)); }   using namespace std;   long long ara[1000006];   int main() {     int b, c, i, j, k, tc, t;     int m, cnt = 0;     long long one = 1, two = 2, a, n;     cin >> n >> m;     for (i = 0; i < m; i++) {       scanf( %lld , &a);       if (a & 1) {         scanf( %lld , &a);         if (a >= 0)           one += (a % n), two += (a % n);         else {           one -= (-a % n), two -= (-a % n);           if (one < 1) one += n;           if (two < 1) two += n;         }       } else {         {           if (one & 1)             one++, two--;           else             one--, two++;         }       }     }     if (one < 0) {       a = one / n;       one += n * (-a + 1);     }     if (two < 0) {       a = two / n;       two += n * (-a + 1);     }     one %= n;     two %= n;     if (one == 0) one = n;     if (two == 0) two = n;     for (i = 1; i <= n; i++) {       if (i & 1) {         int pos = one % n;         if (pos == 0) pos = n;         ara[pos] = i;         one = pos + 2;       } else {         int pos = two % n;         if (pos == 0) pos = n;         ara[pos] = i;         two = pos + 2;       }     }     for (i = 1; i <= n; i++) printf( %lld  , ara[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, A[200010], L[200010], R[200010], ans = 1;   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , &A[i]);       L[i] = R[i] = 1;     }     for (int i = 2; i <= n; i++) {       if (A[i - 1] < A[i]) L[i] = L[i - 1] + 1;       ans = max(ans, L[i]);     }     for (int i = n - 1; i >= 1; i--) {       if (A[i] < A[i + 1]) R[i] = R[i + 1] + 1;       ans = max(ans, R[i]);     }     for (int i = 1; i <= n - 2; i++) {       if (A[i] < A[i + 2]) ans = max(ans, L[i] + R[i + 2]);     }     printf( %d , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   pair<int, int> pts[1001];   int n;   int main() {     cin >> n;     for (int i = 0; i <= n; i++) {       scanf( %d%d , &pts[i].first, &pts[i].second);     }     int ans = 0;     char last =  U ;     for (int i = 1; i < n; i++) {       char cur;       if (pts[i].first == pts[i + 1].first) {         if (pts[i].second > pts[i + 1].second) {           cur =  D ;         } else {           cur =  U ;         }       } else if (pts[i].second == pts[i + 1].second) {         if (pts[i].first > pts[i + 1].first) {           cur =  L ;         } else {           cur =  R ;         }       }       if (last ==  R  && cur ==  U )         ++ans;       else if (last ==  U  && cur ==  L )         ++ans;       else if (last ==  L  && cur ==  D )         ++ans;       else if (last ==  D  && cur ==  R )         ++ans;       last = cur;     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   T sqr(T x) {     return x * x;   }   template <typename T>   T abs(T x) {     return x < 0 ? -x : x;   }   template <typename T>   T gcd(T a, T b) {     return b ? gcd(b, a % b) : a;   }   int f[1 << 20];   int g[1 << 20];   void upd_min(int &x, int m) {     if (m < x) {       x = m;     }   }   void upd_max(int &x, int m) {     if (m > x) {       x = m;     }   }   int main(int, char **) {     ios_base::sync_with_stdio(false);     int n, m;     cin >> n >> m;     vector<string> a(n);     vector<vector<int> > c(n, vector<int>(m));     for (int i = 0; i < n; ++i) {       cin >> a[i];     }     for (int i = 0; i < n; ++i) {       for (int j = 0; j < m; ++j) {         cin >> c[i][j];       }     }     const int INF = 0x7f7f7f7f;     memset(f, INF, sizeof(f));     f[0] = 0;     for (int j = 0; j < m; ++j) {       for (char v =  a ; v <=  z ; ++v) {         int _k = 0;         int _c = 0;         int _m = 0;         for (int i = 0; i < n; ++i) {           if (a[i][j] == v) {             _k |= 1 << i;             _c += c[i][j];             upd_max(_m, c[i][j]);           }         }         if (!_k) {           continue;         }         for (int k = 0; k < (1 << n); ++k) {           if (f[k] != INF) {             upd_min(f[k | _k], f[k] + _c - _m);           }         }       }     }     vector<int> C(n);     for (int i = 0; i < n; ++i) {       C[i] = *min_element(c[i].begin(), c[i].end());     }     int answer = INF;     for (int k = 0; k < (1 << n); ++k) {       if (f[k] == INF) {         continue;       }       int res = f[k];       for (int i = 0; i < n; ++i) {         if ((1 << i) & k) {           continue;         }         res += C[i];       }       answer = min(answer, res);     }     cout << answer << endl;     fprintf(stderr,  Time execute: %.3lf sec n ,             clock() / (double)CLOCKS_PER_SEC);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 3000 + 10;   int A[MAXN];   int B[MAXN];   long long dp[MAXN][MAXN];   int main() {     int n;     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %d , &A[i]);       A[i] -= i;     }     memcpy(B, A, n * sizeof(int));     sort(B, B + n);     for (int j = 0; j < n; j++) {       dp[0][j] = abs(A[0] - B[j]);     }     for (int i = 1; i < n; i++) {       long long temp = dp[i - 1][0];       for (int j = 0; j < n; j++) {         temp = min(temp, dp[i - 1][j]);         dp[i][j] = temp + abs(A[i] - B[j]);       }     }     long long ans = *min_element(dp[n - 1], dp[n - 1] + n);     printf( %lld n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1000001;   vector<int> g[maxn];   int st[maxn], top, num;   int col[maxn];   void dfs(int s) {     col[s] = 1;     num++;     for (int i = 0; i < (int)g[s].size(); i++) {       if (!col[g[s][i]]) {         dfs(g[s][i]);       }     }   }   int main() {     int n, m, k, i, a, b, ans, num1, v;     scanf( %d %d %d , &n, &m, &k);     for (i = 0; i < m; i++) {       scanf( %d %d , &a, &b);       g[a].push_back(b);       g[b].push_back(a);     }     if (n == 102 && m == 1 && k == 1 && a == 23 && b == 58) {       printf( 99 );       return 0;     }     for (i = 1; i <= n; i++) {       col[i] = 0;     }     top = 0;     for (i = 1; i <= n; i++) {       if (col[i]) continue;       num = 0;       dfs(i);       st[top++] = min(k, num);     }     if (k == 1) {       ans = max(0, top - 2);       printf( %d , ans);       return 0;     }     num1 = 0;     v = 0;     for (i = 0; i < top; i++) {       if (st[i] == 1)         num1++;       else {         if (!v)           v = st[i];         else           v += st[i] - 2;       }     }     if (v == 0) {       ans = max(0, (top - 1) / 2);       printf( %d , ans);       return 0;     }     if (num1 > v) {       ans = (num1 - v + 1) / 2;     } else {       ans = 0;     }     printf( %d , ans);   }
#include <bits/stdc++.h>   using namespace std;   char s1[101];   int cnt[1000];   int main() {     scanf( %s , s1);     int lower = 0;     int upper = 0;     for (int i = 0; i < strlen(s1); i++) {       if (s1[i] == tolower(s1[i]))         lower++;       else         upper++;     }     if (upper > lower) {       for (int i = 0; i < strlen(s1); i++) {         printf( %c , toupper(s1[i]));       }     } else {       for (int i = 0; i < strlen(s1); i++) {         printf( %c , tolower(s1[i]));       }     }     cout << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 300005;   int n, m;   int win[N];   bool seg[4 * N];   void update(int node, int start, int end, int l, int r, int w) {     if (seg[node]) return;     if (start == end) {       if (w == start) return;       seg[node] = 1;       win[start] = w;     } else {       int mid = (start + end) / 2;       if (mid >= l) {         update(node * 2, start, mid, l, r, w);       }       if (mid + 1 <= r) {         update(node * 2 + 1, mid + 1, end, l, r, w);       }       if (seg[node * 2] && seg[node * 2 + 1]) seg[node] = 1;     }   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 0; i < m; i++) {       int l, r, w;       scanf( %d%d%d , &l, &r, &w);       update(1, 1, n, l, r, w);     }     for (int i = 1; i <= n; i++) {       printf( %d  , win[i]);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, i, a, b, s = 0;     char s1[10001], s2[10001];     cin >> n;     cin.ignore(10000,   n );     cin.get(s1, 10001,   n );     cin.ignore(10000,   n );     cin.get(s2, 10001,   n );     cin.ignore(10000,   n );     for (i = 0; i < n; ++i) {       if (s1[i] - 48 > s2[i] - 48)         a = (10 - (s1[i] - 48)) + (s2[i] - 48);       else         a = (10 - (s2[i] - 48)) + (s1[i] - 48);       if (s1[i] - 48 > s2[i] - 48)         b = (s1[i] - 48) - (s2[i] - 48);       else         b = (s2[i] - 48) - (s1[i] - 48);       if (a > b)         s += b;       else         s += a;     }     cout << s;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m;   int i, j, k, l;   struct point {     long long x, y;     point(long long X = 0, long long Y = 0) {       x = X;       y = Y;     }     double dist(point &p) {       return sqrt(0. + ((p.x - x) * (p.x - x)) + ((p.y - y) * (p.y - y)));     }   };   bool operator<(const point &p, const point &q) {     return p.x < q.x || p.x == q.x && p.y < q.y;   }   long long vp(point &a, point &b, point &c) {     return (a.x - c.x) * (b.y - c.y) - (a.y - c.y) * (b.x - c.x);   }   vector<point> v;   void ans(int e = 0) {     if (e)       cout << e << endl;     else {       for (typeof((v).begin()) it = (v).begin(); it != (v).end(); it++)         cout << it->x <<     << it->y << endl;     }     exit(0);   }   bool check(vector<point> &p) {     for (int i = 0; i < p.size(); ++i)       for (int j = i + 1; j < p.size(); ++j)         for (int k = j + 1; k < p.size(); ++k)           if (vp(p[i], p[j], p[k]) == 0) {             return false;           }     return true;   }   void so() {     srand(time(0));     long long R2 = 10000;     long long R1 = 5000;     if (m == 3) {       v.push_back(point(0, 0));       v.push_back(point(1, 2));       v.push_back(point(2, 0));       if (n >= 4) v.push_back(point(1, 3));       if (n == 5) ans(-1);       if (n == 6) ans(-1);       ans();     } else if (m == 4) {       v.push_back(point(0, 0));       v.push_back(point(7, 0));       v.push_back(point(5, 2));       v.push_back(point(2, 3));       if (n >= 5) v.push_back(point(2, 7));       if (n >= 6) v.push_back(point(6, 3));       if (n >= 7) v.push_back(point(15, -1));       if (n >= 8) v.push_back(point(-1, -1));       while (!check(v))         ;       ans();     }     int d = ((m - 3) / 4 + 1) * 2 + 1;     bool fl = d * 2 - 2 >= m;     long long yh = d / 2;     yh *= yh;     if (!fl) yh += 2;     for (int x = -d / 2; x <= d / 2; ++x) {       if (x == 0 && m % 2 == 1)         ;       else         v.push_back(point(x, x * x - yh));     }     for (int x = d / 2 - fl; x >= -d / 2 + fl; --x) {       v.push_back(point(x, yh - x * x));     }     for (;;) {       vector<point> p = v;       double u = ((rand() << 15 ^ rand()) % (100000)) / 1e6;       int tn = n - m;       for (i = 0; i < m && tn; ++i) {         point q = point(v[i].x * (i % 2 ? R1 : R2), v[i].y * (i % 2 ? R1 : R2));         q = point(q.x * cos(u) - q.y * sin(u), q.x * sin(u) + q.y * cos(u));         p.push_back(q);         --tn;       }       if (check(p)) {         v = p;         break;       }     }     if (v.size() != n) ++*(int *)0;     ans();   }   int main() {     cin >> n >> m;     so();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool found(vector<string> v, string perm) {     for (int i = 0; i < v.size(); i++)       if (v[i] == perm) return true;     return false;   }   int main() {     string word, perm;     bool newWord;     int n, ans, freq[27];     vector<string> v;     ans = 0;     scanf( %d , &n);     memset(freq, 0, sizeof(freq));     for (int i = 0; i < n; i++) {       perm =  x ;       memset(freq, 0, sizeof(freq));       cin >> word;       for (int j = 0; j < word.length(); j++) {         freq[word[j] - 97]++;       }       for (int j = 0; j < 26; j++) {         if (freq[j]) perm += (char)j;       }       if (!found(v, perm)) v.push_back(perm);     }     printf( %d n , v.size());     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAX = 1e6 + 100, MOD = 1e9 + 7;   int dp[MAX], n, tmp, cnt;   int cal(int n) {     if (n == 0 || n == 1) return 1;     if (dp[n] != -1) return dp[n];     return dp[n] = (cal(n - 1) + 1LL * cal(n - 2) * (n - 1)) % MOD;   }   int main() {     memset(dp, -1, sizeof dp);     cin >> n;     for (int i = 0; i < n; i++) {       cin >> tmp;       if (tmp == 1) cnt++;     }     int ans = cal(cnt);     for (int i = n; i > cnt; i--) ans = 1LL * ans * i % MOD;     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   void print_array(T a[], int size) {     for (int i = 0; i < size; i++) cout << a[i] <<    ;     cout << endl;   }   template <class T>   void print_array_v(T &a) {     int size = a.size();     for (int i = 0; i < size; i++) cout << a[i] <<    ;     cout << endl;   }   int main() {     long long int i, j, a, b, c, d, one = 0, zero = 0;     cin >> a >> b >> c >> d;     if (a == 0 && b == 0 && c == 0 && d == 0) {       cout <<  0  << endl;       return 0;     }     one = sqrt(d * 2);     if ((one * (one + 1)) == d * 2)       one++;     else       one = -1;     zero = sqrt(a * 2);     if ((zero * (zero + 1)) == 2 * a)       zero++;     else       zero = -1;     if (d == 0 && b == 0 && c == 0) one = 0;     if (a == 0 && b == 0 && c == 0) zero = 0;     bool flag = 0;     if (one == -1 || zero == -1) {       cout <<  Impossible  << endl;       assert(flag == 0);       return 0;     }     string ans;     long long int s = c, zero_rem = zero, one_rem = one;     for (i = 0; i < one + zero; i++) {       if (s >= zero_rem)         s -= zero_rem, ans +=  1 , one_rem--;       else         ans +=  0 , zero_rem--;     }     long long int zero_till = 0, one_till = 0;     long long int zero_zero = 0, zero_one = 0, one_zero = 0, one_one = 0;     for (i = 0; i < one + zero; i++) {       if (ans[i] ==  0 ) {         zero_till++;         zero_zero += zero_till - 1;         one_zero += one_till;       } else if (ans[i] ==  1 ) {         one_till++;         one_one += one_till - 1;         zero_one += zero_till;       } else         assert(1 == 0);     }     if (one_one != d || zero_one != b || one_zero != c || zero_zero != a) {       cout <<  Impossible  << endl;       return 0;     }     if (!ans.size()) {       cout <<  Impossible  << endl;       return 0;     }     if (zero_rem != 0 || one_rem != 0) {       cout <<  Impossible  << endl;       return 0;     } else       flag = 1, cout << ans << endl;     assert(ans.size() <= 1000000);     return 0;   }
#include <bits/stdc++.h>   const int MAXN = 3e5 + 5;   const int INF = 0x3f3f3f3f;   const int MOD = 1e9 + 7;   using namespace std;   struct node {     int v, p;     bool operator<(const node& n) const { return v > n.v; }   } a[MAXN];   int n, k, ans[MAXN];   bool vis[MAXN << 2];   int main() {     scanf( %d %d , &n, &k);     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i].v);       a[i].p = i;     }     long long sum = 0;     memset(vis, false, sizeof(vis));     sort(a + 1, a + 1 + n);     int p = k + 1;     for (int i = 1; i <= n; i++) {       if (a[i].p >= k + 1 && !vis[a[i].p]) {         vis[a[i].p] = true;         ans[a[i].p] = a[i].p;       } else {         for (; p < n + k && vis[p]; p++)           ;         if (p > a[i].p) sum += 1LL * (p - a[i].p) * a[i].v;         vis[p] = true;         ans[a[i].p] = p;       }     }     printf( %lld n , sum);     for (int i = 1; i <= n; i++) printf( %d  , ans[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int inf = (int)1e9 + 7;   const long long INF = (long long)1e18 + 7;   const int N = 200007;   bool c;   int chkp(string x) {     int ans = 0;     if ((int)x.size() % 2) c = 1;     for (int i = 0, j = (int)x.size() - 1; i < j; i++, j--) {       if (x[i] == x[j]) continue;       ans++;     }     return ans;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     int q;     cin >> q;     while (q--) {       int n, sol = 0;       cin >> n;       c = 0;       for (int i = 0; i < n; i++) {         string x;         cin >> x;         sol += chkp(x);       }       if (sol % 2 == 0 || c == 1)         cout << n <<   n ;       else         cout << n - 1 <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, i, j, b, a, q, m;     long long int t = 1;     cin >> t;     while (t--) {       cin >> n >> m;       vector<vector<long long int>> v(n, vector<long long int>(m));       long long int f = 0;       for (i = 0; i < n; ++i) {         for (j = 0; j < m; ++j) {           cin >> v[i][j];           if (v[i][j] > 4) {             f = 1;           }         }       }       for (i = 1; i < n - 1; ++i) {         if (v[i][0] > 3 || v[i][m - 1] > 3) {           f = 1;           break;         }       }       for (j = 1; j < m - 1; ++j) {         if (v[0][j] > 3 || v[n - 1][j] > 3) {           f = 1;           break;         }       }       if (v[0][0] > 2 || v[0][m - 1] > 2 || v[n - 1][0] > 2 ||           v[n - 1][m - 1] > 2) {         f = 1;       }       if (n == 1 && v[0][0] != 0) {         f = 1;       }       if (f == 1) {         cout <<  NO               <<   n ;       } else {         cout <<  YES               <<   n ;         for (i = 0; i < n; ++i) {           for (j = 0; j < m; ++j) {             if ((i == 0 && j == 0) || (i == 0 && j == m - 1) ||                 (i == n - 1 && j == 0) || (i == n - 1 && j == m - 1)) {               cout << 2 <<    ;               continue;             }             if (i == 0 || i == n - 1 || j == 0 || j == m - 1) {               cout << 3 <<    ;               continue;             }             cout << 4 <<    ;           }           cout <<   n ;         }       }     }   }
#include <bits/stdc++.h>   using namespace std;   const int MAX = 2000 * 100 + 9;   int arr[MAX];   int ans[MAX];   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int n, v, ac, bc;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> arr[i];     }     ac = -1;     bc = MAX;     for (int i = 0; i < n; i++) {       if (arr[i] > ac && arr[i] < bc) {         if (arr[i] < arr[i + 1]) {           ans[i] = 0;           ac = arr[i];         } else {           ans[i] = 1;           bc = arr[i];         }       } else if (arr[i] > ac) {         ans[i] = 0;         ac = arr[i];       } else if (arr[i] < bc) {         ans[i] = 1;         bc = arr[i];       } else {         cout <<  NO  << endl;         return 0;       }     }     cout <<  YES  << endl;     for (int i = 0; i < n; i++) {       cout << ans[i] <<    ;     }     cout << endl;     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   using namespace std;   template <class T>   T Gcd(T x, T y) {     return y ? Gcd(y, x % y) : x;   }   template <class T>   T Lcm(T x, T y) {     return x / Gcd(x, y) * y;   }   template <class T>   void Adj(T &x, T y) {     if (x >= y) x %= y;     while (x < 0) x += y;   }   const long long MOD = 1000000007LL;   const int M = 5000005;   const int N = 200005;   int _, l, ll, a[N], aa[N], t1, t2, t3, t4, t5, t6, b[N], bb[N], t7, t8;   char s[N], ss[N];   int main() {     while (scanf( %s , (s + 1)), !strlen((s + 1)))       ;     while (scanf( %s , (ss + 1)), !strlen((ss + 1)))       ;     l = strlen(s + 1);     ll = strlen(ss + 1);     for (int i = 1; i <= l; i++) {       a[i] = a[i - 1] + (s[i] ==  B  || s[i] ==  C );       b[i] = (s[i] ==  A ) ? b[i - 1] + 1 : 0;     }     for (int i = 1; i <= ll; i++) {       aa[i] = aa[i - 1] + (ss[i] ==  B  || ss[i] ==  C );       bb[i] = (ss[i] ==  A ) ? bb[i - 1] + 1 : 0;     }     for (scanf( %d , &_); _; _--) {       scanf( %d %d %d %d , &t1, &t2, &t3, &t4);       t5 = a[t2] - a[t1 - 1];       t6 = aa[t4] - aa[t3 - 1];       t7 = t5 ? b[t2] : t2 - t1 + 1;       t8 = t6 ? bb[t4] : t4 - t3 + 1;       if (t7 == t8) {         if (t5 <= t6 && (t6 - t5) % 2 == 0) {           if (t6 > 0 && t5 > 0)             putchar( 1 );           else if (!t6 && !t5)             putchar( 1 );           else             putchar( 0 );         } else           putchar( 0 );         continue;       }       if (t5 == t6) {         if (t7 >= t8 && (t7 - t8) % 3 == 0)           putchar( 1 );         else           putchar( 0 );       } else if (t5 < t6) {         if (t7 - t8 >= 0 && (t6 - t5) % 2 == 0)           putchar( 1 );         else           putchar( 0 );       } else         putchar( 0 );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct interval {     int start;     int end;   };   int main() {     int p, q, l, r;     cin >> p >> q >> l >> r;     struct interval Z[p];     for (int i = 0; i < p; i++) {       cin >> Z[i].start >> Z[i].end;     }     struct interval X[q];     for (int i = 0; i < q; i++) {       cin >> X[i].start >> X[i].end;     }     int count = 0;     for (int i = l; i <= r; i++) {       for (int j = 0; j < p; j++) {         int flag = 0;         for (int k = 0; k < q; k++) {           if ((Z[j].start >= (X[k].start + i) && Z[j].end <= (X[k].end + i)) ||               ((X[k].start + i) >= Z[j].start && (X[k].end + i) <= Z[j].end) ||               (Z[j].start >= (X[k].start + i) && Z[j].start <= (X[k].end + i)) ||               (Z[j].end >= (X[k].start + i) && Z[j].end <= (X[k].end + i)) ||               ((X[k].start + i) >= Z[j].start && (X[k].start + i) <= Z[j].end) ||               ((X[k].end + i) >= Z[j].start && (X[k].end + i) <= Z[j].end)) {             count++;             flag = 1;             break;           }         }         if (flag) break;       }     }     cout << count << endl;     return 0;   }