#include <bits/stdc++.h>   using namespace std;   const int N = 1 << 20;   int n;   int part[N][2];   bool vis[N];   vector<int> ans;   vector<pair<int, int> > G[N];   void dfs(int u) {     vis[u] = true;     for (auto v : G[u])       if (!vis[v.first]) dfs(v.first);   }   bool check(int Mask) {     for (int i = 0; i <= Mask; ++i) G[i].clear(), vis[i] = false;     for (int i = 1; i <= n; ++i) {       int u = part[i][0] & Mask;       int v = part[i][1] & Mask;       G[u].push_back({v, 2 * i - 1});       G[v].push_back({u, 2 * i - 2});     }     int comps = 0;     for (int i = 0; i <= Mask; ++i) {       if (G[i].size() & 1) return false;       if (!vis[i] && G[i].size() > 0) {         ++comps;         dfs(i);       }     }     return comps == 1;   }   void go(int u, int prv = -1) {     while (G[u].size()) {       auto e = G[u].back();       G[u].pop_back();       if (vis[e.second / 2]) continue;       vis[e.second / 2] = true;       go(e.first, e.second);     }     if (prv != -1) {       ans.push_back(prv);       ans.push_back(prv ^ 1);     }   }   void restore(int Mask) {     for (int i = 0; i <= n; ++i) vis[i] = false;     for (int i = 0; i <= Mask; ++i)       if (G[i].size()) {         go(i);         break;       }     for (int i = 0; i < n + n; ++i)       printf( %d%c , ans[i] + 1,    n [i + 1 == n + n]);   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; ++i) scanf( %d %d , &part[i][0], &part[i][1]);     for (int i = 20; i >= 0; --i)       if (check((1 << i) - 1)) {         printf( %d n , i);         restore((1 << i) - 1);         exit(0);       }     assert(false);     return 0;   }


#include <bits/stdc++.h>   int main() {     float d, l, v1, v2, y, z, p, q, i, j;     scanf( %f %f %f %f , &d, &l, &v1, &v2);     float x = (l - d) / (v1 + v2);     printf( %f n , x);   }


#include <bits/stdc++.h>   using namespace std;   inline int read() {     int x = 0, f = 1, c = getchar();     while (c < 48) c ==  -  && (f = -1), c = getchar();     while (c > 47) x = x * 10 + c -  0 , c = getchar();     return x * f;   }   const int MAXN = 100005;   struct Node {     int l, r, mx;     double p;   } q[5005];   std::vector<int> G[5005];   int lg[MAXN], fac[20], st[18][MAXN];   double f[5005][5005];   int n, m;   bool operator<(Node a, Node b) { return a.l ^ b.l ? a.l < b.l : a.r > b.r; }   inline void dfs(int x) {     double p = 1;     for (int y : G[x]) dfs(y);     for (int y : G[x]) p *= f[y][q[x].mx - q[y].mx];     f[x][0] = (1 - q[x].p) * p;     for (int i = 1; i <= m; ++i) {       double lp = 1, rp = 1;       for (int y : G[x]) {         lp *= f[y][min(q[x].mx + i - q[y].mx - 1, m)];         rp *= f[y][min(q[x].mx + i - q[y].mx, m)];       }       f[x][i] = q[x].p * lp + (1 - q[x].p) * rp;     }   }   inline int query(int l, int r) {     int k = lg[r - l + 1];     return max(st[k][l], st[k][r - fac[k] + 1]);   }   inline void buildst() {     for (int i = 1; i <= n; ++i) st[0][i] = read();     for (int i = fac[0] = 1; i < 20; ++i) fac[i] = fac[i - 1] << 1;     for (int i = 2; i <= n; ++i) lg[i] = lg[i >> 1] + 1;     for (int j = 1; j < 17; ++j)       for (int i = 1; i + fac[j] - 1 <= n; ++i)         st[j][i] = max(st[j - 1][i], st[j - 1][i + fac[j - 1]]);   }   int main(int argc, char const *argv[]) {     n = read();     m = read();     buildst();     for (int i = 1; i <= m; ++i) {       q[i].l = read();       q[i].r = read();       scanf( %lf , &q[i].p);       q[i].mx = query(q[i].l, q[i].r);     }     q[++m] = Node{1, n, query(1, n), 0};     sort(q + 1, q + m + 1);     for (int i = 2; i <= m; ++i)       for (int j = i - 1; j; --j)         if (q[j].l <= q[i].l && q[i].r <= q[j].r) {           G[j].push_back(i);           break;         }     dfs(1);     double ans = f[1][0] * q[1].mx;     for (int i = 1; i <= m; ++i) ans += (f[1][i] - f[1][i - 1]) * (q[1].mx + i);     printf( %lf n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     vector<int> v(n);     for (int i = 0; i < n; ++i) {       cin >> v[i];     }     sort(v.begin(), v.end());     cout << min(v[n - 1] - v[1], v[n - 2] - v[0]);   }


#include <bits/stdc++.h>   using namespace std;   const int MaxN = 1e3 + 100;   const int LogN = 20;   long long Inf = 1e9 + 100;   const int dx[4] = {0, 1, 0, -1};   const int dy[4] = {1, 0, -1, 0};   const double eps = 1e-9;   int md = 2520;   struct el {     int v, u, c;   };   vector<el> Ans;   vector<int> Gr[MaxN];   int Sz[MaxN];   int Ct = -1;   int N;   int Next = 1;   int Add = 1;   int find(int v, int p = -1, int c = 0) {     int Mx = 0;     int Sum = 1;     for (int to : Gr[v]) {       if (to == p) continue;       int k = find(to, v, c + 1);       Sum += k;       if (Ct != -1) return Sum;       Sz[to] = k;       Mx = ((Mx) > (Sz[to]) ? (Mx) : (Sz[to]));     }     Mx = ((Mx) > (N - Sum) ? (Mx) : (N - Sum));     if (Mx <= N / 2 && Ct == -1) {       Ct = v;       Sz[p] = N - Sum;     }     return Sum;   }   void dfs(int v, int k, int p = -1) {     for (int to : Gr[v]) {       if (p == to) continue;       Ans.push_back({v, to, Next - k});       Next += Add;       dfs(to, Next - Add, v);     }   }   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     cout << fixed << setprecision(5);     cin >> N;     for (int i = 0; i < N - 1; i++) {       int a, b;       cin >> a >> b;       a--;       b--;       Gr[a].push_back(b);       Gr[b].push_back(a);     }     find(0);     vector<pair<int, int> > Mt;     for (int to : Gr[Ct]) {       Mt.push_back({Sz[to], to});     }     sort(Mt.begin(), Mt.end());     vector<pair<int, int> > At;     int k = 0;     while (k < (N - 1) / 3 + ((N - 1) % 3 != 0)) {       At.push_back(Mt.back());       Mt.pop_back();       k += At.back().first;     }     for (pair<int, int> a : At) {       Ans.push_back({Ct, a.second, Next});       Next += Add;       dfs(a.second, Next - Add, Ct);     }     Add = (k + 1);     Next = k + 1;     for (pair<int, int> a : Mt) {       Ans.push_back({Ct, a.second, Next});       Next += Add;       dfs(a.second, Next - Add, Ct);     }     for (el a : Ans) {       cout << a.v + 1 <<     << a.u + 1 <<     << a.c <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = int(1e9) + 7, INF = 0x3fffffff, maxn = 1e5 + 12;   int n, sum, a[maxn];   int main(void) {     cin >> n;     for (int i = 0; i < n; i++) scanf( %d , &(a[i])), sum += a[i];     sort(a, a + n);     int ans = 0;     int l = sum / n, r;     r = l + 1;     int y = n - sum + l * n;     for (int i = 0; i < n; i++) {       while (i < y) {         ans += abs(a[i] - l);         i++;       }       while (i < n) {         ans += abs(r - a[i]);         i++;       }     }     cout << ans / 2 << endl;   }


#include <bits/stdc++.h>   using namespace std;   int arr[3500];   int main(void) {     int c;     scanf( %d n , &c);     for (int t = 0; t < c; t++) {       int n, m, k;       scanf( %d %d %d n , &n, &m, &k);       for (int i = 0; i < n; i++) {         scanf( %d  , &arr[i]);       }       scanf(  n );       vector<int> v;       for (int i = 0; i < m; i++) {         v.push_back(max(arr[i], arr[i + n - m]));       }       if (k >= m) {         k = m - 1;       }       int ret = 0;       for (int i = 0; i <= k; i++) {         int mini = 2e9;         for (int j = i; j < i + m - k; j++) {           mini = min(v[j], mini);         }         ret = max(ret, mini);       }       printf( %d n , ret);     }   }


#include <bits/stdc++.h>   using namespace std;   int n, sl, fh;   struct node {     int s, m, r, t;   } a[100010];   struct seg {     vector<long long> tim, pre, suf;     vector<node> a;     int lt;     void resize(int l) {       pre.resize(l);       suf.resize(l);     }     long long getans(int T) {       if (!lt) {         long long ret = 0;         for (int i = 0; i < (int)a.size(); ++i)           ret += min(0ll + a[i].m, a[i].s + 1ll * T * a[i].r);         lt = T;         return ret;       }       int t = T - lt,           p = upper_bound(tim.begin(), tim.end(), t) - tim.begin() - 1;       long long ret = 0;       if (p >= 0) ret = pre[p];       if (p < (int)a.size() - 1) ret += t * suf[p + 1];       lt = T;       return ret;     }   } tr[100010 << 2];   int rd() {     sl = 0;     fh = 1;     char ch = getchar();     while (ch <  0  ||  9  < ch) {       if (ch ==  - ) fh = -1;       ch = getchar();     }     while ( 0  <= ch && ch <=  9 ) sl = sl * 10 + ch -  0 , ch = getchar();     return sl * fh;   }   void merge(seg &res, seg &x, seg &y) {     int sz, sx = x.a.size(), sy = y.a.size();     res.resize(sz = sx + sy);     int i = 0, j = 0;     for (; i < sx && j < sy;)       if (x.tim[i] <= y.tim[j])         res.a.push_back(x.a[i]), res.tim.push_back(x.tim[i]), ++i;       else         res.a.push_back(y.a[j]), res.tim.push_back(y.tim[j]), ++j;     for (; i < sx; ++i) res.a.push_back(x.a[i]), res.tim.push_back(x.tim[i]);     for (; j < sy; ++j) res.a.push_back(y.a[j]), res.tim.push_back(y.tim[j]);     res.pre[0] = res.a[0].m;     for (int i = 1; i < sz; ++i) res.pre[i] = res.pre[i - 1] + res.a[i].m;     res.suf[sz - 1] = res.a[sz - 1].r;     for (int i = sz - 1; i; --i) res.suf[i - 1] = res.suf[i] + res.a[i - 1].r;   }   void build(int x, int l, int r) {     if (l == r) {       tr[x].a.push_back(a[l]);       tr[x].tim.push_back(a[l].t);       tr[x].pre.push_back(a[l].m);       tr[x].suf.push_back(a[l].r);       return;     }     build(x << 1, l, ((l + r) >> 1));     build(x << 1 | 1, ((l + r) >> 1) + 1, r);     merge(tr[x], tr[x << 1], tr[x << 1 | 1]);   }   void pushdown(int x) {     if (tr[x].lt >= 0) tr[x << 1].lt = tr[x << 1 | 1].lt = tr[x].lt, tr[x].lt = 0;   }   long long query(int x, int l, int r, int L, int R, int T) {     if (L <= l && r <= R && tr[x].lt >= 0) return tr[x].getans(T);     pushdown(x);     tr[x].lt = -1;     long long ret = 0;     if (L <= ((l + r) >> 1)) ret = query(x << 1, l, ((l + r) >> 1), L, R, T);     if (R > ((l + r) >> 1))       ret += query(x << 1 | 1, ((l + r) >> 1) + 1, r, L, R, T);     if (tr[x << 1].lt == tr[x << 1 | 1].lt) tr[x].lt = tr[x << 1].lt;     return ret;   }   int main() {     n = rd();     for (int i = 1; i <= n; ++i) {       a[i].s = rd();       a[i].m = rd();       a[i].r = rd();       if (!a[i].r)         a[i].t = 1e9;       else         a[i].t = (a[i].m - 1) / a[i].r + 1;     }     build(1, 1, n);     for (int l, r, t, T = rd(); T; --T) {       t = rd();       l = rd();       r = rd();       printf( %lld n , query(1, 1, n, l, r, t));     }     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize(3)   using namespace std;   int n, x, y, final, a[100500], dep[100500], maxn, root, f[100500];   std::vector<int> G[100500];   priority_queue<int> Que;   void DFS1(int now, int fa) {     for (int i = 0; i < (int)G[now].size(); i++) {       if (G[now][i] == fa) continue;       dep[G[now][i]] = dep[now] + 1;       DFS1(G[now][i], now);     }     if (dep[now] > maxn) {       root = now;       maxn = dep[now];     }   }   void DFS2(int now, int fa) {     f[now] = 1;     int son = 0;     for (int i = 0; i < (int)G[now].size(); i++) {       if (G[now][i] == fa) continue;       int to = G[now][i];       DFS2(to, now);       if (f[to] + 1 > f[now]) {         f[now] = f[to] + 1;         son = to;       }     }     for (int i = 0; i < (int)G[now].size(); i++)       if (G[now][i] != fa && G[now][i] != son) Que.push(f[G[now][i]]);   }   int main() {     scanf( %d , &n);     for (int i = 1; i < n; i++) {       scanf( %d%d , &x, &y);       G[x].push_back(y);       G[y].push_back(x);     }     dep[1] = 1;     DFS1(1, 0);     DFS2(root, 0);     Que.push(f[root]);     printf( 1  );     for (int i = 2; i <= n; i++) {       int add = 0;       if (!Que.empty()) add = Que.top(), Que.pop();       final += add;       printf( %d  , final);     }     return 0;   }


