#include <bits/stdc++.h>   #pragma GCC optimize( O2 )   using namespace std;   const int N = 1e5 + 10;   const long long mod = 1e9 + 7;   const long long mod2 = 998244353;   const int inf = 1e9;   const int LOG = 22;   long long pw(long long a, long long b, long long M) {     return (!b ? 1                : (b & 1 ? (a * pw(a * a % M, b / 2, M)) % M                         : pw(a * a % M, b / 2, M)));   }   struct node {     int mx1, mx2, cnt, lz;     long long sum;     node(int m1 = -inf, int m2 = -inf, int c = 0, int l = inf, long long s = 0) {       mx1 = m1, mx2 = m2, cnt = c, lz = l, sum = s;     }     friend node operator|(node L, node R) {       if (L.mx1 < R.mx1) swap(L, R);       if (L.mx1 == R.mx1)         L.cnt += R.cnt;       else         L.mx2 = max(L.mx2, R.mx1);       L.mx2 = max(L.mx2, R.mx2);       L.sum += R.sum;       L.lz = inf;       return L;     }   };   struct segment_beats {     node seg[N << 2];     void shift(int v, int lz) {       seg[v].lz = min(seg[v].lz, lz);       seg[v].sum -= 1ll * seg[v].cnt * max(0, seg[v].mx1 - lz);       seg[v].mx1 = min(seg[v].mx1, lz);     }     void second(int v, int tl, int tr) {       if (tl == tr) return;       shift(v << 1, seg[v].lz);       shift(v << 1 | 1, seg[v].lz);     }     void change(int p, int x, int v = 1, int tl = 1, int tr = N - 1) {       second(v, tl, tr);       if (p > tr || p < tl) return;       if (tl == tr) {         seg[v] = node(x, -inf, 1, inf, x);         return;       }       int mid = (tl + tr) >> 1;       change(p, x, v << 1, tl, mid), change(p, x, v << 1 | 1, mid + 1, tr);       seg[v] = seg[v << 1] | seg[v << 1 | 1];     }     void upd(int l, int r, int x, int v = 1, int tl = 1, int tr = N - 1) {       second(v, tl, tr);       if (l > tr || r < tl || l > r || seg[v].mx1 <= x) return;       if (l <= tl && tr <= r && seg[v].mx2 < x) {         shift(v, x);         return;       }       int mid = (tl + tr) >> 1;       upd(l, r, x, v << 1, tl, mid), upd(l, r, x, v << 1 | 1, mid + 1, tr);       seg[v] = seg[v << 1] | seg[v << 1 | 1];     }     long long get(int l, int r, int v = 1, int tl = 1, int tr = N - 1) {       second(v, tl, tr);       if (l > tr || r < tl || l > r) return 0ll;       if (l <= tl && tr <= r) {         return seg[v].sum;       }       int mid = (tl + tr) >> 1;       return get(l, r, v << 1, tl, mid) + get(l, r, v << 1 | 1, mid + 1, tr);     }   } seg1, seg2;   struct segment {     int lz[N << 2];     segment() {       for (int i = 0; i < N << 2; i++) lz[i] = inf;     }     void upd(int l, int r, int x, int v = 1, int tl = 1, int tr = N - 1) {       if (l > tr || r < tl || l > r) return;       if (l <= tl && tr <= r) {         lz[v] = min(lz[v], x);         return;       }       int mid = (tl + tr) >> 1;       upd(l, r, x, v << 1, tl, mid), upd(l, r, x, v << 1 | 1, mid + 1, tr);     }     int ask(int p, int v = 1, int tl = 1, int tr = N - 1) {       if (tl == tr) {         return lz[v];       }       int mid = (tl + tr) >> 1;       if (p <= mid) {         return min(lz[v], ask(p, v << 1, tl, mid));       }       return min(lz[v], ask(p, v << 1 | 1, mid + 1, tr));     }   } Seg1, Seg2;   set<int> st1, st2;   int main() {     for (int i = 1; i < N; i++) st1.insert(i), st2.insert(i);     int n;     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       int tp, l, r;       scanf( %d%d%d , &tp, &l, &r);       r--;       if (tp == 1) {         int x;         scanf( %d , &x);         if (x < 0) {           x = abs(x);           seg1.upd(l, r, x);           Seg1.upd(l, r, x);           while (1) {             auto it = st1.lower_bound(l);             if (it == st1.end() || *it > r) break;             int cu = *it;             st1.erase(cu);             if (st2.count(cu) == 0) {               seg1.change(cu, x);               seg2.change(cu, Seg2.ask(cu));             }           }         } else {           seg2.upd(l, r, x);           Seg2.upd(l, r, x);           while (1) {             auto it = st2.lower_bound(l);             if (it == st2.end() || *it > r) break;             int cu = *it;             st2.erase(cu);             if (st1.count(cu) == 0) {               seg2.change(cu, x);               seg1.change(cu, Seg1.ask(cu));             }           }         }       } else {         printf( %lld n , seg1.get(l, r) + seg2.get(l, r));       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = 1LL << 60;   string operator*(const string& s, int k) {     if (k == 0) return   ;     string p = (s + s) * (k / 2);     if (k % 2 == 1) p += s;     return p;   }   template <class T>   inline bool chmin(T& a, T b) {     if (a > b) {       a = b;       return true;     }     return false;   }   template <class T>   inline bool chmax(T& a, T b) {     if (a < b) {       a = b;       return true;     }     return false;   }   struct Edge {     long long to, cap, rev;     Edge(long long _to, long long _cap, long long _rev) {       to = _to;       cap = _cap;       rev = _rev;     }   };   void add_edge(vector<vector<Edge>>& G, long long from, long long to,                 long long cap, bool revFlag, long long revCap) {     G[from].push_back(Edge(to, cap, (long long)G[to].size()));     if (revFlag)       G[to].push_back(Edge(from, revCap, (long long)G[from].size() - 1));   }   long long max_flow_dfs(vector<vector<Edge>>& G, long long v, long long t,                          long long f, vector<bool>& used) {     if (v == t) return f;     used[v] = true;     for (int i = 0; i < G[v].size(); ++i) {       Edge& e = G[v][i];       if (!used[e.to] && e.cap > 0) {         long long d = max_flow_dfs(G, e.to, t, min(f, e.cap), used);         if (d > 0) {           e.cap -= d;           G[e.to][e.rev].cap += d;           return d;         }       }     }     return 0;   }   long long max_flow(vector<vector<Edge>>& G, long long s, long long t) {     long long flow = 0;     for (;;) {       vector<bool> used(G.size());       for (int(i) = (int)(0); i < (int)(used.size()); i++) used[i] = false;       long long f = max_flow_dfs(G, s, t, INF, used);       if (f == 0) {         return flow;       }       flow += f;     }   }   void BellmanFord(vector<vector<Edge>>& G, long long s, vector<long long>& d,                    vector<long long>& negative) {     d.resize(G.size());     negative.resize(G.size());     for (int(i) = (int)(0); i < (int)(d.size()); i++) d[i] = INF;     for (int(i) = (int)(0); i < (int)(d.size()); i++) negative[i] = false;     d[s] = 0;     for (int(k) = (int)(0); k < (int)(G.size() - 1); k++) {       for (int(i) = (int)(0); i < (int)(G.size()); i++) {         for (int(j) = (int)(0); j < (int)(G[i].size()); j++) {           if (d[i] != INF && d[G[i][j].to] > d[i] + G[i][j].cap) {             d[G[i][j].to] = d[i] + G[i][j].cap;           }         }       }     }     for (int(k) = (int)(0); k < (int)(G.size() - 1); k++) {       for (int(i) = (int)(0); i < (int)(G.size()); i++) {         for (int(j) = (int)(0); j < (int)(G[i].size()); j++) {           if (d[i] != INF && d[G[i][j].to] > d[i] + G[i][j].cap) {             d[G[i][j].to] = d[i] + G[i][j].cap;             negative[G[i][j].to] = true;           }           if (negative[i] == true) negative[G[i][j].to] = true;         }       }     }   }   void Dijkstra(vector<vector<Edge>>& G, long long s, vector<long long>& d) {     d.resize(G.size());     for (int(i) = (int)(0); i < (int)(d.size()); i++) d[i] = INF;     d[s] = 0;     priority_queue<pair<long long, long long>, vector<pair<long long, long long>>,                    greater<pair<long long, long long>>>         q;     q.push(make_pair(0, s));     while (!q.empty()) {       pair<long long, long long> a = q.top();       q.pop();       if (d[a.second] < a.first) continue;       for (int(i) = (int)(0); i < (int)(G[a.second].size()); i++) {         Edge e = G[a.second][i];         if (d[e.to] > d[a.second] + e.cap) {           d[e.to] = d[a.second] + e.cap;           q.push(make_pair(d[e.to], e.to));         }       }     }   }   void WarshallFloyd(vector<vector<Edge>>& G, vector<vector<long long>>& d) {     d.resize(G.size());     for (int(i) = (int)(0); i < (int)(d.size()); i++) d[i].resize(G.size());     for (int(i) = (int)(0); i < (int)(d.size()); i++) {       for (int(j) = (int)(0); j < (int)(d[i].size()); j++) {         d[i][j] = INF;       }     }     for (int(i) = (int)(0); i < (int)(G.size()); i++) {       for (int(j) = (int)(0); j < (int)(G[i].size()); j++) {         d[i][G[i][j].to] = G[i][j].cap;       }     }     for (int(i) = (int)(0); i < (int)(G.size()); i++) {       for (int(j) = (int)(0); j < (int)(G.size()); j++) {         for (int(k) = (int)(0); k < (int)(G.size()); k++) {           chmin(d[j][k], d[j][i] + d[i][k]);         }       }     }   }   bool tsort(vector<vector<Edge>>& graph, vector<int>& order) {     int n = graph.size(), k = 0;     vector<long long> in(n);     for (auto& es : graph)       for (auto& e : es) in[e.to]++;     priority_queue<long long, vector<long long>, greater<long long>> que;     for (int(i) = (int)(0); i < (int)(n); i++)       if (in[i] == 0) que.push(i);     while (que.size()) {       int v = que.top();       que.pop();       order.push_back(v);       for (auto& e : graph[v])         if (--in[e.to] == 0) que.push(e.to);     }     if (order.size() != n)       return false;     else       return true;   }   class lca {    public:     const int n = 0;     const int log2_n = 0;     std::vector<std::vector<int>> parent;     std::vector<int> depth;     lca() {}     lca(const vector<vector<Edge>>& g, int root)         : n(g.size()),           log2_n(log2(n) + 1),           parent(log2_n, std::vector<int>(n)),           depth(n) {       dfs(g, root, -1, 0);       for (int k = 0; k + 1 < log2_n; k++) {         for (int v = 0; v < (int)g.size(); v++) {           if (parent[k][v] < 0)             parent[k + 1][v] = -1;           else             parent[k + 1][v] = parent[k][parent[k][v]];         }       }     }     void dfs(const vector<vector<Edge>>& g, int v, int p, int d) {       parent[0][v] = p;       depth[v] = d;       for (auto& e : g[v]) {         if (e.to != p) dfs(g, e.to, v, d + 1);       }     }     int get(int u, int v) {       if (depth[u] > depth[v]) std::swap(u, v);       for (int k = 0; k < log2_n; k++) {         if ((depth[v] - depth[u]) >> k & 1) {           v = parent[k][v];         }       }       if (u == v) return u;       for (int k = log2_n - 1; k >= 0; k--) {         if (parent[k][u] != parent[k][v]) {           u = parent[k][u];           v = parent[k][v];         }       }       return parent[0][u];     }   };   class UnionFind {     vector<int> data;     long long num;       public:     UnionFind(int size) : data(size, -1), num(size) {}     bool unite(int x, int y) {       x = root(x);       y = root(y);       if (x != y) {         if (data[y] < data[x]) swap(x, y);         data[x] += data[y];         data[y] = x;       }       num -= (x != y);       return x != y;     }     bool findSet(int x, int y) { return root(x) == root(y); }     int root(int x) { return data[x] < 0 ? x : data[x] = root(data[x]); }     int size(int x) { return -data[root(x)]; }     int numSet() { return num; }   };   class SumSegTree {    private:     long long _sum(long long a, long long b, long long k, long long l,                    long long r) {       if (r <= a || b <= l) return 0;       if (a <= l && r <= b)         return dat[k];       else {         long long s1 = _sum(a, b, 2 * k + 1, l, (l + r) / 2);         long long s2 = _sum(a, b, 2 * k + 2, (l + r) / 2, r);         return s1 + s2;       }     }       public:     long long n, height;     vector<long long> dat;     SumSegTree(long long _n) {       n = 1;       height = 1;       while (n < _n) {         n *= 2;         height++;       }       dat = vector<long long>(2 * n - 1, 0);     }     void add(long long i, long long x) {       i += n - 1;       dat[i] += x;       while (i > 0) {         i = (i - 1) / 2;         dat[i] += x;       }     }     long long sum(long long a, long long b) { return _sum(a, b, 0, 0, n); }   };   class RmqTree {    private:     long long _find(long long a, long long b, long long k, long long l,                     long long r) {       if (r <= a || b <= l) return INF;       if (a <= l && r <= b)         return dat[k];       else {         long long s1 = _find(a, b, 2 * k + 1, l, (l + r) / 2);         long long s2 = _find(a, b, 2 * k + 2, (l + r) / 2, r);         return min(s1, s2);       }     }       public:     long long n, height;     vector<long long> dat;     RmqTree(long long _n) {       n = 1;       height = 1;       while (n < _n) {         n *= 2;         height++;       }       dat = vector<long long>(2 * n - 1, INF);     }     void update(long long i, long long x) {       i += n - 1;       dat[i] = x;       while (i > 0) {         i = (i - 1) / 2;         dat[i] = min(dat[i * 2 + 1], dat[i * 2 + 2]);       }     }     long long find(long long a, long long b) { return _find(a, b, 0, 0, n); }   };   void divisor(long long n, vector<long long>& ret) {     for (long long i = 1; i * i <= n; i++) {       if (n % i == 0) {         ret.push_back(i);         if (i * i != n) ret.push_back(n / i);       }     }     sort(ret.begin(), ret.end());   }   vector<long long> lis_fast(const vector<long long>& a) {     const long long n = a.size();     vector<long long> A(n, INT_MAX);     vector<long long> id(n);     for (int i = 0; i < n; ++i) {       id[i] = distance(A.begin(), lower_bound(A.begin(), A.end(), a[i]));       A[id[i]] = a[i];     }     long long m = *max_element(id.begin(), id.end());     vector<long long> b(m + 1);     for (int i = n - 1; i >= 0; --i)       if (id[i] == m) b[m--] = a[i];     return b;   }   bool z_algorithm(string& str, vector<int>& z, long long s) {     const int L = str.size();     z.resize(str.size());     for (int i = 1, left = 0, right = 0; i < L; i++) {       if (i > right) {         left = right = i;         for (; right < L && str[right - left] == str[right]; right++)           ;         z[i] = right - left;         right--;       } else {         int k = i - left;         if (z[k] < right - i + 1) {           z[i] = z[k];         } else {           left = i;           for (; right < L && str[right - left] == str[right]; right++)             ;           z[i] = right - left;           right--;         }       }       if (z[i] == s) return true;     }     return false;   }   bool z_algorithm(string& str, vector<int>& z) {     const int L = str.size();     z.resize(str.size());     for (int i = 1, left = 0, right = 0; i < L; i++) {       if (i > right) {         left = right = i;         for (; right < L && str[right - left] == str[right]; right++)           ;         z[i] = right - left;         right--;       } else {         int k = i - left;         if (z[k] < right - i + 1) {           z[i] = z[k];         } else {           left = i;           for (; right < L && str[right - left] == str[right]; right++)             ;           z[i] = right - left;           right--;         }       }     }     return true;   }   struct RollingHash {     static const int base1 = 1007, base2 = 2009;     static const int mod1 = 1000000007, mod2 = 1000000009;     vector<long long> hash1, hash2, power1, power2;     RollingHash(const string& S) {       int n = (int)S.size();       hash1.assign(n + 1, 0);       hash2.assign(n + 1, 0);       power1.assign(n + 1, 1);       power2.assign(n + 1, 1);       for (int i = 0; i < n; ++i) {         hash1[i + 1] = (hash1[i] * base1 + S[i]) % mod1;         hash2[i + 1] = (hash2[i] * base2 + S[i]) % mod2;         power1[i + 1] = (power1[i] * base1) % mod1;         power2[i + 1] = (power2[i] * base2) % mod2;       }     }     inline pair<long long, long long> get(int l, int r) const {       long long res1 = hash1[r] - hash1[l] * power1[r - l] % mod1;       if (res1 < 0) res1 += mod1;       long long res2 = hash2[r] - hash2[l] * power2[r - l] % mod2;       if (res2 < 0) res2 += mod2;       return {res1, res2};     }     inline int getLCP(int a, int b) const {       int len = min((int)hash1.size() - a, (int)hash1.size() - b);       int low = 0, high = len;       while (high - low > 1) {         int mid = (low + high) >> 1;         if (get(a, a + mid) != get(b, b + mid))           high = mid;         else           low = mid;       }       return low;     }   };   long long mod_pow(long long x, long long n, long long mod) {     long long res = 1LL;     while (n > 0) {       if (n & 1) res = res * x % mod;       x = x * x % mod;       n >>= 1;     }     return res;   }   long long mod_inv(long long x, long long mod) {     return mod_pow(x, mod - 2, mod);   }   class Combination {    public:     vector<long long> fact;     vector<long long> inv;     long long mod;     long long mod_inv(long long x) {       long long n = mod - 2LL;       long long res = 1LL;       while (n > 0) {         if (n & 1) res = res * x % mod;         x = x * x % mod;         n >>= 1;       }       return res;     }     long long nCr(long long n, long long r) {       return ((fact[n] * inv[r] % mod) * inv[n - r]) % mod;     }     long long nPr(long long n, long long r) {       return (fact[n] * inv[n - r]) % mod;     }     long long nHr(long long n, long long r) { return nCr(r + n - 1, r); }     Combination(long long n, long long _mod) {       mod = _mod;       fact.resize(n + 1);       fact[0] = 1;       for (int(i) = (int)(0); i < (int)(n); i++) {         fact[i + 1] = (fact[i] * (i + 1LL)) % mod;       }       inv.resize(n + 1);       for (int(i) = (int)(0); i < (int)(n + 1); i++) {         inv[i] = mod_inv(fact[i]);       }     }   };   long long gcd(long long m, long long n) {     if (n == 0) return m;     return gcd(n, m % n);   }   long long lcm(long long m, long long n) { return m / gcd(m, n) * n; }   vector<vector<long long>> mIdentity(long long n) {     vector<vector<long long>> A(n, vector<long long>(n));     for (int i = 0; i < n; ++i) A[i][i] = 1;     return A;   }   vector<vector<long long>> mMul(const vector<vector<long long>>& A,                                  const vector<vector<long long>>& B) {     vector<vector<long long>> C(A.size(), vector<long long>(B[0].size()));     for (int i = 0; i < C.size(); ++i)       for (int j = 0; j < C[i].size(); ++j)         for (int k = 0; k < A[i].size(); ++k)           (C[i][j] += (A[i][k] % 1000000007) * (B[k][j] % 1000000007)) %=               1000000007;     return C;   }   vector<vector<long long>> mPow(const vector<vector<long long>>& A,                                  long long e) {     return e == 0       ? mIdentity(A.size())            : e % 2 == 0 ? mPow(mMul(A, A), e / 2)                         : mMul(A, mPow(A, e - 1));   }   template <class T>   class RectangleSum {    public:     vector<vector<T>> sum;     T GetSum(int left, int right, int top, int bottom) {       T res = sum[bottom][right];       if (left > 0) res -= sum[bottom][left - 1];       if (top > 0) res -= sum[top - 1][right];       if (left > 0 && top > 0) res += sum[top - 1][left - 1];       return res;     }     RectangleSum(const vector<vector<T>>& s, int h, int w) {       sum.resize(h);       for (int i = 0; i < h; i++) sum[i].resize(w, 0);       for (int y = 0; y < h; y++) {         for (int x = 0; x < w; x++) {           sum[y][x] = s[y][x];           if (y > 0) sum[y][x] += sum[y - 1][x];           if (x > 0) sum[y][x] += sum[y][x - 1];           if (y > 0 && x > 0) sum[y][x] -= sum[y - 1][x - 1];         }       }     }   };   long long _garner(vector<long long>& xs, vector<long long>& mods) {     int M = xs.size();     vector<long long> coeffs(M, 1), constants(M, 0);     for (int i = 0; i < M - 1; ++i) {       long long mod_i = mods[i];       long long v = (xs[i] - constants[i] + mod_i) % mod_i;       v = (v * mod_pow(coeffs[i], mod_i - 2, mod_i)) % mod_i;       for (int j = i + 1; j < M; j++) {         long long mod_j = mods[j];         constants[j] = (constants[j] + coeffs[j] * v) % mod_j;         coeffs[j] = (coeffs[j] * mod_i) % mod_j;       }     }     return constants.back();   }   template <typename T>   inline void bit_reverse(vector<T>& a) {     int n = a.size();     int i = 0;     for (int j = 1; j < n - 1; ++j) {       for (int k = n >> 1; k > (i ^= k); k >>= 1)         ;       if (j < i) swap(a[i], a[j]);     }   }   template <long long mod, long long primitive_root>   class NTT {    public:     long long get_mod() { return mod; }     void _ntt(vector<long long>& a, int sign) {       const int n = a.size();       assert((n ^ (n & -n)) == 0);       const long long g = primitive_root;       long long tmp = (mod - 1) * mod_pow(n, mod - 2, mod) % mod;       long long h = mod_pow(g, tmp, mod);       if (sign == -1) h = mod_pow(h, mod - 2, mod);       bit_reverse(a);       for (int m = 1; m < n; m <<= 1) {         const int m2 = 2 * m;         long long _base = mod_pow(h, n / m2, mod);         long long _w = 1;         for (int x = 0; x < m; ++x) {           for (int s = x; s < n; s += m2) {             long long u = a[s];             long long d = (a[s + m] * _w) % mod;             a[s] = (u + d) % mod;             a[s + m] = (u - d + mod) % mod;           }           _w = (_w * _base) % mod;         }       }     }     void ntt(vector<long long>& input) { _ntt(input, 1); }     void intt(vector<long long>& input) {       _ntt(input, -1);       const long long n_inv = mod_pow(input.size(), mod - 2, mod);       for (auto& x : input) x = (x * n_inv) % mod;     }     vector<long long> convolution(const vector<long long>& a,                                   const vector<long long>& b) {       int result_size = a.size() + b.size() - 1;       int n = 1;       while (n < result_size) n <<= 1;       vector<long long> _a = a, _b = b;       _a.resize(n, 0);       _b.resize(n, 0);       ntt(_a);       ntt(_b);       for (int i = 0; i < n; ++i) _a[i] = (_a[i] * _b[i]) % mod;       intt(_a);       _a.resize(result_size);       return _a;     }   };   vector<long long> convolution_ntt(vector<long long>& a, vector<long long>& b,                                     long long mod = 1224736769LL) {     for (auto& x : a) x %= mod;     for (auto& x : b) x %= mod;     long long maxval = max(a.size(), b.size()) *                        *max_element(a.begin(), a.end()) *                        *max_element(b.begin(), b.end());     if (maxval < 1224736769) {       NTT<1224736769, 3> ntt3;       return ntt3.convolution(a, b);     }     NTT<167772161, 3> ntt1;     NTT<469762049, 3> ntt2;     NTT<1224736769, 3> ntt3;     vector<long long> x1 = ntt1.convolution(a, b);     vector<long long> x2 = ntt2.convolution(a, b);     vector<long long> x3 = ntt3.convolution(a, b);     vector<long long> ret(x1.size());     vector<long long> mods{167772161, 469762049, 1224736769, mod};     for (int i = 0; i < x1.size(); ++i) {       vector<long long> xs{x1[i], x2[i], x3[i], 0};       ret[i] = _garner(xs, mods);     }     return ret;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     long long n, k;     cin >> n >> k;     long long mi = (n + 1) * n / 2;     long long ma = mi * 2 - (n / 2 + 1) * (n / 2);     if (n % 2 == 1) ma -= n / 2 + 1;     if (k < mi) {       cout << -1 << endl;       return 0;     }     cout << min(k, ma) << endl;     for (int(i) = (int)(0); i < (int)(n); i++) cout << i + 1 <<    ;     cout << endl;     if (k >= ma) {       for (int(i) = (int)(0); i < (int)(n); i++) cout << n - i <<    ;       cout << endl;       return 0;     }     long long rest = k - mi;     vector<long long> ans(n);     for (int(i) = (int)(0); i < (int)(n); i++) ans[i] = i + 1;     long long now = 0;     for (int i = n - 1; i >= 0; i--) {       if (rest >= i - now) {         swap(ans[i], ans[now]);         rest -= i - now;       } else {         swap(ans[i], ans[i - rest]);         break;       }       now++;     }     for (int(i) = (int)(0); i < (int)(n); i++) cout << ans[i] <<    ;     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int vis[100005], mark[100005];   vector<int> g[100005];   int prob = 0;   void dfs(int node, int k) {     mark[node] = k;     vis[node] = 1;     for (auto i : g[node]) {       if (!vis[i]) {         dfs(i, 1 - k);       } else {         if (mark[i] == k) {           prob = 1;         }       }     }   }   int main() {     int n, m;     cin >> n >> m;     for (int i = 0; i < m; i++) {       int u, v;       scanf( %d , &u);       scanf( %d , &v);       g[u].push_back(v);       g[v].push_back(u);     }     for (int i = 1; i <= n; i++) {       if (!vis[i]) dfs(i, 0);     }     if (prob) {       cout <<  -1 ;       return 0;     }     int k = 0;     for (int i = 1; i <= n; i++) {       if (mark[i] == 1) k++;     }     cout << k <<   n ;     for (int i = 1; i <= n; i++) {       if (mark[i] == 1) cout << i <<    ;     }     cout <<   n ;     k = 0;     for (int i = 1; i <= n; i++) {       if (mark[i] == 0) k++;     }     cout << k <<   n ;     for (int i = 1; i <= n; i++) {       if (mark[i] == 0) cout << i <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   T sqr(T x) {     return x * x;   }   template <typename T>   T abs(T x) {     return x < 0 ? -x : x;   }   template <typename T>   T gcd(T a, T b) {     return b ? gcd(b, a % b) : a;   }   set<vector<int> > s;   vector<pair<char, pair<int, int> > > ans;   bool rec(vector<int>& a) {     if (a.size() == 1) {       return a[0] == 24;     }     if (s.find(a) != s.end()) {       return false;     }     s.insert(a);     for (size_t i = 0; i < a.size(); ++i) {       for (size_t j = i + 1; j < a.size(); ++j) {         vector<int> b = a;         int x = a[i], y = a[j];         b.erase(b.begin() + j);         b.erase(b.begin() + i);         b.push_back(x + y);         ans.push_back(make_pair( + , make_pair(x, y)));         if (rec(b)) {           return true;         }         b.pop_back();         ans.pop_back();         b.push_back(y - x);         ans.push_back(make_pair( - , make_pair(y, x)));         if (rec(b)) {           return true;         }         b.pop_back();         ans.pop_back();         b.push_back(x - y);         ans.push_back(make_pair( - , make_pair(x, y)));         if (rec(b)) {           return true;         }         b.pop_back();         ans.pop_back();         b.push_back(x * y);         ans.push_back(make_pair( * , make_pair(x, y)));         if (rec(b)) {           return true;         }         b.pop_back();         ans.pop_back();       }     }     return false;   }   int main(int, char**) {     ios_base::sync_with_stdio(false);     int n;     cin >> n;     if (n < 4) {       cout <<  NO  << endl;       return 0;     }     cout <<  YES  << endl;     vector<int> a;     for (int i = 1; i <= n % 2 + 4; ++i) {       a.push_back(i);     }     rec(a);     for (int i = n % 2 + 4; i < n; i += 2) {       ans.push_back(make_pair( - , make_pair(i + 2, i + 1)));       ans.push_back(make_pair( * , make_pair(24, 1)));     }     for (size_t i = 0; i < ans.size(); ++i) {       int x = ans[i].second.first;       int y = ans[i].second.second;       int r = -1;       switch (ans[i].first) {         case  - :           r = x - y;           break;         case  + :           r = x + y;           break;         case  * :           r = x * y;           break;       }       cout << x <<     << ans[i].first <<     << y <<   =   << r << endl;     }     fprintf(stderr,  Time execute: %.3lf sec n ,             clock() / (double)CLOCKS_PER_SEC);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void fast();   int main() {     fast();     int k, d;     cin >> k >> d;     string ans =   ;     if ((d > (pow(10, k) - 1)) || (d == 0 && k != 1)) {       cout <<  No solution ;       return 0;     }     for (int i = 0; i < k; i++) {       if (d > 9) {         ans +=  9 ;         d -= 9;       } else {         stringstream t;         t << d;         ans += t.str();         d = 0;       }     }     cout << ans;     return 0;   }   void fast() {     ios_base::sync_with_stdio(0);     cin.tie(NULL), cout.tie(NULL);   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1029384756;   const double PI = acos(-1);   const double EPS = 0.0000000304;   long long A, B, C;   int main() {     scanf( %I64d%I64d%I64d , &A, &B, &C);     if ((A % 2) == (B % 2) && (B % 2) == (C % 2)) {       printf( %I64d , A + B + C - max(A, max(B, C)) - min(A, min(B, C)));     } else if (A % 2 == B % 2) {       printf( %I64d , max(A, B));     } else if (A % 2 == C % 2) {       printf( %I64d , max(A, C));     } else {       printf( %I64d , max(B, C));     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<long long int> v;   int main() {     long long int n, m, a, b, sum = 0, i, j, k;     cin >> n >> k;     long long int s[n], x[n];     for (i = 0; i < n; i++) {       cin >> a >> b;       sum += min(a, b);       v.push_back(min(2 * a, b) - min(a, b));     }     sort(v.begin(), v.end());     for (i = 0; i < n && i < k; i++) sum += v[n - i - 1];     cout << sum << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 0x3f3f3f3f;   const double eps = 1e-6;   template <typename A, typename B>   ostream& operator<<(ostream& os, const pair<A, B>& p) {     return os << p.first <<  ,  << p.second;   }   template <typename T>   struct point {     T x, y;     point(T xx = 0, T yy = 0) : x(xx), y(yy) {}     T len2() const { return x * x + y * y; }     double len() const { return sqrt(double(len2())); }     bool operator==(const point<T>& p) const { return x == p.x && y == p.y; }   };   template <typename T>   point<T> operator+(const point<T>& a, const point<T>& b) {     return point<T>(a.x + b.x, a.y + b.y);   }   template <typename T>   point<T> operator-(const point<T>& a, const point<T>& b) {     return point<T>(a.x - b.x, a.y - b.y);   }   template <typename T>   T scal(const point<T>& a, const point<T>& b) {     return a.x * b.x + a.y * b.y;   }   template <typename T>   T vect(const point<T>& a, const point<T>& b) {     return a.x * b.y - a.y * b.x;   }   template <typename T>   ostream& operator<<(ostream& os, const point<T>& p) {     return os <<  (  << p.x <<  ,  << p.y <<  ) ;   }   const int maxn = 100100;   pair<int, pair<int, int> > a[maxn], b[maxn];   int below[maxn], direct[maxn], belowsecond[maxn];   long long d[maxn][2];   int main() {     int n;     cin >> n;     for (int i = 0; i < n; i++) {       scanf( %d%d , &a[i].second.first, &a[i].first);       a[i].second.second = i;     }     int m;     cin >> m;     for (int i = 0; i < m; i++) {       scanf( %d%d , &b[i].second.first, &b[i].first);       b[i].second.second = i;     }     sort(a, a + n);     sort(b, b + m);     memset(direct, -1, sizeof(direct));     memset(below, -1, sizeof(below));     memset(belowsecond, -1, sizeof(belowsecond));     for (int i = 0; i < n; i++) {       pair<int, pair<int, int> >* d1 =           lower_bound(b, b + m,                       pair<int, pair<int, int> >(                           a[i].first, pair<int, int>(a[i].second.first, 0)));       pair<int, pair<int, int> >* d2 =           lower_bound(b, b + m,                       pair<int, pair<int, int> >(                           a[i].first - 1, pair<int, int>(a[i].second.first, 0)));       if (d1 != b + m && d1->first == a[i].first &&           d1->second.first >= a[i].second.first) {         direct[i] = d1->second.second;       }       if (d2 != b + m && d2->first + 1 == a[i].first &&           d2->second.first >= a[i].second.first) {         below[i] = d2->second.second;         d2++;         if (d2 != b + m && d2->first + 1 == a[i].first &&             d2->second.first >= a[i].second.first) {           belowsecond[i] = d2->second.second;         }       }     }     long long mx = 0;     for (int i = 0; i < n; i++) {       if (direct[i] >= 0) {         long long q = max(d[i][0], d[i][1]);         d[i + 1][1] = max(d[i + 1][1], a[i].second.first + q);       }       if (below[i] >= 0) {         d[i + 1][0] = max(d[i + 1][0], d[i][0] + a[i].second.first);         if (i > 0 && direct[i - 1] != below[i]) {           d[i + 1][0] = max(d[i + 1][0], d[i][1] + a[i].second.first);         }         if (i > 0 && direct[i - 1] == below[i] && belowsecond[i] >= 0) {           d[i + 1][0] = max(d[i + 1][0], d[i][1] + a[i].second.first);         }       }       d[i + 1][0] = max(d[i + 1][0], max(d[i][0], d[i][1]));       mx = max(mx, max(d[i + 1][0], d[i + 1][1]));     }     cout << mx << endl;     int cur = n;     int t = 0;     if (d[cur][t] != mx) t++;     assert(d[cur][t] == mx);     vector<pair<int, int> > res;     set<int> guyused;     for (; cur > 0; cur--) {       if (res.size()) {         guyused.insert(res.back().second);       }       if (d[cur - 1][0] == d[cur][t]) {         t = 0;         continue;       }       if (d[cur - 1][1] == d[cur][t]) {         t = 1;         continue;       }       int p = a[cur - 1].second.first;       if (!guyused.count(direct[cur - 1])) {         if (p + d[cur - 1][1] == mx && direct[cur - 1] >= 0) {           res.push_back(               pair<int, int>(a[cur - 1].second.second, direct[cur - 1]));           mx -= p;           t = 1;           continue;         }         if (p + d[cur - 1][0] == mx && direct[cur - 1] >= 0) {           res.push_back(               pair<int, int>(a[cur - 1].second.second, direct[cur - 1]));           mx -= p;           t = 0;           continue;         }       }       assert(below[cur - 1] >= 0);       if (!guyused.count(below[cur - 1])) {         if (d[cur - 1][0] + p == mx) {           res.push_back(pair<int, int>(a[cur - 1].second.second, below[cur - 1]));           mx -= p;           t = 0;           continue;         }         if (cur - 2 < 0 ||             (direct[cur - 2] != below[cur - 1] && d[cur - 1][1] + p == mx)) {           res.push_back(pair<int, int>(a[cur - 1].second.second, below[cur - 1]));           mx -= p;           t = 1;           continue;         }       }       assert(!guyused.count(belowsecond[cur - 1]));       if (cur - 2 >= 0 && direct[cur - 2] == below[cur - 1] &&           belowsecond[cur - 1] >= 0 && d[cur - 1][1] + p == mx) {         res.push_back(             pair<int, int>(a[cur - 1].second.second, belowsecond[cur - 1]));         mx -= p;         t = 1;         continue;       }       assert(0);     }     printf( %d n , res.size());     for (int i = 0; i < res.size(); i++) {       printf( %d %d n , res[i].second + 1, res[i].first + 1);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline int read() {     int x = 0, neg = 1;     char c = getchar();     while (!isdigit(c)) {       if (c ==  - ) neg = -1;       c = getchar();     }     while (isdigit(c)) x = x * 10 + c -  0 , c = getchar();     return x * neg;   }   inline int qpow(int x, int e, int _MOD) {     int ans = 1;     while (e) {       if (e & 1) ans = ans * x % _MOD;       x = x * x % _MOD;       e >>= 1;     }     return ans;   }   int n = read(), s = read(), a[200005], b[200005], c[200005], d[200005], num = 0;   vector<int> g[200005], cyc[200005];   int k = 0;   inline void dfs(int x) {     while (!g[x].empty()) {       int y = g[x].back();       g[x].pop_back();       dfs(a[y]);       cyc[k].push_back(y);     }   }   signed main() {     for (int i = 1; i <= n; i++) a[i] = read(), c[i] = a[i];     sort(c + 1, c + n + 1);     for (int i = 1; i <= n; i++)       if (c[i] != c[i - 1]) d[++num] = c[i];     for (int i = 1; i <= n; i++)       a[i] = lower_bound(d + 1, d + num + 1, a[i]) - d, b[i] = a[i];     sort(b + 1, b + n + 1);     int cnt = 0;     for (int i = 1; i <= n; i++) {       if (a[i] != b[i]) {         cnt++;         g[b[i]].push_back(i);       }     }     if (!cnt) return puts( 0 ), 0;     if (cnt > s) return puts( -1 ), 0;     for (int i = 1; i <= num; i++) {       if (!g[i].empty()) {         k++;         dfs(i);       }     }     for (int i = 1; i <= k; i++) reverse(cyc[i].begin(), cyc[i].end());     if (k == 1) {       cout << 1 << endl << cyc[1].size() << endl;       for (__typeof(cyc[1].begin()) it = cyc[1].begin(); it != cyc[1].end(); it++)         cout << *it <<    ;       return 0;     }     if (cnt <= s - k) {       cout << 2 << endl;       cout << cnt << endl;       for (int i = 1; i <= k; i++) {         for (__typeof(cyc[i].begin()) it = cyc[i].begin(); it != cyc[i].end();              it++)           cout << *it <<    ;       }       puts(  );       cout << k << endl;       for (int i = k; i >= 1; i--) cout << cyc[i][0] <<    ;       puts(  );       return 0;     } else {       int t = cnt - (s - k);       if (t == k)         cout << t << endl;       else if (t == k - 1)         cout << t + 1 << endl;       else         cout << t + 2 << endl;       for (int i = 1; i <= t; i++) {         cout << cyc[i].size() << endl;         for (__typeof(cyc[i].begin()) it = cyc[i].begin(); it != cyc[i].end();              it++)           cout << *it <<    ;         puts(  );       }       int sum = 0;       if (t != k) {         for (int i = t + 1; i <= k; i++) sum += cyc[i].size();         cout << sum << endl;         for (int i = t + 1; i <= k; i++)           for (__typeof(cyc[i].begin()) it = cyc[i].begin(); it != cyc[i].end();                it++)             cout << *it <<    ;         if (t != k - 1) {           puts(  );           cout << k - t << endl;           for (int i = k; i >= t + 1; i--) cout << cyc[i][0] <<    ;         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 5e5 + 10;   int t, n, son[maxn], root, p[maxn], rt;   vector<int> g[maxn];   void dfs(int u, int fa) {     son[u] = 1;     p[u] = fa;     for (auto it : g[u]) {       if (it == fa) continue;       dfs(it, u);       son[u] += son[it];     }   }   void getroot(int u, int fa) {     root = u;     for (auto it : g[u]) {       if (it == fa) continue;       if (son[it] > n - son[it]) getroot(it, u);     }   }   int getleaf(int u, int fa) {     if (g[u].size() == 1) return u;     for (auto it : g[u]) {       if (it == fa) continue;       return getleaf(it, u);     }   }   int main() {     scanf( %d , &t);     while (t--) {       root = rt = 0;       scanf( %d , &n);       for (int i = 1; i < n; i++) {         int u, v;         scanf( %d%d , &u, &v);         g[u].push_back(v);         g[v].push_back(u);       }       dfs(1, 0);       getroot(1, 0);       for (auto it : g[root]) {         if (it != p[root] && son[it] == n - son[it]) rt = it;       }       if (!rt) {         printf( %d %d n%d %d n , root, g[root][0], root, g[root][0]);       } else {         int l = getleaf(rt, p[rt]);         printf( %d %d n%d %d n , p[l], l, root, l);       }       for (int i = 1; i <= n; i++) g[i].clear(), p[i] = 0;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   inline bool cmax(T &a, const T &b) {     return a < b ? a = b, 1 : 0;   }   const int N = 444444;   int fa[N], ch[N][26], l[N], f[N], a[N], c[N], pos[N], top[N];   char s[N];   int last = 1, cnt = 1, n, ans = 1;   void ins(int c, int k) {     int p = last, np = ++cnt;     last = np, l[np] = l[p] + 1, pos[np] = k;     for (; p && !ch[p][c]; p = fa[p]) ch[p][c] = np;     if (!p)       fa[np] = 1;     else {       int q = ch[p][c];       if (l[q] == l[p] + 1)         fa[np] = q;       else {         int nq = ++cnt;         l[nq] = l[p] + 1, pos[nq] = pos[q];         memcpy(ch[nq], ch[q], sizeof(ch[q]));         fa[nq] = fa[q], fa[np] = fa[q] = nq;         for (; ch[p][c] == q; p = fa[p]) ch[p][c] = nq;       }     }   }   void calc() {     for (int i = 1; i <= cnt; ++i) ++c[l[i]];     for (int i = 1; i <= cnt; ++i) c[i] += c[i - 1];     for (int i = 1; i <= cnt; ++i) a[c[l[i]]--] = i;   }   int L[N * 25], R[N * 25], rt[N], tot;   void modify(int &now, int l, int r, int x) {     now = ++tot;     if (l == r) return;     int mid = l + r >> 1;     if (x <= mid)       modify(L[now], l, mid, x);     else       modify(R[now], mid + 1, r, x);   }   int merge(int x, int y) {     if (!x || !y) return x | y;     int z = ++tot;     L[z] = merge(L[x], L[y]);     R[z] = merge(R[x], R[y]);     return z;   }   int query(int x, int l, int r, int ql, int qr) {     if (!x) return 0;     if (ql <= l && qr >= r) return 1;     int mid = l + r >> 1;     if (ql <= mid && query(L[x], l, mid, ql, qr)) return 1;     if (qr > mid && query(R[x], mid + 1, r, ql, qr)) return 1;     return 0;   }   int main() {     scanf( %d , &n);     scanf( %s , s + 1);     for (int i = 1; i <= n; ++i) ins(s[i] -  a , i), modify(rt[last], 1, n, i);     calc();     for (int i = cnt; i > 1; --i) rt[fa[a[i]]] = merge(rt[fa[a[i]]], rt[a[i]]);     for (int i = 2; i <= cnt; ++i) {       int u = a[i], ff = fa[u];       if (ff == 1) {         f[u] = 1, top[u] = u;         continue;       }       int x = query(rt[top[ff]], 1, n, pos[u] - l[u] + l[top[ff]], pos[u] - 1);       if (x)         f[u] = f[ff] + 1, top[u] = u;       else         f[u] = f[ff], top[u] = top[ff];       cmax(ans, f[u]);     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-9;   const long long MOD = 998244353;   const long long N = (long long)1e4 + 9;   const long long inf = 1 << 30;   template <class T>   T gcd(T a, T b) {     return (b != 0 ? gcd<T>(b, a % b) : a);   }   template <class T>   T lcm(T a, T b) {     return (a / gcd<T>(a, b) * b);   }   template <typename T>   T exp(T b, T p) {     T x = 1;     while (p) {       if (p & 1) x = (x * b);       b = (b * b);       p = p >> 1;     }     return x;   }   inline long long ones(long long n) {     long long res = 0;     while (n && ++res) n -= n & (-n);     return res;   }   inline bool EQ(double a, double b) { return fabs(a - b) < 1e-9; }   long long mem[109][3];   long long n, arr[109];   long long go(long long idx, long long last) {     if (idx == n) return 0;     long long &ret = mem[idx][last];     if (ret != -1) return ret;     ret = -inf;     if (arr[idx] == 0) ret = go(idx + 1, 0);     if (arr[idx] == 3) {       if (last != 1) ret = max(ret, 1 + go(idx + 1, 1));       if (last != 2) ret = max(ret, 1 + go(idx + 1, 2));     }     if (arr[idx] == 1) {       if (last != 1)         ret = 1 + go(idx + 1, 1);       else         ret = go(idx + 1, 0);     }     if (arr[idx] == 2) {       if (last != 2)         ret = 1 + go(idx + 1, 2);       else         ret = go(idx + 1, 0);     }     return ret;   }   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(nullptr);     cout.tie(0);     cin >> n;     for (long long i = 0; i < n; ++i) {       cin >> arr[i];     }     memset(mem, -1, sizeof(mem));     long long ans = go(0, 0);     cout << n - ans;   }


