#include <bits/stdc++.h>   using namespace std;   const long long UNDEF = -1;   const long long INF = 1e18;   template <typename T>   inline bool chkmax(T& aa, T bb) {     return aa < bb ? aa = bb, true : false;   }   template <typename T>   inline bool chkmin(T& aa, T bb) {     return aa > bb ? aa = bb, true : false;   }   static char stdinBuffer[1024];   static char* stdinDataEnd = stdinBuffer + sizeof(stdinBuffer);   static const char* stdinPos = stdinDataEnd;   void readAhead(size_t amount) {     size_t remaining = stdinDataEnd - stdinPos;     if (remaining < amount) {       memmove(stdinBuffer, stdinPos, remaining);       size_t sz = fread(stdinBuffer + remaining, 1,                         sizeof(stdinBuffer) - remaining, stdin);       stdinPos = stdinBuffer;       stdinDataEnd = stdinBuffer + remaining + sz;       if (stdinDataEnd != stdinBuffer + sizeof(stdinBuffer)) *stdinDataEnd = 0;     }   }   int rint() {     readAhead(16);     int x = 0;     bool neg = false;     while (*stdinPos ==     || *stdinPos ==   n ) ++stdinPos;     if (*stdinPos ==  - ) {       ++stdinPos;       neg = true;     }     while (*stdinPos >=  0  && *stdinPos <=  9 ) {       x *= 10;       x += *stdinPos -  0 ;       ++stdinPos;     }     return neg ? -x : x;   }   char rch() {     readAhead(16);     while (*stdinPos ==     || *stdinPos ==   n ) ++stdinPos;     char ans = *stdinPos;     ++stdinPos;     return ans;   }   long long rlong() {     readAhead(32);     long long x = 0;     bool neg = false;     while (*stdinPos ==     || *stdinPos ==   n ) ++stdinPos;     if (*stdinPos ==  - ) {       ++stdinPos;       neg = true;     }     while (*stdinPos >=  0  && *stdinPos <=  9 ) {       x *= 10;       x += *stdinPos -  0 ;       ++stdinPos;     }     return neg ? -x : x;   }   const int mc = 26, mn = 1e6 + 4;   char s[mn], t[mn];   int sc[mc + 1], tc[mc + 1], wc[mc + 1];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     scanf( %s n%s n , s, t);     int sl = strlen(s), tl = strlen(t);     int q = 0;     for (int i = 0; i < sl; i++) {       if (s[i] !=  ? )         sc[s[i] -  a ]++;       else         q++;     }     for (int i = 0; i < tl; i++) {       tc[t[i] -  a ]++;     }     int imin = 0, imax = mn;     while (imin < imax) {       int imid = (imin + imax) >> 1;       long long need = 0;       for (int c = 0; c < 26; c++) {         long long want = (tc[c] * (long long)imid) - sc[c];         if (want >= 0) need += want;       }       if (need <= q)         imin = imid + 1;       else         imax = imid;     }     imin--;     for (int c = 0; c < 26; c++) {       wc[c] = tc[c] * imin - sc[c];     }     int cidx = 0;     for (int i = 0; i < sl; i++) {       if (s[i] ==  ? ) {         while (cidx < mc && wc[cidx] <= 0) cidx++;         if (cidx < mc) {           s[i] =  a  + cidx;           wc[cidx]--;         } else {           s[i] =  a ;         }       }     }     printf( %s n , s);   }


#include <bits/stdc++.h>   using namespace std;   int arr[100005];   int reduce(int n) {     while (n % 2 == 0) n /= 2;     while (n % 3 == 0) n /= 3;     return n;   }   int main() {     int n;     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %d , &arr[i]);     }     int r = reduce(arr[0]);     bool ok = true;     for (int i = 1; i < n; i++) {       if (reduce(arr[i]) != r) {         ok = false;         break;       }     }     if (ok)       printf( Yes n );     else       printf( No n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 0x3f3f3f3f;   void err() { cout <<   033[39;0m  << endl; }   template <class T, class... Ts>   void err(const T& arg, const Ts&... args) {     cout << arg <<    ;     err(args...);   }   const int N = 100000 + 5;   int n, h, m, k;   int H[N];   pair<int, int> M[N];   int main() {     scanf( %d%d%d%d , &n, &h, &m, &k);     m /= 2;     for (int i = 1; i <= n; i++) {       scanf( %d%d , &H[i], &M[i].first);       M[i].second = i;       M[i].first %= m;       M[i].first++;     }     sort(M + 1, M + 1 + n);     int res = 0, t = 0;     for (int i = 1; i <= n; i++) {       int num = 0;       if (M[i].first < k) {         int l = lower_bound(M + 1, M + 1 + n, make_pair(M[i].first, 0)) - M;         int r =             upper_bound(M + 1, M + 1 + n, make_pair(m - k + M[i].first, inf)) -             M - 1;         num = r - l + 1;       } else {         num +=             upper_bound(M + 1, M + 1 + n, make_pair(M[i].first - k, inf)) - M - 1;         num +=             n - (lower_bound(M + 1, M + 1 + n, make_pair(M[i].first, 0)) - M) + 1;       }       if (res < num) {         res = num;         t = M[i].first;       }     }     vector<int> kk;     for (int i = 1; i <= n; i++) {       int num = 0;       if (M[i].first < k) {         int l = lower_bound(M + 1, M + 1 + n, make_pair(M[i].first, 0)) - M;         int r =             upper_bound(M + 1, M + 1 + n, make_pair(m - k + M[i].first, inf)) -             M - 1;         num = r - l + 1;         if (num == res) {           for (int i = 1; i < l; i++) kk.push_back(M[i].second);           for (int i = r + 1; i <= n; i++) kk.push_back(M[i].second);           break;         }       } else {         int l =             upper_bound(M + 1, M + 1 + n, make_pair(M[i].first - k, inf)) - M - 1;         num += l;         int r = lower_bound(M + 1, M + 1 + n, make_pair(M[i].first, 0)) - M;         num += n - r + 1;         if (num == res) {           for (int i = l + 1; i < r; i++) kk.push_back(M[i].second);           break;         }       }     }     cout << (n - res) <<     << t - 1 << endl;     sort(kk.begin(), kk.end());     for (int i = 0; i < kk.size(); i++) {       printf( %d  , kk[i]);     }     puts(  );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 7, inf = 1e8;   int read() {     int s = 0, w = 1;     char c;     while (c = getchar(), c >  9  || c <  0 )       if (c ==  - ) w = -1;     while (c >=  0  && c <=  9 ) s = s * 10 + c -  0 , c = getchar();     return s * w;   }   void write(int x) {     if (x < 0) x = -x, putchar( - );     if (x >= 10) write(x / 10);     putchar(x % 10 |  0 );   }   void writeln(int x) {     write(x);     puts(  );   }   struct edge {     int t, nxt;   } e[N];   struct node {     int s, tag;   };   int n, cnt, rt;   int head[N], siz[N], Mx[N], Cx[N], Mn[N], Mson[N], Bigs[N], ans[N], vis[N];   void add(int u, int t) {     e[++cnt].t = t;     e[cnt].nxt = head[u];     head[u] = cnt;   }   struct tree {     node tr[N << 1];     void pushdown(int ts) {       if (!tr[ts].tag) return;       tr[ts << 1].s = 0;       tr[ts << 1 | 1].s = 0;       tr[ts << 1].tag = 1;       tr[ts << 1 | 1].tag = 1;       tr[ts].tag = 0;     }     inline void add(int ts, int l, int r, int pos, int x) {       pushdown(ts);       tr[ts].s += x;       if (l == r) return;       int mid = (l + r) >> 1;       if (pos <= mid)         add(ts << 1, l, mid, pos, x);       else         add(ts << 1 | 1, mid + 1, r, pos, x);     }     inline void clear() {       tr[1].s = 0;       tr[1].tag = 1;     }     inline int query1(int ts, int l, int r, int L, int R) {       if (L > R) return 0;       if (l == L && r == R) return tr[ts].s;       pushdown(ts);       int mid = (l + r) >> 1;       if (R <= mid)         return query1(ts << 1, l, mid, L, R);       else if (L > mid)         return query1(ts << 1 | 1, mid + 1, r, L, R);       else         return query1(ts << 1, l, mid, L, mid) +                query1(ts << 1 | 1, mid + 1, R, mid + 1, R);     }     inline int query2(int ts, int l, int r, int L, int R) {       if (L > R || !tr[ts].s) return 0;       if (l == r) return l;       pushdown(ts);       int mid = (l + r) >> 1;       if (R <= mid)         return query2(ts << 1, l, mid, L, R);       else if (L > mid)         return query2(ts << 1 | 1, mid + 1, r, L, R);       else {         int v = query2(ts << 1 | 1, mid + 1, r, mid + 1, R);         if (v)           return v;         else           return query2(ts << 1, l, mid, L, mid);       }     }     inline int query3(int ts, int l, int r, int L, int R) {       if (L > R || !tr[ts].s) return inf;       if (l == r) return l;       pushdown(ts);       int mid = (l + r) >> 1;       if (R <= mid)         return query3(ts << 1, l, mid, L, R);       else if (L > mid)         return query3(ts << 1 | 1, mid + 1, r, L, R);       else {         int v = query3(ts << 1, l, mid, L, mid);         if (v != inf)           return v;         else           return query3(ts << 1 | 1, mid + 1, r, mid + 1, R);       }     }   } T1, T2, T3;   void chu(int &mx, int &cx, int &mn, int v, int &id, int t) {     if (v > mx)       cx = mx, mx = v, id = t;     else if (v > cx)       cx = v;     if (v) mn = min(mn, v);   }   void dfs1(int u) {     siz[u] = 1;     Mson[u] = -1;     for (int i = head[u]; i; i = e[i].nxt) {       int t = e[i].t;       dfs1(t);       siz[u] += siz[t];       chu(Mx[u], Cx[u], Mn[u], siz[t], Mson[u], t);     }     Bigs[u] = Mson[u];     chu(Mx[u], Cx[u], Mn[u], n - siz[u], Mson[u], 0);     T1.add(1, 1, n, siz[u], 1);   }   void Add(int u) {     T3.add(1, 1, n, siz[u], 1);     for (int i = head[u]; i; i = e[i].nxt) {       int t = e[i].t;       if (vis[t]) continue;       Add(t);     }   }   int query2(int ts, int l, int r, int L, int R) {     if (L > R || T1.tr[ts].s - T3.tr[ts].s <= 0) return 0;     if (l == r) return l;     T3.pushdown(ts);     int mid = (l + r) >> 1;     if (R <= mid)       return query2(ts << 1, l, mid, L, R);     else if (L > mid)       return query2(ts << 1 | 1, mid + 1, r, L, R);     else {       int v = query2(ts << 1 | 1, mid + 1, r, mid + 1, R);       if (v)         return v;       else         return query2(ts << 1, l, mid, L, mid);     }   }   int query3(int ts, int l, int r, int L, int R) {     if (L > R || T1.tr[ts].s - T3.tr[ts].s <= 0) return inf;     if (l == r) return l;     T3.pushdown(ts);     int mid = (l + r) >> 1;     if (R <= mid)       return query3(ts << 1, l, mid, L, R);     else if (L > mid)       return query3(ts << 1 | 1, mid + 1, r, L, R);     else {       int v = query3(ts << 1, l, mid, L, mid);       if (v != inf)         return v;       else         return query3(ts << 1 | 1, mid + 1, r, mid + 1, R);     }   }   void dfs2(int u) {     T1.add(1, 1, n, siz[u], -1);     T2.add(1, 1, n, siz[u], 1);     for (int i = head[u]; i; i = e[i].nxt) {       int t = e[i].t;       if (t == Bigs[u]) continue;       dfs2(t);       T3.clear();     }     if (Bigs[u] != -1) dfs2(Bigs[u]), vis[Bigs[u]] = 1;     int v = 0;     if (Mson[u] == Bigs[u]) {       v = T3.query2(1, 1, n, 1, (Mx[u] - Mn[u]) / 2);       ans[u] = max(max(Mx[u] - v, Mn[u] + v), Cx[u]);       v = T3.query3(1, 1, n, (Mx[u] - Mn[u]) / 2, n);       ans[u] = min(ans[u], max(max(Mx[u] - v, Mn[u] + v), Cx[u]));     }     Add(u);     if (Bigs[u] != -1) vis[Bigs[u]] = 0;     T1.add(1, 1, n, siz[u], 1);     T2.add(1, 1, n, siz[u], -1);     if (Mson[u] != Bigs[u]) {       v = max(           query2(1, 1, n, 1, (Mx[u] - Mn[u]) / 2),           T2.query2(1, 1, n, 1 + siz[u], min((Mx[u] - Mn[u]) / 2 + siz[u], n)) -               siz[u]);       ans[u] = max(max(Mx[u] - v, Mn[u] + v), Cx[u]);       v = min(query3(1, 1, n, (Mx[u] - Mn[u]) / 2, n),               T2.query3(1, 1, n, (Mx[u] - Mn[u]) / 2 + siz[u], n) - siz[u]);       ans[u] = min(ans[u], max(max(Mx[u] - v, Mn[u] + v), Cx[u]));     }   }   int main() {     n = read();     if (n == 1) return puts( 0 ), 0;     memset(Mn, 60, sizeof Mn);     for (int i = 1, u, v; i <= n; i++) {       u = read(), v = read();       if (u == 0)         rt = v;       else         add(u, v);     }     dfs1(rt);     dfs2(rt);     for (int i = 1; i <= n; i++) writeln(ans[i]);   }


