#include <bits/stdc++.h>   using namespace std;   struct node {     int left, right, size;   } t[600000];   int n;   int a[200005], b[200005], sa[200005], sb[200005], s[200005], ans[200005];   int readint() {     int x = 0, f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     return x * f;   }   void build(int id, int l, int r, int x) {     t[id].left = l, t[id].right = r;     if (l == r) return (void)(t[id].size = x);     int mid = (l + r) / 2;     build(id << 1, l, mid, x);     build(id << 1 | 1, mid + 1, r, x);     t[id].size = t[id << 1].size + t[id << 1 | 1].size;   }   int query(int id, int x) {     if (t[id].left == t[id].right) return t[id].size;     if (x <= t[id << 1].right)       return query(id << 1, x);     else       return query(id << 1 | 1, x) + t[id << 1].size;   }   void change(int id, int x, int c) {     if (t[id].left == t[id].right) return (void)(t[id].size = c);     if (x <= t[id << 1].right)       change(id << 1, x, c);     else       change(id << 1 | 1, x, c);     t[id].size = t[id << 1].size + t[id << 1 | 1].size;   }   int find(int id, int x) {     if (t[id].left == t[id].right) return t[id].left;     if (x <= t[id << 1].size)       return find(id << 1, x);     else       return find(id << 1 | 1, x - t[id << 1].size);   }   int main() {     n = readint();     for (int i = 1; i <= n; i++) a[i] = readint() + 1;     for (int i = 1; i <= n; i++) b[i] = readint() + 1;     build(1, 1, n, 0);     for (int i = n; i >= 1; i--) {       sa[i] = query(1, a[i]);       change(1, a[i], 1);     }     build(1, 1, n, 0);     for (int i = n; i >= 1; i--) {       sb[i] = query(1, b[i]);       change(1, b[i], 1);     }     for (int i = n; i >= 1; i--) {       s[i] += sa[i] + sb[i];       if (s[i] >= n - i + 1) s[i] -= n - i + 1, s[i - 1]++;     }     build(1, 1, n, 1);     for (int i = 1; i <= n; i++) {       ans[i] = find(1, s[i] + 1);       change(1, ans[i], 0);     }     for (int i = 1; i <= n; i++) printf( %d  , ans[i] - 1);     printf(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[1000100], g[1000100];   int main() {     for (int i = 1; i < 20; i++) {       int msk = (1 << i) - 1;       for (int j = (1 << i - 1); j < (1 << i); j++) {         g[j] = (1 << i - 1) | g[j ^ msk];       }     }     int n, x;     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %d , &a[i]);     }     for (int i = 19; i >= 0; i--) {       vector<int> v, piv;       for (int j = 0; j < n; j++) {         if (a[j] >= (1 << i)) continue;         int x = a[j];         for (int k = 0; k < v.size(); k++) {           if (x & (piv[k] & -piv[k])) x ^= piv[k];         }         if (x > 0) {           v.push_back(a[j]);           piv.push_back(x);         }       }       if (v.size() == i) {         printf( %d n , i);         for (int j = 0; j < (1 << i); j++) {           int x = 0;           for (int k = 0; k < i; k++) {             if (g[j] & (1 << k)) x ^= v[k];           }           printf( %d  , x);         }         puts(  );         break;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 4e5 + 10;   int n, a[MAX];   int f(int x) {     vector<int> v(n);     for (int i = 0; i < n; ++i) {       v[i] = (a[i] == -1 ? x : a[i]);     }     int ret = 0;     for (int i = 0; i < n - 1; ++i) {       ret = max(ret, abs(v[i] - v[i + 1]));     }     return ret;   }   void solve() {     cin >> n;     for (int i = 0; i < n; ++i) cin >> a[i];     long long beg = 0, end = 1e9;     while (end - beg > 3) {       long long mid1 = (2 * beg + end) / 3;       long long mid2 = (beg + 2 * end) / 3;       int f1 = f(mid1);       int f2 = f(mid2);       if (f1 > f2) {         beg = mid1 + 1;       } else if (f1 <= f2) {         end = mid2 - 1;       }     }     int ans = 1e9, ind;     for (int i = beg; i <= end; ++i) {       int t = f(i);       if (t < ans) {         ans = t;         ind = i;       }     }     cout << ans <<     << ind <<   n ;   }   int main() {     int q;     cin >> q;     while (q--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, k;     while (scanf( %d%d%d , &n, &m, &k) != EOF) {       if (n == m) {         if (n == 2 && k == 1) {           printf( 4 n );           printf( 1 2 3 4 n );         } else {           printf( %d n , 2 * k + 1);           printf( 1 );           for (int i = 1; i < k; i++) {             printf(  1 );           }           printf(  %d , n);           for (int i = 1; i < k; i++) {             printf(  %d , n + 1);           }           if (k == 1)             printf(  %d n , 2 * n - 1);           else             printf(  %d n , 2 * n);         }       } else if (m == n - 1) {         if (k > 1) {           printf( %d n , 2 * k);           printf( 1 );           for (int i = 1; i < k; i++) {             printf(  1 );           }           printf(  %d , n);           for (int i = 1; i < k; i++) {             printf(  %d , n + 1);           }           printf(  n );         } else {           printf( %d n , 2 * k + 1);           printf( 1 );           for (int i = 1; i < k; i++) {             printf(  1 );           }           printf(  %d , n);           for (int i = 1; i < k; i++) {             printf(  %d , n + 1);           }           printf(  %d n , n + m);         }       } else {         printf( %d n , 2 * k);         printf( 1 );         for (int i = 1; i < k; i++) {           printf(  1 );         }         printf(  %d , n);         for (int i = 1; i < k; i++) {           printf(  %d , n + 1);         }         printf(  n );       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct EDGE {     int u, v, l, next;     bool train;     EDGE() {}     EDGE(int a, int b, int c, int d, bool bo) {       u = a;       v = b;       l = c;       next = d;       train = bo;     }   } edge[1000000];   int n, m, k;   int edgenumber, head[200100], visit[200100], fr[200100];   long long d[200100];   void addedge(int u, int v, int l, bool bo) {     edge[edgenumber] = EDGE(u, v, l, head[u], bo);     head[u] = edgenumber++;   }   void spfa(int rt) {     memset(d, 0x3f3f3f3f, sizeof(d));     priority_queue<pair<int, long long> > q;     q.push(make_pair(1, 0));     visit[rt] = 1;     d[rt] = 0;     while (!q.empty()) {       int u = q.top().first;       q.pop();       for (int i = head[u]; i != -1; i = edge[i].next) {         int v = edge[i].v;         int l = edge[i].l;         if (d[u] + l < d[v]) {           d[v] = d[u] + l;           fr[v] = i;           if (!visit[v]) {             visit[v] = 1;             q.push(make_pair(v, -d[v]));           }         } else if (d[v] == d[u] + l && edge[fr[v]].train) {           fr[v] = i;         }       }       visit[u] = 0;     }     for (int i = 2; i <= n; i++)       if (edge[fr[i]].train) k--;   }   int main() {     scanf( %d%d%d , &n, &m, &k);     edgenumber = 0;     memset(head, -1, sizeof(head));     vector<pair<int, int> > kn;     for (int i = 0; i < m; i++) {       int u, v, l;       scanf( %d%d%d , &u, &v, &l);       addedge(u, v, l, false);       addedge(v, u, l, false);     }     for (int i = 0; i < k; i++) {       int v, l;       scanf( %d%d , &v, &l);       kn.push_back(make_pair(v, l));       addedge(1, v, l, true);     }     spfa(1);     printf( %d n , k);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int s;     cin >> s;     while (s--) {       string t;       cin >> t;       int f = 0;       for (int i = 1; i < t.length(); i++) {         if (t[i] != t[i - 1]) {           f = 1;           break;         }       }       if ((f == 0) || (t.length() == 2)) {         cout << t << endl;       } else {         cout << t[0];         for (int i = 1; i < t.length(); i++) {           if (t[i] == t[i - 1]) {             if (t[i] ==  0 ) {               cout << 1 << t[i];             } else if (t[i] ==  1 ) {               cout << 0 << t[i];             }           } else {             cout << t[i];           }         }         cout << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   typedef long long ll;   int main()   {     int t;     cin >> t;     while(t--)     {         string s;         cin >> s;         char c =  a ;         int n = s.size();         if(n&1)         {              for(int i=0;i<=n/2;i++)            {                if(s[n-i-1]!= a )                {                    s = s.substr(0,i)+c+s.substr(i);                    break;                }            }            if(s.size()==n+1)             {                 cout <<  YES  << endl;                 cout << s << endl;             }             else{                 bool p = true;                  for(int i=0;i<n/2;i++)                 {                   if(s[n-i-1]!=s[i])                   {                    p = false;                    break;                   }                }                if(!p)                {                    cout <<  YES  << endl;                    cout << s+c << endl;                }                else                {                    cout <<  NO  << endl;                }             }         }         else{            for(int i=0;i<n/2;i++)            {                if(s[n-i-1]!= a )                {                    s = s.substr(0,i)+c+s.substr(i);                    break;                }            }            if(s.size()==n+1)             {                 cout <<  YES  << endl;                 cout << s << endl;             }             else{                 bool p = true;                  for(int i=0;i<n/2;i++)                 {                   if(s[n-i-1]!=s[i])                   {                    p = false;                    break;                   }                }                if(!p)                {                    cout <<  YES  << endl;                    cout << s+c << endl;                }                else                {                    cout <<  NO  << endl;                }             }         }              }   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC target( avx2,tune=native )   #pragma GCC optimize( unroll-loops )   using namespace std;   using ll = long long;   using ld = long double;   using vi = vector<int>;   using vvi = vector<vi>;   using pi = pair<ll, ll>;   const int mod = 1e9 + 7;   const ll inf = 1e18;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   ll n, k, mn[40][100100], sm[40][100100], p[40][100100];   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n >> k;     for (int i = 0; i < n; i++) cin >> p[0][i];     for (int i = 0; i < n; i++) cin >> mn[0][i], sm[0][i] = mn[0][i];     for (int i = 1; i < 34; i++) {       for (int j = 0; j < n; j++) {         p[i][j] = p[i - 1][p[i - 1][j]];         sm[i][j] = sm[i - 1][j] + sm[i - 1][p[i - 1][j]];         mn[i][j] = min(mn[i - 1][j], mn[i - 1][p[i - 1][j]]);       }     }     for (int i = 0; i < n; i++) {       ll u = i, m = LLONG_MAX, s = 0;       for (int j = 34; j--;) {         if (k & (1ll << j)) {           m = min(m, mn[j][u]);           s = s + sm[j][u];           u = p[j][u];         }       }       cout << s <<     << m <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int __gcd(int x, int y) {     if (!y) return x;     return __gcd(y, x % y);   }   const long long linf = 1e18 + 5;   int mod = (int)1e9;   const int logN = 18;   const int inf = 1e9 + 9;   const int N = 1e5 + 5;   int ff, h[N], n, a[N], x, y, z, p;   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);       h[a[i]]++;     }     int ff = 0;     for (int i = 1; i <= 100000; i++)       if (h[i] & 1) ff = 1;     if (ff) {       cout <<  Conan ;     } else       cout <<  Agasa ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 5007;   const int MX = 1e9 + 7;   const long long int INF = 1e18 + 9LL;   int n, m;   int in[N];   vector<int> cows[N];   int Left[N], Right[N];   int take[N], poss[N], New[N];   void update(int t) {     int canTake = 0;     if (cows[t][0] <= Left[t] || cows[t][0] <= Right[t]) canTake = 1;     if (cows[t].size() >= 2) {       int mn = min(Left[t], Right[t]);       int mx = max(Left[t], Right[t]);       if (cows[t][0] <= mn && cows[t][1] <= mx) canTake = 2;     }     if (canTake == 0) {       if (take[t] == 0) return;       take[t] = 0, poss[t] = 1, New[t] = 1;       return;     }     if (canTake == 1) {       int xd = 0;       for (auto v : cows[t]) {         if (v <= Left[t]) ++xd;         if (v <= Right[t]) ++xd;       }       if (take[t] != canTake) {         take[t] = 1;         poss[t] = New[t] = xd;       } else {         poss[t] = xd;         for (auto v : cows[t])           if (v == Left[t]) New[t] = 1;       }       return;     }     int prawo = 0;     poss[t] = 0;     for (auto v : cows[t])       if (v <= Right[t]) ++prawo;     for (int i = 0; i < (int)cows[t].size(); ++i)       if (cows[t][i] <= Left[t]) {         poss[t] += prawo;         if (cows[t][i] <= Right[t]) --poss[t];       }     if (canTake != take[t]) {       take[t] = 2;       New[t] = poss[t];       return;     }     for (int i = 0; i < (int)cows[t].size(); ++i)       if (cows[t][i] == Left[t]) {         New[t] = prawo;         if (cows[t][i] <= Right[t]) --New[t];       }   }   int main() {     scanf( %d %d , &n, &m);     for (int i = 1; i <= n; ++i) scanf( %d , &in[i]);     for (int i = 1; i <= m; ++i) {       int f, h;       scanf( %d %d , &f, &h);       cows[f].push_back(h);     }     for (int i = 1; i <= n; ++i) sort(cows[i].begin(), cows[i].end());     for (int i = 1; i <= n; ++i) {       Right[in[i]]++;       poss[i] = 1;     }     int ans = 0, ans2 = 1;     for (int i = 1; i <= n; ++i) {       if (cows[i].size() == 0) continue;       update(i);       ans += take[i];       ans2 = (1LL * ans2 * poss[i]) % MX;     }     for (int i = 1; i <= n; ++i) {       Right[in[i]]--;       Left[in[i]]++;       for (int j = 1; j <= n; ++j) New[j] = 0;       if (cows[in[i]].size()) update(in[i]);       int now = 0;       for (int j = 1; j <= n; ++j) now += take[j];       if (now < ans) continue;       if (now > ans) {         ans = now;         ans2 = 0;       }       int tmp1 = 1, tmp2 = 1;       for (int j = 1; j <= n; ++j) {         tmp1 = (1LL * tmp1 * poss[j]) % MX;         tmp2 = (1LL * tmp2 * (poss[j] - New[j])) % MX;       }       ans2 = (1LL * ans2 + tmp1 + MX - tmp2) % MX;     }     printf( %d %d n , ans, ans2);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double PI = acos(-1);   const int inf = 0x3fffffff;   const int maxn = 200005;   int n;   unsigned long long m;   struct P {     int x, y;   } p[maxn];   bool cmp(P a, P b) {     if (a.x == b.x) return a.y < b.y;     return a.x < b.x;   }   int main() {     scanf( %d , &n);     int y = 1;     for (int i = 1; i <= 2 * n; i++) {       int x;       scanf( %d , &x);       p[i].x = x, p[i].y = y;       y++;       if (y > n) y = 1;     }     scanf( %I64u , &m);     sort(p + 1, p + 2 * n + 1, cmp);     unsigned long long ans = 1, tmpans = 1, cnt = 0;     int now = -1;     for (int i = 1; i <= 2 * n; i++) {       if (now != p[i].x) {         now = p[i].x;         ans *= tmpans;         tmpans = 1LL;         ans %= m;         cnt = 0LL;       }       if (i < 2 * n) {         if (p[i + 1].x != p[i].x) {           tmpans *= (cnt + 1LL);           tmpans %= m;         } else {           if (p[i + 1].y != p[i].y) {             tmpans *= (cnt + 1LL);             tmpans %= m;             cnt++;           } else {             unsigned long long tmp1 = cnt + 1LL, tmp2 = cnt + 2LL;             if (tmp1 % 2LL == 0LL)               tmp1 /= 2LL;             else               tmp2 /= 2LL;             tmpans *= tmp1;             tmpans %= m;             tmpans *= tmp2;             tmpans %= m;             cnt += 2LL;             i++;             if (i == 2 * n) {               ans *= tmpans;               ans %= m;               break;             }           }         }       } else {         tmpans *= (cnt + 1LL);         tmpans %= m;         ans *= tmpans;         ans %= m;         break;       }     }     printf( %I64u n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   void show(const vector<T> &a) {     for (T x : a) cout << x <<    ;     cout <<   n ;   }   const long long N = 1e5 + 10, oo = 1e18 + 500;   const long long mod = 1e9 + 7;   const long double eps = 1e-9, PI = 2 * acos(0.0);   long long n, m, k;   long long cnt = 0;   vector<long long> g[N];   vector<long long> rg[N];   vector<long long> visit(N, 0);   vector<vector<long long> > dp(N, vector<long long>(150, -oo));   signed main() {     ios::sync_with_stdio(0);     cout.tie(0);     cin.tie(0);     cin >> n >> m >> k;     vector<vector<long long> > a(n, vector<long long>(m + 1));     for (long long i = 0; i < n; i++) {       cin >> a[i][0];     }     for (long long i = 0; i < n; i++) {       for (long long j = 0; j < m; j++) cin >> a[i][j + 1];     }     sort(a.rbegin(), a.rend());     dp[0][0] = a[0][0];     for (long long j = 0; j < m; j++) {       dp[0][(1 << j)] = a[0][j + 1];     }     for (long long i = 1; i < n; i++) {       for (long long mask = 0; mask < (1 << m); mask++) {         long long ex = 0;         for (long long j = 0; j < m; j++) {           if (mask & (1 << j)) {             ex++;           }         }         long long add = 0;         if (i < k + ex) add = a[i][0];         if (dp[i][mask] < dp[i - 1][mask] + add) {           dp[i][mask] = dp[i - 1][mask] + add;         }         for (long long j = 0; j < m; j++) {           if (!(mask & (1 << j))) {             if (dp[i][mask | (1 << j)] < dp[i - 1][mask] + a[i][j + 1]) {               dp[i][mask | (1 << j)] = dp[i - 1][mask] + a[i][j + 1];             }           }         }       }     }     long long ans = dp[n - 1][(1 << m) - 1];     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 5000 + 100;   int x[maxn][maxn], p[maxn], tx[maxn];   int n;   int ask(int i, int j) {     cout <<  ?   << i <<     << j << endl;     int r;     cin >> r;     return r;   }   void answer(int k) {     cout <<  !  << endl;     cout << k << endl;     for (int i = 0; i < n; ++i) cout << p[i] <<    ;     cout << endl;     exit(0);   }   int main() {     cin >> n;     for (int i = 0; i < n; ++i) {       int xo = ask(0, i);       x[0][i] = xo;     }     for (int i = 1; i < n; ++i) {       int xo = ask(i, i);       for (int j = 0; j < n; ++j) {         x[i][j] = xo ^ x[0][i] ^ x[0][j];       }     }     int xn = 0;     for (int i = 0; i < n; ++i) xn ^= i;     if (n & 1) {       for (int i = 0; i < n; ++i) {         int xnow = 0;         for (int j = 0; j < n; ++j) xnow ^= x[i][j];         xnow ^= xn;         p[i] = xnow;       }       answer(1);       return 0;     }     for (int i = 0; i < n; ++i) tx[i] = (x[0][0] ^ x[i][0]);     int ans = 0;     for (int i = 0; i < n; ++i) {       vector<int> tp(maxn);       tp[0] = i;       for (int j = 1; j < n; ++j) tp[j] = (tx[j] ^ tp[0]);       bitset<maxn> v;       bool good = true;       vector<int> tb(maxn);       for (int j = 0; j < n && good; ++j) {         if (tp[j] >= n || tp[j] < 0) {           good = false;           break;         }         tb[tp[j]] = j;       }       for (int j = 0; j < n; ++j) {         if ((tb[j] ^ tp[j]) != x[j][j]) good = false;       }       for (int j = 0; j < n && good; ++j) {         if (tp[j] >= n || tp[j] < 0) {           good = false;           break;         }         if (v[tp[j]]) good = false;         v[tp[j]] = true;       }       if (good) {         ++ans;         for (int j = 0; j < n; ++j) p[j] = tp[j];       }     }     answer(ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long sz = 1e5 + 5;   vector<long long> A(sz, 0), Lazy(4 * sz, 0), Tree(4 * sz, 0);   long long n, m;   void Built(long long Node, long long I, long long F) {     if (I == F) {       Tree[Node] = A[I];       return;     }     long long M = (I + F) / 2;     Built(2 * Node + 1, I, M);     Built(2 * Node + 2, M + 1, F);     Tree[Node] = max(Tree[2 * Node + 1], Tree[2 * Node + 2]);     return;   }   void Update(long long Node, long long I, long long F, long long L, long long R,               long long Value) {     if (Lazy[Node] != 0) {       Tree[Node] += (Lazy[Node]);       Lazy[2 * Node + 1] += Lazy[Node];       Lazy[2 * Node + 2] += Lazy[Node];       Lazy[Node] = 0;     }     if (L > F || R < I) {       return;     }     if (I >= L && F <= R) {       Tree[Node] += Value;       Lazy[2 * Node + 1] += Value;       Lazy[2 * Node + 2] += Value;       return;     }     long long M = (I + F) / 2;     Update(2 * Node + 1, I, M, L, R, Value);     Update(2 * Node + 2, M + 1, F, L, R, Value);     Tree[Node] = max(Tree[2 * Node + 1], Tree[2 * Node + 2]);     return;   }   long long Query(long long Node, long long I, long long F, long long L,                   long long R) {     if (Lazy[Node] != 0) {       Tree[Node] += (Lazy[Node]);       Lazy[2 * Node + 1] += Lazy[Node];       Lazy[2 * Node + 2] += Lazy[Node];       Lazy[Node] = 0;     }     if (L > F || R < I) return INT_MIN;     if (I >= L && F <= R) {       return Tree[Node];     }     long long M = (I + F) / 2;     return max(Query(2 * Node + 1, I, M, L, R),                Query(2 * Node + 2, M + 1, F, L, R));   }   int main() {     cin >> n >> m;     long long Min = INT_MAX;     long long Max = INT_MIN;     long long ansIn = -1;     for (long long i = 0; i < n; i++) {       cin >> A[i];       Min = min(Min, A[i]);       Max = max(Max, A[i]);     }     long long ans = Max - Min;     Built(0, 0, n - 1);     vector<pair<long long, long long> > tmp(m);     map<pair<long long, long long>, vector<long long> > mp;     for (long long i = 0; i < m; i++) {       cin >> tmp[i].first >> tmp[i].second;       tmp[i].first = tmp[i].first - 1;       tmp[i].second = tmp[i].second - 1;       mp[{tmp[i].first, tmp[i].second}].push_back(i + 1);     }     sort(tmp.begin(), tmp.end());     long long i = 0, j = 0;     multiset<pair<long long, long long> > Set;     for (long long k = 0; k < n; k++) {       while (!Set.empty()) {         auto it = Set.begin();         auto p = *it;         if (p.first < k) {           Update(0, 0, n - 1, p.second, p.first, 1);           Set.erase(it);         } else           break;       }       while (j < m && tmp[j].first <= k && tmp[j].second >= k) {         Update(0, 0, n - 1, tmp[j].first, tmp[j].second, -1);         Set.insert({tmp[j].second, tmp[j].first});         j++;       }       long long sze = Set.size();       long long x = Query(0, 0, n - 1, 0, n - 1);       long long y = A[k] - sze;       if (ans < x - y) {         ans = x - y;         ansIn = k;       }     }     cout << ans << endl;     if (ansIn == -1) {       cout << 0;       return 0;     }     vector<long long> Ans;     for (long long i = 0; i < m; i++) {       if (tmp[i].first <= ansIn && tmp[i].second >= ansIn) {         Ans.push_back(mp[{tmp[i].first, tmp[i].second}]                         [mp[{tmp[i].first, tmp[i].second}].size() - 1]);         mp[{tmp[i].first, tmp[i].second}].pop_back();       }     }     cout << Ans.size() << endl;     for (auto i : Ans) cout << i <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7;   const int N = 2222;   int n, K;   long long sum[N][N], tail[N], f[N][N];   char s[N];   long long work() {     long long ret = 0;     tail[n + 1] = 1;     for (int i = n; i >= 1; i--) tail[i] = tail[i + 1] * (s[i] -  a  + 1) % MOD;     if (K == 0) return tail[1];     f[0][0] = 1;     sum[0][0] = 1;     for (int i = 1; i <= n; i++) {       int dt = n - i + 1;       for (int j = 0; j <= K; j++) {         for (int k = i - 1; k >= 0 && (i - k) * dt <= j; k--) {           f[i][j] = (f[i][j] + f[k][j - (i - k) * dt]) % MOD;         }         f[i][j] = f[i][j] * ( z  - s[i]) % MOD;       }       for (int j = 0; j <= K; j++) {         f[i][j] = (f[i][j] + sum[i - 1][j] * (s[i] -  a ) % MOD) % MOD;         sum[i][j] = (sum[i - 1][j] + f[i][j]) % MOD;       }     }     ret = sum[n][K];     return ret;   }   int main() {     scanf( %d%d%s , &n, &K, s + 1);     printf( %I64d n , work());     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[1000100], b[1000100], cnt[32];   int solve(int n, int m) {     int i, j, k, ret = 0;     memset(cnt, 0, sizeof(cnt));     for (i = 0; i < n; ++i) {       for (j = 0; (1 << j) <= a[i]; ++j) {         if (a[i] & (1 << j)) ++cnt[j];       }     }     sort(b, b + m);     for (i = 0; i < m; ++i) {       for (j = b[i]; j < 32 && !cnt[j]; ++j)         ;       if (j == 32) break;       ++ret;       --cnt[j];       for (k = b[i]; k < j; ++k) ++cnt[k];     }     return ret;   }   int main() {     int n, m, i;     while (~scanf( %d %d , &n, &m)) {       for (i = 0; i < n; ++i) scanf( %d , &a[i]);       for (i = 0; i < m; ++i) scanf( %d , &b[i]);       printf( %d n , solve(n, m));     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = 1e9 + 10;   const long long BINF = 1e18 + 10;   long long get(long long l, long long r) {     if (l > r) {       swap(l, r);     }     return r * (r + 1) / 2 - l * (l - 1) / 2;   }   long long solve(long long a, long long b, long long lim) {     long long res = 0;     if (a > lim) {       if (b >= lim) {         res += lim * (a - b + 1);       } else {         res += get(b, lim) + lim * (a - lim);       }     } else {       res += get(a, b);     }     return res;   }   void source() {     long long n, x, y, need;     cin >> n >> x >> y >> need;     if (need <= 1) {       cout << 0;       exit(0);     }     long long l = 0, r = 2 * n + 10;     long long mx_up = n - y + 1, mx_down = y;     while (r - l > 1) {       long long mid = (l + r) / 2, sum = 0;       long long left = max(x - mid, 1ll), right = min(x + mid, n);       long long a = mid + 1, vl = a - (x - left), vr = a - (right - x);       sum = solve(a, vl, mx_up) + solve(a, vr, mx_up) - min(mx_up, a);       sum += solve(a, vl, mx_down) + solve(a, vr, mx_down) - min(mx_down, a);       sum -= right - left + 1;       if (sum >= need) {         r = mid;       } else {         l = mid;       }     }     cout << r;   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     source();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int num;     int arr[110];     cin >> num;     for (int i = 0; i < num; i++) {       cin >> arr[i];     }     for (int i = 1; i <= num; i++) {       for (int j = 0; j < num; j++) {         if (arr[j] == i) {           cout << j + 1 <<    ;         }       }     }     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   string we, ns, sol =   ;   void fast() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);   }   int main() {     fast();     cin >> n >> m;     cin >> we;     cin >> ns;     sol += we[0];     sol += we.back();     sol += ns[0];     sol += ns.back();     if (sol ==  <>v^  || sol ==  ><^v ) {       cout <<  YES ;     } else {       cout <<  NO ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long logN = 20;   const long long M = 1000000007;   const long long INF = 1e12;   const long long N = 100005;   void solve() {     long long n, k;     cin >> n >> k;     set<long long> s;     while (s.size() < 30 and s.size() < (n - 1)) {       long long i = rand() % n + 1;       if (i != 1 and s.find(i) == s.end()) {         s.insert(i);         cout <<  ? 1 1  << endl;         cout << 1 << endl;         cout << i << endl;         string gt;         cin >> gt;         if (gt ==  SECOND ) {           cout <<  ! 1  << endl;           return;         }       }     }     long long l = 2, r = 2;     for (long long i = 0; i < 10; i++) {       long long dif = (r - l + 1);       cout <<  ?   << dif <<     << dif << endl;       for (long long i = 1; i < dif + 1; i++) cout << i <<    ;       cout << endl;       for (long long i = l; i < l + dif; i++) cout << i <<    ;       cout << endl;       string s;       cin >> s;       if (s ==  FIRST ) break;       l = r + 1;       r = 2 * r;       r = min(r, n);     }     while (r > l) {       long long m = (l + r) / 2;       long long dif = (m - l + 1);       cout <<  ?   << dif <<     << dif << endl;       for (long long i = 1; i < dif + 1; i++) cout << i <<    ;       cout << endl;       for (long long i = l; i < l + dif; i++) cout << i <<    ;       cout << endl;       string s;       cin >> s;       if (s ==  EQUAL )         l = m + 1;       else         r = m;     }     cout <<  !   << l << endl;     return;   }   int main() {     long long no;     cin >> no;     while (no--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int sum[100010], bsum[100010], arr2[100010];   pair<long long int, long long int> arr[100010];   void scanStr(char *str) {     long long int i = 1;     char ch;     for (ch = getchar(); ch !=   n  && ch !=    ; ch = getchar()) str[i++] = ch;     str[i] =   0 ;     return;   }   inline void fastOut(long long int n) {     if (n < 10) {       putchar(n +  0 );       return;     }     fastOut(n / 10);     putchar(n % 10 +  0 );     return;   }   long long int powerFast(long long int a, long long int b) {     long long int i = a, j = 1, k = 1;     while (b) {       if (b & 1) {         k = ((k * i) < 1000000007 ? (k * i) : (k * i) % 1000000007);       }       i = ((i * i) < 1000000007 ? (i * i) : (i * i) % 1000000007);       b = b >> 1;     }     return k;   }   inline long long int scan() {     long long int n = 0;     char c;     for (c = getchar(); c ==     || c ==   n  || c ==   t ; c = getchar())       ;     for (; c > 0x2f && c < 0x3a; c = getchar()) n = (n * 10) + (c & 0x0f);     return n;   }   bool comp(pair<long long int, long long int> a,             pair<long long int, long long int> b) {     if (a.first < b.first) return false;     return true;   }   int main() {     long long int N, A, cf, cm, M, i, j, K, t, tmin, tnA, maxx;     N = scan();     A = scan();     cf = scan();     cm = scan();     M = scan();     for (i = 1; i <= N; i++) {       arr[i].first = scan();       arr[i].second = i;     }     sort(arr + 1, arr + N + 1,          std::greater<pair<long long int, long long int> >());     for (i = 1; i <= N; i++) {       sum[i] = sum[i - 1] + arr[i].first;     }     long long int loc1, loc2, val;     maxx = LONG_MIN;     j = 1;     for (i = 0; i <= N; i++) {       K = M - (A * i - sum[i]);       if (K < 0) {         break;       }       tnA = i;       tmin = A;       for (j = max(i + 1, j); j <= N; j++) {         t = arr[j].first * (N - j + 1);         t = t - (sum[N] - sum[j - 1]);         if (t <= K) {           t = K - t;           tmin = min(arr[j].first + t / (N - j + 1), A);           break;         }       }       if ((cf * tnA + cm * tmin) >= maxx) {         maxx = cf * tnA + cm * tmin;         loc1 = i;         loc2 = j;         val = tmin;       }     }     cout << maxx <<   n ;     for (i = 1; i <= loc1; i++) {       arr2[arr[i].second] = A;     }     for (i = loc1 + 1; i < loc2; i++) {       arr2[arr[i].second] = arr[i].first;     }     for (i = loc2; i <= N; i++) {       arr2[arr[i].second] = val;     }     for (i = 1; i <= N; i++) {       fastOut(arr2[i]);       putchar(   );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void readi(int &x) {     int v = 0, f = 1;     char c = getchar();     while (!isdigit(c) && c !=  - ) c = getchar();     if (c ==  - )       f = -1;     else       v = v * 10 + c -  0 ;     while (isdigit(c = getchar())) v = v * 10 + c -  0 ;     x = v * f;   }   void readll(long long &x) {     long long v = 0ll, f = 1ll;     char c = getchar();     while (!isdigit(c) && c !=  - ) c = getchar();     if (c ==  - )       f = -1;     else       v = v * 10 + c -  0 ;     while (isdigit(c = getchar())) v = v * 10 + c -  0 ;     x = v * f;   }   void readc(char &x) {     char c;     while ((c = getchar()) ==    )       ;     x = c;   }   void writes(string s) { puts(s.c_str()); }   void writeln() { writes(  ); }   void writei(int x) {     if (!x) putchar( 0 );     char a[25];     int top = 0;     while (x) {       a[++top] = (x % 10) +  0 ;       x /= 10;     }     while (top) {       putchar(a[top]);       top--;     }   }   void writell(long long x) {     if (!x) putchar( 0 );     char a[25];     int top = 0;     while (x) {       a[++top] = (x % 10) +  0 ;       x /= 10;     }     while (top) {       putchar(a[top]);       top--;     }   }   long long n, m, li, ns, i, j, k, l, mod = 1e9 + 7, x, y, dp[123456][12][3],                                       vis[123456];   vector<long long> e[123456];   void dfs(int x, int fa) {     long long i;     if (vis[x]) return;     vis[x] = 1;     dp[x][0][2] = ns - 1;     dp[x][1][1] = 1;     dp[x][0][0] = m - ns;     for (i = 0; i < e[x].size(); i++) {       if (e[x][i] == fa) continue;       dfs(e[x][i], x);       for (j = li; ~j; j--) {         long long mem[3] = {0, 0, 0};         for (k = 0; k <= j; k++) {           (mem[0] +=            (dp[x][j - k][0] * (dp[e[x][i]][k][0] + dp[e[x][i]][k][2]))) %= mod;           (mem[1] += (dp[x][j - k][1] * (dp[e[x][i]][k][2]))) %= mod;           (mem[2] += (dp[x][j - k][2] * (dp[e[x][i]][k][0] + dp[e[x][i]][k][1] +                                          dp[e[x][i]][k][2]))) %= mod;         }         for (k = 0; k < 3; k++) dp[x][j][k] = mem[k];       }     }   }   int main() {     readll(n);     readll(m);     for (i = 1; i < n; i++) {       readll(x);       readll(y);       e[x].push_back(y);       e[y].push_back(x);     }     readll(ns);     readll(li);     dfs(1, 0);     long long res = 0;     for (i = 0; i <= li; i++)       (res += dp[1][i][0] + dp[1][i][1] + dp[1][i][2]) %= mod;     writell(res);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int T = 1;     while (T--) {       int n, m;       cin >> n >> m;       map<int, int> mp;       vector<pair<int, int> > pp;       for (int i = 0; i < m; i++) {         int a, b;         cin >> a >> b;         pp.push_back({a, b});         if (a != b) {           mp[a]++;           mp[b]++;         } else           mp[a]++;       }       vector<pair<int, int> > maxi;       for (auto x : mp) {         maxi.push_back({x.second, x.first});       }       sort(maxi.rbegin(), maxi.rend());       int mm = min(4, int((maxi).size()));       for (int q = 0; q < mm; q++) {         vector<int> v(m, 0);         int cnt = 0;         for (int i = 0; i < m; i++) {           if (pp[i].first == maxi[q].second || pp[i].second == maxi[q].second) {             v[i] = 1;             cnt++;           }         }         cnt = m - cnt;         if (cnt == 0) {           cout <<  YES ;           exit(0);         }         mp.clear();         for (int i = 0; i < m; i++) {           if (v[i] == 0) {             if (pp[i].first != pp[i].second) {               mp[pp[i].first]++;               mp[pp[i].second]++;             } else               mp[pp[i].first]++;           }         }         for (auto x : mp) {           if (x.second == cnt) {             cout <<  YES ;             exit(0);           }         }       }       cout <<  NO ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 7;   map<int, int> l, r;   int a[maxn << 1];   int sum[maxn << 1];   int main() {     int t;     cin >> t;     while (t--) {       l.clear();       r.clear();       int n;       cin >> n;       for (int i = 1; i <= 2 * n; i++) cin >> a[i];       for (int i = 1; i <= 2 * n; i++) {         a[i] = (a[i] == 2 ? 1 : -1);       }       for (int i = 1; i <= n; i++) sum[i] = sum[i - 1] + a[i];       sum[2 * n + 1] = 0;       for (int i = 2 * n; i >= n + 1; i--) sum[i] = sum[i + 1] + a[i];       r[0] = 2 * n + 1;       l[0] = 0;       for (int i = 1; i <= n; i++) l[sum[i]] = max(l[sum[i]], i);       for (int i = 2 * n; i >= n + 1; i--)         r[sum[i]] ? r[sum[i]] = min(r[sum[i]], i) : r[sum[i]] = i;       int ans = 2 * n;       for (int i = 0; i <= n; i++) {         if (!r[-sum[i]]) continue;         ans = min(r[-sum[i]] - l[sum[i]] - 1, ans);       }       for (int i = 2 * n + 1; i >= n + 1; i--) {         if (!l[-sum[i]] && sum[i]) continue;         ans = min(ans, r[sum[i]] - l[-sum[i]] - 1);       }       cout << ans << endl;     }     return 0;     ;   }


