#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline T abs(T zz) {     return zz < 0 ? -zz : zz;   }   template <typename T>   inline T sqr(T zz) {     return zz * zz;   }   const int MAGIC = 1000500;   vector<int> used;   vector<int> primes;   bool is_prime(int n) {     for (int p : primes) {       if (p * p > n) break;       if (n % p == 0) return false;     }     return true;   }   int main() {     used = vector<int>(MAGIC, 0);     for (int i = 2; i < MAGIC; ++i) {       if (!used[i]) {         primes.push_back(i);         for (int j = i; j < MAGIC; j += i) {           used[j] = true;         }       }     }     int n;     cin >> n;     if (is_prime(n) == 1) {       cout << 1 << endl;       return 0;     }     if (n % 2 == 0) {       cout << 2 << endl;       return 0;     }     if (is_prime(n - 2)) {       cout << 2 << endl;       return 0;     }     cout << 3 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int ans = 0, n;     string s;     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> s;       int flag = 0;       for (int i = 0; i < s.length(); i++)         if (s[i] ==  + ) flag = 1;       if (flag)         ans += 1;       else         ans -= 1;     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   double R, r;   struct Punct {     double x, y;   };   Punct A, B;   inline double Dist(Punct A, Punct B) {     return sqrt((A.x - B.x) * (A.x - B.x) + (A.y - B.y) * (A.y - B.y));   }   int main() {     double d;     cin >> A.x >> A.y >> R;     cin >> B.x >> B.y >> r;     d = Dist(A, B);     if (R >= r) {       if (d + r <= R) {         d = R - d - r;         d /= 2.0;       } else {         if (d <= R + r)           d = 0.0;         else {           d = d - R - r;           d /= 2.0;         }       }     } else {       if (d + R <= r) {         d = r - d - R;         d /= 2.0;       } else {         if (d <= R + r)           d = 0.0;         else {           d = d - R - r;           d /= 2.0;         }       }     }     printf( %.6lf n , d);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void smain();   int main() {     ios_base::sync_with_stdio(0);     cout.precision(12);     cout << fixed;     smain();     return 0;   }   int n;   int ans[1000001];   int f[1000001];   inline int sum(int r) {     int result = 0;     for (; r >= 0; r = (r & (r + 1)) - 1) result += f[r];     return result;   }   inline void inc(int i, int delta) {     for (; i < n; i = (i | (i + 1))) f[i] += delta;   }   void solve(vector<pair<int, pair<int, int> > > &q) {     vector<int> ts;     ts.reserve(q.size());     for (auto it : q) ts.push_back(it.first);     sort(ts.begin(), ts.end());     ts.resize(unique(ts.begin(), ts.end()) - ts.begin());     int m = ts.size();     memset(f, 0, sizeof(int) * m);     for (auto it : q) {       int tp = it.second.first;       int t = lower_bound(ts.begin(), ts.end(), it.first) - ts.begin();       if (tp == 1) {         inc(t, 1);       } else if (tp == 2) {         inc(t, -1);       } else {         ans[it.second.second] = sum(t);       }     }   }   void smain() {     for (; scanf( %d , &n) != EOF;) {       map<int, vector<pair<int, pair<int, int> > > > q;       for (int i = 0; i < n; i++) {         int a, t, x;         scanf( %d %d %d , &a, &t, &x);         q[x].emplace_back(t, make_pair(a, i));       }       memset(ans, 255, sizeof(int) * n);       for (auto it : q) solve(it.second);       for (int i = 0; i < n; i++)         if (ans[i] != -1) printf( %d n , ans[i]);     }   }


#include <bits/stdc++.h>   using namespace std;   int dx[] = {0, 0, -1, 1};   int dy[] = {-1, 1, 0, 0};   const int N = 1e6 + 5;   long long ans, sum, d[N];   int n, m;   int main() {     int a, b;     while (~scanf( %d%d , &n, &m)) {       memset(d, 0, sizeof(d));       for (int i = 0; i < (m); ++i) {         scanf( %d%d , &a, &b);         d[a]++, d[b]++;       }       if (n < 3) {         puts( 0 );         continue;       }       ans = (long long)n * (n - 1) * (n - 2) / 6;       sum = 0;       for (int i = (1); i <= (n); ++i) sum += d[i] * (n - 1 - d[i]);       sum /= 2;       printf( %lld n , ans - sum);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, a[200009], ans = 1, b[200009], sum = 1;   bool vis[200009];   void dfs(long long x) {     if (vis[x]) return;     vis[x] = 1;     dfs(a[x]);   }   int main() {     cin >> n;     for (int i = 1; i <= n; i++) cin >> a[i];     for (int i = 1; i <= n; i++) cin >> b[i];     dfs(1);     for (int i = 1; i <= n; i++) {       if (vis[i]) continue;       sum++;       dfs(i);     }     bool f = 0, g = 0;     for (int i = 1; i <= n; i++) {       ans += b[i];     }     ans %= 2;     if (sum != 1) ans += sum;     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int dp[2][105];   int main() {     int c, w, h, c2;     cin >> c >> w >> h;     c2 = (c + 1) >> 1;     int *src = dp[0], *dst = dp[1];     src[0] = 1;     for (int i = 1; i <= w; i++) src[i] = 0;     while (c2--) {       dst[0] = src[0];       for (int i = 1; i <= w; i++) {         dst[i] = src[i - 1] * h % 1000003;         dst[0] += src[i];       }       dst[0] %= 1000003;       swap(src, dst);     }     int ans = 0, sum = 0;     if ((c & 1) == 0) {       for (int i = 0; i <= w; i++) {         sum += src[i];         ans = (ans + (long long)sum * src[w - i]) % 1000003;       }     } else {       for (int i = 0; i <= w; i++) {         sum += dst[i];         ans = (ans + (long long)sum * src[w - i]) % 1000003;       }     }     cout << ans % 1000003 << endl;     return 0;   }


#include <bits/stdc++.h>   const int N = 1e6 + 10;   const int mod = 1e9 + 7;   const int INF = 0x3f3f3f3f;   using namespace std;   long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }   int n, m;   long long f[N];   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     f[1] = 2, f[2] = 4;     cin >> n >> m;     for (int i = 3; i <= max(n, m); ++i) f[i] = f[i - 1] % mod + f[i - 2] % mod;     cout << (f[n] + f[m] - 2) % mod <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 200010;   const int px[] = {0, 0, 1, -1}, py[] = {1, -1, 0, 0};   int n, m, a[1010][1010], tx[N], ty[N], f[N], ch[N][2], rev[N], tr[N * 4],       cnt[N * 4], tag[N * 4];   long long ans;   bool isroot(int x) {     return !x || !f[x] || (ch[f[x]][0] != x && ch[f[x]][1] != x);   }   int which(int x) { return ch[f[x]][1] == x; }   void rotate(int x) {     int fx = f[x], ffx = f[fx], d = which(x);     if (!isroot(fx)) ch[ffx][which(fx)] = x;     f[x] = f[fx];     ch[fx][d] = ch[x][d ^ 1];     f[ch[x][d ^ 1]] = fx;     ch[x][d ^ 1] = fx;     f[fx] = x;     return;   }   void rever(int x) {     rev[x] ^= 1;     swap(ch[x][0], ch[x][1]);     return;   }   void pushdown(int x) {     if (rev[x]) {       if (ch[x][0]) rever(ch[x][0]);       if (ch[x][1]) rever(ch[x][1]);       rev[x] = 0;     }     return;   }   void push(int x) {     if (!isroot(x)) push(f[x]);     pushdown(x);     return;   }   void splay(int x) {     push(x);     while (!isroot(x)) {       int fx = f[x];       if (!isroot(fx)) {         if (which(x) == which(fx))           rotate(fx);         else           rotate(x);       }       rotate(x);     }     return;   }   void access(int x) {     for (int y = 0; x; y = x, x = f[x]) {       splay(x);       ch[x][1] = y;     }     return;   }   void makeroot(int x) {     access(x);     splay(x);     rever(x);     return;   }   void link(int x, int y) {     makeroot(x);     f[x] = y;     return;   }   int getroot(int x) {     access(x);     splay(x);     while (ch[x][0]) x = ch[x][0];     return x;   }   void cut(int x, int y) {     makeroot(x);     access(y);     splay(y);     if (!ch[x][1] && ch[y][0] == x) f[x] = ch[y][0] = 0;     return;   }   bool check(int x, int y) {     makeroot(x);     access(y);     splay(y);     while (f[x]) x = f[x];     return x == y;   }   void sgtpushdown(int o) {     if (tag[o]) {       tr[o << 1] += tag[o];       tr[o << 1 | 1] += tag[o];       tag[o << 1] += tag[o];       tag[o << 1 | 1] += tag[o];       tag[o] = 0;     }     return;   }   void pushup(int o) {     if (tr[o << 1] == tr[o << 1 | 1]) {       tr[o] = tr[o << 1];       cnt[o] = cnt[o << 1] + cnt[o << 1 | 1];     } else if (tr[o << 1] < tr[o << 1 | 1]) {       tr[o] = tr[o << 1];       cnt[o] = cnt[o << 1];     } else {       tr[o] = tr[o << 1 | 1];       cnt[o] = cnt[o << 1 | 1];     }     return;   }   void build(int o, int l, int r) {     tr[o] = 0;     cnt[o] = r - l + 1;     if (l == r) return;     int mid = (l + r) >> 1;     build(o << 1, l, mid);     build(o << 1 | 1, mid + 1, r);     return;   }   void update(int o, int l, int r, int L, int R, int v) {     if (L <= l && r <= R) {       tag[o] += v;       tr[o] += v;       return;     }     sgtpushdown(o);     int mid = (l + r) >> 1;     if (L <= mid) update(o << 1, l, mid, L, R, v);     if (R > mid) update(o << 1 | 1, mid + 1, r, L, R, v);     pushup(o);     return;   }   int query(int o, int l, int r, int L, int R) {     if (tr[o] > 1) return 0;     if (L <= l && r <= R) return tr[o] * cnt[o];     sgtpushdown(o);     int mid = (l + r) >> 1, ret = 0;     if (L <= mid) ret += query(o << 1, l, mid, L, R);     if (R > mid) ret += query(o << 1 | 1, mid + 1, r, L, R);     return ret;   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) {         scanf( %d , a[i] + j);         tx[a[i][j]] = i;         ty[a[i][j]] = j;       }     int M = n * m;     build(1, 1, M);     for (int l = n * m, r = l; l >= 1; l--) {       int x = tx[l], y = ty[l];       for (int i = 0; i <= 3; i++) {         int nx = x + px[i], ny = y + py[i];         if (nx <= n && nx >= 1 && ny <= m && ny >= 1) {           while (a[nx][ny] >= l && a[nx][ny] <= r && check(a[x][y], a[nx][ny])) {             for (int j = 0; j <= 3; j++) {               int mx = tx[r] + px[j], my = ty[r] + py[j];               if (mx <= n && mx >= 1 && my <= m && my >= 1)                 cut(a[tx[r]][ty[r]], a[mx][my]);             }             r--;           }           if (a[nx][ny] >= l && a[nx][ny] <= r) {             link(a[x][y], a[nx][ny]);             update(1, 1, M, a[nx][ny], r, -1);           }         }       }       update(1, 1, M, l, r, 1);       ans += query(1, 1, M, l, r);     }     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct lhy {     int x, y, l, r, id;   } b[400040];   int n, m, mN, ans;   int cnt[400040], a[400040], Ans[400040], c[2 * 400040], C[2 * 400040],       L[400040], R[400040], x[2 * 400040];   inline void add(int x, int o) {     for (; x <= mN; x += x & -x) c[x] = max(c[x], o);   }   inline int ask(int x) {     int nowans = 0;     for (; x; x -= x & -x) nowans = max(nowans, c[x]);     return nowans;   }   inline void Add(int x, int o) {     for (; x; x -= x & -x) C[x] = max(C[x], o);   }   inline int Ask(int x) {     int nowans = 0;     for (; x <= mN; x += x & -x) nowans = max(nowans, C[x]);     return nowans;   }   inline int cmp(const lhy &a, const lhy &b) { return a.x < b.x; }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]), x[++x[0]] = a[i];     for (int i = 1; i <= m; i++)       scanf( %d%d , &b[i].x, &b[i].y), b[i].id = i, x[++x[0]] = b[i].y;     sort(x + 1, x + 1 + x[0]);     mN = unique(x + 1, x + 1 + x[0]) - x - 1;     for (int i = 1; i <= n; i++) a[i] = lower_bound(x + 1, x + 1 + mN, a[i]) - x;     for (int i = 1; i <= m; i++)       b[i].y = lower_bound(x + 1, x + 1 + mN, b[i].y) - x;     sort(b + 1, b + 1 + m, cmp);     int now = 1;     for (int i = 1; i <= n; i++) {       L[i] = ask(a[i] - 1);       while (b[now].x == i) {         b[now].l = ask(b[now].y - 1);         now++;       }       add(a[i], L[i] + 1);     }     now = m;     for (int i = n; i; i--) {       R[i] = Ask(a[i] + 1);       while (b[now].x == i) {         b[now].r = Ask(b[now].y + 1);         now--;       }       Add(a[i], R[i] + 1);     }     for (int i = 1; i <= n; i++) ans = max(ans, L[i] + R[i] + 1);     for (int i = 1; i <= n; i++)       if (L[i] + R[i] + 1 == ans) cnt[L[i]]++;     for (int i = 1; i <= m; i++)       if (L[b[i].x] + R[b[i].x] + 1 < ans || cnt[L[b[i].x]] > 1)         Ans[b[i].id] = max(ans, b[i].l + b[i].r + 1);       else         Ans[b[i].id] = max(ans - 1, b[i].l + b[i].r + 1);     for (int i = 1; i <= m; i++) printf( %d n , Ans[i]);   }


