malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   template <class T>   bool umin(T& a, T b) {     if (a > b) {       a = b;       return 1;     }     return 0;   }   template <class T>   bool umax(T& a, T b) {     if (a < b) {       a = b;       return 1;     }     return 0;   }   int arr[100009], n, s[100009 << 2];   int M[2][100009][20], LOG[100009], s1, s2;   void upd(int l, int r, int nd, int x, int y) {     if (l > y or x > r) return;     if (l <= x and y <= r) {       s[nd] = 1;       return;     }     int mid = (x + y) >> 1;     upd(l, r, nd << 1, x, mid);     upd(l, r, nd << 1 | 1, mid + 1, y);   }   int tap(int p, int nd, int x, int y) {     if (x == y) return s[nd];     int mid = (x + y) >> 1;     if (p <= mid) return tap(p, nd << 1, x, mid) | s[nd];     return tap(p, nd << 1 | 1, mid + 1, y) | s[nd];   }   int get(int p, int l, int r) {     int k = LOG[r - l + 1];     if (!p) return max(M[0][l][k], M[0][r - (1 << k) + 1][k]);     return min(M[1][l][k], M[1][r - (1 << k) + 1][k]);   }   bool ok(int x, int y) {     memset(s, 0, sizeof s);     arr[0] = y;     for (int i = 0; i < n; i++) {       if (i and !tap(i, 1, 1, n)) continue;       int st = i + 1, en = n;       while (st + 1 < en) {         int mid = (st + en) >> 1;         int mx = get(0, i + 1, mid), mn = get(1, i + 1, mid);         if (abs(mx - arr[i]) <= x and abs(mn - arr[i]) <= x)           st = mid;         else           en = mid;       }       int mx = get(0, i + 1, en), mn = get(1, i + 1, en);       if (abs(mx - arr[i]) <= x and abs(mn - arr[i]) <= x)         upd(i + 1, en, 1, 1, n);       else if (abs(arr[i] - arr[i + 1]) <= x)         upd(i + 1, st, 1, 1, n);     }     return tap(n, 1, 1, n);   }   int main() {     scanf( %d%d%d , &n, &s1, &s2);     for (int i = 1; i <= n; i++) {       scanf( %d , arr + i);       M[0][i][0] = M[1][i][0] = arr[i];       LOG[i] = log2(i);     }     for (int j = 1; j <= 17; j++)       for (int i = 1; i <= n; i++) {         if (i + (1 << (j - 1)) <= n)           M[0][i][j] = max(M[0][i][j - 1], M[0][i + (1 << (j - 1))][j - 1]);         else           M[0][i][j] = M[0][i][j - 1];       }     for (int j = 1; j <= 17; j++)       for (int i = 1; i <= n; i++) {         if (i + (1 << (j - 1)) <= n)           M[1][i][j] = min(M[1][i][j - 1], M[1][i + (1 << (j - 1))][j - 1]);         else           M[1][i][j] = M[0][1][j - 1];       }     int st = abs(s1 - s2), en = 1e9;     while (st + 1 < en) {       int mid = (st + en) >> 1;       if (ok(mid, s1) or ok(mid, s2))         en = mid;       else         st = mid;     }     if (ok(st, s1) or ok(st, s2))       printf( %d n , st);     else       printf( %d n , en);     return 0;   }
#include <bits/stdc++.h>   int main(void) {     int a[101];     int b, c, d, i, j, count = 0, num, number;     scanf( %d %d , &b, &c);     for (i = 0; i < b; i++) {       scanf( %d , &a[i]);     }     for (i = 0; i < b - 1; i++) {       for (j = i + 1; j < b; j++) {         if (a[i] > a[j]) {           d = a[i];           a[i] = a[j];           a[j] = d;         }       }     }     for (i = 0; i < b; i++) {       num = 0;       number = 1;       for (j = i + 1; j < b; j++) {         num += a[j] - a[j - 1];         if (num > c) {           break;         } else {           number++;         }       }       if (number > count) {         count = number;       }     }     printf( %d n , b - count);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, k;   int a[(int)(1e6 + 10)], b[(int)(1e6 + 10)];   int c[(int)(1e6 + 10)];   int p[(int)(1e6 + 10)];   int rk[(int)(1e6 + 10)];   bool color[(int)(1e6 + 10)];   int find(int x) { return p[x] == x ? x : find(p[x]); }   void init() {     for (int i = 1; i <= 1e6; i++) p[i] = i, rk[i] = 1;   }   struct revo {     int px, py, rkx, rky;   };   stack<revo> st;   void merge(int x, int y) {     int px = find(x), py = find(y);     revo tmp = {px, py, rk[px], rk[py]};     st.push(tmp);     if (rk[px] > rk[py]) swap(px, py);     p[px] = py;     rk[py] = max(rk[py], rk[px] + 1);   }   void revocation(int k) {     while (k--) {       revo node = st.top();       st.pop();       p[node.px] = node.px;       p[node.py] = node.py;       rk[node.px] = node.rkx;       rk[node.py] = node.rky;     }   }   map<pair<int, int>, vector<pair<int, int> > > mp;   long long ans;   int main() {     ios::sync_with_stdio(0);     init();     cin >> n >> m >> k;     for (int i = 1; i <= n; i++) cin >> c[i];     for (int i = 1; i <= m; i++) cin >> a[i] >> b[i];     for (int i = 1; i <= m; i++) {       if (c[a[i]] == c[b[i]]) {         int x = find(a[i]), y = find(b[i]);         if (x != y)           merge(a[i], b[i] + n), merge(b[i], a[i] + n);         else           color[c[a[i]]] = 1;       }     }     for (int i = 1; i <= m; i++) {       if (c[a[i]] == c[b[i]]) continue;       if (color[c[a[i]]] || color[c[b[i]]]) continue;       if (c[a[i]] > c[b[i]]) swap(a[i], b[i]);       mp[{c[a[i]], c[b[i]]}].emplace_back(a[i], b[i]);     }     for (auto node : mp) {       int cnt = 0;       for (auto it : node.second) {         int x, y;         tie(x, y) = it;         int px = find(x), py = find(y);         if (px != py)           merge(x, y + n), merge(y, x + n), cnt += 2;         else {           ans--;           break;         }       }       revocation(cnt);     }     long long cnt = 0;     for (int i = 1; i <= k; i++)       if (!color[i]) cnt++;     ans += cnt * (cnt - 1) / 2;     cout << ans << endl;   }
#include <bits/stdc++.h>   const double EPS = 1e-9;   using namespace std;   template <class T>   inline T gcd(T a, T b) {     while (b) {       a %= b;       swap(a, b);     }     return a;   }   template <class T>   inline T lcm(T a, T b) {     return a / gcd(a, b) * b;   }   inline int nxt() {     int wow;     scanf( %d , &wow);     return wow;   }   inline long long int lxt() {     long long int wow;     scanf( %lld , &wow);     return wow;   }   inline double dxt() {     double wow;     scanf( %lf , &wow);     return wow;   }   bool comp(string xx, string yy) {     if (xx.length() == yy.length())       return xx < yy;     else       return xx.length() > yy.length();   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     map<string, vector<string>> phone, book;     set<string> st;     int n;     cin >> n;     for (int i = 0; i < n; i++) {       string s;       cin >> s;       st.insert(s);       int m;       cin >> m;       for (int i = 0; i < m; i++) {         string num;         cin >> num;         phone[s].push_back(num);       }     }     for (auto it = st.begin(); it != st.end(); ++it) {       sort(phone[*it].begin(), phone[*it].end(), comp);       for (int i = 0; i < phone[*it].size(); i++) {         bool dup = false;         for (int j = 0; j < book[*it].size(); j++) {           bool match = true;           for (int k = phone[*it][i].length() - 1, l = book[*it][j].length() - 1;                k >= 0; k--, l--) {             if (phone[*it][i][k] != book[*it][j][l]) match = false;           }           if (match == true) dup = true;         }         if (dup == false) book[*it].push_back(phone[*it][i]);       }     }     cout << st.size() << endl;     for (auto it = st.begin(); it != st.end(); ++it) {       cout << *it <<     << book[*it].size();       for (int i = 0; i < book[*it].size(); i++) cout <<     << book[*it][i];       cout << endl;     }     return 0;   }
#include <bits/stdc++.h>   int main() {     int n, i, x, k, j = 0;     scanf( %d%d , &n, &k);     for (i = 0; i < n; i++) {       for (x = 0; x < n; x++) {         if (i == j && x == j) {           printf( %d  , k);         } else           printf( 0  );       }       j++;       printf(  n );     }   }
#include <bits/stdc++.h>   using namespace std;   int n, a[200011], c[200011], isc[200011], cn, pow2[200011] = {1}, seen[200011];   int main() {     int ans = 1, mod = 1e9 + 7;     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , a + i);       pow2[i] = pow2[i - 1] * 2LL % mod;     }     for (int i = 1; i <= n; i++) {       if (seen[i] < 0) continue;       ++cn;       int j;       for (j = i; seen[j] >= 0; j = a[j]) seen[j] = -cn, ++c[cn];       if (seen[j] == -cn) isc[cn] = 1;       if (isc[cn]) {         int clen = 1;         for (int k = a[j]; seen[k] == -cn && k != j; k = a[k]) ++clen;         ans = (ans * 1LL * (pow2[clen] - 2 + mod) % mod) % mod;         ans = (ans * 1LL * pow2[c[cn] - clen]) % mod;       } else {         ans = (ans * 1LL * pow2[c[cn]]) % mod;       }     }     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> teams(200000);   int main() {     ios_base::sync_with_stdio(false);     int N;     cin >> N;     for (int i = 0; i < N; i++) cin >> teams[i];     for (int i = 0; i < N; i++) {       if (teams[i] == 0) {         continue;       }       if (teams[i] >= 2) {         teams[i] %= 2;       }       if (teams[i] == 1 && i != N - 1) {         teams[i + 1] -= 1;         teams[i] -= 1;       }       if (teams[i] != 0) {         cout <<  NO               <<   n ;         return 0;       }     }     cout <<  YES           <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int p = n + 1;     int cnt = 0;     cout << ((n + 1) * 3) + 1 << endl;     for (int i = 0; i < p; i++) {       cout << i <<     << i << endl;       cout << i + 1 <<     << i << endl;       cout << i <<     << i + 1 << endl;       cnt += 3;     }     cout << p <<     << p << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, s, i, j;     cin >> n >> m >> s;     long long ans = 0;     for (i = 1; i <= n; i += 2) {       for (j = 1; j <= m; j += 2) {         long long cnt = (n - i + 1) * (m - j + 1);         long long tmp = 0;         if (i * j == s) {           tmp = (i + 1) / 2 * (j + 1) / 2;           ans += cnt * (tmp * 2 - 1);         }         if (i * j > s) {           int x, ss = i * j;           if ((ss - s) % 4) continue;           int res = (ss - s) / 4;           for (int k = 1; k <= j / 2; k++) {             if (res % k) continue;             x = res / k;             if (x > i / 2) continue;             tmp += 2;           }           ans += cnt * tmp;         }       }     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, tot, res = 0, f[666666], g[666666], q[666666], ans[666666][3];   struct edge {     int adj, nex;     bool vis;     edge(int a_ = 0, int n_ = 0) {       adj = a_;       nex = n_;       vis = false;     }   } e[666666];   void add(int u, int v) {     e[++tot] = edge(v, e[u].nex);     e[u].nex = tot;     e[++tot] = edge(u, e[v].nex);     e[v].nex = tot;   }   void bfs(int x) {     int l = 0, r = 1;     q[1] = x;     f[x] = -1;     while (l < r) {       for (int i = e[q[++l]].nex; i; i = e[i].nex) {         if (!f[e[i].adj]) {           q[++r] = e[i].adj;           f[e[i].adj] = q[l];         }       }     }     for (int i = r; i; i--) {       g[0] = 0;       for (int j = e[q[i]].nex; j; j = e[j].nex) {         if (!e[j].vis && e[j].adj != f[q[i]]) {           g[++g[0]] = j;         }       }       for (int j = e[q[i]].nex; j; j = e[j].nex) {         if (!e[j].vis && e[j].adj == f[q[i]]) {           g[++g[0]] = j;           break;         }       }       for (int j = 1; j < g[0]; j += 2) {         e[g[j]].vis = e[g[j] ^ 1].vis = e[g[j + 1]].vis = e[g[j + 1] ^ 1].vis =             true;         ans[++res][0] = e[g[j]].adj;         ans[res][1] = q[i];         ans[res][2] = e[g[j + 1]].adj;       }     }   }   int main() {     int u, v;     scanf( %d%d , &n, &m);     tot = n | 1;     for (int i = 1; i <= m; i++) {       scanf( %d%d , &u, &v);       add(u, v);     }     for (int i = 1; i <= n; i++) {       if (!f[i]) {         bfs(i);       }     }     printf( %d n , res);     for (int i = 1; i <= res; i++) {       printf( %d %d %d n , ans[i][0], ans[i][1], ans[i][2]);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int days[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};   struct date {     int arr[3];     void read() {       string s;       cin >> s;       for (int i = 0; i < 3; i++) {         arr[i] = (s[i * 3] -  0 ) * 10 + (s[i * 3 + 1] -  0 );       }     }     void next() { next_permutation(arr, arr + 3); }     bool valid() {       if (arr[1] > 12) return false;       if (arr[0] > (days[arr[1] - 1] + (arr[1] == 2 && arr[2] % 4 == 0)))         return false;       return true;     }     bool operator<=(const date& oth) const {       for (int i = 2; i >= 0; i--) {         if (arr[i] != oth.arr[i]) {           return arr[i] < oth.arr[i];         }       }       return true;     }   };   int main() {     date a, b;     a.read();     b.read();     for (int i = 0; i < 6; i++) {       if (b.valid()) {         b.arr[2] += 18;         if (b <= a) {           cout <<  YES n ;           return 0;         }         b.arr[2] -= 18;       }       b.next();     }     cout <<  NO n ;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int T;     cin >> T;     while (T--) {       int result = 0;       int a[105];       int n;       cin >> n;       for (int i = 1; i <= n; i++) {         cin >> a[i];         if (a[i] - result - i > 0) {           result += a[i] - result - i;         }       }       cout << result << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 1e9 + 1;   const double pi = acos(-1);   int dp[1001][2002][4];   int MOD = 998244353;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.precision(20);     int n, k;     cin >> n >> k;     dp[0][0][0] = 1;     dp[0][0][1] = 1;     dp[0][0][2] = 1;     dp[0][0][3] = 1;     for (int i = 1; i < n; ++i) {       for (int j = 0; j <= k; ++j) {         dp[i][j][0] = (dp[i][j][0] + dp[i - 1][j][0]) % MOD;         dp[i][j][1] = (dp[i][j][1] + dp[i - 1][j][0]) % MOD;         dp[i][j][2] = (dp[i][j][2] + dp[i - 1][j][0]) % MOD;         dp[i][j + 1][3] = (dp[i][j + 1][3] + dp[i - 1][j][0]) % MOD;         dp[i][j + 1][0] = (dp[i][j + 1][0] + dp[i - 1][j][1]) % MOD;         dp[i][j][1] = (dp[i][j][1] + dp[i - 1][j][1]) % MOD;         dp[i][j + 2][2] = (dp[i][j + 2][2] + dp[i - 1][j][1]) % MOD;         dp[i][j + 1][3] = (dp[i][j + 1][3] + dp[i - 1][j][1]) % MOD;         dp[i][j + 1][0] = (dp[i][j + 1][0] + dp[i - 1][j][2]) % MOD;         dp[i][j + 2][1] = (dp[i][j + 2][1] + dp[i - 1][j][2]) % MOD;         dp[i][j][2] = (dp[i][j][2] + dp[i - 1][j][2]) % MOD;         dp[i][j + 1][3] = (dp[i][j + 1][3] + dp[i - 1][j][2]) % MOD;         dp[i][j + 1][0] = (dp[i][j + 1][0] + dp[i - 1][j][3]) % MOD;         dp[i][j][1] = (dp[i][j][1] + dp[i - 1][j][3]) % MOD;         dp[i][j][2] = (dp[i][j][2] + dp[i - 1][j][3]) % MOD;         dp[i][j][3] = (dp[i][j][3] + dp[i - 1][j][3]) % MOD;       }     }     int ans = 0;     ans = (ans + dp[n - 1][k - 1][0]) % MOD;     if (k > 1) {       ans = (ans + dp[n - 1][k - 2][1]) % MOD;       ans = (ans + dp[n - 1][k - 2][2]) % MOD;     }     ans = (ans + dp[n - 1][k - 1][3]) % MOD;     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int h1, m1, h2, m2;     scanf( %d:%d %d:%d , &h1, &m1, &h2, &m2);     if (m1 < m2) m1 += 60, h2++;     if (h1 < h2) h1 += 24;     printf( %.2d:%.2d n , h1 - h2, m1 - m2);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool cmp(const pair<long long, long long> &a,            const pair<long long, long long> &b) {     return (a.second < b.second);   }   long long power(long long x, long long y) {     long long res = 1;     x = x;     if (x == 0) return 0;     while (y > 0) {       if (y & 1) res = (res * x);       y = y >> 1;       x = (x * x);     }     return res;   }   int main() {     long long t = 1, i, j, k, x, y, z, n, m;     cin >> t;     while (t--) {       cin >> n;       if (n == 1) {         cout <<  0 n ;         continue;       }       long long p = 8;       long long sum = 0;       for (i = 1; i <= (n / 2); i++) {         p = 8 * i;         sum = sum + (p * i);       }       cout << sum << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<long long> primes;   bool vis[20000000];   vector<long long> a, b;   long long v[20000000];   void genp() {     for (long long i = 2; i < 20000000; i++) {       if (!vis[i]) {         primes.push_back(i);         for (long long j = 1; j * i < 20000000; j++) vis[j * i] = 1;       }     }   }   void mark(long long x) {     for (long long i = 2; i <= sqrt(x); i++) {       long long z = i;       if (x % z == 0) {         long long f = x / z;         for (long long j = 1; j * z < 20000000; j++) v[j * z] = 1;         for (long long j = 1; j * f < 20000000; j++) v[j * f] = 1;       }     }     long long z = x;     for (long long j = 1; j * z < 20000000; j++) v[j * z] = 1;   }   int main() {     ios_base::sync_with_stdio(0);     genp();     v[0] = 1;     v[1] = 1;     long long n;     cin >> n;     for (long long i = 0; i < n; i++) {       long long x;       cin >> x;       a.push_back(x);     }     bool ok = 0;     long long s = 2;     for (long long i = 0; i < n; i++) {       if (!ok) {         long long x = a[i];         if (!v[x]) {           b.push_back(x);           mark(x);         } else {           ok = 1;           for (long long k = x + 1; k <= 1e9; k++) {             if (!v[k]) {               b.push_back(k);               mark(k);               break;             }           }         }       } else {         for (s = s; s <= 1e9; s++) {           if (!v[s]) {             b.push_back(s);             mark(s);             break;           }         }       }     }     for (long long i = 0; i < n; i++) cout << b[i] <<    ;     cout << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int oo = int(2e9) + 9;   const double eps = 1e-9;   const double pi = 3.14159265358979323846264338327950;   int main() {     int p, n;     int a[305];     scanf( %d %d , &p, &n);     memset(a, -1, sizeof(a));     for (int i = 1; i <= n; i++) {       int x;       scanf( %d , &x);       if (a[x % p] != -1) {         printf( %d n , i);         return 0;       }       a[x % p] = 1;     }     printf( -1 n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m;   char a[55][55];   int dx[4] = {1, -1, 0, 0}, dy[4] = {0, 0, 1, -1};   vector<pair<int, int> > G[2555];   int vis[2555];   int bfs(int i, int j) {     memset(vis, -1, sizeof vis);     deque<pair<int, int> > q;     q.push_front(make_pair(i * m + j, 0));     int mx = 0;     while (!q.empty()) {       pair<int, int> cur = q.front();       q.pop_front();       int u = cur.first, w = cur.second;       vis[u] = w;       if (a[u / m][u % m] ==  B ) mx = w;       for (int k = 0; k < (int)G[u].size(); k++) {         int v = G[u][k].first, w2 = G[u][k].second;         if (vis[v] == -1) {           vis[v] = w + w2;           if (w2 == 0)             q.push_front(make_pair(v, w));           else             q.push_back(make_pair(v, w + w2));         }       }     }     return mx;   }   int main() {     bool ok = 0;     scanf( %d%d , &n, &m);     for (int i = 0; i < n; i++) scanf( %s , a[i]);     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++)         if (a[i][j] ==  B ) ok = 1;     if (!ok) {       printf( 0 n );       return 0;     }     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) {         for (int k = 0; k < 4; k++) {           int newI = i + dx[k], newJ = j + dy[k];           if (newI < 0 || newJ < 0 || newI >= n || newJ >= m) continue;           if (a[i][j] == a[newI][newJ])             G[i * m + j].push_back(make_pair(newI * m + newJ, 0));           else             G[i * m + j].push_back(make_pair(newI * m + newJ, 1));         }       }     int mn = n * m + 1;     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) {         mn = min(mn, bfs(i, j));       }     printf( %d n , mn + 1);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long cnt[3], dp[1010][4], n, p;   struct seg {     long long l, r, v;     seg() {}     seg(long long _l, long long _r, long long _v) { l = _l, r = _r, v = _v; }   };   vector<seg> v;   long long cal(long long x, long long y) {     if (v[x].v != 0 && v[y].v != 0) return 0;     if (v[x].v != 1 && v[y].v != 1) return 1;     return 2;   }   long long get(long long x, long long y) {     if (x % 3 == 0) return -(!(y & 1));     if (x % 3 == 2) return (y & 1);     return 0;   }   long long npair(long long a, long long b) {     return ((a + b) * (a - b + 1) / 2) % 1000000007;   }   void upd(long long& a, long long b) { a = (a + b) % 1000000007; }   int main() {     cin >> n >> p;     v.push_back(seg(1, 2, 0));     long long nxt = 3;     while (nxt <= p) {       long long x = nxt / 3, y = nxt - x, id1, id2;       for (long long i = 0; i < ((long long)(v).size()); i++) {         if (v[i].l <= x && x <= v[i].r) id1 = i;         if (v[i].l <= y && y <= v[i].r) id2 = i;       }       long long g = cal(id1, id2);       long long cnt1 = v[id1].r - x + 1;       long long cnt2 = v[id2].r - y + 1;       cnt1 = (cnt1 - 1) * 3 + 3 - (nxt % 3);       cnt2 = cnt2 + cnt2 / 2 + get(nxt, cnt2);       long long end = nxt + min(cnt1, cnt2) - 1;       while (!v.empty() && g == v[((long long)(v).size()) - 1].v)         nxt = v[((long long)(v).size()) - 1].l, v.pop_back();       v.push_back(seg(nxt, end, g));       nxt = end + 1;     }     for (__typeof((v).begin()) it = (v).begin(); it != (v).end(); it++)       upd(cnt[it->v], npair(p - it->l, p - min(p, it->r)));     dp[0][0] = 1;     for (long long i = 1; i <= n; i++)       for (long long j = 0; j < 4; j++)         for (long long k = 0; k < 3; k++)           upd(dp[i][j], dp[i - 1][j ^ k] * cnt[k]);     cout << (dp[n][1] + dp[n][2] + dp[n][3]) % 1000000007 << endl;   }
#include <bits/stdc++.h>   using namespace std;   const double pi = acos(-1.0);   const double eps = 1e-11;   const int inf = 0x7FFFFFFF;   template <class T>   inline void checkmin(T &a, T b) {     if (b < a) a = b;   }   template <class T>   inline void checkmax(T &a, T b) {     if (b > a) a = b;   }   template <class T>   inline T sqr(T x) {     return x * x;   }   template <class T>   void show(T a, int n) {     for (int i = 0; i < n; ++i) cout << a[i] <<    ;     cout << endl;   }   template <class T>   void show(T a, int r, int l) {     for (int i = 0; i < r; ++i) show(a[i], l);     cout << endl;   }   int sgn(double x) { return x < -eps ? -1 : x > eps; }   int main() {     double y1, y2, yw, xb, yb, r;     while (cin >> y1 >> y2 >> yw >> xb >> yb >> r) {       if (sgn(y2 - y1 - 2 * r) < 0) {         puts( -1 );         continue;       } else {         double y = (y1 + r), yyw = yw - r;         double ax = (yyw - y) / (yyw - y + yyw - yb) * xb;         double ds = (y2 - y) * ax / (sqrt(sqr(ax) + sqr(yyw - y)));         if (sgn(ds - r) <= 0) {           puts( -1 );           continue;         }         printf( %.12lf n , ax);       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAX = 1e5 + 5;   int n, m;   long long t[MAX << 2], tag[MAX << 2];   int sz = 1;   inline void Period(int k, int l, int r, int a, int b, long long x) {     if (a > r || b < l) return;     if (a >= l && b <= r) {       tag[k] = t[k] = x;       return;     }     Period(k << 1, l, r, a, (a + b) >> 1, x);     Period((k << 1) + 1, l, r, ((a + b) >> 1) + 1, b, x);     t[k] = max(t[k << 1], t[(k << 1) + 1]);   }   inline long long Query(int k, int l, int r, int a, int b) {     if (tag[k]) {       t[k] = tag[k];       tag[k << 1] = max(tag[k << 1], tag[k]);       tag[(k << 1) + 1] = max(tag[(k << 1) + 1], tag[k]);       tag[k] = 0;     }     if (a > r || b < l) return 0;     if (a >= l && b <= r) return t[k];     return max(Query(k << 1, l, r, a, (a + b) >> 1),                Query((k << 1) + 1, l, r, ((a + b) >> 1) + 1, b));   }   int main() {     ios::sync_with_stdio(false);     cin >> n;     while (sz < n) sz <<= 1;     for (int i = 1; i <= n; i++) {       long long x;       cin >> x;       Period(1, i, i, 1, sz, x);     }     cin >> m;     while (m--) {       int x;       long long h;       cin >> x >> h;       long long res = Query(1, 1, x, 1, sz);       cout << res << endl;       Period(1, 1, x, 1, sz, res + h);     }     return 0;   }