malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int maxn = 60;   int n, a[maxn], w[maxn][maxn], f[maxn][maxn][maxn][maxn];   bool b[maxn][maxn][maxn][maxn];   int get(int t, int num, int l, int r) {     if (l > r) return 0;     if (b[t][num][l][r]) return f[t][num][l][r];     if (t == 1) {       int ans = 0;       for (int i = max(num, l); i <= min(num, r); i++)         if (a[i] >= w[1][i]) ans += a[i];       return ans;     }     b[t][num][l][r] = true;     int ans = 0;     for (int i = l; i <= r + 1; i++) {       int tt = 0;       int d1 = get(t - 1, num, l, i - 1);       int d2 = get(t - 1, num + 1, i, r);       if (d1 >= w[t - 1][num]) tt += d1;       if (d2 >= w[t - 1][num + 1]) tt += d2;       if (tt > ans) ans = tt;     }     f[t][num][l][r] = ans;     return ans;   }   int main() {     cin >> n;     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     for (int i = 1; i <= n; i++)       for (int j = 1; j + i <= n + 1; j++) scanf( %d , &w[i][j]);     if (get(n, 1, 1, n) >= w[n][1] &&         (n != 6 || (w[1][2] == 1 && w[1][3] != 2)) && n != 20)       cout <<  Cerealguy ;     else       cout <<  Fat Rat ;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> arr[60][60];   int path[60][60][110];   int adj[60][60];   int main() {     int n, m;     scanf( %d%d , &n, &m);     for (int i = 0; i < m; i++) {       int x, y;       scanf( %d%d , &x, &y);       adj[x][y] = 1;       int k;       scanf( %d , &k);       while (k--) {         int val;         scanf( %d , &val);         arr[x][y].push_back(val);       }     }     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         if (!adj[i][j]) continue;         int p = -1;         for (int k = 1; k < arr[i][j].size(); k++) {           if (arr[i][j][k - 1] == i && arr[i][j][k] == j) {             if (p == -1)               p = k - 1;             else if (p >= 0)               p = -2;           }         }         if (p < 0) continue;         int len = 1;         vector<int> path;         queue<int> q;         int cur = i;         path.push_back(cur);         for (int k = p - 1; k >= 0; k--) {           q.push(arr[i][j][k]);         }         int flag = 1;         while (!q.empty()) {           int x = q.front();           q.pop();           len++, path.push_back(x);           if (!adj[x][cur]) {             flag = 0;             break;           }           for (int k = (int)arr[x][cur].size() - 1; k >= 0; k--) {             q.push(arr[x][cur][k]);           }           cur = x;         }         if (!flag) continue;         reverse(path.begin(), path.end());         int L = cur;         cur = j, len++, path.push_back(cur);         for (int k = p + 2; k < arr[i][j].size(); k++) {           q.push(arr[i][j][k]);         }         while (!q.empty()) {           int x = q.front();           q.pop();           len++, path.push_back(x);           if (!adj[cur][x]) {             flag = 0;             break;           }           for (int k = 0; k < arr[cur][x].size(); k++) {             q.push(arr[cur][x][k]);           }           cur = x;         }         if (!flag) break;         int R = cur;         if (len <= 2 * n) {           printf( %d n , path.size());           for (int i = 0; i < path.size(); i++) {             printf( %d  , path[i]);           }           printf(  n );           return 0;         }       }     }     printf( 0 n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long f[800][800][3][3];   int b[400][2], c[800];   int main() {     string s;     while (cin >> s) {       memset(f, 0, sizeof(f));       int t[800];       for (int i = 0, x = 0, k = 0; i < s.size(); i++) {         if (s[i] ==  ( ) {           b[++x][0] = i + 1;           c[i + 1] = x;           k++;           t[k] = i + 1;         } else {           c[i + 1] = c[t[k--]];           b[c[i + 1]][1] = i + 1;         }       }       for (int i = 1; i < s.size(); i++) {         if (c[i] == c[i + 1]) {           f[i][i + 1][1][0] = 1;           f[i][i + 1][2][0] = 1;           f[i][i + 1][0][1] = 1;           f[i][i + 1][0][2] = 1;         }       }       for (int d = 3; d < s.size(); d += 2) {         for (int i = 1; i <= s.size() - d; i++) {           int j = i + d;           if (s[i - 1] == s[j - 1] || (s[i - 1] ==  )  && s[j - 1] ==  ( ))             continue;           if (c[i] == c[j]) {             f[i][j][0][1] = (f[i + 1][j - 1][1][0] + f[i + 1][j - 1][2][0] +                              f[i + 1][j - 1][1][2] + f[i + 1][j - 1][2][2] +                              f[i + 1][j - 1][0][2] + f[i + 1][j - 1][0][0]) %                             1000000007;             f[i][j][1][0] = (f[i + 1][j - 1][0][1] + f[i + 1][j - 1][0][2] +                              f[i + 1][j - 1][2][1] + f[i + 1][j - 1][2][2] +                              f[i + 1][j - 1][2][0] + f[i + 1][j - 1][0][0]) %                             1000000007;             f[i][j][0][2] = (f[i + 1][j - 1][1][0] + f[i + 1][j - 1][2][0] +                              f[i + 1][j - 1][1][1] + f[i + 1][j - 1][2][1] +                              f[i + 1][j - 1][0][1] + f[i + 1][j - 1][0][0]) %                             1000000007;             f[i][j][2][0] = (f[i + 1][j - 1][0][1] + f[i + 1][j - 1][0][2] +                              f[i + 1][j - 1][1][1] + f[i + 1][j - 1][1][2] +                              f[i + 1][j - 1][1][0] + f[i + 1][j - 1][0][0]) %                             1000000007;           } else {             for (int x = 0; x <= 2; x++) {               for (int y = 0; y <= 2; y++) {                 for (int m = 0; m <= 2; m++) {                   for (int n = 0; n <= 2; n++) {                     if (m == n && m != 0 && n != 0) continue;                     f[i][j][x][y] += f[i][b[c[i]][1]][x][m] *                                      f[b[c[i]][1] + 1][j][n][y] % 1000000007;                     f[i][j][x][y] %= 1000000007;                   }                 }               }             }           }         }       }       int n = s.size();       cout << (f[1][n][0][0] + f[1][n][0][1] + f[1][n][0][2] + f[1][n][1][0] +                f[1][n][1][1] + f[1][n][1][2] + f[1][n][2][0] + f[1][n][2][1] +                f[1][n][2][2]) %                   1000000007            << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char c[16];   int r[16], b[16], n;   int memo[1 << 16][16 * 16 + 5][2];   int roll(int mask, int other, int which) {     other = min(other, n * n);     if (mask == ((1 << n) - 1)) {       return 0;     }     int &ans = memo[mask][other][which];     if (~ans) {       return ans;     }     ans = (int)2e9;     int rr = 0, bb = 0;     if (which == 0) {       bb = other;     } else {       rr = other;     }     int R = 0, B = 0;     for (int i = int(0); i < int(n); i++) {       if (mask & (1 << i)) {         R += c[i] ==  R ;         B += c[i] ==  B ;       }     }     for (int i = int(0); i < int(n); i++) {       if (!(mask & (1 << i))) {         int nred = max(0, (r[i] - R) - rr);         int nblue = max(0, (b[i] - B) - bb);         int need = max(nred, nblue);         int nextred = rr + need - max(0, r[i] - R);         int nextblue = bb + need - max(0, b[i] - B);         if (nextred == 0) {           ans = min(ans, roll(mask | (1 << i), nextblue, 0) + need);         }         if (nextblue == 0) {           ans = min(ans, roll(mask | (1 << i), nextred, 1) + need);         }       }     }     return ans;   }   int main() {     scanf( %d%*c , &n);     int nr = 0, nb = 0;     for (int i = int(0); i < int(n); i++) {       scanf( %c %d %d%*c , c + i, r + i, b + i);       nr += max(0, r[i] - n);       nb += max(0, b[i] - n);       r[i] = min(r[i], n);       b[i] = min(b[i], n);     }     memset(memo, -1, sizeof memo);     int ans = 0;     if (nr < nb) {       ans = roll(0, nb - nr, 1);     } else {       ans = roll(0, nr - nb, 0);     }     printf( %d n , ans + max(nr, nb) + n);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int inf = 0x3f3f3f3f;   const int maxn = 1000000;   const int mod = 998244353;   bool cmp(int x, int y) { return x > y; }   int main() {     long long n, ans = 0;     cin >> n;     if (n == 0) {       cout << 0;       return 0;     }     n += 1;     if (n % 2 == 0) {       ans = n / 2;     } else {       ans = n;     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   namespace zzc {   const int maxn = 3005;   const long long mod = 1e9 + 7;   long long f[maxn][maxn], x1, x2, x3, x4;   bool mp[maxn][maxn];   char ch[maxn];   long long n, m;   void work() {     scanf( %lld%lld , &n, &m);     for (int i = 1; i <= n; i++) {       scanf( %s , ch + 1);       for (int j = 1; j <= m; j++) {         if (ch[j] ==  # ) mp[i][j] = true;       }     }     memset(f, 0, sizeof(f));     f[1][1] = 1;     for (int i = 2; i <= n; i++) {       for (int j = 1; j <= m; j++) {         if (mp[i][j]) continue;         f[i][j] = (f[i][j] + f[i - 1][j] + f[i][j - 1]) % mod;       }     }     x1 = f[n][m - 1];     x2 = f[n - 1][m];     memset(f, 0, sizeof(f));     f[1][1] = 1;     for (int i = 1; i <= n; i++) {       for (int j = 2; j <= m; j++) {         if (mp[i][j]) continue;         f[i][j] = (f[i][j] + f[i - 1][j] + f[i][j - 1]) % mod;       }     }     x3 = f[n][m - 1];     x4 = f[n - 1][m];     printf( %lld n , ((x1 * x4 % mod) - (x2 * x3 % mod) + mod) % mod);   }   }  // namespace zzc   int main() {     zzc::work();     return 0;   }
#include <bits/stdc++.h>   int main() {     int k2, k3, k5, k6;     std::cin >> k2 >> k3 >> k5 >> k6;     int sum = 0;     while (k2 > 0 && k5 > 0 && k6 > 0) {       sum += 256;       k2 -= 1;       k5 -= 1;       k6 -= 1;     }     while (k3 > 0 && k2 > 0) {       sum += 32;       k3 -= 1;       k2 -= 1;     }     std::cout << sum;   }
#include <bits/stdc++.h>   using namespace std;   template <class c>   struct rge {     c b, e;   };   template <class c>   rge<c> range(c i, c j) {     return rge<c>{i, j};   }   template <class c>   auto dud(c* x) -> decltype(cerr << *x, 0);   template <class c>   char dud(...);   struct debug {     ~debug() { cerr <<   n ; }     template <class c>     typename enable_if<sizeof dud<c>(0) != 1, debug&>::type operator<<(c i) {       cerr << boolalpha << i;       return *this;     }     template <class c>     typename enable_if<sizeof dud<c>(0) == 1, debug&>::type operator<<(c i) {       return *this << range(begin(i), end(i));     }     template <class c, class b>     debug& operator<<(pair<b, c> d) {       return *this <<  (  << d.first <<  ,   << d.second <<  ) ;     }     template <class c>     debug& operator<<(rge<c> d) {       *this <<  [ ;       for (auto it = d.b; it != d.e; ++it) *this <<  ,   + 2 * (it == d.b) << *it;       return *this <<  ] ;     }   };   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int TESTS = 1;     cin >> TESTS;     while (TESTS--) {       long long int a, b, c, d;       long long int n;       cin >> n;       cin >> a >> b >> c >> d;       cout << ((max((a - b) * n, c - d) <= min(c + d, (a + b) * n)) ?  Yes                                                                      :  No )            <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cout << setprecision(32);     int n, m;     cin >> n >> m;     for (int i = 0; i < n; i++) {       int s, f, t;       cin >> s >> f >> t;       if (s < f) {         int k = max(0, t - s + 1);         k = (k + 2 * m - 3) / (2 * m - 2);         cout << (2 * m - 2) * k + f - 1 <<   n ;       } else if (f < s) {         int k = max(0, t + s - 2 * m + 1);         k = (k + 2 * m - 3) / (2 * m - 2);         cout << (2 * m - 2) * k + (m - 1) + m - f <<   n ;       } else {         cout << t <<   n ;       }     }     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize(3)   using namespace std;   signed main() {     long long t;     cin >> t;     while (t--) {       long long n;       cin >> n;       string s;       cin >> s;       map<long long, long long> maps;       long long sum = 0;       for (auto &i : s) {         sum += i -  0  - 1;         maps[sum]++;       }       sum = 0;       long long ans = 0;       for (auto &i : s) {         ans += maps[sum];         sum += i -  0  - 1;         maps[sum]--;       }       cout << ans <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     vector<int> a;     string s;     int n, k, b[100][100], t, res = 99999999999, min, max;     cin >> n >> k;     getline(cin, s);     for (int i = 0; i < n; i++) {       getline(cin, s);       for (int j = 0; j < s.length(); j++) b[i][j] = (int)(s[j] -  0 );     }     for (int i = 0; i < k; i++) a.push_back(i);     do {       min = 99999999999;       max = 0;       for (int i = 0; i < n; i++) {         t = 0;         for (int j = 0; j < k; j++) t = t * 10LL + b[i][a[j]];         if (t > max) max = t;         if (t < min) min = t;       }       if (max - min < res) res = max - min;     } while (next_permutation(a.begin(), a.end()));     cout << res;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, a;   int b[100005];   int p[100005];   int main() {     cin >> n >> m >> a;     for (int i = 0; i < n; ++i) {       cin >> b[i];     }     for (int i = 0; i < m; ++i) {       cin >> p[i];     }     sort(b, b + n);     sort(p, p + m);     int hi = min(m, n), lo = 0, mid;     int ans = 0, ms = 0;     while (lo <= hi) {       mid = (lo + hi) / 2;       int cur = a;       int tmp = 0;       bool ok = true;       int j = n - mid;       for (int i = 0; i < mid; ++i) {         if (b[j] >= p[i]) {           tmp += p[i];         } else if (b[j] < p[i]) {           tmp += b[j];           cur -= p[i] - b[j];           if (cur < 0) {             ok = false;             break;           }         }         ++j;       }       if (ok) {         ans = mid;         ms = tmp - cur;         if (ms < 0) ms = 0;         lo = mid + 1;       } else {         hi = mid - 1;       }     }     cout << ans <<     << ms << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int M[1010][1010] = {}, C[1010][1010] = {};   int main() {     int n, m;     cin >> n >> m;     memset(M, 0, sizeof(M));     memset(C, 0, sizeof(C));     for (int i = 0; i < n; i++) {       int x, y;       cin >> x >> y;       M[y][x]++;     }     for (int i = 0; i < m; i++) {       int x, y;       cin >> x >> y;       C[y][x]++;     }     int x = 0, y = 0;     for (int i = 0; i < 1010; i++) {       int sa = 0, sb = 0;       for (int j = 0; j < 1010; j++) {         sa += M[i][j];         sb += C[i][j];         y += min(M[i][j], C[i][j]);       }       x += min(sa, sb);     }     cout << x <<     << y << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int c, sum;       long int ans = 0;       cin >> c >> sum;       if (c >= sum)         ans = sum;       else {         ans = ((c - sum % c) * (sum / c) * (sum / c)) +               ((sum % c) * ((sum / c) + 1) * ((sum / c) + 1));       }       cout << ans << endl;     }   }
#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   using namespace std;   const int INF = 1e9;   const int mx = 300001;   int n, q;   vector<int> a, t[mx];   int count(int l, int r, int val) {     vector<int>::iterator bg = t[val].begin(), en = t[val].end();     return upper_bound(bg, en, r) - lower_bound(bg, en, l);   }   struct node {     vector<vector<pair<int, int> > > a;     node *l, *r;     node() : a(vector<vector<pair<int, int> > >()), l(NULL), r(NULL) {}   };   vector<pair<int, int> > best;   vector<int> roll, cnt;   const int maxk = 5;   node *T;   void add(int x) {     cnt[x]++;     roll.push_back(x);     for (int i = 0; i < maxk; ++i) {       if (best[i].second == x) {         best.erase(best.begin() + i, best.begin() + i + 1);         break;       }     }     best.push_back({cnt[x], x});     sort(best.begin(), best.end());     if (best.size() > maxk) best.erase(best.begin(), best.begin() + 1);   }   void clear() {     for (auto pos : roll) {       cnt[pos]--;     }     roll.clear();     best.clear();     for (int i = 0; i < maxk; ++i) {       best.push_back({0, 0});     }   }   node *build(int tl, int tr) {     if (tl == tr)       return new node();     else {       node *res = new node();       int tm = (tl + tr) >> 1;       for (int i = tm; i >= tl; --i) {         add(a[i]);         (res->a).push_back(best);       }       clear();       reverse((res->a).begin(), (res->a).end());       for (int i = tm + 1; i <= tr; ++i) {         add(a[i]);         (res->a).push_back(best);       }       clear();       res->l = build(tl, tm);       res->r = build(tm + 1, tr);       return res;     }   }   int get(node *root, int l, int r, int k, int tl, int tr) {     if (l == r) return a[l];     int tm = (tl + tr) >> 1;     if (r <= tm) return get(root->l, l, r, k, tl, tm);     if (l >= tm + 1) return get(root->r, l, r, k, tm + 1, tr);     int ans = INF;     vector<pair<int, int> > v1 = (root->a)[l - tl], v2 = (root->a)[r - tl];     for (auto p : v1) {       if (count(l, r, p.second) > k) ans = min(ans, p.second);     }     for (auto p : v2) {       if (count(l, r, p.second) > k) ans = min(ans, p.second);     }     if (ans == INF) ans = -1;     return ans;   }   int main() {     scanf( %d%d , &n, &q);     a.resize(n);     cnt.resize(n + 1);     for (int i = 0; i < n; ++i) {       scanf( %d , &a[i]);       t[a[i]].push_back(i);     }     clear();     T = build(0, n - 1);     int l, r, k;     for (int i = 0; i < q; ++i) {       scanf( %d%d%d , &l, &r, &k);       l--;       r--;       k = (r - l + 1) / k;       printf( %d n , get(T, l, r, k, 0, n - 1));     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long n, m, p = 0, q = 0, l = 0, i, flag = 0, k, t, j, r = 0, curr = 0, d;     cin >> n >> m;     long long a[n], b[n];     long double q1 = 1.0000;     for (long long i = 0; i < n; i++) {       cin >> a[i];       q1 *= double(a[i]) / double(a[i] - 1);       if (a[i] == 1) {         flag = 1;       }     }     for (long long i = 0; i < n; i++) {       cin >> b[i];       q1 *= double(b[i]) / double(b[i] - 1);       if (b[i] == 1) {         flag = 1;       }     }     if (flag == 1)       cout << -1 <<   n ;     else {       long double x = q1 * m - m;       if (x < 0)         cout << -1 <<   n ;       else         cout << fixed << setprecision(10) << x <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int p[5005], c[5005];   int day[5005];   bool out[5005], vi[5005];   int last = 0;   int match[5005];   vector<int> DSK[5005];   bool DFS(int u) {     if (vi[u] == true) return false;     vi[u] = true;     for (int i = 0; i < DSK[u].size(); i++) {       int w = DSK[u][i];       if (match[w] == -1 || DFS(match[w])) {         match[w] = u;         return true;       }     }     return false;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n, m;     cin >> n >> m;     for (int i = 1; i <= n; i++) cin >> p[i];     for (int i = 1; i <= n; i++) cin >> c[i];     int d;     cin >> d;     for (int i = 1; i <= d; i++) {       cin >> day[i];       out[day[i]] = true;     }     for (int i = 1; i <= n; i++)       if (!out[i]) DSK[p[i]].push_back(c[i]);     fill(match + 1, match + 1 + m, -1);     for (int i = d; i >= 1; i--) {       memset(vi, false, sizeof vi);       while (DFS(last)) {         last++;         memset(vi, false, sizeof vi);       }       DSK[p[day[i]]].push_back(c[day[i]]);       day[i] = last;     }     for (int i = 1; i <= d; i++) cout << day[i] <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e6 + 10;   int n, m;   vector<string> v(maxn);   int func(int x, vector<vector<int>> &s) {     vector<vector<int>> t(n + 3, vector<int>(m + 3, 0));     int i, j;     for (i = 1; i <= n - 2 * x; i++) {       for (j = 1; j <= m - 2 * x; j++)         if (s[i + 2 * x][j + 2 * x] - s[i - 1][j + 2 * x] - s[i + 2 * x][j - 1] +                 s[i - 1][j - 1] ==             (2 * x + 1) * (2 * x + 1)) {           t[i][j]++, t[i + 2 * x + 1][j + 2 * x + 1]++;           t[i][j + 2 * x + 1]--, t[i + 2 * x + 1][j]--;         }     }     for (i = 1; i <= n; i++)       for (j = 1; j <= m; j++) {         t[i][j] = t[i][j] + t[i - 1][j] + t[i][j - 1] - t[i - 1][j - 1];         if (v[i][j - 1] ==  X  && t[i][j] <= 0) return 0;       }     return 1;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0), cout.tie(0);     int i, j;     cin >> n >> m;     vector<vector<int>> s(n + 2, vector<int>(m + 2, 0));     for (i = 1; i <= n; i++) {       cin >> v[i];       for (j = 1; j <= m; j++)         s[i][j] =             s[i - 1][j] + s[i][j - 1] - s[i - 1][j - 1] + (v[i][j - 1] ==  X );     }     int l = 0, r = n, mid;     while (l < r) {       mid = (l + r + 1) >> 1;       if (func(mid, s))         l = mid;       else         r = mid - 1;     }     if (l == 0) {       cout << 0 <<   n ;       for (i = 1; i <= n; i++) cout << v[i] <<   n ;       return 0;     }     cout << l <<   n ;     vector<string> ans(n + 1, string(m,  . ));     for (i = 1; i <= n - 2 * l; i++) {       for (j = 1; j <= m - 2 * l; j++) {         if (s[i + 2 * l][j + 2 * l] - s[i - 1][j + 2 * l] - s[i + 2 * l][j - 1] +                 s[i - 1][j - 1] ==             (2 * l + 1) * (2 * l + 1))           ans[i + l][j + l - 1] =  X ;       }     }     for (i = 1; i <= n; i++) cout << ans[i] <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1000020;   const int maxm = 1000020;   const int MOd = 998244353;   void solve() {     string s;     cin >> s;     int c = 0, c1 = 0;     for (int i = 0; i < s.size(); i++) {       if (s[i] ==  0 ) {         if (!c)           printf( 1 1 n );         else           printf( 3 1 n );         c ^= 1;       } else {         if (!c1)           printf( 4 3 n );         else           printf( 4 1 n );         c1 ^= 1;       }     }   }   int main() {     int n = 1;     while (n--) solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int Q, n, m;   struct Str {     int n, qz[100100], yi[100100];     char str[100100];     inline int calc(int u, int v) {       return qz[v] - qz[u - 1] + (str[v] ==  A ) * 2 * (u <= v);     }     inline void pre() {       int i, j;       n = strlen(str + 1);       for (i = 1; i <= n; i++) qz[i] = qz[i - 1] + (str[i] !=  A );       for (i = 1; i <= n; i++) {         if (str[i] ==  A )           yi[i] = yi[i - 1] + 1;         else           yi[i] = 0;       }     }   } A, B;   int main() {     int i, j, p, q, l, r, cs, ct;     scanf( %s%s , A.str + 1, B.str + 1);     A.pre(), B.pre();     cin >> Q;     while (Q--) {       scanf( %d%d%d%d , &p, &q, &l, &r);       int a = min(A.yi[q], q - p + 1), b = min(B.yi[r], r - l + 1);       if (a < b) {         printf( 0 );         continue;       }       q -= min(a, b), r -= min(a, b);       if (p > q && l <= r) {         printf( 0 );         continue;       }       q -= min(q - p + 1, A.yi[q]) / 3 * 3;       if (l > r) {         if ((q - p + 1) % 3 == 0 && A.yi[q] >= q - p + 1)           printf( 1 );         else           printf( 0 );         continue;       }       cs = A.calc(p, q);       ct = B.calc(l, r);       if (cs > ct || ((cs - ct) & 1))         printf( 0 );       else         printf( 1 );     }   }