#include <bits/stdc++.h>   using namespace std;   const int maxn = 200005;   const int INF = 0x3f3f3f3f;   const double PI = acos(-1.0);   const double EPS = 1e-9;   inline int sgn(double a) { return a < -EPS ? -1 : a > EPS; }   struct node {     long long v;     int id;     int date;     node(long long a = 0, int b = 0, int c = 0) {       v = a;       id = b;       date = c;     }   };   bool cmp(node x, node y) { return x.v < y.v; }   int n, m, k;   long long s;   long long a[maxn];   long long b[maxn];   int t[maxn];   long long c[maxn];   int p1[maxn];   int p2[maxn];   vector<node> ans;   bool judge(int x) {     ans.clear();     for (int i = 1; i <= m; i++) {       if (t[i] == 1) {         node xx = node((long long)(a[p1[x]] * c[i]), i, p1[x]);         ans.push_back(xx);       } else {         node xx = node((long long)(b[p2[x]] * c[i]), i, p2[x]);         ans.push_back(xx);       }     }     sort(ans.begin(), ans.end(), cmp);     long long sum = 0;     for (int i = 0; i < k; i++) {       sum += ans[i].v;     }     return sum <= s;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n >> m >> k >> s;     p1[0] = 1;     p2[0] = 1;     for (int i = 1; i <= n; i++) {       cin >> a[i];       if (a[i] < a[p1[i - 1]]) {         p1[i] = i;       } else         p1[i] = p1[i - 1];     }     for (int i = 1; i <= n; i++) {       cin >> b[i];       if (b[i] < b[p2[i - 1]])         p2[i] = i;       else         p2[i] = p2[i - 1];     }     for (int i = 1; i <= m; i++) {       cin >> t[i] >> c[i];     }     int l = 0;     int r = n + 1;     int mid;     while (l + 1 < r) {       mid = (l + r) >> 1;       if (judge(mid)) {         r = mid;       } else         l = mid;     }     if (r == n + 1) {       cout << -1 <<   n ;       return 0;     }     judge(r);     int tt = 0;     for (int i = 0; i < k; i++) {       tt = max(tt, ans[i].date);     }     cout << tt <<   n ;     for (int i = 0; i < k; i++) {       cout << ans[i].id <<     << ans[i].date <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 3e5 + 10, M = (1 << 18);   int n, a[N], fa[N], cnt;   long long ans;   pair<int, int> mx[M][2], cur[M];   int getfa(int x) { return fa[x] == x ? x : fa[x] = getfa(fa[x]); }   bool merge(int x, int y) {     x = getfa(x), y = getfa(y);     if (x == y) return 0;     fa[x] = y;     return 1;   }   int main() {     cin >> n;     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]), fa[i] = i;       ans -= a[i];     }     cnt = n + 1;     while (cnt > 1) {       for (int i = 0; i <= M - 1; i++)         for (int j = 0; j <= 1; j++) mx[i][j] = make_pair(-1, -1);       for (int i = 0; i <= n; i++) {         pair<int, int> t = make_pair(a[i], getfa(i));         if (mx[a[i]][0] < t) {           if (mx[a[i]][0].second != t.second) mx[a[i]][1] = mx[a[i]][0];           mx[a[i]][0] = t;         } else if (mx[a[i]][1] < t) {           if (mx[a[i]][0].second != t.second) mx[a[i]][1] = t;         }       }       for (int i = 0; i <= M - 1; i++) {         for (int j = 0; j <= 18; j++) {           if (i & (1 << j)) {             for (int k = 0; k <= 1; k++) {               if (mx[i][0] < mx[i ^ (1 << j)][k]) {                 if (mx[i][0].second != mx[i ^ (1 << j)][k].second)                   mx[i][1] = mx[i][0];                 mx[i][0] = mx[i ^ (1 << j)][k];               } else if (mx[i][1] < mx[i ^ (1 << j)][k]) {                 if (mx[i][0].second != mx[i ^ (1 << j)][k].second)                   mx[i][1] = mx[i ^ (1 << j)][k];               }             }           }         }       }       for (int i = 0; i <= n; i++) cur[i] = make_pair(-1, -1);       for (int i = 0; i <= n; i++) {         int f = getfa(i);         int t = ((M - 1) ^ a[i]);         if (mx[t][0].second != -1 && mx[t][0].second != f) {           cur[f] = max(cur[f], make_pair(mx[t][0].first + a[i], mx[t][0].second));         } else if (mx[t][1].second != -1 && mx[t][1].second != f) {           cur[f] = max(cur[f], make_pair(mx[t][1].first + a[i], mx[t][1].second));         }       }       for (int i = 0; i <= n; i++) {         if (fa[i] == i && merge(i, cur[i].second)) {           cnt--, ans += cur[i].first;         }       }     }     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   const int LG = 21;   const int N = 1000005;   const long long MOD = 1e9 + 7;   const long long INF = 1e9;   const long long INFLL = 1e18;   using namespace std;   int cx[4] = {-1, 0, 1, 0};   int cy[4] = {0, -1, 0, 1};   string Yes[2] = { No ,  Yes };   string YES[2] = { NO ,  YES };   long long inq(long long x, long long y) {     if (!y) return 1 % MOD;     long long l = inq(x, y / 2);     if (y % 2) return l * l % MOD * x % MOD;     return l * l % MOD;   }   long long rev(long long x) { return inq(x, MOD - 2); }   bool __precomputed_combinatorics = 0;   vector<long long> __fact, __ufact, __rev;   void __precompute_combinatorics() {     __precomputed_combinatorics = 1;     __fact.resize(N);     __ufact.resize(N);     __rev.resize(N);     __rev[1] = 1;     for (int i = 2; i < N; i++) __rev[i] = MOD - __rev[MOD % i] * (MOD / i) % MOD;     __fact[0] = 1, __ufact[0] = 1;     for (int i = 1; i < N; i++)       __fact[i] = __fact[i - 1] * i % MOD,       __ufact[i] = __ufact[i - 1] * __rev[i] % MOD;   }   long long fact(int x) {     if (!__precomputed_combinatorics) __precompute_combinatorics();     return __fact[x];   }   long long cnk(int n, int k) {     if (k < 0 || k > n) return 0;     if (!__precomputed_combinatorics) __precompute_combinatorics();     return __fact[n] * __ufact[n - k] % MOD * __ufact[k] % MOD;   }   int Root(int x, vector<int> &root) {     if (x == root[x]) return x;     return root[x] = Root(root[x], root);   }   void Merge(int v, int u, vector<int> &root, vector<int> &sz) {     v = Root(v, root), u = Root(u, root);     if (v == u) return;     if (sz[v] < sz[u]) {       sz[u] += sz[v];       root[v] = u;     } else {       sz[v] += sz[u];       root[u] = v;     }   }   int ok(int x, int n) { return 0 <= x && x < n; }   void bfs(int v, vector<int> &dist, vector<vector<int> > &graph) {     fill((dist).begin(), (dist).end(), -1);     dist[v] = 0;     vector<int> q = {v};     for (int i = 0; i < q.size(); i++) {       for (auto u : graph[q[i]]) {         if (dist[u] == -1) {           dist[u] = dist[q[i]] + 1;           q.push_back(u);         }       }     }   }   vector<int> z_func(string &s) {     vector<int> z(s.size());     z[0] = s.size();     int L = 0, R = 0;     for (int i = 1; i < s.size(); i++) {       z[i] = max(0, min(z[i - L], R - i));       while (i + z[i] < s.size() && s[i + z[i]] == s[z[i]]) z[i]++;       if (i + z[i] > R) {         R = i + z[i];         L = i;       }     }     return z;   }   vector<int> p_func(string &s) {     vector<int> p(s.size());     for (int i = 1; i < s.size(); i++) {       int j = p[i - 1];       while (j > 0 && s[i] != s[j]) j = p[j - 1];       if (s[i] == s[j]) j++;       p[i] = j;     }     return p;   }   vector<int> d1_func(string &s) {     vector<int> d1(s.size());     int L = 0, R = -1;     for (int i = 0; i < s.size(); i++) {       int k = 0;       if (i <= R) k = min(R - i + 1, d1[R - i + L]);       while (i + k < s.size() && i - k >= 0 && s[i - k] == s[i + k]) k++;       d1[i] = k--;       if (i + k > R) {         L = i - k;         R = i + k;       }     }     return d1;   }   vector<int> d2_func(string &s) {     vector<int> d2(s.size());     int L = 0, R = -1;     for (int i = 1; i < s.size(); i++) {       int k = 0;       if (i <= R) k = min(R - i + 1, d2[R - i + L + 1]);       while (i + k < s.size() && i - k - 1 >= 0 && s[i - k - 1] == s[i + k]) k++;       d2[i] = k--;       if (i + k > R) {         L = i - k - 1;         R = i + k;       }     }     return d2;   }   long long log10(long long x) {     if (x < 10) return 1;     return 1 + log10(x / 10);   }   long long ds(long long x) {     if (x < 10) return x;     return x % 10 + ds(x / 10);   }   double sqr(double x) { return x * x; }   bool in(int bit, int mask) { return (mask & (1 << bit)) > 0; }   void Del(vector<int> &v, int pos) {     swap(v[pos], v[v.size() - 1]);     v.pop_back();   }   long long g(vector<long long> &p, int pos) {     if (ok(pos, p.size())) return p[pos];     if (pos < 0 || p.size() == 0) return 0;     return p.back();   }   int g(vector<int> &p, int pos) {     if (ok(pos, p.size())) return p[pos];     if (pos < 0 || p.size() == 0) return 0;     return p.back();   }   bool comp(pair<int, int> a, pair<int, int> b) {     if (abs(a.first - a.second) == abs(b.first - b.second)) return a > b;     return abs(a.first - a.second) > abs(b.first - b.second);   }   signed main() {     srand(time(NULL));     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n, k;     cin >> n >> k;     int s = max(1, k / 2);     vector<int> a(n, 1);     for (int i = 0; i < n; i++) {       int k = 1;       int x = i;       while (0 <= x && x < n / s) {         for (int j = x * s; j < x * s + s; j++) {           if (a[j]) {             cout <<  ?   << j + 1 << endl;             string s;             cin >> s;             if (s ==  Y ) {               a[j] = 0;             }           }         }         if (k % 2 == 1)           x += k;         else           x -= k;         k++;       }       cout <<  R  << endl;     }     cout <<  !   << accumulate((a).begin(), (a).end(), 0) << endl;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   inline T sqr(T x) {     return x * x;   }   const double EPS = 1e-6;   const int INF = 0x3fffffff;   const long long LINF = INF * 1ll * INF;   const double PI = acos(-1.0);   using namespace std;   bool vis[205][205];   int main(void) {     int a, b;     cin >> a >> b;     string s;     cin >> s;     int x = 0, y = 0;     vis[100][100] = 1;     for (int i = 0; s[i]; i++) {       if (s[i] ==  R )         x++;       else if (s[i] ==  L )         x--;       else if (s[i] ==  D )         y--;       else         y++;       vis[100 + x][100 + y] = true;     }     for (int i = 0; i <= 200; i++)       for (int j = 0; j <= 200; j++) {         if (vis[i][j]) {           long long dx = i - 100, dy = j - 100;           dx = a - dx, dy = b - dy;           if (x == 0) {             if (y == 0) {               if (dx == dy && dx == 0) {                 cout <<  Yes  << endl;                 return 0;               }             } else if (dx == 0 && dy % y == 0 && 1ll * dy * y >= 0) {               cout <<  Yes  << endl;               return 0;             }           } else if (1ll * dx * y == 1ll * dy * x && dx % x == 0 &&                      1ll * dx * x >= 0) {             cout <<  Yes  << endl;             return 0;           }         }       }     cout <<  No  << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, d, m, l, i, j, x;     cin >> n >> d >> m >> l;     for (i = 0; i < n - 1; i++) {       if ((i * m + l) / d * d + d < (i + 1) * m) break;     }     cout << (i * m + l) / d * d + d;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, k;     ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);     cin >> n >> m >> k;     vector<vector<int> > dp(1 << n, vector<int>(1 << n, 0));     vector<int> G[n];     int all = (1 << n) - 1;     for (int i = 1; i <= m; ++i) {       int u, v;       cin >> u >> v;       u--;       v--;       G[u].emplace_back(v);       G[v].emplace_back(u);       dp[(1 << u) | (1 << v)][(1 << u) | (1 << v)]++;     }     for (int m1 = 0; m1 < (1 << n); m1++) {       for (int m2 = 0; m2 < (1 << n); m2++) {         if (!dp[m1][m2]) continue;         for (int i = 0; i < n; i++) {           if (!(m1 >> i & 1)) continue;           for (auto v : G[i]) {             if (m1 >> v & 1) continue;             int m3 = (m2 | (1 << v)) & (all ^ (1 << i));             if (!((m3 >> v) ^ 1)) dp[m1 | (1 << v)][m3] += dp[m1][m2];           }         }       }     }     long long res = 0;     for (int i = 0; i <= all; i++) {       if (__builtin_popcount(i) == k) res += dp[all][i];     }     cout << res <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     int n, m;     cin >> n >> m;     vector<int> cnt(n + 1, false), idx(n + 1), ans(m + 1), b(m + 1);     for (int i = 1; i <= n; i++) {       int x;       cin >> x;       cnt[x]++;       idx[x] = i;     }     for (int i = 1; i <= m; i++) {       cin >> b[i];       if (!cnt[b[i]]) {         cout <<  Impossible  << endl;         return 0;       }     }     for (int i = 1; i <= m; i++) {       if (cnt[b[i]] > 1) {         cout <<  Ambiguity  << endl;         return 0;       }       ans[i] = idx[b[i]];     }     cout <<  Possible  << endl;     for (int i = 1; i <= m; i++) cout << ans[i] <<    ;     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[10] = {4, 8, 15, 16, 23, 42};   int q[5];   int main() {     for (int i = 1; i <= 4; i++) {       printf( ? %d %d n , i, i + 1);       fflush(stdout);       cin >> q[i];     }     do {       if (a[1] * a[0] == q[1] && a[2] * a[1] == q[2] && a[3] * a[2] == q[3] &&           a[4] * a[3] == q[4])         break;     } while (next_permutation(a, a + 6));     printf( ! );     for (int i = 0; i < 6; i++) printf(  %d , a[i]);     fflush(stdout);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 100005;   int first[maxn];   int n;   int main() {     int num, i;     while (scanf( %d , &n) != EOF) {       memset(first, 0, sizeof(first));       for (i = 1; i <= n; i++) {         scanf( %d , &num);         if (i <= n / 2) {           if (num - (i - 1) > 0) first[num - (i - 1)]++;         } else {           if (num - (n - i) > 0) first[num - (n - i)]++;         }       }       int Max = 0;       for (i = 1; i < maxn; i++)         if (first[i] > Max) Max = first[i];       printf( %d n , n - Max);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1000000007;   const long long inf = 1000000000009;   int main() {     ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);     long long l{}, r{}, x{}, y{}, k{}, f{};     cin >> l >> r >> x >> y >> k;     for (int i = x, sz = (int)y + 1; i < sz; i++) {       if (l <= i * k && i * k <= r) {         f = 1;         break;       }     }     (f) ? cout <<  YES                 <<   n          : cout <<  NO                 <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string a;   int main() {     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       cin >> a;       for (int i = 0; i < a.length(); i += 2) cout << a[i];       cout << endl;     }     return 0;   }


