#include <bits/stdc++.h>   using namespace std;   long long a[35], b[35], k[35], p[35];   long long n, u, r, ans;   void op1() {     for (int i = 0; i < n; i++) a[i] = a[i] ^ b[i];   }   void op2() {     long long tmp[35];     for (int i = 0; i < n; i++) tmp[i] = a[p[i]] + r;     for (int i = 0; i < n; i++) a[i] = tmp[i];   }   void dfs(int t, int f) {     long long x = 0;     if ((t & 1) == 0) {       for (int i = 0; i < n; i++) x += a[i] * k[i];       ans = max(x, ans);     }     if (t == 0) return;     long long tmp[35];     for (int i = 0; i < n; i++) tmp[i] = a[i];     op2();     dfs(t - 1, 1);     for (int i = 0; i < n; i++) a[i] = tmp[i];     if (f) {       op1();       dfs(t - 1, 0);       for (int i = 0; i < n; i++) a[i] = tmp[i];     }     return;   }   int main() {     cin >> n >> u >> r;     for (int i = 0; i < n; i++) cin >> a[i];     for (int i = 0; i < n; i++) cin >> b[i];     for (int i = 0; i < n; i++) cin >> k[i];     for (int i = 0; i < n; i++) cin >> p[i], p[i]--;     ans = -100000000000000009;     dfs(u, 1);     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 5e5 + 2, K = 102, P = 102;   int dp[3][K][P], a[N], mn[N][K], pre[N];   int main() {     ios::sync_with_stdio(), cin.tie(0), cout.tie(0);     int n, k, p;     cin >> n >> k >> p;     for (int i = 0; i < n; i++) {       cin >> a[i];       a[i] %= p;     }     if (10000 >= n) {       for (int i = 0; i <= 100; i++)         for (int j = 0; j <= 100; j++) dp[0][i][j] = 1e8;       for (int i = 0; i <= 10000; i++)         for (int j = 0; j <= 100; j++) mn[i][j] = 1e8;       dp[0][0][0] = 0;       mn[0][0] = 0;       for (int i = 1; i <= n; i++) {         int nw = (i & 1);         int pas = (nw ^ 1);         for (int ii = 0; ii <= 100; ii++)           for (int j = 0; j <= 100; j++) dp[nw][ii][j] = 1e8;         for (int j = 1; j <= k; j++) {           for (int las = 0; las < p; las++) {             if (las == a[i - 1]) {               dp[nw][j][las] = mn[i - 1][j - 1] + a[i - 1];             }             dp[nw][j][las] =                 min(dp[nw][j][las], dp[pas][j][((las - a[i - 1] + p) % p)] -                                         ((las - a[i - 1] + p) % p) + las);             mn[i][j] = min(mn[i][j], dp[nw][j][las]);           }         }       }       int ans = 1e8;       for (int i = 0; i < p; i++) {         ans = min(ans, dp[n & 1][k][i]);       }       cout << ans;     } else {       for (int i = 1; i <= n; i++) {         pre[i] = pre[i - 1] + a[i - 1];         pre[i] %= p;       }       vector<int> lis;       lis.clear();       for (int i = 1; i < n; i++) {         auto it = upper_bound(lis.begin(), lis.end(), pre[i]);         if (it == lis.end()) {           lis.emplace_back(pre[i]);         } else {           lis[it - lis.begin()] = pre[i];         }       }       auto it = upper_bound(lis.begin(), lis.end(), pre[n]);       if (it - lis.begin() + 1 >= k)         cout << pre[n];       else         cout << pre[n] + p;     }   }


#include <bits/stdc++.h>   using namespace std;   const long long inf = 1e10, mpow = 33, N = 1e5, M = 1e3;   vector<int> prime;   int nt[N + 10];   void sieve() {     for (int i = 2; i <= N; i++)       if (!nt[i]) {         prime.push_back(i);         for (int j = i * 2; j <= N; j += i) nt[j] = 1;       }   }   string tostring(long long x) {     string res;     while (x) {       char ch = (char)(x % 10 + 48);       res = ch + res;       x /= 10;     }     return res;   }   long long power(long long x, int h) {     long long res = 1;     for (; h; h >>= 1) {       if (h & 1) {         if (res > inf / x) return inf;         res = res * x;       }       if (h == 1) return res;       if (x > inf / x) return inf;       x = x * x;     }     return res;   }   int cb(long long x, int h) {     int l = 2, r = N;     while (l <= r) {       int mid = (l + r) / 2;       long long tmp = power(mid, h);       if (tmp > x)         r = mid - 1;       else if (tmp < x)         l = mid + 1;       else         return mid;     }     return -1;   }   string best_rep1(long long x) {     string res = tostring(x);     for (int i = 2; i <= mpow; i++) {       int tmp = cb(x, i);       if (tmp == -1) continue;       string can = tostring(tmp) +  ^  + tostring(i);       if (can.length() < res.length()) res = can;     }     return res;   }   map<long long, string> in_num3, in_num4;   vector<long long> divi(long long x) {     vector<long long> res;     res.push_back(1);     for (int p : prime)       if (x % p == 0) {         long long bonus = 1;         while (x % p == 0) {           x /= p;           bonus *= p;           for (long long k : res) {             if (k % p == 0) break;             res.push_back(k * bonus);           }         }       }     if (x > 1) {       for (long long k : res) {         if (k % x == 0) break;         res.push_back(k * x);       }     }     return res;   }   string best_rep2(long long x, int mlen) {     string res = best_rep1(x);     vector<long long> divisor = divi(x);     sort(divisor.begin(), divisor.end());     for (long long k : divisor) {       if (x / k < k) break;       string can = best_rep1(k) +  *  + best_rep1(x / k);       if (can.length() < res.length()) res = can;     }     if (mlen == 9) {       for (int i = 2; i <= 9; i++)         for (int j = 2; j <= 9; j++)           for (int t = 2; t <= 9; t++) {             long long tmp = power(i, j) * t;             string st = in_num3[x / tmp];             if (x % tmp == 0 && st !=   ) {               string can =                   tostring(i) +  ^  + tostring(j) +  *  + st +  *  + tostring(t);               if (can.length() < res.length()) res = can;             }           }     }     return res;   }   string solve(long long n) {     if (n == 1e10) return  10^10 ;     for (int i = 2; i <= 9; i++)       for (int j = 2; j <= 9; j++)         in_num3[power(i, j)] = tostring(i) +  ^  + tostring(j);     string res = best_rep2(n, 9);     long long R = n, L = max((long long)1, n - M + 1);     for (long long i = L; i < R; i++) {       string can = tostring(n - i) +  + ;       can += best_rep2(i, 9 - (int)can.length());       if (can.length() < res.length()) res = can;     }     for (int i = 2; i <= 99; i++)       for (int j = 2; j <= mpow; j++) {         long long tmp = power(i, j);         if (tmp >= n) continue;         in_num4[tmp] = tostring(i) +  ^  + tostring(j);         string can = tostring(i) +  ^  + tostring(j) +  +  + tostring(n - tmp);         if (can.length() < res.length()) res = can;       }     for (int i = 2; i <= 99; i++)       for (int j = 2; j <= mpow; j++) {         long long tmp = power(i, j);         if (tmp >= n) continue;         string st = in_num4[n - tmp];         if (st !=   ) {           string can = tostring(i) +  ^  + tostring(j) +  +  + st;           if (can.length() < res.length()) res = can;         }       }     for (int i = 2; i <= 9; i++)       for (int j = 2; j <= 9; j++) {         for (int t = 2; t <= 9; t++) {           long long tmp = power(i, j) + t;           string st = in_num3[n - tmp];           if (st !=   ) {             string can =                 tostring(i) +  ^  + tostring(j) +  +  + st +  +  + tostring(t);             if (can.length() < res.length()) res = can;           }         }         long long tmp = power(i, j);         if (tmp >= n) continue;         string can = tostring(i) +  ^  + tostring(j) +  + ;         can += best_rep2(n - tmp, 9 - can.length());         if (can.length() < res.length()) res = can;       }     return res;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     long long n;     cin >> n;     sieve();     cout << solve(n);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7;   template <typename T>   ostream& operator<<(ostream& out, vector<T> v) {     out <<  { ;     for (size_t i = 0; i < v.size(); ++i) out << (i == 0 ?    :  ,  ) << v[i];     return out <<  } ;   }   template <typename Arg1>   void myPrint(const char* name, Arg1&& arg1) {     std::cout << name <<  =  << arg1 << std::endl;   }   template <typename Arg1, typename... Args>   void myPrint(const char* names, Arg1&& arg1, Args&&... args) {     const char* comma = strchr(names + 1,  , );     std::cout.write(names, comma - names) <<  =  << arg1;     myPrint(comma, args...);   }   void run();   int main() {     if (strlen(  ) > 0) {       freopen(                         .in ,            r , stdin);       freopen(                         .out ,            w , stdout);     }     run();     return 0;   }   long long n, q;   long long add[2];   void run() {     scanf( %d%d , &n, &q);     while (q--) {       int t, x;       scanf( %d , &t);       if (t == 1) {         scanf( %d , &x);         if (x < 0) x += n;         add[0] += x;         add[1] += x;       } else {         if (add[0] % 2) {           --add[0];           ++add[1];         } else {           ++add[0];           --add[1];         }       }     }     vector<int> a(n);     for (int i = 0; i < n; ++i) a[((i + add[i % 2]) % n + n) % n] = i;     for (int x : a) printf( %d  , x + 1);     printf(  n );   }


