#include <bits/stdc++.h>   int search(int n, long long int a[n], long long int target) {     int i;     if (a[0] >= target) {       printf( 1 %lld n , target);       return 0;     }     int L = 0, R = n - 1;     int M;     while ((R - L) > 1) {       if ((L + R) % 2 == 0) {         M = (L + R) / 2;       } else {         M = (L + R - 1) / 2;       }       if (a[M] < target) {         L = M;       } else if (a[M] == target) {         printf( %d %lld n , M + 1, target - a[M - 1]);         return 0;       } else {         R = M;       }     }     if (target == a[L]) {       printf( %d %lld n , L + 1, target);       return 0;     } else if (target == a[R]) {       printf( %d %lld n , R + 1, target - a[R - 1]);     } else {       printf( %d %lld n , L + 2, target - a[L]);     }   }   int main() {     int n, m, i;     scanf( %d %d , &n, &m);     long long int a[n];     long long int b[m];     long long int sum = 0;     long long int tmp;     for (i = 0; i < n; i++) {       scanf( %lld , &tmp);       a[i] = tmp + sum;       sum = tmp + sum;     }     for (i = 0; i < m; i++) {       scanf( %lld , &b[i]);     }     for (i = 0; i < m; i++) search(n, a, b[i]);   }


#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) {     while (a && b) a > b ? a %= b : b %= a;     return a + b;   }   long long lcm(long long a, long long b) { return a * b / gcd(a, b); }   int main() {     int n;     cin >> n;     int i, j, sum = 0, in;     int a[n];     for (i = 0; i < n; ++i) {       cin >> a[i];       sum += a[i];     }     int x = n / 2;     int avg = sum / x;     for (i = 0; i < n; i++) {       if (a[i] == 0) continue;       cout << i + 1 <<    ;       for (j = i + 1; j < n; j++) {         if (a[j] == 0) continue;         if ((a[j] + a[i]) == avg) {           cout << j + 1 <<    ;           a[j] = 0;           a[i] = 0;           break;         }       }       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void _print(long long t) { cerr << t; }   void _print(string t) { cerr << t; }   void _print(char t) { cerr << t; }   void _print(long double t) { cerr << t; }   void _print(double t) { cerr << t; }   void _print(unsigned long long t) { cerr << t; }   template <class T, class V>   void _print(pair<T, V> p);   template <class T>   void _print(vector<T> v);   template <class T>   void _print(set<T> v);   template <class T, class V>   void _print(map<T, V> v);   template <class T>   void _print(multiset<T> v);   template <class T, class V>   void _print(pair<T, V> p) {     cerr <<  { ;     _print(p.first);     cerr <<  , ;     _print(p.second);     cerr <<  } ;   }   template <class T>   void _print(vector<T> v) {     cerr <<  [  ;     for (T i : v) {       _print(i);       cerr <<    ;     }     cerr <<  ] ;   }   template <class T>   void _print(set<T> v) {     cerr <<  [  ;     for (T i : v) {       _print(i);       cerr <<    ;     }     cerr <<  ] ;   }   template <class T>   void _print(multiset<T> v) {     cerr <<  [  ;     for (T i : v) {       _print(i);       cerr <<    ;     }     cerr <<  ] ;   }   template <class T, class V>   void _print(map<T, V> v) {     cerr <<  [  ;     for (auto i : v) {       _print(i);       cerr <<    ;     }     cerr <<  ] ;   }   const long long N = 1e6 + 5;   void solve() {     long long n;     cin >> n;     vector<vector<long long>> a;     for (long long i = 0; i < n; i++) {       long long x;       cin >> x;       vector<long long> temp(x);       for (long long j = 0; j < x; j++) cin >> temp[j];       a.push_back(temp);     }     set<vector<long long>> vis;     set<vector<long long>> banned;     long long m;     cin >> m;     for (long long i = 0; i < m; i++) {       vector<long long> temp(n);       for (long long j = 0; j < n; j++) {         cin >> temp[j];         temp[j]--;       }       banned.insert(temp);     }     set<pair<long long, vector<long long>>> st;     long long s = 0;     vector<long long> temp;     for (long long i = 0; i < n; i++) {       s += a[i][(long long)a[i].size() - 1];       temp.push_back((long long)a[i].size() - 1);     }     st.insert({s, temp});     vis.insert(temp);     while (!st.empty()) {       auto [val, vec] = *prev(st.end());       st.erase(prev(st.end()));       if (banned.find(vec) == banned.end()) {         for (auto i : vec) cout << i + 1 <<    ;         return;       }       for (long long i = 0; i < n; i++) {         if (vec[i] - 1 >= 0) {           long long newval = val - a[i][vec[i]] + a[i][vec[i] - 1];           vector<long long> newvec = vec;           newvec[i]--;           if (vis.find(newvec) == vis.end()) {             st.insert({newval, newvec});             vis.insert(newvec);           }         }       }     }   }   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long t = 1;     while (t--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       set<int> vec;       for (int i = 0; i < n; i++) {         int d;         cin >> d;         vec.insert(d);       }       cout << vec.size() <<   n ;     }   }


#include <bits/stdc++.h>   long long k;   int _, n, a[200020];   int main() {     for (scanf( %d , &_); _--;) {       scanf( %d%lld , &n, &k);       for (int i = 0; i < n; i++) scanf( %d , a + i);       for (int i = 0; i < (k & 1) + 2; i++)         for (int i = 0, d = *std::max_element(a, a + n); i < n; i++)           a[i] = d - a[i];       for (int i = 0 * puts(  ); i < n; i++) printf( %d  , a[i]);     }   }


#include <bits/stdc++.h>   using namespace std;   const long double PI = atan(1.0) * 4.0;   const long long int MOD = 1e9 + 7;   const long long int INF = 1e18;   const long double EPS = 0.0000001;   int main() {     ios_base::sync_with_stdio(false), cin.tie(NULL);     int n, k;     cin >> n >> k;     string s;     cin >> s;     map<char, int> a;     for (int i = 0; i < n; i++) a[s[i]]++;     int j = 97;     while (k != 0 && j <= 122) {       for (int i = 0; i < n; i++) {         if (s[i] == char(j)) {           s[i] =  * ;           k--;           if (k == 0) break;         }       }       j++;     }     for (int i = 0; i < n; i++) {       if (s[i] !=  * ) cout << s[i];     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct abc {     int val, key, s, e, ind;   } z[100005];   bool cmp(abc a, abc b) {     if (a.key == b.key) return a.val < b.val;     return a.key > b.key;   }   bool cmp1(abc a, abc b) { return a.ind < b.ind; }   int main() {     int n, m, i, j, k, a[100005], l;     scanf( %d , &n);     scanf( %d , &m);     for (i = 0; i < m; i++) {       scanf( %d , &z[i].val);       scanf( %d , &z[i].key);       z[i].ind = i;     }     sort(z, z + m, cmp);     for (i = 0; i < n - 1; i++) {       z[i].s = i + 1;       z[i].e = i + 2;     }     l = 1;     j = 1;     k = 3;     for (i = n - 1; i < m; i++) {       if (z[i].val >= z[k - 2].val) {         z[i].s = j;         z[i].e = k;         j++;         if (j == k - 1) {           j = 1;           k++;         }       } else {         l = 0;         break;       }     }     if (l == 0)       printf( -1 n );     else {       sort(z, z + m, cmp1);       for (i = 0; i < m; i++) printf( %d %d n , z[i].s, z[i].e);     }     return 0;   }


#include <bits/stdc++.h>   #define int long long   #define mp make_pair   #define pb push_back   #define ld long double   #define pii pair<int,int>   #define sz(x) (int)x.size()   #define piii pair<pii,pii>   #define precise cout<<fixed<<setprecision(10)   #define st first   #define nd second   #define ins insert   #define vi vector<int>   #define BOOST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)   using namespace std;   const int MAX=5005;   pii p[MAX];   bool O[MAX];   int dist(pii a,pii b){      return (a.st-b.st)*(a.st-b.st)+(a.nd-b.nd)*(a.nd-b.nd);   }   int32_t main(){     BOOST;     int n;     cin>>n;     for (int i=1;i<=n;i++){       cin>>p[i].st>>p[i].nd;     }          vi ans;     ans.clear();     ans.pb(1);     O[1]=true;     while (sz(ans)<n){       int x=ans.back();       int maxi=0,wsk=-1;       for (int i=1;i<=n;i++){         if (!O[i] && dist(p[x],p[i])>maxi){            maxi=dist(p[x],p[i]);            wsk=i;         }       }       assert(wsk!=-1);       O[wsk]=true;       ans.pb(wsk);     }     for (auto it:ans)cout<<it<<   ;     return 0;    }


