#include <bits/stdc++.h>   using namespace std;   struct segment {     int l, r;   };   segment s[1010];   int n, ans[1010], m, pi[1010], d[1010];   bool operator<(const segment &a, const segment &b) { return a.r < b.r; }   int main() {     int i, j;     cin >> n;     for (i = 1; i <= n; i++) {       cin >> s[i].l >> s[i].r;       if (s[i].l > s[i].r) swap(s[i].l, s[i].r);     }     sort(s + 1, s + n + 1);     s[0].r = s[0].l = -2147483647;     pi[0] = 0;     for (i = 1; i <= n; i++) {       j = i - 1;       while (pi[j] == m) {         if (s[j].r < s[i].l) {           d[i] = -1;           break;         }         j--;       }       if (d[i] == -1)         d[i] = d[i - 1] + 1, ans[++m] = s[i].r, pi[i] = m;       else         pi[i] = m, d[i] = d[i - 1];     }     printf( %d n , d[n]);     for (i = 1; i <= m; i++) printf( %d  , ans[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 4e5 + 10;   const int INF = 1e9;   map<int, int> cnt;   vector<int> ind[N];   vector<int> pos(N, 0);   int main() {     int n, k;     cin >> n >> k;     vector<int> a(n);     for (int i = 0; i < n; i++) {       cin >> a[i];       ind[a[i]].push_back(i);     }     for (int i = 0; i < n; i++) {       ind[a[i]].push_back(INF);     }     set<pair<int, int> > s;     set<int> inSet;     int result = 0;     for (int i = 0; i < n; i++) {       int cur = a[i];       pos[cur]++;       if (inSet.find(cur) != inSet.end()) {         s.erase(make_pair(ind[cur][pos[cur] - 1], cur));         s.insert(make_pair(ind[cur][pos[cur]], cur));         continue;       }       if (inSet.size() == k) {         inSet.erase((*s.rbegin()).second);         s.erase(*s.rbegin());       }       s.insert(make_pair(ind[cur][pos[cur]], cur));       inSet.insert(cur);       result++;     }     cout << result;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, a, b, c = 0;     cin >> n;     while (n) {       cin >> a >> b;       if (b > a + 1) c += 1;       n--;     }     cout << c;   }


#include <bits/stdc++.h>   using namespace std;   long long a[100001];   int main() {     long long n, s = 0, i, k, j;     string m;     cin >> n;     for (i = 1; i <= n; i++) {       cin >> m;       k = 0;       for (j = 0; j < n; j++)         if (m[j] ==  C ) k++, a[j + 1]++;       s += ((k - 1) * k) / 2;     }     for (i = 1; i <= n; i++) s += ((a[i] - 1) * a[i]) / 2;     cout << s;     return 0;   }


#include <bits/stdc++.h>   int dr[] = {2, 2, -2, -2, 1, -1, 1, -1};   int dc[] = {1, -1, 1, -1, 2, 2, -2, -2};   int dr1[] = {0, 0, 1, 1, 1, -1, -1, -1};   int dc1[] = {1, -1, 1, 0, -1, 0, 1, -1};   int dr2[] = {0, 0, 1, -1};   int dc2[] = {1, -1, 0, 0};   using namespace std;   long long sum(long long x) { return (x * (x + 1)) / 2; }   long long dp[500005], a[500005];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long i, j, c, x, len, tc, n, k;     cin >> tc;     while (tc--) {       cin >> n;       vector<pair<long long, long long> > v;       for (i = 1; i <= n; i++) {         long long x;         cin >> x;         a[i] = x;         v.push_back({x, i});       }       sort(v.begin(), v.end());       long long ans = -1;       if (v[0].first == v.back().first)         cout <<  -1  << endl;       else {         for (i = 1; i <= n; i++) {           if (a[i] == v.back().first) {             if (i > 1 && a[i - 1] != v.back().first) ans = i;             if (i < n && a[i + 1] != v.back().first) ans = i;           }         }         cout << ans << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       long long a, b, n, m;       cin >> a >> b >> n >> m;       if (m <= min(a, b) && n + m <= a + b)         cout <<  Yes  << endl;       else         cout <<  No  << endl;     }     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:20000000 )   using namespace std;   int ri() {     int x;     scanf( %d , &x);     return x;   }   long long rll() {     long long x;     scanf( %lld , &x);     return x;   }   void solve() {     long long x;     cin >> x;     set<pair<long long, long long> > result;     result.insert(make_pair(1, x));     result.insert(make_pair(x, 1));     long long tmp = 0;     for (long long k = 2;; k++) {       tmp += (k - 1) * (k - 1);       long long ost = x - tmp;       long long wtf = k * k * k - (k - 1) * k / 2 * k * 2;       if (ost < wtf) {         cerr << k << endl;         break;       }       ost *= 2LL;       if (ost % k == 0) {         ost /= k;         long long n = k;         long long t = ost + (k - 1) * n;         long long m = t / (2 * n - k + 1);         if (m * (2 * n - k + 1) == t) {           result.insert(make_pair(n, m)), result.insert(make_pair(m, n));         }       }     }     cout << result.size() << endl;     for (set<pair<long long, long long> >::iterator it = result.begin();          it != result.end(); it++)       cout << it->first <<     << it->second << endl;   }   int main() {     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s, t;     cin >> s >> t;     for (long i = s.size() - 1; i >= 0; i--) {       if (s[i] ==  z ) {         s[i] =  a ;       } else {         s[i]++;         break;       }     }     if (s == t) {       cout <<  No such string ;     } else {       cout << s;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   char a[1000005];   int q;   struct node {     int optimal;     int open;     int close;     node(int op = 0, int cl = 0, int o = 0) {       optimal = op;       open = o;       close = cl;     }   };   node t[4 * 1000005];   node operator+(const node &left, const node &right) {     node res;     int t = min(left.open, right.close);     res.optimal = left.optimal + right.optimal + t;     res.close = left.close + right.close - t;     res.open = left.open + right.open - t;     return res;   }   void update(int k, int l, int r) {     if (l == r) {       if (a[l] ==  ( )         t[k] = node(0, 1, 0);       else         t[k] = node(0, 0, 1);       return;     }     int m = (l + r) / 2;     update(k * 2, l, m);     update(k * 2 + 1, m + 1, r);     t[k] = t[k * 2 + 1] + t[k * 2];   }   node query(int k, int l, int r, int u, int v) {     if (v < l || u > r) return node(0, 0, 0);     if (u <= l && v >= r) {       return t[k];     }     int m = (l + r) / 2;     return (query(k * 2 + 1, m + 1, r, u, v) + query(k * 2, l, m, u, v));   }   int main() {     scanf( %s , a + 1);     n = strlen(a + 1);     update(1, 1, n);     scanf( %d , &q);     for (int i = 1; i <= q; i++) {       int u, v;       scanf( %d%d , &u, &v);       printf( %d n , query(1, 1, n, u, v).optimal * 2);     }   }