#include <bits/stdc++.h>   int m, n = 0, num[(20)];   long long f[(20)][(20)], cnt[(20)], ans = 0;   void CountBit(int m);   long long dfs(int bit, int value, bool limit);   void solve(int p, int s, int q, long long tot);   int main() {     scanf( %d , &m);     CountBit(m);     memset(f, 0xff, sizeof(f));     for (int i = 0; i <= n; i++) cnt[i] = dfs(n, i, true);     cnt[0]--;     for (int i = 1; i <= n; i++) solve(0, 1, i, cnt[i]);     printf(          %I64d            n ,         ans);     return 0;   }   void solve(int p, int s, int q, long long tot) {     if (p >= q) return;     if (s == 7) {       if (q > p) ans += tot, ans %= (1000000007LL);       return;     }     for (int i = 0; i < q; i++) {       if (cnt[i]) {         cnt[i]--;         solve(p + i, s + 1, q, tot * (cnt[i] + 1) % (1000000007LL));         cnt[i]++;       }     }   }   long long dfs(int bit, int value, bool limit) {     long long ret = 0, &save = f[bit][value];     if (!bit) {       if (!value) return save = 1;       return 0;     }     if (!limit && (~save)) return save;     int border = limit ? num[bit] : 9;     for (int i = 0; i <= border; i++)       ret += dfs(bit - 1, value - (i == 4 || i == 7), limit && i == border);     if (!limit) save = ret;     return ret;   }   void CountBit(int m) {     while (m) num[++n] = m % 10, m /= 10;   }


#include <bits/stdc++.h>   using namespace std;   long long x, a[] = {3, 15, 81, 6723, 50625, 2562991875LL};   int sg[] = {0, 1, 2, 0, 3, 1, 2}, n, ans = 0;   int main() {     cin >> n;     while (n--) {       cin >> x;       ans ^= sg[lower_bound(a, a + 6, x) - a];     }     cout << (ans ?  Furlo  :  Rublo ) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int q;     scanf( %d , &q);     map<long long, long long> road;     for (int i = 0; i < q; i++) {       int s;       scanf( %d , &s);       if (s == 1) {         long long u, v, w;         scanf( %I64d %I64d %I64d , &u, &v, &w);         while (u != v) {           if (u > v) {             road[u] += w;             u /= 2;           } else {             road[v] += w;             v /= 2;           }         }       } else if (s == 2) {         long long u, v;         scanf( %I64d %I64d , &u, &v);         long long result = 0;         while (u != v) {           if (u > v) {             result += road[u];             u /= 2;           } else {             result += road[v];             v /= 2;           }         }         printf( %I64d n , result);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 501;   long long matrix[maxn][maxn];   long long sum_col[maxn];   long long sum_row[maxn];   long long sum_d1 = 0;   long long sum_d2 = 0;   int pos_col = 0;   int pos_row = 0;   int main() {     int n, sum = 0;     cin >> n;     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         int tmp;         cin >> tmp;         if (tmp == 0) {           pos_col = j;           pos_row = i;         }         if (i == j) sum_d1 += tmp;         if (i == n - j - 1) sum_d2 += tmp;         sum_row[i] += tmp;         sum_col[j] += tmp;       }     }     if (n == 1) {       cout << 1;       return 0;     }     bool ans = true;     int cor = 0;     if (pos_col == cor) cor = 1;     long long num = sum_col[cor] - sum_col[pos_col];     if (num <= 0) ans = false;     sum_col[pos_col] += num;     sum_row[pos_row] += num;     if (pos_col == pos_row) sum_d1 += num;     if (pos_row == n - pos_col - 1) sum_d2 += num;     for (int i = 0; i < n; i++) {       if (sum_col[i] != sum_col[cor]) ans = false;       if (sum_row[i] != sum_col[cor]) ans = false;     }     if (sum_d1 != sum_col[cor]) ans = false;     if (sum_d2 != sum_col[cor]) ans = false;     if (ans)       cout << num;     else       cout << -1;   }


