#include <bits/stdc++.h>   using namespace std;   string a, b, c, s;   map<string, long long> m[3];   long long f, q;   bool sach(string aa) {     if (s.size() >= aa.size() && s.substr(s.size() - aa.size(), aa.size()) == aa)       return true;     return false;   }   void solve(long long i) {     if (sach(a)) {       if (m[i].count(b) || m[i].count(c)) {         cout <<  NO ;         exit(0);       }       f = 1;       m[i][a]++;     }     if (sach(b)) {       if (m[i].count(b) || m[i].count(c)) {         cout <<  NO ;         exit(0);       }       f = 1;       q = 1;       m[i][b]++;     }     if (sach(c)) {       if (m[i].size() && m[i].count(b) == 0) {         cout <<  NO ;         exit(0);       }       m[i][c]++;       f = 1;     }     if (m[1].size() && m[2].size()) {       cout <<  NO ;       exit(0);     }   }   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     vector<string> ss;     while (cin >> s) {       f = 0;       ss.push_back(s);       a =  lios , b =  etr , c =  initis ;       solve(1);       a =  liala , b =  etra , c =  inites ;       solve(2);       if (f == 0) {         cout <<  NO ;         exit(0);       }     }     if (ss.size() == 1 || q)       cout <<  YES ;     else       cout <<  NO ;   }


#include <bits/stdc++.h>   using namespace std;   int A[100];   int n;   int countNonZero = 0;   int sumElements(int size) {     int sum = 0;     for (int i = 0; i < size; i++) sum = sum + A[i];     return sum;   }   int findNonZero(int size) {     int ind = -1;     for (int i = 0; i < size; i++) {       if (A[i] != 0) {         ind = i;         break;       }     }     return ind;   }   void countZeros() {     for (int i = 0; i < n; i++) {       if (A[i] != 0) countNonZero++;     }   }   int main() {     int w;     cin >> n;     for (int i = 0; i < n; i++) cin >> A[i];     w = sumElements(n);     if (w != 0) {       cout <<  YES  << endl;       cout <<  1  << endl;       cout <<  1   << n << endl;       return 0;     } else {       int k = findNonZero(n);       if (k == -1 || countNonZero == 1) {         cout <<  NO  << endl;         return 0;       } else {         cout <<  YES  << endl;         cout <<  2  << endl;         cout <<  1   << k + 1 << endl;         cout << k + 2 <<     << n << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using namespace std;   int n, k, a[((int)(1e5) + 5)], x, y, bol[((int)(1e6 + 5))],       dp[((int)(1e6 + 5))], t, snr;   int main() {     cin >> n;     for (int i = 1; i <= n; i++) cin >> a[i];     cin >> x >> y;     sort(a + 1, a + n + 1);     n = unique(a + 1, a + n + 1) - a - 1;     for (int i = y; i <= x; i++) bol[i - y + 1] = 2;     for (int i = 1; i <= n; i++) {       t = a[i];       if (t < y)         if (!(y % t))           t = y;         else           t = ((y / t) + 1) * t;       if (t > x) continue;       for (; t <= x; t += a[i]) bol[t - y + 1] = a[i];     }     for (int i = y + 1; i <= x; i++) dp[i - y + 1] = ((int)(1e9 + 5));     for (int i = y; i <= x - 1; i++) {       t = -1;       snr = min(x, i + bol[i - y + 1] - 1);       for (int j = i + 1; j <= snr; j++) {         if (t == -1 or j + bol[j - y + 1] >= t + bol[t - y + 1]) t = j;         dp[j - y + 1] = min(dp[j - y + 1], dp[i - y + 1] + 1);       }       if (snr == x) break;       i = t - 1;     }     cout << dp[x - y + 1] <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int dp[31][31][51];   int solve(int i, int j, int k) {     if (i <= 0 || j <= 0) return 1e9;     if (i * j == k || k <= 0) return 0;     if (dp[i][j][k] != -1) return dp[i][j][k];     int op = 1e9;     for (int x = 1; x <= i; ++x)       for (int y = 1; y <= k; ++y)         op = min(op, j * j + solve(i - x, j, y) + solve(x, j, k - y));     for (int x = 1; x <= j; ++x)       for (int y = 1; y <= k; ++y)         op = min(op, i * i + solve(i, j - x, y) + solve(i, x, k - y));     return dp[i][j][k] = op;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     memset(dp, -1, sizeof(dp));     int t, n, m, k;     cin >> t;     while (t--) {       cin >> n >> m >> k;       cout << solve(n, m, k) <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 2e4 + 14;   const int INF = INT_MAX;   const int MAXC = 30;   const long long LLINF = 1e16 + 14;   int main() {     int t;     scanf( %d , &t);     while (t--) {       int n;       scanf( %d , &n);       int d;       scanf( %d , &d);       int res;       scanf( %d , &res);       for (int i = 1; i < n; ++i) {         int x;         scanf( %d , &x);         int need = i;         int add = min(d / need, x);         d -= add * need;         res += add;       }       printf( %d n , res);     }     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:16777216 )   using namespace std;   vector<vector<int>> g(1000);   bool removed[1000];   int cost[1000];   int n, d;   void input() {     cin >> n >> d;     for (int i = 0; i < n; i++) {       cin >> cost[i];     }   }   void solution() {     int sum = 0;     for (int i = 0; i < n; i++) sum += cost[i];     sum += 10 * (n - 1);     if (sum > d) {       cout << -1;     } else {       cout << (n - 1) * 2 + (d - sum) / 5;     }   }   int main() {     input();     solution();     return 0;   }


#include <algorithm>   #include <bitset>   #include <cmath>   #include <complex>   #include <cstdio>   #include <iostream>   #include <map>   #include <numeric>   #include <queue>   #include <random>   #include <set>   #include <stack>   #include <string>   #include <sys/types.h>   #include <unistd.h>   #include <unordered_map>   #include <unordered_set>   #include <vector>      #pragma region macros   #define _overload(_1, _2, _3, name, ...) name   #define _rep(i, n) _range(i, 0, n)   #define _range(i, a, b) for (int i = int(a); i < int(b); ++i)   #define rep(...) _overload(__VA_ARGS__, _range, _rep, )(__VA_ARGS__)   #define _rrep(i, n) _rrange(i, n, 0)   #define _rrange(i, a, b) for (int i = int(a) - 1; i >= int(b); --i)   #define rrep(...) _overload(__VA_ARGS__, _rrange, _rrep, )(__VA_ARGS__)   #pragma endregion macros      using namespace std;      template <class T> bool chmax(T &a, const T &b) {       return (a < b) ? (a = b, 1) : 0;   }   template <class T> bool chmin(T &a, const T &b) {       return (b < a) ? (a = b, 1) : 0;   }      using ll    = long long;   using R     = long double;   const R EPS = 1e-9L;  // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7   inline int sgn(const R &r) {       return (r > EPS) - (r < -EPS);   }   inline R sq(R x) {       return sqrt(max(x, 0.0L));   }      const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};   const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};      const pid_t pid = getpid();   // Problem Specific Parameter:      ll p[1010][1010];   ll psum[1010];   ll p2sum[1010];      int main(void) {       std::cin.tie(0);       std::ios::sync_with_stdio(false);          int m, k;       cin >> m >> k;          rep(i, k) {           rep(j, m) {               cin >> p[i][j];               psum[i] += p[i][j];               p2sum[i] += 1LL * p[i][j] * p[i][j];           }       }             const ll vsum = (psum[k - 1] - psum[0]) / (k - 1);       ll y          = -1;          rep(i, 1, k - 1) {           const ll v = (psum[i] - psum[i - 1]);           if (v != vsum) {               y = i;               break;           }       }          ll x;       rep(j, m) {           const ll v      = (psum[y] - psum[y - 1]);           const ll modify = vsum - v;              p2sum[y] -= p[y][j] * p[y][j];           p[y][j] += modify;           p2sum[y] += p[y][j] * p[y][j];              set<ll> s;           rep(i, 1, k - 1) {               const ll d2 = (p2sum[i - 1] + p2sum[i + 1]) - 2LL * p2sum[i];               s.insert(d2);           }              if (s.size() == 1) {               x = p[y][j];               break;           }              p2sum[y] -= p[y][j] * p[y][j];           p[y][j] -= modify;           p2sum[y] += p[y][j] * p[y][j];       }          cout << y <<     << x << endl;       return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long poww(long long a, long long b, long long md) {     return (!b ? 1                : (b & 1 ? a * poww(a * a % md, b / 2, md) % md                         : poww(a * a % md, b / 2, md) % md));   }   const long long MAXN = 1e6 + 10;   const long long INF = 8e18;   const long long MOD = 1e9 + 7;   pair<long long, long long> A[MAXN];   long long n;   set<pair<long long, long long> > st;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> A[i].first;       A[i].second = i;       st.insert({i, A[i].first});     }     sort(A, A + n);     long long ans = 0, val = 0;     long long rem = n;     for (int i = 0; i < n - 2; i++) {       auto it = st.find({A[i].second, A[i].first});       auto ite = st.end();       ite--;       if (it == st.begin() || it == ite) {         ans += (A[i].first - val) * (rem - 2);         val += (A[i].first - val);         st.erase(it);         rem--;       } else {         auto nxt = it, prv = it;         nxt++;         prv--;         ans += min(nxt->second, prv->second) - val;         st.erase(it);         rem--;       }     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct comp {     bool operator()(const vector<long long>& lhs,                     const vector<long long>& rhs) const {       return lhs[0] > rhs[0] || (lhs[0] == rhs[0] && lhs[2] > rhs[2]) ||              (lhs[0] == rhs[0] && lhs[2] == rhs[2] && lhs[1] > rhs[1]);     }   };   vector<long long> t;   vector<long long> ans;   priority_queue<vector<long long>, vector<vector<long long> >, comp> events;   queue<long long> q;   set<long long> inq;   priority_queue<long long, vector<long long>, greater<long long> > ready;   bool clear(long long index) {     auto it = inq.lower_bound(index);     if (it == inq.end()) return inq.empty();     return it == inq.begin();   }   int32_t main() {     ios::sync_with_stdio(false);     long long n, p;     cin >> n >> p;     t.resize(n);     ans.resize(n);     for (long long i = 0; i < n; i++) cin >> t[i];     for (long long i = 0; i < n; i++) events.push({t[i], i, 1});     while (!events.empty()) {       vector<long long> a = events.top();       events.pop();       long long status = a[2], index = a[1], time = a[0];       if (status == 1) {         if (clear(index)) {           if (q.empty()) events.push({time + p, index, 2});           q.push(index);           inq.insert(index);         } else           ready.push(index);       } else {         ans[index] = time;         q.pop();         inq.erase(index);         if (!ready.empty() && clear(ready.top())) {           long long nextIndex = ready.top();           ready.pop();           q.push(nextIndex);           inq.insert(nextIndex);         }         if (!q.empty()) {           long long nextIndex = q.front();           events.push({time + p, nextIndex, 2});         }       }     }     for (long long i = 0; i < n; i++) cout << ans[i] <<    ;   }


