#include <bits/stdc++.h>   using namespace std;   using ll = long long;   const ll N = 105, inf = 4e18 + 4, mod = 1e9 + 7;   ll n, a2[N], num[N], ans, sum, dp[N][N * N], tmp[N][N * N], fac[N], inv[N];   bool mark[N];   ll pw(ll a, ll b) {     if (b == 0) return 1;     a %= mod;     if (b % 2 == 1) return a * pw(a, (b - 1)) % mod;     return pw((a * a % mod), (b / 2)) % mod;   }   ll choose(ll a, ll b) {     if (b > a) return 0;     if (b == 0 || b == a) return 1;     return fac[a] % mod * inv[b] % mod * inv[a - b] % mod;   }   int main() {     ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);     tmp[0][0] = 1;     fac[0] = 1;     for (ll i = 1; i < N - 1; i++) fac[i] = (fac[i - 1] * i) % mod;     inv[N - 2] = pw(fac[N - 2], mod - 2) % mod;     for (ll i = N - 3; i >= 0; i--) {       ll x = i + 1;       inv[i] = (inv[x] * (x)) % mod;     }     cin >> n;     ll y = 0;     for (ll i = 0; i < n; i++) {       cin >> a2[i];       if (!mark[a2[i]]) {         mark[a2[i]] = 1;         y++;       }       num[a2[i]]++;       sum += a2[i];       for (ll j = 0; j < n; j++) {         for (ll k = a2[i]; k <= sum; k++) {           dp[j + 1][k] = tmp[j][k - a2[i]];         }       }       for (ll j = 0; j <= n; j++) {         for (ll k = 0; k <= sum; k++) {           (tmp[j][k] += dp[j][k]) % mod;           dp[j][k] = 0;         }       }     }     if (y < 3) {       cout << n << endl;       return 0;     }     for (ll i = 100; i >= 1; i--) {       for (ll j = num[i]; j > 0; j--) {         if (choose(num[i], j) != tmp[j][j * i]) continue;         ans = max(ans, j);       }     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   int a[100001], n;   int main() {     int i, h;     scanf( %d n , &n);     for (i = 1; i <= n; ++i) scanf( %d n , &a[i]);     h = a[1];     for (i = 2; i <= n; ++i)       if (a[i - 1] < a[i])         h += a[i] - a[i - 1] + 1;       else         h += a[i - 1] - a[i] + 1;     h += n;     printf( %d , h);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int cnt[15];   int s[15];   char c[1 << 20];   int need[15];   int digits(int first) { return !first ? 0 : 1 + digits(first / 10); }   int main(void) {     int n;     string str;     cin >> (c + 1) >> str;     n = strlen(c + 1);     for (auto it : str) ++need[it -  0 ];     for (int i = 1; i <= n; ++i) ++cnt[c[i] -  0 ];     for (int nr = 1; nr < n; ++nr)       if (digits(nr) + nr == n) {         for (int i = 0; i <= 9; ++i) s[i] = cnt[i];         int sum = nr;         while (sum) --s[sum % 10], sum /= 10;         int can = 1;         for (int i = 0; i <= 9; ++i)           if (s[i] < need[i]) can = 0;         int prim = 1;         for (int i = 0; i <= 9; ++i) s[i] -= need[i];         for (; prim <= 9; ++prim)           if (s[prim] || (prim == str[0] -  0  && !s[prim])) break;         if (prim == 10) can = 0;         if (can) {           string ans1 =   , ans2 =   ;           int ct = 0;           while (ct + 1 < str.length() && str[ct] == str[ct + 1]) ++ct;           int after = -1;           if (ct + 1 >= str.length() || str[ct] > str[ct + 1])             after = 0;           else             after = 1;           string str1 = str, str2 = str;           if (prim == str[0] -  0 ) {             ans1 += str1;             str1 =   ;           }           for (int i = 0; i <= 9; ++i) cnt[i] -= need[i];           ans2 += prim +  0 ;           int sum = nr;           while (sum) --cnt[sum % 10], sum /= 10;           --cnt[prim];           for (int i = 0; i <= 9; ++i)             while (s[i] > 0) --s[i], ans1 += i +  0 ;           for (int i = 0; i <= 9; ++i) {             if (!str2.empty()) {               if (after && i > str2[0] -  0 )                 ans2 += str2, str2 =   ;               else if (!after && i >= str2[0] -  0 )                 ans2 += str2, str2 =   ;             }             while (cnt[i] > 0) --cnt[i], ans2 += i +  0 ;           }           for (int i = 0; i <= 9; ++i)             if (cnt[i] < 0) ans2 =   ;           if (ans1.length() == ans2.length())             cout << min(ans1, ans2) <<   n ;           else {             if (ans2 ==   )               cout << ans1 <<   n ;             else               cout << ans2 <<   n ;           }           return 0;         }       }     assert(cnt[0] == 1 && cnt[1] == 1 && n == 2);     cout <<  0 n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 5;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n, p;     string s;     bool f = 0;     cin >> n >> p >> s;     s =      + s;     for (int i = n + 1; i > 1; i--) {       for (char j = s[i] + 1; j <  a  + p; j++) {         if (j != s[i - 1] && j != s[i - 2]) {           f = 1;           s[i] = j;           for (int k = i + 1; k <= n + 1; k++) {             char ch =  a ;             for (; ch <  a  + p; ch++) {               if (ch != s[k - 1] && ch != s[k - 2]) break;             }             s[k] = ch;           }         }         if (f) break;       }       if (f) break;     }     if (f) {       for (int i = 2; i < s.size(); i++) cout << s[i];       cout <<   n ;     } else       cout <<  NO n ;   }


#include <bits/stdc++.h>   using namespace std;   struct unionfind_t {     vector<int> parent, rank;     unionfind_t(int n) : parent(n), rank(n, 0) {       iota(parent.begin(), parent.end(), 0);     }     int find(int v) {       if (parent[v] == v) return v;       return parent[v] = find(parent[v]);     }     int join(int a, int b) {       a = find(a), b = find(b);       if (a == b) return a;       if (rank[a] > rank[b]) swap(a, b);       parent[a] = b;       if (rank[a] == rank[b]) ++rank[b];       return b;     }   };   int main() {     int n, m;     scanf( %d %d , &n, &m);     struct edge_t {       int a, b, value;     };     vector<edge_t> edges(m);     for (int i = 0; i < m; ++i) {       scanf( %d %d %d , &edges[i].a, &edges[i].b, &edges[i].value);       --edges[i].a, --edges[i].b;     }     unionfind_t uf(n);     vector<int> node_count(n, 1);     vector<int> edge_count(n, 0);     sort(edges.rbegin(), edges.rend(),          [](const edge_t &a, const edge_t &b) { return a.value < b.value; });     int result = 0;     for (const edge_t &ed : edges) {       int a = uf.find(ed.a), b = uf.find(ed.b);       bool should_add;       if (a == b) {         should_add = (edge_count[a] + 1 <= node_count[a]);       } else {         should_add =             (edge_count[a] + 1 + edge_count[b] <= node_count[a] + node_count[b]);       }       if (should_add) {         int id;         if (a != b) {           id = uf.join(a, b);           edge_count[id] = edge_count[a] + edge_count[b];           node_count[id] = node_count[a] + node_count[b];         } else {           id = a;         }         ++edge_count[id];         result += ed.value;       }     }     printf( %d n , result);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct edge {     int v, nxt;   } e[2050];   int ecnt;   int n, m;   int totdep;   int pw[2050];   map<int, int> head;   map<int, bool> has_fa;   map<int, int> sz;   map<int, bool> vis;   void adde(int u, int v) {     e[++ecnt].v = v;     e[ecnt].nxt = head[u];     head[u] = ecnt;   }   int getdep(int pos) { return pos == 0 ? 0 : getdep(pos / 2) + 1; }   int getsz(int pos) {     int curdep = getdep(pos);     int tmp = curdep;     int lc = pos, rc = pos;     while (curdep < totdep) {       curdep++;       lc = lc << 1;       rc = rc << 1 | 1;     }     if (n < lc)       return pw[totdep - tmp - 1];     else if (n > rc)       return pw[totdep - tmp];     else       return pw[totdep - tmp - 1] + n - lc + 1;   }   int us[2050], vs[2050];   int seq[2050], scnt;   long long ans;   const int mod = 1000000007;   void mark(int pos) {     while (pos / 2) {       if (has_fa[pos]) return;       has_fa[pos] = 1;       seq[++scnt] = pos;       pos = pos / 2;     }   }   void dfs_sz(int pos) {     sz[pos] = getsz(pos);     if (has_fa[pos << 1]) dfs_sz(pos << 1), sz[pos] -= getsz(pos << 1);     if (has_fa[pos << 1 | 1])       dfs_sz(pos << 1 | 1), sz[pos] -= getsz(pos << 1 | 1);   }   int cur;   void dfs_solv(int pos) {     vis[pos] = 1;     ans += 1ll * cur * sz[pos] % mod;     ans %= mod;     if (!vis[pos << 1] && has_fa[pos << 1]) dfs_solv(pos << 1);     if (!vis[pos << 1 | 1] && has_fa[pos << 1 | 1]) dfs_solv(pos << 1 | 1);     if (!vis[pos >> 1] && (pos >> 1)) dfs_solv(pos >> 1);     for (int i = head[pos]; i; i = e[i].nxt) {       int v = e[i].v;       if (!vis[v]) dfs_solv(v);     }     vis[pos] = 0;   }   int main() {     scanf( %d%d , &n, &m);     if (m == 0) {       printf( %lld n , n * 1ll * n % mod);       return 0;     }     seq[++scnt] = 1;     totdep = getdep(n);     pw[0] = 1;     for (int i = 1; i <= 1000; ++i) pw[i] = pw[i - 1] * 2 + 1;     for (int i = 1; i <= m; ++i) {       scanf( %d%d , &us[i], &vs[i]);       mark(us[i]);       mark(vs[i]);       adde(us[i], vs[i]);       adde(vs[i], us[i]);     }     dfs_sz(1);     for (int i = 1; i <= scnt; ++i) {       cur = sz[seq[i]];       dfs_solv(seq[i]);     }     printf( %lld n , ans);   }


#include <bits/stdc++.h>   using namespace std;   #define int long long   int P = 1000000007;   #define F first   #define S second   #define pb push_back   #define mp make_pair      void solve () {    int n, c; cin >> n >> c; int a[n], b[n-1];    int mi=INT_MAX;    for (int i=0; i<n; ++i) {cin >> a[i];}    for (int i=0; i<n-1; ++i) {cin >> b[i];}    int cum=0, day=0;    for (int i=0; i<n; ++i) {     int k = (c-cum+a[i]-1)/a[i]+day;     mi=min(mi,k);     if (i==n-1) {break;}     int x=(b[i]-cum+a[i]-1)/a[i];     day+=x+1;     cum=cum+x*a[i]-b[i];     // cout << i <<     << cum <<     << day <<     << mi <<   n ;    }    cout << mi <<   n ;   }      signed main() {       ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);       #ifndef ONLINE_JUDGE        freopen( input.txt ,  r , stdin);        freopen( output.txt ,  w , stdout);    #endif       int t = 1;       cin >> t;       for (int _t=0; _t<t;++_t) {           // cout <<  Case #  << _t+1 <<  :  ;           solve();       }   }


#include <bits/stdc++.h>   using namespace std;   string tostr(long long x) {     stringstream ss;     ss << x;     return ss.str();   }   long long toint(string &s) {     stringstream ss;     ss << s;     long long x;     ss >> x;     return x;   }   int main() {     long long a1, a2, tmp, arr[20], sum, j;     string st1;     scanf( %lld %lld , &a2, &a1);     st1 = tostr(a1);     reverse(st1.begin(), st1.end());     tmp = a2 + toint(st1);     printf( %lld , tmp);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int T;     cin >> T;     for (int P = 0; P < T; P++) {       int n, k, d;       cin >> n >> k >> d;       vector<int> ar(n);       map<int, int> s;       int count = 0;       for (int i = 0; i < n; i++) {         int tmp = 0;         cin >> tmp;         if (s.find(tmp) == s.end()) {           s.insert(pair<int, int>(tmp, count));           tmp = count;           count++;         } else {           tmp = s.find(tmp)->second;         }         ar[i] = tmp;       }       vector<int> b(count, 0);       int price = 0;       for (int i = 0; i < d; i++) {         if (b[ar[i]] == 0) {           price++;         }         b[ar[i]]++;       }       int min_price = price;       for (int i = d; i < n; i++) {         if (b[ar[i - d]] == 1) {           price--;         }         b[ar[i - d]]--;         if (b[ar[i]] == 0) {           price++;         }         b[ar[i]]++;         min_price = min(min_price, price);       }       cout << min_price <<   n ;     }     return 0;   }