#include <bits/stdc++.h>   using namespace std;   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long n;     cin >> n;     if (n % 2) {       cout <<  black ;     } else {       cout <<  white  << endl;       cout <<  1 2 ;     }     return 0;   }


#include <bits/stdc++.h>   int s, i, e;   int main() {     int t;     scanf( %d , &t);     while (t--) {       int ans = 0;       scanf( %d%d%d , &s, &i, &e);       if (s > i + e) {         printf( %d n , e + 1);       } else if (s + e <= i) {         printf( %d n , 0);       } else {         int k = e - (i + e - s) / 2;         printf( %d n , k);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double pi = acos(-1.0);   const double eps = 1e-11;   template <class T>   inline void ckmin(T &a, T b) {     if (b < a) a = b;   }   template <class T>   inline void ckmax(T &a, T b) {     if (b > a) a = b;   }   template <class T>   inline T sqr(T x) {     return x * x;   }   using VI = vector<int>;   int main() {     std::ios::sync_with_stdio(false);     int n, k;     while (cin >> n >> k) {       vector<int> a(n, -1);       vector<int> b(n, -1);       for (int i = 0; i < (k); ++i) {         int p;         cin >> p;         --p;         if (a[p] < 0) a[p] = i;         b[p] = i;       }       int ret = 0;       for (int x = 0; x < (n); ++x)         for (int d = -1; d <= 1; d++) {           int y = x + d;           if (y < 0 || y >= n) continue;           if (a[x] < 0)             ++ret;           else if (b[y] < a[x])             ++ret;         }       printf( %d n , ret);       break;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1000000 + 20;   int xor_n[maxn];   int p[maxn];   int n;   int q;   void init() {     xor_n[0] = 0;     for (int i = 1; i < maxn; i++) {       xor_n[i] = i ^ xor_n[i - 1];     }   }   int main() {     init();     while (~scanf( %d , &n)) {       q = 0;       for (int i = 1; i <= n; i++) {         scanf( %d , &p[i]);         q = q ^ p[i];       }       for (int i = 1; i <= n; i++) {         int tmp = n / i;         if (n % i == 0) {           if (tmp & 1) q = q ^ xor_n[i - 1];         } else {           if (tmp & 1)             q = q ^ xor_n[i - 1] ^ xor_n[n % i];           else             q = q ^ xor_n[n % i];         }       }       printf( %d n , q);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int i, j, k, n, x, y, a, ans = 0;     cin >> n;     int arr[n];     for (i = 0; i < n; i++) {       cin >> arr[i];       if (arr[i] > ans) ans = arr[i];     }     for (i = 2; i <= n; i++) {       for (j = 0; j < n - i + 1; j++) {         int a = arr[j];         for (k = 1; k < i; k++) {           a = a ^ arr[j + k];         }         if (a > ans) ans = a;       }     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     string s;     cin >> s;     int p = s.find( . );     if (s[p - 1] ==  9 ) {       cout <<  GOTO Vasilisa.  <<   n ;     } else if (s[p + 1] <  5 ) {       cout << s.substr(0, p) <<   n ;     } else {       string z = s.substr(0, p);       z[p - 1]++;       cout << z <<   n ;     }   }   void t(int t) {     if (!t) {       cin >> t;     }     while (t--) {       solve();     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     t(1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int dp[1000007];   int main() {     int n;     scanf( %d , &n);     dp[1] = dp[2] = 1;     for (int i = 3; i <= n; i++) {       int im = (i - 1) / 2;       if (2 * im == (i - 1) && im % 2 == 0)         dp[i] = dp[im];       else if ((2 * im + 1) == (i - 1))         dp[i] = dp[im] && dp[im + 1];     }     printf( %d n , dp[n]);   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 5500;   const int INF = 1E9;   int a[MAXN], b[MAXN], c[MAXN], d[MAXN];   int f[MAXN][MAXN];   vector<int> g[MAXN];   inline bool cmp(int a, int b) { return c[a] > c[b]; }   int main() {     int n, m, k, s;     scanf( %d%d%d , &n, &m, &k);     s = k;     for (int i = 1; i <= n; i++) {       scanf( %d%d%d , &a[i], &b[i], &c[i]);       s += b[i];       d[i] = i;     }     for (int i = 1; i <= m; i++) {       int u, v;       scanf( %d%d , &u, &v);       d[v] = max(d[v], u);     }     for (int i = 1; i <= n; i++) g[d[i]].push_back(i);     for (int i = 1; i <= n; i++) sort(g[i].begin(), g[i].end(), cmp);     for (int i = 0; i <= n; i++)       for (int j = 0; j <= s; j++) f[i][j] = -INF;     for (int i = n; i >= 0; i--)       for (int j = 0; j <= s - b[i]; j++) {         if (j + b[i] >= a[i + 1]) f[i][j] = max(f[i][j], f[i + 1][j + b[i]]);         for (int l = 0, t = 0; l < g[i].size() && j + b[i] - (l + 1) >= a[i + 1];              l++) {           t += c[g[i][l]];           f[i][j] = max(f[i][j], f[i + 1][j + b[i] - (l + 1)] + t);         }       }     printf( %d n , f[0][k] < 0 ? -1 : f[0][k]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<long long> a;   int main() {     int n;     cin >> n;     for (long long x, y, z, i = 1; i <= n; i++) {       cin >> x >> y >> z;       long long l = 0;       if (x % 2 == 1) {         l = y;         x--;         long long h = min(x * y, x / 2 * z);         l = l + h;       } else {         l = min(x / 2 * z, x * y);       }       a.push_back(l);     }     for (long long i = 0; i < a.size(); i++) {       cout << a[i] << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     long long n;     cin >> n;     if (n % 2)       cout << setprecision(0) << fixed <<  -  << ceil((1.0 * n) / 2) <<   n ;     else       cout << fixed << n / 2 <<   n ;   }   int main() { solve(); }


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


#include <bits/stdc++.h>   using namespace std;   const long double eps = 1e-9;   const long double pi = acos(-1.0);   int gcd(int a, int b) { return (b == 0) ? a : gcd(b, a % b); }   int xabs(int a) { return a > 0 ? a : -a; }   struct spoint {     double x;     double y;     int id;     spoint();     spoint(double x, double y) : x(x), y(y){};   };   struct svector {     double x;     double y;     svector();     svector(double x, double y) : x(x), y(y) {}     svector(spoint a, spoint b) {       x = b.x - a.x;       y = b.y - a.y;     }     double len() const { return sqrt((x * x) + (y * y)); }     friend svector operator+(const svector a, const svector b) {       return svector(a.x + b.x, a.y + b.y);     }     friend bool operator==(const svector a, const svector b) {       return (a.x == b.x && a.y == b.y);     }     friend double operator*(const svector a, const svector b) {       return a.x * b.x + a.y * b.y;     }   };   int main() {     vector<spoint> mas;     for (int i = 0; i < 8; i++) {       double a, b;       cin >> a >> b;       mas.push_back(spoint(a, b));     }     for (int i = 0; i < 5; i++) {       for (int k = i + 1; k < 6; k++) {         for (int j = k + 1; j < 7; j++) {           for (int z = j + 1; z < 8; z++) {             svector a1(mas[i], mas[k]);             svector b1(mas[i], mas[j]);             svector c1(mas[i], mas[z]);             if ((a1 + b1 == c1 && fabs(a1.len() - b1.len()) < eps &&                  a1 * b1 == 0) ||                 (a1 + c1 == b1 && fabs(a1.len() - c1.len()) < eps &&                  a1 * c1 == 0) ||                 (b1 + c1 == a1 && fabs(c1.len() - b1.len()) < eps &&                  b1 * c1 == 0)) {               vector<spoint> mm;               vector<int> qw;               for (int q = 0; q < 8; q++) {                 if (q != i && q != k && q != j && q != z) {                   mm.push_back(mas[q]);                   qw.push_back(q);                 }               }               svector a2(mm[0], mm[1]);               svector b2(mm[0], mm[2]);               svector c2(mm[0], mm[3]);               if ((a2 + b2 == c2 && a2 * b2 == 0) ||                   (a2 + c2 == b2 && a2 * c2 == 0) ||                   (b2 + c2 == a2 && b2 * c2 == 0)) {                 cout <<  YES  << endl;                 cout << i + 1 <<     << k + 1 <<     << j + 1 <<     << z + 1                      << endl;                 cout << qw[0] + 1 <<     << qw[1] + 1 <<     << qw[2] + 1 <<                          << qw[3] + 1 << endl;                 return 0;               }             }           }         }       }     }     cout <<  NO ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     int n, m, k;     cin >> n >> m >> k;     int mn = INT_MAX;     for (int i = 1; i <= n; i++) {       int x;       cin >> x;       if (i != m && x != 0 && x <= k) {         mn = min(mn, abs(i - m));       }     }     cout << mn * 10;   }


#include <bits/stdc++.h>   using namespace std;   const long long inf = 1e9 + 7;   const long long INF = 1LL << 60;   const long long mod = 1e9 + 7;   const long double eps = 1e-8;   const long double pi = acos(-1.0);   template <class T>   inline bool chmax(T& a, T b) {     if (a < b) {       a = b;       return 1;     }     return 0;   }   template <class T>   inline bool chmin(T& a, T b) {     if (a > b) {       a = b;       return 1;     }     return 0;   }   struct P {     long long x, y;   };   long double ex(P s, P t, P r) {     long double x1 = (long double)t.x - (long double)s.x;     long double y1 = (long double)t.y - (long double)s.y;     long double x2 = (long double)r.x - (long double)s.x;     long double y2 = (long double)r.y - (long double)s.y;     return x1 * y2 - x2 * y1;   }   bool cross(P a, P b, P s, P t) {     if (ex(a, b, s) * ex(a, b, t) > 0) return false;     if (ex(b, a, s) * ex(b, a, t) > 0) return false;     if (ex(t, s, a) * ex(t, s, b) > 0) return false;     return ex(s, t, a) * ex(s, t, b) < eps;   }   pair<bool, pair<long double, long double>> intersection_ls(P a1, P a2, P b1,                                                              P b2) {     long double d1 = abs(ex(b1, a1, b2));     long double d2 = abs(ex(b1, a2, b2));     if (!cross(a1, a2, b1, b2)) {       return {false, {0.0, 0.0}};     }     return {true,             {a1.x + (a2.x - a1.x) * d1 / (d1 + d2),              a1.y + (a2.y - a1.y) * d1 / (d1 + d2)}};   }   long long gcd(long long x, long long y) {     if (y == 0) return x;     return gcd(y, x % y);   }   void solve() {     long long n;     cin >> n;     vector<pair<P, P>> vec;     long long ans = 0;     for (long long i = 0; i < n; i++) {       long long ax, ay, bx, by;       cin >> ax >> ay >> bx >> by;       vec.push_back({P{ax, ay}, P{bx, by}});       ans += gcd(abs(ax - bx), abs(ay - by)) + 1;     }     map<pair<long long, long long>, long long> mp;     for (long long i = 0; i < n; i++) {       for (long long j = i + 1; j < n; ++j) {         auto res = intersection_ls(vec[i].first, vec[i].second, vec[j].first,                                    vec[j].second);         if (!res.first) continue;         long double X = res.second.first, Y = res.second.second;         if (floor(X + eps) < X + 2 * eps && floor(X + eps) > X - 2 * eps) {           if (floor(Y + eps) < Y + 2 * eps && floor(Y + eps) > Y - 2 * eps) {             mp[{floor(X + eps), floor(Y + eps)}]++;           }         }       }     }     for (auto p : mp) {       long long k = 2;       while (k * (k - 1) / 2 <= p.second) {         if (k * (k - 1) / 2 == p.second) {           ans -= (k - 1);           break;         }         ++k;       }     }     cout << ans << endl;   }   signed main() {     ios::sync_with_stdio(false);     cin.tie(0);     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, a[20], st, tp, i;   int main() {     cin >> n;     for (i = 0; i < n; i++) cin >> a[i];     for (st = 0; st < (1 << n); st++) {       tp = 0;       for (i = 0; i < n; i++) {         if (st & (1 << i)) {           tp += a[i];           tp %= 360;         } else {           tp -= a[i];           tp += 360;           tp %= 360;         }       }       if (tp == 0) {         cout <<  yes ;         return 0;       }     }     cout <<  no ;   }


