malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int maxn = 300010;   multiset<int> val[maxn];   struct Trie {     int next[maxn][26], fail[maxn], end[maxn];     int last[maxn];     int root, L;     int newnode() {       for (int i = 0; i < 26; i++) next[L][i] = -1;       fail[L] = last[L] = end[L] = 0;       return L++;     }     void init() {       L = 0;       root = newnode();     }     int insert(char buf[], int v) {       int len = strlen(buf);       int now = root;       for (int i = 0; i < len; i++) {         if (next[now][buf[i] -  a ] == -1) next[now][buf[i] -  a ] = newnode();         now = next[now][buf[i] -  a ];       }       end[now]++;       val[now].insert(v);       return now;     }     void build() {       queue<int> Q;       fail[root] = root;       for (int i = 0; i < 26; i++) {         if (next[root][i] == -1)           next[root][i] = root;         else {           fail[next[root][i]] = root;           Q.push(next[root][i]);         }       }       while (!Q.empty()) {         int now = Q.front();         Q.pop();         for (int i = 0; i < 26; i++) {           if (next[now][i] == -1)             next[now][i] = next[fail[now]][i];           else {             int son = next[now][i];             fail[son] = next[fail[now]][i];             last[son] = end[fail[son]] ? fail[son] : last[fail[son]];             Q.push(next[now][i]);           }         }       }     }     int count(int x) {       int res = -1;       for (int j = x; j && end[j] != -1; j = last[j]) {         if (end[j]) res = max(res, *val[j].rbegin());       }       return res;     }     void query(char buf[]) {       int len = strlen(buf);       int now = root;       int res = -1;       for (int i = 0; i < len; i++) {         now = next[now][buf[i] -  a ];         if (end[now] != -1)           res = max(res, count(now));         else if (end[last[now]] != -1)           res = max(res, count(last[now]));       }       printf( %d n , res);     }     void ch(int pos, int x, int y) {       auto it = val[pos].lower_bound(x);       val[pos].erase(it);       val[pos].insert(y);     }   } ac;   char s[maxn];   int pos[maxn], w[maxn];   int main() {     int n, m;     ac.init();     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) {       scanf( %s , s);       pos[i] = ac.insert(s, 0);       w[i] = 0;     }     ac.build();     int op, x, y;     while (m--) {       scanf( %d , &op);       if (op == 1) {         scanf( %d%d , &x, &y);         ac.ch(pos[x], w[x], y);         w[x] = y;       } else {         scanf( %s , s);         ac.query(s);       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MOD = 1000000007;   const int WYMIAR = 17;   int mod = MOD;   struct M {     int t[WYMIAR][WYMIAR];     M() {       for (int i = 0; i < (WYMIAR); ++i)         for (int j = 0; j < (WYMIAR); ++j) t[i][j] = 0;       for (int i = 0; i < (WYMIAR); ++i) t[i][i] = 1;     }   };   M operator*(const M &a, const M &b) {     M res;     for (int i = 0; i < (WYMIAR); ++i)       for (int j = 0; j < (WYMIAR); ++j) {         long long acc = 0;         for (int k = 0; k < (WYMIAR); ++k)           acc += (long long)a.t[i][k] * b.t[k][j] % mod;         res.t[i][j] = acc % mod;       }     return res;   }   M potega(M x, long long n) {     M res, acc = x;     for (int i = 0; i < (WYMIAR); ++i) res.t[i][i] = 1;     while (n) {       if (n & 1) res = res * acc;       acc = acc * acc;       n /= 2;     }     return res;   }   pair<int, int> rozloz(int x) { return make_pair(x / 4, x % 4); }   int zabron(int a, int b) {     if (a > b) return zabron(b, a);     if (a == b) return 1;     if (a == 0 && b == 3) return 1;     if (a == 1 && b == 2) return 1;     return 0;   }   int dobra_para(int aa, int bb) {     pair<int, int> a = rozloz(aa);     pair<int, int> b = rozloz(bb);     if (a.second != b.first) return 0;     if (zabron(b.first, b.second)) return 0;     if (a.first == 1 && b.first == 0 && b.second == 2) return 0;     if (a.first == 2 && b.first == 0 && b.second == 1) return 0;     return 1;   }   int licz(int n) {     if (n == 0) return 0;     if (n == 1) return 4;     M m;     for (int i = 0; i < (16); ++i)       for (int j = 0; j < (16); ++j) m.t[i][j] = dobra_para(i, j);     for (int i = 0; i < (17); ++i) m.t[i][16] = 1;     int stan[17];     stan[16] = 4;     for (int i = 0; i < (16); ++i) {       pair<int, int> p = rozloz(i);       stan[i] = !zabron(p.first, p.second);     }     M tmp = potega(m, n - 1);     int acc = 0;     for (int i = 0; i < (17); ++i)       acc = (acc + (long long)stan[i] * tmp.t[i][16]) % MOD;     return acc % MOD;   }   int licz2(int n) {     if (n == 0) return 0;     if (n == 1) return 4;     int res = licz(n);     int palindromy = licz((n + 1) / 2);     int niepal = ((MOD + res - palindromy) % MOD) * (long long)500000004 % MOD;     return (palindromy + niepal) % MOD;   }   int main() {     int l, r;     scanf( %d %d , &l, &r);     printf( %d n , (licz2(r) + MOD - licz2(l - 1)) % MOD);     return 0;   }
#include <bits/stdc++.h>   int f[5005], g[5005], h[5005], n;   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &h[i]);     memset(f, 66, sizeof(f));     f[0] = 0;     for (int i = 1; i <= n; i++) {       int j = i, sum = h[j];       while (j && sum < f[j - 1]) sum += h[--j];       if (sum >= f[j - 1]) f[i] = sum, g[i] = g[j - 1] + i - j;     }     printf( %d n , g[n]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char symmetric[11] = { A ,  H ,  I ,  M ,  O ,  T ,  U ,  V ,  W ,  X ,  Y };   bool isPrime(long long int n) {     if (n <= 1) return false;     if (n <= 3) return true;     if (n % 2 == 0 || n % 3 == 0) return false;     for (int i = 5; i * i <= n; i = i + 6)       if (n % i == 0 || n % (i + 2) == 0) return false;     return true;   }   bool IsPalindrome(string str) {     if (str.empty()) return false;     long long int i = 0;     long long int j = str.length() - 1;     while (i < j) {       if (str[i] != str[j]) {         return false;       }       i++;       j--;     }     return true;   }   long long int binpow(long long int a, long long int b) {     if (b == 0) return 1;     long long int res = binpow(a, b / 2);     if (b % 2) return (res * res * a);     return (res * res);   }   signed main() {     ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);     long long int a, b;     cin >> a >> b;     long long int x = max(a, b);     long long int y = a + b - x;     if (a < 2 * b && b < 2 * a)       cout << a <<     << b;     else if (x % y == 0) {       if ((x / y) % 2 == 0) {         if (y == a) {           cout << y <<   0 ;         } else {           cout <<  0   << y;         }       } else {         cout << y <<     << y;       }     } else {       while (a && b) {         if (a >= 2 * b)           a %= 2 * b;         else if (b >= 2 * a)           b %= 2 * a;         else           break;       }       cout << a <<     << b;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   string nums[1005];   string tostr(int a) {     ostringstream ss;     ss << a;     return ss.str();   }   deque<long long> deq;   vector<int> ans[200001];   vector<pair<int, int> > graph[200001];   int p[200001];   int cmax = 0;   void dfs(int v, int d) {     int c = 0;     for (int i = 0; i < graph[v].size(); i++) {       if (c == d) c++;       int k = graph[v][i].first;       if (k == p[v]) {         continue;       }       p[k] = v;       ans[c].push_back(graph[v][i].second);       dfs(k, c);       cmax = max(c, cmax);       c++;     }   }   set<int> is;   int main() {     int n, m;     cin >> n >> m;     int k;     for (int i = 0; i < n; i++) {       cin >> k;       is.insert(k);     }     vector<int> ans;     for (int kek = 1; kek <= 3000000; kek++) {       if (m >= kek && is.find(kek) == is.end()) {         ans.push_back(kek);         m -= kek;       }     }     cout << ans.size() <<   n ;     for (int i = 0; i < ans.size(); i++) {       cout << ans[i] <<    ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, l, r;     cin >> n;     pair<pair<long long, long long>, long long> lr[n + 1];     for (long long i = 1; i <= n; i++) {       cin >> lr[i].first.first >> lr[i].first.second;       lr[i].second = i;     }     sort(lr + 1, lr + n + 1);     for (long long i = 2; i <= n; i++) {       if (lr[i].first.second <= lr[i - 1].first.second) {         return cout << lr[i].second <<     << lr[i - 1].second, 0;       }       if (lr[i].first.first == lr[i - 1].first.first) {         return cout << lr[i - 1].second <<     << lr[i].second, 0;       }     }     cout <<  -1 -1 ;   }
#include <bits/stdc++.h>   using namespace std;   long long KuriBija[1005];   long long A;   long long Cik, lol;   int main() {     cin >> Cik >> lol;     for (long long i = 0; i < lol; i++) {       cin >> A;       KuriBija[A] = 1;       cin >> A;       KuriBija[A] = 1;     }     lol = 1;     while (KuriBija[lol] != 0) {       lol++;     }     cout << Cik - 1 << endl;     for (long long i = 0; i < Cik; i++) {       if (i + 1 != lol) {         cout << lol <<     << i + 1 << endl;       }     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     cin >> n >> k;     if ((n - 1) * n / 2 <= k) {       cout <<  no solution  << endl;       return 0;     }     long x, y;     x = y = 0;     while (n--) {       cout << x <<     << y++ << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   string ent =   n ;   string space =    ;   int main() {     ios_base::sync_with_stdio(false);     int n;     cin >> n;     string s;     cin >> s;     int zero, one;     zero = one = 0;     for (int i = 0; i < n; i++) {       if (s[i] == 48)         zero++;       else         one++;     }     if (one != zero) {       cout << 1 << ent + s + ent;     } else {       int j = n - 1;       string s_new;       for (int i = 0; i < n; i++) {         if (one != zero) {           j = i;           break;         }         s_new += s[i];         if (s[i] == 48)           zero--;         else           one--;       }       cout << 2 << ent + s_new + space;       for (int i = j; i < n; i++) {         cout << s[i];       }       cout << ent;     }   }
#include <bits/stdc++.h>   using namespace std;   struct Query {     int prefixe, nombre;     int id;     bool operator<(const Query& autre) const { return prefixe < autre.prefixe; }   };   const int MAXP = 20;   const int MAXN = 100 * 1000 + 10;   const int MOD = 1000 * 1000 * 1000 + 7;   bool prise[MAXP];   int puissance[MAXN];   int iConcerne[MAXP];   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     puissance[0] = 1;     for (int i = 1; i < MAXN; i++) {       puissance[i] = (puissance[i - 1] * 2) % MOD;     }     int nbNombres, nbQuestions;     cin >> nbNombres >> nbQuestions;     int nombres[nbNombres];     for (int i = 0; i < nbNombres; i++) {       cin >> nombres[i];     }     Query questions[nbQuestions];     int solution[nbQuestions];     for (int i = 0; i < nbQuestions; i++) {       cin >> questions[i].prefixe >> questions[i].nombre;       questions[i].prefixe--;       questions[i].id = i;     }     sort(questions, questions + nbQuestions);     int inQuestion = 0;     int nbPris = 0;     for (int iN = 0; iN < nbNombres; iN++) {       for (int i = 0; i < nbPris; i++) {         if (nombres[iN] & (1 << iConcerne[i])) nombres[iN] ^= nombres[i];       }       for (int i = 0; i < MAXP; i++) {         if (!prise[i] && (nombres[iN] & (1 << i))) {           swap(nombres[iN], nombres[nbPris]);           iConcerne[nbPris] = i;           nbPris++;           prise[i] = true;           break;         }       }       while (inQuestion < nbQuestions && questions[inQuestion].prefixe == iN) {         for (int i = 0; i < nbPris; i++) {           if (questions[inQuestion].nombre & (1 << iConcerne[i]))             questions[inQuestion].nombre ^= nombres[i];         }         if (questions[inQuestion].nombre == 0) {           solution[questions[inQuestion].id] = puissance[iN + 1 - nbPris];         } else {           solution[questions[inQuestion].id] = 0;         }         inQuestion++;       }     }     for (int i = 0; i < nbQuestions; i++) {       cout << solution[i] << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     long long arr[n + 2];     for (int i = 1; i <= n; i++) cin >> arr[i];     long long cume[n + 2], cumo[n + 2], rcume[n + 2], rcumo[n + 2];     cume[0] = 0;     cumo[0] = 0;     for (int i = 1; i <= n; i++) {       if (i % 2) {         cumo[i] = cumo[i - 1] + arr[i];         cume[i] = cume[i - 1];       } else {         cume[i] = cume[i - 1] + arr[i];         cumo[i] = cumo[i - 1];       }     }     rcume[n + 1] = 0;     rcumo[n + 1] = 0;     for (int i = n; i >= 1; i--) {       if (i % 2) {         rcumo[i] = rcumo[i + 1] + arr[i];         rcume[i] = rcume[i + 1];       } else {         rcume[i] = rcume[i + 1] + arr[i];         rcumo[i] = rcumo[i + 1];       }     }     long long ans = 0;     for (int i = 1; i <= n; i++) {       long long o = cumo[i - 1] + rcume[i + 1];       long long e = cume[i - 1] + rcumo[i + 1];       if (o == e) ans++;     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     string s;     int x = 0, y = 0;     cin >> s;     for (int i = 0; i < t; i++) {       if (s[i] ==  L ) {         x--;       } else {         y++;       }     }     cout << y - x + 1 << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct __s {     __s() {}     ~__s() {       long long n;       cin >> n;     }   } __S;   double mm, back, now, ans;   long long m, n;   double st(double x) {     double res = 1.0;     for (long long i = 0; i < (long long)(n - 1); i++) {       res *= x / m;     }     return res;   }   int main(void) {     cin >> m >> n;     mm = (double)m;     back = st(mm);     for (long long i = 0; i < (long long)(m); i++) {       mm -= 1.0;       now = st(mm);       double res = (mm + 1.0) * (back + (back - now) * mm) / m;       ans += res;       if (res < 1e-6) {         cerr << i <<   n ;         break;       }       back = now;     }     printf( %.10f  n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int N, M;   int p[1010];   long long X[1010];   int A[1010];   long long B[1010];   int U[2020];   int V[2020];   int up[1010];   bool chk[2020];   bool vst[1010];   bool chkv[1010];   long long mn[2020];   vector<int> adj[1010];   priority_queue<pair<long long, int>, vector<pair<long long, int> >,                  greater<pair<long long, int> > >       pq;   int par(int x) {     if (x == p[x]) return x;     return p[x] = par(p[x]);   }   void unite(int a, int b) {     a = par(a);     b = par(b);     p[a] = b;   }   void add(int e) {     int a = U[e], b = V[e];     assert(vst[a] || vst[b]);     if (vst[b]) swap(a, b);     if (vst[b]) {       int t = par(b);       while (t > 1) {         B[1] += B[t];         p[t] = 1;         t = up[t];         t = par(t);       }       t = par(a);       while (t > 1) {         B[1] += B[t];         p[t] = 1;         t = up[t];         t = par(t);       }     } else {       int t = par(a);       vst[b] = true;       up[b] = t;     }     chk[e] = true;   }   void dfs(int v) {     X[v] += B[v];     for (int i : adj[v]) {       X[i] += X[v];       dfs(i);     }   }   void add_edges() {     for (int i = 1; i <= N; i++) {       adj[i].clear();       X[i] = 0;     }     for (int i = 2; i <= N; i++) {       if (p[i] != i || !vst[i]) continue;       adj[par(up[i])].push_back(i);     }     dfs(1);     for (int i = 1; i <= M; i++) {       if (chk[i]) continue;       int a = U[i], b = V[i];       a = par(a);       b = par(b);       if (a == b) {         chk[i] = true;         continue;       }       if (vst[a]) {         if (mn[i] > A[V[i]] - X[a] + 1) {           mn[i] = A[V[i]] - X[a] + 1;           pq.emplace(mn[i], i);         }       }       if (vst[b]) {         if (mn[i] > A[U[i]] - X[b] + 1) {           mn[i] = A[U[i]] - X[b] + 1;           pq.emplace(mn[i], i);         }       }     }   }   int main() {     int tc;     scanf( %d , &tc);     while (tc--) {       scanf( %d%d , &N, &M);       int mxv = 0;       for (int i = 2; i <= N; i++) {         scanf( %d , &A[i]);         if (A[mxv] < A[i]) mxv = i;       }       B[1] = 0;       for (int i = 2; i <= N; i++) scanf( %lld , &B[i]);       for (int i = 1; i <= M; i++) scanf( %d%d , &U[i], &V[i]);       while (pq.size()) pq.pop();       for (int i = 1; i <= N; i++) p[i] = i;       for (int i = 1; i <= N; i++) {         chkv[i] = vst[i] = false;         X[i] = up[i] = 0;       }       for (int i = 1; i <= M; i++) chk[i] = false;       vst[1] = true;       long long ans = 0;       for (int i = 1; i <= M; i++) mn[i] = 1LL << 60;       add_edges();       while (pq.size()) {         if (vst[mxv]) break;         pair<long long, int> t = pq.top();         pq.pop();         if (t.first > mn[t.second] || chk[t.second]) continue;         if (par(U[t.second]) == par(V[t.second])) {           chk[t.second] = true;           continue;         }         ans = max(ans, t.first);         add(t.second);         add_edges();       }       assert(vst[mxv]);       printf( %lld n , ans);     }     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( unroll-loops )   #pragma GCC optimize( O3 ,  omit-frame-pointer ,  inline )   #pragma GCC target(         sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native )   using namespace std;   const long long mod = 998244353;   mt19937 rng((int)chrono::steady_clock::now().time_since_epoch().count());   const int mxN = 5010;   int main(int argc, char *argv[]) {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     srand(time(NULL));     cout << fixed << setprecision(9);     int t = 1;     while (t--) {       int n;       cin >> n;       vector<int> a(n);       for (int i = 0; i < n; i++) cin >> a[i];       vector<int> e;       for (int i = 0; i < n; i++) {         if (!e.empty() && e.back() % 2 == a[i] % 2)           e.pop_back();         else           e.push_back(a[i]);       }       cout << (e.size() <= 1 ?  YES  :  NO ) <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, i, c = 1;     cin >> n;     int a[n + 1];     memset(a, 0, sizeof(a));     for (i = 0; i < n; i++) cin >> a[i];     for (i = 0; i < n; i++) {       if (a[i] != a[i + 1]) c++;     }     cout << c - 1 <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n1, n2, k1, k2, d1, d2;     scanf( %d %d %d %d , &n1, &n2, &k1, &k2);     if (n1 > n2) {       printf( First n );     } else {       printf( Second n );     }     return 0;   }
#include <bits/stdc++.h>   #pragma warning(disable : 4996)   #pragma comment(linker,  /STACK:336777216 )   using namespace std;   int IT_MAX = 1 << 18;   const long long MOD = 1000000007;   const int INF = 0x3f3f3f3f;   const long long LL_INF = 0x3f3f3f3f3f3f3f3f;   const double PI = acos(-1);   const double ERR = 1e-10;   long long dp[55][55][55];   long long tdp[55][55][55];   long long C[55][55];   long long F[55];   long long po2[55];   long long cnt[55][2];   int main() {     int i, j, k, l, m;     for (i = 0; i <= 50; i++) {       C[i][0] = C[i][i] = 1;       for (j = 1; j < i; j++) C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % MOD;       for (j = 0; j <= i; j++) cnt[i][j % 2] = (cnt[i][j % 2] + C[i][j]) % MOD;     }     F[0] = 1;     for (i = 1; i <= 50; i++) F[i] = F[i - 1] * i % MOD;     po2[0] = 1;     for (i = 1; i <= 50; i++) po2[i] = po2[i - 1] * 2 % MOD;     dp[0][0][0] = 1;     int N, tus;     scanf( %d %d , &N, &tus);     for (i = 1; i <= N; i++) {       int st = 0, en = 1;       int t;       scanf( %d , &t);       if (t == 1) st = 1;       if (t == 0) en = 0;       for (k = 0; k < i; k++) {         for (l = 0; k + l < i; l++) {           m = i - 1 - k - l;           if (st == 0) {             long long c0 = cnt[l][1] * po2[k + m] % MOD;             long long c1 = cnt[l][0] * po2[k + m] % MOD;             dp[k + 1][l][m] += c1 * dp[k][l][m] % MOD;             dp[k][l][m + 1] += c0 * dp[k][l][m] % MOD;           }           if (en == 1) {             long long c0 = cnt[k][1] * po2[l + m] % MOD;             long long c1 = cnt[k][0] * po2[l + m] % MOD;             dp[k][l + 1][m] += c1 * dp[k][l][m] % MOD;             dp[k][l][m + 1] += c0 * dp[k][l][m] % MOD;           }         }       }       for (j = 0; j <= i; j++) {         for (k = 0; j + k <= i; k++) {           l = i - j - k;           dp[j][k][l] %= MOD;         }       }     }     long long ans = 0;     for (i = 0; i <= N; i++) {       for (j = 0; i + j <= N; j++) {         k = N - i - j;         if ((i + j) % 2 == tus) ans = (ans + dp[i][j][k]) % MOD;       }     }     return !printf( %lld n , ans);   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     ;     double p = 0, x = 0, m, n, i;     cin >> m >> n;     for (i = m; i >= 1; i--) {       p += (1 - pow(((i - 1) / m), n) - x) * i;       x += 1 - pow(((i - 1) / m), n) - x;     }     cout << fixed << setprecision(12) << p;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 40;   int v[N], x[N], ct, al[N], col[N], n, lu[N], lv[N];   int read() {     int sum = 0, fg = 1;     char c = getchar();     while (c <  0  || c >  9 ) {       if (c ==  - ) fg = -1;       c = getchar();     }     while (c >=  0  && c <=  9 ) {       sum = sum * 10 + c -  0 ;       c = getchar();     }     return sum * fg;   }   inline void add(int u, int V) {     v[++ct] = V;     x[ct] = al[u];     al[u] = ct;   }   inline void dfs(int u, int tw) {     col[u] = tw;     for (int i = al[u]; i; i = x[i])       if (col[v[i]] == -1) dfs(v[i], tw ^ 1);   }   int main() {     n = read();     for (int i = 1; i <= n; i++) col[i] = -1;     for (register int i = 1, x, y; i <= n; i++) {       x = read();       y = read();       if (lu[x]) {         add(lu[x], i);         add(i, lu[x]);         lu[x] = 0;       } else         lu[x] = i;       if (lv[y]) {         add(lv[y], i);         add(i, lv[y]);         lv[y] = 0;       } else         lv[y] = i;     }     for (register int i = 1; i <= n; i++)       if (col[i] == -1) dfs(i, 0);     for (register int i = 1; i <= n; i++)       if (col[i] == 0)         cout <<  b ;       else         cout <<  r ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long m, ans;   string ss, s;   long long i;   int main() {     cin >> s;     for (i = 0; i + 4 < s.length(); i++) {       ss = s.substr(i, 5);       if (ss ==  heavy ) {         m++;       }       if (ss ==  metal ) {         ans += m;       }     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[1006];   int k;   int fun(int x) {     int mid, high = k - 1, low = 0, i;     while (high >= low) {       mid = (low + high) >> 1;       if (a[mid] < x) {         low = mid + 1;       } else if (a[mid] > x) {         high = mid - 1;       } else         break;     }     if (a[mid] == x) return 999999999;     if (a[mid] < x) {       for (i = mid; a[i] <= x && i < k; ++i)         if (a[i] == x) return 999999999;       return i;     } else {       for (i = mid; a[i] >= x && i >= 0; --i)         if (a[i] == x) return 999999999;       return i + 1;     }   }   int main() {     int i, n, m, q, x, y;     while (scanf( %d%d%d%d , &n, &m, &k, &q) != EOF) {       for (i = 0; i < k; ++i) {         scanf( %d%d , &x, &y);         a[i] = (x - 1) * m + y;       }       sort(a, a + k);       while (q--) {         scanf( %d%d , &x, &y);         i = fun((x - 1) * m + y);         if (i == 999999999)           puts( Waste );         else           switch (((x - 1) * m + y - i - 1) % 3) {             case 0:               puts( Carrots );               break;             case 1:               puts( Kiwis );               break;             case 2:               puts( Grapes );               break;           }       }     }     return 0;   }