#include <bits/stdc++.h>   using namespace std;   inline long long ma(long long a, long long b) { return a > b ? a : b; }   inline long long mi(long long a, long long b) { return a > b ? b : a; }   template <typename Arg1>   void __f(const char *name, Arg1 &&arg1) {     cerr << name <<   :   << arg1 << endl;   }   template <typename Arg1, typename... Args>   void __f(const char *names, Arg1 &&arg1, Args &&...args) {     const char *comma = strchr(names + 1,  , );     cerr.write(names, comma - names) <<   :   << arg1 <<   |  ;     __f(comma + 1, args...);   }   vector<long long> adj[100005], v;   bool Q;   struct line {     mutable long long k, m, p;     bool operator<(const line &o) const { return Q ? p < o.p : k < o.k; }   };   struct LineContainer : multiset<line> {     const long long inf = LLONG_MAX;     inline long long div(long long a, long long b) {       return a / b - ((a ^ b) < 0 && a % b);     }     inline bool isect(iterator x, iterator y) {       if (y == end()) {         x->p = inf;         return false;       }       if (x->k == y->k)         x->p = x->m > y->m ? inf : -inf;       else         x->p = div(y->m - x->m, x->k - y->k);       return x->p >= y->p;     }     inline void add(long long k, long long m) {       auto z = insert({k, m, 0}), y = z++, x = y;       while (isect(y, z)) z = erase(z);       if (y != begin() && isect(--x, y)) isect(x, erase(y));       while ((y = x) != begin() && (--x)->p >= y->p) isect(x, erase(y));     }     inline long long query(long long x) {       assert(!empty());       Q = 1;       auto l = *lower_bound({0, 0, x});       Q = 0;       return l.k * x + l.m;     }   };   struct T {     LineContainer lc;     T() {}     T(LineContainer &lc) : lc(lc) {}   };   struct ST {     long long n;     T t[2 * 100005];     inline void Op(T &ty, T &val1, T &val2) {       for (auto xd : val1.lc) {         ty.lc.add(xd.k, xd.m);       }       for (auto xd : val2.lc) {         ty.lc.add(xd.k, xd.m);       }     }     inline long long Op1(T &val1, long long cur, long long x) {       long long val = val1.lc.query(x);       return mi(cur, -val);     }     inline void build() {       for (long long(i) = (n - 1); (i) >= (1); (i)--)         Op(t[i], t[i << 1], t[i << 1 | 1]);     }     inline long long que(long long l, long long r, long long ra) {       long long ans = 23242532523;       for (l += n, r += n; l < r; l >>= 1, r >>= 1) {         if (l & 1) ans = Op1(t[l++], ans, ra);         if (r & 1) ans = Op1(t[--r], ans, ra);       }       return ans;     }   };   long long dp[100005], ar[100005];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     ;     long long n;     cin >> n;     ST st;     st.n = n;     for (long long(i) = (0); (i) < (n); (i)++) cin >> ar[i];     for (long long(i) = (0); (i) < (n); (i)++)       dp[i] = (i == 0) ? ar[i] : dp[i - 1] + ar[i];     for (long long(i) = (0); (i) < (n); (i)++) {       long long x = ar[i], y = ar[i] * (i + 1) - dp[i];       st.t[i + n].lc.add(-x, -y);     }     st.build();     long long q;     cin >> q;     vector<pair<long long, pair<long long, long long> > > qs;     for (long long(i) = (0); (i) < (q); (i)++) {       long long l, r;       cin >> l >> r;       l--;       qs.push_back({l - r + 1, {i, r}});     }     sort((qs).begin(), (qs).end());     reverse((qs).begin(), (qs).end());     long long ez[100005];     for (long long(i) = (0); (i) < (qs.size()); (i)++) {       long long val = qs[i].first, r = qs[i].second.second,                 id = qs[i].second.first;       long long l = val + r;       l = r - l;       ez[id] = st.que(l, r, val) + dp[r - 1];     }     for (long long(i) = (0); (i) < (q); (i)++) cout << ez[i] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 64;   int n, m, r, a[maxn][maxn], dis[maxn];   int dp[maxn][maxn][maxn];   set<pair<int, int> > s;   void dij(int v) {     memset(dis, 127, sizeof dis);     dis[v] = 0;     s.insert(make_pair(dis[v], v));     while (s.size()) {       v = s.begin()->second;       s.erase(s.begin());       for (int u = 0; u < n; u++)         if (dis[v] + a[v][u] < dis[u]) {           s.erase(make_pair(dis[u], u));           dis[u] = dis[v] + a[v][u];           s.insert(make_pair(dis[u], u));         }     }   }   void set_distance() {     memset(dis, 127, sizeof dis);     for (int i = 0; i < n; i++) {       dij(i);       for (int j = 0; j < n; j++)         if (dis[j] < dp[i][j][0]) dp[i][j][0] = dis[j];     }   }   void update_dp() {     for (int k = 1; k < n; k++)       for (int i = 0; i < n; i++)         for (int j = 0; j < n; j++)           for (int l = 0; l < n; l++)             dp[i][j][k] = min(dp[i][j][k], dp[i][l][k - 1] + dp[l][j][0]);   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n >> m >> r;     memset(dp, 31, sizeof dp);     while (m--) {       for (int i = 0; i < n; i++)         for (int j = 0; j < n; j++) cin >> a[i][j];       set_distance();     }     update_dp();     for (int S, T, k; r--;) {       cin >> S >> T >> k;       cout << dp[S - 1][T - 1][min(k, n - 2)] << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[100005], b[100005], c[100005];   class segtree {    public:     int seg[524288 * 2];     int lazy[524288 * 2];     void init() {       for (int i = 0; i < 524288 * 2; i++) {         seg[i] = 0;       }     }     void lazy_evaluate(int x) {       if (x * 2 + 2 >= 524288 * 2) return;       lazy[x * 2 + 1] += lazy[x];       lazy[x * 2 + 2] += lazy[x];       seg[x * 2 + 1] += lazy[x];       seg[x * 2 + 2] += lazy[x];       lazy[x] = 0;     }     int update(int a, int b, int k, int lb, int ub, int val) {       pair<int, int> p;       p.first = -2000000000, p.second = -2000000000;       if (ub < a || b < lb) return seg[k];       if (a <= lb && ub <= b) {         lazy[k] += val;         seg[k] += val;         return seg[k];       }       if (lazy[k]) lazy_evaluate(k);       int p1 = update(a, b, k * 2 + 1, lb, (lb + ub) / 2, val);       int p2 = update(a, b, k * 2 + 2, (lb + ub) / 2 + 1, ub, val);       return seg[k] = max(p1, p2);     }     int query() { return seg[0]; }   } seg;   int main() {     int n;     vector<pair<int, pair<int, int> > > p;     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %d %d %d , &a[i], &b[i], &c[i]);       p.push_back(make_pair(a[i], make_pair(b[i], c[i])));     }     sort(p.begin(), p.end());     seg.init();     int ret = -1;     int lb, ub;     priority_queue<pair<int, int>, vector<pair<int, int> >,                    greater<pair<int, int> > >         que;     for (int i = 0; i < n; i++) {       while (!que.empty() && p[i].first > que.top().first) {         seg.update(p[que.top().second].second.first,                    p[que.top().second].second.second, 0, 0, 524288 - 1, -1);         que.pop();       }       que.push(make_pair(p[i].second.first, i));       seg.update(p[i].second.first, p[i].second.second, 0, 0, 524288 - 1, 1);       int pp = seg.query();       if (pp > ret) {         ret = pp;         lb = p[i].first;       }     }     printf( %d n , ret);     priority_queue<int, vector<int>, greater<int> > que2;     int next;     vector<pair<int, int> > in;     for (int i = 0; i < n; i++) {       if (p[i].second.first >= lb && p[i].first <= lb) {         in.push_back(make_pair(p[i].second.first, i));       }     }     sort(in.begin(), in.end());     next = 0;     for (int j = lb;; j++) {       while (!que2.empty() && que2.top() < j) que2.pop();       while (next != in.size() && in[next].first <= j) {         que2.push(p[in[next].second].second.second);         next++;       }       if (que2.size() == ret) {         ub = j;         break;       }     }     int x = 0;     for (int i = 0; i < n; i++) {       if (a[i] <= lb && ub <= c[i] && lb <= b[i] && b[i] <= ub) {         x++;         printf( %d%c , i + 1, x == ret ?   n  :    );       }     }   }


#include <bits/stdc++.h>   using namespace std;   int n, k;   int ans;   int p1 = 1 << 17;   int p2 = 1 << 18;   void solve(int x) {     int a = p1 | x;     int b = p2 | p1;     cout << a <<     << b <<     << p2;   }   int main() {     cin >> n >> k;     if (n == 2 && k == 0) {       cout <<  NO  << endl;       return 0;     }     if (n == 1) {       cout <<  YES n  << k << endl;       return 0;     }     if (n == 2) {       cout <<  YES n  << k <<     <<  0  << endl;       return 0;     }     cout <<  YES n ;     for (int i = 1; i <= n - 3; i++) {       cout << i <<    ;       ans ^= i;     }     solve(ans ^ k);   }


#include <bits/stdc++.h>   using namespace std;   const int max_N = 2e5 + 10;   const int l_N = 20;   int st[l_N][max_N];   int lg[max_N];   int inp[max_N];   vector<int> bits[30];   int query_max(int i, int j);   int main() {     {       int j = 0;       for (int i = 0; i < max_N; ++i) {         while ((1 << j) <= i) {           ++j;         }         lg[i] = j - 1;       }     }     int N;     scanf( %d , &N);     for (int i = 1; i <= N; ++i) {       scanf( %d , &inp[i]);       st[0][i] = inp[i];     }     for (int j = 1; j < l_N; ++j) {       for (int i = 1; i + (1 << j) - 1 <= N; ++i) {         st[j][i] = max(st[j - 1][i], st[j - 1][i + (1 << (j - 1))]);       }     }     for (int i = 1; i <= N; ++i) {       for (int j = 0; j < 30; ++j) {         if ((inp[i] >> j) & 1) {           bits[j].push_back(i);         }       }     }     long long ans = 0;     for (int i = 1; i <= N; ++i) {       vector<int> or_changes;       for (int j = 0; j < 30; ++j) {         auto it = lower_bound(bits[j].begin(), bits[j].end(), i);         if (it != bits[j].end()) {           or_changes.push_back(*it);         }       }       sort(or_changes.begin(), or_changes.end());       or_changes.push_back(N + 1);       int cid = *or_changes.begin();       int cor = inp[cid];       for (int j = 1; j < or_changes.size(); ++j) {         int L = cid, R = or_changes[j];         int low = L, high = R - 1, mid, best = R;         while (low <= high) {           mid = (low + high) >> 1;           if (query_max(L, mid) >= cor) {             best = mid;             high = mid - 1;           } else {             low = mid + 1;           }         }         ans += best - L;         cid = R;         cor |= inp[R];       }     }     cout << ans << endl;   }   int query_max(int i, int j) {     int d = lg[j - i + 1];     return max(st[d][i], st[d][j - (1 << d) + 1]);   }


#include <bits/stdc++.h>   using namespace std;   int num[1005];   char num0[1005];   int res1[1005];   int N;   int query() {     int res = 0;     for (int i = 0; i < N; i++) {       if (num[i] != 0) {         res *= 10;         res += num[i];       } else if (num[i] == 0) {         res *= 10;       }     }     return res >= 0 ? res : -res;   }   int move_1() {     int t = num[0];     for (int i = 0; i < N - 1; i++) {       num[i] = num[i + 1];     }     num[N - 1] = t;     return 0;   }   int up1() {     for (int i = 0; i < N; i++) {       if (num[i] == 9) {         num[i] = 0;       } else {         num[i] += 1;       }     }     return 0;   }   void print() {     printf(  num =  );     for (int i = 0; i < N; i++) {       printf( %d , num[i]);     }     puts(  );   }   void printres() {     for (int i = 0; i < N; i++) {       printf( %d , res1[i]);     }     puts(  );   }   int panduan() {     char temp1[1005], temp2[1005];     for (int i = 0; i < N; i++) {       temp1[i] = num[i] +  0 ;     }     for (int i = 0; i < N; i++) {       temp2[i] = res1[i] +  0 ;     }     if (strcmp(temp1, temp2) < 0) {       return 1;     } else       return 0;   }   int copy1() {     for (int i = 0; i < N; i++) {       num[i] = num0[i] -  0 ;     }     return 0;   }   int copy2() {     for (int i = 0; i < N; i++) {       res1[i] = num[i];     }     return 0;   }   int main() {     while (scanf( %d , &N) != EOF) {       getchar();       for (int i = 0; i < N; i++) {         scanf( %c , &num0[i]);       }       int res = 1e9;       copy1();       copy2();       for (int i = 0; i < 10; i++) {         for (int j = 1; j <= N; j++) {           move_1();           if (panduan() > 0) {             copy2();           }         }         up1();       }       printres();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long nax = 100001;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       vector<int> a(n);       for (auto& x : a) {         cin >> x;       }       if (a[0]) {         cout << n + 1 <<    ;         for (int i = 1; i <= n; ++i) {           cout << i <<    ;         }         cout <<   n ;         continue;       }       if (!a.back()) {         for (int i = 1; i <= n + 1; ++i) {           cout << i <<    ;         }         cout <<   n ;         continue;       }       for (int i = 0; i < n - 1; ++i) {         if (a[i] == 0 && a[i + 1] == 1) {           for (int j = 1; j <= i + 1; ++j) {             cout << j <<    ;           }           cout << n + 1 <<    ;           for (int j = i + 2; j <= n; ++j) {             cout << j <<    ;           }           cout <<   n ;           break;         }       }     }   }


