#include <bits/stdc++.h>   using namespace std;   long long int MOD = 1e9 + 7;   const long long int INF = 1e18;   long long int sub(long long int a, long long int b, long long int p = MOD) {     return ((a % p) - (b % p) + p) % p;   }   long long int mult(long long int a, long long int b, long long int p = MOD) {     return ((a % p) * (b % p)) % p;   }   long long int add(long long int a, long long int b, long long int p = MOD) {     return (a % p + b % p) % p;   }   long long int fpow(long long int n, long long int k, long long int p = MOD) {     long long int r = 1;     while (k > 0) {       if (k & 1) r = r * n % p;       n = n * n % p;       k = k >> 1;     }     return r;   }   long long int inv(long long int a, long long int p = MOD) {     return fpow(a, p - 2, p);   }   long long int fdiv(long long int a, long long int b, long long int p = MOD) {     long long int yinv = inv(b);     long long int ans = (a * yinv) % p;     return ans;   }   unsigned long long int I1018 = 1000000000000000000;   const unsigned long long int I10e5 = 100000;   const long long int I10e6 = 1e6;   long long int ZERO = 0;   unsigned long long int I10e9 = 1000000000;   long long int ONE = 1;   void printVecpll(std::vector<pair<long long int, long long int> > v) {     for (auto p : v) {       cout << (char)p.first <<     << p.second << endl;     }   }   void printVec(std::vector<long long int> v) {     for (long long int i = 0; i < v.size(); i++) {       cout << v[i] <<    ;     }     cout << endl;   }   std::vector<long long int> read_vec(long long int n) {     long long int i;     std::vector<long long int> v(n);     for (i = 0; i < n; i++) {       cin >> v[i];     }     return v;   }   void print_um(unordered_map<long long int, long long int> m) {     for (pair<long long int, long long int> p : m) {       cout << p.first <<     << p.second << endl;     }   }   std::vector<bool> is_prime;   std::vector<long long int> primes;   void sieve(long long int n) {     is_prime.resize(n + 2, true);     primes.clear();     long long int p;     for (p = 2; p * p <= n; p++) {       if (is_prime[p]) {         long long int i;         for (i = p * p; i <= n; i += p) {           is_prime[i] = false;         }       }     }     is_prime[0] = is_prime[1] = false;     long long int i;     for (i = 2; i <= n; i++) {       if (is_prime[i]) {         primes.emplace_back(i);       }     }   }   class Sol {    public:     long long int n;     vector<std::vector<long long int> > graph;     map<long long int, long long int> lc;     std::vector<bool> visited;     Sol() {       cin >> n;       graph.resize(n);       visited.resize(n, false);       long long int i;       for (i = 1; i < n; i++) {         long long int v;         cin >> v;         v--;         graph[i].emplace_back(v);         graph[v].emplace_back(i);       }       dfs(0, -1);       std::vector<long long int> ans;       long long int temp = lc[0];       for (i = 0; i < temp; i++) {         ans.emplace_back(1);       }       for (auto p : lc) {         if (p.first == 0) continue;         for (i = 0; i < p.second; i++) {           ans.emplace_back(p.first);         }       }       printVec(ans);     }     long long int dfs(long long int src, long long int par) {       long long int lt = 0;       if (graph[src].size() == 1 && src != 0) {         lc[0]++;         return 1;       }       for (auto p : graph[src]) {         if (p != par) {           lt += dfs(p, src);         }       }       lc[lt]++;       return lt;     }   };   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     Sol sol;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <int V, class T = long long>   class max_flow {     static const T INF = numeric_limits<T>::max();     struct edge {       int t, rev;       T cap, f;     };     vector<edge> adj[V];     int dist[V];     int ptr[V];     bool bfs(int s, int t) {       memset(dist, -1, sizeof dist);       dist[s] = 0;       queue<int> q({s});       while (!q.empty() && dist[t] == -1) {         int n = q.front();         q.pop();         for (auto& e : adj[n]) {           if (dist[e.t] == -1 && e.cap != e.f) {             dist[e.t] = dist[n] + 1;             q.push(e.t);           }         }       }       return dist[t] != -1;     }     T augment(int n, T amt, int t) {       if (n == t) return amt;       for (; ptr[n] < adj[n].size(); ptr[n]++) {         edge& e = adj[n][ptr[n]];         if (dist[e.t] == dist[n] + 1 && e.cap != e.f) {           T flow = augment(e.t, min(amt, e.cap - e.f), t);           if (flow != 0) {             e.f += flow;             adj[e.t][e.rev].f -= flow;             return flow;           }         }       }       return 0;     }       public:     void add(int u, int v, T cap = 1, T rcap = 0) {       adj[u].push_back({v, (int)adj[v].size(), cap, 0});       adj[v].push_back({u, (int)adj[u].size() - 1, rcap, 0});     }     T calc(int s, int t) {       T flow = 0;       while (bfs(s, t)) {         memset(ptr, 0, sizeof(ptr));         while (T df = augment(s, INF, t)) flow += df;       }       return flow;     }     void clear() {       for (int n = 0; n < V; n++) adj[n].clear();     }   };   set<int> xsw;   set<int> ysw;   bool adj[105][105];   int x1arr[50];   int x2arr[50];   int y1arr[50];   int y2arr[50];   int xswa[105];   int yswa[105];   int main() {     int n, m;     cin >> n >> m;     xsw.insert(0);     xsw.insert(n);     ysw.insert(0);     ysw.insert(n);     for (int i = 0; i < m; i++) {       cin >> x1arr[i] >> y1arr[i] >> x2arr[i] >> y2arr[i];       xsw.insert(x1arr[i] - 1);       xsw.insert(x2arr[i]);       ysw.insert(y1arr[i] - 1);       ysw.insert(y2arr[i]);     }     int idx = 0;     for (auto x : xsw) {       xswa[idx++] = x;     }     idx = 0;     for (auto y : ysw) {       yswa[idx++] = y;     }     for (int i = 0; i < m; i++) {       int xmin = 0;       for (int j = 0; j < xsw.size(); j++) {         if (xswa[j] == x1arr[i] - 1) {           xmin = j;           break;         }       }       int xmax = 0;       for (int j = 0; j < xsw.size(); j++) {         if (xswa[j] == x2arr[i]) {           xmax = j;           break;         }       }       int ymin = 0;       for (int j = 0; j < ysw.size(); j++) {         if (yswa[j] == y1arr[i] - 1) {           ymin = j;           break;         }       }       int ymax = 0;       for (int j = 0; j < ysw.size(); j++) {         if (yswa[j] == y2arr[i]) {           ymax = j;           break;         }       }       for (int j = xmin; j < xmax; j++) {         for (int k = ymin; k < ymax; k++) {           adj[j][k] = true;         }       }     }     max_flow<500> network;     for (int i = 0; i < xsw.size() - 1; i++) {       network.add(0, i + 1, xswa[i + 1] - xswa[i]);     }     for (int i = 0; i < xsw.size() - 1; i++) {       for (int j = 0; j < ysw.size() - 1; j++) {         if (adj[i][j]) {           network.add(i + 1, xsw.size() + j, n);         }       }     }     for (int j = 0; j < ysw.size() - 1; j++) {       network.add(xsw.size() + j, xsw.size() + ysw.size(), yswa[j + 1] - yswa[j]);     }     cout << network.calc(0, xsw.size() + ysw.size()) << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n;     scanf( %lld , &n);     long long int i;     for (i = 2; i * i <= n; i++) {       while (n % (i * i) == 0) n /= i;     }     printf( %lld n , n);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, s, i, j, k;   bool A[301][301];   char str[301];   int main() {     scanf( %d%d%d , &n, &m, &s);     for (i = 0; i < n; i++) {       scanf( %s , str);       for (j = 0; j < m; j++) A[i][j] = str[j] ==  * ;     }     for (i = 1; 2 * i + 1 <= min(n, m); i++) {       for (j = i; j + i < n; j++) {         for (k = i; k + i < m; k++)           if (A[j][k] && A[j][k + i] && A[j][k - i] && A[j + i][k] &&               A[j - i][k]) {             s--;             if (!s) break;           }         if (!s) break;       }       if (!s) break;     }     if (s)       printf( -1 n );     else {       j++;       k++;       printf( %d %d n%d %d n%d %d n%d %d n%d %d n , j, k, j - i, k, j + i, k, j,              k - i, j, k + i);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int nm = 100002;   int n, d;   long long x;   int a[nm], b[nm], vt[nm];   int c[nm];   int nc;   int getNextX() {     x = (x * 37 + 10007) % 1000000007;     return x;   }   void init() {     int i;     for (i = 0; i < n; i = i + 1) {       a[i] = i + 1;     }     for (i = 0; i < n; i = i + 1) {       swap(a[i], a[getNextX() % (i + 1)]);     }     for (i = 0; i < n; i = i + 1) {       if (i < d)         b[i] = 1;       else         b[i] = 0;     }     for (i = 0; i < n; i = i + 1) {       swap(b[i], b[getNextX() % (i + 1)]);     }   }   int main() {     scanf( %d%d%I64d , &n, &d, &x);     init();     int i, j, k;     for (i = 0; i < n; ++i) {       vt[a[i]] = i;       if (b[i]) c[++nc] = i;     }     for (i = 0; i < n; ++i) {       for (j = n; j > n - 100 && j > 0; --j)         if (vt[j] <= i && b[i - vt[j]]) break;       if (j > n - 100 && j > 0) {         printf( %d n , j);         continue;       }       k = 0;       for (j = 1; j <= nc && c[j] <= i; ++j) k = max(k, a[i - c[j]]);       printf( %d n , k);     }   }


#include <bits/stdc++.h>   using namespace std;   const long long PR = 1000000009;   int n, m, premin[100009], sufmax[100009];   char A[100009], B[100009];   int main() {     ios::sync_with_stdio(false);     cin >> A >> B;     n = strlen(A);     m = strlen(B);     for (int i = 0; i < m; i++) premin[i] = n, sufmax[i] = -1;     int st = 0;     for (int i = 0; i < m && st < n; i++) {       while (A[st] != B[i]) {         st++;         if (st >= n) break;       }       premin[i] = st;       st++;     }     st = n - 1;     for (int i = m - 1; i >= 0 && st >= 0; i--) {       while (A[st] != B[i]) {         st--;         if (st < 0) break;       }       sufmax[i] = st;       st--;     }     int ans = m, i1 = -1, j1 = -1;     for (int i = 0; i < m; i++) {       if (premin[i] != n) {         int mid, st = i + 1, end = m - 1;         while (st < end) {           mid = (st + end) / 2;           if (sufmax[mid] >= premin[i] + 1)             end = mid;           else             st = mid + 1;         }         if (sufmax[st] < premin[i] + 1) st = m;         int now = st - i - 1;         if (now < ans) {           i1 = i + 1;           j1 = st - 1;           ans = now;         }       }     }     for (int i = m - 1; i >= 0; i--) {       if (sufmax[i] == -1) break;       int now = i - 1;       if (now < ans) {         j1 = i - 1;         i1 = 0;         ans = now;       }     }     if (i1 == -1 || j1 - i1 + 1 == m) {       cout <<  -  << endl;       return 0;     }     for (int i = 0; i < i1; i++) cout << B[i];     for (int j = j1 + 1; j < m; j++) cout << B[j];     cout << endl;     return 0;   };


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, m;     cin >> n >> m;     long long mod = 1;     int k = 0;     while (k < n) {       if (mod > m) {         break;       }       mod *= 2;       k++;     }     cout << m % mod << endl;   }


