#include <bits/stdc++.h>   const int MAXN = 2e5 + 5;   int n, a[MAXN];   long long sm[MAXN];   int ans = 0;   int pc[MAXN];   inline bool check(int l, int r) { return (a[l] ^ a[r]) == sm[r - 1] - sm[l]; }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; ++i) scanf( %d , a + i), sm[i] = sm[i - 1] + a[i];     for (int i = 1; i <= n; ++i) {       int x = a[i];       while (x) x >>= 1, ++pc[i];     }     for (int l = 1; l <= n - 2; ++l) {       int r = l + 2;       while (r <= n && sm[r - 1] - sm[l] < (1ll << pc[l])) {         if (pc[l] >= pc[r]) ans += check(l, r);         ++r;       }     }     std::reverse(a + 1, a + n + 1);     std::reverse(pc + 1, pc + n + 1);     for (int i = 1; i <= n; ++i) sm[i] = sm[i - 1] + a[i];     for (int l = 1; l <= n - 2; ++l) {       int r = l + 2;       while (r <= n && sm[r - 1] - sm[l] < (1ll << pc[l])) {         if (pc[l] > pc[r]) ans += check(l, r);         ++r;       }     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX_N = 2e5 + 10;   int n, m, l, r, x, a[MAX_N], left_ancestor[MAX_N];   int main() {     scanf( %d %d , &n, &m);     for (int i = 1; i <= n; i++) scanf( %d , a + i);     for (int i = 2; i <= n; i++)       if (a[i] == a[i - 1])         left_ancestor[i] = left_ancestor[i - 1];       else         left_ancestor[i] = i - 1;     while (m--) {       scanf( %d %d %d , &l, &r, &x);       if (a[r] != x)         printf( %d n , r);       else if (left_ancestor[r] and l <= left_ancestor[r])         printf( %d n , left_ancestor[r]);       else         puts( -1 );     }     return (0);   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 5 * 1e5;   long long s[maxn], del[maxn], mark[maxn];   void build(int u, int l, int r) {     if (l < r) {       int mid = (l + r) / 2;       build(u * 2, l, mid), build(u * 2 + 1, mid + 1, r);     } else       mark[u] = l;   }   long long query(int u, int l, int r, int x, int y) {     if (y < l || x > r) return 0;     if (x <= l && r <= y) return s[u];     int mid = (l + r) / 2;     long long L = query(u * 2, l, mid, x, y);     long long R = query(u * 2 + 1, mid + 1, r, x, y);     return L + R + max(0, min(r, y) - max(l, x) + 1) * del[u];   }   void clear(int u, int l, int r, int z) {     if (mark[u]) {       del[u] += abs(mark[u] - z);       s[u] += 1LL * (r - l + 1) * abs(mark[u] - z);       mark[u] = 0;     } else {       if (l == r) return;       int mid = (l + r) / 2, lc = u * 2, rc = u * 2 + 1;       clear(lc, l, mid, z);       clear(rc, mid + 1, r, z);       s[u] = s[lc] + s[rc] + 1LL * (r - l + 1) * del[u];     }   }   void modify(int u, int l, int r, int x, int y, int z) {     if (y < l || x > r) return;     if (x <= l && r <= y) {       clear(u, l, r, z);       mark[u] = z;       return;     }     int mid = (l + r) / 2, lc = u * 2, rc = u * 2 + 1;     if (mark[u]) mark[lc] = mark[rc] = mark[u], mark[u] = 0;     modify(lc, l, mid, x, y, z);     modify(rc, mid + 1, r, x, y, z);     s[u] = s[lc] + s[rc] + 1LL * (r - l + 1) * del[u];   }   int main() {     int n, m;     scanf( %d%d , &n, &m);     build(1, 1, n);     int type, x, y, z;     ;     for (int i = 0; i < m; i++) {       scanf( %d%d%d , &type, &x, &y);       if (type == 1) {         scanf( %d , &z);         modify(1, 1, n, x, y, z);       } else         (cout << query(1, 1, n, x, y) << endl);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100001;   int n, m, ind[N], dpth[N], s[N], e[N], t, seg[4 * N], lazy[4 * N], a[N];   vector<vector<int> > g, gift;   vector<pair<int, int> > anc;   vector<int> ans, root;   void dfs(int u) {     s[u] = t++;     for (int i = 0; i < g[u].size(); i++) {       dpth[g[u][i]] = dpth[u] + 1;       dfs(g[u][i]);     }     e[u] = t - 1;   }   void dfs2(int u) {     if (gift[a[u]].empty()) {       anc.push_back(make_pair(-dpth[a[u]], a[u]));     }     gift[a[u]].push_back(u);     for (int i = 0; i < g[u].size(); i++) dfs2(g[u][i]);   }   void checkLazy(int p, int s, int e) {     if (lazy[p] != 0) {       seg[p] += (e - s + 1) * lazy[p];       if (s != e) lazy[2 * p] += lazy[p], lazy[2 * p + 1] += lazy[p];       lazy[p] = 0;     }   }   void build(int p, int s, int e) {     if (s == e) {       seg[p] = 1;       lazy[p] = 0;       return;     }     build(2 * p, s, (s + e) / 2);     build(2 * p + 1, (s + e) / 2 + 1, e);     seg[p] = seg[2 * p] + seg[2 * p + 1];     lazy[p] = lazy[2 * p] + lazy[2 * p + 1];   }   void update(int p, int s, int e, int a, int b, int v) {     checkLazy(p, s, e);     if (s >= a && e <= b) {       seg[p] += (e - s + 1) * v;       if (s != e) lazy[2 * p] += v, lazy[2 * p + 1] += v;       return;     }     if (s > b || e < a) return;     update(2 * p, s, (s + e) / 2, a, b, v);     update(2 * p + 1, (s + e) / 2 + 1, e, a, b, v);     seg[p] = seg[2 * p] + seg[2 * p + 1];   }   int get(int p, int s, int e, int a) {     checkLazy(p, s, e);     if (s == e) return seg[p];     if (a <= (s + e) / 2) return get(2 * p, s, (s + e) / 2, a);     return get(2 * p + 1, (s + e) / 2 + 1, e, a);   }   int main() {     std::ios::sync_with_stdio(false);     scanf( %d%d , &n, &m);     g.resize(n);     memset(ind, 0, sizeof(ind));     build(1, 0, n - 1);     for (int i = 0, a, b; i < m; i++) {       scanf( %d%d , &a, &b);       a--, b--;       g[a].push_back(b);       ind[b]++;     }     for (int i = 0; i < n; i++)       if (ind[i] == 0) root.push_back(i);     for (int i = 0; i < n; i++) {       scanf( %d , a + i);       a[i]--;     }     t = 0;     gift.resize(n);     for (int i = 0; i < root.size(); i++) {       int r = root[i];       dpth[r] = 0;       dfs(r);       anc.clear();       dfs2(r);       sort(anc.begin(), anc.end());       for (int j = 0; j < anc.size(); j++) {         for (int k = 0; k < gift[anc[j].second].size(); k++)           if (get(1, 0, n - 1, s[gift[anc[j].second][k]]) <= 0) {             puts( -1 );             return 0;           }         ans.push_back(anc[j].second + 1);         update(1, 0, n - 1, s[anc[j].second], e[anc[j].second], -1);       }     }     printf( %d n , ans.size());     for (int i = 0; i < ans.size(); i++) printf( %d n , ans[i]);     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1000000007;   const int INF = 1000000001;   const long long LINF = 1000000000000000001LL;   struct ConvexHullTrick {     struct line {       int a;       long long b;       long long eval(int x) { return (long long)a * x + b; }     };     bool incrSlope, incrQueries, queryMax;     ConvexHullTrick(bool incrSlope, bool incrQueries, bool queryMax)         : incrSlope(incrSlope), incrQueries(incrQueries), queryMax(queryMax) {       assert(incrSlope xor incrQueries xor queryMax);     }     deque<line> lines;     long long overtakes(const line &p, const line &q) {       long long x = p.b - q.b;       int y = p.a - q.a;       return (x >= 0 ? x : x - y + 1) / y;     }     bool redundantTop(const line &l) {       int s = lines.size();       if (l.a == lines[s - 1].a) {         return true;       } else {         return overtakes(l, lines[s - 1]) >=                overtakes(lines[s - 1], lines[s - 2]);       }     }     void add(int a, long long b) {       if (!(incrSlope xor incrQueries xor queryMax)) a *= -1;       if (queryMax) b *= -1;       if (!lines.empty() && a == lines.back().a && b >= lines.back().b) {         return;       }       line l = {a, b};       while (lines.size() >= 2 && redundantTop(l)) {         lines.pop_back();       }       lines.push_back(l);     }     long long query(int x) {       if (!(incrSlope xor incrQueries)) x *= -1;       while (lines.size() >= 2 && lines[0].eval(x) > lines[1].eval(x)) {         lines.pop_front();       }       return lines.front().eval(x) * (queryMax ? -1 : 1);     }   };   int main() {     ios_base::sync_with_stdio(false);     ConvexHullTrick hull(false, false, true);     auto add = [&](long long dpValue, int x) { hull.add(-x, dpValue); };     int n;     cin >> n;     struct rect {       int x, y;       long long a;     };     vector<rect> rects(n);     for (auto &e : rects) {       cin >> e.x >> e.y >> e.a;     }     sort(rects.begin(), rects.end(),          [&](const rect &a, const rect &b) { return a.x < b.x; });     vector<long long> dp(n + 1, 0);     add(0, 0);     for (int i = (1); i <= (n); i++) {       auto r = rects[i - 1];       dp[i] = (long long)r.x * r.y - r.a + hull.query(r.y);       add(dp[i], r.x);     }     long long ans = *max_element(dp.begin(), dp.end());     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int N, M;   long long tblX[1001001];   int minp[1001001];   long long gs[1001001];   long long bsum[1001001];   long long bsums0[1001001];   long long bsums1[1001001];   long long bsums2[1001001];   long long linsum(long long K) {     long long P = K, Q = K + 1;     if (P % 2 == 0)       P /= 2;     else       Q /= 2;     return (P * Q) % 1000000007;   }   long long sqrsum(long long K) {     long long ret = K;     ret = ret * (K + 1) % 1000000007;     ret = ret * ((2 * K + 1) % 1000000007) % 1000000007;     return ret * ((1000000007 + 1) / 6) % 1000000007;   }   void erat() {     for (int i = 0; i <= 1000000; i++) minp[i] = -1;     for (int i = 2; i <= 1000000; i++)       if (minp[i] == -1) {         for (int j = i; j <= 1000000; j += i)           if (minp[j] == -1) minp[j] = i;       }   }   long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }   long long count(long long a, long long b) {     if (min(N, M) <= a + b - 1) return 0;     long long pat = (long long)(N - (a + b - 1)) * (M - (a + b - 1)) % 1000000007;     long long ec = a * a + b * b - 2 * (a + b) + 2 * gcd(a, b);     ec %= 1000000007;     return pat * ec % 1000000007;   }   void calc_gs() {     gs[1] = 1;     for (int i = 2; i <= 1000000; i++) {       int p = i, q = i;       long long aux = 0;       int ord = 0;       while (q % minp[i] == 0) {         ++ord;         q /= minp[i];       }       long long pow = 1;       for (int j = 0; j < ord - 1; j++) pow = (pow * minp[i]);       aux += pow * minp[i];       aux += pow * (minp[i] - 1) * ord;       aux %= 1000000007;       aux = aux * gs[q] % 1000000007;       gs[i] = aux;     }   }   void calc_bsum() {     bsum[0] = 0;     for (int i = 1; i <= 1000000; i++) {       long long tmp = sqrsum(i) + sqrsum(i - 1) + 2 * 1000000007 -                       (2 * i * (long long)i % 1000000007) + 2 * gs[i];       bsum[i] = tmp % 1000000007;     }   }   void totalize() {     bsums0[0] = bsums1[0] = bsums2[0] = 0;     for (int i = 1; i <= 1000000; i++) {       bsums0[i] = (bsums0[i - 1] + bsum[i]) % 1000000007;       bsums1[i] = (bsums1[i - 1] + bsum[i] * i % 1000000007) % 1000000007;       bsums2[i] = (bsums2[i - 1] + bsum[i] * i % 1000000007 * i % 1000000007) %                   1000000007;     }   }   int main() {     erat();     calc_gs();     calc_bsum();     totalize();     int T;     scanf( %d , &T);     for (int i = 0; i < T; i++) {       scanf( %d%d , &N, &M);       if (N > M) swap(N, M);       long long ret = (long long)(N + 1) * (M + 1) % 1000000007 * bsums0[N];       ret += 1000000007 - ((long long)(N + M + 2) * bsums1[N] % 1000000007);       ret += bsums2[N];       ret %= 1000000007;       printf( %d n , (int)ret);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n1;   int i, j;   int main() {     int a[10] = {4, 7, 47, 74, 447, 474, 477, 774, 747, 744};     string n;     cin >> n;     int z = n.length();     stringstream stoi(n);     stoi >> n1;     for (i = 0; i < 10; i++) {       if (n1 % a[i] == 0) {         cout <<  YES ;         return 0;       }     }     cout <<  NO ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-6;   const double pi = acos(-1);   int sign(double k) {     if (k > eps)       return 1;     else if (k < -eps)       return -1;     return 0;   }   int cmp(double k1, double k2) { return sign(k1 - k2); }   int inmid(double k1, double k2, double k3) {     return sign(k1 - k3) * sign(k2 - k3) <= 0;   }   struct point {     double x, y;     point operator+(const point &k1) const { return (point){k1.x + x, k1.y + y}; }     point operator-(const point &k1) const { return (point){x - k1.x, x - k1.y}; }     point operator*(double &k1) const { return (point){x * k1, y * k1}; }     point operator/(double &k1) const { return (point){x / k1, y / k1}; }     int operator==(const point &k1) const {       return cmp(x, k1.x) == 0 && cmp(y, k1.y) == 0;     }     double abs() { return sqrt(x * x + y * y); }     double abs2() { return x * x + y * y; }     double dis(point k1) { return ((*this) - k1).abs(); }   };   struct osc {     double ang;     int v;   };   bool osccmp(osc a, osc b) {     int res = cmp(a.ang, b.ang);     if (res == -1) return 1;     if (res == 0 && a.v > b.v) return 1;     return 0;   }   int n, K;   int sz;   osc angle[400050];   point a[100050];   bool check(double R) {     sz = 0;     int now = 0;     for (int i = 1; i <= n; i++) {       double d = a[i].abs() / 2;       if (cmp(d, R) == 1) continue;       double t = atan2(a[i].y, a[i].x);       if (t < 0) t += 2 * pi;       double dt = acos(d / R);       double f = t - dt, s = t + dt;       if (cmp(f, 0.0) == -1) f += 2 * pi;       if (cmp(s, 2 * pi) == 1) s -= 2 * pi;       if (cmp(f, s) == 1 || cmp(f, 0.0) == 0) now++;       angle[++sz] = (osc){f, 1};       angle[++sz] = (osc){s, -1};     }     sort(angle + 1, angle + sz + 1, osccmp);     for (int i = 1; i <= sz; i++) {       now += angle[i].v;       if (now >= K) return 1;     }     return 0;   }   int main() {     ios_base::sync_with_stdio(false);     cin >> n >> K;     for (int i = 1; i <= n; i++) {       int x, y;       cin >> x >> y;       if (x == 0 && y == 0) {         K--;         i--;         n--;         continue;       }       a[i] = (point){(double)x, (double)y};     }     if (K <= 0) {       cout << fixed << setprecision(10) << 0.0 <<   n ;       return 0;     }     double l = 0, r = 200000;     for (int round = 1; round <= 100; round++) {       double mid = (l + r) / 2;       if (check(mid))         r = mid;       else         l = mid;     }     cout << fixed << setprecision(10) << l <<   n ;     return 0;   }