/*   python3 ../../CompetitionHelpers/run_codeforces.py --problem A --test 0   g++ -ggdb -fsanitize=address -std=c++17 A.cpp && ./a.out <<<  1   4   0 3 5 6    */      #include <bits/stdc++.h>   using namespace std;      #define rep(i, a, b) for (int i = a; i < (b); i++)   #define trav(a, x) for (auto& a : x)   #define all(x) begin(x), end(x)   #define sz(x) (int)(x).size()   typedef long long ll;   typedef pair<int, int> pii;   typedef vector<int> vi;      string to_string(pii p) { return  (  + to_string(p.first) +  ,  + to_string(p.second) +  ) ; }   template <typename A>   string to_string(A v) { int cnt = 0; string res; for (const auto &x : v) { if (cnt++) res +=    ; res += to_string(x); } return  [  + res +  ] ; }   string to_string(const string& s) { return     + s +    ; }   string to_string(const char* s) { return to_string((string) s); }      void debug_out() { cerr << endl; }   template <typename Head, typename... Tail>   void debug_out(Head H, Tail... T) { cerr <<     << to_string(H); debug_out(T...); }   #define debug(...) cerr <<  [  << #__VA_ARGS__ <<  ]: , debug_out(__VA_ARGS__)      template<typename T>   void output_vector(const vector<T> &v, int start = 0, int end = -1) {       if (end < 0) end = int(v.size());       for (int i = start; i < end; i++)           cout << v[i] << (i < end - 1 ?     :   n );   }      int main() {       cin.sync_with_stdio(0); cin.tie(0);       cin.exceptions(cin.failbit);          int T; cin >> T; while (T--) {           ll n; cin >> n;           vector<ll> Arr(n); rep(i, 0, n) cin >> Arr[i];              sort(all(Arr));              ll ans = Arr.back();           for (ll i = 1; i < n; i++) {               ans -= (Arr[i] - Arr[i - 1]) * i * (n - i);           }              cout << ans <<   n ;       }   }


