#include <bits/stdc++.h>   using namespace std;   int input[100000];   int output[100000];   pair<pair<int, int>, int> queries[100000];   int blockSize;   bool mo_compare(pair<pair<int, int>, int>& x, pair<pair<int, int>, int>& y) {     int firstBlockIndex = x.first.first / blockSize;     int secondBlockIndex = y.first.first / blockSize;     if (firstBlockIndex == secondBlockIndex) {       return x.first.second < y.first.second;     }     return firstBlockIndex < secondBlockIndex;   }   void inline removeElement(unordered_map<int, int>& lookup, int val,                             int& result) {     unordered_map<int, int>::iterator itr = lookup.find(val);     if (itr != lookup.end()) {       if (itr->first == itr->second) {         result--;       }       itr->second--;       if (itr->first == itr->second) {         result++;       }     } else {       lookup[val]--;     }   }   void inline addElement(unordered_map<int, int>& lookup, int val, int& result) {     unordered_map<int, int>::iterator itr = lookup.find(val);     if (itr != lookup.end()) {       if (itr->first == itr->second) {         result--;       }       itr->second++;       if (itr->first == itr->second) {         result++;       }     } else {       lookup[val]++;       if (val == 1) {         result++;       }     }   }   int main() {     cin.tie(NULL);     int n, m;     cin >> n >> m;     blockSize = static_cast<int>(sqrt(n));     for (int i = 0; i < n; i++) {       cin >> input[i];     }     for (int i = 0; i < m; i++) {       pair<pair<int, int>, int>& query = queries[i];       cin >> query.first.first >> query.first.second;       query.first.first--;       query.first.second--;       query.second = i;     }     sort(queries, queries + m, mo_compare);     unordered_map<int, int> lookup;     int result = 0;     int prev_l = 0, prev_r = -1, left, right, index;     unordered_map<int, int>::iterator itr;     for (int i = 0; i < m; i++) {       left = queries[i].first.first;       right = queries[i].first.second;       index = queries[i].second;       while (left > prev_l) {         removeElement(lookup, input[prev_l], result);         prev_l++;       }       while (left < prev_l) {         prev_l--;         addElement(lookup, input[prev_l], result);       }       while (right < prev_r) {         removeElement(lookup, input[prev_r], result);         prev_r--;       }       while (right > prev_r) {         prev_r++;         addElement(lookup, input[prev_r], result);       }       output[index] = result;     }     for (int i = 0; i < m; i++) {       cout << output[i] <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long k, n, m;   int answ = 1;   bool flag = 0;   int main() {     cin >> n >> m;     k = 2;     for (int i = 2; i <= m; i++) k = (k * 2) % 1000000009;     if (k > n) {       for (int i = 1; i <= n; i++) answ = (answ * (k - i)) % 1000000009;       cout << answ;     } else       cout << 0;   }


#include <bits/stdc++.h>   using namespace std;   const double pi = acos(-1.0);   long long int path[100001];   long long int dist[100001];   void shortest_path(vector<pair<long long int, long long int>> v[],                      long long int start) {     long long int i;     for (i = 0; i < 100001; i++) dist[i] = 1e18 + 1;     priority_queue<long long int> q;     q.push(start);     dist[start] = 0;     while (!q.empty()) {       long long int x = q.top();       q.pop();       for (i = 0; i < v[x].size(); i++) {         if (dist[v[x][i].first] > dist[x] + v[x][i].second) {           dist[v[x][i].first] = dist[x] + v[x][i].second;           path[v[x][i].first] = x;           q.push(v[x][i].first);         }       }     }   }   void solve() {     long long int ver, edge, i, x, y, w, start = 1;     cin >> ver >> edge;     vector<pair<long long int, long long int>> v[ver + 1];     vector<long long int> ans;     for (i = 0; i < edge; i++) {       cin >> x >> y >> w;       v[x].push_back(make_pair(y, w));       v[y].push_back(make_pair(x, w));     }     shortest_path(v, start);     if (dist[ver] == 1e18 + 1)       cout <<  -1             <<   n ;     else {       cout <<  1  ;       while (ver != 1) {         ans.push_back(ver);         ver = path[ver];       }       for (i = ans.size() - 1; i >= 0; i--) {         cout << ans[i] <<    ;       }       cout <<   n ;     }   }   void fast() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);   }   int main() {     fast();     int t = 1;     while (t--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = int64_t;   template <typename T, typename U>   ostream& operator<<(ostream& _s, pair<T, U> _t) {     _s <<  (  << _t.first <<  ,  << _t.second <<  ) ;     return _s;   }   template <typename T, typename U>   istream& operator>>(istream& _s, pair<T, U>& _t) {     _s >> _t.first >> _t.second;     return _s;   }   template <typename T>   ostream& operator<<(ostream& _s, vector<T> _t) {     for (int i = 0; i < (int)(_t.size()); i++) _s << (i ?     :   ) << _t[i];     return _s;   }   template <typename T>   istream& operator>>(istream& _s, vector<T>& _t) {     for (int i = 0; i < (int)(_t.size()); i++) _s >> _t[i];     return _s;   }   vector<int> val, comp, z, cont;   int Time, ncomps;   template <class G, class F>   int dfs(int j, G& g, F f) {     int low = val[j] = ++Time, x;     z.push_back(j);     for (auto& e : g[j])       if (comp[e] < 0) low = min(low, val[e] ?: dfs(e, g, f));     if (low == val[j]) {       do {         x = z.back();         z.pop_back();         comp[x] = ncomps;         cont.push_back(x);       } while (x != j);       f(cont);       cont.clear();       ncomps++;     }     return val[j] = low;   }   template <class G, class F>   void scc(G& g, F f) {     int n = g.size();     val.assign(n, 0);     comp.assign(n, -1);     Time = ncomps = 0;     for (int i = 0; i < (int)(n); i++)       if (comp[i] < 0) dfs(i, g, f);   }   void tassert(bool cond) {     if (!cond) {       while (1 < 2) {       }     }   }   void answer(int x) {     cout <<  !   << (x + 1) << endl;     cout << flush;     exit(0);   }   bool ask(int a, int b) {     cout <<  ?   << (a + 1) <<     << (b + 1) << endl;     cout << flush;     int res;     cin >> res;     if (res == -1) {       exit(123);     }     return bool(res);   }   int main() {     int n, m;     cin >> n >> m;     vector<vector<int>> g(n);     for (int i = 0; i < (int)(m); i++) {       int x, y;       cin >> x >> y;       g[x - 1].push_back(y - 1);     }     vector<vector<int>> comps;     scc(g, [&](vector<int>& v) { comps.push_back(v); });     vector<unordered_set<int>> cg(ncomps);     for (int a = 0; a < (int)(n); a++) {       for (int b : g[a]) {         if (comp[a] != comp[b]) {           cg[comp[a]].insert(comp[b]);         }       }     }     vector<int> indeg(ncomps, 0);     for (int aa = 0; aa < (int)(ncomps); aa++) {       for (int bb : cg[aa]) {         indeg[bb]++;       }     }     unordered_set<int> heads;     for (int aa = 0; aa < (int)(ncomps); aa++) {       if (indeg[aa] == 0) {         heads.insert(aa);       }     }     int head = *heads.begin();     int cap = comps[head].back();     comps[head].pop_back();     auto update = [&](int aa) {       if (comps[aa].size() == 0) {         heads.erase(aa);         for (int bb : cg[aa]) {           tassert(comps[bb].size() > 0);           indeg[bb]--;           if (indeg[bb] == 0) {             heads.insert(bb);           }         }       }     };     while (true) {       assert(heads.size());       if (heads.size() == 1) {         answer(cap);       }       auto head2it = heads.begin();       if (head == (*head2it)) {         head2it++;       }       int head2 = *head2it;       tassert(!cg[head].count(head2));       int cap2 = comps[head2].back();       comps[head2].pop_back();       bool ok = ask(cap, cap2);       if (!ok) {         update(head);         head = head2;         cap = cap2;       } else {         update(head2);       }     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     unsigned long long n;     cin >> n;     vector<unsigned long long> a(n);     for (unsigned long long i = 0; i < n; i++) cin >> a[i];     unsigned long long total = 0;     for (unsigned long long i = 0; i < n; i++) total += a[i];     vector<unsigned long long> f;     unsigned long long zd = total;     for (unsigned long long i = 2; (i * i) <= zd; i++) {       if (zd % i == 0) {         f.push_back(i);         while (zd % i == 0) {           zd /= i;         }       }     }     if (zd != 1) f.push_back(zd);     if (total == 1) {       cout << -1 <<   n ;       return 0;     }     unsigned long long is = 900000000000000000;     for (unsigned long long i = 0; i < f.size(); i++) {       unsigned long long x = f[i];       unsigned long long temp = 0;       vector<pair<unsigned long long, unsigned long long>> z;       unsigned long long tt = 0;       for (unsigned long long j = 0; j < n; j++) {         tt += a[j] % x;         z.push_back(make_pair(j, a[j] % x));         if (tt >= x) {           unsigned long long left = 0;           unsigned long long right = 0;           unsigned long long Sr = 0;           unsigned long long Sl = 0;           z[z.size() - 1].second -= (tt - x);           for (unsigned long long k = 0; k < z.size(); k++) {             right +=                 (unsigned long long)z[k].first * (unsigned long long)z[k].second;           }           Sr = x;           unsigned long long ttt = 900000000000000000;           for (unsigned long long k = 0; k < z.size(); k++) {             unsigned long long t2 = 0;             right -= ((unsigned long long)z[k].first *                       (unsigned long long)z[k].second);             left += ((unsigned long long)z[k].first *                      (unsigned long long)z[k].second);             Sr -= z[k].second;             Sl += z[k].second;             t2 += (right - Sr * z[k].first) + (Sl * z[k].first - left);             ttt = min(ttt, t2);           }           temp += ttt;           z.clear();           tt %= x;           z.push_back(make_pair(j, tt));         }       }       is = min(is, temp);     }     cout << is <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ld = long double;   using pii = pair<int, int>;   constexpr int MAXN = 100005;   int n;   string type[MAXN], word[MAXN];   bitset<30> to_bs(const string& s) {     bitset<30> res;     for (char c : s) {       res[c -  a ] = true;     }     return res;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n;     bitset<30> all = to_bs( abcdefghijklmnopqrstuvwxyz );     int ans = 0;     for (int i = 0; i < n; ++i) {       cin >> type[i] >> word[i];       bitset<30> cur = to_bs(word[i]);       if (type[i][0] ==  ! ) {         if (all.count() <= 1) {           ans += 1;         }         all = all & cur;       } else if (type[i][0] ==  . ) {         all = all & cur.flip();       } else {         if (all.count() == 1) ans += 1;         all.reset(word[i][0] -  a );       }     }     cout << max(0, ans - 1) <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 10;   bool lucky[10010];   int n, m;   int a[N];   int t[N + N];   void init() {     memset(lucky, false, sizeof(lucky));     lucky[0] = true;     for (int i = 1; i <= 10000; i++)       if (i % 10 == 4 || i % 10 == 7) lucky[i] = lucky[i / 10];   }   void update(int i, int v) {     if (!v) return;     i += n;     while (i >= 1) {       t[i] += v;       i >>= 1;     }   }   int query(int Left, int Right) {     int res = 0;     Left += n;     Right += n;     while (Left <= Right) {       if (Left % 2) res += t[Left];       if ((~Right) % 2) res += t[Right];       Left = (Left + 1) >> 1;       Right = (Right - 1) >> 1;     }     return res;   }   int main() {     init();     scanf( %d%d , &n, &m);     memset(t, 0, sizeof(t));     for (int i = 0; i < n; i++) {       scanf( %d , &a[i]);       update(i, lucky[a[i]]);     }     char x[10];     int Left, Right, temp;     while (m--) {       scanf( %s , &x);       if (strcmp(x,  count ) == 0) {         scanf( %d%d , &Left, &Right);         Left--;         Right--;         printf( %d n , query(Left, Right));       } else {         scanf( %d%d%d , &Left, &Right, &temp);         Left--;         Right--;         for (int i = Left; i <= Right; i++) {           a[i] += temp;           update(i, lucky[a[i]] - lucky[a[i] - temp]);         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double pi = acos(-1.0), eps = 1e-8;   const int inf = ~0U >> 2;   int mod = 1e9 + 7;   int Pow(int x, long long t) {     int r = 1;     for (; t; t >>= 1, x = (long long)x * x % mod)       if (t & 1) r = (long long)r * x % mod;     return r;   }   const int N = 101010;   int n, K;   struct P {     long long x, y;     void in() { cin >> x >> y; }     P(long long _x = 0, long long _y = 0) { x = _x, y = _y; }     double dis() { return sqrt(x * x + y * y); }     long long operator^(const P& b) { return x * b.y - y * b.x; }     P operator-(const P& b) { return P(x - b.x, y - b.y); }   } p[N << 1], q;   long long mul(P& o, P& a, P& b) { return (a - o) ^ (b - o); }   bool in(P q) {     double a = 0;     for (int i = 0; i < n; ++i) {       long long aera = mul(q, p[i], p[i + 1]);       double disa = (p[i] - q).dis(), disb = (p[i + 1] - q).dis(),              disc = (p[i] - p[i + 1]).dis();       double angle = acos(((disa) * (disa) + (disb) * (disb) - (disc) * (disc)) /                           2.0 / disa / disb);       if (aera > 0)         a += angle;       else         a -= angle;     }     return fabs(a) >= 1;   }   long long wk() {     q.in();     if (!in(q)) return 0;     long long ans = (long long)n * (n - 1) * (n - 2) / 6;     for (int i = 0, j = 1; i < n; ++i) {       while (mul(p[i], p[j], q) <= 0) ++j;       int del = (j + n - i) % n;       int rm = n - del;       ans -= (long long)rm * (rm - 1) / 2;     }     return ans;   }   int main() {     cin >> n;     for (int i = 0; i < n; ++i) p[i].in(), p[i + n] = p[i];     cin >> K;     for (int i = 0; i < K; ++i) cout << wk() << endl;     return 0;   }