#include <bits/stdc++.h>   using namespace std;   int a[1000000], g[1000000], h[1000000];   int d[1000000];   int dp[1000000];   int up[1000000];   int h1[1000000];   int h2[1000000];   int t1[1000000];   int t2[1000000];   vector<int> v[1000000];   int x, y, n, m;   int maxy, one_kek, two_kek;   void dfs(int x, int pr = -1) {     h[x] = 1;     d[x] = g[x];     h1[x] = 0;     h2[x] = 0;     t1[x] = 0;     t2[x] = 0;     for (int i = 0; i < v[x].size(); i++) {       int to = v[x][i];       if (to == pr) continue;       dfs(to, x);       if (d[to] == 0) continue;       d[x] += d[to];       h[x] += h[to];       if (1 + h1[to] > h2[x]) {         h2[x] = 1 + h1[to];         t2[x] = to;         if (h2[x] > h1[x]) {           swap(h1[x], h2[x]);           swap(t1[x], t2[x]);         }       }     }     if (d[x] == 0) return;   }   void dfs1(int x, int pr = -1) {     if (d[x] == 0) return;     if (pr == -1)       dp[x] = h1[x];     else {       if (t1[pr] == x)         up[x] = 1 + max(up[pr], h2[pr]);       else         up[x] = 1 + max(up[pr], h1[pr]);       dp[x] = max(h1[x], up[x]);     }     for (int i = 0; i < v[x].size(); i++) {       int to = v[x][i];       if (to == pr) continue;       dfs1(to, x);     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cin >> n >> m;     for (int i = 1; i < n; i++) {       cin >> x >> y;       v[x].push_back(y);       v[y].push_back(x);     }     for (int i = 1; i <= m; i++) {       cin >> a[i];       g[a[i]]++;     }     if (m == 1) {       cout << a[1] <<   n  << 0;       return 0;     }     dfs(a[1]);     dfs1(a[1]);     for (int i = 1; i <= m; i++) {       if (dp[a[i]] > maxy) {         maxy = dp[a[i]];         one_kek = a[i];       } else if (dp[a[i]] == maxy)         one_kek = min(one_kek, a[i]);     }     cout << one_kek <<   n  << h[a[1]] * 2 - 2 - maxy <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int a[1003][1003];   int r[1003];   int c[1003];   char ch[5];   int main() {     int n, m, k;     scanf( %d %d %d , &n, &m, &k);     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         scanf( %d , &a[i][j]);       }     }     for (int i = 1; i <= n; i++) {       r[i] = i;     }     for (int i = 1; i <= m; i++) {       c[i] = i;     }     for (int i = 1; i <= k; i++) {       scanf( %s , ch);       int x, y;       scanf( %d %d , &x, &y);       if (ch[0] ==  r ) {         swap(r[x], r[y]);       } else if (ch[0] ==  c ) {         swap(c[x], c[y]);       } else {         printf( %d n , a[r[x]][c[y]]);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1000 * 1000 * 1000 + 7;   const double PI = acos(-1.0);   long long gcd(long long a, long long b) {     long long m;     while (b) {       m = a % b;       a = b;       b = m;     }     return a;   }   int solve() {     string s;     cin >> s;     long long total = 0;     int n = s.size();     for (int i = 0; i < n; ++i) {       if (s[i] >=  0  && s[i] <=  9 ) {         int j = i;         long long u = 0;         int dot = -1;         while (s[j] >=  0  && s[j] <=  9  || s[j] ==  . ) {           if (s[j] ==  . )             dot = j;           else             u = u * 10 + (s[j] -  0 );           ++j;         }         if (dot == -1 || j - dot != 3) u = u * 100;         total += u;         i = j - 1;       }     }     s.clear();     if (total % 100 != 0) {       s += total % 10 +  0 ;       total /= 10;       s += total % 10 +  0 ;       total /= 10;       s +=  . ;     } else {       total /= 100;     }     int j = 0;     do {       ++j;       s += total % 10 +  0 ;       if (j == 3) s +=  . , j = 0;     } while (total /= 10);     if (s.back() ==  . ) s.pop_back();     reverse(s.begin(), s.end());     cout << s << endl;     return 0;   }   int main() { solve(); }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     string s;     cin >> s;     int x = 0, y = 0;     for (int i = 0; i < s.size(); i++) s[i] ==  x  ? x++ : y++;     if (x > y)       for (int i = 0; i < x - y; i++) cout <<  x ;     else       for (int i = 0; i < y - x; i++) cout <<  y ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, req = 1;     scanf( %d , &n);     map<int, int> index;     for (int i = 0; i < n; i++) {       int x;       scanf( %d , &x);       if (x == req) {         index[x] = i + 1 + 2000;         req++;       }     }     int cnt = 0;     for (int i = 1; index[i] != 0; i++) {       cnt++;     }     printf( %d n , cnt);     if (cnt) printf( %d , index[1]);     for (int i = 2; index[i] != 0; i++) {       printf(  %d , index[i]);     }     if (cnt) printf(  n );     return 0;   }


#include <bits/stdc++.h>   #pragma warning(disable : 4996)   using namespace std;   int n, m;   char a[2000000], b[2000000];   int main() {     int i, j, k;     scanf( %s%s , a, b);     n = strlen(a), m = strlen(b);     int now = 0;     for (i = 0; i < m; i++) {       if (b[i] == a[now]) {         now++;         if (now == n) break;       }     }     int c1, c2;     c1 = i;     now = n - 1;     for (i = m - 1; i >= 0; i--) {       if (b[i] == a[now]) {         now--;         if (now == -1) break;       }     }     c2 = i;     printf( %d , max(0, c2 - c1));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int u[n + 1];     int a[n + 1][n + 1];     int maxx[n + 1];     int dom[n + 1];     for (int i = 1; i <= n; i++) {       cin >> u[i];       for (int j = 1; j <= n; j++) {         a[i][j] = 0;       }       maxx[i] = u[i];       dom[i] = 0;     }     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= i; j++) {         a[u[i]][j]++;         if (maxx[j] != u[i]) {           if (a[u[i]][j] > a[maxx[j]][j]) {             maxx[j] = u[i];             dom[u[i]]++;           } else if (a[u[i]][j] == a[maxx[j]][j]) {             if (u[i] < maxx[j]) {               maxx[j] = u[i];               dom[u[i]]++;             } else {               dom[maxx[j]]++;             }           } else if (a[u[i]][j] < a[maxx[j]][j]) {             dom[maxx[j]]++;           }         } else {           dom[u[i]]++;         }       }     }     for (int i = 1; i <= n; i++) {       cout << dom[i] <<    ;     }     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma )   #pragma GCC optimize( unroll-loops )   using namespace std;   long long MOD = 998244353;   double eps = 1e-12;   void solve() {     long long n;     cin >> n;     for (long long i = 0; i <= n; i++) {       for (long long j = 0; j <= n; j++) {         for (long long k = 0; k <= n; k++) {           if ((i * 3 + j * 5 + k * 7) == n) {             cout << i <<     << j <<     << k <<   n ;             return;           }         }       }     }     cout << -1 <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long t;     cin >> t;     for (int it = 1; it <= t; it++) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   using namespace std;   int main() {     int T;     cin >> T;     while (T--) {       long long n, m;       cin >> n >> m;       long long d = n / m;       long long w = m % 10;       long long sm = 0;       for (int i = 0; i < 10; i++) {         sm += (i * w) % 10;       }       long long fsm = 0;       for (int i = 1; i <= d % 10; i++) {         fsm += (i * w) % 10;       }       cout << sm * (d / 10) + fsm <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 5000 + 10;   int n, T;   double p[MAXN];   int t[MAXN];   double dp[MAXN][MAXN];   int main() {     scanf( %d%d , &n, &T);     for (int i = 1; i <= n; ++i) {       scanf( %lf%d , &p[i], &t[i]);       p[i] *= 0.01;     }     double ans = 0.0;     dp[0][0] = 1.0;     for (int i = 1; i <= n; ++i) {       double sum = 0.0;       double npn = pow(1.0 - p[i], t[i]);       for (int j = 1; j <= T; ++j) {         sum += dp[i - 1][j - 1];         if (j > t[i]) {           sum -= dp[i - 1][j - t[i] - 1] * npn;         }         dp[i][j] += sum * p[i];         if (j >= t[i]) {           dp[i][j] += dp[i - 1][j - t[i]] * npn;         }         sum *= 1.0 - p[i];         ans += dp[i][j];       }     }     printf( %.8f n , ans);     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   const int MAXBUF = 10000;   char buf[MAXBUF], *ps = buf, *pe = buf + 1;   inline bool isdigit(const char& n) { return (n >=  0  && n <=  9 ); }   inline void rnext() {     if (++ps == pe)       pe = (ps = buf) +            fread(buf, sizeof(char), sizeof(buf) / sizeof(char), stdin);   }   template <class T>   inline bool in(T& ans) {     ans = 0;     T f = 1;     if (ps == pe) return false;     do {       rnext();       if ( -  == *ps) f = -1;     } while (!isdigit(*ps) && ps != pe);     if (ps == pe) return false;     do {       ans = (ans << 1) + (ans << 3) + *ps - 48;       rnext();     } while (isdigit(*ps) && ps != pe);     ans *= f;     return true;   }   const int MAXOUT = 10000;   char bufout[MAXOUT], outtmp[50], *pout = bufout, *pend = bufout + MAXOUT;   inline void write() {     fwrite(bufout, sizeof(char), pout - bufout, stdout);     pout = bufout;   }   inline void out_char(char c) {     *(pout++) = c;     if (pout == pend) write();   }   inline void out_str(char* s) {     while (*s) {       *(pout++) = *(s++);       if (pout == pend) write();     }   }   template <class T>   inline void out_int(T x) {     if (!x) {       out_char( 0 );       return;     }     if (x < 0) x = -x, out_char( - );     int len = 0;     while (x) {       outtmp[len++] = x % 10 + 48;       x /= 10;     }     outtmp[len] = 0;     for (int i = 0, j = len - 1; i < j; i++, j--) swap(outtmp[i], outtmp[j]);     out_str(outtmp);   }   template <typename T, typename... T2>   inline int in(T& value, T2&... value2) {     in(value);     return in(value2...);   }   const double eps = 1e-9;   const int maxn = 5e5 + 10;   const int INF = 0x3f3f3f3f;   const int mod = 1e9 + 7;   int N, M, tmp, K, Q;   struct Edge {     int u, v, w, id;   } edge[maxn];   struct node {     int w, id, pointer;     friend bool operator<(node a, node b) { return a.w > b.w; }   };   vector<int> query[maxn];   priority_queue<node> P;   int Back[maxn][2];   int cnt;   int tree[maxn];   int Size[maxn];   int ans[maxn], ID[maxn];   void init() {     for (register int i = 1; i <= N; i++) tree[i] = i, Size[i] = 1;   }   int find(int p) {     if (p == tree[p]) return p;     return find(tree[p]);   }   bool Union(int u, int v) {     u = find(u);     v = find(v);     if (u == v) return false;     if (Size[u] > Size[v]) swap(u, v);     tree[u] = v;     Size[v] += Size[u];     Back[++cnt][0] = u;     Back[cnt][1] = v;     return true;   }   void Cancel() {     while (cnt) {       int u = Back[cnt][0];       int v = Back[cnt--][1];       tree[u] = u;       Size[v] -= Size[u];     }   }   bool cmp(Edge a, Edge b) { return a.w < b.w; }   int main() {     in(N, M);     init();     for (register int i = 1; i <= M; i++)       in(edge[i].u, edge[i].v, edge[i].w), edge[i].id = i;     sort(edge + 1, edge + M + 1, cmp);     for (register int i = 1; i <= M; i++) ID[edge[i].id] = i;     in(Q);     for (register int i = 1; i <= Q; i++) {       in(tmp);       while (tmp--) {         int t;         in(t);         t = ID[t];         query[i].push_back(t);       }       sort(query[i].begin(), query[i].end());       node h;       h.id = i;       h.pointer = 0;       h.w = query[i][0];       P.push(h);     }     for (int i = 1; i <= M;) {       int W = edge[i].w;       int j = i + 1;       for (; j <= M && edge[j].w == edge[i].w; j++)         ;       j--;       while (!P.empty()) {         node x = P.top();         if (x.w > j) break;         P.pop();         int v = x.id;         while (x.pointer < query[v].size() && query[v][x.pointer] <= j) {           if (!Union(edge[query[v][x.pointer]].u, edge[query[v][x.pointer]].v))             break;           x.pointer++;         }         Cancel();         if (x.pointer == query[v].size()) {           ans[x.id] = 1;           continue;         }         x.w = query[v][x.pointer];         if (x.w > j) P.push(x);       }       for (; i <= j; i++) Union(edge[i].u, edge[i].v);       cnt = 0;     }     for (register int i = 1; i <= Q; i++) {       if (ans[i] == 1)         puts( YES );       else         puts( NO );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100005;   inline int in() {     int x;     scanf( %d , &x);     return x;   }   inline long long lin() {     long long x;     scanf( %I64d , &x);     return x;   }   vector<int> G[N + N];   pair<int, int> edg[N + N];   int n, k, start;   int inp[N + N];   int st[N + N], T = 1;   long long res, f[N + N];   void dfs(int u, int par) {     st[u] = T++;     if (inp[u] == 1) f[u]++;     for (int i = 0; i < (int)G[u].size(); i++) {       int v = G[u][i];       if (v != par) {         dfs(v, u);         f[u] += f[v];         res += min(f[v], 2LL * k - f[v]);       }     }   }   int main() {     n = in();     k = in();     for (int i = 1; i <= k + k; i++) {       int x = in();       inp[x] = 1;     }     for (int i = 1; i <= n - 1; i++) {       int u = in(), v = in();       G[u].push_back(v);       G[v].push_back(u);       edg[i] = make_pair(u, v);     }     res = 0;     dfs(1, -1);     printf( %I64d n , res);   }


