#include <bits/stdc++.h>   void err() { std::cout <<   n ; }   template <typename T, typename... Args>   void err(T a, Args... args) {     std::cout << a <<    ;     err(args...);   }   void pt() { std::cout <<   n ; }   template <typename T, typename... Args>   void pt(T a, Args... args) {     std::cout << a <<    ;     pt(args...);   }   using namespace std;   const int N = 5000 + 5, MOD = 1e9 + 7;   int qpow(long long a, long long b) {     long long res = 1;     while (b) {       if (b & 1) res = res * a % MOD;       a = a * a % MOD;       b >>= 1;     }     return res;   }   int inv(int x) { return qpow(x, MOD - 2); }   int n, m;   int a[N];   int f[N], h[N];   int x[N], y[N];   int l[N], r[N];   vector<int> v[N];   void run() {     cin >> n >> m;     for (int i = 1; i <= n; i++) {       cin >> a[i];       ++r[a[i]];     }     for (int i = 1; i <= m; i++) {       cin >> f[i] >> h[i];       v[f[i]].push_back(h[i]);     }     for (int i = 1; i <= n; i++) sort((v[i]).begin(), (v[i]).end());     pair<int, int> ans(0, 0);     auto upd = [&](int x, int y) {       if (x > ans.first) ans = make_pair(x, 0);       if (x == ans.first) ans.second = (ans.second + y) % MOD;     };     auto calc = [&](int i) {       int a = upper_bound((v[i]).begin(), (v[i]).end(), l[i]) - v[i].begin();       int b = upper_bound((v[i]).begin(), (v[i]).end(), r[i]) - v[i].begin();       if (a > b) swap(a, b);       int cnt1 = 1ll * a * (b - 1) % MOD, cnt2 = a + b;       if (cnt1 > 0) {         x[i] = 2;         y[i] = cnt1;       } else if (cnt2 > 0) {         x[i] = 1;         y[i] = cnt2;       } else {         x[i] = 0;         y[i] = 1;       }     };     int tx = 0, ty = 1;     for (int i = 1; i <= n; i++) {       calc(i);       tx += x[i];       ty = 1ll * ty * y[i] % MOD;     }     upd(tx, ty);     for (int i = 1; i <= n; i++) {       int now = a[i];       tx -= x[now];       ty = 1ll * ty * inv(y[now]) % MOD;       ++l[now], --r[now];       if (binary_search((v[now]).begin(), (v[now]).end(), l[now])) {         int t = upper_bound((v[now]).begin(), (v[now]).end(), r[now]) -                 v[now].begin();         if (r[now] >= l[now]) --t;         if (t > 0) {           x[now] = 2;           y[now] = t;         } else {           x[now] = y[now] = 1;         }         int nx = tx + x[now], ny = 1ll * ty * y[now] % MOD;         upd(nx, ny);       }       calc(now);       tx += x[now];       ty = 1ll * ty * y[now] % MOD;     }     cout << ans.first <<     << ans.second <<   n ;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cout << fixed << setprecision(20);     run();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2 * 1e6;   int a[N];   int main() {     std::ios::sync_with_stdio(false);     int n;     cin >> n;     for (int i = 0; i < n; ++i) {       int tmp;       cin >> tmp;       a[tmp]++;     }     int res = 0;     for (int i = 0; i < N; ++i) {       if (a[i] % 2) ++res;       a[i + 1] += (a[i] / 2);     }     cout << res << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     vector<int> a(n);     int even = 0, odd = 0;     for (int i = 0; i < n; i++) {       cin >> a[i];       if (a[i] % 2 == 0) {         even++;       } else {         odd++;       }     }     if (even > odd) {       cout << odd << endl;     } else {       cout << even << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<pair<long long, long long>> a;   vector<long long> get_res(long long m) {     vector<long long> res;     for (long long i = 0; i < a.size(); ++i) {       long long el = a[i].second;       long long c = a[i].first;       long long t = 0;       while ((c / (t + 1)) >= m) {         t++;         res.push_back(el);       }     }     return res;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     long long n, k;     cin >> n >> k;     vector<long long> s(n);     for (long long i = 0; i < n; ++i) cin >> s[i];     vector<long long> cnt(2e5 + 10);     for (long long i = 0; i < n; ++i) cnt[s[i]]++;     vector<pair<long long, long long>> v;     for (long long i = 0; i < cnt.size(); ++i) v.emplace_back(cnt[i], i);     sort(v.begin(), v.end());     reverse(v.begin(), v.end());     for (long long i = 0; i < v.size(); ++i) {       if (v[i].first > 0) {         a.push_back(v[i]);       }     }     long long l = 1;     long long r = n + 1;     while (l + 1 < r) {       long long m = (l + r) / 2;       if (get_res(m).size() >= k)         l = m;       else         r = m;     }     auto res = get_res(l);     for (long long i = 0; i < k; ++i) cout << res[i] <<    ;   }


