#include <bits/stdc++.h>   #pragma GCC optimize( Ofast,unroll-loops,no-stack-protector )   using namespace std;   int n, k, nrr = 1, t[502 * 1005];   string s;   struct point {     double x, y;     int ind;     point() {}     point(const point& a) {       x = a.x, y = a.y;       ind = a.ind;     }     point(double _x, double _y) {       x = _x;       y = _y;     }     point& operator-(point& a) {       point* r = new point(*this);       r->x -= a.x, r->y -= a.y;       return *r;     }     point& operator+(point& a) {       point* r = new point(*this);       r->x += a.x, r->y += a.y;       return *r;     }     point& operator*(double val) {       point* r = new point(*this);       r->x *= val, r->y *= val;       return *r;     }     point& operator/(double val) {       point* r = new point(*this);       r->x /= val, r->y /= val;       return *r;     }     bool operator<(const point& a) const {       if (fabs(x - a.x) < 1e-9) {         if (fabs(y - a.y) < 1e-9) return false;         return y < a.y;       }       return x < a.x;     }     bool operator==(const point& a) const {       if (fabs(x - a.x) < 1e-9)         if (fabs(y - a.y) < 1e-9) return true;       return false;     }   };   template <class T>   ostream& operator<<(ostream& out, vector<T> v) {     out << v.size() <<   n ;     for (auto e : v) out << e <<    ;     return out;   }   ostream& operator<<(ostream& out, point p) { return out << p.x <<     << p.y; }   double dx[] = {1, -1, -1, 1};   double dy[] = {1, -1, 1, -1};   long double dist(point a, point b) {     long double X = a.x - b.x;     long double Y = a.y - b.y;     return sqrt(X * X + Y * Y);   }   struct circle {     point o;     double r;     circle() {}     bool operator==(circle& c) {       if (fabs(c.r - r) > 1e-9) return false;       if (fabs(c.o.x - o.x) > 1e-9) return false;       if (fabs(c.o.y - o.y) > 1e-9) return false;       return true;     }     vector<point> intersect(circle c) {       long double p, h, a, area, d;       d = dist(o, c.o);       if (d > r + c.r) return {};       if (d < fabs(r - c.r)) return {};       a = 0.5 * (d + (r * r - c.r * c.r) / d);       h = sqrt(r * r - a * a);       point B = o + (c.o - o) * a / d;       point aa = c.o - o;       point ff(-aa.y, aa.x);       aa = ff * h / d;       return {B + aa, B - aa};     }   };   struct seg {     point a, b;   };   istream& operator>>(istream& in, point& p) { return in >> p.x >> p.y; }   istream& operator>>(istream& in, circle& c) { return in >> c.o >> c.r; }   istream& operator>>(istream& in, seg& s) { return in >> s.a >> s.b; }   long double area(point a, point b, point c) {     return a.x * b.y + b.x * c.y + c.x * a.y - a.y * b.x - b.y * c.x - c.y * a.x;     return (b.x - a.x) * (c.y - a.y) - (c.x - a.x) * (b.y - a.y);   }   circle c[550];   bool use[502 * 1000];   int C, V, E;   point pts[500 * 1000];   int sz = 0;   int get_p(point p) {     pts[++sz] = p;     pts[sz].ind = sz;   }   void dfs2(int k) {     use[k] = 1;     if (k == t[k]) C++;     if (!use[t[k]]) dfs2(t[k]);   }   inline int par(int k) {     if (k == t[k]) return k;     return t[k] = par(t[k]);   }   set<point> inters;   void unite(int i, int j) { t[par(i)] = par(j); }   int main() {     ios_base::sync_with_stdio(false);     cin >> n;     for (int i = 0; i <= 502 * 502; i++) t[i] = i;     for (int i = 1; i <= n; i++) cin >> c[i];     for (int i = 1; i <= n; i++)       for (int j = i + 1; j <= n; j++) {         if (c[i] == c[j]) swap(c[j], c[n]), n--, j--;       }     for (int i = 1; i <= n; i++) {       inters.clear();       for (int j = 1; j <= n; j++) {         if (i == j) continue;         auto in = c[i].intersect(c[j]);         for (auto p : in) {           inters.insert(p);         }       }       int init;       for (auto i : inters) {         sz++;         pts[sz] = i;         pts[sz].ind = sz;         if (!(i == *inters.begin()))           unite(sz, init);         else           init = sz;       }       E += inters.size();       if (inters.size() == 0) C++;     }     V = sz;     int u = 0;     for (int i = 1; i <= sz; i++) pts[i].ind = i;     sort(pts + 1, pts + sz + 1);     for (int i = 1; i <= sz; i++, u++) {       int j = i + 1;       while (j <= sz && pts[i] == pts[j]) {         unite(pts[i].ind, pts[j].ind);         j++;       }       i = j - 1;     }     for (int i = 1; i <= V; i++)       if (t[i] == i) C++;     V = u;     cerr <<  V               :            << V <<   n ;     cerr <<  E               :            << E <<   n ;     cout << E - V + C + 1 <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, t;     cin >> t;     while (t--) {       cin >> n;       vector<int> a(n);       int mx = 0;       for (auto &it : a) {         cin >> it;         mx = max(mx, it);       }       int r = n - 1;       int ind = -1;       for (int l = 0; l < n; l++) {         if (a[l] != mx)           continue;         else if (l > 0 && a[l - 1] != mx)           ind = l + 1;         else if (r > l && a[l + 1] != mx)           ind = l + 1;       }       cout << ind << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 998244353;   const int N = 100010;   int a[N];   bool cont[110][N];   long long f[N][110], sumf[N];   int main() {     ios::sync_with_stdio(false);     int n, k, len;     cin >> n >> k >> len;     for (int i = 1; i <= n; i++) cin >> a[i];     for (int j = 1; j <= k; j++) {       int cnt = 0;       for (int i = 1; i <= n; i++) {         if (a[i] == -1 || a[i] == j)           cnt++;         else           cnt = 0;         if (cnt >= len) cont[j][i] = true;       }     }     f[0][0] = 1;     sumf[0] = 1;     for (int i = 1; i <= n; i++) {       if (a[i] == -1)         for (int j = 1; j <= k; j++) {           f[i][j] = sumf[i - 1];           if (cont[j][i]) f[i][j] -= sumf[i - len] - f[i - len][j];           sumf[i] = (sumf[i] + f[i][j]) % MOD;         }       else {         f[i][a[i]] = sumf[i - 1];         if (cont[a[i]][i]) f[i][a[i]] -= sumf[i - len] - f[i - len][a[i]];         sumf[i] = (sumf[i] + f[i][a[i]]) % MOD;       }     }     cout << (sumf[n] + MOD) % MOD <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   const long long maxn = 1e5 + 1;   long long gcd(long long a, long long b) {     long long r;     while (b > 0) {       r = a % b;       a = b;       b = r;     }     return a;   }   int main() {     long long n, k, a, b, maxkq = 0, minkq = 1e18, l, kq, g, tmp;     cin >> n >> k >> a >> b;     tmp = n * k;     for (int i = 0; i < n; i++) {       l = (k * i + a - b) % tmp;       if (l < 0) l += n * k;       g = gcd(l, n * k);       kq = (n * k) / g;       if (kq < minkq) minkq = kq;       if (kq > maxkq) maxkq = kq;       l = (k * i + a + b) % tmp;       g = gcd(l, n * k);       kq = (n * k) / g;       if (kq < minkq) minkq = kq;       if (kq > maxkq) maxkq = kq;       l = (k * i - a + b) % tmp;       if (l < 0) l += n * k;       g = gcd(l, n * k);       kq = (n * k) / g;       if (kq < minkq) minkq = kq;       if (kq > maxkq) maxkq = kq;       l = (k * i - a - b) % tmp;       if (l < 0) l += n * k;       g = gcd(l, n * k);       kq = (n * k) / g;       if (kq < minkq) minkq = kq;       if (kq > maxkq) maxkq = kq;     }     cout << minkq <<     << maxkq;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1000000000;   const long long INF_LL = 1000000000000000000LL;   const double pi = 2 * acos(0.0);   template <class T>   void smin(T& a, T b) {     if (a > b) a = b;   }   template <class T>   void smax(T& a, T b) {     if (a < b) a = b;   }   template <class T>   T gcd(T a, T b) {     return b == 0 ? a : gcd(b, a % b);   }   template <class T>   T sqr(T a) {     return a * a;   }   template <typename Iterator>   void print(const char* fmt, Iterator begin, Iterator end,              const char* separator =    ) {     for (Iterator it = begin; it != end; ++it) {       if (it != begin) printf(separator);       printf(fmt, *it);     }     printf(  n );   }   long long t, a, b;   int main() {     scanf( %I64d%I64d%I64d , &t, &a, &b);     int ans = 0;     if (a == b) ++ans;     if (t > a || a > b) {       printf( %d n , ans);       return 0;     }     if (a > 1) {       vector<int> c;       while (b) c.push_back(b % a), b /= a;       for (int i(int((c).size()) - 1), _b(0); i >= _b; --i) {         b *= t;         b += c[i];       }       if (b == a) ++ans;       if (t == 1 && b == 1 && int((c).size()) > 2) ++ans;     } else {       if (b == 1) ans = -1;     }     if (ans == -1)       printf( inf n );     else       printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     srand(time(0));     if (rand() % 2 == 0)       cout <<  Odd ;     else       cout <<  Even ;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     cout << 3 * (n / 2);   }


#include <bits/stdc++.h>   using namespace std;   struct ppp {     int x, y, id;   } a[120000], b[120000];   int i, j, k, l, n, m, p, t;   bool cmp(const ppp& a, const ppp& b) {     return a.y < b.y || a.y == b.y && a.x > b.x;   }   bool cmp2(const ppp& a, const ppp& b) {     return a.x > b.x || a.x == b.x && a.y > b.y;   }   int main() {     scanf( %d%d%d , &n, &p, &m);     for (i = 1; i <= n; ++i) scanf( %d%d , &a[i].x, &a[i].y), a[i].id = i;     sort(a + 1, a + n + 1, cmp);     p -= m;     for (i = p + 1; i <= n; ++i) b[i].x = a[i].x, b[i].y = i;     sort(b + p + 1, b + n + 1, cmp2);     t = n;     for (i = p + 1; i <= p + m; ++i) {       t = min(t, b[i].y);       printf( %d  , a[b[i].y].id);     }     for (i = 1; i <= p; ++i) printf( %d  , a[t - i].id);   }