#include <iostream>   #include <vector>   #include <string>   #include <cstring>   #include <cmath>   #include <climits>   #include <algorithm>   #include <map>   #include <stack>   #include <unordered_map>   #include <set>   #include <unordered_set>   #include <utility>   #include <iomanip>      using namespace std;   typedef long long int ll;   ll pw(ll a, ll b, ll m){    ll ans=1;    while(b>0){     if(b&1) ans=(ans*a)%m;     a=(a*a)%m;     b>>=1;    }    return ans;   }      ll gcd(ll a,ll b){    if(a==0) return b;    return gcd(b % a , a);   }      bool comp(const pair<int,int> &a,const pair<int,int> &b){       return a.second>b.second;   }      ll n,m;   set<ll> has;   vector<ll> input;      void solve(ll l,ll r){    ll sum=0;    for(ll i=l;i<r+1;i++){     sum+=input[i];    }    has.insert(sum);    ll mid=(input[l]+input[r])/2;    ll pos=-1;    for(ll i=l;i<r+1;i++){     if(input[i]<=mid){      pos=i;     }     else{      break;     }    }    if(pos==-1 || pos==r) return;    solve(l,pos);    solve(pos+1,r);   }   void randomevent(){    ll right=n;    while(right>=0 && input[right-1]==right){     right--;    }    double f=(right>0) ? 1:0;    for(ll i=0;i<m;i++){     ll r;cin>>r;     double p;cin>>p;     if(r>=right){      f*=(1-p);     }    }    cout<<fixed<<setprecision(12)<<(1-f)<<endl;   }            int main(){   #ifndef ONLINE_JUDGE       freopen( input.txt , r , stdin);       freopen( output.txt , w , stdout);   #endif           int t;cin>>t;       while(t--){        cin>>n>>m;        for(ll i=0;i<n;i++){         ll p;cin>>p;         input.push_back(p);        }        randomevent();        input.clear();          }   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast,no-stack-protector )   #pragma GCC target( avx )   int V[100000];   float x;   int main() {     int n, m, l, r, A, T;     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; ++i) scanf( %d , &V[i]);     while (m--) {       scanf( %d%d%d%f , &T, &l, &r, &x);       if (T == 1)         for (int i = l; i <= r; ++i) V[i] -= V[i] > x ? x : 0;       else {         A = 0;         for (int i = l; i <= r; ++i) V[i] == x ? ++A : 0;         printf( %d n , A);       }     }   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 998244353;   const long long N = 5e2 + 1;   const long long M = 1e6 + 1;   long long dp[2 * N][2 * N], min1[2 * N][2 * N], ar[2 * N], ar1[M];   bool check[2 * N][2 * N];   vector<long long> occur[N];   long long solve(long long l, long long r) {     if (l > r) {       return 1;     }     if (check[l][r]) {       return dp[l][r];     }     long long y = min1[l][r];     if (occur[y][0] < l || occur[y][occur[y].size() - 1] > r) {       check[l][r] = true;       return 0;     }     if (l == r) {       check[l][r] = true;       dp[l][r] = 1;       return dp[l][r];     }     check[l][r] = true;     long long tich = 1, sum = solve(l, occur[y][0] - 1),               sum1 = solve(occur[y][occur[y].size() - 1] + 1, r), i;     if (l <= occur[y][0] - 1) {       sum *= 2;     }     if (occur[y][occur[y].size() - 1] + 1 <= r) {       sum1 *= 2;     }     for (i = 0; i + 1 < occur[y].size(); i++) {       tich *= solve(occur[y][i] + 1, occur[y][i + 1] - 1);       tich %= mod;     }     for (i = l; i < occur[y][0] - 1; i++) {       sum += solve(l, i) * solve(i + 1, occur[y][0] - 1);       sum %= mod;     }     for (i = occur[y][occur[y].size() - 1] + 1; i < r; i++) {       sum1 += solve(occur[y][occur[y].size() - 1] + 1, i) * solve(i + 1, r);       sum1 %= mod;     }     dp[l][r] = ((sum * sum1) % mod * tich) % mod;     return dp[l][r];   }   signed main() {     ios::sync_with_stdio(0);     cin.tie(0);     long long n, m, i, j, k, l = 0;     cin >> n >> m;     ar1[0] = -1;     for (i = 1; i <= m; i++) {       cin >> ar1[i];       if (ar1[i] != ar1[i - 1]) {         l++;         ar[l] = ar1[i];         if (l > 2 * n + 1) {           cout << 0;           exit(0);         }       }     }     n = l;     for (i = 1; i <= n; i++) {       min1[i][i] = ar[i];       occur[ar[i]].push_back(i);       for (j = i + 1; j <= n; j++) {         min1[i][j] = min(min1[i][j - 1], ar[j]);       }     }     cout << solve(1, n);   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e6 + 11;   string s;   bool vis[maxn];   int n;   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     cin >> s;     n = s.length();     vector<pair<int, int> > vec, tmp;     for (int i = 0; i < n; i++) {       if (vec.empty() || s[vec.back().first] != s[i])         vec.emplace_back(i, i);       else {         pair<int, int> p = vec.back();         vec.pop_back();         vec.emplace_back(p.first, i);       }     }     int ans = 0;     while (vec.size() > 1) {       for (int i = 0; i < (int)(vec).size(); i++) {         int sub = 2 - (i == 0 || i == (int)(vec).size() - 1);         if (vec[i].second >= vec[i].first + sub) {           if (tmp.empty() || s[tmp.back().first] != s[vec[i].first]) {             vec[i].second -= sub;             tmp.push_back(vec[i]);           } else {             pair<int, int> p = tmp.back();             tmp.pop_back();             p.second += vec[i].second - vec[i].first + 1 - sub;             tmp.push_back(p);           }         }       }       ans++;       tmp.swap(vec);       tmp.clear();     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   int n, m, k;   int main() {     long long ans = 1;     scanf( %d%d%d , &n, &m, &k);     if (k == n) {       int mid = k / 2 + (k & 1);       for (int i = 0; i < mid; ++i) ans = (ans * m) % 1000000007;       printf( %I64d , ans);     } else if (!(k % 2) && k < n)       printf( %d , m);     else if (k == 1 || k > n) {       for (int i = 0; i < n; ++i) ans = (ans * m) % 1000000007;       printf( %I64d , ans);     } else {       printf( %d , m * m);     }   }


#include <bits/stdc++.h>   using namespace std;   const int M = 1000000007;   const int MM = 998244353;   const long double PI = acos(-1);   long long power(long long b, long long e, long long m) {     if (e == 0) return 1;     if (e & 1) return b * power(b * b % m, e / 2, m) % m;     return power(b * b % m, e / 2, m);   }   long long power(long long b, long long e) {     if (e == 0) return 1;     if (e & 1) return b * power(b * b, e / 2);     return power(b * b, e / 2);   }   template <typename T, typename U>   static inline void amin(T &x, U y) {     if (y < x) x = y;   }   template <typename T, typename U>   static inline void amax(T &x, U y) {     if (x < y) x = y;   }   template <typename T, typename U>   ostream &operator<<(ostream &os, const pair<T, U> &p) {     return os <<  (  << p.first <<  ,  << p.second <<  ) ;   }   const int N = 100005;   vector<int> zFunction(string &s) {     int n = (long long)s.size(), l, r, i;     vector<int> z(n);     z[0] = n;     l = r = 0;     for (i = 1; i < n; ++i) {       if (i <= r) z[i] = min(r - i + 1, z[i - l]);       while (i + z[i] < n && s[z[i]] == s[z[i] + i]) ++z[i];       if (i + z[i] - 1 > r) {         l = i;         r = i + z[i] - 1;       }     }     return z;   }   int _runtimeTerror_() {     string s, t;     cin >> s >> t;     int n = (long long)s.size(), m = (long long)t.size();     string u = t +  #  + s;     vector<int> z = zFunction(u);     vector<int> start(n + 10, false);     for (int i = m + 1; i < n + m + 1; ++i) {       if (z[i] == m) start[i - m - 1] = 1;     }     int last = -1;     long long ans = 0;     vector<long long> suf(n + 10, 0);     vector<long long> val(n + 10, 0);     suf[n + 1] = 0;     val[n + 1] = 0;     for (int i = n - 1; i >= 0; --i) {       suf[i] = suf[i + 1];       val[i] = val[i + 1] + suf[i];       if (start[i] == 1) last = i;       if (last == -1) continue;       long long u = (n - 1 - (last + m - 1) + 1);       val[i] += u;       val[i] %= M;       suf[i] += u;       suf[i] %= M;       ans += u;       ans %= M;       suf[i] += val[last + m];       suf[i] %= M;       val[i] += val[last + m];       val[i] %= M;       ans += val[last + m];       ans %= M;     }     cout << ans <<   n ;     return 0;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int TESTS = 1;     while (TESTS--) _runtimeTerror_();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, cnt[200200], mx = 0, val = 0, arr[200200], pr[200200], a[200200], ans;   vector<int> lst, bd;   void tryBuild(int i) {     vector<int> lPos(400400, -1);     lPos[200000] = 0;     for (int i1 = 1; i1 <= n; i1++) {       if (a[i1] == i) {         arr[i1] = 1;       } else {         if (a[i1] != val) {           arr[i1] = 0;         }       }       pr[i1] = pr[i1 - 1] + arr[i1];       if (lPos[pr[i1] + 200000] == -1) {         lPos[pr[i1] + 200000] = i1;       } else {         ans = max(ans, i1 - lPos[pr[i1] + 200000]);       }     }   }   vector<vector<int> > pose(200200);   int pref[200200];   int num[200200];   void solve() {     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> a[i];       cnt[a[i]]++;       if (cnt[a[i]] > mx) {         mx = cnt[a[i]];         val = a[i];       }       pose[a[i]].push_back(i);     }     for (int i = 1; i <= n; i++) {       if (cnt[i] >= (int)sqrt(n)) {         lst.push_back(i);       } else {         bd.push_back(i);       }     }     for (int i = 1; i <= n; i++) {       pref[i] = pref[i - 1];       if (a[i] == val) {         arr[i] = -1;         pref[i]++;         num[pref[i]] = i;       }     }     for (auto i : lst) {       if (i == val) {         continue;       }       tryBuild(i);     }     for (auto ch : bd) {       if (ch == val) {         continue;       }       for (int i = 0; i < pose[ch].size(); i++) {         int x = pose[ch][i];         for (int i1 = pose[ch].size() - 1; i1 >= i; i1--) {           int y = pose[ch][i1];           int cnt = i1 - i + 1 - (pref[y] - pref[x - 1]);           if (cnt < 0) {             continue;           }           int be = pref[x - 1];           int all = pref[y];           for (int i2 = 0; i2 <= cnt; i2++) {             int l = (be < i2 ? 1 : num[be - i2] + 1);             int r = (cnt - i2 + all >= mx ? n : num[cnt - i2 + all + 1] - 1);             ans = max(ans, r - l + 1);           }         }       }     }     cout << ans;   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     int q;     q = 1;     while (q != 0) {       solve();       --q;     }   }