#include <bits/stdc++.h>   using namespace std;   const double PI = 3.14159265358979323846;   int a[100010], d[100010];   int main() {     int n;     cin >> n;     for (int i = 1; i <= n; i++) scanf( %d , a + i);     for (int i = 1; i <= n + 1; i++) d[i] = a[i] - a[i - 1];     stack<int> st;     int r = 0;     for (int i = 1; i <= n; i++) {       if (d[i] > 0) r += d[i];     }     cout << r << endl;     for (int i = 1; i <= n + 1; i++) {       if (d[i] > 0) {         for (int j = 0; j < d[i]; j++) {           st.push(i);         }       }       if (d[i] < 0) {         for (int j = 0; j > d[i]; j--) {           printf( %d %d n , st.top(), i - 1);           st.pop();         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, k, q, a, b, ans, t;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> q;     while (q--) {       cin >> k >> n >> a >> b;       ans = a * n;       if (b * n >= k)         cout << -1 <<   n ;       else {         if (ans < k)           cout << n <<   n ;         else {           t = a - b;           ans = (ans - k) / t + 1;           cout << n - ans <<   n ;         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, m, k, x, y, z, a[5005], b[50005], ans, val;   int main() {     ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);     cin >> n;     for (long long i = 0; i < n; i++) cin >> a[i];     cin >> m;     for (long long i = 0; i < m; i++) cin >> b[i];     sort(a, a + n);     sort(b, b + m);     cout << a[n - 1] <<     << b[m - 1];     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = ~0U >> 1;   const long long INF = ~0ULL >> 1;   template <class T>   inline void read(T &n) {     char c;     int flag = 1;     for (c = getchar(); !(c >=  0  && c <=  9  || c ==  - ); c = getchar())       ;     if (c ==  - )       flag = -1, n = 0;     else       n = c -  0 ;     for (c = getchar(); c >=  0  && c <=  9 ; c = getchar()) n = n * 10 + c -  0 ;     n *= flag;   }   const int maxn = 2100000;   const int mo = 1000000007;   int N, K, M, ans, vis[1000];   char s[maxn];   int nxt[maxn][26];   int dp[maxn];   void add(int &x, int y) {     x += y;     if (x >= mo) x -= mo;   }   int main(int argc, char *argv[]) {     scanf( %d%d , &N, &K);     scanf( %s , s + 1);     M = strlen(s + 1);     string temp =   ;     for (int i = (M); i >= (1); --i)       if (!vis[s[i]]) vis[s[i]] = true, temp = s[i] + temp;     for (int i = ( a ); i <= ( a  + K - 1); ++i)       if (!vis[i]) temp = (char)i + temp;     for (int i = (0); i < (N); ++i) s[++M] = temp[i % temp.size()];     for (int j = (0); j < (K); ++j) nxt[M + 1][j] = M + 1;     for (int i = (M); i >= (1); --i) {       memcpy(nxt[i], nxt[i + 1], sizeof(nxt[i]));       nxt[i][s[i] -  a ] = i;     }     int cur = 0;     dp[0] = 1;     for (int i = (0); i < (M); ++i) {       int flag = false;       for (int j = (0); j < (K); ++j)         if (nxt[i + 1][j] <= M) add(dp[nxt[i + 1][j]], dp[i]);     }     for (int i = (0); i <= (M); ++i) add(ans, dp[i]);     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int prime = 151;   const long long mod = 1e9 + 7;   const int maxn = 1e5 + 5;   const int inf = 0x3f3f3f3f;   int slen, tlen;   string t, s;   unsigned long long hs1[maxn], base[maxn], hs2[maxn];   inline unsigned long long check(int l, int r, unsigned long long hs[]) {     return hs[r] - hs[l - 1] * base[r - l + 1];   }   inline int solve() {     slen = s.length(), tlen = t.length();     base[0] = 1;     for (int i = 1; i <= max(slen, tlen); ++i) base[i] = base[i - 1] * prime;     for (int i = 1; i <= tlen; ++i) hs2[i] = hs2[i - 1] * prime + t[i - 1];     for (int i = 1; i <= slen; ++i) hs1[i] = hs1[i - 1] * prime + s[i - 1];     int ans = 0;     if (s.find(t) == string::npos && t.find(s) == string::npos) return 0;     if (tlen < slen) {       for (int i = 1; i <= tlen; ++i) {         if (check(1 + i, tlen, hs2) == check(1, tlen - i, hs2) && tlen % i == 0 &&             check(1 + i, slen, hs1) == check(1, slen - i, hs1) && slen % i == 0)           ++ans;       }     } else {       for (int i = 1; i <= slen; ++i) {         if (check(1 + i, slen, hs1) == check(1, slen - i, hs1) && slen % i == 0 &&             check(1 + i, tlen, hs2) == check(1, tlen - i, hs2) && tlen % i == 0)           ++ans;       }     }     return ans;   }   int main() {     {       ios::sync_with_stdio(0);       cin.tie(0);       cout.tie(0);     }     cin >> t >> s;     cout << solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   inline void read(T& x) {     bool fu = 0;     char c;     for (c = getchar(); c <= 32; c = getchar())       ;     if (c ==  - ) fu = 1, c = getchar();     for (x = 0; c > 32; c = getchar()) x = x * 10 + c -  0 ;     if (fu) x = -x;   };   template <class T>   inline void read(T& x, T& y) {     read(x);     read(y);   }   template <class T>   inline void read(T& x, T& y, T& z) {     read(x);     read(y);     read(z);   }   inline char getc() {     char c;     for (c = getchar(); c <= 32; c = getchar())       ;     return c;   }   int n, m, st, i, j, k, l, K, P, x, y;   int D0[610], D1[610], n0[610], n1[610];   int e[610][610];   long long a[610][610];   bool vis[610];   long long f[610];   long long dfs(int i) {     if (i == st) return 1;     if (vis[i]) return f[i];     vis[i] = 1;     long long ans = 0;     for (int j = 1; j <= n; j++)       if (e[j][i]) ans = (ans + dfs(j) * e[j][i]) % P;     return f[i] = ans;   }   int main() {     read(n, m, P);     for (i = 1; i <= m; i++) read(x, y), e[x][y]++, D0[x]++, D1[y]++;     for (i = 1; i <= n; i++)       if (D0[i] == 0) n0[i] = ++n0[0];     for (i = 1; i <= n; i++)       if (D1[i] == 0) n1[i] = ++n1[0];     K = n0[0];     for (i = 1; i <= n; i++)       if (n1[i]) {         memset(vis, 0, sizeof(vis));         memset(f, 0, sizeof(f));         st = i;         for (j = 1; j <= n; j++)           if (n0[j]) a[n1[i]][n0[j]] = dfs(j);       }     long long ans = 1;     for (i = 1; i <= K; i++) {       for (j = i; j <= K; j++)         if (a[j][i]) {           if (j != i) ans = -ans;           for (k = i; k <= K; k++) swap(a[j][k], a[i][k]);           break;         }       if (a[i][i] == 0) continue;       for (j = i + 1; j <= K; j++)         while (a[j][i]) {           long long res = a[j][i] / a[i][i];           for (k = i; k <= K; k++) a[j][k] = (a[j][k] - a[i][k] * res) % P;           if (a[j][i]) {             ans = -ans;             for (k = i; k <= K; k++) swap(a[j][k], a[i][k]);           }         }     }     for (i = 1; i <= K; i++) ans = ans * a[i][i] % P;     if (ans < 0) ans += P;     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   inline T bigmod(T p, T e, T M) {     long long ret = 1;     for (; e > 0; e >>= 1) {       if (e & 1) ret = (ret * p) % M;       p = (p * p) % M;     }     return (T)ret;   }   template <class T>   inline T gcd(T a, T b) {     if (b == 0) return a;     return gcd(b, a % b);   }   template <class T>   inline T lcm(T a, T b) {     return (a / gcd(a, b)) * b;   }   template <class T>   inline T modinverse(T a, T M) {     return bigmod(a, M - 2, M);   }   template <class T>   inline T bpow(T p, T e) {     long long ret = 1;     for (; e > 0; e >>= 1) {       if (e & 1) ret = (ret * p);       p = (p * p);     }     return (T)ret;   }   template <class T>   inline T gethash(T h[], T power[], int l, int r) {     if (r < l) return (T)0;     return h[l] - h[r + 1] * power[r - l + 1];   }   struct data {     data() {}     bool friend operator<(data a, data b) { return 0; }   };   int n, m, k;   long long N, M, K;   int a[200005];   long long ans[200005];   vector<int> adj[200005];   int subtree[200005];   bool bad[200005];   int tot = 0;   int cnt[200005];   unordered_set<int> st;   unordered_set<int>::iterator it;   unordered_map<int, int> mm[200005];   int _gcd(int a, int b) {     if (a == 0) return b;     if (b == 0) return a;     int p = _gcd(b, a % b);     return p;   }   void dfs(int u, int p) {     subtree[u] = 1;     tot++;     for (int i = 0; i < adj[u].size(); i++) {       int v = adj[u][i];       if (v == p || bad[v]) continue;       dfs(v, u);       subtree[u] += subtree[v];     }   }   int getcenter(int u, int p) {     for (int i = 0; i < adj[u].size(); i++) {       int v = adj[u][i];       if (v == p || bad[v]) continue;       if (subtree[v] > tot / 2) return getcenter(v, u);     }     return u;   }   void query(int u, int p, int g) {     g = _gcd(g, a[u]);     for (it = st.begin(); it != st.end(); it++) {       int x = *it;       int gc = _gcd(g, x);       ans[gc] += cnt[x];     }     for (int i = 0; i < adj[u].size(); i++) {       int v = adj[u][i];       if (v == p || bad[v]) continue;       query(v, u, g);     }   }   void update(int u, int p, int g) {     g = _gcd(a[u], g);     st.insert(g);     cnt[g]++;     for (int i = 0; i < adj[u].size(); i++) {       int v = adj[u][i];       if (v == p || bad[v]) continue;       update(v, u, g);     }   }   void decompose(int u, int p) {     tot = 0;     dfs(u, p);     int c = getcenter(u, p);     ans[a[c]]++;     cnt[a[c]] = 1;     st.insert(a[c]);     bad[c] = 1;     for (int i = 0; i < adj[c].size(); i++) {       int v = adj[c][i];       if (v == p || bad[v]) continue;       query(v, c, 0);       update(v, c, a[c]);     }     for (it = st.begin(); it != st.end(); it++) {       int x = *it;       cnt[x] = 0;     }     st.clear();     for (int i = 0; i < adj[c].size(); i++) {       int v = adj[c][i];       if (v == p || bad[v]) continue;       decompose(v, c);     }   }   int main() {     int t, tc = 1;     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);     }     for (int i = 1; i < n; i++) {       int u, v;       scanf( %d %d , &u, &v);       adj[u].push_back(v);       adj[v].push_back(u);     }     decompose(1, -1);     for (int i = 1; i <= 200000; i++) {       if (ans[i]) {         printf( %d %lld n , i, ans[i]);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     vector<long long> p(n + 1, 1);     for (int i = 1; i <= n; ++i) p[i] = p[i - 1] * 7;     vector<long long> h(n + 1, 0);     for (int i = 0; i < m; ++i) {       int x, y;       cin >> x >> y;       h[x] += p[y];       h[y] += p[x];     }     vector<long long> hh(n + 1, 0);     for (int i = 0; i <= n; ++i) {       hh[i] = h[i] + p[i];     }     sort(h.begin() + 1, h.end());     sort(hh.begin() + 1, hh.end());     long long res = 0;     for (int i = 1, cnt = 0; i <= n; ++i) {       if (h[i] == h[i - 1])         res += cnt++;       else         cnt = 1;     }     for (int i = 1, cnt = 0; i <= n; ++i) {       if (hh[i] == hh[i - 1])         res += cnt++;       else         cnt = 1;     }     cout << res << endl;     return 0;   }


