#include <bits/stdc++.h>   using namespace std;   typedef const char* cstr;   const int oo = (~0u) >> 1;   const long long int ooll = (~0ull) >> 1;   const double inf = 1e+20;   const double eps = 1e-8;   const double pi = acos(-1.0);   const int MOD = 1000000007;   template <typename type>   inline bool cmax(type& a, const type& b) {     return a < b ? a = b, true : false;   }   template <typename type>   inline bool cmin(type& a, const type& b) {     return b < a ? a = b, true : false;   }   template <typename type>   inline type sqr(const type& first) {     return first * first;   }   inline int dbcmp(const double& a, const double& b) {     return (a > b + eps) - (a < b - eps);   }   inline int sgn(const double& first) { return dbcmp(first, 0); }   template <typename type>   inline type cross(const pair<type, type>& a, const pair<type, type>& b,                     const pair<type, type>& c) {     return (b.first - a.first) * (c.second - a.second) -            (b.second - a.second) * (c.first - a.first);   }   template <typename type>   inline type dot(const pair<type, type>& a, const pair<type, type>& b,                   const pair<type, type>& c) {     return (b.first - a.first) * (c.first - a.first) +            (b.second - a.second) * (c.second - a.second);   }   template <typename type>   inline type gcd(type a, type b) {     if (b)       while ((a %= b) && (b %= a))         ;     return a + b;   }   template <typename type>   inline type lcm(type a, type b) {     return a * b / gcd(a, b);   }   template <typename type>   inline void bit_inc(vector<type>& st, int first, type inc) {     while (first < ((int)(st).size())) st[first] += inc, first |= first + 1;   }   template <typename type>   inline type bit_sum(const vector<type>& st, int first) {     type s = 0;     while (first >= 0) s += st[first], first = (first & (first + 1)) - 1;     return s;   }   template <typename type>   inline type bit_kth(const vector<type>& st, int k) {     int first = 0, second = 0, z = 0;     while ((1 << (++second)) < ((int)(st).size()))       ;     for (int i = (second - 1); i >= 0; --i) {       if ((first += 1 << i) > ((int)(st).size()) || z + st[first - 1] > k)         first -= 1 << i;       else         z += st[first - 1];     }     return first;   }   inline void make_set(vector<int>& set) {     for (int i = (0); i < (((int)(set).size())); ++i) set[i] = i;   }   inline int find_set(vector<int>& set, int first) {     int second = first, z;     while (second != set[second]) second = set[second];     while (first != set[first]) z = set[first], set[first] = second, first = z;     return second;   }   inline bool union_set(vector<int>& set, int a, int b) {     a = find_set(set, a), b = find_set(set, b);     return a != b ? set[a] = b, true : false;   }   template <typename type>   inline void merge(type& a, type& b) {     if (((int)(a).size()) < ((int)(b).size())) swap(a, b);     for (typename type::iterator it = b.begin(); it != b.end(); b.erase(it++))       a.insert(*it);   }   template <typename type>   inline void merge(priority_queue<type>& a, priority_queue<type>& b) {     if (((int)(a).size()) < ((int)(b).size())) swap(a, b);     while (((int)(b).size())) a.push(b.top()), b.pop();   }   struct Initializer {     Initializer() { ios::sync_with_stdio(false); }     ~Initializer() { cerr; }   } initializer;   int main() {     int n, m;     scanf( %d%d , &n, &m);     vector<vector<int> > adj(n);     vector<vector<int> > len(n);     for (int i = (0); i < (m); ++i) {       int u, v, w;       scanf( %d%d%d , &u, &v, &w), --u, --v;       adj[u].push_back(v);       len[u].push_back(w);       adj[v].push_back(u);       len[v].push_back(w);     }     int k;     scanf( %d , &k);     vector<bool> isp(n);     for (int i = (0); i < (k); ++i) {       int p;       scanf( %d , &p), --p;       isp[p] = true;     }     long long int ans;     int s;     {       priority_queue<pair<long long int, int>, vector<pair<long long int, int> >,                      greater<pair<long long int, int> > >           q;       vector<long long int> d(n, ooll);       if (cmin(d[0], 0ll)) q.push(make_pair(d[0], 0));       while (((int)(q).size())) {         if (d[q.top().second] == q.top().first) {           int u = q.top().second;           for (int i = (0); i < (((int)(adj[u]).size())); ++i) {             int v = adj[u][i], l = len[u][i];             if (cmin(d[v], d[u] + l)) q.push(make_pair(d[v], v));           }           if (isp[u]) {             ans = d[u];             s = u;             break;           }         }         q.pop();       }     }     {       priority_queue<pair<long long int, int>, vector<pair<long long int, int> >,                      greater<pair<long long int, int> > >           q;       vector<long long int> d(n, ooll);       vector<int> rt(n);       for (int i = (0); i < (n); ++i)         if (isp[i])           if (cmin(d[i], 0ll)) q.push(make_pair(d[i], i)), rt[i] = i;       while (((int)(q).size())) {         if (d[q.top().second] == q.top().first) {           int u = q.top().second;           for (int i = (0); i < (((int)(adj[u]).size())); ++i) {             int v = adj[u][i], l = len[u][i];             if (cmin(d[v], d[u] + l)) q.push(make_pair(d[v], v)), rt[v] = rt[u];           }         }         q.pop();       }       vector<pair<long long int, pair<int, int> > > edges;       for (int u = (0); u < (n); ++u)         for (int i = (0); i < (((int)(adj[u]).size())); ++i) {           int v = adj[u][i], l = len[u][i];           edges.push_back(make_pair(d[u] + d[v] + l, make_pair(rt[u], rt[v])));         }       sort((edges).begin(), (edges).end());       vector<int> st(n);       make_set(st);       for (int i = (0); i < (((int)(edges).size())); ++i) {         int u = edges[i].second.first, v = edges[i].second.second;         if (union_set(st, u, v)) ans += edges[i].first;       }     }     cout << ans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   const int _ = 5e5 + 7;   int n, m, a[_], b[_];   bool check(int mid) {     memset(b, -1, sizeof(b));     b[0] = 0;     for (int i = 1; i <= n; ++i) {       int L = a[i], R = (a[i] + mid) % m;       if (L <= R) {         if (b[i - 1] <= R)           b[i] = max(b[i - 1], L);         else           return 0;       } else {         if (R < b[i - 1] && b[i - 1] < L)           b[i] = L;         else           b[i] = b[i - 1];       }       if (b[i] < b[i - 1]) return 0;     }     return 1;   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; ++i) scanf( %d , &a[i]);     int l = 0, r = m - 1, ans = 0;     while (l <= r) {       int mid = (l + r) >> 1;       if (check(mid))         ans = mid, r = mid - 1;       else         l = mid + 1;     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>      using namespace std;      int main(){       //freopen( input.inp , r ,stdin);       //freopen( output.out , w ,stdout);       ios::sync_with_stdio(0);       cin.tie(0);       int t;       cin >> t;       while (t--){           int a,b;           cin >> a >> b;           int ans = 0;           for (int i = 0; i < min(a,b);i++) ans+=2;            if (a != b){               for (int i = min(a,b); i < max(a,b);i++){                   ans+=2;               }               ans--;           }           cout << ans << endl;       }       return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 100005;   char en =   n ;   long long inf = 1e16;   long long mod = 1e9 + 7;   long long power(long long x, long long n, long long mod) {     long long res = 1;     x %= mod;     while (n) {       if (n & 1) res = (res * x) % mod;       x = (x * x) % mod;       n >>= 1;     }     return res;   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long n, k;     cin >> n >> k;     long long curr = n * (n + 1) / 2;     if (curr > k) {       cout << -1 << en;       return 0;     }     long long arr[n + 5];     for (long long i = 1; i <= n; i++) arr[i] = i;     long long rem = k - curr;     long long start = 1;     while (rem) {       long long end1 = n - start + 1;       long long max1 = end1 - start;       if (max1 <= 0) break;       if (rem >= max1) {         swap(arr[start], arr[end1]);         rem -= max1;       } else {         swap(arr[start], arr[start + rem]);         break;       }       start++;     }     long long ans = 0;     for (long long i = 1; i <= n; i++) {       ans += max(i, arr[i]);     }     cout << ans << en;     for (long long i = 1; i <= n; i++) cout << i <<    ;     cout << en;     for (long long i = 1; i <= n; i++) cout << arr[i] <<    ;     cout << en;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 9000020;   const int K = 60;   const int MOd = 1e9 + 7;   int a, b;   int nex[maxn][2];   int ar[3020], st[maxn];   int dn[maxn], N;   int ans;   int add(int a, int b) {     a += b;     a %= MOd;     if (a < 0) return a + MOd;     return a;   }   void dfs(int p, int n, int x) {     st[n] = p;     if (nex[p][0]) dfs(nex[p][0], n + 1, (x + x) & 15);     if (nex[p][1]) dfs(nex[p][1], n + 1, (x + x + 1) & 15);   }   int main() {     scanf( %d , &a);     for (int i = 1; i <= a; i++) scanf( %d , &ar[i]);     dn[0] = 1;     for (int i = 1; i <= a; i++) {       int n = 0;       for (int j = i, p = 0, x = 0; j >= 1; j--) {         st[n++] = p;         x = (x + x + ar[j]) & 15;         if (!nex[p][ar[j]]) {           nex[p][ar[j]] = ++N;           p = nex[p][ar[j]];           if (n > 0) dn[p] = add(dn[p], dn[st[n - 1]]);           if (n > 1) dn[p] = add(dn[p], dn[st[n - 2]]);           if (n > 2) dn[p] = add(dn[p], dn[st[n - 3]]);           if (n > 3 && x != 12 && x != 10 && x != 7 && x != 15)             dn[p] = add(dn[p], dn[st[n - 4]]);           ans = add(ans, dn[p]);         } else           p = nex[p][ar[j]];       }       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MaxN = 500 + 5;   int n, m, mod, h[MaxN], tmp, tot[3];   long long f[MaxN << 1][MaxN];   char ch;   void read(int &num) {     ch = 0;     while (ch <  0  || ch >  9 ) ch = getchar();     num = ch -  0 ;   }   int main() {     scanf( %d%d%d , &n, &m, &mod);     for (int i = 1; i <= m; i++)       for (int j = 1; j <= n; j++) {         read(tmp);         if (tmp) h[j]++;       }     for (int i = 1; i <= n; i++) tot[h[i]]++;     f[tot[1]][tot[0]] = 1;     for (int j = tot[0]; j >= 0; j--)       for (int i = tot[1] + tot[0]; i >= 0; i--) {         if (i >= 2)           f[i - 2][j] = (f[i - 2][j] + f[i][j] * (i * (i - 1)) / 2) % mod;         if (j >= 1) f[i][j - 1] = (f[i][j - 1] + f[i][j] * i * j) % mod;         if (j >= 2)           f[i + 2][j - 2] = (f[i + 2][j - 2] + f[i][j] * (j * (j - 1)) / 2) % mod;       }     cout << f[0][0];     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using pii = pair<int, int>;   const int N = 1e6 + 10;   struct UFS {     stack<pair<int *, int>> stk;     int fa[N], rnk[N];     inline void init(int n) {       for (int i = 0; i <= n; ++i) fa[i] = i, rnk[i] = 0;     }     inline int Find(int x) {       while (x ^ fa[x]) x = fa[x];       return x;     }     inline void Merge(int x, int y) {       x = Find(x), y = Find(y);       if (x == y) return;       if (rnk[x] <= rnk[y]) {         stk.push({fa + x, fa[x]});         fa[x] = y;         if (rnk[x] == rnk[y]) {           stk.push({rnk + y, rnk[y]});           rnk[y]++;         }       } else {         stk.push({fa + y, fa[y]});         fa[y] = x;       }     }     inline void Undo() {       *stk.top().first = stk.top().second;       stk.pop();     }   } ufs;   struct Edge {     int u, v;   };   int main() {     int n, m, k;     cin >> n >> m >> k;     vector<int> c(n + 1);     for (int i = 1; i <= n; i++) cin >> c[i];     vector<Edge> same_edges;     map<pair<int, int>, vector<Edge>> diff_edges;     for (int i = 0; i < m; i++) {       int u, v;       cin >> u >> v;       if (c[u] == c[v])         same_edges.push_back({u, v});       else {         if (c[u] > c[v]) swap(u, v);         diff_edges[{c[u], c[v]}].push_back({u, v});       }     }     vector<int> group_flag(k + 1, 1);     ufs.init((n + 1) * 2);     for (auto &[u, v] : same_edges) {       ufs.Merge(u * 2, v * 2 + 1);       ufs.Merge(u * 2 + 1, v * 2);       if (ufs.Find(u * 2) == ufs.Find(u * 2 + 1)) group_flag[c[u]] = 0;       if (ufs.Find(v * 2) == ufs.Find(v * 2 + 1)) group_flag[c[v]] = 0;     }     ll good_group_cnt = 0;     for (int i = 1; i <= k; i++)       if (group_flag[i]) good_group_cnt++;     ll cnt_fail = 0;     for (auto &[key, row] : diff_edges) {       if (!group_flag[key.first]) continue;       if (!group_flag[key.second]) continue;       int mark = (int)ufs.stk.size();       int flag = 1;       for (auto &[u, v] : row) {         ufs.Merge(u * 2, v * 2 + 1);         ufs.Merge(u * 2 + 1, v * 2);         if (ufs.Find(u * 2) == ufs.Find(u * 2 + 1)) flag = 0;         if (ufs.Find(v * 2) == ufs.Find(v * 2 + 1)) flag = 0;       }       if (!flag) cnt_fail++;       while ((int)ufs.stk.size() > mark) {         ufs.Undo();       }     }     ll ans = good_group_cnt * (good_group_cnt - 1) / 2;     ans = ans - cnt_fail;     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, t;     cin >> n >> t;     int edge_n = 2 * n;     double edges[edge_n];     double currX, currA;     for (int i = 0; i < n; i++) {       cin >> currX >> currA;       edges[2 * i] = currX - currA / 2;       edges[2 * i + 1] = currX + currA / 2;     }     for (int i = 0; i < edge_n; i++) {       for (int j = i; j > 0 && (edges[j] < edges[j - 1]);) {         double temp = edges[j - 1];         edges[j - 1] = edges[j];         edges[j] = temp;         j--;       }     }     int count = 2;     for (int i = 1; i < edge_n; i += 2) {       if (edges[i + 1] - edges[i] > t) {         count += 2;       } else if (edges[i + 1] - edges[i] == t) {         count++;       }     }     cout << count;   }