#include <bits/stdc++.h>   using namespace std;   int x, n, p;   int a[1005];   long double f[205][205][205];   int check(int m) {     int s = 0;     while (m % 2 == 0) {       s++;       m /= 2;     }     return s;   }   int main() {     ios_base::sync_with_stdio(false);     int i, j, k;     long double xx, yy;     cin >> x >> n >> p;     xx = (long double)p / 100.0;     yy = (long double)(100 - p) / 100.0;     for (i = 0; i <= 1000; i++) a[i] = check(x + i);     for (j = 0; j <= 201; j++) {       for (k = 0; k <= 201; k++) {         f[0][j][k] = (long double)(a[j] + k);       }     }     for (i = 1; i <= n; i++) {       for (j = 0; j <= 200; j++) {         for (k = 0; k <= 200; k++) {           f[i][j][k] = f[i - 1][j + 1][k] * yy;           if (j % 2 == 0)             f[i][j][k] += (f[i - 1][j / 2][k + 1] * xx);           else             f[i][j][k] += ((long double)k * xx);         }       }     }     cout.precision(9);     cout << fixed << f[n][0][0] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int tr[100001];   int sum(int ind) {     int sum = 0;     ind = ind + 1;     while (ind) {       sum += tr[ind];       ind -= ind & (-ind);     }     return sum;   }   void update(int ind, int val) {     ++ind;     while (ind <= 100000) {       tr[ind] += val;       ind += ind & (-ind);     }   }   int main() {     int n;     cin >> n;     vector<int> a(n);     set<int> ind[100001];     for (int i = 0; i < n; ++i) {       cin >> a[i];       ind[a[i]].emplace(i);     }     long long ans = 1;     int pos = 0;     sort(a.begin(), a.end());     for (int i = 0; i < n; ++i) {       int next;       if (i > 0 && a[i] == a[i - 1]) {         next = (ind[a[i]].upper_bound(pos) == ind[a[i]].end())                    ? *(ind[a[i]].begin())                    : *(ind[a[i]].upper_bound(pos));       } else {         next = (ind[a[i]].lower_bound(pos) == ind[a[i]].end())                    ? *(ind[a[i]].begin())                    : *(ind[a[i]].lower_bound(pos));       }       int rn = next - sum(next);       int rp = pos - sum(pos);       ans += (rn >= rp) ? (long long)(rn - rp) : (long long)(n - i - rp + rn + 1);       if (i) update(pos, 1);       pos = next;     }     cout << ans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2000000;   const int mod = 998244353;   int used[N][2];   int f[N][2];   bool ok[N];   int solve(int n, int k) {     if (used[n][k]) {       return f[n][k];     }     if (!ok[n]) {       return 0;     }     int last = 0;     int m = n;     int j = 0;     for (int i = 0; i < 40; i++) {       if ((1 << i) > m) {         last = m;         break;       }       j = i;       m -= (1 << i);     }     if (m == 0) {       used[n][k] = 1;       f[n][k] = 0;       return 0;     }     int ans = 0;     int nxt = (1 << j);     int sz = (n - last) / 2;     for (int i = max(0, last - sz - 1); i <= min(last, sz + 1); i++) {       if ((sz + i) % 2 != k) {         continue;       }       ans += 1ll * (solve(sz + i, 0) + solve(sz + i, 1)) % mod *              solve(sz + last - i, 1) % mod;       if (ans >= mod) {         ans -= mod;       }     }     used[n][k] = 1;     f[n][k] = ans;     return ans;   }   int main() {     ios_base::sync_with_stdio(false);     int n;     cin >> n;     int x = 1;     int v = 0;     while (x <= n) {       ok[x] = 1;       ok[x + 1] = 1;       x++;       x = x * 2 - v;       v = 1 - v;     }     used[0][0] = 1;     f[0][0] = 1;     used[0][1] = 1;     f[0][1] = 1;     used[1][0] = 1;     f[1][0] = 1;     used[1][1] = 1;     f[1][1] = 0;     cout << (solve(n, 0) + solve(n, 1)) % mod <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int T;     long long a, b, c;     for (scanf( %d , &T); T; T--) {       cin >> a >> b >> c;       if (a >= c) {         printf( -1  );       } else         printf( 1  );       if (a * b > c)         printf( %I64d n , b);       else         printf( -1 n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   inline void upmax(T& a, T b) {     if (a < b) a = b;   }   template <class T>   inline void upmin(T& a, T b) {     if (a > b) a = b;   }   const int maxn = 307;   const int maxm = 100007;   const int mod = 1000000007;   const int inf = 0x7fffffff;   const double eps = 1e-7;   typedef int arr[maxn];   typedef int adj[maxm];   inline int fcmp(double a, double b) {     if (fabs(a - b) <= eps) return 0;     if (a < b - eps) return -1;     return 1;   }   inline int add(int a, int b) { return ((long long)a + b) % mod; }   inline int mul(int a, int b) { return ((long long)a * b) % mod; }   inline int dec(int a, int b) { return add(a, mod - b % mod); }   inline int Pow(int a, int b) {     int t = 1;     while (b) {       if (b & 1) t = mul(t, a);       a = mul(a, a), b >>= 1;     }     return t;   }   template <typename Type>   inline Type RD() {     char c = getchar();     Type x = 0, flag = 1;     while (!isdigit(c) && c !=  - ) c = getchar();     if (c ==  - )       flag = -1;     else       x = c -  0 ;     while (isdigit(c = getchar())) x = x * 10 + c -  0 ;     return x * flag;   }   inline char rdch() {     char c = getchar();     while (!isalpha(c)) c = getchar();     return c;   }   int n, m, k;   double C[maxn][maxn], f[maxm];   void input() {     n = RD<int>(), m = RD<int>(), k = RD<int>();     for (int i = 0, _ = n; i <= _; i++) {       C[i][0] = 1;       for (int j = 1, _ = i; j <= _; j++) C[i][j] = C[i - 1][j] + C[i - 1][j - 1];     }     f[0] = 1;     for (int i = 1, _ = k; i <= _; i++)       f[i] = f[i - 1] * (k - i + 1) / (m - i + 1);   }   void solve() {     double ans = 0;     for (int i = 0, _ = n; i <= _; i++) {       for (int j = 0, _ = n; j <= _; j++) {         ans += C[n][i] * C[n][j] * f[(i + j) * n - i * j];         if (ans > 1e99) break;       }       if (ans > 1e99) break;     }     if (ans > 1e99) ans = 1e99;     printf( %.10lf n , ans);   }   int main() {     input();     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 10;   int n, Q, pos;   long long a[maxn], sum[maxn], x;   long long tr[maxn << 2], tag[maxn << 2];   void pushup(int rt) { tr[rt] = max(tr[rt << 1], tr[rt << 1 | 1]); }   void build(int rt = 1, int l = 1, int r = n) {     tag[rt] = 0;     if (l == r) {       tr[rt] = sum[l];       return;     }     int mid = (l + r) >> 1;     build(rt << 1, l, mid);     build(rt << 1 | 1, mid + 1, r);     pushup(rt);   }   void load(int rt, long long k) {     tag[rt] += k;     tr[rt] += k;   }   void pushdown(int rt, int l, int r) {     if (tag[rt] == 0) return;     load(rt << 1, tag[rt]);     load(rt << 1 | 1, tag[rt]);     tag[rt] = 0;   }   void update(int nl, int nr, long long k, int l = 1, int r = n, int rt = 1) {     if (nl <= l && nr >= r) {       load(rt, k);       return;     }     pushdown(rt, l, r);     int mid = (l + r) >> 1;     if (nl <= mid) update(nl, nr, k, l, mid, rt << 1);     if (nr >= mid + 1) update(nl, nr, k, mid + 1, r, rt << 1 | 1);     pushup(rt);   }   long long temp_x;   int id;   int get_pos(long long limit, int l = 1, int r = n, int rt = 1) {     if (l == r) {       temp_x = tr[rt];       return l;     }     pushdown(rt, l, r);     int mid = (l + r) >> 1;     if (tr[rt << 1] >= limit)       return get_pos(limit, l, mid, rt << 1);     else       return get_pos(limit, mid + 1, r, rt << 1 | 1);   }   void go() {     long long now_x = 0;     int now_id = 0;     while (now_id != n) {       int temp_id = get_pos(2 * now_x);       if (temp_x == 2 * a[temp_id]) {         printf( %d n , temp_id);         return;       }       now_id = temp_id;       now_x = temp_x;     }     puts( -1 );   }   int main() {     scanf( %d %d , &n, &Q);     for (int i = 1; i <= n; i++) {       scanf( %lld , a + i);       sum[i] = sum[i - 1] + a[i];     }     build();     while (Q--) {       scanf( %d %lld , &pos, &x);       update(pos, n, x - a[pos]);       a[pos] = x;       go();     }     return 0;   }


#include <bits/stdc++.h>   const long long mod = 1000000000;   class V {    public:     long long a[2];     V(long long a0 = 0, long long a1 = 0) {       a[0] = a0 % mod;       a[1] = a1 % mod;     }     V operator+(const V &v) { return V(a[0] + v.a[0], a[1] + v.a[1]); }   };   class M {    public:     long long a[2][2];     M(long long a00 = 1, long long a01 = 0, long long a10 = 0,       long long a11 = 1) {       a[0][0] = a00 % mod;       a[0][1] = a01 % mod;       a[1][0] = a10 % mod;       a[1][1] = a11 % mod;     }     M operator+(const M &m) {       return M(a[0][0] + m.a[0][0], a[0][1] + m.a[0][1], a[1][0] + m.a[1][0],                a[1][1] + m.a[1][1]);     }     M operator*(const M &m) {       M r(0, 0, 0, 0);       for (int i = 0; i < 2; i++)         for (int j = 0; j < 2; j++) {           for (int k = 0; k < 2; k++) r.a[i][j] += a[i][k] * m.a[k][j];           r.a[i][j] %= mod;         }       return r;     }     V operator*(const V &v) {       return V(a[0][0] * v.a[0] + a[0][1] * v.a[1],                a[1][0] * v.a[0] + a[1][1] * v.a[1]);     }   };   const int maxn = 200010;   const int maxit = (1 << 19) + 5;   M pow_m[maxn], sum_m[maxn], m0;   long long it_a[maxit], it_b[maxit];   V it_v[maxit];   V it_vr(int u, int L, int R, long long bonus = 0) {     return it_v[u] + sum_m[R - L + 1] * V(it_b[u] + bonus, it_b[u] + bonus);   }   void it_update(int u, int L, int R, int x, int v) {     if (x < L || x > R) return;     if (L == R) {       it_a[u] = v;       it_b[u] = 0;       it_v[u] = V(v, v);       return;     }     it_b[2 * u] += it_b[u];     it_b[2 * u + 1] += it_b[u];     it_b[u] = 0;     int M = (L + R) / 2;     it_update(2 * u, L, M, x, v);     it_update(2 * u + 1, M + 1, R, x, v);     it_v[u] = it_vr(2 * u, L, M) + pow_m[M - L + 1] * it_vr(2 * u + 1, M + 1, R);   }   void it_add(int u, int L, int R, int l, int r, int v) {     if (r < L || l > R) return;     if (l <= L && r >= R) {       it_b[u] += v;       return;     }     int M = (L + R) / 2;     it_add(2 * u, L, M, l, r, v);     it_add(2 * u + 1, M + 1, R, l, r, v);     it_v[u] = it_vr(2 * u, L, M) + pow_m[M - L + 1] * it_vr(2 * u + 1, M + 1, R);   }   V it_get(int u, int L, int R, int l, int r, long long bonus = 0) {     if (r < L || l > R) return V(0, 0);     if (l <= L && r >= R) {       return pow_m[L - l] * it_vr(u, L, R, bonus);     }     int M = (L + R) / 2;     return it_get(2 * u, L, M, l, r, bonus + it_b[u]) +            it_get(2 * u + 1, M + 1, R, l, r, bonus + it_b[u]);   }   int main() {     m0 = M(0, 1, 1, 1);     pow_m[0] = M(1, 0, 0, 1);     sum_m[0] = M(0, 0, 0, 0);     for (int i = 0; i + 1 < maxn; i++) {       pow_m[i + 1] = pow_m[i] * m0;       sum_m[i + 1] = sum_m[i] + pow_m[i];     }     memset(it_b, 0, sizeof(it_b));     int n, m, x, l, r, a, t;     assert(scanf( %d%d , &n, &m) == 2);     for (int i = 0; i < n; i++) {       assert(scanf( %d , &a) == 1);       it_update(1, 0, n - 1, i, a);     }     for (int i = 0; i < m; i++) {       assert(scanf( %d , &t) == 1);       if (t == 1) {         assert(scanf( %d%d , &x, &a) == 2);         it_update(1, 0, n - 1, x - 1, a);       } else if (t == 2) {         assert(scanf( %d%d , &l, &r) == 2);         V v = it_get(1, 0, n - 1, l - 1, r - 1);         printf( %d n , (int)v.a[0]);       } else if (t == 3) {         assert(scanf( %d%d%d , &l, &r, &a) == 3);         it_add(1, 0, n - 1, l - 1, r - 1, a);       } else         assert(t == 1);     }     return 0;   }