#include <bits/stdc++.h>   using namespace std;   #pragma GCC optimize( Ofast )   long long int n, remm[200010], actual_pos[200010];   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     clock_t clk = clock();     int q;     cin >> n;     for (int i = 1; i <= n; i++) cin >> remm[i], actual_pos[i] = remm[i];     remm[n + 1] = 1e15;     cin >> q;     set<int> stations;     for (int i = 1; i <= n + 1; i++) stations.insert(i);     while (q--) {       int type;       cin >> type;       if (type == 1) {         int vess, pour;         cin >> vess >> pour;         while (pour != 0) {           int go_to = *(stations.lower_bound(vess));           if (remm[go_to] > pour) {             remm[go_to] -= pour;             pour = 0;           } else {             pour -= remm[go_to];             remm[go_to] = 0;             stations.erase(go_to);           }         }       } else {         int ves;         cin >> ves;         cout << actual_pos[ves] - remm[ves] << endl;       }     }     cerr << endl          << setprecision(10) << fixed << (double)(clock() - clk) / CLOCKS_PER_SEC;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> t[100000];   int n;   int h[100000];   int arr[100000];   double fac[100001];   bool cmp(int a, int b) { return h[a] < h[b]; }   void dfs(int cur, int he, int par = -1) {     h[cur] = he;     for (int i = 0; i < t[cur].size(); i++) {       if (t[cur][i] == par) continue;       dfs(t[cur][i], he + 1, cur);     }   }   int main() {     cin >> n;     for (int i = 0; i < n - 1; i++) {       int a, b;       cin >> a >> b;       t[a - 1].push_back(b - 1);       t[b - 1].push_back(a - 1);     }     dfs(0, 1);     for (int i = 0; i < n; i++) arr[i] = i;     sort(arr, arr + n, cmp);     double ans = 1;     fac[0] = 1;     fac[1] = 1;     for (int i = 2; i <= n; i++) fac[i] = 1.0 / i;     for (int i = 1; i < n; i++) {       ans = (ans + 1) * fac[h[i]] + ans * (1 - fac[h[i]]);     }     printf( %.9lf n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline void FAST_IO() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);   }   template <class F, class S>   ostream& operator<<(ostream& os, pair<F, S>& p) {     os <<  (  << p.first <<  ,  << p.second <<  ) ;     return os;   }   template <class T, class S>   ostream& operator<<(ostream& os, map<T, S>& v) {     os <<  { ;     for (auto& i : v) cout <<  {  << i.first <<  ,  << i.second <<  } ;     os <<  } ;     return os;   }   template <class T>   ostream& operator<<(ostream& os, set<T>& v) {     os <<  { ;     for (auto& i : v) cout << i <<  , ;     os <<  } ;     return os;   }   template <class T>   ostream& operator<<(ostream& os, vector<T>& v) {     os <<  [ ;     if (v.size()) os << v[0];     for (int i = 1; i < v.size(); ++i) os <<  ,  << v[i];     os <<  ] ;     return os;   }   int main() {     int n;     vector<bool> in(1002);     while (cin >> n) {       in[n] = true;       getchar();     }     int first = true;     for (int i = 0; i < in.size(); ++i) {       if (!in[i]) continue;       int begin = i;       while (in[i]) i++;       if (!first) printf( , );       if (i - begin > 1)         printf( %d-%d , begin, i - 1);       else         printf( %d , i - 1);       first = false;     }     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int n;     cin >> n;     vector<long long> m(n);     for (int i = 0; i < n; i++) cin >> m[i];     long long sum = 0;     for (int i = 0; i < n; i++) sum += m[i];     sum += n;     vector<long long> a(n + 1);     for (int i = n - 1; i >= 0; i--) a[i] = max(a[i + 1] - 1, m[i] + 1);     for (int i = 1; i < n; i++) a[i] = max(a[i], a[i - 1]);     for (int i = 0; i < n; i++) sum -= a[i];     cout << -sum << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   bool chmax(T& a, const T& b) {     if (a < b) {       a = b;       return 1;     }     return 0;   }   template <class T>   bool chmin(T& a, const T& b) {     if (b < a) {       a = b;       return 1;     }     return 0;   }   struct Edge {     int from, to;     Edge(){};     Edge(int from, int to) : from(from), to(to) {}     void scanFrom(std::istream& strm, int base = 1) {       strm >> from >> to;       if (base == 1) --from, --to;     }     Edge reverse() const { return Edge(to, from); }   };   inline std::istream& operator>>(std::istream& strm, Edge& t) {     t.scanFrom(strm);     return strm;   }   template <typename T>   struct WeightedEdge {     int from, to;     T _weight;     WeightedEdge(){};     WeightedEdge(int from, int to, T weight)         : from(from), to(to), _weight(weight) {}     void scanFrom(std::istream& strm, int base = 1) {       strm >> from >> to >> _weight;       if (base == 1) --from, --to;     }     T weight() const { return _weight; }     WeightedEdge reverse() const { return WeightedEdge(to, from, _weight); }   };   template <typename T>   inline std::istream& operator>>(std::istream& strm, WeightedEdge<T>& t) {     t.scanFrom(strm);     return strm;   }   template <typename Edge>   class Digraph {     int _E, _V;     vector<vector<Edge>> _adjacencyList;       public:     int E() const { return _E; }     int V() const { return _V; }     int size() const { return _V; }     Digraph() : _V(0), _E(0){};     Digraph(int V, int E = 0) : _V(V), _E(E) { _adjacencyList.resize(V); }     void addEdge(const Edge& e) {       _adjacencyList[e.from].push_back(e);       ++_E;     }     void addUndirectedEdge(const Edge& e) {       _adjacencyList[e.from].push_back(e);       _adjacencyList[e.to].push_back(e.reverse());       ++_E;     }     void addNode() {       ++_V;       _adjacencyList.push_back(vector<Edge>());     }     void scanFrom(std::istream& strm, int base = 1) {       if (_V == 0) strm >> _V;       if (_E == 0) strm >> _E;       _adjacencyList.resize(_V);       for (int i = 0; i < _E; ++i) {         Edge e;         e.scanFrom(cin, base);         assert(0 <= e.from < _V);         assert(0 <= e.to < _V);         addEdge(e);       }     }     vector<Edge> operator[](int u) const { return _adjacencyList[u]; }     vector<vector<Edge>>& adjacencyList() { return _adjacencyList; }   };   template <typename Edge>   inline std::istream& operator>>(std::istream& strm, Digraph<Edge>& t) {     t.scanFrom(strm);     return strm;   }   int main() {     int V, E;     cin >> V >> E;     Digraph<Edge> G(V, E);     for (int i = 0; i < (int)(E); ++i) {       int u, v;       scanf( %d %d , &u, &v);       --u, --v;       G.addUndirectedEdge(Edge(u, v));     }     int sq = ceil(sqrt(V));     vector<int> depth(V, -1);     vector<bool> independent(V, false);     function<void(int, int)> printCycle = [&](int s, int u) {       printf( %d  , u + 1);       if (u == s) return;       for (Edge& e : G[u]) {         if (depth[e.to] == depth[u] - 1) printCycle(s, e.to);       }     };     function<void(int, int)> dfs = [&](int u, int d) {       depth[u] = d;       bool ind = true;       int mind = d, anc = u;       for (Edge& e : G[u]) {         if (depth[e.to] == -1) dfs(e.to, d + 1);         if (depth[e.to] < depth[u]) {           if (chmin(mind, depth[e.to])) anc = e.to;           continue;         }         ind &= !independent[e.to];       }       if (d - mind >= sq - 1) {         cout << 2 << endl;         cout << d - mind + 1 << endl;         printCycle(anc, u);         exit(0);       }       independent[u] = ind;     };     dfs(0, 0);     cout << 1 << endl;     int c = 0;     for (int u = 0; u < (int)(V); ++u) {       if (c < sq && independent[u]) {         printf( %d  , u + 1);         ++c;       }     }     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   class R {    public:     int l;     int r;     int t;     int b;     R(int l, int r, int t, int b) {       this->l = l;       this->r = r;       this->b = b;       this->t = t;     }   };   int ask(int x1, int x2, int y1, int y2) {     cout <<  ?   << x1 <<     << y1 <<     << x2 <<     << y2 << endl;     fflush(stdout);     int ans;     cin >> ans;     return ans;   }   int askR(R r) {     cout <<  ?   << r.l <<     << r.t <<     << r.r <<     << r.b << endl;     fflush(stdout);     int ans;     cin >> ans;     return ans;   }   bool check(R other, R border) {     if (other.t >= border.t && other.l >= border.l && other.r <= border.r &&         other.b <= border.b)       return true;     return false;   }   void solveBot(R& r, R other) {     int left = r.t;     int right = r.b;     while (right - left > 1) {       int m = (right + left) / 2;       int a = ask(r.l, r.r, r.t, m);       if (a == 2 || (a == 1 && !check(other, R(r.l, r.r, r.t, m)))) {         right = m;         continue;       }       left = m;     }     int a = ask(r.l, r.r, r.t, left);     if (a == 2 || (a == 1 && !check(other, R(r.l, r.r, r.t, left)))) {       R rr = R(r.l, r.r, r.t, left);       r = rr;       return;     }     R rr = R(r.l, r.r, r.t, right);     r = rr;   }   void solveRight(R& r, R other) {     int left = r.l;     int right = r.r;     while (right - left > 1) {       int m = (right + left) / 2;       int a = ask(r.l, m, r.t, r.b);       if (a == 2 || (a == 1 && !check(other, R(r.l, m, r.t, r.b)))) {         right = m;         continue;       }       left = m;     }     int a = ask(r.l, left, r.t, r.b);     if (a == 2 || (a == 1 && !check(other, R(r.l, left, r.t, r.b)))) {       R rr = R(r.l, left, r.t, r.b);       r = rr;       return;     }     R rr = R(r.l, right, r.t, r.b);     r = rr;   }   void solveLeft(R& r, R other) {     int left = r.l;     int right = r.r;     while (right - left > 1) {       int m = (right + left) / 2;       int a = ask(m, r.r, r.t, r.b);       if (a == 2 || (a == 1 && !check(other, R(m, r.r, r.t, r.b)))) {         left = m;         continue;       }       right = m;     }     int a = ask(right, r.r, r.t, r.b);     if (a == 2 || (a == 1 && !check(other, R(right, r.r, r.t, r.b)))) {       R rr = R(right, r.r, r.t, r.b);       r = rr;       return;     }     R rr = R(left, r.r, r.t, r.b);     r = rr;   }   void solveTop(R& r, R other) {     int left = r.t;     int right = r.b;     while (right - left > 1) {       int m = (right + left) / 2;       int a = ask(r.l, r.r, m, r.b);       if (a == 2 || (a == 1 && !check(other, R(r.l, r.r, m, r.b)))) {         left = m;         continue;       }       right = m;     }     int a = ask(r.l, r.r, right, r.b);     if (a == 2 || (a == 1 && !check(other, R(r.l, r.r, right, r.b)))) {       R rr = R(r.l, r.r, right, r.b);       r = rr;       return;     }     R rr = R(r.l, r.r, left, r.b);     r = rr;   }   void solve(int n) {     R r = R(1, n, 1, n);     R fiks = R(-1, -1, -1, -1);     solveBot(r, fiks);     solveLeft(r, fiks);     solveRight(r, fiks);     solveTop(r, fiks);     R s = R(1, n, 1, n);     solveBot(s, r);     solveLeft(s, r);     solveRight(s, r);     solveTop(s, r);     cout <<  !   << r.l <<     << r.t <<     << r.r <<     << r.b;     cout <<     << s.l <<     << s.t <<     << s.r <<     << s.b;   }   int main() {     int n;     cin >> n;     solve(n);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long mod = 1000000007;   int lca[400100][20];   int len[400100];   long long s[400100][20];   int w[400100];   int main() {     ios::sync_with_stdio(false);     int Q;     cin >> Q;     int cnt = 0;     int last = 0;     len[0] = 1;     for (long long q = 0; q < (long long)(Q); ++q) {       int t, x;       long long y;       cin >> t >> x >> y;       x ^= last;       --x;       y ^= last;       if (t == 1) {         ++cnt;         w[cnt] = y;         for (int i = 20 - 1; i >= 0; --i) {           if (w[lca[x][i]] < y) {             x = lca[x][i];           }         }         if (w[x] < y) {           x = lca[x][0];         }         if (w[x] < y) {           x = cnt;         }         lca[cnt][0] = x;         len[cnt] = len[x] + 1;         s[cnt][0] = y;         for (long long i = 0; i < (long long)(20 - 1); ++i) {           lca[cnt][i + 1] = lca[lca[cnt][i]][i];           s[cnt][i + 1] = s[cnt][i] + s[lca[cnt][i]][i];         }       } else {         last = 0;         int upp = len[x];         for (int i = 20 - 1; i >= 0; --i) {           if (s[x][i] <= y) {             y -= s[x][i];             x = lca[x][i];             last += 1 << i;           }         }         last = min(last, upp);         cout << last << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<long long> val(100000 + 5);   struct Gaussian {     long long no_of_bits = 20;     vector<long long> v;     long long set, origsize = 0, redsize = 0;     void push(long long val) {       origsize++;       if (val) v.push_back(val);     }     void clear() {       v.clear();       set = 0, redsize = 0;     }     void eliminate() {       set = redsize = 0;       for (long long bit = 0; bit <= no_of_bits; bit++) {         bool check = false;         for (long long i = redsize; i < v.size(); i++) {           if ((v[i] >> bit) & 1) {             swap(v[i], v[redsize]);             check = true;             break;           }         }         if (check) {           for (long long i = redsize + 1; i < v.size(); i++) {             if ((v[i] >> bit) & 1) v[i] ^= v[redsize];           }           redsize++;         }       }       v.resize(redsize);       for (auto it : v) set |= it;     }     Gaussian& operator=(Gaussian& orig) {       v = orig.v;       set = orig.set;       redsize = orig.redsize;       origsize = orig.origsize;       return *this;     }   };   long long modexpo(long long a, long long b) {     long long res = 1;     while (b > 0) {       if (b % 2) res = (res * a) % 1000000007;       a = (a * a) % 1000000007;       b = b / 2;     }     return res;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long n, q;     cin >> n >> q;     Gaussian arr[n];     val.resize(n);     for (long long i = 0; i < n; i++) cin >> val[i];     arr[0].push(val[0]);     arr[0].eliminate();     for (long long i = 1; i < n; i++) {       arr[i] = arr[i - 1];       arr[i].push(val[i]);       arr[i].eliminate();     }     while (q--) {       long long l, x;       cin >> l >> x;       Gaussian temp = arr[--l];       temp.push(x);       temp.eliminate();       long long ans = 0;       if (temp.redsize == arr[l].redsize)         ans = modexpo(2, arr[l].origsize - arr[l].redsize);       cout << ans <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod1 = 19260817;   const long long mod2 = 19660813;   int n;   int m;   char s[200005];   char opt[5];   struct {     int tree[200005];     int lowbit(int x) { return x & -x; }     void ins(int pos, int val) {       for (; pos <= n; pos += lowbit(pos)) tree[pos] += val;     }     int query(int pos) {       int sum = 0;       for (; pos; pos -= lowbit(pos)) sum += tree[pos];       return sum;     }   } t[125];   int find(int x) {     int ret = 0;     for (int i = 20; i >= 0; --i) {       if (ret + (1 << i) > n) continue;       int sum = 0;       for (int j = 48; j < 125; ++j) sum += t[j].tree[ret + (1 << i)];       if (x >= sum) {         x -= sum;         ret += (1 << i);       }     }     return ret;   }   set<int> book[125];   set<int>::iterator it;   vector<int> memo;   bool check(int pos) {     if (pos == 1) {       if (t[s[pos]].query(pos)) return true;     } else {       if (t[s[pos]].query(pos) - t[s[pos]].query(pos - 1)) return true;     }     return false;   }   int main() {     scanf( %d %d , &n, &m);     scanf( %s , s + 1);     for (int i = 1; i <= n; ++i) {       t[s[i]].ins(i, 1);       book[s[i]].insert(i);     }     while (m--) {       int l;       int r;       scanf( %d %d %s , &l, &r, opt + 1);       int lcur = find(l - 1) + 1;       int rcur = find(r - 1) + 1;       it = book[opt[1]].lower_bound(lcur);       memo.clear();       while (it != book[opt[1]].end()) {         int pos = *it;         if (pos > rcur) break;         memo.push_back(pos);         ++it;       }       for (auto p : memo) book[opt[1]].erase(p);       for (auto p : memo) t[opt[1]].ins(p, -1);     }     for (int i = 1; i <= n; ++i) {       if (check(i)) printf( %c , s[i]);     }     printf(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a, b, k, m, maxa, minb, tem;   int main() {     cin >> a >> b >> k >> m;     for (int i = 0; i < a; i++) {       cin >> tem;       if (i == k - 1) maxa = tem;     }     for (int i = 0; i < b; i++) {       cin >> tem;       if (i == b - m) minb = tem;     }     cout << (maxa < minb ?  YES  :  NO ) << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long w, h, u1, d1, u2, d2;     cin >> w >> h >> u1 >> d1 >> u2 >> d2;     for (int i = h; i >= 0; i--) {       w += i;       if (i == d1) w -= u1;       if (i == d2) w -= u2;       w = max(w, 0LL);     }     cout << w << endl;   }


#include <bits/stdc++.h>   using namespace std;   unordered_set<int> S;   int main() {     int n;     cin >> n;     int A[n], dp[n + 1];     dp[0] = 0;     S.clear();     for (int _n{n}, i{0}; i < _n; ++i) {       cin >> A[i];       dp[i + 1] = dp[i];       if (!S.count(A[i])) {         S.insert(A[i]);         dp[i + 1]++;       }     }     S.clear();     uint64_t ans = 0;     for (int _n{n + 1}, i{1}; i < _n; ++i) {       if (!S.count(A[n - i])) {         ans += dp[n - i];         S.insert(A[n - i]);       }     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   bool comp(long long a, long long b) { return a > b; }   std::vector<long long> fac(500000);   void pre() {     fac[0] = 1;     for (int i = 1; i < 500000; i++) {       fac[i] = i * fac[i - 1];       fac[i] %= 998244353;     }   }   long long power(long long x, long long y, long long p) {     long long res = 1;     x = x % p;     while (y > 0) {       if (y & 1) res = (res * x) % p;       y = y >> 1;       x = (x * x) % p;     }     return res;   }   long long modInverse(long long n, long long p) { return power(n, p - 2, p); }   long long nCrModPFermat(long long n, long long r) {     if (n <= 0 || n < r) return 0;     if (r == 0) return 1;     long long a = (fac[n] * modInverse(fac[r], 998244353) % 998244353 *                    modInverse(fac[n - r], 998244353) % 998244353) %                   998244353;     return a;   }   void solve() {     long long k, x, y, n;     cin >> n >> k;     std::vector<pair<long long, long long>> ar;     long long ans = 0;     for (int i = 0; i < n; i++) {       long long l, r;       cin >> l >> r;       ar.push_back(make_pair(l, r));     }     if (k == 1) {       cout << n <<   n ;       return;     }     sort(ar.begin(), ar.end());     multiset<long long> q;     long long cnt;     for (int i = 0; i < n; i++) {       while (!q.empty() && *q.begin() < ar[i].first) {         q.erase(q.begin());       }       cnt = q.size();       ans += (nCrModPFermat(cnt, k - 1));       ans %= 998244353;       q.insert(ar[i].second);     }     cout << ans <<   n ;   }   int main() {     pre();     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     int t = 1;     while (t--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long int mx = 2e3 + 1, Mod = 1e9 + 7;   long long int k, Pa, Pb;   int pw(long long int a, int b) {     long long int ans = 1;     while (b) {       if (b % 2) ans = (ans * a) % Mod;       a = (a * a) % Mod;       b /= 2;     }     return ans;   }   long long int dp[mx][mx];   long long int dpp(int i, int j) {     if (j >= k) return j;     return dp[i][j];   }   int main() {     ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);     cin >> k >> Pa >> Pb;     long long int divm = pw(Pa + Pb, Mod - 2);     long long int divb = (Pa * pw(Pb, Mod - 2)) % Mod;     for (int i = k; i >= 0; i--)       for (int j = k - 1; j >= 0; j--) {         if (i == k) {           dp[i][j] = (i + j + divb) % Mod;           continue;         }         dp[i][j] =             (((Pa * dpp(i + 1, j) + Pb * dpp(i, i + j)) % Mod) * divm) % Mod;       }     return cout << dp[1][0], 0;   }


#include <bits/stdc++.h>   using namespace std;   char str[2000 + 5][2000 + 5];   int v, res, n, m, k, cnt;   int main() {     scanf( %d%d%d , &n, &m, &k);     bool flag = 0;     if (k == 1) flag = 1;     for (int i = 1; i <= n; i++) scanf( %s , str[i]);     for (int i = 1; i <= n; i++) {       for (int j = 0; j < m; j++) {         if (str[i][j] ==  * ) {           if (v >= k) res += v - k + 1;           v = 0;         } else           v++, cnt++;       }       if (v >= k) res += v - k + 1;       v = 0;     }     if (flag == 1) {       printf( %d , cnt);       return 0;     }     for (int i = 0; i < m; i++) {       for (int j = 1; j <= n; j++) {         if (str[j][i] ==  * ) {           if (v >= k) res += v - k + 1;           v = 0;         } else           v++;       }       if (v >= k) res += v - k + 1;       v = 0;     }     printf( %d , res);     return 0;   }