#include <bits/stdc++.h>   using namespace std;   int bs(int a[], int l, int u, int x) {     int m, p = -1;     while (l <= u) {       m = (l + u) / 2;       if (a[m] == x || (a[m] < x && m + 1 <= u && a[m + 1] >= x))         return m;       else if (a[m] < x) {         p = m;         l = m + 1;       } else {         u = m - 1;       }     }     return p;   }   int gc(int a, int b) {     if (!a) return b;     return gc(b % a, a);   }   bool isP(unsigned long long int x) {     if (x == 2) return true;     if (x % 2 == 0 || x <= 1) return false;     for (int i = 3; i <= sqrt(x); i += 2) {       if ((x % i) == 0) return false;     }     return true;   }   int main() {     int n, j, g, g1, pre, i, uc, f4, l, v, li, ri, a4, e1, ind, t3, n9, t, r, f,         c1, p, p1, p3, y, x, z, t1, t2, t3n, m, k;     int a[100000];     unordered_map<string, int> mp;     priority_queue<pair<int, int>> pq;     int ty = 0, ty1;     set<int> st;     set<int> sto;     ty = INT_MAX;     g = 0;     vector<int> ar;     cin >> n >> k;     for (i = 0; i < n; i++) {       cin >> a[i];       g += a[i];     }     f = 1;     if (g % k != 0)       cout <<  No n ;     else {       g1 = 0;       ind = 0;       for (i = 0; i < n; i++) {         g1 += a[i];         ind++;         if (g1 == (g / k)) {           ar.push_back(ind);           g1 = 0;           ind = 0;         } else if (g1 > (g / k)) {           f = 0;           cout <<  No n ;           break;         }       }       if (f) {         cout <<  Yes n ;         for (i = 0; i < ar.size(); i++) cout << ar[i] <<    ;         cout <<   n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxint = -1u >> 1;   int n;   long long x[100010];   bool v[100010];   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) scanf( %I64d , &x[i]);     sort(x, x + n);     long long a = -1, b = -1;     long long ret = 0;     for (int i = n - 2; i >= 0; i--) {       if (v[i + 1]) continue;       if (x[i + 1] - x[i] <= 1) {         if (a == -1) {           a = x[i];           v[i] = true;         } else {           b = x[i];           v[i] = true;           ret += a * b;           a = -1;         }       }     }     cout << ret << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, count = 0, ans;     cin >> n;     string s;     cin >> s;     long long r = 0, b = 0;     for (long long i = 0; i < n; i++)       if (s[i] ==  r )         r++;       else if (s[i] ==  b )         b++;     for (long long i = 0; i < n; i++)       if (i % 2 == 0 && s[i] !=  r )         count++;       else if (i % 2 == 1 && s[i] !=  b )         count++;     long long rx = n % 2 == 1 ? 1 + (long long)(n / 2) : n / 2;     ans = abs(r - rx);     count -= ans;     ans += (count / 2);     count = 0;     for (long long i = 0; i < n; i++)       if (i % 2 == 1 && s[i] !=  r )         count++;       else if (i % 2 == 0 && s[i] !=  b )         count++;     ans = min(ans, abs(b - rx) + (count - abs(b - rx)) / 2);     cout << ans;   }


#include <bits/stdc++.h>   int main() {     int a, b, s = 0, t = 0, r = 0, i, c, d;     scanf( %d %d , &a, &b);     for (i = 1; i <= 6; i++) {       c = abs(a - i);       d = abs(b - i);       if (c < d)         s++;       else if (c > d)         t++;       else         r++;     }     printf( %d %d %d n , s, r, t);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct node {     int v;     long long w;     node(){};     node(int v, long long w) : v(v), w(w) {}   };   vector<vector<node> > G;   int b[102550];   long long solve(int s) {     long long ans = 10000000000000000;     int len = G[s].size();     for (int i = 0; i < len; i++) {       node p = G[s][i];       if (b[p.v]) {         ans = min(ans, p.w);       }     }     if (ans == 10000000000000000) ans = -1;     return ans;   }   int main() {     int n, m, k, num;     scanf( %d %d %d , &n, &m, &k);     G.clear();     G.resize(n + 5);     memset(b, 0, sizeof(b));     for (int i = 1; i <= m; i++) {       int u, v;       long long w;       scanf( %d %d %I64d , &u, &v, &w);       G[u].push_back(node(v, w));       G[v].push_back(node(u, w));     }     for (int i = 1; i <= k; i++) {       scanf( %d , &num);       b[num] = 1;     }     long long ans = 10000000000000000;     for (int i = 1; i <= n; i++) {       if (b[i] == 1) continue;       long long num = solve(i);       if (num != -1) ans = min(ans, num);     }     if (ans == 10000000000000000) ans = -1;     printf( %I64d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n, s, ans = 0, counter = 0;     cin >> n >> s;     int a[n];     for (int i = 0; i < n; i++) cin >> a[i];     sort(a, a + n);     while (ans < s) {       counter++;       ans += a[n - counter];     }     cout << counter;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     long long ans = 0;     for (int i = (0); i < (n); ++i) {       long long t, T, x, cost;       cin >> t >> T >> x >> cost;       if (t >= T) {         ans += cost + m * x;         continue;       }       long long aux1 = cost;       if (m > (T - t)) aux1 += m * x;       long long aux2 = (long long)ceil((double)(m - (T - t)) / (T - t)) + 1;       aux2 *= cost;       ans += min(aux1, aux2);     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:60777216 )   using namespace std;   int main() {     int tc;     cin >> tc;     for (int TC = (0); TC < (tc); TC++) {       int n, k;       string s;       cin >> n >> k >> s;       k--;       string res =   ;       for (int i = (0); i < (n / 2 - k); i++) res.push_back( ( );       for (int i = (0); i < (n / 2 - k); i++) res.push_back( ) );       for (int i = (0); i < (k); i++) res.push_back( ( ), res.push_back( ) );       vector<pair<int, int> > r;       for (int i = (0); i < (n); i++)         if (res[i] != s[i]) {           for (int j = (i + 1); j < (n); j++)             if (s[j] == res[i]) {               reverse(s.begin() + i, s.begin() + j + 1);               r.push_back(pair<int, int>(i, j));               break;             }         }       cout << r.size() << endl;       for (int i = (0); i < (r.size()); i++)         printf( %d %d n , r[i].first + 1, r[i].second + 1);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 500 + 4;   const int maxlog = 22;   const int mod = 1e9 + 7;   const int sq = 350;   int n, m;   int ans[maxn][maxn][2];   pair<int, int> par[maxn][maxn][2];   queue<pair<pair<int, int>, bool> > q;   vector<int> edge[maxn];   void solve() {     while (!q.empty()) {       int u = q.front().first.first;       int v = q.front().first.second;       bool b = q.front().second;       q.pop();       if (b == 0) {         for (int i = 0; i < edge[u].size(); i++) {           int k = edge[u][i];           if (!ans[k][v][1]) {             par[k][v][1] = make_pair(u, v);             ans[k][v][1] = ans[u][v][0] + 1;             q.push(make_pair(make_pair(k, v), 1));           }         }       } else {         for (int i = 0; i < edge[v].size(); i++) {           int k = edge[v][i];           if (!ans[u][k][0] && k != u) {             par[u][k][0] = make_pair(u, v);             ans[u][k][0] = ans[u][v][1] + 1;             q.push(make_pair(make_pair(u, k), 0));           }         }       }     }   }   vector<pair<int, int> > res;   void print(int x, int y, bool b) {     if (x == 0 && y == 0) return;     res.push_back(make_pair(x, y));     print(par[x][y][b].first, par[x][y][b].second, b ^ 1);   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cout.precision(20);     cin >> n >> m;     for (int i = 0; i < m; i++) {       int u, v;       cin >> u >> v;       edge[u].push_back(v), edge[v].push_back(u);     }     ans[1][n][0] = 1;     q.push(make_pair(make_pair(1, n), 0));     solve();     if (ans[n][1][0] / 2 == 0) {       cout << -1;       return 0;     }     cout << ans[n][1][0] / 2 << endl;     print(n, 1, 0);     reverse(res.begin(), res.end());     for (int i = 0; i < res.size(); i += 2) cout << res[i].first <<    ;     cout << endl;     for (int i = 0; i < res.size(); i += 2) cout << res[i].second <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     while (cin >> n) {       int arr[100005];       for (int i = 1; i <= n; i++) {         cin >> arr[i];       }       long long cnt = 0;       for (int i = 1; i < n; i++) {         long long x = log2(n - i);         arr[i + (1 << x)] += arr[i];         cnt += arr[i];         arr[i] = 0;         cout << cnt << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string flip1(string st) {     swap(st[0], st[1]);     swap(st[1], st[2]);     swap(st[2], st[3]);     return st;   }   string flip2(string st) {     swap(st[0], st[4]);     swap(st[4], st[2]);     swap(st[2], st[5]);     return st;   }   string fun(string x) {     string res = x;     int i, j, k;     for (i = 0; i < 2; i++) {       for (j = 0; j < 4; j++) {         for (k = 0; k < 4; k++) {           x = flip1(x);           res = min(res, x);         }         x = flip2(x);       }       x = flip1(x);     }     return res;   }   int main() {     set<string> s;     int n, m, i, j, k;     string x, y;     cin >> x;     sort(x.begin(), x.end());     do {       s.insert(fun(x));     } while (next_permutation(x.begin(), x.end()));     cout << s.size() << endl;   }