#include <bits/stdc++.h>   int II() {     int n;     scanf( %d , &n);     return n;   }   void II(int n) { printf( %d , n); }   void IIn(int n) { printf( %d n , n); }   void IIb(int n) { printf( %d  , n); }   long long int LL() {     long long int n;     scanf( %lld , &n);     return n;   }   void LL(long long int n) { printf( %lld , n); }   void LLn(long long int n) { printf( %lld n , n); }   void LLb(long long int n) { printf( %lld  , n); }   char CC() { return getchar(); }   char CCa() {     char c = getchar();     while (c <= 32) c = getchar();     return c;   }   void CC(char c) { putchar(c); }   void CCn(char c) {     putchar(c);     putchar(10);   }   void CCb(char c) {     putchar(c);     putchar(32);   }   void CCn() { putchar(10); }   void CCb() { putchar(32); }   void SS(char *s) { scanf( %s , s); }   void SSb(const char *s) { printf( %s  , s); }   void SSn(const char *s) { printf( %s n , s); }   float FF() {     float n;     scanf( %f , &n);     return n;   }   void FF(float n) { printf( %f , n); }   void FFn(float n) { printf( %f n , n); }   void FFb(float n) { printf( %f  , n); }   void FF(double n, int prec) { std::cout << std::setprecision(prec) << n; }   void FFn(double n, int prec) {     std::cout << std::setprecision(prec) << n;     putchar(10);   }   void FFb(double n, int prec) {     std::cout << std::setprecision(prec) << n;     putchar(32);   }   struct node {     int val;     int prio;     int subsize;     bool flagrotate;     node *left, *right;     node() {       prio = rand();       subsize = 1;       flagrotate = false;       left = right = NULL;     }     void clean() {       if (flagrotate) {         flagrotate = false;         std::swap(left, right);         if (left) left->flagrotate ^= 1;         if (right) right->flagrotate ^= 1;       }     }     void assest() {       subsize = 1 + (left ? left->subsize : 0) + (right ? right->subsize : 0);     }   };   typedef node *tree;   tree merge(tree A, tree B) {     if (!A) return B;     if (!B) return A;     A->clean();     B->clean();     if (A->prio > B->prio) {       A->right = merge(A->right, B);       A->assest();       return A;     } else {       B->left = merge(A, B->left);       B->assest();       return B;     }   }   void print(tree x, int d = 0) {     if (!x) return;     x->clean();     print(x->left, d + 1);     IIb(x->val);     print(x->right, d + 1);   }   std::pair<tree, tree> split(tree x, int k) {     if (!x) return {NULL, NULL};     x->clean();     int sl = x->left ? x->left->subsize : 0;     if (k <= sl) {       std::pair<tree, tree> r = split(x->left, k);       x->left = r.second;       x->assest();       return {r.first, x};     }     k -= sl;     --k;     std::pair<tree, tree> r = split(x->right, k);     x->right = r.first;     x->assest();     return {x, r.second};   }   int nth(tree x, int p) {     x->clean();     int sl = x->left ? x->left->subsize : 0;     if (sl == p) return x->val;     if (sl > p) return nth(x->left, p);     return nth(x->right, p - sl - 1);   }   constexpr int MAXN = 200000;   node V[MAXN];   int main() {     int N = II(), Q = II(), M = II();     for (int x = 0; x < N; x++) V[x].val = II();     tree T = NULL;     for (int x = 0; x < N; x++) T = merge(T, V + x);     while (Q--) {       if (II() == 1) {         int l = II() - 1, r = II();         std::pair<tree, tree> A = split(T, r);         std::pair<tree, tree> B = split(A.first, l);         std::pair<tree, tree> C = split(B.second, B.second->subsize - 1);         T = merge(merge(B.first, C.second), merge(C.first, A.second));       } else {         int l = II() - 1, r = II();         std::pair<tree, tree> A = split(T, r);         std::pair<tree, tree> B = split(A.first, l);         B.second->flagrotate ^= 1;         T = merge(merge(B.first, B.second), A.second);       }     }     while (M--) IIb(nth(T, II() - 1));     CCn();   }


#include <bits/stdc++.h>   using namespace std;   int solve(vector<int> &v, int pow) {     if (pow == 20) {       for (int j : v) {         if (j) return 40;       }       return 0;     }     bool fnd = false;     for (int i = 0; i < v.size(); i++) {       if (v[i] % (1 << (pow + 1))) {         fnd = true;       }     }     if (!fnd)       return solve(v, pow + 1);     else {       vector<int> v2(v);       for (int i = 0; i < v.size(); i++) {         if (v[i] % (1 << (pow + 1))) {           v2[i] += (1 << pow);         }       }       sort(v2.begin(), v2.end());       v2.erase(unique(v2.begin(), v2.end()), v2.end());       int tmp = 1 + solve(v2, pow + 1);       v2.clear();       for (int i = 0; i < v.size(); i++) {         v2.push_back(v[i]);       }       for (int i = 0; i < v.size(); i++) {         if (v[i] % (1 << (pow + 1))) {           v2[i] -= (1 << pow);         }       }       sort(v2.begin(), v2.end());       v2.erase(unique(v2.begin(), v2.end()), v2.end());       return min(tmp, 1 + solve(v2, pow + 1));     }   }   int main() {     int N;     cin >> N;     vector<int> v(N);     for (int i = 0; i < N; i++) {       cin >> v[i];     }     int ans = solve(v, 0);     cout << ans << endl;     vector<int> lvl(v);     int rank = 0;     while (rank != 20) {       bool fnd = false;       for (int i = 0; i < v.size(); i++) {         if (v[i] % (1 << (rank + 1))) {           fnd = true;         }       }       if (!fnd) {         rank++;       } else {         vector<int> v2(v);         vector<int> v3(v);         for (int i = 0; i < v.size(); i++) {           if (v[i] % (1 << (rank + 1))) {             v2[i] += (1 << rank);           }         }         sort(v2.begin(), v2.end());         v2.erase(unique(v2.begin(), v2.end()), v2.end());         int tmp = 1 + solve(v2, rank + 1);         for (int i = 0; i < v.size(); i++) {           if (v[i] % (1 << (rank + 1))) {             v3[i] -= (1 << rank);           }         }         sort(v3.begin(), v3.end());         v3.erase(unique(v3.begin(), v3.end()), v3.end());         int tmp2 = 1 + solve(v3, rank + 1);         if (tmp < tmp2) {           cout << -(1 << rank) <<    ;           v = v2;         } else {           cout << (1 << rank) <<    ;           v = v3;         }         rank++;       }     }     cout << endl;   }


#include <bits/stdc++.h>      using namespace std;   using ll = long long;      const ll maxc = 1000000, sz = maxc + 5, modint = 998244353;   ll arrleq2[sz] = {}, arr1[sz] = {}, arr2[sz] = {}, arr3[sz] = {};      int main() {       //ios_base::sync_with_stdio(0); cin.tie(0);       arrleq2[0] = 1;       ll sum = 0;       for (int i = 1; i <= maxc; i++) {           arrleq2[i] = arrleq2[i - 1] * (sum + 1) + arrleq2[i - 1] * (arrleq2[i - 1] + 1) / 2;           arrleq2[i] %= modint;           arr3[i] = arrleq2[i - 1] * (arrleq2[i - 1] + 1) / 2 % modint * (arrleq2[i - 1] + 2) % modint;           while (arr3[i] % 3) arr3[i] += modint;           arr3[i] /= 3;           arr3[i] += arrleq2[i - 1] * (arrleq2[i - 1] + 1) / 2 % modint * sum % modint;           arr3[i] += sum * (sum + 1) / 2 % modint * arrleq2[i - 1];           arr3[i] %= modint;           sum += arrleq2[i - 1];           sum %= modint;       }       arr1[0] = 0; arr2[0] = 0;       for (int i = 1; i <= maxc; i++) {           arr1[i] = arrleq2[i - 1];           arr2[i] = (arrleq2[i] - arr1[i] + modint) % modint;       }       //for (int i = 1; i <= 20; i++) cout << arrleq2[i] <<    ; cout <<   n ;       //f//or (int i = 1; i <= 20; i++) cout << arr1[i] <<    ; cout <<   n ;       //for (int i = 1; i <= 20; i++) cout << arr2[i] <<    ; cout <<   n ;       //for (int i = 1; i <= 20; i++) cout << arr3[i] <<    ; cout <<   n ;          int n;       cin >> n;       ll res = arr3[n] * 2 % modint;       for (int i = 0; i <= n; i++) {           if (i == 0) res += arrleq2[n];           else res += arr1[n - i] * arr2[i];           res %= modint;       }       res = (res + arr2[n]) % modint;       cout << res;       return(0);   }