#include <bits/stdc++.h>   using namespace std;   int ar[1000009];   int main() {     long long a, s, d, f, g, h, j, k, l;     cin >> a;     k = 0;     for (s = 1; s <= a; s++) {       scanf( %d , &ar[s]);       if (ar[s]) k++;     }     d = 0;     l = 0;     for (s = 1; s <= a; s++) {       if (ar[s] == 1) {         d = d + (a - k - l);       } else         l++;     }     f = 0;     for (s = a; s >= 1; s--) {       if (ar[s] == 0)         f = f + k;       else         k--;     }     cout << min(d, f) << endl;     cout << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, count, area;     cin >> a >> b;     area = a * b;     if (area < 2)       cout <<  0  << endl;     else {       while (area >= 2) {         count++;         area -= 2;       }       cout << count << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int n, m;   vector<long long int> a[200005];   long long int rankof[200005];   long long int parentof[200005];   long long int maxof[200005];   void initialize() {     for (long long int i = 0; i <= 200005; i++) {       rankof[i] = 1;       parentof[i] = i;       maxof[i] = i;     }   }   long long int root(long long int x) {     if (x == parentof[x]) {       return x;     }     parentof[x] = root(parentof[x]);     return parentof[x];   }   void combine(long long int x, long long int y) {     x = root(x);     y = root(y);     long long int maxx = max(maxof[x], maxof[y]);     if (x != y) {       if (rankof[x] >= rankof[y]) {         parentof[y] = x;         rankof[x] += rankof[y];         maxof[x] = maxx;       } else {         parentof[x] = y;         rankof[y] += rankof[x];         maxof[y] = maxx;       }     }     return;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long int i, j;     cin >> n >> m;     initialize();     for (i = 0; i < m; i++) {       long long int u, v;       cin >> u >> v;       combine(u, v);     }     long long int curmax, cnt = 0;     for (i = 1; i <= n;) {       curmax = maxof[root(i)];       j = i + 1;       while (j <= curmax) {         if (root(j) != root(i)) {           combine(i, j);           cnt++;         }         curmax = maxof[root(i)];         j++;       }       i = j;     }     cout << cnt;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename P, typename Q>   ostream& operator<<(ostream& os, pair<P, Q> p) {     os <<  (  << p.first <<  ,  << p.second <<  ) ;     return os;   }   template <typename P, typename Q>   istream& operator>>(istream& is, pair<P, Q>& p) {     is >> p.first >> p.second;     return is;   }   template <typename T>   ostream& operator<<(ostream& os, vector<T> v) {     os <<  ( ;     for (auto& i : v) os << i <<  , ;     os <<  ) ;     return os;   }   template <typename T>   istream& operator>>(istream& is, vector<T>& v) {     for (auto& i : v) is >> i;     return is;   }   template <typename T>   ostream& operator<<(ostream& os, set<T> s) {     os <<  #{ ;     for (auto& i : s) os << i <<  , ;     os <<  } ;     return os;   }   template <typename K, typename V>   ostream& operator<<(ostream& os, map<K, V> m) {     os <<  { ;     for (auto& i : m) os << i <<  , ;     os <<  } ;     return os;   }   template <typename T>   inline T setmax(T& a, T b) {     return a = std::max(a, b);   }   template <typename T>   inline T setmin(T& a, T b) {     return a = std::min(a, b);   }   template <typename P, typename Q>   inline pair<Q, P> reverse(pair<P, Q> p) {     return make_pair(p.second, p.first);   }   using lli = long long int;   using ull = unsigned long long;   using point = complex<double>;   using str = string;   template <typename T>   using vec = vector<T>;   constexpr lli mod = 1e9 + 7;   template <typename T>   struct SegTree {     int n;     vector<T> dat;     using F = function<T(T, T)>;     F fn;     T e;     SegTree(int n_, T e_, F fn_) {       e = e_;       fn = fn_;       n = 1;       while (n < n_) n *= 2;       dat.resize(2 * n - 1, e);     }     void update(size_t k, T a) {       k += n - 1;       dat[k] = a;       while (k > 0) {         k = (k - 1) / 2;         dat[k] = fn(dat[k * 2 + 1], dat[k * 2 + 2]);       }       return;     }     T query(size_t a, size_t b) { return query(a, b, 0, 0, n); }     T query(size_t a, size_t b, size_t k, size_t l, size_t r) {       if (r <= a || b <= l) return e;       if (a <= l && r <= b) return dat.at(k);       T vl = query(a, b, k * 2 + 1, l, (l + r) / 2);       T vr = query(a, b, k * 2 + 2, (l + r) / 2, r);       return fn(vl, vr);     }   };   int main(int argc, char* argv[]) {     ios_base::sync_with_stdio(0);     cin.tie(0);     int n, m, k;     while (cin >> n >> m >> k) {       vector<int> a(k);       cin >> a;       for (auto& i : a) --i;       const int N = 2 * 1e5 + 5;       vector<int> g[N];       for (int i = 0; i < m; ++i) {         int x, y;         cin >> x >> y;         --x;         --y;         g[x].push_back(y);         g[y].push_back(x);       }       const int inf = 1 << 29;       auto bfs = [&](int src) {         vector<int> cost(n, inf);         queue<int> q;         cost[src] = 0;         for (q.push(src); q.size(); q.pop()) {           int curr = q.front();           for (auto& next : g[curr]) {             if (cost[next] == inf) {               cost[next] = cost[curr] + 1;               q.push(next);             }           }         }         return cost;       };       vector<int> d1 = bfs(0);       vector<int> d2 = bfs(n - 1);       sort(a.begin(), a.end(), [&](int i, int j) { return d1[i] < d1[j]; });       SegTree<int> rmq(a.size(), -(1 << 29),                        [](int a, int b) { return max(a, b); });       for (int i = 0; i < a.size(); ++i) {         rmq.update(i, d2[a[i]]);       }       int mx = 0;       for (int i = 0; i < a.size(); ++i) {         int x = rmq.query(i + 1, a.size());         setmax(mx, d1[a[i]] + x + 1);       }       cout << min(mx, d1[n - 1]) << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e6;   int L[N], R[N], sp[N], levsp[30], lev[N];   long long val[N], a[N];   void lazyUpdate(int node) {     if (!L[node]) return;     if (sp[node] ^ levsp[lev[node]]) {       swap(L[node], R[node]);       sp[node] ^= 1;     }   }   long long build(int node, int l, int r, int lv) {     if (l == r) return val[node] = a[l];     int mid = l + r >> 1;     lev[node] = lv;     L[node] = node << 1, R[node] = node << 1 | 1;     val[node] =         build(L[node], l, mid, lv - 1) + build(R[node], mid + 1, r, lv - 1);     return val[node];   }   long long update(int node, int l, int r, int pos, int k) {     lazyUpdate(node);     if (r < pos || l > pos) return val[node];     if (l == r) return val[node] = k;     int mid = l + r >> 1;     return val[node] = update(L[node], l, mid, pos, k) +                        update(R[node], mid + 1, r, pos, k);   }   long long query(int node, int l, int r, int pos) {     lazyUpdate(node);     if (l > pos) return 0;     if (r <= pos) return val[node];     int mid = l + r >> 1;     return query(L[node], l, mid, pos) + query(R[node], mid + 1, r, pos);   }   int main() {     int n, q;     scanf( %d%d , &n, &q);     int nn = 1 << n;     for (int i = 1; i <= nn; i++) scanf( %lld , &a[i]);     build(1, 1, nn, n);     while (q--) {       int t, x, k;       scanf( %d , &t);       if (t == 1) {         scanf( %d%d , &x, &k);         update(1, 1, nn, x, k);       } else if (t == 2) {         scanf( %d , &k);         for (int i = 0; i <= k; i++) levsp[i] ^= 1;       } else if (t == 3) {         scanf( %d , &k);         levsp[k + 1] ^= 1;       } else {         int l, r;         scanf( %d%d , &l, &r);         printf( %lld n , query(1, 1, nn, r) - query(1, 1, nn, l - 1));       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string s[101][2];   int n, m;   int main() {     cin >> n;     m = 0;     for (int i = 1; i <= n; i++) {       bool mark = true;       m++;       cin >> s[m][0] >> s[m][1];       for (int j = 1; j < m; j++)         if ((s[m][0] == s[j][0]) && (s[m][1] == s[j][1])) {           mark = false;           break;         }       if (!mark) {         m--;       }     }     cout << m << endl;     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   long long int N[100000 + 100];   long long int ans = 0;   int main() {     int n;     cin >> n;     int court = 0;     int court_1 = 0;     int court_2 = 0;     for (int i = 0; i < n; ++i) cin >> N[i];     for (int i = 0; i < n; ++i) {       if (N[i] < -1) {         ans += -1 - N[i];         N[i] = -1;         ++court_2;       } else if (N[i] > 1) {         ans += N[i] - 1;         N[i] = 1;         ++court_1;       } else if (N[i] == 0) {         court++;       } else if (N[i] == 1) {         court_1++;       } else if (N[i] == -1) {         court_2++;       }     }     if (court_2 % 2 != 0) {       if (court != 0) {         ans += 1;         court--;       } else if (court == 0) {         if (court_1 != 0) {           court_1--;           ans += 2;         } else if (court_1 == 0) {           ans += 2;         }       }     }     if (court != 0) ans += court;     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   char buf[1 << 15], *fs, *ft;   inline char getc() {     return (fs == ft &&             (ft = (fs = buf) + fread(buf, 1, 1 << 15, stdin), fs == ft))                ? 0                : *fs++;   }   inline int read() {     int x = 0, f = 1;     char ch = getc();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getc();     }     while (ch >=  0  && ch <=  9 ) {       x = x * 10 + ch -  0 ;       ch = getc();     }     return x * f;   }   const int MAXN = 40010;   int n, m;   int q[MAXN * 20], vis[MAXN * 20], mark[MAXN * 20];   int cnt, S, T, len, tot = 1, maxflow, t, h, st;   int f[MAXN][16], num[MAXN][16], Log[MAXN], d[MAXN];   int lin[MAXN], ver[MAXN << 1], nex[MAXN << 1], pos[MAXN << 1];   int lc[MAXN * 20], nc[MAXN * 20 << 2], vc[MAXN * 20 << 2], e[MAXN * 20 << 2];   int cur[MAXN * 20];   inline void add(int x, int y) {     ver[++len] = y;     nex[len] = lin[x];     lin[x] = len;   }   inline void adc(int x, int y, int z) {     vc[++tot] = y;     nc[tot] = lc[x];     lc[x] = tot;     e[tot] = z;     vc[++tot] = x;     nc[tot] = lc[y];     lc[y] = tot;     e[tot] = 0;   }   inline void dfs(int x, int father) {     d[x] = d[father] + 1;     for (int i = lin[x]; i; i = nex[i]) {       int tn = ver[i];       if (tn == father) continue;       f[tn][0] = x;       num[tn][0] = pos[i];       for (int j = 1; j <= Log[d[x]]; ++j) {         num[tn][j] = ++cnt;         f[tn][j] = f[f[tn][j - 1]][j - 1];         adc(num[tn][j], num[tn][j - 1], 1000000000);         adc(num[tn][j], num[f[tn][j - 1]][j - 1], 1000000000);       }       dfs(tn, x);     }   }   inline void LCA(int x, int y) {     if (d[x] < d[y]) swap(x, y);     for (int i = Log[d[x]]; i >= 0; --i)       if (d[f[x][i]] >= d[y]) {         adc(st, num[x][i], 1);         x = f[x][i];       }     if (x == y) return;     for (int i = Log[d[x]]; i >= 0; --i)       if (f[x][i] != f[y][i]) {         adc(st, num[x][i], 1);         adc(st, num[y][i], 1);         x = f[x][i];         y = f[y][i];       }     adc(st, num[x][0], 1);     adc(st, num[y][0], 1);     return;   }   inline int bfs() {     t = h = 0;     for (int i = 1; i <= cnt; ++i) {       cur[i] = lc[i];       vis[i] = 0;     }     q[++t] = S;     vis[S] = 1;     while (h++ < t) {       int x = q[h];       for (int i = lc[x]; i; i = nc[i]) {         int tn = vc[i];         if (vis[tn] || !e[i]) continue;         q[++t] = tn;         vis[tn] = vis[x] + 1;         if (tn == T) return 1;       }     }     return 0;   }   inline int dinic(int x, int flow) {     if (x == T) return flow;     int rest = flow, k;     for (int i = cur[x]; i && rest; i = nc[i]) {       cur[x] = i;       int tn = vc[i];       if (vis[tn] == vis[x] + 1 && e[i]) {         k = dinic(tn, min(e[i], rest));         if (!k) {           vis[tn] = 0;           continue;         }         e[i] -= k;         e[i ^ 1] += k;         rest -= k;       }     }     return flow - rest;   }   inline void bfs(int s) {     t = h = 0;     memset(vis, 0, sizeof(vis));     q[++t] = s;     while (h++ < t) {       int x = q[h];       vis[x] = 1;       for (int i = lc[x]; i; i = nc[i]) {         int tn = vc[i];         if (!e[i]) continue;         if (vis[tn]) continue;         q[++t] = tn;       }     }   }   int main() {     n = read();     m = read();     cnt = n - 1;     for (int i = 1; i < n; ++i) {       int x, y;       x = read();       y = read();       add(x, y);       add(y, x);       pos[len] = pos[len - 1] = i;       Log[i + 1] = Log[(i + 1) >> 1] + 1;     }     dfs(1, 0);     S = ++cnt;     T = ++cnt;     for (int i = 1; i < n; ++i) adc(i, T, 1);     for (int i = 1; i <= m; ++i) {       int x, y;       st = i + cnt;       x = read();       y = read();       adc(S, st, 1);       LCA(x, y);     }     int flow = 0;     st = cnt;     cnt = cnt + m;     while (bfs())       while ((flow = dinic(S, 1000000000))) maxflow += flow;     printf( %d n , maxflow);     bfs(S);     int count = 0;     for (int i = 1; i <= m; ++i)       if (!vis[st + i]) ++count;     printf( %d , count);     for (int i = 1; i <= m; ++i)       if (!vis[st + i]) printf(  %d , i);     puts(  );     count = 0;     for (int i = 1; i < n; ++i)       if (vis[i]) ++count;     printf( %d , count);     for (int i = 1; i < n; ++i)       if (vis[i]) printf(  %d , i);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, t[200005], ans = 0;   bool chk[200005];   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , t + i);     chk[0] = true;     for (int i = n; i >= 1; i--)       if (!chk[i]) {         int x = i;         ans++;         while (!chk[x]) chk[x] = true, x = t[x];       }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     for (int i = 0; i < t; i++) {       int x, y, z;       cin >> x >> y >> z;       if (x != y && y != z && z != x)         cout <<  NO               <<   n ;       else {         int a = min(min(x, y), z);         int c = max(max(x, y), z);         int b = x + y + z - a - c;         if (a == c || b == c)           cout <<  YES                 <<   n                 << min(a, b) <<     << min(a, b) <<     << c <<   n ;         else if (a == b) {           if (b == c)             cout <<  YES                   <<   n                   << a <<     << b <<     << c <<   n ;           else             cout <<  NO                   <<   n ;         }       }     }   }