#include <bits/stdc++.h>   using namespace std;   int n, k;   string a;   int change(char c) {     int j = 0, i = 0, ans = 0, cont = 0;     for (i = 0; i < n; i++) {       if (a[i] == c) cont++;       if (cont > k) {         while (cont > k)           if (a[j++] == c) cont--;       }       ans = max(ans, i - j + 1);     }     return ans;   }   int main() {     ios::sync_with_stdio(0);     while (cin >> n >> k) {       a =   ;       int suma = 0, sumb = 0;       for (int i = 0; i < n; ++i) {         char c;         cin >> c;         if (c ==  a )           suma++;         else           sumb++;         a += c;       }       int ans;       if (suma > sumb)         ans = change( b );       else if (sumb > suma)         ans = change( a );       else         ans = max(change( a ), change( b ));       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<pair<int, int> > g[100100];   int fa[100100][18], typ[100100], n;   int sum[100100][2], dep[100100];   void dfs(int u) {     for (int i = 1; i < 18; ++i) fa[u][i] = fa[fa[u][i - 1]][i - 1];     for (auto v : g[u]) {       int A = v.first, tp = v.second;       sum[A][0] = sum[u][0];       sum[A][1] = sum[u][1];       ++sum[A][tp];       dep[A] = dep[u] + 1;       dfs(A);     }   }   int LCA(int u, int v) {     if (dep[u] > dep[v]) swap(u, v);     int hu = dep[u], hv = dep[v];     int tu = u, tv = v;     for (int det = hv - hu, i = 0; det; det >>= 1, i++)       if (det & 1) tv = fa[tv][i];     if (tu == tv) return tu;     for (int i = 17; i >= 0; --i) {       if (fa[tu][i] == fa[tv][i]) continue;       tu = fa[tu][i];       tv = fa[tv][i];     }     return fa[tu][0];   }   int tmp[2];   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; ++i) {       scanf( %d%d , &fa[i][0], &typ[i]);       if (fa[i][0] == -1) fa[i][0] = typ[i] = 0;     }     for (int i = 1; i <= n; ++i) g[fa[i][0]].push_back(pair<int, int>(i, typ[i]));     dfs(0);     int q;     scanf( %d , &q);     while (q--) {       int tp, u, v;       scanf( %d%d%d , &tp, &u, &v);       int lca = LCA(u, v);       if (!lca || lca == v) {         puts( NO );         continue;       }       if (tp == 1) {         if (lca != u) {           puts( NO );           continue;         }         tmp[0] = sum[v][0] - sum[u][0];         tmp[1] = sum[v][1] - sum[u][1];         if (tmp[1]) {           puts( NO );           continue;         }         puts( YES );       } else {         tmp[0] = sum[u][0] - sum[lca][0];         tmp[1] = sum[u][1] - sum[lca][1];         if (tmp[1]) {           puts( NO );           continue;         }         tmp[0] = sum[v][0] - sum[lca][0];         tmp[1] = sum[v][1] - sum[lca][1];         if (tmp[0]) {           puts( NO );           continue;         }         puts( YES );       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[32];   int n, k;   double dp[32][32][205];   int main() {     memset(dp, 0, sizeof(dp));     cin >> n >> k;     for (int i = 0; i < n; ++i) cin >> a[i];     for (int i = 0; i < n; ++i) {       for (int j = i; j < n; ++j) {         if (a[i] > a[j]) {           dp[i][j][0] = 1;         }       }     }     double prob = (double)2 / (n * (n + 1));     for (int op = 1; op <= k; ++op) {       for (int start = 0; start < n; ++start) {         for (int end = start; end < n; ++end) {           for (int x = 0; x < n; ++x) {             for (int y = x; y < n; ++y) {               int nx = x;               if (start <= x && x <= end) nx = end - x + start;               int ny = y;               if (start <= y && y <= end) ny = start + end - y;               if (ny >= nx)                 dp[x][y][op] += dp[nx][ny][op - 1] * prob;               else                 dp[x][y][op] += (1 - dp[ny][nx][op - 1]) * prob;             }           }         }       }     }     double ans = 0;     for (int i = 0; i < n; ++i)       for (int j = i + 1; j < n; ++j) ans += dp[i][j][k];     cout << fixed << setprecision(9) << ans << endl;     return 0;   }


#include <bits/stdc++.h>   const int mod = 1e9 + 7;   const int N = 3e5 + 1;   using namespace std;   void err(istream_iterator<string> it) {}   template <typename T, typename... Args>   void err(istream_iterator<string> it, T a, Args... args) {     cerr << *it <<   =   << a <<    ;     err(++it, args...);   }   long long arr[N], brr[N];   long long n, m, k, q, a, b;   long long binpow(long long a, long long n) {     long long res = 1;     while (n) {       if (n & 1) res = res * a;       a = a * a;       n /= 2;     }     return res;   }   void solve() {     cin >> n;     vector<long long> arr(n);     vector<long long> v;     for (int i = 0; i < n; i++) cin >> arr[i];     long long x = arr[0];     arr[0] = 0;     for (int k = 0; k + 1 < n; k++) {       x = min(max(0LL, arr[k + 1] - arr[k]), x);       arr[k + 1] -= x;     }     bool ok = true;     for (int k = 0; k + 1 < n; k++) {       if (arr[k + 1] - arr[k] < 0) ok = false;     }     n = v.size();     for (int i = 0; i < n; i++)       if (v[i] < 0) ok = false;     if (ok)       cout <<  yes ;     else       cout <<  no ;     cout <<   n ;     cerr <<   n ;   }   int main() {     int t;     t = 1;     cin >> t;     int a = 0;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, q;   struct interv {     long long l, r, ubonus, lbonus;     interv(long long L, long long R, long long UBONUS, long long LBONUS) {       l = L;       r = R;       ubonus = UBONUS;       lbonus = LBONUS;     }     bool operator<(const interv& x) const { return r < x.r; }   };   set<interv> s;   set<interv>::iterator it;   long long x, y, to;   char dir[3];   long long ans;   int main() {     scanf( %lld %lld , &n, &q);     s.insert(interv(1, n, 0, 0));     for (int i = 1; i <= q; i++) {       scanf( %lld %lld , &x, &y);       scanf( %s , dir);       it = s.lower_bound(interv(0, x, 0, 0));       if (it == s.end()) {         printf( 0 n );         continue;       }       long long b = (*it).r;       long long a = (*it).l;       long long ubonus = (*it).ubonus;       long long lbonus = (*it).lbonus;       if (x < a) {         printf( 0 n );         continue;       }       if (dir[0] ==  U ) {         ans = (b - a + 1) - (x - a) + ubonus;         printf( %lld n , ans);         s.erase(it);         if (x - 1 >= 1 && a <= x - 1) s.insert(interv(a, x - 1, ans, lbonus));         if (x + 1 <= n && x + 1 <= b) s.insert(interv(x + 1, b, ubonus, 0));       } else {         ans = (b - a + 1) - (b - x) + lbonus;         printf( %lld n , ans);         s.erase(it);         if (x - 1 >= 1 && a <= x - 1) s.insert(interv(a, x - 1, 0, lbonus));         if (x + 1 <= n && x + 1 <= b) s.insert(interv(x + 1, b, ubonus, ans));       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline void solve() {     long long n;     cin >> n;     vector<bool> isp(n + 1, 1);     vector<long long> maxx(n + 1, -1);     isp[0] = isp[1] = 0;     for (long long i = 2; i <= n; i++) {       if (isp[i]) {         if (i * 2 <= n) {           for (long long j = i * 2; j <= n; j += i) {             isp[j] = 0;             maxx[j] = max(maxx[j], i);           }         }       }     }     long long best = 1, now = n;     for (long long j = 2; j * j <= n; j++) {       while (now % j == 0) {         now /= j;         best = max(best, j);       }     }     best = max(best, now);     long long ans = n - best + 1;     for (long long i = n - best + 1; i < n; i++) {       ans = min(ans, i - maxx[i] + 1);     }     cout << ans;   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, m, k, y, a, b, c;   long long A[2005];   bool B[2005];   int main() {     cin >> n >> k;     priority_queue<pair<int, int> > pq;     for (int i = int(0); i < int(n); i++) {       cin >> A[i];       pq.push({A[i], i});     }     int ans = 0;     for (int i = int(0); i < int(k); i++) {       B[pq.top().second] = true;       ans += pq.top().first;       pq.pop();     }     cout << ans <<   n ;     m = -1;     int t = 0;     for (int i = int(0); i < int(n); i++) {       if (B[i] && t + 1 < k) {         cout << i - m <<    ;         m = i;         t++;       }     }     cout << n - 1 - m <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5;   int n;   int seq[N];   vector<int> zli[N];   int res[N];   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; ++i) {       scanf( %d , seq + i);       seq[i] = n - seq[i];       zli[seq[i]].push_back(i);     }     int rodzaj = 0;     for (int ile = 1; ile <= n; ++ile) {       if ((int)(zli[ile]).size() % ile) {         puts( Impossible );         exit(0);       }       for (int i = 0; i < (int)(zli[ile]).size(); i += ile) {         rodzaj++;         for (int j = i; j < i + ile; ++j) {           res[zli[ile][j]] = rodzaj;         }       }     }     puts( Possible );     for (int i = 1; i <= n; ++i) {       printf( %d  , res[i]);     }     puts(  );   }


#include <bits/stdc++.h>   int find_min(int pos, int target) {     int right = -1;     for (int i = 0; right == -1; i++)       if ((pos + i) % 26 == target) right = i;     int left = -1;     for (int i = 0; left == -1; i++)       if ((pos - i + 26 * 2) % 26 == target) left = i;     return std::min(right, left);   }   int main() {     int n;     std::cin >> n;     std::string s;     std::cin >> s;     std::string genome =  ACTG ;     int min_moves = INT_MAX;     for (int i = 0; i < n - 3; i++) {       int min_temp = 0;       for (int j = 0; j < 4; j++)         min_temp += find_min(s[i + j] -  A , genome[j] -  A );       min_moves = std::min(min_moves, min_temp);     }     std::cout << min_moves <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 50, maxm = 5e3 + 100;   int n, lim, f[maxn + 3], s[maxn + 3];   double p[maxn + 3], q[maxn + 3], dp[maxn + 3][maxm + 3];   bool check(double x) {     for (int i = n; i; i--) {       for (int j = lim + 1; j <= lim + 100; j++) {         dp[i + 1][j] = x;       }       for (int j = 0; j <= lim; j++) {         dp[i][j] = min(x, (dp[i + 1][j + f[i]] + f[i]) * p[i] +                               (dp[i + 1][j + s[i]] + s[i]) * q[i]);       }     }     return dp[1][0] == x;   }   int main() {     scanf( %d %d , &n, &lim);     for (int i = 1, x; i <= n; i++) {       scanf( %d %d %d , &f[i], &s[i], &x);       p[i] = x / 100., q[i] = (100 - x) / 100.;     }     double l = 0, r = 1e9, mid;     for (int k = 0; k < 70; k++) {       mid = (l + r) / 2;       if (check(mid)) {         l = mid;       } else {         r = mid;       }     }     printf( %.12lf n , (l + r) / 2);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, ans = 0;     bool flag = false;     int a[105];     cin >> n;     for (int i = 0; i < n; i++) cin >> a[i];     for (int i = 1; i < n; i++) {       if (a[i] == 2) {         if (a[i - 1] == 1) {           if (i >= 2 && a[i - 2] == 3)             ans += 2;           else             ans += 3;         } else {           flag = true;           break;         }       } else if (a[i] == 1) {         if (a[i - 1] == 2)           ans += 3;         else if (a[i - 1] == 3)           ans += 4;         else {           flag = true;           break;         }       } else {         if (a[i - 1] == 1)           ans += 4;         else {           flag = true;           break;         }       }     }     if (flag)       puts( Infinite );     else {       puts( Finite );       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int matmul[][6] = {{2, 1, 1, 1, 0, 0}, {1, 2, 1, 1, 0, 0},                            {1, 0, 1, 0, 0, 0}, {0, 1, 0, 1, 0, 0},                            {1, 1, 1, 1, 1, 0}, {2, 2, 2, 2, 1, 1}};   long long N, sx, sy, dx, dy, t;   struct matrix {     int m, n;     long long d[13][13];     matrix() {       m = 0;       n = 0;       memset(d, 0, sizeof d);     }     matrix(int m, int n) {       this->m = m;       this->n = n;       memset(d, 0, sizeof d);     }     matrix operator*(const matrix &a) const {       int x = m;       int y = n;       int z = a.n;       matrix res = matrix(x, z);       for (int i = 0; i < (x); i = i + 1)         for (int j = 0; j < (z); j = j + 1)           for (int k = 0; k < (y); k = k + 1)             res.d[i][j] = (res.d[i][j] + d[i][k] * a.d[k][j]) % N;       return (res);     }     matrix operator^(long long k) const {       matrix res = matrix(m, n);       matrix mul = (*this);       for (int i = 0; i < (m); i = i + 1) res.d[i][i] = 1;       while (k > 0) {         if (k % 2 == 1) res = res * mul;         mul = mul * mul;         k = k >> 1;       }       return (res);     }     void print(void) const {       for (int i = 0; i < (m); i = i + 1) {         for (int j = 0; j < (n); j = j + 1) cout << d[i][j] <<    ;         cout <<   n ;       }       cout <<   n ;     }   };   matrix fst, mul;   void process(void) {     cin >> N >> sx >> sy >> dx >> dy >> t;     if (N == 1) {       cout <<  1 1 ;       return;     }     fst = matrix(1, 6);     mul = matrix(6, 6);     for (int i = 0; i < (6); i = i + 1)       for (int j = 0; j < (6); j = j + 1) mul.d[i][j] = matmul[i][j] % N;     fst.d[0][0] = sx - 1;     fst.d[0][1] = sy - 1;     fst.d[0][2] = (dx % N + N) % N;     fst.d[0][3] = (dy % N + N) % N;     fst.d[0][4] = 0;     fst.d[0][5] = 1;     fst = fst * (mul ^ t);     cout << fst.d[0][0] + 1 <<     << fst.d[0][1] + 1;   }   int main(void) {     process();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     int n, m;     cin >> n >> m;     int ver[n + 1];     ver[n] = 1e9;     for (int i = 0; i < n; i++) cin >> ver[i];     int hor[m];     for (int i = 0; i < m; i++) {       int x1, x2, y;       cin >> x1 >> x2 >> y;       if (x1 > 1)         hor[i] = 0;       else         hor[i] = x2;     }     if (m == 0) {       cout << 0 << endl;       return 0;     }     sort(ver, ver + n);     sort(hor, hor + m);     int wy = 10000000;     int poz = m;     int a = 0;     for (int i = 0; i < n + 1; i++) {       while (a < m and hor[a] < ver[i]) {         poz--;         a++;       }       wy = min(wy, poz + i);     }     cout << wy << endl;     return 0;   }


