#include <bits/stdc++.h>   using namespace std;   string to_string(string s) { return     + s +    ; }   string to_string(const char *s) { return to_string((string)s); }   string to_string(bool b) { return (b ?  true  :  false ); }   template <typename A, typename B>   string to_string(pair<A, B> p) {     return  (  + to_string(p.first) +  ,   + to_string(p.second) +  ) ;   }   template <typename A>   string to_string(A v) {     bool first = true;     string res =  { ;     for (const auto &x : v) {       if (!first) {         res +=  ,  ;       }       first = false;       res += to_string(x);     }     res +=  } ;     return res;   }   void debug_out() { cerr << endl; }   template <typename Head, typename... Tail>   void debug_out(Head H, Tail... T) {     cerr <<     << to_string(H);     debug_out(T...);   }   const int md = (int)1e9 + 7;   inline void add(int &a, int b) {     a += b;     if (a >= md) a -= md;   }   inline void sub(int &a, int b) {     a -= b;     if (a < 0) a += md;   }   inline int mul(int a, int b) {     return (int)((long long)a * b % md);     unsigned long long x = (long long)a * b;     unsigned xh = (unsigned)(x >> 32), xl = (unsigned)x, d, m;     asm( divl %4;  n t  :  =a (d),  =d (m) :  d (xh),  a (xl),  r (md));     return m;   }   inline int power(int a, long long b) {     int res = 1;     while (b > 0) {       if (b & 1) {         res = mul(res, a);       }       a = mul(a, a);       b >>= 1;     }     return res;   }   inline int inv(int a) {     a %= md;     if (a < 0) a += md;     int b = md, u = 0, v = 1;     while (a) {       int t = b / a;       b -= t * a;       swap(a, b);       u -= t * v;       swap(u, v);     }     assert(b == 1);     if (u < 0) u += md;     return u;   }   template <typename T>   class graph {    public:     struct edge {       int from;       int to;       T cost;     };     vector<edge> edges;     vector<vector<int>> g;     int n;     function<bool(int)> ignore;     graph(int _n) : n(_n) {       g.resize(n);       ignore = nullptr;     }     virtual int add(int from, int to, T cost) = 0;     virtual void set_ignore_edge_rule(const function<bool(int)> &f) {       ignore = f;     }     virtual void reset_ignore_edge_rule() { ignore = nullptr; }   };   template <typename T>   class forest : public graph<T> {    public:     using graph<T>::edges;     using graph<T>::g;     using graph<T>::n;     forest(int _n) : graph<T>(_n) {}     int add(int from, int to, T cost = 1) {       assert(0 <= from && from < n && 0 <= to && to < n);       int id = (int)edges.size();       assert(id < n - 1);       g[from].push_back(id);       g[to].push_back(id);       edges.push_back({from, to, cost});       return id;     }   };   template <typename T>   class dfs_forest : public forest<T> {    public:     using forest<T>::edges;     using forest<T>::g;     using forest<T>::n;     using forest<T>::ignore;     vector<int> pv;     vector<int> pe;     vector<int> order;     vector<int> pos;     vector<int> end;     vector<int> sz;     vector<int> root;     vector<int> depth;     vector<T> dist;     dfs_forest(int _n) : forest<T>(_n) {}     void init() {       pv = vector<int>(n, -1);       pe = vector<int>(n, -1);       order.clear();       pos = vector<int>(n, -1);       end = vector<int>(n, -1);       sz = vector<int>(n, 0);       root = vector<int>(n, -1);       depth = vector<int>(n, -1);       dist = vector<T>(n);     }     void clear() {       pv.clear();       pe.clear();       order.clear();       pos.clear();       end.clear();       sz.clear();       root.clear();       depth.clear();       dist.clear();     }       private:     void do_dfs(int v) {       pos[v] = (int)order.size();       order.push_back(v);       sz[v] = 1;       for (int id : g[v]) {         if (id == pe[v] || (ignore != nullptr && ignore(id))) {           continue;         }         auto &e = edges[id];         int to = e.from ^ e.to ^ v;         depth[to] = depth[v] + 1;         dist[to] = dist[v] + e.cost;         pv[to] = v;         pe[to] = id;         root[to] = (root[v] != -1 ? root[v] : to);         do_dfs(to);         sz[v] += sz[to];       }       end[v] = (int)order.size() - 1;     }     void do_dfs_from(int v) {       depth[v] = 0;       dist[v] = T{};       root[v] = v;       pv[v] = pe[v] = -1;       do_dfs(v);     }       public:     void dfs(int v, bool clear_order = true) {       if (pv.empty()) {         init();       } else {         if (clear_order) {           order.clear();         }       }       do_dfs_from(v);     }     void dfs_all() {       init();       for (int v = 0; v < n; v++) {         if (depth[v] == -1) {           do_dfs_from(v);         }       }       assert((int)order.size() == n);     }   };   template <typename T>   class lca_forest : public dfs_forest<T> {    public:     using dfs_forest<T>::edges;     using dfs_forest<T>::g;     using dfs_forest<T>::n;     using dfs_forest<T>::pv;     using dfs_forest<T>::pos;     using dfs_forest<T>::end;     using dfs_forest<T>::depth;     int h;     vector<vector<int>> pr;     lca_forest(int _n) : dfs_forest<T>(_n) {}     inline void build_lca() {       assert(!pv.empty());       int max_depth = 0;       for (int i = 0; i < n; i++) {         max_depth = max(max_depth, depth[i]);       }       h = 1;       while ((1 << h) <= max_depth) {         h++;       }       pr.resize(n);       for (int i = 0; i < n; i++) {         pr[i].resize(h);         pr[i][0] = pv[i];       }       for (int j = 1; j < h; j++) {         for (int i = 0; i < n; i++) {           pr[i][j] = (pr[i][j - 1] == -1 ? -1 : pr[pr[i][j - 1]][j - 1]);         }       }     }     inline bool anc(int x, int y) {       return (pos[x] <= pos[y] && end[y] <= end[x]);     }     inline int lca(int x, int y) {       assert(!pr.empty());       if (anc(x, y)) {         return x;       }       if (anc(y, x)) {         return y;       }       for (int j = h - 1; j >= 0; j--) {         if (pr[x][j] != -1 && !anc(pr[x][j], y)) {           x = pr[x][j];         }       }       return pr[x][0];     }   };   template <typename T>   class fenwick {    public:     vector<T> fenw;     int n;     fenwick(int _n) : n(_n) { fenw.resize(n); }     void modify(int x, T v) {       while (x < n) {         fenw[x] += v;         x |= (x + 1);       }     }     T get(int x) {       T v{};       while (x >= 0) {         v += fenw[x];         x = (x & (x + 1)) - 1;       }       return v;     }   };   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     const int MAX = (int)1e7 + 10;     vector<int> prime_div(MAX);     for (int i = 0; i < MAX; i++) {       prime_div[i] = i;     }     for (int i = 2; i * i < MAX; i++) {       if (prime_div[i] == i) {         for (int j = i * i; j < MAX; j += i) {           if (prime_div[j] == j) {             prime_div[j] = i;           }         }       }     }     vector<int> pos(MAX);     vector<int> primes;     for (int i = 2; i < MAX; i++) {       if (prime_div[i] == i) {         pos[i] = (int)primes.size();         primes.push_back(i);       }     }     vector<vector<pair<int, int>>> at(primes.size());     int n;     cin >> n;     lca_forest<int> g(n);     for (int i = 0; i < n - 1; i++) {       int x, y;       cin >> x >> y;       x--;       y--;       g.add(x, y);     }     g.dfs(0);     g.build_lca();     for (int i = 0; i < n; i++) {       int foo;       cin >> foo;       while (foo > 1) {         int d = prime_div[foo];         int cc = 0;         while (foo % d == 0) {           foo /= d;           cc++;         }         at[pos[d]].emplace_back(cc, i);       }     }     int tt;     cin >> tt;     vector<int> u(tt), v(tt), lca(tt);     vector<int> res(tt, 1);     for (int i = 0; i < tt; i++) {       int foo;       cin >> u[i] >> v[i] >> foo;       u[i]--;       v[i]--;       lca[i] = g.lca(u[i], v[i]);       while (foo > 1) {         int d = prime_div[foo];         int cc = 0;         while (foo % d == 0) {           foo /= d;           cc++;         }         for (int j = 1; j <= cc; j++) {           at[pos[d]].emplace_back(j, ~i);         }       }     }     fenwick<int> fenw(n);     for (int it = 0; it < (int)primes.size(); it++) {       if (at[it].empty()) {         continue;       }       sort(at[it].rbegin(), at[it].rend());       for (auto &p : at[it]) {         int id = p.second;         if (id >= 0) {           fenw.modify(g.pos[id], 1);           fenw.modify(g.end[id] + 1, -1);         } else {           id = ~id;           int cnt = fenw.get(g.pos[u[id]]) + fenw.get(g.pos[v[id]]) -                     fenw.get(g.pos[lca[id]]);           if (lca[id] != 0) {             cnt -= fenw.get(g.pos[g.pv[lca[id]]]);           }           res[id] = mul(res[id], power(primes[it], cnt));         }       }       for (auto &p : at[it]) {         int id = p.second;         if (id >= 0) {           fenw.modify(g.pos[id], -1);           fenw.modify(g.end[id] + 1, +1);         }       }     }     for (int i = 0; i < tt; i++) {       cout << res[i] <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 105000;   int a[maxn], ans[maxn];   int n, p, res1, res2;   bool judge1(int k) {     int sum = 0;     for (int i = 1; i <= n; i++) {       if (a[i] <= k)         sum++;       else {         int tmp = a[i] - k;         sum -= tmp;         if (sum < 0) return 0;         k += tmp;         sum++;       }     }     return 1;   }   bool judge2(int k) {     int sum = 0;     for (int i = 1; i <= n; i++) {       if (a[i] <= k) {         sum++;         if (sum >= p) return 0;       } else {         int tmp = a[i] - k;         sum -= tmp;         k += tmp;         sum++;       }     }     return 1;   }   void solve() {     scanf( %d %d , &n, &p);     int max_v = 0;     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);       max_v = max(max_v, a[i]);     }     sort(a + 1, a + n + 1);     int l = 1, r = max_v;     while (l <= r) {       int mid = l + r >> 1;       if (judge1(mid))         r = mid - 1;       else         l = mid + 1;     }     res1 = l;     r = max_v;     while (l <= r) {       int mid = l + r >> 1;       if (judge2(mid))         l = mid + 1;       else         r = mid - 1;     }     res2 = r;     printf( %d n , res2 - res1 + 1);     for (int i = res1; i <= res2; i++) printf( %d  , i);     printf(  n );   }   int main() {     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int b[1100000], a[1100000], pre[1100000];   int main() {     int n, m, k, i, j, s, cnt, len = 0, max = 0;     long long ans = 0;     scanf( %d%d%d , &n, &m, &k);     for (i = 1; i <= m; ++i) {       scanf( %d , &s);       b[s] = 1;     }     b[n] = 1;     for (i = 1; i < n; ++i)       if (b[i])         pre[i] = pre[i - 1];       else         pre[i] = i;     for (i = 1; i < n; ++i) {       if (b[i])         ++len;       else         len = 0;       if (len > max) max = len;     }     for (i = 1; i <= k; ++i) scanf( %d , &a[i]);     if (max == 0)       max = 1;     else       ++max;     for (i = max; i <= k; ++i) {       cnt = 0;       j = 0;       if (b[j]) continue;       while (j < n) {         ++cnt;         if (!b[j])           j = j + i;         else           j = pre[j] + i;       }       if (ans == 0)         ans = (long long)cnt * a[i];       else if ((long long)cnt * a[i] < ans)         ans = (long long)cnt * a[i];     }     if (ans > 0)       printf( %I64d , ans);     else       printf( -1 );     return 0;   }