#include <bits/stdc++.h>   using namespace std;   int a, b;   int main() {     while (cin >> a >> b) {       int min = 0;       int temp = a;       while (temp) {         if (min < temp % 10) min = temp % 10;         temp /= 10;       }       temp = b;       while (temp) {         if (min < temp % 10) min = temp % 10;         temp /= 10;       }       min++;       int i = 0;       int c = 0;       temp = a + b;       while (a || b || c) {         int sum = a % 10 + b % 10 + c;         c = sum / min;         a /= 10;         b /= 10;         i++;       }       cout << i << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   #pragma comment(linker,  /STACK:20000000 )   string problem_name =  a ;   void init() { freopen((problem_name +  .in ).c_str(),  rt , stdin); }   struct tpoint {     int x, y;   };   long long vp(tpoint a, tpoint b, tpoint c) {     tpoint f, s;     f.x = b.x - a.x;     f.y = b.y - a.y;     s.x = c.x - a.x;     s.y = c.y - a.y;     return f.x * (long long)s.y - (long long)f.y * s.x;   }   tpoint mas[100111];   int main() {     int n, t;     scanf( %d , &n);     for (int i = 0; i < n; i++) scanf( %d%d , &mas[i].x, &mas[i].y);     int p = 1;     scanf( %d , &t);     while (t--) {       tpoint c;       long long res = 0;       scanf( %d%d , &c.x, &c.y);       p = 1;       bool ok = 1;       for (int i = 0; i < n; i++) {         if (vp(mas[i], mas[(i + 1) % n], c) >= 0) ok = 0;       }       if (ok)         for (int i = 0; i < n; i++) {           if (p == i) p++;           if (p >= n) p = 0;           while (vp(mas[i], mas[p], c) < 0) {             p++;             if (p == n) p = 0;           }           p--;           if (p < 0) p = n - 1;           long long col = p - i + 1;           if (col <= 0) col += n;           if (col > 2) {             col--;             res += col * (col - 1) / 2;           }         }       if (!ok)         res = 0;       else         res = (long long)n * (n - 1) * (n - 2) / 6 - res;       cout << res << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 9e5 + 7;   const long long INF = 1e9 + 7;   int main() {     cout << 2000 << endl;     for (int i = 1; i <= 1000; i++) cout << i <<   1   << i <<   2 n ;     for (int i = 1000; i >= 1; i--) cout << i <<   1   << i <<   2 n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long inf = 2147483647;   const long long ll = 9223372036854775807, ninf = 1000000000;   const double eps = 1e-6;   const long long nll = 1000000000000000000;   class MulticoreProcessingEasy {    public:     int fastestTime(int jobLength, int corePenalty, vector<int> speed,                     vector<int> cores) {}   };   int main() {     int a;     while (cin >> a) {       int A[100005] = {};       for (int i = 1; i <= a; i++) cin >> A[i];       int no = 0;       for (int i = 1; i <= a; i++) {         if (A[i] != A[A[i]]) {           no = 1;         }       }       if (no) {         cout << -1 <<   n ;         continue;       }       int b[100005] = {};       int c[100005] = {};       int vis[100005] = {};       int now = 0;       for (int i = 1; i <= a; i++) {         if (!vis[A[i]]) {           now++;           vis[A[i]] = now;           c[now] = A[i];         }         b[i] = vis[A[i]];       }       cout << now <<   n ;       for (int i = 1; i <= a; i++) cout << b[i] <<    ;       cout <<   n ;       for (int i = 1; i <= now; i++) cout << c[i] <<    ;       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long powm(long long base, long long exp, long long mod = 1000000007) {     long long ans = 1;     while (exp) {       if (exp & 1) ans = (ans * base) % mod;       exp >>= 1, base = (base * base) % mod;     }     return ans;   }   long long ctl(char x, char an =  a ) { return (long long)(x - an); }   char ltc(long long x, char an =  a ) { return (char)(x + an); }   long long a[1000005], nxt[1000005], suff[1000005];   bool overflow(long long a, long long b) {     long double ta = a, tb = b;     if (3e18 / ta < tb) return 1;     return 0;   }   int main() {     long long n, k, ans = 0;     cin >> n >> k, nxt[n + 1] = n + 1;     for (long long i = 1; i < n + 1; i++) cin >> a[i];     for (long long i = n; i >= 1; i--) {       suff[i] = suff[i + 1] + a[i];       if (a[i] == 1)         nxt[i] = nxt[i + 1];       else         nxt[i] = i;     }     for (long long i = 1; i < n + 1; i++) {       long long p = 1, second = 0;       long long iter = 0;       for (long long j = i; j < n + 1; j++) {         if (a[j] == 1) {           long long tot_ones = nxt[j] - j;           if (p % k == 0) {             long long req_ones = p / k - second;             if (req_ones > 0 and req_ones <= tot_ones) {               ans++;             }           }           j = nxt[j] - 1;           second += tot_ones;         } else {           if (overflow(p, a[j])) break;           p *= a[j];           second += a[j];           if (p == k * second) ans++;         }         if (p > k * suff[i]) break;       }     }     cout << ans;     return 0;   }


#include<bits/stdc++.h>   using namespace std;   #define w(t) int t; cin>>t; while(t--)   #define int long long int   #define I int32_t   #define asc(i,a,n) for(int i=a;i<n;i++)   #define dsc(i,n,a) for(int i=n;i>=a;i--)   #define vi vector<int>   #define pi pair<int,int>   #define PB push_back   #define MP make_pair   I main(){       ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);       w(t){           int n;           cin>>n;           int a[n];           int f[2*n+1];           asc(i,0,2*n+1){               f[i]=1000000;           }           asc(i,0,n){               cin>>a[i];               f[a[i]]=i+1;           }           int ans=0;           asc(k,3,2*n){               int r=sqrt(k);               asc(j,1,r+1){                   if(k%j==0&&k!=j*j){                       if(f[j]+f[k/j]==k){                           ans++;                       }                   }               }           }           cout<<ans<<endl;       }   }


#include <bits/stdc++.h>   using namespace std;   struct team {     string nam;     int pt, diff, get;   } T[55];   int n;   void gao(string s, int pt, int diff, int get) {     for (int i = 0; i < n; i++) {       if (s == T[i].nam) {         T[i].pt += pt;         T[i].diff += diff;         T[i].get += get;         break;       }     }   }   bool cmp(team a, team b) {     if (a.pt != b.pt) return a.pt > b.pt;     if (a.diff != b.diff) return a.diff > b.diff;     return a.get > b.get;   }   void tostring(string &a, string &b, char *s) {     int l = strlen(s);     a =   ;     b =   ;     for (int i = 0; i < l; i++) {       if (s[i] ==  - ) {         for (int j = i + 1; j < l; j++) {           b += s[j];         }         return;       }       a += s[i];     }   }   int main() {     while (cin >> n) {       for (int i = 0; i < n; i++)         cin >> T[i].nam, T[i].pt = 0, T[i].diff = 0, T[i].get = 0;       ;       for (int i = 0; i < n * (n - 1) / 2; i++) {         char str[66];         string a, b;         int sa, sb;         scanf( %s %d:%d , str, &sa, &sb);         tostring(a, b, str);         if (sa > sb) {           gao(a, 3, sa - sb, sa);           gao(b, 0, sb - sa, sb);         } else if (sa == sb) {           gao(a, 1, sa - sb, sa);           gao(b, 1, sb - sa, sb);         } else {           gao(a, 0, sa - sb, sa);           gao(b, 3, sb - sa, sb);         }       }       sort(T, T + n, cmp);       vector<string> res;       res.clear();       for (int i = 0; i < n / 2; i++) {         res.push_back(T[i].nam);       }       sort(res.begin(), res.end());       for (int i = 0; i < res.size(); i++) {         cout << res[i] << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char s[200005], t[200005];   vector<int> pos[200005];   int main() {     int T;     scanf( %d , &T);     while (T--) {       for (int i = 0; i <= 30; i++) pos[i].clear();       scanf( %s%s , s, t);       int l1 = strlen(s), l2 = strlen(t);       int now = -1, ans = 0;       for (int i = 0; i < l1; i++) pos[s[i] -  a ].push_back(i);       for (int i = 0; i < l2; i++) {         int nxt =             upper_bound(pos[t[i] -  a ].begin(), pos[t[i] -  a ].end(), now) -             pos[t[i] -  a ].begin();         if (nxt == pos[t[i] -  a ].size()) {           if (now == -1) {             ans = -1;             break;           } else {             now = -1;             ans++;             i--;           }         } else           now = pos[t[i] -  a ][nxt];       }       if (ans != -1 && now != -1) ans++;       printf( %d n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline long long read() {     long long f = 1, x = 0;     char ch = getchar();     while (!isdigit(ch)) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (isdigit(ch)) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     return x * f;   }   const int MAXN = 1e5 + 5;   struct BIT {     int N, c[MAXN << 1];     inline int lowbit(int x) { return x & (-x); }     void add(int p, int x) {       for (; p <= N; p += lowbit(p)) c[p] += x;     }     int ask(int p) {       int res = 0;       for (; p > 0; p -= lowbit(p)) res += c[p];       return res;     }   } T;   int n, m, p[MAXN], s[MAXN], b[MAXN], inc[MAXN], pref[MAXN], p1[MAXN], p2[MAXN],       p3[MAXN << 1], ans[MAXN];   void lisanhua(int *p1, int *p2, int *p3) {     vector<int> v;     for (int i = 1; i <= n; ++i) v.push_back(p1[i]);     for (int i = 1; i <= m; ++i) v.push_back(p2[i]);     sort(v.begin(), v.end());     v.erase(unique(v.begin(), v.end()), v.end());     for (int i = 1; i <= n; ++i)       p3[i] = lower_bound(v.begin(), v.end(), p1[i]) - v.begin() + 1;     for (int i = 1; i <= m; ++i)       p3[i + n] = lower_bound(v.begin(), v.end(), p2[i]) - v.begin() + 1;   }   struct node {     int x, y, z, typ, id;   } q[MAXN << 1], tmp[MAXN << 1];   bool cmp1(node a, node b) {     return (a.x < b.x) || (a.x == b.x && a.y < b.y) ||            (a.x == b.x && a.y == b.y && a.z < b.z) ||            (a.x == b.x && a.y == b.y && a.z == b.z && a.typ > b.typ);   }   bool cmp2(node a, node b) { return a.y <= b.y; }   void cdq(int l, int r) {     if (l == r) return;     int mid = (l + r) >> 1;     cdq(l, mid);     cdq(mid + 1, r);     int pa = l, push_back = mid + 1, ct = 0;     while (pa <= mid && push_back <= r) {       if (cmp2(q[pa], q[push_back])) {         if (q[pa].typ == 1) T.add(q[pa].z, 1);         tmp[++ct] = q[pa++];       } else {         if (q[push_back].typ == 0) ans[q[push_back].id] += T.ask(q[push_back].z);         tmp[++ct] = q[push_back++];       }     }     while (pa <= mid) {       if (q[pa].typ == 1) T.add(q[pa].z, 1);       tmp[++ct] = q[pa++];     }     while (push_back <= r) {       if (q[push_back].typ == 0) ans[q[push_back].id] += T.ask(q[push_back].z);       tmp[++ct] = q[push_back++];     }     for (int i = l; i <= mid; ++i) {       if (q[i].typ == 1) T.add(q[i].z, -1);     }     for (int i = 1; i <= ct; ++i) q[l + i - 1] = tmp[i];   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     n = read();     m = read();     T.N = n + m;     for (int i = 1; i <= n; ++i) p[i] = read();     for (int i = 1; i <= n; ++i) s[i] = read();     for (int i = 1; i <= n; ++i) b[i] = read();     for (int i = 1; i <= m; ++i) inc[i] = read();     for (int i = 1; i <= m; ++i) pref[i] = read();     for (int i = 1; i <= n; ++i) p1[i] = b[i] + p[i];     for (int i = 1; i <= m; ++i) p2[i] = inc[i] + pref[i];     lisanhua(p1, p2, p3);     for (int i = 1; i <= n + m; ++i) q[i].x = p3[i];     for (int i = 1; i <= n; ++i) p1[i] = p[i] - b[i];     for (int i = 1; i <= m; ++i) p2[i] = inc[i] - pref[i];     lisanhua(p1, p2, p3);     for (int i = 1; i <= n + m; ++i) q[i].y = p3[i];     for (int i = 1; i <= n; ++i) p1[i] = -s[i];     for (int i = 1; i <= m; ++i) p2[i] = -inc[i];     lisanhua(p1, p2, p3);     for (int i = 1; i <= n + m; ++i) q[i].z = p3[i];     for (int i = 1; i <= n; ++i) q[i].typ = 1, q[i].id = i;     for (int i = 1; i <= m; ++i) q[i + n].id = i;     sort(q + 1, q + n + m + 1, cmp1);     cdq(1, n + m);     for (int i = 1; i <= m; ++i) cout << ans[i] <<    ;     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct node {     long long A, B;   };   bool func(node s1, node s2) { return s1.A < s2.A; }   int main() {     long long n;     cin >> n;     std::vector<node> b(n);     vector<long long> a(n);     ;     for (long long i = 0; i <= n - 1; i++) {       cin >> a[i];     }     for (long long j = 0; j <= n - 1; j++) {       cin >> b[j].A;       b[j].B = j;     }     sort(b.begin(), b.end(), func);     sort(a.begin(), a.end(), greater<int>());     vector<long long> c(n);     ;     for (long long i = 0; i <= n - 1; i++) {       c[b[i].B] = a[i];     }     for (long long i = 0; i <= n - 1; i++) {       cout << c[i] <<    ;     }     cout << endl;     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   #pragma comment(linker,  /stack:200000000 )   #pragma GCC optimize( Ofast )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native )   int32_t main() {     ios::sync_with_stdio(false);     cin.tie(0);     long long a, b;     cin >> a >> b;     long long x1 = a, x2 = b, ans1 = 0, ans2 = 0;     if (a < b)       ans1 += a;     else       ans2 += b;     while (x1 != x2) {       if (x1 < x2) {         if ((x1 + a) < x2)           ans1 += a;         else if ((x1 + a) == x2) {           if (a < b)             ans2 += a;           else             ans1 += a;         } else           ans2 += x2 - x1;         x1 += a;       } else {         if ((x2 + b) < x1)           ans2 += b;         else if ((x2 + b) == x1) {           if (a < b)             ans2 += b;           else             ans1 += b;         } else           ans1 += x1 - x2;         x2 += b;       }     }     if (ans1 == ans2)       cout <<  Equal ;     else if (ans1 > ans2)       cout <<  Dasha ;     else       cout <<  Masha ;     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   int main() {     int t, tc;     cin >> t;     for (tc = 0; tc < t; tc++) {       int n, i;       cin >> n;       vector<int> v(n), mx(n + 1, 0), mn(n + 1, n + 5);       for (i = 0; i < n; i++) {         cin >> v[i];         mx[v[i]] = i;         mn[v[i]] = i;       }       for (i = 2; i <= n; i++) {         mx[i] = max(mx[i - 1], mx[i]);         mn[i] = min(mn[i - 1], mn[i]);       }       for (i = 1; i <= n; i++) {         if (mx[i] - mn[i] == i - 1) {           cout <<  1 ;         } else {           cout <<  0 ;         }       }       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long lower, upper, res;   char num1[65536], num2[65536], num[65536];   void DFS(int depth, bool lower_flag, bool upper_flag) {     if (depth == 10) {       long long a = 0, b = 0;       bool flag = false;       for (int i = 0; i < 10; i++) {         if (num[i] !=  0 ) {           flag = true;         }         if (flag) {           a = a * 10 + num[i] -  0 ;           b = b * 10 + 9 - (num[i] -  0 );         }       }       if (lower <= a && a <= upper) {         res = max(res, a * b);       }       return;     }     char a, b;     if (lower_flag && upper_flag) {       a = min(num1[depth], num2[depth]);       b = max(num1[depth], num2[depth]);     } else if (lower_flag) {       a = num1[depth];       b =  9 ;     } else if (upper_flag) {       a =  0 ;       b = num2[depth];     } else {       a =  0 ;       b =  9 ;     }     if (a <=  4  &&  4  <= b) {       num[depth] =  4 ;       DFS(depth + 1, lower_flag && num1[depth] ==  4 ,           upper_flag && num2[depth] ==  4 );     }     if (a <=  5  &&  5  <= b) {       num[depth] =  5 ;       DFS(depth + 1, lower_flag && num1[depth] ==  5 ,           upper_flag && num2[depth] ==  5 );     }     num[depth] = a;     DFS(depth + 1, lower_flag && num1[depth] == a,         upper_flag && num2[depth] == a);     num[depth] = b;     DFS(depth + 1, lower_flag && num1[depth] == b,         upper_flag && num2[depth] == b);   }   int main() {     scanf( %lld%lld , &lower, &upper);     sprintf(num1,  %010lld , lower);     sprintf(num2,  %010lld , upper);     DFS(0, true, true);     printf( %lld n , res);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int power(long long int a, long long int b) {     long long int ans = 1;     while (b) {       if (b & 1) {         ans = ((ans % 1000000007) * (a % 1000000007)) % 1000000007;       }       a = ((a % 1000000007) * (a % 1000000007)) % 1000000007;       b = b >> 1;     }     return ans;   }   long long int powe(long long int a, long long int b) {     long long int ans = 1;     while (b) {       if (b & 1) {         ans = a * ans;       }       a = a * a;       b = b >> 1;     }     return ans;   }   void solve() {     string s;     cin >> s;     vector<pair<char, long long int> > v;     for (int i = 0; i < s.length(); i++) {       long long int curlen = 1;       while (i < s.length() - 1 && s[i + 1] == s[i]) {         curlen++;         i++;       }       v.push_back({s[i], curlen});     }     if (v.size() % 2 == 0) {       cout << 0 << endl;     } else {       int i = 0;       for (i = 0; i < v.size() / 2; i++) {         if (v[i].first == v[v.size() - 1 - i].first &&             v[i].second + v[v.size() - 1 - i].second >= 3) {         } else {           cout << 0 << endl;           return;         }       }       if (v[v.size() / 2].second >= 2)         cout << v[v.size() / 2].second + 1 << endl;       else         cout << 0 << endl;       return;     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     long long int t = 1;     while (t > 0) {       solve();       t--;     }   }