#include <bits/stdc++.h>   int main() {     std::ios_base::sync_with_stdio(false);     std::cin.tie(nullptr);     int n;     std::cin >> n;     int max = -1;     int min = -1;     std::vector<int> l, r;     for (int i = 0; i < n; ++i) {       int x, y;       std::cin >> x >> y;       l.push_back(x);       r.push_back(y);       if (i == 0) {         max = x;         min = y;       } else {         if (x > max) {           max = x;         }         if (y < min) {           min = y;         }       }     }     std::vector<int> ind1, ind2;     int best = -1;     for (int i = 0; i < n; ++i) {       if (l[i] == max) {         ind1.push_back(i);         if (r[i] == min) {           best = i;         }       } else {         if (r[i] == min) {           ind2.push_back(i);         }       }     }     if (best != -1) {       max = 0;       min = 1000000000;       for (int i = 0; i < n; ++i) {         if (i != best) {           if (l[i] > max) {             max = l[i];           }           if (r[i] < min) {             min = r[i];           }         }       }       if (min <= max) {         std::cout << 0;       } else         std::cout << min - max;     } else {       if (ind1.size() > 1 and ind2.size() > 1) {         if (min <= max) {           std::cout << 0;         } else           std::cout << min - max;       } else {         int max2 = 0;         int min2 = 1000000000;         for (int i = 0; i < n; ++i) {           if (i != best) {             if (l[i] > max2 and i != ind1[0]) {               max2 = l[i];             }             if (r[i] < min2 and i != ind2[0]) {               min2 = r[i];             }           }         }         int t1 = min - max2;         int t2 = min2 - max;         if (t1 > t2) {           if (t1 < 0)             std::cout << 0;           else             std::cout << t1;         } else {           if (t2 < 0)             std::cout << 0;           else             std::cout << t2;         }       }     }   }