#include <bits/stdc++.h>       using namespace std;       bool palindrome(const string &s) {       int n = s.length();       for(int i = 0; i < n; i++) {           if(s[i] != s[n - i - 1]) return false;       }       return true;   }       int main() {       ios::sync_with_stdio(false);       cin.tie(0);       int te;       cin >> te;       while(te--) {           string s;           cin >> s;           if(!palindrome(s +  a )) {               cout <<  YES n  << s <<  a  <<   n ;           }else if(!palindrome( a  + s)) {               cout <<  YES n  <<  a  << s <<   n ;           }else {               cout <<  NO n ;           }       }   }


#include <bits/stdc++.h>   const long double PI(acosl(-1.0));   long double eps = 1e-9;   using namespace std;   using namespace std;   const int N = 1000000;   int main() {     std::ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     vector<pair<int, int> > p(n);     int s = 0;     for (int i(0); i < n; i++) {       int x;       cin >> x;       s += x;       p[i] = {x, i + 1};     }     sort(++p.begin(), p.end());     reverse(++p.begin(), p.end());     vector<pair<int, int> > ans;     int j = 1;     int i = 0;     while (j < n) {       while (j < n && p[i].first > 0) {         ans.push_back({p[i].second, p[j].second});         p[i].first--;         j++;       }       i++;       if (i == j) break;     }     if (j < n) {       cout << -1;       return 0;     }     cout << ans.size() << endl;     for (int i(0); i < ans.size(); i++)       cout << ans[i].first <<     << ans[i].second <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   void CIN(T &a) {     cin >> a;   }   template <class T>   void CIN(T &a, T &b) {     cin >> a >> b;   }   template <class T>   void CIN(T &a, T &b, T &c) {     cin >> a >> b >> c;   }   template <class T>   void CIN(T &a, T &b, T &c, T &d) {     cin >> a >> b >> c >> d;   }   template <class T>   void PI(T a) {     cout << a << endl;   }   template <class T>   void PI(T a, T b) {     cout << a <<     << b << endl;   }   template <class T>   void PIS(T a) {     cout << a <<    ;   }   template <class T>   T abs(T a) {     return a < 0 ? -a : a;   }   const int N = 10000010;   long long n, x, y, dx, dy, t;   int b[6][6] = {{2, 1, 1, 0, 1, 0}, {1, 2, 0, 1, 1, 0}, {1, 1, 1, 0, 1, 0},                  {1, 1, 0, 1, 1, 0}, {0, 0, 0, 0, 1, 1}, {0, 0, 0, 0, 0, 1}};   struct matrix {     long long a[6][6];     matrix() { memset(a, 0, sizeof(a)); }     void init() {       int i, j;       for (i = 0; i < (int)(6); ++i)         for (j = 0; j < (int)(6); ++j) a[i][j] = b[i][j];     }     void unit() {       memset(a, 0, sizeof(a));       int i;       for (i = 0; i < (int)(6); ++i) a[i][i] = 1;     }     matrix operator*(const matrix &b) const {       matrix ret;       int i, j, k;       for (i = 0; i < (int)(6); ++i)         for (j = 0; j < (int)(6); ++j)           for (k = 0; k < (int)(6); ++k) {             ret.a[i][j] += a[i][k] * b.a[k][j];             ret.a[i][j] %= n;           }       return ret;     }     matrix Pow(long long k) {       matrix ret, p = *this;       ret.unit();       while (k) {         if (k & 1) ret = ret * p;         k >>= 1;         p = p * p;       }       return ret;     }   } mx;   int main() {     CIN(n);     CIN(x, y, dx, dy);     CIN(t);     mx.init();     mx = mx.Pow(t);     long long ex = mx.a[0][0] * x + mx.a[0][1] * y + mx.a[0][2] * dx +                    mx.a[0][3] * dy + mx.a[0][5];     long long ey = mx.a[1][0] * x + mx.a[1][1] * y + mx.a[1][2] * dx +                    mx.a[1][3] * dy + mx.a[1][5];     ex %= n;     if (ex <= 0) ex += n;     ey %= n;     if (ey <= 0) ey += n;     PI(ex, ey);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, c;     cin >> a >> b >> c;     int max = 0;     int n[100];     n[0] = a * b + c, n[1] = a * b * c, n[2] = a + b * c, n[3] = a + b + c,     n[4] = a * (b + c), n[5] = (a + b) * c;     for (int i = 0; i < 6; i++) {       if (n[i] > max) max = n[i];     }     cout << max << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;      typedef long long Int;   typedef pair<int,int> PII;   typedef vector<int> VInt;       #define FOR(i, a, b) for(i = (a); i < (b); ++i)   #define RFOR(i, a, b) for(i = (a) - 1; i >= (b); --i)   #define EACH(it, a) for(auto it = (a).begin(); it != (a).end(); ++it)   #define CLEAR(a, b) memset(a, b, sizeof(a))   #define SIZE(a) int((a).size())   #define ALL(a) (a).begin(),(a).end()   #define MP make_pair      int f(VInt p, VInt s)   {    int n = SIZE(p);    int left = 0, right = n - 1;    int res = 0;    VInt used(n, 0);    while(left < right)    {     int cnt = 0;     int flips = 0;     int l = left;     int r = right + 1;     while(l >= left || r <= right)     {      if(l >= left)      {       int a = left;       ++left;       if(used[a] == 0)       {        int b = p[a];        used[a] = used[b] = 1;        ++cnt;        flips += s[a];        if(b > r) return -1;        r = b;        if(l >= r) return -1;       }      }      if(r <= right)      {       int a = right;       --right;       if(used[a] == 0)       {        int b = p[a];        used[a] = used[b] = 1;        ++cnt;        flips += s[a];        if(b < l) return -1;        l = b;        if(l >= r) return -1;       }      }     }     res += min(flips, cnt - flips);    }    return res;   }      void SolveTest(int test)   {    int n;    cin >> n;    int i, j;    VInt p(n + n);    VInt s(n + n);    FOR(i, 0, n)    {     int a, b;     cin >> a >> b;     --a;     --b;     p[a] = b;     p[b] = a;     s[a] = 0;     s[b] = 1;    }       cout << f(p, s) << endl;   }      int main()   {    int T, t;    T = 1;    //cin >> T;    FOR(t, 0, T) SolveTest(t);    return 0;   };


#include <bits/stdc++.h>   using namespace std;   const int N = 55;   const int MOD = 1e9 + 7;   struct Node {     int op, x, y, d;     Node() {}     Node(int _op, int _x, int _y, int _d) { op = _op, x = _x, y = _y, d = _d; }     bool operator<(const Node &cur) const { return d > cur.d; }   };   priority_queue<Node> que;   int dist[2][N][N], n, m, nx, ny;   long long ans[2][N][N], C[N][N];   void init() {     int i, j;     memset(C, 0, sizeof(C));     for (i = 0; i < N; i++) {       C[i][0] = 1;       for (j = 1; j <= i; j++) C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % MOD;     }   }   int main() {     int i, j, tmp;     init();     while (scanf( %d%d , &n, &m) != EOF) {       for (i = 1, nx = ny = 0; i <= n; i++) {         scanf( %d , &tmp);         if (tmp == 50)           nx++;         else           ny++;       }       memset(dist, 0x3f, sizeof(dist));       memset(ans, 0, sizeof(ans));       while (!que.empty()) que.pop();       dist[1][0][0] = 0;       ans[1][0][0] = 1;       que.push(Node(1, 0, 0, 0));       while (!que.empty()) {         Node cur = que.top();         que.pop();         if (cur.d > dist[cur.op][cur.x][cur.y]) continue;         for (i = 0; i <= nx; i++)           for (j = 0; j <= ny; j++) {             if (i + j == 0 || 50 * i + 100 * j > m) continue;             if (cur.op == 0 && cur.x >= i && cur.y >= j) {               if (dist[1][cur.x - i][cur.y - j] >= cur.d + 1) {                 if (dist[1][cur.x - i][cur.y - j] > cur.d + 1) {                   ans[1][cur.x - i][cur.y - j] = 0;                   dist[1][cur.x - i][cur.y - j] = cur.d + 1;                   que.push(Node(1, cur.x - i, cur.y - j, cur.d + 1));                 }                 ans[1][cur.x - i][cur.y - j] +=                     ans[0][cur.x][cur.y] * C[cur.x][i] % MOD * C[cur.y][j] % MOD;                 ans[1][cur.x - i][cur.y - j] %= MOD;               }             }             if (cur.op == 1 && cur.x + i <= nx && cur.y + j <= ny) {               if (dist[0][cur.x + i][cur.y + j] >= cur.d + 1) {                 if (dist[0][cur.x + i][cur.y + j] > cur.d + 1) {                   ans[0][cur.x + i][cur.y + j] = 0;                   dist[0][cur.x + i][cur.y + j] = cur.d + 1;                   que.push(Node(0, cur.x + i, cur.y + j, cur.d + 1));                 }                 ans[0][cur.x + i][cur.y + j] += ans[1][cur.x][cur.y] *                                                 C[nx - cur.x][i] % MOD *                                                 C[ny - cur.y][j] % MOD;                 ans[0][cur.x + i][cur.y + j] %= MOD;               }             }           }       }       if (dist[0][nx][ny] == 0x3f3f3f3f) {         printf( -1 n0 n );       } else {         printf( %d n%I64d n , dist[0][nx][ny], ans[0][nx][ny]);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   bool chmax(T &a, const T &b) {     if (a < b) {       a = b;       return 1;     }     return 0;   }   template <class T>   bool chmin(T &a, const T &b) {     if (a > b) {       a = b;       return 1;     }     return 0;   }   template <class T>   ostream &operator<<(ostream &os, const vector<T> &t) {     os <<  [ ;     for (__typeof((t).begin()) it = (t).begin(); it != (t).end(); it++) {       if (it != t.begin()) os <<  , ;       os << *it;     }     os <<  ] ;     return os;   }   template <class T>   ostream &operator<<(ostream &os, const set<T> &t) {     os <<  { ;     for (__typeof((t).begin()) it = (t).begin(); it != (t).end(); it++) {       if (it != t.begin()) os <<  , ;       os << *it;     }     os <<  } ;     return os;   }   template <class S, class T>   ostream &operator<<(ostream &os, const pair<S, T> &t) {     return os <<  (  << t.first <<  ,  << t.second <<  ) ;   }   template <class S, class T>   pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) {     return pair<S, T>(s.first + t.first, s.second + t.second);   }   template <class S, class T>   pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) {     return pair<S, T>(s.first - t.first, s.second - t.second);   }   namespace geom {   enum { TRUE = 1, FALSE = 0, BORDER = -1 };   const long double INF = 1e8;   long double EPS = 1e-6;   const long double PI = 3.1415926535897932384626;   inline int sig(const long double &x) {     return (abs(x) < EPS ? 0 : x > 0 ? 1 : -1);   }   inline int less(const long double &x, const long double &y) {     return sig(x - y) ? x < y : BORDER;   }   inline long double norm(const complex<long double> &p) {     return p.real() * p.real() + p.imag() * p.imag();   }   inline long double inp(const complex<long double> &a,                          const complex<long double> &b) {     return (conj(a) * b).real();   }   inline long double outp(const complex<long double> &a,                           const complex<long double> &b) {     return (conj(a) * b).imag();   }   inline complex<long double> unit(const complex<long double> &p) {     return p / abs(p);   }   inline complex<long double> proj(const complex<long double> &s,                                    const complex<long double> &t) {     return t * inp(s, t) / norm(t);   }   inline int ccw(const complex<long double> &s, const complex<long double> &t,                  const complex<long double> &p, int adv = 0) {     int res = sig(outp(t - s, p - s));     if (res || !adv) return res;     if (sig(inp(t - s, p - s)) < 0) return -2;     if (sig(inp(s - t, p - t)) < 0) return 2;     return 0;   }   }  // namespace geom   using namespace geom;   int f = 0;   namespace std {   bool operator<(const complex<long double> &a, const complex<long double> &b) {     return sig(a.real() - b.real()) ? a.real() < b.real()                                     : a.imag() + EPS < b.imag();   }   bool operator==(const complex<long double> &a, const complex<long double> &b) {     return abs(a - b) < EPS;   }   istream &operator>>(istream &is, complex<long double> &p) {     long double x, y;     is >> x >> y;     p = complex<long double>(x, y);     return is;   }   }  // namespace std   int n, m;   complex<long double> p, q, v, w;   long double vmax, ct;   long double dist(complex<long double> v, complex<long double> wind,                    long double t) {     if (abs(v) > EPS) v = unit(v);     long double l = 0, r = 1e10;     for (int _ = 0; _ < (int)(100); _++) {       long double mid = (l + r) / 2;       long double vx = v.real() * mid;       long double vy = v.imag() * mid;       if ((vx * vx + vy * vy) <= vmax * vmax)         l = mid;       else         r = mid;     }     return abs(v * l) * t;   }   int check(long double t) {     complex<long double> s =         q + v * min<long double>(t, ct) + w * max<long double>(t - ct, 0);     complex<long double> vec = p - s;     return dist(vec, v, min<long double>(t, ct)) +                dist(vec, w, max<long double>(t - ct, 0)) >=            abs(vec);   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> q >> p;     cin >> vmax >> ct;     cin >> v >> w;     long double l = 0, r = 1e10;     for (int _ = 0; _ < (int)(100); _++) {       long double mid = (l + r) / 2;       if (check(mid))         r = mid;       else         l = mid;     }     printf( %.20f n , (double)l);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   long long a[305], Lcm;   long long sol(long long x) {     long long cnt = 0;     for (long long i = 2; i * i <= x; i++) {       if (x % i == 0) {         cnt += 2;         if (i * i == x) cnt--;       }     }     return cnt;   }   int main() {     int T;     cin >> T;     while (T--) {       int ok = 1;       scanf( %d , &n);       for (int i = 0; i < n; i++) scanf( %lld , &a[i]);       sort(a, a + n);       if (n == 1)         Lcm = a[0] * a[0];       else         Lcm = a[0] * a[n - 1];       for (int i = 1; i < (n + 1) / 2; i++) {         if (a[i] * a[n - 1 - i] != Lcm) {           ok = 0;           break;         }       }       if (ok && sol(Lcm) == n)         printf( %lld n , Lcm);       else         puts( -1 );     }   }