#include <bits/stdc++.h>   int main() {     std::ios::sync_with_stdio(false);     std::cin.tie(nullptr);     int32_t n, m, k;     std::cin >> n >> m >> k;     if (n % 2 == 0) {       std::cout <<  Marsel n ;     } else {       bool avail = k == 1;       for (int32_t i = 2; i * i <= m; ++i) {         if (m % i == 0) {           avail |= m / i >= k;           break;         }       }       if (m >= k * 2 && avail) {         std::cout <<  Timur n ;       } else {         std::cout <<  Marsel n ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1 << 19;   const double PI = acos(-1);   int n, x;   int a[N];   vector<long long> f, g, h;   long long res[N];   int rev[N];   void calc_rev(int n, int logn) {     for (int i = 0; i < n; ++i) {       rev[i] = 0;       for (int j = 0; j < logn; ++j)         if (i >> j & 1) {           rev[i] |= 1 << logn - j - 1;         }     }   }   void fft(complex<double> a[], int n, bool invert) {     for (int i = 0; i < n; ++i)       if (i < rev[i]) {         swap(a[i], a[rev[i]]);       }     for (int len = 2; len <= n; len <<= 1) {       double alpha = 2 * PI / len * (invert ? -1 : 1);       complex<double> wl = complex<double>(cos(alpha), sin(alpha));       for (int i = 0; i < n; i += len) {         complex<double> w = complex<double>(1);         for (int j = 0; j < (len >> 1); ++j) {           complex<double> u = a[i + j], v = a[i + j + (len >> 1)] * w;           a[i + j] = u + v;           a[i + j + (len >> 1)] = u - v;           w *= wl;         }       }     }     if (invert)       for (int i = 0; i < n; ++i) a[i] /= n;   }   vector<long long> mult(vector<long long> a, vector<long long> b) {     static complex<double> fa[N], fb[N], fc[N];     int na = a.size(), nb = b.size();     int n = 1, logn = 0;     while (n < max(na, nb)) n <<= 1, logn++;     n <<= 1, logn++;     calc_rev(n, logn);     for (int i = 0; i < n; ++i) fa[i] = fb[i] = complex<double>(0);     for (int i = 0; i < na; ++i) fa[i] = complex<double>(a[i]);     for (int i = 0; i < nb; ++i) fb[i] = complex<double>(b[i]);     fft(fa, n, false);     fft(fb, n, false);     for (int i = 0; i < n; ++i) fc[i] = fa[i] * fb[i];     fft(fc, n, true);     vector<long long> res;     for (int i = 0; i < na + nb - 1; ++i)       res.push_back((long long)(fc[i].real() + 0.5));     return res;   }   int main() {     ios_base::sync_with_stdio(false);     cin >> n >> x;     f.assign(n + 1, 0), g.assign(n + 1, 0);     f[0] = g[n] = 1;     for (int i = 1; i <= n; ++i) {       cin >> a[i];       a[i] = a[i - 1] + (a[i] < x);       f[a[i]]++, g[n - a[i]]++;     }     h = mult(f, g);     for (int i = 0; i <= n; ++i) res[0] += f[i] * (f[i] - 1) / 2;     for (int i = 1; i <= n; ++i) res[i] = h[i + n];     for (int i = 0; i <= n; ++i) cout << res[i] <<    ;     cout <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, k, cla[30], a[200 + 5], hd[2 * 200 + 5], len = 0;   char s[30];   struct Edge {     int v, net;   } e[2 * 160000 + 5];   void addi(int u, int v) {     e[len] = (Edge){v, hd[u]};     hd[u] = len++;   }   void add(int u, int v) {     addi(u, v);     addi(v <= n ? n + v : v - n, u <= n ? n + u : u - n);   }   template <class T>   void read(T &x) {     char ch;     bool ok;     for (ok = 0, ch = getchar(); !isdigit(ch); ch = getchar())       if (ch ==  - ) ok = 1;     for (x = 0; isdigit(ch); x = x * 10 + ch -  0 , ch = getchar())       ;     if (ok) x = -x;   }   int col[200 + 5], col_cpy[200 + 5];   bool dfs(int u, int ty) {     if (col_cpy[u] != -1) return col_cpy[u] == ty;     col_cpy[u] = ty;     for (int i = hd[ty * n + u]; ~i; i = e[i].net) {       int v = e[i].v;       if (!(v > n ? dfs(v - n, 1) : dfs(v, 0))) return 0;     }     return 1;   }   int fl = 0, mx[2];   bool chk(int x, int ty) {     if (fl || ty) return 1;     for (int i = (x), en = (n); i <= en; ++i) {       if (col_cpy[i] == -1) {         if (mx[!cla[a[i]]] > a[i]) return 1;         continue;       }       if (mx[col_cpy[i]] > a[i]) return 1;       if (mx[col_cpy[i]] < a[i]) return 0;     }     return 1;   }   bool chk(int x, int ty, int tty) {     memcpy(col_cpy, col, sizeof col);     if (dfs(x, ty) && chk(x + 1, tty)) {       memcpy(col, col_cpy, sizeof col_cpy);       return 1;     }     return 0;   }   int as[200 + 5];   int main() {     memset(hd, -1, sizeof hd);     scanf( %s , s + 1);     k = strlen(s + 1);     int mn = 0;     for (int i = (1), en = (k); i <= en; ++i) {       cla[i] = s[i] ==  C ;       if (cla[i] != cla[1] && !mn) mn = i;       mx[cla[i]] = max(mx[cla[i]], i);     }     read(n);     read(m);     for (int i = (1), en = (m); i <= en; ++i) {       int x, y, xx, yy;       char c;       read(x);       cin >> c;       y = c ==  C ;       read(xx);       cin >> c;       yy = c ==  C ;       add(x + n * y, xx + n * yy);       if (y != yy && !mx[yy]) {         puts( -1 );         return 0;       }     }     memset(col, -1, sizeof col);     for (int i = (1), en = (n); i <= en; ++i) {       char c;       cin >> c;       a[i] = c -  a  + 1;     }     for (int i = (1), en = (n); i <= en; ++i) {       if (fl) {         if (chk(i, cla[1], 1))           as[i] = 1;         else if (chk(i, !cla[1], 1))           as[i] = mn;         else {           puts( -1 );           return 0;         }       } else {         int tem = 0, tem1 = 0;         for (int j = (a[i] + 1), en = (k); j <= en; ++j) {           if (cla[j] != cla[a[i]]) {             if (!tem) tem = j;           } else {             if (!tem1) tem1 = j;           }         }         if (chk(i, cla[a[i]], 0))           as[i] = a[i];         else {           if (tem > tem1) swap(tem, tem1);           if (tem && chk(i, cla[tem], 1))             as[i] = tem;           else if (tem1 && chk(i, cla[tem1], 1))             as[i] = tem1;           else {             puts( -1 );             return 0;           }         }       }       fl |= as[i] > a[i];     }     for (int i = (1), en = (n); i <= en; ++i) putchar( a  + as[i] - 1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct Exam {     int s, d, c, id;     bool operator<(const Exam &e1) const { return d < e1.d; }   };   const int N = 105;   int n, m, to[N];   Exam e[N];   int main() {     cin >> n >> m;     for (int i = 1; i <= m; i++) {       cin >> e[i].s >> e[i].d >> e[i].c;       e[i].id = i;       to[e[i].d] = m + 1;     }     sort(e + 1, e + m + 1);     for (int i = 1; i <= m; i++) {       int cnt = 0;       for (int j = e[i].s; j < e[i].d; j++) {         if (to[j] == 0) {           to[j] = e[i].id;           if (++cnt == e[i].c) break;         }       }       if (cnt < e[i].c) {         cout << -1 << endl;         return 0;       }     }     for (int i = 1; i <= n; i++) cout << to[i] <<    ;     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const long long INFF = 0x3f3f3f3f3f3f3f3fll;   const long long M = 1e9 + 7;   const long long maxn = 5007;   const double eps = 0.00000001;   long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   template <typename T>   inline T abs(T a) {     return a > 0 ? a : -a;   }   template <typename T>   inline T powMM(T a, T b) {     T ret = 1;     for (; b; b >>= 1ll, a = a * a % M) ret = 1ll * ret * a % M;     return ret;   }   vector<int> edge[maxn];   vector<long long> dp1[maxn], dp2[maxn];   long long now1[maxn], now2[maxn];   long long a[maxn], b[maxn], m;   int num[maxn], ans;   void dfs(int x) {     num[x] = 1;     dp1[x].resize(maxn, INFF);     dp2[x].resize(maxn, INFF);     dp1[x][1] = a[x];     dp1[x][0] = 0;     dp2[x][1] = a[x] - b[x];     dp2[x][0] = INFF;     int i, j;     for (int v : edge[x]) {       dfs(v);       for (i = 0; i <= num[x]; i++) now1[i] = dp1[x][i], now2[i] = dp2[x][i];       for (i = 0; i <= num[x]; i++)         for (j = 1; j <= num[v]; j++) {           dp1[x][i + j] = min(dp1[x][i + j], now1[i] + dp1[v][j]);           dp2[x][i + j] = min(dp2[x][i + j], now2[i] + min(dp1[v][j], dp2[v][j]));         }       vector<long long>().swap(dp1[v]);       vector<long long>().swap(dp2[v]);       num[x] += num[v];     }   }   int n;   int i, j, k;   int main() {     scanf( %d%I64d , &n, &m);     for (i = 1; i <= n; i++) {       scanf( %I64d%I64d , &a[i], &b[i]);       if (i != 1) {         int v;         scanf( %d , &v);         edge[v].push_back(i);       };     }     dfs(1);     ans = 0;     for (i = 1; i <= n; i++)       if (dp1[1][i] <= m || dp2[1][i] <= m) ans = max(ans, i);     printf( %d , ans);   }


#include <bits/stdc++.h>   const double PI = acos(-1);   using namespace std;   template <class T>   ostream& operator<<(ostream& out, vector<T> v) {     out << v.size() <<   n ;     for (auto e : v) out << e <<   n ;     return out;   }   struct point {     long long x, y;     point() {}     point(const point& a) { x = a.x, y = a.y; }     point(long long _x, long long _y) {       x = _x;       y = _y;     }     point operator-(point a) { return point(x - a.x, y - a.y); }     point operator+(point a) { return point(x + a.x, y + a.y); }   };   ostream& operator<<(ostream& out, point p) {     return out <<  (  << p.x <<     << p.y <<  ) ;   }   long double dist(point a, point b) {     long double X = a.x - b.x;     long double Y = a.y - b.y;     return sqrt(X * X + Y * Y);   }   istream& operator>>(istream& in, point& p) { return in >> p.x >> p.y; }   long double area(point a, point b, point c) {     return a.x * b.y + b.x * c.y + c.x * a.y - a.y * b.x - b.y * c.x - c.y * a.x;   }   const long long N = 100100;   point p1, p2, p[N];   long long n, k, use[N];   vector<pair<long long, long long> > v[5];   long long lg(long long a) {     if (a % 2 == 1) a++;     a /= 2;     return max(1LL, a);   }   int main() {     ios_base::sync_with_stdio(false);     cin >> n >> k;     for (long long i = 1; i <= n; i++) {       cin >> p1 >> p2;       p[i] = p1 + p2;     }     for (long long i = 1; i <= n; i++) {       v[0].push_back({p[i].x, i});       v[1].push_back({p[i].x, i});     }     for (long long i = 1; i <= n; i++) {       v[2].push_back({p[i].y, i});       v[3].push_back({p[i].y, i});     }     sort(v[0].begin(), v[0].end());     sort(v[1].begin(), v[1].end(), greater<pair<long long, long long> >());     sort(v[2].begin(), v[2].end());     sort(v[3].begin(), v[3].end(), greater<pair<long long, long long> >());     long long ans = 1e18 + 100;     for (long long i = 0; i < (1 << (2 * k)); i++) {       long long order[12], msk = i, used[12];       for (long long j = 1; j <= k; j++) {         order[j] = msk % 4;         msk /= 4;       }       long long d[] = {v[0][0].first, v[1][0].first, v[2][0].first,                        v[3][0].first};       for (long long j = 1; j <= k; j++) {         long long p = order[j], ind = 0;         while (use[v[order[j]][ind].second]) ind++;         use[v[p][ind].second] = 1;         used[j] = v[p][ind].second;       }       for (int j = 0; j < 4; j++) {         int ind = 0;         while (use[v[j][ind].second]) ind++;         d[j] = v[j][ind].first;       }       ans = min(ans, lg(d[1] - d[0]) * lg(d[3] - d[2]));       for (long long j = 1; j <= k; j++) use[used[j]] = 0;     }     cout << ans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   string s[51];   int n, m;   bool check(int i, int j) {     for (int k = 1; k <= n; ++k)       if (s[k][j] ==  #  && s[k] != s[i]) return false;     return true;   }   signed main() {     ios::sync_with_stdio(false);     cin >> n >> m;     for (int i = 1; i <= n; ++i) cin >> s[i];     for (int i = 1; i <= n; ++i)       for (int j = 0; j <= m - 1; ++j)         if (s[i][j] ==  # )           if (!check(i, j)) {             cout <<  No ;             return 0;           }     cout <<  Yes ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   T gcd(T a, T b) {     while (a > 0 && b > 0) {       if (a > b)         a %= b;       else         b %= a;     }     return a + b;   }   void YES_NO(bool YES_NO, bool isExit = true) {     if (YES_NO)       cout <<  YES  << endl;     else       cout <<  NO  << endl;     if (isExit) {       exit(0);     }   }   void Yes_No(bool Yes_No, bool isExit = true) {     if (Yes_No)       cout <<  Yes  << endl;     else       cout <<  No  << endl;     if (isExit) {       exit(0);     }   }   void yes_no(bool yes_no, bool isExit = true) {     if (yes_no)       cout <<  yes  << endl;     else       cout <<  no  << endl;     if (isExit) {       exit(0);     }   }   int main() {     string s, t;     cin >> s;     cin >> t;     int cnt = 0;     for (int i = 0; i < s.size(); ++i) {       if (s[i] != t[i]) {         ++cnt;       }     }     if (cnt % 2 == 1) {       cout <<  impossible  << endl;       return 0;     }     cnt /= 2;     string ans = s;     for (int i = 0; i < s.size(); ++i) {       if (s[i] != t[i] && cnt) {         ans[i] = t[i];         --cnt;       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   int r, g, b;   int mins;   int total;   int tour;   int cycles;   int main() {     scanf( %d %d %d , &r, &g, &b);     if (r >= 2) {       r -= 2;     } else if (r == 1) {       r -= 1;     }     mins = 30;     tour = 1;     total = r + g + b;     while (total > 0) {       if (tour == 1) {         if (g >= 2) {           g -= 2;         } else if (g == 1) {           g -= 1;         }         tour = 2;       } else if (tour == 2) {         if (b >= 2) {           b -= 2;         } else if (b == 1) {           b -= 1;         }         tour = 0;       } else if (tour == 0) {         if (r >= 2) {           r -= 2;         } else if (r == 1) {           r -= 1;         }         tour = 1;       }       total = r + g + b;       cycles++;     }     mins += cycles;     printf( %d , mins);   }