#include <bits/stdc++.h>   using namespace std;      #define ll long long int   #define mp make_pair   #define pb push_back   #define pf push_front   #define F first   #define S second   #define MOD 1000000007   #define MAXN   1000001   #define MODA 998244353   #define all(a)      (a).begin(),(a).end()   #define allr(a)      (a).rbegin(),(a).rend()      ll power(ll a,ll b){       ll result=1;       while(b>0){           int lastbit=(b&1);           if(lastbit){               result=(result*a);           }           a=(a*a);           b=b>>1;       }       return result;   }      ll power2(ll a,ll b,ll p){       ll result=1;       while(b>0){           int lastbit=(b&1);           if(lastbit){               result=(result*a)%p;           }           a=(a*a)%p;           b=b>>1;       }       return result%p;   }      ll gcd(ll a, ll b){       if (b == 0)           return a;       return gcd(b, a % b);   }      vector<ll> Sieve(int n){       bool prime[n+1];       memset(prime, true, sizeof(prime));       for (int p=2; p*p<=n; p++){           if (prime[p] == true){               for (int i=p*p; i<=n; i += p)                   prime[i] = false;           }       }       vector<ll>v;       for (int p=2; p<=n; p++)           if (prime[p]) v.pb(p);       return v;   }      vector<ll> SeiveOfEratosthenes(int n){       vector<ll>v(n+1,0);       for(int i=0;i<=n;i++){           v[i]=i;       }          for (int p=2; (p*p)<=n; p++){           if (v[p] == p){               v[p]=p;               for (int i=p*p; i<=n; i += p) {                   v[i] = p;               }           }       }       return v;   }      vector<ll> SmallestPrimeFactors(int n){       vector<ll>spf(n+1,0);       spf[1] = 1;       for (int i=2; i<=n; i++){           spf[i] = i;       }       for (int i=4; i<=n; i+=2){           spf[i] = 2;       }       for (int i=3; (i*i)<=n; i++){           if (spf[i] == i){               for (int j=i*i; j<MAXN; j+=i) {                   if (spf[j] == j){                       spf[j] = i;                   }               }           }       }       return spf;   }      void shortest(map<int,vector<pair<int,ll>>>m,int src,int n,ll *dist){       bool visited[n+1];       set<pair<ll,int>>s;       for(int i=0;i<=n;i++){           dist[i]=-1;           visited[i]=false;       }          s.insert(mp(0ll,src));       dist[src]=0;       while(!s.empty()){           auto t=s.begin();           ll dis=(*t).F;           int u=(*t).S;           s.erase(t);           if(visited[u]){               continue;           }           visited[u]=true;           for(auto tt:m[u]){               int v=tt.F;               ll w=tt.S;               if(!visited[v]){                   if(dist[v]!=-1 && dist[v]>dis+w){                       s.erase(mp(dist[v],v));                       dist[v]=dis+w;                       s.insert(mp(dist[v],v));                   }else if(dist[v]==-1){                       dist[v]=dis+w;                       s.insert(mp(dist[v],v));                   }               }           }       }   }      int main(){          ios_base::sync_with_stdio(false);       cin.tie(NULL);       cout.tie(NULL);          int tttttt=1;       cin >> tttttt;       for(int ttttt=1; ttttt <= tttttt; ttttt++){           ll n,l,r,s;           cin>>n>>l>>r>>s;           ll len=(r-l+1);           vector<int>v;           for(int i=0;i<len;i++){               v.pb(i+1);               s-=(i+1);           }           if(s<0){               cout<<-1;           }else{               ll t=n-len;               int x=0;                  for(int i=1;i<=t;i++){                   if(s>=len){                       s-=len;                       x++;                   }else{                       for(int j=v.size()-1;j>=0 && s>0 ;j--){                           v[j]+=1;                           s--;                       }                       break;                   }                   if(s==0){                       break;                   }               }                  for(int j=0;j<v.size();j++){                   v[j]+=x;               }                  if(s!=0){                   cout<<-1;               }else{                      int a[n];                   int j=0;                   int st[n+1];                      for(int i=1;i<=n;i++){                       st[i]=0;                   }                   for(int i=l-1;i<r;i++){                       a[i]=v[j];                       st[v[j]]=-1;                       j++;                   }                      j=1;                   for(int i=0;i<(l-1);){                       if(st[j]==0){                           a[i]=j;                           j++;                           i++;                       }else{                           j++;                       }                   }                   for(int i=r;i<(n);){                       if(st[j]==0){                           a[i]=j;                           j++;                           i++;                       }else{                           j++;                       }                   }                   for(int i=0;i<n;i++){                       cout<<a[i]<<   ;                   }               }           }           cout<<endl;       }          return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int arr[101], ans = 0, temp = 0;     int i, j, n;     scanf( %d , &n);     for (i = 0; i < n; i++) scanf( %I64d , &arr[i]);     for (i = 0; i < n; i++) {       for (j = i; j < n; j++) {         temp = temp ^ arr[j];         ans = max(ans, temp);       }       temp = 0;     }     printf( %I64d , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2020;   int n, m, i, j, cnt[N];   char grid[N][N];   bool check(int s) {     for (int i = 0; i < m; ++i)       if (grid[s][i] ==  1  && cnt[i] <= 1) return 0;     return 1;   }   int main() {     cin >> n >> m;     for (i = 0; i < n; ++i) {       scanf( %s , grid + i);       for (j = 0; j < m; ++j) {         cnt[j] += (grid[i][j] ==  1 );       }     }     for (i = 0; i < n; ++i) {       if (check(i)) {         return cout <<  YES , 0;       }     }     cout <<  NO ;     return 0;   }


#include<string.h>   #include<bits/stdc++.h>   using namespace std;   int main()   {    int t;    cin>>t;    //string a,b;    while(t--)    {     string a,b;     cin>>a;     int n,m,g,maxx;     cin>>b;     string l,k;     int len=a.size(),len1=b.size();     for(int i=1;i<=len;i++)     {      int r=0;      for(int j=0;j<(len-i);)      {       if(a.substr(j,i)!=a.substr(j+i,i))       {        r=1;        break;       }       else j+=i;      }      if(!r)       {      l=a.substr(0,i);      break;     }    }     for(int i=1;i<=len1;i++)     {      int r=0;      for(int j=0;j<(len1-i);)      {       if(b.substr(j,i)!=b.substr(j+i,i))       {        r=1;        break;       }       else j+=i;      }      if(!r)      {        k=b.substr(0,i);        break;}     }     int s,s1;     s=l.size();     s1=k.size();     n=len/s,m=len1/s1;     maxx=min(n,m);     for(int i=maxx;i>=1;i--)     {      if(n%i==0&&m%i==0)      {       g=i;       break;      }     }     //cout<<l<<   <<k;     if(l==k)      {      for(int i=0;i<n*m/g;i++)  cout<<l;      cout<<endl;     }     else cout<< -1 <<endl;    }    return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MaxN = 100 * 1000;   int ok[MaxN];   int bad[MaxN];   char TYPE[MaxN];   int QUERY[MaxN];   bool crime[MaxN];   int main() {     int n, m;     scanf( %d%d n , &n, &m);     int sumWrong = 0;     for (int i = 0; i < n; i++) {       char type;       int x;       scanf( %c%d , &type, &x);       if (i != n - 1) scanf(  n );       TYPE[i] = type;       QUERY[i] = x - 1;       if (type ==  + ) {         bad[x - 1]++;       } else {         ok[x - 1]++;         sumWrong++;       }     }     int sz = 0;     for (int i = 0; i < n; i++) {       int right = bad[i] + sumWrong - ok[i];       if (right == m) {         crime[i] = true;         sz++;       }     }     for (int i = 0; i < n; i++) {       if (TYPE[i] ==  - ) {         if (!crime[QUERY[i]]) printf( Truth n );         if (crime[QUERY[i]] && sz > 1) printf( Not defined n );         if (crime[QUERY[i]] && sz == 1) printf( Lie n );       } else {         if (!crime[QUERY[i]]) printf( Lie n );         if (crime[QUERY[i]] && sz > 1) printf( Not defined n );         if (crime[QUERY[i]] && sz == 1) printf( Truth n );       }     }   }


#include <bits/stdc++.h>   using namespace std;   int main(void) {     cin.sync_with_stdio(false);     long long k[3];     int t[3];     int n, i, j;     for (i = 0; i < 3; i++) cin >> k[i];     for (i = 0; i < 3; i++) cin >> t[i];     cin >> n;     vector<long long> a(n);     vector<long long> b(n);     for (i = 0; i < n; i++) {       cin >> a[i];       b[i] = a[i];     }     for (j = 0; j < 3; j++)       if (k[j] > n) k[j] = n;     for (j = 0; j < 3; j++) {       priority_queue<long long, vector<long long>, greater<long long> > Q;       for (i = 0; i < k[j]; i++) {         Q.push(0);       }       for (i = 0; i < n; i++) {         long long p = Q.top();         Q.pop();         if (p < b[i]) p = b[i];         b[i] = p + t[j];         Q.push(b[i]);       }     }     long long ans = 0;     for (i = 0; i < n; i++) {       if (b[i] - a[i] > ans) ans = b[i] - a[i];     }     cout << ans << endl;     return 0;   }


#include<bits/stdc++.h>   using namespace std;   #define pb push_back   #define reg register   #define int long long   #define For(i,a,b) for(reg int i=a;i<=b;++i)   #define Down(i,a,b) for(reg int i=a;i>=b;--i)    #define ull unsigned long long   #define rep(i,a,b) for(reg int i=a;i<=b;++i)   #define ll long long   inline int max(int x,int y){return x>y?x:y;}   inline int min(int x,int y){return x<y?x:y;}   inline void ckmin(int &x,int y){x=x<y?x:y; return ;}   inline void ckmax(int &x,int y){x=x>y?x:y; return ;}   inline int gcd(int n,int m){return m?gcd(m,n%m):n;}   inline int lcm(int x,int y){return x/gcd(x,y)*y;}   inline void swap(int &x,int &y){int t=x; x=y; y=t; return ;}   namespace yspm{    inline int read(){        int res=0,f=1; char k;        while(!isdigit(k=getchar())) if(k== - ) f=-1;        while(isdigit(k)) res=res*10+k- 0 ,k=getchar();        return res*f;       }       char out[100];       inline void print(int x){           if(!x) return putchar( 0 ),putchar(  n ),void();           if(x<0) putchar( - ),x=-x;            int cnt=0; while(x) out[++cnt]=x%10,x/=10;            Down(i,cnt,1) putchar(out[i]+ 0 ); putchar(  n ); return ;       }        const int N=1e5+10,bl=510;       vector<int>f[N<<2];       int n,a[N],p,v;       inline void push_up(int x){           int rpos=0,lsz=f[x<<1].size(),rsz=f[x<<1|1].size(); f[x].clear();           for(reg int i=0;i<lsz;){               if(rpos==rsz||(f[x<<1][i]<f[x<<1|1][rpos]-i)) f[x].push_back(f[x<<1][i++]);               else f[x].push_back(f[x<<1|1][rpos++]-i);           } for(reg int j=rpos;j<rsz;++j) f[x].push_back(f[x<<1|1][j]-lsz);           return ;       }       inline void build(int p,int l,int r){           if(l==r) return f[p].resize(1),f[p][0]=a[l],void(); int mid=(l+r)>>1;            build(p<<1,l,mid); build(p<<1|1,mid+1,r);            if(r-l+1<=bl) push_up(p); return ;       }       inline void modify(int x,int l,int r){           if(l==r) return f[x][0]=a[l],void(); int mid=(l+r)>>1;            if(p<=mid) modify(x<<1,l,mid); else modify(x<<1|1,mid+1,r);            if(r-l+1<=bl) push_up(x); return ;       }       inline void query(int x,int l,int r){           if(l>=p&&r-l+1<=bl) return v+=upper_bound(f[x].begin(),f[x].end(),v)-f[x].begin(),void(); int mid=(l+r)>>1;            if(mid>=p) query(x<<1,l,mid); return query(x<<1|1,mid+1,r);        }    signed main(){        n=read(); rep(i,1,n) a[i]=i-read(); build(1,1,n);         int Q=read(); while(Q--){            if(read()==1){                int x=read(),y=read();                 a[x]=x-y; p=x; modify(1,1,n);            }else{                p=read(); if(p==n) print(a[n]);                 else v=a[p],++p,query(1,1,n),print(v);            }        } return 0;       }   }signed main(){return yspm::main();}   //Use The Time To Enrich This Selfclosing Youth


