#include <bits/stdc++.h>   using namespace std;   const int OO = 1e9;   const double EPS = 1e-9;   template <class T>   void _db(const char* dbStr, T e) {     cout << dbStr <<   =   << e << endl;   }   template <class T, class... L>   void _db(const char* dbStr, T e, L... r) {     while (*dbStr !=  , ) cout << *dbStr++;     cout <<   =   << e <<  , ;     _db(dbStr + 1, r...);   }   template <class S, class T>   ostream& operator<<(ostream& o, const map<S, T>& v) {     o <<  [ ;     int i = 0;     for (const pair<S, T>& pr : v)       o << (!i++ ?    :  ,  ) <<  {  << pr.first <<   :   << pr.second <<  } ;     return o <<  ] ;   }   template <template <class, class...> class S, class T, class... L>   ostream& operator<<(ostream& o, const S<T, L...>& v) {     o <<  [ ;     int i = 0;     for (const auto& e : v) o << (!i++ ?    :  ,  ) << e;     return o <<  ] ;   }   template <class S, class T>   ostream& operator<<(ostream& o, const pair<S, T>& pr) {     return o <<  (  << pr.first <<  ,   << pr.second <<  ) ;   }   ostream& operator<<(ostream& o, const string& s) {     for (const char& c : s) o << c;     return o;   }   template <class T>   using V = vector<T>;   template <class T>   using VV = V<V<T>>;   template <class T>   using VVV = VV<V<T>>;   using ll = long long;   using pii = pair<int, int>;   using vi = V<int>;   using vii = V<pii>;   using vvi = VV<int>;   using mii = map<int, int>;   using umii = unordered_map<int, int>;   using si = set<int>;   using usi = unordered_set<int>;   vii monoStFunc(vi a) {     int n = int(a.size());     vii b(n);     stack<pii> st;     st.push(make_pair(INT_MAX, -1));     for (int i = 0; i < n; ++i) {       while (st.top().first < a[i]) st.pop();       b[i].first = st.top().second;       st.push(make_pair(a[i], i));     }     while (!st.empty()) st.pop();     st.push(make_pair(INT_MAX, n));     for (int i = n - 1; i >= 0; --i) {       while (st.top().first <= a[i]) st.pop();       b[i].second = st.top().second;       st.push(make_pair(a[i], i));     }     return b;   }   int n, q;   vi a, d;   int main() {     ios::sync_with_stdio(false);     cout.precision(10);     cin.tie(0);     cin >> n >> q;     a.assign(n, 0);     for (int i = 0; i < n; ++i) cin >> a[i];     d.assign(n - 1, 0);     for (int i = 0; i < n - 1; ++i) d[i] = abs(a[i + 1] - a[i]);     true;     for (int qq = 0; qq < q; ++qq) {       int l, r;       cin >> l >> r;       --l, --r;       vi v;       for (int i = l; i < r; ++i) v.push_back(d[i]);       vii LR = monoStFunc(v);       ll ans = 0;       for (int i = 0; i < int(v.size()); ++i)         ans += v[i] * 1LL * ((i - LR[i].first) * 1LL * (LR[i].second - i));       cout << ans <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int gi() {     char cc = getchar();     int cn = 0, flus = 1;     while (cc <  0  || cc >  9 ) {       if (cc ==  - ) flus = -flus;       cc = getchar();     }     while (cc >=  0  && cc <=  9 ) cn = cn * 10 + cc -  0 , cc = getchar();     return cn * flus;   }   const int N = 3e5 + 5;   int n, q, a[N], g[20], f[N][20];   signed main() {     n = gi(), q = gi();     for (register int i = (1); i <= (n); ++i) a[i] = gi();     for (register int i = (0); i <= (19); ++i) g[i] = n + 1;     memset(f, 63, sizeof(f));     for (register int i = n; i >= 1; --i) {       for (register int j = (0); j <= (19); ++j)         if ((1 << j) & a[i]) f[i][j] = i;       for (register int j = (0); j <= (19); ++j)         if ((1 << j) & a[i])           for (register int k = (0); k <= (19); ++k)             f[i][k] = min(f[i][k], f[g[j]][k]);       for (register int j = (0); j <= (19); ++j)         if ((1 << j) & a[i]) g[j] = i;     }     while (q--) {       int x = gi(), y = gi();       int flag = 0;       for (register int j = (0); j <= (19); ++j)         if ((1 << j) & a[y]) flag |= (f[x][j] <= y);       (flag) ? puts( Shi ) : puts( Fou );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 2147483647;   const long long LLINF = 9223372036854775807;   int main() {     int n;     cin >> n;     long long mod = 1000000009;     if (n == 2) cout << 10, exit(0);     long long b = 5, g = 1, r = 6;     long long fb = 2, fg = 2, t = 4;     for (int i = 0; i < n / 2 - 2; ++i) {       b = r + 3 * g * (t + 1);       g = (g * (1 + t)) % mod;       r = (b + g) % mod;       fb = (t + fg * 2) % mod;       fg = (fg * 2) % mod;       t = (fg + fb) % mod;     }     long long ans = ((r * r + 1) * 2) % mod;     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = int(500 * 1000 + 7);   long long n, k;   vector<pair<long long, long long> > adj[N];   long long dp[N][2];   void dfs(int v, int p = -1) {     vector<long long> x;     long long curr = 0;     for (auto it : adj[v]) {       long long to = it.first;       long long w = it.second;       if (to == p) continue;       dfs(to, v);       curr += dp[to][0];       x.push_back(dp[to][1] + w - dp[to][0]);     }     sort(x.begin(), x.end(), greater<long long>());     for (long long i = 0; i < min((long long)x.size(), k); i++) {       if (x[i] > 0) curr += x[i];     }     dp[v][0] = dp[v][1] = curr;     if (k <= (long long)x.size() && x[k - 1] > 0) dp[v][1] -= x[k - 1];   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long q;     cin >> q;     while (q--) {       cin >> n >> k;       for (long long i = 0; i < n; i++) adj[i].clear();       for (long long i = 0; i < n - 1; i++) {         long long u, v, w;         cin >> u >> v >> w;         u--;         v--;         adj[u].push_back({v, w});         adj[v].push_back({u, w});       }       dfs(0, -1);       cout << dp[0][0] << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1010;   struct Point {     double x, y;     Point(double _ = 0, double __ = 0) { x = _, y = __; }     bool operator<(const Point &_) const {       if (fabs(x - _.x) > 1e-10) return x < _.x;       return y < _.y;     }   } po[N], rec[N * 2], stk[N * 2];   struct Line {     Point a, b;   } L;   struct Mem {     Point a;     int type;     bool operator<(const Mem &_) const {       if (fabs(a.x - _.a.x) > 1e-10) return a.x < _.a.x;       if (fabs(a.y - _.a.y) > 1e-10) return a.y < _.a.y;       return type < _.type;     }   } pp[N * 2];   int n, m;   inline double xmul(Point a, Point b, Point c) {     return (a.x - b.x) * (a.y - c.y) - (a.y - b.y) * (a.x - c.x);   }   inline bool across(Point &a, Point &b, Point &c, Point &d) {     double p1 = xmul(a, b, c), p2 = xmul(a, b, d);     if (fabs(p1) < 1e-10 || fabs(p2) < 1e-10) return 1;     if (p1 * p2 < 1e-10) return 1;     return 0;   }   inline bool oneline(Point &a, Point &b, Point &c, Point &d) {     double p1 = xmul(a, b, c), p2 = xmul(a, b, d);     if (fabs(p1) < 1e-10 && fabs(p2) < 1e-10) return 1;     return 0;   }   inline Point intersection(Line &u, Line &v) {     Point ret = u.a;     double t =         ((u.a.x - v.a.x) * (v.a.y - v.b.y) - (u.a.y - v.a.y) * (v.a.x - v.b.x)) /         ((u.a.x - u.b.x) * (v.a.y - v.b.y) - (u.a.y - u.b.y) * (v.a.x - v.b.x));     ret.x += (u.b.x - u.a.x) * t;     ret.y += (u.b.y - u.a.y) * t;     return ret;   }   inline double dis(Point &a, Point &b) {     return sqrt(((a.x - b.x) * (a.x - b.x)) + ((a.y - b.y) * (a.y - b.y)));   }   inline bool onseg(Point &a, Point &b, Point &c) {     if (fabs(xmul(a, b, c)) < 1e-10) return 1;     return 0;   }   inline double getans() {     Point a, b;     int tot = 0, cnt = 0, top = 0;     double ans = 0;     for (int i = 1; i <= n; i++) {       if (oneline(L.a, L.b, po[i], po[i + 1])) {         cnt++;         pp[cnt].a = po[i];         pp[cnt].type = 1;         cnt++;         pp[cnt].a = po[i + 1];         pp[cnt].type = -1;         if (pp[cnt].a < pp[cnt - 1].a) swap(pp[cnt].a, pp[cnt - 1].a);         continue;       }       int k1 = onseg(L.a, L.b, po[i]) || xmul(L.a, L.b, po[i]) < 0;       int k2 = onseg(L.a, L.b, po[i + 1]) || xmul(L.a, L.b, po[i + 1]) < 0;       if (k1 + k2 != 1) continue;       if (onseg(L.a, L.b, po[i])) {         rec[++tot] = po[i];         continue;       }       if (onseg(L.a, L.b, po[i + 1])) {         rec[++tot] = po[i + 1];         continue;       }       if (across(L.a, L.b, po[i], po[i + 1])) {         Line tmp;         tmp.a = po[i], tmp.b = po[i + 1];         rec[++tot] = intersection(L, tmp);       }     }     sort(rec + 1, rec + tot + 1);     for (int i = 1; i < tot; i += 2) {       cnt++;       pp[cnt].a = rec[i];       pp[cnt].type = 1;       cnt++;       pp[cnt].a = rec[i + 1];       pp[cnt].type = -1;     }     sort(pp + 1, pp + cnt + 1);     for (int i = 1; i <= cnt; i++) {       if (pp[i].type == 1)         stk[++top] = pp[i].a;       else {         if (top == 1) ans += dis(stk[top], pp[i].a);         top--;       }     }     return ans;   }   int main() {     scanf( %d %d , &n, &m);     for (int i = 1; i <= n; i++) scanf( %lf%lf , &po[i].x, &po[i].y);     po[n + 1] = po[1];     for (int i = 1; i <= m; i++) {       scanf( %lf%lf%lf%lf , &L.a.x, &L.a.y, &L.b.x, &L.b.y);       printf( %.8lf n , getans());     }     return 0;   }


#include <bits/stdc++.h>   bool vis[100000 + 3];   int pr[20000];   int h;   int a[300];   int n;   int endp[200000], next[200000], cap[200000];   int gra[300], cur[300], dist[300], prev[300];   int cnt[300];   int ecnt;   char buf[10000], *bend;   char out[10000], *oend;   void add_edge(int u, int v, int c) {     endp[++ecnt] = v;     cap[ecnt] = c;     next[ecnt] = gra[u];     gra[u] = ecnt;     endp[++ecnt] = u;     cap[ecnt] = 0;     next[ecnt] = gra[v];     gra[v] = ecnt;   }   int isap(int vcnt, int S_, int T_) {     memmove(cur, gra, sizeof(gra));     memset(cnt, 0, sizeof(cnt));     memset(dist, 0, sizeof(dist));     prev[S_] = S_;     int ret = 0, top;     int u = S_;     while (dist[S_] < vcnt) {       int i = cur[u];       for (; ~i; i = next[i]) {         int v = endp[i];         if (cap[i] && dist[u] == dist[v] + 1) {           prev[v] = cur[u] = i;           u = v;           break;         }       }       if (!~i) {         cur[u] = gra[u];         top = vcnt;         for (int i = gra[u]; ~i; i = next[i]) {           int v = endp[i];           if (cap[i] && dist[v] < top) {             top = dist[v];           }         }         ++cnt[top + 1];         if (!--cnt[dist[u]]) {           goto STOP;         }         dist[u] = top + 1;         if (u != S_) {           u = endp[prev[u] ^ 1];         }       }       if (u == T_) {         int arg = 1 << 29;         while (u != S_) {           if (cap[prev[u]] < arg) {             arg = cap[prev[u]];           }           u = endp[prev[u] ^ 1];         }         ret += arg;         while (u != T_) {           cap[cur[u]] -= arg;           cap[cur[u] ^ 1] += arg;           u = endp[cur[u]];         }         u = S_;       }     }   STOP:     return ret;   }   int find(int u, int p) {     vis[u] = true;     sprintf(bend,   %d , u + 1);     bend += strlen(bend);     *bend = 0;     for (int i = gra[u]; ~i; i = next[i]) {       int v = endp[i];       if (v == p || vis[v]) {         continue;       }       if ((!!cap[i]) ^ (a[u] & 1)) {         return find(v, u) + 1;       }     }     return 1;   }   bool is_pr(int val) {     int l = 0, r = h - 1;     while (r - l > 1) {       int mid = (l + r) >> 1;       if (pr[mid] < val) {         l = mid;       } else {         r = mid;       }     }     return pr[r] == val;   }   int main() {     for (int i = 2; i < 100000; ++i) {       if (!vis[i]) {         pr[h++] = i;       }       for (int j = 0; j < h; ++j) {         if (100000 / pr[j] < i) {           break;         }         vis[pr[j] * i] = true;         if (!(i % pr[j])) {           break;         }       }     }     while (scanf( %d , &n) != EOF) {       for (int i = 0; i < n; ++i) {         scanf( %d , a + i);       }       memset(gra, 255, sizeof(gra));       ecnt = -1;       for (int i = 0; i < n; ++i) {         if (a[i] & 1) {           add_edge(n, i, 2);           for (int j = 0; j < n; ++j) {             if (!(a[j] & 1) && is_pr(a[i] + a[j])) {               add_edge(i, j, 1);             }           }         } else {           add_edge(i, n + 1, 2);         }       }       int flow = isap(n + 2, n, n + 1);       if (flow != n) {         puts( Impossible );       } else {         oend = out;         memset(vis, 0, sizeof(vis));         int cnt = 0;         for (int i = 0; i < n; ++i) {           if (!vis[i]) {             bend = buf;             sprintf(oend,  %d%s n , find(i, -1), buf);             oend += strlen(oend);             ++cnt;           }         }         *(++oend) = 0;         printf( %d n%s , cnt, out);       }     }     return 0;   }