#include <bits/stdc++.h>   using namespace std;   int cap[1000000], flow[1000000];   int to[1000000], _prev[1000000], last[10000], used[10000], level[10000];   struct MaxFlow {     int V, E;     MaxFlow(int n) {       int i;       V = n;       E = 0;       for ((i) = 0; (i) < (int)(V); (i)++) last[i] = -1;     }     void add_edge(int x, int y, int f) {       cap[E] = f;       flow[E] = 0;       to[E] = y;       _prev[E] = last[x];       last[x] = E;       E++;       cap[E] = 0;       flow[E] = 0;       to[E] = x;       _prev[E] = last[y];       last[y] = E;       E++;     }     bool bfs(int s, int t) {       int i;       for ((i) = 0; (i) < (int)(V); (i)++) level[i] = -1;       queue<int> q;       q.push(s);       level[s] = 0;       while (!q.empty()) {         int x = q.front();         q.pop();         for (i = last[x]; i >= 0; i = _prev[i])           if (level[to[i]] == -1 && cap[i] > flow[i]) {             q.push(to[i]);             level[to[i]] = level[x] + 1;           }       }       return (level[t] != -1);     }     int dfs(int v, int t, int f) {       int i;       if (v == t) return f;       for (i = used[v]; i >= 0; used[v] = i = _prev[i])         if (level[to[i]] > level[v] && cap[i] > flow[i]) {           int tmp = dfs(to[i], t, min(f, cap[i] - flow[i]));           if (tmp > 0) {             flow[i] += tmp;             flow[i ^ 1] -= tmp;             return tmp;           }         }       return 0;     }     int maxflow(int s, int t) {       int i;       while (bfs(s, t)) {         for ((i) = 0; (i) < (int)(V); (i)++) used[i] = last[i];         while (dfs(s, t, (1 << 29)) != 0)           ;       }       int ans = 0;       for (i = last[s]; i >= 0; i = _prev[i]) ans += flow[i];       return ans;     }   };   int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1};   int X, Y;   string board[30];   int dist[30][30][30][30];   int A, B;   int cx, cy, ct;   int ax[500], ay[500], at[500];   int bx[500], by[500], bt[500];   queue<int> q;   void bfs(int s, int t) {     int i, j;     for ((i) = 0; (i) < (int)(X); (i)++)       for ((j) = 0; (j) < (int)(Y); (j)++) dist[s][t][i][j] = (1 << 29);     if (board[s][t] ==  # ) return;     dist[s][t][s][t] = 0;     q.push(s);     q.push(t);     while (!q.empty()) {       int x = q.front();       q.pop();       int y = q.front();       q.pop();       for ((i) = 0; (i) < (int)(4); (i)++) {         int x2 = x + dx[i], y2 = y + dy[i];         if (x2 >= 0 && x2 < X && y2 >= 0 && y2 < Y && board[x2][y2] !=  #  &&             dist[s][t][x2][y2] == (1 << 29)) {           dist[s][t][x2][y2] = dist[s][t][x][y] + 1;           q.push(x2);           q.push(y2);         }       }     }   }   bool check(long long T) {     int i, j, k;     MaxFlow mf(A + A + 2 * (X * Y) + 2);     int V = A + A + 2 * (X * Y) + 2;     for ((i) = 0; (i) < (int)(A); (i)++) mf.add_edge(V - 2, i, 1);     for ((i) = 0; (i) < (int)(A); (i)++) mf.add_edge(A + i, V - 1, 1);     for ((i) = 0; (i) < (int)(X * Y); (i)++)       mf.add_edge(A + A + i, A + A + X * Y + i, 1);     for ((i) = 0; (i) < (int)(A); (i)++)       for ((j) = 0; (j) < (int)(X); (j)++)         for ((k) = 0; (k) < (int)(Y); (k)++) {           int d = dist[ax[i]][ay[i]][j][k];           if (d != (1 << 29) && (long long)d * at[i] <= T)             mf.add_edge(i, A + A + j * Y + k, 1);         }     for ((i) = 0; (i) < (int)(A); (i)++)       for ((j) = 0; (j) < (int)(X); (j)++)         for ((k) = 0; (k) < (int)(Y); (k)++) {           int d = dist[bx[i]][by[i]][j][k];           if (d != (1 << 29) && (long long)d * bt[i] <= T)             mf.add_edge(A + A + X * Y + j * Y + k, A + i, 1);         }     int f = mf.maxflow(V - 2, V - 1);     return (f == A);   }   int main(void) {     int i, j;     cin >> X >> Y >> A >> B;     for ((i) = 0; (i) < (int)(X); (i)++) cin >> board[i];     for ((i) = 0; (i) < (int)(X); (i)++)       for ((j) = 0; (j) < (int)(Y); (j)++) bfs(i, j);     cin >> cx >> cy >> ct;     for ((i) = 0; (i) < (int)(A); (i)++) cin >> ax[i] >> ay[i] >> at[i];     for ((i) = 0; (i) < (int)(B); (i)++) cin >> bx[i] >> by[i] >> bt[i];     cx--;     cy--;     for ((i) = 0; (i) < (int)(A); (i)++) {       ax[i]--;       ay[i]--;     }     for ((i) = 0; (i) < (int)(B); (i)++) {       bx[i]--;       by[i]--;     }     if (A < B) {       ax[A] = cx;       ay[A] = cy;       at[A] = ct;       A++;     } else {       bx[B] = cx;       by[B] = cy;       bt[B] = ct;       B++;     }     if (A != B) {       cout << -1 << endl;       return 0;     }     long long low = -1, high = (1ll << 40);     while (high - low > 1) {       long long mid = (low + high) / 2;       if (check(mid))         high = mid;       else         low = mid;     }     if (high == (1ll << 40)) high = -1;     cout << high << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1e9;   const long long LINF = 1e18;   int n, m, k;   bool noted[13];   bool connected[13][13];   int cnt = 0;   set<long long> st;   set<set<int>> sets;   vector<int> vec[13];   long long pw[13];   bool visitedd[13];   map<long long, bool> visiteddd[13][13];   void bruteforce_string(int u, int v, int d, long long code) {     if (d == n / 2) {       if (!connected[u][v]) return;       cnt++;       st.insert(code);       return;     }     for (int x : vec[u])       for (int y : vec[v]) {         if (x == y) continue;         if (visitedd[x] || visitedd[y]) continue;         long long nx = min(x, y);         long long ny = max(x, y);         long long ncode = code + (ny << (4LL * nx));         if (!visiteddd[nx][ny][ncode]) {           visiteddd[nx][ny][ncode] = 1;           visitedd[x] = 1;           visitedd[y] = 1;           bruteforce_string(nx, ny, d + 1, ncode);           visitedd[x] = 0;           visitedd[y] = 0;         }       }   }   int cnt2 = 0;   map<set<int>, bool> visited;   void bruteforce_striling(set<int> st) {     visited[st] = 1;     if (st.size() == 1) return;     for (auto it = st.begin(); it != st.end(); it++) {       auto jt = it;       ++jt;       for (; jt != st.end(); jt++) {         set<int> nt = st;         nt.erase(*it);         nt.erase(*jt);         nt.insert(*it + *jt);         if (!visited[nt]) bruteforce_striling(nt);       }     }   }   long long P(int n, int k) {     long long res = 1;     for (int i = 0; i < k; i++) res = (res * (n - i));     return res;   }   int main() {     pw[0] = 1;     for (int i = 1; i <= 12; i++) pw[i] = pw[i - 1] * 13;     scanf( %d %d %d n , &n, &m, &k);     for (int i = 1; i <= m; i++) {       int u, v;       scanf( %d %d , &u, &v);       vec[u].push_back(v);       vec[v].push_back(u);       connected[u][v] = connected[v][u] = 1;     }     for (int i = 1; i <= n; i++) {       for (int j = i + 1; j <= n; j++) {         visitedd[i] = 1;         visitedd[j] = 1;         bruteforce_string(i, j, 1, ((1LL * j) << (4 * i)));         visitedd[i] = 0;         visitedd[j] = 0;       }     }     for (auto it : st) {       set<int> temp;       for (int i = 1; i <= 12; i++) {         int u = i;         int v = ((it >> (4LL * i)) & 15);         if (v) temp.insert((1 << u) + (1 << v));       }       sets.insert(temp);     }     for (auto it : sets) {       if (!visited[it]) bruteforce_striling(it);     }     long long res = 0;     for (auto it : visited) {       res += P(k, it.first.size());     }     printf( %lld n , res);   }