#include <bits/stdc++.h>   using namespace std;   void ECHO(string _s) {     cout << endl;     (void)_s;   }   template <typename T, typename... Args>   void ECHO(string _s, T x, Args... args) {     unsigned _i;     string _s2 =   ;     for (_i = 0; _i < _s.length(); ++_i) {       if (_s[_i] ==  , ) break;       if (_s[_i] !=    ) _s2 += _s[_i];     }     if (_i == _s.length()) {       --_i;     }     cout <<    (  << _s2 <<  ):  << x;     ECHO(_s.substr(_i + 1, _s.length() - _i - 1), args...);   }   template <typename T0, typename T1>   inline ostream& operator<<(ostream& os, pair<T0, T1>& p) {     return os <<  (  << p.first <<  ,   << p.second <<  ) ;   }   template <typename T>   inline ostream& operator<<(ostream& os, vector<T>& v) {     for (unsigned i = 0; i < v.size(); ++i) {       cout << v[i] <<  _ ;     }     cout << endl;     return os;   }   template <typename T>   inline T _min(T x1, T x2, T x3) {     return min(x1, min(x2, x3));   }   template <typename T>   inline T _min(T x1, T x2, T x3, T x4) {     return min(min(x1, x2), min(x2, x3));   }   inline long long _gcd(long long a, long long b) {     while (b) b %= a ^= b ^= a ^= b;     return a;   }   int main() {     ios::sync_with_stdio(false);     int q;     cin >> q;     while (q--) {       long long n, n5, n3, n2, contador;       cin >> n;       contador = 0;       n5 = (n % 5);       while ((n5) == 0) {         n = 4 * n;         n = n / 5;         n5 = (n % 5);         contador = contador + 1;       }       n3 = (n % 3);       while ((n3) == 0) {         n = (2) * n;         n = n / 3;         n3 = (n % 3);         contador = contador + 1;       }       n2 = (n % 2);       while ((n2) == 0) {         n = n / 2;         n2 = (n % 2);         contador = contador + 1;       }       if (n == 1) {         cout << contador <<   n ;       } else {         cout << -1 <<   n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline T read(T& x) {     x = 0;     int f = 0;     char ch = getchar();     while (ch <  0  || ch >  9 ) f |= (ch ==  - ), ch = getchar();     while (ch >=  0  && ch <=  9 ) x = x * 10 + ch -  0 , ch = getchar();     return x = f ? -x : x;   }   int q, t, l, r, x, last;   map<int, int> fa;   map<int, int> val;   int Find(int x) {     if (fa.find(x) == fa.end()) return fa[x] = x;     if (fa[x] == x) return x;     int root = Find(fa[x]);     val[x] ^= val[fa[x]];     return fa[x] = root;   }   int main() {     for (read(q); q--;) {       read(t);       if (t == 1) {         read(l), read(r), read(x);         l ^= last, r ^= last, x ^= last;         if (l > r) swap(l, r);         l--;         int p = Find(l), q = Find(r);         if (p ^ q) {           if (p < q) swap(p, q);           fa[p] = q;           val[p] = val[l] ^ val[r] ^ x;         }       } else {         read(l), read(r);         l ^= last, r ^= last;         if (l > r) swap(l, r);         l--;         int p = Find(l), q = Find(r);         if (p == q) {           printf( %d n , val[p] ^ val[l] ^ val[r]);           last = val[p] ^ val[l] ^ val[r];         } else {           puts( -1 );           last = 1;         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-9;   const double pi = acos(-1);   const int M = 3e5 + 10;   const int inf = 2e9 + 10;   const int mod = 1e9 + 7;   int n, stk[M], le[M], ri[M], f[M], cnt[M];   char s[M], s1[M];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     cin >> n >> s + 1;     int num = 0, min = 0, id = 0;     for (int i = 1; i <= n; ++i) {       if (s[i] ==  ( )         ++num;       else         --num;       if (num < min) {         min = num;         id = i;       }     }     if (num) {       cout <<  0 n1 1 n ;       return 0;     }     for (int i = 1; i <= id; ++i) s1[n + i - id] = s[i];     for (int i = id + 1; i <= n; ++i) s1[i - id] = s[i];     int top = 0;     num = 0;     for (int i = 1; i <= n; ++i) {       if (s1[i] ==  ( ) {         stk[++top] = ++num;         le[num] = i;       } else {         int t1 = stk[top];         ri[t1] = i;         f[t1] = stk[--top];         ++cnt[stk[top]];       }     }     int ans = cnt[0], lans = 1, rans = 1;     for (int i = 1; i <= num; ++i) {       if (cnt[i] + 1 > ans && !f[i]) {         ans = cnt[i] + 1;         lans = le[i];         rans = ri[i];       }       if (cnt[i] + 1 + cnt[0] > ans && f[i] && !f[f[i]]) {         ans = cnt[i] + 1 + cnt[0];         lans = le[i];         rans = ri[i];       }     }     lans = (lans + id - 1) % n + 1;     rans = (rans + id - 1) % n + 1;     cout << ans <<   n  << lans <<     << rans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   const long long N = 2e5 + 6;   const long long inf = 1e15;   long long ex, ey, ez, bx, by, bz, a[7];   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     if (fopen( inp.txt ,  r )) {       freopen( inp.txt ,  r , stdin);       freopen( outp.txt ,  w , stdout);     }     cin >> ex >> ey >> ez;     cin >> bx >> by >> bz;     long long i, ans = 0;     for (i = 1; i <= 7; i++) cin >> a[i];     if (ex > bx)       ans += a[6];     else if (ex < 0)       ans += a[5];     if (ey > by)       ans += a[2];     else if (ey < 0)       ans += a[1];     if (ez > bz)       ans += a[4];     else if (ez < 0)       ans += a[3];     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2055, mod = (int)1e9 + 7;   template <class o>   void qr(o &x) {     char c = getchar();     x = 0;     while (!isdigit(c)) c = getchar();     while (isdigit(c)) x = x * 10 + c -  0 , c = getchar();   }   int n, m, L, last[N], ys[N], tot, vis[N], col[N];   struct P {     int x, y, c, i;   } a[N];   bool cmpx(P a, P b) { return a.x < b.x; }   bool cmpy(P a, P b) { return a.y < b.y; }   struct Q {     int l[N], r[N];     void del(int x) {       l[r[x]] = l[x];       r[l[x]] = r[x];     }   } q, nq;   struct node {     int mn, mx, s, tag;     node(int a = 0, int b = 0, int c = 0, int d = 0) {       mn = a;       mx = b;       s = c;       tag = d;     }     node operator+(node b) const {       return node(min(mn, b.mn), max(mx, b.mx), (s + b.s) % mod, 0);     }   } tr[N * 2];   int f[N];   void bt(int x, int l, int r) {     if (l == r) {       tr[x] = node(f[l], f[l], 1LL * (ys[r] - ys[l - 1]) * f[l] % mod, 0);       return;     }     int mid = (l + r) / 2;     bt((x << 1), l, mid);     bt((x << 1 | 1), mid + 1, r);     tr[x] = tr[(x << 1)] + tr[(x << 1 | 1)];   }   void upd(int x, int l, int r, long long t) {     tr[x] = node(t, t, t * (ys[r] - ys[l - 1]) % mod, t);   }   void change(int x, int l, int r, int L, long long t) {     if (tr[x].mn >= t) return;     if (tr[x].mx <= t && l == L) {       upd(x, l, r, t);       return;     }     int mid = (l + r) / 2;     if (tr[x].tag) {       upd((x << 1), l, mid, tr[x].tag);       upd((x << 1 | 1), mid + 1, r, tr[x].tag);       tr[x].tag = 0;     }     if (L <= mid) change((x << 1), l, mid, L, t);     change((x << 1 | 1), mid + 1, r, max(mid + 1, L), t);     tr[x] = tr[(x << 1)] + tr[(x << 1 | 1)];   }   int main() {     qr(n);     qr(m);     qr(L);     for (int i = 1; i <= n; i++) qr(a[i].x), qr(a[i].y), qr(a[i].c);     sort(a + 1, a + n + 1, cmpy);     a[0].x = a[0].y = -1;     a[n + 1].x = a[n + 1].y = L;     for (int i = 0; i <= n + 1; i++) ys[i] = a[i].y, a[i].i = i;     for (int i = 1; i <= n; i++) {       int l = nq.l[i] = last[a[i].c];       last[a[i].c] = i;       nq.r[i] = n + 1;       nq.r[l] = i;     }     sort(a + 1, a + n + 1, cmpx);     long long ans = 0;     for (int i = 1; i <= n; i++) {       if (a[i].x ^ a[i - 1].x) {         q = nq;         for (int j = 1; j < i; j++) col[a[j].i] = 0;         for (int j = i; j <= n; j++) col[a[j].i] = a[j].c;         for (int l = 1, r = 1; l <= n; l++) {           for (; r <= n && tot < m; r++)             if (col[r] && !vis[col[r]]++) tot++;           f[l] = (tot < m) ? L : ys[r - 1];           if (col[l] && !--vis[col[l]]) tot--;         }         bt(1, 1, n);         for (int j = n; j >= i; j--) {           ans += (1LL * (ys[n] + 1) * L - tr[1].s) % mod * (a[i].x - a[i - 1].x) %                  mod * (a[j + 1].x - a[j].x) % mod;           int id = a[j].i, L = q.l[id], R = q.r[id];           change(1, 1, n, L + 1, ys[R]);           q.del(id);         }         ans %= mod;       }       nq.del(a[i].i);     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 1e5 + 10;   int arr[MAX];   int n;   string s;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int t;     cin >> t;     set<array<int, 4> > vis;     pair<int, int> p;     for (int tc = 1; tc <= t; ++tc) {       vis.clear();       cin >> s;       array<int, 4> a;       int ans = 0;       int x = 0, y = 0;       for (int i = 0; i < s.size(); ++i) {         a[0] = x;         a[1] = y;         if (s[i] ==  N ) y++;         if (s[i] ==  S ) y--;         if (s[i] ==  E ) x++;         if (s[i] ==  W ) x--;         a[2] = x;         a[3] = y;         if (vis.count(a))           ans++;         else           ans += 5;         vis.insert(a);         swap(a[0], a[2]);         swap(a[1], a[3]);         vis.insert(a);       }       cout << ans <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int a1, b1, c1, ma = 0, maa = 0, x1, y1;       cin >> a1 >> b1 >> c1;       for (int i = 0; i < b1; i++) {         cin >> x1;         ma = max(x1, ma);       }       for (int i = 0; i < c1; i++) {         cin >> y1;         maa = max(y1, maa);       }       if (ma > maa) {         cout <<  YES  << endl;       } else {         cout <<  NO  << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int dx[] = {1, -1, 0, 0};   int dy[] = {0, 0, 1, -1};   int dddx[] = {1, -1, 0, 0, 1, 1, -1, -1};   int dddy[] = {0, 0, 1, -1, 1, -1, 1, -1};   int t;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cin >> t;     while (t--) {       int n;       cin >> n;       vector<int> vec;       for (int i = 0; i < n; i++) {         int a;         cin >> a;         vec.push_back(a);       }       bool at = false;       for (int i = 0; i < int(vec.size()); i++) {         for (int j = i + 2; j < int(vec.size()); j++) {           if (vec[j] == vec[i]) at = true;         }       }       if (!at)         cout <<  NO               <<   n ;       else         cout <<  YES               <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void processTest(int n, int64_t m, int64_t k) {     vector<int64_t> path(n);     int64_t bag = m;     for (auto &v : path) {       cin >> v;     }     for (int i = 1; i < path.size(); ++i) {       auto toEq = max(path[i] - k, int64_t(0));       bag += path[i - 1] - toEq;       if (bag < 0) {         cout <<  NO  << endl;         return;       }     }     cout <<  YES  << endl;   }   int main() {     int t;     cin >> t;     for (int i = 0; i < t; ++i) {       int64_t n, m, k;       cin >> n >> m >> k;       processTest(n, m, k);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline long long read() {     long long s = 0, w = 1;     char ch = getchar();     while (ch < 48 || ch > 57) {       if (ch ==  - ) w = -1;       ch = getchar();     }     while (ch >= 48 && ch <= 57)       s = (s << 1) + (s << 3) + (ch ^ 48), ch = getchar();     return s * w;   }   const long long N = 1e5 + 5, P = 1e9 + 7;   struct ChthollyTree {     map<long long, long long> s;     inline long long find(long long p) { return s.lower_bound(p)->second; }     inline void split(long long p) {       long long pos = find(p);       s[p] = pos;     }     inline pair<map<long long, long long>::iterator,                 map<long long, long long>::iterator>     range(long long l, long long r) {       split(l - 1), split(r);       return make_pair(s.find(l - 1), s.find(r));     }   } T;   long long n, m, seed, vmax, a[N], sum[N], len;   struct Node {     long long val, cnt;   } A[N];   inline bool cmp(Node x, Node y) { return x.val < y.val; }   inline long long rnd() {     long long res = seed;     seed = (seed * 7ll + 13ll) % P;     return res;   }   inline long long qpow(long long x, long long y, long long p) {     long long ans = 1, res = x % p;     while (y) {       if (y & 1) ans = (ans * res) % p;       y >>= 1;       res = (res * res) % p;     }     return ans % p;   }   signed main() {     n = read(), m = read(), seed = read(), vmax = read();     for (register long long i = 1; i <= n; ++i) {       a[i] = (rnd() % vmax) + 1;       T.s[i] = a[i];     }     while (m--) {       long long op = (rnd() % 4) + 1, l = (rnd() % n) + 1, r = (rnd() % n) + 1, x,                 y;       if (l > r) swap(l, r);       if (op == 3)         x = (rnd() % (r - l + 1)) + 1;       else         x = (rnd() % vmax) + 1;       if (op == 4) y = (rnd() % vmax) + 1;       map<long long, long long>::iterator st, ed;       if (op == 1) {         pair<map<long long, long long>::iterator,              map<long long, long long>::iterator>             border = T.range(l, r);         st = border.first, ed = border.second;         while (st != ed) ed->second += x, ed--;       } else if (op == 2) {         pair<map<long long, long long>::iterator,              map<long long, long long>::iterator>             border = T.range(l, r);         st = border.first, ed = border.second;         while (st != ed) T.s.erase(ed--);         T.s[r] = x;       } else if (op == 3) {         long long nxt;         len = 0;         for (register long long i = l; i <= r; i = nxt + 1) {           map<long long, long long>::iterator now = T.s.lower_bound(i);           nxt = min(r, now->first);           A[++len] = (Node){now->second, nxt - i + 1};         }         sort(A + 1, A + len + 1, cmp);         for (register long long i = 1; i <= len; ++i)           sum[i] = sum[i - 1] + A[i].cnt;         long long L = 1, R = len, res = -1;         while (L <= R) {           long long mid = (L + R) >> 1;           if (sum[mid] >= x)             res = mid, R = mid - 1;           else             L = mid + 1;         }         printf( %lld n , A[res].val);       } else {         long long Ans = 0;         long long nxt;         for (register long long i = l; i <= r; i = nxt + 1) {           map<long long, long long>::iterator now = T.s.lower_bound(i);           nxt = min(r, now->first);           Ans = (Ans + qpow(now->second, x, y) * (nxt - i + 1) % y) % y;         }         printf( %lld n , Ans % y);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char str[25];   char times[6] = {4, 5, 6, 3, 2, 1};   int main() {     scanf( %s , str);     int len = strlen(str);     char seat = str[len - 1];     long long rows = 0;     for (int i = 0; i < len - 1; i++) {       rows = rows * 10;       rows += str[i] -  0 ;     }     long long sec;     if (rows % 4 != 0)       sec = rows / 4 * 16;     else       sec = (rows - 1) / 4 * 16;     int tmp = rows % 4;     if (!tmp) tmp = 4;     if (tmp > 2) tmp -= 2;     sec += (tmp - 1) * 7;     sec += times[seat -  a ];     printf( %I64d n , sec);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve(int n, int m, vector<int> a) {     for (int i = int(0); i < int(m); i++) a[i] = min(a[i], n / 2);     int sum = accumulate((a).begin(), (a).end(), 0);     if (sum < n) {       cout << -1 << endl;       return;     }     vector<pair<int, int> > b(m);     for (int i = int(0); i < int(m); i++) b[i] = make_pair(a[i], i);     sort((b).begin(), (b).end(), greater<pair<int, int> >());     vector<int> res(n);     for (int i = int(0); i < int(n); i++) {       int j = -1;       if (i == 0)         j = 0;       else if (i == n - 1) {         for (int k = int(0); k < int(m); k++)           if (b[k].second != res[i - 1] && b[k].second != res[0] &&               (j == -1 || b[k].first > b[j].first))             j = k;       } else {         for (int k = int(0); k < int(m); k++)           if (b[k].second != res[i - 1] && (j == -1 || b[k].first > b[j].first))             j = k;       }       res[i] = b[j].second;       b[j].first--;     }     for (int i = int(0); i < int(n); i++)       cout << res[i] + 1 << (i == n - 1 ?   n  :    );   }   int main() {     for (int n, m; cin >> n >> m, n | m;) {       vector<int> a(m);       for (int i = int(0); i < int(m); i++) cin >> a[i];       solve(n, m, a);       break;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string decToBin(int n) {     string toret;     while (n) {       toret += char((n % 2) +  0 );       n /= 2;     }     while (toret.size() != 8) toret +=  0 ;     return toret;   }   int binToDec(string res) {     int t = 0;     int pow = 1;     for (int i = res.size() - 1; i >= 0; i--) {       t += (res[i] -  0 ) * pow;       pow *= 2;     }     return t;   }   int main() {     string in;     getline(cin, in);     int tmp = 0;     for (int i = 0; i < in.size(); i++) {       int code = (int)in[i];       string p = decToBin(code);       int t = binToDec(p);       int m = tmp - t;       while (m < 0) m += 256;       tmp = t;       cout << m % 256 << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void BFS(map<int, int> &m1, int t) {     queue<pair<int, int>> q1;     set<int> set_help;     set<int>::iterator p;     q1.push(make_pair(t, 0));     m1[t] = 0;     set_help.insert(t);     int Value, step;     while (q1.empty() == 0) {       Value = q1.front().first;       step = q1.front().second;       if (Value % 2 == 0) {         p = set_help.find(Value / 2);         if (p == set_help.end()) {           m1[Value / 2] = step + 1;           q1.push(make_pair(Value / 2, step + 1));           set_help.insert(Value / 2);         }       }       if (Value % 3 == 0) {         p = set_help.find(Value / 3);         if (p == set_help.end()) {           m1[Value / 3] = step + 1;           q1.push(make_pair(Value / 3, step + 1));           set_help.insert(Value / 3);         }       }       if (Value % 5 == 0) {         p = set_help.find(Value / 5);         if (p == set_help.end()) {           m1[Value / 5] = step + 1;           q1.push(make_pair(Value / 5, step + 1));           set_help.insert(Value / 5);         }       }       q1.pop();     }   }   int main() {     int a, b;     ifstream ff( file.txt );     cin >> a >> b;     if (a == b) {       cout << 0 << endl;       return 0;     }     map<int, int> ma, mb;     BFS(ma, a);     BFS(mb, b);     map<int, int>::iterator p = ma.begin(), p1;     int Stap_Min = INT_MAX, Step;     for (p; p != ma.end(); p++) {       p1 = mb.find(p->first);       if (p1 != mb.end()) {         Step = p->second + p1->second;         if (Step < Stap_Min) {           Stap_Min = Step;         }       }     }     if (Stap_Min == INT_MAX) {       cout << -1 << endl;     } else {       cout << Stap_Min << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int func(int a) {     int cnt = 0;     while (a) {       cnt++;       a /= 10;     }     return cnt;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     long long n, k;     cin >> n >> k;     vector<long long> v(n);     map<int, int> m[11];     long long ans = 0;     for (int i = 0; i < n; i++) {       cin >> v[i];       long long c = 10;       for (int j = 1; j <= 10; j++) {         m[j][((v[i] % k) * (c % k)) % k]++;         c *= 10;       }     }     for (int i = 0; i < n; i++) {       int a = (k - v[i] % k) % k;       int b = func(v[i]);       ans += m[b][a];       long long c = 1;       for (int j = 0; j < b; j++) {         c *= 10;       }       ans -= a == (v[i] % k * c % k) % k;     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   int p[300];   int main() {     int i, k, j, l;     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n;     for (i = 0; i < 2 * n; i++) {       cin >> p[i];     }     n *= 2;     int result = 200000000;     for (i = 0; i < n; i++) {       for (j = i + 1; j < n; j++) {         vector<int> V;         for (k = 0; k < n; k++) {           if (k != i && k != j) {             V.push_back(p[k]);           }         }         sort(V.begin(), V.end());         int sum = 0;         for (l = 0; l < V.size(); l = l + 2) {           sum += (V[l + 1] - V[l]);         }         result = min(result, sum);       }     }     cout << result << endl;     return 0;   }