#include <bits/stdc++.h>   using namespace std;   long long mod = 1e9 + 7;   int maxn = 1e9, minn = -1e9;   long long modpow(long long base, long long exp, int modulus) {     base %= modulus;     long long result = 1;     while (exp > 0) {       if (exp & 1) result = (result * base) % modulus;       base = (base * base) % modulus;       exp >>= 1;     }     return result;   }   int sqr(int x) { return x * x; }   bool is_prime(int x) {     for (int i = 2; i * i <= x; ++i) {       if (x % i == 0) return false;     }     return true;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long x = 1234567, y = 123456, z = 1234;     int n;     scanf( %d , &n);     bool ans = false;     for (long long i = 0; i <= n; i += x) {       for (long long j = 0; j <= n; j += y) {         long long c = n - i - j;         if (c % z == 0 && c >= 0) ans = true;       }     }     if (ans)       cout <<  yes ;     else       cout <<  no ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn(1e5 + 5);   struct circle {     int a, b;     long long h;     circle(){};     circle(int x) : a(0), b(x), h(0) {}     inline void input() { cin >> a >> b >> h; }     bool operator<(const circle &t) const {       return b == t.b ? (a < t.a) : b < t.b;     }   } rings[maxn];   long long tree[maxn << 2];   void build(int p, int l, int r) {     if (l == r) {       tree[p] = rings[l].h;       return;     }     int mid = l + r >> 1;     build(p << 1, l, mid);     build(p << 1 | 1, mid + 1, r);     tree[p] = max(tree[p << 1], tree[p << 1 | 1]);   }   void update(int p, int l, int r, int x) {     if (l == r) {       tree[p] = rings[x].h;       return;     }     int mid = l + r >> 1;     if (x <= mid)       update(p << 1, l, mid, x);     else       update(p << 1 | 1, mid + 1, r, x);     tree[p] = max(tree[p << 1], tree[p << 1 | 1]);   }   long long query(int p, int l, int r, int x, int y) {     if (x <= l && r <= y) return tree[p];     int mid = l + r >> 1;     if (y <= mid)       return query(p << 1, l, mid, x, y);     else if (x > mid)       return query(p << 1 | 1, mid + 1, r, x, y);     else {       long long a = query(p << 1, l, mid, x, mid);       long long b = query(p << 1 | 1, mid + 1, r, mid + 1, y);       return max(a, b);     }   }   int main() {     int n;     while (cin >> n) {       for (int i = 1; i <= n; i++) rings[i].input();       sort(rings + 1, rings + n + 1);       build(1, 1, n);       for (int i = 2, j; i <= n; i++) {         j = lower_bound(rings + 1, rings + i, circle(rings[i].a + 1)) - rings;         if (j >= i) continue;         rings[i].h += query(1, 1, n, j, i - 1);         update(1, 1, n, i);       }       long long ans = 0;       for (int i = 1; i <= n; i++) ans = max(ans, rings[i].h);       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class S, class T>   ostream& operator<<(ostream& o, const pair<S, T>& p) {     return o <<  (  << p.first <<  ,  << p.second <<  ) ;   }   template <class T>   ostream& operator<<(ostream& o, const vector<T>& vc) {     o <<  { ;     for (const T& v : vc) o << v <<  , ;     o <<  } ;     return o;   }   using ll = long long;   template <class T>   using V = vector<T>;   template <class T>   using VV = vector<vector<T>>;   constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }   template <unsigned int mod_>   struct ModInt {     using uint = unsigned int;     using ll = long long;     using ull = unsigned long long;     constexpr static uint mod = mod_;     uint v;     ModInt() : v(0) {}     ModInt(ll _v) : v(normS(_v % mod + mod)) {}     explicit operator bool() const { return v != 0; }     static uint normS(const uint& x) { return (x < mod) ? x : x - mod; }     static ModInt make(const uint& x) {       ModInt m;       m.v = x;       return m;     }     ModInt operator+(const ModInt& b) const { return make(normS(v + b.v)); }     ModInt operator-(const ModInt& b) const { return make(normS(v + mod - b.v)); }     ModInt operator-() const { return make(normS(mod - v)); }     ModInt operator*(const ModInt& b) const { return make((ull)v * b.v % mod); }     ModInt operator/(const ModInt& b) const { return *this * b.inv(); }     ModInt& operator+=(const ModInt& b) { return *this = *this + b; }     ModInt& operator-=(const ModInt& b) { return *this = *this - b; }     ModInt& operator*=(const ModInt& b) { return *this = *this * b; }     ModInt& operator/=(const ModInt& b) { return *this = *this / b; }     ModInt& operator++(int) { return *this = *this + 1; }     ModInt& operator--(int) { return *this = *this - 1; }     ll extgcd(ll a, ll b, ll& x, ll& y) const {       ll p[] = {a, 1, 0}, q[] = {b, 0, 1};       while (*q) {         ll t = *p / *q;         for (int i = 0; i < (int)(3); i++) swap(p[i] -= t * q[i], q[i]);       }       if (p[0] < 0)         for (int i = 0; i < (int)(3); i++) p[i] = -p[i];       x = p[1], y = p[2];       return p[0];     }     ModInt inv() const {       ll x, y;       extgcd(v, mod, x, y);       return make(normS(x + mod));     }     ModInt pow(ll p) const {       if (p < 0) return inv().pow(-p);       ModInt a = 1;       ModInt x = *this;       while (p) {         if (p & 1) a *= x;         x *= x;         p >>= 1;       }       return a;     }     bool operator==(const ModInt& b) const { return v == b.v; }     bool operator!=(const ModInt& b) const { return v != b.v; }     friend istream& operator>>(istream& o, ModInt& x) {       ll tmp;       o >> tmp;       x = ModInt(tmp);       return o;     }     friend ostream& operator<<(ostream& o, const ModInt& x) { return o << x.v; }   };   using mint = ModInt<1000000007>;   int main() {     cin.tie(0);     ios::sync_with_stdio(false);     cout << fixed << setprecision(20);     int N, Q;     cin >> N >> Q;     V<ll> A(N);     for (int i = 0; i < (int)(N); i++) cin >> A[i];     V<mint> p2(N + 1);     p2[0] = 1;     for (int i = 1; i <= (int)(N); i++) p2[i] = p2[i - 1] * 2;     struct link {       int to;       mint sum;       ll sum2;     };     V<link> ls(N);     const ll inf = 1e9;     for (int i = 0; i < (int)(N); i++) {       link cur{i, A[i], A[i]};       while (cur.to > 0 && cur.sum2 > 0) {         link x = ls[cur.to - 1];         link nxt;         nxt.to = x.to;         nxt.sum = cur.sum * p2[cur.to - x.to] + x.sum;         nxt.sum2 = (cur.sum2 << min(cur.to - x.to, 30)) + x.sum2;         nxt.sum2 = min(nxt.sum2, inf);         cur = nxt;       }       ls[i] = cur;     }     const int H = 20;     V<array<pair<int, mint>, H>> par(N + 1);     for (int h = 0; h < (int)(H); h++) par[0][h] = {-1, 0};     for (int i = 0; i < (int)(N); i++) {       par[i + 1][0] = {ls[i].to, ls[i].sum};       for (int h = 1; h <= (int)(H - 1); h++) {         int j;         mint js;         tie(j, js) = par[i + 1][h - 1];         if (j == -1) {           par[i + 1][h] = {-1, 0};         } else {           int k;           mint ks;           tie(k, ks) = par[j][h - 1];           if (k == -1)             par[i + 1][h] = {-1, 0};           else             par[i + 1][h] = {k, js + ks};         }       }     }     V<mint> sum(N + 1);     for (int i = N - 1; i >= 0; i--) sum[i] = sum[i + 1] * 2 + A[i];     for (int _ = 0; _ < (int)(Q); _++) {       int l, r;       cin >> l >> r;       l--;       mint ans = 0;       for (int h = H - 1; h >= 0; h--) {         if (l + 1 <= par[r][h].first) {           ans += par[r][h].second;           r = par[r][h].first;         }       }       ans *= 2;       ans += sum[l] - sum[r] * p2[r - l];       cout << ans << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   long long find_seat(char c) {     if (c ==  a ) return 4;     if (c ==  b ) return 5;     if (c ==  c ) return 6;     if (c ==  d ) return 3;     if (c ==  e ) return 2;     if (c ==  f ) return 1;   }   int main() {     long long one, two, a, b, d, n, i, res;     char c;     while (scanf( %lld%c , &n, &c) != EOF) {       one = two = false;       a = n % 4;       if (a == 1 || a == 2)         one = true;       else         two = true;       if (n % 2 == 0)         b = 1;       else         b = 0;       res = 0;       if (one) {         res = n - 1;         d = (n - a) / 4;         d = d * 2 * 6;         d += b * 6;       } else {         res = n - 3;         d = (n - a) / 4;         if (n % 2 == 0) d--;         d = d * 2 * 6;         d += b * 6;       }       res += d + find_seat(c);       printf( %lld n , res);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxN = 1e5 + 5;   int lover[maxN], unlover[maxN];   int speak[maxN];   int N, M;   bool iscrime[maxN];   int totnocommit, totcommit;   int main() {     scanf( %d%d , &N, &M);     for (int i = (1), _ = (N); i <= _; ++i) {       scanf( %d , &speak[i]);       if (speak[i] < 0) {         totnocommit++;         unlover[-speak[i]]++;       } else {         totcommit++;         lover[speak[i]]++;       }     }     int totcrime = 0;     for (int i = (1), _ = (N); i <= _; ++i) {       int toldtruth = lover[i] + totnocommit - unlover[i];       if (toldtruth == M) {         ++totcrime;         iscrime[i] = true;       }     }     for (int i = (1), _ = (N); i <= _; ++i)       if (speak[i] < 0) {         int who = abs(speak[i]);         if (iscrime[who] == true)           if (totcrime == 1)             puts( Lie );           else             puts( Not defined );         else           puts( Truth );       } else {         int who = abs(speak[i]);         if (iscrime[who] == true)           if (totcrime == 1)             puts( Truth );           else             puts( Not defined );         else           puts( Lie );       }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int n;     cin >> n;     long long int h[n];     long long int d[n];     long long int sum = 0;     for (long long int i = 0; i < n; i++) {       cin >> h[i];       d[i] = h[i] - i;       sum += d[i];     }     long long int q = sum / n;     long long int r = sum % n;     for (int i = 0; i < n; i++) {       long long int out = q + i;       if (i < r) out++;       cout << out <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int ns[(1 << 6)];   int s[(1 << 6)];   char str[100005];   int p[100005];   void solve() {     int n;     scanf( %s  , str + 1);     n = strlen(str + 1);     for (int i = n; i; --i) {       int al = str[i] -  a ;       for (int bit = 0; bit < (1 << 6); ++bit) {         if (bit & (1 << al)) {           ns[bit]++;         }       }       p[i] = (1 << 6) - 1;     }     int m;     scanf( %d  , &m);     for (int i = 1; i <= m; ++i) {       int pos;       scanf( %d  , &pos);       scanf( %s  , &str);       int len = strlen(str);       p[pos] = 0;       for (int j = 0; j < len; ++j) {         p[pos] |= (1 << (str[j] -  a ));       }     }     for (int i = n; i; --i) {       for (int bit = 0; bit < (1 << 6); ++bit) {         if ((bit & (p[i])) == p[i]) {           ++s[bit];         }       }     }     for (int bit = 0; bit < (1 << 6); ++bit) {       if (s[bit] > ns[bit]) {         printf( Impossible n );         return;       }     }     for (int i = 1; i <= n; ++i) {       int curAl = -1;       for (int al = 0; al < 6 && curAl == -1; ++al) {         if ((1 << al) & p[i]) {           bool isGood = true;           for (int bit = 0; bit < (1 << 6) && isGood; ++bit) {             int tns = ns[bit], ts = s[bit];             if ((bit & (p[i])) == p[i]) {               --ts;             }             if (bit & (1 << al)) {               --tns;             }             if (ts > tns) {               isGood = false;             }           }           if (isGood) {             curAl = al;           }         }       }       assert(curAl != -1);       for (int bit = 0; bit < (1 << 6); ++bit) {         if ((bit & (p[i])) == p[i]) {           --s[bit];         }       }       for (int bit = 0; bit < (1 << 6); ++bit) {         if (bit & (1 << curAl)) {           --ns[bit];         }       }       putchar( a  + curAl);     }     putchar(  n );   }   int main() {     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 1e9 + 7;   inline void rvi(vector<int>& v, int n) {     int temp;     for (int i = 0; i < n; i++) {       cin >> temp;       v.push_back(temp);     }   }   inline void rvll(vector<long long int>& v, int n) {     long long int temp;     for (int i = 0; i < n; i++) {       cin >> temp;       v.push_back(temp);     }   }   inline void prvi(vector<int>& a) {     for (int i = 0; i < a.size(); i++) {       cout << a[i] <<    ;     }     cout << endl;   }   inline void prvll(vector<long long int>& a) {     for (int i = 0; i < a.size(); i++) {       cout << a[i] <<    ;     }     cout << endl;   }   inline void prmii(map<int, int>& m) {     for (auto x : m) {       cout << x.first <<     << x.second << endl;     }   }   inline vector<long long int> prefixsum(vector<int>& a) {     vector<long long int> b;     b.push_back(a[0]);     for (int i = 1; i < a.size(); i++) {       b.push_back(a[i] + b[i - 1]);     }     return b;   }   inline vector<long long int> suffixsum(vector<int>& a) {     vector<long long int> b((a.size()));     b[(a.size()) - 1] = a[(a.size()) - 1];     for (int i = (a.size()) - 1 - 1; i >= 0; i--) {       b[i] = a[i] + b[i + 1];     }     return b;   }   inline vector<long long int> prefixsum(vector<long long int>& a) {     vector<long long int> b;     b.push_back(a[0]);     for (int i = 1; i < a.size(); i++) {       b.push_back(a[i] + b[i - 1]);     }     return b;   }   inline vector<long long int> suffixsum(vector<long long int>& a) {     vector<long long int> b((a.size()));     b[(a.size()) - 1] = a[(a.size()) - 1];     for (int i = (a.size()) - 1 - 1; i >= 0; i--) {       b[i] = a[i] + b[i + 1];     }     return b;   }   void solve();   int main() {     solve();     return 0;   }   void solve() {     int t;     cin >> t;     while (t--) {       int d;       cin >> d;       double a, b;       if (d * d - 4 * d < 0) {         cout <<  N n ;       } else {         a = (d + sqrt(d * d - 4 * d)) / 2;         b = d - a;         printf( Y %.10lf %.10lf n , a, b);       }     }   }