#include <bits/stdc++.h>   using namespace std;   int main() {     int i, j, n, m, q, p;     cin >> q;     while (q--) {       cin >> n;       string s;       cin >> s;       p = 0;       if (s.length() > 2) {         cout <<  YES n2 n ;         cout << s[0] <<    ;         for (i = 1; i < n; i++) cout << s[i];         cout << endl;       } else {         if (s[0] < s[1])           cout <<  YES n2 n  << s[0] <<     << s[1] << endl;         else           cout <<  NO  << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 4000;   long long p[MAXN + 10], v[MAXN + 10], d[MAXN + 10];   bool lft[MAXN + 10];   int n;   void print(int n) {     for (int i = 0; i < n; i++) cout << p[i] <<    ;     cout << endl;     for (int i = 0; i < n; i++) cout << lft[i] <<    ;     cout << endl;   }   int main() {     cin >> n;     for (int i = 0; i < n; i++) cin >> v[i] >> d[i] >> p[i];     int res = 0;     for (int i = 0; i < n; i++) {       if (lft[i]) continue;       res++;       long long f = 0, effect = 0;       for (int j = i + 1; j < n; j++) {         if (lft[j]) continue;         p[j] -= max(0ll, v[i] - f++);         p[j] -= effect;         if (p[j] < 0) {           lft[j] = true;           effect += d[j];         }       }     }     cout << res << endl;     for (int i = 0; i < n; i++)       if (!lft[i]) cout << i + 1 <<    ;     cout << endl;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 1e5 + 2;   const long long N1 = 1e2 + 2;   const long long mod = 1e9 + 7;   const int MASK = 1 << 17 + 1;   const int who = 6 * N * log2(N);   long long power(long long a, long long b, long long c) {     long long ret = 1;     while (b) {       if (b % 2 == 1) {         ret = (ret * a) % c;       }       b /= 2;       a = (a * a) % c;     }     return ret;   }   long long n, m, r, val;   long long a[N + 3], b[N + 3];   map<long long, long long> vis[N + 3];   vector<double> v;   bool calc(long long x, long long y) {     if (x < n && y < m && x >= 0 && y >= 0) {       if (vis[x][y] == 0) {         return true;       }     }     return false;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cin >> n >> m >> r >> val;     long long tot = n - r + 1;     for (int i = 0; i < n; i++) {       int sum = max(0, (int)(n - r - i)) + max(0, (int)(i - r + 1));       a[i] = tot - sum;     }     tot = m - r + 1;     for (int i = 0; i < m; i++) {       int sum = max(0, (int)(m - r - i)) + max(0, (int)(i - r + 1));       b[i] = tot - sum;     }     priority_queue<pair<double, pair<int, int> > > pq;     long long x = n / 2, y = m / 2;     vis[x][y] = 1;     pq.push(make_pair(a[x] * b[y], make_pair(x, y)));     while (!pq.empty() && v.size() < val) {       pair<double, pair<int, int> > tm = pq.top();       pq.pop();       v.push_back(tm.first);       long long test;       if (calc(tm.second.first - 1, tm.second.second + 0)) {         test = a[(tm.second.first - 1)] * b[(tm.second.second)];         vis[tm.second.first - 1][tm.second.second] = 1;         pq.push(             make_pair(test, make_pair(tm.second.first - 1, tm.second.second)));       }       if (calc(tm.second.first + 0, tm.second.second + 1)) {         test = a[(tm.second.first)] * b[(tm.second.second + 1)];         vis[tm.second.first][tm.second.second + 1] = 1;         pq.push(             make_pair(test, make_pair(tm.second.first, tm.second.second + 1)));       }       if (calc(tm.second.first + 0, tm.second.second - 1)) {         vis[tm.second.first][tm.second.second - 1] = 1;         test = a[(tm.second.first)] * b[(tm.second.second - 1)];         pq.push(             make_pair(test, make_pair(tm.second.first, tm.second.second - 1)));       }       if (calc(tm.second.first + 1, tm.second.second + 0)) {         vis[tm.second.first + 1][tm.second.second] = 1;         test = a[(tm.second.first + 1)] * b[(tm.second.second)];         pq.push(             make_pair(test, make_pair(tm.second.first + 1, tm.second.second)));       }     }     double res = 0, res1 = (n - r + 1) * (m - r + 1);     for (auto it : v) {       res += it;     }     printf( %.15lf n , res / res1);   }


#include <bits/stdc++.h>   using namespace std;   int dr[4][2] = {{1, 1}, {-1, 1}, {-1, -1}, {1, -1}};   bool eq(double d1, double d2) { return fabs(d1 - d2) < 1e-7; }   int getState(double dx, double dy) {     for (int i = 0; i < 4; i++)       if (!eq(dx, 0) && !eq(dy, 0))         if (dx * dr[i][0] > 0 && dy * dr[i][1] > 0) return i;     if (eq(dx, 0)) {       if (dy > 0)         return 1;       else         return 3;     }     if (eq(dy, 0)) {       if (dx > 0)         return 0;       else         return 2;     }     return 10000;   }   namespace std {   bool operator<(const complex<double>& a, const complex<double>& b) {     return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);   }   }  // namespace std   double cross(const complex<double>& a, const complex<double>& b) {     return imag(conj(a) * b);   }   double dot(const complex<double>& a, const complex<double>& b) {     return real(conj(a) * b);   }   int ccw(complex<double> a, complex<double> b, complex<double> c) {     b -= a;     c -= a;     if (cross(b, c) > 0) return +1;     if (cross(b, c) < 0) return -1;     if (dot(b, c) < 0) return +2;     if (norm(b) < norm(c)) return -2;     return 0;   }   bool isconvex(const vector<complex<double> >& P) {     for (int i = 0; i < P.size(); ++i) {       if (ccw(P[(i + P.size() - 1) % P.size()], P[(i) % P.size()],               P[(i + 1) % P.size()]) > 0)         return false;     }     return true;   }   vector<complex<double> > convex_hull(vector<complex<double> >& ps) {     int n = ps.size(), k = 0;     sort(ps.begin(), ps.end());     vector<complex<double> > ch(2 * n);     for (int i = 0; i < n; ch[k++] = ps[i++])       while (k >= 2 && ccw(ch[k - 2], ch[k - 1], ps[i]) <= 0) --k;     for (int i = n - 2, t = k + 1; i >= 0; ch[k++] = ps[i--])       while (k >= t && ccw(ch[k - 2], ch[k - 1], ps[i]) <= 0) --k;     ch.resize(k - 1);     return ch;   }   vector<complex<double> > poly, temp;   vector<complex<double> > cn;   int n, ptr = 0;   bool eqq(complex<double> p1, complex<double> p2) {     return eq(p1.imag(), p2.imag()) && eq(p1.real(), p2.real());   }   int main() {     cin >> n;     poly.resize(n);     for (int i = 0; i < n; i++) {       int x, y;       scanf( %d%d , &x, &y);       poly[i] = complex<double>(x, y);     }     sort(poly.begin(), poly.end());     for (int i = 0; i < poly.size(); i++)       if (i == 0 || poly[i] != poly[i - 1]) temp.push_back(poly[i]);     poly = temp;     n = poly.size();     if (n == 1)       cout << 4 << endl;     else {       cn = convex_hull(poly);       n = cn.size();       int res = 0, curS = getState(cn[1].real() - cn[0].real(),                                    cn[1].imag() - cn[0].imag());       int fs = curS;       for (int i = 0; i < cn.size(); i++) {         int j = (i + 1) % cn.size();         int dx = (int)(cn[j].real() - cn[i].real());         int dy = (int)(cn[j].imag() - cn[i].imag());         int state = getState(dx, dy);         res += max(abs(dx), abs(dy));         while (curS != state) res++, curS = (curS + 1) % 4;       }       while (curS != fs) res++, curS = (curS + 1) % 4;       cout << res << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       long long int n;       cin >> n;       int fl = 0;       long long int ans = 0;       if (n == 2) {         cout << 2 << endl;         continue;       }       ans = pow(2, n);       for (int i = 1; i < n; i++) {         if (i < n / 2)           ans += pow(2, i);         else           ans -= pow(2, i);       }       cout << ans << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     int ans = 0;     int a, b;     cin >> a >> b;     if (a < b) swap(a, b);     cout << b <<     << (a - b) / 2 << endl;     return 0;   }


#include <bits/stdc++.h>   #define ll long long   #define db long double   #define x first   #define y second   #define mp make_pair   #define pb push_back   #define all(a) a.begin(), a.end()      using namespace std;      const int MAGIC = 300;   const int BLOCKS = 160000/MAGIC;      vector<int> tree;   vector<int> leave_block;      int add[BLOCKS];   int cnt[BLOCKS];      int n;      void recalc(int block) {     for (int i = block * MAGIC; i < min(n, (block + 1) * MAGIC); ++i) {       tree[i] = max(0, tree[i] - add[block]);     }     add[block] = 0;        for (int i = block * MAGIC; i < min(n, (block + 1) * MAGIC); ++i) {       int W = tree[i];       if (W < block * MAGIC) leave_block[i] = W;       else leave_block[i] = leave_block[W];     }      }      int layer(int x) {     return x/MAGIC;   }      int go_outer(int x) {     return max(0, leave_block[x] - add[layer(x)]);   }      int go(int x) {     return max(0, tree[x] - add[layer(x)]);   }      int main(){   #ifdef LOCAL    freopen( H_input.txt ,  r , stdin);    //freopen( H_output.txt ,  w , stdout);   #endif    ios_base::sync_with_stdio(0);    cin.tie(0);        int q;     cin >> n >> q;        tree.assign(n, 0);     for (int i = 1; i < n; ++i) {       cin >> tree[i];       tree[i]--;     }        leave_block.assign(n, 0);        for (int i = 0; i * MAGIC < n; ++i) {       recalc(i);     }        for (int i = 0; i < q; ++i) {       int tp;       cin >> tp;          //cout <<   ===   << go_outer(4) << endl;          if (tp == 1) {         int l, r, x;         cin >> l >> r >> x;         l--, r--;         for (int j = 0; j * MAGIC < n; ++j) {           int L = j*MAGIC, R = min(n, (j+1)*MAGIC) - 1;                      int pl = max(L, l), pr = min(R, r);           if (pl > pr) continue;           if (pl != L || pr != R || cnt[j] <= MAGIC) {             if (pl == L && pr == R) {               cnt[j]++;               add[j]+=x;               add[j] = min(add[j], (int) 1e8);             }             else {               for (int e = pl; e <= pr; ++e) tree[e] = max(0, tree[e] - x);             }           //cout <<   ???   << j << endl;             recalc(j);             //cout << leave_block[3] <<     << tree[3] <<     << pl <<      << pr  << endl;           }            else {             add[j]+=x;             add[j] = min(add[j], (int) 1e8);           }            }       }          else {         int u, v;         cin >> u >> v;            u--, v--;         while (true) {           if (u == v) break;           //cout << u <<     << v << endl;           //cout << go_outer(u) <<     << go_outer(v) << endl;           if (layer(u) < layer(v)) {             swap(u, v);           }           if (layer(u) > layer(v)) {             u = go_outer(u);           }           else {             int A = go_outer(u), B = go_outer(v);             if (A!=B) {               u = A, v = B;             }             else {               while (u != v) {                 if (u > v) u = go(u);                 else v = go(v);                }             }           }         }            cout << u+1 <<   n ;             }     }         }


#include <bits/stdc++.h>   using namespace std;   int n, t;   int s[100013];   int g[17][100013];   int lg[100013];   vector<pair<int, int> > sorted;   int gcd(int a, int b) { return (b == 0) ? a : gcd(b, a % b); }   int find_l(int gcf, int ind) {     int left = 0, right = sorted.size() - 1;     while (left < right) {       int mid = (left + right) / 2;       if (sorted[mid].first == gcf && sorted[mid].second == ind) {         break;       }       if (sorted[mid].first < gcf ||           (sorted[mid].first == gcf && sorted[mid].second < ind)) {         left = mid + 1;       } else {         right = mid;       }     }     return (left + right) / 2;   }   int find_r(int gcf, int ind) {     int left = 0, right = sorted.size() - 1;     while (left < right) {       int mid = (left + right + 1) / 2;       if (sorted[mid].first == gcf && sorted[mid].second == ind) {         break;       }       if (sorted[mid].first < gcf ||           (sorted[mid].first == gcf && sorted[mid].second < ind)) {         left = mid;       } else {         right = mid - 1;       }     }     return (left + right + 1) / 2;   }   int query(int l, int r) {     int tmp = l;     int gcf = 0;     for (int i = 16; i >= 0; i--)       if ((r - l + 1) & (1 << i)) {         gcf = gcd(gcf, g[i][l]), l = l + (1 << i);       }     l = tmp;     vector<pair<int, int> >::iterator left =         lower_bound(sorted.begin(), sorted.end(), make_pair(gcf, l));     vector<pair<int, int> >::iterator right =         upper_bound(sorted.begin(), sorted.end(), make_pair(gcf, r));     return r - l + 1 - max(0, (int)(right - left));   }   int main() {     scanf( %d , &n);     int l = 0;     for (int i = 1; i <= n; i++) {       scanf( %d , &s[i]);       sorted.push_back(make_pair(s[i], i));       if (i == (1 << (l + 1))) l++;       lg[i] = l;     }     sort(sorted.begin(), sorted.end());     for (int i = 1; i <= n; i++) {       g[0][i] = s[i];     }     for (int i = 1; i <= 16; i++) {       for (int j = 1; j <= n; j++) {         g[i][j] = gcd(g[i - 1][j], g[i - 1][min(n, j + (1 << (i - 1)))]);       }     }     scanf( %d , &t);     for (int i = 0; i < t; i++) {       int l, r;       scanf( %d%d , &l, &r);       printf( %d n , query(l, r));     }   }