#include <bits/stdc++.h>   using namespace std;   int m[10000000];   int func(int v) {     int r = 1;     while (v != 1) {       if (v % 2 == 0) {         v /= 2;       } else {         v--;         r++;       }     }     return r;   }   int main() {     int n, a;     long long r = 0;     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %d , &a);       m[func(a)]++;     }     for (int i = 0; i < 10000000; i++) {       r += (long long)(((long long)m[i] * (long long)(m[i] - 1)) / 2);     }     cout << r;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long solve(long long A, long long B, long long C) {     if (B == 0) {       return 0;     }     long long N = A % B;     long long X = solve(B, N, C);     long long Y = (-C - A * X) / B;     if (A != 0) {       Y %= A;     }     return Y;   }   int abs(int a) { return a > 0 ? a : -a; }   int _gcd(int a, int b) {     if (b == 0) return a;     return _gcd(b, a % b);   }   int A, B, C;   int main() {     scanf( %d %d %d , &A, &B, &C);     int gcd = _gcd(abs(A), abs(B));     if (C % gcd == 0) {       long long Y = solve(A, B, C);       long long X = 0;       if (A != 0) {         X = (-B * Y - C) / A;       }       printf( %I64d %I64d n , X, Y);     } else {       printf( -1 n );     }     return 0;   }