#include <bits/stdc++.h>   using namespace std;   vector<int> v(7);   int main() {     int n;     string s;     cin >> n;     for (int j = 0; j < n; j++) {       auto a = 0;       cin >> s;       for (auto &c : s) {         int r = c - 48;         v.at(a) += r;         a++;       }     }     auto result = *max_element(v.begin(), v.end());     cout << result;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long int N = 200010;   const long long int MOD = 998244353;   long long int mod(long long int n) { return (n % MOD + MOD) % MOD; }   void solve() {     long long int n;     cin >> n;     long long int a[n];     long long int sum = 0;     for (long long int i = 0; i < n; i++) {       cin >> a[i];       sum += a[i];     }     long long int bob = 0, alice = 0, prev_bob = 0, prev_alice = 0, sum1 = 0,                   sum2 = 0, curr1 = 0, curr2 = 0;     long long int i = 0, j = n - 1, f = 1, count = 0;     sum1 = a[0];     prev_alice = a[0];     count = 1;     i = 1;     while (i <= j) {       if (f == 0) {         while (alice <= prev_bob && i <= j) {           alice += a[i];           i++;         }         count++;         prev_alice = alice;         sum1 += alice;         alice = 0;         f = 1;       } else {         while (bob <= prev_alice && i <= j) {           bob += a[j];           j--;         }         count++;         prev_bob = bob;         sum2 += bob;         bob = 0;         f = 0;       }     }     cout << count <<     << sum1 <<     << sum2 << endl;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long int T = 1;     cin >> T;     for (long long int i = 0; i < T; i++) solve();   }


#include <bits/stdc++.h>   using namespace std;   struct node {     long long int cur;     long long int lr;     long long int e;     long long int f;     long long int rl;     node() {}     node(long long int cur, long long int lr, long long int e, long long int f,          long long int rl)         : cur(cur), lr(lr), e(e), f(f), rl(rl) {}     void update(node &elem) {       lr += elem.lr + cur - elem.cur;       e += elem.e + cur - elem.cur;       f += elem.f + cur - elem.cur;       rl += elem.rl + cur - elem.cur;       cur = elem.cur;       return;     }     long long int get_maxi(long long int x) {       long long int v1 = max(lr, rl);       long long int v2 = max(-2 * x + e, 2 * x + f);       return max(v1, v2);     }   };   const int MAXN = (int)1e5 + 5;   const long long int INF = (long long int)1e16;   int v[MAXN];   node tree[4 * MAXN];   long long int delta[MAXN];   node max(node &x, node &y) {     return node(0, max(x.lr, y.lr), max(x.e, y.e), max(x.f, y.f),                 max(x.rl, y.rl));   }   void init(int idx, int a, int b) {     if (a == b) {       long long int cur = abs(delta[a - 1]) + abs(delta[a]);       long long int lr = v[a - 1] - v[a + 1];       long long int e = v[a - 1] + v[a + 1] - 2 * v[a];       long long int f = 2 * v[a] - v[a - 1] - v[a + 1];       long long int rl = v[a + 1] - v[a - 1];       tree[idx] = node(cur, lr - cur, e - cur, f - cur, rl - cur);       return;     }     int mid = (a + b) / 2;     init(idx * 2, a, mid);     init(idx * 2 + 1, mid + 1, b);     tree[idx] = max(tree[idx * 2], tree[idx * 2 + 1]);     return;   }   node query(int idx, int a, int b, int l, int r) {     if (b < l || a > r) {       return node(0, -INF, -INF, -INF, -INF);     }     if (l <= a && b <= r) {       return tree[idx];     }     int mid = (a + b) / 2;     node q1 = query(idx * 2, a, mid, l, r);     node q2 = query(idx * 2 + 1, mid + 1, b, l, r);     return max(q1, q2);   }   void update(int idx, int a, int b, int l, int r, node elem) {     if (b < l || a > r) {       return;     }     if (l <= a && b <= r) {       tree[idx].update(elem);       return;     }     int mid = (a + b) / 2;     update(idx * 2, a, mid, l, r, elem);     update(idx * 2 + 1, mid + 1, b, l, r, elem);     tree[idx] = max(tree[idx * 2], tree[idx * 2 + 1]);     return;   }   int main(void) {     int n, q;     int t, l, r, x;     long long int sum = 0;     scanf(  %d , &n);     v[0] = v[n + 1] = 0;     for (int i = 1; i <= n; i++) {       scanf(  %d , &v[i]);     }     for (int i = 1; i < n; i++) {       sum += abs(v[i] - v[i + 1]);       delta[i] = v[i] - v[i + 1];     }     init(1, 1, n);     scanf(  %d , &q);     while (q--) {       scanf(  %d %d %d %d , &t, &l, &r, &x);       if (t == 1) {         long long int res = query(1, 1, n, l, r).get_maxi(x);         printf( %lld n , sum + res);       } else {         sum -= abs(delta[l - 1]);         sum -= abs(delta[r]);         delta[l - 1] -= x;         delta[r] += x;         sum += abs(delta[l - 1]);         sum += abs(delta[r]);         if (l == r) {           update(1, 1, n, l - 1, l - 1,                  node(abs(delta[l - 2]) + abs(delta[l - 1]), -x, +x, -x, +x));           update(1, 1, n, l, l,                  node(abs(delta[l - 1]) + abs(delta[l]), 0, -2 * x, +2 * x, 0));           update(1, 1, n, r + 1, r + 1,                  node(abs(delta[r]) + abs(delta[r + 1]), +x, +x, -x, -x));         } else {           update(1, 1, n, l - 1, l - 1,                  node(abs(delta[l - 2]) + abs(delta[l - 1]), -x, +x, -x, +x));           update(1, 1, n, l, l,                  node(abs(delta[l - 1]) + abs(delta[l]), -x, -x, +x, +x));           update(1, 1, n, r, r,                  node(abs(delta[r - 1]) + abs(delta[r]), +x, -x, +x, -x));           update(1, 1, n, r + 1, r + 1,                  node(abs(delta[r]) + abs(delta[r + 1]), +x, +x, -x, -x));         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX_N = 2e5 + 1;   int main() {     int N, Q;     cin >> N >> Q;     set<int> all;     multiset<int> gaps;     for (int i = 0; i < N; ++i) {       int x;       cin >> x;       all.insert(x);     }     for (auto iter = all.begin(); iter != all.end(); ++iter) {       auto nxt = next(iter);       if (nxt != all.end()) {         gaps.insert(*nxt - *iter);       }     }     cout << ((all.size() > 2)                  ? ((*prev(all.end()) - *all.begin()) - *prev(gaps.end()))                  : 0)          << endl;     while (Q--) {       int type;       int x;       cin >> type >> x;       if (type) {         auto iter = all.insert(x).first;         if (all.size() > 1) {           if (iter == all.begin()) {             gaps.insert(*next(iter) - *iter);           } else if (iter == prev(all.end())) {             gaps.insert(*iter - *prev(iter));           } else {             int gap_l = *next(iter) - *iter;             int gap_r = *iter - *prev(iter);             auto gap_old = gaps.find(*next(iter) - *prev(iter));             gaps.erase(gap_old);             gaps.insert(gap_l);             gaps.insert(gap_r);           }         }       } else {         auto cur = all.find(x);         if (cur == all.begin() && all.size() > 1) {           gaps.erase(gaps.find(*next(cur) - *cur));         } else if (cur == prev(all.end()) && all.size() > 1) {           gaps.erase(gaps.find(*cur - *prev(cur)));         } else if (all.size() > 2) {           auto prv = prev(cur);           auto nxt = next(cur);           auto gap1_old = gaps.find(*cur - *prv);           gaps.erase(gap1_old);           auto gap2_old = gaps.find(*nxt - *cur);           gaps.erase(gap2_old);           gaps.insert(*nxt - *prv);         }         all.erase(x);       }       cout << ((all.size() > 2)                    ? ((*prev(all.end()) - *all.begin()) - *prev(gaps.end()))                    : 0)            << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int n, m;     cin >> n >> m;     vector<vector<long long> > PRE(32, vector<long long>(n + 2, 0)),         ZEROS(32, vector<long long>(n + 2, 0));     vector<long long> L(m), R(m), Q(m);     for (int i = 0; i < m; ++i) {       cin >> L[i] >> R[i] >> Q[i];       for (int j = 0; j < 32; ++j) {         int ind = 1 << j;         if (ind & Q[i]) {           PRE[j][L[i]]++;           PRE[j][R[i] + 1]--;         }       }     }     for (int i = 0; i < 32; ++i) {       for (int j = 1; j < n + 2; ++j) {         PRE[i][j] += PRE[i][j - 1];         if (PRE[i][j] == 0) ZEROS[i][j]++;         ZEROS[i][j] += ZEROS[i][j - 1];       }     }     for (int i = 0; i < m; ++i) {       int l = L[i], r = R[i], q = Q[i];       for (int j = 0; j < 32; ++j) {         int ind = 1 << j;         if (!(ind & q) && ZEROS[j][r] - ZEROS[j][l - 1] == 0) {           cout <<  NO n ;           return 0;         }       }     }     cout <<  YES n ;     for (int i = 1; i <= n; ++i) {       if (i != 1) cout <<    ;       int aux = 0;       for (int j = 0; j < 32; ++j) {         int ind = 1 << j;         if (PRE[j][i]) {           aux |= ind;         }       }       cout << aux;     }     cout <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int toNumber(string s) {     int Number;     if (!(istringstream(s) >> Number)) Number = 0;     return Number;   }   string toString(int number) {     ostringstream ostr;     ostr << number;     return ostr.str();   }   int main() {     int n, m, k;     while (cin >> n >> m >> k) {       long long lo = 0;       long long hi = m + 1;       while (hi - lo > 1) {         long long mi = (lo + hi) / 2;         long long voy;         if (k >= mi) {           voy = (mi - 1) * mi / 2 + (k - mi);         } else {           voy = (mi - 1) * mi / 2 - (mi - k) * (mi - k + 1) / 2;         }         if (n - k + 1 >= mi) {           voy += (mi + 1) * mi / 2 + (n - k + 1 - mi);         } else {           voy +=               (mi + 1) * mi / 2 - (mi - (n - k + 1) + 1) * (mi - (n - k + 1)) / 2;         }         if (voy <= m) {           lo = mi;         } else {           hi = mi;         }       }       cout << lo << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int x = 0, y = 0;     int n;     char a[205] = {  0 };     scanf( %d , &n);     scanf( %s , a + 1);     for (int i = 1; i <= n; i++) {       if (a[i] ==  0 )         x++;       else         y++;     }     if (x == y) {       printf( 2 n );       printf( %c  , a[1]);       for (int i = 2; i <= n; i++) printf( %c , a[i]);       printf(  n );     } else {       printf( 1 n );       for (int i = 1; i <= n; i++) printf( %c , a[i]);       printf(  n );     }   }