#include <bits/stdc++.h>   using namespace std;   long long n, a[100069], dv;   int main() {     long long i, j, z = 1;     scanf( %lld%lld , &n, &dv);     if (n > dv) {       printf( 0 n );       return 0;     }     for (i = 1; i <= n; i++) {       scanf( %lld , a + i);       for (j = 1; j < i; j++) {         z = z * abs(a[i] - a[j]) % dv;       }     }     printf( %lld n , z);   }


#include <bits/stdc++.h>   using namespace std;   int f(string s, int i) {     if (s[i] ==  ( ) return 0;     if (s[i] ==  [ ) return 1;     if (s[i] ==  8 ) return 2;   }   int main() {     int a, b;     string s1, s2;     cin >> s1 >> s2;     a = b = 0;     for (int i = 0; i < s1.size(); i += 2) {       if ((f(s1, i) == 0 && f(s2, i) == 2) || (f(s1, i) == 1 && f(s2, i) == 0) ||           (f(s1, i) == 2 && f(s2, i) == 1))         a++;       else if (f(s1, i) != f(s2, i))         b++;     }     if (a == b) cout <<  TIE ;     if (a > b) cout <<  TEAM 1 WINS ;     if (b > a) cout <<  TEAM 2 WINS ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   const int max_n = 200005;   vector<pair<int, int>> g[max_n];   int sz[max_n];   long long dis[max_n];   void dfs(int x) {     sz[x] = 1;     for (auto p : g[x]) {       int u = p.first;       if (sz[u]) continue;       dis[u] = p.second;       dfs(u);       sz[x] += sz[u];     }   }   void solve() {     int n;     cin >> n;     n *= 2;     for (int i = 0; i <= n; i++) g[i].clear();     for (int i = 0; i <= n; i++) sz[i] = dis[i] = 0;     for (int i = 1; i < n; i++) {       int u, v, w;       cin >> u >> v >> w;       g[u].push_back({v, w});       g[v].push_back({u, w});     }     dfs(1);     long long ans1 = 0, ans2 = 0;     for (int i = 2; i <= n; i++) {       if (sz[i] & 1) ans1 += dis[i];       ans2 += min(sz[i], n - sz[i]) * dis[i];     }     cout << ans1 <<     << ans2 << endl;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     int t;     cin >> t;     while (t--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, i, tmp_ara1, tmp_ara2;     vector<long long> ara1(2000007, -1), ara2(2000007, -1), ans(200007, -1),         in_front;     cin >> n;     for (i = 1; i <= n; i++) {       cin >> tmp_ara1 >> tmp_ara2;       ara1[tmp_ara1] = tmp_ara2;       ara2[tmp_ara2] = tmp_ara1;       in_front.push_back(tmp_ara1);     }     long long key = 0;     for (i = 2; i <= n; i += 2) {       ans[i] = ara1[key];       key = ara1[key];     }     long long first;     for (i = 0; i < n; i++) {       if (ara2[in_front[i]] == -1) {         first = in_front[i];         break;       }     }     key = first;     ans[1] = first;     for (i = 3; i <= n; i += 2) {       ans[i] = ara1[key];       key = ara1[key];     }     for (i = 1; i <= n; i++) {       cout << ans[i] <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   char gird[64][64];   set<long long int> set_of_cols;   int main(void) {     int i, j;     scanf( %d%d , &n, &m);     for (i = 0; i < n; ++i) scanf( %s , gird[i]);     for (i = 0; i < n; ++i) {       long long int id = 0;       for (j = 0; j < m; ++j) {         id <<= 1;         id |= ( #  == gird[i][j]) ? 1 : 0;       }       for (auto have : set_of_cols) {         if (have != id && ((have & id) != 0)) {           puts( No );           return 0;         }       }       set_of_cols.insert(id);     }     puts( Yes );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     string str;     cin >> str;     int t;     cin >> t;     int type, pos, l, r;     char c;     set<int> s[26];     for (int i = 0; i < str.length(); i++) s[str[i] -  a ].insert(i + 1);     while (t--) {       cin >> type;       if (type == 1) {         cin >> pos >> c;         s[str[pos - 1] -  a ].erase(pos);         s[c -  a ].insert(pos);         str[pos - 1] = c;       } else {         cin >> l >> r;         int count = 0;         for (int i = 0; i < 26; i++)           if (s[i].lower_bound(l) != s[i].upper_bound(r)) count++;         cout << count << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool check(char a) {     if (a ==  a  || a ==  e  || a ==  i  || a ==  o  || a ==  u ) return true;     if (a ==  1  || a ==  3  || a ==  5  || a ==  7  || a ==  9 ) return true;     return false;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     string s;     cin >> s;     int ans = 0;     for (int i = 0; i < s.length(); i++)       if (check(s[i])) ans++;     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     string s;     getline(cin, s);     long long n = s.size(), i;     for (i = n - 1; i >= 0; i--) {       if (isupper(s[i])) {         s[i] = tolower(s[i]);       }       if (s[i] ==  ?  || s[i] ==    ) {         continue;       } else if (s[i] ==  a  || s[i] ==  e  || s[i] ==  i  || s[i] ==  o  ||                  s[i] ==  u  || s[i] ==  y ) {         cout <<  YES  << endl;         break;       } else {         cout <<  NO  << endl;         break;       }     }   }


#include <bits/stdc++.h>   long long inp() {     char c = getchar();     int neg = 1;     while (c <  0  || c >  9 ) {       if (c ==  - ) neg = -1;       c = getchar();     }     long long sum = 0;     while (c >=  0  && c <=  9 ) {       sum = sum * 10 + c -  0 ;       c = getchar();     }     return sum * neg;   }   long long v[300010], mask[300010];   int main() {     int n = inp();     long long sum = 0;     for (int i = 1; i <= n; i++) {       v[i] = inp();       sum += v[i];       mask[i] = inp();     }     if (sum < 0)       for (int i = 1; i <= n; i++) v[i] *= -1;     long long s = 0;     for (int i = 0; i <= 61; i++) {       long long sum = 0;       for (int j = 1; j <= n; j++) {         if (mask[j] & (1ll << i)) {           if (mask[j] <= (1ll << (i + 1))) {             if (__builtin_popcountll(s & mask[j]) & 1)               sum += v[j];             else               sum -= v[j];           }         }       }       if (sum < 0) s |= (1ll << i);     }     std::cout << s << std::endl;   }


#include <bits/stdc++.h>   using namespace std;   pair<int, int> s[100010];   int a[100010], b[100010];   int main() {     int N, P, i, x;     scanf( %d n , &N);     for (i = 0; i < N; i++) {       scanf( %d , &x);       s[i] = make_pair(x, i);     }     sort(s, s + N);     P = N / 3;     for (i = 0; i < P; i++) {       a[s[i].second] = s[i].first;       b[s[i].second] = 0;     }     P = (2 * N) / 3;     for (; i < P; i++) {       a[s[i].second] = 0;       b[s[i].second] = s[i].first;     }     for (; i < N; i++) {       a[s[i].second] = s[i].first - (N - i - 1);       b[s[i].second] = N - i - 1;     }     printf( YES n );     for (i = 0; i < N; i++) printf( %d  , a[i]);     printf(  n );     for (i = 0; i < N; i++) printf( %d  , b[i]);     printf(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, t[100010], nowt, pos, ans[100010];   pair<int, int> a[100010];   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; ++i) {       scanf( %d%d , &t[i], &a[i].first);       a[i].second = i;     }     for (int i = 1, j; i <= n; i = j + 1) {       j = min(n, i + m - 1);       sort(a + i, a + j + 1);       nowt = max(nowt, t[j]);       pos = 0;       for (int k = i, l; k <= j; k = l) {         l = k;         while (l <= j && a[l].first == a[k].first) ++l;         nowt += a[k].first - pos;         for (int h = k; h < l; ++h) ans[a[h].second] = nowt;         nowt += 1 + (l - k) / 2;         pos = a[k].first;       }       nowt += pos;     }     for (int i = 1; i <= n; ++i) printf( %d  , ans[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long fastPow(long long a, long long b) {     long long ret = 1;     while (b) {       if (b & 1) ret *= a;       a *= a;       b >>= 1;     }     return ret;   }   int main() {     ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);     long long n, e, o, ce, co, ret = INT_MIN, c;     cin >> n;     vector<long long> nums(n + 1);     for (int i = int(1); i < int(n + 1); i++) cin >> nums[i];     e = 0, o = 0, ce = 0, co = 0, c = 0;     for (int l = int(1); l < int(n); l++) {       if (!(l % 2)) {         e = abs(nums[l] - nums[l + 1]);         ce = max(ce + e, c);         o = e * -1;         co = max(co + o, c);       } else {         e = abs(nums[l] - nums[l + 1]) * -1;         ce = max(ce + e, c);         o = e * -1;         co = max(co + o, c);       }       ret = max(ret, max(ce, co));     }     cout << ret << endl;     return 0;   }


#include <bits/stdc++.h>   template <typename T>   void MACRO_VAR_Scan(T& t) {     std::cin >> t;   }   template <typename First, typename... Rest>   void MACRO_VAR_Scan(First& first, Rest&... rest) {     std::cin >> first;     MACRO_VAR_Scan(rest...);   }   template <typename T>   void MACRO_VEC_ROW_Init(int n, T& t) {     t.resize(n);   }   template <typename First, typename... Rest>   void MACRO_VEC_ROW_Init(int n, First& first, Rest&... rest) {     first.resize(n);     MACRO_VEC_ROW_Init(n, rest...);   }   template <typename T>   void MACRO_VEC_ROW_Scan(int p, T& t) {     std::cin >> t[p];   }   template <typename First, typename... Rest>   void MACRO_VEC_ROW_Scan(int p, First& first, Rest&... rest) {     std::cin >> first[p];     MACRO_VEC_ROW_Scan(p, rest...);   }   template <class T>   inline T CHMAX(T& a, const T b) {     return a = (a < b) ? b : a;   }   template <class T>   inline T CHMIN(T& a, const T b) {     return a = (a > b) ? b : a;   }   void CHECKTIME(std::function<void()> f) {     auto start = std::chrono::system_clock::now();     f();     auto end = std::chrono::system_clock::now();     auto res = std::chrono::duration_cast<std::chrono::nanoseconds>((end - start))                    .count();     std::cerr << res / (1.0e9) <<  s n ;   }   template <class T>   using V = std::vector<T>;   template <class T>   using VV = V<V<T>>;   template <typename S, typename T>   std::ostream& operator<<(std::ostream& os, std::pair<S, T> p) {     os <<  (  << p.first <<  ,   << p.second <<  ) ;     return os;   }   using ll = long long;   using ull = unsigned long long;   using ld = long double;   using PAIR = std::pair<ll, ll>;   using PAIRLL = std::pair<ll, ll>;   constexpr ll INFINT = (1 << 30) - 1;   constexpr ll INFINT_LIM = (1LL << 31) - 1;   constexpr ll INFLL = 1LL << 60;   constexpr ll INFLL_LIM = (1LL << 62) - 1 + (1LL << 62);   constexpr double EPS = 1e-10;   constexpr ll MOD = 998244353;   constexpr double PI = 3.141592653589793238462643383279;   template <class T, size_t N>   void FILL(T (&a)[N], const T& val) {     for (auto& x : a) x = val;   }   template <class ARY, size_t N, size_t M, class T>   void FILL(ARY (&a)[N][M], const T& val) {     for (auto& b : a) FILL(b, val);   }   template <class T>   void FILL(std::vector<T>& a, const T& val) {     for (auto& x : a) x = val;   }   template <class ARY, class T>   void FILL(std::vector<std::vector<ARY>>& a, const T& val) {     for (auto& b : a) FILL(b, val);   }   class ModInt {     static constexpr std::int_fast64_t M = MOD;     using value_type = std::int_fast64_t;       public:     value_type x;     ModInt() : x(0) {}     ModInt(value_type n) : x(n % M) {       if (x < 0) x += M;     }     const std::int_fast64_t& operator()() const { return x; }     ModInt operator+() const { return *this; }     ModInt operator-() const { return ModInt(-x); }     ModInt& operator++() { return *this += 1; }     ModInt& operator++(signed tmp) { return *this += 1; }     ModInt& operator--() { return *this -= 1; }     ModInt& operator--(signed tmp) { return *this -= 1; }     ModInt& operator=(const ModInt& r) {       x = r.x;       return *this;     }     ModInt& operator=(const value_type& r) { return *this = ModInt(r); }     ModInt& operator+=(const ModInt& r) {       x += r.x;       if (x >= M) x -= M;       return *this;     }     ModInt& operator-=(const ModInt& r) {       x -= r.x;       if (x < +0) x += M;       return *this;     }     ModInt& operator*=(const ModInt& r) {       x = x * r.x % M;       return *this;     }     ModInt& operator/=(ModInt r) { return *this *= r ^= M - 2; }     ModInt& operator^=(value_type p) {       p %= M - 1;       if (p < 0) p += M - 1;       ModInt res(1);       while (p) {         if (p & 1) res *= *this;         *this *= *this;         p >>= 1;       }       return *this = res;     }     ModInt& operator+=(const value_type& r) { return *this += ModInt(r); }     ModInt& operator-=(const value_type& r) { return *this -= ModInt(r); }     ModInt& operator*=(const value_type& r) { return *this *= ModInt(r); }     ModInt& operator/=(const value_type& r) { return *this /= ModInt(r); }     ModInt operator+(const ModInt& r) const { return ModInt(*this) += r; }     ModInt operator-(const ModInt& r) const { return ModInt(*this) -= r; }     ModInt operator*(const ModInt& r) const { return ModInt(*this) *= r; }     ModInt operator/(const ModInt& r) const { return ModInt(*this) /= r; }     ModInt operator+(const value_type& r) const { return ModInt(*this) += r; }     ModInt operator-(const value_type& r) const { return ModInt(*this) -= r; }     ModInt operator*(const value_type& r) const { return ModInt(*this) *= r; }     ModInt operator/(const value_type& r) const { return ModInt(*this) /= r; }     ModInt operator^(const value_type& r) const { return ModInt(*this) ^= r; }   };   std::ostream& operator<<(std::ostream& os, const ModInt& obj) {     return os << obj.x;   }   std::istream& operator>>(std::istream& is, ModInt& obj) {     std::int_fast64_t x;     is >> x;     obj = ModInt(x);     return is;   }   struct S {     ModInt w, s0, s1;     bool operator<(const S& r) const {       return std::tie(w(), s0(), s1()) < std::tie(r.w(), r.s0(), r.s1());     }   };   std::map<S, ModInt> dp[2];   signed main() {     std::ios::sync_with_stdio(false);     std::cin.tie(0);     ;     ll n, m;     MACRO_VAR_Scan(n, m);     ;     std::vector<ll> a(n);     for (auto& i : a) std::cin >> i;     ;     std::vector<ModInt> w(n);     for (auto& i : w) std::cin >> i;     ;     ModInt bsum0 = 0, bsum1 = 0;     for (ll i = 0; i < ll(n); ++i) {       if (a[i])         bsum1 += w[i];       else         bsum0 += w[i];     }     for (ll i = 0; i < ll(n); ++i) {       dp[0].clear();       dp[1].clear();       dp[1][S{w[i], bsum0, bsum1}] = 1;       for (ll _ = 0; _ < ll(m); ++_) {         std::swap(dp[0], dp[1]);         for (const auto& p : dp[0]) {           const auto& s = p.first;           const auto& v = p.second;           auto sum = s.s0 + s.s1;           if (a[i]) {             dp[1][S{s.w + 1, s.s0 - 0, s.s1 + 1}] += v * s.w / sum;             dp[1][S{s.w + 0, s.s0 - 0, s.s1 + 1}] += v * (s.s1 - s.w) / sum;             dp[1][S{s.w + 0, s.s0 - 1, s.s1 + 0}] += v * s.s0 / sum;           } else {             dp[1][S{s.w - 1, s.s0 - 1, s.s1 + 0}] += v * s.w / sum;             dp[1][S{s.w + 0, s.s0 - 1, s.s1 + 0}] += v * (s.s0 - s.w) / sum;             dp[1][S{s.w + 0, s.s0 - 0, s.s1 + 1}] += v * s.s1 / sum;           }         }         dp[0].clear();       }       ModInt ans = 0;       for (const auto& p : dp[1]) ans += p.second * p.first.w;       std::cout << (ans);       std::cout <<   n ;       ;     }     return 0;   }