#include <bits/stdc++.h>   using namespace std;   char s[2000005], str[2000005];   int pre[2000005];   int find(int x) { return x == pre[x] ? x : pre[x] = find(pre[x]); }   int main() {     int n, q, x;     while (scanf( %d , &n) != EOF) {       for (int i = 1; i < 2000005; i++) pre[i] = i;       int maxx = 0;       while (n--) {         scanf( %s%d , str, &q);         int len = strlen(str);         while (q--) {           scanf( %d , &x);           maxx = max(maxx, x + len);           for (int i = find(x); i < x + len; i = pre[i] = find(i + 1))             s[i] = str[i - x];         }       }       for (int i = 1; i < maxx; i++) {         if (s[i] ==   0 ) s[i] =  a ;       }       printf( %s , s + 1);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 500;   int n, s, deg[N], cnt;   int main() {     scanf( %d%d , &n, &s);     for (int i = 1; i < n; i++) {       int x, y;       scanf( %d%d , &x, &y);       deg[x]++;       deg[y]++;     }     for (int i = 1; i <= n; i++)       if (deg[i] == 1) cnt++;     if (n == 2)       printf( %.10lf n , (double)s);     else       printf( %.10lf n , (double)(2 * s) / (double)cnt);   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 50;   const int magic = 2500;   struct Node {     int from, to, delta, add;     Node(int from, int to, int delta, int add)         : from(from), to(to), delta(delta), add(add) {}   };   int n, a[maxn], c[maxn], q[maxn], id[maxn], b[maxn], ans[maxn], Q;   vector<Node> All;   void BuildInterval() {     for (auto&& x : All)       for (int i = x.from; i <= x.to; ++i)         b[id[i]] -= x.delta, ans[id[i]] += x.add;     for (int i = 1; i <= Q; ++i) id[i] = i;     sort(id + 1, id + Q + 1,          [&](const int& x, const int& y) { return b[x] < b[y]; });     All.clear();     All.push_back(Node(1, Q, 0, 0));   }   int main(int argc, char* argv[]) {     scanf( %d , &n);     for (int i = 1; i <= n; ++i) scanf( %d%d , c + i, q + i), id[i] = i;     sort(id + 1, id + n + 1, [&](const int& x, const int& y) {       return q[x] > q[y] || (q[x] == q[y] && c[x] < c[y]);     });     for (int i = 1; i <= n; ++i) a[i] = c[id[i]];     scanf( %d , &Q);     for (int i = 1; i <= Q; ++i) scanf( %d , b + i);     BuildInterval();     for (int i = 1; i <= n; ++i) {       for (int j = 0, limit = All.size(); j < limit; ++j) {         if (All[j].from > All[j].to) continue;         if (b[id[All[j].from]] - All[j].delta >= a[i])           All[j].delta += a[i], ++All[j].add;         else if (b[id[All[j].to]] - All[j].delta >= a[i]) {           int l = All[j].from + 1, r = All[j].to;           while (l < r) {             int mid = l + r >> 1;             if (b[id[mid]] - All[j].delta >= a[i])               r = mid;             else               l = mid + 1;           }           All.push_back(Node(l, All[j].to, All[j].delta + a[i], All[j].add + 1));           All[j].to = l - 1;         }       }       if (All.size() > magic || i == n) BuildInterval();     }     for (int i = 1; i <= Q; ++i) printf( %d  , ans[i]);     puts(  );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f, N = 3.1e5;   int n, m, dis[N], fm[N];   vector<int> vec[N];   void bfs() {     memset(dis, 0x3f, sizeof(dis));     queue<int> q;     q.push(1);     dis[1] = 0;     while (!q.empty()) {       int u = q.front();       q.pop();       for (int v : vec[u])         if (dis[v] == INF) dis[v] = dis[u] + 1, fm[v] = u, q.push(v);     }   }   int x[N], y[N], fa[N], sz[N], d[N];   bool vis[N];   int find(int u) { return u == fa[u] ? u : fa[u] = find(fa[u]); }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> n >> m;     for (int i = 1; i <= m; i++)       cin >> x[i] >> y[i], vec[x[i]].push_back(y[i]), vec[y[i]].push_back(x[i]);     bfs();     stack<int> s;     if (dis[n] <= 4)       for (int i = n; i; i = fm[i]) s.push(i);     else {       bool ok = 0;       for (int i = 1; i <= n; i++)         if (dis[i] == 2) {           s.push(n);           s.push(1);           s.push(i);           s.push(fm[i]);           s.push(1);           ok = 1;           break;         }       if (!ok) {         for (int i = 1; i <= n; i++) fa[i] = i, sz[i] = 1;         for (int i = 1; i <= m; i++)           if (x[i] != 1 && y[i] != 1 && dis[x[i]] == 1 && dis[y[i]] == 1) {             int u = x[i], v = y[i];             d[u]++, d[v]++;             int fv = find(v), fu = find(u);             if (fu == fv) continue;             fa[fv] = fu, sz[fu] += sz[fv];           }         for (int i = 1; i <= n; i++)           if (dis[i] == 1 && d[i] != sz[find(i)] - 1) {             for (int v : vec[i])               if (v != 1) vis[v] = 1;             for (int v : vec[i])               if (v != 1) {                 bool Get = 0;                 for (int vv : vec[v])                   if (vv != 1 && vv != i && !vis[vv]) {                     s.push(n);                     s.push(i);                     s.push(vv);                     s.push(v);                     s.push(i);                     s.push(1);                     Get = 1;                     break;                   }                 if (Get) break;               }             break;           }       }     }     cout << int(s.size() - 1) << endl;     while (!s.empty()) cout << s.top() <<    , s.pop();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t-- > 0) {       int n, m;       cin >> n;       int a[n];       for (int i = 0; i < n; i++) {         cin >> a[i];       }       int i = 0, t = 0, f = 0;       while (i < n - 1) {         if (a[0] != 1) {           f = 1;           cout <<  First n ;           break;         } else if (a[0] == 1) {           while (i < n - 1 && a[i] == 1) {             t++;             i++;           }           break;         }         i++;       }       if (t % 2 == 0 && f == 0) {         cout <<  First n ;       } else if (t % 2 == 1 && f == 0) {         cout <<  Second n ;       }     }     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   #pragma GCC target( popcnt )   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n;     cin >> n;     vector<pair<char, int>> arr;     for (int i = 0; i < 2 * n; i++) {       char sym;       cin >> sym;       int tmp;       if (sym ==  + ) {         tmp = 1;       } else {         cin >> tmp;       }       arr.emplace_back(sym, tmp);     }     reverse(arr.begin(), arr.end());     stack<int> mys;     string s =  YES ;     vector<int> ans;     for (int i = 0; i < int(arr.size()); i++) {       char sym;       int x;       tie(sym, x) = arr[i];       if (sym ==  + ) {         if (mys.empty()) {           s =  NO ;           break;         }         ans.push_back(mys.top());         mys.pop();       } else {         if (!mys.empty() && mys.top() < x) {           s =  NO ;           break;         }         mys.push(x);       }     }     cout << s <<   n ;     if (s ==  YES ) {       reverse(ans.begin(), ans.end());       for (auto ele : ans) {         cout << ele <<    ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int q;     cin >> q;     int l[500], r[500], d[500], ans[500];     for (int i = 0; i < q; i++) {       cin >> l[i] >> r[i] >> d[i];       int quo;       if (d[i] < l[i]) {         ans[i] = d[i];       } else {         quo = int(r[i] / d[i]);         ans[i] = d[i] * (quo + 1);       }     }     for (int i = 0; i < q; i++) {       cout << ans[i] << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, v[100010], c[100010], l[100010], r, mx = 0;   map<long long, long long> dp, path, acp;   vector<long long> ans, vt[3 * 100010];   void getdp(long long x) {     long long i, ss;     dp.clear();     path.clear();     acp.clear();     for (i = 0; i < vt[x].size(); i++) {       dp[l[vt[x][i]]] = dp[l[vt[x][i]] + c[vt[x][i]]] = -1000000000000000000;       path[l[vt[x][i]]] = path[l[vt[x][i]] + c[vt[x][i]]] = -1;       acp[vt[x][i]] = -1;     }     dp[0] = 0;     for (ss = 0; ss < vt[x].size(); ss++) {       i = vt[x][ss];       if (l[i] == 0) {         if (v[i] > dp[l[i] + c[i]] || path[l[i] + c[i]] == -1) {           dp[l[i] + c[i]] = v[i];           path[l[i] + c[i]] = i;           acp[i] = -1;         }       } else {         if (path[l[i]] == -1) {           continue;         }         if (dp[l[i]] + v[i] > dp[l[i] + c[i]] || path[l[i] + c[i]] == -1) {           dp[l[i] + c[i]] = dp[l[i]] + v[i];           path[l[i] + c[i]] = i;           acp[i] = path[l[i]];         }       }     }     i = path[x];     if (dp[x] > mx) {       mx = dp[x];       ans.clear();       while (i != -1) {         ans.push_back(i);         i = acp[i];       }     }     return;   }   int main() {     long long i, j, mx = 0;     scanf( %lld , &n);     for (i = 0; i < n; i++) {       scanf( %lld%lld%lld%lld , &v[i], &c[i], &l[i], &r);       vt[c[i] + l[i] + r].push_back(i);     }     for (i = 0; i <= 300000; i++) {       if (vt[i].empty()) {         continue;       }       getdp(i);     }     sort(ans.begin(), ans.end());     printf( %lld n , (long long)ans.size());     for (i = 0; i < ans.size(); i++) {       printf( %lld  , ans[i] + 1);     }     puts(  );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 300005, M = 25;   const long long p = 998244353ll;   inline long long expo(long long a, int b = 998244351) {     long long c = 1ll;     while (b) {       if (b & 1) c = c * a % p;       b >>= 1;       a = a * a % p;     }     return c;   }   long long FAC[N], IFA[N];   inline long long comb(int a, int b) {     return (b < 0 || b > a) ? 0ll : (FAC[a] * (IFA[b] * IFA[a - b] % p) % p);   }   vector<int> L[N], R[N];   int I[N], C[M << 1];   long long E[M], ss;   inline void dfs(int m, long long a, int w = 1) {     if (m) {       dfs(m - 1, a, w);       if ((ss & E[m]) == E[m]) dfs(m - 1, a & (~E[m]), -w);     } else {       C[__builtin_popcountll(a)] += w;     }   }   int main() {     int n, m, i, a, b, c = 0, f = 0, c0 = 0, c1 = 0;     long long ans = 0ll, s1 = 0ll;     vector<int>::iterator d;     scanf( %d%d , &n, &m);     FAC[0] = 1ll;     for (i = (1); i <= (n); ++i) FAC[i] = FAC[i - 1] * i % p;     IFA[n] = expo(FAC[n]);     for (i = (n); i >= (1); --i) IFA[i - 1] = IFA[i] * i % p;     for (i = (1); i <= (n); ++i) {       scanf( %d%d , &a, &b);       L[a].push_back(i);       R[b].push_back(i);     }     for (i = (1); i <= (m); ++i) {       scanf( %d%d , &a, &b);       if (!I[a]) I[a] = ++c;       if (!I[b]) I[b] = ++c;       E[i] = (1ll << I[a]) | (1ll << I[b]);     }     C[0] = 1;     for (i = (1); i <= (n); ++i) {       for (d = L[i].begin(); d != L[i].end(); ++d) {         a = *d;         if (I[a]) {           ++c1;           f = 1;           s1 |= 1ll << I[a];         }         ++c0;       }       if (f) {         for (a = (0); a <= (c1); ++a) C[a] = 0;         ss = s1;         dfs(m, s1);         f = 0;       }       for (a = (0); a <= (c1); ++a)         ans = (ans + (C[c1 - a] + p) * comb(c0 - a, i - a)) % p;       for (d = R[i].begin(); d != R[i].end(); ++d) {         a = *d;         if (I[a]) {           --c1;           f = 1;           s1 ^= 1ll << I[a];         }         --c0;       }     }     printf( %lld , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void ga(int N, int *A) {     for (int i(0); i < N; i++) cin >> A[i];   }   int main(void) {     ios_base::sync_with_stdio(false);     string num;     getline(cin, num);     int ln = num.length();     int b = 0;     int st = 0;     int en = ln;     bool dot = 0;     for (char e : num) {       dot = dot or (e ==  . );     }     for (int i(0); i < ln; i++) {       if (num[i] !=  0 ) {         st = i;         break;       }     }     for (int i = ln - 1; i > 0; i--) {       if (num[i] !=  0 ) {         en = i + 1;         break;       }     };     ;     if (num[st] ==  . ) {       b--;       for (int i(st + 1); i < ln; i++) {         if (num[i] !=  0 ) {           st = i;           break;         }         b--;       }       cout << num[st] << (en - st - 1 == 0 ?    :  . )            << num.substr(st + 1, en - st - 1) <<  E  << b << endl;       return 0;     } else {       b--;       for (int i(st); i < ln; i++) {         if (num[i] ==  . ) {           en--;           num.erase(i, 1);           break;         }         b++;       };       for (int i = en - 1; i >= 0; i--) {         if (num[i] !=  0 ) {           ;           en = i + 1;           break;         }       }       cout << num[st] << (en - st - 1 == 0 ?    :  . )            << num.substr(st + 1, en - st - 1)            << (b == 0 ?    :  E  + to_string(b)) << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   int a[1000005];   inline int Pow_Log(int x, int p) {     int sol = 1;     while (p) {       if (p & 1) {         sol = (1LL * sol * x) % 1000000009;         --p;       }       p >>= 1;       x = (1LL * x * x) % 1000000009;     }     return sol;   }   int main() {     int i, j, sol = 1, x;     cin.sync_with_stdio(0);     cin >> n >> m;     x = Pow_Log(2, m);     for (i = 1; i <= n; ++i) {       --x;       if (x < 0) x += 1000000009;       sol = (1LL * sol * x) % 1000000009;     }     cout << sol;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int n, m, a, b, c, d, k, x, y, z, ans = 0, total = 0;   long long int arr[201000] = {0};   int main(void) {     cin >> n >> m;     for (int i = 0; i < n; i++) cin >> arr[i];     sort(arr, arr + n);     a = (n / 2);     ans += abs(arr[a] - m);     for (int i = a + 1; i < n; i++) {       if (arr[i] < m) {         ans += abs(arr[i] - m);       } else {         break;       }     }     for (int i = a - 1; i >= 0; i--) {       if (arr[i] > m) {         ans += abs(arr[i] - m);       } else {         break;       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string file[10005];   unordered_map<string, pair<int, int> > ss;   unordered_map<string, bool> sk;   void deal(const string &in, int loc) {     sk.clear();     int len = in.size();     string temp;     for (int i = 1; i <= len; ++i) {       for (int j = 0; j <= len - i; ++j) {         temp.clear();         for (int k = j; k < i + j; ++k) {           temp.push_back(in[k]);         }         auto &flag = sk[temp];         if (flag)           continue;         else {           flag = true;           auto it = ss.find(temp);           if (it == ss.end()) {             ss.emplace(make_pair(temp, make_pair(loc, 1)));           } else             ++it->second.second;         }       }     }   }   string quest;   int main() {     int n, m;     ios::sync_with_stdio(false);     cin >> n;     for (int i = 0; i < n; ++i) {       cin >> file[i];       deal(file[i], i);     }     cin >> m;     while (m--) {       cin >> quest;       auto it = ss.find(quest);       if (it != ss.end()) {         cout << it->second.second <<     << file[it->second.first] <<   n ;       } else {         cout <<  0 - n ;       }     }     return 0;   }


