#include <bits/stdc++.h>   using namespace std;   template <typename T, typename U>   std::istream& operator>>(std::istream& i, pair<T, U>& p) {     i >> p.first >> p.second;     return i;   }   template <typename T>   std::istream& operator>>(std::istream& i, vector<T>& t) {     for (auto& v : t) {       i >> v;     }     return i;   }   template <typename T, typename U>   std::ostream& operator<<(std::ostream& o, const pair<T, U>& p) {     o << p.first <<     << p.second;     return o;   }   template <typename T>   std::ostream& operator<<(std::ostream& o, const vector<T>& t) {     if (t.empty()) o <<   n ;     for (size_t i = 0; i < t.size(); ++i) {       o << t[i] <<    n [i == t.size() - 1];     }     return o;   }   template <typename T>   using minheap = priority_queue<T, vector<T>, greater<T>>;   template <typename T>   using maxheap = priority_queue<T, vector<T>, less<T>>;   template <typename T>   bool in(T a, T b, T c) {     return a <= b && b < c;   }   unsigned int logceil(int first) {     return 8 * sizeof(int) - __builtin_clz(first);   }   namespace std {   template <typename T, typename U>   struct hash<pair<T, U>> {     hash<T> t;     hash<U> u;     size_t operator()(const pair<T, U>& p) const {       return t(p.first) ^ (u(p.second) << 7);     }   };   }  // namespace std   template <typename T, typename F>   T bsh(T l, T h, const F& f) {     T r = -1, m;     while (l <= h) {       m = (l + h) / 2;       if (f(m)) {         l = m + 1;         r = m;       } else {         h = m - 1;       }     }     return r;   }   template <typename F>   double bshd(double l, double h, const F& f, double p = 1e-9) {     unsigned int r = 3 + (unsigned int)log2((h - l) / p);     while (r--) {       double m = (l + h) / 2;       if (f(m)) {         l = m;       } else {         h = m;       }     }     return (l + h) / 2;   }   template <typename T, typename F>   T bsl(T l, T h, const F& f) {     T r = -1, m;     while (l <= h) {       m = (l + h) / 2;       if (f(m)) {         h = m - 1;         r = m;       } else {         l = m + 1;       }     }     return r;   }   template <typename F>   double bsld(double l, double h, const F& f, double p = 1e-9) {     unsigned int r = 3 + (unsigned int)log2((h - l) / p);     while (r--) {       double m = (l + h) / 2;       if (f(m)) {         h = m;       } else {         l = m;       }     }     return (l + h) / 2;   }   template <typename T>   T gcd(T a, T b) {     if (a < b) swap(a, b);     return b ? gcd(b, a % b) : a;   }   template <typename T>   class vector2 : public vector<vector<T>> {    public:     vector2() {}     vector2(size_t a, size_t b, T t = T())         : vector<vector<T>>(a, vector<T>(b, t)) {}   };   template <typename T>   class vector3 : public vector<vector2<T>> {    public:     vector3() {}     vector3(size_t a, size_t b, size_t c, T t = T())         : vector<vector2<T>>(a, vector2<T>(b, c, t)) {}   };   template <typename T>   class vector4 : public vector<vector3<T>> {    public:     vector4() {}     vector4(size_t a, size_t b, size_t c, size_t d, T t = T())         : vector<vector3<T>>(a, vector3<T>(b, c, d, t)) {}   };   template <typename T>   class vector5 : public vector<vector4<T>> {    public:     vector5() {}     vector5(size_t a, size_t b, size_t c, size_t d, size_t e, T t = T())         : vector<vector4<T>>(a, vector4<T>(b, c, d, e, t)) {}   };   class vowels {    public:     void solve(istream& cin, ostream& cout) {       int N;       cin >> N;       vector<int> D(1 << 24, 0);       for (int i = 0; i < N; ++i) {         string S;         cin >> S;         int u = 0;         for (char c : S) u |= (1 << (c -  a ));         u ^= (1 << 24) - 1;         D[u]++;       }       for (int i = 0; i < 24; ++i) {         for (int j = 0; j < (1 << 24); ++j) {           if (j & (1 << i)) D[j ^ (1 << i)] += D[j];         }       }       int ans = 0;       for (int i = 0; i < (1 << 24); ++i) {         ans ^= (N - D[i]) * (N - D[i]);       }       cout << ans << endl;     }   };   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     vowels solver;     std::istream& in(std::cin);     std::ostream& out(std::cout);     solver.solve(in, out);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 310, INF = (1 << 27);   int d[MAXN][MAXN];   int all[20][MAXN][MAXN];   int ans[MAXN][MAXN];   int main() {     ios::sync_with_stdio(false);     int n, m;     cin >> n >> m;     for (int i = 0; i < n; i++)       for (int j = 0; j < n; j++) d[i][j] = INF;     for (int i = 0; i < n; i++) d[i][i] = 0;     for (int i = 0; i < m; i++) {       int x, y, w1, w2;       cin >> x >> y >> w1 >> w2;       x--;       y--;       w1 = -w1;       w2 = -w2;       d[x][y] = w1;       d[y][x] = w2;     }     for (int i = 0; i < n; i++)       for (int j = 0; j < n; j++) all[0][i][j] = ans[i][j] = d[i][j];     for (int k = 0; k < n; k++)       for (int i = 0; i < n; i++)         for (int j = 0; j < n; j++) d[i][j] = min(d[i][j], d[i][k] + d[k][j]);     bool hasNeg = false;     for (int i = 0; i < n; i++)       if (d[i][i] < 0) hasNeg = true;     if (!hasNeg) {       cout << 0 << endl;       return 0;     }     int ind;     for (ind = 1; (1 << ind) < n; ind++) {       for (int i = 0; i < n; i++)         for (int j = 0; j < n; j++) {           all[ind][i][j] = INF;           for (int k = 0; k < n; k++)             all[ind][i][j] =                 min(all[ind][i][j], all[ind - 1][i][k] + all[ind - 1][k][j]);         }     }     ind--;     int length = 1;     while (ind >= 0) {       int tmp[MAXN][MAXN];       for (int i = 0; i < n; i++)         for (int j = 0; j < n; j++) {           tmp[i][j] = INF;           for (int k = 0; k < n; k++)             tmp[i][j] = min(tmp[i][j], ans[i][k] + all[ind][k][j]);         }       hasNeg = false;       for (int i = 0; i < n; i++)         if (tmp[i][i] < 0) hasNeg = true;       if (!hasNeg) {         for (int i = 0; i < n; i++)           for (int j = 0; j < n; j++) ans[i][j] = tmp[i][j];         length += (1 << ind);       }       ind--;     }     cout << length + 1 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e6 + 7;   const int mod = 51123987;   const int inv2 = mod + 1 >> 1;   struct Edge {     int to, last, v;   } E[maxn];   int fa[maxn];   int len[maxn];   int dep[maxn];   int head[maxn];   int tot;   int last;   int cnt;   int n;   char s[maxn];   int pre[maxn];   long long suf[maxn];   void Init() {     for (int i = 0; i <= tot; ++i) {       fa[i] = len[i] = dep[i] = 0;       head[i] = 0;     }     cnt = 0;     fa[last = 0] = fa[tot = 1] = 1;     len[1] = -1;   }   int Getfail(int x, int ed) {     while (s[ed] ^ s[ed - len[x] - 1]) x = fa[x];     return x;   }   int Check(int x, int v) {     for (int i = head[x], y; y = E[i].to, i; i = E[i].last)       if (E[i].v == v) return E[i].to;     return 0;   }   void Adde(int x, int y, int z) {     E[++cnt] = (Edge){y, head[x], z};     head[x] = cnt;   }   void Extend(int x, int ed) {     int p = Getfail(last, ed);     int np = Check(p, x);     if (!np) {       np = ++tot;       int pp = Getfail(fa[p], ed);       fa[np] = Check(pp, x);       Adde(p, np, x);       len[np] = len[p] + 2;       dep[np] = dep[fa[np]] + 1;     }     last = np;   }   int main() {     Init();     scanf( %d , &n);     scanf( %s , s + 1);     for (int i = 1; i <= n; ++i) Extend(s[i] -  a , i), pre[i] = dep[last];     Init();     reverse(s + 1, s + n + 1);     for (int i = 1; i <= n; ++i)       Extend(s[i] -  a , i), suf[n - i + 1] = dep[last];     for (int i = n; i; --i) suf[i] += suf[i + 1], suf[i] %= mod;     int ans = 0;     for (int i = 1; i <= n; ++i) (ans += 1LL * pre[i] * suf[i + 1] % mod) %= mod;     int sum = 1LL * suf[1] * (suf[1] - 1) / 2 % mod;     ans = (sum - ans) % mod;     ans < 0 ? ans += mod : 0;     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool vis[200005];   vector<int> v[200005], ak, d1, dn;   vector<int> bfs(int n) {     queue<int> q;     vector<int> dis(200005);     q.push(n);     vis[n] = true;     dis[n] = 0;     while (!q.empty()) {       int x = q.front();       q.pop();       for (int i = 0; i < v[x].size(); i++) {         int u = v[x][i];         if (vis[u] == false) {           vis[u] = true;           dis[u] = dis[x] + 1;           q.push(u);         }       }     }     return dis;   }   bool cmp(int x, int y) { return d1[x] < d1[y]; }   int main() {     int n, m, k, n1, n2, sp, ans = 0;     scanf( %d %d %d , &n, &m, &k);     for (int i = 0; i < k; i++) {       scanf( %d , &sp);       ak.push_back(sp);     }     for (int i = 0; i < m; i++) {       scanf( %d %d , &n1, &n2);       v[n1].push_back(n2);       v[n2].push_back(n1);     }     d1 = bfs(1);     memset(vis, false, sizeof(vis));     dn = bfs(n);     sort(ak.begin(), ak.end(), cmp);     for (int i = 1; i < ak.size(); i++) {       int x = ak[i - 1];       int y = ak[i];       ans = max(ans, d1[x] + 1 + dn[y]);     }     ans = min(ans, d1[n]);     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX_N = 1050;   pair<int, int> a[MAX_N];   int cnt[MAX_N];   int sub[MAX_N];   map<int, int> ids;   int inds[MAX_N];   int id = 0;   int countplz(int f0, int f1) {     memset((sub), 0, sizeof(sub));     ++sub[a[f0].second];     ++sub[a[f1].second];     int ans = 2;     while (true) {       int fnval = a[f0].first + a[f1].first;       auto it = ids.find(fnval);       if (it == ids.end()) {         return ans;       }       int fnid = it->second;       int fn = inds[fnid];       int rest = cnt[fnid] - sub[fnid];       if (rest <= 0) {         return ans;       }       ++ans;       sub[fnid]++;       f0 = f1;       f1 = fn;     }   }   int main() {     int n;     cin >> n;     for (int i = 0; i < n; ++i) {       int x;       cin >> x;       if (ids.count(x) == 0) {         ids[x] = id;         inds[id] = i;         ++id;       }       a[i] = make_pair(x, ids[x]);       cnt[ids[x]]++;     }     int maxs = 2;     if (ids.count(0) > 0) {       maxs = max(maxs, cnt[ids[0]]);     }     for (int i = 0; i < n; ++i) {       for (int j = 0; j < n; ++j) {         if (i == j || (a[i].first == a[j].first && a[i].first == 0)) {           continue;         }         maxs = max(maxs, countplz(i, j));       }     }     cout << maxs << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   class TaskB {    public:     long long dist(pair<long long, long long> f, pair<long long, long long> s) {       return (f.first - s.first) * (f.first - s.first) +              (f.second - s.second) * (f.second - s.second);     }     void solve(std::istream& cin, std::ostream& cout) {       ios_base::sync_with_stdio(0);       cin.tie(0);       cout.tie(0);       vector<pair<long long, long long> > v(3);       set<pair<long long, long long> > st;       for (long long i = 0; i < 3; i++) {         cin >> v[i].first >> v[i].second;       }       vector<pair<long long, long long> > ans;       if (1 || dist(v[1], v[2]) <= dist(v[0], v[1]) + dist(v[0], v[2])) {         ans.push_back({v[1].first + v[2].first - v[0].first,                        v[1].second + v[2].second - v[0].second});       }       if (1 || dist(v[0], v[2]) <= dist(v[2], v[1]) + dist(v[1], v[0])) {         ans.push_back({v[0].first + v[2].first - v[1].first,                        v[0].second + v[2].second - v[1].second});       }       if (1 || dist(v[1], v[0]) <= dist(v[2], v[1]) + dist(v[0], v[2])) {         ans.push_back({v[1].first + v[0].first - v[2].first,                        v[1].second + v[0].second - v[2].second});       }       cout << ans.size() << endl;       for (long long i = 0; i < ans.size(); i++)         cout << ans[i].first <<     << ans[i].second << endl;     }   };   int main() {     TaskB solver;     std::istream& in(std::cin);     std::ostream& out(std::cout);     solver.solve(in, out);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   string a, b;   set<int> A, B;   queue<int> qA, qB;   map<char, queue<int> > q;   vector<pair<int, int> > resp;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cin >> n >> a >> b;     for (int i = 0; i < n; ++i) {       if (a[i] ==  ? )         qA.push(i);       else {         q[a[i]].push(i);         A.insert(i);       }     }     for (int i = 0; i < n; ++i) {       if (b[i] ==  ? )         qB.push(i);       else         B.insert(i);     }     for (int i = 0; i < n; ++i) {       if (!q[b[i]].empty()) {         resp.push_back({q[b[i]].front(), i});         B.erase(i);         A.erase(q[b[i]].front());         q[b[i]].pop();       }     }     while (!qA.empty() && !B.empty()) {       auto it = B.begin();       resp.push_back({qA.front(), *it});       qA.pop();       B.erase(it);     }     while (!qB.empty() && !A.empty()) {       auto it = A.begin();       resp.push_back({*it, qB.front()});       qB.pop();       A.erase(it);     }     while (!qA.empty() && !qB.empty()) {       resp.push_back({qA.front(), qB.front()});       qA.pop();       qB.pop();     }     cout << (int)resp.size() <<   n ;     for (auto x : resp) cout << x.first + 1 <<     << x.second + 1 <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     int n;     double p[111];     cin >> n;     for (int i = 0; i < n; i++) cin >> p[i];     sort(p, p + n);     double ans = p[n - 1], notAns = 1 - p[n - 1];     for (int i = n - 2; i >= 0 && ans < notAns; i--) {       ans = ans * (1 - p[i]) + notAns * p[i];       notAns *= (1 - p[i]);     }     printf( %.12lf n , ans);   }