#include <bits/stdc++.h>   using namespace std;   const int Maxn = 1000 + 10;   const int INF = 0x7f7f7f7f;   const double eps = 1e-8;   const double pi = 3.1415926535897932384626433832795;   double p[Maxn], f[Maxn][Maxn];   long long L[Maxn], R[Maxn];   inline long long power(int a, int b) {     long long ans = 1;     for (int i = 1; i <= b; i++) ans *= a;     return ans;   }   double calc(long long a, long long b) {     char ch[50];     int len1, len2;     long long ansa = 0, ansb = 0;     a--;     sprintf(ch,  %I64d , a);     len1 = (int)strlen(ch);     for (int i = 1; i < len1; i++) ansa += power(10, i - 1);     if (ch[0] !=  1  && ch[0] !=  0 )       ansa += power(10, len1 - 1);     else if (ch[0] ==  1 )       ansa += a - power(10, len1 - 1) + 1;     sprintf(ch,  %I64d , b);     len2 = (int)strlen(ch);     for (int i = 1; i < len2; i++) ansb += power(10, i - 1);     if (ch[0] !=  1  && ch[0] !=  0 )       ansb += power(10, len2 - 1);     else if (ch[0] ==  1 )       ansb += b - power(10, len2 - 1) + 1;     return (ansb - ansa) * 1.0 / (b - a);   }   int main() {     int n, K;     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> L[i] >> R[i];       p[i] = calc(L[i], R[i]);     }     cin >> K;     f[0][0] = 1;     for (int i = 1; i <= n; i++) {       f[i][0] = 1;       for (int j = 1; j <= i; j++) f[i][0] *= (1 - p[j]);     }     for (int i = 1; i <= n; i++)       for (int j = 1; j <= n; j++)         f[i][j] = f[i - 1][j] * (1 - p[i]) + f[i - 1][j - 1] * p[i];     double ans = 0;     for (int i = 0; i <= n; i++)       if (100 * i >= K * n) ans += f[n][i];     printf( %.11f n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, m, k;     cin >> n >> m >> k;     vector<long long> v;     for (int i = 0; i < n; i++) {       long long x;       cin >> x;       v.push_back(x);     }     long long sum = 0;     int i;     for (i = n - 1; i >= 0; i--) {       sum += v[i];       if (sum > k) {         sum = 0;         i++;         m--;         if (m == 0) {           break;         }       }     }     if (i < 0) i = 0;     cout << n - i;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) {     long long x = a, y = b;     if (y > x) {       swap(x, y);     }     while (y != 0) {       x = x % y;       swap(x, y);     }     return (a * b) / x;   }   long long x, a, y, b, k, c;   bool checker(long long n, long long k, const vector<long long>& p) {     long long m = (long long)p.size() - 1;     if (m == 2) {     }     long long _c = n / c;     long long _a = n / a - _c;     long long _b = n / b - _c;     long long sum = 0;     for (long long i = 0; i < _c; ++i) {       sum += p[m - i] * (x + y) / 100;     }     for (long long i = _c; i < _c + _a; ++i) {       sum += p[m - i] * x / 100;     }     for (long long i = _c + _a; i < _c + _a + _b; ++i) {       sum += p[m - i] * y / 100;     }     return sum >= k;   }   signed main() {     long long q;     cin >> q;     vector<long long> p;     for (long long qwerty = 0; qwerty < q; ++qwerty) {       long long n;       cin >> n;       vector<long long>(n).swap(p);       for (long long i = 0; i < n; ++i) {         cin >> p[i];       }       sort(p.begin(), p.end());       cin >> x >> a >> y >> b >> k;       if (x < y) {         swap(x, y);         swap(a, b);       }       c = gcd(a, b);       long long L = 0;       long long R = n;       while (L + 1 < R) {         long long m = (L + R) / 2;         if (checker(m, k, p)) {           R = m;         } else {           L = m;         }       }       if (checker(R, k, p)) {         cout << R << endl;       } else {         cout << -1 << endl;       }     }   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   vector<vector<int> > adj;   bool acyclic = 1;   int topo[500005];   int ptr = 0;   bool visited[500005];   bool in_stack[500005];   void solve(int i) {     if (in_stack[i]) {       acyclic = 0;       return;     }     if (visited[i]) {       return;     }     visited[i] = 1;     in_stack[i] = 1;     for (auto m : adj[i]) {       solve(m);     }     in_stack[i] = 0;     topo[ptr++] = i;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int t;     cin >> t;     while (t--) {       cin >> n >> m;       adj.resize(n + 2);       for (int(i) = 1; (i) < (n + 2); (i)++) {         adj[i].clear();       }       vector<pair<int, int> > ans;       for (int(i) = 0; (i) < (m); (i)++) {         bool dir;         int u, v;         cin >> dir >> u >> v;         if (dir) {           adj[u].push_back(v);         }         if (!dir) {           ans.push_back(make_pair((u), (v)));         }       }       acyclic = 1;       ptr = 0;       memset((visited), 0, sizeof((visited)));       bool valid = 0;       for (int i = 1; i <= n; ++i) {         valid = 1;         solve(i);       }       if (!valid || !acyclic) {         cout <<  NO n ;         continue;       }       unordered_map<int, int> topo_map;       for (int i = 0; i < n; ++i) {         topo_map[topo[i]] = i;       }       cout <<  YES n ;       for (auto p : ans) {         if (topo_map[p.first] > topo_map[p.second]) {           cout << p.first <<     << p.second << endl;         } else {           cout << p.second <<     << p.first << endl;         }       }       for (int i = 1; i <= n; ++i) {         for (auto m : adj[i]) {           cout << i <<     << m << endl;         }       }     }   }


#include <bits/stdc++.h>   using namespace std;   using namespace chrono;   void _print(long long t) { cerr << t; }   void _print(int t) { cerr << t; }   void _print(string t) { cerr << t; }   void _print(char t) { cerr << t; }   void _print(long double t) { cerr << t; }   void _print(double t) { cerr << t; }   void _print(unsigned long long t) { cerr << t; }   template <class T, class V>   void _print(T a[], V sz);   template <class T, class V>   void _print(pair<T, V> p);   template <class T>   void _print(vector<T> v);   template <class T>   void _print(set<T> v);   template <class T, class V>   void _print(map<T, V> v);   template <class T>   void _print(multiset<T> v);   template <class T, class V>   void _print(pair<T, V> p) {     cerr <<  { ;     _print(p.first);     cerr <<  , ;     _print(p.second);     cerr <<  } ;   }   template <class T, class V>   void _print(T a[], V sz) {     for (V i = 0; i < sz; i++) {       _print(a[i]);       cerr <<    ;     }     cerr <<   n ;   }   template <class T>   void _print(vector<T> v) {     cerr <<  [  ;     for (T i : v) {       _print(i);       cerr <<    ;     }     cerr <<  ] ;     cerr <<   n ;   }   template <class T>   void _print(set<T> v) {     cerr <<  [  ;     for (T i : v) {       _print(i);       cerr <<    ;     }     cerr <<  ] ;     cerr <<   n ;   }   template <class T>   void _print(multiset<T> v) {     cerr <<  [  ;     for (T i : v) {       _print(i);       cerr <<    ;     }     cerr <<  ] ;   }   template <class T, class V>   void _print(map<T, V> v) {     cerr <<  [  ;     for (auto i : v) {       _print(i);       cerr <<    ;     }     cerr <<  ] ;   }   long long mod = LONG_MAX;   long long add(long long a, long long b) {     return ((a % mod) + (b % mod)) % mod;   }   long long mul(long long a, long long b) {     return ((a % mod) * (b % mod)) % mod;   }   long long sub(long long a, long long b) {     return ((a % mod) - (b % mod) + mod) % mod;   }   long long max(long long a, long long b) { return (a > b) ? a : b; }   long long gcd(long long a, long long b) {     if (b == 0) return a;     return gcd(b, a % b);   }   long long lcm(int a, int b) { return (a / gcd(a, b)) * b; }   long long fe(long long base, long long exp) {     long long ans = 1;     while (exp) {       if (exp & 1) ans = mul(ans, base);       base = mul(base, base);       exp >>= 1;     }     return ans;   }   long long fact(long long n) {     long long res = 1;     for (int i = 1; i <= n; i++) {       res = res * 1ll * i % mod;     }     return res;   }   long long modin(long long a) { return fe(a, mod - 2); }   long long nCr(long long a, long long b) {     if (a < b) return 0;     return mul(fact(a), mul(modin(fact(b)), modin(fact(a - b))));   }   void solve() {     long long n;     cin >> n;     vector<long long> eve, odd;     for (int i = 1; i < 2 * n + 1; i++) {       long long x;       cin >> x;       if (x % 2)         odd.push_back(i);       else         eve.push_back(i);     }     for (int i = 0; i < n - 1; i++) {       if (eve.size() > 1) {         cout << eve[eve.size() - 1] <<    ;         eve.pop_back();         cout << eve[eve.size() - 1] <<   n ;         eve.pop_back();       } else {         cout << odd[odd.size() - 1] <<    ;         odd.pop_back();         cout << odd[odd.size() - 1] <<   n ;         odd.pop_back();       }     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);     ;     int t = 1;     cin >> t;     while (t--) {       solve();     }     cerr <<  time taken :   << (float)clock() / CLOCKS_PER_SEC <<   secs           <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     string s;     cin >> s;     long long n = s.length();     s =  1  + s;     long long x[n + 1], y[n + 1], z[n + 1];     x[0] = 0;     y[0] = 0;     z[0] = 0;     for (long long i = 1; i <= n; i++) {       x[i] = x[i - 1];       y[i] = y[i - 1];       z[i] = z[i - 1];       if (s[i] ==  x ) x[i]++;       if (s[i] ==  y ) y[i]++;       if (s[i] ==  z ) z[i]++;     }     long long m;     cin >> m;     for (long long i = 0; i < m; i++) {       long long l, r;       cin >> l >> r;       long long len = r - l + 1;       long long cx = x[r] - x[l - 1];       long long cy = y[r] - y[l - 1];       long long cz = z[r] - z[l - 1];       if (len < 3) {         cout <<  YES  <<   n ;         continue;       }       if (abs(cx - cy) > 1 || abs(cx - cz) > 1 || abs(cz - cy) > 1)         cout <<  NO  <<   n ;       else         cout <<  YES  <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   inline T gcd(T a, T b) {     while (b) {       a %= b;       swap(a, b);     }     return a;   }   template <class T>   inline T lcm(T a, T b) {     return a / gcd(a, b) * b;   }   inline int nxt() {     int wow;     scanf( %d , &wow);     return wow;   }   inline long long int lxt() {     long long int wow;     scanf( %lld , &wow);     return wow;   }   inline double dxt() {     double wow;     scanf( %lf , &wow);     return wow;   }   long long int dp[2][5002];   int main() {     int n = nxt(), p = 0, c = 1;     long long int a[5002], b[5002];     for (int i = 1; i <= n; i++) b[i] = a[i] = lxt() - i;     sort(b + 1, b + n + 1);     dp[1][0] = (long long int)1e17;     for (int j = 1; j <= n; j++) dp[c][j] = min(dp[c][j - 1], abs(b[j] - a[1]));     for (int i = 2; i <= n; i++) {       swap(c, p);       dp[c][0] = (long long int)1e17;       for (int j = 1; j <= n; j++)         dp[c][j] = min(dp[c][j - 1], abs(b[j] - a[i]) + dp[p][j]);     }     cout << dp[c][n] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 10;   int n, ans, G[8][8], vis[8];   vector<pair<int, int> > Edge;   void dfs(int x) {     if (x > n) {       int res = 0;       for (auto tmp : Edge) {         int u = vis[tmp.first];         int v = vis[tmp.second];         if (u > v) swap(u, v);         if (!G[u][v]) res++, G[u][v] = 1;       }       ans = max(ans, res);       for (auto tmp : Edge) {         int u = vis[tmp.first];         int v = vis[tmp.second];         if (u > v) swap(u, v);         G[u][v] = 0;       }       return;     }     for (int i = 1; i <= 6; i++) {       vis[x] = i;       dfs(x + 1);     }   }   int main() {     int u, v, m;     scanf( %d%d , &n, &m);     for (int i = 1; i <= m; i++) {       scanf( %d%d , &u, &v);       Edge.push_back(make_pair(u, v));     }     dfs(1);     printf( %d n , ans);   }