#include <bits/stdc++.h>   using namespace std;   using cat = long long;   int main() {     cin.sync_with_stdio(0);     cin.tie(0);     cout << fixed << setprecision(10);     int W, N, M;     cin >> W >> N >> M;     vector<int> A(1 << W, 0);     for (int i = 0; i < N; i++) {       int a;       cin >> a;       A[a]++;     }     vector<vector<int> > B(1 << W, vector<int>(1 << W, 0));     for (int i = 0; i < (1 << W); i++)       for (int j = 0; j < (1 << W); j++) B[i][i & j] += A[j];     for (int i = 0; i < M; i++) {       string s;       cin >> s;       int mask[6] = {};       for (int j = 0; j < W; j++) {         if ( O  == s[j]) mask[0] |= 1 << (W - 1 - j);         if ( a  == s[j]) mask[1] |= 1 << (W - 1 - j);         if ( X  == s[j]) mask[2] |= 1 << (W - 1 - j);         if ( x  == s[j]) mask[3] |= 1 << (W - 1 - j);         if ( A  == s[j]) mask[4] |= 1 << (W - 1 - j);         if ( o  == s[j]) mask[5] |= 1 << (W - 1 - j);       }       int vc = mask[1] | mask[3] | mask[5];       int vm = mask[2] | mask[3] | mask[5];       int im = (1 << W) - 1 - mask[4], m = mask[4] | mask[5];       int ans = 0;       for (int j = 0; j < (1 << W); j++)         if ((j & (mask[0] | mask[1])) == mask[1]) {           int mask_cur = (j & m) ^ im;           int val_cur = vc ^ (j & vm);           ans += B[mask_cur][val_cur] * A[j];         }       cout << ans <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }   long long powmod(long long a, long long b, long long MOD) {     long long ans = 1;     while (b) {       if (b % 2) ans = ans * a % MOD;       a = a * a % MOD;       b /= 2;     }     return ans;   }   const int N = 2e5 + 11;   int main() {     ios::sync_with_stdio(false);     int a;     cin >> a;     int b = a;     int cnt = 0;     while (a % 10) {       cnt++;       a++;     }     int p = 0;     while (b % 10) {       b--;       p++;     }     if (cnt <= p)       cout << a;     else       cout << b;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double pi = acos(-1.0);   int main() {     long double x1, y1, r1, x2, y2, r2;     while (~scanf( %Lf%Lf%Lf%Lf%Lf%Lf , &x1, &y1, &r1, &x2, &y2, &r2)) {       long double de = (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);       long double d = sqrt(de);       if (d >= (r1 + r2)) {         printf( 0.00000000000000000000 n );         continue;       }       if (d <= fabs(r1 - r2)) {         printf( %.20Lf n , pi * min(r1, r2) * min(r1, r2));         continue;       }       long double s1 = acos((r1 * r1 + de - r2 * r2) / (2.0 * r1 * d));       long double s2 = acos((r2 * r2 + de - r1 * r1) / (2.0 * r2 * d));       long double v1 = s1 * r1 * r1;       long double ss1 = 1.0 / 2.0 * r1 * r1 * sin(2.0 * s1);       long double v2 = s2 * r2 * r2;       long double ss2 = 1.0 / 2.0 * r2 * r2 * sin(2.0 * s2);       printf( %.20Lf n , v1 + v2 - ss1 - ss2);     }   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   template <class t>   using V = vector<t>;   constexpr ll INF = 1e16;   int n, m;   ll dp[1502][1502];   int tab[1502][1502];   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; ++i)       for (int k = 1; k <= m; ++k) scanf( %d , &tab[i][k]);     for (int i = 1; i <= n; ++i)       for (int k = 1; k <= m; ++k) tab[i][k] += tab[i][k - 1];     for (int i = 1; i <= n + 1; ++i)       for (int k = 0; k <= m + 1; ++k) dp[i][k] = -INF;     for (int i = 1; i <= n; ++i) {       if (i & 1) {         for (int k = 1; k <= m; ++k)           dp[i - 1][k] = max(dp[i - 1][k - 1], dp[i - 1][k]);         for (int k = 2; k <= m; ++k) dp[i][k] = dp[i - 1][k - 1] + tab[i][k];       } else {         for (int k = m; k >= 1; --k)           dp[i - 1][k] = max(dp[i - 1][k], dp[i - 1][k + 1]);         for (int k = 1; k <= m - 1; ++k) dp[i][k] = dp[i - 1][k + 1] + tab[i][k];       }     }     ll res = -INF;     for (int i = 1; i <= m; ++i) res = max(res, dp[n][i]);     printf( %lld n , res);   }


#include <bits/stdc++.h>   using namespace std;   bool alph[26] = {1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1,                    0, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0};   bool check(string s) {     for (int i = 0; i < s.length(); i++)       if (!alph[s[i] -  A ]) return false;     return true;   }   int main() {     string s;     cin >> s;     string t = s;     reverse(s.begin(), s.end());     if (s == t && check(s))       cout <<  YES ;     else       cout <<  NO ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long tests, a, b, c;     cin >> tests;     while (tests--) {       cin >> a >> b >> c;       vector<long long> v;       v.push_back(a);       v.push_back(b);       v.push_back(c);       sort(v.begin(), v.end());       a = v[0];       b = v[1];       c = v[2];       if (a + c <= b)         cout << a + c <<   n ;       else if (a + c > b) {         cout << (a + b + c) / 2 <<   n ;       }     }   }


#include <bits/stdc++.h>   const int MAXN = 200000;   using namespace std;   inline int read() {     int x = 0, w = 1;     char c =    ;     while (c <  0  || c >  9 ) {       c = getchar();       if (c ==  - ) w = -1;     }     while (c >=  0  && c <=  9 ) {       x = (x << 1) + (x << 3) + (c ^ 48);       c = getchar();     }     return x * w;   }   int n, a[MAXN + 5];   void init() {     n = read();     for (int i = 1; i <= n; ++i) a[i] = read();   }   int mx, mxi, ans[MAXN + 5], len;   map<int, int> dp;   int main() {     init();     for (int i = 1; i <= n; ++i) {       dp[a[i]] = dp[a[i] - 1] + 1;       if (dp[a[i]] > mx) {         mx = dp[a[i]];         mxi = a[i];       }     }     printf( %d n , mx);     for (int i = n; i > 0; --i)       if (mxi == a[i]) {         --mxi;         ans[++len] = i;       }     for (int i = len; i > 0; --i) printf( %d  , ans[i]);     printf(  n );     return 0;   }


#include <bits/stdc++.h>      using namespace std;      int main()   {      int t;      cin>>t;      while(t--)      {          int n,m;          int count=0;          cin>>n>>m;          map <int, int > ma;          int a[n],b[m];          for(int i=0;i<n;i++)          {              cin>>a[i];              ma[a[i]]++;          }          for(int i=0;i<m;i++)          {              cin>>b[i];              ma[b[i]]++;          }          for(auto i=ma.begin();i!=ma.end();i++)          {              if(i->second>1)              {                  count=count+2;              }          }          cout<<count/2<<  n ;      }          return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   struct Line {     int k, b;   } a[100100];   struct Fraction {     int x, y;   } b[100100];   int gcd(int x, int y) {     if (x == 0)       return y;     else       return gcd(y % x, x);   }   bool cmp(const Fraction &t1, const Fraction &t2) {     if (t1.x != t2.x) return (t1.x < t2.x);     return (t1.y < t2.y);   }   int main() {     scanf( %d , &n);     int tot = 0;     for (int i = 1; i <= n; ++i) {       scanf( %d%d , &a[i].k, &a[i].b);       if (a[i].k != 0) {         b[++tot].x = -a[i].b;         b[tot].y = a[i].k;         if (b[tot].x < 0) {           b[tot].x *= -1;           b[tot].y *= -1;         }         int g = gcd(abs(b[tot].x), abs(b[tot].y));         b[tot].x /= g;         b[tot].y /= g;         if (b[tot].x == 0) b[tot].y = 1;       }     }     sort(b + 1, b + tot + 1, cmp);     int ans = 0;     for (int i = 1; i <= tot; ++i) {       if (i == 1 || b[i].x != b[i - 1].x || b[i].y != b[i - 1].y) ans++;     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 3e5 + 10;   int n, a[N], b[N], c[N];   int Log[N];   int l[19][N], r[19][N];   struct rmq {     int st[N][19], val[N];     int type;     inline int Max(int x, int y) { return (val[x] < val[y]) ? y : x; }     void build(int *b, int n, int _type) {       type = _type;       for (int i = 1; i <= n; i++) st[i][0] = i, val[i] = type * b[i];       for (int j = 1; j <= Log[n]; j++) {         for (int i = 1; i + (1 << j) - 1 <= n; i++)           st[i][j] = Max(st[i][j - 1], st[i + (1 << j - 1)][j - 1]);       }     }     inline int query(int l, int r) {       int k = Log[r - l + 1];       return Max(st[l][k], st[r - (1 << k) + 1][k]);     }   } rmq_l, rmq_r;   int main() {     scanf( %d , &n);     for (int i = 2; i <= 3 * n; i++) Log[i] = Log[i >> 1] + 1;     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);       a[i + n] = a[i + n * 2] = a[i];     }     if (n == 1) return puts( 0 ), 0;     for (int i = 1; i <= 3 * n; i++) {       b[i] = max(1, i - a[i]);       c[i] = min(3 * n, i + a[i]);     }     for (int i = 0; i <= Log[3 * n]; i++) r[i][3 * n] = 3 * n, l[i][1] = 1;     for (int i = 1; i <= 3 * n; i++) {       l[0][i] = b[i];       r[0][i] = c[i];     }     rmq_l.build(l[0], n * 3, -1);     rmq_r.build(r[0], n * 3, 1);     for (int i = 1; i <= Log[3 * n]; i++)       for (int j = 1; j <= 3 * n; j++) {         int posl = rmq_l.query(l[i - 1][j], r[i - 1][j]);         int posr = rmq_r.query(l[i - 1][j], r[i - 1][j]);         l[i][j] = min(l[i - 1][posl], l[i - 1][posr]);         r[i][j] = max(r[i - 1][posl], r[i - 1][posr]);       }     for (int j = n + 1; j <= n * 2; j++) {       int u = j, v = j;       int ans = 0;       for (int i = Log[3 * n]; i >= 0; i--) {         if (max(r[i][v], r[i][u]) - min(l[i][u], l[i][v]) + 1 >= n) continue;         int nu = rmq_l.query(l[i][u], r[i][v]);         int nv = rmq_r.query(l[i][u], r[i][v]);         u = nu;         v = nv;         ans += 1 << i;       }       ans++;       printf( %d  , ans);     }     puts(  );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     scanf( %d , &n);     char str[105];     scanf( %s , str);     int l = 0, r = 0, u = 0, d = 0;     for (int i = 0; i < n; i++)       if (str[i] ==  L )         l++;       else if (str[i] ==  R )         r++;       else if (str[i] ==  U )         u++;       else if (str[i] ==  D )         d++;     printf( %d n , min(l, r) * 2 + min(u, d) * 2);   }


#include <bits/stdc++.h>   using namespace std;   string a, b, c;   long long n, x, y, z;   pair<long long, long long> f[2000];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n >> a >> b >> c;     for (auto i : a) {       f[i].first++;       x = max(x, f[i].first);     }     for (auto i : b) {       if (f[i].second != 2) f[i] = {0, 2};       f[i].first++;       y = max(y, f[i].first);     }     for (auto i : c) {       if (f[i].second != 3) f[i] = {0, 3};       f[i].first++;       z = max(z, f[i].first);     }     if (n == 1) {       if (a.size() == x) a.erase(0, 1);       if (b.size() == y) b.erase(0, 1);       if (c.size() == z) c.erase(0, 1);     }     x = min(x + n, (long long)a.size());     y = min(y + n, (long long)b.size());     z = min(z + n, (long long)c.size());     if (x > y && x > z) return cout <<  Kuro , 0;     if (y > x && y > z) return cout <<  Shiro , 0;     if (z > x && z > y) return cout <<  Katie , 0;     cout <<  Draw ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   namespace {   int CC_;   const double EPS = 1E-9;   const double PI = 2 * acos(0.0);   const long long MOD = 1000000007;   template <class T>   void DA(T i, T e) {     while (i != e) {       cout <<  Con>>(   << ++CC_ <<   )   << *i++ <<   n ;     }   }   template <class T>   void DA(T* x, int l) {     for (int i = 0; i < l; i++) cout <<  [  << i <<  ]>>   << x[i] <<   n ;   }   template <class T>   inline void sary(T* st, T* nd) {     while (st < nd) cin >> *st++;   }   template <class T>   void tobin(T n, char* bin) {     int pos = 1 << ((int)log2(n));     while (pos >= 1) {       if ((n & pos) == 0)         *bin =  0 ;       else         *bin =  1 ;       pos >>= 1;       bin++;     }     *bin =   0 ;   }   template <class T>   int strOccur(string& s, T& tgt) {     int oc = 0, p = s.find(tgt);     while (p != string::npos) {       p = s.find(tgt, p + 1);       oc++;     }     return oc;   }   template <class T>   inline T LCM(T x, T y) {     return ((x * y) / __gcd(x, y));   }   long long todec(string& num, int b) {     long long dec = num[0] - (isupper(num[0]) ?  A  - 10 :  0 );     for (int i = 1; num[i]; i++) {       if (num[i] >=  A  && num[i] <=  Z )         num[i] -=  A  - 10;       else         num[i] -=  0 ;       dec *= b;       dec += num[i];     }     return dec;   }   int bigMod(int b, int e, int m) {     if (e == 0) return 1;     if (!(e & 1)) {       int temp = bigMod(b, e / 2, m) % m;       return (temp * temp) % m;     } else       return ((b % m) * (bigMod(b, e - 1, m)) % m) % m;   }   bool comp(const int a, const int b) { return a > b; }   }  // namespace   const int sss = 1E6;   int a[200019];   void solve(void) {     int n;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a[i];     }     int lim = n / 2;     for (int i = 0, j = n - 1; i < lim; i++, j--) {       if (i % 2 == 0) {         swap(a[i], a[j]);       }     }     for (int i = 0; i < n; i++) {       cout << a[i] <<    ;     }     cout <<   n ;     ;   }   int main(void) {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 1e5 + 10;   const long long M = 998244353;   const long double PI = acos(-1);   long long n, k;   long long a[N], d[N], mn[N] = {INT_MAX};   signed main() {     long long i, s = 0, ans = 0;     cin >> n >> k;     for (i = 1; i <= n; i++) cin >> a[i];     for (i = 1; i <= n; i++) cin >> d[i], mn[i] = min(mn[i - 1], d[i]);     for (i = n; i >= 1; i--) a[i] += a[i + 1];     if (k == 0) {       for (i = 1; i <= n; i++) ans = max(ans, a[i] - d[i]);       cout << ans;     } else if (k == 1) {       for (i = 2; i <= n; i++)         ans = max(ans, max(0ll, a[1] - a[i] - mn[i - 1]) + max(0ll, a[i] - d[i]));       for (i = 1; i < n; i++)         ans = max(ans, a[1] - (a[i + 1] - a[i + 2]) - d[1] +                            max(0ll, a[i + 1] - a[i + 2] - d[i + 1]));       cout << ans;     } else       cout << max({0ll, a[1] - mn[n - 1], a[n] - d[n]});     return 0;   }