#include <bits/stdc++.h>   using namespace std;   int main(int argc, char** argv) {     int t;     cin >> t;     while (t--) {       long long int n, k;       cin >> n >> k;       long long int q = k / (n - 1);       long long int r = k % (n - 1);       if (r == 0) {         cout << n * q - 1 <<   n ;       } else {         cout << n * q + r <<   n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string res, s[100005], temp, given;   int main() {     std::ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n, pos;     bool valid = false;     temp =  <3 ;     cin >> n;     res =   ;     res += temp;     for (int i = 0; i < n; i++) {       cin >> s[i];       res += s[i];       res += temp;     }     pos = 0;     cin >> given;     for (int i = 0; i < given.length(); i++) {       if (given[i] == res[pos]) pos++;       if (pos == res.length()) {         valid = true;         break;       }     }     if (valid)       cout <<  yes n ;     else       cout <<  no n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     const long long inf = 1e9;     long long n;     cin >> n;     vector<pair<long long, long long> > m(n);     for (int i = 0; i < n; i++) cin >> m[i].first >> m[i].second;     long long maxy = -inf, miny = inf, maxx = -inf, minx = inf;     long long maxyp, maxxp, minxp, minyp;     for (int i = 0; i < n; i++) {       if (maxy < m[i].second) maxyp = i;       if (maxx < m[i].first) maxxp = i;       if (miny > m[i].second) minyp = i;       if (minx > m[i].first) minxp = i;       maxy = max(maxy, m[i].second);       miny = min(miny, m[i].second);       maxx = max(maxx, m[i].first);       minx = min(minx, m[i].first);     }     long long maxans = -inf;     for (int i = 0; i < n; i++) {       maxans = max((maxx - min(m[maxyp].first, m[i].first) + maxy -                     min(m[maxxp].second, m[i].second)) *                        2,                    maxans);       maxans = max((maxx - min(m[minyp].first, m[i].first) +                     max(m[maxxp].second, m[i].second) - miny) *                        2,                    maxans);       maxans = max((max(m[minyp].first, m[i].first) - minx +                     max(m[minxp].second, m[i].second) - miny) *                        2,                    maxans);       maxans = max((max(m[maxyp].first, m[i].first) - minx + maxy -                     min(m[minxp].second, m[i].second)) *                        2,                    maxans);     }     cout << maxans <<    ;     for (int i = 4; i <= n; i++) {       cout << (maxy - miny + maxx - minx) * 2 <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 2097155;   int n, mS;   char s[MAXN], t[MAXN];   long long a[MAXN], b[MAXN], bt[MAXN];   inline void FWT_or(long long *F, int len, int typ) {     for (int i = 0; i < n; ++i) {       for (int S = 0; S < len; ++S) {         if (S >> i & 1) {           F[S] = F[S] + typ * F[S ^ (1 << i)];         }       }     }     return;   }   inline int popcount(int x) {     int cnt = 0;     while (x) {       x -= (x & (-x));       cnt++;     }     return cnt;   }   inline void init() {     bt[0] = 1;     for (int i = 1; i <= n; ++i) bt[i] = bt[i - 1] * 4ll;     return;   }   int main() {     scanf( %d , &n);     scanf( %s , s);     scanf( %s , t);     mS = (1 << n);     init();     for (int i = 0; i < mS; ++i) {       a[i] = (15ll & s[i]) << (popcount(i) << 1);     }     for (int i = 0; i < mS; ++i) {       b[i] = (15ll & t[i]) << (popcount(i) << 1);     }     FWT_or(a, mS, 1);     FWT_or(b, mS, 1);     for (int i = 0; i < mS; ++i) {       a[i] = a[i] * b[i];     }     FWT_or(a, mS, -1);     for (int i = 0; i < mS; ++i) printf( %lld , (a[i] >> (popcount(i) << 1) & 3));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 200005;   long long aa[maxn];   long long bb[maxn];   vector<long long> gou;   int in[maxn << 2];   long long Z[maxn << 2];   set<long long> ans;   int main() {     int n;     long long m;     scanf( %d%lld , &n, &m);     for (int i = 1; i <= n; ++i) scanf( %lld , &aa[i]);     bb[1] = ((aa[1] - aa[n]) + m) % m;     for (int i = 2; i <= n; ++i) bb[i] = ((aa[i] - aa[i - 1]) % m + m) % m;     for (int i = n; i; --i) {       gou.push_back(bb[i]);       in[gou.size() - 1] = i;     }     gou.push_back(-1LL);     for (int i = 1; i <= n; ++i) {       gou.push_back(bb[i]);       in[gou.size() - 1] = i;     }     for (int i = 1; i <= n; ++i) {       gou.push_back(bb[i]);       in[gou.size() - 1] = i;     }     Z[0] = gou.size();     for (int i = 1, j = 1, k; i < (int)gou.size(); i = k) {       j = max(j, i);       while (gou[j] == gou[j - i]) ++j;       Z[i] = j - i;       k = i + 1;       while (k + Z[k - i] < j) {         Z[k] = Z[k - i];         ++k;       }     }     for (int i = 1; i < (int)gou.size(); ++i)       if (Z[i] >= n) ans.insert((aa[in[i] - 1 ? in[i] - 1 : n] + aa[n]) % m);     printf( %d n , (int)ans.size());     for (auto it = ans.begin(); it != ans.end(); ++it) printf( %lld  , *it);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1000 * 100 + 5;   const long long inf = 9223372036854775807;   int n, q, cnt, mark[3][maxn];   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     cin >> n >> q;     for (int i = 1; i <= q; i++) {       int x, y;       cin >> x >> y;       if (mark[x][y] == 0) {         mark[x][y] = 1;         if (mark[3 - x][y] == 1) cnt++;         if (mark[3 - x][y - 1] == 1) cnt++;         if (mark[3 - x][y + 1] == 1) cnt++;       } else {         mark[x][y] = 0;         if (mark[3 - x][y] == 1) cnt--;         if (mark[3 - x][y - 1] == 1) cnt--;         if (mark[3 - x][y + 1] == 1) cnt--;       }       if (cnt > 0)         cout <<  No ;       else         cout <<  Yes ;       cout << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int main(int argc, char* argv[]) {     int n;     scanf( %d , &n);     int c1 = 0, c2 = 0;     for (int i = 0; i < n; ++i) {       int a;       scanf( %d , &a);       if (a == 1)         ++c1;       else         ++c2;     }     int ans = min(c2, c1);     c1 -= ans;     if (c1 > 0) ans += c1 / 3;     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 0x3f3f3f3f;   const long long INF = 0x3f3f3f3f3f3f3f3fll;   const int N = 1e4 + 10;   const int M = 3e6 + 10;   const int maxn = 1e6 + 10;   const int mod = 1000173169;   const double eps = 1e-10;   const double pi = acos(-1.0);   struct Tree {     int num[N << 2], sum[N << 2];     void add(int rt, int l, int r, int p) {       num[rt]++;       sum[rt] += p;       if (l == r) return;       int mid = ((l + r) >> 1);       if (p <= mid)         add(rt << 1, l, mid, p);       else         add(rt << 1 | 1, mid + 1, r, p);     }     int getPos(int rt, int l, int r, int& val) {       if (l == r) return l;       int mid = ((l + r) >> 1);       if (num[rt << 1] >= val)         return getPos(rt << 1, l, mid, val);       else {         val -= num[rt << 1];         return getPos(rt << 1 | 1, mid + 1, r, val);       }     }     int getSum(int rt, int l, int r, int pos) {       if (r <= pos) return sum[rt];       int mid = ((l + r) >> 1);       int res = 0;       if (l <= pos) res = getSum(rt << 1, l, mid, pos);       if (mid < pos) res += getSum(rt << 1 | 1, mid + 1, r, pos);       return res;     }   } seg;   int n, m, k;   vector<int> id;   vector<pair<int, int> > a[3], b, p, res;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n >> m >> k;     int mx = 1e4;     for (int i = 1; i <= n; i++) {       int t, x, y;       cin >> t >> x >> y;       x = x << 1 | y;       if (x == 3)         b.emplace_back(t, i);       else if (x)         a[x].emplace_back(t, i);       else {         seg.add(1, 1, mx, t);         res.emplace_back(t, i);       }     }     sort(a[1].begin(), a[1].end());     sort(a[2].begin(), a[2].end());     sort(b.begin(), b.end());     int cnt1 = 0, cnt2 = 0;     int t1 = min(min(((int)a[1].size()), ((int)a[2].size())), k);     int cur = 0;     for (int i = 0; i < t1; i++) {       cur += a[1][i].first + a[2][i].first;       p.emplace_back(a[1][i].first, a[2][i].first);       cnt1++;       cnt2 += 2;     }     for (int i = t1; i < max(((int)a[1].size()), ((int)a[2].size())); i++) {       if (i < ((int)a[1].size()))         seg.add(1, 1, mx, a[1][i].first), res.push_back(a[1][i]);       if (i < ((int)a[2].size()))         seg.add(1, 1, mx, a[2][i].first), res.push_back(a[2][i]);     }     for (int i = k; i < ((int)b.size()); i++) {       seg.add(1, 1, mx, b[i].first);       res.push_back(b[i]);     }     int P = -1;     long long ans = INF;     int t2 = min(((int)b.size()), k);     for (int i = 0; i <= t2; i++) {       if (cnt1 == k && cnt2 <= m) {         long long res = INF;         if (cnt2 == m)           res = cur;         else if (cnt2 + seg.num[1] >= m) {           int val = m - cnt2;           int pos = seg.getPos(1, 1, mx, val);           res = pos * val + cur;           if (pos > 1) res += seg.getSum(1, 1, mx, pos - 1);         }         if (ans > res) {           ans = res;           P = i;         }       }       if (i < t2) {         if (cnt1 < k) {           cur += b[i].first;           cnt1++;           cnt2++;         } else if (!p.empty()) {           pair<int, int> t = p.back();           p.pop_back();           cur -= t.first + t.second;           seg.add(1, 1, mx, t.first);           seg.add(1, 1, mx, t.second);           cur += b[i].first;           cnt2--;         }       }     }     if (ans == INF)       cout <<  -1 n ;     else {       cout << ans <<   n ;       for (int i = 0; i < P; i++) id.push_back(b[i].second);       for (int i = 0; i < t1; i++) {         if (P + i + 1 <= k) {           id.push_back(a[1][i].second);           id.push_back(a[2][i].second);         } else {           res.push_back(a[1][i]);           res.push_back(a[2][i]);         }       }       sort(res.begin(), res.end());       for (int i = 0; i < ((int)res.size()); i++) {         if (((int)id.size()) == m) break;         id.push_back(res[i].second);       }       for (int v : id) cout << v <<    ;       cout <<   n ;       assert(((int)id.size()) == m);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long read() {     long long num = 0;     int fix = 1;     char ch = getchar();     while (!isdigit(ch)) {       if (ch ==  - ) fix = -1;       ch = getchar();     }     while (isdigit(ch)) {       num = num * 10 + ch -  0 ;       ch = getchar();     }     return num * fix;   }   const int mod = 1e9 + 7;   const int MAXN = 50;   int N, K;   int W[MAXN + 1];   long long fact[MAXN + 1], inv[MAXN + 1];   struct data {     int x, y, pos;   };   long long power(long long x, long long y) {     long long res = 1;     while (y) {       if (y & 1) res = res * x % mod;       x = x * x % mod;       y >>= 1;     }     return res;   }   void initial() {     fact[0] = 1;     for (int i = 1; i <= MAXN; i++) {       fact[i] = fact[i - 1] * i % mod;     }     inv[MAXN] = power(fact[MAXN], mod - 2);     for (int i = MAXN - 1; i >= 0; i--) {       inv[i] = inv[i + 1] * (i + 1) % mod;     }   }   int flag = -1;   int dp[MAXN + 1][MAXN + 1][2];   long long num[MAXN + 1][MAXN + 1][2];   long long C(int x, int y) { return fact[y] * inv[x] % mod * inv[y - x] % mod; }   void BFS(int a, int b) {     memset(dp, -1, sizeof(dp));     dp[a][b][0] = 0, num[a][b][0] = 1;     queue<data> que;     que.push((data){a, b, 0});     while (!que.empty()) {       if (flag != -1 && que.front().pos == flag) break;       data cur = que.front();       que.pop();       int x, y, fix;       if (cur.pos)         x = a - cur.x, y = b - cur.y, fix = 1;       else         x = cur.x, y = cur.y, fix = -1;       for (int i = 0; i <= x; i++) {         for (int j = 0; j <= y; j++) {           if (i + j == 0) continue;           if (i * 50 + j * 100 > K) continue;           int newx = cur.x + i * fix, newy = cur.y + j * fix;           if (dp[newx][newy][cur.pos ^ 1] != -1) {             if (dp[newx][newy][cur.pos ^ 1] == dp[cur.x][cur.y][cur.pos] + 1) {               (num[newx][newy][cur.pos ^ 1] +=                num[cur.x][cur.y][cur.pos] * C(i, x) % mod * C(j, y) % mod) %= mod;             }             continue;           }           dp[newx][newy][cur.pos ^ 1] = dp[cur.x][cur.y][cur.pos] + 1;           num[newx][newy][cur.pos ^ 1] =               num[cur.x][cur.y][cur.pos] * C(i, x) % mod * C(j, y) % mod;           if (newx + newy == 0) {             flag = !cur.pos;           }           que.push((data){newx, newy, cur.pos ^ 1});         }       }     }   }   void solve() {     int cnt50 = 0, cnt100 = 0;     for (int i = 1; i <= N; i++) {       if (W[i] == 50) cnt50++;       if (W[i] == 100) cnt100++;     }     BFS(cnt50, cnt100);     if (flag == -1) {       puts( -1 );       puts( 0 );       return;     }     printf( %d n , dp[0][0][flag]);     printf( %lld n , num[0][0][flag]);   }   int main() {     initial();     N = read(), K = read();     for (int i = 1; i <= N; i++) {       W[i] = read();     }     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char b[101];   char a[101][101];   int mark[101];   int main() {     int n, m, s = 0;     cin >> n >> m;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         cin >> a[i][j];         if (a[i][j] > b[j]) {           b[j] = a[i][j];         }       }     }     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         if (a[i][j] == b[j]) {           if (mark[i] == 0) {             s++;             mark[i]++;           }         }       }     }     cout << s;   }


#include <bits/stdc++.h>   using namespace std;   const double PI = acos(-1.0);   const int INF = 0x3f3f3f3f;   const double eps = 1e-8;   const int MAXN = 50 + 10;   const int MOD = 29;   const int dir[][2] = {{-1, 0}, {0, -1}, {1, 0}, {0, 1}};   int cases = 0;   int vis[MAXN][MAXN], row, col;   char mp[MAXN][MAXN];   bool DFS(int x, int y, char color, int step) {     for (int i = 0; i < 4; i++) {       int xx = x + dir[i][0], yy = y + dir[i][1];       if (xx < 0 || xx >= row || yy < 0 || yy >= col) continue;       if (mp[xx][yy] != color) continue;       if (vis[xx][yy]) {         if (mp[xx][yy] != color || step - vis[xx][yy] == 1) continue;         return true;       }       vis[xx][yy] = step + 1;       if (DFS(xx, yy, color, step + 1)) return true;     }     return false;   }   int main() {     scanf( %d%d , &row, &col);     for (int i = 0; i < row; i++) scanf( %s , mp[i]);     bool flag = false;     for (int i = 0; i < row; i++)       for (int j = 0; j < col; j++) {         if (!vis[i][j]) {           vis[i][j] = 1;           flag = DFS(i, j, mp[i][j], 1);         }         if (flag) {           puts( Yes );           return 0;         }       }     puts( No );     return 0;   }