#include <bits/stdc++.h>   using namespace std;   const long long inf = 1e18;   long long first, T, mt;   long long t[2], p[2], a[2];   long long get(long long ile, long long czas) {     if (ile == 0) {       return 0;     }     if (min(ile * mt, ile * t[1]) > czas) {       return inf;     }     if (ile * mt <= czas) {       return 0;     }     long long st = 0, en = ile, mid = (st + en) / 2, res = inf;     while (st <= en) {       long long il = min(ile, mid * a[1]);       if (il * t[1] + (ile - il) * mt <= czas) {         res = min(res, mid);         en = mid - 1;       } else {         st = mid + 1;       }       mid = (st + en) / 2;     }     return res * p[1];   }   int main() {     scanf( %lld%lld%lld , &first, &T, &mt);     for (int i = 0; i < 2; i++) {       scanf( %lld%lld%lld , a + i, t + i, p + i);     }     if (t[0] > t[1]) {       swap(a[0], a[1]);       swap(t[0], t[1]);       swap(p[0], p[1]);     }     if (min(mt, t[0]) * first > T) {       printf( -1 n );       return 0;     }     if (mt * first <= T) {       printf( 0 n );       return 0;     }     long long res = inf;     for (long long i = 0; (i - 1) * a[0] * t[0] + 1 <= T; i++) {       long long ile = min(first, a[0] * i);       long long cena = i * p[0] + get(first - ile, T - ile * t[0]);       res = min(res, cena);     }     printf( %lld n , res);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t, T, i, n, k, d, ans, val;     cin >> T;     vector<int> id(pow(10, 6) + 1, 0);     for (t = 0; t < T; t++) {       cin >> n >> k >> d;       vector<int> v(n);       for (i = 0; i < n; i++) cin >> v[i];       ans = n;       val = 0;       for (i = 0; i < d; i++) {         id[v[i]]++;         if (id[v[i]] == 1) val++;       }       ans = val;       for (i = d; i < n; i++) {         id[v[i - d]]--;         if (id[v[i - d]] == 0) val--;         id[v[i]]++;         if (id[v[i]] == 1) val++;         ans = min(val, ans);       }       for (i = n - d; i < n; i++) id[v[i]] = 0;       cout << ans << endl;     }   }


#include <bits/stdc++.h>   const int dx[] = {1, 0, -1, 0};   const int dy[] = {0, 1, 0, -1};   using namespace std;   const int MAXN = 55;   int n;   int a[2][MAXN];   int asum[2][MAXN];   int b[MAXN];   int main() {     cin.tie(0);     ios::sync_with_stdio(false);     cin >> n;     for (int j = 0; j < 2; j++)       for (int i = 0; i < n - 1; i++) cin >> a[j][i];     for (int i = 0; i < n; i++) cin >> b[i];     for (int i = 1; i < n; i++) asum[0][i] = asum[0][i - 1] + a[0][i - 1];     for (int i = n - 2; i >= 0; i--) asum[1][i] = asum[1][i + 1] + a[1][i];     vector<int> length;     for (int i = 0; i < n; i++) length.push_back(asum[0][i] + asum[1][i] + b[i]);     sort(length.begin(), length.end());     cout << length[0] + length[1] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100010;   int num[N], tot;   int main() {     int n, a1 = 2, a2 = 1, ans = 1;     cin >> n;     while (a1 - a2 <= n) {       if (n % (a1 - a2) == 0) ans = a1 - a2;       a1 *= 4;       a2 *= 2;     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int k;   int values[107];   int n = 0;   int ans[107][107];   int cmb[107];   int main() {     int i, j, base;     cin >> k;     for (i = 3; i <= 100; i++) values[i] = i * (i - 1) * (i - 2) / 6;     for (i = 2; i <= 100; i++) cmb[i] = i * (i - 1) / 2;     i = 3;     while (values[i] < k) i++;     if (values[i] > k) i--;     k -= values[i];     n = i;     for (i = 1; i <= n; i++)       for (j = 1; j <= n; j++)         if (i != j) ans[i][j] = 1;     while (k) {       for (i = 2; cmb[i] < k; i++)         ;       if (cmb[i] > k) i--;       k -= cmb[i];       n++;       for (j = 1; j <= i; j++) ans[n][j] = ans[j][n] = 1;     }     cout << n <<   n ;     for (i = 1; i <= n; i++) {       for (j = 1; j <= n; j++) cout << ans[i][j];       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct treenode {     long long a, b, c;     treenode(long long a, long long b, long long c) : a(a), b(b), c(c) {}   };   int n, mm, s[111111], m[111111], r[111111], zero[111111], *add;   vector<treenode> tree1[4 * 111111], tree2[4 * 111111], *tree;   set<pair<int, int> > seg;   void mergetrees(vector<treenode> &v1, vector<treenode> &v2,                   vector<treenode> &res) {     for (int i = 0, j = 0;;) {       if (v1[i].a > v2[j].a)         res.push_back(treenode(v1[i].a,                                v1[i].b + v2[j].b + v2[j].c * (v1[i].a - v2[j].a),                                v2[j].c + v1[i].c));       else         res.push_back(treenode(v2[j].a,                                v2[j].b + v1[i].b + v1[i].c * (v2[j].a - v1[i].a),                                v1[i].c + v2[j].c));       if (v1[i].a == 2000000000) break;       if (v1[i + 1].a > v2[j + 1].a)         j++;       else if (v1[i + 1].a < v2[j + 1].a)         i++;       else         i++, j++;     }   }   void build(int node, int vl, int vr) {     if (vl == vr) {       tree[node].push_back(treenode(0, add[vl], r[vl]));       if (r[vl])         tree[node].push_back(treenode((m[vl] - add[vl]) / r[vl] + 1, m[vl], 0));       tree[node].push_back(treenode(2000000000, r[vl] ? m[vl] : add[vl], 0));     } else {       build(node * 2, vl, (vl + vr) / 2);       build(node * 2 + 1, (vl + vr) / 2 + 1, vr);       mergetrees(tree[node * 2], tree[node * 2 + 1], tree[node]);     }   }   long long getsum(int t, int node, int vl, int vr, int l, int r) {     if (l > vr || r < vl)       return 0;     else if (vl >= l && vr <= r) {       vector<treenode> &v = tree[node];       int l = 0, r = (int)v.size() - 1;       while (l != r) {         if (v[(l + r) / 2 + 1].a > t)           r = (l + r) / 2;         else           l = (l + r) / 2 + 1;       }       return tree[node][l].b + tree[node][l].c * (t - tree[node][l].a);     } else {       return getsum(t, node * 2, vl, (vl + vr) / 2, l, r) +              getsum(t, node * 2 + 1, (vl + vr) / 2 + 1, vr, l, r);     }   }   inline long long getdif(int tnow, int tprev, int l, int r) {     if (tprev == -1)       tree = tree2;     else       tree = tree1;     return getsum((tprev == -1) ? tnow : tnow - tprev, 1, 0, n - 1, l - 1, r - 1);   }   int main() {     cin >> n;     for (int i = 0; i < n; i++) scanf( %d%d%d , &s[i], &m[i], &r[i]);     cin >> mm;     tree = tree1;     add = zero;     build(1, 0, n - 1);     tree = tree2;     add = s;     build(1, 0, n - 1);     seg.insert(make_pair(1, -1));     seg.insert(make_pair(n + 1, -1));     for (int i = 0; i < mm; i++) {       int tt, ll, rr;       scanf( %d%d%d , &tt, &ll, &rr);       auto j = seg.upper_bound(make_pair(ll, 2000000000));       j--;       long long ans = 0;       bool flag = true;       for (; j->first <= rr;) {         auto next = j;         next++;         ans += getdif(tt, j->second, max(j->first, ll), min(next->first - 1, rr));         int l1 = j->first, t1 = j->second;         seg.erase(j);         if (l1 < ll) seg.insert(make_pair(l1, t1));         if (flag) seg.insert(make_pair(ll, tt)), flag = false;         if (next->first - 1 > rr) seg.insert(make_pair(rr + 1, t1));         j = next;       }       printf( %I64d n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ld = long double;   using ii = pair<ll, ll>;   using vi = vector<ll>;   using vb = vector<bool>;   using vvi = vector<vi>;   using vii = vector<ii>;   using vvii = vector<vii>;   constexpr int INF = 2000000000;   constexpr ll LLINF = 9000000000000000000;   struct ConvexHullSet {     struct Line {       ld a, b;       mutable ld x;       bool type;       bool operator<(const Line &rhs) const {         return type || rhs.type ? x < rhs.x : a < rhs.a;       }       ld intersect(const Line &rhs) const {         return ld(b - rhs.b) / ld(rhs.a - a);       }     };     set<Line> lines;     static constexpr ld MAX = std::numeric_limits<ld>::max();     ld query(ld x) {       auto it = lines.lower_bound(Line{0.0, 0.0, x, true});       return (it != lines.end() ? it->a * x + it->b : -1e300);     }     void adjust(set<Line>::iterator it) {       if (it != lines.end())         it->x = next(it) != lines.end() ? it->intersect(*next(it)) : MAX;       if (it != lines.begin())         prev(it)->x = it != lines.end() ? it->intersect(*prev(it)) : MAX;     }     void insert(ld a, ld b) {       Line ln = Line{a, b, 0.0, false};       auto it1 = lines.lower_bound(ln);       if (it1 != lines.end() && it1->a == a) {         if (it1->b >= b) return;         it1 = lines.erase(it1);         adjust(it1);       }       ln.x = it1 != lines.end() ? ln.intersect(*it1) : MAX;       while (it1 != lines.end() && ln.x >= it1->x) {         it1 = lines.erase(it1);         ln.x = it1 != lines.end() ? it1->intersect(ln) : MAX;         adjust(it1);       }       while (it1 != lines.begin()) {         --it1;         ld nx = it1->intersect(ln);         if (nx >= it1->x) return;         if (it1 != lines.begin() && prev(it1)->x >= nx) {           it1 = lines.erase(it1);           adjust(it1);         } else           break;       }       it1 = lines.insert(ln).first;       adjust(it1);     }   };   constexpr int L = 0, R = 1000000;   vector<ld> solve(vii &pairs, int s) {     vector<ld> d(R - L + 1, 1e300);     sort(pairs.begin(), pairs.end());     ConvexHullSet chs;     for (int i = 0, p = L; p <= R; ++p) {       while (i < (int)pairs.size() && pairs[i].first == p) {         int x = pairs[i].first, v = pairs[i].second;         ld a = 1.0 / ld(s - v) - ld(v) / (ld(s - v) * ld(s + v));         ld b = -ld(x) / ld(s - v) + ld(x) / ld(s + v) +                ld(v) * ld(x) / (ld(s - v) * ld(s + v));         chs.insert(-a, -b);         ++i;       }       d[p] = -chs.query(p);     }     return d;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     int n, s;     cin >> n >> s;     vi x(n, 0), v(n, 0), t(n, 0);     ld lr = 1e300, rr = 1e300;     int minl = R + 1, maxr = L - 1;     for (int i = 0; i < n; ++i) {       cin >> x[i] >> v[i] >> t[i];       if (t[i] == 1) {         lr = min(lr, ld(x[i]) / ld(v[i]));         if (x[i] < minl) minl = x[i];       } else {         rr = min(rr, ld(R - x[i]) / ld(v[i]));         if (x[i] > maxr) maxr = x[i];       }     }     cerr <<  lr =   << lr <<  , rr =   << rr << endl;     vector<ld> lp, rp;     {       vii pairs[2];       for (int i = 0; i < n; ++i) pairs[t[i] - 1].push_back({x[i], v[i]});       for (ii &pr : pairs[1]) pr.first = R - pr.first;       lp = solve(pairs[0], s);       rp = solve(pairs[1], s);       reverse(rp.begin(), rp.end());     }     ld ans = max(lr, rr);     for (int p = L; p <= R; ++p)       ans = min(ans, max(min(lr, lp[p]), min(rr, rp[p])));     printf( %.10lf n , double(ans));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0), cin.tie(0);     int n, m;     cin >> n >> m;     vector<vector<int>> adj(n);     for (int i = 0, u, v; i < m; ++i) {       cin >> u >> v;       --u, --v;       adj[u].push_back(v);       adj[v].push_back(u);     }     set<int> go;     queue<int> q;     for (int i = 0; i < n; ++i) go.insert(i);     int ans = 0;     for (int x = 0; x < n; ++x)       if (go.find(x) != go.end()) {         ++ans;         go.erase(x);         q.push(x);         while (!q.empty()) {           int u = q.front();           q.pop();           vector<int> add;           for (auto v : adj[u])             if (go.find(v) != go.end()) {               go.erase(v);               add.push_back(v);             }           for (auto v : go) q.push(v);           go.clear();           for (auto v : add) go.insert(v);         }       }     cout << ans - 1 <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct edge {     int v, w;     edge* next;   };   const int N = 100010;   int n, p, ordcnt;   bool vis[N], cut[N];   int ord[N], sum[N], mex[N], q[N], dep[N], digit[N], rdigit[N], rprod[N],       prod[N];   edge* g[N];   void add_edge(int u, int v, int w);   void calc_order(int u);   void calc_sum(int u);   void dfs(int u);   long long calc(int u);   int rev(int a);   void ex_gcd(int a, int b, int& x, int& y);   int main() {     long long ans = 0;     scanf( %d%d , &n, &p);     for (int rep = 1; rep < n; ++rep) {       int u, v, w;       scanf( %d%d%d , &u, &v, &w);       add_edge(u, v, w);       add_edge(v, u, w);     }     prod[0] = 1;     rprod[0] = 1;     rprod[1] = rev(10);     for (int i = 1; i <= n; ++i) prod[i] = 10LL * prod[i - 1] % p;     for (int i = 2; i <= n; ++i)       rprod[i] = (long long)rprod[1] * rprod[i - 1] % p;     calc_order(0);     memset(cut, 0, sizeof(cut));     for (int i = 0; i < n; ++i) {       int u = ord[i];       dep[u] = 0;       digit[u] = 0;       rdigit[u] = 0;       dfs(u);       ans += calc(u);       cut[u] = true;       for (edge* p = g[u]; p; p = p->next)         if (!cut[p->v]) ans -= calc(p->v);       ans -= 1;       ;     }     printf( %lld n , ans);     return 0;   }   int rev(int a) {     int x, y;     ex_gcd(a, p, x, y);     if (x < 0) x += p;     return x;   }   void ex_gcd(int a, int b, int& x, int& y) {     if (b == 0) {       x = 1;       y = 0;       return;     }     ex_gcd(b, a % b, y, x);     y -= a / b * x;   }   long long calc(int u) {     int ql = 0, qr = 1;     long long ret = 0;     map<int, int> mp;     q[0] = u;     while (ql < qr) {       int v = q[ql++];       vis[v] = true;       map<int, int>::iterator it = mp.find(rdigit[v]);       if (it != mp.end())         ++it->second;       else         mp.insert(make_pair(rdigit[v], 1));       for (edge* p = g[v]; p; p = p->next)         if (!vis[p->v] && !cut[p->v]) q[qr++] = p->v;     }     for (int i = 0; i < qr; ++i) vis[q[i]] = false;     for (int i = 0; i < qr; ++i) {       int key = (long long)-digit[q[i]] * rprod[dep[q[i]]] % p;       if (key < 0) key += p;       map<int, int>::iterator it = mp.find(key);       if (it != mp.end()) {         ;         ret += it->second;       }     }     return ret;   }   void dfs(int u) {     vis[u] = true;     for (edge* p = g[u]; p; p = p->next)       if (!vis[p->v] && !cut[p->v]) {         dep[p->v] = dep[u] + 1;         rdigit[p->v] = ((long long)prod[dep[u]] * p->w + rdigit[u]) % ::p;         digit[p->v] = (digit[u] * 10LL + p->w) % ::p;         dfs(p->v);       }     vis[u] = false;   }   void calc_order(int u) {     calc_sum(u);     int s = sum[u], ql = 0, qr = 1;     q[0] = u;     while (ql < qr) {       int v = q[ql++];       vis[v] = true;       mex[v] = max(mex[v], s - sum[v]);       if (mex[v] < mex[u]) u = v;       for (edge* p = g[v]; p; p = p->next)         if (!vis[p->v] && !cut[p->v]) q[qr++] = p->v;     }     for (int i = 0; i < qr; ++i) vis[q[i]] = false;     ord[ordcnt++] = u;     cut[u] = true;     for (edge* p = g[u]; p; p = p->next)       if (!cut[p->v]) calc_order(p->v);   }   void calc_sum(int u) {     vis[u] = true;     mex[u] = 0;     sum[u] = 1;     for (edge* p = g[u]; p; p = p->next)       if (!vis[p->v] && !cut[p->v]) {         calc_sum(p->v);         sum[u] += sum[p->v];         mex[u] = max(mex[u], sum[p->v]);       }     vis[u] = false;   }   void add_edge(int u, int v, int w) {     static edge pool[N * 2];     static edge* p = pool;     ++p;     p->v = v;     p->w = w;     p->next = g[u];     g[u] = p;   }