#include <bits/stdc++.h>   using namespace std;   int a[111111];   map<int, int> cnt;   map<int, int> m;   int main() {     int n;     scanf( %d , &n);     m.clear();     cnt.clear();     for (int i = 0; i < n; i++) scanf( %d , &a[i]);     sort(a, a + n);     int ma = INT_MIN;     for (int i = 0; i < n; i++) {       m[a[i]] += 1;       ma = max(ma, a[i]);     }     vector<int> v;     for (int i = 0; i < n; i++)       if (cnt[a[i]] != 1) {         v.push_back(a[i]);         cnt[a[i]] = 1;         m[a[i]] = m[a[i]] - 1;       }     cnt.clear();     for (int i = n - 1; i >= 0; i--)       if (a[i] != ma && m[a[i]] > 0 && cnt[a[i]] != 1) {         v.push_back(a[i]);         cnt[a[i]] = 1;       }     printf( %d n , v.size());     for (int i = 0; i < v.size(); i++) printf( %d  , v[i]);     printf(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void Read(int &n) {     int sign = 1;     n = 0;     char c;     do {       c = getchar();     } while (!isdigit(c) && c !=  - );     if (c ==  - ) {       c = getchar();       sign = -1;     }     do {       n = n * 10 + c - 48;       c = getchar();     } while (isdigit(c));     n *= sign;   }   void Read(long long &n) {     int sign = 1;     n = 0;     char c;     do {       c = getchar();     } while (!isdigit(c) && c !=  - );     if (c ==  - ) {       c = getchar();       sign = -1;     }     do {       n = n * 10ll + c - 48;       c = getchar();     } while (isdigit(c));     n *= sign;   }   void Write(int n) {     if (n == 0) {       putchar( 0 );       return;     } else if (n < 0)       putchar( - ), n = -n;     char C[30];     int d = 0;     while (n) {       C[++d] = (n % 10) + 48;       n /= 10;     }     for (int i = d; i >= 1; --i) putchar(C[i]);   }   void Write(long long n) {     if (n == 0) {       putchar( 0 );       return;     } else if (n < 0)       putchar( - ), n = -n;     char C[30];     int d = 0;     while (n) {       C[++d] = (n % 10ll) + 48;       n /= 10ll;     }     for (int i = d; i >= 1; --i) putchar(C[i]);   }   const int maxn = 1e4 + 5;   const long long INFL = 0x3f3f3f3f3f3f3f3f;   int n, c;   long long f[maxn], g[maxn];   int p[maxn], s[maxn];   int main() {     scanf( %d%d , &n, &c);     for (int i = 0; i < n; ++i) scanf( %d , &p[i]);     for (int i = 0; i < n; ++i) scanf( %d , &s[i]);     memset(f, INFL, sizeof f);     f[0] = 0;     for (int i = 0; i < n; ++i) {       for (int j = 0; j <= i; ++j) g[j] = f[j], f[j] = INFL;       for (int j = 0; j <= i; ++j) {         f[j + 1] = min(g[j] + s[i], f[j + 1]);         f[j] = min(f[j], g[j] + p[i] + (long long)j * c);       }     }     long long ans = INFL;     for (int i = 0; i <= n; ++i) ans = min(ans, f[i]);     printf( %I64d , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int n, t;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cin >> n;     long long int f[26] = {0}, x = 0;     while (n > 1) {       int j = 0, sum = 0;       while (sum + j + 2 <= n) j = j + 2, sum += j;       f[x++] = (j - 2) / 2 + 2;       f[x++] = (j - 2) / 2 + 2;       n -= sum;     }     if (n == 1) {       f[x++] = 2;     }     long long int flag = 0;     for (int i = 0; i < x; i++) {       char c = i + 97;       while (f[i]) cout << c, f[i]--, flag = 1;     }     if (flag == 0) cout <<  x ;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using lli = long long int;   using str = string;   const ll MOD = 1e9 + 7;   void solve() {     ll a, b, c;     cin >> a >> b >> c;     cout << a + b + c - 1 <<   n ;     return;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout << setprecision(15) << fixed;     ll t = 1;     cin >> t;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int64_t MAXN = 1000000007LL;   int n;   vector<int64_t> a(5), b(5), c(5), s(5);   int64_t maxscore(int64_t s, int64_t n) {     if (s * 2 > n) return 500;     if (s * 4 > n) return 1000;     if (s * 8 > n) return 1500;     if (s * 16 > n) return 2000;     if (s * 32 > n) return 2500;     return 3000;   }   bool win(int64_t mid) {     int64_t sa = 0, sb = 0;     for (int i = 0; i < 5; i++) {       int64_t m = maxscore(s[i] + c[i] * mid, n + mid);       if (a[i] >= 0) sa += m * (250 - a[i]) / 250;       if (b[i] >= 0) sb += m * (250 - b[i]) / 250;     }     return sa > sb;   }   int main(int argc, char **argv) {     ios_base::sync_with_stdio(false);     cin.tie(0);     cin >> n;     for (int i = 0; i < n; i++) {       for (int j = 0; j < 5; j++) {         int64_t x;         cin >> x;         if (x >= 0) s[j]++;         if (i == 0) a[j] = x;         if (i == 1) b[j] = x;       }     }     int64_t minx = -1;     for (int i = 0; i < 32; i++) {       bool ok = true;       for (int j = 0; j < 5; j++) {         c[j] = (i >> j) & 1;         if (c[j] && a[j] < 0) ok = false;       }       if (!ok) continue;       int64_t x;       for (x = 0; x < 100000; x++)         if (win(x)) break;       if (x == 100000) x = -1;       for (int j = 0; j < 5; j++) cerr << c[j];       cerr <<     << x << endl;       minx = x >= 0 && (minx < 0 || x < minx) ? x : minx;     }     cout << minx << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     long double temp;     temp = log2(n + 1);     if (temp == (int)temp) {       cout << temp << endl;     } else {       cout << (int)(temp) + 1 << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     double r1, r2, p1, p2;     double A, B;     int n;     scanf( %d , &n);     double x;     r1 = 0;     for (int i = 0; i < n; i++) {       scanf( %lf , &x);       if (x > r1) r1 = x;     }     int m;     scanf( %d , &m);     p1 = 0;     for (int i = 0; i < m; i++) {       scanf( %lf , &x);       if (x > p1) p1 = x;     }     int z;     scanf( %d , &z);     p2 = 5005;     for (int i = 0; i < z; i++) {       scanf( %lf , &x);       if (x < p2) p2 = x;     }     scanf( %lf %lf , &A, &B);     r2 = (A * p2) / (B * p1) + 1;     r2 = r1 * r1 / r2;     r2 = sqrt(r2);     printf( %.12lf n , r2);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n = 4;     int a[4];     for (int i = 0; i < 4; i++) {       cin >> a[i];     }     sort(a, a + n);     for (int i = 0; i < 3; i++) {       cout << a[3] - a[i] <<    ;     }   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 0x3f3f3f3f;   char s[int(3e5 + 5)];   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     int t;     cin >> t;     while (t--) {       int n, m;       cin >> n >> m;       cin >> (s + 1);       bool flag = true;       int tmp1 = 0, tmp = 0;       for (int i = 1; i <= m; i++)         if (s[i] ==  1 )           tmp1++;         else if (s[i] ==  ? )           tmp++;       if (tmp1 + tmp < m / 2 or tmp1 > m / 2) flag = false;       for (int i = 1; i <= m and flag == true; i++) {         char ch =  ? ;         for (int j = i; j <= n and flag == true; j += m) {           if (s[j] ==  ? ) continue;           if (ch ==  ? )             ch = s[j];           else {             if (ch == s[j])               continue;             else               flag = false;           }         }         if (flag == true)           for (int j = i; j <= n; j += m) s[j] = ch;       }       tmp1 = tmp = 0;       for (int i = 1; i <= m; i++)         if (s[i] ==  1 )           tmp1++;         else if (s[i] ==  ? )           tmp++;       if (tmp1 + tmp < m / 2 or tmp1 > m / 2) flag = false;       if (flag == true)         cout <<  YES  << endl;       else         cout <<  NO  << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 30;   int a[maxn];   int num[maxn] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1};   int ans;   void dfs(string s, int v, int cnt) {     int n = s.length();     if (v == n) {       ans += cnt;       return;     }     if (v < n - 2 && (s[v] -  0  + a[v]) >= 1) {       a[v + 2] += 1;       dfs(s, v + 1, cnt * num[s[v] -  0  + a[v] * 10 - 1]);       a[v + 2] -= 1;     }     dfs(s, v + 1, cnt * num[s[v] -  0  + a[v] * 10]);   }   int main() {     int kase;     cin >> kase;     while (kase--) {       ans = 0;       string s;       cin >> s;       dfs(s, 0, 1);       cout << ans - 2 << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   void c_p_c() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);   }   int32_t main() {     c_p_c();     long long int t;     cin >> t;     while (t--) {       long long int n, k;       cin >> n >> k;       vector<long long int> a(n), b(k);       for (long long int i = 0; i < (long long int)n; i++) cin >> a[i];       for (long long int i = 0; i < (long long int)k; i++) cin >> b[i];       map<long long int, long long int> pos, present;       for (auto it : b) present[it] = 1;       for (long long int i = 0; i < (long long int)n; i++) pos[a[i]] = i;       long long int ans = 1;       for (long long int i = 0; i < (long long int)k; i++) {         long long int p = pos[b[i]];         long long int temp = 0;         if (p == 0) {           if (!present[a[1]]) temp++;         } else if (p == n - 1) {           if (!present[a[n - 2]]) temp++;         } else {           if (!present[a[p - 1]]) temp++;           if (!present[a[p + 1]]) temp++;         }         ans = (ans * temp) % 998244353;         present[b[i]] = 0;       }       cout << ans <<   n ;     }     cerr <<  Time :   << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC          <<  ms n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxN = 2e5 + 9, MOD = 1e9 + 7;   int n;   long long arr[maxN], ot[maxN];   long long maxsub(long long *arr, int n) {     long long cr = LLONG_MIN / 4, maxi = LLONG_MIN / 4;     for (int i = 0; i < n; i++) {       cr = max(arr[i], cr + arr[i]);       maxi = max(maxi, cr);     }     return maxi;   }   long long trr(long long *arr, int sta) {     int ct = 0;     for (int i = sta, cnd = 1; i + 1 < n; i++, cnd *= -1) {       ot[ct++] = abs(arr[i] - arr[i + 1]) * cnd;     }     return maxsub(ot, ct);   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0), cout.tie(0);     cin >> n;     for (int i = 0; i < n; i++) {       cin >> arr[i];     }     cout << max(trr(arr, 0), trr(arr, 1)) <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 3e5 + 5;   const long long mod = 1e9 + 7;   const long long INF = 0x7f7f7f7f7f7f7f7f;   const int INFi = 0x7f7f7f7f;   long long n, m, vis[N];   void solve() {     cin >> n >> m;     for (int i = 1; i <= 3 * n; i++) vis[i] = 0;     vector<long long> match;     for (int i = 1; i <= m; i++) {       int u, v;       cin >> u >> v;       if (!vis[u] && !vis[v]) {         vis[u] = 1;         vis[v] = 1;         match.push_back(i);       }     }     if (match.size() >= n) {       cout <<  Matching             <<   n ;       for (int i = 0; i < n; i++) cout << match[i] <<    ;       cout <<   n ;       ;     } else {       cout <<  IndSet             <<   n ;       for (int i = 1, j = 0; i <= 3 * n; i++) {         if (vis[i]) continue;         if (j == n) break;         cout << i <<    ;         j++;       }       cout <<   n ;       ;     }   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cout << fixed;     cout << setprecision(15);     ;     int test = 1;     cin >> test;     for (int i = 1; i <= test; i++) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 5005, MOD = (int)1e9 + 7;   int dp[MAX][MAX], pref[MAX];   int main() {     int n, k, poc, kraj, i, j, raz;     scanf( %d%d%d%d , &n, &poc, &kraj, &k);     for (i = 1; i <= n; i++) dp[0][i] = 1;     for (i = 1; i <= k; i++) {       for (j = 1; j <= n; j++) {         pref[j] = pref[j - 1] + dp[i - 1][j];         if (pref[j] >= MOD) pref[j] -= MOD;       }       for (j = 1; j <= n; j++) {         raz = abs(j - kraj) - 1;         if (!raz)           dp[i][j] = 0;         else {           dp[i][j] = pref[min(n, j + raz)] - pref[max(0, j - raz - 1)];           if (dp[i][j] < 0)             dp[i][j] += MOD;           else if (dp[i][j] >= MOD)             dp[i][j] -= MOD;           dp[i][j] -= dp[i - 1][j];           if (dp[i][j] < 0)             dp[i][j] += MOD;           else if (dp[i][j] >= MOD)             dp[i][j] -= MOD;         }       }     }     printf( %d n , dp[k][poc]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, m, b, mod, a[509], dp[509][509], ans;   int main() {     cin >> n >> m >> b >> mod;     dp[0][0] = 1;     for (int i = 0; i < n; i++) cin >> a[i];     for (int i = 0; i < n; i++) {       for (int j = 1; j <= m; j++) {         for (int k = 0; k <= b - a[i]; k++) {           dp[j][k + a[i]] = (dp[j - 1][k] + dp[j][k + a[i]]) % mod;         }       }     }     for (int i = 0; i <= b; i++) ans += dp[m][i], ans %= mod;     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     pair<int, int> p[10];     int i, j, w1, w2, cnt2;     for (i = 0; i < 4; i++) scanf( %d%d , &p[i].first, &p[i].second);     for (i = cnt2 = 0; i < 2; i++) {       w1 = w2 = 0;       for (j = 0; j < 2; j++) {         if (p[0].first > p[2].second && p[1].second > p[3].first) w1++;         if (p[0].first < p[2].second && p[1].second < p[3].first) w2++;         swap(p[2], p[3]);       }       if (w2) cnt2++;       if (w1 == 2) break;       swap(p[0], p[1]);     }     if (i < 2)       puts( Team 1 );     else if (cnt2 == 2)       puts( Team 2 );     else       puts( Draw );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int j, t;     cin >> t;     for (j = 0; j < t; j++) {       long long int n;       cin >> n;       long long int a[n], i;       for (i = 0; i < n; i++) cin >> a[i];       long long int p = a[0], sum = a[0];       for (i = 1; i < n; i++) {         if (p < 0 && a[i] < 0) {           if (a[i] > p) {             sum += a[i];             sum -= p;             p = a[i];           }         } else if (p < 0 && a[i] > 0) {           sum += a[i];           p = a[i];         } else if (p > 0 && a[i] > 0) {           if (a[i] > p) {             sum -= p;             sum += a[i];             p = a[i];           }         } else if (p > 0 && a[i] < 0) {           sum += a[i];           p = a[i];         }       }       cout << sum << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   int a[200005];   long long oddpref[200005];   long long evenpref[200005];   long long evensuff[200005];   long long oddsuff[200005];   int main() {     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> a[i];     }     for (int i = 1; i <= n; i++) {       oddpref[i] = oddpref[i - 1];       evenpref[i] = evenpref[i - 1];       if (i % 2)         oddpref[i] += a[i];       else         evenpref[i] += a[i];     }     for (int i = n; i >= 1; i--) {       oddsuff[i] = oddsuff[i + 1];       evensuff[i] = evensuff[i + 1];       if (i % 2)         oddsuff[i] += a[i];       else         evensuff[i] += a[i];     }     int cnt = 0;     for (int i = 1; i <= n; i++) {       if (oddpref[i - 1] + evensuff[i + 1] == evenpref[i - 1] + oddsuff[i + 1]) {         cnt++;       }     }     cout << cnt;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[501102];   int ans, cnt, sum, d;   void solve() {     ans = 0;     cnt = 0;     sum = 0;     d = 0;     int n;     cin >> n;     for (int i = 1; n >= i; i++) {       cin >> a[i];       if (a[i] % 2 == 1) {         ans++;         if (a[i] * n % 2 == 1) d = 1;       } else         cnt++;       sum += a[i];     }     if (ans >= cnt && ans != n || sum % 2 == 1 || d != 0 ||         ans != 0 && cnt != 0) {       cout <<  YES  << endl;       return;     }     cout <<  NO  << endl;   }   int main() {     int t;     cin >> t;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  stack:200000000 )   #pragma GCC optimize( Ofast )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native )   using namespace std;   long long freq[3000005], mul[3000005], n, q, x;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n;     for (int i = n; i--; ++freq[x]) cin >> x;     for (int i = 1; i < 3000005; ++i)       if (freq[i])         for (int j = i; j < 3000005; j += i)           mul[j] += freq[i] * (freq[j / i] - (i == j / i));     for (int i = 1; i < 3000005; ++i) mul[i] += mul[i - 1];     for (cin >> q; q--; cout << n * (n - 1) - mul[x - 1] <<   n ) cin >> x;   }