#include <bits/stdc++.h>   using namespace std;   char ch[100001];   int per[100001];   bool is[100001];   bool vis[100001];   bool mem[100001];   bool have[100001];   vector<int> V;   int main() {     int i, j;     int a, b;     int n, m;     cin >> n >> m;     for (i = 0; i < m; i++) {       cin >> ch[i] >> per[i];       have[per[i]] = true;     }     V.clear();     memset(is, true, sizeof is);     for (i = 0; i < m; i++) {       if (ch[i] ==  + ) {         if (!vis[per[i]] && i) is[per[i]] = false;         if (V.size()) {           is[per[i]] = false;         } else {           for (j = i - 1; j >= 0; j--) {             if (per[i] != per[j]) is[per[j]] = false;             if (mem[j]) break;           }           mem[i - 1] = true;         }         V.push_back(per[i]);       } else {         if (!vis[per[i]]) {           for (j = i - 1; j >= 0; j--) {             is[per[j]] = false;             if (mem[j]) break;           }           mem[i - 1] = true;           if (V.size()) is[per[i]] = false;         } else if (V.size() == 1) {           if (V[0] == per[i])             V.clear();           else {             int num = per[i];             V.erase(std::remove(V.begin(), V.end(), num), V.end());             is[num] = false;           }         } else if (V.size()) {           int num = per[i];           V.erase(std::remove(V.begin(), V.end(), num), V.end());           is[num] = false;         }       }       if (!vis[per[i]]) vis[per[i]] = true;     }     vector<int> res;     res.clear();     for (i = 1; i <= n; i++) {       if (!have[i]) {         res.push_back(i);       } else {         if (is[i]) res.push_back(i);       }     }     int sz = res.size();     cout << sz << endl;     for (i = 0; i < sz; i++) cout << res[i] <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   const long long inf = 2e18;   struct custom_hash {     static uint64_t splitmix64(uint64_t x) {       x += 0x9e3779b97f4a7c15;       x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;       x = (x ^ (x >> 27)) * 0x94d049bb133111eb;       return x ^ (x >> 31);     }     size_t operator()(uint64_t x) const {       static const uint64_t FIXED_RANDOM =           chrono::steady_clock::now().time_since_epoch().count();       return splitmix64(x + FIXED_RANDOM);     }   };   int add(int a, int b) {     int res = (a + b) % mod;     if (res < 0) res += mod;     return res;   }   int mult(int a, int b) {     int res = (a * 1LL * b) % mod;     if (res < mod) res += mod;     return res;   }   int power(int a, int b) {     int res = 1;     while (b) {       if ((b % 2) == 1) res = mult(res, a);       a = mult(a, a);       b /= 2;     }     return res;   }   template <typename A, typename B>   string to_string(pair<A, B> p);   template <typename A, typename B, typename C>   string to_string(tuple<A, B, C> p);   template <typename A, typename B, typename C, typename D>   string to_string(tuple<A, B, C, D> p);   string to_string(const string &s) { return     + s +    ; }   string to_string(const char *s) { return to_string((string)s); }   string to_string(bool b) { return (b ?  true  :  false ); }   string to_string(char c) { return to_string(string(1, c)); }   string to_string(vector<bool> v) {     bool first = true;     string res =  { ;     for (int i = 0; i < static_cast<int>(v.size()); i++) {       if (!first) {         res +=  ,  ;       }       first = false;       res += to_string(v[i]);     }     res +=  } ;     return res;   }   template <size_t N>   string to_string(bitset<N> v) {     string res =   ;     for (size_t i = 0; i < N; i++) {       res += static_cast<char>( 0  + v[i]);     }     return res;   }   template <typename A>   string to_string(A v) {     bool first = true;     string res =  { ;     for (const auto &x : v) {       if (!first) {         res +=  ,  ;       }       first = false;       res += to_string(x);     }     res +=  } ;     return res;   }   template <typename A, typename B>   string to_string(pair<A, B> p) {     return  (  + to_string(p.first) +  ,   + to_string(p.second) +  ) ;   }   template <typename A, typename B, typename C>   string to_string(tuple<A, B, C> p) {     return  (  + to_string(get<0>(p)) +  ,   + to_string(get<1>(p)) +  ,   +            to_string(get<2>(p)) +  ) ;   }   template <typename A, typename B, typename C, typename D>   string to_string(tuple<A, B, C, D> p) {     return  (  + to_string(get<0>(p)) +  ,   + to_string(get<1>(p)) +  ,   +            to_string(get<2>(p)) +  ,   + to_string(get<3>(p)) +  ) ;   }   void dbg() { cout << endl; }   template <typename Head, typename... Tail>   void dbg(Head H, Tail... T) {     cout <<     << to_string(H);     dbg(T...);   }   void solve() {     int n;     cin >> n;     vector<int> v(n);     for (int i = 0; i < n; i++) {       cin >> v[i];     }     vector<int> dp(1 << 22, 0);     for (int i = 0; i < n; i++) {       dp[v[i]] = v[i];     }     for (int mask = 1; mask < (1 << 22); mask++) {       for (int i = 0; i < 22; i++) {         if (mask & (1 << i)) {           dp[mask] = max(dp[mask], dp[mask ^ (1 << i)]);         }       }     }     for (int i = 0; i < n; i++) {       int no = ((1 << 22) - 1) & (~v[i]);       if (dp[no]) {         cout << dp[no] <<    ;       } else {         cout <<  -1  ;       }     }   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     cout << fixed << setprecision(10);     int t = 1;     for (int i = 1; i <= t; i++) {       solve();     }   }


#include<bits/stdc++.h>   using namespace std;   #define ll long long   #define ld long double   #define For(i,x,y) for(ll i = (x);i <= (y);++i)   #define FOr(i,x,y) for(ll i = (x);i >= (y);--i)   #define fi first   #define se second   #define pa pair<ll,ll>   #define mk make_pair   #define pb push_back   #define clr(a,b) memset(a,b,sizeof(a))   #define cpy(a,b) memcpy(a,b,sizeof(b))   #define y1 y11111111111111111111   #define debug puts( @@@@@@@@@@@@@@@@@@@@ )   #define NO puts( NO )   #define YES puts( YES )   #define Yes puts( Yes )   #define No puts( No )   inline ll read()   {    ll x = 0,f = 1;char ch = getchar();    while(ch <  0  || ch >  9 ){if(ch ==  - )f = -1;ch = getchar();}    while(ch >=  0  && ch <=  9 ){x = x*10+ch- 0 ;ch = getchar();}    return x*f;   }   char s[999];   int main()   {    while (scanf( %s ,s)!=EOF)    {     if (s[1]== s ) puts( NO ),fflush(stdout);    }   }