#include <bits/stdc++.h>   using namespace std;   const int maxN = 2e5 + 9, lg = 19, MOD = 998244353, maxV = 1e3 + 9;   int T[3][maxN], n, q, arr[maxN], mp[129];   priority_queue<int> pqs[2][3];   string st;   int query(int w, int *T) {     int ret = 0;     for (w++; w > 0; w -= w & -w) ret += T[w];     return ret;   }   int query(int l, int r, int *T) { return query(r - 1, T) - query(l - 1, T); }   void update(int w, int x, int *T) {     for (w++; w <= n; w += w & -w) T[w] += x;   }   pair<int, int> getpa(int heroe, int mamon, priority_queue<int> *pqs) {     if (pqs[mamon].empty()) return pair<int, int>(n, n);     if (pqs[heroe].empty()) return pair<int, int>(0, pqs[mamon].top());     return pair<int, int>(min(pqs[mamon].top(), pqs[heroe].top()),                           pqs[mamon].top());   }   pair<int, int> gira(pair<int, int> x) {     return pair<int, int>(n - x.second, n - x.first);   }   int mergpl(pair<int, int> one, pair<int, int> two, int *lT) {     if (one > two) swap(one, two);     if (two.first < one.second)       return query(one.first, max(one.second, two.second), lT);     return query(one.first, one.second, lT) + query(two.first, two.second, lT);   }   int countGood() {     int ret = 0;     for (int u = 0, offs = 0, mu = 1; u < 2; u++, offs = n - 1, mu = -1)       for (int i = 0; i < 3; i++)         while (pqs[u][i].size() && arr[offs + mu * pqs[u][i].top()] != i)           pqs[u][i].pop();     for (int i = 0; i < 3; i++) {       int heroe = (i + 1) % 3, mamon = (i + 2) % 3;       ret += query(n - 1, T[i]) - mergpl(getpa(heroe, mamon, pqs[0]),                                          gira(getpa(heroe, mamon, pqs[1])), T[i]);     }     return ret;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     mp[ R ] = 1;     mp[ S ] = 2;     cin >> n >> q >> st;     for (int i = 0; i < n; i++) {       arr[i] = mp[st[i]];       pqs[0][arr[i]].push(i);       pqs[1][arr[i]].push(n - 1 - i);       update(i, 1, T[arr[i]]);     }     cout << countGood() <<   n ;     while (q--) {       int pos;       char c;       cin >> pos >> c;       pos--;       update(pos, -1, T[arr[pos]]);       arr[pos] = mp[c];       update(pos, 1, T[arr[pos]]);       pqs[0][arr[pos]].push(pos);       pqs[1][arr[pos]].push(n - 1 - pos);       cout << countGood() <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   const int NN = 1010;   double first[NN], second[NN];   int main() {     int n, a, b, c, d;     cin >> n;     for (int i = 0; i < n; i++) {       scanf( %d%d%d%d , &a, &b, &c, &d);       double s = a * a * d * d + c * c * b * b;       first[i] = a * b * d * d / s;       second[i] = c * b * b * d / s;     }     const double eps = 1e-9;     vector<pair<pair<double, double>, double> > line(n * (n - 1) / 2);     for (int i = 0, id = 0; i < n; i++)       for (int j = i + 1; j < n; j++, id++) {         line[id] =             make_pair(make_pair(first[i] + first[j], second[i] + second[j]),                       fabs(first[i] - first[j]) < eps                           ? 1e9                           : (second[i] - second[j]) / (first[i] - first[j]));       }     sort(line.begin(), line.end(),          [&](const pair<pair<double, double>, double> &a,              const pair<pair<double, double>, double> &b) {            if (fabs(a.first.first - b.first.first) > eps)              return a.first.first < b.first.first;            if (fabs(a.first.second - b.first.second) > eps)              return a.first.second < b.first.second;            return a.second < b.second - eps;          });     auto cmp1 = [&](double first, double second) {       return fabs(first - second) < eps;     };     auto cmp = [&](pair<double, double> first, pair<double, double> second) {       return cmp1(first.first, second.first) && cmp1(first.second, second.second);     };     int ans = 0;     const int mod = 1000000007;     for (int i = 0, j, k; i < line.size(); i = j) {       int mid = 1;       for (j = i; j < line.size() && cmp(line[i].first, line[j].first); j = k) {         for (k = j; k < line.size() && cmp(line[k].first, line[j].first) &&                     cmp1(line[j].second, line[k].second);              k++)           ;         mid = (long long)mid * (k - j + 1) % mod;       }       mid = (mid + mod - 1 - j + i) % mod;       ans += mid;       if (ans >= mod) ans -= mod;     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long t;     cin >> t;     while (t--) {       set<pair<pair<long long, long long>, pair<long long, long long> > > rem;       long long xi = 0, yi = 0, xf = 0, yf = 0;       string s;       cin >> s;       long long ans = 0;       for (long long i = 0; i < (long long)(s.length()); ++i) {         if (s[i] ==  N ) {           yf++;         } else if (s[i] ==  S ) {           yf--;         } else if (s[i] ==  E ) {           xf++;         } else {           xf--;         }         if (rem.count({{xi, yi}, {xf, yf}})) {           ans += 1;         } else {           ans += 5;           rem.insert({{xi, yi}, {xf, yf}});           rem.insert({{xf, yf}, {xi, yi}});         }         xi = xf;         yi = yf;       }       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MAXN = 1e5 + 7;   long long n;   pair<long double, long double> a[MAXN];   void read() {     cin >> n;     for (long long i = 0; i < n; ++i) {       cin >> a[i].first >> a[i].second;     }     bool ch1 = 0, ch2 = 0;     for (long long i = 0; i < n; ++i) {       if (a[i].second < 0)         ch1 = 1;       else         ch2 = 1;     }     if (ch1 && ch2) {       cout <<  -1 n ;       exit(0);     }   }   const long double INF = 1e16;   const long long IT = 100;   bool check(long double r) {     long double tl = -INF, tr = INF;     for (long long i = 0; i < n; ++i) {       if (abs(a[i].second - r) > r) return 0;       long double d = sqrtl(r * r - (a[i].second - r) * (a[i].second - r));       tl = max(tl, a[i].first - d);       tr = min(tr, a[i].first + d);     }     return tl <= tr;   }   long double ans = INF;   void solve() {     for (long long i = 0; i < n; ++i) a[i].second = abs(a[i].second);     long double l = 0;     long double r = INF;     for (long long i = 0; i < IT; ++i) {       long double m = (l + r) / 2;       if (check(m))         r = m;       else         l = m;     }     ans = r;   }   void print() { cout << ans <<   n ; }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.precision(20);     read();     solve();     print();     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   const int N = 1e6 + 5;   int n, k, top;   int a[N], l[N], r[N], s[N];   long long ans;   long long calc(int l, int r) {     if (l > r || r - l + 1 < k) return 0;     int m = (r - l + 2 - k) / (k - 1);     long long ret = 1LL * (m + 1) * (r - l + 2 - k) % mod -                     1LL * (1 + m) * m / 2 % mod * (k - 1) % mod;     return ret;   }   int main() {     int i;     scanf( %d%d , &n, &k);     for (i = 1; i <= n; ++i) scanf( %d , &a[i]);     for (i = 1; i <= n; ++i) {       while (top && a[s[top]] < a[i]) --top;       l[i] = s[top] + 1, s[++top] = i;     }     top = 0, s[top] = n + 1;     for (i = n; i; --i) {       while (top && a[s[top]] <= a[i]) --top;       r[i] = s[top] - 1, s[++top] = i;     }     for (i = 1; i <= n; ++i)       ans = (ans +              (calc(l[i], r[i]) - calc(l[i], i - 1) - calc(i + 1, r[i])) * a[i]) %             mod;     if (ans < 0) ans += mod;     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   int64_t k;   int a, b;   int result[9];   int ascore[9] = {0, 0, 1, 1, 0, 0, 0, 1, 0};   int bscore[9] = {0, 1, 0, 0, 0, 1, 1, 0, 0};   int stack[10];   int64_t atotalscore, btotalscore;   int cyclestart, cycleend, cyclelength;   int acyclescore, bcyclescore;   int64_t cycletime, cycleremain;   int main() {     int i, j, t;     scanf( %I64d%d%d , &k, &a, &b);     stack[0] = 3 * (a - 1) + (b - 1);     for (i = 0; i < 9; i++) {       scanf( %d , &t);       result[i] = 3 * (t - 1);     }     for (i = 0; i < 9; i++) {       scanf( %d , &t);       result[i] += (t - 1);     }     for (i = 1; i < k; i++) {       stack[i] = result[stack[i - 1]];       for (j = 0; j < i; j++) {         if (stack[i] == stack[j]) {           cyclestart = j;           cycleend = i - 1;           cyclelength = i - j;           break;         }       }       if (cyclelength != 0) break;     }     if (cyclelength == 0) {       for (i = 0; i < k; i++) {         atotalscore += ascore[stack[i]];         btotalscore += bscore[stack[i]];       }       printf( %I64d %I64d n , atotalscore, btotalscore);       return 0;     }     for (i = 0; i < cyclestart; i++) {       atotalscore += ascore[stack[i]];       btotalscore += bscore[stack[i]];     }     for (i = cyclestart; i <= cycleend; i++) {       acyclescore += ascore[stack[i]];       bcyclescore += bscore[stack[i]];     }     cycletime = (k - cyclestart) / cyclelength;     cycleremain = (k - cyclestart) % cyclelength;     atotalscore += acyclescore * cycletime;     btotalscore += bcyclescore * cycletime;     for (i = cyclestart; i < cyclestart + cycleremain; i++) {       atotalscore += ascore[stack[i]];       btotalscore += bscore[stack[i]];     }     printf( %I64d %I64d n , atotalscore, btotalscore);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, x[100005], y[100005];   bool sign(int t) { return (t > 0); }   bool check(long double r) {     vector<pair<long double, long double> > v;     for (int i = 0; i < n; i++) {       long double t = (2.0 * r - y[i]) * y[i];       if (t < 0) return 0;       long double l = sqrt(t);       v.push_back({-l + x[i], l + x[i]});     }     long double mn = 1e18, mx = -1e18;     for (auto p : v) {       mn = min(mn, p.second);       mx = max(mx, p.first);     }     return (mx <= mn);   }   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %d%d , &x[i], &y[i]);       if (sign(y[i]) != sign(y[0])) {         printf( -1 );         return 0;       }     }     for (int i = 0; i < n; i++) y[i] = abs(y[i]);     long double st = 0.0, en = 1e14;     for (int _ = 0; _ < 100; _++) {       long double mid = (st + en) / 2;       if (check(mid))         en = mid;       else         st = mid;     }     printf( %.9Lf , st);   }


#include <bits/stdc++.h>   using namespace std;   const int N = 5005;   const int M = 1005;   const int K = 15;   int n, m;   char name[N][K], oper[N][K], val[N][M];   bool isV[N];   int idx1[N], idx2[N];   map<string, int> mp;   char ansmx[M], ansmn[M];   int res[N];   int work(int a, int b, char op[]) {     if (op[0] ==  A ) return a & b;     if (op[0] ==  O ) return a | b;     return a ^ b;   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 0; i < n; i++) {       scanf( %s , name[i]);       mp[name[i]] = i;       char buf[M];       scanf( %s , buf);       scanf( %s , buf);       if (buf[0] >=  0  && buf[0] <=  9 ) {         memcpy(val[i], buf, sizeof(buf));         isV[i] = 0;       } else {         isV[i] = 1;         idx1[i] = buf[0] ==  ?  ? -1 : mp[buf];         scanf( %s , oper[i]);         scanf( %s , buf);         idx2[i] = buf[0] ==  ?  ? -1 : mp[buf];       }     }     for (int i = 0; i < m; i++) {       int ans[2] = {0, 0};       for (int j = 0; j < 2; j++) {         for (int k = 0; k < n; k++) {           if (!isV[k])             res[k] = (val[k][i] -  0 );           else {             int op1 = idx1[k] == -1 ? j : res[idx1[k]];             int op2 = idx2[k] == -1 ? j : res[idx2[k]];             res[k] = work(op1, op2, oper[k]);           }           ans[j] += res[k];         }       }       if (ans[0] == ans[1])         ansmx[i] = ansmn[i] =  0 ;       else {         ansmx[i] = ans[0] > ans[1] ?  0  :  1 ;         ansmn[i] = ans[0] < ans[1] ?  0  :  1 ;       }     }     printf( %s n%s n , ansmn, ansmx);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int64_t INF = 1e18 + 10;   const int N = 2e7 + 10;   int MOD = 1000000007;   int g[26], in[26], used[26];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     for (int i = 0; i < 26; i++) g[i] = -1;     int n;     cin >> n;     vector<string> a(n,   );     bool arr = 1;     for (int i = 0; i < n; i++) {       string s;       cin >> s;       for (auto j : s) used[j -  a ] = 1;       for (int j = 1; j < s.size(); j++) {         int u = s[j - 1] -  a ;         if (g[u] != -1 && g[u] != s[j] -  a  || s[j] == s[j - 1]) arr = 0;         g[s[j - 1] -  a ] = s[j] -  a ;         in[s[j] -  a ]++;       }     }     if (!arr) {       cout <<  NO ;       return 0;     }     string ans =   ;     for (int i = 0; i < 26; i++) {       if (in[i] == 0 && used[i]) {         int x = i;         while (x != -1) {           used[x]--;           if (used[x] < 0) break;           ans +=  a  + x;           x = g[x];         }       }     }     for (int i = 0; i < 26; i++) {       if (used[i] != 0) arr = 0;     }     if (arr)       cout << ans;     else       cout <<  NO ;   }