#include <bits/stdc++.h>   using namespace std;   multiset<int64_t> h, hl, v, vl;   int main() {     cin.tie(0), ios_base::sync_with_stdio(0);     int W, H, q, r, c, nr, nc, pr, pc;     auto tmp = h.begin();     char t;     cin >> W >> H >> q;     int64_t mv = H, mh = W;     h.insert(0);     h.insert(W);     hl.insert(W);     v.insert(0);     v.insert(H);     vl.insert(H);     while (q--) {       cin >> t;       if (t ==  H ) {         cin >> r;         tmp = v.insert(r);         nr = *next(tmp);         pr = *prev(tmp);         vl.erase(vl.find(nr - pr));         vl.insert(r - pr);         vl.insert(nr - r);       } else {         cin >> c;         tmp = h.insert(c);         nc = *next(tmp);         pc = *prev(tmp);         hl.erase(hl.find(nc - pc));         hl.insert(c - pc);         hl.insert(nc - c);       }       cout << *prev(hl.end()) * *(prev(vl.end())) <<   n ;     }     return 0;     ;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     scanf( %d , &n);     char str[1000][1000];     int i;     for (i = 0; i < n; i++) {       scanf(  %[^ n] , str[i]);     }     int cnt = 0;     int j;     for (i = 0; i < n; i++) {       if (strcmp(str[i],  -1 ) == 0) continue;       cnt++;       int flag = 0;       for (j = i + 1; j < n; j++) {         if (strcmp(str[j],  -1 ) == 0) continue;         if (strcmp(str[i], str[j]) == 0) {           strcpy(str[j],  -1 );         }       }     }     printf( %d n , cnt);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = 1e18 + 9;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     long long n, k;     cin >> n >> k;     vector<long long> a(n);     for (long long i = 0; i < n; i++) {       cin >> a[i];     }     sort(a.begin(), a.end());     vector<long long> pref(n, 0), suf(n, 0);     for (long long i = 1, sm = a[0]; i < n; i++) {       pref[i] = a[i] * i - sm;       sm += a[i];     }     for (long long i = n - 2, sm = a[n - 1]; i >= 0; i--) {       suf[i] = sm - a[i] * (n - i - 1);       sm += a[i];     }     long long ans = INF;     for (long long i = 0, j = 0; i < n; i = j) {       for (; j < n && a[j] == a[i]; j++)         ;       long long prev = 0, forw = 0;       long long base = INF;       prev += pref[i];       prev -= i;       if (i >= k - j + i) base = min(base, prev);       forw += suf[j - 1];       forw -= (n - j);       if (n - j >= k - j + i) base = min(base, forw);       base = min(base, prev + forw);       ans = min(ans, base + k - (j - i));       if (j - i >= k) ans = 0;     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int test;     cin >> test;     while (test--) {       long long int n;       cin >> n;       long long int a[n];       for (int i = 0; i < n; i++) {         cin >> a[i];       }       long long int total_sum = 0;       for (int i = 0; i < n; i++) {         total_sum += a[i];       }       if (total_sum < 0 && n == 1) {         cout <<  YES  << endl;         continue;       } else if (total_sum < 0) {         cout <<  NO  << endl;         continue;       }       long long int sum = 0;       long long int max_so_far = 0;       long long int element = 0;       long long int element_f = 0;       for (int i = 0; i < n; i++) {         sum = sum + a[i];         element++;         if (sum <= 0) {           element = 0;           sum = 0;         } else if (sum > max_so_far) {           element_f = element;           max_so_far = sum;         }       }       if (max_so_far >= total_sum && element_f < n)         cout <<  NO  << endl;       else         cout <<  YES  << endl;     }     return 0;   }


#include <bits/stdc++.h>   const int maxn = 1e5 + 3;   int n;   int k;   int A;   int a[maxn];   int ans[maxn];   int main() {     int sum = 0;     scanf( %d%d , &n, &k);     for (int i = 1; i <= n; ++i) scanf( %d , &a[i]), sum += a[i];     if (sum % k) {       puts( No );       return 0;     }     sum /= k;     for (int i = 1; i <= n;) {       int now = 0, nowsum = 0;       while (nowsum < sum && i <= n) nowsum += a[i++], ++now;       if (nowsum > sum) {         puts( No );         return 0;       }       ans[++A] = now;     }     puts( Yes );     for (int i = 1; i < A; ++i) printf( %d  , ans[i]);     printf( %d n , ans[A]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   ifstream fi( test.txt );   ifstream fir( inp.txt );   ofstream fo( out.txt );   const long long MOD = 1e9 + 7;   const long long base = 269;   const int ooi = 1 << 30;   const int N = 1e5 + 5;   long long n, m, q, k, pos, rs, t, T, cnt, rs1;   long long maxx = -1e9, minn = 1e9;   long long a[N], b[N];   vector<long long> c[N];   int main() {     cin >> n >> k;     for (long long(i) = 0; (i) < (n); (i)++) {       cin >> a[i];     }     for (long long(i) = 0; (i) < (n); (i)++) {       cin >> b[i];       c[a[i]].push_back(b[i]);     }     for (long long(i) = 1; (i) <= (k); (i)++) {       sort(c[i].begin(), c[i].end());       if (c[i].size()) c[i].pop_back(), cnt++;     }     cnt = k - cnt;     vector<long long> ans;     for (long long(i) = 1; (i) <= (k); (i)++) {       for (long long(j) = 0; (j) < (c[i].size()); (j)++) ans.push_back(c[i][j]);     }     sort(ans.begin(), ans.end());     for (long long(i) = 0; (i) < (cnt); (i)++) rs += ans[i];     cout << rs;   }


#include <bits/stdc++.h>   using namespace std;   vector<long long> gr[200011];   vector<long long> v;   vector<long long> v1;   bool vis[200011];   queue<pair<long long, bool> > q;   long long n, m;   void bfs(long long s, bool k) {     q.push({s, k});     while (!q.empty()) {       long long node = q.front().first;       bool z = q.front().second;       q.pop();       if (vis[node]) continue;       if (z)         v.push_back(node);       else         v1.push_back(node);       vis[node] = 1;       for (int i = 0; i < gr[node].size(); i++)         if (!vis[gr[node][i]]) q.push({gr[node][i], !z});     }   }   int main() {     ios::sync_with_stdio(0);     long long q, i, x, y;     cin >> q;     while (q--) {       cin >> n >> m;       for (i = 0; i < m; i++) {         cin >> x >> y;         gr[x].push_back(y);         gr[y].push_back(x);       }       v.clear();       v1.clear();       bfs(1, 0);       if (v.size() <= n / 2) {         cout << v.size() << endl;         for (i = 0; i < v.size(); i++) cout << v[i] <<    ;         cout << endl;       } else {         cout << v1.size() << endl;         for (i = 0; i < v1.size(); i++) cout << v1[i] <<    ;         cout << endl;       }       for (i = 1; i <= n; i++) {         vis[i] = 0;         gr[i].clear();       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   using vc = vector<T>;   template <class T>   using vvc = vc<vc<T>>;   template <class T>   void mkuni(vector<T>& v) {     sort(v.begin(), v.end());     v.erase(unique(v.begin(), v.end()), v.end());   }   template <class T>   void print(T x, int suc = 1) {     cout << x;     if (suc == 1)       cout <<   n ;     else       cout <<    ;   }   template <class T>   void print(const vector<T>& v, int suc = 1) {     for (int i = 0; i < v.size(); i++)       print(v[i], i == (int)(v.size()) - 1 ? suc : 2);   }   const int INF = 0x3f3f3f3f;   const int maxn = 2e5 + 7;   const int mod = 998244353;   long long quick(long long a, long long b) {     long long ret = 1;     while (b) {       if (b & 1) ret = ret * a % mod;       a = a * a % mod;       b >>= 1;     }     return ret;   }   long long inv(long long a) { return quick(a, mod - 2); }   long long sufm[maxn], sufsum[maxn];   int p[maxn];   long long calc(int l, int r) {     long long ret = sufsum[l] - sufsum[r];     ret = (ret + mod) % mod;     ret = ret * inv(sufm[r]) % mod;     return ret;   }   int main() {     std::ios::sync_with_stdio(false);     cin.tie(nullptr);     int n;     cin >> n;     for (int i = 1; i <= n; i++) cin >> p[i];     sufm[n + 1] = 1;     for (int i = n; i >= 1; i--) {       sufm[i] = sufm[i + 1] * (100 * inv(p[i]) % mod) % mod;       sufsum[i] = (sufsum[i + 1] + sufm[i]) % mod;     }     long long ans = sufsum[1];     cout << ans << endl;   }


#include <bits/stdc++.h>      using namespace std;   #define  ll long long   #define f first   #define s second   const int N = 2e5+5;      int n , dp[N] , ans;   vector<int> adj[N];      void dfs(int node , int par)   {       vector<int> v;       for(auto ch : adj[node])       {           if (ch==par) continue;           dfs(ch , node);           v.push_back(dp[ch]+1);       }       sort(v.begin() , v.end());          if (v.size())       {           if (node != 1)           {               int mx = v.back() , mn = v[0];               if (adj[node].size() > 1) ans = max(ans , mx+1);                  dp[node] = mn;           }           else           {               int mx = v.back() , mn;               v.pop_back();               if (v.size()) mn = v.back();               else mn = -1; //second maximum                  ans = max(ans , mn+1);               ans = max(ans , mx);               dp[node] = mx;           }       }   }      void clear()   {       ans = 0;       for(int i=1; i<=n; i++)           adj[i].clear() , dp[i] = 0;   }      int main()   {       ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);          int t;       cin >> t;       while(t--)       {           cin >> n;           for(int i=1; i<n; i++)           {               int v,u;               cin >> v >> u;               adj[v].push_back(u) , adj[u].push_back(v);           }              dfs(1,1);              cout << ans <<   n ;              clear();       }             return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int n;     cin >> n;     int a[n][2];     int l = 0, r = 0;     for (int i = 0; i < n; i++) {       cin >> a[i][0] >> a[i][1];       l += a[i][0];       r += a[i][1];     }     int ans = abs(l - r);     int ind = 0;     int res = ans;     for (int i = 0; i < n; i++) {       int temp;       temp = abs(l - r + 2 * (a[i][1]) - 2 * a[i][0]);       if (temp > res) {         res = temp;         ind = i + 1;       }     }     cout << ind << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e7 + 5;   int l, r, x, y;   char c;   int main() {     cin >> l >> c >> r;     cin >> x >> c >> y;     l = l * 60 + r;     x = x * 60 + y;     l = l - x;     if (l < 0) {       l += 24 * 60;     }     printf( %02d:%02d n , l / 60, l % 60);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int tc;     cin >> tc;     while (tc-- > 0) {       long long int n;       cin >> n;       if (n % 2 == 0) {         long long int a = 2;         long long int b = n / 2;         cout << a <<     << b <<   n ;       } else {         cout << 2 <<     << n - 1 <<   n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 200 + 10;   int main() {     int n, arr[N];     char f;     char ch[N];     scanf( %d , &n);     cin >> ch;     n = 2 * n;     for (int i = 0; i < n; i++) arr[i] = ch[i] -  0 ;     sort(arr, arr + n / 2);     sort(arr + n / 2, arr + n);     bool a = false, b = false;     for (int i = 0; i < n / 2; i++) {       if (arr[i] >= arr[n / 2 + i]) a = true;       if (arr[i] <= arr[n / 2 + i]) b = true;     }     if (a && b)       cout <<  NO ;     else       cout <<  YES ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     long long int i, j, a, b, ans;     for (i = 1; i <= t; i++) {       cin >> a >> b;       ans = 0;       while ((a + b + ans * (ans + 1) / 2) % 2 != 0 ||              (a + b + ans * (ans + 1) / 2) < 2 * max(a, b)) {         ans++;       }       cout << ans << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   struct point {     long long x, a;   } p[100];   int n;   long long key[100][100];   long long k[100];   long long s[3], ans;   long long v;   void getb(long long ab, long long b, int cur) {     if (ab < b * b) return;     if (cur > n + 1) return;     if (cur == n + 1) {       long long a = ab / b;       long long c = v / ab;       long long tmp = a * c + ab + b * c;       if (tmp < ans) {         ans = tmp;         s[0] = a, s[1] = b, s[2] = c;       }       return;     }     int t = p[cur].a - k[cur];     for (int i = t; i >= 0; i--) {       getb(ab, b * key[cur][i], cur + 1);     }   }   void dfs(long long c, int cur) {     if (v / c < c * c || cur > n + 1) return;     if (cur == n + 1) {       long long ab = v / c;       if (ab + 2 * sqrt(1.0 * v * c) <= ans) {         getb(ab, 1, 1);       }       return;     }     for (int i = p[cur].a; i >= 0; i--) {       k[cur] = i;       dfs(c * key[cur][i], cur + 1);     }   }   int main() {     int cas;     long long suma, sumb;     scanf( %d , &cas);     while (cas--) {       scanf( %d , &n);       v = 1;       for (int i = 1; i <= n; i++) {         cin >> p[i].x >> p[i].a;         long long t = 1;         key[i][0] = 1;         for (int j = 1; j <= p[i].a; j++) {           t *= p[i].x;           key[i][j] = t;         }         v *= t;       }       ans = 2 * v + 1;       s[0] = v, s[1] = s[2] = 1;       dfs(1, 1);       ans *= 2;       cout << ans <<     << s[0] <<     << s[1] <<     << s[2] << endl;     }     return 0;   }