#include <bits/stdc++.h>   using namespace std;   int n;   double s;   vector<int> E[100005];   int dist[100005], pa[100005];   int dfs(int u, int p, int d) {     dist[u] = d;     int ans = u;     for (int v : E[u]) {       if (v == p) continue;       int tmp = dfs(v, u, d + 1);       pa[v] = u;       if (dist[ans] < dist[tmp]) ans = tmp;     }     return ans;   }   int main() {     scanf( %d%lf , &n, &s);     for (int i = 0; i < n - 1; i++) {       int u, v;       scanf( %d%d , &u, &v);       E[u].push_back(v);       E[v].push_back(u);     }     if (n == 2) {       printf( %.10lf n , s);       return 0;     }     int l = 0;     for (int i = 1; i <= n; i++) {       if (E[i].size() == 1) l++;     }     printf( %.10lf n , 2.0 * s / l);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long mk[100000];   int main() {     long a, b, m, r0, r;     cin >> a >> b >> m >> r0;     for (long i = 0; i < m; i++) mk[i] = -1;     r = (a * r0 + b) % m;     mk[r] = 1;     long k = 1;     while (true) {       k++;       r = (a * r + b) % m;       if (mk[r] == -1)         mk[r] = k;       else {         cout << k - mk[r];         return 0;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, maxi = 2, ans = 2;   int a[100005];   vector<int> num;   int main() {     cin >> n;     for (int i = 0; i < n; i++) cin >> a[i];     if (n < 3) {       cout << n;       return 0;     }     for (int i = 2; i < n; i++) {       if (a[i] == a[i - 1] + a[i - 2]) {         ans++;         maxi = max(maxi, ans);       } else         ans = 2;     }     cout << maxi;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 100010;   const int mod = 1e9 + 7;   long long dp[maxn] = {0, 1, 2, 3, 5, 8};   int main() {     for (int i = 6; i < maxn; i++) dp[i] = (dp[i - 1] + dp[i - 2]) % mod;     int n, m;     cin >> n >> m;     cout << (2 * (dp[n] + dp[m] - 1)) % mod << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int Set(int N, int pos) { return N = N | (1 << pos); }   int reset(int N, int pos) { return N = N & ~(1 << pos); }   bool check(long long N, int pos) { return (bool)(N & (1LL << pos)); }   int n, m, l, r;   string s;   char c1, c2;   int main() {     cin >> n >> m;     cin >> s;     for (int i = 1; i <= m; i++) {       cin >> l >> r >> c1 >> c2;       l--, r--;       for (int j = l; j <= r; j++) {         if (s[j] == c1) s[j] = c2;       }     }     cout << s << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     set<string> g;     g.insert(s);     int n = s.size();     for (int k = 0; k < s.size(); k++) {       string s1 =   ;       s1 += s[n - 1];       for (int i = 0; i < s.size() - 1; i++) {         s1 += s[i];       }       s = s1;       g.insert(s);     }     cout << g.size();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long mod = 1000000007;   vector<long long> parent(200005), Size(200005, 1);   long long answer = 0;   long long find_set(long long n) {     if (parent[n] == n)       return n;     else       return find_set(parent[n]);   }   void add_edge(long long a, long long b) {     long long A = find_set(a);     long long B = find_set(b);     if (Size[A] >= Size[B]) {       answer -= ((Size[A] * (Size[A] - 1)) / 2);       answer -= ((Size[B] * (Size[B] - 1)) / 2);       Size[A] += Size[B];       Size[B] = 0;       parent[B] = A;       answer += ((Size[A] * (Size[A] - 1)) / 2);     } else {       answer -= ((Size[B] * (Size[B] - 1)) / 2);       answer -= ((Size[A] * (Size[A] - 1)) / 2);       Size[B] += Size[A];       Size[A] = 0;       parent[A] = B;       answer += ((Size[B] * (Size[B] - 1)) / 2);     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long N, Q, p, q, r;     cin >> N >> Q;     if (N == 1) {       for (long long i = 1; i <= Q; i++) cout <<  0  ;       return 0;     }     for (long long i = 1; i <= N; i++) parent[i] = i;     vector<pair<long long, pair<long long, long long>>> G;     for (long long i = 1; i < N; i++) {       cin >> p >> q >> r;       G.push_back({r, {p, q}});     }     sort(G.begin(), G.end());     vector<long long> final_ans(N + 1);     long long ptr = 0;     for (long long i = 1; i <= N;) {       if (G[ptr].first == i) {         add_edge(G[ptr].second.first, G[ptr].second.second);         ptr++;       } else {         final_ans[i] = answer;         i++;       }     }     while (Q--) {       long long k;       cin >> k;       cout << final_ans[k] <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     map<long long, long long> isolados;     long long n, k, i, j, prox, qtd, x, resp;     bool first = true;     while (cin >> n >> k) {       resp = 0;       isolados.clear();       prox = -1;       first = true;       for (i = 0; i < k; i++) {         cin >> qtd;         for (j = 0; j < qtd; j++) {           cin >> x;           if (x == 1) prox = 1;           if (x == prox && first == true) {             prox++;           } else if (j == 0) {             isolados[x] = 0;           } else {             isolados[x] = 1;           }         }         if (prox != -1) first = false;       }       for (prox; prox <= n; prox++) {         resp += isolados[prox] + 1;       }       cout << resp << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, sti[101], i, x, ans;     cin >> n;     memset(sti, 0, sizeof(sti));     for (i = 1; i <= n; i++) {       cin >> x;       sti[x]++;     }     ans = 0;     for (i = 1; i <= 100; i++) {       ans += 2 * (sti[i] / 4);       sti[i] %= 4;       ans += sti[i] / 2;     }     cout << ans / 2 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   double a[4010];   int main() {     cin >> n;     n *= 2;     for (int i = 1; i <= n; ++i) cin >> a[i];     for (int i = 1; i <= n; ++i) a[i] = a[i] - int(a[i]);     int cnt = 0;     for (int i = 1; i <= n; ++i)       if (abs(a[i] - 0) <= 0.0000001) cnt++;     double sum = 0;     for (int i = 1; i <= n; ++i) sum += a[i];     double res = 1000000001;     for (int i = 0; i <= cnt; ++i) res = min(res, abs(n / 2 - sum - i));     printf( %.3f , res);   }


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


#include <bits/stdc++.h>   using namespace std;   long long solve(long long a, long long b, long long c) {     long long a1 = a - c;     a1 *= a1;     long long b1 = c - b;     b1 *= b1;     long long c1 = b - a;     c1 *= c1;     return a1 + b1 + c1;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int t;     t = 1;     cin >> t;     while (t--) {       long long a, b, c;       cin >> a >> b >> c;       vector<long long> arr(a, 0), arr1(b, 0), arr2(c, 0);       for (int i = 0; i < a; i++) {         cin >> arr[i];       }       for (int i = 0; i < b; i++) {         cin >> arr1[i];       }       for (int i = 0; i < c; i++) {         cin >> arr2[i];       }       sort((arr).begin(), (arr).end());       sort((arr1).begin(), (arr1).end());       sort((arr2).begin(), (arr2).end());       long long ans = 4 * (1e18);       vector<long long>::iterator it;       it = unique((arr).begin(), (arr).end());       arr.resize(distance(arr.begin(), it));       it = unique((arr1).begin(), (arr1).end());       arr1.resize(distance(arr1.begin(), it));       it = unique((arr2).begin(), (arr2).end());       arr2.resize(distance(arr2.begin(), it));       a = arr.size();       b = arr1.size();       c = arr2.size();       for (int i = 0; i < a; i++) {         long long in =             lower_bound((arr1).begin(), (arr1).end(), arr[i]) - arr1.begin();         vector<long long> a1;         vector<long long> b1;         if (in == b) {           a1.push_back(arr1[in - 1]);         } else {           a1.push_back(arr1[in]);           if (in < b - 1) {             a1.push_back(arr1[in + 1]);           }           if (in > 0) {             a1.push_back(arr1[in - 1]);           }         }         in = lower_bound((arr2).begin(), (arr2).end(), arr[i]) - arr2.begin();         if (in == c) {           b1.push_back(arr2[in - 1]);         } else {           b1.push_back(arr2[in]);           if (in < c - 1) {             b1.push_back(arr2[in + 1]);           }           if (in > 0) {             b1.push_back(arr2[in - 1]);           }         }         for (int j = 0; j < a1.size(); j++) {           for (int l = 0; l < b1.size(); l++) {             long long k = solve(arr[i], a1[j], b1[l]);             ans = min(k, ans);           }         }       }       for (int i = 0; i < b; i++) {         long long in =             lower_bound((arr).begin(), (arr).end(), arr1[i]) - arr.begin();         vector<long long> a1;         vector<long long> b1;         if (in == a) {           a1.push_back(arr[in - 1]);         } else {           a1.push_back(arr[in]);           if (in < a - 1) {             a1.push_back(arr[in + 1]);           }           if (in > 0) {             a1.push_back(arr[in - 1]);           }         }         in = lower_bound((arr2).begin(), (arr2).end(), arr1[i]) - arr2.begin();         if (in == c) {           b1.push_back(arr2[in - 1]);         } else {           b1.push_back(arr2[in]);           if (in < c - 1) {             b1.push_back(arr2[in + 1]);           }           if (in > 0) {             b1.push_back(arr2[in - 1]);           }         }         for (int j = 0; j < a1.size(); j++) {           for (int l = 0; l < b1.size(); l++) {             long long k = solve(arr1[i], a1[j], b1[l]);             ans = min(k, ans);           }         }       }       for (int i = 0; i < c; i++) {         long long in =             lower_bound((arr1).begin(), (arr1).end(), arr2[i]) - arr1.begin();         vector<long long> a1;         vector<long long> b1;         if (in == b) {           a1.push_back(arr1[in - 1]);         } else {           a1.push_back(arr1[in]);           if (in < b - 1) {             a1.push_back(arr1[in + 1]);           }           if (in > 0) {             a1.push_back(arr1[in - 1]);           }         }         in = lower_bound((arr).begin(), (arr).end(), arr2[i]) - arr.begin();         if (in == a) {           b1.push_back(arr[in - 1]);         } else {           b1.push_back(arr[in]);           if (in < a - 1) {             b1.push_back(arr[in + 1]);           }           if (in > 0) {             b1.push_back(arr[in - 1]);           }         }         for (int j = 0; j < a1.size(); j++) {           for (int l = 0; l < b1.size(); l++) {             long long k = solve(arr2[i], a1[j], b1[l]);             ans = min(k, ans);           }         }       }       cout << ans <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct group {     int sz;     vector<int> worst, best;     group(vector<int>& a)         : sz(1), worst(a.begin(), a.end()), best(a.begin(), a.end()) {}     bool operator<(const group& a) const {       for (int i = 0; i < best.size(); i++)         if (best[i] >= a.worst[i]) return false;       return true;     }     struct group& operator+=(const group& a) {       sz += a.sz;       for (int i = 0; i < best.size(); i++) {         best[i] = max(best[i], a.best[i]);         worst[i] = min(worst[i], a.worst[i]);       }       return *this;     }   };   set<group> positions;   int main() {     int n, k;     scanf( %d %d , &n, &k);     while (n--) {       vector<int> skills(k, 0);       for (int i = 0; i < k; i++) scanf( %d , &skills[i]);       group player = group(skills);       auto f = positions.lower_bound(player), l = positions.upper_bound(player);       while (f != l) {         player += *f;         f = positions.erase(f);       }       positions.insert(f, player);       printf( %d n , positions.rbegin()->sz);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e5 + 10, STAN = (1 << 30) - 1;   struct QJ {     int l, r, q;   } q[MAXN];   int n, m;   struct Seg {     int water[MAXN * 4], sh[MAXN * 4];     bool fir[MAXN * 4];     Seg() {       memset(water, 0, sizeof(water));       memset(fir, 0, sizeof(fir));     }     int _st, _ed, _x, _t;     void _insert(int num, int l, int r) {       if (_st <= l && r <= _ed) {         water[num] |= _x;         return;       }       int mid = (l + r) >> 1;       if (_st <= mid) _insert(num << 1, l, mid);       if (_ed >= mid + 1) _insert(num << 1 | 1, mid + 1, r);     }     int _swim(int num, int l, int r, int now) {       int x;       now |= water[num];       if (l == r) {         if (!fir[num]) {           sh[num] = now;           fir[num] = true;         } else           sh[num] &= now;         return now;       }       int mid = (l + r) >> 1;       if (_t <= mid)         now = _swim(num << 1, l, mid, now);       else         now = _swim(num << 1 | 1, mid + 1, r, now);       if (!fir[num]) {         sh[num] = now;         fir[num] = true;       } else         sh[num] &= now;       return now;     }     int _check(int num, int l, int r) {       if (l == r) return sh[num];       if (_st <= l && r <= _ed) return sh[num];       int mid = (l + r) >> 1;       int ans = STAN;       if (_st <= mid) ans &= _check(num << 1, l, mid);       if (_ed >= mid + 1) ans &= _check(num << 1 | 1, mid + 1, r);       return ans;     }     inline void Insert(int l, int r, int q) {       _st = l, _ed = r, _x = q;       _insert(1, 1, n);     }     inline int Swim(int t) {       _t = t;       return _swim(1, 1, n, 0);     }     inline bool Check(int l, int r, int q) {       _st = l;       _ed = r;       return _check(1, 1, n) == q;     }   } T;   int a[MAXN];   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= m; i++) {       scanf( %d%d%d , &q[i].l, &q[i].r, &q[i].q);       T.Insert(q[i].l, q[i].r, q[i].q);     }     for (int i = 1; i <= n; i++) a[i] = T.Swim(i);     for (int i = 1; i <= m; i++)       if (!T.Check(q[i].l, q[i].r, q[i].q)) {         printf( NO n );         return 0;       }     printf( YES n );     for (int i = 1; i <= n; i++) printf( %d  , a[i]);     printf(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   pair<int, int> a[5003];   vector<int> color[5003];   int ans[5003];   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n, k, i, j;     cin >> n >> k;     for (i = 0; i < n; i++) {       cin >> a[i].first;       a[i].second = i;     }     sort(a, a + n);     for (i = 0; i < n; i++) {       color[i % k].push_back(a[i].first);       ans[a[i].second] = (i % k);     }     for (i = 0; i < k; i++) {       for (j = 1; j < color[i].size(); j++) {         if (color[i][j] == color[i][j - 1]) {           cout <<  NO ;           return 0;         }       }     }     cout <<  YES n ;     for (i = 0; i < n; i++) {       cout << (ans[i] + 1) <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void enable_comma() {}   string tostring(char c) {     string s =   ;     s += c;     return s;   }   string tostring(string s) { return     + s +    ; }   string tostring(const char *c) { return tostring((string)c); }   string tostring(long long x) {     if (x < 0) return  -  + tostring(-x);     if (x > 9)       return tostring(x / 10) + tostring(char( 0  + x % 10));     else       return tostring(char( 0  + x));   }   string tostring(int x) { return tostring((long long)x); }   string tostring(unsigned long long x) {     if (x > 9)       return tostring((long long)(x / 10)) + tostring(char( 0  + x % 10));     else       return tostring(char( 0  + x));   }   string tostring(unsigned x) { return tostring((long long)x); }   string tostring(double x) {     static char res[114];     sprintf(res,  %lf , x);     string s = tostring(res);     return s.substr(1, (int)s.size() - 2);   }   string tostring(long double x) { return tostring((double)x); }   template <class A, class B>   string tostring(pair<A, B> p) {     return  (  + tostring(p.first) +  ,  + tostring(p.second) +  ) ;   }   template <class T>   string tostring(T v) {     string res =   ;     for (auto p : v) res += (res.size() ?  ,  :  { ) + tostring(p);     return res.size() ? res +  }  :  {} ;   }   template <class A>   string tostring(A *a, int L, int R) {     return tostring(vector<A>(a + L, a + R + 1));   };   template <class A>   string tostring(A a, int L, int R) {     return tostring(a.data(), L, R);   }   string tostrings() { return   ; }   template <typename Head, typename... Tail>   string tostrings(Head H, Tail... T) {     return tostring(H) +     + tostrings(T...);   }   long long read() {     long long x = 0, f = 0;     char ch = getchar();     while (!isdigit(ch)) f = ch ==  - , ch = getchar();     while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();     return f ? -x : x;   }   template <class T>   void ckmax(T &x, const T y) {     if (x < y) x = y;   }   template <class T>   void ckmin(T &x, const T y) {     if (x > y) x = y;   }   const int N = 100005;   struct op {     int tp;     long long a, b;   };   vector<op> res;   int a[60];   set<long long> S;   long long gao(int tp, long long a, long long b) {     (!(S.count(a) && S.count(b)) ? cout <<  Assertion failed!  << endl                                         <<  function:   << __FUNCTION__ << endl                                         <<  line:   << 149 << endl                                         <<  expression:                                           <<  S.count(a) && S.count(b)  << endl,      exit(3), 0 : 1);     res.push_back({tp, a, b});     long long res = tp ? a ^ b : a + b;     S.insert(res);     (!(0 <= res && res <= 5000000000000000000LL)      ? cout <<  Assertion failed!  << endl             <<  function:   << __FUNCTION__ << endl             <<  line:   << 153 << endl             <<  expression:               <<  0 <= res && res <= 5000000000000000000LL  << endl,      exit(3), 0 : 1);     return res;   }   int Log(long long x) {     int ans = 0;     while (x > 1) {       ans++;       x >>= 1;     }     return ans;   }   int main() {     long long x = read();     srand(time(NULL));     S.clear();     res.clear();     S.insert(x);     while (x > 1) {       vector<long long> v = {x};       while (1) {         int p = (int)v.size() - 1;         while (p > 0 && rand() % 5 != 0) p--;         long long a = v.back(), b = gao(0, a, a), c = gao(0, v[p], b);         if (Log(b) != Log(c)) {           v.push_back(c);           continue;         } else {           long long t = b ^ c;           for (int i = ((int)v.size() - 1); i >= (0); i--) {             if (Log(t) == Log(v[i] * 2)) t ^= v[i] * 2;             if (Log(t) == Log(v[i])) t ^= v[i];           }           if (~t & 1) {             v.push_back(c);             continue;           }           t = gao(1, b, c);           for (int i = ((int)v.size() - 1); i >= (0); i--) {             if (Log(t) == Log(v[i] * 2)) t = gao(1, t, v[i] * 2);             if (Log(t) == Log(v[i])) t = gao(1, t, v[i]);           }           (!(Log(t) < Log(x)) ? cout <<  Assertion failed!  << endl                                      <<  function:   << __FUNCTION__ << endl                                      <<  line:   << 198 << endl                                      <<  expression:                                        <<  Log(t) < Log(x)  << endl,            exit(3), 0 : 1);           x = t;           break;         }       }     }     printf( %d n , (int)res.size());     for (auto v : res) printf( %I64d %c %I64d n , v.a,  +^ [v.tp], v.b);     return 0;   }