#define DEBUG 0      #include <bits/stdc++.h>   using namespace std;      #if DEBUG   // basic debugging macros   int __i__,__j__;   #define printLine(l) for(__i__=0;__i__<l;__i__++){cout<< - ;}cout<<endl   #define printLine2(l,c) for(__i__=0;__i__<l;__i__++){cout<<c;}cout<<endl   #define printVar(n) cout<<#n<< :  <<n<<endl   #define printArr(a,l) cout<<#a<< :  ;for(__i__=0;__i__<l;__i__++){cout<<a[__i__]<<   ;}cout<<endl   #define print2dArr(a,r,c) cout<<#a<< : n ;for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<a[__i__][__j__]<<   ;}cout<<endl;}   #define print2dArr2(a,r,c,l) cout<<#a<< : n ;for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<setw(l)<<setfill(   )<<a[__i__][__j__]<<   ;}cout<<endl;}      // advanced debugging class   // debug 1,2, A , test ;   class _Debug {       public:           template<typename T>           _Debug& operator,(T val) {               cout << val << endl;               return *this;           }   };   #define debug _Debug(),   #else   #define printLine(l)   #define printLine2(l,c)   #define printVar(n)   #define printArr(a,l)   #define print2dArr(a,r,c)   #define print2dArr2(a,r,c,l)   #define debug   #endif      // define   #define MAX_VAL 999999999   #define MAX_VAL_2 999999999999999999LL   #define EPS 1e-6   #define mp make_pair   #define pb push_back      // typedef   typedef unsigned int UI;   typedef long long int LLI;   typedef unsigned long long int ULLI;   typedef unsigned short int US;   typedef pair<int,int> pii;   typedef pair<LLI,LLI> plli;   typedef vector<int> vi;   typedef vector<LLI> vlli;   typedef vector<pii> vpii;   typedef vector<plli> vplli;      // ---------- END OF TEMPLATE ----------   #define MOD 1000000007      int modPow(int b,int e) {       int r = 1;       while (e > 0) {           if (e & 1) r = ((LLI) r*b) % MOD;           e >>= 1;           b = ((LLI) b*b) % MOD;       }       return r;   }   int fact[41],C[41][41],ways[40];   int p[40],v[40],occ[41],occ2[41];   int dp[1000000];   int main() {       int i;       int n;       scanf( %d ,&n);       for (i = 0; i < n; i++) scanf( %d ,&p[i]),p[i]--;          int j,k;       fact[0] = 1;       for (i = 1; i <= n; i++) fact[i] = ((LLI) i*fact[i-1]) % MOD;       for (i = 0; i <= n; i++) {           C[i][0] = 1;           for (j = 1; j <= i; j++) C[i][j] = (C[i-1][j-1]+C[i-1][j]) % MOD;       }       for (i = 0; i < n; i++) {           for (j = 0; j <= i; j++) {               ways[i] += ((((LLI) C[i][j]*fact[j]) % MOD)*fact[n-j-1]) % MOD;               ways[i] %= MOD;           }       }       for (i = 0; i < n; i++) {           if (!v[i]) {               int u = i,c = 0;               while (!v[u]) v[u] = 1,u = p[u],c++;               occ[c]++;           }       }       int s = 1;       for (i = 1; i <= n; i++) s *= occ[i]+1;       dp[0] = 1;       for (i = 1; i < s; i++) {           int t = i,s2 = 1,sum = 0;           for (j = 1; j <= n; j++) {               occ2[j] = t % (occ[j]+1),s2 *= occ2[j]+1,sum += occ2[j]*j;               t /= occ[j]+1;           }           for (j = 1; j < s2; j++) {               int t2 = j,sum2 = 0,num = 0,j2 = 0,pp = 1;               LLI c = 1;               for (k = 1; k <= n; k++) {                   int occ3 = t2 % (occ2[k]+1);                   c *= C[occ2[k]][occ3],c %= MOD,num += occ3,sum2 += occ3*k;                   j2 += (occ2[k]-occ3)*pp;                   t2 /= occ2[k]+1,pp *= occ[k]+1;               }               if (!(num & 1)) c = MOD-c;               c *= dp[j2],c %= MOD;               dp[i] += (c*modPow(ways[sum-sum2],sum2)) % MOD,dp[i] %= MOD;           }       }       printf( %d n ,dp[s-1]);          return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, a[100069];   int main() {     long long t, rr, i;     bool bad;     scanf( %lld , &t);     for (rr = 0; rr < t; rr++) {       scanf( %lld , &n);       for (i = 1; i <= n * 4; i++) {         scanf( %lld , a + i);       }       sort(a + 1, a + n * 4 + 1);       bad = 0;       for (i = 1; i <= n * 4; i += 2) {         if (a[i] != a[i + 1]) {           bad = 1;           break;         }       }       for (i = 3; i <= n * 2; i += 2) {         if (a[i] * a[n * 4 + 1 - i] != a[1] * a[n * 4]) {           bad = 1;           break;         }       }       if (bad) {         printf( NO n );       } else {         printf( YES n );       }     }   }


#include <bits/stdc++.h>   using namespace std;   int n, m, len, kmpA[100010], ans, kmpB[100010], mxA[100010], mxB[100010];   char S[100010], A[100010], B[100010];   int main() {     scanf( %s , S + 1);     n = strlen(S + 1);     scanf( %d , &m);     while (m--) {       scanf( %s , A);       kmpA[0] = -1;       len = strlen(A);       if (len == 1) continue;       for (int i = 1, k = -1; i <= len; i++) {         while (k != -1 && A[i - 1] != A[k]) k = kmpA[k];         k++;         kmpA[i] = k;       }       for (int i = 0; i <= len - 1; i++) B[len - 1 - i] = A[i];       kmpB[0] = -1;       for (int i = 1, k = -1; i <= len; i++) {         while (k != -1 && B[i - 1] != B[k]) k = kmpB[k];         k++;         kmpB[i] = k;       }       for (int i = 1, k = 0; i <= n; i++) {         while (k != -1 && S[i] != A[k]) k = kmpA[k];         k++;         mxA[i] = k;       }       for (int i = n, k = 0; i >= 1; i--) {         while (k != -1 && S[i] != B[k]) k = kmpB[k];         k++;         mxB[i] = k;       }       for (int i = 1; i <= n; i++) mxA[i] = max(mxA[i - 1], mxA[i]);       for (int i = n; i >= 1; i--) mxB[i] = max(mxB[i + 1], mxB[i]);       bool flag = false;       for (int i = 1; i <= n + 1; i++) {         if (mxA[i - 1] + mxB[i] >= len) {           flag = true;           break;         }       }       ans += flag;     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bitset<1005> tt[30];   unordered_map<bitset<1005>, int> ff;   pair<bitset<1005>, int> ar[1000005];   int bc[1000005];   void print(bitset<1005> t) {     for (int i = 0; i < 12; ++i) {       if (t[i]) {         putchar( 1 );       } else {         putchar( 0 );       }     }     putchar(  n );   }   int construct(int l, int r, bool isG) {     bitset<1005> tmp;     ar[0] = {tmp, 0};     int cc = 1;     for (int i = l; i <= r; ++i) {       int ind = i;       if (isG) {         ind -= l;       }       int tcc = cc;       for (int j = 0; j < cc; ++j) {         ar[tcc++] = {ar[j].first ^ tt[i], (1 << ind) + ar[j].second};       }       cc = tcc;     }     if (!isG) {       for (int i = 0; i < cc; ++i) {         if (!ff.count(ar[i].first)) {           ff[ar[i].first] = bc[ar[i].second];         } else {           ff[ar[i].first] = min(ff[ar[i].first], bc[ar[i].second]);         }       }     }     return cc;   }   void solve() {     int n, s, d;     scanf( %d %d %d  , &n, &s, &d);     for (int i = 0; i < s; ++i) {       int x;       scanf( %d  , &x);       while (x--) {         int t;         scanf( %d  , &t);         tt[i][t - 1] = 1;       }     }     bc[0] = 0;     for (int i = 1; i < 1000005; ++i) {       bc[i] = bc[i / 2] + (i & 1);     }     int g = min(s - 1, 18);     construct(0, g, 0);     int sz = construct(g + 1, s - 1, 1);     while (d--) {       bitset<1005> tmp;       int x;       scanf( %d  , &x);       while (x--) {         int t;         scanf( %d  , &t);         tmp[t - 1] = 1;       }       const int inf = 1e9;       int ret = inf;       for (int i = 0; i < sz; ++i) {         if (ff.count(tmp ^ ar[i].first)) {           ret = min(ret, bc[ar[i].second] + ff[tmp ^ ar[i].first]);         }       }       if (ret == inf) {         ret = -1;       }       printf( %d n , ret);     }   }   int main() {     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int t;     cin >> t;     while (t--) {       long long n1, n2, n3;       cin >> n1 >> n2 >> n3;       vector<long long> a, b, c;       for (long long i = (0); i < (n1); i++) {         long long m;         cin >> m;         a.push_back(m);       }       for (long long i = (0); i < (n2); i++) {         long long m;         cin >> m;         b.push_back(m);       }       for (long long i = (0); i < (n3); i++) {         long long m;         cin >> m;         c.push_back(m);       }       sort(a.begin(), a.end());       sort(b.begin(), b.end());       sort(c.begin(), c.end());       long long ans = 9e18L;       long long fans = 9e18L;       for (long long i = (0); i < (n1); i++) {         long long x = a[i];         long long yi = lower_bound(b.begin(), b.end(), x) - b.begin();         long long zi = upper_bound(c.begin(), c.end(), x) - c.begin();         zi--;         if (zi >= 0 && zi < n3 && yi >= 0 && yi < n2) {           long long y = b[yi];           long long z = c[zi];           ans = (x - y) * (x - y) + (x - z) * (x - z) + (z - y) * (z - y);           fans = min(fans, ans);         }       }       for (long long i = (0); i < (n1); i++) {         long long x = a[i];         long long yi = upper_bound(b.begin(), b.end(), x) - b.begin();         long long zi = lower_bound(c.begin(), c.end(), x) - c.begin();         yi--;         if (zi >= 0 && zi < n3 && yi >= 0 && yi < n2) {           long long y = b[yi];           long long z = c[zi];           ans = (x - y) * (x - y) + (x - z) * (x - z) + (z - y) * (z - y);           fans = min(fans, ans);         }       }       for (long long i = (0); i < (n2); i++) {         long long x = b[i];         long long yi = lower_bound(a.begin(), a.end(), x) - a.begin();         long long zi = upper_bound(c.begin(), c.end(), x) - c.begin();         zi--;         if (zi >= 0 && zi < n3 && yi >= 0 && yi < n1) {           long long y = a[yi];           long long z = c[zi];           ans = (x - y) * (x - y) + (x - z) * (x - z) + (z - y) * (z - y);           fans = min(fans, ans);         }       }       for (long long i = (0); i < (n2); i++) {         long long x = b[i];         long long yi = upper_bound(a.begin(), a.end(), x) - a.begin();         long long zi = lower_bound(c.begin(), c.end(), x) - c.begin();         yi--;         if (zi >= 0 && zi < n3 && yi >= 0 && yi < n1) {           long long y = a[yi];           long long z = c[zi];           ans = (x - y) * (x - y) + (x - z) * (x - z) + (z - y) * (z - y);           fans = min(fans, ans);         }       }       for (long long i = (0); i < (n3); i++) {         long long x = c[i];         long long yi = upper_bound(b.begin(), b.end(), x) - b.begin();         long long zi = lower_bound(a.begin(), a.end(), x) - a.begin();         yi--;         if (zi >= 0 && zi < n1 && yi >= 0 && yi < n2) {           long long y = b[yi];           long long z = a[zi];           ans = (x - y) * (x - y) + (x - z) * (x - z) + (z - y) * (z - y);           fans = min(fans, ans);         }       }       for (long long i = (0); i < (n3); i++) {         long long x = c[i];         long long yi = lower_bound(b.begin(), b.end(), x) - b.begin();         long long zi = upper_bound(a.begin(), a.end(), x) - a.begin();         zi--;         if (zi >= 0 && zi < n1 && yi >= 0 && yi < n2) {           long long y = b[yi];           long long z = a[zi];           ans = (x - y) * (x - y) + (x - z) * (x - z) + (z - y) * (z - y);           fans = min(fans, ans);         }       }       cout << fans <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());   const int INF = 2e9;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int n, p;     cin >> n >> p;     vector<int> a(n);     for (int i = 0; i < (int)(n); i++) cin >> a[i];     sort((a).begin(), (a).end());     int l = -INF, r = INF;     for (int i = 0; i < (int)(n); i++) {       l = max(l, a[i] - i);       if (p - 1 <= i) r = min(r, a[i] - i + (p - 1));     }     vector<int> ans;     for (int i = l; i < r; i++) ans.push_back(i);     cout << ((int)(ans).size()) << endl;     for (auto x : ans) cout << x <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int getReverted(int num) {     bool bin[8] = {0};     for (int j = 0; num != 0; j++) {       bin[j] = num % 2;       num /= 2;     }     for (int j = 0; j < 8; j++) {       num += (int)bin[j] * pow(2, 7 - j);     }     return num;   }   int strSize(char *str) {     int i;     for (i = 0; str[i] !=   0 ; i++)       ;     return i;   }   int main() {     char str[101];     int last = 0, result, size, reverted;     scanf(  %[^ n]s , str);     size = strSize(str);     for (int i = 0; str[i] !=   0 ; i++) {       reverted = getReverted(str[i]);       result = (last - reverted) % 256;       if (result < 0)         while (result < 0) result += 256;       cout << result;       if (i != size - 1) cout << endl;       last = getReverted(str[i]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string getmin(string prev, string cur) {     if (prev.length() < cur.length()) {       for (int i = 0; i < cur.length(); i++) {         if (cur[i] ==  ? ) cur[i] = (i == 0) ?  1  :  0 ;       }       return cur;     }     if (prev.length() > cur.length()) return   ;     int fmsm = 100;     for (int i = 0; i < cur.length(); i++) {       if (cur[i] ==  ? ) continue;       if (cur[i] != prev[i]) {         fmsm = i;         break;       }     }     int nm = 0;     for (int i = 0; i < cur.length(); i++) {       if (i == fmsm) {         if (cur[i] < prev[i]) nm++;       }       if (cur[i] ==  ? ) {         if (i < fmsm)           nm = nm * 10 + prev[i] -  0 ;         else {           nm *= 10;         }       }     }     if (fmsm == 100) nm++;     for (int i = cur.length() - 1; i >= 0; i--) {       if (cur[i] ==  ? ) {         cur[i] =  0  + nm % 10;         nm /= 10;       }     }     if (nm) return   ;     return cur;   }   int main() {     int n;     scanf( %d , &n);     string cur =   ;     vector<string> nums;     for (int i = 0; i < n; i++) {       char ch[32];       scanf(  %s , ch);       string chs(ch);       string x = getmin(cur, chs);       if (x.empty()) {         printf( NO n );         return 0;       }       nums.push_back(x);       cur = x;     }     printf( YES n );     for (int i = 0; i < n; i++) printf( %s n , nums[i].c_str());     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     int t, ang;     cin >> t;     while (t--) {       cin >> ang;       int ans = -1;       for (int i = 3; i <= 360; ++i) {         int k = ang * i / 180;         if ((ang * i) % 180 == 0 && 360 % i == 0 && 1 <= k && k <= i - 2) {           ans = i;           break;         }       }       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e3 + 1;   char a[N], b[N];   vector<int> g[26];   bool vis[26][26];   vector<pair<char, char> > sol;   char go[26];   int main() {     scanf( %s%s , a, b);     int n = strlen(a);     for (int i = 0; i < n; ++i) {       if (a[i] == b[i]) continue;       int x = a[i] -  a ;       int y = b[i] -  a ;       g[x].push_back(y);       g[y].push_back(x);     }     bool can = true;     for (int i = 0; i < 26 && can; ++i) {       sort(g[i].begin(), g[i].end());       g[i].resize(unique(g[i].begin(), g[i].end()) - g[i].begin());       can &= g[i].size() <= 1;     }     if (!can) {       puts( -1 );       return 0;     }     for (int i = 0; i < 26; ++i)       if (!g[i].empty()) {         int x = min(i, g[i][0]), y = max(i, g[i][0]);         if (vis[x][y]) continue;         go[x] = y +  a ;         go[y] = x +  a ;         vis[x][y] = true;         sol.push_back(make_pair(x +  a , y +  a ));       } else         go[i] = i +  a ;     for (int i = 0; i < 26 && can; ++i) {       can &= go[a[i] -  a ] == b[i];       can &= go[b[i] -  a ] == a[i];     }     if (!can) {       puts( -1 );       return 0;     }     printf( %d n , (int)sol.size());     for (int i = 0; i < (int)sol.size(); ++i)       printf( %c %c n , sol[i].first, sol[i].second);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     int n, k;     cin >> n >> k;     long long a[n * k];     for (int i = 0; i < n * k; i++) {       cin >> a[i];     }     long long sum = 0;     int jump = ((n + 1) / 2);     if (n % 2 == 0) jump++;     int count = 0;     for (int i = n * k - jump; count < k; i -= jump) {       sum += a[i];       count++;     }     cout << sum << endl;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t;     cin >> t;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     string input, temp;     bool f1, f2;     cin >> n;     getline(cin, input);     for (int i = 0; i < n; i++) {       f1 = false;       f2 = false;       getline(cin, input);       if (input.length() > 4) {         temp = input.substr(0, 5);         if (temp ==  miao. ) f2 = true;         temp = input.substr(input.length() - 5, 5);         if (temp ==  lala. ) f1 = true;       }       if (f1 && !f2)         cout <<  Freda s  << endl;       else if (f2 && !f1)         cout <<  Rainbow s  << endl;       else         cout <<  OMG>.< I don t know!  << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int arr[n];     for (int i = 0; i < n; i++) {       cin >> arr[i];     }     sort(arr, arr + n);     int runsum = 0;     int pen = 0;     int k = 0;     while (runsum <= 350 && ((runsum + arr[k]) <= 710) && k < n)       runsum += arr[k++];     if (runsum <= 350) {       cout << k <<   0  << endl;     } else {       runsum -= 350;       pen += runsum;       while ((runsum + arr[k]) <= 360 && k < n) {         runsum += arr[k++];         pen += runsum;       }       cout << k <<     << pen << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int temp1[26];   int temp2[1001][26];   set<int> myset[1001];   set<int> empty;   vector<int> myvec;   int main() {     int n;     cin >> n;     string str;     cin >> str;     int m;     cin >> m;     string arr[m];     for (int i = 0; i < m; i++) {       cin >> arr[i];     }     for (int i = 0; i < n; i++) {       if (str[i] !=  * ) {         temp1[str[i] -  a ] = 1;       }     }     for (int i = 0; i < m; i++) {       for (int j = 0; j < n; j++) {         if (str[j] ==  * ) {           if (temp1[arr[i][j] -  a ] == 1) {             myset[i] = empty;             break;           } else {             myset[i].insert(arr[i][j] -  a );             temp2[i][arr[i][j] -  a ] = 1;           }         } else {           if (str[j] != arr[i][j]) {             myset[i] = empty;             break;           }         }       }     }     for (int i = 0; i < m; i++) {       if (myset[i].empty() == false) {         myvec.push_back(i);       }     }     int ans = 0;     int size = myvec.size();     for (int j = 0; j < 26; j++) {       int cnt = 0;       for (int i = 0; i < size; i++) {         if (temp2[myvec[i]][j] == 1) {           cnt++;         }       }       if (cnt == size) {         ans++;       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e5 + 100;   vector<int> G[MAXN];   map<int, int> cnt;   bool vis[MAXN];   int sz;   int cN, c[MAXN], b[MAXN];   int dp[MAXN];   void dfs(int u) {     vis[u] = true;     sz++;     for (int i = 0; i < G[u].size(); i++) {       int v = G[u][i];       if (!vis[v]) dfs(v);     }   }   inline int smin(int &a, int b) { return a = min(a, b); }   bool lucky(int x) {     while (x) {       if (x % 10 != 7 && x % 10 != 4) return false;       x /= 10;     }     return true;   }   int main() {     ios::sync_with_stdio(false);     cout.tie(0);     cin.tie(0);     int n, m;     cin >> n >> m;     for (int i = 0; i < m; i++) {       int a, b;       cin >> a >> b;       a--;       b--;       G[a].push_back(b);       G[b].push_back(a);     }     for (int u = 0; u < n; u++)       if (!vis[u]) {         sz = 0;         dfs(u);         cnt[sz]++;       }     for (map<int, int>::iterator iter = cnt.begin(); iter != cnt.end(); iter++) {       int x = iter->first, pw = 1;       int temp = iter->second;       while (temp >= pw) {         c[cN++] = x * pw, b[cN - 1] = pw, temp -= pw;         pw *= 2;       }       if (temp) {         c[cN++] = x * temp;         b[cN - 1] = temp;       }     }     fill(dp, dp + MAXN, -1u / 4);     dp[0] = 0;     for (int i = 0; i < cN; i++) {       int val = c[i];       for (int j = MAXN - 1; j >= 0; j--)         if (val + j < MAXN) smin(dp[j + val], dp[j] + b[i]);     }     int ans = -1u / 4;     for (int i = 1; i < MAXN; i++)       if (lucky(i)) smin(ans, dp[i]);     cout << (ans < MAXN ? ans - 1 : -1) << endl;   }