#include <bits/stdc++.h>   using namespace std;   long long N, M, nn;   long long a[300002];   long long suma[300002];   long long f[300002];   long long sumf[300002];   struct data {     long long a, b;     long long tot;   } seg[1200002];   long long s, e;   bool cross(long long x1, long long y1, long long x2, long long y2) {     if (y1 < x2 || y2 < x1) return false;     return true;   }   void add(long long node, long long left, long long right) {     seg[node].tot += (sumf[min(right, e) - s + 1] - sumf[max(left, s) - s]);     seg[node].tot %= 1000000009;     if (s <= left && right <= e) {       seg[node].a += f[left - s];       seg[node].b += f[left - s + 1];       seg[node].a %= 1000000009;       seg[node].b %= 1000000009;       return;     }     int mid = (left + right) / 2;     if (cross(s, e, left, mid)) add(node * 2, left, mid);     if (cross(s, e, mid + 1, right)) add((node * 2) + 1, mid + 1, right);   }   long long ans;   long long x, y;   void sum(long long node, long long left, long long right) {     if (s <= left && right <= e) {       ans += seg[node].tot;       ans %= 1000000009;       return;     }     int mid = (left + right) / 2;     seg[node * 2].a += seg[node].a;     seg[node * 2].b += seg[node].b;     seg[node * 2].a %= 1000000009;     seg[node * 2].b %= 1000000009;     x = seg[node].a;     y = seg[node].b;     seg[node * 2].tot += ((x * sumf[mid - left]) + (y * sumf[mid - left + 1]));     seg[node * 2].tot %= 1000000009;     seg[(node * 2) + 1].tot +=         ((x * sumf[right - left]) + (y * sumf[right - left + 1]));     seg[(node * 2) + 1].tot -=         ((seg[node].a * sumf[mid - left]) + (seg[node].b * sumf[mid - left + 1]));     seg[(node * 2) + 1].tot %= 1000000009;     x = ((seg[node].a * f[mid - left]) + (seg[node].b * f[mid - left + 1]));     y = ((seg[node].a * f[mid - left + 1]) + (seg[node].b * f[mid - left + 2]));     seg[(node * 2) + 1].a += x;     seg[(node * 2) + 1].b += y;     seg[(node * 2) + 1].a %= 1000000009;     seg[(node * 2) + 1].b %= 1000000009;     seg[node].a = seg[node].b = 0;     if (cross(s, e, left, mid)) sum(node * 2, left, mid);     if (cross(s, e, mid + 1, right)) sum((node * 2) + 1, mid + 1, right);   }   long long tmp[300002], ans2;   void process() {     long long i, j;     long long op, l, r;     for (nn = 1; nn < N; nn *= 2)       ;     for (i = 1; i <= N; i++) {       suma[i] = suma[i - 1] + a[i];       suma[i] %= 1000000009;     }     f[1] = f[2] = 1;     for (i = 3; i <= N; i++) {       f[i] = f[i - 1] + f[i - 2];       f[i] %= 1000000009;     }     for (i = 1; i <= N; i++) {       sumf[i] = sumf[i - 1] + f[i];       sumf[i] %= 1000000009;       tmp[i] = a[i];     }     for (i = 1; i <= M; i++) {       scanf( %lld %lld %lld , &op, &l, &r);       if (op == 1) {         s = l;         e = r;         add(1, 1, nn);       } else {         s = l;         e = r;         ans = 0;         sum(1, 1, nn);         ans += suma[e];         ans -= suma[s - 1];         ans %= 1000000009;         if (ans < 0) ans += 1000000009;         printf( %lld n , ans);         ans2 = 0;       }     }   }   void clean() {     long long i;     for (i = 1; i <= nn * 2; i++) seg[i].a = seg[i].b = seg[i].tot;   }   int main(void) {     long long i;     scanf( %lld %lld , &N, &M);     for (i = 1; i <= N; i++) scanf( %lld , &a[i]);     process();     clean();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   #define fore(i, a, b) for(int i = a; i <= b; i++)   #define Fore(i, a, b) for(int i = a; i < b; i++)   #define pii pair<int, int>   #define fi first   #define se second   #define MP make_pair   #define EP emplace_back   #define li long long      const int MAXN = 2100, mod = 998244353;      inline int input(){       char c = getchar(); int o; bool f = 0;       while(c > 57 || c < 48)           f |= (c ==  - ), c = getchar();       for(o = 0; c > 47 && c < 58; c = getchar())           o = (o << 1)+(o << 3)+(c - 48);       return f ? -o : o;   }      li C[MAXN * 2][MAXN * 2];      int main(){       int n = input(), m = input();       li ans = 0;       C[0][0] = 1;       fore(i, 1, n + m){           C[i][0] = 1;           fore(j, 1, i)               C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % mod;               // cout << C[i][j] <<    n [j == i];       }       Fore(r, 1, n){           li F = 0;           for(int c = m - 1; c >= 1; c--){               F = (F + C[n - r + m - c - 1][n - r] * C[n - r - 1 + c][n - r - 1] % mod) % mod;               ans = (ans + F * (C[r + c - 1][r] * C[r + m - c - 1][r - 1] % mod) % mod) % mod;           }       }       swap(n, m);       Fore(r, 1, n){           li F = 0;           for(int c = m - 1; c >= 1; c--){               ans = (ans + F * (C[r + c - 1][r] * C[r + m - c - 1][r - 1] % mod) % mod) % mod;               F = (F + C[n - r + m - c - 1][n - r] * C[n - r - 1 + c][n - r - 1] % mod) % mod;           }       }       printf( %lld , (ans << 1) % mod);   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     long long n, x;     cin >> n;     long long a[n + 1];     for (long long i = 0; i < n; i++) {       cin >> a[i + 1];     }     long long dp[n + 2];     dp[0] = 0;     dp[n + 1] = 0;     for (long long i = 1; i <= n; i++) dp[i] = min(dp[i - 1] + 1, a[i]);     for (long long i = n; i >= 1; i--) dp[i] = min(dp[i + 1] + 1, dp[i]);     long long mx = dp[1];     for (long long i = 2; i <= n; i++) mx = max(mx, dp[i]);     cout << mx;     return;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     ;     long long t;     t = 1;     while (t--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, ans, u, v, i, root_u, root_v, arr[100001], len[100001], c[100001],       k;   vector<pair<long long, long long> > in;   long long find(long long x) {     if (arr[x] == x) return x;     return arr[x] = find(arr[x]);   }   int main() {     cin >> n >> k;     for (i = 1; i <= n; i++) arr[i] = i, len[i] = 1;     for (i = 0; i < k; i++) {       cin >> u >> v;       root_u = find(u);       root_v = find(v);       if (root_u != root_v) arr[root_u] = root_v, len[root_v] += len[root_u];       c[u]++;     }     for (i = 1; i <= n; i++)       if (arr[i] != i) c[find(i)] += c[i];     for (i = 1; i <= n; i++)       if (arr[i] == i) ans += (c[i] - len[i] + 1);     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   const int maxn = 3e5 + 5;   int n, a, b;   string s;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int q;     cin >> q;     while (q--) {       int a, b;       cin >> a >> b;       cin >> s;       n = s.size();       vector<int> sz(n, 0);       vector<int> segs;       for (int i = 0; i < n; i++) {         if (s[i] !=  . ) continue;         sz[i] = i == 0 ? 1 : sz[i - 1] + 1;         if (i == n - 1 || s[i + 1] !=  . ) segs.push_back(sz[i]);       }       int numSmall = 0;       int numBig = 0;       for (int i : segs) {         if (b <= i && i < a)           numSmall++;         else if (i >= 2 * b)           numBig++;       }       if (numSmall > 0) {         cout <<  NO n ;       } else {         if (numBig >= 2) {           cout <<  NO n ;         } else if (numBig == 0) {           int cnt = 0;           for (int i : segs) {             if (i >= a) cnt++;           }           cout << (cnt & 1 ?  YES  :  NO ) <<   n ;         } else if (numBig == 1) {           int mxSize = 0;           for (int i : segs) {             mxSize = max(mxSize, i);           }           int cnt = 0;           for (int i : segs) {             if (i == mxSize) continue;             if (i >= a) cnt++;           }           if (a > mxSize) {             cout <<  NO n ;             return 0;           }           int s1 = 0, s2 = mxSize - a;           bool canWin = false;           for (; s2 >= 0; s1++, s2--) {             if ((b <= s1 && s1 < a) || (b <= s2 && s2 < a)) continue;             if (s1 >= 2 * b || s2 >= 2 * b) continue;             int c = cnt;             if (s1 >= a) c++;             if (s2 >= a) c++;             if (c % 2 == 0) {               canWin = true;               break;             }           }           cout << (canWin ?  YES  :  NO ) <<   n ;         }       }     }   }


#include <bits/stdc++.h>   using namespace std;   int ans1[300003], ans2[300003], l[300003];   vector<int> t[2400024];   vector<int> a, q;   void build(int v, int tl, int tr) {     if (tl == tr) {       t[v].push_back(a[tl]);       return;     }     int mid = (tl + tr) / 2;     build(v * 2, tl, mid);     build(v * 2 + 1, mid + 1, tr);     int l = 0, r = 0;     t[v].reserve(t[v * 2].size() + t[v * 2 + 1].size());     while (l != t[v * 2].size() || r != t[v * 2 + 1].size()) {       if (l == t[v * 2].size()) {         t[v].push_back(t[v * 2 + 1][r++]);       } else if (r == t[v * 2 + 1].size()) {         t[v].push_back(t[v * 2][l++]);       } else if (t[v * 2][l] < t[v * 2 + 1][r]) {         t[v].push_back(t[v * 2][l++]);       } else {         t[v].push_back(t[v * 2 + 1][r++]);       }     }   }   int ask(int v, int tl, int tr, int l, int r, int x) {     if (l > r) {       return 0;     }     if (tl == l && tr == r) {       l = -1;       r = t[v].size();       while (r - l > 1) {         int mid = (r + l) / 2;         if (t[v][mid] < x) {           l = mid;         } else {           r = mid;         }       }       return r;     }     int mid = (tl + tr) / 2;     return ask(v * 2, tl, mid, l, min(r, mid), x) +            ask(v * 2 + 1, mid + 1, tr, max(l, mid + 1), r, x);   }   int main() {     int n, m;     cin >> n >> m;     a.push_back(1e9 + 7);     for (int i = n; i > 0; --i) {       ans1[i] = i;       l[i] = a.size();       a.push_back(0);     }     while (m--) {       int x;       cin >> x;       ans1[x] = 1;       q.push_back(x);       a.push_back(l[x]);       l[x] = a.size() - 1;     }     build(1, 0, a.size() - 1);     for (int i = n + 1; i < a.size(); ++i) {       ans2[q[i - n - 1]] =           max(ans2[q[i - n - 1]], ask(1, 0, a.size() - 1, a[i], i, a[i]));     }     for (int i = 1; i <= n; ++i) {       ans2[i] = max(ans2[i], ask(1, 0, a.size() - 1, l[i], a.size() - 1, l[i]));       cout << ans1[i] <<     << ans2[i] << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int n, a[(1 << 20)];   vector<int> odd, ev;   int main() {     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a[i];     }     for (int s = 0, f = n - 1; s < f; s++, f--) {       if (s % 2 == 0) {         swap(a[s], a[f]);       }     }     for (int i = 0; i < n; i++) {       cout << a[i] <<    ;     }     cout <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 5;   vector<int> v1[maxn], v2[maxn];   int n, lazy[maxn << 2], minnode[maxn << 2], maxnode[maxn << 2];   long long sumnode[maxn << 2];   void modify(int rt, int l, int r, int c) {     lazy[rt] = c;     minnode[rt] = maxnode[rt] = c;     sumnode[rt] = (r - l + 1LL) * (n + 1 - c);   }   void pushup(int rt) {     sumnode[rt] = sumnode[rt << 1] + sumnode[rt << 1 | 1];     minnode[rt] = min(minnode[rt << 1], minnode[rt << 1 | 1]);     maxnode[rt] = max(maxnode[rt << 1], maxnode[rt << 1 | 1]);   }   void pushdown(int rt, int l, int r) {     if (lazy[rt]) {       int m = (l + r) >> 1;       modify(rt << 1, l, m, lazy[rt]);       modify(rt << 1 | 1, m + 1, r, lazy[rt]);       lazy[rt] = 0;     }   }   void build(int rt, int l, int r) {     lazy[rt] = 0;     if (l == r) {       minnode[rt] = l;       sumnode[rt] = n - l + 1;       return;     }     int m = (l + r) >> 1;     build(rt << 1, l, m), build(rt << 1 | 1, m + 1, r);     pushup(rt);   }   void update(int rt, int l, int r, int x, int y, int c) {     if (c <= minnode[rt]) return;     if (x <= l && r <= y && maxnode[rt] <= c) {       modify(rt, l, r, c);       return;     }     pushdown(rt, l, r);     int m = (l + r) >> 1;     if (x <= m) update(rt << 1, l, m, x, y, c);     if (m < y) update(rt << 1 | 1, m + 1, r, x, y, c);     pushup(rt);   }   void init() {     for (int i = 1; i < maxn; ++i) {       for (int j = i; j < maxn; j += i) v1[j].push_back(i);     }   }   int main() {     init();     scanf( %d , &n);     int mx = 0;     for (int i = 1; i <= n; ++i) {       int x;       scanf( %d , &x);       mx = max(x, mx);       for (int j = 0; j < v1[x].size(); ++j) v2[v1[x][j]].push_back(i);     }     build(1, 1, n);     long long ans = 0, cur = sumnode[1];     for (int i = mx; i; --i) {       if (v2[i].size() > 1) {         int p = v2[i][0], q = v2[i][1];         if (q < n) update(1, 1, n, q + 1, n, n + 1);         update(1, 1, n, p + 1, q, v2[i].back());         update(1, 1, n, 1, p, v2[i][v2[i].size() - 2]);         ans += i * (cur - sumnode[1]);         cur = sumnode[1];       }     }     printf( %I64d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int t[4000005];   void update(long long int v, long long int tl, long long int tr,               long long int pos) {     if (tl == tr) {       t[v]++;       return;     }     long long int tm = (tl + tr) / 2;     if (pos <= tm)       update(2 * v, tl, tm, pos);     else       update(2 * v + 1, tm + 1, tr, pos);     t[v] = t[2 * v] + t[2 * v + 1];   }   long long int sum(long long int v, long long int tl, long long int tr,                     long long int l, long long int r) {     if (l > r) return 0;     if (l == tl && r == tr) return t[v];     long long int tm = (tl + tr) / 2;     return sum(2 * v, tl, tm, l, min(r, tm)) +            sum(2 * v + 1, tm + 1, tr, max(l, tm + 1), r);   }   void solve() {     long long int n, k;     cin >> n >> k;     if (k >= (n + 1) / 2) k = n - k;     long long int cnt = n, x = 1, cur = 1;     while (cnt) {       long long int y = x + k;       if (y > n) y -= n;       long long int s = x + 1, e = y - 1, val;       if (s == n + 1) s = 1;       if (e == 0) e = n;       if (s <= e)         val = sum(1, 1, n, s, e);       else         val = sum(1, 1, n, s, n) + sum(1, 1, n, 1, e);       cur += val + 1;       cout << cur <<    ;       update(1, 1, n, x);       update(1, 1, n, y);       x = y;       cnt--;     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     clock_t z = clock();     long long int qc = 1;     for (long long int i = 1; i <= qc; i++) {       solve();     }     fprintf(stderr,  Total Time:%.4Lf n ,             (long double)(clock() - z) / CLOCKS_PER_SEC),         fflush(stderr);   }