#include <bits/stdc++.h>   #pragma GCC target( avx2 )   #pragma GCC optimization( O3 )   #pragma GCC optimization( unroll-loops )   using namespace std;   const long long N = 1e5 + 10;   const long double Pie = acos(-1);   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long t;     cin >> t;     while (t--) {       long long n;       cin >> n;       long long arr[n];       for (long long i = 0; i < n; i++) cin >> arr[i];       for (long long i = 0; i < n; i++) {         if (i % 2 == 0) {           if (arr[i] >= 0)             cout << arr[i] <<    ;           else             cout << -1 * arr[i] <<    ;         } else if (i % 2 == 1) {           if (arr[i] <= 0)             cout << arr[i] <<    ;           else             cout << -1 * arr[i] <<    ;         }       }       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   const int maxn = 200005;   vector<int> g[maxn];   int dis[maxn];   int pa[maxn];   set<pair<int, int>> st;   void dfs(int now, int pre = 0) {     if (dis[now] > 2) {       st.insert({dis[now], now});     }     for (auto &i : g[now]) {       if (i ^ pre) {         pa[i] = now;         dis[i] = dis[now] + 1;         dfs(i, now);       }     }   }   void go() {     int n;     cin >> n;     for (int i = 0; i < n - 1; i++) {       int x, y;       cin >> x >> y;       g[x].push_back(y);       g[y].push_back(x);     }     dfs(1);     int ans = 0;     while (st.size()) {       auto x = *(--st.end());       int v = pa[x.second];       st.erase({dis[v], v});       for (auto &i : g[v]) {         st.erase({dis[i], i});       }       ans++;     }     cout << ans <<   n ;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int c = 0;     int t;     if (!c) {       t = 1;     } else {       cin >> t;     }     while (t--) {       go();     }   }


#include <bits/stdc++.h>   using namespace std;   long long int newarr[1005];   long long int dp[1005][1005];   long long int n, k;   long long int solution(long long int index, long long int m) {     if (m < 0) m += k;     if (index >= n && m != 0)       return 0;     else if (m == 0)       return 1;     else if (dp[index][m] != -1)       return dp[index][m];     else {       long long int x = solution(index + 1, m);       long long int y = solution(index + 1, m - newarr[index]);       if (x > 0) x = 1;       if (y > 0) y = 1;       if (m >= newarr[index]) {         dp[index + 1][m - newarr[index]] = y;       }       dp[index + 1][m] = x;       return x + y;     }   }   int32_t main() {     memset(dp, -1, sizeof(dp));     cin >> n;     cin >> k;     long long int arr[n];     long long int ctr = 0;     for (long long int i = 0; i < n; i++) {       cin >> arr[i];     }     if (n > k) {       cout <<  YES n ;     } else {       for (long long int i = 0; i < n; i++) {         newarr[i] = arr[i] % k;         if (newarr[i] == 0) ctr++;       }       long long int x = solution(0, k);       if (x > 0 || ctr > 0)         cout <<  YES n ;       else         cout <<  NO ;     }   }


#include <bits/stdc++.h>   using namespace std;   typedef long long lo;   typedef vector<lo> vl;   typedef vector<lo> vll;   typedef vector<vl> vvl;   template <typename T>   ostream &operator<<(ostream &o, vector<T> v) {     if (v.size() > 0) o << v[0];     for (unsigned i = 1; i < v.size(); i++) o <<     << v[i];     return o <<   n ;   }   template <typename U, typename V>   ostream &operator<<(ostream &o, pair<U, V> p) {     return o <<  (  << p.first <<  ,   << p.second <<  )  ;   }   template <typename T>   istream &operator>>(istream &in, vector<T> &v) {     for (unsigned i = 0; i < v.size(); i++) in >> v[i];     return in;   }   template <typename T>   istream &operator>>(istream &in, pair<T, T> &p) {     in >> p.first;     in >> p.second;     return in;   }   string s;   lo len[203][2];   lo dp[203][203][203][2];   lo cal(string &t) {     for (lo i = t.size(); i > 0; i--) {       if (s.substr(0, i) == t.substr(t.size() - i, i)) return i;     }     return 0;   }   void add(lo &a, lo b) {     a += b;     if (a >= 1000000007) a -= 1000000007;     if (a < 0) a += 1000000007;   }   int main() {     std::ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cout.precision(20);     lo n, ssz;     cin >> n >> s;     ssz = s.size();     if (s[0] ==  ( )       len[0][0] = 1;     else       len[0][1] = 1;     string pref;     for (lo i = (0); i < (lo)ssz; i++) {       pref += s[i];       pref +=  ( ;       len[i + 1][0] = cal(pref);       pref.pop_back();       pref +=  ) ;       len[i + 1][1] = cal(pref);       pref.pop_back();     }     dp[0][0][0][0] = 1;     for (lo i = (0); i < (lo)2 * n; i++) {       for (lo(j) = 0; (j) < (n + 1); (j)++) {         for (lo(pos) = 0; (pos) < (ssz + 1); (pos)++) {           for (lo(f) = 0; (f) < (2); (f)++) {             if (dp[i][j][pos][f] == 0) continue;             if (j + 1 <= n)               add(dp[i + 1][j + 1][len[pos][0]][f | (len[pos][0] == ssz)],                   dp[i][j][pos][f]);             if (j > 0)               add(dp[i + 1][j - 1][len[pos][1]][f | (len[pos][1] == ssz)],                   dp[i][j][pos][f]);           }         }       }     }     lo ans = 0;     for (lo i = (0); i < (lo)ssz + 1; i++) add(ans, dp[2 * n][0][i][1]);     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline void checkMax(T& a, const T& b) {     if (a < b) a = b;   }   template <typename T>   inline void checkMin(T& a, const T& b) {     if (a > b) a = b;   }   const int kMod = 1000000007;   template <typename U, typename V>   inline void addMod(U& x, const V y) {     x += y;     if (x >= kMod) {       x -= kMod;     }   }   template <int N>   struct CombinationTable {     CombinationTable() { init(); }     static long long table[N + 1][N + 1];     static void init() {       table[0][0] = 1;       for (int i = 1; i <= N; ++i) {         table[i][0] = table[i][i] = 1;         for (int j = 1; j < i; ++j) {           table[i][j] = table[i - 1][j] + table[i - 1][j - 1];         }       }     }   };   template <int N>   long long CombinationTable<N>::table[N + 1][N + 1];   CombinationTable<40> comb_tbl;   long long n, t;   void go() {     if ((t & -t) != t) {       puts( 0 );       return;     }     ++n;     int tt = 1;     while (t >>= 1) ++tt;     int num_one;     long long tmp = n;     do {       num_one += (tmp & 1);     } while (tmp >>= 1);     long long ans = (tt == num_one);     for (int n___LINE__ = (50), i = 0; i < n___LINE__; ++i) {       if (n & 1) {         --num_one;         if (num_one <= tt && i >= 0 && tt >= num_one && tt - num_one <= i) {           ans += comb_tbl.table[i][tt - num_one];         }       }       n >>= 1;     }     if (tt == 1) --ans;     cout << ans << endl;   }   int main() {     cin >> n >> t;     go();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename S, typename T>   ostream& operator<<(ostream& out, const pair<S, T> p) {     out <<  (  << p.first <<  ,  << p.second <<  ) ;     return out;   }   template <typename T>   ostream& operator<<(ostream& out, const vector<T>& v) {     for (auto a : v) out << a <<    ;     return out;   }   template <typename T>   ostream& operator<<(ostream& out, const set<T>& S) {     for (auto a : S) cout << a <<    ;     return out;   }   template <typename T>   ostream& operator<<(ostream& out, const multiset<T>& S) {     for (auto a : S) cout << a <<    ;     return out;   }   template <typename S, typename T>   ostream& operator<<(ostream& out, const map<S, T>& M) {     for (auto m : M) cout <<  (  << m.first <<  ->  << m.second <<  )  ;     return out;   }   template <typename S, typename T>   pair<S, T> operator+(pair<S, T> a, pair<S, T> b) {     return make_pair(a.first + b.first, a.second + b.second);   }   template <typename S, typename T>   pair<S, T> operator-(pair<S, T> a, pair<S, T> b) {     return make_pair(a.first - b.first, a.second - b.second);   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int n;     cin >> n;     cout << n + n / 2 << endl;     return 0;   }