#include <bits/stdc++.h>   const int MAX_N = (int)1e5 + 123;   const double eps = 1e-6;   const int inf = (int)1e9 + 123;   using namespace std;   int n, k;   int mini = inf;   string second;   int sum[MAX_N];   int main() {     cin >> n >> k >> second;     for (int i = 0; i < int((second).size()); i++)       sum[i] = (i > 0 ? sum[i - 1] : 0) + (second[i] ==  0 );     vector<int> q;     for (int i = 0; i < int((second).size()); i++)       if (second[i] ==  0 ) q.push_back(i);     for (int i = 0; i < int((second).size()); i++) {       if (sum[int((second).size()) - 1] - (i > 0 ? sum[i - 1] : 0) < k + 1) break;       int l = i, r = int((second).size()) - 1, mid = -1, ans = -1;       while (l <= r) {         mid = (l + r) / 2;         if (sum[mid] - (i > 0 ? sum[i - 1] : 0) >= k + 1) {           ans = mid;           r = mid - 1;         } else           l = mid + 1;       }       assert(ans != -1);       int now = ans - i;       if ((ans - i + 1) % 2 == 1) {         int mid = (ans + i) / 2;         auto it = lower_bound(q.begin(), q.end(), mid);         if (it != q.end()) now = min(now, max(*it - i, ans - *it));         if (it != q.begin()) {           it--;           now = min(now, max(*it - i, ans - *it));         }       } else {         int mid = (ans + i) / 2 + 1;         auto it = lower_bound(q.begin(), q.end(), mid);         if (it != q.end()) now = min(now, max(*it - i, ans - *it));         mid--;         it = lower_bound(q.begin(), q.end(), mid);         if (it != q.end()) now = min(now, max(*it - i, ans - *it));         if (it != q.begin()) {           it--;           now = min(now, max(*it - i, ans - *it));         }       }       mini = min(mini, now);     }     cout << mini;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int t;     cin >> t;     while (t--) {       long long int n, m, sum = 0;       cin >> n >> m;       long long int a[5] = {0};       if (n == 1)         cout <<  0  << endl;       else if (n == 2)         cout << m << endl;       else         cout << (2 * m) << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 200005;   int n;   vector<int> adj[N];   vector<pair<int, int> > r;   int color[N];   bool vis[N];   void solve(int x) {     vis[x] = true;     for (auto w : adj[x]) {       if (!vis[w]) {         color[w] = (color[x]) ^ 1;         solve(w);       }     }   }   int32_t main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) {       int x, y;       scanf( %d%d , &x, &y);       x--, y--;       adj[x].push_back(y);       adj[y].push_back(x);       int k = 2 * i;       int kk = 2 * i + 1;       k %= 2 * n;       kk %= 2 * n;       adj[k].push_back(kk);       adj[kk].push_back(k);       r.push_back(pair<int, int>(x, y));     }     for (int i = 0; i < 2 * n; i++) {       if (!vis[i]) {         solve(i);       }     }     for (auto w : r) {       cout << color[w.first] + 1 <<     << color[w.second] + 1 << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   long long mod;   long long lgput(long long a, long long b) {     if (b == 0) return 1;     if (b == 1) return a % mod;     long long c = lgput(a, b / 2);     c = c * c % mod;     if (b & 1) c = c * a % mod;     return c;   }   map<long long, int> hh;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long n, k;     cin >> n >> mod >> k;     int i, j, z;     for (i = 0; i < n; i++) {       cin >> z;       hh[(lgput(z, 4) - 1LL * k * z % mod + mod) % mod]++;     }     long long ans = 0;     for (pair<int, int> cur : hh) ans += 1LL * cur.second * (cur.second - 1) / 2;     cout << ans;     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC target( avx,avx2,fma )   #pragma GCC optimization( unroll-loops )   const int N = 1e5 + 5;   const long double pi = 3.141592653;   const long long MOD = 1e9 + 7;   const long long mod = 998244353;   const long long INF = 9223372036854775807LL;   using namespace std;   int dx[9] = {1, -1, 0, 0, 1, 1, -1, -1, 0};   int dy[9] = {0, 0, 1, -1, 1, -1, 1, -1, 0};   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int T = 1;     while (T--) {       string s;       long long i, j, ans = 1, n;       cin >> s;       n = (long long)s.size();       bool ok = true;       for (i = 0; i < n; i++) {         if (s[i] ==  w  || s[i] ==  m ) ok = false;       }       if (!ok)         ans = 0;       else {         long long dp[N];         dp[0] = 0;         dp[1] = 1;         dp[2] = 2;         for (i = 3; i < N; i++) dp[i] = (dp[i - 1] + dp[i - 2]) % MOD;         for (i = 0; i < n; i++) {           if (s[i] ==  u  || s[i] ==  n ) {             j = i;             while (j < n && s[j] == s[i]) j++;             ans = (ans * dp[j - i]) % MOD;             i = j - 1;           }         }       }       cout << ans;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 200005;   map<int, int> Map;   struct Node {     int au, sub;   } node[MAX];   int n, temp, m;   int main() {     cin >> n;     for (int i = 1; i <= n; i++) {       scanf( %d , &temp);       Map[temp]++;     }     int m;     scanf( %d , &m);     for (int i = 1; i <= m; i++) {       scanf( %d , &node[i].au);     }     int Max1, Max2;     Max1 = Max2 = 0;     int id = 1;     for (int i = 1; i <= m; i++) {       scanf( %d , &node[i].sub);       if (Map[node[i].au] > Max1 ||           (Map[node[i].au] == Max1 && Map[node[i].sub] > Max2)) {         Max1 = Map[node[i].au];         Max2 = Map[node[i].sub];         id = i;       }     }     cout << id << endl;     return 0;   }


#include <bits/stdc++.h>   long long get2(long long, long long);   long long get1(long long n, long long x) {     if (x & 1)       return (x + 1) / 2;     else if (n & 1)       return get2(n / 2, x / 2) + (n + 1) / 2;     else       return get1(n / 2, x / 2) + n / 2;   }   long long get2(long long n, long long x) { return get1(n, x == 1 ? n : x - 1); }   int main() {     long long n;     int q;     std::cin >> n >> q;     while (q--) {       long long x;       std::cin >> x;       std::cout << get1(n, x) << std::endl;     }     return 0;   }


/*   {   ######################   #       Author       #   #        Gary        #   #        2021        #   ######################   */   #include<bits/stdc++.h>   #define rb(a,b,c) for(int a=b;a<=c;++a)   #define rl(a,b,c) for(int a=b;a>=c;--a)   #define LL long long   #define IT iterator   #define PB push_back   #define II(a,b) make_pair(a,b)   #define FIR first   #define SEC second   #define FREO freopen( check.out , w ,stdout)   #define rep(a,b) for(int a=0;a<b;++a)   #define SRAND mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())   #define random(a) rng()%a   #define ALL(a) a.begin(),a.end()   #define POB pop_back   #define ff fflush(stdout)   #define fastio ios::sync_with_stdio(false)   #define check_min(a,b) a=min(a,b)   #define check_max(a,b) a=max(a,b)   using namespace std;   //inline int read(){   //    int x=0;   //    char ch=getchar();   //    while(ch< 0 ||ch> 9 ){   //        ch=getchar();   //    }   //    while(ch>= 0 &&ch<= 9 ){   //        x=(x<<1)+(x<<3)+(ch^48);   //        ch=getchar();   //    }   //    return x;   //}   const int INF=0x3f3f3f3f;   typedef pair<int,int> mp;   /*}   */   const int MAXN=1e5+233;   vector<int> gra[MAXN];   vector<int> tree[MAXN];   int n,m;   int vis[MAXN];   int num[MAXN];   bool leaf[MAXN];   int g[MAXN],f[MAXN][2],h[MAXN];   void dfs(int now,int pre){    for(auto it:gra[now]){     if(it!=pre){      if(vis[it]){       if(vis[it]<vis[now]){        num[it]--;        num[now]++;       }      }      else{       vis[it]=vis[now]+1;       dfs(it,now);      }     }    }   }   void gao(int now,int pre){    vis[now]=1;    for(auto it:gra[now]) if(it!=pre){     if(!vis[it]){      gao(it,now);      num[now]+=num[it];   //   cout<<now<<   <<it<<   <<num[now]<<endl;     }    }    if(!num[now]&&pre){     tree[pre].PB(now);     tree[now].PB(pre);    }   }   vector<mp> rest;   bool cmp(int A,int B){    return f[A][1]-f[A][0]<f[B][1]-f[B][0];   }   void calc(int now,int pre){    vis[now]=1;    vector<int> sons;    f[now][0]=0;    bool all_leaf=true;    for(auto it:gra[now]) if(it!=pre) calc(it,now),sons.PB(it),f[now][0]+=f[it][1],all_leaf&=leaf[it];    if((sons.size()&1)&&all_leaf) f[now][0]=INF;    else    f[now][0]+=(sons.size()+1)>>1;    int sum=0;    for(auto it:sons) sum+=f[it][0];    sort(ALL(sons),cmp);    f[now][1]=INF;    if(sons.size()==0){     f[now][1]=0;     g[now]=now;     h[now]=0;     leaf[now]=true;    }    rb(i,1,sons.size()){     sum+=f[sons[i-1]][1]-f[sons[i-1]][0];     if(i>=sons.size()-1);     else continue;   //  cout<< # <<now<<   <<sum<<   <<f[sons[i-1]][1]<<   <<f[sons[i-1]][0]<<endl;     if(i&1){      if(sum+i/2<f[now][1]){       f[now][1]=sum+i/2;       g[now]=g[sons[0]];       h[now]=i;      }     }     else{      if(leaf[sons[0]]) continue;      if(sum+i/2<f[now][1]){       g[now]=g[sons[1]];       f[now][1]=sum+i/2;        h[now]=i;      }     }    }   // cout<<now<< : <<f[now][0]<<   <<f[now][1]<<endl;   }   void gao(int now,int ty,int pre){    vector<int> sons;    for(auto it:gra[now]) if(it!=pre) sons.PB(it);    if(ty==0){     int notleaf=-1;     rep(i,sons.size()){      int now=i,nex=i+1;       if((sons.size()&1)&&notleaf==-1&&!leaf[sons[now]]){       notleaf=sons[now];       now++;       nex++;      }      if((sons.size()&1)&&notleaf==-1&&!leaf[sons[nex]]){       notleaf=sons[nex];       nex++;      }      if(nex>=sons.size()) break;      rest.PB(II(g[sons[now]],g[sons[nex]]));      i=nex;     }     if(notleaf!=-1){      rest.PB(II(g[notleaf],now));     }     for(auto it:sons) gao(it,1,now);return;    }    if(sons.empty()) return;    sort(ALL(sons),cmp);    if((h[now])&1){     rb(i,1,h[now]-1){      rest.PB(II(g[sons[i]],g[sons[i+1]]));      ++i;     }    }    else{     rb(i,2,h[now]-1){      rest.PB(II(g[sons[i]],g[sons[i+1]]));      ++i;     }     rest.PB(II(g[sons[0]],now));    }    rb(i,1,h[now]) gao(sons[i-1],1,now);    rb(i,h[now]+1,sons.size()) gao(sons[i-1],0,now);   }   void solve(){    rest.clear();    rb(i,1,n) gra[i].clear(),leaf[i]=false;    rb(i,1,n) tree[i].clear();    rb(i,1,n) vis[i]=0;    rb(i,1,n) num[i]=0;    rb(i,1,m){     int si;     scanf( %d ,&si);     int pre=-1;     rb(j,1,si){      int ai;      scanf( %d ,&ai);      if(pre!=-1) gra[pre].PB(ai),gra[ai].PB(pre);      pre=ai;     }    }    vis[1]=1;    dfs(1,0);    rb(i,1,n) vis[i]=0;    gao(1,0);    rb(i,1,n) vis[i]=0;    rb(i,1,n) gra[i]=tree[i];    rb(i,1,n) if(!vis[i]){     calc(i,0);     int ret=f[i][0],z=0;     int sum=0;     for(auto it:gra[i]){      sum+=f[it][1];     }     for(auto it:gra[i]){      if(sum-f[it][1]+f[it][0]+gra[i].size()/2<ret){       ret=sum-f[it][1]+f[it][0]+gra[i].size()/2;       z=it;      }     }     if(z==0)     gao(i,0,0);      else{      gao(z,0,i);      for(auto it:gra[i]) if(it!=z) gao(it,1,i);      int pre=-1;      for(auto it:gra[i]){       if(it!=z){        if(pre!=-1) rest.PB(II(g[pre],g[it])),pre=-1;        else{         pre=it;        }       }      }      if(pre!=-1) rest.PB(II(g[pre],i));     }    }    printf( %d n ,int(rest.size()));    for(auto it:rest){     printf( %d %d n ,it.FIR,it.SEC);     }   }   int main(){    while(true){     scanf( %d%d ,&n,&m);     if(!n&&!m){      break;     }     solve();     }    return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 5;   string s[N];   int n, k, fa[N], len[N], ch[N][26], root = 1, last = 1, tot = 1, times[N];   void insert(int x) {     int now = ++tot, pre = last;     last = now, len[now] = len[pre] + 1;     for (; pre && !ch[pre][x]; pre = fa[pre]) ch[pre][x] = now;     if (!pre)       fa[now] = root;     else {       int q = ch[pre][x];       if (len[q] == len[pre] + 1)         fa[now] = q;       else {         int nows = ++tot;         len[nows] = len[pre] + 1;         memcpy(ch[nows], ch[q], sizeof(ch[q]));         fa[nows] = fa[q], fa[q] = fa[now] = nows;         for (; pre && ch[pre][x] == q; pre = fa[pre]) ch[pre][x] = nows;       }     }   }   long long vis[N], sum[N];   void getcnt() {     for (int i = 1; i <= n; i++) {       int now = root;       for (int j = 0; j < s[i].length(); j++) {         now = ch[now][s[i][j] -  a ];         int t = now;         while (t && vis[t] != i) vis[t] = i, times[t]++, t = fa[t];       }     }   }   void dfs(int x) {     if (x == root || vis[x]) return;     vis[x] = 1;     dfs(fa[x]);     sum[x] += sum[fa[x]];   }   int main() {     ios::sync_with_stdio(0);     cin >> n >> k;     for (int i = 1; i <= n; i++) cin >> s[i];     for (int i = 1; i <= n; i++) {       last = 1;       for (int j = 0; j < s[i].length(); j++) insert(s[i][j] -  a );     }     getcnt();     for (int i = 1; i <= tot; i++)       sum[i] = (times[i] >= k) * (len[i] - len[fa[i]]);     memset(vis, 0, sizeof(vis));     for (int i = 1; i <= tot; i++) dfs(i);     for (int i = 1; i <= n; i++) {       long long ans = 0, now = root;       for (int j = 0; j < s[i].length(); j++)         now = ch[now][s[i][j] -  a ], ans += sum[now];       printf( %lld  , ans);     }   }


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