#include <bits/stdc++.h>   using namespace std;   template <class n, class second>   ostream &operator<<(ostream &p, pair<n, second> x) {     return p <<  <  << x.first <<  ,   << x.second <<  > ;   }   template <class n>   auto operator<<(ostream &p, n y) ->       typename enable_if<!is_same<n, string>::value,                          decltype(y.begin(), p)>::type {     int o = 0;     p <<  { ;     for (auto c : y) {       if (o++) p <<  ,  ;       p << c;     }     return p <<  } ;   }   void dor() { cerr <<   n ; }   template <class n, class... second>   void dor(n p, second... y) {     cerr << p <<    ;     dor(y...);   }   template <class n, class second>   void mini(n &p, second y) {     if (p > y) p = y;   }   template <class n, class second>   void maxi(n &p, second y) {     if (p < y) p = y;   }   int main() {     vector<vector<int> > res;     string second;     cin >> second;     while (1) {       if (second.size() == 0) break;       int wsk = second.size() - 1;       vector<int> act;       for (int i = 0; i < (int)(second.size()); ++i) {         ;         if (second[i] ==  ( ) {           while (wsk > i && second[wsk] !=  ) ) {             wsk--;           }           if (wsk <= i) break;           act.push_back(i);           act.push_back(wsk);           second[i] =    ;           second[wsk] =    ;         }       }       if (act.size() == 0) break;       res.push_back(act);     }     sort((res).begin(), (res).end());     if (res.size() == 0)       cout << 0 <<   n ;     else {       cout << res.size() <<   n ;       for (auto j : res) {         sort((j).begin(), (j).end());         cout << j.size() <<   n ;         for (auto i : j) cout << i + 1 <<    ;         cout <<   n ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 5;   vector<int> basis;   void add(int x) {     for (int& a : basis)       if (a & -a & x) x ^= a;     if (x == 0) return;     for (int& a : basis)       if (x & -x & a) a ^= x;     basis.emplace_back(x);   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int x = 0;     int n;     cin >> n;     for (int i = 1; i <= n; ++i) {       int a;       cin >> a;       add(x ^= a);     }     if (x)       cout << basis.size();     else       cout <<  -1 ;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = (int)1e9 + 7;   int pw(int a, int b) {     if (b == 0) return 1;     long long t = pw(a, b / 2);     t = (t * t) % mod;     if (b % 2) t = (t * a) % mod;     return t;   }   int arr[26];   int main() {     int n, i, j;     string str;     cin >> n >> str;     for (i = 0; i < n; i++) arr[str[i] -  A ]++;     int mx = 0;     for (i = 0; i < 26; i++) mx = max(mx, arr[i]);     int k = 0;     for (i = 0; i < 26; i++) {       if (arr[i] == mx) k++;     }     cout << pw(k, n) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long modpow(long long a, long long b,                    long long mod = (long long)(1e9 + 7)) {     if (!b) return 1;     a %= mod;     return modpow(a * a % mod, b / 2, mod) * (b & 1 ? a : 1) % mod;   }   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   const int mxn = 1e6;   const long long infty = 1e18;   int n, a, b, p;   int x[mxn];   vector<int> primes;   long long dp[mxn][3];   long long cost(int i) {     return x[i] % p ? (x[i] % p == 1 || x[i] % p + 1 == p ? b : infty) : 0;   }   long long dpsolve() {     for (int i = 0; i < n; i++)       for (int j = 0; j < 3; j++) dp[i][j] = infty;     dp[0][0] = dp[0][2] = cost(0);     dp[0][1] = a;     for (int i = 0; i < n - 1; i++)       for (int j = 0; j < 3; j++)         if (dp[i][j] < infty)           for (int k = j; k <= 2; k++) {             if (k == 1)               (dp[i + 1][k]) = min((dp[i + 1][k]), (dp[i][j] + a));             else               (dp[i + 1][k]) = min((dp[i + 1][k]), (dp[i][j] + cost(i + 1)));           }     long long ans = infty;     for (int k = 0; k < 3; k++) (ans) = min((ans), (dp[n - 1][k]));     return ans;   }   inline void getPrime(int temp) {     for (long long p = 2; p * p <= temp; p++)       if (temp % p == 0) {         primes.push_back(p);         while (temp % p == 0) temp /= p;       }     if (temp > 1) primes.push_back(temp);   }   void solve() {     scanf( %d , &n);     scanf( %d , &a);     scanf( %d , &b);     for (int i = 0; i < n; i++) scanf( %d , &x[i]);     for (int d = -1; d <= 1; d++) getPrime(x[0] + d), getPrime(x[n - 1] + d);     long long ans = infty;     for (int pp : primes) p = pp, (ans) = min((ans), (dpsolve()));     cout << ans << endl;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     long long T;     cin >> T;     while (T--) {       long long n;       cin >> n;       long long ans = 0;       long long one = 0, two = 0;       for (int i = 1; i <= n; i++) {         long long x;         cin >> x;         x %= 3;         if (x == 0) ans++;         if (x == 1) one++;         if (x == 2) two++;       }       if (one >= two) {         ans += two;         ans += (one - two) / 3;       } else {         ans += one;         ans += (two - one) / 3;       }       cout << ans <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5;   const int mx = (1 << 30) - 1;   int n, m;   struct node {     vector<pair<int, int> > p;     void cal(int a, int b) {       int res = a ^ b;       for (int i = 0; i < 30; i++) {         int t = res ^ (1 << i) ^ (res & ((1 << i) - 1));         if ((t ^ a) > b) p.emplace_back(t, t + (1 << i) - 1);       }     }     void get(int first, int l, int r) {       cal(first, r);       cal(mx ^ first, mx ^ l);     }   };   void solve() {     node temp;     scanf( %d%d , &n, &m);     temp.get(n, 0, m);     sort(temp.p.begin(), temp.p.end());     printf( %d n , temp.p[0].first);   }   int main() {     int t;     scanf( %d , &t);     while (t--) solve();   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 5e5 + 10;   inline long long rd() {     long long x = 0;     char c = getchar();     int neg = 1;     while (c <  0  || c >  9 ) {       if (c ==  - ) neg = -1;       c = getchar();     }     while (c >=  0  && c <=  9 ) x = x * 10 + c -  0 , c = getchar();     return x * neg;   }   int N, Q, pre[maxn], A[maxn], tmp[maxn], ans[maxn];   pair<int, int> mn[maxn << 2];   struct Node {     int l, r, i;   } que[maxn];   inline bool cmp(Node a, Node b) { return a.r < b.r; };   inline void update(int p) { mn[p] = min(mn[p << 1], mn[p << 1 | 1]); }   void change(int p, int l, int r, int x, int y) {     if (l == r)       mn[p] = make_pair(y, x);     else {       int m = l + r >> 1;       if (x <= m)         change(p << 1, l, m, x, y);       else         change(p << 1 | 1, m + 1, r, x, y);       update(p);     }   }   pair<int, int> query(int p, int l, int r, int x, int y) {     if (x <= l && r <= y) return mn[p];     int m = l + r >> 1;     pair<int, int> re = make_pair(N + 1, 0);     if (x <= m) re = query(p << 1, l, m, x, y);     if (y >= m + 1) re = min(re, query(p << 1 | 1, m + 1, r, x, y));     return re;   }   int main() {     int i, j, k;     N = rd();     for (i = 1; i <= N; i++) {       A[i] = rd();       pre[i] = tmp[A[i]], tmp[A[i]] = i;     }     Q = rd();     for (i = 1; i <= Q; i++) {       que[i].l = rd(), que[i].r = rd(), que[i].i = i;     }     sort(que + 1, que + Q + 1, cmp);     memset(mn, 127, sizeof(mn));     for (i = 1, j = 1; i <= Q; i++) {       for (; j <= que[i].r && j <= N; j++) {         if (pre[j]) change(1, 1, N, pre[j], N + 1);         change(1, 1, N, j, pre[j]);       }       pair<int, int> re = query(1, 1, N, que[i].l, que[i].r);       if (re.first < que[i].l) ans[que[i].i] = A[re.second];     }     for (i = 1; i <= Q; i++) printf( %d n , ans[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   double f[100];   int k[100];   double cpw[100];   int N;   double calc(int i) { return (1 - cpw[i] * f[i]) / (1 - cpw[i]); }   int main() {     cin >> N;     int c;     int highInc = 0;     double P = 1;     for (int i = 0; i < N; i++) {       cin >> c;       cpw[i] = f[i] = 1.0 - (c / 100.0);       k[i] = 1;       if (calc(i) > calc(highInc)) highInc = i;       P *= (1 - f[i]);     }     double expval = 0;     double oldP;     for (int i = 1; i <= 300000; i++) {       oldP = P;       P *= calc(highInc);       k[highInc]++;       cpw[highInc] *= f[highInc];       expval += i * (P - oldP);       for (int j = 0; j < N; j++)         if (calc(j) > calc(highInc)) highInc = j;     }     cout << fixed << setprecision(20) << expval + N <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   const int oo = 0x3f3f3f3f;   const int SIZE = 4000050;   const int P = 67;   const int maxn = 20;   int a[maxn], b[maxn];   int F[260];   char str[10];   struct HASH {     int head[SIZE], next[SIZE];     unsigned long long state[SIZE];     double dp[SIZE];     int tol;     void init() {       memset(head, -1, sizeof head);       tol = 0;     }     double find(unsigned long long s) {       for (int i = head[s % SIZE]; i != -1; i = next[i]) {         if (state[i] == s) return dp[i];       }       return -1;     }     bool ins(unsigned long long s, double f) {       if (find(s) > -1) return false;       dp[++tol] = f;       state[tol] = s;       next[tol] = head[s % SIZE];       head[s % SIZE] = tol;       return true;     }   } mat;   unsigned long long Hash(int n) {     for (int i = 1; i <= n; i++) b[i] = a[i];     sort(b + 1, b + n);     unsigned long long s = 0;     for (int i = 1; i <= n; i++) {       s *= P;       s += b[i];     }     return s;   }   inline void set_ST(int st[], int x) {     st[0] = (x >> 4) & 3;     st[1] = (x >> 2) & 3;     st[2] = x & 3;   }   inline int get_ST(int a, int b, int c) {     if (a > c) swap(a, c);     return (((a << 2) + b) << 2) + c;   }   double dfs(int n) {     unsigned long long s = Hash(n);     double f = mat.find(s), c[4] = {0, 1e9, 1e9, 1e9};     if (f > -1) return f;     for (int i = 1; i < n; i++) {       int x[3], y[3], nn = n;       int ai = a[i], an = a[n];       set_ST(x, ai);       set_ST(y, an);       if ((!!x[0]) + (!!x[1]) + (!!x[2]) == 1) continue;       if (y[0] && y[1] && y[2]) {         nn++;         y[0] = y[1] = y[2] = 0;       }       for (int j = 0; j < 3; j++)         if (x[j]) {           if ((!!x[0]) + (!!x[1]) + (!!x[2]) == 2 && (j == 1 || !x[1])) continue;           int t = x[j];           x[j] = 0;           a[i] = get_ST(x[0], x[1], x[2]);           if ((!!x[0]) + (!!x[1]) + (!!x[2]) == 1 || !x[1]) a[i] = 0;           x[j] = t;           for (int k = 0; k < 3; k++)             if (!y[k]) {               y[k] = t;               a[nn] = get_ST(y[0], y[1], y[2]);               y[k] = 0;               c[t] = min(c[t], dfs(nn));             }         }       a[i] = ai;       a[n] = an;     }     if (c[1] == 1e9 && c[2] == 1e9 && c[3] == 1e9) {       mat.ins(s, 0);       return 0.0;     }     double p = 1.0 / 6.0;     if (c[1] == 1e9) p += 1.0 / 3.0, c[1] = 0;     if (c[2] == 1e9) p += 1.0 / 3.0, c[2] = 0;     if (c[3] == 1e9) p += 1.0 / 6.0, c[3] = 0;     f = (c[1] / 3.0 + c[2] / 3.0 + c[3] / 6.0 + 1.0) / (1.0 - p);     mat.ins(s, f);     return f;   }   int main() {     int n;     F[ G ] = 1;     F[ B ] = 2;     F[ R ] = 3;     mat.init();     while (scanf( %d , &n) != EOF) {       for (int i = 1; i <= n; i++) {         scanf( %s , str);         a[i] = get_ST(F[str[0]], F[str[1]], F[str[2]]);       }       printf( %.15lf n , dfs(n));     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     int n;     cin >> n;     vector<int> a(101);     for (int i = 0; i < n; i++) {       int x;       cin >> x;       ++a[x];     }     cout << *max_element(a.begin(), a.end()) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, k;   vector<int> v;   void solve() {     if (k == 1) {       for (int i = 0; 1 + i * (n - 1) <= n + m; i++) v.push_back(1 + i * (n - 1));       return;     }     for (int i = 1; i <= k; i++) v.push_back(1);     v.push_back(n);     for (int i = 1; i < k; i++) v.push_back(n + 1);     if (n == m) v.push_back(2 * n);   }   int main() {     scanf( %d %d %d , &n, &m, &k);     solve();     printf( %d n , v.size());     for (int i = 0; i < v.size(); i++)       printf( %d%c , v[i], i < v.size() - 1 ?     :   n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using pii = pair<int, int>;   void solve() {     int n, b, d;     cin >> n >> b >> d;     int res = 0;     int currMass = 0;     for (int i = 0; i < n; i++) {       int got;       cin >> got;       if (got > b) continue;       currMass += got;       if (currMass > d) {         currMass = 0;         res++;       }     }     cout << res;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   int cnt = 0;   void rec(vector<bool> mask, int i, int ops) {     if (cnt == n) return;     if (i == n) {       for (int j = 0; j < n; j++) cout << char( (  + mask[j]);       for (int j = 0; j < n; j++) {         if (ops > 0) {           cout <<  ) ;           ops--;         } else {           cout <<  ( ;           ops++;         }       }       cout << endl;       cnt++;     } else {       mask[i] = 0;       rec(mask, i + 1, ops + 1);       if (ops > 0) {         mask[i] = 1;         rec(mask, i + 1, ops - 1);       }     }   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int T;     cin >> T;     while (T--) {       cin >> n;       cnt = 0;       vector<bool> t(n, 0);       rec(t, 0, 0);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = (int)1e4 + 22;   int n, m;   void solve() {     int l, r;     cin >> n >> m;     int val = INT_MAX;     for (int i = 0; i < m; i++) {       cin >> l >> r;       val = min(val, r - l + 1);     }     cout << val <<   n ;     for (int i = 0; i < n; i++) cout << i % val <<    ;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> x;   int modulo_sum(int a, int b) {     return ((a % 1000000007) + (b % 1000000007)) % 1000000007;   }   int modulo_subtract(int a, int b) {     return ((a % 1000000007) - (b % 1000000007)) % 1000000007;   }   int modulo_mult(int a, int b) { return ((long long)a * b) % 1000000007; }   int power(int n) {     int ini = 2;     int ret = 1;     while (n >= 1) {       if (n % 2 == 1) ret = modulo_mult(ret, ini);       ini = modulo_mult(ini, ini);       n /= 2;     }     return ret;   }   int powerr[300005];   int main() {     int n;     cin >> n;     powerr[0] = 1;     for (int i = 1; i <= n; i++) {       powerr[i] = modulo_sum(powerr[i - 1], powerr[i - 1]);       int apl;       cin >> apl;       x.push_back(apl);     }     x.push_back(0);     sort(x.begin(), x.end());     int ans = 0;     for (int i = 1; i <= n; i++) {       ans = modulo_sum(           ans,           modulo_mult(modulo_sum(powerr[i - 1], (-1) * powerr[n - i]), x[i]));     }     cout << ans << endl;     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   long long n, S, top, pos[2005], id[2005];   struct point {     long long x, y;   } a[2005];   struct line {     long long x, y;     double k;   } b[4000005];   inline bool cmp1(point A, point B) {     return A.x != B.x ? A.x < B.x : A.y < B.y;   }   inline bool cmp2(line A, line B) { return A.k < B.k; }   inline long long cross(point A, point B) {     return abs((A.x * B.y) - (B.x * A.y));   }   inline point operator-(point A, point B) {     return (point){A.x - B.x, A.y - B.y};   }   inline long long getS(point A, point B, point C) {     return abs(cross(B - A, C - A));   }   inline long long read() {     long long ret = 0, ff = 1;     char ch = getchar();     while (!isdigit(ch)) {       if (ch ==  - ) ff = -1;       ch = getchar();     }     while (isdigit(ch)) {       ret = (ret << 3) + (ret << 1) + (ch ^ 48);       ch = getchar();     }     return ret * ff;   }   signed main() {     n = read();     S = read() * 2;     for (long long i = 1; i <= n; i++) {       a[i].x = read();       a[i].y = read();       pos[i] = id[i] = i;     }     sort(a + 1, a + n + 1, cmp1);     for (long long i = 1; i <= n; i++)       for (long long j = i + 1; j <= n; j++)         b[++top] =             (line){i, j, atan2((double)(a[j] - a[i]).y, (double)(a[j] - a[i]).x)};     sort(b + 1, b + top + 1, cmp2);     for (long long i = 1; i <= top; i++) {       long long x = b[i].x, y = b[i].y;       if (pos[x] > pos[y]) swap(x, y);       long long l, r, t;       l = 1, r = pos[x] - 1;       while (l <= r) {         long long mid = (l + r) >> 1;         if (getS(a[id[mid]], a[x], a[y]) >= S)           l = mid + 1, t = mid;         else           r = mid - 1;       }       if (getS(a[id[t]], a[x], a[y]) == S) {         puts( Yes );         printf( %lld %lld n , a[id[t]].x, a[id[t]].y);         printf( %lld %lld n , a[x].x, a[x].y);         printf( %lld %lld n , a[y].x, a[y].y);         return 0;       }       l = pos[y] + 1, r = n;       while (l <= r) {         long long mid = (l + r) >> 1;         if (getS(a[id[mid]], a[x], a[y]) >= S)           r = mid - 1, t = mid;         else           l = mid + 1;       }       if (getS(a[id[t]], a[x], a[y]) == S) {         puts( Yes );         printf( %lld %lld n , a[id[t]].x, a[id[t]].y);         printf( %lld %lld n , a[x].x, a[x].y);         printf( %lld %lld n , a[y].x, a[y].y);         return 0;       }       swap(pos[x], pos[y]);       swap(id[pos[x]], id[pos[y]]);     }     printf( No );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 5e6;   int a[maxn], ans;   int main() {     ios_base::sync_with_stdio(0);     int n;     cin >> n;     while (n--) {       int tmp;       cin >> tmp;       a[tmp]++;     }     for (int i = 0; i < maxn; i++) {       a[i + 1] += a[i] / 2;       ans += a[i] % 2;     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   int main() {     long long int tc;     cin >> tc;     while (tc--) {       long long int n;       cin >> n;       while (n--) cout << 1 <<    ;       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 100100, SQRT = 320, MAXM = 13;   int N, M, Q;   pair<int, int> up[MAXN][MAXM];   pair<int, int> jump[MAXN][MAXM];   char grid[MAXN][MAXM];   bool bounded(int x, int y) { return 1 <= x && x <= N && 1 <= y && y <= M; }   bool bounded(pair<int, int> p) { return bounded(p.first, p.second); }   pair<int, int> getup(int x, int y) {     pair<int, int> &ref = up[x][y];     if (ref.first != -2) {       return ref;     }     if (!bounded(x, y)) {       return ref = pair<int, int>(x, y);     }     if (grid[x][y] ==  ^ ) {       return ref = pair<int, int>(x - 1, y);     } else if (grid[x][y] ==  < ) {       return ref = (grid[x][y - 1] ==  >  ? pair<int, int>(-1, -1)                                           : getup(x, y - 1));     } else {       return ref = (grid[x][y + 1] ==  <  ? pair<int, int>(-1, -1)                                           : getup(x, y + 1));     }   }   void calcjump(int i) {     if (i % SQRT == 1) {       copy_n(up[i] + 1, M, jump[i] + 1);     } else {       for (int j = 1; j <= M; j++) {         pair<int, int> p = up[i][j];         jump[i][j] = bounded(p) ? jump[p.first][p.second] : p;       }     }   }   int main() {     if (fopen( input.txt ,  r )) {       freopen( input.txt ,  r , stdin);     }     ios_base::sync_with_stdio(false);     scanf( %d %d %d n , &N, &M, &Q);     for (int i = 1; i <= N; i++) {       gets(grid[i] + 1);       fill_n(up[i], M + 2, pair<int, int>(-2, -2));     }     for (int i = 0; i <= N; i++) {       for (int j = 0; j <= M + 1; j++) {         getup(i, j);       }     }     for (int i = 1; i <= N; i++) {       calcjump(i);     }     char ch;     for (int x, y; Q--;) {       scanf( %c %d %d , &ch, &x, &y);       if (ch ==  A ) {         pair<int, int> p(x, y);         while (bounded(p)) {           p = jump[p.first][p.second];         }         printf( %d %d n , p.first, p.second);       } else {         scanf(  %c , &ch);         grid[x][y] = ch;         fill_n(up[x] + 1, M, pair<int, int>(-2, -2));         for (int j = 1; j <= M; j++) {           getup(x, j);         }         for (calcjump(x++); x <= N && x % SQRT != 1; x++) {           calcjump(x);         }       }       getchar();     }   }