#include <bits/stdc++.h>   inline long long rd() {     long long _x = 0;     int _ch = getchar(), _f = 1;     for (; !isdigit(_ch) && (_ch !=  - ) && (_ch != EOF); _ch = getchar())       ;     if (_ch ==  - ) {       _f = 0;       _ch = getchar();     }     for (; isdigit(_ch); _ch = getchar()) _x = _x * 10 + _ch -  0 ;     return _f ? _x : -_x;   }   void write(long long _x) {     if (_x >= 10)       write(_x / 10), putchar(_x % 10 +  0 );     else       putchar(_x +  0 );   }   inline void wrt(long long _x, char _p) {     if (_x < 0) putchar( - ), _x = -_x;     write(_x);     if (_p) putchar(_p);   }   int n, m;   char s[1005][1005];   bool flag1, flag2;   bool vis[1005][1005];   void dfs(int x, int y) {     if (vis[x][y] || s[x][y] !=  #  || x == 0 || y == 0 || x == n + 1 ||         y == m + 1)       return;     vis[x][y] = 1;     dfs(x + 1, y), dfs(x, y + 1);     dfs(x - 1, y), dfs(x, y - 1);   }   int main() {     n = rd(), m = rd();     for (int i = 1; i <= n; i++) {       scanf( %s , s[i] + 1);     }     for (int i = 1; i <= n; i++) {       bool tag = 0;       for (int j = 1; j <= m; j++) {         if (s[i][j] ==  # ) tag = 1;       }       flag1 |= !tag;     }     for (int i = 1; i <= m; i++) {       bool tag = 0;       for (int j = 1; j <= n; j++) {         if (s[j][i] ==  # ) tag = 1;       }       flag2 |= !tag;     }     if (((!flag1) && (flag2)) || ((flag1) && (!flag2))) {       printf( -1 n );       return 0;     }     bool flag = 0;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         if (s[i][j] ==  # ) {           int t = j;           while (s[i][t] ==  # ) t++;           for (int k = t; k <= m; k++)             if (s[i][k] ==  # ) flag = 1;         }       }     }     for (int i = 1; i <= m; i++) {       for (int j = 1; j <= n; j++) {         if (s[j][i] ==  # ) {           int t = j;           while (s[t][i] ==  # ) t++;           for (int k = t; k <= n; k++)             if (s[k][i] ==  # ) flag = 1;         }       }     }     if (flag) {       printf( -1 n );       return 0;     }     int cnt = 0;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++)         if (s[i][j] ==  #  && !vis[i][j]) {           dfs(i, j);           cnt++;         }     }     wrt(cnt,   n );   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t, n, a[1000], d;     cin >> t;     while (t--) {       cin >> n;       for (int i = 0; i < n; i++) {         cin >> a[i];       }       sort(a, a + n);       d = 0;       for (int i = 1; i < n; i++) {         if (a[i] - a[i - 1] <= 1) {           d++;         }       }       if (d)         cout << 2 << endl;       else         cout << 1 << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   int p[100];   char mm[100];   int main() {     while (scanf( %d , &n) != EOF) {       scanf( %s , &mm);       int len = strlen(mm);       m = 0;       for (int i = 0; i < len; ++i) m = m * 10 + (mm[i] -  0 );       if (n == 0) {         if (strlen(mm) != 1)           puts( WRONG_ANSWER );         else if (m == 0)           puts( OK );         else           puts( WRONG_ANSWER );       } else {         if (mm[0] ==  0 ) {           puts( WRONG_ANSWER );           return 0;         }         int x = n;         memset(p, 0, sizeof(p));         while (x > 0) {           p[x % 10]++;           x /= 10;         }         int now = 0;         for (int i = 1; i <= 9; ++i)           if (p[i]) {             now = i;             p[i]--;             break;           }         for (int i = 0; i <= 9; ++i) {           while (p[i]) {             now = now * 10 + i;             p[i]--;           }         }         if (now == m)           puts( OK );         else           puts( WRONG_ANSWER );       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MX_N = 3e5 + 5;   const int MX_M = 3e5 + 5;   int N, M, D[MX_N];   vector<pair<int, int>> al[MX_N];   int vis[MX_N], sumD;   vector<int> edges;   void dfs(int u, int p = 0, int pe = 0) {     vis[u] = 1;     for (auto v : al[u])       if (!vis[v.first]) {         dfs(v.first, u, v.second);       }     if (D[u]) edges.push_back(pe), D[p] ^= 1;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cin >> N >> M;     for (int i = (1); i <= (N); ++i) {       cin >> D[i];       if (D[i] >= 0) sumD += D[i];     }     for (int i = (1); i <= (M); ++i) {       int U, V;       cin >> U >> V;       al[U].emplace_back(V, i);       al[V].emplace_back(U, i);     }     for (int i = (1); i <= (N); ++i)       if (D[i] == -1) {         if (sumD & 1)           D[i] = 1, ++sumD;         else           D[i] = 0;       }     if (sumD & 1)       cout << -1;     else {       dfs(1);       cout << ((int)(edges).size()) <<   n ;       sort(edges.begin(), edges.end());       for (int& e : edges) cout << e <<    ;     }   }


#include <bits/stdc++.h>   long long RemoveZeros(long long a) {     long long temp;     long long x = 0;     long long i = 10;     while (a > 0) {       if (a % 10 != 0) {         temp = (a % 10) * i;         x += temp;         i *= 10;       }       a /= 10;     }     return x / 10;   }   using namespace std;   int main() {     long long a, b, c;     cin >> a >> b;     c = a + b;     long long a1 = RemoveZeros(a);     long long b1 = RemoveZeros(b);     long long c1 = RemoveZeros(c);     if (a1 + b1 == c1)       cout <<  YES ;     else       cout <<  NO ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using li = long long;   using ld = long double;   using pii = pair<int, int>;   const int INF = 1e9 + 13;   const int N = 2e5 + 13;   const int M = 1e9 + 7;   const int B = 600;   const int A = 256;   const ld e = 1e-8;   const int LOGN = 20;   mt19937 rnd(time(0));   void solve() {     int n, m;     cin >> n >> m;     vector<bool> a(n, false);     for (int i = 0; i < m; i++) {       int x, y, z;       cin >> x >> y >> z;       y--;       a[y] = true;     }     int v = -1;     for (int i = 0; i < n; i++)       if (!a[i]) v = i;     for (int i = 0; i < n; i++) {       if (i != v) cout << v + 1 <<     << i + 1 <<   n ;     }   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int t = 1;     cin >> t;     while (t--) solve();   }


#include <bits/stdc++.h>   #pragma GCC optimize  03    using namespace std;   const int N = 1e5 + 5;   const int mod = 1e9 + 7;   const int inf = 1e9 + 9;   pair<int, int> ans[1004];   signed main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     string s;     cin >> s;     int c1 = 0, c2 = 0;     for (int i = 0; i < s.length(); i++) {       if (s[i] ==  0 ) {         if (c1 == 0) {           c1 = 1;           ans[i].first = 3, ans[i].second = 1;         } else {           c1 = 0;           ans[i].first = 1, ans[i].second = 1;         }       } else {         if (c2 == 0) {           c2 = 1;           ans[i].first = 1, ans[i].second = 3;         } else {           c2 = 0;           ans[i].first = 1, ans[i].second = 1;         }       }     }     for (int i = 0; i < s.length(); i++)       cout << ans[i].first <<     << ans[i].second <<   n ;     return 0;   }