#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);   }   const int INF = 1 << 28;   const double EPS = 1e-8;   const int MOD = 1000000007;   int n, m, t;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     scanf( %d%d%d , &n, &m, &t);     deque<pair<int, int> > ends;     int ans = 0, accept = 0;     vector<int> idxs(n);     for (int i = 0; i < (int)(n); i++) {       int h, mm, s, x;       scanf( %d:%d:%d , &h, &mm, &s);       x = h * 3600 + mm * 60 + s;       while (!ends.empty() && ends.front().first <= x) {         idxs[ends.front().second] = 1;         ans++;         ends.pop_front();       }       ends.emplace_back(x + t, i);       if (ends.size() == m) accept = 1;       while (ends.size() > m) {         idxs[ends.back().second] = 0;         ends.pop_back();         ends.back().first = x + t;       }     }     while (!ends.empty()) {       idxs[ends.back().second] = 1;       ans++;       ends.pop_back();     }     if (!accept) {       puts( No solution );       return 0;     }     int sum = 0;     printf( %d n , ans);     for (int i = 0; i < (int)(n); i++) printf( %d n , sum += idxs[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 5;   int tim;   int t[maxn];   int sum[maxn], sum2[maxn];   int in[maxn], ou[maxn], dfn[maxn];   vector<int> G[maxn];   void dfs(int rt, int fa) {     in[rt] = ++tim;     dfn[tim] = rt;     for (int i = 0; i < G[rt].size(); i++) {       int to = G[rt][i];       if (to == fa) continue;       dfs(to, rt);     }     ou[rt] = tim;   }   struct T {     int l, r, mid;     int add, sum;   } tree[maxn << 2];   void push_up(int rt) {     tree[rt].sum = tree[rt << 1].sum + tree[rt << 1 | 1].sum;   }   void push_down(int rt) {     if (tree[rt].add) {       tree[rt << 1].add ^= 1;       tree[rt << 1].sum =           (tree[rt << 1].r - tree[rt << 1].l + 1) - tree[rt << 1].sum;       tree[rt << 1 | 1].add ^= 1;       tree[rt << 1 | 1].sum =           (tree[rt << 1 | 1].r - tree[rt << 1 | 1].l + 1) - tree[rt << 1 | 1].sum;       tree[rt].add = 0;     }   }   void build(int rt, int l, int r) {     tree[rt].add = 0;     tree[rt].l = l;     tree[rt].r = r;     if (l == r) {       tree[rt].sum = t[dfn[l]];       return;     }     int mid = tree[rt].mid = l + r >> 1;     build(rt << 1, l, mid);     build(rt << 1 | 1, mid + 1, r);     push_up(rt);   }   void update(int rt, int l, int r) {     if (tree[rt].r < l || tree[rt].l > r) return;     if (tree[rt].l >= l && tree[rt].r <= r) {       tree[rt].sum = (tree[rt].r - tree[rt].l + 1) - tree[rt].sum;       tree[rt].add ^= 1;       return;     }     push_down(rt);     if (tree[rt].mid >= l) update(rt << 1, l, r);     if (tree[rt].mid < r) update(rt << 1 | 1, l, r);     push_up(rt);   }   int query(int rt, int l, int r) {     if (tree[rt].r < l || tree[rt].l > r) return 0;     if (tree[rt].l >= l && tree[rt].r <= r) return tree[rt].sum;     push_down(rt);     int ans = 0;     if (tree[rt].mid >= l) ans += query(rt << 1, l, r);     if (tree[rt].mid < r) ans += query(rt << 1 | 1, l, r);     push_up(rt);     return ans;   }   int main() {     int n, x;     scanf( %d , &n);     for (int i = 2; i <= n; i++) {       scanf( %d , &x);       G[x].push_back(i);       G[i].push_back(x);     }     for (int i = 1; i <= n; i++) scanf( %d , &t[i]);     dfs(1, -1);     build(1, 1, n);     int q;     scanf( %d , &q);     while (q--) {       char op[4];       int v;       scanf( %s%d , op, &v);       if (op[0] ==  p )         update(1, in[v], ou[v]);       else         printf( %d n , query(1, in[v], ou[v]));     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 200007;   string s;   int q, n, cnt[maxn][26];   void Solve() {     int l, r;     cin >> l >> r;     if (l == r) {       cout <<  Yes  <<   n ;       return;     }     if (s[l] != s[r]) {       cout <<  Yes  <<   n ;       return;     }     int cnt = 0;     for (int i = 0; i < 26; i++) {       if (i == s[l] -  a ) continue;       int gau = ::cnt[r][i] - ::cnt[l - 1][i];       if (gau) cnt++;     }     if (cnt >= 2)       cout <<  Yes  <<   n ;     else       cout <<  No  <<   n ;   }   int32_t main() {     auto start = chrono::steady_clock::now();     ios_base::sync_with_stdio(0);     cin.tie(0);     if (fopen( test.inp ,  r )) freopen( test.inp ,  r , stdin);     cin >> s >> q;     n = s.length();     s =     + s;     for (int i = 1; i <= n; i++) {       for (int j = 0; j < 26; j++) {         cnt[i][j] = cnt[i - 1][j];         if (j == s[i] -  a ) cnt[i][j]++;       }     }     while (q--) Solve();     auto finish = chrono::steady_clock::now();     cerr << chrono::duration_cast<chrono::milliseconds>(finish - start).count();   }


#include <bits/stdc++.h>   using namespace std;   int n;   int a[300010];   int p[300010];   struct node {     int next[2] = {};     int cnt = 0;     int par;   };   node t[31 * 300010];   int root = 1;   int E = 2;   int main() {     ios_base::sync_with_stdio(false);     cin >> n;     for (int i = 0; i < n; i++) cin >> a[i];     for (int i = 0; i < n; i++) cin >> p[i];     for (int i = 0; i < n; i++) {       int u = root;       for (int j = 29; j >= 0; j--) {         int c;         if (p[i] & (1 << j))           c = 1;         else           c = 0;         if (!t[u].next[c]) {           t[u].next[c] = E++;           t[E - 1].par = u;         }         u = t[u].next[c];       }       while (u != 1) {         t[u].cnt++;         u = t[u].par;       }     }     for (int i = 0; i < n; i++) {       int x = a[i];       int u = root;       int val = 0;       for (int j = 29; j >= 0; j--) {         int c;         if (a[i] & (1 << j))           c = 1;         else           c = 0;         if (t[u].next[c] && t[t[u].next[c]].cnt) {           val ^= (1 << j) * c;           u = t[u].next[c];         } else {           val ^= (1 << j) * (!c);           u = t[u].next[!c];         }       }       while (u != 0) {         t[u].cnt--;         u = t[u].par;       }       x ^= val;       cout << x <<    ;     }   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 9;   const int mod1 = 999999937;   const int inf = 2e9;   const double eps = 1e-7;   int d[101][101];   int main() {     int n, m;     cin >> n >> m;     for (int i = 0; i < m; i++) {       int a, b, c;       cin >> a >> b >> c;       d[a - 1][b - 1] = c;     }     int ans = 0;     int w = n;     while (w--) {       for (int i = 0; i < n; i++) {         for (int j = 0; j < n; j++) {           for (int k = 0; k < n; k++) {             if (d[i][j] > 0 && d[j][k] > 0) {               int q = min(d[i][j], d[j][k]);               d[i][j] -= q;               d[j][k] -= q;               d[i][k] += q;             }           }         }       }     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         ans += d[i][j];       }     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:1024000000,1024000000 )   using namespace std;   const int maxn = 1e6 + 7;   const int INF = 1e9 + 7;   int n, k;   int a[maxn];   vector<int> fac[maxn];   int sum[maxn];   int L[maxn], R[maxn];   long long ans;   void ini() {     stack<int> st;     a[n + 1] = INF;     for (int i = 1; i < n + 1; i++) L[i] = 1;     for (int i = 1; i < n + 2; i++) {       int num = 0;       while (!st.empty() && a[st.top()] <= a[i]) {         int p = st.top();         st.pop();         R[p] = num;         L[i] += L[p];         num = L[p] + R[p];       }       st.push(i);     }   }   int query(int x, int l, int r) {     int a = lower_bound(fac[x].begin(), fac[x].end(), l) - fac[x].begin();     int b = upper_bound(fac[x].begin(), fac[x].end(), r) - fac[x].begin();     return b - a;   }   int main() {     scanf( %d%d , &n, &k);     for (int i = 1; i < n + 1; i++) scanf( %d , &a[i]);     for (int i = 1; i < n + 1; i++) sum[i] = (sum[i - 1] + a[i]) % k;     fac[0].push_back(0);     for (int i = 1; i < n + 1; i++) fac[sum[i]].push_back(i);     ini();     for (int i = 1; i < n + 1; i++) {       L[i] = i - L[i];       R[i] = i + R[i] + 1;     }     for (int i = 1; i < n + 1; i++) {       if (i - L[i] < R[i] - i) {         for (int j = L[i]; j < i; j++)           ans += query((sum[j] + a[i]) % k, i, R[i] - 1);       } else {         for (int j = i; j < R[i]; j++)           ans += query((sum[j] - a[i] % k + k) % k, L[i], i - 1);       }     }     printf( %I64d n , ans - n);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   inline T sqr(const T& x) {     return x * x;   }   template <class T>   inline string tostr(const T& a) {     ostringstream os(  );     os << a;     return os.str();   }   const int inf = 1999999999;   const double pi = acos(-1.0);   const double eps = 1e-9;   int main(int argc, char* argv[]) {     clock_t _ = clock();     cout << fixed << setprecision(15);     string s, t;     cin >> s >> t;     bool automaton = false, array = true;     int cnt1[26], cnt2[26];     memset((cnt1), (0), sizeof(cnt1));     memset((cnt2), (0), sizeof(cnt2));     for (__typeof((s).begin()) it = (s).begin(), _it = (s).end(); it != _it;          ++it) {       cnt1[*it -  a ]++;     }     for (__typeof((t).begin()) it = (t).begin(), _it = (t).end(); it != _it;          ++it) {       cnt2[*it -  a ]++;     }     if (s.size() > t.size()) automaton = true;     for (int i = 0, _i = (26); i < _i; ++i) {       if (cnt1[i] < cnt2[i]) {         automaton = array = false;         break;       }     }     int i2 = 0;     for (int i1 = 0, _i1 = (s.size()); i1 < _i1; ++i1) {       if (s[i1] == t[i2]) i2++;     }     if (i2 == t.size()) {       automaton = true;       array = false;     }     if (automaton && array)       cout <<  both  << (  n );     else if (automaton)       cout <<  automaton  << (  n );     else if (array)       cout <<  array  << (  n );     else       cout <<  need tree  << (  n );     return 0;   }