#include <bits/stdc++.h>   using namespace std;   const int N = 100010;   const int MX = 123456;   const int mod = (int)1e9 + 7;   const int base = 1023456789;   const unsigned long long BS1 = 10000019ULL;   const int INF = (1 << 29);   template <class T>   inline void fastScan(T &x) {     register char c = getchar();     int neg = 0;     x = 0;     for (; (c < 48 || c > 57) && (c !=  - ); c = getchar())       ;     if (c ==  - ) {       neg = 1;       c = getchar();     }     for (; c > 47 && c < 58; c = getchar()) {       x = (x << 1) + (x << 3) + c - 48;     }     if (neg) x = -x;   }   int n, m, q;   int W[15];   int kunt[(1 << 12) + 10];   char str[15];   long long dp[(1 << 12) + 5][105];   bool Check(int nn, int pos) { return (bool)(nn & (1 << pos)); }   int P(int a, int b) {     int x = 0;     for (int i = 0; i < n; i++) {       if (Check(a, i) == Check(b, i)) {         x += W[i];       }     }     return x;   }   int main() {     fastScan(n);     fastScan(m);     fastScan(q);     for (int i = 0; i < n; i++) {       fastScan(W[i]);     }     for (int i = 0; i < m; i++) {       scanf( %s , str);       int x = 0;       for (int j = 0; str[j]; j++) {         if (str[j] ==  1 ) {           x += (1 << j);         }       }       kunt[x]++;     }     for (int i = 0; i <= (1 << 12); i++) {       int x = 0;       for (int j = 0; j <= (1 << 12); j++) {         if (kunt[j] >= 0) {           x = P(i, j);           if (x <= 100) dp[i][x] += kunt[j];         }       }     }     for (int i = 0; i <= (1 << 12); i++) {       for (int k = 1; k <= 101; k++) dp[i][k] += dp[i][k - 1];     }     for (int i = 0; i < q; i++) {       int x = 0, k = 0;       scanf( %s %d , str, &k);       for (int j = 0; j < n; j++) {         if (str[j] ==  1 ) x += (1 << j);       }       printf( %d n , dp[x][k]);     }   }


#include <bits/stdc++.h>   using namespace std;   long long mod = 1000000007, ans = 1, n, ert, dp[1000002];   int main() {     ios_base::sync_with_stdio(false);     cin >> n, ert = n;     dp[0] = 1, dp[1] = 1;     for (int i = 2; i <= n; i++) {       dp[i] = ((i - 1) * dp[i - 2] + dp[i - 1]) % mod;     }     for (int i = 1; i <= n; i++) {       int x;       cin >> x;       if (x == 2) ans *= ert, ans %= mod, ert--;     }     cout << ans * dp[ert] % mod <<   n ;     return 0;   }


#include <bits/stdc++.h>   #define arr(i,n) for(ll i=0;i<n;i++)   #define ARR(i,n) for(ll i=n-1;i>=0;i--)   #define f(i,a,b)  for(ll i=a;i<b;i++)   #define F(i,a,b)  for(ll i=b-1;i>=a;i--)   #define float double   #define PI 3.14159265358979323846   #define pb push_back   #define mp make_pair   #define vi vector<ll>   #define ceil(a) (ll) ceil(a)   #define floor(a) (ll) floor(a)   #define pow(a,b) (ll) pow(a,b)   #define fixed(x) cout<<fixed<<setprecision(6)<<x;   #define vpii vector< pair<ll,ll> >   #define debug(x) cout<<(#x)<<  is  <<(x)<<endl   #define dbg(x,y)  cout<<#x<< =  <<x<<   and   <<#y<< = <<y<<endl   #define gcd(a,b) __gcd(a,b)   #define lcm(a,b) (a*(b/gcd(a,b)))   #define all(v) v.begin(),v.end()   #define array(a,n) arr(i,n) cout<<a[i]<<   ;   #define array2D(a,n,m) arr(i,n) {arr(j,m) cout<<a[i][j]<<   ; cout<<endl;}   #define IOS  ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)   typedef long long ll;   using namespace std;   const ll  mod = 1000000000 + 7;   void solve()   {       //code start here       ll n;       cin>>n;       n=2*n;       ll a[n];       arr(i,n) cin>>a[i];       sort(a,a+n);       ll start=0,end=n-1;       arr(i,n)       {           if(i%2==0) {cout<<a[start]; start++;}           else {cout<<a[end]; end--; }           cout<<   ;       }       cout<<endl;   }   int main()   {       IOS;       int t; cin>>t;       while(t--)  solve();       return 0;   }


#include <bits/stdc++.h>   using namespace std;   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int t;     cin >> t;     while (t--) {       long long int n, i, j, x, y, a[100005], v[100005];       map<long long int, long long int> ma;       cin >> n;       for (i = 1; i <= n; i++) {         cin >> a[i];         ma[a[i]] = i;         v[i] = 0;       }       long long int fl = 0, p = -1;       for (i = 1; i <= n; i++) {         if (!v[ma[i]]) {           for (j = ma[i]; j <= n; j++) {             if (v[j] == 1 || j == n + 1) {               break;             }             if (a[j] != j - ma[i] + i) {               fl = 1;               break;             }             v[j] = 1;           }         }       }       if (fl) {         cout <<  No n ;       } else {         cout <<  Yes n ;       }     }     return 0;   }


#include<iostream>   #include<string>   using namespace std;   int  main()   {    int t;    cin>>t;    for(int i=0;i<t;i++)    {     int n;     string r,b;     cin>>n;     cin>>r>>b;     int counter1=0,counter2=0;     for(int i=0;i<n;i++)     {      if(r[i]>b[i])       counter1++;      else if(r[i]<b[i])       counter2++;     }     if(counter1>counter2)      cout<< RED <<endl;     else if(counter1==counter2)      cout<< EQUAL <<endl;     else       cout<< BLUE <<endl;    }    return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   char s[105][105];   char t[105];   bool judge1() {     int i = 0;     for (; i < n; i++) t[i] =  E ;     t[i] =   0 ;     for (int i = 0; i < n; i++)       if (strcmp(t, s[i]) == 0) return 1;     return 0;   }   bool judge2() {     for (int i = 0; i < n; i++) {       int F = 1;       for (int j = 0; j < n; j++)         if (s[j][i] !=  E ) {           F = 0;           break;         }       if (F) return 1;     }     return 0;   }   int main() {     while (~scanf( %d , &n)) {       for (int i = 0; i < n; i++) scanf( %s , s[i]);       if (judge1() && judge2()) {         cout << -1 << endl;         continue;       }       if (judge1()) {         for (int i = 0; i < n; i++) {           for (int j = 0; j < n; j++)             if (s[j][i] ==  . ) {               cout << j + 1 <<     << i + 1 << endl;               break;             }         }       } else         for (int i = 0; i < n; i++) {           int l = strlen(s[i]);           for (int j = 0; j < l; j++)             if (s[i][j] ==  . ) {               cout << i + 1 <<     << j + 1 << endl;               break;             }         }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     float n;     cin >> n;     int p = 1;     float count = 0;     while (n != 0) {       count = count + 1.0 / n;       n--;     }     cout << count;   }


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