#include <bits/stdc++.h>   using namespace std;   int32_t main() {     long long int a, b;     cin >> a >> b;     if (a == 9 and b == 1) {       cout << 9 <<     << 10;     } else if (a == b) {       cout << a * 10 <<     << a * 10 + 1;     } else if (b - a == 1) {       cout << a * 10 + 9 <<     << b * 10 << endl;     } else {       cout << -1 << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int dy[] = {-1, 0, 1, 0}, dx[] = {0, -1, 0, 1};   int h, w;   string in[1000];   void put(int y1, int x1, int y2, int x2) {     bool use[10] = {};     for (int d = 0; d < 4; d++) {       int y = y1 + dy[d], x = x1 + dx[d];       if (y < 0 || x < 0 || y >= h || x >= w || !isdigit(in[y][x])) continue;       use[in[y][x] -  0 ] = 1;     }     for (int d = 0; d < 4; d++) {       int y = y2 + dy[d], x = x2 + dx[d];       if (y < 0 || x < 0 || y >= h || x >= w || !isdigit(in[y][x])) continue;       use[in[y][x] -  0 ] = 1;     }     for (int i = 0; i < 10; i++)       if (!use[(y1 + x1 * 3 + i) % 10]) {         in[y1][x1] = in[y2][x2] =  0  + (y1 + x1 * 3 + i) % 10;         break;       }   }   int get(int y, int x, int c, bool paint) {     if (paint)       in[y][x] =  0  + c;     else       in[y][x] =  - ;     for (int d = 0; d < 4; d++) {       int ny = y + dy[d], nx = x + dx[d];       if (ny < 0 || nx < 0 || ny >= h || nx >= w) continue;       if (!paint && isdigit(in[ny][nx])) c = in[ny][nx] -  0 ;       if (paint && in[ny][nx] ==  -  || !paint && in[ny][nx] ==  . )         get(ny, nx, c, paint);     }     return c;   }   void run() {     cin >> h >> w;     for (int i = 0; i < h; i++) cin >> in[i];     for (int i = 0; i < h; i++)       for (int j = 0; j < w; j++) {         if (j < w - 1 && in[i][j] ==  .  && in[i][j + 1] ==  . )           put(i, j, i, j + 1);         if (i < h - 1 && in[i][j] ==  .  && in[i + 1][j] ==  . )           put(i, j, i + 1, j);       }     for (int i = 0; i < h; i++)       for (int j = 0; j < w; j++)         if (in[i][j] ==  . ) {           int c = get(i, j, -1, 0);           if (c < 0) {             cout << -1 << endl;             return;           }           get(i, j, c, 1);         }     for (int i = 0; i < h; i++) cout << in[i] << endl;   }   int main() {     run();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[105], b[105], n, k;   bool f[105];   void dfs(int i) {     f[i] = true;     for (int k = 1; k <= n; k++) {       if (f[k]) continue;       if (a[i] > a[k] && a[i] < b[k])         dfs(k);       else if (b[i] > a[k] && b[i] < b[k])         dfs(k);     }   }   void setup() { cin >> k; }   void work() {     while (k--) {       int x, y, m;       cin >> m;       if (m == 1) {         n++;         cin >> a[n] >> b[n];       } else {         cin >> x >> y;         memset(f, 0, sizeof(f));         dfs(x);         if (f[y])           cout <<  YES  <<   n ;         else           cout <<  NO  <<   n ;       }     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie();     cout.tie();     setup();     work();     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( O2 )   #pragma GCC optimize( unroll-loops )   using namespace std;   const long double eps = 1e-7;   const int inf = 1000000010;   const long long INF = 10000000000000010LL;   const int mod = 1000000007;   const int MAXN = 100010, LOG = 20;   long long n, m, k, u, v, x, y, t, l, r, ans;   long long S[MAXN], M[MAXN], R[MAXN], D[MAXN];   int Mn[MAXN << 2], Mx[MAXN << 2], lazy[MAXN << 2];   vector<pair<int, int> > seg[MAXN << 2];   vector<long long> ps1[MAXN << 2], ps2[MAXN << 2];   void Build(int id, int tl, int tr) {     if (tr - tl == 1) {       seg[id].push_back({D[tl], tl});       ps1[id].push_back(0);       ps1[id].push_back(R[tl]);       ps2[id].push_back(M[tl]);       ps2[id].push_back(0);       return;     }     int mid = (tl + tr) >> 1;     Build(id << 1, tl, mid);     Build(id << 1 | 1, mid, tr);     seg[id].resize(tr - tl);     ps1[id].resize(tr - tl + 1, 0);     ps2[id].resize(tr - tl + 1, 0);     merge(seg[id << 1].begin(), seg[id << 1].end(), seg[id << 1 | 1].begin(),           seg[id << 1 | 1].end(), seg[id].begin());     ps1[id][0] = ps2[id][tr - tl] = 0;     for (int i = 0; i < tr - tl; i++)       ps1[id][i + 1] = ps1[id][i] + M[seg[id][i].second];     for (int i = tr - tl; i; i--)       ps2[id][i - 1] = ps2[id][i] + R[seg[id][i - 1].second];   }   void add_lazy(int id, int val) { lazy[id] = Mn[id] = Mx[id] = val; }   void shift(int id) {     if (!lazy[id]) return;     add_lazy(id << 1, lazy[id]);     add_lazy(id << 1 | 1, lazy[id]);     lazy[id] = 0;   }   void query(int id, int tl, int tr, int l, int r, int t) {     if (tr <= l || r <= tl) return;     if (l <= tl && tr <= r && Mn[id] == Mx[id] &&         (Mn[id] != -1 || tr - tl == 1)) {       long long time = t - Mn[id];       int shit = (Mn[id] == -1);       add_lazy(id, t);       if (tr - tl == 1) {         time -= shit;         ans += min(M[tl], S[tl] + R[tl] * time);         S[tl] = 0;         return;       }       int pos = upper_bound(seg[id].begin(), seg[id].end(),                             pair<int, int>(time, inf + 1)) -                 seg[id].begin();       ans += ps1[id][pos];       ans += ps2[id][pos] * time;       return;     }     shift(id);     int mid = (tl + tr) >> 1;     query(id << 1, tl, mid, l, r, t);     query(id << 1 | 1, mid, tr, l, r, t);     Mn[id] = min(Mn[id << 1], Mn[id << 1 | 1]);     Mx[id] = max(Mx[id << 1], Mx[id << 1 | 1]);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     memset(Mn, -1, sizeof(Mn));     memset(Mx, -1, sizeof(Mx));     cin >> n;     for (int i = 1; i <= n; i++)       cin >> S[i] >> M[i] >> R[i], D[i] = (R[i] ? (M[i] + R[i] - 1) / R[i] : inf);     Build(1, 1, n + 1);     cin >> m;     while (m--) {       cin >> t >> l >> r;       ans = 0;       query(1, 1, n + 1, l, r + 1, t);       cout << ans <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1000000404;   const long long MOD = 1000000007ll;   const long double PI = acos(-1.0);   const long double EPS = 1e-9;   template <typename t1, typename t2>   inline void upmax(t1 &a, t2 b) {     a = max(a, (t1)b);   }   template <typename t1, typename t2>   inline void upmin(t1 &a, t2 b) {     a = min(a, (t1)b);   }   template <typename T>   inline T gcd(T a, T b) {     return b ? gcd(b, a % b) : a;   }   template <typename T>   inline T lcm(T a, T b) {     return a * (b / gcd(a, b));   }   template <typename T>   inline T sqr(T a) {     return a * a;   }   template <typename T>   inline bool pal(T &x) {     int n = (int((x.size())));     for (int i = 0; i < n / 2; i++) {       if (x[i] != x[n - i - 1]) return 0;     }     return 1;   }   template <typename T>   inline void rev(T &x) {     int n = (int((x.size())));     for (int i = 0; i < n / 2; i++) swap(x[i], x[n - i - 1]);   }   int month[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};   int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};   int dy[] = {0, 1, 0, -1, 1, -1, 1, -1};   inline long long mp(long long a, long long b) { return (a << 31) + b; }   class compare {    public:     bool operator()(const int a, const int b) const { return 1; }   };   int SQ = 400;   int l[211111];   int r[211111];   int m[211111];   int a[211111];   void solve() {     int n;     vector<int> st;     cin >> n;     for (int i = 1; i < n + 1; i++) {       cin >> a[i];     }     for (int i = 1; i < n + 1; i++) {       while (!st.empty() && a[st.back()] >= a[i]) st.pop_back();       if (st.empty())         l[i] = 0;       else         l[i] = st.back();       st.push_back(i);     }     st.resize(0);     for (int i = n + 1 - 1; i >= 1; i--) {       while (!st.empty() && a[st.back()] >= a[i]) st.pop_back();       if (st.empty())         r[i] = n + 1;       else         r[i] = st.back();       st.push_back(i);     }     st.resize(0);     for (int i = 1; i < n + 1; i++) upmax(m[r[i] - l[i] - 1], a[i]);     for (int i = n + 1 - 1; i >= 1; i--) upmax(m[i], m[i + 1]);     for (int i = 1; i < n + 1; i++) cout << m[i] <<    ;     cout << endl;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int t = 1;     while (t--) {       solve();     };     getchar();     getchar();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 1010;   string a[MAX];   int n, m;   bool visit[MAX][MAX];   bool v[1000010];   int b[MAX][MAX];   int val[1000010];   void dfs(int x, int y, int cnt) {     if (x < 0 || y < 0 || x >= n || y >= m) {       return;     }     if (visit[x][y]) {       return;     }     if (a[x][y] ==  * ) {       return;     }     visit[x][y] = true;     val[cnt]++;     b[x][y] = cnt;     dfs(x + 1, y, cnt);     dfs(x, y + 1, cnt);     dfs(x - 1, y, cnt);     dfs(x, y - 1, cnt);   }   int main() {     ios::sync_with_stdio(false);     cin >> n >> m;     for (int i = 0; i < n; i++) {       cin >> a[i];     }     memset(visit, false, sizeof(visit));     memset(b, -1, sizeof(visit));     memset(val, 0, sizeof(val));     int cnt = 1;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (!visit[i][j] && a[i][j] ==  . ) {           dfs(i, j, cnt);           cnt++;         }       }     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (a[i][j] ==  * ) {           int temp = 1, t[5] = {0};           if (b[i - 1][j] != -1 && i - 1 >= 0) {             t[0] = b[i - 1][j];           }           if (b[i][j - 1] != -1 && j - 1 >= 0) {             t[1] = b[i][j - 1];           }           if (b[i + 1][j] != -1 && i + 1 < n) {             t[2] = b[i + 1][j];           }           if (b[i][j + 1] != -1 && j + 1 < m) {             t[3] = b[i][j + 1];           }           sort(t, t + 4);           for (int k = 0; k < 4; k++) {             if (t[k] != t[k + 1]) {               temp += val[t[k]];             }           }           a[i][j] =  0  + (temp) % 10;         }       }     }     for (int i = 0; i < n; i++) {       cout << a[i] <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, cnt, a[220000];   long long sum;   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     for (int l = 1; l <= n; l++) {       sum = a[l + 1];       for (int r = l + 2; r <= n; r++) {         if (a[l] < a[r]) {           sum += a[r];           if (sum > (1 << ((int)log2(a[l]) + 1))) break;           continue;         }         if ((a[l] ^ a[r]) == sum) cnt++;         sum += a[r];         if (sum > (1 << ((int)log2(a[l]) + 1))) break;       }     }     reverse(a + 1, a + n + 1);     for (int l = 1; l <= n; l++) {       sum = a[l + 1];       for (int r = l + 2; r <= n; r++) {         if (a[l] <= a[r]) {           sum += a[r];           if (sum > (1 << ((int)log2(a[l]) + 1))) break;           continue;         }         if ((a[l] ^ a[r]) == sum) cnt++;         sum += a[r];         if (sum > (1 << ((int)log2(a[l]) + 1))) break;       }     }     printf( %d , cnt);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     int k = 1;     int r = 0;     int index1, index2;     cin >> n;     vector<pair<pair<int, int>, pair<int, int>>> s(n);     vector<int> t(3);     for (int i = 0; i < n; i++) {       scanf( %i%i%i , &t[0], &t[1], &t[2]);       sort(t.begin(), t.end());       s[i].first.first = t[2];       s[i].first.second = t[1];       s[i].second.first = t[0];       s[i].second.second = i;       if (t[0] > r) {         index1 = i;         r = t[0];       }     }     sort(s.begin(), s.end());     for (int i = 0; i < s.size() - 1; i++) {       if (s[i].first.first == s[i + 1].first.first &&           s[i].first.second == s[i + 1].first.second) {         int temp = min(s[i].second.first + s[i + 1].second.first,                        min(s[i].first.first, s[i].first.second));         if (temp > r) {           r = temp;           index1 = s[i].second.second;           index2 = s[i + 1].second.second;           k = 2;         }       }     }     cout << k << endl;     if (k == 1) {       cout << index1 + 1 << endl;     } else       cout << index1 + 1 <<     << index2 + 1 << endl;     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize(3)   using namespace std;   const long long N = 210;   inline long long read() {     long long s = 0, w = 1;     register char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) w = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 )       s = (s << 3) + (s << 1) + (ch ^ 48), ch = getchar();     return s * w;   }   long long n, K, vis[N], g[N];   struct Node {     long long l, r;   } a[N];   inline bool Check(long long x, long long y) {     Node p = a[x], q = a[y];     if (p.l > q.l) swap(p, q);     return (q.l < p.r && p.r < q.r);   }   signed main() {     for (register long long T = read(); T; T--) {       memset(vis, 0, sizeof(vis));       n = read(), K = read();       for (register long long i = 1; i <= K; i++) {         a[i].l = read(), a[i].r = read();         if (a[i].l > a[i].r) swap(a[i].l, a[i].r);         vis[a[i].l] = vis[a[i].r] = 1;       }       long long m = 0;       for (register long long i = 1; i <= n * 2; i++) {         if (!vis[i]) g[++m] = i;       }       long long sz = n - K;       for (register long long i = 1; i <= sz; i++) {         a[++K] = (Node){g[i], g[i + sz]};       }       long long ans = 0;       for (register long long i = 1; i <= n; i++) {         for (register long long j = i + 1; j <= n; j++) {           if (Check(i, j)) ans++;         }       }       printf( %lld n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long a[5010], b[5010], n, dp[5010];   int main() {     cin >> n;     for (long long i = 1ll; i <= n; i++) scanf( %I64d , &a[i]), b[i] = a[i];     sort(b + 1ll, b + n + 1ll);     dp[0ll] = (long long)1000000000000000007;     for (long long i = 1ll; i <= n; i++) {       for (long long j = 1ll; j <= n; j++) {         dp[j] = min(dp[j - 1ll], dp[j] + abs(b[j] - a[i]));       }     }     cout << dp[n] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 1123;   const int INF = 0x3f3f3f3f;   const long long MOD = 1000000007;   const double EPS = 1e-9;   const double PI = acos(-1);   inline int cmp(double x, double y = 0, double tol = EPS) {     return (x <= y + tol) ? (x + tol < y) ? -1 : 0 : 1;   }   struct point {     double x, y;     point(double a, double b) : x(a), y(b) {}     point() : x(0.0), y(0.0) {}     point operator+(point q) { return point(x + q.x, y + q.y); }     point operator-(point q) { return point(x - q.x, y - q.y); }     point operator*(double t) { return point(x * t, y * t); }     point operator/(double t) { return point(x / t, y / t); }     double operator*(point q) { return x * q.x + y * q.y; }     double operator^(point q) { return x * q.y - y * q.x; }     double polar() { return ((y > -EPS) ? atan2(y, x) : 2 * PI + atan2(y, x)); }     double mod() { return sqrt(x * x + y * y); }     double mod2() { return (x * x + y * y); }     point rotate(double t) {       return point(x * cos(t) - y * sin(t), x * sin(t) + y * cos(t));     }     int cmp(point q) const {       if (int t = ::cmp(x, q.x)) return t;       return ::cmp(y, q.y);     }     bool operator==(point q) const { return cmp(q) == 0; }     bool operator!=(point q) const { return cmp(q) != 0; }     bool operator<(point q) const { return cmp(q) < 0; }   };   int n, tam;   point P[MAX];   point Q[MAX * MAX];   inline int ccw(point p, point q, point r) { return cmp((q - r) ^ (p - r)); }   int gcd(int a, int b) {     if (b == 0) return a;     return gcd(b, a % b);   }   int main() {     cin.sync_with_stdio(false);     cin.tie(0);     cin >> n;     for (int i = 0; i < n; i++) cin >> P[i].x >> P[i].y;     if (P[0].x == P[1].x) {       tam = 0;       if (P[1].y > P[0].y) {         for (int i = P[0].y; i <= P[1].y; i++) Q[tam++] = point(P[0].x, i);       } else {         for (int i = P[0].y; i >= P[1].y; i--) Q[tam++] = point(P[0].x, i);       }     } else if (P[0].y == P[1].y) {       tam = 0;       if (P[1].x > P[0].x) {         for (int i = P[0].x; i <= P[1].x; i++) Q[tam++] = point(i, P[0].y);       } else {         for (int i = P[0].x; i >= P[1].x; i--) Q[tam++] = point(i, P[0].y);       }     } else {       tam = 0;       int g = gcd((int)(abs(P[0].y - P[1].y)), (int)(abs(P[0].x - P[1].x)));       int p = (P[0].y - P[1].y) / g;       int q = (P[0].x - P[1].x) / g;       for (int i = P[0].x; q ? (i <= P[1].x) : (i >= P[1].x); i += q)         Q[tam++] = point(i, P[0].y + ((i - P[0].x) * p) / q);     }     int st = 0, ed = tam - 1;     fprintf(stderr,  %d %d n , st, ed);     for (int i = 1; i < n; i++) {       while (st <= ed && ccw(P[i], P[(i + 1) % n], Q[st]) < 0) st++;       while (ed >= st && ccw(P[i], P[(i + 1) % n], Q[ed]) < 0) ed--;     }     cout << max(ed - st + 1, 0) <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   inline void read(int &x) {     int v = 0, f = 1;     char c = getchar();     while (!isdigit(c) && c !=  - ) c = getchar();     if (c ==  - )       f = -1;     else       v = (c & 15);     while (isdigit(c = getchar())) v = (v << 1) + (v << 3) + (c & 15);     x = v * f;   }   inline void read(long long &x) {     long long v = 0ll, f = 1ll;     char c = getchar();     while (!isdigit(c) && c !=  - ) c = getchar();     if (c ==  - )       f = -1;     else       v = (c & 15);     while (isdigit(c = getchar())) v = (v << 1) + (v << 3) + (c & 15);     x = v * f;   }   inline void readc(char &x) {     char c;     while (((c = getchar()) ==    ) || c ==   n )       ;     x = c;   }   inline void writes(string s) { puts(s.c_str()); }   inline void writeln() { writes(  ); }   inline void writei(int x) {     if (x < 0) {       putchar( - );       x = abs(x);     }     if (!x) putchar( 0 );     char a[25];     int top = 0;     while (x) {       a[++top] = (x % 10) +  0 ;       x /= 10;     }     while (top) {       putchar(a[top]);       top--;     }   }   inline void writell(long long x) {     if (x < 0) {       putchar( - );       x = abs(x);     }     if (!x) putchar( 0 );     char a[25];     int top = 0;     while (x) {       a[++top] = (x % 10) +  0 ;       x /= 10;     }     while (top) {       putchar(a[top]);       top--;     }   }   const int dx[9] = {0, -2, -2, -1, -1, 1, 1, 2, 2},             dy[9] = {0, -1, 1, -2, 2, -2, 2, -1, 1};   int n, m, i, j, dis[1005][1005][2], x, y, xx, yy;   int a, b;   bool inmap(int x, int y) { return 1 <= x && x <= n && 1 <= y && y <= m; }   void bfs(int x, int y, int typ) {     dis[x][y][typ] = 0;     queue<int> qx, qy;     qx.push(x);     qy.push(y);     while (!qx.empty()) {       int x = qx.front(), y = qy.front();       int i;       qx.pop();       qy.pop();       for (((i)) = (1); ((i)) <= ((8)); ((i))++) {         int nx = x + dx[i], ny = y + dy[i];         if (inmap(nx, ny) && dis[nx][ny][typ] > dis[x][y][typ] + 1) {           dis[nx][ny][typ] = dis[x][y][typ] + 1;           qx.push(nx);           qy.push(ny);         }       }     }   }   void solve(int x, int y, int typ) {     for (;;) {       if (dis[x][y][typ] == 0) break;       int i;       for (((i)) = (1); ((i)) <= ((8)); ((i))++) {         int nx = x + dx[i], ny = y + dy[i];         if (nx == a && ny == b) {           printf( %d %d n , nx, ny);           return;         }       }       for (((i)) = (1); ((i)) <= ((8)); ((i))++) {         int nx = x + dx[i], ny = y + dy[i];         if (inmap(nx, ny) && dis[nx][ny][typ] == dis[x][y][typ] - 1) {           printf( %d %d n , nx, ny);           fflush(stdout);           x = nx;           y = ny;           if (dis[x][y][typ] == 0) return;           scanf( %d%d , &a, &b);           break;         }       }     }   }   int main() {     scanf( %d%d , &n, &m);     scanf( %d%d%d%d , &x, &y, &xx, &yy);     memset((dis), (0x16), (sizeof((dis))));     bfs(n / 2, m / 2, 0);     bfs(n / 2 + 1, m / 2, 1);     double wg = dis[x][y][0];     double wb = dis[x][y][1];     double bg = dis[xx][yy][1] + 0.5;     double bb = dis[xx][yy][0] + 0.5;     if ((x + y) % 2 == (xx + yy) % 2) {       if (bg < wg) {         puts( BLACK );         fflush(stdout);         scanf( %d%d , &a, &b);         solve(xx, yy, 1);         return 0;       }       if (bb < wg + 1) {         puts( BLACK );         fflush(stdout);         scanf( %d%d , &a, &b);         solve(xx, yy, 0);         solve(n / 2, m / 2, 1);         return 0;       }       puts( WHITE );       fflush(stdout);       solve(x, y, 0);     } else {       if (wg < bg) {         puts( WHITE );         fflush(stdout);         solve(x, y, 0);         return 0;       }       if (wb < bg + 1) {         puts( WHITE );         fflush(stdout);         solve(x, y, 1);         solve(n / 2 + 1, m / 2, 0);         return 0;       }       puts( BLACK );       fflush(stdout);       scanf( %d%d , &a, &b);       solve(xx, yy, 1);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int arr[100005];   int lfl[100005];   int rfl[100005];   int main() {     int n;     cin >> n;     int i, j;     for (i = 1; i <= n; i++) {       cin >> arr[i];     }     for (i = 1; i <= n; i++) {       lfl[i] = min(lfl[i - 1] + 1, arr[i]);     }     long long ans = INT_MIN;     for (i = n; i >= 1; i--) {       rfl[i] = min(rfl[i + 1] + 1, arr[i]);       ans = (long long)max(ans, (long long)min(lfl[i], rfl[i]));     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename A, typename B>   ostream &operator<<(ostream &os, const pair<A, B> &p) {     return os <<  (  << p.first <<  ,   << p.second <<  ) ;   }   template <typename T_container, typename T = typename enable_if<                                       !is_same<T_container, string>::value,                                       typename T_container::value_type>::type>   ostream &operator<<(ostream &os, const T_container &v) {     os <<  [ ;     string sep;     for (const T &x : v) os << sep << x, sep =  ,  ;     return os <<  ] ;   }   void debug_out() { cerr << endl; }   template <typename Head, typename... Tail>   void debug_out(Head H, Tail... T) {     cerr <<     << H;     debug_out(T...);   }   void run_case() {     int N;     cin >> N;     vector<int> A(N);     for (int &a : A) cin >> a;     int MX = *max_element(A.begin(), A.end()) / 3 + 100;     int best = MX;     for (int ones = 0; ones <= 2; ++ones)       for (int twos = 0; twos <= 2; ++twos) {         int threes = 0;         for (int a : A) {           int least = MX;           for (int one = 0; one <= ones; ++one)             for (int two = 0; two <= twos; ++two) {               int want = a - two * 2 - one;               if (want % 3 != 0 || want < 0) continue;               least = min(least, want / 3);             }           threes = max(threes, least);         }         best = min(best, ones + twos + threes);       }     cout << best <<   n ;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int tests;     cin >> tests;     while (tests--) run_case();   }


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


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     vector<int> lucky;     for (int i = 1; i <= 9; i++) {       for (int j = 0; j < (1 << i); j++) {         int num = 0;         for (int k = 0; k < i; k++) {           if (j & (1 << k))             num = num * 10 + 7;           else             num = num * 10 + 4;         }         lucky.push_back(num);       }     }     sort(lucky.begin(), lucky.end());     int n;     cin >> n;     for (int i = 0; i < lucky.size(); i++) {       if (lucky[i] == n) {         cout << i + 1;         break;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, x, y;     cin >> n >> x >> y;     long long chis = y - n + 1;     if (n - 1 + chis * chis >= x && chis > 0) {       for (long long i = 0; i < n - 1; i++) cout <<  1  <<   n ;       cout << chis;     } else       cout <<  -1 ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int test;     cin >> test;     while (test--) {       int a, b;       cin >> a >> b;       cout << (a ^ b) << endl;     }     return 0;   }


#include <bits/stdc++.h>   class arr {     bool* marked;     int* nummarked;     int markednumber;       public:     arr() {       marked = new bool[1000000];       for (int i = 0; i < 1000000; i++) {         marked[i] = false;       }       nummarked = new int[1000];       for (int i = 0; i < 1000; i++) {         nummarked[i] = 0;       }       markednumber = 0;     }     void mark(int i) {       marked[i] = true;       nummarked[i / 1000]++;       markednumber++;     }     int position(int i) {       int pr = 0;       for (int j = 0; j < (i / 1000); j++) {         pr += 1000;         pr -= nummarked[j];       }       for (int j = (i / 1000 * 1000); j < i; j++) {         if (!marked[j]) {           pr++;         }       }       return pr;     }     int number(int i) {       int sh = 0;       int tek = 0;       while ((i - sh - (1000 - nummarked[tek / 1000])) >= 0) {         sh += (1000 - nummarked[tek / 1000]);         tek += 1000;       }       while (i > sh) {         if (!marked[tek]) {           sh++;         }         tek++;       }       while (marked[tek]) tek++;       return tek;     }   };   const int max = 200000;   int main() {     int n;     scanf( %d , &n);     int* p1 = new int[n];     int* p2 = new int[n];     for (int i = 0; i < n; i++) scanf( %d , (p1 + i));     for (int i = 0; i < n; i++) scanf( %d , (p2 + i));     int* i1 = new int[max];     {       arr ist;       for (int i = 0; i < (n - 1); i++) {         i1[i] = ist.position(p1[i]);         ist.mark(p1[i]);       }     }     int* i2 = new int[max];     {       arr ist2;       for (int i = 0; i < (n - 1); i++) {         i2[i] = ist2.position(p2[i]);         ist2.mark(p2[i]);       }     }     int* is = new int[max];     for (int i = 0; i < (n - 1); i++) {       is[i] = i1[i] + i2[i];     }     for (int j = (n - 2); j > 0; j--) {       while (is[j] > (n - 1 - j)) {         is[j] -= (n - j);         is[j - 1]++;       }     }     while (is[0] > (n - 1)) {       is[0] -= n;     }     int* ps = new int[n];     for (int i = 0; i < n; i++) {       ps[i] = 0;     }     arr ists;     for (int i = 0; i < (n - 1); i++) {       ps[i] = ists.number(is[i]);       ists.mark(ps[i]);     }     ps[n - 1] = ists.number(0);     for (int i = 0; i < n; i++) {       printf( %d  , ps[i]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   ifstream fin( AAtest.in.txt );   long long n, p, t[4][ T ], su;   string s;   int main() {     ios::sync_with_stdio(0);     cin >> n;     for (int(i) = (0); ((i)) < ((n)); ((i))++) {       cin >> s;       p = s.size();       p--;       t[p][s[p]]++;       su++;     }     for (int(i) = (0); ((i)) < ((n)); ((i))++) {       cin >> s;       p = s.size();       p--;       su -= abs(t[p][s[p]]);       t[p][s[p]]--;       su += abs(t[p][s[p]]);     }     cout << su / 2;   }


#include <bits/stdc++.h>   using namespace std;   void solve(void) {     int N;     long int s = 0;     cin >> N;     for (int i = 2; i <= N; i++) s += i - 1;     cout << s * 6 * 2 + 1 << endl;   }   int main(int argc, char const *argv[]) {     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   vector<string> v;   set<string> st;   map<string, int> mp;   int main() {     char t[11];     int c;     scanf( %d , &n);     for (int i = 0; i < n; i++) {       memset(t,   0 , sizeof(t));       scanf( %s , t);       if (st.count(t) == 0) {         st.insert(t);         v.push_back(t);         mp[t] = 1;       } else         mp[t]++;     }     int cur = mp[v[0]];     string res = v[0];     for (int i = 1; i < v.size(); i++)       if (mp[v[i]] > cur) res = v[1];     printf( %s , res.c_str());     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, k;   long long cnt, sum, mx, ans = 0;   bool flag, gov[1010], vis[1010];   vector<int> vec, edges[1010];   void dfs(int u) {     vis[u] = 1;     for (int v : edges[u])       if (!vis[v]) dfs(v);     ++cnt;     flag |= gov[u];   }   int main() {     int u, v, i;     cin >> n >> m >> k;     for (i = 0; i < k; ++i) {       scanf( %d , &u);       gov[u] = 1;     }     for (i = 0; i < m; ++i) {       scanf( %d %d , &u, &v);       edges[u].push_back(v);       edges[v].push_back(u);     }     for (i = 1; i <= n; ++i) {       if (vis[i]) continue;       cnt = flag = 0;       dfs(i);       ans += cnt * (cnt - 1) / 2;       if (flag)         mx = max(mx, cnt);       else         vec.push_back(cnt);     }     for (int v : vec) {       ans += mx * v;       mx += v;     }     cout << ans - m << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = 4e18;   const long long MAX = 2e5 + 5;   const long long MOD = 1e9 + 7;   int n, m;   void exgcd(int a, int b, long long &c, long long &d) {     if (a == 0) {       c = 0;       d = 1;       return;     }     exgcd(b % a, a, d, c);     c -= b / a * d;   }   long long gcd(int a, int b) {     if (a == 0) return b;     return gcd(b % a, a);   }   int g[MAX];   bool arv[MAX], avb[MAX];   int sz[MAX];   pair<int, int> ma[MAX];   vector<int> v;   vector<int> son[MAX];   void build() {     for (int i = 0; i < m; i++) {       g[i] = gcd(i, m);       sz[g[i]]++;       son[g[i]].push_back(i);     }     g[m] = m;     int x = m;     for (int i = 2; i <= sqrt(x); i++) {       if (x % i == 0) v.push_back(i);       while (x % i == 0) x /= i;     }     if (x > 1) v.push_back(x);   }   void read() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n >> m;     build();     for (int i = 0; i < n; i++) {       int x;       cin >> x;       avb[x] = 1;       if (!x) avb[m] = 1;       sz[gcd(x, m)]--;     }   }   void dfs(long long x) {     if (arv[x]) return;     for (int i : v) {       if (i * x > m) break;       if (g[i * x] == i * x) {         dfs(i * x);         ma[x] = max(ma[x], {ma[i * x].first, i * x});       }     }     ma[x].first += sz[x];     ;     arv[x] = 1;   }   vector<int> ans;   void output() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout << ((long long)(ans).size()) <<   n ;     for (int i : ans) cout << i <<    ;     cout <<   n ;     ;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     read();     for (int i = 1; i <= m; i++)       if (g[i] == i && !arv[i]) dfs(i);     long long now = 1, pre = 1;     long long cod;     while (now <= m) {       ;       for (long long i : son[now]) {         if (!avb[i]) {           long long r, y;           long long gc = gcd(pre, m);           exgcd(pre / gc, m / gc, r, y);           if (r < 0) r += m;           ans.push_back(i / gc * r % m);           pre = i;         }       }       if (ma[now].second) {         now = ma[now].second;       } else         break;     }     output();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1010000;   long long binpow(long long a, long long b, long long c) {     long long res = 1;     while (b) {       if (b & 1) res = (res * a) % c;       a = (a * a) % c;       b >>= 1;     }     return res;   }   int gcd(int a, int b) {     if (!b) return a;     return gcd(b, a % b);   }   int phi;   int lp[N], pr[N], k = 0;   int cnt[N];   int n, m, mod, x;   long long go[N];   vector<pair<int, int> > fact(int x) {     vector<pair<int, int> > res;     while (x > 1) {       if (res.size() > 0 && res[(int)res.size() - 1].first == lp[x])         res[(int)res.size() - 1].second++;       else         res.push_back(make_pair(lp[x], 1));       x /= lp[x];     }     return res;   }   long long f[N], inv[N];   long long C(int n, int m) {     if (n < m) return 0;     long long res = f[n];     res = (res * inv[m]) % phi;     res = (res * inv[n - m]) % phi;     return res;   }   long long ans[N];   int main() {     lp[0] = lp[1] = 1;     for (int i = 2; i <= 1000123; ++i) {       if (!lp[i]) {         lp[i] = i;         pr[++k] = i;       }       for (int j = 1; j <= k && pr[j] <= lp[i]; ++j) {         if ((long long)pr[j] * i > 1000123) break;         lp[pr[j] * i] = pr[j];       }     }     cin >> n >> m >> x >> mod;     for (int i = 1; i < mod; ++i) {       if (binpow(x, i, mod) == 1) {         phi = i;         break;       }     }     f[0] = inv[0] = 1;     for (int i = 1; i <= 1000123; ++i) {       f[i] = (f[i - 1] * i) % phi;       inv[i] = binpow(f[i], phi - 2, phi);     }     go[0] = 1;     for (int i = 1; i <= n; ++i) {       go[i] = (go[i - 1] + C(m, i)) % phi;     }     for (int i = 1; i <= n; ++i) {       ans[i] = binpow(x, go[i - 1], mod);     }     for (int i = n; i > 0; --i) printf( %lld  , ans[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, len = 0, max = 0, flag = 1;     cin >> n;     string alpha =  abcdefghijklmnopqrstuvwxyz ;     vector<string> vs(n);     for (int i = 0; i < n; i++) cin >> vs[i];     for (auto i : alpha) {       for (auto j : alpha) {         len = 0;         for (auto k : vs) {           flag = 1;           for (auto l : k) {             if (l != i && l != j) {               flag = 0;               break;             }           }           if (flag) len += k.size();         }         if (len > max) max = len;       }     }     cout << max;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       int arr[105];       for (int i = 0; i < n; i++) {         cin >> arr[i];       }       int visited[105] = {0};       for (int i = 0; i < n; i++) {         visited[arr[i]]++;       }       int flag1 = -1;       int flag2 = -1;       for (int i = 0; i < 105; i++) {         if (visited[i] == 1 and flag1 == -1) {           flag1 = i;         }         if (visited[i] == 0 and flag1 == -1) {           flag1 = i;           flag2 = i;           break;         } else if (visited[i] == 0 and flag1 != -1) {           flag2 = i;           break;         }       }       cout << flag1 + flag2 << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 7;   vector<pair<int, int> > v[N];   int n, m;   int foo, bar, id;   long long val[N];   long long wt[N];   int dep[N];   int dp[20][N];   int par[N];   int x1[N];   int x2[N];   void dfs(int node, int baap) {     dep[node] = dep[baap] + 1;     dp[0][node] = baap;     par[node] = baap;     for (int i = 0; i < v[node].size(); i++) {       int beta = v[node][i].first;       int mark = v[node][i].second;       if (beta == baap) continue;       val[beta] = wt[mark];       dfs(beta, node);     }   }   int jump(int p, int dist) {     for (int i = 19; i >= 0; i--) {       if ((1 << i) <= dist) {         dist -= 1 << i;         p = dp[i][p];       }     }     return p;   }   int lca(int p, int q) {     if (dep[p] < dep[q]) swap(p, q);     p = jump(p, dep[p] - dep[q]);     if (p == q) return p;     for (int i = 19; i >= 0; i--) {       int pp = dp[i][p];       int qq = dp[i][q];       if (pp != qq) p = pp, q = qq;     }     return dp[0][p];   }   int find(int p) {     if (val[p] > 1) return p;     return par[p] = find(par[p]);   }   int main() {     cin >> n >> m;     for (int i = 1; i < n; i++) {       scanf( %d%d%lld , &foo, &bar, &wt[i]);       v[foo].push_back(make_pair(bar, i));       v[bar].push_back(make_pair(foo, i));       x1[i] = foo;       x2[i] = bar;     }     val[1] = 2;     dfs(1, 0);     for (int j = 1; j < 20; j++) {       for (int i = 1; i <= n; i++) {         dp[j][i] = dp[j - 1][dp[j - 1][i]];       }     }     while (m--) {       int p, q, tp;       long long r;       scanf( %d , &id);       if (id == 1) {         scanf( %d%d%lld , &p, &q, &r);         int lc = lca(p, q);         tp = p;         while (r and dep[tp] > dep[lc]) {           r /= val[tp];           tp = find(par[tp]);         }         tp = q;         while (r and dep[tp] > dep[lc]) {           r /= val[tp];           tp = find(par[tp]);         }         printf( %lld n , r);       } else {         scanf( %d%lld , &p, &r);         wt[p] = r;         if (x2[p] == dp[0][x1[p]]) swap(x1[p], x2[p]);         val[x2[p]] = r;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     long double P = 3.1415926536, a[110], n;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a[i];       a[i] *= a[i];       a[i] *= P;     }     for (int i = 0; i < n; i++)       for (int j = 0; j < n - 1; j++)         if (a[j] > a[j + 1]) swap(a[j], a[j + 1]);     long double ans = 0;     for (int i = n - 1; i >= 0; i -= 2)       if (i == 0)         ans += a[i];       else         ans += a[i] - a[i - 1];     cout << setprecision(12) << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MN = 5e5 + 5;   int N, i, j, pre = 1;   long long ans, cur, acc;   string s;   stack<pair<int, int> > stk;   int main() {     cin >> N >> s;     s.insert(s.begin(),    );     for (i = 1; i <= N; i++) {       if (s[i] ==  1 ) {         int len = i - pre + 1;         long long hm = 1LL * len * (len + 1) / 2;         while (stk.size()) {           if (stk.top().first <= len) {             acc += stk.top().second;             cur -= 1LL * stk.top().first * stk.top().second;             stk.pop();           } else             break;         }         ans += acc * len + hm + cur;       } else {         if (pre < i) {           int len = i - pre;           cur += 1LL * len * (acc + 1);           stk.push({len, acc + 1});           acc = 0;           for (j = len - 1; j >= 1; j--) {             cur += j;             stk.push({j, 1});           }         }         stk.push({0, 1});         pre = i + 1;         ans += cur;       }     }     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int p, n;   char arr[1002], brr[1002];   int main() {     scanf( %s , arr);     n = strlen(arr);     for (int i = 0; i < n; i++) {       if (arr[i] ==  . ) {         p = i;       }     }     if (arr[p - 1] ==  9 ) {       printf( GOTO Vasilisa. n );     } else {       if (arr[p + 1] -  0  >= 5) {         arr[p - 1]++;       }       for (int i = 0; i < p; i++) {         printf( %c , arr[i]);       }       printf(  n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int N, M;   const int MAX = 1e6;   vector<int> edges[MAX];   int indeg[MAX];   vector<int> source;   map<int, int> sink;   int reachable[20];   const int BITMAX = 1 << 20;   int dp[BITMAX];   void dfs(int start, int i) {     if (sink.count(i)) {       reachable[start] |= sink[i];     } else {       for (auto j : edges[i]) dfs(start, j);     }   }   int main() {     int i, j, k;     cin >> N >> M;     for (i = 0; i < M; i++) {       int x, y;       scanf( %d %d , &x, &y);       edges[x - 1].push_back(y - 1);       indeg[y - 1]++;     }     int num = 1;     for (i = 0; i < N; i++) {       if (indeg[i] == 0) source.push_back(i);       if (edges[i].size() == 0) {         sink[i] = num;         num *= 2;       }     }     int sz = source.size();     for (i = 0; i < sz; i++) dfs(i, source[i]);     int bitmax = 1 << sz;     for (i = 1; i < bitmax; i++) {       bool updated = false;       int in = 0;       for (j = 0; j < sz; j++) {         if ((i >> j) & 1) {           in++;           if (!updated) {             dp[i] = dp[i - (1 << j)] | reachable[j];             updated = true;           }         }       }       int out = 0;       for (j = 0; j < sz; j++) {         if ((dp[i] >> j) & 1) out++;       }       if (in >= out && in < sz) {         cout <<  NO  << endl;         return 0;       }     }     cout <<  YES  << endl;     return 0;   }


#include <bits/stdc++.h>   const long long _INF = 1e18;   const int INF = 1e9;   using namespace std;   int T;   void solved() {     long long n = 0;     cin >> n;     if (n % 2 == 1) n++;     if (n <= 6)       cout << 15 <<   n ;     else       cout << n * 5 / 2 <<   n ;   }   int main() {     setbuf(stdout, NULL);     ios::sync_with_stdio(0);     cin.tie(0);     cin >> T;     for (int i = 0; i < (T); i++) {       solved();     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int i = 0, a = 0, b = 0;     string s;     cin >> s;     while (s[i] !=   0 ) {       if (s[i] >= 65 && s[i] <= 90) {         a++;       } else if (s[i] >= 97 && s[i] <= 122)         b++;       i++;     }     i = 0;     if (a > b) {       while (s[i] !=   0 ) {         s[i] = toupper(s[i]);         i++;       }     } else if (a < b) {       while (s[i] !=   0 ) {         s[i] = tolower(s[i]);         i++;       }     } else if (a == b) {       while (s[i] !=   0 ) {         s[i] = tolower(s[i]);         i++;       }     }     cout << s;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 20;   int n, x, i, f[N];   int main() {     scanf( %d , &n);     while (n--) scanf( %d , &x), f[x]++;     for (i = N - 1; i >= 0; i--)       if (f[i] & 1) return 0 * printf( Conan );     printf( Agasa );   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 1e3 + 7;   int n, m, k;   int x[N], y[N];   vector<int> s[N], t[N];   int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};   int bor[4];   int xnow, ynow, flg[N];   int main() {     scanf( %d%d%d , &n, &m, &k);     for (int i = 1; i <= k; i++) {       scanf( %d%d , &x[i], &y[i]), s[x[i]].push_back(y[i]),           t[y[i]].push_back(x[i]);       if (y[i] == 1) flg[x[i]] = 1;     }     int now = 1, num = 0;     while (now <= n) {       if (flg[now]) break;       num++;       now++;     }     if (num == 1ll * n * m - k) {       puts( Yes );       return 0;     }     for (int i = 1; i <= n; i++)       s[i].push_back(0), s[i].push_back(m + 1), sort(s[i].begin(), s[i].end());     for (int i = 1; i <= m; i++)       t[i].push_back(0), t[i].push_back(n + 1), sort(t[i].begin(), t[i].end());     bor[0] = m + 1, bor[1] = n + 1, bor[2] = 0, bor[3] = 1;     int dir = 3;     xnow = ynow = 1;     long long tot = 1;     while (1) {       dir = (dir + 1) % 4;       if (dir == 0) {         int pos =             lower_bound(s[xnow].begin(), s[xnow].end(), ynow) - s[xnow].begin();         int to = min(s[xnow][pos], bor[dir]);         if (to == ynow + 1) break;         tot += to - ynow - 1;         bor[dir] = to - 1;         ynow = to - 1;       }       if (dir == 1) {         int pos =             lower_bound(t[ynow].begin(), t[ynow].end(), xnow) - t[ynow].begin();         int to = min(t[ynow][pos], bor[dir]);         if (to == xnow + 1) break;         tot += to - xnow - 1;         bor[dir] = to - 1;         xnow = to - 1;       }       if (dir == 2) {         int pos = lower_bound(s[xnow].begin(), s[xnow].end(), ynow) -                   s[xnow].begin() - 1;         int to = max(s[xnow][pos], bor[dir]);         if (to == ynow - 1) break;         tot += ynow - to - 1;         bor[dir] = to + 1;         ynow = to + 1;       }       if (dir == 3) {         int pos = lower_bound(t[ynow].begin(), t[ynow].end(), xnow) -                   t[ynow].begin() - 1;         int to = max(t[ynow][pos], bor[dir]);         if (to == xnow - 1) break;         tot += xnow - to - 1;         bor[dir] = to + 1;         xnow = to + 1;       }     }     if (tot == 1ll * n * m - k)       puts( Yes );     else       puts( No );   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long t;     cin >> t;     while (t--) {       long long n, x;       cin >> n;       string s =   ;       if (n % 2 == 0) {         s +=  1 ;       } else         s +=  7 ;       x = n / 2 - 1;       for (long long i = 0; i < (x); ++i) s +=  1 ;       cout << s <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int arr[250];   int N = 250;   void tmain() {     double m = 0;     for (int i = 0; i < N; ++i) {       scanf( %d , arr + i);       m += arr[i];     }     m /= N;     double dev = 0;     for (int i = 0; i < N; ++i) {       dev += (m - arr[i]) * (m - arr[i]);     }     dev /= N;     dev = sqrt(dev);     if (dev < (m / sqrt(3) + sqrt(m)) / 2) {       printf( %d n , (int)(m + 0.5));     } else {       printf( %d n , (int)(0.52 * (*max_element(arr, arr + 250))));     }     return;   }   int main() {     int T;     scanf( %d , &T);     while (T--) tmain();   }


#include <bits/stdc++.h>   using namespace std;   #define ll long long   ll gcd(ll a, ll b){       if (a == 0)          return b;       if (b == 0)          return a;       if (a == b)           return a;       if (a > b)           return gcd(a-b, b);       return gcd(a, b-a);   }   int main(){     ll t;     cin>>t;     while(t--){       ll k;       cin>>k;       ll k_ = 100-k;       ll g = gcd(k,k_);       ll a = k/g;       ll b = k_/g;       cout<<a+b<<endl;     }        }


#include <bits/stdc++.h>   using namespace std;   vector<int> v;   void sep(int x) {     if (x == 0) return;     sep(x / 10);     v.push_back(x % 10);   }   int main() {     int i;     for (int i = 1; i < 1 << 30 && v.size() < 1010; i++) {       sep(i);     }     int x;     cin >> x;     cout << v[x - 1];     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int mod = 998244353;   int main() {     ios_base ::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     long long int fac[n + 1];     fac[0] = 1;     for (int i = 1; i <= n; i++) {       fac[i] = fac[i - 1] * i;       fac[i] %= mod;     }     long long int dp[n + 1];     dp[0] = 1;     for (int i = 1; i <= n; i++) {       dp[i] = (dp[i - 1] + fac[i - 1] - 1) * i;       dp[i] %= mod;     }     cout << dp[n] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int N, V, k, y;   vector<int> vec;   int main() {     cin >> N >> V;     for (int i = 1; i <= N; i++) {       cin >> k;       int x = 1000000000;       for (int j = 1; j <= k; j++) {         cin >> y;         x = min(x, y);       }       if (x < V) vec.push_back(i);     }     cout << vec.size() << endl;     for (int i = 0; i < vec.size(); i++) cout << vec[i] <<    ;     return (0);   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 1e9, mod = 1e9 + 7;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int t;     cin >> t;     while (t--) {       int a, b;       cin >> a >> b;       int ans = 0;       int x = abs(a - b);       ans += x / 5;       x %= 5;       ans += x / 2;       x %= 2;       ans += x;       cout << ans <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 2e9;   int fa[100010], n, cnt;   bitset<1010> G[1010], S[1010], vis;   int find(int x) {     if (fa[x] == x) return x;     return fa[x] = find(fa[x]);   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       int k, x;       scanf( %d , &k);       while (k--) {         scanf( %d , &x);         G[i][x] = 1;       }     }     for (int i = 1; i <= n; i++) {       fa[i] = i;     }     bitset<1010> t;     int u, v;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         t = (G[i] & G[j]);         if (t.count() == 2) {           u = 0, v = 0;           for (int k = 1; k <= n; k++) {             if (t[k]) {               if (!u)                 u = k;               else                 v = k;             }           }           int fa_u = find(u), fa_v = find(v);           if (fa_u != fa_v) {             fa[fa_u] = fa_v, cnt++;             printf( %d %d n , u, v);             vis[u] = vis[v] = 1;             S[u][u] = S[v][v] = S[u][v] = S[v][u] = 1;           }         }       }     }     if (cnt == 0) {       for (int i = 2; i <= n; i++) {         printf( 1 %d n , i);       }     } else if (cnt == 1) {       for (int i = 1; i <= n; i++) {         if (G[i].count() < n) {           for (int j = 1; j <= n; j++) {             if (!vis[j]) {               if (G[i][j]) {                 printf( %d %d n , u, j);               } else {                 printf( %d %d n , v, j);               }             }           }           break;         }       }     } else {       for (int i = 1; i <= n; i++) {         if (!vis[i]) {           int minn = INF;           for (int j = 1; j <= n; j++) {             if (G[j][i] && (G[j] & vis).count() < minn) {               t = (G[j] & vis), minn = t.count();             }           }           for (int j = 1; j <= n; j++) {             if (t[j] && t == S[j]) {               printf( %d %d n , i, j);               break;             }           }         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n;     cin >> n;     long long a[n], b[n];     for (long long i = 0; i < n; i++) {       cin >> a[i] >> b[i];     }     long long sum = 0;     long long price = 99999;     for (long long i = 0; i < n; i++) {       price = min(price, b[i]);       sum += price * a[i];     }     cout << sum << endl;   }


#include <bits/stdc++.h>   using namespace std;   int cmp(double x, double y) {     if (fabs(x - y) < 1e-7) return 0;     if (x < y) return -1;     return 1;   }   float call(double a, double b) {     double s1, s2;     if (cmp(a / 4, b) <= 0) {       s1 = b + a / 8;     } else {       double l1, l2, t1, t2;       l1 = b * 4;       t1 = b + b / 2;       l2 = a - l1;       t2 = 2 * b;       s1 = (l1 * t1 + l2 * t2) / a;     }     return s1 / (2 * b);   }   int main() {     int n, a, b;     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %d %d , &a, &b);       if (b == 0)         printf( 1 n );       else if (a == 0)         printf( 0.5 n );       else         printf( %.9lf n , call(a, b));     }   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 100005;   int BIT[4][11][MAXN * 2], n;   void add(int BIT[], int p, int x) {     for (int i = p; i <= n; i += ((i) & (-(i)))) BIT[i] += x;   }   int ask(int BIT[], int p) {     int res = 0;     for (int i = p; i; i -= ((i) & (-(i)))) res += BIT[i];     return res;   }   char str[MAXN], tmp[11];   ;   int biao[233];   int HASH(int i, int Base) {     --i;     return i / Base + (i % Base) * (n / Base) + min(i % Base, n % Base) + 1;   }   int main(void) {     biao[ A ] = 0;     biao[ G ] = 1;     biao[ C ] = 2;     biao[ T ] = 3;     scanf( %s , str + 1);     n = strlen(str + 1);     for (int i = 1; i <= n; ++i) {       str[i] = biao[str[i]];       for (int Base = 1; Base <= 10; ++Base) {         add(BIT[str[i]][Base], HASH(i, Base), 1);       }     }     int q;     cin >> q;     while (q--) {       int op, l, r;       scanf( %d%d , &op, &l);       if (op == 1) {         scanf( %s , tmp);         for (int Base = 1; Base <= 10; ++Base)           add(BIT[str[l]][Base], HASH(l, Base), -1);         str[l] = biao[tmp[0]];         for (int Base = 1; Base <= 10; ++Base)           add(BIT[str[l]][Base], HASH(l, Base), 1);       } else {         scanf( %d%s , &r, tmp);         int Base = min(int(strlen(tmp)), r - l + 1), res = 0;         for (int i = 0; i < Base; ++i) {           res += ask(BIT[biao[tmp[i]]][Base],                      HASH((r - l - i) / Base * Base + l + i, Base)) -                  ask(BIT[biao[tmp[i]]][Base], HASH(l + i, Base) - 1);         }         printf( %d n , res);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void printPath(vector<pair<int, int>> &path) {     for (auto it : path) cout << (it.first + 1) <<     << (it.second + 1) << endl;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     long long arr[n][n];     memset(arr, 0, sizeof(arr));     pair<long long, long long> achieve[n][n];     arr[0][0] = 0;     achieve[0][0] = {0, 0};     for (int k = 1; k < 2 * (n - 1); k++) {       long long prev = 0;       for (int i = 0; i < n; i++) {         int j = k - i;         if (j < 0 || j >= n) continue;         pair<long long, long long> available = {2000000000000000000, -1};         if (i) {           available.first = (available.first < achieve[i - 1][j].first                                  ? available.first                                  : achieve[i - 1][j].first);           available.second = (available.second > achieve[i - 1][j].second                                   ? available.second                                   : achieve[i - 1][j].second);         }         if (j) {           available.first = (available.first < achieve[i][j - 1].first                                  ? available.first                                  : achieve[i][j - 1].first);           available.second = (available.second > achieve[i][j - 1].second                                   ? available.second                                   : achieve[i][j - 1].second);         }         long long diff = prev - available.first;         arr[i][j] = diff;         available.first += diff;         available.second += diff;         achieve[i][j] = available;         prev = available.second + 1;       }     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) cout << arr[i][j] <<    ;       cout << endl;     }     int q;     cin >> q;     vector<pair<int, int>> path;     while (q--) {       long long x;       cin >> x;       int i = n - 1, j = n - 1;       while (i || j) {         x -= arr[i][j];         path.push_back({i, j});         if (i == 0) {           j--;           continue;         }         if (j == 0) {           i--;           continue;         }         if (achieve[i - 1][j].first <= x && x <= achieve[i - 1][j].second)           i--;         else           j--;       }       path.push_back({i, j});       reverse(path.begin(), path.end());       printPath(path);       path.clear();     }   }


#include <bits/stdc++.h>   using namespace std;   string ori;   string start;   string target;   int n;   char mapping[256];   char mapn[256];   char used[256];   bool apply(int a, int b) {     if ((mapping[a] == 0 && used[b] == false) || mapping[a] == b) {       mapping[a] = b;       used[b] = true;       mapn[a]++;       return true;     }     return false;   }   void undo(int a, int b) {     mapn[a]--;     if (mapn[a] == 0) {       used[mapping[a]] = 0;       mapping[a] = 0;     }   }   bool recurse(int i, bool eqa, bool eqb) {     if (i == ori.size())       return true;     else if (eqa && eqb) {       if (start[i] == target[i]) {         if (apply(ori[i], start[i])) {           if (recurse(i + 1, true, true)) {             return true;           }           undo(ori[i], start[i]);         }       } else {         for (int c = start[i]; c <= target[i]; c++) {           if (apply(ori[i], c)) {             if (recurse(i + 1, start[i] == c, target[i] == c)) {               return true;             }             undo(ori[i], start[i]);           }         }       }     } else if (eqa) {       for (int c =  a  + n; --c >= start[i];) {         if (apply(ori[i], c)) {           if (recurse(i + 1, start[i] == c, false)) {             return true;           }           undo(ori[i], c);           break;         }       }     } else if (eqb) {       for (int c =  a ; c <= target[i]; c++) {         if (apply(ori[i], c)) {           if (recurse(i + 1, false, target[i] == c)) {             return true;           }           undo(ori[i], c);           break;         }       }     } else {       return true;     }     return false;   }   void go() {     cin >> n;     cin >> ori >> start >> target;     memset(mapping, 0, sizeof(mapping));     memset(mapn, 0, sizeof(mapn));     memset(used, 0, sizeof(used));     bool res = recurse(0, true, true);     if (res) {       cout <<  YES n ;       set<char> unused;       for (int i =  a ; i <  a  + n; i++) {         if (not used[i]) {           unused.insert(i);         }       }       for (int i =  a ; i <  a  + n; i++) {         if (mapping[i] == 0) {           mapping[i] = *unused.begin();           unused.erase(unused.begin());         }       }       cout << mapping +  a ;       cout <<   n ;     } else {       cout <<  NO n ;     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int testn;     cin >> testn;     for (int testi = 1; testi <= testn; testi++) {       go();     }   }


#include <bits/stdc++.h>   using namespace std;   vector<int> g1[2111];   vector<int> g2[2111];   vector<int> v1, v2;   int s1[1111][1111];   int s2[1111][1111];   int N;   pair<int, int> dfs1(int v) {     pair<int, int> p = {1000, 0};     if (v1[v]) p = {v1[v], v1[v]};     for (auto to : g1[v]) {       auto cur = dfs1(to);       p.first = min(cur.first, p.first);       p.second = max(cur.second, p.second);     }     for (int i = 1; i <= p.first; ++i)       for (int j = p.second; j <= N; ++j) s1[i][j]++;     return p;   }   pair<int, int> dfs2(int v) {     pair<int, int> p = {1000, 0};     if (v2[v]) p = {v2[v], v2[v]};     for (auto to : g2[v]) {       auto cur = dfs2(to);       p.first = min(cur.first, p.first);       p.second = max(cur.second, p.second);     }     for (int i = 1; i <= p.first; ++i)       for (int j = p.second; j <= N; ++j) s2[i][j]++;     return p;   }   int dp[1111];   int main() {     cin >> N;     int n1;     cin >> n1;     for (int i = 2; i <= n1; ++i) {       int t;       cin >> t;       g1[t].push_back(i);     }     v1.assign(n1 + 1, 0);     for (int i = 1; i <= N; ++i) {       int t;       cin >> t;       v1[t] = i;     }     int n2;     cin >> n2;     for (int i = 2; i <= n2; ++i) {       int t;       cin >> t;       g2[t].push_back(i);     }     v2.assign(n2 + 1, 0);     for (int i = 1; i <= N; ++i) {       int t;       cin >> t;       v2[t] = i;     }     dfs1(1);     dfs2(1);     for (int i = 1; i <= N; ++i) {       for (int j = 1; j <= N; ++j) {         s1[i][j] = min(s1[i][j], n1 - 1);         s2[i][j] = min(s2[i][j], n2 - 1);       }     }     for (int i = 1; i <= N; ++i) {       int mx1 = s1[1][i];       int mx2 = s2[1][i];       dp[i] = max(mx1, mx2);       for (int j = i; j >= 2; --j) {         {           int cur = s1[j][i];           dp[i] = max(dp[i], dp[j - 1] + cur);         }         {           int cur = s2[j][i];           dp[i] = max(dp[i], dp[j - 1] + cur);         }       }     }     cout << dp[N] << endl;   }


#include <bits/stdc++.h>   int main() {     int s, v1, v2, t1, t2;     scanf( %d %d %d %d %d , &s, &v1, &v2, &t1, &t2);     int a = s * v1 + 2 * t1;     int b = s * v2 + 2 * t2;     if (a == b) {       printf( Friendship n );     } else if (a < b) {       printf( First n );     } else {       printf( Second n );     }   }


#include <bits/stdc++.h>   using namespace std;   const long long maxn = 5e5 + 10;   long long N, arr[maxn], use[maxn];   signed main() {     ios::sync_with_stdio(false);     cin.tie(0);     cin >> N;     for (register long long i = 1; i <= N; ++i) {       cin >> arr[i];     }     sort(arr + 1, arr + 1 + N);     long long pos = N / 2, l = pos + 1, r = N, ans = N;     while (pos >= 1) {       if (l <= r && arr[pos] * 2 <= arr[r]) {         --ans, --r;       }       pos--;     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     string s;     cin >> n >> s;     int ones = 0, zeros = 0;     for (char c : s) {       if (c ==  n ) ones++;       if (c ==  r ) zeros++;     }     while (ones--) cout <<  1  ;     while (zeros--) cout <<  0  ;     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T, typename U>   T pow_mod(T a, U b, int mod) {     T r = 1;     for (; b > 0; b >>= 1) {       if (b & 1) r = (long long)r * a % mod;       a = (long long)a * a % mod;     }     return r;   }   enum bit_op { AND, OR, XOR };   namespace bitwise_transform {   template <int P, typename T>   inline void fix(T &x) {     if (x >= P)       x -= P;     else if (x < 0)       x += P;   }   template <bit_op B, int P, bool inv = false, typename T>   void transform(T a[], int n) {     for (int len = 1; len < n; len <<= 1)       for (int i = 0; i < n; i += len << 1)         for (int j = i; j < i + len; ++j) {           T u = a[j], v = a[j + len];           if (B == AND) a[j] = v - u * inv, a[j + len] = u + v * (!inv);           if (B == OR) a[j] = u * (!inv) + v, a[j + len] = u - inv * v;           if (B == XOR) a[j] = u + v, a[j + len] = u - v;           if (P != -1) fix<P>(a[j]), fix<P>(a[j + len]);         }     if (B == XOR && inv) {       int in = pow_mod(n, P - 2, P);       for (int i = 0; i < n; ++i) {         if (P == -1)           a[i] /= n;         else           a[i] = (long long)a[i] * in % P;       }     }   }   template <bit_op B, int P = -1, typename T>   vector<T> convolve(vector<T> a, vector<T> b) {     int n = max(a.size(), b.size()), sz = 1;     while (sz < n) sz <<= 1;     a.resize(sz);     b.resize(sz);     transform<B, P>(a.data(), sz);     transform<B, P>(b.data(), sz);     for (int i = 0; i < sz; ++i) {       if (P == -1)         a[i] *= b[i];       else         a[i] = (long long)a[i] * b[i] % P;     }     transform<B, P, true>(a.data(), sz);     return a;   }   }  // namespace bitwise_transform   const int mod = 998244353, B = 36, C = B / 2;   inline void add(int &x, int y) {     x += y;     if (x >= mod) x -= mod;   }   inline int bp(int x) { return __builtin_popcount(x); }   int main() {     ios_base::sync_with_stdio(0), cin.tie(0);     int n, m;     cin >> n >> m;     vector<long long> b(B);     for (long long i = 0, x; i < n; ++i) {       cin >> x;       for (int j = B - 1; j >= 0; --j)         if ((x = min(x ^ b[j], x)) >> j & 1) {           b[j] = x;           break;         }     }     int len = B - count(b.begin(), b.end(), 0LL);     vector<int> y(1 << C);     for (int i = 0; i < 1 << C; ++i) {       int z = i;       for (int j = C - 1; j >= 0; --j)         if (z >> j & 1) z ^= b[j];       if (!z) y[i] = 1;     }     vector<int> ans(m + 1);     for (int k = 0; k < B; ++k) {       vector<int> x(1 << C);       for (int i = 0; i < 1 << C; ++i)         if (bp(i) == k) {           long long z = (long long)i << C;           for (int j = B - 1; j >= C; --j)             if (z >> j & 1) z ^= b[j];           if (!(z >> C)) x[z & ((1 << C) - 1)] += 1;         }       auto z = bitwise_transform::convolve<XOR, mod>(x, y);       for (int i = z.size() - 1; i >= 0; --i)         if (z[i]) add(ans[k + bp(i)], z[i]);     }     int p = pow_mod(2, n - len, mod);     for (int i = 0; i <= m; ++i)       cout << (long long)ans[i] * p % mod <<    n [i == m];     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, k, x, y, l, r, fact[200001], inv[200001], mod = 1e9 + 7;   map<int, int> m;   int powlog(int a, int b) {     if (b == 0) return 1;     int ret = powlog(a, b / 2);     if (b % 2) return 1LL * ret * ret % mod * a % mod;     return 1LL * ret * ret % mod;   }   int C(int n, int r) { return 1LL * fact[n] * inv[r] % mod * inv[n - r] % mod; }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);     fact[0] = inv[0] = 1;     for (int i = 1; i <= 200000; i++) {       fact[i] = 1LL * i * fact[i - 1] % mod;       inv[i] = powlog(fact[i], mod - 2);     }     cin >> n >> k;     for (int i = 0; i < n && cin >> x >> y; i++) m[x]++, m[y + 1]--;     long long ans = 0;     int prev = 0, lines = 0;     for (auto &i : m) {       if (lines >= k)         ans = (ans + 1LL * (i.first - prev) * C(lines, k) % mod) % mod;       lines += i.second;       prev = i.first;     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   template <typename T>   inline T range(T l, T r) {     return uniform_int_distribution<T>(l, r)(rng);   }   inline void setin(string s) { freopen(s.c_str(),  r , stdin); }   inline void setout(string s) { freopen(s.c_str(),  w , stdout); }   template <typename T>   void Min(T &a, T b) {     a = min(a, b);   }   template <typename T>   void Max(T &a, T b) {     a = max(a, b);   }   const int K = 2;   const int mod[K] = {998244353, 1000000007};   const int inf = 0x3f3f3f3f;   const int N = 1e4 + 15;   int n, q;   int dp[K][N];   bool ans[N];   struct query {     int x, val, t;     bool operator<(const query &rhs) const {       return make_pair(x, t) < make_pair(rhs.x, rhs.t);     }   };   vector<query> is;   inline int add(int a, int b, int mod) {     a += b;     if (a >= mod)       a -= mod;     else if (a < 0)       a += mod;     return a;   }   inline void add_t(int &a, int b, int mod) { a = add(a, b, mod); }   inline int mt(int a, int b, int mod) { return 1ll * a * b % mod; }   inline void add(int x, int coef) {     if (coef == 1)       for (int i = n - x; i >= 0; --i)         for (int j = 0; j < K; ++j) add_t(dp[j][i + x], dp[j][i], mod[j]);     else       for (int i = 0; i <= n - x; ++i)         for (int j = 0; j < K; ++j) add_t(dp[j][i + x], -dp[j][i], mod[j]);   }   int main() {     ios_base::sync_with_stdio(0);     cout.tie(0);     cin.tie(0);     cin >> n >> q;     for (int i = 1; i <= q; ++i) {       int l, r, x;       cin >> l >> r >> x;       is.push_back({l, x, 1});       is.push_back({r + 1, x, -1});     }     sort(is.begin(), is.end());     for (int j = 0; j < K; ++j) dp[j][0] = 1;     for (int i = 1, j = 0; i <= n; ++i) {       while (j < is.size() && is[j].x <= i) {         add(is[j].val, is[j].t);         ++j;       }       for (int y = 1; y <= n; ++y) {         bool flag = false;         for (int j = 0; j < K; ++j) flag |= dp[j][y];         ans[y] |= flag;       }     }     int cnt = 0;     for (int i = 1; i <= n; ++i) cnt += ans[i];     cout << cnt <<   n ;     for (int i = 1; i <= n; ++i)       if (ans[i]) cout << i <<    ;     cout <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 10, M = 1e6 + 10, K = 2e4 + 10;   int head[N], h2[N], cur[N], dep[N], to[M], lim[M], nxt[M], vis[N], cnt = 1, n,                                                                      m, s, t;   void add_edge(int u, int v, int l, int *head) {     nxt[++cnt] = head[u], head[u] = cnt, lim[cnt] = l, to[cnt] = v;     nxt[++cnt] = head[v], head[v] = cnt, lim[cnt] = 0, to[cnt] = u;   }   bool bfs() {     queue<int> q;     memset(dep, 0x3f, sizeof(dep));     memset(vis, 0, sizeof(vis));     memcpy(cur, head, sizeof(cur));     dep[s] = 0;     q.push(s);     while (!q.empty()) {       int h = q.front();       vis[h] = 0;       q.pop();       for (int i = head[h]; i; i = nxt[i])         if ((dep[to[i]] > dep[h] + 1) && lim[i]) {           dep[to[i]] = dep[h] + 1;           if (!vis[to[i]]) vis[to[i]] = 1, q.push(to[i]);         }     }     if (dep[t] != 0x3f3f3f3f) return true;     return false;   }   long long dfs(int rt = s, long long flow = 1e18) {     if (rt == t) return flow;     long long f = 0, ans = 0;     for (int i = cur[rt]; i; i = nxt[i]) {       cur[rt] = i;       if (lim[i] && dep[to[i]] == dep[rt] + 1) {         f = dfs(to[i], min(flow - ans, 1ll * lim[i]));         if (f) {           lim[i] -= f;           lim[i ^ 1] += f;           ans += f;           if (ans == flow) break;         }       }     }     return ans;   }   long long dinic() {     long long ans = 0, flow;     while (bfs()) {       while (flow = dfs()) ans += flow;     }     return ans;   }   vector<int> ans, edg;   int nd, P[N], Q[N], Dep[K], fa[K], siz[K], son[K], top[K], id[K], tim, eid[N];   bool _vis[N];   void dfs1(int rt, int f, int e = 0) {     fa[rt] = f, siz[rt] = 1, Dep[rt] = Dep[f] + 1, eid[rt] = e;     for (int i = h2[rt]; i; i = nxt[i])       if (to[i] != f) {         dfs1(to[i], rt, lim[i]);         siz[rt] += siz[to[i]];         if (siz[to[i]] > top[rt]) top[rt] = siz[to[i]], son[rt] = to[i];       }   }   void dfs2(int rt, int t) {     top[rt] = t, id[rt] = ++tim;     if (son[rt]) dfs2(son[rt], t);     for (int i = h2[rt]; i; i = nxt[i])       if (to[i] != fa[rt] && to[i] != son[rt]) dfs2(to[i], to[i]);   }   void dfs3(int rt) {     vis[rt] = 1;     for (int i = head[rt]; i; i = nxt[i])       if (lim[i] && !vis[to[i]]) dfs3(to[i]);   }   void build(int l = 1, int r = n, int rt = 1) {     P[rt] = ++nd;     if (l == r) return Q[l] = P[rt], add_edge(P[rt], t, 1, head);     int mid = (l + r) >> 1;     build(l, mid, (rt << 1)), build(mid + 1, r, ((rt << 1) | 1));     add_edge(P[rt], P[(rt << 1)], 1e9, head),         add_edge(P[rt], P[((rt << 1) | 1)], 1e9, head);   }   void _add_edges(int L, int R, int u, int l = 1, int r = n, int rt = 1) {     if (L <= l && r <= R) return add_edge(u, P[rt], 1e9, head);     int mid = (l + r) >> 1;     if (L <= mid) _add_edges(L, R, u, l, mid, (rt << 1));     if (R > mid) _add_edges(L, R, u, mid + 1, r, ((rt << 1) | 1));   }   void add_edges(int u, int v, int from) {     while (top[u] != top[v]) {       if (Dep[top[u]] < Dep[top[v]]) swap(u, v);       _add_edges(id[top[u]], id[u], from);       u = fa[top[u]];     }     if (Dep[u] > Dep[v]) swap(u, v);     if (u == v) return;     _add_edges(id[u] + 1, id[v], from);   }   int main() {     ios::sync_with_stdio(false);     cin >> n >> m;     int u, v;     for (int i = 1; i < n; ++i)       cin >> u >> v, add_edge(u, v, i, h2), lim[cnt] = i;     dfs1(1, 0);     dfs2(1, 1);     nd = m;     s = ++nd, t = ++nd;     build();     for (int i = 1; i <= m; ++i) add_edge(s, i, 1, head);     for (int i = 1; i <= m; ++i) {       cin >> u >> v;       add_edges(u, v, i);     }     cout << dinic() << endl;     dfs3(s);     for (int i = 1; i <= m; ++i)       if (!vis[i]) ans.push_back(i);     for (int i = 2; i <= n; ++i)       if (vis[Q[id[i]]]) edg.push_back(eid[i]);     cout << ans.size() <<    ;     for (auto i : ans) cout << i <<    ;     cout << endl << edg.size() <<    ;     for (auto i : edg) cout << i <<    ;   }


#include <bits/stdc++.h>   using namespace std;   long long in() {     int32_t x;     scanf( %d , &x);     return x;   }   inline long long lin() {     long long x;     scanf( %lld , &x);     return x;   }   inline void read(long long *a, long long n) {     for (long long i = 0; i < n; i++) a[i] = in();   }   inline void readL(long long *a, long long n) {     for (long long i = 0; i < n; i++) a[i] = lin();   }   const long long maxn = 100 + 10;   const long long mod = 1e9 + 7;   const long long MAX_VAL = 1e18 + 10;   const long long MAGIC = 350;   long long n, m;   vector<pair<long long, long long> > g[maxn];   long long dp[maxn][maxn][27];   long long ret[maxn][maxn];   inline long long dfs(long long a, long long b, long long pre) {     if (pre >= 26) return 1;     if (dp[a][b][pre] + 1) return dp[a][b][pre];     for (auto u : g[a]) {       if (u.second >= pre) {         long long getRes = dfs(b, u.first, u.second);         if (getRes == 1) return dp[a][b][pre] = 0;       }     }     return dp[a][b][pre] = 1;   }   int32_t main() {     n = in(), m = in();     memset(dp, -1, sizeof dp);     for (long long i = 0; i < m; i++) {       long long v = in() - 1, u = in() - 1;       char ch;       do {         ch = getchar();       } while (!isalpha(ch));       g[v].push_back({u, ch -  a });     }     for (long long a = 0; a < n; a++, cout <<   n ) {       for (long long b = 0; b < n; b++) {         ret[a][b] = dfs(a, b, 0);         if (ret[a][b] == 0)           cout <<  A ;         else           cout <<  B ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 300000 + 10;   const long long MOD = 1000000000 + 7;   const long long INF = 10000000;   vector<long long> Poi;   unordered_map<long long, long long> koj;   long long q, SEG[4 * N][2], lazy[4 * N];   vector<pair<int, pair<long long, long long>>> Q;   void modify(int id, int l, int r, int x) {     if (x == -1) return;     if (x == 0) {       SEG[id][0] = INF;       SEG[id][1] = l;       lazy[id] = x;       return;     }     if (x == 1) {       SEG[id][0] = l;       SEG[id][1] = INF;       lazy[id] = x;       return;     }     if (lazy[id] == -1) {       swap(SEG[id][0], SEG[id][1]);       lazy[id] = x;       return;     }     if (lazy[id] == 2) {       swap(SEG[id][0], SEG[id][1]);       lazy[id] = -1;       return;     }     if (lazy[id] == 0) {       SEG[id][0] = l;       SEG[id][1] = INF;       lazy[id] = 1;       return;     }     SEG[id][0] = INF;     SEG[id][1] = l;     lazy[id] = 0;     return;   }   void shift(int id, int l, int r) {     int mid = (l + r) >> 1;     modify(id << 1, l, mid, lazy[id]);     modify(id << 1 | 1, mid, r, lazy[id]);     lazy[id] = -1;     return;   }   void build(int id, int l, int r) {     if (r - l == 1) {       SEG[id][0] = l;       SEG[id][1] = INF;       return;     }     int mid = (l + r) >> 1;     build(id << 1, l, mid);     build(id << 1 | 1, mid, r);     SEG[id][0] = l;     SEG[id][1] = INF;     return;   }   void update(int id, int lq, int rq, int x, int l, int r) {     if (rq <= l || r <= lq) {       return;     }     if (lq <= l && r <= rq) {       modify(id, l, r, x);       return;     }     int mid = (l + r) >> 1;     shift(id, l, r);     update(id << 1, lq, rq, x, l, mid);     update(id << 1 | 1, lq, rq, x, mid, r);     SEG[id][0] = min(SEG[id << 1][0], SEG[id << 1 | 1][0]);     SEG[id][1] = min(SEG[id << 1][1], SEG[id << 1 | 1][1]);     return;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> q;     while (q--) {       long long x, l, r;       cin >> x >> l >> r;       Poi.push_back(l);       Poi.push_back(r);       Poi.push_back(r + 1);       Q.push_back({x, {l, r}});     }     Poi.push_back(1);     sort(Poi.begin(), Poi.end());     Poi.push_back(1000000000000000001);     Poi.resize(unique(Poi.begin(), Poi.end()) - Poi.begin());     for (int i = 0; i < Poi.size(); i++) {       koj[Poi[i]] = i + 1;     }     for (int i = 0; i < 4 * N; i++) {       SEG[i][0] = INF;       SEG[i][1] = INF;     }     memset(lazy, -1, sizeof lazy);     build(1, 1, N);     for (auto u : Q) {       update(1, koj[u.second.first], koj[u.second.second] + 1, u.first - 1, 1, N);       cout << Poi[SEG[1][0] - 1] <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int oo = 0x3f3f3f3f;   const int max0 = 1e7;   const int maxm = 400;   const int maxabs = 101;   const int max1 = 1e3;   bool a[(maxabs << 1) + 5][(maxabs << 1) + 5] = {{0}};   int pre[(max1 << 1) + 5][(max1 << 1) + 5] = {{0}};   int n, ax, ay, bx, by;   int walk[4][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};   char cr[4] = { U ,  D ,  R ,  L };   bool go(const int &first) {     putchar(cr[first]);     ax += walk[first][0], ay += walk[first][1];     int ux = bx + walk[first][0], uy = by + walk[first][1];     if (ux >= 0 && ux <= maxabs << 1 && uy >= 0 && uy <= maxabs << 1 && a[ux][uy])       return 0;     bx = ux, by = uy;     return 1;   }   void bfs(const int &ax, const int &ay) {     static pair<int, int> q[max0 + 5];     memset(pre, -1, sizeof pre);     pre[ax + max1][ay + max1] = 4;     int tot = 0;     q[tot++] = make_pair(ax, ay);     for (int i = 0; i != tot; ++i) {       const pair<int, int> &first = q[i];       for (int j = (0), _end_ = (4); j != _end_; ++j) {         int ux = first.first + walk[j][0], uy = first.second + walk[j][1];         if (ux < -max1 || uy < -max1 || ux >= max1 << 1 || uy >= max1 << 1 ||             pre[ux + max1][uy + max1] != -1)           continue;         if (ux >= 0 && ux <= maxabs << 1 && uy >= 0 && uy <= maxabs << 1 &&             a[ux][uy])           continue;         pre[ux + max1][uy + max1] = j;         q[tot++] = make_pair(ux, uy);       }     }   }   void trace_path(const int &first, const int &second, const int &bx,                   const int &by, const bool &flag = 0) {     static int qq[max0 + 5];     int ux = first, uy = second;     int tot = 0;     while (ux != bx || uy != by) {       int tmp = pre[ux + max1][uy + max1];       qq[tot++] = tmp;       ux -= walk[tmp][0], uy -= walk[tmp][1];     }     reverse(qq, qq + tot);     for (int i = 0; i != tot; ++i) {       if (go(qq[i]) && flag) qq[tot++] = qq[i];       if (ax == ::bx && ay == ::by) break;     }   }   void solve_inf() {     memset(pre, -1, sizeof pre);     if (ay > by) {       swap(cr[0], cr[1]);       for (int i = (0), _end_ = (maxabs); i != _end_; ++i)         for (int j = (0), _end_ = (maxabs << 1); j <= _end_; ++j)           swap(a[j][i], a[j][(maxabs << 1) - i]);       ay = (maxabs << 1) - ay, by = (maxabs << 1) - by;     }     if (ax > bx) {       swap(cr[2], cr[3]);       for (int i = (0), _end_ = (maxabs); i != _end_; ++i)         for (int j = (0), _end_ = (maxabs << 1); j <= _end_; ++j)           swap(a[i][j], a[(maxabs << 1) - i][j]);       ax = (maxabs << 1) - ax, bx = (maxabs << 1) - bx;     }     bfs(ax, ay), trace_path(0, 0, ax, ay);     for (int i = (0), _end_ = (maxabs * 3); i != _end_; ++i) go(1);     bfs(bx, by), trace_path(0, 0, bx, by);     pair<int, int> yyt = make_pair(oo, oo);     for (int i = (0), _end_ = (maxabs << 1); i <= _end_; ++i)       for (int j = (0), _end_ = (maxabs << 1); j <= _end_; ++j)         if (a[i][j]) yyt = min(yyt, make_pair(j, i));     swap(yyt.first, yyt.second);     while (bx != yyt.first) go(2);     while (ay != by || by != yyt.second - 1) go(0);     go(3), go(0);     while (ax != bx) go(2);     exit(0);   }   int main() {     scanf( %d%d%d%d%d , &ax, &ay, &bx, &by, &n), ax += maxabs, ay += maxabs,         bx += maxabs, by += maxabs;     if (!n) printf( -1 n ), exit(0);     for (int i = (0), _end_ = (n); i != _end_; ++i) {       static int first, second;       scanf( %d%d , &first, &second);       a[first + maxabs][second + maxabs] = 1;     }     bfs(ax, ay);     if (pre[bx + max1][by + max1] == -1) printf( -1 n ), exit(0);     if (pre[max1][max1] != -1) solve_inf();     trace_path(bx, by, ax, ay, 1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     size_t n, m, q;     cin >> n >> m >> q;     vector<uint32_t> perm(n);     for (size_t i = 0; i < n; ++i) {       cin >> perm[i];       perm[i]--;     }     vector<uint32_t> a(m);     for (size_t i = 0; i < m; ++i) {       cin >> a[i];       a[i]--;     }     vector<uint32_t> next(n);     next[perm.back()] = perm.front();     for (size_t i = 0; i < n - 1; ++i) {       next[perm[i]] = perm[i + 1];     }     constexpr static auto IMPOSSIBLE = numeric_limits<size_t>::max();     size_t log2n = 8 * sizeof(int) - __builtin_clz((int)n);     vector<vector<size_t>> cycle_ends(log2n);     for (size_t i = 0; i < log2n; ++i) {       cycle_ends[i].resize(m);     }     vector<size_t> closest_next(n, IMPOSSIBLE);     for (int i = m - 1; i >= 0; --i) {       cycle_ends[0][i] = closest_next[next[a[i]]];       closest_next[a[i]] = i;     }     for (size_t i = 1; i < log2n; ++i) {       for (size_t j = 0; j < m; ++j) {         auto next = cycle_ends[i - 1][j];         cycle_ends[i][j] =             next == IMPOSSIBLE ? IMPOSSIBLE : cycle_ends[i - 1][next];       }     }     vector<size_t> bits;     for (size_t i = 0; i < log2n; ++i) {       if (((n - 1) >> i) & 1) {         bits.emplace_back(i);       }     }     vector<size_t> min_right(m);     size_t closest = IMPOSSIBLE;     for (int i = m - 1; i >= 0; --i) {       size_t next = i;       for (auto j : bits) {         next = cycle_ends[j][next];         if (next == IMPOSSIBLE) {           break;         }       }       closest = min(closest, next);       min_right[i] = closest;     }     for (size_t i = 0; i < q; ++i) {       size_t l, r;       cin >> l >> r;       cout << (int)(min_right[l - 1] <= r - 1);     }     cout <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int q;     scanf( %d , &q);     while (q--) {       int n;       scanf( %d , &n);       vector<int> a(n);       for (int i = 0; i < n; i++) scanf( %d , &a[i]);       sort(a.begin(), a.end());       a.erase(unique(a.begin(), a.end()), a.end());       n = a.size();       int ans = a.back();       for (int i = n - 1; i >= 0; i--) {         if (i >= 2) {           if (ans > a[i] + a[i - 1] + a[i - 2]) break;         }         for (int j = i - 1; j >= 0; j--) {           if (j >= 1) {             if (ans > a[i] + a[j] + a[j - 1]) break;           }           if (a[i] % a[j]) {             ans = max(ans, a[i] + a[j]);             for (int k = j - 1; k >= 0; k--) {               if (ans > a[i] + a[j] + a[k]) break;               if ((a[i] % a[k]) && (a[j] % a[k])) {                 ans = max(ans, a[i] + a[j] + a[k]);                 break;               }             }           }         }       }       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 500010;   int n, a[N], rt = 1, ba[30], sta[N], top = 0;   vector<int> e[N];   long long ans;   void dfs(int u, int ff) {     sta[++top] = u;     if (ff) {       long long w = a[sta[top - 1]];       int i = 1;       for (; top - ba[i] > 0; i++)         if (w > (long long)(i + 1) * a[sta[top - ba[i]]])           w = (long long)(i + 1) * a[sta[top - ba[i]]];       if (w > (long long)(i + 1) * a[rt]) w = (long long)(i + 1) * a[rt];       ans += w + (long long)a[u];     }     for (auto v : e[u])       if (v ^ ff) dfs(v, u);     --top;   }   int main() {     ba[0] = 1;     for (int i = 1; i < 25; i++) ba[i] = ba[i - 1] * 2;     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);       if (a[i] < a[rt]) rt = i;     }     for (int i = 1, x, y; i < n; i++)       scanf( %d%d , &x, &y), e[x].push_back(y), e[y].push_back(x);     dfs(rt, 0), printf( %I64d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long int mod = 1e9 + 7;   long long quickpow(long long a, long long b) {     long long ans = 1;     a = a % mod;     while (b > 0) {       if (b % 2) ans = ans * a;       b = b / 2;       a = a * a;     }     return ans;   }   int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }   long long a[500005];   long long sum[500005];   long long tot = 0;   int main() {     ios::sync_with_stdio(false);     int n;     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> a[i];     }     sort(a + 1, a + n + 1);     for (int i = 1; i <= n; i++) {       sum[i] = sum[i - 1] + a[i];     }     tot += sum[n];     for (int i = 1; i <= n - 1; i++) {       tot += (sum[n] - sum[i - 1]);     }     cout << tot << endl;   }


#include <iostream>   #include <string>   #include <vector>   #include <algorithm>   #include <sstream>   #include <queue>   #include <deque>   #include <bitset>   #include <iterator>   #include <list>   #include <stack>   #include <map>   #include <set>   #include <functional>   #include <numeric>   #include <utility>   #include <limits>   #include <time.h>   #include <math.h>   #include <stdio.h>   #include <string.h>   #include <stdlib.h>   #include <assert.h>      using namespace std;      #define ll long long int   #define nl cout<<  n ;   #define pb push_back      void solve(){       ll a[4],b[4],i;       for(i=0;i<4;i++){           cin>>a[i];           b[i]=a[i];       }       ll c=max(a[0],a[1]),d=max(a[2],a[3]);       sort(b,b+4);       if(max(b[3],b[2])==max(c,d) && min(b[3],b[2])==min(c,d))           cout<< YES n ;       else           cout<< NO n ;   }      int main(){       ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);       int t=1;       cin>>t;       while(t--){           solve();       }       return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> odd;   int main() {     int n, t;     cin >> n;     long long cnt = 0, res = -1e9;     for (int i = 0; i < n; i++) {       cin >> t;       if (abs(t) % 2 == 1)         odd.push_back(t);       else if (t > 0)         cnt += t;     }     sort(odd.begin(), odd.end());     bool flag = 0;     int sz = odd.size();     for (int i = sz - 1; i >= 0; i--) {       cnt += odd[i];       if (abs(cnt) % 2 == 1) res = max(cnt, res);     }     cout << res << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long double n, k;     cin >> n >> k;     string s;     cin >> s;     set<string, greater<string> > st;     queue<string> stk;     stk.push(s);     while (k && !stk.empty()) {       string temp = stk.front();       stk.pop();       if (st.find(temp) == st.end()) {         st.insert(temp);         k--;         for (long double i = 0; i < temp.length(); i++) {           string s1 = temp;           s1.erase(s1.begin() + i);           if (s1.size()) stk.push(s1);         }       }     }     long double ans = 0;     if (k == 0 || (k == 1 && stk.empty())) {       for (auto i = st.begin(); i != st.end(); i++) {         ans += (n - (*i).length());       }       if (stk.empty()) ans += n;       cout << ans << endl;     } else {       cout << -1 << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1010;   int dp[N], c[N];   long long ncr[N][N];   void pascal() {     ncr[0][0] = 1;     for (int i = 1; i < N; i++) {       ncr[i][0] = 1;       for (int j = 1; j <= i; j++) {         ncr[i][j] = (ncr[i - 1][j] + ncr[i - 1][j - 1]) % 1000000007;       }     }   }   int main() {     pascal();     int k;     cin >> k;     for (int i = 0; i < (int)(k); ++i) cin >> c[i];     long long res = 1, total = 0;     for (int i = 0; i < (int)(k); ++i) {       res = (res * ncr[(total + c[i] - 1)][c[i] - 1]) % 1000000007;       total += c[i];     }     cout << res << endl;   }


#include <bits/stdc++.h>   using namespace std;   int MSB1(long long x) {     int d = 0;     while ((1LL << d) <= x) d++;     return d;   }   int main() {     int n, m;     cin >> n >> m;     struct Elm {       int l, r, x;     };     vector<vector<Elm>> vals(n);     while (m--) {       int op;       cin >> op;       if (op == 1) {         int t, l, r, x;         cin >> t >> l >> r >> x, t--;         vals[t].emplace_back(Elm{l, r, x});         continue;       }       int t, v;       cin >> t >> v, t--;       set<int> se;       for (int l = v, r = v; t < n; t++, l += MSB1(l - 1), r += MSB1(r)) {         for (auto &e : vals[t])           if (e.l <= r && l <= e.r) se.emplace(e.x);       }       cout << se.size() << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool isprime(int n) {     for (int i = (2); i < (sqrt(n) + 1); ++i)       if (n % i == 0) return false;     return true;   }   int main() {     vector<int> ans;     int h[400] = {0};     for (int i = 4; i < 400; i += 2) h[i] = 1;     h[2] = 0;     h[1] = 1;     for (int i = 3; i < 400; i += 2)       if (!h[i]) {         for (int j = i; j * i < 400; j += 2)           if (!h[j * i]) h[j * i] = 1;       }     int n, sp, diff;     scanf( %d , &n);     if (n == 3) {       printf( 1 n3 );       return 0;     }     for (int i = (n - 1); i >= (2); --i)       if (isprime(i)) {         sp = i;         break;       }     ans.push_back(sp);     diff = n - sp;     if (!h[diff])       ans.push_back(diff);     else {       for (int i = (2); i < (diff); ++i)         if (!h[i] && !h[diff - i]) {           ans.push_back(i), ans.push_back(diff - i);           break;         }     }     printf( %d n , ans.size());     for (int i = (0); i < (ans.size()); ++i) printf( %d  , ans[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int n;     cin >> n;     vector<pair<long double, long double> > v(n);     int k = 0;     for (int i = 0; i < n; ++i) {       long double a, b, c;       cin >> a >> b >> c;       if (c == 0) ++k;       long double m = a * a + b * b;       v[i].first = -a * c / m;       v[i].second = -b * c / m;     }     int ans = 0;     for (int i = 0; i < n; ++i) {       if (v[i].first != 0 || v[i].second != 0 || k < 2) {         map<double, int> m;         int inf = 0;         for (int j = i + 1; j < n; ++j) {           long double dy = v[i].second - v[j].second,                       dx = v[i].first - v[j].first;           if (dx == 0)             ++inf;           else             ++m[double(dy / dx)];         }         ans += (inf * (inf - 1)) / 2;         for (auto it = m.begin(); it != m.end(); ++it) {           ans += ((it->second) * (it->second - 1)) / 2;         }       } else {         --k;         map<double, int> m;         int inf = 0;         for (int j = i + 1; j < n; ++j) {           long double dy = v[i].second - v[j].second,                       dx = v[i].first - v[j].first;           if (dx == 0)             ++inf;           else             ++m[double(dy / dx)];         }         ans += ((inf - 1) * (inf - 2)) / 2;         for (auto it = m.begin(); it != m.end(); ++it) {           ans += ((it->second) * (it->second - 1)) / 2;         }         ans += n - i - 2;       }     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   vector<long long unsigned> p_pow;   vector<long long unsigned> reverse_p_pow;   const int hash_base = 31;   long long unsigned binpow(long long unsigned a, long long unsigned n) {     long long res = 1;     while (n) {       if (n & 1) res *= a;       a *= a;       n >>= 1;     }     return res;   };   const long long unsigned MAX_DEGREE = binpow(2, 63) - 1;   vector<long long unsigned> init_p_pow(int length_of_vector) {     vector<long long unsigned> res(length_of_vector);     long long unsigned p_pow = (long long unsigned)hash_base;     res[0] = 1;     for (size_t i = 1; i < length_of_vector; i++)       if (i) res[i] = res[i - 1] * p_pow;     return res;   }   vector<long long unsigned> init_reverse_p_pow(       vector<long long unsigned> p_pow) {     vector<long long unsigned> result(p_pow.size());     int l = p_pow.size();     for (int i = 0; i < l; i++) result[i] = binpow(p_pow[i], MAX_DEGREE);     return result;   };   vector<int> zfunction(string s) {     int n = s.length();     vector<int> z(n, 0);     for (int i = 1, l = 0, r = 0; i < n; i++) {       if (i <= r) z[i] = min(r - i + 1, z[i - l]);       while (i + z[i] < n && s[z[i]] == s[i + z[i]]) ++z[i];       if (i + z[i] - 1 > r) l = i, r = i + z[i] - 1;     }     return z;   }   pair<string, vector<long long unsigned> > getHashes(string s) {     if (p_pow.size() == 0) p_pow = init_p_pow(2000);     if (reverse_p_pow.size() == 0) reverse_p_pow = init_reverse_p_pow(p_pow);     vector<long long unsigned> result(s.length());     int l = s.length();     for (int i = 0; i < l; i++) {       result[i] = (s[i] -  a  + 1) * p_pow[i];       if (i) result[i] += result[i - 1];     }     return make_pair(s, result);   }   inline long long unsigned get_hash_substr(       pair<string, vector<long long unsigned> > h, int i, int j) {     long long unsigned res = 0;     res = h.second[j];     if (i) res -= h.second[i - 1];     res *= reverse_p_pow[i];     return res;   }   int main() {     string t, a, b;     cin >> t >> a >> b;     vector<int> za = zfunction(a +  #  + t);     vector<int> zb = zfunction(b +  #  + t);     vector<int> ia(t.length(), 0);     vector<int> ib(t.length(), 0);     int la = a.length();     int lb = b.length();     int lt = t.length();     pair<string, vector<long long unsigned> > t_hash = getHashes(t),                                               a_hash = getHashes(a),                                               b_hash = getHashes(b);     int intersection = 0;     int i1 = la - 1;     int j2 = 0;     int count = 1;     int mi = min(la, lb);     bool f = false;     long long unsigned ha, hb;     while (count <= mi) {       f = false;       ha = a_hash.second[la - 1];       if (i1) ha -= a_hash.second[i1 - 1];       ha *= reverse_p_pow[i1];       hb = b_hash.second[j2];       hb *= reverse_p_pow[0];       f = (ha == hb);       if (f)         if (count > intersection) intersection = count;       i1--;       j2++;       count++;     }     long long unsigned *answer = new long long unsigned[2001000];     int len_ans = 0;     int c1 = 0, c2 = 0;     for (int i = 0; i < lt; i++) {       if (za[la + 1 + i] == la)         ia[i] = 1;       else         c1++;       if (zb[lb + 1 + i] == lb)         ib[i] = 1;       else         c2++;     }     if (c2 + c1 == 2 * lt) {       cout << 0;       return 0;     }     for (int i = 0; i < lt; i++) {       if (ia[i]) {         for (int j = i + la - intersection; j < lt; j++) {           if (ib[j]) {             long long unsigned h = t_hash.second[j + lb - 1];             if (i) h -= t_hash.second[i - 1];             h *= reverse_p_pow[i];             answer[len_ans] = h;             len_ans++;           }         }       }     }     sort(answer, answer + len_ans);     int ans_count = 0;     for (int i = 0; i < len_ans - 1; i++) {       if (answer[i] != answer[i + 1]) ans_count++;     }     if (len_ans) ans_count++;     cout << ans_count;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int s = 1e6;   int vis[s];   int main() {     int n, t;     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %d , &t);       vis[t] = 1;     }     printf( %d n , n);     int num = 0;     for (int i = 0; i < s + 2; i++) {       if (vis[i] == 1) {         if (vis[s - i + 1] == 0) {           printf( %d  , s - i + 1);           num++;         }       }     }     for (int i = 1; num < n; i++) {       if (vis[i] == 0 && vis[s - i + 1] == 0) {         printf( %d %d  , s - i + 1, i);         num += 2;       }     }     puts(  );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, cnt = 0, cnt2 = 0;     cin >> n;     int w;     for (int i = 0; i < n; i++) {       cin >> w;       if (w == 100) cnt++;       if (w == 200) cnt2++;     }     if (cnt == 0 && cnt2 % 2 != 0) {       cout <<  NO ;       return 0;     }     if (cnt % 2 == 0)       cout <<  YES ;     else       cout <<  NO ;     return 0;   }