#include <bits/stdc++.h>   const int MAX_N = 20;   int n, k, t;   int e[MAX_N + 1][MAX_N + 1];   int choosen[MAX_N + 1];   int mid;   int cnt;   void dfs(int x, int now_cost_sum) {     if (x > n) {       cnt++;       return;     }     dfs(x + 1, now_cost_sum);     for (int y = 1; y <= n && cnt < t; y++) {       if (!choosen[y] && e[x][y] && now_cost_sum + e[x][y] <= mid) {         choosen[y] = 1;         dfs(x + 1, now_cost_sum + e[x][y]);         choosen[y] = 0;       }     }   }   int main() {     scanf( %d%d%d , &n, &k, &t);     for (int i = 1; i <= k; i++) {       int h, w, r;       scanf( %d%d%d , &h, &w, &r);       e[h][w] = r;     }     int low = 0, high = 1000 * n;     while (low < high) {       mid = (low + high) >> 1;       cnt = 0;       dfs(1, 0);       if (cnt >= t)         high = mid;       else         low = mid + 1;     }     printf( %d n , low);   }


#include <bits/stdc++.h>   using namespace std;   map<string, long long> mp;   string S[1006];   long long cost[1006];   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     int N, i, j, k;     cin >> N;     mp[ A ] = 1e9;     mp[ B ] = 1e9;     mp[ C ] = 1e9;     mp[ AB ] = 1e9;     mp[ AC ] = 1e9;     mp[ BC ] = 1e9;     mp[ ABC ] = 1e9;     for (i = 1; i <= N; i++) {       cin >> cost[i] >> S[i];       sort(S[i].begin(), S[i].end());       mp[S[i]] = min(mp[S[i]], cost[i]);     }     mp[ AB ] = min(mp[ AB ], mp[ A ] + mp[ B ]);     mp[ AC ] = min(mp[ AC ], mp[ A ] + mp[ C ]);     mp[ BC ] = min(mp[ BC ], mp[ B ] + mp[ C ]);     mp[ ABC ] = min(mp[ ABC ], mp[ AB ] + mp[ C ]);     mp[ ABC ] = min(mp[ ABC ], mp[ A ] + mp[ BC ]);     mp[ ABC ] = min(mp[ ABC ], mp[ AC ] + mp[ B ]);     mp[ ABC ] = min(mp[ ABC ], mp[ AB ] + mp[ BC ]);     mp[ ABC ] = min(mp[ ABC ], mp[ AC ] + mp[ BC ]);     mp[ ABC ] = min(mp[ ABC ], mp[ AB ] + mp[ AC ]);     mp[ ABC ] = min(mp[ ABC ], mp[ A ] + mp[ B ] + mp[ C ]);     if (mp[ ABC ] >= (long long)1e9)       printf( -1 n );     else       printf( %d n , mp[ ABC ]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1000010;   const int MOD = 1e9 + 7;   int n, m;   vector<int> tmp;   vector<int> g[N];   int cnt1[N];   int marked[N];   int f[N];   map<vector<int>, int> cnt;   int product(int a, int b) { return (1ll * a * b) % MOD; }   void mult(int &a, int b) { a = (1ll * a * b) % MOD; }   int main() {     f[0] = 1;     for (int i = 1; i < N; i++) f[i] = product(f[i - 1], i);     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) {       int k;       scanf( %d , &k);       for (int j = 0; j < k; j++) {         int x;         scanf( %d , &x);         g[x].push_back(i);       }     }     for (int i = 1; i <= m; i++) cnt[g[i]]++;     int ans = 1;     for (auto p : cnt) {       mult(ans, f[p.second]);     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   #pragma comment(linker,  /STACK:1000000000 )   static long long m1[70][70];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     m1[0][0] = 1;     for (int i = 1; i <= 30; ++i) {       m1[i][0] = 1;       for (int j = 1; j <= 30; ++j) m1[i][j] = m1[i - 1][j - 1] + m1[i - 1][j];     }     long long n, m, t, r = 0;     cin >> n >> m >> t;     for (int i = 4; i < t; ++i)       if (t - i >= 0) r += m1[n][i] * m1[m][t - i];     cout << r << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int N, M;   char in[2010][2010];   int deg[2010][2010];   pair<int, int> Q[4000010];   int QL, QR, FREE;   int sft[4][2] = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};   int get(int x, int y) {     if (x < 0 || x >= N || y < 0 || y >= M) return  * ;     return in[x][y];   }   void say_no() {     puts( Not unique );     exit(0);   }   void put(pair<int, int> a, pair<int, int> b) {     if (a > b) swap(a, b);     if (a.first == b.first)       in[a.first][a.second] =  < , in[b.first][b.second] =  > ;     else       in[a.first][a.second] =  ^ , in[b.first][b.second] =  v ;   }   int main() {     scanf( %d%d , &N, &M);     for (int i = 0; i < N; ++i) scanf( %s , &in[i]);     for (int i = 0; i < N; ++i)       for (int j = 0; j < M; ++j) {         if (in[i][j] ==  * )           deg[i][j] = -1;         else           for (int p = 0; p < 4; ++p)             if (get(i + sft[p][0], j + sft[p][1]) ==  . ) ++deg[i][j];         if (deg[i][j] == 1) Q[QR++] = make_pair(i, j);         if (deg[i][j] >= 0) ++FREE;       }     while (QL < QR) {       pair<int, int> a = Q[QL++];       if (deg[a.first][a.second] != 1) continue;       pair<int, int> b(-1, -1);       for (int p = 0; p < 4; ++p)         if (get(a.first + sft[p][0], a.second + sft[p][1]) ==  . )           b = make_pair(a.first + sft[p][0], a.second + sft[p][1]);       if (b.first < 0) say_no();       deg[a.first][a.second] = -1;       deg[b.first][b.second] = -1;       put(a, b);       FREE -= 2;       for (int p = 0; p < 4; ++p)         if (get(a.first + sft[p][0], a.second + sft[p][1]) ==  . ) {           int x = a.first + sft[p][0];           int y = a.second + sft[p][1];           --deg[x][y];           if (deg[x][y] == 1) Q[QR++] = make_pair(x, y);         }       for (int p = 0; p < 4; ++p)         if (get(b.first + sft[p][0], b.second + sft[p][1]) ==  . ) {           int x = b.first + sft[p][0];           int y = b.second + sft[p][1];           --deg[x][y];           if (deg[x][y] == 1) Q[QR++] = make_pair(x, y);         }     }     if (FREE != 0) say_no();     for (int i = 0; i < N; ++i) {       for (int j = 0; j < M; ++j) printf( %c , in[i][j]);       puts(  );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, p;   int sum, mx;   vector<int> ans;   int32_t main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n;     for (int i = (1); i <= (n); i++) {       if (i == 1) {         cin >> p;         ans.push_back(1);         sum += p;         mx += p;       } else {         int x;         cin >> x;         mx += x;         if (x <= p / 2) {           ans.push_back(i);           sum += x;         }       }     }     if (sum <= mx / 2)       cout << 0;     else {       cout << (int)ans.size() <<   n ;       for (int x : ans) cout << x <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e4 + 9;   struct Point {     int col, id;     int x, y;     bool operator<(const Point& b) {       if (x == b.x) return y < b.y;       return x < b.x;     }   } p0, p[N * 2];   int cross(Point a, Point b, Point c) {     return (b.x - a.x) * (c.y - a.y) - (c.x - a.x) * (b.y - a.y);   }   bool cmpang(Point a, Point b) { return cross(p0, a, b) > 0; }   int ans[N];   void solve(int L, int R) {     int c = L;     for (int i = L; i <= R; ++i)       if (p[i] < p[c]) c = i;     swap(p[c], p[L]);     p0 = p[L];     sort(p + L + 1, p + R + 1, cmpang);     int a1 = 0, a0 = 0;     int k = 1000000;     int mid = (L + R) >> 1;     for (int i = L + 1; i <= R; ++i) {       if (a1 == a0 && p[i].col != p0.col) {         k = i;         break;       }       if (p[i].col)         ++a1;       else         ++a0;     }     if (p0.col)       ans[p[k].id] = p0.id;     else       ans[p0.id] = p[k].id;     if (L + 1 < k - 1) solve(L + 1, k - 1);     if (k + 1 < R) solve(k + 1, R);   }   inline int read() {     char ch = getchar();     int x = 0, f = 1;     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while ( 0  <= ch && ch <=  9 ) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     return x * f;   }   int main() {     int n = read();     for (int i = 1; i <= n; ++i) {       p[i].x = read();       p[i].y = read();       p[i].col = 0;       p[i].id = i;     }     for (int i = 1; i <= n; ++i) {       p[i + n].x = read();       p[i + n].y = read();       p[i + n].col = 1;       p[i + n].id = i;     }     solve(1, 2 * n);     for (int i = 1; i <= n; ++i) cout << ans[i] <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   void factorize(long long v, std::map<long long, int> &result) {     long long p = 2;     while (v > 1 && p * p <= v) {       int cnt = 0;       while (v % p == 0) {         cnt++;         v /= p;       }       if (cnt > 0) {         if (result.count(p) == 0) {           result[p] = 0;         }         result[p] += cnt;       }       p += p == 2 ? 1 : 2;     }     if (v > 1) {       if (result.count(v) == 0) {         result[v] = 0;       }       result[v] += 1;     }   }   long long int ex_gcd(long long int x, long long int y, long long int &a,                        long long int &b) {     if (y == 0) {       a = 1;       b = 0;       return x;     }     long long int q = x / y;     long long int r = x % y;     long long int res = ex_gcd(y, r, a, b);     long long int tmp = a - q * b;     a = b;     b = tmp;     return res;   }   const int N = 123456;   int n;   long long int p;   vector<long long int> q;   vector<int> e;   long long int fact[N];   long long int invfact[N];   vector<int> fact_e[N];   void init(void) {     map<long long int, int> factor;     factorize(p, factor);     for (map<long long int, int>::iterator it = factor.begin();          it != factor.end(); ++it) {       q.push_back(it->first);       e.push_back(it->second);     }     int l = e.size();     fact_e[0] = vector<int>(l, 0);     fact[0] = invfact[0] = 1;     for (int i = (int)(1); i < (int)(N); i++) {       int v = i;       fact_e[i] = fact_e[i - 1];       for (int j = (int)(0); j < (int)(l); j++) {         while (v % q[j] == 0) {           fact_e[i][j] += 1;           v /= q[j];         }       }       fact[i] = fact[i - 1] * v % p;       long long int dummy2;       long long int dummy = ex_gcd(fact[i], p, invfact[i], dummy2);       assert(dummy == 1);       invfact[i] = (invfact[i] % p + p) % p;     }   }   long long int tri_comb(int x, int y) {     long long int t = 1;     int len = e.size();     t = (fact[n] * invfact[x]) % p;     t = t * invfact[y] % p;     t = t * invfact[n - x - y] % p;     vector<int> es(len);     for (int i = (int)(0); i < (int)(len); i++) {       es[i] = fact_e[n][i] - fact_e[x][i] - fact_e[y][i] - fact_e[n - x - y][i];       for (int j = (int)(0); j < (int)(es[i]); j++) {         t = t * q[i] % p;       }     }     return t;   }   long long int calc(int l) {     long long int tot = 0;     for (int i = (int)(0); i < (int)(n - l + 1); i++) {       if ((n + i + l) % 2 == 0) {         tot = (tot + tri_comb(i, (n - i - l) / 2)) % p;       }     }     return tot;   }   int main(void) {     ios::sync_with_stdio(false);     cin.tie(0);     int l, r;     cin >> n >> p >> l >> r;     init();     cout << (calc(l) + calc(l + 1) - calc(r + 1) - calc(r + 2) + 2 * p) % p          <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 200005;   const int LOGN = 18;   int n, q, p[N], stk[N], L[LOGN][N], R[LOGN][N];   long long a[N], b[N], LC[LOGN][N], RC[LOGN][N];   inline long long getdist(int u, int v) {    long long ret = 0;    for (int i = LOGN - 1; i >= 0; i--) if (R[i][u] <= v) {     ret += RC[i][u];     u = R[i][u];    }    if (u == v) return ret;    for (int i = LOGN - 1; i >= 0; i--) if (L[i][v] >= u) {     ret += LC[i][v];     v = L[i][v];    }    return ret;   }   int main() {    scanf( %d%d , &n, &q);    for (int i = 1; i <= n; i++) scanf( %d , &p[i]);    p[n + 1] = n + 1;    for (int i = 1; i <= n; i++) scanf( %lld , &a[i]);    for (int i = 1; i <= n; i++) scanf( %lld , &b[i]);    int tp = 0;    stk[++tp] = n + 1;    for (int j = 0; j < LOGN; j++) {     R[j][n + 1] = n + 1;     RC[j][n + 1] = 0;    }    for (int i = n; i >= 1; i--) {     while (tp && p[stk[tp]] < p[i]) tp--;     R[0][i] = stk[tp];     RC[0][i] = b[i] = min(b[i], a[i] + getdist(i + 1, stk[tp]));     for (int j = 1; j < LOGN; j++) {      R[j][i] = R[j - 1][R[j - 1][i]];      RC[j][i] = RC[j - 1][i] + RC[j - 1][R[j - 1][i]];     }     stk[++tp] = i;    }    tp = 0;    stk[++tp] = 1;    for (int j = 0; j < LOGN; j++) {     L[j][1] = L[j][0] = 0;     LC[j][1] = 0;    }    for (int i = 2; i <= n + 1; i++) {     while (tp && p[stk[tp]] < p[i]) tp--;     L[0][i] = tp ? stk[tp] : 0;     LC[0][i] = tp ? a[stk[tp]] + getdist(stk[tp] + 1, i) : 0;     for (int j = 1; j < LOGN; j++) {      L[j][i] = L[j - 1][L[j - 1][i]];      LC[j][i] = LC[j - 1][i] + LC[j - 1][L[j - 1][i]];     }     stk[++tp] = i;    }    set<int> st;    st.insert(1);    st.insert(n + 1);    long long sum = getdist(1, n + 1);    while (q--) {     int x;     scanf( %d , &x);     if (x != 1) {      if (st.count(x)) {       auto it = st.find(x);       int prv = *prev(it), nxt = *next(it);       sum += getdist(prv, nxt);       sum -= getdist(prv, x);       sum -= getdist(x, nxt);       st.erase(it);      } else {       auto it = st.insert(x).first;       int prv = *prev(it), nxt = *next(it);       sum -= getdist(prv, nxt);       sum += getdist(prv, x);       sum += getdist(x, nxt);      }     }     printf( %lld n , sum);    }    return 0;   }