#include <bits/stdc++.h>   std::mt19937 rng(       (int)std::chrono::steady_clock::now().time_since_epoch().count());   const int MOD = 1e9 + 7;   const int ms = 220;   int c = 1;   int to[ms][20];   int fail[ms];   int cost[ms];   int addString(const std::vector<int> &str) {     int on = 0;     for (auto ch : str) {       if (to[on][ch] == 0) {         to[on][ch] = c++;       }       on = to[on][ch];     }     return on;   }   void buildAho() {     std::queue<int> que;     que.push(0);     while (!que.empty()) {       int on = que.front();       que.pop();       cost[on] += cost[fail[on]];       for (int i = 0; i < 20; i++) {         if (to[on][i]) {           fail[to[on][i]] = on == 0 ? 0 : to[fail[on]][i];           que.push(to[on][i]);         } else {           to[on][i] = to[fail[on]][i];         }       }     }   }   int l[ms], r[ms];   int dp[ms][ms][505];   int main() {     std::ios_base::sync_with_stdio(false);     std::cin.tie(NULL);     int n, m, k;     std::cin >> n >> m >> k;     {       int len;       std::cin >> len;       while (len > 0) {         std::cin >> l[ms - len];         len--;       }       l[ms - 1]--;       for (int i = ms - 1; l[i] < 0; i--) {         l[i] += m;         l[i - 1]--;       }     }     {       int len;       std::cin >> len;       while (len > 0) {         std::cin >> r[ms - len];         len--;       }     }     while (n--) {       int len;       std::cin >> len;       std::vector<int> str(len);       for (auto &v : str) std::cin >> v;       int v;       std::cin >> v;       cost[addString(str)] += v;     }     buildAho();     {       for (int i = 0; i < c; i++) {         for (int j = 0; j <= k; j++) {           dp[0][i][j] = 1;         }       }       for (int i = 1; i < ms; i++) {         for (int j = 0; j < c; j++) {           for (int val = 0; val <= k; val++) {             for (int ch = 0; ch < m; ch++) {               int newState = to[j][ch];               int newCost = val - cost[newState];               if (newCost >= 0) {                 dp[i][j][val] =                     (dp[i][j][val] + dp[i - 1][newState][newCost]) % MOD;               }             }           }         }       }     }     int ans = 0;     {       bool wtf = false;       int st = 0;       int sum = k;       for (int on = 0; on < ms; on++) {         if (!wtf && r[on] == 0) {           continue;         }         for (int i = (wtf ? 0 : 1); i < r[on]; i++) {           int newState = to[st][i];           int newCost = sum - cost[newState];           if (newCost >= 0) {             ans = (ans + dp[ms - on - 1][newState][newCost]) % MOD;           }         }         st = to[st][r[on]];         sum -= cost[st];         if (wtf) {           for (int i = 1; i < m; i++) {             int newState = to[0][i];             int newCost = k - cost[newState];             if (newCost >= 0) {               ans = (ans + dp[ms - on - 1][newState][newCost]) % MOD;             }           }         }         wtf = true;       }       if (sum >= 0) {         ans = (ans + 1) % MOD;       }     }     {       bool wtf = false;       int st = 0;       int sum = k;       for (int on = 0; on < ms; on++) {         if (!wtf && l[on] == 0) {           continue;         }         for (int i = (wtf ? 0 : 1); i < l[on]; i++) {           int newState = to[st][i];           int newCost = sum - cost[newState];           if (newCost >= 0) {             ans = (ans - dp[ms - on - 1][newState][newCost]) % MOD;           }         }         st = to[st][l[on]];         sum -= cost[st];         if (wtf) {           for (int i = 1; i < m; i++) {             int newState = to[0][i];             int newCost = k - cost[newState];             if (newCost >= 0) {               ans = (ans - dp[ms - on - 1][newState][newCost]) % MOD;             }           }         }         wtf = true;       }       if (wtf && sum >= 0) {         ans = (ans - 1 + MOD) % MOD;       }     }     ans = (ans % MOD + MOD) % MOD;     std::cout << ans << std::endl;   }