#include <bits/stdc++.h>   int dx[] = {-1, 0, 1, 0};   int dy[] = {0, 1, 0, -1};   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int n;     cin >> n;     int a[n];     for (int i = 0; i < n; i++) cin >> a[i];     bool flag = false;     for (int i = 1; i < n - 1; i++) {       if ((1ll * (a[i] - a[0]) * (a[i] - a[i + 1])) > 0) {         cout << 3 <<   n ;         cout << 1 <<     << (i + 1) <<     << (i + 2) <<   n ;         flag = true;         break;       }     }     if (!flag) cout << 0 <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 1;   vector<int> adj[N];   int numDiv[N];   int a[N];   bool cand[N];   int sz[N], dsu[N];   int f(int x) {     if (x == dsu[x]) {       return x;     }     return dsu[x] = f(dsu[x]);   }   void merge(int x, int y) {     x = f(x), y = f(y);     if (x != y) {       dsu[x] = y;       sz[y] += sz[x];     }   }   int val[N];   int numPrime[N];   long long all[N];   vector<int> in[N];   int lastColor[N];   int isGood[N];   int curColorList[N];   int go[N];   int bfs(int root, int curColor) {     int sz = 0;     queue<int> q;     q.push(root);     lastColor[root] = curColor;     while (!q.empty()) {       int node = q.front();       q.pop();       ++sz;       for (int i = 0; i < (int)adj[node].size(); ++i) {         int nextNode = adj[node][i];         if (isGood[nextNode] == curColor && lastColor[nextNode] < curColor) {           lastColor[nextNode] = curColor;           q.push(nextNode);         }       }     }     return sz;   }   void solve() {     int n;     scanf( %d , &n);     for (int i = 1; i <= n; ++i) {       scanf( %d , &a[i]);       in[a[i]].push_back(i);     }     for (int i = 0; i < n - 1; ++i) {       int x, y;       scanf( %d %d  , &x, &y);       adj[x].push_back(y);       adj[y].push_back(x);     }     int g = N;     for (int i = 1; i < N; ++i) {       val[i] = 1;     }     int maxi = 0;     for (int i = 2; i < N; ++i) {       if (val[i] == 1) {         for (int j = i; j < N; j += i) {           val[j] *= i;           numPrime[j] ^= 1;         }       }     }     int curColor = 1;     int lim = (int)2e5;     int pos;     for (int num = lim; num >= 1; --num) {       ++curColor;       pos = 0;       for (int j = num; j <= lim; j += num) {         for (auto node : in[j]) {           if (isGood[node] != curColor) {             isGood[node] = curColor;             curColorList[pos++] = node;           }         }       }       long long tmp = 0;       for (int i = 0; i < pos; ++i) {         int node = curColorList[i];         if (lastColor[node] < curColor) {           int sz = bfs(node, curColor);           tmp += (long long)sz * (sz + 1);         }       }       tmp /= 2;       all[num] = tmp;     }     for (int num = 1; num <= lim; ++num) {       int g = 1;       long long ret = 0;       for (int j = num; j <= lim; j += num, ++g) {         if (val[g] == g) {           if (numPrime[g]) {             ret -= all[j];           } else {             ret += all[j];           }         }       }       if (ret > 0) {         printf( %d %lld n , num, ret);       }     }   }   int main() { solve(); }