#include <bits/stdc++.h>   using namespace std;   bool test(long long, long long, long long);   int main(void) {     long long n, m;     cin >> n >> m;     long long first, last;     first = 0;     last = sqrt(2 * n) + 1;     if (m >= n) {       cout << n;       return 0;     }     while (test(first, n, m) == 0) {       long long med;       med = (first + last) / 2;       if (test(med, n, m) == 1)         last = med;       else         first = med;       if (last - first == 1 && test(first, n, m) == 0) first = last;     }     cout << first + m;     return 0;   }   bool test(long long day, long long n, long long m) {     if (day % 2 == 0) {       if ((day / 2) * (day + 1) >= (n - m)) return 1;     } else {       if (day * ((day + 1) / 2) >= (n - m)) return 1;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char s[50005];   map<string, int> st;   int sq = 300;   vector<int> p[500100];   vector<int> h;   string s1[500100];   int res[1010][1010];   void pro(int x1, int y1) {     int x = h[x1];     int y = h[y1];     int pri = -1, prj = -1;     int mn = 1e9;     int r;     for (int i = 0, j = 0; i < p[x].size() || j < p[y].size();) {       if (i < p[x].size() && j < p[y].size()) {         r = max(p[x][i] + s1[x].size(), p[y][j] + s1[y].size()) -             min(p[x][i], p[y][j]);         mn = min(mn, r);       }       if (i >= p[x].size())         prj = p[y][j], j++;       else if (j >= p[y].size())         pri = p[x][i], i++;       else if (p[x][i] < p[y][j])         pri = p[x][i], i++;       else         prj = p[x][j], j++;     }     res[x1][y1] = mn;     res[y1][x1] = mn;   }   int main() {     scanf( %s , s);     int n = strlen(s);     int k = 0;     for (int i = 0; i < n; i++) {       string t =   ;       for (int j = 0; j < 4 && j + i < n; j++) {         t.push_back(s[j + i]);         if (st.count(t) == 0) {           s1[k] = t;           st[t] = k++;         }         p[st[t]].push_back(i);       }     }     for (int i = 0; i < k; i++) {       if (p[i].size() > sq) {         h.push_back(i);       }     }     for (int i = 0; i < h.size(); i++) {       res[i][i] = s1[h[i]].size();       for (int j = i + 1; j < h.size(); j++) {         pro(i, j);       }     }     int q;     cin >> q;     char s2[10];     char s3[10];     vector<int>::iterator it, it1;     while (q--) {       scanf( %s , s2);       scanf( %s , s3);       if (st.count(s2) == 0 || st.count(s3) == 0) {         printf( -1 n );         continue;       }       int x = st[s2];       int y = st[s3];       it = lower_bound(h.begin(), h.end(), x);       it1 = lower_bound(h.begin(), h.end(), y);       int mn = 1e9, r;       if (it != h.end() && *it == x && it1 != h.end() && *it1 == y) {         printf( %d n , res[it - h.begin()][it1 - h.begin()]);         continue;       } else if (it == h.end() || *it != x) {         for (int i = 0; i < p[x].size(); i++) {           it = lower_bound(p[y].begin(), p[y].end(), p[x][i]);           if (it != p[y].end()) {             r = max(p[x][i] + s1[x].size(), *it + s1[y].size());             r -= min(p[x][i], *it);             mn = min(mn, r);           }           if (it != p[y].begin()) {             it--;             r = max(p[x][i] + s1[x].size(), *it + s1[y].size());             r -= min(p[x][i], *it);             mn = min(mn, r);           }         }       } else {         for (int i = 0; i < p[y].size(); i++) {           it = lower_bound(p[x].begin(), p[x].end(), p[y][i]);           if (it != p[x].end()) {             r = max(p[y][i] + s1[y].size(), *it + s1[x].size());             r -= min(p[y][i], *it);             mn = min(mn, r);           }           if (it != p[x].begin()) {             it--;             r = max(p[y][i] + s1[y].size(), *it + s1[x].size());             r -= min(p[y][i], *it);             mn = min(mn, r);           }         }       }       printf( %d n , mn);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, m, a[1000500];   map<pair<int, long long>, bool> dp;   bool found = false;   void solve(int idx, long long sum, bool take) {     if (found) return;     if (take && sum % m == 0) {       found = true;       return;     }     if (idx >= n) return;     bool &ret = dp[{idx, sum}];     if (ret) return;     ret = true;     solve(idx + 1, sum + a[idx], take + 1);     if (found) return;     solve(idx + 1, sum, take);     if (found) return;   }   int main() {     scanf( %lld%lld , &n, &m);     bool z = false;     for (int i = 0; i < n; ++i) scanf( %lld , &a[i]), z |= (a[i] == 0);     solve(0, 0, 0);     if (z || found) return puts( YES );     puts( NO );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline int read() {     char c = getchar();     int x = 0, f = 1;     for (; !isdigit(c); c = getchar())       if (c ==  - ) f = -1;     for (; isdigit(c); c = getchar()) x = x * 10 + c -  0 ;     return x * f;   }   const int MAXN = 8e3 + 5;   int nxt[MAXN], p[MAXN][MAXN], dp[MAXN];   int N, len;   char s[MAXN], S[MAXN];   inline int calc(int x) {     int ret = 0;     while (x) x /= 10, ret++;     return ret;   }   inline void KMP(int st) {     len = N - st + 1;     for (int i = 1; i <= len; i++) s[i] = S[st + i - 1];     int j = 0;     for (int i = 2; i <= len; i++) {       while (j && s[i] != s[j + 1]) j = nxt[j];       if (s[i] == s[j + 1]) j++;       nxt[i] = j;     }     for (int i = 1; i <= len; i++) {       int tmp = i - nxt[i];       if (i % tmp) tmp = i;       p[st][st + i - 1] = tmp + calc(i / tmp);     }   }   int main() {     scanf( %s , S + 1);     N = strlen(S + 1);     for (int i = 1; i <= N; i++) KMP(i);     memset(dp, 0x3f, sizeof(dp));     dp[0] = 0;     for (int i = 1; i <= N; i++)       for (int j = 0; j < i; j++) dp[i] = min(dp[i], dp[j] + p[j + 1][i]);     printf( %d n , dp[N]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   void maxtt(T& t1, T t2) {     t1 = max(t1, t2);   }   template <typename T>   void mintt(T& t1, T t2) {     t1 = min(t1, t2);   }   bool debug = 0;   int n, m, k;   string direc =  URDL ;   const long long MOD2 = (long long)1000000007 * (long long)1000000007;   long long ln, lk, lm;   void etp(bool f = 0) {     puts(f ?  YES  :  NO );     exit(0);   }   void addmod(int& x, int y, int mod = 1000000007) {     x += y;     if (x >= mod) x -= mod;     if (x < 0) x += mod;     assert(x >= 0 && x < mod);   }   void et(int x = -1) {     printf( %d n , x);     exit(0);   }   long long fastPow(long long x, long long y, int mod = 1000000007) {     long long ans = 1;     while (y > 0) {       if (y & 1) ans = (x * ans) % mod;       x = x * x % mod;       y >>= 1;     }     return ans;   }   long long gcd1(long long x, long long y) { return y ? gcd1(y, x % y) : x; }   int p[1000035], q[1000035];   void fmain(int tid) {     scanf( %d%lld , &n, &lk);     for (int(i) = 1; (i) <= (int)(n); (i)++) {       p[i] = q[i] = i;     }     long long mi = (long long)(n + 1) * n / 2;     int hf = n / 2;     long long mx = (long long)(n - hf + 1 + n) * hf;     if (n & 1) mx += n / 2 + 1;     if (lk < mi) et();     mintt(lk, mx);     long long tar = lk - mi;     for (int(i) = 1; (i) <= (int)(hf); (i)++) {       int bg = n + 1 - i;       if (bg - i <= tar) {         swap(q[i], q[bg]);         tar -= bg - i;       } else {         swap(q[i], q[i + tar]);         break;       }     }     printf( %lld n , lk);     for (int(i) = 1; (i) <= (int)(n); (i)++) printf( %d  , p[i]);     puts(  );     for (int(i) = 1; (i) <= (int)(n); (i)++) printf( %d  , q[i]);     puts(  );   }   int main() {     int t = 1;     for (int(i) = 1; (i) <= (int)(t); (i)++) {       fmain(i);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct abc {     int p, q, idx;   };   bool compareTwoStudents(abc a, abc b) {     if (a.p != b.p) return a.p < b.p;     return (a.q < b.q);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int i, j, k, m, n, t, u, v, w, p = 0, q, flag = 0;     long long int x, y, z;     string s, s1, s2;     vector<int> abc;     vector<int>::iterator it;     priority_queue<int> pq;     map<int, int> make_pair;     cin >> t;     while (t--) {       std::cin >> n;       std::cout << n <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   void out(T x) {     cout << x << endl;     exit(0);   }   const int maxn = 2000 + 7;   int n;   long double p;   int t;   long double dp[maxn][maxn];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n >> p >> t;     dp[0][0] = 1.0;     for (int i = 0; i < t; i++) {       for (int j = 0; j < n; j++) {         dp[i + 1][j] += (1.0 - p) * dp[i][j];         dp[i + 1][j + 1] += p * dp[i][j];       }       dp[i + 1][n] += dp[i][n];     }     long double ans = 0.0;     for (int i = 1; i <= n; i++) {       ans += 1.0 * i * dp[t][i];     }     cout << fixed << setprecision(12) << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize(3,  Ofast ,  inline )   #pragma GCC target( avx )   using namespace std;   template <class t>   inline t read(t &x) {     char c = getchar();     bool f = 0;     x = 0;     while (!isdigit(c)) f |= c ==  - , c = getchar();     while (isdigit(c)) x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();     if (f) x = -x;     return x;   }   template <class t>   inline void write(t x) {     if (x < 0)       putchar( - ), write(-x);     else {       if (x > 9) write(x / 10);       putchar( 0  + x % 10);     }   }   const int mod = 1e9 + 7, N = 705;   int ans, n, dig[N], f[N][N][10][2];   char s[N];   signed main() {     scanf( %s , s + 1);     n = strlen(s + 1);     for (int i = 1; i <= n; i++) dig[i] = s[i] ^ 48;     for (int i = 0; i <= 9; i++) f[0][0][i][0] = 1;     for (int i = 0; i < n; i++)       for (int j = 0; j <= i; j++)         for (int k = 1; k <= 9; k++)           for (int lim = 0; lim <= 1; lim++)             for (int x = 0; x <= (lim ? 9 : dig[i + 1]); x++)               (f[i + 1][j + (x >= k)][k][lim | (x < dig[i + 1])] +=                f[i][j][k][lim]) %= mod;     for (int k = 1; k <= 9; k++)       for (int i = 1, mul = 1; i <= n; i++)         ans = (ans + 1ll * mul * (f[n][i][k][0] + f[n][i][k][1]) % mod) % mod,         mul = (1ll * mul * 10 + 1) % mod;     write(ans);   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 100;   int a[N];   int per[N];   int main() {     int n;     cin >> n;     for (int i = 0; i < n - 1; i++) {       scanf( %d , &a[i]);     }     int ls = a[0];     set<int> st;     for (int i = 1; i <= n; i++) {       st.insert(i);     }     for (int i = 0; i < n - 1; i++) {       if (per[a[i]]) {         ls = *(--st.end());         st.erase(--st.end());         per[ls] = a[i];       } else {         st.erase(a[i]);         per[a[i]] = per[ls];         per[ls] = a[i];         if (i == 0) i--;       }     }     printf( %d n , a[0]);     for (int i = 1; i <= n; i++) {       if (per[i] == i) continue;       printf( %d %d n , i, per[i]);     }     return 0;   }


#include <bits/stdc++.h>   int a, b, c;   long long int MOD;   long long int Comb[110][110];   long long int comb(int a, int b) {     if (a == b) return 1;     if (b == 0) return 1;     if (Comb[a][b] != -1) return Comb[a][b];     return Comb[a][b] = (comb(a - 1, b - 1) + comb(a - 1, b)) % MOD;   }   int check[110][110];   std::vector<long long int> ans[110][110];   void func(int k, int h) {     if (check[k][h]) return;     if (k == 0) {       ans[k][h].push_back(1 % MOD);       check[k][h] = 1;       return;     }     int start = 0;     if (h == b) start++;     for (int i = 0; i <= k - 1; i++) {       func(i, h + 1);       func(k - i - 1, h + 1);       while (ans[k][h].size() <=              start + ans[i][h + 1].size() + ans[k - i - 1][h + 1].size() - 2)         ans[k][h].push_back(0);       for (int j1 = 0; j1 < ans[i][h + 1].size(); j1++) {         for (int j2 = 0; j2 < ans[k - i - 1][h + 1].size(); j2++) {           long long int t = ans[i][h + 1][j1] * ans[k - i - 1][h + 1][j2];           t %= MOD;           t *= comb(k - 1, i), t %= MOD;           ans[k][h][start + j1 + j2] += t, ans[k][h][start + j1 + j2] %= MOD;         }       }     }     check[k][h] = 1;   }   int main() {     scanf( %d%d%d%lld , &a, &b, &c, &MOD);     for (int i = 0; i <= a; i++)       for (int j = 0; j <= a; j++) Comb[i][j] = -1;     func(a, 1);     if (ans[a][1].size() >= c + 1)       printf( %lld , ans[a][1][c] % MOD);     else       printf( 0 );   }