#include <bits/stdc++.h>   #include <stdio.h>   using namespace std;      #define all(v) v.begin(), v.end()   #define eb emplace_back   #define ll long long      const int N = 2e5 + 5;      const int inf = 1e9 + 7;      ll t[4 * N];   ll z[4 * N];   ll a[N];   bool modify[4 * N];      void push(int tl, int tr, int v) {       if (modify[v]) {           t[v] += z[v];           if (tl != tr) {               modify[v + v + 1] = modify[v + v + 2] = 1;               z[v + v + 1] += z[v];               z[v + v + 2] += z[v];           }           modify[v] = 0;           z[v] = 0;       }   }      void build(int tl, int tr, int v) {       if (tl == tr) {           t[v] = a[tl];       } else {           int tm = (tl + tr) >> 1;           build(tl, tm, v + v + 1);           build(tm + 1, tr, v + v + 2);           t[v] = min(t[v + v + 1], t[v + v + 2]);       }   }      ll query(int ql, int qr, int tl, int tr, int v) {       if (ql > tr || qr < tl) {           return inf;       }       push(tl, tr, v);       if (ql <= tl && tr <= qr) {           return t[v];       }       int tm = (tl + tr) >> 1;       return min(                  query(ql, qr, tl, tm, v + v + 1),                  query(ql, qr, tm + 1, tr, v + v + 2));   }      void update(int ql, int qr, int val, int tl, int tr, int v) {       push(tl, tr, v);       if (ql > tr || qr < tl) {           return;       }       if (ql <= tl && tr <= qr) {           z[v] += val;           modify[v] = 1;           push(tl, tr, v);       } else {           int tm = (tl + tr) >> 1;           update(ql, qr, val, tl, tm, v + v + 1);           update(ql, qr, val, tm + 1, tr, v + v + 2);           t[v] = min(t[v + v + 1], t[v + v + 2]);       }   }      void solve() {       int n;       cin >> n;       int answer = 0;       vector<pair<int, int>> neg;       for(int i = 0; i < n; i += 1) {           int x;           cin >> x;           if (x < 0) {               neg.emplace_back(x, i);           }           if (i)               a[i] = a[i - 1];           if (x >= 0) {               a[i] += x;               answer += 1;           }       }       build(0, n - 1, 0);       sort(all(neg));       reverse(all(neg));      //    for(int i = 0; i < n; i += 1) {   //        cout << query(i, i, 0, n - 1, 0) <<    ;   //    }   //    cout << endl;       for(auto [val, id] : neg) {           update(id, n - 1, val, 0, n - 1, 0);           if (query(0, n - 1, 0, n - 1, 0) >= 0) {               answer += 1;   //            cout <<  id =   << id << endl;   //            for(int i = 0; i < n; i += 1) {   //                cout << query(i, i, 0, n - 1, 0) <<    ;   //            }   //            cout << endl;           } else {               update(id, n - 1, -val, 0, n - 1, 0);           }       }       cout << answer << endl;   }      int main() {       ios_base::sync_with_stdio(false);       cin.tie(0);       cout.tie(0);   //    freopen( taskA.in ,  r , stdin);   //    freopen( taskA.out ,  w , stdout);       int t = 1;   //    cin >> t;       while(t--) {           solve();       }       return 0;   }


#include <bits/stdc++.h>   using namespace std;   int cnt[300007];   int main() {     int n, k;     scanf( %d%d , &n, &k);     string s;     cin >> s;     int check = 100;     for (int i = (0); i <= ((int)s.size() - 1); ++i) ++cnt[s[i] -  a ];     for (int i = ( a ); i <= ( z ); ++i) {       if (k >= cnt[i -  a ])         k -= cnt[i -  a ];       else {         cnt[i -  a ] -= k;         check = i -  a ;         break;       }     }     string str =   ;     for (int i = (0); i <= ((int)s.size() - 1); ++i) {       if (s[i] -  a  < check) continue;       if (s[i] -  a  == check) {         if (k) {           --k;           continue;         }       }       str += s[i];     }     cout << str << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string num;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> num;     for (int i = 0; i < num.length(); i++) {       cout << num[i];     }     for (int i = num.length() - 1; i >= 0; i--) {       cout << num[i];     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double pi = acos(-1.0);   const double eps = 1e-7;   const long long MOD = 1000000007LL;   const int INF = 0x3f3f3f3f;   const int _NAN = -0x3f3f3f3f;   const double EULC = 0.5772156649015328;   const int NIL = -1;   template <typename T>   void read(T &x) {     x = 0;     char ch = getchar();     long long f = 1;     while (!isdigit(ch)) {       if (ch ==  - ) f *= -1;       ch = getchar();     }     while (isdigit(ch)) {       x = x * 10 + ch - 48;       ch = getchar();     }     x *= f;   }   const int maxn = 1e7 + 10;   bool isprime[maxn] = {1, 1};   int prime[maxn], kase;   vector<long long> ve;   long long ls[12] = {0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024};   int ans;   void primeMaker() {     for (int i = 2; i < maxn; ++i) {       if (!isprime[i]) prime[kase++] = i;       for (int j = 0; j < kase && prime[j] * i < maxn; ++j) {         isprime[i * prime[j]] = true;         if (!(i % prime[j])) break;       }     }   }   int solve(long long &n) {     long long t2 = n;     int __max = -1;     for (int i = 0; i < kase && prime[i] <= t2; ++i) {       if (!(t2 % prime[i])) {         int cnt = 0;         while (!(t2 % prime[i])) {           ++cnt;           t2 /= prime[i];         }         if (__max != -1 && __max != cnt) ++ans;         __max = max(__max, cnt);         ve.push_back(prime[i]);       }     }     if (ans) ans = 1;     if (__max == -1) __max = 1;     for (int i = 0; i < 10; ++i) {       if (__max == ls[i]) break;       if (__max > ls[i] && __max < ls[i + 1]) {         __max = ls[i + 1];         if (ans != 1) ++ans;         break;       }     }     n = 1;     if (!ve.empty()) {       for (auto num : ve) n *= num;     }     return __max;   }   int main(void) {     primeMaker();     long long n;     while (~scanf( %lld , &n)) {       ans = 0;       if (!isprime[n]) {         printf( %lld %d n , n, 0);         continue;       }       int res = solve(n);       ans += log2l(res) + eps;       printf( %lld %d n , n, ans);       ve.clear();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> g[100005];   int par[18][100005];   int depth[100005];   void dfs(int u, int p = 0, int d = 0) {     par[0][u] = p;     depth[u] = d;     for (int i = 0; i < g[u].size(); i++) {       int v = g[u][i];       if (v == p) continue;       dfs(v, u, d + 1);     }   }   int LCA(int a, int b) {     if (depth[a] < depth[b]) swap(a, b);     int diff = depth[a] - depth[b];     for (int i = 17; i >= 0; i--)       if ((diff >> i) & 1) a = par[i][a];     if (a == b) return a;     for (int i = 17; i >= 0; i--) {       if (par[i][a] != par[i][b]) a = par[i][a], b = par[i][b];     }     return par[0][a];   }   int dist(int a, int b) {     int lca = LCA(a, b);     return depth[a] + depth[b] - 2 * depth[lca];   }   int main() {     int n, q, p;     scanf( %d%d , &n, &q);     for (int i = 2; i <= n; i++)       scanf( %d , &p), g[i].push_back(p), g[p].push_back(i);     dfs(1);     for (int j = 1; j <= 17; j++)       for (int i = 1; i <= n; i++)         if (par[j - 1][i] != 0) par[j][i] = par[j - 1][par[j - 1][i]];     while (q--) {       int a[3];       scanf( %d%d%d , &a[0], &a[1], &a[2]);       int ans = -1;       for (int i = 0; i < 3; i++) {         for (int j = 0; j < 3; j++) {           for (int k = 0; k < 3; k++) {             if (i == j || i == k || j == k) continue;             int s = a[i], t = a[j], f = a[k];             ans = max(ans, (dist(s, f) + dist(t, f) - dist(s, t) + 1) / 2);           }         }       }       printf( %d n , ans + 1);     }   }


#include <bits/stdc++.h>   using namespace std;   bool is_integer(long double k) { return std::floor(k) == k; }   int main() {     long long i, j = 0;     string s;     cin >> s;     if (s.length() == 1 && s[0] ==  0 ) {       cout << 0;       return 0;     }     int c = 0;     for (i = (s.length() - 1); i >= 0; i--) {       if (s[i] ==  1 ) {         c++;       }     }     if (c == 1) {       cout << floor(s.length() / 2.0);     } else {       cout << ceil(s.length() / 2.0);     }   }