#include <bits/stdc++.h>   using namespace std;   long long ans = 0;   long long rootans = 0;   vector<long long> dp1(200001, 1);   vector<long long> dp2(200001, 1);   vector<int> adj[200001];   void dfs(int u, int p) {     for (int i : adj[u]) {       if (i != p) {         dfs(i, u);         dp1[u] += dp1[i];       }     }   }   void dfs2(int u, int p) {     rootans += dp1[u];     for (int i : adj[u]) {       if (i != p) {         dfs2(i, u);       }     }   }   void dfs3(int u, int p) {     for (int i : adj[u]) {       if (i != p) {         dp2[i] = dp2[u] - dp1[i] + dp1[1] - dp1[i];         ans = max(ans, dp2[i]);         dfs3(i, u);       }     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int n;     cin >> n;     int a, b;     for (int i = 1; i < n; i++) {       cin >> a >> b;       adj[a].push_back(b);       adj[b].push_back(a);     }     dfs(1, 0);     dfs2(1, 0);     dp2[1] = rootans;     dfs3(1, 0);     cout << ans << endl;   }


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


#include <bits/stdc++.h>   using namespace std;   static const int maxn = 100012;   int K1, K2, K3;   int T1, T2, T3;   int N;   int C[maxn];   void Read() {     int i;     scanf( %d%d%d , &K1, &K2, &K3);     scanf( %d%d%d , &T1, &T2, &T3);     scanf( %d , &N);     for (i = 0; i < N; ++i) {       scanf( %d , &C[i]);     }   }   inline bool Greater(long long x, long long y) { return x > y; }   long long Result;   long long X[maxn];   long long Y[maxn];   long long Z[maxn];   void Work() {     int i;     Result = 0;     memset(X, 0, sizeof(X));     memset(Y, 0, sizeof(Y));     memset(Z, 0, sizeof(Z));     if (K1 > N) K1 = N;     if (K2 > N) K2 = N;     if (K3 > N) K3 = N;     make_heap(X, X + K1, Greater);     make_heap(Y, Y + K2, Greater);     make_heap(Z, Z + K3, Greater);     for (i = 0; i < N; ++i) {       long long t = C[i];       pop_heap(X, X + K1, Greater);       if (t < X[K1 - 1]) t = X[K1 - 1];       t += T1;       X[K1 - 1] = t;       push_heap(X, X + K1, Greater);       pop_heap(Y, Y + K2, Greater);       if (t < Y[K2 - 1]) t = Y[K2 - 1];       t += T2;       Y[K2 - 1] = t;       push_heap(Y, Y + K2, Greater);       pop_heap(Z, Z + K3, Greater);       if (t < Z[K3 - 1]) t = Z[K3 - 1];       t += T3;       Z[K3 - 1] = t;       push_heap(Z, Z + K3, Greater);       if (Result < t - C[i]) Result = t - C[i];     }   }   void Write() { printf( %I64d n , Result); }   int main() {     Read();     Work();     Write();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char s[100005];   long long int V[256];   map<pair<int, long long int>, int> M;   int main() {     int i, n;     long long int prefixSum = 0, ans = 0;     for (i = 0; i < 26; i++) scanf( %lld , &V[ a  + i]);     scanf( %s , s);     n = strlen(s);     for (i = 0; i < n; i++) {       ans += M[make_pair(s[i], prefixSum)];       prefixSum += V[(int)s[i]];       M[make_pair(s[i], prefixSum)]++;     }     printf( %lld n , ans);   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:16777216 )   using namespace std;   int n, k;   char g[3][100005];   bool f;   bool isval(int i, int j) {     if (j >= n) return true;     if (j < 0) return false;     if (g[i][j] ==  X ) return false;     return true;   }   void dfs(int i, int j, int t) {     if (j >= n)       f = true;     else {       g[i][j] =  X ;       if (j + k > t && isval((i + 1) % 2, j + k))         dfs((i + 1) % 2, (j + k), t + 1);       if (j + 1 > t && isval(i, j + 1)) dfs(i, j + 1, t + 1);       if (j - 1 > t && isval(i, j - 1)) dfs(i, (j - 1), t + 1);     }   }   int main() {     cin >> n >> k;     for (int i = 0; i < 2; i++) cin >> g[i];     f = 0;     dfs(0, 0, 0);     if (!f)       cout <<  NO  << endl;     else       cout <<  YES  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n,i,j,k,a[5050],x[5050],y[5050];   long long scp(int i, int j, int k) {     long long xa=x[i]-x[j];     long long ya=y[i]-y[j];     long long xb=x[k]-x[j];     long long yb=y[k]-y[j];     return xa*xb+ya*yb;   }   int main() {     scanf( %d ,&n);     for (i=0; i<n; i++) scanf( %d%d ,&x[i],&y[i]);     a[0]=0;     a[1]=1;     for (i=2; i<n; i++) {       for (j=i; j>=0; --j) {         if (j>=2 && scp(a[j-2],a[j-1],i)<=0) continue;         if (j>=1 && j<i && scp(a[j-1],i,a[j])<=0) continue;         if (j+1<i && scp(i,a[j],a[j+1])<=0) continue;         for (k=i; k>j; --k) a[k]=a[k-1];         a[j]=i;         break;       }       if (j<0) { puts( -1 ); return 0; }     }     for (i=0; i<n; i++) printf( %d  ,a[i]+1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 0x3f3f3f3f;   const long long infL = LLONG_MAX;   struct psychotronic_induction {     int electromagnetic_wave = 7;   };   const int nmax = 1e5 + 10;   int n, m, a[nmax];   ;   int s[nmax], used[nmax];   vector<int> g[nmax];   pair<int, int> edge[nmax];   int second_node(int idx, int node) {     return (edge[idx].first == node) ? edge[idx].second : edge[idx].first;   }   bool dfs(int node, int curr = 0) {     s[node] ^= curr;     used[node] = 1;     for (auto &it : g[node]) {       if (used[second_node(it, node)]) {         if (s[second_node(it, node)] != 1 ^ a[it] ^ s[node]) return 0;         continue;       }       s[second_node(it, node)] = 1 ^ a[it] ^ s[node];       if (!dfs(second_node(it, node))) return 0;     }     return 1;   }   void mark(int node, int s) {     used[node] = s;     for (auto &it : g[node]) {       if (used[second_node(it, node)] == s) continue;       mark(second_node(it, node), s);     }   }   int main() {     scanf( %d %d , &n, &m);     for (int i = 1; i <= n; ++i) scanf( %d , &a[i]);     for (int i = 1; i <= m; ++i) {       int nr;       scanf( %d , &nr);       for (int j = 1; j <= nr; ++j) {         int x;         scanf( %d , &x);         if (!edge[x].first)           edge[x].first = i;         else           edge[x].second = i;       }     }     swap(n, m);     for (int i = 1; i <= m; ++i)       g[edge[i].first].push_back(i), g[edge[i].second].push_back(i);     for (int i = 1; i <= n; ++i) {       if (used[i]) continue;       if (!dfs(i, 0)) {         mark(i, 0);         if (!dfs(i, 1)) {           printf( NO n );           return 0;         }       }       mark(i, 1);     }     printf( YES n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int Nmax = 1e5 + 5;   string s, t;   int n, m, pos, l, r;   int pre[Nmax];   int suf[Nmax];   int main() {     cin >> s;     cin >> t;     n = s.size();     m = t.size();     s =     + s;     t =     + t;     pos = 1;     for (int i = 1; i <= m; i++) {       while (pos <= n && s[pos] != t[i]) pos++;       if (pos > n) break;       pre[pos++] = i;     }     for (int i = 1; i <= n; i++) {       if (pre[i] == 0) pre[i] = pre[i - 1];     }     pos = n;     for (int i = m; i >= 1; i--) {       while (pos > 0 && s[pos] != t[i]) pos--;       if (pos == 0) break;       suf[pos--] = m - i + 1;     }     for (int i = n; i >= 1; i--) {       if (suf[i] == 0) suf[i] = suf[i + 1];     }     for (int i = 0; i <= n; i++) {       if (pre[i] + suf[i + 1] > l + r) {         l = pre[i];         r = suf[i + 1];       }     }     if (l + r == 0)       cout <<  - ;     else {       if (l + r > m) {         for (int i = 1; i <= m; i++) cout << t[i];         return 0;       }       for (int i = 1; i <= l; i++) cout << t[i];       for (int i = m - r + 1; i <= m; i++) cout << t[i];     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     int depth;     cin >> depth;     int n = (1 << (depth + 1)) - 1;     vector<int> pre(n + 1, 0), add(n + 1, 0);     for (int i = 2; i <= n; ++i) {       cin >> pre[i];     }     vector<int> way(n + 1, 0);     for (int i = 2; i <= n; ++i) {       way[i] = way[i / 2] + pre[i];     }     int target = *max_element((way).begin(), (way).end());     for (int i = n / 2 + 1; i <= n; ++i) {       add[i] = target - way[i];     }     for (int i = n / 2; i >= 2; --i) {       add[i] = min(add[2 * i], add[2 * i + 1]);       add[2 * i] -= add[i];       add[2 * i + 1] -= add[i];     }     cout << accumulate((add).begin(), (add).end(), 0) <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   bool ispos(long long x, long long y, long long n, long long m) {     if (x < 0 or x >= n or y < 0 or y >= m)       return false;     else       return true;   }   signed solve() {     long long n, m;     cin >> n >> m;     string s[n];     for (long long i = 0; i < n; i++) cin >> s[i];     char a[n][m];     vector<pair<pair<long long, long long>, long long>> v;     for (long long i = 0; i < n; i++) {       for (long long j = 0; j < m; j++) a[i][j] =  . ;     }     for (long long i = 0; i < n; i++) {       for (long long j = 0; j < m; j++) {         long long sz = 0;         if (s[i][j] ==  * ) {           for (long long k = 1; k <= max(n, m); k++) {             if (ispos(i - k, j, n, m) and s[i - k][j] ==  *  and                 ispos(i, j - k, n, m) and s[i][j - k] ==  *  and                 ispos(i + k, j, n, m) and s[i + k][j] ==  *  and                 ispos(i, j + k, n, m) and s[i][j + k] ==  * ) {               sz++;             } else               break;           }         }         if (sz > 0) {           a[i][j] =  * ;           v.push_back({{i + 1, j + 1}, sz});           for (long long k = 1; k <= sz; k++) {             a[i - k][j] =  * ;             a[i + k][j] =  * ;             a[i][j - k] =  * ;             a[i][j + k] =  * ;           }         }       }     }     for (long long i = 0; i < n; i++) {       for (long long j = 0; j < m; j++) {         if (s[i][j] != a[i][j]) {           cout <<  -1                 <<   n ;           return 0;         }       }     }     cout << v.size() <<   n ;     for (long long i = 0; i < v.size(); i++) {       cout << v[i].first.first <<     << v[i].first.second <<     << v[i].second            <<   n ;     }   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long tests = 1;     while (tests--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 100005;   const int N = 200005;   int from[N], to[N];   stack<pair<int, int> > G[MAX];   stack<int> res;   bool visited[2 * N];   void dfs(int src, int ind = -1) {     if (ind != -1) {       visited[ind] = true;     }     while (!G[src].empty()) {       int v = G[src].top().first, e = G[src].top().second;       G[src].pop();       if (!visited[e]) {         dfs(v, e);       }     }     res.push(src);   }   int main() {     int n, m;     scanf( %d %d , &n, &m);     for (int i = 0; i < m; i++) {       scanf( %d %d , &from[i], &to[i]);       from[i]--;       to[i]--;       G[from[i]].push(make_pair(to[i], i));       G[to[i]].push(make_pair(from[i], i));     }     int pre = -1, cnt = 0;     for (int i = 0; i < n; i++) {       if (G[i].size() % 2) {         if (pre == -1) {           pre = i;         } else {           G[pre].push(make_pair(i, cnt + m));           G[i].push(make_pair(pre, cnt++ + m));           pre = -1;         }       }     }     if ((cnt + m) % 2) {       G[0].push(make_pair(0, cnt + m));     }     dfs(0);     pre = res.top();     res.pop();     printf( %d n , res.size());     while (!res.empty()) {       if (res.size() % 2) {         printf( %d %d n , 1 + pre, 1 + res.top());       } else {         printf( %d %d n , 1 + res.top(), 1 + pre);       }       pre = res.top();       res.pop();     }     return 0;   }