#include <bits/stdc++.h>   using namespace std;   vector<vector<int>> tree;   int res = 0;   int dfs(int node, int parent) {     int left = 2;     for (int child : tree[node]) {       if (child == parent) {         continue;       }       int x = dfs(child, node);       if (x == 1 && left > 0) {         ++res;         --left;       }     }     return left > 0;   }   int main() {     int n, x, y;     cin >> n >> x >> y;     vector<int> degs(n, 0);     tree.resize(n);     for (int i = 0; i < n - 1; ++i) {       int a, b;       cin >> a >> b;       --a;       --b;       tree[a].push_back(b);       tree[b].push_back(a);       ++degs[a];       ++degs[b];     }     if (x < y) {       dfs(0, -1);       cout << res * (long long)x + (n - res - 1) * (long long)y <<   n ;     } else {       if (*max_element(degs.begin(), degs.end()) == n - 1) {         cout << (long long)(n - 2) * y + x <<   n ;       } else {         cout << (long long)(n - 1) * y <<   n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   map<int, int> a, b;   int f[100005];   int main() {     int n, tmp, i;     scanf( %d , &n);     a.clear();     b.clear();     for (i = 0; i < n; i++) {       scanf( %d , &tmp);       a.insert(make_pair(tmp, i));     }     for (i = 0; i < n; i++) {       scanf( %d , &tmp);       b.insert(make_pair(tmp, i));     }     for (i = 0; i < n; i++) f[b[i + 1]] = a[i + 1];     for (i = 0; i < n - 1; i++) printf( %d  , f[i] + 1);     printf( %d n , f[n - 1] + 1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int64_t n;   vector<int64_t> adj[100001];   int64_t ss[100001];   void dfs(int64_t no, int64_t par = -1) {     ss[no] = 1;     for (auto j : adj[no]) {       if (j == par) {         continue;       }       dfs(j, no);       ss[no] += ss[j];     }   }   vector<int64_t> ord;   int64_t dfs2(int64_t no, int64_t par = -1) {     for (auto j : adj[no]) {       if (j == par) {         continue;       }       if (ss[j] > n / 2) {         return dfs2(j, no);       }     }     return no;   }   int64_t ans = 0;   void dfs3(int64_t no, int64_t par = -1, int64_t levv = 0) {     ord.push_back(no);     ans += levv * 2;     for (auto j : adj[no]) {       if (j == par) {         continue;       }       dfs3(j, no, levv + 1);     }   }   int64_t ans2[100001];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cin >> n;     for (int64_t i = 0; i < n - 1; i++) {       int64_t aa, bb;       cin >> aa >> bb;       aa--;       bb--;       adj[aa].push_back(bb);       adj[bb].push_back(aa);     }     dfs(0);     int64_t cen = dfs2(0);     dfs3(cen);     for (int64_t i = 0; i < n; i++) {       ord.push_back(ord[i]);     }     int64_t x = (n / 2);     cout << ans << endl;     for (int64_t i = 0; i < n; i++) {       ans2[ord[i]] = ord[i + x] + 1;     }     for (int64_t i = 0; i < n; i++) {       cout << ans2[i] <<    ;     }     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 400005;   multiset<int> S;   int x, y, n, m, k;   map<pair<int, int>, int> flag;   struct Tree {     int l, r, num, flag;   } T[N * 4];   void build(int x, int l, int r) {     T[x].l = l;     T[x].r = r;     if (l == r) {       T[x].num = l - 1;       return;     }     int mid = (l + r) / 2;     build(x * 2, l, mid);     build(x * 2 + 1, mid + 1, r);     T[x].num = max(T[x * 2].num, T[x * 2 + 1].num);   }   void down(int x) {     T[x * 2].num += T[x].flag;     T[x * 2 + 1].num += T[x].flag;     T[x * 2].flag += T[x].flag;     T[x * 2 + 1].flag += T[x].flag;     T[x].flag = 0;   }   void insert(int x, int l, int r, int z) {     if (T[x].l > r || l > T[x].r) return;     if (T[x].l >= l && T[x].r <= r) {       T[x].num += z;       T[x].flag += z;       return;     }     down(x);     insert(x * 2, l, r, z);     insert(x * 2 + 1, l, r, z);     T[x].num = max(T[x * 2].num, T[x * 2 + 1].num);   }   int find(int x, int l, int r) {     if (T[x].l > r || l > T[x].r) return 0;     if (T[x].l >= l && T[x].r <= r) return T[x].num;     down(x);     return max(find(x * 2, l, r), find(x * 2 + 1, l, r));   }   int main() {     scanf( %d%d%d , &n, &k, &m);     build(1, 1, n + n);     S.insert(n + 1);     while (m--) {       scanf( %d%d , &x, &y);       if (flag[make_pair(x, y)]) {         S.erase(S.find(y + abs(x - k)));         flag[make_pair(x, y)] = 0;         insert(1, 1, y + abs(x - k), -1);       } else {         S.insert(y + abs(x - k));         flag[make_pair(x, y)] = 1;         insert(1, 1, y + abs(x - k), 1);       }       printf( %d n , find(1, 1, *S.rbegin()) - n);     }   }