#include <bits/stdc++.h>   using namespace std;   #pragma GCC optimize( Ofast )   #pragma GCC target( avx,avx2,fma )   #pragma GCC optimization( unroll-loops )   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   void __print(int x) { cout << x; }   void __print(long x) { cout << x; }   void __print(long long x) { cout << x; }   void __print(unsigned x) { cout << x; }   void __print(unsigned long x) { cout << x; }   void __print(unsigned long long x) { cout << x; }   void __print(float x) { cout << x; }   void __print(double x) { cout << x; }   void __print(long double x) { cout << x; }   void __print(char x) { cout <<      << x <<     ; }   void __print(const char *x) { cout <<     << x <<    ; }   void __print(const string &x) { cout <<     << x <<    ; }   void __print(bool x) { cout << (x ?  true  :  false ); }   template <typename T, typename V>   void __print(const pair<T, V> &x) {     cout <<  { ;     __print(x.first);     cout <<  , ;     __print(x.second);     cout <<  } ;   }   template <typename T>   void __print(const T &x) {     int first = 0;     cout <<  { ;     for (auto &i : x) cout << (first++ ?  ,  :   ), __print(i);     cout <<  } ;   }   void _print() { cout <<  ] n ; }   template <typename T, typename... V>   void _print(T t, V... v) {     __print(t);     if (sizeof...(v)) cout <<  ,  ;     _print(v...);   }   template <class T>   void remdup(vector<T> &v) {     sort((v).begin(), (v).end());     v.erase(unique((v).begin(), (v).end()), end(v));   }   template <typename T>   struct cmp {     bool operator()(const T &p1, const T &p2) {}   };   const long long N = 2e5 + 100;   const long long mod = 1e9 + 7;   const long long X = 2e5 + 100;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     ;     string s;     cin >> s;     long long ans = 0, wait = 0, m = 0;     for (auto &it : s) {       if (it ==  M ) {         m++;         if (wait) wait--;       } else {         if (m) {           ans = max(ans, m + wait);           wait++;         }       }     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long int MOD = 1e9 + 7;   long long int t;   string s;   long long int n;   long long int dp[100][2501];   long long int adp[100][2501];   long long int l, r, sm;   void solve() {     cin >> s;     n = s.length() - 1;     sm = 0;     for (auto it : s) sm += it -  a ;     l = adp[n][sm] - 1;     if (l < 0) l += MOD;     cout << l << endl;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     for (int i = 0; i < 26; i++) adp[0][i] = dp[0][i] = 1;     for (int i = 1; i <= 2500; i++) {       dp[0][i] += dp[0][i - 1];       dp[0][i] %= MOD;     }     for (int i = 1; i < 100; i++) {       for (int j = 0; j <= 2500; j++) {         l = r = 0;         if (j - 26 >= 0) l = dp[i - 1][j - 26];         r = dp[i - 1][j];         dp[i][j] = r - l;         if (dp[i][j] < 0) dp[i][j] += MOD;         dp[i][j] %= MOD;         adp[i][j] = dp[i][j];         if (j != 0) {           dp[i][j] += dp[i][j - 1];           dp[i][j] %= MOD;         }       }     }     t = 1;     cin >> t;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     for (int tc = 1; tc <= t; tc++) {       int n;       cin >> n;       pair<pair<int, int>, int> arr[2 * n - 1];       for (int i = 0; i < 2 * n - 1; i++) {         cin >> arr[i].first.first >> arr[i].first.second;         arr[i].second = i;       }       sort(arr, arr + 2 * n - 1);       long long odd = 0, even = 0;       for (int i = 0; i < 2 * n - 1; i++) {         if (i & 1)           even += arr[i].first.second;         else           odd += arr[i].first.second;       }       if (odd >= even) {         cout <<  YES n ;         int ans[n];         for (int i = 0; i < 2 * n - 1; i += 2) ans[i / 2] = arr[i].second + 1;         sort(ans, ans + n);         for (int i = 0; i < n - 1; i++) cout << ans[i] <<    ;         cout << ans[n - 1] <<   n ;       } else {         cout <<  YES n ;         int ans[n];         for (int i = 1; i < 2 * n - 1; i += 2) ans[i / 2] = arr[i].second + 1;         ans[n - 1] = arr[2 * n - 2].second + 1;         sort(ans, ans + n);         for (int i = 0; i < n - 1; i++) cout << ans[i] <<    ;         cout << ans[n - 1] <<   n ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   pair<int, pair<int, int> > tup[100000 * 2 + 10];   multiset<int> st;   int L[100000 * 2 + 10], R[100000 * 2 + 10], sl[100000 * 2 + 10],       sr[100000 * 2 + 10];   int main() {     int m, n, r, l, t;     scanf( %d%d , &m, &n);     int flag = 0;     for (int i = 1; i <= n; i++) {       scanf( %d%d%d , &l, &r, &t);       tup[i] = make_pair(l, make_pair(t, 0));       tup[i + n] = make_pair(r, make_pair(t, 1));     }     n *= 2;     sort(tup + 1, tup + n + 1);     int lasty = -1, o = 0;     for (int i = 1; i <= n; i++) {       int cury = tup[i].first;       if (lasty != -1 && cury != lasty && st.size()) {         if (st.empty()) {           printf( empty n );           return 0;         }         int curt = *st.begin();         L[++o] = curt - lasty;         R[o] = curt - cury;       }       lasty = cury;       if (tup[i].second.second)         st.erase(st.lower_bound(tup[i].second.first));       else         st.insert(tup[i].second.first);     }     if (flag) {       printf( o:%d n , o);       return 0;     }     sort(L + 1, L + o + 1);     sort(R + 1, R + o + 1);     for (int i = 1; i <= o; i++)       sl[i] = sl[i - 1] + L[i], sr[i] = sr[i - 1] + R[i];     while (m--) {       scanf( %d , &t);       l = lower_bound(L + 1, L + o + 1, t) - L - 1;       r = lower_bound(R + 1, R + o + 1, t) - R - 1;       printf( %d n , (int)((r - l) * (long long)t - sr[r] + sl[l]));     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       string s[n];       map<string, int> m;       set<string> k;       int count = 0;       for (int i = 0; i < n; i++) {         cin >> s[i];         k.insert(s[i]);       }       for (int i = 0; i < n; i++) {         if (m[s[i]] >= 1) {           count++;           int j = 0;           while (k.find(s[i]) != k.end()) {             s[i][3] = j +  0 ;             j++;           }         }         m[s[i]]++;         k.insert(s[i]);       }       cout << count << endl;       for (int i = 0; i < n; i++) cout << s[i] << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0), cout.tie(0);     int t;     cin >> t;     while (t--) {       int a, b, c, d;       cin >> a >> b >> c >> d;       cout << max(a + b, c + d) <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long double eps = 1e-9;   const int inf = 1e+9;   const double pi = acos(-1.0);   long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }   long long xabs(long long a) { return a > 0 ? a : -a; }   map<int, vector<string>> s;   int sm[9][2] = {{0, 1},  {0, -1}, {1, 0},   {-1, 0}, {1, 1},                   {1, -1}, {-1, 1}, {-1, -1}, {0, 0}};   void dfs(int x, int y, int t) {     if (t == 9) {       cout <<  WIN ;       exit(0);     }     if (s[t][x][y] ==  S ) return;     for (int i = 0; i < 9; i++) {       int xx = x + sm[i][0];       int yy = y + sm[i][1];       if (xx >= 0 && xx < 8 && yy >= 0 && yy < 8 && s[t][xx][yy] !=  S )         dfs(xx, yy, t + 1);     }   }   int main() {     for (int i = 0; i < 8; i++) {       string t;       cin >> t;       s[0].push_back(t);     }     for (int i = 1; i <= 8; i++) {       string r =  ........ ;       s[i].push_back(r);       for (int k = 0; k < 7; k++) {         s[i].push_back(s[i - 1][k]);       }     }     dfs(7, 0, 0);     cout <<  LOSE ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T, class U>   void maximize(T &x, U y) {     if (x < y) x = y;   }   template <class T, class U>   void minimize(T &x, U y) {     if (x > y) x = y;   }   template <class T>   T Abs(T x) {     return (x < (T)0 ? -x : x);   }   namespace task {   const int N = 2e5 + 5;   const int maxVal = 5e5;   vector<int> prime;   vector<vector<int> > p;   int e[maxVal + 5];   int cnt[maxVal + 5];   bool inshelf[N];   int a[N];   int n, q;   void solve() {     cin >> n >> q;     for (int i = 1; i <= n; ++i) {       cin >> a[i];     }     iota(e, e + 1 + maxVal, 0);     for (int i = 2; i <= maxVal; ++i) {       if (e[i] == i) {         prime.emplace_back(i);       }       for (int j = 0; j < (int)((prime).size()) and i * prime[j] <= maxVal; ++j) {         e[i * prime[j]] = prime[j];         if (i % prime[j] == 0) {           break;         }       }     }     p.resize(n + 2, vector<int>());     for (int i = 1; i <= n; ++i) {       int tmp = a[i];       for (int k = e[tmp]; k > 1 and tmp > 1; k = e[tmp]) {         while (tmp % k == 0) {           tmp /= k;         }         p[i].emplace_back(k);       }     }     int cur = 0;     long long ans = 0;     while (q--) {       int x;       cin >> x;       long long subs = 0;       int k = (inshelf[x] ? -1 : 1);       for (int mask = 1; mask < ((1LL) << ((int)((p[x]).size()))); ++mask) {         int mul = 1;         for (int i = 0; i < (int)((p[x]).size()); ++i) {           if ((((mask) >> (i)) & 1)) {             mul *= p[x][i];           }         }         subs += 1LL * ((__builtin_popcount(mask) & 1) ? 1 : -1) * 1LL * cnt[mul];       }       if (!inshelf[x]) {         ans += cur - subs;         inshelf[x] = true;         ++cur;       } else {         ans -= cur - (a[x] == 1 ? 1 : subs);         inshelf[x] = false;         --cur;       }       cout << ans <<   n ;       for (int mask = 1; mask < ((1LL) << ((int)((p[x]).size()))); ++mask) {         int mul = 1;         for (int i = 0; i < (int)((p[x]).size()); ++i) {           if ((((mask) >> (i)) & 1)) {             mul *= p[x][i];           }         }         cnt[mul] += k;       }     }   }   }  // namespace task   int main(void) {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     task::solve();   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 0x3f3f3f3f;   const int mod = 1e9 + 7;   const int maxn = 55;   int st[maxn];   struct E {     int u, v, w, cost;     int nxt;   } edge[500009];   int gtot = 0, head[maxn * 100];   void addedge(int u, int v, int w, int cost) {     edge[gtot].v = v;     edge[gtot].w = w;     edge[gtot].cost = cost;     edge[gtot].nxt = head[u];     head[u] = gtot++;     edge[gtot].v = u;     edge[gtot].w = 0;     edge[gtot].cost = -cost;     edge[gtot].nxt = head[v];     head[v] = gtot++;   }   int dis[maxn * 100], path[500009], vis[maxn * 100], pre[maxn * 100];   bool spfa(int s, int t) {     memset(pre, -1, sizeof(pre));     memset(dis, inf, sizeof(dis));     memset(vis, 0, sizeof(vis));     queue<int> que;     que.push(s);     vis[s] = 1;     dis[s] = 0;     while (!que.empty()) {       int u = que.front();       que.pop();       vis[u] = 0;       for (int i = head[u]; ~i; i = edge[i].nxt) {         int v = edge[i].v, val = edge[i].w, cost = edge[i].cost;         if (val > 0 && dis[v] > dis[u] + cost) {           dis[v] = dis[u] + cost;           pre[v] = u;           path[v] = i;           if (vis[v] == 0) {             vis[v] = 1;             que.push(v);           }         }       }     }     return pre[t] != -1;   }   int mcmf(int s, int t) {     int flow = 0, cost = 0;     while (spfa(s, t)) {       int f = inf;       for (int i = t; i != s; i = pre[i]) {         f = min(f, edge[path[i]].w);       }       flow += f;       cost += f * dis[t];       for (int i = t; i != s; i = pre[i]) {         edge[path[i]].w -= f;         edge[path[i] ^ 1].w += f;       }     }     return cost;   }   int main() {     memset(head, -1, sizeof(head));     gtot = 0;     int n, m, k, c, d;     scanf( %d%d%d%d%d , &n, &m, &k, &c, &d);     for (int i = 1; i <= k; i++) {       int x;       scanf( %d , &x);       st[x]++;     }     int s = 0, t = 100 * n + 1;     for (int i = 1; i <= n; i++) {       for (int j = 2; j <= 100; j++) {         addedge((i - 1) * 100 + j - 1, (i - 1) * 100 + j, inf, c);       }     }     for (int i = 2; i <= n; i++) {       if (st[i]) addedge(s, (i - 1) * 100 + 1, st[i], 0);     }     for (int i = 1; i <= 100; i++) addedge(i, t, inf, 0);     for (int i = 1; i <= m; i++) {       int u, v;       scanf( %d%d , &u, &v);       for (int j = 2; j <= 100; j++) {         for (int k = 1; k <= 20; k++) {           addedge((u - 1) * 100 + j - 1, (v - 1) * 100 + j, 1,                   (k * k - (k - 1) * (k - 1)) * d + c);           addedge((v - 1) * 100 + j - 1, (u - 1) * 100 + j, 1,                   (k * k - (k - 1) * (k - 1)) * d + c);         }       }     }     printf( %d n , mcmf(s, t));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int read();   int n;   int a[200005], b[200005], c[200005], bk[200005];   int hd[200005], nx[400005], to[400005], cnt;   void add(int f, int t) { nx[++cnt] = hd[f], hd[f] = cnt, to[cnt] = t; }   int fa[200005], dep[200005];   void dfs1(int u) {     for (int i = hd[u], v; i; i = nx[i])       if ((v = to[i]) != fa[u]) dep[v] = dep[fa[v] = u] + 1, dfs1(v);   }   bool check1() {     for (int i = 1; i <= n; ++i) c[i] = b[i];     int u = a[1];     while (fa[u]) swap(c[u], c[fa[u]]), u = fa[u];     for (int i = 1; i <= n; ++i)       if (c[i] != i) return 0;     return 1;   }   vector<int> st[2];   int idcnt;   void fail() { puts( -1 ), exit(0); }   void get(int u, int id) {     if (id >= 2 || (id == 1 && fa[st[0][0]] != fa[u])) fail();     st[id].push_back(u);     while (1) {       int v = 0;       for (int i = hd[u]; i; i = nx[i])         if (to[i] != fa[u] && c[to[i]] != to[i]) v ? fail() : (v = to[i], void());       if (!v) break;       st[id].push_back(u = v);     }   }   void dfs2(int u) {     for (int i = hd[u], v; i; i = nx[i])       if ((v = to[i]) != fa[u]) (c[v] != v) ? get(v, idcnt++) : dfs2(v);   }   int p[200005], q[200005], len;   int M(int x) { return x >= len ? x - len : x; }   int getdis(int u, int v) {     int rt = 0;     while (u != v) (dep[u] < dep[v]) ? swap(u, v) : void(), ++rt, u = fa[u];     return rt;   }   void work() {     for (int i = 1; i <= n; ++i) q[i] = -1;     for (int i = 0; i < st[0].size(); ++i)       p[len] = c[st[0][i]], q[st[0][i]] = len, ++len;     int ru = st[0].back(), rv = fa[st[0].front()], rw = rv;     if (st[1].size()) {       rv = st[1].back();       for (int i = st[1].size() - 1; i >= 0; --i)         p[len] = c[st[1][i]], q[st[1][i]] = len, ++len;     }     if ((ru = bk[ru]) > (rv = bk[rv])) swap(ru, rv);     long long dis = q[p[0]];     for (int i = 1; i < len; ++i)       if (M(q[p[i]] - i + len) != dis) fail();     for (int i = 1; i <= n; ++i)       if (c[i] != i && q[i] == -1) fail();     int t = a[1];     while (q[t] == -1 && t != 1) t = fa[t];     if (t == 1) {       dis = min(dis, len - dis) * (len + 1);       printf( %d %d %lld n , ru, rv, dis + getdis(a[1], rw) + dep[rw]);       return;     }     dis = q[t] >= st[0].size()               ? min((dis - 1) * (len + 1) + (q[t] + 1),                     1ll * M(len - dis) * (len + 1) + (len - q[t]))               : min(dis * (len + 1) + (q[t] + 1),                     (len - dis - 1) * (len + 1) + (len - q[t]));     printf( %d %d %lld n , ru, rv, dis + dep[rw] + getdis(a[1], t));   }   int main() {     n = read();     for (int i = 1; i <= n; ++i) bk[a[i] = read() + 1] = i;     for (int i = 1; i <= n; ++i) b[a[i]] = read() + 1;     for (int i = 1, u, v; i < n; ++i)       u = a[read()], v = a[read()], add(u, v), add(v, u);     for (int i = 1; i <= n; ++i) a[b[i]] = i;     dfs1(1);     if (check1()) return printf( 0 %d n , dep[a[1]]), 0;     dfs2(1), work();     return 0;   }   const int _SIZE = 1 << 22;   char ibuf[_SIZE], *iS = ibuf, *iT = ibuf;   int read() {     int x = 0, f = 1;     char c = (iS == iT ? iT = ((iS = ibuf) + fread(ibuf, 1, _SIZE, stdin)),               (iS == iT ? EOF : *iS++) : *iS++);     while (!isdigit(c))       f = (c ==  - ) ? -1 : f,       c = (iS == iT ? iT = ((iS = ibuf) + fread(ibuf, 1, _SIZE, stdin)),            (iS == iT ? EOF : *iS++) : *iS++);     while (isdigit(c))       x = x * 10 + c -  0 ,       c = (iS == iT ? iT = ((iS = ibuf) + fread(ibuf, 1, _SIZE, stdin)),            (iS == iT ? EOF : *iS++) : *iS++);     return x * f;   }