#include <bits/stdc++.h>   using namespace std;       #define fastIO ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);   #define endl   n    #define lli long long int   #define ld long double   #define p_b push_back   #define m_p make_pair   #define fs first   #define sc second   #define sz(x) ((lli)x.size())   #define all(x) x.begin(),x.end()   const lli mod = 1e9 + 7;   const lli N = 1e6 + 5;   /*****************************************************/   lli t,n,m,a[N]={0},target;   bool dp[105][200005],vis[105][200005];   lli F(lli idx,lli ss)   {       if(vis[idx][ss])           return dp[idx][ss];       vis[idx][ss]=true;       if(idx>n)       {           if(ss==target)               return dp[idx][ss]=true;           return dp[idx][ss]=false;       }       bool ret=F(idx+1,ss),ret1=F(idx+1,ss+a[idx]);       if(ret || ret1)           return dp[idx][ss]=true;       return dp[idx][ss]=false;   }   int main()   {       fastIO       lli i,j,k,x,y;       lli ss=0;       cin>>n;       for(i=1;i<=n;i++)       {           cin>>a[i];           ss+=a[i];       }       if(ss%2!=0)       {           cout<< 0 ;           return 0;       }       target=ss/2;       memset(vis,false,sizeof vis);       memset(dp,false,sizeof dp);       if(F(1,0)==false)       {           cout<< 0 ;           return 0;       }       while(1)       {           for(i=1;i<=n;i++)           {               if(a[i]%2!=0)               {                   cout<< 1 n <<i;                   return 0;               }               a[i]/=2;           }        }              // cerr<<   n  <<  Time elapsed :  << clock() * 1000.0 / CLOCKS_PER_SEC <<   ms n  ;       return 0;   }


#include <bits/stdc++.h>   using namespace std;   int time_to_minute(int h, int m) { return h * 60 + m; }   void minute_to_time(int t, int& h, int& m) {     h = t / 60;     m = t % 60;   }   int main() {     ios_base::sync_with_stdio(false);     int h, m, a;     cin >> h;     cin.ignore(1);     cin >> m >> a;     minute_to_time((time_to_minute(h, m) + a) % (24 * 60), h, m);     cout << (h < 10 ?  0  :   ) << h <<  :  << (m < 10 ?  0  :   ) << m;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100010;   int n, BIT[N];   void update(int idx, int val) {     while (idx <= n) {       BIT[idx] = max(val, BIT[idx]);       idx += idx & -idx;     }   }   int get(int idx) {     int ret = 0;     while (idx > 0) {       ret = max(BIT[idx], ret);       idx -= idx & -idx;     }     return ret;   }   int main() {     scanf( %d , &n);     int ans = 0;     for (int i = 0, x; i < n; ++i) {       scanf( %d , &x);       update(x, get(x) + 1);     }     printf( %d n , get(n));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int iinf = 1e9 + 7;   const long long linf = 1ll << 60;   const double dinf = 1e60;   template <typename T>   inline void scf(T &x) {     bool f = 0;     x = 0;     char c = getchar();     while ((c <  0  || c >  9 ) && c !=  - ) c = getchar();     if (c ==  - ) {       f = 1;       c = getchar();     }     while (c >=  0  && c <=  9 ) {       x = x * 10 + c -  0 ;       c = getchar();     }     if (f) x = -x;     return;   }   template <typename T1, typename T2>   void scf(T1 &x, T2 &y) {     scf(x);     return scf(y);   }   template <typename T1, typename T2, typename T3>   void scf(T1 &x, T2 &y, T3 &z) {     scf(x);     scf(y);     return scf(z);   }   template <typename T1, typename T2, typename T3, typename T4>   void scf(T1 &x, T2 &y, T3 &z, T4 &w) {     scf(x);     scf(y);     scf(z);     return scf(w);   }   inline char mygetchar() {     char c = getchar();     while (c ==     || c ==   n ) c = getchar();     return c;   }   template <typename T>   void chkmax(T &x, const T &y) {     if (y > x) x = y;     return;   }   template <typename T>   void chkmin(T &x, const T &y) {     if (y < x) x = y;     return;   }   const int N = 510;   const int M = 110;   int n, m, k;   double A[N][N + N];   double w[M][M], p[N][N];   bool f[N];   vector<int> trap;   double beg[N];   void calc_w() {     for (int i = (1); i <= (n); ++i) {       A[i][i] = 1.0;       if (!f[i])         for (int j = (1); j <= (n); ++j)           if (i != j) A[i][j] = -p[i][j];       A[i][i + n] = 1.0;     }     for (int row = 1, col = 1; row <= n; ++row) {       int pivot = row;       for (int i = (row + 1); i <= (n); ++i)         if (fabs(A[i][col]) > fabs(A[pivot][col])) pivot = i;       if (fabs(A[pivot][col]) <= 1e-6) continue;       swap(A[pivot], A[row]);       double foo = A[row][col];       for (int i = (1); i <= (n + n); ++i) A[row][i] /= foo;       for (int i = (1); i <= (n); ++i)         if (i != row) {           foo = A[i][col];           for (int j = (1); j <= (n + n); ++j) A[i][j] -= foo * A[row][j];         }       ++col;     }     for (int i = 0; i < (m); ++i)       for (int j = 0; j < (m); ++j) {         int u = trap[i], v = trap[j];         for (int k = (1); k <= (n); ++k) w[i][j] += p[u][k] * A[k][v + n];       }     for (int i = 0; i < (m); ++i) beg[i] = A[1][trap[i] + n];     return;   }   void TZL() {     static int g[N][N], deg[N];     memset((g), (0), sizeof((g)));     memset((deg), (0), sizeof((deg)));     scf(n, m, k);     for (int i = (1); i <= (n); ++i) {       scf(f[i]);       if (f[i]) trap.push_back(i);     }     for (int i = 0; i < (m); ++i) {       int u, v;       scf(u, v);       g[u][v]++;       g[v][u]++;       deg[u]++;       deg[v]++;     }     m = (int)trap.size();     for (int i = (1); i <= (n); ++i)       for (int j = (1); j <= (n); ++j) p[i][j] = (1.0 * g[i][j]) / (1.0 * deg[i]);     return calc_w();   }   struct mat {     double num[M][M];     mat() { memset((num), (0), sizeof((num))); }     mat(int x) {       memset((num), (0), sizeof((num)));       for (int i = 0; i < (M); ++i) num[i][i] = x;     }     mat(double a[][M]) {       for (int i = 0; i < (M); ++i)         for (int j = 0; j < (M); ++j) num[i][j] = a[i][j];     }     double &operator()(int i, int j) { return num[i][j]; }     double operator()(int i, int j) const { return num[i][j]; }     friend mat operator*(const mat &a, const mat &b) {       mat c;       for (int i = 0; i < (M); ++i)         for (int j = 0; j < (M); ++j)           for (int k = 0; k < (M); ++k) c(i, j) += a(i, k) * b(k, j);       return c;     }   } g;   mat kiss_me(mat a, int n) {     mat ret = mat(1);     while (n) {       if (n & 1) ret = ret * a;       a = a * a;       n >>= 1;     }     return ret;   }   void RANK1() {     g = mat(w);     g = kiss_me(g, k - 2);     double ans = 0.0;     for (int i = 0; i < (m); ++i) ans += beg[i] * g(i, m - 1);     printf( %.12f n , ans);     return;   }   int main() {     TZL();     RANK1();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   long long dis[100010];   vector<int> mom[100010];   vector<pair<int, int> > vertex[100010];   set<int> q;   void readin() {     scanf( %d%d , &n, &m);     int u, v, c;     for (int i = 0; i < m; ++i) {       scanf( %d%d%d , &u, &v, &c);       vertex[u].push_back(make_pair(v, c));       vertex[v].push_back(make_pair(u, c));     }     int cnt;     for (int i = 1; i <= n; ++i) {       scanf( %d , &cnt);       while (cnt--) {         scanf( %d , &v);         mom[i].push_back(v);       }     }   }   void spfa() {     int u, v, c, nt, sz;     vector<int>::iterator low;     memset(dis, -1, sizeof(dis));     while (!q.empty()) q.clear();     q.insert(1);     dis[1] = 0;     while (!q.empty()) {       u = *q.begin();       q.erase(u);       if (u == n) continue;       nt = dis[u];       low = lower_bound(mom[u].begin(), mom[u].end(), nt);       for (; low != mom[u].end(); low++) {         if (*low == nt)           nt++;         else if (*low > nt)           break;       }       sz = vertex[u].size();       for (int i = 0; i < sz; ++i) {         v = vertex[u][i].first;         c = vertex[u][i].second;         if (dis[v] == -1 || dis[v] > nt + c) {           dis[v] = nt + c;           q.insert(v);         }       }     }   }   int main() {     readin();     spfa();     printf( %I64d , dis[n]);   }