#include <bits/stdc++.h>   const long long INF = 2 * 1e9;   const long long MOD = 1000000007;   using namespace std;   void solve() {     long long n, k, m;     cin >> n >> k >> m;     vector<long long> a(n);     vector<pair<long long, long long> > c;     long long x;     cin >> x;     c.push_back({x, 1});     long long cnt = 0;     for (long long i = 1; i < n; i++) {       long long x;       cin >> x;       if (c.size() == 0) {         c.push_back({x, 1});         continue;       }       if (x == c.back().first) {         c[(long long)(c).size() - 1].second++;         cnt += c[(long long)(c).size() - 1].second / k * k;         c[(long long)(c).size() - 1].second %= k;         if (c[(long long)(c).size() - 1].second == 0) c.pop_back();       } else {         c.push_back({x, 1});       }     }     if ((long long)(c).size() == 0) {       cout << 0 <<   n ;       return;     }     long long i = 0, j = (long long)(c).size() - 1;     auto tmp = c;     long long cnt1 = 0;     while (1) {       if (tmp[i].first == tmp[j].first) {         if (i == j) break;         cnt1 += (tmp[i].second + tmp[j].second) / k * k;         if ((tmp[i].second + tmp[j].second) % k == 0) {           i++;           j--;         } else           break;       } else {         break;       }     }     long long ans = 0;     if (i == j && tmp[i].first == tmp[j].first) {       long long cur = tmp[i].second * m;       long long cnt2 = (cur / k) * k;       cur %= k;       ans += cnt * m + cnt1 * (m - 1) + cnt2;       if (cur == 0) {         i--;         j++;         while (i >= 0 && j < tmp.size()) {           if (tmp[i].first == tmp[j].first) {             ans += (tmp[i].second + tmp[j].second) / k * k;             if ((tmp[i].second + tmp[j].second) % k == 0) {               i--;               j++;             } else               break;           } else             break;         }       }     } else {       ans += cnt * m + (cnt1) * (m - 1);     }     cout << n * m - ans <<   n ;   }   signed main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cout.fixed;     cout.precision(12);     solve();     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   template <typename _T>   inline void read(_T &f) {     f = 0;     _T fu = 1;     char c = getchar();     while (c <  0  || c >  9 ) {       if (c ==  - ) {         fu = -1;       }       c = getchar();     }     while (c >=  0  && c <=  9 ) {       f = (f << 3) + (f << 1) + (c & 15);       c = getchar();     }     f *= fu;   }   template <typename T>   void print(T x) {     if (x < 0) putchar( - ), x = -x;     if (x < 10)       putchar(x + 48);     else       print(x / 10), putchar(x % 10 + 48);   }   template <typename T>   void print(T x, char t) {     print(x);     putchar(t);   }   const int md = 998244353;   inline int add(int x, int y) {     x += y;     if (x >= md) x -= md;     return x;   }   inline int sub(int x, int y) {     x -= y;     if (x < 0) x += md;     return x;   }   inline int mul(int x, int y) { return 1ll * x * y % md; }   inline int fpow(int x, int y) {     int ans = 1;     while (y) {       if (y & 1) ans = mul(ans, x);       y >>= 1;       x = mul(x, x);     }     return ans;   }   namespace Poly {   vector<int> rev, roots, one(1, 1);   vector<int> operator+(vector<int> a, vector<int> b) {     int n = max((int)a.size(), (int)b.size());     a.resize(n);     b.resize(n);     for (int i = 0; i < n; i++) {       a[i] = add(a[i], b[i]);     }     return a;   }   vector<int> operator-(vector<int> a, vector<int> b) {     int n = max((int)a.size(), (int)b.size());     a.resize(n);     b.resize(n);     for (int i = 0; i < n; i++) {       a[i] = sub(a[i], b[i]);     }     return a;   }   void getRevRoot(int base) {     int n = 1 << base;     rev.resize(n);     roots.resize(n);     for (int i = 1; i < n; i++)       rev[i] = (rev[i >> 1] >> 1) | ((i & 1) << (base - 1));     for (int mid = 1; mid < n; mid <<= 1) {       int wn = fpow(3, (md - 1) / (mid << 1));       roots[mid] = 1;       for (int i = 1; i < mid; i++) roots[mid + i] = mul(roots[mid + i - 1], wn);     }   }   void ntt(vector<int> &a, int base) {     int n = 1 << base;     for (int i = 0; i < n; i++)       if (i < rev[i]) swap(a[i], a[rev[i]]);     for (int mid = 1; mid < n; mid <<= 1) {       for (int i = 0; i < n; i += (mid << 1)) {         for (int j = 0; j < mid; j++) {           int x = a[i + j], y = mul(a[i + j + mid], roots[mid + j]);           a[i + j] = add(x, y);           a[i + j + mid] = sub(x, y);         }       }     }   }   vector<int> operator*(vector<int> a, vector<int> b) {     int base = 0, n = (int)a.size() + (int)b.size() - 1;     while ((1 << base) < n) ++base;     a.resize(1 << base);     b.resize(1 << base);     getRevRoot(base);     ntt(a, base);     ntt(b, base);     for (int i = 0; i < (1 << base); i++) a[i] = mul(a[i], b[i]);     reverse(a.begin() + 1, a.end());     ntt(a, base);     a.resize(n);     int inv = fpow(1 << base, md - 2);     for (int i = 0; i < n; i++) {       a[i] = mul(a[i], inv);     }     return a;   }   }  // namespace Poly   using Poly::operator*;   const int N = 1e5 + 5;   vector<int> f, g, tmp;   int fac[N], inv[N];   int n;   long long m;   int main() {     read(n);     read(m);     f.resize(n + 1);     tmp.resize(n + 1);     fac[0] = 1;     for (int i = 1; i <= n; i++) fac[i] = mul(fac[i - 1], i);     inv[n] = fpow(fac[n], md - 2);     for (int i = n; i >= 1; i--) inv[i - 1] = mul(inv[i], i);     for (int i = 0; i <= n; i++) read(f[i]), tmp[i] = inv[i];     for (int i = 0; i <= n; i++) f[i] = mul(f[i], fac[i]);     reverse(f.begin(), f.end());     g = f * tmp;     g.resize(n + 1);     reverse(g.begin(), g.end());     for (int i = 0; i <= n; i++)       g[i] = mul(mul(g[i], inv[i]), fpow(fpow(i + 1, m % (md - 1)), md - 2));     for (int i = 1; i <= n; i += 2) tmp[i] = md - tmp[i];     for (int i = 0; i <= n; i++) g[i] = mul(g[i], fac[i]);     reverse(g.begin(), g.end());     f = g * tmp;     f.resize(n + 1);     reverse(f.begin(), f.end());     for (int i = 0; i <= n; i++)       f[i] = mul(f[i], inv[i]), print(f[i], i == n ?   n  :    );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     map<int, int> m;     cin >> n;     int a[n];     for (int i = 0; i < n; i++) {       cin >> a[i];       m[a[i]]++;     }     int chek[32];     chek[0] = 2;     for (int i = 1; i < 32; i++) {       chek[i] = chek[i - 1] * 2;     }     int sm = 0, coun = 0;     for (int i = 0; i < n; i++) {       for (int j = 0; j < 32; j++) {         int h = chek[j] - a[i];         if (m.find(h) != m.end()) {           if (h == a[i] && m[a[i]] > 1) {             coun++;             break;           }           if (h != a[i]) {             coun++;             break;           }         }       }     }     cout << n - coun << endl;     return 0;   }


#include <bits/stdc++.h>   #define testCase int T; cin>>T; while(T--)   #define int long long   #define Endl endl      using namespace std;      /*    */   const int N = 1e5+13, LMAX  = 3e18 + 13, IMAX = 1e9 + 5, mod  = 1e9 + 7; //998244353;      int32_t main() {       ios_base::sync_with_stdio(false);       cin.tie(nullptr);          testCase {           int mn = 101;           int n, x;           cin >> n;           for (int i = 0; i < n; ++i) {               cin >> x;               mn = min(mn, x);           }           if (mn < 0) cout <<  NO n ;           else {               cout <<  YES n ;               cout <<  101 n ;               for (int i = 0; i <=100; ++i) {                   cout << i <<    ;               }cout <<   n ;           }       }       return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, k, a[300001], seti = 0, l, r, z = 0, maxi = 0, fz, lt = -1,                                rt = -1;     cin >> n >> k;     for (long long i = 0; i < n; i++) cin >> a[i];     l = 0;     for (long long i = 0; i < n; i++) {       if (a[i] == 0) {         z++;         if (z == k + 1) {           r = i - 1;           if (r - l + 1 > maxi) {             maxi = r - l + 1;             lt = l;             rt = r;           }           z--;           if (a[l] == 0) {             l++;           } else {             for (long long j = l + 1; j < n; j++) {               if (a[j] == 0) {                 l = j + 1;                 break;               }             }           }         }       }     }     if (n - l > maxi) {       lt = l;       rt = n - 1;       maxi = n - l;     }     cout << maxi << endl;     if (lt != -1)       for (long long i = lt; i <= rt; i++) a[i] = 1;     for (long long i = 0; i < n; i++) cout << a[i] <<    ;   }


#include <bits/stdc++.h>   using namespace std;   template <typename Arg1>   void __f(const char* name, Arg1&& arg1) {     cout << name <<   :   << arg1 <<   n ;   }   template <typename Arg1, typename... Args>   void __f(const char* names, Arg1&& arg1, Args&&... args) {     const char* comma = strchr(names + 1,  , );     cout.write(names, comma - names) <<   :   << arg1 <<   |  ;     __f(comma + 1, args...);   }   inline int sbt(int x) { return __builtin_popcount(x); }   inline long long gl(long long a, long long b) { return (b - a + 1); }   inline long long mul(long long a, long long b,                        long long m = (long long)(1e9 + 7)) {     return ((a % m) * (b % m)) % m;   }   inline long long add(long long a, long long b,                        long long m = (long long)(1e9 + 7)) {     return (a + b) % m;   }   inline long long sub(long long a, long long b,                        long long m = (long long)(1e9 + 7)) {     return (a - b + m) % m;   }   long long fastpow(long long a, long long b) {     long long res = 1;     while (b > 0) {       if (b & 1) res = mul(res, a);       a = mul(a, a);       b >>= 1;     }     return res;   }   long long modinv(long long a) { return fastpow(a, (long long)(1e9 + 7) - 2); }   void get_ac() {     long long n, k;     cin >> n >> k;     string s;     cin >> s;     vector<vector<long long>> v;     bool f;     long long mink = 0, maxk = 0;     while (1) {       f = 0;       vector<long long> va;       for (int i = 0; i < n - 1; i++) {         if (s[i] ==  R  && s[i + 1] ==  L ) {           swap(s[i], s[i + 1]);           f = 1;           va.push_back(i);           i++;         }       }       if (!f) break;       v.push_back(va);       maxk += (long long)(va.size());       mink++;     }     if (k < mink || k > maxk) {       cout << -1;       return;     }     long long i = 0, j = 0;     while (k > mink - i) {       cout << 1 <<     << v[i][j] + 1;       cout <<   n ;       j++;       if (j == (long long)(v[i].size())) {         i++;         j = 0;       }       k--;     }     for (int l = i; l < mink; l++) {       cout << ((long long)(v[l].size()) - j) <<    ;       for (int m = j; m < (long long)(v[l].size()); m++) {         cout << v[l][m] + 1 <<    ;       }       j = 0;       cout <<   n ;     }   }   int main() {     cin.sync_with_stdio(false);     cout.sync_with_stdio(false);     cin.tie(NULL);     { get_ac(); }     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   using namespace std;   struct Point {     int x;     int y;   };   int direction(Point a, Point b, Point c) {     return (c.x - a.x) * (b.y - a.y) - (c.y - a.y) * (b.x - a.x);   }   bool onsegment(Point a, Point b, Point c) {     return (min(a.x, b.x) <= c.x && max(a.x, b.x) >= c.x &&             min(a.y, b.y) <= c.y && max(a.y, b.y) >= c.y);   }   bool intersects(Point a, Point b, Point c, Point d) {     int d1 = direction(c, d, a), d2 = direction(c, d, b), d3 = direction(a, b, c),         d4 = direction(a, b, d);     if (d1 * d2 < 0 && d3 * d4 < 0) {       return true;     } else if (d1 == 0 && onsegment(c, d, a)) {       return true;     } else if (d2 == 0 && onsegment(c, d, b)) {       return true;     } else if (d3 == 0 && onsegment(a, b, c)) {       return true;     } else if (d4 == 0 && onsegment(a, b, d)) {       return true;     } else {       return false;     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     Point a[5], b[5];     for (int i = 0; i < 4; i++) {       int x, y;       cin >> x >> y;       a[i] = {x, y};     }     a[4] = a[0];     for (int i = 0; i < 4; i++) {       int x, y;       cin >> x >> y;       b[i] = {x, y};     }     b[4] = b[0];     for (int i = 0; i < 4; i++) {       if (intersects(b[i], b[i + 1], a[0], a[2]) ||           intersects(b[i], b[i + 1], a[1], a[3])) {         return cout <<  YES n , 0;       }     }     for (int i = 0; i < 4; i++) {       if (b[i].x >= min(min(a[0].x, a[1].x), min(a[2].x, a[3].x)) &&           b[i].x <= max(max(a[0].x, a[1].x), max(a[2].x, a[3].x)) &&           b[i].y >= min(min(a[0].y, a[1].y), min(a[2].y, a[3].y)) &&           b[i].y <= max(max(a[0].y, a[1].y), max(a[2].y, a[3].y))) {         return cout <<  YES n , 0;       }     }     for (int i = 0; i < 5; i++) {       a[i] = {a[i].x - a[i].y, a[i].x + a[i].y};       b[i] = {b[i].x - b[i].y, b[i].x + b[i].y};     }     for (int i = 0; i < 4; i++) {       if (a[i].x >= min(min(b[0].x, b[1].x), min(b[2].x, b[3].x)) &&           a[i].x <= max(max(b[0].x, b[1].x), max(b[2].x, b[3].x)) &&           a[i].y >= min(min(b[0].y, b[1].y), min(b[2].y, b[3].y)) &&           a[i].y <= max(max(b[0].y, b[1].y), max(b[2].y, b[3].y))) {         return cout <<  YES n , 0;       }     }     return cout <<  NO n , 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     vector<int> a;     while (n) {       int x = n, p = 1, m = 0;       while (x) {         if (x % 10) m += p;         x /= 10;         p *= 10;       }       n -= m;       a.push_back(m);     }     cout << a.size() << endl;     for (int &i : a) cout << i <<    ;   }