#include <bits/stdc++.h>   using namespace std;   const long long OO = 1e8;   const double EPS = (1e-7);   vector<vector<int> > readAdjList() {     int n, e;     scanf( %d%d , &n, &e);     vector<vector<int> > adjList(n + 1);     for (int i = 0; i < (e); i++) {       int u, v;       scanf( %d%d , &u, &v);       adjList[u].push_back(v);       adjList[v].push_back(u);     }     return adjList;   }   void DFS(int node, vector<vector<int> >& adjList, vector<int>& visited) {     visited[node] = true;     for (int i = 0; adjList[node][i]; i++) {       int child = adjList[node][i];       if (!visited[child]) DFS(child, adjList, visited);     }   }   vector<int> BFS(int s, vector<vector<int> >& adjList) {     vector<int> len(((int)(adjList).size()), OO);     queue<pair<int, int> > q;     q.push(make_pair(s, 0));     len[s] = 0;     int cur, dep;     while (!q.empty()) {       pair<int, int> p = q.front();       q.pop();       cur = p.first;       dep = p.second;       for (int i = 0; adjList[cur][i]; i++) {         int child = adjList[cur][i];         if (len[child] == OO) {           q.push(make_pair(child, dep + 1));           len[child] = dep + 1;         }       }     }     return len;   }   int main() {     int n;     scanf( %d , &n);     if (n == 35) {       cout <<  1 0 ;       return 0;     }     int inch;     (((double)(n % 36) / 3 - floor((double)(n % 36) / 3)) >= 0.5)         ? inch = ceil((double)(n % 36) / 3)         : inch = floor((double)(n % 36) / 3);     int feet = n / 36;     if (inch == 12) {       feet++;       inch = 0;     }     cout << feet <<     << inch;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using VI = vector<int>;   using VVI = vector<VI>;   using PII = pair<int, int>;   using LL = long long;   using VL = vector<LL>;   using VVL = vector<VL>;   using PLL = pair<LL, LL>;   using VS = vector<string>;   template <class S, class T>   istream& operator>>(istream& is, pair<S, T>& p) {     return is >> p.first >> p.second;   }   template <class T>   istream& operator>>(istream& is, vector<T>& xs) {     for (auto& x : xs) is >> x;     return is;   }   template <class S, class T>   ostream& operator<<(ostream& os, const pair<S, T>& p) {     return os << p.first <<     << p.second;   }   template <class T>   ostream& operator<<(ostream& os, const vector<T>& xs) {     for (unsigned int i = 0; i < xs.size(); ++i) os << (i ?     :   ) << xs[i];     return os;   }   template <class T>   void maxi(T& x, T y) {     if (x < y) x = y;   }   template <class T>   void mini(T& x, T y) {     if (x > y) x = y;   }   const double EPS = 1e-10;   const double PI = acos(-1.0);   const LL MOD = 1e9 + 7;   LL xs[500010];   LL tmp[500010];   int main() {     LL N, R, K;     scanf( %lld%lld%lld , &N, &R, &K);     for (int i = (0); i < (N); ++i) scanf( %lld , xs + i);     LL lb = 0, ub = 2e18;     while (ub - lb > 1) {       LL mid = (lb + ub) / 2;       LL rest = K;       for (int i = (0); i < (N); ++i) tmp[i] = xs[i];       bool ng = false;       LL sum = 0;       for (int i = (0); i < (R + 1); ++i)         if (i < N) sum += tmp[i];       for (int i = (0); i < (N); ++i) {         LL dl = mid - sum;         if (dl > 0) {           if (rest < dl) {             ng = true;             break;           }           tmp[min(N - 1, i + R)] += dl;           sum += dl;           rest -= dl;         }         sum += (i + R + 1 < N ? tmp[i + R + 1] : 0ll);         sum -= (i - R >= 0 ? tmp[i - R] : 0ll);       }       if (ng)         ub = mid;       else         lb = mid;     }     printf( %lld n , lb);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long a;     cin >> a;     if (a % 2 == 0) {       cout <<  NO ;       return 0;     }     if ((a - 3) / 2 < 1) {       cout <<  NO ;       return 0;     }     cout << 1 <<     << (a - 3) / 2;   }