#include <bits/stdc++.h>   const int md = 1e9 + 7;   const long long hs = 199;   using namespace std;   int n, x;   set<int> a;   int main() {     ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);     cin >> n;     for (int i = 1; i <= n; i++) a.insert(i);     cout <<  1  ;     while (--n) {       cin >> x;       a.erase(x);       auto it = a.end();       it--;       cout << 1 + *it - n <<   n ;     }     cout << 1 <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int setBite(int r, int pos) { return r | (1 << pos); }   int resetBit(int r, int pos) { return r & ~(1 << pos); }   bool checkBit(int r, int pos) { return (r & (1 << pos)); }   bool leap(long long x) {     if ((x % 4 == 0 && x % 100 != 0) || x % 400 == 0) return true;     return false;   }   long long bigmod(long long a, long long b, long long mod) {     if (b == 0) return 1;     if (b % 2 == 0) {       long long ret = bigmod(a, b / 2, mod);       return ((ret % mod) * (ret % mod)) % mod;     } else       return ((a % mod) * (bigmod(a, b - 1, mod) % mod)) % mod;   }   template <class T>   inline T gcd(T a, T b) {     if (a < 0) return gcd(-a, b);     if (b < 0) return gcd(a, -b);     return (b == 0) ? a : gcd(b, a % b);   }   template <class T>   inline T lcm(T a, T b) {     if (a < 0) return lcm(-a, b);     if (b < 0) return lcm(a, -b);     return a * (b / gcd(a, b));   }   template <class T>   inline T sqr(T x) {     return x * x;   }   template <class T>   inline T power(T r, T p) {     T ans = 1;     for (T i = 0; i < p; i++) {       ans *= r;     }     return ans;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int n;     cin >> n;     int g[2 * n + 5][2 * n + 5];     for (int i = 0; i < 2 * n + 5; i++) {       for (int j = 0; j < 2 * n + 5; j++) {         g[i][j] = 0;       }     }     for (int i = 1; i <= n - 1; i++) {       int a;       cin >> a;       g[i][i + 1] = a;       g[i + 1][i] = a;     }     for (int i = n + 1; i <= 2 * n - 1; i++) {       int a;       cin >> a;       g[i][i + 1] = a;       g[i + 1][i] = a;     }     for (int i = 1; i <= n; i++) {       int a;       cin >> a;       g[i][i + n] = a;       g[i + n][i] = a;     }     vector<int> v;     for (int i = 1; i <= n; i++) {       int ans = 0;       for (int j = 1; j <= i - 1; j++) {         ans += g[j][j + 1];       }       ans += g[i][i + n];       for (int j = i + n; j <= 2 * n - 1; j++) {         ans += g[j][j + 1];       }       v.push_back(ans);     }     sort(v.begin(), v.end());     cout << v[0] + v[1];     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int m;   long long int a;   long long int b;   set<int> s;   long long int im(long long int val, int dv) {     long long int z = 0;     long long int U = (1LL + val / dv) * (val / dv) / 2LL;     U *= dv;     U -= (val / dv) * (dv - (val % dv) - 1);     return U;     for (int i = 0; i <= val; i++) {       z += i / dv;     }     return z;   }   long long int cn(int star, int ds) {     long long int ret = im(m - ds, b) - im(star - ds - 1, b);     ret += m - star + 1;     return ret;   }   int main() {     cin >> m >> a >> b;     long long int mx = 0;     long long int cur = 0;     swap(a, b);     long long int ans = cn(0, 0);     s.insert(0);     while (true) {       if (cur < a) {         cur += b * ((a - cur + b - 1) / b);       }       mx = max(mx, cur);       cur -= a;       cur %= b;       if (mx > m) break;       if (s.count(cur)) break;       s.insert(cur);       ans += cn(mx, cur);     }     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n;     int a = 0;     cin >> n;     long long tp = n;     for (long long i = 2; i <= sqrt(tp); i++) {       if (tp % i == 0) {         while (tp % i == 0) tp /= i;         a = i;         break;       }     }     if (a == 0)       cout << n;     else if (tp != 1) {       printf( 1 );     } else       printf( %d , a);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   map<string, int> Map;   char str[2200][22];   int p[2200], q[2200];   int main() {     int num, n, k1, k2, cnt;     char s1[22], s2[22];     while (scanf( %d , &n) != EOF) {       memset(p, 0, sizeof(p));       memset(q, 0, sizeof(q));       cnt = 1;       num = 0;       while (n--) {         scanf( %s %s , s1, s2);         if (Map[s2] > 0) continue;         if ((k1 = Map[s1]) > 0) {           Map[s1] = 0;           strcpy(str[cnt++], s2);           p[q[k1]] = cnt - 1;           q[cnt - 1] = q[k1];           Map[s2] = cnt - 1;         } else {           strcpy(str[cnt++], s1);           strcpy(str[cnt++], s2);           p[cnt - 2] = cnt - 1;           q[cnt - 1] = cnt - 2;           Map[s2] = cnt - 1;           num++;         }       }       printf( %d n , num);       int i;       for (i = 0; i < cnt; i++)         if (p[i]) printf( %s %s n , str[i], str[p[i]]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[100002];   int gcd(int a, int b) {     int c;     while (a != 0) {       c = a;       a = b % a;       b = c;     }     return b;   }   int main() {     int n;     int mina = 2000000009;     cin >> n;     cin >> a[1];     int ucln;     ucln = a[1];     for (long long int i = 2; i <= n; i++) {       scanf( %d , a + i);       ucln = gcd(ucln, a[i]);     }     int res0 = 1;     for (long long int i = 1; i <= n; i++) {       if (a[i] % ucln != 0) {         res0 = 0;       }     }     if (ucln == 1) {       res0 = 0;     }     if (res0 == 1) {       cout <<  YES n ;       cout << 0;     } else {       a[n + 1] = 2;       int res = 0;       for (int i = 1; i <= n;) {         if (a[i] % 2 == 0) {           i++;         } else {           if (a[i + 1] % 2 == 1) {             res += 1;             i += 2;           } else {             res += 2;             i += 2;           }         }       }       cout <<  YES n ;       cout << res;     }   }


#include <bits/stdc++.h>   using namespace std;   int maxx = 1e6 + 10;   int up(int a, int b) {     if (a % b)       return a / b + 1;     else       return a / b;   }   int main() {     int t;     scanf( %d , &t);     while (t--) {       int n, d;       scanf( %d%d , &n, &d);       bool flag = 0;       for (int x = 0; x < maxx; x++) {         if ((x + up(d, x + 1)) <= n) {           flag = 1;           break;         }       }       if (flag)         printf( YES n );       else         printf( NO n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int mod = 998244353;   long long int expo(long long int base, long long int exponent,                      long long int mod) {     long long int ans = 1;     while (exponent != 0) {       if (exponent & 1) ans = (1LL * ans * base) % mod;       base = (1LL * base * base) % mod;       exponent >>= 1;     }     return ans % mod;   }   vector<long long int> g[100005];   long long int val[100005], dist[100005];   void dfs(long long int node, long long int par, long long int d) {     dist[node] = d;     if (g[node].size() == 1) val[par]++;     for (auto x : g[node]) {       if (x != par) dfs(x, node, d + 1);     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int tests = 1;     while (tests--) {       long long int i, j, u, v, n;       cin >> n;       for (long long int i = 1; i <= n - 1; i++) {         cin >> u >> v;         g[u].push_back(v);         g[v].push_back(u);       }       long long int root = -1;       for (long long int i = 1; i <= n; i++) {         if (g[i].size() > 1) {           root = i;           break;         }       }       dfs(root, 0, 0);       long long int mx = n - 1, mn;       long long int odd = 0, even = 0;       for (long long int i = 1; i <= n; i++) {         if (g[i].size() > 1) continue;         if (dist[i] % 2)           odd++;         else           even++;       }       if (odd == 0 || even == 0)         mn = 1;       else         mn = 3;       for (long long int i = 1; i <= n; i++) {         mx -= max(0LL, val[i] - 1);       }       cout << mn <<     << mx;     }     cerr <<   nTime elapsed:   << 1000 * clock() / CLOCKS_PER_SEC <<  ms n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int Maxn = 55;   long long dp[Maxn][10];   int main() {     string k;     cin >> k;     int n = k.length();     for (int i = 0; i < 10; i++) {       dp[0][i] = 1;     }     for (int i = 1; i < n; i++) {       int t = k[i] -  0 ;       for (int j = 0; j < 10; j++) {         int l = (t + j) / 2, r = (t + j + 1) / 2;         dp[i][l] += dp[i - 1][j];         if (l != r) dp[i][r] += dp[i - 1][j];       }     }     bool flag = false;     for (int i = 1; i < n; i++) {       int t = k[i] -  0 , j = k[i - 1] -  0 ;       if ((t + j + 1) / 2 != t && (t + j) / 2 != t) flag = true;     }     long long ans = (long long)-1 + flag;     for (int i = 0; i <= 9; i++) {       ans = (long long)ans + (long long)dp[n - 1][i];     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long M = 1000000007;   const double pi = acos(-1);   const int N = 2e5 + 10;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);     ;     long long n, k, m, d, q = 1, ans = 0;     cin >> n >> k >> m >> d;     for (long long i = 1; i < d + 1; i++) {       long long mx1 = m;       long long mx2 = n / q;       long long w = min(mx1, mx2) * i;       ans = max(ans, w);       q += k;       if (q > n) break;     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 105;   const int M = 1005;   int n, m, x[N], s;   double p[N * M], tmp[N * M];   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; ++i) scanf( %d , &x[i]);     for (int i = 1; i <= n; ++i) s += x[i];     if (m == 1) {       puts( 1.0000000000 );       return 0;     }     p[0] = 1;     for (int i = 1; i <= n; ++i) {       double now = 0;       for (int j = 1; j < s; ++j) {         now += p[j - 1];         if (x[i] <= j) now -= p[j - x[i]];         if (x[i] < j) now += p[j - x[i] - 1];         if (m < j) now -= p[j - m - 1];         tmp[j] = now / (m - 1);       }       for (int j = 0; j <= s; ++j) p[j] = tmp[j];       copy(tmp, tmp + s, p);     }     double ans = 0;     for (int i = 1; i <= s; ++i) ans += p[i];     ans = ans * (m - 1) + 1;     printf( %.10f n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 10;   const int M = 1e6 + 10;   int n, m, x, y, a[N], f[M];   bitset<N> ans, tmp;   int main() {     scanf( %d%d%d , &n, &x, &y);     for (int i = 1; i <= n + 1; i++) {       scanf( %d , &a[i]);       tmp.set(a[i]);     }     for (int i = 1; i <= n + 1; i++) {       ans |= tmp >> a[i];     }     for (int i = 1; i <= x; i++)       if (ans[i]) f[2 * (i + y)] = 2 * (i + y);     for (int i = 1; i < M; i++)       for (int j = i; j < M; j += i) f[j] = max(f[j], f[i]);     scanf( %d , &m);     while (m--) {       scanf( %d , &x);       if (f[x])         printf( %d  , f[x]);       else         printf( -1  );     }   }


#include <bits/stdc++.h>   using namespace std;   int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};   long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int n, m;     cin >> n >> m;     string s;     char x, y;     cin >> s;     char ch[26];     for (long long int i = 0; i < 26; i++) {       ch[i] = i +  a ;     }     for (long long int i = 0; i < m; i++) {       cin >> x >> y;       for (long long int j = 0; j < 26; j++) {         if (x == ch[j]) {           ch[j] = y;         } else if (y == ch[j]) {           ch[j] = x;         }       }     }     for (long long int i = 0; i < s.size(); i++) {       cout << ch[s[i] -  a ];     }     return 0;   }