#include <bits/stdc++.h>   using namespace std;   const int N = 220;   int n, m;   pair<int, double> a[N];   double Dp[N][N][N];   double Rec(int i, int j, int k) {     k = min(k, n);     if (k < 0) return 0.0;     if (i == n) return j >= m;     if (Dp[i][j][k] == Dp[i][j][k]) return Dp[i][j][k];     return Dp[i][j][k] = a[i].second * Rec(i + 1, j + 1, k + a[i].first) +                          (1.0 - a[i].second) * Rec(i + 1, j, k);   }   int main() {     memset(Dp, -1, sizeof(Dp));     int k;     cin >> n >> m >> k;     for (int i = 0; i < n; i++) cin >> a[i].second, a[i].second /= 100.0;     for (int i = 0; i < n; i++) cin >> a[i].first;     sort(a, a + n);     reverse(a, a + n);     printf( %.9f , Rec(0, 0, k));   }


#include <bits/stdc++.h>   using namespace std;   inline int read() {     int x = 0, c = getchar(), f = 0;     for (; c >  9  || c <  0 ; f = c ==  - , c = getchar())       ;     for (; c >=  0  && c <=  9 ; x = (x << 1) + (x << 3) + c -  0 , c = getchar())       ;     return f ? -x : x;   }   inline void write(int x) {     if (x < 0) putchar( - ), x = -x;     if (x >= 10) write(x / 10);     putchar(x % 10 + 48);   }   const int N = 100000 + 10;   int n, m, cnt = 1, head[N], du[N], layer[N], leader[N], q[N];   bool vis1[N], vis2[N], vis3[N * 2];   vector<vector<int> > ans;   vector<int> tmp, _;   vector<pair<int, int> > comp;   struct edge {     int to, nxt;   } e[N * 4];   void addedge(int u, int v) {     e[++cnt] = (edge){v, head[u]};     head[u] = cnt;     e[++cnt] = (edge){u, head[v]};     head[v] = cnt;     du[u]++;     du[v]++;   }   void dfs(int u, int fa, int lineid) {     vis1[u] = 1;     vis2[layer[u]] = 1;     tmp.push_back(u);     for (int i = head[u], v; i; i = e[i].nxt)       if ((i >> 1) != lineid) {         if (!vis1[v = e[i].to]) {           dfs(v, u, i >> 1);           tmp.push_back(u);           for (; cnt >= 0 && vis2[comp[cnt].second]; cnt--)             ;           if (cnt >= 0) {             vis3[i >> 1] = 1;             v = leader[comp[cnt].second];             ans.push_back(tmp);             tmp.clear();             _.clear();             _.push_back(i >> 1);             _.push_back(u);             _.push_back(v);             ans.push_back(_);             dfs(v, u, i >> 1);             tmp.push_back(u);           }         } else {           if (vis3[i >> 1]) continue;           for (; cnt >= 0 && vis2[comp[cnt].second]; cnt--)             ;           if (cnt >= 0) {             vis3[i >> 1] = 1;             v = leader[comp[cnt].second];             ans.push_back(tmp);             tmp.clear();             _.clear();             _.push_back(i >> 1);             _.push_back(u);             _.push_back(v);             ans.push_back(_);             dfs(v, u, i >> 1);             tmp.push_back(u);           }         }       }   }   void print() {     puts( YES );     write(ans.size() / 2);     puts(  );     for (int i = (int)0; i <= (int)ans.size() - 1; i++) {       if (i & 1)         write(ans[i][0]), putchar(   ), write(ans[i][1]), putchar(   ),             write(ans[i][2]), puts(  );       else {         write(ans[i].size());         for (int j = (int)0; j <= (int)ans[i].size() - 1; j++)           putchar(   ), write(ans[i][j]);         puts(  );       }     }   }   int findbridge() {     for (int i = (int)2; i <= (int)n; i++) vis1[i] = 0;     for (int i = (int)1; i <= (int)m; i++) vis3[i] = 0;     for (int i = (int)2; i <= (int)n; i++)       if (!vis1[i]) {         q[*q = 1] = i;         vis1[i] = 1;         for (int j = (int)1; j <= (int)*q; j++) {           int u = q[j];           for (int k = head[u], v; k; k = e[k].nxt)             if (!vis3[k >> 1]) {               vis3[k >> 1] = 1;               if (vis1[v = e[k].to])                 return k >> 1;               else                 vis1[v] = 1, q[++*q] = v;             }         }       }     return 0;   }   int getblo(int l, int r) {     for (int i = (int)l; i <= (int)r; i++) vis1[i] = 0;     int blo = 0;     comp.clear();     for (int i = (int)l; i <= (int)r; i++)       if (!vis1[i]) {         ++blo;         q[*q = 1] = i;         vis1[i] = 1;         for (int j = (int)1; j <= (int)*q; j++) {           int u = q[j];           for (int k = head[u], v; k; k = e[k].nxt)             if (!vis1[v = e[k].to]) vis1[v] = 1, q[++*q] = v;         }         for (int j = (int)1; j <= (int)*q; j++) layer[q[j]] = blo;         leader[blo] = q[1];         comp.push_back(make_pair(*q, blo));       }     sort(comp.begin(), comp.end());     return blo;   }   void go(int id) {     int u = 1;     for (int i = (int)2; i <= (int)n; i++) {       for (int j = head[i], pre; j; pre = j, j = e[j].nxt)         if ((j >> 1) == id) {           if (du[i] > 1) u = i;           du[i]--;           if (j == head[i])             head[i] = e[j].nxt;           else             e[pre].nxt = e[j].nxt;           break;         }     }     getblo(2, n);     cnt = comp.size() - 1;     for (int i = (int)1; i <= (int)n; i++) vis1[i] = vis2[i] = 0;     for (int i = (int)1; i <= (int)m; i++) vis3[i] = 0;     vis1[1] = 1;     _.clear();     _.push_back(1);     ans.push_back(_);     _.clear();     _.push_back(id);     _.push_back(1);     _.push_back(u);     ans.push_back(_);     dfs(u, 1, 0);     if (tmp.size()) ans.push_back(tmp), tmp.clear();     print();   }   int main() {     n = read(), m = read();     for (int i = (int)1; i <= (int)m; i++) addedge(read(), read());     if (n == 1) return puts( YES n0 n1 1 n ), 0;     int blo = getblo(1, n);     if (m < blo - 1) return puts( NO ), 0;     if (du[1]) {       for (int i = (int)1; i <= (int)n; i++) vis1[i] = vis2[i] = 0;       for (int i = (int)1; i <= (int)m; i++) vis3[i] = 0;       cnt = comp.size() - 1;       dfs(1, 0, 0);       if (tmp.size()) ans.push_back(tmp), tmp.clear();       print();     } else {       int id = findbridge();       if (id)         go(id);       else {         if (m < blo)           puts( NO );         else {           for (int i = (int)2; i <= (int)n; i++)             if (du[i] > 1) {               id = head[i] / 2;               break;             }           if (id)             go(id);           else             puts( NO );         }       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int oo = (int)1e9;   const double eps = 1e-9;   long long gcd(long long a, long long b);   int main() {     int n;     long long maxi = 0, num, g;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> num;       maxi = max(maxi, num);       g = gcd(g, num);     }     if ((maxi / g - n) % 2)       cout <<  Alice  << endl;     else       cout <<  Bob  << endl;   }   long long gcd(long long a, long long b) {     if (b == 0)       return a;     else       return gcd(b, a % b);   }