#include <bits/stdc++.h>   int cut;   int q[100005] = {0};   int totalnode, totaledge, i, j, k, l, a, b, t1, t2;   int c(int q) {     if (q == 2) {       return cut;     } else if (q == cut) {       return 2;     } else       return q;   }   int main() {     for (i = 0; i < 100005; i++) q[i] = i;     scanf( %d %d %d , &totalnode, &totaledge, &cut);     q[cut] = 2;     q[2] = cut;     if (totaledge >= totalnode - 1 &&         (totalnode - 1) * (totalnode - 2) / 2 + 1 >= totaledge) {       for (i = 1; i <= totalnode - 1; i++) {         printf( %d %d n , q[i], q[i + 1]);         totaledge--;       }       for (i = 2; i <= totalnode && totaledge > 0; i++) {         for (j = i + 2; j <= totalnode && totaledge > 0; j++) {           printf( %d %d n , q[i], q[j]);           totaledge--;         }       }     } else {       printf( -1 );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct Date {     int y, m, d;   };   const int monthDays[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};   int countLeapYears(Date d) {     int years = d.y;     if (d.m <= 2) years--;     return years / 4 - years / 100 + years / 400;   }   int getDifference(Date dt1, Date dt2) {     long int n1 = dt1.y * 365 + dt1.d;     for (int i = 0; i < dt1.m - 1; i++) n1 += monthDays[i];     n1 += countLeapYears(dt1);     long int n2 = dt2.y * 365 + dt2.d;     for (int i = 0; i < dt2.m - 1; i++) n2 += monthDays[i];     n2 += countLeapYears(dt2);     return (n2 - n1);   }   int main() {     int y1, y2, m1, m2, d1, d2;     char ch1, ch2, ch3, ch4;     int tmp;     cin >> y1 >> ch1 >> m1 >> ch2 >> d1;     cin >> y2 >> ch3 >> m2 >> ch4 >> d2;     if ((y1 > y2) || (y1 == y2 && m1 > m2) || (y1 == y2 && m1 == m2 && d1 > d2)) {       tmp = y1;       y1 = y2;       y2 = tmp;       tmp = m1;       m1 = m2;       m2 = tmp;       tmp = d1;       d1 = d2;       d2 = tmp;     }     Date dt1 = {y1, m1, d1};     Date dt2 = {y2, m2, d2};     cout << getDifference(dt1, dt2) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = 1e16;   long long n, a[200005], p[200005], MA = 0, z = 0;   int main() {     scanf( %lld , &n);     memset(p, 0, sizeof(p));     for (int i = 0; i < n; i++) {       scanf( %lld , &a[i]);       p[a[i]]++;       if (p[a[i]] > MA) {         MA = p[a[i]];         z = a[i];       }     }     printf( %lld n , n - MA);     for (int i = 0; i < n - 1; i++) {       if (a[i] == z) {         if (a[i + 1] < a[i]) {           printf( 1 %d %d n , i + 2, i + 1);           a[i + 1] = z;         } else if (a[i + 1] > a[i]) {           printf( 2 %d %d n , i + 2, i + 1);           a[i + 1] = z;         }       }     }     for (int i = n - 1; i >= 1; i--) {       if (a[i] == z) {         if (a[i - 1] < a[i]) {           printf( 1 %d %d n , i, i + 1);           a[i - 1] = z;         } else if (a[i - 1] > a[i]) {           printf( 2 %d %d n , i, i + 1);           a[i - 1] = z;         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   set<pair<pair<long long int, long long int>, long long int> > ev;   vector<long long int> cnt, len;   multiset<pair<long long int, long long int> > flug;   void expand(       set<pair<pair<long long int, long long int>, long long int> >::iterator it,       long long int a) {     pair<pair<long long int, long long int>, long long int> p = *it;     p.first.first += a;     cnt[p.second]++, len[p.second] += a;     auto nt = ev.insert(p).first;     ev.erase(it, nt);     auto ft = flug.upper_bound(make_pair(p.first.first, 1e18));     if (ft == flug.begin()) return;     ft--;     if (ft->first >= -p.first.second) {       long long int add = ft->second;       flug.erase(ft);       expand(nt, add);     }   }   int main() {     int n, m;     scanf( %d%d , &n, &m);     vector<pair<pair<long long int, long long int>, long long int> > g(n), f(m);     cnt = len = vector<long long int>(n, 0);     for (int((i)) = (0); ((i)) < ((n)); ((i))++) {       int x, sz;       scanf( %d%d , &x, &sz);       g[i] = make_pair(make_pair((x), (sz)), (i));       len[i] = sz;     }     for (int((i)) = (0); ((i)) < ((m)); ((i))++) {       int x, sz;       scanf( %d%d , &x, &sz);       f[i] = make_pair(make_pair((x), (sz)), (i));     }     sort((g).begin(), (g).end());     reverse((g).begin(), (g).end());     for (int((i)) = (0); ((i)) < ((n)); ((i))++) {       auto it =           ev.insert(make_pair(make_pair((g[i].first.first + g[i].first.second),                                         (-g[i].first.first)),                               (g[i].second)))               .first;       ev.erase(ev.begin(), it);     }     for (int((i)) = (0); ((i)) < ((m)); ((i))++) {       pair<pair<long long int, long long int>, long long int> fp =           make_pair(make_pair((f[i].first.first), (-1e18)), (0));       auto it = ev.lower_bound(fp);       if (it != ev.end() && -it->first.second <= f[i].first.first)         expand(it, f[i].first.second);       else         flug.insert({f[i].first.first, f[i].first.second});     }     for (int((i)) = (0); ((i)) < ((n)); ((i))++)       printf( %I64d %I64d n , cnt[i], len[i]);   }


#include <bits/stdc++.h>   using namespace std;   const long double eps = 1e-9;   const long long MOD = 1e9 + 7;   const int N = 2e6 + 10;   const long double pi = 3.1415926535897932384650288;   int n, m;   string s, t;   bool ok(int i, int j, int d) {     if (j == m) return 1;     if (i == n) return 0;     if (i < 0) return 0;     if (s[i] != t[j]) return 0;     if (d) {       return ok(i - 1, j + 1, d);     }     return ok(i + 1, j + 1, d) || ok(i - 1, j + 1, 1);   }   void solve() {     cin >> s >> t;     n = s.size();     m = t.size();     for (int i = 0; i < n; i++) {       if (ok(i, 0, 0)) {         puts( Yes );         return;       }     }     puts( No );   }   int main() {     int t = 1;     scanf( %d , &t);     while (t--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline T read() {     T x = 0, f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = (x << 1) + (x << 3) + (ch ^ 48);       ch = getchar();     }     return x * f;   }   const int N = 100010, INF = 0x3f3f3f3f;   int n, q, k, key[N];   struct Edge {     int to, nxt;   };   struct Graph {     int head[N], tot;     Edge e[N << 1];     void addedge(int x, int y) {       e[++tot] = (Edge){y, head[x]};       head[x] = tot;     }   };   struct Tree : public Graph {     int dfn[N], ti, f[N][19], dep[N];     void dfs(int x, int fa) {       dfn[x] = ++ti;       f[x][0] = fa;       dep[x] = dep[fa] + 1;       for (int i = 1; i <= 18; i++) f[x][i] = f[f[x][i - 1]][i - 1];       for (int i = head[x]; i; i = e[i].nxt) {         int y = e[i].to;         if (y == fa) continue;         dfs(y, x);       }     }     int lca(int x, int y) {       if (dep[x] < dep[y]) swap(x, y);       for (int i = 18; i >= 0; i--) {         if (dep[f[x][i]] >= dep[y]) x = f[x][i];       }       if (x == y) return x;       for (int i = 18; i >= 0; i--) {         if (f[x][i] != f[y][i]) x = f[x][i], y = f[y][i];       }       return f[x][0];     }   } t;   struct Virtual_Tree : public Graph {     int dp[N][2], d[N], st[N], tp;     void build_vtree(Tree& t, int* key, int cnt) {       memcpy(d, key, sizeof(int) * (cnt + 1));       sort(d + 1, d + cnt + 1, [&](int x, int y) { return t.dfn[x] < t.dfn[y]; });       head[1] = 0, tot = 0;       st[tp = 1] = 1;       for (int i = 1; i <= cnt; i++) {         if (d[i] == 1) continue;         int lc = t.lca(d[i], st[tp]);         if (lc != st[tp]) {           while (t.dfn[lc] < t.dfn[st[tp - 1]]) {             addedge(st[tp - 1], st[tp]);             tp--;           }           if (t.dfn[lc] != t.dfn[st[tp - 1]]) {             head[lc] = 0, addedge(lc, st[tp]);             st[tp] = lc;           } else             addedge(lc, st[tp]), tp--;         }         head[d[i]] = 0, st[++tp] = d[i];       }       for (int i = 1; i < tp; i++) addedge(st[i], st[i + 1]);     }     void dfs_dp(int, int);   } vt;   int iskey[N];   void Virtual_Tree::dfs_dp(int x, int fa) {     dp[x][0] = (!iskey[x]) * n, dp[x][1] = iskey[x] * n;     int minx = INF, sum = 1, cnt = 0;     for (int i = head[x]; i; i = e[i].nxt) {       int y = e[i].to;       if (y == fa) continue;       cnt += iskey[y];       dfs_dp(y, x);       if (iskey[x])         dp[x][0] += min(dp[y][1], dp[y][0] + 1);       else {         minx = min(minx, dp[y][0] - dp[y][1]);         sum += min(dp[y][0], dp[y][1]);         dp[x][1] += dp[y][1];       }     }     if (!iskey[x] && cnt <= 1) dp[x][0] = dp[x][1] + minx;     if (!iskey[x]) dp[x][1] = min(dp[x][1], sum);   }   void solve() {     k = read<int>();     for (int i = 1; i <= k; i++) iskey[key[i] = read<int>()] = 1;     for (int i = 1; i <= k; i++) {       int x = key[i];       if (iskey[t.f[x][0]]) {         for (int j = 1; j <= k; j++) iskey[key[j]] = 0;         puts( -1 );         return;       }     }     vt.build_vtree(t, key, k);     vt.dfs_dp(1, 0);     printf( %d n , min(vt.dp[1][0], vt.dp[1][1]));     for (int j = 1; j <= k; j++) iskey[key[j]] = 0;   }   int main() {     n = read<int>();     for (int i = 1; i < n; i++) {       int x = read<int>(), y = read<int>();       t.addedge(x, y);       t.addedge(y, x);     }     t.dfs(1, 0);     q = read<int>();     while (q--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int arr[102];       int n;       cin >> n;       for (int i = 1; i <= n; i++) cin >> arr[i];       int myseq[102];       for (int i = 1; i <= n; i++) {         if (i & 1)           myseq[i] = arr[i + 1];         else           myseq[i] = -arr[i - 1];       }       for (int i = 1; i <= n; i++) cout << myseq[i] <<    ;       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2005;   const long long mod = 998244353;   string s, t;   long long p[maxn], n;   long long dp[maxn][maxn];   long long ksm(long long a, long long b) {     long long r = 1;     while (b) {       if (b & 1) r = (r * a) % mod;       a = a * a % mod;       b >>= 1;     }     return r;   }   long long dfs(int l, int r) {     if (dp[l][r] != -1) return dp[l][r];     if (l >= r || l > n || r <= 0) return dp[l][r] = 0;     long long ans = 0;     if (s[l] !=  ( ) ans = (ans + dfs(l + 1, r)) % mod;     if (s[r] !=  ) ) ans = (ans + dfs(l, r - 1)) % mod;     if (s[l] !=  (  && s[r] !=  ) ) ans = (ans - dfs(l + 1, r - 1) + mod) % mod;     if (s[l] !=  )  && s[r] !=  ( )       ans = (ans + dfs(l + 1, r - 1) + ksm(2, p[r - 1] - p[l])) % mod;     return dp[l][r] = ans;   }   int main() {     s +=  # ;     cin >> t;     s += t;     n = t.size();     memset(dp, -1, sizeof(dp));     for (int i = 1; i <= n; i++) p[i] = p[i - 1] + (s[i] ==  ? );     dfs(1, n);     cout << dp[1][n] << endl;   }