#include <bits/stdc++.h>   long long n, ans;   int main() {     scanf( %lld , &n);     for (long long i = 2; i / 2 <= n; i *= 2) {       ans += (n + i / 2 - 1) / i * (i / 2);     }     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long k;     cin >> k;     getchar();     char s[1000001];     cin >> s;     int a[strlen(s)];     long long sum = 0;     for (int i = 0; i < strlen(s); i++) {       sum += s[i] - 48;       a[i] = s[i] - 48;     }     k = k - sum;     sort(a, a + strlen(s));     int c = 0;     for (int i = 0; i < strlen(s); i++) {       if (k > 0) {         k -= (9 - a[i]);         c++;       } else         break;     }     cout << c << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n;     long long l, a;     cin >> n >> l >> a;     long long arr[n][2];     long long ans = 0;     for (int i = 0; i < n; i++) {       cin >> arr[i][0] >> arr[i][1];       if (i == 0) {         ans += arr[i][0] / a;       }       if (i != 0) {         ans = ans + (arr[i][0] - (arr[i - 1][0] + arr[i - 1][1])) / a;       }     }     if (n != 0)       ans = ans + (l - arr[n - 1][0] - arr[n - 1][1]) / a;     else       ans = l / a;     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   bitset<50000000> arr;   int primes[100100], pr = 0;   int n;   unsigned int A, B, C, D;   int main() {     cin >> n >> A >> B >> C >> D;     for (int i = 2; i <= 18000; i++) {       arr[i] = 1;     }     for (int i = 2; i <= 18000; i++) {       if (arr[i] == 0) continue;       primes[pr++] = i;       for (int j = i * i; j <= 18000; j += i) {         arr[j] = 0;       }     }     int st = 2;     unsigned int sol = 0;     while (st <= n) {       int en = min(st + 40000000, n);       int ln = en - st + 1;       for (int i = 0; i < ln; i++) {         arr[i] = 1;       }       for (int i = 0; i < pr; i++) {         int beg = max(primes[i] * primes[i],                       ((st + primes[i] - 1) / primes[i]) * primes[i]);         for (int j = beg - st; j < ln; j += primes[i]) {           arr[j] = 0;         }       }       for (int i = 0; i < ln; i++) {         if (arr[i] == 1) {           unsigned int rep = 0;           int cur_pr = st + i;           while (cur_pr <= n) {             rep += (unsigned int)(n / cur_pr);             if (cur_pr > n / (st + i)) {               break;             } else {               cur_pr *= (st + i);             }           }           sol += rep * (A * (st + i) * (st + i) * (st + i) +                         B * (st + i) * (st + i) + C * (st + i) + D);         }       }       st = en + 1;     }     cout << sol << endl;   }


#include <bits/stdc++.h>   using namespace std;   struct node {     int l;     int r;   } a[200005], b[2000005];   int cmpl(struct node n, struct node m) { return n.l < m.l; }   int cmpr(struct node n, struct node m) { return n.r < m.r; }   int main() {     int n, m;     while (~scanf( %d , &n)) {       int sum = 0;       for (int i = 0; i < n; i++) {         scanf( %d%d , &a[i].l, &a[i].r);       }       scanf( %d , &m);       for (int i = 0; i < m; i++) {         scanf( %d%d , &b[i].l, &b[i].r);       }       sort(a, a + n, cmpl);       sort(b, b + m, cmpr);       if (a[n - 1].l > b[0].r) {         sum = max(sum, a[n - 1].l - b[0].r);       }       sort(a, a + n, cmpr);       sort(b, b + m, cmpl);       if (b[m - 1].l > a[0].r) {         sum = max(sum, b[m - 1].l - a[0].r);       }       if (!sum)         printf( 0 n );       else         printf( %d n , sum);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const string FILENAME =   ;   const bool FILE_IO = 1;   const int INF = 1000000000;   void init() {     if (!FILENAME.empty()) {       freopen((FILENAME +  .in ).c_str(),  r , stdin);       freopen((FILENAME +  .out ).c_str(),  w , stdout);     }   }   int main() {     init();     int n, m;     cin >> n;     vector<int> arr(n);     vector<long long> s(n);     for (int i = 0; i < n; i++) {       cin >> arr[i];     }     cin >> m;     sort(arr.begin(), arr.end());     reverse(arr.begin(), arr.end());     s[0] = arr[0];     for (int i = 1; i < n; i++) {       s[i] += arr[i] + s[i - 1];     }     for (int i = 0; i < m; i++) {       int q;       long long ans = 0;       cin >> q;       ans = s[q - 2] + s[n - 1] - s[q - 1];       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100005, M = 100005;   inline int read() {     int x = 0;     char ch = getchar();     bool positive = 1;     for (; !isdigit(ch); ch = getchar())       if (ch ==  - ) positive = 0;     for (; isdigit(ch); ch = getchar()) x = x * 10 + ch -  0 ;     return positive ? x : -x;   }   inline void write(long long a) {     if (a >= 10) write(a / 10);     putchar( 0  + a % 10);   }   inline void writeln(long long a) {     if (a < 0) {       a = -a;       putchar( - );     }     write(a);     puts(  );   }   int sum, b[N], k, n, len, m, i, ll, rr, qian[N], hou[N];   long long tong[N], a[N], c[N], kind, an[N];   map<long long, int> Ma;   struct data {     int l, r, id, num;   } q[M];   inline void del1(int p) {     tong[a[p]]--;     if (hou[a[p]]) kind -= tong[hou[a[p]]];   }   inline void del2(int p) {     tong[a[p]]--;     if (qian[a[p]]) kind -= tong[qian[a[p]]];   }   inline void ins1(int p) {     if (hou[a[p]]) kind += tong[hou[a[p]]];     tong[a[p]]++;   }   inline void ins2(int p) {     if (qian[a[p]]) kind += tong[qian[a[p]]];     tong[a[p]]++;   }   inline bool cmp(data a, data b) {     return a.id < b.id || (a.id == b.id && a.r < b.r);   }   int main() {     n = read();     k = read();     len = sqrt(n);     for (i = 1; i <= n; i++) b[i] = read();     for (i = 1; i <= n; i++)       c[i] = a[i] = read() * (b[i] == 1 ? 1 : -1) + a[i - 1];     sort(&c[1], &c[n + 1]);     c[0] = c[1] - 1;     for (i = 1; i <= n; i++) {       if (c[i] != c[i - 1]) {         Ma[c[i]] = ++sum;       }     }     for (i = 1; i <= n; i++) {       qian[Ma[c[i]]] = Ma[c[i] - k];       hou[Ma[c[i]]] = Ma[c[i] + k];       a[i] = Ma[a[i]];     }     hou[0] = Ma[k];     m = read();     for (i = 1; i <= m; i++) {       q[i].l = read();       q[i].r = read();       q[i].id = q[i].l / len;       q[i].num = i;     }     sort(&q[1], &q[m + 1], cmp);     ll = q[1].l;     rr = q[1].l - 1;     for (i = 1; i <= m; i++) {       while (ll > q[i].l) ins1(--ll);       while (rr < q[i].r) ins2(++rr);       while (ll < q[i].l) del1(ll++);       while (rr > q[i].r) del2(rr--);       an[q[i].num] = kind + tong[hou[a[ll - 1]]];     }     for (i = 1; i <= m; i++) writeln(an[i]);   }


#include <bits/stdc++.h>   using namespace std;   long long int MOD;   long long int mod(long long int a) {     a %= MOD;     if (a < 0) a += MOD;     return a;   }   struct matrix {     int n, m;     long long int a[6][6];     matrix() {}     matrix(int n_, int m_) {       n = n_, m = m_;       for (int i = 0; i < n; i++)         for (int j = 0; j < m; j++) a[i][j] = 0;     }     matrix operator*(const matrix &t) {       int p = t.m;       matrix res(n, p);       for (int i = 0; i < n; i++) {         for (int j = 0; j < p; j++) {           for (int k = 0; k < m; k++) {             long long int v = mod(1ll * a[i][k] * t.a[k][j]);             res.a[i][j] = mod(res.a[i][j] + v);           }         }       }       return res;     }     void print() {       for (int i = 0; i < n; i++) {         for (int j = 0; j < m; j++) printf( %d  , a[i][j]);         printf(  n );       }       printf(  n );     }   };   matrix fpow(matrix a, long long int n) {     matrix ans(6, 6);     for (int i = 0; i < 6; i++) ans.a[i][i] = 1;     while (n > 0) {       if (n & 1) ans = ans * a;       a = a * a;       n >>= 1;     }     return ans;   }   int ar[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}};   int main() {     int x, y, dx, dy;     long long int t;     scanf( %d%d%d%d%d%lld , &MOD, &x, &y, &dx, &dy, &t);     matrix m(6, 6), v(6, 1);     for (int i = 0; i < 6; i++) {       for (int j = 0; j < 6; j++) m.a[i][j] = ar[i][j];     }     v.a[0][0] = x, v.a[1][0] = y, v.a[2][0] = dx, v.a[3][0] = dy, v.a[5][0] = 1;     matrix sol = fpow(m, t - 1) * v;     long long int sum = mod(sol.a[0][0] + sol.a[1][0]);     sum = mod(sum + t - 1);     dx = mod(sol.a[2][0] + sum);     dy = mod(sol.a[3][0] + sum);     x = mod(sol.a[0][0] + dx - 1) + 1;     y = mod(sol.a[1][0] + dy - 1) + 1;     printf( %d %d , x, y);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char pal[111];   int nn, L;   int dp[101][55][2];   bool calc[101][55][2];   pair<int, int> pai[101][55][2];   int go(int ini, int n, bool pos) {     int r1;     if (ini == L) {       pai[ini][n][pos] = make_pair(n, pos);       return (n % 2 != 0) * (-0x3f3f3f3f);     }     if (!calc[ini][n][pos]) {       calc[ini][n][pos] = true;       int resp = 0;       if (pal[ini] ==  F ) {         resp = go(ini + 1, n, pos) + pos - (!pos);         if (n)           r1 = go(ini + 1, n - 1, !pos);         else           r1 = -0x3f3f3f3f;         if (resp > r1) {           pai[ini][n][pos] = make_pair(n, pos);         } else {           resp = r1;           pai[ini][n][pos] = make_pair(n - 1, !pos);         }       } else {         resp = go(ini + 1, n, !pos);         if (n)           r1 = go(ini + 1, n - 1, pos) + pos - (!pos);         else           r1 = -0x3f3f3f3f;         if (resp > r1) {           pai[ini][n][pos] = make_pair(n, !pos);         } else {           resp = r1;           pai[ini][n][pos] = make_pair(n - 1, pos);         }       }       dp[ini][n][pos] = resp;     }     return dp[ini][n][pos];   }   void psol(int ind, int n, bool opa) {     if (ind == L) return;     if (n == pai[ind][n][opa].first)       cout << pal[ind];     else if (pal[ind] ==  T )       cout <<  F ;     else       cout <<  T ;     psol(ind + 1, pai[ind][n][opa].first, pai[ind][n][opa].second);   }   int main() {     while (scanf( %s %d , pal, &nn) == 2) {       L = strlen(pal);       memset(calc, false, sizeof(calc));       int r1 = go(0, nn, true);       int r2 = go(0, nn, false);       printf( %d n , max(r2, r1));     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int oo = 1e9 + 9;   const long long inf = 1e18 + 18;   const int max6 = 1e6 + 6;   const int modx = 1e9 + 7;   const int mody = 997;   const int base = 137;   int n, m;   int cnt[max6], a[max6], tmp[max6];   int f[3][1005][1005];   int b[3][1005][1005];   int Pow(int a, int b) {     if (b == 0) return 1;     int half = Pow(a, b / 2);     int res = 1ll * half * half % m;     if (b % 2) res = 1ll * res * a % m;     return res;   }   void update(int id, int j, int u) {     if (id == 1) {       for (; u > 0; u -= u & (-u)) b[id][j][u]++;     } else {       for (; u <= n; u += u & (-u)) b[id][j][u]++;     }   }   int get(int id, int j, int u) {     int res = 0;     if (id == 1) {       for (; u <= n; u += u & (-u)) res = res + b[id][j][u];     } else {       for (; u > 0; u -= u & (-u)) res = res + b[id][j][u];     }     return res;   }   int main() {     ios_base::sync_with_stdio(false);     int n, m;     cin >> n >> m;     for (int i = 1; i <= n; ++i) cin >> a[i];     for (int i = 1; i <= n; ++i) {       int u = a[i] % m;       if (cnt[u]) {         cout << 0;         return 0;       }       cnt[u]++;     }     int res = 1;     for (int i = 1; i <= n; ++i)       for (int j = i + 1; j <= n; ++j) res = 1ll * res * abs(a[i] - a[j]) % m;     cout << res;   }