#include <bits/stdc++.h>   int main() {     long long n;     scanf( %lld , &n);     long long a[1000005] = {0};     for (int i = 1; i <= n; i++) {       scanf( %lld , &a[i]);     }     long long ans = 0;     for (int i = 1; i <= n; i++) {       ans = ans + a[i] * i - (i - 1);     }     printf( %lld , ans);     return 0;   }


#include <bits/stdc++.h>   using lint = long long;   using ld = long double;   template <class T>   using numr = std::numeric_limits<T>;   struct input_t {     template <class T>     operator T() {       T t;       std::cin >> t;       return t;     }   } input;   namespace ns {   using namespace std;   template <int mod>   struct NumberTheoreticTransform {     vector<int> rev, rts;     int base, max_base, root;     NumberTheoreticTransform() : base(1), rev{0, 1}, rts{0, 1} {       assert(mod >= 3 && mod % 2 == 1);       auto tmp = mod - 1;       max_base = 0;       while (tmp % 2 == 0) tmp >>= 1, max_base++;       root = 2;       while (mod_pow(root, (mod - 1) >> 1) == 1) ++root;       assert(mod_pow(root, mod - 1) == 1);       root = mod_pow(root, (mod - 1) >> max_base);     }     inline int mod_pow(int x, int n) {       int ret = 1;       while (n > 0) {         if (n & 1) ret = mul(ret, x);         x = mul(x, x);         n >>= 1;       }       return ret;     }     inline int inverse(int x) { return mod_pow(x, mod - 2); }     inline unsigned add(unsigned x, unsigned y) {       x += y;       if (x >= mod) x -= mod;       return x;     }     inline unsigned mul(unsigned a, unsigned b) {       return 1ull * a * b % (unsigned long long)mod;     }     void ensure_base(int nbase) {       if (nbase <= base) return;       rev.resize(1 << nbase);       rts.resize(1 << nbase);       for (int i = 0; i < (1 << nbase); i++) {         rev[i] = (rev[i >> 1] >> 1) + ((i & 1) << (nbase - 1));       }       assert(nbase <= max_base);       while (base < nbase) {         int z = mod_pow(root, 1 << (max_base - 1 - base));         for (int i = 1 << (base - 1); i < (1 << base); i++) {           rts[i << 1] = rts[i];           rts[(i << 1) + 1] = mul(rts[i], z);         }         ++base;       }     }     void ntt(vector<int> &a) {       const int n = (int)a.size();       assert((n & (n - 1)) == 0);       int zeros = __builtin_ctz(n);       ensure_base(zeros);       int shift = base - zeros;       for (int i = 0; i < n; i++) {         if (i < (rev[i] >> shift)) {           swap(a[i], a[rev[i] >> shift]);         }       }       for (int k = 1; k < n; k <<= 1) {         for (int i = 0; i < n; i += 2 * k) {           for (int j = 0; j < k; j++) {             int z = mul(a[i + j + k], rts[j + k]);             a[i + j + k] = add(a[i + j], mod - z);             a[i + j] = add(a[i + j], z);           }         }       }     }     vector<int> multiply(vector<int> a, vector<int> b) {       int need = a.size() + b.size() - 1;       int nbase = 1;       while ((1 << nbase) < need) nbase++;       ensure_base(nbase);       int sz = 1 << nbase;       a.resize(sz, 0);       b.resize(sz, 0);       ntt(a);       ntt(b);       int inv_sz = inverse(sz);       for (int i = 0; i < sz; i++) {         a[i] = mul(a[i], mul(b[i], inv_sz));       }       reverse(a.begin() + 1, a.end());       ntt(a);       a.resize(need);       return a;     }   };   }  // namespace ns   constexpr int mod = 998244353;   lint inverse(lint x) {     assert(x % mod);     lint y = 1, u = mod, v = 0;     while (x) {       lint q = u / x;       u -= q * x;       std::swap(u, x);       v -= q * y;       std::swap(v, y);     }     assert(x == 0 && std::abs(u) == 1 && std::abs(y) == mod && std::abs(v) < mod);     return v < 0 ? v + mod : v;   }   lint normalized(lint x) {     if (x <= -mod || mod <= x) x %= mod;     if (x < 0) x += mod;     return x;   }   struct mint {     lint value;     mint() = default;     mint(lint x) : value(normalized(x)) {}   };   std::ostream &operator<<(std::ostream &os, mint x) { return os << x.value; }   mint operator+(mint x, mint y) {     lint z = x.value + y.value;     if (mod <= z) z -= mod;     return mint{z};   }   mint operator-(mint x, mint y) {     lint z = x.value - y.value;     if (z < 0) z += mod;     return mint{z};   }   mint operator*(mint x, mint y) { return mint{x.value * y.value % mod}; }   mint operator/(mint x, mint y) {     return mint{x.value * inverse(y.value) % mod};   }   mint &operator+=(mint &x, mint y) { return x = x + y; }   mint &operator-=(mint &x, mint y) { return x = x - y; }   mint &operator*=(mint &x, mint y) { return x = x * y; }   mint &operator/=(mint &x, mint y) { return x = x / y; }   bool operator==(mint x, mint y) { return x.value == y.value; }   bool operator!=(mint x, mint y) { return x.value != y.value; }   mint power(mint x, lint y) {     mint z = 1;     for (; y; y >>= 1) {       if (y & 1) z *= x;       x *= x;     }     return z;   }   int main() {     std::cin.tie(nullptr);     std::ios_base::sync_with_stdio(false);     std::cout.setf(std::ios_base::fixed);     std::cout.precision(15);     lint n = (lint)input / 2, k = input;     std::vector<int> a(10);     while (k--) {       int x = input;       a.at(x) = 1;     }     while (!a.back()) a.pop_back();     ns::NumberTheoreticTransform<mod> ntt;     std::vector<int> b = {1};     for (; n; n >>= 1) {       if (n & 1ll) b = ntt.multiply(a, b);       a = ntt.multiply(a, a);     }     std::vector<mint> c(b.size());     std::transform(std::begin(b), std::end(b), c.begin(),                    [](int x) { return x; });     std::cout << std::accumulate(std::begin(c), std::end(c), mint{0},                                  [](mint acc, mint x) { return acc + x * x; })               <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 500;   const int inf = 1e9 + 5;   struct node {     int l, r;   } b[N];   bool cmp(node a, node b) { return a.l < b.l; }   bool rcmp(node a, node b) { return a.r > b.r; }   int n, m, a[N], cnt, rt, ls[N * 32], rs[N * 32], sz[N * 32], vl[N * 32], Big[N],       Small[N], flag, b1[N], b2[N];   bool tag[N * 32];   void add(int &x, int l, int r, int pos) {     if (!x) x = ++cnt;     sz[x]++;     vl[x]++;     if (l == r) return;     int mi = (l + r) >> 1;     if (pos <= mi)       add(ls[x], l, mi, pos);     else       add(rs[x], mi + 1, r, pos);   }   void Pd(int x) {     if (x) tag[x] ^= 1, vl[x] = sz[x] - vl[x];   }   void pd(int x) {     if (tag[x]) Pd(ls[x]), Pd(rs[x]), tag[x] = 0;   }   void modify(int x, int l, int r, int pos) {     if (!x) return;     if (r <= pos) {       Pd(x);       return;     }     int mi = (l + r) >> 1;     pd(x);     modify(ls[x], l, mi, pos);     if (mi < pos) modify(rs[x], mi + 1, r, pos);     vl[x] = vl[ls[x]] + vl[rs[x]];   }   int ask(int x, int l, int r, int pos) {     if (!x) return 0;     if (l >= pos) return vl[x];     int mi = (l + r) >> 1, ans = 0;     pd(x);     if (pos <= mi) ans += ask(ls[x], l, mi, pos);     ans += ask(rs[x], mi + 1, r, pos);     return ans;   }   void modifyy(int x, int l, int r, int pos) {     if (!x) return;     if (l >= pos) {       Pd(x);       return;     }     int mi = (l + r) >> 1;     pd(x);     if (pos <= mi) modifyy(ls[x], l, mi, pos);     modifyy(rs[x], mi + 1, r, pos);     vl[x] = vl[ls[x]] + vl[rs[x]];   }   int askk(int x, int l, int r, int pos) {     if (!x) return 0;     if (r <= pos) return vl[x];     int mi = (l + r) >> 1, ans = 0;     pd(x);     ans += askk(ls[x], l, mi, pos);     if (mi < pos) ans += askk(rs[x], mi + 1, r, pos);     return ans;   }   int main() {     scanf( %d%d , &n, &m);     long long ans = 1ll * n * (n - 1) / 2 * (n - 2) / 3;     long long spc = 0;     for (int i = 1; i <= n; i++) scanf( %d , a + i);     for (int i = 1; i <= m; i++) scanf( %d%d , &b[i].l, &b[i].r);     sort(b + 1, b + m + 1, cmp);     sort(a + 1, a + n + 1);     for (int i = 1, j = 1; i <= n; i = j) {       while (j <= n && a[i] == a[j]) ++j;       for (int k = i; k <= j - 1; k++) b1[k] = j - k - 1, b2[k] = k - i;       ans -= 1ll * (j - i) * (j - i - 1) / 2 * (j - i - 2) / 3;       spc += 1ll * (j - i) * (j - i - 1) / 2 * (n - j + i);     }     cnt = rt = 0;     for (int i = 1; i <= n; i++) add(rt, 0, inf, a[i]);     int j = 1;     for (int i = 1; i <= n; i++) {       while (j <= m && b[j].l <= a[i]) {         modify(rt, 0, inf, b[j].r), ++j;       }       int t = ask(rt, 0, inf, a[i] + 1);       Big[i] += t;       Small[i] += n - i - b1[i] - t;     }     cnt = rt = 0;     memset(sz, 0, sizeof(sz));     memset(vl, 0, sizeof(vl));     memset(ls, 0, sizeof(ls));     memset(rs, 0, sizeof(rs));     memset(tag, 0, sizeof(tag));     for (int i = 1; i <= n; i++) add(rt, 0, inf, a[i]);     sort(b + 1, b + m + 1, rcmp);     j = 1;     for (int i = n; i >= 1; i--) {       while (j <= m && b[j].r >= a[i]) modifyy(rt, 0, inf, b[j].l), ++j;       int t = askk(rt, 0, inf, a[i] - 1);       Small[i] += t;       Big[i] += i - 1 - b2[i] - t;     }     long long tmp = 0;     for (int i = 1; i <= n; i++) {       tmp += 1ll * Big[i] * (Big[i] - 1) / 2;       tmp += 1ll * Small[i] * (Small[i] - 1) / 2;     }     tmp = (tmp + spc) / 2;     printf( %I64d n , ans - tmp);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   typedef long long LL;   typedef pair<int, int> PII;   typedef pair<LL,LL> PLL;   const int INF = 0x3f3f3f3f, N = 1e5 + 10;   inline int lc(int u) {return u << 1;}   inline int rc(int u) {return u << 1 | 1;}   inline int lowbit(int x) {return x & (-x);}   int y[27] = {10010,11020,20011,21012,11011,21021,22022,12021,11011,12012,10120,11130,20121,21122,11121,21131,22132,12131,11121,12122,10221,11231,12113,20222,21223,11222};   char x[30000];   inline void solve() {       for (int i = 0; i < 26; i ++ ) {           if (x[y[i]] == 0) x[y[i]] = i +  a ;       }       int n; cin >> n;       for (int i = 1; i <= n; i ++ ) {           int res = 0;           for (int j = 0; j < 5; j ++ ) {               int tmp; cin >> tmp;               res = res * 10 + tmp;           }           cout << x[res];       }   }   int main() {   //    ios::sync_with_stdio(false), cin.tie(nullptr);   //    int t; cin >> t;   //    while (t -- )           solve();       return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 10;   int n, k, root, ans;   vector<int> g[N];   int dfs(int u, int f) {     if (g[u].size() == 1) return 0;     vector<int> d;     for (int v : g[u])       if (v != f) d.push_back(dfs(v, u) + 1);     sort(d.begin(), d.end());     int sz = d.size();     while (sz >= 2) {       if (d[sz - 1] + d[sz - 2] <= k) break;       ans++, sz--;       d.pop_back();     }     int ret = d.back();     d.clear();     return ret;   }   int main() {     scanf( %d %d , &n, &k);     for (int i = 1; i < n; i++) {       int u, v;       scanf( %d %d , &u, &v);       g[u].push_back(v);       g[v].push_back(u);     }     for (int i = 1; i <= n; i++)       if (g[i].size() > 1) {         root = i;         break;       }     dfs(root, -1);     printf( %d , ans + 1);     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast,no-stack-protector,unroll-loops )   #pragma GCC optimize( no-stack-protector,fast-math )   using namespace std;   const long long N = 1e6 + 100, OO = 724249387, T = (1 << 20) + 10,                   M = 998244353, P = 6151, SQ = 280, lg = 64;   long long n, m, k, num, ed, t;   vector<long long> v[N];   bool mark[N];   void dfs(long long x) {     mark[x] = 1;     num++;     for (auto u : v[x])       if (!mark[u]) dfs(u);   }   int32_t main() {     ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);     cin >> n >> m >> k;     for (long long i = 0; i < m; i++) {       long long x, y;       cin >> x >> y;       v[x].push_back(y);       v[y].push_back(x);     }     for (long long i = 1; i <= n; i++) {       if (!mark[i]) {         num = 0;         dfs(i);         ed += min(num, k);         t++;       }     }     ed /= 2;     if (k == 1) return cout << max((long long)0, t - 2), 0;     cout << max((long long)0, t - 1 - ed);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline int read() {     char ch = getchar();     int res = 0, flag = 1;     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) flag = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       res = res * 10 + ch -  0 ;       ch = getchar();     }     return res * flag;   }   int r, c, n, k, p[3005][3005], x, y, cnt[3005], nxt[3005], lst[3005], tmp[3005];   long long ans;   int main() {     r = read();     c = read();     n = read();     k = read();     for (register int i = 1; i <= n; ++i) {       x = read();       y = read();       p[x][++p[x][0]] = y;     }     for (register int i = 1; i <= r; ++i) sort(p[i] + 1, p[i] + p[i][0] + 1);     for (register int i = r; i; --i) {       int h = 1, t = 0, s = 0;       long long now = 0;       for (register int j = 1; j <= p[i][0]; ++j) ++cnt[p[i][j]];       while (1) {         while (t < c && s < k) {           ++t;           s += cnt[t];         }         if (s < k) break;         while (h <= t && s >= k) {           s -= cnt[h];           ++h;           now += c - t + 1;         }       }       nxt[0] = 1;       lst[c + 1] = c;       for (register int j = 1; j <= c; ++j) {         nxt[j] = j + 1;         lst[j] = j - 1;       }       for (register int j = 1; j <= c; ++j)         if (!cnt[j]) {           nxt[lst[j]] = nxt[j];           lst[nxt[j]] = lst[j];         }       memcpy(tmp, cnt, sizeof(cnt));       for (register int j = r; j >= i; --j) {         ans += now;         for (register int u = 1; u <= p[j][0]; ++u) {           h = t = p[j][u];           int s1 = tmp[h], s2 = 0;           while (nxt[t] <= c && s1 + s2 + tmp[nxt[t]] <= k) {             t = nxt[t];             s2 += tmp[t];           }           while (1) {             if (s1 + s2 == k) now -= (h - lst[h]) * (nxt[t] - t);             h = lst[h];             s1 += tmp[h];             if (!h || s1 > k) break;             while (s1 + s2 > k) {               s2 -= tmp[t];               t = lst[t];             }           }           --tmp[p[j][u]];           if (!tmp[p[j][u]]) {             nxt[lst[p[j][u]]] = nxt[p[j][u]];             lst[nxt[p[j][u]]] = lst[p[j][u]];           }         }       }     }     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = int(1e9 + 5);   const long long MAXL = long long(1e18 + 5);   const long long MOD = long long(1e9 + 7);   const long long MOD2 = long long(998244353);   void fastio() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     return;   }   void precision(int x) {     cout.setf(ios::fixed | ios::showpoint);     cout.precision(x);     return;   }   long long gcd(long long a, long long b) {     if (a > b) {       swap(a, b);     }     if (a == 0) {       return b;     }     if (a == b) {       return a;     }     return gcd(b % a, a);   }   long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }   bool is_prime(long long a) {     if (a == 1) {       return false;     }     long long i;     for (i = 2; i * i <= a; i++) {       if (a % i == 0) {         return false;       }     }     return true;   }   bool is_square(long long a) {     long long b = long long(sqrt(a));     return (b * b == a);   }   bool is_cube(long long a) {     long long b = long long(cbrt(a));     return (b * b * b == a);   }   int digit_sum(long long a) {     int sum = 0;     while (a) {       sum += int(a % 10);       a /= 10;     }     return sum;   }   long long binpow(long long a, int b) {     long long ans = 1;     while (b) {       if ((b & 1) == 1) {         ans *= a;       }       b >>= 1;       a *= a;     }     return ans;   }   long long binpow_by_mod(long long a, long long b, long long mod) {     long long ans = 1;     while (b) {       if ((b & 1) == 1) {         ans *= a;         ans %= mod;       }       b >>= 1;       a *= a;       a %= mod;     }     return ans;   }   long long factorial(int a) {     int i;     long long ans = 1;     for (i = 2; i <= a; i++) {       ans *= long long(i);     }     return ans;   }   long long factorial_by_mod(int a, long long mod) {     int i;     long long ans = 1;     for (i = 2; i <= a; i++) {       ans *= long long(i);       ans %= mod;     }     return ans;   }   const int N = 200005;   int a[N];   int n;   void solve() {     int i, j;     cin >> n;     for (i = 1; i <= n; i++) {       cin >> a[i];     }     sort(a + 1, a + n + 1);     for (i = 2; i <= (n / 2) + 1; i++) {       cout << a[i] <<     << a[1] << endl;     }     return;   }   void precalc() { return; }   int main() {     fastio();     precalc();     int tests = 1, tc;     cin >> tests;     for (tc = 1; tc <= tests; tc++) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 1e3 + 10;   long long n, m, ans, h[N][N];   char ar[N][N];   bool get(long long i, long long j) {     long long x = h[i][j];     i -= x;     if (i < 0) return 0;     if (h[i][j] != x) return 0;     i -= x;     if (i < 0) return 0;     return h[i][j] >= x;   }   bool ok(long long row, long long l, long long r) {     long long x = h[row][l];     if (ar[row][l] != ar[row][r]) return 0;     row -= x;     if (ar[row][l] != ar[row][r]) return 0;     row -= x;     return ar[row][l] == ar[row][r];   }   long long choose2(long long x) { return (x * (x - 1)) / 2; }   long long solve(vector<bool> &vec, long long row) {     assert(vec.size() == m);     long long res = 0;     for (long long i = 0; i < vec.size(); i++) {       if (!vec[i]) continue;       long long r = i + 1;       while (r < vec.size() && vec[r] && h[row][i] == h[row][r] && ok(row, i, r))         r++;       res += choose2(r - i + 1);       i = r - 1;     }     return res;   }   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> n >> m;     for (long long i = 0; i < n; i++)       for (long long j = 0; j < m; j++) cin >> ar[i][j];     for (long long j = 0; j < m; j++) h[0][j] = 1;     for (long long i = 1; i < n; i++)       for (long long j = 0; j < m; j++) {         if (ar[i][j] == ar[i - 1][j])           h[i][j] = h[i - 1][j] + 1;         else           h[i][j] = 1;       }     for (long long i = 0; i < n; i++) {       vector<bool> vec;       for (long long j = 0; j < m; j++) vec.push_back(get(i, j));       ans += solve(vec, i);     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   void solve(int test_case) {     int a, b;     cin >> a >> b;     cout << b % max(b / 2 + 1, a) <<   n ;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     int t;     cin >> t;     for (int test_case = 1; test_case <= t; ++test_case) {       solve(test_case);     }   }