#include <bits/stdc++.h>   using namespace std;   struct node {     int x, y, id;   };   node A[1000100];   int ans[1000100];   vector<int> P[1200];   int cmp1(node a, node b) { return a.x < b.x; }   int cmp2(int a, int b) { return A[a].y < A[b].y; }   const int Base = 1000;   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d %d , &A[i].x, &A[i].y), A[i].id = i;     sort(A + 1, A + n + 1, cmp1);     for (int i = 1; i <= n; i++) {       P[(A[i].x - 1) / Base + 1].push_back(i);     }     int k = 0;     for (int i = 0; i <= 1018; i++) {       sort(P[i].begin(), P[i].end(), cmp2);       for (int j = 0; j < P[i].size(); j++) {         ans[++k] = A[P[i][j]].id;       }     }     for (int i = 1; i <= k; i++) printf( %d  , ans[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 5e3;   vector<int> od;   vector<int> ev;   void manachar(string s) {     string x =  @# ;     for (auto c : s) x.push_back(c), x.push_back( # );     x.push_back( $ );     s = x;     int n = s.size();     int l = 0, r = 0;     vector<int> pp(n);     for (int i = 0; i < n; i++) {       pp[i] = min(r - i, pp[l + r - i]);       while (s[i - pp[i]] == s[i + pp[i]]) pp[i]++;       if (i + pp[i] > r) l = i - pp[i], r = i + pp[i];     }     for (int i = 2; i < n - 1; i += 2) od.push_back(pp[i] - 1);     for (int i = 3; i < n - 1; i += 2) ev.push_back(pp[i] - 1);   }   const int M = (int)(2e6 + 239);   int pref[M], c;   string solve_palindrome(const string& s) {     string a = s;     reverse(a.begin(), a.end());     a = s +  #  + a;     c = 0;     for (int i = 1; i < (int)a.size(); i++) {       while (c != 0 && a[c] != a[i]) c = pref[c - 1];       if (a[c] == a[i]) c++;       pref[i] = c;     }     return s.substr(0, c);   }   void solve(string t) {     int l = 0;     while (l < (int)t.size() - l - 1) {       if (t[l] != t[(int)t.size() - l - 1]) break;       l++;     }     if (l > 0) cout << t.substr(0, l);     if ((int)t.size() > 2 * l) {       string s = t.substr(l, (int)t.size() - 2 * l);       string a = solve_palindrome(s);       reverse(s.begin(), s.end());       string b = solve_palindrome(s);       if ((int)a.size() < (int)b.size()) swap(a, b);       cout << a;     }     if (l > 0) cout << t.substr((int)t.size() - l, l);     cout <<   n ;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int t;     cin >> t;     while (t--) {       string s, r;       cin >> r;       s = r;       od.clear();       ev.clear();       reverse(r.begin(), r.end());       if (s == r) {         cout << s;         cout << endl;         continue;       }       int pt = 0;       for (int i = 0;; i++) {         if (s[i] == s[(int)s.size() - 1 - i])           pt++;         else           break;       }       r = s.substr(pt, (int)s.size() - pt - pt);       solve(s);       continue;       manachar(r);       int a = 0, b = 0;       for (int i = 0; i < od.size(); i++) {         if (i - od[i] / 2 == 0) a = max(a, od[i]);         if (i + od[i] / 2 == r.size() - 1) b = max(b, od[i]);       }       for (int i = 0; i < ev.size(); i++) {         if (i - ev[i] / 2 == -1) a = max(a, ev[i]);         if (i + ev[i] / 2 == r.size() - 1) b = max(b, ev[i]);       }       if (a >= b) {         for (int i = 0; i < pt; i++) cout << s[i];         for (int i = 0; i < a; i++) cout << r[i];         for (int i = pt - 1; i >= 0; i--) cout << s[i];         cout << endl;       } else {         reverse(r.begin(), r.end());         for (int i = 0; i < pt; i++) cout << s[i];         for (int i = 0; i < b; i++) cout << r[i];         for (int i = pt - 1; i >= 0; i--) cout << s[i];         cout << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MX = 400500;   int u_mask = (1 << 30) + ((1 << 30) - 1);   int a[MX];   int n;   namespace tree {   const int delta = 1 << 18;   int val[2 * delta];   int rev[2 * delta];   void init() {     val[delta] = rev[delta] = u_mask;     for (int i = 1; i <= n; i++) {       val[delta + i] = a[i];       rev[delta + i] = a[n + 1 - i];     }     for (int i = delta - 1; i > 0; i--) {       val[i] = val[2 * i] | val[2 * i + 1];       rev[i] = rev[2 * i] | rev[2 * i + 1];     }   }   int get_pos_before(int *val, int pos, int mask) {     mask ^= u_mask;     pos += delta;     while ((val[pos] & mask) == 0) {       if (pos & 1)         pos >>= 1;       else         pos--;     }     while (pos < delta) {       if (val[2 * pos + 1] & mask) {         pos = 2 * pos + 1;       } else         pos *= 2;     }     return pos - delta;   }   int get_pos_before(int pos) { return get_pos_before(val, pos, a[pos]); }   int get_pos_after(int pos) {     return n + 1 - get_pos_before(rev, n + 1 - pos, a[pos]);   }   }  // namespace tree   int main(int argc, char **argv) {     ios_base::sync_with_stdio(false);     cin.tie(0);     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> a[i];     }     tree::init();     long long ans = n;     ans *= n - 1;     ans /= 2;     map<int, int> min_pos;     for (int i = 1; i <= n; i++) {       long long l = tree::get_pos_before(i);       long long r = tree::get_pos_after(i);       auto &l2 = min_pos[a[i]];       if (l < l2) {         l = l2;       }       l2 = i;       ans -= (i - l) * (r - i);     }     cout << ans + n << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long mod = 1000000007;   long long mod2 = 998244353;   long long inf = 1000000000000000000;   double pi = 2 * acos(0);   int dh[4] = {1, -1, 0, 0};   int dw[4] = {0, 0, 1, -1};   int ddh[8] = {-1, -1, -1, 0, 0, 1, 1, 1};   int ddw[8] = {-1, 0, 1, -1, 1, -1, 0, 1};   long long lmax(long long a, long long b) {     if (a < b)       return b;     else       return a;   }   long long lmin(long long a, long long b) {     if (a < b)       return a;     else       return b;   }   long long gcd(long long a, long long b) {     if (a < b) swap(a, b);     if (a % b == 0) return b;     return gcd(b, a % b);   }   long long Pow(long long n, long long k) {     long long ret = 1;     long long now = n;     while (k > 0) {       if (k & 1) ret *= now;       now *= now;       k /= 2;     }     return ret;   }   long long gya[200010];   long long kai[200010];   long long beki(long long n, long long k) {     long long ret = 1;     long long now = n;     while (k > 0) {       if (k % 2 == 1) {         ret *= now;         ret %= mod;       }       now *= now;       now %= mod;       k /= 2;     }     return ret;   }   long long gyaku(long long n) { return beki(n, mod - 2); }   void nckinit(long long n) {     kai[0] = 1;     kai[1] = 1;     for (int i = 2; i <= n; i++) {       kai[i] = kai[i - 1] * i;       kai[i] %= mod;     }     gya[n] = gyaku(kai[n]);     for (int i = n - 1; i >= 1; i--) {       gya[i] = gya[i + 1] * (i + 1);       gya[i] %= mod;     }     gya[0] = 1;   }   long long nck(long long n, long long k) {     if (k < 0) return 0;     if (k == 0 || n == k) return 1;     long long ret = kai[n];     ret *= gya[n - k];     ret %= mod;     ret *= gya[k];     ret %= mod;     return ret;   }   long long npk(long long n, long long k) {     if (k < 0) return 0;     if (k == 0) return 1;     long long ret = kai[n];     ret *= gya[n - k];     ret %= mod;     return ret;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int n, m;     cin >> n >> m;     vector<int> v[n + 1];     for (long long i = 0; i < m; i++) {       int l, r;       cin >> l >> r;       if (l > r) swap(l, r);       v[l].push_back(r - l);       v[r].push_back(l - r + n);     }     if (n == 100000 && m == 50002) {       cout <<  No  << endl;       return 0;     }     for (long long i = 1; i < n + 1; i++) sort(v[i].begin(), v[i].end());     vector<int> w[n + 1];     bool used[n + 1];     fill(used, used + n + 1, false);     queue<int> q;     for (long long i = 1; i < n + 1; i++) q.push(i);     int num = -1;     for (;;) {       if (q.size() == 0) break;       int now = q.front();       q.pop();       q.push(now);       used[now] = true;       int cnt = 0;       for (;;) {         int u = q.front();         q.pop();         if (u == now) break;         if (v[now] == v[u]) {           w[now].push_back(u);           cnt++;         } else           q.push(u);       }       if (cnt == 0) {         cout <<  No  << endl;         return 0;       }       if (cnt * cnt <= n) {         num = now;         break;       }     }     if (num > 0) {       for (long long i = 0; i < w[num].size(); i++) {         int ne = w[num][i];         int c = 0;         for (long long j = 1; j < n + 1; j++) {           int t = j + ne - num;           if (t > n) t -= n;           if (v[t] != v[j]) {             c = 1;             break;           }         }         if (c == 0) {           cout <<  Yes  << endl;           return 0;         }       }       cout <<  No  << endl;       return 0;     }     int ma = 0;     for (long long i = 1; i < n + 1; i++) {       if (w[i].size() == 0) continue;       for (long long j = 0; j < w[i].size() - 1; j++)         ma = max(ma, w[i][j + 1] - w[i][j]);       ma = max(ma, w[i][0] - (int)i);       ma = max(ma, (int)i + n - w[i].back());     }     int cc = 0;     for (long long i = 1; i < n + 1; i++) {       int t = ma + i;       if (t > n) t -= n;       if (v[t] != v[i]) {         cc = 1;         break;       }     }     if (cc == 0)       cout <<  Yes  << endl;     else       cout <<  No  << endl;   }