#include <bits/stdc++.h>   int main() {     int x, y, z;     scanf( %d %d %d , &x, &y, &z);     if (x > y + z) {       printf( + n );     } else if (y > x + z) {       printf( - n );     } else if (x == y && z == 0) {       printf( 0 n );     } else {       printf( ? n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, k, cnt;   int main() {     scanf( %d%d%d , &n, &m, &k);     if (4 * n * m - 2 * n - 2 * m < k) {       puts( NO );       return 0;     }     puts( YES );     if (m == 1) {       if (k <= n - 1) {         puts( 1 );         printf( %d D n , k);       } else {         puts( 2 );         printf( %d D n , n - 1);         printf( %d U n , k - n + 1);       }       return 0;     }     int kk = k, x = 1;     while (k && x < n) {       cnt++;       if (k <= 3 * (m - 1)) {         if (k % 3 && k > 3) cnt++;         break;       }       k -= 3 * (m - 1);       cnt++;       if (k <= m - 1) break;       k -= m - 1;       cnt++;       if (k <= 1) break;       k--;       x++;     }     if (k && x == n) {       cnt++;       if (k > m - 1) cnt++;       if (k > 2 * (m - 1)) cnt++;     }     printf( %d n , cnt);     k = kk, x = 1;     while (k && x < n) {       if (k <= 3 * (m - 1)) {         if (k >= 3) printf( %d RDU n , k / 3);         if (k % 3 >= 1) printf( 1 R );         if (k % 3 >= 2) printf( D );         puts(  );         break;       }       printf( %d RDU n , m - 1);       k -= 3 * (m - 1);       if (k <= m - 1) {         printf( %d L n , k);         break;       }       printf( %d L n , m - 1);       k -= m - 1;       if (k <= 1) {         printf( 1 D n );         break;       }       printf( 1 D n );       k--;       x++;     }     if (k && x == n) {       if (k <= m - 1)         printf( %d R n , k);       else {         printf( %d R n , m - 1);         k -= m - 1;         if (k <= m - 1)           printf( %d L n , k);         else {           printf( %d L n , m - 1);           k -= m - 1;           printf( %d U n , k);         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int ar[] = {2, 7, 2, 3, 3, 4, 2, 5, 1, 2};   int main() {     int n, a, sum = 1;     cin >> n;     for (int i = 0; i < 2; i++) {       a = n % 10;       sum *= ar[a];       n /= 10;     }     cout << sum << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     srand(time(NULL));     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.setf(ios::fixed);     cout.precision(0);     long long n;     cin >> n;     string s;     char y =  a ;     while (n != 0) {       s.push_back(y);       int t = 1;       while (t <= n) {         s.push_back(y);         n -= t;         t++;       }       y++;     }     if (s.size() == 0) s.push_back( a );     cout << s;   }


#include <bits/stdc++.h>   using namespace std;   inline int ckmax(int &a, int b) { return a < b ? a = b, 1 : 0; }   inline int ckmin(int &a, int b) { return a > b ? a = b, 1 : 0; }   char s[500100], t[500100];   int n, m, wt, p[500100], sta[500100], pre[500100], nex[500100], top;   int main() {     scanf( %d%d%d , &n, &m, &wt);     scanf( %s , s + 1);     scanf( %s , t + 1);     for (int i = 1; i <= n; ++i) {       if (s[i] ==  ( )         sta[++top] = i;       else {         p[i] = sta[top];         p[sta[top--]] = i;       }       pre[i] = i - 1;       nex[i] = i + 1;     }     nex[0] = 1;     pre[n + 1] = n;     for (int i = 1; i <= m; ++i) {       if (t[i] ==  L )         wt = pre[wt];       else if (t[i] ==  R )         wt = nex[wt];       else {         int ww = p[wt];         if (ww > wt) swap(ww, wt);         nex[pre[ww]] = nex[wt];         pre[nex[wt]] = pre[ww];         if (nex[wt] <= n)           wt = nex[wt];         else           wt = pre[ww];       }     }     int w = nex[0];     while (w <= n) {       printf( %c , s[w]);       w = nex[w];     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       int a[n];       map<int, int> mp;       for (int i = 0; i < n; i++) {         cin >> a[i];         mp[a[i]]++;       }       int mx = 0, p = 0;       for (auto it = mp.begin(); it != mp.end(); it++) {         mx = max(mx, it->second);         p++;       }       cout << max(min(mx, p - 1), min(mx - 1, p)) << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     cin >> n >> k;     deque<int> dq;     map<int, int> freq;     for (int i = 0; i < n; i++) {       int x;       cin >> x;       if (freq[x] == 0) {         if ((int)dq.size() < k)           dq.push_front(x);         else {           dq.push_front(x);           freq[dq.back()] = 0;           dq.pop_back();         }         freq[x] = 1;       }     }     cout << (int)dq.size() <<   n ;     for (auto i : dq) cout << i <<    ;     cout <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = unsigned long long;   using pii = pair<int, int>;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   template <class Ty>   Ty randint(Ty a, Ty b) {     return uniform_int_distribution<Ty>(a, b)(rng);   }   template <class T>   void DBG(T&& x) {     cerr << x <<    ;   }   template <class T, class... Args>   void DBG(T&& x, Args&&... args) {     DBG(x);     DBG(args...);   }   template <class num>   inline void rd(num& x) {     cin >> x;   }   template <class Ty, class... Args>   inline void rd(Ty& x, Args&... args) {     rd(x);     rd(args...);   }   template <class num>   inline void print(num&& x) {     cout << x;   }   template <class Ty, class... Args>   inline void print(Ty&& x, Args&&... args) {     print(x);     print(   );     print(args...);   }   const int MOD = 1e9 + 7;   struct mint {     int v;     mint() : v{} {}     mint(int v) : v(v) { go(); }     inline void go() {       if (abs(v) >= MOD) v %= MOD;       if (v < 0) v += MOD;     }     inline static mint fpow(mint x, long long y) {       mint r = 1;       for (; y > 0; y /= 2, x *= x)         if (y % 2 != 0) r *= x;       return r;     }     mint inv() const { return fpow(*this, MOD - 2); }     mint operator+(mint const& m) const {       return v + m.v >= MOD ? v + m.v - MOD : v + m.v;     }     mint operator-(mint const& m) const {       return v - m.v < 0 ? v - m.v + MOD : v - m.v;     }     mint operator*(mint const& m) const { return (long long)v * m.v % MOD; }     mint operator/(mint const& m) const { return (*this) * m.inv(); }     mint operator^(long long m) const { return fpow(*this, m); }     mint& operator+=(mint const& m) { return (*this) = (*this) + m; }     mint& operator-=(mint const& m) { return (*this) = (*this) - m; }     mint& operator*=(mint const& m) { return (*this) = (*this) * m; }     mint& operator/=(mint const& m) { return (*this) = (*this) / m; }   };   int cant[6][6];   mint memo[61][6];   mint mem2[2006 * 60][6];   int k;   int find_level(ll u) {     int ans = 0;     while (u >= 1) {       ans++;       u /= 2;     }     return k - ans;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     cant[0][0] = cant[0][1] = 1;     cant[1][0] = cant[1][1] = 1;     cant[2][2] = cant[2][3] = 1;     cant[3][3] = cant[3][2] = 1;     cant[4][4] = cant[4][5] = 1;     cant[5][5] = cant[5][4] = 1;     rd(k);     int n;     rd(n);     map<ll, int> mp;     for (int i = 0; i < n; i++) {       ll u;       rd(u);       string c;       rd(c);       int cur;       if (c[0] ==  o ) cur = 5;       if (c[0] ==  w ) cur = 0;       if (c[0] ==  y ) cur = 1;       if (c[0] ==  g ) cur = 2;       if (c[0] ==  b ) cur = 3;       if (c[0] ==  r ) cur = 4;       mp[u] = cur;     }     vector<ll> special;     for (auto [cc, c] : mp) {       ll cur = cc;       while (cur >= 1) {         special.emplace_back(cur);         cur /= 2;       }     }     sort(special.begin(), special.end());     special.erase(unique(special.begin(), special.end()), special.end());     for (int i = 0; i < 6; i++) memo[0][i] = 1;     for (int i = 1; i < k; i++) {       for (int c = 0; c < 6; c++) {         mint& ans = memo[i][c];         for (int c1 = 0; c1 < 6; c1++)           if (!cant[c][c1]) {             for (int c2 = 0; c2 < 6; c2++)               if (!cant[c][c2]) {                 ans += memo[i - 1][c1] * memo[i - 1][c2];               }           }       }     }     const int N = special.size();     for (int i = N - 1; i >= 0; i--) {       ll u = special[i];       int l = find_level(u);       if (l == 0) {         mem2[i][mp[u]] = 1;         continue;       }       for (int c = 0; c < 6; c++)         if (!mp.count(u) || mp[u] == c) {           mint& ans = mem2[i][c];           for (int c1 = 0; c1 < 6; c1++)             if (!cant[c][c1]) {               for (int c2 = 0; c2 < 6; c2++)                 if (!cant[c][c2]) {                   mint ans1 = memo[l - 1][c1];                   if (binary_search(special.begin(), special.end(), 2 * u)) {                     int id = lower_bound(special.begin(), special.end(), 2 * u) -                              special.begin();                     ans1 = mem2[id][c1];                   }                   mint ans2 = memo[l - 1][c2];                   if (binary_search(special.begin(), special.end(), 2 * u + 1)) {                     int id =                         lower_bound(special.begin(), special.end(), 2 * u + 1) -                         special.begin();                     ans2 = mem2[id][c2];                   }                   ans += ans1 * ans2;                 }             }         }     }     mint ans = 0;     for (int i = 0; i < 6; i++) ans += mem2[0][i];     print(ans.v), print(  n );   }