#include <bits/stdc++.h>   using namespace std;   static const int INF = 500000000;   template <class T>   void debug(T a, T b) {     for (; a != b; ++a) cerr << *a <<    ;     cerr << endl;   }   int n;   pair<pair<int, int>, int> es[5005];   vector<pair<int, int> > g[5005];   int size[5005];   int cut[5005];   int prep(int v, int p) {     size[v] = 1;     for (int i = 0; i < g[v].size(); ++i) {       int to = g[v][i].first;       if (to == p || cut[to]) continue;       size[v] += prep(to, v);     }     return size[v];   }   int type;   int cost[2], root[2], all[2];   void dfs(int v, int p) {     int maxi = 0;     for (int i = 0; i < g[v].size(); ++i) {       int to = g[v][i].first;       if (to == p || cut[to]) continue;       maxi = max(maxi, size[to]);       dfs(to, v);     }     if (max(maxi, all[type] - size[v]) < cost[type]) {       cost[type] = max(maxi, all[type] - size[v]);       root[type] = v;     }   }   long long int tot;   int dfs2(int v, int p) {     size[v] = 1;     for (int i = 0; i < g[v].size(); ++i) {       int to = g[v][i].first;       if (to == p || cut[to]) continue;       size[v] += dfs2(to, v);       tot += size[to] * (all[type] - size[to]) * (long long int)g[v][i].second;       tot += size[to] * (long long int)all[type ^ 1] * g[v][i].second;     }     return size[v];   }   int main() {     scanf( %d , &n);     for (int i = 0; i < n - 1; ++i) {       int a, b, c;       scanf( %d%d%d , &a, &b, &c);       --a;       --b;       g[a].push_back(make_pair(b, c));       g[b].push_back(make_pair(a, c));       es[i] = make_pair(make_pair(a, b), c);     }     long long int ans = 1e18;     for (int i = 0; i < n - 1; ++i) {       int a = es[i].first.first, b = es[i].first.second;       tot = 0;       cost[0] = cost[1] = INF;       type = 0;       cut[b] = 1;       all[0] = prep(a, b);       all[1] = n - all[0];       dfs(a, b);       dfs2(root[0], -1);       type = 1;       cut[b] = 0;       cut[a] = 1;       all[1] = prep(b, a);       dfs(b, a);       dfs2(root[1], -1);       cut[a] = 0;       tot += all[0] * all[1] * (long long int)es[i].second;       ans = min(ans, tot);     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int t;     cin >> t;     while (t--) {       vector<pair<int, int>> st, re;       int a, b;       int n;       cin >> n;       for (int i = 0; i < n; i++) {         cin >> a >> b;         st.emplace_back(a, b);         re.emplace_back(b, a);       }       sort(st.begin(), st.end());       sort(re.begin(), re.end());       cout << max(st[n - 1].first - re[0].first, 0) <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-8;   const double pi = acos(-1.0);   struct Q {     int a, b, c;     Q(int a, int b, int c) : a(a), b(b), c(c) {}     bool operator<(const Q& o) const {       if (a == o.a) return c < o.c;       return a < o.a;     }   };   vector<pair<int, int> > ans;   set<Q> q;   int in[100000];   int main() {     int n, i, a, b;     scanf( %d , &n);     for (i = 0; i < n; ++i) {       scanf( %d%d , &a, &b);       in[i] = a;       if (a) q.insert(Q(a, b, i));     }     while (!q.empty()) {       Q u = *(q.begin());       q.erase(q.begin());       int cur = u.c;       ans.push_back(make_pair(u.b, u.c));       in[u.b]--;       in[u.c]--;       u = *q.lower_bound(Q(in[u.b] + 1, 0, u.b));       q.erase(u);       u.a--;       u.b ^= cur;       if (u.a) q.insert(u);     }     printf( %d n , ans.size());     for (i = 0; i < ans.size(); ++i)       printf( %d %d n , ans[i].first, ans[i].second);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int pos[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};   int n;   char s[510][510];   int v[510][510];   vector<pair<int, int> > vec, ans;   int operator*(const pair<int, int> &a, const pair<int, int> &b) {     return a.first * b.second - a.second * b.first;   }   pair<int, int> operator-(const pair<int, int> &a, const pair<int, int> &b) {     return make_pair(a.first - b.first, a.second - b.second);   }   pair<int, int> stk[250010];   int main() {     while (1) {       ans.clear();       scanf( %d , &n);       if (n == 0) break;       for (int i = n; i >= 1; i--) scanf( %s , s[i] + 1);       for (int i = 1; i <= n; i++)         for (int j = 1; j <= n; j++) v[i][j] = s[i][j] -  0 ;       vec.clear();       for (int i = 1; i <= n; i++) {         for (int j = 1; j <= n; j++) {           int cnt = 0;           for (int k = -1; k <= 0; k++) {             for (int l = -1; l <= 0; l++) {               cnt += v[i + k][j + l];             }           }           if (cnt == 1) {             if (v[i][j] == 1)               vec.push_back(make_pair(i, j));             else if (v[i - 1][j] == 1)               vec.push_back(make_pair(i - 2, j));             else if (v[i][j - 1] == 1)               vec.push_back(make_pair(i, j - 2));             else               vec.push_back(make_pair(i - 2, j - 2));           }         }       }       for (auto &x : vec) swap(x.first, x.second);       sort(vec.begin(), vec.end());       int top = 0;       for (auto &x : vec) {         while (top > 1 && (stk[top] - stk[top - 1]) * (x - stk[top]) >= 0) top--;         stk[++top] = x;       }       for (int i = 1; i <= top; i++) ans.push_back(stk[i]);       reverse(vec.begin(), vec.end());       top = 0;       for (auto &x : vec) {         while (top > 1 && (stk[top] - stk[top - 1]) * (x - stk[top]) >= 0) top--;         stk[++top] = x;       }       for (int i = 2; i < top; i++) ans.push_back(stk[i]);       printf( %d n , ans.size());       for (auto &x : ans) printf( %d %d n , x.first, x.second);     }     return 0;   }


#include <bits/stdc++.h>   #pragma GCC target( avx2 )   #pragma GCC optimization( O3 )   #pragma GCC optimization( unroll-loops )   using namespace std;   const int mod = 1e9 + 7;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int t;     cin >> t;     while (t--) {       long long n, m, a, b, i, j;       cin >> n;       deque<long long> dq, tmp;       long long ar[n], ans[n];       set<long long> s;       for (i = 0; i < n; i++) {         cin >> a;         ar[a - 1] = i;         ans[i] = 0;       }       a = n, b = 0;       for (i = 0; i < n; i++) {         a = min(a, ar[i]);         b = max(b, ar[i]);         if (b - a == i) ans[i] = 1;       }       for (i = 0; i < n; i++) cout << ans[i];       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long n, p, b = 0;     cin >> n >> p;     vector<long long> v;     for (int i = 0; i < n; ++i) {       string s;       cin >> s;       if (s ==  half ) {         v.push_back(0);       } else         v.push_back(1), b++;     }     reverse(v.begin(), v.end());     long long at = 0;     for (int i = 0; i < n; ++i) {       at *= 2;       at += v[i];     }     cout << (at * p) - (b * p / 2) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 1005;   vector<int> v[MAX];   int dp[105][MAX];   int main() {     ios::sync_with_stdio(false);     int n, t;     cin >> n >> t;     for (int i = 0; i < n; i++) {       int t, p;       cin >> t >> p;       v[t].push_back(p);     }     for (int i = 0; i < MAX; i++) {       sort(v[i].begin(), v[i].end());       v[i].push_back(0);       reverse(v[i].begin(), v[i].end());       for (int j = 1; j < v[i].size(); j++) v[i][j] += v[i][j - 1];     }     for (int i = 1; i <= t; i++)       for (int j = 1; j < MAX; j++)         for (int k = 0; k < min((int)v[i].size(), j + 1); k++)           dp[i][j] =               max(dp[i][j], dp[i - 1][min(MAX - 1, (j - k) * 2)] + v[i][k]);     cout << dp[t][1] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long M = 7e2 + 5;   const long long mod = 1e9 + 7;   char sz[M];   long long a[M], js;   inline long long read() {     register long long x = 0, y = 1;     register char c = getchar();     while (!isdigit(c)) {       if (c ==  - ) y = 0;       c = getchar();     }     while (isdigit(c)) {       x = x * 10 + (c ^ 48);       c = getchar();     }     return y ? x : -x;   }   long long f[M][M][10];   long long dfs(long long pos, long long limit, long long sum, long long l) {     if (!pos) return !sum % mod;     if (!limit && ~f[pos][sum][l]) return f[pos][sum][l] % mod;     long long up = limit ? a[pos] : 9;     long long cnt = 0;     for (long long i = 0; i <= up; i++)       cnt = (cnt + dfs(pos - 1, limit && i == up, sum - (i >= l), l)) % mod;     if (!limit) f[pos][sum][l] = cnt;     return cnt % mod;   }   signed main() {     scanf( %s , sz + 1);     memset(f, -1, sizeof(f));     long long len = strlen(sz + 1);     for (long long i = 1; i <= len; i++) a[i] = sz[len - i + 1] -  0 ;     a[0] = 0;     for (long long i = 1; i <= 9; i++)       for (long long j = 1, puz = 1; j <= len;            j++, puz = (10ll * puz + 1ll) % mod)         js = (js + dfs(len, 1, j, i) * puz % mod) % mod;     printf( %lld n , js);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     int A[n][m], B[n][m], C[n][m];     vector<int> a, b;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         cin >> A[i][j];         a.push_back(A[i][j]);       }     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         cin >> B[i][j];         b.push_back(B[i][j]);       }     }     sort(a.begin(), a.end());     sort(b.begin(), b.end());     for (int i = 0; i < a.size(); i++) {       if (a[i] != b[i]) {         cout <<  NO  << endl;         return 0;       }     }     if (n >= m) {       for (int i = 0; i < n; i++) {         long long x = 0;         for (int j = 0; j < min(i + 1, m); j++) {           x ^= (long long)(A[i - j][j] ^ B[i - j][j]);         }         if (x) {           cout <<  NO  << endl;           return 0;         }       }       for (int i = 0; i < m - 1; i++) {         long long x = 0;         for (int j = 1; j + i < m; j++) {           x ^= (long long)(A[n - j][j + i] ^ B[n - j][j + i]);         }         if (x) {           cout <<  NO  << endl;           return 0;         }       }     } else {       for (int i = 0; i < m; i++) {         long long x = 0;         for (int j = 0; j < min(i + 1, n); j++) {           x ^= (long long)(A[j][i - j] ^ B[j][i - j]);         }         if (x) {           cout <<  NO  << endl;           return 0;         }       }       for (int i = 0; i < n - 1; i++) {         long long x = 0;         for (int j = 1; j + i < n; j++) {           x ^= (long long)(A[j + i][m - j] ^ B[j + i][m - j]);         }         if (x) {           cout <<  NO  << endl;           return 0;         }       }     }     cout <<  YES  << endl;   }