#include <bits/stdc++.h>   using namespace std;   const int iinf = 1e9 + 7;   const long long linf = 1ll << 60;   const double dinf = 1e60;   template <typename T>   inline void scf(T &x) {     bool f = 0;     x = 0;     char c = getchar();     while ((c <  0  || c >  9 ) && c !=  - ) c = getchar();     if (c ==  - ) {       f = 1;       c = getchar();     }     while (c >=  0  && c <=  9 ) {       x = x * 10 + c -  0 ;       c = getchar();     }     if (f) x = -x;     return;   }   template <typename T1, typename T2>   void scf(T1 &x, T2 &y) {     scf(x);     return scf(y);   }   template <typename T1, typename T2, typename T3>   void scf(T1 &x, T2 &y, T3 &z) {     scf(x);     scf(y);     return scf(z);   }   template <typename T1, typename T2, typename T3, typename T4>   void scf(T1 &x, T2 &y, T3 &z, T4 &w) {     scf(x);     scf(y);     scf(z);     return scf(w);   }   inline char mygetchar() {     char c = getchar();     while (c ==     || c ==   n ) c = getchar();     return c;   }   template <typename T>   void chkmax(T &x, const T &y) {     if (y > x) x = y;     return;   }   template <typename T>   void chkmin(T &x, const T &y) {     if (y < x) x = y;     return;   }   const int N = 20;   int n, dig[N];   long long dp[N][N][2], g[65540][N][N];   long long table[65540];   int get(char c) { return c - (c >=  a  ?  a  - 10 :  0 ); }   bool check(long long x) {     long long ret = x, y = 0;     while (x) {       y |= (1ll << (x & 15));       x >>= 4;     }     return (ret ^ y) < ret;   }   void MEI() {     for (int x = 0; x < (65536); ++x) {       if (x) table[x] = table[x - 1];       table[x] += check(x);     }     for (int x = 0; x < (65536); ++x) {       int y = x, mx = 0;       while (y) {         chkmax(mx, y & 15);         y >>= 4;       }       for (int mx_front = 0; mx_front < (16); ++mx_front) {         if ((x >> max(mx_front, mx)) & 1) {           g[x][mx][mx_front]++;         }       }     }     for (int x = (1); x <= (65535); ++x)       for (int mx1 = 0; mx1 < (16); ++mx1)         for (int mx2 = 0; mx2 < (16); ++mx2) g[x][mx1][mx2] += g[x - 1][mx1][mx2];     return;   }   long long solve(long long x) {     memset((dp), (0), sizeof((dp)));     ;     if (x < 65536) return table[x];     long long y = x & 65535, ans = 0;     n = 0;     while (x) dig[n++] = x & 15, x >>= 4;     dp[n][0][1] = 1;     for (int i = (n); i >= (5); --i)       for (int mx = 0; mx < (16); ++mx)         for (int f = 0; f < (2); ++f)           if (dp[i][mx][f]) {             long long &t = dp[i][mx][f];             for (int y = 0; y < (16); ++y) {               if (f && y > dig[i - 1]) break;               dp[i - 1][max(mx, y)][f && y == dig[i - 1]] += t;             }           }     for (int mx1 = 0; mx1 < (16); ++mx1)       for (int mx2 = 0; mx2 < (16); ++mx2) {         ans +=             dp[4][mx1][0] * g[65535][mx2][mx1] + dp[4][mx1][1] * g[y][mx2][mx1];       }     return ans;   }   void ZI() {     int q;     scf(q);     while (q--) {       char s[N];       long long x = 0, res;       scanf( %s , s);       int n = strlen(s);       for (int i = 0; i < (n); ++i) x = x * 16 + get(s[i]);       res = -solve(x - 1);       scanf( %s , s);       n = strlen(s);       x = 0;       for (int i = 0; i < (n); ++i) x = x * 16 + get(s[i]);       res += solve(x);       printf( %I64d n , res);     }     return;   }   int main() {     MEI();     ZI();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7;   const int SIZE = 1e6 + 10;   int a[SIZE], b[SIZE], c[SIZE], cnt[SIZE];   bool used[SIZE];   vector<int> r[SIZE];   set<int> H;   void print_array(vector<int>& arr) {     for (int i = 0; i < (((int)(arr).size())); ++i) {       if (i) printf(   );       printf( %d , arr[i]);     }     puts(  );   }   bool check(int r_id) {     if (b[r_id] == c[r_id]) {       if (a[r_id] == b[r_id]) {         return cnt[c[r_id]] < 9;       } else {         return cnt[c[r_id]] < 8;       }     } else {       if (a[r_id] != b[r_id]) {         if (cnt[b[r_id]] == 9) return false;       }       if (a[r_id] != c[r_id]) {         if (cnt[c[r_id]] == 9) return false;       }       return true;     }   }   int main() {     int(n);     scanf( %d , &n);     for (int i = 0; i < (4 * n); ++i) {       scanf( %d%d%d , &(a[i]), &(b[i]), &(c[i]));       r[a[i]].push_back(i);       r[b[i]].push_back(i);       r[c[i]].push_back(i);       H.insert(i);     }     for (int i = 0; i < (n); ++i) cnt[i + 1] = 4;     puts( YES );     vector<int> an;     while (((int)(H).size())) {       int me = *H.begin();       used[me] = 1;       H.erase(me);       int now[3] = {a[me], b[me], c[me]};       cnt[a[me]]--;       cnt[b[me]]++;       cnt[c[me]]++;       an.push_back(me + 1);       for (int k = 0; k < (3); ++k) {         int id = now[k];         for (int i = 0; i < (((int)(r[id]).size())); ++i) {           int r_id = r[id][i];           if (!used[r_id]) {             if (check(r_id)) {               H.insert(r_id);             } else {               if (H.count(r_id)) H.erase(r_id);             }           }         }       }     }     print_array(an);     assert(((int)(an).size()) == n * 4);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char s[200001], t[200001];   int main() {     int i;     int n, m;     scanf( %d %d %s %s , &n, &m, s, t);     for (i = 0; i < n; i++) {       if (s[i] ==  * ) break;     }     if (i == n) {       if (n != m) {         printf( NO n );         return 0;       }       for (i = 0; i < n; i++) {         if (s[i] != t[i]) {           printf( NO n );           return 0;         }       }       printf( YES n );     } else {       int p = i;       if (m < n - 1) {         printf( NO n );         return 0;       }       for (i = 0; i < p; i++) {         if (s[i] != t[i]) {           printf( NO n );           return 0;         }       }       for (i = n - 1; i > p; i--) {         if (s[i] != t[m - (n - 1 - i) - 1]) {           printf( NO n );           return 0;         }       }       printf( YES n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     int t;     cin >> t;     while (t--) {       int a0, a1, a2, b0, b1, b2, ex0, ex1, ex2, ever, only0, only1, only2;       cin >> a0 >> a1 >> a2 >> b0 >> b1 >> b2 >> ever >> ex2 >> ex1 >> only0 >>           ex0 >> only1 >> only2;       int s0 = ever + ex1 + ex2 + only0, s1 = ever + ex0 + ex2 + only1,           s2 = ever + ex0 + ex1 + only2;       if (s0 > a0 + b0 || s1 > a1 + b1 || s2 > a2 + b2) {         cout <<  -1 n ;         continue;       }       int anime = ever + ex0 + ex1 + ex2;       bool ok = false;       for (int i = 0; i <= anime; i++) {         int luex0 = i + max(-a0, ex0 - anime),             ruex0 = ex0 + min(0, b0 + i - anime),             luex1 = i + max(-a1, ex1 - anime),             ruex1 = ex1 + min(0, b1 + i - anime),             luex2 = i + max(-a2, ex2 - anime),             ruex2 = ex2 + min(0, b2 + i - anime);         luex0 = max(0, luex0);         luex1 = max(0, luex1);         luex2 = max(0, luex2);         if (luex0 > ruex0 || luex1 > ruex1 || luex2 > ruex2 ||             min(i, ruex0 + ruex1 + ruex2) <                 max(max(0, i - ever), luex0 + luex1 + luex2))           continue;         int uex0 = max(luex0, max(0, i - ever) - ruex1 - ruex2),             uex1 = max(luex1, max(0, i - ever) - uex0 - ruex2),             uex2 = max(luex2, max(0, i - ever) - uex0 - uex1);         int uonly0 = min(only0, a0 - i + uex0),             uonly1 = min(only1, a1 - i + uex1),             uonly2 = min(only2, a2 - i + uex2);         ok = true;         cout << i - uex0 - uex1 - uex2 <<     << uex2 <<     << uex1 <<                  << uonly0 <<     << uex0 <<     << uonly1 <<     << uonly2 <<   n ;         break;       }       if (!ok) cout <<  -1 n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int i = 1, j = n, count = 0, k = 1;     while (k <= (n - 1)) {       count = count + ((i + j) % (n + 1));       if (k % 2 == 1) {         i++;       } else {         j--;       }       k++;     }     cout << count;   }


#include <bits/stdc++.h>   using namespace std;   struct point {     int x, y, z;     double dist(point& p) {       return sqrt((double)((p.x - x) * (p.x - x) + (p.y - y) * (p.y - y) +                            (p.z - z) * (p.z - z)));     }   };   int N;   point P[5005];   double solve() {     double res = 1e10;     for (int i = 1; i < N; i++) {       for (int j = i + 1; j < N; j++) {         double per = P[i].dist(P[j]) + P[i].dist(P[0]) + P[j].dist(P[0]);         if (per < res) res = per;       }     }     return res / 2.0;   }   int main() {     while (cin >> N) {       for (int i = 0; i < N; i++) {         cin >> P[i].x >> P[i].y >> P[i].z;       }       cout << setprecision(12) << solve() << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   inline vector<int> prefix(string p) {     vector<int> pi;     int m = p.size();     for (int(i) = (0); (i) < (m); ++(i)) pi.push_back(-1);     int k = -1;     for (int(i) = (1); (i) < (m); ++(i)) {       while (k != -1 && p[k + 1] != p[i]) k = pi[k];       if (p[k + 1] == p[i]) k++;       pi[i] = k;     }     return pi;   }   set<int> s;   inline void shift(string p) {     vector<int> pi = prefix(p);     int m = p.size();     int k = pi[m - 1];     while (k != -1) {       s.insert(m - k);       k = pi[k];     }   }   int main() {     ios_base::sync_with_stdio(false);     long long n, m;     cin >> n >> m;     string p;     cin >> p;     vector<int> pi = prefix(p);     shift(p);     vector<int> v;     for (int(i) = (0); (i) < (m); ++(i)) {       int a;       cin >> a;       v.push_back(a);     }     bool ok = true;     for (int(i) = (1); (i) < (v.size()); ++(i)) {       long long r = v[i], l = v[i - 1];       if (r < (l + p.size()) && s.find((r - l + 1)) == s.end()) {         cout << 0 << endl;         ok = false;         break;       }       if ((p.size() + r - 1) > n && ok) {         cout << 0 << endl;         ok = false;         break;       }     }     long long first = n;     if (ok) {       v.push_back(2000000000);       for (int(i) = (0); (i) < (v.size() - 1); ++(i))         first -= min((int)p.size(), v[i + 1] - v[i]);     }     long long ans = 1;     if (first < 0 && ok) {       cout << 0 << endl;       ok = false;     }     for (int(i) = (0); (i) < (first); ++(i))       ans = (ans * (long long)26) % 1000000007;     if (ok) cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, oh, wow;     cin >> n >> oh >> wow;     vector<int> res;     res.push_back(1);     int sum = 1;     for (int i = 0; i < wow; i++) {       res.push_back(sum + 1);       sum += sum + 1;     }     if (!wow && oh) res.push_back(1);     for (int i = 0; i < oh; i++) {       res.push_back(res.back() + 1);     }     while ((int)res.size() < n) res.push_back(1);     if ((int)res.size() > n) {       cout <<  -1 n ;       return 0;     }     for (int i = 0; i < n; i++)       if (res[i] > 50000) {         cout <<  -1 n ;         return 0;       }     for (int i = 0; i < n; i++) {       if (i) cout <<    ;       cout << res[i];     }     cout <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   long long rdtsc() {     long long tmp;     asm( rdtsc  :  =A (tmp));     return tmp;   }   inline int myrand() { return abs((rand() << 15) ^ rand()); }   inline int rnd(int x) { return myrand() % x; }   const int INF = (int)1e9 + 1;   const long double EPS = 1e-9;   void precalc() {}   int gcd(int a, int b) {     for (; b; a %= b, swap(a, b))       ;     return a;   }   int getFunc(const pair<int, int> &a, const pair<int, int> &b) {     return gcd(abs(a.first - b.first), abs(a.second - b.second));   }   long long inside(int n, pair<int, int> *ps, long long G = -1) {     if (n < 3) {       return 0;     }     bool needG = (G == -1);     if (needG) {       G = 0;     }     long long S2 = 0;     for (int i = 0; i < n; ++i) {       int in = (i == n - 1 ? 0 : (i + 1));       int dx = ps[in].first - ps[i].first;       S2 += (long long)dx * (ps[in].second + ps[i].second);       if (needG) {         G += getFunc(ps[i], ps[in]);       }     }     S2 = abs(S2);     long long res = S2 + 2 - G;     assert(!(res & 1));     return res / 2;   }   const int maxn = (int)1e5 + 10;   pair<int, int> ps[maxn * 2];   int n;   bool read() {     if (scanf( %d , &n) < 1) {       return 0;     }     for (int i = 0; i < n; ++i) {       scanf( %d%d , &ps[i].first, &ps[i].second);     }     return 1;   }   long long cnts[maxn];   int gcdn[maxn * 2];   int gcdc[maxn];   void solve() {     for (int i = 0; i < n; ++i) {       cnts[i] = 0;       ps[n + i] = ps[i];     }     for (int i = 0; i < n; ++i) {       gcdc[i] = gcdn[i] = gcdn[i + n] = getFunc(ps[i], ps[i + 1]);     }     long long whole = inside(n, ps);     long double up, down;     long double prob;     if (n <= 100) {       up = 1;       for (int i = 0; i < n; ++i) {         up *= 2;       }       down = up - (long double)(n * (n - 1) / 2 + n + 1);       up /= 8;       up -= 1;     } else {       prob = 1;       prob /= 8;     }     pair<int, int> tmp[3];     long double res = whole;     for (int k = 3; k < min(60, n); ++k) {       assert(k <= 150);       if (n <= 100) {         prob = up / down;       }       for (int i = 0; i < n; ++i) {         long long &cnt = cnts[i];         tmp[0] = ps[i], tmp[1] = ps[i + k - 2], tmp[2] = ps[i + k - 1];         int ngcd = getFunc(ps[i], ps[i + k - 1]);         cnt += inside(3, tmp, (long long)gcdc[i] + gcdn[i + k - 2] + ngcd) +                ngcd - 1;         gcdc[i] = ngcd;         res -= prob * cnt;       }       if (n <= 100) {         up -= 1;         up /= 2;       } else {         prob /= 2;       }     }     printf( %.18f n , (double)res);   }   int main() {     srand(rdtsc());     precalc();     while (1) {       if (!read()) {         break;       }       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[1000010];   long long cnt[1000010];   int main() {     ios::sync_with_stdio(0);     int n;     cin >> n;     long long s = 0;     for (int i = 0; i < n; ++i) {       cin >> a[i];       s += a[i];     }     if (s % 3 != 0)       cout <<  0 n ;     else {       s /= 3;       long long ss = 0;       for (int i = n - 1; i >= 0; --i) {         ss += a[i];         if (ss == s) cnt[i] = 1;       }       for (int i = n - 2; i >= 0; --i) cnt[i] += cnt[i + 1];       long long ans = 0;       ss = 0;       for (int i = 0; i + 2 < n; ++i) {         ss += a[i];         if (ss == s) ans += cnt[i + 2];       }       cout << ans <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main(int argc, char** argv) {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int x1, y1, x2, y2;     cin >> x1 >> y1 >> x2 >> y2;     double slope;     slope = x2 == x1 ? INT_MAX : (double)(y2 - y1) / (double)(x2 - x1);     if (slope == 0 || abs(slope) == 1 || abs(slope) == INT_MAX) {       if (slope == 0) {         int sideSq = abs(x2 - x1);         int next_y = y1 + sideSq;         if (next_y > 1000) {           next_y = y1 - sideSq;           if (next_y < -1000) {             cout << -1 <<   n ;             return 0;           }         }         cout << x1 <<     << next_y <<     << x2 <<     << next_y <<   n ;       } else if (slope == INT_MAX) {         int sideSq = abs(y2 - y1);         int next_x = x1 + sideSq;         if (next_x > 1000) {           next_x = x1 - sideSq;           if (next_x < -1000) {             cout << -1 <<   n ;             return 0;           }         }         cout << next_x <<     << y1 <<     << next_x <<     << y2 <<   n ;       } else {         cout << x1 <<     << y2 <<     << x2 <<     << y1 <<   n ;       }     } else {       cout << -1 <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int N, M;   int For[100000], Against[100000];   int TotalFor = 0, TotalAgainst = 0;   int Vote[100000];   int Sign[100000];   int J[100000];   int R[100000];   void Solve() {     int c = 0;     for (int i = 0; i < N; i++) {       J[i] = true;       if (For[i] + TotalAgainst - Against[i] != M) {         J[i] = false;       } else {         J[i] = true;         c++;       }     }     for (int i = 0; i < N; i++) {       if (!J[Vote[i]]) {         if (Sign[i] > 0)           R[i] = 2;         else           R[i] = 1;       } else if (c == 1) {         if (Sign[i] > 0)           R[i] = 1;         else           R[i] = 2;       }       if (R[i] == 0)         printf( Not defined n );       else if (R[i] == 1)         printf( Truth n );       else         printf( Lie n );     }   }   int main() {     scanf( %d %d , &N, &M);     char c;     for (int i = 0; i < N; i++) {       scanf(  %c%d , &c, &Vote[i]);       Vote[i]--;       if (c ==  + ) {         For[Vote[i]]++;         Sign[i] = 1;         TotalFor++;       } else {         Against[Vote[i]]++;         Sign[i] = -1;         TotalAgainst++;       }     }     Solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 3e5 + 10;   long long a[maxn];   int main() {     long long n, k, x;     cin >> n >> k;     for (int i = 1; i <= n; i++) {       cin >> x;       a[i] = a[i - 1] + x;     }     long long ans = a[n] * k;     sort(a + 1, a + n);     for (int i = 1; i < k; i++) ans -= a[i];     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>      using namespace std;      typedef long long ll;   typedef pair<int, int> pii;      const int N = 510;   const int MOD = 998244353;      int a[N];   int b[N];   int dp[N][N];      void add_self(int& x, int y) {       if ((x += y) >= MOD) {           x -= MOD;       }   }      void sub_self(int& x, int y) {       if ((x -= y) < 0) {           x += MOD;       }   }      int add(int x, int y) {       return add_self(x, y), x;   }      int sub(int x, int y) {       return sub_self(x, y), x;   }      int mul(int x, int y) {       return (ll)x * y % MOD;   }      int main() {       int n;       cin >> n;          for (int i = 0; i < n; i++) {           char c;           scanf(  %c , &c);           if (c ==  + ) {               b[i] = 1;               scanf( %d , a + i);           }       }          int answer = 0;          for (int k = 0; k < n; k++) {           if (!b[k]) {               continue;           }              memset(dp, 0, sizeof(dp));              for (int j = 0; j <= n; j++) {               dp[n][j] = 1;           }              for (int i = n - 1; ~i; --i) {               for (int j = 0; j < n; j++) {                   if (i == k) {                       dp[i][j] = dp[i + 1][j];                   } else {                       dp[i][j] = dp[i + 1][j];                       if (b[i]) {                           add_self(dp[i][j], dp[i + 1][j + (pii(a[i], i) < pii(a[k], k))]);                       } else if (i < k || j > 0) {                           add_self(dp[i][j], dp[i + 1][max(0, j - 1)]);                       }                   }               }           }              add_self(answer, mul(a[k], dp[0][0]));       }          cout << answer << endl;   }