#include <bits/stdc++.h>   const int MAX_N = 1e5 + 5;   int n, m;   char str[MAX_N], nxt[256];   bool chk[256], vis[256], not_root[256], flag;   std::vector<char> ans;   void dfs(char c) {     if (!vis[c]) {       vis[c] = true;       ans.push_back(c);       if (nxt[c]) dfs(nxt[c]);     } else       flag = true;   }   int main() {     scanf( %d , &n);     while (n--) {       scanf(  %s , str);       m = strlen(str);       for (int i = 0; i < m; ++i) chk[str[i]] = true;       for (int i = 0; i + 1 < m; ++i) {         if (nxt[str[i]] == 0)           nxt[str[i]] = str[i + 1];         else if (nxt[str[i]] != str[i + 1]) {           printf( NO n );           return 0;         }         not_root[str[i + 1]] = true;       }     }     for (char i =  a ; i <=  z ; ++i)       if (!not_root[i] && chk[i]) dfs(i);     for (char i =  a ; i <=  z ; ++i) flag |= chk[i] != vis[i];     if (flag) {       printf( NO n );       return 0;     }     for (char c : ans) printf( %c , c);     printf(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct S {     int a, b;     S() {}     S(int _a, int _b) {       a = _a;       b = _b;     }     const bool operator<(const S &o) const { return a < o.a; }   };   string exm;   inline void exf(void) {     cout << exm <<   n ;     exit(0);   }   template <typename T>   inline void showAll(vector<T> &v, string sep =   ) {     for (T &here : v) cout << here << sep;   }   template <typename T>   inline void showAll(T arr[], int st, int end, string sep =   ) {     for (int i = st; i <= end; i++) cout << arr[i] << sep;   }   template <typename T>   inline vector<int> int_seperation(T N, int d = 10) {     vector<int> v;     while (N) {       v.push_back(N % d);       N /= d;     }     reverse(v.begin(), v.end());     return v;   }   const int SIZE = 500009;   char s[SIZE], t[SIZE];   int main() {     int n, k;     scanf( %d %d , &n, &k);     scanf( %s %s , s + 1, t + 1);     long long INF = 1e18, ans = 0, diff = 0;     for (int i = 1; i <= n; i++) {       diff = 2 * diff + (t[i] - s[i]);       diff = min(diff, INF);       ans += min(diff + 1, (long long)k);     }     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void qmax(int &x, int y) {     if (x < y) x = y;   }   void qmin(int &x, int y) {     if (x > y) x = y;   }   inline long long read() {     char s;     long long k = 0, base = 1;     while ((s = getchar()) !=  -  && s != EOF && !(isdigit(s)))       ;     if (s == EOF) exit(0);     if (s ==  - ) base = -1, s = getchar();     while (isdigit(s)) {       k = k * 10 + (s ^  0 );       s = getchar();     }     return k * base;   }   inline void write(int x) {     static char cnt, num[15];     cnt = 0;     if (!x) {       printf( 0 );       return;     }     for (; x; x /= 10) num[++cnt] = x % 10;     for (; cnt; putchar(num[cnt--] + 48))       ;   }   const int maxn = 2020;   int n, k;   char ch[maxn][maxn];   int a[maxn][maxn], Max;   char d[maxn + maxn];   bool vis[maxn][maxn];   int main() {     n = read();     k = read();     for (int i = 1; i <= n; i++) {       scanf( %s , ch[i] + 1);     }     if (k >= (2 * n - 1)) {       for (int i = 1; i <= n + n - 1; i++) putchar( a );       return 0;     }     memset(a, 0x3f3f, sizeof(a));     a[1][1] = 1;     if (ch[1][1] ==  a ) a[1][1] = 0;     for (int l = 2; l <= n + n; l++) {       for (int i = 1, j; i <= n; i++) {         j = l - i;         if (j <= 0) break;         if (j > n) continue;         if (i > n) continue;         if (j + 1 <= n) qmin(a[i][j + 1], a[i][j] + (ch[i][j + 1] !=  a ));         if (i + 1 <= n) qmin(a[i + 1][j], a[i][j] + (ch[i + 1][j] !=  a ));         if (a[i][j] <= k) Max = max(Max, l);       }     }     if (Max == n + n) {       for (int i = 1; i <= n + n - 1; i++) putchar( a );       return 0;     }     bool flag = false;     if (!Max) Max = 2, vis[1][1] = true, d[2] = ch[1][1], flag = true;     for (int i = 1, j; i <= n; i++) {       j = Max - i;       if (j <= 0) break;       if (j > n) continue;       if (a[i][j] <= k) vis[i][j] = true;     }     for (int l = Max; l <= n + n; l++) {       char z =  z ;       for (int i = 1, j; i <= n; i++) {         j = l - i;         if (j <= 0) break;         if (j > n) continue;         if (!vis[i][j]) continue;         if (j + 1 <= n) z = min(z, ch[i][j + 1]);         if (i + 1 <= n) z = min(z, ch[i + 1][j]);       }       d[l + 1] = z;       for (int i = 1, j; i <= n; i++) {         j = l - i;         if (j <= 0) break;         if (j > n) continue;         if (!vis[i][j]) continue;         if (j + 1 <= n && ch[i][j + 1] == z) vis[i][j + 1] = true;         if (i + 1 <= n && ch[i + 1][j] == z) vis[i + 1][j] = true;       }     }     if (flag) Max--;     for (int i = 2; i <= Max; i++) d[i] =  a ;     for (int i = 2; i <= n + n; i++) {       putchar(d[i]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long read() {     long long a = 0;     char c = getchar();     while (c >  9  || c <  0 ) c = getchar();     while ( 0  <= c && c <=  9 ) {       a = a * 10 + c - 48;       c = getchar();     }     return a;   }   struct data {     long long x, y, c;     data(long long X = 0, long long Y = 0, long long C = 0) {       x = X;       y = Y;       c = C;     }   } w[2005], e[2005];   long long n, k, L;   bool cmp(data a, data b) { return a.x < b.x; };   bool cmp2(data a, data b) { return a.y < b.y; }   long long nxt[2005], f[2005];   multiset<long long> Set[2005];   long long sum[2005 << 2], Max[2005 << 2], tag[2005 << 2];   void pushup(long long x) {     sum[x] = (sum[(x << 1)] + sum[(x << 1 | 1)]) % 1000000007;     assert(Max[(x << 1)] <= Max[(x << 1 | 1)]);     Max[x] = Max[(x << 1 | 1)];   }   void build(long long x, long long l, long long r) {     tag[x] = 0;     if (l == r) {       sum[x] = f[l] * (e[l].y - e[l - 1].y) % 1000000007;       Max[x] = f[l];       return;     }     build((x << 1), l, ((l + r) >> 1));     build((x << 1 | 1), ((l + r) >> 1) + 1, r);     pushup(x);   }   void ptag(long long x, long long l, long long r, long long v) {     assert(Max[x] <= v);     sum[x] = v * (e[r].y - e[l - 1].y) % 1000000007;     tag[x] = Max[x] = v;   }   void pushdown(long long x, long long l, long long r) {     if (tag[x]) {       ptag((x << 1), l, ((l + r) >> 1), tag[x]);       ptag((x << 1 | 1), ((l + r) >> 1) + 1, r, tag[x]);       tag[x] = 0;     }   }   void chkmax(long long x, long long l, long long r, long long b, long long e,               long long v) {     if (r < b || l > e) return;     if (l == r && Max[x] > v) return;     if (Max[x] <= v && b <= l && r <= e) {       ptag(x, l, r, v);       return;     }     bool flag = (v > Max[(x << 1)]);     pushdown(x, l, r);     chkmax((x << 1), l, ((l + r) >> 1), b, e, v);     if (flag) chkmax((x << 1 | 1), ((l + r) >> 1) + 1, r, b, e, v);     pushup(x);   }   signed main() {     n = read();     k = read();     L = read();     for (long long i = 1; i <= n; ++i) {       w[i].x = read() + 1;       w[i].y = read() + 1;       w[i].c = read();       e[i] = w[i];     }     sort(w + 1, w + 1 + n, cmp);     sort(e + 1, e + 1 + n, cmp2);     e[n + 1].y = L + 1;     w[n + 1].x = w[n + 2].x = L + 1;     w[n + 1].y = L + 1;     long long ans = 0;     for (long long i = n; i; --i) {       long long tmp = (w[i].x - w[i - 1].x);       if (!tmp) continue;       multiset<long long> S;       S.clear();       for (long long i = 1; i <= k; ++i) {         S.insert(L + 1), nxt[i] = L + 1;         Set[i].clear();         Set[i].insert(L + 1);         Set[i].insert(0);       }       for (long long j = n; j; --j) {         if (e[j].x >= w[i].x) {           S.erase(S.find(nxt[e[j].c]));           nxt[e[j].c] = e[j].y;           S.insert(nxt[e[j].c]);           Set[e[j].c].insert(e[j].y);         }         f[j] = (*(--S.end()));       }       build(1, 1, n);       for (long long j = n + 1; j > i; --j) {         if (w[j].c) {           assert(Set[w[j].c].find(w[j].y) != Set[w[j].c].end());           Set[w[j].c].erase(Set[w[j].c].find(w[j].y));           multiset<long long>::iterator it = --Set[w[j].c].upper_bound(w[j].y),                                         ir = it;           ++ir;           long long ll = lower_bound(e, e + 1 + n, data(0, *it, 0), cmp2) - e;           if (ll) assert(e[ll].y != e[ll - 1].y);           chkmax(1, 1, n, ll + 1, n, *ir);         }         long long res = ((L + 1) * e[n].y - sum[1] + 1000000007) % 1000000007;         ans =             (ans + (res * tmp % 1000000007 * (w[j].x - w[j - 1].x))) % 1000000007;       }     }     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   #pragma GCC target( sse4 )   using namespace std;   using ii = pair<int, int>;   using ll = long long;   const int N = 1e5 + 5;   const int mod = 1e9 + 7;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int a, b;     cin >> a >> b;     vector<int> ans1, ans2;     ll limit = 0;     for (; limit * (limit + 1) / 2 <= a + b; limit++)       ;     cerr << limit <<   n ;     for (int i = --limit; i >= 1; i--) {       if (a >= b)         ans1.push_back(i), a -= i;       else         ans2.push_back(i), b -= i;     }     cout << ans1.size() <<   n ;     for (auto x : ans1) cout << x <<    ;     cout <<   n ;     cout << ans2.size() <<   n ;     for (auto x : ans2) cout << x <<    ;     cout <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 10;   int t;   int n;   struct node {     long long id, val;     bool flag;     friend bool operator<(node a, node b) {       if (a.val == b.val) return a.flag == false;       return a.val > b.val;     }   };   int main() {     while (~scanf( %d , &n)) {       priority_queue<node> q;       long long num;       scanf( %lld , &num);       node nxt;       nxt.id = 1, nxt.val = num, nxt.flag = false;       q.push(nxt);       long long ans = 0;       for (int i = 2; i <= n; ++i) {         scanf( %lld , &num);         nxt.flag = false;         if (q.top().val < num) {           node now = q.top();           q.pop();           ans = ans + num - now.val;           if (now.flag) {             now.flag = false;             q.push(now);           }           nxt.flag = true;         }         nxt.id = i;         nxt.val = num;         q.push(nxt);       }       printf( %lld n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7, inf = 1061109567;   const long long infll = 4557430888798830399;   const int N = 2e5 + 5;   int n, q, a[N], cnt[N];   bool last[N], first[N];   vector<int> app[N];   bool start[N];   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n >> q;     for (int i = 0; i < n; i++) cin >> a[i];     for (int i = 0; i < n; i++) app[a[i]].push_back(i);     for (int i = 0; i < N; i++)       if (app[i].size()) {         first[app[i][0]] = 1;         last[app[i].back()] = 1;       }     int thing = 0;     memset(start, 0, sizeof start);     start[0] = 1;     for (int i = 0; i < n; i++) {       if (first[i]) thing++;       if (last[i]) thing--;       if (!thing) start[i + 1] = 1;     }     int ans = 0;     int cur = 0;     while (cur < n) {       int nxt = n - 1;       for (int i = cur + 1; i < n; i++)         if (start[i]) {           nxt = i - 1;           break;         }       int lolMax = 0;       for (int i = cur; i < nxt + 1; i++) {         cnt[a[i]]++;         lolMax = max(lolMax, cnt[a[i]]);       }       ans += lolMax;       for (int i = cur; i < nxt + 1; i++) cnt[a[i]]--;       cur = nxt + 1;     }     cout << n - ans;     return 0;   }


#include <bits/stdc++.h>   const int MAXN = (int)1e5 + 5;   const int MODN = (int)1e9 + 7;   int inf = 0x3f3f3f3f;   using namespace std;   char str[MAXN];   int num[MAXN];   int a[MAXN];   int vis[MAXN];   int main() {     int n, m;     while (scanf( %d , &n) != EOF) {       memset(vis, 0, sizeof(vis));       int sum = 0;       for (int i = 0; i < n; i++) {         scanf( %d , &a[i]);         sum += a[i];       }       int it = sum * 2 / n;       for (int i = 0; i < n; i++) {         if (vis[i] == 0) {           vis[i] = 1;           printf( %d  , i + 1);           for (int j = 0; j < n; j++) {             if (vis[j] == 0 && a[j] + a[i] == it) {               vis[j] = 1;               printf( %d n , j + 1);               break;             }           }         }       }     }   }