#include <bits/stdc++.h>   using namespace std;   int n, q;   int x[100100], y[100100];   bool ans[100100];   int par[100100], sz[100100];   int distToPar[100100];   int getpar(int now) { return (par[now] == now) ? now : getpar(par[now]); }   bool getdist(int now) {     bool ret = (par[now] == now) ? 0 : (getdist(par[now]) ^ distToPar[now]);     return ret;   }   stack<pair<pair<int, int>, bool> > prevStat;   map<pair<int, int>, int> mp;   vector<pair<pair<int, int>, pair<int, int> > > opSeg;   vector<pair<int, int> > add[400400];   void addSeg(int tl, int tr, pair<int, int> val, int l, int r, int k) {     if (tl > r || l > tr) return;     if (tl <= l && r <= tr) {       add[k].push_back(val);       return;     }     int mid = (l + r) >> 1;     addSeg(tl, tr, val, l, mid, k + k);     addSeg(tl, tr, val, mid + 1, r, k + k + 1);   }   bool isBipar = 1;   void addEdge(pair<int, int> now) {     int u = now.first, v = now.second;     int pu = getpar(u), pv = getpar(v);     if (pu == pv) {       prevStat.push(make_pair(make_pair(-1, -1), isBipar));       if ((getdist(u) ^ getdist(v)) == 0) {         isBipar = 0;       }       return;     }     if (sz[pu] > sz[pv]) swap(u, v), swap(pu, pv);     prevStat.push(make_pair(make_pair(pu, sz[pu]), isBipar));     distToPar[pu] = getdist(u) ^ getdist(v) ^ 1;     par[pu] = pv;     sz[pv] += sz[pu];   }   void undo() {     int pos = prevStat.top().first.first, presz = prevStat.top().first.second,         preIsBipar = prevStat.top().second;     prevStat.pop();     if (pos >= 0) {       sz[pos] = presz;       sz[par[pos]] -= sz[pos];       par[pos] = pos;     }     isBipar = preIsBipar;   }   void solve(int l, int r, int k) {     for (int i = 0; i < (int)add[k].size(); i++) {       addEdge(add[k][i]);     }     if (l == r) {       ans[l] = isBipar;     } else {       int mid = (l + r) >> 1;       solve(l, mid, k + k);       solve(mid + 1, r, k + k + 1);     }     for (int i = 0; i < (int)add[k].size(); i++) undo();   }   int main() {     ios::sync_with_stdio(false);     cin >> n >> q;     for (int i = 0; i < q; i++) {       cin >> x[i] >> y[i];       x[i]--, y[i]--;       if (x[i] > y[i]) swap(x[i], y[i]);     }     for (int i = 0; i < n; i++) par[i] = i, sz[i] = 1;     for (int i = 0; i < q; i++) {       pair<int, int> now = make_pair(x[i], y[i]);       if (!mp.count(now) || mp[now] < 0) {         mp[now] = i;       } else {         opSeg.push_back(make_pair(make_pair(mp[now], i), now));         mp[now] = -1;       }     }     for (map<pair<int, int>, int>::iterator it = mp.begin(); it != mp.end();          it++) {       if (it->second >= 0) {         opSeg.push_back(make_pair(make_pair(it->second, q), it->first));       }     }     for (int i = 0; i < (int)opSeg.size(); i++) {       addSeg(opSeg[i].first.first, opSeg[i].first.second - 1, opSeg[i].second, 0,              q - 1, 1);     }     solve(0, q - 1, 1);     for (int i = 0; i < q; i++) cout << (ans[i] ?  YES  :  NO ) << endl;     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   stringstream ans;   int final_sum;   string print_line(string a0) {     int S = 0;     for (int i = 0; i < a0.size() - 1; i++) {       int digit = a0[i] -  0 ;       S += digit;       ans << digit <<  + ;     }     int digit = a0[a0.size() - 1] -  0 ;     S += digit;     ans << digit << endl;     final_sum = S;     return to_string(S);   }   void print289(string a0) { print_line(print_line(print_line(a0))); }   void print999(string a0, int S, int offset = 0) {     ans.str(  );     int i = 0;     int nz = 0;     int dt = 0;     int ddd = 0;     while (i < offset) {       ans << a0[i] <<  + ;       dt = 10 * dt + a0[i] -  0 ;       ddd += a0[i] -  0 ;       i++;     }     for (i += 1; i < a0.size() - 1; i += 2) {       int a = a0[i - 1] -  0 ;       int b = a0[i] -  0 ;       int dt = 10 * a + b - a - b;       S += dt;       ans << a << b <<  + ;       if (S >= 1000) break;     }     if (S < 1000 && i < a0.size()) {       int a = a0[i - 1] -  0 ;       int b = a0[i] -  0 ;       int dt = 10 * a + b - a - b;       S += dt;       ans << a << b;     }     i++;     for (i; i < a0.size() - 1; i++) ans << a0[i] <<  + ;     for (i; i < a0.size(); i++) ans << a0[a0.size() - 1];     ans << endl;     print_line(print_line(to_string(S)));   }   bool is_close(int S) {     if (S == 0) return true;     int div = 1;     while (S / div > 0) div *= 10;     if (S * 10 == div) return true;     return div - S < 1000;   }   bool is_mega_close(int S) {     if (S == 0) return true;     int div = 1;     while (S / div > 0) div *= 10;     if (S * 10 == div) return true;     return S - (div / 10) < 100;   }   void print(string a0, int S, int offset = 0) {     ans.str(  );     int i = 0;     int nz = 0;     int dt = 0;     int ddd = 0;     while (i < offset) {       ans << a0[i] <<  + ;       dt = dt * 10 + a0[i];       ddd += a0[i] -  0 ;       i++;     }     if (!is_close(S)) {       for (i += 2; i < a0.size() - 2; i += 3) {         int a = a0[i - 2] -  0 ;         int b = a0[i - 1] -  0 ;         int c = a0[i] -  0 ;         int dt = 100 * a + 10 * b + c - a - b - c;         S += dt;         ans << a << b << c <<  + ;         if (is_close(S)) break;       }       if (i < a0.size() - 2) i++;     }     if (!is_mega_close(S))       for (i += 2; i < a0.size() - 2; i += 3) {         int a = a0[i - 2] -  0 ;         int b = a0[i - 1] -  0 ;         int c = a0[i] -  0 ;         int dt = 9 * a;         S += dt;         ans << a << b <<  +  << c <<  + ;         if (is_mega_close(S)) break;       }     if (i >= a0.size() - 2)       i -= 2;     else       i++;     for (i; i < a0.size() - 1; i++) ans << a0[i] <<  + ;     for (i; i < a0.size(); i++) ans << a0[a0.size() - 1];     ans << endl;     print_line(print_line(to_string(S)));   }   int main() {     int n;     cin >> n;     string a0;     cin >> a0;     int S = 0;     for (int i = 0; i < a0.size(); i++) {       int digit = a0[i] -  0 ;       S += digit;     }     if (S < 199) {       print289(a0);       cout << ans.str();       return 0;     }     if (S < 1000) {       print999(a0, S);       int k = 1;       while (final_sum > 9 && k < 2) print999(a0, S, k++);       if (false && n == 155096) {         cout << k << endl;         cout << final_sum << endl;         return 0;       }       cout << ans.str();       return 0;     }     print(a0, S);     int k = 1;     while (final_sum > 9 && k < 3) print(a0, S, k++);     cout << ans.str();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline T read() {     T s = 0, f = 1;     char ch = getchar();     while (!isdigit(ch)) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (isdigit(ch)) {       s = (s << 3) + (s << 1) + ch - 48;       ch = getchar();     }     return s * f;   }   template <typename T>   inline void print(T x) {     if (x < 0) putchar( - ), x = -x;     if (x > 9) print(x / 10);     putchar(x % 10 +  0 );   }   const int N = 2e5 + 100;   const int mod = 1e9 + 7;   long long h[N], w[N], sum[N];   struct Segment {     static const int maxn = 2e5 + 100;     struct star {       long long lsum, rsum, sum;     } s[maxn << 2];     void pushup(int node, int l, int r) {       int mid = l + r >> 1;       s[node].lsum =           max(s[node << 1].lsum, h[l] + sum[mid - 1] - sum[l - 1] +                                      s[node << 1 | 1].lsum - h[mid + 1] + w[mid]);       s[node].lsum = max(s[node].lsum, h[l] + h[mid + 1] + sum[mid] - sum[l - 1]);       s[node].rsum =           max(s[node << 1 | 1].rsum,               h[r] + sum[r - 1] - sum[mid] + s[node << 1].rsum - h[mid] + w[mid]);       s[node].rsum = max(s[node].rsum, h[r] + h[mid] + sum[r - 1] - sum[mid - 1]);       s[node].sum = max(s[node << 1].rsum + s[node << 1 | 1].lsum - h[mid] -                             h[mid + 1] + w[mid],                         max(s[node << 1].sum, s[node << 1 | 1].sum));       s[node].sum = max(s[node].sum, max(s[node].lsum, s[node].rsum));       s[node].sum = max(s[node].sum, h[r] + h[l] + sum[r - 1] - sum[l - 1]);       s[node].sum = max(           s[node].sum, max(s[node << 1].rsum - h[mid] + h[mid + 1] + w[mid],                            s[node << 1 | 1].lsum - h[mid + 1] + h[mid] + w[mid]));       s[node].sum = max(s[node].sum, h[mid] + h[mid + 1] + w[mid]);     }     void build(int node, int l, int r) {       if (l == r) {         s[node].lsum = s[node].rsum = h[l];         s[node].sum = 0;         return;       }       int mid = l + r >> 1;       build(node << 1, l, mid);       build(node << 1 | 1, mid + 1, r);       pushup(node, l, r);     }     star query(int node, int l, int r, int L, int R) {       if (L == l && R == r) {         return s[node];       }       int mid = l + r >> 1;       if (R <= mid)         return query(node << 1, l, mid, L, R);       else if (L > mid)         return query(node << 1 | 1, mid + 1, r, L, R);       else {         star lnode = query(node << 1, l, mid, L, mid);         star rnode = query(node << 1 | 1, mid + 1, r, mid + 1, R);         star now;         now.lsum = max(lnode.lsum, h[L] + sum[mid - 1] - sum[L - 1] + rnode.lsum -                                        h[mid + 1] + w[mid]);         now.lsum = max(now.lsum, h[L] + h[mid + 1] + sum[mid] - sum[L - 1]);         now.rsum = max(rnode.rsum, h[R] + sum[R - 1] - sum[mid] + lnode.rsum -                                        h[mid] + w[mid]);         now.rsum = max(now.rsum, h[R] + h[mid] + sum[R - 1] - sum[mid - 1]);         now.sum = max(lnode.rsum + rnode.lsum - h[mid] - h[mid + 1] + w[mid],                       max(lnode.sum, rnode.sum));         now.sum = max(now.sum, max(now.lsum, now.rsum));         now.sum = max(now.sum, h[L] + h[R] + sum[R - 1] - sum[L - 1]);         now.sum = max(now.sum, max(lnode.rsum - h[mid] + h[mid + 1] + w[mid],                                    rnode.lsum - h[mid + 1] + h[mid] + w[mid]));         now.sum = max(now.sum, h[mid] + h[mid + 1] + w[mid]);         return now;       }     }   } tree;   int main() {     int n = read<int>(), m = read<int>();     for (int i = 1; i <= n; ++i) {       w[i] = read<long long>();       w[i + n] = w[i];       sum[i] = sum[i - 1] + w[i];     }     for (int i = 1; i <= n; ++i) {       h[i] = read<long long>();       h[i] = h[i] + h[i];       h[i + n] = h[i];     }     for (int i = n + 1; i <= n + n; ++i) {       sum[i] = sum[i - 1] + w[i];     }     tree.build(1, 1, n + n);     for (int i = 1; i <= m; ++i) {       int l = read<int>(), r = read<int>();       int lc, rc;       if (r >= l)         lc = r + 1, rc = l + n - 1;       else         lc = r + 1, rc = l - 1;       printf( %lld n , tree.query(1, 1, n + n, lc, rc).sum);     }   }


#include <bits/stdc++.h>   using namespace std;   int n, m, a[1001000], cnt[1001000], z[1001000];   int main() {     ios::sync_with_stdio(false);     memset(cnt, 0, sizeof(cnt));     memset(z, 0, sizeof(z));     cin >> n >> m;     for (int i = 1; i <= n; i++) {       cin >> a[i];       if (a[i] <= m) cnt[a[i]]++;     }     int ans = 0, flag = 0;     for (int i = 1; i <= m; i++) {       if (cnt[i]) {         for (int k = 1; k * i <= m; k++) z[k * i] += cnt[i];       }     }     for (int i = 1; i <= m; i++) {       if (z[i] > ans) {         ans = z[i];         flag = i;       }     }     cout << (flag == 0 ? 1 : flag) <<     << ans << endl;     for (int i = 1; i <= n; i++) {       if (flag % a[i] == 0 && flag != 0) cout << i <<    ;     }     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   signed long long int n, m, k, x, y;   signed long long int ct[3], myct;   int main() {     cin >> n >> m >> k >> x >> y;     signed long long int f1, q, val, rem = k;     if (n == 1) {       f1 = m;       q = rem / f1;       rem -= q * f1;       myct = q;       ct[1] = q;       ct[2] = q;       if (y <= rem) myct++;       if (rem != 0) ct[1]++;       cout << ct[1] <<     << ct[2] <<     << myct <<   n ;       return 0;     } else if (n == 2) {       f1 = 2 * m;       q = rem / f1;       rem -= q * f1;       myct = q;       ct[1] = ct[2] = q;       if (((x - 1) * m + y) <= rem) myct++;       if (rem != 0) ct[1]++;       cout << ct[1] <<     << ct[2] <<     << myct <<   n ;       return 0;     }     f1 = ((n - 2) * m * 2) + (2 * m);     q = rem / f1;     rem -= q * f1;     ct[0] = 2 * q;     ct[1] = q;     ct[2] = q;     int grp = -1;     if (x == 1) {       myct = q;       grp = 1;     } else if (x == n) {       myct = q;       grp = 2;     } else {       myct = 2 * q;       grp = 0;     }     int stp = 0;     if (rem > 0 && rem <= m) {       ct[1]++;       if (((x - 1) * m + y) <= rem) myct++;     } else if (rem > m && rem <= (n - 1) * m) {       ct[0]++;       ct[1]++;       if (((x - 1) * m + y) <= rem) myct++;     } else if (rem > (n - 1) * m && rem <= n * m) {       ct[0]++;       ct[1]++;       stp = 3;       if (rem == n * m) ct[2]++;       if (((x - 1) * m + y) <= rem) myct++;     } else if (rem > n * m && rem <= f1) {       ct[0] += 2;       ct[1]++;       ct[2]++;       myct++;       stp = 4;       if (x == 1 || x == n) {       } else {         rem -= n * m;         val = (n - x - 1) * m + y;         if (val <= rem) myct++;       }     }     signed long long int mini = ct[0], maxi = ct[0];     for (int i = 1; i < 3; i++) {       mini = min(mini, ct[i]);       maxi = max(maxi, ct[i]);     }     cout << maxi <<     << mini <<     << myct <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, mncnt = 1000000000, cnt;     string a;     string c =  ACTG ;     cin >> n >> a;     for (int i = 0; i <= n - 4; i++) {       cnt = 0;       string b = a.substr(i, 4);       for (int j = 0; j < 4; j++) {         int x = c[j] -  A ;         int y = b[j] -  A ;         if (abs(y - x) <= 13)           cnt += abs(y - x);         else           cnt += 26 - (abs(y - x));       }       mncnt = min(mncnt, cnt);     }     cout << mncnt << endl;   }