#include <bits/stdc++.h>   using namespace std;   int read() {     int xx = 0, ff = 1;     char ch = getchar();     while (ch >  9  || ch <  0 ) {       if (ch ==  - ) ff = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       xx = xx * 10 + ch -  0 ;       ch = getchar();     }     return xx * ff;   }   int N, K, f[110][100010];   struct Segment {     int L, R;   } S[110];   int q[100010], head, tail;   int main() {     N = read(), K = read();     for (int i = 1; i <= K; i++) S[i].L = read(), S[i].R = read();     for (int j = 0; j <= N; j++) f[0][j] = (1 << 29);     f[0][0] = 0;     for (int i = 1; i <= K; i++) {       for (int j = 0; j <= N; j++) f[i][j] = f[i - 1][j];       head = 1, tail = 0;       for (int j = 0; j <= S[i].R; j++) {         if (j <= N) {           while (head <= tail && f[i - 1][j] <= f[i - 1][q[tail]]) tail--;           q[++tail] = j;         }         while (head <= tail && q[head] <= j - (S[i].R - S[i].L + 1)) head++;         if (head <= tail) f[i][j] = min(f[i][j], f[i - 1][q[head]] + 2);       }       head = 1, tail = 0;       for (int j = S[i].R; j >= 0; j--) {         if (S[i].R - j <= N) {           while (head <= tail && f[i - 1][S[i].R - j] <= f[i - 1][q[tail]])             tail--;           q[++tail] = S[i].R - j;         }         while (head <= tail && q[head] <= S[i].L - (j + 1)) head++;         if (head <= tail) f[i][j] = min(f[i][j], f[i][q[head]] + 1);       }     }     if (f[K][N] >= (1 << 29))       puts( Hungry );     else {       puts( Full );       printf( %d n , f[K][N]);     }     return 0;   }


#include<bits/stdc++.h>   #define pb push_back   using namespace std;   typedef long long ll;   const int maxn=1e6+100;   const int M=1000000007;   typedef array<int,41> A;   bool vis[50];   int f[50],n,mx,F[50][50],G[50][50],p[50],nf[50],inv[50];   int ways[50][50][50];   map<A,int> dp[41][41][41];   void add(int &x,int y){x+=y;if (x>=M)x-=M;}   int C(int x,int y){    if (y<0||y>x) return 0;    return 1ll*f[x]*nf[y]%M*nf[x-y]%M;   }   void init(){    inv[1]=1; for (int i=2;i<=n;i++) inv[i]=M-1ll*(M/i)*inv[M%i]%M;    f[0]=nf[0]=1; for (int i=1;i<=n;i++) f[i]=1ll*f[i-1]*i%M,nf[i]=1ll*nf[i-1]*inv[i]%M;    F[0][0]=f[n-1];    for (int i=0;i<=n-1;i++)    for (int j=1;j+i<=n-1;j++){           F[i][j]=0;           for (int x=0;x<=i;x++)      for (int y=0;y<=j;y++){       add(F[i][j],1ll*C(i,x)*C(j,y)%M*f[n-1-x-y]%M*f[x+y]%M);       if (!y) add(G[i][j],1ll*C(i,x)*C(j,y)%M*f[n-1-x-y]%M*f[x+y]%M);      }    }    for (int i=0;i<=n-1;i++)    for (int j=0;j+i<=n-1;j++){     int x=1,y=1;     for (int k=1;k<=n;k++){      x=1ll*x*F[i][j]%M;      y=1ll*y*G[i][j]%M;      ways[i][j][k]=(x-y+M)%M;     }    }   }   int solve(int lasttot,int tot,int block,A a){       if (dp[lasttot][tot][block].find(a)!=dp[lasttot][tot][block].end()){     return dp[lasttot][tot][block][a];       }       int ret=0,sum=n;       for (int i=1;i<=mx;i++) sum-=a[i]*i;       if (sum==n) return dp[lasttot][tot][block][a]=nf[block];    A tmp=a;       for (int i=1;i<=mx;i++) {     if (a[i]){      tmp[i]--;               add(ret,1ll*ways[sum-tot-lasttot][lasttot][i]*a[i]%M*solve(lasttot,tot+i,block+1,tmp)%M);               if (block) add(ret,1ll*ways[sum-tot][tot][i]*a[i]%M*nf[block]%M*solve(tot,i,1,tmp)%M);      tmp[i]++;     }       }       return dp[lasttot][tot][block][a]=ret;   }   int main(){    scanf( %d ,&n);    init();    for (int i=1;i<=n;i++) scanf( %d ,&p[i]);    A a;    for (int i=0;i<=40;i++) a[i]=0;    for (int i=1;i<=n;i++) if (!vis[i]){     int w=0,tmp=i;     while (!vis[tmp]){      w++;      vis[tmp]=1;      tmp=p[tmp];     }     a[w]++;     mx=max(mx,w);    }    printf( %d n ,solve(0,0,0,a));    return 0;   }


#include <bits/stdc++.h>   using namespace std;   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     string s;     cin >> s;     long long l = s.length();     vector<char> s1;     long long pos = -1;     for (long long i = 0; i < l; i++) {       if (s[i] ==  a )         pos = i;       else         s1.push_back(s[i]);     }     long long l2 = s1.size();     long long ri = l - 1 - pos;     long long le = l2 - ri;     if (l2 % 2 != 0 || le > ri)       cout <<  :( ;     else {       long long j = l2 / 2;       bool flag = true;       for (long long i = 0; i < j; i++) {         if (s1[i] != s1[i + j]) {           flag = false;           break;         }       }       if (!flag)         cout <<  :( ;       else {         for (long long i = 0; i < l - j; i++) cout << s[i];       }     }   }