#include <bits/stdc++.h>   const long long mod = 1000000007;   long long qpow(long long v, long long st) {     long long r = 1;     while (st) {       if (st & 1) {         r *= v;         r %= mod;       }       v = v * v;       v %= mod;       st = st / 2;     }     return r;   }   long long f[1024];   long long dp[1024][1024];   long long sdp[1024][1024];   long long getDP(int, int);   long long getSdp(int b1, int b2) {     if (sdp[b1][b2] != -1) return sdp[b1][b2];     if (b2 == 0) return getDP(b1 - 2, 0);     sdp[b1][b2] = getSdp(b1, b2 - 1) + getDP(b1 - 2, b2) * qpow(f[b2], mod - 2);     sdp[b1][b2] %= mod;     return sdp[b1][b2];   }   long long getDP(int b1, int b2) {     if (dp[b1][b2] != -1) return dp[b1][b2];     if (!b1) return f[b2];     long long sol = 0;     if (b1 >= 2) {       long long p = getSdp(b1, b2);       p *= f[b2];       p %= mod;       p *= (b1 - 1);       p %= mod;       sol += p;       sol %= mod;     }     if (b2 > 0) {       sol += getDP(b1, b2 - 1) * b2;       sol %= mod;     }     sol += getDP(b1 - 1, b2);     if (sol >= mod) sol %= mod;     dp[b1][b2] = sol;     return dp[b1][b2];   }   int main() {     int i, j, k;     f[0] = 1;     for (i = 1; i <= 1000; i++) {       f[i] = f[i - 1] * i;       f[i] %= mod;     }     j = k = 0;     int n, l;     scanf( %d , &n);     for (i = 0; i < n; i++) {       scanf( %d , &l);       if (l == 1)         j++;       else         k++;     }     memset(dp, -1, sizeof(dp));     memset(sdp, -1, sizeof(sdp));     printf( %d n , (int)getDP(j, k));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int frombase(int x, int base) {     int i = 0;     int ans = 0;     while (x) {       ans += ((x % base) * pow((double)10, i));       i++;       x /= base;     }     return ans;   }   int tobase(int x, int base) {     int i = 0;     int ans = 0;     while (x) {       ans += ((x % 10) * pow((double)base, i));       i++;       x /= 10;     }     return ans;   }   int main() {     int a, b;     cin >> a >> b;     int maxi = 0;     int x = a;     while (x) {       maxi = max(x % 10, maxi);       x /= 10;     }     x = b;     while (x) {       maxi = max(x % 10, maxi);       x /= 10;     }     maxi++;     int sum = tobase(a, maxi) + tobase(b, maxi);     sum = frombase(sum, maxi);     x = 0;     while (sum) {       sum /= 10;       x++;     }     cout << x << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k, sum = 0;     cin >> n >> k;     int a[n];     for (int i = 0; i < n; i++) {       cin >> a[i];     }     for (int j = 0; j < k; j++) {       int c1 = 0, c2 = 0;       for (int i = j; i < n; i += k) {         if (a[i] == 1)           c1++;         else           c2++;       }       (c1 > c2) ? (sum += c2) : (sum += c1);     }     cout << sum << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     if ((int)s.size() < 26) {       cout << -1;       return 0;     }     char cur =  a ;     bool fg = 0;     for (int i = 0; i < (int)s.size(); i++) {       if (s[i] <= cur) {         if (cur ==  z ) {           s[i] = cur;           fg = 1;           break;         } else           s[i] = cur;         cur++;       }     }     if (cur ==  z  && fg)       cout << s;     else       cout << -1;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   T nextInt() {     T x = 0, p = 1;     char ch;     do {       ch = getchar();     } while (ch <=    );     if (ch ==  - ) {       p = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = x * 10 + (ch -  0 );       ch = getchar();     }     return x * p;   }   const int maxN = (int)4e5 + 10;   const int INF = (int)1e9;   const int mod = (int)1e9 + 7;   const long long LLINF = (long long)1e15;   int fw[maxN];   int answer[maxN];   vector<pair<int, int> > g[maxN];   int get(int r) {     int ret = 0;     for (; r >= 0; r = (r & (r + 1)) - 1) {       ret += fw[r];     }     return ret;   }   void update(int r) {     for (; r < maxN; r |= r + 1) {       fw[r]++;     }   }   int l[maxN];   int r[maxN];   int main() {     ios_base::sync_with_stdio(0);     int n;     cin >> n;     vector<int> x;     for (int i = 0; i < n; ++i) {       cin >> l[i] >> r[i];       x.push_back(l[i]);       x.push_back(r[i]);     }     sort(x.begin(), x.end());     for (int i = 0; i < n; ++i) {       l[i] = lower_bound(x.begin(), x.end(), l[i]) - x.begin();       r[i] = lower_bound(x.begin(), x.end(), r[i]) - x.begin();       g[r[i]].push_back(make_pair(l[i], i));     }     for (int i = 0; i < maxN; ++i) {       for (auto x : g[i]) {         int l = x.first;         int idx = x.second;         answer[idx] = get(maxN - 1) - get(l);         update(l);       }     }     for (int i = 0; i < n; ++i) {       cout << answer[i] <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int read() {     int q = 0;     char ch =    ;     while (ch <  0  || ch >  9 ) ch = getchar();     while (ch >=  0  && ch <=  9 ) q = q * 10 + ch -  0 , ch = getchar();     return q;   }   const int N = 100005;   double P[N][110], ans;   int n, m, a[N], b[N];   double C(int d, int u) {     if (d < u || d < 0 || u < 0) return 0;     double ans = 1;     for (register int i = d - u + 1; i <= d; ++i) ans *= i;     for (register int i = 1; i <= u; ++i) ans /= i;     return ans;   }   int main() {     n = read();     for (register int i = 1; i <= n; ++i)       a[i] = b[i] = read(), P[i][a[i]] = 1, ans += (a[i] == 0);     m = read();     while (m--) {       int x = read(), y = read(), k = read();       ans -= P[x][0];       for (register int i = 0; i <= a[x]; ++i) {         double tmp = 0, all = C(b[x], k);         for (register int j = 0; j <= k; ++j)           tmp += P[x][i + j] * C(b[x] - i - j, k - j) * C(i + j, j);         P[x][i] = tmp / all;       }       ans += P[x][0], b[x] -= k, b[y] += k;       printf( %.10lf n , ans);     }     return 0;   }


#include <bits/stdc++.h>   int const INF = 2e9;   int const MOD = 1000000007;   int const MAXN = 100010;   using namespace std;   int n, m, sum1, sum2, ans;   int a[MAXN], b[MAXN];   int main() {     ios_base::sync_with_stdio(0);     cin >> n >> m;     for (int i = 0; i < n; i++) cin >> a[i];     for (int j = 0; j < m; j++) cin >> b[j];     int i = 1, j = 1;     sum1 = a[0], sum2 = b[0];     while (true) {       if (sum1 < sum2)         sum1 += a[i], i++;       else if (sum2 < sum1)         sum2 += b[j], j++;       else {         if (i == n && j == m) {           ans++;           break;         } else           sum1 = a[i], sum2 = b[j], i++, j++, ans++;       }     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[100010], dp[100010], rec[100010];   int n;   int main() {     while (~scanf( %d , &n)) {       int maxn = 0;       for (int i = 1; i <= n; i++) {         dp[i] = 1;         scanf( %d , &a[i]);       }       for (int i = 1; i <= n; i++) {         rec[a[i]] = 1;         if (rec[a[i] - 1] > 0) {           dp[a[i]] = dp[a[i] - 1] + 1;         }         maxn = max(maxn, dp[a[i]]);       }       printf( %d n , n - maxn);     }   }


#include <bits/stdc++.h>   using namespace std;   long long zyo[114514], sum[114514], kai[114514];   long long mo = 1000000007;   long long extgcd(long long a, long long b, long long &x, long long &y) {     long long g = a;     x = 1;     y = 0;     if (b != 0) g = extgcd(b, a % b, y, x), y -= (a / b) * x;     return g;   }   long long invMod(long long a, long long m) {     long long x, y;     if (extgcd(a, m, x, y) == 1) return (x + m) % m;     return 0;   }   long long co(int a, int b) {     if (a < 0 || b < 0 || b > a) return 0;     return ((kai[a] * invMod(kai[b], mo)) % mo * invMod(kai[a - b], mo)) % mo;   }   int main() {     long long out = 0;     int n, k;     string s;     zyo[0] = kai[0] = 1;     sum[0] = 0;     for (int i = 0; i < 100100; i++) {       zyo[i + 1] = (zyo[i] * 10) % mo;       kai[i + 1] = (kai[i] * (i + 1)) % mo;     }     cin >> n >> k;     cin >> s;     reverse(s.begin(), s.end());     for (int i = 0; i < n; i++) sum[i + 1] = sum[i] + (s[i] -  0 );     for (int i = 0; i < n; i++) {       int now = (s[i] -  0 );       out = (out + (zyo[i] * co(n - i - 1, k)) % mo * now) % mo;     }     for (int i = 1; i < n; i++) {       long long now = sum[n] - sum[i];       out = (out + (zyo[i - 1] * co(n - i - 1, k - 1)) % mo * now) % mo;     }     cout << out << endl;   }


#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) {     if (b == 0)       return a;     else       return gcd(b, a % b);   }   long long lcm(long long a, long long b) { return (a / gcd(a, b)) * b; }   bool isPrime(int n) {     if (n <= 1) return false;     if (n <= 3) return true;     if (n % 2 == 0 || n % 3 == 0) return false;     for (int i = 5; i * i <= n; i = i + 6)       if (n % i == 0 || n % (i + 2) == 0) return false;     return true;   }   struct segment {     int start;     int end;   };   struct monster {     int a;     int b;     int nof_to_kill;     monster(int attack, int health) {       a = attack;       b = health;     }     bool operator<(const monster &new_monster) const {       return (nof_to_kill * a < new_monster.nof_to_kill * new_monster.a);     }   };   void solution() {     int64_t n{};     cin >> n;     cout << -n + 1 <<     << n << endl;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t;     cin >> t;     while (t--) {       solution();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e6;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n;     cin >> n;     int h[n];     for (int i = 0; i < n; ++i) {       cin >> h[i];     }     vector<int> v(n, 0);     int maxx = 0;     for (int i = n - 1; i >= 0; i--) {       v[i] = max(0, maxx - h[i] + 1);       maxx = max(maxx, h[i]);     }     for (int i = 0; i < n; i++) {       cout << v[i] <<    ;     }   }


#include <bits/stdc++.h>   int main() {     int n, m;     int a, b;     int min1, min2;     int s1 = 0, s2 = 0, k1 = 0, k2 = 0;     scanf( %d%d , &n, &m);     while (n--) {       scanf( %d , &a);       if (a % 2 == 0)         s1++;       else         s2++;     }     while (m--) {       scanf( %d , &b);       if (b % 2 == 0)         k1++;       else         k2++;     }     if (s1 > k2)       min1 = k2;     else       min1 = s1;     if (k1 > s2)       min2 = s2;     else       min2 = k1;     printf( %d , min1 + min2);   }