#include <bits/stdc++.h>   int main(int argc, const char* argv[]) {     int n, k;     int a[100000 + 1];     scanf( %d%d , &n, &k);     int i;     int count = 0;     int is_ukn = scanf( %d , a) != 1;     for (i = !is_ukn; i <= n; i++)       scanf( %d , a + i) != 1 && getchar() && count++;     int is_man_move = (n + 1 - count) & 1;     int is_man_end = n & 1;     if (k == 0) {       puts((is_ukn && is_man_move) || (!is_ukn && a[0] == 0) ?  Yes  :  No );       return 0;     }     int some_ukn = is_ukn || count;     if (some_ukn) {       puts(is_man_end ?  Yes  :  No );       return 0;     }     int sum2 = 0;     for (i = 0; i <= n && sum2 % k == 0; i++) {       sum2 /= k;       sum2 += a[i];     }     if (i == n + 1) {       if (k != 1 && k != -1)         while (sum2 != 0 && sum2 % k == 0) sum2 /= k;       if (sum2 == 0) {         puts( Yes );         return 0;       }     }     puts( No );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   inline int f(int a) {     int n1 = n;     bool y = 0;     while (n1 != 0) {       int h = a;       int u = n1 % 10;       n1 = n1 / 10;       while (h != 0) {         int j = h % 10;         h = h / 10;         if (u == j) {           y = 1;           break;         }       }     }     return y;   }   int main() {     cin >> n;     int ans = 0;     for (int i = 1; i * i <= n; i++) {       if (n % i == 0) {         int i2 = n / i;         if (f(i) == 1) ans++;         if (f(i2) == 1 && i2 != i) ans++;       }     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, d = 1;   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     cin >> n >> m;     while (n > d) {       for (int i = 1; i < (m + 1); i++) {         cout << d <<     << i <<   n ;         cout << n <<     << m + 1 - i <<   n ;       }       n--;       d++;     }     if (n == d) {       for (int i = 0; i < (m / 2); i++) {         cout << d <<     << 1 + i <<   n ;         cout << d <<     << m - i <<   n ;       }       if (m & 1) cout << d <<     << (m + 1) / 2 <<   n ;     }   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:1073741824 )   #pragma warning(disable : 4996)   using namespace std;   const int N = 1e5 + 100;   pair<int, int> ar[N];   int col[N], us[5];   int ct(int m) {     int c = 0;     while (m) {       c += m & 1;       m >>= 1;     }     return c;   }   int main() {     int n, h;     scanf( %d%d , &n, &h);     for (int i = 0; i < n; i++) {       scanf( %d , &ar[i].first);       ar[i].second = i;     }     if (n < 8) {       int ans = 2e9, t;       for (int mk = 0; mk < (1 << n); mk++) {         int mx = -1, mn = 2e9;         for (int i = 0; i < n; i++) {           for (int j = i + 1; j < n; j++) {             int d = ar[i].first + ar[j].first;             if (((mk >> i) & 1) != ((mk >> j) & 1)) d += h;             mx = max(mx, d);             mn = min(mn, d);           }         }         if (ans > mx - mn) {           ans = mx - mn;           t = mk;         }       }       printf( %d n , ans);       for (int i = 0; i < n; i++) printf( %d  , ((t >> i) & 1) + 1);       return 0;     }     sort(ar, ar + n);     int ans = ar[n - 1].first + ar[n - 2].first - ar[0].first - ar[1].first,         s = -1, f;     for (int g = 0; g < (1 << 4); g++) {       int mn = 2e9, mx = -1, c = ct(g);       if (c != 2) continue;       for (int a = 0; a < 4; a++) {         for (int b = a + 1; b < 4; b++) {           int d = ar[a].first + ar[b].first;           if (((g >> a) & 1) != ((g >> b) & 1)) d += h;           mx = max(mx, d);           mn = min(mn, d);         }       }       for (int k = g == 0; k < (1 << 4); k++) {         c = ct(k);         if (c != 2) continue;         int cmx = mx, cmn = mn;         for (int a = 0; a < 4; a++) {           for (int b = a + 1; b < 4; b++) {             int d = ar[n - 4 + a].first + ar[n - 4 + b].first;             if (((k >> a) & 1) != ((k >> b) & 1)) d += h;             cmn = min(cmn, d);             cmx = max(cmx, d);           }         }         if (ans > cmx - cmn) {           ans = cmx - cmn;           f = g;           s = k;         }       }     }     int cans = 2e9, ind = -1;     for (int i = 0; i < n; i++) {       int j = 0, d = 0, mx = -1, mn = 2e9;       while (j == i) j++;       mn = min(mn, ar[i].first + ar[j].first + h);       d += ar[j].first;       j++;       while (j == i) j++;       d += ar[j].first;       mn = min(d, mn);       d = 0;       j = n - 1;       while (j == i) j--;       mx = max(mx, ar[i].first + ar[j].first + h);       d += ar[j].first;       j--;       while (j == i) j--;       d += ar[j].first;       mx = max(d, mx);       if (cans > mx - mn) {         cans = mx - mn;         ind = i;       }     }     if (cans < ans) {       printf( %d n , cans);       ind = ar[ind].second;       for (int i = 0; i < n; i++) {         printf( %d  , i == ind ? 2 : 1);       }       return 0;     }     if (s != -1) {       for (int i = 0; i < 4; i++) {         col[ar[i].second] = (f >> i) & 1;         us[ar[i].second] = 1;       }       for (int i = 0; i < 4; i++) {         col[ar[n - 4 + i].second] = (s >> i) & 1;         us[col[ar[n - 4 + i].second]] =             us[col[ar[n - 4 + i].second]] == 1 ? 2 : 1;       }       if (us[0] == 2)         for (int i = 5; i < n - 4; i++) col[ar[i].second] = 0;       else         for (int i = 5; i < n - 4; i++) col[ar[i].second] = 1;     }     printf( %d n , ans);     for (int i = 0; i < n; i++) printf( %d  , col[i] + 1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5;   const int MOD = 1e9 + 7;   const int INF = 0x3f3f3f3f;   pair<long long, long long> ans1[N], ans2[N];   long long x;   long long cal(long long n) {     n--;     long long tmp = n * (n + 1) * (2 * n + 1) / 6;     n++;     tmp -= (n * n * n - n * n) / 2;     if (2 * (x - tmp) % (n * n + n)) return -1;     long long m = 2 * (x - tmp) / (n * n + n);     return m;   }   void solve() {     int cnt = 0, tot = 0;     for (int i = 1; i < 1500000; i++) {       long long m = cal((long long)i);       if (m == -1) continue;       if (m < i) break;       ans1[tot++] = make_pair(i, m);       if (m == i) break;       ans2[cnt++] = make_pair(m, i);     }     printf( %d n , tot + cnt);     for (int i = 0; i < tot; i++)       printf( %I64d %I64d n , ans1[i].first, ans1[i].second);     for (int i = cnt - 1; i >= 0; i--)       printf( %I64d %I64d n , ans2[i].first, ans2[i].second);   }   int main() {     scanf( %I64d , &x);     solve();     return 0;   }