#include <bits/stdc++.h>   const int N = 200010;   std::vector<int> e[N];   int color[N], dep[N];   bool vis[N];   int n, k;   int max = 0;   void dfs(int u, int fa) {     max = std::max(max, dep[u]);     for (auto v : e[u]) {       if (vis[v] || v == fa) {         continue;       }       dep[v] = dep[u] + 1;       dfs(v, u);     }   }   std::vector<int> stack;   std::vector<int> diameter;   void find_diameter(int u, int fa, int t) {     stack.push_back(u);     if (u == t) {       diameter = stack;     }     for (auto v : e[u]) {       if (v == fa) {         continue;       }       find_diameter(v, u, t);     }     stack.pop_back();   }   void solve(int u, int fa, int add) {     for (auto v : e[u]) {       if (vis[v] || v == fa) {         continue;       }       color[v] = (color[u] + add + k) % k;       solve(v, u, add);     }   }   int main() {     scanf( %d%d , &n, &k);     for (int i = 0, u, v; i < n - 1; ++i) {       scanf( %d%d , &u, &v);       e[u].push_back(v);       e[v].push_back(u);     }     if (k == 2) {       solve(1, 0, 1);       puts( Yes );       for (int i = 1; i <= n; ++i) {         printf( %d%c , color[i] + 1,    n [i == n]);       }       return 0;     }     dfs(1, 0);     int s = std::max_element(dep + 1, dep + n + 1) - dep;     dep[s] = 0;     dfs(s, 0);     int t = std::max_element(dep + 1, dep + n + 1) - dep;     find_diameter(s, 0, t);     int sz = diameter.size();     for (int i = 0; i < sz; ++i) {       color[diameter[i]] = i % k;       vis[diameter[i]] = true;     }     for (int i = 0; i < sz; ++i) {       dep[diameter[i]] = 0;       max = 0;       dfs(diameter[i], 0);       if (max == 0) {         continue;       }       if (max + i + 1 < k) {         solve(diameter[i], 0, -1);       } else if (max + sz - i < k) {         solve(diameter[i], 0, 1);       } else {         puts( No );         return 0;       }     }     puts( Yes );     for (int i = 1; i <= n; ++i) {       printf( %d%c , color[i] + 1,    n [i == n]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long n1, m;     cin >> n1 >> m;     string s;     cin >> s;     long long n;     n = s.size();     long long lps[n];     lps[0] = 0;     long long i, j;     if (m == 0) {       long long ans3 = 1;       for (i = 1; i <= n1; i++) {         ans3 = (ans3 * 26) % 1000000007;       }       cout << ans3 << endl;       return 0;     }     i = 0;     i++;     long long len = 0;     j = 0;     while (i < n) {       if (s[i] == s[len]) {         len++;         lps[i] = len;         i++;       } else {         if (len != 0) {           len = lps[len - 1];         } else {           lps[i] = 0;           i++;         }       }     }     vector<long long> v;     for (i = 0; i < m; i++) {       long long x;       cin >> x;       v.push_back(x);     }     if (s.size() == 1) {       long long ans3 = 1;       for (i = 1; i <= n1 - m; i++) {         ans3 = (ans3 * 26) % 1000000007;       }       cout << ans3 << endl;       return 0;     }     if (s.size() == 1 && m == 1) {       cout << 1 << endl;       return 0;     }     long long vis[n1];     for (i = 0; i < n1; i++) {       vis[i] = 0;     }     long long r;     r = -1;     for (i = 0; i < m; i++) {       long long x;       x = v[i];       x--;       if (x > r) {         if (x + n - 1 >= n1) {           cout << 0 << endl;           return 0;         }         for (j = x; j < x + n; j++) {           vis[j] = 1;         }         r = x + n - 1;       } else {         if (r + (n - (r - x + 1)) >= n1) {           cout << 0 << endl;           return 0;         }         for (j = r + 1; j <= r + (n - (r - x + 1)); j++) {           vis[j] = 1;         }         r = r + (n - (r - x + 1));       }     }     long long c = 0LL;     for (i = 0; i < n1; i++) {       if (vis[i] == 0) c++;     }     long long arr[c + 1];     arr[0] = 1;     for (i = 1; i <= c; i++) {       arr[i] = (arr[i - 1] * 26) % 1000000007;     }     map<long long, long long> m1;     long long k1;     k1 = lps[n - 1];     while (k1 > 0) {       m1[n - k1] = 1;       k1 = lps[k1 - 1];     }     if (m == 1) {       cout << arr[c] << endl;       return 0;     }     r = v[0] - 1;     for (i = 1; i < m; i++) {       long long x;       x = v[i];       x--;       if (r + n - 1 < x) {         r = x;       } else {         long long pos;         pos = x - r;         if (m1.find(pos) == m1.end()) {           cout << 0 << endl;           return 0;         } else           r = x;       }     }     cout << arr[c] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 100010;   const int INF = 0x7f7f7f7f;   const double pi = 4.0 * atan(1.0);   int cases;   struct Segment_Tree {     long long lazy[MAXN << 2];     long long data[MAXN << 2];     long long flag[MAXN << 2];     void pushup(int o) {       data[o] = data[(o << 1)] + data[(o << 1) | 1];       if (flag[(o << 1)] != flag[(o << 1) | 1]) {         flag[o] = 0;       } else {         flag[o] = flag[(o << 1)];       }     }     void setlazy(int o, int m, long long v) {       lazy[o] += v;       data[o] += m * v;     }     void pushdown(int o, int m) {       if (lazy[o]) {         setlazy((o << 1), m - (m >> 1), lazy[o]);         setlazy((o << 1) | 1, m >> 1, lazy[o]);         flag[(o << 1)] = flag[(o << 1) | 1] = flag[o];         lazy[o] = 0;       }     }     void build_tree(int o, int l, int r) {       if (l == r) {         flag[o] = l;         return;       }       int mid = (l + r) >> 1;       build_tree((o << 1), l, mid);       build_tree((o << 1) | 1, mid + 1, r);       pushup(o);     }     void update(int o, int l, int r, int x, int y, long long v) {       if (x <= l && r <= y && flag[o] != 0) {         lazy[o] += abs(flag[o] - v);         data[o] += (long long)(r - l + 1) * abs(flag[o] - v);         flag[o] = v;         return;       }       pushdown(o, r - l + 1);       int mid = (l + r) >> 1;       if (x <= mid) update((o << 1), l, mid, x, y, v);       if (y > mid) update((o << 1) | 1, mid + 1, r, x, y, v);       pushup(o);     }     long long query(int o, int l, int r, int x, int y) {       if (x <= l && r <= y) {         return data[o];       }       pushdown(o, r - l + 1);       int mid = (l + r) >> 1;       if (y <= mid) return query((o << 1), l, mid, x, y);       if (x > mid) return query((o << 1) | 1, mid + 1, r, x, y);       return query((o << 1), l, mid, x, y) +              query((o << 1) | 1, mid + 1, r, x, y);     }   } segtree;   int main() {     int n, m, op, x, y;     long long z;     scanf( %d%d , &n, &m);     segtree.build_tree(1, 1, n);     for (int i = 0; i < m; i++) {       scanf( %d , &op);       if (op == 1) {         scanf( %d%d%lld , &x, &y, &z);         segtree.update(1, 1, n, x, y, z);       } else if (op == 2) {         scanf( %d%d , &x, &y);         printf( %lld n , segtree.query(1, 1, n, x, y));       }     }   }