#include <bits/stdc++.h>   using namespace std;   using tint = tuple<int, int, int>;   const int maxn = 200004;   int N, M;   tint a[maxn];   struct dsu {     dsu() { iota(p, p + maxn, 0); }     int p[maxn], add[maxn];     int root(int k) { return p[k] != k ? p[k] = root(p[k]) : k; }     bool connect(int x, int y) {       x = root(x);       y = root(y);       if (x == y) return false;       p[y] = x;       add[x] |= add[y];       return true;     }   } d;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> N >> M;     for (int i = 0; i < M; i++) {       int x, y, w;       cin >> x >> y >> w;       a[i] = tint(x, y, w);     }     sort(a, a + M, [](tint x, tint y) { return get<2>(x) > get<2>(y); });     int ans = 0;     for (int i = 0; i < M; i++) {       int x, y, w;       tie(x, y, w) = a[i];       if (d.root(x) != d.root(y) and not(d.add[d.root(x)] and d.add[d.root(y)])) {         ans += w;         d.connect(x, y);       } else if (!d.add[d.root(x)]) {         ans += w;         d.add[d.root(x)] = true;       }     }     cout << ans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1e9;   int totb = 0, totr = 0, totx = 0, deep;   int n;   struct data {     int next, num;   } edgeb[400001], edger[400001];   struct data2 {     int x;     bool judge;   } ans[200001];   struct seg {     int l, r, va;   } tr[1600001], tb[1600001];   int headb[200001], headr[200001];   int wb[200001], wr[200001], vr[200001], vb[200001], db[200001], dr[200001];   int fab[200001][19], far[200001][19], lb[200001], rb[200001], lr[200001],       rr[200001];   int eb[200001], er[200001], vab[400001], var[400001], locb[400001],       locr[400001], px;   bool visb[200001], visr[200001];   queue<data2> q;   bool cmp(data2 p, data2 q) { return p.x < q.x; }   void add1(int u, int v) {     edgeb[++totb].next = headb[u];     edgeb[totb].num = v;     headb[u] = totb;   }   void add2(int u, int v) {     edger[++totr].next = headr[u];     edger[totr].num = v;     headr[u] = totr;   }   void dfsb1(int x) {     wb[x] = vb[x];     db[x] = deep;     lb[x] = totx + 1;     totx += wb[x];     for (int i = headb[x]; i != -1; i = edgeb[i].next) {       int kx = edgeb[i].num;       if (!db[kx]) {         deep++;         fab[kx][0] = x;         dfsb1(kx);         deep--;         wb[x] += wb[kx];       }     }     rb[x] = totx;   }   void dfsr1(int x) {     wr[x] = vr[x];     dr[x] = deep;     lr[x] = totx + 1;     totx += wr[x];     for (int i = headr[x]; i != -1; i = edger[i].next) {       int kx = edger[i].num;       if (!dr[kx]) {         deep++;         far[kx][0] = x;         dfsr1(kx);         deep--;         wr[x] += wr[kx];       }     }     rr[x] = totx;   }   void build(int i, int l, int r) {     tr[i].l = tb[i].l = l;     tr[i].r = tb[i].r = r;     if (l == r) {       tb[i].va = vab[l];       tr[i].va = var[l];       if (locr[l] == px) tr[i].va = INF;       return;     }     int mid = (l + r) / 2;     build(i * 2, l, mid);     build(i * 2 + 1, mid + 1, r);     tr[i].va = min(tr[i * 2].va, tr[i * 2 + 1].va);     tb[i].va = min(tb[i * 2].va, tb[i * 2 + 1].va);   }   void deleb(int i, int l, int r, int va) {     int nowl = tb[i].l, nowr = tb[i].r;     if (nowl > r || nowr < l) return;     if (tb[i].va > va) return;     if (nowl == nowr) {       tb[i].va = INF;       if (visb[locb[nowl]]) return;       tb[i].va = INF;       data2 now;       now.x = locb[nowl];       now.judge = 1;       q.push(now);       visb[now.x] = 1;       return;     }     deleb(i * 2, l, r, va);     deleb(i * 2 + 1, l, r, va);     tb[i].va = min(tb[i * 2].va, tb[i * 2 + 1].va);   }   void deler(int i, int l, int r, int va) {     int nowl = tr[i].l, nowr = tr[i].r;     if (nowl > r || nowr < l) return;     if (tr[i].va > va) return;     if (nowl == nowr) {       tr[i].va = INF;       if (visr[locr[nowl]]) return;       data2 now;       now.x = locr[nowl];       now.judge = 0;       q.push(now);       visr[now.x] = 1;       return;     }     deler(i * 2, l, r, va);     deler(i * 2 + 1, l, r, va);     tr[i].va = min(tr[i * 2].va, tr[i * 2 + 1].va);   }   void prelca() {     fab[1][0] = far[1][0] = 1;     for (int j = 1; j <= 18; j++)       for (int i = 1; i <= n; i++) {         far[i][j] = far[far[i][j - 1]][j - 1];         fab[i][j] = fab[fab[i][j - 1]][j - 1];       }   }   int lcab(int u, int v) {     while (db[u] > db[v]) {       int kx = log2(db[u] - db[v]);       u = fab[u][kx];     }     while (db[u] < db[v]) {       int kx = log2(db[v] - db[u]);       v = fab[v][kx];     }     if (u == v) return u;     int kg = log2(db[u]);     for (int i = kg; i >= 0; i--) {       if (fab[u][i] == fab[v][i]) continue;       u = fab[u][i];       v = fab[v][i];     }     return fab[u][0];   }   int lcar(int u, int v) {     while (dr[u] > dr[v]) {       int kx = log2(dr[u] - dr[v]);       u = far[u][kx];     }     while (dr[u] < dr[v]) {       int kx = log2(dr[v] - dr[u]);       v = far[v][kx];     }     if (u == v) return u;     int kg = log2(dr[u]);     for (int i = kg; i >= 0; i--) {       if (far[u][i] == far[v][i]) continue;       u = far[u][i];       v = far[v][i];     }     return far[u][0];   }   void prep() {     memset(headr, -1, sizeof(headr));     memset(headb, -1, sizeof(headb));     scanf( %d , &n);     for (int i = 2; i <= n; i++) {       scanf( %d , &eb[i]);       add1(i, eb[i]);       add1(eb[i], i);     }     for (int i = 2; i <= n; i++) {       scanf( %d , &er[i]);       add2(i, er[i]);       add2(er[i], i);     }     for (int i = 2; i <= n; i++) {       vr[i]++;       vr[eb[i]]++;       vb[i]++;       vb[er[i]]++;     }     deep = 1;     totx = 0;     dfsb1(1);     deep = 1;     totx = 0;     dfsr1(1);     memset(vr, 0, sizeof(vr));     memset(vb, 0, sizeof(vb));     prelca();     for (int i = 2; i <= n; i++) {       vr[i]++;       vr[eb[i]]++;       var[vr[i] + lr[i] - 1] = var[vr[eb[i]] + lr[eb[i]] - 1] =           dr[lcar(i, eb[i])];       locr[vr[i] + lr[i] - 1] = locr[vr[eb[i]] + lr[eb[i]] - 1] = i - 1;       vb[i]++;       vb[er[i]]++;       vab[vb[i] + lb[i] - 1] = vab[vb[er[i]] + lb[er[i]] - 1] =           db[lcab(i, er[i])];       locb[vb[i] + lb[i] - 1] = locb[vb[er[i]] + lb[er[i]] - 1] = i - 1;     }     scanf( %d , &px);     build(1, 1, 2 * n - 2);   }   int getp(data2 x) {     int i = x.x;     if (x.judge == 0) {       if (db[i + 1] < db[eb[i + 1]]) return eb[i + 1];       return i + 1;     }     if (dr[i + 1] < dr[er[i + 1]]) return er[i + 1];     return i + 1;   }   void work() {     data2 gx;     gx.judge = 0;     gx.x = px;     q.push(gx);     visr[px] = 1;     int headpx = 0;     while (!q.empty()) {       data2 k = q.front();       ans[++headpx] = k;       q.pop();       int point = getp(k);       if (k.judge == 0)         deleb(1, lb[point], rb[point], db[point] - 1);       else         deler(1, lr[point], rr[point], dr[point] - 1);     }     printf( Blue n%d , ans[1].x);     for (int i = 2; i <= headpx; i++) {       if (ans[i].judge != ans[i - 1].judge) {         int nowj = i;         while (nowj <= headpx && ans[nowj].judge == ans[i].judge) nowj++;         sort(ans + i, ans + nowj, cmp);         if (ans[i].judge == 0)           printf(  nBlue n );         else           printf(  nRed n );       }       printf( %d  , ans[i].x);     }   }   int main() {     prep();     work();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 3e6 + 7;   const int mod = 1e9 + 7;   long long int dp[maxn] = {0};   int main() {     int t;     cin >> t;     dp[1] = 0;     dp[2] = 0;     dp[3] = 1;     for (int i = 4; i < maxn; i++) {       dp[i] = 2 * dp[i - 2] + dp[i - 1];       if (i % 3 == 0) dp[i]++;       dp[i] %= mod;     }     while (t--) {       int n;       cin >> n;       cout << (dp[n] * 4 + mod) % mod << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 200010;   const int MOD = 1e9 + 7;   int read() {     int x = 0, ch;     while (isspace(ch = getchar()))       ;     do x = x * 10 + ch -  0 ;     while (isdigit(ch = getchar()));     return x;   }   int n;   map<int, int> idx, idy;   int nid;   namespace G {   int head[MAXN], nxt[MAXN], to[MAXN], m;   void init() { memset(head, -1, sizeof head); }   void adde(int u, int v) {     to[m] = v, nxt[m] = head[u], head[u] = m++;     to[m] = u, nxt[m] = head[v], head[v] = m++;   }   }  // namespace G   int fpow(int a, int b) {     int c = 1;     while (b) {       if (b & 1) c = int(1LL * c * a % MOD);       a = int(1LL * a * a % MOD);       b >>= 1;     }     return c;   }   int vis[MAXN];   queue<int> q;   int solve(int s) {     using namespace G;     int e = 0, o = 0;     vis[s] = 1, q.push(s);     while (!q.empty()) {       int u = q.front();       q.pop();       ++o;       for (int i = head[u]; ~i; i = nxt[i], ++e)         if (!vis[to[i]]) vis[to[i]] = 1, q.push(to[i]);     }     e >>= 1;     return e == o - 1 ? (fpow(2, o) - 1 + MOD) % MOD : fpow(2, o);   }   int main() {     n = read();     G::init();     for (int i = 0; i < n; ++i) {       int x = read(), y = read();       if (!idx[x]) idx[x] = ++nid;       if (!idy[y]) idy[y] = ++nid;       G::adde(idx[x], idy[y]);     }     int ans = 1;     for (int i = 1; i <= nid; ++i)       if (!vis[i]) ans = int(1LL * ans * solve(i) % MOD);     printf( %d n , ans);     return 0;   }


#include <iostream>   #include <vector>   #include <algorithm>   #include <string>   #include <ctype.h>   #include <deque>   #include <cstring>   #include <set>   #include <bitset>   #include <map>   #include <chrono>   #include <random>   #include <unordered_map>   #include <stdio.h>      using namespace std;      typedef long long ll;   typedef long double ld;   typedef std::vector<int> vi;   typedef std::vector<bool> vb;   typedef std::vector<string> vs;   typedef std::vector<double> vd;   typedef std::vector<long long> vll;   typedef std::vector<std::vector<int> > vvi;   typedef vector<vll> vvll;   typedef std::vector<std::pair<int, int> > vpi;   typedef vector<vpi> vvpi;   typedef std::pair<int, int> pi;   typedef std::pair<ll, ll> pll;   typedef std::vector<pll> vpll;      const long long mod = 1000000007;   const unsigned gen_seed = std::chrono::system_clock::now().time_since_epoch().count();   std::mt19937_64 gen(gen_seed);      #define all(c) (c).begin(),(c).end()   #define srt(c) sort(all(c))   #define srtrev(c) sort(all(c)); reverse(all(c))   #define forn(i, a, b) for(int i = a; i < b; i++)   #define read(x) scanf( %d , &x)   #define readv(x, n) vi x(n); forn(i,0,n) scanf( %d , &x[i])      #define pb push_back   #define mp make_pair      void mul(vi & a, int k) {       vi b(k,0);       for(auto x : a) b.pb(x);       forn(i,0,a.size()) b[i] = (b[i] + mod-a[i])%mod;       a.resize(b.size() - 1);       for(int i = b.size() - 1; i > 0; i--) {           a[i-1] = b[i];           b[i-1] = (b[i] + b[i-1])%mod;       }   }   vi c, b;   int n;   int get(int x) {       vi p(1,1);       int sb = 0;       int sbt = 0;       int add = 0;       forn(i,0,n) {           mul(p, c[i]+1);           int cur = x*(i+1) + sbt - add;           if(cur > (int)p.size()) {               return 0;           }           if(cur>0) {               forn(j,0,p.size() - cur) p[j] = p[j + cur];               p.resize(p.size() - cur);               add += cur;           }                      sb+=b[i];           sbt+=sb;       }       ll ans = 0;       forn(i,0,p.size()) ans = ans+p[i];       return ans % mod;   }   set<int> cool;   int death = 1000;      void getcool() {       int sb = 0;       int sbt = 0;       int dp = 0;       forn(i,0,n) {           dp += c[i];              forn(x,-sbt/(i+1),(dp-sbt)/(i+1)+2) {               int cur = x*(i+1) + sbt;               if(cur >0 && cur <= dp) {                   cool.insert(x);               }               else if(cur > dp) {                   death = min(death, x);               }           }           sb+=b[i];           sbt+=sb;       }   }         int main()   {   #ifndef ONLINE_JUDGE       freopen( input.txt ,  rt , stdin);       freopen( output.txt ,  wt , stdout);   #endif              scanf( %d , &n);   //    readv(c,n);   //    readv(b,n-1);       c.resize(n);       b.resize(n-1);       forn(i,0,n) scanf( %d , &c[i]);       forn(i,0,n-1) scanf( %d , &b[i]);       int q;       read(q);       getcool();       map<int, int> ans;       for(auto x : cool) {           if(x < death) ans[x] = get(x);           else ans[x] = 0;       }       ll full = 1;       forn(i,0,n) full = (full * (c[i]+1))%mod;          while(q--) {           int x;           read(x);           if(cool.find(x) != cool.end()) printf( %d n , ans[x]);           else if(x >= death) printf( 0 n );           else printf( %d n , full);       }          }