#include <bits/stdc++.h>   using namespace std;   struct node {     long long x, y;     int id;     bool operator<(const node& b) const {       if (y != b.y)         return y < b.y;       else         return x < b.x;     }   } a[210000], b[210000], c, d[210000];   vector<node> q;   int n, num, last;   int ans[210000];   set<node> s;   int main() {     cin >> n;     for (int i = 1; i <= n; i++)       cin >> a[i].x >> a[i].y, a[i].id = i, d[i] = a[i];     sort(a + 1, a + 1 + n);     for (int i = n; i >= 1; i--)       if (a[i].x > last) last = a[i].x, b[++num] = a[i];     reverse(b + 1, b + 1 + num);     for (int i = 1; i <= num; i++) {       while (q.size() > 1) {         node c = q[q.size() - 1], d = q[q.size() - 2];         if ((c.y - d.y) * d.x * b[i].y * (c.x - b[i].x) <             (b[i].y - c.y) * b[i].x * d.y * (d.x - c.x))           q.pop_back();         else           break;       }       q.push_back(b[i]);     }     num = 0;     for (int i = 0; i < q.size(); i++) s.insert(q[i]);     for (int i = 1; i <= n; i++)       if (s.count(d[i])) printf( %d  , i);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n, a, b;       cin >> n >> a >> b;       int N = n;       if (abs(a - b) > 1) {         cout << -1 <<   n ;         continue;       }       if (a + b > n - 2) {         cout << -1 <<   n ;         continue;       }       bool flag = false;       if (a < b) {         swap(a, b);         flag = true;       }       int A = a;       int B = b;       int sol[n];       int i = 1;       while (a--) {         sol[i] = n;         i += 2;         n--;       }       i = 2;       int temp = 1;       while (b--) {         sol[i] = temp;         i += 2;         temp++;       }       sol[0] = B + 1;       temp = B + 2;       int index = A + B + 1;       if (B == A) {         while (index != N) {           sol[index] = temp;           temp++;           index++;         }       } else {         temp = N - A;         while (index != N) {           sol[index] = temp;           temp--;           index++;         }       }       if (flag) {         for (int i = 0; i < N; i++) {           sol[i] = N + 1 - sol[i];         }       }       for (int i = 0; i < N; i++) {         cout << sol[i] <<    ;       }       cout <<   n ;     }     cerr <<  Time :   << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC          <<  ms n ;     return 0;   }


#include <bits/stdc++.h>   char str[110];   int main() {     int len, t, _max = 0;     scanf( %s , str);     len = strlen(str);     for (int i = 0; i < len; i++)       for (int j = i + 1; j < len; j++) {         t = 0;         while (str[i + t] == str[j + t]) t++;         if (t > _max) _max = t;       }     printf( %d , _max);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 100;   long long n, m, dp[N][N], a[N][N], b[N][N], c[N], len;   char go[N][N][N];   char str[N << 1];   inline long long read() {     long long sym = 0, res = 0;     char ch = 0;     while (!isdigit(ch)) sym |= (ch ==  - ), ch = getchar();     while (isdigit(ch)) res = (res << 3) + (res << 1) + (ch ^ 48), ch = getchar();     return sym ? -res : res;   }   void file() {     freopen( read.in ,  r , stdin);     freopen( write.out ,  w , stdout);   }   long long power(long long a, long long x) {     long long res = 1;     while (x) {       if (x & 1) res *= a;       a *= a;       x >>= 1;     }     return res;   }   void write(long long now, long long x, long long y, char ch) {     if (now == 0) {       printf( %c , ch);       return;     }     if (go[now][x][y] ==  H )       write(now - 1, x - 1, y,  H );     else       write(now - 1, x, y - 1,  M );     if (now != len) printf( %c , ch);   }   signed main() {     n = read();     len = n << 1;     scanf( %s , str + 1);     for (long long i = 1; i <= len; i++) {       c[i] = str[i] -  0 ;     }     for (long long i = 1; i <= n; i++) {       a[i][i] = a[i - 1][i - 1] + c[i] * power(10, n - i);       go[i][i][0] =  H ;       b[i][i] = b[i - 1][i - 1] + c[i] * power(10, n - i);       go[i][0][i] =  M ;     }     for (long long i = 1; i <= len; i++) {       for (long long j = max(i - n, 1ll); j <= min(i - 1ll, n); j++) {         long long k = i - j, ta = c[i] * power(10, n - j),                   tb = c[i] * power(10, n - k);         if (a[i - 1][j - 1] + ta + b[i - 1][k] >             b[i - 1][k - 1] + tb + a[i - 1][j]) {           a[i][j] = a[i - 1][j - 1] + ta;           b[i][k] = b[i - 1][k];           go[i][j][k] =  H ;         } else {           b[i][k] = b[i - 1][k - 1] + tb;           a[i][j] = a[i - 1][j];           go[i][j][k] =  M ;         }       }     }     write(len, n, n,    );     return 0;   }


#include<bits/stdc++.h>   #define ll long long   #define vi vector<int>   #define vl vector<ll>    #define pb push_back   #define FASTANDFURIOUS ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);   #define rep(i,a,b) for(ll i=a;i<b;i++)   #define For(i,n) for(ll i=0;i<n;i++)   #define MOD 1000000007   #define MAX 100001   #define pll pair <ll,ll>   #define pii pair <int,int>   #define dbg(x)    cout << #x <<  :   << x << endl;   #define fi first   #define se second   #define read(n,v) For(i,n)cin>>v[i]   #define mkp make_pair   #define YES cout<< YES n ;   #define NO cout<< NO n ;   #define No cout<< No n ;   #define Yes cout<< Yes n ;   #define INF 1e18   using namespace std;        ll ncr2(ll n, ll k )   {       if (k > n) return 0;       if (k * 2 > n) k = n-k;       if (k == 0) return 1;           ll result = n;       for(ll i = 2; i <= k; ++i ) {           result = result * (n-i+1);           result /= i;       }       return result;   }   ll pow(ll x, unsigned int y, int p){       ll res=1;       x=x%p;       if (x==0) return 0;       while (y > 0)       {           if (y & 1)               res = (res*x) % p;           y = y>>1;           x = (x*x) % p;       }       return res;   }   ll _pow(ll a, ll b){       if(!b)           return 1;       ll temp = _pow(a, b / 2);       temp = (temp * temp);       if(b % 2)           return (a * temp);       return temp;   }   ll invmod(ll a,ll m){       return pow(a,m-2,m);   }   ll feelthepower(ll x,ll y){       ll res = 1LL;       while(y){           if(y&1){               res = (res*1LL*x)%MOD;           }           x = (x*1LL*x)%MOD;           y/=2;       }       return res;   }   // ll ncr(ll n,ll r)   // {   //     if(n<r)   //         return 0;   //     ll ans=fac[n];   //     ans*=invmod(fac[n-r],MOD);   //     ans%=MOD;   //     ans*=invmod(fac[r],MOD);   //     ans%=MOD;   //     return ans;   // }   bool has(int kek,int d){       while(kek){           int temp = kek%10;           if(temp == d){               return true;           }           kek/=10;       }       return false;   }   signed main(){       FASTANDFURIOUS;       #ifndef ONLINE_JUDGE       freopen( input.txt ,  r , stdin);       freopen( output.txt ,  w , stdout);       #endif       int tc=1;       cin>>tc;       For(ti,tc){           int n,d;           cin>>n>>d;           For(i,n){               string s;               cin>>s;               if(s.length()>2){                   cout<< YES n ;               }               else{                   int req = stoi(s);                   int flag=0;                   while(req>=0){                       if(has(req,d)){                           flag=1;                           break;                       }                       else{                           req-=d;                      }                   }                   if(flag){                       cout<< YES n ;                   }                   else{                       cout<< NO n ;                   }               }           }       }   }


#include <bits/stdc++.h>   using namespace std;   long long int a1, b1, a2, b2;   int main() {     scanf( %lld %lld , &a1, &b1);     scanf( %lld %lld , &a2, &b2);     long long int p, q, ans = 0;     p = (a1 * b1);     q = (a2 * b2);     long long int tp = 0, tq = 0, thp = 0, thq = 0;     while ((p % 3) == 0) {       p = (p / 3);       thp++;     }     while ((q % 3) == 0) {       q = (q / 3);       thq++;     }     while ((p % 2) == 0) {       p = (p / 2);       tp++;     }     while ((q % 2) == 0) {       q = (q / 2);       tq++;     }     p = (a1 * b1);     q = (a2 * b2);     long long int x;     if (thp > thq) {       tp = tp + (thp - thq);       ans = ans + (thp - thq);       x = (thp - thq);       while (x--) {         if ((a1 % 3) == 0)           a1 = ((a1 / 3) * 2);         else           b1 = ((b1 / 3) * 2);       }     } else if (thq > thp) {       tq = tq + (thq - thp);       ans = ans + (thq - thp);       x = (thq - thp);       while (x--) {         if ((a2 % 3) == 0)           a2 = ((a2 / 3) * 2);         else           b2 = ((b2 / 3) * 2);       }     }     if (tp > tq) {       ans = ans + (tp - tq);       x = (tp - tq);       while (x--) {         if ((a1 % 2) == 0)           a1 = (a1 / 2);         else           b1 = (b1 / 2);       }     } else {       ans = ans + (tq - tp);       x = (tq - tp);       while (x--) {         if ((a2 % 2) == 0)           a2 = (a2 / 2);         else           b2 = (b2 / 2);       }     }     if ((a1 * b1) == (a2 * b2)) {       printf( %lld n , ans);       printf( %lld %lld n , a1, b1);       printf( %lld %lld n , a2, b2);     } else       printf( -1 n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   int t, k, l[1005], r[1005], lenl, lenr;   long long f[1005][1005][2];   long long dfs(int *x, int Index, int d, int q, int lim) {     if (Index < 1) return (long long)q;     if (!lim && f[Index][d][q] != -1) return f[Index][d][q];     long long res = 0;     int up = lim ? x[Index] : 9;     for (int i = 0; i <= up; i++) {       if (i != 4 && i != 7)         res = (res + dfs(x, Index - 1, max(d - 1, 0), q, lim && i == up)) % mod;       else         res = (res + dfs(x, Index - 1, k, q || d, lim && i == up)) % mod;     }     if (!lim) f[Index][d][q] = res;     return res;   }   long long solve(int *x, int len) { return dfs(x, len, 0, 0, 1); }   int main() {     scanf( %d %d , &t, &k);     memset(f, -1, sizeof f);     while (t--) {       char now[1005];       scanf( %s , now + 1);       lenl = strlen(now + 1);       for (int i = 1; i <= lenl; i++) l[lenl - i + 1] = now[i] - 48;       scanf( %s , now + 1);       lenr = strlen(now + 1);       for (int i = 1; i <= lenr; i++) r[lenr - i + 1] = now[i] - 48;       l[1]--;       int Index = 1;       while (l[Index] < 0) {         l[Index] = 9;         l[Index + 1]--;         Index++;       }       if (Index == lenl && !l[Index]) lenl--;       printf( %lld n , (solve(r, lenr) - solve(l, lenl) + mod) % mod);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     long long ans = 0;     for (int i = (0); i < (n); ++i) {       long long t, T, x, cost;       cin >> t >> T >> x >> cost;       if (t >= T) {         ans += cost + m * x;         continue;       }       long long aux1 = cost;       if (m > (T - t)) aux1 += m * x;       long long aux2 = (long long)ceil((double)(m - (T - t)) / (T - t)) + 1;       aux2 *= cost;       ans += min(aux1, aux2);     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   pair<pair<int, int>, int> a[100001];   pair<int, int> ans[100001];   int n, m, i, j, k, l, r, t, last, b[100001], x, y;   map<int, pair<int, int> > mp;   int main() {     cin >> n >> m;     for (i = 0; i < m; i++) {       cin >> a[i].first.first >> a[i].first.second;       a[i].first.second = 1 - a[i].first.second;       b[i] = a[i].first.first;       a[i].second = i;     }     sort(a, a + m);     if (a[0].first.second || a[1].first.second) {       cout << -1;       return 0;     }     k = 3;     for (i = 2; i < m; i++) {       if (a[i].first.second) {         if (t == (k - 2) * (k - 1) / 2) {           cout << -1;           return 0;         }         t++;         continue;       }       k++;     }     t = 2;     for (i = 0; i < m; i++) {       if (!a[i].first.second) {         ans[a[i].second].first = t - 1;         ans[a[i].second].second = t;         t++;       }     }     x = 3;     y = 1;     for (i = 0; i < m; i++) {       if (!a[i].first.second) continue;       ans[a[i].second].first = y;       ans[a[i].second].second = x;       y++;       if (x == y + 1) {         x++;         y = 1;       }     }     for (i = 0; i < m; i++) {       cout << ans[i].first <<     << ans[i].second << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const int inv = 1000000000;   const int minv = -inv;   const int max_n = 500000 + 5;   const int max_cn2 = max_n / 2 + 5;   int n, cn2, fn2;   int a[max_cn2];   int x;   long long q[max_cn2];   int main() {     scanf( %d , &n);     cn2 = (n + 1) / 2;     fn2 = n / 2;     long long suma = 0ll;     for (int i = 0; i < cn2; ++i) {       scanf( %d , &a[i]);       suma += ((long long)(a[i]));     }     scanf( %d , &x);     suma += ((long long)(fn2)) * ((long long)(x));     if (suma > 0ll) {       printf( %d n , n);       return 0;     }     if (x >= 0) {       printf( %d n , -1);       return 0;     }     q[0] = 0ll;     for (int i = 1; i < n - fn2; ++i)       q[i] = min(q[i - 1] + ((long long)(a[i - 1] - x)), 0ll);     long long rsum = ((long long)(fn2)) * ((long long)(x));     for (int k = fn2 + 1; k < n; ++k) {       rsum += ((long long)(a[n - k]));       if (rsum + q[n - k] > 0ll) {         printf( %d n , k);         return 0;       }     }     printf( %d n , -1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1000 * 1000 * 1000 + 7;   const long long LINF = 1LL * INF * INF;   const int MAX = 1e5 + 7;   const double PI = acos(-1.);   const double EPS = 1e-7;   const int MOD = 998244353;   const int MAXF = 1000000000;   int dx[] = {1, -1, 0, 0};   int dy[] = {0, 0, -1, 1};   bool isInField(int x, int y) {     return 1 <= x && x <= MAXF && 1 <= y && y <= MAXF;   }   bool isWhite(int x, int y) { return x % 2 == y % 2; }   void solve() {     int black, white;     cin >> black >> white;     map<pair<int, int>, int> was;     vector<pair<int, int> > ans;     int sX = 200000, sY = 200000;     if (black > white) {       sX++;       --black;     } else {       --white;     }     ans.emplace_back(sX, sY);     was[{sX, sY}] = 1;     while (black > 0 && white > 0) {       --black;       --white;       ++sX;       ans.emplace_back(sX, sY);       was[{sX, sY}] = 1;       ++sX;       ans.emplace_back(sX, sY);       was[{sX, sY}] = 1;     }     for (int i = 0; i < (((int)ans.size())); ++i) {       int x = ans[i].first;       int y = ans[i].second;       for (int j = 0; j < (4); ++j) {         int a = x + dx[j];         int b = y + dy[j];         if (black > 0) {           if (!was.count({a, b}) && !isWhite(a, b)) {             --black;             ans.emplace_back(a, b);             was[{a, b}] = 1;           }         } else if (white > 0) {           if (!was.count({a, b}) && isWhite(a, b)) {             --white;             ans.emplace_back(a, b);             was[{a, b}] = 1;           }         }       }     }     if (black != 0 || white != 0) {       cout <<  NO n ;       return;     }     cout <<  YES n ;     for (auto [x, y] : ans) {       cout << x <<     << y << endl;     }   }   int main() {     ios_base::sync_with_stdio(0);     int q;     cin >> q;     while (q--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   typedef long long ll;   #define mod 1000000007      int main(){       int n;cin>>n;       int summ = 0;       while(n>9){           int summ = 0;           while(n>9){               summ = summ + n%10;               n = n/10;           }           summ = summ + n;           n = summ;       }       cout<<n;       return 0;   }