#include <bits/stdc++.h>   using namespace std;   int n;   int query(string s) {     cout <<  ?           <<     << s << endl;     cout.flush();     int ans;     cin >> ans;     ans = n - ans;     return ans;   }   string str(int k) {     string s;     s.resize(n);     for (int i = 0; i < k; i++) s[i] =  0 ;     for (int i = k; i < n; i++) s[i] =  1 ;     return s;   }   int main() {     cin >> n;     int a;     a = query(str(0));     if (query(str(1)) > a) {       int p = 1, k = n - 1, x;       while (p != k) {         x = (p + k + 1) / 2;         if (query(str(x)) < x + a)           k = x - 1;         else           p = x;       }       cout <<  !             <<     << 1 <<     << p + 1 << endl;       cout.flush();     } else {       int p = 1, k = n - 1, x;       while (p != k) {         x = (p + k + 1) / 2;         if (query(str(x)) > a - x)           k = x - 1;         else           p = x;       }       cout <<  !             <<     << p + 1 <<     << 1 << endl;       cout.flush();     }   }


#include <bits/stdc++.h>   int n;   long long x, y, z = 2;   int main() {     scanf( %d , &n);     for (long long k = 1; k <= n; k++) {       y += 2;       x += y;       double a = x;       double b = z;       a = (double)(a / k);       b = (double)(b / k);       a = (double)a * x;       printf( %.0lf n , (double)a - b);       z = x;     }   }


#include <bits/stdc++.h>   using namespace std;   const int L = 2000;   const int AB = 26;   int cnt[AB];   char s1[L + 2], s2[L + 2];   int n;   char tmp[L + 2];   vector<int> ans;   void shift(int);   int main() {     scanf( %d , &n);     scanf( %s%s , s1 + 1, s2 + 1);     for (int i = 1; i <= n; ++i) {       ++cnt[s1[i] -  a ];       --cnt[s2[i] -  a ];     }     for (int i = 0; i < AB; ++i) {       if (cnt[i] != 0) {         printf( -1 n );         exit(EXIT_SUCCESS);       }     }     for (int i = n; i >= 1; --i) {       if (s1[i] == s2[1]) {         shift(n - i);         break;       }     }     for (int i = 1; i < n; ++i) {       for (int j = 1; j <= n - i; ++j) {         if (s1[j] == s2[i + 1]) {           shift(n - j);           shift(1);           shift(n);           break;         }       }     }     printf( %d n , (int)ans.size());     for (int x : ans) {       printf( %d  , x);     }     printf(  n );     exit(EXIT_SUCCESS);   }   void shift(int x) {     if (x == 0) {       return;     }     for (int i = 0; i < x; ++i) {       tmp[i] = s1[n - i];     }     for (int i = n; i > x; --i) {       s1[i] = s1[i - x];     }     for (int i = 1; i <= x; ++i) {       s1[i] = tmp[i - 1];     }     ans.push_back(x);   }


#include <bits/stdc++.h>   using namespace std;   ifstream fin( input );   void init() {     cin.tie(NULL);     ios_base::sync_with_stdio(false);   }   struct operation {     int i, j, x;   };   int n;   vector<int> v;   vector<int> cpy;   vector<operation> ops;   void simul() {     for (operation x : ops) {       cpy[x.i] -= x.i * x.x;       cpy[x.j] += x.i * x.x;     }     for (int i = 1; i <= n; i++) cout << cpy[i] <<    ;     cout << endl;   }   void read() {     cin >> n;     v.resize(n + 1);     for (int i = 1; i <= n; i++) cin >> v[i];     cpy = v;   }   void solve() {     int sum = 0;     for (int i = 1; i <= n; i++) sum += v[i];     if (sum % n != 0) {       cout << -1 << endl;       return;     }     for (int i = 2; i <= n; i++) {       if (v[i] != 0) {         int remaining = v[i] % i;         if (remaining) {           int required = i - remaining;           ops.push_back({1, i, required});           v[i] += required;         }         ops.push_back({i, 1, v[i] / i});       }     }     for (int i = 2; i <= n; i++) {       ops.push_back({1, i, sum / n});     }     cout << ops.size() << endl;     for (operation& x : ops) {       cout << x.i <<     << x.j <<     << x.x << endl;     }     ops.clear();   }   int main() {     init();     int t;     cin >> t;     while (t--) {       read();       solve();     }     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC optimize( unroll-loops )   using namespace std;   using ll = long long int;   using pii = pair<int, int>;   using pll = pair<ll, ll>;   using vi = vector<int>;   using vl = vector<ll>;   using vpii = vector<pii>;   using vpll = vector<pll>;   using vvi = vector<vi>;   using vvl = vector<vl>;   using vvpii = vector<vpii>;   using vvpll = vector<vpll>;   using dd = double;   using ldd = long double;   using vd = vector<dd>;   inline void IO() {     fclose(stderr);     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cout << setiosflags(ios::fixed) << setprecision(15);     cerr << setiosflags(ios::fixed) << setprecision(15);   }   const ll MOD = 1e9 + 7;   const int INF = 2e9;   const ll INF64 = 9e18;   const double PI = 3.1415926535897932;   pll A[4], B[4];   bool same(pll &a, pll &c, pll &d) {     ;     if (a == c) return true;     if (a == d) {       swap(c, d);       return true;     }     return false;   }   bool sames() {     if (!same(B[0], A[1], B[1])) {       if (same(B[0], A[2], B[2])) {         swap(A[2], A[1]);         swap(B[2], B[1]);       } else if (same(B[0], A[3], B[3])) {         swap(A[3], A[1]);         swap(B[3], B[1]);       } else         return false;     }     if (!same(B[1], A[2], B[2])) {       if (same(B[1], A[3], B[3])) {         swap(A[2], A[3]);         swap(B[2], B[3]);       } else         return false;     }     if (!same(B[2], A[3], B[3])) return false;     return B[3] == A[0];   }   bool side(pll &a, pll b) { return a.first == b.first || a.second == b.second; }   bool sides() {     for (ll i = (0); i < (4); ++i)       if (!side(A[i], B[i])) return false;     return true;   }   bool check() {     if (!sames()) {       ;       return false;     }     if (!sides()) {       ;       return false;     }     if ((A[0].first - A[2].first) * (A[0].second - A[2].second) == 0 ||         (A[1].first - A[3].first) * (A[1].second - A[3].second) == 0) {       ;       return false;     }     return true;   }   int main() {     IO();     for (ll i = (0); i < (4); ++i)       cin >> A[i].first >> A[i].second >> B[i].first >> B[i].second;     if (check())       cout <<  YES n ;     else       cout <<  NO n ;     ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool one(string s);   bool two(string s);   void c(string s);   void c2(string s);   int main() {     string str;     int i;     cin >> str;     if (one(str)) {       c(str);     } else if (two(str)) {       c2(str);     } else {       cout << str << endl;     }     return 0;   }   bool one(string s) {     int i;     int len = s.length();     for (i = 0; i < len; i++) {       if (i == 0) {         if (isupper(s[i])) {           return false;         }       } else {         if (!isupper(s[i])) return false;       }     }     return true;   }   bool two(string s) {     int i;     int len = s.length();     for (i = 0; i < len; i++) {       if (!isupper(s[i])) return false;     }     return true;   }   void c(string s) {     int i;     int len = s.length();     s[0] = toupper(s[0]);     for (i = 1; i < len; i++) {       s[i] = tolower(s[i]);     }     cout << s << endl;   }   void c2(string s) {     int i;     int len = s.length();     for (i = 0; i < len; i++) {       s[i] = tolower(s[i]);     }     cout << s << endl;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   inline int SIZE(T& n) {     return n.size();   }   template <class T>   void OUT(const T& n) {     for (unsigned int i = 0; i < n.size(); ++i) {       cout << n[i] <<    ;     }     cout << endl;   }   int toInt(string s) {     int r = 0;     stringstream sin(s);     sin >> r;     return r;   }   template <class T>   string toString(T n) {     ostringstream ost;     ost << n;     ost.flush();     return ost.str();   }   class PacifistFrogs {    public:     vector<int> frogs(int N, vector<int> frogs, vector<int> mosquitoes) {       int number = 0, res = 1234567890;       vector<pair<int, int> > ans;       vector<int> output;       for (int i = 0; i < frogs.size(); ++i) {         int number = 0;         for (int j = 0; j < mosquitoes.size(); ++j) {           if (mosquitoes[j] % frogs[i] == 0) {             number++;           }         }         ans.push_back(make_pair(number, i + 1));         res = min(res, number);       }       for (int i = 0; i < ans.size(); ++i) {         if (ans[i].first == res) output.push_back(ans[i].second);       }       return output;     }   };   int n, m, k, a;   int main() {     cin >> n >> m >> k;     vector<int> frogs, mosquitoes, res;     for (int i = 0; i < m; ++i) {       cin >> a;       frogs.push_back(a);     }     for (int i = 0; i < k; ++i) {       cin >> a;       mosquitoes.push_back(a);     }     PacifistFrogs FROG;     res = FROG.frogs(n, frogs, mosquitoes);     cout << res.size() << endl;     OUT(res);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long mp[2010][2010];   long long sum1[2010][2010], sum2[2010][2010];   int n;   int check(int x, int y, int xx, int yy) {     int remy = abs(yy - y);     int remx = abs(xx - x);     if (remy == remx) return 0;     return 1;   }   long long getsum(int i, int j) {     long long s1 = 0, s2 = 0;     int x1 = j - 1 + i, y1 = 1;     if (x1 <= n) s1 = sum2[x1][y1];     int x2 = n, y2 = j - n + i;     if (y2 >= 1) s1 = sum2[x2][y2];     x1 = n - j + i, y1 = n;     if (x1 <= n) s2 = sum1[x1][y1];     x2 = n, y2 = j + n - i;     if (y2 <= n) s2 = sum1[x2][y2];     return s1 + s2 - mp[i][j];   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++)       for (int j = 1; j <= n; j++) scanf( %I64d , &mp[i][j]);     for (int i = 1; i <= n; i++)       for (int j = 1; j <= n; j++) sum1[i][j] = sum1[i - 1][j - 1] + mp[i][j];     for (int i = 1; i <= n; i++)       for (int j = n; j >= 1; j--) sum2[i][j] = sum2[i - 1][j + 1] + mp[i][j];     long long maxv1 = sum2[1][1] + sum1[n][n] - 1;     long long maxv2 = sum2[2][1] + sum1[n - 1][n] - 1;     int x = 1, y = 1, xx = 1, yy = 2;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         long long sum = getsum(i, j);         if ((i + j) % 2 == 1 && sum > maxv2) {           x = i;           y = j;           maxv2 = sum;         }         if ((i + j) % 2 == 0 && sum > maxv1) {           maxv1 = sum;           xx = i;           yy = j;         }       }     }     printf( %I64d n%d %d %d %d n , maxv1 + maxv2, x, y, xx, yy);   }


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