#include <bits/stdc++.h>   using namespace std;   const int inf = ~0u >> 2;   const int N = 500010;   int Max[N << 2];   struct node {     int x, y, z;   } in[N];   int tot, n;   int num[N];   int max(int a, int b) { return a > b ? a : b; }   void pushup(int rt) { Max[rt] = max(Max[rt << 1], Max[rt << 1 | 1]); }   void build(int l, int r, int rt) {     Max[rt] = 0;     if (l == r) return;     int m = (l + r) >> 1;     build(l, m, rt << 1);     build(m + 1, r, rt << 1 | 1);   }   void update(int p, int val, int l, int r, int rt) {     if (l == r) {       if (val > Max[rt]) Max[rt] = val;       return;     }     int m = (l + r) >> 1;     if (p <= m)       update(p, val, l, m, rt << 1);     else       update(p, val, m + 1, r, rt << 1 | 1);     pushup(rt);   }   int query(int L, int R, int l, int r, int rt) {     if (L <= l && r <= R) return Max[rt];     int m = (l + r) >> 1;     int ret = 0;     if (L <= m) ret = max(ret, query(L, R, l, m, rt << 1));     if (R > m) ret = max(ret, query(L, R, m + 1, r, rt << 1 | 1));     return ret;   }   void init() {     sort(num + 1, num + n + 1);     tot = unique(num + 1, num + n + 1) - num - 1;     build(1, tot, 1);     for (int i = 1; i <= n; i++)       in[i].x = lower_bound(num + 1, num + 1 + tot, in[i].x) - num;   }   inline int cmp(node a, node b) { return a.y > b.y; }   int main() {     int i, j, k;     scanf( %d , &n);     for (i = 1; i <= n; i++) {       scanf( %d , &in[i].x);       num[i] = in[i].x;     }     for (i = 1; i <= n; i++) scanf( %d , &in[i].y);     for (i = 1; i <= n; i++) scanf( %d , &in[i].z);     init();     sort(in + 1, in + n + 1, cmp);     int ans = 0;     for (i = 1; i <= n; i = j) {       for (j = i; j <= n && in[j].y == in[i].y; j++) {         int z;         z = query(in[j].x + 1, tot, 1, tot, 1);         if (z > in[j].z) ans++;       }       for (; i <= j - 1; i++) {         update(in[i].x, in[i].z, 1, tot, 1);       }     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   namespace chtholly {   char buf[1 << 23], *p1 = buf, *p2 = buf;   inline int read() {     int x = 0, f = 1;     char c = getchar();     for (; !isdigit(c); c = getchar()) f ^= c ==  - ;     for (; isdigit(c); c = getchar()) x = (x << 3) + (x << 1) + (c ^  0 );     return f ? x : -x;   }   template <typename mitsuha>   inline bool read(mitsuha &x) {     x = 0;     int f = 1;     char c = getchar();     for (; !isdigit(c) && ~c; c = getchar()) f ^= c ==  - ;     if (!~c) return 0;     for (; isdigit(c); c = getchar()) x = (x << 3) + (x << 1) + (c ^  0 );     return x = f ? x : -x, 1;   }   template <typename mitsuha>   inline int write(mitsuha x) {     if (!x) return 0 & putchar(48);     if (x < 0) putchar( - ), x = -x;     int bit[20], i, p = 0;     for (; x; x /= 10) bit[++p] = x % 10;     for (i = p; i; --i) putchar(bit[i] + 48);     return 0;   }   inline char fuhao() {     char c = getchar();     for (; isspace(c); c = getchar())       ;     return c;   }   }  // namespace chtholly   using namespace chtholly;   using namespace std;   const int yuzu = 1e5;   typedef long long fuko[yuzu | 10];   fuko a, b, c, d;   int n, k;   typedef long long karen[yuzu << 2 | 13];   struct segtree {     karen val;     void build(int rt = 1, int l = 1, int r = n) {       if (l == r)         val[rt] = read() % k;       else {         int mid = l + r >> 1;         build(rt << 1, l, mid), build(rt << 1 | 1, mid + 1, r);         val[rt] = val[rt << 1] * val[rt << 1 | 1] % k;       }     }     long long query(int ql, int qr, int rt = 1, int l = 1, int r = n) {       if (ql > r || qr < l) return 1;       if (ql <= l && qr >= r) return val[rt];       int mid = l + r >> 1;       return query(ql, qr, rt << 1, l, mid) *              query(ql, qr, rt << 1 | 1, mid + 1, r) % k;     }   } my;   int main() {     read(n), read(k), my.build();     int i, l = 1, r = 1;     long long llx = 0;     for (; r <= n; llx += n - r + 1, ++l, r = max(l, r))       for (; r <= n && my.query(l, r); ++r)         ;     write(llx);   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = 1e17;   const long long maxn = 2e5 + 700;   const int mod = 1e9 + 7;   template <typename T>   inline void read(T &a) {     char c = getchar();     T x = 0, f = 1;     while (!isdigit(c)) {       if (c ==  - ) f = -1;       c = getchar();     }     while (isdigit(c)) {       x = (x << 1) + (x << 3) + c -  0 ;       c = getchar();     }     a = f * x;   }   long long n, m, p;   char s[maxn];   int a[maxn], b[maxn];   int digit(long long x, int *d) {     int ans = 0;     while (x) {       d[++ans] = x % 10;       x /= 10;     }     return ans;   }   int path[maxn];   int check(int pos, int lbound, int rbound) {     if (!pos) return 1;     if (!lbound && !rbound) return 1;     int l = lbound ? a[pos] : 0;     int r = rbound ? b[pos] : 9;     for (int i = l; i <= r; i++) {       if (path[i] > 0) {         path[i]--;         if (check(pos - 1, lbound && i == l, rbound && i == r)) {           path[i]++;           return 1;         }         path[i]++;       }     }     return 0;   }   int pos, res = 0;   void dfs(int u, int w) {     if (u == 9) {       path[u] = w;       if (check(pos, 1, 1)) res++;       return;     }     for (int i = 0; i <= w; i++) {       path[u] = i;       dfs(u + 1, w - i);     }   }   int main() {     read(n);     read(m);     digit(n, a);     pos = digit(m, b);     dfs(0, pos);     printf( %d n , res);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int q[3001], t, n;   int main() {     scanf( %d , &n);     for (int i = 2; i <= n; i++) {       if (q[i - 1] == 2) t++;       if (q[i] > 0) continue;       for (int j = i; j <= n; j += i) q[j]++;     }     if (q[n] == 2) t++;     printf( %d n , t);   }


#include <bits/stdc++.h>   using namespace std;   long long n, x;   vector<string> ans;   long long dec(string s) {     long long ret = 0;     for (long long i = 0; i < s.size(); i++) {       ret = ret * 10 + s[i] - 48;     }     return ret;   }   void add(long long v) {     long long rs = 0;     if (ans.size() == 0) {       string tmp =   ;       while (v > 9) {         tmp =  9  + tmp;         v -= 9;       }       tmp = to_string(v) + tmp;       ans.push_back(tmp);     } else {       string p_s = ans[ans.size() - 1], req = p_s;       long long cnt = 0;       for (long long i = 0; i < req.size(); i++) {         cnt += req[i] - 48;       }       if (cnt < v) {         long long df = v - cnt;         for (long long i = req.size() - 1; i >= 0; i--) {           if (req[i] <  9  && df) {             long long dy =  9  - req[i];             req[i] += min(df, dy);             df -= min(df, dy);             if (!df) {               ans.push_back(req);               return;             }           }         }         while (df >= 9) {           req =  9  + req;           df -= 9;         }         if (v) req = to_string(df) + req;         ans.push_back(req);       } else {         string p_s = ans[ans.size() - 1];         long long idx = -1, sm = 0, tmp_sm = 0;         for (long long i = 0; i < p_s.size(); i++) {           tmp_sm += p_s[i] - 48;           if (v > tmp_sm && p_s[i] <  9 ) {             idx = i;             sm = tmp_sm;           } else if (v < sm)             break;         }         if (idx == -1) {           string p_s =  1 ;           long long sz = ans[ans.size() - 1].size();           for (long long i = 0; i < sz; i++) p_s = p_s +  0 ;           v -= 1;           long long idx = p_s.size() - 1;           while (idx > 0 && v > 0) {             char c = (char)min((long long) 9 , v + 48);             p_s[idx] = c;             idx--, v -= 9;           }           ans.push_back(p_s);         } else {           sm = v - sm - 1;           p_s[idx] += 1;           for (long long j = idx + 1; j < p_s.size(); j++) {             p_s[j] =  0 ;           }           for (long long i = p_s.size() - 1; i > idx; i--) {             if (sm > 0) {               long long dx =  9  - p_s[i];               p_s[i] += min(sm, dx);               sm -= min(sm, dx);             } else               break;           }           ans.push_back(p_s);         }       }     }   }   int main() {     cin >> n;     for (long long i = 0; i < n; i++) {       cin >> x;       add(x);     }     for (long long i = 0; i < ans.size(); i++) cout << ans[i] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int N;     scanf( %d , &N);     if (N == 1) {       puts( 1 );       return 0;     }     int s = 0;     for (int i = 0; i < N; ++i) {       int t;       scanf( %d , &t);       s += t;     }     printf( %d n , s % N == 0 ? N : N - 1);   }