#include <bits/stdc++.h>   const char en =   n ;   using namespace std;   int main() {     ios::sync_with_stdio(false);     int n;     cin >> n;     vector<long long> V(n + 47, 0);     long long ma2 = 0;     long long ma3 = 0;     vector<long long> X;     for (int i = 0; i < n; i++) {       cin >> V[i];       long long p2 = 0, p3 = 0;       long long k = V[i];       while (k % 2 == 0) {         p2++;         k /= 2;       }       while (k % 3 == 0) {         p3++;         k /= 3;       }       X.push_back(k);     }     sort(X.begin(), X.end());     if (X[0] == X[n - 1])       cout <<  Yes  << en;     else       cout <<  No  << en;   }


#include <bits/stdc++.h>   using namespace std;   const int oo = 1000000000;   const double H = sqrt(3.0) * 0.5;   const double eps = 1e-6;   int main() {     double r;     scanf( %lf , &r);     int i;     long long ans = 0;     for (i = 0; i <= r; i++) {       double x = 1.5 * i + 1.0;       if (x > r) break;       double y = sqrt(r * r - x * x);       int k;       if (i % 2)         k = (floor(y / H + eps) + 1) / 2;       else         k = floor(y / H + eps) / 2 + 1;       x = 1.5 * i + 0.5;       y = sqrt(r * r - x * x);       if (i % 2)         k = 2 * min(k, (int)floor(y / H + eps) / 2);       else         k = 2 * min(k, ((int)floor(y / H + eps) + 1) / 2) - 1;       ans += i ? 2 * k : k;     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     string s;     cin >> s;     unordered_map<char, vector<long long int> > um;     long long int i;     for (i = 0; i < s.length(); i++) {       um[s[i]].push_back(i);     }     long long int last = -1;     bool flag;     string ans =   ;     for (i = 25; i >= 0; i--) {       char ch =  a  + i;       auto f = um.find(ch);       if (f != um.end()) {         for (auto it : um[ch]) {           if (it > last) {             ans += string(1, s[it]);             flag = true;           }         }         if (flag == true) last = um[ch][um[ch].size() - 1];       }       flag = false;     }     cout << ans << endl;   }   int main() {     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using pii = pair<int, int>;   using ll = long long;   const int N = 3e3 + 3;   int a[N][N];   pii sum[N];   int main() {     ios_base::sync_with_stdio(false);     int n, m;     cin >> n >> m;     for (int i = 0; i < m; i++) {       for (int j = 0; j < n; j++) cin >> a[i][j];     }     vector<int> res;     int mn = 1e9;     for (int i = 0; i < n - 1; i++) {       vector<pii> ve;       int sum = 0;       for (int j = 0; j < m; j++) {         sum += a[j][i] - a[j][n - 1];         ve.push_back({a[j][i] - a[j][n - 1], j});       }       sort(ve.begin(), ve.end());       vector<int> cur;       for (int i = 0; i < m; i++) {         if (sum >= 0) break;         sum -= ve[i].first;         cur.push_back(ve[i].second);       }       if (cur.size() < mn) {         mn = cur.size();         res = cur;       }     }     cout << res.size() <<   n ;     for (auto x : res) cout << ++x <<    ;     cout <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1000005;   long long A[N], B[N], n, xx, mx;   bool check(int n, int m) {     int x = n - xx, y = mx - x;     if (x < 0 || x >= n || y < 0 || y >= m) return 0;     memset(B, 0, sizeof(B));     for (int i = 0; i < n; ++i)       for (int j = 0; j < m; ++j) ++B[abs(y - j) + abs(i - x)];     if (!memcmp(A, B, sizeof(A))) {       printf( %d %d n%d %d n , n, m, x + 1, y + 1);       return 1;     }     return 0;   }   int main() {     cin >> n;     for (int i = 1; i <= n; ++i) {       scanf( %lld , &xx);       A[xx]++;       if (xx > mx) mx = xx;     }     if (A[0] != 1) {       printf( -1 );       return 0;     }     for (xx = 1; xx <= mx; ++xx)       if (A[xx] != xx * 4) {         if (A[xx] > xx * 4) {           printf( -1 );           return 0;         } else           break;       }     for (int i = 1; i * i <= n; ++i) {       if (n % i) continue;       if (check(i, n / i)) return 0;       if (check(n / i, i)) return 0;     }     printf( -1 n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char A[1005][1005];   int P[1000005], MinX[1000005], MinY[1000005], MaxX[1000005], MaxY[1000005],       M[1005][1005];   int xr[] = {-1, 1, 0, 0};   int xc[] = {0, 0, -1, 1};   int n, m;   void dfs(int x, int y, int i) {     if ((x < 0) || (x >= n) || (y < 0) || (y >= m) || (A[x][y] ==  . ) ||         (M[x][y]))       return;     M[x][y] = 1;     MinX[i] = min(MinX[i], x);     MinY[i] = min(MinY[i], y);     MaxX[i] = max(MaxX[i], x);     MaxY[i] = max(MaxY[i], y);     for (int j = 0; j < 4; ++j) {       dfs(x + xr[j], y + xc[j], i);     }   }   bool check_convex_island(int len) {     set<int> X, Y;     for (int i = 0; i < n; ++i) X.insert(i);     for (int i = 0; i < m; ++i) Y.insert(i);     int x, i, j, ans = 1;     for (x = 0; x < len; ++x) {       int minx = MinX[x];       int miny = MinY[x];       int maxx = MaxX[x];       int maxy = MaxY[x];       for (i = minx; i <= maxx; ++i) {         if (!X.count(i)) return false;         X.erase(i);         for (j = miny; A[i][j] ==  . ; ++j)           ;         for (; (j <= maxy) && (A[i][j] ==  # ); ++j)           ;         for (; (j <= maxy) && (A[i][j] ==  . ); ++j)           ;         ans &= (j > maxy);       }       for (j = miny; j <= maxy; ++j) {         if (!Y.count(j)) return false;         Y.erase(j);         for (i = minx; A[i][j] ==  . ; ++i)           ;         for (; (i <= maxx) && (A[i][j] ==  # ); ++i)           ;         for (; (i <= maxx) && (A[i][j] ==  . ); ++i)           ;         ans &= (i > maxx);       }     }     return ans;   }   int main() {     ios_base::sync_with_stdio(false);     cout.tie(0);     cin.tie(0);     int i, j, k, x, y, z, a, b;     for (i = 0; i <= 1000000; ++i) MinX[i] = MinY[i] = 1000000007;     cin >> n >> m;     for (i = 0; i < n; ++i) cin >> A[i];     int ans = 1, len = 0;     set<int> X, Y;     for (i = 0; i < n; ++i) X.insert(i);     for (i = 0; i < m; ++i) Y.insert(i);     for (i = 0; i < n; ++i) {       for (j = 0; j < m; ++j) {         if (A[i][j] ==  . ) continue;         if (X.find(i) != X.end()) X.erase(i);         if (Y.find(j) != Y.end()) Y.erase(j);         if (!M[i][j]) dfs(i, j, len++);       }     }     ans &= ((X.size() == 0 && Y.size() == 0) || (X.size() && Y.size()));     ans &= check_convex_island(len);     if (ans)       cout << len << endl;     else       cout << -1 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int _5 = 100005, _6 = 1000006;   int n, a[1001], b[1001];   vector<int> v;   int main() {     scanf( %d , &n);     for (int i = 0, b; i < n; ++i) cin >> a[i];     for (int i = n - 1; i >= 0; --i) {       if (!b[a[i]]) {         b[a[i]] = 1;         v.push_back(a[i]);       }     }     cout << v.size() << endl;     for (int i = v.size() - 1; i >= 0; --i) {       cout << v[i] <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int oo = numeric_limits<int>::max();   const int n_oo = numeric_limits<int>::min();   const int ALF = 26;   struct SuffixAutomaton {     int toInt(char c) { return c -  a ; }     char toChar(int j) { return char(j +  a ); }     struct Nodo {       vector<int> hijos;       int r;       int l;       int sl;       Nodo(int L = 0) : hijos(ALF, -1), l(L), sl(0), r(1) {}       int& operator[](int idx) { return hijos[idx]; }     };     vector<int> orden;     vector<long long int> seen;     int n, ult;     vector<Nodo> t;     void extender(char c) {       int act = n++;       t.push_back(Nodo(t[ult].l + 1));       int p = ult;       while (~p && t[p][toInt(c)] == -1) {         t[p][toInt(c)] = act;         p = t[p].sl;       }       if (~p) {         int q = t[p][toInt(c)];         if (t[q].l == t[p].l + 1) {           t[act].sl = q;         } else {           int clon = n++;           t.push_back(t[q]);           t[clon].l = t[p].l + 1;           t[clon].r = 0;           t[q].sl = t[act].sl = clon;           while (~p && t[p][toInt(c)] == q) {             t[p][toInt(c)] = clon;             p = t[p].sl;           }         }       }       ult = act;     }     SuffixAutomaton(string s =   ) : n(1), ult(0), t(1) {       t[0].sl = -1;       for (int i = 0; i < s.size(); i++) extender(s[i]);     }     void rTopoSort() {       int m = t[ult].l;       vector<vector<int> > bks(m + 1);       for (int i = 0; i < n; i++) bks[t[i].l].push_back(i);       for (int i = m; i >= 0; i--)         for (int j = 0; j < bks[i].size(); j++) orden.push_back(bks[i][j]);     }     void cuentaRepeticiones() {       rTopoSort();       for (int i = 0; i < n - 1; i++) {         int u = orden[i];         int v = t[u].sl;         t[v].r += t[u].r;       }       t[0].r = 1;     }     long long int dfs(int u) {       if (seen[u]) return seen[u];       long long int& ret = seen[u];       ret = t[u].r;       for (int i = 0; i < ALF; i++) {         if (t[u][i] == -1) continue;         ret += dfs(t[u][i]);       }       return ret;     }     void cuentaCaminos() {       seen = vector<long long int>(n);       dfs(0);     }     string kth(long long int k) {       int u = 0;       k++;       string ans;       if (k > seen[0]) return  No such line. ;       while (true) {         k -= t[u].r;         if (k <= 0) return ans;         for (int i = 0; i < ALF; i++) {           if (t[u][i] == -1) continue;           if (k > seen[t[u][i]])             k -= seen[t[u][i]];           else {             ans.push_back(toChar(i)), u = t[u][i];             break;           }         }       }       return ans;     }     void imprime() {       for (int i = 0; i < n; i++) {         cout << i <<   n ;         cout <<  suffix link:   << t[i].sl <<   n ;         cout <<  length:   << t[i].l <<   n ;         cout <<  reps:  << t[i].r <<   n ;         for (int j = 0; j < ALF; j++) {           if (t[i][j] == -1) continue;           cout << toChar(j) <<  :   << t[i][j] <<    ;         }         cout <<   n ;         cout <<   n ;       }     }   };   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     string s;     cin >> s;     SuffixAutomaton SA(s);     SA.cuentaRepeticiones();     SA.cuentaCaminos();     int k;     cin >> k;     cout << SA.kth(k) <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   vector<int> x;   int ax[3];   int main() {     ax[0] = ax[1] = ax[2] = 0;     cin >> n;     for (int i = 0; i < n; ++i) {       string s;       cin >> s;       int cc = 0;       for (int i = 0; i < s.size(); ++i) cc += s[i] -  0 ;       x.push_back(cc % 3);       ax[cc % 3]++;     }     int res = ax[0] / 2 + min(ax[1], ax[2]);     cout << res;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = 998244353;   const long long N = 1e5 + 5;   vector<long long> vp;   long long n;   long long a[N];   long long binsearch(long long lo, long long hi, long long check) {     long long ans = -1;     while (hi >= lo) {       long long mid = (lo + hi) / 2;       if (a[mid] * check == n) {         return mid;       } else if (a[mid] * check < n) {         lo = mid + 1;       } else {         hi = mid - 1;       }     }     return ans;   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cin >> n;     for (long long i = 1; i * i <= n; i++) {       if (n % i == 0) {         vp.push_back(n / i);         if (n / i != i) vp.push_back(i);       }     }     sort(vp.begin(), vp.end());     for (long long i = 1; i <= vp.size(); i++) {       a[i] = vp[i - 1];     }     long long mx = 0;     long long mn = 1e18;     for (long long i = 0; i < vp.size(); i++) {       for (long long j = 0; j < vp.size(); j++) {         long long k = binsearch(1, vp.size(), vp[i] * vp[j]);         if (k != -1) {           k--;           if (vp[i] * vp[j] * vp[k] == n) {             mn = min(mn, (vp[i] + 1) * (vp[j] + 2) * (vp[k] + 2) - n);             mn = min(mn, (vp[i] + 2) * (vp[j] + 2) * (vp[k] + 1) - n);             mn = min(mn, (vp[i] + 2) * (vp[j] + 1) * (vp[k] + 2) - n);             mx = max(mx, (vp[i] + 1) * (vp[j] + 2) * (vp[k] + 2) - n);             mx = max(mx, (vp[i] + 2) * (vp[j] + 2) * (vp[k] + 1) - n);             mx = max(mx, (vp[i] + 2) * (vp[j] + 1) * (vp[k] + 2) - n);           }         }       }     }     cout << mn <<     << mx <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   const long long int N = 100005;   bool powertwo(long long int n) { return (n and !(n & (n - 1))); }   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long int t;     cin >> t;     while (t--) {       long long int n;       cin >> n;       long long int arr[n];       map<long long int, long long int> mp;       for (long long int i = 0; i < n; i++) {         cin >> arr[i];         mp[arr[i]]++;       }       long long int g = 0, s = 0, b = 0;       vector<long long int> v;       for (auto it = mp.rbegin(); it != mp.rend(); it++) v.push_back(it->second);       g = v[0];       long long int i = 1;       while (s <= g and i < v.size()) {         s += v[i];         i++;       }       while (b <= g and i < v.size()) {         b += v[i];         i++;       }       while ((g + s + b + v[i]) <= n / 2 and i < v.size()) {         b += v[i];         i++;       }       if ((g + s + b) > n / 2 or s < g or b < g)         cout <<  0 0 0 n ;       else if (g == 0 or s == 0 or b == 0)         cout <<  0 0 0 n ;       else         cout << g <<     << s <<     << b <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct Point {     double x, y;     int num;     Point() {}     Point(double _x, double _y, int _num) : x(_x), y(_y), num(_num) {}     void read() { scanf( %lf%lf , &x, &y); }     double operator*(const Point &a) const { return x * a.y - a.x * y; }     Point operator-(const Point &a) const { return Point(x - a.x, y - a.y, num); }     bool operator<(const Point &a) const {       return y < a.y || y == a.y && x < a.x;     }     bool operator==(const Point &a) const { return x == a.x && y == a.y; }   } a[2000], s;   int sum = 0, cnt = 0, n, ans[2000], sz[2000];   int des[4000], nxt[4000], fst[2000];   int c[2000], nxtc[2000], fstc[2000];   bool vis[2000];   void add(int x, int y) { des[++sum] = y, nxt[sum] = fst[x], fst[x] = sum; }   void add2(int x, int y) { c[++cnt] = y, nxtc[cnt] = fstc[x], fstc[x] = cnt; }   void tree(int x) {     vis[x] = 1;     sz[x] = 1;     for (int i = fst[x]; i; i = nxt[i])       if (!vis[des[i]]) tree(des[i]), add2(x, des[i]), sz[x] += sz[des[i]];   }   double cross(Point a, Point b, Point c) { return (a - c) * (b - c); }   bool cmp(Point i, Point j) {     if (i == s) return 1;     if (j == s) return 0;     double y = cross(i, j, s);     if (y < 0) return 0;     return 1;   }   void solve(vector<Point> b, int fa) {     s = b[0];     for (int i = 1; i < b.size(); ++i)       if (b[i] < s) s = b[i];     sort(b.begin(), b.end(), cmp);     int l = 1;     ans[s.num] = fa;     for (int i = fstc[fa]; i; i = nxtc[i]) {       int k = c[i];       vector<Point> m;       for (int j = 1; j <= sz[k]; ++j) m.push_back(b[l]), l++;       solve(m, k);     }   }   int main() {     scanf( %d , &n);     for (int i = 1; i < n; ++i) {       int x, y;       scanf( %d%d , &x, &y);       add(x, y), add(y, x);     }     memset(vis, 0, sizeof vis);     tree(1);     vector<Point> b;     for (int i = 1; i <= n; ++i) a[i].read(), a[i].num = i, b.push_back(a[i]);     solve(b, 1);     for (int i = 1; i <= n; ++i) printf( %d  , ans[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     double a, b, c, d, e, f;     cin >> a >> b;     for (int i = 0; i < a; i++) {       cin >> c >> d;       e = c / d;       if (i > 0)         f = min(e, f);       else if (i == 0)         f = e;     }     printf( %.08f n , f * b);     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   const double PI = acos(-1.0);   const int INF = 1000 * 1000 * 1000 + 7;   const long long LINF = INF * (long long)INF;   const int L = 22;   int G[L];   int dp[1 << L];   int P[1 << L];   int M[1 << L];   int n;   void print(int mask) {     for (int i = (0); i < (n); i++) {       if (mask & (1 << i)) {         cout <<  1  ;         continue;       }       cout <<  0  ;     }     cout << endl;   }   bool isClik(int mask) {     for (int i = (0); i < (n); i++) {       if ((1 << i) & mask) {         mask ^= 1 << i;         if ((mask & G[i]) != mask) return false;         mask ^= 1 << i;       }     }     return true;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int m;     cin >> n >> m;     for (int i = (0); i < (m); i++) {       int a, b;       cin >> a >> b;       a--;       b--;       G[a] |= 1 << b;       G[b] |= 1 << a;     }     for (int mask = (0); mask < (1 << n); mask++) {       dp[mask] = INF;     }     for (int mask = (0); mask < (1 << n); mask++) {       if (isClik(mask)) {         dp[mask] = 0;       }     }     for (int mask = (0); mask < (1 << n); mask++) {       for (int k = (0); k < (n); k++) {         if (!(mask & (1 << k))) continue;         if (dp[mask | G[k]] > dp[mask] + 1) {           dp[mask | G[k]] = dp[mask] + 1;           P[mask | G[k]] = k;           M[mask | G[k]] = mask;         }         dp[mask | G[k]] = min(dp[mask | G[k]], dp[mask] + 1);       }     }     int ans = dp[(1 << n) - 1];     cout << ans << endl;     vector<int> res;     int mask = (1 << n) - 1;     for (int i = (0); i < (ans); i++) {       res.push_back(P[mask]);       mask = M[mask];     }     reverse(res.begin(), res.end());     for (int i = (0); i < ((int)res.size()); i++) {       cout << res[i] + 1 <<    ;     }     cout << endl;   }