#include <bits/stdc++.h>   using namespace std;   struct data {     int x, h, p;   } a[100005];   int n, x[100005], kq[100005], st[4 * 100005];   void update(int id, int l, int r, int p, int v) {     if (l > p || r < p) return;     if (l == p && l == r) {       st[id] = v;       return;     }     int m = (l + r) >> 1;     update(id << 1, l, m, p, v);     update((id << 1) + 1, m + 1, r, p, v);     st[id] = max(st[id << 1], st[(id << 1) + 1]);   }   int getmax(int id, int l, int r, int d, int c) {     if (l > c || r < d) return 0;     if (l >= d && r <= c) return st[id];     int m = (l + r) >> 1;     return max(getmax((id << 1), l, m, d, c),                getmax((id << 1) + 1, m + 1, r, d, c));   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n;     for (int i = 1; i <= n; ++i) {       cin >> a[i].x >> a[i].h;       a[i].p = i;       a[i].h = a[i].x + a[i].h - 1;     }     sort(a + 1, a + n + 1, [](data a, data b) { return a.x < b.x; });     for (int i = n; i >= 1; --i) {       x[i] = a[i].x;       int pos = upper_bound(x + i + 1, x + n + 1, a[i].h) - x - 1;       int t = getmax(1, 1, n, i + 1, pos);       if (t < i) t = i;       kq[a[i].p] = t - i + 1;       update(1, 1, n, i, t);     }     for (int i = 1; i <= n; ++i) cout << kq[i] <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int mas[1010][1010];   int main() {     int N, K;     cin >> N >> K;     for (int i = 1; i <= N; i++) {       int k = 0;       for (int j = 1; j <= N; j++) {         if (k == K)           break;         else if (i == j)           continue;         else if (mas[j][i] || mas[i][j])           continue;         else {           mas[i][j] = 1;           k++;         }       }       if (k < K) {         cout << -1 << endl;         return 0;       }     }     int cnt = 0;     for (int i = 1; i <= N; i++) {       for (int j = 1; j <= N; j++) {         if (mas[i][j]) cnt++;       }     }     cout << cnt << endl;     for (int i = 1; i <= N; i++) {       for (int j = 1; j <= N; j++) {         if (mas[i][j]) cout << i <<     << j << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, m, k, mod = 1e9 + 7;   map<long long, long long> mp;   string s;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     srand(time(0));     cin >> n >> k;     vector<long long> a(n + 2);     vector<long long> b(k + 2);     for (long long i = 1; i <= n; ++i) cin >> a[i], a[i] -= i;     a[0] = -2e9;     a[n + 1] = 2e9;     b[k + 1] = n + 1;     for (long long i = 1; i <= k; ++i) cin >> b[i];     long long ans = 0;     for (long long i = 0; i <= k; ++i) {       long long l = b[i];       long long r = b[i + 1];       if (a[l] > a[r]) {         cout << -1;         exit(0);       }       vector<long long> v;       for (long long j = l + 1; j < r; ++j) {         if (a[j] > a[r] || a[j] < a[l]) continue;         auto x = upper_bound(v.begin(), v.end(), a[j]);         if (x == v.end())           v.push_back(a[j]);         else           *x = a[j];       }       ans += r - l - 1 - v.size();     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   int N, K, M, S;   int arr[500000];   int raito[500005];   int seen[500005];   int bucket[500005];   int shift[500005];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> M >> K >> N >> S;     for (int i = 0; i < M; i++) {       cin >> arr[i];     }     int t;     for (int i = 0; i < S; i++) {       cin >> t;       bucket[t]++;     }     for (int i = 0; i < 500005; i++) seen[i] = -1;     for (int i = M - 1; i >= 0; i--) {       raito[i] = seen[arr[i]];       seen[arr[i]] = i;     }     int maxima = 0;     for (int i = 0; i < 500005; i++) {       if (bucket[i] == 0) continue;       int cur = seen[i];       int p = 1;       while (cur != -1 && p < bucket[i]) {         cur = raito[cur];         p++;       }       if (cur == -1) {         cout << -1;         return 0;       }       shift[i] = cur;       maxima = max(maxima, cur);     }     vector<int> adj;     for (int i = 0; i < M;) {       int total = i / K + 1 + ((M - 1) - (maxima + 1) + 1) / K;       if (total >= N) {         int extra = K - S;         for (int j = i; j <= maxima; j++) {           if (extra <= 0 && bucket[arr[j]] == 0) {             adj.push_back(j + 1);           } else if (bucket[arr[j]] == 0) {             extra--;           } else {             bucket[arr[j]]--;           }         }         cout << adj.size() <<   n ;         for (int j = 0; j < adj.size(); j++) {           cout << adj[j] <<    ;         }         return 0;       }       if (i + 1 == M) break;       int pp = 0;       if (bucket[arr[i]] != 0) {         shift[arr[i]] = raito[shift[arr[i]]];         maxima = max(maxima, shift[arr[i]]);         if (shift[arr[i]] == -1) {           cout << -1;           return 0;         }       }       i++;     }     cout << -1;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 400010;   int n;   int fa[MAXN][21];   int dep[MAXN];   int LCA(int x, int y) {     if (dep[x] < dep[y]) swap(x, y);     for (int i = 20; i >= 0; i--) {       if (dep[x] - (1 << i) >= dep[y]) {         x = fa[x][i];       }     }     if (x == y) return x;     for (int i = 20; i >= 0; i--) {       if (fa[x][i] != fa[y][i]) {         x = fa[x][i];         y = fa[y][i];       }     }     return fa[x][0];   }   int main() {     scanf( %d , &n);     int L, R;     L = R = 1;     int mx = 0;     int p;     for (int i = 2; i <= n; i++) {       scanf( %d , &p);       fa[i][0] = p;       dep[i] = dep[p] + 1;       for (int j = 1; j <= 20; j++) {         fa[i][j] = fa[fa[i][j - 1]][j - 1];       }       int z = LCA(i, L);       int ans1 = dep[i] + dep[L] - 2 * dep[z];       z = LCA(i, R);       int ans2 = dep[i] + dep[R] - 2 * dep[z];       if (ans1 > ans2 && ans1 > mx) {         mx = ans1;         R = i;       }       if (ans2 >= ans1 && ans2 > mx) {         L = i;         mx = ans2;       }       if (i == n)         printf( %d n , mx);       else         printf( %d  , mx);     }   }


#include <bits/stdc++.h>   using namespace std;   #pragma GCC optimize( Ofast,no-stack-protector )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native )   #pragma GCC optimize( unroll-loops )   long long fun(long long n, long long m, long long mid) {     long long val = 0;     for (long long i = 1; i <= n; i++) val += min(m, (mid - 1) / i);     return val;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     long long tst = 1;     for (long long tt = 1; tt <= tst; tt++) {       long long n, m, k;       cin >> n >> m >> k;       long long l = 1, r = (n * m) + 1;       while (l < r) {         long long mid = (l + r) / 2;         if (fun(n, m, mid) < k)           l = mid + 1;         else           r = mid;       }       cout << l - 1 << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }   int main() {     long long a, b;     while (cin >> a >> b) {       long long suma = 0, sumb = 0;       long long ca = 0, cb = 0;       long long limit = lcm(a, b);       long long now = 0, prev = 0;       while (now <= limit) {         if (now % b != 0 || (now % a == 0 && a > b)) {           suma += now - prev;         } else {           sumb += now - prev;         }         prev = now;         now = min(a * (ca + 1), b * (cb + 1));         if (now % a == 0) ca++;         if (now % b == 0) cb++;       }       cout << (suma == sumb ?  Equal  : suma > sumb ?  Dasha  :  Masha ) << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, k, dp[2000 + 10][2000 + 10];   bool v[2000 + 10][2000 + 10];   vector<int> vec[2000 + 10];   int solve(int curr, int kk) {     if (kk > k) return 0;     if (kk == k) return 1;     if (v[curr][kk]) return dp[curr][kk];     for (int i = 0; i < vec[curr].size(); i++) {       dp[curr][kk] += (solve(vec[curr][i], kk + 1)) % 1000000007;       dp[curr][kk] %= 1000000007;     }     v[curr][kk] = true;     return dp[curr][kk];   }   int main() {     ios::sync_with_stdio(false), cin.tie(0);     cin >> n >> k;     for (int i = 1; i <= n; i++) {       for (int j = i; j <= n; j += i) {         if (!(j % i)) vec[i].push_back(j);       }     }     cout << solve(1, 0) <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[100005];   int dp[302][100005];   int main() {     ios::sync_with_stdio(0);     int n, q;     cin >> n;     for (int i = 1; i <= n; ++i) cin >> a[i];     cin >> q;     memset(dp, 0, sizeof(dp));     for (int k = min(300, n); k >= 1; --k) {       for (int i = n; i >= 1; --i) {         if (i + a[i] + k > n)           dp[k][i] = 1;         else           dp[k][i] = 1 + dp[k][i + a[i] + k];       }     }     while (q--) {       int p, k;       cin >> p >> k;       if (k <= 300)         cout << dp[k][p] << endl;       else {         int ans = 0;         while (p <= n) {           p = p + a[p] + k;           ans++;         }         cout << ans << endl;       }     }   }