#include <bits/stdc++.h>   using namespace std;   const double PI = acos(-1.0);   #pragma GCC diagnostic ignored  -Wsign-compare    int main() {     int n, ind = 0;     scanf( %d , &n);     vector<long long> vals(n);     vector<long long> pref(n);     for (int i = 0; i < n; i++) {       scanf( %d , &vals[i]);     }     42;     partial_sum(vals.begin(), vals.end(), pref.begin());     vals.insert(vals.begin(), 0);     pref.insert(pref.begin(), 0);     vector<double> hull(n);     vector<pair<int, int> > inds(n);     for (int i = 1; i <= n; i++) {       double cur = vals[i];       pair<int, int> use = make_pair(i, i);       while (ind > 0 and hull[ind - 1] > cur) {         ind--;         cur = ((double)pref[i] - pref[inds[ind].first - 1]) /               ((double)i - inds[ind].first + (double)1.000000);         use = make_pair(inds[ind].first, i);       }       hull[ind] = cur;       inds[ind] = use;       ind++;     }     42;     for (int i = 0; i < ind; i++) {       for (int j = inds[i].first; j <= inds[i].second; j++) {         printf( %.10f n , hull[i]);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) {     if (a < b) {       swap(a, b);     }     if (a % b == 0) {       return b;     }     return gcd(b, a % b);   }   vector<vector<int>> gr;   vector<int> used;   void dfs(int v) {     used[v] = 1;     for (auto i : gr[v]) {       if (!used[i]) {         dfs(i);       }     }   }   void solution() {     long int n;     cin >> n;     vector<long long> mass(n);     long long minn = 1e10;     long long minn_ind = 0;     for (int i = 0; i < n; i++) {       cin >> mass[i];       if (mass[i] < minn) {         minn = mass[i];         minn_ind = i;       }     }     gr = vector<vector<int>>(n);     used = vector<int>(n, 0);     for (int i = 0; i < n; i++) {       if (gcd(mass[i], minn) == minn) {         gr[i].push_back(minn_ind);         gr[minn_ind].push_back(i);       }     }     dfs(minn_ind);     vector<long long> sorted = mass;     sort(sorted.begin(), sorted.end());     vector<long long> get_ans;     for (int i = 0; i < n; i++) {       if (mass[i] != sorted[i] || i == minn_ind) {         get_ans.push_back(i);       }     }     bool ans = 1;     for (auto i : get_ans) {       if (!used[i]) {         ans = 0;         break;       }     }     if (ans) {       cout <<  YES ;     } else {       cout <<  NO ;     }     cout << endl;   }   int main() {     int t;     cin >> t;     for (int i = 0; i < t; i++) {       solution();     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int res;     cin >> res;     if (res % 2 == 0) {       cout <<  Mahmoud ;     } else {       cout <<  Ehab ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int grundy[] = {0, 1, 2, 1, 4, 3, 2, 1, 5, 6,  2, 1, 8, 7,  5,                   9, 8, 7, 3, 4, 7, 4, 2, 1, 10, 9, 3, 6, 11, 12};   int main() {     int n;     scanf( %d , &n);     int ones = n;     bool vis[100100] = {false};     vector<int> v;     for (long long i = 2; i * i <= n; i++) {       if (vis[i]) continue;       int size = 0;       for (long long j = i; j <= n; j = j * i) {         if (j * j <= n) vis[j] = true;         size++;         ones--;       }       v.push_back(grundy[size]);     }     ones %= 2;     for (int i = 0; i < (int)v.size(); i++) ones = ones ^ v[i];     if (ones)       cout <<  Vasya  << endl;     else       cout <<  Petya  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long xyp(long long x, long long y) {     if (y == 0) return 1LL;     if (y == 1) return x;     if (y % 2) {       long long p = xyp(x, y - 1);       return (x * p) % 1000000007;     }     long long p = xyp(x, y / 2);     return (p * p) % 1000000007;   }   long long inv(long long x) { return xyp(x, 1000000007 - 2); }   long long fact[10000007];   long long pr[10000007];   vector<long long> rp;   void init() {     fact[0] = 1;     for (long long i = 1; i < 10000007; i++) {       fact[i] = (fact[i - 1] * i) % 1000000007;     }   }   long long ncr(long long n, long long r) {     if (r < 0) return 0LL;     if (r == 0 || n == r) return 1LL;     if (r == 1 || ((n - r) == 1)) return n;     long long p =         (((fact[n] * inv(fact[r])) % 1000000007) * inv(fact[n - r])) % 1000000007;     return p;   }   void sieve() {     memset(pr, 1, sizeof(pr));     pr[0] = pr[1] = 0;     for (long long i = 2; i < 10000007; i++) {       if (pr[i]) {         rp.push_back(i);         for (long long j = i * i; j < 10000007; j += i) {           pr[j] = 0;         }       }     }   }   void solve() {     long long n, k;     cin >> n >> k;     long long a[n + 1], b[n + 1];     long long flag = 1;     for (long long i = 1; i <= n; i++) {       cin >> a[i];       b[i] = a[i];       if (a[i] == k) flag = 0;     }     if (flag) {       cout <<  no n ;       return;     }     sort(b + 1, b + n + 1);     if (b[(n + 1) / 2] == k) {       cout <<  yes n ;       return;     }     if (n == 1) {       if (a[1] == k)         cout <<  yes n ;       else         cout <<  no n ;       return;     }     if (n == 2) {       if (b[1] == k)         cout <<  yes n ;       else         cout <<  no n ;       return;     }     vector<long long> v;     for (long long i = 1; i <= n; i++) {       if (a[i] >= k) {         v.push_back(i);       }     }     flag = 0;     for (long long i = 0; i < v.size() - 1; i++) {       if ((v[i + 1] - v[i]) <= 2) {         flag = 1;       }     }     if (flag)       cout <<  yes n ;     else       cout <<  no n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     ;     int testcases;     cin >> testcases;     while (testcases--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   const long double PI = acos(-1.0);   const long double EPS = 1e-14;   const long long INF = 1e18;   const long long MOD = 1e9 + 7;   const long long p = 97;   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.precision(9);     long long n;     cin >> n;     vector<long long> a(n);     for (long long i = 0; i < n; i++) {       cin >> a[i];     }     vector<vector<long long>> pr(n, vector<long long>(6, INF));     pr[0] = vector<long long>(6, -1);     for (long long i = 1; i < n; i++) {       for (long long j = 1; j <= 5; j++) {         if (pr[i - 1][j] == INF) continue;         for (long long z = 1; z <= 5; z++) {           if (a[i] > a[i - 1]) {             if (z > j) {               pr[i][z] = j;             }           } else if (a[i] < a[i - 1]) {             if (z < j) {               pr[i][z] = j;             }           } else {             if (z != j) {               pr[i][z] = j;             }           }         }       }     }     long long last = -1;     for (long long i = 1; i <= 5; i++) {       if (pr[n - 1][i] != INF) last = i;     }     if (last == -1) {       cout << -1;       return 0;     }     long long num = n - 1;     vector<long long> ans;     while (num != -1) {       ans.push_back(last);       last = pr[num][last];       num--;     }     reverse(ans.begin(), ans.end());     for (long long i = 0; i < ans.size(); i++) {       cout << ans[i] <<    ;     }     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   const int N = 300005, B = 35;   int n;   char t[N];   struct AC {     struct Trie {       int ch[26], fail, c, c2;     } A[N];     int siz[B], root[N], top, cnt;     string str[N];     void build(int RT) {       queue<int> q;       q.push(RT);       while (!q.empty()) {         int x = q.front(), F, k;         q.pop();         for (int i = 0; i < 26; i++)           if (A[x].ch[i]) {             F = A[x].fail;             k = A[x].ch[i];             while (F && !A[F].ch[i]) F = A[F].fail;             if (F)               A[k].fail = A[F].ch[i];             else               A[k].fail = RT;             q.push(k);             A[k].c2 = A[A[k].fail].c2 + A[k].c;           }       }     }     int merge(int x, int y) {       if (!x || !y) return x + y;       A[x].c = A[x].c | A[y].c;       for (int i = 0; i < 26; i++) A[x].ch[i] = merge(A[x].ch[i], A[y].ch[i]);       return x;     }     void Add(string s) {       root[++top] = ++cnt;       int x = root[top], len = s.length(), k;       for (int i = 0; i < len; i++) {         k = s[i] -  a ;         if (!A[x].ch[k]) A[x].ch[k] = ++cnt;         x = A[x].ch[k];       }       A[x].c++;       siz[top] = 1;       build(root[top]);       while (top && siz[top] == siz[top - 1]) {         merge(root[top - 1], root[top]);         build(root[top - 1]);         siz[top - 1] *= 2;         top--;       }     }     int Ask(string s) {       int len = s.length(), sum = 0;       for (int i = 1; i <= top; i++) {         int x = root[i], k;         for (int j = 0; j < len; j++) {           k = s[j] -  a ;           while (x && !A[x].ch[k]) x = A[x].fail;           if (x)             x = A[x].ch[k];           else             x = root[i];           sum += A[x].c2;         }       }       return sum;     }   } IN, OUT;   int main() {     scanf( %d , &n);     int tp;     while (n--) {       scanf( %d %s , &tp, t);       if (tp == 1)         IN.Add(t);       else if (tp == 2)         OUT.Add(t);       else         cout << IN.Ask(t) - OUT.Ask(t) <<   n  << flush;     }   }


#include <bits/stdc++.h>   using namespace std;   typedef long long ll;      inline int read(){       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<<1)+(x<<3)+(ch^48);           ch=getchar();       }       return x*f;   }   const int maxn = 3e4 + 9;    int t;   int a[3];   int solve(){    int l = a[0], m = a[1], r = a[2];    int avg = (l + m + r) / 3;    //printf( avg: %d n , avg);    int ans = 0;    if (l < avg){     if (r > avg){      if (m > avg){       ans += (m - avg) * 2 + r - avg;       return ans;      }      else if (m < avg){       ans += avg - l + (avg - m) * 2;       return ans;      }      else{       ans += avg - l;       return ans;      }     }     else if (r < avg){      ans += (avg - l) * 2 + avg - r;      return ans;     }     else{      ans += (avg - l) * 2;      return ans;     }    }    else if (l == avg){     if (m == avg){      return ans;     }     else if (m < avg){      ans += (avg - m) * 2;      return ans;     }     else{      ans += m - avg;      return ans;     }    }    else{     if (m < avg){      if (r > avg){       ans += (r - avg) * 2 + l - avg;       return ans;      }      else if (r < avg){       ans += (avg - r) * 2 + avg - m;       return ans;      }      else{       ans += avg - m;       return ans;      }     }     else if (m > avg){      ans += (l - avg) * 2 + m - avg;      return ans;     }     else{      ans = (l - avg) * 2;      return ans;     }    }    return ans;   }   int main(){       t = read();       while(t--){        int n = read();        int m;        a[0] = a[1] = a[2] = 0;        for (int i = 1; i <= n; i++){         m = read();         a[m % 3]++;     }     //sort(a, a + 3);     int ans = solve();     printf( %d n , ans);    }    return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 998244353, N = 20, M = 1 << 5;   int n, m;   int f[2][N][N][N][N][2][2], (*nxt)[N][N][N][2][2] = f[1],                               (*cur)[N][N][N][2][2] = *f;   int snx[M], sny[M], spx[M], spy[M], A;   void add(int &x, int y) {     x += y - mod;     x += x >> 31 & mod;   }   int main() {     scanf( %d%d , &n, &m);     A = (1 << n) - 1;     int x, y;     for (int i = 0; i < n; i++) {       scanf( %d%d , &x, &y);       if (x < 0)         snx[1 << i] -= x;       else         spx[1 << i] += x;       if (y < 0)         sny[1 << i] -= y;       else         spy[1 << i] += y;     }     for (int i = 1; i <= A; i++)       spx[i] = spx[i - (i & -i)] + spx[i & -i],       spy[i] = spy[i - (i & -i)] + spy[i & -i],       snx[i] = snx[i - (i & -i)] + snx[i & -i],       sny[i] = sny[i - (i & -i)] + sny[i & -i];     ******nxt = 1;     for (; m; m >>= 1) {       int c = m & 1, tmp;       swap(nxt, cur);       memset(nxt, 0, sizeof *f);       for (int ppx = 0; ppx <= spx[A]; ppx++)         for (int ppy = 0; ppy <= spy[A]; ppy++)           for (int pnx = 0; pnx <= snx[A]; pnx++)             for (int pny = 0; pny <= sny[A]; pny++)               for (int ox = 0; ox < 2; ox++)                 for (int oy = 0; oy < 2; oy++)                   if (tmp = cur[ppx][pnx][ppy][pny][ox][oy])                     for (int d = 0; d <= A; d++) {                       int npx = ppx + spx[d], npy = ppy + spy[d],                           nnx = pnx + snx[d], nny = pny + sny[d];                       if (((npx ^ nnx) | (npy ^ nny)) & 1) continue;                       add(nxt[npx >> 1][nnx >> 1][npy >> 1][nny >> 1]                              [(npx ^ c) & 1 ? !c : ox][(npy ^ c) & 1 ? !c : oy],                           tmp);                     }     }     printf( %d n , ((******nxt) + mod - 1) % mod);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100010;   char s[N];   int main() {     int t;     scanf( %d , &t);     while (t--) {       map<long long, long long> mp;       long long n;       scanf( %lld , &n);       scanf( %s , s);       long long sum = 0, ans = 0;       long long x;       for (int i = 1; i <= n; i++) {         x = s[i - 1] -  0  - 1;         sum += x;         if (sum == 0) ans++;         ans += mp[sum];         mp[sum]++;       }       printf( %lld n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int par[200005], vis[200005], tree[200005];   set<pair<int, int> > par_change;   void dfs(int u, vector<int> next[], int dfs_par) {     vis[u] = 1;     if (par[u] == u) {       par_change.insert({1, u});     }     for (int i = 0; i < next[u].size(); ++i) {       int v = next[u][i];       if (!vis[v]) {         dfs(v, next, u);       } else if (v != dfs_par) {         if (par[u] == v) {           par_change.insert({2, u});         } else {           par_change.insert({2, v});         }       }     }     vis[u] = 2;   }   int main() {     int n, cnt = 0;     scanf( %d , &n);     vector<int> next[n + 5];     for (int i = 1; i <= n; ++i) {       scanf( %d , &par[i]);       tree[i] = par[i];       if (i != par[i]) {         next[i].push_back(par[i]);         next[par[i]].push_back(i);       }     }     for (int i = 1; i <= n; ++i) {       if (!vis[i]) {         dfs(i, next, 0);       }     }     int flag = 0;     tree[par_change.begin()->second] = par_change.begin()->second;     auto it1 = par_change.begin(), it2 = ++it1;     it1 = par_change.begin();     for (; it2 != par_change.end(); ++it2, ++it1) {       tree[it2->second] = it1->second;     }     for (int i = 1; i <= n; ++i) {       if (tree[i] != par[i]) {         ++cnt;       }     }     printf( %d n , cnt);     for (int i = 1; i <= n; ++i) {       printf( %d  , tree[i]);     }     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   void swap(int ar[], int i, int j) {     int aux = ar[j];     ar[j] = ar[i];     ar[i] = ar[j];   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int n, m;     cin >> n >> m;     int Ma[n][m];     int Mb[n][m];     for (int i = 0; i < n; i++)       for (int k = 0; k < m; k++) cin >> Ma[i][k];     for (int i = 0; i < n; i++)       for (int k = 0; k < m; k++) {         int aux;         cin >> aux;         if (aux <= Ma[i][k]) {           int aux2 = Ma[i][k];           Ma[i][k] = aux;           Mb[i][k] = aux2;         } else           Mb[i][k] = aux;       }     for (int i = 0; i < n; i++)       for (int k = 1; k < m; k++)         if (Ma[i][k] <= Ma[i][k - 1] || Mb[i][k] <= Mb[i][k - 1]) {           cout <<  Impossible ;           return 0;         }     for (int k = 0; k < m; k++)       for (int i = 1; i < n; i++)         if (Ma[i][k] <= Ma[i - 1][k] || Mb[i][k] <= Mb[i - 1][k]) {           cout <<  Impossible ;           return 0;         }     cout <<  Possible ;     return 0;   }