#include <bits/stdc++.h>   using namespace std;      const int N = 102;   int t, n, m, r[N], b[N];      int main() {    ios::sync_with_stdio(0);    cin.tie(0);    cin >> t;    for(int ti = 1; ti <= t; ++ti) {     cin >> n;     for(int i = 1; i <= n; ++i) {      cin >> r[i];      r[i] += r[i - 1];     }     cin >> m;     for(int i = 1; i <= m; ++i) {      cin >> b[i];      b[i] += b[i - 1];     }     int fp = 0;     for(int i = 0; i <= n; ++i) {      for(int j = 0; j <= m; ++j) {       fp = max(fp, r[i] + b[j]);      }     }     cout << fp <<   n ;    }    return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxi = 1e6 + 6;   int b, di;   string a, c, t;   pair<int, int> d[maxi], d1[maxi];   int ob[maxi];   int main() {     cin >> b >> di;     cin >> a;     cin >> c;     int n = a.size();     int m = c.size();     for (int i = 0; i < m; i++) {       int id = 0;       for (int j = 0; j < n; j++)         if (c[i] == a[j]) id++;       if (!id) {         printf( %d n , 0);         return 0;       }     }     for (int i = 0; i < (m + 1); i++) t += a;     int cur = 0;     for (int j = 0; j < n; j++) {       cur = 0;       for (int i = j; i < (m + 1) * n; i++) {         if (c[cur] == t[i]) cur++;         if (cur == m) {           d[j] = {i / n, i % n};           break;         }       }     }     for (int j = 0; j < n; j++) {       int posl = -1;       int cur = 0;       int tt = 0;       for (int k = j; k < n; k++) {         if (a[k] == c[cur]) cur++;         if (cur == m) {           posl = k;           cur = 0;           tt++;         }       }       d1[j] = {tt, posl};     }     int tot = 0;     int ans = 0;     int c1 = 0;     while (ans < b) {       if (d[c1].first > 0) {         tot++;         ans += d[c1].first;         c1 = d[c1].second;         c1++;         if (c1 == n) {           c1 -= n;           ans++;           if (ans == b) {             printf( %d n , tot / di);             return 0;           }         }       } else {         tot += d1[c1].first;         c1 = d1[c1].second;         c1++;         if (c1 == n) {           c1 -= n;           ans++;           if (ans == b) {             printf( %d n , tot / di);             return 0;           }         }       }     }     tot--;     cout << tot / di <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     cin >> n;     cin >> k;     vector<string> s(n);     set<string> exist;     for (int i = 0; i < n; i++) {       cin >> s[i];       exist.insert(s[i]);     }     long long int count = 0;     for (int x = 0; x < n - 1; x++) {       for (int y = x + 1; y < n; y++) {         string temp =   ;         for (int i = 0; i < k; i++) {           if (s[x][i] == s[y][i]) {             temp += s[x][i];           } else if ((s[x][i] ==  S  && s[y][i] ==  T ) ||                      (s[x][i] ==  T  && s[y][i] ==  S )) {             temp +=  E ;           } else if ((s[x][i] ==  S  && s[y][i] ==  E ) ||                      (s[x][i] ==  E  && s[y][i] ==  S )) {             temp +=  T ;           } else if ((s[x][i] ==  E  && s[y][i] ==  T ) ||                      (s[x][i] ==  T  && s[y][i] ==  E )) {             temp +=  S ;           }         }         if (exist.find(temp) != exist.end()) {           count++;         }       }     }     cout << count / 3 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline long long max(long long a, long long b) { return a > b ? a : b; }   inline long long min(long long a, long long b) { return a > b ? b : a; }   template <typename T>   inline int read(T& res) {     long long x = 0, f = 1, flag = 0;     char ch;     flag = ch = getchar();     if (flag == -1) return -1;     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       flag = ch = getchar();       if (flag == -1) return -1;     }     while (ch >=  0  && ch <=  9  && flag != -1) {       x = (x << 1) + (x << 3) + (ch ^ 48);       flag = ch = getchar();     }     res = x * f;     return flag;   }   template <typename T, typename... Args>   inline int read(T& t, Args&... a) {     int res;     res = read(t);     if (res == -1) return -1;     res = read(a...);     return res;   }   const int maxn = 5511, mod = 1e9 + 9;   long long n, m, k;   long long qpow(long long x, long long y) {     long long ans = 1;     while (y) {       if (y & 1) ans = (ans * x) % mod;       y >>= 1;       x = (x * x) % mod;     }     return ans % mod;   }   long long A1, A2, C1[maxn], C2[maxn], w, b;   inline void solve() {     long long ans = 0, mx = max(w, b);     A1 = A2 = 1;     for (int i = 2; i <= w; i++) A1 = (A1 * i) % mod;     for (int i = 2; i <= b; i++) A2 = (A2 * i) % mod;     C1[2] = w - 1;     C2[2] = b - 1;     C1[1] = C2[1] = 1;     for (int i = 3; i <= mx; i++) {       long long inv = qpow(i - 1, mod - 2);       C1[i] = (C1[i - 1] * (w - i + 1) % mod * inv) % mod,       C2[i] = (C2[i - 1] * (b - i + 1) % mod * inv) % mod;     }     int lim = max(1, n - w);     for (int x = min(n - 2, b); x >= lim; x--) {       ans = (ans + (((((n - x - 1) * A1 % mod) * C1[n - x] % mod) * A2) % mod) *                        C2[x]) %             mod;     }     cout << ans << endl;   }   int main() {     ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);     int t = 1;     while (cin >> n >> w >> b) solve();   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, t;     scanf( %d%d , &n, &t);     int x, y;     vector<pair<int, int> > v(n);     for (int i = 0; i < (int)(n); ++i) {       scanf( %d%d , &x, &y);       v[i].first = x;       v[i].second = y;     }     int a[4] = {v[0].first, v[0].second, 7 - v[0].first, 7 - v[0].second};     bool f = true;     for (int i = 0; i < (int)(n); ++i) {       if (find(a, a + 4, v[i].first) == a + 4 or           find(a, a + 4, v[i].second) == a + 4)         f = false;     }     cout << (f ?  YES  :  NO );   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   void deb(T v[], long long n) {     if (false) cerr <<  ARRAY   :  ;     long long i;     for (i = 0; i < n; i++)       if (false) cerr << v[i] <<    ;     if (false) cerr << endl;   }   template <typename T>   void deb(set<T> s) {     if (false) cerr <<  SET     :  ;     for (auto it : s)       if (false) cerr << it <<    ;     if (false) cerr << endl;   }   template <typename T>   void deb(vector<T> v) {     if (false) cerr <<  VECTOR :  ;     long long i;     for (i = 0; i < v.size(); i++)       if (false) cerr << v[i] <<    ;     if (false) cerr << endl;   }   template <typename T>   void deb(stack<T> s) {     if (false) cerr <<  STACK   :  ;     stack<T> st = s;     while (st.size()) {       if (false) cerr << st.top() <<    ;       st.pop();     };     if (false) cerr << endl;   }   template <typename T>   void deb(queue<T> q) {     if (false) cerr <<  Queue   :  ;     queue<T> qq = q;     while (qq.size()) {       if (false) cerr << qq.front() <<    ;       qq.pop();     };     if (false) cerr << endl;   }   void deb(map<long long, long long> m) {     if (false) cerr <<  MAP :  ;     for (auto it : m)       if (false) cerr << it.first <<   :   << it.second << endl;   }   void deb(unordered_map<long long, long long> m) {     if (false) cerr <<  MAP :  ;     for (auto it : m)       if (false) cerr << it.first <<   :   << it.second << endl;   }   template <typename T>   T abs(T a) {     return a < 0 ? a * -1 : a;   }   void swap(long long &x, long long &y);   bool isPrime(long long n);   long long power(long long x, long long y, long long p);   long long gcdExtended(long long a, long long b, long long *x, long long *y);   long long modInverse(long long b, long long m);   long long modDivide(long long a, long long b, long long m);   void simpleSieve(long long N, bool[]);   void PrimeDivisorSieve(long long N, long long prime[]);   class nCrModPClass {    public:     vector<long long> f, fi;     long long N;     long long MOD;     long long poww(long long a, long long b, long long m) {       long long ans = 1;       while (b) {         if (b & 1) ans = (ans * a) % m;         b /= 2;         a = (a * a) % m;       }       return ans;     }     long long modinvv(long long k) { return poww(k, MOD - 2, MOD); }     nCrModPClass(long long size, long long mod) {       MOD = mod;       N = size + 10;       f.resize(N);       fi.resize(N);       f[0] = f[1] = 1;       for (long long i = 2; i < N; i++) f[i] = (f[i - 1] * i) % MOD;       fi[N - 1] = modinvv(f[N - 1]);       for (long long i = N - 2; i >= 0; i--) fi[i] = (fi[i + 1] * (i + 1)) % MOD;     }     long long nCrModPfromClass(long long n, long long r) {       if (r > n) return 0;       long long ret = f[n];       ret %= MOD;       ret *= fi[r];       ret %= MOD;       ret *= fi[n - r];       ret %= MOD;       return ret;     }   };   long long testCases;   long long minTocs(string a, char c) {     if (a.length() == 1) {       return a[0] != c;     }     string lef, rig;     long long dlef, drig;     dlef = drig = 0;     for (long long i = 0; i < a.length() / 2; i++) {       dlef += a[i] != c;       lef += a[i];     }     for (long long i = a.length() / 2; i < a.length(); i++) {       drig += a[i] != c;       rig += a[i];     }     return min(dlef + minTocs(rig, (char)c + 1),                minTocs(lef, (char)c + 1) + drig);   }   int main() {     testCases = 1;     cin >> testCases;     while (testCases--) {       long long n;       cin >> n;       string s;       cin >> s;       cout << minTocs(s,  a ) << endl;     }     return 0;   }   void simpleSieve(long long N, bool prime[]) {     long long i, j;     for (i = 0; i < N + 1; i++) prime[i] = true;     for (i = 2; i * i <= N; i++) {       if (prime[i]) {         for (j = i * i; j <= N; j += i) {           prime[j] = false;         }       }     }   }   void PrimeDivisorSieve(long long N, long long prime[]) {     long long i, j;     for (i = 0; i < N + 1; i++) prime[i] = i;     for (i = 2; i * i <= N; i++) {       if (prime[i] == i) {         for (j = i; j <= N; j += i) {           if (prime[j] == j) prime[j] = i;         }       }     }   }   void swap(long long &x, long long &y) {     x ^= y;     y ^= x;     x ^= y;   }   bool isPrime(long long n) {     if (n <= 1) return false;     for (long long i = 2; i < n; i++)       if (n % i == 0) return false;     return true;   }   long long power(long long x, long long y, long long p) {     long long res = 1;     x = x % p;     while (y > 0) {       if (y & 1) res = (res * x) % p;       y = y >> 1;       x = (x * x) % p;     }     return res;   }   long long gcdExtended(long long a, long long b, long long *x, long long *y) {     if (a == 0) {       *x = 0, *y = 1;       return b;     }     long long x1, y1;     long long gcd = gcdExtended(b % a, a, &x1, &y1);     *x = y1 - (b / a) * x1;     *y = x1;     return gcd;   }   long long modInverse(long long b, long long m) {     long long x, y;     long long g = gcdExtended(b, m, &x, &y);     if (g != 1) return -1;     return (x % m + m) % m;   }   long long modDivide(long long a, long long b, long long m) {     a = a % m;     long long inv = modInverse(b, m);     if (inv == -1)       return -1;     else       return (inv * a) % m;   }