#include <bits/stdc++.h>   using namespace std;   void __print(int x) { cout << x; }   void __print(long x) { cout << x; }   void __print(long long x) { cout << x; }   void __print(unsigned x) { cout << x; }   void __print(unsigned long x) { cout << x; }   void __print(unsigned long long x) { cout << x; }   void __print(float x) { cout << x; }   void __print(double x) { cout << x; }   void __print(long double x) { cout << x; }   void __print(char x) { cout <<      << x <<     ; }   void __print(const char *x) { cout <<     << x <<    ; }   void __print(const string &x) { cout <<     << x <<    ; }   void __print(bool x) { cout << (x ?  true  :  false ); }   void _print() { cout <<  ] n ; }   template <typename T, typename... V>   void _print(T t, V... v) {     __print(t);     if (sizeof...(v)) cout <<  ,  ;     _print(v...);   }   const long long int dx4[4] = {+1, -1, 0, 0};   const long long int dy4[4] = {0, 0, +1, -1};   const long long int dx8[8] = {-1, -1, -1, 0, 0, 1, 1, 1};   const long long int dy8[8] = {-1, 0, 1, -1, 1, -1, 0, 1};   const long long int MOD = 1e9 + 7;   const long long int INF = 1e10;   const long long int N = 2e5 + 5;   void solve() {     long long int n;     string s;     cin >> n >> s;     map<char, long long int> cnt;     for (auto x : s) cnt[x]++;     for (auto x : cnt)       while (x.second) cout << x.first, x.second--;     return;   }   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long int t = 1;     while (t--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 450000 + 100;   int n, k;   vector<int> pos[maxn];   int a[maxn];   int b[maxn];   int v[maxn];   int main() {     while (cin >> n >> k) {       for (int i = 1; i <= n; i++) {         cin >> a[i];         v[i] = a[i];         pos[i].push_back(0);       }       pos[0].push_back(0);       int tot = n;       sort(v + 1, v + n + 1);       tot = unique(v + 1, v + n + 1) - (v + 1);       for (int i = 1; i <= n; i++) {         a[i] = lower_bound(v + 1, v + 1 + tot, a[i]) - (v + 1) + 1;       }       long long mx = 0, ans = 0;       for (int i = 1; i <= n; i++) {         int v = a[i];         pos[v].push_back(i);         int sz = pos[v].size();         while (b[v] + k < sz) {           b[v]++;         }         mx = max(mx, (long long)pos[v][b[v]]);         ans += mx;       }       cout << ans << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   string s;   long long ans, i, l, n, d, m;   int main() {     cin >> n >> m;     for (i = 1; i < n; i++) {       cin >> s;     }     cin >> s;     for (i = 1; i < s.size(); i++) {       if (s[i] != s[i - 1]) ans++;     }     if (ans % 2 == 0) {       ans /= 2;       if (s[0] ==  B ) ans++;     } else {       ans++;       ans /= 2;     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   inline void input(T &x) {     register char c = getchar();     x = 0;     int neg = 0;     for (; ((c < 48 || c > 57) && c !=  - ); c = getchar())       ;     if (c ==  - ) {       neg = 1;       c = getchar();     }     for (; c > 47 && c < 58; c = getchar()) {       x = (x << 1) + (x << 3) + c - 48;     }     if (neg) x = -x;   }   inline long long bigmod(long long p, long long e, long long M) {     long long ret = 1;     for (; e > 0; e >>= 1) {       if (e & 1) ret = (ret * p) % M;       p = (p * p) % M;     }     return ret;   }   template <class T>   inline T gcd(T a, T b) {     if (b == 0) return a;     return gcd(b, a % b);   }   template <class T>   inline T modinverse(T a, T M) {     return bigmod(a, M - 2, M);   }   const int N = 1e6 + 6;   char str[N], inp[26];   int qu[10001];   int main() {     scanf( %s , str);     int n = strlen(str);     int q;     input(q);     int mask = 0;     unordered_map<int, int> Map;     for (int t = 0; t < q; t++) {       scanf( %s  , inp);       mask = 0;       for (int i = 0; inp[i]; i++) {         mask |= 1 << inp[i] -  a ;       }       qu[t] = mask;       Map[mask] = 0;     }     for (int i = 0; i < n; i++) {       mask = 0;       for (int j = i; j < n; j++) {         if (i < j && str[i] == str[j]) break;         mask |= 1 << str[j] -  a ;         if (j + 1 == n || (mask & 1 << str[j + 1] -  a ) == 0)           if (Map.count(mask)) Map[mask]++;       }     }     for (int i = 0; i < q; i++) {       printf( %d n , Map[qu[i]]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using lli = long long int;   using pii = pair<int, int>;   using vi = vector<int>;   using vb = vector<bool>;   using vvi = vector<vector<int>>;   using vlli = vector<long long int>;   using vpii = vector<pair<int, int>>;   lli n, m, k, u, v, x, ans, curr, T;   vlli c;   lli fast_exp(lli base, lli exp) {     lli res = 1;     base = base % 1000000007;     while (exp > 0) {       if (exp % 2) res = (res * base) % 1000000007;       base = (base * base) % 1000000007;       exp /= 2;     }     return res % 1000000007;   }   template <class T>   struct DSU {     map<T, T> par;     T comp_sz = n;     T get(T u) {       if (par.find(u) == par.end()) return u;       return par[u] = get(par[u]);     }     void unite(T x, T y) {       T X = get(x), Y = get(y);       if (X == Y) return;       par[Y] = X;       --comp_sz;     }   };   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n >> m >> k;     c.resize(n + 1);     map<lli, DSU<lli>> virus;     for (int i = 1; i <= n; i++) cin >> c[i];     for (int i = 1; i <= m; i++) {       cin >> u >> v;       x = c[u] ^ c[v];       virus[x].unite(u, v);     }     ans = ((fast_exp(2, k) - virus.size() + 1000000007) * fast_exp(2, n)) %           1000000007;     for (auto i : virus) {       curr = (i.second).comp_sz;       ans = (ans + fast_exp(2, curr)) % 1000000007;     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   int n, a[1111], f[1111];   int main() {     cin >> n;     for (int i = 0; i < n; ++i) cin >> a[i];     for (int day = 1000; day >= 1; --day) {       for (int i = 0; i < n; ++i) f[i] = 0;       f[0] = (day <= a[0]);       for (int i = 1; i < n; ++i) {         if (day > a[i]) continue;         f[i] |= f[i - 1];         if (i > 1) f[i] |= f[i - 2];       }       if (f[n - 1]) {         cout << day << endl;         return 0;       }     }   }


#include <bits/stdc++.h>   using namespace std;   string str, queries[100010];   int n;   unsigned long long values[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};   unsigned long long length[10] = {10, 10, 10, 10, 10, 10, 10, 10, 10, 10};   int main() {     cin >> str >> n;     queries[0] =  0->  + str;     for (int i = 0; i < n; i++) {       cin >> queries[i + 1];     }     for (int i = n; i >= 0; i--) {       unsigned long long len = 1, val = 0;       for (int j = 3; j < queries[i].size(); ++j) {         int d = queries[i][j] -  0 ;         val = (val * length[d] + values[d]) % 1000000007;         len = len * length[d] % 1000000007;       }       length[queries[i][0] -  0 ] = len;       values[queries[i][0] -  0 ] = val;     }     cout << values[0] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int h, m;     while (scanf( %d:%d , &h, &m) == 2) {       int a;       scanf( %d , &a);       int t = (h * 60 + m + a) % (24 * 60);       printf( %02d:%02d n , t / 60, t % 60);     }   }