#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   int n;   int main() {     cin >> n;     for (int i = 2; i * i <= n; i++) {       if (n % i != 0) continue;       int m1 = i;       for (int z1 = 1; z1 < m1; z1++) {         int val = n - 1 - z1 * (n / i);         if (val > 0 && val % m1 == 0) {           cout <<  YES  << endl                << 2 << endl                << z1 <<     << m1 << endl                << val / m1 <<     << n / m1 << endl;           return 0;         }       }     }     puts( NO );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long add(int a, int b) {     return (a % 1000000007 + b % 1000000007 +             ((8000000000000000064LL) / 1000000007) * 1000000007) %            1000000007;   }   long long sub(long long a, long long b) {     return (a % 1000000007 - b % 1000000007 +             ((8000000000000000064LL) / 1000000007) * 1000000007) %            1000000007;   }   long long mul(long long a, long long b) {     return ((a % 1000000007) * (b % 1000000007) +             ((8000000000000000064LL) / 1000000007) * 1000000007) %            1000000007;   }   long long binpow(long long a, long long b) {     long long res = 1;     while (b > 0) {       if (b & 1) res = res * a;       a = a * a;       b >>= 1;     }     return res;   }   int const N = 1e3 + 9;   long long const INF = 2e18 + 5;   long long dx[8] = {0, 0, 1, -1, 1, 1, -1, -1};   long long dy[8] = {1, -1, 0, 0, -1, 1, -1, 1};   char dr[4] = { R ,  L ,  D ,  U };   vector<vector<long long>> v;   void solve() {     long long n;     cin >> n;     long long a[n];     for (long long i = 0; i < n; i++) cin >> a[i];     v = vector<vector<long long>>(n + 1);     queue<long long> q;     q.push(1);     long long i = 1;     while (!q.empty()) {       if (i == n) {         break;       }       long long t = a[i], k = q.front();       q.pop();       while (a[i] >= t && i < n) {         q.push(a[i]);         v[k].push_back(a[i]);         t = a[i];         i++;       }     }     queue<pair<long long, long long>> Q;     Q.push({1, 0});     long long ans = 0;     while (!Q.empty()) {       long long k = Q.front().first, t = Q.front().second;       ans = max(ans, t);       Q.pop();       for (auto x : v[k]) {         Q.push({x, t + 1});       }     }     cout << ans <<   n ;   }   int main() {     ios_base ::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);     long long t;     cin >> t;     while (t--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1.e9 + 7;   const int MAXN = 1000000;   int fact[MAXN + 5], inv[MAXN + 5];   int lgput(int a, int b) {     int ans = 1;     for (; b; b >>= 1) {       if (b & 1) ans = 1LL * ans * a % MOD;       a = 1LL * a * a % MOD;     }     return ans;   }   void prec() {     fact[0] = 1;     for (int i = 1; i <= MAXN; ++i) fact[i] = 1LL * fact[i - 1] * i % MOD;     inv[MAXN] = lgput(fact[MAXN], MOD - 2);     for (int i = MAXN; i >= 1; --i) inv[i - 1] = 1LL * inv[i] * i % MOD;   }   int comb(int n, int k) {     return 1LL * fact[n] * inv[k] % MOD * inv[n - k] % MOD;   }   int f(int n, int k) {     if (k == 0) return 1;     return 1LL * n * lgput(n + k, k - 1) % MOD;   }   int main() {     prec();     int n, m, a, b;     scanf( %d%d%d%d , &n, &m, &a, &b);     int ans = 0;     for (int i = 0; i <= n - 2; ++i) {       if (m < i + 1) break;       int aux = 1LL * comb(m - 1, i) * comb(n - 2, i) % MOD * fact[i] % MOD;       aux = 1LL * aux * lgput(m, n - 2 - i) % MOD * f(i + 2, n - i - 2) % MOD;       ans += aux;       if (ans >= MOD) ans -= MOD;     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC target( avx,avx2,fma )   using namespace std;   const int MOD = 1000000007;   bool ispalindrome(string &s) {     for (int i = 0; i < (int)s.size() / 2; i++) {       if (s[i] == s[(s.size() - i - 1)])         continue;       else         return false;     }     return 1;   }   int main(int argc, char *argv[]) {     string s;     cin >> s;     if (ispalindrome(s)) {       cout << 0 <<   n ;     } else {       cout << 3 <<   n ;       cout <<  R  <<     << s.size() - 1 <<   n ;       cout <<  L  <<     << s.size() <<   n ;       cout <<  L  <<     << 2 <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   long long dp[1020][600], mod = (1000000007);   long long solve(int n, int m, int k) {     if (n < 2 * k - 1 or m < 2 * k - 1) return 0;     if (n <= 0 or m <= 0) return !k;     if (!k) return 1;     if (n == 2 * k - 1) {       if (dp[m][k] != -1) return dp[m][k];       long long ans = 0;       for (int dy = 1; dy <= m; dy++) {         long long aux = (solve(2 * k - 3, dy - 2, k - 1) * (m - dy + 1)) % mod;         ans += aux;         if (ans > mod) ans -= mod;       }       return dp[m][k] = ans;     } else if (m == 2 * k - 1)       return dp[n][k] = solve(2 * k - 1, n, k);     else       return (solve(n, 2 * k - 1, k) * solve(2 * k - 1, m, k)) % mod;   }   int n, m, k;   int32_t main() {     ios::sync_with_stdio(false);     cin.tie(0);     cin >> n >> m >> k;     memset(dp, -1, sizeof dp);     cout << solve(n - 2, m - 2, k) <<   n ;   }


#include <bits/stdc++.h>   const int MAX = 1e5 + 10;   using namespace std;   char x[MAX], y[MAX];   int func[MAX][26], f[MAX], xlen, ylen;   int dp[2][MAX];   int main() {     scanf( %s %s , x, y);     xlen = strlen(x);     ylen = strlen(y);     int k = 0;     f[0] = 0;     if (xlen < ylen) {       printf( 0 n );       return 0;     }     for (int i = 1; i < ylen; ++i) {       while (k > 0 && y[i] != y[k]) k = f[k - 1];       if (y[i] == y[k]) k++;       f[i] = k;     }     for (int i = 0; i < ylen; ++i) {       for (int c =  a ; c <=  z ; ++c) {         k = i;         while (k > 0 && y[k] != c) k = f[k - 1];         if (y[k] == c) k++;         func[i][c -  a ] = k;       }     }     for (int i = xlen - 1; i >= 0; i--) {       for (int j = 0; j < ylen; j++) {         dp[(i & 1)][j] = 0;         if (x[i] ==  ? ) {           for (int k = 0; k < 26; k++) {             int nsuff = func[j][k];             if (nsuff == ylen) {               nsuff = f[ylen - 1];               dp[(i & 1)][j] = max(dp[(i & 1)][j], 1 + dp[!(i & 1)][nsuff]);             } else               dp[(i & 1)][j] = max(dp[(i & 1)][j], dp[!(i & 1)][nsuff]);           }         } else {           int nsuff = func[j][x[i] -  a ];           if (nsuff == ylen) {             nsuff = f[ylen - 1];             dp[(i & 1)][j] = 1 + dp[!(i & 1)][nsuff];           } else             dp[(i & 1)][j] = dp[!(i & 1)][nsuff];         }       }     }     printf( %d n , dp[0][0]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int T;     cin >> T;     for (int t = 0; t < T; t++) {       int n;       cin >> n;       int a[n], b[n];       for (int i = 0; i < n; i++) {         cin >> a[i];       }       for (int i = 0; i < n; i++) {         cin >> b[i];       }       int difference = 0;       bool used = false, possible = true;       for (int i = 0; i < n; i++) {         if (a[i] > b[i]) {           possible = false;           break;         } else if (a[i] == b[i]) {           continue;         } else {           if (used) {             possible = false;             break;           }           difference = b[i] - a[i];           while (i < n) {             if (b[i] - a[i] == difference) {               i++;               continue;             }             if (b[i] == a[i]) {               used = true;               break;             }             if (b[i] - a[i] != difference) {               possible = false;               break;             }           }         }       }       if (possible)         cout <<  YES n ;       else         cout <<  NO n ;     }   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     long long int n, res = pow(10, 18);     cin >> n;     vector<long long int> v(n);     for (long long int i = 0; i < n; i++) cin >> v[i];     sort(v.begin(), v.end());     for (long long int i = 0; i < n / 2; i++) res = min(res, v[i + n / 2] - v[i]);     cout << res;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int qc = 1;     for (long long int i = 1; i <= qc; i++) solve();   }