#include <bits/stdc++.h>   using namespace std;   int n, a[100001], c[100001];   int main() {     cin >> n;     for (int i = 0; i < n; i++) cin >> a[i];     int s = 0;     for (int i = n - 1; i >= 0; i--)       if (s > 0)         s -= a[i];       else {         c[i] = 1;         s += a[i];       }     if (s < 0)       for (int i = 0; i < n; i++) c[i] ^= 1;     for (int i = 0; i < n; i++) cout << (c[i] ?  +  :  - );     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct num2 {     static const int MB = 1e9 + 9;     int b;     num2() {}     num2(int x) : b(x) {}     num2 operator+(const num2& x) const { return num2((b + x.b) % MB); }     num2 operator-(const num2& x) const { return num2((b + MB - x.b) % MB); }     num2 operator*(int x) const { return num2(((long long)b * x) % MB); }     num2 operator*(const num2& x) const {       return num2(((long long)b * x.b) % MB);     }     bool operator==(const num2& x) const { return b == x.b; }   };   const int MODP = 701;   template <class T>   struct StringOps {     StringOps() {}     StringOps(const string& s) : s(s) {       n = s.length();       deg.resize(n + 1);       hashes.resize(n);       deg[0] = T(1);       for (int i = 1; i <= n; ++i) {         deg[i] = deg[i - 1] * T(MODP);       }       T curhash = T(0);       for (int i = 0; i < n; ++i) {         curhash = curhash * T(MODP) + T(s[i]);         hashes[i] = curhash;       }     }     char get(int idx) { return s[idx]; }     T get_hash(int l, int r) {       T cur(0);       if (l > 0) {         cur = hashes[l - 1];       }       return hashes[r] - cur * deg[r - l + 1];     }     int string_lcp(int l, int r, int lim = 1e9) {       int cleft = 1, cright = min(n - r, n - l);       cright = min(lim, cright);       int res = 0;       while (cleft <= cright) {         int key = (cleft + cright) / 2;         if (s[l + key - 1] != s[r + key - 1]) {           cright = key - 1;         } else if (get_hash(l, l + key - 1) == get_hash(r, r + key - 1)) {           res = key;           cleft = key + 1;         } else {           cright = key - 1;         }       }       return res;     }     vector<T> hashes;     vector<T> deg;     string s;     int n;   };   const int maxN = 1000100;   const int MOD = 1e9 + 7;   int len1, len2;   int u, v;   StringOps<num2> sops;   int get_nlength(const pair<int, int>& a) {     if (a.first == u) {       if (a.second != len1) {         return len1 - 1;       } else {         return len1;       }     }     if (a.second != len2) {       return len2 - 1;     } else {       return len2;     }   }   void fill_segs(int& l1, int& r1, int& l2, int& r2, const pair<int, int>& a) {     if (a.first == u) {       l2 = r2 = -1;       if (a.second == 0) {         l1 = 1, r1 = len1 - 1;       } else if (a.second >= len1 - 1) {         l1 = 0, r1 = a.second - 1;       } else {         l1 = 0, r1 = a.second - 1;         l2 = a.second + 1, r2 = len1 - 1;       }       return;     }     l2 = r2 = -1;     if (a.second == 0) {       l1 = 1, r1 = len2 - 1;     } else if (a.second >= len2 - 1) {       l1 = 0, r1 = a.second - 1;     } else {       l1 = 0, r1 = a.second - 1;       l2 = a.second + 1, r2 = len2 - 1;     }     l1 += len1, r1 += len1;     if (l2 != -1) {       l2 += len1, r2 += len1;     }   }   int cmp2(vector<pair<int, int>>& a, vector<pair<int, int>>& b, int p1 = 0,            int p2 = 0) {     if (p1 == a.size() && p2 < b.size()) {       return -1;     }     if (p1 == a.size() && p2 == b.size()) {       return 0;     }     if (p2 == b.size() && p1 < a.size()) {       return 1;     }     if (p1 + 1 == a.size() && p2 + 1 == b.size() && a[0] == b[0]) {       return 0;     }     if (p1 + 2 == a.size() && p2 + 2 == b.size() && a[0] == b[0] &&         a[1] == b[1]) {       return 0;     }     if (sops.get(a[p1].first) != sops.get(b[p2].first)) {       char c1 = sops.get(a[p1].first);       char c2 = sops.get(b[p2].first);       if (c1 < c2) {         return -1;       }       return 1;     }     int lcp = sops.string_lcp(         a[p1].first, b[p2].first,         min(a[p1].second - a[p1].first + 1, b[p2].second - b[p2].first + 1));     lcp = min(         lcp, min(a[p1].second - a[p1].first + 1, b[p2].second - b[p2].first + 1));     int nx = a[p1].first + lcp - 1, ny = b[p2].first + lcp - 1;     if (nx >= a[p1].second) {       ++p1;     } else {       a[p1].first = nx + 1;     }     if (ny >= b[p2].second) {       ++p2;     } else {       b[p2].first = ny + 1;     }     return cmp2(a, b, p1, p2);   }   bool cmp(const pair<int, int>& a, const pair<int, int>& b) {     int nlen1 = get_nlength(a);     int nlen2 = get_nlength(b);     if (nlen1 == 0 && nlen2 == 0) {       if (a.first == u & b.first == v) {         return true;       }       return false;     }     if (nlen1 == 0) {       return true;     }     if (nlen2 == 0) {       return false;     }     int l1, r1, l2, r2;     fill_segs(l1, r1, l2, r2, a);     int p1, q1, p2, q2;     fill_segs(p1, q1, p2, q2, b);     vector<pair<int, int>> na;     vector<pair<int, int>> nb;     na.push_back(make_pair(l1, r1));     if (l2 != -1) {       na.push_back(make_pair(l2, r2));     }     nb.push_back(make_pair(p1, q1));     if (p2 != -1) {       nb.push_back(make_pair(p2, q2));     }     int val = cmp2(na, nb);     if (val == 0) {       if (a.first == u && b.first == v) {         return true;       }       return false;     }     return val == -1;   }   struct Node {     Node() { left = right = nullptr; }     int idxleft, idxright;     Node* left;     Node* right;   };   int curorder[maxN];   int lenorder;   void dfs(Node* root) {     if (!root) {       return;     }     if (root->left) {       dfs(root->left);     }     for (int i = root->idxleft; i <= root->idxright; ++i) {       curorder[lenorder] = i;       ++lenorder;     }     if (root->right) {       dfs(root->right);     }   }   pair<int, int> order[2][maxN];   int clen[2];   void get_order(const string& s, int p) {     int n = s.length();     Node* root = new Node();     Node* curnode = root;     for (int i = 0; i < n;) {       int cur = i;       while (cur < n && s[cur] == s[i]) {         ++cur;       }       curnode->idxleft = i, curnode->idxright = cur - 1;       if (cur == n) {         break;       }       if (s[i] < s[cur]) {         Node* left = new Node();         curnode->left = left;         curnode = curnode->left;       } else {         Node* right = new Node();         curnode->right = right;         curnode = curnode->right;       }       i = cur;     }     lenorder = 0;     dfs(root);     int ps = n;     for (int i = 0; i < n; ++i) {       if (curorder[i] == n - 1) {         ps = i + 1;         break;       }     }     vector<pair<int, int>> result;     clen[p] = 0;     for (int i = 0; i < ps; ++i) {       order[p][clen[p]] = make_pair(v, curorder[i]);       ++clen[p];     }     order[p][clen[p]] = make_pair(v, n);     ++clen[p];     for (int i = ps; i < n; ++i) {       order[p][clen[p]] = make_pair(v, curorder[i]);       ++clen[p];     }   }   int dp[2][maxN];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     int n;     cin >> n;     vector<string> s(n);     for (int i = 0; i < n; ++i) {       cin >> s[i];     }     for (int i = 0; i <= s[0].length(); ++i) {       dp[u][i] = 1;     }     sops = StringOps<num2>(s[0]);     len1 = 0, len2 = s[0].length();     u = 1, v = 0;     get_order(s[0], 0);     swap(u, v);     for (int i = 0; i + 1 < n; ++i) {       string& s1 = s[i];       string& s2 = s[i + 1];       string nw = s1 + s2;       len1 = s1.length(), len2 = s2.length();       sops = StringOps<num2>(nw);       get_order(s[i + 1], v);       int cadd = 0;       int head1 = 0, head2 = 0;       while (head1 < clen[u] || head2 < clen[v]) {         if (head1 == clen[u]) {           dp[v][order[v][head2].second] = cadd;           ++head2;         } else if (head2 == clen[v]) {           break;         } else {           if (cmp(order[u][head1], order[v][head2])) {             int nhead1 = head1;             while (nhead1 < clen[u] &&                    s1[order[u][nhead1].second] == s1[order[u][head1].second] &&                    order[u][nhead1].second - order[u][head1].second ==                        nhead1 - head1) {               ++nhead1;             }             for (int j = head1; j < nhead1; ++j) {               cadd += dp[u][order[u][j].second];               if (cadd >= MOD) {                 cadd -= MOD;               }             }             head1 = nhead1;           } else {             int nhead2 = head2;             while (nhead2 < clen[v] &&                    s2[order[v][nhead2].second] == s2[order[v][head2].second] &&                    order[v][nhead2].second - order[v][head2].second ==                        nhead2 - head2) {               ++nhead2;             }             for (int j = head2; j < nhead2; ++j) {               dp[v][order[v][j].second] = cadd;             }             head2 = nhead2;           }         }       }       swap(u, v);     }     int res = 0;     int res2 = 0;     for (int i = 0; i <= s.back().length(); ++i) {       res += dp[u][i];       if (res >= MOD) {         res -= MOD;       }     }     cout << res << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   namespace Elaina {   template <class T>   inline T Max(const T x, const T y) {     return x < y ? y : x;   }   template <class T>   inline T Min(const T x, const T y) {     return x < y ? x : y;   }   template <class T>   inline T fab(const T x) {     return x < 0 ? -x : x;   }   template <class T>   inline void getMax(T& x, const T y) {     x = Max(x, y);   }   template <class T>   inline void getMin(T& x, const T y) {     x = Min(x, y);   }   template <class T>   T gcd(const T x, const T y) {     return y ? gcd(y, x % y) : x;   }   template <class T>   inline T readin(T x) {     x = 0;     int f = 0;     char c;     while ((c = getchar()) <  0  ||  9  < c)       if (c ==  - ) f = 1;     for (x = (c ^ 48);  0  <= (c = getchar()) && c <=  9 ;          x = (x << 1) + (x << 3) + (c ^ 48))       ;     return f ? -x : x;   }   template <class T>   void fwrit(const T x) {     if (x < 0) return putchar( - ), fwrit(-x);     if (x > 9) fwrit(x / 10);     putchar(x % 10 ^ 48);   }   }  // namespace Elaina   using namespace Elaina;   const int maxn = 3e5;   const int jzm = 1000000007;   char fuck[maxn + 5];   int min_len;   char s[maxn + 5];   int n;   int tot[maxn + 5][4];   int sy = 0;   int ans[maxn + 5];   inline void addchar(const char c, const int i) {     ++n;     s[n] = c, ++tot[n][i];   }   inline void init() {     min_len = (1 << 30);     for (int id = 1, id_end_ = 3; id <= id_end_; ++id) {       scanf( %s , fuck + 1);       int len = strlen(fuck + 1);       for (int i = 1, i_end_ = len; i <= i_end_; ++i) addchar(fuck[i], id);       addchar( z  + id, 0);       min_len = Min(min_len, len);     }     --n;   }   int sa[maxn + 5], x[maxn * 2 + 5], y[maxn * 2 + 5], c[maxn + 5], lev;   inline void getsa() {     lev =  z  + 3;     for (int i = 1, i_end_ = n; i <= i_end_; ++i) ++c[x[i] = s[i]];     for (int i = 2, i_end_ = lev; i <= i_end_; ++i) c[i] += c[i - 1];     for (int i = n, i_end_ = 1; i >= i_end_; --i) sa[c[x[i]]--] = i;     for (int k = 1; k <= n; k <<= 1) {       int sz = 0;       for (int i = n - k + 1, i_end_ = n; i <= i_end_; ++i) y[++sz] = i;       for (int i = 1, i_end_ = n; i <= i_end_; ++i)         if (sa[i] > k) y[++sz] = sa[i] - k;       for (int i = 1, i_end_ = lev; i <= i_end_; ++i) c[i] = 0;       for (int i = 1, i_end_ = n; i <= i_end_; ++i) ++c[x[i]];       for (int i = 2, i_end_ = lev; i <= i_end_; ++i) c[i] += c[i - 1];       for (int i = n, i_end_ = 1; i >= i_end_; --i)         sa[c[x[y[i]]]--] = y[i], y[i] = 0;       swap(x, y);       x[sa[1]] = 1;       int level = 1;       for (int i = 2, i_end_ = n; i <= i_end_; ++i)         x[sa[i]] = (y[sa[i]] == y[sa[i - 1]] && y[sa[i] + k] == y[sa[i - 1] + k])                        ? level                        : ++level;       if (level == n) break;       lev = level;     }   }   int heit[maxn + 5], rk[maxn + 5];   inline void getheit() {     int h = 0;     for (int i = 1, i_end_ = n; i <= i_end_; ++i) rk[sa[i]] = i;     for (int i = 1, i_end_ = n; i <= i_end_; ++i) {       if (rk[i] == 1) continue;       if (h) --h;       int j = sa[rk[i] - 1];       while (i + h <= n && j + h <= n && s[i + h] == s[j + h]) ++h;       heit[rk[i]] = h;     }   }   struct node {     int x, v;     inline int operator<(const node rhs) const { return v > rhs.v; }   } v[maxn + 5 + 5];   int fa[maxn + 5];   int find(const int x) { return fa[x] == x ? x : fa[x] = find(fa[x]); }   int cock(const int x) {     return 1ll * tot[x][1] * tot[x][2] % jzm * tot[x][3] % jzm;   }   inline void merge(int x, int y) {     x = find(x), y = find(y);     if (x == y) return;     sy -= cock(x);     if (sy < 0) sy += jzm;     sy -= cock(y);     if (sy < 0) sy += jzm;     fa[x] = y;     for (int j = 1, j_end_ = 3; j <= j_end_; ++j) tot[y][j] += tot[x][j];     sy += cock(y);     if (sy >= jzm) sy -= jzm;   }   inline void solve() {     for (int i = 1, i_end_ = n; i <= i_end_; ++i) v[i] = node{sa[i], heit[i]};     for (int i = 1, i_end_ = n; i <= i_end_; ++i) fa[i] = i;     sort(v + 1, v + n + 1);     int now = 1;     for (int i = min_len, i_end_ = 1; i >= i_end_; --i) {       while (now <= n && v[now].v >= i) {         int pre = sa[rk[v[now].x] - 1];         merge(pre, v[now].x);         ++now;       }       ans[i] = sy;     }     for (int i = 1, i_end_ = min_len; i <= i_end_; ++i) printf( %d  , ans[i]);   }   signed main() {     init();     getsa();     getheit();     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 1000000007;   const long double eps = 1e-9;   const long double pi = 3.141592653589793;   const long double e = 2.718281828459045;   int dp[100005], h[100005];   int n, mmm;   int main() {     memset(dp, -1, sizeof(dp));     memset(h, 0, sizeof(h));     mmm = 0;     scanf( %d , &n);     dp[0] = 0;     dp[n + 1] = 0;     for (int i = 1; i <= n; i++) {       scanf( %d , &h[i]);     }     for (int i = 1; i <= n; i++) {       dp[i] = min(dp[i - 1] + 1, h[i]);     }     for (int i = n; i >= 1; i--) {       dp[i] = min(dp[i], dp[i + 1] + 1);       mmm = max(mmm, dp[i]);     }     cout << mmm << endl;     return 0;   }


//THINK ALOUD !!    #include <bits/stdc++.h>   #define debug(x) cout <<   -> [   << #x <<   =   << x <<  ] n     #define debug2(x, y) cout <<   -> [   << #x <<   =   << x <<   ,   << #y <<   =   << y <<   ] n    #define debug3(x, y, z) cout <<   -> [   << #x <<   =   << x <<   ,   << #y <<   =   << y <<   ,   << #z <<   =   << z <<   ] n ;   #define debug4(x, y, z, xx) cout <<   -> [   << #x <<   =   << x <<   ,   << #y <<   =   << y <<   ,   << #z <<   =   << z <<   ,   << #xx <<   =   << xx <<   ] n ;      using namespace std;   using ll=long long int;   using lld=long double;   #define mp make_pair   #define pb push_back   #define accu accumulate       #define pll pair<ll, ll>   #define pii pair<int, int>    #define pci pair<char, int>    #define pic pair<int, char>    #define pls pair<ll, string>   #define psl pair<string, ll>   #define pis pair<int, string>   #define psi paid<string, int>   // #define x first    // #define y second   #define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);         #define rep(i, a, n) for (ll i = a; i < n; i++)   #define per(i, a, n) for (ll i = n-1; i >= a; i--)   #define repp(i, a, n, p) for (ll i = a; i < n; i += p)   #define all(c) (c).begin(), (c).end()   #define lla(c) (c).rbegin(), (c).rend()   #define print_arr(arr, n) for (int i = 0; i < n; i++) std::cout << arr[i] <<    ; std::cout <<   n ;   #define mod 1000000007   #define primeSize 2000000   #define Size 1e6      template <typename t> inline void print(const t & v) {       for (const auto& i : v) {           std::cout << i <<    ;       } std::cout <<   n ;   }      template <typename t> inline void printt(const t & v) {        for (const auto& i : v) {            std::cout << i.first <<     << i.second <<   n ;       } std::cout <<   n ;   }      template <typename INT> INT GCD(INT a, INT b) {        //     if (b == 0) return a;        //     return gcd(b, a%b);       return b ? gcd(b, a%b) : a;   }         template <typename INT> INT LCM(INT a, INT b) {        return a / gcd(a, b) * b;   }      template <typename INT> std::map<INT, int> factorize(INT n) {        map<INT, int> mp;        for (INT i = 2; i * i <= n; i++) {            while (n % i == 0) {                n /= i;                mp[i] ++;           }       }          if (n > 1) mp[n] += 1;       return mp;   }      ll bin_pow(ll a, ll b) {       if (b == 0) return 1;       long long res = bin_pow(a, b / 2);       if (b % 2) return res * res * a;       else return res * res;   }      int totalDigits(ll i) {        return i > 0 ? (int) log10 ((double) i) + 1 : 1;   }      vector<bool> isPrime(primeSize, true);   vector<int> arePrimes;   void make_seive() {        isPrime[0] = false;        isPrime[1] = false;           for (int i = 2; i <= sqrt(primeSize); i++) {            if (isPrime[i]) {                for (int j = i * 2; j <= primeSize; j += i) {                    isPrime[j] = false;                }           }       }          for (int i = 2; i < primeSize; i++) {            if (isPrime[i]) {                arePrimes.push_back(i);            }       }   }         void solve() {       int n;       cin >> n;          vector<ll> X;       vector<ll> Y;          for (int i = 0; i < 2 * n; i++) {            int a, b;            cin >> a >> b;               a = abs(a);            b = abs(b);           if (a == 0)                X.push_back(b);           else                Y.push_back(a);       }          sort(all(X));       sort(lla(Y));          lld ans = 0;       lld ans2 = 0;       for (int i = 0; i < n; i++)            ans += sqrt(X[i]*X[i] + Y[i]*Y[i]);          sort(all(Y));       for (int i = 0; i < n; i++)            ans2 += sqrt(X[i]*X[i] + Y[i]*Y[i]);                 lld final_ans = 0;       final_ans = min(ans, ans2);       cout << setprecision(20) << final_ans <<   n ;   }      int main() {        fast;        int t = 1;       //make_seive();       cin >> t;       while (t--)            solve();    }      /*   Tips:   -- for queries involving sum using queue or minimum sum of size k, do also consider prefix sum.    */      /*      Build and running      g++ --std=c++17 -Wall -Wextra -Wshadow -fsanitize=undefined -fsanitize=address FILE.cpp && ./a.out < in          Naming       -for types (class/struct name) UpperCamelCase: Point, Info, SegTree       -functions and variable lowerCamelCase: someMethod, someVariable       -MACROS and constants all capital letters separated by _ : SOME_MACRO, MAX_N, MOD      */