#include <bits/stdc++.h>   using namespace std;   const int MAX_N = 1e6 + 5;   long long magic_const = 3e18;   const int MAX_L = 3;   class segment_tree {     int n;     vector<long long> val;     vector<long long> pushes;     int l, r;     long long ans, adding_value;     void push(int v, bool is_leaf) {       val[v] += pushes[v];       if (!is_leaf) {         pushes[v << 1] += pushes[v];         pushes[(v << 1) + 1] += pushes[v];       }       pushes[v] = 0;     }     void update(int v) {       int lp = v << 1;       int rp = lp + 1;       val[v] = min(val[lp] + pushes[lp], val[rp] + pushes[rp]);     }     void build(vector<long long>& a, int v, int lb, int rb) {       if (lb == rb) {         val[v] = a[lb];         return;       }       int midt = (lb + rb) / 2;       int lv = v << 1;       int rv = lv + 1;       build(a, lv, lb, midt);       build(a, rv, midt + 1, rb);       update(v);     }     void count(int v, int lb, int rb) {       push(v, lb == rb);       if (lb >= l && rb <= r) {         ans = min(ans, val[v]);       } else {         int midt = (lb + rb) / 2;         int lv = v << 1;         int rv = lv + 1;         if (midt >= l && lb <= r) count(lv, lb, midt);         if (midt + 1 <= r && rb >= l) count(rv, midt + 1, rb);       }     }     void add(int v, int lb, int rb) {       push(v, lb == rb);       if (lb >= l && rb <= r) {         pushes[v] += adding_value;       } else {         int midt = (lb + rb) / 2;         int lv = v << 1;         int rv = lv + 1;         if (midt >= l && lb <= r) add(lv, lb, midt);         if (midt + 1 <= r && rb >= l) add(rv, midt + 1, rb);         update(v);       }     }       public:     segment_tree(vector<long long>& a) {       n = a.size();       if (n < 10) {         val.resize(n * 4, magic_const);         pushes.resize(n * 4);       } else {         val.resize(n * 4, magic_const);         pushes.resize(n * 4);       }       build(a, 1, 0, n - 1);     }     long long get_answer(int l, int r) {       this->l = l;       this->r = r;       this->ans = magic_const;       count(1, 0, n - 1);       return this->ans;     }     void add_on_segment(int l, int r, long long value) {       this->l = l;       this->r = r;       this->adding_value = value;       add(1, 0, n - 1);     }   };   int n, m;   vector<vector<int>> graph;   vector<vector<int>> cost;   vector<int> pr;   vector<int> pr_cost;   vector<int> h;   vector<pair<pair<int, int>, pair<int, int>>> queries;   vector<int> tin;   vector<int> tout;   vector<int> leafs;   vector<long long> used;   int t = 0;   void dfs(int v, int new_h) {     tin[v] = t++;     h[v] = new_h;     if (graph[v].size() <= 1) leafs.push_back(v);     for (int i = 0; i < graph[v].size(); i++) {       int new_v = graph[v][i];       if (h[new_v] == -1) {         pr[new_v] = v;         pr_cost[new_v] = cost[v][i];         dfs(new_v, new_h + 1);       }     }     tout[v] = t;   }   void dfs_2(int v, long long cnt) {     used[v] = cnt;     for (int i = 0; i < graph[v].size(); i++) {       int new_v = graph[v][i];       if (used[new_v] == -1) {         dfs_2(new_v, cnt + cost[v][i]);       }     }   }   const bool cmp(const pair<pair<int, int>, pair<int, int>>& first,                  const pair<pair<int, int>, pair<int, int>>& second) {     if (tin[first.first.first] != tin[second.first.first])       return tin[first.first.first] < tin[second.first.first];     return first.first.second < second.first.second;   }   void solve() {     cin >> n >> m;     graph.resize(n);     cost.resize(n);     pr.resize(n);     pr_cost.resize(n);     h.resize(n, -1);     tin.resize(n);     tout.resize(n);     used.resize(n, -1);     for (int i = 1; i < n; i++) {       int a, b;       cin >> a >> b;       a--;       graph[i].push_back(a);       graph[a].push_back(i);       cost[i].push_back(b);       cost[a].push_back(b);     }     dfs(0, 0);     for (int i = 0; i < m; i++) {       int v, a, b;       cin >> v >> a >> b;       v--, a--, b--;       queries.push_back({{v, i}, {a, b}});     }     vector<long long> answer(m);     sort(queries.begin(), queries.end(), cmp);     dfs_2(queries[0].first.first, 0);     int cur_v = queries[0].first.first;     int target_v = -1;     vector<long long> new_used(n, magic_const);     for (auto& leaf : leafs) {       new_used[leaf] = used[leaf];     }     segment_tree st(new_used);     auto up_cur = [&]() {       st.add_on_segment(0, new_used.size() - 1, -pr_cost[cur_v]);       st.add_on_segment(tin[cur_v], tout[cur_v] - 1, 2 * pr_cost[cur_v]);       cur_v = pr[cur_v];     };     auto up_target = [&]() {       st.add_on_segment(0, new_used.size() - 1, pr_cost[target_v]);       st.add_on_segment(tin[target_v], tout[target_v] - 1,                         -2 * pr_cost[target_v]);       target_v = pr[target_v];     };     for (int i = 0; i < queries.size(); i++) {       int l = queries[i].second.first;       int r = queries[i].second.second;       target_v = queries[i].first.first;       int cur_i = queries[i].first.second;       while (h[cur_v] > h[target_v]) up_cur();       while (h[target_v] > h[cur_v]) up_target();       while (cur_v != target_v) {         up_cur();         up_target();       }       answer[cur_i] = st.get_answer(l, r);       cur_v = queries[i].first.first;     }     for (auto& i : answer) cout << i <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     srand(555);     solve();   }


#include <bits/stdc++.h>   using namespace std;   const long long maxx = 1e6 + 7;   const long long maxn = 1e6 + 7;   const long long mod = 998244353;   const long long maxs = 500000 + 7;   const long long maxm = 400000 + 7;   const long long maxk = 1008 + 7;   const long long maxw = 100 + 7;   const long long maxh = 100 + 7;   const double pi = 3.1415926;   const long long ten = 10;   const long long ooi = 1000000;   const long long ool = 1e18 + 7;   const long double eps = 1e-8;   const int apsz = 26;   int seq[maxn];   int n;   void init() {     cin >> n;     for (long long i = (1); i <= (n); i++) {       cin >> seq[i];     }     sort(seq + 1, seq + 1 + n);   }   void solve() {     int ans = 0;     int i = 1;     int nowd = 1;     while (i <= n) {       while (i <= n && seq[i] < nowd) i++;       if (i == n + 1) break;       ans++;       nowd++, i++;     }     cout << ans << endl;   }   int main(void) {     ios::sync_with_stdio(false);     cout.tie(0);     cin.tie(0);     init();     solve();     return 0;   }


#include <bits/stdc++.h>   const int mn = 10100, mm = 5010000;   char st[mm], ans[mm];   int f[mm], s[mm], L[mn], R[mn];   int n, m, K, i, j, d, len, now;   void del(int p) {     for (; p <= m; p += p & (-p)) --s[p];   }   int query(int v) {     int i = 1, l = m >> 1;     for (; l; l >>= 1)       if (s[i + l - 1] < v) v -= s[i + l - 1], i += l;     return i;   }   int main() {     scanf( %s , st + 1);     scanf( %d , &K);     for (m = 1; m < K; m <<= 1)       ;     scanf( %d , &n);     for (i = 1; i <= n; ++i) scanf( %d%d , L + i, R + i);     for (i = 1; i <= m; ++i) s[i] = i & (-i);     for (i = n; i >= 1; --i) {       if (R[i] >= s[m]) continue;       len = R[i] - L[i] + 1, now = L[i] + 1;       for (j = 1; j <= len; ++j) {         if (R[i] >= s[m]) break;         if (now > R[i]) now = L[i];         d = query(R[i] + 1), del(d);         f[d] = query(now);         now += 2;       }     }     j = 1;     for (i = 1; i <= K; ++i) ans[i] = f[i] ? ans[f[i]] : st[j++];     puts(ans + 1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 7;   const int INF = 1e8;   void boost() {     cin.tie(0);     cout.tie(0);     ios_base::sync_with_stdio(NULL);   }   long long n, a[N], b[N], sum, sum2, ans, dp[N], t;   string s;   int main() {     boost();     cin >> t;     for (int l = 1; l <= t; ++l) {       cin >> n;       sum = 0;       ans = 0;       for (int i = 1; i <= n; ++i) {         cin >> a[i];       }       for (int i = 1; i <= n; ++i) {         sum += a[i];         if (sum <= 0) {           cout <<  NO  <<   n ;           ans = 1;           break;         }       }       sum = 0;       for (int i = n; i >= 1; --i) {         sum += a[i];         if (sum <= 0 && ans == 0) {           cout <<  NO  <<   n ;           ans = 1;           break;         }       }       if (!ans) {         cout <<  YES  <<   n ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   const double PI = 3.1415926535897932384626433;   int MOD = 0;   int pl(int v1, int v2) {     int res = v1 + v2;     if (res < 0)       res += MOD;     else if (res >= MOD)       res -= MOD;     return res;   }   int mul(const int v1, const int v2) { return (int)((1LL * v1 * v2) % MOD); }   const int N = 250007;   vector<int> fac(N);   void initFac() {     fac[1] = 1;     for (int i = 2; i < N; i++) {       fac[i] = mul(fac[i - 1], i);     }   }   void solve() {     int n;     cin >> n;     ;     cin >> MOD;     if (n == 1) {       cout << 1 << endl;       return;     }     initFac();     int ans = mul(fac[n], n);     ans = pl(ans, fac[n]);     for (int len = 2; len < n; len++) {       int lans = n - len + 1;       lans = mul(lans, fac[len]);       lans = mul(lans, n - len + 1);       lans = mul(lans, fac[n - len]);       ans = pl(ans, lans);     }     cout << ans << endl;   }   int main() {     cin.tie(nullptr);     std::ios::sync_with_stdio(false);     solve();   }


#include <bits/stdc++.h>   #pragma warning(disable : 4996)   using namespace std;   vector<int> get_sb(int num) {     vector<int> res;     while (num) {       res.push_back(num % 10);       num /= 10;     }     return res;   }   string get_a(vector<int> kol, string sub) {     string reserve =  9 ;     ++reserve[0];     if (sub[0] ==  0 ) return reserve;     string ss =   ;     for (int i = 0; i < kol.size(); ++i) {       for (int j = 0; j < kol[i]; ++j) ss += (char)(i +  0 );     }     return sub + ss;   }   string get_b(vector<int> kol, string sub) {     string res =   ;     string reserve =  9 ;     ++reserve[0];     int mc = -1;     for (int i = 1; i < kol.size(); ++i) {       if (0 != kol[i]) {         mc = i;         break;       }     }     if (-1 == mc) return reserve;     int cci = sub[0] -  0 ;     res += (char)(mc +  0 );     --kol[mc];     for (int i = 0; i < cci; ++i) {       for (int j = 0; j < kol[i]; ++j) res += (char)(i +  0 );     }     res += sub;     for (int i = cci; i < kol.size(); ++i) {       for (int j = 0; j < kol[i]; ++j) res += (char)(i +  0 );     }     return res;   }   string get_c(vector<int> kol, string sub) {     string res =   ;     string reserve =  9 ;     ++reserve[0];     int mc = -1;     for (int i = 1; i < kol.size(); ++i) {       if (0 != kol[i]) {         mc = i;         break;       }     }     if (-1 == mc) return reserve;     int cci = sub[0] -  0 ;     res += (char)(mc +  0 );     --kol[mc];     for (int i = 0; i <= cci; ++i) {       for (int j = 0; j < kol[i]; ++j) res += (char)(i +  0 );     }     res += sub;     for (int i = cci + 1; i < kol.size(); ++i) {       for (int j = 0; j < kol[i]; ++j) res += (char)(i +  0 );     }     return res;   }   int main() {     string num, sub;     getline(cin, num);     getline(cin, sub);     if (num ==  01  || num ==  10 ) {       printf( 0 );       return 0;     }     int len_all = (int)num.size();     bool flag = true;     for (int i = 1; i < sub.size(); ++i) {       if (sub[i - 1] < sub[i]) {         flag = false;         break;       }     }     vector<int> kol(10);     for (int i = 0; i < num.size(); ++i) ++kol[num[i] -  0 ];     for (int i = 0; i < sub.size(); ++i) --kol[sub[i] -  0 ];     for (int aa = 1; aa <= 1000000; ++aa) {       bool flag = true;       vector<int> vv = get_sb(aa);       vector<int> kol1 = kol;       for (int i = 0; i < vv.size(); ++i) {         --kol1[vv[i]];         if (kol1[vv[i]] < 0) {           flag = false;           break;         }       }       if (!flag) continue;       int vsz = (int)vv.size();       if (len_all - vsz != aa) continue;       string a = get_a(kol1, sub);       string b = get_b(kol1, sub);       string c = get_c(kol1, sub);       string ans = min(a, b);       ans = min(ans, c);       cout << ans;       break;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     int n, k;     cin >> n >> k;     int t[n];     for (int i = 0; i < n; i++) cin >> t[i];     sort(t, t + n);     if (k == n)       cout << t[n - 1] << endl;     else if (k == 0) {       if (t[0] - 1 == 0)         cout << -1 << endl;       else         cout << t[0] - 1 << endl;     } else if (k == 1) {       if (t[0] == t[1])         cout << -1 << endl;       else         cout << t[0] << endl;     } else if (t[k - 1] == t[k])       cout << -1 << endl;     else       cout << t[k - 1] << endl;   }


#include <bits/stdc++.h>   using namespace std;   int absol(int x);   int main() {     int n, C, left, right, top, bot;     char c;     int xy[10][2] = {{1, 3}, {0, 0}, {1, 0}, {2, 0}, {0, 1},                      {1, 1}, {2, 1}, {0, 2}, {1, 2}, {2, 2}};     cin >> n;     cin >> c;     C = c;     C -= 48;     left = C;     right = C;     top = C;     bot = C;     for (int i = 1; i < n; i++) {       cin >> c;       C = c;       C -= 48;       if (xy[C][0] < xy[left][0])         left = C;       else if (xy[C][0] > xy[right][0])         right = C;       if (xy[C][1] < xy[top][1])         top = C;       else if (xy[C][1] > xy[bot][1] || (bot != 0 && (C == 7 || C == 9)))         bot = C;     }     if ((absol(xy[bot][1] - xy[top][1]) == 2 &&          absol(xy[right][0] - xy[left][0]) == 2 && bot != 8 && bot != 0) ||         absol(xy[bot][1] - xy[top][1]) == 3) {       cout <<  YES  << endl;     } else       cout <<  NO  << endl;     return 0;   }   int absol(int x) {     if (x < 0)       return x * -1;     else       return x;   }