#include <bits/stdc++.h>   using namespace std;   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     double d, L, v1, v2;     cin >> d >> L >> v1 >> v2;     double distance;     int i, r;     cout << fixed << setprecision(20) << (L - d) / (v1 + v2);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int key;   long long dis[1000];   struct pt {     long long x, y, z;   } f[8], point[8];   long long meow(int a, int b) {     long long ta, tb, tc;     ta = f[a].x - f[b].x;     tb = f[a].y - f[b].y;     tc = f[a].z - f[b].z;     return (ta * ta + tb * tb + tc * tc);   }   int chk() {     int i, j, cnta, cntb, cntc, k;     long long dis, sq2, sq3, ik;     for (i = 0; i < 8; i++) {       for (j = 0; j < 8; j++) {         if (i != j && f[i].x == f[j].x && f[i].y == f[j].y && f[i].z == f[j].z)           return false;       }     }     for (i = 0; i < 8; i++) {       for (j = 0; j < 8; j++) {         dis = meow(i, j);         cnta = cntb = cntc = 0;         for (k = 0; k < 8; k++) {           ik = meow(i, k);           if (ik == dis) cnta++;           if (ik == dis * 2) cntb++;           if (ik == dis * 3) cntc++;         }         if (cnta == 3 && cntb == 3 && cntc == 1) break;       }       if (j == 8) return false;     }     return true;   }   void go(int r) {     if (r == 8) {       if (chk()) {         key = 1;         cout <<  YES  << endl;         for (int i = 0; i < 8; i++)           cout << f[i].x <<     << f[i].y <<     << f[i].z << endl;       }       return;     }     f[r] = point[r];     go(r + 1);     if (key) return;     swap(f[r].x, f[r].y);     go(r + 1);     if (key) return;     swap(f[r].y, f[r].z);     go(r + 1);     if (key) return;     swap(f[r].x, f[r].y);     go(r + 1);     if (key) return;     swap(f[r].y, f[r].z);     go(r + 1);     if (key) return;     swap(f[r].x, f[r].y);     go(r + 1);     return;   }   int main() {     int i;     for (i = 0; i < 8; i++) cin >> point[i].x >> point[i].y >> point[i].z;     key = 0;     f[0] = point[0];     go(1);     if (!key) cout <<  NO  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   void read(T &x) {     x = 0;     char c;     for (c = getchar(); !isdigit(c); c = getchar())       ;     for (; isdigit(c); c = getchar()) x = x * 10 + c -  0 ;   }   const int N = 255, P = 998244353, oo = 0x3f3f3f3f;   int mul(int a, int b) { return 1ll * a * b % P; }   int add(int a, int b) {     a += b;     return a >= P ? a - P : a;   }   int sub(int a, int b) {     a -= b;     return a < 0 ? a + P : a;   }   int gcd(int a, int b) { return !b ? a : gcd(b, a % b); }   namespace Dinic {   const int S = N * N;   struct Edge {     int d, cap, nxt;   } es[S << 2];   int vn, g[S], lev[S], itr[S], q[S], h, t, en = 1;   void add(int s, int d, int cap) {     es[++en] = (Edge){d, cap, g[s]}, g[s] = en;     es[++en] = (Edge){s, 0, g[d]}, g[d] = en;   }   void bfs(int s) {     int v;     memset(lev, -1, sizeof(lev));     h = t = 0;     q[t++] = s;     lev[s] = 0;     while (h < t) {       v = q[h++];       for (int i = g[v], d = es[i].d; i; i = es[i].nxt, d = es[i].d) {         if (es[i].cap > 0 && lev[d] < 0) {           lev[d] = lev[v] + 1;           q[t++] = es[i].d;         }       }     }   }   int dfs(int v, int t, int f) {     if (v == t) return f;     for (int &i = itr[v]; i; i = es[i].nxt) {       if (es[i].cap <= 0 || lev[es[i].d] <= lev[v]) continue;       int a = dfs(es[i].d, t, min(es[i].cap, f));       if (a <= 0) continue;       es[i].cap -= a;       es[i ^ 1].cap += a;       return a;     }     return 0;   }   int sol(int s, int t) {     int i, res = 0, a;     while (true) {       bfs(s);       if (lev[t] < 0) break;       for (i = 0; i <= vn; ++i) itr[i] = g[i];       for (a = dfs(s, t, oo); a > 0; a = dfs(s, t, oo)) {         res += a;       }     }     return res;   }   }  // namespace Dinic   using namespace Dinic;   int n, m;   vector<int> xx, yy;   struct Rec {     int x1, y1, x2, y2;   } rec[N];   int f(vector<int> &a, int x) {     return lower_bound(a.begin(), a.end(), x) - a.begin() + 1;   }   int main(int argc, char *argv[]) {     scanf( %d%d , &n, &m);     for (int i = 1; i <= (m); ++i) {       int x1, y1, x2, y2;       scanf( %d%d%d%d , &x1, &y1, &x2, &y2);       --x1, --y1;       xx.push_back(x1), xx.push_back(x2);       yy.push_back(y1), yy.push_back(y2);       rec[i] = (Rec){x1, y1, x2, y2};     }     xx.push_back(0), yy.push_back(0);     sort(xx.begin(), xx.end()), sort(yy.begin(), yy.end());     xx.erase(unique(xx.begin(), xx.end()), xx.end());     yy.erase(unique(yy.begin(), yy.end()), yy.end());     int sx = xx.size(), sxy = sx + yy.size(), src = sxy + m + 1, snk = src + 1;     vn = snk;     for (int i = 1; i < (xx.size()); ++i) {       add(src, i + 1, xx[i] - xx[i - 1]);     }     for (int i = 1; i < (yy.size()); ++i) {       add(sx + i + 1, snk, yy[i] - yy[i - 1]);     }     for (int i = 1; i <= (m); ++i) {       int x1 = rec[i].x1, x2 = rec[i].x2, y1 = rec[i].y1, y2 = rec[i].y2;       x1 = f(xx, x1);       x2 = f(xx, x2);       y1 = f(yy, y1);       y2 = f(yy, y2);       for (int j = x1 + 1; j <= x2; ++j) add(j, sxy + i, oo);       for (int j = y1 + 1; j <= y2; ++j) add(sxy + i, sx + j, oo);     }     cout << sol(src, snk) << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1e9;   const int MX = 3001;   map<pair<int, int>, bool> forbidden[MX];   struct Graph {     int d[MX][MX];     int parent[MX][MX];     vector<int> adj[MX];     void addEdge(int u, int v) {       adj[u].push_back(v);       adj[v].push_back(u);     }     vector<int> bfs(int s, int n) {       for (int i = 0; i < n; i++) {         for (int j = 0; j < n; j++) {           d[i][j] = INF;           parent[i][j] = -1;         }       }       d[n][s] = 0;       deque<pair<int, int>> q;       q.push_back({n, s});       while (!q.empty()) {         int a = q.front().first;         int b = q.front().second;         q.pop_front();         for (int c : adj[b]) {           if (d[b][c] == INF && !forbidden[a][{b, c}]) {             d[b][c] = d[a][b] + 1;             parent[b][c] = a;             q.push_back({b, c});           }         }       }       int minDistance = INF;       for (int i = 0; i < n; i++) {         minDistance = min(minDistance, d[i][n - 1]);       }       if (minDistance == INF) return {};       int prev = -1;       for (int i = 0; i < n; i++) {         if (d[i][n - 1] == minDistance) {           prev = i;           break;         }       }       vector<int> path = {n};       int cur = n - 1;       while (prev != n) {         path.push_back(prev + 1);         int aux = prev;         prev = parent[prev][cur];         cur = aux;       }       reverse(path.begin(), path.end());       return path;     }   } G;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int n, m, k;     cin >> n >> m >> k;     for (int i = 0; i < m; i++) {       int u, v;       cin >> u >> v;       u--;       v--;       G.addEdge(u, v);     }     for (int i = 0; i < k; i++) {       int a, b, c;       cin >> a >> b >> c;       a--;       b--;       c--;       forbidden[a][{b, c}] = true;     }     vector<int> path = G.bfs(0, n);     cout << (int)path.size() - 1 <<   n ;     for (int u : path) cout << u <<    ;     cout <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void err(istream_iterator<string> it) {}   template <typename T, typename... Args>   void err(istream_iterator<string> it, T a, Args... args) {     cerr << *it <<   =   << a << endl;     err(++it, args...);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n, m, a;     cin >> n >> m;     vector<int> cost(m);     for (int i = 0; i < m; i++) cin >> a >> cost[i];     sort(cost.begin(), cost.end(), greater<int>());     int k = 1;     while (true) {       int nxtk = k + 1;       int need = nxtk * (nxtk - 1) / 2;       if (nxtk % 2 == 0) need += nxtk / 2 - 1;       if (need <= (n - 1) && nxtk <= m)         k = nxtk;       else         break;     }     long long res = 0;     for (int i = 0; i < k; i++) res += cost[i];     cout << res;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e+6 + 5;   int lp[N], ans = 1e+9;   set<int> factors;   void factorise(int n, int isv) {     int cnt = 0, ans = 0, n1 = n;     while (n % 2 == 0) {       cnt++;       n = n / 2;     }     if (cnt) {       ans = max(ans, 2);       if (isv) factors.insert(2);     }     for (int i = 3; i * i <= n; i++) {       cnt = 0;       while (n % i == 0) {         cnt++;         n = n / i;       }       if (cnt) {         ans = max(ans, i);         if (isv) factors.insert(i);       }     }     if (n > 1) {       ans = max(ans, n);       if (isv) factors.insert(n);     }     lp[n1] = ans;   }   int main() {     int x;     cin >> x;     for (int i = 2; i <= x; i++) factorise(i, i == x);     for (auto it : factors) {       int i = x - it + 1;       for (i; i <= x; i++) {         if (lp[i] != i) ans = min(ans, i - lp[i] + 1);       }     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   int a, s, d, f, g, h, j, k, l, i, n, m;   int main() {     cin >> n >> m >> k;     l = n * m * k / 100;     for (i = 0; i < n; i++) {       if (l > m) {         cout << m;         l = l - m;       } else if (l > 0) {         cout << l;         l = 0;       } else         cout << 0;       cout <<    ;     }   }