#include <bits/stdc++.h>   using namespace std;   int n;   int m;   int p[100];   int f() {     int r = 0;     for (int i = 0; i < n; i++) {       int m = p[i];       for (int j = i; j < n; j++) {         if (m > p[j]) m = p[j];         r += m;       }     }     return r;   }   void print() {     for (int i = 0; i < n; i++) {       cout << p[i] <<    ;     }     cout << endl;   }   int main() {     scanf( %d %d , &n, &m);     for (int i = 99; i >= 0; i--) {       p[i] = i + 1;     }     int ma = f();     iota(p, p + 100, 1);     int i = 0;     do {       if (f() == ma) {         i++;         if (i == m) {           print();           break;         }       }     } while (next_permutation(p, p + n));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string a, b, c, d;   int pref[123456];   int main() {     int n, k;     cin >> n >> k;     string s;     cin >> s;     s =  .  + s;     for (int i = 1; i < s.length(); i++) {       pref[i] = pref[i - 1];       if (s[i] ==  0 ) pref[i]++;     }     int ans = INT_MAX;     for (int i = 1; i < s.length(); i++) {       if (s[i] ==  0 ) {         int lo = k / 2;         int hi = s.length() - 1;         while (hi - lo > 2) {           int mid = (lo + hi) / 2;           int lft = max(0, i - mid);           int cccc = s.length() - 1;           int rt = min(cccc, i + mid);           if (pref[rt] - pref[lft - 1] < k + 1)             lo = mid;           else             hi = mid;         }         while (lo <= hi) {           int lft = max(0, i - lo);           int cccc = s.length() - 1;           int rt = min(cccc, i + lo);           if (pref[rt] - pref[lft - 1] < k + 1) lo++;           if (pref[rt] - pref[lft - 1] >= k + 1) break;         }         ans = min(ans, lo);       }     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }   int main() {     int n;     cin >> n;     int a[100005];     for (int i = 0; i < n; i++) cin >> a[i];     sort(a, a + n);     int inter = a[1] - a[0];     for (int i = 2; i < n; i++) {       inter = gcd(inter, a[i] - a[i - 1]);     }     int cnt = 0;     for (int i = 1; i < n; i++) {       cnt += (a[i] - a[i - 1]) / inter - 1;     }     printf( %d n , cnt);   }


#include <bits/stdc++.h>   using namespace std;   struct Meth {     int hud, ten;     void init(int hud, int ten) { this->hud = hud, this->ten = ten; }     bool operator==(const class Meth &ans) const {       return hud == ans.hud && ten == ans.ten;     }   };   bool cmpC(const struct Meth &ans1, const struct Meth &ans2) {     return ans1.hud > ans2.hud;   }   bool cmpH(const struct Meth &ans1, const struct Meth &ans2) {     return ans1.ten > ans2.ten;   }   struct Comb {     Meth ci, ha;     int chud, cten;     void init(Meth a, Meth b) {       ci.init(a.hud, a.ten), ha.init(b.hud, b.ten);       chud = ci.hud + ha.hud, cten = ci.ten + ha.ten;     }     bool operator<(const class Comb &ans) const {       return (cmpC(ci, ans.ci) || (ci == ans.ci && cmpH(ha, ans.ha)));     }   };   Meth mat[3];   Comb comb[9];   int cnt, cnthud, cntten;   void Prepare() {     for (int i = 0; i < 3; i++) mat[i].init(i, 22 - i * 10);     cnt = 0;     for (int i = 0; i < 3; i++)       for (int j = 0; j < 3; j++) comb[cnt++].init(mat[i], mat[j]);     sort(comb, comb + cnt);   }   int main() {     Prepare();     while (scanf( %d%d , &cnthud, &cntten) != EOF) {       for (int i = 0; i < cnt; i++) {         if (cnthud >= comb[i].chud && cntten >= comb[i].cten) {           int a = cntten / comb[i].cten;           if (comb[i].chud != 0) a = min(a, cnthud / comb[i].chud);           cnthud -= a * comb[i].chud, cntten -= a * comb[i].cten;         }       }       if (cnthud * 100 + cntten * 10 >= 220 && cntten >= 2) {         printf( Ciel n );       } else {         printf( Hanako n );       }     }     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC target( avx,avx2,fma )   using namespace std;   const long long MOD = 1000000007;   const long long mod = 1000000007;   const int Nmax = 2000006;   long long gcd(long long a, long long b) {     if (a == 0) {       return b;     }     return gcd(b % a, a);   }   int lcm(int a, int b) { return (a * b) / gcd(a, b); }   bool isPrime(long long n) {     for (int i = 2; i <= sqrt(n); i++)       if (n % i == 0) return 0;     return 1;   }   void binaryRepresentation(int x) {     for (int i = 31; i >= 0; i--) {       if (x & (1 << i))         cout <<  1 ;       else         cout <<  0 ;     }   }   long long combination(long long n, long long r) {     if (r == n || r == 0) {       return 1LL;     }     return combination(n - 1, r - 1) + combination(n - 1, r);   }   bool isPowerOfTwo(long long n) {     if (n == 0) return false;     return (ceil(log2(n)) == floor(log2(n)));   }   long long power(long long a, long long b) {     long long ans = 1;     while (b) {       if (b & 1) ans = (ans * a) % MOD;       b /= 2;       a = (a * a) % MOD;     }     return ans % MOD;   }   long long inverse(long long i) {     if (i == 1) return 1;     return (MOD - ((MOD / i) * inverse(MOD % i)) % MOD + MOD) % MOD;   }   bool cmp(const pair<long long, long long> &a,            const pair<long long, long long> &b) {     if (a.first == b.first) return a.second < b.second;     return a.first < b.first;   }   string toString(long long a) {     ostringstream temp;     temp << a;     return temp.str();   }   int main() {     long long n, k;     cin >> n >> k;     long long ct = 1;     if (k == 1) {       cout << n;       return 0;     }     while (ct <= n) {       ct = ct * 2;     }     cout << ct - 1;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     scanf( %d%d , &n, &k);     char a[4][n];     for (int i = 0; i < 4; i++)       for (int j = 0; j < n; j++) a[i][j] =  . ;     if (!k) {       printf( YES n );       for (int i = 0; i < 4; i++) {         for (int j = 0; j < n; j++) printf( . );         printf(  n );       }       return 0;     }     if (k == 2 * (n - 2)) {       printf( YES n );       for (int i = 0; i < 4; i++) {         for (int j = 0; j < n; j++) {           if (i == 0 || i == 3 || j == 0 || j == n - 1)             printf( . );           else             printf( # );         }         printf(  n );       }       return 0;     }     if (k > 2 * (n - 2)) {       printf( NO n );       return 0;     } else       printf( YES n );     if (k % 2 == 0) {       for (int i = 1; i < 3 && k > 0; i++)         for (int j = 1; j < n / 2 && k > 0; j++) {           a[i][j] = a[i][n - j - 1] =  # ;           k -= 2;         }     } else {       for (int i = 1; i < 3 && k > 1; i++)         for (int j = 1; j < n / 2 && k > 1; j++) {           a[i][j] = a[i][n - j - 1] =  # ;           k -= 2;         }       a[1][n / 2] =  # ;     }     for (int i = 0; i < 4; i++) {       for (int j = 0; j < n; j++) printf( %c , a[i][j]);       printf(  n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-7;   int ary[10005];   int bry[10005];   vector<pair<int, int> > ans;   int pivot[31], pid[31];   int pivot2[31], pid2[31];   bool vis[10005];   void solve(int n, int a[]) {     for (int i = 0; i < 31; ++i) pid[i] = -1;     for (int k = 0; k < n; ++k) {       int v = a[k];       for (int i = 31 - 1; i >= 0; --i) {         if (pid[i] == -1) continue;         if (v & (1 << i)) v ^= pivot[i], ans.push_back(make_pair(k, pid[i]));       }       if (v == 0) continue;       for (int i = 31 - 1; i >= 0; --i) {         if (v & (1 << i)) {           assert(pid[i] == -1);           pivot[i] = v, pid[i] = k;           for (int j = 0; j < 31; ++j)             if (pid[j] != -1 and i != j and pivot[j] & (1 << i))               pivot[j] ^= pivot[i], ans.push_back(make_pair(pid[j], pid[i]));           break;         }       }     }   }   bool solve3(vector<pair<int, int> > candi);   bool solve2(int n, int a[]) {     for (int k = 0; k < n; ++k) {       if (vis[k]) continue;       int v = a[k];       for (int i = 31 - 1; i >= 0; --i) {         if (pid[i] == -1) continue;         if (v & (1 << i)) v ^= pivot[i], ans.push_back(make_pair(k, pid[i]));       }       if (v != 0) return false;     }     vector<pair<int, int> > candi;     for (int i = 31 - 1; i >= 0; --i)       if (pid[i] != -1) candi.push_back(make_pair(a[pid[i]], pid[i]));     return solve3(candi);   }   bool solve3(vector<pair<int, int> > candi) {     vector<pair<int, int> > buf;     for (int i = 0; i < 31; ++i) pid2[i] = -1;     for (const auto &p : candi) {       int k = p.second;       int v = p.first;       for (int i = 31 - 1; i >= 0; --i) {         if (pid2[i] == -1) continue;         if (v & (1 << i)) v ^= pivot2[i], buf.push_back(make_pair(k, pid2[i]));       }       if (v == 0) continue;       for (int i = 31 - 1; i >= 0; --i) {         if (v & (1 << i)) {           assert(pid2[i] == -1);           pivot2[i] = v, pid2[i] = k;           for (int j = 0; j < 31; ++j)             if (pid2[j] != -1 and i != j and pivot2[j] & (1 << i))               pivot2[j] ^= pivot2[i], buf.push_back(make_pair(pid2[j], pid2[i]));           break;         }       }     }     for (int i = 31 - 1; i >= 0; --i) {       int a = pid[i];       int b = pid2[i];       if (a == -1 and b == -1) continue;       if (a == -1 and b != -1)         return false;       else if (a != -1 and b == -1)         ans.push_back(make_pair(a, a));       else {         int d = pivot[i] ^ pivot2[i];         for (int j = i - 1; j >= 0; --j)           if (pid[j] != -1 and d & (1 << j))             d ^= pivot[j], ans.push_back(make_pair(pid[i], pid[j]));         if (d != 0) return false;         if (a == b) continue;         ans.push_back(make_pair(pid[i], b));         ans.push_back(make_pair(b, pid[i]));         ans.push_back(make_pair(pid[i], b));         for (int j = 0; j < 31; ++j)           if (pid[j] == b) {             swap(pid[i], pid[j]);             break;           }       }     }     reverse((buf).begin(), (buf).end());     for (const auto &p : buf) ans.push_back(p);     return true;   }   int main() {     int n;     scanf( %d , &n);     for (int i = 0; i < n; ++i) scanf( %d , &ary[i]);     solve(n, ary);     for (int i = 0; i < 31; ++i)       if (pid[i] != -1) vis[pid[i]] = true;     for (int i = 0; i < n; ++i) scanf( %d , &bry[i]);     bool posi = solve2(n, bry);     if (not posi)       printf( -1 );     else {       printf( %d n , ((int)(ans).size()));       for (const auto &p : ans) printf( %d %d n , p.first + 1, p.second + 1);     }   }