#include <bits/stdc++.h>   int const MAX = 1e5 + 5;   using namespace std;   bool check(long long m, long long ai, long long di, long long hm, long long am,              long long dm) {     long long retval;     if (hm % (ai - dm) == 0)       retval = m - (((hm) / (ai - dm))) * (am - (di));     else       retval = m - (1 + ((hm) / (ai - dm))) * (am - (di));     if (retval > 0) return true;     return false;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long hy, hm, ay, am, dy, dm;     cin >> hy >> ay >> dy >> hm >> am >> dm;     long long h, a, d;     cin >> h >> a >> d;     long long ans = LLONG_MAX;     for (long long i = 0; i < 1000; i++) {       for (long long j = 0; j < 1000; j++) {         long long ai = ay + i;         long long di = dy + j;         long long c = a * i + d * j;         if (ai <= dm) continue;         long long l = 0, r = 10000;         while (r - l > 1) {           long long mid = (l + r) >> 1;           if (check(hy + mid, ai, di, hm, am, dm))             r = mid;           else             l = mid;         }         if (!check(hy + l, ai, di, hm, am, dm)) l++;         if (l < 0) l = 0;         c += l * h;         ans = min(ans, c);       }     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   void solve(long long int input) {     long long int n;     cin >> n;     double a[n], b[n];     for (long long int i = 0; i < n; i++) cin >> a[i];     for (long long int i = 0; i < n; i++) cin >> b[i];     map<long double, long long int> mp;     long long int ans = 0;     long long int j = 0;     for (long long int i = 0; i < n; i++) {       if (a[i] == 0 && b[i] == 0) {         j++;         continue;       }       if (a[i] == 0) continue;       mp[(b[i] / (a[i]))]++;       ans = max(ans, mp[(b[i] / (a[i]))]);     }     cout << ans + j <<   n ;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long int x = 1;     for (long long int i = 1; i <= x; i++) solve(i);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 200005;   int n, a, b, k, pr[N], seq[N];   char s[200005];   int main() {     scanf( %d%d%d%d , &n, &a, &b, &k);     scanf( %s , s + 1);     int len = strlen(s + 1), lst = 0, cur = 0;     for (int i = 1; i <= len; ++i) {       if (s[i] ==  1 ) {         cur += (i - lst - 1) / b;         lst = i;       }     }     if (s[len] !=  1 ) cur += (len - lst) / b;     int ans = 0, now = 0, da = 0;     for (int i = 1; i <= len; ++i) {       now++;       if (s[i] ==  1 ) now = 0;       if (now == b) {         now = 0;         ans++;         seq[ans] = i;         if (cur - ans < a) break;       }     }     printf( %d n , ans);     for (int i = 1; i <= ans; ++i) printf( %d  , seq[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e6 + 5;   double a[maxn], st[maxn];   int len[maxn];   int main() {     int n, x;     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , &x);       a[i] = x;     }     int p = 0;     for (int i = 1; i <= n; i++) {       st[++p] = a[i];       len[p] = 1;       while (p > 1 && st[p] < st[p - 1]) {         st[p - 1] =             (st[p - 1] * len[p - 1] + st[p] * len[p]) / (len[p - 1] + len[p]);         len[p - 1] += len[p];         p--;       }     }     for (int i = 1; i <= p; i++) {       for (int j = 1; j <= len[i]; j++) {         printf( %.10f n , st[i]);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int32_t main() {     long long a, b;     cin >> a >> b;     double d = ((pow(b, 2)) - (pow(a, 2))) / (2 * a);     cout << fixed << setprecision(12) << abs(d);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   inline T SQR(T x) {     return x * x;   }   template <class T>   inline string TOSTR(const T &x) {     stringstream ss;     ss << x;     return ss.str();   }   template <class T>   void UPDATE_MIN(T &x, T y) {     if (y < x) {       x = y;     }   }   template <class T>   void UPDATE_MAX(T &x, T y) {     if (x < y) {       x = y;     }   }   int gcd(int a, int b) { return a ? gcd(b % a, a) : b; }   long long gcd(long long a, long long b) { return a ? gcd(b % a, a) : b; }   long long powmod(long long a, long long p, long long m) {     long long r = 1;     while (p) {       if (p & 1) r = r * a % m;       p >>= 1;       a = a * a % m;     }     return r;   }   template <typename K, typename V>   V GetWithDef(const std::unordered_map<K, V> &m, const K &key, const V &defval) {     auto it = m.find(key);     if (it == m.end()) {       return defval;     } else {       return it->second;     }   }   template <typename K, typename V>   void SetDef(std::unordered_map<K, V> &m, const K &key, const V &defval) {     auto it = m.find(key);     if (it == m.end()) m[key] = defval;   }   const int MOD = 1000 * 1000 * 1000 + 7;   const double PI = 3.1415926535897932384626433832795l;   struct Event {     int id;     long long x;     char type;     bool operator<(const Event &other) const {       if (x < other.x) return true;       if (x > other.x) return false;       return type < other.type;     }   };   Event events[2 * 200123];   int saved_max[200123];   int evtop = 0;   int N;   int main() {     ios_base::sync_with_stdio(0);     cin >> N;     for (int(i) = 0; (i) < (int)(N); (i)++) {       int x, w;       cin >> x >> w;       events[evtop++] = {i, x - w, 1};       events[evtop++] = {i, x + w, 0};     }     sort(events, events + evtop);     int max_cur_closed = 0;     for (int(i) = 0; (i) < (int)(evtop); (i)++) {       Event &e = events[i];       if (e.type == 1) {         saved_max[e.id] = max_cur_closed;       } else if (e.type == 0) {         UPDATE_MAX(max_cur_closed, saved_max[e.id] + 1);       } else         assert(0);     }     cout << max_cur_closed << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   #define f first   #define s second   #define ll long long   #define ld long double   #define pii pair <int,int>   #define pll pair <ll,ll>   #define pil pair <int,ll>   #define pli pair <ll,int>   #define pss pair <short,short>   #define ull unsigned long long   #define pdd pair <ld,ld>    #define pb push_back   #define mp make_pair   #define puu pair<ull,ull>   #define pvv pair<vector<int>, vector<int> >   #define _bp __builtin_popcount   #define ptt pair <pnode,pnode>   #define all(v) v.begin(),v.end()   #define en   n    void file()   {       freopen( input.txt , r ,stdin);       freopen( f.txt , w ,stdout);   }   void boos()   {    ios_base :: sync_with_stdio(0);    cin.tie(0);    cout.tie(0);   }   //const long double pi = acos(-1);   const ll INF = (ll)1e9 + 7ll;   const ll INF1 = 998244353;   const ll INF2 = (ll)1e9 + 9ll;   const ll LLINF = (ll)1e18;   const ll INTmx = (ll)1e9;   const ld EPS = (ld)1e-15;   const int N = 3e5 + 100;   string a[N];   ll st[N],dp[N],dp1[N],dp2[N];   int main()   {    boos();    //file();    int n,m;    cin >> n >> m;    int k = 0;    for(int i = 1;i <= n;i++)    {     cin >> a[i];     a[i] =  0  + a[i];     for(int j = 1;j <= m;j++)     {      if(a[i][j] ==  o )k++;     }    }    st[0] = 1;    dp1[0] = 1;    for(int i = 1;i <= k;i++)    {     st[i] = (st[i - 1] * 2ll) % INF1;    }    dp2[2] = 1;    dp1[2] = 1;    for(ll i = 3;i <= max(n,m);i++)    {     dp[i] = (dp[i - 2] + (st[i - 3] * (i - 2)) % INF1) % INF1;     if(i % 2 == 0)dp1[i] = (dp1[i - 1] * 2ll + 1ll) % INF1;     else dp1[i] = (dp1[i - 1] * 2ll) % INF1;     dp2[i] = dp[i];     dp2[i] = (dp2[i] + dp1[i]) % INF1;    }    //cout << dp2[3] <<     << k <<     << st[k - 2] << en;    ll ans = 0;    for(int i = 1;i <= n;i++)    {     int L = 1;     for(int j = 1;j <= m;j++)     {      if(a[i][j] ==  * )      {       if(L != j)       {        ans += (dp2[j - L] * st[k - (j - L)]) % INF1;        //ans += (st[j - L - 2] * st[k - (j - L)]) % INF1;        //cout << j - L <<    ;        ans %= INF1;       }       L = j + 1;      }     }     if(L != m + 1)     {      ans += (dp2[m - L + 1] * st[k - (m - L + 1)]) % INF1;      //ans += (st[m - L - 1] * st[k - (m - L + 1)]) % INF1;      //cout << m - L + 1 <<    ;      ans %= INF1;     }    }    //cout << dp[4] << en;    for(int j = 1;j <= m;j++)    {     int L = 1;     for(int i = 1;i <= n;i++)     {      if(a[i][j] ==  * )      {       if(L != i)       {        ans += (dp2[i - L] * st[k - (i - L)]) % INF1;        //ans += (st[i - L - 2] * st[k - (i - L)]) % INF1;        //cout << i - L <<    ;        ans %= INF1;       }       L = i + 1;      }     }     if(L != n + 1)     {      ans += (dp2[n - L + 1] * st[k - (n - L + 1)]) % INF1;      //ans += (st[n - L - 1] * st[k - (n - L + 1)]) % INF1;      //cout << n- L + 1 <<    ;      ans %= INF1;     }    }    cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   const int MX = 300005;   long long n, m, k;   struct node {     int id;     long long pos;     long long dir;   } no[MX];   int now[MX];   int ans[MX];   bool cmp(node a, node b) {     if (a.pos < b.pos) return true;     return false;   }   int main() {     char ss[5];     scanf( %I64d%I64d%I64d , &n, &m, &k);     long long p = 0;     for (int i = 0; i < n; i++) {       scanf( %I64d%s , &no[i].pos, ss);       --no[i].pos;       no[i].id = i;       no[i].dir = 1;       if (ss[0] ==  L ) no[i].dir = -1;       if (ss[0] ==  R )         p += (k + no[i].pos) / m;       else         p -= (k + m - 1 - no[i].pos) / m;       now[i] = ((no[i].pos + no[i].dir * k) % m + m) % m;     }     p = p % n;     sort(no, no + n, cmp);     sort(now, now + n);     for (int i = 0; i < n; i++) {       ans[no[((i - p) % n + n) % n].id] = now[i] + 1;     }     for (int i = 0; i < n; i++) {       printf( %d%c , ans[i], i == n - 1 ?   n  :    );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   const int MAXN = 200010;   int B[MAXN], C[MAXN], a[MAXN];   long long b[MAXN], c[MAXN];   struct Node {     int b, c, id;     bool operator<(const Node ano) const { return b + c < ano.b + ano.c; }   } opt[MAXN];   int cnt[MAXN];   bool check(int x) {     int now = x;     for (int i = 1; i <= n; i++) {       a[opt[i].id] = now;       now += ((opt[i + 1].b + opt[i + 1].c - opt[i].b - opt[i].c) / n);     }     memset(cnt, 0, sizeof cnt);     memset(b, 0, sizeof b);     memset(c, 0, sizeof c);     for (int i = 1; i <= n; i++) {       for (int j = 0; j < 30; j++) {         if ((a[i] >> j) & 1) cnt[j]++;       }     }     for (int i = 1; i <= n; i++) {       for (int j = 0; j < 30; j++) {         if ((a[i] >> j) & 1) {           b[i] += 1LL * cnt[j] * (1 << j);           c[i] += 1LL * n * (1 << j);         } else {           c[i] += 1LL * cnt[j] * (1 << j);         }       }     }     return b[1] + c[1] >= B[1] + C[1];   }   bool check2(int x) {     int now = x;     for (int i = 1; i <= n; i++) {       a[opt[i].id] = now;       now += ((opt[i + 1].b + opt[i + 1].c - opt[i].b - opt[i].c) / n);     }     memset(cnt, 0, sizeof cnt);     memset(b, 0, sizeof b);     memset(c, 0, sizeof c);     for (int i = 1; i <= n; i++) {       for (int j = 0; j < 30; j++) {         if ((a[i] >> j) & 1) cnt[j]++;       }     }     for (int i = 1; i <= n; i++) {       for (int j = 0; j < 30; j++) {         if ((a[i] >> j) & 1) {           b[i] += 1LL * cnt[j] * (1 << j);           c[i] += 1LL * n * (1 << j);         } else {           c[i] += 1LL * cnt[j] * (1 << j);         }       }     }     for (int i = 1; i <= n; i++) {       if ((b[i] != B[i]) || (c[i] != C[i])) return 0;     }     return 1;   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++)       scanf( %d , &opt[i].b), B[i] = opt[i].b, opt[i].id = i;     for (int i = 1; i <= n; i++) scanf( %d , &opt[i].c), C[i] = opt[i].c;     sort(opt + 1, opt + n + 1);     for (int i = 2; i <= n; i++) {       if ((opt[i].b + opt[i].c - opt[i - 1].b - opt[i - 1].c) % n != 0) {         puts( -1 );         return 0;       }     }     int l = 0, r = 1000000000;     while (l < r) {       int mid = (l + r) >> 1;       if (check(mid))         r = mid;       else         l = mid + 1;     }     if (check2(l)) {       for (int i = 1; i <= n; i++) printf( %d%c , a[i], (i == n ? 10 :    ));     } else       puts( -1 );   }