#include <bits/stdc++.h>   using namespace std;   const int nax = 1000 * 1007;   long long int revi(long long int i) {     long long int rev = 0;     while (i > 0) {       rev = (rev * 10) + (i % 10);       i = i / 10;     }     return rev;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long int n;     cin >> n;     long long int a[n];     for (int i = 0; i < n; i++) {       cin >> a[i];       a[i] = abs(a[i]);     }     sort(a, a + n);     long long int l = 0, ans = 0;     for (int i = 0; i < n; i++) {       while (2 * a[l] < a[i]) l++;       ans = ans + (i - l);     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     string str;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> str;       sort(str.begin(), str.end());       for (int j = 0; j < str.size() - 1; j++) {         if (str[j + 1] - str[j] != 1) {           cout <<  NO                 <<   n ;           break;         } else if (j == str.size() - 2) {           cout <<  YES                 <<   n ;         }       }       if (str.size() == 1) {         cout <<  YES               <<   n ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2 * 1000 * 100 + 100;   long long nums[maxn];   long long ans = 0;   long long cou[30];   int main() {     int n;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> nums[i];       cou[nums[i] + 10]++;     }     ans += (cou[0 + 10] * (cou[10] - 1)) / 2;     for (int i = 1; i < 11; i++) {       ans += cou[i + 10] * cou[-i + 10];     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int l, r;     cin >> l >> r;     if (l == r) {       cout << l << endl;       return 0;     } else {       cout <<  2  << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int const N = 8;   char a[N][N + 1];   int d[N * N][N][N];   inline int in(int x) { return x >= 0 && x < N; }   int main() {     for (int i = 0; i < N; ++i) scanf( %s , a[i]);     for (int i = 0; i < N; ++i)       for (int j = 0; j < N; ++j) d[0][i][j] = (a[i][j] ==  M );     for (int i = 0; i + 1 < N * N; ++i) {       for (int j = 0; j < N; ++j)         for (int k = 0; k < N; ++k) {           if (a[j][k] ==  A  && d[i][j][k]) {             cout <<  WIN n ;             return 0;           }           if (a[j][k] ==  S  && in(j + i)) d[i][j + i][k] = 0;         }       for (int j = 0; j < N; ++j)         for (int k = 0; k < N; ++k)           if (d[i][j][k])             for (int dx = -1; dx <= 1; ++dx)               for (int dy = -1; dy <= 1; ++dy)                 if (in(j + dx) && in(k + dy) &&                     (!in(j + dx - i) || a[j + dx - i][k + dy] !=  S ))                   d[i + 1][j + dx][k + dy] = 1;     }     printf( LOSE n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using LL = long long;   using ULL = unsigned long long;   using VI = vector<int>;   using VL = vector<LL>;   using PII = pair<int, int>;   using PLL = pair<LL, LL>;   void dout() { cerr << endl; }   template <typename Head, typename... Tail>   void dout(Head H, Tail... T) {     cerr << H <<    ;     dout(T...);   }   const int MAX = 1 << 10;   int a[MAX][MAX];   set<int> s[MAX];   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int n, m, k;     cin >> n >> m >> k;     for (int i = (0); i < (n); ++i)       for (int j = (0); j < (m); ++j) {         cin >> a[i][j];         if (a[i][j] != 2) s[j].insert(i);       }     while (k--) {       int c;       cin >> c;       c--;       int r = 0;       while (true) {         auto it = s[c].lower_bound(r);         if (it == s[c].end()) break;         int nr = *it;         int& na = a[nr][c];         s[c].erase(it);         if (na == 1) {           c++;         } else {           assert(na == 3);           c--;         }         na = 2;         r = nr;       }       cout << c + 1 <<    ;     }     cout <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int t, n, i, min1, min2, max1, max2, a[10000], b[10000];     cin >> n;     t = n;     while (n--) {       cin >> a[i] >> b[i];       i++;     }     max1 = a[0];     max2 = b[0];     min1 = a[0];     min2 = b[0];     for (i = 0; i < t; i++) {       if (a[i] > max1) max1 = a[i];       if (b[i] > max2) max2 = b[i];       if (a[i] <= min1) min1 = a[i];       if (b[i] <= min2) min2 = b[i];     }     max1 = max1 - min1;     max2 = max2 - min2;     if (max1 >= max2)       cout << max1 * max1;     else       cout << max2 * max2;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 0x7f7f7f7f;   const double EPS = 1e-8;   int n, m;   int ans[707][707][3];   bool used[707];   int start;   void DFS(int v, int len = 0) {     used[v] = true;     for (int i = 0; i < n; i++) {       if (ans[v][i][0] && !used[v]) {         DFS(i, len + 1);       }     }     used[v] = false;   }   int main() {     scanf( %d %d , &n, &m);     for (int i = 0; i < m; i++) {       int a, b;       scanf( %d %d , &a, &b);       --a;       --b;       ans[a][b][0] = ans[b][a][0] = 1;     }     for (int i = 0; i < n; i++) {       used[i] = true;       for (int u = 0; u < n; u++) {         if (ans[i][u][0]) {           used[u] = true;           for (int t = 0; t < n; t++) {             if (ans[u][t][0] && !used[t]) ++ans[i][t][1];           }           used[u] = false;         }       }       used[i] = false;     }     long long sum = 0;     for (int i = 0; i < n; i++) {       used[i] = true;       for (int u = 0; u < n; u++) {         if (ans[i][u][0]) {           used[u] = true;           for (int t = 0; t < n; t++) {             if (!used[t]) {               ans[i][t][2] += ans[u][t][1];               if (ans[i][t][0]) --ans[i][t][2];             }           }           used[u] = false;         }       }       used[i] = false;     }     for (int i = 0; i < n; i++) {       used[i] = true;       for (int u = 0; u < n; u++) {         if (ans[i][u][0]) {           used[u] = true;           for (int t = 0; t < n; t++) {             if (!used[t] && ans[i][t][0]) {               sum += ans[u][t][2];               int minus = 0;               if (ans[u][t][0]) minus = 1;               sum -= (long long)(max(0, ans[i][u][1] - minus)) +                      (max(0, ans[i][t][1] - minus));             }           }           used[u] = false;         }       }       used[i] = false;     }     cout << sum / 5 / 2 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   pair<long long, long long> sn[100005], sp[100005];   bool myfunction(pair<long long, long long> i, pair<long long, long long> j) {     return (i.first > j.first);   }   int main() {     int n, p, a, first = 0, second = 0;     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d%d , &p, &a);       if (p < 0) {         first++;         sn[first] = make_pair(p, a);       } else {         second++;         sp[second] = make_pair(p, a);       }     }     sort(sn, sn + first + 1, myfunction);     sort(sp, sp + second + 1);     for (int i = 1; i <= first; i++) sn[i].second += sn[i - 1].second;     for (int i = 1; i <= second; i++) sp[i].second += sp[i - 1].second;     sn[first + 1] = sn[first];     sp[second + 1] = sp[second];     int m = min(first, second);     long long ans = sp[m + 1].second + sn[m].second;     ans = max(ans, sp[m].second + sn[m + 1].second);     printf( %I64d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1000010;   const long long inf = (1ll << 58ll);   int k, n, q;   int ten[10] = {1, 10, 100, 1000, 10000, 100000};   long long F[7];   long long dp[maxn], g[7][maxn];   long long read() {     long long s = 0, f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       s = s * 10 + ch -  0 ;       ch = getchar();     }     return s * f;   }   int main() {     k = read();     for (int i = 0; i < 6; ++i) F[i] = read();     fill(dp, dp + 1 + 999999, -inf);     dp[0] = 0;     for (int d = 1; d <= 6; ++d) {       long long left = 1ll * 3 * (k - 1);       long long group = 1ll;       while (left > 0) {         group = min(group, left);         long long val = 1ll * group * F[d - 1];         long long wei = 1ll * 3 * group * ten[d - 1];         for (int i = 999999; i >= wei; --i) {           dp[i] = max(dp[i], dp[i - wei] + val);         }         left -= group;         group *= 2;       }     }     for (int i = 1; i <= 6; ++i) fill(g[i], g[i] + 1000000, -inf);     for (int i = 0; i <= 999999; ++i) g[0][i] = dp[i];     for (int d = 1; d <= 6; ++d) {       for (int j = 0; j <= 9; ++j) {         long long val, wei;         if (j == 3 || j == 6 || j == 9)           val = 1ll * (j / 3) * F[d - 1];         else           val = 0;         wei = 1ll * j * ten[d - 1];         for (int i = 999999; i >= wei; i--)           g[d][i] = max(g[d][i], g[d - 1][i - wei] + val);       }     }     q = read();     for (int i = 1; i <= q; ++i) {       n = read();       printf( %lld n , g[6][n]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, c[205], num = 1e9;   vector<int> a, ans;   void dfs(int n, vector<int> a, int d, int t) {     if (n == 0) {       if (d < num) {         ans.clear();         num = d;         for (int i = 0; i < d; i++) ans.push_back(c[i]);       }       return;     }     int m = a.size();     bool f = 1;     for (int i = 0; i < m; i++)       if (a[i] % 2 != 0) {         f = 0;         break;       }     if (f) {       for (int i = 0; i < m; i++) a[i] /= 2;       return dfs(n / 2, a, d, t + 1);     }     if (m == 2 && a[0] == 0 && a[1] == 1 || m == 1 && a[0] == 1) {       c[d] = 1 << t;       return dfs(0, a, d + 1, t + 1);     }     if (m == 2 && a[0] == -1 && a[1] == 0 || m == 1 && a[0] == -1) {       c[d] = -(1 << t);       return dfs(0, a, d + 1, t + 1);     }     vector<int> b;     b.clear();     int lst = -1e9;     for (int i = 0; i < m; i++) {       int u = a[i];       if (u % 2 == 0)         u /= 2;       else         u = (u - 1) / 2;       if (u != lst) {         b.push_back(u);         lst = u;       }     }     c[d] = 1 << t;     dfs((n + 1) / 2, b, d + 1, t + 1);     b.clear();     lst = -1e9;     for (int i = 0; i < m; i++) {       int u = a[i];       if (u % 2 == 0)         u /= 2;       else         u = (u + 1) / 2;       if (u != lst) {         b.push_back(u);         lst = u;       }     }     c[d] = -(1 << t);     dfs((n + 1) / 2, b, d + 1, t + 1);   }   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) {       int x;       scanf( %d , &x);       a.push_back(x);     }     sort(a.begin(), a.end());     dfs(100000, a, 0, 0);     printf( %d n , ans.size());     for (int i = 0; i < ans.size(); i++) printf( %d  , ans[i]);     printf(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, m, ans;   int main() {     scanf( %I64d%I64d , &n, &m);     if (n > m) swap(n, m);     if (n == 2) {       if (m <= 2)         ans = 0;       else {         ans = n * m;         if (m == 3)           ans -= 2;         else if (m == 7)           ans -= 2;       }     } else if (n == 1) {       ans = n * m;       long long t = ans % 6;       if (t <= 3)         ans -= t;       else if (t == 4)         ans -= 2;       else if (t == 5)         --ans;     } else {       ans = (n * m) - ((n * m) & 1);     }     printf( %I64d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t, n, a, b, c, d;     cin >> t;     while (t--) {       cin >> n >> a >> b >> c >> d;       int rice_left = a - b;       int rice_right = a + b;       int packeg_left = c - d;       int packeg_right = c + d;       rice_left *= n;       rice_right *= n;       if (rice_left > packeg_right || rice_right < packeg_left)         cout <<  No  << endl;       else         cout <<  Yes  << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   template <class T1, class T2>   ostream& operator<<(ostream& os, const pair<T1, T2>& p) {     os <<  {  << p.first <<  ,   << p.second <<  } ;     return os;   }   template <class T>   ostream& operator<<(ostream& os, const vector<T>& p) {     os <<  [ ;     int i = 0;     for (typename vector<T>::const_iterator it = p.begin(); it != p.end(); ++it) {       os << (i == 0 ?    :  ,  ) << *it;       i++;     }     os <<  ] ;     return os;   }   template <class T>   ostream& operator<<(ostream& os, const set<T>& p) {     os <<  [ ;     int i = 0;     for (typename set<T>::const_iterator it = p.begin(); it != p.end(); ++it) {       os << (i == 0 ?    :  ,  ) << *it;       i++;     }     os <<  ] ;     return os;   }   template <class K, class V>   ostream& operator<<(ostream& os, const map<K, V>& p) {     os <<  [ ;     int i = 0;     for (typename map<K, V>::const_iterator it = p.begin(); it != p.end(); ++it) {       os << (i == 0 ?    :  ,  ) << *it;       i++;     }     os <<  ] ;     return os;   }   template <class T>   string toString(const T& o) {     stringstream ss;     ss << o;     string ret;     getline(ss, ret);     return ret;   }   template <class T>   vector<T> subv(const vector<T>& v, int from, int to) {     return vector<T>(v.begin() + min(max(0, from), (int)v.size()),                      v.begin() + min(max(0, to), (int)v.size()));   }   pair<int, int> operator+(const pair<int, int>& a, const pair<int, int>& b) {     return make_pair(a.first + b.first, a.second + b.second);   }   pair<int, int> operator*(const int& a, const pair<int, int>& b) {     return make_pair(a * b.first, a * b.second);   }   vector<int> sex, parent, used[2], path, bestw[2];   vector<int> was;   vector<int> points;   vector<vector<int> > adj;   vector<pair<int, int> > w[2], o[2];   int k, mark, n;   void dfs(int v, int color) {     if (was[v] == color) {       points.push_back(v);       return;     }     if (was[v]) return;     was[v] = color;     for (int i = 0; i < adj[v].size(); ++i) dfs(adj[v][i], color);   }   void go(int v) {     if (used[k][v]) return;     used[k][v] = 1;     w[k][v] = o[k][v] = make_pair(0, 0);     for (int i = 0; i < adj[v].size(); ++i) {       int to = adj[v][i];       go(to);       if (mark != to) o[k][v] = o[k][v] + max(w[k][to], o[k][to]);     }     for (int i = 0; i < adj[v].size(); ++i) {       int to = adj[v][i];       if (to == mark) continue;       pair<int, int> val = o[k][v] + (-1) * max(w[k][to], o[k][to]) + o[k][to] +                            make_pair(1, sex[v] != sex[to]);       if (w[k][v] < val) {         bestw[k][v] = to;         w[k][v] = val;       }     }   }   void make_path(int v, bool with) {     int to = -1;     if (with) {       to = bestw[k][v];       path[to] = 1;     }     for (int i = 0; i < adj[v].size(); ++i) {       int to2 = adj[v][i];       if (to2 != mark) make_path(to2, (to2 != to) && (w[k][to2] > o[k][to2]));     }   }   int main() {     cin >> n;     adj.resize(n);     sex.resize(n);     path.resize(n, 0);     parent.resize(n);     was.resize(n, 0);     for (int i = 0; i < 2; ++i) {       bestw[i].resize(n, -1);       w[i].resize(n);       o[i].resize(n);       used[i].resize(n, 0);     }     for (int i = 0; i < n; ++i) {       int f, s;       cin >> f >> s;       f--, s--;       parent[i] = f;       sex[i] = s;       adj[f].push_back(i);     }     for (int i = 0; i < n; ++i)       if (!was[i]) dfs(i, i + 1);     for (int i = 0; i < points.size(); ++i) {       int v1 = points[i];       int v2 = parent[v1];       k = 0;       mark = v1;       go(v1);       k = 1;       mark = v2;       go(v2);       int v;       if (max(o[0][v1], w[0][v1]) > max(o[1][v2], w[1][v2])) {         k = 0;         v = v1;         mark = v1;       } else {         k = 1;         v = v2;         mark = v2;       }       make_path(v, w[k][v] > o[k][v]);     }     int all = 0, diff = 0;     for (int i = 0; i < n; ++i)       if (path[i]) {         all++;         diff += (sex[i] != sex[parent[i]]);       }     cout << all <<     << diff << endl;     for (int i = 0; i < n; ++i)       if (path[i]) cout << i + 1 <<     << parent[i] + 1 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, a[20000], i, j, s = 1;     cin >> n;     for (i = 0; i < n; i++) {       cin >> a[i];     }     for (i = 0; i < n; i++) {       if (a[i] % 2) {         printf( %d n , (s + a[i]) / 2);         s *= -1;       } else         printf( %d n , a[i] / 2);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = 1e18 + 1;   const int INF_INT = 2e9 + 100;   const long long POLTOS = 50;   const long long SOTKA = 100;   const long long P = 1e9 + 7;   const long double eps = 1e-9;   const long long base = 1000 * 1000 * 1000;   const long long M = 3050;   const long long MAXN = 1e6 + 1;   const long long MAXN1 = 2 * 1e2;   const long long N = 2e5 + 1000;   const long double pi = acos(-1);   const long long mod = 1e9 + 7;   const int S_M = 20;   const long long LEN = 96;   const long long DMOD = 500000004;   const long long PR = 32000;   int main() {     int n, k;     cin >> n >> k;     vector<pair<int, int>> a(n);     for (auto &i : a) {       cin >> i.first;     }     for (auto &i : a) {       cin >> i.second;     }     sort(a.begin(), a.end(),          [&](pair<int, int> a, pair<int, int> b) { return a.second > b.second; });     vector<int> used(k + 1, false);     multiset<int> b;     for (int i = 0; i < n; ++i) {       if (used[a[i].first]) {         b.insert(a[i].second);       } else {         used[a[i].first] = 1;       }     }     long long ans = 0;     for (int i = 1; i <= k; i++)       if (!used[i]) {         ans += *b.begin();         b.erase(b.begin());       }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   inline long long pow(long long a, long long b, long long mod) {     long long ans = 1;     a %= mod;     for (; b; b >>= 1, a = a * a % mod)       if (b & 1) ans = ans * a % mod;     return ans;   }   struct Node {     int L, R;     mutable long long val;     Node(int L, int R = -1, long long val = 0) : L(L), R(R), val(val) {}     inline bool operator<(const Node& b) const { return L < b.L; }   };   std::set<Node> Chtholly;   inline std::set<Node>::iterator spilt(int pos) {     std::set<Node>::iterator iter = Chtholly.lower_bound(Node(pos));     if (iter != Chtholly.end() && iter->L == pos) return iter;     --iter;     int L = iter->L, R = iter->R;     long long V = iter->val;     Chtholly.erase(iter);     Chtholly.insert(Node(L, pos - 1, V));     return Chtholly.insert(Node(pos, R, V)).first;   }   inline void Add(int L, int R, long long val = 1) {     std::set<Node>::iterator end = spilt(R + 1), iter = spilt(L);     for (; iter != end; ++iter) iter->val += val;   }   inline void assign(int L, int R, long long val = 0) {     std::set<Node>::iterator terR = spilt(R + 1), terL = spilt(L);     Chtholly.erase(terL, terR);     Chtholly.insert(Node(L, R, val));   }   inline long long Rank(int L, int R, int k) {     std::vector<std::pair<long long, int> > s;     std::set<Node>::iterator end = spilt(R + 1), iter = spilt(L);     for (; iter != end; ++iter) {       s.push_back(std::pair<long long, int>(iter->val, iter->R - iter->L + 1));     }     std::sort(s.begin(), s.end());     for (auto iter : s) {       k -= iter.second;       if (k <= 0) return iter.first;     }     return -1ll;   }   inline long long Sum(int L, int R, long long k, long long mod) {     std::set<Node>::iterator end = spilt(R + 1), iter = spilt(L);     long long ans = 0;     for (; iter != end; ++iter) {       ans = (ans + 1ll * (iter->R - iter->L + 1) * pow(iter->val, k, mod) % mod) %             mod;     }     return ans;   }   long long n, m, seed, vmax;   const int MOD = 1e9 + 7;   inline long long rnd() {     long long ret = seed;     seed = (seed * 7 + 13) % MOD;     return ret;   }   signed main() {     int i;     scanf( %lld%lld%lld%lld , &n, &m, &seed, &vmax);     for (i = 1; i <= n; ++i) Chtholly.insert(Node(i, i, rnd() % vmax + 1));     Chtholly.insert(Node(n + 1, n + 1, 0));     for (i = 1; i <= m; ++i) {       int op = rnd() % 4 + 1, L = rnd() % n + 1, R = rnd() % n + 1, x, y;       if (L > R) L ^= R ^= L ^= R;       x = rnd() % (op == 3 ? R - L + 1 : vmax) + 1;       if (op == 4) y = rnd() % vmax + 1;       if (op == 1) {         Add(L, R, x);       }       if (op == 2) {         assign(L, R, x);       }       if (op == 3) {         printf( %lld n , Rank(L, R, x));       }       if (op == 4) {         printf( %lld n , Sum(L, R, x, y));       }     }   }