#include <bits/stdc++.h>   using namespace std;   long long pow_mod(long long x, long long y) {     long long ret = 1;     while (y) {       if (y & 1) ret = (ret * x) % 1000000007;       x = (x * x) % 1000000007;       y >>= 1;     }     return ret;   }   long long f[2000010];   void init() {     f[0] = 1;     for (int i = 1; i <= 2000005; i++) f[i] = (f[i - 1] * i) % 1000000007;   }   long long inv(long long x) { return pow_mod(x, 1000000007 - 2); }   long long C(long long x, long long y) {     long long ret;     ret = (f[x] * inv(f[y])) % 1000000007;     ret = (ret * inv(f[x - y])) % 1000000007;     return ret;   }   int main() {     init();     int n;     scanf( %d , &n);     long long ans = 0;     for (int i = 0; i <= n; i++) ans = (ans + C(i + n + 1, n)) % 1000000007;     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long t;     cin >> t;     while (t--) {       long long n, i;       cin >> n;       long long c1 = 0, c2 = 0;       vector<long long> a(n);       for (i = 0; i < n; i++) {         cin >> a[i];         if (a[i] % 2)           c1++;         else           c2++;       }       if (!c2 and c1 == 1)         cout << -1 << endl;       else {         if (c2) {           cout << 1 << endl;           for (i = 0; i < n; i++) {             if (a[i] % 2 == 0) {               cout << i + 1 << endl;               break;             }           }         } else {           cout << 2 << endl;           long long k = 0;           for (i = 0; i < n; i++) {             if (a[i] % 2 == 1) {               cout << i + 1 <<    ;               k++;               if (k == 2) {                 cout << endl;                 break;               }             }           }         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int casex, n, k;   int num, hed[200010], nex[400010], vt[400010];   long long dp[200010][10], sum[200010], ans;   int read() {     int u = 0;     char c = getchar();     while (c <  0  || c >  9 ) c = getchar();     while (c >=  0  && c <=  9 ) u = (u << 1) + (u << 3) + c -  0 , c = getchar();     return u;   }   void add(int x, int y) {     vt[++num] = y, nex[num] = hed[x], hed[x] = num;     vt[++num] = x, nex[num] = hed[y], hed[y] = num;   }   void dfs1(int u, int fa) {     for (int i = hed[u]; i; i = nex[i]) {       if (vt[i] == fa) continue;       dfs1(vt[i], u);       for (int j = 1; j < k; j++) dp[u][j] += dp[vt[i]][j - 1];       sum[u] += sum[vt[i]] + dp[vt[i]][k - 1];       dp[u][0] += dp[vt[i]][k - 1];     }     dp[u][0]++;   }   void dfs2(int u, int fa) {     int tmp1 = dp[u][k - 1], tmp2 = dp[u][max(0, k - 2)];     for (int j = k - 1; j >= 2; j--) dp[u][j] += dp[fa][j - 1] - dp[u][j - 2];     dp[u][1] += dp[fa][0] - tmp1;     dp[u][0] += dp[fa][k - 1] - tmp2;     sum[u] += sum[fa] - sum[u] - tmp1 + dp[fa][k - 1] - tmp2;     for (int i = hed[u]; i; i = nex[i]) {       if (vt[i] == fa) continue;       dfs2(vt[i], u);     }   }   int main() {     n = read(), k = read();     for (int i = 1; i <= n - 1; i++) {       int x = read(), y = read();       add(x, y);     }     dfs1(1, 0);     for (int i = hed[1]; i; i = nex[i]) dfs2(vt[i], 1);     for (int i = 1; i <= n; i++) {       ans += sum[i];       for (int j = 1; j < k; j++) ans += dp[i][j];     }     printf( %lld , ans / 2);   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using pii = pair<int, int>;   using vi = vector<int>;   using vii = vector<vector<int>>;   const ll LINF = 1LL << 60;   const int INF = 1 << 29;   const int MOD = 1e9 + 7;   int main() {     int n;     cin >> n;     vector<pii> v(n);     for (int i = 0; i < n; i++) {       int x, w;       cin >> x >> w;       v[i] = {x + w, x - w};     }     sort((v).begin(), (v).end());     int ans = 0, cur = -1e9 - 5;     for (int i = 0; i < n; i++) {       if (cur <= v[i].second) {         cur = v[i].first;         ans++;       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1100;   int n, m, l[N], u[N], dd, ll;   double d[N][N], p = 1;   vector<pair<int, int> > el;   vector<int> eld;   int main() {     int i, j, x;     cin >> n >> m;     for (i = 1; i <= m; ++i) {       cin >> l[i];       for (j = 1; j <= l[i]; ++j) {         cin >> x;         el.push_back(pair<int, int>(x, i));       }     }     sort(el.begin(), el.end());     dd = el[el.size() - n].first;     for (i = el.size() - 1; el[i].first != dd; --i) {       p = p * (u[el[i].second] + 1) / (l[el[i].second] ? l[el[i].second] : 1);       ++u[el[i].second];       --l[el[i].second];     }     ll = i - el.size() + n + 1;     for (; i >= 0 && el[i].first == dd; --i) eld.push_back(el[i].second);     d[0][0] = p;     for (j = 0; j < eld.size(); ++j)       for (i = 0; i <= j; ++i) {         d[i + 1][j + 1] += d[i][j] * (i + 1.0) / (j + 1.0) * (u[eld[j]] + 1) /                            (l[eld[j]] ? l[eld[j]] : 1);         d[i][j + 1] += d[i][j] * (j - i + 1.0) / (j + 1.0);       }     cout << setprecision(10) << fixed << d[ll][eld.size()];     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   void out(T x) {     cout << x << endl;     exit(0);   }   const int maxn = 1e6 + 5;   int n, k;   int bsize;   set<int> alive[maxn];   int cnt;   char ask(int i) {     cnt++;     cout <<  ?   << i + 1 << endl;     cout.flush();     char res;     cin >> res;     if (res ==  E ) exit(0);     return res;   }   void reset() {     cout <<  R  << endl;     cout.flush();   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n >> k;     bsize = max(1, k / 2);     for (int i = 0; i < n; i++) {       alive[i / bsize].insert(i);     }     reset();     set<int> kill;     for (int i = 0; i < n; i++) {       if (ask(i) ==  Y ) {         kill.insert(i);       }     }     for (int x : kill) {       alive[x / bsize].erase(x);     }     for (int i = 0; i < n / bsize; i++) {       for (int j = i + 1; j < n / bsize; j++) {         if (alive[j].empty()) continue;         reset();         for (int x : alive[i]) {           assert(ask(x) ==  N );         }         set<int> kill;         for (int x : alive[j]) {           if (ask(x) ==  Y ) {             kill.insert(x);           }         }         for (int x : kill) {           alive[j].erase(x);         }       }     }     int ans = 0;     for (int i = 0; i < n / bsize; i++) {       ans += alive[i].size();     }     cout <<  !   << ans << endl;     cout.flush();     return 0;   }


#include<bits/stdc++.h>   #define ll long long   #define ri register int   #define lowbit(x) x&(-x)   #define lson rt<<1, l, mid   #define rson rt<<1|1, mid+1, r   using namespace std;   const int p = 1e9+7;   const int maxn = 4e5+10;   int n, m, t, q;   int a[maxn], vis[maxn], go[maxn], two;   int dp[maxn][30];   void divide(int x, int k){    int t = sqrt(x);    for(int i = 2;i <= t;i ++){     if(x%i == 0){      vis[i] += k;      if(vis[i] == 1 && k == -1) two --;      else if(vis[i] >= 2) two ++;      while(x%i == 0) x /= i;     }    }    if(x > 1){     vis[x] += k;     if(vis[x] == 1 && k == -1) two --;     else if(vis[x] >= 2) two ++;    }   }   int main(){    scanf( %d%d ,&n,&q);    for(int i = 1;i <= n;i ++)     scanf( %d ,&a[i]);    int l = 1, r = 0;    while(r < n){     r ++;     divide(a[r], 1);     if(two){      go[l] = r;      while(two){       divide(a[l], -1);       l ++;       go[l] = r;      }     }    }    for(int i = l;i <= n+1;i ++)     go[i] = n+1;    for(int i = 1;i <= n;i ++){     dp[i][0] = go[i];    }    for(int j = 1;j <= 20;j ++)     for(int i = 1;i <= n+1;i ++){      if(dp[dp[i][j-1]][j-1])       dp[i][j] = dp[dp[i][j-1]][j-1];      else dp[i][j] = n+1;     }    for(int i = 1;i <= q;i ++){     int l, r;     ll ans = 0;     scanf( %d%d ,&l,&r);     for(int j = 20;j >= 0;j --){      //cout << l <<     << j <<     << dp[l][j] << endl;      if(dp[l][j] <= r){       l = dp[l][j];       ans += 1ll<<j;      }     }     printf( %lld n ,ans+1);    }    return 0;   }


#include <bits/stdc++.h>   using namespace std;   int sqr(int v) { return v * v; }   int main() {     int x1, y1, x2, y2, r1, r2;     cin >> x1 >> y1 >> r1 >> x2 >> y2 >> r2;     if (r1 < r2) swap(x1, x2), swap(y1, y2), swap(r1, r2);     int t1 = sqr(x1 - x2) + sqr(y1 - y2);     long double ans(0);     if (t1 < sqr(r1 - r2))       ans = r1 - r2 - sqrt((long double)t1);     else if (t1 > sqr(r1 + r2))       ans = sqrt((long double)t1) - r1 - r2;     cout << fixed << setprecision(20) << ans / 2 << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 998244353;   int c[80][80], m;   struct tree {     int n, ans[80], f[80][5000], g[80][5000];     int root, sum, siz[5000], w[5000], a[5000], tot;     bool vis[5000];     vector<int> v[5000];     inline void getrt(int x, int fa) {       siz[x] = 1;       w[x] = 0;       for (int i = 0; i < v[x].size(); i++)         if (v[x][i] != fa && !vis[v[x][i]]) {           getrt(v[x][i], x);           siz[x] += siz[v[x][i]];           w[x] = max(w[x], siz[v[x][i]]);         }       w[x] = max(w[x], sum - siz[x]);       if (!root || w[x] < w[root]) root = x;     }     inline void dfs(int x, int fa) {       a[++tot] = x;       siz[x] = 1;       for (int i = 0; i < v[x].size(); i++)         if (v[x][i] != fa && !vis[v[x][i]]) {           dfs(v[x][i], x);           siz[x] += siz[v[x][i]];         }     }     inline void work(int x) {       tot = 0;       dfs(x, 0);       int i, j, k;       memset(f, 0, sizeof(f));       memset(g, 0, sizeof(g));       f[0][x] = g[0][x] = 1;       for (i = 1; i <= m; i++)         for (j = 1; j <= tot; j++) {           for (k = 0; k < v[a[j]].size(); k++) {             if (vis[v[a[j]][k]]) continue;             if (a[j] != x) f[i][a[j]] = (f[i][a[j]] + f[i - 1][v[a[j]][k]]) % mod;             g[i][a[j]] = (g[i][a[j]] + g[i - 1][v[a[j]][k]]) % mod;           }         }       for (i = 1; i <= tot; i++) {         if (a[i] == x) {           for (j = 0; j <= m; j++) ans[j] = (ans[j] + g[j][a[i]]) % mod;         } else {           for (j = 0; j <= m; j++)             for (k = 0; k + j <= m; k++)               ans[k + j] =                   (ans[k + j] + (long long)f[j][a[i]] * g[k][a[i]] % mod) % mod;         }       }       vis[x] = 1;       for (i = 0; i < v[x].size(); i++)         if (!vis[v[x][i]]) {           root = 0;           sum = siz[v[x][i]];           getrt(v[x][i], x);           work(root);         }     }     inline void solve() {       sum = n;       root = 0;       memset(vis, 0, sizeof(vis));       memset(ans, 0, sizeof(ans));       getrt(1, 0);       work(root);     }   };   tree t1, t2;   int main() {     int i, j, k;     scanf( %d%d%d , &t1.n, &t2.n, &m);     c[0][0] = 1;     for (i = 1; i <= m; i++) c[i][i] = c[i][0] = 1;     for (i = 1; i <= m; i++)       for (j = 1; j < i; j++) c[i][j] = (c[i - 1][j] + c[i - 1][j - 1]) % mod;     for (i = 0; i <= t1.n; i++) t1.v[i].clear();     for (i = 0; i <= t2.n; i++) t2.v[i].clear();     for (i = 1; i < t1.n; i++) {       int x, y;       scanf( %d%d , &x, &y);       t1.v[x].push_back(y);       t1.v[y].push_back(x);     }     for (i = 1; i < t2.n; i++) {       int x, y;       scanf( %d%d , &x, &y);       t2.v[x].push_back(y);       t2.v[y].push_back(x);     }     t1.solve(), t2.solve();     int Ans = 0;     for (i = 0; i <= m; i++)       Ans = (Ans + (long long)t1.ans[i] * t2.ans[m - i] % mod * c[m][i]) % mod;     cout << Ans;     return 0;   }


#include <bits/stdc++.h>   const int N = 400 + 10, MOD = 1000000007;   inline void add(int &lhs, long long rhs) { lhs = (lhs + rhs) % MOD; }   int n, f[N][N];   int main() {     scanf( %d , &n);     f[1][0] = f[1][1] = 1;     for (int i = 2; i <= n; ++i) {       for (int x = 0; x <= n; ++x) {         for (int y = 0; x + y <= n; ++y) {           int cur = (long long)f[i - 1][x] * f[i - 1][y] % MOD;           if (!cur) continue;           add(f[i][x + y], cur);           add(f[i][x + y + 1], cur);           if (x) add(f[i][x + y], 2LL * x * cur);           if (y) add(f[i][x + y], 2LL * y * cur);           if (x || y) add(f[i][x + y - 1], (x + y) * (x + y - 1LL) * cur);         }       }     }     printf( %d n , f[n][1]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long power(int base, long long p) {     long long res = 1;     while (p) {       if (p & 1) {         res *= base;         --p;       }       base *= base;       p /= 2;     }     return res;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       vector<int> vec;       for (int i = 0; i < (int)(n); ++i) {         int x;         cin >> x;         vec.push_back(x);       }       sort((vec).begin(), (vec).end());       int sz = unique((vec).begin(), (vec).end()) - vec.begin();       if (sz == n)         cout <<  No  <<   n ;       else         cout <<  Yes  <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 5000;   long long n, a, b, c, d;   pair<long long, long long> p[MAX];   bool cmp(pair<int, int> x, pair<int, int> y) {     if (x.first > y.first) return 1;     if (x.first == y.first) return x.second < y.second;     return 0;   }   int main() {     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a >> b >> c >> d;       long long sum = a + b + c + d;       p[i].first = sum;       p[i].second = i + 1;     }     sort(p, p + n, cmp);     for (int i = 0; i < n; i++)       if (p[i].second == 1) {         cout << i + 1 << endl;         break;       }     return 0;   }