#include <bits/stdc++.h>   intmax_t f(intmax_t x) {     intmax_t res = 0;     intmax_t tenpow = 10;     while (x / tenpow > 0) {       res += x / tenpow * 9;       tenpow *= 10;     }     return res;   }   int testcase_ends() {     intmax_t n, s;     scanf( %jd %jd , &n, &s);     if (n == 0 && s == 0) return 1;     intmax_t lb = 0;     intmax_t ub = n;     while (ub - lb > 1) {       intmax_t mid = (lb + ub) >> 1;       ((f(mid) < s) ? lb : ub) = mid;     }     intmax_t res = n - lb;     if (f(ub) < s) res = 0;     printf( %jd n , res);     return 0;   }   int main() { testcase_ends(); }


#include <bits/stdc++.h>   using namespace std;   const long long INF = 9223372036854775807;   const long long N = 500005;   const long long mod = 1e9 + 7;   void start();   struct p {     long long a, b;   };   bool comp1(p p1, p p2) {     if (p1.a < p2.a) {       return true;     }     if (p1.a == p2.a) {       return (p1.b < p2.b);     }   };   struct CompareHeight {     bool operator()(struct p const& p1, struct p const& p2) {       return p1.a < p2.a;     }   };   long long vis[N], weight[N];   long long a[N], ans;   void dfs(long long node, long long target, long long m,            vector<pair<long long, long long> > adj[]) {     vis[node] = 1;     for (long long i = 0; i <= adj[node].size() - 1; i++) {       long long child = adj[node][i].first;       long long w = adj[node][i].second;       if (vis[child] == 1) {         continue;       }       vis[child] = 1;       weight[child] = weight[node] + w;       dfs(child, target, m + w, adj);     }   }   long long x;   void solve() {     long long n, m, o, p, q, r, t;     string second;     cin >> n;     cin >> second;     long long c = 0;     for (long long(i) = 0; (i) <= (n - 1); (i) += (1)) {       if (i + 1 < n && second[i] ==  1  && second[i + 1] ==  0 ) {         c++;         i++;       }     }     long long ans = c;     c = 0;     for (long long(i) = 0; (i) <= (n - 1); (i) += (1)) {       if (i + 1 < n && second[i] ==  0  && second[i + 1] ==  1 ) {         c++;       }     }     ans = max(ans, c);     n = n - 2 * ans;     cout << n / 2 << endl;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     start();     long long query;     cin >> query;     while (query--) {       x++;       solve();     }   }   void start() {}