#include <bits/stdc++.h>   int main() {     int n, m;     int left, right;     int i;     int count = 0;     scanf( %d %d , &n, &m);     while (n--) {       for (i = 0; i < m; i++) {         scanf( %d %d , &left, &right);         if (left == 1 || right == 1) {           count++;         }       }     }     printf( %d n , count);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     if (n == 1) {       cout << 0 << endl;       return 0;     }     if (n == 2) {       cout << 3 << endl;       return 0;     }     long long a, b, c;     a = 0;     b = 3;     c = 6;     for (int i = 3; i <= n; i++) {       c = ((a * 3) % 1000000007 + (b * 2) % 1000000007) % 1000000007;       a = b;       b = c;     }     cout << c << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5;   struct P {     int t, id;     bool operator<(const P &tmp) const {       if (t != tmp.t) return t < tmp.t;       return id < tmp.id;     }   } p[N];   priority_queue<int, vector<int>, greater<int> > qu;   queue<int> q;   set<int> s;   long long ans[N];   int n, t;   long long now = 0, ed = -1, nid = 0;   void gao() {     if (qu.empty()) return;     int x = qu.top();     if (!s.empty() && (*s.begin()) < x) return;     if (q.empty()) ed += t;     qu.pop();     q.push(x);     s.insert(x);   }   int main() {     scanf( %d%d , &n, &t);     for (int i = 0; i < n; i++) scanf( %d , &p[i].t), p[i].id = i;     sort(p, p + n);     while (true) {       if (nid < n && (ed >= p[nid].t || q.empty())) {         now = p[nid].t;         if (!s.empty() && (*s.begin()) < p[nid].id)           qu.push(p[nid].id);         else if (ed == p[nid].t)           qu.push(p[nid].id);         else {           if (q.empty()) ed = now + t;           q.push(p[nid].id);           s.insert(p[nid].id);         }         nid++;       } else if (!q.empty()) {         int x = q.front();         q.pop();         now = max(now, ed);         s.erase(x);         ans[x] = ed;         if (!q.empty()) ed += t;         gao();       } else         break;     }     for (int i = 0; i < n; i++) printf( %lld  , ans[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string b[1 << 15];   int x[100], y[100], n;   map<string, int> mp;   int main() {     scanf( %d , &n);     for (int i = 0, z; i < n; i++) {       scanf( %d , &z);       x[i] = z & ((1 << 15) - 1);       y[i] = z >> 15;     }     for (int B = 0; B < (1 << 15); B++) {       for (int i = 1, j = __builtin_popcount(B ^ y[0]); i < n; i++) {         b[B].push_back(__builtin_popcount(B ^ y[i]) - j);       }       if (!mp.count(b[B])) mp[b[B]] = B;     }     for (int B = 0; B < 1 << 15; B++) {       string tmp;       for (int i = 1, j = __builtin_popcount(B ^ x[0]); i < n; i++) {         tmp.push_back(j - __builtin_popcount(B ^ x[i]));       }       if (mp.count(tmp)) {         printf( %d n , B + (mp[tmp] << 15));         return 0;       }     }     puts( -1 );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   char a[505][505];   long long int ans, mod;   namespace tree {   int edge[505][505];   long long int a[505][505];   inline void init() { memset(edge, 0, sizeof(edge)); }   inline long long int qpow(long long int x, long long int y) {     long long int ans = 1, base = x;     while (y) {       if (y & 1) ans = ans * base % mod;       base = base * base % mod;       y >>= 1;     }     return ans;   }   inline long long int solve(int n) {     memset(a, 0, sizeof(a));     for (int i = 1; i <= n; ++i)       for (int j = 1; j <= n; ++j) {         (a[i][j] -= edge[i][j]) %= mod;         (a[i][i] += edge[i][j]) %= mod;       }     long long int ans = 1;     for (int i = 1; i < n; ++i) {       int pos = i;       while (pos < n && !a[pos][i]) ++pos;       if (pos >= n) continue;       if (pos != i) ans = mod - ans, swap(a[pos], a[i]);       for (int j = i + 1; j < n; ++j) {         long long int d = qpow(a[i][i], mod - 2) * a[j][i] % mod;         for (int k = 1; k < n; ++k) a[j][k] = (a[j][k] - a[i][k] * d % mod) % mod;       }     }     for (int i = 1; i < n; ++i) ans = ans * a[i][i] % mod;     return (ans % mod + mod) % mod;   }   }  // namespace tree   struct UFO {     int fa[123456];     inline void init() {       for (int i = 0; i < 123456; ++i) fa[i] = i;     }     int find(int x) { return fa[x] == x ? x : fa[x] = find(fa[x]); }     inline void merge(int x, int y) { fa[find(x)] = find(y); }   } U;   const int maxn = 1E6 + 5;   inline void clear() { U.init(); }   inline int num(int x, int y) { return x * (m + 1) + y + 1; }   inline int c(int x) {     if (m % 2 == 1) return (x + (x - 1) / (m + 1)) & 1;     return x & 1;   }   int tot, bel[maxn];   inline void solve1() {     clear();     for (int i = 1; i <= n; ++i)       for (int j = 1; j <= m; ++j)         if (a[i][j] ==     )           U.merge(num(i - 1, j - 1), num(i, j));         else if (a[i][j] ==  / )           U.merge(num(i - 1, j), num(i, j - 1));     for (int i = 1; i <= (n + 1) * (m + 1); ++i)       if (c(i) == 0 && (!bel[U.find(i)])) bel[U.find(i)] = ++tot;     for (int i = 1; i <= n; ++i)       for (int j = 1; j <= m; ++j) {         if (a[i][j] !=  * ) continue;         int u = num(i - 1, j - 1), v = num(i, j);         if (c(num(i - 1, j - 1)) == 1) u = num(i, j - 1), v = num(i - 1, j);         if (u > v) swap(u, v);         u = bel[U.find(u)], v = bel[U.find(v)];         if (u == v) continue;         ++tree::edge[u][v];         ++tree::edge[v][u];       }     ans = (ans + tree::solve(tot)) % mod;   }   inline void solve2() {     clear();     tree::init();     for (int i = 1; i <= n; ++i)       for (int j = 1; j <= m; ++j)         if (a[i][j] ==     )           U.merge(num(i - 1, j - 1), num(i, j));         else if (a[i][j] ==  / )           U.merge(num(i - 1, j), num(i, j - 1));     tot = 0;     memset(bel, 0, sizeof(bel));     for (int i = 1; i <= (n + 1) * (m + 1); ++i)       if (c(i) == 1 && (!bel[U.find(i)])) bel[U.find(i)] = ++tot;     for (int i = 1; i <= n; ++i)       for (int j = 1; j <= m; ++j) {         if (a[i][j] !=  * ) continue;         int u = num(i - 1, j - 1), v = num(i, j);         if (c(num(i - 1, j - 1)) == 0) u = num(i, j - 1), v = num(i - 1, j);         if (u > v) swap(u, v);         u = bel[U.find(u)], v = bel[U.find(v)];         if (u == v) continue;         ++tree::edge[u][v];         ++tree::edge[v][u];       }     ans = (ans + tree::solve(tot)) % mod;   }   int main() {     ios::sync_with_stdio(false);     cin >> n >> m >> mod;     for (int i = 1; i <= n; ++i)       for (int j = 1; j <= m; ++j) cin >> a[i][j];     solve1();     solve2();     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline int ni() {     int a;     scanf( %d , &a);     return a;   }   const int max_n = 5000;   char s1[max_n + 1], s2[max_n + 1], res[max_n + 1];   int digits[26], minuses[26];   bool check(int from, int code, int n, int m) {     bool ok = true, founded = false;     digits[code]--;     memset(minuses, 0, sizeof(minuses));     for (int i = from; i < m; i++) {       int next = -1, need = s2[i] -  a ;       for (int j = 25; j >= 0; j--) {         if (j >= need && digits[j] > 0) {           next = j;           break;         }       }       if (next == -1) {         ok = false;         break;       } else if (next > need) {         founded = true;         break;       } else {         digits[next]--;         minuses[next]++;       }     }     for (int i = 0; i < int(26); i++) digits[i] += minuses[i];     digits[code]++;     if (n <= m && !founded) ok = false;     return ok;   }   int main() {     scanf( %s , s1);     scanf( %s , s2);     int n = strlen(s1), m = strlen(s2);     bool found = true, before = false;     for (int i = 0; i < int(n); i++) digits[s1[i] -  a ]++;     for (int i = 0; i < int(n); i++) {       if (i >= m || before) {         int code = -1;         for (int j = 0; j < int(26); j++) {           if (digits[j] > 0) {             code = j;             break;           }         }         res[i] =  a  + code;         digits[code]--;       } else {         int same = s2[i] -  a , next = -1;         for (int j = 0; j < int(26); j++) {           if (j > same && digits[j] > 0) {             next = j;             break;           }         }         if (digits[same] > 0 && check(i + 1, same, n, m)) {           digits[same]--;           res[i] =  a  + same;         } else if (next != -1) {           digits[next]--;           res[i] =  a  + next;           before = true;         } else {           found = false;           break;         }       }     }     if (found) {       res[n] =   0 ;       printf( %s n , res);     } else {       printf( -1 n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     int intersection = n * m;     int turn = 0;     while (n > 1 && m > 1) {       intersection -= (n + m - 1);       n--;       m--;       turn++;     }     if (n == 1 && m == 1 && turn % 2 == 0) {       cout <<  Akshat  << endl;     } else if (n == 1 && m == 1 && turn % 2 != 0) {       cout <<  Malvika  << endl;     } else if ((n != 1 || m != 1) && turn % 2 == 0) {       cout <<  Akshat  << endl;     } else {       cout <<  Malvika  << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline long long in() {     int32_t x;     scanf( %d , &x);     return x;   }   const long long maxn = 1e5 + 10;   const long long mod = 1e9 + 7;   const long long inf = 1e9 + 10;   long long pref[2][maxn], pref2[maxn];   long long maxDp[maxn], minDp[maxn];   int32_t main() {     long long n = in();     string s;     cin >> s;     long long lenT = in();     long long cntA = (lenT + 1) / 2;     long long cntB = lenT / 2;     for (long long i = 0; i < n; i++) {       pref[0][i + 1] = (i ? pref[0][i - 1] : 0) + (s[i] !=  b );       if (i - cntA * 2 >= 0) pref[0][i + 1] -= (s[i - cntA * 2] !=  b );       pref[1][i + 1] = (i ? pref[1][i - 1] : 0) + (s[i] !=  a );       if (i - cntB * 2 >= 0) pref[1][i + 1] -= (s[i - cntB * 2] !=  a );       pref2[i + 1] =           pref2[i] + (s[i] ==  ? ) - (i >= lenT ? (s[i - lenT] ==  ? ) : 0);     }     for (long long i = 0; i < n; i++) {       if (i + 1 < lenT) continue;       maxDp[i + 1] = maxDp[i];       long long value = maxDp[i - lenT + 1];       bool fl = (pref[1][i + 1 * bool(lenT % 2 == 0)] +                  pref[0][i + 1 * bool(lenT % 2)]) == lenT;       value += fl;       maxDp[i + 1] = max(maxDp[i + 1], value);       long long options[2] = {inf, inf};       if (maxDp[i + 1] == maxDp[i]) options[0] = minDp[i];       if (fl) options[1] = minDp[i - lenT + 1] + pref2[i + 1];       minDp[i + 1] = min(options[0], options[1]);     }     cout << minDp[n] <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int stuff(int x) {     int s = 0;     while (x / 10 != 0) {       int r = x % 10;       x /= 10;       s += r;     }     s += x;     return s;   }   int main() {     ios_base::sync_with_stdio(false);     long long int i = 0;     long long int p, f, a, b, c, s, spow = 1;     long long int arr[1000];     cin >> a >> b >> c;     f = a;     for (s = 1; s <= 81; s++) {       f = a;       spow = 1;       while (f--) {         spow *= s;       }       p = (b * spow) + c;       if (stuff(p) == s && p < 1000000000) {         arr[i] = p;         i++;       }     }     sort(arr, arr + i);     cout << i <<   n ;     for (int j = 0; j < i; j++) {       cout << arr[j] <<    ;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int t;     cin >> t;     for (int k = 0; k < t; k++) {       int n, total = 0;       cin >> n;       while (n / 10 > 0) {         total = total + (n - (n % 10));         n = ((n - (n % 10)) / 10) + n % 10;       }       cout << total + (n % 10) <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   void max_self(T &a, const T &b) {     if (a < b) a = b;   }   template <class T>   void min_self(T &a, const T &b) {     if (a > b) a = b;   }   const int INF = 1e9 + 7;   const double PI = acos(-1.0);   const double EPS = (1e-9);   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int N, d;     long long cnt = 0;     cin >> N >> d;     vector<int> pos(N);     for (int &ele : pos) cin >> ele;     for (auto itr = pos.begin(); itr != pos.end(); ++itr) {       auto lim = upper_bound((pos).begin(), (pos).end(), *itr + d);       int len = distance(itr, lim) - 1;       cnt += (long long)len * (len - 1) / 2;     }     cout << cnt <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void init() {     ios::sync_with_stdio(0);     cin.tie(0);   }   int main() {     init();     int t;     cin >> t;     while (t--) {       int n, m;       cin >> n >> m;       long long arr[n][m];       for (int i = 0; i < n; i++) {         for (int j = 0; j < m; j++) {           cin >> arr[i][j];         }       }       long long ops = 0;       for (long long i = 0; i < n; i++) {         for (int j = 0; j < m; j++) {           long long a[4];           a[0] = arr[i][j];           a[1] = arr[n - 1 - i][m - 1 - j];           a[2] = arr[i][m - 1 - j];           a[3] = arr[n - 1 - i][j];           sort(a, a + 4);           long long m = (a[1] + a[2]) / 2;           for (int ii = 0; ii < 4; ii++) {             ops += abs(a[ii] - (m));           }         }       }       ops /= 4;       cout << ops << endl;     }   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC target( avx,avx2,fma )   #pragma GCC optimization( unroll-loops )   using namespace std;   const int maxn = 3e5 + 5;   const long long mod = 998244353;   const double eps = 1e-6L;   struct node {     int l, r;     bool operator<(const node& k) const {       if (l == k.l) return r > k.r;       return l < k.l;     }   } a[maxn];   long long fac[maxn], f[maxn], inv[maxn];   void init() {     fac[1] = 1;     f[1] = 1;     inv[1] = 1;     for (long long i = 2; i <= maxn; i++) {       fac[i] = fac[i - 1] * i % mod;       f[i] = (mod - mod / i) * f[mod % i] % mod;       inv[i] = inv[i - 1] * f[i] % mod;     }   }   long long C(long long m, long long n) {     if (m < n) return 0;     if (n == 0 || m == n) return 1;     return fac[m] * inv[n] % mod * inv[m - n] % mod;   }   int b[maxn];   int main() {     int T = 1;     init();     while (T--) {       int n, k, m = 1;       scanf( %d %d , &n, &k);       for (int i = 0; i < n; i++) {         scanf( %d %d , &a[i].l, &a[i].r);         b[i] = a[i].r;       }       sort(a, a + n);       sort(b, b + n);       int left = a[0].l, right = a[0].r;       long long ans = 0;       bool flag = true;       for (int i = n - 1; i >= 0; i--) {         int num = i + 1 - (lower_bound(b, b + n, a[i].l) - b);         ans = (ans + C(num - 1, k - 1)) % mod;       }       printf( %lld n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long N;   void solve() {     int i, j, k, l, r, x, y;     string s;     cin >> N;     long long ret = 0;     long long a = 1;     while (N > 1) {       ret += N / 2 * a;       N = (N + 1) >> 1;       a <<= 1;     }     cout << ret << endl;   }   int main() {     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 200008;   int n, k, l, r;   char g[2][maxn];   bool f[2][maxn];   struct arr {     int t, s, x;   } h[maxn];   bool Add(int t, int s, int x) {     if (t >= x) return 0;     if (x > n) return 1;     if (f[s][x]) return 0;     if (g[s][x] ==  X ) return 0;     f[s][x] = 1;     ++r;     h[r].t = t;     h[r].s = s;     h[r].x = x;     return 0;   }   bool Work() {     h[1].t = 0;     h[1].s = 0;     h[1].x = 1;     l = 1, r = 1;     f[0][1] = 1;     while (l <= r) {       int t = h[l].t, s = h[l].s, x = h[l].x;       ++l;       if (Add(t + 1, s, x + 1)) return 1;       if (Add(t + 1, s, x - 1)) return 1;       if (Add(t + 1, s ^ 1, x + k)) return 1;     }     return 0;   }   int main() {     scanf( %d%d%*c , &n, &k);     scanf( %s , &g[0][1]);     scanf( %s , &g[1][1]);     if (Work())       printf( YES n );     else       printf( NO n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main(void) {     int n, m, a, b;     cin >> n >> m >> a >> b;     int ans = 1000000000;     for (int i = 0; i <= n / m + 1; i++) {       ans = min(ans, i * b + max(n - m * i, 0) * a);     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 5e2 + 5;   vector<pair<int, int> > adj[MAX];   int dis[MAX][MAX], in[MAX][MAX];   int n, m;   void dijkstra(int source) {     memset(dis[source], 0x3F, sizeof dis[source]);     dis[source][source] = 0;     priority_queue<pair<int, int>, vector<pair<int, int> >,                    greater<pair<int, int> > >         pq;     pq.emplace(dis[source][source], source);     while (!pq.empty()) {       pair<int, int> cur = pq.top();       pq.pop();       int w, v;       tie(w, v) = cur;       if (w > dis[source][v]) {         continue;       }       for (auto &each : adj[v]) {         int vv, ww;         tie(vv, ww) = each;         if (dis[source][vv] > w + ww) {           dis[source][vv] = w + ww;           in[source][vv] = 1;           pq.emplace(dis[source][vv], vv);         } else if (dis[source][vv] == w + ww) {           in[source][vv]++;         }       }     }   }   int main() {     scanf( %d %d , &n, &m);     for (int i = int(0); i < int(m); i++) {       int u, v, w;       scanf( %d %d %d , &u, &v, &w);       adj[u].emplace_back(v, w);       adj[v].emplace_back(u, w);     }     for (int i = int(1); i < int(n + 1); i++) {       dijkstra(i);     }     for (int i = int(1); i < int(n + 1); i++) {       for (int j = int(i + 1); j < int(n + 1); j++) {         int total = 0;         for (int k = int(1); k < int(n + 1); k++) {           if (dis[i][k] + dis[k][j] == dis[i][j]) {             total += in[i][k];           }         }         printf( %d  , total);       }     }     puts(  );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using namespace std::chrono;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int n;     cin >> n;     if (n % 2 == 0) {       cout <<  NO  << endl;       return 0;     }     cout <<  YES  << endl;     int arr[2 * n + 5];     for (int i = 1, j = 2 * n; i <= n; i++) {       if (i % 2 == 1) {         arr[i] = j;         j--;         arr[i + n] = j;         j--;       } else {         arr[i + n] = j;         j--;         arr[i] = j;         j--;       }     }     for (int i = 1; i <= 2 * n; i++) {       cout << arr[i] <<    ;     }     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class II, class SZ, class OI>   OI cpy_n(II _i, SZ _s, OI _o) {     for (int_fast64_t _j = 1; _j <= _s; _j++) {       *(_o++) = *_i;       if (_j != _s) {         _i++;       }     };     return _o;   }   template <class T>   void slurp(vector<T>& v, int_least32_t n = 1000000000) {     istream_iterator<T> i(cin);     istream_iterator<T> eoi;     ;     if (n == 1000000000) {       copy((i), (eoi), back_inserter((v)));     } else {       v.reserve(n);       cpy_n(i, n, back_inserter((v)));     }   }   template <class T, class U>   void slurp2(vector<T>& va, vector<U>& vb, int_least32_t n = 1000000000) {     istream_iterator<T> a(cin);     istream_iterator<T> eoa;     ;     istream_iterator<U> b(cin);     istream_iterator<U> eob;     ;     if (n != 1000000000) {       va.reserve(n);       vb.reserve(n);     }     auto ao = back_inserter((va));     auto bo = back_inserter((vb));     for (int_fast64_t i = 1; i <= n; i++) {       if (a == eoa) break;       *(ao++) = *a;       *(bo++) = *b;       if (i != n) {         a++;         b++;       }     }   }   chrono::time_point<chrono::system_clock> start_time;   void do_thing(vector<string>& bs, int_fast64_t i, int_fast64_t j) {     for (int_fast64_t int_least32_t = (i); int_least32_t <= (i + 2);          int_least32_t++) {       if (bs[int_least32_t][j + 1] !=  . ) {         return;       }     }     for (int_fast64_t jj = (j); jj <= (j + 2); jj++) {       if (bs[i + 1][jj] !=  . ) {         return;       }     }     for (int_fast64_t int_least32_t = (i); int_least32_t <= (i + 2);          int_least32_t++) {       bs[int_least32_t][j + 1] =  # ;     }     for (int_fast64_t jj = (j); jj <= (j + 2); jj++) {       bs[i + 1][jj] =  # ;     }   }   void do_it() {     int_fast64_t n;     cin >> n;     vector<string> bs;     slurp(bs, n);     for (int_fast64_t i = (0); i <= (n - 3); i++) {       for (int_fast64_t j = (0); j <= (n - 3); j++) {         do_thing(bs, i, j);       }     }     for (int_fast64_t i = (0); i <= (n - 1); i++) {       for (int_fast64_t j = (0); j <= (n - 1); j++) {         if (bs[i][j] !=  # ) {           cout <<  NO  << endl;           return;         }       }     }     cout <<  YES  << endl;   }   void start() { start_time = chrono::system_clock::now(); }   void end() {     chrono::time_point<chrono::system_clock> end_time;     end_time = chrono::system_clock::now();     chrono::duration<double> diff = end_time - start_time;     cerr << fixed << setprecision(4) << diff.count() <<  s  << endl;   }   void do_mult() {     int_least32_t times;     cin >> times;     for (int_fast64_t i = 1; i <= times; i++) {       do_it();     }   }   int main() {     ios::sync_with_stdio(false);     start();     do_it();     end();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int prime = 999983;   const int INF = 0x7FFFFFFF;   const long long INFF = 0x7FFFFFFFFFFFFFFF;   const double pi = acos(-1.0);   const double inf = 1e18;   const double eps = 1e-6;   const long long mod = 1e9 + 7;   long long qpow(long long a, long long b) {     long long s = 1;     while (b > 0) {       if (b & 1) s = s * a % mod;       a = a * a % mod;       b >>= 1;     }     return s;   }   long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   int dr[2][4] = {1, -1, 0, 0, 0, 0, -1, 1};   using namespace std;   const int N = 2e5 + 5;   int n, m, q, to[N << 1], nxt[N << 1], ww[N << 1], head[N];   int vis[N], o[N], len, pre[N], id[N], mrk[N];   long long dis[N], sid[N], tr[N << 2];   vector<int> E[N];   priority_queue<pair<long long, int>, vector<pair<long long, int>>,                  greater<pair<long long, int>>>       Q;   void spfa(int s) {     memset(dis, 63, sizeof(dis));     memset(vis, 0, sizeof(vis));     Q.push(make_pair(dis[s] = 0, s));     pre[s] = 0;     while (!Q.empty()) {       int u = Q.top().second;       Q.pop();       if (vis[u]) continue;       vis[u] = 1;       for (int e = head[u]; e; e = nxt[e]) {         int v = to[e], w = ww[e];         if (dis[v] > dis[u] + w)           pre[v] = e, Q.push(make_pair(dis[v] = dis[u] + w, v));       }     }   }   void dfs(int u) {     for (int v : E[u]) {       if (!id[v]) id[v] = id[u];       dfs(v);     }   }   void modify(int x, int l, int r, int ql, int qr, long long v) {     if (l >= ql && r <= qr) {       tr[x] = min(tr[x], v);       return;     }     int mid = (l + r) >> 1;     if (ql <= mid) modify(x << 1, l, mid, ql, qr, v);     if (qr > mid) modify(x << 1 | 1, mid + 1, r, ql, qr, v);   }   long long query(int x, int l, int r, int p) {     if (l == r) return tr[x];     int mid = (l + r) >> 1;     if (p <= mid)       return min(tr[x], query(x << 1, l, mid, p));     else       return min(tr[x], query(x << 1 | 1, mid + 1, r, p));   }   int main() {     ios::sync_with_stdio(false);     cin >> n >> m >> q;     for (int i = 1, j = 1; i <= m; ++i) {       int u, v, w;       cin >> u >> v >> w;       to[++j] = v;       nxt[j] = head[u];       ww[j] = w;       head[u] = j;       to[++j] = u;       nxt[j] = head[v];       ww[j] = w;       head[v] = j;     }     spfa(n);     memcpy(sid, dis, sizeof(sid));     spfa(1);     for (int i = n; i > 1; i = to[pre[i] ^ 1]) {       o[++len] = i, mrk[pre[i] >> 1] = 1;     }     o[++len] = 1, reverse(o + 1, o + len + 1);     for (int i = 1; i <= len; ++i) {       id[o[i]] = i;     }     for (int i = 2; i <= n; ++i)       if (pre[i]) {         E[to[pre[i] ^ 1]].push_back(i);       }     dfs(1);     memset(tr, 63, sizeof(tr));     for (int i = 1; i <= n; ++i) {       for (int e = head[i]; e; e = nxt[e]) {         int u = i, v = to[e];         if (id[u] >= id[v] || mrk[e >> 1]) continue;         modify(1, 1, len, id[u], id[v] - 1, dis[u] + ww[e] + sid[v]);       }     }     while (q--) {       int x, y;       cin >> x >> y;       x <<= 1;       if (mrk[x >> 1]) {         if (id[to[x]] > id[to[x ^ 1]]) x ^= 1;         printf( %lld n , min(dis[n] - ww[x] + y, query(1, 1, len, id[to[x]])));       } else {         printf( %lld n , min(dis[n], min(dis[to[x]] + sid[to[x ^ 1]],                                          dis[to[x ^ 1]] + sid[to[x]]) +                                          y));       }     }   }