#include <bits/stdc++.h>   template <class c>   int popc(c a) {     if (sizeof(c) == 8)       return __builtin_popcountll(a);     else       return __builtin_popcount(a);   }   template <class c>   int ctz(c a) {     if (sizeof(c) == 8)       return __builtin_ctzll(a);     else       return __builtin_ctz(a);   }   template <class c>   int clz(c a) {     if (sizeof(c) == 8)       return __builtin_clzll(a);     else       return __builtin_clz(a);   }   inline int min(const int &first, const int &second) {     return (((second - first) >> (32 - 1)) & (first ^ second)) ^ first;   }   inline int max(const int &first, const int &second) {     return (((second - first) >> (32 - 1)) & (first ^ second)) ^ second;   }   inline long long min(const long long &first, const long long &second) {     return (((second - first) >> (64 - 1)) & (first ^ second)) ^ first;   }   inline long long max(const long long &first, const long long &second) {     return (((second - first) >> (64 - 1)) & (first ^ second)) ^ second;   }   using namespace std;   char string_in_buffer[(int)260];   void fast_scan(int &first) { scanf( %d , &first); }   void fast_scan(long long &first) { scanf( %lld , &first); }   void fast_scan(unsigned long long &first) { scanf( %llu , &first); }   void fast_scan(double &first) { scanf( %lf , &first); }   void fast_scan(long double &first) { scanf( %Lf , &first); }   void fast_scan(char &first) {     scanf( %c , &first);     if (first ==   n ) {       fast_scan(first);     }   }   void fast_scan(string &first) {     scanf( %s , string_in_buffer);     first = string(string_in_buffer);   }   template <class TFirst, class TSecond>   void fast_scan(pair<TFirst, TSecond> &p) {     fast_scan(p.first);     fast_scan(p.second);   }   template <class T>   void fast_scan(vector<T> &v) {     for (auto &first : v) fast_scan(first);   }   void fast_print(const int &first) { printf( %d , first); }   void fast_print(const unsigned int &first) { printf( %u , first); }   void fast_print(const long long &first) { printf( %lld , first); }   void fast_print(const unsigned long long &first) { printf( %llu , first); }   void fast_print(const char &first) { printf( %c , first); };   void fast_print(const double &first) { printf( %.15lf , first); }   void fast_print(const long double &first) { printf( %.15Lf , first); }   void fast_print(const string &first) { printf( %s , first.c_str()); }   void fast_print(const char v[]) { fast_print((string)v); }   template <class TFirst, class TSecond>   void fast_print(const pair<TFirst, TSecond> &p) {     fast_print(p.first);     fast_print(   );     fast_print(p.second);   }   template <class T>   void fast_print(const vector<T> &v) {     if (v.empty()) return;     fast_print(v[0]);     for (int i = 1; i < v.size(); i++) {       fast_print(   );       fast_print(v[i]);     }   }   template <class T>   void fast_print(const vector<vector<T>> &v) {     if (v.empty()) return;     fast_print(v[0]);     for (int i = 1; i < v.size(); i++) {       fast_print(  n );       fast_print(v[i]);     }   }   template <class T>   void fast_print(const T &v) {     for (const auto &first : v) {       fast_print(first);       fast_print(   );     }   }   using namespace std;   namespace smart_io {   string print_start =   ;   string sep =    ;   bool first_print = false;   void precall_print() {     fast_print(print_start);     print_start =   n ;     first_print = true;   }   void _print(deque<string>) {}   template <class T, class... Args>   void _print(deque<string> names, T elem, Args... args) {     if (!first_print) {       fast_print(  n );     } else {       first_print = false;     }     fast_print(names.front());     fast_print(  =  );     fast_print(elem);     names.pop_front();     _print(names, args...);   }   }  // namespace smart_io   template <class T>   ostream &operator,(ostream &os, const T &object) {     if (!smart_io::first_print) {       fast_print(smart_io::sep);     } else {       smart_io::first_print = false;     }     fast_print(object);     return os;   }   template <class T>   istream &operator,(istream &is, T &object) {     fast_scan(object);     return is;   }   namespace escape__from__random__aetuhoetnuhshe {   using namespace std::chrono;   mt19937 rng(duration_cast<milliseconds>(system_clock::now().time_since_epoch())                   .count());   uniform_real_distribution<> prob_dist(0.0, 1.0);   };  // namespace escape__from__random__aetuhoetnuhshe   namespace typedefs {}   namespace numbers_operation {   template <class T>   inline T floor_mod(T a, const T &b) {     a %= b;     if (a < 0) a += b;     return a;   }   }  // namespace numbers_operation   using namespace numbers_operation;   using namespace typedefs;   using namespace escape__from__random__aetuhoetnuhshe;   long long n;   vector<long long> v;   void solve() {     cin, n;     v.clear();     v.resize(n);     cin, v;     long long _max = v[0];     long long rez = 0;     for (long long i = 0; i < n; i++) {       _max = max(_max, v[i]);       if (_max > v[i]) {         rez = max(rez, (long long)(64 - clz(_max - v[i])));       }     }     smart_io::precall_print();     cout, rez;   }   signed main(signed argc, char *argv[]) {     long long tests;     cin, tests;     for (long long test = 0; test < (tests); test++) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());   struct Event {     long long x, t, i;     Event() {}     Event(long long x, long long t, long long i) : x(x), t(t), i(i) {}   };   bool cmpEvents(const Event &a, const Event &b) {     return tie(a.x, a.t, a.i) < tie(b.x, b.t, b.i);   }   const long long MAX_N = 2e5 + 5;   long long n;   long long cnt[MAX_N];   pair<bool, bool> cover[MAX_N];   void solve() {     cin >> n;     vector<Event> sc;     for (long long i = 1; i <= n; ++i) {       cnt[i] = 0;       cover[i] = make_pair(false, false);       long long l, r;       cin >> l >> r;       l *= 2, r *= 2;       sc.emplace_back(l, -1, i);       sc.emplace_back(r, 1, i);     }     sort(sc.begin(), sc.end(), cmpEvents);     for (long long i = 1; i < 2 * n; ++i) {       sc.emplace_back((sc[i - 1].x + sc[i].x) / 2, 0, 0);     }     sort(sc.begin(), sc.end(), cmpEvents);     set<long long> alive;     long long start_ans = 2;     for (long long i = 0; i < (long long)sc.size();) {       long long j = i;       while (j < (long long)sc.size() && sc[i].x == sc[j].x && sc[j].t == -1) {         alive.emplace(sc[j].i);         ++j;       }       while (i < j) {         cover[sc[i].i].first = (long long)alive.size() > 1;         ++i;       }       while (j < (long long)sc.size() && sc[i].x == sc[j].x && sc[j].t == 0) {         if ((long long)alive.size() == 1) {           cnt[*alive.begin()]++;         }         ++j;       }       if (alive.empty()) {         start_ans++;       }       i = j;       while (j < (long long)sc.size() && sc[i].x == sc[j].x && sc[j].t == 1) {         cover[sc[j].i].second = (long long)alive.size() > 1;         ++j;       }       while (i < j) {         alive.erase(sc[i].i);         ++i;       }     }     long long ans = 0;     for (long long i = 1; i <= n; ++i) {       ans = max(ans, start_ans + cnt[i] - !cover[i].first - !cover[i].second - 1);     }     cout << ans <<   n ;   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     long long T;     cin >> T;     while (T--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, in[100010], sum1, sum2;   int main() {     cin >> n >> m;     for (int i = 1; i <= m; i++) {       int x, y;       cin >> x >> y;       in[x]++;       in[y]++;     }     for (int i = 1; i <= n + 1; i++)       if (in[i] == 1)         sum1++;       else if (in[i] == 2)         sum2++;     if (sum1 == 2 && sum2 == n - 2) {       cout <<  bus topology ;       return 0;     }     sum1 = sum2 = 0;     for (int i = 1; i <= n; i++)       if (in[i] == 2) sum1++;     if (sum1 == n) {       cout <<  ring topology ;       return 0;     }     sum1 = sum2 = 0;     for (int i = 1; i <= n + 1; i++)       if (in[i] == 1)         sum1++;       else if (in[i] == n - 1)         sum2++;     if (sum1 == n - 1 && sum2 == 1) {       cout <<  star topology ;       return 0;     }     cout <<  unknown topology ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     long long n, m, k, t;     cin >> n >> m >> k >> t;     pair<int, int> mp[k + 1];     long long x, y, a, b;     for (int i = 0; i < k; i++) {       cin >> mp[i].first >> mp[i].second;     }     sort(mp, mp + k);     for (int i = 0; i < t; i++) {       cin >> x >> y;       long long idx = m * (x - 1) + y;       bool f = true;       for (int i = 0; i < k; i++) {         if (mp[i].first > x || (mp[i].first == x && mp[i].second > y)) {           idx -= (i + 1);           break;         }         if (mp[i].first == x && mp[i].second == y) {           f = false;           cout <<  Waste  << endl;           break;         }         if (i == k - 1) idx = idx - k - 1;       }       if (idx % 3 == 0 && f)         cout <<  Carrots  << endl;       else if (idx % 3 == 1 && f)         cout <<  Kiwis  << endl;       else if (idx % 3 == 2 && f)         cout <<  Grapes  << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 100 + 10;   const int INF = int(1e9);   int main() {     int n;     char str1[maxn], str2[maxn];     while (~scanf( %d , &n)) {       scanf( %s %s , str1, str2);       int h, m;       h = (str1[0] -  0 ) * 10 + str1[1] -  0 ;       m = (str2[0] -  0 ) * 10 + str2[1] -  0 ;       int ans = 0;       while (h % 10 != 7 && m % 10 != 7) {         if (m - n < 0) {           m = m - n + 60;           if (h == 0)             h = 23;           else             h--;         } else           m = m - n;         ans++;       }       printf( %d n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = 9e18;   const int inf = 2147483647;   long long qpow(long long a, long long b, long long mod) {     long long r = 1;     for (; b; b >>= 1) {       if (b & 1) r = (r * a) % mod;       a = (a * a) % mod;     }     return r;   }   const int N = 1e5 + 5;   void work() {     int t;     scanf( %d , &t);     while (t--) {       int r, g, b, w;       scanf( %d%d , &r, &g);       scanf( %d%d , &b, &w);       int sum = 0;       if (r % 2) sum++;       if (g % 2) sum++;       if (b % 2) sum++;       if (sum == 0)         puts( YES );       else if (sum == 1) {         puts(w % 2 == 0 ?  YES  :  NO );       } else if (sum == 2) {         if (r && g && b)           puts(w % 2 ?  YES  :  NO );         else           puts( NO );       } else {         puts( YES );       }     }   }   int main() {     work();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a[1000], b, c, d;     cin >> b >> c >> d;     a[0] = b;     a[1] = c;     for (int i = 2; i <= d; i++) {       a[i] = a[i - 1] + a[i - 2];     }     cout << a[d];   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int a[n], i, j, k1 = 0, k2 = 0;     for (i = 0; i < n; i++) {       cin >> a[i];       if (a[i] == 1)         k1++;       else         k2++;     }     int k3 = 0, k4 = 0;     for (i = 0; i < n; i++) {       if (a[i] == 1)         k3++;       else         k4++;       if (k3 >= k1 || k4 >= k2) {         j = i;         break;       }     }     cout << j + 1;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   struct Node {     long long x, y;   } Edge[300005];   long long pre[300005];   bool cmp(Node a, Node b) { return a.y > b.y; }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) {       scanf( %lld%lld , &Edge[i].x, &Edge[i].y);     }     sort(Edge + 1, Edge + n + 1, cmp);     priority_queue<int, vector<int>, greater<int>> q;     long long ans = 0;     for (int i = 1; i <= n; i++) {       if (q.size() < m) {         q.push(Edge[i].x);         pre[i] = pre[i - 1] + Edge[i].x;         ans = max(ans, Edge[i].y * pre[i]);       } else {         if (Edge[i].x <= q.top()) {           pre[i] = pre[i - 1];         } else {           pre[i] = pre[i - 1] - q.top() + Edge[i].x;           q.pop();           q.push(Edge[i].x);           ans = max(ans, Edge[i].y * pre[i]);         }       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char x, y, t;   struct node {     char c;     int p;   } ans[4];   inline bool cmp(const node &a, const node &b) { return a.p < b.p; }   int main() {     for (register int i = 1; i <= 3; i++) {       ans[i].c =  A  + i - 1;       cin >> x >> t >> y;       if (t ==  > ) swap(x, y);       ans[x -  A  + 1].p++;       ans[y -  A  + 1].p += 2;     }     sort(ans + 1, ans + 4, cmp);     if (ans[1].p == ans[2].p || ans[2].p == ans[3].p) {       cout <<  Impossible ;       return 0;     }     cout << ans[1].c << ans[2].c << ans[3].c;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MX = 1e6 + 5;   long long ans[MX];   long long upd[MX];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int n, w;     cin >> n >> w;     vector<int> a[n];     int mx[n];     for (int i = 0; i < n; i++) {       int l;       cin >> l;       a[i] = vector<int>(l);       mx[i] = -1000000000;       for (int j = 0; j < l; j++) {         cin >> a[i][j];         mx[i] = max(mx[i], a[i][j]);       }     }     memset(ans, 0, sizeof(ans));     for (int i = 0; i < n; i++) {       if (w >= 2 * a[i].size() + 1) {         int currmx = 0;         for (int j = 0; j < a[i].size(); j++) {           currmx = max(currmx, a[i][j]);           ans[j + 1] += currmx;         }         currmx = 0;         for (int j = a[i].size() - 1; j >= 0; j--) {           currmx = max(currmx, a[i][j]);           ans[w - ((a[i].size() - 1) - j)] += currmx;         }         upd[a[i].size()] -= max(mx[i], 0);         upd[w - a[i].size()] += max(mx[i], 0);       } else {         deque<int> q;         int idx = 0;         bool zero = false;         for (int j = 1; j <= w; j++) {           if (idx < a[i].size()) {             while (!q.empty() && a[i][q.back()] <= a[i][idx]) {               q.pop_back();             }             q.push_back(idx++);           }           zero = (a[i].size() <= (j - 1)) || (a[i].size() <= (w - j));           if (zero)             ans[j] += max(a[i][q.front()], 0);           else             ans[j] += a[i][q.front()];           if (((a[i].size() - q.front()) + j) >= w + 1) {             q.pop_front();           }         }       }     }     for (int i = w; i >= 1; i--) {       upd[i] += upd[i + 1];     }     for (int i = 1; i <= w; i++) cout << ans[i] + upd[i] <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     string a;     string b;     cin >> a >> b;     int order = 0;     while (a[order] ==  0 ) {       order++;     }     a.erase(0, order);     order = 0;     while (b[order] ==  0 ) {       order++;     }     b.erase(0, order);     if (a.size() > b.size()) {       cout <<  > ;     } else if (a.size() < b.size()) {       cout <<  < ;     } else {       for (int i = 0; i < a.size(); i++) {         if (a[i] > b[i]) {           cout <<  > ;           return 0;         } else if (a[i] < b[i]) {           cout <<  < ;           return 0;         }       }       cout <<  = ;     }   }