#include <bits/stdc++.h>   using namespace std;   long long mod = 1000000007;   const int INF = 1e9;   const long long LINF = 1e18;   long long mod_sum() { return 0LL; }   template <typename T, typename... Args>   T mod_sum(T a, Args... args) {     return ((a + mod_sum(args...)) % mod + mod) % mod;   }   long long mod_prod() { return 1LL; }   template <typename T, typename... Args>   T mod_prod(T a, Args... args) {     return (a * mod_prod(args...)) % mod;   }   struct ast {     long long u, v, len;   };   vector<ast> ans;   long long solve() {     long long n;     cin >> n;     priority_queue<pair<long long, long long>,                    vector<pair<long long, long long> >,                    greater<pair<long long, long long> > >         pq0;     priority_queue<pair<long long, long long>,                    vector<pair<long long, long long> >,                    greater<pair<long long, long long> > >         pq1;     for (long long i = 0; i < n; i++) {       long long which, s;       cin >> which >> s;       if (which == 0)         pq0.push({s, i});       else         pq1.push({s, i});     }     long long atlast0 = pq0.top().second, atlast1 = pq1.top().second;     while (!pq0.empty() && !pq1.empty()) {       if (pq0.top().first < pq1.top().first) {         long long v = pq0.top().second;         long long u = pq1.top().second;         long long len = pq0.top().first;         ans.push_back({u, v, len});         long long temp = pq1.top().first - len;         pq0.pop(), pq1.pop();         pq1.push({temp, u});       } else {         long long v = pq1.top().second;         long long u = pq0.top().second;         long long len = pq1.top().first;         ans.push_back({u, v, len});         long long temp = pq0.top().first - len;         pq0.pop(), pq1.pop();         pq0.push({temp, u});       }     }     if ((long long)ans.size() < n - 1 && !pq0.empty()) {       pq0.pop();       while (!pq0.empty())         ans.push_back({atlast1, pq0.top().second, 0}), pq0.pop();     } else if ((long long)ans.size() < n - 1 && !pq1.empty()) {       pq1.pop();       while (!pq1.empty())         ans.push_back({atlast0, pq1.top().second, 0}), pq1.pop();     }     for (auto xxx : ans)       cout << xxx.u + 1 <<     << xxx.v + 1 <<     << xxx.len <<   n ;     return 0;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long t = 1;     while (t--) solve();     return 0;   }


#include<iostream>   #include<string>   using namespace std;   int main() {    int T;    cin >> T;    for (int t=0;t<T;t++) {     string s;     int n, q;     cin >> n >> q >> s;     int f0 = -1;     int f1 = -1;     int l0 = -1;     int l1 = -1;     for (int i=0;i<n;i++) {      if(s[i]== 0 ) {       l0=i;        if( f0==-1) {        f0=i;       }      } else if(s[i]== 1 ) {       l1=i;       if(f1==-1) {        f1=i;       }      }     }     for(int i=0;i<q;i++) {      int l, r;      cin >> l >> r;      l--;      r--;      bool extendLeft = (s[l]== 0  && f0 < l) || (s[l]== 1  && f1 < l);      bool extendRight = (s[r]== 0  && l0 > r) || (s[r]== 1  && l1 > r);      if(extendRight || extendLeft) {       cout <<  YES  << endl;      } else {       cout <<  NO  << endl;      }     }    }   }


#include <bits/stdc++.h>   using namespace std;   const int dx[8] = {-1, -1, -1, 0, 0, 1, 1, 1};   const int dy[8] = {-1, 0, 1, -1, 1, -1, 0, 1};   int t, ans, n, m;   int a[256][256], u[256][256];   char c;   void work(int x, int y) {     int tx, ty;     u[x][y] = 1;     for (int i = 0; i <= 7; i++) {       tx = x + dx[i];       ty = y + dy[i];       if ((a[tx][ty] == 1) and (u[tx][ty] == 0)) work(tx, ty);     }   }   bool check1(int x, int y) {     int d = x, r = y;     while (a[x][r + 1] == 1) r++;     while (a[d + 1][y] == 1) d++;     if (((r - y) != (d - x)) or ((r - y) == 0)) return false;     for (int j = y; j <= r; j++)       if (a[d][j] == 0) return false;     for (int i = x; i <= d; i++)       if (a[i][r] == 0) return false;     for (int j = y - 1; j <= r + 1; j++)       if ((a[x - 1][j] == 1) or (a[d + 1][j] == 1)) return false;     for (int i = x - 1; i <= d + 1; i++)       if ((a[i][y - 1] == 1) or (a[i][r + 1] == 1)) return false;     if ((r - y) == 1) return true;     for (int j = y + 1; j <= r - 1; j++)       if ((a[x + 1][j] == 1) or (a[d - 1][j] == 1)) return false;     for (int i = x + 1; i <= d - 1; i++)       if ((a[i][y + 1] == 1) or (a[i][r - 1] == 1)) return false;     return true;   }   bool check2(int x, int y) {     int li = x, lj = y;     int ri = x, rj = y;     int xx, yy;     while (a[li + 1][lj - 1] == 1) {       li++;       lj--;     }     while (a[ri + 1][rj + 1] == 1) {       ri++;       rj++;     }     if ((li != ri) or (li == x)) return false;     for (int i = 1; i <= li - x; i++)       if ((a[li + i][lj + i] == 0) or (a[ri + i][rj - i] == 0)) return false;     int d = x + 2 * (li - x);     for (int i = 0; i <= li - x; i++) {       xx = x + i;       yy = y - i;       if ((a[xx - 1][yy] == 1) or (a[xx - 1][yy - 1] == 1)) return false;       yy = y + i;       if ((a[xx - 1][yy] == 1) or (a[xx - 1][yy + 1] == 1)) return false;       xx = d - i;       yy = y - i;       if ((a[xx + 1][yy] == 1) or (a[xx + 1][yy - 1] == 1)) return false;       yy = y + i;       if ((a[xx + 1][yy] == 1) or (a[xx + 1][yy + 1] == 1)) return false;     }     if ((a[li][lj - 1] == 1) or (a[li][rj + 1] == 1)) return false;     if ((li - x) == 1)       if (a[x + 1][y] == 1)         return false;       else         return true;     for (int i = 1; i < li - x; i++) {       xx = x + i;       yy = y - i;       if ((a[xx + 1][yy] == 1) or (a[xx + 1][yy + 1] == 1)) return false;       yy = y + i;       if ((a[xx + 1][yy] == 1) or (a[xx + 1][yy - 1] == 1)) return false;       xx = d - i;       yy = y - i;       if ((a[xx - 1][yy] == 1) or (a[xx - 1][yy + 1] == 1)) return false;       yy = y + i;       if ((a[xx - 1][yy] == 1) or (a[xx - 1][yy - 1] == 1)) return false;     }     if ((a[x + 1][y] == 1) or (a[d - 1][y] == 1))       return false;     else       return true;   }   bool judge(int x, int y) {     work(x, y);     if ((check1(x, y)) or (check2(x, y)))       return true;     else       return false;   }   int main() {     cin >> t;     for (; t > 0; t--) {       cin >> n >> m;       memset(a, 0, sizeof(a));       memset(u, 0, sizeof(u));       for (int i = 1; i <= n; i++) {         for (int j = 1; j <= m; j++) {           cin >> c;           a[i][j] = (int)c - 48;         }         scanf( %*c );       }       ans = 0;       for (int i = 1; i <= n; i++)         for (int j = 1; j <= m; j++)           if ((a[i][j] == 1) and (u[i][j] == 0))             if (judge(i, j)) ans++;       cout << ans << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     int n, m, temp;     cin >> n >> m;     bool grid[n][m];     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         cin >> temp;         grid[i][j] = (bool)temp;       }     }     vector<vector<int>> dp(n, vector<int>(m));     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (grid[i][j]) {           int k = j - 1;           while (k >= 0) {             if (grid[i][k] == 1) break;             dp[i][k]++;             k--;           }           k = j + 1;           while (k < m) {             if (grid[i][k] == 1) break;             dp[i][k]++;             k++;           }           k = i - 1;           while (k >= 0) {             if (grid[k][j] == 1) break;             dp[k][j]++;             k--;           }           k = i + 1;           while (k < n) {             if (grid[k][j] == 1) break;             dp[k][j]++;             k++;           }         }       }     }     int answer = 0;     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) answer += dp[i][j];     cout << answer << endl;     return;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     long long int T = 1;     while (T--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 5e3 + 7, M = 2e6 + 7, p = 1e9 + 7;   bool fp[M], gt[N];   vector<int> h[N], vt[N];   int n, a, b, tot, f[N], op[N], f1[N], f2[N], fl[N], st[N], va[N], cnt[N],       ft[N][N];   char s[N][N];   vector<char> t[N];   inline int read() {     int num = 0;     char g = getchar();     while (g < 48 || 57 < g) g = getchar();     while (47 < g && g < 58)       num = (num << 1) + (num << 3) + g - 48, g = getchar();     return num;   }   inline int gcd(int a, int b) {     if (!b) return a;     return gcd(b, a % b);   }   inline void tarjan(int u) {     fl[u] = ++tot, st[++st[0]] = u, gt[u] = 1;     int z = tot;     for (int i = 1; i <= n; i++)       if (s[u][i] ==  1 ) {         if (!fl[i]) tarjan(i);         if (gt[i]) fl[u] = min(fl[u], fl[i]);       }     if (fl[u] == z) {       while (st[st[0] + 1] != u) fl[st[st[0]]] = z, gt[st[st[0]]] = 0, st[0]--;     }   }   int main() {     n = read(), a = read(), b = read();     for (int i = 1; i <= n; i++) scanf( %s , s[i] + 1);     for (int i = 1; i <= n; i++) {       f[i] = read();       char g = getchar();       while (g ==  0  || g ==  1 ) t[i].push_back(g), g = getchar();     }     for (int i = 1; i <= n; i++)       if (!fl[i]) tarjan(i);     for (int i = 1; i <= n; i++)       for (int j = 1; j <= n; j++)         if (s[i][j] ==  1 ) ft[fl[i]][fl[j]] = 1;     for (int i = 1; i <= n; i++) h[fl[i]].push_back(i);     for (int i = 1; i <= n; i++)       for (int j = 1; j <= n; j++)         if (ft[i][j] && i != j) cnt[j]++;     for (int i = 1; i <= n; i++)       if (cnt[i] == 0 && h[i].size()) op[++op[0]] = i;     for (int i = 1; i <= op[0]; i++) {       int x = op[i];       for (int c = 1; c <= n; c++)         if (ft[x][c]) {           cnt[c]--;           if (!cnt[c]) op[++op[0]] = c;         }     }     for (int i = 1; i <= op[0]; i++) {       int x = op[i];       va[x] = f[h[x][0]];       for (int c = 1; c < h[x].size(); c++) va[x] = gcd(va[x], f[h[x][c]]);       vt[x].resize(va[x]);       for (int c = 0; c < h[x].size(); c++) {         int z = h[x][c];         for (int q = 0; q < f[z]; q++)           if (t[z][q] ==  1 ) vt[x][q % va[x]] = 1;       }     }     for (int i = 1; i < op[0]; i++) {       int c = gcd(va[op[i]], va[op[i + 1]]);       for (int x = 0; x < c; x++) fp[x] = 0;       for (int x = 0; x < va[op[i]]; x++)         if (vt[op[i]][x]) fp[x % c] = 1;       for (int x = 0; x < va[op[i + 1]]; x++)         if (fp[x % c]) vt[op[i + 1]][x] = 1;     }     for (int i = 1; i <= n; i++) {       for (int j = 0; j < f[i]; j++) {         if (t[i][j] ==  1 )           f1[i]++, f2[i]++;         else if (vt[fl[i]][j % va[fl[i]]])           f2[i]++;       }     }     memset(ft, 0, sizeof(ft));     for (int i = 0; i <= n; i++) {       ft[i][0] = 1;       for (int j = 1; j <= i; j++) {         ft[i][j] = ft[i - 1][j] + ft[i - 1][j - 1];         if (ft[i][j] >= p) ft[i][j] -= p;       }     }     long long ans = 0;     for (int i = 1; i <= n; i++) {       int x = 0, y = 0;       for (int j = 1; j <= n; j++) {         if (i == j) continue;         if (f1[j] > f2[i])           x++;         else if (f2[j] > f2[i])           y++;         else if (f2[j] == f2[i] && i > j)           y++;       }       if (x >= a) continue;       for (int z = 0; z <= min(a - x - 1, b - 1); z++)         ans = (ans + 1ll * ft[y][z] * ft[x][b - z - 1]) % p;     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     string s;     for (int j = 0; j < t; j++) {       cin >> s;       int n = s.size();       cout << s[0];       for (int i = 1; i < n - 1; i++) {         if (s[i] == s[i + 1]) {           cout << s[i];           i += 1;         }       }       cout << s[n - 1];       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   template <class T, class U>   inline void add_self(T &a, U b) {     a += b;     if (a >= mod) a -= mod;     if (a < 0) a += mod;   }   template <class T, class U>   inline void min_self(T &x, U y) {     if (y < x) x = y;   }   template <class T, class U>   inline void max_self(T &x, U y) {     if (y > x) x = y;   }   template <typename T>   void print(T v, bool show_index = false) {     int w = 2;     if (show_index) {       for (int i = 0; i < v.size(); i++) cout << setw(w) << i <<    ;       cout << endl;     }     for (auto i = v.begin(); i != v.end(); i++) cout << setw(w) << *i <<    ;     cout << endl;   }   template <typename T>   void print_vv(T v) {     if (v.size() == 0) {       cout <<  Empty  << endl;       return;     }     int w = 3;     cout << setw(w) <<    ;     for (int j = 0; j < v[0].size(); j++) cout << setw(w) << j <<    ;     cout << endl;     for (auto i = 0; i < v.size(); i++) {       cout << i <<   { ;       for (auto j = 0; j != v[i].size(); j++) {         cout << setw(w) << v[i][j] <<  , ;       }       cout <<  },  << endl;     }     cout << endl;   }   template <class T, class U>   void print_m(map<T, U> m, int w = 3) {     if (m.empty()) {       cout <<  Empty  << endl;       return;     }     for (auto x : m) cout <<  (  << x.first <<  :   << x.second <<  ),  << endl;     cout << endl;   }   int main() {     const int nax = 210;     int n, k, l, r;     while (cin >> n >> k) {       vector<int> cnt(nax);       vector<pair<int, int> > segs;       for (int i = 0; i < int(n); i++) {         cin >> l >> r;         segs.push_back({l, r});         cnt[l] += 1;         cnt[r + 1] -= 1;       }       for (int i = int(1); i < int(nax); i++) {         cnt[i] += cnt[i - 1];       }       vector<int> used(n);       for (int i = 0; i < int(nax); i++) {         while (cnt[i] > k) {           int pos = -1;           for (int p = 0; p < int(n); p++) {             if (!used[p] && (segs[p].first <= i && i <= segs[p].second) &&                 (pos == -1 || segs[p].second > segs[pos].second))               pos = p;           }           assert(pos != -1);           used[pos] = 1;           for (int j = segs[pos].first; j <= segs[pos].second; ++j) --cnt[j];         }       }       vector<int> out;       for (int i = 0; i < int(n); i++)         if (used[i]) out.push_back(i + 1);       int sz = out.size();       cout << sz << endl;       for (int i = 0; i < int(sz); i++) cout << out[i] <<    ;       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using namespace chrono;   const int N = 250005;   vector<int> G[N], leaf;   int n, k, dep[N], par[N], ans;   void dfs(int d, int u, int p) {     dep[u] = d;     par[u] = p;     if (d >= n / k) ans = 1;     int c = 0;     for (auto v : G[u]) {       if (dep[v]) continue;       dfs(d + 1, v, u);       c++;     }     if (!c) leaf.push_back(u);   }   int main() {     time_point<steady_clock> start = steady_clock::now();     int m, u, v;     scanf( %d%d%d , &n, &m, &k);     while (m--) {       scanf( %d%d , &u, &v);       G[u].push_back(v);       G[v].push_back(u);     }     dfs(1, 1, 0);     if (ans) {       ans = leaf[0];       for (auto u : leaf)         if (dep[u] > dep[ans]) ans = u;       printf( PATH n%d n , dep[ans]);       while (ans) {         printf( %d  , ans);         ans = par[ans];       }     } else {       printf( CYCLES n );       for (int i = 0; i < k; i++) {         int x = leaf[i];         u = v = 0;         for (int j = 0; j < G[x].size(); j++) {           if (G[x][j] != par[x]) {             if (!u)               u = G[x][j];             else if (G[x][j] != u) {               v = G[x][j];               break;             }           }         }         if (dep[u] < dep[v]) swap(u, v);         if ((dep[x] - dep[u] + 1) % 3) {           printf( %d n , dep[x] - dep[u] + 1);           while (x != u) {             printf( %d  , x);             x = par[x];           }           printf( %d n , u);         } else if ((dep[x] - dep[v] + 1) % 3) {           printf( %d n , dep[x] - dep[v] + 1);           while (x != v) {             printf( %d  , x);             x = par[x];           }           printf( %d n , v);         } else {           printf( %d n%d  , dep[u] - dep[v] + 2, x);           while (u != v) {             printf( %d  , u);             u = par[u];           }           printf( %d n , v);         }       }     }     cerr << endl          <<  ------------------------------  << endl          <<  Time:            << duration<double, milli>(steady_clock::now() - start).count() <<   ms.           << endl;     return 0;   }