#include <bits/stdc++.h>   using namespace std;   long long i, j, k, l, n, m, s, sum, K;   double an;   const long long N = 1020;   long long f[N][N], lu[N][N], ld[N][N], ru[N][N], rd[N][N];   long long Lu[N][N], Ld[N][N], Ru[N][N], Rd[N][N];   int hang[N], lie[N];   char a[N][N];   void work(long long x, long long y) {     long long s = 0;     long long sum = 0;     for (long long i = 1; i < y; i++) {       sum += s;       f[x][i] += sum;       s++;     }     sum += 3 * s;     for (long long i = y + 1; i <= m; i++) {       sum += s;       f[x][i] += sum;       s++;     }     s = 0;     sum = 0;     for (long long i = m; i > y; i--) {       sum += s;       f[x][i] += sum;       s++;     }     sum += 3 * s;     for (long long i = y - 1; i >= 1; i--) {       sum += s;       f[x][i] += sum;       s++;     }     s = 0;     sum = 0;     for (long long i = 1; i < x; i++) {       sum += s;       f[i][y] += sum;       s++;     }     sum += 3 * s;     for (long long i = x + 1; i <= n; i++) {       sum += s;       f[i][y] += sum;       s++;     }     s = 0;     sum = 0;     for (long long i = n; i > x; i--) {       sum += s;       f[i][y] += sum;       s++;     }     sum += 3 * s;     for (long long i = x - 1; i >= 1; i--) {       sum += s;       f[i][y] += sum;       s++;     }   }   int main() {     scanf( %I64d%I64d , &n, &m);     for (long long i = 1; i <= n; i++) {       scanf( %s , a[i] + 1);       for (long long j = 1; j <= m; j++)         if (a[i][j] ==  X ) {           hang[i] = j;           lie[j] = i;           break;         }     }     for (long long i = 1; i <= n; i++) {       long long s = 0;       long long sum = 0;       for (long long j = 1; j <= m; j++) {         sum += s;         lu[i][j] = lu[i - 1][j] + sum + Lu[i - 1][j] * 1;         if (a[i][j] !=  X ) s++;         Lu[i][j] = Lu[i - 1][j] + s;       }     }     for (long long i = 1; i <= n; i++) {       long long s = 0;       long long sum = 0;       for (long long j = m; j >= 1; j--) {         sum += s;         ru[i][j] = ru[i - 1][j] + sum + Ru[i - 1][j] * 1;         if (a[i][j] !=  X ) s++;         Ru[i][j] = Ru[i - 1][j] + s;       }     }     for (long long i = n; i >= 1; i--) {       long long s = 0;       long long sum = 0;       for (long long j = 1; j <= m; j++) {         sum += s;         ld[i][j] = ld[i + 1][j] + sum + Ld[i + 1][j] * 1;         if (a[i][j] !=  X ) s++;         Ld[i][j] = Ld[i + 1][j] + s;       }     }     for (long long i = n; i >= 1; i--) {       long long s = 0;       long long sum = 0;       for (long long j = m; j >= 1; j--) {         sum += s;         rd[i][j] = rd[i + 1][j] + sum + Rd[i + 1][j] * 1;         if (a[i][j] !=  X ) s++;         Rd[i][j] = Rd[i + 1][j] + s;       }     }     long long sx = 0;     for (long long i = 1; i <= n; i++) {       bool ok = false;       for (long long j = 1; j <= m; j++)         if (a[i][j] ==  X ) {           sx++;           work(i, j);           ok = true;           break;         }       if (!ok) work(i, 0);     }     for (long long j = 1; j <= m; j++) {       bool ok = false;       for (long long i = 1; i <= n; i++)         if (a[i][j] ==  X ) {           ok = true;           break;         }       if (!ok) work(0, j);     }     for (long long i = 1; i <= n; i++)       for (long long j = 1; j <= m; j++)         if (a[i][j] !=  X ) {           an += lu[i - 1][j - 1] + ru[i - 1][j + 1] + ld[i + 1][j - 1] +                 rd[i + 1][j + 1];           an += (Lu[i - 1][j - 1] + Ru[i - 1][j + 1] + Ld[i + 1][j - 1] +                  Rd[i + 1][j + 1]) *                 2;           an += f[i][j];         }     for (i = 1; i < n; i++) {       int j = i;       while (hang[j] && hang[j + 1] && (hang[j + 1] > hang[j])) j++;       for (int x = i; x < j; x++)         for (int y = x + 1; y <= j; y++) {           if (hang[x] < hang[y])             an += 4 * (hang[x] - 1) * (m - hang[y]);           else             an += 4 * (hang[y] - 1) * (m - hang[x]);         }       i = j;     }     for (i = 1; i < n; i++) {       int j = i;       while (hang[j] && hang[j + 1] && (hang[j + 1] < hang[j])) j++;       for (int x = i; x < j; x++)         for (int y = x + 1; y <= j; y++) {           if (hang[x] < hang[y])             an += 4 * (hang[x] - 1) * (m - hang[y]);           else             an += 4 * (hang[y] - 1) * (m - hang[x]);         }       i = j;     }     for (i = 1; i < m; i++) {       int j = i;       while (lie[j] && lie[j + 1] && (lie[j + 1] > lie[j])) j++;       for (int x = i; x < j; x++)         for (int y = x + 1; y <= j; y++) {           if (lie[x] < lie[y])             an += 4 * (lie[x] - 1) * (n - lie[y]);           else             an += 4 * (lie[y] - 1) * (n - lie[x]);         }       i = j;     }     for (i = 1; i < m; i++) {       int j = i;       while (lie[j] && lie[j + 1] && (lie[j + 1] < lie[j])) j++;       for (int x = i; x < j; x++)         for (int y = x + 1; y <= j; y++) {           if (lie[x] < lie[y])             an += 4 * (lie[x] - 1) * (n - lie[y]);           else             an += 4 * (lie[y] - 1) * (n - lie[x]);         }       i = j;     }     an = an / ((n * m - sx) * (n * m - sx));     printf( %.8lf , an);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 610;   int N;   vector<int> edge[MAXN];   bool seen[MAXN];   int mtype[MAXN];   int par[MAXN];   int get_count(vector<int> v) {     if (v.size() <= 1) return 0;     cout <<  ?   << v.size() <<   n ;     for (int i = 0; i < v.size(); i++) {       if (i) cout <<    ;       cout << v[i] + 1;     }     cout <<   n  << flush;     int r;     cin >> r;     return r;   }   int through(vector<int> v, int cloc) {     int l = get_count(v);     v.push_back(cloc);     int r = get_count(v);     v.pop_back();     return r - l;   }   vector<int> find_all(vector<int> v, int cloc, int ntot) {     vector<int> res;     if (!ntot) return res;     if (ntot == v.size()) {       for (int x : v) res.push_back(x);       return res;     }     vector<int> vleft, vright;     for (int i = 0; i < v.size(); i++) {       if (i % 2 == 0)         vleft.push_back(v[i]);       else         vright.push_back(v[i]);     }     int tnew = through(vleft, cloc);     res = find_all(vleft, cloc, tnew);     vector<int> vres = find_all(vright, cloc, ntot - tnew);     for (int x : vres) res.push_back(x);     return res;   }   void bflood(int x) {     for (int neigh : edge[x]) {       if (par[neigh] == -1) {         par[neigh] = x;         bflood(neigh);       }     }   }   void solve_bad(int l, int r) {     for (int i = 0; i < MAXN; i++) par[i] = -1;     par[l] = l;     bflood(l);     vector<int> res;     int cloc = r;     while (cloc != l) {       res.push_back(cloc);       cloc = par[cloc];     }     res.push_back(cloc);     cout <<  N   << res.size() <<   n ;     for (int i = 0; i < res.size(); i++) {       if (i) cout <<    ;       cout << res[i] + 1;     }     cout << endl;   }   void wrong(vector<int> v) {     int vtot = get_count(v);     while (true) {       int cloc = v.back();       v.pop_back();       if (get_count(v) != vtot) {         for (int i = 0; i < v.size(); i++) {           vector<int> vq;           vq.push_back(cloc);           vq.push_back(v[i]);           if (get_count(vq)) {             solve_bad(cloc, v[i]);             return;           }         }       }     }   }   void dfs(int cloc) {     seen[cloc] = true;     vector<int> vposs;     for (int i = 0; i < N; i++)       if (cloc != i && !edge[i].size()) vposs.push_back(i);     vector<int> bv = find_all(vposs, cloc, through(vposs, cloc));     for (int i = 0; i < bv.size(); i++) {       edge[cloc].push_back(bv[i]);       edge[bv[i]].push_back(cloc);     }     for (int i = 0; i < bv.size(); i++) {       int neigh = bv[i];       if (!seen[neigh]) dfs(neigh);     }   }   void flood(int cloc, int ctype) {     mtype[cloc] = ctype;     for (int neigh : edge[cloc]) {       if (!mtype[neigh]) flood(neigh, 3 - ctype);     }   }   int main() {     ios_base::sync_with_stdio(0);     cin >> N;     dfs(0);     flood(0, 1);     vector<int> v1, v2;     for (int i = 0; i < N; i++) {       if (mtype[i] == 1)         v1.push_back(i);       else         v2.push_back(i);     }     if (get_count(v1) > 0)       wrong(v1);     else if (get_count(v2) > 0)       wrong(v2);     else {       cout <<  Y   << v1.size() <<   n ;       for (int i = 0; i < v1.size(); i++) {         if (i) cout <<    ;         cout << v1[i] + 1;       }       cout << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     char c;     char prev;     vector<int> A;     int i = 0, count = 1;     scanf( %c , &prev);     A.push_back(1);     while (scanf( %c , &c) != EOF) {       if (c !=  +  && c !=  - ) continue;       if (c == prev) {         A[i]++;       } else {         if (!(A[i] & 1)) {           if (i != 0) {             A[i - 1] += A[i];             A.erase(A.begin() + i);             i--;           }           A[i]++;           prev = c;         } else {           A.push_back(1);           i++;           prev = c;         }       }     }     int flag = 0;     while (flag == 0 && A.size() != 1) {       flag = 1;       for (vector<int>::iterator it = A.begin(); it != A.end(); it++) {         if (!((*it) & 1)) {           flag = 0;           if (it != A.begin()) {             *it += *(it - 1);           }           if ((it + 1) != A.end()) {             *it += *(it + 1);           }           if ((it + 1) != A.end()) A.erase(it + 1);           if (it != A.begin()) A.erase(it - 1);           break;         }       }     }     if (A.size() == 1 && !(A[0] & 1))       cout <<  Yes n ;     else       cout <<  No n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 505;   vector<int> g[N];   int used[N], cant, pep[N][N];   void dfs(int u, int col) {     if (g[u].size() == 0) return;     used[u] = col;     int ncol = ((col == 1) ? 2 : 1);     for (int v : g[u])       if (!used[v]) {         dfs(v, ncol);       } else if (used[v] == col) {         cant = 1;       }   }   int main() {     int n, m;     scanf( %d %d , &n, &m);     for (int i = 0; i < m; ++i) {       int u, v;       scanf( %d %d , &u, &v);       pep[u][v] = pep[v][u] = 1;     }     for (int i = 1; i <= n; ++i) {       for (int j = 1; j <= n; ++j) {         if (!pep[i][j] && i != j) {           g[i].push_back(j);         }       }     }     for (int i = 1; i <= n; ++i) {       if (!used[i]) dfs(i, 1);     }     if (cant) {       printf( No n );       return 0;     }     char s[N];     for (int i = 1; i <= n; ++i) {       if (used[i] == 1) {         s[i - 1] =  a ;       } else if (used[i] == 2) {         s[i - 1] =  c ;       } else {         s[i - 1] =  b ;       }     }     s[n] =   0 ;     for (int i = 1; i <= n; ++i) {       for (int j = 1; j <= n; ++j) {         if (pep[i][j]) {           if (abs(s[i - 1] - s[j - 1]) > 1) {             printf( No n );             return 0;           }         }       }     }     printf( Yes n%s n , s);     return (0);   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 2;   bool vis[N];   int trie[N * 20][2], sz;   void inser(int n) {     int curr = 0;     for (int i = 19; i >= 0; i--) {       int dir = (n >> i) & 1;       if (trie[curr][dir] == -1) trie[curr][dir] = ++sz;       curr = trie[curr][dir];     }   }   int query(int n) {     int curr = 0, ans = 0;     for (int i = 19; i >= 0; i--) {       int dir = (n >> i) & 1;       if (trie[curr][dir] != -1) {         curr = trie[curr][dir];       } else {         ans += (1 << i);         curr = trie[curr][1 ^ dir];       }     }     return ans;   }   int main() {     memset(trie, -1, sizeof(trie));     int n, q;     scanf( %d%d , &n, &q);     while (n--) {       int a;       scanf( %d , &a);       vis[a] = true;     }     for (int i = 0; i < N; i++)       if (!vis[i]) inser(i);     int xorval = 0;     while (q--) {       int x;       scanf( %d , &x);       xorval ^= x;       printf( %d n , query(xorval));     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 55;   const long long M = 1000003;   struct ban {     long long x;     ban() { x = 0; }     ban(long long x) { this->x = x % M; }   };   bool operator<(const ban& a, const ban& b) { return a.x < b.x; }   bool operator>(const ban& a, const ban& b) { return a.x > b.x; }   bool operator==(const ban& a, const ban& b) { return a.x == b.x; }   ban operator+(const ban& a, const ban& b) { return ban(a.x + b.x); }   ban operator*(const ban& a, const ban& b) { return ban(a.x * b.x); }   ban ast(ban x, int n) {     if (n == 0) return ban(1);     if (n % 2 == 0) {       ban y = ast(x, n / 2);       return y * y;     } else {       ban y = ast(x, n - 1);       return x * y;     }   }   ban operator/(const ban& a, const ban& b) { return a * ast(b, M - 2); }   ban operator-(const ban& a, const ban& b) { return ban(a.x - b.x + M); }   const int n = 50;   const int m = 10;   ban a[N][N];   ban b[N];   int w[N];   ban g[N];   int solv() {     for (int ii = 1; ii <= n; ++ii) {       cout <<  ?   << ii << endl;       cin >> b[ii].x;       for (int j = 0; j <= m; ++j) a[ii][j] = ast(ban(ii), j);     }     for (int jj = 0, ii = 1; jj <= m && ii <= n; ++jj) {       ban maxu;       int maxi;       for (int i = ii; i <= n; ++i) {         if (a[i][jj] > maxu) {           maxu = a[i][jj];           maxi = i;         }       }       w[jj] = ii;       for (int j = 0; j <= m; ++j) {         swap(a[ii][j], a[maxi][j]);       }       swap(b[ii], b[maxi]);       for (int i = 1; i <= n; ++i) {         if (i == ii) continue;         ban t = a[i][jj] / a[ii][jj];         for (int j = jj; j <= m; ++j) {           a[i][j] = a[i][j] - a[ii][j] * t;         }         b[i] = b[i] - b[ii] * t;       }       ++ii;     }     for (int jj = 0; jj <= m; ++jj) {       int ii = w[jj];       if (ii == 0) continue;       g[jj] = b[ii] / a[ii][jj];     }     for (int x = 0; x < M; ++x) {       ban u;       for (int j = 0; j <= m; ++j) {         u = u + g[j] * ast(ban(x), j);       }       if (u.x == 0) return x;     }     return -1;   }   int main() {     int x = solv();     cout <<  !   << x << endl;     return 0;   }