#include <bits/stdc++.h>   using namespace std;   long long a, b, c;   int vis[12];   bool ok(long long mid, int x) {     long long m = mid % 7;     int day = x;     long long res[5];     res[1] = mid / 7;     res[2] = mid / 7;     res[3] = mid / 7;     res[1] *= 3;     res[2] *= 2;     res[3] *= 2;     while (m--) {       res[vis[day]]++;       day++;       day %= 7;     }     return res[1] <= a && res[2] <= b && res[3] <= c;   }   long long ans(int x) {     long long st = 0, en = 1e12;     while (st < en) {       long long mid = (st + en) / 2;       if (ok(mid, x))         st = mid + 1;       else         en = mid;     }     return st;   }   int main() {     ios_base::sync_with_stdio(false);     cin >> a >> b >> c;     vis[0] = 2;     vis[1] = 1;     vis[2] = 1;     vis[3] = 2;     vis[4] = 3;     vis[5] = 1;     vis[6] = 3;     long long mx = 0;     for (int i = 0; i < 7; i++) {       mx = max(mx, ans(i));     }     cout << --mx <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 2000000000;   using namespace std;   template <typename A, typename B>   string to_string(pair<A, B> p);   template <typename A, typename B, typename C>   string to_string(tuple<A, B, C> p);   template <typename A, typename B, typename C, typename D>   string to_string(tuple<A, B, C, D> p);   string to_string(const string& s) { return     + s +    ; }   string to_string(const char* s) { return to_string((string)s); }   string to_string(bool b) { return (b ?  true  :  false ); }   string to_string(vector<bool> v) {     bool first = true;     string res =  { ;     for (int i = 0; i < static_cast<int>(v.size()); i++) {       if (!first) {         res +=  ,  ;       }       first = false;       res += to_string(v[i]);     }     res +=  } ;     return res;   }   template <size_t N>   string to_string(bitset<N> v) {     string res =   ;     for (size_t i = 0; i < N; i++) {       res += static_cast<char>( 0  + v[i]);     }     return res;   }   template <typename A>   string to_string(A v) {     bool first = true;     string res =  { ;     for (const auto& x : v) {       if (!first) {         res +=  ,  ;       }       first = false;       res += to_string(x);     }     res +=  } ;     return res;   }   template <typename A, typename B>   string to_string(pair<A, B> p) {     return  (  + to_string(p.first) +  ,   + to_string(p.second) +  ) ;   }   template <typename A, typename B, typename C>   string to_string(tuple<A, B, C> p) {     return  (  + to_string(get<0>(p)) +  ,   + to_string(get<1>(p)) +  ,   +            to_string(get<2>(p)) +  ) ;   }   template <typename A, typename B, typename C, typename D>   string to_string(tuple<A, B, C, D> p) {     return  (  + to_string(get<0>(p)) +  ,   + to_string(get<1>(p)) +  ,   +            to_string(get<2>(p)) +  ,   + to_string(get<3>(p)) +  ) ;   }   void debug_out() { cerr << endl; }   template <typename Head, typename... Tail>   void debug_out(Head H, Tail... T) {     cerr <<     << to_string(H);     debug_out(T...);   }   long long n;   vector<int> adj[200005];   vector<bool> visited;   vector<int> ans;   void dfs(int v) {     visited[v] = true;     for (int u : adj[v]) {       if (!visited[u]) dfs(u);     }     ans.push_back(v);   }   void topological_sort() {     visited.assign(n, false);     ans.clear();     for (int i = 0; i < n; ++i) {       if (!visited[i]) dfs(i);     }     reverse(ans.begin(), ans.end());   }   long long p2(long long x) { return x * x; }   long long dist2(pair<long long, long long> p, pair<long long, long long> q) {     return p2(p.first - q.first) + p2(p.second - q.second);   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n;     vector<long long> t(n);     vector<double> p(n);     vector<pair<long long, long long> > x(n);     for (int i = (0); i < (int)(n); i++) {       long long ti, xi, yi;       double pi;       cin >> xi >> yi >> ti >> pi;       t[i] = ti, p[i] = pi;       x[i] = {xi, yi};     }     for (int i = (0); i < (int)(n); i++) {       for (int j = (0); j < (int)(n); j++) {         if (t[i] < t[j] && p2(t[i] - t[j]) >= dist2(x[j], x[i]))           adj[i].push_back(j);       }     }     vector<double> dp(n, 0);     for (int i = (0); i < (int)(n); i++) dp[i] = p[i];     topological_sort();     for (int iii = (0); iii < (int)(n); iii++) {       long long i = ans[iii];       for (auto j : adj[i]) dp[j] = max(dp[j], dp[i] + p[j]);     }     for (int i = (0); i < (int)(n); i++) 42;     42;     42;     double out = dp[0];     for (int i = (0); i < (int)(n); i++) out = max(out, dp[i]);     cout << fixed << setprecision(10) << out << endl;     return 0;   }


#include <bits/stdc++.h>   const double eps = 1e-7, PI = 3.1415926;   const int N = 2e5 + 10;   using namespace std;   int n, q, m, k, x, y, a[N], mx = -1, mn = 1e9, sum, t;   char c[N];   string s, s1, s2;   map<pair<int, char>, int> mp;   vector<int> vec;   int main() {     cin >> q;     while (q--) {       cin >> n;       cin >> s1 >> s2;       y = 0;       mp.clear();       sum = 0;       for (int i = 0; i < 20; i++) {         char v =  a  + i;         mn = 1e9;         int hg = 20;         while (hg--) {           mn = 1e9;           for (int j = 0; j < n; j++) {             if (s1[j] == v && s2[j] != s1[j]) {               mn = min(mn, s2[j] - s1[j]);             }           }           for (int j = 0; j < n; j++) {             if (s1[j] == v && s2[j] != s1[j]) {               s1[j] += mn;             }           }           if (mn < 0) y = 1;           if (mn == 1e9)             break;           else             sum++;         }       }       if (!y)         cout << sum << endl;       else         cout << -1 << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1005;   const int INF = 0x3f3f3f3f;   int a[MAXN];   int book[MAXN * 2];   int main() {     int n, m;     scanf( %d%d , &n, &m);     for (int i = 1; i <= m; i++) {       int tmp;       scanf( %d , &tmp);       a[tmp] = 1;     }     queue<int> Q;     memset(book, 0x3f, sizeof(book));     for (int i = 0; i <= 1000; i++) {       if (a[i]) {         book[i - n + MAXN] = 1;         Q.push(i - n + MAXN);       }     }     while (!Q.empty()) {       if (book[MAXN] != INF) {         return 0 * printf( %d n , book[MAXN]);       }       int now = Q.front();       Q.pop();       for (int i = 0; i <= 1000; i++) {         if (!a[i]) continue;         int co = i - n;         int nxt = now + co;         if (nxt < 0 || nxt > 2005) continue;         if (book[nxt] > book[now] + 1) {           Q.push(nxt);           book[nxt] = book[now] + 1;         }       }     }     printf( -1 n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct ring {     int inside, outside, height;   } rings[200000];   long long all, tot;   bool cmp(ring a, ring b) {     if (a.outside != b.outside) return a.outside < b.outside;     return a.inside < b.inside;   }   int main() {     int n;     while (cin >> n) {       all = 0;       tot = 0;       for (int i = 0; i < n; i++) {         scanf( %d%d%d , &rings[i].inside, &rings[i].outside, &rings[i].height);       }       sort(rings, rings + n, cmp);       stack<ring> keys;       for (int i = n - 1; i >= 0; i--) {         while (1) {           if (keys.empty()) break;           ring key = keys.top();           if (key.outside >= rings[i].outside && key.inside < rings[i].outside)             break;           all -= key.height;           keys.pop();         }         keys.push(rings[i]);         all += rings[i].height;         tot = max(tot, all);       }       cout << tot << endl;     }   }