#include <bits/stdc++.h>   using namespace std;   using uint = unsigned int;   using ll = long long;   using ld = long double;   using ull = unsigned long long;   using pii = pair<int, int>;   using pll = pair<ll, ll>;   void debug_out() { cerr << endl; }   template <typename Head, typename... Tail>   void debug_out(Head H, Tail... T) {     cerr <<     << H;     debug_out(T...);   }   template <typename T1, typename T2>   ostream &operator<<(ostream &out, const pair<T1, T2> &item) {     out <<  (  << item.first <<  ,   << item.second <<  ) ;     return out;   }   template <typename T>   ostream &operator<<(ostream &out, const vector<T> &v) {     for (const auto &item : v) out << item <<    ;     return out;   }   const int N = 100010;   const int B = 666013;   const int SZ = 500;   const int NRB = N / SZ + 5;   struct Block {     int i, l, r;     Block(int i, int l, int r) : i(i), l(l), r(r) {}   };   int bid[N], s[N], aux[SZ + 5];   int nOpen[NRB], nClosed[NRB];   ull pw[N], open[NRB][SZ + 5], closed[NRB][SZ + 5];   bool ok[N];   ull getHash(ull h[], int l, int r) { return h[r] - h[l] * pw[r - l]; }   int genStack(int l, int r) {     if (l >= N) return -2;     int top = -1;     for (int p = l; p < r && s[p]; ++p) {       if (s[p] > 0)         aux[++top] = s[p];       else {         if (top == -1 || aux[top] < 0)           aux[++top] = s[p];         else if (aux[top] != -s[p])           return -2;         else           --top;       }     }     return top;   }   void makeHashes(int i, int top) {     int p;     for (p = 0; p <= top && aux[p] < 0; ++p)       closed[i][p + 1] = closed[i][p] * B - aux[p];     nClosed[i] = p;     nOpen[i] = top + 1 - p;     reverse(aux + p, aux + p + nOpen[i]);     for (int j = 0; p + j <= top; ++j)       open[i][j + 1] = open[i][j] * B + aux[p + j];   }   void buildBlock(int i) {     int top = genStack(i * SZ, (i + 1) * SZ);     if (top == -2) return void(ok[i] = false);     ok[i] = true;     makeHashes(i, top);   }   void update(int p, int t) {     s[p] = t;     buildBlock(bid[p]);   }   bool process(int i, vector<Block> &v) {     int a = 0, b = nClosed[i];     while (a < b && !v.empty()) {       auto &lst = v.back();       int d = min(b - a, lst.r - lst.l);       if (lst.r - lst.l <= b - a) {         if (getHash(open[lst.i], lst.l, lst.r) == getHash(closed[i], a, a + d))           a += d, v.pop_back();         else           return false;       } else {         if (getHash(open[lst.i], lst.l, lst.l + d) == getHash(closed[i], a, b))           lst.l += d, a = b;         else           return false;       }     }     if (a < b) return false;     if (nOpen[i]) v.emplace_back(i, 0, nOpen[i]);     return true;   }   bool query(int l, int r) {     if (bid[l] == bid[r - 1]) return genStack(l, r) == -1;     int lid = NRB - 2, rid = NRB - 1;     int top = genStack(bid[l] * SZ + l % SZ, (bid[l] + 1) * SZ);     if (top == -2) return false;     makeHashes(lid, top);     top = genStack(bid[r] * SZ, bid[r] * SZ + r % SZ);     if (top == -2) return false;     makeHashes(rid, top);     vector<Block> v;     if (!process(lid, v)) return false;     for (int i = bid[l] + 1; i < bid[r]; ++i) {       if (!ok[i]) return false;       if (!process(i, v)) return false;     }     if (!process(rid, v)) return false;     return v.empty();   }   int main() {     ios_base::sync_with_stdio(false);     pw[0] = 1;     for (int i = 1; i < N; ++i) pw[i] = pw[i - 1] * B;     for (int i = 0; i < N; ++i) bid[i] = i / SZ;     int n, k, q, type, p, t, l, r;     cin >> n >> k;     for (int i = 0; i < n; ++i) cin >> s[i];     for (int i = 0; i < NRB; ++i) buildBlock(i);     for (cin >> q; q; --q) {       cin >> type;       if (type == 1) {         cin >> p >> t;         update(p - 1, t);       } else {         cin >> l >> r;         cout << (query(l - 1, r) ?  Yes  :  No ) <<   n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1000000007;   using pii = pair<long long, long long>;   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     long long q;     cin >> q;     while (q--) {       long long n, m;       cin >> n >> m;       vector<pair<long long, pii>> a;       long long len = 0;       for (long long i = 0; i < n; i++) {         long long x, y, z;         cin >> x >> y >> z;         if (i > 0 && x == a[len - 1].first) {           a[len - 1].second.first = max(a[len - 1].second.first, y);           a[len - 1].second.second = min(a[len - 1].second.second, z);         } else {           a.push_back({x, {y, z}});           len++;         }       }       n = len;       long long low = m, high = m, curt = 0;       long long pos = 1;       for (long long i = 0; i < n; i++) {         long long t = a[i].first, l = a[i].second.first, h = a[i].second.second;         if (l > h) {           pos = 0;           break;         }         low -= t - curt;         high += t - curt;         if (low > h || high < l) {           pos = 0;           break;         }         low = max(l, low);         high = min(h, high);         curt = t;       }       if (pos)         cout <<  YES n ;       else         cout <<  NO n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, x;     cin >> n >> x;     int s = 0;     for (int i = 0; i < n; ++i) {       int a;       cin >> a;       s += a;     }     s += n - 1;     if (s == x) {       cout <<  YES  << endl;     } else {       cout <<  NO  << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     vector<int> b1, b2;     int n;     cin >> n;     int a[n];     long long s1 = 0, s2 = 0;     for (int i = 0; i < n; i++) {       cin >> a[i];       if (a[i] > 0) {         s1 += a[i];         b1.push_back(a[i]);       } else {         s2 -= a[i];         b2.push_back(-a[i]);       }     }     if (s1 > s2) {       cout <<  first ;       return 0;     }     if (s1 < s2) {       cout <<  second ;       return 0;     }     for (int i = 0; i < min(b1.size(), b2.size()); i++) {       if (b1[i] > b2[i]) {         cout <<  first ;         return 0;       }       if (b1[i] < b2[i]) {         cout <<  second ;         return 0;       }     }     if (b1.size() != b2.size()) {       if (b1.size() > b2.size()) {         cout <<  first ;       } else {         cout <<  second ;       }       return 0;     }     for (int i = 0; i < b1.size(); i++) {       if (b1[i] != b2[i]) {         if (b1[i] > b2[i]) {           cout <<  first ;         } else {           cout <<  second ;         }         return 0;       }     }     if (a[n - 1] > 0) {       cout <<  first ;     } else {       cout <<  second ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1000 * 1000 + 100;   int d[MAXN];   int main() {     ios::sync_with_stdio(false);     long long n, m;     cin >> n >> m;     long long ans = n * (n - 1) * (n - 2) / 6;     ans -= m * (n - 2);     for (int i = 0; i < m; i++) {       int u, v;       cin >> u >> v;       d[u]++;       d[v]++;     }     for (int i = 1; i <= n; i++) ans += d[i] * (d[i] - 1) / 2;     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;      struct point{   public:       int x, y;   };      bool cmpx(point a, point b){       return a.x<b.x;   }      bool cmpy(point a, point b){       return a.y<b.y;   }      int main(){       int t, i, j, x1, x2, y1, y2, d;       point ptsx[4], ptsy[4];       cin>>t;       for(j=0; j<t; j++){           for(i=0; i<4; i++) cin>>ptsx[i].x>>ptsx[i].y;           sort(ptsx, ptsx+4, cmpx);           for(i=0; i<4; i++) ptsy[i]=ptsx[i];           sort(ptsy, ptsy+4, cmpy);           x1=ptsx[1].x;           x2=ptsx[2].x;           y1=ptsy[1].y;           y2=ptsy[2].y;           if(x2-x1>=y2-y1){               d=x2-x1-y2+y1;               y2=min(y2+d, ptsy[3].y);               d=x2-x1-y2+y1;               y1-=d;               cout<<x1-ptsx[0].x+ptsx[3].x-x2+min(abs(ptsx[0].y-y1)+abs(ptsx[1].y-y2), abs(ptsx[0].y-y2)+abs(ptsx[1].y-y1))+min(abs(ptsx[2].y-y1)+abs(ptsx[3].y-y2), abs(ptsx[2].y-y2)+abs(ptsx[3].y-y1))<<endl;           }           else{               d=y2-y1-x2+x1;               x2=min(x2+d, ptsx[3].x);               d=y2-y1-x2+x1;               x1-=d;               cout<<y1-ptsy[0].y+ptsy[3].y-y2+min(abs(ptsy[0].x-x1)+abs(ptsy[1].x-x2), abs(ptsy[0].x-x2)+abs(ptsy[1].x-x1))+min(abs(ptsy[2].x-x1)+abs(ptsy[3].x-x2), abs(ptsy[2].x-x2)+abs(ptsy[3].x-x1))<<endl;           }       }   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   inline void amin(T &a, T b) {     if (a > b) a = b;   }   template <class T>   inline void amax(T &a, T b) {     if (a < b) a = b;   }   int gcd(int x, int y) {     while (y) {       x %= y;       swap(x, y);     }     return x;   }   int GCD[111][111];   int N, B[111];   pair<int, int> A[111];   int best;   vector<int> v, best_v;   int sums[111];   void update() {     int sum = 0;     sum = sums[N - v.size()];     for (int i = 0; i < int(v.size()); i++)       sum += abs(A[i + N - v.size()].first - v[i]);     if (best > sum) {       best = sum;       best_v = v;     }   }   void rec(int x) {     update();     if ((int)v.size() == N || x == 59) {       return;     }     bool ok = true;     for (int i = 0; i < int(v.size()); i++)       if (GCD[v[i]][x] != 1) {         ok = false;         break;       }     if (ok) {       v.push_back(x);       rec(x + 1);       v.pop_back();     }     rec(x + 1);   }   int main() {     for (int i = 0; i < int(111); i++)       for (int j = 0; j < int(111); j++) GCD[i][j] = gcd(i, j);     scanf( %d , &N);     for (int i = 0; i < int(N); i++) {       int x;       scanf( %d , &x);       A[i] = make_pair(x, i);     }     sort(A, A + N);     for (int i = 0; i < int(N); i++) sums[i + 1] = sums[i] + A[i].first;     best = 1 << 29;     rec(2);     for (int i = 0; i < int(N); i++) B[i] = 1;     for (int i = 0; i < int(best_v.size()); i++)       B[A[i + N - best_v.size()].second] = best_v[i];     for (int i = 0; i < int(N); i++)       printf( %d%c , B[i], i + 1 == N ?   n  :    );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 5e5 + 10;   int n, m;   struct bian {     int from, to;   };   struct tree {     bian eg[N << 2];     int num, front[N << 1];     int zong;     int fa[N << 1], siz[N << 1];     void add(int x, int y) {       eg[++num].to = y;       eg[num].from = front[x];       front[x] = num;     }     void init() {       zong = n;       for (int i = 1; i <= zong; ++i) fa[i] = i, siz[i] = 1;     }     int find(int x) { return x == fa[x] ? x : fa[x] = find(fa[x]); }     int tot, now;     int son[N << 4][2];     long long tag[N << 4];     int root[N];     void merge(int x, int y) {       int d1 = find(x), d2 = find(y);       fa[++zong] = zong;       add(zong, d1);       add(zong, d2);       siz[zong] = siz[find(x)] + siz[find(y)];       fa[d1] = zong;       fa[d2] = zong;     }     int ll[N << 1], rr[N << 1], ids[N], p;     void dfs(int o) {       if (o <= n) {         ids[o] = ++p;         ll[o] = rr[o] = ids[o];         return;       }       ll[o] = 1e9;       for (int i = front[o]; i; i = eg[i].from) {         int to = eg[i].to;         dfs(to);         ll[o] = min(ll[o], ll[to]);         rr[o] = max(rr[o], rr[to]);       }     }     void opt1(int be, int &o, int l, int r, int L, int R, int w) {       if (o == 0) o = ++tot;       tag[o] = tag[be];       if (L <= l && r <= R) {         tag[o] += w;         son[o][0] = son[be][0];         son[o][1] = son[be][1];         return;       }       int mid = (l + r) >> 1;       if (mid >= L)         opt1(son[be][0], son[o][0], l, mid, L, R, w);       else         son[o][0] = son[be][0];       if (mid < R)         opt1(son[be][1], son[o][1], mid + 1, r, L, R, w);       else         son[o][1] = son[be][1];     }     long long opt2(int o, int l, int r, int i, long long now) {       if (o == 0) return now;       if (l == r) return now + tag[o];       int mid = (l + r) >> 1;       if (mid >= i)         return opt2(son[o][0], l, mid, i, now + tag[o]);       else         return opt2(son[o][1], mid + 1, r, i, now + tag[o]);     }   } T1;   struct tree_ {     bian eg[N << 2];     int num, front[N << 1];     int zong;     int fa[N << 1];     void add(int x, int y) {       eg[++num].to = y;       eg[num].from = front[x];       front[x] = num;     }     void init() {       zong = n;       for (int i = 1; i <= zong; ++i) fa[i] = i;     }     int find(int x) { return x == fa[x] ? x : fa[x] = find(fa[x]); }     void merge(int x, int y) {       int d1 = find(x), d2 = find(y);       fa[++zong] = zong;       add(zong, d1);       add(zong, d2);       fa[d1] = zong;       fa[d2] = zong;     }     int ll[N << 1], rr[N << 1], ids[N], p;     void dfs(int o) {       if (o <= n) {         ids[o] = ++p;         ll[o] = rr[o] = ids[o];         return;       }       ll[o] = 1e9;       for (int i = front[o]; i; i = eg[i].from) {         int to = eg[i].to;         dfs(to);         ll[o] = min(ll[o], ll[to]);         rr[o] = max(rr[o], rr[to]);       }     }     int col[N << 2];     void opt3(int o, int l, int r, int L, int R, int w) {       if (L <= l && r <= R) {         col[o] = w;         return;       }       int mid = (l + r) >> 1;       if (col[o]) {         col[o << 1] = col[o << 1 | 1] = col[o];         col[o] = 0;       }       if (mid >= L) opt3(o << 1, l, mid, L, R, w);       if (mid < R) opt3(o << 1 | 1, mid + 1, r, L, R, w);     }     int opt4(int o, int l, int r, int i) {       if (l == r) return col[o];       int mid = (l + r) >> 1;       if (col[o]) {         col[o << 1] = col[o << 1 | 1] = col[o];         col[o] = 0;       }       if (mid >= i)         return opt4(o << 1, l, mid, i);       else         return opt4(o << 1 | 1, mid + 1, r, i);     }   } T2;   int que[N][3];   struct b {     int fa[N << 1], zong;     void init() {       zong = n;       for (int i = 1; i <= n; ++i) fa[i] = i;     }     int find(int o) { return fa[o] == o ? o : fa[o] = find(fa[o]); }     void merge(int x, int y) {       int d1 = find(x), d2 = find(y);       fa[++zong] = zong;       fa[d1] = zong;       fa[d2] = zong;     }   } B1, B2;   int main() {     scanf( %d%d , &n, &m);     T1.init();     T2.init();     for (int i = 1; i <= m; ++i) {       char s[10];       scanf( %s , s);       if (s[0] ==  U ) {         int x, y;         scanf( %d%d , &x, &y);         que[i][0] = 1;         que[i][1] = x;         que[i][2] = y;         T1.merge(x, y);       }       if (s[0] ==  M ) {         int x, y;         scanf( %d%d , &x, &y);         que[i][0] = 2;         que[i][1] = x;         que[i][2] = y;         T2.merge(x, y);       }       if (s[0] ==  A ) {         int x;         scanf( %d , &x);         que[i][0] = 3;         que[i][1] = x;       }       if (s[0] ==  Z ) {         int x;         scanf( %d , &x);         que[i][0] = 4;         que[i][1] = x;       }       if (s[0] ==  Q ) {         int x;         scanf( %d , &x);         que[i][0] = 5;         que[i][1] = x;       }     }     for (int i = 1; i <= T1.zong; ++i)       if (T1.find(i) == i) T1.dfs(i);     for (int i = 1; i <= T2.zong; ++i)       if (T2.find(i) == i) T2.dfs(i);     B1.init();     B2.init();     for (int i = 1; i <= m; ++i) {       if (que[i][0] == 1) {         B1.merge(que[i][1], que[i][2]);       }       if (que[i][0] == 2) {         B2.merge(que[i][1], que[i][2]);       }       if (que[i][0] == 3) {         ++T1.now;         T1.opt1(T1.root[T1.now - 1], T1.root[T1.now], 1, n,                 T1.ll[B1.find(que[i][1])], T1.rr[B1.find(que[i][1])],                 T1.siz[B1.find(que[i][1])]);       }       if (que[i][0] == 4) {         T2.opt3(1, 1, n, T2.ll[B2.find(que[i][1])], T2.rr[B2.find(que[i][1])],                 T1.now);       }       if (que[i][0] == 5) {         printf( %lld n , T1.opt2(T1.root[T1.now], 1, n, T1.ids[que[i][1]], 0) -                              T1.opt2(T1.root[T2.opt4(1, 1, n, T2.ids[que[i][1]])],                                      1, n, T1.ids[que[i][1]], 0));       }     }   }