#include <bits/stdc++.h>   using namespace std;   inline long long rd() {     long long x = 0;     int ch = getchar(), f = 1;     while (!isdigit(ch) && (ch !=  - ) && (ch != EOF)) ch = getchar();     if (ch ==  - ) {       f = -1;       ch = getchar();     }     while (isdigit(ch)) {       x = (x << 1) + (x << 3) + ch -  0 ;       ch = getchar();     }     return x * f;   }   inline void rt(long long x) {     if (x < 0) putchar( - ), x = -x;     if (x >= 10)       rt(x / 10), putchar(x % 10 +  0 );     else       putchar(x +  0 );   }   const int maxn = 5005, S = 100005;   int n, m, a[maxn], id[S], dsc[maxn];   short int f[maxn][maxn], g[maxn][maxn], h[maxn][7], ans;   void upd(short int &x, short int y) {     if (y > x) x = y;   }   int main() {     n = rd();     for (int i = int(1); i <= (int)(n); i++) a[i] = dsc[i] = rd();     sort(dsc + 1, dsc + n + 1);     m = unique(dsc + 1, dsc + n + 1) - dsc - 1;     for (int i = int(1); i <= (int)(m); i++) id[dsc[i]] = i;     for (int i = int(1); i <= (int)(n); i++) {       int x = id[a[i]];       for (int j = int(0); j <= (int)(i - 1); j++) {         if (x && dsc[x - 1] + 1 == a[i]) upd(f[j][i], g[j][x - 1] + 1);         if (x < m && dsc[x + 1] - 1 == a[i]) upd(f[j][i], g[j][x + 1] + 1);         upd(f[j][i], h[j][a[i] % 7] + 1);         if (j)           upd(h[i][a[j] % 7], f[j][i]), upd(g[i][id[a[j]]], f[j][i]);         else {           for (int k = int(0); k <= (int)(6); k++) upd(h[i][k], f[j][i]);           for (int k = int(1); k <= (int)(m); k++) upd(g[i][k], f[j][i]);         }         upd(g[j][id[a[i]]], f[j][i]), upd(h[j][a[i] % 7], f[j][i]);         upd(ans, f[j][i]);       }     }     rt(ans), putchar(  n );   }


#include <bits/stdc++.h>   using namespace std;   int a[1005], b[1005];   int main() {     int n;     string s, ss;     cin >> n >> s >> ss;     for (int i = 0; i < n; i++) {       a[i] = s[i] -  0 ;       b[i] = ss[i] -  0 ;     }     sort(a, a + n);     sort(b, b + n);     int sum1 = 0, sum2 = 0;     for (int i = 0, j = 0; i < n && j < n;) {       while (j < n) {         if (a[i] <= b[j]) {           i++;           j++;           sum1++;           break;         } else {           j++;         }       }     }     int sum = n - sum1;     cout << sum << endl;     for (int i = 0, j = 0; i < n && j < n;) {       while (j < n) {         if (a[i] < b[j]) {           i++;           j++;           sum2++;           break;         } else {           j++;         }       }     }     cout << sum2;   }