#include <bits/stdc++.h>   using i8 = std::int8_t;   using i16 = std::int16_t;   using i32 = std::int32_t;   using i64 = std::int64_t;   using u8 = std::uint8_t;   using u16 = std::uint16_t;   using u32 = std::uint32_t;   using u64 = std::uint64_t;   auto SolveTest() -> void {     int n;     std::cin >> n;     std::vector<int> a(n);     for (auto &elem : a) {       std::cin >> elem;     }     std::set<int> numbers(std::begin(a), std::end(a));     for (auto it = std::begin(numbers); std::next(it) != std::end(numbers);          ++it) {       if (std::abs(*it - *std::next(it)) > 1) {         std::cout <<  NO n ;         return;       }     }     std::cout <<  YES n ;   }   int main() {     std::ios_base::sync_with_stdio(false);     std::cin.tie(nullptr);     std::cout.tie(nullptr);     i32 test_count;     std::cin >> test_count;     for (i32 t = 0; t < test_count; ++t) {       SolveTest();     }   }


#include <bits/stdc++.h>   using namespace std;   int n;   unordered_map<int, int> mask, f;   int SG(int s) {     if (f.count(s)) return f[s];     bool t[30] = {0};     for (int i = 0; s >> i; i++) {       t[SG(s >> (i + 1) | (s & ((1 << i) - 1)))] = 1;     }     for (int i = 0; i < 30; i++)       if (!t[i]) return f[s] = i;     return 30;   }   int main() {     scanf( %d , &n);     for (int i = 1, x; i <= n; i++) {       scanf( %d , &x);       for (int d = 2; d * d <= x; d++)         if (x % d == 0) {           int c = 0;           while (x % d == 0) x /= d, c++;           mask[d] |= 1 << (c - 1);         }       if (x > 1) mask[x] |= 1;     }     int ans = 0;     for (auto s : mask) ans ^= SG(s.second);     puts(ans ?  Mojtaba  :  Arpa );     return 0;   }


//Author: AnandRaj uux   #include <bits/stdc++.h>   using namespace std;      typedef long long ll;   typedef long double ld;   typedef pair<int,int> pii;   typedef vector<int> vi;   typedef vector<vi> vvi;   typedef vector<pii> vpii;   typedef pair<ll,ll> pll;   typedef vector<ll> vl;   typedef vector<vl> vvl;   typedef vector<pll> vpll;       #define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);   #define test() int t;cin>>t;while(t--)   #define all(v) v.begin(),v.end()   #define prinp(p) cout<<p.first<<   <<p.second<<endl   #define prinv(V) for(auto v:V) cout<<v<<   ;cout<<endl   #define take(V,f,n) for(int in=f;in<f+n;in++) cin>>V[in]   #define what(x) cerr<<#x<<  =  <<x<<endl   #define KStest() int t,t1;cin>>t;t1=t;while(t--)   #define KScout cout<< Case # <<t1-t<< :     mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   const int MOD = 1e9+7,MAX = 1e6+5;   const ll INF = 1e18+5;      vvi A;   bool can = true;   vi TS;   vi vis,inStack;   void dfs(int x, int parent)    {       vis[x] = true;       inStack[x] = true;       for(auto v:A[x])        {           if (vis[v] && inStack[v])            {               can = false;               return;           }           if(!vis[v])            {               dfs(v, x);           }       }       inStack[x] = false;       TS.push_back(x);   }      int main()   {    int n,m,k;    cin>>n>>m>>k;    A.resize(n+1);    vector<string> P(n+1);    map<string,int> Sp;    take(P,1,n);    for(int i=1;i<=n;i++) Sp[P[i]] = i;        vis.resize(n+1);    inStack.resize(n+1);       vector<int> MT(m+1);    vector<string> S(m+1);       for(int i=1;i<=m;i++)    {     cin>>S[i]>>MT[i];     set<string> X;     X.insert(  );     for(int j=0;j<k;j++)     {      set<string> XX;      for(auto x:X)      {       XX.insert(x+ _ );       XX.insert(x+S[i][j]);      }      X = XX;     }     if(X.count(P[MT[i]])==0) {can = false;break;}     for(auto x:X)     {      if(Sp.find(x)==Sp.end() || Sp[x]==MT[i]) continue;      else      {       A[MT[i]].push_back(Sp[x]);      }     }    }    // for(int i=1;i<=n;i++)    // {    //  prinv(A[i]);    // }    for(int i=1;i<=n;i++)    {     if(!vis[i]) dfs(i,-1);    }    if(can)    {     cout<< YES <<endl;     reverse(all(TS));     prinv(TS);    }    else cout<< NO <<endl;         }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 5;   inline long long rd() {     long long x = 0;     char c = getchar();     int neg = 1;     while (c <  0  || c >  9 ) {       if (c ==  - ) neg = -1;       c = getchar();     }     while (c >=  0  && c <=  9 ) x = x * 10 + c -  0 , c = getchar();     return x * neg;   }   pair<int, int> p[maxn];   int main() {     int i, j, k;     for (i = 1; i <= 3; i++) p[i].first = rd(), p[i].second = rd();     sort(p + 1, p + 4);     if (p[1].second <= p[2].second && p[1].second <= p[3].second) {       if (p[2].second <= p[3].second) {         int ans = p[2].second - p[1].second + p[3].first - p[1].first +                   p[3].second - p[2].second + 1;         printf( %d n , ans);         for (i = p[1].second; i <= p[2].second; i++)           printf( %d %d n , p[1].first, i);         for (i = p[1].first + 1; i <= p[3].first; i++)           printf( %d %d n , i, p[2].second);         for (i = p[2].second + 1; i <= p[3].second; i++)           printf( %d %d n , p[3].first, i);       } else {         int ans = p[3].second - p[1].second + p[3].first - p[1].first +                   p[2].second - p[3].second + 1;         printf( %d n , ans);         for (i = p[1].second; i <= p[3].second; i++)           printf( %d %d n , p[1].first, i);         for (i = p[1].first + 1; i <= p[3].first; i++)           printf( %d %d n , i, p[3].second);         for (i = p[3].second + 1; i <= p[2].second; i++)           printf( %d %d n , p[2].first, i);       }     } else if (p[1].second <= p[2].second && p[1].second > p[3].second) {       int ans = p[1].second - p[3].second + p[3].first - p[1].first +                 p[2].second - p[1].second + 1;       printf( %d n , ans);       for (i = p[3].second; i <= p[1].second; i++)         printf( %d %d n , p[3].first, i);       for (i = p[1].first; i <= p[3].first - 1; i++)         printf( %d %d n , i, p[1].second);       for (i = p[1].second + 1; i <= p[2].second; i++)         printf( %d %d n , p[2].first, i);     } else if (p[1].second > p[2].second && p[1].second <= p[3].second) {       int ans = p[3].second - p[1].second + p[3].first - p[1].first +                 p[1].second - p[2].second + 1;       printf( %d n , ans);       for (i = p[1].second; i <= p[3].second; i++)         printf( %d %d n , p[3].first, i);       for (i = p[1].first; i <= p[3].first - 1; i++)         printf( %d %d n , i, p[1].second);       for (i = p[2].second; i <= p[1].second - 1; i++)         printf( %d %d n , p[2].first, i);     } else if (p[1].second > p[2].second && p[1].second > p[3].second) {       if (p[2].second <= p[3].second) {         int ans = p[1].second - p[2].second + p[2].first - p[1].first +                   p[3].first - p[2].first + 1;         printf( %d n , ans);         for (i = p[1].first; i <= p[3].first; i++)           printf( %d %d n , i, p[3].second);         for (i = p[2].second; i <= p[3].second - 1; i++)           printf( %d %d n , p[2].first, i);         for (i = p[3].second + 1; i <= p[1].second; i++)           printf( %d %d n , p[1].first, i);       } else {         int ans = p[3].first - p[1].first + p[1].second - p[3].second + 1;         printf( %d n , ans);         for (i = p[2].second; i <= p[1].second; i++)           printf( %d %d n , p[1].first, i);         for (i = p[1].first + 1; i <= p[3].first; i++)           printf( %d %d n , i, p[2].second);         for (i = p[3].second; i <= p[2].second - 1; i++)           printf( %d %d n , p[3].first, i);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 405;   int n, kk;   vector<pair<int, int>> v[N][N], e[N];   int dp[N][N], sz[N], f[N];   void dfs1(int pos, int fa) {     sz[pos] = 1;     for (auto &i : e[pos])       if (i.first != fa) {         dfs1(i.first, pos);         sz[pos] += sz[i.first];         f[i.first] = i.second;       }   }   void dfs2(int pos, int fa) {     if (pos == 1)       dp[pos][sz[pos]] = 0;     else       dp[pos][sz[pos]] = 1;     dp[pos][0] = 0;     for (auto &i : e[pos]) {       if (i.first == fa) continue;       dfs2(i.first, pos);       for (int j = sz[pos] - 1; j > 0; --j) {         int tk = -1;         for (int k = 0; k <= sz[i.first] && k <= j; k++)           if (dp[pos][j] > dp[i.first][k] + dp[pos][j - k]) {             dp[pos][j] = dp[i.first][k] + dp[pos][j - k], tk = k;             v[pos][j] = v[pos][j - tk], v[pos][j].push_back({i.first, tk});           }         if (tk != -1)           v[pos][j] = v[pos][j - tk], v[pos][j].push_back({i.first, tk});       }     }   }   void print_ans(int pos, int cnt) {     if (sz[pos] == cnt) {       cout << f[pos] <<    ;       return;     }     for (auto &i : v[pos][cnt]) print_ans(i.first, i.second);   }   int main() {     ios::sync_with_stdio(false);     cin >> n >> kk;     cin.tie(0);     for (int i = 1; i < n; i++) {       int t1, t2;       cin >> t1 >> t2;       e[t1].push_back({t2, i});       e[t2].push_back({t1, i});     }     memset(dp, 63, sizeof(dp));     dfs1(1, 0);     dfs2(1, 0);     int ans = dp[1][n - kk], pos = 1;     for (int i = 2; i <= n; i++)       if (sz[i] >= kk && ans > dp[i][sz[i] - kk] + 1)         ans = dp[i][sz[i] - kk] + 1, pos = i;     cout << ans << endl;     if (pos != 1) cout << f[pos] << endl;     print_ans(pos, sz[pos] - kk);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int c3[100010], c2[1010];   int graph[110][110];   int main() {     ios ::sync_with_stdio(0);     cin.tie(0);     memset(graph, 0, sizeof graph);     for (int i = (3), _b = (100); i <= _b; ++i) {       c3[i] = (i * (i - 1) * (i - 2)) / 6;     }     for (int i = (2), _b = (100); i <= _b; ++i) {       c2[i] = (i * (i - 1)) / 2;     }     int k, esco;     cin >> k;     for (int i = (100), _b = (3); i >= _b; --i) {       if (k >= c3[i]) {         k -= c3[i];         esco = i;         break;       }     }     for (int i = 0; i < (int)(esco); ++i) {       for (int j = 0; j < (int)(esco); ++j) {         if (i != j) graph[i][j] = graph[j][i] = 1;       }     }     int fixo = esco;     while (k > 0) {       int cont = 0;       for (int i = (fixo), _b = (2); i >= _b; --i) {         cont = i;         if (k >= c2[i]) break;       }       for (int i = 0; i < (int)(cont); ++i) graph[i][esco] = graph[esco][i] = 1;       k -= c2[cont];       esco++;     }     cout << esco << endl;     for (int i = 0; i < (int)(esco); ++i) {       for (int j = 0; j < (int)(esco); ++j) {         cout << graph[i][j] <<   ;       }       cout << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     cout << fixed;     cout << setprecision(10);     int row, column;     char temp;     cin >> row >> column;     for (int i = 0; i < int(row - 1); ++i) {       for (int j = 0; j < int(column); ++j) {         cin >> temp;       }     }     string s;     cin >> s;     int s1 = 0;     for (int i = 0; i < int(column); ++i) {       if (s[i] ==  B ) {         s1++;         while (s[i] ==  B ) i++;       }     }     cout << s1;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 100;   int test[maxn];   int main() {     int n, num(0), x;     cin >> n;     char ch;     int l = 2e5;     int r = l + 1;     int mi, ma;     for (int i = 0; i < n; i++) {       cin >> ch >> x;       if (ch ==  L ) {         test[x] = l;         num++;         l--;         mi = test[x];       } else if (ch ==  R ) {         test[x] = r;         num++;         r++;         ma = test[x];       } else if (ch ==  ? ) {         int temp = test[x];         int ans = min(temp - mi, r - 1 - temp);         cout << ans << endl;       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 2;   int len, ans = 0, maxdis[N];   vector<int> adj[N], cur;   void dfs(int x, int p) {     if (adj[x].size() == 1) {       maxdis[x] = 0;       return;     }     int i, idxmin1;     for (i = 0; i < adj[x].size(); i++) {       if (adj[x][i] != p) {         dfs(adj[x][i], x);       }     }     cur.clear();     for (i = 0; i < adj[x].size(); i++) {       if (adj[x][i] != p) {         cur.push_back(maxdis[adj[x][i]] + 1);       }     }     sort(cur.begin(), cur.end());     for (i = 0; i < cur.size() - 1; i++) {       if (cur[i] + cur[i + 1] > len) {         break;       }     }     ans += cur.size() - 1 - i;     maxdis[x] = cur[i];   }   int main() {     ios::sync_with_stdio(0);     int n, i, j, k, l = 0;     cin >> n >> len;     for (i = 1; i < n; i++) {       cin >> j >> k;       adj[j].push_back(k);       adj[k].push_back(j);     }     for (i = 1; i <= n; i++) {       if (adj[i].size() > 1) {         l = i;         break;       }     }     dfs(l, l);     cout << ans + 1;   }


