malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const long long N = 505, mod = 1e9 + 7;   long long c[N][N], s[N][N], p[N], inv[N];   long long l, r;   long long k, ans;   long long add(long long a, long long b) {     return a + b >= mod ? a + b - mod : a + b;   }   long long dec(long long a, long long b) {     return a - b < 0 ? a - b + mod : a - b;   }   long long ksm(long long a, long long b) {     long long ans = 1;     while (b) {       if (b & 1) ans = 1ll * ans * a % mod;       a = 1ll * a * a % mod;       b >>= 1;     }     return ans;   }   struct node {     long long a, b;     node() {}     node(long long aa, long long bb) { a = aa, b = bb; }     inline node operator+(const node& x) const {       return node(add(a, x.a), add(b, x.b));     }     inline node operator+(const long long& x) const { return node(add(a, x), b); }     inline node operator-(const node& x) const {       return node(dec(a, x.a), dec(b, x.b));     }     inline node operator-(const long long& x) const { return node(dec(a, x), b); }     inline node operator*(const node& x) const {       node ans;       ans.a = (a * x.a + b * x.b * 5) % mod;       ans.b = (a * x.b + b * x.a) % mod;       return ans;     }     inline node operator*(const long long& x) const {       return node(a * x % mod, b * x % mod);     }     friend inline node operator/(const node& x, const node& y) {       node ans, z = y;       if (z.b != 0) z.b = mod - z.b;       ans = x * z;       return ans * ksm(dec(y.a * y.a % mod, y.b * y.b * 5 % mod), mod - 2);     }   };   node ksm(node a, long long b) {     node ans = node(1, 0);     while (b) {       if (b & 1) ans = ans * a;       a = a * a;       b >>= 1;     }     return ans;   }   node sum(node a, long long b) { return (ksm(a, b + 1) - a) / (a - 1); }   node query(node x, long long l, long long r) {     if (x.a == 1 && x.b == 0) return x * (r - l + 1);     return sum(x, r) - sum(x, l - 1);   }   signed main() {     scanf( %d%lld%lld , &k, &l, &r);     l += 2, r += 2;     p[0] = p[1] = inv[1] = 1;     for (long long i = 2; i <= max(k, 5ll); i++) {       p[i] = p[i - 1] * i % mod;       inv[i] = (mod - mod / i) * inv[mod % i] % mod;     }     c[0][0] = c[1][0] = c[1][1] = s[0][0] = s[1][1] = 1;     for (long long i = 2; i <= k; i++) {       c[i][0] = 1, s[i][0] = 0;       for (long long j = 1; j <= i; j++)         c[i][j] = add(c[i - 1][j], c[i - 1][j - 1]),         s[i][j] = dec(s[i - 1][j - 1], (i - 1) * s[i - 1][j] % mod);     }     node a = node(0, inv[5]), b = node(0, mod - inv[5]);     node x = node(inv[2], inv[2]), y = node(inv[2], mod - inv[2]);     for (long long i = 0; i <= k; i++) {       node sum = node(0, 0);       for (long long j = 0; j <= i; j++) {         node ss = ksm(a, j) * ksm(b, i - j) *                   query(ksm(x, j) * ksm(y, i - j), l, r) * c[i][j];         sum = sum + ss;       }       sum = sum * s[k][i];       ans = add(ans, sum.a);     }     ans = ans * ksm(p[k], mod - 2) % mod;     printf( %lld , ans);   }
#include<bits/stdc++.h>   #define fi first   #define se second         #define all(x) (x).begin(), (x).end()   #define rall(x) (x).rbegin(), (x).rend()   #define pb push_back   #define len(x) (int)(x).size()   typedef long long ll;   typedef long double ld;   using namespace std;      const int N = 1001;   const int mod = 998244353;   int g[N][N];   int perm[N][N];   int cnt[N][N];   int n;   void add(int id, int val){       for(int x = 0; x < n; ++x){           cnt[x][perm[id][x]] += val;       }   }   void md(int &a){       if(a >= mod)           a-=mod;   }   void solve(){       cin >> n;       for(int i = 0;  i < 2*n; ++i){           for(int j = 0 ; j < n; ++j){               cin >> perm[i][j];           }           add(i , +1);       }       vector < bool > active(2*n, 1);       int ans = 1;       vector < int > answer;       while(true){           bool have = 0;           for(int x = 0; x < 2*n; ++x)               if(active[x])have = 1;           if(!have)               break;           int found = -1;           for(int x = 0 ;x < 2 * n; ++x){               if(active[x]){                   for(int i = 0 ;i  < n; ++i){                       if(cnt[i][perm[x][i]] == 1){                           found = x;                           break;                       }                   }               }           }           if(found == -1){               ans *= 2, md(ans);               for(int x = 0; x < 2*n; ++x)                   if(active[x])                       found = x;              }           answer.pb(found);           /// dell all shit           for(int j = 0; j < 2*n;++j){               if(active[j]){                   bool del = 0;                   for(int z = 0; z < n; ++z){                       if(perm[found][z] == perm[j][z])                           del = 1;                   }                   if(del)                       active[j] = 0, add(j , -1);               }           }       }       cout << ans <<   n ;       for(auto u : answer)           cout << u + 1 <<    ;       cout <<   n ;   }   signed main()   {       ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);       int t;cin >> t;       while(t--){           solve();       }       return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxN = 105;   int n, s, c[maxN], sum1, sum2;   vector<int> d;   bool cmp(int A, int B) { return A > B; }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> s;       for (int j = 1; j <= s; j++) cin >> c[j];       for (int j = 1; j <= s / 2; j++) sum1 += c[j];       for (int j = (s + 1) / 2 + 1; j <= s; j++) sum2 += c[j];       if (s % 2 == 1) d.push_back(c[(s + 1) / 2]);     }     sort(d.begin(), d.end(), cmp);     for (int i = 0; i < d.size(); i++)       if (i % 2 == 0)         sum1 += d[i];       else         sum2 += d[i];     cout << sum1 <<     << sum2;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long n, ans = 0;     cin >> n;     vector<int> a(n + 5), b(n + 5), c(n + 5);     map<long long, long long> m;     for (int i = 1; i <= n; i++) cin >> a[i];     for (int i = 1; i <= n; i++) cin >> b[i], m[b[i]] = i;     for (int i = 0; i < n; i++) c[i + 1] = m[a[i + 1]];     for (int i = 0; i < n - 1; i++)       if (c[i + 2] > c[i + 1])         ans++;       else         break;     cout << n - ans - 1;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   bool uin(T &a, T b) {     return a <= b ? true : false;   }   template <class T>   bool uax(T &a, T b) {     return a >= b ? true : false;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     cout.precision(10);     cout << fixed;     long long H;     int n;     cin >> H >> n;     vector<long long> a(n);     long long sum = 0;     long long gap = 0;     long long h = H;     for (int i = 0; i < n; i++) {       cin >> a[i];       sum -= a[i];       h += a[i];       if (h <= 0) {         cout << i + 1 << endl;         return 0;       }       gap = max(gap, sum);     }     if (sum <= 0) {       cout << -1 << endl;       return 0;     }     long long whole = (H - gap) / sum;     H -= whole * sum;     long long result = whole * n;     for (int i = 0;; i++) {       H += a[i % n];       result++;       if (H <= 0) {         cout << result << endl;         break;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long arr[1002][1002];   long long store[2][1000002];   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     long long n, m, k, p;     cin >> n >> m >> k >> p;     for (long long i = 1; i <= n; i++)       for (long long j = 1; j <= m; j++) cin >> arr[i][j];     multiset<long long> s1, s2;     for (long long i = 1; i <= n; i++) {       long long s = 0;       for (long long j = 1; j <= m; j++) s += arr[i][j];       s1.insert(s);     }     for (long long i = 1; i <= m; i++) {       long long s = 0;       for (long long j = 1; j <= n; j++) s += arr[j][i];       s2.insert(s);     }     for (long long i = 1; i <= k; i++) {       long long a = *s1.rbegin();       store[0][i] += store[0][i - 1] + a;       s1.erase(s1.find(a));       s1.insert(a - m * p);       a = *s2.rbegin();       store[1][i] += store[1][i - 1] + a;       s2.erase(s2.find(a));       s2.insert(a - n * p);     }     long long maxi = -1e18;     for (long long i = 0; i <= k; i++)       maxi = max(maxi, store[0][i] + store[1][k - i] - i * (k - i) * p);     cout << maxi;   }
#include <bits/stdc++.h>   using namespace std;   int n, i, j, m, ans, p = 51123987, i1, i2, i3, la[3], nt[151][3],                        f[151][53][53][53];   char s[201];   int main() {     scanf( %d , &n);     scanf( %s , s + 1);     for (i = n; i; i--) {       la[s[i] -  a ] = i;       for (j = 0; j < 3; j++) nt[i][j] = la[j];     }     f[1][0][0][0] = 1;     m = (n + 2) / 3;     for (i = 1; i <= n; i++)       for (i1 = 0; i1 <= m; i1++)         for (i2 = 0; i2 <= m; i2++)           for (i3 = 0; i3 <= m; i3++) {             if (i1 + i2 + i3 == n && abs(i1 - i2) <= 1 && abs(i1 - i3) <= 1 &&                 abs(i2 - i3) <= 1)               ans = (ans + f[i][i1][i2][i3]) % p;             if (nt[i][0]) (f[nt[i][0]][i1 + 1][i2][i3] += f[i][i1][i2][i3]) %= p;             if (nt[i][1]) (f[nt[i][1]][i1][i2 + 1][i3] += f[i][i1][i2][i3]) %= p;             if (nt[i][2]) (f[nt[i][2]][i1][i2][i3 + 1] += f[i][i1][i2][i3]) %= p;           }     printf( %d , ans);   }
#include <bits/stdc++.h>   using namespace std;   long long int arr[10000];   int main() {     std::ios::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int a, b, c, i, j, k, n, m, state = 0;     for (i = 0; i < 6; i++) cin >> arr[i];     sort(arr, arr + 6);     for (i = 0; i < 3; i++) {       if (arr[i] == arr[i + 1] && arr[i + 1] == arr[i + 2] &&           arr[i + 2] == arr[i + 3] && state == 0) {         state = 1;         arr[i] = 0;         arr[i + 1] = 0;         arr[i + 2] = 0;         arr[i + 3] = 0;         break;       }     }     if (state == 0) {       cout <<  Alien  << endl;       return 0;     }     long long int t1 = 0, t2 = 0;     for (i = 0; i < 6; i++) {       if (arr[i] != 0 && t1 == 0)         t1 = arr[i];       else if (arr[i] != 0)         t2 = arr[i];     }     if (t1 == t2)       cout <<  Elephant  << endl;     else       cout <<  Bear  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   T Max(const T &a, const T &b) {     return a > b ? a : b;   }   const int SN = 100000 + 10;   long long w[SN], f[SN][2], down[SN], g[SN], h[SN], head[SN];   long long u, v, n, num;   bool vis[SN];   struct Edge {     int from, to, next;   } E[SN << 2];   void Read(long long &x) {     long long in = 0, f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch =  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       in = in * 10 + ch -  0 ;       ch = getchar();     }     x = in * f;   }   void Add(int u, int v) {     E[++num].from = u;     E[num].to = v;     E[num].next = head[u];     head[u] = num;   }   void dfs(int u) {     vis[u] = 1;     g[u] = f[u][0] = f[u][1] = down[u] = w[u];     for (int i = head[u]; i; i = E[i].next) {       int to = E[i].to;       if (vis[to]) continue;       dfs(to);       f[u][0] = Max(f[u][0], f[to][0]);       f[u][0] = Max(f[u][0], f[u][1] + f[to][1]);       f[u][0] = Max(f[u][0], g[to] + down[u]);       f[u][0] = Max(f[u][0], down[to] + g[u]);       f[u][1] = Max(f[u][1], f[to][1]);       f[u][1] = Max(f[u][1], down[u] + down[to]);       g[u] = Max(g[u], g[to] + w[u]);       g[u] = Max(g[u], down[u] + f[to][1]);       g[u] = Max(g[u], down[to] + w[u] + h[u]);       h[u] = Max(h[u], f[to][1]);       down[u] = Max(down[u], down[to] + w[u]);     }   }   int main() {     Read(n);     for (int i = 1; i <= n; i++) Read(w[i]);     for (int i = 1; i < n; i++) {       Read(u), Read(v);       Add(u, v), Add(v, u);     }     dfs(1);     printf( %lld n , f[1][0]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void solve() {     long long n;     cin >> n;     vector<pair<long long, long long> > a(n);     for (auto &x : a) cin >> x.first;     for (auto &x : a) cin >> x.second;     long long ans = 0;     sort(a.begin(), a.end());     priority_queue<long long> pq;     long long sum = 0;     for (long long i = 0; i < n; ++i) {       if (!pq.empty()) {         long long dif = a[i].first - a[i - 1].first - 1;         long long j = 0;         while (!pq.empty()) {           if (j >= dif) break;           long long top = pq.top();           pq.pop();           ans += top * j;           sum -= top;           ++j;         }         assert(sum >= 0);         ans += sum * dif;       }       long long j = i;       while (j < n and a[i].first == a[j].first) {         pq.push(a[j].second);         sum += a[j].second;         ++j;       }       long long top = pq.top();       pq.pop();       sum -= top;       assert(sum >= 0);       ans += sum;       i = j - 1;     }     long long j = 0;     while (!pq.empty()) {       ans += pq.top() * j;       ++j;       pq.pop();     }     cout << ans <<   n ;   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long t = 1;     for (long long i = 0; i < t; ++i) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename P, typename Q>   ostream& operator<<(ostream& os, pair<P, Q> p) {     os <<  (  << p.first <<  ,  << p.second <<  ) ;     return os;   }   template <typename P, typename Q>   istream& operator>>(istream& is, pair<P, Q>& p) {     is >> p.first >> p.second;     return is;   }   template <typename T>   ostream& operator<<(ostream& os, vector<T> v) {     os <<  ( ;     for (auto& i : v) os << i <<  , ;     os <<  ) ;     return os;   }   template <typename T>   istream& operator>>(istream& is, vector<T>& v) {     for (auto& i : v) is >> i;     return is;   }   int f(string s) {     int cnt = 0;     for (int i = 0; i < s.size(); ++i) {       for (int j = 0; j <= s.size(); ++j) {         string t;         for (int k = i; k < j; ++k) {           t += s[k];         }         if (t.size()) {           string u = t;           reverse(u.begin(), u.end());           cnt += (t == u);         }       }     }     return cnt;   }   void fn() {     cout << f( ghghghg ) <<     << f( gggghhh ) << endl;     cout << f( llooo ) <<     << f( ololo ) << endl;     cout << f( gagadbcgghhchbdf ) <<     << f( abccbaghghghgdfd ) <<              << f( aabbccddfgggghhh ) << endl;   }   int main(int argc, char* argv[]) {     ios_base::sync_with_stdio(0);     cin.tie(0);     int n;     string s;     while (cin >> n >> s) {       sort(s.begin(), s.end());       cout << s << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 105;   int n;   string s[MAXN];   string ans =   ;   vector<int> g[MAXN];   bool has[MAXN];   bool used[MAXN];   vector<int> tp;   void dfs(int v) {     used[v] = true;     for (int i = 0; i < g[v].size(); i++) {       int to = g[v][i];       if (!used[to]) dfs(to);     }     tp.push_back(v);   }   void dfs2(int v) {     used[v] = true;     ans.append(1, (char)( a  + v));     for (int i = 0; i < (int)g[v].size(); i++) {       int to = g[v][i];       if (!used[to]) dfs2(to);     }   }   int main() {     scanf( %d n , &n);     for (int i = 1; i <= n; i++) {       getline(cin, s[i]);     }     for (int i = 1; i <= n; i++) {       for (int j = 0; j < s[i].length(); j++) {         has[s[i][j] -  a ] = true;         if (j + 1 < s[i].length()) {           int from = s[i][j] -  a ;           int to = s[i][j + 1] -  a ;           g[from].push_back(to);         }       }     }     for (int i = 0; i < 26; i++) {       if (has[i] && !used[i]) {         dfs(i);       }     }     reverse(tp.begin(), tp.end());     memset(used, false, sizeof(used));     for (int i = 0; i < (int)tp.size(); i++) {       int cur = tp[i];       if (!used[cur]) dfs2(cur);     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   int n;   long long l[100001], r[100001], ans = 0;   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %I64d%I64d , &l[i], &r[i]);     std::sort(l + 1, l + n + 1);     std::sort(r + 1, r + n + 1);     for (int i = 1; i <= n; i++) {       ans += l[i] > r[i] ? l[i] : r[i];     }     printf( %I64d n , ans + 1ll * n);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, a, b, men, may;   vector<pair<int, int> > arr;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n;     men = 1000000009;     for (int i = 0; i < n; i++) {       cin >> a >> b;       arr.push_back(make_pair(a, b));       men = min(a, men);       may = max(may, b);     }     for (int i = 0; i < n; i++) {       if (arr[i].first == men && arr[i].second == may) {         cout << i + 1;         return 0;       }     }     cout << -1;   }
#include <bits/stdc++.h>   using namespace std;   const long long Max = 2e5 + 9, inf = 1e18;   long long A[Max], B[Max], d[Max];   int find_nxt(long long id, long long x) {     if (A[id] - B[id] >= x) return B[id] += x, id;     d[id] = find_nxt(d[id], x - A[id] + B[id]), B[id] = A[id];     return d[id];   }   int main() {     ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);     long long n, m, a, id, x;     cin >> n;     for (int i = 1; i <= n; i++) cin >> A[i], d[i] = i + 1;     A[n + 1] = inf;     cin >> m;     while (m--) {       cin >> a >> id;       if (a == 1) {         cin >> x;         find_nxt(id, x);       } else         cout << B[id] <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 100005;   int c1[MAXN], c2[MAXN];   vector<pair<int, int> > ans;   int main() {     int n;     scanf( %d , &n);     int in, winner;     for (int i = 1; i <= n; i++) {       scanf( %d , &in);       if (i == n) winner = in;       c1[i] = c1[i - 1] + (in == 1);       c2[i] = c2[i - 1] + (in == 2);     }     for (int t = 1; t <= n; t++) {       int w1 = 0, w2 = 0, loc = 0;       while (loc < n) {         int loc1 = lower_bound(c1, c1 + n + 1, c1[loc] + t) - c1;         int loc2 = lower_bound(c2, c2 + n + 1, c2[loc] + t) - c2;         loc = min(loc1, loc2);         if (loc > n) break;         if (loc1 < loc2)           w1++;         else           w2++;       }       if (loc == n)         if ((winner == 1 && w1 > w2) || (winner == 2 && w1 < w2))           ans.push_back(make_pair(max(w1, w2), t));     }     sort(ans.begin(), ans.end());     printf( %d n , ans.size());     for (int i = 0; i < ans.size(); i++)       printf( %d %d n , ans[i].first, ans[i].second);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int32_t main() {     int n, m;     char x;     cin >> n >> m;     cin >> x;     vector<vector<char> > c(n + 1);     char gar;     vector<char> u1(m + 1,  . );     for (int j = 0; j < (n + 1); ++j) c[j] = u1;     bool b[n][m];     stack<pair<int, int> > s, t;     for (int i = 0; i < (n); ++i) {       scanf( %c , &gar);       for (int j = 0; j < (m); ++j) {         scanf( %c , &c[i][j]);         if (c[i][j] == x) s.push({i, j});         b[i][j] = false;       }     }     while (!s.empty()) {       auto k = s.top();       int u = k.first;       int v = k.second;       s.pop();       if (u > 0 && c[u - 1][v] != x) t.push({u - 1, v});       if (v > 0 && c[u][v - 1] != x) t.push({u, v - 1});       if (u + 1 < n && c[u + 1][v] != x) t.push({u + 1, v});       if (v + 1 < m && c[u][v + 1] != x) t.push({u, v + 1});     }     int cou = 0;     while (!t.empty()) {       auto k = t.top();       t.pop();       int u = k.first;       int v = k.second;       if (c[u][v] ==  . ) continue;       if ((u > 0 && b[u - 1][v] == 1 && c[u - 1][v] == c[u][v]) ||           (v > 0 && c[u][v - 1] == c[u][v] && b[u][v - 1] == 1) ||           (u + 1 < n && c[u + 1][v] == c[u][v] && b[u + 1][v] == 1) ||           (v + 1 < m && c[u][v + 1] == c[u][v] && b[u][v + 1] == 1))         b[u][v] = 1;       else {         cou++;         b[u][v] = 1;       }     }     cout << cou <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct Rect {     int x1, y1, x2, y2;     long long area() { return (long long)(x2 - x1) * (y2 - y1); }   };   long long intersect(const Rect&, const Rect&);   Rect intersectingRect(const Rect&, const Rect&);   int main() {     Rect white, black1, black2, b1Inside, b2Inside;     long long b1Cover, b2Cover, totalCover;     cin >> white.x1 >> white.y1 >> white.x2 >> white.y2;     cin >> black1.x1 >> black1.y1 >> black1.x2 >> black1.y2;     cin >> black2.x1 >> black2.y1 >> black2.x2 >> black2.y2;     b1Cover = intersect(white, black1);     b2Cover = intersect(white, black2);     b1Inside = intersectingRect(white, black1);     b2Inside = intersectingRect(white, black2);     totalCover = b1Cover + b2Cover - intersect(b1Inside, b2Inside);     if (white.area() - totalCover == 0)       cout <<  NO ;     else       cout <<  YES ;   }   long long intersect(const Rect& rect1, const Rect& rect2) {     long long x = max(0, min(rect1.x2, rect2.x2) - max(rect1.x1, rect2.x1));     long long y = max(0, min(rect1.y2, rect2.y2) - max(rect1.y1, rect2.y1));     return x * y;   }   Rect intersectingRect(const Rect& rect1, const Rect& rect2) {     Rect rect;     if (intersect(rect1, rect2)) {       rect.x1 = max(rect1.x1, rect2.x1);       rect.x2 = min(rect1.x2, rect2.x2);       rect.y1 = max(rect1.y1, rect2.y1);       rect.y2 = min(rect1.y2, rect2.y2);     } else {       rect.x1 = 0;       rect.x2 = 0;       rect.y1 = 0;       rect.y2 = 0;     }     return rect;   }
#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   const int N = 2e5 + 10;   const int INF = 0x3f3f3f3f;   const long long LINF = 0x3f3f3f3f3f3f3f3f;   inline int read() {     static char buf[1000000], *p1 = buf, *p2 = buf;     register int x = false;     register char ch =         p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin), p1 == p2)             ? EOF             : *p1++;     ;     register bool sgn = false;     while (ch !=  -  && (ch <  0  || ch >  9 ))       ch = p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin), p1 == p2)                ? EOF                : *p1++;     ;     if (ch ==  - )       sgn = true,       ch = p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin), p1 == p2)                ? EOF                : *p1++;     ;     while (ch >=  0  && ch <=  9 )       x = (x << 1) + (x << 3) + (ch ^ 48),       ch = p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin), p1 == p2)                ? EOF                : *p1++;     ;     return sgn ? -x : x;   }   long long fpow(long long a, int b, int mod) {     long long res = 1;     for (; b > 0; b >>= 1) {       if (b & 1) res = res * a % mod;       a = a * a % mod;     }     return res;   }   long long h[N][2];   char s[N];   long long base[N];   int cnt[N];   long long calc(int L, int R) {     return (h[R][L & 1] - h[L - 1][L & 1] * base[cnt[R] - cnt[L - 1]] % mod +             mod) %            mod;   }   int main() {     int n, m;     cin >> n;     scanf( %s , s + 1);     cin >> m;     base[0] = 1;     for (int i = 1; i <= n; i++) {       base[i] = base[i - 1] * 998244353 % mod;       cnt[i] = cnt[i - 1];       h[i][0] = h[i - 1][0];       h[i][1] = h[i - 1][1];       if (s[i] ==  0 ) {         cnt[i] = cnt[i - 1] + 1;         h[i][0] = (h[i - 1][0] * 998244353 % mod + (i & 1) + 1) % mod;         h[i][1] = (h[i - 1][1] * 998244353 % mod + (i & 1 ^ 1) + 1) % mod;       }     }     while (m--) {       int x, y, z;       cin >> x >> y >> z;       if (calc(x, x + z - 1) == calc(y, y + z - 1))         puts( YES );       else         puts( NO );     }     return 0;   }