#include <bits/stdc++.h>   int pprime[1010] = {0};   int prime[1010];   int total;   void Getprime() {     int i, j;     for (i = 2; i * i <= 1010; i++) {       if (!pprime[i]) {         for (j = i; j * i <= 1010; j++) pprime[j * i] = 1;       }     }     total = 0;     for (i = 2; i <= 1010; i++)       if (!pprime[i]) prime[total++] = i;   }   struct Edge {     int next;     int v;     int gcd, lcm;   } edge[10010];   int head[110];   int pos;   void insert(int x, int y, int gcd, int lcm) {     edge[pos].next = head[x];     edge[pos].v = y;     edge[pos].gcd = gcd;     edge[pos].lcm = lcm;     head[x] = pos++;   }   int ans[110];   int mark[110];   bool dfs(int now, int pre) {     int i;     int l, r;     for (i = head[now]; i; i = edge[i].next) {       int v = edge[i].v;       if (v == pre) continue;       l = edge[i].gcd;       r = edge[i].lcm;       if (mark[now] != l && mark[now] != r) return false;       if (mark[now] == l) {         if (mark[v] == r)           continue;         else if (mark[v] == -1) {           mark[v] = r;           if (!dfs(v, now)) {             mark[v] = -1;             return false;           }         } else           return false;       } else {         if (mark[v] == l)           continue;         else if (mark[v] == -1) {           mark[v] = l;           if (!dfs(v, now)) {             mark[v] = -1;             return false;           }         } else           return false;       }     }     return true;   }   struct fff {     int x, y, gcd, lcm;   } ooxx[10010];   int judge(int m) {     for (int i = 0; i < m; i++) {       if (ooxx[i].gcd != 1) return ooxx[i].gcd;       if (ooxx[i].lcm != 1) return ooxx[i].lcm;     }     return 0;   }   int main() {     Getprime();     int n, m;     int x, y;     int l, r;     int now;     scanf( %d %d , &n, &m);     for (int i = 1; i <= n; i++) ans[i] = 1;     for (int i = 0; i < m; i++)       scanf( %d %d %d %d , &ooxx[i].x, &ooxx[i].y, &ooxx[i].gcd, &ooxx[i].lcm);     for (int i = 0; i < m; i++)       if (ooxx[i].lcm % ooxx[i].gcd != 0) {         printf( NO n );         return 0;       }     int flag;     for (int k = 0; k < total; k++) {       flag = judge(m);       if (!flag) break;       now = prime[k];       memset(head, 0, sizeof(head));       pos = 1;       for (int i = 0; i < m; i++) {         x = ooxx[i].x;         y = ooxx[i].y;         l = 0;         r = 0;         while (ooxx[i].gcd % now == 0) {           l++;           ooxx[i].gcd /= now;         }         while (ooxx[i].lcm % now == 0) {           r++;           ooxx[i].lcm /= now;         }         insert(x, y, l, r);         insert(y, x, l, r);       }       memset(mark, -1, sizeof(mark));       for (int i = 1; i <= n; i++)         if (mark[i] == -1) {           if (!head[i]) {             mark[i] = 0;             continue;           }           int j = head[i];           l = edge[j].gcd;           r = edge[j].lcm;           mark[i] = l;           if (dfs(i, -1)) continue;           mark[i] = r;           if (dfs(i, -1)) continue;           printf( NO n );           return 0;         }       for (int i = 1; i <= n; i++) {         int add = 1;         int time = mark[i];         while (time--) add *= now;         ans[i] *= add;       }     }     while (1) {       flag = judge(m);       if (!flag) break;       now = flag;       memset(head, 0, sizeof(head));       pos = 1;       for (int i = 0; i < m; i++) {         x = ooxx[i].x;         y = ooxx[i].y;         l = 0;         r = 0;         while (ooxx[i].gcd % now == 0) {           l++;           ooxx[i].gcd /= now;         }         while (ooxx[i].lcm % now == 0) {           r++;           ooxx[i].lcm /= now;         }         insert(x, y, l, r);         insert(y, x, l, r);       }       memset(mark, -1, sizeof(mark));       for (int i = 1; i <= n; i++)         if (mark[i] == -1) {           if (!head[i]) {             mark[i] = 0;             continue;           }           int j = head[i];           l = edge[j].gcd;           r = edge[j].lcm;           mark[i] = l;           if (dfs(i, -1)) continue;           mark[i] = r;           if (dfs(i, -1)) continue;           printf( NO n );           return 0;         }       for (int i = 1; i <= n; i++) {         int add = 1;         int time = mark[i];         while (time--) add *= now;         ans[i] *= add;       }     }     printf( YES n );     for (int i = 1; i <= n; i++) printf( %d  , ans[i]);     printf(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   #pragma GCC optimize( Ofast,no-stack-protector,unroll-loops,fast-math )   const int maxn = 1e6 + 50;   int seg[2 * maxn], ans[maxn], last_pos[maxn], next_pos[maxn];   int n, m;   vector<int> v, get_val, partial_xor;   vector<pair<pair<int, int>, int> > ques;   void update(int val, int l, int r = n) {     for (l += n, r += n; l < r; l >>= 1, r >>= 1) {       if (l & 1) seg[l++] ^= val;       if (r & 1) seg[--r] ^= val;     }   }   int get_xor(int idx) {     int res = 0;     for (idx += n; idx; idx >>= 1) res ^= seg[idx];     return res;   }   void sweep(int pos) {     int val = get_val[v[pos]];     int nxt = next_pos[pos];     update(val, pos, nxt);   }   void input() {     cin >> n;     for (int i = 0; i < n; i++) {       int b;       cin >> b;       if (i == 0)         partial_xor.push_back(b);       else         partial_xor.push_back(partial_xor[i - 1] ^ b);       get_val.push_back(b);       v.push_back(b);       last_pos[i] = n;     }     cin >> m;     for (int i = 0; i < m; i++) {       int l, r;       cin >> l >> r;       l--, r--;       ques.push_back({{l, r}, i});     }   }   void map_it() {     sort(get_val.begin(), get_val.end());     get_val.resize(unique((get_val).begin(), (get_val).end()) - get_val.begin());     for (int i = v.size() - 1; i > -1; i--) {       v[i] =           lower_bound((get_val).begin(), (get_val).end(), v[i]) - get_val.begin();       next_pos[i] = last_pos[v[i]];       last_pos[v[i]] = i;     }     for (int i = 0; i < get_val.size(); i++) update(get_val[i], last_pos[i]);   }   void answer_ques(int i) {     pair<int, int> p = ques[i].first;     ans[ques[i].second] = get_xor(p.second) ^ partial_xor[p.first] ^                           partial_xor[p.second] ^ get_val[v[p.first]];   }   void calc() {     int go_pos = 0;     int i = 0;     sort(ques.begin(), ques.end());     while (go_pos < ques.size()) {       while (go_pos < ques.size() and i == ques[go_pos].first.first)         answer_ques(go_pos++);       if (go_pos == ques.size()) break;       while (i < ques[go_pos].first.first) sweep(i++);     }   }   void ansing() {     for (int i = 0; i < m; i++) cout << ans[i] <<   n ;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     input();     map_it();     calc();     ansing();   }


#include <bits/stdc++.h>   const long long mod = 1e9 + 7;   const int N = 1e5 + 20;   using namespace std;   int main() {     int n, s[N], m;     s[0] = 0;     cin >> n;     for (int i = (1); i <= (n); i++) {       cin >> m;       s[i] = s[i - 1] + m;     }     cin >> m;     for (int i = (1); i <= (m); i++) {       int x, y;       cin >> x >> y;       cout << (s[y] - s[x - 1]) / 10 << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int m, n;     int out;     cin >> m >> n;     if (m >= n && m >= 2) {       out = (m / 2) * n;       if (m % 2 && n / 2) {         out += (n / 2);       }     } else if (n > m && n >= 2) {       out = (n / 2) * m;       if (n % 2 && m / 2) {         out += (m / 2);       }     } else {       out = 0;     }     cout << out;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = (int)1e6 + 7;   const int MOD = (int)1e9 + 7;   const long long INF = (long long)1e18 + 7;   vector<vector<long long>> a;   long long col[N], row[N], trow[N], tcol[N];   long long res;   int m, n;   long long getrow() {     long long ma = trow[1];     long long pos = 1;     for (int i = 2; i <= m; i++)       if (trow[i] > ma) {         ma = trow[i];         pos = i;       }     trow[pos] = 0;     for (int i = 1; i <= n; i++) tcol[i] -= a[pos][i];     return max(0ll, ma);   }   long long getcol() {     long long ma = tcol[1];     long long pos = 1;     for (int i = 2; i <= n; i++)       if (tcol[i] > ma) {         ma = tcol[i];         pos = i;       }     tcol[pos] = 0;     for (int i = 1; i <= m; i++) trow[i] -= a[i][pos];     return max(0ll, ma);   }   void sett() {     for (int i = 1; i <= m; i++) trow[i] = row[i];     for (int i = 1; i <= n; i++) tcol[i] = col[i];   }   void proces(int st, int nd, int rd, int th) {     long long ma = 0;     sett();     if (st)       ma += getcol();     else       ma += getrow();     if (nd)       ma += getcol();     else       ma += getrow();     if (rd)       ma += getcol();     else       ma += getrow();     if (th)       ma += getcol();     else       ma += getrow();     res = max(res, ma);   }   int main() {     cin >> m >> n;     a.resize(m + 1);     for (int i = 1; i <= m; i++) {       a[i].push_back(0);       long long t;       for (int j = 1; j <= n; j++) {         cin >> t;         a[i].push_back(t);       }     }     for (int i = 1; i <= m; i++)       for (int j = 1; j <= n; j++) row[i] += a[i][j];     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) col[i] += a[j][i];     for (int a1 = 0; a1 <= 1; a1++)       for (int a2 = 0; a2 <= 1; a2++)         for (int a3 = 0; a3 <= 1; a3++)           for (int a4 = 0; a4 <= 1; a4++) proces(a1, a2, a3, a4);     cout << res;   }


#include <bits/stdc++.h>   using namespace std;   long long dp[10001];   const long long INF = 1e60 + 7;   long long binpow(long long a, long long b) {     if (a == 0) {       return 0;     }     if (b == 0) return 1;     long long temp = binpow(a, b / 2);     if (b & 1) {       return temp * temp * a;     } else       return temp * temp;   }   long long poweroftwo(long long n) {     if ((n && n & (n - 1)) == 0)       cout <<  y ;     else       cout <<  n ;   }   long long binarysearch(long long a[], long long l, long long r, long long x) {     while (l <= r) {       long long mid = l + (r - l) / 2;       if (a[mid] == x)         return 1;       else if (a[mid] > x) {         r = mid - 1;       } else {         l = mid + 1;       }     }     return 0;   }   long long findSplitPoint(long long arr[], long long n) {     long long leftSum = 0;     for (long long i = 0; i < n; i++) {       leftSum += arr[i];       long long rightSum = 0;       for (long long j = i + 1; j < n; j++) rightSum += arr[j];       if (leftSum == rightSum) return i + 1;     }     return -1;   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     {       long long n, m;       cin >> n >> m;       long long ans = 0;       for (long long i = 0; i < n; i++) {         long long x;         cin >> x;         ans = ans + x;         cout << ans / m <<    ;         ans = ans % m;       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7;   int fx[] = {+1, -1, +0, +0, +1, +1, -1, -1, +0};   int fy[] = {+0, +0, +1, -1, +1, -1, +1, -1, +0};   template <typename T>   inline T GCD(T a, T b) {     a = abs(a);     b = abs(b);     while (b) {       a = a % b;       swap(a, b);     }     return a;   }   template <typename T>   inline T LCM(T x, T y) {     T tp = GCD(x, y);     if ((x / tp) * 1. * y > 9e18) return 9e18;     return (x / tp) * y;   }   template <typename T>   inline T BigMod(T A, T B, T M) {     T ret = 1;     while (B) {       if (B & 1) ret = (ret * A) % M;       A = (A * A) % M;       B = B >> 1;     }     return ret;   }   template <typename T>   inline T ModInv(T A, T M) {     return BigMod(A, M - 2, M);   }   template <typename T>   bool scani(T &n) {     n = 0;     bool got = false;     bool negative = false;     char c = getchar();     while (c <  0  || c >  9 ) {       if (c ==  - ) negative = true;       c = getchar();     }     while (c >=  0  && c <=  9 ) {       got = true;       n = n * 10 + c - 48;       c = getchar();     }     if (negative) n = ~(n - 1);     return got;   }   template <typename T>   void write(T n, bool line = true) {     if (n < 0) {       putchar( - );       n = -n;     }     if (!n) {       putchar( 0 );       if (line) putchar(  n );       return;     }     char buff[22];     int len = 0;     while (n) buff[len++] = n % 10 + 48, n /= 10;     for (int i = len - 1; i >= 0; i--) putchar(buff[i]);     if (line) putchar(  n );   }   int scans(char *a) {     int i = 0;     char c = 0;     while (c < 33) c = getchar();     while (c > 33) {       a[i++] = c;       c = getchar();     }     a[i] = 0;     return i;   }   int main() {     int a, b, c, d, e, f;     cin >> a >> b >> c >> d >> e;     write(min(min(min(a / 1, b / 1), min(c / 2, d / 7)), e / 4));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 100010;   bool vis[MAXN];   char str[MAXN];   int main() {     gets(str);     int len = strlen(str);     char maxch = 0;     memset(vis, false, sizeof(vis));     for (int i = len - 1; i >= 0; i--) {       if (str[i] >= maxch) vis[i] = true;       maxch = max(maxch, str[i]);     }     for (int i = 0; i < len; i++) {       if (vis[i]) putchar(str[i]);     }     puts(  );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   inline void read(T &x) {     x = 0;     char c = getchar();     int f = 1;     while (!isdigit(c)) {       if (c ==  - ) f = -1;       c = getchar();     }     while (isdigit(c)) {       x = x * 10 + c -  0 ;       c = getchar();     }     x *= f;   }   template <class T>   T gcd(T a, T b) {     return !b ? a : gcd(b, a % b);   }   template <class T>   inline void umin(T &x, T y) {     x = x < y ? x : y;   }   template <class T>   inline void umax(T &x, T y) {     x = x > y ? x : y;   }   inline unsigned int R() {     static unsigned int seed = 416;     return seed ^= seed >> 5, seed ^= seed << 17, seed ^= seed >> 13;   }   const int N = 505000;   int n;   map<int, int> Map;   pair<int, int> s[N];   int len;   long long res;   priority_queue<long long, vector<long long>, greater<long long> > heap;   int main() {     read(n);     for (register int i = (1); i <= (n); i++) {       int x;       read(x);       Map[x]++;       res += x;     }     for (auto i : Map) s[++len] = pair<int, int>(i.first, i.second);     int sum = 0;     for (register int j = (len); j >= (1); j--) {       int c = min(s[j].second, sum - 2 * ((int)heap.size()));       vector<long long> cur(c, s[j].first);       c = s[j].second - c;       for (int i = 1; i <= c; i += 2)         if (!heap.empty()) {           long long t = heap.top();           heap.pop();           if (t < s[j].first) {             cur.push_back(s[j].first);             if (i < c) cur.push_back(s[j].first);           } else {             cur.push_back(t);             if (t < 2 * s[j].first && i < c) cur.push_back(2 * s[j].first - t);           }         }       for (auto i : cur) heap.push(i);       sum += s[j].second;     }     while (!heap.empty()) res -= heap.top(), heap.pop();     cout << res;     return 0;   }