#include <bits/stdc++.h>   using namespace std;   long long n, t = 1, c1, c2;   vector<vector<long long>> adj;   vector<vector<long long>> g;   vector<bool> visited;   void DFS(long long v) {     visited[v] = true;     g[t].push_back(v);     for (auto i : adj[v])       if (!visited[i]) DFS(i);   }   long long number_of_components() {     for (long long v = 1; v <= n; v++)       if (!visited[v]) {         DFS(v);         if (g[t].size() > 3) {           cout <<  -1 ;           return -1;         }         if (g[t].size() == 1) c1++;         if (g[t].size() == 2) c2++;         t++;       }   }   void solve() {     long long m, x, y, j = 0, h = 1;     cin >> n >> m;     adj.resize(n + 1);     g.resize(n + 1);     visited.assign(n + 1, false);     for (long long i = 1; i <= m; i++) {       cin >> x >> y;       adj[x].push_back(y);       adj[y].push_back(x);     }     long long z = number_of_components();     if (z == -1) return;     if (c2 > c1) {       cout <<  -1 ;       return;     }     if ((c1 - c2) % 3 != 0) {       cout << -1;       return;     }     for (long long i = 1; i <= t; i++) {       if (g[i].size() == 3) {         for (auto v : g[i]) cout << v <<    ;         cout <<   n ;       }       if (g[i].size() == 2) {         for (auto v : g[i]) cout << v <<    ;         for (j = h; j <= t; j++)           if (g[j].size() == 1) {             cout << g[j][0];             break;           }         h = j + 1;         cout <<   n ;       }     }     for (long long i = j + 1; i <= t; i++) {       if (g[i].size() == 1) cout << g[i][0] <<    ;       if ((j - i) % 3 == 0) cout <<   n ;     }   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     solve();     cerr <<  time taken :   << (float)clock() / CLOCKS_PER_SEC <<   secs  << endl;     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   long long n, m, k;   char s[200005];   vector<long long> cnt[3][202];   vector<pair<long long, long long> > res;   int main() {     long long i, j;     scanf( %lld , &n);     scanf( %s , &s);     for (i = 0; i <= n - 1; i++) {       cnt[1][s[i]].push_back(i + 1);     }     scanf( %s , &s);     for (i = 0; i <= n - 1; i++) {       cnt[2][s[i]].push_back(i + 1);     }     for (i =  a ; i <=  z ; i++) {       while (cnt[1][i].size() && cnt[2][i].size()) {         res.push_back(make_pair(cnt[1][i].back(), cnt[2][i].back()));         cnt[1][i].pop_back(), cnt[2][i].pop_back();       }     }     for (i =  a ; i <=  z ; i++) {       while (cnt[2][i].size() && cnt[1][ ? ].size()) {         res.push_back(make_pair(cnt[1][ ? ].back(), cnt[2][i].back()));         cnt[1][ ? ].pop_back(), cnt[2][i].pop_back();       }     }     for (i =  a ; i <=  z ; i++) {       while (cnt[1][i].size() && cnt[2][ ? ].size()) {         res.push_back(make_pair(cnt[1][i].back(), cnt[2][ ? ].back()));         cnt[2][ ? ].pop_back(), cnt[1][i].pop_back();       }     }     while (cnt[1][ ? ].size() && cnt[2][ ? ].size()) {       res.push_back(make_pair(cnt[1][ ? ].back(), cnt[2][ ? ].back()));       cnt[2][ ? ].pop_back(), cnt[1][ ? ].pop_back();     }     long long d = res.size();     printf( %lld n , d);     for (i = 0; i <= d - 1; i++) {       printf( %lld %lld n , res[i].first, res[i].second);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2010;   char mp[N][N];   int n, m, cnt1, cnt2, in[N][N];   int xx[6] = {0, 0, 1, 0, -1};   int yy[6] = {0, 1, 0, -1, 0};   queue<pair<long long, long long> > q;   int main() {     int n, m;     while (cin >> n >> m) {       memset(in, 0, sizeof in);       for (int i = 1; i <= n; i++) {         scanf( %s , mp[i] + 1);       }       cnt1 = cnt2 = 0;       for (int i = 1; i <= n; i++) {         for (int j = 1; j <= m; j++)           if (mp[i][j] ==  . ) {             cnt1++;             for (int k = 1; k <= 4; k++)               if (mp[i + xx[k]][j + yy[k]] ==  . ) in[i][j]++;             if (in[i][j] == 1) {               q.push(pair<long long, long long>(i, j));             }           }       }       while (!q.empty()) {         pair<long long, long long> u = q.front();         q.pop();         int x = u.first, y = u.second, tx, ty, i;         for (i = 1; i <= 4; i++) {           tx = x + xx[i];           ty = y + yy[i];           if (mp[tx][ty] ==  . ) {             cnt2 += 2;             if (i == 1) mp[x][y] =  < , mp[tx][ty] =  > ;             if (i == 2) mp[x][y] =  ^ , mp[tx][ty] =  v ;             if (i == 3) mp[x][y] =  > , mp[tx][ty] =  < ;             if (i == 4) mp[x][y] =  v , mp[tx][ty] =  ^ ;             break;           }         }         if (i == 5) continue;         x = tx, y = ty;         for (int i = 1; i <= 4; i++) {           tx = x + xx[i];           ty = y + yy[i];           if (mp[tx][ty] ==  . ) {             in[tx][ty]--;             if (in[tx][ty] == 1) {               q.push(pair<long long, long long>(tx, ty));             }           }         }       }       if (cnt1 < cnt2) {         cout << cnt1 <<     << cnt2 << endl;         for (int i = 1; i <= n; i++) {           printf( %s n , mp[i] + 1);         }         break;       }       if (cnt1 != cnt2) {         printf( Not unique n );         continue;       }       for (int i = 1; i <= n; i++) {         printf( %s n , mp[i] + 1);       }     }   }


#include <bits/stdc++.h>   long long int segMax[1000010] = {0}, segSum[1000010] = {0};   long long int a[200010];   void constructMax(int low, int high, int pos) {     if (low > high) return;     if (low == high) {       segMax[pos] = a[low];       return;     }     int mid = low + (high - low) / 2;     constructMax(low, mid, pos * 2 + 1);     constructMax(mid + 1, high, pos * 2 + 2);     segMax[pos] = std::max(segMax[pos * 2 + 1], segMax[pos * 2 + 2]);   }   void updateMax(int low, int high, int node, long long int val, int pos) {     if (low == high && low == node) {       segMax[pos] = val;       return;     }     if (high < node || low > node) return;     int mid = low + (high - low) / 2;     updateMax(low, mid, node, val, pos * 2 + 1);     updateMax(mid + 1, high, node, val, pos * 2 + 2);     segMax[pos] = std::max(segMax[pos * 2 + 1], segMax[pos * 2 + 2]);   }   void constructSum(int low, int high, int pos) {     if (low > high) return;     if (low == high) {       segSum[pos] = a[low];       return;     }     int mid = low + (high - low) / 2;     constructSum(low, mid, pos * 2 + 1);     constructSum(mid + 1, high, pos * 2 + 2);     segSum[pos] = segSum[pos * 2 + 1] + segSum[pos * 2 + 2];   }   void updateSum(int low, int high, int node, long long int val, int pos) {     if (low == high && low == node) {       a[low] = val;       segSum[pos] = val;       return;     }     if (low > node || high < node) return;     int mid = low + (high - low) / 2;     updateSum(low, mid, node, val, pos * 2 + 1);     updateSum(mid + 1, high, node, val, pos * 2 + 2);     segSum[pos] = segSum[pos * 2 + 1] + segSum[pos * 2 + 2];   }   int findMax(int low, int high, int sumToFind, int pos) {     if (low == high && segMax[pos] >= sumToFind) {       return low;     } else if (low == high) {       return -1;     }     int mid = low + (high - low) / 2;     if (segMax[pos * 2 + 1] >= sumToFind) {       return findMax(low, mid, sumToFind, pos * 2 + 1);     } else if (segMax[pos * 2 + 2] >= sumToFind) {       return findMax(mid + 1, high, sumToFind, pos * 2 + 2);     } else {       return -1;     }   }   long long int findSum(int qlow, int qhigh, int low, int high, int pos) {     if (high < qlow || low > qhigh) return 0;     if (qlow > qhigh)       return 0;     else if (qlow <= low && high <= qhigh) {       return segSum[pos];     }     int mid = low + (high - low) / 2;     return findSum(qlow, qhigh, low, mid, pos * 2 + 1) +            findSum(qlow, qhigh, mid + 1, high, pos * 2 + 2);   }   int main() {     std::ios_base::sync_with_stdio(0);     std::cin.tie(0);     int n, q;     std::cin >> n >> q;     for (int i = 0; i < n; ++i) {       std::cin >> a[i];     }     constructMax(1, n - 1, 0);     constructSum(1, n - 1, 0);     while (q--) {       int node;       long long int val;       std::cin >> node >> val;       --node;       if (node != 0) {         updateMax(1, n - 1, node, val, 0);         updateSum(1, n - 1, node, val, 0);       } else {         a[node] = val;       }       if (a[0] == 0) {         std::cout <<  1 n ;         continue;       }       long long int curSum = a[0];       bool flag = false;       while (curSum <= 1e9) {         int node = findMax(1, n - 1, curSum, 0);         long long int nowSum;         if (node == -1)           break;         else {           nowSum = findSum(1, node - 1, 1, n - 1, 0);           nowSum += a[0];         }         if (nowSum == a[node]) {           std::cout << node + 1 <<   n ;           flag = true;           break;         } else {           curSum = nowSum + a[node];         }       }       if (!flag) {         std::cout <<  -1 n ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t;     cin >> t;     for (int z = 0; z < t; z++) {       int n, x, y;       cin >> n;       vector<vector<int>> v;       for (int i = 0; i < n; i++) {         cin >> x >> y;         vector<int> t(2);         t[0] = x, t[1] = y;         v.push_back(t);       }       sort(v.begin(), v.end());       bool e = false;       for (int i = 0; i < n - 1; i++)         if (v[i + 1][1] < v[i][1]) {           e = true;           break;         }       if (e)         cout <<  NO  << endl;       else {         cout <<  YES  << endl;         string s;         for (int i = 0; i < v[0][0]; i++) s +=  R ;         for (int i = 0; i < v[0][1]; i++) s +=  U ;         for (int i = 0; i < n - 1; i++) {           for (int j = v[i][0]; j < v[i + 1][0]; j++) s +=  R ;           for (int j = v[i][1]; j < v[i + 1][1]; j++) s +=  U ;         }         cout << s << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     string a[n];     for (int i = 0; i < n; ++i) cin >> a[i];     string col[] = { Power ,  Space ,  Time ,  Soul ,  Reality ,  Mind };     string stone[] = { purple ,  blue ,  green ,  orange ,  red ,  yellow };     cout << 6 - n <<   n ;     for (int i = 0; i < 6; ++i) {       int flag = 0;       for (int j = 0; j < n; ++j) {         if (stone[i] == a[j]) {           flag = 1;           break;         }       }       if (!flag) {         cout << col[i] <<   n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 1e5 + 10, M = 1e9, eps = 1e-7, MOD = 1e9 + 7;   long long tab[N];   int main() {     long long n, l;     cin >> n >> l;     n--;     for (long long i = 1; i <= n; i++) cin >> tab[i];     long long pocz = 0;     long long pot = 1 << 30;     while (pot > 0) {       long long moze = pot + pocz;       if (moze > M) {         pot /= 2;         continue;       }       long long pom = 0;       bool czujka = true;       for (long long i = 1; i <= l; i++) pom += tab[i];       if (pom < moze) czujka = false;       for (long long i = l + 1; i <= n; i++) {         pom += tab[i];         pom -= tab[i - l];         if (pom < moze) czujka = false;       }       if (czujka) pocz = moze;       pot /= 2;     }     cout << pocz;   }