#include <bits/stdc++.h>   using namespace std;   using vl = vector<long long>;   using vpl = vector<pair<long long, long long>>;   using vs = vector<string>;   using pl = pair<long long, long long>;   using ll = long long int;   using vb = vector<bool>;   void printcase(ll x) { cout <<  Case #  << x <<  :  ; }   void read(vector<ll> &v, ll &n) {     for (ll i = 0; i < n; ++i) cin >> v[i];   }   void read(ll a[], ll &n) {     for (ll i = 0; i < n; ++i) cin >> a[i];   }   void print() { cout << endl; }   void write(vector<ll> &v, ll &n) {     for (ll i = 0; i < n; ++i) cout << v[i] <<    ;     cout << endl;   }   void write(vector<ll> &v) {     ll n = v.size();     for (ll i = 0; i < n; ++i) cout << v[i] <<    ;     cout << endl;   }   void write(ll a[], ll &n) {     for (ll i = 0; i < n; ++i) cout << a[i] <<    ;     cout << endl;   }   bool sorted(vl &v) {     ll n = v.size();     for (int i = 0; i < n - 1; i++) {       if (v[i] > v[i + 1]) return 0;     }     return 1;   }   bool solve() {     ll n;     cin >> n;     vl v(n);     read(v, n);     if (n <= 2) return 1;     vl suff(n), suffind(n), preind(n);     suff[n - 1] = v[n - 1];     suffind[n - 1] = n - 1;     preind[0] = 0;     for (int i = 1; i < n; i++) {       if (v[i] == v[i - 1])         preind[i] = preind[i - 1];       else         preind[i] = i;     }     for (int i = n - 2; i >= 0; i--) {       if (v[i] < suff[i + 1])         suffind[i] = i;       else         suffind[i] = suffind[i + 1];       suff[i] = min(v[i], suff[i + 1]);     }     for (int i = 0; i < n - 1; i++) {       if (v[i] > v[i + 1]) {         swap(v[preind[i]], v[suffind[i + 1]]);         if (sorted(v))           return 1;         else           return 0;       }     }     return 1;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     if (solve())       cout <<  YES  << endl;     else       cout <<  NO  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct plan {     bool used;     int type;     int single;     int start;     int end;     long long cost;   };   void getInput(vector<plan> &plans, vector<vector<int> > &outs,                 vector<forward_list<int> > &segtree);   void addPlan(vector<forward_list<int> > &segtree, int st_ind, int cs, int ce,                int ds, int de, int pi);   void getMinCosts(vector<long long> &min_costs, int source,                    vector<vector<int> > &outs,                    vector<forward_list<int> > &segtree, vector<plan> &plans);   void processNode(int n, vector<bool> &visited, set<int> &unvisited,                    priority_queue<pair<long long, int> > &to_visit,                    vector<vector<int> > &outs,                    vector<forward_list<int> > &segtree, vector<plan> &plans,                    long long cur_cost, vector<long long> &min_costs);   int main() {     int num_planets, num_plans, source;     cin >> num_planets >> num_plans >> source;     source--;     vector<long long> min_costs(num_planets, LLONG_MAX);     min_costs[source] = 0;     vector<vector<int> > outs(num_planets);     vector<forward_list<int> > segtree(2 *                                        pow(2, ceil(log(num_planets) / log(2))));     vector<plan> plans(num_plans);     getInput(plans, outs, segtree);     getMinCosts(min_costs, source, outs, segtree, plans);     for (int i = 0; i < min_costs.size(); i++)       cout << ((min_costs[i] < LLONG_MAX) ? min_costs[i] : -1) <<    ;     cout <<   n ;     return 0;   }   void getInput(vector<plan> &plans, vector<vector<int> > &outs,                 vector<forward_list<int> > &segtree) {     for (int pi = 0; pi < plans.size(); pi++) {       plans[pi].used = false;       cin >> plans[pi].type >> plans[pi].single >> plans[pi].start;       plans[pi].type -= 2;       if (plans[pi].type >= 0)         cin >> plans[pi].end;       else {         plans[pi].end = plans[pi].start;         plans[pi].type = 0;       }       plans[pi].single--;       plans[pi].start--;       plans[pi].end--;       cin >> plans[pi].cost;       if (plans[pi].type == 0)         outs[plans[pi].single].push_back(pi);       else         addPlan(segtree, 1, 0, segtree.size() / 2 - 1, plans[pi].start,                 plans[pi].end, pi);     }   }   void addPlan(vector<forward_list<int> > &segtree, int st_ind, int cs, int ce,                int ds, int de, int pi) {     if (cs > de || ce < ds)       return;     else if (cs >= ds && ce <= de)       segtree[st_ind].push_front(pi);     else {       int cm = (cs + ce) / 2;       addPlan(segtree, 2 * st_ind, cs, cm, ds, de, pi);       addPlan(segtree, 2 * st_ind + 1, cm + 1, ce, ds, de, pi);     }   }   void getMinCosts(vector<long long> &min_costs, int source,                    vector<vector<int> > &outs,                    vector<forward_list<int> > &segtree, vector<plan> &plans) {     vector<bool> visited(min_costs.size(), false);     set<int> unvisited;     for (int i = 0; i < min_costs.size(); i++) unvisited.insert(i);     priority_queue<pair<long long, int> > to_visit;     processNode(source, visited, unvisited, to_visit, outs, segtree, plans, 0,                 min_costs);     while (to_visit.size() > 0) {       int cur_pi = to_visit.top().second;       long long cur_cost = -to_visit.top().first;       to_visit.pop();       if (plans[cur_pi].type == 0) {         set<int>::iterator s_it = unvisited.lower_bound(plans[cur_pi].start);         set<int>::iterator e_it = unvisited.upper_bound(plans[cur_pi].end);         for (set<int>::iterator it = s_it; it != e_it;) {           int n = *it;           it++;           processNode(n, visited, unvisited, to_visit, outs, segtree, plans,                       cur_cost, min_costs);         }       } else {         if (!visited[plans[cur_pi].single])           processNode(plans[cur_pi].single, visited, unvisited, to_visit, outs,                       segtree, plans, cur_cost, min_costs);       }     }   }   void processNode(int n, vector<bool> &visited, set<int> &unvisited,                    priority_queue<pair<long long, int> > &to_visit,                    vector<vector<int> > &outs,                    vector<forward_list<int> > &segtree, vector<plan> &plans,                    long long cur_cost, vector<long long> &min_costs) {     if (visited[n]) return;     min_costs[n] = cur_cost;     visited[n] = true;     unvisited.erase(n);     for (auto &out : outs[n])       to_visit.push(make_pair(-(cur_cost + plans[out].cost), out));     for (int st_ind = segtree.size() / 2 + n; st_ind > 0; st_ind /= 2) {       for (auto &pi : segtree[st_ind])         if (!plans[pi].used) {           plans[pi].used = true;           to_visit.push(make_pair(-(cur_cost + plans[pi].cost), pi));         }       segtree[st_ind].clear();     }   }


#include <bits/stdc++.h>   using namespace std;   const int M = INT32_MAX;   const int NMAX = 10007;   int main() {     cin.tie(0);     cin.sync_with_stdio(0);     cout.precision(30);     string z[2];     cin >> z[0] >> z[1];     int n;     cin >> n;     cout << z[1] <<     << z[0] << endl;     for (int i = 0; i < n; i++) {       string k, next;       cin >> k >> next;       if (k == z[1])         z[1] = next;       else         z[0] = next;       cout << z[1] <<     << z[0] << endl;     }     return 0;   };


#include <bits/stdc++.h>   using namespace std;   pair<int, int> arr[200000];   int ans[200000], tree[500000], lazy[500000];   set<int> s;   int n;   set<int>::iterator it;   int main() {     ios::sync_with_stdio(false);     cin >> n;     for (int i = 0; i < n; i++) {       cin >> arr[i].first;       arr[i].second = i;     }     sort(arr, arr + n);     int l, r, mn = arr[0].second, len;     for (int i = 0; i < n; i++) {       ans[i] = arr[0].first;     }     s.insert(arr[0].second);     for (int i = 1; i < n; i++) {       it = s.lower_bound(arr[i].second);       r = *it;       if (it == s.end()) {         r = n;       }       if (*it == mn) {         l = -1;       } else {         it--;         l = *it;       }       mn = min(mn, arr[i].second);       s.insert(arr[i].second);       len = r - l - 1;       ans[len - 1] = max(arr[i].first, ans[len - 1]);     }     for (int i = n - 2; i >= 0; i--) {       ans[i] = max(ans[i], ans[i + 1]);     }     for (int i = 0; i < n; i++) {       cout << ans[i] <<    ;     }   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 1e9 + 7;   int arr[200005];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     if (n % 2 == 0) {       cout <<  NO n ;       return 0;     }     int flag = 1, ct = 1;     for (int i = 1; i <= n; i++) {       if (flag) {         arr[i] = ct;         arr[n + i] = ct + 1;         flag = 0;       } else {         arr[i] = ct + 1;         arr[n + i] = ct;         flag = 1;       }       ct += 2;     }     cout <<  YES n ;     for (int i = 1; i <= 2 * n; i++) {       cout << arr[i] <<    ;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     vector<int> a;     scanf( %d%d , &n, &m);     int min = n + 2;     for (int i = 0; i < m; i++) {       int t;       scanf( %d , &t);       if (t < min) {         a.push_back(t);         min = t;       }       if (t == 1) break;     }     sort(a.begin(), a.end());     for (int i = 0; i < a.size() - 1; i++)       for (int j = 0; j < a[i + 1] - a[i]; j++) printf( %d  , a[i]);     for (int i = 0; i < n - a.back(); i++) printf( %d  , a.back());     printf( %d n , a.back());   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     int t = 1;     while (t--) {       map<char, long long int> a, b;       long long int n;       cin >> n;       string s, t;       cin >> s >> t;       for (long long int i = 0; i < n; i++) a[s[i]]++, b[t[i]]++;       vector<long long int> ans;       if (a != b)         cout << -1;       else {         if (s == t)           cout << 0;         else {           std::vector<int> move;           for (int i = n - 1; i >= 0; --i) {             if (s[i] != t[i]) {               int j = i - 1;               for (j = i - 1; j >= 0; --j) {                 if (s[j] == t[i]) break;               }               while (j < i) {                 move.push_back(j + 1);                 swap(s[j], s[j + 1]);                 ++j;               }             }           }           cout << move.size() <<   n ;           for (int x : move) cout << x <<    ;         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int f;   vector<string> cur;   void upd(string s, int x, int y, int o) {     int dx = 0, dy = 1;     if (o) swap(dx, dy);     for (int i = 0; i < s.size(); i++) {       int xx = x + dx * i;       int yy = y + dy * i;       if (cur[xx][yy] ==  .  || cur[xx][yy] == s[i]) {         cur[xx][yy] = s[i];       } else {         f = 0;       }     }   }   int main() {     vector<string> a(6);     for (auto &x : a) {       cin >> x;     }     sort((a).begin(), (a).end());     vector<string> ans = { Z };     ans[0][0]++;     vector<string> ans0 = ans;     do {       f = 1;       vector<int> b;       vector<int> c;       for (int t = 0; t < 6; t += 3) {         int mx = 0;         int s = 0;         for (int i = t; i < t + 3; i++) {           s += a[i].size();           mx = max(mx, (int)a[i].size());         }         for (int i = t; i < t + 3; i++) {           if (a[i].size() == mx) {             b.push_back(i);             break;           }         }         if (s - 2 * mx != 1) {           f = 0;         }       }       for (int i = 0; i < 6; i++) {         if (i != b[0] && i != b[1]) {           c.push_back(i);         }       }       if (f) {         vector<int> bb, cc;         for (auto x : b) bb.push_back(a[x].size());         for (auto x : c) cc.push_back(a[x].size());         string t;         for (int i = 0; i < bb[1]; i++) {           t.push_back( . );         }         cur = vector<string>(bb[0], t);         upd(a[c[0]], 0, 0, 1);         upd(a[c[2]], 0, 0, 0);         upd(a[b[0]], 0, cc[2] - 1, 1);         upd(a[b[1]], cc[0] - 1, 0, 0);         upd(a[c[1]], cc[0] - 1, bb[1] - 1, 1);         upd(a[c[3]], bb[0] - 1, cc[2] - 1, 0);       }       if (f) {         if (cur < ans) ans = cur;       }     } while (next_permutation((a).begin(), (a).end()));     if (ans == ans0) {       cout <<  Impossible  << endl;       return 0;     }     for (auto s : ans) {       cout << s << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long mod(long long a, long long b) {     if (a % b < 0) {       return a % b + b;     }     return a % b;   }   long long mod_exp(long long a, long long b, long long c) {     long long res = 1;     a = a % c;     while (b > 0) {       if (b % 2 == 1) {         res = (res * a) % c;       }       b /= 2;       a = (a * a) % c;     }     return res;   }   long long gcd(long long a, long long b) {     if (b == 0) {       return a;     }     return gcd(b, a % b);   }   bool prime[3001];   void SieveOfEratosthenes() {     memset(prime, true, sizeof(prime));     prime[1] = false;     for (int p = 2; p * p <= 3000; p++) {       if (prime[p] == true) {         for (int i = p * p; i <= 3000; i += p) prime[i] = false;       }     }   }   long long powe[20];   void power() {     powe[0] = 1;     for (long long i = 1; i < 20; i++) {       powe[i] = (powe[i - 1] * 10) % 1000000007;       if (powe[i] < 0) powe[i] += 1000000007;     }   }   long long func(long long A[], long long n) {     long long lis[n];     lis[0] = 1;     for (long long i = 0; i < n; i++) {       lis[i] = 1;     }     return lis[0];   }   void solve() {     long long a, b, c;     cin >> a >> b >> c;     if ((c >= b && b >= a) || (a >= b && b >= c)) {       if (a >= b && b >= c) {         swap(a, c);       }       while (b > (a + c) / 2) {         b--;         a++;       }       while (b < (a + c) / 2) {         b++;         c--;       }       cout << ((((a > b) ? a : b) > c) ? ((a > b) ? a : b) : c) <<   n ;       return;     }   }   int main() {     long long n, a, b, c;     cin >> n;     cout <<   n? 1 2 n ;     fflush(stdout);     cin >> a;     cout <<  ? 2 3 n ;     fflush(stdout);     cin >> b;     cout <<  ? 1 3 n ;     fflush(stdout);     cin >> c;     long long A[n];     A[0] = (a + c - b) / 2;     A[1] = a - A[0];     A[2] = c - A[0];     for (long long i = 3; i < n; i++) {       cout <<  ? 1   << i + 1 <<   n ;       fflush(stdout);       cin >> a;       A[i] = a - A[0];     }     cout <<  !  ;     for (long long i = 0; i < n; i++) {       cout << A[i] <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 3e5 + 5;   struct ACA {     int pool[N], ptp;     int stk[30], sz[N], rt[N], rtid, tp;     int nxt[N][26], tran[N][26], fail[N], end[N], num[N], tot;     inline int newnode() { return ++tot; }     int merge(int x, int y) {       if (!x || !y) return x | y;       for (int i = 0; i < 26; i++) nxt[x][i] = merge(nxt[x][i], nxt[y][i]);       end[x] += end[y];       pool[++ptp] = y;       return x;     }     void build(int p) {       queue<int> q;       for (int i = 0; i < 26; i++)         if (nxt[p][i])           fail[tran[p][i] = nxt[p][i]] = p, q.push(nxt[p][i]);         else           tran[p][i] = p;       while (!q.empty()) {         int k = q.front();         q.pop();         num[k] = end[k] + num[fail[k]];         for (int i = 0; i < 26; i++) {           if (nxt[k][i]) {             fail[tran[k][i] = nxt[k][i]] = tran[fail[k]][i];             q.push(tran[k][i]);           } else             tran[k][i] = tran[fail[k]][i];         }       }     }     void ins(char *s, int n, int v) {       rt[++rtid] = newnode();       sz[rtid] = 1;       int p = rt[rtid];       for (int i = 0; i < n; i++) {         int k = s[i] -  a ;         if (!nxt[p][k]) nxt[p][k] = newnode();         p = nxt[p][k];       }       end[p] += v;       while (tp && sz[stk[tp]] < 2 * sz[rtid])         rt[rtid] = merge(rt[rtid], rt[stk[tp]]), sz[rtid] += sz[stk[tp]], --tp;       build(rt[rtid]);       stk[++tp] = rtid;     }     int qry(char *s, int n) {       int ans = 0;       for (int i = 1; i <= tp; i++) {         int p = rt[stk[i]];         for (int i = 0; i < n; i++) {           p = tran[p][s[i] -  a ];           ans += num[p];         }       }       return ans;     }   } ac;   int main() {     int m;     scanf( %d , &m);     for (int i = 1; i <= m; i++) {       static char s[N];       int op;       scanf( %d%s , &op, s);       if (op == 1)         ac.ins(s, strlen(s), 1);       else if (op == 2)         ac.ins(s, strlen(s), -1);       else         printf( %d n , ac.qry(s, strlen(s))), fflush(stdout);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 1, logN = 21 + 1, mod = 1e9 + 7;   int fl(int n) {     int ans = 0;     while (n /= 2) ++ans;     return ans;   }   int ord2(int n) {     int ans = 0;     while (n % 2 == 0) {       n >>= 1;       ++ans;     }     return ans;   }   long long binpow(long long a, long long s) {     long long ans = 1;     while (s) {       if (s & 1) ans = ans * a % mod;       a = a * a % mod;       s >>= 1;     }     return ans;   }   long long inv(long long a) { return binpow(a, mod - 2); }   long long f[N], finv[N];   void init() {     f[0] = 1;     finv[0] = 1;     for (long long i = 1; i < N; ++i) {       f[i] = f[i - 1] * i % mod;       finv[i] = inv(f[i]);     }   }   int n, logn;   int cnt[logN];   long long solve(int k) {     for (int i = 0; i < logn; ++i) cnt[i] = 0;     for (int i = 1; i <= n; ++i) {       int ord = ord2(i);       if (ord < k)         ++cnt[ord];       else if (ord >= k) {         if (i % 3)           ++cnt[k];         else           ++cnt[ord + 1];       }     }     long long ans = 1;     for (int i = 0; i < logn; ++i) ans = ans * cnt[i] % mod;     ans = ans * f[cnt[0] - 1] % mod;     int sum = cnt[0] - 1;     for (int i = 1; i < logn; ++i) {       ans = ans * (f[sum + cnt[i]] * finv[sum + 1] % mod) % mod;       sum += cnt[i];     }     return ans;   }   int main() {     ios_base::sync_with_stdio(false);     cout.tie(0);     cin.tie(0);     init();     cin >> n;     logn = fl(n) + 1;     long long ans = 0;     for (int i = 0; i < logn; ++i) ans = (ans + solve(i)) % mod;     cout << ans <<   n ;   }


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


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     int a[100005];     int b[100005];     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d%d , &a[i], &b[i]);     }     int flag = 1;     if (n % 2 == 0)       for (int i = 1; i < n / 2; i++) {         if (a[i] + a[i + n / 2] != a[i + 1] + a[i + 1 + n / 2] ||             b[i] + b[i + n / 2] != b[i + 1] + b[i + 1 + n / 2]) {           flag = 0;           break;         }       }     else       flag = 0;     if (flag)       printf( YES n );     else       printf( NO n );   }