#include <bits/stdc++.h>   const int N = 1000005;   int fa[N], h[N], nxt[N], adj[N], a[N], u, v, t, id[N], Id, ans[N], f[N], n, tot,       m;   inline int fd(register int x) { return fa[x] == x ? x : fa[x] = fd(fa[x]); }   inline void add() {     nxt[++t] = h[u], h[u] = t, adj[t] = v, id[t] = Id, nxt[++t] = h[v], h[v] = t,     adj[t] = u, id[t] = Id;   }   inline void mer() {     register int t1 = fd(u), t2 = fd(v);     if (t1 != t2) fa[t1] = t2, add();   }   inline void dfs(register int x) {     for (register int i = h[x], j; i; i = nxt[i])       if ((j = adj[i]) != f[x])         f[j] = x, dfs(j), a[x] += a[j], ans[id[i]] = (i & 1 ? a[j] : -a[j]);   }   inline void fr(int &num) {     num = 0;     char c = getchar();     int p = 1;     while (c <  0  || c >  9 ) c ==  -  ? p = -1, c = getchar() : c = getchar();     while (c >=  0  && c <=  9 ) num = num * 10 + c -  0 , c = getchar();     num *= p;   }   int main() {     fr(n);     for (register int i = 1; i <= n; ++i) fr(a[i]), tot += a[i], fa[i] = i;     if (tot) return puts( Impossible ), 0;     puts( Possible );     fr(m);     for (Id = 1; Id <= m; ++Id) fr(u), fr(v), mer();     dfs(1);     for (register int i = 1; i <= m; ++i) printf( %d n , ans[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string a;   string s;   int main() {     cin >> a >> s;     sort(s.rbegin(), s.rend());     for (int i = 0, j = 0; i < a.size(); i++) {       int ins = s[j] -  0 ;       int ina = a[i] -  0 ;       if (ina < ins && j < s.size()) {         a[i] = s[j++];       }     }     cout << a << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void ga(int N, int *A) {     for (int i(0); i < N; i++) scanf( %d , A + i);   }   struct lt {     char c;     long long T;     bool operator<(const lt &r) const { return c != r.c ? T < r.T : c < r.c; }     bool operator==(const lt &r) const { return c == r.c && T == r.T; }     bool operator!=(const lt &r) const { return c != r.c || T != r.T; }   } T[(1 << 20)], P[(1 << 20)], I[(1 << 20)];   long long S;   void preKMP(lt *p, int *f) {     *f = -1;     for (int i(1), k; p[i + 1].c; ++i) {       k = f[i - 1];       while (~k && p[k] != p[i - 1]) k = f[k];       f[i] = k + 1;     }   }   int N, M, n, m, a;   int sm(int b) {     if (!b) return 0;     if (T[b - 1].c != P[0].c || T[b - 1].T < P[0].T) return 0;     if (T[b + m - 2].c != P[m - 1].c || T[b + m - 2].T < P[m - 1].T) return 0;     return 1;   }   void KMP(lt *p, lt *t, int m) {     static int f[(1 << 20)];     preKMP(p, f);     for (int i(0), k(0); t[i].c;)       if (!~k)         ++i, k = 0;       else if (t[i] == p[k]) {         ++i;         if (++k == m) S += sm(i - k), k = f[k - 1], --i;       } else         k = f[k];   }   char c;   int main(void) {     scanf( %d%d , &N, &M);     for (int i(0); i < N; i++) {       scanf( %d-%c , &a, &c);       if (i && T[n - 1].c == c)         T[n - 1].T += a;       else         T[n++] = {c, a};     }     T[n].c = 0;     for (int i(0); i < M; i++) {       scanf( %d-%c , &a, &c);       if (i && P[m - 1].c == c)         P[m - 1].T += a;       else         P[m++] = {c, a};     }     P[m].c = 0;     if (m == 1) {       for (int i(0); i < n; i++)         if (T[i].c == P[0].c) S += max(0ll, T[i].T - P[0].T + 1);     } else if (m == 2)       for (int i(0); i < n - 1; i++)         S += T[i].c == P[0].c && T[i].T >= P[0].T && T[i + 1].c == P[1].c &&              T[i + 1].T >= P[1].T;     else if (m == 3)       for (int i(0); i < n - 1; i++)         S += T[i + 1] == P[1] && T[i].c == P[0].c && T[i].T >= P[0].T &&              T[i + 2].c == P[2].c && T[i + 2].T >= P[2].T;     else       KMP(P + 1, T, m - 2);     printf( %lld n , S);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long x;     cin >> x;     if (!x)       cout << 0 << endl;     else {       if (x < 0) x = -1 * x;       long long ans = 1, temp = 0;       while (temp < x) {         temp = temp + ans;         ans++;       }       ans--;       long long res = ans * (ans + 1) / 2 - x;       if (!res)         cout << ans << endl;       else if (res % 2) {         if (ans % 2) ans++;         cout << ans + 1 << endl;       } else         cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize(2)   #pragma warning(disable : 4996)   using namespace std;   const long long INF = 2147483647;   const double PI = acos(-1);   const int mod = 1e9 + 7;   char arr[121212];   int main() {     long long t;     cin >> t;     for (int j = 1; j <= t; j++) {       long long n;       cin >> n;       cin >> (arr + 1);       long long ans = 0;       bool sign = false;       while (sign == false) {         sign = true;         for (int i = 1; i <= n - 1; i++) {           if (arr[i] ==  A  && arr[i + 1] ==  P ) {             arr[i + 1] =  A ;             sign = false;             i = i + 1;           }         }         if (!sign) ans++;       }       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7, seed = 131, MAXN = 0;   struct Item {     string s;     int x;   };   int main() {     cin.tie(0);     cin.sync_with_stdio(0);     int t;     cin >> t;     while (t--) {       int n, m;       cin >> n >> m;       vector<string> arr(n);       for (int i = 0; i < n; ++i) cin >> arr[i];       queue<Item> q;       q.push({  , 0});       string str;       int curr, uwu;       for (int idx = 0; idx < m; ++idx) {         int qsize = q.size();         for (int _ = 0; _ < qsize; ++_) {           str = q.front().s;           curr = q.front().x;           q.pop();           for (char c =  a ; c <=  z ; ++c) {             uwu = 0;             for (int i = 0; i < n; ++i)               if (arr[i][idx] != c) uwu |= (1 << i);             if ((uwu & curr) == 0) q.push({str + c, uwu | curr});           }         }       }       if (q.empty())         cout << -1 <<   n ;       else         cout << q.front().s <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1000005;   int n, a[N], b[N], lst[N], pre[N], suf[N], pr[N], sf[N], cn[N], sta[N], top,       ans;   long long s[N][4], tag[N][4];   inline long long S2(const int x) { return (x + 1ll) * x >> 1; }   inline long long S(const int l, const int r) { return S2(r) - S2(l - 1); }   inline void pd(const int rt, const int l, const int r, const int x,                  const int i) {     s[rt][2] = s[rt][i ^ 1] * x, s[rt][i] = (r - l + 1ll) * x, tag[rt][i] = x,     !i ? s[rt][3] = S(l, r) * x : 0;   }   inline void pd(const int rt, const int l, const int r) {     const int mid = l + r >> 1, ls = rt << 1, rs = ls | 1;     tag[rt][0] ? pd(ls, l, mid, tag[rt][0], 0), pd(rs, mid + 1, r, tag[rt][0], 0),         tag[rt][0] = 0 : 0;     tag[rt][1] ? pd(ls, l, mid, tag[rt][1], 1), pd(rs, mid + 1, r, tag[rt][1], 1),         tag[rt][1] = 0 : 0;   }   inline void upd(const int rt, const int l, const int r, const int u,                   const int v, const int x, const int i) {     if (l >= u && r <= v) return pd(rt, l, r, x, i);     const int mid = l + r >> 1, ls = rt << 1, rs = ls | 1;     pd(rt, l, r);     u <= mid ? upd(ls, l, mid, u, v, x, i), 0 : 0,         v > mid ? upd(rs, mid + 1, r, u, v, x, i), 0 : 0;     s[rt][0] = s[ls][0] + s[rs][0], s[rt][1] = s[ls][1] + s[rs][1],     s[rt][2] = s[ls][2] + s[rs][2], s[rt][3] = s[ls][3] + s[rs][3];   }   inline long long que(const int rt, const int l, const int r, const int u,                        const int v, const int i) {     if (u > v) return 0;     if (l >= u && r <= v) return s[rt][i];     const int mid = l + r >> 1, ls = rt << 1, rs = ls | 1;     pd(rt, l, r);     if (v <= mid) return que(ls, l, mid, u, v, i);     if (u > mid) return que(rs, mid + 1, r, u, v, i);     return que(ls, l, mid, u, mid, i) + que(rs, mid + 1, r, mid + 1, v, i);   }   int main() {     scanf( %d , &n);     register int i, j;     for (i = 1; i <= n; ++i) scanf( %d , &a[i]), b[i] = a[i];     std::sort(b + 1, b + 1 + n), *b = std::unique(b + 1, b + 1 + n) - b - 1;     for (i = 1; i <= n; ++i)       a[i] = std::lower_bound(b + 1, b + 1 + *b, a[i]) - b,       pre[i] = lst[a[i]] + 1, lst[a[i]] = i;     for (i = 1; i <= *b; ++i) lst[i] = n + 1;     for (i = n; i; --i) suf[i] = lst[a[i]] - 1, lst[a[i]] = i;     for (i = n, top = 0; i; --i) {       while (top && pre[i] > pre[sta[top]]) --top;       pr[i] = top ? sta[top] - 1 : n, sta[++top] = i;     }     for (i = n, top = 0; i; --i) {       while (top && suf[i] < suf[sta[top]]) --top;       sf[i] = top ? sta[top] - 1 : n, sta[++top] = i;     }     for (i = n, j = n; i; --i) {       upd(1, 1, n, i, pr[i], pre[i], 0), upd(1, 1, n, i, sf[i], suf[i], 1),           ++cn[a[i]];       while (cn[a[i]] > 1) --cn[a[j]], --j;       ans = (ans + que(1, 1, n, i, j, 3) + que(1, 1, n, i, j, 1) * i -              S(i, j) * i - que(1, 1, n, i, j, 2)) %             1000000007;     }     printf( %d , ans < 0 ? ans + 1000000007 : ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 2;   void testCase() {     int n, k, cnt = 0, ans = 1, s = 0;     scanf( %d%d , &n, &k);     vector<int> a(n), fr(101), z(101);     for (int i = 0; i < n; ++i) {       scanf( %d , &a[i]);       if (fr[a[i]]++ == 0) ++cnt, ++s;       if (cnt == k + 1) cnt = 2, ans++;     }     if (s >= 2 && k == 1) {       puts( -1 );       return;     }     cout << ans << endl;   }   int main() {     int T = 1;     scanf( %d , &T);     while (T--) {       testCase();     }   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   const int maxn = 1e5 + 10;   int main() {     ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);     int n;     cin >> n;     vector<int> a(n);     for (int i = 0; i < n; ++i) cin >> a[i];     int ans = 0;     vector<int> b(n);     for (int k = 0; k < 26; ++k) {       for (int i = 0, mod = (1 << (k + 1)); i < n; ++i) b[i] = a[i] % mod;       sort(b.begin(), b.end());       long long cnt = 0;       int l1 = (1 << k), r1 = (1 << (k + 1)) - 1;       int l2 = (1 << (k + 1)) + (1 << k), r2 = (1 << (k + 2)) - 2;       for (int i = 0; i < n; ++i) {         int l = l1 - b[i], r = r1 - b[i];         cnt += upper_bound(b.begin(), b.begin() + i, r) -                lower_bound(b.begin(), b.begin() + i, l);       }       for (int i = 0; i < n; ++i) {         int l = l2 - b[i], r = r2 - b[i];         cnt += upper_bound(b.begin(), b.begin() + i, r) -                lower_bound(b.begin(), b.begin() + i, l);       }       if (cnt & 1) ans += (1 << k);     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, i, k, j, c;     while (scanf( %d%d , &n, &m) != EOF) {       c = 0;       char a[990][101], x;       for (i = 0; i < n; i++) scanf( %s , a[i]);       for (i = 0; i < n; i++) {         for (k = 0; k < m; k++) {           x = a[i][k];           for (j = 0; j < n; j++) {             if (x >= a[j][k])               continue;             else               break;           }           if (j == n) {             c = c + 1;             break;           }         }       }       printf( %d n , c);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int s[100010];   int main() {     long long n, x;     cin >> n >> x;     long long sum = 0, ans = 0;     for (int i = 0; i < n; i++) {       cin >> s[i];     }     sort(s, s + n);     int j = 0;     while (j < n) {       if (x < 1) x = 1;       ans += s[j] * x;       x--;       j++;     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 3e5;   int n;   pair<long long, long long> a[MAXN + 5];   priority_queue<long long, vector<long long>, greater<long long> > q;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> n;     for (int i = 1; i <= n; ++i) {       long long t, w;       cin >> t >> w;       a[i] = make_pair(t, w);     }     sort(a + 2, a + n + 1);     int ans = n, pos = n;     for (;;) {       for (; pos > 1 && a[pos].first > a[1].first; --pos)         q.push(a[pos].second - a[pos].first + 1);       ans = min(ans, (int)q.size() + 1);       if (!q.empty() && a[1].first >= q.top()) {         a[1].first -= q.top();         q.pop();       } else         break;     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline bool chmax(T& a, T b) {     if (a < b) {       a = b;       return true;     }     return false;   }   template <typename T>   inline bool chmin(T& a, T b) {     if (a > b) {       a = b;       return true;     }     return false;   }   const double EPS = 1e-10;   const double PI = acos(-1);   class EDividePoints {    public:     int N;     void rec(std::ostream& out, vector<pair<int, int>>& vec) {       vector<vector<int>> par(2);       for (int i = (0); i < (N); ++i)         par[((vec[i].first + vec[i].second) % 2 + 2) % 2].push_back(i + 1);       if (not par[0].empty() and (int)(par[0]).size() < N) {         out << (int)(par[0]).size() <<   n ;         for (auto u : par[0]) out << u <<    ;         out <<   n ;         return;       }       vector<vector<vector<int>>> ids(2, vector<vector<int>>(2));       for (int i = (0); i < (N); ++i) {         ids[(vec[i].first % 2 + 2) % 2][(vec[i].second % 2 + 2) % 2].push_back(i +                                                                                1);       }       for (int i = (0); i < (2); ++i)         for (int j = (0); j < (2); ++j)           if (not ids[i][j].empty() and (int)(ids[i][j]).size() < N) {             out << (int)(ids[i][j]).size() <<   n ;             for (auto u : ids[i][j]) out << u <<    ;             out <<   n ;             return;           }       for (int i = (0); i < (N); ++i) {         if (vec[i].first % 2) vec[i].first--;         if (vec[i].second % 2) vec[i].second--;         vec[i].first /= 2, vec[i].second /= 2;       }       rec(out, vec);     }     void solve(std::istream& in, std::ostream& out) {       ios_base::sync_with_stdio(false);       in.tie(nullptr), out.tie(nullptr);       in >> N;       vector<pair<int, int>> A(N);       for (int i = (0); i < (N); ++i) in >> A[i].first >> A[i].second;       rec(out, A);     }   };   int main() {     EDividePoints solver;     std::istream& in(std::cin);     std::ostream& out(std::cout);     solver.solve(in, out);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline T read() {     register T sum = 0;     register char cc = getchar();     int sym = 1;     while (cc !=  -  && (cc >  9  || cc <  0 )) cc = getchar();     if (cc ==  - ) sym = -1, cc = getchar();     sum = sum * 10 + cc -  0 ;     cc = getchar();     while (cc >=  0  && cc <=  9 ) sum = sum * 10 + cc -  0 , cc = getchar();     return sym * sum;   }   template <typename T>   inline T read(T &a) {     a = read<T>();     return a;   }   template <typename T, typename... Others>   inline void read(T &a, Others &...b) {     a = read(a);     read(b...);   }   struct Data {     int x, y, p;   } a[200010];   int n, l[200010], r[200010], t[200010];   long long ans1, ans2;   int lowbit(int x) { return x & -x; }   void change(int x, int y) {     for (int i = x; i <= n << 1; i += lowbit(i)) t[i] += y;   }   int query(int x) {     int res = 0;     for (int i = x; i; i -= lowbit(i)) res += t[i];     return res;   }   bool cmp1(const Data &a, const Data &b) { return a.x < b.x; }   bool cmp2(const Data &a, const Data &b) { return a.y > b.y; }   int main() {     read(n);     for (int i = 1; i <= n; i++) {       read(a[i].x, a[i].y);       if (a[i].x > a[i].y) swap(a[i].x, a[i].y);       a[i].p = i;     }     sort(a + 1, a + 1 + n, cmp1);     for (int i = 1; i <= n; i++) {       l[a[i].p] += query(a[i].x) + query(n << 1) - query(a[i].y);       change(a[i].y, 1);     }     memset(t + 1, 0, sizeof(int) * (n << 1));     for (int i = n; i >= 1; i--) {       r[a[i].p] = query(a[i].y);       change(a[i].y, 1);     }     memset(t + 1, 0, sizeof(int) * (n << 1));     sort(a + 1, a + 1 + n, cmp2);     for (int i = 1; i <= n; i++) {       l[a[i].p] += query(n << 1) - query(a[i].y);       change(a[i].x, 1);     }     ans1 = 1ll * n * (n - 1) * (n - 2) / 6;     for (int i = 1; i <= n; i++) {       ans1 -= 1ll * l[i] * r[i];       ans2 += 1ll * (l[i] + r[i]) * (n - l[i] - r[i] - 1);     }     printf( %lld n , ans1 - ans2 / 2);     return 0;   }