#include<bits/stdc++.h>   #define endl   n    #define bug puts( aaa );   #define Case int t;scanf( %d ,&t);while(t--)   #define ios ios::sync_with_stdio(0),cin.tie(0);   using namespace std;   typedef long long ll;   typedef unsigned long long ull;   const double eps = 1e-5;   const int inf = 0x3f3f3f3f;   const int mod = 1e9+7;   const int N = 1e6+10;      int n,x,mi[N<<2],a[N];   unordered_map<int,int>mp;      struct node {    int x,y;   }e[N];         void pushup(int rt) {    mi[rt] = mp[e[mi[rt<<1]].y] > mp[e[mi[rt<<1|1]].y] ? mi[rt<<1|1] : mi[rt<<1];   }      void build(int l,int r,int rt) {    if(l==r) {     mi[rt] = 0;     return;    }    int mid = l+r>>1;    build(l,mid,rt<<1);    build(mid+1,r,rt<<1|1);    pushup(rt);   }      void update(int pos, int val, int l, int r, int rt) {    if(l==r) {     mi[rt] = mp[e[val].y] < mp[e[mi[rt]].y] ? val : mi[rt];     return;    }    int mid = l+r>>1;    if(pos <= mid) update(pos,val,l,mid,rt<<1);    else update(pos,val,mid+1,r,rt<<1|1);    pushup(rt);   }      int query(int L,int R,int l,int r,int rt) {    if(L<=l && r<=R) {     return mi[rt];    }    int mid = l+r>>1;    int lson = 0,rson = 0;    if(L <= mid) lson = query(L,R,l,mid,rt<<1);    if(R > mid) rson = query(L,R,mid+1,r,rt<<1|1);    return mp[e[lson].y] > mp[e[rson].y] ?rson:lson;   }      void run() {    mp.clear();    scanf( %d ,&n);    int x,y,range = 0,idx=0;    e[0].x = e[0].y = inf;    mp[inf] = inf;    for (int i=1;i<=n;i++) {     scanf( %d %d ,&e[i].x,&e[i].y);     a[++idx] = e[i].x;     a[++idx] = e[i].y;        /**      * 如果不交换,只符合hj<hi && wj<wi的情况      * 首先按把w和h大的那个，放在x位置      * 那么我们去找[1,x-1]区间，里面的x肯定满足条件      * 接着在这个区间中去找符合条件的y,      */     if(e[i].x > e[i].y) swap(e[i].x,e[i].y);    }       /**     * 离散化     */    sort(a+1,a+idx+1);    for (int i=1;i<=idx;i++) {     if(mp[a[i]])continue;     mp[a[i]] = ++range;    }             build(1,range,1);    for (int i=1;i<=n;i++) {     update(mp[e[i].x],i,1,range,1);    }    for (int i=1;i<=n;i++) {     if(mp[e[i].x] == 1) {      printf( -1  );      continue;     }     int res = query(1,mp[e[i].x]-1,1,range,1);     if (e[res].y >= e[i].y) {      printf( -1  );     } else {      printf( %d  ,res);     }    }    printf(  n );   }         int main() {    // freopen( input.txt , r ,stdin);    // freopen( output.txt , w ,stdout);    Case    run();    return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int64_t N = 1e5 + 1;   int64_t crt_node = 0, maxi = 0;   vector<int64_t> previous;   vector<vector<int64_t>> adj;   void dfs(int64_t node, int64_t pere, int64_t len) {     previous[node] = pere;     if (len > maxi) {       crt_node = node;       maxi = len;     }     for (int64_t i : adj[node]) {       if (i != pere) dfs(i, node, len + 1);     }   }   bool ok = true;   vector<int64_t> level, path;   void hedgehog(int64_t node, int64_t pere) {     int64_t k = 0;     for (int64_t i : adj[node]) {       if (i != pere) {         hedgehog(i, node);         if (k == 0)           k = level[i];         else if (k != level[i])           ok = false;       }     }     if (adj[node].size() == 1)       level[node] = 1;     else if (adj[node].size() < 3 or              (adj[node].size() == 3 and path[path.size() / 2] != node))       ok = false;     else       level[node] = k + 1;   }   int32_t main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     int64_t n, k;     cin >> n >> k;     if (n == 1) {       cout <<  No ;       return 0;     }     adj.resize(n + 1);     for (int64_t i = 1; i < n; ++i) {       int64_t u, v;       cin >> u >> v;       adj[u].emplace_back(v);       adj[v].emplace_back(u);     }     previous.resize(n + 1);     dfs(1, 0, 0);     int64_t a = crt_node;     maxi = 0;     fill(previous.begin(), previous.end(), 0ll);     dfs(crt_node, 0, 0);     int64_t b = crt_node;     while (b) {       path.emplace_back(b);       b = previous[b];     }     level.resize(n + 1);     hedgehog(path[path.size() / 2], 0);     if (level[path[path.size() / 2]] != k + 1) ok = false;     cout << (ok ?  Yes  :  No );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MN = 111;   int a[MN], n, g[MN][MN], c[MN];   struct Block {     int f[MN][MN];     void cal1() {       memset(f, 0, sizeof f);       for (int from = (1), _b = (100); from <= _b; from++) {         for (int to = (from), _b = (100); to <= _b; to++) f[from][to] = 0;         memset(g, 0, sizeof g);         for (int i = (1), _b = (n); i <= _b; i++) {           for (int to = (from), _b = (100); to <= _b; to++)             g[i][to] = g[i - 1][to];           if (a[i] >= from) {             g[i][a[i]] = max(g[i][a[i]], 1);             for (int prev = (from), _b = (a[i]); prev <= _b; prev++)               g[i][a[i]] = max(g[i][a[i]], g[i - 1][prev] + 1);           }         }         for (int to = (from), _b = (100); to <= _b; to++) f[from][to] = g[n][to];       }     }     void print() {       for (int from = (1), _b = (4); from <= _b; from++) {         for (int to = (1), _b = (4); to <= _b; to++) cout << f[from][to] <<    ;         cout << endl;       }       cout <<  ----  << endl;     }   } f[30], trans;   Block operator+(const Block& a, const Block& b) {     Block res;     memset(res.f, 0, sizeof res.f);     for (int from = (1), _b = (100); from <= _b; from++) {       for (int to = (1), _b = (100); to <= _b; to++) {         res.f[from][to] = a.f[from][to];         for (int mid = (from), _b = (to); mid <= _b; mid++)           res.f[from][to] = max(res.f[from][to], a.f[from][mid] + b.f[mid][to]);       }     }     return res;   }   void RR() {     for (int i = (1), _b = (n); i <= _b; i++) c[i] = a[i];     sort(c + 1, c + n + 1);     int sc = unique(c + 1, c + n + 1) - c - 1;     for (int i = (1), _b = (n); i <= _b; i++)       a[i] = lower_bound(c + 1, c + n + 1, a[i]) - c;   }   int main() {     ios ::sync_with_stdio(false);     int T;     while (cin >> n >> T) {       for (int i = (1), _b = (n); i <= _b; i++) cin >> a[i];       RR();       f[0].cal1();       for (int i = (1), _b = (23); i <= _b; i++) f[i] = f[i - 1] + f[i - 1];       bool first = true;       for (int bit = 0, _a = (24); bit < _a; bit++)         if ((T >> bit) & 1) {           if (first) {             first = false;             trans = f[bit];           } else             trans = trans + f[bit];         }       int res = 0;       for (int from = (1), _b = (100); from <= _b; from++)         for (int to = (from), _b = (100); to <= _b; to++) {           res = max(res, trans.f[from][to]);           if (res == 8) {             cout << from <<     << to << endl;             assert(0);           }         }       cout << res << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 300 + 10;   const int maxm = maxn * maxn;   const int INF = 0x3f3f3f3f;   int connect[maxn][maxn], edgecnt[maxn];   int price[maxn], vis[maxn * 2], match[maxn * 2];   int n;   bool extend(int u) {     vis[u] = true;     for (int i = 1; i <= edgecnt[u]; i++) {       int v = connect[u][i] + n;       if (vis[v] || v == match[u]) continue;       vis[v] = true;       if (match[v] == 0 || extend(match[v])) {         match[u] = v;         match[v] = u;         return true;       }     }     return false;   }   void Match() {     memset(match, 0, sizeof(match));     for (int i = 1; i <= n; i++) {       if (match[i]) continue;       memset(vis, 0, sizeof(vis));       extend(i);     }     for (int i = 1; i <= 2 * n; i++) {     }   }   int S, T;   struct Edge {     Edge *n, *o;     int v, c, w;     void init(int _v, int _c, int _w) {       v = _v;       c = _c;       w = _w;     }   };   Edge *E[maxn * 2], Er[maxn * maxn * 2];   int Es = 0;   void addedge(int u, int v, int c, int w) {     static Edge *P1, *P2;     P1 = &Er[++Es];     P2 = &Er[++Es];     P1->init(v, c, w);     P1->n = E[u];     P1->o = P2;     E[u] = P1;     P2->init(u, 0, -w);     P2->n = E[v];     P2->o = P1;     E[v] = P2;   }   int H[maxn * 2];   bool V[maxn * 2];   bool BFS() {     static int Q[maxn * 20], bot, u, v;     memset(H, INF, sizeof(H));     memset(V, true, sizeof(V));     H[Q[bot = 1] = S] = 0;     V[S] = false;     for (int top = 1; top <= bot; top++) {       u = Q[top];       for (Edge *P = E[u]; P; P = P->n)         if (P->c && H[P->v] > H[u] + 1) {           H[P->v] = H[u] + 1;           if (V[P->v]) {             Q[++bot] = P->v;             V[P->v] = false;           }         }       V[u] = true;     }     return H[T] < INF;   }   int extend(int u, int lefts) {     if (u == T) {       return lefts;     }     V[u] = false;     int ret = 0, t;     for (Edge *P = E[u]; P && ret < lefts; P = P->n) {       if (P->c && V[P->v] && H[u] + 1 == H[P->v]) {         t = extend(P->v, min(lefts - ret, P->c));         ret += t;         P->c -= t;         P->o->c += t;       }     }     V[u] = true;     if (ret < lefts) H[u] = INF;     return ret;   }   int maxflow() {     int ret = 0, cnt = 0;     while (BFS()) {       ret += extend(S, INF);     }     return ret;   }   void build() {     memset(E, 0, sizeof(E));     for (int i = 1; i <= n; i++) {       if (price[i] >= 0) {         addedge(S, i, price[i], 1);       } else {         addedge(i, T, -price[i], 1);       }       for (int j = 1; j <= edgecnt[i]; j++) {         int t = match[connect[i][j] + n];         addedge(i, t, INF, 1);       }     }   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , &edgecnt[i]);       for (int j = 1; j <= edgecnt[i]; j++) {         scanf( %d , &connect[i][j]);       }     }     S = 0;     T = 2 * n + 1;     int ans = 0;     for (int i = 1; i <= n; i++) {       scanf( %d , price + i);       price[i] *= -1;       if (price[i] >= 0) ans += price[i];     }     Match();     build();     ans = maxflow() - ans;     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   int v[200010];   int c[200010];   int ans[200010];   string s;   priority_queue<pair<int, pair<int, int> > > pi, pe;   int main() {     memset(c, 0, sizeof c);     cin >> n;     for (int i = 0; i < n; ++i) {       cin >> v[i];       pi.push({0, {-v[i], i}});     }     string s;     cin >> s;     for (int i = 0; i < (int)s.size(); ++i) {       if (s[i] ==  0 ) {         int no = pi.top().first;         int wd = pi.top().second.first;         int id = pi.top().second.second;         pi.pop();         ans[i] = id;         pe.push({100, {-wd, id}});       } else {         int no = pe.top().first;         int wd = pe.top().second.first;         int id = pe.top().second.second;         pe.pop();         ans[i] = id;       }     }     for (int i = 0; i < (int)s.size(); ++i) cout << ans[i] + 1 <<    ;     cout <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char a[101];   int main() {     int n, i, l;     long long int ans = 0;     scanf( %s , a);     l = strlen(a);     for (i = 0; i < l; i++) {       if (a[i] ==  4 )         a[i] =  1 ;       else         a[i] =  2 ;     }     long long int c = 1;     for (i = l - 1; i >= 0; i--) {       ans = ans + c * (a[i] -  0 );       c = c * 2;     }     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   const int LEN = 8;   const int MASK = (1 << LEN);   const int maxn = 240;   double f[2][LEN + 1][MASK][2][maxn + 1];   int old, now;   double result;   int n, original;   double add1, time2;   void init() {     int P;     scanf( %d%d%d , &original, &n, &P);     time2 = P / 100.0;     add1 = 1 - time2;   }   int numlen(int x) {     int len = 0;     if (x == 0) return 1;     while (x) {       ++len;       x = (x >> 1);     }     return len;   }   int count0(int x) {     int g0 = 0;     while ((x > 0) && ((x & 1) == 0)) {       x = (x >> 1);       ++g0;     }     return g0;   }   int count1(int x) {     int g1 = 0;     while ((x > 0) && ((x & 1) == 1)) {       x = (x >> 1);       ++g1;     }     return g1;   }   inline void calc(int &d, int &plen, int nd, int &d2, int &plen2) {     if (nd == d) {       d2 = d;       plen2 = plen + 1;     } else {       d2 = nd;       plen2 = 1;     }   }   void work() {     int i, len, num, digit, prelen, tmp, len2, num2, digit2, prelen2;     now = 0;     for (len = 1; len <= LEN; ++len)       for (num = 0; num < (1 << len); ++num)         for (digit = 0; digit < 2; ++digit)           for (prelen = 0; prelen <= maxn; ++prelen)             f[now][len][num][digit][prelen] = 0;     if (numlen(original) <= LEN)       f[now][numlen(original)][original][0][0] = 1;     else {       tmp = original >> LEN;       if ((tmp & 1) == 0)         f[now][LEN][original & ((1 << LEN) - 1)][0][count0(tmp)] = 1;       else         f[now][LEN][original & ((1 << LEN) - 1)][1][count1(tmp)] = 1;     }     for (i = 1; i <= n; ++i) {       old = now;       now = 1 - now;       for (len = 1; len <= LEN; ++len)         for (num = 0; num < (1 << len); ++num)           for (digit = 0; digit < 2; ++digit)             for (prelen = 0; prelen <= maxn; ++prelen)               f[now][len][num][digit][prelen] = 0;       for (len = 1; len <= LEN; ++len)         for (num = 0; num < (1 << len); ++num)           for (digit = 0; digit < 2; ++digit)             for (prelen = 0; prelen <= maxn; ++prelen)               if (f[old][len][num][digit][prelen] > 1e-16) {                 len2 = len;                 num2 = num;                 digit2 = digit;                 prelen2 = prelen;                 if (len < LEN) {                   len2 = len + 1;                   num2 = num << 1;                 } else {                   if (num & (1 << (LEN - 1)))                     calc(digit, prelen, 1, digit2, prelen2);                   else                     calc(digit, prelen, 0, digit2, prelen2);                   num2 = ((num << 1) & ((1 << LEN) - 1));                 }                 f[now][len2][num2][digit2][prelen2] +=                     f[old][len][num][digit][prelen] * time2;                 len2 = len;                 num2 = num;                 digit2 = digit;                 prelen2 = prelen;                 if (num + 1 < (1 << len))                   num2 = num + 1;                 else {                   if (len < LEN) {                     num2 = num + 1;                     len2 = len + 1;                   } else {                     num2 = 0;                     if (digit == 0) {                       digit2 = 1;                       prelen2 = 1;                     } else {                       digit2 = 0;                       prelen2 = prelen;                     }                   }                 }                 f[now][len2][num2][digit2][prelen2] +=                     f[old][len][num][digit][prelen] * add1;               }     }   }   void output() {     int i, j, d, k;     int g0;     result = 0;     for (i = 1; i <= LEN; ++i)       for (j = 0; j < (1 << i); ++j)         for (d = 0; d < 2; ++d)           for (k = 0; k <= maxn; ++k) {             if (j == 0) {               g0 = i;               if (d == 0) g0 += k;             } else               g0 = count0(j);             result += f[now][i][j][d][k] * g0;           }     printf( %.10lf n , result);   }   int main() {     init();     work();     output();     return 0;   }


