malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   char s[2000006];   char t[1000006];   int len[100005], pos[100005];   vector<pair<int, int>> e;   int main() {     int n;     scanf( %d , &n);     int tp = 0;     for (int i = 0; i < n; i++) {       scanf( %s , t + tp);       len[i] = strlen(t + tp);       pos[i] = tp;       tp += len[i];       int ki;       scanf( %d , &ki);       while (ki--) {         int xij;         scanf( %d , &xij);         e.push_back({xij - 1, i});       }     }     int p = 0;     sort(e.begin(), e.end());     int esz = (int)e.size();     tp = -1;     int te = -1, sp = 0;     while (p < esz) {       int f = e[p].first;       while (sp < f) {         if (tp != -1) {           s[sp++] = t[tp++];           if (tp >= te) tp = te = -1;         } else           s[sp++] =  a ;       }       if (tp == -1) {         tp = pos[e[p].second];         te = pos[e[p].second] + len[e[p].second];       } else if (len[e[p].second] > te - tp) {         tp = pos[e[p].second];         te = pos[e[p].second] + len[e[p].second];       }       while (p + 1 < esz && e[p + 1].first == e[p].first) {         p++;         if (len[e[p].second] > te - tp) {           tp = pos[e[p].second];           te = pos[e[p].second] + len[e[p].second];         }       }       p++;     }     while (tp < te) s[sp++] = t[tp++];     s[sp] =   0 ;     printf( %s , s);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 5e3 + 5;   const int mod = 998244353;   inline long long fpm(long long a, long long p) {     long long r = 1;     while (p) {       if (p & 1) r = r * a % mod;       a = a * a % mod;       p /= 2;     }     return r;   }   int k, n, m;   int s[maxn][maxn];   inline void init() {     s[0][0] = 1;     for (int i = 1; i <= k; i++) {       for (int j = 1; j <= i; j++) {         s[i][j] = (s[i - 1][j - 1] + 1ll * j * s[i - 1][j] % mod) % mod;       }     }   }   int main() {     cin >> n >> m >> k;     init();     long long ans = 0, cur = 1;     long long invm = fpm(m, mod - 2);     for (int i = 0; i <= k; i++) {       ans = (ans + 1ll * cur * s[k][i] % mod * fpm(invm, i) % mod) % mod;       cur = 1ll * cur * (n - i) % mod;     }     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   char S[5000005], T[5000005];   int n, l = 1, tot = 0, R[5000005], st[5000005], ed[5000005];   void modify() {     T[0] =  $ , T[1] =  # ;     for (int i = 0; i < n; ++i) T[++l] = S[i], T[++l] =  # ;     T[++l] =   0 ;   }   void Manacher() {     int p = 0, mx = 0;     for (int i = 1; i < l; ++i) {       R[i] = (mx > i) ? min(R[2 * p - i], mx - i) : 1;       while (T[i - R[i]] == T[i + R[i]]) R[i]++;       if (mx < i + R[i]) mx = i + R[i], p = i;       st[i - R[i] + 1]++, st[i + 1]--;       ed[i]++, ed[i + R[i]]--, tot = (tot + R[i] / 2) % 51123987;     }     tot = (1ll * tot * (tot - 1) / 2) % 51123987;   }   int main() {     int i, ans = 0, sum = 0;     scanf( %d%s , &n, S);     modify(), Manacher();     for (i = 1; i < l; i++) {       st[i] += st[i - 1];       ed[i] += ed[i - 1];       if (T[i] !=  # ) {         ans = (ans + 1ll * sum * st[i] % 51123987) % 51123987;         sum = (sum + ed[i]) % 51123987;       }     }     printf( %d , (tot - ans + 51123987) % 51123987);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using vint = vector<long long>;   using pint = pair<long long, long long>;   using vpint = vector<pint>;   template <typename A, typename B>   inline void chmin(A& a, B b) {     if (a > b) a = b;   }   template <typename A, typename B>   inline void chmax(A& a, B b) {     if (a < b) a = b;   }   template <class A, class B>   ostream& operator<<(ostream& ost, const pair<A, B>& p) {     ost <<  {  << p.first <<  ,  << p.second <<  } ;     return ost;   }   template <class T>   ostream& operator<<(ostream& ost, const vector<T>& v) {     ost <<  { ;     for (long long i = 0; i < v.size(); i++) {       if (i) ost <<  , ;       ost << v[i];     }     ost <<  } ;     return ost;   }   inline long long topbit(unsigned long long x) {     return x ? 63 - __builtin_clzll(x) : -1;   }   inline long long popcount(unsigned long long x) {     return __builtin_popcountll(x);   }   inline long long parity(unsigned long long x) { return __builtin_parity(x); }   signed main() {     long long N, K;     cin >> N >> K;     if (K > 1000000 || K * (K + 1) / 2 > N) {       cout << -1 << endl;       return 0;     }     long long s = K * (K + 1) / 2;     long long G = 0;     for (long long g = 1; g * g <= N; g++) {       if (N % g) continue;       if (N / s >= g) chmax(G, g);       if (N / s >= N / g) chmax(G, N / g);     }     vint ans(K);     iota((ans).begin(), (ans).end(), 1);     ans[K - 1] += N / G - s;     for (long long i = 0; i < (K); i++) ans[i] *= G;     for (long long i = 0; i < (K); i++) {       if (i) cout <<    ;       cout << ans[i];     }     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   int a[100002];   int mini[100002][21];   vector<pair<int, int> > vp;   int f(int l, int r, int m) {     if (l == r) {       for (int i = 0; i < a[l] - m; i++) {         vp.push_back(make_pair(l, r));       }       return a[l] - m;     }     int i = 0;     for (i = 0;; i++)       if (l + (1 << i) > r) break;     int minIndex = -1;     if (a[mini[l][i - 1]] < a[mini[r - (1 << (i - 1)) + 1][i - 1]]) {       minIndex = mini[l][i - 1];     } else {       minIndex = mini[r - (1 << (i - 1)) + 1][i - 1];     }     for (int i = 0; i < a[minIndex] - m; i++) {       vp.push_back(make_pair(l, r));     }     if (minIndex == l) {       return a[minIndex] - m + f(l + 1, r, a[minIndex]);     }     if (minIndex == r) {       return a[minIndex] - m + f(l, r - 1, a[minIndex]);     } else {       return a[minIndex] - m + f(l, minIndex - 1, a[minIndex]) +              f(minIndex + 1, r, a[minIndex]);     }   }   int main() {     cout << setprecision(9);     cin >> n;     for (int i = 0; i < n; i++) cin >> a[i];     for (int i = 0; i < n; i++) mini[i][0] = i;     for (int i = 1; i < 21; i++) {       for (int j = 0; j + (1 << i) - 1 < n; j++) {         if (a[mini[j][i - 1]] < a[mini[j + (1 << (i - 1))][i - 1]]) {           mini[j][i] = mini[j][i - 1];         } else {           mini[j][i] = mini[j + (1 << (i - 1))][i - 1];         }       }     }     cout << f(0, n - 1, 0) << endl;     for (int i = 0; i < vp.size(); i++)       cout << 1 + vp[i].first <<     << 1 + vp[i].second << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct custom_hash {     static uint64_t splitmix64(uint64_t x) {       x += 0x9e3779b97f4a7c15;       x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;       x = (x ^ (x >> 27)) * 0x94d049bb133111eb;       return x ^ (x >> 31);     }     size_t operator()(uint64_t x) const {       static const uint64_t FIXED_RANDOM =           chrono::steady_clock::now().time_since_epoch().count();       return splitmix64(x + FIXED_RANDOM);     }   };   const int maxn = 2e5 + 5;   const long long mod = 1e9 + 7;   long long gcd(long long a, long long b) {     if (!b) return a;     return gcd(b, a % b);   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int n;     cin >> n;     long long maxl = 1e18 + 2;     for (int i = 0; i < n; i++) {       long long p, q, b;       cin >> p >> q >> b;       if (p % q == 0) {         cout <<  Finite  << endl;         continue;       }       long long g = gcd(p, q);       p /= g;       q /= g;       while (true) {         if (q == 1) {           cout <<  Finite  << endl;           break;         }         g = gcd(b, q);         if (g == 1) {           cout <<  Infinite  << endl;           break;         }         q /= g;         b = g;       }     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n;     for (int k = 0; k < n; k++) {       cin >> m;       for (int i = 0; i < m / 2; i++) {         int fir, sec;         cin >> fir >> sec;         if (fir > 0 && sec > 0) {           cout << sec <<     << -fir <<    ;         } else if (fir < 0 && sec < 0) {           cout << -sec <<     << fir <<    ;         } else if (fir > 0 && sec < 0) {           cout << -sec <<     << fir <<    ;         } else if (fir < 0 && sec > 0) {           cout << sec <<     << -fir <<    ;         }       }       cout << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   const int N = 100010;   int n;   char s[N], t[N];   bitset<N> c[30], ans;   int main() {     scanf( %s%d , s + 1, &n);     for (int i = 1, _ = strlen(s + 1); i <= _; i++) c[s[i] -  a ][i] = 1;     int op, x, y;     while (n--) {       scanf( %d , &op);       if (op == 1) {         scanf( %d%s , &x, t + 1);         c[s[x] -  a ].reset(x);         s[x] = t[1];         c[s[x] -  a ].set(x);       } else {         scanf( %d%d%s , &x, &y, t + 1);         int len = strlen(t + 1);         ans.set();         y = y - len + 1;         for (int i = 1; i <= len; i++) ans &= c[t[i] -  a ] >> (i - 1);         printf( %d n ,                max(0, (int)((ans >> x).count() - (ans >> (y + 1)).count())));       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long MAXN = 1000005;   long long pw(long long b, long long r, long long md) {     long long ans = 1;     while (r) {       if (r & 1) ans = (ans * b) % md;       b = (b * b) % md;       r >>= 1;     }     return ans;   }   bool cmp(pair<long long, long long> a, pair<long long, long long> b) {     if (a.first == b.first) return a.second < b.second;     return a.first > b.first;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long n, m, k;     cin >> n >> m >> k;     long long dp[n][k + 1];     for (long long i = 0; i <= n - 1; ++i)       for (long long j = 0; j <= k; ++j) dp[i][j] = -1e18;     long long arr[n];     for (long long i = 0; i <= n - 1; ++i) cin >> arr[i];     long long pref[n];     pref[0] = arr[0];     for (long long i = 1; i <= n - 1; ++i) pref[i] = pref[i - 1] + arr[i];     for (long long i = 0; i <= n - 1; ++i) dp[i][0] = 0;     dp[m - 1][1] = pref[m - 1];     long long ans = 0;     for (long long i = m; i <= n - 1; ++i) {       for (long long j = 0; j <= k; ++j) {         dp[i][j] = dp[i - 1][j];         if (j == 0) continue;         dp[i][j] = max(dp[i][j], dp[i - m][j - 1] + pref[i] - pref[i - m]);       }     }     for (long long i = 0; i <= n - 1; ++i) ans = max(ans, dp[i][k]);     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int x[200005], y[200005], z[200005];   long long a[200005], b[200005];   int main() {     long long n, t;     cin >> n >> t;     x[0] = 0;     for (int i = 1; i <= n; i++) {       cin >> a[i];       y[i] = 0;     }     for (int i = 1; i <= n; i++) {       cin >> x[i];       y[x[i]]++;       z[x[i]] = i;     }     for (int i = 1; i <= n; i++) {       if ((x[i] < i) || (x[i] < x[i - 1])) {         cout <<  No  << endl;         return 0;       }       if (y[i] > 0 && z[i] != i) {         cout <<  No  << endl;         return 0;       }     }     if (x[n] != n) {       cout <<  No  << endl;       return 0;     }     for (int i = 1; i < n; i++)       if ((a[i + 1] == (a[i] + 1)) && x[i + 1] != x[i] && y[x[i]] > 1) {         cout <<  No  << endl;         return 0;       }     for (int i = 1; i <= n; i++) {       int m = z[i];       if (y[i] == 1)         b[m] = a[m] + t;       else {         for (int j = 0; j < y[i]; j++) b[m - j] = a[m] + t + 1LL - j;       }     }     cout <<  Yes  << endl;     for (int i = 1; i <= n; i++) cout << b[i] <<    ;     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ull = unsigned long long;   using pii = pair<int, int>;   using pll = pair<ll, ll>;   template <class T>   inline bool Min(T &a, T b) {     return a > b ? (a = b, true) : false;   }   template <class T>   inline bool Max(T &a, T b) {     return a < b ? (a = b, true) : false;   }   inline int ni() {     int a;     scanf( %d , &a);     return a;   }   inline ll nl() {     ll a;     scanf( %lld , &a);     return a;   }   inline double nd() {     double a;     scanf( %lf , &a);     return a;   }   inline void pi(int a) { printf( %d  , a); }   inline void pl(ll a) { printf( %lld  , a); }   inline void pd(double a) { printf( %.12lf  , a); }   const int N = 1e5 + 10;   using ld = long double;   void solve() {     ld x, y, z;     cin >> x >> y >> z;     ld ans[10];     ans[1] = log(x) * pow(y, z);     ans[2] = log(x) * pow(z, y);     ans[3] = log(x) * y * z;     ans[4] = log(y) * pow(x, z);     ans[5] = log(y) * pow(z, x);     ans[6] = log(y) * x * z;     ans[7] = log(z) * pow(x, y);     ans[8] = log(z) * pow(y, x);     ans[9] = log(z) * x * y;     ans[0] = ans[1];     int t = 1;     for (int i = 1; i <= 9; i++)       if (Max(ans[0], ans[i])) t = i;     if (t == 1) puts( x^y^z );     if (t == 2) puts( x^z^y );     if (t == 3) puts( (x^y)^z );     if (t == 4) puts( y^x^z );     if (t == 5) puts( y^z^x );     if (t == 6) puts( (y^x)^z );     if (t == 7) puts( z^x^y );     if (t == 8) puts( z^y^x );     if (t == 9) puts( (z^x)^y );   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int powm[100005];   int fact[100005];   int sum[100005];   string s;   void powers_of_10(int m) {     powm[0] = 1;     for (int i = 1; i <= m; i++) powm[i] = 1LL * powm[i - 1] * 10 % 1000000007;   }   void factorials(int m) {     fact[0] = 1;     for (int i = 1; i <= m; i++) fact[i] = 1LL * i * fact[i - 1] % 1000000007;   }   void sums(int m) {     sum[0] = s[0] -  0 ;     for (int i = 1; i < m; i++) {       sum[i] = sum[i - 1] + (s[i] -  0 );       if (sum[i] >= 1000000007) sum[i] -= 1000000007;     }   }   void euclid(int a, int b, long long& x, long long& y) {     if (b == 0) {       x = 1;       y = 0;     } else {       long long x0, y0;       euclid(b, a % b, x0, y0);       x = y0;       y = x0 - (a / b) * y0;     }   }   int invers_modular(int n) {     long long x, y;     euclid(n, 1000000007, x, y);     while (x < 0) x += 1000000007;     return (int)x;   }   int comb(int n, int k) {     if (k > n) return 0;     int Ret = fact[n];     Ret = 1LL * Ret * invers_modular(fact[n - k]) % 1000000007;     Ret = 1LL * Ret * invers_modular(fact[k]) % 1000000007;     return Ret;   }   int main() {     ios_base::sync_with_stdio(false);     int n, k;     cin >> n >> k;     cin >> s;     powers_of_10(n);     factorials(n);     sums(n);     int FirstSum = 0;     int SecondSum = 0;     for (int i = 0; i < n; i++) {       FirstSum += 1LL * (s[i] -  0 ) * powm[n - 1 - i] * comb(i, k) % 1000000007;       if (FirstSum >= 1000000007) FirstSum -= 1000000007;     }     for (int i = 0; i <= n - 2; i++) {       SecondSum += 1LL * (1LL * sum[n - i - 2] * powm[i] % 1000000007) *                    comb(n - i - 2, k - 1) % 1000000007;       if (SecondSum >= 1000000007) SecondSum -= 1000000007;     }     cout << (SecondSum + FirstSum) % 1000000007;   }
#include <bits/stdc++.h>   using namespace std;   inline char gc() {     static char buf[100000], *p1 = buf, *p2 = buf;     return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2)                ? EOF                : *p1++;   }   inline long long read() {     long long x = 0;     char ch = getchar();     bool positive = 1;     for (; !isdigit(ch); ch = getchar())       if (ch ==  - ) positive = 0;     for (; isdigit(ch); ch = getchar()) x = x * 10 + ch -  0 ;     return positive ? x : -x;   }   inline void write(long long a) {     if (a < 0) {       a = -a;       putchar( - );     }     if (a >= 10) write(a / 10);     putchar( 0  + a % 10);   }   inline void writeln(long long a) {     write(a);     puts(  );   }   inline void wri(long long a) {     write(a);     putchar(   );   }   long long t, l, r;   long long dp[35][2][2];   long long calc(long long x, long long y) {     if (x < 0 || y < 0) return 0;     memset(dp, 0, sizeof(dp));     dp[32][1][1] = 1;     for (long long i = 31; i >= 0; i--) {       for (int j = 0; j <= 1; j++) {         for (int k = 0; k <= 1; k++) {           long long nextj = (j && !((x >> i) & 1));           long long nextk = (k && !((y >> i) & 1));           dp[i][nextj][nextk] += dp[i + 1][j][k];           if (!j || ((x >> i) & 1)) dp[i][j][nextk] += dp[i + 1][j][k];           if (!k || ((y >> i) & 1)) dp[i][nextj][k] += dp[i + 1][j][k];         }       }     }     return dp[0][0][0] + dp[0][0][1] + dp[0][1][0] + dp[0][1][1];   }   int main() {     t = read();     while (t--) {       l = read(), r = read();       writeln(calc(r, r) - 2 * calc(l - 1, r) + calc(l - 1, l - 1));     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   static inline void WRITE(int a) { printf( %d n , a); }   static inline void WRITE2(int a, int b) { printf( %d %d n , a, b); }   const int S9 = 1000000007, S6 = 1000007, S5 = 100007, S4 = 10007, S3 = 1007,             S2 = 107;   const double E2 = 0.01, E4 = 0.0001, E6 = 0.000001, E8 = 0.00000001;   int tab[4][2];   int check() {     bool czy = false;     int ob = 0, at = 1;     if (tab[ob][0] > tab[2][1] && tab[at][1] > tab[3][0])       if (tab[ob][0] > tab[3][1] && tab[at][1] > tab[2][0]) return 1;     if ((tab[ob][0] < tab[2][1] && tab[at][1] < tab[3][0]) ||         (tab[ob][0] < tab[3][1] && tab[at][1] < tab[2][0]))       czy = true;     ob = 1;     at = 0;     if (tab[ob][0] > tab[2][1] && tab[at][1] > tab[3][0])       if (tab[ob][0] > tab[3][1] && tab[at][1] > tab[2][0]) return 1;     if (((tab[ob][0] < tab[2][1] && tab[at][1] < tab[3][0]) ||          (tab[ob][0] < tab[3][1] && tab[at][1] < tab[2][0])) &&         czy)       return 2;     return 0;   }   int main() {     for (int i = 0; i < 4; i++) scanf( %d%d , &tab[i][0], &tab[i][1]);     int x = check();     if (x == 0)       puts( Draw );     else       printf( Team %d n , x);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = (int)1010;   set<int> ans;   int n, m;   char a[MAXN][MAXN];   int posk[MAXN];   int posG[MAXN];   int main() {     cin >> n >> m;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         cin >> a[i][j];         if (a[i][j] ==  S ) {           posk[i] = j;         }         if (a[i][j] ==  G ) {           posG[i] = j;         }       }     }     for (int i = 0; i < n; i++) {       if (posG[i] > posk[i]) {         cout << -1;         return 0;       } else {         ans.insert((int)posG[i] - posk[i] + 1);       }     }     cout << ans.size();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct node {     bool flag = 0;     long long sum1 = 0, sum2 = 0;     void operator+=(const node& rhs) {       flag |= rhs.flag;       sum1 += rhs.sum1;       sum2 = max(sum2, rhs.sum2);     }   };   const int N = 200200;   int n, m, s, T;   int par[N], siz[N];   int tin[N], low[N];   long long a[N];   vector<int> edges[N], tree[N];   vector<pair<int, int>> bridges;   int findSetId(int u) { return (par[u] == u ? u : par[u] = findSetId(par[u])); }   void findBridges(int u = 1, int p = -1) {     tin[u] = low[u] = ++T;     for (int v : edges[u]) {       if (v == p) {         continue;       }       if (tin[v] == 0) {         findBridges(v, u);         if (low[v] > tin[u]) {           bridges.push_back({u, v});         } else {           int x = findSetId(u);           int y = findSetId(v);           if (x != y) {             par[y] = x;             siz[x] += siz[y];             a[x] += a[y];           }         }       }       low[u] = min(low[u], low[v]);     }   }   void buildBridgeTree() {     for (int i = 1; i <= n; ++i) {       par[i] = i, siz[i] = 1;     }     findBridges();     for (auto& b : bridges) {       int u = findSetId(b.first);       int v = findSetId(b.second);       tree[u].push_back(v);       tree[v].push_back(u);     }   }   node solve(int u = s, int p = -1) {     node ret;     for (int v : tree[u]) {       if (v == p) {         continue;       }       ret += solve(v, u);     }     if (siz[u] > 1 || ret.flag) {       ret.sum1 += a[u], ret.flag = 1;     } else {       ret.sum2 += a[u];     }     return ret;   }   int main() {     cin >> n >> m;     for (int i = 1; i <= n; ++i) {       scanf( %lld , a + i);     }     while (m--) {       int u, v;       scanf( %d %d , &u, &v);       edges[u].push_back(v);       edges[v].push_back(u);     }     cin >> s;     buildBridgeTree();     auto out = solve(findSetId(s));     cout << out.sum1 + out.sum2;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long double n;     cin >> n;     if (n <= 127) {       cout <<  byte ;     } else if (n <= 32767) {       cout <<  short ;     } else if (n <= 2147483647) {       cout <<  int ;     } else if (n <= 9223372036854775807LL) {       cout <<  long ;     } else {       cout <<  BigInteger ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     std::ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long int t;     cin >> t;     while (t--) {       long long int n;       cin >> n;       if (n <= 6)         cout << 15 << endl;       else {         long long int r = n % 6;         long long int y = ((n - r - 6) / 6) * 15;         if (r != 0) long long int y = ((n - r - 6) / 6) * 15;         if (r + 6 <= 6)           y = y + 15;         else if (r + 6 <= 8)           y = y + 20;         else if (r + 6 <= 10)           y = y + 25;         else           y = y + 30;         cout << y << endl;       }     }   }
#include <bits/stdc++.h>   using namespace std;   char a[1005];   char b[1005];   int t[1005];   int sum[1005];   int main() {     memset(t, 0, sizeof(t));     int p, n, m;     cin >> n >> m >> p;     cin >> a >> b;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (a[i + j] != b[j])           break;         else if (j == m - 1)           t[i] = 1;       }     }     sum[0] = t[0];     for (int i = 1; i < n; i++) sum[i] = sum[i - 1] + t[i];     while (p--) {       int l, r;       scanf( %d%d , &l, &r);       l--, r--;       if (n < m || r - l + 1 < m)         cout << 0 << endl;       else         cout << sum[r - m + 1] - sum[l - 1] << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 200006;   int a[MAXN], b[MAXN];   int N;   int main() {     while (scanf( %d , &N) != EOF) {       int i, j;       int x;       int n = 0, m = 0;       long long suma = 0, sumb = 0;       int win = 0;       int last;       for (i = 1; i <= N; i++) {         scanf( %d , &x);         if (x > 0) {           a[++n] = x;           suma += x;           last = 1;         } else {           b[++m] = -x;           sumb += (-x);           last = 2;         }       }       if (suma > sumb)         win = 1;       else if (suma < sumb)         win = 2;       else {         for (i = 1, j = 1; i <= n && j <= m; i++, j++) {           if (a[i] > b[j]) {             win = 1;             break;           } else if (a[i] < b[j]) {             win = 2;             break;           }         }         if (i > n && j > m)           win = last;         else if (i > n && j <= m)           win = 2;         else if (i <= n && j > m)           win = 1;       }       if (win == 1)         printf( first n );       else if (win == 2)         printf( second n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const double eps = 1e-6;   const int MAXN = 1e5 + 10;   const int MAXM = 1e6 + 10;   const long long mod = 1e9 + 7;   int a[1010];   int main() {     int n;     scanf( %d , &n);     for (int i = 0; i < n; i++) scanf( %d , &a[i]);     int ans = 0;     for (int i = 1; i < n - 1; i++) {       if (a[i] > a[i - 1] && a[i] > a[i + 1]) ans++;       if (a[i] < a[i - 1] && a[i] < a[i + 1]) ans++;     }     printf( %d n , ans);     return 0;   }