#include <bits/stdc++.h>   int n;   struct camel {     int x, d;     inline bool operator<(const camel& a) const { return x < a.x; }   } c[105];   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) scanf( %d%d , &c[i].x, &c[i].d);     std::sort(c, c + n);     for (int i = 0; i < n; i++)       for (int j = i; j < n; j++)         if ((c[i].x + c[i].d == c[j].x) && (c[j].x + c[j].d == c[i].x)) {           puts( YES );           return 0;         }     puts( NO );   }


#include <bits/stdc++.h>   using namespace std;   const double pi = acos(-1.);   const double eps = 1e-6;   int n, d;   int main() {     scanf( %d%d , &n, &d);     if (n == 1)       printf( %d n , d);     else {       if (d == 0) {         puts( No solution );       } else {         printf( %d , 1);         for (int i = 0; i < n - 2; i++) printf( %d , 0);         printf( %d n , d - 1);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   vector<pair<int, int> > ans;   int a[1000000];   int b[1000000];   int main() {     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a[i];     }     for (int i = 0; i < n; i++) {       cin >> b[i];     }     for (int i = 0; i < n; i++) {       if (b[i] == a[i])         continue;       else {         for (int j = i + 1; j < n; j++) {           if (b[j] == a[i]) {             for (int k = j; k > i; k--) {               swap(b[k], b[k - 1]);               ans.push_back(make_pair(k - 1, k));             }             break;           }         }       }     }     cout << ans.size() << endl;     for (int i = 0; i < ans.size(); i++) {       cout << ++ans[i].first <<     << ++ans[i].second << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main(int argc, char const *argv[]) {     int n;     cin >> n;     int a[n];     int sum = 0, ans = 0;     for (int i = 0; i < n; i++) {       cin >> a[i];       sum += a[i];     }     for (int i = 0; i < n; i++)       if (!((sum - a[i]) % 2)) ans++;     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class c>   struct rge {     c b, e;   };   template <class c>   rge<c> range(c i, c j) {     return rge<c>{i, j};   }   template <class c>   auto dud(c* x) -> decltype(cerr << *x, 0);   template <class c>   char dud(...);   struct debug {     ~debug() { cerr << endl; }     template <class c>     typename enable_if<sizeof dud<c>(0) != 1, debug&>::type operator<<(c i) {       cerr << boolalpha << i;       return *this;     }     template <class c>     typename enable_if<sizeof dud<c>(0) == 1, debug&>::type operator<<(c i) {       return *this << range(begin(i), end(i));     }     template <class c, class b>     debug& operator<<(pair<b, c> d) {       return *this <<  (  << d.first <<  ,   << d.second <<  ) ;     }     template <class c>     debug& operator<<(rge<c> d) {       *this <<  [ ;       for (auto it = d.b; it != d.e; ++it) *this <<  ,   + 2 * (it == d.b) << *it;       return *this <<  ] ;     }   };   const long long p = 1e9 + 7;   long long factmod(long long n) {     long long res = 1;     while (n > 1) {       res = (res * ((n / p) % 2 ? p - 1 : 1)) % p;       for (long long i = 2; i <= n % p; ++i) res = (res * i) % p;       n /= p;     }     return res % p;   }   long long binpow(long long a, long long b, long long m) {     a %= m;     long long res = 1;     while (b > 0) {       if (b & 1) res = res * a % m;       a = a * a % m;       b >>= 1;     }     return res;   }   int32_t main() {     ios::sync_with_stdio(false);     cin.tie(0);     long long n;     cin >> n;     cout << (factmod(n) + p - binpow(2, n - 1, p)) % p << endl;   }


#include <bits/stdc++.h>   using namespace std;   long long iHateGeometry[100001];   int main() {     int N;     scanf( %d , &N);     long long maxi = -1, sum = 0;     for (int i = 0; i < N; i++) {       scanf( %lld , &iHateGeometry[i]);       sum += iHateGeometry[i];       maxi = max(maxi, iHateGeometry[i]);     }     printf( %lld n , 2 * maxi - sum + 1);   }


#include <bits/stdc++.h>   using namespace std;   long long a[3000005], has[3000005], visited[2000005], dist[1000005];   long long pr[3000010];   long long addmod(long long n, long long m) {     return ((n % 1000000007) + (m % 1000000007)) % 1000000007;   }   long long multmod(long long n, long long m) {     return ((n % 1000000007) * (m % 1000000007)) % 1000000007;   }   long long submod(long long n, long long m) {     return ((n % 1000000007) - (m % 1000000007) + 1000000007) % 1000000007;   }   void prime() {     pr[0] = 1;     pr[1] = 1;     for (long long i = 2; i <= sqrt(3000010); i++) {       for (long long j = 2 * i; j <= 3000010; j += i) {         pr[j] = 1;       }     }   }   long long cntDiv(long long n) {     long long cnt = 0;     for (long long i = 1; i <= sqrt(n); i++) {       if (n % i == 0) {         if (n / i == i)           cnt++;         else           cnt += 2;       }     }     return cnt;   }   long long gcd(long long a, long long b) {     if (a == 0) return b;     return gcd(b % a, a);   }   long long has1[3000011], b[1000005], temp1[1000005];   vector<long long> mat[10001];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long x, y, z, w;     cin >> x >> y >> z >> w;     if (x + y == z + w || x + z == y + w || x + w == y + z || x == y + z + w ||         y == x + z + w || z == x + y + w || w == x + y + z)       cout <<  YES ;     else       cout <<  NO ;     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   #pragma GCC optimize( Ofast )   #pragma GCC optimize( unroll-loops )   using namespace std;   template <class T>   inline bool setmin(T &a, T b) {     if (a > b) return a = b, 1;     return 0;   }   template <class T>   inline bool setmax(T &a, T b) {     if (a < b) return a = b, 1;     return 0;   }   template <class T>   inline T fast(T a, T b, T mod) {     long long res = 1;     while (b) {       if (b & 1) res = (res * a) % mod;       a = (a * a) % mod;       b >>= 1;     }     return res;   }   template <class T>   istream &operator>>(istream &os, vector<T> &container) {     for (auto &u : container) os >> u;     return os;   }   template <class T>   ostream &operator<<(ostream &os, const vector<T> &container) {     for (auto &u : container) os << u <<    ;     return os;   }   template <class T>   inline T gcd(T a, T b) {     while (b) swap(a %= b, b);     return a;   }   const long long INF = 1e9 + 7;   const long long mod = 100000007;   const long long BIG_INF = 1e18 + 7;   const long long N = 1e6 + 7;   const long long T = 1 << 20;   const long double inf = 1e18;   long long n, m, k, q;   int tree[T * 2];   int tree2[T * 2];   int ros[N];   int mal[N];   void add1(int pocz, int kon) {     pocz += T - 1;     kon += T + 1;     while (pocz / 2 != kon / 2) {       if (pocz % 2 == 0) tree[pocz + 1]++;       if (kon & 1) tree[kon - 1]++;       pocz /= 2;       kon /= 2;     }   }   int ask1(int poz) {     poz += T;     int ret = 0;     while (poz) {       ret += tree[poz];       poz /= 2;     }     return ret;   }   int ask2(int pocz, int kon) {     pocz += T - 1;     kon += T + 1;     int ret = 0;     while (pocz / 2 != kon / 2) {       if (pocz % 2 == 0) ret = max(ret, tree2[pocz + 1]);       if (kon & 1) ret = max(ret, tree2[kon - 1]);       pocz /= 2;       kon /= 2;     }     return ret;   }   void add2(int poz, int val) {     poz += T;     tree2[poz] = val;     poz /= 2;     while (poz) {       tree2[poz] = max(tree2[poz + poz], tree2[poz + poz + 1]);       poz /= 2;     }   }   signed main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> n >> m;     add1(1, m);     for (int i = 0; i < (n); i++) {       int a, b;       cin >> a >> b;       add1(a, b);     }     for (int i = 1; i <= m; i++) {       ros[i] = ask2(1, ask1(i)) + 1;       add2(ask1(i), ros[i]);     }     for (int i = 0; i < (T * 2); i++) tree2[i] = 0;     int ans = 0;     for (int i = m; i >= 1; i--) {       mal[i] = ask2(1, ask1(i)) + 1;       add2(ask1(i), mal[i]);       ans = max(ans, ros[i] + mal[i] - 1);     }     cout << ans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   const int mod = 1e9 + 7;   const int sz = 1e5 + 10;   int main() {     ll k, b, n, t, z, ans, zz;     while (cin >> k >> b >> n >> t) {       z = 1;       ans = n;       for (int i = 0; i < n && z < t; i++) {         z = z * k + b;         ans--;       }       if (z > t) ans++;       cout << ans <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline long long read() {     char ch = getchar();     long long res = 0, pd = 1;     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) pd = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       res = (res << 1) + (res << 3) + ch -  0 ;       ch = getchar();     }     return res * pd;   }   inline void write(long long x) {     if (x < 0) putchar( - ), x = -x;     if (x > 9) write(x / 10);     putchar(x % 10 |  0 );   }   inline void wlk(long long x) {     write(x);     putchar(32);   }   inline void wln(long long x) {     write(x);     putchar(10);   }   const long long maxn = 100003;   long long a[maxn];   signed main() {     long long n = read(), flag = 1;     for (long long i = 1; i <= n; ++i) a[i] = read();     for (long long i = 2; i <= n; ++i)       if (a[i] % a[1] != 0) flag = 0;     if (!flag) return puts( -1 ), 0;     wln(2 * n);     for (long long i = 1; i <= n; ++i) {       wlk(a[1]), wlk(a[i]);     }     return puts(  ), 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     long long int n;     cin >> n;     string s;     cin >> s;     long long int mid = n / 2;     long long int check = 0;     for (long long int i = 0; i < n; i++) {       if (s[i] ==  0 ) {         check = 1;         if (i >= mid) {           cout << 1 <<     << i + 1 <<     << 1 <<     << i << endl;           return;         } else {           cout << i + 2 <<     << n <<     << i + 1 <<     << n << endl;           return;         }       }     }     if (check == 0) {       cout << 1 <<     << n - 1 <<     << 2 <<     << n << endl;     }   }   int32_t main() {     long long int t;     cin >> t;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void sol_problem(const long *, long);   int main() {     long n, t, *matriz;     cin >> n >> t;     matriz = new long[n - 1];     for (int i = 0; i < n - 1; i++) cin >> matriz[i];     sol_problem(matriz, t);     return 0;   }   void sol_problem(const long *matriz, long t) {     long ind = 1 + matriz[0];     while (ind <= t) {       if (ind == t) {         cout <<  YES ;         break;       }       ind += matriz[ind - 1];     }     if (ind > t) cout <<  NO ;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 200005;   long long mod = (1e9 + 7);   int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }   long long lcm(long long a, long long b) { return a * (b / gcd(a, b)); }   bool is_vowel(char c) {     if (c ==  a  || c ==  e  || c ==  i  || c ==  o  || c ==  u ) return 1;     return 0;   }   double getDistance(double x1, double y1, double x2, double y2) {     return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));   }   long long extended_euclidean(long long a, long long b, long long &x,                                long long &y) {     if (b == 0) {       x = 1;       y = 0;       return a;     }     long long g = extended_euclidean(b, a % b, y, x);     y -= (a / b) * x;     return g;   }   long long power(long long base, long long p) {     if (p == 1) return base;     if (!p) return 1ll;     long long ret = power(base, p / 2);     ret *= ret;     ret %= mod;     if (p & 1) ret *= base;     return ret % mod;   }   vector<int> v;   map<int, int> mp;   int n;   int solve(long long sum, long long a, long long b, long long c) {     v.clear();     int mn = n, A = 0, B = 0, C = 0;     for (int i = (0); i <= (n); ++i) {       long long cur = sum - a * i;       int cost = min(i, mp[a]);       long long mx = c * (n - i);       int taken2 = n - i;       int taken1 = 0;       if (mx > cur) {         long long delta = mx - cur;         taken2 -= delta;         taken1 += delta;         mx = cur;       }       if (mx == cur && taken1 + taken2 == n - i && taken1 >= 0 && taken2 >= 0) {         cost += min(mp[b], taken1);         cost += min(mp[c], taken2);         mn = min(mn, cost);         if (mn == cost) {           A = i;           B = taken1;           C = taken2;         }       }     }     while (A--) v.push_back(a);     while (B--) v.push_back(b);     while (C--) v.push_back(c);     return mn;   }   int main() {     scanf( %d , &n);     set<long long> st;     long long sum = 0;     vector<int> z;     for (int i = (0); i <= (n - 1); ++i) {       int a;       scanf( %d , &a);       st.insert(a);       mp[a]++;       sum += a;       z.push_back(a);     }     vector<long long> x(st.begin(), st.end());     long long mn = *(st.begin());     long long mx = *(--st.end());     int sol = n;     if (abs(mn - mx) < 2) {       cout << n << endl;       for (int i = (0); i <= (n - 1); ++i) {         cout << z[i] <<    ;       }       return 0;     }     sol = solve(sum, mn, mn + 1, mn + 2);     cout << sol << endl;     for (int i = (0); i <= (n - 1); ++i) cout << v[i] <<    ;     return 0;   }