#include <bits/stdc++.h>   using namespace std;   const int N = (1 << 18);   const double PI = acos(-1.0);   char s[N];   int lA, lB;   int a[N], b[N];   int inB[110][N];   int S, B;   struct cpx {     double x, y;     cpx(double p = 0, double q = 0) : x(p), y(q) {}     cpx operator+(cpx &o) { return cpx(x + o.x, y + o.y); }     cpx operator-(cpx &o) { return cpx(x - o.x, y - o.y); }     cpx operator*(cpx &o) { return cpx(x * o.x - y * o.y, x * o.y + y * o.x); }   } u[N], v[N];   void fft(cpx *a, int n, int f) {     int i, j, k;     for (i = j = 0; i < n; ++i) {       if (i > j) swap(a[i], a[j]);       for (k = n >> 1; (j ^= k) < k; k >>= 1)         ;     }     for (i = 1; i < n; i <<= 1) {       cpx wn(cos(PI / i), f * sin(PI / i));       for (j = 0; j < n; j += i << 1) {         cpx w(1, 0);         for (k = 0; k < i; ++k, w = w * wn) {           cpx x = a[j + k], y = w * a[i + j + k];           a[j + k] = x + y;           a[i + j + k] = x - y;         }       }     }     if (f == -1)       for (i = 0; i < n; ++i) a[i].x /= n, a[i].y /= n;   }   void work(int *a, int A, int id) {     int n = 1;     while (n <= A + lB) n <<= 1;     for (int i = 0; i < A; ++i) u[i] = cpx(a[i], 0);     for (int i = A; i < n; ++i) u[i] = cpx(0, 0);     for (int i = 0; i < A - 1 - i; ++i) swap(u[i], u[A - 1 - i]);     for (int i = 0; i < lB; ++i) v[i] = cpx(b[i], 0);     for (int i = lB; i < n; ++i) v[i] = cpx(0, 0);     fft(u, n, 1), fft(v, n, 1);     for (int i = 0; i < n; ++i) u[i] = u[i] * v[i];     fft(u, n, -1);     for (int i = 0; i < lB; ++i) inB[id][i] = (A - round(u[i].x)) / 2;   }   int main() {     scanf( %s , s);     lA = strlen(s);     for (int i = 0; i < lA; ++i) a[i] = (s[i] ==  1  ? 1 : -1);     scanf( %s , s);     lB = strlen(s);     for (int i = 0; i < lB; ++i) b[i] = (s[i] ==  1  ? 1 : -1);     S = sqrt(lA * log2(lA));     B = ceil(1. * lA / S);     for (int i = 0; i < B; ++i) {       int l = i * S, r = min(lA, l + S);       work(a + l, r - l, i);     }     int q;     scanf( %d , &q);     while (q--) {       int l, r, len, res = 0;       scanf( %d %d %d , &l, &r, &len);       int p = l / S, q = (l + len - 1) / S;       if (p == q) {         for (int i = l; i < l + len; ++i) res += (a[i] != b[i - l + r]);       } else {         for (int i = l; i < (p + 1) * S; ++i) res += (a[i] != b[i - l + r]);         for (int i = p + 1; i < q; ++i) res += (inB[i][(i + 1) * S - 1 - l + r]);         for (int i = q * S; i < l + len; ++i) res += (a[i] != b[i - l + r]);       }       printf( %d n , res);     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k, a, b;     cin >> n >> k >> a >> b;     bool impossible = false;     string s;     int curGroup = (a > b) ? 0 : 1;     int groupSize = 0;     for (int i = 0; i < n; ++i) {       if (curGroup) {         if (!b--) {           impossible = true;           break;         }         s.push_back( B );       } else {         if (!a--) {           impossible = true;           break;         }         s.push_back( G );       }       if (++groupSize == k || ((curGroup && a > b) || (!curGroup && b > a))) {         curGroup = 1 - curGroup;         groupSize = 0;       }     }     cout << (impossible ?  NO  : s) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int v[3 * 100001];   int main() {     int n;     long long s = 0;     cin >> n;     for (int i = 1; i <= n; ++i) {       cin >> v[i];     }     sort(v + 1, v + n + 1);     for (int i = 1; i <= n / 2; ++i) {       s += (v[i] + v[n - i + 1]) * (v[i] + v[n - i + 1]);     }     cout << s;     return 0;   }