#include <bits/stdc++.h>   using namespace std;   bool endline = false;   template <class T>   istream& operator>>(istream& inp, vector<T>& v) {     for (auto& it : v) inp >> it;     return inp;   }   template <class T>   ostream& operator<<(ostream& out, vector<T>& v) {     for (auto& it : v) out << it << (endline ?   n  :    );     return out;   }   template <class T, class U>   istream& operator>>(istream& inp, pair<T, U>& v) {     inp >> v.first >> v.second;     return inp;   }   template <class T, class U>   ostream& operator<<(ostream& out, pair<T, U>& v) {     out << v.first <<     << v.second;     return out;   }   void debug() { cout << endl; }   template <typename H, typename... T>   void debug(H a, T... b) {     cout << a <<    ;     debug(b...);   }   void FAST_IO(string filein =   , string fileout =   ) {     if (fopen(filein.c_str(),  r )) {       freopen(filein.c_str(),  r , stdin);       freopen(fileout.c_str(),  w , stdout);     }     cin.tie(0), cout.tie(0)->sync_with_stdio(0);   }   void Hollwo_Pelw();   signed main() {     FAST_IO( .inp ,  .out );     int testcases = 1;     for (int test = 1; test <= testcases; test++) {       Hollwo_Pelw();     }     return 0;   }   const int allmod[3] = {(int)1e9 + 7, 998244353, (int)1e9 + 9};   const int mod = allmod[1];   const int MAXN = 1e6 + 6;   const int inf = 2e9;   const long long linf = 1e18;   long long n;   void dofirst() {     cout <<  First  << endl;     for (long long i = 1; i <= n; i++) cout << i <<    ;     for (long long i = 1; i <= n; i++) cout << i <<    ;     cout << endl;   }   vector<long long> pr[MAXN], adj[MAXN];   void addedge(long long u, long long v) {     adj[u].push_back(v), adj[v].push_back(u);   }   long long vis[MAXN];   void dfs(long long u, long long c) {     vis[u] = c;     for (auto v : adj[u])       if (!vis[v]) dfs(v, 3 - c);   }   void check(long long v) {     long long sum = 0;     for (long long i = 1; i <= 2 * n; i++)       if (vis[i] == v) sum += i;     if (sum % (2 * n) == 0) {       for (long long i = 1; i <= 2 * n; i++)         if (vis[i] == v) cout << i <<    ;       cout << endl;     }   }   void dosecond() {     cout <<  Second  << endl;     for (long long i = 1, p; i <= 2 * n; i++) cin >> p, pr[p].push_back(i);     for (long long i = 1; i <= n; i++)       addedge(pr[i][0], pr[i][1]), addedge(i, i + n);     for (long long i = 1; i <= 2 * n; i++)       if (!vis[i]) dfs(i, 1);     check(1);     check(2);   }   void getverdict() {     long long x;     cin >> x;     if (!x) exit(0);   }   void Hollwo_Pelw() {     cin >> n;     if (n % 2 == 0) {       dofirst();     } else {       dosecond();     }     getverdict();   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k, i = 1;     cin >> n >> k;     if (k == 1)       cout << n;     else {       vector<int> ans;       while (ans.size() < k) {         i = 2;         while (n % i != 0 && i <= n + 1) i++;         if (i >= n + 1) {           cout << -1;           return 0;         }         n /= i;         ans.push_back(i);       }       for (i = 0; i < ans.size() - 1; i++) cout << ans[i] <<    ;       cout << n * ans[ans.size() - 1];     }   }


#include <bits/stdc++.h>   using namespace std;   void OJ() {}   void solve() {     long long n;     cin >> n;     long long digit = 1000000, a = -1, b = -1;     for (long long i = 0; i < 1e6; ++i) {       if (n >= 4 * i)         if ((n - 4 * i) % 7 == 0) {           if ((n - 4 * i) / 7 + i <= digit)             digit = (n - 4 * i) / 7 + i, a = i, b = (n - 4 * i) / 7;         }     }     if (a == -1) {       cout << -1;       return;     }     for (long long i = 0; i < a; ++i) cout << 4;     for (long long i = 0; i < b; ++i) cout << 7;   }   signed main() {     OJ();     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     solve();   }


#include <bits/stdc++.h>   using namespace std;   int p[12];   int main() {     long long n;     cin >> n;     if (n < 5) {       cout << (n * (n - 1) / 2) << endl;       return 0;     }     long long p = 5;     for (int i = 1;; ++i) {       if (p > n) {         p /= 10;         long long tot = p * 2;         --i;         ++n;         if (n % tot <= p) {           long long a = n % tot;           long long b = p - a;           long long x = n / tot;           long long ans = (a * x * (x + 1)) + (b * x * x);           ans -= x;           cout << ans << endl;         } else {           long long a = n % tot - p;           long long b = p - a;           long long x = n / tot;           long long ans = (a * (x + 1) * (x + 1)) + b * x * (x + 1);           ans -= x;           cout << ans << endl;         }         return 0;       }       p *= 10;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   void rd(T &k) {     char c = getchar();     int f = 1;     k = 0;     while (c <  0  || c >  9 ) {       if (c ==  - ) f *= -1;       c = getchar();     }     while (c >=  0  && c <=  9 ) {       k = k * 10 + c -  0 ;       c = getchar();     }     k *= f;   }   const int N = 2200;   int n, m, k, s, t;   char c[5005];   int f[N][1 << 12], sum[N];   int g[1 << 12];   int main() {     cin >> c + 1;     n = strlen(c + 1);     for (k = 0, s = 1; s <= n; ++k, s <<= 1)       ;     --k;     m = n + 1 - (1 << k);     f[0][0] = 1;     for (register int i = 1; i <= m; ++i) {       char mx =  z ;       memset(g, 0, sizeof(g));       for (register int j = 0; j < (1 << k); ++j) {         if (f[i - 1][j]) g[j] = 1;         for (register int p = 0; p < k; ++p)           if ((j & (1 << p)) && g[j ^ (1 << p)]) g[j] = 1;         if (g[j]) mx = min(mx, c[i + j]);       }       cout << mx;       for (register int j = 0; j < (1 << k); ++j)         if (g[j] && c[j + i] == mx) f[i][j] = 1;     }   }


#include <bits/stdc++.h>   using namespace std;   const long long int INF = 1e18;   int32_t main() {     long long int n;     cin >> n;     if (n % 2 != 0) {       cout << 0 <<   n ;       return 0;       ;     }     long long int k = pow(2, n / 2);     cout << k <<   n ;     return 0;     ;   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   #pragma GCC optimize( unroll-loops )   using namespace std;   using ll = long long;   using db = long double;   using ii = pair<int, int>;   const int N = 5e5 + 5, LG = 19, MOD = 1e9 + 7;   const int SQ = 225;   const long double EPS = 1e-7;   string s;   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int _;     cin >> _;     while (_--) {       int n;       cin >> n;       int cnt[2] = {};       vector<int> v;       for (int i = 0; i < n; i++) {         string s;         cin >> s;         v.push_back(s.size() / 2);         for (auto c : s) cnt[c -  0 ]++;       }       cnt[0] /= 2;       cnt[1] /= 2;       sort(v.begin(), v.end());       int sum = cnt[0] + cnt[1];       int ans = 0;       for (auto x : v)         if (x <= sum) {           sum -= x;           ans++;         }       cout << ans <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long power(long long x, long long y, long long mod = 2e18) {     long long ans = 1;     x %= mod;     while (y) {       if (y & 1) ans = (x * ans) % mod;       x = (x * x) % mod;       y >>= 1;     }     return ans;   }   signed main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     long long t;     cin >> t;     cout << setprecision(20);     while (t--) {       long long n, k;       cin >> n >> k;       if (n >= 32) {         cout <<  YES   << n - 1 << endl;         continue;       }       long long total = (pow(4, n) - 1) / 3;       if (k > total) {         cout <<  NO  << endl;         continue;       }       long long left;       bool f = 0;       for (long long i = n; i >= 1; i--) {         left = power(2, i + 1) - (i + 2);         long long curr = (2 * (i) + 1) * (power(4, n - i) / 3);         if (total - curr >= k && k >= left) {           cout <<  YES   << n - i << endl;           f = 1;           break;         }       }       if (!f) cout <<  NO n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long a[51][51];   long long combinatorics(long long n, long long k) {     double res = 1;     for (long long i = 1; i <= k; ++i) res = res * (n - k + i) / i;     return (long long)(res + 0.01);   }   int main() {     long long n, m, i, j, numOneRow[51] = {0}, numZeroRow[51] = {0},                           numOneColumn[51] = {0}, numZeroColumn[51] = {0}, x, y;     long long c;     cin >> n >> m;     c = m * n;     for (i = 0; i < n; i++) {       for (j = 0; j < m; j++) {         cin >> a[i][j];         if (a[i][j] == 0) {           numZeroRow[i]++, numZeroColumn[j]++;         } else {           numOneRow[i]++, numOneColumn[j]++;         }       }     }     for (i = 0; i < n; i++) {       j = 2;       x = numOneRow[i], y = numZeroRow[i];       while (x >= j) {         c += combinatorics(x, j);         j++;       }       j = 2;       while (y >= j) {         c += combinatorics(y, j);         j++;       }     }     for (j = 0; j < m; j++) {       i = 2;       x = numOneColumn[j], y = numZeroColumn[j];       while (x >= i) {         c += combinatorics(x, i);         i++;       }       i = 2;       while (y >= i) {         c += combinatorics(y, i);         i++;       }     }     cout << c << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long max(long long a, long long b) {     if (a > b) {       return a;     } else {       return b;     }   }   long long min(long long a, long long b) {     if (a < b) {       return a;     } else {       return b;     }   }   struct P {     double x, y;     P() {}     P(double x, double y) : x(x), y(y) {}     P operator+(const P &a) const { return P(x + a.x, y + a.y); }     P operator-(const P &a) const { return P(x - a.x, y - a.y); }     double operator^(const P &a) const { return x * a.x + y * a.y; }     void in() { scanf( %lf%lf , &x, &y); }     void out() { printf( REQUIRED %.7f %.7f n , x, y); }     double dist(P a, P b) {       return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));     }     double sqdist(P a, P b) {       return (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y);     }   };   int n, m;   int a[300001], b[300001];   int nxt[1000001], dir[1000001], cost[1000001], rev[1000001];   int h;   int visit[300001], c[300001];   int edge[300001];   int l[300001], r[300001];   int lb[300001], ty[1000001];   void insert(int u, int v) {     nxt[++h] = nxt[u];     nxt[u] = h;     dir[h] = v;     nxt[++h] = nxt[v];     nxt[v] = h;     dir[h] = u;   }   void insert2(int u, int v, int id) {     nxt[++h] = nxt[u];     nxt[u] = h;     dir[h] = v;     rev[h] = h + 1;     ty[h] = id;     edge[id] = h;     nxt[++h] = nxt[v];     nxt[v] = h;     dir[h] = u;     rev[h] = h - 1;     ty[h] = -1;   }   void DFS2(int p, int color) {     c[p] = color;     visit[p] = 1;     for (int i = nxt[p]; i > 0; i = nxt[i])       if (visit[dir[i]] == 0) {         DFS2(dir[i], 1 - color);       }   }   int s, t;   int lvl[300001];   int q[300001];   bool BFS() {     for (int i = (1); i <= (2 * n); i++) lvl[i] = -1;     lvl[s] = 0;     int top = 0, tail = 0;     q[top++] = s;     while (top > tail) {       int u = q[tail++];       for (int po = nxt[u]; po > 0; po = nxt[po]) {         if (lvl[dir[po]] == -1 && cost[po] > 0) {           lvl[dir[po]] = lvl[u] + 1;           q[top++] = dir[po];         }       }     }     return (lvl[t] != -1);   }   int DFS(int u, int flow) {     if (u == t) return flow;     int w = flow;     for (int po = nxt[u]; po > 0; po = nxt[po]) {       if (lvl[dir[po]] == lvl[u] + 1 && cost[po]) {         int x = DFS(dir[po], min(w, cost[po]));         w -= x;         cost[po] -= x;         cost[rev[po]] += x;       }     }     if (w == flow) lvl[u] = -3;     return flow - w;   }   int MaxFlow() {     int ans = 0;     int p;     while (BFS()) {       while (p = DFS(s, 99999), p) {         ans += p;       }     }     return ans;   }   set<int> S;   int main() {     scanf( %d%d , &n, &m);     for (int i = (1); i <= (n); i++) nxt[i] = -1;     h = n;     for (int i = (1); i <= (n); i++) scanf( %d , &a[i]);     for (int i = (1); i <= (m); i++) {       scanf( %d%d , &l[i], &r[i]);       insert(l[i], r[i]);     }     for (int i = (1); i <= (n); i++) visit[i] = 0;     for (int i = (1); i <= (n); i++)       if (visit[i] == 0) DFS2(i, 1);     for (int i = (0); i <= (n + 1); i++) nxt[i] = -1;     h = n + 1;     for (int i = (1); i <= (n); i++) {       if (c[i] == 1)         insert2(i, n + 1, i);       else         insert2(0, i, i);     }     for (int i = (1); i <= (m); i++) {       if (c[l[i]] == 1)         insert2(r[i], l[i], 0);       else         insert2(l[i], r[i], 0);     }     for (int i = (1); i <= (n); i++) {       int base = a[i];       for (int j = (2); j <= (sqrt(base)); j++) {         if (base % j == 0) {           S.insert(j);           while (base % j == 0) base /= j;         }       }       if (base != 1) S.insert(base);     }     int ans = 0;     s = 0;     t = n + 1;     for (set<int>::iterator it = S.begin(); it != S.end(); ++it) {       int w = *it;       for (int i = (1); i <= (h); i++) cost[i] = 0;       for (int i = (1); i <= (h); i++)         if (ty[i] == 0) cost[i] = 999;       for (int i = (1); i <= (n); i++) {         b[i] = 0;         int base = a[i];         while (base % w == 0) {           base /= w;           b[i]++;         }         cost[edge[i]] = b[i];       }       ans += MaxFlow();     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e6 + 10;   typedef struct Item {     long long v;     int id;     Item(long long a, int b) {       v = a;       id = b;     }     bool operator<(const Item &rhs) const { return v < rhs.v; }   } Item;   typedef struct Node {     vector<int> p;     vector<Item> pp;     long long sum, r;     int id;     bool operator<(const Node &rhs) const {       return pp.back().v < rhs.pp.back().v;     }   } Node;   int n, m;   Node nd[MAXN];   int bs(int i, int u, int v, long long x) {     if (u > v) return -1;     int mid = u + (v - u) / 2;     if (nd[i].pp[mid].v == x)       return mid;     else if (nd[i].pp[mid].v > x)       return bs(i, u, mid - 1, x);     return bs(i, mid + 1, v, x);   }   int main(void) {     ios::sync_with_stdio(false);     cin.tie(0);     cout << setprecision(10) << fixed;     cin >> n;     for (int i = 0; i < n; i++) {       int k;       cin >> k;       nd[i].sum = 0;       nd[i].id = i + 1;       for (int j = 0; j < k; j++) {         long long v;         cin >> v;         nd[i].sum += v;         nd[i].p.push_back(v);       }       for (int j = 0; j < k; j++)         nd[i].pp.push_back(Item(nd[i].sum - nd[i].p[j], j + 1));       sort(nd[i].pp.begin(), nd[i].pp.end());       nd[i].r = nd[i].pp.back().v;     }     sort(nd, nd + n);     bool found = false;     for (int i = 1; i < n; i++) {       for (int j = i - 1; j >= 0; j--) {         if (nd[j].r < nd[i].pp[0].v) break;         for (int k = 0; k < nd[j].pp.size(); k++) {           int pos = bs(i, 0, nd[i].pp.size() - 1, nd[j].pp[k].v);           if (pos > -1) {             found = true;             cout <<  YES  << endl;             cout << nd[i].id <<     << nd[i].pp[pos].id << endl;             cout << nd[j].id <<     << nd[j].pp[k].id << endl;             break;           }         }         if (found) break;       }       if (found) break;     }     if (!found) cout <<  NO  << endl;     cerr <<  execute time :   << (double)clock() / CLOCKS_PER_SEC << endl;     return 0;   }