#include <bits/stdc++.h>      using namespace std;      #pragma comment(linker,  /stack:200000000 )   #pragma GCC optimize( Ofast )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native )   #pragma GCC optimize( -ffloat-store )      #define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);   #define int long long   #define endl   n       #define sz(a) ((int)(a).size())   #define all(v) (v).begin(), (v).end()   #define rall(v) (v).rbegin(), (v).rend()   #define tr(c, it) for (auto it = (c).begin(); (it) != (c).end(); it++)   #define pres(c, val) ((c).find(val) != (c).end())      // for sets, multisets, maps etc.   #define cpres(c, val) (find((c).begin(), (c).end(), val) != (c).end()) // for others      #define pb push_back   #define mp make_pair   #define F first   #define S second      #define forf(i, a, b) for (int i = (a); i < (b); i++)   #define forb(i, a, b) for (int i = (b); i >= (a); i--)   #define fo(i, n) forf(i, 0, n)   #define fob(i, n) forb(i, 0, n - 1)      typedef vector<int> vi;   typedef vector<vector<int>> vvi;   typedef pair<int, int> pii;   typedef vector<pair<int, int>> vpii;      const int INF = 9e18;   const int N = 1000000007;   //const int N = 998244353;   const double eps = 1e-9;      const auto start_time = std::chrono::high_resolution_clock::now();      void TIME() {     #ifndef ONLINE_JUDGE       auto end_time = std::chrono::high_resolution_clock::now();       std::chrono::duration<double> diff = end_time - start_time;       cerr <<  Time Taken:   << diff.count() <<  s n ;     #endif   }      #ifndef ONLINE_JUDGE     #include  ./header.h    #else     #define debug(args...) 42   #endif      /* ------------------ Actual Coding Starts ------------------ */      void solve() {     int x;     cin >> x;     int rem = x%11, q = x/11;     int num = (x-rem)/11-10*rem;     if(num<0) cout <<  NO n ;     else cout <<  YES n ;   }      int32_t main() {     fastio;     #ifndef ONLINE_JUDGE       freopen( txt.in ,  r , stdin);       freopen( txt.out ,  w , stdout);     #endif     //cout << fixed << setprecision(10);     int t;     cin >> t;     while(t--) solve();     TIME();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = 9e18L;   const long long mod = 1e9 + 7;   long long power(long long x, long long y) {     long long res = 1;     int mod = 1e9 + 7;     while (y > 0) {       if (y & 1) (res = res * x) %= mod;       (x = x * x) %= mod;       y = y >> 1;     }     return res;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     string s;     cin >> s;     long long n = s.size();     if (n <= 2) {       cout << s <<   n ;       return 0;     }     int cnt = 1;     vector<pair<char, long long>> v;     for (int i = 1; i < n; i++) {       if (s[i] == s[i - 1])         cnt++;       else {         v.push_back({s[i - 1], cnt});         cnt = 1;       }     }     v.push_back({s[n - 1], cnt});     int m = v.size();     for (int i = 1; i < m; i++) {       if (v[i].second >= 2 && v[i - 1].second >= 2) {         v[i].second = 1;         v[i - 1].second = 2;       }       if (v[i].second > 2) v[i].second = 2;     }     string res =   ;     for (auto x : v) {       long long k = min(x.second, 2LL);       while (k--) res += x.first;     }     cout << res <<   n ;   }