#include <bits/stdc++.h>   using namespace std;   int addOne(int x) { return x + 1; }   int main() {     int a, b;     cin >> a >> b;     while (b) {       a = addOne(a);       b--;     }     cout << a << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1e9 + 7;   const int MOD = 1e9 + 7;   const int dx[4] = {0, 0, -1, 1};   const int dy[4] = {-1, 1, 0, 0};   const int N = 1e5 + 1;   int n;   long long a[N], s[N], p[N], k;   int ans = INF;   bool Check(int val) {     long long ans = k + 1;     for (int l = 1, r = 1; l <= n; l++) {       while (r <= n && a[r] - a[l] <= val) r++;       r--;       long long x = (a[l] * l - p[l]) + (s[r + 1] - (a[l] + val) * (n - r));       ans = min(ans, x);     }     for (int r = n, l = n; r > 0; r--) {       while (l > 0 && a[r] - a[l] <= val) l--;       l++;       long long x =           (s[r] - a[r] * (n - r + 1)) + ((a[r] - val) * (l - 1) - p[l - 1]);       ans = min(ans, x);     }     return (ans <= k);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n >> k;     for (int i = 1; i <= n; i++) cin >> a[i];     sort(a + 1, a + 1 + n);     for (int i = 1; i <= n; i++) p[i] = ((i == 1) ? a[i] : p[i - 1] + a[i]);     for (int i = n; i > 0; i--) s[i] = ((i == n) ? a[i] : s[i + 1] + a[i]);     int l = 0;     int r = INF;     while (l <= r) {       int m = (l + r) / 2;       if (Check(m)) {         ans = m;         r = m - 1;       } else         l = m + 1;     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[100000];   int b[100000];   int c[100000];   struct P {     int a, b;   } p[100000];   int cmp(P x, P y) { return x.a < y.a; }   int main() {     int n, x;     while (cin >> n) {       for (int i = 1; i <= n; i++) {         cin >> x;         a[x] = i;       }       for (int i = 1; i <= n; i++) {         cin >> x;         b[x] = i;         p[i - 1].a = i;         p[i - 1].b = x;       }       for (int i = 1; i <= n; i++) {         int key = a[i];         int l = 0, r = n, mid;         while (l < r) {           mid = (l + r) / 2;           if (p[mid].a == key) {             if (i != n)               cout << p[mid].b <<    ;             else               cout << p[mid].b << endl;             break;           } else if (p[mid].a > key)             r = mid;           else             l = mid + 1;         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5;   int cnt[N], steps[N], vis[N];   void solve() {     int n, res = INT_MAX, x, y;     cin >> n;     for (int i = 1; i < n + 1; i++) {       cin >> x;       queue<pair<int, int>> q;       q.push({x, 0});       while (!q.empty()) {         x = q.front().first;         y = q.front().second;         q.pop();         if (x > N) continue;         if (vis[x] == i) continue;         vis[x] = i;         steps[x] += y;         cnt[x]++;         q.push({2 * x, y + 1});         q.push({x / 2, y + 1});       }     }     for (int i = 0; i < N; i++) {       if (cnt[i] == n) {         if (res > steps[i]) res = steps[i];       }     }     cout << res;   }   int main() {     ios::sync_with_stdio(0), cin.tie(0), cout.tie(0), cerr.tie(0);     ;     int t = 1;     while (t--) solve();   }