#include <bits/stdc++.h>   const int maxn = int(1e5) + 7, mod = int(1e9) + 7;   bool not_prime[maxn];   std::map<int, int> cnt[maxn];   std::vector<int> factor[maxn];   long long qpow(long long p, long long q) {     long long ret = 1;     while (q) {       if (q & 1) ret = ret * p % mod;       p = p * p % mod;       q >>= 1;     }     return ret;   }   void init() {     for (int i = 2; i < maxn; i++) {       for (int j = 2; i * j < maxn; j++) factor[i * j].push_back(i);       if (!not_prime[i]) {         for (int j = 1; i * j < maxn; j++) {           int num = i * j;           not_prime[num] = true;           cnt[num][i] = j;         }       }     }   }   int f[maxn], m;   int calc(int x, int y) {     int ret = m / y, a = x / y, b = m / y;     std::vector<int> buf;     for (auto &it : cnt[a]) {       buf.push_back(it.first);     }     int len = int(buf.size());     for (int i = 1; i < 1 << len; i++) {       int tmp = 1;       for (int j = 0; j < len; j++) {         if ((i >> j) & 1) {           tmp = -tmp * buf[j];         }       }       ret += b / tmp;     }     return ret;   }   int main() {     init();     std::cin >> m;     int inv_m = int(qpow(m, mod - 2)), ans = 1;     for (int i = 2; i <= m; i++) {       f[i] = 1;       for (auto &k : factor[i]) {         f[i] = int((f[i] + 1ll * calc(i, k) * f[k] % mod * inv_m % mod) % mod);       }       f[i] =           int(1ll * f[i] *               qpow((1 - 1ll * (m / i) * inv_m % mod + mod) % mod, mod - 2) % mod);       ans = int((ans + 1ll * f[i] * inv_m % mod) % mod);     }     std::cout << ans << std::endl;     return 0;   }