#include <bits/stdc++.h>   unsigned long long int factorial(unsigned long long int n) {     unsigned long long int facto;     if (n == 0) return 1;     return facto = n * factorial(n - 1);   }   int main() {     long long int a, b, GCD;     unsigned long long int fa, fb;     scanf( %I64d %I64d , &a, &b);     if (a > b) {       fb = factorial(b);       printf( %I64d n , fb);     } else {       fa = factorial(a);       printf( %I64d n , fa);     }     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 40;   const int MAXM = 210;   int n, m, A[MAXN];   double p[MAXM][MAXN][MAXN];   void lucky() {     scanf( %d %d , &n, &m);     for (int i = 1; i <= n; i++) scanf( %d , &A[i]);   }   int main() {     lucky();     for (int i = 1; i <= n; i++)       for (int j = 1; j <= n; j++) p[0][i][j] = (A[i] > A[j]);     double rat = 1.0 / (0.5 * n * (n + 1));     for (int R = 1; R <= m; R++)       for (int l = 1; l <= n; l++)         for (int r = l; r <= n; r++) {           for (int i = 1; i <= n; i++)             for (int j = 1; j <= n; j++) {               int x = (l <= i && i <= r) ? l + r - i : i;               int y = (l <= j && j <= r) ? l + r - j : j;               p[R][i][j] += rat * p[R - 1][x][y];             }         }     double ans = 0;     for (int i = 1; i <= n; i++)       for (int j = i + 1; j <= n; j++) ans += p[m][i][j];     printf( %.10lf n , ans);     return 0;   }