#include <bits/stdc++.h>   using namespace std;   int n, k, i;   int oma = 0, omi = 0, ma, mi;   int a[101];   string s;   int main() {     cin >> n >> k;     for (i = 1; i <= n; i++) {       cin >> s;       a[s.size()]++;     }     cin >> s;     for (i = 1; i < s.size(); i++) omi = omi + a[i];     mi = omi;     ma = oma;     omi = 5 * (omi / k) + 1 + omi;     oma = a[s.size()] + ((a[s.size()] - 1 + mi) / k) * 5 + mi;     cout << omi <<     << oma << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, k;   string s;   void solve() {}   int main() {     std::ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long test = 1;     cin >> test;     while (test--) {       cin >> n >> k;       cin >> s;       int ans = 0;       int cnt = 0;       for (long long i = 0; i < (n); ++i) {         if (s[i] ==  0 )           cnt++;         else {           if (i == cnt && cnt >= k + 1)             ans += (cnt - 1 - k) / (k + 1) + 1;           else             ans += (cnt - k) / (k + 1);           cnt = 0;         }       }       if (cnt == n)         cout << 1 + (cnt - 1) / (k + 1);       else         cout << ans + cnt / (k + 1);       solve();       cout <<   n ;     }   }


#include<cmath>   #include<cstdio>   #include<vector>   #include<algorithm>   #include<map>   using namespace std;      int main() {       int n, M=1000000007, tmp, maxc=100;       vector<int> c;       scanf( %d , &n);          int sumc=0;       for(int i=0;i<n;++i) {           scanf( %d , &tmp);           c.push_back(tmp);           sumc+=tmp;       }          int sumb=0, global_bi_over_i_ub=0;       vector<int> b(n, 0);       for(int i=0;i<n-1;++i) {           scanf( %d , &tmp);           sumb = sumb+tmp;           b[i+1] = b[i] + sumb;           global_bi_over_i_ub = min(global_bi_over_i_ub, -(b[i+1] / (i+2)));       }       int global_x_ub = maxc+global_bi_over_i_ub;          int q;       vector<int> x;       scanf( %d , &q);       for(int i=0;i<q;++i) {           scanf( %d , &tmp);           x.push_back(max(global_x_ub-maxc-5, min(global_x_ub+5, tmp)));       }       //printf( ub: %d , global_x_ub);          map<int,int> x2ans;       for(int xval=global_x_ub+5;xval>=global_x_ub-maxc-5;--xval) {           vector<int> *p_ans=nullptr, *p_ans_last=nullptr;           p_ans_last = new vector<int>(sumc+2,0);           (*p_ans_last)[0]=1;           for(int i=0;i<n;++i) {               p_ans = new vector<int>(sumc+2, 0);               int sum_last = 0, lower_bound=xval*(i+1)+b[i];               //printf( lb=%d, xval=%d, mul=%d, b=%d n , lower_bound, xval, xval*(i+1), b[i]);               for(int j=0;j<=c[i];++j) {                   sum_last = (sum_last + (*p_ans_last)[j])%M;                   (*p_ans)[j] = sum_last;               }               for(int j=c[i]+1;j<=sumc;++j) {                   sum_last = (sum_last - (*p_ans_last)[j-c[i]-1] + M) % M;                   sum_last = (sum_last + (*p_ans_last)[j]) % M;                   (*p_ans)[j] = sum_last;               }               for(int j=0;j<lower_bound && j<=sumc+1;++j)                   (*p_ans)[j]=0;               swap(p_ans, p_ans_last);               delete p_ans;           }           int cnt=0;           for(int i=0;i<=sumc;++i)               cnt = (cnt + (*p_ans_last)[i])%M;           x2ans[xval] = cnt;           delete p_ans_last;       }          for(int i=0;i<q;++i) {           printf( %d n , x2ans[x[i]]);       }          return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct query {     int n, str_l, id;     friend bool operator<(query a, query b) { return a.str_l < b.str_l; }   };   const long long MOD = 1e9 + 7;   const int maxn = 1e5 + 5;   int n, str_len;   char str[maxn];   long long ans[maxn], fac[maxn], ifac[maxn], inv[maxn], q25[maxn], q26[maxn],       iq26[maxn];   long long s[maxn];   query q[maxn];   int q_len;   int read_int() {     int t = 1, m = 0;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) t = -1;       ch = getchar();     }     while ( 0  <= ch && ch <=  9 )       m = (m << 3) + (m << 1) + ch -  0 , ch = getchar();     return t * m;   }   void init() {     fac[0] = fac[1] = ifac[0] = ifac[1] = inv[1] = 1;     q25[0] = q26[0] = iq26[0] = 1;     for (int i = 2; i < maxn; i++) {       fac[i] = fac[i - 1] * i % MOD;       inv[i] = (MOD - MOD / i) * inv[MOD % i] % MOD;       ifac[i] = ifac[i - 1] * inv[i] % MOD;     }     for (int i = 1; i < maxn; i++)       iq26[i] = iq26[i - 1] * inv[26] % MOD, q25[i] = q25[i - 1] * 25 % MOD,       q26[i] = q26[i - 1] * 26 % MOD;   }   long long qpow(long long a, long long b) {     long long c = 1;     while (b) {       if (b & 1) c = c * a % MOD;       b >>= 1, a = a * a % MOD;     }     return c;   }   inline long long C(long long a, long long b) {     return fac[a] * ifac[b] % MOD * ifac[a - b] % MOD;   }   int main() {     init();     int Q = read_int();     scanf( %s , str), str_len = strlen(str);     while (Q--) {       int t = read_int();       if (t == 1)         scanf( %s , str), str_len = strlen(str);       else         q_len++, q[q_len].str_l = str_len, q[q_len].n = read_int(),                  q[q_len].id = q_len;     }     sort(q + 1, q + 1 + q_len);     for (int t = 1; t <= q_len; t++) {       n = q[t].n, str_len = q[t].str_l;       if (str_len != q[t - 1].str_l) {         memset(s, 0, sizeof(s));         for (int i = str_len; i < maxn; i++)           s[i] = (s[i - 1] + C(i - 1, str_len - 1) * iq26[i] % MOD *                                  q25[i - str_len] % MOD) %                  MOD;       }       ans[q[t].id] = q26[n] * s[n] % MOD;     }     for (int i = 1; i <= q_len; i++) printf( %lld n , ans[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   T abs(T x) {     return x > 0 ? x : -x;   }   int n;   int m;   int x[100];   int main() {     scanf( %d%d , &n, &m);     int s = 0, f = 0;     for (int i = 0; i < n; i++) {       scanf( %d , &x[i]);       s += x[i];       f = max(f, x[i]);     }     if (s + m < f * n)       printf( -1 n );     else       for (int i = 0; i < n; i++) printf( %.10f n , (s + m + 0.0) / n - x[i]);     return 0;   }