#include <bits/stdc++.h>   using namespace std;   const int inft = 1000000009;   const int MAXN = 1000006;   int n, T[MAXN], A[MAXN], B[MAXN];   int main() {     scanf( %d , &n);     for (int i = 0; i < (n); ++i) scanf( %d , &T[i]);     A[0] = 1;     for (int i = 1; i < n; ++i) A[i] = min(A[i - 1] + 1, T[i]);     B[n - 1] = 1;     for (int i = n - 2; i >= 0; --i) B[i] = min(B[i + 1] + 1, T[i]);     int ret = 0;     for (int i = 0; i < (n); ++i) ret = max(ret, min(A[i], B[i]));     printf( %d n , ret);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long K = 1000000000000000000;   map<int, int> M;   int q, mn, w[600005], nxt[600005], Q[600005], anc[600005], r;   char opt[5], s[600005];   long long ans0, ans, g, ansx, ansy;   int mask((1 << 30) - 1);   int calc(int x) { return w[Q[lower_bound(Q + 1, Q + r + 1, x) - Q]]; }   int main() {     mn = 1 << 30;     scanf( %d , &q);     int j(0);     for (int i = 1; i <= q; ++i) {       scanf( %s%d , opt, &w[i]);       s[i] = (ansy + opt[0] -  a ) % 26 +  a ;       w[i] ^= (ansx & mask);       mn = min(mn, w[i]);       if (i == 1) {         printf( %lld n , ans = w[i]);         ansx = ans & mask;         ansy = w[i] % 26;         while (r && w[Q[r]] >= w[i]) --r;         Q[++r] = i;         continue;       }       while (j && s[j + 1] != s[i]) j = nxt[j];       if (s[j + 1] == s[i]) ++j;       nxt[i] = j;       if (s[i] == s[nxt[i - 1] + 1])         anc[i - 1] = anc[nxt[i - 1]];       else         anc[i - 1] = nxt[i - 1];       for (int j = (s[i - 1] == s[1] ? i - 1 : nxt[i - 1]); j;) {         if (s[j + 1] == s[i])           j = anc[j];         else {           int o(calc(i - j));           g -= o;           map<int, int>::iterator it = M.lower_bound(o);           assert(it != M.end());           --it->second;           if (!it->second) M.erase(it);           j = nxt[j];         }       }       while (r && w[Q[r]] >= w[i]) --r;       Q[++r] = i;       int cnt(s[i] == s[1]);       map<int, int>::iterator it = M.lower_bound(w[i]);       while (it != M.end()) {         g -= (long long)it->first * it->second;         cnt += it->second;         M.erase(it);         it = M.lower_bound(w[i]);       }       g += (long long)cnt * w[i];       M.insert(make_pair(w[i], cnt));       ans += g, ans += mn;       if (ans >= K) ++ans0, ans -= K;       ansx = (ansx + g + mn) & mask;       ansy = (ansy + g + mn) % 26;       if (!ans0)         printf( %lld n , ans);       else {         cout << ans0 << setw(18) << setfill( 0 ) << ans << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long double chance[100005];   int main() {     int n, p;     while (cin >> n >> p) {       memset(chance, 0, sizeof chance);       long double tmp;       for (int i = 0; i < n; i++) {         int a, b;         cin >> a >> b;         int tem = b / p - (a - 1) / p;         tmp = (long double)tem / (b - a + 1);         chance[i] = tmp;       }       long double ans = 0;       for (int i = 1; i < n; i++) {         ans += chance[i] + chance[i - 1] - chance[i] * chance[i - 1];       }       ans += chance[0] + chance[n - 1] - chance[n - 1] * chance[0];       cout << fixed << setprecision(10) << ans * 2000.0 << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 0x3f3f3f3f;   const int _inf = 0xc0c0c0c0;   const long long INF = 0x3f3f3f3f3f3f3f3f;   const long long _INF = 0xc0c0c0c0c0c0c0c0;   const long long mod = (int)1e9 + 7;   const int N = 4e5 + 100;   int n, m;   vector<int> vc[N];   int to[N];   multiset<int> st;   void Ac() {     for (int i = 1, v; i <= n; ++i) {       scanf( %d , &v);       to[v] = i;     }     st.insert(n + 1);     for (int i = 1, u, v; i <= m; ++i) {       scanf( %d%d , &u, &v);       u = to[u];       v = to[v];       if (u > v) swap(u, v);       vc[u].push_back(v);       st.insert(v);     }     long long ans = 0;     for (int i = 1; i <= n; ++i) {       ans += (*st.begin()) - i;       for (int v : vc[i]) {         st.erase(st.lower_bound(v));       }     }     printf( %I64d n , ans);   }   int main() {     while (~scanf( %d%d , &n, &m)) {       Ac();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   map<long long, long long>::iterator itr;   void c_p_c() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);   }   int32_t main() {     c_p_c();     long long t;     cin >> t;     while (t--) {       long long num, k;       cin >> num >> k;       vector<long long> v;       vector<long long> v1;       for (long long i = 0; i < num; i++) {         long long x;         cin >> x;         v.push_back(x);       }       for (long long i = 0; i < num; i++) {         long long x;         cin >> x;         v1.push_back(x);       }       sort(v.begin(), v.end());       sort(v1.begin(), v1.end(), greater<long long>());       long long sum = 0;       for (long long i = 0; i < k; i++) {         if (v1[i] > v[i])           sum += v1[i];         else           sum += v[i];       }       for (long long i = k; i < num; i++) {         sum += v[i];       }       cout << sum << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = 1e9 + 7;   const int N = 3e5 + 10;   vector<pair<int, int>> vp[N];   vector<int> v[N];   int pos[N];   int deg[N];   int vis[N];   vector<int> ans;   void dfs(int x, int p = 0, int o = 0) {     if (vis[x]) return;     v[p].push_back(x);     vis[x] = 1;     pos[x] = o;     for (auto &pp : vp[x]) {       int y, oo;       tie(y, oo) = pp;       dfs(y, x, oo);     }   }   int solve(int x) {     int cur = deg[x];     for (auto &y : v[x]) {       cur ^= solve(y);     }     if (cur) ans.push_back(pos[x]);     return cur;   }   int main() {     int n, m;     cin >> n >> m;     int cnt1 = 0, cnt_1 = 0;     for (int i = 1; i <= n; i++) {       cin >> deg[i];       if (deg[i] == 1) cnt1 ^= 1;       if (deg[i] == -1) cnt_1++;     }     if (cnt1 == 1 && cnt_1 == 0) {       puts( -1 );       return 0;     }     for (int i = 1; i <= n; i++) {       if (deg[i] == -1) {         deg[i] = cnt1;         cnt1 = 0;       }     }     for (int i = 1; i <= m; i++) {       int x, y;       cin >> x >> y;       vp[x].push_back({y, i});       vp[y].push_back({x, i});     }     dfs(1);     solve(1);     printf( %d n , ans.size());     for (auto &x : ans) printf( %d n , x);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string pal, pal2;     int x = 0;     bool b1 = false;     cin >> pal;     for (int i = 0; i < pal.size(); i++) {       if (pal[i] ==  W  and pal[i + 1] ==  U  and pal[i + 2] ==  B ) {         i += 2;         if (b1 == true) {           pal2 +=    ;           b1 = false;         }       } else {         b1 = true;         pal2 += pal[i];       }     }     cout << pal2;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline int read() {     int x = 0, f = 1;     char c = getchar();     while (c <  0  || c >  9 ) {       if (c ==  - ) f = -1;       c = getchar();     }     while (c >=  0  && c <=  9 )       x = (x << 3) + (x << 1) + (c ^  0 ), c = getchar();     return x * f;   }   const int N = 2e5 + 5;   int d, n, m;   struct node {     int x, p;   } a[N];   inline int operator<(const node x, const node y) {     if (x.p == y.p) return x.x > y.x;     return x.p > y.p;   }   inline int cmp(node x, node y) { return x.x < y.x; }   priority_queue<node> q;   long long ans;   int main() {     d = read(), n = read(), m = read();     for (int i = 1; i <= m; i++) a[i] = {read(), read()};     sort(a + 1, a + m + 1, cmp);     int t = n, j = 1;     while (t < d) {       while (j <= m && a[j].x <= t) q.push(a[j++]);       while (!q.empty() && q.top().x + n <= t) q.pop();       if (q.empty()) return puts( -1 ), 0;       int x = q.top().x, p = q.top().p;       int nxt = min(d, x + n);       if (j <= m && nxt >= a[j].x) nxt = a[j].x;       ans += 1ll * p * (nxt - t);       t = nxt;     }     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long nMod = 1e9 + 7;   inline long long GCD(long long a, long long b) {     while (b != 0) {       long long c = a % b;       a = b;       b = c;     }     return a;   };   inline long long LCM(long long a, long long b) { return (a / GCD(a, b)) * b; };   void vietnakid() {     int TC;     cin >> TC;     while (TC--) {       int n;       string s;       cin >> n;       cin >> s;       int fm = n, lr = 0;       for (int i = 0; i < n; i++) {         if (s[i] ==  > ) {           fm = min(fm, i);         } else {           lr = max(lr, i);         }       }       cout << min(fm, n - lr - 1) <<   n ;     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie();     vietnakid();     cerr <<   nTime elapsed:   << 1000 * clock() / CLOCKS_PER_SEC <<  ms n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct node {     long long int word, prefix;     node *child[2];     node() {       word = prefix = 0;       child[0] = child[1] = NULL;     }   };   void insert(node *root, long long int x, long long int bit) {     root->prefix += 1;     if (bit < 0) {       root->word += 1;       return;     }     bool b = (x & (1 << bit));     if (root->child[b] == NULL) {       root->child[b] = new node();     }     insert(root->child[b], x, bit - 1);   }   node *deleteit(node *root, long long int x, long long int bit) {     if (root == NULL) {       return NULL;     }     root->prefix -= 1;     if (bit < 0) {       root->word -= 1;       if (root->word == 0 && root->prefix == 0) {         delete root;         return NULL;       }       return root;     }     bool b = (x & (1 << bit));     root->child[b] = deleteit(root->child[b], x, bit - 1);     if (root->word == 0 && root->prefix == 0) {       delete root;       return NULL;     }     return root;   }   long long int query(node *root, long long int x, long long int k,                       long long int bit, long long int ans) {     if (bit < 0 || root == NULL) {       return ans;     }     bool a = (x & (1 << bit)), a_complement = (!a);     bool b = (k & (1 << bit)), b_complement = (!b);     if (b == true) {       if (root->child[a] != NULL) {         ans += root->child[a]->prefix;       }       return query(root->child[a_complement], x, k, bit - 1, ans);     } else {       return query(root->child[a], x, k, bit - 1, ans);     }     return ans;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     node *root = new node;     long long int q, x, y, t;     cin >> q;     for (long long int i = 0; i < q; i++) {       cin >> t >> x;       if (t == 1) {         insert(root, x, 31);       } else if (t == 2) {         root = deleteit(root, x, 31);         if (root == NULL) {           root = new node;         }       } else {         cin >> y;         cout << query(root, x, y, 31, 0) <<   n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int a, b, n;     cin >> a >> b >> n;     bool exist(false);     for (int i = 0; i < 10; i++) {       if ((a * 10 + i) % b == 0) {         cout << a * 10 + i;         string s(n - 1,  0 );         cout << s << endl;         exist = true;         break;       }     }     if (!exist) cout <<  -1  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool vis[100010];   int pr[100010], e;   void Shai() {     vis[1] = true;     for (long long i = 2; i <= 1000ll; i++) {       if (!vis[i]) {         pr[++e] = i;         for (long long j = i * i; j <= 1000ll; j += i) {           vis[j] = true;         }       }     }   }   int n, cnta[100010];   int main() {     Shai();     int x, y;     scanf( %d , &n);     for (int i = 1; i <= n; ++i) {       scanf( %d%d , &x, &y);       int X = x;       for (int j = 1; j <= e; ++j) {         if (X % pr[j] == 0) {           while (X % pr[j] == 0) {             X /= pr[j];             ++cnta[j];           }         }       }       bool lose = 0;       for (int j = 1; j <= e; ++j) {         int cntb = 0;         if (y % pr[j] == 0) {           while (y % pr[j] == 0) {             y /= pr[j];             ++cntb;           }         }         if ((cnta[j] + cntb) % 3 != 0) {           lose = 1;           break;         } else if (min(cnta[j], cntb) * 2 < max(cnta[j], cntb)) {           lose = 1;           break;         }       }       if (!(X == 1 && y == 1) && !((long long)min(X, y) * (long long)min(X, y) ==                                    (long long)max(X, y))) {         lose = 1;       }       for (int j = 1; j <= e; ++j) {         cnta[j] = 0;       }       if (!lose)         puts( Yes );       else         puts( No );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   ifstream in( test.in );   ofstream out( test.out );   const int DIM = 2e3 + 1;   const int INF = 1e9 + 7;   int dp[DIM];   set<int> mst;   deque<int> que;   vector<int> edg[DIM];   int main() {     ios::sync_with_stdio(false);     cin.tie();     cout.tie();     int k, n;     cin >> k >> n;     for (int i = 1; i <= n; i++) {       int x;       cin >> x;       mst.insert(x - k);     }     for (int x : mst) {       for (int i = 0; i < DIM; i++) {         if (i + x > -1 && i + x < DIM) edg[i].push_back(i + x);       }     }     fill(dp, dp + DIM, INF);     dp[DIM / 2] = 0;     que.push_back(DIM / 2);     int ans = INF;     for (; que.empty() == false; que.pop_front()) {       int x = que.front();       for (int y : edg[x]) {         if (dp[y] == INF)           dp[y] = dp[x] + 1, que.push_back(y);         else if (y == DIM / 2)           ans = min(ans, dp[x] + 1);       }     }     cout << (ans == INF ? -1 : ans) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   const int N = 1e6 + 4;   bool isPrime(int n) {     if (n <= 1) return false;     if (n <= 3) return true;     if (n % 2 == 0 || n % 3 == 0) return false;     for (int i = 5; i * i <= n; i = i + 6)       if (n % i == 0 || n % (i + 2) == 0) return false;     return true;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long test = 1;     cin >> test;     for (int qw = 1; qw <= test; qw++) {       int n;       cin >> n;       int a[n];       for (int i = 0; i < n; i++) cin >> a[i];       int sum = 0;       for (int i = 0; i < n; i++) sum += a[i];       if (!isPrime(sum)) {         cout << n << endl;         for (int i = 1; i <= n; i++) cout << i <<    ;         cout << endl;       } else {         int flag = 0;         for (int i = 0; i < n; i++) {           if (!isPrime(sum - a[i])) {             cout << n - 1 << endl;             flag = 1;             for (int j = 0; j < n; j++) {               if (i != j) cout << j + 1 <<    ;             }             cout << endl;           }           if (flag == 1) break;         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }   long long a, b, x, y;   long long best, ansp, ansq;   int main() {     while (cin >> a >> b >> x >> y) {       long long gg = gcd(x, y);       x /= gg;       y /= gg;       best = -1;       long long maxr = min(a / x, b / y);       if (maxr <= 0)         cout << 0 <<     << 0 << endl;       else         cout << x * maxr <<     << y * maxr << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   const int maxn = 2e5 + 10;   int n, k;   long long fac[maxn + 10], afac[maxn + 10];   long long qpow(long long a, long long b) {     long long ret = 1LL;     while (b) {       if (b & 1) ret = ret * a % mod;       a = a * a % mod;       b >>= 1;     }     return ret;   }   long long inv(long long x) { return qpow(x, mod - 2); }   void Pre() {     fac[0] = 1LL;     for (int i = 1; i <= maxn; i++) fac[i] = fac[i - 1] * (long long)i % mod;     afac[maxn] = inv(fac[maxn]);     for (int i = maxn; i >= 1; --i) afac[i - 1] = afac[i] * i % mod;   }   long long C(long long n, long long m) {     if (m > n) return 0;     return fac[n] * afac[n - m] % mod * afac[m] % mod;   }   void solve() {     vector<pair<int, int> > h;     int l, r;     for (int i = 1; i <= n; i++) {       scanf( %d %d , &l, &r);       h.push_back(make_pair(l - 1, 1));       h.push_back(make_pair(r, -1));     }     sort(h.begin(), h.end());     long long cnt = 0LL, ans = 0LL;     int pos = h[0].first;     for (int i = 0; i < h.size(); i++) {       long long tmp = C(cnt, k) * (h[i].first - pos) % mod;       ans = (ans + tmp) % mod;       cnt += 1LL * h[i].second;       pos = h[i].first;     }     printf( %I64d n , ans);   }   int main() {     Pre();     while (scanf( %d %d , &n, &k) != EOF) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 100005;   const int INF = 0x3f3f3f3f;   char tmp[20][20];   char raw[MAXN];   long long n, m, T, k;   bool check(int l, int r) {     for (int i = 1; i <= n; i++) {       if (r - l + 1 < strlen(tmp[i]))         continue;       else {         int cur_len = strlen(tmp[i]);         bool flg = true;         for (int j = 0; j < cur_len; j++) {           if (tmp[i][cur_len - j - 1] == raw[r - j])             continue;           else {             flg = false;             continue;           }         }         if (flg) return false;       }     }     return true;   }   int main() {     scanf( %s , raw);     int l = 0, r = 0, res_len = 0, res_pos = 0;     scanf( %I64d  , &n);     for (int i = 1; i <= n; i++) scanf( %s , tmp[i]);     while (r < strlen(raw)) {       while (l <= r) {         if (check(l, r)) {           if (r - l + 1 > res_len) {             res_len = r - l + 1;             res_pos = l;           }           break;         }         l++;       }       r++;     }     cout << res_len <<     << res_pos << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   bool flag[21][21];   int deg[21], id[21];   vector<int> G[21];   inline int cmp(int x, int y) {     return deg[x] != deg[y] ? deg[x] < deg[y] : x < y;   }   bool vis[21];   inline void dfs(int np) {     vis[np] = 1;     for (int &x : G[np]) {       if (!vis[x]) {         dfs(x);         return;       }     }   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1, ti, tj; i <= m; i++) {       scanf( %d%d , &ti, &tj);       if (ti != tj) flag[ti][tj] = flag[tj][ti] = 1;     }     for (int i = 1; i <= n; i++) {       id[i] = i;       for (int j = 1; j <= n; j++) {         if (flag[i][j]) deg[i]++, G[i].push_back(j);       }     }     for (int i = 1; i <= n; i++) sort(G[i].begin(), G[i].end(), cmp);     for (int i = 1; i <= n; i++) {       memset(vis, 0, sizeof(vis));       dfs(i);       int cnt = 0;       for (int j = 1; j <= n; j++) cnt += vis[j];       if (cnt == n) {         puts( Yes );         return 0;       }     }     puts( No );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 300300;   int a[maxn];   set<int> st;   int MIN(int x, int y) { return x < y ? x : y; }   int MAX(int x, int y) { return x > y ? x : y; }   int main(void) {     st.clear();     int n, i, j, mi, mx, fg = 0, x;     scanf( %d , &n);     for (i = 1; i <= n - 1; i++) {       scanf( %d , &a[i]);       if (i == 1) {         mx = mi = a[i];       } else {         a[i] = a[i] + a[i - 1];         mx = MAX(mx, a[i]);         mi = MIN(mi, a[i]);       }       if (!st.count(a[i])) {         st.insert(a[i]);       } else         fg = 1;       if (a[i] == 0) fg = 1;     }     if (fg) {       printf( -1 n );       return 0;     }     for (i = 1; i <= n; i++)       if (i + mx >= 1 && i + mx <= n && i + mi >= 1 && i + mi <= n) {         fg = 1;         x = i;         break;       }     if (fg == 0) {       printf( -1 n );     } else {       printf( %d , x);       for (i = 1; i <= n - 1; i++) {         printf(  %d , x + a[i]);       }       printf(  n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = (int)1e8;   const int N = 500;   int n;   int ans;   int a[N];   set<int> p;   int m;   int b[N][2];   struct Edge {     int to, cap, flow;     Edge() : to(), cap(), flow() {}     Edge(int _to, int _cap) : to(_to), cap(_cap), flow(0) {}   };   int sz;   Edge ed[2 * N];   vector<int> g[N];   int S, T;   void fact(int x) {     for (int i = 2; i * i <= x; i++) {       if (x % i != 0) continue;       p.insert(i);       while (x % i == 0) x /= i;     }     if (x != 1) p.insert(x);     return;   }   void addEdge(int v, int to, int cap) {     ed[sz] = Edge(to, cap);     g[v].push_back(sz++);     ed[sz] = Edge(v, 0);     g[to].push_back(sz++);     return;   }   int q[N];   int qSz;   int d[N];   bool bfs(int S, int T, int n) {     for (int i = 0; i < n; i++) d[i] = INF;     d[S] = 0;     qSz = 1;     q[0] = S;     for (int k = 0; k < qSz; k++) {       int v = q[k];       for (int i = 0; i < (int)g[v].size(); i++) {         Edge e = ed[g[v][i]];         if (e.flow == e.cap) continue;         int to = e.to;         if (d[to] <= d[v] + 1) continue;         d[to] = d[v] + 1;         q[qSz++] = to;       }     }     return (d[T] < INF);   }   int idx[N];   int dfs(int v, int T, int pushFlow) {     int res = 0;     if (v == T || pushFlow == 0) return pushFlow;     for (; idx[v] < (int)g[v].size(); idx[v]++) {       int id = g[v][idx[v]];       Edge e = ed[id];       int to = e.to;       if (d[to] != d[v] + 1) continue;       int deltaFlow = dfs(to, T, min(pushFlow, e.cap - e.flow));       pushFlow -= deltaFlow;       res += deltaFlow;       ed[id].flow += deltaFlow;       ed[id ^ 1].flow -= deltaFlow;       if (pushFlow == 0) break;     }     return res;   }   int flow(int S, int T, int n) {     int res = 0;     while (bfs(S, T, n)) {       for (int i = 0; i < n; i++) idx[i] = 0;       res += dfs(S, T, INF);     }     return res;   }   int solve(int q) {     for (int i = 0; i < n + 2; i++) g[i].clear();     sz = 0;     for (int i = 0; i < n; i++) {       int c = 0;       int t = a[i];       while (t % q == 0) {         t /= q;         c++;       }       if (i % 2 == 0)         addEdge(S, i, c);       else         addEdge(i, T, c);     }     for (int i = 0; i < m; i++) addEdge(b[i][0], b[i][1], INF);     return flow(S, T, n + 2);   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 0; i < n; i++) scanf( %d , &a[i]);     for (int i = 0; i < n; i++) fact(a[i]);     for (int i = 0; i < m; i++)       for (int j = 0; j < 2; j++) {         scanf( %d , &b[i][j]);         b[i][j]--;       }     for (int i = 0; i < m; i++) {       if (b[i][0] % 2 == 1) swap(b[i][0], b[i][1]);     }     S = n;     T = n + 1;     for (auto it = p.begin(); it != p.end(); it++) ans += solve(*it);     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int p[200007];   int c1[200007];   int c2[200007];   bool used[200007];   int main() {     int n;     cin >> n;     for (int i = 0; i < n; ++i) {       scanf( %d , &p[i]);     }     for (int i = 0; i < n; ++i) {       scanf( %d , &c1[i]);       c1[i]--;     }     for (int i = 0; i < n; ++i) {       scanf( %d , &c2[i]);       c2[i]--;     }     priority_queue<pair<int, int>> q[3];     for (int i = 0; i < n; ++i) {       if (c1[i] == c2[i]) {         q[c1[i]].push(make_pair(-p[i], i));       } else {         q[c1[i]].push(make_pair(-p[i], i));         q[c2[i]].push(make_pair(-p[i], i));       }     }     int m, x;     cin >> m;     for (int i = 0; i < m; ++i) {       scanf( %d , &x);       x--;       while (!q[x].empty() && used[q[x].top().second]) q[x].pop();       if (q[x].empty())         printf( -1  );       else {         printf( %d  , -q[x].top().first);         used[q[x].top().second] = 1;         q[x].pop();       }     }   }