#include <bits/stdc++.h>   using namespace std;   long long n, ans = 0, minm;   long long A[10 * 100000 + 6];   unordered_map<long long, long long> M;   long long pos, neg, cc = 0, k = 0;   int main() {     scanf( %lld , &n);     for (int i = 1; i <= n; ++i) {       scanf( %lld , &A[i]);       M[A[i] - i]++;       ans += abs(A[i] - i);       if (A[i] <= i)         neg++;       else         pos++;     }     minm = ans;     for (long long i = 1, j = n; i <= n - 1; ++i, --j) {       if (A[j] - j - cc <= 0)         --neg;       else         --pos;       ans -= abs(A[j] - j - cc);       ans += A[j];       ++pos;       M[A[j] + cc]++;       M[A[j] - j]--;       ++cc;       ans -= pos;       ans += neg;       pos -= M[cc];       neg += M[cc];       if (ans <= minm) {         minm = ans;         k = i;       }     }     printf( %lld %lld n , minm, k);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main(int argc, const char* argv[]) {     int cases;     cin >> cases;     while (cases--) {       int num;       scanf( %d , &num);       vector<pair<int, int> > coords;       pair<int, int> z(0, 0);       coords.push_back(z);       for (int i = 0; i < num; ++i) {         int x, y;         scanf( %d%d , &x, &y);         coords.push_back({x, y});       }       sort(coords.begin(), coords.end());       string out;       bool ok = true;       for (int i = 1; i <= num; ++i) {         int diffx = coords[i].first - coords[i - 1].first;         int diffy = coords[i].second - coords[i - 1].second;         if (diffx < 0 || diffy < 0) {           ok = false;           break;         }         while (diffx--) out +=  R ;         while (diffy--) out +=  U ;       }       if (ok) {         cout <<  YES  << endl;         cout << out << endl;       } else {         cout <<  NO  << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int M = 110;   int a[M];   int main() {     int n, cnt = 0;     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , a + i);       if (a[i] % 2 == 0) cnt++;     }     if (n % 2 == 0) {       printf( No n );       return 0;     }     if (a[1] % 2 == 0 || a[n] % 2 == 0) {       printf( No n );       return 0;     } else {       printf( Yes n );       return 0;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   T mulmod(T a, T b) {     if (b == 0) return 0;     if (b == 1) return a;     T x = mulmod(a, b >> 1);     x = (x + x) % 1000000007;     if (b & 1) x = (x + a) % 1000000007;     return x;   }   template <class T>   T larger(T a, T b) {     return (a > b ? a : b);   }   template <class T>   T smaller(T a, T b) {     return (a < b ? a : b);   }   template <class T>   T gcd(T a, T b) {     if (b == 0) return a;     return gcd(b, a % b);   }   template <class T>   T lcm(T a, T b) {     return (a * b) / gcd(a, b);   }   template <class T>   string converter(T n) {     stringstream x;     x << n;     return x.str();   }   template <class T>   T pw(T a, T b) {     if (b == 0) return 1;     T x = pw(a, b >> 1);     x = mulmod(x, x);     if (b & 1) x = mulmod(x, a);     return x;   }   template <class T1>   void deb(T1 e1) {     cout << e1 << endl;   }   template <class T1, class T2>   void deb(T1 e1, T2 e2) {     cout << e1 <<     << e2 << endl;   }   template <class T1, class T2, class T3>   void deb(T1 e1, T2 e2, T3 e3) {     cout << e1 <<     << e2 <<     << e3 << endl;   }   template <class T1, class T2, class T3, class T4>   void deb(T1 e1, T2 e2, T3 e3, T4 e4) {     cout << e1 <<     << e2 <<     << e3 <<     << e4 << endl;   }   template <class T1, class T2, class T3, class T4, class T5>   void deb(T1 e1, T2 e2, T3 e3, T4 e4, T5 e5) {     cout << e1 <<     << e2 <<     << e3 <<     << e4 <<     << e5 << endl;   }   template <class T1, class T2, class T3, class T4, class T5, class T6>   void deb(T1 e1, T2 e2, T3 e3, T4 e4, T5 e5, T6 e6) {     cout << e1 <<     << e2 <<     << e3 <<     << e4 <<     << e5 <<     << e6          << endl;   }   void letsgo() {     long long int a, b, x, n;     cin >> a >> b >> n >> x;     if (a == 1) {       cout << (x + (n % 1000000007 * b) % 1000000007) % 1000000007;       return;     }     long long int aN = pw(a, n);     long long int ans = (aN * x) % 1000000007;     long long int z = ((aN - 1 + 1000000007) % 1000000007 * b) % 1000000007;     z = (z * pw(a - 1, 1000000007 - 2ll)) % 1000000007;     cout << (ans + z) % 1000000007;   }   int main() {     letsgo();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 0x3f3f3f3f;   const double eps = 1e-8;   const double PI = acos(-1.0);   const int maxn = 200 + 10;   char str[maxn];   struct TwoSat {     int n;     vector<int> G[maxn * 2];     bool mark[maxn * 2];     int S[maxn * 2], c;     bool isv[maxn];     int sz;     bool dfs(int x) {       if (mark[x ^ 1]) return false;       if (mark[x]) return true;       if (x / 2 < xi) {         int id = str[x / 2] -  a ;         if (isv[id] != (x & 1)) return false;         tmp[x / 2] = str[x / 2];       } else if (x / 2 == xi) {         int t = get_min(str[xi] -  a , (x & 1) ? true : false);         if (t == -1) return false;         tmp[x / 2] = t +  a ;       } else {         int t = get_min(-1, (x & 1) ? true : false);         if (t == -1) return false;         tmp[x / 2] = t +  a ;       }       mark[x] = true;       S[c++] = x;       for (int i = 0; i < G[x].size(); i++)         if (!dfs(G[x][i])) return false;       return true;     }     void init(int n, char *s) {       this->n = n;       for (int i = 0; i < n * 2; i++) G[i].clear();       memset(mark, false, sizeof(mark));       sz = strlen(s);       for (int i = 0; i < sz; i++) isv[i] = s[i] ==  V  ? true : false;     }     void add_clause(int x, int xval, int y, int yval) {       x = x * 2 + xval;       y = y * 2 + yval;       G[x ^ 1].push_back(y);       G[y ^ 1].push_back(x);     }     int get_min(int pos, bool c) {       for (int i = pos + 1; i < sz; i++) {         if (c == isv[i]) return i;       }       return -1;     }     char ans[maxn], tmp[maxn];     int xi;     void solve() {       bool OK = false;       for (int pos = 0; pos <= n; pos++) {         for (int x = 0; x <= 1; x++) {           xi = pos;           bool ok = false;           memset(mark, false, sizeof(mark));           strcpy(tmp, str);           if (pos < n) {             int t = get_min(str[pos] -  a , (x & 1) ? true : false);             if (t == -1) continue;             tmp[pos] = t +  a ;           }           for (int i = pos + 1; i < n; i++) tmp[i] =  a ;           c = 0;           for (int i = 0; i < n; i++) {             int x1 = (i << 1) | (isv[tmp[i] -  a ]);             if (!dfs(x1)) {               ok = true;               break;             }           }           if (n == 200) {           }           if (ok) continue;           OK = true;           tmp[n] = 0;           if (ans[0] == 0)             strcpy(ans, tmp);           else if (strcmp(tmp, ans) < 0)             strcpy(ans, tmp);         }       }       if (OK)         printf( %s n , ans);       else         printf( -1 n );     }   } sat;   int main() {     int n, m;     while (~scanf( %s , str)) {       scanf( %d%d , &n, &m);       sat.init(n, str);       for (int i = 0, x, y, xval, yval; i < m; i++) {         char t1[5], t2[5];         scanf( %d%s%d%s , &x, t1, &y, t2);         xval = t1[0] ==  V  ? 1 : 0;         yval = t2[0] ==  V  ? 1 : 0;         --x;         --y;         sat.add_clause(x, xval ^ 1, y, yval);       }       scanf( %s , str);       sat.solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int thien, n, tt, h;   string s;   int main() {     cin >> tt;     for (int ii = 1; ii <= tt; ii++) {       cin >> n;       thien = 0;       h = 0;       for (int i = 1; i <= n; i++) {         cin >> s;         if (s.length() % 2 != 0) thien++;         for (int j = 0; j < s.length(); j++)           if (s[j] ==  1 ) h++;       }       if (h % 2 != 0 && thien == 0)         cout << n - 1 << endl;       else         cout << n << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 300010;   int p1[maxn], p2[maxn], q[maxn];   int main() {     int n, m;     scanf( %d%d , &n, &m);     for (int i = 0; i < n; i++) {       scanf( %d , &p1[i]);       p1[i]--;       p2[p1[i]] = i;       q[i] = n;     }     for (int i = 0; i < m; i++) {       int x, y;       scanf( %d%d , &x, &y);       x--;       y--;       x = p2[x];       y = p2[y];       if (x > y) swap(x, y);       q[x] = min(q[x], y);     }     int r = n - 1;     long long ans = 0;     for (int i = n - 1; i >= 0; i--) {       r = min(q[i] - 1, r);       ans += r - i + 1;     }     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, a[200001];   const double esl = 1e-11;   double cal(double x) {     double t = 0;     double ans = 0;     for (int i = 1; i <= n; i++) {       if (t + a[i] - x < 0) {         ans = max(ans, t);         t = 0;       } else {         t += ((double)a[i] - x);         ans = max(ans, t);       }     }     ans = max(ans, t);     double t1 = 0;     for (int i = 1; i <= n; i++) {       if (t1 + a[i] - x > 0) {         ans = max(ans, -t1);         t1 = 0;       } else {         t1 += ((double)a[i] - x);         ans = max(ans, -t1);       }     }     ans = max(ans, -t1);     return ans;   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);     }     double l = -(1e5);     double r = 1e5;     for (int i = 1; i <= 500; i++) {       double d = (2.0 * l + r) / 3;       double c = (2.0 * r + l) / 3;       if (cal(d) > cal(c)) {         l = d;       } else         r = c;     }     printf( %.10f , cal(l));     return 0;   }


#include <bits/stdc++.h>   const int N = 5e4 + 10;   int n, m;   std::vector<char> a[N];   int sx[N], sy[N];   int main() {     int T;     scanf( %d , &T);     while (T--) {       scanf( %d%d , &n, &m);       for (int i = 1; i <= n; ++i) {         a[i].resize(m + 2);         getchar();         for (int j = 1; j <= m; ++j) scanf( %c , &a[i][j]);       }       int cnt_x = 0, cnt_y = 0, p_x = 1, p_y = 1;       for (int i = 1; i <= n; ++i) {         int sum = 0;         for (int j = 1; j <= m; ++j) sum += (a[i][j] ==  * );         sx[i] = sum;       }       for (int i = 1; i <= m; ++i) {         int sum = 0;         for (int j = 1; j <= n; ++j) sum += (a[j][i] ==  * );         sy[i] = sum;       }       int ans = 0x3f3f3f3f;       for (int i = 1; i <= n; ++i)         for (int j = 1; j <= m; ++j) {           int now = n + m - sx[i] - sy[j];           if (a[i][j] ==  . ) --now;           ans = std::min(ans, now);         }       printf( %d n , ans);       for (int i = 1; i <= n; ++i) a[i].clear(), sx[i] = 0;       for (int i = 1; i <= m; ++i) sy[i] = 0;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   auto clk = clock();   mt19937_64 rang(       chrono::high_resolution_clock::now().time_since_epoch().count());   void test_case() {     long long int n;     cin >> n;     long long int a[n + 1];     long long int t = -1, b = -1, c = -1;     for (long long int i = 1; i <= n; i++) {       cin >> a[i];     }     for (long long int i = 2; i <= n - 1; i++) {       for (long long int j = i - 1; j >= 1; j--) {         if (a[j] < a[i]) {           t = j;           break;         }       }       for (long long int j = i + 1; j <= n; j++) {         if (a[j] < a[i]) {           c = j;           break;         }       }       if (t != -1 && c != -1) {         b = i;         break;       }       t = -1, c = -1;     }     if (b != -1) {       cout <<  YES  << endl;       cout << t <<     << b <<     << c << endl;     } else       cout <<  NO  << endl;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     srand(chrono::high_resolution_clock::now().time_since_epoch().count());     cout << fixed << setprecision(10);     long long int t = 1;     cin >> t;     while (t--) {       test_case();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long nthRoot(long long A, long long N) {     float xPre = rand() % 10;     float eps = 1e-3;     float delX = LLONG_MAX;     float xK;     while (delX > eps) {       xK = ((N - 1.0) * xPre + (float)A / pow(xPre, N - 1)) / (float)N;       delX = abs(xK - xPre);       xPre = xK;     }     return ceil(xK);   }   int main() {     long long n;     cin >> n;     char a[] = { c ,  o ,  d ,  e ,  f ,  o ,  r ,  c ,  e ,  s };     long long in = 0, num;     num = nthRoot(n, 10);     if (pow(num, 10) < n) num++;     for (int i = 0; i <= 10; i++) {       if (pow(num - 1, i) * pow(num, 10 - i) >= n) {         in = i;       } else         break;     }     if (in * (num - 1) + (10 - in) * num - 10 < n - 1) {       for (int i = 0; i < in; i++) {         long long t = num - 1;         while (t--) cout << a[i];       }       for (int i = in; i < 10; i++) {         long long t = num;         while (t--) cout << a[i];       }     } else {       for (int i = 0; i < 10; i++) cout << a[i];       long long t = n - 1;       while (t--) cout << a[9];     }   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   inline void amin(T& a, const T& b) {     if (a > b) a = b;   }   template <class T>   inline void amax(T& a, const T& b) {     if (a < b) a = b;   }   template <class T>   inline void rv(vector<T>& v, int n) {     vector<T>(n).swap(v);     for (int i = 0; i < (n); i++) cin >> v[i];   }   inline void rv(int* v, int n) {     for (int i = 0; i < (n); i++) scanf( %d , &v[i]);   }   inline void rv(long long* v, int n) {     for (int i = 0; i < (n); i++) scanf( %lld , &v[i]);   }   inline vector<int> rvi(int n) {     vector<int> v(n);     for (int i = 0; i < (n); i++) scanf( %d , &v[i]);     return v;   }   inline vector<long long> rvl(int n) {     vector<long long> v(n);     for (int i = 0; i < (n); i++) scanf( %lld , &v[i]);     return v;   }   inline vector<string> rvs(int n) {     vector<string> v(n);     for (int i = 0; i < (n); i++) scanf( %s , &v[i]);     return v;   }   template <class T>   inline void readvv(vector<vector<T>>& v, int m, int n) {     vector<vector<T>>(m).swap(v);     for (int i = 0; i < (m); i++) readv(v[i], n);   }   inline void pvi(vector<int>& v) {     for (int i = 0; i < (v.size()); i++) printf( %d  , v[i]);     printf(  n );   }   inline void pvl(vector<long long>& v) {     for (int i = 0; i < (v.size()); i++) {       printf( %lld  , v[i]);     }     printf(  n );   }   inline void pvs(vector<string>& v) {     for (int i = 0; i < (v.size()); i++) {       printf( %s n , v[i].c_str());     }   }   int main() {     long long n;     long double s;     cin >> n >> s;     vector<vector<long long>> g(n);     for (int i = 0; i < (n - 1); i++) {       long long u, v;       cin >> u >> v;       g[u - 1].push_back(v - 1);       g[v - 1].push_back(u - 1);     }     long double leaves = 0, two = 2;     for (int i = 0; i < (n); i++) {       if (g[i].size() == 1) leaves++;     }     cout << setprecision(20) << endl;     cout << ((two * s) / leaves) << endl;     return 0;   }