#include <bits/stdc++.h>   using namespace std;   int a[1000001];   int mod = 1000000007;   int f(int x, int y) {     int res = 1;     long long xx = x;     while (y > 0) {       if (y % 2) res = (res * xx) % mod;       xx = (xx * xx) % mod;       y = y / 2;     }     return res;   }   int main() {     int t, p;     int n, ba;     int i, j;     scanf( %d , &t);     for (p = 1; p <= t; p++) {       scanf( %d%d , &n, &ba);       for (i = 1; i <= n; i++) scanf( %d , &a[i]);       if (ba == 1) {         printf( %d n , n % 2);         continue;       }       sort(a + 1, a + n + 1);       long long cur = 1;       for (i = n - 1; i >= 1; i--) {         if (a[i] == a[i + 1]) {           if (cur == 0)             cur++;           else             cur--;         } else {           if (cur == 0)             cur++;           else {             while (a[i + 1] > a[i] && cur < i) {               a[i + 1]--;               cur = cur * ba;             }             if (cur < i)               cur--;             else               break;           }         }       }       if (i == 0)         printf( %d n , (cur * f(ba, a[1])) % mod);       else {         int res = (cur * f(ba, a[i + 1])) % mod;         for (; i >= 1; i--) res = ((res - f(ba, a[i])) % mod + mod) % mod;         printf( %d n , res);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   char grid[101][101];   bool rw[101], cl[101];   int main() {     bool f, r = 0, c = 0;     int cnt;     scanf( %d , &n);     for (int i = 0; i < n; ++i) {       scanf( %s , grid[i]);       f = 1;       for (int j = 0; j < n; ++j) {         f &= (grid[i][j] ==  E );         if (grid[i][j] ==  . ) rw[i] = cl[j] = 1;       }       c |= f;     }     for (int j = 0; j < n; ++j) {       f = 1;       for (int i = 0; i < n; ++i) {         f &= (grid[i][j] ==  E );       }       r |= f;     }     if (r && c) {       printf( -1 n );     } else {       cnt = 0;       for (int i = 0; i < n; ++i) cnt += rw[i];       if (cnt == n) {         for (int i = 0; i < n; ++i) {           for (int j = 0; j < n; ++j) {             if (grid[i][j] ==  . ) {               printf( %d %d n , i + 1, j + 1);               break;             }           }         }       } else {         for (int j = 0; j < n; ++j) {           for (int i = 0; i < n; ++i) {             if (grid[i][j] ==  . ) {               printf( %d %d n , i + 1, j + 1);               break;             }           }         }       }     }     return 0;   }


#include <bits/stdc++.h>   int main() {     int n, k, a[4] = {2, 3, 4, 5}, x, min = 250;     scanf( %d %d , &n, &k);     if (n * 5 == k || n * 3 == k || n * 4 == k) {       printf( 0 );       return 0;     }     for (int i = n; i >= 0; i--) {       x = i * 5;       if (x > k) continue;       for (int j = n; j >= 0; j--) {         x = i * 5 + j * 4;         if (x > k) continue;         for (int z = n; z >= 0; z--) {           x = i * 5 + j * 4 + z * 3;           if (x > k) continue;           for (int l = 0; l <= n; l++) {             x = i * 5 + j * 4 + z * 3 + l * 2;             if (x > k) break;             if (x == k && l < min && (i + j + z + l == n)) min = l;           }         }       }     }     printf( %d , min);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool check(vector<vector<int>> &a, int n, int x) {     deque<pair<int, int>> q;     map<pair<int, int>, bool> was;     q.push_back({1, 1});     was[{1, 1}] = true;     int dx[] = {1, 0, -1, 0};     int dy[] = {0, 1, 0, -1};     while (!q.empty()) {       auto u = q.front();       q.pop_front();       for (int i = 0; i < 4; i++) {         int xx = u.first + dx[i];         int yy = u.second + dy[i];         if (xx == n && yy == n) return false;         if (a[xx][yy] == x && !was[{xx, yy}]) {           q.push_back({xx, yy});           was[{xx, yy}] = true;         }       }     }     return true;   }   void v(vector<vector<int>> &a, int n) {     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         cout << a[i][j];       }       cout << endl;     }   }   void solve() {     vector<vector<int>> a;     int n;     cin >> n;     a = vector<vector<int>>(n + 2, vector<int>(n + 2, 2));     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         char x;         cin >> x;         if (x !=  S  && x !=  F ) {           a[i][j] = x -  0 ;         }       }     }     vector<pair<int, int>> c = {         {n - 1, n - 1}, {n - 1, n}, {n, n - 1}, {n - 2, n}, {n, n - 2}};     if (check(a, n, 1) && check(a, n, 0)) {       cout << 0 << endl;       return;     }     for (int i = 0; i < c.size(); i++) {       a[c[i].first][c[i].second] = 1 - a[c[i].first][c[i].second];       if (check(a, n, 1) && check(a, n, 0)) {         cout << 1 <<   n ;         cout << c[i].first <<     << c[i].second << endl;         return;       }       a[c[i].first][c[i].second] = 1 - a[c[i].first][c[i].second];     }     for (int i = 0; i < c.size(); i++) {       for (int j = i + 1; j < c.size(); j++) {         a[c[i].first][c[i].second] = 1 - a[c[i].first][c[i].second];         a[c[j].first][c[j].second] = 1 - a[c[j].first][c[j].second];         if (check(a, n, 1) && check(a, n, 0)) {           cout << 2 <<   n ;           cout << c[i].first <<     << c[i].second << endl;           cout << c[j].first <<     << c[j].second << endl;           return;         }         a[c[i].first][c[i].second] = 1 - a[c[i].first][c[i].second];         a[c[j].first][c[j].second] = 1 - a[c[j].first][c[j].second];       }     }   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int t = 1;     cin >> t;     for (int i = 1; i <= t; i++) {       solve();     }   }