#include <bits/stdc++.h>   const int maxn = 0x3f3f3f3f;   const double EI =       2.71828182845904523536028747135266249775724709369995957496696762772407663035354594571382178525166427;   const double PI = 3.141592653589793238462643383279;   using namespace std;   struct node {     int l, r;     double x, y, a;   } tree[300010 * 4];   int n;   void pushup(int p) {     double dis = sqrt(tree[2 * p + 1].x * tree[2 * p + 1].x +                       tree[2 * p + 1].y * tree[2 * p + 1].y);     double a = atan2(tree[2 * p + 1].y, tree[2 * p + 1].x);     tree[p].x = tree[2 * p].x + dis * cos(tree[2 * p].a + a);     tree[p].y = tree[2 * p].y + dis * sin(tree[2 * p].a + a);     tree[p].a = tree[2 * p].a + tree[2 * p + 1].a;     return;   }   void build(int l, int r, int p) {     tree[p].l = l;     tree[p].r = r;     if (l + 1 == r) {       tree[p].x = 1.0;       tree[p].y = 0.0;       tree[p].a = 0.0;       return;     }     int k = ((l + r) >> 1);     build(l, k, p << 1);     build(k, r, (p << 1) + 1);     pushup(p);     return;   }   void update(int pos, double len, double aa, int p) {     if (tree[p].l + 1 == tree[p].r) {       double dis = sqrt(tree[p].x * tree[p].x + tree[p].y * tree[p].y);       double a = atan2(tree[p].y, tree[p].x);       dis += len, a += aa;       tree[p].x = dis * cos(a);       tree[p].y = dis * sin(a);       tree[p].a = a;       return;     }     if (pos <= tree[p << 1].r) {       update(pos, len, aa, p << 1);     } else {       update(pos, len, aa, (p << 1) + 1);     }     pushup(p);     return;   }   int main() {     double val;     int q, op, pos;     while (~scanf( %d %d , &n, &q)) {       build(0, n, 1);       while (q--) {         scanf( %d %d %lf , &op, &pos, &val);         if (op == 1) {           update(pos, val, 0, 1);         } else {           update(pos, 0, (1 - val / 360) * 2 * PI, 1);         }         printf( %.10f %.10f n , tree[1].x, tree[1].y);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long int t;     cin >> t;     while (t--) {       long long int n;       cin >> n;       string s;       cin >> s;       long long int oc = 0, zc = 0, fpos = -1, lpos;       for (int i = 0; i < (int)n; i++) {         if (s[i] ==  0 )           zc++;         else {           oc++;           if (fpos == -1) {             fpos = i;           }           lpos = i;         }       }       if (oc == 0)         cout << n <<   n ;       else if (zc == 0)         cout << 2 * n <<   n ;       else {         if (s[0] ==  1 ) {           cout << 2 * n <<   n ;         } else {           cout << 2 * max((n - fpos), (lpos + 1)) <<   n ;         }       }     }   }


#include <bits/stdc++.h>   using namespace std;   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long n;     cin >> n;     long long a[n + 1];     long long diff[n];     long long max_count = INT_MIN;     for (long long i = 1; i <= n; i++) cin >> a[i];     multiset<long long> eles;     eles.insert(a[1]);     long long i = 2, j = 1;     while (i <= n && j <= n) {       eles.insert(a[i]);       long long mini = *eles.begin();       long long maxi = *eles.rbegin();       while (maxi - mini > 1) {         eles.erase(eles.find(a[j]));         j++;         maxi = *eles.rbegin();         mini = *eles.begin();       }       long long sz = eles.size();       max_count = max(max_count, sz);       i++;     }     cout << max_count;     return 0;   }


#include <bits/stdc++.h>   int main() {     int n, i, j, count = 0;     scanf( %d , &n);     int ara[n];     for (i = 0; i < n; i++) {       scanf( %d , &ara[i]);     }     for (i = 0; i < n - 1; i++) {       for (j = i + 1; j < n; j++) {         if (ara[i] == 0) {           continue;         }         if (ara[i] == ara[j]) {           ara[i] = 0;         }       }       if (ara[i] != 0) {         count++;       }     }     if (ara[n - 1] != 0) {       count++;     }     printf( %d n , count);     for (i = 0; i < n; i++) {       if (ara[i] == 0) {         continue;       }       printf( %d  , ara[i]);     }     printf(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char s[450000];   int main() {     scanf( %s , &s);     vector<string> list;     char cur, last =  ! ;     string word =   ;     int len = strlen(s);     for (int i = 0; i < len; i++) {       cur = s[i];       if (last ==  ! ) {         if (cur !=  . ) {           word += cur;         } else {           printf( NO );           return 0;         }       } else {         if (cur ==  . ) {           if (last !=  . ) {             if (((word.length() > 11))) {               printf( NO );               return 0;             } else {               list.push_back(word);               word =   ;             }           } else {             printf( NO );             return 0;           }         } else {           word += cur;         }       }       last = cur;     }     if (last ==  . ) {       printf( NO );       return 0;     }     if (word !=   ) {       if (word.length() < 4) {         list.push_back(word);       } else {         printf( NO );         return 0;       }     }     if (list.size() == 2) {       if (!(list[0].length() > 0 && list[0].length() < 9 &&             list[1].length() > 0 && list[1].length() < 4)) {         printf( NO );         return 0;       }     } else {       if (list.size() == 1) {         printf( NO );         return 0;       }     }     for (int i = 1; i < list.size() - 1; i++) {       if (list[i].length() == 1) {         printf( NO );         return 0;       }     }     len = list.size();     bool was = false;     for (int i = 0; i < len; i++) {       if (!was) {         was = true;         if (list[i].length() > 8) {           printf( NO );           return 0;         } else {           cout <<  YES n ;           cout << list[i] <<  . ;         }       } else {         if (i != len - 1) {           if (list[i].length() > 3) {             cout << list[i].substr(0, 3) <<   n ;             cout << list[i].substr(3, list[i].length() - 3) <<  . ;           } else {             cout << list[i].substr(0, 1) <<   n ;             cout << list[i].substr(1, list[i].length() - 1) <<  . ;           }         } else {           cout << list[i] <<   n ;         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double EPS = 1.0e-8;   struct Point {     double x, y;     Point(double _x = 0, double _y = 0) {       x = _x;       y = _y;     }     friend Point operator+(const Point &a, const Point &b) {       return Point(a.x + b.x, a.y + b.y);     }     friend Point operator-(const Point &a, const Point &b) {       return Point(a.x - b.x, a.y - b.y);     }     friend double operator^(const Point &a, const Point &b) {       return a.x * b.y - a.y * b.x;     }   };   Point Basic;   set<Point> Set;   double Distance(Point a, Point b) {     return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));   }   bool operator<(Point a, Point b) {     a = a - Basic;     b = b - Basic;     double Ang1 = atan2(a.y, a.x), Ang2 = atan2(b.y, b.x);     double Len1 = Distance(a, Point(0.0, 0.0)),            Len2 = Distance(b, Point(0.0, 0.0));     if (fabs(Ang1 - Ang2) < EPS) return Len1 < Len2;     return Ang1 < Ang2;   }   set<Point>::iterator Pre(set<Point>::iterator it) {     if (it == Set.begin()) it = Set.end();     return --it;   }   set<Point>::iterator Nxt(set<Point>::iterator it) {     ++it;     return it == Set.end() ? Set.begin() : it;   }   int Query(Point p) {     set<Point>::iterator it = Set.lower_bound(p);     if (it == Set.end()) it = Set.begin();     return ((p - *(Pre(it))) ^ (*(it) - *(Pre(it)))) < EPS;   }   void Insert(Point p) {     if (Query(p)) return;     Set.insert(p);     set<Point>::iterator it = Nxt(Set.find(p));     while (Set.size() > 3 && ((p - *(Nxt(it))) ^ (*(it) - *(Nxt(it)))) < EPS) {       Set.erase(it);       it = Nxt(Set.find(p));     }     it = Pre(Set.find(p));     while (Set.size() > 3 && ((p - *(it)) ^ (*(it) - *(Pre(it)))) > -EPS) {       Set.erase(it);       it = Pre(Set.find(p));     }   }   int main() {     int q;     scanf( %d , &q);     Basic = Point(0, 0);     int oper;     Point a, str[5];     for (int i = 1; i <= 3; ++i) {       scanf( %d%lf%lf , &oper, &str[i].x, &str[i].y);       Basic = Basic + str[i];     }     Basic.x /= 3.0;     Basic.y /= 3.0;     q -= 3;     for (int i = 1; i <= 3; ++i) {       Set.insert(str[i]);     }     while (q--) {       scanf( %d%lf%lf , &oper, &a.x, &a.y);       if (oper == 1) {         Insert(a);       } else {         if (Query(a))           printf( YES n );         else           printf( NO n );       }     }   }