#include <bits/stdc++.h>      using namespace std;      struct node {       int u , v , w;       node(){}       node(int u,int v,int w):       u(u) , v(v) , w(w){};       bool operator < (const node &o) const {           return w < o.w;       }   };      struct dsu {       int par[200010];       void init() {           for (int i = 1 ; i <= 200000 ; ++i) par[i] = i;       }       int fin(int u) {           if (u != par[u]) par[u] = fin(par[u]);           return par[u];       }       bool join(int u , int v) {           u = fin(u);           v = fin(v);           if (u == v) return false;           if (par[u] > par[v]) swap(u , v);           par[u] = v;           return true;       }   } a , b;      set < int > vertex;   vector < int > g[200010];   vector < node > edge;   long long rest;      void DFS(int u) {       vertex.erase(u);       sort(g[u].begin(),g[u].end());       int v = 0;       while (1) {           auto it = vertex.lower_bound(v);           if (it == vertex.end()) return;           v = *it;           if (!binary_search(g[u].begin(),g[u].end(),v)) {               a.join(u , v);               DFS(v);               rest--;           }           v++;       }   }      int main() {       ios::sync_with_stdio(0);       cin.tie(0);cout.tie(0);       long long n , m;       int x = 0;       cin >> n >> m;       rest = n * (n - 1) / 2 - m;       for (int i = 1 ; i <= m ; ++i) {           int u , v , w;           cin >> u >> v >> w;           x ^= w;           g[u].push_back(v);           g[v].push_back(u);           edge.emplace_back(u , v , w);       }       a.init();b.init();       for (int i = 1 ; i <= n ; ++i)           vertex.insert(i);       for (int i = 1 ; i <= n ; ++i)           if (vertex.count(i)) DFS(i);       if (rest > 0) x = 0;       int res = 0;       sort(edge.begin(),edge.end());       for (auto p : edge) {           int u = p.u , v = p.v , w = p.w;           if (a.join(u , v)) {               res += w;               b.join(u , v);           } else if (b.join(u , v)) x = min(x , w);       }       cout << res + x;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 5;   int a[N];   vector<int> v;   int main() {     int n, s;     scanf( %d%d , &n, &s);     int ans = 0;     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     if (a[s] != 0) ans++;     for (int i = 1; i <= n; i++)       if (i == s)         continue;       else         v.push_back(a[i]);     v.push_back(0);     sort(v.begin(), v.end());     int cnt = 0;     int idx = 0;     while (v[idx] == 0 && idx < n) cnt++, idx++;     ans += cnt;     cnt--;     ans--;     int last = n - 1;     for (int i = idx; i <= last; i++) {       if (i == 0) continue;       if (v[i] == v[i - 1]) continue;       if (v[i - 1] == v[i] - 1) continue;       int diff = v[i] - v[i - 1] - 1;       if (diff <= cnt) {         cnt -= diff;         continue;       }       diff -= cnt;       cnt = 0;       while (diff--) {         if (last >= i) {           last--;           ans++;           continue;         }         if (last <= i) break;       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int base = 998244353;   int sum(int a, int b) {     int c = a + b;     if (c >= base) return c - base;     return c;   }   int diff(int a, int b) {     int c = a - b;     if (c < 0) return c + base;     return c;   }   int mul(int a, int b) { return (int)(a * (long long)b % base); }   int pow(int a, int b) {     if (!b) return 1;     if (b == 1) return a;     int d = pow(mul(a, a), b / 2);     if (b % 2) return mul(d, a);     return d;   }   int divis(int a, int b) { return mul(a, pow(b, base - 2)); }   struct segment_tree {    public:     segment_tree() : ts(0) {}     explicit segment_tree(vector<int> &p) : ts(1) {       size_t n = p.size();       while (ts < n) {         ts <<= 1u;       }       st.resize(2 * ts);       for (int i = ts; i < ts + n; ++i) {         st[i] = p[i - ts];       }       for (int i = (int)ts - 1; i; --i) {         st[i] = mul(st[i * 2], st[2 * i + 1]);       }     }     int get_mul(int l, int r) {       l += ts;       r += (int)ts - 1;       int res = 1;       while (l <= r) {         if (l % 2) {           res = mul(res, st[l++]);         }         if (r % 2 == 0) {           res = mul(res, st[r--]);         }         l /= 2;         r /= 2;       }       return res;     }       private:     size_t ts;     vector<int> st;   };   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n, q;     cin >> n >> q;     vector<int> p(n);     for (auto &x : p) {       cin >> x;     }     segment_tree st(p);     vector<int> deg100(n + 1), pref(n + 1);     deg100[0] = pref[0] = 1;     for (int i = 1; i <= n; ++i) {       deg100[i] = mul(100, deg100[i - 1]);     }     for (int i = 1; i <= n; ++i) {       pref[i] = mul(pref[i - 1], p[i - 1]);     }     vector<int> dot_product(n);     dot_product[0] = 100;     for (int i = 1; i < n; ++i) {       dot_product[i] = mul(100, sum(dot_product[i - 1], pref[i]));     }     int ans = divis(dot_product.back(), pref[n]);     set<pair<int, int>> ind = {{0, ans}, {n, 0}};     function<int(int, int)> func = [&](int l, int r) {       if (r - l == 1) {         return 100;       }       int res = dot_product[r - 1];       int a = 0;       if (l) {         a = mul(deg100[r - l], dot_product[l - 1]);       }       res = diff(res, a);       return divis(res, pref[l]);     };     while (q--) {       int i;       cin >> i;       --i;       auto v = ind.lower_bound({i, 0});       if (v->first != i) {         int r = v->first;         --v;         int l = v->first;         ans = diff(ans, v->second);         int fst = divis(func(l, i), st.get_mul(l, i));         int snd = divis(func(i, r), st.get_mul(i, r));         ind.insert({v->first, fst});         ind.erase(v);         ind.insert({i, snd});         ans = sum(ans, fst);         ans = sum(ans, snd);       } else {         auto u = prev(v);         ans = diff(ans, v->second);         ans = diff(ans, u->second);         ind.erase(v);         int l = u->first, r = next(u)->first;         int val = divis(func(l, r), st.get_mul(l, r));         ans = sum(ans, val);         ind.insert({u->first, val});         ind.erase(u);       }       cout << ans <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, p;     long long int cost;     bool na;     string line;     vector<int> a, b;     pair<int, int> t;     priority_queue<pair<int, int> > q;     getline(cin, line);     n = line.length();     a.resize(n);     b.resize(n);     m = 0;     for (int i = 0; i < n; i++) {       if (line[i] ==  ? ) {         cin >> a[i] >> b[i];         ++m;       }     }     p = 0;     cost = 0LL;     if (n & 1) {       na = true;     } else {       na = false;       for (int i = 0; i < n; i++) {         if (line[i] ==  ( ) {           ++p;         } else if (line[i] ==  ) ) {           --p;         } else {           --p;           q.push(make_pair(b[i] - a[i], i));           line[i] =  ) ;           cost += b[i];         }         if (p < 0) {           if (q.empty()) {             na = true;             break;           }           t = q.top();           q.pop();           cost -= t.first;           line[t.second] =  ( ;           p += 2;         }       }       if (p) {         na = true;       }     }     if (na) {       cout <<  -1  << endl;     } else {       cout << cost << endl;       cout << line << endl;     }     return 0;   }


#include<cstdio>   #include<iostream>   #include<queue>   #include<algorithm>   #include<cstring>   #include<set>   #include<vector>   #include<cmath>   #define PII pair<int,int>   #define pb push_back   #define ep emplace_back   #define mp make_pair   #define fi first   #define se second   using namespace std;   inline int read(){    int x=0,f=1;char c=getchar();    while(c< 0 ||c> 9 ){ if(c== - ) f=-1; c=getchar();}    while(c>= 0 &&c<= 9 ){x=(x<<3)+(x<<1)+(c^48);c=getchar();}    return f==1?x:~x+1;   }   inline void print(int x){    if(x<0) putchar( - ),x=~x+1;    if(x>=10) print(x/10);    putchar((x%10)|48);   }   int n;   int a[100010];   char str[10];   bool add,fminus,times;   char ans[100010];   const int mxn=131072;   void solve(int l,int r){    if(l>r) return ;    int sum=1;    int cnt=0;    vector<int>pos;    pos.pb(l-1);    for(int i=l;i<=r;++i){     if(sum<=mxn) sum*=a[i];     if(a[i]>1){      ++cnt;      pos.pb(i);     }    }    ++cnt;pos.pb(r+1);    if(sum>mxn){     for(int i=l;i<r;++i) ans[i]= + ;     for(int i=pos[1];i<pos[cnt-1];++i) ans[i]= * ;      return ;    }    vector<int>dp(cnt+1),pre(cnt+1);dp[0]=0;    for(int i=0;i<cnt;++i){     int s=dp[i]+pos[i+1]-pos[i]-1,t=1;     for(int j=i+1;j<=cnt;++j){      t=t*a[pos[j]];      int r=s+t;      if(r>dp[j]){       pre[j]=i;dp[j]=r;      }     }    }    int ps=cnt;    while(ps){     int t=ps;     ps=pre[ps];     for(int i=max(l,pos[ps]);i<pos[ps+1];++i) ans[i]= + ;     for(int i=pos[ps+1];i<pos[t];++i) ans[i]= * ;    }   }    int main(){    n=read();    for(int i=1;i<=n;++i) a[i]=read();    scanf( %s ,str+1);    for(int i=1;i<=strlen(str+1);++i){     switch(str[i]){      case  + :{add=1; break;}      case  - :fminus=1;break ;      case  * :times=1;break ;     }    }    if(!times){     if(add) for(int i=1;i<n;++i) printf( %d+ ,a[i]);     else for(int i=1;i<n;++i) printf( %d- ,a[i]);printf( %d n ,a[n]);     return 0;    }    if(!add){     if(fminus){      int p=n+1;      for(int i=1;i<=n;++i) if(a[i]==0){p=i;break ;}      if(p==n+1){        for(int i=1;i<n;++i) printf( %d* ,a[i]);printf( %d n ,a[n]);       return 0;      }      for(int i=1;i<p-1;++i) printf( %d* ,a[i]);      if(p!=1) printf( %d- ,a[p-1]);      for(int i=p;i<n;++i) printf( %d* ,a[i]);printf( %d n ,a[n]);     }     else{   //   if(n==67878) printf( 43423423 n );      for(int i=1;i<n;++i) printf( %d* ,a[i]);printf( %d n ,a[n]);     }     return 0;    }    int l=1,r=l;    while(l<=n){     while(a[r]!=0) ++r;     ans[r-1]= + ,ans[r]= + ;     solve(l,r-1);l=r+1;r=l;    }    for(int i=1;i<n;++i) printf( %d%c ,a[i],ans[i]);printf( %d n ,a[n]);    return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int singles, doubles, n;     cin >> n >> singles >> doubles;     int refused = 0, partlyOccDoubles = 0;     for (int i = 0; i < n; i++) {       int cur;       cin >> cur;       if (cur == 1) {         if (singles > 0) {           singles--;         } else if (doubles > 0) {           doubles--;           partlyOccDoubles++;         } else if (partlyOccDoubles > 0) {           partlyOccDoubles--;         } else {           refused += cur;         }       } else {         if (doubles == 0)           refused += cur;         else           doubles--;       }     }     cout << refused;     return 0;   }