#include <bits/stdc++.h>   int main() {     int l, r, a, n;     scanf( %d %d %d , &l, &r, &a);     if (l > r) {       if (r + a < l) {         printf( %d n , 2 * (r + a));       } else {         n = r + a - l;         printf( %d n , 2 * (l + n / 2));       }     } else {       if (l + a < r) {         printf( %d n , 2 * (l + a));       } else {         n = l + a - r;         printf( %d n , 2 * (r + n / 2));       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 200010;   pair<int, int> bug[N];   pair<int, pair<int, int> > stud[N];   set<pair<int, int> > smart;   int ans[N];   int studs, bugs, exams;   long long solve(int days) {     long long sum = 0;     smart.clear();     int last = 0;     for (int i = 0; i < bugs; i += days) {       while (last < studs && stud[last].first >= bug[i].first) {         smart.insert(stud[last].second);         last++;       }       if (smart.empty()) {         return (long long)1e18;       }       pair<int, int> t = *(smart.begin());       smart.erase(smart.begin());       sum += t.first;       for (int j = i; j < bugs && j < i + days; j++) {         ans[bug[j].second] = t.second;       }     }     return sum;   }   int main() {     scanf( %d%d%d , &studs, &bugs, &exams);     for (int i = 0; i < bugs; i++) {       scanf( %d , &(bug[i].first));       bug[i].second = i;     }     for (int i = 0; i < studs; i++) {       scanf( %d , &(stud[i].first));     }     for (int i = 0; i < studs; i++) {       scanf( %d , &(stud[i].second.first));       stud[i].second.second = i;     }     sort(bug, bug + bugs);     reverse(bug, bug + bugs);     sort(stud, stud + studs);     reverse(stud, stud + studs);     int ll = 1, rr = bugs + 1;     while (ll < rr) {       int mid = (ll + rr) >> 1;       if (solve(mid) <= exams)         rr = mid;       else         ll = mid + 1;     }     if (ll > bugs) {       cout <<  NO n ;       return 0;     }     solve(ll);     printf( YES n );     for (int i = 0; i < bugs; i++) {       printf( %d  , ans[i] + 1);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     double a, b, mn = 1e12;     cin >> a >> b;     int n;     cin >> n;     while (n--) {       double x, y, v, dis;       cin >> x >> y >> v;       dis = sqrt((a - x) * (a - x) + (b - y) * (b - y));       dis /= v;       mn = min(mn, dis);     }     cout << fixed << setprecision(7) << mn << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double PI = acos(-1.0);   const int N = 1e6 + 5;   int f[N];   int a[] = {1, 2};   int na = 2;   int main() {     int cnt;     cin >> cnt;     if (cnt == 1) {       cout <<  1 1 n1 ;       return 0;     }     int x = 1;     for (int i = 2; i < N; i++) {       if (i % 2 == 0) x++;       if (x == cnt) {         cout << i <<   2 n1 2 ;         return 0;       }     }     return 0;   }


#include <cstdio>   #include <cmath>   long long T, n;   bool flag;   int main()   {    scanf( %d , &T);    for(int t = 1; t <= T; t ++)    {     scanf( %lld , &n);     flag = false;     for(long long i = 2; i <= n; i *= 2)     {      if(n == i)       {       printf( NO n );       flag = true;       break;      }     }     if(!flag) printf( YES n );    }    return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 3020;   long long a[maxn], b[maxn];   long long dp1[maxn][maxn];   int n;   bool cmp(int x, int y) { return x > y; }   int main() {     while (cin >> n) {       for (int i = 0; i < n; i++) cin >> a[i];       for (int i = 0; i < n; i++) {         a[i] -= i;         b[i] = a[i];       }       sort(b, b + n);       memset(dp1, 0, sizeof(dp1));       for (int i = 0; i < n; i++) {         long long minx = dp1[i][0];         for (int j = 0; j < n; j++) {           minx = min(minx, dp1[i][j]);           dp1[i + 1][j] = minx + abs(a[i] - b[j]);         }       }       long long min_up = dp1[n][0];       for (int i = 1; i < n; i++) {         min_up = min(min_up, dp1[n][i]);       }       cout << min_up << endl;     }     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( O2,unroll-loops )   using namespace std;   const int inf = 1000000010;   const long long INF = 1000000000000001000LL;   const int mod = 1000000007;   const int MAXN = 100200, SQ = 320, NSQ = MAXN / SQ + 1;   int n, m, w, u, v, x, y, t, a, b, maxb;   int A[MAXN], B[MAXN], ans[MAXN], lazy[NSQ];   pair<long long, long long> X[MAXN];   vector<int> vec[MAXN];   struct CHT {     pair<long long, int> cht[SQ];     int L, R;     inline long long Inter(pair<long long, long long> x,                            pair<long long, long long> y) {       if (x.first == y.first) return (x <= y ? -INF : INF);       return (x.second - y.second) / (y.first - x.first) +              ((x.second - y.second) % (y.first - x.first) > 0);     }     inline void Add(int a) {       while (R && Inter(X[cht[R - 1].second], X[a]) <= cht[R - 1].first) R--;       if (!R)         cht[R++] = {-INF, a};       else         cht[R] = {Inter(X[cht[R - 1].second], X[a]), a}, R++;     }     inline pair<long long, long long> Get(long long x) {       while (L + 1 < R && cht[L + 1].first <= x) L++;       int i = cht[L].second;       return {X[i].first * x + X[i].second, i};     }   } cht[NSQ];   void Build(int id) {     int tl = id * SQ, tr = min(MAXN, tl + SQ);     cht[id].L = cht[id].R = 0;     for (int i = tl; i < tr; i++) {       X[i].second += lazy[id] * X[i].first;       cht[id].Add(i);     }     lazy[id] = 0;   }   void Add(int l, int r, int val) {     int idl = -1, idr = -1;     while (l < r && l % SQ) idl = l / SQ, X[l].second += val * l, l++;     while (l < r && r % SQ) idr = r / SQ, r--, X[r].second += val * r;     while (l < r) lazy[l / SQ] += val, l += SQ;     if (idl != -1) Build(idl);     if (idr != -1) Build(idr);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n >> w;     for (int i = 1; i <= n; i++) {       cin >> A[i] >> B[i];       vec[B[i]].push_back(i);       maxb = max(maxb, B[i]);     }     for (int i = 0; i < MAXN; i++) X[i].first = i;     for (int i = 0; i * SQ < MAXN; i++) Build(i);     int ted = n;     for (int i = 0; i <= maxb + 1; i++) {       pair<long long, long long> p = {-inf, -1};       for (int j = 0; j * SQ + SQ <= MAXN; j++) p = max(p, cht[j].Get(lazy[j]));       cout << p.first + 1ll * ted * i * w <<     << p.second <<   n ;       for (int j : vec[i]) Add(0, A[j] + 1, +1), ted--;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using namespace std::chrono;   long long mod = 1000000007;   void __print(int x) { cerr << x; }   void __print(long x) { cerr << x; }   void __print(long long x) { cerr << x; }   void __print(unsigned x) { cerr << x; }   void __print(unsigned long x) { cerr << x; }   void __print(unsigned long long x) { cerr << x; }   void __print(float x) { cerr << x; }   void __print(double x) { cerr << x; }   void __print(long double x) { cerr << x; }   void __print(char x) { cerr <<      << x <<     ; }   void __print(const char *x) { cerr <<     << x <<    ; }   void __print(const string &x) { cerr <<     << x <<    ; }   void __print(bool x) { cerr << (x ?  true  :  false ); }   template <typename T, typename V>   void __print(const pair<T, V> &x) {     cerr <<  { ;     __print(x.first);     cerr <<  , ;     __print(x.second);     cerr <<  } ;   }   template <typename T>   void __print(const T &x) {     int f = 0;     cerr <<  { ;     for (auto &i : x) cerr << (f++ ?  ,  :   ), __print(i);     cerr <<  } ;   }   void _print() { cerr <<  ] n ; }   template <typename T, typename... V>   void _print(T t, V... v) {     __print(t);     if (sizeof...(v)) cerr <<  ,  ;     _print(v...);   }   void init() {}   void solve() {     long long x, y, n, i, j;     cin >> n;     vector<pair<long long, long long> > adj(n - 1);     vector<long long> deg(n + 1, 0);     for (i = 0; i < n - 1; i++) {       cin >> x >> y;       deg[x]++;       deg[y]++;       adj[i] = {x, y};     }     vector<long long> edge;     for (i = 0; i < n + 1; i++) {       if (deg[i] == 1) {         edge.push_back(i);       }     }     if ((int)edge.size() == 2) {       for (i = 0; i < n - 1; i++) {         cout << i << endl;       }     } else {       long long ep = 0, elp = 3;       for (i = 0; i < n - 1; i++) {         bool flag = false;         for (j = 0; j < 3; j++) {           if (edge[j] == adj[i].first or edge[j] == adj[i].second) {             flag = true;           }         }         if (flag) {           cout << ep << endl;           ep++;         } else {           cout << elp << endl;           elp++;         }       }     }   }   int main() {     init();     auto start = high_resolution_clock::now();     int T = 1;     while (T--) {       solve();     }     auto stop = high_resolution_clock::now();     auto duration = duration_cast<milliseconds>(stop - start);   }


#include <bits/stdc++.h>   #define int long long   #define f(i,a,n) for (int i = a; i < n; ++i)   #define f1(i,a,n) for(int i=n-1;i>=a;i--)   #define ff first   #define ss second   #define pb push_back   #define mp make_pair   #define all(x) x.begin(), x.end()   #define sortall(x) sort(all(x))   #define fastio ios_base::sync_with_stdio(false), cin.tie(NULL);   #define w1 solve();   #define mod (int)(1e9 + 7)   #define prq priority_queue   #define gcd __gcd   #define sz(x) (int)x.size()   #define w(t) int t; cin>>t; while (t--) { solve(); }   #define N 1000001      using namespace std;      void __print(int x) {cerr << x;}   void __print(float x) {cerr << x;}   void __print(double x) {cerr << x;}   void __print(long double x) {cerr << x;}   void __print(char x) {cerr <<      << x <<     ;}   void __print(const char *x) {cerr <<     << x <<    ;}   void __print(const string &x) {cerr <<     << x <<    ;}   void __print(bool x) {cerr << (x ?  true  :  false );}      template<typename T, typename V>   void __print(const pair<T, V> &x) {cerr <<  { ; __print(x.first); cerr <<  , ; __print(x.second); cerr <<  } ;}   template<typename T>   void __print(const T &x) {int f = 0; cerr <<  { ; for (auto &i : x) cerr << (f++ ?  ,  :   ), __print(i); cerr <<  } ;}   void _print() {cerr <<  ] n ;}   template <typename T, typename... V>   void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr <<  ,  ; _print(v...);}      #ifdef Avash_Local_Machine   #define debug(x...) cerr <<  [  << #x <<  ] = [ ; _print(x)   #else   #define debug(x...)   #endif      typedef vector<int> vi;   typedef pair<int, int> pii;   typedef vector<pii> vpi;   typedef vector<string> vs;   typedef vector<char> vc;      const int INF = (int)(1e17);   const double PI = 3.141592653589793;      int dx[4] = { -1, 0, 1, 0};   int dy[4] = {0, 1, 0, -1};   string path =  URDL ;         void solve()   {    int q;    cin >> q;    char c; int n , id = 1;    set<pii> set1, set2;    //set1 for price,id    //set2 for id,price    while (q--)    {     cin >> c;     if (c ==  1 )     {      cin >> n;      set1.insert(mp(n, id));      set2.insert(mp(id, n));      ++id;     }     if (c ==  2 )     {      auto it = *set2.begin();      cout << it.ff <<   n ;      auto ind = set1.lower_bound(mp(it.ss, it.ff));      set1.erase(ind);      set2.erase(set2.begin());     }     if (c ==  3 )     {      auto it = *set1.rbegin();      // debug(it);      auto ind = set1.lower_bound(mp(it.ff, -INF));      // debug(ind);      cout << (*ind).ss <<   n ;      auto ind1 = set2.lower_bound(mp((*ind).ss, (*ind).ff));      // debug(*ind1);      set2.erase(ind1);      set1.erase(ind);      // debug(set2);     }    }   }      int32_t main()   {       fastio    w1    // w(t)    return 0;   }