#include<bits/stdc++.h>       using namespace std;       typedef unsigned long long int ull;   typedef long long int ll;   typedef long double ld;       #define PB push_back   #define MP make_pair   #define F first   #define S second   #define Pair vector<pair<ll,ll>>   #define vec vector <ll>    #define all(a) a.begin(),a.end()   #define mo 1000000007   #define decimal(i,n) fixed << setprecision(i) << n   #define show(a) for(auto xyz:a)cout<<xyz<<   ;cout<<endl;   #define show_nl(a) for(auto xyz:a)cout<<xyz<<endl;   #define MAX (ll)(pow(2,63)-1)   #define fill(a,b) memset(a, b, sizeof(a))   #define yes cout<< YES <<endl;   #define no cout<< NO <<endl;       //modular inverse   void eea(ll a,ll b,ll &x,ll &y)   {       if (a == 1)       {           x = 1; y = 0;           return;       }       ll x1, y1;       eea(b%a,a,x1,y1);       x=y1-(b/a)*x1;       y=x1;   }   ll mi(ll a,ll m)   {       ll x,y;       eea(a,m,x,y);       x= (x%m+m)%m;       return x;   }   //complete       void Sieve(int n)    {        int prime[n+1];       fill(prime,-1);       for (int p=2; p*p<=n; p++)        {            if (prime[p] == -1)            {                for (int i=p*p; i<=n; i += p)                    prime[i] = 0;            }        }        for (int p=2; p<=n; p++)        {                  }          }               int main()   {       ios::sync_with_stdio(0);       cin.tie(0); cout.tie(0);             // freopen( ladder.in ,  r , stdin);   // name of input file    // freopen( ladder.out ,  w , stdout); // name of output file           // ifstream fin( art.in );       // ofstream fout( art.out );              // fstream file, output;    // file.open(R () , ios::in);        // add the address of local input file    // output.open(R () , ios::out);  // add the address of local output file                ll t=1,t1=1;       cin>>t;       while(t--)       {           ll n;           cin>>n;           string s;           cin>>s;           ll t=0,m=0,x=0;           for(ll i=0;i<n;i++)           {               if(s[i]== M )               {                   m++;               }               else if(s[i]== T )               {                   t++;               }               if(m>t)               x=1;           }           t=0,m=0;           for(ll i=n-1;i>=0;i--)           {               if(s[i]== M )               {                   m++;               }               else if(s[i]== T )               {                   t++;               }               if(m>t)               x=1;           }           if(2*m!=t)           x=1;           if(x==1)           cout<< NO n ;           else           cout<< YES n ;           }     }       /*   Some helpful points   1.) Calm yourself   2.) check for semicolon or data type mismatch   3.) It can be solved   */


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     cin >> n >> k;     int z = 0;     for (int i = 0; i < n; ++i) {       int t;       cin >> t;       if ((5 - t) >= k) ++z;     }     cout << z / 3;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void getre() {     int x = 0;     printf( %d n , 1 / x);   }   void gettle() {     int res = 1;     while (1) res <<= 1;     printf( %d n , res);   }   template <typename T, typename S>   inline bool upmin(T &a, const S &b) {     return a > b ? a = b, 1 : 0;   }   template <typename T, typename S>   inline bool upmax(T &a, const S &b) {     return a < b ? a = b, 1 : 0;   }   template <typename N, typename PN>   inline N flo(N a, PN b) {     return a >= 0 ? a / b : -((-a - 1) / b) - 1;   }   template <typename N, typename PN>   inline N cei(N a, PN b) {     return a > 0 ? (a - 1) / b + 1 : -(-a / b);   }   template <typename N>   N gcd(N a, N b) {     return b ? gcd(b, a % b) : a;   }   template <typename N>   inline int sgn(N a) {     return a > 0 ? 1 : (a < 0 ? -1 : 0);   }   inline void gn(long long &x) {     int sg = 1;     char c;     while (((c = getchar()) <  0  || c >  9 ) && c !=  - )       ;     c ==  -  ? (sg = -1, x = 0) : (x = c -  0 );     while ((c = getchar()) >=  0  && c <=  9 ) x = x * 10 + c -  0 ;     x *= sg;   }   inline void gn(int &x) {     long long t;     gn(t);     x = t;   }   inline void gn(unsigned long long &x) {     long long t;     gn(t);     x = t;   }   inline void gn(double &x) {     double t;     scanf( %lf , &t);     x = t;   }   inline void gn(long double &x) {     double t;     scanf( %lf , &t);     x = t;   }   inline void gs(char *s) { scanf( %s , s); }   inline void gc(char &c) {     while ((c = getchar()) > 126 || c < 33)       ;   }   inline void pc(char c) { putchar(c); }   inline long long sqr(long long a) { return a * a; }   inline double sqrf(double a) { return a * a; }   const int inf = 0x3f3f3f3f;   const double pi = 3.14159265358979323846264338327950288L;   const double eps = 1e-6;   const int mo = 1;   int qp(int a, long long b) {     int n = 1;     do {       if (b & 1) n = 1ll * n * a % mo;       a = 1ll * a * a % mo;     } while (b >>= 1);     return n;   }   int n;   int a[222];   int nok[33333];   int ok[33333];   int bo[222][222];   const int dinic_inf = 0x3f3f3f3f;   const int DINIC_MAXV = 555 + 5;   const int DINIC_MAXE = 55555 + 5;   int s, t, vtot;   struct edge {     int v, next;     int f;   } e[DINIC_MAXE * 2];   int g[DINIC_MAXV], etot, eid;   int ae(int u, int v, int f) {     upmax(vtot, u);     upmax(vtot, v);     e[etot].v = v;     e[etot].f = f;     e[etot].next = g[u];     g[u] = etot++;     e[etot].v = u;     e[etot].f = 0;     e[etot].next = g[v];     g[v] = etot++;     return eid++;   }   int d[DINIC_MAXV];   bool lb() {     for (int i = 0; i <= vtot; i++) d[i] = 0;     static int qu[DINIC_MAXV];     int p = 0, q = 0;     qu[q++] = s, d[s] = 1;     while (p != q) {       int u = qu[p++];       for (int i = g[u]; ~i; i = e[i].next)         if (e[i].f && !d[e[i].v]) {           d[e[i].v] = d[u] + 1;           if (e[i].v == t) return 1;           qu[q++] = e[i].v;         }     }     return 0;   }   int aug(int u, int mi) {     if (u == t) return mi;     int su = 0, del;     for (int i = g[u]; ~i; i = e[i].next)       if (e[i].f && d[e[i].v] == d[u] + 1) {         del = aug(e[i].v, min(mi, e[i].f));         e[i].f -= del;         e[i ^ 1].f += del;         mi -= del;         su += del;         if (!mi) break;       }     if (!su) d[u] = -1;     return su;   }   int dinic() {     int su = 0;     while (lb()) su += aug(s, dinic_inf);     return su;   }   void dinic_init() {     static bool ini = 0;     if (!ini) {       ini = 1;       memset(g, -1, sizeof(g));     } else {       for (int i = 0; i <= vtot; i++) g[i] = -1;     }     etot = eid = 0;     vtot = 2, s = 1, t = 2;   }   inline int capaof(int ei) { return e[ei << 1].f + e[ei << 1 ^ 1].f; }   inline int flowof(int ei) { return e[ei << 1 ^ 1].f; }   inline int resiof(int ei) { return e[ei << 1].f; }   inline int uof(int ei) { return e[ei << 1 ^ 1].v; }   inline int vof(int ei) { return e[ei << 1].v; }   vector<int> nei[222];   int vis[222];   int cur = 0;   vector<int> ans[222];   void dfs(int u) {     if (vis[u]) return;     ans[cur].push_back(u);     vis[u] = 1;     dfs(nei[u][0]);     dfs(nei[u][1]);   }   int main() {     nok[1] = 1;     for (int i = 2; i <= 30000; i++)       if (!nok[i])         for (int j = i + i; j <= 30000; j += i) nok[j] = 1;     for (int i = 2; i <= 30000; i++) ok[i] = !nok[i];     gn(n);     for (int i = (1), _ed = (n + 1); i < _ed; i++) gn(a[i]);     for (int i = (1), _ed = (n + 1); i < _ed; i++)       for (int j = (1), _ed = (n + 1); j < _ed; j++)         if (i != j && ok[a[i] + a[j]]) bo[i][j] = 1;     int nu0 = 0, nu1 = 0;     for (int i = (1), _ed = (n + 1); i < _ed; i++)       if (a[i] & 1)         nu1++;       else         nu0++;     if (nu0 != nu1) {       printf( Impossible n );       return 0;     }     dinic_init();     for (int i = (1), _ed = (n + 1); i < _ed; i++)       if (a[i] & 1)         for (int j = (1), _ed = (n + 1); j < _ed; j++)           if (bo[i][j]) ae(i, j, 1);     s = n + 1, t = n + 2;     for (int i = (1), _ed = (n + 1); i < _ed; i++)       if (a[i] & 1)         ae(s, i, 2);       else         ae(i, t, 2);     int su = dinic();     if (su != n) {       printf( Impossible n );       return 0;     }     for (int i = (0), _ed = (eid); i < _ed; i++)       if (uof(i) != s && vof(i) != t && flowof(i) == 1) {         nei[uof(i)].push_back(vof(i));         nei[vof(i)].push_back(uof(i));       }     for (int i = (1), _ed = (n + 1); i < _ed; i++)       if (!vis[i]) {         ++cur;         dfs(i);       }     printf( %d , cur);     for (int i = (1), _ed = (cur + 1); i < _ed; i++) {       printf(  n%d , ans[i].size());       for (int j = (0), _ed = (((int)(ans[i]).size())); j < _ed; j++)         printf(  %d , ans[i][j]);     }     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC optimize( inline )   using namespace std;   const int N = 101010, mod = 1e9 + 7;   namespace {   inline int add(int x, int y) { return (x += y) >= mod ? x - mod : x; }   inline int sub(int x, int y) { return (x -= y) < 0 ? x + mod : x; }   inline int mul(int x, int y) { return 1LL * x * y % mod; }   }  // namespace   struct edge {     int u, v, w;   } e[N];   int n, K, fac[N];   map<long long, int> f[55][55];   vector<pair<int, int> > adj[N];   vector<int> allu, allv;   long long least[N];   inline void U(int &x, int y) { (x += y) >= mod ? x -= mod : x; }   int main(void) {     scanf( %d%d , &n, &K);     fac[0] = 1;     for (int i = 1; i <= n; i++) {       fac[i] = mul(fac[i - 1], i);     }     for (int i = 1, u, v, w; i <= K; i++) {       scanf( %d%d%d , &u, &v, &w);       e[i] = (edge){u, v, sub(w, 1)};       allu.push_back(u);       allv.push_back(v);     }     sort(allu.begin(), allu.end());     sort(allv.begin(), allv.end());     allu.erase(unique(allu.begin(), allu.end()), allu.end());     allv.erase(unique(allv.begin(), allv.end()), allv.end());     int m = allu.size();     for (int i = 1; i <= K; i++) {       int u = lower_bound(allu.begin(), allu.end(), e[i].u) - allu.begin();       int v = lower_bound(allv.begin(), allv.end(), e[i].v) - allv.begin();       adj[u].push_back((pair<int, int>){v, e[i].w});     }     for (int i = m - 1; ~i; i--) {       least[i] = least[i + 1];       for (auto p : adj[i]) {         least[i] |= 1LL << p.first;       }     }     f[0][0][0] = 1;     for (int i = 0; i < m; i++) {       for (int j = 0; j <= i; j++) {         for (auto p : f[i][j]) {           U(f[i + 1][j][p.first & least[i + 1]], p.second);           for (auto t : adj[i]) {             if (~p.first >> t.first & 1) {               U(f[i + 1][j + 1][(p.first | (1LL << t.first)) & least[i + 1]],                 mul(p.second, t.second));             }           }         }       }     }     int ans = 0;     for (int i = 0; i <= m; i++) {       for (auto p : f[m][i]) {         U(ans, mul(p.second, fac[n - i]));       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false), cin.tie(NULL);     long long k = 0;     cin >> k;     if (k == 1) {       cout <<  4 ;       return 0;     }     string s =   ;     unsigned long long a = 1000000000000000000;     unsigned long long num = 0;     long long f = 0;     while (k > 0) {       if (k >= 2) {         k -= 2;         s += to_string(8);         num = (num * 10) + 8;       } else {         k -= 1;         s += to_string(0);         num = (num * 10) + 0;       }       if (num > a) {         f = 1;         break;       }     }     if (f == 0)       cout << s;     else       cout <<  -1 ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int h[36020];   int main() {     char sir[4005];     int a, n, i, j, suma, v[4005];     cin >> a;     cin.get();     cin.get(sir + 1, 4005);     n = strlen(sir + 1);     v[0] = 0;     for (i = 1; i <= n; i++) v[i] = v[i - 1] + (sir[i] -  0 );     for (i = 1; i <= n; i++)       for (j = i; j <= n; j++) {         suma = v[j] - v[i - 1];         h[suma]++;       }     long long int rasp = 0;     for (i = 1; i <= n; i++)       for (j = i; j <= n; j++) {         suma = v[j] - v[i - 1];         if (a == 0) {           if (suma == 0)             rasp += ((n * (n + 1)) / 2);           else             rasp += h[0];         } else if (suma != 0)           if (a % suma == 0) rasp += (((a / suma) < 36020) ? h[a / suma] : 0);       }     cout << rasp <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, k;   unordered_map<int, vector<int> > g;   map<pair<int, int>, int> weights;   map<pair<int, int>, int> idx;   unordered_map<int, bool> used;   struct elem {     int prev;     int u;     long long dist;     elem(int prev, int u, long long dist) : prev(prev), u(u), dist(dist) {}     friend bool operator<(const elem& lh, const elem& rh) {       return lh.dist > rh.dist;     }   };   int main() {     ios_base::sync_with_stdio(false);     cin >> n >> m >> k;     for (int i = 1; i <= m; ++i) {       int u, v, w;       cin >> u >> v >> w;       g[u].push_back(v);       g[v].push_back(u);       weights[make_pair(u, v)] = w;       weights[make_pair(v, u)] = w;       idx[make_pair(u, v)] = i;       idx[make_pair(v, u)] = i;     }     vector<int> res;     priority_queue<elem> q;     q.push(elem(0, 1, 0));     int taken = 0;     int mx = min(n, k);     while (!q.empty() && mx != taken) {       int prev = q.top().prev;       int u = q.top().u;       long long dist = q.top().dist;       q.pop();       if (used[u]) continue;       used[u] = true;       if (prev) {         res.push_back(idx[make_pair(prev, u)]);         ++taken;       }       for (int v : g[u])         if (!used[v]) {           q.push(elem(u, v, dist + weights[make_pair(u, v)]));         }     }     cout << res.size() << endl;     for (int i : res) cout << i <<    ;     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int arr[100005];   long long ans = 0;   int main() {     int n;     cin >> n;     vector<int> a;     for (int i = 0; i < n; i++) {       cin >> arr[i];       if (arr[i] % 2)         a.push_back(arr[i]);       else         ans += arr[i];     }     int i;     if ((int)a.size() % 2)       i = 1;     else       i = 0;     sort(a.begin(), a.end());     int sz = a.size();     for (; i < sz; i++) ans += a[i];     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 2e9;   const long long INFL = 1e18;   const int N = 3e5;   int n, m, R;   vector<int> adj[N + 5];   pair<int, int> E[2 * N + 5];   long long d[N + 5];   struct cmp {     bool operator()(pair<int, long long> x, pair<int, long long> y) {       return (x.second > y.second);     }   };   priority_queue<pair<int, long long>, vector<pair<int, long long> >, cmp> H;   int tr[N + 5];   void Dijkstra() {     for (int i = (1), _b = (n); i <= _b; ++i) d[i] = INFL;     d[R] = 0;     H.push(make_pair(R, d[R]));     while (!H.empty()) {       int u = H.top().first;       long long oldDist = H.top().second;       H.pop();       if (oldDist != d[u]) continue;       for (int i = (0), _b = (((int)(adj[u]).size())); i < _b; ++i) {         int v = E[adj[u][i]].first, w = E[adj[u][i]].second;         if (d[u] + w < d[v] ||             d[u] + w == d[v] && E[adj[u][i]].second < E[tr[v]].second) {           d[v] = d[u] + w;           H.push(make_pair(v, d[v]));           tr[v] = adj[u][i];         }       }     }   }   vector<int> pth;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cin >> n >> m;     int cntE = 0;     while (m--) {       int u, v, w;       cin >> u >> v >> w;       E[++cntE] = make_pair(v, w);       adj[u].push_back(cntE);       E[++cntE] = make_pair(u, w);       adj[v].push_back(cntE);     }     cin >> R;     Dijkstra();     long long res = 0;     for (int i = (1), _b = (n); i <= _b; ++i)       if (i != R) {         res += E[tr[i]].second;         pth.push_back(tr[i]);       }     cout << res <<   n ;     for (int i = (0), _b = (((int)(pth).size())); i < _b; ++i)       cout << (pth[i] + 1) / 2 <<    ;     cout <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MAXN = 2e5 + 10, MOD = 1e9 + 7;   long long n, T, ni[MAXN], jie[MAXN], jie_ni[MAXN], A[MAXN], ans, sum;   long long sum_N, sum_K;   void Init() {     ni[1] = 1;     for (long long i = 2; i <= MAXN - 10; i++) {       ni[i] = ((MOD - (MOD / i)) * ni[MOD % i] % MOD) % MOD;     }     jie_ni[0] = 1;     for (long long i = 1; i <= MAXN - 10; i++) {       jie_ni[i] = jie_ni[i - 1] * ni[i] % MOD;     }     jie[0] = 1;     for (long long i = 1; i <= MAXN - 10; i++) {       jie[i] = jie[i - 1] * i % MOD;     }   }   long long Quick(long long x, long long y) {     long long res = 1, a = x;     while (y) {       if (y & 1) res *= a, res %= MOD;       a = a * a, a %= MOD;       y /= 2;     }     return res;   }   long long C(long long x, long long y) {     if (y == 0) return 1;     if (x == y) return 1;     return (jie[x] * jie_ni[y]) % MOD * jie_ni[x - y] % MOD;   }   long long work(long long N, long long K) {     if (sum_N == 0) {       sum_N = 1;       for (long long i = 1; i <= K; i++) sum_N += C(N, i), sum_N %= MOD;       sum_K = K;       return sum_N;     } else {       sum_N = (sum_N * 2 - C(N - 1, sum_K) + MOD) % MOD;       for (long long i = sum_K; i >= K + 1; i--) {         sum_N -= C(N, i), sum_N = (sum_N + MOD) % MOD;       }       sum_K = K;       return sum_N;     }   }   signed main() {     cin >> n >> T;     Init();     for (long long i = 1; i <= n; i++) cin >> A[i];     long long BASE = 1;     for (long long i = 1; i <= n; i++) {       sum += A[i];       BASE = BASE * 2;       BASE %= MOD;       if (T - sum >= i) {         ans++;         ans %= MOD;       } else if (T - sum < 0) {         break;       } else {         ans += (work(i, T - sum) * Quick(BASE, MOD - 2)) % MOD;         ans %= MOD;       }     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char a[2000][2000];   const int dx[4] = {-1, 0, 1, 0};   const int dy[4] = {0, -1, 0, 1};   queue<pair<int, int> > que;   int main() {     int n, m;     while (~scanf( %d %d , &n, &m)) {       for (int i = 0; i < n; i++) {         getchar();         for (int j = 0; j < m; j++) {           a[i][j] = getchar();         }       }       for (int i = 0; i < n; i++) {         for (int j = 0; j < m; j++) {           int cnt = 0;           for (int k = 0; k < 4; k++) {             int ni = i + dx[k];             int nj = j + dy[k];             if (ni >= 0 && ni < n && nj >= 0 && nj < m && a[ni][nj] ==  . ) {               cnt++;             }           }           if (cnt == 1) {             que.push({i, j});           }         }       }       while (!que.empty()) {         pair<int, int> p = que.front();         que.pop();         int i = p.first, j = p.second, k, ni, nj;         if (a[i][j] !=  . ) {           continue;         }         for (k = 0; k < 4; k++) {           ni = i + dx[k];           nj = j + dy[k];           if (ni >= 0 && ni < n && nj >= 0 && nj < m && a[ni][nj] ==  . ) {             break;           }         }         if (k == 0) {           a[i][j] =  v ;           a[i - 1][j] =  ^ ;         } else if (k == 1) {           a[i][j] =  > ;           a[i][j - 1] =  < ;         } else if (k == 2) {           a[i][j] =  ^ ;           a[i + 1][j] =  v ;         } else if (k == 3) {           a[i][j] =  < ;           a[i][j + 1] =  > ;         } else {           continue;         }         for (int k = 0; k < 4; k++) {           int mi = ni + dx[k];           int mj = nj + dy[k];           if (mi >= 0 && mi < n && mj >= 0 && mj < m && a[mi][mj] ==  . ) {             int cnt = 0;             for (int k = 0; k < 4; k++) {               int pi = mi + dx[k];               int pj = mj + dy[k];               if (pi >= 0 && pi < n && pj >= 0 && pj < m && a[pi][pj] ==  . ) {                 cnt++;               }             }             if (cnt == 1) {               que.push({mi, mj});             }           }         }       }       bool flag = false;       for (int i = 0; i < n; i++) {         for (int j = 0; j < m; j++) {           if (a[i][j] ==  . ) {             flag = true;             break;           }         }         if (flag) {           printf( Not unique n );           break;         }       }       if (!flag) {         for (int i = 0; i < n; i++) {           for (int j = 0; j < m; j++) {             putchar(a[i][j]);           }           putchar(10);         }       }     }     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize  trapv    const int inf1 = 1e9;   const long long int inf2 = 1e18;   const int N = 100000;   using namespace std;   int dirs[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};   vector<int> z_function(string s) {     int n = s.length();     vector<int> z(n);     for (int i = 1, l = 0, r = 0; i < n; ++i) {       if (i <= r) z[i] = min(r - i + 1, z[i - l]);       while (i + z[i] < n && s[z[i]] == s[i + z[i]]) z[i]++;       if (i + z[i] - 1 > r) l = i, r = i + z[i] - 1;     }     return z;   }   bool ispalindrome(string s) {     string t = s;     reverse(s.begin(), s.end());     return t == s;   }   string LPP(string s) {     if (s.length() == 1) return s;     int l = s.length();     string t = s +  # ;     string t2 = s;     reverse(t2.begin(), t2.end());     t += t2;     vector<int> z = z_function(t);     int l2 = 2 * l + 1;     for (int i = l + 1; i < l2; i++) {       if (z[i] == (l2 - i)) {         string ans = t.substr(i, l2 - i);         return ans;       }     }   }   int solve() {     string s;     cin >> s;     int n = s.length();     if (ispalindrome(s)) {       cout << s <<   n ;       return 0;     }     int i = 0;     while (s[i] == s[n - 1 - i]) i++;     string ans = s.substr(0, i);     string ans4 = ans;     reverse(ans4.begin(), ans4.end());     string s2 = s.substr(i, n - 2 * i);     string s3 = s2;     reverse(s3.begin(), s3.end());     string ans1 = LPP(s2);     string ans2 = LPP(s3);     if (ans1.size() >= ans2.size()) {       cout << ans + ans1 + ans4 <<   n ;     } else {       cout << ans + ans2 + ans4 <<   n ;     }     return 0;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int t = 1;     cin >> t;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   inline T euclide(T a, T b, T& x, T& y) {     if (a < 0) {       T d = euclide(-a, b, x, y);       x = -x;       return d;     }     if (b < 0) {       T d = euclide(a, -b, x, y);       y = -y;       return d;     }     if (b == 0) {       x = 1;       y = 0;       return a;     } else {       T d = euclide(b, a % b, x, y);       T t = x;       x = y;       y = t - (a / b) * y;       return d;     }   }   template <class T>   inline void checkmin(T& a, T b) {     if (b < a) a = b;   }   template <class T>   inline void checkmax(T& a, T b) {     if (b > a) a = b;   }   template <class T>   T Abs(T x) {     return x > 0 ? x : -x;   }   template <class T>   inline T sqr(T x) {     return x * x;   }   template <class T>   inline bool isPrime(T n) {     if (n <= 1) return false;     for (T i = 2; i * i <= n; i++)       if (n % i == 0) return false;     return true;   }   template <class T>   inline T Mod(T n, T m) {     return (n % m + m) % m;   }   template <class T>   string toString(T n) {     ostringstream oss;     oss << n;     oss.flush();     return oss.str();   }   int toInt(string s) {     int r = 0;     istringstream sin(s);     sin >> r;     return r;   }   long long toLl(string s) {     long long r = 0;     istringstream sin(s);     sin >> r;     return r;   }   template <class T>   void debug(const T& e) {     cout << e << endl;   }   template <class T1, class T2>   void debug(const T1& e1, const T2& e2) {     cout << e1 <<   t  << e2 << endl;   }   template <class T1, class T2, class T3>   void debug(const T1& e1, const T2& e2, const T3& e3) {     cout << e1 <<   t  << e2 <<   t  << e3 << endl;   }   template <class T1, class T2, class T3, class T4>   void debug(const T1& e1, const T2& e2, const T3& e3, const T4& e4) {     cout << e1 <<   t  << e2 <<   t  << e3 <<   t  << e4 << endl;   }   template <class T1, class T2, class T3, class T4, class T5>   void debug(const T1& e1, const T2& e2, const T3& e3, const T4& e4,              const T5& e5) {     cout << e1 <<   t  << e2 <<   t  << e3 <<   t  << e4 <<   t  << e5 << endl;   }   template <class T>   void debug(vector<T>& e) {     int i;     for (i = 0; i < (int)e.size(); i++) cout << e[i] <<    ;     cout << endl;   }   template <class T>   void debug(vector<basic_string<T> >& e) {     int i, j;     for (i = 0; i < (int)e.size(); i++) {       for (j = 0; j < (int)e[i].size(); j++) cout << e[i][j];       cout << endl;     }     cout << endl;   }   template <class T>   void debug(vector<vector<T> >& e, int row, int col) {     int i, j;     for (i = 0; i < row; i++) {       for (j = 0; j < col; j++) cout << e[i][j] <<   t ;       cout << endl;     }     cout << endl;   }   template <class T>   void debug(T e[100010][100010], int row, int col) {     int i, j;     for (i = 0; i < row; i++) {       for (j = 0; j < col; j++) cout << e[i][j] <<    ;       cout << endl;     }   }   long long Pow(long long B, long long P) {     long long R = 1;     while (P > 0) {       if (P % 2 == 1) R = (R * B);       P /= 2;       B = (B * B);     }     return R;   }   int x[100010], y[100010], a[100010];   int main() {     int i, j, test, Case = 1, n, cnt;     while (scanf( %d , &n) == 1) {       for (i = 0; i < n; i++) scanf( %d , &a[i]);       x[0] = a[0];       for (i = 1; i < n; i++) x[i] = a[i] + x[i - 1];       y[n - 1] = a[n - 1];       for (i = n - 2; i >= 0; i--) y[i] = a[i] + y[i + 1];       cnt = 0;       for (i = 0; i < n - 1; i++)         if (x[i] == y[i + 1]) cnt++;       printf( %d n , cnt);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline long long read() {     long long s = 0, w = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) w = -1;       ch = getchar();     }     while ( 0  <= ch && ch <=  9 )       s = (s << 1) + (s << 3) + (ch ^ 48), ch = getchar();     return s * w;   }   int n, q;   long long A[300010], B[300010], C[300010], D[300010], E[300010];   multiset<long long> S_Max, S_Min;   multiset<long long> S[300010];   int main() {     n = read(), q = read();     for (register int i = 1; i <= n; i++) B[i] = read();     for (register int i = 1; i <= n; i++) A[i] = read(), D[i] += 2, D[A[i]]++;     for (register int i = 1; i <= n; i++) E[i] = B[i] / D[i];     for (register int i = 1; i <= n; i++) C[A[i]] += E[i];     for (register int i = 1; i <= n; i++)       S[A[i]].insert(B[i] - D[i] * E[i] + E[i] + C[i]);     for (register int i = 1; i <= n; i++)       if (!S[i].empty()) {         S_Max.insert(*S[i].rbegin() + E[i]);         S_Min.insert(*S[i].begin() + E[i]);       }     while (q--) {       int opt = read();       if (opt == 1) {         int x = read(), y = read(), fa = A[x];         S_Max.erase(S_Max.find(*S[fa].rbegin() + E[fa]));         S_Min.erase(S_Min.find(*S[fa].begin() + E[fa]));         S[fa].erase(S[fa].find(B[x] - D[x] * E[x] + E[x] + C[x]));         S_Max.erase(S_Max.find(*S[A[fa]].rbegin() + E[A[fa]]));         S_Min.erase(S_Min.find(*S[A[fa]].begin() + E[A[fa]]));         S[A[fa]].erase(S[A[fa]].find(B[fa] - D[fa] * E[fa] + E[fa] + C[fa]));         S_Max.erase(S_Max.find(*S[A[A[fa]]].rbegin() + E[A[A[fa]]]));         S_Min.erase(S_Min.find(*S[A[A[fa]]].begin() + E[A[A[fa]]]));         S[A[A[fa]]].erase(S[A[A[fa]]].find(B[A[fa]] - D[A[fa]] * E[A[fa]] +                                            E[A[fa]] + C[A[fa]]));         C[A[fa]] -= E[fa];         D[fa]--, E[fa] = B[fa] / D[fa], C[fa] -= E[x];         C[A[fa]] += E[fa];         S[A[A[fa]]].insert(B[A[fa]] - D[A[fa]] * E[A[fa]] + E[A[fa]] + C[A[fa]]);         S_Max.insert(*S[A[A[fa]]].rbegin() + E[A[A[fa]]]);         S_Min.insert(*S[A[A[fa]]].begin() + E[A[A[fa]]]);         S[A[fa]].insert(B[fa] - D[fa] * E[fa] + E[fa] + C[fa]);         S_Max.insert(*S[A[fa]].rbegin() + E[A[fa]]);         S_Min.insert(*S[A[fa]].begin() + E[A[fa]]);         if (!S[fa].empty()) {           S_Max.insert(*S[fa].rbegin() + E[fa]);           S_Min.insert(*S[fa].begin() + E[fa]);         }         if (!S[y].empty()) {           S_Max.erase(S_Max.find(*S[y].rbegin() + E[y]));           S_Min.erase(S_Min.find(*S[y].begin() + E[y]));         }         S[y].insert(B[x] - D[x] * E[x] + E[x] + C[x]);         S_Max.erase(S_Max.find(*S[A[y]].rbegin() + E[A[y]]));         S_Min.erase(S_Min.find(*S[A[y]].begin() + E[A[y]]));         S[A[y]].erase(S[A[y]].find(B[y] - D[y] * E[y] + E[y] + C[y]));         S_Max.erase(S_Max.find(*S[A[A[y]]].rbegin() + E[A[A[y]]]));         S_Min.erase(S_Min.find(*S[A[A[y]]].begin() + E[A[A[y]]]));         S[A[A[y]]].erase(             S[A[A[y]]].find(B[A[y]] - D[A[y]] * E[A[y]] + E[A[y]] + C[A[y]]));         C[A[y]] -= E[y];         D[y]++, E[y] = B[y] / D[y], C[y] += E[x];         C[A[y]] += E[y];         S[A[A[y]]].insert(B[A[y]] - D[A[y]] * E[A[y]] + E[A[y]] + C[A[y]]);         S_Max.insert(*S[A[A[y]]].rbegin() + E[A[A[y]]]);         S_Min.insert(*S[A[A[y]]].begin() + E[A[A[y]]]);         S[A[y]].insert(B[y] - D[y] * E[y] + E[y] + C[y]);         S_Max.insert(*S[A[y]].rbegin() + E[A[y]]);         S_Min.insert(*S[A[y]].begin() + E[A[y]]);         S_Max.insert(*S[y].rbegin() + E[y]);         S_Min.insert(*S[y].begin() + E[y]);         A[x] = y;       } else if (opt == 2) {         int x = read();         printf( %lld n , B[x] - D[x] * E[x] + E[x] + C[x] + E[A[x]]);       } else         printf( %lld %lld n , *S_Min.begin(), *S_Max.rbegin());     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int N, M, Dx, Dy;     cin >> N >> M >> Dx >> Dy;     vector<pair<int, int>> way(N);     way[0].first = way[0].second = 0;     for (int i = 1; i < N; ++i) {       way[i].first = (way[i - 1].first + Dx) % N;       way[i].second = (way[i - 1].second + Dy) % N;     }     sort(way.begin(), way.end());     vector<pair<int, int>> trees(M);     for (auto& p : trees) {       cin >> p.first >> p.second;     }     sort(trees.begin(), trees.end());     map<int, int> lower, upper;     for (const auto& tree : trees) {       int x = tree.first;       int y = tree.second;       if (y == way[x].second) {         lower[0]++;         upper[0]++;       } else if (y < way[x].second) {         upper[way[x].second - y]++;         lower[y + N - way[x].second]++;       } else {         lower[y - way[x].second]++;         upper[N - y + way[x].second]++;       }     }     auto it1 =         max_element(lower.begin(), lower.end(),                     [](const pair<int, int>& lhs, const pair<int, int>& rhs) {                       return lhs.second < rhs.second;                     });     auto it2 =         max_element(upper.begin(), upper.end(),                     [](const pair<int, int>& lhs, const pair<int, int>& rhs) {                       return lhs.second < rhs.second;                     });     if (it2->second >= it1->second) {       cout << 0 <<     << (2 * N - it2->first) % N <<   n ;     } else {       cout << 0 <<     << it1->first % N <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k, c = 0;     cin >> n;     int a, f[7];     for (int j = 0; j < 7; j++) f[j] = 0;     for (int i = 0; i < n; i++) {       cin >> a;       for (int j = 0; j < 7; j++) {         if (a % (int)pow(10, 1) == 1) f[j]++;         a = a / 10;       }     }     for (int i = 0; i < 7; i++) c = max(c, f[i]);     cout << c;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int o, O, f, z, i, d;   string t, s[6] = { lios ,  liala ,  etr ,  etra ,  initis ,  inites };   int V[ zz ];   int main() {     while (cin >> t) {       for (i = O = 0; i < 6; i++)         if ((d = t.size() - s[i].size()) < 0 ? 0 : t.substr(d) == s[i]) {           if (z && V[z - 1] > i) break;           O = 1;           V[z++] = i;           f += i / 2 == 1;           o += i % 2;         }       if (!O) {         cout <<  NO n ;         return 0;       }     }     cout << (z != 1 && (o % z || f != 1) ?  NO n  :  YES n );   }


#include <bits/stdc++.h>   using namespace std;   int n, x, y, son[100005], q;   int fir[100005], nxt[200005], to[200005], cnt;   long long wi[200005], z, dp[100005][2], f[100005];   struct node {     int id;     long long val;   } c[100005];   int size[100005], fa[100005], Fa[100005];   long long read() {     long long x = 0;     char ch = getchar();     while (!isdigit(ch)) ch = getchar();     while (isdigit(ch)) x = (x << 3) + (x << 1) + (ch ^ 48), ch = getchar();     return x;   }   void dfs(int x, int fa) {     for (int i = fir[x]; i; i = nxt[i]) {       if (to[i] == fa) continue;       dfs(to[i], x);       if (dp[x][0] < dp[to[i]][0] + wi[i])         dp[x][1] = dp[x][0], dp[x][0] = dp[to[i]][0] + wi[i], son[x] = to[i];       else if (dp[x][1] < dp[to[i]][0] + wi[i])         dp[x][1] = dp[to[i]][0] + wi[i];     }   }   void Dfs(int x, int fa, long long W) {     f[x] = max(dp[x][0], W);     for (int i = fir[x]; i; i = nxt[i]) {       if (to[i] == fa) continue;       if (to[i] == son[x])         Dfs(to[i], x, max(W, dp[x][1]) + wi[i]);       else         Dfs(to[i], x, max(W, dp[x][0]) + wi[i]);     }   }   int cmp(node u, node v) { return u.val < v.val; }   void DFS(int x, int f) {     Fa[x] = f;     for (int i = fir[x]; i; i = nxt[i]) {       if (to[i] == f) continue;       DFS(to[i], x);     }   }   int find(int x) {     if (x == fa[x]) return x;     return fa[x] = find(fa[x]);   }   int main() {     n = read();     for (int i = 1; i < n; i++) {       x = read(), y = read(), z = read();       to[++cnt] = y, nxt[cnt] = fir[x], fir[x] = cnt, wi[cnt] = z;       to[++cnt] = x, nxt[cnt] = fir[y], fir[y] = cnt, wi[cnt] = z;     }     dfs(1, 0);     Dfs(1, 0, 0);     for (int i = 1; i <= n; i++) c[i] = (node){i, f[i]};     sort(c + 1, c + n + 1, cmp);     DFS(c[1].id, 0);     q = read();     for (int i = 1; i <= q; i++) {       z = read();       for (int i = 1; i <= n; i++) fa[i] = i;       for (int i = 1; i <= n; i++) size[i] = 1;       int r = n, ans = 0;       for (int j = n; j >= 1; j--) {         while (r && c[r].val - c[j].val > z) size[find(c[r].id)]--, r--;         ans = max(ans, size[find(c[j].id)]);         int u = find(c[j].id), v = find(Fa[c[j].id]);         if (u != v) fa[u] = v, size[v] += size[u];       }       printf( %d n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char buf[1 << 20], *p1 = buf, *p2 = buf;   template <typename T>   void read(T &x) {     x = 0;     bool f = 1;     char c =         (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 20, stdin), p1 == p2)              ? EOF              : *p1++);     for (; !isdigit(c);          c = (p1 == p2 &&                       (p2 = (p1 = buf) + fread(buf, 1, 1 << 20, stdin), p1 == p2)                   ? EOF                   : *p1++))       if (c ==  - ) f = 0;     if (f)       for (; isdigit(c);            c = (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 20, stdin),                             p1 == p2)                     ? EOF                     : *p1++))         x = x * 10 - 48 + c;     else       for (; isdigit(c);            c = (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 20, stdin),                             p1 == p2)                     ? EOF                     : *p1++))         x = x * 10 + 48 - c;   }   template <typename T, typename... Args>   void read(T &t, Args &...args) {     read(t), read(args...);   }   const int N = 5e3 + 5;   int n, a[N];   int raw, mn, cnt, f[N][N], g[N][N];   int qf(int i, int l, int r) { return f[i][r] - f[i][l - 1]; }   int qg(int i, int l, int r) { return g[i][l] - g[i][r + 1]; }   int main() {     read(n);     for (int i = 1; i <= n; ++i) read(a[i]);     for (int i = 1; i <= n; ++i)       for (int j = i + 1; j <= n; ++j) raw += a[i] > a[j];     for (int i = 1; i <= n; ++i) {       for (int j = 1; j <= n; ++j) f[i][j] = a[j] > a[i], g[i][j] = a[j] < a[i];       for (int j = 1; j <= n; ++j) f[i][j] += f[i][j - 1];       for (int j = n; j >= 1; --j) g[i][j] += g[i][j + 1];     }     for (int i = 1; i <= n; ++i)       for (int j = i + 1; j <= n; ++j) {         int cur = qf(i, i + 1, j - 1) - qg(i, i + 1, j - 1) -                   qf(j, i + 1, j - 1) + qg(j, i + 1, j - 1) +                   (a[i] < a[j] ? 1 : -1);         if (cur < mn)           mn = cur, cnt = 1;         else if (cur == mn)           ++cnt;       }     printf( %d %d , raw + mn, cnt);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 150, M = 65;   int n;   int dist[N][N], g[N][N];   vector<long long> v[M];   map<long long, int> mp;   int main() {     memset(g, 0x3f, sizeof g);     memset(dist, 0x3f, sizeof dist);     cin >> n;     for (int i = 0; i < n; i++) {       long long t, x;       cin >> x;       t = x;       int cnt = 0;       while (t) {         if (t & 1) v[cnt].push_back(x);         t >>= 1;         cnt++;       }     }     int cnt = 0;     bool flag = false;     for (int i = 0; i <= 64; i++) {       int m = v[i].size();       if (!m)         continue;       else if (m > 2) {         flag = true;         break;       } else if (m == 2) {         long long x = v[i][0], y = v[i][1];         if (!mp[x]) mp[x] = ++cnt;         if (!mp[y]) mp[y] = ++cnt;         x = mp[x], y = mp[y];         g[x][y] = g[y][x] = 1;         dist[x][y] = dist[y][x] = 1;       }     }     if (flag)       cout << 3 << endl;     else {       int res = 0x3f3f3f3f;       for (int k = 1; k <= cnt; k++) {         for (int i = 1; i < k; i++)           if (g[k][i] == 1)             for (int j = i + 1; j < k; j++)               if (g[k][j] == 1)                 if (dist[i][j] != 0x3f3f3f3f)                   res = min(res, dist[i][j] + g[i][k] + g[j][k]);         for (int i = 1; i <= cnt; i++)           if (dist[i][k] != 0x3f3f3f3f)             for (int j = 1; j <= cnt; j++)               if (dist[k][j] != 0x3f3f3f3f)                 dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);       }       if (res != 0x3f3f3f3f)         cout << res << endl;       else         cout << -1 << endl;     }   }


#include <bits/stdc++.h>   int n, k, a, b, c, d;   std::vector<int> first_path;   std::vector<int> second_path;   bool first_reversed = false;   bool second_reversed = false;   bool failed = false;   void read() {     scanf( %d %d n%d %d %d %d , &n, &k, &a, &b, &c, &d);     --a;     --b;     --c;     --d;     first_path.resize(n);     second_path.resize(n);   }   void fill_with_everything_except(std::vector<int>::iterator begin,                                    std::vector<int>::iterator end,                                    const std::vector<int> &except) {     for (int i = 0; begin != end; ++begin, ++i) {       while (find(except.begin(), except.end(), i) != except.end()) {         ++i;       }       *begin = i;     }   }   void solve() {     if (a > b) {       std::swap(a, b);       first_reversed = true;     }     if (c > d) {       std::swap(c, d);       second_reversed = true;     }     first_path[0] = a;     first_path[n - 1] = b;     if (a == c && b == d) {       fill_with_everything_except(next(begin(first_path)), prev(end(first_path)),                                   std::vector<int>{a, b});       copy(begin(first_path), end(first_path), begin(second_path));     } else {       if (k < n) {         failed = true;         return;       }       if (a == c) {         fill_with_everything_except(next(begin(first_path)),                                     prev(prev(end(first_path))),                                     std::vector<int>{a, b, d});         first_path[n - 2] = d;         copy(begin(first_path), end(first_path), begin(second_path));         std::swap(second_path[n - 1], second_path[n - 2]);       } else if (b == d) {         fill_with_everything_except(next(next(begin(first_path))),                                     prev(end(first_path)),                                     std::vector<int>{a, b, c});         first_path[1] = c;         copy(begin(first_path), end(first_path), begin(second_path));         std::swap(second_path[0], second_path[1]);       } else {         if (k < n + 1 || n == 4) {           failed = true;           return;         }         fill_with_everything_except(next(next(begin(first_path))),                                     prev(prev(end(first_path))),                                     std::vector<int>{a, b, c, d});         first_path[1] = c;         first_path[n - 2] = d;         copy(begin(first_path), end(first_path), begin(second_path));         std::swap(second_path[0], second_path[1]);         std::swap(second_path[n - 1], second_path[n - 2]);       }     }     if (first_reversed) {       reverse(begin(first_path), end(first_path));     }     if (second_reversed) {       reverse(begin(second_path), end(second_path));     }   }   void print() {     if (failed) {       printf( -1 n );     } else {       for (int i = 0; i < n; ++i) {         printf( %d  , first_path[i] + 1);       }       printf(  n );       for (int i = 0; i < n; ++i) {         printf( %d  , second_path[i] + 1);       }     }   }   int main() {     read();     solve();     print();     return 0;   }