#include <bits/stdc++.h>   int main() {     int64_t n, i, j;     scanf( %I64d , &n);     j = (n) * (2 * 3 + (n - 1) * 3) + 1;     printf( %I64d , j);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void fail(string s) {     cout << s;     exit(0);   }   void fail(int s) {     cout << s;     exit(0);   }   int n;   int x[5005], y[5005];   int d[5005];   vector<int> v[5005];   int len(int a, int b) { return abs(x[a] - x[b]) + abs(y[a] - y[b]); }   int ok = 0;   void dfs(int u, int dep, int mid) {     d[u] = dep;     for (int i = (0); i < (n); i++)       if (len(u, i) > mid) {         if (!d[i])           dfs(i, dep + 1, mid);         else if (d[i] > 0) {           if ((d[i] - d[u]) % 2 == 0) ok = 1;         }       }     d[u] = -1;   }   int chk(int num) {     ok = 0;     for (int i = (0); i < (n); i++) d[i] = 0;     int ans = 1;     for (int i = (0); i < (n); i++) {       if (!d[i]) {         ans = ans * 2 % 1000000007;         dfs(i, 1, num);         if (ok) return 0;       }     }     return ans;   }   signed main() {     cin >> n;     for (int i = (0); i < (n); i++) {       cin >> x[i] >> y[i];     }     int ans = -1, can = 0;     int l = 0, r = 1000000, mid;     while (l < r) {       int mid = (l + r) / 2;       int p = chk(mid);       if (p)         ans = mid, can = p, r = mid;       else         l = mid + 1;     }     cout << ans <<   n  << can <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool ask(int a, int b, int c, int d) {     cout <<  ?   << a <<     << b <<     << c <<     << d << endl;     fflush(stdout);     string response;     cin >> response;     if (response ==  BAD ) {       exit(0);     } else if (response ==  YES )       return true;     else       return false;   }   int main() {     int n;     cin >> n;     int x = 1, y = 1;     string ans1 =   , ans2 =   ;     for (int i = 0; i < n - 1; ++i) {       if (ask(x + 1, y, n, n)) {         x++;         ans1.push_back( D );       } else {         y++;         ans1.push_back( R );       }     }     x = n, y = n;     for (int i = 0; i < n - 1; ++i) {       if (ask(1, 1, x, y - 1)) {         y--;         ans2.push_back( R );       } else {         x--;         ans2.push_back( D );       }     }     reverse((ans2).begin(), (ans2).end());     string finalans = ans1 + ans2;     cout <<  !   << finalans << endl;     fflush(stdout);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a;     scanf( %d , &a);     string ans =  NO ;     for (int i = 0; i < a; i++) {       string name;       int bef, aft;       cin >> name;       scanf( %d %d , &bef, &aft);       if (bef >= 2400 && aft > bef) {         ans =  YES ;       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, t1, p;   int b[200000], h[200000];   int main() {     cin >> n;     for (int i = 0; i < n; i++) {       cin >> b[i];       if (!b[i]) {         --i;         --n;       }     }     for (int i = 0; i < n; i++) {       cin >> h[i];       if (h[i] == b[0]) p = i;       if (!h[i]) --i;     }     for (int i = 0; i < n; i++) {       if (b[i] != h[(p + i) % (n)]) {         cout <<  NO  << endl;         exit(0);       }     }     cout <<  YES  << endl;   }


#include <bits/stdc++.h>   using namespace std;   const double pi = acos(-1.0);   const double eps = 1e-11;   double memo[105][105][105];   double dp(int R, int S, int P) {     if (R == 0) return 0;     if (S + P == 0) return 1;     double& ret = memo[R][S][P];     if (memo[R][S][P] >= 0) return ret;     ret = 0;     if (R && S) ret += dp(R, S - 1, P) * R * S;     if (S && P) ret += dp(R, S, P - 1) * S * P;     if (R && P) ret += dp(R - 1, S, P) * R * P;     ret /= (R * S + S * P + R * P);     return ret;   }   int main() {     std::ios_base::sync_with_stdio(0);     int x, y, z;     for (int x = 0; x < 105; x++)       for (int y = 0; y < 105; y++)         for (int i = 0; i < 105; i++) memo[x][y][i] = -1;     cin >> x >> y >> z;     cout << fixed;     cout << setprecision(10);     cout << dp(x, y, z) <<     << dp(y, z, x) <<     << dp(z, x, y) << endl;     ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 500000 + 10;   int n;   vector<int> li;   struct node {     int x, y;   } p[maxn];   bool cmp1(node a, node b) { return a.x < b.x; }   bool cmp2(node a, node b) { return a.y < b.y; }   long long vis[maxn], ans;   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d%d , &p[i].x, &p[i].y);       li.push_back(p[i].x), li.push_back(p[i].y);     }     sort(li.begin(), li.end());     li.erase(unique(li.begin(), li.end()), li.end());     for (int i = 1; i <= n; i++) {       p[i].x = lower_bound(li.begin(), li.end(), p[i].x) - li.begin();       p[i].y = lower_bound(li.begin(), li.end(), p[i].y) - li.begin();     }     sort(p + 1, p + n + 1, cmp1);     int st = 1, ed = 1;     long long num = 0ll;     for (; ed <= n; ed++) {       if (p[ed].x == p[st].x) {         vis[p[ed].y]++, num++;       } else {         ans += ((num - 1) * num / 2ll);         for (int i = st; i < ed; i++) {           if (vis[p[i].y]) {             ans -= ((vis[p[i].y] - 1) * vis[p[i].y] / 2ll), vis[p[i].y] = 0;           }         }         st = ed, num = 1ll;         vis[p[ed].y] = 1;       }     }     if (num) {       ans += ((num - 1) * num / 2ll);       for (int i = st; i <= n; i++) {         if (vis[p[i].y]) {           ans -= ((vis[p[i].y] - 1) * vis[p[i].y] / 2ll), vis[p[i].y] = 0;         }       }     }     sort(p + 1, p + n + 1, cmp2);     st = 1, ed = 1, num = 0ll;     for (; ed <= n; ed++) {       if (p[ed].y == p[st].y)         num++;       else {         ans += ((num - 1) * num / 2ll);         st = ed, num = 1ll;       }     }     if (num) ans += ((num - 1) * num / 2ll);     printf( %I64d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7;   const int maxn = 222222;   int main(int argc, char const *argv[]) {     long long s, x;     cin >> s >> x;     if (s < x || (s - x) % 2) {       puts( 0 );     } else {       long long c = (s - x) / 2;       long long ans = 1;       for (int i = 0; i < 40; ++i) {         long long b1 = (x >> i) & 1;         long long b2 = (c >> i) & 1;         if (b1 && b2)           ans = 0;         else if (b1)           ans *= 2L;       }       if (c == 0) ans -= 2;       cout << (ans) << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string s;   int n;   int oddb, evenb, oddr, evenr;   int main() {     cin >> n;     cin >> s;     int ans = 0;     for (int i = 0; i < n; i++) {       if (i % 2 == 0) {         if (s[i] ==  b )           evenb++;         else if (s[i] ==  r )           evenr++;       } else if (i % 2 == 1) {         if (s[i] ==  r )           oddr++;         else if (s[i] ==  b )           oddb++;       }     }     ans = min(max(oddr, evenb), max(oddb, evenr));     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int s[4];   int main() {     long long int x, y;     while (scanf( %I64d%I64d , &x, &y) == 2) {       s[0] = y;       s[1] = y;       s[2] = y;       sort(s, s + 3);       long long int cnt = 0;       while (1) {         if (s[0] == x && s[1] == x && s[2] == x) {           break;         }         if (s[1] + s[2] - 1 > x) {           s[0] = x;         } else {           s[0] = s[1] + s[2] - 1;         }         cnt++;         sort(s, s + 3);       }       printf( %I64d n , cnt);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline void FAST_IO() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);   }   const int N = 3e5 + 5;   long long n, k, A, B;   long long a[N];   inline long long dfs(long long l, long long r) {     long long now = upper_bound(a, a + k, r) - lower_bound(a, a + k, l);     if (now == 0) return A;     if (l == r) return (now == 0 ? A : now * B);     long long mid = (l + r) >> 1;     long long sum = dfs(l, mid) + dfs(mid + 1, r);     sum = now * B * (r - l + 1) > sum ? sum : now * B * (r - l + 1);     return sum;   }   signed main() {     FAST_IO();     cin >> n >> k >> A >> B;     for (int i = 0; i < k; i++) {       cin >> a[i];     }     sort(a, a + k);     cout << dfs(1ll, 1ll << n) <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     long long n, m;     cin >> n >> m;     vector<set<long long>> v((size_t)n);     auto add = [&](long long a, long long b) { v[a].insert((b - a + n) % n); };     for (long long i = 0; i < m; i++) {       long long a, b;       cin >> a >> b;       a--, b--;       add(a, b);       add(b, a);     }     bool o = false;     for (long long j = 2, k = n; j <= k; j++) {       if (k % j == 0) {         bool g = true;         for (long long i = 0; i < n - n / j; i++) {           if (v[i] != v[i + n / j]) {             g = false;             break;           }         }         if (g) {           o = true;           break;         }       }       while (k % j == 0) {         k /= j;       }     }     cout << (o ?  Yes  :  No ) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXSIZE = 10000020;   int bufpos;   char buf[MAXSIZE];   void init() {     buf[fread(buf, 1, MAXSIZE, stdin)] =   0 ;     bufpos = 0;   }   int readint() {     int val = 0;     for (; !isdigit(buf[bufpos]); bufpos++)       ;     for (; isdigit(buf[bufpos]); bufpos++) val = val * 10 + buf[bufpos] -  0 ;     return val;   }   char readchar() {     for (; isspace(buf[bufpos]); bufpos++)       ;     return buf[bufpos++];   }   int readstr(char* s) {     int cur = 0;     for (; isspace(buf[bufpos]); bufpos++)       ;     for (; !isspace(buf[bufpos]); bufpos++) s[cur++] = buf[bufpos];     s[cur] =   0 ;     return cur;   }   char s[5003], w[5003];   int main() {     init();     int n = readstr(s + 1);     bool flag = true;     for (int i = 1; i <= n; i++) {       if (n % 2 == 1 && i * 2 == n + 1) continue;       if (s[i] != s[1]) {         flag = false;         break;       }     }     if (flag) return puts( Impossible ), 0;     for (int i = 1; i < n; i++) {       int cur = 0;       for (int j = i + 1; j <= n; j++) w[++cur] = s[j];       for (int j = 1; j <= i; j++) w[++cur] = s[j];       if (!strcmp(s + 1, w + 1)) continue;       bool flag = true;       for (int j = 1; j <= n; j++)         if (w[j] != w[n - j + 1]) {           flag = false;           break;         }       if (flag) return puts( 1 ), 0;     }     puts( 2 );   }