#include <bits/stdc++.h>   using namespace std;   int tt;   int n, m;   int main() {     scanf( %d , &tt);     while (tt--) {       scanf( %d %d , &n, &m);       long long z = (n - m), g = m + 1;       long long k = z / g;       long long ans =           (n * 1ll * (n + 1) / 2) - (k * (k + 1) / 2) * g - (k + 1) * (z % g);       printf( %lld n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, F[500007], wartosc[500007], Fat[500007];   bool valid_number[500007], valid_edges[300007], query_node[500007];   int Find(int a) { return (a == Fat[a] ? a : Fat[a] = Find(Fat[a])); }   inline void Union(int a, int b) {     a = Find(a);     b = Find(b);     F[a] = F[b] = ++n;     Fat[a] = Fat[b] = F[n] = Fat[n] = n;   }   vector<int> G[500007];   int pre[500007], pos[500007], order[500007], nr;   bool visited[500007];   void DFS(int v) {     visited[v] = 1;     pre[v] = ++nr;     order[nr] = v;     for (auto i : G[v])       if (!visited[i]) DFS(i);     pos[v] = nr;   }   int tree[1 << 20], M = 1;   inline void zrob_drzewa() {     for (int i = 1; i <= n; i++)       if (F[i] != i) {         G[i].push_back(F[i]);         G[F[i]].push_back(i);       }     for (int i = 1; i <= n; i++)       if (F[i] == i) DFS(i);     while (M < n) M *= 2;     for (int i = 1; i <= n; i++) tree[i + M - 1] = wartosc[order[i]];     for (int i = M - 1; i > 0; i--) tree[i] = max(tree[i * 2], tree[i * 2 + 1]);   }   void remove_invalid(int v) {     if (valid_number[tree[v]]) return;     tree[v] = 0;     if (v >= M) return;     remove_invalid(v * 2);     remove_invalid(v * 2 + 1);     tree[v] = max(tree[v * 2], tree[v * 2 + 1]);   }   int maks(int a, int b, int v = 1, int p = 1, int k = M) {     if (p > b || k < a) return 0;     if (p >= a && k <= b) {       remove_invalid(v);       return tree[v];     }     return max(maks(a, b, v * 2, p, (p + k) / 2),                maks(a, b, v * 2 + 1, (p + k) / 2 + 1, k));   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int m, q;     cin >> n >> m >> q;     n = n;     for (int i = 1, a; i <= n; i++) {       cin >> wartosc[i];       valid_number[wartosc[i]] = true;       F[i] = i;       Fat[i] = i;     }     vector<pair<int, int>> edges(m + 1);     for (int i = 1; i <= m; i++) {       cin >> edges[i].first >> edges[i].second;       valid_edges[i] = true;     }     vector<pair<int, int>> queries(q);     for (int i = 0; i < q; i++) {       cin >> queries[i].first >> queries[i].second;       if (queries[i].first == 2) valid_edges[queries[i].second] = false;     }     for (int i = 1; i <= m; i++)       if (valid_edges[i]) Union(edges[i].first, edges[i].second);     int Res[q];     for (int i = q - 1; i >= 0; i--) {       if (queries[i].first == 1) {         int v = queries[i].second;         v = Find(v);         Res[i] = v;       } else {         int j = queries[i].second;         int a = edges[j].first, b = edges[j].second;         Union(a, b);       }     }     zrob_drzewa();     for (int i = 0; i < q; i++) {       if (queries[i].first == 2) continue;       int v = Res[i];       int res = maks(pre[v], pos[v]);       cout << res <<   n ;       valid_number[res] = false;       valid_number[0] = true;     }   }


#include <bits/stdc++.h>   using namespace std;   int N, Y[50001];   set<int> pos[50001];   set<int> used;   priority_queue<int> q;   int next(int x) {     int temp = x;     while (x != 0) {       if (used.count(x) == 0) return x;       x /= 2;     }     return temp;   }   int main() {     cin >> N;     for (int i = 0; i < N; i++) {       cin >> Y[i];       used.insert(Y[i]);       q.push(Y[i]);     }     for (;;) {       int num = next(q.top());       if (q.top() == num) break;       used.erase(num);       used.insert(num);       q.pop();       q.push(num);     }     while (!q.empty()) {       cout << q.top() <<    ;       q.pop();     }     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 3;   int a[maxn], b[maxn], c[maxn], sum;   int main() {     int n;     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> a[i];       sum += a[i];     }     int ans = 0, cnt = 0;     for (int i = 1; i <= n; i++) {       ans += a[i];       cnt -= a[i];       b[i] = max(max(cnt, ans), b[i - 1] + a[i]);     }     ans = 0, cnt = 0;     for (int i = n; i > 0; i--) {       ans += a[i];       cnt -= a[i];       c[i] = max(max(cnt, ans), c[i + 1] + a[i]);     }     int mx = 0;     for (int i = 0; i <= n; i++) mx = max(c[i + 1] + b[i], mx);     cout << mx;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, l, r, c, pl, pr, cl, cr;     cin >> a >> b >> l >> r;     c = a + b;     cl = --l / c;     cr = --r / c;     pl = l % c;     pr = r % c;     if (cl == cr) {       if (pl < a && pr < a) {         cout << pr - pl + 1 << endl;       } else if (pl < a && pr >= a) {         cout << a - pl << endl;       } else {         cout << 1 << endl;       }     } else if (a <= b) {       if (cl < cr - 1) {         cout << a + 1 << endl;       } else {         if (pr >= a) {           cout << a + 1 << endl;         } else {           if (pl >= a) {             cout << pr + 1 + 1 << endl;           } else {             int left = a - pl;             int right = pr + 1;             if (left + right > a) {               cout << a + (right == a) << endl;             } else {               cout << left + right + (right == a) << endl;             }           }         }       }     } else {       int d = a - b;       if (cl == cr - 1) {         if (pr >= a && pl >= a) {           cout << a + 1 << endl;         } else if (pr < a && pl >= a) {           cout << pr + 1 + 1 << endl;         } else if (pr >= a && pl < a) {           cout << min((a + a - pl), a + a - b) << endl;         } else if (pr < a && pl < a) {           if (pl > b) {             cout << pr + 1 + a - pl << endl;           } else {             cout << pr + 1 + a - b << endl;           }         }       } else if (cl == cr - 2) {         if (pr >= a && pl >= a) {           cout << a + a - b << endl;         } else if (pr >= a && pl < a) {           cout << a + a - b << endl;         } else if (pr < a && pl < a) {           cout << min((a + pr + 1 + a - pl + 1), a + a - b) << endl;         } else {           cout << a + max(1, d + min(0, pr - a + 1 + max(0, a - pl)));         }       } else {         cout << a + d << endl;       }     }   }


#include <bits/stdc++.h>   using namespace std;   int gcd(int x, int y) { return (!y ? x : gcd(y, x % y)); }   const int maxn = 2e5;   vector<int> g[maxn], tree[maxn];   map<pair<int, int>, int> we;   int par[maxn];   int gpar(int v) { return (par[v] == v ? v : par[v] = gpar(par[v])); }   bool mrg(int u, int v) {     u = gpar(u);     v = gpar(v);     if (u == v) return false;     par[v] = u;     return true;   }   int h[maxn];   void dfs(int v, int p) {     for (auto u : tree[v]) {       if (u == p) continue;       par[u] = v;       h[u] = h[v] + 1;       dfs(u, v);     }   }   vector<int> get_path(int u, int v) {     if (h[u] < h[v]) swap(u, v);     vector<int> p, rig;     while (h[u] > h[v]) {       p.push_back(u);       u = par[u];     }     while (u != v) {       p.push_back(u);       rig.push_back(v);       u = par[u], v = par[v];     }     p.push_back(u);     reverse(rig.begin(), rig.end());     for (auto i : rig) p.push_back(i);     return p;   }   const int maxb = 18;   int mods[2] = {int(1e9 + 7), int(1e9 + 9)};   int mod;   const int N = (1 << maxb);   int bpw(int a, int b) {     int ans = 1;     while (b) {       if (b & 1) ans = 1LL * ans * a % mod;       a = 1LL * a * a % mod;       b >>= 1;     }     return ans;   }   void fwht(int* a, int val) {     for (int len = 2; len <= N; len *= 2)       for (int i = 0; i < N; i += len) {         int nxt = len / 2;         for (int j = 0; j < nxt; j++) {           int x = a[i + j], y = a[i + j + nxt];           a[i + j] = (x + y) % mod;           a[i + j + nxt] = (x - y + mod) % mod;         }       }     if (val == -1) {       int inv = bpw(N, mod - 2);       for (int i = 0; i < N; i++) a[i] = 1LL * a[i] * inv % mod;     }   }   int ans[2][N], cnt[N];   int32_t main() {     ios::sync_with_stdio(0), cin.tie(0);     int n, m;     cin >> n >> m;     int tot = 0;     for (int i = 0; i < m; i++) {       int u, v, w;       cin >> u >> v >> w;       u--, v--;       g[u].push_back(v);       g[v].push_back(u);       we[{u, v}] = we[{v, u}] = w;       tot ^= w;     }     for (int i = 0; i < n; i++) par[i] = i;     vector<pair<int, int> > bads;     for (int i = 0; i < n; i++) {       for (auto j : g[i]) {         if (mrg(i, j)) {           tree[i].push_back(j);           tree[j].push_back(i);         } else if (i < j)           bads.push_back({i, j});       }     }     if (bads.size() == 0) {       cout << tot <<     << 1 <<   n ;       return 0;     }     dfs(0, 0);     for (int it = 0; it < 2; it++) {       mod = mods[it];       for (int i = 0; i < N; i++) ans[it][i] = 1;       for (auto t : bads) {         vector<int> p = get_path(t.first, t.second);         p.push_back(p[0]);         memset(cnt, 0, sizeof cnt);         for (int i = 0; i + 1 < p.size(); i++) {           int w = we[{p[i], p[i + 1]}];           cnt[w]++;         }         fwht(cnt, 1);         for (int i = 0; i < N; i++) ans[it][i] = 1LL * ans[it][i] * cnt[i] % mod;       }       fwht(ans[it], -1);     }     int jav = 1e9, who = -1;     for (int i = 0; i < N; i++)       if (ans[0][i] || ans[1][i]) {         if ((i ^ tot) < jav) {           jav = i ^ tot;           who = i;         }       }     assert(who != -1);     cout << jav <<     << ans[0][who] <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   long long bbuy(long long* c, long long l, int n);   int main() {     long long n, l;     cin >> n >> l;     long long c[n];     for (int i = 0; i < n; ++i) {       cin >> c[i];     }     long long bp = c[0];     for (int i = 0; i < n; ++i) {       bp *= 2;       bp = min(bp, c[i]);       if (bp != c[i]) c[i] = -1;     }     long long bcost = 0;     bcost += bbuy(c, l, n);     cout << bcost;     return 0;   }   long long bbuy(long long* c, long long l, int n) {     int i = int(log2(l));     long long gcost = 0;     long long cost = 0, buy;     long long prev = l;     while (i >= n || c[i] == -1) i--;     buy = l / pow(2, i);     l -= buy * pow(2, i);     cost = buy * c[i];     if (l > 0) cost += bbuy(c, l, n);     for (int j = i + 1; j < n; ++j) {       l = prev;       if (c[j] == -1) continue;       buy = (l / pow(2, j)) + 1;       if (cost > buy * c[j]) {         cost = buy * c[j];         l -= buy * pow(2, j);       }     }     gcost += cost;     return gcost;   }


#include <bits/stdc++.h>   using namespace std;   namespace std {   template <>   struct hash<pair<int, int>> {     size_t operator()(const pair<int, int> &x) const {       long long P = 38923, Q = 109797901;       return (size_t)((x.first * P + x.second) % Q);     }   };   };  // namespace std   template <class T>   using pqg = priority_queue<T, vector<T>, greater<T>>;   template <typename T>   void print(T t) {     cout << t << endl;   }   template <typename T, typename... Args>   void print(T t, Args... args) {     cout << t <<    ;     print(args...);   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     long long x, y, z;     cin >> x >> y >> z;     if (x > y + z)       print( + );     else if (y > x + z)       print( - );     else if (x == y && z == 0)       print( 0 );     else       print( ? );     return 0;   }