#include <bits/stdc++.h>   const int N = 110;   using namespace std;   inline int read() {     int x = 0, f = 1;     int ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) {         f = -1;       }       ch = getchar();     }     while (ch <=  9  && ch >=  0 ) {       x = (x << 1) + (x << 3) + ch -  0 ;       ch = getchar();     }     return x * f;   }   int n, a[N];   int main() {     int q = read();     while (q--) {       bool flg = 0;       n = read();       for (int i = 1; i <= n; i++) {         a[i] = read();       }       sort(a + 1, a + 1 + n);       for (int i = 2; i <= n; i++) {         if (a[i] == a[i - 1] + 1) {           cout << 2 << endl;           flg = 1;           break;         }       }       if (!flg) cout << 1 << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void __print(int x) { cerr << x; }   void __print(long x) { cerr << x; }   void __print(long long x) { cerr << x; }   void __print(unsigned x) { cerr << x; }   void __print(unsigned long x) { cerr << x; }   void __print(unsigned long long x) { cerr << x; }   void __print(float x) { cerr << x; }   void __print(double x) { cerr << x; }   void __print(long double x) { cerr << x; }   void __print(char x) { cerr <<      << x <<     ; }   void __print(const char *x) { cerr <<     << x <<    ; }   void __print(const string &x) { cerr <<     << x <<    ; }   void __print(bool x) { cerr << (x ?  true  :  false ); }   template <typename T, typename V>   void __print(const pair<T, V> &x) {     cerr <<  { ;     __print(x.first);     cerr <<  , ;     __print(x.second);     cerr <<  } ;   }   template <typename T>   void __print(const T &x) {     int f = 0;     cerr <<  { ;     for (auto &i : x) cerr << (f++ ?  ,  :   ), __print(i);     cerr <<  } ;   }   void _print() { cerr <<  ] n ; }   template <typename T, typename... V>   void _print(T t, V... v) {     __print(t);     if (sizeof...(v)) cerr <<  ,  ;     _print(v...);   }   void pre() {}   void solve() {}   int p[100];   int vis[109];   int main() {     cin.sync_with_stdio(0);     cin.tie(0);     cin.exceptions(cin.failbit);     pre();     int n;     cin >> n;     for (int i = 0; i < (n); ++i) {       cin >> p[i];       vis[p[i]] = 1;     }     vector<pair<int, int> > v;     for (int i = 0; i < (n); ++i)       if (p[i]) p[i] = p[i] % 2 + 2;     v.push_back(make_pair(p[0], 1));     for (int i = 1; i <= (n - 1); ++i) {       if (p[i] == p[i - 1])         v.back().second++;       else         v.push_back(make_pair(p[i], 1));     }     if ((int)(v).size() == 1) {       if (p[0] == 0) {         if (n == 1)           cout << 0;         else           cout << 1;       } else         cout << 0;       return 0;     }     vector<int> cnt[2];     int fns = 0;     for (int i = 0; i < ((int)(v).size()); ++i) {       if (v[i].first == 0) {         if (i == 0)           ;         else if (i == (int)(v).size() - 1)           ;         else if (v[i - 1].first % 2 == v[i + 1].first % 2)           cnt[v[i - 1].first % 2].push_back(v[i].second);         else           fns++;       } else if (i != (int)(v).size() - 1 && v[i + 1].first != 0 &&                  v[i].first != v[i + 1].first) {         fns++;       }     }     int val[2];     val[0] = val[1] = 0;     for (int i = 1; i <= (n); ++i)       if (!vis[i]) val[i % 2]++;     sort(cnt[0].begin(), cnt[0].end());     sort(cnt[1].begin(), cnt[1].end());     reverse(cnt[0].begin(), cnt[0].end());     reverse(cnt[1].begin(), cnt[1].end());     int gns = n;     int st[2];     st[0] = val[0], st[1] = val[1];     vector<int> gg1 = cnt[0], gg2 = cnt[1];     int cns = fns;     for (int q = 0; q < (4); ++q) {       val[0] = st[0];       val[1] = st[1];       cnt[0] = gg1;       cnt[1] = gg2;       fns = cns;       if (v[(int)(v).size() - 1].first == 0) {         if (q & 2) {           if (val[v[(int)(v).size() - 2].first % 2] >=               v[(int)(v).size() - 1].second) {             val[v[(int)(v).size() - 2].first % 2] -=                 v[(int)(v).size() - 1].second;           } else             fns++;         } else           fns++;       }       if (v[0].first == 0) {         if (q & 1) {           if (val[v[1].first % 2] >= v[0].second) {             val[v[1].first % 2] -= v[0].second;           } else             fns++;         } else           fns++;       }       while ((int)(cnt[1]).size() && cnt[1].back() <= val[1]) {         val[1] -= cnt[1].back();         cnt[1].pop_back();       }       while ((int)(cnt[0]).size() && cnt[0].back() <= val[0]) {         val[0] -= cnt[0].back();         cnt[0].pop_back();       }       gns = min(gns, fns + 2 * ((int)(cnt[0]).size() + (int)(cnt[1]).size()));     }     cout << gns;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n = 0;     int answer = 0;     cin >> n;     int last = -1;     int xs = 0, ys = 0, x = 0, y = 0;     for (int i = 0; i < n; i++) {       int px = x, py = y;       char c;       cin >> c;       if (c ==  L )         x--;       else if (c ==  R )         x++;       else if (c ==  U )         y++;       else         y--;       if (abs(x - xs) + abs(y - ys) != i - last)         answer++, last = i - 1, xs = px, ys = py;     }     answer++;     cout << answer;   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = (long long)1000 * 1000 * 1000 * 1000 * 1000 * 100;   const int MOD = 1000 * 1000 * 1000 + 9;   const int SIZE = 5000;   int main() {     std::ios_base::sync_with_stdio(false);     int n;     cin >> n;     vector<int> a(n);     vector<vector<int> > p(100500);     for (int i = 0; i < n; ++i) {       cin >> a[i];       a[i] = abs(a[i]);       p[a[i]].push_back(i);     }     int cur = 0;     for (int i = 0; i < n; ++i) {       for (int j = i + 1; j < n; ++j)         if (a[j] < a[i]) ++cur;     }     for (int k = 1; k < 100500; ++k) {       if (p[k].size() == 0) continue;       int best = 0;       int before = 0;       int after = 0;       int tmp = 0;       for (int c = 0; c < n; ++c) {         if (a[c] > -k && a[c] < k) ++after;       }       int i = 0;       for (int cnt = 0; cnt < p[k].size(); ++cnt) {         for (; i != p[k][cnt]; ++i) {           if (a[i] > -k && a[i] < k) ++before, --after;         }         tmp += before - after;         if (tmp < best) best = tmp;       }       cur += best;     }     cout << cur << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 100010;   const int inf = 1e9;   int n, l[maxn], c[maxn], ans, cnt, pri[maxn], lst, cur, p[maxn], st[maxn],       f[maxn];   bool tf[maxn];   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , l + i);     for (int i = 1; i <= n; i++) scanf( %d , c + i);     for (int i = 2; i <= 100000; i++) {       if (!tf[i]) pri[++cnt] = i;       for (int j = 1; j <= cnt && i * pri[j] <= 100000; j++) {         tf[i * pri[j]] = true;         if (i % pri[j] == 0) break;       }     }     ans = inf;     for (int i = 1; i <= n; i++) {       lst = l[i];       cur = 0;       for (int j = 1; j <= cnt && pri[j] * pri[j] <= lst; j++)         if (lst % pri[j] == 0) {           p[++cur] = pri[j];           while (lst % pri[j] == 0) lst /= pri[j];         }       if (lst != 1) p[++cur] = lst;       for (int j = 1; j <= n; j++) {         st[j] = 0;         for (int k = 1; k <= cur; k++)           if (l[j] % p[k] == 0) st[j] |= (1 << (k - 1));       }       for (int i = 0; i < (1 << 10); i++) f[i] = inf;       f[(1 << cur) - 1] = c[i];       for (int i = 1; i <= n; i++)         for (int j = 0; j < (1 << cur); j++)           f[st[i] & j] = min(f[st[i] & j], f[j] + c[i]);       ans = min(ans, f[0]);     }     if (ans >= inf)       printf( -1 n );     else       printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long num[200000];   pair<long long, long long> p[200000];   int main() {     long long n, m, k, sum = 0, cnt = 1;     cin >> n >> m >> k;     for (int i = 1; i <= n; i++) {       cin >> p[i].first;       p[i].second = i;     }     sort(p + 1, p + n + 1);     for (int i = n; i > n - m * k; i--) {       sum += p[i].first;       num[cnt++] = p[i].second;     }     cout << sum <<   n ;     sort(num + 1, num + m * k + 1);     for (int i = m; i < m * k; i += m) cout << num[i] <<    ;     return 0;   }


#include <bits/stdc++.h>   using ll = long long;   using ld = long double;   using ull = unsigned long long;   using namespace std;   const int N = 1e5 + 2, SQ = 400;   int n, q, a[N], jump[N], cost[N];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cin >> n >> q;     for (int i = (0); i <= (n - 1); ++i) cin >> a[i];     for (int i = (n - 1); i >= (0); --i) {       int nxt = min(n, i + a[i]);       if (nxt == n) {         jump[i] = i;         continue;       }       if (nxt / SQ > i / SQ)         jump[i] = nxt, cost[i] = 1;       else         jump[i] = jump[nxt], cost[i] = cost[nxt] + 1;     }     while (q--) {       int t;       cin >> t;       if (t == 0) {         int x, y;         cin >> x >> y;         x--;         a[x] = y;         for (int i = (x); i >= (x / SQ * SQ); --i) {           int nxt = min(n, i + a[i]);           if (nxt == n) {             jump[i] = i;             cost[i] = 0;             continue;           }           if (nxt / SQ > i / SQ)             jump[i] = nxt, cost[i] = 1;           else             jump[i] = jump[nxt], cost[i] = cost[nxt] + 1;         }       } else {         int x, res = 1;         cin >> x;         x--;         while (cost[x]) res += cost[x], x = jump[x];         cout << x + 1 <<     << res <<   n ;       }     }     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:102400000,102400000 )   #pragma GCC optimize( Ofast )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native )   using namespace std;   const int maxn = 2e5 + 5;   map<int, int> dp, pos;   int pre[maxn];   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int i, j, k, m, n;     cin >> n;     for (int i = 1; i <= n; ++i) {       cin >> k;       if (!dp.count(k - 1)) {         dp[k] = 1;         pre[i] = -1;         pos[k] = i;       } else if (dp[k - 1] + 1 > dp[k]) {         dp[k] = dp[k - 1] + 1;         pos[k] = i;         pre[i] = pos[k - 1];       }     }     pair<int, int> mst = {0, 0};     for (auto it : dp) {       if (it.second > mst.second) {         mst.first = it.first;         mst.second = it.second;       }     }     int npos = pos[mst.first];     vector<int> ans;     while (npos != -1) {       ans.push_back(npos);       npos = pre[npos];     }     reverse(ans.begin(), ans.end());     cout << ans.size() << endl;     for (auto it : ans) cout << it <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     vector<vector<char> > v(4);     for (int i = 0; i < 4; i++) v[i].resize(4);     for (int i = 0; i < 4; i++) {       for (int j = 0; j < 4; j++) {         cin >> v[i][j];       }     }     for (int i = 0; i < 3; i++) {       for (int j = 0; j < 3; j++) {         int cntd = 0, cnth = 0;         if (v[i][j] ==  # )           cnth++;         else           cntd++;         if (v[i][j + 1] ==  # )           cnth++;         else           cntd++;         if (v[i + 1][j] ==  # )           cnth++;         else           cntd++;         if (v[i + 1][j + 1] ==  # )           cnth++;         else           cntd++;         if (cntd >= 3 || cnth >= 3) {           cout <<  YES n ;           return 0;         }       }     }     cout <<  NO n ;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long a[100], b[100], i, n, m, r;     cin >> n >> m >> r;     long long ans = r;     for (i = 0; i < n; ++i) {       cin >> a[i];     }     for (i = 0; i < m; ++i) {       cin >> b[i];     }     long long minn = *min_element(a, a + n);     long long akcia = r / minn;     r %= minn;     r += akcia * (*max_element(b, b + m));     cout << max(ans, r) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, x = 0;     cin >> n;     string s;     while (n-- != 0) {       cin >> s;       if (s.find( + ) != string::npos)         x++;       else         x--;     }     cout << x;     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize(2)   #pragma GCC optimize(3,  Ofast ,  inline )   using namespace std;   void err(istream_iterator<string> it) { cerr << endl; }   template <typename T, typename... Args>   void err(istream_iterator<string> it, T a, Args... args) {}   namespace fastIO {   bool IOerror = 0;   inline char nc() {     static char buf[100000], *p1 = buf + 100000, *pend = buf + 100000;     if (p1 == pend) {       p1 = buf;       pend = buf + fread(buf, 1, 100000, stdin);       if (pend == p1) {         IOerror = 1;         return -1;       }     }     return *p1++;   }   inline bool blank(char ch) {     return ch ==     || ch ==   n  || ch ==   r  || ch ==   t ;   }   inline void read(int &x) {     char ch;     while (blank(ch = nc()))       ;     if (IOerror) return;     for (x = ch -  0 ; (ch = nc()) >=  0  && ch <=  9 ; x = x * 10 + ch -  0 )       ;   }   }  // namespace fastIO   using namespace fastIO;   const double PI = acos(-1.0);   const double eps = 1e-8;   const int maxn = 3e5 + 5;   int cnt[maxn];   int main() {     int t;     scanf( %d , &t);     while (t--) {       string s;       int n, k;       cin >> n >> k >> s;       int ans = 1;       for (int i = 0; i < k; ++i) cnt[i] = 0;       for (int i = 0; i < s.size(); ++i) {         if (s[i] ==  ? ) continue;         if ((s[i] ==  0  && cnt[i % k] == 1) ||             (s[i] ==  1  && cnt[i % k] == -1)) {           ans = 0;           break;         }         cnt[i % k] = s[i] ==  0  ? -1 : 1;       }       int cnt1 = 0, cnt0 = 0;       for (int i = 0; i < n; ++i)         if (cnt[i % k]) s[i] = cnt[i % k] == -1 ?  0  :  1 ;       for (int i = 0; i < k; ++i) {         if (s[i] ==  1 )           cnt1++;         else if (s[i] ==  0 )           cnt0++;       }       if (2 * cnt1 > k || 2 * cnt0 > k) ans = 0;       puts(ans ?  YES  :  NO );     }   }