#include <bits/stdc++.h>   using namespace std;      #define fast_io                     ios::sync_with_stdio(0);        cin.tie(NULL);                  cout.tie(NULL);   #define lli long long   #define loop(i, l, r) for (lli i = l; l < r ? i < r : i > r; l < r ? i += 1 : i -= 1)   #define itr(it, a) for (auto it = a.begin(); it != a.end(); it++)   #define it(i, a) for (auto i : a)   #define endl   n    #define inputarray(arr, start, size)        loop(i, start, size) { cin >> arr[i]; }   #define printarray(arr, start, size)                       loop(i, start, size) { cout << arr[i] <<    ; }        cout << endl;   #define mod 1000000007   #define inf 1e18   #define sp(x, y) fixed << setprecision(y) << x << endl;   #define pii pair<lli, lli>   #define mp make_pair   #define pb push_back   #define fi first   #define se second   #define all(x) x.begin(), x.end()   #define clr(x) memset(x, 0, sizeof(x))   #define sortall(x) sort(all(x))   #define debug(x) cout << #x <<  =  << x << endl      int main()   {   #ifndef ONLINE_JUDGE       freopen( input.txt ,  r , stdin);       freopen( output.txt ,  w , stdout);   #endif       fast_io           lli t = 1;       cin >> t;       while (t--)       {           lli n;           cin >> n;           vector<lli> v(n);           inputarray(v, 0, n);           bool flag = 0;           lli diff = INT_MAX, md = INT_MIN;           loop(i, 0, n)           {               if (v[i] < 0)               {                   flag = 1;                   break;               }           }           if (flag)           {               cout <<  NO  << endl;               continue;           }              cout <<  YES  << endl;           cout <<  101  << endl;           vector<lli> b;           loop(i, 0, 101)           {               b.push_back(i);           }           printarray(b, 0, b.size());       }       return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ld = long double;   vector<vector<int>> selfloops;   vector<vector<pair<int, int>>> adjlist;   vector<vector<int>> otherIdx;   vector<int> cycle, validIdx;   void swapEdges(int n, int a, int b) {     int neighA = adjlist[n][a].first, neighB = adjlist[n][b].first;     int idxNeighA = otherIdx[n][a], idxNeighB = otherIdx[n][b];     swap(adjlist[n][a], adjlist[n][b]);     swap(otherIdx[n][a], otherIdx[n][b]);     otherIdx[neighA][idxNeighA] = b;     otherIdx[neighB][idxNeighB] = a;   }   void removeEdge(int n, int i) {     int other = adjlist[n][i].first;     validIdx[n]++;     int otherIndex = otherIdx[n][i];     if (otherIndex != validIdx[other]) {       swapEdges(other, otherIndex, validIdx[other]);     }     validIdx[other]++;   }   void addEdge(int a, int b, int id) {     otherIdx[a].push_back((ll)(adjlist[b]).size() + (a == b));     otherIdx[b].push_back((ll)(adjlist[a]).size());     adjlist[a].push_back({b, id});     adjlist[b].push_back({a, -id});   }   void euler(int n) {     while (validIdx[n] < (ll)(adjlist[n]).size()) {       ll edge = adjlist[n][validIdx[n]].second;       int nn = adjlist[n][validIdx[n]].first;       removeEdge(n, validIdx[n]);       euler(nn);       cycle.push_back(edge);     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     ll n;     cin >> n;     vector<pair<ll, ll>> in(n);     for (ll i = 0; i < n; i++) {       ll a, b;       cin >> a >> b;       in[i] = {a, b};     }     auto ok = [&](ll res) {       selfloops.assign(1ll << res, {});       adjlist.assign(1ll << res, {});       otherIdx.assign(1ll << res, {});       validIdx.assign(1ll << res, 0);       cycle.clear();       ll mask = (1ll << res) - 1;       for (ll i = 0; i < n; i++) {         addEdge(in[i].first & mask, in[i].second & mask, i + 1);       }       bool ok = true;       ll start = 0;       for (ll i = 0; i < (1ll << res); i++) {         ok &= ((ll)(adjlist[i]).size() % 2) == 0;         if (!adjlist[i].empty()) start = i;       }       if (ok) euler(start);       return (ll)(cycle).size() == n;     };     ll l = 0;     ll r = 21;     while (l + 1 < r) {       ll m = (l + r) / 2;       if (ok(m)) {         l = m;       } else {         r = m;       }     }     ok(l);     reverse(begin(cycle), end(cycle));     cout << l << endl;     for (ll x : cycle) {       ll a = 2 * abs(x) - 1;       ll b = 2 * abs(x);       ll c = in[abs(x) - 1].first;       ll d = in[abs(x) - 1].second;       if (x < 0) swap(a, b);       if (x < 0) swap(c, d);       cout << a <<     << b <<    ;     }     cout << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string word, type;     int n;     cin >> n;     int j;     int cur = 0, real = 0, sreal = 0;     bool t = false, b = false;     getline(cin, word);     for (int i = 0; i < n; ++i) {       getline(cin, word);       for (j = 0; j < (int)word.size() && word[j] ==    ; ++j)         ;       if (j != word.size()) {         if (word[j] ==  c ) {           if (t) {             if (cur <= real) {               for (; j < (int)word.size() && word[j] !=  ( ; ++j)                 ;               for (; j < (int)word.size() && word[j] ==  (  || word[j] ==    ;                    ++j)                 ;               if (type == word.substr(j, type.size())) {                 for (; j < (int)word.size() && word[j] !=    ; ++j)                   ;                 ++j;                 for (; j < (int)word.size() && word[j] !=    ; ++j) {                   cout << word[j];                 }                 return 0;               }             }             --cur;             if (b) {               if (sreal) {                 --sreal;               } else {                 --real;               }             }           }         }         if (word[j] ==  t  && word[j + 1] ==  r ) {           ++cur;           if (b) {             ++sreal;           }         }         if (word[j] ==  t  && word[j + 1] ==  h ) {           t = true;           b = true;           for (; j < word.size() && word[j] !=  ( ; ++j)             ;           for (; j < word.size() && word[j] ==  (  || word[j] ==    ; ++j)             ;           for (; j < word.size() && word[j] !=     && word[j] !=  ) ; ++j) {             type.push_back(word[j]);           }           real = cur;         }       }     }     cout <<  Unhandled Exception ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, L, m, head[1000005], cnt, root, sz[1000005], sum, mx;   long long t[1000005], ans;   struct edge {     int to, next, cost;   } e[1000005 << 1];   struct dist {     int len, dis;     bool operator<(const dist &p) const { return dis < p.dis; }   } dis[1000005], q[1000005];   bool vis[1000005];   inline int read() {     int x = 0, w = 1;     char c = getchar();     while (c <  0  || c >  9 ) {       if (c ==  - ) w = -1;       c = getchar();     }     while (c >=  0  && c <=  9 ) {       x = x * 10 + c -  0 ;       c = getchar();     }     return x * w;   }   int lowbit(int x) { return x & (-x); }   void add(int x, int y) {     if (x == 0) return;     for (int i = x; i <= n + 1; i += lowbit(i)) t[i] += y;   }   long long query(int x) {     if (x <= 0) return 0;     long long res = 0;     for (int i = x; i; i -= lowbit(i)) res += t[i];     return res;   }   inline void add(int u, int v, int w) {     e[++cnt] = (edge){v, head[u], w};     head[u] = cnt;   }   void fdrt(int u, int fa) {     sz[u] = 1;     int num = 0;     for (int i = head[u]; i; i = e[i].next) {       int v = e[i].to;       if (v == fa || vis[v]) continue;       fdrt(v, u);       sz[u] += sz[v];       num = max(num, sz[v]);     }     num = max(num, sum - sz[u]);     if (mx > num) mx = num, root = u;   }   void gtds(int u, int fa) {     q[++cnt] = dis[u];     for (int i = head[u]; i; i = e[i].next) {       int v = e[i].to;       if (v == fa || vis[v]) continue;       dis[v].len = dis[u].len + 1;       dis[v].dis = dis[u].dis + e[i].cost;       gtds(v, u);     }   }   long long calc(int u, int len, int d) {     cnt = 0;     dis[u].len = len, dis[u].dis = d;     gtds(u, 0);     sort(q + 1, q + cnt + 1);     for (int i = 1; i <= cnt; i++) add(q[i].len + 1, 1);     int l = 1, r = cnt;     long long res = 0;     while (l < r) {       if (q[l].dis + q[r].dis <= m) {         add(q[l].len + 1, -1);         res += query(L - q[l].len + 1);         l++;       } else         add(q[r].len + 1, -1), r--;     }     add(q[l].len + 1, -1);     return res;   }   void solve(int u) {     ans += calc(u, 0, 0);     vis[u] = 1;     for (int i = head[u]; i; i = e[i].next) {       int v = e[i].to;       if (vis[v]) continue;       ans -= calc(v, 1, e[i].cost);       sum = mx = sz[v];       fdrt(v, 0);       solve(root);     }   }   int main() {     n = read();     L = read();     m = read();     for (int i = 2; i <= n; i++) {       int u = read(), w = read();       add(u, i, w);       add(i, u, w);     }     sum = mx = n;     fdrt(1, 0);     solve(root);     printf( %I64d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int sum = 0, n, a[120], x, y, i;     cin >> n;     for (i = 0; i < n - 1; ++i) {       cin >> a[i];     }     cin >> x >> y;     for (i = x - 1; i < y - 1; ++i) {       sum += a[i];     }     cout << sum <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1100, M = 2 * 1e5 + 10, INF = 1e9 + 10;   pair<int, int> e[M];   int dp[N][N];   vector<pair<pair<int, int>, pair<int, int> > > que[M];   bool ans[M];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int n, m, q;     cin >> n >> m >> q;     for (int i = 0; i < m; i++) cin >> e[i].first >> e[i].second;     for (int i = 0; i < q; i++) {       int l, r, s, t;       cin >> l >> r >> s >> t;       l--;       que[l].push_back({{s, t}, {r, i}});     }     for (int i = 1; i <= n; i++)       for (int j = 1; j <= n; j++)         if (i != j) dp[i][j] = INF;     for (int i = m - 1; i >= 0; i--) {       int u = e[i].first, v = e[i].second;       dp[u][v] = dp[v][u] = i;       for (int j = 1; j <= n; j++) {         if (j == u || j == v) continue;         if (dp[u][j] > dp[v][j])           dp[u][j] = dp[v][j];         else           dp[v][j] = dp[u][j];       }       for (auto X : que[i]) {         int s = X.first.first, t = X.first.second, r = X.second.first,             id = X.second.second;         if (dp[s][t] < r)           ans[id] = true;         else           ans[id] = false;       }     }     for (int i = 0; i < q; i++) {       if (ans[i])         cout <<  Yes n ;       else         cout <<  No n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int col[5001], mid, n, dis[5001][5001], ans;   bool v[5001];   long long mod = 1e9 + 7;   bool dfs(int x) {     v[x] = 1;     for (int i = 1; i <= n; ++i)       if (i != x && dis[x][i] > mid)         if (!v[i]) {           col[i] = col[x] ^ 1;           if (dfs(i)) return 1;         } else if (col[x] == col[i])           return 1;     return 0;   }   bool check() {     memset(v, 0, sizeof(v));     for (int i = 1; i <= n; ++i)       if (!v[i])         if (dfs(i)) return 0;     return 1;   }   void dfss(int x) {     v[x] = 1;     for (int i = 1; i <= n; ++i)       if (!v[i] && dis[x][i] > ans) dfss(i);   }   long long mult(long long x, long long y) {     long long res = x * 1ll;     y--;     while (y) {       if (y & 1) res = res * x % mod;       x = x * x % mod;       y >>= 1;     }     return res;   }   int cnt, x[5001], y[5001];   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; ++i) scanf( %d%d , &x[i], &y[i]);     for (int i = 1; i <= n; ++i)       for (int j = 1; j <= n; ++j)         dis[i][j] = abs(x[i] - x[j]) + abs(y[i] - y[j]);     int l = 0, r = 10000;     while (l <= r) {       mid = l + r >> 1;       if (check()) {         ans = mid;         r = mid - 1;       } else         l = mid + 1;     }     memset(v, 0, sizeof(v));     printf( %d n , ans);     for (int i = 1; i <= n; ++i)       if (!v[i]) {         ++cnt;         dfss(i);       }     printf( %I64d , mult(2ll, (long long)cnt));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 200 * 1000 + 13;   const long long INF64 = 1e18;   int n, m;   long long a[N];   vector<pair<int, long long>> g[N];   long long dist[N];   void Dijkstra() {     set<pair<long long, int>> q;     for (int i = 0; i < int(n); i++) {       dist[i] = a[i];       q.insert({dist[i], i});     }     while (!q.empty()) {       int v = q.begin()->second;       q.erase(q.begin());       for (auto it : g[v]) {         int u = it.first;         long long w = it.second;         if (dist[u] > dist[v] + w) {           q.erase({dist[u], u});           dist[u] = dist[v] + w;           q.insert({dist[u], u});         }       }     }   }   int main() {     scanf( %d%d , &n, &m);     for (int _ = 0; _ < int(m); _++) {       int f, t;       long long w;       scanf( %d%d%lld , &f, &t, &w);       --f, --t;       w *= 2;       g[f].push_back({t, w});       g[t].push_back({f, w});     }     for (int i = 0; i < int(n); i++) {       scanf( %lld , &a[i]);     }     Dijkstra();     for (int i = 0; i < int(n); i++) printf( %lld  , dist[i]);     puts(  );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int _ = 2e2 + 20;   int n;   struct matrix {     double a[_][_];     matrix operator*(matrix b) {       matrix c;       for (int i = 0; i <= n * 2; ++i)         for (int j = 0; j <= n * 2; ++j) {           c.a[i][j] = 0;           for (int k = 0; k <= n * 2; ++k)             c.a[i][j] = max(c.a[i][j], a[i][k] + b.a[k][j]);           c.a[i][j] /= 2;         }       return c;     }   } A;   double a[_];   int main() {     cin >> n;     for (int i = 0; i <= n; ++i) cin >> a[i];     for (int i = 0; i <= n * 2; ++i) {       for (int j = 0; j <= n * 2; ++j) {         if (i + j >= n && (i + n - j & 1) == 0 && i - j <= n && j - i <= n)           A.a[i][j] = a[(i + n - j) / 2];         else           A.a[i][j] = -1e18;       }     }     double ans = 0;     for (int i = 1; i <= 50; ++i) A = A * A;     for (int i = 0; i <= n * 2; ++i) ans = max(ans, A.a[0][i]);     printf( %.10f n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 3000010;   const int inf = 1e9 + 1;   int n, k, a[N], b[N];   bool check(long long x) {     long long s = 0;     for (int i = 1; i <= n; i++) {       long long tmp = b[i] - a[i] * x;       if (tmp < 0) {         s -= tmp;       }       if (s > k) return false;     }     return (s <= k);   }   int main() {     scanf( %d%d , &n, &k);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     for (int i = 1; i <= n; i++) scanf( %d , &b[i]);     long long l = 0, r = 2e9;     while (l + 1 < r) {       long long m = (l + r) / 2;       if (check(m))         l = m;       else         r = m - 1;     }     if (check(r))       cout << r;     else       cout << l;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     stack<char> stk;     int cnt = 0;     for (int i = s.size() - 1; i >= 0; i--) {       if (stk.empty())         stk.push(s[i]);       else {         if (stk.top() == s[i]) {           cnt++;           stk.pop();         } else           stk.push(s[i]);       }     }     cout << (cnt & 1 ?  Yes  :  No ) << endl;     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   void File_input() {     freopen( in.txt ,  r , stdin);     freopen( out.txt ,  w , stdout);   }   void FastInputOutput() {     ios_base ::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);   }   vector<char> geno[ z  + 1];   int t, n;   string str;   bool vis[ z  + 1], in[ z  + 1];   int indeg[ z  + 1];   void DFS(char a) {     cout << a;     for (auto i : geno[a]) {       if (!vis[i]) {         vis[i] = 1;         DFS(i);       }     }   }   int main() {     cin >> t;     while (t--) {       cin >> str;       n = (long long)str.size();       for (int i = 0; i < n; i++) in[str[i]] = 1;       for (int i = 1; i < n; i++) {         geno[str[i - 1]].push_back(str[i]);         indeg[str[i]]++;       }     }     for (char a =  a ; a <=  z ; a++) {       if (!vis[a] && in[a] && !indeg[a]) {         DFS(a);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   double distance(double x1, double y1, double x2, double y2) {     return sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));   }   int main() {     double ax, ay, bx, by, tx, ty;     scanf( %lf%lf%lf%lf%lf%lf , &ax, &ay, &bx, &by, &tx, &ty);     int n;     scanf( %d , &n);     double cdist[n], D = 0;     pair<double, double> p[n];     for (int i = 0; i < n; ++i) {       scanf( %lf%lf , &p[i].first, &p[i].second);       cdist[i] = distance(tx, ty, p[i].first, p[i].second);       D += 2 * cdist[i];     }     set<pair<double, int> > A, B;     double distA[n], distB[n];     for (int i = 0; i < n; ++i) {       double x = -cdist[i] + distance(ax, ay, p[i].first, p[i].second);       distA[i] = x;       A.insert({x, i});       x = -cdist[i] + distance(bx, by, p[i].first, p[i].second);       distB[i] = x;       B.insert({x, i});     }     double temp1 = D + A.begin()->first;     double temp2 = D + B.begin()->first;     double temp3 = D + A.begin()->first;     int idx = A.begin()->second;     B.erase({distB[idx], idx});     if (not B.empty()) temp3 += B.begin()->first;     B.insert({distB[idx], idx});     double temp4 = D + B.begin()->first;     idx = B.begin()->second;     A.erase({distA[idx], idx});     if (not A.empty()) temp4 += A.begin()->first;     double ans = min(min(temp1, temp2), min(temp3, temp4));     printf( %lf n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct Activity {     int gym, contest;     bool gym_used, contest_used;   };   int main() {     int n;     cin >> n;     vector<int> v(n);     for (int &e : v) cin >> e;     vector<Activity> res(n);     switch (v[0]) {       case 0:         res[0].gym = res[0].contest = 0;         res[0].gym_used = res[0].contest_used = false;         break;       case 1:         res[0].gym = 0;         res[0].contest = 1;         res[0].gym_used = false;         res[0].contest_used = true;         break;       case 2:         res[0].gym = 1;         res[0].contest = 0;         res[0].gym_used = true;         res[0].contest_used = false;         break;       case 3:         res[0].gym = res[0].contest = 1;         res[0].gym_used = res[0].contest_used = true;         break;     }     for (int i = 1; i < v.size(); i++) {       if (v[i] == 1) {         res[i] = res[i - 1];         res[i].contest_used = res[i].gym_used = false;       }       if (v[i] == 1 || v[i] == 3) {         if (res[i - 1].contest_used) {           if (res[i - 1].gym >= res[i - 1].contest) {             res[i].contest_used = true;             res[i].contest = res[i - 1].gym + 1;           } else {             res[i].contest_used = false;             res[i].contest = res[i - 1].contest;           }         } else {           res[i].contest_used = true;           res[i].contest = max(res[i - 1].gym, res[i - 1].contest) + 1;         }       }       if (v[i] == 0 || v[i] == 1) {         res[i].gym = res[i - 1].gym;         res[i].gym_used = false;       }       if (v[i] == 0 || v[i] == 2) {         res[i].contest = res[i - 1].contest;         res[i].contest_used = false;       }       if (v[i] == 2 || v[i] == 3) {         if (res[i - 1].gym_used) {           if (res[i - 1].contest >= res[i - 1].gym) {             res[i].gym_used = true;             res[i].gym = res[i - 1].contest + 1;           } else {             res[i].gym_used = false;             res[i].gym = res[i - 1].gym;           }         } else {           res[i].gym_used = true;           res[i].gym = max(res[i - 1].gym, res[i - 1].contest) + 1;         }       }     }     cout << n - max(res[n - 1].gym, res[n - 1].contest) << endl;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     int a;     cin >> a;     int b[a];     for (int i = 0; i < a; i++) {       cin >> b[i];     }     int ind = 0;     for (int i = 0; i < a - 1; i++) {       if (b[i] > b[i + 1]) {         b[0] = b[0] - b[i] + b[i + 1];         if (b[0] < 0) {           cout <<  NO ;           return;         }       }     }     cout <<  YES ;   }   int main() {     int t;     cin >> t;     while (t--) {       solve();       cout << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e6 + 60;   const int IN = 0;   const int AND = 1;   const int OR = 2;   const int XOR = 3;   const int NOT = 4;   struct Node {     int val, p1, p2;     int op;   } node[maxn];   int n, p1, p2;   string op;   bool change[maxn];   int eval(int cur) {     if (node[cur].op == IN) {       return node[cur].val;     }     if (node[cur].op == AND) {       return node[cur].val = (eval(node[cur].p1) & eval(node[cur].p2));     }     if (node[cur].op == OR) {       return node[cur].val = (eval(node[cur].p1) | eval(node[cur].p2));     }     if (node[cur].op == XOR) {       return node[cur].val = (eval(node[cur].p1) ^ eval(node[cur].p2));     }     if (node[cur].op == NOT) {       return node[cur].val = (!eval(node[cur].p1));     }   }   void process(int cur, int now) {     int l = node[cur].p1;     int r = node[cur].p2;     int vl = node[l].val;     int vr = node[r].val;     if (node[cur].op == IN) {       return;     } else if (node[cur].op == AND) {       if (vl == 0 && vr == 0) {         process(l, change[l] = 0);         process(r, change[r] = 0);       } else if (vl == 0 && vr == 1) {         process(l, change[l] = (now & 1));         process(r, change[r] = 0);       } else if (vl == 1 && vr == 0) {         process(l, change[l] = 0);         process(r, change[r] = (now & 1));       } else if (vl == 1 && vr == 1) {         process(l, change[l] = (now & 1));         process(r, change[r] = (now & 1));       }     } else if (node[cur].op == OR) {       if (vl == 0 && vr == 0) {         process(l, change[l] = (now & 1));         process(r, change[r] = (now & 1));       } else if (vl == 0 && vr == 1) {         process(l, change[l] = 0);         process(r, change[r] = (now & 1));       } else if (vl == 1 && vr == 0) {         process(l, change[l] = (now & 1));         process(r, change[r] = 0);       } else if (vl == 1 && vr == 1) {         process(l, change[l] = 0);         process(r, change[r] = 0);       }     } else if (node[cur].op == XOR) {       process(l, change[l] = (now & 1));       process(r, change[r] = (now & 1));     } else if (node[cur].op == NOT) {       process(l, change[l] = (now & 1));     }   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       cin >> op;       if (op ==  IN ) {         scanf( %d , &p1);         node[i] = {p1, 0, 0, IN};       } else if (op ==  NOT ) {         scanf( %d , &p1);         node[i] = {0, p1, 0, NOT};       } else if (op ==  AND ) {         scanf( %d%d , &p1, &p2);         node[i] = {0, p1, p2, AND};       } else if (op ==  OR ) {         scanf( %d%d , &p1, &p2);         node[i] = {0, p1, p2, OR};       } else if (op ==  XOR ) {         scanf( %d%d , &p1, &p2);         node[i] = {0, p1, p2, XOR};       }     }     eval(1);     process(1, 1);     for (int i = 1; i <= n; i++) {       if (node[i].op == IN) printf( %d , change[i] ^ node[1].val);     }   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = (long long)1e13 + 7LL;   int reqHigh[100100], grow[100100];   int n, nDay, allow, cut;   struct Tree {     int id;     long long finHigh, timeDie;     Tree() { id = finHigh = timeDie = 0; }     Tree(int id, long long x) {       this->id = id;       finHigh = x - 1LL * grow[id] * nDay;       timeDie = min((x + 1) / grow[id] + ((x + 1) % grow[id] > 0), nDay + 1LL);     }     void cutTree(void) {       finHigh += cut;       long long tmp = finHigh + 1LL * grow[id] * nDay + 1;       timeDie = min(tmp / grow[id] + (tmp % grow[id] > 0), nDay + 1LL);     }     bool needCut(void) const { return (finHigh < reqHigh[id]); }     bool operator>(const Tree &t) const {       if (timeDie != t.timeDie) return (timeDie < t.timeDie);       return (reqHigh[id] - finHigh > reqHigh[t.id] - t.finHigh);     }     bool operator<(const Tree &t) const { return (t > *this); }   };   void init(void) {     scanf( %d%d%d%d , &n, &nDay, &allow, &cut);     for (int i = (1), _b = (n); i <= _b; i = i + 1)       scanf( %d%d , &reqHigh[i], &grow[i]);   }   bool ok(long long x) {     priority_queue<Tree> q;     for (int i = (1), _b = (n); i <= _b; i = i + 1) q.push(Tree(i, x));     for (int i = (1), _b = (nDay); i <= _b; i = i + 1) {       Tree tmp = q.top();       q.pop();       if (tmp.timeDie <= i) return (false);       q.push(tmp);       int used = 0;       while (used < allow) {         Tree tmp = q.top();         q.pop();         if (!tmp.needCut()) return (true);         tmp.cutTree();         q.push(tmp);         used++;       }     }     Tree tmp = q.top();     q.pop();     return (!tmp.needCut());   }   long long process(void) {     long long L = 1;     long long R = INF;     while (true) {       if (L == R) return (R);       if (R - L == 1) return (ok(L) ? L : R);       long long M = (L + R) >> 1;       if (ok(M))         R = M;       else         L = M + 1;     }   }   int main(void) {     init();     cout << process() << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 105;   int n, m, grid[N][N];   int val[N][N];   bool vis[105][105];   int a[105];   int b[105];   int dp[105][105];   int tot;   int main() {     scanf( %d%d , &n, &m);     for (int i = 0; i < n; i++) scanf( %d , a + i), tot ^= a[i];     int tmp = 0;     for (int i = 0; i < m; i++) scanf( %d , b + i), tmp ^= b[i];     if (tot != tmp) return puts( NO );     for (int x = 0; x < 31; x++) {       for (int i = 0; i < n; i++) {         if (a[i] >> x & 1) {           bool f = false;           for (int j = 0; j < m; j++)             if (b[j] >> x & 1) {               grid[i][j] ^= (1 << x);               b[j] ^= (1 << x);               a[i] ^= (1 << x);               break;             }         }       }       int cnt = 0;       for (int j = 0; j < m; j++) cnt += (b[j] >> x & 1);       if (cnt & 1) return puts( NO );       for (int j = 0; j < m; j++)         if (b[j] >> x & 1) grid[0][j] ^= (1 << x), b[j] ^= (1 << x);     }     for (int x = 0; x < 31; x++) {       for (int j = 0; j < m; j++) {         if (b[j] >> x & 1) {           bool f = false;           for (int i = 0; i < n; i++)             if (a[i] >> x & 1) {               grid[i][j] ^= (1 << x);               b[j] ^= (1 << x);               a[i] ^= (1 << x);               break;             }         }       }       int cnt = 0;       for (int i = 0; i < n; i++) cnt += (a[i] >> x & 1);       if (cnt & 1) return puts( NO );       for (int i = 0; i < n; i++)         if (a[i] >> x & 1) grid[i][0] ^= (1 << x), a[i] ^= (1 << x);     }     puts( YES );     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) cout << grid[i][j] <<    ;       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main(int argc, char* argv[]) {     char str[105];     cin.getline(str, 104);     for (unsigned i = 1; i < strlen(str) + 1; i++) {       if ((str[i] == str[i - 1]) && (str[i - 1] ==  / )) {         for (unsigned j = i; j < strlen(str); j++) {           str[j] = str[j + 1];         }         i--;       }     }     if ((str[strlen(str) - 1] ==  / ) && (strlen(str) >= 2)) {       str[strlen(str) - 1] = 0;     }     cout << str << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-6;   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...);   }   const long long N = 2010;   long long n;   long long k;   string s[N];   string ans;   long long dp[N][N];   long long path[N][N];   void solve() {     cin >> n;     cin >> k;     for (long long i = 0; i < n; ++i) cin >> s[i];     for (long long i = 0; i < n; ++i) {       for (long long j = 0; j < n; ++j) {         if (i == 0 && j == 0) {           dp[i][j] += (s[i][j] !=  a );           continue;         }         if (i == 0) {           dp[i][j] = dp[i][j - 1];           dp[i][j] += (s[i][j] !=  a );           continue;         }         if (j == 0) {           dp[i][j] = dp[i - 1][j];           dp[i][j] += (s[i][j] !=  a );           continue;         }         dp[i][j] += min(dp[i - 1][j], dp[i][j - 1]) + (s[i][j] !=  a );       }     }     if (k >= 2 * n - 1) {       ans = string(2 * n - 1,  a );       cout << ans <<   n ;       return;     }     set<pair<long long, long long>> pool;     long long len = -1;     for (long long i = 0; i < n; ++i) {       for (long long j = 0; j < n; ++j) {         if (dp[i][j] <= k) {           len = max(len, i + j);         }       }     }     if (len == -1) {       ans.push_back(s[0][0]);       len = 0;       if (1 < n) {         pool.insert({0, 1});         pool.insert({1, 0});       }     } else {       ans = string(len + 1,  a );       for (long long i = 0; i < n; ++i) {         for (long long j = 0; j < n; ++j) {           if (i + j == len && dp[i][j] <= k) {             if (i + 1 < n) pool.insert({i + 1, j});             if (j + 1 < n) pool.insert({i, j + 1});           }         }       }     }     long long req = 2 * n - 1 - len - 1;     ;     while (req > 0) {       char c =  z ;       for (auto it : pool) {         c = min(c, s[it.first][it.second]);       }       vector<pair<long long, long long>> toerase;       for (auto it : pool) {         if (c != s[it.first][it.second]) toerase.push_back(it);       }       for (auto it : toerase) pool.erase(it);       vector<pair<long long, long long>> topush;       for (auto [i, j] : pool) {         if (i + 1 < n) topush.push_back({i + 1, j});         if (j + 1 < n) topush.push_back({i, j + 1});       }       pool.clear();       for (auto it : topush) pool.insert(it);       req--;       ans.push_back(c);     }     cout << ans <<   n ;   }   signed main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     ;     long long t = 1;     while (t--) solve();   }