#include <bits/stdc++.h>   using namespace std;   const int N = 200005;   int n, k, a[N], ans = 0;   multiset<int> ms;   int main(int argc, char const *argv[]) {     cin >> n >> k;     for (int i = 1; i <= n; ++i) {       cin >> a[i];       if (!a[i] && i != k) a[i] = n + 1;       if (i == k && a[i]) a[i] = 0, ans = 1;       ms.insert(a[i]);     }     int mex = 0;     while (!ms.empty()) {       if (ms.find(mex) == ms.end()) {         int k = *ms.rbegin();         ms.erase(ms.find(k));         ans++;       } else {         ms.erase(mex);       }       mex++;     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX_N = 3e5 + 5;   int n, q;   struct Edge {     int to, nxt;   } e[MAX_N];   int head[MAX_N], tote;   void add_edge(int u, int v) {     e[++tote].to = v, e[tote].nxt = head[u];     head[u] = tote;   }   int siz[MAX_N], fa[MAX_N], ans[MAX_N];   void dfs(int u, int pre) {     fa[u] = pre;     siz[u] = 1;     int son = -1;     for (int i = head[u]; i; i = e[i].nxt) {       int to = e[i].to;       dfs(to, u);       siz[u] += siz[to];       if (son == -1 || siz[to] > siz[son]) son = to;     }     if (son == -1)       ans[u] = u;     else {       son = ans[son];       while ((2 * (siz[u] - siz[son])) > siz[u]) son = fa[son];       ans[u] = son;     }   }   void init() { memset(head, 0, sizeof(head)), tote = 0; };   int main() {     init();     scanf( %d , &n), scanf( %d , &q);     for (register int i = 2; i <= n; i++) {       int x;       scanf( %d , &x);       add_edge(x, i);     }     dfs(1, 1);     while (q--) {       int x;       scanf( %d , &x);       printf( %d n , ans[x]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 0x3f3f3f3f;   const long long inff = 0x3f3f3f3f3f3f3f3f;   const int mod = 998244353;   const double eps = 1e-9;   const int maxV = 3e5 + 5;   int n, V, mV, a[maxV], tot;   long long dp[5][maxV];   vector<long long> w[5];   void solve(int l, int r, int L, int R, int id) {     if (l > r) return;     int pos = L, mid = l + r >> 1;     for (int i = max(mid - (int)w[id].size(), L); i <= min(mid, R); i++) {       if (dp[id][a[mid]] <           dp[id - 1][a[i]] + (i == mid ? 0 : w[id][mid - i - 1])) {         dp[id][a[mid]] = dp[id - 1][a[i]] + (i == mid ? 0 : w[id][mid - i - 1]);         pos = i;       }     }     solve(l, mid - 1, L, pos, id);     solve(mid + 1, r, pos, R, id);   }   namespace fastIO {   static char buf[100000], *h = buf, *d = buf;   template <typename T>   inline void read(T& x) {     int f = 1;     x = 0;     register char c(         h == d && (d = (h = buf) + fread(buf, 1, 100000, stdin), h == d) ? EOF                                                                          : *h++);     while (c >  9  || c <  0 ) {       if (c ==  - ) f = -1;       c = h == d && (d = (h = buf) + fread(buf, 1, 100000, stdin), h == d) ? EOF                                                                            : *h++;     }     while (c <=  9  && c >=  0 )       x = (x << 1) + (x << 3) + (c ^ 48),       c = h == d && (d = (h = buf) + fread(buf, 1, 100000, stdin), h == d) ? EOF                                                                            : *h++;     x *= f;   }   template <typename T>   void output(T x) {     if (x < 0) {       putchar( - );       x = ~(x - 1);     }     static int s[20], top = 0;     while (x) {       s[++top] = x % 10;       x /= 10;     }     if (!top) s[++top] = 0;     while (top) putchar(s[top--] +  0 );   }   }  // namespace fastIO   using fastIO::output;   using fastIO::read;   int main() {     read(n), read(V);     for (int i = (1); i <= (int)(n); ++i) {       int c, w0;       read(c), read(w0);       w[c].push_back(w0);       mV = max(mV, c);     }     for (int i = (1); i <= (int)(mV); ++i) {       sort(w[i].begin(), w[i].end(), greater<int>());       for (int j = 1; j < w[i].size(); j++) {         w[i][j] += w[i][j - 1];       }     }     for (int i = (1); i <= (int)(mV); ++i) {       for (int j = (0); j <= (int)(i - 1); ++j) {         tot = 0;         for (int k = j; k <= V; k += i) {           a[++tot] = k;         }         solve(1, tot, 1, tot, i);       }     }     int flag = 0;     printf( %lld n , dp[mV][V]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long max_n = 500 + 5;   long long n;   long long a[max_n], b[max_n];   bool are_equal(long long arr1[], long long arr2[], long long sz) {     for (int i = 0; i < sz; ++i) {       if (arr1[i] != arr2[i]) return false;     }     return true;   }   bool same_elements(long long arr1[], long long arr2[], long long sz) {     long long tarr1[sz], tarr2[sz];     for (int i = 0; i < sz; ++i) {       tarr1[i] = arr1[i];       tarr2[i] = arr2[i];     }     sort(tarr1, tarr1 + sz);     sort(tarr2, tarr2 + sz);     return are_equal(tarr1, tarr2, sz);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long t;     cin >> t;     while (t--) {       cin >> n;       for (int z = 0; z < n; ++z) cin >> a[z];       ;       for (int z = 0; z < n; ++z) cin >> b[z];       ;       if (!same_elements(a, b, n) or (n & 1 and a[n / 2] != b[n / 2])) {         cout <<  No n ;         continue;       }       vector<pair<long long, long long> > p;       for (int i = 0; i < (n / 2); ++i) p.push_back({a[i], a[n - 1 - i]});       bool flag = true;       for (int i = 0; i < (n / 2) and flag; ++i) {         long long x;         bool got = false;         pair<long long, long long> temp = {b[i], b[n - 1 - i]};         for (x = 0; x < p.size() and !got; ++x) {           if (p[x] == temp) {             p.erase(p.begin() + x);             got = true;           }         }         temp = {b[n - 1 - i], b[i]};         for (x = 0; x < p.size() and !got; ++x) {           if (p[x] == temp) {             p.erase(p.begin() + x);             got = true;           }         }         flag = got;       }       if (flag)         cout <<  Yes n ;       else         cout <<  No n ;     }     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:1024000000,1024000000 )   using namespace std;   const double pi = acos(-1);   const double e = exp(1);   const int INF = 0x3f3f3f3f;   const int MOD = 1e9 + 7;   template <typename T>   inline void read(T &x) {     T ans = 0;     char last =    , ch = getchar();     while (ch <  0  || ch >  9 ) last = ch, ch = getchar();     while (ch >=  0  && ch <=  9 ) ans = ans * 10 + ch -  0 , ch = getchar();     if (last ==  - ) ans = -ans;     x = ans;   }   const int maxn = 1000 + 10;   char str[maxn];   int vis[maxn];   int main() {     while (~scanf( %s , str)) {       memset(vis, 0, sizeof(vis));       int flag = 1;       for (int i = 0; str[i]; i++) {         for (int j = 0; j < str[i] -  a ; j++) {           if (!vis[j]) {             flag = 0;             break;           }         }         if (!flag) break;         vis[str[i] -  a ] = 1;       }       puts(flag ?  YES  :  NO );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long a[105][105], v[105][105], dp[105][105];   long long slove(int x, int y, int n, int m) {     long long t = a[x][y] - (x + y - 2);     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         v[i][j] = a[i][j] - (t + i + j - 2);       }     }     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         dp[i][j] = -1;         if (v[i][j] < 0) continue;         if (i == 1 && j == 1)           dp[i][j] = v[i][j];         else if (i == 1) {           long long t = dp[i][j - 1];           if (t != -1) dp[i][j] = t + v[i][j];         } else if (j == 1) {           long long t = dp[i - 1][j];           if (t != -1) dp[i][j] = t + v[i][j];         } else {           long long t1 = dp[i - 1][j], t2 = dp[i][j - 1];           if (t1 != -1) dp[i][j] = t1 + v[i][j];           if (t2 != -1) {             if (dp[i][j] == -1)               dp[i][j] = t2 + v[i][j];             else               dp[i][j] = min(dp[i][j], t2 + v[i][j]);           }         }       }     }     if (dp[n][m] != -1)       return dp[n][m];     else       return 1e18;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int t;     cin >> t;     while (t--) {       int n, m;       cin >> n >> m;       for (int i = 1; i <= n; i++) {         for (int j = 1; j <= m; j++) {           cin >> a[i][j];         }       }       long long ans = 1e18;       for (int i = 1; i <= n; i++) {         for (int j = 1; j <= m; j++) {           ans = min(ans, slove(i, j, n, m));         }       }       cout << ans <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   const int INF = (1 << 31) - 1;   const double EPS = 1E-9;   const double PI = acos(-1);   using namespace std;   vector<bool> U;   vector<vector<int> > G;   vector<int> P, order, T;   int M[5100][5100];   void dfs(int v) {     U[v] = true;     for (int i = 0; i < G[v].size(); ++i)       if (!U[G[v][i]]) {         P[G[v][i]] = v;         dfs(G[v][i]);       }     order.push_back(v);   }   int main() {     int n, a, b, c;     cin >> n;     priority_queue<pair<int, int> > Q[n];     G.resize(n);     P.resize(n);     T.resize(n);     T.assign(n, 0);     U.resize(n);     U.assign(n, false);     for (int i = 0; i < n; ++i) {       cin >> a;       Q[i].push(make_pair(-a, i));     }     for (int i = 0; i < n - 1; ++i) {       cin >> a >> b >> c;       G[a - 1].push_back(b - 1);       G[b - 1].push_back(a - 1);       M[a - 1][b - 1] = c;       M[b - 1][a - 1] = c;     }     P[0] = -1;     dfs(0);     int TIMER = 0;     reverse(order.begin(), order.end());     while (Q[0].size() < n) {       TIMER++;       for (int i = 1; i < n; ++i)         for (int j = 0; j < M[order[i]][P[order[i]]] && !Q[order[i]].empty();              ++j) {           pair<int, int> v = Q[order[i]].top();           Q[order[i]].pop();           Q[P[order[i]]].push(v);           if (P[order[i]] == 0) T[v.second] = TIMER;         }     }     for (int i = 0; i < n; ++i) cout << T[i] <<    ;     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long base = 7;   const long long maxn = 1e6 + 9;   const long long inf = 1e9 + 7;   set<long long> W, H;   multiset<long long> l1, l2;   long long w, h, n, a;   long long x, y;   char c;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> w >> h >> n;     W.insert(0);     W.insert(w);     l1.insert(w);     H.insert(0);     H.insert(h);     l2.insert(h);     long long maxx;     while (n--) {       cin >> c >> a;       if (c ==  V ) {         W.insert(a);         x = *prev(W.find(a));         y = *next(W.find(a));         auto it = l1.find(y - x);         l1.erase(it);         l1.insert(y - a);         l1.insert(a - x);       } else {         H.insert(a);         x = *prev(H.find(a));         y = *next(H.find(a));         auto it = l2.find(y - x);         l2.erase(it);         l2.insert(y - a);         l2.insert(a - x);       }       long long p = *prev(l1.end());       long long q = *prev(l2.end());       cout << p * q <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 2e5 + 6;   const long long MOD = 1e9 + 7;   int par[MAX];   long long sz[MAX];   long long triplets(long long x) { return x * (x - 1) * (x - 2); }   bool isLucky(long long x) {     while (x) {       if (x % 10 != 4 and x % 10 != 7) return false;       x /= 10;     }     return true;   }   int Find(int u) {     if (u == par[u]) return u;     return par[u] = Find(par[u]);   }   void Union(int u, int v) {     u = Find(u);     v = Find(v);     if (sz[u] < sz[v]) swap(u, v);     if (u != v) {       par[v] = u;       sz[u] += sz[v];     }   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long n;     cin >> n;     for (int i = 1; i <= n; i++) par[i] = i, sz[i] = 1;     for (int i = 1; i <= n - 1; i++) {       long long u, v, w;       cin >> u >> v >> w;       if (!isLucky(w)) Union(u, v);     }     long long ans = n * (n - 1) * (n - 2);     for (int i = 1; i <= n; i++) {       if (Find(i) == i) {         ans -= 2 * sz[i] * (sz[i] - 1) * (n - sz[i]) +                sz[i] * (sz[i] - 1) * (sz[i] - 2);       }     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   const double EPS = 1e-10;   const double PI = acos(-1.L);   struct Point {     double x;     double y;     Point() {       x = 0;       y = 0;     }     Point(double x, double y) : x(x), y(y) {}     Point operator+(const Point& other) const {       return Point(x + other.x, y + other.y);     }     Point operator-(const Point& other) const {       return Point(x - other.x, y - other.y);     }     double operator*(const Point& other) const {       return x * other.x + y * other.y;     }     double operator^(const Point& other) const {       return x * other.y - y * other.x;     }   };   ostream& operator<<(ostream& s, Point p) { return s << p.x <<     << p.y; }   int main() {     double px, py, vx, vy, a, b, c, d;     cin >> px >> py >> vx >> vy >> a >> b >> c >> d;     Point displ(px, py);     Point t1(0, b);     Point t2(-a / 2., 0);     Point t3(-c / 2., 0);     Point t4(-c / 2., -d);     Point t5(c / 2., -d);     Point t6(c / 2., 0);     Point t7(a / 2., 0);     double angle = atan2(vy, vx) - PI / 2.;     Point rotx(cos(angle), -sin(angle));     Point roty(sin(angle), cos(angle));     cout << fixed << setprecision(12);     Point s1(rotx * t1, roty * t1);     s1 = s1 + displ;     Point s2(rotx * t2, roty * t2);     s2 = s2 + displ;     Point s3(rotx * t3, roty * t3);     s3 = s3 + displ;     Point s4(rotx * t4, roty * t4);     s4 = s4 + displ;     Point s5(rotx * t5, roty * t5);     s5 = s5 + displ;     Point s6(rotx * t6, roty * t6);     s6 = s6 + displ;     Point s7(rotx * t7, roty * t7);     s7 = s7 + displ;     cout << s1 <<   n           << s2 <<   n           << s3 <<   n           << s4 <<   n           << s5 <<   n           << s6 <<   n           << s7 <<   n ;   }


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


#include <bits/stdc++.h>   long long i, j, k, m, n;   int main() {     scanf( %lld , &n);     if (n <= 1)       puts( -1 );     else       printf( %lld %lld %lld n , n, n + 1, n * (n + 1));     return 0;   }