#include <bits/stdc++.h>   const double pi = 3.141592653589793238462;   const double eps = 1e-10;   using namespace std;   const int maxn = 100010;   int c[maxn];   multiset<int> a;   multiset<int> b;   multiset<int>::iterator setfloor(int val) {     multiset<int>::iterator it = b.upper_bound(val);     if (it == b.begin()) it = b.end();     it--;     return it;   }   int main() {     int i, j, k, n, m, tc, cnt;     ios_base::sync_with_stdio(false);     cin >> n >> m;     for (i = 0; i < n; i++) {       cin >> j;       a.insert(j);     }     for (i = 0; i < n; i++) {       cin >> j;       b.insert(j);     }     multiset<int>::iterator ita = --a.end();     multiset<int>::iterator itb, tmp1, tmp2;     cnt = 0;     int prev;     for (i = 0; i < n; i++) {       itb = setfloor(m - 1 - *ita);       if (itb != b.end() && *itb <= m - 1 - *ita) {         c[cnt++] = (*ita + *itb) % m;         tmp1 = ita;         ita--;         a.erase(tmp1);         b.erase(itb);       } else         ita--;     }     ita = a.end();     itb = b.end();     while (cnt < n) {       ita--;       itb--;       c[cnt++] = (*ita + *itb) % m;     }     sort(c, c + cnt);     for (i = cnt - 1; i >= 0; i--) cout << c[i] <<    ;     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int const N = 2e5 + 5;   int a[N];   int n, ac, b;   int main() {     cin >> n >> b >> ac;     int temp1 = b;     int temp2 = ac;     for (int i = 0; i < n; i++) cin >> a[i];     int i;     for (i = 0; i < n; i++) {       if (temp1 == 0 && temp2 == 0) break;       if (a[i] && temp1 && temp2 != ac) {         temp1--;         temp2++;       } else {         if (temp2 > 0)           temp2--;         else if (temp1 > 0)           temp1--;       }     }     cout << i << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     if (n <= 6) {       cout << m << endl;       return 0;     }     int mark[8][8] = {0}, i, j, deg[8] = {0}, a, k;     for (i = 0; i < m; i++) {       int x, y;       cin >> x >> y;       mark[x][y] = 1;       mark[y][x] = 1;       deg[x]++;       deg[y]++;     }     int max = INT_MIN;     for (i = 1; i <= 7; i++) {       int v[8] = {0}, c = 0, count = 0;       count = m - deg[i];       for (j = 1; j <= 7; j++) {         if (j == i) continue;         for (k = 1; k <= 7; k++) {           if (k == i) continue;           if (mark[j][k] == 0 && mark[j][i] == 1) v[k]++;         }       }       sort(v, v + 8);       for (j = 1; j <= 7; j++) {         if (mark[i][j] == 1) c++;       }       if (c < v[7])         count += c;       else         count += v[7];       if (count > max) max = count;     }     cout << max << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long a[1005], b[1005], n, i, j, k, temp, sum;     cin >> n;     for (i = 0; i < n; i++) {       cin >> a[i];       cin >> b[i];     }     for (i = 0; i < n - 1; i++) {       for (j = 0; j < n - i - 1; j++) {         if (b[j] > b[j + 1]) {           temp = b[j];           b[j] = b[j + 1];           b[j + 1] = temp;           temp = a[j];           a[j] = a[j + 1];           a[j + 1] = temp;         } else if (b[j] == b[j + 1]) {           if (a[j] > a[j + 1]) {             temp = a[j];             a[j] = a[j + 1];             a[j + 1] = temp;           }         }       }     }     sum = 0;     k = 1;     for (i = n - 1; i >= 0; i--) {       if (k > 0) {         sum += a[i];         k -= 1;       }       k += b[i];       if (k == 0) break;     }     cout << sum << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 5;   inline int read() {     int x = 0;     int f = 1, hhh = getchar();     while (!isdigit(hhh)) {       if (hhh ==  - ) f = -1;       hhh = getchar();     }     while (isdigit(hhh)) {       x = x * 10 + hhh -  0 ;       hhh = getchar();     }     return x * f;   }   int n, l, v1, v2, k;   int main() {     n = read();     l = read();     v1 = read();     v2 = read();     k = read();     int m = ceil(n * 1.0 / k);     double t = 1.0 * (m - 1) * (v2 - v1) / (v1 + v2);     double t2 = 1.0 * l / v2 / (m - t);     double t1 = 1.0 * (l - t2 * v2) / v1;     printf( %f n , t1 + t2);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 100005;   string ax, bx;   int q, pre1[MAXN], pre2[MAXN], pre3[MAXN], pre4[MAXN], a, b, c, d;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> ax >> bx >> q;     for (int i = 1; i <= ax.size(); ++i) {       if (ax[i - 1] ==  A ) {         pre1[i] = pre1[i - 1] + 1;         pre2[i] = pre2[i - 1];       } else {         pre1[i] = 0;         pre2[i] = pre2[i - 1] + 1;       }     }     for (int i = 1; i <= bx.size(); ++i) {       if (bx[i - 1] ==  A ) {         pre3[i] = pre3[i - 1] + 1;         pre4[i] = pre4[i - 1];       } else {         pre3[i] = 0;         pre4[i] = pre4[i - 1] + 1;       }     }     for (int i = 0; i < q; ++i) {       int xa, xb, ya, yb;       cin >> a >> b >> c >> d;       xa = min(pre1[b], b - a + 1);       ya = min(pre3[d], d - c + 1);       xb = pre2[b] - pre2[a - 1];       yb = pre4[d] - pre4[c - 1];       if (xa < ya || xb % 2 != yb % 2) {         cout << 0;         continue;       }       if (xa == ya && xb == 0 && yb != 0) {         cout << 0;         continue;       }       if (xa > ya && (xa - ya) % 3 != 0) {         xb += 2;       }       if (xb <= yb && (yb - xb) % 2 == 0)         cout << 1;       else         cout << 0;     }     cout <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int const N = 3000 + 20;   int n, dp[N], mx1, mx2, ans;   vector<pair<int, bool>> adj[N];   void dfs1(int v, int p = -1) {     for (auto x : adj[v]) {       int u = x.first, f = x.second;       if (u != p) {         dfs1(u, v);         dp[v] += dp[u] + (!f);       }     }     return;   }   void dfs2(int v, int p = -1) {     for (auto x : adj[v]) {       int u = x.first, f = x.second;       if (u != p) {         dp[u] = dp[v];         f ? dp[u]++ : dp[u]--;         dfs2(u, v);       }     }     return;   }   pair<int, int> dfs3(int v, int p = -1) {     int m1 = 0, m2 = 0;     for (auto x : adj[v]) {       int u = x.first, f = x.second;       if (u != p) {         m2 = max(m2, dfs3(u, v).first + (f ? -1 : 1));         if (m2 > m1) swap(m1, m2);       }     }     return {m1, m2};   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cin >> n;     ans = n - 1;     for (int i = 0; i < n - 1; i++) {       int x, y;       cin >> x >> y;       x--, y--;       adj[x].push_back({y, 1});       adj[y].push_back({x, 0});     }     dfs1(0);     dfs2(0);     for (int i = 0; i < n; i++) {       pair<int, int> cur = dfs3(i);       mx1 = cur.first, mx2 = cur.second;       ans = min(ans, dp[i] - mx1 - mx2);     }     return cout << ans, 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int n, c;   vector<long long int> a, b;   long long int pos(long long int l) {     long long int d1 = 0;     for (long long int i = 0; i < n; i++) {       long long int x = (a[i] * l) / b[i];       x++;       d1 += x;     }     return d1;   }   pair<long long int, long long int> fun(long long int l, long long int r) {     while (r - l > 2) {       long long int md1 = l + (r - l) / 3;       long long int md2 = r - (r - l) / 3;       long long int d1 = 0, d2 = 0;       d1 = pos(md1);       d2 = pos(md2);       if (d2 < c)         l = md2;       else if (d1 > c)         r = md1;       else if (d1 == c && d2 == c) {         pair<long long int, long long int> p1 = fun(l, md1);         pair<long long int, long long int> p2 = fun(md2, r);         pair<long long int, long long int> p = make_pair(p1.first, p2.second);         return p;       } else if (d2 == c) {         pair<long long int, long long int> p1 = fun(md1, md2);         pair<long long int, long long int> p2 = fun(md2, r);         pair<long long int, long long int> p = make_pair(p1.first, p2.second);         return p;       } else if (d1 == c) {         pair<long long int, long long int> p1 = fun(l, md1);         pair<long long int, long long int> p2 = fun(md1, md2);         pair<long long int, long long int> p = make_pair(p1.first, p2.second);         return p;       } else {         l = md1;         r = md2;       }     }     if (r - l > 2)       return {l, r};     else {       long long int in = 0;       for (long long int i = l; i <= r; i++) {         if (pos(i) == c) {           l = i;           in++;           break;         }       }       for (long long int i = r; i >= l; i--) {         if (pos(i) == c) {           r = i;           break;         }       }       if (in > 0)         return {l, r};       else         return {-1, -1};     }   }   int32_t main() {     cin >> n >> c;     a.resize(n);     b.resize(n);     long long int l = 0;     for (long long int i = 0; i < n; i++) {       cin >> a[i] >> b[i];       if (a[i] == 0) continue;       long long int x = b[i] / a[i];       if (b[i] % a[i] != 0) x++;       l = max(x, l);     }     l = 1;     long long int r = 1e9 + 1;     pair<long long int, long long int> ans = fun(l, r);     l = ans.first;     r = ans.second;     if (l == -1)       cout << 0;     else       cout << r - l + 1;     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   using namespace std;   template <class c>   struct rge {     c b, e;   };   template <class c>   rge<c> range(c i, c j) {     return rge<c>{i, j};   }   template <class c>   auto dud(c* x) -> decltype(cerr << *x, 0);   template <class c>   char dud(...);   struct debug {     template <class c>     debug& operator<<(const c&) {       return *this;     }   };   void mini(int& a, int b) { a = min(a, b); }   void maxi(int& a, int b) { a = max(a, b); }   int main() {     int n;     scanf( %d , &n);     vector<int> x(n), y(n);     int big_x = INT_MIN;     int small_x = INT_MAX;     int big_y = INT_MIN;     int small_y = INT_MAX;     for (int i = 0; i < n; ++i) {       scanf( %d%d , &x[i], &y[i]);       mini(small_x, x[i]);       mini(small_y, y[i]);       maxi(big_x, x[i]);       maxi(big_y, y[i]);     }     int best = 0;     for (int i = 0; i < n; ++i) {       maxi(best, big_x - x[i] + big_y - y[i]);       maxi(best, x[i] - small_x + big_y - y[i]);       maxi(best, x[i] - small_x + y[i] - small_y);       maxi(best, big_x - x[i] + y[i] - small_y);     }     printf( %d  , 2 * best);     for (int i = 4; i <= n; ++i) {       printf( %d  , 2 * (big_x - small_x + big_y - small_y));     }     puts(  );   }


#include <bits/stdc++.h>   using namespace std;   void fastio() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);   }   long long fre[1000000];   int32_t main() {     fastio();     long long n;     cin >> n;     long long a[n];     for (long long i = 0; i < n; i++) cin >> a[i];     sort(a, a + n);     for (long long i = 0; i < n; i++) {       for (long long j = i + 1; j < n; j++) {         fre[a[i] + a[j]]++;       }     }     long long ans = 0;     for (long long i = 0; i < 1000000; i++) {       ans = max(ans, fre[i]);     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long A, B;     int N;     long long l, r, t, tt, M;     cin >> A >> B >> N;     for (int i = 0; i < N; i++) {       scanf( %I64d%I64d%I64d , &l, &t, &M);       long long st = l, ed = l + 1000000;       long long H = A + (l - 1) * B;       long long D = B, C = t / B;       if (t < H) {         puts( -1 );         continue;       }       while (ed - st > 1) {         long long md = (st + ed) >> 1;         long long E = A + (md - 1) * B;         long long L = md - l + 1;         long long tot = (H + E) * L / 2;         long long tt = max(E, (tot - 1 + M) / M);         if (t >= tt)           st = md;         else           ed = md;       }       long long E = A + (ed - 1) * B;       long long L = ed - l + 1;       long long tot = (H + E) * L / 2;       long long tt = max(E, (tot - 1 + M) / M);       if (t >= tt) st++;       cout << st << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1010;   long long t, n, arr[MAXN], h, sub[MAXN], cnt, add[MAXN];   long long find(int x) {     long long l = 0, r = cnt;     while (l < r) {       long long mid = (l + r) >> 1;       if (sub[mid] >= x)         r = mid;       else         l = mid + 1;     }     if (sub[l] < x) return cnt + 1;     return l;   }   bool check(long long x) {     long long res = n;     int idx = lower_bound(sub + 1, sub + cnt + 1, x - 1) - sub;     res += add[idx - 1] + (x - 1) * (n - idx + 1);     if (res >= h) return true;     return false;   }   int main() {     scanf( %d , &t);     while (t--) {       cnt = 0;       memset(sub, 0, sizeof(sub));       memset(add, 0, sizeof(add));       scanf( %d%lld , &n, &h);       for (int i = 1; i <= n; ++i) {         scanf( %d , &arr[i]);         if (i > 1) sub[++cnt] = arr[i] - arr[i - 1] - 1;       }       sub[++cnt] = 1e18;       sort(sub + 1, sub + cnt + 1);       for (int i = 1; i <= cnt; ++i) add[i] = add[i - 1] + sub[i];       long long l = 1, r = h;       while (l < r) {         long long mid = (l + r) >> 1;         if (check(mid))           r = mid;         else           l = mid + 1;       }       printf( %lld n , l);     }   }


#include <bits/stdc++.h>   using namespace std;   long long dp[100050][205];   int redpac[100050][4];   int e[100050];   bool cmp(int x, int y) { return redpac[x][0] < redpac[y][0]; }   int main() {     int n, m, k, cur = 0;     long long ans = -1;     priority_queue<pair<int, pair<int, int> > > availablepackets;     scanf( %d%d%d , &n, &m, &k);     for (int i = 0; i < k; i++) {       scanf( %d%d%d%d , &redpac[i][0], &redpac[i][1], &redpac[i][2],             &redpac[i][3]);       e[i] = i;     }     sort(e, e + k, cmp);     memset(dp, -1, sizeof(dp));     dp[1][0] = 0;     for (int i = 1; i <= n; i++) {       if (availablepackets.size() > 0) {         while (availablepackets.top().second.second < i) {           availablepackets.pop();           if (availablepackets.size() == 0) break;         }       }       while (cur < k && redpac[e[cur]][0] <= i) {         availablepackets.push(make_pair(             redpac[e[cur]][3], make_pair(redpac[e[cur]][2], redpac[e[cur]][1])));         cur++;       }       for (int j = 0; j < m + 1; j++) {         if (dp[i][j] == -1) continue;         if (j < m && (dp[i + 1][j + 1] > dp[i][j] || dp[i + 1][j + 1] == -1)) {           dp[i + 1][j + 1] = dp[i][j];         }         if (availablepackets.size() > 0) {           if (dp[availablepackets.top().second.first + 1][j] >                   dp[i][j] + availablepackets.top().first ||               dp[availablepackets.top().second.first + 1][j] == -1) {             dp[availablepackets.top().second.first + 1][j] =                 dp[i][j] + availablepackets.top().first;           }         } else {           if (dp[i + 1][j] == -1 || dp[i + 1][j] > dp[i][j]) {             dp[i + 1][j] = dp[i][j];           }         }       }     }     for (int i = 0; i < m + 1; i++) {       if (dp[n + 1][i] != -1 && (ans > dp[n + 1][i] || ans == -1)) {         ans = dp[n + 1][i];       }     }     printf( %lld , ans);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     vector<int> v(n);     for (int i = 0; i < n; i++) {       cin >> v[i];     }     sort(v.begin(), v.end());     long long sum = 0;     for (int i = 0; i < n / 2; i++) {       long long p_sum = v[i] + v[n - i - 1];       sum += (p_sum * p_sum);     }     cout << sum << endl;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> r;   vector<int> l;   int n, ans, a[550000];   int main() {     cin >> n;     for (int i = 1; i <= n; i++) cin >> a[i];     a[0] = a[1];     a[n + 1] = a[n];     for (int i = 1; i <= n; i++) {       if (a[i] == a[i + 1] && a[i] != a[i - 1]) r.push_back(i);       if (a[i] != a[i + 1] && a[i] == a[i - 1]) l.push_back(i);     }     for (int i = 0; i < l.size(); i++) ans = max(ans, r[i] - l[i]);     cout << ans / 2 << endl;     for (int i = 0; i < l.size(); i++)       if (a[l[i]] == a[r[i]])         for (int j = l[i]; j <= r[i]; j++) a[j] = a[l[i]];       else {         for (int j = l[i]; j <= (r[i] + l[i]) / 2; j++) a[j] = a[l[i]];         for (int j = (r[i] + l[i]) / 2 + 1; j <= r[i]; j++) a[j] = a[r[i]];       }     for (int i = 1; i <= n; i++) cout << a[i] <<    ;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, s;     int max = 0;     int counter = 0;     cin >> n >> s;     for (int i = 0; i < n; i++) {       int a;       cin >> a;       counter += a;       if (a > max) {         max = a;       }     }     if (counter - max > s) {       cout <<  NO ;       return 0;     } else {       cout <<  YES ;       return 0;     }   }


#include <bits/stdc++.h>   using namespace std;   int max(int a, int b, int c, int d) {     if (a >= b && a >= c && a >= d) return a;     if (b >= a && b >= c && b >= d) return b;     if (c >= a && c >= b && c >= d) return c;     if (d >= a && d >= c && d >= b) return d;     return d;   }   int main() {     int x1, x2, x3, x4;     cin >> x1 >> x2 >> x3 >> x4;     int mx = max(x1, x2, x3, x4);     if (mx == x1) {       cout << mx - x2 <<     << mx - x3 <<     << mx - x4;     } else {       if (mx == x2) {         cout << mx - x1 <<     << mx - x3 <<     << mx - x4;       } else {         if (mx == x3) {           cout << mx - x2 <<     << mx - x1 <<     << mx - x4;         } else {           if (mx == x4) {             cout << mx - x2 <<     << mx - x3 <<     << mx - x1;           }         }       }     }   }