#include <bits/stdc++.h>   int dx[] = {0, 0, 1, -1, 1, -1, 1, -1};   int dy[] = {1, -1, 0, 0, -1, 1, 1, -1};   const double PI = acos(-1), EPS = 1e-7;   const int OO = 0x3f3f3f3f, N = 1e6 + 5, mod = 1e9 + 7;   using namespace std;   long long gcd(long long x, long long y) { return (!y) ? x : gcd(y, x % y); }   long long lcm(long long x, long long y) { return ((x / gcd(x, y)) * y); }   void file() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);   }   int n, red, blue, cnt;   vector<vector<int>> g;   vector<int> col;   pair<int, int> DFS(int v, int p = -1) {     int r = (col[v] == 1), b = (col[v] == 2);     for (auto u : g[v])       if (u != p) {         auto tmp = DFS(u, v);         cnt += (tmp.first == red && tmp.second == 0);         cnt += (tmp.first == 0 && tmp.second == blue);         r += tmp.first;         b += tmp.second;       }     return make_pair(r, b);   }   int main() {     file();     cin >> n;     g = vector<vector<int>>(n + 1);     col = vector<int>(n + 1);     for (int i = 1; i <= n; i++) {       cin >> col[i];       if (col[i] == 1) red++;       if (col[i] == 2) blue++;     }     n--;     while (n--) {       int a, b;       cin >> a >> b;       g[a].push_back(b);       g[b].push_back(a);     }     DFS(1, -1);     cout << cnt;   }


#include <bits/stdc++.h>   using namespace std;   int num[200000 + 5];   int main() {     int i, j, k, n, m;     cin >> n;     long long sum = 0;     for (i = 0; i < n; i++) {       cin >> num[i];       sum += num[i];     }     long long ans = 0;     sum++;     sum /= 2;     for (i = 0; i < n; i++) {       ans += num[i];       if (ans >= sum) {         cout << i + 1 << endl;         return 0;       }     }   }


#include <bits/stdc++.h>   using namespace std;   queue<int> d[110];   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       for (int j = (n / 2) * (i - 1) + 1, g = 1; g <= (n / 2); j++, g++) {         d[i].push(j);       }     }     for (int i = 1; i <= n; i++) {       for (int j = (n / 2) * (n + i - 1) + 1, g = 1; g <= (n / 2); j++, g++) {         d[n - i + 1].push(j);       }     }     for (int i = 1; i <= n; i++) {       while (!d[i].empty()) {         printf( %d  , d[i].front());         d[i].pop();       }       puts(  );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 3e5 + 10;   const int block = 450;   int n, p[maxn], l[maxn], cost[maxn], nxt[maxn], f[maxn], g[maxn], aft[maxn],       bit[maxn << 2];   void update(int pos, int x) {     for (; pos <= n; pos += (pos & -pos)) bit[pos] = max(bit[pos], x);   }   int get(int pos) {     int res = 0;     for (; pos > 0; pos -= (pos & -pos)) res = max(res, bit[pos]);     return res;   }   int main() {     cin >> n;     for (int i = 0; i < n; i++) scanf( %d%d , &p[i], &l[i]);     for (int i = n - 1; i > -1; i--) {       int pos = upper_bound(p, p + n, p[i] + l[i]) - p;       f[i] = max(get(pos), p[i] + l[i]);       update(i + 1, f[i]);       aft[i] = upper_bound(p, p + n, f[i]) - p;       if (i / block == (n - 1) / block) continue;       if (aft[i] / block > i / block) {         nxt[i] = aft[i];         g[i] = f[i];       } else {         nxt[i] = nxt[aft[i]];         g[i] = g[aft[i]];         cost[i] = cost[aft[i]] + p[aft[i]] - f[i];       }     }     int q;     cin >> q;     while (q--) {       int x, y;       scanf( %d%d , &x, &y);       x--, y--;       int ans = 0;       while (x / block < y / block && g[x] < p[y]) {         ans += cost[x] + p[nxt[x]] - g[x];         x = nxt[x];       }       if (x / block < y / block) {         ans += cost[x];         printf( %d n , ans);         continue;       }       while (f[x] < p[y]) {         ans += p[aft[x]] - f[x];         x = aft[x];       }       printf( %d n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<long long int> f(200005, 0), d(200005, 0), l(200005, 0), r(200005, -1);   map<pair<long long int, long long int>, long long int> mp;   long long int gcd(long long int a, long long int b) {     if (b == 0) return a;     return gcd(b, a % b);   }   long long int bpow(long long int a, long long int b) {     long long int res = 1;     while (b > 0) {       if (b & 1) res = (res * a) % 1000000007;       a = (a * a) % 1000000007;       b >>= 1;     }     return res % 1000000007;   }   void fact(long long int i) {     f[0] = 1;     for (long long int k = 1; k <= i; k++) {       (f[k] = f[k - 1] * k) %= 1000000007;     }   }   long long int isprime(long long int n) {     if (n == 1) return 0;     for (long long int i = 2; i <= sqrt(n); i++)       if (n % i == 0) return 0;     return 1;   }   long long int find(long long int x) {     if (f[x] == x)       return x;     else       return f[x] = find(f[x]);   }   bool cmp(long long int x, long long int y) { return x < y; }   long long int comb(long long int i, long long int j) {     long long int k = f[i];     long long int g = (f[j] * (f[i - j])) % 1000000007;     long long int h = bpow(g, 1000000007 - 2);     return (k * h) % 1000000007;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int n;     cin >> n;     vector<long long int> a(n);     for (long long int i = 0; i < n; i++) cin >> a[i];     long long int mx = 0;     for (long long int i = 0; i < n; i++) {       mx = max(mx, a[i]);     }     for (long long int i = 0; i < n; i++) {       long long int k = a[i], c = 0;       while (k > 0) {         f[k]++;         r[k] = i;         l[k] += (c);         long long int h = k, j = c;         while (h <= mx) {           h *= 2;           j++;           if (r[h] != i) {             f[h]++;             r[h] = i;             l[h] += j;           } else             break;         }         k /= 2;         c++;       }     }     long long int ans = 1e18;     for (long long int i = 1; i <= 100000; i++) {       if (f[i] == n) {         ans = min(ans, l[i]);       }     }     cout << ans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> out[1000];   int main() {     int n;     scanf( %d , &n);     int ans;     for (int i = 1; i * (i - 1) / 2 <= n; i++) {       ans = i;     }     int id = 1;     for (int i = 0; i < ans; i++) {       for (int j = i + 1; j < ans; j++) {         out[i].push_back(id);         out[j].push_back(id);         id++;       }     }     printf( %d n , ans);     for (int i = 0; i < ans; i++, puts(  ))       for (int j = 0; j < out[i].size(); j++) printf( %d  , out[i][j]);     return 0;   }


#include <bits/stdc++.h>   namespace IO {   const long long IN_LEN = 1 << 18 | 1;   static char buf[IN_LEN], *s, *t;   inline long long Getchar(void) {     return s == t && (t = (s = buf) + fread(buf, 1, IN_LEN, stdin)),            s == t ? -1 : *s++;   }   template <class T>   inline void read(T& x) {     static long long c, f;     c = Getchar(), x = f = 0;     while (c <  0  || c >  9 ) {       if (c ==  - ) f = 1;       c = Getchar();     }     while (c <=  9  && c >=  0 ) x = x * 10 + c - 48, c = Getchar();     x = f ? -x : x;   }   }  // namespace IO   using IO::read;   using namespace std;   const long long N = 1e5 + 5;   const long long INF = 0x3f3f3f3f3f3f3f3fLL;   long long head[N], eidx, dis[N], n, m, f[N];   struct Edge {     long long nxt, to, val;   } edge[N];   queue<long long> q[N];   priority_queue<pair<long long, long long>, vector<pair<long long, long long> >,                  greater<pair<long long, long long> > >       Q;   void dij(void) {     static long long u, w;     memset(dis, 0x3f, sizeof dis);     Q.push(pair<long long, long long>(dis[1] = 0, 1));     while (!Q.empty()) {       u = Q.top().second, w = Q.top().first;       Q.pop();       if (dis[u] != w) continue;       for (long long i = head[u], v; i; i = edge[i].nxt)         if (dis[v = edge[i].to] > dis[u] + edge[i].val)           Q.push(pair<long long, long long>(dis[v] = dis[u] + edge[i].val, v));     }   }   void bfs(const long long& lim) {     static long long u, mx;     mx = 0;     memset(f, 0x3f, sizeof f);     q[0].push(1), f[1] = 0;     for (long long c = 0; c <= mx; ++c) {       while (!q[c].empty()) {         u = q[c].front();         q[c].pop();         if (f[u] < c) continue;         for (long long i = head[u], v; i; i = edge[i].nxt)           if (f[(v = edge[i].to)] > dis[u] - dis[v] + edge[i].val + f[u]) {             f[v] = dis[u] - dis[v] + edge[i].val + f[u];             if (f[v] <= lim && f[v] < n - 1) q[f[v]].push(v), mx = max(mx, f[v]);           }       }     }   }   signed main(void) {     long long q;     read(n), read(m), read(q);     for (long long i = 1, u, v, w; i <= m; ++i) {       read(u), read(v), read(w);       edge[++eidx] = (Edge){head[u], v, w};       head[u] = eidx;     }     dij();     long long opt, x, y;     while (q--) {       read(opt), read(x);       if (opt == 1)         printf(dis[x] == INF ?  -1 n  :  %lld n , dis[x]);       else {         for (long long i = 1; i <= x; ++i) {           read(y);           ++edge[y].val;         }         bfs(x);         for (long long i = 1; i <= n; ++i) dis[i] = min(INF, dis[i] + f[i]);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, n, j, temp, num;     stringstream s, t;     cin >> a >> b >> n;     string out;     s << a;     num = a;     for (j = 0; j < 10; j++) {       s << j;       s >> temp;       if (temp % b == 0) {         num = temp;         s.clear();         s << num;         break;       } else {         s.clear();         s << num;       }     }     if (j == 10)       cout << -1;     else {       for (int i = 0; i < n - 1; i++) s <<  0 ;       s >> out;       cout << out;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int p[1000001];   int main() {     int n, ind = 0, w, input;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> input;       p[input]++;       if (ind < p[input]) {         ind = p[input];         w = input;       }     }     cout << w << endl;   }