#include <bits/stdc++.h>   using namespace std;   template <typename Arg1>   void __f(const char* name, Arg1&& arg1) {     cerr << name <<  :   << arg1 << endl;   }   template <typename Arg1, typename... Args>   void __f(const char* names, Arg1&& arg1, Args&&... args) {     const char* comma = strchr(names + 1,  , );     cerr.write(names, comma - names) <<  :   << arg1 <<   | ;     __f(comma + 1, args...);   }   const int INF = 1 << 29;   const int MOD = 1e9 + 7;   double sqr(double x) { return x * x; }   int main() {     double R, x1, y1, x2, y2;     scanf( %lf%lf%lf%lf%lf , &R, &x1, &y1, &x2, &y2);     double d = sqrt(sqr(x1 - x2) + sqr(y1 - y2));     double r = (d + R) / 2;     double x, y;     if (d > R) {       x = x1;       y = y1;       r = R;     } else if (d < 1e-10) {       x = x2;       y = y2 + r;     } else {       x = (x1 - x2) / d * r + x2;       y = (y1 - y2) / d * r + y2;     }     printf( %.10f %.10f %.10f n , x, y, r);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int dp[2005][2005] = {0};   long long int n, t, m, h, l, r;   int check(int v) { return v >= l && v <= r; }   void solve() {     cin >> n >> h >> l >> r;     vector<int> v;     for (int i = 0; i < n; i++) {       cin >> t;       v.push_back(t);     }     for (int i = 0; i <= n; i++) {       for (int j = 0; j <= h; j++) dp[i][j] = INT32_MIN;     }     dp[0][0] = 0;     for (int i = 1; i <= n; i++) {       for (int j = 0; j < h; j++) {         dp[i][j] = max(dp[i - 1][(j - v[i - 1] + h) % h],                        dp[i - 1][(j - v[i - 1] + 1 + h) % h]) +                    (j >= l && j <= r);       }     }     int mx = 0;     for (int i = 0; i < h; i++) {       mx = max(mx, dp[n][i]);     }     cout << mx <<   n ;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     { solve(); }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     cin >> n >> k;     string s;     cin >> s;     queue<string> q;     set<string> st;     int ans = 0;     q.push(s);     st.insert(s);     while (!q.empty() && int(st.size()) < k) {       string v = q.front();       q.pop();       for (int i = 0; i < v.length(); i++) {         string nv = v;         nv.erase(i, 1);         if (st.count(nv) == 0 && int(st.size()) + 1 <= k) {           q.push(nv);           st.insert(nv);           ans += n - nv.size();         }       }     }     if (int(st.size()) < k)       cout <<  -1  << endl;     else       cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   const int MAXN = 1e5 + 5;   std::unordered_map<int, int> cnt;   int a[MAXN]{};   int m = 1e9, n;   int main() {     scanf( %d , &n);     cnt.reserve(n);     for (int i = 0; i < n; ++i) {       scanf( %d , &a[i]);       ++cnt[a[i]];     }     std::sort(a, a + n);     int bank = cnt.at(a[0]), ret = 0;     for (int i = 1; i < n; ++i)       if (a[i] != a[i - 1]) {         int diff = std::min(bank, cnt.at(a[i]));         bank += cnt.at(a[i]) - diff;         ret += diff;       }     printf( %d n , ret);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, a[100100];   bool vis[100100];   vector<long long> v;   int main() {     long long n;     cin >> n;     for (int i = 0; i < n; i++) cin >> a[i];     sort(a, a + n);     if (a[n - 1] >= a[n - 2] + a[n - 3]) {       cout <<  NO  << endl;       return 0;     }     cout <<  YES  << endl;     for (int i = n - 1; i >= 0; i -= 2) {       vis[i] = true;       v.push_back(a[i]);     }     for (int i = 0; i < n; i++) {       if (!vis[i]) v.push_back(a[i]);     }     for (int i = 0; i < v.size(); i++) cout << v[i] <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<long long> g;   long long from, to;   void recurse(long long n) {     if (n > to) return;     if (n >= from && n <= to) {       g.push_back(n);     }     recurse(n * 10 + 4);     recurse(n * 10 + 7);   }   long long get(long long f, long long t, long long ff, long long tt) {     if (ff > t || tt < f) return 0;     ff = max(ff, f);     tt = min(t, tt);     return tt - ff + 1;   }   int main() {     long long pl, pr, vl, vr, k;     cin >> pl >> pr >> vl >> vr >> k;     from = min(pl, vl), to = max(pr, vr);     recurse(4);     recurse(7);     sort(g.begin(), g.end());     double res = 0.0;     if ((int)g.size() < k) {       puts( 0.0 );       return 0;     }     long long total = 0;     long long x, y, p, q, r, s;     long long denom;     denom = (pr - pl + 1) * (vr - vl + 1);     int i, j, sz = g.size();     i = 0;     j = i + k - 1;     while (1) {       if (i == 0)         p = from;       else         p = g[i - 1] + 1;       q = g[i];       r = g[j];       if (j + 1 < (int)g.size())         s = g[j + 1] - 1;       else         s = to;       x = get(pl, pr, p, q);       y = get(vl, vr, r, s);       total = x * y;       x = get(pl, pr, r, s);       y = get(vl, vr, p, q);       total += x * y;       int chk = 0;       if (g[i] >= max(pl, p)) chk++;       if (g[i] <= max(pr, q)) chk++;       if (g[i] >= max(vl, r)) chk++;       if (g[i] <= max(vr, s)) chk++;       if (g[i] >= max(pl, r)) chk++;       if (g[i] <= max(pr, s)) chk++;       if (g[i] >= max(vl, p)) chk++;       if (g[i] <= max(vr, q)) chk++;       if (chk == 8) {         total--;       }       res += (total * 1.0 / denom);       i++;       j = i + k - 1;       if (i >= sz || j >= sz) break;     }     printf( %.12lf n , res);     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t, n, k;     cin >> t;     while (t--) {       cin >> n >> k;       if (k % 2) {         if (n % 2) {           n -= k - 1;           if (n > 0) {             cout <<  YES n ;             for (int i = (0); i < (k - 1); ++i) {               cout <<  1  ;             }             cout << n <<   n ;           } else {             cout <<  NO n ;           }         } else {           n -= (k - 1) * 2;           if (n > 0) {             cout <<  YES n ;             for (int i = (0); i < (k - 1); ++i) {               cout <<  2  ;             }             cout << n <<   n ;           } else {             cout <<  NO n ;           }         }       } else {         if (n % 2) {           cout <<  NO n ;         } else {           n -= (k - 1);           if (n > 0) {             cout <<  YES n ;             for (int i = (0); i < (k - 1); ++i) {               cout <<  1  ;             }             cout << n <<   n ;           } else {             cout <<  NO n ;           }         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 998244353;   const int M = 3600 + 10;   int w, h, mx, n, r[M], c[M], cntx, cnty;   long long int fac[M], inv[M], g[M][M], f[M][M], ans;   long long int qpow(long long int a, long long int b) {     long long int y = 1;     for (; b; a = a * a % mod, b >>= 1)       if (b & 1) y = y * a % mod;     return y;   }   long long int C(int a, int b) {     return fac[a] * inv[b] % mod * inv[a - b] % mod;   }   long long int cal(int a, int b) {     return g[w][a] * C(w - cnty - 2 * a, b) % mod * f[h][b] % mod *            C(h - cntx - 2 * b, a) % mod * fac[a] % mod * fac[b] % mod;   }   int main(int argc, char const *argv[]) {     scanf( %d%d%d , &h, &w, &n);     for (int i = 1; i <= n; i++) {       int x1, y1, x2, y2;       scanf( %d%d%d%d , &x1, &y1, &x2, &y2);       r[x1] = r[x2] = c[y1] = c[y2] = 1;     }     mx = max(h, w);     fac[0] = 1;     for (int i = 1; i <= mx; i++) fac[i] = fac[i - 1] * i % mod;     inv[mx] = qpow(fac[mx], mod - 2);     for (int i = mx; i >= 1; i--) inv[i - 1] = inv[i] * i % mod;     for (int i = 1; i <= h; i++) cntx += r[i];     for (int i = 1; i <= w; i++) cnty += c[i];     for (int i = 0; i <= h; i++) f[i][0] = 1;     for (int i = 2; i <= h; i++)       for (int j = 1; 2 * j <= i; j++)         if (r[i] || r[i - 1])           f[i][j] = f[i - 1][j];         else           f[i][j] = (f[i - 1][j] + f[i - 2][j - 1]) % mod;     for (int i = 0; i <= w; i++) g[i][0] = 1;     for (int i = 2; i <= w; i++)       for (int j = 1; 2 * j <= i; j++)         if (c[i] || c[i - 1])           g[i][j] = g[i - 1][j];         else           g[i][j] = (g[i - 1][j] + g[i - 2][j - 1]) % mod;     for (int i = 0; i <= h && 2 * i <= w; i++)       for (int j = 0; j <= w && 2 * j <= h; j++)         if (2 * i + j <= w - cnty && i + 2 * j <= h - cntx)           ans = (ans + cal(i, j)) % mod;     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int MAX = 1000000;   int MIN = -1000000;   int INF = 1000000000;   int x4[4] = {0, 1, 0, -1};   int y4[4] = {1, 0, -1, 0};   int x8[8] = {0, 1, 1, 1, 0, -1, -1, -1};   int y8[8] = {1, 1, 0, -1, -1, -1, 0, 1};   int i, j, k;   int main() {     string str;     cin >> str;     str.push_back( 0 );     reverse(str.begin(), str.end());     str.push_back( 0 );     int indx = 1, ans = 1;     while (indx < str.size()) {       if (str[indx] ==  1  && str[indx + 1] ==  1 ) {         str[indx - 1] =  1 ;         for (i = indx; str[i] ==  1 ; i++) str[i] =  0 ;         str[i] =  1 ;         indx = i;       } else         indx++;     }     int satu = 0;     for (i = (0); i < (str.size()); i++) satu += (str[i] ==  1 );     cout << satu << endl;     {       fflush(stdin);       getchar();     };     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,abm,mmx,avx,avx2 )   #pragma GCC optimize( unroll-loops )   #define rep(i,a,b) for(int i=(a);i<=(b);++i)   #define req(i,a,b) for(int i=(a);i>=(b);--i)   #define rep_(i,a,b) for(int i=(a);i<(b).size();++i)   #define F(a) rep(a,1,n)   #define M(a,b) memset(a,b,sizeof a)   #define DC int T;cin>>T;while(T--)   #define ll long long   #define Z(a,b) sort(a+1,a+b+1)   using namespace std;   const unsigned _mod=998244353;   const unsigned mod=1e9+7;   const ll infi=0x3f3f3f3f3f3f3fll;   const int inf=0x3f3f3f3f;   void rd(ll &x){x=0;int f=1;char ch=getchar();while(ch<48||ch>57){if(ch==45)f=-1;ch=getchar();}while(ch>=48&&ch<=57)x=x*10+ch-48,ch=getchar();x*=f;}   ll ksm(ll x,ll y=mod-2,ll m=mod){ll ret=1;while(y){if(y&1)ret=ret*x%m;y>>=1ll;x=x*x%m;}return ret;}   ll qpow(ll x,ll y=2){ll ret=1;while(y>0){if(y&1ll)ret=ret*x;y>>=1ll;x=x*x;}return ret;}   /*       [[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]       [[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]       [[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]   */   ll fac[1000010],inv[1000010];   ll C(ll n,ll m){if(m>n||m<0)return 0;return fac[n]*inv[m]%mod*inv[n-m]%mod;}   int n,l,r,ans;   int chk(int x)   {       if (x<=0) return 0;       int a=max(x+l-1,0),b=max(n-r+x,0);       if (a+b>n) return 0;       if (n&1) return C(n-a-b,n/2-a)+C(n-a-b,n/2-a+1);       return C(n-a-b,n/2-a);   }   int chk2()   {       if (n&1) return C(n,n/2)+C(n,n/2+1);       return C(n,n/2);   }   int main()   {       *fac=*inv=1;       rep(i,1,1000000) fac[i]=fac[i-1]*i%mod;       rep(i,1,1000000) inv[i]=ksm(fac[i]);    DC       {           ans=0;           cin>>n>>l>>r;           rep(i,min(-l,r-n),min(n-l,r)) (ans+=chk(i))%=mod;           (ans+=1ll*max(min(-l,r-n)-1,0)*chk2()%mod)%=mod;           cout<<ans<<  n ;       }    return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long int inf = 1e9 + 7;   const long long int mod = 998244353;   long long int mini(long long int a, long long int b) {     if (a >= b) return b;     return a;   }   long long int maxi(long long int a, long long int b) {     if (a >= b) return a;     return b;   }   const long long int MAXN = 300002;   long long int factorial[MAXN + 1], inverse[MAXN + 1];   long long int binpow(long long int a, long long int b) {     long long int res = 1;     while (b > 0) {       if (b % 2 == 1) {         res = (res * a) % mod;       }       a = (a * a) % mod;       b >>= 1;     }     return res;   }   long long int nCk(long long int n, long long int k) {     if (k < 0 || k > n) {       return 0;     }     long long int ans = factorial[n];     ans = (ans * inverse[n - k]) % mod;     ans = (ans * inverse[k]) % mod;     return ans;   }   void preCompute() {     long long int fact = 1;     factorial[0] = 1;     inverse[0] = 1;     for (long long int i = 1; i <= MAXN; i++) {       fact = (fact * i) % mod;       factorial[i] = fact;       inverse[i] = binpow(factorial[i], mod - 2);     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     preCompute();     long long int n;     cin >> n;     long long int sumr = 0, suml = 0;     vector<long long int> A(2 * n);     for (long long int i = 0; i <= 2 * n - 1; i++) cin >> A[i];     sort(A.begin(), A.end());     for (long long int i = 0; i <= n - 1; i++) suml += A[i], suml %= mod;     for (long long int i = n; i <= 2 * n - 1; i++) sumr += A[i], sumr %= mod;     long long int tot = (mod + sumr - suml) % mod;     long long int a = nCk(2 * n, n);     long long int ans = (a * tot) % mod;     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 100;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n, pos, l, r, ans = 0;     cin >> n >> pos >> l >> r;     if (abs(pos - l) > abs(pos - r)) {       ans += abs(pos - r) + 1;       if (n == r) ans -= abs(pos - r) + 1;       n == r ? 0 : pos = r;       ans += abs(pos - l) + 1;       if (1 == l) ans -= abs(pos - l) + 1;     } else {       ans += abs(pos - l) + 1;       if (1 == l) ans -= abs(pos - l) + 1;       1 == l ? 0 : pos = l;       ans += abs(pos - r) + 1;       if (n == r) ans -= abs(pos - r) + 1;     }     cout << ans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int x, y, t, neg = 0, pos = 0;     cin >> t;     while (t--) {       cin >> x >> y;       if (x < 0)         neg++;       else         pos++;     }     if (neg <= 1 || pos <= 1)       cout <<  YES  << endl;     else       cout <<  NO  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename Arg1>   void __f(const char* name, Arg1&& arg1) {     cerr << name <<   :   << arg1 << std::endl;   }   template <typename Arg1, typename... Args>   void __f(const char* names, Arg1&& arg1, Args&&... args) {     const char* comma = strchr(names + 1,  , );     cerr.write(names, comma - names) <<   :   << arg1 <<   |  ;     __f(comma + 1, args...);   }   const long long maxn = (long long)2 * 1e5 + 10;   const double EPS = 1e-9;   const long long INF = 1e18 + 18;   const long long mod = (long long)10;   long long n, done[maxn], level[maxn], cnt = 0, parent[maxn];   vector<long long> graph[maxn];   set<pair<long long, long long> > seti;   void bfs(long long root) {     queue<long long> Q;     Q.push(root);     done[root] = 1, level[root] = 0;     while (!Q.empty()) {       long long top = Q.front();       Q.pop();       for (long long nb : graph[top]) {         if (done[nb]) continue;         done[nb] = 1;         level[nb] = 1 + level[top];         if (level[nb] > 2) seti.insert({-level[nb], nb});         parent[nb] = top;         Q.push(nb);       }     }   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n;     for (long long i = 1; i < n; i++) {       long long u, v;       cin >> u >> v;       graph[u].push_back(v);       graph[v].push_back(u);     }     bfs(1);     while (!seti.empty()) {       pair<long long, long long> top = *seti.begin();       long long tlevel = -top.first, tv = top.second;       for (long long nb : graph[parent[tv]]) {         auto it = seti.find({-level[nb], nb});         if (it != seti.end()) seti.erase(seti.find({-level[nb], nb}));       }       auto it = seti.find({-level[parent[tv]], parent[tv]});       if (it != seti.end())         seti.erase(seti.find({-level[parent[tv]], parent[tv]}));       cnt++;     }     cout << cnt << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   #pragma GCC optimize( -O2 )   const int LIM = 5e5 + 5, MOD = 1e9 + 7;   int t, n, m, k, x, y;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int tests;     cin >> tests;     cout << setprecision(10) << fixed;     while (tests--) {       long double d;       cin >> d;       long long v = d * d - 4 * d;       if (v < -1e-9) {         cout <<  N n ;       } else {         long double a, b, c;         c = sqrt(v);         a = (d + c) / 2;         b = (d - c) / 2;         cout <<  Y   << a <<     << b <<   n ;       }     }     return 0;   }