#include <bits/stdc++.h>   #pragma GCC target( sse4,avx )   struct Solution {     int n;     std::vector<std::vector<int>> graph;     std::vector<std::vector<int>> matrix;     int counter;     std::vector<int> dirtyFlags;     std::vector<double> maxProbs;     double checkFirst(int a) {       double res = 0;       for (int dist = 0; dist < n; dist++) {         std::vector<int> group;         for (int i = 0; i < n; i++) {           if (matrix[a][i] == dist) {             group.push_back(i);           }         }         if (group.size() == 0) continue;         double caseProb = group.size() / (double)n;         double c = 1.0 / group.size();         double ans = c;         std::vector<double> t(n);         for (int v : group) {           for (int nv : graph[v]) {             t[nv] += c / graph[v].size();           }         }         std::vector<int> groupT;         std::vector<double> groupTD;         for (int i = 0; i < n; i++) {           if (t[i] > 1e-20) {             groupT.push_back(i);             groupTD.push_back(t[i]);           }         }         for (int b = 0; b < n; b++) {           counter++;           double cur = 0;           for (size_t i = 0; i < groupT.size(); i++) {             int v = groupT[i];             double tv = groupTD[i];             int d = matrix[b][v];             if (dirtyFlags[d] == counter) {               if (tv > maxProbs[d]) {                 cur += tv - maxProbs[d];                 maxProbs[d] = tv;               }             } else {               dirtyFlags[d] = counter;               maxProbs[d] = tv;               cur += tv;             }           }           ans = std::max(ans, cur);         }         res += caseProb * ans;       }       return res;     }     void run(std::istream& in, std::ostream& out) {       int m;       in >> n >> m;       graph.clear();       graph.resize(n);       matrix.clear();       matrix.resize(n, std::vector<int>(n, 1000000));       for (int i = 0; i < n; i++) {         matrix[i][i] = 0;       }       for (int i = 0; i < m; i++) {         int a, b;         in >> a >> b;         a--;         b--;         graph[a].push_back(b);         graph[b].push_back(a);         matrix[a][b] = 1;         matrix[b][a] = 1;       }       for (int i = 0; i < n; i++) {         for (int j = 0; j < n; j++) {           for (int k = 0; k < n; k++) {             matrix[j][k] = std::min(matrix[j][k], matrix[j][i] + matrix[i][k]);           }         }       }       counter = 0;       dirtyFlags.resize(n);       maxProbs.resize(n);       double ans = 0;       for (int a = 0; a < n; a++) {         ans = std::max(ans, checkFirst(a));       }       out.precision(12);       out << ans << std::endl;     }   };   int main() {     std::cin.sync_with_stdio(false);     std::cin.tie(nullptr);     Solution().run(std::cin, std::cout);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   set<string> f;   int main() {     int n;     cin >> n;     int ans = 0;     for (int i = 0; i < n; ++i) {       string s =   ;       while (1) {         char c;         cin >> c;         if (isdigit(c)) s += c;         if (((int)(s).size()) == 4) break;       }       swap(s[2], s[3]);       string t = s;       for (int i = 0; i < 4; ++i) {         char c = s[0];         for (int j = 0; j < 3; ++j) s[j] = s[j + 1];         s[3] = c;         if (s < t) t = s;       }       if (!f.count(t)) ++ans;       f.insert(t);     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 ,  unroll-all-loops )   #pragma GCC target( sse4.2 )   using namespace std;   const long long kk = 1000;   const long long ml = kk * kk;   const long long mod = ml * kk + 7;   const long long inf = ml * ml * ml + 7;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   long long n;   bool viv = false;   string a, b;   int in[20], out[20];   vector<vector<int>> comp;   void DFS(int v, vector<bool> &used) {     used[v] = true;     comp.back().push_back(v);     for (int s = 0; s < 20; s++)       if ((out[v] & (1 << s)) || (in[v] & (1 << s)))         if (!used[s]) DFS(s, used);   }   void get_comp() {     vector<bool> used(20, false);     for (int i = 0; i < 20; i++)       if (!used[i]) {         comp.push_back({});         DFS(i, used);       }   }   int cnt(int val) {     int res = 0;     while (val) res += (val & 1), val >>= 1;     return res;   }   void solve() {     cin >> n;     cin >> a >> b;     comp.clear();     for (int i = 0; i < 20; i++) in[i] = out[i] = 0;     for (int i = 0; i < n; i++)       if (a[i] != b[i]) {         out[a[i] -  a ] |= (1 << (b[i] -  a ));         in[b[i] -  a ] |= (1 << (a[i] -  a ));       }     bool dag[1 << 20];     for (int i = 0; i < (1 << 20); i++) dag[i] = false;     dag[0] = true;     for (int mask = 0; mask < (1 << 20); mask++) {       for (int i = 0; i < 20; i++)         if ((mask >> i) & 1) {           if (((mask ^ (1 << i)) & (in[i])) == 0)             dag[mask] |= dag[mask ^ (1 << i)];         }     }     get_comp();     int ans = 0;     for (auto c : comp) {       if (viv) {         for (auto i : c) cout << i <<    ;         cout << endl;       }       int sz = c.size();       int mx_dag = 0;       for (int smask = 0; smask < (1 << sz); smask++) {         int mask = 0;         for (int i = 0; i < sz; i++)           if ((smask >> i) & 1) mask ^= (1 << c[i]);         if (dag[mask]) mx_dag = max(mx_dag, cnt(mask));       }       ans += 2 * sz - mx_dag - 1;     }     cout << ans <<   n ;     if (viv) cout <<   t____ t____ t  << endl;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long t = 1;     cin >> t;     while (t--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int n, m, k, w;   vector<vector<vector<char>>> mp;   struct dsu {     vector<long long int> p, sz;     dsu(long long int n) {       p.resize(n);       sz.resize(n, 1);       for (long long int i = 0; i < n; i++) p[i] = i;     }     long long int getRoot(long long int v) {       if (p[v] == v)         return v;       else         return p[v] = getRoot(p[v]);     }     void unite(long long int a, long long int b) {       a = getRoot(a);       b = getRoot(b);       if (a != b) {         if (sz[a] < sz[b]) swap(a, b);         p[b] = a;         sz[a] += sz[b];       }     }     bool inOne(long long int a, long long int b) {       a = getRoot(a);       b = getRoot(b);       return a == b;     }   };   long long int getR(long long int a, long long int b) {     long long int ans = 0;     for (long long int i = 0; i < n; i++) {       for (long long int j = 0; j < m; j++) {         ans += (mp[a][i][j] != mp[b][i][j]);       }     }     return ans;   }   struct edge {     long long int a, b, w;     edge(long long int a = 0, long long int b = 0, long long int w = 0) {       this->a = a;       this->b = b;       this->w = w;     }   };   bool cmp(const edge& a, const edge& b) { return a.w < b.w; }   vector<vector<long long int>> g;   vector<pair<long long int, long long int>> path;   void dfs(long long int v = 0, long long int p = -1) {     if (p > -1) path.push_back({v, p});     for (auto to : g[v]) {       if (to == p) continue;       dfs(to, v);     }   }   signed main() {     cin >> n >> m >> k >> w;     mp.resize(k + 1, vector<vector<char>>(n, vector<char>(m)));     g.resize(k + 1);     for (long long int i = 1; i <= k; i++) {       for (long long int j = 0; j < n; j++) {         for (long long int w = 0; w < m; w++) cin >> mp[i][j][w];       }     }     vector<edge> ed;     for (long long int i = 1; i <= k; i++) ed.push_back(edge(0, i, n * m));     for (long long int i = 1; i <= k; i++) {       for (long long int j = i + 1; j <= k; j++)         ed.push_back(edge(i, j, getR(i, j) * w));     }     sort(ed.begin(), ed.end(), cmp);     dsu s(k + 1);     long long int ans = 0;     for (auto e : ed) {       long long int a = e.a, b = e.b, w = e.w;       if (s.inOne(a, b)) continue;       ans += w;       s.unite(a, b);       g[a].push_back(b);       g[b].push_back(a);     }     dfs();     cout << ans <<   n ;     for (auto i : path) cout << i.first <<     << i.second <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 5000 + 10, MOD = 1000000007;   vector<pair<int, int> > lis[MAXN * 2];   pair<int, int> p[MAXN];   int n, f[MAXN], cnt;   bool b[MAXN];   int dis(const pair<int, int> &a, const pair<int, int> &b) {     return abs(a.first - b.first) + abs(a.second - b.second);   }   int getf(int first) {     if (first == f[first]) return first;     int fx = f[first];     f[first] = getf(f[first]);     b[first] ^= b[fx];     return f[first];   }   bool Merge(int first, int second) {     int fx = getf(first), fy = getf(second);     if (fx == fy) return b[first] ^ b[second];     f[fx] = fy;     b[fx] = b[first] ^ b[second] ^ 1;     --cnt;     return true;   }   int Pow(int a, int b) {     int d = 1;     for (; b; d = (b & 1) ? (long long)d * a % MOD : d,               a = (long long)a * a % MOD, b /= 2)       ;     return d;   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; ++i) scanf( %d%d , &p[i].first, &p[i].second);     for (int i = 1; i <= n; ++i)       for (int j = i + 1; j <= n; ++j)         lis[dis(p[i], p[j])].push_back(make_pair(i, j));     cnt = n;     for (int i = 1; i <= n; ++i) f[i] = i, b[i] = 0;     for (int i = MAXN * 2 - 1; i >= 1; --i) {       bool flag = true;       int sum = cnt;       for (vector<pair<int, int> >::iterator it = lis[i].begin();            it != lis[i].end(); ++it)         if (!Merge(it->first, it->second)) {           flag = false;           break;         }       if (!flag) {         cout << i << endl;         cout << Pow(2, sum) << endl;         exit(0);       }     }     cout << 0 << endl << 2 << endl;     fclose(stdin);     fclose(stdout);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   #pragma comment(linker,  /STACK:102400000,102400000 )   const int N = 1e5 + 10, M = 1024;   int a[N], cnt[N], n, k, x;   int main() {     scanf( %d %d %d , &n, &k, &x);     int ai;     for (int i = 1; i <= n; i++) {       scanf( %d , &ai);       a[ai]++;     }     for (int ca = 1; ca <= k; ca++) {       int tot = 0, y;       for (int i = 0; i <= M; i++) {         if (tot & 1)           cnt[i] = a[i] >> 1;         else           cnt[i] = (a[i] + 1) >> 1;         tot += a[i];       }       for (int i = 0; i <= M; i++) a[i] -= cnt[i], a[i ^ x] += cnt[i];     }     for (int i = M; i >= 0; i--)       if (a[i]) {         printf( %d  , i);         break;       }     for (int i = 0; i <= M; i++)       if (a[i]) {         printf( %d n , i);         break;       }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 333333;   vector<pair<int, int> > graph[N];   int vis[N], d[N];   bool has[N];   int n, m;   int dfs(int u) {     vis[u] = true;     int cnt = 0;     for (auto e : graph[u]) {       if (!vis[e.first]) {         if (dfs(e.first)) {           has[e.second] = true;           cnt++;         }       }     }     return cnt % 2 != d[u];   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cin >> n >> m;     for (int i = (1); i <= (n); i++) {       cin >> d[i];     }     for (int i = (1); i <= (m); i++) {       int u, v;       cin >> u >> v;       graph[u].push_back(make_pair(v, i));       graph[v].push_back(make_pair(u, i));     }     int cnt = 0;     for (int i = (1); i <= (n); i++) {       cnt += d[i] == 1;     }     for (int i = (1); i <= (n); i++) {       if (d[i] == -1) {         if (cnt & 1) {           d[i] = 1;           cnt++;         } else {           d[i] = 0;         }       }     }     if (cnt & 1) {       cout << -1 <<   n ;       return 0;     }     dfs(1);     vector<int> v;     for (int i = (1); i <= (m); i++) {       if (has[i]) {         v.push_back(i);       }     }     cout << (int)(v).size() <<   n ;     for (auto x : v) {       cout << x <<    ;     }     cout <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int a[n];     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);     }     int sol = 0;     for (int i = 1; i <= n; i++) {       int cnt = 1;       for (int j = i - 1; j >= 1; j--) {         if (a[j] > a[j + 1])           break;         else           cnt++;       }       for (int k = i + 1; k <= n; k++) {         if (a[k] > a[k - 1])           break;         else           cnt++;       }       sol = max(sol, cnt);     }     cout << sol;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, p[1000010], cur[1000010 * 2];   int main() {     long long ans = 0, sum = 0;     int l = 0, r = 0, temp = 0;     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &p[i]);     for (int i = 1; i <= n; i++) {       sum += abs(p[i] - i);       if (p[i] >= i) {         l++;         cur[p[i] - i]++;       } else         r++;     }     ans = sum;     for (int i = 0; i < n - 1; i++) {       l -= cur[i];       r += cur[i];       sum = sum - l + r - abs(p[n - i] - n - 1) + p[n - i] - 1;       cur[p[n - i] + i]++;       l++, r--;       if (sum < ans) {         ans = sum;         temp = i + 1;       }     }     printf( %lld %d n , ans, temp);     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   const int INF = 2000 * 1000 * 1000;   int calc(int sweet, string str) {     int mx = -1;     for (register int i = (0); i < (int)(((int)(str).size())); ++i)       if (sweet > 0 && str[i] ==  H ) {         mx = max(mx, i);         str[i] =  . ;         sweet--;       }     int pos = 0;     vector<pair<int, int> > v;     for (register int i = (0); i < (int)(((int)(str).size())); ++i)       if (str[i] ==  H ) {         while (pos < ((int)(str).size()) && str[pos] !=  S ) pos++;         if (pos == ((int)(str).size())) return INF;         str[pos] =  . ;         if (pos > i)           v.push_back(pair<int, int>(i, pos));         else           mx = max(mx, i);       }     sort((v).begin(), (v).end());     vector<pair<int, int> > u;     for (register int i = (0); i < (int)(((int)(v).size())); ++i)       if (u.empty() || u.back().second < v[i].first)         u.push_back(v[i]);       else         u.back().second = v[i].second;     if (u.empty()) return mx + 1;     mx = max(mx, u.back().second);     int res = mx + 1;     for (__typeof((u).begin()) it = (u).begin(); it != (u).end(); ++it)       res += 2 * (it->second - it->first);     int ans = res;     for (int i = ((int)(u).size()) - 1; i >= 0; i--) {       res -= u[i].second - u[i].first;       res += i + 1 == ((int)(u).size()) ? mx - u.back().second                                         : u[i + 1].first - u[i].second;       ans = min(ans, res);     }     return ans;   }   int main() {     int n, t;     string s;     cin >> n >> t >> s;     if (calc(n, s) > t) {       cout << -1 << endl;       return 0;     }     int mn = 0, mx = n;     while (mn < mx) {       int mid = (mn + mx) / 2;       if (calc(mid, s) <= t)         mx = mid;       else         mn = mid + 1;     }     cout << mn << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = 1e17;   int n, s, e, nxt[5001];   long long x[5001], a[5001], b[5001], c[5001], d[5001];   long long dp[5001][5001];   inline long long dis(int s, int e) {     return (s < e) ? d[s] + a[e] : c[s] + b[e];   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cin >> n >> s >> e;     s--, e--;     for (int i = 0; i < n; i++) cin >> x[i];     for (int i = 0; i < n; i++) cin >> a[i], a[i] += x[i];     for (int i = 0; i < n; i++) cin >> b[i], b[i] -= x[i];     for (int i = 0; i < n; i++) cin >> c[i], c[i] += x[i];     for (int i = 0; i < n; i++) cin >> d[i], d[i] -= x[i];     long long ans = dis(s, e);     nxt[s] = e;     for (int i = 0; i < n; i++) {       if (i == s || i == e) continue;       long long minv = INF, ind = i;       for (int j = s; j != e; j = nxt[j]) {         long long val = dis(j, i) + dis(i, nxt[j]) - dis(j, nxt[j]);         if (val < minv) {           minv = val;           ind = j;         }       }       ans += minv;       nxt[i] = nxt[ind];       nxt[ind] = i;     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int N, M, P, Q;   int A[101], B[101];   int w[202][202];   bool V[202];   vector<int> path;   bool dfs(int n) {     path.push_back(n);     V[n] = 1;     if (n == N + N + 1) return 1;     for (int i = 0; i <= N + N + 1; i++)       if (!V[i] && w[n][i]) {         if (dfs(i)) return 1;       }     path.pop_back();     return 0;   }   int main() {     ios_base::sync_with_stdio(false);     cin >> N >> M;     for (int i = 1; i <= N; i++) cin >> A[i], w[0][i] = A[i], P += A[i];     for (int i = 1; i <= N; i++)       cin >> B[i], w[N + i][N + N + 1] = B[i], Q += B[i];     for (int i = 1; i <= N; i++) w[i][N + i] = 1e9;     for (int i = 1; i <= M; i++) {       int a, b;       cin >> a >> b;       w[a][N + b] = 1e9;       w[b][N + a] = 1e9;     }     int ans = 0;     while (dfs(0)) {       int flow = 2e9;       for (int i = 1; i < ((int)(path).size()); i++)         flow = min(flow, w[path[i - 1]][path[i]]);       for (int i = 1; i < ((int)(path).size()); i++) {         w[path[i - 1]][path[i]] -= flow;         w[path[i]][path[i - 1]] += flow;       }       ans += flow;       path.clear();       for (int i = 0; i <= N + N + 1; i++) V[i] = 0;     }     if (P != Q || ans != P) {       puts( NO );       return 0;     }     puts( YES );     for (int i = 1; i <= N; i++, puts(  ))       for (int j = 1; j <= N; j++) {         printf( %d  , w[N + j][i]);       }   }


#include <bits/stdc++.h>   using namespace std;   const long double PI = 4 * atan(1);   const int32_t MOD = 1e9 + 7;   int power(int x, unsigned int y) {     int temp;     if (y == 0) return 1;     temp = power(x, y / 2);     if (y % 2 == 0)       return temp * temp % MOD;     else       return x * temp % MOD * temp % MOD;   }   void solve() {     string s;     cin >> s;     int n = s.length();     string s1, s2;     cin >> s1 >> s2;     int m1 = s1.length(), m2 = s2.length();     int j = -1, k = -1;     bool f1 = 0, f2 = 0;     j = s.find(s1);     k = s.find(s2, s1.length() + j);     if (j != -1 && k != -1) f1 = 1;     reverse(s.begin(), s.end());     j = -1, k = -1;     j = s.find(s1);     k = s.find(s2, s1.length() + j);     if (j != -1 && k != -1) f2 = 1;     if (f1 && f2)       cout <<  both n ;     else if (f1)       cout <<  forward n ;     else if (f2)       cout <<  backward n ;     else       cout <<  fantasy n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(0);     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 111111;   vector<int> g[N];   bool s[N], f[N], used[N], foo[N], bar[N];   int q[N], qb, qe;   int main() {     int n;     cin >> n;     for (int i = 1; i < n; i++) {       int u, v;       cin >> u >> v;       g[u].push_back(v);       g[v].push_back(u);     }     for (int i = 1; i <= n; i++) cin >> s[i];     for (int i = 1; i <= n; i++) cin >> f[i];     vector<int> x;     q[qe++] = 1;     used[1] = true;     if (s[1] != f[1]) {       x.push_back(1);       foo[1] = 1;     }     while (qb < qe) {       int u = q[qb++];       for (int i = 0; i < g[u].size(); i++) {         int v = g[u][i];         if (used[v]) continue;         q[qe++] = v;         used[v] = true;         if ((s[v] ^ bar[u]) != f[v]) {           x.push_back(v);           foo[v] = bar[u] ^ 1;           bar[v] = foo[u];         } else {           foo[v] = bar[u];           bar[v] = foo[u];         }       }     }     cout << x.size() << endl;     for (int i = 0; i < x.size(); i++) cout << x[i] << endl;   }