#include <bits/stdc++.h>   using namespace std;   long long po(long long a, long long b) {     long long x = 1, y = a;     while (b > 0) {       if (b % 2) {         x = x * y;         x %= 1000000007;       }       y = y * y;       y %= 1000000007;       b /= 2;     }     return x;   }   int main() {     if (0) {       freopen( C:/Users/gold/Desktop/sublime IO/input.txt ,  r , stdin);       freopen( C:/Users/gold/Desktop/sublime IO/output.txt ,  w , stdout);     }     int T = 1;     while (T--) {       string s, s1;       cin >> s >> s1;       int n = s.length();       static int cnt[256];       for (int i = 0; i < n; i++) {         cnt[s[i]]++;       }       int m = s1.length();       int ans = 0, ans1 = 0;       for (int i = 0; i < m; i++) {         if (cnt[s1[i]] > 0) {           cnt[s1[i]]--;           ans++;           s1[i] =  1 ;         }       }       for (int i = 0; i < m; i++) {         if (s1[i] ==  1 ) {           continue;         }         if (s1[i] >=  a  && cnt[s1[i] -  a  +  A ] > 0) {           ans1++;           cnt[s1[i] -  a  +  A ]--;         } else if (cnt[s1[i] -  A  +  a ] > 0) {           ans1++;           cnt[s1[i] -  A  +  a ]--;         }       }       printf( %d %d n , ans, ans1);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1000100;   int n, q, s[N / 2], f[N / 2], par[N / 2], timer;   vector<int> g[N / 2];   void dfs(int x = 1, int pp = 0) {     s[x] = ++timer;     par[x] = pp;     for (auto &it : g[x])       if (it != par[x]) {         dfs(it, x);       }     f[x] = ++timer;   }   struct node {     int sum;     bool set;     void merge(node &lt, node &rt) { sum = lt.sum + rt.sum; }   } st[N << 2];   void push(int x, int lx, int rx) {     if (st[x].set) {       st[x].set = 0;       st[x].sum = rx - lx + 1;       if (lx == rx) return;       st[x << 1].set = st[x << 1 | 1].set = 1;     }   }   void bld(int x = 1, int lx = 1, int rx = n + n) {     if (lx == rx) {       st[x] = {0, 0};       return;     }     int mid = lx + rx >> 1;     bld(x << 1, lx, mid);     bld(x << 1 | 1, mid + 1, rx);     st[x].merge(st[x << 1], st[x << 1 | 1]);   }   void modify(bool z, int &u, int &v, int x = 1, int lx = 1, int rx = n + n) {     push(x, lx, rx);     if (v < lx or u > rx) return;     if (u <= lx and rx <= v) {       if (z) {         st[x].set = 1;         push(x, lx, rx);       } else {         st[x].sum = 0;       }       return;     }     int mid = lx + rx >> 1;     modify(z, u, v, x << 1, lx, mid);     modify(z, u, v, x << 1 | 1, mid + 1, rx);     st[x].merge(st[x << 1], st[x << 1 | 1]);   }   int qry(int &u, int &v, int x = 1, int lx = 1, int rx = n + n) {     push(x, lx, rx);     if (v < lx or u > rx) return 0;     if (u <= lx and rx <= v) return st[x].sum;     int mid = lx + rx >> 1;     return qry(u, v, x << 1, lx, mid) + qry(u, v, x << 1 | 1, mid + 1, rx);   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n;     for (int u, v, i = 1; i < n; i++) {       cin >> u >> v;       g[u].emplace_back(v);       g[v].emplace_back(u);     }     timer = 0;     dfs();     bld();     cin >> q;     int ty, v;     while (q--) {       cin >> ty >> v;       if (ty == 1) {         if (par[v] != 0 and qry(s[v], f[v]) != f[v] - s[v] + 1) {           modify(0, s[par[v]], s[par[v]]);         }         modify(1, s[v], f[v]);       } else if (ty == 2) {         modify(0, s[v], s[v]);       } else {         cout << (qry(s[v], f[v]) == f[v] - s[v] + 1) <<   n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 200005;   int n, k, root, col[N], sz[N];   vector<int> g[N], a[N];   int dfs(int v, int pr = -1) {     int mx = col[v];     sz[v] = col[v];     for (auto& to : g[v]) {       if (to == pr) continue;       int root = dfs(to, v);       if (root != -1) return root;       sz[v] += sz[to];       mx = max(mx, sz[to]);     }     mx = max(mx, 2 * k - sz[v]);     if (mx > k) return -1;     return v;   }   void go(int v, int pr = -1) {     priority_queue<pair<int, int>> q;     if (col[v]) {       a[v].push_back(v);       q.push({1, v});     }     for (auto& to : g[v]) {       if (to == pr) continue;       go(to, v);       if (pr != -1) {         if (a[v].size() < a[to].size()) {           a[v].swap(a[to]);         }         a[v].insert(a[v].end(), a[to].begin(), a[to].end());         a[to].clear();       } else {         if (!a[to].empty()) {           q.push({(int)a[to].size(), to});         }       }     }     if (pr == -1) {       while (!q.empty()) {         auto x = q.top();         q.pop();         auto y = q.top();         q.pop();         cout << a[x.second].back() + 1 <<     << a[y.second].back() + 1 <<                  << root + 1 <<   n ;         --x.first;         --y.first;         a[x.second].pop_back();         a[y.second].pop_back();         if (x.first > 0) q.push(x);         if (y.first > 0) q.push(y);       }     }   }   int main() {     ios::sync_with_stdio(false);     cin >> n >> k;     for (int(i) = 0; (i) < (n - 1); ++(i)) {       int x, y;       cin >> x >> y;       --x;       --y;       g[x].push_back(y);       g[y].push_back(x);     }     for (int(i) = 0; (i) < (2 * k); ++(i)) {       int x;       cin >> x;       --x;       col[x] = 1;     }     root = dfs(0);     cout << 1 <<   n  << root + 1 <<   n ;     go(root);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   #pragma comment(linker,  /STACK:100000000 )   int matrix[900][900];   int tmp[900][900];   int dx[4] = {1, 0, -1, 0};   int dy[4] = {0, 1, 0, -1};   vector<pair<int, int> > all;   void go(int x, int y) {     queue<pair<int, int> > q;     tmp[x][y] = 1;     q.push(make_pair(x, y));     all.push_back(make_pair(x, y));     while (!q.empty()) {       x = q.front().first;       y = q.front().second;       q.pop();       for (int i = 0; i < 4; i++) {         if (x + dx[i] >= 0 && x + dx[i] <= 799 && y + dy[i] >= 0 &&             y + dy[i] <= 799) {           if (matrix[x + dx[i]][y + dy[i]] != 255 &&               tmp[x + dx[i]][y + dy[i]] == 0) {             tmp[x + dx[i]][y + dy[i]] = 1;             q.push(make_pair(x + dx[i], y + dy[i]));             all.push_back(make_pair(x + dx[i], y + dy[i]));           }         }       }     }   }   vector<int> path;   int cnt = 0;   void bfs(int x1, int y1, int x2, int y2) {     for (int i = 0, maxi = (int)(all).size(); i < maxi; i++) {       int x = all[i].first;       int y = all[i].second;       tmp[x][y] = 0;     }     all.clear();     path.clear();     cnt = 0;     queue<pair<int, int> > q;     q.push(make_pair(x1, y1));     tmp[x1][y1] = 111;     all.push_back(make_pair(x1, y1));     while (!q.empty()) {       for (int i = 0, maxi = (int)(q).size(); i < maxi; i++) {         int x = q.front().first;         int y = q.front().second;         q.pop();         if (x == x2 && y == y2) {           cnt = 0;           while (x != x1 || y != y1) {             int j = tmp[x][y] - 1;             cnt++;             path.push_back(j);             x = x - dx[j];             y = y - dy[j];           }           return;         }         for (int j = 0; j < 4; j++) {           if (x + dx[j] >= 0 && x + dx[j] <= 799 && y + dy[j] >= 0 &&               y + dy[j] <= 799) {             if (matrix[x + dx[j]][y + dy[j]] != 255 &&                 tmp[x + dx[j]][y + dy[j]] == 0) {               tmp[x + dx[j]][y + dy[j]] = j + 1;               q.push(make_pair(x + dx[j], y + dy[j]));               all.push_back(make_pair(x + dx[j], y + dy[j]));             }           }         }       }     }   }   string ans =   ;   int main() {     int x1, y1, x2, y2;     scanf( %d %d %d %d , &x1, &y1, &x2, &y2);     x1 += 400;     y1 += 400;     x2 += 400;     y2 += 400;     int m;     scanf( %d , &m);     int max_x = 0, min_x = 800, max_y = 0, min_y = 800;     for (int i = 0; i < m; i++) {       int x, y;       scanf( %d %d , &x, &y);       x += 400;       y += 400;       min_x = min(min_x, x);       max_x = max(max_x, x);       min_y = min(min_y, y);       max_y = max(max_y, y);       matrix[x][y] = 255;     }     go(x1, y1);     if (m == 0 || tmp[x1][y1] != tmp[x2][y2]) {       printf( -1 );       return 0;     }     while (true) {       bfs(x1, y1, x2, y2);       reverse(path.begin(), path.end());       for (int i = 0; i < cnt; i++) {         if (path[i] == 0)           ans +=  R ;         else if (path[i] == 1)           ans +=  U ;         else if (path[i] == 2)           ans +=  L ;         else if (path[i] == 3)           ans +=  D ;         int j = path[i];         x1 += dx[j];         y1 += dy[j];         if (matrix[x2 + dx[j]][y2 + dy[j]] != 255) {           x2 += dx[j];           y2 += dy[j];           path.push_back(j);           cnt++;         }         if (min(y1, y2) > max_y || max(y1, y2) < min_y || min(x1, x2) > max_x ||             max(x1, x2) < min_x || x1 == x2 && y1 == y2)           break;       }       if (x1 == x2 && y1 == y2) {         cout << ans;         return 0;       }       bool flag = false;       if (min(y1, y2) > max_y) {         if (max(x1, x2) >= min_x) {           int diff = max(x1, x2) - min_x + 1;           x1 -= diff;           x2 -= diff;           for (int i = 0; i < diff; i++) ans +=  L ;         }         if (max(y1, y2) >= min_y) {           int diff = max(y1, y2) - min_y + 1;           y1 -= diff;           y2 -= diff;           for (int i = 0; i < diff; i++) ans +=  D ;         }         flag = true;       } else if (max(y1, y2) < min_y) {         if (max(x1, x2) >= min_x) {           int diff = max(x1, x2) - min_x + 1;           x1 -= diff;           x2 -= diff;           for (int i = 0; i < diff; i++) ans +=  L ;         }         if (max(y1, y2) >= min_y) {           int diff = max(y1, y2) - min_y + 1;           y1 -= diff;           y2 -= diff;           for (int i = 0; i < diff; i++) ans +=  D ;         }         flag = true;       } else if (min(x1, x2) > max_x) {         if (max(y1, y2) >= min_y) {           int diff = max(y1, y2) - min_y + 1;           y1 -= diff;           y2 -= diff;           for (int i = 0; i < diff; i++) ans +=  D ;         }         if (max(x1, x2) >= min_x) {           int diff = max(x1, x2) - min_x + 1;           x1 -= diff;           x2 -= diff;           for (int i = 0; i < diff; i++) ans +=  L ;         }         flag = true;       } else if (max(x1, x2) < min_x) {         if (max(y1, y2) >= min_y) {           int diff = max(y1, y2) - min_y + 1;           y1 -= diff;           y2 -= diff;           for (int i = 0; i < diff; i++) ans +=  D ;         }         if (max(x1, x2) >= min_x) {           int diff = max(x1, x2) - min_x + 1;           x1 -= diff;           x2 -= diff;           for (int i = 0; i < diff; i++) ans +=  L ;         }         flag = true;       }       if (flag) {         if (y2 > y1) {           int y = min_y;           int x;           for (int i = 290; i < 510; i++) {             if (matrix[i][y] == 255) {               x = i;               break;             }           }           if (x2 < x) {             int diff = x - x2;             x1 += diff;             x2 += diff;             for (int i = 0; i < diff; i++) ans +=  R ;           }           if (y2 != y1) {             int diff = y - y1 - 1;             y2 = y - 1;             y1 = y2;             for (int i = 0; i < diff; i++) ans +=  U ;           }         } else {           if (min(y1, y2) <= max_y) {             int diff = max_y - min(y1, y2) + 1;             y1 += diff;             y2 += diff;             for (int i = 0; i < diff; i++) ans +=  U ;           }           int y = max_y;           int x;           for (int i = 290; i < 510; i++) {             if (matrix[i][y] == 255) {               x = i;               break;             }           }           if (x2 < x) {             int diff = x - x2;             x1 += diff;             x2 += diff;             for (int i = 0; i < diff; i++) ans +=  R ;           }           if (y2 != y1) {             int diff = y1 - y - 1;             y1 -= diff;             y2 = y + 1;             for (int i = 0; i < diff; i++) ans +=  D ;           }         }         if (x2 > x1) {           if (max(x1, x2) >= min_x) {             int diff = max(x1, x2) - min_x + 1;             x2 -= diff;             x1 -= diff;             for (int i = 0; i < diff; i++) ans +=  L ;           }           if (max(y1, y2) >= min_y) {             int diff = max(y1, y2) - min_y + 1;             y2 -= diff;             y1 -= diff;             for (int i = 0; i < diff; i++) ans +=  D ;           }           int x = min_x;           int y;           for (int i = 290; i < 510; i++) {             if (matrix[x][i] == 255) {               y = i;               break;             }           }           if (y1 < y) {             int diff = y - y1;             y1 += diff;             y2 += diff;             for (int i = 0; i < diff; i++) ans +=  U ;           }           if (x2 != x1) {             int diff = x - x1 - 1;             x1 += diff;             x2 = x - 1;             for (int i = 0; i < diff; i++) ans +=  R ;           }           cout << ans;           return 0;         } else {           if (min(x1, x2) <= max_x) {             int diff = max_x - min(x1, x2) + 1;             x1 += diff;             x2 += diff;             for (int i = 0; i < diff; i++) ans +=  R ;           }           if (max(y1, y2) >= min_y) {             int diff = max(y1, y2) - min_y + 1;             y2 -= diff;             y1 -= diff;             for (int i = 0; i < diff; i++) ans +=  D ;           }           int x = max_x;           int y;           for (int i = 290; i < 510; i++) {             if (matrix[x][i] == 255) {               y = i;               break;             }           }           if (y1 < y) {             int diff = y - y1;             y1 += diff;             y2 += diff;             for (int i = 0; i < diff; i++) ans +=  U ;           }           while (x2 != x1) {             int diff = x1 - x - 1;             x1 -= diff;             x2 = x + 1;             for (int i = 0; i < diff; i++) ans +=  L ;           }           cout << ans;           return 0;         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long mod = 1e9 + 7;   long long INF = 1e7;   double EPS = 1e-12;   double tick() {     static clock_t oldt;     clock_t newt = clock();     double diff = 1.0 * (newt - oldt) / CLOCKS_PER_SEC;     oldt = newt;     return diff;   }   long long int powP(long long int a, long long int b) {     if (b == 0) return 1 % mod;     long long int k;     k = powP(a, b / 2);     k = k * k % mod;     if (b % 2 == 0)       return k;     else       return a * k % mod;   }   bool bitSet(long long int n, long long int i) {     if ((n & (1LL << i)) != 0)       return true;     else       return false;   }   long long int findGcd(long long int a, long long int b) {     if (a == 0)       return b;     else       return findGcd(b % a, a);   }   long long int A[700005], B[700005], C[700005];   int main() {     long long int T, i, n, m, p, j, l, e, r, b, c, k, q, a, d, w, x, y, v, z, t,         curr, prev, sum, ans, pos, val, countA, secondMin, indicator;     scanf( %lld , &n);     stack<int> S;     ans = 0;     S.push(0);     B[0] = INT_MAX;     for (long long int i = (1); i <= (n); ++i) {       scanf( %lld , &A[i]);       B[i] = 1;       while (!S.empty() && A[i] > A[S.top()]) {         B[i] = max(B[i], B[S.top()] + 1);         S.pop();       }       if (B[i] < INT_MAX) ans = max(ans, B[i]);       S.push(i);     }     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int N, M, K, P[105];   int main() {     scanf( %d %d %d , &N, &M, &K);     for (int i = 0; i < K; i++) scanf( %d , &P[i]);     int ans = 0;     for (int i = 0; i < N; i++) {       for (int j = 0; j < M; j++) {         int x;         scanf( %d , &x);         int idx;         for (int k = 0; k < K; k++)           if (x == P[k]) {             idx = k;             break;           }         for (int k = idx; k > 0; k--) P[k] = P[k - 1];         P[0] = x;         ans += idx + 1;       }     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f, N = 2e5 + 5;   const long long inf = 1e18;   inline int read() {     int sum = 0, f = 1;     char c = getchar();     while (c >  9  || c <  0 ) {       if (c ==  - ) f = -f;       c = getchar();     }     while (c >=  0  && c <=  9 ) sum = sum * 10 + c - 48, c = getchar();     return sum * f;   }   int n, m, k, q, t[N][2], safe[N];   long long dp[N][2];   long long cost(int a, int b, int c, int d) {     int pos = lower_bound(safe + 1, safe + q + 1, t[a][b]) - safe;     long long ans = inf;     if (pos <= q)       ans = abs(t[a][b] - safe[pos]) + abs(t[c][d ^ 1] - safe[pos]) +             abs(t[c][d] - t[c][d ^ 1]);     pos = upper_bound(safe + 1, safe + q + 1, t[a][b]) - safe - 1;     if (pos >= 1)       ans =           min(ans, (long long)abs(t[a][b] - safe[pos]) +                        abs(t[c][d ^ 1] - safe[pos]) + abs(t[c][d] - t[c][d ^ 1]));     return ans;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cin >> n >> m >> k >> q;     for (int i = 1; i <= k; i++) {       int r, c;       cin >> r >> c;       if (t[r][0] == 0)         t[r][0] = c;       else         t[r][0] = min(t[r][0], c);       t[r][1] = max(t[r][1], c);     }     t[1][0] = 1, t[1][1] = max(t[1][1], 1);     for (int i = 1; i <= q; i++) cin >> safe[i];     sort(safe + 1, safe + q + 1);     for (int i = 2; i <= n; i++) dp[i][0] = dp[i][1] = inf;     dp[1][0] = abs(t[1][1] - 1) * 2;     dp[1][1] = abs(t[1][1] - 1);     int pre = 1;     for (int i = 2; i <= n; i++) {       if (t[i][0] == 0) continue;       for (int j = 0; j < 2; j++) {         for (int k = 0; k < 2; k++) {           dp[i][j] = min(dp[i][j], dp[pre][k] + i - pre + cost(pre, k, i, j));         }       }       pre = i;     }     long long ans = min(dp[pre][0], dp[pre][1]);     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   int main() {     char s[51];     scanf( %s , s);     int i, tf, na = 0, t1 = strlen(s);     if (t1 >= 1 && t1 <= 50) {       for (i = 0; i < t1; i++) {         if (s[i] ==  a ) {           na = na + 1;         }       }       if (2 * na > t1) {         tf = t1;       } else {         tf = (2 * na) - 1;       }       printf( %d n , tf);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int M = 131;   int a[100002], rmp[100002], n, cnt, ans;   unsigned int h[100002], p[100002];   vector<int> v[100002];   vector<pair<int, int> > del;   map<int, int> mp;   inline bool cmp(int x, int y) {     int xe = y - 1, ye = 2 * y - x - 1;     if (ye > n) return 0;     int hx = h[xe] - h[x - 1] * p[y - x], hy = h[ye] - h[y - 1] * p[y - x];     return hx == hy;   }   inline int read() {     int t = 0;     char v = getchar();     while (v <  0 ) v = getchar();     while (v >=  0 ) t = (t << 3) + (t << 1) + v - 48, v = getchar();     return t;   }   int main() {     p[0] = 1;     n = read();     for (int i = 1; i <= n; ++i) {       int x = read();       if (mp.find(x) != mp.end())         a[i] = mp[x];       else {         mp[x] = ++cnt;         a[i] = cnt;         rmp[cnt] = x;       }       p[i] = p[i - 1] * M;       v[a[i]].push_back(i);       h[i] = h[i - 1] * M + a[i];     }     for (int i = 1; i <= cnt; ++i)       for (int j = 0; j < v[i].size(); ++j)         for (int k = j + 1; k < v[i].size(); ++k)           if (cmp(v[i][j], v[i][k]))             del.push_back(make_pair(v[i][k] - v[i][j], v[i][j]));     sort(del.begin(), del.end());     for (int i = 0; i < del.size(); ++i)       if (del[i].second > ans) ans = del[i].second + del[i].first - 1;     printf( %d n , n - ans);     for (int i = ans + 1; i <= n; ++i) printf( %d  , rmp[a[i]]);   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e5 + 5;   int N, M;   int arr[MAXN];   int dp[MAXN];   int main() {     cin.tie(0);     cin.sync_with_stdio(0);     cin >> N >> M;     int prv;     cin >> prv;     int lft = 1;     for (int a = 2; a <= N; a++) {       int cur;       cin >> cur;       if (prv <= cur) {       } else {         lft = a;       }       if (prv >= cur) {         dp[a] = min(dp[a - 1], lft);       } else {         dp[a] = lft;       }       prv = cur;     }     while (M--) {       int l, r;       cin >> l >> r;       if (l >= dp[r]) {         cout <<  Yes n ;       } else {         cout <<  No n ;       }     }   }


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


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int trn = 1 << (n + 1);     trn--;     int a[30000];     for (int i = 2; i <= trn; i++) cin >> a[i];     int q = 1 << n;     int mx = 0;     int leng[30000];     for (int i = q; i <= trn; i++) {       leng[i] = 0;       int j = i;       while (j > 0) {         leng[i] += a[j];         j /= 2;       }       mx = max(mx, leng[i]);     }     int add[30000];     for (int i = q; i <= trn; i++) add[i] = mx - leng[i];     for (int depth = n + 1; depth > 1; depth--) {       q = 1 << (depth - 1);       for (int i = q; i < q * 2; i += 2) {         if ((add[i] > 0) && (add[i + 1] > 0)) {           int t = min(add[i], add[i + 1]);           add[i / 2] = t;           add[i] = add[i] - t;           add[i + 1] = add[i + 1] - t;         }       }     }     int ans = 0;     for (int i = 0; i <= trn; i++) ans += add[i];     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 998244353;   const int N = 1e5 + 5;   void __print(int x) { cerr << x; }   void __print(long x) { cerr << x; }   void __print(long long x) { cerr << x; }   void __print(unsigned x) { cerr << x; }   void __print(unsigned long x) { cerr << x; }   void __print(unsigned long long x) { cerr << x; }   void __print(float x) { cerr << x; }   void __print(double x) { cerr << x; }   void __print(long double x) { cerr << x; }   void __print(char x) { cerr <<      << x <<     ; }   void __print(const char *x) { cerr <<     << x <<    ; }   void __print(const string &x) { cerr <<     << x <<    ; }   void __print(bool x) { cerr << (x ?  true  :  false ); }   template <typename T, typename V>   void __print(const pair<T, V> &x) {     cerr <<  { ;     __print(x.first);     cerr <<  , ;     __print(x.second);     cerr <<  } ;   }   template <typename T>   void __print(const T &x) {     int f = 0;     cerr <<  { ;     for (auto &i : x) cerr << (f++ ?  ,  :   ), __print(i);     cerr <<  } ;   }   void _print() { cerr <<  ] n ; }   template <typename T, typename... V>   void _print(T t, V... v) {     __print(t);     if (sizeof...(v)) cerr <<  ,  ;     _print(v...);   }   vector<vector<int> > ans;   void solve(int n) {     int i = 1, j = 2, k = 3;     while (k <= n) {       ans.push_back({i, j, k});       i += 2;       j += 2;       k += 2;     }     i = 1, j = 2, k -= 2;     while (j < n - 1) {       ans.push_back({i, j, k});       i += 2, j += 2;     }   }   void solve() {     int n;     cin >> n;     long long a[n];     long long x = 0;     for (long long i = 0; i < n; i++) {       cin >> a[i];       x ^= a[i];     }     if (n % 2 == 0) {       if (x) {         cout <<  NO n ;         return;       } else {         solve(n - 1);       }     } else {       solve(n);     }     cout <<  YES n ;     cout << ans.size() <<   n ;     for (auto v : ans) {       printf( %d %d %d n , v[0], v[1], v[2]);     }   }   signed main() {     int t = 1;     for (long long i = 1; i < t + 1; i++) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   const int N = 1e5 + 5;   int n, k, a[N];   int ans[N], top;   int main() {     scanf( %d%d , &n, &k);     int sum = 0;     for (int i = 1; i <= n; i++) scanf( %d , a + i), sum += a[i];     if (sum % k) return !printf( No );     int num = sum / k;     top = 0;     int now = 0, l = 1;     for (int i = 1; i <= n; i++) {       now += a[i];       if (now > num) return !printf( No );       if (now == num) {         ans[++top] = i - l + 1;         l = i + 1;         now = 0;       }     }     printf( Yes n );     for (int i = 1; i <= top; i++) printf( %d  , ans[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     long long int n, m, t, q, a, b, c, h, d, x, y, z, i, j, k,         ans = 0, ans2 = 0, cur = 0, cur2 = 0, sum = 0, sum2 = 0, maxn;     string str =   , str2, str3;     cin >> t;     while (t--) {       cin >> n >> x >> y;       if (abs(x - y) > 1) {         cout <<  -1 n ;         continue;       } else if (x + y > n - 2) {         cout <<  -1 n ;         continue;       }       a = 1;       b = n;       if (x == y) {         cout <<  1  ;         a++;         for (i = 0; i < x; i++) {           cout << b <<     << a <<    ;           a++;           b--;         }         for (i = a; i <= b; i++) cout << i <<    ;         cout <<   n ;       } else if (x > y) {         for (i = 0; i < x; i++) {           cout << a <<     << b <<    ;           a++;           b--;         }         for (i = b; i >= a; i--) cout << i <<    ;         cout <<   n ;       } else {         for (i = 0; i < y; i++) {           cout << b <<     << a <<    ;           a++;           b--;         }         for (i = a; i <= b; i++) cout << i <<    ;         cout <<   n ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   long long A[100005], Nr[100005], Viz[100005];   vector<pair<long long, long long> > V[100005];   long long n;   long long ans;   long long DFSNR(long long x) {     long long nrc = 1;     Viz[x] = 1;     for (auto i : V[x])       if (!Viz[i.first]) {         nrc += DFSNR(i.first);       }     Nr[x] = nrc;     return nrc;   }   void DFS(long long x, long long dist) {     if (A[x] < dist) {       ans += Nr[x];       return;     }     Viz[x] = 1;     for (auto i : V[x])       if (!Viz[i.first]) {         DFS(i.first, max(dist + i.second, i.second));       }   }   int main() {     cin >> n;     for (long long i = 1; i <= n; i++) cin >> A[i];     for (long long i = 1; i < n; i++) {       long long x, y;       cin >> x >> y;       V[x].push_back({i + 1, y});       V[i + 1].push_back({x, y});     }     DFSNR(1);     memset(Viz, 0, sizeof(Viz));     DFS(1, 0);     cout << ans;     return 0;   }


#include <bits/stdc++.h>   int w, n, m, c[1 << 12], id[1 << 12], f[531441];   int dfs(char* g, int s, int t) {     if (!*g) return c[s] * f[t];     s <<= 1;     t *= 3;     switch (*g++) {       case  A :         return dfs(g, s, t + 2) + dfs(g, s | 1, t);       case  O :         return dfs(g, s, t);       case  X :         return dfs(g, s, t) + dfs(g, s | 1, t + 1);       case  a :         return dfs(g, s | 1, t + 1);       case  o :         return dfs(g, s, t + 1) + dfs(g, s | 1, t + 2);       case  x :         return dfs(g, s, t + 1) + dfs(g, s | 1, t);     }   }   int main() {     scanf( %d%d%d , &w, &n, &m);     for (int i = 1; i < 1 << w; i++) id[i] = id[i / 2] * 3 + i % 2;     while (n--) {       int a;       scanf( %d , &a);       c[a]++;       f[id[a]]++;     }     for (int i = 0, lim = 1; i < w; i++, lim *= 3)       for (int s = 0; s < 1 << w; s += 1 << i + 1)         for (int t = 0, j = id[s]; t < lim; t++, j++)           f[j + lim * 2] += f[j] + f[j + lim];     while (m--) {       char g[15];       scanf( %s , g);       printf( %d n , dfs(g, 0, 0));     }   }


/*   AUTHOR: lz.askey   CREATED: 23.07.2021 13:57:23   LANG: C++11   */   #include <assert.h>      #include <algorithm>   #include <bitset>   #include <cmath>   #include <cstdio>   #include <cstdlib>   #include <cstring>   #include <deque>   #include <iostream>   #include <iterator>   #include <map>   #include <new>   #include <queue>   #include <set>   #include <sstream>   #include <stack>   #include <string>   #include <unordered_map>   #include <unordered_set>   #include <vector>      using namespace std;   typedef vector<int> vi;   typedef pair<int, int> ii;   typedef vector<pair<int, int> > vii;   typedef long long ll;   #define bit(x, i) (x & (1 << i))   #define in(i, l, r) (l < i && i < r)   #define linr(i, l, r) (l <= i && i <= r)   #define lin(i, l, r) (l <= i && i < r)   #define inr(i, l, r) (l < i && i <= r)   #define gi(a) scanf( %d , &a)   #define gii(a, b) scanf( %d%d , &a, &b)   #define giii(a, b, c) scanf( %d%d%d , &a, &b, &c)   #define gs(x) scanf( %s , x)   #define clr(a, x) memset(a, x, sizeof(a))   #define c2i(c) (c -  0 )   #define sz(x) ((int)((x).size()))   #define all(c) (c).begin(), (c).end()   #define mp make_pair   #define pb push_back   #define eb emplace_back   #define ff first   #define ss second   // for debug   #define what_is(x)      cerr <<  Line   << __LINE__ <<  :   << #x <<   is   << (x) << endl;   #define error(args...)                            {                                                 string _s = #args;                              replace(_s.begin(), _s.end(),  , ,    );        stringstream _ss(_s);                           istream_iterator<string> _it(_ss);              err(_it, args);                               }   void err(istream_iterator<string> it) { cerr << endl; }   template <typename T, typename... Args>   void err(istream_iterator<string> it, T a, Args... args) {     cerr << *it <<   =   << a << endl;     err(++it, args...);   }      #define REP(i, a, b) for (int i = int(a); i < int(b); i++)   const int inf = 0x3f3f3f3f;   const int mod = 1e9 + 7;   const int fx[4][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};   const int fxx[8][2] = {{0, 1}, {0, -1}, {1, 0},  {-1, 0},                          {1, 1}, {1, -1}, {-1, 1}, {-1, -1}};      // struct      // data   int m, k, ans1, ans2;   ll a[1010][1010], c[1010];   ll x, y;      int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     cin >> m >> k;     REP(i, 0, k) {       REP(j, 0, m) {         cin >> a[i][j];         c[i] += a[i][j];       }     }     x = (c[k - 1] - c[0]) / (k - 1);     REP(i, 1, k) {       if (c[i] - c[0] != x * i) {         ans1 = i;         y = c[i] - c[0] - x * i;         break;       }     }     REP(i, 1, k - 1) {       if (i - 1 != ans1 && i != ans1 && i + 1 != ans1) {         x = 0;         REP(j, 0, m) {           x += a[i - 1][j] * a[i - 1][j] + a[i + 1][j] * a[i + 1][j] -                2 * a[i][j] * a[i][j];         }         break;       }     }     ll ad = 0, mi = 0;     REP(j, 0, m) {       ad += a[ans1 - 1][j] * a[ans1 - 1][j] + a[ans1 + 1][j] * a[ans1 + 1][j];       mi += a[ans1][j] * a[ans1][j] * 2;     }     ad -= x;     REP(i, 0, m) {       ll temp = mi - a[ans1][i] * a[ans1][i] * 2 +                 (a[ans1][i] - y) * (a[ans1][i] - y) * 2;       if (temp == ad) {         ans2 = a[ans1][i] - y;         break;       }     }     cout << ans1 <<     << ans2 <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string s[102];   int main() {     int n, i, cnt[27], j, k;     cin >> n;     for (i = 0; i < n; i++) cin >> s[i];     int ans = 0, temp, first, second, x, r;     for (i = 1; i <= 26; i++) {       for (j = 1; j <= 26; j++) {         temp = 0;         for (k = 0; k < n; k++) {           memset(cnt, 0, sizeof(cnt));           x = 0;           for (r = 0; r < s[k].size(); r++) {             cnt[(int)s[k][r] - 96]++;           }           for (r = 1; r <= 26; r++) {             if (cnt[r]) x++;           }           if (x <= 2) {             int flag = 0;             for (r = 1; r <= 26; r++) {               if (cnt[r]) {                 if (r != i && r != j) flag = 1;               }             }             if (flag == 0) temp += s[k].size();           }         }         ans = max(ans, temp);       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string ans[10] = {  ,   ,  2 ,  3 ,  223 ,  5 ,  53 ,  7 ,  7222 ,  7332 };   int main() {     int n;     string s, a =   ;     cin >> n;     cin >> s;     for (int i = 0; i < n; i++) {       if (s[i] ==  0  || s[i] ==  1 ) continue;       a += ans[(s[i] -  0 )];     }     sort(a.begin(), a.end());     reverse(a.begin(), a.end());     cout << a << endl;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   void solve() {     ll a, b, p;     string s;     cin >> a >> b >> p >> s;     ll n = s.length();     s[n - 1] = s[n - 2];     vector<ll> cost(n, 0);     if (s[n - 1] ==  A )       cost[n - 1] = a;     else       cost[n - 1] = b;     for (int i = n - 2; i >= 0; i--) {       if (s[i] != s[i + 1]) {         if (s[i] ==  A )           cost[i] = cost[i + 1] + a;         else           cost[i] = cost[i + 1] + b;       } else         cost[i] = cost[i + 1];     }     for (int i = 0; i < n; i++)       if (cost[i] <= p) {         cout << i + 1 << endl;         return;       }     cout << n << endl;   }   int main() {     int ___T;     scanf( %d , &___T);     for (int cs = 1; cs <= ___T; cs++) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   typedef struct {     int sum, l;     bool f[55];   } node;   queue<node> qu;   node x, y;   map<int, int> m;   map<int, int>::iterator pos;   int main() {     int n, k, a[55], i, j, t;     while (scanf( %d %d , &n, &k) != EOF) {       for (i = 0; i < n; i++) scanf( %d , &a[i]);       x.sum = x.l = 0;       for (i = 0; i < 55; i++) x.f[i] = true;       while (!qu.empty()) qu.pop();       qu.push(x);       m.clear();       t = 0;       while (!qu.empty()) {         x = qu.front();         qu.pop();         for (i = 0; i < n; i++) {           if (x.f[i]) {             y.sum = x.sum + a[i];             pos = m.find(y.sum);             if (pos != m.end()) continue;             y.l = x.l + 1;             for (j = 0; j < n; j++) y.f[j] = x.f[j];             y.f[i] = false;             qu.push(y);             m.insert(pair<int, int>(y.sum, 0));             printf( %d , y.l);             for (j = 0; j < n; j++)               if (!y.f[j]) printf(  %d , a[j]);             printf(  n );             t++;             if (t == k) break;           }         }         if (t == k) break;       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 10;   int a[maxn];   queue<int> q;   queue<int> m;   int main() {     int n;     scanf( %d , &n);     int fu = 0;     int maxfu = -0x3f3f3f3f;     int idfu;     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);       if (a[i] < 0) {         fu++;         if (maxfu < a[i]) {           maxfu = a[i];           idfu = i;         }       }     }     int flag = 0;     if (fu % 2 != 0) {       m.push(idfu);       flag = 1;     }     for (int i = 1; i <= n; i++) {       if (flag && i == idfu) continue;       if (a[i] == 0)         m.push(i);       else         q.push(i);     }     while (m.size() != 0) {       if (m.size() == 1) {         if (q.size() == 0)           return 0;         else           printf( 2 %d n , m.front());         break;       } else {         int t1, t2;         t1 = m.front();         m.pop();         t2 = m.front();         printf( 1 %d %d n , t1, t2);       }     }     if (q.size() < 2) return 0;     while (q.size() != 1) {       int t1, t2;       t1 = q.front();       q.pop();       t2 = q.front();       printf( 1 %d %d n , t1, t2);     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int T;     cin >> T;     string ans =  / ;     while (T--) {       string s;       cin >> s;       if (s[0] ==  p ) {         cout << ans << endl;         continue;       }       cin >> s;       if (s[0] ==  / )         ans = s +  / ;       else         ans += s +  / ;       while (1) {         int flag = 1;         int x = ans.find( .. );         if (x == -1) break;         int c = 0;         int i;         for (i = x + 1; i >= 0; i--) {           if (ans[i] ==  / ) {             if (!flag) break;             flag = 0;           }           c++;         }         ans.erase(i, c + 1);       }     }     return 0;   }


#include <bits/stdc++.h>   int deg[100000];   int xr[100000];   int edges[100000][2];   int main() {     int n, t = 0;     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %d%d , &deg[i], &xr[i]);     }     for (int i = 0; i < n; i++) {       if (deg[i] == 1) {         int k = i;         do {           edges[t][0] = k;           edges[t][1] = xr[k];           t++;           deg[k] -= 1;           xr[xr[k]] ^= k;           deg[xr[k]] -= 1;           k = xr[k];         } while (deg[k] == 1);       }     }     printf( %d n , t);     for (int i = 0; i < t; i++) printf( %d %d n , edges[i][0], edges[i][1]);     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   const int N = 1e6;   long long int n, m, ans, col;   vector<long long int> v[N], par(N), cola(N);   set<long long int> se[N];   void dfs(long long int s, long long int p) {     par[s] = p;     col = 1;     set<long long int> no, used;     for (auto ic : se[s]) {       if (se[p].find(ic) == se[p].end()) {         no.insert(ic);       } else {         used.insert(cola[ic]);       }     }     for (auto x : no) {       while (used.find(col) != used.end()) col++;       cola[x] = col;       used.insert(col);       ans = max(ans, col);     }     for (auto u : v[s])       if (u != p) {         dfs(u, s);       }   }   int main() {     cin >> n >> m;     for (long long int i = (long long int)1; i <= (long long int)n; i++) {       long long int sz;       cin >> sz;       for (long long int j = (long long int)0; j <= (long long int)sz - 1; j++) {         long long int x;         cin >> x;         se[i].insert(x);       }     }     for (long long int i = (long long int)1; i <= (long long int)n - 1; i++) {       long long int x, y, z;       cin >> x >> y;       v[x].push_back(y);       v[y].push_back(x);     }     dfs(1, 0);     ans = max(ans, 1LL);     cout << ans <<   n ;     for (long long int i = (long long int)1; i <= (long long int)m; i++)       cout << max(1LL, cola[i]) <<    ;   }


#include <bits/stdc++.h>   using namespace std;   const long long inf = 0x3f3f3f3f3f3f3f3f;   int32_t main() {     long long n;     cin >> n;     vector<long long> v1, v2;     long long i, j, ans = 0;     for (i = 0; i < n; i++) {       long long len;       cin >> len;       bool fg = true;       long long mi = INT_MAX, mx = INT_MIN;       for (j = 0; j < len; j++) {         long long x;         cin >> x;         if (x > mi) {           fg = false;         }         mi = min(mi, x);         mx = max(mx, x);       }       if (fg) {         v1.push_back(mi);         v2.push_back(mx);       }     }     sort(v1.begin(), v1.end());     sort(v2.begin(), v2.end());     long long c = 0;     for (auto x : v1) {       auto p = upper_bound(v2.begin(), v2.end(), x) - v2.begin();       c += p;     }     ans = n * n - c;     cout << ans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t = 1;     while (t--) {       int n, k;       cin >> n >> k;       vector<int> m(n), c(k + 1), cnt(k + 1, 0);       for (int i = 0; i < n; i++) {         cin >> m[i];         cnt[m[i]]++;       }       for (int i = 1; i <= k; i++) cin >> c[i];       for (int i = k - 1; i >= 1; i--) cnt[i] += cnt[i + 1];       sort(m.begin(), m.end());       int x, mx = 0;       for (int i = 1; i <= k; i++) {         x = cnt[i] / c[i];         if (cnt[i] % c[i] != 0) x++;         mx = max(x, mx);       }       cout << mx <<   n ;       vector<vector<int> > ans(mx);       int j = 0;       for (int i = n - 1; i >= 0; i--) {         ans[j].push_back(m[i]);         j = (j + 1) % mx;       }       for (int i = 0; i < mx; i++) {         cout << ans[i].size() <<    ;         for (auto x : ans[i]) cout << x <<    ;         cout <<   n ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long x, sum;     while (~scanf( %lld , &x)) {       if (x < 0) x = -x;       if (x == 2)         printf( 3 n );       else if (x == 0)         printf( 0 n );       else {         for (long long i = 1; i <= x; i++) {           sum = i * (i + 1) / 2;           if (sum == x || (sum > x && ((sum - x) % 2 == 0))) {             printf( %d n , i);             break;           }         }       }     }   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     long long x, y, ans;     cin >> x >> y;     ans = (x / 2) * y;     if (x % 2) ans += y / 2;     cout << ans;   }   int32_t main() {     ios_base::sync_with_stdio(false);     long long t = 1;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     long long n, x, m = 1e18;     cin >> n;     vector<long long> v;     for (int i = 0; i < n; i++) {       cin >> x;       v.push_back(x);     }     sort(v.begin(), v.end());     for (int i = 0; i < v.size() / 2; i++) {       m = min(m, v[v.size() / 2 + i] - v[i]);     }     cout << m;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1005;   const int MAXM = 1e5 + 5;   struct EC {     vector<pair<int, int> > has[2][MAXN];     int deg[2][MAXN], color[MAXM], c[2];     void prep(int d) {       for (int i = 0; i < 2; i++)         for (int j = 0; j < MAXN; j++) has[i][j].resize(d + 1, {0, 0});     }     void dfs(int x, int p) {       auto i = has[p][x][c[!p]];       if (has[!p][i.first][c[p]].second)         dfs(i.first, !p);       else         has[!p][i.first][c[!p]] = {0, 0};       has[p][x][c[p]] = i, has[!p][i.first][c[p]] = {x, i.second};       color[i.second] = c[p];     }     int solve(vector<pair<int, int> > &e, vector<int> &res) {       int m = ((int)e.size()), ans = 0;       for (int i = 0; i < m; i++)         ans = max({ans, ++deg[0][e[i].first + 1], ++deg[1][e[i].second + 1]});       prep(ans);       for (int i = 0; i < m; i++) {         int x[2] = {e[i].first + 1, e[i].second + 1};         for (int d = 0; d < 2; d++)           for (c[d] = 1; has[d][x[d]][c[d]].second; c[d]++)             ;         if (c[0] != c[1]) dfs(x[1], 1);         for (int d = 0; d < 2; d++) has[d][x[d]][c[0]] = {x[!d], i + 1};         color[i + 1] = c[0];       }       res.resize(m);       for (int i = 0; i < m; i++) res[i] = color[i + 1];       return ans;     }   } ec;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int a, b, m;     cin >> a >> b >> m;     vector<pair<int, int> > e;     for (int i = 0; i < m; i++) {       int x, y;       cin >> x >> y;       e.push_back({x - 1, y - 1});     }     vector<int> res;     cout << ec.solve(e, res) <<   n ;     for (auto x : res) cout << x <<    ;     cout <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, k, sum = 0, curr = 0, j = 0;     vector<long long int> a(100000), res;     cin >> n >> k;     for (long long int i = 0; i < n; i++) {       cin >> a[i];       sum += a[i];     }     if (sum % k) {       cout <<  No ;     } else {       for (long long int i = 0; i < n; i++) {         curr += a[i];         if (curr == sum / k) {           res.push_back(i + 1 - j);           j = i + 1;           curr = 0;         }       }       if (res.size() == k) {         cout <<  Yes  << endl;         for (long long int i = 0; i < k; i++) {           cout << res[i] <<    ;         }       } else         cout <<  No ;     }     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   struct point {     double x, y;     point() { x = y = 0.0; }     point(double A, double B) { x = A, y = B; }     double operator*(point B) { return x * B.x + y * B.y; }     point turn(double A) {       return point(x * cos(A) - y * sin(A), y * cos(A) + x * sin(A));     }   } zero, e, s, t;   double ans, L1, L2, L3, L4, ev, ew, sv, r;   double dis(point &A, point &B) {     return sqrt(((B.x - A.x) * (B.x - A.x)) + ((B.y - A.y) * (B.y - A.y)));   }   bool check(double mid) {     double A, B, C;     t = e.turn(ew * mid);     L2 = dis(t, zero);     L4 = sqrt(((L2) * (L2)) - ((r) * (r)));     C = acos(t * s / L1 / L2);     A = acos(r / L1);     B = acos(r / L2);     if (A + B - C > 1e-8) {       if (sv * mid - dis(s, t) > 1e-8) return true;       return false;     } else {       C -= A + B;       if (sv * mid - C * r - L3 - L4 > 1e-8) return true;       return false;     }   }   int main() {     scanf( %lf%lf%lf , &e.x, &e.y, &ev);     double R = dis(e, zero);     ew = ev / R;     scanf( %lf%lf%lf%lf , &s.x, &s.y, &sv, &r);     L1 = dis(s, zero);     L3 = sqrt(((L1) * (L1)) - ((r) * (r)));     double l = 0, r = dis(s, e);     while (r - l > 1e-8) {       double mid = (l + r) / 2.0;       if (check(mid))         ans = mid, r = mid;       else         l = mid;     }     printf( %lf n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9;   int n, m;   long long a[200100], fibo[200100], sumfibo[200100];   struct Segment_Tree {     int left, right, len;     long long s0, s1;   } tree[200100 << 2];   struct Data {     long long a[2][2];   } bb[200100], one, b;   Data operator*(const Data x, const Data y) {     Data res;     res.a[0][0] =         (x.a[0][0] * y.a[0][0] % mod + x.a[0][1] * y.a[1][0] % mod) % mod;     res.a[0][1] =         (x.a[0][0] * y.a[0][1] % mod + x.a[0][1] * y.a[1][1] % mod) % mod;     res.a[1][0] =         (x.a[1][0] * y.a[0][0] % mod + x.a[1][1] * y.a[1][0] % mod) % mod;     res.a[1][1] =         (x.a[1][0] * y.a[0][1] % mod + x.a[1][1] * y.a[1][1] % mod) % mod;     return res;   }   long long cal_fx(long long s0, long long s1, int l) {     long long res;     res = (bb[l - 1].a[0][0] * s1 % mod + bb[l - 1].a[0][1] * s0 % mod) % mod;     return res;   }   void plant_tree(int id, int l, int r) {     tree[id].left = l, tree[id].right = r;     tree[id].len = r - l + 1;     if (l == r) {       tree[id].s0 = fibo[0] * a[l] % mod;       tree[id].s1 = fibo[1] * a[l] % mod;       return;     }     int mid = (l + r) >> 1;     plant_tree(id << 1, l, mid);     plant_tree(id << 1 | 1, mid + 1, r);     tree[id].s0 =         (tree[id << 1].s0 +          cal_fx(tree[id << 1 | 1].s0, tree[id << 1 | 1].s1, tree[id << 1].len)) %         mod;     tree[id].s1 =         (tree[id << 1].s1 + cal_fx(tree[id << 1 | 1].s0, tree[id << 1 | 1].s1,                                    tree[id << 1].len + 1)) %         mod;   }   void push_down() {}   void update_pos(int id, int pos, long long val) {     if (tree[id].left == tree[id].right) {       tree[id].s0 = fibo[0] * val % mod;       tree[id].s1 = fibo[1] * val % mod;       return;     }     int mid = (tree[id].left + tree[id].right) >> 1;     if (pos <= mid)       update_pos(id << 1, pos, val);     else       update_pos(id << 1 | 1, pos, val);     tree[id].s0 =         (tree[id << 1].s0 +          cal_fx(tree[id << 1 | 1].s0, tree[id << 1 | 1].s1, tree[id << 1].len)) %         mod;     tree[id].s1 =         (tree[id << 1].s1 + cal_fx(tree[id << 1 | 1].s0, tree[id << 1 | 1].s1,                                    tree[id << 1].len + 1)) %         mod;   }   Segment_Tree query(int id, int l, int r) {     if (tree[id].left == l && tree[id].right == r) {       return tree[id];     }     int mid = (tree[id].left + tree[id].right) >> 1;     if (r <= mid)       return query(id << 1, l, r);     else if (mid < l)       return query(id << 1 | 1, l, r);     else {       Segment_Tree leftson, rightson, now;       leftson = query(id << 1, l, mid);       rightson = query(id << 1 | 1, mid + 1, r);       now.s0 = (leftson.s0 + cal_fx(rightson.s0, rightson.s1, leftson.len)) % mod;       now.s1 =           (leftson.s1 + cal_fx(rightson.s0, rightson.s1, leftson.len + 1)) % mod;       now.len = leftson.len + rightson.len;       return now;     }   }   int main() {     fibo[0] = fibo[1] = 1;     for (int i = 2; i < 200100; i++) {       fibo[i] = (fibo[i - 2] + fibo[i - 1]) % mod;     }     sumfibo[0] = fibo[0];     for (int i = 1; i < 200100; i++) {       sumfibo[i] = (sumfibo[i - 1] + fibo[i]) % mod;     }     one.a[0][0] = one.a[1][1] = 1;     one.a[1][0] = one.a[0][1] = 0;     b.a[0][0] = b.a[0][1] = b.a[1][0] = 1;     b.a[1][1] = 0;     bb[0] = one;     for (int i = 1; i < 200100; i++) {       bb[i] = bb[i - 1] * b;     }     scanf( %d %d , &n, &m);     for (int i = 1; i <= n; i++) {       scanf( %lld , a + i);     }     plant_tree(1, 1, n);     while (m--) {       int type;       scanf( %d , &type);       if (type == 1) {         int x, v;         scanf( %d %d , &x, &v);         update_pos(1, x, v);       } else if (type == 2) {         int l, r;         scanf( %d %d , &l, &r);         Segment_Tree res = query(1, l, r);         printf( %lld n , res.s0);       } else if (type == 3) {         int l, r, d;         scanf( %d %d %d , &l, &r, &d);       }     }   }


#include <bits/stdc++.h>   long a[2200];   long absl(long k) {     if (k < 0) {       k = 0 - k;     }     return k;   }   int main() {     long i, j, n, ans, l, r;     scanf( %ld , &n);     for (i = 0; i < n; i++) {       scanf( %ld , a + i);       a[i] = absl(a[i]);     }     for (i = 0, ans = 0; i < n; i++) {       for (j = 0, l = 0; j < i; j++) {         if (a[j] < a[i]) {           l++;         }       }       for (j = i + 1, r = 0; j < n; j++) {         if (a[j] < a[i]) {           r++;         }       }       if (l > r) {         ans += r;       } else {         ans += l;       }     }     printf( %ld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char a[500001], b[500001];   int nxt[500000];   int c[2], la, lb;   int kmp() {     nxt[0] = -1;     if (lb == 0) {       return 0;     }     int no = -1;     for (int i = 1; i < lb; i++) {       while (no != -1 && b[no + 1] != b[i]) {         no = nxt[no];       }       if (b[no + 1] == b[i]) {         no++;       }       nxt[i] = no;     }     return nxt[lb - 1] + 1;   }   void solve() {     scanf( %s%s , a, b);     c[0] = c[1] = 0;     la = strlen(a);     lb = strlen(b);     for (int i = 0; i < la; i++) {       c[a[i] -  0 ]++;     }     int add = kmp();     for (int i = 0; i < lb; i++) {       c[b[i] -  0 ]--;       if (c[b[i] -  0 ] < 0) {         printf( %s n , a);         return;       }     }     printf( %s , b);     int c0 = 0, c1 = 0;     for (int i = add; i < lb; i++) {       if (b[i] ==  0 ) {         c0++;       } else {         c1++;       }     }     while (c[0] >= c0 && c[1] >= c1) {       c[0] -= c0;       c[1] -= c1;       for (int i = add; i < lb; i++) {         putchar(b[i]);       }     }     while (c[0]-- > 0) {       putchar( 0 );     }     while (c[1]-- > 0) {       putchar( 1 );     }     printf(  n );   }   int main() { solve(); }


#include <bits/stdc++.h>   using namespace std;   const int N = 200005;   struct node {     int to, next;   } p[N << 2];   int head[N], tot, n, now[N], du[N];   bool vis[N], isok;   vector<pair<int, int> > a;   void add(int x, int y) {     p[++tot] = (node){y, head[x]};     head[x] = tot;     p[++tot] = (node){x, head[y]};     head[y] = tot;   }   inline void del(int x, int fa) {     du[fa]--;     vis[x] = 1;     for (int i = head[x]; i; i = p[i].next) {       int y = p[i].to;       if (vis[y] || y == fa) continue;       del(y, x);     }   }   inline void dfs(int x, int fa) {     int son = 0, id = 0;     for (int i = head[x]; i; i = p[i].next) {       int y = p[i].to;       if (vis[y] || y == fa) continue;       dfs(y, x);       if (~now[y])         son++, id = y;       else         son += 2;     }     if (!son) {       now[x] = 1;       return;     }     if (son == 1) {       now[x] = (~now[id] ? now[id] : -2) + 1;       return;     }     a.clear();     for (int i = head[x]; i; i = p[i].next) {       int y = p[i].to;       if (vis[y] || y == fa || now[y] == -1) continue;       a.push_back(make_pair(now[y], y));     }     sort(a.begin(), a.end());     int m = a.size();     for (int i = 0; i < m; i++) {       int r = i;       while (r < m && a[r].first == a[i].first) r++;       for (int j = i + 1; j < r; j++) del(a[j].second, x), isok = 1;       i = r - 1;     }     now[x] = -1;   }   int check() {     for (int i = 1; i <= n; i++)       if (du[i] > 2) return i;     return -1;   }   int main() {     scanf( %d , &n);     for (int i = 1; i < n; i++) {       int x, y;       scanf( %d%d , &x, &y);       add(x, y);       du[x]++;       du[y]++;     }     while (1) {       int root = check();       isok = 0;       if (root == -1) break;       dfs(root, -1);       if (!isok) break;     }     if (check() == -1) {       int ans = n - 1;       for (int i = 1; i <= n; i++) ans -= vis[i];       while (ans % 2 == 0) ans /= 2;       printf( %d n , ans);     } else       puts( -1 );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1000005;   const int mod = 998244353;   long long f[5009];   long long c[5009][5009];   long long ch(int a, int b) {     long long sum = 0;     for (int i = 0; i <= a && i <= b; i++) {       sum += ((c[a][i] * c[b][i] % mod) * f[i] % mod);     }     return sum % mod;   }   int main() {     f[0] = f[1] = 1;     for (int i = 2; i <= 5000; i++) {       f[i] = f[i - 1] * i % mod;     }     for (int i = 1; i <= 5000; i++) {       c[i][0] = c[i][i] = 1;       for (int j = 1; j < i; j++) {         c[i][j] = (c[i - 1][j] + c[i - 1][j - 1]) % mod;       }     }     int a, b, c;     while (~scanf( %d%d%d , &a, &b, &c)) {       long long ans = 1;       ans = ans * ch(a, b);       ans %= mod;       ans = ans * ch(a, c);       ans %= mod;       ans = ans * ch(b, c);       ans %= mod;       printf( %I64d n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1000000;   int k;   int n;   vector<int> v;   int read() {     scanf( %d %d , &n, &k);     for (int i = 1; i <= n; i++) {       int t;       scanf( %d , &t);       v.push_back(t);     }     sort(v.begin(), v.end());     printf( %d , v[n - k]);     return 0;   }   int process() { return 0; }   int main() {     read();     process();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 998244353;   template <typename T>   void chkmin(T &x, T y) {     if (y < x) x = y;   }   template <typename T>   void chkmax(T &x, T y) {     if (y > x) x = y;   }   template <typename T>   void upd(T &x, T y) {     if ((x += y) >= mod) x -= mod;   }   int n, m, K, N, sl, fh, a[510][510];   int rd() {     sl = 0;     fh = 1;     char ch = getchar();     while (ch <  0  ||  9  < ch) {       if (ch ==  - ) fh = -1;       ch = getchar();     }     while ( 0  <= ch && ch <=  9 ) sl = sl * 10 + ch -  0 , ch = getchar();     return sl * fh;   }   int main() {     ios::sync_with_stdio(false);     K = rd();     for (N = 1; N <= K; N <<= 1)       ;     a[1][1] = a[1][2] = a[1][3] = (N << 1) - 1;     a[3][1] = a[3][2] = a[3][3] = (N << 1) - 1;     a[2][3] = a[3][4] = K;     a[2][1] = N;     a[2][2] = N << 1;     n = 3;     m = 4;     printf( %d %d n , n, m);     for (int i = 1; i <= n; ++i, puts(  ))       for (int j = 1; j <= m; ++j) printf( %d  , a[i][j]);     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:256000000 )   using namespace std;   const int INF = (1 << 29) + 5;   const long long int LLINF = (1ll << 59) + 5;   const int MOD = 1000 * 1000 * 1000 + 7;   int n, q;   pair<string, string> arr[228];   map<string, bool> can;   queue<string> now;   int main() {     cin >> n >> q;     string st1, st2;     for (int i = 0; i < q; ++i) {       cin >> arr[i].first >> arr[i].second;     }     now.push( a );     string dd;     string next;     while (!now.empty()) {       dd = now.front();       now.pop();       if (dd.size() >= 6) continue;       for (int i = 0; i < q; ++i) {         if (dd[0] == arr[i].second[0]) {           next = arr[i].first + dd.substr(1, (int)dd.size() - 1);           if (!can[next]) {             can[next] = true;             now.push(next);           }         }       }     }     int answer = 0;     for (auto it = can.begin(); it != can.end(); ++it) {       if (it->first.size() == n) {         ++answer;       }     }     cout << answer;     fclose(stdin);     fclose(stdout);     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   bool isprime(long long int n) {     if (n <= 1) return false;     if (n <= 3) return true;     if (n % 2 == 0 || n % 3 == 0) return false;     for (long long int i = 5; i * i <= n; i += 6) {       if (n % i == 0 || n % (i + 2) == 0) return false;     }     return true;   }   long long int smallestfactor(long long int n) {     for (long long int i = 2; i <= sqrt(n); i++) {       if (n % i == 0) {         long long int x = min(i, n / i);         return x;       }     }   }   int main() {     long long int n;     cin >> n;     long long int ans = 0;     while (1) {       ans += n;       if (isprime(n)) {         ans++;         break;       }       long long int temp = smallestfactor(n);       n /= temp;       if (n == 1) {         ans++;         break;       }     }     cout << ans;   }