#include <bits/stdc++.h>   using namespace std;   const int INF = (int)1e9 + 7, mod = (int)1e9 + 9, pw = 31, N = (int)1e5 + 123,             M = (int)1e6 + 123;   const double eps = 1e-11;   const unsigned long long inf = 5e18 + 1;   unsigned long long n, a, b, x, m, ans;   bool check = 0;   unsigned long long binpow(unsigned long long a, unsigned long long b) {     unsigned long long rec = 0;     while (b) {       if (b % 2) {         rec = rec + a;         b--;       } else {         a = a + a;         b /= 2;       }       if (rec > n || a > n) {         check = 1;         return 0;       }     }     return rec;   }   long long gcd(long long x, long long y) { return (y ? gcd(y, x % y) : x); }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     cin >> n >> a >> b;     ans = min(n, min(a, b) - 1);     m = binpow(a, b / gcd(a, b));     if (check) {       cout << ans / gcd(ans, n) <<  /  << n / gcd(ans, n);       return 0;     }     ans += ((n / m) - 1) * min(a, b);     ans += min((n / m) * m + min(a, b) - 1, n) - (n / m) * m + 1;     cout << ans / gcd(ans, n) <<  /  << n / gcd(ans, n);     return 0;   }


#include <bits/stdc++.h>   const int N = 7e3 + 5;   int n, k[2], a[2][N], cnt[2][N];   bool vis[2][N], win[2][N];   void dfs(int v, int now) {     if (vis[v][now]) return;     vis[v][now] = 1;     int u = v ^ 1;     for (int i = 1; i <= k[u]; ++i) {       int pre = (now - a[u][i] + n - 1) % n + 1;       if (pre == 1) continue;       if (!win[v][now]) {         win[u][pre] = 1;         dfs(u, pre);       } else if (++cnt[u][pre] == k[u]) {         win[u][pre] = 0;         dfs(u, pre);       }     }   }   int main() {     scanf( %d , &n);     for (int o = 0; o <= 1; ++o) {       scanf( %d , &k[o]);       for (int i = 1; i <= k[o]; ++i) scanf( %d , &a[o][i]);     }     dfs(0, 1), dfs(1, 1);     for (int o = 0; o <= 1; ++o) {       for (int i = 2; i <= n; ++i) {         if (!vis[o][i])           printf( %s%c ,  Loop ,    n [i == n]);         else           printf( %s%c , win[o][i] ?  Win  :  Lose ,    n [i == n]);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int Z = (int)2e5 + 111;   const int inf = (int)1e9 + 111;   const long long llinf = (long long)1e18 + 5;   const int MOD = (int)1e9 + 7;   vector<long long> pref[4 * Z];   vector<int> t[4 * Z];   int a[Z];   void build(int v, int vl, int vr) {     if (vl == vr) {       t[v].push_back(a[vl]);       pref[v].push_back(a[vl]);       return;     }     int vm = (vl + vr) / 2;     build(2 * v, vl, vm);     build(2 * v + 1, vm + 1, vr);     merge((t[2 * v]).begin(), (t[2 * v]).end(), (t[2 * v + 1]).begin(),           (t[2 * v + 1]).end(), back_inserter(t[v]));     pref[v].resize((int)t[v].size());     pref[v][0] = t[v][0];     for (int i = 1; i < (int)t[v].size(); ++i) {       pref[v][i] = pref[v][i - 1] + t[v][i];     }   }   pair<long long, long long> query(int v, int vl, int vr, int l, int r, int val1,                                    int val2) {     if (vl > r || vr < l) return make_pair(0, 0);     if (l <= vl && r >= vr) {       long long cnt = upper_bound((t[v]).begin(), (t[v]).end(), val2) -                       lower_bound((t[v]).begin(), (t[v]).end(), val1);       int posL = lower_bound((t[v]).begin(), (t[v]).end(), val1) - t[v].begin();       int posR = upper_bound((t[v]).begin(), (t[v]).end(), val2) - t[v].begin();       posR--;       long long sum;       if (posR == -1)         sum = 0;       else         sum = pref[v][posR] - (posL == 0 ? 0 : pref[v][posL - 1]);       return make_pair(sum, cnt);     }     int vm = (vl + vr) / 2;     pair<long long, long long> ql = query(2 * v, vl, vm, l, r, val1, val2);     pair<long long, long long> qr =         query(2 * v + 1, vm + 1, vr, l, r, val1, val2);     return make_pair(ql.first + qr.first, ql.second + qr.second);   }   int main() {     srand(time(0));     ios_base::sync_with_stdio(false);     int n;     cin >> n;     for (int i = 1; i <= n; ++i) {       cin >> a[i];     }     build(1, 1, n);     long double ans = 0;     for (int i = 1; i <= n; ++i) {       pair<long long, long long> l;       if (a[i] - 2 >= 1)         l = query(1, 1, n, i + 1, n, 1, a[i] - 2);       else         l = make_pair(0, 0);       pair<long long, long long> r = query(1, 1, n, i + 1, n, a[i] + 2, inf);       ans += l.first + r.first - (l.second + r.second) * a[i];     }     cout << fixed << setprecision(0) << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long maxN = 1e7 + 5;   const long long inf = 1e10;   const long long mod = 1e9 + 7;   long long n;   long long a[maxN];   double f[maxN];   int main() {     ios_base::sync_with_stdio(0);     cin >> n;     for (long long i = 1; i <= n; i++) {       cin >> a[i];     }     long long cnt = 0;     for (long long i = 1; i <= n; i++) {       for (long long j = i + 1; j <= n; j++)         if (a[i] > a[j]) cnt++;     }     f[0] = 0.0;     f[1] = 1.0;     for (long long i = 2; i <= cnt + 2; i++) {       f[i] = f[i - 2] + 4.0;     }     printf( %.10f , f[cnt]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int M = 200000;   int a[M];   vector<int> all[M];   int main() {     int n, m;     scanf( %d %d , &n, &m);     long long init = 0;     for (int i = 1; i <= m; i++) scanf( %d , &a[i]);     for (int i = 2; i <= m; i++) init += abs(a[i] - a[i - 1]);     for (int i = 1; i <= m; i++) {       if (i != 1 && a[i] != a[i - 1]) all[a[i]].push_back(a[i - 1]);       if (i != m && a[i] != a[i + 1]) all[a[i]].push_back(a[i + 1]);     }     long long ans = init;     for (int i = 1; i <= n; i++) {       int t = all[i].size();       if (t == 0) continue;       long long cur = init;       sort(all[i].begin(), all[i].end());       int be = all[i][t >> 1];       for (int j = 0; j < t; j++)         cur += -abs(i - all[i][j]) + abs(be - all[i][j]);       ans = min(ans, cur);     }     printf( %I64d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     int n;     cin >> n;     vector<int> ans;     int power = 1;     while (n > 0) {       if (n % 10 > 0) {         ans.push_back((n % 10) * power);       }       n /= 10;       power *= 10;     }     cout << ans.size() << endl;     for (auto number : ans) cout << number <<    ;     cout << endl;   }   int main() {     int t;     cin >> t;     while (t--) solve();   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 5;   int n, q, a[N], s1[N], t1, s2[N], t2;   vector<int> ans1[N], ans2[N];   bool tag[N];   inline void down(int &x, const int y) { x > y ? x = y : 0; }   int main() {     scanf( %d%d , &n, &q);     for (int i = 1; i <= n; ++i) scanf( %d , &a[i]);     set<int> cand;     int mp[2] = {n, n};     for (int i = n; i; --i) {       if (i < n && a[i] != a[i + 1]) {         bool t = a[i] > a[i + 1];         if (mp[t ^ 1] < n) ans1[i] = {i, mp[t ^ 1], mp[t ^ 1] + 1};         mp[t] = i;       }       while (t1 && a[s1[t1]] > a[i]) {         if (tag[s1[t1]]) cand.emplace(s1[t1]);         tag[s1[t1--]] = true;       }       while (t2 && a[s2[t2]] < a[i]) {         if (tag[s2[t2]]) cand.emplace(s2[t2]);         tag[s2[t2--]] = true;       }       int _t1 = t1, _t2 = t2, l, r;       for (l = 1, r = t1, t1 = 0; l <= r;) {         int mid = l + r >> 1;         if (a[s1[mid]] != a[i])           t1 = mid, l = mid + 1;         else           r = mid - 1;       }       for (l = 1, r = t2, t2 = 0; l <= r;) {         int mid = l + r >> 1;         if (a[s2[mid]] != a[i])           t2 = mid, l = mid + 1;         else           r = mid - 1;       }       if (t1 && t2) {         int pos = max(s1[t1], s2[t2]);         auto nxt = cand.upper_bound(pos);         if (nxt != cand.end()) {           int p1, p2, l, r, rr = *nxt;           for (l = 1, r = t1; l <= r;) {             int mid = l + r >> 1;             if (s1[mid] < rr)               p1 = s1[mid], r = mid - 1;             else               l = mid + 1;           }           for (l = 1, r = t2; l <= r;) {             int mid = l + r >> 1;             if (s2[mid] < rr)               p2 = s2[mid], r = mid - 1;             else               l = mid + 1;           }           if (p1 > p2) swap(p1, p2);           ans2[i] = {i, p1, p2, rr};         }       }       s1[t1 = _t1 + 1] = i, s2[t2 = _t2 + 1] = i;     }     for (int i = n; i; --i) {       if (!ans1[i + 1].empty() &&           (ans1[i].empty() || ans1[i + 1].back() < ans1[i].back()))         ans1[i] = ans1[i + 1];       if (!ans2[i + 1].empty() &&           (ans2[i].empty() || ans2[i + 1].back() < ans2[i].back()))         ans2[i] = ans2[i + 1];     }     for (int t = 0, l, r; t < q; ++t) {       scanf( %d%d , &l, &r);       if (!ans2[l].empty() && ans2[l].back() <= r) {         puts( 4 );         for (auto x : ans2[l]) printf( %d  , x);         puts(  );       } else if (!ans1[l].empty() && ans1[l].back() <= r) {         puts( 3 );         for (auto x : ans1[l]) printf( %d  , x);         puts(  );       } else         puts( 0 ), puts(  );     }     return 0;   }


#include <bits/stdc++.h>   int mod, n, a, b, good;   std::set<std::pair<int, int> > set;   std::pair<int, int> make_pair(int i, int j) {     return {std::min(i, j), std::max(i, j)};   }   int main() {     scanf( %d%d , &mod, &n);     for (int i = 0; i < n; i++) {       scanf( %d%d , &a, &b);       set.insert(make_pair(a - 1, b - 1));     }     for (int k = 1; k < mod && !good; k++) {       if (mod % k == 0) {         good = true;         for (auto p = set.begin(); good && p != set.end(); p++)           if (!set.count(make_pair((p->first + k) % mod, (p->second + k) % mod)))             good = false;       }     }     printf( %s n , good ?  yes  :  no );     return 0;   }