#include <bits/stdc++.h>   using namespace std;   long long dp[64][64][64][64];   double fact[64];   int main() {     int n, a[64], p, s = 0;     cin >> n;     for (int i = 0; i < n; ++i) {       cin >> a[i];       s += a[i];     }     cin >> p;     if (s <= p) {       printf( %.9f n , (double)n);       return 0;     }     fact[0] = 1;     for (int i = 1; i < 64; ++i) {       fact[i] = fact[i - 1] * i;     }     for (int ignore = 0; ignore < n; ++ignore) {       dp[ignore][0][0][0] = 1;       for (int i = 0; i < n; ++i) {         for (int j = 0; j <= i; ++j) {           for (int k = 0; k <= p; ++k) {             if (i != ignore && k + a[i] <= p) {               dp[ignore][i + 1][j + 1][k + a[i]] += dp[ignore][i][j][k];             }             dp[ignore][i + 1][j][k] += dp[ignore][i][j][k];           }         }       }     }     double res = 0;     for (int cnt = 1; cnt < n; ++cnt) {       long long pats = 0;       for (int last = 0; last < n; ++last) {         for (int w = max(0, p - a[last] + 1); w <= p; ++w) {           pats += dp[last][n][cnt][w];         }       }       res += cnt * (double)pats * fact[cnt] * fact[n - cnt - 1] / fact[n];     }     printf( %.9f n , res);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     cin.sync_with_stdio(false);     long long int n;     cin >> n;     vector<long long int> a(n), start(n), end(n);     for (long long int i = 0; i < n; i++) {       cin >> a[i];       start[i] = i;       end[i] = i + 1;     }     for (long long int i = 0; i < n; i++) {       while (start[i] > 0 && (a[i] | a[start[i] - 1]) == a[i]) {         start[i] = start[start[i] - 1];       }     }     for (long long int i = n - 1; i >= 0; i--) {       while (end[i] < n && (a[i] | a[end[i]]) == a[i]) {         end[i] = end[end[i]];       }     }     map<long long int, long long int> last;     long long int good = (n * (n - 1)) / 2;     for (long long int i = 0; i < n; i++) {       if (last.count(a[i]) && last[a[i]] >= start[i]) {         good -= (i - last[a[i]]) * (end[i] - i) - 1;         last[a[i]] = i;         continue;       }       last[a[i]] = i;       good -= (i - start[i] + 1) * (end[i] - i) - 1;     }     cout << good << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int T, a, b, c, d, k;   int main() {     cin >> T;     for (; T--;) {       cin >> a >> b >> c >> d >> k;       int sol1 = 0;       int sol2 = 0;       if (a % c == 0)         sol1 = a / c;       else         sol1 = a / c + 1;       if (b % d == 0)         sol2 = b / d;       else         sol2 = b / d + 1;       if (sol1 + sol2 <= k)         cout << sol1 <<     << sol2 <<   n ;       else         cout << -1 <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1005;   const int mod1 = 998244353;   const int mod2 = 1e9 + 7;   const int b1 = 337;   const int b2 = 421;   const int inf = 2147483647;   struct Pair {     int x[2] = {};     bool operator<(const Pair a) const {       return x[0] < a.x[0] || x[0] == a.x[0] && x[1] < a.x[1];     }   };   struct BitSet {     unsigned long long b[16] = {};     inline void reset() { memset(b, 0, sizeof(b)); }     inline void set(int x) { b[x / 64] |= (1ull << (x % 64)); }     inline void operator^=(const BitSet &a) {       for (int i = 0; i < 16; ++i) b[i] ^= a.b[i];     }     inline Pair getHashVal() {       Pair ans;       for (int i = 0; i < 16; ++i) {         ans.x[0] = (1ll * ans.x[0] * b1 % mod1 + b[i] % mod1) % mod1;         ans.x[1] = (1ll * ans.x[1] * b2 % mod2 + b[i] % mod2) % mod2;       }       return ans;     }   };   int n, s, d;   BitSet bs[31], sta[1 << 20], cur;   int cnt[1 << 20], m;   map<Pair, int> mp;   void init() {     m = min(s, 20);     for (int i = 0; i < m; ++i) {       cnt[1 << i] = 1;       sta[1 << i] = bs[i];     }     for (int i = 0; i < (1 << m); ++i) {       if (i != (i & -i)) {         cnt[i] = cnt[i - (i & -i)] + 1;         sta[i] = sta[i - (i & -i)];         sta[i] ^= sta[i & -i];       }       Pair x = sta[i].getHashVal();       if (!mp.count(x) || mp[x] > cnt[i]) {         mp[x] = cnt[i];       }     }     for (int i = 0; i < (s - m); ++i) {       sta[1 << i] = bs[i + m];     }     for (int i = 1; i < (1 << (s - m)); ++i) {       if (i == (i & -i)) continue;       sta[i] = sta[i - (i & -i)];       sta[i] ^= sta[i & -i];     }   }   int getans() {     BitSet now;     int ans = inf;     for (int i = 0; i < (1 << (s - m)); ++i) {       if (cnt[i] >= ans) continue;       now = cur, now ^= sta[i];       Pair x = now.getHashVal();       if (mp.count(x) && mp[x] + cnt[i] < ans) {         ans = mp[x] + cnt[i];       }     }     return ans == inf ? -1 : ans;   }   int main() {     scanf( %d%d%d , &n, &s, &d);     for (int i = 0; i < s; ++i) {       int c;       scanf( %d , &c);       for (int j = 0; j < c; ++j) {         int u;         scanf( %d , &u);         u--;         bs[i].set(u);       }     }     init();     vector<int> ans;     for (int i = 0; i < d; ++i) {       int t;       scanf( %d , &t);       cur.reset();       while (t--) {         int u;         scanf( %d , &u);         u--;         cur.set(u);       }       ans.push_back(getans());     }     for (int i = 0; i < ans.size(); ++i) printf( %d n , ans[i]);     puts(  );   }