#include <bits/stdc++.h>   using namespace std;   long long calc_gcd(long long a, long long b) {     while (true)       if (a)         b %= a, swap(a, b);       else         return b;   }   void foo() {     long long A, M;     cin >> A >> M;     long long gcd = calc_gcd(A, M);     A /= gcd;     M /= gcd;     set<long long> yakusuu;     long long tmp = M;     while (tmp % 2 == 0) {       yakusuu.insert(2);       tmp /= 2;     }     for (long long i = 3; i * i <= M; i += 2) {       while (tmp % i == 0) {         yakusuu.insert(i);         tmp /= i;       }     }     if (tmp > 1) {       yakusuu.insert(tmp);       tmp = 1;     }     vector<long long> yakusuu_vec;     for (auto it : yakusuu) yakusuu_vec.push_back(it);     long long limit = 1;     limit <<= yakusuu_vec.size();     long long foo = 0;     long long bar = 0;     for (long long i = 0; i < limit; i++) {       long long tmp = 1;       long long count = 0;       for (long long k = 0; k < (yakusuu_vec.size()); k++) {         if (((i >> k) & 1) == 1) {           tmp *= yakusuu_vec[k];           count++;         }       }       if (count % 2) {         foo -= (A + M - 1) / tmp;         bar -= (A - 1) / tmp;       } else {         foo += (A + M - 1) / tmp;         bar += (A - 1) / tmp;       }     }     cout << (foo - bar) << endl;   }   void solve() {     long long T;     cin >> T;     for (long long t = 0; t < (T); t++) foo();   }   int main(void) {     cin.tie(0);     ios::sync_with_stdio(false);     cout.precision(12);     cout << fixed;     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int fib[51];   vector<long long int> calc(long long int n, long long int k) {     vector<long long int> res;     if (!n) return res;     if (n == 1) {       res.push_back(1);       return res;     }     if (k <= fib[n - 1]) {       res.push_back(1);       vector<long long int> v = calc(n - 1, k);       for (auto i : v) res.push_back(i + 1);     } else {       res.push_back(2);       res.push_back(1);       vector<long long int> v = calc(n - 2, k - fib[n - 1]);       for (auto i : v) res.push_back(i + 2);     }     return res;   }   void solve() {     fib[1] = 1, fib[2] = 2;     for (long long int i = 3; i <= 50; i++) fib[i] = fib[i - 1] + fib[i - 2];     long long int n, k;     cin >> n >> k;     vector<long long int> ans = calc(n, k);     for (auto i : ans) cout << i <<    ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     cout.precision(20);     long long int t = 1;     for (long long int i = 1; i <= t; i++) {       if (0) cout <<  Case #  << i <<  :  ;       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   void pv(T a, T b) {     for (T i = a; i != b; ++i) cout << *i <<    ;     cout << endl;   }   template <class T>   void chmin(T &t, T f) {     if (t > f) t = f;   }   template <class T>   void chmax(T &t, T f) {     if (t < f) t = f;   }   int in() {     int x;     scanf( %d , &x);     return x;   }   int N;   long long T[10010], C[10010];   int main() {     int i;     for (; ~scanf( %d , &N);) {       for (i = 0; i < N; ++i) {         T[i] = in();         C[i] = in();       }       long long ans = 0;       long long t = 0;       for (i = 0; i < N; ++i) {         if (t <= T[i]) {           chmax(ans, C[i]);           t = T[i] + C[i];         } else {           chmax(ans, (t - T[i]) + C[i]);           t += C[i];         }       }       cout << t <<     << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, k, a[100009], dau, cuoi, d[100009], c[100009], Res;   string st;   void Input() {     cin >> n >> k >> st;     for (int i = 0; i < n; ++i) {       a[i + 1] = st[i] -  a ;     }   }   void Solve() {     dau = 1;     cuoi = 1;     d[0] = 0;     c[0] = 0;     while (cuoi <= n) {       if (a[cuoi] == 0) {         d[cuoi] = d[cuoi - 1] + 1;         c[cuoi] = c[cuoi - 1];       } else {         if (c[cuoi - 1] + 1 <= k) {           d[cuoi] = d[cuoi - 1] + 1;           c[cuoi] = c[cuoi - 1] + 1;         } else {           c[cuoi] = c[cuoi - 1] + 1;           d[cuoi] = d[cuoi - 1] + 1;           while (dau <= cuoi) {             if (c[cuoi] > k) {               if (a[dau] == 1) {                 c[cuoi]--;               }               dau++;               d[cuoi]--;             } else               break;           }         }       }       Res = max(Res, d[cuoi]);       cuoi++;     }     dau = 1;     cuoi = 1;     d[0] = 0;     c[0] = 0;     while (cuoi <= n) {       if (a[cuoi] == 1) {         d[cuoi] = d[cuoi - 1] + 1;         c[cuoi] = c[cuoi - 1];       } else {         if (c[cuoi - 1] + 1 <= k) {           d[cuoi] = d[cuoi - 1] + 1;           c[cuoi] = c[cuoi - 1] + 1;         } else {           c[cuoi] = c[cuoi - 1] + 1;           d[cuoi] = d[cuoi - 1] + 1;           while (dau <= cuoi) {             if (c[cuoi] > k) {               if (a[dau] == 0) {                 c[cuoi]--;               }               dau++;               d[cuoi]--;             } else               break;           }         }       }       Res = max(Res, d[cuoi]);       cuoi++;     }     cout << Res;   }   int main() {     Input();     Solve();   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n, m;     cin >> n >> m;     int c[n], w[m];     for (int i = 0; i < n; i++) cin >> c[i];     for (int i = 0; i < m; i++) cin >> w[i];     int res = 0;     int j = 0;     for (int i = 0; i < n; i++) {       if (j > m - 1) {         break;       }       if (w[j] >= c[i]) {         res++;         j++;       }     }     cout << res <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   const int dr[] = {0, -1, 0, 1, -1, 1, 1, -1};   const int dc[] = {1, 0, -1, 0, 1, 1, -1, -1};   const double eps = 1e-9;   template <class T>   void print(const vector<T> &v) {     ostringstream os;     for (int i = 0; i < (int)v.size(); ++i) {       if (i) os <<    ;       os << v[i];     }     cout << os.str() << endl;   }   template <class T>   int sz(const T &c) {     return (int)c.size();   }   template <class T>   void srt(T &c) {     sort(c.begin(), c.end());   }   template <class T>   void checkmin(T &a, T b) {     if (b < a) a = b;   }   template <class T>   void checkmax(T &a, T b) {     if (b > a) a = b;   }   template <class T>   T sqr(T x) {     return x * x;   }   template <class T, class U>   T cast(U x) {     ostringstream os;     os << x;     T res;     istringstream is(os.str());     is >> res;     return res;   }   template <class T>   vector<T> split(string s, string x =    ) {     vector<T> res;     for (int i = 0; i < s.size(); i++) {       string a;       while (i < (int)s.size() && x.find(s[i]) == string::npos) a += s[i++];       if (!a.empty()) res.push_back(cast<T>(a));     }     return res;   }   template <class T>   bool inside(T r, T c, T R, T C) {     return r >= 0 && r < R && c >= 0 && c < C;   }   struct item {     int prio;     int pos;     bool operator<(const item &o) const { return prio > o.prio; }   };   void dfs(vector<vector<pair<int, int> > > &g, int u, int p,            vector<priority_queue<item> > &h) {     for (int i(0), _b(sz(g[u]) - 1); i <= _b; ++i) {       int v = g[u][i].first;       if (v == p) continue;       int c = g[u][i].second;       while (c > 0 && !h[v].empty()) {         h[u].push(h[v].top());         h[v].pop();         --c;       }       dfs(g, v, u, h);     }   }   int main(int argc, char *argv[]) {     int n;     cin >> n;     vector<priority_queue<item> > h(n);     vector<int> a(n);     for (int i(0), _n(n); i < _n; ++i) {       cin >> a[i];       item e = {a[i], i};       h[i].push(e);     }     vector<vector<pair<int, int> > > g(n);     for (int i(0), _n(n - 1); i < _n; ++i) {       int u, v, c;       cin >> u >> v >> c;       --u;       --v;       g[u].push_back(make_pair(v, c));       g[v].push_back(make_pair(u, c));     }     vector<int> res(n);     int t = 0;     int cnt = 0;     while (1) {       while (!h[0].empty()) {         item e = h[0].top();         h[0].pop();         res[e.pos] = t;         ++cnt;         if (cnt == n) goto m1;       }       dfs(g, 0, -1, h);       ++t;     }   m1:     print(res);     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   #pragma GCC target( sse4 )   using namespace std;   using ll = long long;   using db = long double;   using str = string;   using pi = pair<int, int>;   using pl = pair<ll, ll>;   using pd = pair<db, db>;   using vi = vector<int>;   using vb = vector<bool>;   using vl = vector<ll>;   using vd = vector<db>;   using vs = vector<str>;   using vpi = vector<pi>;   using vpl = vector<pl>;   using vpd = vector<pd>;   template <class T>   using V = vector<T>;   template <class T>   using PR = pair<T, T>;   template <class T, size_t SZ>   using AR = array<T, SZ>;   template <class T>   using pqg = priority_queue<T, vector<T>, greater<T>>;   const int MX = 2e5 + 5;   const int MOD = 1e9 + 7;   const ll INF = 1e18;   const db PI = acos((db)-1);   const int xdir[4] = {1, 0, -1, 0}, ydir[4] = {0, 1, 0, -1};   mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());   constexpr int pct(int x) { return __builtin_popcount(x); }   constexpr int bits(int x) { return x == 0 ? 0 : 31 - __builtin_clz(x); }   ll cdiv(ll a, ll b) { return a / b + ((a ^ b) > 0 && a % b); }   ll fdiv(ll a, ll b) { return a / b - ((a ^ b) < 0 && a % b); }   template <class T>   bool ckmin(T& a, const T& b) {     return b < a ? a = b, 1 : 0;   }   template <class T>   bool ckmax(T& a, const T& b) {     return a < b ? a = b, 1 : 0;   }   template <class T, class U>   T fstTrue(T lo, T hi, U first) {     hi++;     assert(lo <= hi);     while (lo < hi) {       T mid = lo + (hi - lo) / 2;       first(mid) ? hi = mid : lo = mid + 1;     }     return lo;   }   template <class T, class U>   T lstTrue(T lo, T hi, U first) {     lo--;     assert(lo <= hi);     while (lo < hi) {       T mid = lo + (hi - lo + 1) / 2;       first(mid) ? lo = mid : hi = mid - 1;     }     return lo;   }   template <class T>   void remDup(V<T>& v) {     sort(begin(v), end(v));     v.erase(unique(begin(v), end(v)), end(v));   }   template <typename T1, typename T2>   str to_string(pair<T1, T2> p);   template <typename T1, typename T2, typename T3>   str to_string(tuple<T1, T2, T3> p);   template <typename T1, typename T2, typename T3, typename T4>   str to_string(tuple<T1, T2, T3, T4> p);   str to_string(const str& S) { return     + S +    ; }   str to_string(const char* S) { return to_string((str)S); }   str to_string(bool b) { return b ?  true  :  false ; }   template <class T>   str to_string(complex<T> c) {     stringstream ss;     ss << c;     return ss.str();   }   template <size_t SZ>   str to_string(bitset<SZ> v) {     str res =   ;     for (int i = (0); i < (SZ); ++i) res += char(v[i] +  0 );     return res;   }   template <typename T>   str to_string(T v) {     bool fst = 1;     str res =   ;     for (const auto& x : v) {       if (!fst) res +=    ;       fst = 0;       res += to_string(x);     }     return res;   }   template <typename T1, typename T2>   str to_string(pair<T1, T2> p) {     return  (  + to_string(p.first) +  ,   + to_string(p.second) +  ) ;   }   void DBG() { cerr << endl; }   template <typename Head, typename... Tail>   void DBG(Head H, Tail... T) {     cerr <<     << to_string(H);     DBG(T...);   }   void setPrec() { cout << fixed << setprecision(15); }   void unsyncIO() { cin.tie(0)->sync_with_stdio(0); }   void setIn(str name) { freopen(name.c_str(),  r , stdin); }   void setOut(str name) { freopen(name.c_str(),  w , stdout); }   void setIO(str name =   ) {     unsyncIO();     setPrec();     if ((int)((name).size())) setIn(name +  .in ), setOut(name +  .out );   }   struct node {     ll prefix, suffix, sum, msum;     node() { prefix = suffix = sum = msum = 0LL; }     node(ll value) {       sum = value;       prefix = suffix = sum = msum = max(0LL, value);     }   };   node operator+(node a, node b) {     node res;     res.sum = a.sum + b.sum;     res.prefix = max(a.prefix, a.sum + b.prefix);     res.suffix = max(b.suffix, a.suffix + b.sum);     res.msum = max({a.msum, b.msum, a.suffix + b.prefix});     return res;   }   template <class T>   struct Seg {     const T ID = T();     T comb(T a, T b) { return a + b; }     int N;     vector<T> seg;     void init(int _N) {       N = _N;       seg.assign(2 * N, ID);     }     void pull(int p) { seg[p] = comb(seg[2 * p], seg[2 * p + 1]); }     void upd(int p, T val) {       seg[p += N] = val;       for (p /= 2; p; p /= 2) pull(p);     }     T query(int l, int r) {       T ra = ID, rb = ID;       for (l += N, r += N + 1; l < r; l /= 2, r /= 2) {         if (l & 1) ra = comb(ra, seg[l++]);         if (r & 1) rb = comb(seg[--r], rb);       }       return comb(ra, rb);     }   };   Seg<node> ST;   int SZ(int n) {     int sz = 0;     while ((1 << sz) < n) sz++;     return 1 << sz;   }   int32_t main() {     setIO();     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       vi arr(n);       for (auto& x : arr) cin >> x, --x;       vi p(n);       for (int i = (0); i < (n); ++i) p[arr[i]] = i;       ST.init(SZ(n));       vb marked(n, false);       bool res = true;       int lst = n - 1, fst = 0;       for (int i = (0); i < (n); ++i) {         while (marked[lst]) --lst;         ll csc = ST.query(fst, lst).msum + 1;         auto can = [&](int x) { return ST.query(x, p[i]).sum == p[i] - x; };         ll sum = p[i] - fstTrue(0, p[i], can) + 1;         if (sum != csc) {           res = false;           break;         }         ST.upd(p[i], 1);         marked[p[i]] = 1;       }       cout << (res ?  Yes n  :  No n );     }   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 5000;   const int MOD = 1000000007;   string mx[MAXN];   int dp[MAXN][MAXN];   int m, n;   void mainp() {     cin >> n >> m;     for (int i = 0; i < n; i++) cin >> mx[i];     for (int i = 0; i < n; i++)       for (int j = m - 1; j >= 0; j--) {         if (j == m - 1)           dp[i][j] = mx[i][j] ==  1  ? 1 : 0;         else {           if (mx[i][j] ==  1 )             dp[i][j] = 1 + dp[i][j + 1];           else             dp[i][j] = 0;         }       }     int ans = 0;     for (int j = 0; j < m; j++) {       int temp[MAXN];       for (int i = 0; i < n; i++) temp[i] = dp[i][j];       sort(temp, temp + n);       for (int i = 0; i < n; i++)         if (temp[i] * (n - i) > ans) ans = temp[i] * (n - i);     }     cout << ans <<   n ;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     mainp();     return 0;   }