#include <bits/stdc++.h>   int gcd(int a, int b) {     int r;     while (b != 0) {       r = a % b;       a = b;       b = r;     }     return a;   }   int main() {     int n, m;     int deg1, deg2;     scanf( %d %d , &n, &m);     for (int i = 0, a; i <= n; i++) {       scanf( %d , &a);       if (i == 0) deg1 = a;     }     for (int i = 0, a; i <= m; i++) {       scanf( %d , &a);       if (i == 0) deg2 = a;     }     if (n > m) {       if (deg1 > 0 && deg2 > 0 || (deg1 < 0 && deg2 < 0))         printf( Infinity );       else         printf( -Infinity );     } else if (m > n)       printf( 0/1 );     else {       while (gcd(deg1, deg2) != 1) {         int r = gcd(deg1, deg2);         deg1 /= r;         deg2 /= r;       }       if (deg1 < 0 && deg2 < 0 || (deg1 > 0 && deg2 > 0))         printf( %d/%d , deg1, deg2);       else         printf( -%d/%d , abs(deg1), abs(deg2));     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e5 + 5;   struct node {     int vl, mnvl;     node *l, *r;     node() {       mnvl = MAXN;       vl = -1;       l = r = NULL;     }   };   vector<node*> dv(MAXN);   vector<bool> inarr(MAXN, false);   vector<vector<int>> diverse(MAXN);   deque<int> dbl(int a) {     deque<int> d;     while (a != 0) d.push_front(a % 2), a /= 2;     while (d.size() != 18) d.push_front(0);     return d;   }   void ins(node* d, deque<int> a, int n) {     while (!a.empty()) {       d->mnvl = min(d->mnvl, n);       int b = a.front();       a.pop_front();       if (b == 0) {         if (d->l == NULL) d->l = new node();         d = d->l;       } else {         if (d->r == NULL) d->r = new node();         d = d->r;       }     }     d->vl = n;     d->mnvl = min(d->mnvl, n);   }   int fnd(node* d, deque<int> xd, int s, int x) {     while (!xd.empty()) {       int xx = xd.front();       xd.pop_front();       if (xx == 0)         if (d->r != NULL && d->r->mnvl + x <= s)           d = d->r;         else if (d->l != NULL && d->l->mnvl + x <= s)           d = d->l;         else           return -1;       else if (d->l != NULL && d->l->mnvl + x <= s)         d = d->l;       else if (d->r != NULL && d->r->mnvl + x <= s)         d = d->r;       else         return -1;     }     return d->vl;   }   int main() {     for (int i = 1; i < MAXN; i++)       for (int j = i; j < MAXN; j += i) diverse[j].push_back(i);     for (int i = 1; i < dv.size(); i++) dv[i] = new node();     int n, q, a, x, k, s;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> q;       if (q == 1) {         cin >> a;         if (!inarr[a]) {           inarr[a] = true;           deque<int> d = dbl(a);           for (int i = 0; i < diverse[a].size(); i++)             ins(dv[diverse[a][i]], d, a);         }       } else {         cin >> x >> k >> s;         if (x % k != 0 || s - x <= 0)           cout << -1 << endl;         else           cout << fnd(dv[k], dbl(x), s, x) << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long fast_pow(long long a, long long p) {     long long res = 1;     while (p) {       if (p % 2 == 0) {         a = a * 1LL * a % 1000000007;         p /= 2;       } else {         res = res * 1LL * a % 1000000007;         p--;       }     }     return res;   }   long long fact(long long n) {     long long res = 1;     for (long long i = 1; i <= n; i++) {       res = res * 1LL * i % 1000000007;     }     return res;   }   long long C(long long n, long long k) {     return fact(n) * 1LL * fast_pow(fact(k), 1000000007 - 2) % 1000000007 * 1LL *            fast_pow(fact(n - k), 1000000007 - 2) % 1000000007;   }   vector<long long> sieveOfEratosthenes(long long n) {     vector<long long> primes;     vector<bool> prime(n + 1, true);     for (long long p = 2; p * p <= n; p++) {       if (prime[p] == true) {         for (long long i = p * p; i <= n; i += p) prime[i] = false;       }     }     for (long long p = 2; p <= n; p++)       if (prime[p]) primes.push_back(p);     return primes;   }   bool isPrime(long long n) {     if (n <= 1) return false;     if (n <= 3) return true;     if (n % 2 == 0 || n % 3 == 0) return false;     for (long long i = 5; i * i <= n; i = i + 6)       if (n % i == 0 || n % (i + 2) == 0) return false;     return true;   }   bool isPerfectSquare(long double x) {     if (x >= 0) {       long long sr = sqrt(x);       return (sr * sr == x);     }     return false;   }   long long sum(long long n) {     long long res = 0;     while (n > 0) {       res += n % 10;       n = n / 10;     }     return res;   }   vector<long long> adj[10001];   vector<long long> vis(10001);   vector<long long> col(10001);   void dfs(long long v) {     vis[v] = 1;     for (auto ch : adj[v]) {       if (vis[ch] == 0) {         dfs(ch);       }     }   }   bool bptdfs(long long v, long long c) {     vis[v] = 1;     col[v] = c;     for (auto ch : adj[v]) {       if (vis[ch] == 0) {         if (bptdfs(ch, c ^ 1) == false) {           return false;         }       } else {         if (col[v] == col[ch]) {           return false;         }       }     }     return true;   }   int32_t main() {     ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);     long long t = 1;     while (t--) {       long long n, M;       cin >> n >> M;       vector<long long> t(n);       for (long long i = (0); i <= (n - 1); i++) {         cin >> t[i];       }       vector<long long> ans(n, 0);       for (long long i = (1); i <= (n - 1); i++) {         long long c = 0, sum = 0;         priority_queue<long long> q;         for (long long j = (0); j <= (i); j++) {           sum += t[j];           if (j != i) {             q.push(t[j]);           }         }         if (sum > M) {           while (sum > M) {             long long x = q.top();             q.pop();             sum -= x;             c++;           }         }         ans[i] = c;       }       for (auto x : ans) {         cout << x <<    ;       }       cout << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   class UFDS {    public:     vector<int> p, rank;     int count = 0;     UFDS(int n) {       p.resize(n);       rank.resize(n);       for (int i = 0; i < n; i++) p[i] = i;       count = n;     }     int getParent(int i) { return (p[i] == i) ? i : (p[i] = getParent(p[i])); }     void join(int i, int j) {       int a = getParent(i), b = getParent(j);       if (a == b) return;       count -= 1;       if (rank[a] > rank[b]) {         p[b] = a;       } else {         p[a] = b;         if (rank[a] == rank[b]) rank[b] += 1;       }     }   };   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int n, m;     cin >> n >> m;     set<int> ls, rss;     vector<int> rs;     vector<vector<int> > edges(m, vector<int>(4));     for (int i = 0; i < m; i++) {       cin >> edges[i][2] >> edges[i][3] >> edges[i][0] >> edges[i][1];       ls.insert(edges[i][0]);       if (!rss.count(edges[i][1])) {         rss.insert(edges[i][1]);         rs.push_back(edges[i][1]);       }       edges[i][2] -= 1;       edges[i][3] -= 1;     }     sort(rs.begin(), rs.end());     sort(edges.begin(), edges.end());     int out = 0, prev = 0;     for (auto l : ls) {       int lo = prev, hi = rss.size(), ans = -1;       while (lo < hi) {         int idx = (lo + hi) / 2;         int mid = rs[idx];         UFDS ufds(n);         for (auto e : edges) {           if (e[0] > l) break;           if (e[1] >= mid) ufds.join(e[2], e[3]);         }         if (ufds.getParent(0) == ufds.getParent(n - 1)) {           lo = idx + 1;           ans = mid;           prev = idx;         } else {           hi = idx;         }       }       if (ans != -1) out = max(out, ans - l + 1);     }     if (out)       cout << out;     else       cout <<  Nice work, Dima! ;     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   const long double PI = 3.141592653589793238462643383279502884197;   priority_queue<int, vector<int>, greater<int> > pq;   vector<int> v;   int al[256];   char s[200001], t[200001];   int visit[200001];   int n, m;   int main() {     scanf( %s %s , s, t);     n = strlen(s);     m = strlen(t);     memset(al, -1, sizeof(al));     int l = 0;     for (int i = 0; i < n; i++) {       if (l < m && s[i] == t[l]) {         al[s[i]] = l;         l++;       }       if (al[s[i]] == -1) return !printf( No );       visit[i] = al[s[i]];     }     if (l != m) return !printf( No );     l = m - 1;     memset(al, -1, sizeof(al));     for (int i = n - 1; i >= 0; i--) {       if (l >= 0 && s[i] == t[l]) {         al[s[i]] = l;         l--;       }       if (al[s[i]] == -1) return !printf( No );       if (visit[i] < al[s[i]]) return !printf( No );     }     if (l != -1) return !printf( No );     printf( Yes );   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int a, b, c, p, k;     cin >> a >> b >> c;     if (c != 0) {       p = b - a;       k = p / c;       if (p % c == 0) {         if (k >= 0)           cout <<  YES  << endl;         else           cout <<  NO  << endl;       } else         cout <<  NO  << endl;     } else if (c == 0) {       if (a == b)         cout <<  YES  << endl;       else         cout <<  NO  << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 100005;   int pos[maxn];   int n, x, y;   int main() {     int i, j;     while (scanf( %d , &n) != EOF) {       memset(pos, -1, sizeof(pos));       for (i = 1; i <= n; i++) {         scanf( %d%d , &x, &y);         int ans = 0;         for (j = 1; j * j <= x; j++) {           if (x % j == 0) {             if (y == 0) {               ans++;               pos[j] = i;               if (x / j != j) ans++;               pos[x / j] = i;               continue;             }             if (pos[j] < i - y) ans++;             pos[j] = i;             if (x / j != j && pos[x / j] < i - y) ans++;             pos[x / j] = i;           }         }         printf( %d n , ans);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1000000007;   const int MAX = 5000001;   unsigned int arr[MAX], P[MAX];   void sieve() {     unsigned int i, j, t, k;     arr[0] = arr[1] = 0;     for (i = 2; i < MAX; i++) arr[i] = i;     for (i = 4; i < MAX; i += 2) arr[i] = 2;     for (i = 3; i * i <= MAX; i += 2)       if (arr[i] == i)         for (j = i * i; j < MAX; j += 2 * i)           if (arr[j] == j) arr[j] = i;     for (i = 2; i < 5000001; i++) P[i] = P[i / arr[i]] + 1;     for (i = 2; i < 5000001; i++) P[i] += P[i - 1];   }   int main(void) {     sieve();     unsigned int tc, i, a, b;     scanf( %u , &tc);     for (i = 1; i <= tc; i++) {       scanf( %u %u , &a, &b);       printf( %u n , P[a] - P[b]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int64_t solve(int m, int n) {     if (m > n) swap(m, n);     if (m == 1) {       if (n <= 3) return 0;       if (n % 6 == 2 || n % 6 == 4) return n - 2;       if (n % 6 == 1 || n % 6 == 5) return n - 1;       if (n % 6 == 3) return n - 3;       return n;     }     if (m == 2) {       if (n <= 2) return 0;       if (n == 3) return 4;       if (n == 4) return 8;       if (n == 7) return 12;       return n * 2;     }     int64_t res = 1LL * m * n;     if (res % 2 == 1) res -= 1;     return res;   }   int main() {     int n, m;     cin >> n >> m;     cout << solve(n, m) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline int gi() {     int data = 0, m = 1;     char ch = 0;     while (ch !=  -  && (ch <  0  || ch >  9 )) ch = getchar();     if (ch ==  - ) {       m = 0;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       data = (data << 1) + (data << 3) + (ch ^ 48);       ch = getchar();     }     return (m) ? data : -data;   }   int SS, TT, P0, n, m, K, Init[405], Flow, Cost, A[405], C[405];   struct _Edge {     int to, next, flow;     int cost;   } Edge[3 * 405 * 405];   int head[405], CNT, S, T;   int dis[405], flw[405], frm[405];   bool vis[405];   queue<int> Q;   inline void AddEdge(int u, int v, int fl, int cs) {     Edge[++CNT] = (_Edge){v, head[u], fl, cs};     head[u] = CNT;     Edge[++CNT] = (_Edge){u, head[v], 0, -cs};     head[v] = CNT;   }   inline bool spfa() {     for (int i = 1; i <= TT; ++i) dis[i] = 1e9 + 7;     dis[SS] = 0;     flw[SS] = 1e9;     vis[SS] = true;     Q.push(SS);     while (!Q.empty()) {       int u = Q.front();       Q.pop();       for (int e = head[u]; e; e = Edge[e].next) {         int v = Edge[e].to;         if (Edge[e].flow && dis[v] > dis[u] + Edge[e].cost) {           dis[v] = dis[u] + Edge[e].cost;           frm[v] = e;           flw[v] = min(flw[u], Edge[e].flow);           if (!vis[v]) vis[v] = true, Q.push(v);         }       }       vis[u] = false;     }     if (dis[TT] == 1e9 + 7) return false;     for (int x = TT; x ^ SS; x = Edge[frm[x] ^ 1].to) {       Edge[frm[x]].flow -= flw[TT];       Edge[frm[x] ^ 1].flow += flw[TT];     }     return true;   }   int main() {     n = gi();     K = gi();     CNT = 1;     P0 = 2 * n + 1;     S = P0 + 1;     T = S + 1;     for (int i = 1; i <= n; i++) A[i] = gi();     for (int i = 1; i <= n; i++) C[i] = gi();     AddEdge(S, P0, K, 0);     for (int i = 1; i <= n; ++i)       AddEdge(P0, i, 1, C[A[i]]), AddEdge(i + n, T, 1e9 + 7, 0);     for (int i = 1; i <= n; ++i)       Init[i]--, Init[i + n]++, AddEdge(i, i + n, 1e9 + 7, 0);     for (int i = 1; i <= n; ++i)       for (int j = i + 1; j <= n; ++j)         AddEdge(i + n, j, 1e9 + 7, (A[i] ^ A[j]) ? C[A[j]] : 0);     SS = T + 1;     TT = SS + 1;     int Delay = 0;     for (int i = 1; i <= T; i++)       if (Init[i] < 0)         AddEdge(i, TT, -Init[i], 0);       else if (Init[i] > 0)         AddEdge(SS, i, Init[i], 0), Delay += Init[i];     AddEdge(T, S, 1e9 + 7, 0);     while (spfa()) Flow += flw[TT], Cost += flw[TT] * dis[TT];     if (Flow ^ Delay)       return puts( -1 ), 0;     else       printf( %d n , Cost);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 100002;   map<int, int> cnt[MAX];   vector<int> adj[MAX];   long long ans[MAX];   int color[MAX];   int max_el[MAX];   void dfs(int node, int par) {     cnt[node][color[node]] = true;     max_el[node] = 1;     ans[node] = color[node];     for (int i = 0; i < adj[node].size(); i++) {       int child = adj[node][i];       if (child != par) {         dfs(child, node);         if (cnt[node].size() < cnt[child].size()) {           swap(cnt[node], cnt[child]);           max_el[node] = max_el[child];           ans[node] = ans[child];         }         for (pair<int, int> p : cnt[child]) {           cnt[node][p.first] += p.second;           if (cnt[node][p.first] == max_el[node])             ans[node] += p.first;           else if (cnt[node][p.first] > max_el[node]) {             max_el[node] = cnt[node][p.first];             ans[node] = p.first;           }         }       }     }   }   int main() {     int n, u0, v0;     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> color[i];     }     for (int i = 0; i < n - 1; i++) {       cin >> u0 >> v0;       adj[u0].push_back(v0);       adj[v0].push_back(u0);     }     dfs(1, 0);     for (int i = 1; i <= n; i++) {       cout << ans[i] <<    ;     }   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1000000007;   const long long inv2 = 500000004;   const long long inv6 = 166666668;   const long long inv4 = 250000002;   const long long inv30 = 233333335;   const long long inv12 = 83333334;   const int KKK = 5;   long long ipow(long long b, int e) {     b = b % mod;     long long r = 1;     while (e-- > 0) r = (r * b) % mod;     return r;   }   struct node {     node *lc, *rc;     size_t l, r;     long long v;     int k;     bool flazy;     long long lazy;   };   const int max_n = 100100;   const int max_t = 13 * max_n;   int tn;   node T[max_t], *troot[KKK + 1];   int n, m, a[max_n];   long long C[KKK + 1][KKK + 1];   long long P[max_n][KKK + 1];   long long Q[max_n][KKK + 1];   void lazy(node *x) {     if (x->flazy) {       x->v = (((x->lazy) * ((Q[x->r][x->k] - Q[x->l - 1][x->k] + mod))) % mod);       x->flazy = false;       if (x->l < x->r) {         x->lc->flazy = true;         x->rc->flazy = true;         x->lc->lazy = x->lazy;         x->rc->lazy = x->lazy;       }     }   }   long long query(node *x, size_t ql, size_t qr) {     lazy(x);     if (ql <= x->l && x->r <= qr)       return x->v;     else {       long long ans = 0;       if (ql <= x->lc->r) ans += query(x->lc, ql, qr);       if (qr >= x->rc->l) ans += query(x->rc, ql, qr);       return ans < mod ? ans : ans % mod;     }   }   void modify(node *x, size_t ql, size_t qr, long long v) {     lazy(x);     if (ql <= x->l && x->r <= qr) {       x->flazy = true;       x->lazy = v;       lazy(x);     } else {       if (ql <= x->lc->r) modify(x->lc, ql, qr, v);       if (qr >= x->rc->l) modify(x->rc, ql, qr, v);       lazy(x->lc);       lazy(x->rc);       x->v = x->lc->v + x->rc->v;       x->v = x->v < mod ? x->v : x->v % mod;     }   }   void build(node *x) {     if (x->l == x->r) x->v = (((a[x->l]) * (P[x->l][x->k])) % mod);     if (x->l < x->r) {       int mid = (x->l + x->r) / 2;       x->lc = &T[tn++];       x->lc->l = x->l;       x->lc->r = mid;       x->lc->k = x->k;       build(x->lc);       x->rc = &T[tn++];       x->rc->l = mid + 1;       x->rc->r = x->r;       x->rc->k = x->k;       build(x->rc);       x->v = x->lc->v + x->rc->v;       x->v = x->v < mod ? x->v : x->v % mod;     }   }   int op_query(int l, int r, int k) {     long long ans = 0;     for (int i = 0; i <= k; ++i)       ans = (ans +              ((((((C[k][i]) *                   (((((k - i) & 1 ? mod - 1 : 1) * (P[l - 1][k - i])) % mod))) %                  mod)) *                (query(troot[i], l, r))) %               mod)) %             mod;     return ans % mod;   }   long long iin() {     char c = 0;     long long u = 0;     int b = 1;     while (c <  0  || c >  9 ) {       c = getchar();       if (c ==  - ) b = -1;     }     while (c >=  0  && c <=  9 ) {       u = u * 10 + c -  0 ;       c = getchar();     }     return u;   }   int main() {     for (int k = 0; k <= KKK; ++k) C[k][0] = 1;     for (int k = 1; k <= KKK; ++k)       for (int i = 1; i <= k; ++i)         C[k][i] = (C[k - 1][i] + C[k - 1][i - 1]) % mod;     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; ++i) scanf( %d , &a[i]);     for (int i = 0; i <= n; ++i)       for (int k = 0; k <= KKK; ++k) P[i][k] = ipow(i, k);     for (int k = 0; k <= KKK; ++k)       for (int i = 0, z = 0; i <= n; ++i, z = (z + P[i][k]) % mod) Q[i][k] = z;     for (int i = 0; i <= KKK; ++i) {       troot[i] = &T[tn++];       troot[i]->k = i;       troot[i]->l = 1;       troot[i]->r = n;       build(troot[i]);     }     for (int i = 0; i < m; ++i) {       char op[10];       scanf( %s , op);       if (op[0] ==  ? ) {         int l, r, k;         scanf( %d%d%d , &l, &r, &k);         int ans = op_query(l, r, k);         printf( %d n , ans);       }       if (op[0] ==  = ) {         int l, r, x;         scanf( %d%d%d , &l, &r, &x);         for (int k = 0; k <= KKK; ++k) modify(troot[k], l, r, x);       }     }     return 0;   }