#include  bits/stdc++.h    using namespace std;   #define all(x) x.begin(),x.end()   #define pb push_back   #define ff first   #define ss second   #define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)   #define ar array   #define int long long    #define F(i,a,b) for(i=a;i<b;++i)   #define RF(i,b,a) for(i=b;i>=a;--i)    #define NL cout<<  n ;   #define INF LONG_LONG_MAX   #define pii pair<int,int>   #define vi vector<int>      typedef long long ll;   typedef long double ld;   const ll mod=1e9+7;   bool comp(ll a,ll b)   {    return a<b;   }   ll fpow(ll a, ll b) {       ll res=1;    while(b) {     if(b&1)      res=(res*a);     a=(a*a);     b>>=1;    }    return res;   }      ll minm(ll a,ll b){    if(a<b) return a;    return b;   }      ll maxm(ll a,ll b){    if(a>b){ return a;}    else return b;   }      int PHI(int k){    // This is Euler s Totient Function.    //This function returns no. of coprime numbers to N in range [1,2,....,N]         int ans=k;      for(int i=2;i*i<=k;++i){       if(k%i==0){        ans-=ans/i;        while(k%i==0){         k/=i;        }       }      }        if(k>1) ans-=ans/k;        return ans;          }      void solve(){           int n,i;      cin >> n;            vector<pii>ecells;      vector<pii>ocells;            for(i=1;i<=n;i++){       for(int j=1;j<=n;j++){        if((i+j)%2){         ocells.pb({i,j});        }        else ecells.pb({i,j});       }      }            // 1 even      // 2,3 odd      // if not possible ie all odd are filled, fill 2,3 in even            int cnt=0;            while(cnt<n*n){       int a; cin >> a;              if(a==1){         // try to fill 2 in odd cell          // if not possible , fill 3 in even         if(ocells.empty()){          cout<< 3  <<ecells.back().ff<<   <<ecells.back().ss<<endl;          ecells.pop_back();         }                  else{          cout<< 2  <<ocells.back().ff<<   <<ocells.back().ss<<endl;          ocells.pop_back();         }         ++cnt;       }              else if(a==2){        // fill 1 in even , if possible        if(!ecells.empty()){         cout<< 1  <<ecells.back().ff<<   <<ecells.back().ss<<endl;         ecells.pop_back();        }                else{         // fill 3 in ocells         cout<< 3  <<ocells.back().ff<<   <<ocells.back().ss<<endl;         ocells.pop_back();        }        cnt++;       }       else{        // fill 1 in even if possible        if(!ecells.empty()){         cout<< 1  <<ecells.back().ff<<   <<ecells.back().ss<<endl;         ecells.pop_back();        }        else{         // fill 2 in odd         cout<< 2  <<ocells.back().ff<<   <<ocells.back().ss<<endl;         ocells.pop_back();        }        cnt++;       }      }                  }         signed main(void)        {       fast;            int _=1;    //cin>>_;             for(int test_case=1;test_case<=_;++test_case){            solve();         }             }


#include <bits/stdc++.h>   int main() {     char str[3][100];     int i;     for (i = 0; i < 3; i++) {       scanf( %s  , &str[i][0]);     }     int r = 0, p = 0, s = 0;     for (i = 0; i < 3; i++) {       if (str[i][0] ==  r )         r++;       else if (str[i][0] ==  p )         p++;       else if (str[i][0] ==  s )         s++;     }     char m =  a ;     if (r == 1 && s == 2)       m =  r ;     else if (s == 1 && p == 2)       m =  s ;     else if (p == 1 && r == 2)       m =  p ;     if (m !=  a ) {       for (i = 0; i < 3; i++) {         if (str[i][0] == m) break;       }       if (i == 0)         printf( F );       else if (i == 1)         printf( M );       else if (i == 2)         printf( S );     } else       printf( ? );   }


#include <bits/stdc++.h>   using namespace std;   long long int powe(long long int d, long long int s) {     if (s == 1)       return d;     else if (s == 0)       return 1;     else {       long long int u, v = d;       for (u = 1; u < s; u++) {         d = d * v;       }       return d;     }   }   bool isprime(long long int n) {     long long int i;     for (i = 2; i * i <= n; i++) {       if (n % i == 0) {         return false;       }     }     return true;   }   long long int a[2000005], c[10000005];   int main() {     map<int, int> b;     long long int i, p, y, mx = -1, j, q;     cin >> p >> y;     for (i = y; i > p; i--) {       q = 1;       for (j = 2; j * j <= i && j <= p; j++) {         if (i % j == 0) {           q = 0;           break;         }       }       if (q == 1) {         cout << i;         return 0;       }     }     cout << -1;   }


#include <bits/stdc++.h>   using namespace std;   using llint = long long;   using par = pair<int, int>;   const int MAXN = 200100;   llint w[MAXN];   vector<par> edges[MAXN];   int p[MAXN], in[MAXN], out[MAXN], idx[MAXN], id;   void dfs(int u) {     in[u] = ++id;     for (const auto& edge : edges[u]) {       if (edge.first == p[u]) continue;       p[edge.first] = u;       idx[edge.first] = edge.second;       dfs(edge.first);     }     out[u] = id;   }   int next(int u) { return w[idx[u]] == 1 ? p[u] = next(p[u]) : u; }   void toLCA(int u, int v, llint& c) {     if (!u || !c) return;     if (in[u] <= in[v] && out[u] >= out[v]) return;     c /= w[idx[u]];     toLCA(p[u] = next(p[u]), v, c);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     llint c;     int n, m, u, v;     cin >> n >> m;     for (int i = 1; i < n; ++i) {       cin >> u >> v >> w[i];       edges[u].emplace_back(v, i);       edges[v].emplace_back(u, i);     }     dfs(1);     while (m--) {       cin >> u;       if (u == 1) {         cin >> u >> v >> c;         toLCA(u, v, c);         toLCA(v, u, c);         cout << c <<   n ;       } else {         cin >> u >> c;         w[u] = c;       }     }   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   ll BASE_NUM = 998244353;   class UnionFindTree {     map<ll, ll> union_tree_data;       public:     UnionFindTree() {}     UnionFindTree(vector<ll> verticals) {       for (auto v : verticals) {         union_tree_data[v] = v;       }     }     void add_vertical(ll v) { union_tree_data[v] = v; }     void reset() {       for (auto &pair : union_tree_data) {         pair.second = pair.first;       }     }     long long find(long long N) {       if (union_tree_data[N] == N) {         return N;       } else {         return union_tree_data[N] = find(union_tree_data[N]);       }     }     bool same(long long x, long long y) { return find(x) == find(y); }     void union_tree(long long x, long long y) {       x = find(x);       y = find(y);       if (x == y) return;       union_tree_data[x] = y;     }   };   class edge {    public:     ll from, to, cost;     bool operator<(const edge &another) const { return cost < another.cost; };     bool operator>(const edge &another) const { return cost > another.cost; };   };   class MST {     UnionFindTree uft;       public:     priority_queue<edge, vector<edge>, greater<edge>> que;     vector<edge> result;     ll cost = 0;     MST(vector<ll> &nodes, vector<edge> &edges) : uft(nodes) {       for (auto e : edges) {         que.push(e);       }       while (!que.empty()) {         edge e;         e = que.top();         if (!uft.same(e.from, e.to)) {           uft.union_tree(e.from, e.to);           result.push_back(e);           cost += e.cost;         }         que.pop();       }     }   };   int main() {     ll n;     vector<pair<ll, ll>> towns;     vector<ll> costs;     vector<ll> ks;     vector<edge> edges;     cin >> n;     for (int i = 0; i < n; i++) {       pair<ll, ll> p;       cin >> p.first >> p.second;       towns.push_back(p);     }     for (int i = 0; i < n; i++) {       ll c;       cin >> c;       costs.push_back(c);     }     for (int i = 0; i < n; i++) {       ll k;       cin >> k;       ks.push_back(k);     }     for (int i = 0; i < n; i++) {       for (int j = i + 1; j < n; j++) {         edges.push_back({i, j,                          (abs(towns[i].first - towns[j].first) +                           abs(towns[i].second - towns[j].second)) *                              (ks[i] + ks[j])});       }     }     for (int i = 0; i < n; i++) {       edges.push_back({i, n, costs[i]});     }     vector<ll> nodes(n + 1);     for (int i = 0; i < n + 1; i++) {       nodes[i] = i;     }     MST mst(nodes, edges);     vector<ll> stations;     vector<pair<ll, ll>> connections;     for (auto e : mst.result) {       if (e.to == n) {         stations.push_back(e.from);       } else {         connections.push_back(make_pair(e.from, e.to));       }     }     cout << mst.cost <<   n ;     cout << stations.size() <<   n ;     for (int i = 0; i < stations.size(); i++) {       if (i == 0) {         cout << stations[i] + 1;       } else {         cout <<     << stations[i] + 1;       }     }     cout <<   n ;     cout << connections.size() <<   n ;     for (int i = 0; i < connections.size(); i++) {       cout << connections[i].first + 1 <<     << connections[i].second + 1            <<   n ;     }     cout << flush;     return 0;   }


#include <bits/stdc++.h>   #define fi first   #define se second   #define gc getchar() //(p1==p2&&(p2=(p1=buf)+fread(buf,1,size,stdin),p1==p2)?EOF:*p1++)   #define mk make_pair   #define pii pair<int, int>   #define pll pair<ll, ll>   #define pb push_back   #define IT iterator   #define V vector   #define TP template <class o>   #define TPP template <typename t1, typename t2>   #define SZ(a) ((int)a.size())   #define all(a) a.begin(), a.end()   #define rep(i, a, b) for (int i = a; i <= b; i++)   #define REP(i, a, b) for (int i = b; i >= a; i--)   #define FOR(i,n) rep(i,1,n)   #define debug(x) cerr << #x <<   =   << x << endl   using namespace std;   typedef unsigned ui;   typedef long long ll;   typedef unsigned long long ull;   typedef double db;   typedef long double ld;   const int N = 3010, size = 1 << 20, mod = 998244353, inf = 2e9;   const ll INF = 1e15;      // char buf[size],*p1=buf,*p2=buf;   TP void qr(o& x) {       char c = gc;       x = 0;       int f = 1;       while (!isdigit(c)) {           if (c ==  - )               f = -1;           c = gc;       }       while (isdigit(c))           x = x * 10 + c -  0 , c = gc;       x *= f;   }   template<class o,class ... O> void qr(o& x, O& ... y) {qr(x); qr(y...);}   TP void qw(o x) {       if (x / 10)           qw(x / 10);       putchar(x % 10 +  0 );   }   TP void pr1(o x) {       if (x < 0)           x = -x, putchar( - );       qw(x);       putchar(   );   }   template<class o,class ... O> void pr1(o x, O ... y) { pr1(x); pr1(y...);}   TP void pr2(o x) {       if (x < 0)           x = -x, putchar( - );       qw(x);       putchar(  n );   }   template<class o,class ... O> void pr2(o x, O ... y) { pr2(x); pr2(y...);}      // math   ll gcd(ll a, ll b) { return !a ? b : gcd(b % a, a); }   ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }   ll power(ll a, ll b = mod - 2, ll p = mod) {       ll c = 1;       while (b) {           if (b & 1) c = c * a % p;           b /= 2;           a = a * a % p;       }       return c;   }   ll exgcd(ll a,ll b,ll &x,ll &y) {    if(!a) {x=0; y=1; return b;}    ll d=exgcd(b%a,a,y,x); x -= b/a*y;    return d;   }   ll INV(ll n,ll p=mod) {ll x,y; exgcd(n,p,x,y); return (x%p+p)%p;}      TP void cmax(o& x, o y) {       if (x < y)           x = y;   }   TP void cmin(o& x, o y) {       if (x > y)           x = y;   }   TPP void ad(t1& x, t2 y) {       x += y;       if (x >= mod)           x -= mod;   }   TPP void dl(t1& x, t2 y) {       x -= y;       if (x < 0)           x += mod;   }       int n, m, X[N], Y[N];   V<int> e[N], g[N], E, P;   bool v[N];   #define DEBUG      void dfs(int x) {    int i, y;    while(SZ(g[x])) {     i = g[x].back(); g[x].pop_back();     if(v[i]) continue;     y = x ^ X[i] ^ Y[i];     v[i] = 1; dfs(y);    }    P.pb(x);   }      void check(int s, int w = 0) {    FOR(i, n) g[i] = e[i];    FOR(i, m) v[i] = 0;    int cnt = 0;    FOR(i, n) if(i ^ s) cnt += SZ(e[i]) & 1;    if(cnt > 1) return ;    P.clear(); dfs(s);    if(SZ(P) + SZ(E) - 1 - (w > 0) != m) return ;    P.pb(-1);    for(int i: E) if(i ^ w) P.pb(X[i] ^ Y[i] ^ s), P.pb(s);     pr2(SZ(P));    for(int i: P) pr1(i);    exit(0);   }      void solve() {    qr(n, m);    FOR(i, m) qr(X[i], Y[i]);    FOR(s, n) {     FOR(i, n) e[i].clear();     P.clear(); E.clear();     FOR(i, m) {      int x = X[i], y = Y[i];      if(x == s || y == s) continue;      e[x].pb(i); e[y].pb(i);     }     FOR(i, m) {      int x = X[i], y = Y[i];      if(x == s || y == s) {       int v = s ^ x ^ y;       if(SZ(e[v]) & 1) e[s].pb(i), e[v].pb(i);       else E.pb(i);      }     }     check(s);     for(int i: E) {      e[X[i]].pb(i); e[Y[i]].pb(i);      check(s, i);      e[X[i]].pop_back(); e[Y[i]].pop_back();     }    }    puts( 0 );   }      int main() {       int T = 1;   //    qr(T);       while (T--)           solve();       return 0;   }