#include <bits/stdc++.h>   using namespace std;   int cntinv(vector<int> &a) {     int n = a.size();     int ans = 0;     for (int i = 0; i < n; ++i) {       for (int j = i + 1; j < n; ++j) {         if (a[j] < a[i]) ans++;       }     }     return ans;   }   int main(int argc, char const *argv[]) {     int n;     scanf( %d , &n);     vector<int> a(n);     for (int i = 0; i < n; ++i) {       scanf( %d , &a[i]);     }     int pv = (cntinv(a) & 1);     int m;     scanf( %d , &m);     while (m--) {       int l, r, swaps;       scanf( %d , &l);       scanf( %d , &r);       l--;       r--;       swaps = (r - l + 1) >> 1;       int cur = pv;       if (swaps & 1) cur = 1 - cur;       if (cur)         printf( odd n );       else         printf( even n );       pv = cur;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   int a[100010], d[100010];   int main() {     int ans = 1, i, j;     int temp;     int dlen = 0, mx = 0;     while (~scanf( %d , &n)) {       for (i = 0; i != n; ++i) {         dlen = mx = 0;         scanf( %d , &temp);         for (j = 2; j * j <= temp; j++) {           if (temp % j == 0) {             d[dlen++] = j;             if (a[j] + 1 > mx) mx = a[j] + 1;             while (temp % j == 0) temp /= j;           }         }         if (temp > 1) {           d[dlen++] = temp;           if (a[temp] + 1 > mx) mx = a[temp] + 1;         }         for (j = 0; j != dlen; j++) a[d[j]] = mx;         if (ans < mx) ans = mx;       }       printf( %d n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct UF {     vector<int> par, sz;     UF(int n) {       sz.resize(n);       par.resize(n);       for (int i = 0; i < n; i++) sz[i] = 1, par[i] = i;     }     int find(int x) {       if (par[x] == x) return x;       return par[x] = find(par[x]);     }     void unite(int x, int y) {       x = find(x);       y = find(y);       if (x == y) return;       if (sz[x] > sz[y]) swap(x, y);       sz[y] += sz[x];       par[x] = y;     }     bool same(int x, int y) { return find(x) == find(y); }   };   int main() {     int i, j, n, m1, m2;     cin >> n >> m1 >> m2;     UF uf1(n), uf2(n);     for (i = 0; i < m1; i++) {       int a, b;       cin >> a >> b;       a--;       b--;       uf1.unite(a, b);     }     for (i = 0; i < m2; i++) {       int a, b;       cin >> a >> b;       a--;       b--;       uf2.unite(a, b);     }     vector<pair<int, int>> p;     for (i = 0; i < n; i++) {       for (j = 0; j < n; j++) {         if (!uf1.same(i, j)) p.push_back({i, j});       }     }     int ans = 0;     vector<pair<int, int>> ansv;     for (i = 0; i < p.size(); i++) {       int x = p[i].first, y = p[i].second;       if (!uf1.same(x, y) && !uf2.same(x, y)) {         uf1.unite(x, y);         uf2.unite(x, y);         ans++;         ansv.push_back({x, y});       }     }     cout << ans << endl;     for (auto p : ansv) cout << p.first + 1 <<     << p.second + 1 << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = (int)1e6 + 100;   const long long inf = (1ll << 60);   const int mod2 = (int)998244353;   const int mod = (int)1e9 + 7;   int n, m;   vector<long long> b;   vector<long long> c;   void add(long long x) {     for (int i = 0; i < b.size(); i++) {       if (c[i] & x) {         x ^= b[i];       }     }     if (x > 0) {       long long y = 1;       while (!(x & y)) y *= 2;       for (int i = 0; i < b.size(); i++) {         if (b[i] & y) {           b[i] ^= x;         }       }       b.push_back(x);       c.push_back(y);     }   }   long long d[maxn];   int u[maxn];   vector<pair<long long, long long> > g[maxn];   vector<int> ord;   void dfs(int v) {     u[v] = 1;     ord.push_back(v);     for (auto to : g[v]) {       if (u[to.first] == 0) {         d[to.first] = d[v] ^ to.second;         dfs(to.first);       } else if (u[to.first] == 1) {         add(d[v] ^ d[to.first] ^ to.second);       }     }     u[v] = 2;   }   void solve() {     cin >> n >> m;     for (int i = 0; i < m; i++) {       long long x, y, z;       cin >> x >> y >> z;       g[x].push_back({y, z});       g[y].push_back({x, z});     }     long long ans = 0;     for (int i = 1; i <= n; i++) {       if (u[i]) continue;       b.clear();       c.clear();       ord.clear();       dfs(i);       long long sz = ord.size();       long long C = sz * (sz - 1) / 2;       C %= mod;       for (int j = 1; j < b.size(); j++) C = (C * 2) % mod;       for (int j = 0; j <= 60; j++) {         int ok = 0;         long long cur = (1ll << j);         for (long long x : b) {           if (x & cur) {             ok = 1;           }         }         if (ok) {           ans = (ans + cur % mod * C % mod) % mod;         } else {           long long cnt = 0;           for (int v : ord) {             if (d[v] & cur) {               cnt++;             }           }           long long cur_ans = cnt * (sz - cnt) % mod;           cur_ans = (cur % mod * cur_ans) % mod;           for (int j = 0; j < b.size(); j++) {             cur_ans = (cur_ans * 2) % mod;           }           ans += cur_ans;           ans %= mod;         }       }     }     cout << ans <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int t = 1;     for (int i = 1; i <= t; i++) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline int read() {     int X = 0, w = 1;     char c = getchar();     while (c <  0  || c >  9 ) {       if (c ==  - ) w = -1;       c = getchar();     }     while (c >=  0  && c <=  9 ) X = X * 10 + c -  0 , c = getchar();     return X * w;   }   const int N = 1000 + 10;   int n, m, a[N];   double f[N][N];   int main() {     n = read(), m = read();     for (register int i = 1; i <= n; ++i) a[i] = read();     for (register int i = 1; i <= n; ++i)       for (register int j = 1; j <= n; ++j) f[i][j] = (a[i] > a[j]);     while (m--) {       int x = read(), y = read();       for (register int i = 1; i <= n; ++i) {         f[x][i] = f[y][i] = (f[x][i] + f[y][i]) / 2;         f[i][x] = f[i][y] = 1 - f[x][i];       }       f[x][y] = f[y][x] = 0.5;     }     double ans = 0;     for (register int i = 1; i <= n; ++i)       for (register int j = i + 1; j <= n; ++j) ans += f[i][j];     printf( %.9lf n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char orz[500001];   int gg[500001];   int t;   int main() {     cin >> t;     while (t--) {       int n, q;       scanf( %d%d , &n, &q);       scanf( %s , orz + 1);       int rrr = 1;       for (int i = 1; i <= n; i++) {         if (orz[i] ==  + )           gg[i] = gg[i - 1] + 1 * rrr;         else           gg[i] = gg[i - 1] - 1 * rrr;         rrr *= -1;       }       while (q--) {         int l, r;         scanf( %d%d , &l, &r);         int eee = abs(gg[r] - gg[l - 1]);         if (eee != 0) {           if (eee % 2 == 1) eee = 1;           if (eee % 2 == 0) eee = 2;         }         cout << eee << endl << endl;       }     }   }


#include <bits/stdc++.h>   using namespace std;   struct debugger {     template <typename T>     debugger& operator,(const T& v) {       cerr << v <<    ;       return *this;     }   } dbg;   void solve() {     int n, m;     cin >> n >> m;     for (int i = 0; i < 200; i++) cout <<  9 ;     cout << endl;     for (int i = 0; i < 200; i++) cout <<  9 ;     for (int i = 0; i < 199; i++) cout <<  0 ;     cout <<  1 ;   }   int main() {     ios_base::sync_with_stdio(false);     int t = 1, num = 1;     while (t--) {       ;       ;       solve();       ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   vector<vector<long long>> mul(vector<vector<long long>> A,                                 vector<vector<long long>> B) {     int n = A.size();     vector<vector<long long>> res(n, vector<long long>(n));     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         for (int k = 0; k < n; k++) {           res[i][j] = (res[i][j] + A[i][k] * B[k][j]) % MOD;         }       }     }     return res;   }   vector<vector<long long>> mexp(vector<vector<long long>> M, long long e) {     if (e == 1) return M;     if (e % 2) return mul(M, mexp(M, e - 1));     vector<vector<long long>> R = mexp(M, e / 2);     return mul(R, R);   }   int main() {     long long n, m;     cin >> n >> m;     if (m > n) {       cout << 1 << endl;       return 0;     }     vector<vector<long long>> M(m, vector<long long>(m));     M[0][0] = M[0][m - 1] = 1;     for (int i = 1; i < m; i++) M[i][i - 1] = 1;     vector<vector<long long>> R = mexp(M, n - m + 1);     long long res = 0;     for (int i = 0; i < m; i++) res = (res + R[0][i]) % MOD;     cout << res << endl;   }


#include <bits/stdc++.h>   using vi = std::vector<long long int>;   using vvi = std::vector<vi>;   using pii = std::pair<long long int, long long int>;   using vpii = std::vector<pii>;   using vvpii = std::vector<vpii>;   using namespace std;   const long long int N = 2e6 + 10;   const long long int inf = 1e18 + 10;   const long double Pi = 3.14159265;   long long int n;   vi a;   long long int f(vi &a) {     long long int n = a.size();     if (a.empty() == 1) return 0;     if (a.back() == 0) return a.size();     long long int hig = 0;     for (long long int i = 0; i <= n - 1; i++) {       hig = max(hig, (long long int)log2(a[i]));     }     vi l, r;     for (long long int i = 0; i <= n - 1; i++) {       if ((long long int)log2(a[i]) < hig)         l.emplace_back(a[i]);       else         r.emplace_back(a[i] ^ (1 << (long long int)log2(a[i])));     }     if (!(l.size() < r.size())) swap(l, r);     a = vi();     if (l.size() == 0) return f(r);     return 1 + max(f(l), f(r));   }   void solve() {     cin >> n;     a.resize(n);     for (long long int i = 1; i <= n; i++) cin >> a[i - 1];     sort(a.begin(), a.end());     cout << (a.size() - f(a));   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     solve();     return 0;     long long int xx = 0;     long long int t;     cin >> t;     while (t--) {       ;       solve();       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[111111], b[111111];   vector<int> id[111111];   int main() {     int N, M;     cin >> N >> M;     for (int i = 1; i <= N; i++) id[i].clear();     for (int i = 0; i < M; i++) scanf( %d , a + i);     long long tot = 0;     for (int i = 1; i < M; i++) {       if (a[i] == a[i - 1]) continue;       id[a[i]].push_back(a[i - 1]);       id[a[i - 1]].push_back(a[i]);       tot += abs(a[i] - a[i - 1]);     }     long long d = 0;     for (int i = 1; i <= N; i++) {       sort(id[i].begin(), id[i].end());       long long s = 0;       int k = id[i].size() / 2;       for (int j = 0; j < id[i].size(); j++)         s += abs(id[i][j] - id[i][k]) - abs(id[i][j] - i);       if (d > s) d = s;     }     cout << tot + d << endl;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 1e5 + 5;   vector<long long> tim(N), pos(N), cur(N);      int main() {       long long T, n, act, start, des, dir, ans, startTime;       cin>>T;       for(long long t = 1; t <= T; ++t) {           tim[0] = pos[0] = start = des = act = ans = startTime = 0;           cin>>n;           for(long long i = 1; i <= n; ++i) {               cin>>tim[i]>>pos[i];               if(tim[i] >= act) {                   cur[i] = des;                   startTime = tim[i];                   act = tim[i] + abs(des - pos[i]);                   start = des;                   des = pos[i];               } else {                   dir = (start <= des) ? 1 : -1;                   cur[i] = start + dir * (tim[i] - startTime);               }           }           cur[n+1] = des;           for(long long i = 1; i <= n; ++i) {               if(min(cur[i],cur[i+1]) <= pos[i] && pos[i] <= max(cur[i],cur[i+1])) {                   ans += 1;               }           }           cout<<ans<<endl;       }       return 0;   }


#include <bits/stdc++.h>   using namespace std;   int max_can;   pair<int, int> red, blue;   int main() {     scanf( %d%d%d%d%d , &max_can, &red.first, &blue.first, &red.second,           &blue.second);     long long ans = 0;     int sq = (int)sqrt(max_can);     if (red.second >= sq) {       for (int cnt = 0;; ++cnt) {         if (red.second * cnt > max_can) break;         int can = max_can - red.second * cnt;         ans = max(ans,                   cnt * 1ll * red.first + (can / blue.second) * 1ll * blue.first);       }       printf( %I64d n , ans);       return 0;     } else if (blue.second >= sq) {       for (int cnt = 0;; ++cnt) {         if (blue.second * cnt > max_can) break;         int can = max_can - blue.second * cnt;         ans = max(ans,                   cnt * 1ll * blue.first + (can / red.second) * 1ll * red.first);       }       printf( %I64d n , ans);       return 0;     } else {       if (red.first * 1ll * blue.second < blue.first * 1ll * red.second)         swap(red, blue);       for (int cnt = 0; cnt <= sq; ++cnt) {         int weight = blue.second * cnt;         if (weight > max_can) break;         int can = max_can - weight;         ans = max(ans,                   blue.first * 1ll * cnt + (can / red.second) * 1ll * red.first);       }       printf( %I64d n , ans);       return 0;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline long long read() {     long long x = 0, f = 0;     char ch = getchar();     while (!isdigit(ch)) f |= (ch ==  - ), ch = getchar();     while (isdigit(ch)) x = x * 10 + ch -  0 , ch = getchar();     return f ? -x : x;   }   inline void write(long long x) {     if (x < 0) x = -x, putchar( - );     if (x >= 10) write(x / 10);     putchar(x % 10 +  0 );   }   long long n, a[200005], tot[200005], tong[105], mx, mxat, now;   signed main() {     n = read();     for (register long long i = 1; i <= n; i++) {       a[i] = read();       now = a[i];       while (now && now % 2 == 0) {         tot[i]++;         now /= 2;       }       tong[tot[i]]++;       if (tong[tot[i]] > mx) mx = tong[tot[i]], mxat = tot[i];     }     write(n - mx);     puts(  );     for (register long long i = 1; i <= n; i++)       if (tot[i] != mxat) write(a[i]), putchar(   );     return 0;   }


#include <bits/stdc++.h>   int main() {     int loop, cnt = 1, max = 1;     scanf( %d , &loop);     int arr[loop];     for (int i = 0; i < loop; i++) scanf( %d , &arr[i]);     for (int i = 1; i < loop; i++) {       if (arr[i - 1] >= arr[i]) {         cnt = 1;       }       if (arr[i - 1] < arr[i]) {         cnt++;       }       if (max < cnt) max = cnt;     }     printf( %d , max);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   multiset<int> ms;   const int MAXN = 1000000;   int pos[MAXN], a[MAXN], b[MAXN], st[MAXN];   int n, i, j, k, ans;   int main() {     scanf( %d , &n);     for (i = 1; i <= n; ++i) {       scanf( %d , &a[i]);       pos[a[i]] = i;     }     for (j = 1; j <= n; ++j) {       scanf( %d , &b[j]);       int diff = j - pos[b[j]];       st[j] = diff;       ms.insert(diff);     }     for (i = 0; i < n; ++i) {       ans = n;       multiset<int>::iterator it = ms.lower_bound(i);       if (it != ms.end()) ans = min(ans, abs(*(it)-i));       if (it != ms.begin()) ans = min(ans, abs(*(--it) - i));       cout << ans << endl;       ms.erase(ms.find(st[i + 1]));       int num = b[i + 1];       ms.insert((i + n + 1) - pos[num]);     }   }