#include <bits/stdc++.h>   using ii = std::pair<int, int>;   bool visited[50001];   int nexts[50001];   int value[50001];   int n, start, x;   void input() {     for (int i = 1; i <= n; i++) {       scanf( %d %d , &value[i], &nexts[i]);     }   }   ii query(int pos) {     visited[pos] = true;     printf( ? %d n , pos);     fflush(stdout);     ii res;     scanf( %d %d , &res.first, &res.second);     return res;   }   int main() {     srand(time(nullptr));     scanf( %d %d %d , &n, &start, &x);     ii max = query(start);     if (max.first >= x) {       printf( ! %d n , max.first);       fflush(stdout);       return 0;     }     std::vector<int> pick;     for (int i = 1; i <= n; i++) {       if (i == start) continue;       pick.push_back(i);     }     std::random_shuffle(pick.begin(), pick.end());     for (int i = 0; i < std::min(n - 1, 1000); i++) {       auto q = query(pick[i]);       if (q.first < x && q.first > max.first) max = q;     }     if (max.second == -1) {       printf( ! -1 n );       fflush(stdout);       return 0;     }     for (int i = 0; i < 1000; i++) {       auto q = query(max.second);       if (q.first >= x) {         printf( ! %d n , q.first);         fflush(stdout);         return 0;       } else if (q.second == -1) {         printf( ! -1 n );         fflush(stdout);         return 0;       } else {         max = q;       }     }     while (true)       ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s, s1, s2;     cin >> s;     s1 = s;     sort(s1.begin(), s1.end());     s2 += s1[0];     for (int i = 1; i < s1.length(); i++) {       if (s1[i] != s1[i - 1]) s2 += s1[i];     }     int d = 0;     for (int j = s2.length() - 1; j >= 0; j--) {       for (int i = d; i < s.length(); i++) {         if (s2[j] == s[i]) cout << s[i], d = i + 1;       }     }     cout << endl;     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize(3,  Ofast ,  inline )   using namespace std;   mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());   const long long maxn = (long long)1e6 + 5;   const long long mod = 998244353;   const long long inf = 0x3f3f3f3f;   long long T = 1;   vector<long long> v[maxn], vec[maxn];   long long dep[maxn], pre[maxn];   long long maxx;   void dfs(long long now) {     maxx = max(maxx, dep[now]);     vec[dep[now]].push_back(now);     for (auto &to : v[now]) {       if (dep[to]) continue;       pre[to] = now;       dep[to] = dep[now] + 1;       dfs(to);     }   }   void solve() {     long long n, m;     cin >> n >> m;     maxx = 1;     for (long long i = 1; i <= n; ++i) v[i].clear(), vec[i].clear(), dep[i] = 0;     for (long long i = 1; i <= m; ++i) {       long long x, y;       cin >> x >> y;       v[x].push_back(y);       v[y].push_back(x);     }     dep[1] = 1;     dfs(1);     if (maxx > (n + 1) / 2) {       cout <<  PATH n ;       stack<long long> s;       long long now = vec[maxx][0];       while (now) {         s.push(now);         now = pre[now];       }       cout << s.size() <<   n ;       while (!s.empty()) {         cout << s.top() <<    ;         s.pop();       }       cout <<   n ;       return;     }     cout <<  PAIRING n ;     long long ans = 0;     for (long long i = 1; i <= maxx; ++i) {       ans += vec[i].size() / 2;     }     cout << ans <<   n ;     for (long long i = 1; i <= maxx; ++i) {       for (long long j = 0; j + 1 < vec[i].size(); j += 2) {         cout << vec[i][j] <<     << vec[i][j + 1] <<   n ;       }     }   }   signed main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     cin >> T;     while (T--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int int_inf = 0x7fffffff;   const long long ll_inf = ~(1ll << 63);   const double eps = 1e-7;   char *p1, *p2, buf[1 << 20];   inline int read() {     int f = 1, x = 0;     char ch;     while (!isdigit(         ch = (p1 == p2 &&                       (p2 = (p1 = buf) + fread(buf, 1, 1 << 20, stdin), p1 == p2)                   ? EOF                   : *p1++)))       if (ch ==  - ) f = -1;     x = ch -  0 ;     while (isdigit(         ch = (p1 == p2 &&                       (p2 = (p1 = buf) + fread(buf, 1, 1 << 20, stdin), p1 == p2)                   ? EOF                   : *p1++)))       x = x * 10 + ch -  0 ;     return x * f;   }   const int N = 1e6 + 10;   unordered_map<long long, int> m;   long long sa[N], sb[N];   int a[N], b[N], s[N], n;   int main() {     n = read();     for (int i = 1; i <= n; i++) a[i] = read(), sa[i] = sa[i - 1] + a[i];     for (int i = 1; i <= n; i++) b[i] = read(), sb[i] = sb[i - 1] + b[i];     m[0] = 0;     for (int i = 1; i <= n; i++) {       int p = s[i - 1];       while (sb[p] <= sa[i] && p <= n) p++;       s[i] = p - 1;       long long delt = sa[i] - sb[p - 1];       if (m.count(delt)) {         int x = m[delt];         cout << (i - x) << endl;         for (int j = x + 1; j <= i; j++) cout << j <<    ;         cout << endl;         cout << (s[i] - s[x]) << endl;         for (int j = s[x] + 1; j <= s[i]; j++) cout << j <<    ;         return 0;       }       m[delt] = i;     }     cout << -1;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int read() {     int x = 0;     char ch = getchar();     while (!isdigit(ch)) ch = getchar();     while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^  0 ), ch = getchar();     return x;   }   const int N = 1e7 + 5;   const long long mod = 998244353;   int ksm(int a, int b) {     int ans = 1;     while (b) {       if (b & 1) ans = 1ll * ans * a % mod;       a = 1ll * a * a % mod;       b >>= 1;     }     return ans;   }   int prime[N], kth[N], cnt;   bool is_not_prime[N];   void sieve(int n, int k) {     is_not_prime[0] = is_not_prime[1] = 1;     kth[1] = 1;     for (int i = 2; i <= n; i++) {       if (!is_not_prime[i]) prime[++cnt] = i, kth[i] = ksm(i, k);       for (int j = 1; j <= cnt && 1ll * prime[j] * i <= n; j++) {         if (i % prime[j] == 0) break;         prime[i * prime[j]] = 1;         kth[i * prime[j]] = 1ll * kth[i] * kth[prime[j]] % mod;       }     }   }   int inv[N];   void preinv(int n) {     inv[1] = 1;     for (int i = 2; i <= n; i++)       inv[i] = 1ll * inv[mod % i] * (mod - mod / i) % mod;   }   long long n, m, k, p, q, ivq, ivp;   int S[N];   int main() {     n = read(), m = read(), k = read();     sieve(k, k);     p = ksm(m, mod - 2), q = (1 - p + mod) % mod, ivq = ksm(q, mod - 2),     ivp = ksm(p, mod - 2);     preinv(k);     if (m == 1)       printf( %d n , ksm(n, k));     else if (n <= k) {       long long ans = 0;       for (int i = 0, xs1 = 1, xs2 = ksm(q, n), xs3 = 1, xs4 = 1; i <= n; i++,                xs1 = 1ll * xs1 * p % mod, xs2 = 1ll * xs2 * ivq % mod,                xs3 = 1ll * xs3 * (n - i + 1) % mod,                xs4 = 1ll * xs4 * inv[i] % mod)         ans =             (ans + 1ll * xs3 * xs4 % mod * kth[i] % mod * xs1 % mod * xs2 % mod) %             mod;       cout << ans;     } else {       S[k] = 1;       for (int i = k - 1, xs1 = mod - p,                xs2 = 1ll * (n - i - 1) * inv[k - i] % mod;            i >= 0; i--, xs1 = 1ll * xs1 * (mod - p) % mod,                xs2 = 1ll * xs2 * (n - i - 1) % mod * inv[k - i] % mod)         S[i] =             (1ll * S[i + 1] * (1 - p + mod) % mod + 1ll * xs2 * xs1 % mod) % mod;       long long ans = 0;       for (int i = 0, xs1 = 1, xs2 = 1; i <= k; i++,                xs1 = 1ll * xs1 * (n - i + 1) % mod * inv[i] % mod,                xs2 = 1ll * xs2 * p % mod)         ans = (ans + 1ll * kth[i] * xs1 % mod * S[i] % mod * xs2 % mod) % mod;       cout << ans;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     set<char> ss;     map<string, bool> mp;     long long l = 0;     for (long long i = 0; i < s.size(); i++) {       if (!mp[s]) l++;       mp[s] = true;       rotate(s.begin(), s.end() - 1, s.end());     }     cout << l << endl;   }