#include <bits/stdc++.h>   using namespace std;   int n, m, q;   std::vector<int> val(500005);   std::map<int, pair<int, int> > edges;   std::vector<pair<int, int> > query(500005);   int vis[500005];   int par[500005];   set<pair<int, int> > ss[500005];   int sz[500005];   std::vector<pair<int, int> > changes[500005];   int st[500005], en[500005];   int getpar(int x) {     if (par[x] == x)       return x;     else       return getpar(par[x]);   }   void merge(int n1, int n2, int idx) {     int p1 = getpar(n1);     int p2 = getpar(n2);     if (p1 == p2) return;     if (sz[p1] > sz[p2]) swap(p1, p2);     sz[p2] += sz[p1];     sz[p1] = 0;     for (auto i : ss[p1]) {       ss[p2].insert(i);     }     par[p1] = p2;     if (idx != -1) {       st[idx] = p1;       en[idx] = p2;       for (auto i : ss[p1]) {         changes[idx].push_back(i);       }     }     ss[p1].clear();   }   int getans(int node) {     int pp = getpar(node);     pair<int, int> zz = *(ss[pp].rbegin());     cout << zz.first <<   n ;     auto it = ss[pp].rbegin();     ss[pp].erase(zz);     val[zz.second] = 0;     ss[pp].insert({val[zz.second], zz.second});     return zz.first;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n >> m >> q;     for (int i = 1; i < n + 1; i++) {       cin >> val[i];       sz[i] = 1;       par[i] = i;       ss[par[i]].insert({val[i], i});     }     for (int i = 1; i < m + 1; i++) {       int x, y;       cin >> x >> y;       edges[i] = {x, y};     }     for (int i = 1; i < q + 1; i++) {       cin >> query[i].first >> query[i].second;       if (query[i].first == 2) {         vis[query[i].second] = 1;       }     }     for (int i = 1; i < m + 1; i++) {       if (!vis[i]) {         merge(edges[i].first, edges[i].second, -1);       }     }     for (int i = q; i >= 1; i--) {       if (query[i].first == 2) {         merge(edges[query[i].second].first, edges[query[i].second].second, i);       }     }     for (int i = 1; i < q + 1; i++) {       if (query[i].first == 1) {         getans(query[i].second);       } else {         int st1 = st[i];         int en1 = en[i];         ss[st1].clear();         for (auto j : changes[i]) {           ss[st1].insert({val[j.second], j.second});           ss[en1].erase({val[j.second], j.second});         }         par[st1] = st1;       }     }   }


#include <bits/stdc++.h>   const int bufSize = 1e6;   using namespace std;   inline char nc() {     return getchar();     static char buf[bufSize], *p1 = buf, *p2 = buf;     return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, bufSize, stdin), p1 == p2)                ? EOF                : *p1++;   }   inline void read(char* s) {     static char c;     for (; !isalpha(c); c = nc())       ;     for (; isalpha(c); c = nc()) *s++ = c;     *s =   0 ;   }   template <typename T>   inline T read(T& r) {     static char c;     static int flag;     flag = 1, r = 0;     for (c = nc(); !isdigit(c); c = nc())       if (c ==  - ) flag = -1;     for (; isdigit(c); c = nc()) r = r * 10 + c - 48;     return r *= flag;   }   const int maxn = 1e5 + 100;   const int maxm = 22;   int T, n;   char A[maxn], B[maxn];   int G[maxm][maxm];   int G2[maxm];   vector<int> s[maxm];   int fa[maxm];   int find(const int& x) { return fa[x] == x ? x : fa[x] = find(fa[x]); }   inline void merge(int x, int y) {     x = find(x), y = find(y);     if (x == y) return;     if (s[x].size() < s[y].size()) swap(x, y);     fa[y] = x;     for (vector<int>::iterator it = s[y].begin(); it != s[y].end(); ++it)       s[x].push_back(*it);     s[y].clear();   }   int f[1 << 21], num[1 << 21];   inline void init() {     for (int i = 1; i <= 20; ++i) fa[i] = i, s[i].clear(), s[i].push_back(i);     for (int i = 1; i <= 20; ++i)       for (int j = 1; j <= 20; ++j) G[i][j] = 0;   }   int main() {     for (int i = 0; i < (1 << 20); ++i)       for (int x = i; x; x >>= 1) num[i] += (x & 1);     read(T);     while (T--) {       read(n);       read(A + 1), read(B + 1);       init();       for (int i = 1; i <= n; ++i) {         if (A[i] == B[i]) continue;         G[A[i] -  a  + 1][B[i] -  a  + 1] = 1;         merge(A[i] -  a  + 1, B[i] -  a  + 1);       }       int ans = 0;       for (int i = 1; i <= 20; ++i) {         if (find(i) != i) continue;         for (unsigned int j = 0; j < s[i].size(); ++j) G2[j] = 0;         for (unsigned int j = 0; j < s[i].size(); ++j)           for (unsigned int k = 0; k < s[i].size(); ++k)             if (G[s[i][j]][s[i][k]]) G2[j] |= (1 << k);         int maxx = (1 << (int)s[i].size());         for (int status = 0; status < maxx; ++status) f[status] = 0;         f[0] = 1;         int res = 0;         for (int status = 0; status < maxx; ++status) {           if (!f[status]) continue;           res = max(res, num[status]);           for (unsigned int j = 0; j < s[i].size(); ++j)             if (!(status & (1 << j)) && !(G2[j] & status))               f[status | (1 << j)] = 1;         }         ans += 2 * s[i].size() - res - 1;       }       printf( %d n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve(long long int test) {     long long int n;     cin >> n;     cout << n << endl;     for (long long int i = 1; i <= n; i++) cout << i <<    ;     cout << endl;   }   int main() {     long long int t = 1, test = 1;     cin >> t;     while (t--) {       solve(test++);     }   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 303303;   const int Max = 101101;   int n, S, L;   int a[Max];   int lg[Max];   struct sparse {     int g, h;   };   sparse s[22][Max];   void build_table() {     for (int i = 1; i <= n; i++) {       s[0][i].g = a[i];       s[0][i].h = a[i];     }     for (int i = 1; i <= lg[n]; i++) {       for (int j = 1; j <= n - (1 << i) + 1; j++) {         s[i][j] = s[i - 1][j];         int G = s[i - 1][j + (1 << (i - 1))].g;         int H = s[i - 1][j + (1 << (i - 1))].h;         if (G < s[i][j].g) s[i][j].g = G;         if (H > s[i][j].h) s[i][j].h = H;       }     }     return;   }   int get_table(int L, int R) {     int len = R - L + 1;     int G1 = s[lg[len]][L].g;     int H1 = s[lg[len]][L].h;     int G2 = s[lg[len]][R - (1 << lg[len]) + 1].g;     int H2 = s[lg[len]][R - (1 << lg[len]) + 1].h;     int G, H;     if (G1 <= G2)       G = G1;     else       G = G2;     if (H1 >= H2)       H = H1;     else       H = H2;     int result = H - G;     return result;   }   int tree[Max * 11];   int get(int v, int L, int R, int pos) {     if (L == R) return tree[v];     if (pos <= (L + R) / 2)       return get(2 * v + 1, L, (L + R) / 2, pos);     else       return get(2 * v + 2, (L + R) / 2 + 1, R, pos);   }   int get_min(int v, int L, int R, int l, int r) {     if (l > R || L > r) return INF;     if (l <= L && R <= r) return tree[v];     int M1 = get_min(2 * v + 1, L, (L + R) / 2, l, r);     int M2 = get_min(2 * v + 2, (L + R) / 2 + 1, R, l, r);     if (M1 <= M2)       return M1;     else       return M2;   }   void push(int v, int L, int R, int pos, int num) {     if (L == R) {       tree[v] = num;       return;     }     if (pos <= (L + R) / 2)       push(2 * v + 1, L, (L + R) / 2, pos, num);     else       push(2 * v + 2, (L + R) / 2 + 1, R, pos, num);     tree[v] = tree[2 * v + 1];     if (tree[2 * v + 2] < tree[v]) tree[v] = tree[2 * v + 2];     return;   }   int main() {     cin >> n >> S >> L;     for (int i = 1; i <= n; i++) cin >> a[i];     lg[1] = 0;     int t = 1;     for (int i = 2; i <= n; i++) {       lg[i] = lg[i - 1];       if (t * 2 == i) {         t *= 2;         lg[i]++;       }     }     build_table();     for (int i = 0; i < Max * 11; i++) tree[i] = INF;     for (int i = L; i <= n; i++) {       int raz = get_table(i - L + 1, i);       if (raz <= S) {         int LL = 1;         int RR = i - L + 1;         int start;         while (true) {           if (LL == RR) {             start = LL;             break;           }           int MM = (LL + RR) / 2;           int raz_new = get_table(MM, i);           if (raz_new <= S)             RR = MM;           else             LL = MM + 1;         }         if (start == 1)           push(0, 1, n, i, 1);         else {           int dp = get_min(0, 1, n, start - 1, i - L);           if (dp != INF) push(0, 1, n, i, dp + 1);         }       }     }     int ans = get(0, 1, n, n);     if (ans == INF)       cout <<  -1  << endl;     else       cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   using namespace std;   template <class c>   struct rge {     c b, e;   };   template <class c>   rge<c> range(c i, c j) {     return rge<c>{i, j};   }   template <class c>   auto dud(c* x) -> decltype(cerr << *x, 0);   template <class c>   char dud(...);   struct debug {     template <class c>     debug& operator<<(const c&) {       return *this;     }   };   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   using ll = long long;   using pii = pair<int, int>;   using pll = pair<ll, ll>;   using vi = vector<int>;   using vll = vector<ll>;   const int kMaxN = 110;   bool can_reach[kMaxN][kMaxN * kMaxN];   bool is_ordered[kMaxN][kMaxN * kMaxN];   int num_children[kMaxN][kMaxN * kMaxN];   void Preproc() {     can_reach[1][1] = true;     for (int len = 1; len < kMaxN; ++len) {       for (int nintvs = 1; nintvs <= len * len; ++nintvs) {         if (!can_reach[len][nintvs]) {           continue;         }         for (int k = 2; len + k <= kMaxN; ++k) {           const int new_len = len + k - 1;           const int new_nintvs = nintvs + k * (k + 1) / 2 - 1;           can_reach[new_len][new_nintvs] = true;           is_ordered[new_len][new_nintvs] = true;           num_children[new_len][new_nintvs] = k;         }         for (int k = 4; len + k <= kMaxN; ++k) {           const int new_len = len + k - 1;           const int new_nintvs = nintvs + k;           can_reach[new_len][new_nintvs] = true;           is_ordered[new_len][new_nintvs] = false;           num_children[new_len][new_nintvs] = k;         }       }     }   }   void Construct(int len, int nintvs) {     vector<int> roots(len);     const int init_len = len;     iota((roots).begin(), (roots).end(), 0);     vector<bool> node_ordered(len);     vector<vi> node_children(len);     while (len > 1) {       assert(can_reach[len][nintvs]);       const int k = num_children[len][nintvs];       const int new_root = ((int)(node_children).size());       vi children(roots.end() - k, roots.end());       roots.erase(roots.end() - k, roots.end());       node_children.push_back(children);       roots.push_back(new_root);       if (is_ordered[len][nintvs]) {         node_ordered.push_back(true);         len -= (k - 1);         nintvs -= k * (k + 1) / 2 - 1;       } else {         node_ordered.push_back(false);         len -= (k - 1);         nintvs -= k;       }     }     debug() <<   [              <<  node_children                  :               << (node_children) <<  ]  ;     debug() <<   [              <<  node_ordered                  :               << (node_ordered) <<  ]  ;     assert(len == 1 && nintvs == 1);     assert(((int)(roots).size()) == 1);     vi answer;     function<void(int, bool)> Dfs = [&](int v, bool ordered_inc) {       if (v < init_len) {         answer.push_back(v + 1);       } else if (node_ordered[v]) {         if (ordered_inc) {           for (int child : node_children[v]) {             Dfs(child, !ordered_inc);           }         } else {           const int sz = ((int)(node_children[v]).size());           for (int i = sz - 1; i >= 0; --i) {             Dfs(node_children[v][i], !ordered_inc);           }         }       } else {         const int sz = ((int)(node_children[v]).size());         vi order;         for (int start : {1, 0}) {           for (int i = start; i < sz; i += 2) {             order.push_back(i);           }         }         if (sz % 2 == 1) {           swap(order[sz - 2], order[sz - 1]);         }         for (int i : order) {           Dfs(node_children[v][i], !ordered_inc);         }       }     };     Dfs(roots[0], true);     for (int v : answer) {       cout << v <<    ;     }     cout <<   n ;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout << fixed << setprecision(11);     cerr << fixed << setprecision(6);     Preproc();     int q;     cin >> q;     while (q--) {       int n, k;       cin >> n >> k;       if (!can_reach[n][k]) {         cout <<  NO n ;       } else {         cout <<  YES n ;         Construct(n, k);       }     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long q1, q2;     cin >> q1 >> q2;     long long w1, w2;     cin >> w1 >> w2;     long long e1, e2;     cin >> e1 >> e2;     long long l1 = (q2 - w2) * (w1 - e1);     long long l2 = (q1 - w1) * (w2 - e2);     if (l2 > l1) return cout <<  LEFT , 0;     if (l1 > l2) return cout <<  RIGHT , 0;     cout <<  TOWARDS ;     return 0;   }