malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   const int inf = 0x7FFFFFFF;   using namespace std;   int dep[2014], shortcut[20][2014];   struct Edge {     int u, v, w;     bool operator<(const Edge &A) const { return w < A.w; }   } E[4000005];   int mp[2014][2014];   int fa[2014], d[2014];   int find(int x) { return x == fa[x] ? x : fa[x] = find(fa[x]); }   vector<int> G[2014], Q;   int get_lca(int a, int b) {     if (dep[a] < dep[b]) swap(a, b);     for (int i = 20 - 1; i >= 0; i--) {       if (dep[a] - dep[b] >> i & 1) {         a = shortcut[i][a];       }     }     if (a == b) return a;     for (int i = 20 - 1; i >= 0; i--) {       if (shortcut[i][a] != shortcut[i][b]) {         a = shortcut[i][a];         b = shortcut[i][b];       }     }     return shortcut[0][a];   }   int main() {     int N;     scanf( %d , &N);     for (int i = 1; i <= N; i++)       for (int j = 1; j <= N; j++) scanf( %d , &mp[i][j]);     int tot = 0;     for (int i = 1; i <= N; i++)       for (int j = i + 1; j <= N; j++) {         E[tot].u = i;         E[tot].v = j;         E[tot].w = mp[i][j];         tot++;       }     sort(E, E + tot);     for (int i = 1; i <= N; i++) fa[i] = i;     for (int i = 0; i < tot; i++) {       int u = E[i].u;       int v = E[i].v;       if (find(u) != find(v)) {         fa[find(u)] = find(v);         G[u].push_back(v);         G[u].push_back(E[i].w);         G[v].push_back(u);         G[v].push_back(E[i].w);       }     }     int *parent = shortcut[0];     d[1] = 0;     parent[1] = -1;     dep[1] = 0;     Q.push_back(1);     for (int head = 0; head < int(Q.size()); head++) {       int u = Q[head];       for (int i = 0; i < int(G[u].size()); i += 2) {         int v = G[u][i];         int w = G[u][i + 1];         if (v != parent[u]) {           parent[v] = u;           dep[v] = dep[u] + 1;           d[v] = d[u] + w;           Q.push_back(v);         }       }     }     for (int i = 1; i < 20; i++) {       for (int j = 1; j <= N; j++) {         int &res = shortcut[i][j];         res = shortcut[i - 1][j];         if (~res) {           res = shortcut[i - 1][res];         }       }     }     bool ok = true;     int num = 0;     for (int i = 1; i <= N; i++)       if (fa[i] == i) num++;     if (num > 1) ok = false;     for (int u = 1; ok && u <= N; u++) {       if (mp[u][u] != 0) ok = false;       for (int v = u + 1; ok && v <= N; v++) {         if (mp[u][v] != mp[v][u]) ok = false;         if (mp[u][v] == 0) ok = false;         int mid = get_lca(u, v);         if (d[u] + d[v] - d[mid] * 2 != mp[u][v]) ok = false;       }     }     puts(ok ?  YES  :  NO );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long inf = 1e18;   const long long mod = 1e9 + 7;   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     long long q;     cin >> q;     ;     for (long long i = (1); i <= (q); i++) {       long long n;       cin >> n;       ;       long long r;       cin >> r;       ;       set<long long, greater<long long>> s;       for (long long i = (1); i <= (n); i++) {         long long x;         cin >> x;         ;         s.insert(x);       }       long long k = 0, st = 0;       for (long long j : s) {         if (j - r * k <= 0) {           cout << k <<   n ;           st = 1;           break;         }         k++;       }       if (!st) cout << k <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   const int mx = 2e5 + 10;   long long x[mx], y[mx];   ifstream fin( input.txt );   ofstream fout( output.txt );   long long sum[5];   int main() {     string b;     cin >> b;     int x = 0, y = 0;     for (int i = 0; i < b.size(); i++) {       if (b[i] ==  x )         x++;       else         y++;     }     if (x > y) {       for (int i = 1; i <= x - y; i++) cout <<  x ;       return 0;     }     for (int i = 1; i <= y - x; i++) cout <<  y ;   }
#include <bits/stdc++.h>   const long long INFLL = 1e18;   using namespace std;   const int MAXN = 2 * 100000;   const int INF = 1000 * 1000 * 1000;   int a[MAXN + 1], used[MAXN + 10];   int main() {     int n;     scanf( %d , &n);     int ans = 1;     for (int i = 0; i < n; i++) {       scanf( %d , &a[i]);       if (used[a[i]]) {         ans++;       }       used[a[i]] = 1;     }     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<vector<int>> segT;   vector<int> lazy;   long long n, m, l, r;   string s;   void buildT(int ss, int se, int si) {     if (ss == se) {       if (s[ss] ==  4 )         segT[si][0] = 1;       else         segT[si][1] = 1;       segT[si][2] = 1;       segT[si][3] = 1;       return;     }     int mid = (ss + se) / 2;     buildT(ss, mid, 2 * si + 1);     buildT(mid + 1, se, 2 * si + 2);     segT[si][0] = segT[2 * si + 1][0] + segT[2 * si + 2][0];     segT[si][1] = segT[2 * si + 1][1] + segT[2 * si + 2][1];     segT[si][2] = max(segT[2 * si + 1][2] + segT[2 * si + 2][1],                       segT[2 * si + 1][0] + segT[2 * si + 2][2]);     segT[si][3] = max(segT[2 * si + 1][3] + segT[2 * si + 2][0],                       segT[2 * si + 1][1] + segT[2 * si + 2][3]);   }   void upd(int ss, int se, int si) {     if (lazy[si] == 1) {       swap(segT[si][0], segT[si][1]);       swap(segT[si][2], segT[si][3]);       if (ss != se) {         lazy[2 * si + 1] ^= 1;         lazy[2 * si + 2] ^= 1;       }       lazy[si] = 0;     }     if (r < ss || l > se) return;     if (ss >= l && se <= r) {       swap(segT[si][0], segT[si][1]);       swap(segT[si][2], segT[si][3]);       if (ss != se) {         lazy[2 * si + 1] ^= 1;         lazy[2 * si + 2] ^= 1;       }       return;     }     int mid = (ss + se) / 2;     upd(ss, mid, 2 * si + 1);     upd(mid + 1, se, 2 * si + 2);     segT[si][0] = segT[2 * si + 1][0] + segT[2 * si + 2][0];     segT[si][1] = segT[2 * si + 1][1] + segT[2 * si + 2][1];     segT[si][2] = max(segT[2 * si + 1][2] + segT[2 * si + 2][1],                       segT[2 * si + 1][0] + segT[2 * si + 2][2]);     segT[si][3] = max(segT[2 * si + 1][3] + segT[2 * si + 2][0],                       segT[2 * si + 1][1] + segT[2 * si + 2][3]);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int i, j;     cin >> n >> m;     cin >> s;     long long lim = 2 * pow(2, ceil(log(n) / log(2.0))) + 2;     vector<int> temp(lim, 0);     vector<vector<int>> temp2(lim, vector<int>(4, 0));     segT = temp2;     lazy = temp;     buildT(0, n - 1, 0);     string typ;     for (i = 0; i < m; i++) {       cin >> typ;       if (typ.compare( switch ) == 0) {         cin >> l >> r;         l -= 1;         r -= 1;         upd(0, n - 1, 0);       } else {         if (lazy[0] == 1)           cout << segT[0][3] << endl;         else           cout << segT[0][2] << endl;       }     }   }
#include <bits/stdc++.h>   using namespace ::std;   int main() {     long long int temp, q, v1, v2, t, d, i, sum = 0;     cin >> v1 >> v2 >> t >> d;     long long int a[t];     sum = d * (t - 1);     i = 0;     temp = 0;     bool ff = false;     while (1) {       if (!ff) {         i += v1;         a[temp] = i;         temp++;         ff = true;         continue;       } else if (i + d - sum + d <= v2) {         i += d;         sum -= d;         a[temp] = i;       } else {         for (long long int k = d - 1; k >= -d; k--) {           if (i + k - sum + d <= v2) {             i += k;             sum -= d;             a[temp] = i;             break;           }         }       }       temp++;       if (temp == t) break;     }     long long int s = 0;     for (long long int j = 0; j < t; j++) s += a[j];     cout << s;   }
#include <bits/stdc++.h>   using namespace std;   const long long N = 1e6 + 1e5, inf = 3e18, mod = 1e9 + 7;   long long tc, n, m, q, a, b, c, d, i, j, k;   long long A[N];   vector<long long> vec;   string s;   int main() {     ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);     cin >> tc;     while (tc--) {       cin >> n >> m;       long long flag1 = 0, flag2 = 0;       for (i = 2; i < n + 2; i++) {         cin >> A[i];         if (A[i] == m) flag1 = 1;         if (A[i] >= m && (A[i - 1] >= m || A[i - 2] >= m)) flag2 = 1;       }       if (flag1 && flag2 || (n == 1 && A[2] == m))         cout <<  yes n ;       else         cout <<  no n ;     }   }
#include <bits/stdc++.h>   using namespace std;   const long long int N = 2e5 + 5;   void solve() {     long long int n;     cin >> n;     double ans, pi = 3.14159265358979323846;     double rad = (2.0 * sin(pi / (2.0 * (double)n)));     ans = (cos(pi / (4.0 * n))) / sin(pi / (2.0 * (double)n));     cout << fixed << setprecision(15) << ans <<   n ;   }   signed main() {     ios_base::sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL);     long long int t = 1;     cin >> t;     while (t--) {       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, l[10], r[10], t = 1;     double ans = 0, o = 1;     cin >> n;     for (int i = 0; i < n; i++) {       t *= 2;       cin >> l[i] >> r[i];       o *= r[i] - l[i] + 1;     }     if (n == 1) {       cout << setprecision(10) << fixed << (r[0] + l[0]) / 2.0 << endl;       return 0;     }     for (int i = 1; i <= 10000; i++) {       for (int g = 0; g < n; g++) {         if (r[g] <= i) continue;         for (int j = 1; j < t; j++) {           int a[10] = {}, t2 = j, o = 0;           while (t2) {             a[o++] = t2 % 2;             t2 /= 2;           }           if (a[g]) continue;           double k = 1;           bool ch = 0;           for (int h = 0; h < n; h++) {             if (h == g) continue;             if (a[h] && (r[h] < i || l[h] > i)) {               ch = 1;               h = n;             }             if (!a[h] && l[h] >= i) {               ch = 1;               h = n;             }             if (!a[h]) k *= min(i - 1, r[h]) - l[h] + 1;           }           if (ch) continue;           k *= r[g] - max(i + 1, l[g]) + 1;           ans += k * i;         }       }     }     for (int i = 1; i <= 10000; i++) {       for (int j = 1; j < t; j++) {         int a[10] = {}, t2 = j, o = 0, d = 0;         while (t2) {           a[o++] = t2 % 2;           if (a[o - 1]) d++;           t2 /= 2;         }         double k = 1;         if (d == 1) continue;         bool ch = 0;         for (int h = 0; h < n; h++) {           if (a[h] && (r[h] < i || l[h] > i)) {             ch = 1;             h = n;           }           if (!a[h] && l[h] >= i) {             ch = 1;             h = n;           }           if (!a[h]) k *= min(i - 1, r[h]) - l[h] + 1;         }         if (ch) continue;         ans += k * i;       }     }     cout << setprecision(10) << fixed << ans / o << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   template <class T>   inline T read() {     T x = 0, f = 1;     char s = getchar();     while (s <  0  || s >  9 ) {       if (s ==  - ) f = -1;       s = getchar();     };     while (s >=  0  && s <=  9 ) {       x = (x << 3) + (x << 1) + s - 48;       s = getchar();     };     return x * f;   }   template <typename T>   inline void wri(T x) {     if (x < 0) {       x = -x;       putchar( - );     };     if (x / 10) wri(x / 10);     putchar(x % 10 + 48);   }   template <typename T>   inline void print(T x, char s) {     wri(x);     putchar(s);   }   struct node {     int l, r, val, add;   } e[800010];   int a[200010], ans[200010];   void build_tree(int node, int start, int end) {     e[node].l = start, e[node].r = end;     if (start == end) {       e[node].add = 0;       e[node].val = a[start];       return;     }     int mid = (start + end) >> 1;     build_tree(node << 1, start, mid), build_tree(node << 1 | 1, mid + 1, end);   }   void update(int x, int q, int val) {     if (e[x].l == q && e[x].r == q) {       e[x].val = val, e[x].add = 0;       return;     }     int mid = (e[x].l + e[x].r) >> 1;     e[x << 1].add = max(e[x << 1].add, e[x].add);     e[x << 1 | 1].add = max(e[x << 1 | 1].add, e[x].add);     e[x].add = 0;     if (q <= mid)       update(x << 1, q, val);     else       update(x << 1 | 1, q, val);   }   void query(int x) {     if (e[x].l == e[x].r) {       ans[e[x].l] = max(e[x].val, e[x].add);       return;     }     e[x << 1].add = max(e[x << 1].add, e[x].add);     e[x << 1 | 1].add = max(e[x << 1 | 1].add, e[x].add);     query(x << 1), query(x << 1 | 1);   }   int main() {     int n;     n = read<int>();     for (register int i = (1); i < (n + 1); i++) a[i] = read<int>();     build_tree(1, 1, n);     int q;     q = read<int>();     while (q--) {       int x, y, z;       x = read<int>();       if (x == 1) {         y = read<int>(), z = read<int>();         update(1, y, z);       } else         y = read<int>(), e[1].add = max(e[1].add, y);     }     query(1);     for (register int i = (1); i < (n + 1); i++) print(ans[i],    );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int t;     cin >> t;     string cnv;     cnv.reserve(62);     for (char i =  a ; i <=  z ; ++i) {       cnv.push_back(i);     }     for (char i =  A ; i <=  Z ; ++i) {       cnv.push_back(i);     }     for (char i =  0 ; i <=  9 ; ++i) {       cnv.push_back(i);     }     for (int i = 0; i < t; ++i) {       int n, m, k;       cin >> n >> m >> k;       vector<string> mas(n);       int cnt = 0;       for (int j = 0; j < n; ++j) {         cin >> mas[j];         for (char c : mas[j]) {           cnt += (c ==  R );         }       }       int cur = 0;       int perc = cnt / k;       int bigger = cnt % k;       int curcnt = 0;       for (int i = 0; i < n; ++i) {         if (i & 1) {           for (int j = 0; j < m; ++j) {             if (mas[i][j] ==  R  && curcnt == perc + (cur < bigger)) {               ++cur;               curcnt = 0;             }             if (mas[i][j] ==  R ) ++curcnt;             mas[i][j] = cnv[cur];           }         } else {           for (int j = m - 1; j >= 0; --j) {             if (mas[i][j] ==  R  && curcnt == perc + (cur < bigger)) {               ++cur;               curcnt = 0;             }             if (mas[i][j] ==  R ) ++curcnt;             mas[i][j] = cnv[cur];           }         }       }       for (int i = 0; i < n; ++i) {         cout << mas[i] <<   n ;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, k, l[50 + 1];   void Answer() {     int j = 1, s = n;     for (int i = 1; i <= k; i++) {       if (i > s) s += n - (++j) + 1;       cout << j <<    ;       for (int u = n - 1; u > n - j; u--) cout << l[u] <<    ;       cout << l[s - i] << endl;     }   }   int main() {     cin >> n >> k;     for (int i = 0; i < n; i++) cin >> l[i];     sort(l, l + n);     Answer();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   double cal(int n, int *a, double x) {     double ret = 0, t1 = 0, t2 = 0;     for (int i = 0; i < n; i++) {       t1 += a[i] - x;       t2 += a[i] - x;       t1 = max(0., t1);       t2 = min(0., t2);       ret = max(ret, t1);       ret = max(ret, -t2);     }     return ret;   }   int main() {     int n;     scanf( %d , &n);     static int a[200000];     for (int i = 0; i < n; i++) {       scanf( %d , a + i);     }     double l = -10001, r = 10001, ans;     for (int t = 0; t < 100; t++) {       double d1 = (2 * l + r) / 3, d2 = (l + 2 * r) / 3;       double e1 = cal(n, a, d1), e2 = cal(n, a, d2);       if (e1 <= e2) {         r = d2;         ans = e1;       } else {         l = d1;         ans = e2;       }     }     printf( %.9lf n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1005;   char g[N][N];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int t;     cin >> t;     while (t--) {       long double h, c, t;       cin >> h >> c >> t;       if (t >= h) {         cout <<  1 n ;         continue;       }       if ((h + c) / 2 >= t) {         cout <<  2 n ;         continue;       }       int x = 0;       x = (h - t) / (2 * t - h - c);       long double curd = 100000000.0;       int res = -1;       for (int i = max(0, x - 50); i <= x + 50; ++i) {         long double xx = (i + 1) * h + i * c;         xx = 1.0 * xx / (2 * i + 1);         xx = abs(xx - t);         if (xx < curd) {           curd = xx;           res = i;         }       }       cout << 2 * res + 1 <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   int Day12[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};   int prime100[] = {2,  3,  5,  7,  11, 13, 17, 19, 23, 29, 31, 37,  41, 43,                     47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103};   template <typename T>   inline bool isLeap(T y) {     return (y % 400 == 0) || (y % 100 ? y % 4 == 0 : false);   }   template <typename T>   inline T GCD(T a, T b) {     a = abs(a);     b = abs(b);     if (a < b) swap(a, b);     while (b) {       a = a % b;       swap(a, b);     }     return a;   }   template <typename T>   inline T LCM(T x, T y) {     T tp = GCD(x, y);     if ((x / tp) * 1. * y > 9e18) return 9e18;     return (x / tp) * y;   }   template <typename T>   inline T BIGMOD(T A, T B, T M = 1000000007) {     T ret = 1;     while (B) {       if (B & 1) ret = (ret * A) % M;       A = (A * A) % M;       B = B >> 1;     }     return ret;   }   template <typename T>   inline T BigMod(T A, T B, T M) {     T ret = 1;     while (B) {       if (B & 1) ret = (ret * A) % M;       A = (A * A) % M;       B = B >> 1;     }     return ret;   }   long long int MySqrt(long long int n) {     long long int p = sqrt(n);     if ((p + 1) * (p + 1) <= n)       return p + 1;     else if (p * p <= n)       return p;     else       return p - 1;   }   long long int MyPow(long long int x, long long int n) {     if (n == 0)       return 1;     else if (n % 2 == 0)       return MyPow(x * x, n / 2);     else       return x * MyPow(x * x, ((n - 1) / 2));   }   long long int modInverse(long long int n) {     return BIGMOD(n, (long long int)1000000007 - 2) % 1000000007;   }   void solve() {     long long int ans = 1, n;     cin >> n;     if (n % 2 == 1)       printf( 0 n );     else {       n /= 2;       for (int i = 1; i <= n; i++) ans *= 2;       printf( %lld n , ans);     }   }   char arr[505][505];   int Left[505][505];   int Right[505][505];   int Up[505][505];   int Low[505][505];   void Now() {     int n, m, cnt = 0;     cin >> n >> m;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         cin >> arr[i][j];         if (arr[i][j] ==  * ) cnt++;       }     }     for (int i = 1; i < n; i++) {       for (int j = 0; j < m; j++) {         if (arr[i - 1][j] ==  * ) Up[i][j] += 1 + Up[i - 1][j];       }     }     for (int i = 0; i < n; i++) {       for (int j = 1; j < m; j++) {         if (arr[i][j - 1] ==  * ) Left[i][j] += 1 + Left[i][j - 1];       }     }     for (int i = n - 1; i >= 0; i--) {       for (int j = m - 2; j >= 0; j--) {         if (arr[i][j + 1] ==  * ) Right[i][j] += 1 + Right[i][j + 1];       }     }     for (int i = n - 2; i >= 0; i--) {       for (int j = m - 1; j >= 0; j--) {         if (arr[i + 1][j] ==  * ) Low[i][j] += 1 + Low[i + 1][j];       }     }     for (int i = 1; i < n - 1; i++) {       for (int j = 1; j < m - 1; j++) {         if (Left[i][j] > 0 && Up[i][j] > 0 && Right[i][j] > 0 && Low[i][j] > 0 &&             arr[i][j] ==  * ) {           if (Left[i][j] + Up[i][j] + Right[i][j] + Low[i][j] + 1 == cnt) {             printf( YES n );             exit(0);           }         }       }     }     printf( NO n );   }   int main() { solve(); }
#include <bits/stdc++.h>   using namespace std;   void solve() {     int n, m;     int x, y;     int z = 1;     cin >> n >> m;     cin >> x >> y;     cout << x <<     << y <<   n ;     cout << 1 <<     << y <<   n ;     for (int i = 1; i <= n; i++) {       vector<pair<int, int>> v;       for (int j = 1; j <= m; j++) {         if ((i == x && j == y) || (i == 1 && j == y)) continue;         v.push_back({i, j});       }       if (z) {         reverse(v.begin(), v.end());       }       for (auto it : v) {         cout << it.first <<     << it.second <<   n ;       }       z ^= 1;     }   }   int main() {     ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 5;   int n, q, a[N], node[4 * N];   vector<int> pos[N];   void init(int i, int l, int r) {     if (l == r) {       node[i] = (a[l] == 0 ? 1e9 : a[l]);       return;     }     int m = (l + r) >> 1;     init(i << 1, l, m);     init(i << 1 | 1, m + 1, r);     node[i] = min(node[i << 1], node[i << 1 | 1]);   }   int get(int i, int l, int r, int a, int b) {     if (l > r || a > r || b < l) return (int)1e9;     if (a <= l && r <= b) return node[i];     int m = (l + r) >> 1;     return min(get(i << 1, l, m, a, b), get(i << 1 | 1, m + 1, r, a, b));   }   int main() {     scanf( %d %d , &n, &q);     bool f = false;     bool zero = false;     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);       if (a[i] == q) f = true;       if (a[i])         pos[a[i]].push_back(i);       else         zero = true;     }     if (!f && !zero) return !printf( NO );     init(1, 1, n);     for (int i = 1; i <= q; i++) {       if (pos[i].size() > 0) {         if (get(1, 1, n, pos[i][0], pos[i][pos[i].size() - 1]) < i)           return !printf( NO );       }     }     puts( YES );     int l = 1;     while (l <= n) {       while (l <= n && a[l]) l++;       int r = l;       while (r <= n && !a[r]) r++;       if (l > 1) {         for (int j = l; j < r; j++) a[j] = f ? a[l - 1] : q;         if (!f) f = true;       } else if (r <= n) {         for (int j = l; j < r; j++) a[j] = f ? a[r] : q;         if (!f) f = true;       } else         for (int j = l; j < r; j++) a[j] = q;       l = r;     }     for (int i = 1; i <= n; i++) printf( %d  , a[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     long long a, f, sec, t = 0, h = 0;     cin >> a;     vector<long long> par;     vector<long long> m;     for (int i = 0; i < s.length(); i++) {       if (s[i - 1] == s[i]) {         h++;       }       par.push_back(h);     }     for (int i = 0; i < a; i++) {       cin >> f >> sec;       m.push_back(par[sec - 1] - par[f - 1]);     }     for (int i = 0; i < a; i++) {       cout << m[i] << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   long long dp[2];   void solve() {     long long n;     cin >> n;     for (int i = 0; i < n; i++) {       dp[i % 2] = dp[i % 2] + dp[!(i % 2)] + 1;       if (dp[i % 2] > 1000000007) dp[i % 2] %= 1000000007;     }     cout << (dp[0] + dp[1] + 1000000007) % (1000000007);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     ;     solve();   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, t;     cin >> n >> t;     int* time = new int[n];     for (int i = 0; i < n; i++) {       cin >> time[i];     }     int sum = 0, count = 0;     int ans = INT_MIN;     for (int i = 0; i < n; i++) {       if (sum + time[i] <= t) {         sum += time[i];         count++;       } else {         sum = sum - time[i - count] + time[i];       }       ans = max(ans, count);     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   vector<int> a;   int was[100100];   int t[100100];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n;     for (int i = 1; i <= 2 * n; i++) {       int x;       cin >> x;       a.push_back(x);     }     vector<int> ans;     int cnt = 0;     for (int i = 0; i < 2 * n; i++) {       if (!was[a[i]]) {         t[a[i]] = i;         ans.push_back(a[i]);         was[a[i]] = true;       } else {         was[a[i]] = true;         cnt += i - t[a[i]] - 1;         ans.insert(ans.begin() + t[a[i]] + 1, a[i]);         for (int j = 0; j < ans.size(); j++) {           t[ans[j]] = j;         }       }     }     cout << cnt;     return 0;   }