#include <bits/stdc++.h>   using namespace std;   const int N = 400010;   const int P = 10000007;   int m, n;   char str[N];   char ans[N];   int l[N], r[N];   int p[N];   bool ok(int i, int m) {     if (++i < m) return 0;     return (r[i] - r[i - m]) == ((l[i] - l[i - m] * p[m]) * p[i - m]);   }   int dfs(int i, int ismax) {     if (i == n) {       puts(ans);       return 1;     }     for (ans[i] = ismax ? str[i] :  a ; ans[i] <=  z ; ans[i]++) {       l[i + 1] = l[i] * P + ans[i];       r[i + 1] = r[i] + ans[i] * p[i];       if (!ok(i, m) && !ok(i, m + 1) && dfs(i + 1, ans[i] == str[i] && ismax))         return 1;     }     return 0;   }   int main() {     scanf( %d%s , &m, str);     n = strlen(str);     int i = n - 1;     for (; i >= 0 && str[i] ==  z ; i--) str[i] =  a ;     if (i < 0) {       puts( Impossible );       return 0;     }     str[i]++;     p[0] = 1;     for (int i = 1; i <= n; i++) p[i] = p[i - 1] * P;     if (!dfs(0, 1)) puts( Impossible );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, i, out = 0;     cin >> n;     for (i = 1; i <= n; i++) {       out += pow(2, i);     }     cout << out;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   enum STATE { IN, OUT, BOUNDRY };   const double PI = acos(-1.0);   void fast_in_out() {     std::ios_base::sync_with_stdio(NULL);     cin.tie(NULL);     cout.tie(NULL);   }   int dx[] = {0, 0, -1, 1, -1, 1, -1, 1, 0};   int dy[] = {-1, 1, 0, 0, -1, -1, 1, 1, 0};   int lx[] = {2, 2, -1, 1, -2, -2, -1, 1};   int ly[] = {-1, 1, 2, 2, 1, -1, -2, -2};   const int N = 19, M = 200 + 10, mod = 998244353;   const double eps = 1e-9;   long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   int n;   double ar[N][N];   double dp[N][(1 << N)];   int main() {     fast_in_out();     cout << fixed << setprecision(9);     cin >> n;     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) cin >> ar[i][j];       dp[i][1 << i] = 1;     }     for (int mask = 3; mask < (1 << n); mask++) {       int cnt = __builtin_popcount(mask);       if (cnt == 1) continue;       cnt = cnt * (cnt - 1) / 2;       double lose[N]{0};       for (int i = 0; i < n; i++) {         for (int j = i + 1; j < n && (mask & (1 << i)); j++) {           if (mask & (1 << j)) {             lose[j] += ar[i][j] / cnt;             lose[i] += ar[j][i] / cnt;           }         }       }       for (int i = 0; i < n; i++) {         for (int j = i + 1; j < n && (mask & (1 << i)); j++) {           if (mask & (1 << j)) {             dp[j][mask] += dp[j][mask - (1 << i)] * lose[i];             dp[i][mask] += dp[i][mask - (1 << j)] * lose[j];           }         }       }     }     for (int i = 0; i < n; i++) cout << dp[i][(1 << n) - 1] <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct __timestamper {};   vector<vector<int>> g;   vector<vector<int>> id;   vector<int> used;   vector<int> ts;   void dfs(int v, int x) {     if (used[v]) return;     used[v] = 1;     for (int i = 0; i < (int)g[v].size(); i++) {       if (id[v][i] < x) {         dfs(g[v][i], x);       }     }     ts.push_back(v);   }   bool check(int x) {     ts.clear();     used = vector<int>(g.size());     for (int i = 0; i < (int)g.size(); i++) {       dfs(i, x);     }     reverse(ts.begin(), ts.end());     for (int i = 0; i + 1 < (int)ts.size(); i++) {       int v = ts[i];       bool ok = false;       for (int j = 0; j < (int)g[v].size(); j++)         if (g[v][j] == ts[i + 1] && id[v][j] < x) {           ok = true;         }       if (!ok) return false;     }     return true;   }   int main() {     int n, m;     scanf( %d%d , &n, &m);     g = vector<vector<int>>(n);     id = vector<vector<int>>(n);     for (int i = 0; i < m; i++) {       int a, b;       scanf( %d%d , &a, &b);       --a, --b;       g[a].push_back(b);       id[a].push_back(i);     }     if (!check(m)) {       printf( -1 n );       return 0;     }     int l = 0;     int r = m;     while (r - l > 1) {       int mid = (l + r) / 2;       if (check(mid))         r = mid;       else         l = mid;     }     printf( %d n , r);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 5;   char str1[maxn], str2[maxn];   int a[maxn], len1, len2;   bool book[maxn];   bool judge(int x) {     for (int i = 1; i <= x; i++) book[a[i] - 1] = 1;     int j = 0, cnt = 0;     for (int i = 0; i < len2; i++) {       for (; j < len1; j++) {         if (str2[i] == str1[j] && !book[j]) {           j++;           cnt++;           break;         }       }     }     return cnt == len2;   }   int main(void) {     while (~scanf(  %s %s , str1, str2)) {       len1 = strlen(str1);       len2 = strlen(str2);       for (int i = 1; i <= len1; i++) scanf( %d , &a[i]);       int l = 0, r = len1, ans;       while (l <= r) {         memset(book, 0, sizeof(book));         int mid = (l + r) / 2;         if (judge(mid))           l = mid + 1, ans = mid;         else           r = mid - 1;       }       printf( %d n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int q;     scanf( %d , &q);     while (q--) {       int l, r, d;       scanf( %d %d %d , &l, &r, &d);       if (d < l)         printf( %d n , d);       else if (d > r)         printf( %d n , d);       else {         int res = r - d;         res = res % d;         printf( %d n , r + d - res);       }     }   }


#include <bits/stdc++.h>   using namespace std;   map<int, int> mp;   int main() {     int n;     scanf( %d , &n);     for (int i = 0; i < n; i++) {       int a;       scanf( %d , &a);       mp[a]++;     }     int res = n;     while (!mp.empty()) {       for (auto itr = mp.begin(); itr != mp.end();) {         if (--itr->second == 0)           mp.erase(itr++);         else           itr++;       }       res--;     }     printf( %d n , res);     return 0;   }